[Top][All Lists]

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

Re: Changing the way bash expands associative array subscripts

From: Chet Ramey
Subject: Re: Changing the way bash expands associative array subscripts
Date: Mon, 29 Mar 2021 11:02:56 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.8.1

On 3/15/21 9:41 PM, Koichi Murase wrote:
2021年3月16日(火) 8:12 Chet Ramey <chet.ramey@case.edu>:
key='x],b[$(echo uname >&2)'
(( assoc[$key]++ ))
declare -A assoc=(["x],b[\$(echo uname >&2)"]="1" )

I agree with this change. I think the same rule should apply also to
the indexed arrays in the arithmetic command. With `index='0],b[1';
((array[$index]++))', I expect a syntax error rather than an
unexpected structure of the arithmetic evaluation.

Yes, this is a part of the proposed change.

The issue lies with shell builtins. Builtin commands have to undergo the
full set of shell expansions [...]

Can you also take care of the behavior of `unset -v 'a[@]''?

Well, you have to pick one behavior or another. The `@' subscript always
expands to all members of the array. The current behavior is consistent
with that, and documented.

Maybe this is unrelated to the extra expansions of array subscripts,
but is there any reason that Bash disallows empty associative keys?

That's a separate change I haven't considered as part of this.

``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/

reply via email to

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