Redirection (computing): Difference between revisions

Content deleted Content added
m Replaces obsolete tag.
Lahwaacz (talk | contribs)
Line 102:
To write both errors and standard output to ''file'', the order should be reversed. Standard output would first be redirected to the file, then stderr would additionally be redirected to the stdout handle that has already been changed to point at the file: <syntaxhighlight lang="bash" inline>command > file 2>&1</syntaxhighlight>.
 
==Chained pipelines==
The redirection and piping tokens can be chained together to create complex commands. For example, <syntaxhighlight lang="bash" inline>sort infile | uniq -c | sort -n > outfile</syntaxhighlight> sorts the lines of {{mono|infile}} in lexicographical order, writes unique lines prefixed by the number of occurrences, sorts the resultant output numerically, and places the final output in {{mono|outfile}}. This type of construction is used very commonly in [[shell script]]s and [[batch file]]s.