This question already has an answer here:

I couldn't post a minimal example since I do not have a REST server available to people.

This works on my system --

$ curl --header "Content-Type: application/json" --header "Accept: application/json" --user user:password -X PUT  -d "[{\"name\":\"zwave_device_8faeda92_node14_sensor_binary\",\"label\":\"Node 14 - Binary Sensor\",\"editable\":true,\"type\":\"Switch\"}]" "https://demo.openhab.org:8080/rest/items"


But when I try to save the headers to another variable and repeat the command it fails --

$ CURL_OPTS="--header \"Content-Type: application/json\" --header \"Accept: application/json\" --user user:password"; curl $CURL_OPTS -X PUT  -d "[{\"name\":\"zwave_device_8faeda92_node14_sensor_binary\",\"label\":\"Node 14 - Binary Sensor\",\"editable\":true,\"type\":\"Switch\"}]" "https://demo.openhab.org:8080/rest/items"

curl: (6) Could not resolve host: application
curl: (6) Could not resolve host: application
{"error":{"message":"HTTP 415 Unsupported Media Type","http-code":415,"exception":{"class":"javax.ws.rs.NotSupportedException","message":"HTTP 415 UnsupportedMedia Type","localized-message":"HTTP 415 Unsupported Media Type"}}}

I have tried debugging with set -x on bash and seen that this is not an issue if the CURL_OPTS doesn't have any literal quotes inside them. But as soon as I try to pass an option it escapes all quotes, sometimes the double quotes as \'\' which stops me from getting any configuration of single and double quotes that gets the job done.

marked as duplicate by Kusalananda bash Aug 3 '18 at 11:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Browse other questions tagged or ask your own question.