MSFN Forum: FOR Loop in Linux Help - MSFN Forum

Jump to content


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

FOR Loop in Linux Help Yes, homework help Rate Topic: -----

#1 User is offline   footballking3420 

  • Horror & Metal purist
  • PipPip
  • Group: Members
  • Posts: 119
  • Joined: 13-June 06

Posted 10 June 2008 - 09:23 PM

This is what I have so far:

 
COUNT=0
echo "You have entered $# arguments:"
for ARG in $*
do
echo "#`expr $COUNT + 1`: $ARG"
done 


I can't seem to get the COUNT variable to increase for each listed argument. For example, if I enter something like:

 
./FILE_NAME one two three 


I ended up getting this:

 
You have entered 3 arguments:
#1: one
#1: two
#1: three 



#2 User is offline   Zxian 

  • Scroll up - see the Google bar?
  • Group: Super Moderator
  • Posts: 5,066
  • Joined: 30-September 04
  • OS:none specified
  • Country: Country Flag

Posted 10 June 2008 - 09:32 PM

Normally, we don't help with homework (see Forum Rules #2c)... but I'll give you a small hint - look at what you're doing with count... you're simply adding one to the existing value and displaying the result (what happens to $COUNT after it's executed?).

#3 User is offline   footballking3420 

  • Horror & Metal purist
  • PipPip
  • Group: Members
  • Posts: 119
  • Joined: 13-June 06

Posted 10 June 2008 - 10:03 PM

Oh, I got it now. I had to add COUNT=`expr $COUNT + 1` as a second statement.

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy