After entering set -e
in an interactive bash shell, bash will exit immediately if any command exits with non-zero. How can I undo this effect?
3 Answers
With set +e
. Yeah, it's backward that you enable shell options with set -
and disable them with set +
. Historical raisins, donchanow.
-
2Thank you very much, it's among the very last lines of corresponding manual page (faqs.org/docs/bashman/bashref_56.html) which I didn't read to the end. Aug 18, 2010 at 22:22
-
The bash manual is dauntingly huge, it is true. (FYI, since you seem to be new: it is the done thing to click the check mark under the best answer to your question, this is called "accepting" it.)– zwolAug 18, 2010 at 22:26
-
12Sadly, the Unix shell language (most of which is not specific to 'bash') is one of the least internally consistent programming languages still in wide use today. You're going to have to learn lots more of these little warts. And I'd say that's a documentation bug, there.– zwolAug 18, 2010 at 22:36
-
10
-
3Finally, an unfair bashing of Bash: single dash is the standard POSIX shell command line option, and therefore most natural for "do something".
+
is like-
but crossing over something means "not" as in "≠". Jun 29, 2018 at 8:44
It might be unhandy to use set +e
/set -e
each time you want to override it. I found a simpler solution.
Instead of doing it like this:
set +e
command_that_might_fail_but_we_want_to_ignore_it
set -e
you can do it like this:
command_that_might_fail_but_we_want_to_ignore_it || true
or, if you want to save keystrokes and don't mind being a little cryptic:
command_that_might_fail_but_we_want_to_ignore_it || :
Hope this helps!