MIAOU-BASH is a collection of settings and helpers for leveraging BASH. Developer-friendly, it may be used as solo package with or without the miaou project.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
875 B

#!/usr/bin/env bash
# constants
## functions
function on_error {
code="${1:-0}"
>&2 echo on_error: $$ $BASHPID
if [[ $$ == "$BASHPID" ]]; then
>&2 echo "${BASH_SOURCE[1]}: line ${BASH_LINENO[0]}: command_error: ${code}"
exit "$code"
else
>&2 echo "${BASH_SOURCE[1]}: line ${BASH_LINENO[0]}: subshell_error: ${code}"
kill -PIPE $$
fi
# kill -INT $BASHPID
# kill -INT $$
}
function on_exit {
code="${1:-0}"
echo "on_exit $code"
}
function on_pipe {
>&2 echo on_pipe: $$ $BASHPID
#TODO: compute code from latest sterr in case of command_error
code="${1:-24}" # 24 => CTRL-C
trap - EXIT ERR PIPE
exit "$code"
}
## main
set -euo pipefail
set -T # DEBUG RETURN
set -E # ERR on subshell
# set -b
trap 'on_error $?' ERR
trap 'on_exit $?' EXIT
trap 'on_pipe' PIPE
echo "${BASHPID}"
source ./test/stub/scenario.bash subshell_term