When the connection is slow, I connect to remote computers using SSH without allocating a pseudo-terminal (e.g. ssh -T user@example.com
or ssh user@example.com bash
). Although I am able to use the shell, the shell does not display a prompt. Is there a way to make the shell display a prompt (e.g. $
) when connecting via SSH without a pseudo-terminal?
I could run the bash script below on the remote computer, but I'm wondering if there is something built-in that I can use to get a prompt.
#!/bin/bash
# or #!/bin/sh
PS='$ '
prompt() {
printf '%s' "$PS"
read -r line
# Exit if EOF (Ctrl-d).
[ "$?" -ne 0 ] && echo && exit
eval "$line"
}
# Handle Ctrl-c.
trap 'echo && prompt' INT
while :
do
prompt
done
(Adapted based on: https://tldp.org/LDP/abs/html/intandnonint.html)
This script has the disadvantage that it is not able to handle multi-line inputs.
-T
option isn't actually helping much. Does it? Do you know? Happily I no longer need to deal with such slow connections these days so I can't test.