Pipes & Redirection

stdin/stdout/stderr, pipes, here-docs, process substitution, and tee for multi-destination output.

Overview

Overview Every process inherits three open file descriptors, the small numbers a program uses to name its input and output: 0 (stdin), 1 (stdout) and 2 (stderr). Each one points at the terminal until something changes it. Redirection changes where these point, and a pipe joins one command's output to the next command's input.

Key concepts

  • File descriptors 0/1/2
  • 2>&1
  • Pipeline subshell
  • Process substitution
  • tee

Interview questions

  • Why does this script not work: count=0; cat file.txt | while read line; do count=$((count+1)); done; echo $count?
  • You need to log all output of a script to a file while still displaying it on the terminal. How?

Sign up free to read the full topic

More Linux topics

Start free on Cariara · Coding problems · System design studio