Tuesday, September 4, 2007

prompt and press a key between script lines

Ever wonder how this simple mechanism goes where in an installation script prompts you a question and waits for you to press any key at a give time interval?

Here's a quick entry on how to prompt for a single key from a script with time interval.

Getkey is one linux command that waits until a keyboard key is pressed. This is useful on installation or even from a simple bash script. If your script is programmed to ask a user simple questions answerable by single keystroke, you might find this nice getkey tool script useful.

USAGE:
~~~~~~

Waits for user to press any key and display the pressed key
# getkey

Waits for a user to answer a question by Y or N within 5 seconds and display the pressed key
# getkey -c 5 -m "Press a kay within %d Continue the process Y or N?"

Waits for a user to answer a question by Y or N within 5 seconds and display the pressed key but ignores any special control keys except Ctrl+C and Ctrl+D
# getkey -i -c 5 -m "Press a kay within %d Continue the process Y or N?"

Another usage is for pausing between bash script lines like for 5 seconds instead of using sleep. But ignores any pressed key
# getkey -c 5

HTH

No comments:

Post a Comment

Thanks for the comment and for peeping into my blogspot. Hope you enjoy your reading them.

If you wish to receive posts updates, you can subscribe directly from this link:

http://feeds.feedburner.com/VertitosBlogspot

using any RSS reader or even Google Reader.

Again, appreciate your site visits.

Cheers then

VeRTiTO
Email: vertito@gmail.com