About
This article is about expansion in Bash.
An expansion is the replacement of a special token in your code by the result of the expansion during code execution.
It's performed on the command line after it has been split into words.
There are seven kinds of expansion performed:
- pathname expansion (globbing) - replace a glob expression by file name
- brace expansion {} - generate strings
- tilde expansion ~, - replace the tilde by a path (user home, print working directory, …)
- parameter expansion - replace the $ expression by a parameter value
- variable expansion - replace the $ expression by a variable value,
- arithmetic expansion, - perform arithmetic operation
- word splitting, splits a string into an array of words (token)
Order
The order of expansions is:
- brace expansion,
- tilde expansion,
- parameter expansion,
- variable expansion
- arithmetic expansion
- and command substitution (done in a left-to-right fashion),
- word splitting,
- and pathname expansion.
On systems that can support it, there is an additional expansion available:
- process substitution.
Word change
Expansions can be use to change the number of word (token) processed. See Shell - (Word | Token | Field)