方法1:let 算术运算表达式
示例1:
[[email protected] Scripts]# A=2 [[email protected] Scripts]# B=3 [[email protected] Scripts]# let C=$A*$B [[email protected] Scripts]# echo $C 6 [[email protected] Scripts]#
方法2:$[算术运算表达式]
示例2:
[[email protected] Scripts]# echo $A 2 [[email protected] Scripts]# echo $B 3 [[email protected] Scripts]# C=$[$A+$B] [[email protected] Scripts]# echo $C 5 [[email protected] Scripts]#
方法3:$((算术运算表达式))
示例3:
[[email protected] Scripts]# echo $A 2 [[email protected] Scripts]# echo $B 3 [[email protected] Scripts]# D=$(($A-$B)) [[email protected] Scripts]# echo $D -1 [[email protected] Scripts]#
方法4:expr 算术运算表达式
注意:表达式中个操作数和操作符之间都要有空格,并且要使用反引号。
示例4:
[[email protected] Scripts]# echo $A 2 [[email protected] Scripts]# echo $B 3 [[email protected] Scripts]# E=`expr $A + $B` [[email protected] Scripts]# echo $E 5 [[email protected] Scripts]#
shell编程(五)--- 条件判断之算术运算
时间: 2024-10-05 02:46:11