bash:如何使读取超时工作
为什么以下脚本在bash中不起作用:bash:如何使读取超时工作,bash,Bash,为什么以下脚本在bash中不起作用: while [[ true ]]; do read -t2 -n1 check if [[ $check == "q" ]];then echo "pressed" read -n1 check="" else echo "not pressed" fi echo "Doing Something" done 我正在使用最新的macOS和Terminal.app
while [[ true ]]; do
read -t2 -n1 check
if [[ $check == "q" ]];then
echo "pressed"
read -n1
check=""
else
echo "not pressed"
fi
echo "Doing Something"
done
我正在使用最新的macOS和Terminal.app也许您想要这样的东西(bash版本4.3): 请看一下什么
$ echo "$BASH_VERSION"
打印。它做什么,以及您希望它做什么?检查您的bash手册页:read命令是否在您的bash版本中使用了
-t
选项?我相信osx附带了一个非常旧的bash版本。@glennjackman在2.04中将-t
添加到read
。甚至macOS也不是那么过时:)
$ echo "$BASH_VERSION"