of pipes and shells

Only now I came across the following problem:

cmd1 | cmd2; echo $?
...where I'd like to have the errorcode of cmd1. I did not even expect that this issue was indeed so very common and documented. The solutions are even shell-specific, in short: * For bash or zsh, use $PIPESTATUS[n], resp. $pipestatus[n] * For any other shell the solution is way more complicated, but not impossible. See the FAQ again for all the gory details.