Created
October 21, 2024 14:49
-
-
Save fubits1/8664dac0109a8a158b18d9ae44811c0c to your computer and use it in GitHub Desktop.
Bash: resumable download function with curl
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
| # 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