(Pipe): Communicates Between Processes

 < Day Day Up > 

| (Pipe): Communicates Between Processes

Because pipes are integral to the functioning of a Linux system, they are introduced here for use in examples. Pipes are covered in detail on page 122.

A process is the execution of a command by Linux (page 292). Communication between processes is one of the hallmarks of UNIX/Linux. A pipe (written as a vertical bar, |, on the command line and appearing as a solid or broken vertical line on keyboards) provides the simplest form of this kind of communication. Simply put, a pipe takes the output of one utility and sends that output as input to another utility. Using UNIX/Linux terminology, a pipe takes standard output of one process and redirects it to become standard input of another process. (See page 113 for more information on standard input and output.) Most of what a process displays on the screen is sent to standard output. If you do not redirect it, this output appears on the screen. Using a pipe, you can redirect the output so that it becomes instead standard input of another utility. A utility such as head can take its input from a file whose name you specify on the command line following the word head, or it can take its input from standard input. For example, you can give the command shown in Figure 3-5 on page 49 as follows:

 $ cat months | head Jan Feb Mar Apr May Jun Jul Aug Sep Oct 

The next command displays the first line of the months file:

 $ cat months | head -1 Jan 

You can use a pipe to send output of a program to the printer:

 $ tail months | lpr 

     < Day Day Up > 


    A Practical Guide to LinuxR Commands, Editors, and Shell Programming
    A Practical Guide to LinuxR Commands, Editors, and Shell Programming
    ISBN: 131478230
    EAN: N/A
    Year: 2005
    Pages: 213

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net