[英]Using git command with -q but doesn't stay quiet when failed?
I'm creating a script where I clone git repositories. 我正在创建一个脚本,用于克隆git存储库。 I want my script to print "Cloning OK" when the cloning is successful and "Cloning FAILED" when it fails and ignore all command output for both occasions.
我希望脚本在克隆成功时打印“ Cloning OK”,在克隆失败时打印“ Cloning FAILED”,并且在两种情况下都忽略所有命令输出。 This is the code I'm using:
这是我正在使用的代码:
(git clone -q "$url" && echo "$url: Cloning OK") || echo "$url: Cloning FAILED" >&2
The problem is that for successful cloning the command stays quiet but for unsuccessful cloning it doesn't. 问题在于,成功克隆命令后,命令将保持安静,但克隆失败后,命令将保持安静。 How can I make it quiet for both occasions?
如何在两次场合都保持安静?
Thanks in advance 提前致谢
You have to silence the command by sending standard output and standard error to somewhere other than the terminal . 您必须通过将标准输出和标准错误发送到终端以外的其他位置来使命令静音。 This is easiest achieved by sending both output streams to /dev/null:
通过将两个输出流都发送到/ dev / null最容易实现:
(git clone -q "$url" >/dev/null 2>&1 && …
Please note that silencing this command will make your script harder to debug. 请注意,使此命令静音将使脚本更难调试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.