I am trying to create a dictionary of key value pair using Bash script. I am trying using this logic:
declare -d dictionary
defaults write \"$dictionary\" ke
In bash, we use
declare -A name_of_dictonary_variable
so that Bash understands it is a dictionary.
For e.g. you want to create sounds dictionary then,
declare -A sounds
sounds[dog]="Bark"
sounds[wolf]="Howl"
where dog and wolf are "keys", and Bark and Howl are "values".
You can access all values using : echo ${sounds[@]} OR echo ${sounds[*]}
You can access all keys only using: echo ${!sounds[@]}
And if you want any value for a particular key, you can use:
${sounds[dog]}
this will give you value (Bark) for key (Dog).