我需要将我的输入与Enter/ Returnkey 进行比较......
read -n1 key
if [ $key == "\n" ]
echo "@@@"
fi
Run Code Online (Sandbox Code Playgroud)
但这不起作用..这段代码有什么问题
我有一个shell脚本,基本上就是这样的
while true; do
read -r input
if ["$input" = "a"]; then
echo "hello world"
fi
done
Run Code Online (Sandbox Code Playgroud)
这一切都很好,很好,但我只是意识到必须点击ENTER在这种情况下提出了一个严重的问题.我需要的是脚本在按下键时响应,而不必按Enter键.
有没有办法在shell脚本中实现此功能?