1.“$变量名”或${变量名}代表获取变量的值
[root@localhost ~]# test=123
[root@localhost ~]# test="$test"456
[root@localhost ~]# echo $test
123456
#叠加变量 test,变量值变成了 123456
[root@localhost ~]# test=${test}789
[root@localhost ~]# echo $test
123456789
#再叠加变量 test,变量值编程了 123456789
2.如果是把命令的结果作为变量值赋予变量,则需要使用反引号或$()包含命令
[root@localhost ~]# test=$(date)
[root@localhost ~]# echo $test
2018 年 10 月 21 日 星期一 20:27:50 CST
3. "$((运算式))"或"$[运算式]"代表运算
[root@localhost ~]# aa=11
[root@localhost ~]# bb=22
[root@localhost ~]# ff=$(( $aa+$bb ))
[root@localhost ~]# echo $ff
33
#变量 ff 的值是 aa 和 bb 的和
[root@localhost ~]# gg=$[ $aa+$bb ]
[root@localhost ~]# echo $gg
33
#变量 gg 的值是 aa 和 bb 的和
4.特殊符号
bash中的特殊符号
网友评论