3 Invoking ed ¶
The format for running ed is:
ed [options] [[+line] file] red [options] [[+line] file] ed [options] [[+line] '!command [arguments]']
file specifies the name of a file to read. If file is prefixed
with a bang (!), then it is interpreted as a shell command. In this case,
what is read is the standard output of file executed via sh.
To read a file whose name begins with a bang (or a hyphen), prefix the name
with ./. The default filename is set to file only if it is not
prefixed with a bang.
The file name may be preceded by ‘+line’ to set the current line to the line number specified. If line exceeds the number of lines in the file, the current line is set to the last line.
The file name may be preceded by ‘+/re’ to set the current line to the first line matching the regular expression re, or by ‘+?re’ to set the current line to the last line matching re. If re does not match any line, ed fails immediately with exit status 1 unless the option -l is specified and standard input is not a regular file.
ed supports the following options: See Syntax of command-line arguments.
-h--helpPrint an informative help message describing the options and exit.
-V--versionPrint the version number of
edon the standard output and exit. This version number should be included in all bug reports.-E--extended-regexpUse extended regular expressions instead of the basic regular expressions mandated by POSIX.
-G--traditionalForces backwards compatibility. This affects the behavior of the
edcommands ‘G’, ‘V’, ‘f’, ‘l’, ‘m’, ‘t’, and ‘!!’. If the default behavior of these commands does not seem familiar, then try invokingedwith this switch.-l--loose-exit-statusDon’t exit with bad status if a command happens to "fail" (for example if a substitution command finds nothing to replace). This can be useful when
edis invoked as the editor for crontab.-p string--prompt=stringSpecifies a command prompt string and turns prompting on. Showing the prompt string may be toggled on and off with the ‘P’ command.
-q--quiet--silentSuppress diagnostic messages written to standard error.
-r--restrictedRun in restricted mode. This mode disables editing of files out of the current directory and execution of shell commands.
-s--scriptSuppress the printing of byte counts by ‘e’, ‘E’, ‘r’, ‘w’, and ‘!’ commands, and the ‘!’ prompt after a ‘!’ command. Suppress also the messages "Newline inserted" and "Newline appended". This option does not suppress diagnostic messages written to standard error (see -q above). -s may be useful if
ed’s standard input is from a script.-v--verboseTurn help mode on; print a help message explaining the reason for each ‘?’ notification. This may be toggled on and off with the ‘H’ command. Use this option to aid in debugging ed scripts.
--strip-trailing-crStrip the carriage returns at the end of text lines in DOS files. CRs are removed only from the CR/LF (carriage return/line feed) pair ending the line. CRs at other positions in the line, including a CR finishing an unterminated line, are not removed. The CRs are not restored when saving the buffer to a file.
--unsafe-namesedrejects file names containing the control characters ‘\a’, ‘\b’, ‘\t’, ‘\v’, ‘\f’, ‘\r’, ‘\033’, and ‘\177’ unless they are allowed with this option. Newline characters in file names are rejected even if this option is specified.
Exit status: 0 for a normal exit, 1 for environmental problems (invalid command-line options, memory exhausted, command failed, etc), 2 for problems with the input file (file not found, buffer modified, I/O errors), 3 for an internal consistency error (e.g., bug) which caused ed to panic.