#!/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