#!/bin/bash ############################################################################################################ # WTF? # # Script which allows exit-code checking and graceful "dying" in BASH scripts as simply as: # command # die command $? # ############################################################################################################ # BUGS: # # 1. There shouldn't be a need to export really_die... I should RTFM some more. # ############################################################################################################ # LOG: # # (version 0.1) # function really_die() { if [[ $1 != 0 ]] then exit=$1 else exit=1 fi if [[ $FORCE_CONTINUE ]] then echo "ignoring will to die w/ $exit" else exit $exit fi } function die() { if [[ $# != 2 ]] then echo "die() called with bad arguments." really_die fi COMMAND=$1 RETURNED=$2 if [[ $RETURNED != 0 ]] then echo "$COMMAND died w/ $RETURNED" really_die $RETURNED fi } export -f really_die export -f die