fc(C)


fc -- process the command history list

Syntax

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

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

fc -s [ old=new ] [ command ]

Description

fc enables you to list, edit, and re-execute commands that you have previously entered into your shell. By default, the last 128 commands are kept in a history list file .sh_history in your home directory.

The default action of fc is to invoke an editor on the last command run. You may then edit this command; on exiting the editor, the shell runs the new command. You can also edit a contiguous range of previous commands, in the order they were originally run, or in reverse order.

Other options to fc allow you to list previous commands without editing or running them, or to run a specified command without editing it.

Commands in the history list may be referenced by their number in the list, a relative negative number, or the first few characters in the command.

The arguments first and last select the commands you wish to list or edit:

If a number falls outside those in the history list, fc uses the first command in the list for first or the last command for last.

fc takes the following options:


-e editor
Use editor to edit a list of commands. The environment variable FCEDIT specifies the default editor; if this is null or not set, ed(C) is invoked instead. first specified by itself invokes the editor on that command only. If no first and last commands are specified, only the previous command is edited. When you exit the editor, the shell invokes the edited list of commands.

-l
List the specified commands and their command numbers without editing or executing them. If no first and last commands are specified, fc displays the previous 16 commands.

-n
Do not display command numbers when using -l.

-r
Reverse the order of the commands listed with -l, or to be edited. This is equivalent to specifying values for first and last where the first command was run after the last command.

-s
Re-execute the previous command, or a specified command without editing it. Specifying old=new replaces the first occurrence of an old string in the command with a new string.

Environment variables


FCEDIT
The default editor to use with fc. If null or not set, and the -e option is not used, fc uses ed.

HISTFILE
The pathname to be used for the history list file. If not set, the file $HOME/.sh_history is used.

HISTSIZE
The number of previous commands that are accessible in the history list file. If not set, fc uses a default value of 128.

Exit values

fc normally returns the exit status of the commands it executes; it may also return the following values:

0
successful listing using the -l option

>0
an error occurred in fc

Examples

Set up an independent history list file for a shell:
   HISTFILE=$HOME/.sh_hist$$
Invoke the vi(C) editor on the last 10 commands:

fc -e vi -10 -1

Repeat the previous example, but reverse the order of the commands:

fc -e vi -1 -10

The following command is equivalent to the previous one:

fc -r -e vi -10 -1

Create an alias to re-execute the last command entered:

   alias r="fc -s"
Run ls(C), and then re-execute it with added options:

ls
fc -s -- -FC

Limitations

The command history substitution mechanism described here is built into ksh(C).

The command history substitution mechanism built into csh(C) differs substantially from that described here.

An fc command that causes editing or re-execution is not entered into the history list itself; the commands that it runs are put in the list.

If the editor returns a non-zero exit status, fc does not run the commands, and they are not entered into the history list.

Variable assignments and redirection on the command line act on both fc and any commands it executes (including the command editor). As a consequence, redirection of the standard output or input of fc may not work as expected.

Files


$HOME/.sh_history
default pathname of a user's command history file

See also

csh(C), ksh(C)

Standards conformance

fc is conformant with:

ISO/IEC DIS 9945-2:1992, Information technology - Portable Operating System Interface (POSIX) - Part 2: Shell and Utilities (IEEE Std 1003.2-1992);
X/Open CAE Specification, Commands and Utilities, Issue 4, 1992.


© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 03 June 2005