Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有许多数组,但只想遍历通过 STDIN 输入的一个我的代码看起来像
ARR1=(a b c) ARR2=(d e f) ARR3=(g h i) read array_name for i in ${array_name[@]} do echo "i is $i" done
现在,如果我输入 ARR1 作为输入,则不会打印 ARR1 值。有人可以帮忙吗
你可以写:
ARR1=(a b c) ARR2=(d e f) ARR3=(g h i) read array_name array_name="${array_name}[@]" # append '[@]' to array_name for i in "${!array_name}" ; do # use indirection to expand e.g. "${ARR1[@]}" echo "i is $i" done