bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Zero-length indexed arrays


From: Greg Wooledge
Subject: Re: Zero-length indexed arrays
Date: Tue, 21 Dec 2021 23:07:06 -0500

On Tue, Dec 21, 2021 at 10:48:07PM -0500, Dale R. Worley wrote:
> Lawrence Velázquez <vq@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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]