There is a statement

stty onlcr 0>&1

in rc.sysvinit file. What does exactly this line do? What's the reason for redirecting stdin to stdout?

2 Answers 2

$ man stty
   * [-]onlcr
          translate newline to carriage return-newline

and there's even a comment in the file, which you failed to mention:

# Set onlcr to avoid staircase effect.

So that should make it clear what the line does. stty operates on stdin by default, but this line changes output settings, so 0>&1 makes it work on stdout. Which can actually matter if you've a box where the console stdout is hooked up to one serial port, and the console stdin input to some other source ...


stty changes terminal parameters. To do so, it must issue system calls which operate on a file handle that correspond to a terminal. By default, this is stdin, as the manpage says:

  -F, --file=DEVICE
          open and use the specified DEVICE instead of stdin

I'm not sure what kind of example would help you ...

  • What do you mean "stty operates on stdin by default"? Can you give me an example?
    – Ringger81
    Jul 29, 2018 at 9:08
  • Can You answer my last question please?
    – Ringger81
    Jul 30, 2018 at 9:21
  • I tried to answer the question with the edit. Which part of the edit is not clear? What kind of examples do you think you need? Do you understand the concept of Unix tty's, and that stty changes parameters for them?
    – dirkt
    Jul 30, 2018 at 9:26
  • How does stdin relates to dev/tty1, dev/tty2 ...?.
    – Ringger81
    Jul 30, 2018 at 9:39
  • Do you understand what stdin and stdout mean? When a process is executed on Unix, what can a process assume about stdin and stdout, and who decides where stdin and stdout point to?
    – dirkt
    Jul 30, 2018 at 10:16

If you type man stty you'll get the documentation for stty, which among other things says

[-]onlcr translate newline to carriage return-newline

The reason for the redirection is that stty operates on its stdin, but there's only stdout available at the time the command is run.

  • "stty operates on its stdin, but there's only stdout available at the time the command is run" - can You explain me that more?
    – Ringger81
    Jul 30, 2018 at 9:20
  • Can You answer my last question?
    – Ringger81
    Aug 1, 2018 at 9:34
  • @Ringger81 which bit is unclear? Aug 1, 2018 at 18:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .