如何恢复终端中的输入回显?

如何恢复终端中的输入回显?

有时,当脚本在密码提示符下被终止时,我无法再看到我的输入在终端中回显。也就是说,通常在终端上,我会看到以下内容:

$ _
<after typing 'foobar':>
$ foobar_

但在这种情况下,我看不到我所输入的内容。

我知道我可以重新启动终端以恢复其常规设置,但是有没有办法在不重新启动的情况下恢复输入回显?

答案1

对于 bash,我通常只需键入reset,它就会修复任何“奇怪”的东西。看起来它也被称为,tset但调用每个命令都会做一些不同的事情。

tset, reset - terminal initialization

   When  invoked  as  reset,  tset  sets  cooked and echo modes, turns off
   cbreak and raw modes, turns on newline translation and resets any unset
   special  characters  to  their default values before doing the terminal
   initialization described above.  This is useful after  a  program  dies
   leaving a terminal in an abnormal state.  Note, you may have to type

       <LF>reset<LF>

   (the  line-feed character is normally control-J) to get the terminal to
   work, as carriage-return may no longer  work  in  the  abnormal  state.
   Also, the terminal will often not echo the command.

答案2

使用stty命令。具体来说,运行以下命令:

stty echo

这将恢复回显(打印输入字符),该功能可能在密码提示期间被关闭。

要查看所有终端设置,请运行stty -a。虽然输入被隐藏,但它应该显示-echo在输出的某个位置。修复后,它应该显示echo在原处。

相关内容