expr-evaluates arguments as an expression

 <  Day Day Up  >  

expr ” evaluates arguments as an expression

 expr arguments 

The arguments are taken as an expression. After evaluation, the result is written to the standard output. The terms of the expression must be separated by blanks. Characters special to the shell must be escaped. Used in Bourne shell scripts for performing simple arithmetic operations.

Example A.24.
 1   expr 5 + 4 2   expr 5 \* 3 3   num=0     num=`expr $num + 1` 

EXPLANATION

  1. Prints the sum of 5 + 4

  2. Prints the result of 5 * 3 . The asterisk is protected from shell expansion.

  3. After assigning to variable num , the expr command adds 1 to num and result is assigned to num .

 <  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