Search code examples
shellsh

Can “set -e” be disabled in a script?


I want to do something like this in a shell script main.sh. Is it possible?

set -e

******some code

unset -e

******some other code.

set -e


Solution

  • @Charles Duffy on another thread answered this. not exit a bash script when one of the sub-script fails

    set +e undoes set -e. However, using set -e is a bad idea in general; better to use || exit on individual commands where you want a nonzero exit status to be fatal. (Skip past the parable to the exercises if you're in a hurry). – Charles Duffy