Home > database >  Run wget to download several files in shell script
Run wget to download several files in shell script

Time:03-08

I'm trying to download some file by wget. But it seems that the number "i" is unworkable.

Here is the code:

#!/bin/bash
for ((i == 1; i <= 10; i  ))
do
    wget -r ftp://example/hw/"$i"/test*
done

It showed the link "ftp://example/hw//test*" on the cmd. The number did not be printed out.

How can I solve the problem?

Thanks for any help.

CodePudding user response:

Try this:

#!/bin/bash
for i in {1..10}
do
    wget -r ftp://example/hw/"$i"/test*
done

CodePudding user response:

The format of your for loop should be a bit different:

for ((i = 1; i <= 10; i  ))

(have one = instead of two)
And also is good practice to use variables on this way:

wget -r ftp://example/hw/"${i}"/test*
  • Related