I am writing a bash script to automate the build process. There are two major build blocks, one is an ant task and one is a plain old mvn clean install
. I want
Correct solution for unix/linux:
mvn clean install
rc=$?
if [ $rc -ne 0 ] ; then
echo Could not perform mvn clean install, exit code [$rc]; exit $rc
fi
The "if" statement itself is a command and if it is successful, it will reset the $? variable to 0. Same goes for echo. So, you have to use an intermediary local var, for example $rc to store the return code from "mvn clean install", then it can be passed to the "exit" command as well.