Explorar o código

Allow exit status in die

George Jones hai 1 ano
pai
achega
ab7075f71e
Modificáronse 1 ficheiros con 11 adicións e 1 borrados
  1. 11 1
      lib/bash/bashutils.sh

+ 11 - 1
lib/bash/bashutils.sh

@@ -76,7 +76,17 @@ function error() { echo `date +%c` `stackfuncs`\: error: "$@" 1>&2; }
 # TODO
 #   have it check debug levels and or strings
 function debug() { [[ -v DEBUG ]] && echo `date +%c` `stackfuncs`\: debug: "$@" 1>&2 || true ; }
-function die()   { echo `date +%c` `stackfuncs`\: fatal: "$@" 1>&2 && exit 1; }
+function die()   {
+
+    exit_code=1
+    if [[ -v 2 ]]; then
+       exit_code="${1}"
+       shift;
+    fi
+
+    echo `date +%c` `stackfuncs`\: fatal: "$@" 1>&2 && exit "${exit_code}";
+}
+
 
 FALSE=1
 TRUE=0