【问题标题】:bash - Unable to save entire output of git clone into a variable [duplicate]bash - 无法将 git clone 的整个输出保存到变量中[重复]
【发布时间】:2021-02-21 09:19:21
【问题描述】:

我正在尝试将git clone 的输出保存到 bash 变量中。当我执行以下操作时,我只得到第一行

DIR=$(git clone repo_url  >& /dev/stdout)
echo $DIR

输出:

Cloning into [repo_name]...

如何保存git clone的整个输出?

我已经在 Ubuntu 和 MacOS 上尝试过。

期望的输出

remote: Enumerating objects: 57, done.
remote: Counting objects: 100% (57/57), done.
remote: Compressing objects: 100% (43/43), done.
remote: Total 9163 (delta 28), reused 30 (delta 11), pack-reused 9106
Receiving objects: 100% (9163/9163), 14.62 MiB | 44.41 MiB/s, done.
Resolving deltas: 100% (7014/7014), done.

【问题讨论】:

  • 缺少的行到底是什么?如果出现错误,可能是您的解决方案仅捕获标准输出而不捕获标准错误,这就是我问...
  • 刚刚添加了所需的输出。我想保存所有克隆进度更新
  • 刚试过declare -p DIR,它也只是给了第一行

标签: bash git


【解决方案1】:

尝试在完整输出中使用--progress

DIR=$(git clone --progress repo_url  >& /dev/stdout)

>& 重定向标准输出和标准错误,考虑到git commands often outputs information on stderr,这是正确的。

【讨论】:

    猜你喜欢
    • 2013-09-09
    • 2021-11-19
    • 2021-06-12
    • 1970-01-01
    • 2021-11-18
    • 2021-12-30
    • 2011-11-10
    • 2018-08-16
    • 1970-01-01
    相关资源
    最近更新 更多