fc - process the command history list
fc [-r][-e editor]
[first[last]]
fc -l[-nr] [first[last]]
The fc utility shall list, or shall edit and re-execute, commands previously entered to an interactive sh.
The command history list shall reference commands by number. The first number in the list is selected arbitrarily. The relationship of a number to its command shall 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-defined upper limit, which shall 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 shall 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 shall be entered at the end of the history list and then re-executed by sh. The fc command that caused the editing shall not be entered into the history list. If the editor returns a non-zero exit status, this shall suppress the entry into the history list and the command re-execution. Any command line variable assignments or redirection operators used with fc shall 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.
The fc utility shall conform to the Base Definitions volume of IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines.
The following options shall be supported:
The following operands shall be supported:
When the synopsis form with -s is used:
If first is omitted, the previous command shall be used.
For the synopsis forms without -s:
If last is omitted, last shall default to the previous command when -l is specified; otherwise, it shall default to first.
If first and last are both omitted, the previous 16 commands shall be listed or the previous single command shall be edited (based on the -l option).
If first and last are both present, all of the commands from first to last shall be edited (without -l) or listed (with -l). Editing multiple commands shall 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 shall 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 shall not be an error to specify first or last values that are not in the history list; fc shall 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
shall list and edit, respectively, all ten commands.
The following environment variables shall affect the execution of fc:
When the -l option is used to list commands, the format of each command in the list shall be as follows:
"%d\t%s\n", <line number>, <command>
If both the -l and -n options are specified, the format of each command shall be:
"\t%s\n", <command>
If the <command> consists of more than one line, the lines after the first shall be displayed as:
"\t%s\n", <continued-command>
The standard error shall be used only for diagnostic messages.
The following exit values shall be returned:
Otherwise, the exit status shall be that of the commands executed by fc.
Default.
The following sections are informative.
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
does 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$$
This utility is based on the fc built-in of the KornShell.
An early proposal specified the -e option as [-e editor [ old = new ]], which is not historical practice. Historical practice in fc of either [-e editor ] or [-e - [ old = new ]] is acceptable, but not both together. To clarify this, a new option -s was introduced replacing the [-e -]. This resolves the conflict and makes fc conform to the Utility Syntax Guidelines.
The initialization process for the history file can be dependent on the system start-up files, in that they may contain commands that effectively preempt the settings the user has for HISTFILE and HISTSIZE . For example, function definition commands are recorded in the history file. If the system administrator includes function definitions in some system start-up file called before the ENV file, the history file is initialized before the user can influence its characteristics. In some historical shells, the history file is initialized just after the ENV file has been processed. Because of these situations, the text requires the initialization process to be implementation-defined.
Consideration was given to omitting the fc utility in favor of the command line editing feature in sh. For example, in vi editing mode, typing "<ESC> v" is equivalent to:
EDITOR=vi fc
However, the fc utility allows the user the flexibility to edit multiple commands simultaneously (such as fc 10 20) and to use editors other than those supported by sh for command line editing.
In the KornShell, the alias r (``re-do") is preset to fc -e - (equivalent to the POSIX fc -s). This is probably an easier command name to remember than fc (``fix command"), but it does not meet the Utility Syntax Guidelines. Renaming fc to hist or redo was considered, but since this description closely matches historical KornShell practice already, such a renaming was seen as gratuitous. Users are free to create aliases whenever odd historical names such as fc, awk, cat, grep, or yacc are standardized by POSIX.
Command numbers have no ordering effects; they are like serial numbers. The -r option and -number operand address the sequence of command execution, regardless of serial numbers. So, for example, if the command number wrapped back to 1 at some arbitrary point, there would be no ambiguity associated with traversing the wrap point. For example, if the command history were:
32766: echo 1 32767: echo 2 1: echo 3
the number -2 refers to command 32767 because it is the second previous command, regardless of serial number.
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |