使用curl传递带括号的url

Passing a URL with brackets to curl

如果我尝试将一个URL传递给包含括号的curl,它将失败并出现错误:

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

但是,如果我避开这两个括号,它似乎会起作用:

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

有趣的是,我使用反斜杠仅转义第一个括号,它会自动失败,错误代码为20497:

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

我的问题是如何解决一般情况下的问题?是否有一个参数将自动转义URL,或者在传递给curl之前需要转义的字符的描述?


不过,我在医生那里找到的:

1
2
3
4
5
-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.