[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The `$' character introduces parameter expansion, command substitution, or arithmetic expansion. The parameter name or symbol to be expanded may be enclosed in braces, which are optional but serve to protect the variable to be expanded from characters immediately following it which could be interpreted as part of the name.
When braces are used, the matching ending brace is the first `}' not escaped by a backslash or within a quoted string, and not within an embedded arithmetic expansion, command substitution, or parameter expansion.
The basic form of parameter expansion is ${parameter}. The value of parameter is substituted. The braces are required when parameter is a positional parameter with more than one digit, or when parameter is followed by a character that is not to be interpreted as part of its name.
If the first character of parameter is an exclamation point,
a level of variable indirection is introduced.
Bash uses the value of the variable formed from the rest of
parameter as the name of the variable; this variable is then
expanded and that value is used in the rest of the substitution, rather
than the value of parameter itself.
This is known as indirect expansion
.
The exception to this is the expansion of ${!prefix*}
described below.
In each of the cases below, word is subject to tilde expansion, parameter expansion, command substitution, and arithmetic expansion.
When not performing substring expansion, Bash tests for a parameter that is unset or null; omitting the colon results in a test only for a parameter that is unset. Put another way, if the colon is included, the operator tests for both existence and that the value is not null; if the colon is omitted, the operator tests only for existence.
${parameter:-word}
${parameter:=word}
${parameter:?word}
${parameter:+word}
${parameter:offset}
${parameter:offset:length}
length must evaluate to a number greater than or equal to zero.
If offset evaluates to a number less than zero, the value
is used as an offset from the end of the value of parameter.
If parameter is `@', the result is length positional
parameters beginning at offset.
If parameter is an array name indexed by `@' or `*',
the result is the length
members of the array beginning with ${parameter[offset]}
.
Substring indexing is zero-based unless the positional parameters
are used, in which case the indexing starts at 1.
${!prefix*}
IFS
special variable.
${#parameter}
${parameter#word}
${parameter##word}
${parameter%word}
${parameter%%word}
${parameter/pattern/string}
${parameter//pattern/string}
The pattern is expanded to produce a pattern just as in
filename expansion.
Parameter is expanded and the longest match of pattern
against its value is replaced with string.
In the first form, only the first match is replaced.
The second form causes all matches of pattern to be
replaced with string.
If pattern begins with `#', it must match at the beginning
of the expanded value of parameter.
If pattern begins with `%', it must match at the end
of the expanded value of parameter.
If string is null, matches of pattern are deleted
and the /
following pattern may be omitted.
If parameter is `@' or `*',
the substitution operation is applied to each positional
parameter in turn, and the expansion is the resultant list.
If parameter
is an array variable subscripted with `@' or `*',
the substitution operation is applied to each member of the
array in turn, and the expansion is the resultant list.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |