【问题标题】:Latest version of Git in Bash?Bash 中最新版本的 Git?
【发布时间】:2016-10-03 02:36:55
【问题描述】:

尝试从http://git-scm.com 拉取最新版本的 Git,但下面的脚本似乎没有打印出任何内容...

我在这里错过了什么?

if [ -z "$CURRENT_GIT_VERSION" ]; then
    if [ "`uname`" == "Darwin" ]; then 
        sed_regexp="-E"; 
    else 
        sed_regexp="-r"; 
    fi
    CURRENT_GIT_VERSION=$(curl http://git-scm.com/ 2>&1 | grep '<span class="version">' -A 1 | tail -n 1 | sed $sed_regexp 's/ *//')
fi
echo "$CURRENT_GIT_VERSION"

不工作:

CURRENT_GIT_VERSION=$(curl -silent http://git-scm.com/ | sed -n '/id="ver"/ s/.*v\([0-9].*\)<.*/\1/p')
echo "$CURRENT_GIT_VERSION"

也不行:

CURRENT_GIT_VERSION=$(echo $(curl -s http://git-scm.com/ | grep 'class="version"' -A 2) | perl -pe 's/.*?([0-9\.]+).*/$1/')
echo "$CURRENT_GIT_VERSION"

【问题讨论】:

    标签: git bash shell installation


    【解决方案1】:

    问题是http://git-scm.com/ 正在重定向到https://git-scm.com/,而curl 默认情况下不遵循重定向。

    尝试直接从https://git-scm.com/ 获取。

    或者,将-L 选项添加到curl 命令以使其跟随重定向。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-04
      • 1970-01-01
      • 2011-04-03
      • 2013-10-07
      • 2021-02-26
      • 2010-11-15
      • 1970-01-01
      • 2015-04-06
      相关资源
      最近更新 更多