-Functions to deal with errors in bash
+Bash stack trace and error handling functions
-err: usually, just copy and source this. contains the other files
+Usually, just copy the err file and source it. Then on any non-zero
+return code outside of a conditional, the program will exit and print a
+stack trace.
+The err file has some functions which you may want to call manually for
+different or additional error handling. See the comments at the start of
+each one.
-err-catch: set a trap on error to do bash-trace and exit
-err-allow: undo errcatch
-err-exit: exit and print stack trace
-bash-trace: print stack trace (best bash stack trace ever)
-
-the err* functions depend on bash-trace.
-
-For scripts without any nested function calls, this is usually sufficient:
+For scripts where functions are not used, you can optionally use a more
+minimal approach:
set -eE -o pipefail
trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
-Cleanup commands or functions can be appended to the ERR trap after a
-semicolon within the single quotes.
+In the above line, cleanup commands or functions can be appended to the
+ERR trap after a semicolon within the single quotes.
Related: see my bash script template repo, at https://iankelling.org/git.
+Most recently tested on bash 4.4.20(1)-release (x86_64-pc-linux-gnu).
+
Please email me if you have a patches, bugs, feedback, or republish this
somewhere else: Ian Kelling <ian@iankelling.org>.