2

I have an associative array:

declare -A hash

hash[one]=1
hash[two]=2
hash[third item]=3

How can I create an indexed array from the keys of this associative array?

1 Answer 1

3

To make an array with the keys from an associative array:

arr=("${!hash[@]}")

To make an array with the values:

arr=("${hash[@]}")

Note that you need the double quotes to prevent the shell from word splitting.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.