I want to run the command mvn clean in a bash script. But I want to put it in an if statement. If the clean does not run properly I would like to exit out of the bash script wit
I prefer to use a variable to capture the return code. Improves readability and allows running additional commands without fear of clobbering return code value:
mvn clean
MVN_RTN=$?
if [ "${MVN_RTN}" -ne 0 ]; then
echo "Maven returned failure code ${MVN_RTN}"
exit 1
fi