bash - shell脚本响应按键

标签 bash shell input keypress

我有一个 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/

相关文章:

bash - 使用 cut 的奇怪 bash 结果

Linux .profile 覆盖其他 bash 命令

javascript - js中重置计算器输入框以便下一步操作

linux - 通过命令行显示 Ubuntu Unity Launcher

REGEX 文件名 Shellscript 检查

linux - Bash 脚本并行处理有限数量的命令

linux - 对 bash 行为感到困惑 - Bash/awk mystery

python - 如何使用Python替换多个文件中的字符串

C 非阻塞键盘输入

Angular 2通过输入更改类中的变量