SysIII/usr/src/man/man1/ed.1

Compare this file to the similar file:
Show the results in this format:

.if t .ds ^ \^\s+4\v@.3m@^\v@-.3m@\s-4\^
.if n .ds ^ ^
.TH ED 1
.SH NAME
ed \- text editor
.SH SYNOPSIS
.B ed
[
.B \-
] [
.B \-x
] [ file ]
.SH DESCRIPTION
.I Ed\^
is the standard text editor.
If the
.I file\^
argument is given,
.I ed\^
simulates an
.I e\^
command (see below) on the named file; that is to say,
the file is read into
.IR ed 's
buffer so that it can be edited.
The optional
.B \-
suppresses the printing
of character counts by
.IR e ,
.IR r ,
and
.I w\^
commands,
of diagnostics from
.I e\^
and
.I q\^
commands,
and of the
.B !
prompt after a
\f3!\fP\f2shell\ command\^\fP.
If
.B \-x
is present, an
.I x\^
command is simulated first to handle an encrypted file.
.I Ed\^
operates on a copy of the file it is editing; changes made
to the copy have no effect on the file until a
.I w\^
(write)
command is given.
The copy of the text being edited resides
in a temporary file called the
.IR buffer .
There is only
one buffer.
.PP
Commands to
.I ed\^
have a simple and regular structure: zero, one, or two
.I addresses\^
followed by a single-character
.IR command ,
possibly
followed by parameters to that command.
These addresses specify one or more lines in the buffer.
Every command that requires addresses has default addresses,
so that the addresses can very often be omitted.
.PP
In general, only one command may appear on a line.
Certain commands allow the input of text.
This text is placed in the appropriate place in the buffer.
While
.I ed\^
is accepting text, it is said
to be in
.IR "input mode" .
In this mode,
.I no\^
commands are recognized;
all input is merely collected.
Input mode is left by typing a period (\^\f3.\fP\^) alone at the
beginning of a line.
.PP
.I Ed\^
supports a limited form of
.I "regular expression\^"
notation;
regular expressions are used in addresses to specify
lines and in some commands
(e.g.,
.IR s )
to specify portions of a line that are to be substituted.
A regular expression (\s-1RE\s+1) specifies
a set of character strings.
A member of this set of strings is said to be
.I matched\^
by the \s-1RE\s+1.
The \s-1RE\s+1s allowed by
.I ed\^
are constructed as follows:
.PP
The following
.I one-character\^
.IR \s-1RE\s+1 s
match a
.I single\^
character:
.TP "\w'1.1\ \ \ \ 'u"
1.1
An ordinary character
(\c
.I not\^
one of those discussed in 1.2 below)
is a
one-character \s-1RE\s+1
that matches itself.
.TP
1.2
A backslash (\f3\^\e\fP) followed by any special character is a
one-character \s-1RE\s+1
that matches the special character itself.
The special characters are:
.RS
.TP "\w'a.\ \ \ \ 'u"
a.
\&\f3.\fP,
\f3\(**\fP,
\f3[\fP,
and
\f3\^\e\fP (period, asterisk, left square bracket,
and backslash, respectively), which are always special,
.I except\^
when they appear within square brackets (\^\f3[\|]\fP\^; see 1.4 below).
.TP
b.
\*^ (caret or circumflex), which is special at the
.I beginning\^
of an
.I entire\^
\s-1RE\s+1
(see 3.1 and 3.2 below),
or when it immediately follows the left of a pair of square brackets (\^\f3[\|]\fP\^) (see 1.4 below).
.TP
c.
\f3$\fP (currency symbol), which is special at the
.I end\^
of an
entire \s-1RE\s+1
(see 3.2 below).
.TP
d.
The character used to bound
(i.e., delimit) an entire \s-1RE\s+1, which is special for that RE (for example,
see how slash (\^\f3/\fP\^) is used in the
.I g\^
command, below.)
.\s-1RE\s+1
.TP "\w'1.1\ \ \ \ 'u"
1.3
A period (\^\f3.\fP\^) is a
one-character \s-1RE\s+1
that matches any character except new-line.
.TP
1.4
A non-empty string of characters enclosed in square brackets (\^\f3[\|]\fP\^) is a
one-character \s-1RE\s+1
that matches
.I "any one\^"
character in that string.
If, however, the first character of the string is a circumflex
(\*^), the
one-character \s-1RE\s+1
matches any character
.I except\^
new-line and the remaining characters in the string.
The \*^ has this special meaning
.I only\^
if it
occurs first in the string.
The minus (\f3\-\fP) may be used to indicate a range of consecutive
.SM ASCII
characters;
for example, \f3[0\-9]\fP is equivalent to \f3[0123456789]\fP.
The \f3\-\fP loses this special meaning if it occurs first (after
an initial \*^, if any)
or last in the string.
The right square bracket (\^\f3]\fP\^)
does not terminate such a string when it
is the first character within it (after an initial \*^, if any);
e.g., \f3[\|]a\-f]\fP matches either a right square
bracket (\^\f3]\fP\^) or one of the letters \f3a\fP through \f3f\fP inclusive.
The four characters listed in 1.2.a above stand for themselves
within such a string of characters.
.PP
The following rules may be used to construct
.IR \s-1RE\s+1 s
from
one-character
\s-1RE\s+1s:
.TP "\w'1.1\ \ \ \ 'u"
2.1
A
one-character \s-1RE\s+1
is a
\s-1RE\s+1
that matches whatever the
one-character \s-1RE\s+1 matches.
.TP
2.2
A
one-character \s-1RE\s+1
followed by an asterisk (\f3\(**\fP) is a
\s-1RE\s+1
that matches
.I zero\^
or more occurrences of the
one-character \s-1RE\s+1.
If there is any choice,
the longest leftmost string that permits a match is chosen.
.TP
2.3
A
one-character \s-1RE\s+1
followed by \f3\^\e{\fP\^\f2m\fP\^\f3\e}\fP,
\f3\^\e{\fP\^\f2m,\fP\^\f3\e}\fP,
or
\f3\^\e{\fP\^\f2m,n\fP\^\f3\e}\fP is a
\s-1RE\s+1
that matches a
.I range\^
of occurrences of the
one-character \s-1RE\s+1.
The values of
.I m\^
and
.I n\^
must be non-negative integers less than 256;
\f3\^\e{\fP\^\f2m\fP\^\f3\e}\fP
matches
.I exactly\^
.I m\^
occurrences;
\f3\^\e{\fP\^\f2m,\fP\^\f3\e}\fP
matches
.I "at least\^"
.I m\^
occurrences;
\f3\^\e{\fP\^\f2m,n\fP\^\f3\e}\fP
matches
.I "any number\^"
of occurrences
.I between\^
.I m\^
and
.I n\^
inclusive.
Whenever a choice exists,
the
\s-1RE\s+1
matches as many occurrences as possible.
.TP
2.4
The concatenation of
\s-1RE\s+1s
is a
\s-1RE\s+1
that matches the concatenation of the strings matched by each component of the
\s-1RE\s+1.
.TP
2.5
A
\s-1RE\s+1
enclosed between the character sequences
\f3\^\e(\fP and \f3\^\e)\fP
is a
\s-1RE\s+1
that matches whatever the unadorned
\s-1RE\s+1
matches.
.TP
2.6
The expression \f3\^\e\fP\f2n\fP\^ matches the same string of characters
as was
matched by an expression enclosed between \f3\^\e(\fP and \f3\^\e)\fP
.I earlier\^
in the same \s-1RE\s+1.
Here
.I n\^
is a digit;
the sub-expression specified is that beginning with the
.IR n -th
occurrence of \f3\^\e(\fP counting from the left.
For example, the expression \*^\f3\e(.\(**\e)\e1$\fP matches a line
consisting of two repeated appearances of the same string.
.PP
Finally, an
.I entire\^
.I \s-1RE\s+1\^
may be constrained to match only an initial segment or final segment
of a line (or both):
.TP "\w'1.1\ \ \ \ 'u"
3.1
A circumflex (\*^) at the beginning of an
entire \s-1RE\s+1
constrains that \s-1RE\s+1 to match an
.I initial\^
segment of a line.
.TP
3.2
A currency symbol (\^\f3$\fP\^)
at the end of an
entire \s-1RE\s+1
constrains that
\s-1RE\s+1
to match a
.I final\^
segment of a line.
The construction
\%\*^\f2entire \s-1RE\s+1\fP\|\f3$\fP
constrains the
entire \s-1RE\s+1
to match the entire line.
.PP
The null \s-1RE\s+1 (e.g., \f3//\fP)
is equivalent to the last \s-1RE\s+1 encountered.
See also the last paragraph before
.SM
.I FILES\^
below.
.PP
To understand addressing in
.I ed\^
it is necessary to know that at any time there is a
.IR "current line" .
Generally speaking, the current line is
the last line affected by a command;
the exact effect on the current line
is discussed under the description of
each command.
.I Addresses\^
are constructed as follows:
.TP "\w'1.1\ \ \ \ 'u"
\01.
The character \f3.\fP addresses the current line.
.TP
\02.
The character \f3$\fP addresses the last line of the buffer.
.TP
\03.
A decimal number
.I n\^
addresses the
.IR n -th
line of the buffer.
.TP
\04.
\f2\(fmx\fP\^ addresses the line marked with the
mark name character
.IR x ,
which must be a lower-case letter.
Lines are marked with the
.I k\^
command described below.
.TP
\05.
A \s-1RE\s+1 enclosed by slashes (\^\f3/\fP\^) addresses
the first line found by searching
.I forward\^
from the line
.I following\^
the current line
toward the end of the
buffer and stopping at the first line containing a
string matching the \s-1RE\s+1.
If necessary, the search wraps around to the beginning of the
buffer
and continues up to and including the current line, so that the entire
buffer is searched.
See also the last paragraph before
.SM
.I FILES\^
below.
.TP
\06.
A \s-1RE\s+1 enclosed in question marks (\^\f3?\fP\^) addresses
the first line found by searching
.I backward\^
from the line
.I preceding\^
the current line
toward the beginning of
the buffer and stopping at the first line containing
a string matching the \s-1RE\s+1.
If necessary,
the search wraps around to the end of the buffer
and continues up to and including the current line.
See also the last paragraph before
.SM
.I FILES\^
below.
.TP
\07.
An address followed by a plus sign (\^\f3+\fP\^)
or a minus sign (\f3\-\fP) followed by a decimal number specifies that address plus
(respectively minus) the indicated number of lines.
The plus sign may be omitted.
.TP
\08.
If an address begins with \f3+\fP or \f3\-\fP,
the addition or subtraction is taken with respect to the current line;
e.g, \f3\-5\fP is understood to mean \f3.\-5\fP.
.TP
\09.
If an address ends with \f3+\fP or \f3\-\fP,
then 1 is added to or subtracted from the address, respectively.
As a consequence of this rule and of rule 8 immediately above,
the address \f3\-\fP refers to the line preceding the current line.
(To maintain compatibility with earlier versions of the editor,
the character \*^ in addresses is entirely
equivalent to \f3\-\fP.)
Moreover,
trailing
\f3+\fP and \f3\-\fP characters
have a cumulative effect, so \f3\-\-\fP refers to the current
line less 2.
.TP
10.
For convenience, a comma (\^\f3,\fP\^) stands for the
address pair \f31,\^$\fP,
while a semicolon (\^\f3;\fP\^) stands for the
pair \f3.\^,\^$\fP.
.PP
Commands may require zero, one, or two addresses.
Commands that require no addresses regard the presence
of an address as an error.
Commands that accept one or two addresses
assume default addresses when an insufficient number of addresses is given;
if more addresses are given than such a command requires,
the last one(s) are used.
.PP
Typically, addresses are separated from each other by a comma
(\^\f3,\fP\^).
They may also be separated by a semicolon
(\^\f3;\fP\^).
In the latter case, the current line (\^\f3.\fP\^) is set to
the first address,
and only then is the second address calculated.
This feature can be used to determine the starting
line for forward and backward searches (see rules 5. and 6. above).
The second address of any two-address sequence
must correspond to a line that follows, in the buffer, the line corresponding to the first address.
.PP
In the following list of
.I ed\^
commands, the default addresses
are shown in parentheses.
The parentheses are
.I not\^
part of
the address; they show that the given addresses are
the default.
.PP
It is generally illegal for more than one
command to appear on a line.
However, any command
(except
.IR e ,
.IR f ,
.IR r ,
or
.IR w )
may be suffixed by \f3p\fP
or by \f3l\fP, in which case
the current line is either
printed or listed, respectively,
as discussed below under the
.I p\^
and
.I l\^
commands.
.HP
.B (\|.\|)a
.br
.ns
.HP
<text>
.br
.ns
.HP
.if t .rs
.if t .sp -.5v
\&\f3.\fP
.br
The
.IR a ppend
command reads the given text
and appends it after the addressed line;
\&\f3.\fP is left
at the last inserted line, or, if there
were none, at the addressed line.
Address 0 is legal for this command: it causes the ``appended'' text to be placed
at the beginning of the buffer.
.HP
.B (\|.\|)c
.br
.ns
.HP
<text>
.br
.ns
.HP
.if t .rs
.if t .sp -.5v
\&\f3.\fP
.br
The
.IR c hange
command deletes the addressed lines, then accepts input
text that replaces these lines;
\&\f3.\fP is left at the last line input, or, if there were none,
at the first line that was not deleted.
.HP
.B (\|.\|,\|.\|)d
.br
The
.IR d elete
command deletes the addressed lines from the buffer.
The line after the last line deleted becomes the current line;
if the lines deleted were originally at the end of the buffer,
the new last line becomes the current line.
.HP
.BI e " file\^"
.br
The
.IR e dit
command causes the entire contents of the buffer to be deleted,
and then the named file to be read in;
\&\f3.\fP is set to the last line of the buffer.
If no file name is given, the currently-remembered file name, if any, is used
(see the
.I f\^
command).
The number of characters read is typed;
.I file\^
is remembered for possible use as a default file name
in subsequent
.IR e ,
.IR r ,
and
.IR w " commands."
If
.I file\^
begins with \f3!\fP, the rest of the line
is taken to be a
shell (\f2sh\fP\^(1))
command whose output is to be read.
Such a
shell
command is
.I not\^
remembered as the current file name.
See also
.SM
.I DIAGNOSTICS\^
below.
.HP
.BI E " file\^"
.br
The
.IR E dit
command is like
.IR e ,
except that the editor does not check to see
if any changes have been made to the buffer since
the last
.I w\^
command.
.HP
.BI f " file\^"
.br
If
.I file\^
is given,
the
.IR f \|ile-name
command changes
the currently-remembered file name to
.IR file ;
otherwise, it prints the currently-remembered file name.
.HP
.BI (\|1\|,\|$\|)g/ \s-1RE\s+1 / "command list\^"
.br
In the
.IR g lobal
command, the first step is to mark every line that matches
the given
\s-1RE\s+1.
Then, for every such line, the
given
.I "command list\^"
is executed with \f3.\fP initially set to that line.
A single command or the first of a list of commands
appears on the same line as the global command.
All lines of a multi-line list except the last line must be ended with a \f3\^\e\fP;
.IR a ,
.IR i ,
and
.I c\^
commands and associated input are permitted;
the \f3.\fP terminating input mode may be omitted if it would be the
last line of the
.IR "command list" .
An empty
.I "command list\^"
is equivalent to the
.I p\^
command.
The
.IR g ,
.IR G ,
.IR v ,
and
.I V\^
commands
are
.I not\^
permitted in the
.IR "command list" .
See also
.SM
.I BUGS\^
and the last paragraph before
.SM
.I FILES\^
below.
.HP
.BI (\|1\|,\|$\|)G/ \s-1RE\s+1 /\^
.br
In the interactive
.IR G lobal
command, the first step
is to mark every line that matches the given
\s-1RE\s+1.
Then, for every such line, that line is printed, \f3.\fP is changed to that line, and
any
.I one\^
command (other than one of the
.IR a ,
.IR c ,
.IR i ,
.IR g ,
.IR G ,
.IR v ,
and
.I V\^
commands)
may be input and is executed.
After the execution of that command, the next marked line is printed, and so on;
a new-line acts as a null command;
an \f3&\fP causes the re-execution of the most recent command executed within
the current invocation of
.IR G .
Note that the
commands input
as part of the execution of the
.I G\^
command
may
address and affect
.I any\^
lines in the buffer.
The
.I G\^
command can be terminated by an interrupt signal (\s-1ASCII\s0 \s-1DEL\s0 or \s-1BREAK\s0).
.HP
.br
.B h
.br
The
.IR h elp
command gives a short error message that explains
the reason for the most recent \f3?\fP diagnostic.
.HP
.B H
.br
The
.IR H elp
command causes
.I ed\^
to enter a mode in which error messages are
printed for all subsequent \f3?\fP diagnostics.
It will also explain the previous \f3?\fP if
there was one.
The
.I H\^
command alternately turns this mode
on and off; it is initially off.
.HP
.B (\|.\|)i
.br
.ns
.HP
<text>
.br
.ns
.HP
.if t .rs
.if t .sp -.5v
\&\f3.\fP
.br
The
.IR i nsert
command inserts the given text before the addressed line;
\&\f3.\fP is left at the last inserted line, or, if there were none,
at the addressed line.
This command differs from the
.I a\^
command only in the placement of the
input
text.
Address 0 is not legal for this command.
.HP
.B (\|.\|,\|.+1\|)j
.br
The
.IR j oin
command joins contiguous lines by removing the appropriate new-line characters.
If only one address is given, this command does nothing.
.HP
.BI (\|.\|)k x\^
.br
The mar\f2k\fP\^ command marks the addressed line with
name
.IR x ,
which must be a lower-case letter.
The address \f2\(fmx\fP\^ then addresses this line;
\&\f3.\fP is unchanged.
.HP
.B (\|.\|,\|.\|)l
.br
The
.IR l ist
command
prints the addressed lines in an unambiguous way:
a few non-printing characters (e.g.,
.IR "tab, backspace" )
are represented by (hopefully) mnemonic overstrikes, all other non-printing
characters are
printed in octal,
and long lines are folded.
An
.I l\^
command may be appended to any other command
other than
.IR e ,
.IR f ,
.IR r ,
or
.IR w .
.HP
.BI (\|.\|,\|.\|)m a\^
.br
The
.IR m ove
command repositions the addressed line(s) after the line
addressed by
.IR a .
Address 0 is legal for
.I a\^
and causes the addressed line(s) to be moved to
the beginning of the file;
it is an error if address
.I a\^
falls within the range of moved lines;
\&\f3.\fP is left at the last line moved.
.HP
.B (\|.\|,\|.\|)n
.br
The
.IR n umber
command prints the addressed lines,
preceding each line by its
line number and a tab character;
\&\f3.\fP is left at the last line printed.
The
.I n\^
command
may
be appended to any other command
other than
.IR e ,
.IR f ,
.IR r ,
or
.IR w .
.HP
.B (\|.\|,\|.\|)p
.br
The
.IR p rint
command prints the addressed lines;
\&\f3.\fP is left at the last line printed.
The
.I p\^
command
may
be appended to any other command
other than
.IR e ,
.IR f ,
.IR r ,
or
.IR w ;
for example, \f2dp\fP\^
deletes the current line and prints the
new current line.
.HP
.br
.B P
.br
The editor will prompt with a \f3\(**\fP for
all subsequent commands.
The
.I P\^
command alternately turns this mode on and off; it is
initially off.
.HP
.B q
.br
The
.IR q uit
command causes
.I ed\^
to exit.
No automatic write
of a file is done
(but see
.SM
.I DIAGNOSTICS\^
below).
.HP
.br
.B Q
.br
The editor exits without
checking if changes have been made in the buffer since the
last
.I w\^
command.
.HP
.BI (\|$\|)r " file\^"
.br
The
.IR r ead
command
reads in the given file after the addressed line.
If no file name is given,
the currently-remembered file name, if any, is used
(see
.I e\^
and
.I f\^
commands).
The currently-remembered file name is
.I not\^
changed unless
.I file\^
is the very first file name
mentioned
since
.I ed\^
was invoked.
Address 0 is legal for
.I r\^
and causes the
file to be read at the beginning of the buffer.
If the read is successful, the number of characters
read is typed;
\&\f3.\fP is set to the last line read in.
If
.I file\^
begins with \f3!\fP, the rest of the line
is taken to be a
shell (\f2sh\fP\^(1))
command whose output is to be read.
Such a
shell
command is
.I not\^
remembered as the current file name.
.HP
.BI (\|.\|,\|.\|)s/ \s-1RE\s+1 / replacement /\^
\ \ \ \ \ \ \ \ or
.br
.ns
.HP
.BI (\|.\|,\|.\|)s/ \s-1RE\s+1 / replacement /g\^
.br
The
.IR s ubstitute
command searches each addressed
line for an occurrence of the specified \s-1RE\s+1.
In each line in which a match is found,
all (non-overlapped) matched strings are
replaced by the
.I replacement\^
if the global replacement indicator \f3g\fP appears after the command.
If the global indicator does not appear, only the first occurrence
of the matched string is replaced.
It is an error for the substitution to fail on
.I all\^
addressed lines.
Any character other than space or new-line
may be used instead of \f3/\fP to delimit the \s-1RE\s+1
and
the
.IR replacement ;
\&\f3.\fP is left at the last line on which a substitution occurred.
See also the last paragraph before
.SM
.I FILES\^
below.
.IP
An ampersand (\^\f3&\fP\^) appearing in the
.I replacement\^
is replaced by the string matching the \s-1RE\s+1 on the current line.
The special meaning of \f3&\fP in this context may be
suppressed by preceding it by \f3\^\e\fP.
As a more general feature,
the characters
\f3\^\e\fP\f2n\fP\^,
where
.I n\^
is a digit,
are replaced by the text matched by the
.IR n -th
regular subexpression
of the specified \s-1RE\s+1
enclosed between \f3\^\e(\fP and \f3\^\e)\fP.
When
nested parenthesized subexpressions
are present,
.I n\^
is determined by counting occurrences of \f3\^\e(\fP starting from the left.
When the character \f3%\fP is the only character
in the
.IR replacement ,
the
.I replacement\^
used in the most recent substitute
command is used as the
.I replacement\^
in the current substitute command.
The \f3%\fP loses its special meaning when it is
in a replacement string of more than one
character or is preceded by a \f3\^\e\fP.
.IP
A line may be split by substituting a new-line character into it.
The new-line in the
.I replacement\^
must be escaped by preceding it by \f3\^\e\fP.
Such substitution cannot be done as part of a
.I g\^
or
.I v\^
command list.
.HP
.BI (\|.\|,\|.\|)t a\^
.br
This command acts just like the
.I m\^
command, except that a
.I copy\^
of the addressed lines is placed
after address
.I a\^
(which may be 0);
\&\f3.\fP is left at the last line of the copy.
.HP
.B u
.br
The
.IR u ndo
command nullifies the effect of the most recent
command that modified anything in the buffer, namely
the most recent
.IR a ,
.IR c ,
.IR d ,
.IR g ,
.IR i ,
.IR j ,
.IR m ,
.IR r ,
.IR s ,
.IR t ,
.IR v ,
.IR G ,
or
.I V\^
command.
.HP
.BI (\|1\|,\|$\|)v/ \s-1RE\s+1 / "command list\^"
.br
This command is the same as the global command
.I g\^
except that the
.I "command list\^"
is executed
with \f3.\fP initially set to every line
that does
.I not\^
match the
\s-1RE\s+1.
.HP
.BI (\|1\|,\|$\|)V/ \s-1RE\s+1 /\^
.br
This command is the same as the interactive global command
.I G\^
except
that the lines that are marked during the first step are those that do
.I not\^
match the
\s-1RE\s+1.
.HP
.BI (\|1\|,\|$\|)w " file\^"
.br
The
.IR w rite
command writes the addressed lines into
the named file.
If the file does not exist,
it is created with mode 666 (readable and writable by everyone),
unless your
.I umask\^
setting
(see
.IR sh (1))
dictates otherwise.
The currently-remembered file name is
.I not\^
changed unless
.I file\^
is the very first file name mentioned since
.I ed\^
was invoked.
If no file name is given,
the currently-remembered file name, if any, is used
(see
.I e\^
and
.I f\^
commands);
\&\f3.\fP is unchanged.
If the command is successful, the number of characters written is
typed.
If
.I file\^
begins with \f3!\fP, the rest of the line
is taken to be a
shell (\f2sh\fP\^(1))
command whose output is to be read.
Such a
shell
command is
.I not\^
remembered as the current file name.
.HP
.B X
.br
A key string is demanded from the standard input.
Subsequent
.IR e ,
.IR r ,
and
.IR w " commands"
will encrypt and decrypt the text
with this key by the algorithm of
.IR crypt (1).
An explicitly empty key turns off encryption.
.HP
.B (\|$\|)=
.br
The line number of the addressed line is typed;
\&\f3.\fP is unchanged by this command.
.HP
.BI ! "shell\| command\^"
.br
The remainder of the line after the \f3!\fP is sent
to the
.SM UNIX
shell (\f2sh\fP\^(1)) to be interpreted as a command.
Within the text of that command, the unescaped character
.B %
is replaced with the remembered file name;
if a
.B !
appears as the first character of the shell command,
it is replaced with the text of the previous shell command.
Thus,
.B !!
will repeat the last shell command.
If any expansion is performed, the expanded line is echoed;
\&\f3.\fP is unchanged.
.HP
.BR (\|.+1\|) <new-line>
.br
An address alone on a line causes the addressed line to be printed.
A new-line alone is equivalent to \f3.+1p\fP; it is useful
for stepping forward through the buffer.
.PP
If an interrupt signal (\s-1ASCII\s0 \s-1DEL\s0 or \s-1BREAK\s0) is sent,
.I ed\^
prints a \f3?\fP and returns to
.I its\^
command level.
.PP
Some size limitations:
512 characters per line,
256 characters per global command list,
64 characters per file name,
and 128K characters in the buffer.
The limit on the number of lines depends on the amount of user memory:
each line takes 1 word.
.PP
When reading a file,
.I ed\^
discards
.SM ASCII
.SM NUL
characters
and all characters after the last new-line.
Files
(e.g.,
.BR a.out )
that
contain characters not in the
.SM ASCII
set (bit
8 on) cannot be edited by
.IR ed .
.PP
If the closing delimiter of a \s-1RE\s+1 or of a 
replacement string (e.g., \f3/\fP) would be the last
character before a new-line,
that delimiter may be omitted, in
which case the addressed line
is printed.
The following pairs of commands are equivalent:
.PD 0
.RS
.TP 10
s/s1/s2
s/s1/s2/p
.TP
g/s1
g/s1/p
.TP
?s1
?s1?
.\s-1RE\s+1
.SH FILES
.PD 0
.TP 10
/tmp/e#
temporary;
# is the process number.
.TP
ed\s+4.\s-4hup
work is saved here if the terminal is hung up.
.SH DIAGNOSTICS
.TP 10
.B ?
for command errors.
.TP
.BI ? file\^
for an inaccessible file.
.br
(use the
.IR h elp
and
.IR H elp
commands for detailed explanations).
.PD
.PP
If changes have been made in the buffer since the last
.I w\^
command that wrote the entire buffer,
.I ed\^
warns the user if an attempt is made to destroy
.IR ed 's
buffer via the
.I e\^
or
.I q\^
commands:
it
prints
.B ?
and
allows one to continue editing.
A second
.I e\^
or
.I q\^
command
at this point will take effect.
The \f3\-\fP command-line option inhibits this feature.
.SH "SEE ALSO"
crypt(1), grep(1), sed(1), sh(1).
.br
.I
A Tutorial Introduction to the
.I
.SM UNIX
.I
Text Editor
by B.\ W. Kernighan.
.br
.I
Advanced Editing on
.I
.SM UNIX
by B.\ W. Kernighan.
.SH CAVEATS AND BUGS
A
.IR  !
command cannot be subject to a
.I g\^
or a
.I v\^
command.
.br
The
.IR  !
command
and the
.B !
escape from the
.IR e ,
.IR r ,
and
.I w\^
commands
cannot be used if the the editor is invoked from a restricted
shell (see
.IR sh (1)).
.br
The sequence \f3\^\en\fP in a \s-1RE\s+1 does not
match any character.
.br
The
.I l\^
command mishandles
.SM DEL.
.br
Files encrypted directly with the
.IR crypt (1)
command with the null key cannot be edited.
.br
Because 0 is an illegal address for the
.I w\^
command, it is not possible to create an
empty file with
.IR ed .