The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group

 NAME

fc - process the command history list

 SYNOPSIS



fc [-r][-e editor] [first[last]]

fc -l[-nr] [first[last]]

fc -s[old=new][first]

 DESCRIPTION

The fc utility lists or edits and reexecutes, commands previously entered to an interactive sh.

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 HISTSIZE 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, fc 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.

When commands are edited (when the -l option is not specified), the resulting lines will be entered at the end of the history list and then reexecuted by sh. The fc 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 fc will affect both the fc command itself as well as the command that results, for example:


fc -s -- -1 2>/dev/null

reinvokes the previous command, suppressing standard error for both fc and the previous command.

 OPTIONS

The fc utility supports the XBD specification, Utility Syntax Guidelines  .

The following options are supported:

-e editor
Use the editor named by editor to edit the commands. The editor string is a utility name, subject to search via the PATH variable (see the XBD specification, Environment Variables  ). The value in the FCEDIT variable is used as a default when -e is not specified. If FCEDIT is null or unset, ed will be used as the editor.
-l
(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 -r, with each command preceded by the command number.
-n
Suppress command numbers when listing with -l.
-r
Reverse the order of the commands listed (with -l) or edited (with neither -l nor -s).
-s
Reexecute the command without invoking an editor.

 OPERANDS

The following operands are supported:
first
last
Select 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 will be one of the following:
[+]number
A positive number representing a command number; command numbers can be displayed with the -l option.
-number
A negative decimal number representing the command that was executed number of commands previously. For example, -1 is the immediately previous command.
string
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.

When the synopsis form with -s is used:

  • If first is omitted, the previous command will be used.

For the synopsis forms without -s:

  • If last is omitted, last defaults to the previous command when -l is specified; otherwise, it defaults to first.

  • 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).

  • 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:
    
    fc -r 10 20    fc    30 40
    fc    20 10    fc -r 40 30
    
    

  • 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:
    
    fc -l
    fc 1 99
    
    
    will list and edit, respectively, all ten commands.

old=new
Replace the first occurrence of string old in the commands to be reexecuted by the string new.

 STDIN

Not used.

 INPUT FILES

None.

 ENVIRONMENT VARIABLES

The following environment variables affect the execution of fc:
FCEDIT
This variable, when expanded by the shell, determines the default value for the -e editor option's editor option-argument. If FCEDIT is null or unset, ed will be used as the editor.
HISTFILE
Determine a pathname naming a command history file. If the HISTFILE variable is not set, the shell may attempt to access or create a file .sh_history 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 fc or sh 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 ENV 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 HISTFILE and HISTSIZE . For example, function definition commands are recorded in the history file, unless the set -o nolog option is set. If the system administrator includes function definitions in some system startup file called before the ENV 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 ENV file has been processed. Therefore, it is implementation-dependent whether changes made to HISTFILE 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 HISTFILE ; 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.
HISTSIZE
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 HISTFILE . Therefore, it is unspecified whether changes made to HISTSIZE after the history file has been initialised are effective.
LANG
Provide a default value for the internationalisation variables that are unset or null. If LANG is unset or null, the corresponding value from the implementation-dependent default locale will be used. If any of the internationalisation variables contains an invalid setting, the utility will behave as if none of the variables had been defined.
LC_ALL
If set to a non-empty string value, override the values of all the other internationalisation variables.
LC_CTYPE
Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files).
LC_MESSAGES
Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
NLSPATH
Determine the location of message catalogues for the processing of LC_MESSAGES .

 ASYNCHRONOUS EVENTS

Default.

 STDOUT

When the -l option is used to list commands, the format of each command in the list is as follows:

"%d\t%s\n", <line number>, <command>

If both the -l and -n options are specified, the format of each command is:

"\t%s\n", <command>

If the <command> consists of more than one line, the lines after the first are displayed as:

"\t%s\n", <continued-command>

 STDERR

Used only for diagnostic messages.

 OUTPUT FILES

None.

 EXTENDED DESCRIPTION

None.

 EXIT STATUS

The following exit values are returned:
0
Successful completion of the listing.
>0
An error occurred.

Otherwise, the exit status will be that of the commands executed by fc.

 CONSEQUENCES OF ERRORS

Default.

 APPLICATION USAGE

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 command:

fc -s | more

will not work correctly on many systems.

Users on windowing systems may want to have separate history files for each window by setting HISTFILE as follows:


HISTFILE=$HOME/.sh_hist$$

 EXAMPLES

None.

 FUTURE DIRECTIONS

The IEEE PASC 1003.2 Interpretations Committee has forwarded concerns about parts of this interface definition to the IEEE PASC Shell and Utilities Working Group which is identifying the corrections. A future revision of this specification will align with IEEE Std. 1003.2b when finalised.

 SEE ALSO

sh.

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]