用户如何在bash中传递数组的特定索引中的值
我想一个接一个地传递数组的特定索引中的值,我如何才能实现这一点 我的代码用户如何在bash中传递数组的特定索引中的值,bash,Bash,我想一个接一个地传递数组的特定索引中的值,我如何才能实现这一点 我的代码 count=("$@") read -p 'enter index 0 ' {count[0]} read -p 'enter index 1 ' {count[1]} read -p 'enter index 2 ' {count[2]} echo "${count[0]}" 不工作读取变量(索引或不索引)时,不应将其置于括号中。考虑 count=(
count=("$@")
read -p 'enter index 0 ' {count[0]}
read -p 'enter index 1 ' {count[1]}
read -p 'enter index 2 ' {count[2]}
echo "${count[0]}"
不工作读取变量(索引或不索引)时,不应将其置于括号中。考虑
count=( "$@" )
read -p 'enter index 0' count[0]
read -p 'enter index 0' count[1]
read -p 'enter index 0' count[2]
...
试试这个:
for i in {0..2}
do
read -p "enter index ${i}" count[0]
echo "${count[i]}"
done
示例代码仅包含注释。它不会做任何事情。