-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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