From 4cb803cffa7cd6243844b28ef0728ca9da8b3022 Mon Sep 17 00:00:00 2001 From: pvincent Date: Sat, 11 Jul 2026 17:50:58 +0400 Subject: [PATCH] tee >/dev/null --- bin/bash-back | 13 ++----------- lib/utility.bash | 10 +++++----- useless.sh | 4 +++- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/bin/bash-back b/bin/bash-back index dc1f996..2735233 100755 --- a/bin/bash-back +++ b/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:") # 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 diff --git a/lib/utility.bash b/lib/utility.bash index 2dc7102..c583fa5 100755 --- a/lib/utility.bash +++ b/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 diff --git a/useless.sh b/useless.sh index 67eda1b..e8dffa5 100755 --- a/useless.sh +++ b/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