Browse Source

tee >/dev/null

main
pvincent 1 week ago
parent
commit
4cb803cffa
  1. 13
      bin/bash-back
  2. 10
      lib/utility.bash
  3. 4
      useless.sh

13
bin/bash-back

@ -1,8 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# CONSTANTS # CONSTANTS
DEBUG=${BASH_BACK_DEBUG:-false}
TMP_ERROR=$(mktemp -t "$(basename $0).XXXXXXXX" --tmpdir=/run/user/$(id -u)) TMP_ERROR=$(mktemp -t "$(basename $0).XXXXXXXX" --tmpdir=/run/user/$(id -u))
DEBUG=${BASH_BACK_DEBUG:-false}
SCRIPT=$1 SCRIPT=$1
# FUNCTIONS # FUNCTIONS
@ -78,15 +78,6 @@ function on_exit {
stack_summary+=("ERROR $code: [$message]") stack_summary+=("ERROR $code: [$message]")
fi fi
else else
# FIXME: should either
# 1. grab the whole stacktrace, then print back again
# 2. or FLUSH previous stderr
# because previous stderr might disappear from the first script when calling subprocess!
#
# ```bash
# >&2 echo some trace in stderr
# lib/utility.bash # which contains error
# ```
regex="^ .*:[0-9]* .*\$" regex="^ .*:[0-9]* .*\$"
[[ "$last_error" =~ $regex ]] || stack_summary+=("ERROR $code:") # <undefined> [[ "$last_error" =~ $regex ]] || stack_summary+=("ERROR $code:") # <undefined>
fi fi
@ -145,7 +136,7 @@ trap 'on_exit $?' ERR TERM INT EXIT
trap 'on_return' DEBUG trap 'on_return' DEBUG
# magic FD # magic FD
exec 3>$TMP_ERROR 4>/dev/stderr
exec 3> >(tee $TMP_ERROR >/dev/null) 4>/dev/stderr
$DEBUG && >/dev/tty echo '---stdout---' $DEBUG && >/dev/tty echo '---stdout---'
source $SCRIPT 2>&3 source $SCRIPT 2>&3
success success

10
lib/utility.bash

@ -3,17 +3,17 @@
function blabla { function blabla {
echo IN blabla OUT echo IN blabla OUT
>&2 echo stderr from utility
suite suite
echo $?
} }
function suite { function suite {
return 7
exit 10 # youpi
echo $nope echo $nope
return
exit
command_not_found command_not_found
exit 10 # youpi
return 7
exit
return
} }
blabla blabla

4
useless.sh

@ -31,8 +31,10 @@ function F3 {
echo start of useless echo start of useless
F3 F3
>&2 echo some trace in stderr
>&2 echo some trace in stderr1
lib/utility.bash lib/utility.bash
>&2 echo some trace in stderr2
. lib/utility.bash . lib/utility.bash
main main

Loading…
Cancel
Save