[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13. Expansion

The following types of expansions are performed in the indicated order in five steps:

History Expansion
This is performed only in interactive shells.

Alias Expansion
Aliases are expanded immediately before the command line is parsed as explained in 5.7 Aliasing.

Process Substitution
Parameter Expansion
Command Substitution
Arithmetic Expansion
Brace Expansion
These five are performed in one step in left-to-right fashion. After these expansions, all unquoted occurrences of the characters `\', `'' and `"' are removed.

Filename Expansion
If the SH_FILE_EXPANSION option is set, the order of expansion is modified for compatibility with sh and ksh. In that case filename expansion is performed immediately after alias expansion, preceding the set of five expansions mentioned above.

Filename Generation
This expansion, commonly referred to as globbing, is always done last.

The following sections explain the types of expansion in detail.

13.1 History Expansion  
13.2 Process Substitution  
13.3 Parameter Expansion  
13.4 Command Substitution  
13.5 Arithmetic Expansion  
13.6 Brace Expansion  
13.7 Filename Expansion  
13.8 Filename Generation  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1 History Expansion

History expansion 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. Immediately before execution, each command is saved in the history list, the size of which is controlled by the HISTSIZE parameter. The one most recent command is always retained in any case. Each saved command in the history list is called a history event and is assigned a number, beginning with 1 (one) when the shell starts up. The history number that you may see in your prompt (see 12. Prompt Expansion) is the number that is to be assigned to the next command.

13.1.1 Overview  
13.1.2 Event Designators  
13.1.3 Word Designators  
13.1.4 Modifiers  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.1 Overview

A history expansion begins with the first character of the histchars parameter, which is `!' by default, and may occur anywhere on the command line; history expansions do not nest. The `!' can be escaped with `\' or can be enclosed between a pair of single quotes (") to suppress its special meaning. Double quotes will not work for this. Following this history character is an optional event designator (13.1.2 Event Designators) and then an optional word designator (13.1.3 Word Designators); if neither of these designators is present, no history expansion occurs.

Input lines containing history expansions are echoed after being expanded, but before any other expansions take place and before the command is executed. It is this expanded form that is recorded as the history event for later references.

By default, a history reference with no event designator refers to the same event as any preceding history reference on that command line; if it is the only history reference in a command, it refers to the previous command. However, if the option CSH_JUNKIE_HISTORY is set, then every history reference with no event specification always refers to the previous command.

For example, `!' is the event designator for the previous command, so `!!:1' always refers to the first word of the previous command, and `!!$' always refers to the last word of the previous command. With CSH_JUNKIE_HISTORY set, then `!:1' and `!$' function in the same manner as `!!:1' and `!!$', respectively. Conversely, if CSH_JUNKIE_HISTORY is unset, then `!:1' and `!$' refer to the first and last words, respectively, of the same event referenced by the nearest other history reference preceding them on the current command line, or to the previous command if there is no preceding reference.

The character sequence `^foo^bar' (where `^' is actually the second character of the histchars parameter) repeats the last command, replacing the string foo with bar. More precisely, the sequence `^foo^bar^' is synonymous with `!!:s^foo^bar^', hence other modifiers (see 13.1.4 Modifiers) may follow the final `^'.

If the shell encounters the character sequence `!"' in the input, the history mechanism is temporarily disabled until the current list (see 5. Shell Grammar) is fully parsed. The `!"' is removed from the input, and any subsequent `!' characters have no special significance.

A less convenient but more comprehensible form of command history support is provided by the fc builtin.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.2 Event Designators

An event designator is a reference to a command-line entry in the history list. In the list below, remember that the initial `!' in each item may be changed to another character by setting the histchars parameter.

!
Start a history expansion, except when followed by a blank, newline, `=' or `('. If followed immediately by a word designator (13.1.3 Word Designators), this forms a history reference with no event designator (13.1.1 Overview).

!!
Refer to the previous command. By itself, this expansion repeats the previous command.

!n
Refer to command-line n.

!-n
Refer to the current command-line minus n.

!str
Refer to the most recent command starting with str.

!?str[?]
Refer to the most recent command containing str. The trailing `?' is necessary if this reference is to be followed by a modifier or followed by any text that is not to be considered part of str.

!#
Refer to the current command line typed in so far. The line is treated as if it were complete up to and including the word before the one with the `!#' reference.

!{...}
Insulate a history reference from adjacent characters (if necessary).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.3 Word Designators

A word designator indicates which word or words of a given command line are to be included in a history reference. A `:' usually separates the event specification from the word designator. It may be omitted only if the word designator begins with a `^', `$', `*', `-' or `%'. Word designators include:

0
The first input word (command).
n
The nth argument.
^
The first argument. That is, 1.
$
The last argument.
%
The word matched by (the most recent) ?str search.
x-y
A range of words; x defaults to 0.
*
All the arguments, or a null value if there are none.
x*
Abbreviates `x-$'.
x-
Like `x*' but omitting word $.

