Operating System - HP-UX
1843983 Members
1923 Online
110226 Solutions
New Discussion

Use Arrow keys to view previous commands in a unix shell

 
SOLVED
Go to solution
Bala_4
Occasional Advisor

Use Arrow keys to view previous commands in a unix shell

Hi All

I want to map my arrow keys so that I can use it to scroll to previous commands.
The shell I am using is ksh. Presently I use ESC K to view my previous commands. Is there any way I can map my keyboard.
OS : HP-UX ver 11.00
Shell : /usr/bin/ksh

Thanks in advance

Bala
6 REPLIES 6
Rick Garland
Honored Contributor

Re: Use Arrow keys to view previous commands in a unix shell

The bash shell allows you to do this. Can go forward and backwards to view previous commands
Bala_4
Occasional Advisor

Re: Use Arrow keys to view previous commands in a unix shell

Hi Rick
I am aware that this can be done in bash shell. But can it be done in ksh

Thanks
Bala
Vinit Adya
Frequent Advisor

Re: Use Arrow keys to view previous commands in a unix shell

Bala,

This can be done in ksh using the emacs editor, if you have it.
i.e.
set -o emacs
Alexander M. Ermes
Honored Contributor

Re: Use Arrow keys to view previous commands in a unix shell

Good day, Bala.
Sorry for using this way to try to find something out.
Is your real name Balasubramanya or something ?
This nickname sounds familiar to me.
Please check my forum profile. If you are the person, i think you are, please contact me.
Email : Alexander_Ermes@ web.de
.. and all these memories are going to vanish like tears in the rain! final words from Rutger Hauer in "Blade Runner"
Steve Post
Trusted Contributor

Re: Use Arrow keys to view previous commands in a unix shell

You can identify what ascii key sequence is comming out of your arrow keys this way....
vi junkfile
hit i to insert, type control-v, then the up arrow key.
Then you will probably see something like ^[[A.
So now you know the up arrow is escape[A.
Somehow you would map escape[A to change to escape k. In normal vi, you would modify $HOME/.exrc file to add a "map command". But for everyone with command shell editing? I don't know. Hope this helps.
Tom Rosenfeld
Occasional Advisor
Solution

Re: Use Arrow keys to view previous commands in a unix shell

You can actually do this in ksh88, but only if you use emacs mode. From a previous posting:

here is the mapping if you use Emacs-style editing...
alias -x __A=^P # Ctrl-P: Line up (Previous)
alias -x __B=^N # Ctrl-N: Line down (Next)
alias -x __C=^F # Ctrl-F: Character right (Forward)
alias -x __D=^B # Ctrl-B: Character left (Backward)
alias -x __H=^H # Ctrl-H: Go to line beginning
alias -x __P=^D # Ctrl-D: Delete character forward
alias -x __q=^E # Ctrl-E: Go to line end

You need to enter the control keys carefully...
e.g. $(echo '\016') for ^P

In ksh93 (dtksh) you can also use the above, or use the KBD trap which will also work in vi mode. For details see the newsgroup discusson at:
http://groups.google.com/groups?hl=en&lr=&safe=off&ic=1&th=bee009ab2ea86936&seekd=991501790#991501790