Shell Pipes & Redirects
debt(d9/e3/b3/t7)
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.
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).
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.
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.
Also Known As
TL;DR
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
Why It Matters
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
# 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
# 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));
}