linux – 如何检测git克隆在bash脚本中是否失败

如何知道git克隆在bash脚本中是否有错误
git clone git@github.com:my-username/my-repo.git

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

解决方法

这是一些常见的形式.哪个是最好的选择取决于你做什么.您可以在单个脚本中使用任何子集或组合,而不是不良风格.
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; }

相关文章

1、安装Apache。 1)执行如下命令,安装Apache服务及其扩展包...
一、先说一下用ansible批量采集机器信息的实现办法: 1、先把...
安装配置 1. 安装vsftpd 检查是否安装了vsftpd # rpm -qa | ...
如何抑制stable_secret读取关键的“net.ipv6.conf.all.stabl...
1 删除0字节文件 find -type f -size 0 -exec rm -rf {} ...
## 步骤 1:安装必要的软件包 首先,需要确保系统已安装 `dh...