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