尚硅谷大数据技术之Shell (新)第5章 运算符

5运算符

1.基本语法

(1)“$((运算式))”或“$[运算式]”

(2)expr  + , - , \*,  /,  %    加,减,乘,除,取余

注意:expr运算符间要有空格

2.案例实操:

(1)计算3+2的值

[atguigu@hadoop101 datas]$ expr 2 + 3

5

(2)计算3-2的值

[atguigu@hadoop101 datas]$ expr 3 - 2

1

(3)计算(2+3)X4的值

(a)expr一步完成计算

[atguigu@hadoop101 datas]$ expr `expr 2 + 3` \* 4

20

(b)采用$[运算式]方式

[atguigu@hadoop101 datas]# S=$[(2+3)*4]

[atguigu@hadoop101 datas]# echo $S