如何做一个汞更新或克隆在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.