I’ve had 0 exposure to BASH scripting and this is something I would love to learn. I can’t figure out how to run a conditional statement based on the output of ant debug on an Android build.
I would like to essentially say something like
if(`ant debug` == SUCCESS) {
// EXECUTE THESE COMMANDS
} else {
// EXECUTE THESE COMMANDS
}
How can I determine if the ant debug has passed or failed in shell script?
SOLUTION
Okay here is what I have:
ant clean
if ant debug; then
echo "success"
else
echo "failure"
fi
I’ll give a quick summary for you.
In Bash, conditionals are based around the exit codes of programs. An exit code of
0is accepted as true, while everything else is accepted as false.For example, the
trueprogram always exits with an exit code of0, which means that something like this is possible:Most commands honor this system, but not every program does. The first thing to check is what exit code ant returns on success and failure. You can check the exit code of the previous command with
$?.Here is an example:
If ant does honor the exit code system properly, then something like the following should be possible: