Last active
October 16, 2015 14:16
-
-
Save mike0004/6a8afc4ad8a2b066e38a to your computer and use it in GitHub Desktop.
associative array example, requires bash 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# good ref: http://www.artificialworlds.net/blog/2012/10/17/bash-associative-array-examples/ | |
# requires bash 4 for associative arrays | |
declare -A MYMAP=( | |
[foo]=bar | |
[baz]=quux | |
) | |
KEYS=(${!MYMAP[@]}) # Make a normal array containing all the keys in the associative array | |
for (( I=0; $I < ${#MYMAP[@]}; I+=1 )); do | |
KEY=${KEYS[$I]} | |
echo $KEY --- ${MYMAP[$KEY]}; | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment