Bash中Git的最新版本?
试图从中提取Git的最新版本,但下面的脚本似乎没有打印出任何内容 我错过了什么Bash中Git的最新版本?,git,bash,shell,installation,Git,Bash,Shell,Installation,试图从中提取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
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"
问题是
http://git-scm.com/
正在重定向到https://git-scm.com/
,默认情况下,curl
不遵循重定向
尝试从https://git-scm.com/
直接输入
或者,在
curl
命令中添加-L
选项,使其遵循重定向。问题在于http://git-scm.com/
正在重定向到https://git-scm.com/
,默认情况下,curl
不遵循重定向
尝试从https://git-scm.com/
直接输入
或者,在curl
命令中添加-L
选项,以使其遵循重定向
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"