> Because Ctrl+W is provided by something called TTY, and the other three are provided by the shell
This is more complicated (or simpler?) than what the article explains. Or I might be really confused. But if you strace bash while typing in stuff, you see clearly that it is reading in characters one by one, including ^W, and handling them itself. I don't see TTY doing much magic here at all:
stracing bash more reveals another thing; when executing command like stty then before forking bash calls TCSETSW ioctl to set tty settings, and after child exists its calls TCSETSW again to set its own values, so stty does not actually show what mode the tty is in while bash is handling the input:
I wish it would fully reset the terminal mode after every command though so you don't get stuck without seeing what you type when some CUI program terminates without cleaning up properly. That's why I have `stty sane` in my PROMPT_COMMAND.
I believe this is handled by the tty "canonical" (line input) mode. If you run "stty -a" you'll see a number of special characters defined, like werase = ^W
If you set this to something else (stty werase ^O) you'll see it takes effect immediately.
but as it turns out bash does not use canonical mode, and I suspect that applies to many other interactive repls/shells too; probably something readline handles
You are correct for bash. If you run "cat" (from "bash"), you'll see that it no longer handles control-A or control-E (handled by readline...), but control-W is still handled by the tty.
Also if you disable werase i.e. "stty werase ''" and use the bind bash builtin to set "bind Control-w:' backward-kill-word'" you will get slightly different behaviour. A hyphen will be considered a word ending, unlike the tty.
So does bash read ^w and mimics the tty behaviour regarding the definition of a word?
I don't have linux handy right now and tracing on macos is painful otherwise I'd dive deeper.
This is more complicated (or simpler?) than what the article explains. Or I might be really confused. But if you strace bash while typing in stuff, you see clearly that it is reading in characters one by one, including ^W, and handling them itself. I don't see TTY doing much magic here at all: