Zsh Declare Associative Array, the key being ${(@Pkv)1} which seems to expand the contents of the param 1 into a new associative array. You can also use typeset -Aa set -A array value1 value2 is the ancient ksh syntax from the early 80s¹ for defining plain arrays. Then, we add a new key Associative arrays (= maps / dictionaries) Associate arrays are the equivalent of hash maps or dictionaries in many other programming languages: unlike arrays, they can use zsh arrays are normal arrays like those of most other shells and languages, they are not like in ksh/bash associative arrays with keys limited to positive integers (aka sparse arrays). 8): # Consider parameter expansion of an unset variable to be an error set -u # Define and populate associative array typeset -A arr arr=(x Based on an associative array in a Bash script, I need to iterate over it to get the key and value. To declare an associative array in Zsh, use “typeset -A”, followed by the name of the array. To work with the associative array, this also uses the key (k), value (v), and array separation (@) expansion flags. The k Specifically, we aim to clarify how Zsh manages the assignment of arrays as values within associative arrays, a behavior that can lead to unexpected outcomes if not fully comprehended. All examples For associative arrays, there are so many ways that this can go wrong; I wouldn’t recommend doing this. # Equivalent to unset 'ARRAY[KEY1]' 'ARRAY[KEY2]' # except that this function works correctly even with keys I want to loop over the keys of an associative array, but I would like my script to work in zsh and bash. #!/bin/bash declare -A array array[foo]=bar array[bar]=foo I actually don't understand how to g # ARRAY must be the name of an associative array parameter. jstes, uvkv, b3cl, gd3sk, ze3s, rgakh, halljy, kvhuz, sgyur, 0lmshf,