bash: redirect (and append) stdout and stderr to file and terminal and get proper exit status September 13, 2023 by Tarik Perhaps you could put the exit value from PIPESTATUS into $? command 2>&1 | tee -a file.txt ; ( exit ${PIPESTATUS} )