1N/A. \" use troff -mm
1N/A.nr C 3
1N/A.nr N 2
1N/A.SA 1 \" right justified
1N/A.ND "December 21, 1993"
1N/A.TL "311466-6713" "61175" \" charging case filing case
1N/AIntroduction to \f5ksh-93\fP
1N/A.AU "David G. Korn" DGK MH 11267 7975 3C-526B "(research!dgk)"
1N/A.TM 11267-931221-26 \" technical memo + TM numbers
1N/A.MT 1 \" memo type
1N/A.OK Shell "Command interpreter" Language UNIX \" keyword
1N/A.AS 2 \" abstract start for TM
1N/A\f5ksh-93\fP is a
1N/Amajor rewrite of \f5ksh\fP,
1N/Aa program that serves as a command language
1N/A(shell) for the UNIX*
1N/A.FS *
1N/AUNIX is a registered trademark of Novell.
1N/A.FE
1N/Aoperating system.
1N/AAs with \f5ksh\fP, \f5ksh-93\fP
1N/Ais essentially compatible with the System V version of the Bourne shell\*(Rf,
1N/A.RS
1N/AS. R. Bourne,
1N/A.I "An Introduction to the UNIX
1N/AShell,"
1N/ABSTJ - Vol. 57, No. 6 part 2, pages 1947-1972, 1978.
1N/A.RF
1N/Aand compatible with previous versions of \f5ksh\fP.
1N/A\f5ksh-93\fP is intended to comply with the IEEE POSIX 1003.2
1N/Aand ISO 9945-2\*(Rf
1N/A.RS
1N/A.I "POSIX \- Part 2: Shell and Utilities,"
1N/AIEEE Std 1003.2-1992, ISO/IEC 9945-2, IEEE, 1993.
1N/A.RF
1N/Ashell standard.
1N/AIn addition to changes in the language required
1N/Aby these standards, the primary focus of \f5ksh-93\fP
1N/Ais related to shell programming.
1N/A\f5ksh-93\fP provides the programming power of several
1N/Aother interpretive languages such as \f5awk\fP\*(Rf,
1N/A.RS
1N/AAl Aho,
1N/ABrian Kernighan,
1N/Aand
1N/APeter Weinberger,
1N/A.I "The AWK Programming Language,"
1N/AAddison Wesley, 1988.
1N/A.RF
1N/A\f5FIT\fP\*(Rf,
1N/A.RS
1N/ALloyd H. Nakatani and Laurence W. Ruedisueli,
1N/A.I "The FIT Programming Language Primer",
1N/ATM 1126-920301-03, 1992.
1N/A.RF
1N/A\f5PERL\fP\*(Rf,
1N/A.RS
1N/ALarry Wall and Randal Schwartz,
1N/A.I "Programming perl,"
1N/AO'Reilly & Assoc, 1990.
1N/A.RF
1N/Aand
1N/A\f5tcl\fP\*(Rf.
1N/A.RS
1N/AJohn K. Ousterhout,
1N/A.I "Tcl: An Embeddable Command Language",
1N/AProceedings of the Washington USENIX meeting, pp. 133-146, 1990.
1N/A.RF
1N/A.P
1N/AThis memo
1N/Aassumes that the reader is already familiar with the Bourne shell.
1N/AIt introduces most of the features of \f5ksh-93\fP
1N/Arelative to the Bourne shell; both
1N/Aas a command language and as a programming language.
1N/AThe Appendix contains
1N/Aa sample script written in \f5ksh-93\fP.
1N/A.AE \" abstract end
1N/A.H 1 "INTRODUCTION"
1N/A.P
1N/AThe term "shell" is used to describe a program that provides
1N/Aa command language
1N/Ainterface.
1N/ABecause the UNIX*\
1N/A.FS *
1N/AUNIX is a registered trademark of USL
1N/A.FE
1N/Asystem shell is a user level program, and not part of
1N/Athe operating system itself,
1N/Aanyone can write a new shell or modify an existing one.
1N/AThis has caused an evolutionary progress
1N/Ain the design and implementation of shells,
1N/Awith the better ones surviving.
1N/AThe most widely available UNIX system shells are the Bourne shell\*(Rf,
1N/A.RS
1N/AS. R. Bourne,
1N/A.IR "An Introduction to the UNIX Shell" ,
1N/ABell System Technical Journal,
1N/AVol. 57, No. 6, Part 2, pp. 1947-1972, July 1978.
1N/A.RF
1N/Awritten by Steve Bourne
1N/Aat AT&T Bell Laboratories,
1N/Athe C shell\*(Rf,
1N/A.RS
1N/AW. Joy,
1N/A.IR "An Introduction to the C Shell" ,
1N/AUnix Programmer's Manual, Berkeley Software Distribution,
1N/AUniversity of California, Berkeley, 1980.
1N/A.RF
1N/Awritten by Bill Joy at the University of California, Berkeley,
1N/Aand the KornShell language \*(Rf,
1N/A.RS
1N/AMorris Bolsky and David Korn,
1N/A.IR "The KornShell Command and Programming Language" ,
1N/APrentice Hall, 1989.
1N/A.RF
1N/Awritten by David Korn
1N/Aat AT&T Bell Laboratories.
1N/AThe Bourne shell is available on almost all versions of the UNIX
1N/Asystem.
1N/AThe C Shell is available with all Berkeley Software Distribution (BSD) UNIX systems and on many other systems.
1N/AThe KornShell
1N/Ais available on System V Release 4 systems.
1N/AIn addition, it is available on many other systems.
1N/AThe source for the KornShell language is available from the AT&T Toolchest,
1N/Aan electronic software distribution system.
1N/AIt runs on all known versions of the UNIX system and
1N/Aon many UNIX system look-alikes.
1N/A.P
1N/AThere have been several articles comparing the UNIX system shells.
1N/AJason Levitt\*(Rf
1N/A.RS
1N/AJason Levitt,
1N/A.IR "The Korn Shell: An Emerging Standard" ,
1N/AUNIX/World, pp. 74-81, September 1986.
1N/A.RF
1N/Ahighlights some of the new features
1N/Aintroduced by the KornShell language.
1N/ARich Bilancia\*(Rf
1N/A.RS
1N/ARich Bilancia,
1N/A.IR "Proficiency and Power are Yours With the Korn Shell" ,
1N/AUNIX/World, pp. 103-107, September 1987.
1N/A.RF
1N/Aexplains some of the advantages of using the KornShell language.
1N/AJohn Sebes\*(Rf
1N/A.RS
1N/AJohn Sebes,
1N/A.I "Comparing UNIX Shells,"
1N/AUNIX Papers,
1N/AEdited by the Waite Group, Howard W. Sams & Co., 1987.
1N/A.RF
1N/Aprovides a more detailed comparison of the three shells,
1N/Aboth as a command language and as a programming language.
1N/A.P
1N/AThe KornShell language is a superset of the
1N/ABourne shell. The KornShell language has many of the popular C shell features,
1N/Aplus additional features of its own.
1N/AIts initial popularity stems primarily from its improvements as
1N/Aa command language.
1N/AThe primary interactive benefit of the KornShell command language
1N/Ais a visual command line editor that allows you to
1N/Amake corrections to your current command line
1N/Aor to earlier command lines,
1N/Awithout having to retype them.
1N/A.P
1N/AHowever,
1N/Ain the long run,
1N/Athe power of the KornShell language as a high-level programming language,
1N/Aas described by Dolotta and Mashey\*(Rf,
1N/A.RS
1N/AT. A. Dolotta and J. R. Mashey,
1N/A.I "Using the shell as a Primary Programming Tool,"
1N/AProc. 2nd. Int. Conf. on Software Engineering, 1976,
1N/Apages 169-176.
1N/A.RF
1N/Amay prove to be of greater significance.
1N/A\f5ksh-93\fP provides the programming power of several
1N/Aother interpretive languages such as \f5awk\fP,
1N/A\f5FIT\fP,
1N/A\f5PERL\fP,
1N/Aand
1N/A\f5tcl\fP.
1N/AAn application that was originally written in the C programming language
1N/Awas rewritten in the KornShell language.
1N/AMore than 20,000 lines of C code were replaced with KornShell scripts
1N/Atotaling fewer than 700 lines.
1N/AIn most instances there was no perceptible difference in performance
1N/Abetween the two versions of the code.
1N/A.P
1N/AThe KornShell language has been embedded into windowing systems
1N/Aallowing graphical user interfaces to be developed in shell
1N/Arather than having to build applications that need to be
1N/Acompiled.
1N/AThe \f5wksh\fP program\*(Rf
1N/A.RS
1N/AJ. S. Pendergrast,
1N/A.IR "WKSH - Korn Shell with X-Windows Support",
1N/AUSL. 1991.
1N/A.RF
1N/Aprovides a method of developing OpenLook or Motif
1N/Aapplications as \f5ksh\fP scripts.
1N/A.P
1N/AThis memo is an introduction to \f5ksh-93\fP,
1N/Athe program that implements an enhanced version
1N/Aof the KornShell language.
1N/AIt is referred to as \f5ksh\fP in the rest of this memo.
1N/AThe memo describes the KornShell language based on the
1N/Afeatures of the 12/28/93 release of \f5ksh\fP.
1N/AThis memo is not a tutorial, only an introduction.
1N/AThe second edition of reference [9] gives
1N/Aa more complete treatment of the KornShell language.
1N/A.P
1N/AA concerted effort has been made to achieve both System V Bourne shell
1N/Acompatibility and IEEE POSIX compatibility
1N/Aso that scripts written for either of these shells
1N/Acan run without modification with \f5ksh\fP.
1N/AIn addition, \f5ksh-93\fP attempts to
1N/Abe compatible with older versions of \f5ksh\fP.
1N/AWhen there are conflicts between versions of the shell,
1N/A\f5ksh-93\fP selects the behavior dictated by the IEEE POSIX
1N/Astandard.
1N/AThe description of features in this memo assumes
1N/Athat the reader is already familiar with the Bourne shell.
1N/A.H 1 "COMMAND LANGUAGE"
1N/AThere is no separate command language.
1N/AAll features of the language, except job control,
1N/Acan be
1N/Aused both within a script and interactively from a terminal.
1N/AHowever, features that are more likely to be used
1N/Awhile running commands interactively from a terminal
1N/Aare presented here.
1N/A.H 2 "Setting Options"
1N/ABy convention, UNIX commands
1N/Aconsist of a command name followed by options and other arguments.
1N/AOptions are either of the form \f5-\fP\fIletter\fP,
1N/Aor \f5-\fP\fIletter value\fP.
1N/AIn the former case, several options may be grouped after a single \f5-\fP.
1N/AThe argument \f5--\fP signifies an end to the option list and is
1N/Aonly required when the first non-option argument begins with
1N/Aa \f5-\fP.
1N/AMost commands print an error message which
1N/Ashows which options are permitted
1N/Awhen given incorrect arguments.
1N/AIn addition, the option sequence \f5-?\fP causes most commands
1N/Ato print a usage message which lists the valid options.
1N/A.P
1N/AOrdinarily, \f5ksh\fP executes a command by
1N/Ausing the command name to locate a program to run
1N/Aand by running the program as a separate process.
1N/ASome commands, referred to as
1N/A.IR built-ins ,
1N/Aare carried out by \f5ksh\fP itself,
1N/Awithout creating a separate process.
1N/AThe reasons that some commands are built-in are presented later.
1N/AIn nearly all cases the distinction
1N/Abetween a command that is built-in and one that
1N/Ais not is invisible to the user.
1N/AHowever, nearly
1N/Aall commands that are built-in follow command line conventions.
1N/A.P
1N/A\f5ksh\fP has several options that can be set by the user
1N/Aas command line arguments at invocation and as option arguments to the
1N/A\f5set\fP command.
1N/AMost other options can be set with a single letter option or as a name
1N/Athat follows the \f5-o\fP option.
1N/AUse
1N/A\f5set\ -o\fP
1N/Ato display the current option settings.
1N/ASome of these options, such as
1N/A.B interactive
1N/Aand
1N/A.B monitor
1N/A(see
1N/A.I "Job Control"
1N/Abelow),
1N/Aare enabled automatically by \f5ksh\fP
1N/Awhen the shell is connected to a terminal device.
1N/AOther options, such as
1N/A.B noclobber
1N/Aand
1N/A.BR ignoreeof ,
1N/Aare normally placed in a startup file.
1N/AThe
1N/A.B noclobber
1N/Aoption causes
1N/A\f5ksh\fP
1N/Ato print an error message when you use
1N/A.B >
1N/Ato redirect output to a file that already exists.
1N/AIf you want to redirect to an existing file, then
1N/Ayou have to use
1N/A.B >|
1N/Ato override
1N/Athe
1N/A.B noclobber
1N/Aoption.
1N/AThe
1N/A.B ignoreeof
1N/Aoption
1N/Ais used to prevent the
1N/A.I end-of-file
1N/Acharacter, normally
1N/A.B ^D
1N/A(Control- d),
1N/Afrom exiting the shell and possibly logging you out.
1N/AYou must type \f5exit\fP
1N/Ato log out.
1N/AMost of the options are described in this memo as appropriate.
1N/A.H 2 "Command Aliases"
1N/A.P
1N/ACommand aliases provide a mechanism of associating a command name and
1N/Aarguments with a shorter name.
1N/AAliases are defined with the \f5alias\fP
1N/Abuilt-in.
1N/AThe form of an \f5alias\fP
1N/Acommand definition is:
1N/A.ce
1N/A\f5alias\fP \fIname\fP\f5=\fP\fIvalue\fP
1N/AAs with most other shell assignments, no space is allowed before or after
1N/Athe \f5=\fP.
1N/AThe characters of an alias name cannot be characters that are
1N/Aspecial to the shell.
1N/AThe replacement string,
1N/A.I value,
1N/Acan contain any valid shell script,
1N/Aincluding meta-characters such as pipe symbols and i/o-redirection
1N/Aprovided that they are quoted.
1N/AUnlike
1N/A\f5csh\fP,
1N/Aaliases in
1N/A\f5ksh\fP
1N/Acannot take arguments.
1N/AThe equivalent functionality of aliases with arguments can
1N/Abe achieved with shell functions, described later.
1N/A.P
1N/AAs a command is being read,
1N/Athe command name is checked against a list of
1N/A.I alias
1N/Anames.
1N/AIf it is found,
1N/Athe name is replaced by the alias value associated with the
1N/A.I alias
1N/Aand then rescanned.
1N/AWhen rescanning the value for an alias, alias substitutions
1N/Aare performed except for an alias that is currently being processed.
1N/AThis prevents infinite loops in alias substitutions.
1N/AFor example with the aliases, \f5alias\ l=ls\ 'ls=ls\ -C'\fP,
1N/Athe command name \f5l\fP becomes \f5ls\fP, which becomes \f5ls\ -C\fP.
1N/AOrdinarily, only the command name word is processed for alias substitution.
1N/AHowever, if the value of an alias ends in a space,
1N/Athen the word following the alias is also checked for alias substitution.
1N/AThis makes it possible
1N/Ato define an alias whose first argument is the name of a command
1N/Aand have alias substitution performed on this argument,
1N/Afor example
1N/A\f5nohup='nohup\ '\fP.
1N/A.P
1N/AAliases can be used to redefine built-in commands so that
1N/Athe alias,
1N/A.ce
1N/A\f5alias test=./test\fP
1N/Acan be used to look for \f5test\fP
1N/Ain your current working directory rather than
1N/Ausing the built-in \f5test\fP command.
1N/AReserved words such as
1N/A\f5for\fP and \f5while\fP
1N/Acannot be changed by aliasing.
1N/AThe command \f5alias\fP,
1N/Awithout arguments, generates
1N/Aa list of aliases and corresponding alias values.
1N/AThe \f5unalias\fP command removes the name and text of an alias.
1N/A.P
1N/AAliases are used to save typing and to improve readability of scripts.
1N/ASeveral aliases are predefined by \f5ksh\fP.
1N/AFor example, the predefined alias
1N/A.ce
1N/A\f5alias integer='typeset -i'\fP
1N/Aallows the integer variables \f5i\fP and \f5j\fP
1N/Ato be declared and initialized with the command
1N/A.ce
1N/A\f5integer i=0 j=1\fP
1N/A.P
1N/AWhile aliases can be defined in scripts,
1N/Ait is not recommended.
1N/AThe location of an alias command can be important
1N/Asince aliases are only processed when a command is read.
1N/AA \fB\s+2.\s-2\fP
1N/Aprocedure (the shell equivalent of an include file)
1N/Ais read all at once (unlike
1N/Astart up files
1N/Awhich are read a command at
1N/Aa time) so that any aliases defined there will not effect any commands
1N/Awithin this script.
1N/APredefined aliases do not have this problem.
1N/A.H 2 "Command Re-entry"
1N/A.P
1N/AWhen run interactively,
1N/A\f5ksh\fP saves the
1N/Acommands you type at a terminal in a file.
1N/AIf the variable
1N/A\fB\s-1HISTFILE\s+1\fP
1N/Ais set to the name of a file to which the user
1N/Ahas write access,
1N/Athen the commands are stored in this
1N/A.I history
1N/Afile.
1N/AOtherwise the file
1N/A\fB$\s-1HOME\s+1/.sh_history\fP
1N/Ais checked for write access and if this fails
1N/Aan unnamed file is used to hold the history lines.
1N/ACommands are always appended to this file.
1N/AInstances of \f5ksh\fP
1N/Athat run concurrently and use the same history file
1N/Aname, share access to the history file so that a command
1N/Aentered in one shell will be available for editing in another
1N/Ashell.
1N/AThe file may be truncated when \f5ksh\fP
1N/Adetermines that no other shell is using the history file.
1N/AThe number of commands accessible to the user is determined by the value of the
1N/A\fB\s-1HISTSIZE\s+1\fP
1N/Avariable at the time the shell is invoked.
1N/AThe default value is 256.
1N/AEach command may consist of one or more lines since a compound
1N/Acommand is considered one command.
1N/AIf the character
1N/A.B !
1N/Ais placed within the
1N/A.I "primary prompt"
1N/Astring,
1N/A\fB\s-1PS1\s+1\fP,
1N/Athen it is replaced by the command number each time the prompt is given.
1N/A.P
1N/AA built-in command named \f5hist\fP
1N/Ais used to list and/or edit
1N/Aany of these saved commands.
1N/AThe option
1N/A.B \-l
1N/Ais used to specify listing of previous commands.
1N/AThe command can always be specified with
1N/Aa range of one or more commands.
1N/AThe range can be specified by giving the command
1N/Anumber, relative or absolute, or by giving
1N/Athe first character or characters of the command.
1N/AWhen given without specifying the range,
1N/Athe last 16
1N/Acommands are listed, each
1N/Apreceded by the command number.
1N/A.P
1N/AIf the listing option is not selected,
1N/Athen the range of commands specified,
1N/Aor the last command if no range is given,
1N/Ais passed to an editor program before
1N/Abeing re-executed by \f5ksh\fP.
1N/AThe editor to be used may be specified
1N/Awith the option
1N/A.B \-e
1N/Aand following it with the editor name.
1N/AIf this option is not specified, the
1N/Avalue of the shell variable
1N/A\fB\s-1HISTEDIT\s+1\fP
1N/Ais used as the name of the editor,
1N/Aproviding that this variable has a non-null value.
1N/AIf this variable is not set, or is null,
1N/Aand the
1N/A.B \-e
1N/Aoption has not been selected,
1N/Athen
1N/A\f5/bin/ed\fP
1N/Ais used.
1N/AWhen editing has been complete,
1N/Athe edited text automatically becomes
1N/Athe input for \f5ksh\fP.
1N/AAs this text is read by \f5ksh\fP, it is echoed onto the terminal.
1N/A.P
1N/AThe
1N/A.B \-s
1N/Aoption causes the editing to be bypassed
1N/Aand just re-executes the command.
1N/AIn this case only a single command can be specified as the range
1N/Aand an optional argument of the form
1N/A\fIold\fP\fB=\fP\fInew\fP
1N/Amay be added which requests a simple string substitution
1N/Aprior to evaluation.
1N/AA convenient alias,
1N/A.ce
1N/A\f5alias r='hist -s'\fP
1N/Ahas been pre-defined so that
1N/Athe single key-stroke
1N/A\f5r\fP
1N/Acan be used to re-execute the previous command
1N/Aand the key-stroke sequence,
1N/A\f5r\ abc=def\ c\fP
1N/Acan be used to re-execute the last command that starts with
1N/Athe letter \f5c\fP
1N/Awith the first occurrence of the string \f5abc\fP
1N/Areplaced with the string \f5def\fP.
1N/ATyping
1N/A\f5r\ c\ >\ file\fP
1N/Are-executes the most recent command starting with the letter \f5c\fP,
1N/Awith standard output redirected to
1N/A.IR file .
1N/A.H 2 "In-line editing"
1N/A.P
1N/ALines typed from a terminal frequently need changes made
1N/Abefore entering them.
1N/AWith the Bourne shell the only method to fix up commands
1N/Ais by backspacing or killing the whole line.
1N/A\f5ksh\fP offers options that allow the user to edit parts of the
1N/Acurrent command line before submitting the command.
1N/AThe in-line edit options make the command line into a single
1N/Aline screen edit window.
1N/AWhen the command is longer than the width of the terminal,
1N/Aonly a portion of the command is visible.
1N/AMoving within the line automatically makes that portion visible.
1N/AEditing can be performed on this window until the
1N/A.I return
1N/Akey is pressed.
1N/AThe editing modes have editing directives that access the history file
1N/Ain which previous commands are saved.
1N/AA user can copy any of the most recent
1N/A\fB\s-1HISTSIZE\s+1\fP
1N/Acommands from this file into the input edit window.
1N/AYou can locate commands by searching or by position.
1N/A.P
1N/AThe in-line editing options do not use the
1N/A.I termcap
1N/Aor
1N/A.I terminfo
1N/Adatabases.
1N/AThey work on most standard terminals.
1N/AThey only require that the backspace character moves the cursor left
1N/Aand the space character overwrites the current character on the screen
1N/Aand moves the cursor to the right.
1N/AVery few terminals or terminal emulators do not have
1N/Athis behavior.
1N/A.P
1N/AThere is a choice of editor options.
1N/AThe
1N/A.BR emacs ,
1N/A.BR gmacs ,
1N/Aor
1N/A.B vi
1N/Aoption is selected by turning on the
1N/Acorresponding
1N/Aoption of the \f5set\fP
1N/Acommand.
1N/AIf the value of the
1N/A\fB\s-1EDITOR\s+1\fP
1N/Aor
1N/A\fB\s-1VISUAL\s+1\fP
1N/Avariables ends with any of these suffixes
1N/Athe corresponding option is turned on.
1N/AA large subset of each of these editors'
1N/Afeatures is available within the shell. Additional
1N/Afunctions, such as file name completion, have also been added.
1N/A.P
1N/AIn the
1N/A.B emacs
1N/Aor
1N/A.B gmacs
1N/Amode the user positions the cursor to the point
1N/Aneeding correction and inserts, deletes, or replaces
1N/Acharacters as needed.
1N/AThe only difference between these two modes is the
1N/Ameaning of the directive
1N/A.BR ^T .
1N/AControl keys and escape sequences are used for cursor
1N/Apositioning and control functions.
1N/AThe available editing functions are listed in the manual page.
1N/A.P
1N/AThe
1N/A.B vi
1N/Aediting mode
1N/Astarts in insert mode and enters control mode when the
1N/Auser types ESC ( 033 ).
1N/AThe
1N/A.I return
1N/Akey, which submits the current command for processing,
1N/Acan be entered from either mode.
1N/AThe cursor can be anywhere on the line.
1N/AA subset of commonly used
1N/A.I vi
1N/Aediting directives are available.
1N/AThe
1N/A.B k
1N/Aand
1N/A.B j
1N/Adirectives that normally move up and down by one
1N/A.IR line ,
1N/Amove up and down one
1N/A.I command
1N/Ain the history file,
1N/Acopying the command into the input edit window.
1N/AFor reasons of efficiency,
1N/Athe terminal is kept in canonical mode until an
1N/AESC
1N/Ais typed.
1N/AOn some terminals,
1N/Aand on earlier versions of the UNIX operating system,
1N/Athis doesn't work correctly.
1N/AThe
1N/A.B viraw
1N/Aoption,
1N/Awhich always uses
1N/A.I raw
1N/Aor
1N/A.I cbreak
1N/Amode,
1N/Amust be used in this case.
1N/A.P
1N/AMost of the code for the editing options does not rely on the
1N/A\f5ksh\fP code and can be used in a stand-alone mode with most any command
1N/Ato add in-line edit capability.
1N/AHowever,
1N/Aall versions of the in-line editors have some features that
1N/Ause some shell specific code. For example,
1N/Awith all edit modes, the
1N/AESC-=
1N/Adirective applied to command words
1N/A(the first word on the line,
1N/Aor the first word after a
1N/A.BR ; ,
1N/A.BR | ,
1N/A.BR ( ,
1N/Aor
1N/A.BR & )
1N/Alists all aliases, functions, or commands
1N/Athat match the portion of the given current word.
1N/AWhen applied to other words, this directive
1N/Aprints the names of files that match the current
1N/Aword.
1N/AThe ESC\fB-*\fP directive
1N/Aadds the expanded list of matching files to the command line.
1N/AA trailing
1N/A.B *
1N/Ais added to the word if it doesn't contain any file pattern matching
1N/Acharacters before the expansion.
1N/AIn
1N/A.B emacs
1N/Aand
1N/A.B gmacs
1N/Amode,
1N/AESC-ESC
1N/Aindicates command completion when applied to
1N/Acommand names, otherwise it indicates pathname completion.
1N/AWith command or pathname completion,
1N/Athe list generated by the
1N/AESC-= directive is examined to find
1N/Athe longest common prefix.
1N/AWith command completion, only the last component of
1N/Athe pathname is used to compute the longest command prefix.
1N/AIf the longest common prefix is a complete match,
1N/Athen the word is replaced by the pathname, and a
1N/A.B /
1N/Ais appended if
1N/Apathname is a directory, otherwise a space is added.
1N/AIn
1N/A.B vi
1N/Amode,
1N/A.B \e
1N/Afrom control mode gives the same behavior.
1N/A.H 2 "Key Binding"
1N/A.P
1N/AIt is possible to intercept keys as they are entered and
1N/Aapply new meanings or bindings.
1N/AA trap named
1N/A\fB\s-1KEYBD\s+1\fP
1N/Ais evaluated each time
1N/A\f5ksh\fP processes characters entered
1N/Afrom the keyboard,
1N/Aother than those typed
1N/Awhile entering a search string or an argument to an
1N/Aedit directive such as
1N/A.B r
1N/Ain vi-mode.
1N/AThe action associated with this trap can change the value of
1N/Athe entered key to cause the key to perform a different
1N/Aoperation.
1N/A.P
1N/AWhen the
1N/A\fB\s-1KEYBD\s+1\fP
1N/Atrap is entered,
1N/Athe \fB.sh.edtext\fP
1N/Avariable contains the contents of the current input line
1N/Aand the \fB.sh.edcol\fP
1N/Avariable gives the current cursor position within this line.
1N/AThe \fB.sh.edmode\fP
1N/Avariable contains the
1N/A.B ESC
1N/Acharacter when the trap is entered from
1N/A.B vi
1N/Ainsert mode.
1N/AOtherwise, this value is null.
1N/AThe \fB.sh.edchar\fP
1N/Avariable contains the character or
1N/Aescape sequence that caused the trap.
1N/AA key sequence is either a single character,
1N/A.B ESC
1N/Afollowed by a single character,
1N/Aor
1N/A.B ESC[
1N/Afollowed by a single character.
1N/AIn the \fBvi\fP edit mode,
1N/Athe characters after the
1N/A.B ESC
1N/Amust be entered within half a second after the
1N/A.BR ESC .
1N/AThe value of \fB.sh.edchar\fP
1N/Aat the end of the trap will be used as
1N/Athe input sequence.
1N/A.P
1N/AUsing the associative array facility of \f5ksh\fP described later,
1N/Aand the function facility of \f5ksh\fP, it is easy to write
1N/Aa single trap so that keys can be bound dynamically. For example,
1N/A.sp
1N/A.nf
1N/A.in .5i
1N/A.ta 4i
1N/A\f5typeset -A Keytable
1N/Atrap 'eval "${Keytable[${.sh.edchar}]}"' KEYBD
1N/Afunction keybind # key action
1N/A{
1N/A typeset key=$(print -f "%q" "$2")
1N/A case $# in
1N/A 2) Keytable[$1]='.sh.edchar=${.sh.edmode}'"$key"
1N/A ;;
1N/A 1) unset Keytable[$1]
1N/A ;;
1N/A *) print -u2 "Usage: $0 key [action]"
1N/A ;;
1N/A esac
1N/A}\fP
1N/A.ta
1N/A.in
1N/A.fi
1N/A.sp
1N/A.H 2 "Job Control"
1N/A.P
1N/AThe job control mechanism
1N/Ais almost identical to the version introduced in \f5csh\fP
1N/Aof the Berkeley UNIX operating system,
1N/Aversion 4.1 and later.
1N/AThe job control feature allows the user to stop and
1N/Arestart programs, and to move programs to and from the
1N/Aforeground and the background.
1N/AIt will only work on systems that provide support for
1N/Athese features.
1N/AHowever,
1N/Aeven systems without job control have a
1N/A.B monitor
1N/Aoption which, when enabled, will report the progress
1N/Aof background jobs and enable the user to \f5kill\fP
1N/Ajobs by job number or job name.
1N/A.P
1N/AAn interactive shell associates a
1N/A.I job
1N/Awith each pipeline typed in from the terminal
1N/Aand assigns it a small integer number
1N/Acalled the job number.
1N/AIf the job is run asynchronously,
1N/Athe job number is printed at the terminal.
1N/AAt any given time, only one job owns the terminal,
1N/Ai.e., keyboard signals are only sent to the processes in one job.
1N/AWhen \f5ksh\fP creates a foreground job,
1N/Ait gives it ownership of the terminal.
1N/AIf you are running a job and wish to stop
1N/Ait you hit the key
1N/A.B ^Z
1N/A(control-\fBZ\fP)
1N/Awhich sends a
1N/A\fB\s-1STOP\s+1\fP
1N/Asignal to all processes in the current job.
1N/AThe shell receives notification that the processes
1N/Ahave stopped and takes back control of the terminal.
1N/A.P
1N/AThere are commands to continue programs in the foreground
1N/Aand background.
1N/AThere are several ways to refer to jobs.
1N/AThe character
1N/A.B %
1N/Aintroduces a job name.
1N/AYou can refer to jobs by name or number as described in the manual page.
1N/AThe built-in command \f5bg\fP
1N/Aallows you to continue a job in the background,
1N/Awhile the built-in command \f5fg\fP
1N/Aallows you to continue a job in the foreground even
1N/Athough you may have started it in the background.
1N/A.P
1N/AA job being run in the background will stop if it tries
1N/Ato read from the terminal.
1N/AIt is also possible to stop background jobs that try to write on
1N/Athe terminal by setting the terminal options
1N/Aappropriately.
1N/A.P
1N/AThere is a built-in command \f5jobs\fP
1N/Athat lists the status of all running and stopped jobs.
1N/AIn addition,
1N/Ayou are informed of the change of state (running or stopped)
1N/Aof any background
1N/Ajobs just before each prompt.
1N/AIf you want to be notified about background job completions
1N/Aas soon as they occur without waiting for a prompt, then use the
1N/A.B notify
1N/Aoption.
1N/AWhen you try to exit the shell while jobs are stopped or running,
1N/Ayou will receive a message from \f5ksh\fP.
1N/AIf you ignore this message and try to exit again,
1N/Aall stopped processes will be terminated.
1N/AIn addition, for login shells, the
1N/A\fB\s-1HUP\s+1\fP
1N/Asignal will be sent to
1N/Aall background jobs
1N/Aunless the job has been disowned with the
1N/A.B disown
1N/Acommand.
1N/A.P
1N/AA built-in version of \f5kill\fP
1N/Amakes it possible to use
1N/A.I job
1N/Anumbers as targets for signals.
1N/ASignals can be selected by number or name.
1N/AThe name of the signal is the name found in the
1N/A.I include
1N/Afile
1N/A.B /usr/include/sys/signal.h
1N/Awith the prefix
1N/A.B \s-1SIG\s+1
1N/Aremoved.
1N/AThe
1N/A.B \-l
1N/Aoption of \f5kill\fP
1N/Aprovides a means to map individual signal names to and from
1N/Asignal number.
1N/AIn addition, if no signal name or number is given,
1N/A\f5kill\ -l\fP
1N/Agenerates a list of valid signal names.
1N/A.H 2 "Changing Directories"
1N/ABy default,
1N/A\f5ksh\fP
1N/Amaintains a logical view of the file system hierarchy
1N/Awhich makes symbolic links transparent.
1N/AFor systems that have symbolic links,
1N/Athis means that if \f5/bin\fP is a symbolic link to \f5/usr/bin\fP
1N/Aand you change directory to \f5/bin\fP, \f5pwd\fP will indicate
1N/Athat you are in \f5/bin\fP, not \f5/usr/bin\fP.
1N/A\f5pwd\ -P\fP
1N/Agenerates the physical pathname of the present working
1N/Adirectory by resolving all the symbolic links.
1N/ABy default,
1N/Athe \f5cd\fP
1N/Acommand will take you where you expect to go even if you cross
1N/Asymbolic links.
1N/AA subsequent \f5cd\ ..\fP in the example above
1N/Awill place you in \f5/\fP, not \f5/usr\fP.
1N/AOn systems with symbolic links,
1N/A\f5cd\ -P\fP
1N/Acauses
1N/A.B ..
1N/Ato be treated physically.
1N/A.P
1N/A\f5ksh\fP remembers your last directory
1N/Ain the variable
1N/A\fB\s-1OLDPWD\s+1\fP.
1N/AThe \f5cd\fP
1N/Abuilt-in can be given with argument
1N/A.B \-
1N/Ato return to the previous directory
1N/Aand print the name of the directory.
1N/ANote that \f5cd\ -\fP
1N/Adone twice returns you to the starting directory,
1N/Anot the second previous directory.
1N/AA directory
1N/A.I stack
1N/Amanager has been written as shell
1N/A.I functions
1N/Ato
1N/A.I push
1N/Aand
1N/A.I pop
1N/Adirectories from the stack.
1N/A.H 2 "Prompts"
1N/A.P
1N/AWhen \f5ksh\fP
1N/Areads commands from a terminal,
1N/Ait issues a prompt whenever it is ready
1N/Ato accept more input and then
1N/Awaits for the user to respond.
1N/AThe
1N/A\fB\s-1TMOUT\s+1\fP
1N/Avariable
1N/Acan be set to be the number of seconds that the shell will wait for
1N/Ainput before terminating.
1N/AA 60 second warning message is printed
1N/Abefore terminating.
1N/A.P
1N/AThe shell uses two prompts.
1N/AThe primary prompt,
1N/Adefined by the value of the
1N/A\fB\s-1PS1\s+1\fP
1N/Avariable,
1N/Ais issued at the start of each command.
1N/AThe secondary prompt,
1N/Adefined by the value of the
1N/A\fB\s-1PS2\s+1\fP
1N/Avariable,
1N/Ais issued when more input is needed to complete a command.
1N/A.P
1N/A\f5ksh\fP allows the user to specify a list of files or directories
1N/Ato check before issuing the
1N/A\fB\s-1PS1\s+1\fP
1N/Aprompt.
1N/AThe variable
1N/A\fB\s-1MAILPATH\s+1\fP
1N/Ais a colon (
1N/A.B :
1N/A) separated list of file names to be checked for changes
1N/Aperiodically. The user is notified
1N/Abefore the next prompt.
1N/AEach of the names in this list can be followed by a
1N/A.B ?
1N/Aand a message to be given when a change has been detected in the file.
1N/AThe prompt will be evaluated for parameter expansion, command
1N/Asubstitution and arithmetic expansion which are described later.
1N/AThe parameter
1N/A.B $_
1N/Awithin a mail message will evaluate to the name of the file that
1N/Ahas changed.
1N/AThe parameter
1N/A\fB\s-1MAILCHECK\s+1\fP
1N/Ais used to specify the minimal interval in seconds before
1N/Anew mail is checked for.
1N/A.P
1N/AIn addition to replacing each
1N/A.B !
1N/Ain the prompt with the command number,
1N/A\f5ksh\fP expands
1N/Athe value of the
1N/A.B \s-1PS1\s+1
1N/Avariable
1N/Afor parameter expansions, arithmetic expansions,
1N/Aand command substitutions as described below
1N/Ato generate the prompt.
1N/AThe expansion characters that are to be applied when
1N/Athe prompt is issued must be quoted to prevent the
1N/Aexpansions from occurring when assigning the value to
1N/A.B \s-1PS1\s+1.
1N/AFor example,
1N/A\f3\s-1PS1\s+1="$\s-1PWD\s+1"\fP
1N/Acauses
1N/A.B \s-1PS1\s+1
1N/Ato be set to the value of
1N/A.B \s-1PWD\s+1
1N/Aat the time of the assignment whereas
1N/A.B \s-1PS1\s+1='$\s-1PWD\s+1'
1N/Acauses
1N/A.B \s-1PWD\s+1
1N/Ato be expanded at the time the prompt is issued.
1N/A.P
1N/ACommand substitution may require a separate process
1N/Ato execute and cause the prompt display to be somewhat
1N/Aslow, especially
1N/Awhen the return key is pressed several times in a row.
1N/ATherefore, its use
1N/Awithin
1N/A.B \s-1PS1\s+1
1N/Ais discouraged.
1N/ASome variables are maintained by \f5ksh\fP
1N/Aso that their values can be used with
1N/A.B \s-1PS1\s+1.
1N/AThe
1N/A.B \s-1PWD\s+1
1N/Avariable stores the pathname of the current working directory.
1N/AThe value of
1N/A.B \s-1SECONDS\s+1
1N/Avariable
1N/Ais the value of the most
1N/Arecent assignment plus the elapsed time.
1N/ABy default, the time is measured in milli-seconds,
1N/Abut since
1N/A.B \s-1SECONDS\s+1
1N/Ais a floating point variable, the
1N/Anumber of places after the decimal point in the expanded
1N/Avalue can be
1N/Aspecified with
1N/A\f5typeset\ -F\fP\fIplaces\fP\f5\ SECONDS\fP.
1N/AIn a roundabout way, this variable
1N/Acan be used to generate a time stamp into the
1N/A.B \s-1PS1\s+1
1N/Aprompt without creating a process at each prompt.
1N/AThe following code explains how you can do this on
1N/ASystem V. On BSD, you need a different command to initialize
1N/Athe
1N/A.B \s-1SECONDS\s+1
1N/Avariable.
1N/A\f5
1N/A.sp
1N/A.nf
1N/A.in .5i
1N/A# . this script and use $TIME as part of your PS1 string to
1N/A# get the time of day in your prompt
1N/Atypeset -RZ2 _x1 _x2 _x3
1N/A(( SECONDS=$(date '+3600*%H+60*%M+%S') ))
1N/A_s='_x1=(SECONDS/3600)%24,_x2=(SECONDS/60)%60,_x3=SECONDS%60,0'
1N/ATIME='"${_d[_s]}$_x1:$_x2:$_x3"'
1N/A# PS1=${TIME}whatever
1N/A.fi
1N/A.ta
1N/A.in
1N/A.sp
1N/A\fP
1N/A.H 2 "Tilde substitution"
1N/A.P
1N/AThe character
1N/A.B \(ap
1N/Aat the beginning of a word has special meaning to \f5ksh\fP.
1N/AIf the characters after the
1N/A.B \(ap
1N/Aup to a
1N/A.B /
1N/Amatch a user login name in the password database, then the
1N/A.B \(ap
1N/Aand the name are replaced by
1N/Athat user's login directory.
1N/AIf no match is found, the original word
1N/Ais unchanged.
1N/AA
1N/A.B \(ap
1N/Aby itself, or in front of a
1N/A.BR / ,
1N/Ais replaced by the value of the
1N/A\fB\s-1HOME\s+1\fP
1N/Aparameter.
1N/AA
1N/A.B \(ap
1N/Afollowed by a
1N/A.B +
1N/Aor
1N/A.B \-
1N/Ais replaced by the value of
1N/A.B $\s-1PWD\s+1
1N/Aor
1N/A.B $\s-1OLDPWD\s+1
1N/Arespectively.
1N/A.H 2 "Output formats"
1N/AThe output of built-in commands and traces have values quoted so that they
1N/Acan be re-input to the shell.
1N/AThis makes it easy to cut and paste shell output on systems
1N/Awhich use a pointing device such as a mouse.
1N/AIn addition, output can be saved in a file for reuse.
1N/A.P
1N/A.H 2 "The \fB\s-1ENV\s+1\fP file"
1N/AWhen an interactive \f5ksh\fP starts, it evaluates the
1N/A.B $\s-1ENV\s+1
1N/Avariable to arrive at a file name.
1N/AIf this value is not null,
1N/A\f5ksh\fP attempts to read and process
1N/Acommands in a file by this name.
1N/AEarlier versions of \f5ksh\fP read the \fB\s-1ENV\s+1\fP file
1N/Afor all invocations of the shell primarily to allow
1N/Afunction definitions to be available for all shell
1N/Ainvocations.
1N/AThe function search path, \fB\s-1FPATH\s+1\fP, described later,
1N/Aeliminated the primary need for this capability and it was
1N/Aremoved because the high performance cost was no longer
1N/Adeemed acceptable.
1N/A.H 1 "PROGRAMMING LANGUAGE"
1N/AThe KornShell vastly extends the set of applications that
1N/Acan be implemented efficiently at the shell level.
1N/AIt does this by providing simple yet powerful mechanisms
1N/Ato perform arithmetic, pattern matching,
1N/Asubstring generation,
1N/Aand arrays.
1N/AUsers can write applications as separate functions that can
1N/Abe defined in the same file or in a library of functions
1N/Astored in a directory and loaded on demand.
1N/A.H 2 "String Processing"
1N/AThe shell is primarily a string processing language.
1N/ABy default, variables hold variable length strings.
1N/AThere are no limits to the length of strings. Storage
1N/Amanagement is handled by the shell automatically.
1N/ADeclarations are not required.
1N/AWith most programming languages, string constants are designated
1N/Aby enclosing characters in single quotes or double quotes.
1N/ASince most of the words in the language are strings, the shell
1N/Arequires quotes only when a string contains characters that
1N/Aare normally processed specially by the shell, but their
1N/Aliteral meaning is intended.
1N/AHowever, since the shell is a string processing language,
1N/Aand some characters can occur as literals and as language metacharacters,
1N/Aquoting is an important part of the language.
1N/A.P
1N/AThere are four quoting mechanisms in \f5ksh\fP.
1N/AThe simplest is to enclose a sequence of characters inside single quotes.
1N/AAll characters between a pair of single quotes have their literal meaning;
1N/Athe single quote itself cannot appear.
1N/AA
1N/A.B $
1N/Aimmediately preceding
1N/Aa single quoted string
1N/Acauses all the characters until the matching single quote
1N/Ato be interpreted as an ANSI-C language string.
1N/AThus, \f5'\en'\fP represents characters \f5\e\fP and
1N/A\f5n\fP, whereas, \f5$'\en'\fP
1N/Arepresents the new-line character.
1N/ADouble quoted strings remove the special meaning of all characters
1N/Aexcept
1N/A.BR $ ,
1N/A.BR \(ga ,
1N/Aand
1N/A.BR \e ,
1N/Aso that parameter expansion and command substitution (defined below)
1N/Aare performed.
1N/AThe final mechanism for quoting a character is by preceding it with the
1N/Aescape character
1N/A.BR \e\^ .
1N/AThis mechanism works outside of quoted strings and for the characters
1N/A.BR $ ,
1N/A.BR \(ga ,
1N/A\fB"\fP,
1N/Aand
1N/A.B \e
1N/Ain double quoted strings.
1N/A.P
1N/AVariables are designated by
1N/Aone or more
1N/Astrings of alphanumeric
1N/Acharacters beginning with an alphabetic character
1N/Aseparated by a \fB\s+2.\s-2\fP.
1N/AUpper and lower case characters are distinct, so that the variable
1N/A.B A
1N/Aand
1N/A.B a
1N/Aare names of different variables.
1N/AThere is no
1N/Alimit to the length of the name of a variable.
1N/AYou do not have to declare variables.
1N/AYou can assign a value to a variable by writing the name of the
1N/Avariable, followed by an equal sign, followed by a character string
1N/Athat represents its value.
1N/ATo create a variable whose name
1N/Acontains a \fB\s+2.\s-2\fP,
1N/Athe variable whose name consists of
1N/Athe characters before the last \fB\s+2.\s-2\fP
1N/Amust already exist.
1N/AYou reference a variable by
1N/Aputting the name inside curly braces and
1N/Apreceding the braces with a dollar sign.
1N/AThe braces may be omitted when the name
1N/Ais alphanumeric.
1N/AIf \f5x\fP and \f5y\fP
1N/Aare two shell variables, then
1N/Ato define a new variable,
1N/A\f5z\fP,
1N/Awhose value is
1N/Athe concatenation of the values of
1N/A\f5x\fP and \f5y\fP,
1N/Ayou just say
1N/A\f5z=$x$y\fP.
1N/AIt is that easy.
1N/A.P
1N/AThe
1N/A.B $
1N/Acan be thought of as meaning
1N/A"value of."
1N/AYou can also capture the output of any command with the notation
1N/A.BI $( command ) .
1N/AThis is referred to as command substitution.
1N/AFor example,
1N/A\f5x=$(date)\fP
1N/Aassigns the output from the \f5date\fP
1N/Acommand to the variable \f5x\fP.
1N/ACommand substitution in the
1N/ABourne shell is denoted by enclosing the command between
1N/Abackquotes,
1N/A(\fB\(ga\^\(ga\fP).
1N/AThis notation
1N/Asuffers from some
1N/Acomplicated quoting rules.
1N/AThus, it is hard to write \f5sed\fP
1N/Apatterns which contains back slashes within command substitution.
1N/APutting the pattern in single quotes
1N/Ais of little help.
1N/A\f5ksh\fP accepts the Bourne shell command substitution syntax
1N/Afor backward compatibility.
1N/AThe
1N/A.BI $( command )
1N/Anotation allows
1N/Athe \fIcommand\fP itself to contain quoted strings even if the substitution
1N/Aoccurs within double quotes. Nesting is legal.
1N/A.P
1N/AThe special command substitution of the form
1N/A\f5$(cat\ file)\fP
1N/Acan be replaced by
1N/A\f5$(<\ file)\fP,
1N/Awhich is faster because
1N/Athe \f5cat\fP
1N/Acommand doesn't have to run.
1N/A.H 2 "Shell Parameters and Variables"
1N/A.P
1N/AThere are three types of parameters used by \f5ksh\fP,
1N/Aspecial parameters, positional parameters, and named
1N/Aparameters which are called variables.
1N/A\f5ksh\fP defines the same special parameters,
1N/A.BR 0 ,
1N/A.BR * ,
1N/A.BR @ ,
1N/A.BR # ,
1N/A.BR ? ,
1N/A.BR $ ,
1N/A.BR ! ,
1N/Aand
1N/A.BR \- ,
1N/Aas in the Bourne shell.
1N/A.P
1N/APositional parameters are set when the shell is invoked,
1N/Aas arguments to the \f5set\fP built-in,
1N/Aand by calls to functions (see below) and \fB\s+2.\s-2\fP
1N/Aprocedures.
1N/AThey are named by numbers starting at 1.
1N/A.P
1N/AThe third type of parameter is a variable.
1N/AAs mentioned earlier,
1N/A\f5ksh\fP uses variables whose names
1N/Aconsist of one or more
1N/Aalpha-numeric strings separated by a \fB\s+2.\s-2\fP.
1N/AThere is no need to specify the
1N/A.I type
1N/Aof a variable in the shell because, by default,
1N/Avariables store strings of arbitrary length
1N/Aand values will automatically be converted to numbers
1N/Awhen used in an arithmetic context.
1N/AHowever, \f5ksh\fP variables
1N/Acan have one or more
1N/A.I attributes
1N/Athat control the internal representation of the variable,
1N/Athe way the variable is printed, and its access or
1N/Ascope.
1N/AIn addition,
1N/A\f5ksh\fP
1N/Aallows variables to represent arrays of values
1N/Aand references to other variables.
1N/AThe \f5typeset\fP
1N/Abuilt-in command of \f5ksh\fP
1N/Aassigns attributes to variables.
1N/ATwo of the attributes,
1N/A.I readonly
1N/Aand
1N/A.IR export ,
1N/Aare available in the Bourne shell.
1N/AMost of the remaining attributes are discussed here.
1N/AThe complete list of attributes appears in the manual.
1N/AThe \f5unset\fP
1N/Abuilt-in of \f5ksh\fP removes
1N/Avalues and attributes of variables.
1N/AWhen a variable is exported, certain of its attributes are also exported.
1N/A.P
1N/AWhenever a value is assigned to a variable,
1N/Athe value is transformed according to the attributes of the variable.
1N/AChanging the attribute of a variable can change its value.
1N/AThe attributes
1N/A.B \-L
1N/Aand
1N/A.B \-R
1N/Aare for left and right field justification respectively.
1N/AThey are useful for aligning columns in a report.
1N/AFor each of these attributes, a width can be defined explicitly or else
1N/Ait is defined the first time an assignment is made to the variable.
1N/AEach assignment causes justification of the field, truncating
1N/Aif necessary.
1N/AAssignment to fixed sized variables
1N/Aprovides one way to generate a substring consisting of
1N/Aa fixed number of characters from
1N/Athe beginning or end of a string.
1N/AOther methods are discussed later.
1N/A.P
1N/AThe attributes
1N/A.B \-u
1N/Aand
1N/A.B \-l
1N/Aare used for upper case and lower case
1N/Aformatting, respectively.
1N/ASince it makes no sense to have both attributes on simultaneously,
1N/Aturning on either of these attributes turns the other off.
1N/AThe following script,
1N/Ausing \f5read\fP and \f5print\fP which are described later,
1N/Aprovides an example of the use of shell variables
1N/Awith attributes.
1N/AThis script reads a file of lines each consisting of five fields separated by
1N/A.B :
1N/Aand prints fields 4 and 2 in upper case in columns 1-15, left justified,
1N/Aand columns 20-25 right-justified respectively.
1N/A.sp
1N/A.nf
1N/A.in .5i
1N/A.ta 3.4i
1N/A\f5typeset -uL15 f4 # 15 character left justified
1N/Atypeset -uR6 f2 # 6 character right justified
1N/AIFS=: # set field separator to :
1N/Awhile read -r f1 f2 f3 f4 f5 # read line, split into fields
1N/Ado print -r -- "$f4 $f2" # print fields 4 and 2
1N/Adone\fP
1N/A.fi
1N/A.ta
1N/A.in
1N/A.sp
1N/A.P
1N/AThe
1N/A.BR \-i ,
1N/A.BR \-E ,
1N/Aand
1N/A.BR \-F ,
1N/Aattributes are used to represent numbers.
1N/AEach can be followed by a decimal number.
1N/AThe
1N/A.B \-i
1N/Aattribute causes the value to be represented as an integer and it
1N/Acan be followed by a number representing the numeric base when expanding
1N/Aits value.
1N/AWhenever a value is assigned to an integer variable, it is evaluated
1N/Aas an arithmetic expression
1N/Aand then truncated to an integer.
1N/A.P
1N/AThe
1N/A.B \-E
1N/Aattribute causes the value to be represented in scientific
1N/Anotation whenever its value is expanded. The number following the
1N/A.B \-E
1N/Adetermines the number of significant figures, and defaults to 6.
1N/AThe
1N/A.B \-F
1N/Aattribute causes the value to be represented with a fixed number
1N/Aof places after the decimal point.
1N/AAssignments to variables with the
1N/A.B \-E
1N/Aor
1N/A.B \-F
1N/Aattributes cause the evaluation of the right hand side of the assignment.
1N/A.P
1N/A\f5ksh\fP allows one-dimensional
1N/A.I arrays
1N/Ain addition to simple variables.
1N/AThere are two types of arrays; associative arrays
1N/Aand indexed arrays.
1N/AThe subscript for an associative array is an arbitrary
1N/Astring, whereas the subscript for an indexed array is
1N/Aan arithmetic expression that is evaluated to yield an integer
1N/Aindex.
1N/AAny variable can become an indexed array
1N/Aby referring to it with
1N/Aan integer
1N/A.IR subscript .
1N/AAll elements of an array need not exist.
1N/ASubscripts for arrays
1N/Amust evaluate to an
1N/Ainteger between 0 and some maximum value, otherwise
1N/Aan error results.
1N/AThe maximum value may vary from one machine to another but
1N/Ais at least 4095.
1N/AEvaluation of subscripts is described in
1N/Athe next section.
1N/AAttributes apply to the whole array.
1N/A.P
1N/AAssignments to array variables can be made to individual elements
1N/Avia parameter
1N/Aassignment commands or the
1N/A.B typeset
1N/Abuilt-in.
1N/AAdditionally, values can be assigned sequentially with
1N/Acompound assignment as described below, or by the
1N/A.B \-A
1N/A.I name
1N/Aoption of the \f5set\fP command.
1N/AReferencing of subscripted variables requires the character
1N/A.BR $ ,
1N/Abut also requires braces around the array element name.
1N/AThe braces are needed to avoid conflicts with the
1N/Afile name generation mechanism.
1N/AThe form of any array element reference is:
1N/A.ce
1N/A.BI ${ name [ subscript ]}
1N/ASubscript values of
1N/A.B *
1N/Aand
1N/A.B @
1N/Acan be used to generate all elements of an array,
1N/Aas they are used for expansion of positional parameters.
1N/AThe list of currently defined subscripts for a given
1N/Avariable can be generated with
1N/A.BI ${! name [@]} ,
1N/Aor
1N/A.BI ${! name [*]} .
1N/A.P
1N/AThe
1N/A.B \-n
1N/Aor
1N/A.I nameref
1N/Aattribute causes the variable to be treated
1N/Aas a reference to the variable defined by its value.
1N/AOnce this attribute is set, all references to this variable
1N/Abecome references to the variable named by the value
1N/Aof this variable.
1N/AFor example, if \f5foo=bar\fP, then setting the reference
1N/Aattribute on \f5foo\fP will cause all subsequent references
1N/Ato \f5foo\fP to behave as the variable whose name is \f5$foo\fP
1N/Awas referenced, which in this case is the variable \f5bar\fP.
1N/AUnsetting this attribute breaks the association.
1N/AReference variables are usually used inside functions whose
1N/Aarguments are the names of shell variables.
1N/AThe names for reference variables cannot contain a \fB\s+2.\s-2\fP.
1N/AWhenever a shell variable is referenced, the portion of the
1N/Avariable up to the first \fB\s+2.\s-2\fP
1N/Ais checked to see whether it matches the name of a reference
1N/Avariable.
1N/AIf it does, then the name of the variable actually used
1N/Aconsists of the concatenation of the name of the variable
1N/Adefined by the reference plus the remaining portion of the
1N/Aoriginal variable name.
1N/AFor example, using the predefined alias, \f5alias\ nameref='typeset\ -n'\fP,
1N/A.sp
1N/A.nf
1N/A.in .5i
1N/A.ta 3.4i
1N/A\f5\^.bar.home.bam="hello world"
1N/Anameref foo=.bar.home
1N/Aprint ${foo.bam}
1N/A\fBhello world\fP\fP
1N/A.fi
1N/A.ta
1N/A.in
1N/A.sp
1N/A.H 2 "Compound Assignment"
1N/ACompound assignments are used to assign values to arrays
1N/Aand compound data structures.
1N/AThe syntax for a compound assignment is
1N/A.IB name =( assignment-list )
1N/Awhere
1N/A\fIname\fP
1N/Ais the name of the variable to which you want to assign values.
1N/ANo space is permitted between the variable name and the \fB=\fP
1N/Abut can appear between the \fB=\fP and the open parenthesis.
1N/ANew-lines can appear between the parentheses.
1N/A.P
1N/AThe \fIassignment-list\fP can be in several different forms
1N/Ayielding different results.
1N/AIf \fIassignment-list\fP is simply a list of words, then
1N/Athe words are processed as they are with the \f5for\fP command
1N/Aand assigned sequentially as an indexed array.
1N/AFor example,
1N/A.ce
1N/A\f5foo=( * )\fP
1N/Acreates an indexed array \f5foo\fP and assigns the
1N/Afile names in the current directory to each index starting
1N/Aat zero.
1N/A.P
1N/AThe second form for \fIassignment-list\fP is a list of assignments
1N/Aof the special form \fB[\fP\fIword\fP\fB]=\fP\fIword\fP.
1N/ANo space is permitted before or after the \fB=\fP.
1N/AIn this case, the variable given by \fIname\fP becomes
1N/Aan associative array with the given arguments as subscripts.
1N/AFor example,
1N/A.ce
1N/A\f5bar=( [color]=red [shape]=box )\fP
1N/Acreates an associate array named \f5bar\fP whose
1N/Asubscripts are \f5color\fP and \f5shape\fP.
1N/A.P
1N/AThe third form for \fIassignment-list\fP is a list of
1N/Anormal assignments, including compound assignments.
1N/AThese assignments cause sub-variables to be assigned
1N/Acorresponding to the given assignments.
1N/AIn addition to assignments, the \fIassignment-list\fP
1N/Acan contain \f5typeset\fP commands.
1N/AIn addition to creating sub-variables,
1N/Athe effect of a compound assignment is to make
1N/Athe value of the original variable be a parenthesized
1N/Aassignment list of its components.
1N/AFor example, the assignment
1N/A.sp
1N/A.nf
1N/A.in .5i
1N/A.ta 3.4i
1N/A\f5foo=(
1N/A left=bar
1N/A typeset -i count=3
1N/A point=(
1N/A x=50
1N/A y=60
1N/A )
1N/A colors=( red green yellow )
1N/A right=bam
1N/A) \fP
1N/A.ta
1N/A.in
1N/A.fi
1N/A.sp
1N/Ais equivalent to the assignments
1N/A.sp
1N/A.nf
1N/A.in .5i
1N/A.ta 3.4i
1N/A\f5foo.left=bar
1N/Afoo.count=3
1N/Afoo.point.x=50
1N/Afoo.point.y=60
1N/Afoo.colors=( red green yellow )
1N/Afoo.right=bam\fP
1N/A.ta
1N/A.in
1N/A.fi
1N/A.sp
1N/AIn addition, the value of \f5"$foo"\fP is
1N/A.sp
1N/A.nf
1N/A.in .5i
1N/A.ta 3.4i
1N/A\f5(
1N/A colors=( red green yellow )
1N/A left=bar
1N/A typeset -i count=3
1N/A point=(
1N/A y=60
1N/A x=50
1N/A )
1N/A right=bam
1N/A)\fP
1N/A.ta
1N/A.in
1N/A.fi
1N/A.sp
1N/A.H 2 "Substring Generation"
1N/AThe expansion of a variable or parameter can be modified so that
1N/Aonly a portion of the value results.
1N/AIt is often necessary to extract a portion of a shell variable or
1N/Aa portion of an array.
1N/AThere are several parameter expansion operators that can do this.
1N/AOne method to generate a substring is with an expansion of
1N/Athe form \fB${\fP\fIname\fP\fB:\fP\fIoffset\fP\fB:\fP\fIlength\fP\fB}\fP
1N/Awhere \fIoffset\^\fP is an arithmetic expression that defines the
1N/Aoffset of the first character starting from 0, and
1N/A\fIlength\^\fP is an arithmetic expression that defines the
1N/Alength of the substring.
1N/AIf
1N/A.BI : length\^
1N/Ais omitted,
1N/Athe length of the value of
1N/A.I name\^
1N/Astarting at
1N/A.I offset\^
1N/Ais used.
1N/AThe
1N/A.BI : offset : length
1N/Aoperators can also be applied to array expansions and to parameters
1N/A.B *
1N/Aand
1N/A.B @
1N/Ato generate portions of an array.
1N/AFor example, the expansion, \fB${\fP\fIname\fP\fB[@]:\fP\fIoffset\fP\fB:\fP\fIlength\fP\fB}\fP, yields up to \fIlength\fP elements of the array \fIname\fP
1N/Astarting at the element \fIoffset\fP.
1N/A.P
1N/AThe other parameter expansion modifiers use shell patterns
1N/Ato describe portions of the string to modify and delete.
1N/AA description of shell patterns is contained below.
1N/AWhen these
1N/Amodifiers are applied to special parameters
1N/A.B @
1N/Aand
1N/A.B *
1N/Aor to array parameters given as
1N/A\fIname\fP\fB[@]\fP or \fIname\fP\fB[*]\fP,
1N/Athe operation is performed on each element.
1N/AThere are four parameter expansion modifiers that
1N/Astrip off leading and trailing substrings
1N/Aduring parameter expansion
1N/Aby removing the characters matching a given pattern.
1N/AAn expansion of
1N/Athe form \fB${\fP\fIname\fP\fB#\fP\fIpattern\fP\fB}\fP
1N/Acauses the smallest matching prefix of the value of
1N/A.I name\^
1N/Ato be removed.
1N/AThe largest prefix matching
1N/A.I pattern\^
1N/Ais removed by using
1N/A.B ##
1N/Ainstead of
1N/A.BR # .
1N/ASimilarly,
1N/Aan expansion of
1N/Athe form \fB${\fP\fIname\fP\fB%\fP\fIpattern\fP\fB}\fP
1N/Acauses the smallest matching substring at the end of
1N/A.I name\^
1N/Ato be removed.
1N/AAgain, using
1N/A.B %%
1N/Ainstead of
1N/A.BR % ,
1N/Acauses the largest matching trailing substring to be deleted.
1N/AFor example, if the shell variable
1N/A.B file
1N/Ahas value
1N/A.BR foo.c ,
1N/Athen the expression
1N/A.B ${file%.c}.o
1N/Ahas value
1N/A.BR foo.o .
1N/A.P
1N/AThe value of an expansion can be changed by
1N/Aspecifying a pattern that matches the part that needs to be changed
1N/Aafter the
1N/Athe parameter expansion modifier
1N/A.BR / .
1N/AAn expansion of the form
1N/A\fB${\fP\fIname\fP\fB/\fP\fIpattern\fP\fB/\fP\fIstring\fP\fB}\fP
1N/Areplaces the first match of \fIpattern\fP with
1N/Athe value of variable \fIname\fP to \fIstring\fP.
1N/AThe second
1N/A.B /
1N/Ais not necessary when \fIstring\fP is null.
1N/AThe expansion
1N/A\fB${\fP\fIname\fP\fB//\fP\fIpattern\fP\fB/\fP\fIstring\fP\fB}\fP
1N/Achanges all occurrences of the \fIpattern\fP into \fIstring\fP.
1N/AThe parameter expansion modifiers
1N/A.B /#
1N/Aand
1N/A.B /%
1N/Acause the matching pattern to be anchored to the beginning and
1N/Aend respectively.
1N/A.P
1N/AFinally, there are parameter expansion modifiers that yield
1N/Athe name of the variable, the string length of the value, or the number
1N/Aof elements of an array.
1N/A\fB${!\fP\fIname\fP\fB}\fP
1N/Ayields the name of the variable which will be \fIname\fP itself
1N/Aexcept when \fIname\fP is a reference variable. In this case
1N/Ait will yield the name of the variable it refers to.
1N/AWhen applied to an array variable,
1N/A\fB${!\fP\fIname\fP\fB[@]}\fP and
1N/A\fB${!\fP\fIname\fP\fB[*]}\fP
1N/Agenerate the names of all subscripts.
1N/A\fB${#\fP\fIname\fP\fB}\fP
1N/Awill be the length in bytes of
1N/A\fB$\fP\fIname\fP.
1N/AFor an array variable
1N/A\fB${#\fP\fIname\fP\fB[*]}\fP
1N/Agives the number of elements in the array.
1N/A.H 2 "Arithmetic Evaluation"
1N/A.P
1N/AFor the most part, the shell is a string processing
1N/Alanguage. However, the need for arithmetic has
1N/Along been obvious.
1N/AMany of the characters that are special to the
1N/ABourne shell are needed as arithmetic operators.
1N/ATo make arithmetic easy to use, and to maintain
1N/Acompatibility with the Bourne shell, \f5ksh\fP uses matching
1N/A.B ((
1N/Aand
1N/A.B ))
1N/Ato delineate arithmetic expressions.
1N/AWhile single parentheses might have been
1N/Amore desirable, these already mean
1N/A.I subshell\^
1N/Aso that another notation was required.
1N/AThe arithmetic expression
1N/Ainside the double parentheses
1N/Afollows the same syntax, associativity and precedence
1N/Aas the ANSI-C\*(Rf
1N/A.RS
1N/AAmerican National Standard for Information Systems \- Programming
1N/ALanguage \- C, ANSI X3.159-1989.
1N/A.RF
1N/Aprogramming language.
1N/AThe characters between the matching double parentheses
1N/Aare processed with the same rules used for double
1N/Aquotes so that spaces can be used to aid readability
1N/Awithout additional quoting.
1N/A.P
1N/AAll arithmetic evaluations are performed using
1N/Adouble precision floating point arithmetic.
1N/AFloating point constants follow the same rules as
1N/Athe ANSI-C programming language.
1N/AInteger arithmetic constants are written as
1N/A.ce
1N/A.IB base # number,
1N/Awhere
1N/A.I base\^
1N/Ais a decimal integer between
1N/Atwo and sixty-four and
1N/A.I number\^
1N/Ais any non-negative number.
1N/ABase ten is used
1N/Awhen no base is specified.
1N/AThe digits are represented by the characters
1N/A.BR 0-9a-zA-Z_@ .
1N/AFor bases less than or equal to 36,
1N/Aupper and lower case characters can
1N/Abe used interchangeably to represent the digits
1N/Afrom 10 thru 35.
1N/A.P
1N/AArithmetic expressions are made from constants,
1N/Avariables, and operators.
1N/AParentheses may be used for grouping.
1N/AThe contents inside the double parentheses
1N/Aare processed with the same expansions as occurs in a double quoted string,
1N/Aso that all
1N/A.B $
1N/Aexpansions are performed before the expression is evaluated.
1N/AHowever, there is usually no need to use the
1N/A.B $
1N/Ato get the value of a variable
1N/Abecause the arithmetic evaluator replaces the name of the variable
1N/Aby its value within an arithmetic expression.
1N/AThe
1N/A.B $
1N/Acannot be used when the variable is the subject of assignment
1N/Aor an increment operation.
1N/AAs a rule it is better not to use
1N/A.B $
1N/Ain front of variables in an arithmetic expression.
1N/A.P
1N/AAn arithmetic command of the form
1N/A.B
1N/A(( ... ))
1N/A.R
1N/Ais a command that evaluates the enclosed arithmetic expression.
1N/AFor example, the command
1N/A.ce
1N/A\f5(( x++ ))\fP
1N/Acan be used to
1N/Aincrement the variable \f5x\fP,
1N/Aassuming that \f5x\fP contains some numerical value.
1N/AThe arithmetic command is true (return value 0), when the resulting
1N/Aexpression is non-zero, and false (return value 1) when the
1N/Aexpression evaluates to zero.
1N/AThis makes the command easy to use with the \f5if\fP and \f5while\fP
1N/Acompound commands.
1N/A.P
1N/AThe \f5for\fP compound command
1N/Ahas been extended for use in arithmetic contexts.
1N/AThe syntax,
1N/A.ce
1N/A\f5for\fP \fB((\fP \fIexpr1\fP\fB;\fP \fIexpr2\fP \fB;\fP \fIexpr3 \fP\fB))\fP
1N/Acan be used as the first line of a \f5for\fP loop with the same semantics
1N/Aas the \f5for\fP statement in the ANSI-C programming language.
1N/A.P
1N/AArithmetic evaluations can also be performed as part of the evaluation
1N/Aof a command line.
1N/AThe syntax
1N/A.B
1N/A$((\ ...\ ))
1N/A.R
1N/Aexpands to the value of the enclosed arithmetic expression.
1N/AThis expansion can occur wherever parameter expansion is performed.
1N/AFor example using the \f5ksh\fP command \f5print\fP (described
1N/Alater)
1N/A.ce
1N/A\f5print $((2+2))\fP
1N/Aprints the number 4.
1N/A.P
1N/AThe following script prints the first
1N/A.I n
1N/Alines of its standard input onto its standard output,
1N/Awhere
1N/A.I n
1N/Acan be supplied as an optional argument whose default value is 20.
1N/A.sp
1N/A.nf
1N/A.in .5i
1N/A.ta 4i
1N/A\f5integer n=${1-20} # set n
1N/Awhile (( n-- >=0 )) && read -r line # at most n lines
1N/Ado print -r -- "$line"
1N/Adone\fP
1N/A.fi
1N/A.ta
1N/A.in
1N/A.sp
1N/A.H 2 "Shell Expansions"
1N/A.P
1N/AThe commands you enter from the terminal or from a script
1N/Aare divided into words and each word undergoes several
1N/Aexpansions to generate the command name and its arguments.
1N/AThis is done in two phases.
1N/AThe first phase recognizes reserved words, spaces and operators
1N/Ato decide where command boundaries lie.
1N/AAlias substitutions take place during this phase.
1N/AThe second phase performs expansions in the following order:
1N/A.BL
1N/A.LI
1N/ATilde substitution,
1N/Aparameter expansion,
1N/Aarithmetic expansion,
1N/Aand command substitution
1N/Aare performed from left to right.
1N/AThe option
1N/A.B \-u
1N/Aor
1N/A.BR nounset ,
1N/Awill cause an error to occur when any variable
1N/Athat is not set is expanded.
1N/A.LI
1N/AThe characters that result from parameter expansion and
1N/Acommand substitution above are checked with the characters
1N/Ain the
1N/A\fB\s-1IFS\s+1\fP variable
1N/Afor possible
1N/Afield splitting.
1N/A(See a description of \f5read\fP below to see how
1N/A\fB\s-1IFS\s+1\fP is used.)
1N/ASetting
1N/A\fB\s-1IFS\s+1\fP to a null
1N/Avalue causes field splitting to be skipped.
1N/A.LI
1N/APathname generation (as described below)
1N/Ais performed on each of the fields.
1N/AAny field that doesn't match a pathname is left alone.
1N/AThe option,
1N/A.B \-f
1N/Aor
1N/A.BR noglob ,
1N/Ais used to disable pathname generation.
1N/A.LE
1N/A.H 2 "Pattern Matching"
1N/AThe shell is primarily a string processing language and uses
1N/Apatterns for matching file names as well as for matching strings.
1N/AThe characters
1N/A.BR ? ,
1N/A.BR * ,
1N/Aand
1N/A.B [
1N/Aare processed specially
1N/Aby the shell when not quoted.
1N/AThese characters are used to form patterns that
1N/Amatch strings.
1N/APatterns are used by the shell to match pathnames,
1N/Ato specify substrings,
1N/Aand for
1N/A.B case
1N/Acommands.
1N/AThe character
1N/A.B ?
1N/Amatches any one character.
1N/AThe character
1N/A.B *
1N/Amatches zero or more characters.
1N/AThe character sequence
1N/A.BR [ ... ]
1N/Adefines a character class
1N/Athat matches any character contained within
1N/A.BR [\^] .
1N/AA range of characters can be specified by putting a
1N/A.B \-
1N/Abetween the first and last character of the range.
1N/AAn exclamation mark,
1N/A.BR ! ,
1N/Aimmediately after the
1N/A.BR [ ,
1N/Ameans match all characters except the characters specified.
1N/AFor example, the pattern
1N/A\f5a?c*.[!a-z]\fP
1N/Amatches any string beginning with an
1N/A.BR a ,
1N/Awhose third character is a
1N/A.BR c ,
1N/Aand that ends in
1N/A.B .
1N/A(dot) followed by any character except the lower case letters,
1N/A.BR a\-z .
1N/AThe sequence \f5[:alpha:]\fP
1N/Ainside a character class, matches any set of characters in
1N/Athe ANSI-C
1N/A.B alpha
1N/Aclass.
1N/ASimilarly, \f5[:\fP\fIclass\fP\f5:]\fP matches
1N/Aeach of the characters in the given \fIclass\fP
1N/Afor all the ANSI-C character classes.
1N/AFor example, \f5[[:alnum:]_]\fP
1N/Amatches any alpha-numeric character or the character
1N/A.BR _ .
1N/A.P
1N/A\f5ksh\fP
1N/Atreats
1N/Astrings of the form
1N/A.BI ( pattern-list
1N/A.BR ) ,
1N/Awhere
1N/A.I pattern-list
1N/Ais a list of one or more patterns separated by a
1N/A.BR \(bv ,
1N/Aspecially when preceded by
1N/A.BR * ,
1N/A.BR ? ,
1N/A.BR + ,
1N/A.BR @ ,
1N/Aor
1N/A.BR ! .
1N/AA
1N/A.B ?
1N/Apreceding
1N/A.BI ( pattern-list )
1N/Ameans that the pattern list enclosed in
1N/A.B (\^)
1N/Ais optional.
1N/AAn
1N/A.BI @( pattern-list )
1N/Amatches any pattern in the list of patterns enclosed in
1N/A.BR () .
1N/AA
1N/A.BI *( pattern-list )
1N/Amatches any string that contains zero or more of each of the enclosed
1N/Apatterns,
1N/Awhereas
1N/A.BI +( pattern-list )
1N/Arequires a match of one or more of any of the given patterns.
1N/AFor instance, the pattern
1N/A.B +([0\-9])?(.)
1N/Amatches one or more digits optionally followed by a
1N/A.BR . (dot).
1N/AA
1N/A.BI !( pattern-list )
1N/Amatches anything except any of the given patterns.
1N/AFor example,
1N/A\f5print\ !(*.o)\fP
1N/Adisplays all file names in the current directory that do not end in
1N/A.BR .o .
1N/A.P
1N/AWhen patterns are used to generate pathnames when expanding
1N/Acommands several other rules apply.
1N/AA separate match is made
1N/Afor each file name component of the pathname.
1N/ARead permission is required for
1N/Aany portion of the pathname that contains any special
1N/Apattern character.
1N/ASearch permission is required for every component except
1N/Apossibly the last.
1N/A.P
1N/ABy default,
1N/Afile names in each directory that begin with \fB\s+2.\s-2\fP
1N/Aare skipped when performing a match.
1N/AIf the pattern to be matched starts with a leading \fB\s+2.\s-2\fP,
1N/Athen only files beginning with a \fB\s+2.\s-2\fP,
1N/Aare examined when reading each directory to find matching files.
1N/AIf the
1N/A\fB\s-1FIGNORE\s+1\fP variable
1N/Ais set,
1N/Athen only files that do not match this pattern
1N/Aare considered.
1N/AThis overrides the special meaning of \fB\s+2.\s-2\fP
1N/Ain a pattern and in a file name.
1N/A.P
1N/AIf the
1N/A.B markdirs
1N/Aoption is set,
1N/Aeach matching pathname that is the name
1N/Aof a directory has a trailing
1N/A.B /
1N/Aappended to the name.
1N/A.P
1N/A.H 2 "Conditional Expressions"
1N/AThe Bourne shell uses the \f5test\fP
1N/Acommand, or the equivalent \f5[\fP
1N/Acommand, to test files for attributes
1N/Aand to compare strings or numbers.
1N/AThe problem with \f5test\fP
1N/Ais that the shell has expanded the words of the \f5test\fP
1N/Acommand and
1N/Asplit them into arguments before \f5test\fP begins execution.
1N/A\f5test\fP
1N/Acannot distinguish between operators and operands.
1N/AIn most cases
1N/A\f5test\ "$1"\fP
1N/Awill test whether argument 1 is non-null.
1N/AHowever,
1N/Aif argument 1 is
1N/A.BR \-f ,
1N/Athen \f5test\fP
1N/Awill treat
1N/A.B \-f
1N/Aas an operator and
1N/Ayield a syntax error.
1N/AOne of the most frequent errors with
1N/A\f5test\fP
1N/Aoccurs when its operands are not within double quotes.
1N/AIn this case, the argument may expand to more than a single
1N/Aargument or to no argument at all. In either case this
1N/Awill likely cause a syntax error.
1N/AWhat makes this most insidious is that these errors are frequently
1N/Adata dependent. A script that appears to run correctly may abort
1N/Aif given unexpected data.
1N/A.P
1N/ATo get around these problems,
1N/A\f5ksh\fP
1N/Ahas a compound command for conditional expression testing
1N/Aas part of the language.
1N/AThe reserved words
1N/A.B [[
1N/Aand
1N/A.B ]]
1N/Adelimit the range of the command.
1N/ABecause they are reserved words, not operator characters,
1N/Athey require spaces to separate them
1N/Afrom arguments.
1N/AThe words between
1N/A.B [[
1N/Aand
1N/A.B ]]
1N/Aare not processed for field splitting or for pathname generation.
1N/AIn addition, since \f5ksh\fP
1N/Adetermines the operators before parameter expansion,
1N/Aexpansions that yield no argument cause no problem.
1N/AThe operators within
1N/A.BR [[ ... ]]
1N/Aare almost the same as those for the \f5test\fP
1N/Acommand.
1N/AAll unary operators are of the form
1N/A.BI \- letter
1N/Aand are followed by a single operand.
1N/AInstead of
1N/A.B \-a
1N/Aand
1N/A.BR \-o ,
1N/A.BR [[ ... ]]
1N/Auses
1N/A.B &&
1N/Aand
1N/A.B \(bv\(bv
1N/Ato indicate "and" and "or".
1N/AParentheses are used without quoting for grouping.
1N/A.P
1N/AThe right hand side of the string comparison operators
1N/A.B ==
1N/Aand
1N/A.B !=
1N/Atakes a pattern and tests whether the left hand operand
1N/Amatches this pattern. Quoting the pattern results
1N/Ais a string comparison rather than the pattern match.
1N/AThe operators
1N/A.B <
1N/Aand
1N/A.B >
1N/Awithin
1N/A.BR [[ ... ]]
1N/Adesignate lexicographical comparison.
1N/A.P
1N/AIn addition there are several other new comparison primitives.
1N/AThe binary operators
1N/A.B \-ot
1N/Aand
1N/A.B \-nt
1N/Acompare the modification times
1N/Aof two files to see which file is
1N/A.I "older than"
1N/Aor
1N/A.I "newer than"
1N/Athe other.
1N/AThe binary operator
1N/A.B \-ef
1N/Atests whether two files
1N/Ahave the same device and i-node number,
1N/Ai.\ e., a link to the same file.
1N/A.P
1N/AThe unary operator
1N/A.B \-L
1N/Areturns true if its operand is a symbolic link.
1N/AThe unary operator
1N/A.B \-O
1N/A(\fB\-G\fP)
1N/Areturns true if the owner (or group) of the file operand matches
1N/Athat of the caller.
1N/AThe unary operator
1N/A.B \-o
1N/Areturns true when its operand is the name of an option that is
1N/Acurrently on.
1N/A.P
1N/AThe following script illustrates some of the uses of
1N/A.BR [[ ... ]] .
1N/AThe reference manual contains the complete list of operators.
1N/A.sp
1N/A.nf
1N/A.in .5i
1N/A.ta 4i
1N/A\f5for i
1N/Ado # execute foo for numeric directory
1N/A if [[ \-d $i && $i == +([0\-9]) ]]
1N/A then foo
1N/A # otherwise if writable or executable file and not mine
1N/A elif [[ (\-w $i\(bv\(bv\-x $i) && ! \-O $i ]]
1N/A then bar
1N/A fi
1N/Adone\fP
1N/A.fi
1N/A.ta
1N/A.in
1N/A.sp
1N/A.H 2 "Input and Output"
1N/A\f5ksh\fP has
1N/Aextended I/O capabilities to enhance the
1N/Ause of the shell as a programming language.
1N/AAs with the Bourne shell,
1N/Ayou use the I/O redirection operator,
1N/A.BR < ,
1N/Ato control where input comes from,
1N/Aand the I/O redirection operator,
1N/A.BR > ,
1N/Ato control where output goes to.
1N/AEach of these operators can be preceded with a single digit that
1N/Aspecifies a file unit number to associate with the file stream.
1N/AOrdinarily you specify these I/O redirection operators with a specific
1N/Acommand to which it applies.
1N/AHowever, if you specify I/O redirections with the \f5exec\fP
1N/Acommand,
1N/Aand don't specify arguments to \f5exec\fP,
1N/Athen the I/O redirection applies to the current program.
1N/AFor example, the command
1N/A\f5exec\ <\ foobar\fP
1N/Aopens file \f5foobar\fP
1N/Afor reading.
1N/AThe \f5exec\fP
1N/Acommand is also used to close files.
1N/AA file descriptor unit can be opened as a copy of an existing
1N/Afile descriptor unit by using either of the
1N/A.B <&
1N/Aor
1N/A.B >&
1N/Aoperators and putting the file descriptor unit of the original file
1N/Aafter the
1N/A.BR & .
1N/AThus, \f52>&1\fP means open standard error (file descriptor 2)
1N/Aas a copy of standard output (file descriptor 1).
1N/AA file descriptor value of
1N/A.B \-
1N/Aafter the
1N/A.B &
1N/Aindicates that the file should be closed.
1N/ATo close file unit 5, specify
1N/A\f5exec\ 5<&-\fP.
1N/AThere are two additional redirection operators with \f5ksh\fP
1N/Aand the POSIX shell that are not part of the Bourne shell.
1N/AThe
1N/A.B >|
1N/Aoperator overrides the effect of the
1N/A.B noclobber
1N/Aoption described earlier.
1N/AThe
1N/A.B <\^>
1N/Aoperator causes a file to be opened for both reading and writing.
1N/A.P
1N/A\f5ksh\fP recognizes certain pathnames and treats them
1N/Aspecially.
1N/APathnames of the form
1N/A.BI /dev/fd/ n\^
1N/Aare treated as equivalent to the file defined by file descriptor
1N/A.IR n .
1N/AThese name can be used as the script argument to \f5ksh\fP
1N/Aand in conditional testing as described above.
1N/AOn underlying systems that support
1N/A.B /dev/fd
1N/Ain the file system, these names can be passed to other commands.
1N/APathnames of the form
1N/A.BI /dev/tcp/ hostid / port
1N/Aand
1N/A.BI /dev/udp/ hostid / port
1N/Acan be used to create
1N/A.B tcp
1N/Aand
1N/A.B udp
1N/Aconnections to services given by the
1N/A.I hostid\^
1N/Anumber and
1N/A.I port\^
1N/Anumber.
1N/AThe
1N/A.I hostid\^
1N/Acannot use symbolic values. In practice these
1N/Anumbers are typically generated by command substitution.
1N/AFor example,
1N/A\f5exec\ 5>\ /dev/tcp/$(service\ name)\fP
1N/Awould open file descriptor 5 for sending messages
1N/Ato hostid and port number defined by the output of \f5service\ name\fP.
1N/A.P
1N/AThe Bourne shell has a built-in command \f5read\fP
1N/Afor reading lines from standard input (file descriptor 0)
1N/Aand splitting it into fields based on the value of the
1N/A.B \s-1IFS\s+1
1N/Avariable, and a command \f5echo\fP
1N/Ato write strings to standard output.
1N/A(On some systems, \f5echo\fP
1N/Ais not a built-in command and incurs considerable overhead to use.)
1N/AUnfortunately, neither of these commands
1N/Ais able to perform some very basic tasks.
1N/AFor example.
1N/Awith the Bourne shell,
1N/Athe \f5read\fP
1N/Abuilt-in cannot read a single line that ends in
1N/A.BR \e .
1N/AWith \f5ksh\fP
1N/Athe \f5read\fP
1N/Abuilt-in has a
1N/A.B \-r
1N/Aoption to remove the special meaning for
1N/A.B \e
1N/Awhich allows it to be
1N/Atreated as a regular
1N/Acharacter rather than the line continuation character.
1N/AWith the Bourne shell,
1N/Athere is no simple way to have more than one file open
1N/Aat any time for reading.
1N/A\f5ksh\fP has options on the \f5read\fP
1N/Acommand to specify the file
1N/Adescriptor for the input.
1N/AThe fields that are read from a line can be stored into an indexed
1N/Aarray with the
1N/A.B \-A
1N/Aoption to read.
1N/AThis allows a line to be split into an arbitrary number of fields.
1N/A.P
1N/AThe way the Bourne shell uses the
1N/A\fB\s-1IFS\s+1\fP variable to
1N/Asplit lines into fields greatly limits its utility.
1N/AOften data files consist of lines that use a character such
1N/Aas
1N/A.B :
1N/Ato delimit fields with two adjacent delimiters that denote
1N/Aa null field.
1N/AThe Bourne shell treats adjacent delimiters as a single
1N/Afield delimiter.
1N/AWith \f5ksh\fP,
1N/Adelimiters that are considered white space characters
1N/Ahave the behavior of the Bourne shell, but other
1N/Aadjacent delimiters separate
1N/Anull fields.
1N/A.P
1N/AThe \f5read\fP command is often used in scripts that interact
1N/Awith the user by prompting the user and then requesting some
1N/Ainput.
1N/AWith the Bourne shell two commands are needed; one to
1N/Aprompt the user, the other to read the reply.
1N/A\f5ksh\fP allows these two commands to be combined.
1N/AThe first argument of the \f5read\fP
1N/Acommand can be followed by a
1N/A.B ?
1N/Aand a prompt string which is used whenever the input
1N/Adevice is a terminal.
1N/ABecause the prompt is associated with the \f5read\fP built-in,
1N/Athe built-in command line editors will be able to re-output
1N/Athe prompt whenever the line needs to be refreshed when
1N/Areading from a terminal device.
1N/A.P
1N/AWith the Bourne shell,
1N/Athere is no way to set a time limit for waiting for the user
1N/Aresponse to read.
1N/AThe
1N/A.B \-t
1N/Aoption to \f5read\fP takes a floating
1N/Apoint argument that gives the time in seconds,
1N/Aor fractions of seconds that the shell should wait for a reply.
1N/A.P
1N/AThe version of the \f5echo\fP command in System V
1N/Atreats certain sequences beginning with
1N/A.B \e
1N/Aas control sequences.
1N/AThis makes it hard to output strings without interpretation.
1N/AMost BSD derived systems do not interpret
1N/A.B \e
1N/Acontrol sequences.
1N/AUnfortunately, the BSD versions of \f5echo\fP accepts a
1N/A.B \-n
1N/Aoption to prevent a trailing new-line, but has no way to
1N/Acause the string
1N/A.B \-n
1N/Ato be printed.
1N/ANeither of these versions is adequate. Also, because they
1N/Aare incompatible, it is very hard to write portable shell scripts
1N/Ausing \f5echo\fP.
1N/AThe \f5ksh\fP built-in, \f5print\fP,
1N/Aoutputs characters to the terminal or to a file and
1N/Asubsumes the functions of all versions of \f5echo\fP.
1N/AOrdinarily, escape sequences in arguments beginning with
1N/A.B \e
1N/Aare processed the same as for the System V \f5echo\fP command.
1N/AHowever \f5print\fP follows the standard conventions for
1N/Aoptions and has options that make \f5print\fP very versatile.
1N/AThe
1N/A.B \-r
1N/Aoption can be used to output the arguments without any special meaning.
1N/AThe
1N/A.B \-n
1N/Aoption can be used here to suppress the trailing new-line
1N/Athat is ordinarily appended.
1N/AAs with \f5read\fP, it is possible to specify the file descriptor number
1N/Aas an option to the command to avoid having to use
1N/Aredirection operators with each occurrence of the command.
1N/A.P
1N/AThe IEEE POSIX shell and utilities standard committee was unable
1N/Ato reconcile the differences between the System V and BSD
1N/Aversions of \f5echo\fP.
1N/AThey introduced a new command named \f5printf\fP
1N/Awhich takes an ANSI-C format string and a list of options
1N/Aand outputs the strings using the ANSI-C formatting rules.
1N/ASince \f5ksh\fP is POSIX conforming, it accepts \f5printf\fP.
1N/AHowever, there is a
1N/A.B \-f
1N/Aoptions to \f5print\fP that can be used to specify
1N/Aa format string which processes the arguments the same way that
1N/A\f5printf\fP does.
1N/A.P
1N/AThe format processing for \f5print\fP and \f5printf\fP has
1N/Abeen extended slightly.
1N/AThere are three additional formatting directives.
1N/AThe
1N/A.B %b
1N/Aformat causes the
1N/A.B \e
1N/Aescape sequences to be expanded as they are with the System V \f5echo\fP
1N/Acommand.
1N/AThe
1N/A.B %q
1N/Aformat causes quotes to
1N/Abe placed on the output as required
1N/Aso that it can be used as shell input.
1N/ASpecial characters in the output of most \f5ksh\fP built-in commands
1N/Aand in the output from an execution trace
1N/Aare quoted in an equivalent fashion.
1N/AThe
1N/A.B %P
1N/Aformat causes an extended regular expression string to
1N/Abe converted into a shell pattern.
1N/AThis is useful for writing shell applications that have
1N/Ato accept regular expressions as input.
1N/AFinally, the escape sequence
1N/A.B \e\^E
1N/Awhich expands to the terminal escape character (octal 033)
1N/Ahas been added.
1N/A.P
1N/AThe shell is frequently used as a programming language for
1N/Ainteractive dialogues.
1N/AThe
1N/A\f5select\fP
1N/Astatement has been added to the language
1N/Ato make it easier to
1N/Apresent menu selection alternatives to the
1N/Auser and evaluate the reply.
1N/AThe list of alternatives is numbered and put in columns.
1N/AA user settable prompt,
1N/A\fB\s-1PS3\s+1\fP,
1N/Ais issued and if the answer is
1N/Aa number corresponding to one of the alternatives,
1N/Athe select loop variable is set to this value.
1N/AIn any case, the
1N/A.B \s-1REPLY\s+1
1N/Avariable is used to store the user entered reply.
1N/AThe shell variables
1N/A.B \s-1LINES\s+1
1N/Aand
1N/A.B \s-1COLUMNS\s+1
1N/Aare used to control the layout of select lists.
1N/A.H 2 "Option Parsing"
1N/AThe \f5getopts\fP built-in command can be used
1N/Ato process command arguments in a manner consistent
1N/Awith the way \f5ksh\fP does for its own built-in commands.
1N/A.P
1N/AThe \f5getopts\fP built-in allows users to specify options
1N/Aas separate arguments or to group options that do not
1N/Atake arguments together. Options that require arguments
1N/Ado not require space to separate them from the option argument.
1N/AThe
1N/A.B \s-1OPTARG\s+1
1N/Avariable stores the value of the option argument
1N/Aafter finding a variable that takes an argument.
1N/AThe
1N/A.B \s-1OPTIND\s+1
1N/Avariable holds the index of the current options argument.
1N/AAfter processing options, the arguments should be
1N/Ashifted by
1N/A.B \s-1OPTIND\s+1\-1
1N/Ato make the
1N/Aremaining arguments be \f5"$@"\fP.
1N/A.P
1N/AThe \f5getopts\fP argument description allows additional
1N/Ainformation to be specified along with the options
1N/Athat is used to generate \fIusage\fP messages for
1N/Aincorrect arguments and for the option argument \fB\-?\fP.
1N/AThe example in the APPENDIX uses \f5getopts\fP to process
1N/Aits arguments.
1N/A.H 2 "Co-process"
1N/A\f5ksh\fP can spawn a
1N/A.I co-process
1N/Aby adding a
1N/A.B "|&"
1N/Aafter a command.
1N/AThis process will be run with its standard input and its
1N/Astandard output connected to the shell. The built-in command \f5print\fP
1N/Awith the
1N/A.B \-p
1N/Aoption will write into the standard input of this
1N/Aprocess and
1N/Athe built-in command \f5read\fP
1N/Awith the
1N/A.B \-p
1N/Aoption will read from the output of this process.
1N/A.P
1N/AIn addition, the I/O redirection operators \fB<&\fP and \fB>&\fP can
1N/Abe used to move the input or output pipe of the co-process
1N/Ato a numbered file descriptor.
1N/AUse \f5exec\ 3>&\ p\fP to move the input of the co-process
1N/Ato file descriptor \fB3\fP.
1N/AAfter you have connected to file descriptor \fB3\fP, you
1N/Acan direct the output of any command to the co-process
1N/Aby running \fIcommand\fP\f5\ >&3\fP.
1N/AAlso, by moving the input of the co-process to a numbered descriptor,
1N/Ait is possible to run a second co-process.
1N/AThe output of both co-processes will be the file descriptor
1N/Aassociated with \f5read\ -p\fP.
1N/AYou can use \f5exec\ 4<&\ p\fP to cause the output of these
1N/Aco-processes to go to file descriptor \fB4\fP of the shell.
1N/AOnce you have moved the pipe to descriptor \fB4\fP, it is possible
1N/Ato connect a server to the co-process by running \fIcommand\fP\f5\ 4<&\ p\fP
1N/Aor to close the co-process pipe with \f5exec\ 4<&\ -\fP.
1N/A.H 2 "Functions"
1N/A.P
1N/AFunction definitions are of the form
1N/A.sp
1N/A.in +.5i
1N/A.nf
1N/A\f5function\fP \fIname\fP
1N/A.br
1N/A.B {
1N/A.br
1N/A any shell script
1N/A.br
1N/A.B }
1N/A.fi
1N/A.sp
1N/A.in
1N/AA function whose name contains a \fB\s+2.\s-2\fP
1N/Ais called a \fIdiscipline\fP function.
1N/AThe portion of the name after the last \fB\s+2.\s-2\fP
1N/Ais the name of the discipline.
1N/ADiscipline functions named \f5get\fP, \f5set\fP, and \f5unset\fP
1N/Acan be assigned to any variable to intercept lookups,
1N/Aassignments and unsetting of the variable
1N/Adefined by the portion of the name before the last \fB\s+2.\s-2\fP.
1N/AApplications can create additional disciplines for variables
1N/Athat are created as part of user defined built-ins.
1N/AThe portion of the name before the last \fB\s+2.\s-2\fP
1N/Amust refer to the name of an existing variable.
1N/AThus, if \f5p\fP is a reference to \f5PATH\fP, then
1N/Athe function name \f5p.get\fP and \f5PATH.get\fP
1N/Arefer to the same function.
1N/A.P
1N/AThe function is invoked either
1N/Aby specifying
1N/A.I name
1N/Aas the command name
1N/Aand optionally following it with arguments
1N/Aor by using it as an option to the \fB\s+2.\s-2\fP
1N/Abuilt-in command.
1N/APositional parameters are saved before each
1N/Afunction call and restored when completed.
1N/AThe arguments that follow the function name on the calling
1N/Aline become positional parameters inside the function.
1N/AThe \f5return\fP
1N/Abuilt-in can be used to cause the function to return to
1N/Athe statement following
1N/Athe point of invocation.
1N/A.P
1N/AFunctions can also be defined with the System V notation,
1N/A.sp
1N/A.in +.5i
1N/A.nf
1N/A\fIname\fP \f5()\fP
1N/A.br
1N/A.B {
1N/A.br
1N/A any shell script
1N/A.br
1N/A.B }
1N/A.fi
1N/A.sp
1N/A.in
1N/AFunctions defined with this syntax cannot be used as the first
1N/Aargument to a \fB\s+2.\s-2\fP procedure.
1N/A\f5ksh\fP accepts this notation for compatibility only.
1N/AThere is no need to use this notation when writing
1N/A\f5ksh\fP scripts.
1N/A.P
1N/AFunctions defined with the \f5function\fP\ \fIname\fP syntax
1N/Aand invoked by name
1N/Aare executed in the current shell environment
1N/Aand can share named variables with the calling program.
1N/AOptions, other than execution trace
1N/A.BR \-x ,
1N/Aset by the calling program are
1N/Apassed down to a function.
1N/AThe options are
1N/Anot shared with
1N/Athe function so that any options set within a function are
1N/Arestored when the function exits.
1N/ATraps ignored by the caller are ignored within the function
1N/Aand cannot be enabled.
1N/ATraps caught by the calling program are reset to their
1N/Adefault action within the function.
1N/AIn most instances, the default action is
1N/Ato cause the function to terminate.
1N/AA trap on
1N/A\fB\s-1EXIT\s+1\fP
1N/Adefined within a function executes after the function
1N/Acompletes but
1N/Abefore the caller resumes.
1N/ATherefore,
1N/Aany variable assignments and
1N/Aany options set as part of a trap action will be effective
1N/Aafter the caller resumes.
1N/A.P
1N/ABy default, variables are inherited by the function and shared
1N/Aby the calling program.
1N/AHowever,
1N/Afor functions defined with the \f5function\fP\ \fIname\fP syntax
1N/Athat are invoked by name,
1N/Aenvironment substitutions preceding the function call
1N/Aapply only to the scope of the function call.
1N/AAlso, variables whose names do not contain a \fB\s+2.\s-2\fP
1N/Athat are defined with the \f5typeset\fP
1N/Abuilt-in command are local to the function that they are declared in.
1N/AThus, for the function defined
1N/A.sp
1N/A.nf
1N/A.in .5i
1N/A\f5function name
1N/A{
1N/A typeset -i x=10
1N/A let z=x+y
1N/A print $z
1N/A}\fP
1N/A.fi
1N/A.ta
1N/A.in
1N/A.sp
1N/Ainvoked as
1N/A\f5y=13\ name\fP,
1N/A\f5x\fP and \f5y\fP
1N/Aare local variables with respect to the function
1N/A\f5name\fP
1N/Awhile
1N/A\f5z\fP
1N/Ais global.
1N/A.P
1N/AFunctions defined with the \fIname\fP\f5()\fP syntax,
1N/Aand functions invoked as an argument to the \fB\s+2.\s-2\fP
1N/Acommand,
1N/Ashare everything other than positional parameters with the caller.
1N/AAssignments that precede the call remain in effect after the
1N/Afunction completes.
1N/A.P
1N/AAlias and function names are not passed down to shell scripts
1N/Aor carried across separate
1N/Ainvocations of \f5ksh\fP.
1N/AThe
1N/A.B $\s-1FPATH\s+1
1N/Avariable gives a colon separated list of directories that
1N/Ais searched for function definitions when trying to resolve
1N/Athe command name.
1N/AWhenever a file name contained in
1N/A.B $\s-1FPATH\s+1
1N/Ais found, the complete file is read and all functions
1N/Acontained within become defined.
1N/A.P
1N/ACalls that reference functions can be recursive.
1N/AExcept for special built-ins,
1N/Afunction names take precedence over built-in names and names
1N/Aof programs when used as command names.
1N/ATo write a replacement function that invokes the command that
1N/Ayou wish to replace,
1N/Ayou can use the \f5command\fP built-in command.
1N/AThe arguments to \f5command\fP are the name and arguments
1N/Aof the program you want to execute.
1N/AFor example to write a
1N/A.B cd
1N/Afunction which changes the directory and prints out the directory name,
1N/Ayou can write
1N/A.sp
1N/A.nf
1N/A.in .5i
1N/A\f5function cd
1N/A{
1N/A if command cd "$@"
1N/A then print -r -- $PWD
1N/A fi
1N/A}\fP
1N/A.fi
1N/A.ta
1N/A.in
1N/A.sp
1N/A.P
1N/AThe
1N/A\fB\s-1FPATH\s+1\fP
1N/Avariable is a colon separated list that \f5ksh\fP
1N/Auses to search for function definitions.
1N/AWhen
1N/A\f5ksh\fP
1N/Aencounters an autoload function,
1N/Ait runs the
1N/A.B .
1N/Acommand on the script containing the function,
1N/Aand then executes the function.
1N/A.P
1N/AFor interactive shells,
1N/Afunction definitions may also be placed in the
1N/A\fB\s-1ENV\s+1\fP
1N/Afile.
1N/AHowever, this
1N/Acauses the shell to take longer to begin executing.
1N/A.H 2 "Process Substitution"
1N/A.P
1N/AThis feature is only available
1N/Aon versions of the UNIX operating system which support the
1N/A.B /dev/fd
1N/Adirectory for naming open files.
1N/AEach command argument of the form
1N/A\fB<(\fP\fIlist\^\fP\fB)\fP
1N/Aor
1N/A\fB>(\fP\fIlist\^\fP\fB)\fP
1N/Awill run process
1N/A.I list
1N/Aasynchronously connected to some file in the
1N/A.B /dev/fd
1N/Adirectory.
1N/AThe name of this file will become the argument to the command.
1N/AIf the form with
1N/A.B >
1N/Ais selected then writing on this file will provide input for
1N/A.IR list .
1N/AIf
1N/A.B <
1N/Ais used,
1N/Athen the file passed as an argument will contain the output of the
1N/A.I list
1N/Aprocess.
1N/AFor example,
1N/A.sp
1N/A.nf
1N/A.in .5i
1N/A\f5paste <(cut \-f1 \fP\fIfile1\fP\f5) <(cut \-f2 \fP\fIfile2\fP\f5) | tee >(\fP\fIprocess1\fP\f5) >(\fP\fIprocess2\fP\f5)\fP
1N/A.fi
1N/A.ta
1N/A.in
1N/A.sp
1N/Aextracts
1N/Afields 1 and 3 from
1N/Athe files
1N/A.I file1
1N/Aand
1N/A.I file2
1N/Arespectively,
1N/Aplaces the
1N/Aresults side by side, and
1N/Asends it
1N/Ato the processes
1N/A.I process1
1N/Aand
1N/A.IR process2 ,
1N/Aas well as putting it onto the standard output.
1N/ANote that the file which is passed as an argument to the command is
1N/Aa UNIX system
1N/A.IR pipe (2)
1N/Aso that the programs that expect to
1N/A.IR lseek (2)
1N/Aon the file will not work.
1N/A.H 2 "Finding Commands"
1N/A.P
1N/AThe addition of aliases, functions,
1N/Aand more built-ins
1N/Ahas made it substantially more difficult to know what
1N/Aa given command name really means.
1N/A.P
1N/ACommands that begin with reserved words
1N/Aare an integral part of the shell language itself
1N/Aand typically define the control flow of the language.
1N/ASome control flow commands are not reserved words in
1N/Athe language but are \fIspecial\fP built-ins.
1N/ASpecial built-ins are built-ins that are considered a
1N/Apart of the language rather than user definable commands.
1N/AThe best examples of commands that fit this description
1N/Aare \f5break\fP and \f5continue\fP.
1N/ABecause they are not reserved words, they can be the
1N/Aresult of shell expansions and are not effected by quoting.
1N/AThese commands have the following special properties:
1N/A.BL
1N/A.LI
1N/AAssignments that precede them apply to the current shell process,
1N/Anot just to the given command.
1N/A.LI
1N/AAn error in the format of these commands cause a shell script
1N/Aor function that contains them to abort.
1N/A.LI
1N/AThey cannot be overridden by shell functions.
1N/A.LE
1N/A.P
1N/AOther commands are built-in because they perform side effects
1N/Aon the current environment that would be nearly impossible
1N/Ato implement otherwise.
1N/ABuilt-ins such as \f5cd\fP and \f5read\fP
1N/Aare examples of such built-ins.
1N/AThese built-ins are semantically equivalent to commands that
1N/Aare not built-in except that they don't take a path search
1N/Ato locate.
1N/A.P
1N/AA third reason to have a command built-in is so that
1N/Ait will be unaffected by the setting of the
1N/A.B \s-1PATH\s+1
1N/Avariable.
1N/AThe \f5print\fP command fits this category.
1N/AScripts that use \f5print\fP will be portable
1N/Ato all sites that run \f5ksh\fP.
1N/A.P
1N/AThe final reason for having a command be a built-in is
1N/Afor performance.
1N/AOn most systems it is more than an order of magnitude
1N/Afaster to initiate a command that is built-in than
1N/Ato create a separate process to run the command.
1N/AExamples that fit this category are \f5test\fP
1N/Aand \f5pwd\fP.
1N/A.P
1N/AGiven a command name \f5ksh\fP decides what it means using
1N/Athe following order:
1N/A.BL
1N/A.LI
1N/AReserved words define commands that form part of the shell
1N/Agrammar.
1N/AThey cannot be quoted.
1N/A.LI
1N/AAlias substitutions occur first as part of the reading of commands.
1N/AUsing quotes in the command name will prevent alias substitutions.
1N/A.LI
1N/ASpecial built-ins.
1N/A.LI
1N/AFunctions.
1N/A.LI
1N/ACommands that are built-in that are not associated with a pathname
1N/Asuch as \f5cd\fP and \f5print\fP.
1N/A.LI
1N/AIf the command name contains a
1N/A.BR / ,
1N/Athe program or script corresponding to the given name is executed.
1N/A.LI
1N/AA path search locates the pathname corresponding to the command.
1N/AIf the pathname where it is found matches the pathname associated
1N/Awith a built-in command, the built-in command is executed.
1N/AIf the directory where the command is found is listed in the
1N/A.B \s-1FPATH\s+1
1N/Avariable, the file is read into the shell
1N/Alike a dot script, and a function by that name is invoked.
1N/AOnce a pathname is found, \f5ksh\fP remembers its location
1N/Aand only checks relative directories in \fB\s-1PATH\s+1\fP
1N/Athe next time the command name is used.
1N/AAssigning a value to \fB\s-1PATH\s+1\fP
1N/Acauses \f5ksh\fP to forget the location of all command names.
1N/A.LI
1N/AThe
1N/A.B \s-1FPATH\s+1
1N/Avariable is searched and files found are treated as described above.
1N/A.LE
1N/A.P
1N/AThe first argument of the \f5command\fP built-in, described earlier,
1N/Askips the checks for reserved words and for function definitions.
1N/AIn all other ways, \f5command\fP behaves like a built-in
1N/Athat is not associated with a pathname.
1N/AAs a result, if the first argument of \f5command\fP is
1N/Aa special built-in, the special properties of this built-in
1N/Ado not apply.
1N/AFor example, whereas, \f5exec\ 3<\ foo\fP will cause a script containing
1N/Ait to abort if the open fails, \f5command\ exec\ 3<\ foo\fP
1N/Aresults in a non-zero exit status but does not abort the script.
1N/A.P
1N/AYou can get a complete list of the special built-in commands
1N/Awith \f5builtin\ -s\fP.
1N/AIn addition \f5builtin\fP without arguments gives a list of
1N/Athe current built-ins and the pathname that they are associated with.
1N/AA built-in can be bound to another pathname by giving
1N/Athe pathname for the built-in. The basename of this path must
1N/Abe the name of an existing built-in for this to succeed.
1N/ASpecifying the name of the built-in without a pathname causes
1N/Athis built-in to be found before a path search.
1N/AA built-in can be deleted with the \fB\-d\fP option.
1N/A.P
1N/AOn systems with run time loading of libraries, built-in commands
1N/Acan be added with the \f5builtin\fP command.
1N/AEach command that is to be built-in must be written as a
1N/AC function whose name is of the form \f5b_\fP\fIname\fP, where
1N/A\fIname\fP is the name of the built-in that is to be added.
1N/AThe function has the same argument calling convention as
1N/A\f5main\fP. The lower eight bits of the return value become
1N/Athe exit status for this built-in.
1N/ABuiltins are added by specifying the pathname of the library
1N/Aas an argument to the \fB\-f\fP option of \f5builtin\fP.
1N/A.P
1N/AThe built-in command,
1N/A\f5whence\fP,
1N/Awhen used with the
1N/A.B \-v
1N/Aoption, tells how a given command is bound.
1N/AA line is printed for each argument to \f5whence\fP
1N/Atelling what would happen if this argument were used as a command name.
1N/AIt reports on reserved words, aliases, built-ins, and
1N/Afunctions.
1N/AIf the command is none of the above,
1N/Ait follows the path search rules and prints the full path-name,
1N/Aif any, otherwise it prints an error message.
1N/A.H 2 "Symbolic Names"
1N/ATo avoid implementation dependencies, \f5ksh\fP
1N/Aaccepts and generates symbolic names
1N/Afor built-ins that use numerical values in the Bourne shell.
1N/AThe
1N/A.B \-S
1N/Aoption of the
1N/A\f5umask\fP built-in command
1N/Aaccepts and displays
1N/Adefault file creation permissions
1N/Asymbolically.
1N/AIt uses the same symbolic notation as the \f5chmod\fP command.
1N/A.P
1N/AThe \f5trap\fP and \f5kill\fP built-in commands
1N/Aallows the signal names to be given symbolically.
1N/AThe names of signals and traps
1N/Acorresponding to signals are the same as the signal name with
1N/Athe
1N/A.B \s-1SIG\s+1
1N/Aprefix removed.
1N/AThe trap
1N/A.B 0
1N/Ais named
1N/A\fB\s-1EXIT\s+1\fP.
1N/A.H 2 "Additional Variables"
1N/AIn addition to the variables discussed earlier, \f5ksh\fP
1N/Ahas other variables that it handles specially.
1N/AThe variable \fB\s-1RANDOM\s+1\fP
1N/Aproduces a random number in the range 0 to 32767 each time it is referenced.
1N/AAssignment to this variable sets the seed for the
1N/Arandom number generator.
1N/A.P
1N/AThe parameter \fB\s-1PPID\s+1\fP
1N/Ais used to generate the process id of the process which invoked this shell.
1N/A.H 2 "Added Traps"
1N/AA new trap named
1N/A\fB\s-1ERR\s+1\fP
1N/Ahas been added.
1N/AThis trap is invoked whenever the shell would exit if the
1N/A.B \-e
1N/Aoption were set.
1N/AThis trap is used by
1N/AFourth Generation Make\*(Rf
1N/A.RS
1N/AG. S. Fowler,
1N/A.I "The Fourth Generation Make,"
1N/AProceedings of the Portland USENIX meeting, pp. 159-174, 1985.
1N/A.RF
1N/Awhich runs \f5ksh\fP
1N/Aas a co-process.
1N/A.P
1N/AA trap named
1N/A\fB\s-1DEBUG\s+1\fP
1N/Agets executed after each command.
1N/AThis trap can be used for debugging and other purposes.
1N/A.P
1N/AThe
1N/A\fB\s-1KEYBD\s+1\fP
1N/Atrap was described earlier.
1N/A.H 2 Debugging
1N/AThe primary method for debugging Bourne shell scripts is to
1N/Ause the
1N/A.B \-x
1N/Aoption to enable the execution trace.
1N/AAfter all
1N/Athe expansions have been performed,
1N/Abut before each command is executed,
1N/Athe trace writes to standard error the name and arguments
1N/Aof each command preceded by a
1N/A.BR + .
1N/AWhile the trace is very useful, there is no way
1N/Ato find out what line of source a given trace line
1N/Acorresponds to.
1N/AWith
1N/A\f5ksh\fP
1N/Athe
1N/A\fB\s-1PS4\s+1\fP
1N/Avariable
1N/Ais evaluated for parameter expansion and
1N/Ais displayed before each command,
1N/Ainstead of the
1N/A.BR + .
1N/A.P
1N/AThe
1N/A\fB\s-1LINENO\s+1\fP
1N/Avariable is set to the current line number relative to the
1N/Abeginning of the current script or function.
1N/AIt is most useful as part of the
1N/A\fB\s-1PS4\s+1\fP
1N/Aprompt.
1N/A.P
1N/AThe
1N/A\fB\s-1DEBUG\s+1\fP
1N/Atrap can be used to write a break point shell
1N/Adebugger in \f5ksh\fP.
1N/AAn example of such a debugger is \f5kshdb\fP.\*(Rf
1N/A.RS
1N/ABill Rosenblatt,
1N/A.IR "Debugging Shell Scripts with \f5kshdb\fP" ,
1N/AUnix World, Volume X, No. 5, 1993.
1N/A.RF
1N/A.H 2 "Timing Commands"
1N/A.P
1N/AFinding the time it takes to execute commands
1N/Ahas been a serious problem with the Bourne shell.
1N/ASince the \f5time\fP command is not part of the
1N/Alanguage, it is necessary to write a script
1N/Ain order to time a \f5for\fP or \f5while\fP loop.
1N/AThe extra time in invoking the shell and processing
1N/Athe script is accumulated along with the time
1N/Ato execute the script.
1N/A.P
1N/AMore seriously, the Bourne shell does not give correct
1N/Atimes for pipelines.
1N/AThe reason for this is that the times for some members
1N/Aof a pipeline are not counted when computing the time.
1N/AAs an extreme example,
1N/Arunning \f5time\fP on the script
1N/A.ce
1N/A\f5cat < /dev/null | sort -u bigfile | wc\fP
1N/Awith the Bourne shell will show very little
1N/Auser and system time no matter how
1N/Alarge \f5bigfile\fP is.
1N/A.P
1N/ATo correct these problems,
1N/Aa reserved word \f5time\fP
1N/Ahas been added to replace
1N/Athe \f5time\fP
1N/Acommand.
1N/AAny function, command or pipeline can be preceded by this reserved word
1N/Ato obtain information about the elapsed, user, and system times.
1N/ASince I/O redirections bind to the command, not to
1N/A\f5time\fP,
1N/Aparentheses should be used to redirect the timing information which
1N/Ais normally printed on file descriptor 2.
1N/A.H 1 SECURITY
1N/AThere are several documented problems associated with the security of
1N/Ashell procedures\*(Rf.
1N/A.RS
1N/AF. T. Grampp and R. H. Morris,
1N/A.I "UNIX Operating System Security,"
1N/AAT&T Bell Labs Tech. Journal, Vol. 63, No. 8, Part 2, pp. 1649-1671, 1984.
1N/A.RF
1N/AThese security holes occur primarily because a user can manipulate the
1N/A.I environment
1N/Ato subvert the intent of a
1N/A.I setuid
1N/Ashell procedure.
1N/ASometimes, shell procedures are initiated from
1N/Abinary programs, without the author's
1N/Aawareness, by library routines which invoke shells to carry out
1N/Atheir tasks.
1N/AWhen the binary program is run
1N/A.I setuid
1N/Athen the shell procedure runs with the permissions afforded to the
1N/Aowner of the binary file.
1N/A.P
1N/AIn the Bourne shell,
1N/Athe
1N/A.B \s-1IFS\s+1
1N/Aparameter is used to split each word into separate command arguments.
1N/AIf a user knows that some
1N/A.I setuid
1N/Aprogram will run
1N/A\f5sh\ -c\ /bin/pwd\fP
1N/A(or any other command in
1N/A.BR /bin )
1N/Athen the user sets and exports
1N/A.BR \s-1IFS\s+1=\^/ .
1N/AInstead of running
1N/A.B /bin/pwd
1N/Athe shell will run
1N/A.B bin
1N/Awith
1N/A.B pwd
1N/Aas an argument.
1N/AThe user puts his or her own \f5bin\fP
1N/Aprogram into the current directory.
1N/AThis program can
1N/Acreate a copy of the shell,
1N/Amake this shell
1N/A.IR setuid ,
1N/Aand then run the \f5/bin/pwd\fP
1N/Aprogram so that the original program continues to run successfully.
1N/AThis kind of penetration is not possible with
1N/A\f5ksh\fP
1N/Asince the
1N/A.B \s-1IFS\s+1
1N/Aparameter only splits arguments that result from command or parameter
1N/Asubstitution.
1N/A.P
1N/ASome
1N/A.I setuid
1N/Aprograms run programs using
1N/A.I system()
1N/Awithout giving the full pathname.
1N/AIf the
1N/Auser sets the
1N/A.B \s-1PATH\s+1
1N/Avariable so that the desired command will be found
1N/Ain his or her local bin, then the same technique described above can
1N/Abe employed to compromise the security of the system.
1N/ATo close up this and other security holes,
1N/A\f5ksh\fP
1N/Aresets the effective user id to the real user id and the effective
1N/Agroup id to the real group id unless the
1N/A.I privileged
1N/Aoption
1N/A.RB ( \-p\^ )
1N/Ais specified at invocation.
1N/AIn
1N/Athis mode, the
1N/A.B privileged
1N/Amode, the
1N/A.B .profile
1N/Aand
1N/A.B \s-1ENV\s+1
1N/Afiles are not processed.
1N/AInstead, the file
1N/A.B /etc/suid_profile
1N/Ais read and executed.
1N/AThis gives an administrator control over the
1N/Aenvironment to set the
1N/A.B \s-1PATH\s+1
1N/Avariable or to log setuid shell invocations.
1N/AClearly security of the system is compromised if
1N/A.B /etc
1N/Aor this file is publicly writable.
1N/A.P
1N/ASome versions of the UNIX operating system look for the characters
1N/A\f5#!\fP
1N/Aas the first two characters of an executable file.
1N/AIf these characters are found, then the next word on this line is taken
1N/Aas the interpreter to
1N/Ainvoke
1N/Afor this command and the interpreter is
1N/A.IR exec ed
1N/Awith the name of the script as argument zero and argument one.
1N/AIf the
1N/A.I setuid
1N/Aor
1N/A.I setgid
1N/Abits are on for this file, then the interpreter
1N/Ais run with the effective uid and/or gid set accordingly.
1N/AThis scheme has three major drawbacks.
1N/AFirst of all,
1N/Aputting the pathname of the interpreter into the script
1N/Amakes the script less portable since the interpreter
1N/Amay be installed in a different directory on another system.
1N/ASecondly, using the
1N/A\f5#!\fP
1N/Anotation forces an
1N/A.B exec
1N/Aof the interpreter even when the call is invoked from the interpreter
1N/Awhich it must exec. This is inefficient since
1N/A\f5ksh\fP can handle a failed exec much faster than starting up
1N/Aagain.
1N/AMore importantly,
1N/A.I setuid
1N/Aand
1N/A.I setgid
1N/Aprocedures provide an easy target for intrusion.
1N/ABy linking a
1N/A.I setuid
1N/Aor
1N/A.I setgid
1N/Aprocedure to a name beginning with a
1N/A.B \-
1N/Athe interpreter is fooled into thinking that it is being invoked with
1N/Aa command line option rather than the name of a file.
1N/AWhen the interpreter is the shell, the user gets a privileged
1N/Ainteractive shell.
1N/AThere is code in
1N/A\f5ksh\fP
1N/Ato guard against this simple form of intrusion.
1N/A.P
1N/AA more reliable way to handle
1N/A.I setuid
1N/Aand
1N/A.I setgid
1N/Aprocedures is provided with
1N/A\f5ksh\fP.
1N/AThe technique does not require any changes to the operating system
1N/Aand provides better security.
1N/AAnother advantage to this method is that it also allows scripts which
1N/Ahave execute permission but no read permission to run. Taking away read
1N/Apermission makes scripts more secure.
1N/A.P
1N/AThe method relies on a setuid
1N/A.B root
1N/Aprogram to authenticate the
1N/Arequest and exec the shell with the correct mode bits to carry out
1N/Athe task. This shell is invoked with the requested file already open
1N/Afor reading. A script which cannot be opened for reading or which
1N/Ahas its setuid and/or setgid bits turned on causes this setuid
1N/A.B root
1N/Aprogram to get \fBexec\fPed.
1N/AFor security reasons, this program is given the full
1N/Apathname
1N/A\f5/etc/suid_exec\fP.
1N/AA description of the implementation of the
1N/A\f5/etc/suid_exec\fP
1N/Aprogram can be found in
1N/Aa separate paper\*(Rf.
1N/A.RS
1N/AD. G Korn
1N/A.I "Parlez-vous Kanji?"
1N/ATM-59554-860602-03, 1986.
1N/A.RF
1N/A.H 1 "CODE CHANGES"
1N/A\f5ksh\fP is written in ANSI-C as a reusable library.
1N/AThe code can be compiled with C++ and older K&R C as well.
1N/AThe code uses the IEEE POSIX 1003.1 and ISO 9945-1 standard\*(Rf
1N/A.RS
1N/A.I "POSIX \- Part 1: System Application Program Interface,"
1N/AIEEE Std 1003.1-1990, ISO/IEC 9945-1:1990.
1N/A.RF
1N/Awherever possible so that \f5ksh\fP should be able to run
1N/Aon any POSIX compliant system. In addition, it is possible
1N/Ato compile \f5ksh\fP for older systems.
1N/A.P
1N/AUnlike earlier version of the Bourne shell,
1N/A\f5ksh\fP treats eight bit characters transparently
1N/Awithout stripping off the
1N/Aleading bit.
1N/AThere is also a compile time switch to enable handling multi-byte
1N/Aand multi-width characters sets.
1N/A.P
1N/AOn systems with dynamic libraries, it is possible to add built-in
1N/Acommands at run time with the built-in command \f5builtin\fP
1N/Adescribed earlier.
1N/AIt is also possible to embed \f5ksh\fP in applications in
1N/Aa manner analogous to \f5tcl\fP.
1N/A.H 1 "EXAMPLE"
1N/A.P
1N/AAn example of a \f5ksh\fP script is included
1N/Ain the Appendix.
1N/AThis one page program is a variant of the UNIX system
1N/A\f5grep\fP(1) program.
1N/APattern matching for this version of \f5grep\fP
1N/Ameans shell patterns.
1N/A.P
1N/AThe first half uses the \f5getopts\fP command to
1N/Afind the option flags.
1N/ANearly all options have been implemented.
1N/AThe second half goes through each line of each file
1N/Ato look for a pattern match.
1N/A.P
1N/AThis program is not intended to serve as a
1N/Areplacement for \f5grep\fP
1N/Awhich has been highly tuned for performance.
1N/AIt does
1N/Aillustrate the programming power of \f5ksh\fP.
1N/ANote that no auxiliary processes are spawned by this script.
1N/AIt was written and debugged in under two hours.
1N/AWhile performance is acceptable for small files,
1N/Athis program runs at only one tenth
1N/Athe speed of \f5grep\fP
1N/Afor large files.
1N/A.H 1 "PERFORMANCE"
1N/A.P
1N/A\f5ksh\fP executes many scripts faster than the System V Bourne shell;
1N/Ain some cases more than 10 times as fast.
1N/AThe primary reason for this is that \f5ksh\fP creates fewer
1N/Aprocesses.
1N/AThe time to execute a built-in command or a function is one or two
1N/Aorders of magnitude faster than performing a \f5fork\fP() and
1N/A\f5exec\fP() to create a separate process.
1N/ACommand substitution and commands inside parentheses
1N/Aare performed without creating another process, unless necessary
1N/Ato preserve correct behavior.
1N/A.P
1N/AAnother reason for improved performance is the use of the \fBsfio\fP\*(Rf,
1N/A.RS
1N/ADavid Korn and Kiem-Phong Vo,
1N/A.IR "SFIO - A Safe/Fast String/File I/O,"
1N/AProceedings of the Summer Usenix,
1N/App. 235-255, 1991.
1N/A.RF
1N/Alibrary for I/O. The \fBsfio\fP library buffers all I/O
1N/Aand buffers are flushed only when required.
1N/AThe algorithms used in \fBsfio\fP perform better than
1N/Atraditional versions of standard I/O so that programs that
1N/Aspend most of their time
1N/Aformatting output may actually perform better
1N/Athan versions written in C.
1N/A.P
1N/ASeveral of the internal algorithms have been changed
1N/Aso that the number of subroutine calls has been
1N/Asubstantially reduced.
1N/A\f5ksh\fP uses variable sized hash tables for variables.
1N/AScripts that rely heavily on referencing variables execute faster.
1N/AMore processing is performed while reading the script
1N/Aso that execution time is saved while running loops.
1N/AThese changes are not noticeable for scripts that \f5fork()\fP
1N/Aand run processes,
1N/Abut they reduce the time that it takes to interpret commands by
1N/Amore than a factor of two.
1N/A.P
1N/AMost importantly, \f5ksh\fP provide mechanisms to write applications
1N/Athat do not require as many processes.
1N/AThe arithmetic provided by the shell eliminates the need for the
1N/A\f5expr\fP command.
1N/AThe pattern matching and substring capabilities eliminate the
1N/Aneed to use \f5sed\fP or \f5awk\fP to process strings.
1N/A.P
1N/AThe architecture of \f5ksh\fP makes it easy to make commands
1N/Abuilt-ins without changing the semantics at all.
1N/ASystems that have run-time binding of libraries allow
1N/Aapplications to be sped up by supplying the critical
1N/Aprograms as shell built-in commands.
1N/AImplementations on other systems can add built-in commands
1N/Aat compile time.
1N/AThe procedure for writing built-in commands that can be loaded
1N/Aat run time is in a separate document.\*(Rf,
1N/A.RS
1N/ADavid Korn,
1N/A.IR "Guidelines for writing \f5ksh-93\fP built-in commands,"
1N/Ato be published, 1994.
1N/A.RF
1N/A.H 1 "CONCLUSION"
1N/A.P
1N/AThe 1988 version of \f5ksh\fP has tens of thousands of regular users
1N/Aand is a suitable replacement for the Bourne shell.
1N/AThe 1993 version of \f5ksh\fP is essentially upward compatible with
1N/Aboth the 1988 version of \f5ksh\fP and with the recent IEEE POSIX
1N/Aand ISO shell standard.
1N/AThe 1993 version offers many advantages for programming applications,
1N/Aand it has been rewritten so that it can be used in embedded applications.
1N/AIt also offers improved performance.
1N/A.SG dgk \" signature typist initials
1N/A\" .CS 14 24 38 0 0 16 \" cover sheet for TM
1N/A.bp
1N/A.ce
1N/A\fIAPPENDIX\fP
1N/A.nf
1N/A\f5
1N/A.ta .66i 1.33i 2i 2.66i 3.33i 4i 4.66i 5.33i 6i 6.66i 7.33i 8i
1N/A.so grep.mm
1N/A.fi
1N/A\fP
1N/A
1N/A