24 September 2015

Get backspace working in a mixed environment often involves stty erase ^? (or stty erase ^h). However, today I found that sometimes they work sometimes they do not work. This seemed a bug to me at first. But, after more tests, I found it might be not a bug but a feature.

Here is the summary of the behavior of stty erase on redhat linux.

  1. Whatever you set in your profile (default is "^?"), both "^h" and "^?" are regarded as <erase>.
  2. A stty erase command takes effect only when it really changes the <erase>.

    For example, if you stty erase ^h in your profile, running stty erase ^h again in command line does nothing and both "^h" and "^?" still work as <erase>. But, running stty erase ^? will instantly make "^?" the only erase character.

So, when you find stty erase ^? does not work as expected, run stty erase ^h first and then retry stty erase ^?.

This behavior might be a nice feature. While still keeps the ability to modify the settings of <erase>, it makes both "^h" and "^?" work as <erase> even if you "inherit" a profile which set <erase> explicitly, which is very beginner-friendly.



blog comments powered by Disqus