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!
  • Question about... 王伟
    • Re: Quest... Greg Wooledge
      • Re: Q... Koichi Murase
        • R... Greg Wooledge
          • ... Zachary Santer
            • ... Greg Wooledge
          • ... Koichi Murase
            • ... Koichi Murase
          • ... Félix Hauri via Bug reports for the GNU Bourne Again SHell
            • ... Greg Wooledge
              • ... Félix Hauri via Bug reports for the GNU Bourne Again SHell

Reply via email to