Linux Shell parameter substitution
2013-06-03 10:01 by Xuan Blade, 1816 Read, 0 reviews, Favorites, compilation
Bash in theCharacterNo.OfForUseIsParameterNumberForChange,WillParameterNumberNameForChangeForParameterNumberTheGenerationTableOf value < Span style= "font-family:stixgeneral, ' Arial Unicode MS ', serif; font-size:90%; Font-style:normal; Font-weight:normal; " > to on
, the curly braces are optional, i.e.A and
{A} represents the same parameter.
${} There are several expressions with colons: ${parameter:-word}
If parameter is null or not set, the entire parameter substitution expression value is word
${parameter:=word}
If parameter is null or not set, the entire parameter substitution expression value is word, and the parameter parameter value is set to Word
${parameter:?word}
If parameter is null or not set, an error message is printed. Otherwise, the entire parameter substitution expression value is $parameter
${parameter:+word}
If parameter is not NULL or not set, the entire parameter substitution expression value is word
${parameter:offset}${parameter:offset:length}
A substring of the value of the parameter.
Here are some examples to understand:
${} band! There are several expressions: ${!prefix*}${[email protected]}
Prints the name of the parameter with the prefix prefix
${!name[@]}${!name[*]}
This is for the name array, which prints out what subscript the name array has
Here are some examples to understand:
${} Several expressions with regular matches: ${parameter#word}${parameter# #word}
Scan Word from the beginning to filter out characters that match the word's regular expression
#为最短匹配, # #为最长匹配
${parameter%word}${parameter%%word}
Scan Word from the end to filter out characters that match the word regular expression
% is the shortest match and the percent is the longest match
Here are some examples to understand:
${parameter/pattern/string}${parameter//pattern/string}
Replace the pattern string of the parameter corresponding value with a string string
/means replace only once
means replace All
Here are some examples to understand:
Linux Shell parameter substitution