UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old January 19th, 2004, 02:54 AM
farhad farhad is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Iran
Posts: 6 farhad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Help me to write a loop counter

Hi,
I very need to write a loop ( containt while or until
or for ) that can count in ScoUnixOpenserver shell script (bash shell) .
I try to write a loop like follow but don't work correctly :

----------------------------------------------------------------
#!/bin/bash
clear
no=1
while test $no -le 100
do
no=expr $no + 1
echo $no
done
----------------------------------------------------------------
enyone can help me .
thank you for your note.
F.H.

Reply With Quote
  #2  
Old January 19th, 2004, 10:48 AM
fpmurphy fpmurphy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: USA
Posts: 257 fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 23 h 46 sec
Reputation Power: 6
See below for solution. Note the use of backquotes
to evaluate the expression.

Also the echo command needs to be before the count
increment - otherwise the numbers 2 to 101 are output.

no=1
while test $no -le 100
do
echo $no
no=`expr $no + 1`
done

- Finnbarr

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Help me to write a loop counter


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway