- Brace expansions
- Parameter expansions
- Command substitutions
- Filename generation (globs)
Table of Expansion Types
For an in-depth reference, see the Bash manual on Shell Expansions.
1. Brace Expansion
Brace expansion quickly generates arbitrary strings. It’s purely a string generation mechanism—no variables or globs involved.Brace expansions must not be quoted for the shell to recognize them. For example,
echo "{A,B}" will literally output {A,B}.2. Parameter Expansion
Parameter expansion lets you inspect or transform variable values without invoking external commands.Basic Variable Expansion
Removing Directory Components
To strip the longest matching prefix (e.g., remove everything up to the last slash), use##*/:
Always quote your expansions (e.g.,
"${var}") to prevent word splitting and globbing in unexpected ways.