bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "${assoc[@]@k}" doesn't get expanded to separate words within compou


From: Chet Ramey
Subject: Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax
Date: Fri, 22 Mar 2024 11:23:35 -0400
User-agent: Mozilla Thunderbird

On 3/20/24 10:16 AM, Zachary Santer wrote:

and then uses eval in his examples of how Bash could incorporate
similar behavior:

array=( val1 "val2*[special-chars]" )
printf -v serialized "%q " "${array[@]}"
eval "deserialized=($serialized)"

declare-A hash=( [key1]=val1 ['key2*[special-chars]']=val2 )
printf -v serialized "%q " "${*hash[@]}"
typeset -A deserialized_hash
eval "deserialized_hash=($serialized)"

I don't get it.

This is what you can do with @K.

https://lists.gnu.org/archive/html/bug-bash/2021-08/msg00119.html

Word splitting doesn't happen on the rhs of an assignment statement, so you
use eval. The @K quoting is eval-safe.

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

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]