Bash 由curl返回的未使用字符串不可用
我想从java风格的属性文件向curl传递一个主机名 此.propertiesBash 由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
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" )