#!/bin/sh -u # Demonstrate the TEST command in an IF statement (string tests). # String comparison uses "=" not "-eq". # # NOTE: This script fragment is incomplete - it does not follow all # the script guidelines set out in "script_style.txt". # # -IAN! idallen@idallen.ca s1="dog" s2="cat" # Two different strings # if [ "$s1" = "$s2" ] ; then echo "$s1/$s2: two strings are equal" else echo "$s1/$s2: two strings are not equal" fi # Two same strings # if [ "$s1" = "$s1" ] ; then echo "$s1/$s1: two strings are equal" else echo "$s1/$s1: two strings are not equal" fi # This next one produces an error message from TEST. # You must use "=" not "-eq" for string comparisons. # echo "The next one will produce an error message:" if [ "$s1" -eq "$s1" ] ; then echo "$s1/$s1: two strings are equal" else echo "$s1/$s1: two strings are not equal" fi