# put commands in an array, e.g.: cat /etc/passwd | grep 1555 | grep sh
cmd=("cat /etc/passwd" "grep 1555" "grep sh")
# execute commands
eval "${cmd[0]}" | eval "${cmd[1]}" | eval "${cmd[2]}"
# save PIPESTATUS
save=("${PIPESTATUS[@]}")
# print returncode and failed command
for ((i=0;i<${#save[@]};i++)); do
[[ ${save[$i]} -ne 0 ]] && echo "${save[$i]}: ${cmd[$i]}"
done
unset save cmd
Saída (por exemplo):
1: grep 1555 1: grep sh