shopt -s extdebug # stub is_function() { return 1 } # die [-q] "Message" PUBLIC # Display "Message" as an error. If -q is not provided, gives a stacktrace. die() { local item funcname="" sourcefile="" lineno="" n e s="yes" # do we have a working write_error_msg? if is_function "write_error_msg" ; then e="write_error_msg" else e="echo" fi # quiet? if [[ ${1} == "-q" ]] ; then s="" shift fi $e "${@:-(no message)}" if [[ -n "${s}" ]] ; then echo "Call stack:" 1>&2 for (( n = 1 ; n < ${#FUNCNAME[@]} ; ++n )) ; do funcname=${FUNCNAME[${n}]} sourcefile=$(basename ${BASH_SOURCE[$(( n - 1 ))]}) lineno=${BASH_LINENO[$(( n - 1 ))]} echo " * ${funcname} (${sourcefile}:${lineno})" 1>&2 done fi # Evil, but effective. # kill ${ESELECT_KILL_TARGET} exit 249 }