[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, 12 Apr 2021 10:05:24 -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:

How about the cases with `test -v a[@]' and `key=@; test -v a[$key]'?

By the time test sees its arguments, there is no difference between these
two cases. You can do things to differentiate when running the `[['
command, but `test' goes through the entire set of word expansions.

I remember there was some discussion in the bug-bash list on the
behavior of `test -v a[@]' which actually tests whether the array `a'
has at least one element. It cannot be replaced by `test -v a' because
`a' implies `a[0]' here. But if I correctly understand it, `test -v
a[@]' can be replaced by `((${#a[@]}))'. Should any scripts relying on
`test -v a[@]' to test the array elements also be changed?

I'm ok with making the old behavior contingent on a compatibility setting,
like with `unset'.

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