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.
SED: GNUsedcommandAWK: GNUawkcommandGREP: GNUgrepcommandFIND: GNUfindcommandSORT: GNUsortcommandTAR: GNUtarcommandDATE: GNUdatecommandXARGS: GNUxargscommandCUT: GNUcutcommandHEAD: GNUheadcommandTAIL: GNUtailcommandTR: GNUtrcommandUNIQ: GNUuniqcommandWC: GNUwccommandDIFF: GNUdiffcommand
Functions
is_gnu
Signal, if the given tool is a GNU tool.
Usage:
if ! is_gnu "sed"; then
echo "Not a GNU tool."
fi