bug-bash
[Top][All Lists]
Advanced

[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, 12 Apr 2021 11:16:14 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.9.0

On 4/6/21 12:46 PM, Koichi Murase wrote:

Looking at another thread
https://lists.gnu.org/archive/html/bug-bash/2021-04/threads.html#00051,
I'm now also interested in how we can handle the indirect expansions
for 'a[@]' and the namerefs for 'a[@]':

$ declare -A a=(['@']=x [1]=y)
$
$ # indirect expansions
$ iref1=a[@]; printf '<%s>' "${!iref1}"; echo
<y><x>
$ key=@; iref2=a[$key]; printf '<%s>' "${!iref2}"; echo
<y><x>    # <-- unexpected

But these cases are identical. After the assignment statement, iref2 has
value 'a[@]', just like iref1. I don't see why one would be more unexpected
than the other, and they're both equivalent to ${a[@]}. Unless that's your
point?


$ # namrefs
$ declare -n nref1=a[@]; printf '<%s>' "$nref1"; echo
<y x>
$ key=@; declare -n nref2=a[$key]; printf '<%s>' "$nref2"; echo
<y x>    # <-- unexpected

Yes, namerefs are different, but not in a way that matters here. These two
cases are identical as well. If you added `declare -p nref2', you'd see it.
(The differing output issue got fixed back in January, the result of
https://lists.gnu.org/archive/html/bug-bash/2021-01/msg00148.html)

I guess I see what your point might be, but these aren't different cases.
Variables don't carry around the kind of state that might be used to
differentiate their behavior depending on the value they got at assignment
time. There is no useful syntactic information there.

Chet
--
``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]