Files
oldlinux-files/Ref-docs/POSIX/susv3/utilities/fc.html
2024-02-19 00:21:47 -05:00

487 lines
19 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
<title>fc</title>
</head>
<body bgcolor="white">
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
</script>
<basefont size="3"> <a name="fc"></a> <a name="tag_04_52"></a><!-- fc -->
<!--header start-->
<center><font size="2">The Open Group Base Specifications Issue 6<br>
IEEE Std 1003.1-2001<br>
Copyright &copy; 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
<!--header end-->
<hr size="2" noshade>
<h4><a name="tag_04_52_01"></a>NAME</h4>
<blockquote>fc - process the command history list</blockquote>
<h4><a name="tag_04_52_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<div class="box"><code><tt><sup>[<a href="javascript:open_code('UP')">UP</a>]</sup> <img src="../images/opt-start.gif" alt=
"[Option Start]" border="0"> fc</tt> <b>[</b><tt>-r</tt><b>][</b><tt>-e</tt> <i>editor</i><b>]
[</b><i>first</i><b>[</b><i>last</i><b>]]</b><tt><br>
<br>
fc -l</tt><b>[</b><tt>-nr</tt><b>] [</b><i>first</i><b>[</b><i>last</i><b>]]</b><tt><br>
<br>
fc -s</tt><b>[</b><i>old</i><tt>=</tt><i>new</i><b>][</b><i>first</i><b>]</b><tt><img src="../images/opt-end.gif" alt=
"[Option End]" border="0"></tt></code></div>
<tt><br>
</tt></blockquote>
<h4><a name="tag_04_52_03"></a>DESCRIPTION</h4>
<blockquote>
<p>The <i>fc</i> utility shall list, or shall edit and re-execute, commands previously entered to an interactive <a href=
"../utilities/sh.html"><i>sh</i></a>.</p>
<p>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 <i>HISTSIZE</i> 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, <i>fc</i> 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.</p>
<p>When commands are edited (when the <b>-l</b> option is not specified), the resulting lines shall be entered at the end of the
history list and then re-executed by <a href="../utilities/sh.html"><i>sh</i></a>. The <i>fc</i> 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 <i>fc</i> shall
affect both the <i>fc</i> command itself as well as the command that results; for example:</p>
<pre>
<tt>fc -s -- -1 2&gt;/dev/null
</tt>
</pre>
<p>reinvokes the previous command, suppressing standard error for both <i>fc</i> and the previous command.</p>
</blockquote>
<h4><a name="tag_04_52_04"></a>OPTIONS</h4>
<blockquote>
<p>The <i>fc</i> utility shall conform to the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../basedefs/xbd_chap12.html#tag_12_02">Section 12.2, Utility Syntax Guidelines</a>.</p>
<p>The following options shall be supported:</p>
<dl compact>
<dt><b>-e&nbsp;</b> <i>editor</i></dt>
<dd>Use the editor named by <i>editor</i> to edit the commands. The <i>editor</i> string is a utility name, subject to search via
the <i>PATH</i> variable (see the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../basedefs/xbd_chap08.html">Chapter 8, Environment Variables</a>). The value in the <i>FCEDIT</i> variable shall be used as a
default when <b>-e</b> is not specified. If <i>FCEDIT</i> is null or unset, <a href="../utilities/ed.html"><i>ed</i></a> shall be
used as the editor.</dd>
<dt><b>-l</b></dt>
<dd>(The letter ell.) List the commands rather than invoking an editor on them. The commands shall be written in the sequence
indicated by the <i>first</i> and <i>last</i> operands, as affected by <b>-r</b>, with each command preceded by the command
number.</dd>
<dt><b>-n</b></dt>
<dd>Suppress command numbers when listing with <b>-l</b>.</dd>
<dt><b>-r</b></dt>
<dd>Reverse the order of the commands listed (with <b>-l</b>) or edited (with neither <b>-l</b> nor <b>-s</b>).</dd>
<dt><b>-s</b></dt>
<dd>Re-execute the command without invoking an editor.</dd>
</dl>
</blockquote>
<h4><a name="tag_04_52_05"></a>OPERANDS</h4>
<blockquote>
<p>The following operands shall be supported:</p>
<dl compact>
<dt><i>first</i>,&nbsp;<i>last</i></dt>
<dd>Select the commands to list or edit. The number of previous commands that can be accessed shall be determined by the value of
the <i>HISTSIZE</i> variable. The value of <i>first</i> or <i>last</i> or both shall be one of the following:
<dl compact>
<dt><b>[+]</b><i>number</i></dt>
<dd>A positive number representing a command number; command numbers can be displayed with the <b>-l</b> option.</dd>
<dt><b>-</b><i>number</i></dt>
<dd>A negative decimal number representing the command that was executed <i>number</i> of commands previously. For example, -1 is
the immediately previous command.</dd>
<dt><i>string</i></dt>
<dd>A string indicating the most recently entered command that begins with that string. If the <i>old</i>= <i>new</i> operand is
not also specified with <b>-s</b>, the string form of the <i>first</i> operand cannot contain an embedded equal sign.</dd>
</dl>
<p>When the synopsis form with <b>-s</b> is used:</p>
<ul>
<li>
<p>If <i>first</i> is omitted, the previous command shall be used.</p>
</li>
</ul>
<p>For the synopsis forms without <b>-s</b>:</p>
<ul>
<li>
<p>If <i>last</i> is omitted, <i>last</i> shall default to the previous command when <b>-l</b> is specified; otherwise, it shall
default to <i>first</i>.</p>
</li>
<li>
<p>If <i>first</i> and <i>last</i> are both omitted, the previous 16 commands shall be listed or the previous single command shall
be edited (based on the <b>-l</b> option).</p>
</li>
<li>
<p>If <i>first</i> and <i>last</i> are both present, all of the commands from <i>first</i> to <i>last</i> shall be edited (without
<b>-l</b>) or listed (with <b>-l</b>). 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 <i>first</i> represents a newer command than <i>last</i>, the
commands shall be listed or edited in reverse sequence, equivalent to using <b>-r</b>. For example, the following commands on the
first line are equivalent to the corresponding commands on the second:</p>
<pre>
<tt>fc -r 10 20 fc 30 40
fc 20 10 fc -r 40 30
</tt>
</pre>
</li>
<li>
<p>When a range of commands is used, it shall not be an error to specify <i>first</i> or <i>last</i> values that are not in the
history list; <i>fc</i> 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:</p>
<pre>
<tt>fc -l
fc 1 99
</tt>
</pre>
<p>shall list and edit, respectively, all ten commands.</p>
</li>
</ul>
</dd>
<dt><i>old</i>=<i>new</i></dt>
<dd>Replace the first occurrence of string <i>old</i> in the commands to be re-executed by the string <i>new</i>.</dd>
</dl>
</blockquote>
<h4><a name="tag_04_52_06"></a>STDIN</h4>
<blockquote>
<p>Not used.</p>
</blockquote>
<h4><a name="tag_04_52_07"></a>INPUT FILES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_52_08"></a>ENVIRONMENT VARIABLES</h4>
<blockquote>
<p>The following environment variables shall affect the execution of <i>fc</i>:</p>
<dl compact>
<dt><i>FCEDIT</i></dt>
<dd>This variable, when expanded by the shell, shall determine the default value for the <b>-e</b> <i>editor</i> option's
<i>editor</i> option-argument. If <i>FCEDIT</i> is null or unset, <a href="../utilities/ed.html"><i>ed</i></a> shall be used as the
editor.</dd>
<dt><i>HISTFILE</i></dt>
<dd>Determine a pathname naming a command history file. If the <i>HISTFILE</i> variable is not set, the shell may attempt to access
or create a file <b>.sh_history</b> in the directory referred to by the <i>HOME</i> environment 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 &quot;file&quot; 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 when <i>fc</i> or <a href="../utilities/sh.html"><i>sh</i></a> 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 <i>ENV</i> variable, or implementation-defined system
start-up files. In some historical shells, the history file is initialized just after the <i>ENV</i> file has been processed.
Therefore, it is implementation-defined whether changes made to <i>HISTFILE</i> after 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 set
<i>HISTFILE ;</i> 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.</dd>
<dt><i>HISTSIZE</i></dt>
<dd>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 shall be used. The maximum number of commands in the history list is
unspecified, but shall be at least 128. An implementation may choose to access this variable only when initializing the history
file, as described under <i>HISTFILE .</i> Therefore, it is unspecified whether changes made to <i>HISTSIZE</i> after the history
file has been initialized are effective.</dd>
<dt><i>LANG</i></dt>
<dd>Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of
IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/xbd_chap08.html#tag_08_02">Section 8.2, Internationalization Variables</a> for
the precedence of internationalization variables used to determine the values of locale categories.)</dd>
<dt><i>LC_ALL</i></dt>
<dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd>
<dt><i>LC_CTYPE</i></dt>
<dd>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).</dd>
<dt><i>LC_MESSAGES</i></dt>
<dd>Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard
error.</dd>
<dt><i>NLSPATH</i></dt>
<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
Determine the location of message catalogs for the processing of <i>LC_MESSAGES .</i> <img src="../images/opt-end.gif" alt=
"[Option End]" border="0"></dd>
</dl>
</blockquote>
<h4><a name="tag_04_52_09"></a>ASYNCHRONOUS EVENTS</h4>
<blockquote>
<p>Default.</p>
</blockquote>
<h4><a name="tag_04_52_10"></a>STDOUT</h4>
<blockquote>
<p>When the <b>-l</b> option is used to list commands, the format of each command in the list shall be as follows:</p>
<pre>
<tt>"%d\t%s\n", &lt;</tt><i>line number</i><tt>&gt;, &lt;</tt><i>command</i><tt>&gt;
</tt>
</pre>
<p>If both the <b>-l</b> and <b>-n</b> options are specified, the format of each command shall be:</p>
<pre>
<tt>"\t%s\n", &lt;</tt><i>command</i><tt>&gt;
</tt>
</pre>
<p>If the &lt;<i>command</i>&gt; consists of more than one line, the lines after the first shall be displayed as:</p>
<pre>
<tt>"\t%s\n", &lt;</tt><i>continued-command</i><tt>&gt;
</tt>
</pre>
</blockquote>
<h4><a name="tag_04_52_11"></a>STDERR</h4>
<blockquote>
<p>The standard error shall be used only for diagnostic messages.</p>
</blockquote>
<h4><a name="tag_04_52_12"></a>OUTPUT FILES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_52_13"></a>EXTENDED DESCRIPTION</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_52_14"></a>EXIT STATUS</h4>
<blockquote>
<p>The following exit values shall be returned:</p>
<dl compact>
<dt>&nbsp;0</dt>
<dd>Successful completion of the listing.</dd>
<dt>&gt;0</dt>
<dd>An error occurred.</dd>
</dl>
<p>Otherwise, the exit status shall be that of the commands executed by <i>fc</i>.</p>
</blockquote>
<h4><a name="tag_04_52_15"></a>CONSEQUENCES OF ERRORS</h4>
<blockquote>
<p>Default.</p>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_04_52_16"></a>APPLICATION USAGE</h4>
<blockquote>
<p>Since editors sometimes use file descriptors as integral parts of their editing, redirecting their file descriptors as part of
the <i>fc</i> command can produce unexpected results. For example, if <a href="../utilities/vi.html"><i>vi</i></a> is the
<i>FCEDIT</i> editor, the command:</p>
<pre>
<tt>fc -s | more
</tt>
</pre>
<p>does not work correctly on many systems.</p>
<p>Users on windowing systems may want to have separate history files for each window by setting <i>HISTFILE</i> as follows:</p>
<pre>
<tt>HISTFILE=$HOME/.sh_hist$$
</tt>
</pre>
</blockquote>
<h4><a name="tag_04_52_17"></a>EXAMPLES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_52_18"></a>RATIONALE</h4>
<blockquote>
<p>This utility is based on the <i>fc</i> built-in of the KornShell.</p>
<p>An early proposal specified the <b>-e</b> option as <b>[-e</b> <i>editor</i> <b>[</b> <i>old</i> = <i>new</i> <b>]]</b>, which
is not historical practice. Historical practice in <i>fc</i> of either <b>[-e</b> <i>editor</i> <b>]</b> or <b>[-e - [</b>
<i>old</i> = <i>new</i> <b>]]</b> is acceptable, but not both together. To clarify this, a new option <b>-s</b> was introduced
replacing the <b>[-e -]</b>. This resolves the conflict and makes <i>fc</i> conform to the Utility Syntax Guidelines.</p>
<dl compact>
<dt><i>HISTFILE</i></dt>
<dd>Some implementations of the KornShell check for the superuser and do not create a history file unless <i>HISTFILE</i> is set.
This is done primarily to avoid creating unlinked files in the root file system when logging in during single-user mode.
<i>HISTFILE</i> must be set for the superuser to have history.</dd>
<dt><i>HISTSIZE</i></dt>
<dd>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.</dd>
</dl>
<p>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 <i>HISTFILE</i> and <i>HISTSIZE .</i> 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 <i>ENV</i> 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 <i>ENV</i> file has been processed. Because of these situations,
the text requires the initialization process to be implementation-defined.</p>
<p>Consideration was given to omitting the <i>fc</i> utility in favor of the command line editing feature in <a href=
"../utilities/sh.html"><i>sh</i></a>. For example, in <a href="../utilities/vi.html"><i>vi</i></a> editing mode, typing
<tt>"&lt;ESC&gt; v"</tt> is equivalent to:</p>
<pre>
<tt>EDITOR=vi fc
</tt>
</pre>
<p>However, the <i>fc</i> utility allows the user the flexibility to edit multiple commands simultaneously (such as <i>fc</i> 10
20) and to use editors other than those supported by <a href="../utilities/sh.html"><i>sh</i></a> for command line editing.</p>
<p>In the KornShell, the alias <b>r</b> (``re-do&quot;) is preset to <i>fc</i> <b>-e -</b> (equivalent to the POSIX <i>fc</i>
<b>-s</b>). This is probably an easier command name to remember than <i>fc</i> (``fix command&quot;), but it does not meet the Utility
Syntax Guidelines. Renaming <i>fc</i> to <i>hist</i> or <i>redo</i> 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 <i>fc</i>, <a href="../utilities/awk.html"><i>awk</i></a>, <a href="../utilities/cat.html"><i>cat</i></a>,
<a href="../utilities/grep.html"><i>grep</i></a>, or <a href="../utilities/yacc.html"><i>yacc</i></a> are standardized by
POSIX.</p>
<p>Command numbers have no ordering effects; they are like serial numbers. The <b>-r</b> option and -<i>number</i> 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:</p>
<pre>
<tt>32766: echo 1
32767: echo 2
1: echo 3
</tt>
</pre>
<p>the number -2 refers to command 32767 because it is the second previous command, regardless of serial number.</p>
</blockquote>
<h4><a name="tag_04_52_19"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_52_20"></a>SEE ALSO</h4>
<blockquote>
<p><a href="sh.html"><i>sh</i></a></p>
</blockquote>
<h4><a name="tag_04_52_21"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 4.</p>
</blockquote>
<h4><a name="tag_04_52_22"></a>Issue 5</h4>
<blockquote>
<p>The FUTURE DIRECTIONS section is added.</p>
</blockquote>
<h4><a name="tag_04_52_23"></a>Issue 6</h4>
<blockquote>
<p>This utility is marked as part of the User Portability Utilities option.</p>
<p>In the ENVIRONMENT VARIABLES section, the text &quot;user's home directory&quot; is updated to &quot;directory referred to by the
<i>HOME</i> environment variable&quot;.</p>
</blockquote>
<div class="box"><em>End of informative text.</em></div>
<hr>
<hr size="2" noshade>
<center><font size="2"><!--footer start-->
UNIX &reg; is a registered Trademark of The Open Group.<br>
POSIX &reg; is a registered Trademark of The IEEE.<br>
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
]</font></center>
<!--footer end-->
<hr size="2" noshade>
</body>
</html>