I need to write an infinite loop that stops when any key is pressed.
Unfortunately this one loops only when a key is pressed.
Ideas please?
#!/bin/bash
count=0
while : ; do
# dummy action
echo -n "$a "
let "a+=1"
# detect any key press
read -n 1 keypress
echo $keypress
done
echo "Thanks for using this script."
exit 0
> Hi all,
>
> I need to write an infinite loop that stops when any key is pressed.
>
> Unfortunately this one loops only when a key is pressed.
>
> Ideas please?
> …
> read -n 1 keypress
> …
Try this one instead
read -t 0.5 -n 1 keypress && exit