Set -e shell command for in Linux

I see set -e in scripts when it starts. Something like as follows:

#!/bin/sh
set -e

# Set by config.status
PACKAGE="smartmontools"
VERSION="6.2"
prefix="/usr"
sysconfdir="/etc/smartmontools"
....
...

What is the purpose of set -e in the /bin/sh or /bin/bash shell script running on a Linux or Unix system?

Your shell script will exit immediately if a command exits with a non-zero status. So if there is an error in your shell script, it will exit or get terminated immediately.

2 Likes