www.delorie.com/gnu/docs/sh-utils/sh-utils_30.html   search  
 
Buy GNU books!


GNU shell utilities

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.4.4 Examples of using expr

Here are a few examples, including quoting for shell metacharacters.

To add 1 to the shell variable foo, in Bourne-compatible shells:
 
foo=`expr $foo + 1`

To print the non-directory part of the file name stored in $fname, which need not contain a /.
 
expr $fname : '.*/\(^.*\)' '^|' $fname

An example showing that \+ is an operator:
 
expr aaa : 'a\+'
=> 3

 
expr abc : 'a\(.\)c'
=> b
expr index abcdef cz
=> 3
expr index index a
error--> expr: syntax error
expr index quote index a
=> 0


  webmaster   donations   bookstore     delorie software   privacy  
  Copyright © 2003   by The Free Software Foundation     Updated Jun 2003