|
From: | Zachary Santer |
Subject: | Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax |
Date: | Wed, 20 Mar 2024 10:16:29 -0400 |
On Wed, Mar 20, 2024 at 9:32 AM Lawrence Velázquez <vq@larryv.me> wrote: > > https://lists.gnu.org/archive/html/bug-bash/2019-07/msg00056.html Wherein he shows that Zsh can do this without eval: > declare -a array=( a 1 b 2 c 3 ) > declare -A hash=( ${array[@]} ) > declare -p hash > => typeset -A hash=( [a]=1 [b]=2 [c]=3 ) > declare -a array2=( ${(kv)hash[@]} ) > declare -p array2 > ==> typeset -a array2=( a 1 b 2 c 3 ) 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.
[Prev in Thread] | Current Thread | [Next in Thread] |