declare -/+ 选项 变量名
- 设类型
+ 取消类型
-i 设为整型
-x 设为环境变量
-p 显示类型属性(property)
[root@localhost ~]# a=
[root@localhost ~]# declare -p a
declare -- a=""
[root@localhost ~]# export a
[root@localhost ~]# declare -p a
declare -x a=""
[root@localhost ~]# declare -i a
[root@localhost ~]# declare -p a
declare -ix a=""
[root@localhost ~]# b=
[root@localhost ~]# c=$a+$b
[root@localhost ~]# echo $c
+
[root@localhost ~]# declare -i d=$a+$b
[root@localhost ~]# echo $d [root@localhost ~]# e=$(expr $a + $b)
[root@localhost ~]# echo $e [root@localhost ~]# f=$(($a+$b))
[root@localhost ~]# echo $f [root@localhost ~]# g=$(expr $a+$b)
[root@localhost ~]# echo $g
+
[root@localhost ~]# h=$[$a+$b]
[root@localhost ~]# echo $h
变量测试与内容替换
[root@localhost ~]# x=${y-new}
[root@localhost ~]# echo $x
new
[root@localhost ~]# y=""
[root@localhost ~]# x=${y-new}
[root@localhost ~]# echo $x [root@localhost ~]# y=
[root@localhost ~]# x=${y-new}
[root@localhost ~]# echo $x