0

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:

//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:

$ vi .bash_profile
$ vi .bashrc

Any help will be appreciated.

Jack Zhang
  • 304
  • 1
  • 9
  • 21
  • The question is unclear because `^[[C` (right-arrow) is not used for "navigation" in the shell. You may be finding some problems with mismatch of terminal and `TERM` setting, but there are no details to help people answer. – Thomas Dickey May 13 '16 at 23:08
  • When I am saying `navigation`, I mean navigating in between the characters I have typed on the command like. – Jack Zhang May 15 '16 at 22:41

2 Answers2

4

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.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Jack Zhang
  • 304
  • 1
  • 9
  • 21
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:

set -o emacs

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

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.

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:

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)
  • 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.

Community
  • 1
  • 1
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105