Re: Question about associative array runtime assignment vs literal initialization

Koichi Murase <[email protected]>
Newsgroups gmane.comp.shells.bash.bugs
Message-ID <CAFLRLk-Uzy=sousGveDAL-j2MWa7PqMjew3xao46VzehwcLh3A@mail.gmail.com>
2025年12月23日(火) 1:05 Koichi Murase <[email protected]>:
> > hobbit:~$ declare -A aa="("${kv[@]}")"; declare -p aa
> > declare -A aa=([3]="" [a]="half" [two]="and" [2.5]="three" [one]="1" )
>
> [...] 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

I'm sorry. Actually, my explanation above is wrong, because the
right-hand side of the assignment for the declare builtin is not a
context where word splitting.happens. The word splitting happens
because the declare builtin receives the literal '(one 1 two 2 two and
a half 2.5 three 3)' and parses it again. Anyway, the current behavior
for the latter example is expected in my understanding.

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