Bootstrap FreeKB - Bash (Scripting) - Getting Started with Dictionaries
Bash (Scripting) - Getting Started with Dictionaries

Updated:   |  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 Buy Me A Coffee



Comments


Add a Comment


Please enter c59a63 in the box below so that we can be sure you are a human.