全部博文(1493)
分类:
2012-08-14 08:48:15
原文地址:在Shell中获取当前全路径 作者:bzzjg
In the parameter expansions shown previously, use of the colon in the format shall result in a test for a parameter that is unset or null; omission of the colon shall result in a test for a parameter that is only unset. The following table summarizes the effect of the colon:
|
parameter |
parameter |
parameter |
---|---|---|---|
|
Set and Not Null |
Set But Null |
Unset |
${parameter:-word} |
substitute parameter |
substitute word |
substitute word |
${parameter-word} |
substitute parameter |
substitute null |
substitute word |
${parameter:=word} |
substitute parameter |
assign word |
assign word |
${parameter=word} |
substitute parameter |
substitute null |
assign word |
${parameter:?word} |
substitute parameter |
error, exit |
error, exit |
${parameter?word} |
substitute parameter |
substitute null |
error, exit |
${parameter:+word} |
substitute word |
substitute null |
substitute null |
${parameter+word} |
substitute word |
substitute word |
substitute null |
In all cases shown with "substitute", the expression is replaced with the value shown. In all cases shown with "assign", parameter is assigned that value, which also replaces the expression.
${#parameter}String Length. The length in characters of the value of parameter shall be substituted. If parameter is '*' or '@', the result of the expansion is unspecified.The following four varieties of parameter expansion provide for substring processing. In each case, pattern matching notation (see Pattern Matching Notation), rather than regular expression notation, shall be used to evaluate the patterns. If parameter is '*' or '@', the result of the expansion is unspecified. Enclosing the full parameter expansion string in double-quotes shall not cause the following four varieties of pattern characters to be quoted, whereas quoting characters within the braces shall have this effect.
${parameter%word}Remove Smallest Suffix Pattern. The word shall be expanded to produce a pattern. The parameter expansion shall then result in parameter, with the smallest portion of the suffix matched by the pattern deleted.