Skip to content

Latest commit

 

History

History
33 lines (25 loc) · 738 Bytes

exit_a_function_in_bash.md

File metadata and controls

33 lines (25 loc) · 738 Bytes

在Shell中,会使用

fuction func_1(){
    ....
}

如果在function中,有某些判断后结束function不再执行后面部分,例如:

# Start script
Do scripty stuff here
Ok now lets call FUNCT
FUNCT
Here is A to come back to

function FUNCT {
  if [ blah is false ]; then
    exit the function and go up to A
  else
    keep running the function
  fi
}

则应该使用return [n]方法,从help return可以看到:

return可以从一个shell函数中返回指定的n数值。如果没有指定n,则返回值是函数或脚本最后执行命令的返回值。

参考