[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Zero-length indexed arrays
From: |
Lawrence Velázquez |
Subject: |
Re: Zero-length indexed arrays |
Date: |
Wed, 22 Dec 2021 00:12:04 -0500 |
User-agent: |
Cyrus-JMAP/3.5.0-alpha0-4525-g8883000b21-fm-20211221.001-g8883000b |
On Tue, Dec 21, 2021, at 10:48 PM, 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
> $ bash -uc ': "${FOO[*]}"'
> bash: FOO[*]: unbound variable
> $
>
>> Like ${FOO[*]}, ${FOO[@]} and $@ are exempt from ''set -u''.
>
> It looks like that's a change since 4.2.46.
Yes, it appears to be from 4.4.
https://git.savannah.gnu.org/cgit/bash.git/tree/CHANGES?id=15409324f1974d41c183904ad575da7188058c1c#n1512
This document details the changes between this version,
bash-4.4-rc2, and the previous version, bash-4.4-beta2.
[...]
3. New Features in Bash
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.
> Is there text in the manual page about that?
I don't know.
--
vq