I am using echo var >> "${log_file}" 2>&1 to redirect stdout and stderr to a file path stored in the ${log_file}. But when the variable is empty, I would like to send stdout and stderr to their default/standard locations.
For example, if the variable ${log_file} is empty, the output should not go to a file, but to stdout. How I should set the ${log_file} variable value to make it output to stdout?
I tried setting to &1 (the stdout file descriptor)
if [[ -z "${log_file}" ]]; then
log_file=&1
fi
echo var >> "${log_file}" 2>&1
But it did not work and bash threw this error:
No such file or directory
1: command not found