"set -e" is used to exit immediately when a command (pipeline or subcommand command, etc.) exits with non-zero status.
By default, BASH ignores errors and continues to interpret your script. This can cause a very bad surprise, for example:
if ! lss myLock then touch myLock; echo "No lock, I can do the job"; rm -f myLock fi
The result of this script is:
bash: lss : commande introuvable No lock, I can do the job
As you can see, BASH has no meaning between the team not found and the team that failed.
"- e" is often used to make sure that the shell interpreter stops immediately after an error (so we should think about all the errors ...). This helps prevent a very bad problem when we make a mistake in the script (think about rm -rf "$ v" / * when you forgot to install v ;-)). To do this, we pass the -e option to shebang . Obviously, it is not intended for interactive use, and I cannot imagine the good use of "set -e" or "set + e" (but for testing).
To answer your initial question. You can avoid completing your shell by applying one of the following solutions:
Use if statement
function myF1() { if git foobar; then echo "I will not print this, because git foobar returned a non-zero exit code" fi }
Use the control operator & </ h3>
function myF2() { git foobar && \ echo "I will not print this, because git foobar returned a non-zero exit code" }
Open subshell
function myF4() {( set -e git foobar echo "I will not print this, because git foobar returned a non-zero exit code" )}
In this case, "set -e" will exit the sub-shell immediately, but will not terminate the caller :-)
Using a trap here is not very good, since it can cause a side effect for the caller (the trap is defined globally). Obviously, we can combine a trap and a sub-shell, but this is not useful in your case.