Previous Section  < Day Day Up >  Next Section

13.13. Arithmetic Expansion

The shell performs arithmetic expansion by evaluating an arithmetic expression and substituting the result. The expression is treated as if it were in double quotes and the expressions may be nested. For a complete discussion of arithmetic operations, and arithmetic evaluations, see "Arithmetic Operators and the let Command" on page 662.

There are two formats for evaluating arithmetic expressions:

FORMAT


$[ expression ]

$(( expression ))


Example 13.77.

echo $[ 5 + 4 - 2 ]

7

echo $[ 5 + 3 * 2]

11

echo $[(5 + 3) * 2]

16

echo $(( 5 + 4 ))

9

echo $(( 5 / 0 ))

bash: 5/0: division by 0 ( error token is "0")


    Previous Section  < Day Day Up >  Next Section