5

Why don't stty -a list raw in its output, when any modern shell, like Bash, is said to operate in raw mode?

I understand that any modern shell should operate in raw mode, i.e:

  • Input made available character by character.
  • Echoing is disabled.
  • All special processing of terminal input and ouput is disabled.

and that Readline processes user input.

So, why isn't raw listed in the output from stty -a?

2
  • 1. raw is not a tty flag, but a combination setting, which will turn other flags on and off. stty -a only tells you which flags are on and which are off. 2. the commands run from the shell get a "cooked" not a raw terminal -- either cat or stty. 3. only the bash shell is using readline. 4. readline will change the terminal back to "cooked" when the user has finished editing. 5. your Q looks artificial, sorry.
    – user313992
    Commented Aug 25, 2019 at 9:42
  • 1
    @pizdelect - is there any way I could see the current terminal mode for Bash, e.g. raw or cooked? Why does Readline change the terminal back to "cooked"? Doesn't it stay "raw" for Bash? Otherwise, Readline will not get input before the user presses a newline.
    – Shuzheng
    Commented Aug 25, 2019 at 10:12

1 Answer 1

5

Because that raw mode is a bit of an approximation. There's no official definition of raw mode and in practice it means different things for different APIs.

What they meant is that shells like bash that implement their own line editor disable some of the features of the tty line discipline. In particular, they need to disable the line discipline's own line editor (icanon setting aka -cbreak) and local echo. They don't disable some other line discipline features like the sending of SIGINT upon ^C (isig setting).

stty -a reports the individual discrete termios settings (like those icanon, echo, isig above).

stty also supports a few aliases to set more than one setting at a time like sane, cooked or... raw.

stty raw disables all tty line discipline features except echo. So there are features it disables (like isig) that bash doesn't for its line editor and it doesn't disable echo while bash does.

The manual of the GNU implementation of stty describes raw as being equivalent to -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -icanon -opost -isig -iuclc -ixany -imaxbel -xcase min 1 time 0. That's the set of discrete termios settings that stty raw tweaks (leaving the other ones alone).

Note that opost is not a stty alias, it's a discrete tty line discipline setting of its own but it affects all other output post-processing settings like onlcr, olcuc. Or in other words onlcr/olcuc are ineffective if opost is not on which explains why stty raw doesn't bother turning off all those output processing features.

Some systems have cfmakeraw() / cfmakesane() libc functions that can also set more than one setting at once. The cfmakeraw() of the GNU libc at least is different from GNU's stty raw in that for instance it disables echo and doesn't disable iuclc or ixoff.

8
  • Thank you. So, is the raw mode described by man termios by any means related to the raw combination setting of stty? In particular, while man termios describes canonical and raw modes with respect to how input is made available, either line-by-line or char-by-char, respectively, will the settings of stty change how input is made available (e.g. stty icanon or stty raw), or do they only affect the line discipline (handling of special characters, signals etc.)?
    – Shuzheng
    Commented Aug 26, 2019 at 9:26
  • @Shuzheng, if you're referring to cfmakeraw(), that's yet a different set of settings. In any case, that's all about the tty line discipline. icanon/isig are all configuration of the tty line discipline. They are not applicable and wouldn't make sense when using a difference line discipline like SLIP (IP over serial) or serial mouse driver. Commented Aug 26, 2019 at 9:45
  • StéphaneChazelas - but, will setting stty icanon but the terminal in "canonical mode" as described by man termios? The icanon setting (stty) only enables the following characters: erase, kill, werase, rprnt, but it doesn't say whether the input will be made available line-by-line?
    – Shuzheng
    Commented Aug 26, 2019 at 13:28
  • 1
    @Shuzheng the "Canonical and noncanonical mode" are described in the termios(3) manpage in the section with the same name. Just read it.
    – user313992
    Commented Aug 26, 2019 at 13:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .