我在bash里有剧本。
我想用一些头向服务器发送一个请求(cloudflare block:)。
我写的是:

headers="\
-H 'Host: somesite.com' \
-H 'Accept-Language: pl,en-US;q=0.7,en;q=0.3' \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' \
-H 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0' \
-H 'Accept-Encoding: gzip, deflate' \
-H 'DNT: 1' \
-H 'Connection: keep-alive'";

curl $headers somesite.com

但在输出中我有这个..
curl: (6) Couldn't resolve host 'Accept-Language'
curl: (6) Couldn't resolve host 'pl,en-US;q=0.7,en;q=0.3'
curl: (6) Couldn't resolve host 'Accept'
curl: (6) Couldn't resolve host 'text'
curl: (6) Couldn't resolve host 'User-Agent'
curl: (6) Couldn't resolve host 'Mozilla'
curl: (6) Couldn't resolve host '(Windows'
curl: (6) Couldn't resolve host 'NT'
curl: (6) Couldn't resolve host '6.1;'

如何将变量头放入命令中?

最佳答案

这件事不要用细绳。试图在这样的字符串中正确引用基本上是不可能的,请使用数组。
更多信息请参见http://mywiki.wooledge.org/BashFAQ/050

07-25 22:28
查看更多