Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Shell脚本中连接并删除回车符_Shell_Http_Curl - Fatal编程技术网

在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

在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.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