停在第一个错误上[重复]

本文翻译自:Stop on first error [duplicate]

Possible Duplicate: 可能重复:
Automatic exit from bash shell script on error 错误时自动退出bash shell脚本

How can I have bash stop on the first command failure, without putting stuff like this all through my code? 如何让bash在第一个命令失败时停止,而又不会在我的代码中放这样的东西呢?

some_prog || exit 1
some_other_prog || exit 1

#1楼

参考:https://stackoom.com/question/ezSK/停在第一个错误上-重复


#2楼

Maybe you want set -e : 也许你想set -e

www.davidpashley.com/articles/writing-robust-shell-scripts.html#id2382181 : www.davidpashley.com/articles/writing-robust-shell-scripts.html#id2382181

This tells bash that it should exit the script if any statement returns a non-true return value. 这告诉bash如果有任何语句返回非真实的返回值,则应退出脚本。 The benefit of using -e is that it prevents errors snowballing into serious issues when they could have been caught earlier. 使用-e的好处是,它可以防止错误在可能早些时候被捕获时就滚入严重的问题。 Again, for readability you may want to use set -o errexit. 同样,出于可读性考虑,您可能需要使用set -o errexit。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值