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
# CONSTANTS
DEBUG=${BASH_BACK_DEBUG:-false}
TMP_ERROR=$(mktemp -t "$(basename $0).XXXXXXXX" --tmpdir=/run/user/$(id -u))
DEBUG=${BASH_BACK_DEBUG:-false}
SCRIPT=$1
# FUNCTIONS
@ -78,15 +78,6 @@ function on_exit {
stack_summary+=("ERROR $code: [$message]")
fi
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]* .*\$"
[[ "$last_error" =~ $regex ]] || stack_summary+=("ERROR $code:") # <undefined>
fi
@ -145,7 +136,7 @@ trap 'on_exit $?' ERR TERM INT EXIT
trap 'on_return' DEBUG
# magic FD
exec 3>$TMP_ERROR 4>/dev/stderr
exec 3> >(tee $TMP_ERROR >/dev/null) 4>/dev/stderr
$DEBUG && >/dev/tty echo '---stdout---'
source $SCRIPT 2>&3
success

10
lib/utility.bash

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

4
useless.sh

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

Loading…
Cancel
Save