Bash Find out the exit codes of all piped commands

Originally published at: https://www.cyberciti.biz/faq/unix-linux-bash-find-out-the-exit-codes-of-all-piped-commands/

How do I get exit status of process that’s piped to another (for e.g. ‘netstat -tulpn | grep nginx’) on a Linux or Unix-like system using a bash shell?