Jus*_*tin 15 linux git bash shell
如何判断git clonebash脚本中是否有错误?
git clone git@github.com:my-username/my-repo.git
如果有错误,我想简单地说exit 1;
Jo *_* So 23
这是一些常见的形式.哪个是最好的选择取决于你做什么.您可以在单个脚本中使用它们的任何子集或组合,而不会出现错误的样式.
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 clone git@github.com:my-username/my-repo.git || exit 1
或者执行:
exec git clone git@github.com:my-username/my-repo.git
后者将允许克隆操作接管shell进程,如果失败,则返回错误.你可以在这里找到更多关于exec的信息.
方法一:
git clone git@github.com:my-username/my-repo.git || exit 1
方法二:
if ! (git clone git@github.com:my-username/my-repo.git) then
    exit 1
    # Put Failure actions here...
else
    echo "Success"
    # Put Success actions here...
fi
| 归档时间: | 
 | 
| 查看次数: | 9668 次 | 
| 最近记录: |