linux系统中let命令

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

 

posted @ 2020-10-13 22:01  小鲨鱼2018  阅读(1199)  评论(0编辑  收藏  举报