Added bash-support

Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
2020-11-16 12:54:24 +01:00
parent 5b8989ac04
commit fc7dc3f34a
56 changed files with 12377 additions and 1 deletions

@ -0,0 +1,22 @@
# PS4 : timestamp; the current time in 24-hour HH:MM:SS format
PS4='+[\t] '
# PS4 : timestamp; 'seconds.nanoseconds' since 1970-01-01 00:00:00 UT
PS4='+[$(date "+%s.%N")] '
# PS4 : position, line number, function name
# The following line avoids error messages due to an unset FUNCNAME[0] :
# set +o nounset # Treat unset variables as an error
#
PS4='+|${BASH_SOURCE##*/} ${LINENO}${FUNCNAME[0]:+ ${FUNCNAME[0]}}| '
# PS4 : position, line number, function name, subshell information
# The following line avoids error messages due to an unset FUNCNAME[0] :
# set +o nounset # Treat unset variables as an error
#
PS4='+(${BASH_SOURCE##*/}: ${LINENO}) : ${FUNCNAME[0]} - [level ${SHLVL}, '
PS4=$PS4'subshell ${BASH_SUBSHELL}, return code $?]\n '
# PS4 : default prompt
PS4='+ '

@ -0,0 +1,16 @@
#=== FUNCTION ================================================================
# NAME: _assert
# DESCRIPTION: Abort the script if assertion is false.
# PARAMETERS: 1) expression used as test inside brackets
# 2) optional information, e.g. $LINENO
# RETURNS: 0 / 99 assertion is true / false
#===============================================================================
function _assert ()
{
if [ ! $1 ]; then
echo "${0##*/}${2:+:$2}: assertion '$1' failed."
exit 99
fi
return 0
}

@ -0,0 +1,15 @@
DEBUG=${DEBUG:-0} # 0 = no debug output, 1 = show debug output,
# or enable debug with: DEBUG=1 script.sh
#=== FUNCTION ================================================================
# NAME: _debug
# DESCRIPTION: echo debug output controlled by a global variable
# PARAMETERS: list, e.g.; "$LINENO: x=$x"
# RETURNS: always 0
#===============================================================================
_debug ()
{
[ ${DEBUG} -ne 0 ] && echo -e "${@}"
return 0
} # ---------- end of function _debug ----------

@ -0,0 +1,3 @@
# print the positional parameters
printf "'%b'\n" "$0" "$@" | nl -v0 -s': '

@ -0,0 +1,16 @@
DEBUG=${DEBUG:-0} # 0 = no debug output, 1 = show debug output,
# or enable debug with: DEBUG=1 script.sh
#=== FUNCTION ================================================================
# NAME: _debug_timestamp
# DESCRIPTION: timestamp + optional information
# timestamp: {seconds since 1970-01-01 00:00:00}.{nanoseconds}
# PARAMETERS: identification, e.g. $LINENO (optional)
# RETURNS: always 0
#===============================================================================
_debug_timestamp ()
{
[ ${DEBUG} -ne 0 ] && echo -e "[ $(date "+%s.%N") ]${@:+ -- ${@}}"
return 0
} # ---------- end of function _debug_timestamp ----------