Shell特殊功能合集

/ 默认分类 / 0 条评论 / 1050浏览
输出数组的index和value
array=(one two three)

# ${#array[@]} is the number of elements in the array
for ((i = 0; i < ${#array[@]}; ++i)); do
    # bash arrays are 0-indexed
    position=$(( $i + 1 ))
    echo "$position,${array[$i]}"
done