If you aren’t aware, there are a lot of useful internal BASH variables, some of which can be found here:
One of particular use is PIPESTATUS. This can be very useful if you need to pipe a commands output to another command, and you need to check the return code.
my_super_command | tee my.log
If my_super_command fails and you print the last return code you will see everything worked just fine:
However, if you print the PIPESTATUS, then you can see the error:
I like apples.