On Tue, Apr 6, 2021 at 6:53 PM Greg Wooledge <g...@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