Created
January 23, 2014 06:50
-
-
Save aks/8574081 to your computer and use it in GitHub Desktop.
Show how bash associative arrays work.
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/local/bin/bash | |
declare -A aa | |
aa[foo]=bar | |
aa[fee]=baz | |
aa[fie]=tar | |
for key in "${!aa[@]}" ; do | |
printf "key: '%s' val: '%s'\n" $key "${aa[$key]}" | |
done | |
echo "${aa[@]}" | |
exit |
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
$ ./test-bash-aarrays.sh | |
key: 'fie' val: 'tar' | |
key: 'foo' val: 'bar' | |
key: 'fee' val: 'baz' | |
tar bar baz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment