Re: Question about associative array runtime assignment vs literal initialization

Koichi Murase <[email protected]>
Newsgroups gmane.comp.shells.bash.bugs
Message-ID <CAFLRLk858XgfEG0pQA7dLMHXKUdrvEjSB_GWPVgqXDuBCNavCg@mail.gmail.com>
2025年12月22日(月) 22:40 Greg Wooledge <[email protected]>:
> On Mon, Dec 22, 2025 at 10:46:12 +0800, 王伟 wrote:
> > Is this behavior intentional design, or is it considered a bug / limitation
> > of associative array assignment?

I believe « declare -A assoc=("${kv[@]}") » should be supported [where
kv is an indexed array in the form kv=(key1 value1 key2 value2 ...)].

> This came up just two weeks ago, in the thread starting at
> <https://lists.gnu.org/archive/html/bug-bash/2025-12/msg00026.html>.

That thread discussed a slightly different behavior: The OP of that
thread expected "[x]=y" in the results of shell expansion to be
treated as assignments like « [key]=value ».

However, the present report discusses whether "key1 value1 key2 value2
..." in the results of shell expansion should be subject to word
splitting and cause the assignments of « [key1]=value1 [key2]=value2
».

> I constructed an example very similar to yours, and Chet's response
> is here: <https://lists.gnu.org/archive/html/bug-bash/2025-12/msg00032.html>

It's similar, but it seems slightly different. The present report
seems to discuss a different point. « declare -A aa="( "${kv[@]}" )"»
and « declare -A aa=( "${kv[@]}" ) » are 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.