CentOS expr和let

1、expr,用于计算变量等

用法:expr 表达式

用例1:

#运算符号和参数之间要有空格分开
[es@bigdata-senior01 ~]$ expr 2 + 3 5
#乘号(*)需要用  ,"",''来转义
[es@bigdata-senior01 ~]$ expr 2 * 5
10
#中间表达式需要用反引号括起来
[es@bigdata-senior01 ~]$ expr `expr 2 + 3` * 5 25
或者用$()括起来
[es@bigdata-senior01 ~]$ expr $(expr 2 + 3) * 5
2

2、let命令,整数运算,与expr类似

与expr命令相比,let命令更简洁直观,计算速度更快

格式:let arg1 [arg2 ......] 
[ ]表示可以有多个参数,arg n (n=1,2…)
运算符与操作数据之间不必用空格分开,但表达式与表达式之间必须要用空格分开
当运算符中有<、>、&、|等符号时,同样需要用引号(单引号、双引号)或者斜杠来修饰运算符

用例1:

[es@bigdata-senior01 ~]$ let s=(3+3)*4
[es@bigdata-senior01 ~]$ echo $s
24
原文地址:https://www.cnblogs.com/asker009/p/10248695.html