OR list

Two commands joined by ||, where the second runs only if the first fails.

In more detail

cd dir || exit 1 is the standard guard against carrying on in the wrong directory. Under set -e, a failing command on the left of || does not stop the script, because the failure has been handled.

Example

cmd || { echo 'what failed' >&2; exit 1; }

Related terms

Taught in

References