Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 } 
like image 332
Chris Avatar asked Aug 23 '11 18:08

Chris


People also ask

How do you run a loop in a shell script?

1) Syntax:Syntax of for loop using in and list of values is shown below. This for loop contains a number of variables in the list and will execute for each item in the list. For example, if there are 10 variables in the list, then loop will execute ten times and value will be stored in varname.

How do you write a loop in Linux terminal?

The basic syntax of a for loop is: for <variable name> in <a list of items>;do <some command> $<variable name>;done; The variable name will be the variable you specify in the do section and will contain the item in the loop that you're on.

How do you repeat a command in Mac terminal?

The commands you enter during a session are saved so you can repeat a previously used command without retyping it. In the Terminal app on your Mac, press the Up Arrow key. The last command you entered appears on the command line. Continue pressing the Up Arrow key until you see the command you want, then press Return.


1 Answers

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.

like image 80
Simon Avatar answered Oct 04 '22 21:10

Simon