Reference: expr
expr
expr arg1 operator
arg2 [ operator arg3 ... ]|&- :
Examples
expr 5 + 10 / 2
Addition happens first; result is 7 (truncated from 7.5):
expr \( 5 + 10 \) / 2
Add 1 to variable i;
this is how variables are incremented in shell scripts:
i=`expr $i + 1`
expr $a = hello
expr $b + 5 \>= 10
expr $p : '.*' Result is 11
expr $p : '\(.*\)' Result is "version.100"
Print the number of lowercase letters at the beginning of
p:
expr $p : '[a-z]*' Result is 7
Match the lowercase letters at the beginning of p:
expr $p : '\([a-z]*\)' Result is "version"
expr "$x" : '\(.....\)' \| "$x"
mv "$x" `expr "$x" : '\(.....\)' \| "$x"`





