ex (text editor)

from Wikipedia, the free encyclopedia

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 ( edand vi), but also those for batch operation ( sed) and that are derived from one another.

exis standardized in terms of functionality and behavior by the POSIX standard.

history

The original exwas an expanded version of the - then - Unix standard editor ed, which in turn was part of the Berkeley Software Distribution (BSD). The further development eximproved edthe 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 vialso be exswitched 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 alldisplayed 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 noand switched on without this prefix (see for example nonumber , the command set numberswitches on the output of line numbers, switches set nonumberthis behavior off).

The instructions for setting exare 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 exrcset, the file is ./.exrcevaluated.

Settings are also taken from the environment variable EXINIT .

Often the functionality of is provided exby 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 exintended 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 sedfor automated changes.

In the following script example, all files /some/wherewith names txtending 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 exalso be called by the command e(which is then a hard link to ex).

Web links

Individual evidence

  1. ^ Ex specification of the Open Group. Retrieved September 7, 2016 .