1FC(P)                      POSIX Programmer's Manual                     FC(P)
2
3
4

NAME

6       fc - process the command history list
7

SYNOPSIS

9       fc [-r][-e editor] [first[last]]
10
11       fc -l[-nr] [first[last]]
12
13       fc -s[old=new][first]
14
15

DESCRIPTION

17       The  fc utility shall list, or shall edit and re-execute, commands pre‐
18       viously entered to an interactive sh.
19
20       The command history list shall reference commands by number. The  first
21       number  in the list is selected arbitrarily. The relationship of a num‐
22       ber to its command shall not change except when the user logs in and no
23       other process is accessing the list, at which time the system may reset
24       the numbering to start the oldest retained command  at  another  number
25       (usually  1).  When  the number reaches an implementation-defined upper
26       limit, which shall be no smaller than the value in  HISTSIZE  or  32767
27       (whichever  is  greater),  the shell may wrap the numbers, starting the
28       next command with a lower number (usually  1).  However,  despite  this
29       optional  wrapping  of  numbers,  fc  shall  maintain the time-ordering
30       sequence of the commands. For example, if four commands in sequence are
31       given  the  numbers  32766,  32767, 1 (wrapped), and 2 as they are exe‐
32       cuted, command 32767 is considered the  command  previous  to  1,  even
33       though its number is higher.
34
35       When  commands  are  edited  (when the -l option is not specified), the
36       resulting lines shall be entered at the end of  the  history  list  and
37       then  re-executed  by  sh. The fc command that caused the editing shall
38       not be entered into the history list. If the editor returns a  non-zero
39       exit  status,  this  shall suppress the entry into the history list and
40       the command re-execution. Any command line variable assignments or  re‐
41       direction  operators  used  with  fc  shall  affect both the fc command
42       itself as well as the command that results; for example:
43
44
45              fc -s -- -1 2>/dev/null
46
47       reinvokes the previous command, suppressing standard error for both  fc
48       and the previous command.
49

OPTIONS

51       The  fc  utility  shall  conform  to  the  Base  Definitions  volume of
52       IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines.
53
54       The following options shall be supported:
55
56       -e  editor
57              Use the editor named by editor to edit the commands. The  editor
58              string  is  a utility name, subject to search via the PATH vari‐
59              able (see the Base Definitions volume  of  IEEE Std 1003.1-2001,
60              Chapter 8, Environment Variables). The value in the FCEDIT vari‐
61              able shall be used as a default when -e  is  not  specified.  If
62              FCEDIT is null or unset, ed shall be used as the editor.
63
64       -l     (The letter ell.) List the commands rather than invoking an edi‐
65              tor on them. The commands shall be written in the sequence indi‐
66              cated  by  the  first and last operands, as affected by -r, with
67              each command preceded by the command number.
68
69       -n     Suppress command numbers when listing with -l.
70
71       -r     Reverse the order of the commands listed  (with  -l)  or  edited
72              (with neither -l nor -s).
73
74       -s     Re-execute the command without invoking an editor.
75
76

OPERANDS

78       The following operands shall be supported:
79
80       first, last
81              Select the commands to list or edit. The number of previous com‐
82              mands that can be accessed shall be determined by the  value  of
83              the  HISTSIZE variable. The value of first or last or both shall
84              be one of the following:
85
86       [+]number
87              A positive number representing a command number; command numbers
88              can be displayed with the -l option.
89
90       -number
91              A negative decimal number representing the command that was exe‐
92              cuted number of commands previously.  For  example,  -1  is  the
93              immediately previous command.
94
95       string
96              A  string  indicating  the  most  recently  entered command that
97              begins with that string. If the old= new  operand  is  not  also
98              specified  with  -s, the string form of the first operand cannot
99              contain an embedded equal sign.
100
101
102       When the synopsis form with -s is used:
103
104               * If first is omitted, the previous command shall be used.
105
106       For the synopsis forms without -s:
107
108               * If last is omitted, last shall default to the  previous  com‐
109                 mand  when  -l  is  specified; otherwise, it shall default to
110                 first.
111
112               * If first and last are both omitted, the previous 16  commands
113                 shall  be  listed  or  the  previous  single command shall be
114                 edited (based on the -l option).
115
116               * If first and last are both present, all of the commands  from
117                 first  to  last  shall be edited (without -l) or listed (with
118                 -l). Editing multiple commands shall be accomplished by  pre‐
119                 senting  to  the editor all of the commands at one time, each
120                 command starting on a new line. If first represents  a  newer
121                 command  than last, the commands shall be listed or edited in
122                 reverse sequence, equivalent to using -r.  For  example,  the
123                 following  commands  on  the first line are equivalent to the
124                 corresponding commands on the second:
125
126
127                 fc -r 10 20    fc    30 40
128                 fc    20 10    fc -r 40 30
129
130               * When a range of commands is used, it shall not be an error to
131                 specify  first  or  last  values  that are not in the history
132                 list; fc shall substitute the value representing  the  oldest
133                 or  newest  command in the list, as appropriate. For example,
134                 if there are only ten commands in the history list,  numbered
135                 1 to 10:
136
137
138                 fc -l
139                 fc 1 99
140
141              shall list and edit, respectively, all ten commands.
142
143       old=new
144              Replace the first occurrence of string old in the commands to be
145              re-executed by the string new.
146
147

