How can I compare a variable to a text string, rather than integer, in an if/else statement?

Solution 1:

Something like this:

act="add"
if [[ $act = "add" ]]
then
    echo good
else
    echo not good
fi

-eq is for number comparison, use = for string comparison

Solution 2:

This method would also work. Very similar to @Guru's answer but removes the need for double square brackets.

if [ "$act" == "add" ]
then
echo "Good!"
      else
      echo "Not good!"
fi