Skip to content

Instantly share code, notes, and snippets.

@mihow
Last active January 15, 2019 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mihow/4c5481cfb678f87975b03e4f56fc273e to your computer and use it in GitHub Desktop.
Save mihow/4c5481cfb678f87975b03e4f56fc273e to your computer and use it in GitHub Desktop.
Test a URL in bash script and exit on failure or return failure exit code.
#! /bin/bash
set -o errexit
curl --fail --show-error --location http://httpbin.org/status/200 > /dev/null
echo "It worked!"
curl --fail --show-error --location http://httpbin.org/status/500 > /dev/null
echo "It failed, but you will never see this message."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment