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:
  #1  
Old October 3rd, 2006, 01:15 PM
sarunda sarunda is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 13 sarunda User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 32 m 14 sec
Reputation Power: 0
Simple Q -- count variable in loop

I need to do something very simple, and as I'm a newbie, I need some help. How do I get a count of items processed in a loop? Using ksh.

A simple example:

for file in `ls ${stagedir}/*.txt`

do
mv ${file} ${workdir}
# count variable here -- x++

done

echo "${x} files were moved"

Thanks!
Stacy

Reply With Quote
  #2  
Old October 3rd, 2006, 01:31 PM
sarunda sarunda is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 13 sarunda User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 32 m 14 sec
Reputation Power: 0
Never mind. Got it. Sorry for the super-simple question!

count=0
for file in `ls ${stagedir}/*.txt`

do
mv ${file} ${workdir}
count=`expr $count + 1`

done

echo "$count files were moved"

Thanks,
Stacy

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Simple Q -- count variable in loop


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 4 hosted by Hostway
Stay green...Green IT