I'm writing a bash script that I want by default to output everything into a log file. However, I also want the ability to output it to the calling terminal by request (e.g. parameter) INSTEAD of the log file (so tee
is out I believe). Does anyone know of a simple way to do this?
It would be nice if the parameter could be a custom log file OR a reference to a calling terminal.
I'm thinking along the lines of this: (pseudo-code)
#!/bin/bash
if [ ! $1 ]; then
OUT="default.log"
else
OUT=$1
fi
#then do this to every call in the script
commands [param] [param] >> ${OUT}
I guess more of what I am asking is, is there an easy way to reference the current terminal for output to? So I could do ./script.sh
, ./script.sh custom.log
or script.sh TERMINAL
?