Alex Rivera | Logout

Terminal Commands: For loop with echo

Asked 2011-08-23T18:25:26.193
81

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
}
Edit
Report

2 Answers

157

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.

answered 2011-08-23T18:31:28.303
4

jot would work too (in bash shell)

for i in `jot 1000 1`; do echo "http://example.com/$i.jpg"; done
answered 2012-12-19T11:55:23.617

Your Answer