Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cURL: how can I return 0 if status is 200? [closed]

How can I return 0 when the response status is 200?

Right now I'm able to get the status, e.g., 200 with the following command:

curl -LI http://google.com -o /dev/null -w '%{http_code}\n' -s

But I need to turn this 200 in a return of 0.

How can I achieve this?

I tried the following command, but it doesn't return:

if [$(curl -LI http://google.com -o /dev/null -w '%{http_code}\n' -s) == "200"]; then echo 0
like image 631
1Z10 Avatar asked Oct 22 '25 23:10

1Z10


1 Answers

You can also use the -f parameter:

(HTTP) Fail silently (no output at all) on server errors. This is mostly done to better enable scripts etc to better deal with failed attempts.

So:

curl -f -LI http://google.com

Will return status 0 if the call was sucessful.

like image 200
Dherik Avatar answered Oct 25 '25 20:10

Dherik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!