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 arrayfor i in ${arr[@]}do        if [ $i=green ];        then                echo i('$i') is equal to green        else                echo i('$i') is not equal to green        fidoneI'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 greeni('blue') is equal to greeni('yellow') is equal to greeni('green') is equal to greenWhat am I doing wrong with the comparison? 
String comparison failing in bash
bash
Missing whitespace.[ $i=green ] means [ -n $i=green ]you need[ $i = green ]or even[ green = $i ]which works even for i=-n.If you don't need portability to other shells, you can use double square brackets in bash. [[ $i = green ]]Quotes are not needed (in fact, on the right hand side they have a special meaning - they prevent expansion). You can use == instead of =, too.