why can't I write to the standard input of my terminal device from another terminal why can't I write to the standard input of my terminal device from another terminal unix unix

why can't I write to the standard input of my terminal device from another terminal


Writing to a terminal device just prints output on the terminal. If it stuffed the text back into the input buffer, then everything you printed to stdout would loop back into stdin, since they're both connected to the same terminal device.

In order to put data into a pseudo-tty's input buffer, you have to write to its master device. Unfortunately, they don't have distinct names in the filesystem on Linux. There's a single /dev/ptmx device, and the master process uses grantpt() to create a slave that's linked to it before spawning the child that uses it as its controlling terminal. So there's nothing in the filesystem that you can write to that will feed into the pty's input buffer.


You can do it by doing this commands, (from /dev/pts/1 or another tty):

exec 1>/dev/pts/0

to deactivate

exec 1>/dev/pts/1 #or your actually original tty address.

Basically you are supplanting the tty stdin.

Edited for more details.

"exec" in this case starts a new bash and you can feed this with a new set of environment variables that normally you can not change on the fly. For more details please do "man exec".

"1>/dev/pts/0" here we are saying, "whatever I type on this new bash, write it to this another one, and indeed it will do it, but all the stdout will be displayed at the original tty.

Good luck learning linux, I hope you enjoy it.