9
4
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)?
http://stackoverflow.com/questions/29528624/how-to-restore-previous-set-x-option-in-bash – Ciro Santilli 新疆改造中心法轮功六四事件 – 2016-08-24T16:38:45.410
The same issue (for the
– Scott – 2018-11-02T00:28:02.773-x
/xtrace
option) is addressed at Suppress execution trace for echo command?