I want to make clear: When does pipe | or redirection < > take precedence in a command?
This is my thought but I need confirmation this is how it works.
Example 1:
sort < names | head
The pipe runs first: names|head then it sorts what is returned from names|head
Example 2:
ls | sort > out.txt
This one seems straight forward by testing, ls|sort then redirects to out.txt
Example 3:
Fill in the blank? Can you have both a < and a > with a | ???
In terms of syntactic grouping,
>and<have higher precedence; that is, these two commands are equivalent:as are these two:
But in terms of sequential ordering,
|is performed first; so, this command:will populate
out1.txt, notout2.txt, because the> out1.txtis performed after the|, and therefore supersedes it (so no output is piped out tocat > out2.txt).Similarly, this command:
will print
in2.txt, notin1.txt, because the< in2.txtis performed after the|, and therefore supersedes it (so no input is piped in fromcat < in1.txt).