Pipes are connectors that join two
or more programs or commands together. A pipe allows you to take
the output of one program and use it as input to another program
without the use of intermediate files.
The metacharacter for the pipe is the vertical bar (|).
For example, suppose you want to list all the current users logged
into the system and then alphabetically sort them and print them
out. The command line reads:
In the following example, a list of people logged into a system
is produced by the who
command. That output is sent as input into the sort
command which outputs the sorted list of people on the system to
the display. For example:
$ who michael tty02 Oct 4 14:49 dave tty03 Oct 4 14:49 mary tty00 Oct 4 13:34 george tty04 Oct 4 14:49 keith tty05 Oct 4 14:49 $ who | sort dave tty03 Oct 4 14:49 george tty04 Oct 4 14:49 keith tty05 Oct 4 14:49 mary tty01 Oct 4 13:34 michael tty02 Oct 4 14:49 |
Two-Way Pipes |
 |
Two-way pipes or coprocesses
can be established between the shell and a job. The parent
process is the original shell and the child
process (or subprocess) is the job, the command or shell spawned
from the parent shell.
The standard input and output of the spawned command can be
written to and read from the parent shell in a two-way pipe. A two-way
pipe is created by placing the |&
metacharacter after the command to be executed. See Chapter 23 “Advanced Concepts and Commands” for details on
two-way pipes.