Robottinosino
Robottinosino

Reputation: 10882

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

Upvotes: 5

Views: 399

Answers (1)

user1621465
user1621465

Reputation:

You can preceed x in echo ${x[@]} with a ! to get keys:

echo ${!x[@]}

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

Upvotes: 7

Related Questions