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

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       fc — process the command history list
14

SYNOPSIS

16       fc [−r] [−e editor] [first [last]]
17
18       fc −l [−nr] [first [last]]
19
20       fc −s [old=new] [first]
21

DESCRIPTION

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

OPTIONS

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

OPERANDS

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

STDIN

148       Not used.
149

INPUT FILES

151       None.
152

ENVIRONMENT VARIABLES

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

ASYNCHRONOUS EVENTS

222       Default.
223

STDOUT

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

STDERR

241       The standard error shall be used only for diagnostic messages.
242

OUTPUT FILES

244       None.
245

EXTENDED DESCRIPTION

247       None.
248

EXIT STATUS

250       The following exit values shall be returned:
251
252        0    Successful completion of the listing.
253
254       >0    An error occurred.
255
256       Otherwise, the exit status shall be that of the  commands  executed  by
257       fc.
258

CONSEQUENCES OF ERRORS

260       Default.
261
262       The following sections are informative.
263

APPLICATION USAGE

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

EXAMPLES

280       None.
281

RATIONALE

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

FUTURE DIRECTIONS

350       None.
351

SEE ALSO

353       sh
354
355       The  Base  Definitions  volume  of POSIX.1‐2008, Chapter 8, Environment
356       Variables, Section 12.2, Utility Syntax Guidelines
357
359       Portions of this text are reprinted and reproduced in  electronic  form
360       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
361       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
362       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
363       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
364       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) In the
365       event of any discrepancy between this version and the original IEEE and
366       The  Open Group Standard, the original IEEE and The Open Group Standard
367       is the referee document. The original Standard can be  obtained  online
368       at http://www.unix.org/online.html .
369
370       Any  typographical  or  formatting  errors that appear in this page are
371       most likely to have been introduced during the conversion of the source
372       files  to  man page format. To report such errors, see https://www.ker
373       nel.org/doc/man-pages/reporting_bugs.html .
374
375
376
377IEEE/The Open Group                  2013                               FC(1P)
Impressum