Chris
Chris

Reputation: 7310

Terminal Commands: For loop with echo

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
}

Upvotes: 79

Views: 209560

Answers (6)

vishal
vishal

Reputation: 2391

you can also use for loop to append or write data to a file. example:

for i in {1..10}; do echo "Hello Linux Terminal"; >> file.txt done

">>" is used to append.

">" is used to write.

Upvotes: 3

Grimmace
Grimmace

Reputation: 4041

By using jot:

jot -w "http://example.com/%d.jpg" 1000 1

Upvotes: 2

thomas
thomas

Reputation: 41

jot would work too (in bash shell)

for i in `jot 1000 1`; do echo "http://example.com/$i.jpg"; done

Upvotes: 4

Simon
Simon

Reputation: 32943

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.

Upvotes: 156

Cygnusx1
Cygnusx1

Reputation: 5409

Is you are in bash shell:

for i in {1..1000}
do
   echo "Welcome $i times"
done

Upvotes: 6

Gordon Davisson
Gordon Davisson

Reputation: 125998

for ((i=0; i<=1000; i++)); do
    echo "http://example.com/$i.jpg"
done

Upvotes: 31

Related Questions