PIPESTATUS
PIPESTATUS: array that contains the return codes of the 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).
From Bash Manual
PIPESTATUS : An array variable (see Arrays below) containing a list of exit status values from the processes in the most-recently-executed foreground pipeline (which may contain only a single command).
Children
Backlinks