Change the key that show previous command lines in ksh












3














In most shells on Linux, when you press the Up-arrow key, it shows the previous command lines from the command line history.



My question is, for the ksh shell,




  1. How do I set up some other key so that it shows previous command line?


  2. How do I disable the Up-arrow key so that it doesn't show the previous command line?











share|improve this question
























  • You might have to look at cat /etc/inputrc
    – Keyshov Borate
    Jul 8 '16 at 8:27












  • Many shells provide command line history with the aid of the readline library. To find which shell you are using, run echo $0 -- then edit your question to include the output.
    – JigglyNaga
    Jul 8 '16 at 8:43












  • OK, you're using the korn shell. See stackoverflow.com/questions/1623256/… .
    – JigglyNaga
    Jul 8 '16 at 9:35










  • ksh? That brings back memories! It used to be my favourite shell (or certainly I don't remember using any shell as much). Like say in the 1990s. That was mostly under SunOS/Solaris. I didn't know people still used ksh (even though I did look at it a few years ago out of curiosity).
    – Pryftan
    Jan 15 at 22:38
















3














In most shells on Linux, when you press the Up-arrow key, it shows the previous command lines from the command line history.



My question is, for the ksh shell,




  1. How do I set up some other key so that it shows previous command line?


  2. How do I disable the Up-arrow key so that it doesn't show the previous command line?











share|improve this question
























  • You might have to look at cat /etc/inputrc
    – Keyshov Borate
    Jul 8 '16 at 8:27












  • Many shells provide command line history with the aid of the readline library. To find which shell you are using, run echo $0 -- then edit your question to include the output.
    – JigglyNaga
    Jul 8 '16 at 8:43












  • OK, you're using the korn shell. See stackoverflow.com/questions/1623256/… .
    – JigglyNaga
    Jul 8 '16 at 9:35










  • ksh? That brings back memories! It used to be my favourite shell (or certainly I don't remember using any shell as much). Like say in the 1990s. That was mostly under SunOS/Solaris. I didn't know people still used ksh (even though I did look at it a few years ago out of curiosity).
    – Pryftan
    Jan 15 at 22:38














3












3








3


1





In most shells on Linux, when you press the Up-arrow key, it shows the previous command lines from the command line history.



My question is, for the ksh shell,




  1. How do I set up some other key so that it shows previous command line?


  2. How do I disable the Up-arrow key so that it doesn't show the previous command line?











share|improve this question















In most shells on Linux, when you press the Up-arrow key, it shows the previous command lines from the command line history.



My question is, for the ksh shell,




  1. How do I set up some other key so that it shows previous command line?


  2. How do I disable the Up-arrow key so that it doesn't show the previous command line?








keyboard-shortcuts ksh command-history






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 9 '16 at 10:07









Kusalananda

121k16229372




121k16229372










asked Jul 8 '16 at 8:22









user6507246

365




365












  • You might have to look at cat /etc/inputrc
    – Keyshov Borate
    Jul 8 '16 at 8:27












  • Many shells provide command line history with the aid of the readline library. To find which shell you are using, run echo $0 -- then edit your question to include the output.
    – JigglyNaga
    Jul 8 '16 at 8:43












  • OK, you're using the korn shell. See stackoverflow.com/questions/1623256/… .
    – JigglyNaga
    Jul 8 '16 at 9:35










  • ksh? That brings back memories! It used to be my favourite shell (or certainly I don't remember using any shell as much). Like say in the 1990s. That was mostly under SunOS/Solaris. I didn't know people still used ksh (even though I did look at it a few years ago out of curiosity).
    – Pryftan
    Jan 15 at 22:38


















  • You might have to look at cat /etc/inputrc
    – Keyshov Borate
    Jul 8 '16 at 8:27












  • Many shells provide command line history with the aid of the readline library. To find which shell you are using, run echo $0 -- then edit your question to include the output.
    – JigglyNaga
    Jul 8 '16 at 8:43












  • OK, you're using the korn shell. See stackoverflow.com/questions/1623256/… .
    – JigglyNaga
    Jul 8 '16 at 9:35










  • ksh? That brings back memories! It used to be my favourite shell (or certainly I don't remember using any shell as much). Like say in the 1990s. That was mostly under SunOS/Solaris. I didn't know people still used ksh (even though I did look at it a few years ago out of curiosity).
    – Pryftan
    Jan 15 at 22:38
















You might have to look at cat /etc/inputrc
– Keyshov Borate
Jul 8 '16 at 8:27






You might have to look at cat /etc/inputrc
– Keyshov Borate
Jul 8 '16 at 8:27














Many shells provide command line history with the aid of the readline library. To find which shell you are using, run echo $0 -- then edit your question to include the output.
– JigglyNaga
Jul 8 '16 at 8:43






Many shells provide command line history with the aid of the readline library. To find which shell you are using, run echo $0 -- then edit your question to include the output.
– JigglyNaga
Jul 8 '16 at 8:43














OK, you're using the korn shell. See stackoverflow.com/questions/1623256/… .
– JigglyNaga
Jul 8 '16 at 9:35




OK, you're using the korn shell. See stackoverflow.com/questions/1623256/… .
– JigglyNaga
Jul 8 '16 at 9:35












ksh? That brings back memories! It used to be my favourite shell (or certainly I don't remember using any shell as much). Like say in the 1990s. That was mostly under SunOS/Solaris. I didn't know people still used ksh (even though I did look at it a few years ago out of curiosity).
– Pryftan
Jan 15 at 22:38




ksh? That brings back memories! It used to be my favourite shell (or certainly I don't remember using any shell as much). Like say in the 1990s. That was mostly under SunOS/Solaris. I didn't know people still used ksh (even though I did look at it a few years ago out of curiosity).
– Pryftan
Jan 15 at 22:38










1 Answer
1






active

oldest

votes


















4














Most tutorials you can find are about bash. Ksh is very good at scripting but is bad at interactive use. Use zsh (best) or bash (second-best) as a command line if you can.



There are two main implementations of ksh today: the actual Korn shell ksh93, and the clone mksh (derived from the long-unmaintained pdksh). They have different key binding facilities.



In ksh93, the Up and Down keys don't move in the command line history by default. The default keys are Ctrl+P and Ctrl+N. You can change key bindings via the KEYBD trap; it's rather clumsy as you can only translate keys to other keys and all the bindings have to be defined in the same place. Here's how to make Up and Down navigate the history (this code goes into ~/.kshrc):



set -o emacs
function KEYBD_trap {
case ${.sh.edchar} in
$'e'[[O]A) .sh.edchar=$'e>';;
$'e'[[O]B) .sh.edchar=$'e<';;
esac
}
trap KEYBD_trap KEYBD


e[A and eOA, where e stands for the ASCII escape character, are the two escape sequences that the terminal may send when the user presses the Up key (it depends on the terminal and on its current mode). Likewise e[B and eOB is for Down. $'e is a notation you can use in ksh for the escape character; the pattern [[O] matches either a [ or a O.



In mksh, you define key bindings via the bind builtin. Up and Down navigate the history by default (in addition to kbd>Ctrl+P and Ctrl+N). The following code (to be put in ~/.mkshrc) disables the arrow keys:



bind '^[OA'=
bind '^[[A'=
bind '^[OB'=
bind '^[[B'=


^[ is a notation you can use in mskh key bindings for the escape character.



All this information is in the man page of the shell, not necessarily in a form that's comprehensible if you aren't familiar with Unix shells already.






share|improve this answer























  • (opinions) For interactive use, I find that shells, like bash and zsh, that tries too hard to second-guess my behaviour (and gets it wrong), or have too many bells-and-whistles, are more a hinderance than a help. ksh is brutally honest with me, like a good friend ;-)
    – Kusalananda
    Jul 9 '16 at 10:19











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f294592%2fchange-the-key-that-show-previous-command-lines-in-ksh%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














Most tutorials you can find are about bash. Ksh is very good at scripting but is bad at interactive use. Use zsh (best) or bash (second-best) as a command line if you can.



There are two main implementations of ksh today: the actual Korn shell ksh93, and the clone mksh (derived from the long-unmaintained pdksh). They have different key binding facilities.



In ksh93, the Up and Down keys don't move in the command line history by default. The default keys are Ctrl+P and Ctrl+N. You can change key bindings via the KEYBD trap; it's rather clumsy as you can only translate keys to other keys and all the bindings have to be defined in the same place. Here's how to make Up and Down navigate the history (this code goes into ~/.kshrc):



set -o emacs
function KEYBD_trap {
case ${.sh.edchar} in
$'e'[[O]A) .sh.edchar=$'e>';;
$'e'[[O]B) .sh.edchar=$'e<';;
esac
}
trap KEYBD_trap KEYBD


e[A and eOA, where e stands for the ASCII escape character, are the two escape sequences that the terminal may send when the user presses the Up key (it depends on the terminal and on its current mode). Likewise e[B and eOB is for Down. $'e is a notation you can use in ksh for the escape character; the pattern [[O] matches either a [ or a O.



In mksh, you define key bindings via the bind builtin. Up and Down navigate the history by default (in addition to kbd>Ctrl+P and Ctrl+N). The following code (to be put in ~/.mkshrc) disables the arrow keys:



bind '^[OA'=
bind '^[[A'=
bind '^[OB'=
bind '^[[B'=


^[ is a notation you can use in mskh key bindings for the escape character.



All this information is in the man page of the shell, not necessarily in a form that's comprehensible if you aren't familiar with Unix shells already.






share|improve this answer























  • (opinions) For interactive use, I find that shells, like bash and zsh, that tries too hard to second-guess my behaviour (and gets it wrong), or have too many bells-and-whistles, are more a hinderance than a help. ksh is brutally honest with me, like a good friend ;-)
    – Kusalananda
    Jul 9 '16 at 10:19
















4














Most tutorials you can find are about bash. Ksh is very good at scripting but is bad at interactive use. Use zsh (best) or bash (second-best) as a command line if you can.



There are two main implementations of ksh today: the actual Korn shell ksh93, and the clone mksh (derived from the long-unmaintained pdksh). They have different key binding facilities.



In ksh93, the Up and Down keys don't move in the command line history by default. The default keys are Ctrl+P and Ctrl+N. You can change key bindings via the KEYBD trap; it's rather clumsy as you can only translate keys to other keys and all the bindings have to be defined in the same place. Here's how to make Up and Down navigate the history (this code goes into ~/.kshrc):



set -o emacs
function KEYBD_trap {
case ${.sh.edchar} in
$'e'[[O]A) .sh.edchar=$'e>';;
$'e'[[O]B) .sh.edchar=$'e<';;
esac
}
trap KEYBD_trap KEYBD


e[A and eOA, where e stands for the ASCII escape character, are the two escape sequences that the terminal may send when the user presses the Up key (it depends on the terminal and on its current mode). Likewise e[B and eOB is for Down. $'e is a notation you can use in ksh for the escape character; the pattern [[O] matches either a [ or a O.



In mksh, you define key bindings via the bind builtin. Up and Down navigate the history by default (in addition to kbd>Ctrl+P and Ctrl+N). The following code (to be put in ~/.mkshrc) disables the arrow keys:



bind '^[OA'=
bind '^[[A'=
bind '^[OB'=
bind '^[[B'=


^[ is a notation you can use in mskh key bindings for the escape character.



All this information is in the man page of the shell, not necessarily in a form that's comprehensible if you aren't familiar with Unix shells already.






share|improve this answer























  • (opinions) For interactive use, I find that shells, like bash and zsh, that tries too hard to second-guess my behaviour (and gets it wrong), or have too many bells-and-whistles, are more a hinderance than a help. ksh is brutally honest with me, like a good friend ;-)
    – Kusalananda
    Jul 9 '16 at 10:19














4












4








4






Most tutorials you can find are about bash. Ksh is very good at scripting but is bad at interactive use. Use zsh (best) or bash (second-best) as a command line if you can.



There are two main implementations of ksh today: the actual Korn shell ksh93, and the clone mksh (derived from the long-unmaintained pdksh). They have different key binding facilities.



In ksh93, the Up and Down keys don't move in the command line history by default. The default keys are Ctrl+P and Ctrl+N. You can change key bindings via the KEYBD trap; it's rather clumsy as you can only translate keys to other keys and all the bindings have to be defined in the same place. Here's how to make Up and Down navigate the history (this code goes into ~/.kshrc):



set -o emacs
function KEYBD_trap {
case ${.sh.edchar} in
$'e'[[O]A) .sh.edchar=$'e>';;
$'e'[[O]B) .sh.edchar=$'e<';;
esac
}
trap KEYBD_trap KEYBD


e[A and eOA, where e stands for the ASCII escape character, are the two escape sequences that the terminal may send when the user presses the Up key (it depends on the terminal and on its current mode). Likewise e[B and eOB is for Down. $'e is a notation you can use in ksh for the escape character; the pattern [[O] matches either a [ or a O.



In mksh, you define key bindings via the bind builtin. Up and Down navigate the history by default (in addition to kbd>Ctrl+P and Ctrl+N). The following code (to be put in ~/.mkshrc) disables the arrow keys:



bind '^[OA'=
bind '^[[A'=
bind '^[OB'=
bind '^[[B'=


^[ is a notation you can use in mskh key bindings for the escape character.



All this information is in the man page of the shell, not necessarily in a form that's comprehensible if you aren't familiar with Unix shells already.






share|improve this answer














Most tutorials you can find are about bash. Ksh is very good at scripting but is bad at interactive use. Use zsh (best) or bash (second-best) as a command line if you can.



There are two main implementations of ksh today: the actual Korn shell ksh93, and the clone mksh (derived from the long-unmaintained pdksh). They have different key binding facilities.



In ksh93, the Up and Down keys don't move in the command line history by default. The default keys are Ctrl+P and Ctrl+N. You can change key bindings via the KEYBD trap; it's rather clumsy as you can only translate keys to other keys and all the bindings have to be defined in the same place. Here's how to make Up and Down navigate the history (this code goes into ~/.kshrc):



set -o emacs
function KEYBD_trap {
case ${.sh.edchar} in
$'e'[[O]A) .sh.edchar=$'e>';;
$'e'[[O]B) .sh.edchar=$'e<';;
esac
}
trap KEYBD_trap KEYBD


e[A and eOA, where e stands for the ASCII escape character, are the two escape sequences that the terminal may send when the user presses the Up key (it depends on the terminal and on its current mode). Likewise e[B and eOB is for Down. $'e is a notation you can use in ksh for the escape character; the pattern [[O] matches either a [ or a O.



In mksh, you define key bindings via the bind builtin. Up and Down navigate the history by default (in addition to kbd>Ctrl+P and Ctrl+N). The following code (to be put in ~/.mkshrc) disables the arrow keys:



bind '^[OA'=
bind '^[[A'=
bind '^[OB'=
bind '^[[B'=


^[ is a notation you can use in mskh key bindings for the escape character.



All this information is in the man page of the shell, not necessarily in a form that's comprehensible if you aren't familiar with Unix shells already.







share|improve this answer














share|improve this answer



share|improve this answer








edited 5 mins ago









Isaac

11.2k11648




11.2k11648










answered Jul 9 '16 at 0:43









Gilles

528k12810581583




528k12810581583












  • (opinions) For interactive use, I find that shells, like bash and zsh, that tries too hard to second-guess my behaviour (and gets it wrong), or have too many bells-and-whistles, are more a hinderance than a help. ksh is brutally honest with me, like a good friend ;-)
    – Kusalananda
    Jul 9 '16 at 10:19


















  • (opinions) For interactive use, I find that shells, like bash and zsh, that tries too hard to second-guess my behaviour (and gets it wrong), or have too many bells-and-whistles, are more a hinderance than a help. ksh is brutally honest with me, like a good friend ;-)
    – Kusalananda
    Jul 9 '16 at 10:19
















(opinions) For interactive use, I find that shells, like bash and zsh, that tries too hard to second-guess my behaviour (and gets it wrong), or have too many bells-and-whistles, are more a hinderance than a help. ksh is brutally honest with me, like a good friend ;-)
– Kusalananda
Jul 9 '16 at 10:19




(opinions) For interactive use, I find that shells, like bash and zsh, that tries too hard to second-guess my behaviour (and gets it wrong), or have too many bells-and-whistles, are more a hinderance than a help. ksh is brutally honest with me, like a good friend ;-)
– Kusalananda
Jul 9 '16 at 10:19


















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f294592%2fchange-the-key-that-show-previous-command-lines-in-ksh%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Accessing regular linux commands in Huawei's Dopra Linux

Can't connect RFCOMM socket: Host is down

Kernel panic - not syncing: Fatal Exception in Interrupt