Comparing Expressions with tcsh
As stated earlier, the method for comparing expressions in tcsh
is different from the method used under pdksh
and bash
. The comparison of expression demonstrated in this section uses the syntax necessary for the tcsh
shell environment.
String Comparison
You can use the following operators to compare two string expressions:
• ==
—To compare whether two strings are equal
• !=
—To compare whether two strings are not equal
The following examples compare two strings, string1
and string2
, in the shell program compare1
:
#!/bin/tcshset string1 = "abc"set string2 = ""abd"if (string1 == string2) then echo "string1 equal to string2"else echo ""string1 not equal to string2"endifif (string2 != string1) then echo ""string2 ...
Get Ubuntu Unleashed 2013 Edition: Covering 12.10 and 13.04, Eighth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.