looping a number 1-100 or so?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting looping a number 1-100 or so?
# 1  
Old 06-18-2008
looping a number 1-100 or so?

Im stilla newb at scripting. But can anyone tell me how to take a block of numbers in a loop as a variable?

example I want to create 100 files named test1.txt through test100.txt How can I loop the 1-100? I cant find a code example anywhere on how to do this?
# 2  
Old 06-18-2008
Code:
way1:
$ for ((i=1;i<=100;i++)); do echo $i; done

way2:
$ for i in `seq 1 100`; do echo $i; done

//Jadu
# 3  
Old 06-18-2008
Quote:
Originally Posted by jaduks
Code:
way1:
$ for ((i=1;i<=100;i++)); do echo $i; done

way2:
$ for i in `seq 1 100`; do echo $i; done

//Jadu
Awesome! Thanks for the help. it's a pain to find those types of examples by searching here or on google Smilie
# 4  
Old 06-18-2008
ohh.. by the way, way1, what is this called: (i=1;i<=100;i++) an expression? I need to read up on this Smilie
# 5  
Old 06-18-2008
Code:
While loop: 

$ i=1
while [ $i -le 100 ]
do
echo $i
((i+=1)) #or i=`expr $i + 1`
done

Until loop: 

$ i=1
until [ $i -eq 101 ]
do 
echo $i
((i+=1))
done

for ((i=1;i<=100;i++)) is one more for loop syntax in bash

//Jadu
# 6  
Old 06-18-2008
Ksh88 does not have the for loop construct, but Ksh93 and Bash do.
The while/until loop construct is more portable...
Code:
i=1; while [[ $i -le 100 ]]; do echo $i; let i=i+1; done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Looping

Hey guys, so I am trying to do a loop script that will go through each folder (no gui so just each domain has a folder) and grab out the databases being used on that domain. I know I would use mysql -e "show databases where not 'information_schema';" once in each directory to pull the actual... (3 Replies)
Discussion started by: dough
3 Replies

2. Shell Programming and Scripting

Looping

Hi evryone i need a help . i have a file xcv.the content is : accelerate i want a script which will run 1000 times in loop and changing the value to accelerate to acceler in 1st loop and in 2nd loop it will be again accelerate and so on . (6 Replies)
Discussion started by: Aditya.Gurgaon
6 Replies

3. Shell Programming and Scripting

how to get the data from line number 1 to line number 100 of a file

Hi Everybody, I am trying to write a script that will get some perticuler data from a file and redirect to a file. My Question is, I have a Very huge file,In that file I have my required data is started from 25th line and it will ends in 100th line. I know the line numbers, I need to get all... (9 Replies)
Discussion started by: Anji
9 Replies

4. Shell Programming and Scripting

Looping

Hi, Now I have written a script which sorts the records in the file and splits them according to some condition. Now, I need to modify the script so that it reads all the files one after the other and does the sorting & splitting. Pls help me in reading all the files in a directory and... (8 Replies)
Discussion started by: Sunitha_edi82
8 Replies

5. Shell Programming and Scripting

help with looping

vesselNames values: xxx yyy zzz vesselPlanned values: xxx zzz zzz zzz OIFS="" OIFS=$IFS IFS="\n" (2 Replies)
Discussion started by: finalight
2 Replies

6. Shell Programming and Scripting

How to erase files with line number less than 100

I am trying to delete all the files with line number less than 100 in a directory. Thank you. (5 Replies)
Discussion started by: Sean2008
5 Replies

7. Shell Programming and Scripting

help on looping using if/for or while

Hello, where can I get usefull information on the use of looping with for , if and while with extensive examples. Also use of variables in scripts (1 Reply)
Discussion started by: sam4now
1 Replies

8. Shell Programming and Scripting

for looping

I run into a issue when I try to do sorting of the following with ascending order, one round of for looping seems not working, anyone knows how to use shell or perl? $array = (5,0,3,2,7,9,8) (2 Replies)
Discussion started by: ccp
2 Replies

9. Shell Programming and Scripting

looping

Hi I have around 100 users in sun server and have default home directory in /usr/home/<username> I want to clean their home directory time to time to make free space on root, as users generate many output files during usage of application. My idea is, generate a file with following command... (4 Replies)
Discussion started by: ishir
4 Replies

10. UNIX for Dummies Questions & Answers

Help with looping

Hi, Actually I have a file which consists data . for eg names. Then I want my sql query to read this file and produce the output. Currently I am using this FOR EG : FILENAME is NAMES for i in `cat NAMES` { sqlplus -s $CONNECTID << EOF spool rooh set heading off select... (1 Reply)
Discussion started by: rooh
1 Replies
Login or Register to Ask a Question