1、linux系統中let命令在bash中用於計算,變量名前不用加$,可以實現自加和自減操作
簡單用法
[root@linuxprobe test]# a=3 [root@linuxprobe test]# echo $a 3 [root@linuxprobe test]# b=a+4 [root@linuxprobe test]# echo $b a+4 [root@linuxprobe test]# let b=a+4 ## let可以實現變量前不加$的計算 [root@linuxprobe test]# echo $b 7
2、自加、自減操作
[root@linuxprobe test]# a=3 [root@linuxprobe test]# echo $a 3 [root@linuxprobe test]# let a+=10 ## 自加操作 [root@linuxprobe test]# echo $a 13 [root@linuxprobe test]# let a-=20 ##自減操作 [root@linuxprobe test]# echo $a -7
3、let a++、a--
[root@linuxprobe test]# a=5;for i in `seq 10`;do echo -n "";let a++;done ##自加操作 [root@linuxprobe test]# echo $a 15 [root@linuxprobe test]# a=5;for i in `seq 20`;do echo -n "";let a--;done ##自減操作 [root@linuxprobe test]# echo $a -15