$PIPESTATUS
The exit status of every link in the pipe, not just the last.
In a pipeline, $? only sees the last link — grep x file | sort returns 0 even with grep empty-handed. PIPESTATUS is the array with each link's status, in order.
It is volatile like few others: any following command replaces it, so copy first — ecos=("${PIPESTATUS[@]}"). In zsh the same ghost answers to pipestatus, in lowercase.
$ grep rainha vazio.txt | sort
$ echo "${PIPESTATUS[@]}"
1 0