Describe expr statement with example.
The expr command is used to evaluate an arithmetic expression from the command line.
The expr command can be used to perform arithmetic operations, comparison operations and string operations. The following table specify the way how to use the different operators with expr command in shell and their meaning. Most of the operators are escaped with backslash as these operators are shell built in operators and having specific meaning for example < and > are redirection operators.
Syntax: expr operator value2
Example :
$ expr 1 + 2
3
$ expr 5 \* 2
10
$
$ y= ‘expr 7+9’
$ echo $y
16
$ a=10; b=17
$ c=’expr $a * $b’
$ echo $c
170
$ expr 5 “*” 10
50