When you run ssh user@somehost
without an explicit command, you're requesting ssh to start an interactive shell on the remote machine.
An interactive shell (such as bash) typically wants to have a terminal available, since it will use terminal commands to implement improved experience when editing the command line and browsing the history. (Terminal commands allow full-screen control.)
But ssh will only allocate a terminal by default (also called a pseudo-terminal) if its standard output is connected to a terminal.
If you simply run ssh user@somehost
from a terminal program (such as gnome-terminal, rxvt, xterm, etc.), then its standard output will be a terminal, so ssh will create a pseudo-terminal and the remote interactive shell will behave nicely.
If you pipe ssh through something (anything), like ssh user@somehost | cat
, then its standard output will be a pipe (and not the terminal), so ssh will not create a terminal and that might make the remote interactive shell misbehave.
A possible solution is to force ssh to create a pseudo-terminal, by passing it the -t
option, like ssh -t user@somehost | cat
, which might help. (Also, you might need a double option -tt
to force allocation of the pseudo-terminal.)
Another possibility, if you're running ssh mainly because you're interested on a specific command, is to run the specific command from the ssh command line, such as ssh user@somehost mycommand | cat
. If you run a specific command, an interactive shell does not get involved, in which case having a terminal available is likely not going to cause any issues.
sed ...
withstdbuf -oL sed ...
. Though notice that you won't have echoing and prompting in the interactivessh
if you usesed
at all (with or withouttee
). If your case, I wonder why you aren't simply usingscript(1)
. – Nov 17 '18 at 16:12sed
is GNUsed
, usesed -u
. – Nov 17 '18 at 16:19