next up previous contents index
Next: Shell Scripts Up: UNIX Shells Previous: Standard InputOutput

Pipes

  UNIX uses the concept of a pipe  to connect the standard output of one program directly into the standard input of another program. This is specified by separating the two commands with the pipe operator, the vertical bar ( ). The general format is:

 
               		   command1      command2    ...

For example, to sort the output of the who command:
 
               		  who  sort

Of course, each command can have options and arguments.

The tee command   can be used to send output to a file as well as to another command.

 
               		  who  tee  whoout  sort

This is the same as the previous example except that a file named whoout is created containing the original who output. The sorted output goes to standard output, the terminal screen.

It is possible to set up multiple pipes. Commands that appear in pipe statements may include all the usual options and file designations.

 
               		  ls -l | lp

This command pipes the output of the ls command to the printer via the lp command.



Alan Silverman
Wed Apr 12 16:54:02 METDST 1995