加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – 停止处理源文件并继续

发布时间:2020-12-15 21:10:11 所属栏目:安全 来源:网络整理
导读:当编写源于另一个文件的bash时,有时我想跳过处理,如果某些条件为真.现在,我要么: 在嵌套的if语句中包装整个子文件 在嵌套的if语句中包含对源文件的调用 这两种策略都有一些缺点.如果我能用这种代码样式编写脚本会好得多: main.sh echo "before". otherecho
当编写源于另一个文件的bash时,有时我想跳过处理,如果某些条件为真.现在,我要么:

>在嵌套的if语句中包装整个子文件
>在嵌套的if语句中包含对源文件的调用

这两种策略都有一些缺点.如果我能用这种代码样式编写脚本会好得多:

main.sh

echo "before"
. other
echo "after"

other.sh

# guard
if true; then
  # !! return to main somehow
fi
if true; then
  # !! return to main somehow
fi

# commands
echo "should never get here"

有没有办法做到这一点,以便调用main中的“after”行回显?

解决方法

是的,你可以回来:

if true; then
  return
fi

引用帮助返回:

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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读