Shell scripts can stop upon exception rather than handling each one manually. This can significanlty reduce logical clutter in a script. Stop a shell script on error for Unix / Linux / MacOS shell by setting near the top of the .sh script file:
set -o errexit
This is a human-readable equivalent to
This works for commonly used Unix shells including Bash and
Another useful option is to stop the script if any script variables are defined:
set -o nounset
Stop executing a Powershell script upon exception by adding near the top of the .ps1 Powershell script:
$ErrorActionPreference = 'Stop'