如何在Shell脚本中实现数组的遍历操作?

使用for循环来遍历Shell脚本中的数组,示例如下:

#!/bin/bash

# 定义数组
fruits=('apple' 'banana' 'cherry' 'date')

# 遍历数组
for fruit in "${fruits[@]}";
do
  echo "Fruit: $fruit"
done

以上示例中,使用for循环来遍历名为fruits的数组,输出数组中的每个元素。