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:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old December 1st, 2003, 09:48 PM
tzeyik tzeyik is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 22 tzeyik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
for statement problem

I face problem with a very simple for statement function. This is the script below

for (( i=1; i<=5; i++ ))
do
for (( j=1; j<=i; j++ ))
do
echo -n "$i"
done
echo ""
done

and the error msg is
syntax error at line 1 : `((' unexpected

y this happend? can anyone tell me y?

Reply With Quote
  #2  
Old December 1st, 2003, 10:16 PM
Perderabo Perderabo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 121 Perderabo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 54 sec
Reputation Power: 5
It would help us to know which language you are using. My coin toss says ksh, so I'm gonna roll with that.

It would also help the computer to know what language you're using, so your script should start with a #! /path/to/interpreter statement. Here is a sample script that shows what "for" actually does. And it shows how to use a "while" to get what I think you want....
Code:
#! /usr/bin/ksh
LIST="one two three four"
for item in $LIST ; do
       echo $item
done

i=0
while ((i<5)) ; do
     echo $i
     ((i=i+1))
done

exit 0

Reply With Quote
  #3  
Old December 1st, 2003, 11:58 PM
tzeyik tzeyik is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 22 tzeyik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I did include the !# /usr/bin/ksh in my script.
I test on the while statement, it work.. but my problem is y for statement cannot be used.

for my information, for statement is shell script canbe hv this kind of syntax
for variable in list
do
...
done

but my question is can this kind of for statement working?
for (( i=1; i<=5; i++ ))
do
...
done

Thanks~

Reply With Quote
  #4  
Old December 2nd, 2003, 06:46 AM
Perderabo Perderabo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 121 Perderabo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 54 sec
Reputation Power: 5
Well, you tried it and got an error message. That's a pretty strong indication that it won't work.

The confusion comes from the fact that there are several versions of the Korn shell. ksh-88 got picked up by all of the major unix vendors. The syntax for the posix shell is very close to ksh-88. So everyone was forced into ksh-88 for posix compliance.

I see from The New Kornshell Command and Programming Language by Bolsky and Korn that the syntax you are trying was added to ksh-93. But the only way to get ksh-93 is to download the source code and install it yourself. And it's not like perl, compiling ksh is a tough job. And you can't redistribute ksh-93. That shuts the door on a guru porting it to each version of unix and making the port available on a free download site. As a result, ksh-93 is almost never available, and even if you have it, you should ignore the extentions if you want your script to be portable.

Reply With Quote
  #5  
Old December 2nd, 2003, 06:54 PM
tzeyik tzeyik is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 22 tzeyik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for the information~~ Then, i think i hv to choice other alternative instead of using for loop.. By the way, thanks for ur advice. I appreciate it very much~ Thank you very much!
Have a nice day!

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > for statement problem


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 3 hosted by Hostway