13.13. Arithmetic Expansion

 <  Day Day Up  >  

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")  

 <  Day Day Up  >  


UNIX Shells by Example
UNIX Shells by Example (4th Edition)
ISBN: 013147572X
EAN: 2147483647
Year: 2004
Pages: 454
Authors: Ellie Quigley

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net