Bash, Best logic for ending a function but not ending the script
Function being called multiple times
_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 c开发者_StackOverflow社区om5 com6 com7 com8 20 21
I cant think what the answer might be.... :-|
Use return
statement:
From 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.
You can use the return
statement in _TestFun. And modify the script to have an exit after it has finished calling _TestFun
_TestFun com1 com2 com3 com4 10 11
_TestFun com5 com6 com7 com8 20 21
exit <status>;
精彩评论