Shell Inconsistent werase (^W) behavior between shells

Hello,

It's my first time in a while running FreeBSD, and I'm very much enjoying it. In fact, having spun up about 8 jails running various services in the last few days, there is exactly one issue that is bothering me, and I'm hopeful that someone here can help me out. It's such a minor thing, but here we go:

  • In tcsh(1), pressing ^W behaves as I am used to, in that it erases a single (whitespace-separated) word of the command line being edited, moving left from the current cursor position.
  • In sh(1), pressing ^W erases the entire line, which is not the behavior I am used to, and seems contrary to every other shell I'm used to. I could change shells, but I otherwise am starting to like sh(1).

Am I missing a configuration option somewhere?

I am on 12-RELEASE. The output of 'stty -a' is the following:

Code:
$ stty -a
speed 9600 baud; 42 rows; 138 columns;
lflags: icanon isig iexten echo echoe -echok echoke -echonl echoctl
    -echoprt -altwerase -noflsh -tostop -flusho -pendin -nokerninfo
    -extproc
iflags: -istrip icrnl -inlcr -igncr ixon -ixoff ixany imaxbel -ignbrk
    brkint -inpck -ignpar -parmrk
oflags: opost onlcr -ocrnl tab0 -onocr -onlret
cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow
    -dtrflow -mdmbuf
cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = <undef>;
    eol2 = <undef>; erase = ^?; erase2 = ^H; intr = ^C; kill = ^U;
    lnext = ^V; min = 1; quit = ^\; reprint = ^R; start = ^Q;
    status = ^T; stop = ^S; susp = ^Z; time = 0; werase = ^W;

Thank you.
 
The sh(1) shell has very little features for interactive use. There's some rudimentary command history and a few other things but it's quite spartan. It's not meant to be used interactively, it's main use is for scripting. Install shells/zsh or shells/bash if you want a Bourne compatible shell with rich features for interactive use. Others like shells/pdksh or similar Korn shell implementations. There's plenty to choose from.

Or simply use tcsh(1) for interactive use and sh(1) for scripting. I personally like tcsh(1) but not everyone does. Usually you can set quick key combinations with each shell using the bindkey(1) command. On Bash for example CTRL-W erases the whole word, and this includes slashes. Which is slightly different behavior compared to tcsh(1). But bindkey(1) can be used to make each shell behave the same way. Each shell has different settings, just enter the bindkey command to see their current settings.
 
Thanks SirDice, that pointed me in the right direction. I got acceptable behavior (it removes words using spaces or slashes as delimeters) by adding the following to my .shrc

Code:
bind ^W "ed-delete-prev-word"

The first thing I used to do, upon loading a FreeBSD box, was to get bash(1) installed. Trying to expand my horizons a bit. :)
 
Back
Top