Get exit status of process that's piped to another | echo "${PIPESTATUS[0]} ${PIPESTATUS[1]}"
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?
If you are using
bash
, you can use the PIPESTATUS
array variable to get the exit status of each element of the pipeline.$ false | true
$ echo "${PIPESTATUS[0]} ${PIPESTATUS[1]}"
1 0
Comments
Post a Comment