Associative Arrays ".keys ()"

In Bash (v4 +):

$ declare -A x=([foo]=bar [coconut]=banana)
$ echo ${x[@]}

gives:

banana bar

What can I type to get this:

foo coconut
+5
source share
1 answer

You can run xin echo ${x[@]}with !to get the keys:

echo ${!x[@]}

Additional information on associative arrays: http://www.artificialworlds.net/blog/2012/10/17/bash-associative-array-examples/

+7
source

All Articles