The following is a summary of various options for string comparison using test, which is taken from the Bash reference manual available at http://www.gnu.org/software/bash/:
Test operator |
Tests true if |
-n string |
True if the length of string is non-zero. |
-z string |
True if the length of string is zero. |
string1 != string2 |
True if the strings are not equal. |
string1 == string2 string1 = string2 |
True if the strings are equal. |
string1 > string2 |
True if string1 sorts after string2 lexicographically. |
string1 < string2 |
True if string1 sorts before string2 lexicographically. |
If we want to check whether the length of a string is non-zero, then we can check it ...