The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Alternative for a while read line loop kabs UNIX for Dummies Questions & Answers 2 04-01-2008 09:25 AM
Using awk (or an alternative) michaeltravisuk Shell Programming and Scripting 5 03-08-2007 07:37 PM
.NET Alternative goon12 UNIX for Dummies Questions & Answers 3 04-06-2005 09:07 AM
cut -f (or awk alternative) gefa Shell Programming and Scripting 6 03-02-2005 09:26 AM
loop alternative? apalex Shell Programming and Scripting 2 05-02-2002 09:47 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-17-2008
Registered User
 

Join Date: May 2007
Posts: 54
help with while loop or any other alternative?

Code:
i=1
while [ $i -le $1 ]
do

mm=02
dd=03
yy=2008

echo "$mm$dd$yy"

        i=$(( i+1))
        echo "$i"
done
whenever i execute the script above i will get the error below:

syntax error at line 30: `i=$' unexpected

could anyone kindly tell me what is wrong with the above script or is there any other alternative loop that i can use ? can i use a 'for loop' ?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-17-2008
Registered User
 

Join Date: Sep 2006
Location: Mysore, India
Posts: 153
Change increment step as below.

Code:
i=`expr $i + 1`
Reply With Quote
  #3 (permalink)  
Old 04-17-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 2,688
Which shell are you running this under? The $((...)) construct is not understood by /bin/sh

If you need this to work in Bourne shell, the classical syntax for incrementing a variable is

Code:
i=`expr $i + 1`
Note the use of backticks, and spaces around the plus.
Reply With Quote
  #4 (permalink)  
Old 04-17-2008
Registered User
 

Join Date: May 2007
Posts: 54
thanks for the prompt reply.... i got it ...
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:10 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0