How to create recursive download and rename bash script

Solution 1:

I would change two things to make it work

  • the variable need to be put in {} to separate it from the other text (how should bash know that the variable isn't called ilatest otherwise?
  • sleep expects the sleep time in seconds

This gives you

#!/bin/bash
i=0
while true
do
    curl -O link.com/latest.jpg
    let "i++"
    mv latest.jpg latest-${i}.jpg
    sleep $((5*60))
done

In addition, having the sleep as part of the loop code will require that you press ^C twice to terminate the loop. You might want to try the following instead

#!/bin/bash
i=0
s=0
while sleep $s
do
    curl -O link.com/latest.jpg
    let "i++"
    mv latest.jpg latest-${i}.jpg
    let 's=5*60'
done