Reputation: 81
Is there a way to make an array of dictionary like in python for bash?
I want to have to keep track of multiple associative arrays in bash. Is this possible?
I am reading in from a file and each line(separated by a certain character) represents different properties.
Upvotes: 1
Views: 658
Reputation: 123650
You can trivially simulate nested associative arrays in flat ones by combining their keys:
declare -A array
set_value() { array[$1:$2]=$3; }
get_value() { echo "${array[$1:$2]}"; }
set_value english name "Name"
set_value fremch name "Nom"
get_value english name
This simple example uses arrayname:keyname
as key. If your array or key names can contain colons, you can choose another delimiter, or add appropriate escaping.
Upvotes: 1