Pcornel
Automation · Bash Automation

Pipes

Cheat sheet · https://pcornel.dk/topic.php?topic=5282

Back to the Topic

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.

Remember

  • 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.

First checks

  • set -o pipefail — pipeline failures detected
  • cmd1 | cmd2; echo "${PIPESTATUS[@]}" — per-command status
  • Avoid useless cat — efficiency

Verify in this order

cmd1 stdout → cmd2 stdin

Where it usually breaks

Input/desired state → request accepted → job/task terminal status → target object read-back → effective runtime state → original workload → regression/rollback readiness.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5282

Confirmation

Confirm action

Continue?