Changing my login directory
vogelke+unix at pobox.com
Mon Jun 22 18:58:09 UTC 2009
>> On Mon, 22 Jun 2009 11:12:20 +0200,
>> Ruben de Groot <mail25 at bzerk.org> said:
R> No need for any external programs. The following shell script [accepts
R> one key, no need to hit return]
R> % more readkey.sh
R> echo -n "Press any key: "
R> stty cbreak -echo
R> KEY=$(dd bs=1 count=1 2>/dev/null)
R> stty -cbreak echo
R> echo "You pressed the \"$KEY\" key."
Advantages of grabchars:
* One program invocation, instead of running stty twice and dd once.
* NOT having to deal with vendor-specific stty crap on different Unixen,
which is a definite bite in the nether regions when trying to make
things work on Solaris and BSD.
* Erase/kill processing handled for you, so you can still do ^X or ^U
deletion if you're entering multiple characters.
* Handles mapping characters to upper/lowercase, timeouts, default
answers if return is hit, and limiting answers to given character
sets. For example, "grabchars -c 0123456789 -n2 -t10" get two numbers
with a 10-second timeout.
Karl Vogel I don't speak for the USAF or my company
Never do anything against conscience even if the state demands it.
More information about the freebsd-questions