I have an awk script in .bashrc that reads characters and modifies some keywords. It works perfectly when I pipe tail -f and other basic commands through it, but I have a problem when I pipe ssh through it. Everything works fine as expected except I cannot see anything I type on terminal until I press return:

~# ssh admin@localhost -p 5200 | my-script

admin@localhost's password: 

admin connected from using ssh on home

admin@ssh-server> exit   ***<- I don't see this line (including the prompt) at all on terminal until I type my command (exit) and press Enter***

Connection to localhost closed.

I think I understand why it's behaving like that but don't know how to fix it. I think the interactive commands to ssh are not sent through pipe until EOL is returned. I have tried everything I found searching from unbuffer/stdbuf to tee/script and playing with various redirection commands but all without luck.

Note: I'm actually ok that the strings are passed to my-script after EOL, I just need to be able to see what I'm typing i.e. need terminal stdin to echo as usual.

  • it won't echo if you pipe it away. Use a tee to pipe it into the file and then into the script. Or make your script to do that job.
    – Jakuje
    Aug 15, 2017 at 10:01
  • @Jakuje - I assume you meant 'ssh example.com | tee file | my-script' .... I still see same behavior. Can't see what I'm typing until hit return (no stdin echo by tty kernel).
    – lamp
    Aug 15, 2017 at 18:00

2 Answers 2


I am able to do the following:

$ ssh [email protected] | tee output
Last login: Tue Aug 15 03:06:11 2017 from
$ ls /
bin  boot  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
$ logout
Shared connection to example.com closed.
$ cat output
Last login: Tue Aug 15 03:06:11 2017 from
$ ls /
bin  boot  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
$ logout

I see the prompt, my input, and everything else when sshed into the remote host as normal.

  • you're teeing to a file named 'output'... that's not what I'm doing. I'm piping to an awk script shown as 'my-script'
    – lamp
    Aug 15, 2017 at 4:08
  • How about | tee >(my-script)? Aug 15, 2017 at 10:42
  • @AndrásKorn - that works partially. I get duplicate output on terminal, one from ssh and one from my-script. I need the interactive ssh output to be processed by my-script first and then printed on terminal.
    – lamp
    Aug 15, 2017 at 18:11
  • You could try to make stdin and stdout unbuffered using stdbuf -i0 -o0, but something your script does may still insist on reading an entire line before outputting anything. Aug 15, 2017 at 18:45
  • @AndrásKorn - I had tried stdbuf before without luck. Also I'm totally ok with my script reading an entire line before outputting, the problem is I can't see what is being typed inside ssh session i.e terminal doesn't echo stdin until eol is returned.
    – lamp
    Aug 15, 2017 at 21:43

If your interactive shell doesn't require a terminal to work, consider disabling PTY in your SSH client, by adding option -T to ssh(1) command. You will be able to see your typings because the echo is done in your local terminal in this case.

Note that OpenSSH ssh(1) redirects stderr to stdout if PTY is enabled, so your script may get less data if PTY is disabled. See also https://stackoverflow.com/questions/16838624/why-does-openssh-requesttty-cause-stderr-redirected-to-stdout.

You must log in to answer this question.

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