I'm trying to understand a little issue I met today regarding string variables in bash
I'm trying do define a string containing options to pass to another command. This string contains double quotes, but when used as arguments for another command, those double quotes are hard quoted, and the command doesn't understand its passed parameters
Example :
`CURL_OPTS="-sL \
--header \"Content-Type: application-json\" \
--header \"Accept: application/json\" \
--header \"Authorization: Bearer ${TOKEN}\""
curl ${CURL_OPTS} "${API_URL}/endpoint/"`
When runing this script in debug mode, I see that the executed command is
`curl -s --header '"Content-Type:' 'application-json"' --header '"Accept:' 'application/json"' --header '"Authorization:' Bearer 'mySecretToken"' http://localhost:39080/api/hub/processors/`
instead of
`curl -s --header "Content-Type: application-json" --header "Accept: application/json" --header "Authorization: Bearer mySecretToken" http://localhost:39080/api/hub/processors/`
the curl request is indeed sent (strangely), but none of the options is taken into account (no custom header) when removing manually the hard quotes, everything works fine
so why are the hard quotes added ?
thanks