Terminal Commands: For loop with echo

Chris picture Chris · Aug 23, 2011 · Viewed 135.1k times · Source

I've never used commands in terminal like this before but I know its possible. How would I for instance write:

for (int i = 0; i <=1000; i++) {
    echo "http://example.com/%i.jpg",i
}

Answer

Simon picture Simon · Aug 23, 2011

The default shell on OS X is bash. You could write this:

for i in {1..100}; do echo http://www.example.com/${i}.jpg; done

Here is a link to the reference manual of bash concerning loop constructs.