Skip to content

Instantly share code, notes, and snippets.

@rbramwell
Forked from hrwgc/validate.sh
Last active December 11, 2017 00:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rbramwell/3cb56c58d38fcda12872 to your computer and use it in GitHub Desktop.
Save rbramwell/3cb56c58d38fcda12872 to your computer and use it in GitHub Desktop.
Validate URL using Bash cURL - Check if a resource exists at a URL
#!/bin/bash
# Simple function to check http response code before downloading a remote file
# Example usage:
# if `validate_url $url >/dev/null`; then dosomething; else echo "does not exist"; fi
function validate_url () {
if [[ `curl -s --head "$1" | head -n 1 | grep "HTTP/[1-3].[0-9] [23].."` ]]; then echo "true"; fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment