linux中中括号[]用于取变量的值



1、

[root@rhel7pc1 test]# ls
[root@rhel7pc1 test]# echo $a

[root@rhel7pc1 test]# a=100
[root@rhel7pc1 test]# echo $a
100
[root@rhel7pc1 test]# b=a+50   
[root@rhel7pc1 test]# echo $b  ## 无法直接提取变量的值
a+50
[root@rhel7pc1 test]# c=$[a+50]
[root@rhel7pc1 test]# echo $c   ##利用中括号可以直接提取变量的值
150

补充:

[root@rhel7pc1 test]# echo $a
100
[root@rhel7pc1 test]# c=$a+50
[root@rhel7pc1 test]# echo $c
100+50

let实现:

[root@rhel7pc1 test]# a=100
[root@rhel7pc1 test]# echo $a
100
[root@rhel7pc1 test]# let b=a+50
[root@rhel7pc1 test]# echo $b
150