[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: Thu, 8 Apr 2021 14:44:13 -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 10:28 AM, Koichi Murase wrote:

Thank you for the pointer. I still think changing the syntactic
treatment of the arguments of the `unset' builtin is the cleanest way
to solve the problem of `key=@; unset -v a[$key]'. Maybe we can ask
Chet why this isn't considered.

It's not necessary, and the cost and resultant mess aren't worth it.

We now see two benefits of changing
the treatment of the arguments of `unset', 1) `unset -v a[$key]' is
not the subject to the pathname expansions and word splitting.

Appropriate quoting.

2) we
can distinguish the erasure of the element associated with key=@
`unset -v a[$key]' from the entire array erasure `unset -v a[@]'.

I'm prepared to accept the argument that it's not necessary to support
a[@] unsetting the entire array except in a compatibility mode.

Conversely, there are definitely more codes naively writing as `unset
a[1]' which can be broken by pathname expansions.

I don't think the way to fix broken code is to change the shell to
accommodate it. The bash documentation has warned about this for a long

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