1

I have the following script:

for i in {1..16}; do
$wget http://url/$i.jpg -O C:/Users/User/Desktop/Test/
done

Saved the file as test.sh and run it within Git on windows.

The files are live on the server but when I run the script i get "No such file or directory"...

Thoughts?

2 Answers 2

1

Your script is substantially correct if not for the character $ that you have to delete and for the file name that you have to repeat

for i in {1..16}; do
   wget http://url/$i.jpg -O C:/Users/User/Desktop/Test/$i.jpg
done

Indeed the option -O asks to write the filename and not the directory.

-O file
--output-document=file
The documents will not be written to the appropriate files, but all will be concatenated together and written to file.

Some words more
In your version $wget is a variable never assigned and so empty.
The result of the command inside the cycle becomes, for example,

http://url/1.jpg -O C:/Users/User/Desktop/Test/

that is a file not present on your HDD.

To investigate errors of this kind you can add an echo in the line and see the output generated by your cycle:

for i in {1..16}; do
   echo $wget http://url/$i.jpg -O C:/Users/User/Desktop/Test/
done

it will reveal your problem/mistake.

1
  • Thanks! Made me re-read my code and realized my mistakes.
    – tackdetack
    Dec 29, 2015 at 1:14
0

My -P directory had not been created so wget didn't have a place to download the files to.

Needed to change -O to -P. Added "" for the directory location.

This is now working

 for i in {1..16}; do
 wget http://url/$i.jpg -P "C:/Users/user/Desktop/Test"
 done

Also needed to ensure the formatting was correct in Notepad++. Changed EOL Conversion from windows to Unix.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .