標籤:let expr $[ ]
方法1:let 算術運算運算式
樣本1:
[[email protected] Scripts]# A=2[[email protected] Scripts]# B=3[[email protected] Scripts]# let C=$A*$B[[email protected] Scripts]# echo $C6[[email protected] Scripts]#
方法2:$[算術運算運算式]
樣本2:
[[email protected] Scripts]# echo $A2[[email protected] Scripts]# echo $B3[[email protected] Scripts]# C=$[$A+$B][[email protected] Scripts]# echo $C5[[email protected] Scripts]#
方法3:$((算術運算運算式))
樣本3:
[[email protected] Scripts]# echo $A2[[email protected] Scripts]# echo $B3[[email protected] Scripts]# D=$(($A-$B))[[email protected] Scripts]# echo $D-1[[email protected] Scripts]#
方法4:expr 算術運算運算式
注意:運算式中個運算元和操作符之間都要有空格,並且要使用反引號。
樣本4:
[[email protected] Scripts]# echo $A2[[email protected] Scripts]# echo $B3[[email protected] Scripts]# E=`expr $A + $B`[[email protected] Scripts]# echo $E5[[email protected] Scripts]#
本文出自 “HeZhang” 部落格,請務必保留此出處http://hezhang.blog.51cto.com/1347601/1435416