1

I've got a test script that repeatedly builds a library under different configurations. It also tee's the output for postmortem failures:

$MAKE" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
if [ "$?" -ne "0" ]; then
    echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
fi

The script is not working as intended because the test is capturing tee's return code, and not make's return code.

I looked at the man pages for tee(1), but I don't see an option to have it restore a return code.

How can I capture the return code from make before tee smashes it?

  • Thanks @steeldriver. I don't really understand the significance of the braces in ${PIPESTATUS[0]}. Would I simply use if [ "${PIPESTATUS[0]}" -ne "0" ]; then ...? Or do I need something else within the script? (My apologies; I'm a C/C++/Objective C guy). –  Dec 31 '15 at 16:02
  • since PIPESTATUS takes you into bash land, you may as well use a bash arithmetic expression, so if (( PIPESTATUS[0] )) is equivalent to if [ "${PIPESTATUS[0]}" -ne "0" ] – iruvar Dec 31 '15 at 16:25

0 Answers0