Re: Zero-length indexed arrays

2021-12-22 Thread L A Walsh
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 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 shi

Re: Zero-length indexed arrays

2021-12-22 Thread Chet Ramey
On 12/22/21 12:12 AM, Lawrence Velázquez wrote: a. Using ${a[@]} or ${a[*]} with an array without any assigned elements when the nounset option is enabled no longer throws an unbound variable error. https://lists.gnu.org/archive/html/bug-bash/2016-07/msg00031.html --

Re: Zero-length indexed arrays

2021-12-22 Thread konsolebox
On Wed, Dec 22, 2021 at 4:07 AM Greg Wooledge wrote: > I would recommend not using set -u. > Especially > when you need to support multiple bash versions, or even multiple shells. It's still useful during development stages. -- konsolebox

Re: Zero-length indexed arrays

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

Re: Zero-length indexed arrays

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

Re: Zero-length indexed arrays

2021-12-21 Thread Dale R. Worley
Lawrence Velázquez 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

Re: Zero-length indexed arrays

2021-12-16 Thread Lawrence Velázquez
On Thu, Dec 16, 2021, at 11:45 PM, Lawrence Velázquez wrote: > Did you mean to say that ${#FOO[*]} causes an error? Because > ${FOO[*]} does not, à la $*: > > [...] > > Like ${FOO[*]}, ${FOO[@]} and $@ are exempt from ''set -u''. Perhaps you're using an old bash, like the one shipped with macOS?

Re: Zero-length indexed arrays

2021-12-16 Thread Lawrence Velázquez
On Thu, Dec 16, 2021, at 11:01 PM, Dale R. Worley wrote: > A bit ago I was debugging a failing script at work. It turns out that > when you say > FOO=(x y z) > then the variable FOO is an array and is defined. But when you say > FOO=() > then the variable FOO is an array (because ${#FOO[*

Zero-length indexed arrays

2021-12-16 Thread Dale R. Worley
A bit ago I was debugging a failing script at work. It turns out that when you say FOO=(x y z) then the variable FOO is an array and is defined. But when you say FOO=() then the variable FOO is an array (because ${#FOO[*]} substitutes an integer viz. 0) but it is *not* defined (because ${