3.6. Pipelines

In addition to the redirection operators, there is one additional operator which gives control over how input and output are handled. The operator is a pipeline, "|". Pipelines allow the standard output of one command to be used as the standard input to another command. This is almost equivalent to running the first command with its output redirected to a temporary file, then running the second command with its input redirected from the temporary file, then removing the temporary file. Pipelines make useful "filter" processes where the output of one command can be sent to another command which filters the output to whatever parameters you give the second command. As an example, you could display all the filenames with the character "a" in their name:


[1]% echo foo > file1
[2]% echo abc >> file1
[3]% echo aabc >> file1
[4]% echo GNO >> file1
[5]% echo standard >> file1
[6]% echo oof >> file1
[7]% cat file1
foo
abc
aabc
GNO
standard
oof
[8]% cat file1 | grep 'a'
abc
aabc
standard

Pipelines are useful when you wish to view lines of text in a file that contain a phrase, or if you want to connect two programs directly, bypassing intermediate files. It is also possible to connect multiple commands with multiple pipelines.

Pipelines are frequently used for paging output. The coff program mentioned previously prints the output of an OMF disassembly to the screen but does not pause when a key is pressed. In order to pause the display, the output must be piped through a paging utility. The ORCA shell requires that you wait for the entire command to complete execution before the pipeline is processed. However, GNO/ME executes both commands concurrently which allows the coff utility to execute while the paging utility displays the program output. GNO/ME comes with two page utilities, more and less. Complete desciptions of coff, more, and less can be found in the electronic manual using the man command.