我需要看到使用curl或wget找到的搜索,当它找到带有'301‘状态代码的结果时。
这是我使用卷发的变量。
website=$(curl -s --head -w %{http_code} https://launchpad.net/~[a-z]/+archive/pipelight -o /dev/null | sed 's#404##g')
echo $website
301上述功能,但只有当站点存在“301”状态代码.时才显示。
,我想要
echo $website
https://launchpad.net/~mqchael/+archive/pipelight发布于 2014-03-22 01:47:29
您可以将“有效URL”添加到输出中。将%{http_code}更改为"%{http_code} %{url_effective} "。
从那里开始,这只是一个对正则表达式的麻烦。将sed字符串更改为's#404 [^ ]* ##g'。这将消除(假设您还不知道)不仅404,但也将吃掉它后面的URL。
所以:
curl -s --head -w "%{http_code} %{url_effective} " https://launchpad.net/~[a-z]/+archive/pipelight -o /dev/null | sed 's#404 [^ ]* ##g''s#404 [^ ]* ##g'会给你:
301 https://launchpad.net/~j/+archive/pipelight在此之后,您可能希望用新行替换HTTP代码。
https://stackoverflow.com/questions/22572108
复制相似问题