KSH For Loop Array: Iterate Through Array Values

‮l.www‬autturi.com
KSH For Loop Array: Iterate Through Array Values

In KSH (Korn Shell), you can use a for loop to iterate through the values of an array.

Here is an example of how to do this:

# Declare an array
my_array=(apple orange banana)

# Iterate through the array values
for value in "${my_array[@]}"; do
  echo "$value"
done

This will print the values of the array (apple, orange, and banana) on separate lines.

You can also use a for loop to iterate through the indices of an array, rather than the values, like this:

# Declare an array
my_array=(apple orange banana)

# Iterate through the array indices
for i in "${!my_array[@]}"; do
  echo "$i: ${my_array[$i]}"
done

This will print the indices and values of the array, like this:

0: apple
1: orange
2: banana

For more information on working with arrays in KSH, you can consult the KSH manual or online documentation.

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