Pcornel
Browse topics
Options
Recent
Favorites
Automation · Technical reference

Pipes

Direct answer

Pipes in Bash send one command's output to the next, such as journalctl -u nginx | grep error | wc -l. Use set -o pipefail so a failure anywhere in the pipe is detected.

When to use this

Use this when chaining commands with pipes.

First 30 seconds

1. Pipes connect stdout to stdin.

2. pipefail makes pipeline fail if any command fails.

3. PIPESTATUS for details.

4. Pipes run in subshells.

5. Keep pipelines readable.

Operational verification

cmd1 stdout → cmd2 stdin

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
GNU Bash shell automation
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformGNU Bash shell automation · Automation implementations are tool and platform specific. Use the adjacent Domain for the technology being automated and this Domain for automation behavior.
Scope / prerequisiteUse this when chaining commands with pipes.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Verification path Verify boundary

The negative fixture should deliberately exercise risks such as unquoted expansion, globbing, pipeline status loss, subshell scope, set -e misconceptions, signal races, temporary-file leakage and destructive path ambiguity, choosing the cases most relevant to producer/consumer process boundaries, buffering, exit status for each command, stderr separation and avoiding silent failure of non-final pipeline commands.

Step 2 Common mistakes Narrow the fault
  • Missing pipefail, so failed pipelines return 0.
  • Useless cat file | grep.
Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points
  • set -o pipefail makes a failure anywhere fail the pipe.
  • Each pipe stage runs in a subshell.
  • Variables set inside a pipe do not survive it.
Key checks
  • set -o pipefail — pipeline failures detected
  • cmd1 | cmd2; echo "${PIPESTATUS[@]}" — per-command status
  • Avoid useless cat — efficiency
ReferenceWhy it matters1 section · depth on demand

What it is

A pipe sends one command's output to the next command's input. Use set -o pipefail so a failure early in the pipe is not hidden by the last command's success.

ReferenceImportant terms & boundaries2 sections · depth on demand

In depth

Pipes connect commands so the output of one becomes the input of the next — the core of shell automation. Small tools (grep, awk, sort, jq) combine into powerful one-liners.

# Top 10 source IPs denied in a firewall log
grep ' DENY ' fw.log | awk '{print $5}' | sort | uniq -c | sort -rn | head -10
# Device names from an API
curl -s "$NB/api/dcim/devices/?site=oslo" -H "Authorization: Token $T" | jq -r '.results[].name'

By default a pipeline's exit status is that of the last command, so failures earlier in the pipe are hidden. set -o pipefail makes the pipeline fail if any command fails; ${PIPESTATUS[@]} shows each command's status.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docGNU Bash shell automation current

Authoritative/upstream documentation reviewed for bounded claims in Bash Automation > Pipes. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://www.gnu.org/software/bash/manual/bash.html · confidence 94%
Depth when you need it

Deep reference

Healthy vs suspicious evidence

Output interpretation

For producer/consumer process boundaries, buffering, exit status for each command, stderr separation and avoiding silent failure of non-final pipeline commands, prefer typed fields and stable IDs over human presentation text.

Confirmation

Confirm action

Continue?