On 2021/12/21 20:07, Greg Wooledge wrote:
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
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.
----
Not using '-u' in bash is akin to not using 'strict' in perl. you
can put int misspelled variables
and not detect them -- and then wonder why your scripts don't work.
If you adhere to always requiring a definition of a variable, then using
'-u' is never a problem.
But not using '-u', in a script where all variables are defined will
show unintended errors.
They key is to always require definitions, which is why I always rely on
alias my='declare '
to shorten my declares.