typeset也可以实现计算
[root@linhexiao shellTest]# typeset -i a=1 b=3 [root@linhexiao shellTest]# a=a+b [root@linhexiao shellTest]# echo $a 4 [root@linhexiao shellTest]# a=a*b [root@linhexiao shellTest]# echo $a 12
$[ ]也可以实现计算
1)只要式合法的表达式都可以计算 [root@linhexiao shellTest]# echo $[2+3] 5 [root@linhexiao shellTest]# echo $[2+ 3] 5 [root@linhexiao shellTest]# echo $[ 2+ 3] 5 2)$[]不可以计算小数 [root@linhexiao shellTest]# echo $[ 2.2+ 3] bash: 2.2+ 3: syntax error: invalid arithmetic operator (error token is ".2+ 3") [root@linhexiao shellTest]# echo $[ 2+ 3] 5 [root@linhexiao shellTest]# echo $[ 2- 3] -1 [root@linhexiao shellTest]# echo $[ 2* 3] 6 [root@linhexiao shellTest]# echo $[ 2** 3] 8 [root@linhexiao shellTest]# echo $[ 2/ 3] 0