To make a bash script exit after any failed command, you can add
set -e
Imagine, you have a CI agent which allow people to embed bash scripts as tasks in build jobs.
How to make the exit behaviour given by set -e
default for all new bash instances? Is there some sort of bashrc
hack for that?
You can make the present running bash shell activate the -e
option with:
$ set -e
Just to confirm:
$ echo "$-"
himBHs
$ set -e
ehimBHs
As the bashrc file is sourced to interactive shells you can make all new bash shells use the -e
option by adding this:
set -e
As one line at any place (that is executed) of the .bashrc
script.
This is a very bad idea however, as there are many conditions under which the detection of a failed command fails and there are several cases where a failed command is desirable. Please read
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments