Skip to content

Instantly share code, notes, and snippets.

@kerasai
Created October 28, 2024 10:53
Show Gist options
  • Save kerasai/8a3ad16c0458c283f610fc56c5d5d170 to your computer and use it in GitHub Desktop.
Save kerasai/8a3ad16c0458c283f610fc56c5d5d170 to your computer and use it in GitHub Desktop.
CURL with clean file name
#!/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