The issue is that brace expansion in Bash does not support variables; it's performed before variable expansion. Therefore, {00001..$last_part} doesn't work as expected. Here's the corrected script:
#!/bin/bash
set +x
baseurl="https://huggingface.co/bartowski/deepseek-ai_DeepSeek-R1-0528-GGUF/resolve/main/deepseek-ai_DeepSeek-R1-0528-IQ1_M/deepseek-ai_DeepSeek-R1-0528-IQ1_M"
last_part=00004
category=blah
# Convert last_part to a number (removes leading zeros)
last_num=$((10#$last_part))
# Generate sequence using a loop
for ((i=1; i<=last_num; i++)); do
# Format number as 5-digit with leading zeros
part_num=$(printf "%05d" "$i")
downloadable_object="${baseurl}-${part_num}"
echo a2.py "$category" "$downloadable_object"
done
Key Fixes:
- Brace Expansion Limitation: Variables can't be used in brace expansions (
{1..$end}).
- Numeric Conversion: Convert
last_part (string) to a number using $((10#$var)) to handle leading zeros.
- Loop with Formatted Numbers: Use a C-style loop to iterate numerically, then format the number with
printf to 5 digits.
Changes Made:
- Combined
baseurl into a single line (original had a trailing -IQ1_M on a new line, which was invalid).
- Added quotes around variables to handle potential spaces.
- Used arithmetic expansion (
$(( ))) for safe number conversion.
Test Output:
With last_part=00004, the script outputs:
a2.py blah https://huggingface.co/...IQ1_M-00001
a2.py blah https://huggingface.co/...IQ1_M-00002
a2.py blah https://huggingface.co/...IQ1_M-00003
a2.py blah https://huggingface.co/...IQ1_M-00004