Bird
0
0

Given the command:

medium📝 Command Output Q5 of 15
Bash Scripting - Error Handling
Given the command:

ls /nonexistent 2>&1 | tee output.log

What will be the content of output.log?
AThe error message from ls about /nonexistent directory
BAn empty file because errors are not captured
CThe list of files in the current directory
DOnly standard output without errors
Step-by-Step Solution
Solution:
  1. Step 1: Understand 2>&1 redirection

    Redirects stderr to stdout so both go through the pipe.
  2. Step 2: Understand tee command

    Tee writes input it receives to output.log and stdout.
  3. Final Answer:

    The error message from ls about /nonexistent directory -> Option A
  4. Quick Check:

    2>&1 merges errors to stdout for piping [OK]
Quick Trick: Use 2>&1 to pipe errors through commands like tee [OK]
Common Mistakes:
MISTAKES
  • Assuming errors are not piped
  • Expecting directory listing despite error
  • Confusing tee behavior with redirection

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes