Method 1: Let arithmetic expression
Example 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]#
Method 2: $ [arithmetic expression]
Example 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]#
Method 3: $ (arithmetic expression ))
Example 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]#
Method 4: expr arithmetic expression
Note: There must be spaces between the operands and operators in the expression, and anti-quotation marks must be used.
Example 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]#
This article is from the "Hezhang" blog, please be sure to keep this source http://hezhang.blog.51cto.com/1347601/1435416