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

0 comments:

Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy