9
1
If a shell function needs a specific setting of -e/+e in order to work, is it possible to set that setting locally and then restore it to its previous setting before exiting the function?
myfunction()
{
# Query here if -e is set and remember in a variable?
# Or push the settings to then pop at the end of the function?
set +e
dosomething
doanotherthing
# Restore -e/+e as appropriate, don't just do unconditional set -e
}
It should be noted that
$-
also works in/bin/sh
and you probably don't need bashisms to parse it, just use e.g. globbing thatcase
provides – Josip Rodin – 2017-07-06T10:50:45.077