LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-14-2005, 03:48 PM   #1
bong.mau
Member
 
Registered: Apr 2004
Posts: 290

Rep: Reputation: 30
bash script loop


hi

i'm new to linux...

i 'm building a bash script to automate some jobs & commands....
i need to check n times a condition and then exit...
the below example i think will repeat a cycle 5 times.....
___________________
for i in 1 2 3 4 5
do
echo "Welcome $i times"
done
_______________________

then does not matter what instructons i will put insiede the do - done
delimiters....

now the question...if i have to repeat a loop to check a condition 100 times
what is the syntax ?
i have to specify all the numbers from 1 to 100 in the for instruction
or there is something like..... "for 1 to 100"
then in another thread i opened ,it was suggested me to learn about
script looking into some guides....
these guides are useful,but i still have not found a reference guide of the
bash script language....
a reference where i can look to the "for" instruction and see the syntax ....
sumarizing ....... i need to know if there is a simplier syntax about the
sample code to repeat 100 times...and if there is a reference book about bash script language..a book where all the instruction are listed in alphabetical order...
thanks in advance

Maurizio
 
Old 09-14-2005, 03:54 PM   #2
bong.mau
Member
 
Registered: Apr 2004
Posts: 290

Original Poster
Rep: Reputation: 30
to be more clear
i need to check if pgm is startet
the check must be repeated 5 times
for ..... (repeat 5 times)
do
sleep 2
ps -e | grep pppd
done
 
Old 09-14-2005, 03:56 PM   #3
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
You can use this syntax too:
for((i=0;$i<=100;i=$(($i+1))));do
echo $i
done
 
Old 09-14-2005, 04:00 PM   #4
bong.mau
Member
 
Registered: Apr 2004
Posts: 290

Original Poster
Rep: Reputation: 30
hi

david i think my example in the forst update is misleading.....(sorry ..i done a mistake putting this example i find on internet site....)
really what i need is to repeat n times the loop in the second post
 
Old 09-14-2005, 04:15 PM   #5
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
Just use 5 rather than 100 then.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Script and Loop error handling Kedelfor Programming 5 05-22-2005 02:22 PM
bash script for loop drisay Programming 5 12-25-2004 12:32 AM
Bash for loop Genjix Programming 5 12-23-2004 02:56 AM
bash script - for loop question rignes Programming 3 10-05-2004 11:16 PM
while loop ending prematurely in a bash script meat-head Programming 7 05-08-2004 01:46 AM


All times are GMT -5. The time now is 02:17 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration