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?
${PIPESTATUS[0]}. Would I simply useif [ "${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:02PIPESTATUStakes you intobashland, you may as well use a bash arithmetic expression, soif (( PIPESTATUS[0] ))is equivalent toif [ "${PIPESTATUS[0]}" -ne "0" ]– iruvar Dec 31 '15 at 16:25