Use System Environment Variable${PIPESTATUS[X]}. $ exit 1 | exit 2 | exit 3 | exit 0 $ echo ${PIPESTATUS[@]} 1 2 3 0 Also, the exit code of the normal end is 0, and the one of the abnormal end is Greater than 0 in Bash. Tags All Bash