About Shell Expansions
(this post if part of the material I cover in my devops course)
Shell Operation
Covered here in bash documentation.
- The shell reads its input from one of these:
- an input from a file
- from a string supplied as an argument to the -c invocation option
- from the user’s terminal
- Breaks the input into words and operators, obeying the quoting rules described in Quoting
- These words (called tokens) are separated by metacharacters (like space, tab, new-line |, & etc.).
- Alias expansion is performed by this step (see Aliases).
- It then parses the tokens into simple and compound commands
- NOW IT IS THE TIME OF EXPANSIONS where certain tokens are expanded to lists of filenames, or command arguments.
We'll later talk about the IFS variable that is part of the expansions phase. It is not used when the shell breaks the input to words (item 2. in this list) - redirections
- Command execution
Shell Expansions
- Expansion is performed on the command line after it has been split into tokens.
- There are seven kinds of expansion performed (and in this order):
- brace expansion
- tilde expansion
- parameter and variable expansion
- arithmetic expansion
- command substitution
- word splitting
- filename expansion
We'll cover these in the other posts.