Description
A bash script is a series of commands written in a file. These are read and executed by the bash command-line interpreter program. The program executes line by line. For example, you can navigate to a certain path, create a folder and spawn a process inside it using the command line.[1]
example
1 |
|
setting options
set -o <option>
is the generic way to set various options.
errexit
set -e
is a shortcut for setting theerrexit
option.set -o errexit
has the same effect.- The
set -e
option instructs bash to immediately exit if any command has a non-zero exit status; subsequent lines of the script are not executed.[2] - By default, bash does not do this… if it encounters a runtime error, it does not halt execution of the program; it keeps going and if one line in a script fails, but the last line succeeds, the whole script has a successful exit code.[2:1]
errtrace
set -E
is a shortcut for setting theerrtrace
option.set -o errtrace
has the same effect.- When
errtrace
is enabled, theERR
trap is also triggered when the error (a command returning a nonzero code) occurs inside a function or a subshell. Another way to put it is that the context of a function or a subshell does not inherit theERR
trap unlesserrtrace
is enabled.[3]