O'Reilly logo

Unix in a Nutshell, 4th Edition by Arnold Robbins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Expressions

Expressions are used in @ (the C shell math operator), if, and while statements to perform arithmetic , string comparisons, file testing, and so on. exit and set also specify expressions , as can the tcsh built-in command filetest. Expressions are formed by combining variables and constants with operators that resemble those in the C programming language. Operator precedence is the same as in C. It is easiest to just remember the following precedence rules:

  • * / %

  • + -

  • Group all other expressions inside ()s; parentheses are required if the expression contains <, >, &, or |

Operators

Operators can be one of the following types.

Assignment operators

Operator

Description

=

Assign value.

+= -=

Reassign after addition/subtraction.

*= /= %=

Reassign after multiplication/division/remainder.

&= ^= |=

Reassign after bitwise AND/XOR/OR.

++

Increment.

--

Decrement.

Arithmetic operators

Operator

Description

* / %

Multiplication; integer division; modulus (remainder).

+ -

Addition; subtraction.

Bitwise and logical operators

Operator

Description

~

Binary inversion (one's complement).

!

Logical negation.

<< >>

Bitwise left shift; bitwise right shift.

&

Bitwise AND.

^

Bitwise exclusive OR.

|

Bitwise OR.

&&

Logical AND (short-circuit).

||

Logical OR (short-circuit).

{ command }

Return 1 if command is successful, 0 otherwise. Note that this is the opposite of command 's normal return code. The $status variable may ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required