如何做一个汞更新或克隆在bash的一条线? [英] How to do a hg update or clone in one line of bash?

查看:151
本文介绍了如何做一个汞更新或克隆在bash的一条线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找一个选项,做一个信息库中的汞更新或克隆它,如果它不存在。因此命令只有当出事了(克隆或更新)失败。

I am looking for an option to do an hg update on a repository or to clone it if it doesn't exist. So the command has to fail only if something went wrong (clone or update).

已经在庆典,preferably工作,如果你有设置-e 已配置。

That has to work in bash, preferably if you have the set -e already configured.

推荐答案

在bash中析取运算符, || ,能做到这样的场景:尝试的第一个命令,如果它失败尝试第二个命令,如果的的失败则返回错误code。具体到这个问题,

The disjunction operator in bash, ||, can do this scenario: try first command, if it fails try second command, if that fails return the error code. Specific to this question,

hg update || hg clone <source>

将尝试更新;如果失败,它会尝试克隆。如果克隆失败,整条生产线将退出克隆的错误code。

would try the update; if it fails, it would try to clone. If cloning fails, the whole line exits with clone's error code.

我想不看到在输出的任何错误,当命令成功。

I would like not to see any errors in the output when the command succeeds.

为什么会发生错误时,该命令执行成功?

Why should there be errors when the command succeeds?

您可以杀死由输出&GT;的/ dev / null的;你可以杀死的错误 2 - ;的/ dev / null的;是否每个组件分开,或者由封闭括号中的整条生产线后把重定向。

You can kill the output by >/dev/null; you can kill the errors by 2>/dev/null; whether on each component separately, or by enclosing the whole line in parentheses and putting redirection after.

这篇关于如何做一个汞更新或克隆在bash的一条线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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