我有一个 shell 脚本,基本上是这样的
while true; do
read -r input
if ["$input" = "a"]; then
echo "hello world"
fi
done
一切都很好,很好,但我刚刚意识到在这种情况下必须按 ENTER 键会带来严重的问题。我需要的是让脚本在按下某个键时做出响应,而不必按回车键。
有没有办法在 shell 脚本中实现此功能?
最佳答案
read -rsn1
只期待一封信(不要等待提交)并保持沉默(不要回信)。
关于bash - shell脚本响应按键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24016046/