From 6c6e8281d5f16c4446562762c6422eb0163aa3a1 Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Wed, 29 Mar 2023 08:15:55 +0000 Subject: [PATCH] Fix log_loop emitting an empty line on zero output --- codearchiver-bot | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codearchiver-bot b/codearchiver-bot index d4fc2e6..09f9a6e 100755 --- a/codearchiver-bot +++ b/codearchiver-bot @@ -27,8 +27,8 @@ function log { function log_loop { prefix="$1" - # If the output does not end with a LF, add one. Then replace CRLF with LF and replace remaining CR with LF. - { lastchar="$(tee /dev/fd/42 | tail -c 1 | xxd -p)"; if [[ "${lastchar}" != '0a' ]]; then printf '\n'; fi } 42>&1 | + # If there is output and it does not end with a LF, add one. Then replace CRLF with LF and replace remaining CR with LF. + { lastchar="$(tee /dev/fd/42 | tail -c 1 | xxd -p)"; if [[ "${lastchar}" && "${lastchar}" != '0a' ]]; then printf '\n'; fi } 42>&1 | sed -u 's,\r$,,; s,\r,\n,g' | while IFS= read -r line; do log "${prefix}${line}"; done }