Skip to content

Instantly share code, notes, and snippets.

@fubits1
Created October 21, 2024 14:49
Show Gist options
  • Select an option

  • Save fubits1/8664dac0109a8a158b18d9ae44811c0c to your computer and use it in GitHub Desktop.

Select an option

Save fubits1/8664dac0109a8a158b18d9ae44811c0c to your computer and use it in GitHub Desktop.
Bash: resumable download function with curl
# add definition to ~/.bashrc / ~/.zshrc
# invoke with download <url>
download() {
url="${1:-}"
# Loop until the download is successful
while true; do
# Use curl with the -C - option to resume the download
curl -C - -O "$url"
# Check the exit status of curl
if [ $? -eq 0 ]; then
echo "Download completed successfully."
break
else
echo "Download interrupted. Retrying..."
fi
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment