📄 fc.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>fc</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_001_014_662"> </a>NAME</h4><blockquote>fc - process the command history list</blockquote><h4><a name = "tag_001_014_663"> </a>SYNOPSIS</h4><blockquote><pre><code>fc <b>[</b>-r<b>][</b>-e <i>editor</i><b>] [</b><i>first</i><b>[</b><i>last</i><b>]]</b>fc -l<b>[</b>-nr<b>] [</b><i>first</i><b>[</b><i>last</i><b>]]</b>fc -s<b>[</b><i>old</i>=<i>new</i><b>][</b><i>first</i><b>]</b></code></pre></blockquote><h4><a name = "tag_001_014_664"> </a>DESCRIPTION</h4><blockquote>The<i>fc</i>utility lists or edits and reexecutes,commands previously entered to an interactive<i><a href="sh.html">sh</a></i>.<p>The command history list references commands by number.The first number in the list is selected arbitrarily.The relationship of a number to its commandwill not change except whenthe user logs in and noother process is accessing the list, at which time thesystem may reset the numbering to startthe oldest retained command at another number (usually 1).When the number reaches an implementation-dependent upper limit,which will be no smaller than the value in<i>HISTSIZE</i>or 32767 (whichever is greater),the shell may wrap the numbers, starting thenext command with a lower number (usually 1).However, despite this optional wrapping of numbers,<i>fc</i>will maintain the time-ordering sequence of the commands.For example, if four commands in sequence are given the numbers32766, 32767, 1 (wrapped),and 2 as they are executed, command 32767is considered the command previous to 1,even though its number is higher.<p>When commands are edited (when the<b>-l</b>option is not specified), the resulting lines will beentered at the end of the history list and then reexecuted by<i><a href="sh.html">sh</a></i>.The<i>fc</i>command that caused the editing will not be entered into the history list.If the editor returns a non-zero exit status,this will suppress the entry into the history listand the command reexecution.Any command-line variable assignments or redirection operatorsused with<i>fc</i>will affect both the<i>fc</i>command itself as well as the command that results, for example:<pre><code>fc -s -- -1 2>/dev/null</code></pre>reinvokes the previous command, suppressing standard errorfor both<i>fc</i>and the previous command.</blockquote><h4><a name = "tag_001_014_665"> </a>OPTIONS</h4><blockquote>The<i>fc</i>utility supports the <b>XBD</b> specification, <a href="../xbd/utilconv.html#usg"><b>Utility Syntax Guidelines</b> </a> .<p>The following options are supported:<dl compact><dt><b>-e </b><i>editor</i><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 (seethe <b>XBD</b> specification, <a href="../xbd/envvar.html"><b>Environment Variables</b> </a> ).The value in the<i>FCEDIT</i>variable is used as a default when<b>-e</b>is not specified.If<i>FCEDIT</i>is null or unset,<i><a href="ed.html">ed</a></i>will be used as the editor.<dt><b>-l</b><dd>(The letter ell.)List the commands rather than invoking an editor on them.The commands will be writtenin 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.<dt><b>-n</b><dd>Suppress command numbers when listing with<b>-l</b>.<dt><b>-r</b><dd>Reverse the order of the commands listed (with<b>-l</b>)or edited (with neither<b>-l</b>nor<b>-s</b>).<dt><b>-s</b><dd>Reexecute the command without invoking an editor.</dl></blockquote><h4><a name = "tag_001_014_666"> </a>OPERANDS</h4><blockquote>The following operands are supported:<dl compact><dt><i>first</i><dd><dt><i>last</i><dd>Select the commands to list or edit.The number of previous commands that can be accessedis determined by the value of the<i>HISTSIZE</i>variable.The value of<i>first</i>or<i>last</i>or both will be one of the following:<dl compact><dt><b>[+]</b><i>number</i><dd>A positive number representing a command number;command numbers can be displayed with the<b>-l</b>option.<dt><b>-</b><i>number</i><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.<dt><i>string</i><dd>A string indicating the most recently entered commandthat begins with that string.If the<i>old=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.</dl><p>When the synopsis form with<b>-s</b>is used:<ul><p><li>If<i>first</i>is omitted, the previous command will be used.<p></ul><p>For the synopsis forms without<b>-s</b>:<ul><p><li>If<i>last</i>is omitted,<i>last</i>defaults tothe previous command when<b>-l</b>is specified; otherwise, it defaults to<i>first</i>.<p><li>If<i>first</i>and<i>last</i>are both omitted, the previous 16 commands will be listedor the previous single command will be edited (based on the<b>-l</b>option).<p><li>If<i>first</i>and<i>last</i>are both present,all of the commands from<i>first</i>to<i>last</i>will be edited (without<b>-l</b>)or listed (with<b>-l</b>).Editing multiple commands will be accomplishedby 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 will be listed or editedin reverse sequence, equivalent to using<b>-r</b>.For example, the following commandson the first line are equivalentto the corresponding commands on the second:<pre><code>fc -r 10 20 fc 30 40fc 20 10 fc -r 40 30</code></pre><p><li>When a range of commands is used, it will not be anerror to specify<i>first</i>or<i>last</i>values that are not in the history list;<i>fc</i>will substitute the value representing theoldest or newest command in the list, as appropriate.For example, if there are only ten commands in the history list,numbered 1 to 10:<pre><code>fc -lfc 1 99</code></pre>will list and edit, respectively, all ten commands.<p></ul><p><dt><i>old=new</i><dd>Replace the first occurrence of string<i>old</i>in the commands to bereexecuted by the string<i>new</i>.<p></dl></blockquote><h4><a name = "tag_001_014_667"> </a>STDIN</h4><blockquote>Not used.</blockquote><h4><a name = "tag_001_014_668"> </a>INPUT FILES</h4><blockquote>None.</blockquote><h4><a name = "tag_001_014_669"> </a>ENVIRONMENT VARIABLES</h4><blockquote>The following environment variables affect the execution of<i>fc</i>:<dl compact><dt><i>FCEDIT</i><dd>This variable, when expanded by the shell,determines 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,<i><a href="ed.html">ed</a></i>will be used as the editor.<dt><i>HISTFILE</i><dd>Determine a pathname naming a command history file.If the<i>HISTFILE</i>variable is not set, theshell may attempt to access or create a file<b>.sh_history</b>in the user's home directory.If the shell cannotobtain both read and write access to,or create, the history file,it will use an unspecified mechanism that allows the historyto operate properly.(References to history "file" in this sectionare understood to mean this unspecified mechanismin such cases.)An implementation may choose to access this variable only wheninitialising the history file;this initialisation will occur when<i>fc</i>or<i><a href="sh.html">sh</a></i>first attempt to retrieve entries from,or add entries to, the file, as the result ofcommands issued by the user, the file named by the<i>ENV</i>variable, or implementation-dependent system startup files.(The initialisation process for the history filecan be dependent on the system startup files, in thatthey may contain commands that will effectivelypreempt the user's settings of<i>HISTFILE</i>and<i>HISTSIZE .</i>For example, function definition commands are recordedin the history file, unless the<i>set</i><b>-o</b><b>nolog</b>option is set.If the system administrator includes function definitionsin some system startup file called before the<i>ENV</i>file, the history file will be initialised beforethe user gets a chance to influence its characteristics.)In some historical shells, the history file is initialisedjust after the<i>ENV</i>file has been processed.Therefore, it is implementation-dependent whether changes made to<i>HISTFILE</i>after the history file has been initialised are effective.Implementations may choose to disable the history listmechanism for users with appropriate privileges who do not set<i>HISTFILE ;</i>the specific circumstances under which this will occur areimplementation-dependent.If more than one instance of the shell is using the same historyfile, it is unspecified how updates to the history file fromthose shells interact.As entries are deleted from the history file,they will be deleted oldest first.It is unspecified when history file entries arephysically removed from the history file.<dt><i>HISTSIZE</i><dd>Determine a decimal number representingthe limit to the number of previous commands that are accessible.If this variable is unset,an unspecified default greater than or equal to 128 will be used.The maximum number of commands in the history list is unspecified,but will be at least 128.An implementation may choose to access this variable only wheninitialising 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 initialised are effective.<dt><i>LANG</i><dd>Provide a default value for the internationalisation variablesthat are unset or null.If<i>LANG</i>is unset or null, the corresponding value from theimplementation-dependent default locale will be used.If any of the internationalisation variables contains an invalid setting, theutility will behave as if none of the variables had been defined.<dt><i>LC_ALL</i><dd>If set to a non-empty string value,override the values of all the other internationalisation variables.<dt><i>LC_CTYPE</i><dd>Determine thelocale for the interpretation of sequences of bytes of text data ascharacters (for example, single- as opposed to multi-byte charactersin arguments and input files).<dt><i>LC_MESSAGES</i><dd>Determine the locale that should be used to affectthe format and contents of diagnosticmessages written to standard error.<dt><i>NLSPATH</i><dd>Determine the location of message cataloguesfor the processing of<i>LC_MESSAGES .</i></dl></blockquote><h4><a name = "tag_001_014_670"> </a>ASYNCHRONOUS EVENTS</h4><blockquote>Default.</blockquote><h4><a name = "tag_001_014_671"> </a>STDOUT</h4><blockquote>When the<b>-l</b>option is used to list commands, the format of each command inthe list is as follows:<p><code><tt>"%d\t%s\n"</tt>, <<i>line number</i>>,<<i>command</i>></code><p>If both the<b>-l</b>and<b>-n</b>options are specified, the format of each command is:<p><code><tt>"\t%s\n"</tt>, <<i>command</i>></code><p>If the<<i>command</i>>consists of more than one line, the lines after the first aredisplayed as:<p><code><tt>"\t%s\n"</tt>, <<i>continued-command</i>></code></blockquote><h4><a name = "tag_001_014_672"> </a>STDERR</h4><blockquote>Used only for diagnostic messages.</blockquote><h4><a name = "tag_001_014_673"> </a>OUTPUT FILES</h4><blockquote>None.</blockquote><h4><a name = "tag_001_014_674"> </a>EXTENDED DESCRIPTION</h4><blockquote>None.</blockquote><h4><a name = "tag_001_014_675"> </a>EXIT STATUS</h4><blockquote>The following exit values are returned:<dl compact><dt>0<dd>Successful completion of the listing.<dt>>0<dd>An error occurred.</dl><p>Otherwise, the exit status will be that of the commands executed by<i>fc</i>.</blockquote><h4><a name = "tag_001_014_676"> </a>CONSEQUENCES OF ERRORS</h4><blockquote>Default.</blockquote><h4><a name = "tag_001_014_677"> </a>APPLICATION USAGE</h4><blockquote>Since editors sometimes use file descriptorsas integral parts of their editing,redirecting their file descriptors as part of the<i>fc</i>command can produce unexpected results.For example, if<i><a href="vi.html">vi</a></i>is the<i>FCEDIT</i>editor, the command:<pre><code>fc -s | more</code></pre>will not work correctly on many systems.<p>Users on windowing systems may want to have separatehistory files for each window by setting<i>HISTFILE</i>as follows:<pre><code>HISTFILE=$HOME/.sh_hist$$</code></pre></blockquote><h4><a name = "tag_001_014_678"> </a>EXAMPLES</h4><blockquote>None.</blockquote><h4><a name = "tag_001_014_679"> </a>FUTURE DIRECTIONS</h4><blockquote>The IEEE PASC 1003.2 Interpretations Committee has forwarded concerns about parts of this interface definition to the IEEE PASC Shell and Utilities Working Groupwhich is identifying the corrections.A future revision of this specification will align withIEEE Std. 1003.2b when finalised.</blockquote><h4><a name = "tag_001_014_680"> </a>SEE ALSO</h4><blockquote><i><a href="sh.html">sh</a></i>.</blockquote><hr size=2 noshade><center><font size=2>UNIX ® is a registered Trademark of The Open Group.<br>Copyright © 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -