Parameter related knowledge
${parameter:-word}: If parameter is empty or undefined, the variable is expanded to "word"; otherwise, the value of parameter is expanded; ${parameter:+word}: If parameter is empty or undefined, do nothing; otherwise, expand to "word" value; ${parameter:=word}: If parameter is empty or undefined, the variable is expanded to Word and the expanded value is assigned to Parameter;${parameter : Offset}${parameter:offset:length}: Take a substring, starting at offset at the next character, take lenth long substring;-[[Email protected] etc]# a=3 [[email& Nbsp;protected] etc]# Echo ${a:-30} 3 [[email protected] etc]# unset A [[email protected] etc]# Echo ${ A:-30} [[email protected] etc]# echo $a + [[email protected] etc]# echo $a #结果为空 [[email Protected] etc]# echo ${a:+30} #结果为空 [[email protected] etc]# a=1 [[email protected] etc]# Echo ${a:+30 } 30= [[email protected] etc]# echo $a 1 [[email protected] etc]# Echo ${a:=30} 1 [[Email&nbs P;protected] etc]# echo $a 1 [[email protected] etc]# unset A [[email protected] etc]# Echo ${a:=30} [[email protected] etc]# echo $a 30 variable assignment relatedcontent [[email protected] etc]# a= "Hello World" [[email protected] etc]# Echo ${a:2:3} llo [[email Protected] etc]# echo ${a:2} Llo World
Variable assignment for shell scripts