Search code examples
linuxterminalttyxtermpty

Executing string sent from one terminal in another in Linux pseudo-terminal


Lets say I have one terminal where the output of "tty" is "/dev/pts/2" From another terminal, I want to send a command to the first terminal and execute it. Using: echo "ls" > "/dev/pts/2" only prints "ls" in the first terminal Is there a way to execute the string?


Solution

  • No; terminals don't execute commands. They're just channels for data.

    You can sort of run a command and attach it to another terminal like this, though:

    ls </dev/pts/2 >/dev/pts/2 2>/dev/pts/2
    

    It won't behave exactly like you ran it from that terminal, though, as it won't have that device set as its controlling terminal. It's reasonably close, though.