这是我在脚本中的方式。逃避它有什么不对?
"curl --fail $solrIndex/update?commit=true -H \"Content-Type: text/xml\" --data-binary '<delete><query>*:*</query></delete>'"
这就是它的执行方式:
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'
什么有效:
$ 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">51</int></lst>
</response>
答案 0 :(得分:1)
将命令存储在数组中而不是单个字符串
cmd=(curl --fail $solrIndex/update?commit=true -H "Content-Type: text/xml" --data-binary '<delete><query>*:*</query></delete>')
用
执行"${cmd[@]}"
答案 1 :(得分:0)
你几乎从不引用整个命令;引用这些论点:
curl --fail "$solrIndex/update?commit=true" -H "Content-Type: text/xml" --data-binary '<delete><query>*:*</query></delete>'