如何退出在bash功能 [英] How to exit a function in bash

查看:392
本文介绍了如何退出在bash功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你将如何退出的功能了,如果条件而不杀死整个脚本真的,只是返回到你调用该函数之前。

示例

 #启动脚本
这里做的东西指令码
好了,现在让我们称之为FUNCT
FUNCT
这里是一个回来功能FUNCT {
  如果[嗒嗒是假]。然后
    退出功能,并上升到一个
  其他
    继续运行功能
  科幻
}


解决方案

使用:

 回归[N]

帮助返回


  

收益:返回[N]

 从shell函数返回。原因函数或执行的脚本与返回值退出
如果省略n由N指定,返回状态是的
最后一个命令函数或脚本内执行。退出状态:
如果外壳没有执行的函数或脚本返回N,或者失败。


How would you exit out of a function if a condition is true without killing the whole script, just return back to before you called the function.

Example

# 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
}

解决方案

Use:

return [n]

From help return

return: return [n]

Return from a shell function.

Causes a function or sourced script to exit with the return value
specified by N.  If N is omitted, the return status is that of the
last command executed within the function or script.

Exit Status:
Returns N, or failure if the shell is not executing a function or script.

这篇关于如何退出在bash功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