Bird
0
0

You want to run a script that outputs normal messages to output.log and error messages to error.log. Which command correctly achieves this?

hard🚀 Application Q15 of 15
Bash Scripting - File Operations in Scripts
You want to run a script that outputs normal messages to output.log and error messages to error.log. Which command correctly achieves this?
A./script.sh > output.log 2> error.log
B./script.sh 2>&1 > output.log error.log
C./script.sh > output.log 2>&1 error.log
D./script.sh > output.log &> error.log
Step-by-Step Solution
Solution:
  1. Step 1: Understand separate redirection for output and error

    To send stdout and stderr to different files, use > for stdout and 2> for stderr separately.
  2. Step 2: Analyze each option

    ./script.sh > output.log 2> error.log correctly redirects stdout to output.log and stderr to error.log. Others mix or misuse redirection syntax.
  3. Final Answer:

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

    Separate > and 2> for output and error [OK]
Quick Trick: Use > for output, 2> for errors to separate files [OK]
Common Mistakes:
MISTAKES
  • Using &> redirects both to one file
  • Mixing order of redirections incorrectly
  • Omitting file names after redirection operators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes