2011-11-30 98 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