Bash Expansions
Explore the various Bash expansions and their order of execution to enhance your shell scripting skills. Learn how brace, tilde, parameter, arithmetic, and command substitutions work, including handling variable ambiguities and default values. This lesson equips you to use Bash expansions confidently for effective script automation.
We'll cover the following...
We'll cover the following...
Bash expansions
The following illustration shows a few bash expansions.
The following table gives the full picture of Bash expansions. It lists all of them and specifies their order of execution.
| Order of Execution | Expansion | Description | Example |
|---|---|---|---|
| 1 | Brace Expansion | It generates a set of strings by the specified pattern with braces. | echo a{d,c,b}e |
| 2 | Tilde Expansion | Bash replaces the tilde with the value of the HOME variable. |
cd ~ |
| 3 | Parameter Expansion | Bash replaces parameters and variables by their values. | echo "$PATH" |
| 4 | Arithmetic Expansion | Bash replaces |