STDIN

149       Not used.
150

INPUT FILES

152       None.
153

ENVIRONMENT VARIABLES

155       The following environment variables shall affect the execution of fc:
156
157       FCEDIT This variable, when expanded by the shell, shall  determine  the
158              default value for the -e editor option's editor option-argument.
159              If FCEDIT is null or unset, ed shall be used as the editor.
160
161       HISTFILE
162              Determine a pathname naming a command history file. If the HIST‐
163              FILE  variable  is  not  set, the shell may attempt to access or
164              create a file .sh_history in the directory referred  to  by  the
165              HOME  environment variable. If the shell cannot obtain both read
166              and write access to, or create, the history file, it  shall  use
167              an  unspecified  mechanism  that  allows  the history to operate
168              properly. (References to history "file" in this section shall be
169              understood to mean this unspecified mechanism in such cases.) An
170              implementation may choose to access this variable only when ini‐
171              tializing the history file; this initialization shall occur when
172              fc or sh first attempt to retrieve entries from, or add  entries
173              to,  the file, as the result of commands issued by the user, the
174              file named by the ENV variable, or implementation-defined system
175              start-up  files.  In some historical shells, the history file is
176              initialized just after the ENV file has been processed.   There‐
177              fore, it is implementation-defined whether changes made to HIST‐
178              FILE after the history file has been initialized are  effective.
179              Implementations may choose to disable the history list mechanism
180              for users with appropriate privileges who do not set HISTFILE  ;
181              the specific circumstances under which this occurs are implemen‐
182              tation-defined. If more than one instance of the shell is  using
183              the same history file, it is unspecified how updates to the his‐
184              tory file from those shells interact.  As  entries  are  deleted
185              from  the  history file, they shall be deleted oldest first.  It
186              is unspecified when history file entries are physically  removed
187              from the history file.
188
189       HISTSIZE
190              Determine  a decimal number representing the limit to the number
191              of previous commands that are accessible. If  this  variable  is
192              unset, an unspecified default greater than or equal to 128 shall
193              be used. The maximum number of commands in the history  list  is
194              unspecified,  but  shall  be at least 128. An implementation may
195              choose to access this variable only when initializing  the  his‐
196              tory  file,  as  described  under  HISTFILE  .  Therefore, it is
197              unspecified whether changes made to HISTSIZE after  the  history
198              file has been initialized are effective.
199
200       LANG   Provide  a  default value for the internationalization variables
201              that are unset or null. (See  the  Base  Definitions  volume  of
202              IEEE Std 1003.1-2001,  Section  8.2,  Internationalization Vari‐
203              ables for the precedence of internationalization variables  used
204              to determine the values of locale categories.)
205
206       LC_ALL If  set  to a non-empty string value, override the values of all
207              the other internationalization variables.
208
209       LC_CTYPE
210              Determine the locale for  the  interpretation  of  sequences  of
211              bytes  of  text  data as characters (for example, single-byte as
212              opposed to multi-byte characters in arguments and input files).
213
214       LC_MESSAGES
215              Determine the locale that should be used to  affect  the  format
216              and contents of diagnostic messages written to standard error.
217
218       NLSPATH
219              Determine the location of message catalogs for the processing of
220              LC_MESSAGES .
221
222

ASYNCHRONOUS EVENTS

224       Default.
225

STDOUT

227       When the -l option is used to list commands, the format of each command
228       in the list shall be as follows:
229
230
231              "%d\t%s\n", <line number>, <command>
232
233       If both the -l and -n options are specified, the format of each command
234       shall be:
235
236
237              "\t%s\n", <command>
238
239       If the <command> consists of more than one line, the  lines  after  the
240       first shall be displayed as:
241
242
243              "\t%s\n", <continued-command>
244

STDERR

246       The standard error shall be used only for diagnostic messages.
247

OUTPUT FILES

249       None.
250

EXTENDED DESCRIPTION

252       None.
253

