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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。