简体   繁体   English

在-q中使用git命令,但失败时不会保持安静?

[英]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? 如何在两次场合都保持安静?

output of command 命令输出

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.

相关问题 文件所有权不会停留在git分支更改上 - file ownership doesn't stay on git branch change 当我包含git bash命令行时,pwd在Windows中不起作用? - pwd doesn't work in windows when I include the git bash command line? 使用 list 命令时 GDB 不显示源代码 - GDB doesn't show source code when using list command 在grep –q上使用变量不会产生发现 - Using variables on grep –q doesn’t produce founds 由于 tee 命令,Maven 在 jekins 作业中的安装不会失败 - Maven install in jekins job doesn't failed because of tee command git cli 和这个命令中的选项“-q”有什么作用? - What does the option " -q" in git cli and this command do? 使用SharpSSH库时,Linux命令无法通过.NET执行 - Linux Command Doesn't work from .NET execution when using SharpSSH library 当使用php exec()运行shell脚本时,一个脚本工作(它只是git状态)而一个脚本没有(它执行git checkout)。 怎么会? - When using php exec() to run shell scripts, one script works (which simply does git status) and one doesn't (which does git checkout). How come? 从sshj启动时,来自控制台的命令未运行 - Command from console doesn't run when launched from sshj 当 src 文件不存在时,避免使用 cat 命令出错 - Avoid error with cat command when src file doesn't exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM