[Next] [Previous] [Up] [Top] [Contents]

9.9 Control Commands

9.9.7 C Shell Logical and Relational Operators

The C shell has its own set of built-in logical and relational expression operators. In descending order of precedence they are:

(...) group expressions with ()

~ inversion (one's complement)

! logical negation

*, /, % multiply, divide, modulus

+, - add, subtract

<<, >> bitwise shift left, bitwise shift right

<= less than or equal

>= greater than or equal

< less than

> greater than

== equal

!= not equal

=~ match a string

!~ don't match the string

& bitwise AND

^ bitwise XOR (exclusive or)

| bitwise OR

&& logical AND

|| logical OR

{command} true (1) if command terminates with a zero exit status, false (0) otherwise.

The C shell also allows file type and permission inquiries with the operators:

-r return true (1) if it exists and is readable, otherwise return false (0)

-w true if it exists and is writable

-x true if it exists and is executable

-f true if it exists and is a regular file (or for csh, exists and is not a directory)

-d true if it exists and is a directory

-e true if the file exists

-o true if the user owns the file

-z true if the file has zero length (empty)


Introduction to Unix - 14 AUG 1996
[Next] [Previous] [Up] [Top] [Contents]