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

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -