Skip to content

Instantly share code, notes, and snippets.

@aks
Created January 23, 2014 06:50
Show Gist options
  • Save aks/8574081 to your computer and use it in GitHub Desktop.
Save aks/8574081 to your computer and use it in GitHub Desktop.
Show how bash associative arrays work.
#!/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
$ ./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