In ZSH, how do you set the value of an associative array parameter to an array?
e.g.,
% declare -A a=() % a[first]=(1 2) zsh: a: attempt to set slice of associative array And when I try and append the associative array a with the array b it seems to work but silently converts the value of b from an array to a scalar.
% declare -A a=() % declare -a b=(1 2) % print ${(t)b} array % a+=( [b]=($b) ) % print $a[b] (1 2) % print ${#a[b]} 5 % for ((i=1; i<=${#a[b]}; i++)) ; do print -n "${a[b][$i]}" ; done ; echo (1 2) %
zshdoes not have direct support for storing arrays this way, you can get very close using null-separated lists. Try:local -A a=(); in=(1 2); a[fr]=${(pj:\0:)in}; out=("${(0)a[fr]}"); typeset -p out