Views:
7,344β
Votes: 3β
Tags:
command-line
bash
redirect
Link:
π See Original Answer on Ask Ubuntu β§ π
URL:
https://askubuntu.com/q/861522
Title:
In what order does the shell execute commands and stream redirection?
ID:
/2016/12/17/In-what-order-does-the-shell-execute-commands-and-stream-redirection_
Created:
December 17, 2016
Upload:
September 15, 2024
Layout: post
TOC:
false
Navigation: false
Copy to clipboard: false
Itβs always left to rightβ¦ except when
Just like in Math we do left to right except multiplication and division is done before addition and subtraction, except operations inside parenthesis (+ -) would be done before multiplication and division.
As per the Bash beginners guide here (Bash Beginners Guide) there are 8 orders of hierarchy of what comes first (before left to right):
- Brace expansion β{}β
- Tilde expansion β~β
- Shell parameter and variable expression β$β
- Command substitution β$(command)β
- Arithmetic expression β$((EXPRESSION))β
- Process Substitution what we are talking about here β<(LIST)β or β>(LIST)β
- Word Splitting ββ< space>< tab>< newline>ββ
- File Name Expansion β*β, β?β, etc.
So itβs always left to rightβ¦ except whenβ¦