Home

Awesome

bash-core

Core functions for any Bash program

Summary

The following is a brief overview of the available functions. See api.md for more details

trap

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

shopt

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

err

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

print

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 (/home/edwin/repos/bash-core/.hidden/test.sh:0)
  in err_handler (/home/edwin/repos/bash-core/.hidden/test.sh:36)
  in fn3 (/home/edwin/repos/bash-core/.hidden/test.sh:48)
  in fn2 (/home/edwin/repos/bash-core/.hidden/test.sh:53)
  in fn (/home/edwin/repos/bash-core/.hidden/test.sh:57)

Installation

Use Basalt, a Bash package manager, to add this project as a dependency

basalt add hyperupcall/bash-core