I want to create a script that, when called interactively, writes to stdout, but if called from another script and variable EVENT_LOGGER is defined by the calling script, writes to file EVENT_LOGGER.
There's probably an easy way to do this but it's just not coming to me. I can certainly add this logic to every place where output is generated:
if [[ -f $EVENT_LOGGER ]] then echo "Some message" >> $EVENT_LOGGER else echo "Some message" fi
but that'll add a lot of bulk to the script.
I was hoping I could do something like this instead:
if [[ ! -f $EVENT_LOGGER ]] then EVENT_LOGGER = "&1" fi
Then, all output commands would be:
echo "Some message" >> $EVENT_LOGGER
and they'd go to either the file or stdout, whichever EVENT_LOGGER point to.
That didn't work. Is there another way to have $EVENT_LOGGER resolve to stdout?
I'm using ksh93 on AIX 7.1