0

Okay, so I have tried this:

curl -X 'POST' \
  'http://localhost:5000/log' \
  -H 'Authorization: Basic $token' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{}'

and there seems to be absolutely no way I can run this command by passing the $token. I have also tried this:

curl -X 'POST' \
  'http://localhost:5000/log' \
  -H '$token' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{}'

And even other escape sequences such as including the escape in the token variable without quotes around the token:

curl -X 'POST' \
  'http://localhost:5000/log' \
  -H $token \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{}'

And even echoing the token, with or without quotes:

curl -X 'POST' \
  'http://localhost:5000/log' \
  -H $(echo $token) \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{}'

And I seem to have tried all combinations of token variables, unquoted and quoted, including only the token or including the token with 'Authorization: Basic ' or not, and it still doesn't work.

Why is it that I can't echo my bash variable in there? Believe me, I have tried to paste the token into the query and it works directly, but as soon as I try to use a bash variable, it doesn't work. I am under Linux. I would like this to work in other OSes as well, such as mac.

What is it that doesn't work in the $token?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Guillaume Chevalier
  • 9,613
  • 8
  • 51
  • 79
  • 2
    Variables are not expanded inside single quotes, only inside double quotes. So it should be `-H "Authorization: Basic $token"` – Barmar Oct 10 '22 at 22:48

0 Answers0