32

Based on what I have read, when a terminal is in raw mode, the characters are not processed by the terminal driver, but are sent straight through.

I set the terminal in raw mode using the command stty raw, and I noticed that the output is indented to the right each time until there is no more room. This is what I mean:

enter image description here

Why is this behavior happening?!

Cornelius
  • 103
paul
  • 475
  • 5
  • 10

1 Answers1

49

One of the stty settings (onlcr) tells the terminal driver to convert newline (which is actually ASCII line-feed) to carriage-return plus line-feed.

Unix-like systems just write a newline to end lines, letting the terminal driver do the right thing (convert newline to carriage-return plus line-feed).

Carriage-return "goes left" and line-feed "goes down".

When you set the terminal to raw mode, newline will no longer be converted to carriage-return plus line-feed. Lacking the carriage-returns, you get that staircase effect.

John
  • 563
Thomas Dickey
  • 76,765
  • and for a in-depth view, you can have a look at @stéphane-chazelas really good post: https://unix.stackexchange.com/questions/151916/why-is-this-binary-file-transfered-over-ssh-t-being-changed/151963#151963 , which shows a lot of interresting things about terminal conversions (and their side effects). In a nutshell: only "ssh -t" to use interactive commands, but in your scripts use just ssh if you want to get the exact thing the command generated (ex: tar files created on one side of an ssh and read/written on the other side: don't add "-t" or it could (...will?) mess up your binaries ) – Olivier Dulac May 22 '17 at 15:52