Bird
0
0

What will this script output?

medium📝 Command Output Q5 of 15
Bash Scripting - Error Handling
What will this script output?
rm /root/secretfile || echo "Cannot delete file"
Assuming the user is not root.
ANo output
BFile deleted successfully
CPermission granted
DCannot delete file
Step-by-Step Solution
Solution:
  1. Step 1: Check command failure

    rm fails because user lacks permission to delete /root/secretfile.
  2. Step 2: Error handling triggers

    Because rm fails, the '||' runs and prints "Cannot delete file".
  3. Final Answer:

    Cannot delete file -> Option D
  4. Quick Check:

    Failed command triggers error message [OK]
Quick Trick: Failed commands trigger '||' error messages [OK]
Common Mistakes:
MISTAKES
  • Assuming file deletes without permission
  • Expecting no output on failure
  • Confusing success and failure outputs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes