Bird
0
0

You want to run a script and save both standard output and error messages into separate files, but also keep the error messages appended (not overwritten). Which command achieves this?

hard📝 Best Practice Q15 of 15
Bash Scripting - Error Handling
You want to run a script and save both standard output and error messages into separate files, but also keep the error messages appended (not overwritten). Which command achieves this?
A./script.sh > output.log 2> error.log
B./script.sh > output.log 2>> error.log
C./script.sh &> output.log
D./script.sh >> output.log 2> error.log
Step-by-Step Solution
Solution:
  1. Step 1: Understand output and error redirection

    > overwrites standard output, 2>> appends standard error to a file.
  2. Step 2: Match requirement to command

    We want output overwritten in output.log and errors appended in error.log, so ./script.sh > output.log 2>> error.log fits.
  3. Final Answer:

    ./script.sh > output.log 2>> error.log -> Option B
  4. Quick Check:

    Use 2>> to append errors [OK]
Quick Trick: Use 2>> to append errors, > to overwrite output [OK]
Common Mistakes:
MISTAKES
  • Using 2> which overwrites error file
  • Using &> which merges output and errors
  • Appending output but overwriting errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes