Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Arrow and delete keys work in KornShell command line

Tags:

shell

unix

ksh

I am new to Unix and am using sun solaris (v10 I think). I have my shell set as KornShell (ksh).

I am wondering how to make the arrow keys and delete key work in the command line. I have done set -o emacs and the backspace works, but not the arrow keys and the delete keys.

Also is it possible to set the up and down arrow key to cycle through the command line history?

like image 927
user66854 Avatar asked Oct 26 '09 05:10

user66854


People also ask

How do I use the arrow key in CMD?

You can simply press Shift-right-arrow, and then start typing. In contrast, to these combination shift-arrow commands which move the cursor to the beginning and end of lines, the Ctrl-left-arrow and Ctrl-right-arrow keys move the screen image 20 spaces in the opposite direction to the arrow, without moving the cursor.

What does the up arrow key do at the CLI?

To access previous commands, simply press the up arrow. This will give you the last command you typed in. Pressing it again will produce the command before that, and so on.


3 Answers

For the arrow keys, you can put this into your the .kshrc file in your home directory:

set -o emacs
alias __A=`echo "\020"`     # up arrow = ^p = back a command
alias __B=`echo "\016"`     # down arrow = ^n = down a command
alias __C=`echo "\006"`     # right arrow = ^f = forward a character
alias __D=`echo "\002"`     # left arrow = ^b = back a character
alias __H=`echo "\001"`     # home = ^a = start of line
alias __Y=`echo "\005"`     # end = ^e = end of line

Note that there are two underscore characters before the letters on the left side of the equal sign. On the right-hand side of the equal, the goal is to get the proper control character assigned to the alias. The way this script does that, is by running the command (via back-tics)

echo "\020"

to get the control-n character assigned to __B.

like image 197
Tim Avatar answered Sep 18 '22 15:09

Tim


I used following and is working fine:

set -o emacs

Note: these are the actual control characters. In vi, type i ctrl-v then ctrl-P (if u want a ctrl-p)

alias _A=^P
alias _B=^N
alias _D=^B
alias _C=^F

and add below lines too:

alias __A=^P
alias __B=^N
alias __D=^B
alias __C=^F
like image 26
Vishal Avatar answered Sep 19 '22 15:09

Vishal


Don't fight it. Just have your administrator change your default shell to bash. bash is included with Solaris 10, is highly ksh compatible, and it supports the key mappings that you like. You can launch bash just by typing:

$ bash

You could exec bash out of your .profile if your administrator is not helpful. Here is what your administrator would do to change user1 to bash (as root):

# passwd -e user1
Old shell: /bin/ksh
New shell: /usr/bin/bash        <- You type this, use whence bash to look up the path
passwd: password information changed for user1
like image 27
Bob Stark Avatar answered Sep 18 '22 15:09

Bob Stark