Variable expansion Modifiers (parameter expansion)

Modifier

Value

${variable:–word}

If variable is set and is non-null, substitute its value; otherwise, substitute word.

${variable:=word}

If variable is set or is non-null, substitute its value; otherwise, set it to word. The value of variable is substituted permanently. Positional parameters may not be assigned in this way.

${variable:+word}

If variable is set and is non-null, substitute word; otherwise, substitute nothing.

${variable:?word}

If variable is set and is non-null, substitute its value; otherwise, print word and exit from the shell. If word is omitted, the message parameter null or not set is printed.

${variable:offset}

Gets the substring of the value in variable starting at offset, where offset starts at 0 to the end of the string.

${variable:offset:length}

Gets the substring of the value in variable starting at offset, length characters over.


Using the colon with any of the modifiers (–, =, +, ?) checks whether the variable is not set or is null; without the colon, a variable set to null is considered to be set.

你可能感兴趣的:(null,Parameters)