I'm writing a shell script that executes a command. I want to save both stdout and stderr to the same log file + print to sceen and at the same time catch if there is an error. What I have so far is:
set -o pipefail
command arg1 arg2 2>&1 | tee logFile.log || errorsFound=1
if [[ $errorsFound == 1 ]]; then
echo "command failed!"
When I run the shell script the logFile.log is created and seems to contain all the output information. However, the variable "errorsFound" always turns to 1, even though there are no errors from the command. Have I set this up wrong?
Thanks in advance!