To declare associative array programmatically, I tried this:
foo=bar
typeset -A "${foo}"=([hello]=world)
Whatever I try, I’m getting:
zsh: unknown sort specifier
How to declare an associative array using a variable to set its name ?
>Solution :
This might not be the best way, but you can use indirect parameter expansion after declaring the name to be an associative array.
foo=bar
typeset -A "${(p)foo}"
typeset "${(p)foo}[hello]=world"
You can also use set -A
foo=bar
set -A $foo hello world