fc - Processes the command history list
fc [-r] [-e editor] [first[last]]
fc -l [-nr] [first[last]]
fc [-s] [old=new] [first]
Interfaces documented on this reference page conform to industry standards as follows:
fc: XPG4, XPG4-UNIX
Refer to the
reference page for more information
about industry standards and associated tags.
Uses the editor named by
to edit the commands. The
string is a utility
name, subject to search via the
variable. The value in the
variable is used as a default when
is not specified. If
is null or unset,
is used as the editor.
Lists the commands rather than invoking an editor on them.
The commands are written in the sequence indicated by the
parameters, as affected
-r, with each command preceded by the command number.
Suppresses command numbers when listing with
Reverses the order of the commands listed (with
-l) or edited (with neither
Reexecutes the command without invoking an editor.
Selects the commands to list or edit. The number of previous commands that can be accessed is determined by the value of the HISTSIZE variable. The value of first or last or both is one of the following: A positive number representing a command number; command numbers can be displayed with the -l option. A negative decimal number representing the command that was executed number of commands previously. For example, -1 is the immediately previous command. A string indicating the most recently entered command that begins with that string. If the old=new operand is not also specified with -s, the string form of the first operand cannot contain an embedded equal sign.
The fc utility lists or edits and reexecutes commands previously entered to an interactive shell.
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 does 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 upper limit, either the value in HISTSIZE or 32767 (whichever is greater), the shell wraps the numbers, starting the next command with number 1. However, despite this optional wrapping of numbers, fc maintains 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.
When commands are edited (when the -l option is not specified), the resulting lines are entered at the end of the history list and then reexecuted by sh. The fc command that caused the editing is not entered into the history list. If the editor returns a non-zero exit status, this suppresses the entry into the history list and the command reexecution. Any command-line variable assignments or redirection operators used with fc affect both the fc command itself as well as the command that results. The following command reinvokes the previous command, suppressing standard error for both fc and the previous command: fc -s -- -1 2>/dev/null
Users on windowing systems may want to have separate history files for each window by setting HISTFILE to the following: HISTFILE=$HOME/.sh_hist$$
Since editors sometimes use file descriptors as integral parts of their editing, redirecting their file descriptors as part of the fc command can produce unexpected results. For example, if vi is the FCEDIT editor, the following command will not work correctly on many systems: fc -s | more
The following exit values are returned: Successful completion of the listing. An error occurred.
Otherwise, the exit status is that of the commands executed by
The following environment variables affect the execution of
This variable, when expanded by the shell, determines
the default value for the
option's editor option-argument. If
is null or unset,
is used as the editor.
Determines a path name naming a command history
file. If the
is not set, the shell attempts to access or create a file
in your home directory. If the shell cannot obtain both read and
write access to, or create, the history file, it uses a default mechanism
that allows the history to operate properly. Changes made to
after the history file has been initialized
are not effective. 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.
Determines a decimal number representing the
limit to the number of previous commands that are accessible. If this variable
is unset, a default of 128 is used. Changes made to
after the history file has been initialized are not
Provides a default value for the internationalization
variables that are unset or null. If
is unset or null, the corresponding value from the default locale is used.
If any of the internationalization variables contain an invalid setting, the
utility behaves as if none of the variables had been defined.
If set to a non-empty string value, overrides
the values of all the other internationalization variables.
Determines the locale for the interpretation
of sequences of bytes of text data as characters (for example, single-byte
as opposed to multibyte characters in arguments and input files).
Determines the locale used to affect the
format and contents of diagnostic messages written to standard error.
Determines the location of message catalogues
for the processing of