脚本
if type -p mvn; thenecho "maven has been installed."elsecd /home/zenglgwget https://dlcdn.apache.org/maven/maven-3/3.9.5/binaries/apache-maven-3.9.5-bin.tar.gz --no-check-certificatetar vxf apache-maven-3.9.5-bin.tar.gz rm -rf /usr/local/maven3mv apache-maven-3.9.5 /usr/local/maven3#设置mvn的环境变量checkMvnExist(){mvn1=$(grep -n "MAVEN_HOME=.*" /etc/profile | cut -f1 -d':')if [ -n "$mvn1" ];thensed -i "${mvn1}d" /etc/profilefimvn2=$(grep -n "export MAVEN_HOME" /etc/profile | cut -f1 -d':')if [ -n "$mvn2" ];thensed -i "${mvn2}d" /etc/profilefimvn3=$(grep -n "export PATH=${PATH}:${MAVEN_HOME}/bin" /etc/profile | cut -f1 -d':')if [ -n "$mvn3" ];thensed -i "${mvn3}d" /etc/profilefi}checkMvnExistecho "MAVEN_HOME=/usr/local/maven3" >> /etc/profilesource /etc/profileecho "export MAVEN_HOME" >> /etc/profileif [[ ${PATH} =~ ${MAVEN_HOME}/bin ]]; thenecho " MAVEN_HOME has been set"elseecho "export PATH=${PATH}:${MAVEN_HOME}/bin" >> /etc/profileecho "setting MAVEN_HOME path successful."fi#保存刷新source /etc/profilefi
mvn -v
安装成功