stair-stepping when using a pty (through ssh) and piping to more stair-stepping when using a pty (through ssh) and piping to more unix unix

stair-stepping when using a pty (through ssh) and piping to more


To remove extra carriage return characters you have to use stty -onlcr, not stty onlcr (see: Extra Carriage Return on Each Printed Line).

What happens if you first pipe the output of the ssh command to cat -v and then to less?

ssh -t localhost "stty -echo -onlcr; cat testfile.txt; stty echo onlcr" | cat -v | less -U

If you want your ctrl+C keyboard interrupts to propagate through to the remote process, you may try an "EOF to SIGHUP" converter via a named pipe (see: ssh command unexpectedly continues on other system after ssh terminates; to kill the entire remote shell use: kill -HUP -- -$$).


Your problem is EOL markers; MacOS uses CR (\r aka \x0d) characters, Linux uses LF (\n aka \x0a). Due to supporting terminal drawing characters like the CR, ssh is interpreting them as characters that move the cursor around the screen instead of EOL markers. Try this:

ssh -t myuser@anotherhost "sed -e 's,\\r,\\n,' ~/severalLineFile"

OR

ssh -t myuser@anotherhost "tr '\\r' '\\n' < ~/severalLineFile"

If that doesn't work you can use scp to copy the file to the terminal:

scp myuser@anotherhost:severalLineFile /dev/stdout