mvn in bash script if statement

前端 未结 3 1759
北荒
北荒 2021-02-15 18:06

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

3条回答
  •  旧巷少年郎
    2021-02-15 18:29

    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
    

提交回复
热议问题