is, comparing values using characters representing NOT, AND, and OR:
!—Negates a logical expression
-a—Logically ANDs two logical expressions
-o—Logically ORs two logical expressions
This example named logic uses the file and directory mentioned in the
previous compare3 example:
Click here to view code image
#!/bin/sh
if [ -x file1 -a -x dir1 ]; then
echo file1 and dir1 are executable
else
echo at least one of file1 or dir1 are not executable
fi
if [ -w file1 -o -w dir1 ]; then
echo file1 or dir1 are writable
else
echo neither file1 or dir1 are executable
fi
if [ ! -w file1 ]; then
echo file1 is not writable
else
echo file1 is writable
fi
If you execute logic, it yields the following result:
Click here to view code image
file1 and dir1 are executable
file1 or dir1 are writable
file1 is not writable
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: