2011-11-30 96 views
210

如果我试图通过一个URL卷曲包含括号时,出现了一个错误:传递用括号中的URL卷曲

$ curl 'http://www.google.com/?TEST[]=1' 
curl: (3) [globbing] illegal character in range specification at pos 29 

但是,如果我逃跑两个支架,它似乎工作:

$ curl 'http://www.google.com/?TEST\[\]=1' 

有趣的是,我使用反斜杠逃脱第一托架它与错误代码静静地失败20497:

$ curl 'http://www.google.com/?TEST\[]=1' 
$ echo $! 
20497 

我的问题是如何解决这个一般情况下?是否有一个参数会自动跳过网址,或者在传递卷曲之前需要转义的字符的描述?

回答

316

没关系,我发现它在文档:

-g/--globoff 
       This option switches off the "URL globbing parser". When you set this option, you can 
       specify URLs that contain the letters {}[] without having them being interpreted by curl 
       itself. Note that these letters are not normal legal URL contents but they should be 
       encoded according to the URI standard. 
+1

对于我来说,它没有工作。我不得不在每个方括号前加上一个\ \ – Jesus

+4

好像这个选项应该像'-g/- glob'一样选择加入 – jchook