如何在这个 while 循环中编写交互式响应?
#!/bin/bash
shows=$(< ${HOME}/.get_iplayer/tv.cache)
# ...
# ... stuff with shows omitted ...
# ...
function print_show {
# ...
return
}
while read -r line
do
print_show "$line"
read -n 1 -p "do stuff? [y/n] : " resp # PROBLEM
# ...
# resp actions omitted
# ...
done <<< "$shows"
因此,读取、“处理”文件,然后在while read
循环中使用生成的面向行的数据
但是 while 循环中的 read 行没有按预期工作,即它不等待用户响应,大概是由于while read
它封装的上下文。
您能否建议如何解决此问题或替代机制?