Use stty to facilitate interactive script input

Jun 09, '04 09:09:00AM

Contributed by: gshenaut

I noticed that under some circumstances, such as using "gets" in tcl, or "read" in certain shell scripts, that when I made a typo and pressed the "delete" key to back up, it just echoed ^H at me and didn't erase the mistake. After some fiddling around, I discovered that if I ran the command

    stty erase ^H
things started working correctly. I guess the erase character wasn't getting set automatically, but the shells were reading input in raw mode and doing their own editing so I hadn't ever realized it. (Or maybe there's some other explanation???). To type ^H, what I do is to type Control-V Control-H. It's possible that you may need to do something else such asL
\ Control-H
or the like, depending on various settings in your system. What you're trying to do is to escape the normal meaning the CTL-H key has to your shell. To make it more automatic, I added the command to /etc/profile. If you want to put this into a script and then put things back the way they were before exiting, you can use stty -g to get the previous settings in a ready-to-use format (see man stty for more details).

Comments (3)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20040607193546219