If you execute the file compare3, you get the following results:
Click here to view code image
dir1 is a directory
file1 is a regular file
file1 has read permission
file1 does not have write permission
dir1 has execute permission
file1 has greater than zero length
Logical Operators
You use logical operators with conditional statements. You use the following
operators to negate a logical expression or to perform logical ANDs and ORs:
!—Negates a logical expression
&&—Logically ANDs two logical expressions
||—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/tcsh
if ( -x file1 && -x dir1 ) then
echo file1 and dir1 are executable
else
echo at least one of file1 or dir1 are not executable
endif
if ( -w file1 || -w dir1 ) then
echo file1 or dir1 are writable
else
echo neither file1 or dir1 are executable
endif
if ( ! -w file1 ) then
echo file1 is not writable
else
echo file1 is writable
endif
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