小编Dav*_*Rau的帖子

shell脚本语法:引用数组的变量名

这很接近,但我在循环中引用第二个数组时遇到了麻烦.语法应该是什么样的?$ item返回"1"而不是"a,b,c或d"

colors=( teal purple pink red green darkblue skyblue )
teal=( a b c d )


for color in ${colors[@]}
do
    echo $color

    for item in ${#{$color}[@]}
    do
        echo $item
    done

done
Run Code Online (Sandbox Code Playgroud)

arrays variables bash shell

1
推荐指数
1
解决办法
2277
查看次数

标签 统计

arrays ×1

bash ×1

shell ×1

variables ×1