Ksh does not work for loop range

I tried this

#!/bin/ksh
for i in {1..10}
do
  echo "Welcome $i times"
done

in Ksh AIX windows. I get the output as

Welcome {1..10} times

What is wrong here? Shouldn't he print from 1 to 10 ?. Edit: According to the percolator post, from Iteration through a series of ints to ksh?

It works only with linux. Is there any other work around / replace for unix box ksh?

for i in 1 2 3 4 5 6 7 8 9 10

is ugly.

Thank.

+3
source share
4 answers

I think from memory that standard kshon AIX is an older option. It may not support a range loop. Try running ksh93instead ksh. It should be in the same place as kshpossible /usr/bin.

Otherwise, just use something old, like this:

i=1
while [[ $i -le 10 ]] ; do
    echo "Welcome $i times"
    i=$(expr $i + 1)
done

, publib, , ( ksh93), .

+4

, pre-93 ksh .

Linux, , ksh bash ksh93.

: -

for ((i=0;i<10;i++))
do
 echo "Welcome $i time"
done
0

, ksh . .

while:

while [[ $i -lt 10 ]] ; do
    echo "Welcome $i times"
   (( i += 1 ))
done

perl, script

#!/usr/bin/perl
for $i (1 .. 10) {
    echo "Welcome $i times"
}
0

, jot , man, , C, .

jot - -

for i in `jot 1 10`
do 
    //do stuff here
done
0

All Articles