The if [ {$i[0]} = "true" ] below is failing. I can’t seem to figure out how to get the correct formatting for {$i[0]} in the if statement.
#!/bin/bash
foo=bar1,bar2
for i in ${foo//,/" "}
do
declare -a ${i}='(true null null null)'
done
for i in ${foo//,/" "}
do
if [ {$i[0]} = "true" ]
then echo "yes"
eval "echo \${$i[*]}"
else echo "no"
fi
done
I had a somewhat of related problem that someone was kind enough to help me with
Bash echo all array members when array is referenced as a variable in a loop
Thanks for any help!
You’re going to have to use
evalhere, too, but I would again recommend a different overall design.Edit:
Proposal for redesign (uses an imaginary scenario extrapolated from the little bit I’ve seen of what you’re doing):
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.