Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: eval "echo \"$a=( \${(qq)$a[@]} )\""



On Feb 14,  6:16pm, Sebastian Gniazdowski wrote:
} Subject: eval "echo \"$a=( \${(qq)$a[@]} )\""
}
} say "a" holds array name "arr".

This is the reason ${(P)a} exists.

It wasn't fully functional for associative arrays until quite recently.

} Doing:
} 
} % a=arr; arr=( a b "c d" ); eval "echo \"$a=( \${(qq)$a[@]} )\""

The [@] is being applied to $a, not to the expansion into "arr".
You meant (note one extra set of braces):

% a=arr; arr=( a b "c d" ); eval "echo \"$a=( \${(qq)${a}[@]} )\""
arr=( 'a' 'b' 'c d' )


But all you really need is

% echo $a=\(${(kvqqP)a}\)
arr=('a' 'b' 'c d')

For an associative array that works only in zsh-5.2 and later, but it
otherwise works for both associative and indexed arrays (the kv is just
ignored in the indexed case).



Messages sorted by: Reverse Date, Date, Thread, Author