Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
522 views
in Technique[技术] by (71.8m points)

unix - Make Arrow and delete keys work in KornShell command line

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

set -o emacs
alias __A=`echo "20"`     # up arrow = ^p = back a command
alias __B=`echo "16"`     # down arrow = ^n = down a command
alias __C=`echo "06"`     # right arrow = ^f = forward a character
alias __D=`echo "02"`     # left arrow = ^b = back a character
alias __H=`echo "01"`     # home = ^a = start of line
alias __Y=`echo "05"`     # 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 "20"

to get the control-n character assigned to __B.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...