I am writing a script which uses CURL.
There are some HTTP headers common to all requests.
curl -X GET "..." -H 'accept: */*' -H "api-key: $API_KEY"
So I would like to put those to a variable:
HEADERS="-H 'accept: */*' -H \"api-key: $API_KEY\""
curl -X GET "..." $HEADERS ### <-- This is what I want to achieve.
As you can see, it needs a mix of
'
s because it contains*
, which could expand,"
s because there is a variable.
I have tried quite a few combinations of escaping, mixing ' and ", building the string gradually, but always I end up with Bash adding unwanted escapes or leaving those which I need.
How can I achieve to have both -H
params (i.e. all 4 arguments) in a variable which I can then use in a command?
There are a few similar questions but they are specific for other cases.