Note that a `%' word designator works only when used in one of `!%', `!:%' or `!?str?:%', and only when used after a !? expansion (possibly in an earlier command). Anything else results in an error, although the error may not be the most obvious one.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.4 Modifiers

After the optional word designator, you can add a sequence of one or more of the following modifiers, each preceded by a `:'. These modifiers also work on the result of filename generation and parameter expansion, except where noted.

h
Remove a trailing pathname component, leaving the head. This works like `dirname'.

r
Remove a filename extension of the form `.xxx', leaving the root name.

e
Remove all but the extension.

t
Remove all leading pathname components, leaving the tail. This works like `basename'.

p
Print the new command but do not execute it. Only works with history expansion.

q
Quote the substituted words, escaping further substitutions. Works with history expansion and parameter expansion, though for parameters it is only useful if the resulting text is to be re-evaluated such as by eval.

Q
Remove one level of quotes from the substituted words.

x
Like q, but break into words at whitespace. Does not work with parameter expansion.

l
Convert the words to all lowercase.

u
Convert the words to all uppercase.

s/l/r[/]
Substitute r for l>' characters have no special significance.

A less convenient but more comprehensible form of command history support is provided by the fc builtin.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.2 Event Designators

An event designator is a reference to a command-line entry in the history list. In the list below, remember that the initial `!' in each item may be changed to another character by setting the histchars parameter.

