Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用户如何在bash中传递数组的特定索引中的值_Bash - Fatal编程技术网

用户如何在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

示例代码仅包含注释。它不会做任何事情。