Kolam Ayer MakersLinux Foundations

set

Use

set -euo pipefail

What It Does

set changes shell options for the current shell or script. These options depend on exit status: 0 means success, nonzero means failure.

Course Options

Stop when a command fails:

set -e

Reject unset variables:

set -u

Make a pipeline fail if any stage fails:

set -o pipefail

Combine them:

set -euo pipefail

Why Use It

These options make script bugs loud. Without them, a script may continue after an earlier command failed.

Watch Out

set -u makes $1 fail when no argument was passed. Add argument checks before using positional arguments.

set -e is not a replacement for understanding failures. It reacts to nonzero exit statuses; you still need to know which command failed and why.

Docs Pointers