Core functions for any Bash program
The following is a brief overview of the available functions. See api.md for more details
Add or remove multiple functions at a time to any set of signals. Without these, it is impossible to trap a signal without erasing a previous one
core.trap_addcore.trap_remove
Enable or disable a shell option. Enabling a shell option adds it to a hidden stack. When that shell option is no longer needed, it should be removed by popping it from the stack
core.shopt_pushcore.shopt_pop
It can look redundant (compared to if ! fn; then :; fi) to define error functions, but it can help make errors a bit more safe in larger applications, since you don't have to worry about a caller forgetting to if ! fn or fn || (and terminating the script if set -e). It also makes it easier to communicate specific error codes and helps separate between calculated / expected errors and unexpected errors / faults
core.err_setcore.err_clearcore.err_exists
core.print_stacktracecore.print_fatalcore.print_errorcore.print_warncore.print_infocore.print_debug
The function core.print_stacktrace prints the stack trace. It is recommended to use this with core.trap_add (see example)
Following is a core.print_stacktrace example:
Stacktrace:
in core.stacktrace_print (/tmp/test.sh:0)
in err_handler (/tmp/test.sh:36)
in fn3 (/tmp/test.sh:48)
in fn2 (/tmp/test.sh:53)
in fn (/tmp/test.sh:57)Use Basalt, a Bash package manager, to add this project as a dependency
basalt add hyperupcall/bash-core