|
Pipes
In Unix-like computer operating systems, a pipeline is the original software pipeline: a set of processes chained by their standard streams, so that the output of each process (stdout) feeds directly as input (stdin) of the next one. more...
Home
Knives, Swords & Blades
Militaria
Science Fiction
Tobacciana
Ashtrays
Cases
Cigar
Cigarette
Felts, Silks
Lighters
Match Holders
Other Tobacciana
Papers
Pipes
Estate
Other Pipes
Rollers, Makers
Signs
Tags
Tins
Tobacco Cards
Trading Cards
Transportation
Each connection is implemented by an anonymous pipe. Filter programs are often used in this configuration. The concept was invented by Douglas McIlroy for Unix shells and it was named by analogy to a physical pipeline.
Example
Below is an example of a pipeline that implements a kind of spell checker for the web resource indicated by a URL. An explanation of what it does follows. (Some machines have /usr/share/dict/words instead.)
First, curl obtains the HTML contents of a web page (could use wget on some systems).;
Second, sed this expression removes all characters which are not spaces or letters from the web page's content, replacing them with spaces.;
Third, tr changes all of the uppercase letters into lowercase and converts the spaces in the lines of text to newlines (each 'word' is now on a separate line).;
Fourth, grep includes only lines that contain at least one lowercase alphabetical character (removing any blank lines).;
Fifth, sort sorts the list of 'words' into alphabetical order, and the -u switch removes duplicates.;
Finally, comm finds lines in common between two files, -23 suppresses lines unique to the second file, and those which are common to both, leaving only those which are found only in the first file named. The - in place of a filename causes comm to use its standard input (from the pipe line in this case). This results in a list of "words" (lines) which are not found in /usr/dict/words.;
The special character "|" tells the operating system to pipe the output from the previous command in the line into the next command in the line. That is, the output of the curl command is given as the input of the sed command.;
The character "\" is used to place all five lines into a single command line.;
Pipelines in command line interfaces
Most Unix shells have a special syntax construct for the creation of pipelines. Typically, one simply writes the filter commands in sequence, separated by the ASCII vertical bar character "|" (which, for this reason, is often called "pipe character" by Unix users). The shell starts the processes and arranges for the necessary connections between their standard streams (including some amount of buffer storage).
Error stream
By default, the standard error streams ("stderr") of the processes in a pipeline are not passed on through the pipe; instead, they are merged and directed to the console. However, many shells have additional syntax for changing this behaviour. In the csh shell, for instance, using "|&" instead of "| " signifies that the standard error stream too should be merged with the standard output and fed to the next process. The Bourne Shell can also merge standard error, using 2>&1, as well as redirect it to a different file.
Read more at Wikipedia.org
|
|