I have a script called script1 which returns a result code. However the script itself also calls other scripts which frequently display important messages we need to capture. Unfortunately
script1 | tee -a LOGFILE
captures the messages, but loses the result code, because the act of calling tee resets it to 0. We need to be able to both see the messages at runtime and also keep them stored in LOGFILE. How can I still do both of these and yet not destroy the rc from script1?