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

Copy assiociative arrays



Hi all,

is it possible to copy associative arrays?

I.e. have

declare -A foo bar
foo=(muh vier bla "\\sechs")
bar=$foo

using this, bar only contains the values of foo (and using ${(kv)foo}
instead still only makes it a string).

The current awkward way I found is:

declare -A foo bar
foo=(muh vier bla "\\sechs")
: ${(AA)bar::=${(kv)foo}}

But this seems rather cluttered and unintuitive...

The other way is using indirection, in that bar only holds the string
"foo" and with the (P) flag this is resolved. But unfortunately I can't
make it work with subscripts:

declare -A foo bar
foo=(muh vier bla "\\sechs")
bar=foo
# all output the empty string
echo ${${(P)bar}[muh]}
echo ${${bar}[muh]}

Thanks and regards,
René

Attachment: signature.asc
Description: OpenPGP digital signature



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