|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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? |
|
#2
|
|||
|
|||
|
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
|
|
#3
|
|||
|
|||
|
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~ |
|
#4
|
|||
|
|||
|
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. |
|
#5
|
|||
|
|||
|
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! |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > for statement problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|