What does set -e do?

This builtin is so complicated that it deserves its own section.

set allows you to change the values of shell options and set the positional parameters, or to display the names and values of shell variables.

The -e option

-e

Exit immediately if a pipeline (see Pipelines), which may consist of a single simple command (see Simple Commands), a subshell command enclosed in parentheses (see Command Grouping), or one of the commands executed as part of a command list enclosed by braces (see Command Grouping) returns a non-zero status. The shell does not exit if the command that fails is part of the command list immediately following a while or until keyword, part of the test in an if statement, part of any command executed in a && or || list except the command following the final && or ||, any command in a pipeline but the last, or if the command’s return status is being inverted with !. A trap on ERR, if set, is executed before the shell exits.

This option applies to the shell environment and each subshell environment separately (see Command Execution Environment), and may cause subshells to exit before executing all the commands in the subshell.

Source: www.gnu.org

Edited due to @psusi's comment below.

Additionally you can read the bash's manual page

man bash 

at the section: SHELL BUILTIN COMMANDS

or issue

help set 

for a short help message.


set -e in short, when it is at the top of your bash script, tells script to exit as soon as any line in the script fails (with some exceptions listed in the manual.)[1]

As a debugging option, it's often used with set -x, which is to print each expanded command line before execution with a "+" sign.[2]

See more at:

[1] https://www.peterbe.com/plog/set-ex

[2] http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html

Tags:

Bash