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 
 `(反引号)与键盘上的~同一个键上的符号 

 

相关文章:

  • 2021-07-06
  • 2021-11-20
  • 2022-12-23
  • 2021-09-14
  • 2022-12-23
  • 2022-02-27
  • 2021-10-11
  • 2021-12-09
猜你喜欢
  • 2022-12-23
  • 2021-07-04
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-07
相关资源
相似解决方案