Bash (Scripting) - Getting Started with Dictionaries
by
Jeremy Canfield |
Updated: April 05 2024
| Bash (Scripting) articles
Here is an example of how you can create a dictionary in a bash shell script and then loop through the keys and values in the dictionary.
#!/bin/bash
declare -A dictionary=( ["foo"]="hello" ["bar"]="world")
for key in ${!dictionary[@]}; do
echo $key = "${dictionary[$key]}"
done
Running this script should return the following.
bar = world
foo = hello
Did you find this article helpful?
If so, consider buying me a coffee over at