Вот некоторые общие формы. Выбор лучшего зависит от того, что вы делаете. Вы можете использовать любое подмножество или комбинацию из них в одном script без плохого стиля.
if ! failingcommand
then
echo >&2 message
exit 1
fi
failingcommand
ret=$?
if ! test "$ret" -eq 0
then
echo >&2 "command failed with exit status $ret"
exit 1
fi
if ! (git clone [email protected]:my-username/my-repo.git) then
exit 1
# Put Failure actions here...
else
echo "Success"
# Put Success actions here...
fi