associative arrays' ".keys()"

bash

Solution

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/

Problem

In Bash (v4+): ``` $ declare -A x=([foo]=bar [coconut]=banana) $ echo ${x[@]} ``` gives: ``` banana bar ``` What can I type to get this: ``` foo coconut ```

Original source