vars="a,b"
a="True"
b="False"
IFS=","
for var in $vars; do
if [[ "$var" = "True" ]]; then
echo "True found"
fi
done
I would expect the above bash script to print out "True found". But it does not print anything. Any ideas as to why ?
Make this:
if [[ "${!var}" = "True" ]]; then
${!varname} expands the variable named in $varname. Otherwise, you get the name itself, not the contents of the variable with that name.
See BashFAQ #6 for far more details.
vars="a,b"is not an array$varto evaluate toTrueorFalse, rather thanaorb?set -xto the top of this script to see what is actually happening at each step to better understand what is going on.