TTY Console – Why Script Output Newline is CR + LF (DOS-Style)?

consolenewlinesttytypescript

In the typescript of script command (i.e. in the saved file), the newline is CR + LF (\r\n), although the original one (fed to script) is LF. Why?
It seems it's tty issue, which I don't know at all. Can someone explain it without much detail?

I'm not in any trouble; I'm just curious. 🙂 (But I think it's better to fix it, or at leasd should be documented.)

My script is from util-linux, but probably it does not matter much.

Best Answer

The typescript output captures all the characters sent to the pty. If you use for example stty -opost to stop the terminal driver from doing its normal change of the newline character to CR+LF then you will see that you only have LF characters in the output.

Hopefully helpful tip, use

col -b < typescript

to do a first pass at cleaning up the file.

Related Question