开发者

How do I escape a cmd with options and a query?

This is how I have it in the script. What's wrong escaping it?

"curl --fail $solrIndex/update?commit=true -H \"Content-Type: text/xml\" --data-binary '<delete><query>*:*</query></delete>'"

This is how it executes:

curl --fail http://localhost:8080/solr/update?commit=true -H "Content-Type: text/xml" --data-binary '<delete><query>*:*</query></delete>'
<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader"><int name="status">0</int><int name="QTime">17</int></lst>
</response>
curl: (6) Couldn't resolve host 'text'

What works:

$ curl --fail http://localhost:8080/solr/update?commit=true -H "Content-Type: text/xml" --data-binary '<delete><query>*:*</query></delete>'
<?xml version="1.0" encoding="UTF-8"?>
<res开发者_如何学Cponse>
<lst name="responseHeader"><int name="status">0</int><int name="QTime">51</int></lst>
</response>


Store the command in an array instead of a single string

cmd=(curl --fail $solrIndex/update?commit=true -H "Content-Type: text/xml" --data-binary '<delete><query>*:*</query></delete>')

And execute it with

"${cmd[@]}"


You should almost never quote the whole command; quote the arguments:

curl --fail "$solrIndex/update?commit=true" -H "Content-Type: text/xml" --data-binary '<delete><query>*:*</query></delete>'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