Você pode usar set -e
dentro do script ou passar -e
para o intérprete ao iniciar.
#!/bin/sh
set -e
ou
/bin/sh -e /path/to/script.sh
link :
-e
When this option is on, if a simple command fails for any of the reasons listed in Consequences of Shell Errors or returns an exit status value >0, and is not part of the compound list following a while, until, or if keyword, and is not a part of an AND or OR list, and is not a pipeline preceded by the ! reserved word, then the shell shall immediately exit.