2

I have some script in bash. I want to send a request to server with some headers (cloudflare block :).

I wrote this:

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

But in output I'm have this..

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;'

How can I put headers from variable into command ?

2
  • 2
    Try quoting the variable curl "$headers" somesite.com Commented Oct 26, 2014 at 19:57
  • To add to @TomFenech, best practice is to quote a variable when it contains spaces. Commented Oct 26, 2014 at 20:12

1 Answer 1

1

Don't use a string for this. Trying to get quoting correct in a string like this is essentially impossible, use an array.

See http://mywiki.wooledge.org/BashFAQ/050 for more.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.