shell expr用法

expr 计算整数变量值

使用方法如下:

linux-zpycfm:/home/test/shell # s=expr 2+ 3
-bash: 2+: command not found
linux-zpycfm:/home/test/shell # s=expr 2+3
-bash: 2+3: command not found
linux-zpycfm:/home/test/shell # s=`expr 2 + 3`
linux-zpycfm:/home/test/shell # echo $s
5
linux-zpycfm:/home/test/shell # `expr 2 + 3`
-bash: 5: command not found
linux-zpycfm:/home/test/shell # expr 2 + 3
5
linux-zpycfm:/home/test/shell # expr 2+3
2+3
linux-zpycfm:/home/test/shell # expr $s * 4
expr: syntax error
linux-zpycfm:/home/test/shell # expr $s * 4
20
linux-zpycfm:/home/test/shell # expr `expr 2 + 3` * 4
20
linux-zpycfm:/home/test/shell # expr 2 "*" 3
6
linux-zpycfm:/home/test/shell # expr 2 '*' 3
6
linux-zpycfm:/home/test/shell # expr 2 * 3
expr: syntax error
linux-zpycfm:/home/test/shell # expr 2.3 + 3.4
expr: non-integer argument
运算符号和参数之间要有空格分开;
通配符号(*),在作为乘法运算符时要用、“”、‘’符号修饰
:expr 3 * 2         expr 3 “*” 2       expr 3 ‘*’ 2 
 `(反引号)与键盘上的~同一个键上的符号 
原文地址:https://www.cnblogs.com/xingmuxin/p/8950780.html