Bird
0
0

You want a script to exit on error but allow a specific command to fail without stopping. How do you write it?

hard🚀 Application Q8 of 15
Bash Scripting - Error Handling
You want a script to exit on error but allow a specific command to fail without stopping. How do you write it?
Aset -e command1 command2 command3
Bset -e command1 command2 || true command3
Cset +e command1 command2 command3
Dset -e command1 if command2; then :; fi command3
Step-by-Step Solution
Solution:
  1. Step 1: Enable exit on error globally

    Use set -e to make the script exit on any error.
  2. Step 2: Allow specific command to fail without exiting

    Use command2 || true so failure of command2 does not cause exit.
  3. Step 3: Confirm other commands still cause exit on error

    Other commands like command1 and command3 will still cause exit if they fail.
  4. Final Answer:

    set -e\ncommand1\ncommand2 || true\ncommand3 -> Option B
  5. Quick Check:

    Use || true to allow failure with set -e [OK]
Quick Trick: Use || true to ignore error for one command [OK]
Common Mistakes:
MISTAKES
  • Disabling set -e globally
  • Not handling allowed failure properly
  • Using if without understanding exit behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes