不记名令牌作为 curl 中的变量

Bearer token as variable in curl

我正在尝试为不记名令牌传递变量,但我伪造请求失败了。 基本上,如果我手动添加令牌,它就可以工作。

curl ... --header "Authorization: Bearer MmM2MDZkMDA0MjE0" --verbose
* About to connect()
* Connected to ...
* ...
> Authorization: Bearer MmM2MDZkMDA0MjE0
< HTTP/1.1 200 OK
<...
    response header and body was here
...
* Connection #0 to host host.local left intact

但是当我尝试将它分配给一个变量时,它不起作用

$bearerToken='MmM2MDZkMDA0MjE0'
curl ... --header "Authorization: Bearer $bearerToken" --verbose
* About to connect()
* Connected to ...
* ...
> Authorization: Bearer MmM2MDZkMDA0MjE0
< HTTP/1.1 400 Bad EOL
< Content-Length: 0
< Connection: close
<
* Closing connection 0

我什至尝试像下面这样创建变量并传递它,但我得到了相同的输出

testToken='Authorization: Bearer '$bearerToken
curl ... --header $testToken

我做错了什么?

我发现 curl 被破坏了,因为当使用变量时,它们在末尾包含新行。对我有用的是使用:

"Authorization: Bearer ${bearerToken//[$'\t\r\n ']}"