This question already has an answer here:
- Why does shell ignore quotes in arguments passed to it through variables? [duplicate] 3 answers
I am attempting to do a curl command that uses a predefined variable as a header.
header='-H "Content-Type: application/json" -H "userGUID: 7feb6e62-35da-4def-88e9-376e788ffd97" -H "Content-Length: 51"'
And this is essentially the curl command
curl $header -w "http code: %{http_code}\\n" -X POST -d $BODY $URL
Which then returns the error message
rl: (6) Could not resolve host: application
curl: (6) Could not resolve host: 7feb6e62-35da-4def-88e9-376e788ffd97"
curl: (6) Could not resolve host: 51"
This works as expected
curl -H "Content-Type: application/json" -H "userGUID: 7feb6e62-35da-4def-88e9-376e788ffd97" -H "Content-Length: 51" -w "http code: %{http_code}\\n" -X POST -d $BODY $URL
The reason I'm trying to pass the header as a variable is because I'm writing a script that loops through and array, but currently this does not work with headers for some reason. There is no issue passing arguments for body.