在 bash 中,是否有可能在按下 [Return] 键时退出不等待用户输入的循环?
这是我的意思的那种循环。关键是 [q]。我希望它是[返回]。
#!/bin/bash
stty -echo -icanon time 0 min 0 # Don't wait when read the input
i=1
while [ 1 ]; do
echo -ne "$i\r"
((i+=1))
read key
if [ "$key" == "q" ]; then break; fi # If [q] is hit, get out of the loop
done
stty sane # Come back to the classic behavior
exit 0