To iterate through an array in Bash, you can use a for loop. Here's a simple example:
#!/bin/bash
# Initialize an array
FRUITS=("apple" "banana" "cherry")
# Iterate through the array
for fruit in "${FRUITS[@]}"; do
echo "$fruit"
done
Explanation:
FRUITS=("apple" "banana" "cherry")initializes an array with three fruit names.- The
forloop iterates over each element in the array using"${FRUITS[@]}", which expands to all elements. echo "$fruit"prints each fruit to the console.
Feel free to ask if you need more details or examples!
