Revise "Piping" section

This commit is contained in:
Matthew Dutson 2021-01-12 17:24:23 -06:00
parent 0136db0a22
commit 480f7fdb37

View file

@ -280,24 +280,19 @@ For example, ``echo hello 2> output.stderr`` writes the standard error (file des
Piping Piping
------ ------
Another way to redirect streams is a *pipe*. This connects streams with each other, usually the standard output of one command with the standard input of another. Another way to redirect streams is a *pipe*. A pipe connects streams with each other. Usually the standard output of one command is connected with the standard input of another. This is done by separating commands with the pipe character ``|``. For example::
This is done by separating the commands by the pipe character ``|``. For example
::
cat foo.txt | head cat foo.txt | head
will call the ``cat`` program with the parameter 'foo.txt', which will print the contents of the file 'foo.txt'. The contents of foo.txt will then be sent to the 'head' program, which will write the first few lines it reads to its output - the screen. The command ``cat foo.txt`` sends the contents of ``foo.txt`` to stdout. This output is provided as input for the ``head`` program, which prints the first 10 lines of its input.
It is possible to use a different output file descriptor by prepending its FD number and then output redirect symbol to the pipe. For example:: It is possible to pipe a different output file descriptor by prepending its FD number and the output redirect symbol to the pipe. For example::
make fish 2>| less make fish 2>| less
will attempt to build ``fish``, and any errors will be shown using the ``less`` pager. [#]_ will attempt to build ``fish``, and any errors will be shown using the ``less`` pager. [#]_
As a convenience, the pipe ``&|`` redirects both stdout and stderr to the same process. (Note this is different from bash, which uses ``|&``). As a convenience, the pipe ``&|`` redirects both stdout and stderr to the same process. Note that this is different from bash, which uses ``|&``.
.. [#] A "pager" here is a program that takes output and "paginates" it. ``less`` doesn't just do pages, it allows arbitrary scrolling (even back!). .. [#] A "pager" here is a program that takes output and "paginates" it. ``less`` doesn't just do pages, it allows arbitrary scrolling (even back!).