Bird
0
0

You want to run a script and log all output and errors to separate files, but also display errors on the terminal immediately. Which command achieves this?

hard📝 Best Practice Q8 of 15
Bash Scripting - Error Handling
You want to run a script and log all output and errors to separate files, but also display errors on the terminal immediately. Which command achieves this?
Ascript.sh &> output.log
Bscript.sh > output.log 2> error.log
Cscript.sh > output.log 2> >(tee error.log >&2)
Dscript.sh > output.log 2>&1 | tee error.log
Step-by-Step Solution
Solution:
  1. Step 1: Understand process substitution

    Using '2> >(tee error.log >&2)' sends stderr to tee, which writes to error.log and stderr.
  2. Step 2: Confirm output and error separation

    Stdout goes to output.log, stderr both saved and displayed on terminal.
  3. Final Answer:

    script.sh > output.log 2> >(tee error.log >&2) -> Option C
  4. Quick Check:

    Process substitution duplicates stderr to file and terminal [OK]
Quick Trick: Use process substitution to tee stderr to file and terminal [OK]
Common Mistakes:
MISTAKES
  • Redirecting stderr only to file without display
  • Merging stdout and stderr incorrectly
  • Using &> which merges outputs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes