Re: Question about associative array runtime assignment vs literal initialization

Koichi Murase <[email protected]>
Newsgroups gmane.comp.shells.bash.bugs
Message-ID <CAFLRLk_zfZMgCVT4Q8P+9aEShVB3W20ZBuL9i+4ftL+ajyZc-g@mail.gmail.com>
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.

> hobbit:~$ declare -A aa="("${kv[@]}")"; declare -p aa
> declare -A aa=([3]="" [a]="half" [two]="and" [2.5]="three" [one]="1" )

However, I agree with Chet that the above is the correct behavior. In
this example, ${kv[@]} is outside the double quoting (because the
first double quotation is « "(" » and the second double quotation is «
")" »), and then the bare ${kv[@]} is subject to word splitting so
that "two and a half" are split into four words "two", "and", "a", and
"half". Could you describe the reason that you think this is wrong?

> Both of these are "wrong" from the point of view of everybody but Chet.

No, at least, the latter is correct from my perspective. And, in
my perspective, the two cases are actually completely different.

--
Koichi
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.