talvez você só precise fazer:
stty sane
Noto que a página forkpty() man diz que copiará as configurações de termios *termp para o pty recém-aberto, mas ele não diz especificamente o que faz com isso de outra forma, e o único argumento não-NULL que você entrega forkpty() é para o pty master fd. Eu acho que você acabaria com uma estrutura termios inteiramente NULL, que não pode ser muito útil. Ele não se incomodaria bash terrivelmente que tem readline() para lidar com todo o seu próprio material de terminal, e assim interpretaria todos os caracteres padrão por padrão.
a"qui está um blockquote de um a"rtigo a"> sobre o assunto:
stty's-Foption can be great for peeking at what some other program is doing to its terminal. If you runttyin a shell, it will print the path to that shell's terminal device (usually of the form/dev/pts/N, at least under Linux). Now, from a different shell, you can runstty -a -F /dev/pts/Nto see how the first shell's terminal is configured. You can then run programs in the first shell, and repeat thesttyincant in shell two to see what settings are getting set. For example, if I runstty -F /dev/pts/10right now (while I have abashtalking to agnome-terminalvia that pty), I see:
$ stty -F /dev/pts/10
speed 38400 baud; line = 0;
eol = M-^?; eol2 = M-^?; swtch = M-^?; lnext = <undef>; min = 1; time = 0;
-icrnl iutf8
-icanon -echo
So we can see that
bash/readlinehas disabledCR→LFtranslation on input (icrnl), disabledcanonicalmode andecho, but turned on UTF-8 mode (becausebashdetected a utf-8 locale). Note that if I runsttydirectly in that shell, I see something slightly different:
$ stty
speed 38400 baud; line = 0;
eol = M-^?; eol2 = M-^?; swtch = M-^?;
iutf8
This is because
bashmaintains its own set oftermiossettings (forreadline), and saves and restores settings around running programs, so that settings in place while running a program are different from those in place while you're typing at thebashprompt.