==—Compares whether two strings are equal
!=—Compares whether two strings are not equal
The following examples compare two strings, string1 and string2, in
the shell program compare1:
Click here to view code image
#!/bin/tcsh
set string1 = "abc"
set string2 = ""abd"
if (string1 == string2) then
echo "string1 equal to string2"
else
echo ""string1 not equal to string2"
endif
if (string2 != string1) then
echo ""string2 not equal to string1"
else
echo ""string2 equal to string1"
endif
If you execute compare1, you get the following results:
Click here to view code image
string1 not equal to string2
string2 not equal to string1
Number Comparison
You can use the following operators to compare two numbers:
>=—Determines whether one number is greater than or equal to the other
number
<=—Determines whether one number is less than or equal to the other
number
>—Determines whether one number is greater than the other number
<—Determines whether one number is less than the other number
The next examples compare three numbers, number1, number2, and
number3, in a shell program called compare2:
Click here to view code image
#!/bin/tcsh
set number1=5