!
Start a history expansion, except when followed by a blank, newline, `=' or `('. If followed immediately by a word designator (13.1.3 Word Designators), this forms a history reference with no event designator (13.1.1 Overview).

!!
Refer to the previous command. By itself, this expansion repeats the previous command.

!n
Refer to command-line n.

!-n
Refer to the current command-line minus n.

!str
Refer to the most recent command starting with str.

!?str[?]
Refer to the most recent command containing str. The trailing `?' is necessary if this reference is to be followed by a modifier or followed by any text that is not to be considered part of str.

!#
Refer to the current command line typed in so far. The line is treated as if it were complete up to and including the word before the one with the `!#' reference.

!{...}
Insulate a history reference from adjacent characters (if necessary).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.3 Word Designators

A word designator indicates which word or words of a given command line are to be included in a history reference. A `:' usually separates the event specification from the word designator. It may be omitted only if the word designator begins with a `^', `$', `*', `-' or `%'. Word designators include:

0
The first input word (command).
n
The nth argument.
^
The first argument. That is, 1.
$
The last argument.
%
The word matched by (the most recent) ?str search.
x-y
A range of words; x defaults to 0.
*
All the arguments, or a null value if there are none.
x*
Abbreviates `x-$'.
x-
Like `x*' but omitting word $.

Note that a `%' word designator works only when used in one of `!%', `!:%' or `!?str?:%', and only when used after a !? expansion (possibly in an earlier command). Anything else results in an error, although the error may not be the most obvious one.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.4 Modifiers

After the optional word designator, you can add a sequence of one or more of the following modifiers, each preceded by a `:'. These modifiers also work on the result of filename generation and parameter expansion, except where noted.

h
Remove a trailing pathname component, leaving the head. This works like `dirname'.

r
Remove a filename extension of the form `.xxx', leaving the root name.

e
Remove all but the extension.

t
Remove all leading pathname components, leaving the tail. This works like `basename'.

p
Print the new command but do not execute it. Only works with history expansion.

q
Quote the substituted words, escaping further substitutions. Works with history expansion and parameter expansion, though for parameters it is only useful if the resulting text is to be re-evaluated such as by eval.

Q
Remove one level of quotes from the substituted words.

x
Like q, but break into words at whitespace. Does not work with parameter expansion.

l
Convert the words to all lowercase.

u
Convert the words to all uppercase.

s/l/r[/]
Substitute r for l>' characters have no special significance.

A less convenient but more comprehensible form of command history support is provided by the fc builtin.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.2 Event Designators

An event designator is a reference to a command-line entry in the history list. In the list below, remember that the initial `!' in each item may be changed to another character by setting the histchars parameter.

!
Start a history expansion, except when followed by a blank, newline, `=' or `('. If followed immediately by a word designator (13.1.3 Word Designators), this forms a history reference with no event designator (13.1.1 Overview).

!!
Refer to the previous command. By itself, this expansion repeats the previous command.

!n
Refer to command-line n.

!-n
Refer to the current command-line minus n.

!str
Refer to the most recent command starting with str.

!?str[?]
Refer to the most recent command containing str. The trailing `?' is necessary if this reference is to be followed by a modifier or followed by any text that is not to be considered part of str.

!#
Refer to the current command line typed in so far. The line is treated as if it were complete up to and including the word before the one with the `!#' reference.

!{...}
Insulate a history reference from adjacent characters (if necessary).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.3 Word Designators

A word designator indicates which word or words of a given command line are to be included in a history reference. A `:' usually separates the event specification from the word designator. It may be omitted only if the word designator begins with a `^', `$', `*', `-' or `%'. Word designators include:

0
The first input word (command).
n
The nth argument.
^
The first argument. That is, 1.
$
The last argument.
%
The word matched by (the most recent) ?str search.
x-y
A range of words; x defaults to 0.
*
All the arguments, or a null value if there are none.
x*
Abbreviates `x-$'.
x-
Like `x*' but omitting word $.

Note that a `%' word designator works only when used in one of `!%', `!:%' or `!?str?:%', and only when used after a !? expansion (possibly in an earlier command). Anything else results in an error, although the error may not be the most obvious one.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.4 Modifiers

After the optional word designator, you can add a sequence of one or more of the following modifiers, each preceded by a `:'. These modifiers also work on the result of filename generation and parameter expansion, except where noted.

h
Remove a trailing pathname component, leaving the head. This works like `dirname'.

r
Remove a filename extension of the form `.xxx', leaving the root name.

e
Remove all but the extension.

t
Remove all leading pathname components, leaving the tail. This works like `basename'.

p
Print the new command but do not execute it. Only works with history expansion.

q
Quote the substituted words, escaping further substitutions. Works with history expansion and parameter expansion, though for parameters it is only useful if the resulting text is to be re-evaluated such as by eval.

Q
Remove one level of quotes from the substituted words.

x
Like q, but break into words at whitespace. Does not work with parameter expansion.

l
Convert the words to all lowercase.

u
Convert the words to all uppercase.

s/l/r[/]
Substitute r for l>' characters have no special significance.

A less convenient but more comprehensible form of command history support is provided by the fc builtin.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.2 Event Designators

An event designator is a reference to a command-line entry in the history list. In the list below, remember that the initial `!' in each item may be changed to another character by setting the histchars parameter.

!
Start a history expansion, except when followed by a blank, newline, `=' or `('. If followed immediately by a word designator (13.1.3 Word Designators), this forms a history reference with no event designator (13.1.1 Overview).

!!
Refer to the previous command. By itself, this expansion repeats the previous command.

!n
Refer to command-line n.

!-n
Refer to the current command-line minus n.

!str
Refer to the most recent command starting with str.

!?str[?]
Refer to the most recent command containing str. The trailing `?' is necessary if this reference is to be followed by a modifier or followed by any text that is not to be considered part of str.

!#
Refer to the current command line typed in so far. The line is treated as if it were complete up to and including the word before the one with the `!#' reference.

!{...}
Insulate a history reference from adjacent characters (if necessary).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.3 Word Designators

A word designator indicates which word or words of a given command line are to be included in a history reference. A `:' usually separates the event specification from the word designator. It may be omitted only if the word designator begins with a `^', `$', `*', `-' or `%'. Word designators include:

0
The first input word (command).
n
The nth argument.
^
The first argument. That is, 1.
$
The last argument.
%
The word matched by (the most recent) ?str search.
x-y
A range of words; x defaults to 0.
*
All the arguments, or a null value if there are none.
x*
Abbreviates `x-$'.
x-
Like `x*' but omitting word $.

Note that a `%' word designator works only when used in one of `!%', `!:%' or `!?str?:%', and only when used after a !? expansion (possibly in an earlier command). Anything else results in an error, although the error may not be the most obvious one.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.4 Modifiers

After the optional word designator, you can add a sequence of one or more of the following modifiers, each preceded by a `:'. These modifiers also work on the result of filename generation and parameter expansion, except where noted.

h
Remove a trailing pathname component, leaving the head. This works like `dirname'.

r
Remove a filename extension of the form `.xxx', leaving the root name.

e
Remove all but the extension.

t
Remove all leading pathname components, leaving the tail. This works like `basename'.

p
Print the new command but do not execute it. Only works with history expansion.

q
Quote the substituted words, escaping further substitutions. Works with history expansion and parameter expansion, though for parameters it is only useful if the resulting text is to be re-evaluated such as by eval.

Q
Remove one level of quotes from the substituted words.

x
Like q, but break into words at whitespace. Does not work with parameter expansion.

l
Convert the words to all lowercase.

u
Convert the words to all uppercase.

s/l/r[/]
Substitute r for l>' characters have no special significance.

A less convenient but more comprehensible form of command history support is provided by the fc builtin.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.2 Event Designators

An event designator is a reference to a command-line entry in the history list. In the list below, remember that the initial `!' in each item may be changed to another character by setting the histchars parameter.

!
Start a history expansion, except when followed by a blank, newline, `=' or `('. If followed immediately by a word designator (13.1.3 Word Designators), this forms a history reference with no event designator (13.1.1 Overview).

!!
Refer to the previous command. By itself, this expansion repeats the previous command.

!n
Refer to command-line n.

!-n
Refer to the current command-line minus n.

!str
Refer to the most recent command starting with str.

!?str[?]
Refer to the most recent command containing str. The trailing `?' is necessary if this reference is to be followed by a modifier or followed by any text that is not to be considered part of str.

!#
Refer to the current command line typed in so far. The line is treated as if it were complete up to and including the word before the one with the `!#' reference.

!{...}
Insulate a history reference from adjacent characters (if necessary).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.3 Word Designators

A word designator indicates which word or words of a given command line are to be included in a history reference. A `:' usually separates the event specification from the word designator. It may be omitted only if the word designator begins with a `^', `$', `*', `-' or `%'. Word designators include:

0
The first input word (command).
n
The nth argument.
^
The first argument. That is, 1.
$
The last argument.
%
The word matched by (the most recent) ?str search.
x-y
A range of words; x defaults to 0.
*
All the arguments, or a null value if there are none.
x*
Abbreviates `x-$'.
x-
Like `x*' but omitting word $.

Note that a `%' word designator works only when used in one of `!%', `!:%' or `!?str?:%', and only when used after a !? expansion (possibly in an earlier command). Anything else results in an error, although the error may not be the most obvious one.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.4 Modifiers

After the optional word designator, you can add a sequence of one or more of the following modifiers, each preceded by a `:'. These modifiers also work on the result of filename generation and parameter expansion, except where noted.

h
Remove a trailing pathname component, leaving the head. This works like `dirname'.

r
Remove a filename extension of the form `.xxx', leaving the root name.

e
Remove all but the extension.

t
Remove all leading pathname components, leaving the tail. This works like `basename'.

p
Print the new command but do not execute it. Only works with history expansion.

q
Quote the substituted words, escaping further substitutions. Works with history expansion and parameter expansion, though for parameters it is only useful if the resulting text is to be re-evaluated such as by eval.

Q
Remove one level of quotes from the substituted words.

x
Like q, but break into words at whitespace. Does not work with parameter expansion.

l
Convert the words to all lowercase.

u
Convert the words to all uppercase.

s/l/r[/]
Substitute r for l>' characters have no special significance.

A less convenient but more comprehensible form of command history support is provided by the fc builtin.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.2 Event Designators

An event designator is a reference to a command-line entry in the history list. In the list below, remember that the initial `!' in each item may be changed to another character by setting the histchars parameter.

!
Start a history expansion, except when followed by a blank, newline, `=' or `('. If followed immediately by a word designator (13.1.3 Word Designators), this forms a history reference with no event designator (13.1.1 Overview).

!!
Refer to the previous command. By itself, this expansion repeats the previous command.

!n
Refer to command-line n.

!-n
Refer to the current command-line minus n.

!str
Refer to the most recent command starting with str.

!?str[?]
Refer to the most recent command containing str. The trailing `?' is necessary if this reference is to be followed by a modifier or followed by any text that is not to be considered part of str.

!#
Refer to the current command line typed in so far. The line is treated as if it were complete up to and including the word before the one with the `!#' reference.

!{...}
Insulate a history reference from adjacent characters (if necessary).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.3 Word Designators

A word designator indicates which word or words of a given command line are to be included in a history reference. A `:' usually separates the event specification from the word designator. It may be omitted only if the word designator begins with a `^', `$', `*', `-' or `%'. Word designators include:

0
The first input word (command).
n
The nth argument.
^
The first argument. That is, 1.
$
The last argument.
%
The word matched by (the most recent) ?str search.
x-y
A range of words; x defaults to 0.
*
All the arguments, or a null value if there are none.
x*
Abbreviates `x-$'.
x-
Like `x*' but omitting word $.

Note that a `%' word designator works only when used in one of `!%', `!:%' or `!?str?:%', and only when used after a !? expansion (possibly in an earlier command). Anything else results in an error, although the error may not be the most obvious one.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.4 Modifiers

After the optional word designator, you can add a sequence of one or more of the following modifiers, each preceded by a `:'. These modifiers also work on the result of filename generation and parameter expansion, except where noted.

h
Remove a trailing pathname component, leaving the head. This works like `dirname'.

r
Remove a filename extension of the form `.xxx', leaving the root name.

e
Remove all but the extension.

t
Remove all leading pathname components, leaving the tail. This works like `basename'.

p
Print the new command but do not execute it. Only works with history expansion.

q
Quote the substituted words, escaping further substitutions. Works with history expansion and parameter expansion, though for parameters it is only useful if the resulting text is to be re-evaluated such as by eval.

Q
Remove one level of quotes from the substituted words.

x
Like q, but break into words at whitespace. Does not work with parameter expansion.

l
Convert the words to all lowercase.

u
Convert the words to all uppercase.

s/l/r[/]
Substitute r for l>' characters have no special significance.

A less convenient but more comprehensible form of command history support is provided by the fc builtin.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.2 Event Designators

An event designator is a reference to a command-line entry in the history list. In the list below, remember that the initial `!' in each item may be changed to another character by setting the histchars parameter.

!
Start a history expansion, except when followed by a blank, newline, `=' or `('. If followed immediately by a word designator (13.1.3 Word Designators), this forms a history reference with no event designator (13.1.1 Overview).

!!
Refer to the previous command. By itself, this expansion repeats the previous command.

!n
Refer to command-line n.

!-n
Refer to the current command-line minus n.

!str
Refer to the most recent command starting with str.

!?str[?]
Refer to the most recent command containing str. The trailing `?' is necessary if this reference is to be followed by a modifier or followed by any text that is not to be considered part of str.

!#
Refer to the current command line typed in so far. The line is treated as if it were complete up to and including the word before the one with the `!#' reference.

!{...}
Insulate a history reference from adjacent characters (if necessary).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.3 Word Designators

A word designator indicates which word or words of a given command line are to be included in a history reference. A `:' usually separates the event specification from the word designator. It may be omitted only if the word designator begins with a `^', `$', `*', `-' or `%'. Word designators include:

0
The first input word (command).
n
The nth argument.
^
The first argument. That is, 1.
$
The last argument.
%
The word matched by (the most recent) ?str search.
x-y
A range of words; x defaults to 0.
*
All the arguments, or a null value if there are none.
x*
Abbreviates `x-$'.
x-
Like `x*' but omitting word $.

Note that a `%' word designator works only when used in one of `!%', `!:%' or `!?str?:%', and only when used after a !? expansion (possibly in an earlier command). Anything else results in an error, although the error may not be the most obvious one.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.4 Modifiers

After the optional word designator, you can add a sequence of one or more of the following modifiers, each preceded by a `:'. These modifiers also work on the result of filename generation and parameter expansion, except where noted.

h
Remove a trailing pathname component, leaving the head. This works like `dirname'.

r
Remove a filename extension of the form `.xxx', leaving the root name.

e
Remove all but the extension.

t
Remove all leading pathname components, leaving the tail. This works like `basename'.

p
Print the new command but do not execute it. Only works with history expansion.

q
Quote the substituted words, escaping further substitutions. Works with history expansion and parameter expansion, though for parameters it is only useful if the resulting text is to be re-evaluated such as by eval.

Q
Remove one level of quotes from the substituted words.

x
Like q, but break into words at whitespace. Does not work with parameter expansion.

l
Convert the words to all lowercase.

u
Convert the words to all uppercase.

s/l/r[/]
Substitute r for l>' characters have no special significance.

A less convenient but more comprehensible form of command history support is provided by the fc builtin.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.2 Event Designators

An event designator is a reference to a command-line entry in the history list. In the list below, remember that the initial `!' in each item may be changed to another character by setting the histchars parameter.

!
Start a history expansion, except when followed by a blank, newline, `=' or `('. If followed immediately by a word designator (13.1.3 Word Designators), this forms a history reference with no event designator (13.1.1 Overview).

!!
Refer to the previous command. By itself, this expansion repeats the previous command.

!n
Refer to command-line n.

!-n
Refer to the current command-line minus n.

!str
Refer to the most recent command starting with str.

!?str[?]
Refer to the most recent command containing str. The trailing `?' is necessary if this reference is to be followed by a modifier or followed by any text that is not to be considered part of str.

!#
Refer to the current command line typed in so far. The line is treated as if it were complete up to and including the word before the one with the `!#' reference.

!{...}
Insulate a history reference from adjacent characters (if necessary).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.3 Word Designators

A word designator indicates which word or words of a given command line are to be included in a history reference. A `:' usually separates the event specification from the word designator. It may be omitted only if the word designator begins with a `^', `$', `*', `-' or `%'. Word designators include:

0
The first input word (command).
n
The nth argument.
^
The first argument. That is, 1.
$
The last argument.
%
The word matched by (the most recent) ?str search.
x-y
A range of words; x defaults to 0.
*
All the arguments, or a null value if there are none.
x*
Abbreviates `x-$'.
x-
Like `x*' but omitting word $.

Note that a `%' word designator works only when used in one of `!%', `!:%' or `!?str?:%', and only when used after a !? expansion (possibly in an earlier command). Anything else results in an error, although the error may not be the most obvious one.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.4 Modifiers

After the optional word designator, you can add a sequence of one or more of the following modifiers, each preceded by a `:'. These modifiers also work on the result of filename generation and parameter expansion, except where noted.

h
Remove a trailing pathname component, leaving the head. This works like `dirname'.

r
Remove a filename extension of the form `.xxx', leaving the root name.

e
Remove all but the extension.

t
Remove all leading pathname components, leaving the tail. This works like `basename'.

p
Print the new command but do not execute it. Only works with history expansion.

q
Quote the substituted words, escaping further substitutions. Works with history expansion and parameter expansion, though for parameters it is only useful if the resulting text is to be re-evaluated such as by eval.

Q
Remove one level of quotes from the substituted words.

x
Like q, but break into words at whitespace. Does not work with parameter expansion.

l
Convert the words to all lowercase.

u
Convert the words to all uppercase.

s/l/r[/]
Substitute r for l>' characters have no special significance.

A less convenient but more comprehensible form of command history support is provided by the fc builtin.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.2 Event Designators

An event designator is a reference to a command-line entry in the history list. In the list below, remember that the initial `!' in each item may be changed to another character by setting the histchars parameter.

!
Start a history expansion, except when followed by a blank, newline, `=' or `('. If followed immediately by a word designator (13.1.3 Word Designators), this forms a history reference with no event designator (13.1.1 Overview).

!!
Refer to the previous command. By itself, this expansion repeats the previous command.

!n
Refer to command-line n.

!-n
Refer to the current command-line minus n.

!str
Refer to the most recent command starting with str.

!?str[?]
Refer to the most recent command containing str. The trailing `?' is necessary if this reference is to be followed by a modifier or followed by any text that is not to be considered part of str.

!#
Refer to the current command line typed in so far. The line is treated as if it were complete up to and including the word before the one with the `!#' reference.

!{...}
Insulate a history reference from adjacent characters (if necessary).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.3 Word Designators

A word designator indicates which word or words of a given command line are to be included in a history reference. A `:' usually separates the event specification from the word designator. It may be omitted only if the word designator begins with a `^', `$', `*', `-' or `%'. Word designators include:

0
The first input word (command).
n
The nth argument.
^
The first argument. That is, 1.
$
The last argument.
%
The word matched by (the most recent) ?str search.
x-y
A range of words; x defaults to 0.
*
All the arguments, or a null value if there are none.
x*
Abbreviates `x-$'.
x-
Like `x*' but omitting word $.

Note that a `%' word designator works only when used in one of `!%', `!:%' or `!?str?:%', and only when used after a !? expansion (possibly in an earlier command). Anything else results in an error, although the error may not be the most obvious one.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.4 Modifiers

After the optional word designator, you can add a sequence of one or more of the following modifiers, each preceded by a `:'. These modifiers also work on the result of filename generation and parameter expansion, except where noted.

h
Remove a trailing pathname component, leaving the head. This works like `dirname'.

r
Remove a filename extension of the form `.xxx', leaving the root name.

e
Remove all but the extension.

t
Remove all leading pathname components, leaving the tail. This works like `basename'.

p
Print the new command but do not execute it. Only works with history expansion.

q
Quote the substituted words, escaping further substitutions. Works with history expansion and parameter expansion, though for parameters it is only useful if the resulting text is to be re-evaluated such as by eval.

Q
Remove one level of quotes from the substituted words.

x
Like q, but break into words at whitespace. Does not work with parameter expansion.

l
Convert the words to all lowercase.

u
Convert the words to all uppercase.

s/l/r[/]
Substitute r for l>' characters have no special significance.

A less convenient but more comprehensible form of command history support is provided by the fc builtin.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.2 Event Designators

An event designator is a reference to a command-line entry in the history list. In the list below, remember that the initial `!' in each item may be changed to another character by setting the histchars parameter.

!
Start a history expansion, except when followed by a blank, newline, `=' or `('. If followed immediately by a word designator (13.1.3 Word Designators), this forms a history reference with no event designator (13.1.1 Overview).

!!
Refer to the previous command. By itself, this expansion repeats the previous command.

!n
Refer to command-line n.

!-n
Refer to the current command-line minus n.

!str
Refer to the most recent command starting with str.

!?str[?]
Refer to the most recent command containing str. The trailing `?' is necessary if this reference is to be followed by a modifier or followed by any text that is not to be considered part of str.

!#
Refer to the current command line typed in so far. The line is treated as if it were complete up to and including the word before the one with the `!#' reference.

!{...}
Insulate a history reference from adjacent characters (if necessary).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.3 Word Designators

A word designator indicates which word or words of a given command line are to be included in a history reference. A `:' usually separates the event specification from the word designator. It may be omitted only if the word designator begins with a `^', `$', `*', `-' or `%'. Word designators include:

0
The first input word (command).
n
The nth argument.
^
The first argument. That is, 1.
$
The last argument.
%
The word matched by (the most recent) ?str search.
x-y
A range of words; x defaults to 0.
*
All the arguments, or a null value if there are none.
x*
Abbreviates `x-$'.
x-
Like `x*' but omitting word $.

Note that a `%' word designator works only when used in one of `!%', `!:%' or `!?str?:%', and only when used after a !? expansion (possibly in an earlier command). Anything else results in an error, although the error may not be the most obvious one.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.4 Modifiers

After the optional word designator, you can add a sequence of one or more of the following modifiers, each preceded by a `:'. These modifiers also work on the result of filename generation and parameter expansion, except where noted.

h
Remove a trailing pathname component, leaving the head. This works like `dirname'.

r
Remove a filename extension of the form `.xxx', leaving the root name.

e
Remove all but the extension.

t
Remove all leading pathname components, leaving the tail. This works like `basename'.

p
Print the new command but do not execute it. Only works with history expansion.

q
Quote the substituted words, escaping further substitutions. Works with history expansion and parameter expansion, though for parameters it is only useful if the resulting text is to be re-evaluated such as by eval.

Q
Remove one level of quotes from the substituted words.

x
Like q, but break into words at whitespace. Does not work with parameter expansion.

l
Convert the words to all lowercase.

u
Convert the words to all uppercase.

s/l/r[/]
Substitute r for l>' characters have no special significance.

A less convenient but more comprehensible form of command history support is provided by the fc builtin.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.2 Event Designators

An event designator is a reference to a command-line entry in the history list. In the list below, remember that the initial `!' in each item may be changed to another character by setting the histchars parameter.

!
Start a history expansion, except when followed by a blank, newline, `=' or `('. If followed immediately by a word designator (13.1.3 Word Designators), this forms a history reference with no event designator (13.1.1 Overview).

!!
Refer to the previous command. By itself, this expansion repeats the previous command.

!n
Refer to command-line n.

!-n
Refer to the current command-line minus n.

!str
Refer to the most recent command starting with str.

!?str[?]
Refer to the most recent command containing str. The trailing `?' is necessary if this reference is to be followed by a modifier or followed by any text that is not to be considered part of str.

!#
Refer to the current command line typed in so far. The line is treated as if it were complete up to and including the word before the one with the `!#' reference.

!{...}
Insulate a history reference from adjacent characters (if necessary).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.3 Word Designators

A word designator indicates which word or words of a given command line are to be included in a history reference. A `:' usually separates the event specification from the word designator. It may be omitted only if the word designator begins with a `^', `$', `*', `-' or `%'. Word designators include:

0
The first input word (command).
n
The nth argument.
^
The first argument. That is, 1.
$
The last argument.
%
The word matched by (the most recent) ?str search.
x-y
A range of words; x defaults to 0.
*
All the arguments, or a null value if there are none.
x*
Abbreviates `x-$'.
x-
Like `x*' but omitting word $.

Note that a `%' word designator works only when used in one of `!%', `!:%' or `!?str?:%', and only when used after a !? expansion (possibly in an earlier command). Anything else results in an error, although the error may not be the most obvious one.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.4 Modifiers

After the optional word designator, you can add a sequence of one or more of the following modifiers, each preceded by a `:'. These modifiers also work on the result of filename generation and parameter expansion, except where noted.

h
Remove a trailing pathname component, leaving the head. This works like `dirname'.

r
Remove a filename extension of the form `.xxx', leaving the root name.

e
Remove all but the extension.

t
Remove all leading pathname components, leaving the tail. This works like `basename'.

p
Print the new command but do not execute it. Only works with history expansion.

q
Quote the substituted words, escaping further substitutions. Works with history expansion and parameter expansion, though for parameters it is only useful if the resulting text is to be re-evaluated such as by eval.

Q
Remove one level of quotes from the substituted words.

x
Like q, but break into words at whitespace. Does not work with parameter expansion.

l
Convert the words to all lowercase.

u
Convert the words to all uppercase.

s/l/r[/]
Substitute r for l>' characters have no special significance.

A less convenient but more comprehensible form of command history support is provided by the fc builtin.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.2 Event Designators

An event designator is a reference to a command-line entry in the history list. In the list below, remember that the initial `!' in each item may be changed to another character by setting the histchars parameter.

!
Start a history expansion, except when followed by a blank, newline, `=' or `('. If followed immediately by a word designator (13.1.3 Word Designators), this forms a history reference with no event designator (13.1.1 Overview).

!!
Refer to the previous command. By itself, this expansion repeats the previous command.

!n
Refer to command-line n.

!-n
Refer to the current command-line minus n.

!str
Refer to the most recent command starting with str.

!?str[?]
Refer to the most recent command containing str. The trailing `?' is necessary if this reference is to be followed by a modifier or followed by any text that is not to be considered part of str.

!#
Refer to the current command line typed in so far. The line is treated as if it were complete up to and including the word before the one with the `!#' reference.

!{...}
Insulate a history reference from adjacent characters (if necessary).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.3 Word Designators

A word designator indicates which word or words of a given command line are to be included in a history reference. A `:' usually separates the event specification from the word designator. It may be omitted only if the word designator begins with a `^', `$', `*', `-' or `%'. Word designators include:

0
The first input word (command).
n
The nth argument.
^
The first argument. That is, 1.
$
The last argument.
%
The word matched by (the most recent) ?str search.
x-y
A range of words; x defaults to 0.
*
All the arguments, or a null value if there are none.
x*
Abbreviates `x-$'.
x-
Like `x*' but omitting word $.

Note that a `%' word designator works only when used in one of `!%', `!:%' or `!?str?:%', and only when used after a !? expansion (possibly in an earlier command). Anything else results in an error, although the error may not be the most obvious one.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.4 Modifiers

After the optional word designator, you can add a sequence of one or more of the following modifiers, each preceded by a `:'. These modifiers also work on the result of filename generation and parameter expansion, except where noted.

h
Remove a trailing pathname component, leaving the head. This works like `dirname'.

r
Remove a filename extension of the form `.xxx', leaving the root name.

e
Remove all but the extension.

t
Remove all leading pathname components, leaving the tail. This works like `basename'.

p
Print the new command but do not execute it. Only works with history expansion.

q
Quote the substituted words, escaping further substitutions. Works with history expansion and parameter expansion, though for parameters it is only useful if the resulting text is to be re-evaluated such as by eval.

Q
Remove one level of quotes from the substituted words.

x
Like q, but break into words at whitespace. Does not work with parameter expansion.

l
Convert the words to all lowercase.

u
Convert the words to all uppercase.

s/l/r[/]
Substitute r for l>' characters have no special significance.

A less convenient but more comprehensible form of command history support is provided by the fc builtin.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.2 Event Designators

An event designator is a reference to a command-line entry in the history list. In the list below, remember that the initial `!' in each item may be changed to another character by setting the histchars parameter.

!
Start a history expansion, except when followed by a blank, newline, `=' or `('. If followed immediately by a word designator (13.1.3 Word Designators), this forms a history reference with no event designator (13.1.1 Overview).

!!
Refer to the previous command. By itself, this expansion repeats the previous command.

!n
Refer to command-line n.

!-n
Refer to the current command-line minus n.

!str
Refer to the most recent command starting with str.

!?str[?]
Refer to the most recent command containing str. The trailing `?' is necessary if this reference is to be followed by a modifier or followed by any text that is not to be considered part of str.

!#
Refer to the current command line typed in so far. The line is treated as if it were complete up to and including the word before the one with the `!#' reference.

!{...}
Insulate a history reference from adjacent characters (if necessary).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.3 Word Designators

A word designator indicates which word or words of a given command line are to be included in a history reference. A `:' usually separates the event specification from the word designator. It may be omitted only if the word designator begins with a `^', `$', `*', `-' or `%'. Word designators include:

0
The first input word (command).
n
The nth argument.
^
The first argument. That is, 1.
$
The last argument.
%
The word matched by (the most recent) ?str search.
x-y
A range of words; x defaults to 0.
*
All the arguments, or a null value if there are none.
x*
Abbreviates `x-$'.
x-
Like `x*' but omitting word $.

Note that a `%' word designator works only when used in one of `!%', `!:%' or `!?str?:%', and only when used after a !? expansion (possibly in an earlier command). Anything else results in an error, although the error may not be the most obvious one.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.4 Modifiers

After the optional word designator, you can add a sequence of one or more of the following modifiers, each preceded by a `:'. These modifiers also work on the result of filename generation and parameter expansion, except where noted.

h
Remove a trailing pathname component, leaving the head. This works like `dirname'.

r
Remove a filename extension of the form `.xxx', leaving the root name.

e
Remove all but the extension.

t
Remove all leading pathname components, leaving the tail. This works like `basename'.

p
Print the new command but do not execute it. Only works with history expansion.

q
Quote the substituted words, escaping further substitutions. Works with history expansion and parameter expansion, though for parameters it is only useful if the resulting text is to be re-evaluated such as by eval.

Q
Remove one level of quotes from the substituted words.

x
Like q, but break into words at whitespace. Does not work with parameter expansion.

l
Convert the words to all lowercase.

u
Convert the words to all uppercase.

s/l/r[/]
Substitute r for l>' characters have no special significance.

A less convenient but more comprehensible form of command history support is provided by the fc builtin.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1.2 Event Designators

An event designator is a reference to a command-line entry in the history list. In the list below, remember that the initial `!' in each item may be changed to another character by setting the histchars parameter.

!
Start a history expansion, except when followed by a blank, newline, `=' or `('. If followed immediately by a word designator (13.1.3 Word Designators), this forms a history reference with no event designator (13.1.1 Overview).

!!
Refer to the previous command. By itself, this expansion repeats the previous command.

!n
Refer to command-line n.

!-n
Refer to the current command-line minus n.

!str
Refer to the most recent command starting with str.

!?str[?]
Refer to the most recent command containing str. The trailing `?' is necessary if this reference is to be followed by a modifier or followed by any text that is not to be c