In a Linux shell, there are two ways to create an array.

  1. declare -a array
  2. array=()

but when I check if an array is empty using

 if [ ${#array[@]} -eq 0 ]

when an array is created using the declare -a array.it will have an error "unbound variabl".however, it works fine when using array=()

  • for me, both options works!! – msp9011 Dec 6 at 6:36
  • what is your bash version?when >=4.4,both is working. – focus zheng Dec 6 at 11:09

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.