254 lines
9.5 KiB
Groff
254 lines
9.5 KiB
Groff
'\"macro stdmacro
|
|
.if n .pH g1.fc @(#)fc 30.2 of 12/25/85
|
|
.nr X
|
|
.if \nX=0 .ds x} fc 1 "Essential Utilities" "\&"
|
|
.if \nX=1 .ds x} fc 1 "Essential Utilities"
|
|
.if \nX=2 .ds x} fc 1 "" "\&"
|
|
.if \nX=3 .ds x} fc "" "" "\&"
|
|
.ds OK [\|
|
|
.ds CK \|]
|
|
.TH \*(x}
|
|
.SH NAME
|
|
\f3fc\f1 - process the command history list
|
|
.SH SYNOPSIS
|
|
.nf
|
|
\f3fc [-r][-e editor] [first[last]]\f1
|
|
|
|
\f3fc -l[-nr] [first[last]]\f1
|
|
|
|
\f3fc -s[old=new][first]\f1
|
|
.fi
|
|
.SH DESCRIPTION
|
|
The \f3fc\f1 utility lists or edits and reexecutes, commands previously
|
|
entered to an interactive sh.
|
|
.PP
|
|
The command history list references commands by number. The first
|
|
number in the list is selected arbitrarily. The relationship of a
|
|
number to its command will not change except when the user logs in and
|
|
no other process is accessing the list, at which time the system may
|
|
reset the numbering to start the oldest retained command at another
|
|
number (usually 1). When the number reaches an implementation-dependent
|
|
upper limit, which will be no smaller than the value in \f3HISTSIZE\f1 or
|
|
32767 (whichever is greater), the shell may wrap the numbers, starting
|
|
the next command with a lower number (usually 1). However, despite this
|
|
optional wrapping of numbers, \f3fc\f1 will maintain the time-ordering
|
|
sequence of the commands. For example, if four commands in sequence are
|
|
given the numbers 32766, 32767, 1 (wrapped), and 2 as they are
|
|
executed, command 32767 is considered the command previous to 1, even
|
|
though its number is higher.
|
|
.PP
|
|
When commands are edited (when the \f3-l\f1 option is not specified), the
|
|
resulting lines will be entered at the end of the history list and then
|
|
reexecuted by sh. The \f3fc\f1 command that caused the editing will not be
|
|
entered into the history list. If the editor returns a non-zero exit
|
|
status, this will suppress the entry into the history list and the
|
|
command reexecution. Any command-line variable assignments or
|
|
redirection operators used with \f3fc\f1 will affect both the \f3fc\f1 command
|
|
itself as well as the command that results, for example:
|
|
.TP 4
|
|
\
|
|
fc -s -- -1 2>/dev/null
|
|
.PP
|
|
reinvokes the previous command, suppressing standard error for both \f3fc\f1
|
|
and the previous command.
|
|
.SH OPTIONS
|
|
The \f3fc\f1 utility supports the XBD specification, Utility Syntax
|
|
Guidelines.
|
|
.PP
|
|
The following options are supported:
|
|
.TP 12
|
|
\f3-e editor\f1
|
|
Use the editor named by editor to edit the commands. The editor string
|
|
is a utility name, subject to search via the \f3PATH\f1 variable.
|
|
The value in the \f3FCEDIT\f1
|
|
variable is used as a default when \f3-e\f1 is not specified. If \f3FCEDIT\f1 is
|
|
null or unset, \f3ed\f1 will be used as the editor.
|
|
.TP
|
|
\f3-l\f1
|
|
(The letter ell.) List the commands rather than invoking an editor on them. The commands
|
|
will be written in the sequence indicated by the first and last
|
|
operands, as affected by \f3-r\f1, with each command preceded by the command
|
|
number.
|
|
.TP
|
|
\f3-n\f1
|
|
Suppress command numbers when listing with \f3-l\f1.
|
|
.TP
|
|
\f3-r\f1
|
|
Reverse the order of the commands listed (with \f3-l\f1) or edited
|
|
(with neither \f3-l\f1 nor \f3-s\f1).
|
|
.TP
|
|
\f3-s\f1
|
|
Reexecute the command without invoking an editor.
|
|
.SH OPERANDS
|
|
The following operands are supported:
|
|
.TP 12
|
|
first
|
|
.TP
|
|
last
|
|
Select the commands to list or edit. The number of previous
|
|
commands that can be accessed is determined by the value of the
|
|
\f3HISTSIZE\f1 variable. The value of \f3first\f1 or \f3last\f1 or both will be one of
|
|
the following:
|
|
.RS
|
|
.TP 10
|
|
[+]number
|
|
A positive number representing a command number; command numbers can be
|
|
displayed with the \f3-l\f1 option.
|
|
.TP 10
|
|
-number
|
|
A negative decimal number representing the command that was executed
|
|
number of commands previously. For example, -1 is the immediately
|
|
previous command.
|
|
.TP 10
|
|
string
|
|
A string indicating the most recently entered command that begins
|
|
with that string. If the \f3old=new\f1 operand is not also specified with \f3-s\f1,
|
|
the string form of the first operand cannot contain an embedded equal
|
|
sign.
|
|
.RE
|
|
.TP 12
|
|
\
|
|
When the synopsis form with -s is used:
|
|
.TP 16
|
|
\
|
|
If first is omitted, the previous command will be used.
|
|
.TP 12
|
|
\
|
|
For the synopsis forms without -s:
|
|
.TP 16
|
|
\
|
|
If last is omitted, last defaults to the previous command when -l is
|
|
specified; otherwise, it defaults to first.
|
|
.TP 16
|
|
\
|
|
If first and last are both omitted, the previous 16 commands will be
|
|
listed or the previous single command will be edited (based on the -l
|
|
option).
|
|
.TP 16
|
|
\
|
|
If first and last are both present, all of the commands from first to
|
|
last will be edited (without -l) or listed (with -l). Editing multiple
|
|
commands will be accomplished by presenting to the editor all of the
|
|
commands at one time, each command starting on a new line. If first
|
|
represents a newer command than last, the commands will be listed or
|
|
edited in reverse sequence, equivalent to using -r. For example, the
|
|
following commands on the first line are equivalent to the
|
|
corresponding commands on the second:
|
|
.IP
|
|
.nf
|
|
fc -r 10 20 fc 30 40
|
|
fc 20 10 fc -r 40 30
|
|
.fi
|
|
.TP 16
|
|
\
|
|
When a range of commands is used, it will not be an error to specify
|
|
first or last values that are not in the history list; fc will
|
|
substitute the value representing the oldest or newest command in the
|
|
list, as appropriate. For example, if there are only ten commands in
|
|
the history list, numbered 1 to 10:
|
|
.IP
|
|
.nf
|
|
fc -l fc 1 99
|
|
.fi
|
|
.TP 16
|
|
\
|
|
will list and edit, respectively, all ten commands.
|
|
.TP 12
|
|
old=new
|
|
Replace the first occurrence of string old in the commands to be
|
|
reexecuted by the string new.
|
|
.SH ENVIRONMENT VARIABLES
|
|
The following environment variables affect the execution of fc:
|
|
.TP 12
|
|
\f3FCEDIT\f1
|
|
This variable, when expanded by the shell, determines the default value
|
|
for the \f3-e editor\f1 option's editor option-argument. If \f3FCEDIT\f1 is null or
|
|
unset, \f3ed\f1 will be used as the editor.
|
|
.TP
|
|
\f3HISTFILE\f1
|
|
Determine a pathname naming a command history file. If the \f3HISTFILE\f1
|
|
variable is not set, the shell may attempt to access or create a file \f3.sh_history\f1
|
|
in the user's home directory. If the shell cannot obtain
|
|
both read and write access to, or create, the history file, it will use
|
|
an unspecified mechanism that allows the history to operate properly.
|
|
(References to history "file" in this section are understood to mean
|
|
this unspecified mechanism in such cases.) An implementation may choose
|
|
to access this variable only when initialising the history file; this
|
|
initialisation will occur when \f3fc\f1 or \f3sh\f1 first attempt to retrieve
|
|
entries from, or add entries to, the file, as the result of commands
|
|
issued by the user, the file named by the \f3ENV\f1 variable, or
|
|
implementation-dependent system startup files. (The initialisation
|
|
process for the history file can be dependent on the system startup
|
|
files, in that they may contain commands that will effectively preempt
|
|
the user's settings of \f3HISTFILE\f1 and \f3HISTSIZE\f1. For example, function
|
|
definition commands are recorded in the history file, unless the \f3set -o\f1
|
|
\f3nolog\f1 option is set. If the system administrator includes function
|
|
definitions in some system startup file called before the \f3ENV\f1 file, the
|
|
history file will be initialised before the user gets a chance to
|
|
influence its characteristics.) In some historical shells, the history
|
|
file is initialised just after the \f3ENV\f1 file has been processed.
|
|
Therefore, it is implementation-dependent whether changes made to
|
|
\f3HISTFILE\f1 after the history file has been initialised are effective.
|
|
Implementations may choose to disable the history list mechanism for
|
|
users with appropriate privileges who do not set \f3HISTFILE\f ; the
|
|
specific circumstances under which this will occur are
|
|
implementation-dependent. If more than one instance of the shell is
|
|
using the same history file, it is unspecified how updates to the
|
|
history file from those shells interact. As entries are deleted from
|
|
the history file, they will be deleted oldest first. It is unspecified
|
|
when history file entries are physically removed from the history
|
|
file.
|
|
.TP
|
|
\f3HISTSIZE\f1
|
|
Determine a decimal number representing the limit to the number of
|
|
previous commands that are accessible. If this variable is unset, an
|
|
unspecified default greater than or equal to 128 will be used. The
|
|
maximum number of commands in the history list is unspecified, but will
|
|
be at least 128. An implementation may choose to access this variable
|
|
only when initialising the history file, as described under \f3HISTFILE\f.
|
|
Therefore, it is unspecified whether changes made to \f3HISTSIZE\f1 after the
|
|
history file has been initialised are effective.
|
|
.SH STDOUT
|
|
When the \f3-l\f1 option is used to list commands, the format of each command
|
|
in the list is as follows:
|
|
.IP
|
|
"%d\\t%s\\n", <line number>, <command>
|
|
.PP
|
|
If both the \f3-l\f1 and \f3-n\f1 options are specified, the format of each command
|
|
is:
|
|
.IP
|
|
"\\t%s\\n", <command>
|
|
.PP
|
|
If the <\f3command\f1> consists of more than one line, the lines after the
|
|
first are displayed as:
|
|
.IP
|
|
"\\t%s\\n", <continued-command>
|
|
.PP
|
|
.SH \f3EXIT STATUS\f1
|
|
The following exit values are returned:
|
|
.TP 4
|
|
0
|
|
Successful completion of the listing.
|
|
.TP 4
|
|
>0
|
|
An error occurred.
|
|
.PP
|
|
Otherwise, the exit status will be that of the commands executed by
|
|
\f3fc\f1.
|
|
.SH APPLICATION USAGE
|
|
Since editors sometimes use file descriptors as integral parts of their
|
|
editing, redirecting their file descriptors as part of the \f3fc\f1 command
|
|
can produce unexpected results. For example, if \f3vi\f1 is the \f3FCEDIT\f1
|
|
editor, the command:
|
|
.IP
|
|
fc -s | more
|
|
.PP
|
|
will not work correctly on many systems.
|
|
.PP
|
|
Users on windowing systems may want to have separate history files for
|
|
each window by setting HISTFILE as follows:
|
|
.IP
|
|
HISTFILE=$HOME/.sh_hist$$
|
|
.SH SEE ALSO
|
|
\f3sh(1).\f1
|