From 212dd663d0fbc436a14b8fe2cfa58b07adbeee02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E7=91=9E?= <807495056@qq.com> Date: Wed, 26 Feb 2020 18:34:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20'bin/func.sh'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 方法里面的exit改为return --- bin/func.sh | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/bin/func.sh b/bin/func.sh index 42732d7..e3dc22a 100644 --- a/bin/func.sh +++ b/bin/func.sh @@ -10,14 +10,14 @@ function get_config() { # 判断是否传入空 if [ 'a'$1 == 'a' ] || [ 'a'$2 == 'a' ];then echo '没有传入配置项' - exit 1 + return 1 fi # 获取类型 cfg_type=`cat $CONFIG_PATH|grep '\['$1'\]'` cfg_start=`grep '\['$1'\]' $CONFIG_PATH -n|awk -F ':' '{print $1}'` if [ 'a'$cfg_type == 'a' ];then echo '配置['$1']不存在' - exit 1 + return 1 fi cfg_data='' while read line;do @@ -38,9 +38,10 @@ function get_config() { if [ 'a'$cfg_data == 'a' ];then echo '配置['$1']里面项'$2'不存在' - exit 1 + return 1 fi echo $cfg_data + return 0 } # 获取路径文件名 @@ -49,6 +50,7 @@ function get_config() { function get_path_name() { fun_file_path=$1 echo ${fun_file_path##*/} + return 0 } # 获取路径文件夹 @@ -57,6 +59,7 @@ function get_path_name() { function get_path_dir() { fun_file_path=$1 echo ${fun_file_path%/*} + return 0 } # 获取路径文件后缀 @@ -69,6 +72,7 @@ function get_file_suffix() { fun_suffix=`echo $1|awk -F '.' '{print $(NF-1)}'`'.'`echo $1|awk -F '.' '{print $NF}'` fi echo $fun_suffix + return 0 } # 获取路径文件的文件夹 @@ -79,6 +83,7 @@ function get_file_dir() { fun_suffix=`get_file_suffix $1` fun_file_dir=`echo $1|awk -F $fun_suffix '{print $1}'` echo ${fun_file_dir%*.} + return 0 } # 解压文件 @@ -87,12 +92,12 @@ function decompression() { # 判断是否传入空 if [ 'a'$1 == 'a' ];then echo '没有传入压缩包地址' - exit 1 + return 1 fi # 判断文件是否存在 if [ ! -f $1 ];then echo $1'文件不存在' - exit 1 + return 1 fi # 删除原解压 zip_file_dir=`get_file_dir $1` @@ -108,8 +113,9 @@ function decompression() { unzip $zip_path_name else echo $zip_suffix'格式的压缩文件无法解压' - exit 1 + return 1 fi + return 0 } # 存在http且下载 @@ -124,10 +130,11 @@ function exists_download() { wget -P $PWD'/package' $1 if [ $? != 0 ];then echo $1'下载失败' - exit 1 + return 1 fi fi echo $PWD'/package/'$down_path_name + return 0 } # 修改文件 @@ -138,7 +145,7 @@ function update_file() { update_name=$3 if [ ! -f $update_file_url ];then echo $update_file_url'文件不存在' - exit 1 + return 1 fi # 文件备份 if [ ! -f $update_file_url'.bak' ];then @@ -158,6 +165,7 @@ function update_file() { done < $update_file_url'.tmp' IFS=$SAVEIFS rm -rf $update_file_url'.tmp' + return 0 } # 追加文件 @@ -167,9 +175,10 @@ function append_file() { append_name=$2 if [ ! -f $append_file_url ];then echo $append_file_url'文件不存在' - exit 1 + return 1 fi if [ `cat $append_file_url|grep "$append_name"|wc -l` == 0 ];then echo "$append_name" >> $append_file_url fi + return 0 }