next up previous contents
Next: UNIX Filters and searching Up: The UNIX C Shell Previous: Redirection of Output

Using Pipes

Redirection works fine if you only need to redirect streams to and from files, but if you need to chain commands together that read and write to the default file handles, then you need to use pipes. Pipes connect the stdout of one command to the stdin of the command that is next in the chain. As an example, suppose that you wish to concatenate three files, sort the contents of the files, then display the output a page at a time on the terminal screen:

cat file1 file2 file3 | sort | more

In this example, cat's stdout is piped into sort's stdin, and sort's stdout is piped into more's stdin. Since no pipe exists after the last command, output goes to the default stdout.

If you add an ampersand to the pipe operator ( tex2html_wrap_inline1470 ), stderr will also be redirected to the next command's stdin.



Larry Latour
Fri Sep 12 08:12:59 EDT 1997