bash, non-blocking stdin/console input -
i write (using bash)
while no_user_key_pressed { do_something.... }
there few options using c++, java, ncurses , others o/s specific. want simple bash portable function.
^c interrupt should used kill remaining code. imagine like: 'press key stop test'
you can use small timeout on read -t
.
the drawback user must press < return >, not "any key".
for example:
while ! read -t 0.01 echo -en "$(date)\r" done echo "user pressed: $reply"
tested on bash 3.2 (os x)
the !
because read
returns failure (false) if timeout expires.
Comments
Post a Comment