This project is collection of Bourne-again shell functions.
As for almost every function library the idea is to keep scripts readable, collect best practices and keep people from reinventing the wheel. It is developed and tested with Bash 4 (GNU) but most functions should also work in Bash 3 and on MacOS.
All libraries are located in lib/*
. Since we are talking about Bash, all you have to use is to source the library you want to use:
source ${BFL_PATH}/lib/Log.sh
For better transparency all functions, with the exception of the Log library, are intentionally self contained. They do not access variables that are defined outside of their local scope, requiring the user explicitly pass all inputs to them instead of just setting some "magic" variables. The same applies to return values.
Some functions take or return arrays. Since Bash does not support to pass arrays, references and their serialized string representations are used. Pass an array as to a function:
declare -a my_array=()
Array::contains_element my_array[@] ${some_element}
Read an array returned by a function:
declare -a kernel_available=$( System::Kernel::get_available )
# The returned string looks like '( [0]="4.16.18-gentoo" [1]="4.17.13-gentoo" [2]="4.17.14-gentoo" )'
# and will be transformed to an array automatically
Functions related to bash arrays
Functions related to the internet
Functions related to terminal and file logging Note: Logging to files is not yet implemented.
All available colors and formats are made available as constants that can be used in strings:
CLR_GOOD
CLR_INFORM
CLR_WARN
CLR_BAD
CLR_HILITE
CLR_BRACKET
CLR_NORMAL
FMT_BOLD
FMT_UNDERLINE
The same applies to the available log levels
LOG_LVL_OFF
LOG_LVL_ERR
LOG_LVL_WRN
LOG_LVL_INF
LOG_LVL_DBG
The current log level and whether a timestamp should be added to each entry can be configured:
LOG_LEVEL=${LOG_LVL_INF}
LOG_SHOW_TIMESTAMP=true
Functions related to the build tool Apache Maven
Functions related to the software repository manager Sonatype Nexus
Functions related to the Secure Shell
Functions related to Bash Strings
Functions related to Linux Systems
Library of useful utility functions
Most functions are covered with tests using the Bash Automated Testing System (BATS) by Sam Stephenson
Each library has its own test suite that can be run separately:
$ bats test/*.bats
- Michael Strache - Initial work - Jarodiv
This project is licensed under the MIT License - see the LICENSE.md file for details