[英]I want to save the output of git command to a variable in bash script
The way I use var=$(git push origin main)
I tried git push origin main > tmp.txt
我使用
var=$(git push origin main)
的方式我试过git push origin main > tmp.txt
and still do the output to the terminal I don't want it to begin output and also I want to store it onto the variable, but the variable is empty并且仍然对终端执行 output 我不希望它开始 output 并且我想将它存储到变量中,但变量为空
Git prints some of its output to stderr
, the standard error stream. Git 将它的一些 output 打印到
stderr
,标准错误 stream。 If you want to capture it in a variable you need to redirect the standard error stream to the standard output stream: var=$(git push origin main 2>&1)
.如果要在变量中捕获它,则需要将标准错误 stream 重定向到标准 output stream:
var=$(git push origin main 2>&1)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.