coreutils: Examples of expr
1
1 16.4.4 Examples of using ‘expr’
1 -------------------------------
1
1 Here are a few examples, including quoting for shell metacharacters.
1
1 To add 1 to the shell variable ‘foo’, in Bourne-compatible shells:
1
1 foo=$(expr $foo + 1)
1
1 To print the non-directory part of the file name stored in ‘$fname’,
1 which need not contain a ‘/’:
1
1 expr $fname : '.*/\(.*\)' '|' $fname
1
1 An example showing that ‘\+’ is an operator:
1
1 expr aaa : 'a\+'
1 ⇒ 3
1
1 expr abc : 'a\(.\)c'
1 ⇒ b
1 expr index abcdef cz
1 ⇒ 3
1 expr index index a
1 error→ expr: syntax error
1 expr index + index a
1 ⇒ 0
1