break script on error


set -o errexit
set -o pipefail
set -o nounset

Another useful option is set -o xtrace which prints each command as it runs, even if piped or nested.

If you want print usage information instead of dying on missing input arguments, use bash defaults:

if [ -z ${1:-} ]
then
    echo "usage: myscript arg1"
    exit 1
fi

Date: 2017-09-21

Tags:  bash

Share: