Arrays
KSH array operations
KSH basic array operations
KSH basic array declaration, access, and manipulation
#!/bin/ksh
# Declare array
set -A fruits apple banana cherry
# Access elements
print "First fruit: ${fruits[0]}"
print "All fruits: ${fruits[@]}"
print "Array length: ${#fruits[@]}"
# Add element
fruits[${#fruits[@]}]="orange"
print "After adding: ${fruits[@]}"
KSH array iteration
KSH array iteration methods
#!/bin/ksh
set -A colors red green blue yellow
# Method 1: Index-based iteration
integer i=0
while (( i < ${#colors[@]} )); do
print "Color $i: ${colors[$i]}"
(( i++ ))
done
# Method 2: Direct iteration
for color in "${colors[@]}"; do
print "Color: $color"
done