Created
October 28, 2024 10:53
-
-
Save kerasai/8a3ad16c0458c283f610fc56c5d5d170 to your computer and use it in GitHub Desktop.
CURL with clean file name
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 | |
# Check if a URL was provided | |
if [ -z "$1" ]; then | |
echo "Usage: $0 <URL>" | |
exit 1 | |
fi | |
# Assign the first argument to a variable | |
URL="$1" | |
# Strip parameters and fragments from the URL just to extract the filename | |
FILENAME=$(basename "$(echo "$URL" | sed 's/[?#].*//')") | |
# Use curl with -O -J to download using the full URL and extracted filename as a fallback | |
curl -L -J -o "$FILENAME" "$URL" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment