Why does a curl GET request with query string parameters require quotes?

Issue

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).

Solution

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 …

Answered By – Slimane amiar

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published