在Shell脚本中连接并删除回车符
在shell脚本中,我执行以下操作:在Shell脚本中连接并删除回车符,shell,http,curl,Shell,Http,Curl,在shell脚本中,我执行以下操作: locationUrl=$(grep -r "Location:" output.txt) fullUrl="http://test.com/temp/${locationUrl##*/}" tempUrl="$fullUrl/tests" echo $tempUrl 我的预期产出是 http://test.com/temp/226/tests 但我明白了: /tests/test.com/temp/226 output.txt如下所示: HTTP/1
locationUrl=$(grep -r "Location:" output.txt)
fullUrl="http://test.com/temp/${locationUrl##*/}"
tempUrl="$fullUrl/tests"
echo $tempUrl
我的预期产出是
http://test.com/temp/226/tests
但我明白了:
/tests/test.com/temp/226
output.txt如下所示:
HTTP/1.1 100 Continue
HTTP/1.1 201 Created
Server: Apache-Coyote/1.1
Location: http://test.dev:8080/webservice/temp/226
Content-Type: application/xml
我怀疑output.txt中有carrige returns。通过管道将输出通过
tr-d'\r'
删除这些。我建议你试试:
locationUrl=$(grep -r "Location:" output.txt | tr -d '\r')
entries="entries"
fullUrl="http://test.com/temp/${locationUrl##*/}"
tempUrl="$fullUrl/tests"
echo $tempUrl
您的原始代码可能正在输出http://test.com/temp/226^M/测试
,使用^M使终端开始重写当前行。您可以通过管道将输出通过less
:
$ sh test.s | less
http://test.com/temp/226^M/tests