这是一个参数扩展,许多与${开始的一部分。
Like $ {parameter:-word},$ {parameter:= word},$ {parameter:?word},$ {parameter:+ word}等等。
这一个(专用于ksh,bash和zsh):${parameter:offset:length}从偏移处开始提取长度字符(可选,如果缺失,参数中字符串的其余部分)。随着bash手册中描述的几个细节。
${name:offset:length}
Substring Expansion. Expands to up to length characters of the value
of parameter starting at the character specified by offset. If parameter
is @, an indexed array subscripted by @ or *, or an associative
array name, the results differ as described below. If length is omitted,
expands to the substring of the value of parameter starting at the character
specified by offset and extending to the end of the value. length and
offset are arithmetic expressions (see ARITHMETIC EVALUATION below).
If offset evaluates to a number less than zero, the value is used as an
offset in characters from the end of the value of parameter. If length
evaluates to a number less than zero, it is interpreted as an offset in
characters from the end of the value of parameter rather than a number
of characters, and the expansion is the characters between offset and
that result. Note that a negative offset must be separated from the
colon by at least one space to avoid being confused with the :- expansion.
If parameter is @, the result is length positional parameters
beginning at offset. A negative offset is taken relative to one greater
than the greatest positional parameter, so an offset of -1 evaluates
to the last positional parameter. It is an expansion error if length
evaluates to a number less than zero.
If parameter is an indexed array name subscripted by @ or *, the result
is the length members of the array beginning with ${parameter[offset]}.
A negative offset is taken relative to one greater than the maximum
index of the specified array. It is an expansion error if length evaluates
to a number less than zero.
Substring expansion applied to an associative array produces undefined
results.
Substring indexing is zero-based unless the positional parameters
are used, in which case the indexing starts at 1 by default. If
offset is 0, and the positional parameters are used, $0 is prefixed
to the list.