Bash:在读取循环中读取输入不起作用

wel*_*lly 14 bash

在 while 读取循环中读取输入似乎不起作用

while read line
do
 echo "get some input from the user"
 read response
done < some_file.txt
Run Code Online (Sandbox Code Playgroud)

执行不会像读取在循环之外那样暂停。为什么是这样?是否有在 while 读取循环中读取输入的解决方法?

gle*_*man 17

让内部读取命令使用 stdin,并为 while 循环使用不同的文件描述符

while read -u 3 line; do
  read -p "get some input from the user" response
done 3< some_file.txt
Run Code Online (Sandbox Code Playgroud)


Nif*_*fle 16

问题是read line和 都read response期望(并获取)来自stdin. 关于 SO 的
这个问题通过指向更多信息的链接解释了其中的一些内容。

tl;dr
接受的答案表明:

从控制终端设备读取: read input </dev/tty