web-dev-qa-db-fra.com

Passer une URL avec des crochets pour boucler

Si j'essaie de passer une URL à curl contenant des crochets, cela échoue avec une erreur:

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

Cependant, si j'échappe aux deux crochets, cela semble fonctionner:

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

Fait intéressant, j'utilise une barre oblique inverse pour s'échapper niquement le premier crochet, il échoue silencieusement avec le code d'erreur 20497:

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

Ma question est de savoir comment résoudre ce problème dans des cas généraux. Existe-t-il un argument qui échappera automatiquement aux URL ou une description des caractères à échapper avant de passer à curl?

278
chaimp

Qu'à cela ne tienne, je l'ai trouvé dans la documentation:

-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.
438
chaimp