40.2.1.1 Variable Substitution
Variable substitution happens when a `$' prefixed word is found
in a command. There are three types of variable substitution:
$
name
- where name is a scalar variable. name is simply substituted
in the word for its value. name can contain only letters,
digits, or underscores.
$
name(
index)
- where name is the name of an array variable and index is the
index into it. This is substituted by the value of the array element.
name must contain only letters, digits, or underscores.
index has variable, command, and backslash substitution performed
on it too.
${
name}
- where name can have any characters in it except closing curly
bracket. This is more or less the same as
$
name
substitution except it is used to get around the restrictions in the
characters that can form name.
An example of variable substitution is:
set a 1
set b $a
which sets the value of variable a
to 1
, and then sets the value
of variable b
to the value of variable a
.