I have a bash script setup to perform a few curl requests

for currency in EUR INR JPY
  curl -i --data '{"currency": "'$currency'"}' -H "Accept: application/json" -H "Content-Type: application/json" && echo

Is there a way to make the script exit if one of the curl responses come back with an http status != 200?

I also want to keep the standard curl output, e.g I don't want a solution that only prints the http status code.


1 Answer 1


--fail, as mentioned in the man page, seems to do the job:

$ curl --fail --location http://google.com/nope
$ echo $?
  • 7
    From the manpage, --fail is not suitable for a couple of reasons: 1. Fail silently (no output at all), and 2. This method is not fail-safe and there are occasions where non-successful response codes will slip through.
    – Armand
    Sep 12, 2016 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.