← Back to Bash Course | Chapter 3: Control Flow | Lesson 7 of 14

Pipes

In this page:

  1. Pipes

Pipes

The pipe operator | connects the standard output of one command directly to the standard input of the next, letting you chain small commands into a data-processing pipeline. Bash runs both commands concurrently, streaming data between them. Pipelines are one of the most powerful and idiomatic features of shell scripting.

Note: Chain several pipes together, like cmd1 | cmd2 | cmd3, to build a multi-step data pipeline in one line.

Example: Pipes

bash
#!/bin/bash
printf "banana\napple\ncherry\n" | sort

echo "---"

printf "a\nb\nc\nd\n" | wc -l

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.