KSH for Syntax

www.‮ttual‬uri.com
KSH for Syntax

Here is the basic syntax for a for loop in KSH (Korn Shell):

for variable in list; do
  commands
done

The for loop will execute the commands for each value in the list. The variable will be set to the current value of the list on each iteration.

Here is an example of a for loop that counts from 1 to 10:

for i in {1..10}; do
  echo $i
done

You can also specify a range of numbers using a step size:

for i in {1..10..2}; do
  echo $i
done

This will count from 1 to 10 with a step size of 2, resulting in the output 1 3 5 7 9.

You can also use the (( )) syntax to iterate over a range of numbers with a step size of 1:

for ((i=1; i<=10; i++)); do
  echo $i
done

This will count from 1 to 10 with a step size of 1, resulting in the output 1 2 3 4 5 6 7 8 9 10.

For more information on using for loops in KSH, you can consult the KSH manual or online documentation.

Created Time:2017-10-29 22:08:50  Author:lautturi