← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

Shell Pipes & Redirects

Linux Intermediate
debt(d9/e3/b3/t7)
d9 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'silent in production until users hit it' (d9). The detection_hints flag automated=no, and the listed tools (bash, grep, awk, sed) are runtime tools, not static analyzers. A misplaced 2>&1 in a deployment script silently loses stderr to the terminal while the log file appears complete — no linter or compiler catches this; it surfaces only when errors are missing from logs in production.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix and common_mistakes indicate that corrections are small, localized changes: reordering redirect operators on a single command line, removing unnecessary cat pipes, or quoting arguments in PHP exec(). No multi-file refactor is needed, but the developer must understand the pattern to apply the fix correctly, placing it above a trivial one-liner (e1).

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3). The applies_to context is cli only, meaning this concept is scoped to shell scripts and deployment tooling rather than application code. It imposes a persistent learning requirement on anyone writing bash scripts for deployment or log analysis, but the rest of the codebase is unaffected, keeping it at b3 rather than higher.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7). The misconception field directly documents that `cmd > out.log 2>&1` and `cmd 2>&1 > out.log` appear equivalent but behave differently in a way that contradicts intuitive left-to-right reading. This contradicts how similar sequential operations work in other contexts (assignment, piping), making it a serious trap. It is not catastrophic (t9) because the correct form is a documented, teachable rule.

About DEBT scoring →

Also Known As

pipes stdin stdout stderr redirects

TL;DR

Pipes (|) connect stdout of one command to stdin of another; redirects (<, >, >>) send stdin/stdout to files — the foundation of composable Unix command-line workflows.

Explanation

Standard streams: stdin (0), stdout (1), stderr (2). Redirect stdout: cmd > file (overwrite), cmd >> file (append). Redirect stderr: cmd 2> error.log. Redirect both: cmd > out.log 2>&1. Pipe: cmd1 | cmd2 connects cmd1's stdout to cmd2's stdin. Named pipes (mkfifo) persist as filesystem objects. Pipes are synchronous — cmd1 runs concurrently with cmd2, with a kernel buffer between them. Understanding pipes enables composing tools: cat access.log | grep '500' | awk '{print $1}' | sort | uniq -c | sort -rn

Common Misconception

cmd > out.log 2>&1 and cmd 2>&1 > out.log are equivalent — order matters: the second form redirects stderr to the terminal stdout first, then redirects stdout to the file — stderr still goes to the terminal.

Why It Matters

Pipes and redirects are how PHP deployment scripts, log analysis, and server administration tasks are composed from simple tools — essential for writing correct bash scripts.

Common Mistakes

  • Losing stderr in deployment scripts — use 2>&1 to capture errors alongside stdout in logs.
  • 2>&1 > file vs > file 2>&1 — order matters; always put the file redirect first: > file 2>&1.
  • Using cat file | grep instead of grep file — unnecessary pipe; grep reads files directly.
  • Not quoting pipes in PHP exec() — shell special characters in arguments can break the pipe.

Code Examples

✗ Vulnerable
# Wrong order — stderr not captured in file:
deploy.sh 2>&1 > deploy.log
# stderr goes to terminal (original stdout at time of 2>&1)
# stdout goes to deploy.log
# Errors missing from log!

# PHP: exec without capturing stderr:
exec('composer install', $output); // Errors from composer lost
✓ Fixed
# Correct order — both streams to file:
deploy.sh > deploy.log 2>&1
# stdout → file, then stderr → same as stdout (now the file)

# PHP: capture stderr too:
exec('composer install 2>&1', $output, $exitCode);
if ($exitCode !== 0) {
    file_put_contents('/var/log/deploy_errors.log', implode("\n", $output));
}

Added 15 Mar 2026
Edited 22 Mar 2026
Views 39
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 1 ping W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 0 pings F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 1 ping F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Amazonbot 7 Google 6 Ahrefs 4 Perplexity 3 Unknown AI 3 SEMrush 3 Claude 2 ChatGPT 2 Scrapy 2 Meta AI 1
crawler 29 crawler_json 3 pre-tracking 1
DEV INTEL Tools & Severity
🟢 Low ⚙ Fix effort: Low
⚡ Quick Fix
Understand pipes (|) and redirects (>, >>, 2>&1) to build PHP deployment scripts — grep errors in PHP logs, transform with awk, count with wc, all without writing PHP
📦 Applies To
bash cli
🔗 Prerequisites
🔍 Detection Hints
PHP script parsing log files that shell pipeline would handle; missing stderr redirect causing lost error messages; deployment script not capturing output
Auto-detectable: ✗ No bash grep awk sed
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: Low Context: File


✓ schema.org compliant