bash - string returned from sed unusable by curl -
i want pass hostname curl java style properties file.
this.properties
instance.dns=localhost ...
bash command
./postfiles.sh this.properties
bash script
#!/bin/bash #blows 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
both code blocks echo same url: http://admin:admin@localhost:8080/documentservice/api/doc
however, if utilize url generated sed curl can not resolve host
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 * not resolve host: localhost * closing connection 0 curl: (6) not resolve host: localhost
why sed url unusable when looks same?
if this.properties
uses dos-style line endings, you'll have host="localhost\r"
try this:
host=$( sed -n -e 's/\r$//' -e 's/^instance.dns=//p' "$1" )
bash url curl sed
No comments:
Post a Comment