标签:shell
parameter相关知识${parameter:-word}:如果parameter为空或未定义,则变量展开为“word”;否则,展开为parameter的值;
${parameter:+word}:如果parameter为空或未定义,不做任何操作;否则,则展开为“word”值;否则什么都不做
${parameter:=word}:如果parameter为空或未定义,则变量展开为“word”,并将展开后的值赋值给parameter;
${parameter:offset}
${parameter:offset:length}:取子串,从offset处的后一个字符开始,取lenth长的子串;
-号
[root@feitian etc]# a=3
[root@feitian etc]# echo ${a:-30}
3
[root@feitian etc]# unset a
[root@feitian etc]# echo ${a:-30}
30
[root@feitian etc]# echo $a
+号
[root@feitian etc]# echo $a
#结果为空
[root@feitian etc]# echo ${a:+30}
#结果为空
[root@feitian etc]# a=1
[root@feitian etc]# echo ${a:+30}
30
=号
[root@feitian etc]# echo $a
1
[root@feitian etc]# echo ${a:=30}
1
[root@feitian etc]# echo $a
1
[root@feitian etc]# unset a
[root@feitian etc]# echo ${a:=30}
30
[root@feitian etc]# echo $a
30
变量赋值的相关内容
[root@feitian etc]# a="hello world"
[root@feitian etc]# echo ${a:2:3}
llo
[root@feitian etc]# echo ${a:2}
llo world
标签:shell
原文地址:http://blog.51cto.com/13132323/2073712