Re: Question about associative array runtime assignment vs literal initialization

Koichi Murase <[email protected]>
Newsgroups gmane.comp.shells.bash.bugs
Message-ID <CAFLRLk-y2RMjdh9X4kS9u7dD1id04EchLok6RfHftXm1Y7GXmg@mail.gmail.com>
2025年12月24日(水) 0:03 Chet Ramey <[email protected]>:
> On 12/22/25 11:05 AM, Koichi Murase wrote:
> > 2025年12月23日(火) 0:21 Greg Wooledge <[email protected]>:
> >> hobbit:~$ declare -A aa=("${kv[@]}"); declare -p aa
> >> declare -A aa=(["one 1 two 2 two and a half 2.5 three 3"]="" )
> >
> > I agree that the above behavior is wrong.
>
> You would like word splitting in this one specific case?

No, not specific to the above exact form. I request that shell
expansions (including word splitting) be applied to ALL
non-subscripted words in the compound list.

> Treating `declare'
> as a declaration utility in all cases except this one?

Could you explain in a bit more detail? It seems that treating «kv=(k1
v1); declare -A aa=("${kv[@]}")» as «declare -A aa; aa[k1]=v1» seems
exactly what has been made possible as a declaration utility. In the
first place, if it were not a declaration utility, the entire compound
assignment would be a syntax error. Also, the traditional behavior of
indexed arrays «x='1 2 3 4'; declare -a a=($x)» results in «a=(1 2 3
4)» (but not in «a=('1 2 3 4')» as you suggest for the associative
array).

--
Koichi

> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>                  ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRU    [email protected]    http://tiswww.cwru.edu/~chet/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.