Question about associative array runtime assignment vs literal initialization

王伟 <[email protected]>
Newsgroups gmane.comp.shells.bash.bugs
Message-ID <CAPGy_BawFzTfFxR3afZQk62ijFYKykeXipzKW1Hy8VsNJhutBA@mail.gmail.com>
Hi,

I have a question about associative array behavior in Bash 5.3.

When using literal initialization:

declare -A params=(a 1 b 2)

Bash correctly interprets the elements as key/value pairs.

declare -p params
Output:
declare -A params=([b]="2" [a]="1" )

But when using runtime assignment:

local -A params=("$@")

or:

declare -A params=("${array[@]}")

Bash does not interpret the arguments as key/value pairs, and instead
produces something like:

declare -p params
declare -A params=(["a 1 b 2"]="")

My question is:

Is this behavior intentional design, or is it considered a bug / limitation
of associative array assignment?

If this is intentional, could you clarify why runtime assignment does not
follow the same key/value parsing rules as literal initialization?

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