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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

new "for" loop syntax in Korn shell 1

Status
Not open for further replies.

risby

Programmer
Feb 27, 2002
84
Has anybody seen this Korn shell syntax for a for loop
Code:
for (( i=0; i<10; i++ ))
do
  print $i
done
An employee of the company I'm working for at the moment just asked me why he got a "syntax error: `((' unexpected" message.

I showed him how to do it as a while loop but I am intrigued as to which version of Korn shell might support this syntax.

My O'Reilly "Learning the Korn Shell" (c) 1993 does mention a c style arithmetic for loop as a future feature.

It isn't available in the PD KSH v5.2.14 99/07/13.2 that I have.

==========================================
toff.jpg
I phoned the local ramblers club today, and this bloke just went on and on.
 
This is ksh-93 syntax.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
No output, but no error message either from RedHat bash, syntax error in RedHat and AIX 5.1 ksh

On the internet no one knows you're a dog

Columb Healy
 
feherke
From my RedHat server
Code:
[root@gbmddh221usvr]# uname -a
Linux gbmddh221usvr 2.6.9-67.0.1.ELsmp #1 SMP Fri Nov 30 11:51:05 EST 2007 i686 i686 i386 GNU/Linux
[root@gbmddh221usvr]# for (( i=0; i>10; i++ )); do   print $i; done
[root@gbmddh221usvr]#

On the internet no one knows you're a dog

Columb Healy
 
for (( i=0; i[!]<[/!]10; i++ )); do print $i; done

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Durr....

Another embarassing oops from Columb!

The output is now
Code:
[root@gbmddh221usvr /]# for (( i=0; i<10; i++ )); do   print $i; done
-bash: print: command not found
-bash: print: command not found
-bash: print: command not found
-bash: print: command not found
-bash: print: command not found
-bash: print: command not found
-bash: print: command not found
-bash: print: command not found
-bash: print: command not found
-bash: print: command not found
[root@gbmddh221usvr /]# for (( i=0; i<10; i++ )); do   echo $i; done
0
1
2
3
4
5
6
7
8
9
[root@gbmddh221usvr /]#
as predicted.

On the internet no one knows you're a dog

Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top