EXIT STATUS

255       The following exit values shall be returned:
256
257        0     Successful completion of the listing.
258
259       >0     An error occurred.
260
261
262       Otherwise,  the  exit  status shall be that of the commands executed by
263       fc.
264

CONSEQUENCES OF ERRORS

266       Default.
267
268       The following sections are informative.
269

APPLICATION USAGE

271       Since editors sometimes use file descriptors as integral parts of their
272       editing,  redirecting  their file descriptors as part of the fc command
273       can produce unexpected results. For example, if vi is the  FCEDIT  edi‐
274       tor, the command:
275
276
277              fc -s | more
278
279       does not work correctly on many systems.
280
281       Users  on windowing systems may want to have separate history files for
282       each window by setting HISTFILE as follows:
283
284
285              HISTFILE=$HOME/.sh_hist$$
286

EXAMPLES

288       None.
289

RATIONALE

291       This utility is based on the fc built-in of the KornShell.
292
293       An early proposal specified the -e option as [-e editor [ old = new ]],
294       which  is  not historical practice. Historical practice in fc of either
295       [-e editor ] or [-e - [ old =  new  ]]  is  acceptable,  but  not  both
296       together.   To  clarify  this, a new option -s was introduced replacing
297       the [-e -]. This resolves the conflict and  makes  fc  conform  to  the
298       Utility Syntax Guidelines.
299
300       HISTFILE
301              Some  implementations  of  the KornShell check for the superuser
302              and do not create a history file unless HISTFILE is  set.   This
303              is  done  primarily to avoid creating unlinked files in the root
304              file system when logging in during single-user  mode.   HISTFILE
305              must be set for the superuser to have history.
306
307       HISTSIZE
308              Needed  to  limit the size of history files. It is the intent of
309              the standard developers that when two shells share the same his‐
310              tory  file,  commands  that  are  entered  in one shell shall be
311              accessible by the other shell. Because of  the  difficulties  of
312              synchronization over a network, the exact nature of the interac‐
313              tion is unspecified.
314
315
316       The initialization process for the history file can be dependent on the
317       system  start-up  files,  in that they may contain commands that effec‐
318       tively preempt the settings the user has for HISTFILE  and  HISTSIZE  .
319       For  example,  function definition commands are recorded in the history
320       file. If the system administrator includes function definitions in some
321       system  start-up  file  called before the ENV file, the history file is
322       initialized before the user can influence its characteristics. In  some
323       historical  shells,  the history file is initialized just after the ENV
324       file has been processed. Because of these situations, the text requires
325       the initialization process to be implementation-defined.
326
327       Consideration was given to omitting the fc utility in favor of the com‐
328       mand line editing feature in sh. For example, in vi editing mode,  typ‐
329       ing "<ESC> v" is equivalent to:
330
331
332              EDITOR=vi fc
333
334       However,  the fc utility allows the user the flexibility to edit multi‐
335       ple commands simultaneously (such as fc 10 20) and to use editors other
336       than those supported by sh for command line editing.
337
338       In  the KornShell, the alias r (``re-do") is preset to fc -e - (equiva‐
339       lent to the POSIX fc -s). This is probably an easier  command  name  to
340       remember  than  fc  (``fix  command"), but it does not meet the Utility
341       Syntax Guidelines. Renaming fc to hist  or  redo  was  considered,  but
342       since  this  description  closely matches historical KornShell practice
343       already, such a renaming was seen as gratuitous. Users are free to cre‐
344       ate  aliases  whenever odd historical names such as fc, awk, cat, grep,
345       or yacc are standardized by POSIX.
346
347       Command numbers have no ordering effects; they are like serial numbers.
348       The  -r option and -number operand address the sequence of command exe‐
349       cution, regardless of serial numbers. So, for example, if  the  command
350       number  wrapped  back  to  1 at some arbitrary point, there would be no
351       ambiguity associated with traversing the wrap point.  For  example,  if
352       the command history were:
353
354
355              32766: echo 1
356              32767: echo 2
357              1: echo 3
358
359       the number -2 refers to command 32767 because it is the second previous
360       command, regardless of serial number.
361

FUTURE DIRECTIONS

363       None.
364

SEE ALSO

366       sh
367
369       Portions of this text are reprinted and reproduced in  electronic  form
370       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
371       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
372       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
373       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
374       event of any discrepancy between this version and the original IEEE and
375       The Open Group Standard, the original IEEE and The Open Group  Standard
376       is  the  referee document. The original Standard can be obtained online
377       at http://www.opengroup.org/unix/online.html .
378
379
380
381IEEE/The Open Group                  2003                                FC(P)
Impressum