In zsh, is there a way to assign an associative array to another variable? I would like something like this:
typeset -A orig orig=(key1 val1 key2 val2) typeset -A other other=$orig print '$orig: '$orig print '$other: '$other print '$orig[key1]: '$orig[key1] print '$other[key1]: '$other[key1]
This will print:
$orig: val1 val2 $other: val1 val2 $orig[key1]: val1 $other[key1]:
I want to be able to use $other[key1] and get val1 .
I know that I can iterate over the keys and copy them over the elements, but I really want to avoid this. In addition, eval is evil :)
I tried other=($orig) and other options, but this will get my values ββfrom orig and create as an associative array like this
other=(val1 val2)
So other[key1] returns nothing, and other[val1] returns val2 , which I don't want.
If I understand correctly, what happens in each of mine is that $other receives an array of $orig values ββwithout keys. How can I get it to receive both keys and and have the correct connection between them?
I'm not worried about null values, even if that would be a problem, because I'm sure $orig will behave well.
Thanks!
arrays shell associative-array zsh
Vitor eiji
source share