ex (text editor)
ex
( /usr/bin/ex
) is a line-oriented editor and part of Unix and Unix -like systems. It belongs to a family of editors that include those that can be used interactively ( ed
and vi
), but also those for batch operation ( sed
) and that are derived from one another.
ex
is standardized in terms of functionality and behavior by the POSIX standard.
history
The original ex
was an expanded version of the - then - Unix standard editor ed
, which in turn was part of the Berkeley Software Distribution (BSD). The further development ex
improved ed
the user friendliness in comparison to, above all, without affecting the basic concept of the line-oriented editor. Bill later took Joyex
as the basis and developed the vi editor - first in the form of a macro package and later as an independent program . Therefore, the can vi
also be ex
switched to a mode with a command .
use
configuration
Setting options differ from system to system due to slightly different implementations, even if there is always a common base. All currently valid settings can be set all
displayed during the session using the command . The following example shows this as well as the program call itself on a current AIX system (oslevel 7100-04-02-1614). The highlighting is not present in the original and is only used for clarification:
$ ex .kshrc ".kshrc" 129/2238 :set all autoindent mesg noshowmode autoprint nomodeline noslowopen noautowrite nonumber tabstop=8 nobeautify nonovice taglength=0 closepunct='".,;)]} nooptimize tags=tags /usr/lib/tags directory=/var/tmp paragraphs=IPLPPPQPP LIpplpipbp backtag noedcompatible partialcharacter=- term=xterm-r5 noerrorbells prompt terse exrc noreadonly timeout noflash redraw ttytype=xterm-r5 hardtabs=8 remap warn history=0 report=5 window=39 noignorecase scroll=19 wrapscan linelimit=1048560 sections=NHSHH HUuhsh+c wrapmargin=0 nolisp shell=/usr/bin/ksh nowriteany nolist shiftwidth=5 wraptype=word magic noshowmatch
Settings are either declarative in nature, where an identifier is assigned a value (see, for example, ttytype in the example ) or logical. In the case of logical settings, the identifier is traditionally switched off with a preceding prefix no
and switched on without this prefix (see for example nonumber , the command set number
switches on the output of line numbers, switches set nonumber
this behavior off).
The instructions for setting ex
are taken from files when the program starts. System-wide settings are in /etc/exrc
. User-related settings are in $HOME/.exrc
. If the option is exrc
set, the file is ./.exrc
evaluated.
Settings are also taken from the environment variable EXINIT
.
Often the functionality of is provided ex
by other programs, e.g. B. from vim . Then the file name z. B. Change the settings and to evaluate additional files ( /etc/vim/vimrc
, $HOME/.vimrc
, ./.vimrc)
.
Interactive and non-interactive use
Even if it was ex
intended for interactive use, it is still possible to transfer a list of commands to the program stdin
(either as a pipeline or as a here document ) for automated processing. This makes it possible to use the editor in a similar way as sed
for automated changes.
In the following script example, all files /some/where
with names txt
ending in are changed in such non-interactive editor sessions (each occurrence of "abc" in the first three lines in "XYZ"). Please note that, in contrast to sed
, the changed file does not first have to be saved in a temporary intermediate file and then copied over the original:
#! /bin/ksh typeset chSrc="abc" typeset chRpl="XYZ" typeset fTgt=""
for fTgt in /some/where/*txt ; do ex - "$fTgt" <<-EOF 1,3 s/$chSrc/$chRpl/g w EOF done
particularities
On some HP-UX systems it can ex
also be called by the command e
(which is then a hard link to ex
).
Web links
-
ex
: text editor - Open Group Base Specification -
ex(1)
: ex, vi, view - text editors - OpenBSD General Commands Manual - ex (P) : text editor - Debian POSIX Programmer's Manual
Individual evidence
- ^ Ex specification of the Open Group. Retrieved September 7, 2016 .