Help on "for" loop in bourne shell

Hello Everyone....

I am trying to print a number sequence in following format using for loop.

I am using a bourne shell. I tried following for loop condition but it is bash syntax.

for (( i=0; i<=5; i++ ))

It is giving syntax error.

Kindly help with the syntax of "for" loop in order to print the above format.

Thanks in advance......

in bourne, you can try the usual

for i in 1 2 3 4 5

Thank you very mcuh for the reply....

I could use the above mentioned for loop syntax......

But the limit of the loop is unkonown i.e., in

 for i in 1 2 3 4 5 

limit is only 5. What it should be for 'n' numbers ?

Secondly, with the above code is it possible to manipulate the value of i....i.e., if I want a decrement of 3 instead of 1......is it possible...

Thanks in advance.......

Hi, You could have a look at seq, man seq

Example:

master:~ # for x in $(seq 1 2 10);do for y in $(seq 1 $x);do echo -n $x; done;echo;done
1
333
55555
7777777
999999999
master:~ #

Best regards,
Lakris

Another way:

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

if seq doesn't work you can use a while or until loop and increment an index

I=1
until [ $I -eq $LIMIT ]
do
     let I+=1 # or let I=I+1 if the other syntax doesn't work
...
done

Thank you for your replies.....

Lakris:
seq is a bash command. I am using a bourne shell......sh

Franklin52:
thank you for the code......
my task is to achieve it using for loop.

Thanks in advance.....

Why is it not permitted to use a while loop?