0

When I run the following command in linux:

wget http://page.com/{0000..0100}.jpg

he tries to download the following sequence:

http://page.com/0.jpg

http://page.com/1.jpg

http://page.com/2.jpg

http://page.com/3.jpg

...

http://page.com/100.jpg

that is, it does not place the zeros.

Community
  • 1
  • 1
alex
  • 83
  • 6

2 Answers2

1

The bash expansion isn't going to pad teh numbers to use mathematically insignificant zeros. You can use seq with the -w (width) option to pad with leading zeros.

for i in `seq -w 1 1000`
do 
  wget http://example.com/path/to/$i.jpg
done
ivanivan
  • 2,155
  • 2
  • 10
  • 11
1

Consider upgrading Bash. Your code works on Bash4+:

$ echo $BASH_VERSION {001..003}
4.4.19(1)-release 001 002 003

but not on older versions like Bash 3.x:

$ echo $BASH_VERSION {001..003}
3.2.57(1)-release 1 2 3

If you're unable to upgrade, you can use printf as a workaround:

wget $(printf "http://page.com/%04d.jpg\n" {1..100})
that other guy
  • 116,971
  • 11
  • 170
  • 194