On 12/22/25 11:15 AM, Koichi Murase wrote:
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.

"You can defer the expansion and let the declare builtin do it by adding a
layer of quoting. If you quote the rhs of the assignment statement, you
prevent it from being recognized as a compound assignment by the parser,
and it undergoes the `normal' string word expansions before the `declare'
builtin sees it.

For backwards compatiblity, declare accepts compound assignment statements
as arguments and treats them like standalone compound assignments. This
isn't how I would choose to do it today, but I did initially, and still
support it."

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    [email protected]    http://tiswww.cwru.edu/~chet/

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

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

Reply via email to