The bash shell uses the exit status of the last command in the
pipeline as the exit status of the entire pipeline. The other statuses
are available via the PIPESTATUS variable, which is an array variable
containing the exit statuses of all of the commands in the pipeline.
Example:
command1 | command2
if [ "${PIPESTATUS[@]}" != "0 0" ]
then
echo "*** ERROR ***"
fi