#!/usr/pkg/bin/bash # logfile is $1 or ./log f="${1:-./log}" # if file exists we'll keep it's content [[ -f "$f" ]] && l="$f" # use date in UTC d="$(env TZ=UTC date +%F)" # Bash moment read -rd '' m < <( cat <(printf "[$d] ") <(read -rep "[$d] "; echo "$REPLY") $l ) # overwrite the file only after cating the whole thing together to # eliminate pipeline weirdness echo "$m" > "$f"