Bird
0
0

What will be the output of the following command if my_script.sh prints "Done" to stdout and "Warning" to stderr?

medium📝 Command Output Q4 of 15
Bash Scripting - Error Handling
What will be the output of the following command if my_script.sh prints "Done" to stdout and "Warning" to stderr?

./my_script.sh > output.log 2> error.log
ABoth "Done" and "Warning" are saved in output.log
B"Done" is saved in output.log and "Warning" is saved in error.log
CBoth "Done" and "Warning" are saved in error.log
DNothing is saved in either file
Step-by-Step Solution
Solution:
  1. Step 1: Understand redirection operators

    > redirects stdout to output.log, 2> redirects stderr to error.log.
  2. Step 2: Match outputs to files

    "Done" (stdout) goes to output.log, "Warning" (stderr) goes to error.log.
  3. Final Answer:

    "Done" is saved in output.log and "Warning" is saved in error.log -> Option B
  4. Quick Check:

    Separate stdout and stderr to different files [OK]
Quick Trick: Use > for stdout, 2> for stderr redirection [OK]
Common Mistakes:
MISTAKES
  • Assuming both outputs go to the same file
  • Mixing up stdout and stderr
  • Forgetting to redirect stderr separately

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes