help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Expansions in associative array subscripts


From: Greg Wooledge
Subject: Re: [Help-bash] Expansions in associative array subscripts
Date: Wed, 7 Aug 2019 09:53:06 -0400
User-agent: Mutt/1.10.1 (2018-07-13)

On Wed, Aug 07, 2019 at 02:33:24PM +0100, Stephane Chazelas wrote:
> 2019-08-07 08:49:16 -0400, Greg Wooledge:
> [...]
> > > "${associativeArray[*]}"
> > 
> > The one-character string * is the key.  No globbing is done.
> [...]
> 
> ${associativeArray[*]} and ${associativeArray[@]} are
> special and expand to value of all elements similarly to
> Bourne's "$@" and "$*". That's only when literal. With k=*;
> ${associativeArray[$k]} still gets you the value for the literal
> "*" key like ${associativeArray["*"]} or even
> ${associativeArray[""*]}.

Of course, you're right... I got confused, and slightly lazy, and only
tested the [?] case and not the [*] case.

wooledg:~$ declare -A aa
wooledg:~$ aa[?]=foo
wooledg:~$ aa[*]=foo
bash: aa[*]: bad array subscript
wooledg:~$ declare -p aa
declare -A aa=(["?"]="foo" )

wooledg:~$ key=*
wooledg:~$ aa[$key]=bar
wooledg:~$ declare -p aa
declare -A aa=(["?"]="foo" ["*"]="bar" )



reply via email to

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