Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
Shells: User's Guide: HP 9000 Computers > Chapter 17 Shell Grammar

Using Pipes

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Index

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:

who | sort

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.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-1991 Hewlett-Packard Development Company, L.P.