Bash,结束函数但不结束脚本的最佳逻辑

时间:2011-06-27 09:55:05

标签: bash function

多次调用函数

_TestFun() {
local arg1=${1}
local arg2=${2}
local arg3=${3}
local arg4=${4}
local timearg1=${5}
local timearg2=${6}

testDATE=$(date |awk {' print $4 '}|cut -b 1-2)
 if [[ $testDATE == ${timearg1} ]] || [[ $testDATE == {timearg2} ]]; then
# exit ### I dont want to exit the script just this function if testDATE is true
 else
 continue
 fi

command1 ${arg4}" ${arg1}@${arg2} ${arg3}
}

_TestFun com1 com2 com3 com4 10 11
_TestFun com5 com6 com7 com8 20 21

我想不出答案可能是什么......: - |

2 个答案:

答案 0 :(得分:4)

使用return声明:

来自man bash

 If  the  builtin command return is executed in a function, the function
       completes and execution resumes with the next command after  the  func-
       tion  call.

答案 1 :(得分:1)

您可以在_TestFun中使用return语句。并在完成调用_TestFun

后修改脚本以退出
_TestFun com1 com2 com3 com4 10 11
_TestFun com5 com6 com7 com8 20 21
exit <status>;