You're going to have to use eval
here, too, but I would again recommend a different overall design.
if [ "$(eval "echo \${$i[0]}")" = "true" ]
Edit:
Proposal for redesign (uses an imaginary scenario extrapolated from the little bit I've seen of what you're doing):
#!/bin/bash
# sample input: $1=foo,bar,baz
saveIFS=$IFS
IFS=',' # word splitting will be done using a comma as the delimiter
names=($1) # store the names for cross reference or indirection
IFS=$saveIFS
# Constants:
declare -r heater=0
declare -r exhaust=1
declare -r light=2
declare -r rotation=3
# deserialize and serialize:
# initialize settings
for ((i=0; i<${#names}; i++))
do
declare ${names[i]}=$i # setup indirection pointers
config[i]="null null null null"
done
# by index:
vals=(${config[0]}) # deserialize
echo ${vals[light]} # output value
vals[light]="false" # change it
config[0]=${vals[@]} # reserialize
# by name:
vals=(${config[$foo]})
echo ${vals[light]} # output value
# by indirection:
vals=(${config[${!names[0]}]})
echo ${vals[light]} # output value
# iteration using indirection
for name in ${names[@]}
do
echo "Configuration: $name"
echo " all settings: ${config[${!name}]}"
vals=(${config[${!name}]})
for setting in heater light # skipping exhaust and rotation
do
echo " $setting: ${vals[${!setting}]}"
done
done
This may give you some ideas and principles that you can make use of. If you're using Bash 4, you could use associative arrays which would greatly simplify this type of thing. You can also use functions to do some simplification.