Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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
Bash 由curl返回的未使用字符串不可用_Bash_Url_Curl_Sed - Fatal编程技术网

Bash 由curl返回的未使用字符串不可用

Bash 由curl返回的未使用字符串不可用,bash,url,curl,sed,Bash,Url,Curl,Sed,我想从java风格的属性文件向curl传递一个主机名 此.properties instance.dns=localhost ... bash命令 ./postFiles.sh this.properties bash脚本 #!/bin/bash #blows up HOST=$(grep "^instance.dns=" ${1}| sed "s%instance.dns=\(.*\)%\1%") URL="$(echo 'http://admin:admin@'${HOST}':8

我想从java风格的属性文件向curl传递一个主机名

此.properties

instance.dns=localhost  
...
bash命令

./postFiles.sh this.properties

bash脚本

#!/bin/bash

#blows up
HOST=$(grep  "^instance.dns=" ${1}| sed "s%instance.dns=\(.*\)%\1%")
URL="$(echo 'http://admin:admin@'${HOST}':8080/documentservice/api/doc')"
echo "$URL"

#works
HOST="$(echo 'localhost')"
URL="$(echo 'http://admin:admin@'${HOST}':8080/documentservice/api/doc')"
echo "$URL"

curl -v --globoff -F 'docKey=testFile0' -F 'fileType=IFP Paper Application' -F 'myFile=@DarthTests.jpg' $URL
两个代码块都回显相同的url:
http://admin:admin@localhost:8080/documentservice/api/doc

但是,如果我使用sed curl生成的URL,则无法解析主机

 Adding handle: conn: 0x7ff473803a00
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7ff473803a00) send_pipe: 1, recv_pipe: 0
* Could not resolve host: localhost
* Closing connection 0
curl: (6) Could not resolve host: localhost

为什么sed url看起来完全相同时不可用?

如果
此.properties
使用DOS样式的行结尾,您将使用
HOST=“localhost\r”

试试这个:

HOST=$( sed -n -e 's/\r$//' -e 's/^instance.dns=//p' "$1" )