Frequently, string comparison is done using the test operator, [. This is ill-advised in bash, as there's a much more convenient format for string comparison, using the case statement. Here's a simple example:
testcase() {
for VAR; do
case “${VAR}” in
'') echo “empty”;;
a) echo “a”;;
b) echo “b”;;
c) echo “c”;;
*) echo “not a, b, c”;;
esac
done
}
testcase '' foo a bar b c d
The testcase function lets us test the case statement by wrapping it in a for loop that assigns each function argument to the VAR variable, then executes the case statement. With the foo a bar b c d arguments, we can expect the following output:
empty
not a, b, c
a
not a, b, c
b
c
d