HISTORY(1CSH) COMMAND REFERENCE HISTORY(1CSH) NAME history - history substitution (csh built-in) SYNOPSIS history [ -h ] [ -r ] [ number ] DESCRIPTION The history command is used to print out previously executed commands in csh(1csh). With no arguments, the commands are printed preceded by history numbers. If a number argument is given, that many items are printed. By default, the value of the shell variable `history' is used. This document describes the csh history mechanism. History substitutions place words from previous command input as portions of new commands, making it easy to repeat commands, repeat arguments of a previous command in the current command, or fix spelling mistakes in the previous command with little typing and a high degree of confidence. History substitutions begin with the character ! and may begin anywhere in the input stream (with the provision that they do not nest.) This ! may be preceded by a backslash (\) to prevent its special meaning; for convenience, a ! is passed unchanged when it is followed by a blank, tab, newline, =, or (. (History substitutions also occur when an input line begins with ↑. This special abbreviation will be described later.) Any input line which contains history substitution is echoed on the terminal before it is executed, as it could have been typed without history substitution. Commands input from the terminal which consist of one or more words are saved on the history list. The history substitutions reintroduce sequences of words from these saved commands into the input stream. Their size is controlled by the history variable; the previous command is always retained, regardless of its value. Commands are numbered sequentially from 1. For example, consider the following output from the history command: 9 write michael 10 ex write.c 11 cat oldwrite.c 12 diff *write.c The commands are shown with their event numbers. It is not usually necessary to use event numbers, but the current event number can be made part of the prompt by placing an ! (or the current main history character) in the prompt string. Printed 4/6/89 1
HISTORY(1CSH) COMMAND REFERENCE HISTORY(1CSH) With the current event 13 you can refer to previous events by event number 11, relatively as in -2 (referring to the same event), by a prefix of a command word as in !d for event 12 or !wri for event 9, or by a string contained in a word in the command as in !?mic? also referring to event 9. These forms, without further modification, simply reintroduce the words of the specified events, each separated by a single blank. As a special case !! refers to the previous command; thus !! alone is essentially a redo. To select words from an event you can follow the event specification by a colon (:) and a designator for the desired words. The words of a input line are numbered from 0, the first word (usually command) being 0, the second word (first argument) being 1, and so forth. The basic word designators are: 0 first (command) word n n'th argument ↑ first argument; for example, 1 $ last argument % word matched by (immediately preceding) ?s? search x-y range of words -y abbreviates 0-y * abbreviates ↑-$, or nothing if only 1 word in event x* abbreviates x-$ x- like x* but omitting word $ The colon (:) separating the event specification from the word designator can be omitted if the argument selector begins with a ↑, $, * -, or %. After the optional word designator you can place a sequence of modifiers, each preceded by a colon. The following modifiers are defined: h Remove a trailing pathname component, leaving the head r Remove a trailing .xxx component, leaving the root name e Remove all but the extension .xxx part s/l/r/ Substitute l for r t Remove all leading pathname components, leaving the tail & Repeat the previous substitution g Apply the change globally, prefixing the above; (e.g.,g&.) p Print the new command but do not execute it q Quote the substituted words, preventing further substitutions x Like q, but break into words at blanks, tabs and newlines Unless preceded by a g the modification is applied only to the first modifiable word. With substitutions, it is an error for no word to be applicable. The left hand side of substitutions are not regular expressions in the sense of the editors, but rather strings. Any character may be used as the delimiter in place of /; a Printed 4/6/89 2
HISTORY(1CSH) COMMAND REFERENCE HISTORY(1CSH) backslash (\) quotes the delimiter into the l and r strings. The character & in the right hand side is replaced by the text from the left. A \ quotes & also. A null l uses the previous string either from a l or from a contextual scan string s in !?s?. The trailing delimiter in the substitution may be omitted if a newline follows immediately as may the trailing `?' in a contextual scan. A history reference may be given without an event specification; for example, !$. In this case the reference is to the previous command unless a previous history reference occurred on the same line, in which case this form repeats the previous reference. Thus !?foo?^ !$ gives the first and last arguments from the command matching ?foo?. A special abbreviation of a history reference occurs when the first non-blank character of an input line is a ↑. This is equivalent to !:s^ and provides a convenient shorthand for substitutions on the text of the previous line. Thus, ^lb^lib fixes the spelling of lib in the previous command. Finally, a history substitution can be surrounded with { and } if necessary to insulate it from the characters which follow. Thus, after ls -ld ~paul we might do !{l}a to do ls -ld ~paula, while !la would look for a command starting la. The shell variable `savehist' may be set to a number which specifies how many history items are to be saved when the user logs out. The next login will cause this list to be loaded into the history list. See the manual page for set(1csh) for more information. OPTIONS -h Display the history list without numbers. This can be used to produce files to use with the command source -h . -r Print the list in reverse order. Normally, the most recent commands are printed last. EXAMPLES The following example prints up to the last 20 elements of the history list without numbers. history -h 20 CAVEATS Before a command line is saved in the history list, it is broken up into words. This means that a command such as ``echo foo;bar'' is saved as ``echo foo ; bar'', so a subsitution such as ``^o;b^o:b^'' will fail. SEE ALSO @(1csh), alias(1csh), bg(1csh), break(1csh), cd(1csh), Printed 4/6/89 3
HISTORY(1CSH) COMMAND REFERENCE HISTORY(1CSH) chdir(1csh), continue(1csh), csh(1csh), dirs(1csh), echo(1csh), ed(1), eval(1csh), exec(1csh), exit(1csh), fg(1csh), glob(1csh), goto(1csh), hashstat(1csh), jobs(1csh), kill(1csh), limit(1csh), logout(1csh), nice(1csh), nohup(1csh), notify(1csh), onintr(1csh), popd(1csh), pushd(1csh), rehash(1csh), repeat(1csh), set(1csh), setenv(1csh), sh(1sh), shift(1csh), source(1csh), stop(1csh), suspend(1csh), time(1csh), umask(1csh), unhash(1csh), unalias(1csh), unlimit(1csh), unset(1csh), unsetenv(1csh), wait(1csh), and which(1csh). Printed 4/6/89 4
%%index%% na:384,127; sy:511,250; de:761,2607;3824,2895;7175,2353; op:9528,442; ex:9970,218; ca:10188,313; se:10501,209;11166,1343; %%index%%000000000155