FC(1P)
๐ธ PROLOG ๐ธ
okay so before we even get into it โ this manual page, fc(1P), is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so go check the corresponding Linux manual page for the details on Linux behavior, bestie), or the interface may not be implemented on Linux at all. Not me being dramatic, that's just the tea. โ
โจ NAME โจ
fc โ process the command history list ๐
๐ฆ SYNOPSIS ๐ฆ
the vibe check: here's how you call her โจ
fc [-r] [-e editor] [first [last]]
fc -l [-nr] [first [last]]
fc -s [old=new] [first]
๐ DESCRIPTION ๐
Okay so fc does one of two things: it either lists commands you previously entered to an interactive sh, or it edits and re-executes them. Iconic behavior, honestly.
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 shall not change โ except when the user logs in and no other process is accessing the list. At that time, the system may reset the numbering to start the oldest retained command at another number (usually 1). No cap.
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). But 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. The math is mathing, bestie. ๐งฎ
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. Obsessed with the efficiency. โจ
๐ OPTIONS ๐
The fc utility shall conform to the Base Definitions volume of POSIX.1โ2017, Section 12.2, Utility Syntax Guidelines. The following options shall be supported:
-e editorโ Use the editor named by editor to edit the commands. The editor string is a utility name, subject to search via thePATHvariable (see the Base Definitions volume of POSIX.1โ2017, Chapter 8, Environment Variables). The value in theFCEDITvariable shall be used as a default when-eis not specified. IfFCEDITis null or unset,edshall be used as the editor.-lโ (The letter ell.) List the commands rather than invoking an editor on them. The commands shall be written in the sequence indicated by thefirstandlastoperands, 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-lnor-s).-sโ Re-execute the command without invoking an editor.
๐ OPERANDS ๐
The following operands shall be supported:
first,lastโ Select the commands to list or edit. The number of previous commands that can be accessed shall be determined by the value of theHISTSIZEvariable. The value offirstorlastor both shall be one of the following:[+]numberโ A positive number representing a command number; command numbers can be displayed with the-loption.-numberโ A negative decimal number representing the command that was executed number of commands previously. For example,-1is the immediately previous command.stringโ A string indicating the most recently entered command that begins with that string. If theold=newoperand is not also specified with-s, the string form of thefirstoperand cannot contain an embedded<equals-sign>.- When the synopsis form with
-sis used:- If
firstis omitted, the previous command shall be used.
- If
- For the synopsis forms without
-s:- If
lastis omitted,lastshall default to the previous command when-lis specified; otherwise, it shall default tofirst. - If
firstandlastare both omitted, the previous 16 commands shall be listed or the previous single command shall be edited (based on the-loption). - If
firstandlastare both present, all of the commands fromfirsttolastshall 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. Iffirstrepresents a newer command thanlast, 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:
- If
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
firstorlastvalues that are not in the history list;fcshall 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, numbered1to10:
fc -l fc 1 99
shall list and edit, respectively, all ten commands.
old=newโ Replace the first occurrence of stringoldin the commands to be re-executed by the stringnew.
๐ STDIN ๐
Not used. She's not reading from stdin, bestie. ๐
๐ฆ INPUT FILES ๐ฆ
None. Zero. Nada. ๐ฆ
๐ง ENVIRONMENT VARIABLES ๐ง
The following environment variables shall affect the execution of fc:
FCEDITโ This variable, when expanded by the shell, shall determine the default value for the-e editoroption's editor option-argument. IfFCEDITis null or unset,edshall be used as the editor.HISTFILEโ Determine a pathname naming a command history file. If theHISTFILEvariable is not set, the shell may attempt to access or create a file.sh_historyin the directory referred to by theHOMEenvironment variable. If the shell cannot obtain both read and write access to, or create, the history file, it shall use an unspecified mechanism that allows the history to operate properly. (References to history โfileโ in this section shall be understood to mean this unspecified mechanism in such cases.) An implementation may choose to access this variable only when initializing the history file; this initialization shall occur whenfcorshfirst attempt to retrieve entries from, or add entries to, the file, as the result of commands issued by the user, the file named by theENVvariable, or implementation-defined system start-up files. In some historical shells, the history file is initialized just after theENVfile has been processed. Therefore, it is implementation-defined whether changes made toHISTFILEafter the history file has been initialized are effective. Implementations may choose to disable the history list mechanism for users with appropriate privileges who do not setHISTFILE; the specific circumstances under which this occurs are implementation-defined. 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 shall 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 to128shall be used. The maximum number of commands in the history list is unspecified, but shall be at least128. An implementation may choose to access this variable only when initializing the history file, as described underHISTFILE. Therefore, it is unspecified whether changes made toHISTSIZEafter the history file has been initialized are effective.LANGโ Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of POSIX.1โ2017, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.)LC_ALLโ If set to a non-empty string value, override the values of all the other internationalization variables.LC_CTYPEโ Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte 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 catalogs for the processing ofLC_MESSAGES.
๐ ASYNCHRONOUS EVENTS ๐
Default. Nothing extra, bestie. ๐
โญ STDOUT โญ
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>
๐ธ STDERR ๐ธ
The standard error shall be used only for diagnostic messages.
๐ OUTPUT FILES ๐
None.
โจ EXTENDED DESCRIPTION โจ
None.
๐ฅ EXIT STATUS ๐ฅ
okay so when you run fc, here's the tea on what it returns:
0โ successful completion of the listing. slay. ๐>0โ an error occurred. not slay. ๐ญ
Otherwise? The exit status shall be that of the commands executed by fc. So if the command you pulled up and ran goes off, fc is just matching its energy, periodt. ๐ฅ
๐ CONSEQUENCES OF ERRORS ๐
Default.
The following sections are informative.
๐ ๏ธ APPLICATION USAGE ๐ ๏ธ
Bestie, real talk: editors sometimes use file descriptors as integral parts of their editing. So if you redirect their file descriptors as part of the fc command, you can get unexpected results. Like, no cap. For example, if vi is the FCEDIT editor, this command:
fc -s | more
does not work correctly on many systems. It's giving chaos. ๐
Users on windowing systems may want to have separate history files for each window by setting HISTFILE like this:
HISTFILE=$HOME/.sh_hist$$
cute, organized, per-window vibes. ๐ชโจ
๐ญ EXAMPLES ๐ญ
None. Zero. Zilch. Not a single example, bestie. ๐
๐ง RATIONALE ๐ง
This utility is based on the fc built-in of the KornShell. iconic behavior, honestly. ๐
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. periodt. ๐
HISTFILE โ Some implementations of the KornShell check for the superuser and do not create a history file unless HISTFILE is set. This is done primarily to avoid creating unlinked files in the root file system when logging in during single-user mode. HISTFILE must be set for the superuser to have history. so if you're root and you want receipts, set it. ๐
HISTSIZE โ Needed to limit the size of history files. It is the intent of the standard developers that when two shells share the same history file, commands that are entered in one shell shall be accessible by the other shell. Because of the difficulties of synchronization over a network, the exact nature of the interaction is unspecified. so like, shared history is the dream, but the exact mechanics are a mystery. ๐ฆ
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. translation: it's complicated, and the standard said "you know what, that's on the implementation." ๐ญ
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. so fc said "I'm not like other girls," and stayed. ๐
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. so yes, you can make your own aliases, bestie. go off. ๐
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. numbers are just vibes, not order. ๐ขโจ
๐ฎ FUTURE DIRECTIONS ๐ฎ
None. The future is now, and it's empty. ๐
๐ SEE ALSO ๐
sh- The Base Definitions volume of
POSIX.1โ2017, Chapter 8, Environment Variables, Section 12.2, Utility Syntax Guidelines
๐ COPYRIGHT ๐
okay legal bestie moment, here's the official fine print, no cap:
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
kisses bestie, this page is brought to you by IEEE/The Open Group, version/date 2017, and it's the FC(1P) page. mwah ๐โจ
๐ฆ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 ยท custom
- alpine 3.23: man-pages-posix 2017a-r0 ยท custom
- alpine 3.24: man-pages-posix 2017a-r0 ยท custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 ยท SUSE-IEEE
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms