I've got the following problem: I got a config-file (written in bash) with multiple arrays, the amount of these arrays is different from config to config. Each array contains three values.
declare -a array0
array0=(value1 value2 value3)
#
declare -a array1
array1=(value1 value2 value3)
#
declare -a array2
array2=(value1 value2 value3)
Now, this config file is sourced into the main bash script. I want to go from array to array and store the values into single variables. My actual solution:
for ((i=0;i=2;i++))
do
if [ "$i" = 0 ]
then
wantedvalue1="${array0["$i"]}"
fi
if [ "$i" = 1 ]
then
wantedvalue2="${array0["$i"]}"
fi
if [ "$i" = 2 ]
then
wantedvalue3="${array0["$i"]}"
fi
done
I guess, this will work for one specific array. But how can I tell the script to analyze every array in the config file like this?
Thanks for any help!