Question:
How do I repeat last command in Unix ksh?
jtbmax
2007-09-06 12:27:37 UTC
Been away from Unix for a long time. How do I make Unix repeat the last command entered. I'm using ksh
Four answers:
morgan
2007-09-06 21:51:21 UTC
I think the answer you're probably looking for is

simply to turn on "command line editing". This

essentially gives you a one-line "vi" or "emacs"

editor on the command line history.



To use "vi" mode, enter the command:



    set -o vi



You then need to hit the "escape" key whenever

you want to edit your history. To recall the

last command, just type "k" (which is "up" in

"vi"), which will display the last command. You

can move around with normal editing commands

like "$" (go to end of line), "fx" to find the

letter "x", or just hit the "return" key to

enter the command. By the way, instead of

using "k" to go back a single command, you can

use "/pattern" to search for the last command

which contained "pattern" (since "/" is the

search command).



In summary, to re-do the last command:



    1) hit the escape key to enter edit mode

    2) press the "k" key to go back one line

    3) press the "enter" key to execute the command





To use the "emacs" mode instead, enter the command



    set -o emacs



In this case, you can go up and down in the history

by using ^p ("control p" for previous line),

^n (next line), ^f (forward one character),

^b (backward one character).



So, to re-do the last command:



    1) "^p" (hold down "control" key and strike "p")

    2) press the "return" key to execute the command



All that being said, there is *another* history

mechanism in ksh that you might be asking about.

It is the "fc" command (see "man fc"). There's

usually an alias called "r" for a specific "fc"

command, which can be used to re-execute the

previous command:



    $ alias r

    r='fc -e -'



By typing "r" followed by the "return" key, you

will re-do the last command. Similarly, if you

type "r pattern" followed by the "return" key,

you will re-do the last command which contained

"pattern".



.
fries
2016-11-17 02:18:06 UTC
Unix Last Command
anonymous
2015-08-06 19:57:36 UTC
This Site Might Help You.



RE:

How do I repeat last command in Unix ksh?

Been away from Unix for a long time. How do I make Unix repeat the last command entered. I'm using ksh
?
2016-03-14 05:22:15 UTC
the up arrow key and to go to a command that you did a few commands ago just hit it again.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...