Logical operators are used with conditional statements. These operators are used to negate a logical expression or to perform logical ands and ors:
! To negate a logical expression
&& To logically and two logical expressions
II To logically or two logical expressions
This example named logic uses the file and directory mentioned in the previous compare3 example.
#!/bin/tcsh if ( -x filel && -x dirl ) then echo filel and dirl are executable else echo at least one of filel or dirl are not executable endif if ( -w filel || -w dirl ) then echo filel or dirl are writable else echo neither filel or dirl are executable endif if ( ! -w filel ) then echo filel is not writable else echo filel is writable endif
If you execute logic, it will yield the following result:
filel and dirl are executable filel or dirl are writable filel is not writable
Was this article helpful?