问题描述
所以我有一个非常简单的bash脚本,正在curl'ing到一个头的auth服务器。头url被写入var,然后在下一个curl调用中使用。当在第一次curl调用中使用var set时,我得到curl:(3)URL中发现非法字符。我可以回应var和所有看起来不错,我甚至能重置var(在我的例子下面)和它的工作原理。
脚本
URL = $(curl -i -X GET -HX-Auth-User:MyUserna, e-HX-Auth-Key:MyAPIKeyhttps://urlToAuthServer.tld/auth/v1.0/| grepX-Storage-Url:| awk'{print $ 2}')
curl -X GET -HX-Auth-Token:MyAuthTok$ {URL} /folder/myfile.txt-o ./myfile.txt
运行上面的示例时,我获得:
curl:(3)在URL中找到非法字符
网址var看起来像这样(无非法字符)
https://somesecureurl.com/auth/AUTH_67383834 -45245453-g34g34t5-34534
当我在终端中这样做:
现在我复制并粘贴字符串并将其重新设置为URL(再次全部在终端):
> $ URL =https://somesecureurl.com/auth/AUTH_67383834-45245453-g34g34t5-34534
> $ curl -X GET -HX- Auth-Token:MyAuthTok$ {URL} /folder/myfile.txt-o ./myfile.txt
。
$ b因此,为什么我在第一个例子中得到curl:(3)URL中发现的非法字符错误?
更新
我这样做:
printf%s$ URL| xxd
以下是输出(已解决的地址改变了你的想法)
0000000:6874 7470 733a 2f2f 6461 6c30 352e 6f62 https://server.ob
0000010:6a65 6374 7374 6f72 6167 652e 736f 6674 jectstorage.lite
0000020: 6c61 7965 722e 6e65 742f 7631 2f41 5554 sabers.com/v1/AUT
0000030:485f 6665 3235 3339 3434 2d38 6433 322d H_aE2563981-7d32-
0000040:3432 3138 2d61 6566 632d 6665 6638 3465 4201-bdoi -fef94a
0000050:6166 3331 6232 0d ag11c8。
解决方案$ URL包含
\r
(CR)(0d
)。删除它URL = $ {URL%$'\r'}
之前使用
curl
。So I have a very simple bash script that is curl'ing to an auth server for a header. The header url is written to a var and then used in the next curl call. When using the var set in the first curl call I am getting "curl: (3) Illegal characters found in URL". I am able to echo the var and all looks good, I am even able to reset the var (in my example below) and it works.
The Bash script
URL=$(curl -i -X GET -H "X-Auth-User: MyUserna,e" -H "X-Auth-Key: MyAPIKey" "https://urlToAuthServer.tld/auth/v1.0/" | grep "X-Storage-Url:" | awk '{print $2}') curl -X GET -H "X-Auth-Token: MyAuthTok" "${URL}/folder/myfile.txt" -o ./myfile.txt
When running the above example I get:
curl: (3) Illegal characters found in URL
The URL var looks like this (no illegal chars)
https://somesecureurl.com/auth/AUTH_67383834-45245453-g34g34t5-34534
When I do this in terminal it works:
Now I copy and paste the string and reasign it to URL like so (again all in terminal):
>$ URL="https://somesecureurl.com/auth/AUTH_67383834-45245453-g34g34t5-34534" >$ curl -X GET -H "X-Auth-Token: MyAuthTok" "${URL}/folder/myfile.txt" -o ./myfile.txt
It works.
So why am I getting the "curl: (3) Illegal characters found in URL" error in the first example?
UpdateI ran this:
printf %s "$URL" | xxd
Here is the output (addressed changed up you get the idea)
0000000: 6874 7470 733a 2f2f 6461 6c30 352e 6f62 https://server.ob 0000010: 6a65 6374 7374 6f72 6167 652e 736f 6674 jectstorage.lite 0000020: 6c61 7965 722e 6e65 742f 7631 2f41 5554 sabers.com/v1/AUT 0000030: 485f 6665 3235 3339 3434 2d38 6433 322d H_aE2563981-7d32- 0000040: 3432 3138 2d61 6566 632d 6665 6638 3465 4201-bdoi-fef94a 0000050: 6166 3331 6232 0d ag11c8.
解决方案The $URL contains a
\r
(CR) at the end (0d
). Remove it withURL=${URL%$'\r'}
before using it with
curl
.这篇关于在bash脚本中使用curl并获取curl:(3)在URL中发现非法字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!