Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #16743
| From | Chet Ramey <chet.ramey@case.edu> |
|---|---|
| Newsgroups | gnu.bash.bug |
| Subject | Re: Bash parameter transforamtion on empty array triggers unset variable. |
| Date | 2020-08-12 09:49 -0400 |
| Organization | ITS, Case Western Reserve University |
| Message-ID | <mailman.1714.1597240155.2739.bug-bash@gnu.org> (permalink) |
| References | <CAJjXSE9b8G0aXyc+t58cbYRwFbiN5eX2rpKnyFwg728x5ZQhKQ@mail.gmail.com> <3ddb8a56-c7d0-b87e-8bb4-520acecc90d5@case.edu> <CAJjXSE8vfCpx7r4owo5V0tA=G1qi5nr5oDwqJwyQoM41oC2W3Q@mail.gmail.com> <6afdb56d-5dff-e780-e794-8c053fb166ee@case.edu> |
On 8/11/20 11:45 AM, Andrew Neff wrote:
> Ah, I see the confusion.
>
> The issue you pointed out, "@Q breaks set -o nounset" refers to quote
> parameter expansion, as does the line in CHANGES-5.1, 1.q, which makes
> sense to call this a bug that was allowed in bash 4.4 and 5.0.
Not quite. The report revealed that none of the parameter transformations
obeyed `set -u'. The fix was to make that happen, so that parameter
transformations were aligned with the other word expansions.
> I should have specified, the focus of this issue is the "@a" expansion.
Sure, you want an exception.
> It
> makes sense that @Q/E/P/A expansion should not work on unset variables with
> nounset enabled. However, @a is uniquely different, in that it does not
> have to do with the value of the variable, but rather the variable type.
This is why it works on unset variables when `set -u' isn't enabled. The
question is whether that makes it special enough to be an exception.
> Here are 3 specific details I would like to address:
>
> 1. @a expansion should work on unset variables with "set -u" in bash 5.1.
> It seems like the correct thing to do. Only @a expansion. This has been a
> very useful feature in bash 4.4 and 5.0.
OK, you found it useful in something you wanted to do. You're restating the
proposition.
>
> 2. With "set -u", the following works in bash 4.4 or newer (and makes sense
> that it works): (set -eu; x=(); echo "${x[@]}")
> Here x is not unset, it is set to an empty array. This expansion make sense
> with nounset turned on because x is not unset, it is set to ()
That's not why. The variable is indeed unset. The reason it doesn't fail
is because there's a special POSIX carveout for $@ with no positional
parameters and I extended it to ${var[@]}. The expansions of $@ and ${A[@]}
parallel each other in just about every other way, so it made sense.
> 3. The same as #2, but for associative arrays
> Works: (set -eu; declare -A x=(); echo "${x[@]}")
The same carveout for ${A[@]}.
So I guess the question is whether or not @A and @a are exceptional enough.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/
Back to gnu.bash.bug | Previous | Next | Find similar
Re: Bash parameter transforamtion on empty array triggers unset variable. Chet Ramey <chet.ramey@case.edu> - 2020-08-12 09:49 -0400
csiph-web