Redirection order changes the destination

An available program, ./report, writes exactly four newline-terminated result lines to standard output and exactly two newline-terminated warning lines to standard error. It produces no other output.


Consider four independent Bash command lines:


Shell
# Run A
./report 2>&1 | wc -l

# Run B
./report >saved.log 2>&1 | wc -l

# Run C
./report 2>&1 >saved.log | wc -l

# Run D
./report 2>errors.log | wc -l


Before each independent run, saved.log and errors.log both exist and are empty. All commands and file operations succeed. Complete the table with the integer printed by wc -l and the number of lines in each file after that run. Enter exact integers; do not include units.

RunInteger printed by wc -lLines in saved.logLines in errors.log
A
B
C
D

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More The Shell Questions: