5

If I open up a terminal (xfce4-terminal 0.6.3, but I doubt it matters) and I look at what terminal attributes are set (BASH is running in the terminal),

$ stty -a
speed 38400 baud; rows 24; columns 80; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = M-^?; eol2 = M-^?;
swtch = M-^?; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;
lnext = ^V; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 hupcl -cstopb cread -clocal -crtscts
-ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
-iuclc ixany imaxbel iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke -extproc

then I have a whole bunch of terminal attributes. Fine enough. If I then take a look at what terminal I'm using:

$ tty
/dev/pts/0

then, on a new tab of my terminal (which new tab happens to be /dev/pts/1) I look at the terminal attributes of my first terminal, it seems to have slightly different terminal attributes:

$ stty -a -F /dev/pts/0
speed 38400 baud; rows 24; columns 80; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = M-^?; eol2 = M-^?;
swtch = M-^?; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;
lnext = <undef>; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 hupcl -cstopb cread -clocal -crtscts
-ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl ixon -ixoff
-iuclc ixany imaxbel iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig -icanon iexten -echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke -extproc

Notably, the original terminal here appears to not be in canonical mode, it has no literal next special character...

So why does this happen? I'd like to be able to look at things like this to see, e.g., if modern ed uses canonical mode, but if there's a Heisenberg problem of looking at it from another terminal, I don't know how I'd do it.

So, my two main questions:

  1. Does the terminal just appear to have different attributes when I look at it from another terminal? (e.g. is my first terminal still in canonical mode, but stty -a -F returns incorrect information?)
  2. If the terminal does really change attributes when I switch to the other terminal, how does it know? Is the 1st terminal somehow informed when I'm not directly looking at it?

P.S.: I tried this on the Linux Console also, just to make sure it wasn't a pseudo-terminal thing. Same results.

6

Bash needs to put the terminal into character-at-a-time mode while it's waiting for you to type in a command line, so that you can edit the command line using emacs or vi-like editing characters. That's the mode you saw when you looked at the terminal's attributes from another terminal in your example.

Just before it runs a program (in your example, stty), bash puts the terminal back into canonical mode, where you have just a few special editing characters available courtesy of the operating system, such as backspace and Control-W, and basically the program gets input only after you type Enter.

When bash regains control, say after the program finishes or is suspended, it will put the terminal into character-at-a-time mode again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.