Bird
0
0

Identify the error in this script snippet:

medium📝 Debug Q6 of 15
Bash Scripting - Error Handling
Identify the error in this script snippet:
#!/bin/bash
set -e
command1
command2 || true
command3
Acommand2 || true disables exit on error for command2
Bset -e is not enabled properly
Ccommand3 will never run
DSyntax error in command2
Step-by-Step Solution
Solution:
  1. Step 1: Understand how set -e interacts with || true

    Using command2 || true means even if command2 fails, the overall command succeeds.
  2. Step 2: Effect on script exit

    This disables exit on error for command2, so the script continues regardless of command2's success.
  3. Final Answer:

    command2 || true disables exit on error for command2 -> Option A
  4. Quick Check:

    || true bypasses set -e exit [OK]
Quick Trick: || true lets script continue despite errors [OK]
Common Mistakes:
MISTAKES
  • Thinking set -e always stops script
  • Ignoring || true effect
  • Assuming command3 won't run

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes