【问题标题】:Bash/Zsh issues with stty raw -echostty raw -echo 的 Bash/Zsh 问题
【发布时间】:2021-09-18 19:44:15
【问题描述】:

之所以出现这个问题,是因为我经常使用反向 shell,并且经常需要升级 shell 以启用选项卡自动完成或光标使用。不过,问题不仅在反向 shell 上,即使我在自己的终端中使用以下输入,我也会得到相同的结果。我使用终结者,但也在终端中尝试过这个并遇到同样的问题。

我尝试的第一种方法是:

<Ctrl-z>
stty raw -echo
fg
<enter>
<enter>

这会导致我无法输入文本(出现错误字符,例如 ^M 表示输入):

Shell working

使用 Ctrl-z 暂停,“stty raw -echo”,按两次回车,然后 fg 恢复(忽略“whoami”...!):

Ctrl-z, stty raw -echo, (please ignore the "whoami"...)

在底部您可以看到,当输入 fg 时,我可以输入文本,但如果按 ENTER,我会得到 ^M。

查看其他帖子后,我尝试了两件事。一是确保 icrnl 设置为 ON,它是。另一种是尝试将“stty raw -echo; fg”作为一个命令而不是两个命令。这产生了不同的结果。它工作得更好,但是每当我按 Enter 键时,提示就会在屏幕上移动:

stty raw -echo; fg

我尝试在 bash 而不是 zsh 中执行此操作,我得到了相同的结果。有谁知道我可以如何解决这个问题?我将在下面附上我的 stty 以获取信息:

└─$ stty -a
speed 38400 baud; rows 46; columns 116; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q;
stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc

感谢您的帮助。

【问题讨论】:

    标签: bash terminal zsh stty


    【解决方案1】:

    奇怪的是,这个问题已经有好几个星期了,我真的只是修复了它......!

    在暂停和执行 stty 之前...更改 python 命令已修复它:

    原文:python -c "import pty; pty.spawn('/bin/bash')"

    新(作品):python -c 'import pty;pty.spawn("/bin/bash")'

    去掉pty之间的空格; pty 已修复它。然后执行上述命令,但在 stty raw -echo 之后包含 ;fg。标签自动完成等一切正常! ——

    【讨论】:

    • 这不是问题的答案。如果您想包含其他详细信息,请修改您的问题。顺便说一句,我认为这个问题应该去Super User,而不是stackoverflow。
    猜你喜欢
    • 2018-12-13
    • 2014-05-15
    • 1970-01-01
    • 1970-01-01
    • 2017-10-07
    • 2011-05-30
    • 1970-01-01
    • 2013-05-09
    • 2021-06-05
    相关资源
    最近更新 更多