Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with count in a loop

Status
Not open for further replies.

chris01010

Programmer
Jan 29, 2004
25
GB
When using a While flow, using an argument of count, the value of the variable $count is not incrementing but instead just displaying an output of 1+1+1....

i.e.

Script:

while

[ $count -lt 10 ]

do

echo "$count"

count=`expr $count+1`

done

Output:

+ [ 1 -lt 10 ]
+ echo 1
1
+ + expr 1+1
count=1+1
+ [ 1+1 -lt 10 ]
+ echo 1+1
1+1
+ + expr 1+1+1
count=1+1+1
+ [ 1+1+1 -lt 10 ]
+ echo 1+1+1
1+1+1
+ + expr 1+1+1+1
count=1+1+1+1
+ [ 1+1+1+1 -lt 10 ]
+ echo 1+1+1+1
1+1+1+1
+ + expr 1+1+1+1+1
count=1+1+1+1+1
+ [ 1+1+1+1+1 -lt 10 ]
+ echo 1+1+1+1+1
1+1+1+1+1
+ + expr 1+1+1+1+1+1
count=1+1+1+1+1+1
+ [ 1+1+1+1+1+1 -lt 10 ]
+ echo 1+1+1+1+1+1
1+1+1+1+1+1
+ + expr 1+1+1+1+1+1+1
count=1+1+1+1+1+1+1
+ [ 1+1+1+1+1+1+1 -lt 10 ]

...etc, etc

Anyone have any ideas where i'm going wrong with the syntax??

Cheers

Chris
 
Try this:
Code:
count=`expr $count + 1`

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Thanks. Shell scripting is quite unforgiving with regards to spacing!
 
You can also use that:

let count=count+1
 
In the Korn shell you can do...
Code:
(( count += 1 ))
Hope this helps.

 
@Sam

what is the tag for this "code" block?

Regards
-- Franz
Sorry I'm not a native spaeker, I'm from Munich, Germany - "Home of the Whopper", oh no, "Home of the Oktoberfest" ;-)
Solaris System Manager; I used to work for Sun Microsystems Support (EMEA) for 5 years
 
Code:
 and

Click on 'Process TGML' to get the fillung listing of the TGML supported tags.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
great! Thanks!

Regards
-- Franz
Sorry I'm not a native spaeker, I'm from Munich, Germany - &quot;Home of the Whopper&quot;, oh no, &quot;Home of the Oktoberfest&quot; ;-)
Solaris System Manager; I used to work for Sun Microsystems Support (EMEA) for 5 years
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top