在Bash脚本中将单词定义为变量

时间:2021-02-19 01:47:06

I'm trying to define two variables to be used in a bash script but, ONLY the first texts, "em" and "ctl" in the variables are read... I need them all to work.

我正在尝试定义两个要在bash脚本中使用的变量,但是,只读取变量中的第一个文本“em”和“ctl”......我需要它们全部工作。

What am I doing wrong?

我究竟做错了什么?

cores=("em" "nmm" "nmb")
mems=("ctl" "n1" "n2" "n3" "p1" "p2" "p3")

echo "${cores}"
echo "${mems}"

2 个解决方案

#1


0  

To print the whole array, you need to add [@] which expands to all elements.

要打印整个数组,需要添加扩展到所有元素的[@]。

echo "${cores[@]}"
echo "${mems[@]}"

#2


0  

I think you're doing it right, but to see everything in the array you need to use

我认为你做得对,但要查看数组中你需要使用的所有内容

echo ${cores[*]}
echo ${mems[*]}

#1


0  

To print the whole array, you need to add [@] which expands to all elements.

要打印整个数组,需要添加扩展到所有元素的[@]。

echo "${cores[@]}"
echo "${mems[@]}"

#2


0  

I think you're doing it right, but to see everything in the array you need to use

我认为你做得对,但要查看数组中你需要使用的所有内容

echo ${cores[*]}
echo ${mems[*]}