Pipelines
Pipelines, often called pipes, is a way to chain commands and connect output from one command to the input of the next.
Pipelines, often called pipes, is a way to chain commands and connect output from one command to the input of the next. A pipeline is represented by the pipe character: |. It’s particularly handy when a complex or long input is required for a command.
command1 | command2By default pipelines redirects only the standard output, if you want to include the standard error you need to use the form |& which is a short hand for 2>&1 |.
Example:#
Imagine you quickly want to know the number of entries in a directory, you can use a pipe to redirect the output of the ls command to the wc command with option -l.
ls / | wc -lThen you want to see only the first 10 results
ls / | headNote: head outputs the first 10 lines by default, use option -n to change this behavior
Try it
Expected output
4Solution
#!/bin/bash
cat /proc/cpuinfo | grep processor | wc -lGet the Bash agent pack
A battle-tested AGENTS.md, the review checklist, and the failure-mode cheat sheet for Bash. One email, then occasional updates when the tooling shifts. No course pitch.
AGENTS.md now — no email needed.