diff --git a/poc b/poc new file mode 100755 index 0000000..68d262e --- /dev/null +++ b/poc @@ -0,0 +1,48 @@ +#!/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 diff --git a/test/stub/scenario.bash b/test/stub/scenario.bash index dcedd75..0da564a 100755 --- a/test/stub/scenario.bash +++ b/test/stub/scenario.bash @@ -13,8 +13,11 @@ function do_subshell_false { } function do_subshell_term { - echo "found2=$(grep nope nope)" - echo "found1=$(command_not_found)" + + # grep none none + + echo "found1=$(grep nope nope)" + echo "found2=$(command_not_found)" echo SHOULD NOT SHOW UP! }