I have a script that attempts to log its actions. There's a single tee in there that does all of this. Currently, when the $LOG_FILE cannot be written to the script dies. Instead, I would like it to just not write to a log file.
In the script, the part that's logged looks something like this:
for foo in "${array_of_foos[@]"; do
{get bar from foo} | sort -u
done | xargs -n 100 -P 20 bar_processor.sh |& tee "$LOG_FILE"
When the user does not want to write a log file, can I just set LOG_FILE=/dev/null
or is there some better way to handle that? Note that this script is not and will never be run as root.
$LOG_FILE
can't be written to? I don't thinktee
should just up and die even itself if it can't write to a file, let alone kill the whole script. Unless you're usingset -e
, but you didn't mention that. – ilkkachu Sep 10 '21 at 09:29