这里有一个奇怪的,Bash版本是4.25,CURL是7.32
据我所知,这是通过终端
运行的脚本(适合你) #!/bin/bash
protocol='https://bing.com'
location="$(curl -Is $protocol |awk '/Location/{print$2}')" #responds: https://www.bing.com/
shopt -s extglob;
echo "'${location}'" #echos: 'https://www.bing.com/
#but where's my trailing ' (quote) ????
#its completely gone.... ???
location=$(echo ${location%%*(/)}) #should remove trailing slashes
#but I believe that the missing
#quote from above is causing trouble....
shopt -u extglob
echo $location; #should be: https://www.bing.com ???
我无法切断我的尾随斜线,有些东西在干扰,我只是想不出来?
答案 0 :(得分:3)
每当你的线路末端的某些东西在回声中丢失时,立即想到“回车!”。 echo "$location" | cat -v
最后会显示^M
。
要从HTTP标头卷曲输出中删除回车符,请使用tr -d '\r'
:
location="$(curl -Is "$protocol" | tr -d '\r' | awk '/Location/{print$2}')"