The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Increment date in 'for' loop? SunnyK Shell Programming and Scripting 4 10-30-2007 06:12 AM
Infinite Loop in Autosys while running a shell script, Manual run is fine sharmagaurav_2k Shell Programming and Scripting 2 09-04-2007 08:20 AM
pick the bug the server enters an infinite loop arjunjag High Level Programming 3 07-19-2007 01:53 AM
ls command in infinite Loop umakant SUN Solaris 3 07-17-2007 01:25 AM
high priority thread contains an infinite loop rvan High Level Programming 0 02-14-2007 09:30 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-25-2007
mrityunjay22 mrityunjay22 is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 4
Question the given code goes in infinite loop and does not increment variable i

code is as

#!/bin/sh

i=1;
while [ $i -le 5]
do
welcome $i times;

i='expr $i+1';


done
exit 0;
  #2 (permalink)  
Old 12-25-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by mrityunjay22 View Post
while [ $i -le 5]
A space between the 5 and ] might make a difference.
  #3 (permalink)  
Old 12-25-2007
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 750
Quote:
Originally Posted by mrityunjay22 View Post
code is as

#!/bin/sh

i=1;
while [ $i -le 5]
do
welcome $i times;

i='expr $i+1';


done
exit 0;
The while test expression should have proper spacing as well as the line that increments i. Don't need the terminating semicolons after every command. Is welcome as in "welcome $i times" a functon in your script and it would be nice to printout the value of i while executing the loop...

Code:
#!/bin/sh

i=1
while [ $i -le 5 ]
do
   welcome $i times;
   echo "value of i is...$i"
   i='expr $i + 1'
done
exit 0
  #4 (permalink)  
Old 12-26-2007
mrityunjay22 mrityunjay22 is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 4
after doing all the above steps its not worki9ng can anyone suggest another workable way of incrementing the variable i
  #5 (permalink)  
Old 12-26-2007
rinku rinku is offline
Registered User
  
 

Join Date: May 2007
Posts: 54
Smile Try it

Please try to do it. I think it will increament the value of i.

#!/bin/sh

i=0
while [ $i -le 5 ]
do
echo "value of i is...$i"
i=`expr $i + 1`

done
  #6 (permalink)  
Old 12-26-2007
mrityunjay22 mrityunjay22 is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 4
Quote:
Originally Posted by rinku View Post
Please try to do it. I think it will increament the value of i.

#!/bin/sh

i=0
while [ $i -le 5 ]
do
echo "value of i is...$i"
i=`expr $i + 1`

done
thanks its working
  #7 (permalink)  
Old 12-26-2007
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,078
wrong format

HI,

There are two typos for you i think.
First,
5 ] not 5]
Second,
` not '

Code:
i=1;
while [ $i -le 5 ] 
do
echo "welcome $i times"
i=`expr $i + 1`
done
Sponsored Links
Closed Thread

Bookmarks

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:19 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0