< Day Day Up > |
There is not really a need to do math problems in a shell script, but sometimes arithmetic is necessary, for instance, to increment or decrement a loop counter. The C shell supports integer arithmetic only. The @ symbol is used to assign the results of calculations to numeric variables . 10.3.1 Arithmetic OperatorsThe following operators shown in Table 10.1 are used to perform integer arithmetic operations. They are the same operators as found in the C programming language. See Table 10.6 on page 538 for operator precedence. Also borrowed from the C language are shortcut assignment operators, shown in Table 10.2. Example 10.5.1 % @ sum = 4 + 6 echo $sum 10 2 % @ sum++ echo $sum 11 3 % @ sum += 3 echo $sum 14 4 % @ sum-- echo $sum 13 5 % @ n = 3+4 @: Badly formed number Table 10.1. Integer Arithmetic Operators
Table 10.6. Operator Precedence
Table 10.2. Shortcut Operators
EXPLANATION
|