Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Use stty to facilitate interactive script input' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use stty to facilitate interactive script input
Authored by: bluehz on Jun 09, '04 01:02:30PM
Here is a simple example for further explanation. Normally a read statement in a script will wait for input and then a RETURN or ENTER key, but it will not let you backspace over chars if you make a mistake in tying. This simple little line in your scripts make them much more professional allowing the user to edit what they have typed in.
#!/bin/sh

# allow terminal to accept backspace key in read statement
stty erase '^h'

echo -e "Try it out... enter some text and backspace over it... \c"
read test
you can also use the -e switch of the "read" command to enable the readline routines which gives you backspace and arrow keys among other things.
#!/bin/sh

echo -e "Try it out... enter some text and backspace or use arrow keys over it... \c"
read -e test


[ Reply to This | # ]