From: Ian Kelling Date: Sun, 11 Aug 2019 23:48:30 +0000 (-0400) Subject: fix newlines in output X-Git-Url: https://iankelling.org/git/?a=commitdiff_plain;h=d05b05db1c99982622ee70186c02d54f7d5cb5f9;p=log-quiet fix newlines in output --- 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