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: konsolebox
Subject: Re: Changing the way bash expands associative array subscripts
Date: Wed, 14 Apr 2021 07:28:43 +0800

On Wed, Apr 14, 2021 at 6:37 AM L A Walsh <bash@tlinx.org> wrote:
>     So echo ${a[@]} = expansion of all, but
> unset a[@] would only delete 1 element w/key '@'....
> how do I echo 1 element with key '@'

Indeed we can only quote:

a['@']=1234
echo "${a['@']}"
unset "a['@']"

Or have it interpreted as a value of a variable:

key=@
a[$key]=1234
echo "${a[$key]}"
unset 'a[$key]'

The current behavior of unset already does it right because unset is
not a keyword and not a special builtin like local.  Quoting and
re-evaluation are necessary so it gets evaluated well like how it is
evaluated during expansion and assignment.

I think I finally can say I'm against unset being defaulted to the
behavior of  assoc_expand_once.  It's oversimplified, adds
inconsistencies, and will majorly break scripts.

The only change I'd want is have `unset 'a[@]'` only unset the
elements and not the array itself.

-- 
konsolebox



reply via email to

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