I know this is almost too complicated for scripting purposes, but bear with me.
I know how you can declare arrays:
arr=(hello world)
echo ${arr[1]} # "world"
And I know that you can use hash maps in bash:
declare -A map=([hello]=world [foo]=bar)
echo ${map[hello]} # "world"
But can you have hash maps that have arrays as values in bash? I've tried several syntaxes, but usually I got a hash map, which had whitespace seperated list of string as the value associated with the hash
EDIT:
An example: I want to write an adapter toolNew
for a cmdline tool toolOld
. Both just printout some information about the system.
toolOld
can take nine different arguments a1
, a2
, a3
, b1
, ..., or c3
, which I want to simplify.
I.e. toolNew
only takes three differen arguments a
, b
, or c
.
The (imo) cleanest way to do this would be to have a function
toolNew() {
newArgument="$1"
for argument in "${argumentMap[newArgument][@]}"; do
toolOld "$argument"
done
}