2016-10-03 152 views
1

試圖從http://git-scm.com拉最新版本的Git,但下面的腳本似乎沒有打印出任何東西...Bash最新版本的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" 

回答

4

的問題是,http://git-scm.com/被重定向到https://git-scm.com/,並curl默認情況下不執行重定向。

嘗試直接從https://git-scm.com/獲取。

或者,將-L選項添加到curl命令以使其遵循重定向。