If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Hot key in Korn shell?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-19-06, 15:39
mburke mburke is offline
Registered User
 
Join Date: Aug 2006
Posts: 56
Hot key in Korn shell?

I want to be able to use the arrow keys (up and down) to cycle through the commands I have already executed. Is this possile? I can do it on a DOS prompt.
Reply With Quote
  #2 (permalink)  
Old 09-20-06, 02:53
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
I prefer
set -o vi
this allow me to use vi to edit the commands I type
just hit escape and use normal vi commands to edit the line
and
<esc-k><k><k><k> to scroll back thru previous 3 commands
<esc-j><j><j> to scroll forward 2 commands

But to answer your question
Code:
#!/bin/ksh
# file: enable-arrows
# source in current environment with
# command:
#       . enable-arrows
#

set -o emacs

# Note: these are the actual control
# characters. In vi, type ctrl-v
# then ctrl-P (if u want a ctrl-p)
alias _A=^P
alias _B=^N
alias _D=^B
alias _C=^F

alias __A=^P
alias __B=^N
alias __D=^B
alias __C=^F
Reply With Quote
  #3 (permalink)  
Old 09-20-06, 10:31
mburke mburke is offline
Registered User
 
Join Date: Aug 2006
Posts: 56
Ok, I copied the script and executed it. But I am not sure how to use it (I don't use Unix often)
Reply With Quote
  #4 (permalink)  
Old 09-20-06, 16:23
Tyveleyn Tyveleyn is offline
Registered User
 
Join Date: Aug 2006
Location: The Netherlands
Posts: 248
Writing the lines in your .profile, or importing the script into the .profile with the line:
Code:
. path/enable-arrows
makes the functionality always available...

BTW. Your requested behaviour is standard for the bash-shell in many (if not all) Linux distributions. I don't miss anything I had in ksh, so if it's available on your system...

Last edited by Tyveleyn; 09-20-06 at 16:35.
Reply With Quote
  #5 (permalink)  
Old 09-21-06, 10:26
mburke mburke is offline
Registered User
 
Join Date: Aug 2006
Posts: 56
It's a development account, so I cannot touch the .profile. I just don't know which keys are used for navigation once I execute the script.
Reply With Quote
  #6 (permalink)  
Old 09-21-06, 17:38
Tyveleyn Tyveleyn is offline
Registered User
 
Join Date: Aug 2006
Location: The Netherlands
Posts: 248
Quote:
I just don't know which keys are used for navigation once I execute the script.
what do you mean by that? If the script doesn't make the cursor keys function like you wanted then probably you didn't enter the control characters the right way. Do it as pdreyer described:
Quote:
In vi, first type ctrl-v, then ctrl-P (if u want a ^P)
Be sure the script is executable and make it's code effective in your current shell with
Code:
. enable-arrows
on the prompt. Works fine in my ksh under AIX.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On