how to set top arrow to get the history of last used commands


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how to set top arrow to get the history of last used commands
# 1  
Old 08-06-2011
how to set top arrow to get the history of last used commands

guys

can any one help me how to set top arrow to get the history of last used commands.I am using ksh
# 2  
Old 08-06-2011
It really depends on version of your ksh and your system/terminal (emulator) you use.
# 3  
Old 08-06-2011
well this is what I have .I did a tty and

/dev/pts/1


but in general how do we set that option
# 4  
Old 08-07-2011
Well... My daily English exercise Smilie

The easy way: try to put in your "~/.profile" this lines:
Code:
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

If this wouldn't work there is always a hard way. Smilie

1. You should know what key sequence your cursor keys send. The most terminal emulators send
<ESC>[A - up
<ESC>[B - down
<ESC>[C - right
<ESC>[D - left
But it may be different for your terminal (and they are very different, for example, for PgDn, PgUp, etc.)
Another variant they cand send <ESC>OA, <ESC>OB, etc...
You can try to check this pressing <CTRL>V key and then <Up> cursor key. If it doesn't work (but I believe it should) you can try run "cat" and use the same combination (it's necessary that your kernel supports lnext control character - maybe you can see this with "stty -a" command). The last resort is to use "vi" and use again this combination in input mode.
If you see some output after this key pressing it is should be like this: "^[[A" The first two keys are actually the one <ESC> key.

2. Then you need to learn what file you can use to write your settings. This is really depends on your shell. If you login in text console then to change ".profile" in your home directory would be enough. But if you use some kind of DE, then it may be ".kshrc" (for the latest ksh93) or ".mkshrs" (for mksh) or more likely you need to set your ENV variable to the name of your .rc (run commands) file in your .profile or something else (it depens on you system - it can be "~/.pam_environment", for example). Try to add this in your "~/.profile":
Code:
ENV="$HOME/.kshrc"
export ENV

Then relogin and see what "echo $ENV" prints.

3. Now the final part. At the first add to your "rc" or ".profile"
Code:
set -o emacs

Then your keys in ksh will act like keys in emacs editor. This mode is much more intuitive for novices. Even if you know or learn vi, emacs mode for shell is better choice. And I believe it is more hard (if possible) to assign cursor keys to work in ksh vi mode.

I assume that your attempt with "alias __A" doesn't work. So you should use some black magic:
Code:
trap '.sh.edchar=${keymap[${.sh.edchar}]:-${.sh.edchar}}' KEYBD
keymap=(
  [$'\e[A']=$'\cp'
  [$'\e[B']=$'\cn'
  [$'\e[D']=$'\cb'
  [$'\e[C']=$'\cf'
)

Of course, you should change $'\e[A' to $'\eOA' if your terminal send these key sequences for cursor keys.

Hope, this can help.
Regards, yazu.

PS You can try to learn your ksh version using this keys: <ESC> and then <CTRL>V.

Last edited by yazu; 08-07-2011 at 01:25 AM.. Reason: PS
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UP arrow button to recall previous commands in Putty

Hi, I remember in my previous project, I used UP arrow button to recall previous unix commands (using putty on Sun OS), which I am not able to do in my new project... I do not know if this is some project specific settings or not... when I press UP arrow button, all I get is ^. I have to... (3 Replies)
Discussion started by: juzz4fun
3 Replies

2. Shell Programming and Scripting

commands History

how to list all commands history for a username during a certain time ? Maany Thanks (2 Replies)
Discussion started by: Sara_84
2 Replies

3. Shell Programming and Scripting

history commands

Hi Guys, I am running RHEL5, I am trying to find out the history of the cammands that were executed on my server. I have files that are missing I just want to find out what happened to them. I used history | more but I can't find anything related to my query. I also checked... (1 Reply)
Discussion started by: Phuti
1 Replies

4. UNIX for Dummies Questions & Answers

Hiding history of my commands

i have several boxes running either ubuntu, redhat or solaris. there are multiple people with root access on these boxes. i really dont like people looking through my command history, is there a way i can prevent this? what files do i have to edit to prevent anyone from being able to see what... (7 Replies)
Discussion started by: SkySmart
7 Replies

5. UNIX for Dummies Questions & Answers

How to review the history and the commands that has been done in this history?

Hello every body, Kindly inform me How Do i find out the time I executed a command previously on UNIX Solaris?? To be more specific and more clear about what i want to know is that I want a command the enables me to know the history and which command i run at this history/time. FYI I used... (5 Replies)
Discussion started by: ahmedamer12
5 Replies

6. Solaris

How to set history key in Solaris

Hi Solaris guys, I just have my solaris 10 setup on x86 old box... How can i get history key? eg. Linux using up/down arrow key to call history command... HPUX using Esc-k How can i do the samething in Solaris? Thanks in advanced! Regards, gary (3 Replies)
Discussion started by: timontt
3 Replies

7. Linux

history of commands

I would like to log all the commands I type (on the terminal) to a file. The command "history" does this only for current terminal only. I typically keep around 10 terminals open. Thanks, j Note: I do not have root access. (2 Replies)
Discussion started by: superuser84
2 Replies

8. Solaris

History commands

Dear What's the command to be executed to retreive all history commands for a specific user? (1 Reply)
Discussion started by: abu_hassan
1 Replies

9. UNIX for Dummies Questions & Answers

how do I get my arrow keys to work for looking thru my PREVIOUS UNIX COMMANDS

how do I make my arrow keys behave like they are on DOS. ALSO i need editing on command promt like it is on DOS on my UNIX prompt can anyone help pl.. (11 Replies)
Discussion started by: spotnis
11 Replies

10. UNIX for Dummies Questions & Answers

ksh: how to make [up arrow] recall command history

I want to get my up arrow key to recall my previous commands in Korn shell. Anyone help please? thanks a bunch! BG (3 Replies)
Discussion started by: BG_JrAdmin
3 Replies
Login or Register to Ask a Question