${(A)…}
: Convert substitution into array expression
Converts the substitution of the value into an array expression, regardless of the name of the variable.
Field splitting, e.g. ${(A)=name}
, is helpful for scalar values of name
.
If AA
, then the substitution is interpreted as an associative array.
Links
Examples
- Convert a list of key-value pairs into an associative array
- Output:
1 2 3 4 5 6
key_value_list="a 1 b 2 c 3" unset myArray # 1st '=' splits key_value_list into separate words, # 2nd '=' declares and assigns to associative array 'myArray' : ${(AA)=myArray=$key_value_list} typeset -p myArray
1
typeset -A myArray=( [a]=1 [b]=2 [c]=3 )
BashSupport Pro is a Zsh IDE with support for ${(A)…} – try it now!