I have bash code like this (Mac OS X):
foo.sh | tee foo.log
echo $?
The problem is that $? contains the exit code of tee and not the exit code of foo.sh. How do I get the exit code of foo.sh?
I have bash code like this (Mac OS X):
foo.sh | tee foo.log
echo $?
The problem is that $? contains the exit code of tee and not the exit code of foo.sh. How do I get the exit code of foo.sh?
The environment variable
$PIPESTATUS
is an array of exit statuses for all processes in a pipeline.Also use a subshell: