如何检测如果一个Git克隆在bash脚本失败 [英] How to detect if a git clone failed in a bash script

查看:706
本文介绍了如何检测如果一个Git克隆在bash脚本失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能判断一个 git的克隆在bash脚本有一个错误?

How can I tell if a git clone had an error in a bash script?

git clone git@github.com:my-username/my-repo.git

如果有一个错误,我想简单退出1 ;

If there was an error, I want to simply exit 1;

推荐答案

下面是一些常见的形式。这是最好的选择取决于你怎么做。您可以使用一个脚本任何子集或将它们组合没有它是坏的风格。

Here are some common forms. Which is the best to choose depends on what you do. You can use any subset or combination of them in a single script without it being bad style.

if ! failingcommand
then
    echo >&2 message
    exit 1
fi


failingcommand
ret=$?
if ! test "$ret" -eq 0
then
    echo >&2 "command failed with exit status $ret"
    exit 1
fi


failingcommand || exit "$?"


failingcommand || { echo >&2 "failed with $?"; exit 1; }

这篇关于如何检测如果一个Git克隆在bash脚本失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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