Pipelines

Learn how to combine several programs using a pipeline.

We'll cover the following

The redirection operators are useful when we save data for manual analysis or processing. When we want to process data with another program, storing them in temporary files is inconvenient. Managing these files takes extra effort. We should remember their paths and remove them after usage.

Unix provides an alternative solution for transferring text data: a pipeline. This mechanism shares data between programs by passing messages. It doesn’t use the file system.

How pipelines work

The following example demonstrates how pipelines work. Let’s suppose that we are looking for information about the Bash license. The Bash documentation has it. Therefore, we call the grep utility to parse documentation files this way:

grep -R "GNU" /usr/share/doc/bash

Another source of the Bash license information is the info help page. We can take this information and transfer it to the grep utility. The pipeline does this job. It takes the output of one program and sends it to the input of another one. The following command accomplishes this for info and grep programs:

info bash | grep -n "GNU"

Run the commands discussed in this lesson in the terminal below.

Get hands-on with 1200+ tech skills courses.