Linux终端:输入反馈消失,换行符不显示

E.Z*_*.Z. 50 linux bash terminal putty gnome-terminal

我不得不运行一个命令行工具(Python脚本),其输出似乎打破了我的终端.执行完成后,输入的反馈消失了(我看不到我正在键入的内容),也没有显示换行符.如果终端通过远程启动出现这种情况Putty,而且在本地使用时gnome-terminal.

例如,问题发生后,如果我输入ENTER pwd ENTER,我希望看到:

[userA@host006 ~]$
[userA@host006 ~]$ pwd
/home/userA
[userA@host006 ~]$
Run Code Online (Sandbox Code Playgroud)

但实际上输出是:

[userA@host006 ~]$ [userA@host006 ~]$ /home/userA
                                                             [userA@host006 ~]$
Run Code Online (Sandbox Code Playgroud)

修复它的唯一方法是关闭该终端并启动一个新终端.

也许是相关的:脚本输出包含一些基于终端的格式化(例如,反转前景/背景以突出显示某些状态消息).如果我将此输出转储到文件,我可以看到类似的东西[07mSome Message Here[0m.

我有什么想法可以防止这种情况发生?

Jos*_*man 105

执行命令reset,应恢复终端(参考).

当将二进制数据转储到终端STDOUT时,通常会发生此问题,当处理收到的转义码时,可以通过更改文本的颜色,禁用回显,甚至更改字符集来执行任何操作.

避免这种情况的简单方法是确保不将未知二进制数据转储到终端,如果必须将其转换为十六进制以确保它不会更改终端设置.


Bas*_*ers 8

To elaborate on Joshua Briefman's answer, executing reset -c will only reset the control characters responsible for your problem:

tset, reset - terminal initialization

Usage: tset [options] [terminal]

Options:
  -c          set control characters
  -e ch       erase character
  -I          no initialization strings
  -i ch       interrupt character
  -k ch       kill character
  -m mapping  map identifier to type
  -Q          do not output control key settings
  -r          display term on stderr
  -s          output TERM set command
  -V          print curses-version
  -w          set window-size
Run Code Online (Sandbox Code Playgroud)

Also note the following form the the command's manual:

Note, you may have to type

<LF>reset<LF>
Run Code Online (Sandbox Code Playgroud)

(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.