Andy
Andy

Reputation: 12005

How can I configure the Linux terminal to only line feed (and not carriage return) when outputting a "\n"?

When I run a program that outputs "\n" to the terminal, I'd like to configure the terminal beforehand (perhaps via stty) to not do a Carriage Return, but to only move the cursor down a row. To actually consider it a Line Feed, and not to perform a Carriage Return.

For example, if the program prints "123\n456", I would like to see:

123
   456

but I, of course, currently see:

123
456

Upvotes: 2

Views: 1421

Answers (1)

that other guy
that other guy

Reputation: 123660

man stty says:

   * [-]onlcr
          translate newline to carriage return-newline

So we can turn it off, print something, and turn it on again:

$ stty -onlcr; printf '\rfoo\nbar\r\n'; stty onlcr
foo
   bar

Upvotes: 4

Related Questions