On Tue, Dec 21, 2021 at 10:48:07PM -0500, Dale R. Worley wrote: > Lawrence Velázquez <v...@larryv.me> writes: > > Did you mean to say that ${#FOO[*]} causes an error? Because > > ${FOO[*]} does not, a la $*: > > The case that matters for me is the Bash that ships with "Oracle Linux". > Which turns out to be version 4.2.46(2) from 2011, which is a lot older > than I would expect. But it *does* cause an error in that verison: > > $ ( set -u ; FOO=() ; echo "${FOO[@]}" ) > bash: FOO[@]: unbound variable
unicorn:~$ bash-4.1 -c 'set -u; a=(); echo "${foo[@]}"' bash-4.1: foo[@]: unbound variable unicorn:~$ bash-4.2 -c 'set -u; a=(); echo "${foo[@]}"' bash-4.2: foo[@]: unbound variable unicorn:~$ bash-4.3 -c 'set -u; a=(); echo "${foo[@]}"' bash-4.3: foo[@]: unbound variable unicorn:~$ bash-4.4 -c 'set -u; a=(); echo "${foo[@]}"' unicorn:~$ I would recommend not using set -u. It's not as bad as set -e, but it's still pretty bad. It breaks what would otherwise be valid scripts, and the breakage is not always easy to predict, as you've now seen. Especially when you need to support multiple bash versions, or even multiple shells.