Been away from Unix for a long time. How do I make Unix repeat the last command entered. I'm using ksh
How do I repeat last command in Unix ksh?
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".
.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment