PIPESTATUS_array_has_return_codes_of_commands_in_a_pipe

foo_unhappy(){
  local input_data=$(cat)
  echo -n "foo_unhappy(${input_data})"
  return 1
}

foo_happy(){
  echo -n "foo_happy($(cat))"
  return 0
}

main() {
  echo "start it off" | foo_unhappy | foo_unhappy | foo_happy | foo_unhappy | tee /tmp/out
  echo "PIPESTATUS: ${PIPESTATUS[@]}"
}

main "${@}" || exit 1

New liens added in the output for clarity

foo_unhappy(foo_happy(foo_unhappy(foo_unhappy(start it off))))

PIPESTATUS: 0 1 1 0 1 0

PIPESTATUS corresponds the the status of each elements within the pipe (starting with echo in the above example).


Backlinks