制表符和箭头键在redhat中的奇怪行为

时间:2022-05-05 17:26:51

I am facing some weird behavior when trying to ssh to the server by using either Iterm2 or OSX Terminal. Basically, the issue is when using tab for auto-completion, it will print one more random extra char in the end, for example:

尝试使用Iterm2或OSX终端ssh到服务器时,我面临一些奇怪的行为。基本上,问题是当使用tab进行自动完成时,它会在最后打印一个随机的额外char,例如:

//the 'e' is extra in this case
$ cd keys/e

And when trying to use any arrow keys for navigation, it basically does not work at all.

当试图使用任何箭头键进行导航时,它基本上根本不起作用。

//^[[C^[[C^[[C^[[C^[[C^[[C^[[C are printed by pressing arrow keys
$ cd keys/^[[C^[[C^[[C^[[C^[[C^[[C^[[Ce

//Kernel Version
OS Version: 2.6.39-400.246.2.el6uek.x86_64

//Distribution Information
$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.6 (Santiago)

But it works just fine in my macbook, I was guessing it is caused by my server profile setting up, but I have double-checked that I do not have either of the following files in my home:

但它在我的macbook中运行得很好,我猜它是由我的服务器配置文件设置引起的,但我已经仔细检查过我家中没有以下任何一个文件:

$ vi .bash_profile
$ vi .bashrc

Any help will be appreciated.

任何帮助将不胜感激。

2 个解决方案

#1


3  

I had it figured out, it is because of my default shell in the server is ksh, need to ask the system admin to change it to bash or zsh.

我弄明白了,这是因为我在服务器中的默认shell是ksh,需要请求系统管理员将其更改为bash或zsh。

BTW, I really hate those people who gives downvote to the question for no reason, it is kind of upset, if you do not like the question, you can just ignore it.

顺便说一句,我真的很讨厌那些无缘无故地回答这个问题的人,有点不高兴,如果你不喜欢这个问题,你可以忽略它。

#2


1  

What you termed "navigation" is part of line-editing.

你所谓的“导航”是行编辑的一部分。

If you're using ksh, the way to best use its line-editing capabilities is to turn on emacs mode:

如果您正在使用ksh,那么最好地使用其行编辑功能的方法是打开emacs模式:

set -o emacs

Apparently ksh's developer doesn't use vi, because the vi-mode is very limited. However, emacs mode is the default.

显然ksh的开发人员不使用vi,因为vi模式非常有限。但是,emacs模式是默认模式。

In your question, the cursor-keys are in normal mode (the ^[[ characters), which is assumed if TERM=linux, while other terminals conventionally use application mode (^[O characters). If your TERM is set incorrectly, that might confuse ksh. Some people define aliases in their shell initialization to make the shell work with either.

在您的问题中,光标键处于正常模式(^ [[字符],如果TERM = linux则假设,而其他终端通常使用应用程序模式(^ [O字符])。如果您的TERM设置不正确,可能会混淆ksh。有些人在shell初始化中定义了别名,以使shell可以使用。

See for example Make Arrow and delete keys work in KornShell command line. The solutions in that answer should work for you, since RHEL6 (and CentOS6) use ksh-93:

例如,参见Make Arrow和删除键在KornShell命令行中工作。该答案中的解决方案应该适合您,因为RHEL6(和CentOS6)使用ksh-93:

Name        : ksh                          Relocations: (not relocatable)
Version     : 20120801                          Vendor: CentOS
Release     : 28.el6_7.3                    Build Date: Tue Sep 22 11:08:59 2015
Install Date: Mon Mar 28 16:22:50 2016         Build Host: c6b9.bsys.dev.centos>
Group       : System Environment/Shells     Source RPM: ksh-20120801-28.el6_7.3>
Size        : 1743023                          License: EPL
Signature   : RSA/SHA1, Tue Sep 22 14:35:03 2015, Key ID 0946fca2c105b9de
Packager    : CentOS BuildSystem <http://bugs.centos.org>
URL         : http://www.kornshell.com/
Summary     : The Original ATT Korn Shell
Description :
KSH-93 is the most recent version of the KornShell by David Korn of
AT&T Bell Laboratories.
KornShell is a shell programming language, which is upward compatible
with "sh" (the Bourne Shell).

Further reading:

  • 2.1 Enabling Command-line Editing (Learning the Korn Shell)
  • 2.1启用命令行编辑(学习Korn Shell)

  • Command Line Editing in Bash and Ksh notes

    Some actions are also bound to keys with special markings, eg: Up Arrow, Del (or Delete). These are also shown where applicable. Note that these might not work if the terminal emulation is incorrect, ksh does not support them as well as does bash.

    某些操作也绑定到具有特殊标记的键,例如:向上箭头,删除(或删除)。这些也在适用的地方显示。请注意,如果终端仿真不正确,这些可能不起作用,ksh不支持它们,也不支持bash。

#1


3  

I had it figured out, it is because of my default shell in the server is ksh, need to ask the system admin to change it to bash or zsh.

我弄明白了,这是因为我在服务器中的默认shell是ksh,需要请求系统管理员将其更改为bash或zsh。

BTW, I really hate those people who gives downvote to the question for no reason, it is kind of upset, if you do not like the question, you can just ignore it.

顺便说一句,我真的很讨厌那些无缘无故地回答这个问题的人,有点不高兴,如果你不喜欢这个问题,你可以忽略它。

#2


1  

What you termed "navigation" is part of line-editing.

你所谓的“导航”是行编辑的一部分。

If you're using ksh, the way to best use its line-editing capabilities is to turn on emacs mode:

如果您正在使用ksh,那么最好地使用其行编辑功能的方法是打开emacs模式:

set -o emacs

Apparently ksh's developer doesn't use vi, because the vi-mode is very limited. However, emacs mode is the default.

显然ksh的开发人员不使用vi,因为vi模式非常有限。但是,emacs模式是默认模式。

In your question, the cursor-keys are in normal mode (the ^[[ characters), which is assumed if TERM=linux, while other terminals conventionally use application mode (^[O characters). If your TERM is set incorrectly, that might confuse ksh. Some people define aliases in their shell initialization to make the shell work with either.

在您的问题中,光标键处于正常模式(^ [[字符],如果TERM = linux则假设,而其他终端通常使用应用程序模式(^ [O字符])。如果您的TERM设置不正确,可能会混淆ksh。有些人在shell初始化中定义了别名,以使shell可以使用。

See for example Make Arrow and delete keys work in KornShell command line. The solutions in that answer should work for you, since RHEL6 (and CentOS6) use ksh-93:

例如,参见Make Arrow和删除键在KornShell命令行中工作。该答案中的解决方案应该适合您,因为RHEL6(和CentOS6)使用ksh-93:

Name        : ksh                          Relocations: (not relocatable)
Version     : 20120801                          Vendor: CentOS
Release     : 28.el6_7.3                    Build Date: Tue Sep 22 11:08:59 2015
Install Date: Mon Mar 28 16:22:50 2016         Build Host: c6b9.bsys.dev.centos>
Group       : System Environment/Shells     Source RPM: ksh-20120801-28.el6_7.3>
Size        : 1743023                          License: EPL
Signature   : RSA/SHA1, Tue Sep 22 14:35:03 2015, Key ID 0946fca2c105b9de
Packager    : CentOS BuildSystem <http://bugs.centos.org>
URL         : http://www.kornshell.com/
Summary     : The Original ATT Korn Shell
Description :
KSH-93 is the most recent version of the KornShell by David Korn of
AT&T Bell Laboratories.
KornShell is a shell programming language, which is upward compatible
with "sh" (the Bourne Shell).

Further reading:

  • 2.1 Enabling Command-line Editing (Learning the Korn Shell)
  • 2.1启用命令行编辑(学习Korn Shell)

  • Command Line Editing in Bash and Ksh notes

    Some actions are also bound to keys with special markings, eg: Up Arrow, Del (or Delete). These are also shown where applicable. Note that these might not work if the terminal emulation is incorrect, ksh does not support them as well as does bash.

    某些操作也绑定到具有特殊标记的键,例如:向上箭头,删除(或删除)。这些也在适用的地方显示。请注意,如果终端仿真不正确,这些可能不起作用,ksh不支持它们,也不支持bash。