0

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
phuclv
  • 37,963
  • 15
  • 156
  • 475
Andy
  • 11,215
  • 5
  • 31
  • 33

1 Answers1

2

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
Andy
  • 11,215
  • 5
  • 31
  • 33
that other guy
  • 116,971
  • 11
  • 170
  • 194