10.4.1 The Stages of Word Expansion
When word expansion is applied to a sequence of words, it performs the
following transformations in the order shown here:
- Tilde expansion: Replacement of ‘~foo’ with the name of
the home directory of ‘foo’.
- Next, three different transformations are applied in the same step,
from left to right:
- Variable substitution: Environment variables are substituted for
references such as ‘$foo’.
- Command substitution: Constructs such as ‘`cat foo`’ and
the equivalent ‘$(cat foo)’ are replaced with the output from
the inner command.
- Arithmetic expansion: Constructs such as ‘$(($x-1))’ are
replaced with the result of the arithmetic computation.
- Field splitting: subdivision of the text into words.
- Wildcard expansion: The replacement of a construct such as ‘*.c’
with a list of ‘.c’ file names. Wildcard expansion applies to an
entire word at a time, and replaces that word with 0 or more file names
that are themselves words.
- Quote removal: The deletion of string-quotes, now that they have
done their job by inhibiting the above transformations when appropriate.
For the details of these transformations, and how to write the constructs
that use them, see The BASH Manual (to appear).