Merge commit 'b31320a79e2054c6739b5229259dbf98f3afc547' into merges
[unleashed.git] / share / man / man1 / history.1
blobccecac365e2e887c44819d22cab4b6c0e3a992ff
1 '\" te
2 .\" Copyright 1989 AT&T
3 .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved
4 .\" Portions Copyright (c) 1982-2007 AT&T Knowledge Ventures
5 .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
6 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
7 .\" http://www.opengroup.org/bookstore/.
8 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
9 .\"  This notice shall appear on any product containing this material.
10 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
11 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
12 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
13 .TH HISTORY 1 "May 13, 2017"
14 .SH NAME
15 history, fc, hist \- process command history list
16 .SH SYNOPSIS
17 .LP
18 .nf
19 \fB/usr/bin/fc\fR [\fB-r\fR] [\fB-e\fR \fIeditor\fR] [\fIfirst\fR [\fIlast\fR]]
20 .fi
22 .LP
23 .nf
24 \fB/usr/bin/fc\fR \fB-l\fR [\fB-nr\fR] [\fIfirst\fR [\fIlast\fR]]
25 .fi
27 .LP
28 .nf
29 \fB/usr/bin/fc\fR \fB-s\fR [\fIold\fR=\fInew\fR] [\fIfirst\fR]
30 .fi
32 .SS "csh"
33 .LP
34 .nf
35 \fBhistory\fR [\fB-hr\fR] [\fIn\fR]
36 .fi
38 .SS "ksh"
39 .LP
40 .nf
41 \fBfc\fR \fB-e\fR \fB-\fR [\fIold\fR=\fInew\fR] [\fIcommand\fR]
42 .fi
44 .LP
45 .nf
46 \fBfc\fR \fB-s\fR [\fIold\fR = \fInew\fR] [\fIcommand\fR]
47 .fi
49 .LP
50 .nf
51 \fBfc\fR [\fB-e\fR \fIename\fR] [\fB-nlr\fR] [\fIfirst\fR [\fIlast\fR]]
52 .fi
54 .SS "ksh93"
55 .LP
56 .nf
57 \fBhist\fR [\fB-lnprs\fR] [\fB-e\fR \fIeditor\fR][\fB-N\fR \fInum\fR][\fIfirst\fR[\fIlast\fR]]
58 .fi
60 .SH DESCRIPTION
61 .SS "/usr/bin/fc"
62 .LP
63 The \fBfc\fR utility lists or edits and reexecutes, commands previously entered
64 to an interactive \fBsh\fR.
65 .sp
66 .LP
67 The command history list references commands by number. The first number in the
68 list is selected arbitrarily. The relationship of a number to its command does
69 not change except when the user logs in and no other process is accessing the
70 list, at which time the system can reset the numbering to start the oldest
71 retained command at another number (usually 1). When the number reaches the
72 value in \fBHISTSIZE\fR or \fB32767\fR (whichever is greater), the shell can
73 wrap the numbers, starting the next command with a lower number (usually 1).
74 However, despite this optional wrapping of numbers, \fBfc\fR maintains the
75 time-ordering sequence of the commands. For example, if four commands in
76 sequence are given the numbers 32 766, 32 767, 1 (wrapped), and 2 as they are
77 executed, command 32 767 is considered the command previous to 1, even though
78 its number is higher.
79 .sp
80 .LP
81 When commands are edited (when the \fB-l\fR option is not specified), the
82 resulting lines is entered at the end of the history list and then reexecuted
83 by \fBsh\fR. The \fBfc\fR command that caused the editing is not entered into
84 the history list. If the editor returns a non-zero exit status, this suppresses
85 the entry into the history list and the command reexecution. Any command-line
86 variable assignments or redirection operators used with \fBfc\fR affects both
87 the \fBfc\fR command itself as well as the command that results, for example:
88 .sp
89 .in +2
90 .nf
91 \fBfc -s -- -1 2>/dev/null\fR
92 .fi
93 .in -2
94 .sp
96 .sp
97 .LP
98 reinvokes the previous command, suppressing standard error for both \fBfc\fR
99 and the previous command.
100 .SS "csh"
102 Display the history list. If \fIn\fR is given, display only the \fIn\fR most
103 recent events.
105 .ne 2
107 \fB\fB-r\fR\fR
109 .RS 6n
110 Reverse the order of printout to be most recent first rather than oldest first.
114 .ne 2
116 \fB\fB-h\fR\fR
118 .RS 6n
119 Display the history list without leading numbers. This is used to produce files
120 suitable for sourcing using the \fB-h\fR option to the \fBcsh\fR built-in
121 command, \fBsource\fR(1).
124 .SS "History Substitution:"
126 History substitution allows you to use words from previous command lines in the
127 command line you are typing. This simplifies spelling corrections and the
128 repetition of complicated commands or arguments. Command lines are saved in the
129 history list, the size of which is controlled by the \fBhistory\fR variable.
130 The \fBhistory\fR shell variable can be set to the maximum number of command
131 lines that is saved in the history file, that is:
133 .in +2
135 set history = 200
137 .in -2
141 allows the history list to keep track of the most recent 200 command lines. If
142 not set, the C shell saves only the most recent command.
145 A history substitution begins with a \fB!\fR (although you can change this with
146 the \fBhistchars\fR variable) and can occur anywhere on the command line;
147 history substitutions do not nest. The \fB!\fR can be escaped with \fB\e\fR to
148 suppress its special meaning.
151 Input lines containing history substitutions are echoed on the terminal after
152 being expanded, but before any other substitutions take place or the command
153 gets executed.
154 .SS "Event Designators:"
156 An event designator is a reference to a command line entry in the history list.
158 .ne 2
160 \fB\fB!\fR\fR
162 .sp .6
163 .RS 4n
164 Start a history substitution, except when followed by a space character, tab,
165 newline, \fB=\fR or \fB(\fR.
169 .ne 2
171 \fB\fB!!\fR\fR
173 .sp .6
174 .RS 4n
175 Refer to the previous command. By itself, this substitution repeats the
176 previous command.
180 .ne 2
182 \fB\fB!\fR\fIn\fR\fR
184 .sp .6
185 .RS 4n
186 Refer to command line \fIn\fR.
190 .ne 2
192 \fB\fB!\fR\fB-n\fR\fR
194 .sp .6
195 .RS 4n
196 Refer to the current command line minus \fIn\fR.
200 .ne 2
202 \fB\fB!\fR\fIstr\fR\fR
204 .sp .6
205 .RS 4n
206 Refer to the most recent command starting with \fIstr\fR.
210 .ne 2
212 \fB\fB!?\fR\fIstr\fR\fB?\fR\fR
214 .sp .6
215 .RS 4n
216 Refer to the most recent command containing \fIstr\fR.
220 .ne 2
222 \fB\fB!?\fR\fIstr\fR\fB?\fR \fIadditional\fR\fR
224 .sp .6
225 .RS 4n
226 Refer to the most recent command containing \fIstr\fR and append
227 \fIadditional\fR to that referenced command.
231 .ne 2
233 \fB\fB!{\fR\fBcommand\fR\fB}\fR \fIadditional\fR\fR
235 .sp .6
236 .RS 4n
237 Refer to the most recent command beginning with \fBcommand\fR and append
238 \fIadditional\fR to that referenced command.
242 .ne 2
244 \fB\fB^\fR\fIprevious_word\fR\fB^\fR\fIreplacement\fR\fB^\fR\fR
246 .sp .6
247 .RS 4n
248 Repeat the previous command line replacing the string \fIprevious_word\fR with
249 the string \fIreplacement\fR. This is equivalent to the history substitution:
251 Repeat the previous command line replacing the string \fIprevious_word\fR with
252 the string \fIreplacement\fR. This is equivalent to the history substitution:
254 .in +2
256 \fB!:s/\fR\fIprevious_word\fR\fB/\fR\fIreplacement\fR\fB/\fR.
258 .in -2
260 To re-execute a specific previous command \fBand\fR make such a substitution,
261 say, re-executing command #6:
263 .in +2
265 \fB!:6s/\fR\fIprevious_word\fR\fB/\fR\fIreplacement\fR\fB/\fR.
267 .in -2
271 .SS "Word Designators:"
273 A `\fB:\fR' (colon) separates the event specification from the word designator.
274 2It can be omitted if the word designator begins with a \fB^\fR, \fB$\fR,
275 \fB*\fR, \fB\(mi\fR or \fB%\fR. If the word is to be selected from the previous
276 command, the second \fB!\fR character can be omitted from the event
277 specification. For instance, \fB!!:1\fR and \fB!:1\fR both refer to the first
278 word of the previous command, while \fB!!$\fR and \fB!$\fR both refer to the
279 last word in the previous command. Word designators include:
281 .ne 2
283 \fB\fB#\fR\fR
285 .RS 10n
286 The entire command line typed so far.
290 .ne 2
292 \fB\fB0\fR\fR
294 .RS 10n
295 The first input word (command).
299 .ne 2
301 \fB\fIn\fR\fR
303 .RS 10n
304 The \fIn\fR'th argument.
308 .ne 2
310 \fB\fB^\fR\fR
312 .RS 10n
313 The first argument, that is, \fB1\fR.
317 .ne 2
319 \fB\fB$\fR\fR
321 .RS 10n
322 The last argument.
326 .ne 2
328 \fB\fB%\fR\fR
330 .RS 10n
331 The word matched by (the most recent) \fB?\fR\fIs\fR search.
335 .ne 2
337 \fB\fIx\fR\fB\(mi\fR\fIy\fR\fR
339 .RS 10n
340 A range of words; \fB\(mi\fR\fIy\fR abbreviates \fB0\(mi\fR\fIy\fR.
344 .ne 2
346 \fB\fB*\fR\fR
348 .RS 10n
349 All the arguments, or a null value if there is just one word in the event.
353 .ne 2
355 \fB\fIx\fR\fB*\fR\fR
357 .RS 10n
358 Abbreviates \fIx\fR\fB\(mi$\fR\fI\&.\fR
362 .ne 2
364 \fB\fIx\fR\fB\(mi\fR\fR
366 .RS 10n
367 Like \fIx\fR\fB*\fR but omitting word \fB$\fR.
370 .SS "Modifiers:"
372 After the optional word designator, you can add a sequence of one or more of
373 the following modifiers, each preceded by a \fB:\fR.
375 .ne 2
377 \fB\fBh\fR\fR
379 .RS 28n
380 Remove a trailing pathname component, leaving the head.
384 .ne 2
386 \fB\fBr\fR\fR
388 .RS 28n
389 Remove a trailing suffix of the form `\fB\&.\fR\fIxxx\fR', leaving the
390 basename.
394 .ne 2
396 \fB\fBe\fR\fR
398 .RS 28n
399 Remove all but the suffix, leaving the extension.
403 .ne 2
405 \fB\fBs/\fR\fIoldchars\fR\fB/\fR\fIreplacements\fR\fB/\fR\fR
407 .RS 28n
408 Substitute \fIreplacements\fR for \fIoldchars\fR. \fIoldchars\fR is a string
409 that can contain embedded blank spaces, whereas \fIprevious_word\fR in the
410 event designator can not.
412 .in +2
414 \fB^\fR\fIoldchars\fR\fB^\fR\fIreplacements\fR\fB^\fR
416 .in -2
421 .ne 2
423 \fB\fBt\fR\fR
425 .RS 28n
426 Remove all leading pathname components, leaving the tail.
430 .ne 2
432 \fB\fB&\fR\fR
434 .RS 28n
435 Repeat the previous substitution.
439 .ne 2
441 \fB\fBg\fR\fR
443 .RS 28n
444 Apply the change to the first occurrence of a match in each word, by prefixing
445 the above (for example, \fBg&\fR).
449 .ne 2
451 \fB\fBp\fR\fR
453 .RS 28n
454 Print the new command but do not execute it.
458 .ne 2
460 \fB\fBq\fR\fR
462 .RS 28n
463 Quote the substituted words, escaping further substitutions.
467 .ne 2
469 \fB\fBx\fR\fR
471 .RS 28n
472 Like \fBq\fR, but break into words at each space character, tab or newline.
477 Unless preceded by a \fBg\fR, the modification is applied only to the first
478 string that matches \fIoldchars\fR. An error results if no string matches.
481 The left-hand side of substitutions are not regular expressions, but character
482 strings. Any character can be used as the delimiter in place of \fB/\fR. A
483 backslash quotes the delimiter character. The character \fB&\fR, in the right
484 hand side, is replaced by the text from the left-hand-side. The \fB&\fR can be
485 quoted with a backslash. A null \fIoldchars\fR uses the previous string either
486 from a \fIoldchars\fR or from a contextual scan string \fIs\fR from
487 \fB!?\fR\fIs\fR. You can omit the rightmost delimiter if a newline immediately
488 follows \fIreplacements\fR; the rightmost \fB?\fR in a context scan can
489 similarly be omitted.
492 Without an event specification, a history reference refers either to the
493 previous command, or to a previous history reference on the command line (if
494 any).
495 .SS "ksh"
497 Using \fBfc\fR, in the form of
499 .in +2
501 \fBfc -e \(mi [\fIold\fR=\fInew\fR] [\fIcommand\fR],\fR
503 .in -2
510 .in +2
512 \fBfc -s [\fIold\fR=\fInew\fR] [\fIcommand\fR],\fR
514 .in -2
519 the \fIcommand\fR is re-executed after the substitution
520 \fIold\fR\fB=\fR\fInew\fR is performed. If there is not a \fIcommand\fR
521 argument, the most recent command typed at this terminal is executed.
524 Using \fBfc\fR in the form of
526 .in +2
528 \fBfc [-e \fIename\fR] [-nlr ] [\fIfirst\fR [\fIlast\fR]],\fR
530 .in -2
535 a range of commands from \fIfirst\fR to \fIlast\fR is selected from the last
536 \fBHISTSIZE\fR commands that were typed at the terminal. The arguments
537 \fIfirst\fR and \fIlast\fR can be specified as a number or as a string. A
538 string is used to locate the most recent command starting with the given
539 string. A negative number is used as an offset to the current command number.
540 If the \fB-l\fR flag is selected, the commands are listed on standard output.
541 Otherwise, the editor program \fB-e\fR \fIname\fR is invoked on a file
542 containing these keyboard commands. If \fIename\fR is not supplied, then the
543 value of the variable \fBFCEDIT\fR (default \fB/bin/ed\fR) is used as the
544 editor. When editing is complete, the edited command(s) is executed. If
545 \fBlast\fR is not specified, it is set to \fIfirst\fR. If \fIfirst\fR is not
546 specified, the default is the previous command for editing and \(mi16 for
547 listing. The flag \fB-r\fR reverses the order of the commands and the flag
548 \fB-n\fR suppresses command numbers when listing. (See \fBksh\fR(1) for more
549 about command line editing.)
551 .ne 2
553 \fB\fBHISTFILE\fR\fR
555 .RS 12n
556 If this variable is set when the shell is invoked, then the value is the
557 pathname of the file that is used to store the command history.
561 .ne 2
563 \fB\fBHISTSIZE\fR\fR
565 .RS 12n
566 If this variable is set when the shell is invoked, then the number of
567 previously entered commands that are accessible by this shell is greater than
568 or equal to this number. The default is \fB128\fR.
571 .SS "Command Re-entry:"
573 The text of the last \fBHISTSIZE\fR (default 128) commands entered from a
574 terminal device is saved in a \fBhistory\fR file. The file
575 \fB$HOME/.sh_history\fR is used if the \fBHISTFILE\fR variable is not set or if
576 the file it names is not writable. A shell can access the commands of all
577 \fIinteractive\fR shells which use the same named \fBHISTFILE\fR. The special
578 command \fBfc\fR is used to list or edit a portion of this file. The portion of
579 the file to be edited or listed can be selected by number or by giving the
580 first character or characters of the command. A single command or range of
581 commands can be specified. If you do not specify an editor program as an
582 argument to \fBfc\fR then the value of the variable \fBFCEDIT\fR is used. If
583 \fBFCEDIT\fR is not defined then \fB/bin/ed\fR is used. The edited command(s)
584 is printed and re-executed upon leaving the editor. The editor name \fB\(mi\fR
585 is used to skip the editing phase and to re-execute the command. In this case a
586 substitution parameter of the form \fIold\fR\fB=\fR\fInew\fR can be used to
587 modify the command before execution. For example, if \fBr\fR is aliased to
588 \fBa\'fc\fR \fB-e\fR \fB\(mi a\'\fR then typing \fB`r\fR \fBbad=good\fR
589 \fBc'\fR re-executes the most recent command which starts with the letter
590 \fBc\fR, replacing the first occurrence of the string \fBbad\fR with the string
591 \fBgood\fR.
594 Using the \fBfc\fR built-in command within a compound command causes the whole
595 command to disappear from the history file.
596 .SS "ksh93"
598 \fBhist\fR lists, edits, or re-executes commands previously entered into the
599 current shell environment.
602 The command history list references commands by number. The first number in the
603 list is selected arbitrarily. The relationship of a number to its command does
604 not change during a login session. When the number reaches \fB32767\fR the
605 number wraps around to \fB1\fR but maintains the ordering.
608 When the \fBl\fR option is not specified, and commands are edited, the
609 resulting lines are entered at the end of the history list and then re-executed
610 by the current shell. The \fBhist\fR command that caused the editing is not
611 entered into the history list. If the editor returns a \fBnon-zero\fR exit
612 status, this suppresses the entry into the history list and the command
613 re-execution. Command line variable assignments and redirections affect both
614 the \fBhist\fR command and the commands that are re-executed.
617 \fIfirst\fR and \fIlast\fR define the range of commands. Specify \fIfirst\fR
618 and \fIlast\fR as one of the following:
620 .ne 2
622 \fB\fInumber\fR\fR
624 .RS 11n
625 A positive number representing a command number. A \fB+\fR sign can precede
626 \fInumber\fR.
630 .ne 2
632 \fB\fB-\fR\fInumber\fR\fR
634 .RS 11n
635 A negative number representing a command that was executed \fInumber\fR
636 commands previously. For example, \fB-1\fR is the previous command.
640 .ne 2
642 \fB\fIstring\fR\fR
644 .RS 11n
645 \fIstring\fR indicates the most recently entered command that begins with
646 \fIstring\fR. \fIstring\fR should not contain an \fB=\fR.
651 If \fIfirst\fR is omitted, the previous command is used, unless \fB-l\fR is
652 specified, in which case it defaults to \fB-16\fR and last defaults to
653 \fB-1\fR.
656 If \fIfirst\fR is specified and \fIlast\fR is omitted, then \fIlast\fR defaults
657 to \fIfirst\fR unless \fB-l\fR is specified in which case it defaults to
658 \fB-1\fR.
661 If no editor is specified, then the editor specified by the \fBHISTEDIT\fR
662 variable is used if set, or the \fBFCEDIT\fR variable is used if set,
663 otherwise, \fBed\fR is used.
664 .SH OPTIONS
666 The following options are supported:
668 .ne 2
670 \fB\fB\fR\fB-e\fR \fIeditor\fR\fR
672 .RS 13n
673 Uses the editor named by \fIeditor\fR to edit the commands. The \fIeditor\fR
674 string is a utility name, subject to search via the \fBPATH\fR variable. The
675 value in the \fBFCEDIT\fR variable is used as a default when \fB-e\fR is not
676 specified. If \fBFCEDIT\fR is null or unset, \fBed\fR is used as the editor.
680 .ne 2
682 \fB\fB-l\fR\fR
684 .RS 13n
685 (The letter ell.) Lists the commands rather than invoking an editor on them.
686 The commands is written in the sequence indicated by the \fIfirst\fR and
687 \fIlast\fR operands, as affected by \fB-r\fR, with each command preceded by the
688 command number.
692 .ne 2
694 \fB\fB-n\fR\fR
696 .RS 13n
697 Suppresses command numbers when listing with \fB-l\fR.
701 .ne 2
703 \fB\fB-r\fR\fR
705 .RS 13n
706 Reverses the order of the commands listed (with \fB-l\fR \fB)\fR or edited
707 (with neither \fB-l\fR nor \fB-s\fR).
711 .ne 2
713 \fB\fB-s\fR\fR
715 .RS 13n
716 Re-executes the command without invoking an editor.
719 .SS "ksh93"
721 \fBksh93\fR supports the following options:
723 .ne 2
725 \fB\fB-e\fR \fIeditor\fR\fR
727 .RS 13n
728 Specify the editor to use to edit the history command. A value of \fB-\fR for
729 \fIeditor\fR is equivalent to specifying the \fB-s\fR option.
733 .ne 2
735 \fB\fB-l\fR\fR
737 .RS 13n
738 List the commands rather than editing and re-executing them.
742 .ne 2
744 \fB\fB-N\fR \fInum\fR\fR
746 .RS 13n
747 Start at \fInum\fR commands back.
751 .ne 2
753 \fB\fB-n\fR\fR
755 .RS 13n
756 Suppress the command numbers when the commands are listed.
760 .ne 2
762 \fB\fB-p\fR\fR
764 .RS 13n
765 Write the result of history expansion for each operand to standard output. All
766 other options are ignored.
770 .ne 2
772 \fB\fB-r\fR\fR
774 .RS 13n
775 Reverse the order of the commands.
779 .ne 2
781 \fB\fB-s\fR\fR
783 .RS 13n
784 Re-execute the command without invoking an editor. In this case an operand of
785 the form \fIold=new\fR can be specified to change the first occurrence of the
786 string \fIold\fR in the command to \fInew\fR before re-executing the command.
789 .SH OPERANDS
791 The following operands are supported:
793 .ne 2
795 \fB\fIfirst\fR\fR
799 \fB\fIlast\fR\fR
801 .RS 9n
802 Selects the commands to list or edit. The number of previous commands that can
803 be accessed is determined by the value of the \fBHISTSIZE\fR variable. The
804 value of \fIfirst\fR or \fIlast\fR or both is one of the following:
806 .ne 2
808 \fB[\fB+\fR]\fInumber\fR\fR
810 .RS 14n
811 A positive number representing a command number. Command numbers can be
812 displayed with the \fB-l\fR option.
816 .ne 2
818 \fB\fB\(mi\fR\fInumber\fR\fR
820 .RS 14n
821 A negative decimal number representing the command that was executed
822 \fInumber\fR of commands previously. For example, \fB\(mi1\fR is the
823 immediately previous command.
827 .ne 2
829 \fB\fIstring\fR\fR
831 .RS 14n
832 A string indicating the most recently entered command that begins with that
833 string. If the \fIold=new\fR operand is not also specified with \fB-s\fR, the
834 string form of the \fIfirst\fR operand cannot contain an embedded equal sign.
836 When the synopsis form with \fB-s\fR is used, if \fIfirst\fR is omitted, the
837 previous command is used.
839 For the synopsis forms without \fB-s\fR \fB:\fR
840 .RS +4
842 .ie t \(bu
843 .el o
844 If \fIlast\fR is omitted, \fIlast\fR defaults to the previous command when
845 \fB-l\fR is specified; otherwise, it defaults to \fIfirst\fR.
847 .RS +4
849 .ie t \(bu
850 .el o
851 If \fIfirst\fR and \fIlast\fR are both omitted, the previous 16 commands is
852 listed or the previous single command is edited (based on the \fB-l\fR option).
854 .RS +4
856 .ie t \(bu
857 .el o
858 If \fIfirst\fR and \fIlast\fR are both present, all of the commands from
859 \fIfirst\fR to \fIlast\fR is edited (without \fB-l\fR \fB)\fR or listed (with
860 \fB-l\fR). Editing multiple commands is accomplished by presenting to the
861 editor all of the commands at one time, each command starting on a new line. If
862 \fIfirst\fR represents a newer command than \fIlast\fR, the commands is listed
863 or edited in reverse sequence, equivalent to using \fB-r\fR. For example, the
864 following commands on the first line are equivalent to the corresponding
865 commands on the second:
867 .in +2
869 fc -r 10 20     fc    30 40
870 fc   20 10      fc -r 40 30
872 .in -2
875 .RS +4
877 .ie t \(bu
878 .el o
879 When a range of commands is used, it is not be an error to specify \fIfirst\fR
880 or \fIlast\fR values that are not in the history list. \fBfc\fR substitutes the
881 value representing the oldest or newest command in the list, as appropriate.
882 For example, if there are only ten commands in the history list, numbered 1 to
885 .in +2
887 fc -l
888 fc 1 99
890 .in -2
892 lists and edits, respectively, all ten commands.
897 .ne 2
899 \fB\fIold=new\fR\fR
901 .RS 14n
902 Replace the first occurrence of string \fIold\fR in the commands to be
903 reexecuted by the string \fInew\fR.
908 .SH OUTPUT
910 When the \fB-l\fR option is used to list commands, the format of each command
911 in the list is as follows:
913 .in +2
915 \fB"%d\et%s\en", <\fR\fIline number\fR\fB>, <\fR\fIcommand\fR\fB>\fR
917 .in -2
921 If both the \fB-l\fR and \fB-n\fR options are specified, the format of each
922 command is:
924 .in +2
926 \fB"\et%s\en", <\fR\fIcommand\fR\fB>\fR
928 .in -2
932 If the \fIcommand\fR\fIcommand\fR consists of more than one line, the lines
933 after the first are displayed as:
935 .in +2
937 \fB"\et%s\en", <\fR\fIcontinued-command\fR\fB>\fR
939 .in -2
941 .SH EXAMPLES
943 \fBExample 1 \fRUsing history and fc
945 .in +2
947              csh                                     ksh
949 % history                               $ fc -l
950   1   cd /etc                             1   cd /etc
951   2   vi passwd                           2   vi passwd
952   3   date                                3   date
953   4   cd                                  4   cd
954   5   du .                                5   du .
955   6   ls -t                               6   ls -t
956   7   history                             7   fc -l
958 % !d                                    $ fc -e - d
959   du .                                    du .
960   262   ./SCCS                            262   ./SCCS
961   336   .                                 336   .
963 % !da                                   $ fc -e - da
964   Thu Jul 21 17:29:56 PDT 1994            Thu Jul 21 17:29:56 PDT 1994
966 %                                       $ alias \e!='fc -e -'
968 % !!                                    $ !
969   date                                    alias ='fc -e -'
970   Thu Jul 21 17:29:56 PDT 1994
972 .in -2
974 .SH ENVIRONMENT VARIABLES
976 See \fBenviron\fR(5) for descriptions of the following environment variables
977 that affect the execution of \fBfc\fR: \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and
978 \fBNLSPATH\fR.
980 .ne 2
982 \fB\fBFCEDIT\fR\fR
984 .RS 12n
985 This variable, when expanded by the shell, determines the default value for the
986 \fB-e\fR \fIeditor\fR option's \fIeditor\fR option-argument. If \fBFCEDIT\fR is
987 null or unset, \fBed\fR(1) is used as the editor.
991 .ne 2
993 \fB\fBHISTFILE\fR\fR
995 .RS 12n
996 Determine a pathname naming a command history file. If the \fBHISTFILE\fR
997 variable is not set, the shell can attempt to access or create a file
998 \fB\&.sh_history\fR in the user's home directory. If the shell cannot obtain
999 both read and write access to, or create, the history file, it uses an
1000 unspecified mechanism that allows the history to operate properly. (References
1001 to history ``file'' in this section are understood to mean this unspecified
1002 mechanism in such cases.) \fBfc\fR can choose to access this variable only when
1003 initializing the history file; this initialization occurs when \fBfc\fR or
1004 \fBsh\fR first attempt to retrieve entries from, or add entries to, the file,
1005 as the result of commands issued by the user, the file named by the \fBENV\fR
1006 variable, or a system startup file such as \fB/etc/profile\fR. (The
1007 initialization process for the history file can be dependent on the system
1008 startup files, in that they can contain commands that effectively preempts the
1009 user's settings of \fBHISTFILE\fR and \fBHISTSIZE\fR. For example, function
1010 definition commands are recorded in the history file, unless the \fBset\fR
1011 \fB-o\fR \fBnolog\fR option is set. If the system administrator includes
1012 function definitions in some system startup file called before the \fBENV\fR
1013 file, the history file is initialized before the user gets a chance to
1014 influence its characteristics.) The variable \fBHISTFILE\fR is accessed
1015 initially when the shell is invoked. Any change to \fBHISTFILE\fR does not
1016 take effect until another shell is invoked.
1020 .ne 2
1022 \fB\fBHISTSIZE\fR\fR
1024 .RS 12n
1025 Determine a decimal number representing the limit to the number of previous
1026 commands that are accessible. If this variable is unset, an unspecified default
1027 greater than or equal to 128 are used. The variable \fBHISTSIZE\fR is accessed
1028 initially when the shell is invoked. Any changes to \fBHISTSIZE\fR does not
1029 take effect until another shell is invoked.
1032 .SH EXIT STATUS
1034 The following exit values are returned:
1036 .ne 2
1038 \fB\fB0\fR\fR
1040 .RS 6n
1041 Successful completion of the listing.
1045 .ne 2
1047 \fB\fB>0\fR\fR
1049 .RS 6n
1050 An error occurred.
1055 Otherwise, the exit status is that of the commands executed by \fBfc\fR or
1056 \fBhist\fR.
1057 .SH SEE ALSO
1059 \fBcsh\fR(1), \fBed\fR(1), \fBksh\fR(1), \fBksh93\fR(1), \fBset\fR(1),
1060 \fBsh\fR(1), \fBsource\fR(1), \fBattributes\fR(5),
1061 \fBenviron\fR(5)