5
votes
4answers
144 views

Can a program next in a pipeline see the exit code of the previous program?

I would like to make a pipeline of Bash scripts like this prog1 | prog2 such that prog2 can see the exit code of prog1 and act differently based on that information. Is this possible?
2
votes
2answers
397 views

.DELETE_ON_ERROR behavior with make and pipelines

The .DELETE_ON_ERROR target will tell make to delete a target if a rule fails. But this doesn't work for pipelines, because the exit status value $? holds the value of the last program in the ...
40
votes
12answers
12k views

Get exit status of process that's piped to another

I have two processes foo and bar, connected with a pipe: $ foo | bar bar always exits 0; I'm interested in the exit code of foo. Is there any way to get at it?