Bash 中具有多个值的变量

tro*_*ron 7 bash

我正在尝试创建一个具有多个值的变量,并在将一个一个执行这些值的命令中使用它。

例子:

value=(a, b, c, d, e)
Run Code Online (Sandbox Code Playgroud)

通过使用,echo "$value"我希望将这些值一一传递。

当我使用时ARRAY=(a, b, c, d, e),它们都会立即执行。我试图避免。

有任何想法吗?

gle*_*man 13

# declare the array
ARRAY=( a "b c" d e )

# to get the elements out of the array, use this syntax:
#   "${ARRAY[@]}" -- with the quotes

for element in "${ARRAY[@]}"; do
    echo "$element"
done
Run Code Online (Sandbox Code Playgroud)
a
b c
d
e
Run Code Online (Sandbox Code Playgroud)