1FC(1P) POSIX Programmer's Manual FC(1P)
2
3
4
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
12 fc - process the command history list
13
15 fc [-r][-e editor] [first[last]]
16
17 fc -l[-nr] [first[last]]
18
19 fc -s[old=new][first]
20
21
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
51 fc -s -- -1 2>/dev/null
52
53 reinvokes the previous command, suppressing standard error for both fc
54 and the previous command.
55
57 The fc utility shall conform to the Base Definitions volume of
58 IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines.
59
60 The following options shall be supported:
61
62 -e editor
63 Use the editor named by editor to edit the commands. The editor
64 string is a utility name, subject to search via the PATH vari‐
65 able (see the Base Definitions volume of IEEE Std 1003.1-2001,
66 Chapter 8, Environment Variables). The value in the FCEDIT vari‐
67 able shall be used as a default when -e is not specified. If
68 FCEDIT is null or unset, ed shall be used as the editor.
69
70 -l (The letter ell.) List the commands rather than invoking an edi‐
71 tor on them. The commands shall be written in the sequence indi‐
72 cated by the first and last operands, as affected by -r, with
73 each command preceded by the command number.
74
75 -n Suppress command numbers when listing with -l.
76
77 -r Reverse the order of the commands listed (with -l) or edited
78 (with neither -l nor -s).
79
80 -s Re-execute the command without invoking an editor.
81
82
84 The following operands shall be supported:
85
86 first, last
87 Select the commands to list or edit. The number of previous com‐
88 mands that can be accessed shall be determined by the value of
89 the HISTSIZE variable. The value of first or last or both shall
90 be one of the following:
91
92 [+]number
93 A positive number representing a command number; command numbers
94 can be displayed with the -l option.
95
96 -number
97 A negative decimal number representing the command that was exe‐
98 cuted number of commands previously. For example, -1 is the
99 immediately previous command.
100
101 string
102 A string indicating the most recently entered command that
103 begins with that string. If the old= new operand is not also
104 specified with -s, the string form of the first operand cannot
105 contain an embedded equal sign.
106
107
108 When the synopsis form with -s is used:
109
110 * If first is omitted, the previous command shall be used.
111
112 For the synopsis forms without -s:
113
114 * If last is omitted, last shall default to the previous com‐
115 mand when -l is specified; otherwise, it shall default to
116 first.
117
118 * If first and last are both omitted, the previous 16 commands
119 shall be listed or the previous single command shall be
120 edited (based on the -l option).
121
122 * If first and last are both present, all of the commands from
123 first to last shall be edited (without -l) or listed (with
124 -l). Editing multiple commands shall be accomplished by pre‐
125 senting to the editor all of the commands at one time, each
126 command starting on a new line. If first represents a newer
127 command than last, the commands shall be listed or edited in
128 reverse sequence, equivalent to using -r. For example, the
129 following commands on the first line are equivalent to the
130 corresponding commands on the second:
131
132
133 fc -r 10 20 fc 30 40
134 fc 20 10 fc -r 40 30
135
136 * When a range of commands is used, it shall not be an error to
137 specify first or last values that are not in the history
138 list; fc shall substitute the value representing the oldest
139 or newest command in the list, as appropriate. For example,
140 if there are only ten commands in the history list, numbered
141 1 to 10:
142
143
144 fc -l
145 fc 1 99
146
147 shall list and edit, respectively, all ten commands.
148
149 old=new
150 Replace the first occurrence of string old in the commands to be
151 re-executed by the string new.
152
153
155 Not used.
156
158 None.
159
161 The following environment variables shall affect the execution of fc:
162
163 FCEDIT This variable, when expanded by the shell, shall determine the
164 default value for the -e editor option's editor option-argument.
165 If FCEDIT is null or unset, ed shall be used as the editor.
166
167 HISTFILE
168 Determine a pathname naming a command history file. If the HIST‐
169 FILE variable is not set, the shell may attempt to access or
170 create a file .sh_history in the directory referred to by the
171 HOME environment variable. If the shell cannot obtain both read
172 and write access to, or create, the history file, it shall use
173 an unspecified mechanism that allows the history to operate
174 properly. (References to history "file" in this section shall be
175 understood to mean this unspecified mechanism in such cases.) An
176 implementation may choose to access this variable only when ini‐
177 tializing the history file; this initialization shall occur when
178 fc or sh first attempt to retrieve entries from, or add entries
179 to, the file, as the result of commands issued by the user, the
180 file named by the ENV variable, or implementation-defined system
181 start-up files. In some historical shells, the history file is
182 initialized just after the ENV file has been processed. There‐
183 fore, it is implementation-defined whether changes made to HIST‐
184 FILE after the history file has been initialized are effective.
185 Implementations may choose to disable the history list mechanism
186 for users with appropriate privileges who do not set HISTFILE ;
187 the specific circumstances under which this occurs are implemen‐
188 tation-defined. If more than one instance of the shell is using
189 the same history file, it is unspecified how updates to the his‐
190 tory file from those shells interact. As entries are deleted
191 from the history file, they shall be deleted oldest first. It
192 is unspecified when history file entries are physically removed
193 from the history file.
194
195 HISTSIZE
196 Determine a decimal number representing the limit to the number
197 of previous commands that are accessible. If this variable is
198 unset, an unspecified default greater than or equal to 128 shall
199 be used. The maximum number of commands in the history list is
200 unspecified, but shall be at least 128. An implementation may
201 choose to access this variable only when initializing the his‐
202 tory file, as described under HISTFILE. Therefore, it is
203 unspecified whether changes made to HISTSIZE after the history
204 file has been initialized are effective.
205
206 LANG Provide a default value for the internationalization variables
207 that are unset or null. (See the Base Definitions volume of
208 IEEE Std 1003.1-2001, Section 8.2, Internationalization Vari‐
209 ables for the precedence of internationalization variables used
210 to determine the values of locale categories.)
211
212 LC_ALL If set to a non-empty string value, override the values of all
213 the other internationalization variables.
214
215 LC_CTYPE
216 Determine the locale for the interpretation of sequences of
217 bytes of text data as characters (for example, single-byte as
218 opposed to multi-byte characters in arguments and input files).
219
220 LC_MESSAGES
221 Determine the locale that should be used to affect the format
222 and contents of diagnostic messages written to standard error.
223
224 NLSPATH
225 Determine the location of message catalogs for the processing of
226 LC_MESSAGES .
227
228
230 Default.
231
233 When the -l option is used to list commands, the format of each command
234 in the list shall be as follows:
235
236
237 "%d\t%s\n", <line number>, <command>
238
239 If both the -l and -n options are specified, the format of each command
240 shall be:
241
242
243 "\t%s\n", <command>
244
245 If the <command> consists of more than one line, the lines after the
246 first shall be displayed as:
247
248
249 "\t%s\n", <continued-command>
250
252 The standard error shall be used only for diagnostic messages.
253
255 None.
256
258 None.
259
261 The following exit values shall be returned:
262
263 0 Successful completion of the listing.
264
265 >0 An error occurred.
266
267
268 Otherwise, the exit status shall be that of the commands executed by
269 fc.
270
272 Default.
273
274 The following sections are informative.
275
277 Since editors sometimes use file descriptors as integral parts of their
278 editing, redirecting their file descriptors as part of the fc command
279 can produce unexpected results. For example, if vi is the FCEDIT edi‐
280 tor, the command:
281
282
283 fc -s | more
284
285 does not work correctly on many systems.
286
287 Users on windowing systems may want to have separate history files for
288 each window by setting HISTFILE as follows:
289
290
291 HISTFILE=$HOME/.sh_hist$$
292
294 None.
295
297 This utility is based on the fc built-in of the KornShell.
298
299 An early proposal specified the -e option as [-e editor [ old = new ]],
300 which is not historical practice. Historical practice in fc of either
301 [-e editor ] or [-e - [ old = new ]] is acceptable, but not both
302 together. To clarify this, a new option -s was introduced replacing
303 the [-e -]. This resolves the conflict and makes fc conform to the
304 Utility Syntax Guidelines.
305
306 HISTFILE
307 Some implementations of the KornShell check for the superuser
308 and do not create a history file unless HISTFILE is set. This
309 is done primarily to avoid creating unlinked files in the root
310 file system when logging in during single-user mode. HISTFILE
311 must be set for the superuser to have history.
312
313 HISTSIZE
314 Needed to limit the size of history files. It is the intent of
315 the standard developers that when two shells share the same his‐
316 tory file, commands that are entered in one shell shall be
317 accessible by the other shell. Because of the difficulties of
318 synchronization over a network, the exact nature of the interac‐
319 tion is unspecified.
320
321
322 The initialization process for the history file can be dependent on the
323 system start-up files, in that they may contain commands that effec‐
324 tively preempt the settings the user has for HISTFILE and HISTSIZE.
325 For example, function definition commands are recorded in the history
326 file. If the system administrator includes function definitions in some
327 system start-up file called before the ENV file, the history file is
328 initialized before the user can influence its characteristics. In some
329 historical shells, the history file is initialized just after the ENV
330 file has been processed. Because of these situations, the text requires
331 the initialization process to be implementation-defined.
332
333 Consideration was given to omitting the fc utility in favor of the com‐
334 mand line editing feature in sh. For example, in vi editing mode, typ‐
335 ing "<ESC> v" is equivalent to:
336
337
338 EDITOR=vi fc
339
340 However, the fc utility allows the user the flexibility to edit multi‐
341 ple commands simultaneously (such as fc 10 20) and to use editors other
342 than those supported by sh for command line editing.
343
344 In the KornShell, the alias r (``re-do") is preset to fc -e - (equiva‐
345 lent to the POSIX fc -s). This is probably an easier command name to
346 remember than fc (``fix command"), but it does not meet the Utility
347 Syntax Guidelines. Renaming fc to hist or redo was considered, but
348 since this description closely matches historical KornShell practice
349 already, such a renaming was seen as gratuitous. Users are free to cre‐
350 ate aliases whenever odd historical names such as fc, awk, cat, grep,
351 or yacc are standardized by POSIX.
352
353 Command numbers have no ordering effects; they are like serial numbers.
354 The -r option and -number operand address the sequence of command exe‐
355 cution, regardless of serial numbers. So, for example, if the command
356 number wrapped back to 1 at some arbitrary point, there would be no
357 ambiguity associated with traversing the wrap point. For example, if
358 the command history were:
359
360
361 32766: echo 1
362 32767: echo 2
363 1: echo 3
364
365 the number -2 refers to command 32767 because it is the second previous
366 command, regardless of serial number.
367
369 None.
370
372 sh
373
375 Portions of this text are reprinted and reproduced in electronic form
376 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
377 -- Portable Operating System Interface (POSIX), The Open Group Base
378 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
379 Electrical and Electronics Engineers, Inc and The Open Group. In the
380 event of any discrepancy between this version and the original IEEE and
381 The Open Group Standard, the original IEEE and The Open Group Standard
382 is the referee document. The original Standard can be obtained online
383 at http://www.opengroup.org/unix/online.html .
384
385
386
387IEEE/The Open Group 2003 FC(1P)