如果数字以0开头的linux的bash默认会给转换成八进制
[root@local-test-node1 ~]# a=08 [root@local-test-node1 ~]# b=0$(($a+1)) -bash: 08: value too great for base (error token is "08") [root@local-test-node1 ~]# b=$(($a+1)) -bash: 08: value too great for base (error token is "08") [root@local-test-node1 ~]# b=$((08+1)) -bash: 08: value too great for base (error token is "08")
解决办法如下
[root@local-test-node1 ~]# b=$((10#08+1)) [root@local-test-node1 ~]# echo $b 9
[root@local-test-node1 ~]# b=0$((8#$a+1)) -bash: 8#08: value too great for base (error token is "8#08") [root@local-test-node1 ~]# b=0$((10#$a+1)) [root@local-test-node1 ~]# echo $b 09