3 ms·
You're conflating the shell and the terminal. The shell is a running process, the terminal (or tty) is essentially an input-output device connected to the kerne
by DSMan195276 10y ago
You're conflating the shell and the terminal. The shell is a running process, the terminal (or tty) is essentially an input-output device connected to the kernel. If you want to see what I mean, open a terminal and run the `tty` utility. It will print the device file for your current terminal (Probably a `/dev/pts/` entry). If you write any data to that 'file', it will appear in your terminal, and if you read from that file you'll get completely unfiltered input from the terminal (Unfiltered as in you simply see the keys as they are pressed. If you backspace, you'll see a backspace character - no line editing).
The kernel acts as the gatekeeper between the input/output of the processes running on a tty, and the input/output of the tty device itself. In 'raw' mode, the kernel simply takes the input from the tty and sends it as input to the running process, and then takes the output from the running processes and sends it as output to the tty device. The kernel still isn't completely pointless in this instance though, as it does provide some other facilities.
But it doesn't have* to do that. In 'cooked' mode (The default mode), the kernel will allow line-editing. It does this by buffering the inputs from the tty device (And writing them back to the tty device, so they appear on the screen) without actually sending them to the running processes until you press return.
The result is the programs like `cat`[1] which do nothing more then call `read()`, and send the buffer to `write()` still allow line editing features like backspace - even though the program itself has no concept of line editing (or even lines at all).
It should be clarified that modern `bash` does operate in raw mode, and handles all the line editing itself (The `readline` library also does this - I can't say for certain if `bash` uses `readline` internally or not, I haven't checked). Unix utilities like `cat` though don't change tty settings and thus are generally operating in `cooked` mode (You can change these settings via `stty`, but it's generally not necessary).
[1] https://github.com/DSMan195276/protura/blob/master/disk/utils/coreutils/cat/cat.c#L89 https://github.com/DSMan195276/protura/blob/master/disk/util...
- WildUtah 10y agoBut try remapping C-w in bash. The tty remaps it on the very next line. You'll have to stty werase unmap it to be able to change it in your read line .inputrc. So the tty cooking still has charge of some things.
- DSMan195276 10y agoI think that's actually just bash messing with you. Bash implements it's own erase-word and binds it to whatever is set to werase in the terminal, so if you don't clear the werase entry bash will just keep rebinding it every new prompt. It's definitely not the kernel's doing - for example vim, which also uses raw mode, can use C-w just fine, and the functionality bash gives to C-w is different from what the kernel provides.
- deleted 10y ago[deleted]
- deleted 10y ago[deleted]
- deleted 10y ago[deleted]