Mathematical Operations

You can do mathematical operations only on integers (whole numbers) for all three shells. If you want to do more complicated arithmetic, use the awk or the bc command.

To perform mathematical operations in the Bourne shell, use the expr command. The expr command has the following syntax.

expr arguments
					

You must separate the mathematical operators (shown in Table 98) and the operand with white space.

Table 98. Mathematical Operators
Operator Description
+ Addition.
- Subtraction.
* Multiplication.
/ Division.
% Remainder (modulus).

The multiplication, division, and remainder operators have higher precedence than do the addition or subtraction operators. Use parentheses for grouping.

Bourne Shell Mathematical Operations ...

Get Solaris™ 8 Advanced System Administrator's Guide, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.