Skip to content
Physics and Astronomy
Home Our Teaching Resources CDHW Electronics2 Userguide secE.html
Back to top

SPICE 3 User's Manual - Appendix E


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 most recent command is retained in any case. A history substitution begins with a ! and may occur anywhere on the command line; history substitutions do not nest.

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. The history list of previous commands can be printed using the interactive interpreter's history command.

Event Designators

An event designator is a reference to a command line entry in the history list.

Start a history substitution, except when followed by a space character, tab, newline, = or (.
Refer to the previous command. By itself, this substitution repeats the previous command.
Refer to command line n.
Refer to the current command line minus n.
Refer to the most recent command starting with str.
Refer to the most recent command containing str.
Refer to the most recent command containing str and append additional to that referenced command.
! {command}additional
Refer to the most recent command beginning with command and append additional to that referenced command.
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/.

Word Designators

A `:' (colon) separates the event specification from the word designator. It 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:

The entire command line typed so far.
The first input word (command).
The nth argument.
The first argument, that is, 1.
The last argument.
The word matched by (the most recent) ?s search.
A range of words; -y abbreviates 0-y.
All the arguments, or a null value if there is just one word in the event.
Abbreviates x-$.
Like x* but omitting word $.


After the optional word designator, you can add one of the following modifiers, preceded by a :.

Remove a trailing pathname component, leaving the head.
Remove a trailing suffix of the form `.xxx', leaving the basename.
Remove all but the suffix, leaving the Extension.
Substitute r for l.
Remove all leading pathname components, leaving the tail.
Repeat the previous substitution.
Apply the change to the first occurrence of a match in each word, by prefixing the above (for example, g&).
Print the new command but do not execute it.
Quote the substituted words, escaping further substitutions.
Like q, but break into words at each space character, tab or newline.

Unless preceded by a g, the modification is applied only to the first string that matches l; 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 l uses the previous string either from a l or from a contextual scan string s from !?s. You can omit the rightmost delimiter if a newline immediately follows r; 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).

Quick Substitution

This is equivalent to the history substitution: !:s/l/r/.

Validate   Link-check © Copyright & disclaimer Privacy & cookies Share
Back to top