Turn on -e mode (do you feel lucky - punk?)

In this mode any command your script runs which returns a non-zero exitcode - an error in the world of shell - will cause your script to itself terminate immediately with an error.

You can do that in your shebang line:

#!/bin/sh -e

Or using set:

set -e

Yes, this is what you want. A neat predictable failure is infinitely better than a noisy unreliable failure.

If you REALLY want to ignore an error, be explicit about it:

# I don't care if evil-broken-command fails evil-broken-command || true

Oh and as long as you're messing with shell modes, -e goes well with -x (which I like to think of as shell X-ray).

Like this:

#!/bin/sh -ex

Or like this:

# turn -x on if DEBUG is set to a non-empty string [ -n "$DEBUG" ] && set -x

That way you can actually see what your script was doing right before it failed.