[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: stty erase & ssh & vi

From: Ryan Jackson
Subject: Re: stty erase & ssh & vi
Date: Mon, 5 Jul 2004 09:36:41 -0600
User-agent: Mutt/1.5.6i

* s c <address@hidden> [040617 18:45]:
> but the backspace key shows "^?" in vi. `stty erase [CTRL-v] [backspace]` will
> fix the backspace problem with vi but i'd like a persistent fix so i don't 
> have
> to manually fix it everytime. unfortunately, i know nothing of how to set
> termcapinfo. 

> fc2 defaults to erase = ^? but i thought most linuxes are happy with ^? or ^H,
> is this incorrect? 

True, _some_ terminal applications will accept both ^? and ^H for
backspace, but only becuase they're configured that way (in bash, run
'bind -k | less' and look for backward-delete-char.  You'll see that
it's bound to both C-h and C-?).

The problem isn't so much with screen as it is with RedHat's broken
/etc/bashrc file (explanation below).  I've had the same problem when I
ssh from my debian machine to any redhat machine.  Here's what I found:

When ssh runs, it takes your terminal settings, including your erase
character, and your TERM variable and tells the remote sshd to use those
settings for the tty device on the remote machine.  Then sshd runs a
shell (bash by default on RH machines) on that tty.  At this point, if
you were to examine the output of 'stty -a', you'd see that the erase
character is still '^?'.  Now, bash starts parsing its config files.
When it gets to your ~/.bashrc on the remote machine, it sees the
following lines:

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc

This tells it to read RedHat's /etc/bashrc, which is what is really
causing the problem.  In there you'll find the following code:

if [ -x /usr/bin/tput ]; then
 if [ "x`tput kbs`" != "x" ]; then # We can't do this with "dumb" terminal
  stty erase `tput kbs`
 elif [ -x /usr/bin/wc ]; then
  if [ "`tput kbs|wc -c `" -gt 0 ]; then # We can't do this with "dumb" terminal
   stty erase `tput kbs`

I have no idea why this code exists, as it appears to do nothing useful.
It tries to make sure that the tty erase character matches the kbs
definition in the terminfo entry for $TERM (in this case, 'screen').
Screen's terminfo entry has kbs=^H, so the line 'stty erase `tput kbs`
has the effect of telling your remote tty that the erase character is
'^H', when what you're really sending it is '^?'.  Thus, vi will now
only backspace on '^H' (since that is what the terminal _thinks_ the
erase character is), and will echo '^?' just like any other character.

There are 3 possible solutions to this problem:

1) Remove the above lines from your remote .bashrc file.
2) Remove the above lines from the remote /etc/bashrc file.
3) Change the remote machine's terminfo and termcap entries for screen.

If you have root on the remote machine, #2 is the correct solution.  If
not, #1 is the best way.

I used #2 on all of the machines I admin, and I've never had this
problem since.

Ryan Jackson

reply via email to

[Prev in Thread] Current Thread [Next in Thread]