user3828398 user3828398 -5 years ago 303
Bash Question

curl returns 400 bad request without quotes

curl -v ''

returns a 200, but using

curl -v

returns a 400. Why do the quotes matters?

Answer Source

Your URL has characters your shell recognizes as special. Most likely, the &, which is the signal to UNIX-ish shells to place the command in the background. So you effectively are executing three commands:

curl -v

You're not seeing any shell error output, because the last two are valid shell constructs.

Always quote your arguments. If in PHP, use escapeshellarg. Better, use the curl built-in or a third-party library like Guzzle.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download