Processes the command history list.
fc [ -r ] [ -e Editor ] [ First [ Last ] ]
fc -l [ -n ] [ -r ] [ First [ Last ] ]
The fc command displays the contents of your command history file or invokes an editor to modify and reexecutes commands previously entered in the shell.
The command history file lists 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. In that case, the system resets the numbering to start the oldest retained command at 1.
If the numbers in the command history file reach a limit greater than the value of the HISTSIZE environment variable or 32767, whichever is greater, the shell wraps to 1. Despite this optional number wrapping, the fc command maintains the time-ordering sequence of the commands. For example, if three commands in sequence are given the numbers 32766, 32767, and 1 (wrapped), command 32767 is still considered previous to command 1.
The commands in the history file can be displayed using the -l (lowercase L) flag. When the -l flag is not specified and commands are edited using the -e Editor flag, the resulting lines are entered at the end of the history file and then reexecuted by the shell (the fc -e Editor command is not entered into the command history list). If the editor returns a non-zero exit status, this suppresses entry in the history file and command reexecution.
Any command-line variable assignments or redirection operators used with the fc command again invoke the previous command, suppressing standard error for both the fc command and the previous command. For example:
fc -s -- -1 2>/dev/null
When the -s flag is not specified, the following rules apply:
fc -r 10 20 fc 30 40 fc 20 10 fc -r 40 30
fc -l fc 1 99list and edit, respectively, all ten commands.
Old=New | In commands to be reexecuted, replaces the fist occurrence of the old string with the new string. |
The following environment variables affect the execution of the fc command:
FCEDIT | When expanded by the shell, determines the default value for the -e editor variable. If the FCEDIT environment variable is null or is not set, the ed editor is the default. |
HISTFILE | Determines the path name of the command history file. If the HISTFILE environment variable is not set, the shell may attempt to access or create the .sh_history file in the user's home directory. |
HISTSIZE | Determines a decimal number representing the limit to the number of previous commands that are accessible. If this variable is not set, a default value of128 is used. |
The following exit values are returned:
0 | Successful completion of the listing. |
>0 | An error occurred. |
Otherwise, the exit status is that of the commands executed by the fc command.
fcThe command is executed when you finish editing.
fc -l -2
fc -s foo=bar cc
/usr/bin/ksh | Contains the Korn shell fc built-in command. |
/usr/bin/fc | Contains the fc command. |
The ksh command.