1753827 Members
8868 Online
108805 Solutions
New Discussion юеВ

stty erase / stty werase

 
SOLVED
Go to solution
luissma
Advisor

stty erase / stty werase

Hi,

I'm having a problem with stty. Whenever I hit 'backspace', instead of a single character, an entire word is deleted from the command line.

I've tried to set 'werase' in many different ways to avoid this word deletion but I'm not able to sort out the problem:

#> stty
speed 38400 baud; -parity hupcl
intr = ^C; erase = DEL; kill = ^U;
eol ; swtch ;
susp = ^Z;
werase = DEL; lnext = ^V;
brkint -inpck -istrip icrnl -ixany onlcr tab3
-iexten echo -echoe -echok
-echoctl -echoke


#> stty werase '^W'

#> stty
speed 38400 baud; -parity hupcl
intr = ^C; erase = DEL; kill = ^U;
eol ; swtch ;
susp = ^Z;
werase = ^W; lnext = ^V;
brkint -inpck -istrip icrnl -ixany onlcr tab3
-iexten echo -echoe -echok
-echoctl -echoke


#> stty werase undef
#> stty
speed 38400 baud; -parity hupcl
intr = ^C; erase = DEL; kill = ^U;
eol ; swtch ;
susp = ^Z;
werase = u; lnext = ^V;
brkint -inpck -istrip icrnl -ixany onlcr tab3
-iexten echo -echoe -echok
-echoctl -echoke


I'm working with bash shell on a HP-UX B.11.11.

Could anybody lend me a hand?

Thanks in advance.
2 REPLIES 2
Matti_Kurkela
Honored Contributor
Solution

Re: stty erase / stty werase

After making changes to stty settings, restart your bash shell.

Bash uses the readline library for command line editing. One of the features of the readline library is that at startup, it checks the stty settings for special characters and then binds those control characters to equivalent readline functions.

So, when you login, something has caused werase to be set to DEL, the same as erase. This clearly incorrect setting is copied to bash's readline keybindings.

When you use stty to change the werase character, you're changing only the stty setting; the equivalent readline mapping remains in the wrong value.

Try this after logging in:

stty werase '^W'
exec bash

The second command will cause the shell to be restarted, and it will have a chance to re-initialize the readline mappings to match the new stty values.

Alternatively, this bash command should explicitly unbind the word-erasing function:

bind -u unix-word-rubout

Once you get your shell environment fixed, it's time to try and find the root cause. Perhaps someone has made the incorrect "werase = DEL" setting as the default for all TTYs? To check this, run this command as root:

stty -a
You'll see the default settings for all TTY devices. If this includes the incorrect werase setting, you can fix it with:

stty werase '^W'
The default settings will revert to built-in kernel defaults when the system is rebooted. You might want to check your startup scripts and/or /etc/inittab: perhaps someone has made a less-than-successful customization to your system.

MK
MK
luissma
Advisor

Re: stty erase / stty werase

The strange thing is that in the default settings "werase" is Ok:

#> stty -a min = 4; time = 0;
intr = DEL; quit = ^\; erase = #; kill = @
eof = ^D; eol = ^@; eol2 ; swtch
stop = ^S; start = ^Q; susp ; dsusp
werase ; lnext

I'm not able to find the file/script where "stty werase..." could be set. I'll keep on searching.

Both methods you propose ("exec bash" or "bind -u...") works as expected.

For the moment I've set it in my .bash_profile and it works properly (before I was trying to set in /etc/profile and from command line but, as seen, it didn't work):

#> grep werase .bash_profile
stty werase '^W'

#> stty -a | grep werase
werase = ^W; lnext = ^V


Thanks a lot for your help.

Luisma Arranz