3

To compile my project and to check if it's good or not, I want to print out the status message after make command. Which one should I use?

make && echo “Success” || echo “Fail”
make || echo “Fail” && echo “Success”
make || echo “Success” && echo “Fail”

I should use the first one right?

1 Answer 1

5

Experiment - replace 'make' with 'true' and 'false' (these are commands that do nothing except to return the implied status) and try to understand why you get the results you do.

edit: Here is the sort of experiment I have in mind:

for cmd in true false ; do
    printf "\n%s\n" $cmd
    $cmd && echo "1 Success"    || echo "1 Fail"
    $cmd || echo "2 Fail"       && echo "2 Success"
    $cmd || echo "3 Success"    && echo "3 Fail"
done

but for make, you should find out what return values the version of make you use returns - here's an excerpt from what I'm running:

EXIT STATUS
GNU make exits with a status of zero if all makefiles were successfully parsed and no targets that were built failed.
A status of one will be returned if the -q flag was used and make determines that a target needs to be rebuilt.
A status of two will be returned if any errors were encountered.

and a script with a similar intent that handles those return values:

for cmd in true false ; do
# make;
$cmd
status=$?;
case "$status" in
    0) echo 'all makefiles parsed, no builds failed'; ;;
    1) echo 'target needs to be rebuilt'; ;;
    2) echo 'error(s) in make'; ;;
    *) echo "make returned unknown status: $status"; ;;
esac;
done
return $status

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .