M P Mathugama
M P Mathugama

Reputation: 1418

Run makefile command from bash script and return error result code

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.

Upvotes: 1

Views: 1067

Answers (1)

Tanktalus
Tanktalus

Reputation: 22294

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

Upvotes: 7

Related Questions