Bird
0
0

What will be the output of this script?

medium📝 Command Output Q13 of 15
Bash Scripting - Error Handling
What will be the output of this script?
mkdir /root/testdir || echo "Failed to create directory"
echo "Script finished"
AFailed to create directory Script finished
BScript finished
Cmkdir: cannot create directory '/root/testdir': Permission denied Script finished
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Analyze mkdir command

    Creating a directory in /root usually requires root permission, so mkdir will fail with permission denied.
  2. Step 2: Check error handling

    Because mkdir fails, the || operator triggers the echo "Failed to create directory" message.
  3. Final Answer:

    Failed to create directory Script finished -> Option A
  4. Quick Check:

    mkdir fails triggers echo = B [OK]
Quick Trick: If command fails, || runs the error message [OK]
Common Mistakes:
MISTAKES
  • Assuming mkdir succeeds without permission
  • Expecting no error message printed
  • Confusing command error output with echo message

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes