Skip to content

运算符

基本语法

shell
 “$((运算式))”或“$[运算式]”
 expr  + , - , \*,  /,  %    加,减,乘,除,取余

注意:

expr运算符间要有空格

案例实操:

(1)计算3+2的值

shell
[root@centos7 sh]# expr 2 + 3
5

(2)计算3-2的值

shell
[root@centos7 sh]# expr 3 - 2 
1

(3)计算(2+3)X4的值 (a)expr一步完成计算

shell
[root@centos7 sh]# expr `expr 2 + 3` \* 4
20

(3)计算(2+3)X4的值 (b)采用$[运算式]方式

shell
[root@centos7 sh]# S=$[(2+3)*4]
[root@centos7 sh]# echo $S