1

I have a python makefile. I can run its commands from my bash script as below

local make_lint_output=""
make_lint_output="$( make test-unit  2>&1 )"
echo "${make_lint_output}"

local result=$? 
if (( result == 0 )); then
    return 1
fi 

But the problem is it always return $? as 0 even though make command exits with an error.

On failure part of the output is like below

E ImportError: No module named 'serial' !!!!!!!!!!!!!!!!!!! Interrupted: 3 errors during collection !!!!!!!!!!!!!!!!!!!! =========================== 3 error in 0.17 seconds ============================ Makefile:61: recipe for target 'test-power-control' failed

$? should be return other than 0 in this case. What am I missing here? I m running the bash script in unix machine.

1
  • 3
    It would be much simpler if you just wrote the script as ! make test-unit 2>&1. The output will then be written to stdout rather than captured by the shell before being written to stdout via echo, and the return value will be appropriately inverted as your if statement is doing. Commented Feb 27, 2019 at 16:30

1 Answer 1

7

echo is succeeding, and thus returning 0. You have to capture the return code before running another command that may clobber $? (before the echo).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.