Browse Source

poc starting1

main
pvincent 2 weeks ago
parent
commit
473bed362e
  1. 48
      poc
  2. 7
      test/stub/scenario.bash

48
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

7
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!
}

Loading…
Cancel
Save