I'm writing a script that needs to be executed using source
, because its task is to modify the environment. During the script, I want to use set -e
so that any error stops the script. The script looks like this:
#!/bin/bash
set -e
# do something
cd somewhere
source anotherScript
The problem is that set -e
naturally remains in effect after the script finishes. How can I ensure that the altered set
option is properly restored to its prevous value when the script stops (in any way - either by completing successfully or on an error)?
-x
/xtrace
option) is addressed at Suppress execution trace for echo command?