From d05b05db1c99982622ee70186c02d54f7d5cb5f9 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Sun, 11 Aug 2019 19:48:30 -0400 Subject: [PATCH] fix newlines in output --- log-once | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/log-once b/log-once index 5980b81..8f2fafe 100755 --- a/log-once +++ b/log-once @@ -17,7 +17,7 @@ append() { cat >> "$1" } log-once() { - local cbase c log x i out file + local cbase c log x i out file o cbase=/var/local/cron-errors [[ $EUID == 0 ]] || cbase=$HOME/cron-errors local help="Usage: log-once [OPTION]... LOG_NAME [LOG_MESSAGE] @@ -60,7 +60,7 @@ state in the same directory. # read stdin for anything which is not just a newline elif [[ ! -t 0 ]]; then while read -r x; do - output+=( $x ) + output+=( "$x" ) [[ $x ]] && log=true done fi @@ -80,12 +80,17 @@ state in the same directory. fi else file=${c}1 + if (( errors == 1 )); then + out="tee -a" + fi fi $out $file <<<"log-once: $(date "+%A, %B %d, %r")" if [[ $2 ]]; then $out $file <<<"$2" else - $out $file <<<"${output[@]}" + for o in "${output[@]}"; do + $out $file <<<"$o" + done $out $file fi return 0 -- 2.30.2