0

I'll try to explain the title better :)

I have two terminals tty1 and tty2, let's call them that.

From tty1 I redirect the output from echo to the tty2 terminal with:

echo hello > $(tty2)

This works and I get 'hello' on tty2.

The "problem" is that after 'hello' is printed on tty2, the tty2 terminal doesn't give a prompt back. I have to manually press enter on tty2 to get a new prompt.

How can I redirect the output, but and get a new prompt after the redirect?

Thanks :)

Note: Even though 'hello' is there, I can still execute a new command, but it looks weird, and I wanted to have a clean prompt after the redirect.

5
  • 1
    "the tty2 terminal doesn't give a prompt back" – The prompt in the other terminal comes from a shell there. The shell and the terminal are two different things. To redraw the prompt you need help from the shell, but your redirection involves the terminal, not the shell. What is the shell? Please make sure there is no XY problem here. Edit the question if there is. Why do you want to print to another terminal that is in interactive use? Commented May 1 at 7:23
  • @KamilMaciorowski I am using the "at" command as an scheduler, and I have a command line app, the scheduler is called after time x, then it takes one of the actions of the command line app. Since the action is not executed on a shell, I don't see any output created by the action. So I use the tty to redirect the output back to the command line. What was annoying me, is that the "me@computer:~$" is not reset after the output. The output is printed after the prompt, then a new line is inserted.
    – Daniel
    Commented May 7 at 19:18
  • Again: what is the shell? SIGWINCH may cause the shell to rewrite the prompt, but in my tests Bash or Zsh rewrites only if the size of the window has actually changed (optimization?); besides, you would need to know the PID. In Bash you can do this, which is a manual action, still better than your Enter (especially if you may have already typed something). In Zsh you can redraw the prompt every second; note in some circumstances this may overwrite the "foreign" output. Commented May 8 at 5:26
  • Consider using tmux and printing to a dedicated pane whose shell you simply don't use interactively (easiest) or where there is no shell in the first place (harder to set up, but somewhat more elegant: "thou shalt not spawn thy shell in vain"). Commented May 8 at 5:49
  • @KamilMaciorowski I'm using Bash to run my commands. tmux doesn't work for me :( I want the output to be printed back to the shell that the user ran teh ommand from. As I mentioned, is fine as it is, it's just a cosmetic thing that doesn't affect new commands. I didn't find a way to reset the prompt as I mentioned :/
    – Daniel
    Commented May 11 at 8:33

0

You must log in to answer this question.

Browse other questions tagged .