0
0
Linux CLIscripting~10 mins

Pipe operator (|) in Linux CLI - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Pipe operator (|)
Command 1 runs
Output of Command 1
Pipe operator (|) passes output
Command 2 receives input
Command 2 runs and outputs result
The pipe operator (|) takes the output of the first command and sends it as input to the second command.
Execution Sample
Linux CLI
echo "apple banana cherry" | tr ' ' '\n'
This command sends a string to 'tr' which replaces spaces with new lines, splitting words vertically.
Execution Table
StepCommandActionOutputNext Input
1echo "apple banana cherry"Outputs string 'apple banana cherry'apple banana cherryPassed to tr
2tr ' ' '\n'Replaces spaces with new linesapple banana cherryDisplayed on screen
3EndNo more commandsProcess completeNo input
💡 Pipe ends after last command outputs result to screen
Variable Tracker
VariableStartAfter Step 1After Step 2Final
Output Streamemptyapple banana cherryapple banana cherryapple banana cherry
Key Moments - 2 Insights
Why does the output of the first command become the input of the second?
Because the pipe operator (|) connects the output stream of the first command directly to the input stream of the second command, as shown in execution_table step 1 and 2.
What happens if the first command produces no output?
The second command receives no input and may produce no output or behave differently, since the pipe passes exactly what the first command outputs.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the output after step 1?
A"apple\nbanana\ncherry"
Bempty
C"apple banana cherry"
D"apple, banana, cherry"
💡 Hint
Check the 'Output' column in row for step 1 in execution_table
At which step does the pipe operator pass data to the next command?
AStep 3
BStep 1
CStep 2
DNo step
💡 Hint
Look at the 'Next Input' column in execution_table for step 1
If the first command output was empty, how would the final output change?
ASecond command outputs nothing
BSecond command outputs original string
CSecond command outputs error
DNo change
💡 Hint
Refer to key_moments about empty output from first command
Concept Snapshot
Pipe operator (|) connects commands.
Output of first command becomes input of second.
Used to chain commands simply.
Example: echo "a b" | tr ' ' '\n'
Splits words into lines.
Full Transcript
The pipe operator (|) in Linux command line takes the output from one command and sends it as input to the next command. For example, 'echo "apple banana cherry" | tr ' ' '\n'' sends the string from echo to tr, which replaces spaces with new lines. Step 1 runs echo and outputs the string. Step 2 runs tr, receiving that string as input and outputs each word on a new line. The pipe allows chaining commands easily by passing data between them without saving to files. If the first command outputs nothing, the second command receives no input and may output nothing. This flow helps build powerful command sequences.