lib-bash – Bash Libraries

A set of libraries to use from within your Bash scripts.

Download as .zip Download as .tar.gz View on GitHub

lib_gnucompat.sh

GNU-Tools Compatibility Layer:

This script provides compatibility functions for GNU tools on non-GNU systems, such as macOS.

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_gnucompat.sh"

Tools Aliases

These functions will return the corresponding GNU-tool on non-GNU systems, if available. Such as gsed on macOS, which is the GNU version of sed.

Functions

is_gnu

Signal, if the given tool is a GNU tool.

Usage:

if ! is_gnu "sed"; then
echo "Not a GNU tool."
fi