HISTORY(1) | User Commands | HISTORY(1) |
history, fc, hist - process command history list
/usr/bin/fc [-r] [-e editor] [first [last]]
/usr/bin/fc -l [-nr] [first [last]]
/usr/bin/fc -s [old=new] [first]
history [-hr] [n]
fc -e - [old=new] [command]
fc -s [old = new] [command]
fc [-e ename] [-nlr] [first [last]]
hist [-lnprs] [-e editor][-N num][first[last]]
The fc utility lists or edits and reexecutes, commands previously entered to an interactive sh.
The command history list references commands by number. The first number in the list is selected arbitrarily. The relationship of a number to its command does not change except when the user logs in and no other process is accessing the list, at which time the system can reset the numbering to start the oldest retained command at another number (usually 1). When the number reaches the value in HISTSIZE or 32767 (whichever is greater), the shell can wrap the numbers, starting the next command with a lower number (usually 1). However, despite this optional wrapping of numbers, fc maintains the time-ordering sequence of the commands. For example, if four commands in sequence are given the numbers 32 766, 32 767, 1 (wrapped), and 2 as they are executed, command 32 767 is considered the command previous to 1, even though its number is higher.
When commands are edited (when the -l option is not specified), the resulting lines is entered at the end of the history list and then reexecuted by sh. The fc command that caused the editing is not entered into the history list. If the editor returns a non-zero exit status, this suppresses the entry into the history list and the command reexecution. Any command-line variable assignments or redirection operators used with fc affects both the fc command itself as well as the command that results, for example:
fc -s -- -1 2>/dev/null
reinvokes the previous command, suppressing standard error for both fc and the previous command.
Display the history list. If n is given, display only the n most recent events.
-r
-h
History substitution allows you to use words from previous command lines in the command line you are typing. This simplifies spelling corrections and the repetition of complicated commands or arguments. Command lines are saved in the history list, the size of which is controlled by the history variable. The history shell variable can be set to the maximum number of command lines that is saved in the history file, that is:
set history = 200
allows the history list to keep track of the most recent 200 command lines. If not set, the C shell saves only the most recent command.
A history substitution begins with a ! (although you can change this with the histchars variable) and can occur anywhere on the command line; history substitutions do not nest. The ! can be escaped with \ to suppress its special meaning.
Input lines containing history substitutions are echoed on the terminal after being expanded, but before any other substitutions take place or the command gets executed.
An event designator is a reference to a command line entry in the history list.
!
!!
!n
!-n
!str
!?str?
!?str? additional
!{command} additional
^previous_word^replacement^
Repeat the previous command line replacing the string previous_word with the string replacement. This is equivalent to the history substitution:
!:s/previous_word/replacement/.
To re-execute a specific previous command and make such a substitution, say, re-executing command #6:
!:6s/previous_word/replacement/.
A `:' (colon) separates the event specification from the word designator. 2It can be omitted if the word designator begins with a ^, $, *, − or %. If the word is to be selected from the previous command, the second ! character can be omitted from the event specification. For instance, !!:1 and !:1 both refer to the first word of the previous command, while !!$ and !$ both refer to the last word in the previous command. Word designators include:
#
0
n
^
$
%
x−y
*
x*
x−
After the optional word designator, you can add a sequence of one or more of the following modifiers, each preceded by a :.
h
r
e
s/oldchars/replacements/
^oldchars^replacements^
t
&
g
p
q
x
Unless preceded by a g, the modification is applied only to the first string that matches oldchars. An error results if no string matches.
The left-hand side of substitutions are not regular expressions, but character strings. Any character can be used as the delimiter in place of /. A backslash quotes the delimiter character. The character &, in the right hand side, is replaced by the text from the left-hand-side. The & can be quoted with a backslash. A null oldchars uses the previous string either from a oldchars or from a contextual scan string s from !?s. You can omit the rightmost delimiter if a newline immediately follows replacements; the rightmost ? in a context scan can similarly be omitted.
Without an event specification, a history reference refers either to the previous command, or to a previous history reference on the command line (if any).
Using fc, in the form of
fc -e − [old=new] [command],
or
fc -s [old=new] [command],
the command is re-executed after the substitution old=new is performed. If there is not a command argument, the most recent command typed at this terminal is executed.
Using fc in the form of
fc [-e ename] [-nlr ] [first [last]],
a range of commands from first to last is selected from the last HISTSIZE commands that were typed at the terminal. The arguments first and last can be specified as a number or as a string. A string is used to locate the most recent command starting with the given string. A negative number is used as an offset to the current command number. If the -l flag is selected, the commands are listed on standard output. Otherwise, the editor program -e name is invoked on a file containing these keyboard commands. If ename is not supplied, then the value of the variable FCEDIT (default /bin/ed) is used as the editor. When editing is complete, the edited command(s) is executed. If last is not specified, it is set to first. If first is not specified, the default is the previous command for editing and −16 for listing. The flag -r reverses the order of the commands and the flag -n suppresses command numbers when listing. (See ksh(1) for more about command line editing.)
HISTFILE
HISTSIZE
The text of the last HISTSIZE (default 128) commands entered from a terminal device is saved in a history file. The file $HOME/.sh_history is used if the HISTFILE variable is not set or if the file it names is not writable. A shell can access the commands of all interactive shells which use the same named HISTFILE. The special command fc is used to list or edit a portion of this file. The portion of the file to be edited or listed can be selected by number or by giving the first character or characters of the command. A single command or range of commands can be specified. If you do not specify an editor program as an argument to fc then the value of the variable FCEDIT is used. If FCEDIT is not defined then /bin/ed is used. The edited command(s) is printed and re-executed upon leaving the editor. The editor name − is used to skip the editing phase and to re-execute the command. In this case a substitution parameter of the form old=new can be used to modify the command before execution. For example, if r is aliased to a´fc -e − a´ then typing `r bad=good c' re-executes the most recent command which starts with the letter c, replacing the first occurrence of the string bad with the string good.
Using the fc built-in command within a compound command causes the whole command to disappear from the history file.
hist lists, edits, or re-executes commands previously entered into the current shell environment.
The command history list references commands by number. The first number in the list is selected arbitrarily. The relationship of a number to its command does not change during a login session. When the number reaches 32767 the number wraps around to 1 but maintains the ordering.
When the l option is not specified, and commands are edited, the resulting lines are entered at the end of the history list and then re-executed by the current shell. The hist command that caused the editing is not entered into the history list. If the editor returns a non-zero exit status, this suppresses the entry into the history list and the command re-execution. Command line variable assignments and redirections affect both the hist command and the commands that are re-executed.
first and last define the range of commands. Specify first and last as one of the following:
number
-number
string
If first is omitted, the previous command is used, unless -l is specified, in which case it defaults to -16 and last defaults to -1.
If first is specified and last is omitted, then last defaults to first unless -l is specified in which case it defaults to -1.
If no editor is specified, then the editor specified by the HISTEDIT variable is used if set, or the FCEDIT variable is used if set, otherwise, ed is used.
The following options are supported:
-e editor
-l
-n
-r
-s
ksh93 supports the following options:
-e editor
-l
-N num
-n
-p
-r
-s
The following operands are supported:
first
last
[+]number
−number
string
When the synopsis form with -s is used, if first is omitted, the previous command is used.
For the synopsis forms without -s :
fc -r 10 20 fc 30 40 fc 20 10 fc -r 40 30
fc -l fc 1 99
lists and edits, respectively, all ten commands.
old=new
When the -l option is used to list commands, the format of each command in the list is as follows:
"%d\t%s\n", <line number>, <command>
If both the -l and -n options are specified, the format of each command is:
"\t%s\n", <command>
If the commandcommand consists of more than one line, the lines after the first are displayed as:
"\t%s\n", <continued-command>
Example 1 Using history and fc
csh ksh % history $ fc -l
1 cd /etc 1 cd /etc
2 vi passwd 2 vi passwd
3 date 3 date
4 cd 4 cd
5 du . 5 du .
6 ls -t 6 ls -t
7 history 7 fc -l % !d $ fc -e - d
du . du .
262 ./SCCS 262 ./SCCS
336 . 336 . % !da $ fc -e - da
Thu Jul 21 17:29:56 PDT 1994 Thu Jul 21 17:29:56 PDT 1994 % $ alias \!='fc -e -' % !! $ !
date alias ='fc -e -'
Thu Jul 21 17:29:56 PDT 1994
See environ(7) for descriptions of the following environment variables that affect the execution of fc: LC_CTYPE, LC_MESSAGES, and NLSPATH.
FCEDIT
HISTFILE
HISTSIZE
The following exit values are returned:
0
>0
Otherwise, the exit status is that of the commands executed by fc or hist.
csh(1), ed(1), ksh(1), ksh93(1), set(1), sh(1), source(1), attributes(7), environ(7)
May 13, 2017 | OmniOS |