I have a couple of curl commands, one to fetch an authentication key and then another that needs to use that key, currently i have the below bash script.
#!/bin/bash
ACCESS_TOKEN=$(curl -XPOST -H "Content-type: application/json" -d '{"client_id":"XXX", "client_secret":"XXX", "grant_type":"client_credentials"}' 'https://url.com' | ./jq '.access_token')
echo $ACCESS_TOKEN
UPLOADARRAY=$(curl -v -XGET -H 'Authorization: Bearer "$ACCESS_TOKEN"' -H 'client_id:XXX' -H "Content-type:application/json" 'https://otherurl.com' | ./jq '{authCode: .authCode, name: .uploadUrl}')
echo $UPLOADARRAY
The issue is looking at the verbose output of the second curl command i see:
> User-Agent: curl/7.77.0
> Accept: */*
> Authorization: Bearer "$ACCESS_TOKEN"
So the content of the variable access content (which the test echo statement shows does contain the right value) isn't being used and instead the string "$ACCESS_TOKEN" is used.
I did have a look at Quoting within $(command substitution) in Bash and wrapping the command with the additional double quotes but this made no difference.
Can anyone spot whats wrong here?
"Authorization: Bearer $ACCESS_TOKEN"
– muru Feb 17 '22 at 15:11