Home > Software engineering >  Why does a curl GET request with query string parameters require quotes?
Why does a curl GET request with query string parameters require quotes?

Time:08-01

When making a curl GET request from the command line, why are quotes required?

I'm matching to the following route...

router.get('/', async (req, res) => {
  console.log(req.query.test);
  res.status(200).send('done');
});

...and this matches the route just fine...

curl http://localhost:5000/weather
curl "http://localhost:5000/weather?test=testing"

This, however, fails to match the route...

curl http://localhost:5000/weather?test=testing

It returns this error:

zsh: no matches found: http://localhost:5000/weather?test=testing

I'd like to know why this is the case, but I can't find anything more than people saying quotes are required (or that they are required when an "&" is present in the QSP).

CodePudding user response:

Because the question mark "?" is a metacharacter for the command line , it represent a single character, like . in regex, so you need to escape it by putting it between quotes, for example file?.txt could match file1.txt filea.txt ...

  • Related