lib_init.sh
A file for some initial Bash Scripting best practices. It applies the following settings:
errexit
: Abort on nonzero exit statusnounset
: Abort on unbound variablepipefail
: Don’t hide errors within pipesxtrace
: Show expanded commands ifDEBUG
is set to 2. Set to 1 for more verbose output.
Usage:
MY_PATH="$(realpath "${BASH_SOURCE[0]}")"
SCRIPT_DIR="$(dirname "${MY_PATH}")"
readonly MY_PATH
readonly SCRIPT_DIR
readonly LIB_BASH_DIR="${SCRIPT_DIR}/lib_bash"
source "${LIB_BASH_DIR}/lib_init.sh"
Constants
DEBUG
: Provide option to trigger debug output with different verbosity levels. Call withDEBUG=2 <command>.sh <file>
to enable verbose debug output