WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: why "stty -echo" exits from ssh  (Read 186 times)

Offline mocore

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 788
  • ~.~
why "stty -echo" exits from ssh
« on: May 22, 2026, 04:45:05 AM »
sshing into a box running tc ...
then running "stty -echo"
eg
Quote
   ( '>')
  /) TC (\   Core is distributed with ABSOLUTELY NO WARRANTY.
 (/-_--_-\)           www.tinycorelinux.net

tinycore@pc:~$ stty -echo
Connection to *ip-address* closed.
ob@otherbox:~/


causes  exit from ssh
presumably something to do with  still somewhat mystic tty ...
see also :" the TTY demystified " @ https://forum.tinycorelinux.net/index.php?topic=27406.0


background , trying (to copy) various methods[2] to capture key press in script (awk)
i found "stty -echo" appeared to be used to prevent "asci control characters"
from being echoed

eg
Quote
awk 'function cmd(str){ cmd_str=( str == "" ? "echo foo" : str) ; while( (cmd_str | getline line) >0 ) print line  }
BEGIN{ cmd("clear"); while(1) { getline xline < "/dev/tty" ; print  xline ; } }'

run the above infinite loop
then pressing
>up down left right
arrow keys
*should* show
Quote
^[[A^[[C^[[D^[[C

** use ctrl-c to exit the process ( though id assume that is obvious to most readers !)

Code: [Select]
awk 'function cmd(str){ cmd_str=( str == "" ? "echo foo" : str) ; while( (cmd_str | getline line) >0 ) print line  }
BEGIN{ cmd("clear;stty -echo"); while(1) { getline xline < "/dev/tty" ; print  xline ; } }'

adding (the mystical) command "stty -echo" to the command indeed prevents this echoing ;
when run locally

can any more knowledgeable mystic explain
what magic it is exactly
which makes  "stty -echo" exit from ssh? ?.?.?


**[2]
comparing
key-press methods from fm.awk and
https://jellepelgrims.com/posts/awkventure
 https://github.com/jpelgrims/awkventure

« Last Edit: May 22, 2026, 04:47:02 AM by mocore »

Offline mocore

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 788
  • ~.~
Re: why "stty -echo" exits from ssh
« Reply #1 on: May 23, 2026, 06:39:46 AM »
it appears my testing / meddling in the mysterious cli domain

The second  stty  command restores the terminal to "sane" settings.

 might have  made my  terminal un "sane" 

and a potential solution might be to wrap the key-press test
in a shell script and *some how* "reset" the terminal if when the tests exits....

https://unix.stackexchange.com/questions/609115/how-to-make-ctrl-c-work-in-command-line-when-it-does-not
https://stackoverflow.com/questions/5297638/bash-how-to-end-infinite-loop-with-any-key-pressed


Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 12786
Re: why "stty -echo" exits from ssh
« Reply #2 on: May 23, 2026, 08:19:37 AM »
Hi mocore
You know you can undo:
Code: [Select]
stty -echoby running:
Code: [Select]
stty echo

Offline mocore

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 788
  • ~.~
Re: why "stty -echo" exits from ssh
« Reply #3 on: Today at 03:31:29 PM »
^^

hi rich
iv did not! ... do you think this method is likely

to appease the "line discipline"  and therein  preventing *whatever* causes  ssh exiting ?

on abit of a tanget
i managed to find this
https://bbs.archlinux.org/viewtopic.php?pid=779448#p779448

Code: [Select]
#!/bin/awk -f

BEGIN {
  do {
    exit_code = system("sleep 10 && exit 27")
    print "exit_code: " exit_code
  } while (exit_code != 0)
}

and more tangents relating to sleep
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/kernel/time/hrtimer.c
and busybox sleep configuration support for fractions
...  ???


+
https://unix.stackexchange.com/questions/267415/make-bash-exit-0-when-called-by-awk-and-interrupted-with-c
https://stackoverflow.com/questions/37491467/what-is-the-behavior-of-each-ctrl-key-and-its-signals
+gawk extensions
https://github.com/takubo/awk-posix-signal

wrt to the original topic
https://stackoverflow.com/questions/21384040/why-does-the-terminal-show-a-b-c-d-when-pressing-the-arrow-k
https://stackoverflow.com/questions/21384040/why-does-the-terminal-show-a-b-c-d-when-pressing-the-arrow-k#comment134750432_76418140


it seams that the above expose some of the historically rougher edges of script composition  :o

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 12786
Re: why "stty -echo" exits from ssh
« Reply #4 on: Today at 03:57:19 PM »
Hi mocore
I don't know if it will help you.
All I know is:
Code: [Select]
stty echois supposed to re-enable echo on the terminal.