I'm attempting to loop through an array of strings, and do something a little different with one of the values. The string comparison fails on every element.
arr[0]='red'
arr[1]='blue'
arr[2]='yellow'
arr[3]='green'
## now loop through the above array
for i in "${arr[@]}"
do
if [ "$i"="green" ];
then
echo "i('$i') is equal to green"
else
echo "i('$i') is not equal to green"
fi
done
I've also tried (with the same result):
if [ "$i"='green' ];
and
if [ $i='green' ];
and
if [ $i="green" ];
Output of each of the above:
i('red') is equal to green
i('blue') is equal to green
i('yellow') is equal to green
i('green') is equal to green
What am I doing wrong with the comparison?
/bash
tag so I assumed this was acceptable use of the sub. – a coder Oct 01 '15 at 14:28