Is there a more elegant way to make dual output (display on standard output and append to a file) while I'm executing a shell script, besides duplicating the echo command for every string?
#!/bin/ksh
LOG_FILE=/tmp/${0##*/}.log
LogMsg() {
#Redirecting the Output just to the Log file.
#print "$@:$(date +%d/%m/%y:%H:%M:%S)" >> $LOG_FILE
#Redirection to stdout and file.
print "$@:$(date +%d/%m/%y:%H:%M:%S)" | tee -a $LOG_FILE
}
CallB() {
LogMsg "Entering CallB routine"
}
Main() {
LogMsg "Entering the function"
CallB
}
#Call the Main Function here.
Main
Just in case in future after having tested code you may have to remove logging,using the above approach you have just haveto change the LOG_FILE=/dev/null or LogMsg function.