11.3. Arithmetic

There is not really a need to do math problems in a shell script, but sometimes arithmetic is necessary, e.g., to increment or decrement a loop counter. The TC shell supports integer arithmetic only. The @ symbol is used to assign the results of calculations to numeric variables.

11.3.1. Arithmetic Operators

The following operators in Table 11.1 are used to perform integer arithmetic operations. They are the same operators found in the C programming language. See Table 11.6 on page 629 for operator precedence. Also borrowed from the C language are shortcut assignment operators, shown in Table 11.2.

Table 11.1. Operators
Function Operator
Addition +
Subtraction
Division /
Multiplication *
Modulus %
Left shift ...

Get Linux Shells by Example 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.