Created
October 22, 2014 04:55
-
-
Save chaimleib/89f88f0918c801f8d614 to your computer and use it in GitHub Desktop.
Gets the actual name of a remote file, then downloads to an identically-named file
This file contains 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 | |
function getUriFilename() { | |
header="$(curl -sI "$1" | tr -d '\r')" | |
filename="$(echo "$header" | grep -o -E 'filename=.*$')" | |
if [[ -n "$filename" ]]; then | |
echo "${filename#filename=}" | |
return | |
fi | |
filename="$(echo "$header" | grep -o -E 'Location:.*$')" | |
if [[ -n "$filename" ]]; then | |
basename "${filename#Location\:}" | |
return | |
fi | |
return 1 | |
} | |
url="http://www.vim.org/scripts/download_script.php?src_id=10872" | |
filename="$(getUriFilename $url)" | |
curl -L $url -o "$filename" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment