如果出错怎么退出bash功能? [英] How to exit bash function if error?

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

问题描述

我正在制作一个预先提交的脚本.看起来像这样:

I am making a presubmit script. It looks like this:

function presubmit() {
  gradle test android
  gradle test ios
  gradle test server
  git push origin master
}

如果任何测试失败,我希望函数退出,这样就不会将错误推送到git.怎么样?

I want the function to exit, if any of the tests fail so it won't push a bug to git. How?

推荐答案

我的方法是在函数中的每个命令(最后一个命令除外)之后添加&& \.

The way I do it is to add && \ after every command in the function (except the last one).

function presubmit() {
    gradle test android && \
    gradle test ios && \
    gradle test server && \
    git push origin master
}

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

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