我想等待按键并在按下字母时退出 q
.
脚本不等待 key 。如何纠正?
while read line
do
...
while :
do
read -n 1 key
if [[ $key = q ]]
then
break
fi
done
done < $1
最佳答案
read
读取输入。
在您的脚本中,输入更改为 $1
.
第一层while
循环正在从文件中读取一行,该文件的名称存储在 $1
中。 , 和 read -n 1 key
从同一个文件中读取并存储下一行的第一个字符。
试一试:
while read line ; do
while : ; do
read -n 1 key <&1
if [[ $key = q ]] ; then
break
fi
done
done < $1
<&1
是标准输入。
关于bash - 在 while 循环中等待按键并停止脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37242631/