Unleashed v1.4
[unleashed.git] / share / man / man1 / history.1
blob981781d18b854c0086842ac07390f68b86dc1d64
1 .\"
2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
6 .\"
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
9 .\" documentation.
10 .\"
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
13 .\"
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group.  In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document.  The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
24 .\"
25 .\" This notice shall appear on any product containing this material.
26 .\"
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
30 .\"
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
35 .\"
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
41 .\"
42 .\"
43 .\" Copyright 1989 AT&T
44 .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
45 .\" Portions Copyright (c) 1982-2007 AT&T Knowledge Ventures
46 .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved
47 .\"
48 .TH HISTORY 1 "May 13, 2017"
49 .SH NAME
50 history, fc, hist \- process command history list
51 .SH SYNOPSIS
52 .LP
53 .nf
54 \fB/usr/bin/fc\fR [\fB-r\fR] [\fB-e\fR \fIeditor\fR] [\fIfirst\fR [\fIlast\fR]]
55 .fi
57 .LP
58 .nf
59 \fB/usr/bin/fc\fR \fB-l\fR [\fB-nr\fR] [\fIfirst\fR [\fIlast\fR]]
60 .fi
62 .LP
63 .nf
64 \fB/usr/bin/fc\fR \fB-s\fR [\fIold\fR=\fInew\fR] [\fIfirst\fR]
65 .fi
67 .SS "csh"
68 .LP
69 .nf
70 \fBhistory\fR [\fB-hr\fR] [\fIn\fR]
71 .fi
73 .SS "ksh"
74 .LP
75 .nf
76 \fBfc\fR \fB-e\fR \fB-\fR [\fIold\fR=\fInew\fR] [\fIcommand\fR]
77 .fi
79 .LP
80 .nf
81 \fBfc\fR \fB-s\fR [\fIold\fR = \fInew\fR] [\fIcommand\fR]
82 .fi
84 .LP
85 .nf
86 \fBfc\fR [\fB-e\fR \fIename\fR] [\fB-nlr\fR] [\fIfirst\fR [\fIlast\fR]]
87 .fi
89 .SS "ksh93"
90 .LP
91 .nf
92 \fBhist\fR [\fB-lnprs\fR] [\fB-e\fR \fIeditor\fR][\fB-N\fR \fInum\fR][\fIfirst\fR[\fIlast\fR]]
93 .fi
95 .SH DESCRIPTION
96 .SS "/usr/bin/fc"
97 .LP
98 The \fBfc\fR utility lists or edits and reexecutes, commands previously entered
99 to an interactive \fBsh\fR.
102 The command history list references commands by number. The first number in the
103 list is selected arbitrarily. The relationship of a number to its command does
104 not change except when the user logs in and no other process is accessing the
105 list, at which time the system can reset the numbering to start the oldest
106 retained command at another number (usually 1). When the number reaches the
107 value in \fBHISTSIZE\fR or \fB32767\fR (whichever is greater), the shell can
108 wrap the numbers, starting the next command with a lower number (usually 1).
109 However, despite this optional wrapping of numbers, \fBfc\fR maintains the
110 time-ordering sequence of the commands. For example, if four commands in
111 sequence are given the numbers 32 766, 32 767, 1 (wrapped), and 2 as they are
112 executed, command 32 767 is considered the command previous to 1, even though
113 its number is higher.
116 When commands are edited (when the \fB-l\fR option is not specified), the
117 resulting lines is entered at the end of the history list and then reexecuted
118 by \fBsh\fR. The \fBfc\fR command that caused the editing is not entered into
119 the history list. If the editor returns a non-zero exit status, this suppresses
120 the entry into the history list and the command reexecution. Any command-line
121 variable assignments or redirection operators used with \fBfc\fR affects both
122 the \fBfc\fR command itself as well as the command that results, for example:
124 .in +2
126 \fBfc -s -- -1 2>/dev/null\fR
128 .in -2
133 reinvokes the previous command, suppressing standard error for both \fBfc\fR
134 and the previous command.
135 .SS "csh"
137 Display the history list. If \fIn\fR is given, display only the \fIn\fR most
138 recent events.
140 .ne 2
142 \fB\fB-r\fR\fR
144 .RS 6n
145 Reverse the order of printout to be most recent first rather than oldest first.
149 .ne 2
151 \fB\fB-h\fR\fR
153 .RS 6n
154 Display the history list without leading numbers. This is used to produce files
155 suitable for sourcing using the \fB-h\fR option to the \fBcsh\fR built-in
156 command, \fBsource\fR(1).
159 .SS "History Substitution:"
161 History substitution allows you to use words from previous command lines in the
162 command line you are typing. This simplifies spelling corrections and the
163 repetition of complicated commands or arguments. Command lines are saved in the
164 history list, the size of which is controlled by the \fBhistory\fR variable.
165 The \fBhistory\fR shell variable can be set to the maximum number of command
166 lines that is saved in the history file, that is:
168 .in +2
170 set history = 200
172 .in -2
176 allows the history list to keep track of the most recent 200 command lines. If
177 not set, the C shell saves only the most recent command.
180 A history substitution begins with a \fB!\fR (although you can change this with
181 the \fBhistchars\fR variable) and can occur anywhere on the command line;
182 history substitutions do not nest. The \fB!\fR can be escaped with \fB\e\fR to
183 suppress its special meaning.
186 Input lines containing history substitutions are echoed on the terminal after
187 being expanded, but before any other substitutions take place or the command
188 gets executed.
189 .SS "Event Designators:"
191 An event designator is a reference to a command line entry in the history list.
193 .ne 2
195 \fB\fB!\fR\fR
197 .sp .6
198 .RS 4n
199 Start a history substitution, except when followed by a space character, tab,
200 newline, \fB=\fR or \fB(\fR.
204 .ne 2
206 \fB\fB!!\fR\fR
208 .sp .6
209 .RS 4n
210 Refer to the previous command. By itself, this substitution repeats the
211 previous command.
215 .ne 2
217 \fB\fB!\fR\fIn\fR\fR
219 .sp .6
220 .RS 4n
221 Refer to command line \fIn\fR.
225 .ne 2
227 \fB\fB!\fR\fB-n\fR\fR
229 .sp .6
230 .RS 4n
231 Refer to the current command line minus \fIn\fR.
235 .ne 2
237 \fB\fB!\fR\fIstr\fR\fR
239 .sp .6
240 .RS 4n
241 Refer to the most recent command starting with \fIstr\fR.
245 .ne 2
247 \fB\fB!?\fR\fIstr\fR\fB?\fR\fR
249 .sp .6
250 .RS 4n
251 Refer to the most recent command containing \fIstr\fR.
255 .ne 2
257 \fB\fB!?\fR\fIstr\fR\fB?\fR \fIadditional\fR\fR
259 .sp .6
260 .RS 4n
261 Refer to the most recent command containing \fIstr\fR and append
262 \fIadditional\fR to that referenced command.
266 .ne 2
268 \fB\fB!{\fR\fBcommand\fR\fB}\fR \fIadditional\fR\fR
270 .sp .6
271 .RS 4n
272 Refer to the most recent command beginning with \fBcommand\fR and append
273 \fIadditional\fR to that referenced command.
277 .ne 2
279 \fB\fB^\fR\fIprevious_word\fR\fB^\fR\fIreplacement\fR\fB^\fR\fR
281 .sp .6
282 .RS 4n
283 Repeat the previous command line replacing the string \fIprevious_word\fR with
284 the string \fIreplacement\fR. This is equivalent to the history substitution:
286 Repeat the previous command line replacing the string \fIprevious_word\fR with
287 the string \fIreplacement\fR. This is equivalent to the history substitution:
289 .in +2
291 \fB!:s/\fR\fIprevious_word\fR\fB/\fR\fIreplacement\fR\fB/\fR.
293 .in -2
295 To re-execute a specific previous command \fBand\fR make such a substitution,
296 say, re-executing command #6:
298 .in +2
300 \fB!:6s/\fR\fIprevious_word\fR\fB/\fR\fIreplacement\fR\fB/\fR.
302 .in -2
306 .SS "Word Designators:"
308 A `\fB:\fR' (colon) separates the event specification from the word designator.
309 2It can be omitted if the word designator begins with a \fB^\fR, \fB$\fR,
310 \fB*\fR, \fB\(mi\fR or \fB%\fR. If the word is to be selected from the previous
311 command, the second \fB!\fR character can be omitted from the event
312 specification. For instance, \fB!!:1\fR and \fB!:1\fR both refer to the first
313 word of the previous command, while \fB!!$\fR and \fB!$\fR both refer to the
314 last word in the previous command. Word designators include:
316 .ne 2
318 \fB\fB#\fR\fR
320 .RS 10n
321 The entire command line typed so far.
325 .ne 2
327 \fB\fB0\fR\fR
329 .RS 10n
330 The first input word (command).
334 .ne 2
336 \fB\fIn\fR\fR
338 .RS 10n
339 The \fIn\fR'th argument.
343 .ne 2
345 \fB\fB^\fR\fR
347 .RS 10n
348 The first argument, that is, \fB1\fR.
352 .ne 2
354 \fB\fB$\fR\fR
356 .RS 10n
357 The last argument.
361 .ne 2
363 \fB\fB%\fR\fR
365 .RS 10n
366 The word matched by (the most recent) \fB?\fR\fIs\fR search.
370 .ne 2
372 \fB\fIx\fR\fB\(mi\fR\fIy\fR\fR
374 .RS 10n
375 A range of words; \fB\(mi\fR\fIy\fR abbreviates \fB0\(mi\fR\fIy\fR.
379 .ne 2
381 \fB\fB*\fR\fR
383 .RS 10n
384 All the arguments, or a null value if there is just one word in the event.
388 .ne 2
390 \fB\fIx\fR\fB*\fR\fR
392 .RS 10n
393 Abbreviates \fIx\fR\fB\(mi$\fR\fI\&.\fR
397 .ne 2
399 \fB\fIx\fR\fB\(mi\fR\fR
401 .RS 10n
402 Like \fIx\fR\fB*\fR but omitting word \fB$\fR.
405 .SS "Modifiers:"
407 After the optional word designator, you can add a sequence of one or more of
408 the following modifiers, each preceded by a \fB:\fR.
410 .ne 2
412 \fB\fBh\fR\fR
414 .RS 28n
415 Remove a trailing pathname component, leaving the head.
419 .ne 2
421 \fB\fBr\fR\fR
423 .RS 28n
424 Remove a trailing suffix of the form `\fB\&.\fR\fIxxx\fR', leaving the
425 basename.
429 .ne 2
431 \fB\fBe\fR\fR
433 .RS 28n
434 Remove all but the suffix, leaving the extension.
438 .ne 2
440 \fB\fBs/\fR\fIoldchars\fR\fB/\fR\fIreplacements\fR\fB/\fR\fR
442 .RS 28n
443 Substitute \fIreplacements\fR for \fIoldchars\fR. \fIoldchars\fR is a string
444 that can contain embedded blank spaces, whereas \fIprevious_word\fR in the
445 event designator can not.
447 .in +2
449 \fB^\fR\fIoldchars\fR\fB^\fR\fIreplacements\fR\fB^\fR
451 .in -2
456 .ne 2
458 \fB\fBt\fR\fR
460 .RS 28n
461 Remove all leading pathname components, leaving the tail.
465 .ne 2
467 \fB\fB&\fR\fR
469 .RS 28n
470 Repeat the previous substitution.
474 .ne 2
476 \fB\fBg\fR\fR
478 .RS 28n
479 Apply the change to the first occurrence of a match in each word, by prefixing
480 the above (for example, \fBg&\fR).
484 .ne 2
486 \fB\fBp\fR\fR
488 .RS 28n
489 Print the new command but do not execute it.
493 .ne 2
495 \fB\fBq\fR\fR
497 .RS 28n
498 Quote the substituted words, escaping further substitutions.
502 .ne 2
504 \fB\fBx\fR\fR
506 .RS 28n
507 Like \fBq\fR, but break into words at each space character, tab or newline.
512 Unless preceded by a \fBg\fR, the modification is applied only to the first
513 string that matches \fIoldchars\fR. An error results if no string matches.
516 The left-hand side of substitutions are not regular expressions, but character
517 strings. Any character can be used as the delimiter in place of \fB/\fR. A
518 backslash quotes the delimiter character. The character \fB&\fR, in the right
519 hand side, is replaced by the text from the left-hand-side. The \fB&\fR can be
520 quoted with a backslash. A null \fIoldchars\fR uses the previous string either
521 from a \fIoldchars\fR or from a contextual scan string \fIs\fR from
522 \fB!?\fR\fIs\fR. You can omit the rightmost delimiter if a newline immediately
523 follows \fIreplacements\fR; the rightmost \fB?\fR in a context scan can
524 similarly be omitted.
527 Without an event specification, a history reference refers either to the
528 previous command, or to a previous history reference on the command line (if
529 any).
530 .SS "ksh"
532 Using \fBfc\fR, in the form of
534 .in +2
536 \fBfc -e \(mi [\fIold\fR=\fInew\fR] [\fIcommand\fR],\fR
538 .in -2
545 .in +2
547 \fBfc -s [\fIold\fR=\fInew\fR] [\fIcommand\fR],\fR
549 .in -2
554 the \fIcommand\fR is re-executed after the substitution
555 \fIold\fR\fB=\fR\fInew\fR is performed. If there is not a \fIcommand\fR
556 argument, the most recent command typed at this terminal is executed.
559 Using \fBfc\fR in the form of
561 .in +2
563 \fBfc [-e \fIename\fR] [-nlr ] [\fIfirst\fR [\fIlast\fR]],\fR
565 .in -2
570 a range of commands from \fIfirst\fR to \fIlast\fR is selected from the last
571 \fBHISTSIZE\fR commands that were typed at the terminal. The arguments
572 \fIfirst\fR and \fIlast\fR can be specified as a number or as a string. A
573 string is used to locate the most recent command starting with the given
574 string. A negative number is used as an offset to the current command number.
575 If the \fB-l\fR flag is selected, the commands are listed on standard output.
576 Otherwise, the editor program \fB-e\fR \fIname\fR is invoked on a file
577 containing these keyboard commands. If \fIename\fR is not supplied, then the
578 value of the variable \fBFCEDIT\fR (default \fB/bin/ed\fR) is used as the
579 editor. When editing is complete, the edited command(s) is executed. If
580 \fBlast\fR is not specified, it is set to \fIfirst\fR. If \fIfirst\fR is not
581 specified, the default is the previous command for editing and \(mi16 for
582 listing. The flag \fB-r\fR reverses the order of the commands and the flag
583 \fB-n\fR suppresses command numbers when listing. (See \fBksh\fR(1) for more
584 about command line editing.)
586 .ne 2
588 \fB\fBHISTFILE\fR\fR
590 .RS 12n
591 If this variable is set when the shell is invoked, then the value is the
592 pathname of the file that is used to store the command history.
596 .ne 2
598 \fB\fBHISTSIZE\fR\fR
600 .RS 12n
601 If this variable is set when the shell is invoked, then the number of
602 previously entered commands that are accessible by this shell is greater than
603 or equal to this number. The default is \fB128\fR.
606 .SS "Command Re-entry:"
608 The text of the last \fBHISTSIZE\fR (default 128) commands entered from a
609 terminal device is saved in a \fBhistory\fR file. The file
610 \fB$HOME/.sh_history\fR is used if the \fBHISTFILE\fR variable is not set or if
611 the file it names is not writable. A shell can access the commands of all
612 \fIinteractive\fR shells which use the same named \fBHISTFILE\fR. The special
613 command \fBfc\fR is used to list or edit a portion of this file. The portion of
614 the file to be edited or listed can be selected by number or by giving the
615 first character or characters of the command. A single command or range of
616 commands can be specified. If you do not specify an editor program as an
617 argument to \fBfc\fR then the value of the variable \fBFCEDIT\fR is used. If
618 \fBFCEDIT\fR is not defined then \fB/bin/ed\fR is used. The edited command(s)
619 is printed and re-executed upon leaving the editor. The editor name \fB\(mi\fR
620 is used to skip the editing phase and to re-execute the command. In this case a
621 substitution parameter of the form \fIold\fR\fB=\fR\fInew\fR can be used to
622 modify the command before execution. For example, if \fBr\fR is aliased to
623 \fBa\'fc\fR \fB-e\fR \fB\(mi a\'\fR then typing \fB`r\fR \fBbad=good\fR
624 \fBc'\fR re-executes the most recent command which starts with the letter
625 \fBc\fR, replacing the first occurrence of the string \fBbad\fR with the string
626 \fBgood\fR.
629 Using the \fBfc\fR built-in command within a compound command causes the whole
630 command to disappear from the history file.
631 .SS "ksh93"
633 \fBhist\fR lists, edits, or re-executes commands previously entered into the
634 current shell environment.
637 The command history list references commands by number. The first number in the
638 list is selected arbitrarily. The relationship of a number to its command does
639 not change during a login session. When the number reaches \fB32767\fR the
640 number wraps around to \fB1\fR but maintains the ordering.
643 When the \fBl\fR option is not specified, and commands are edited, the
644 resulting lines are entered at the end of the history list and then re-executed
645 by the current shell. The \fBhist\fR command that caused the editing is not
646 entered into the history list. If the editor returns a \fBnon-zero\fR exit
647 status, this suppresses the entry into the history list and the command
648 re-execution. Command line variable assignments and redirections affect both
649 the \fBhist\fR command and the commands that are re-executed.
652 \fIfirst\fR and \fIlast\fR define the range of commands. Specify \fIfirst\fR
653 and \fIlast\fR as one of the following:
655 .ne 2
657 \fB\fInumber\fR\fR
659 .RS 11n
660 A positive number representing a command number. A \fB+\fR sign can precede
661 \fInumber\fR.
665 .ne 2
667 \fB\fB-\fR\fInumber\fR\fR
669 .RS 11n
670 A negative number representing a command that was executed \fInumber\fR
671 commands previously. For example, \fB-1\fR is the previous command.
675 .ne 2
677 \fB\fIstring\fR\fR
679 .RS 11n
680 \fIstring\fR indicates the most recently entered command that begins with
681 \fIstring\fR. \fIstring\fR should not contain an \fB=\fR.
686 If \fIfirst\fR is omitted, the previous command is used, unless \fB-l\fR is
687 specified, in which case it defaults to \fB-16\fR and last defaults to
688 \fB-1\fR.
691 If \fIfirst\fR is specified and \fIlast\fR is omitted, then \fIlast\fR defaults
692 to \fIfirst\fR unless \fB-l\fR is specified in which case it defaults to
693 \fB-1\fR.
696 If no editor is specified, then the editor specified by the \fBHISTEDIT\fR
697 variable is used if set, or the \fBFCEDIT\fR variable is used if set,
698 otherwise, \fBed\fR is used.
699 .SH OPTIONS
701 The following options are supported:
703 .ne 2
705 \fB\fB\fR\fB-e\fR \fIeditor\fR\fR
707 .RS 13n
708 Uses the editor named by \fIeditor\fR to edit the commands. The \fIeditor\fR
709 string is a utility name, subject to search via the \fBPATH\fR variable. The
710 value in the \fBFCEDIT\fR variable is used as a default when \fB-e\fR is not
711 specified. If \fBFCEDIT\fR is null or unset, \fBed\fR is used as the editor.
715 .ne 2
717 \fB\fB-l\fR\fR
719 .RS 13n
720 (The letter ell.) Lists the commands rather than invoking an editor on them.
721 The commands is written in the sequence indicated by the \fIfirst\fR and
722 \fIlast\fR operands, as affected by \fB-r\fR, with each command preceded by the
723 command number.
727 .ne 2
729 \fB\fB-n\fR\fR
731 .RS 13n
732 Suppresses command numbers when listing with \fB-l\fR.
736 .ne 2
738 \fB\fB-r\fR\fR
740 .RS 13n
741 Reverses the order of the commands listed (with \fB-l\fR \fB)\fR or edited
742 (with neither \fB-l\fR nor \fB-s\fR).
746 .ne 2
748 \fB\fB-s\fR\fR
750 .RS 13n
751 Re-executes the command without invoking an editor.
754 .SS "ksh93"
756 \fBksh93\fR supports the following options:
758 .ne 2
760 \fB\fB-e\fR \fIeditor\fR\fR
762 .RS 13n
763 Specify the editor to use to edit the history command. A value of \fB-\fR for
764 \fIeditor\fR is equivalent to specifying the \fB-s\fR option.
768 .ne 2
770 \fB\fB-l\fR\fR
772 .RS 13n
773 List the commands rather than editing and re-executing them.
777 .ne 2
779 \fB\fB-N\fR \fInum\fR\fR
781 .RS 13n
782 Start at \fInum\fR commands back.
786 .ne 2
788 \fB\fB-n\fR\fR
790 .RS 13n
791 Suppress the command numbers when the commands are listed.
795 .ne 2
797 \fB\fB-p\fR\fR
799 .RS 13n
800 Write the result of history expansion for each operand to standard output. All
801 other options are ignored.
805 .ne 2
807 \fB\fB-r\fR\fR
809 .RS 13n
810 Reverse the order of the commands.
814 .ne 2
816 \fB\fB-s\fR\fR
818 .RS 13n
819 Re-execute the command without invoking an editor. In this case an operand of
820 the form \fIold=new\fR can be specified to change the first occurrence of the
821 string \fIold\fR in the command to \fInew\fR before re-executing the command.
824 .SH OPERANDS
826 The following operands are supported:
828 .ne 2
830 \fB\fIfirst\fR\fR
834 \fB\fIlast\fR\fR
836 .RS 9n
837 Selects the commands to list or edit. The number of previous commands that can
838 be accessed is determined by the value of the \fBHISTSIZE\fR variable. The
839 value of \fIfirst\fR or \fIlast\fR or both is one of the following:
841 .ne 2
843 \fB[\fB+\fR]\fInumber\fR\fR
845 .RS 14n
846 A positive number representing a command number. Command numbers can be
847 displayed with the \fB-l\fR option.
851 .ne 2
853 \fB\fB\(mi\fR\fInumber\fR\fR
855 .RS 14n
856 A negative decimal number representing the command that was executed
857 \fInumber\fR of commands previously. For example, \fB\(mi1\fR is the
858 immediately previous command.
862 .ne 2
864 \fB\fIstring\fR\fR
866 .RS 14n
867 A string indicating the most recently entered command that begins with that
868 string. If the \fIold=new\fR operand is not also specified with \fB-s\fR, the
869 string form of the \fIfirst\fR operand cannot contain an embedded equal sign.
871 When the synopsis form with \fB-s\fR is used, if \fIfirst\fR is omitted, the
872 previous command is used.
874 For the synopsis forms without \fB-s\fR \fB:\fR
875 .RS +4
877 .ie t \(bu
878 .el o
879 If \fIlast\fR is omitted, \fIlast\fR defaults to the previous command when
880 \fB-l\fR is specified; otherwise, it defaults to \fIfirst\fR.
882 .RS +4
884 .ie t \(bu
885 .el o
886 If \fIfirst\fR and \fIlast\fR are both omitted, the previous 16 commands is
887 listed or the previous single command is edited (based on the \fB-l\fR option).
889 .RS +4
891 .ie t \(bu
892 .el o
893 If \fIfirst\fR and \fIlast\fR are both present, all of the commands from
894 \fIfirst\fR to \fIlast\fR is edited (without \fB-l\fR \fB)\fR or listed (with
895 \fB-l\fR). Editing multiple commands is accomplished by presenting to the
896 editor all of the commands at one time, each command starting on a new line. If
897 \fIfirst\fR represents a newer command than \fIlast\fR, the commands is listed
898 or edited in reverse sequence, equivalent to using \fB-r\fR. For example, the
899 following commands on the first line are equivalent to the corresponding
900 commands on the second:
902 .in +2
904 fc -r 10 20     fc    30 40
905 fc   20 10      fc -r 40 30
907 .in -2
910 .RS +4
912 .ie t \(bu
913 .el o
914 When a range of commands is used, it is not be an error to specify \fIfirst\fR
915 or \fIlast\fR values that are not in the history list. \fBfc\fR substitutes the
916 value representing the oldest or newest command in the list, as appropriate.
917 For example, if there are only ten commands in the history list, numbered 1 to
920 .in +2
922 fc -l
923 fc 1 99
925 .in -2
927 lists and edits, respectively, all ten commands.
932 .ne 2
934 \fB\fIold=new\fR\fR
936 .RS 14n
937 Replace the first occurrence of string \fIold\fR in the commands to be
938 reexecuted by the string \fInew\fR.
943 .SH OUTPUT
945 When the \fB-l\fR option is used to list commands, the format of each command
946 in the list is as follows:
948 .in +2
950 \fB"%d\et%s\en", <\fR\fIline number\fR\fB>, <\fR\fIcommand\fR\fB>\fR
952 .in -2
956 If both the \fB-l\fR and \fB-n\fR options are specified, the format of each
957 command is:
959 .in +2
961 \fB"\et%s\en", <\fR\fIcommand\fR\fB>\fR
963 .in -2
967 If the \fIcommand\fR\fIcommand\fR consists of more than one line, the lines
968 after the first are displayed as:
970 .in +2
972 \fB"\et%s\en", <\fR\fIcontinued-command\fR\fB>\fR
974 .in -2
976 .SH EXAMPLES
978 \fBExample 1 \fRUsing history and fc
980 .in +2
982              csh                                     ksh
984 % history                               $ fc -l
985   1   cd /etc                             1   cd /etc
986   2   vi passwd                           2   vi passwd
987   3   date                                3   date
988   4   cd                                  4   cd
989   5   du .                                5   du .
990   6   ls -t                               6   ls -t
991   7   history                             7   fc -l
993 % !d                                    $ fc -e - d
994   du .                                    du .
995   262   ./SCCS                            262   ./SCCS
996   336   .                                 336   .
998 % !da                                   $ fc -e - da
999   Thu Jul 21 17:29:56 PDT 1994            Thu Jul 21 17:29:56 PDT 1994
1001 %                                       $ alias \e!='fc -e -'
1003 % !!                                    $ !
1004   date                                    alias ='fc -e -'
1005   Thu Jul 21 17:29:56 PDT 1994
1007 .in -2
1009 .SH ENVIRONMENT VARIABLES
1011 See \fBenviron\fR(5) for descriptions of the following environment variables
1012 that affect the execution of \fBfc\fR: \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and
1013 \fBNLSPATH\fR.
1015 .ne 2
1017 \fB\fBFCEDIT\fR\fR
1019 .RS 12n
1020 This variable, when expanded by the shell, determines the default value for the
1021 \fB-e\fR \fIeditor\fR option's \fIeditor\fR option-argument. If \fBFCEDIT\fR is
1022 null or unset, \fBed\fR(1) is used as the editor.
1026 .ne 2
1028 \fB\fBHISTFILE\fR\fR
1030 .RS 12n
1031 Determine a pathname naming a command history file. If the \fBHISTFILE\fR
1032 variable is not set, the shell can attempt to access or create a file
1033 \fB\&.sh_history\fR in the user's home directory. If the shell cannot obtain
1034 both read and write access to, or create, the history file, it uses an
1035 unspecified mechanism that allows the history to operate properly. (References
1036 to history ``file'' in this section are understood to mean this unspecified
1037 mechanism in such cases.) \fBfc\fR can choose to access this variable only when
1038 initializing the history file; this initialization occurs when \fBfc\fR or
1039 \fBsh\fR first attempt to retrieve entries from, or add entries to, the file,
1040 as the result of commands issued by the user, the file named by the \fBENV\fR
1041 variable, or a system startup file such as \fB/etc/profile\fR. (The
1042 initialization process for the history file can be dependent on the system
1043 startup files, in that they can contain commands that effectively preempts the
1044 user's settings of \fBHISTFILE\fR and \fBHISTSIZE\fR. For example, function
1045 definition commands are recorded in the history file, unless the \fBset\fR
1046 \fB-o\fR \fBnolog\fR option is set. If the system administrator includes
1047 function definitions in some system startup file called before the \fBENV\fR
1048 file, the history file is initialized before the user gets a chance to
1049 influence its characteristics.) The variable \fBHISTFILE\fR is accessed
1050 initially when the shell is invoked. Any change to \fBHISTFILE\fR does not
1051 take effect until another shell is invoked.
1055 .ne 2
1057 \fB\fBHISTSIZE\fR\fR
1059 .RS 12n
1060 Determine a decimal number representing the limit to the number of previous
1061 commands that are accessible. If this variable is unset, an unspecified default
1062 greater than or equal to 128 are used. The variable \fBHISTSIZE\fR is accessed
1063 initially when the shell is invoked. Any changes to \fBHISTSIZE\fR does not
1064 take effect until another shell is invoked.
1067 .SH EXIT STATUS
1069 The following exit values are returned:
1071 .ne 2
1073 \fB\fB0\fR\fR
1075 .RS 6n
1076 Successful completion of the listing.
1080 .ne 2
1082 \fB\fB>0\fR\fR
1084 .RS 6n
1085 An error occurred.
1090 Otherwise, the exit status is that of the commands executed by \fBfc\fR or
1091 \fBhist\fR.
1092 .SH SEE ALSO
1094 \fBcsh\fR(1), \fBed\fR(1), \fBksh\fR(1), \fBksh93\fR(1), \fBset\fR(1),
1095 \fBsh\fR(1), \fBsource\fR(1), \fBattributes\fR(5),
1096 \fBenviron\fR(5)