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.
我又遇到了一个小问题,我想将字符串存储在数组中,我得到以下代码:
echo -e "Enter an amount" read n for ((i=0;i<n;i++)); do echo "Enter number $i " read ${array[$i]} done echo -e "$array[@]}"
你能帮我看一下吗?谢谢
第 5 行应该读作:
read array[$i]
${array[$i]},也就是你目前所拥有的,会输出带有下标$i的数组元素的值。该read命令将用户输入读入指定变量,因此您需要指定变量名称。
${array[$i]}
read
你也可以写
array=() for ((i=0; i<n; i++)); do read -p "Enter number $i " array+=($REPLY) done