How do pipes and redirection work?
Assesses fundamental understanding of Shell & Bash conventions, runtime behavior, and memory/performance considerations.
Hiring managers look for precision, avoidance of ambiguous jargon, and ability to explain trade-offs under real production conditions.
Every process has three standard streams: stdin (0), stdout (1) and stderr (2). Redirection connects them to files or other processes.
cmd > out.log # stdout to file, truncate
cmd >> out.log # append
cmd 2> err.log # stderr only
cmd > all.log 2>&1 # both, order matters
cmd &> all.log # bash shorthand
cmd < input.txt # stdin from file
cmd | tee out.log # pipe and also write a file
A pipe connects the stdout of the left command to the stdin of the right and runs both concurrently. The exit status of a pipeline is the last command's unless pipefail is set.
Order matters in > all.log 2>&1: the file descriptor 2 is pointed at wherever 1 currently points, so redirect stdout first. <<< is a here-string, <<EOF a here-document, and |& pipes both streams. Process substitution such as <(cmd) presents command output as a file.
Candidate Response Strategy & Interview Tips
- Start with a concise one-sentence summary: Deliver a direct, confident answer first before expanding into nuances.
- Demonstrate real-world trade-offs: Discuss where this approach excels and when you would avoid it in production systems.
- Discuss complexity & edge cases: Proactively explain time/space complexity or boundary conditions (null values, scale limits).
- Prepare for interviewer follow-ups: Technical hiring panels frequently probe deeper into concurrency, backward compatibility, or alternative libraries.