【记录】shell脚本简写
#!/bin/bash ###shell脚本开头 if [ $# != 2 ]; ###参数长度不为2,输出语句 exit 1; ###退出 if [ $? -ne 0 ]; ###上一步执行不成功 fi ###结束
#!/bin/bash if [ $# != 2 ]; then echo "命令错误:./deploy.sh 压缩文件名 压缩文件解压后路径" echo "e.g.: ./deploy.sh dist.zip baseline" exit 1; fi zipname=$1 filename=$2 echo "开始解压"${zipname}"新文件夹"${filename}-new unzip ${zipname} -d ${filename}-new if [ $? -ne 0 ]; then echo "解压失败" exit 1; fi echo "开始移动生成newone" mv ${filename}-new/dist ${filename}-newone if [ $? -ne 0 ]; then echo "移动生成newone失败" exit 1; fi echo "删除-new" rm -rf ${filename}-new if [ $? -ne 0 ]; then echo "删除-new失败" exit 1; fi echo "删除-bak" rm -rf ${filename}-bak if [ $? -ne 0 ]; then echo "删除-bak失败" echo "不存在-back,跳过" fi echo "生成-bak" mv ${filename} ${filename}-bak if [ $? -ne 0 ]; then echo "生成-bak失败" echo "不存在源文件,跳过" fi echo "newone重命名" mv ${filename}-newone ${filename} if [ $? -ne 0 ]; then echo "newone重命名失败" exit 1; fi