redit and re-execute previous command |
KornShell Built-in |
r
[old=new] [specifier]
r
command (a built-in KornShell alias) re-executes a
command you ran previously, possibly editing it first. Commands are obtained
from your command history file; see
fc
and
sh
for more details.
The specifier tells which command you want to re-execute.
It can have any of the following forms:
r
run the command with that number.
r
runs the command that came n commands
before the current one.
r
runs the most recent command beginning with
x.
r
runs the most recent
command.
The old=
new feature lets you edit a command before
running it. old and new must be character strings.
r
replaces the first occurrence of old in the
command arguments with new and then re-executes the command.
runs the most recently executed command beginning with the charactersr cp
cp
. The cp
could be the whole command name or it could
be part of a longer command name (for example,
cpio
).
This is equivalent tocp file1 /dir r 1=2 r 2=3
Compare this withcp file1 /dir cp file2 /dir cp file3 /dir
which is equivalent tocp file1 /dir/file1 r 1=2
Sincecp file1 /dir/file1 cp file2 /dir/file1
r
only replaces the first occurrence of the
old string 1
, the second 1
does not change.
This shows that you have to be careful when you use the substitution feature.
r
is a built-in MKS KornShell alias, defined with
alias r='fc -s'
HISTFILE
contains the path name of the history file.
HISTSIZE
gives the maximum number of previous commands that are accessible.
0
Successful completion.
1
Failure due to any of the following:
2
Failure due to an invalid command line option or argument.