www.delorie.com/gnu/docs/textutils/coreutils_106.html   search  
 
Buy GNU books!


GNU Core-utils

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

16.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     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003