I have this:

node ${SUMAN_RUNNABLE} | tee -a run.sh.log

but it looks like the exit code is always 0 because tee is providing the code not the node executable.

Is there a way to capture the exit code from the node executable in such a scenario?


1 Answer 1


From https://stackoverflow.com/a/1221870/5020949:

There is an internal Bash variable called $PIPESTATUS; it’s an array that holds the exit status of each command in your last foreground pipeline of commands.

<command> | tee out.txt ; test ${PIPESTATUS[0]} -eq 0

Or another alternative which also works with other shells (like zsh) would be to enable pipefail:

set -o pipefail

The first option does not work with zsh due to a little bit different syntax.

Not the answer you're looking for? Browse other questions tagged or ask your own question.