Lines Matching refs:the
16 (shell) for the UNIX*
22 is essentially compatible with the System V version of the Bourne shell\*(Rf,
25 .I "An Introduction to the UNIX
30 \f5ksh-93\fP is intended to comply with the IEEE POSIX 1003.2
37 In addition to changes in the language required
38 by these standards, the primary focus of \f5ksh-93\fP
40 \f5ksh-93\fP provides the programming power of several
67 Proceedings of the Washington USENIX meeting, pp. 133-146, 1990.
71 assumes that the reader is already familiar with the Bourne shell.
72 It introduces most of the features of \f5ksh-93\fP
73 relative to the Bourne shell; both
83 Because the UNIX*\
88 the operating system itself,
91 in the design and implementation of shells,
92 with the better ones surviving.
93 The most widely available UNIX system shells are the Bourne shell\*(Rf,
96 .IR "An Introduction to the UNIX Shell" ,
102 the C shell\*(Rf,
105 .IR "An Introduction to the C Shell" ,
109 written by Bill Joy at the University of California, Berkeley,
110 and the KornShell language \*(Rf,
118 The Bourne shell is available on almost all versions of the UNIX
124 The source for the KornShell language is available from the AT&T Toolchest,
126 It runs on all known versions of the UNIX system and
129 There have been several articles comparing the UNIX system shells.
136 highlights some of the new features
137 introduced by the KornShell language.
141 .IR "Proficiency and Power are Yours With the Korn Shell" ,
144 explains some of the advantages of using the KornShell language.
150 Edited by the Waite Group, Howard W. Sams & Co., 1987.
152 provides a more detailed comparison of the three shells,
155 The KornShell language is a superset of the
156 Bourne shell. The KornShell language has many of the popular C shell features,
160 The primary interactive benefit of the KornShell command language
167 in the long run,
168 the power of the KornShell language as a high-level programming language,
172 .I "Using the shell as a Primary Programming Tool,"
177 \f5ksh-93\fP provides the programming power of several
183 An application that was originally written in the C programming language
184 was rewritten in the KornShell language.
188 between the two versions of the code.
204 the program that implements an enhanced version
205 of the KornShell language.
206 It is referred to as \f5ksh\fP in the rest of this memo.
207 The memo describes the KornShell language based on the
208 features of the 12/28/93 release of \f5ksh\fP.
211 a more complete treatment of the KornShell language.
219 When there are conflicts between versions of the shell,
220 \f5ksh-93\fP selects the behavior dictated by the IEEE POSIX
223 that the reader is already familiar with the Bourne shell.
226 All features of the language, except job control,
235 Options are either of the form \f5-\fP\fIletter\fP,
237 In the former case, several options may be grouped after a single \f5-\fP.
238 The argument \f5--\fP signifies an end to the option list and is
239 only required when the first non-option argument begins with
244 In addition, the option sequence \f5-?\fP causes most commands
245 to print a usage message which lists the valid options.
248 using the command name to locate a program to run
249 and by running the program as a separate process.
255 In nearly all cases the distinction
257 is not is invisible to the user.
261 \f5ksh\fP has several options that can be set by the user
262 as command line arguments at invocation and as option arguments to the
265 that follows the \f5-o\fP option.
268 to display the current option settings.
277 when the shell is connected to a terminal device.
294 the
300 is used to prevent the
305 from exiting the shell and possibly logging you out.
308 Most of the options are described in this memo as appropriate.
313 Aliases are defined with the \f5alias\fP
320 the \f5=\fP.
322 special to the shell.
337 the command name is checked against a list of
341 the name is replaced by the alias value associated with the
344 When rescanning the value for an alias, alias substitutions
347 For example with the aliases, \f5alias\ l=ls\ 'ls=ls\ -C'\fP,
348 the command name \f5l\fP becomes \f5ls\fP, which becomes \f5ls\ -C\fP.
349 Ordinarily, only the command name word is processed for alias substitution.
350 However, if the value of an alias ends in a space,
351 then the word following the alias is also checked for alias substitution.
353 to define an alias whose first argument is the name of a command
359 the alias,
364 using the built-in \f5test\fP command.
371 The \f5unalias\fP command removes the name and text of an alias.
375 For example, the predefined alias
378 allows the integer variables \f5i\fP and \f5j\fP
379 to be declared and initialized with the command
388 procedure (the shell equivalent of an include file)
398 \f5ksh\fP saves the
400 If the variable
402 is set to the name of a file to which the user
404 then the commands are stored in this
407 Otherwise the file
410 an unnamed file is used to hold the history lines.
413 that run concurrently and use the same history file
414 name, share access to the history file so that a command
418 determines that no other shell is using the history file.
419 The number of commands accessible to the user is determined by the value of the
421 variable at the time the shell is invoked.
425 If the character
427 is placed within the
431 then it is replaced by the command number each time the prompt is given.
441 The range can be specified by giving the command
443 the first character or characters of the command.
444 When given without specifying the range,
445 the last 16
447 preceded by the command number.
449 If the listing option is not selected,
450 then the range of commands specified,
451 or the last command if no range is given,
455 with the option
457 and following it with the editor name.
458 If this option is not specified, the
459 value of the shell variable
461 is used as the name of the editor,
464 and the
471 the edited text automatically becomes
472 the input for \f5ksh\fP.
473 As this text is read by \f5ksh\fP, it is echoed onto the terminal.
477 option causes the editing to be bypassed
478 and just re-executes the command.
479 In this case only a single command can be specified as the range
480 and an optional argument of the form
488 the single key-stroke
490 can be used to re-execute the previous command
491 and the key-stroke sequence,
493 can be used to re-execute the last command that starts with
494 the letter \f5c\fP
495 with the first occurrence of the string \f5abc\fP
496 replaced with the string \f5def\fP.
499 re-executes the most recent command starting with the letter \f5c\fP,
506 With the Bourne shell the only method to fix up commands
507 is by backspacing or killing the whole line.
508 \f5ksh\fP offers options that allow the user to edit parts of the
509 current command line before submitting the command.
510 The in-line edit options make the command line into a single
512 When the command is longer than the width of the terminal,
513 only a portion of the command is visible.
514 Moving within the line automatically makes that portion visible.
515 Editing can be performed on this window until the
518 The editing modes have editing directives that access the history file
520 A user can copy any of the most recent
522 commands from this file into the input edit window.
525 The in-line editing options do not use the
531 They only require that the backspace character moves the cursor left
532 and the space character overwrites the current character on the screen
533 and moves the cursor to the right.
543 option is selected by turning on the
545 option of the \f5set\fP
547 If the value of the
552 the corresponding option is turned on.
554 features is available within the shell. Additional
557 In the
561 mode the user positions the cursor to the point
564 The only difference between these two modes is the
565 meaning of the directive
569 The available editing functions are listed in the manual page.
574 starts in insert mode and enters control mode when the
578 key, which submits the current command for processing,
580 The cursor can be anywhere on the line.
592 in the history file,
593 copying the command into the input edit window.
595 the terminal is kept in canonical mode until an
599 and on earlier versions of the UNIX operating system,
611 Most of the code for the editing options does not rely on the
615 all versions of the in-line editors have some features that
617 with all edit modes, the
620 (the first word on the line,
621 or the first word after a
628 that match the portion of the given current word.
630 prints the names of files that match the current
633 adds the expanded list of matching files to the command line.
636 is added to the word if it doesn't contain any file pattern matching
637 characters before the expansion.
647 the list generated by the
649 the longest common prefix.
650 With command completion, only the last component of
651 the pathname is used to compute the longest command prefix.
652 If the longest common prefix is a complete match,
653 then the word is replaced by the pathname, and a
661 from control mode gives the same behavior.
670 from the keyboard,
676 The action associated with this trap can change the value of
677 the entered key to cause the key to perform a different
680 When the
683 the \fB.sh.edtext\fP
684 variable contains the contents of the current input line
685 and the \fB.sh.edcol\fP
686 variable gives the current cursor position within this line.
688 variable contains the
690 character when the trap is entered from
695 variable contains the character or
696 escape sequence that caused the trap.
703 In the \fBvi\fP edit mode,
704 the characters after the
706 must be entered within half a second after the
709 at the end of the trap will be used as
710 the input sequence.
712 Using the associative array facility of \f5ksh\fP described later,
713 and the function facility of \f5ksh\fP, it is easy to write
740 is almost identical to the version introduced in \f5csh\fP
741 of the Berkeley UNIX operating system,
743 The job control feature allows the user to stop and
744 restart programs, and to move programs to and from the
745 foreground and the background.
751 option which, when enabled, will report the progress
752 of background jobs and enable the user to \f5kill\fP
757 with each pipeline typed in from the terminal
759 called the job number.
760 If the job is run asynchronously,
761 the job number is printed at the terminal.
762 At any given time, only one job owns the terminal,
763 i.e., keyboard signals are only sent to the processes in one job.
765 it gives it ownership of the terminal.
767 it you hit the key
772 signal to all processes in the current job.
773 The shell receives notification that the processes
774 have stopped and takes back control of the terminal.
776 There are commands to continue programs in the foreground
782 You can refer to jobs by name or number as described in the manual page.
784 allows you to continue a job in the background,
785 while the built-in command \f5fg\fP
786 allows you to continue a job in the foreground even
787 though you may have started it in the background.
789 A job being run in the background will stop if it tries
790 to read from the terminal.
792 the terminal by setting the terminal options
796 that lists the status of all running and stopped jobs.
798 you are informed of the change of state (running or stopped)
802 as soon as they occur without waiting for a prompt, then use the
805 When you try to exit the shell while jobs are stopped or running,
809 In addition, for login shells, the
813 unless the job has been disowned with the
822 The name of the signal is the name found in the
826 with the prefix
840 maintains a logical view of the file system hierarchy
847 generates the physical pathname of the present working
848 directory by resolving all the symbolic links.
850 the \f5cd\fP
853 A subsequent \f5cd\ ..\fP in the example above
862 in the variable
867 to return to the previous directory
868 and print the name of the directory.
870 done twice returns you to the starting directory,
871 not the second previous directory.
880 directories from the stack.
887 waits for the user to respond.
891 can be set to be the number of seconds that the shell will wait for
898 defined by the value of the
901 is issued at the start of each command.
903 defined by the value of the
908 \f5ksh\fP allows the user to specify a list of files or directories
909 to check before issuing the
918 before the next prompt.
919 Each of the names in this list can be followed by a
921 and a message to be given when a change has been detected in the file.
926 within a mail message will evaluate to the name of the file that
930 is used to specify the minimal interval in seconds before
935 in the prompt with the command number,
937 the value of the
942 to generate the prompt.
944 the prompt is issued must be quoted to prevent the
945 expansions from occurring when assigning the value to
951 to be set to the value of
953 at the time of the assignment whereas
957 to be expanded at the time the prompt is issued.
960 to execute and cause the prompt display to be somewhat
962 when the return key is pressed several times in a row.
972 variable stores the pathname of the current working directory.
976 is the value of the most
977 recent assignment plus the elapsed time.
978 By default, the time is measured in milli-seconds,
981 is a floating point variable, the
982 number of places after the decimal point in the expanded
987 can be used to generate a time stamp into the
992 the
1000 # get the time of day in your prompt
1015 at the beginning of a word has special meaning to \f5ksh\fP.
1016 If the characters after the
1020 match a user login name in the password database, then the
1022 and the name are replaced by
1024 If no match is found, the original word
1030 is replaced by the value of the
1039 is replaced by the value of
1046 can be re-input to the shell.
1052 When an interactive \f5ksh\fP starts, it evaluates the
1058 Earlier versions of \f5ksh\fP read the \fB\s-1ENV\s+1\fP file
1059 for all invocations of the shell primarily to allow
1063 eliminated the primary need for this capability and it was
1064 removed because the high performance cost was no longer
1067 The KornShell vastly extends the set of applications that
1068 can be implemented efficiently at the shell level.
1074 be defined in the same file or in a library of functions
1079 There are no limits to the length of strings. Storage
1080 management is handled by the shell automatically.
1084 Since most of the words in the language are strings, the shell
1086 are normally processed specially by the shell, but their
1088 However, since the shell is a string processing language,
1090 quoting is an important part of the language.
1095 the single quote itself cannot appear.
1100 causes all the characters until the matching single quote
1104 represents the new-line character.
1105 Double quoted strings remove the special meaning of all characters
1113 The final mechanism for quoting a character is by preceding it with the
1116 This mechanism works outside of quoted strings and for the characters
1129 Upper and lower case characters are distinct, so that the variable
1135 limit to the length of the name of a variable.
1137 You can assign a value to a variable by writing the name of the
1142 the variable whose name consists of
1143 the characters before the last \fB\s+2.\s-2\fP
1146 putting the name inside curly braces and
1147 preceding the braces with a dollar sign.
1148 The braces may be omitted when the name
1155 the concatenation of the values of
1165 You can also capture the output of any command with the notation
1170 assigns the output from the \f5date\fP
1171 command to the variable \f5x\fP.
1172 Command substitution in the
1173 Bourne shell is denoted by enclosing the command between
1181 Putting the pattern in single quotes
1183 \f5ksh\fP accepts the Bourne shell command substitution syntax
1188 the \fIcommand\fP itself to contain quoted strings even if the substitution
1191 The special command substitution of the form
1196 the \f5cat\fP
1203 \f5ksh\fP defines the same special parameters,
1213 as in the Bourne shell.
1215 Positional parameters are set when the shell is invoked,
1216 as arguments to the \f5set\fP built-in,
1226 There is no need to specify the
1228 of a variable in the shell because, by default,
1235 that control the internal representation of the variable,
1236 the way the variable is printed, and its access or
1245 Two of the attributes,
1249 are available in the Bourne shell.
1250 Most of the remaining attributes are discussed here.
1251 The complete list of attributes appears in the manual.
1258 the value is transformed according to the attributes of the variable.
1259 Changing the attribute of a variable can change its value.
1267 it is defined the first time an assignment is made to the variable.
1268 Each assignment causes justification of the field, truncating
1273 the beginning or end of a string.
1283 turning on either of these attributes turns the other off.
1286 provides an example of the use of shell variables
1316 attribute causes the value to be represented as an integer and it
1317 can be followed by a number representing the numeric base when expanding
1325 attribute causes the value to be represented in scientific
1326 notation whenever its value is expanded. The number following the
1328 determines the number of significant figures, and defaults to 6.
1331 attribute causes the value to be represented with a fixed number
1332 of places after the decimal point.
1333 Assignments to variables with the
1337 attributes cause the evaluation of the right hand side of the assignment.
1345 string, whereas the subscript for an indexed array is
1360 the next section.
1361 Attributes apply to the whole array.
1365 assignment commands or the
1369 compound assignment as described below, or by the
1372 option of the \f5set\fP command.
1373 Referencing of subscripted variables requires the character
1375 but also requires braces around the array element name.
1376 The braces are needed to avoid conflicts with the
1397 attribute causes the variable to be treated
1398 as a reference to the variable defined by its value.
1400 become references to the variable named by the value
1402 For example, if \f5foo=bar\fP, then setting the reference
1404 to \f5foo\fP to behave as the variable whose name is \f5$foo\fP
1405 was referenced, which in this case is the variable \f5bar\fP.
1406 Unsetting this attribute breaks the association.
1408 arguments are the names of shell variables.
1410 Whenever a shell variable is referenced, the portion of the
1411 variable up to the first \fB\s+2.\s-2\fP
1412 is checked to see whether it matches the name of a reference
1414 If it does, then the name of the variable actually used
1415 consists of the concatenation of the name of the variable
1416 defined by the reference plus the remaining portion of the
1418 For example, using the predefined alias, \f5alias\ nameref='typeset\ -n'\fP,
1438 is the name of the variable to which you want to assign values.
1439 No space is permitted between the variable name and the \fB=\fP
1440 but can appear between the \fB=\fP and the open parenthesis.
1441 New-lines can appear between the parentheses.
1446 the words are processed as they are with the \f5for\fP command
1451 creates an indexed array \f5foo\fP and assigns the
1452 file names in the current directory to each index starting
1456 of the special form \fB[\fP\fIword\fP\fB]=\fP\fIword\fP.
1457 No space is permitted before or after the \fB=\fP.
1458 In this case, the variable given by \fIname\fP becomes
1459 an associative array with the given arguments as subscripts.
1469 corresponding to the given assignments.
1470 In addition to assignments, the \fIassignment-list\fP
1473 the effect of a compound assignment is to make
1474 the value of the original variable be a parenthesized
1476 For example, the assignment
1495 is equivalent to the assignments
1510 In addition, the value of \f5"$foo"\fP is
1531 only a portion of the value results.
1536 the form \fB${\fP\fIname\fP\fB:\fP\fIoffset\fP\fB:\fP\fIlength\fP\fB}\fP
1537 where \fIoffset\^\fP is an arithmetic expression that defines the
1538 offset of the first character starting from 0, and
1539 \fIlength\^\fP is an arithmetic expression that defines the
1540 length of the substring.
1544 the length of the value of
1556 For example, the expansion, \fB${\fP\fIname\fP\fB[@]:\fP\fIoffset\fP\fB:\fP\fIlength\fP\fB}\fP, yie…
1557 starting at the element \fIoffset\fP.
1560 to describe portions of the string to modify and delete.
1569 the operation is performed on each element.
1573 by removing the characters matching a given pattern.
1575 the form \fB${\fP\fIname\fP\fB#\fP\fIpattern\fP\fB}\fP
1576 causes the smallest matching prefix of the value of
1587 the form \fB${\fP\fIname\fP\fB%\fP\fIpattern\fP\fB}\fP
1588 causes the smallest matching substring at the end of
1595 causes the largest matching trailing substring to be deleted.
1596 For example, if the shell variable
1600 then the expression
1606 specifying a pattern that matches the part that needs to be changed
1607 after the
1608 the parameter expansion modifier
1610 An expansion of the form
1612 replaces the first match of \fIpattern\fP with
1613 the value of variable \fIname\fP to \fIstring\fP.
1619 changes all occurrences of the \fIpattern\fP into \fIstring\fP.
1624 cause the matching pattern to be anchored to the beginning and
1628 the name of the variable, the string length of the value, or the number
1631 yields the name of the variable which will be \fIname\fP itself
1633 it will yield the name of the variable it refers to.
1637 generate the names of all subscripts.
1639 will be the length in bytes of
1643 gives the number of elements in the array.
1646 For the most part, the shell is a string processing
1647 language. However, the need for arithmetic has
1649 Many of the characters that are special to the
1652 compatibility with the Bourne shell, \f5ksh\fP uses matching
1662 inside the double parentheses
1663 follows the same syntax, associativity and precedence
1664 as the ANSI-C\*(Rf
1670 The characters between the matching double parentheses
1671 are processed with the same rules used for double
1677 Floating point constants follow the same rules as
1678 the ANSI-C programming language.
1690 The digits are represented by the characters
1694 be used interchangeably to represent the digits
1700 The contents inside the double parentheses
1701 are processed with the same expansions as occurs in a double quoted string,
1704 expansions are performed before the expression is evaluated.
1705 However, there is usually no need to use the
1707 to get the value of a variable
1708 because the arithmetic evaluator replaces the name of the variable
1712 cannot be used when the variable is the subject of assignment
1718 An arithmetic command of the form
1722 is a command that evaluates the enclosed arithmetic expression.
1723 For example, the command
1727 increment the variable \f5x\fP,
1729 The arithmetic command is true (return value 0), when the resulting
1730 expression is non-zero, and false (return value 1) when the
1732 This makes the command easy to use with the \f5if\fP and \f5while\fP
1740 can be used as the first line of a \f5for\fP loop with the same semantics
1741 as the \f5for\fP statement in the ANSI-C programming language.
1743 Arithmetic evaluations can also be performed as part of the evaluation
1749 expands to the value of the enclosed arithmetic expression.
1751 For example using the \f5ksh\fP command \f5print\fP (described
1755 prints the number 4.
1757 The following script prints the first
1777 The commands you enter from the terminal or from a script
1779 expansions to generate the command name and its arguments.
1784 The second phase performs expansions in the following order:
1800 command substitution above are checked with the characters
1801 in the
1812 is performed on each of the fields.
1829 by the shell when not quoted.
1832 Patterns are used by the shell to match pathnames,
1850 between the first and last character of the range.
1853 immediately after the
1855 means match all characters except the characters specified.
1856 For example, the pattern
1864 (dot) followed by any character except the lower case letters,
1868 the ANSI-C
1872 each of the characters in the given \fIclass\fP
1873 for all the ANSI-C character classes.
1875 matches any alpha-numeric character or the character
1880 strings of the form
1898 means that the pattern list enclosed in
1903 matches any pattern in the list of patterns enclosed in
1907 matches any string that contains zero or more of each of the enclosed
1911 requires a match of one or more of any of the given patterns.
1912 For instance, the pattern
1918 matches anything except any of the given patterns.
1921 displays all file names in the current directory that do not end in
1927 for each file name component of the pathname.
1929 any portion of the pathname that contains any special
1932 possibly the last.
1937 If the pattern to be matched starts with a leading \fB\s+2.\s-2\fP,
1940 If the
1945 This overrides the special meaning of \fB\s+2.\s-2\fP
1948 If the
1951 each matching pathname that is the name
1954 appended to the name.
1957 The Bourne shell uses the \f5test\fP
1958 command, or the equivalent \f5[\fP
1962 is that the shell has expanded the words of the \f5test\fP
1978 One of the most frequent errors with
1981 In this case, the argument may expand to more than a single
1991 as part of the language.
1996 delimit the range of the command.
2006 determines the operators before parameter expansion,
2010 are almost the same as those for the \f5test\fP
2012 All unary operators are of the form
2027 The right hand side of the string comparison operators
2031 takes a pattern and tests whether the left hand operand
2032 matches this pattern. Quoting the pattern results
2033 is a string comparison rather than the pattern match.
2047 compare the modification times
2052 the other.
2056 have the same device and i-node number,
2057 i.\ e., a link to the same file.
2065 returns true if the owner (or group) of the file operand matches
2066 that of the caller.
2069 returns true when its operand is the name of an option that is
2072 The following script illustrates some of the uses of
2074 The reference manual contains the complete list of operators.
2094 extended I/O capabilities to enhance the
2095 use of the shell as a programming language.
2096 As with the Bourne shell,
2097 you use the I/O redirection operator,
2100 and the I/O redirection operator,
2104 specifies a file unit number to associate with the file stream.
2107 However, if you specify I/O redirections with the \f5exec\fP
2110 then the I/O redirection applies to the current program.
2111 For example, the command
2118 file descriptor unit by using either of the
2122 operators and putting the file descriptor unit of the original file
2123 after the
2129 after the
2131 indicates that the file should be closed.
2135 and the POSIX shell that are not part of the Bourne shell.
2138 operator overrides the effect of the
2147 Pathnames of the form
2149 are treated as equivalent to the file defined by file descriptor
2151 These name can be used as the script argument to \f5ksh\fP
2155 in the file system, these names can be passed to other commands.
2156 Pathnames of the form
2164 connections to services given by the
2176 to hostid and port number defined by the output of \f5service\ name\fP.
2180 and splitting it into fields based on the value of the
2189 with the Bourne shell,
2190 the \f5read\fP
2194 the \f5read\fP
2197 option to remove the special meaning for
2201 character rather than the line continuation character.
2202 With the Bourne shell,
2205 \f5ksh\fP has options on the \f5read\fP
2206 command to specify the file
2207 descriptor for the input.
2209 array with the
2214 The way the Bourne shell uses the
2226 have the behavior of the Bourne shell, but other
2231 with the user by prompting the user and then requesting some
2233 With the Bourne shell two commands are needed; one to
2234 prompt the user, the other to read the reply.
2236 The first argument of the \f5read\fP
2239 and a prompt string which is used whenever the input
2241 Because the prompt is associated with the \f5read\fP built-in,
2242 the built-in command line editors will be able to re-output
2243 the prompt whenever the line needs to be refreshed when
2246 With the Bourne shell,
2247 there is no way to set a time limit for waiting for the user
2252 point argument that gives the time in seconds,
2253 or fractions of seconds that the shell should wait for a reply.
2255 The version of the \f5echo\fP command in System V
2263 Unfortunately, the BSD versions of \f5echo\fP accepts a
2266 cause the string
2273 outputs characters to the terminal or to a file and
2274 subsumes the functions of all versions of \f5echo\fP.
2277 are processed the same as for the System V \f5echo\fP command.
2278 However \f5print\fP follows the standard conventions for
2282 option can be used to output the arguments without any special meaning.
2285 option can be used here to suppress the trailing new-line
2287 As with \f5read\fP, it is possible to specify the file descriptor number
2288 as an option to the command to avoid having to use
2289 redirection operators with each occurrence of the command.
2292 to reconcile the differences between the System V and BSD
2296 and outputs the strings using the ANSI-C formatting rules.
2301 a format string which processes the arguments the same way that
2309 format causes the
2311 escape sequences to be expanded as they are with the System V \f5echo\fP
2316 be placed on the output as required
2318 Special characters in the output of most \f5ksh\fP built-in commands
2319 and in the output from an execution trace
2327 Finally, the escape sequence
2329 which expands to the terminal escape character (octal 033)
2336 statement has been added to the language
2338 present menu selection alternatives to the
2339 user and evaluate the reply.
2343 is issued and if the answer is
2344 a number corresponding to one of the alternatives,
2345 the select loop variable is set to this value.
2346 In any case, the
2348 variable is used to store the user entered reply.
2353 are used to control the layout of select lists.
2357 with the way \f5ksh\fP does for its own built-in commands.
2362 do not require space to separate them from the option argument.
2365 variable stores the value of the option argument
2369 variable holds the index of the current options argument.
2370 After processing options, the arguments should be
2373 to make the
2377 information to be specified along with the options
2379 incorrect arguments and for the option argument \fB\-?\fP.
2380 The example in the APPENDIX uses \f5getopts\fP to process
2389 standard output connected to the shell. The built-in command \f5print\fP
2390 with the
2392 option will write into the standard input of this
2394 the built-in command \f5read\fP
2395 with the
2397 option will read from the output of this process.
2399 In addition, the I/O redirection operators \fB<&\fP and \fB>&\fP can
2400 be used to move the input or output pipe of the co-process
2402 Use \f5exec\ 3>&\ p\fP to move the input of the co-process
2405 can direct the output of any command to the co-process
2407 Also, by moving the input of the co-process to a numbered descriptor,
2409 The output of both co-processes will be the file descriptor
2411 You can use \f5exec\ 4<&\ p\fP to cause the output of these
2412 co-processes to go to file descriptor \fB4\fP of the shell.
2413 Once you have moved the pipe to descriptor \fB4\fP, it is possible
2414 to connect a server to the co-process by running \fIcommand\fP\f5\ 4<&\ p\fP
2415 or to close the co-process pipe with \f5exec\ 4<&\ -\fP.
2418 Function definitions are of the form
2434 The portion of the name after the last \fB\s+2.\s-2\fP
2435 is the name of the discipline.
2438 assignments and unsetting of the variable
2439 defined by the portion of the name before the last \fB\s+2.\s-2\fP.
2442 The portion of the name before the last \fB\s+2.\s-2\fP
2443 must refer to the name of an existing variable.
2445 the function name \f5p.get\fP and \f5PATH.get\fP
2446 refer to the same function.
2451 as the command name
2453 or by using it as an option to the \fB\s+2.\s-2\fP
2457 The arguments that follow the function name on the calling
2458 line become positional parameters inside the function.
2460 built-in can be used to cause the function to return to
2461 the statement following
2462 the point of invocation.
2464 Functions can also be defined with the System V notation,
2478 Functions defined with this syntax cannot be used as the first
2484 Functions defined with the \f5function\fP\ \fIname\fP syntax
2486 are executed in the current shell environment
2487 and can share named variables with the calling program.
2490 set by the calling program are
2494 the function so that any options set within a function are
2495 restored when the function exits.
2496 Traps ignored by the caller are ignored within the function
2498 Traps caught by the calling program are reset to their
2499 default action within the function.
2500 In most instances, the default action is
2501 to cause the function to terminate.
2504 defined within a function executes after the function
2506 before the caller resumes.
2510 after the caller resumes.
2512 By default, variables are inherited by the function and shared
2513 by the calling program.
2515 for functions defined with the \f5function\fP\ \fIname\fP syntax
2517 environment substitutions preceding the function call
2518 apply only to the scope of the function call.
2520 that are defined with the \f5typeset\fP
2521 built-in command are local to the function that they are declared in.
2522 Thus, for the function defined
2539 are local variables with respect to the function
2545 Functions defined with the \fIname\fP\f5()\fP syntax,
2546 and functions invoked as an argument to the \fB\s+2.\s-2\fP
2548 share everything other than positional parameters with the caller.
2549 Assignments that precede the call remain in effect after the
2559 the command name.
2562 is found, the complete file is read and all functions
2569 To write a replacement function that invokes the command that
2571 you can use the \f5command\fP built-in command.
2572 The arguments to \f5command\fP are the name and arguments
2573 of the program you want to execute.
2576 function which changes the directory and prints out the directory name,
2599 it runs the
2601 command on the script containing the function,
2602 and then executes the function.
2605 function definitions may also be placed in the
2609 causes the shell to take longer to begin executing.
2613 on versions of the UNIX operating system which support the
2616 Each command argument of the form
2622 asynchronously connected to some file in the
2625 The name of this file will become the argument to the command.
2626 If the form with
2633 then the file passed as an argument will contain the output of the
2647 the files
2652 places the
2655 to the processes
2659 as well as putting it onto the standard output.
2660 Note that the file which is passed as an argument to the command is
2663 so that the programs that expect to
2665 on the file will not work.
2674 are an integral part of the shell language itself
2675 and typically define the control flow of the language.
2677 the language but are \fIspecial\fP built-ins.
2679 part of the language rather than user definable commands.
2682 Because they are not reserved words, they can be the
2684 These commands have the following special properties:
2687 Assignments that precede them apply to the current shell process,
2688 not just to the given command.
2690 An error in the format of these commands cause a shell script
2697 on the current environment that would be nearly impossible
2706 it will be unaffected by the setting of the
2717 to create a separate process to run the command.
2722 the following order:
2725 Reserved words define commands that form part of the shell
2729 Alias substitutions occur first as part of the reading of commands.
2730 Using quotes in the command name will prevent alias substitutions.
2739 If the command name contains a
2741 the program or script corresponding to the given name is executed.
2743 A path search locates the pathname corresponding to the command.
2744 If the pathname where it is found matches the pathname associated
2745 with a built-in command, the built-in command is executed.
2746 If the directory where the command is found is listed in the
2748 variable, the file is read into the shell
2752 the next time the command name is used.
2754 causes \f5ksh\fP to forget the location of all command names.
2761 The first argument of the \f5command\fP built-in, described earlier,
2762 skips the checks for reserved words and for function definitions.
2765 As a result, if the first argument of \f5command\fP is
2766 a special built-in, the special properties of this built-in
2769 it to abort if the open fails, \f5command\ exec\ 3<\ foo\fP
2770 results in a non-zero exit status but does not abort the script.
2772 You can get a complete list of the special built-in commands
2775 the current built-ins and the pathname that they are associated with.
2777 the pathname for the built-in. The basename of this path must
2778 be the name of an existing built-in for this to succeed.
2779 Specifying the name of the built-in without a pathname causes
2781 A built-in can be deleted with the \fB\-d\fP option.
2784 can be added with the \f5builtin\fP command.
2786 C function whose name is of the form \f5b_\fP\fIname\fP, where
2787 \fIname\fP is the name of the built-in that is to be added.
2788 The function has the same argument calling convention as
2789 \f5main\fP. The lower eight bits of the return value become
2790 the exit status for this built-in.
2791 Builtins are added by specifying the pathname of the library
2792 as an argument to the \fB\-f\fP option of \f5builtin\fP.
2796 when used with the
2803 If the command is none of the above,
2804 it follows the path search rules and prints the full path-name,
2809 for built-ins that use numerical values in the Bourne shell.
2812 option of the
2817 It uses the same symbolic notation as the \f5chmod\fP command.
2820 allows the signal names to be given symbolically.
2822 corresponding to signals are the same as the signal name with
2823 the
2831 In addition to the variables discussed earlier, \f5ksh\fP
2834 produces a random number in the range 0 to 32767 each time it is referenced.
2835 Assignment to this variable sets the seed for the
2839 is used to generate the process id of the process which invoked this shell.
2844 This trap is invoked whenever the shell would exit if the
2852 Proceedings of the Portland USENIX meeting, pp. 159-174, 1985.
2867 use the
2869 option to enable the execution trace.
2871 the expansions have been performed,
2873 the trace writes to standard error the name and arguments
2876 While the trace is very useful, there is no way
2881 the
2886 instead of the
2891 variable is set to the current line number relative to the
2892 beginning of the current script or function.
2893 It is most useful as part of the
2909 Finding the time it takes to execute commands
2910 has been a serious problem with the Bourne shell.
2911 Since the \f5time\fP command is not part of the
2914 The extra time in invoking the shell and processing
2915 the script is accumulated along with the time
2916 to execute the script.
2918 More seriously, the Bourne shell does not give correct
2920 The reason for this is that the times for some members
2921 of a pipeline are not counted when computing the time.
2923 running \f5time\fP on the script
2926 with the Bourne shell will show very little
2933 the \f5time\fP
2936 to obtain information about the elapsed, user, and system times.
2937 Since I/O redirections bind to the command, not to
2939 parentheses should be used to redirect the timing information which
2942 There are several documented problems associated with the security of
2949 These security holes occur primarily because a user can manipulate the
2951 to subvert the intent of a
2955 binary programs, without the author's
2958 When the binary program is run
2960 then the shell procedure runs with the permissions afforded to the
2961 owner of the binary file.
2963 In the Bourne shell,
2964 the
2973 then the user sets and exports
2977 the shell will run
2983 program into the current directory.
2985 create a copy of the shell,
2988 and then run the \f5/bin/pwd\fP
2989 program so that the original program continues to run successfully.
2992 since the
3001 without giving the full pathname.
3002 If the
3003 user sets the
3005 variable so that the desired command will be found
3006 in his or her local bin, then the same technique described above can
3007 be employed to compromise the security of the system.
3010 resets the effective user id to the real user id and the effective
3011 group id to the real group id unless the
3017 this mode, the
3019 mode, the
3024 Instead, the file
3027 This gives an administrator control over the
3028 environment to set the
3031 Clearly security of the system is compromised if
3035 Some versions of the UNIX operating system look for the characters
3037 as the first two characters of an executable file.
3038 If these characters are found, then the next word on this line is taken
3039 as the interpreter to
3041 for this command and the interpreter is
3043 with the name of the script as argument zero and argument one.
3044 If the
3048 bits are on for this file, then the interpreter
3049 is run with the effective uid and/or gid set accordingly.
3052 putting the pathname of the interpreter into the script
3053 makes the script less portable since the interpreter
3055 Secondly, using the
3059 of the interpreter even when the call is invoked from the interpreter
3074 the interpreter is fooled into thinking that it is being invoked with
3075 a command line option rather than the name of a file.
3076 When the interpreter is the shell, the user gets a privileged
3088 The technique does not require any changes to the operating system
3096 program to authenticate the
3097 request and exec the shell with the correct mode bits to carry out
3098 the task. This shell is invoked with the requested file already open
3103 For security reasons, this program is given the full
3106 A description of the implementation of the
3118 The code uses the IEEE POSIX 1003.1 and ISO 9945-1 standard\*(Rf
3127 Unlike earlier version of the Bourne shell,
3129 without stripping off the
3135 commands at run time with the built-in command \f5builtin\fP
3142 in the Appendix.
3143 This one page program is a variant of the UNIX system
3148 The first half uses the \f5getopts\fP command to
3149 find the option flags.
3158 illustrate the programming power of \f5ksh\fP.
3163 the speed of \f5grep\fP
3167 \f5ksh\fP executes many scripts faster than the System V Bourne shell;
3178 Another reason for improved performance is the use of the \fBsfio\fP\*(Rf,
3182 Proceedings of the Summer Usenix,
3193 Several of the internal algorithms have been changed
3194 so that the number of subroutine calls has been
3198 More processing is performed while reading the script
3202 but they reduce the time that it takes to interpret commands by
3207 The arithmetic provided by the shell eliminates the need for the
3209 The pattern matching and substring capabilities eliminate the
3213 built-ins without changing the semantics at all.
3215 applications to be sped up by supplying the critical
3229 and is a suitable replacement for the Bourne shell.
3231 both the 1988 version of \f5ksh\fP and with the recent IEEE POSIX