0

This question already has an answer here:

I have this:

node ${SUMAN_RUNNABLE} | tee -a run.sh.log
EXIT_CODE=$?;

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?

marked as duplicate by Jenny D, countermode, Kusalananda bash Jun 27 '17 at 9:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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.