shell script循环遍历字符串数组

前端之家收集整理的这篇文章主要介绍了shell script循环遍历字符串数组前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

遇到了, 记一下, 简单东西, 我只能说, shell script语法真TM奇葩和难记:

#!/bin/bash

arr=("0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "a" "b" "c" "e" "e" "f")
 
for value in ${arr[@]}
do
  echo $value
done


# 或者采取如下方式
echo "----------------------another way----------------------"

for (( i = 0 ; i < ${#arr[@]} ; i++ ))
do
  echo ${arr[$i]}
done

结果:

0 1 2 3 4 5 6 7 8 9 a b c e e f ----------------------another way---------------------- 0 1 2 3 4 5 6 7 8 9 a b c e e f

原文链接:https://www.f2er.com/bash/389955.html

猜你在找的Bash相关文章