I am trying to substitute both the array name and value using eval and losing my mind with combinations that are not working
$ eval echo \$${port[$index]}${item[0]}${item[8]}
some_value
declare -a port=('Ex' 'backup' 'DRAC' 'Service');
declare -a item=('net' 'switch' 'port' 'speed' 'cvsswitch' 'vlan' 'link' 'count' 'list')
for x in $(eval echo \$${port[$index]}${item[0]}${item[8]}) ; do
eval ${port[$index]}${item[7]}=$[${port[$index]}${item[7]} +1] # incriment count
eval echo \$${port[$index]}${item[7]} # set count
eval \$"${port[$index]}${item[1]}"[\$${port[$index]}${item[7]}] <---- not working
done
fi
I am getting the following output when trying to eval this statement to assign the array[index_value] a value.
$ eval \$${port[$index]}${item[1]}[\$${port[$index]}${item[7]}]=abc123
-bash: [1]: command not found
or
$ eval \$${port[$index]}${item[1]}[\$${port[$index]}${item[7]}]=abc123
-bash: [1]=abc123: command not found
Does anyone have advice on how to get this working?
Thanks!
eval \$${port[$index]}${item[1]}[\$${port[$index]}${item[7]}]=abc123-- what, exactly, do you expect that to actually do?