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: Ilkka Virta
Subject: Re: Changing the way bash expands associative array subscripts
Date: Tue, 6 Apr 2021 19:19:37 +0300

On Tue, Apr 6, 2021 at 6:53 PM Greg Wooledge <greg@wooledge.org> wrote:

> In that case, I have no qualms about proposing that unset 'a[@]' and
> unset 'a[*]' be changed to remove only the array element whose key is
> '@' or '*', respectively, and screw backward compatibility.
>

That also seems to be what Ksh and Zsh do.

$ zsh -c 'k=@; typeset -A a=("$k" at foo 123); typeset -p a; unset "a[$k]";
typeset -p a;'
typeset -A a=( @ at foo 123 )
typeset -A a=( foo 123 )
$ ksh -c 'k=@; typeset -A a=([$k]=at [foo]=123); typeset -p a; unset a[$k];
typeset -p a;'
typeset -A a=([@]=at [foo]=123)
typeset -A a=([foo]=123)

Both also have issues with unset a[$k] when k="x] b[y", btw.

What konsolebox said about a[$k]=() works in my Zsh for indexed arrays, but
not associative ones.
(It replaces an array slice, so can also be used to insert elements in the
middle.)


reply via email to

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