diff options
Diffstat (limited to 'bin/ksh/sh.1tbl')
-rw-r--r-- | bin/ksh/sh.1tbl | 300 |
1 files changed, 196 insertions, 104 deletions
diff --git a/bin/ksh/sh.1tbl b/bin/ksh/sh.1tbl index c0f5b8efae9..e13435e1792 100644 --- a/bin/ksh/sh.1tbl +++ b/bin/ksh/sh.1tbl @@ -1,4 +1,4 @@ -.\" $OpenBSD: sh.1tbl,v 1.12 1999/06/03 09:50:32 aaron Exp $ +.\" $OpenBSD: sh.1tbl,v 1.13 1999/06/14 03:13:59 pjanzen Exp $ .\" .\" Copyright (c) 1980, 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -78,14 +78,14 @@ If neither the .Fl c nor the .Fl s -options are specified, the first non-option argument specifies the name +option is specified, the first non-option argument specifies the name of a file the shell reads commands from. If there are no non-option arguments, the shell reads commands from the standard input. The name of the shell (i.e., the contents of $0) is determined as follows: if the .Fl c option is used and there is a non-option argument, it is used as the name; if commands are being read from a file, the file is used as the name; -otherwise the name the shell was called with (i.e., argv[0]) is used. +otherwise, the name the shell was called with (i.e., argv[0]) is used. .Pp A shell is .Dq interactive @@ -94,10 +94,10 @@ if the option is used or if both standard input and standard error are attached to a tty. An interactive shell has job control enabled (if available), ignores the -.Dv INT , -.Dv QUIT , +.Dv SIGINT , +.Dv SIGQUIT , and -.Dv TERM +.Dv SIGTERM signals, and prints prompts before reading input (see .Ev PS1 and @@ -225,7 +225,7 @@ and .Ql \&) .Pc . Aside from delimiting words, spaces and tabs are ignored, while newlines -usually delimit commands. The meta-charcters are used in building the +usually delimit commands. The meta-characters are used in building the following tokens: .Ql < , .Ql <& , @@ -284,7 +284,7 @@ the .Ql # up to the nearest newline is ignored; .Ql $ -is used to introduce parameter, command and arithmetic substitutions (see +is used to introduce parameter, command, and arithmetic substitutions (see .Sx Substitution below); .Ql ` @@ -400,9 +400,9 @@ does keep track of the status of asynchronous commands, see .Sx Job control below). When an asynchronous command is started when job control is disabled (i.e., in most scripts), the command is started with signals -.Dv INT +.Dv SIGINT and -.Dv QUIT +.Dv SIGQUIT ignored and with input redirected from .Pa /dev/null (however, redirections specified in the asynchronous command have precedence). @@ -442,7 +442,7 @@ control structure. .Pp In the following compound command descriptions, command lists (denoted as .Em list ) -that are followed by reserved words must end with a semi-colon, a newline or +that are followed by reserved words must end with a semicolon, a newline, or a (syntactically correct) reserved word. For example, .Pp .Bl -inset -indent -compact @@ -497,7 +497,7 @@ and .Ql / are dropped. Note that any unquoted space before and after a pattern is stripped; any space with a pattern must be quoted. Both the word and the -patterns are subject to parameter, command and arithmetic substitution as +patterns are subject to parameter, command, and arithmetic substitution, as well as tilde substitution. For historical reasons, open and close braces may be used instead of .Ic in @@ -525,7 +525,7 @@ is set to the word and is executed. If .Ic in is not used to specify a word list, the positional parameters ($1, $2, etc.) -are used instead. For historical reasons, open and clase braces may be used +are used instead. For historical reasons, open and close braces may be used instead of .Ic do and @@ -551,7 +551,7 @@ If the exit status of the first .Ar list is zero, the second .Ar list -is executed; otherwise the +is executed; otherwise, the .Ar list following the .Ic elif , @@ -700,7 +700,7 @@ and .Ss Substitution The first step the shell takes in executing a simple-command is to perform substitutions on the words of the command. There are three kinds of -substitution: parameter, command and arithmetic. Parameter substitutions, +substitution: parameter, command, and arithmetic. Parameter substitutions, which are described in detail in the next section, take the form .Ic $name or @@ -719,7 +719,7 @@ the current value of the parameter. The .Ev IFS parameter specifies a list of characters which are used to break a string up -into several words; any characters from the set space, tab and newline that +into several words; any characters from the set space, tab, and newline that appear in the .Ev IFS characters are called @@ -729,7 +729,7 @@ Sequences of one or more whitespace characters, in combination with zero or no .Pf non- Ev IFS whitespace -characters delimit a field. As a special case, leading and trailing +characters, delimit a field. As a special case, leading and trailing .Ev IFS whitespace is stripped (i.e., no leading or trailing empty field is created by it); leading or trailing @@ -753,10 +753,10 @@ Note that if the parameter is set to the .Dv NULL string, no field splitting is done; if the parameter is unset, the default -value of space, tab and newline is used. +value of space, tab, and newline is used. .Pp Also, note that the field splitting applies only to the immediate result of -the substituion. Using the previous example, the substitution for $VAR:E +the substitution. Using the previous example, the substitution for $VAR:E results in the fields: .Dq A , .Dq B , @@ -771,7 +771,7 @@ and .Dq E . This behavior is POSIX compliant, but incompatible with some other shell implementations which do field splitting on the word which contained the -substituion or use +substitution or use .Dv IFS as a general whitespace delimiter. .Pp @@ -783,7 +783,7 @@ command, which is run in a subshell. For .Ic $( Ns Ar command Ns Ic ) substitutions, normal quoting rules are used when .Ar command -is parsed, however, for the +is parsed; however, for the .Ic ` Ns Ar command Ns Ic ` form, a .Ql \e @@ -808,7 +808,7 @@ but it is carried out more efficiently because no process is started). .Sy Note: .Ic $( Ns Ar command Ns Ic \&) expressions are currently parsed by finding the matching parenthesis, -regardless of quoting. This will hopefully be fixed soon. +regardless of quoting. This should be fixed soon. .Pp Arithmetic substitutions are replaced by the value of the specified expression. For example, the command @@ -910,7 +910,7 @@ If .Ar name is set and not .Dv NULL , -it is substituted, otherwise +it is substituted; otherwise, .Ar word is substituted. .It Xo Ic ${ Ns Ar name Ns @@ -921,7 +921,7 @@ If is set and not .Dv NULL , .Ar word -is substituted, otherwise nothing is substituted. +is substituted; otherwise, nothing is substituted. .It Xo Ic ${ Ns Ar name Ns .Ic \&:\&= Ns Ar word Ns Ic \&} .Xc @@ -929,7 +929,7 @@ If .Ar name is set and not .Dv NULL , -it is substituted, otherwise it is assigned +it is substituted; otherwise, it is assigned .Ar word and the resulting value of .Ar name @@ -941,7 +941,7 @@ If .Ar name is set and not .Dv NULL , -it is substituted, otherwise +it is substituted; otherwise, .Ar word is printed on standard error (preceded by .Ar name Ns No \&: ) @@ -953,7 +953,7 @@ is used instead. .Pp In the above modifiers, the .Ql \&: -can be omitted, in which case the conditions only depand on +can be omitted, in which case the conditions only depend on .Ar name being set (as opposed to set and not .Dv NULL ) . @@ -991,8 +991,8 @@ matches the beginning of the value of parameter .Ar name , the matched text is deleted from the result of substitution. A single .Ql # -results in the shortest match, two -of them results in the longest match. +results in the shortest match, and two +of them result in the longest match. .Sm off .It Xo .Ic ${ Ar name Ic \&% Ar pattern Ic \&},\ \& @@ -1013,7 +1013,9 @@ have been started, the parameter is not set. .It Ev \&# The number of positional parameters (i.e., $1, $2, etc.). .It Ev \&$ -The process ID of the shell, or the PID of the original shell if it is a +The process ID of the shell, or the +.Tn PID +of the original shell if it is a subshell. .It Ev \&- The concatenation of the current single letter options (see @@ -1180,7 +1182,7 @@ below. .It Ev PPID The process ID of the shell's parent (read-only). .It Ev PS1 -The prompt is printed verbatim (i.e., no substituions are done). +The prompt is printed verbatim (i.e., no substitutions are done). Default is .Dq \&$\ \& for non-root users, @@ -1319,14 +1321,16 @@ option is set, any directories that result from file name generation are marked with a trailing .Ql / . .Pp -The POSIX character classes (i.e., +The +.Tn POSIX +character classes (i.e., .Ic \&[\&: Ns Ar class-name Ns Ic \&:\&] inside a .Ic \&[ Ns No .. Ns Ic \&] expression) are not yet implemented. .Ss Input/output redirection -When a command is executed, its standard input, standard output and standard -error (file descriptors 0, 1 and 2, respectively) are normally inherited from +When a command is executed, its standard input, standard output, and standard +error (file descriptors 0, 1, and 2, respectively) are normally inherited from the shell. Three exceptions to this are commands in pipelines, for which standard input and/or standard output are those set up by the pipeline, asynchronous commands created when job control is disabled, for which standard @@ -1341,7 +1345,7 @@ If .Ar file does not exist, it is created; if it does exist, is a regular file and the .Ic noclobber -option is set, an error occurs, otherwise the file is truncated. Note that this +option is set, an error occurs; otherwise, the file is truncated. Note that this means the command .Ic cmd < foo > foo will open @@ -1375,7 +1379,7 @@ except the file is opened for reading and writing. .It Ic \&<\&< Ar marker After reading the command line containing this kind of redirection (called a .Dq here document ) , -the shell copies lines from the command source into a termpoary file until a +the shell copies lines from the command source into a temporary file until a line matching .Ar marker is read. When the command is executed, standard input is redirected from the @@ -1383,7 +1387,7 @@ temporary file. If .Ar marker contains no quoted characters, the contents of the temporary file are processed as if enclosed in double quotes each time the command is executed, so -parameter, command and arithmetic substitutions are performed, along with +parameter, command, and arithmetic substitutions are performed, along with backslash .Pq Sq \e escapes for @@ -1417,8 +1421,8 @@ except the operation is done on standard output. .Pp In any of the above redirections, the file descriptor that is redirected (i.e., standard input or standard output) can be explicitly given by preceding the -redirection with a single digit. Parameter, command and arithmetic -substitutions, tilde substitutions and (if the shell is interative) +redirection with a single digit. Parameter, command, and arithmetic +substitutions, tilde substitutions, and (if the shell is interactive) file name generation are all performed on the .Ar file , .Ar marker @@ -1429,8 +1433,8 @@ generation are only used if a single file is matched; if multiple files match, the word with the expanded file name generation characters is used. Note that in restricted shells, redirections which can create files cannot be used. .Pp -For simple-commands, redirections may appear anywhere in the command, for -compund-commands +For simple-commands, redirections may appear anywhere in the command; for +compound-commands .Po .Ic if statements, etc. @@ -1522,9 +1526,12 @@ Result is the argument (included for completeness). .It unary Ic \&- Negation. .It Ic \&! -Logical NOT; the result is 1 if argument is zero, 0 if not. +Logical +.Tn NOT ; +the result is 1 if argument is zero, 0 if not. .It Ic \&~ -Arithmetic (bit-wise) NOT. +Arithmetic (bit-wise) +.Tn NOT . .It Ic \&+\&+ Increment; must be applied to a parameter (not a literal or other expression). The parameter is incremented by 1. When used as a prefix operator, the result @@ -1555,17 +1562,25 @@ is the same as .Ao Ar expr Ac .Ic \&) . .It Ic \&|\&| -Logical OR; the result is 1 if either argument is non-zero, 0 if not. The right +Logical +.Tn OR ; +the result is 1 if either argument is non-zero, 0 if not. The right argument is evaluated only if the left argument is zero. .It Ic \&&\&& -Logical AND; the result is 1 if both arguments are non-zero, 0 if not. The +Logical +.Tn AND ; +the result is 1 if both arguments are non-zero, 0 if not. The right argument is evaluated only if the left argument is non-zero. .It Ic \&| -Arithmetic (bit-wise) OR. +Arithmetic (bit-wise) +.Tn OR . .It Ic ^ -Arithmetic (bit-wise) XOR (exclusive-OR). +Arithmetic (bit-wise) +.Tn XOR +(exclusive-OR). .It Ic \&& -Arithmetic (bit-wise) AND. +Arithmetic (bit-wise) +.Tn AND . .It Ic == Equal; the result is 1 if both arguments are equal, 0 if not. .It Ic \&!= @@ -1602,11 +1617,11 @@ syntax or the Bourne/POSIX shell .Fn name syntax (see below for the difference between the two forms). Functions are like .Li .-scripts -in that they are executed in the current environment. Howeer, unlike +in that they are executed in the current environment. However, unlike .Li .-scripts , shell arguments (i.e., positional parameters $1, $2, etc.) are never visible inside them. When the shell is determining the location of a command, functions -are searched after special built-in commands, and before regular and +are searched after special built-in commands, before regular and non-regular built-ins, and before the .Ev PATH is searched. @@ -1701,20 +1716,26 @@ returns. .El .El .Ss POSIX mode -The shell is intended to be POSIX compliant, however, in some cases, POSIX +The shell is intended to be +.Tn POSIX +compliant; however, in some cases, +.Tn POSIX behaviour is contrary either to the original Korn shell behaviour or to user convenience. How the shell behaves in these cases is determined by the state of the .Ic posix option .Pq Ic set Fl o Ic posix . -If it is on, the POSIX behaviour is followed, otherwise it is not. The +If it is on, the +.Tn POSIX +behaviour is followed; otherwise, it is not. The .Ic posix option is set automatically when the shell starts up if the environment contains the .Dv POSIXLY_CORRECT -parameter. (The shell can also be compiled so that it is in POSIX mode by -default, however this is usually not desirable). +parameter. (The shell can also be compiled so that it is in +.Tn POSIX +mode by default; however, this is usually not desirable). .Pp The following is a list of things that are affected by the state of the .Ic posix @@ -1733,22 +1754,34 @@ Occurrences of .Ic \e\&" inside double quoted .Ic `\&.\&.` -command substitutions. In POSIX mode, the +command substitutions. In +.Tn POSIX +mode, the .Ic \e\&" -is interpreted when the command is interpreted; in non-POSIX mode, the +is interpreted when the command is interpreted; in +.Pf non- Tn POSIX +mode, the backslash is stripped before the command substitution is interpreted. For example, .Ic echo \&"`echo \e\&"hi\e\&"`\&" produces .Dq \&"hi\&" -in POSIX mode, +in +.Tn POSIX +mode, .Dq hi -in non-POSIX mode. To avoid problems, use the +in +.Pf non- Tn POSIX +mode. To avoid problems, use the .Ic $(...) form of command substitution. .It .Ic kill -l -output. In POSIX mode, signal names are listed one per line; in non-POSIX mode, +output. In +.Tn POSIX +mode, signal names are listed one per line; in +.Pf non- Tn POSIX +mode, signal numbers, names and descriptions are printed in columns. In future, a new option .Po Fl v @@ -1757,43 +1790,65 @@ option will be added to distinguish the two behaviours. .It .Ic fg -exit status. In POSIX mode, the exit status is 0 if no errors occur; in -non-POSIX mode, the exit status is that of the last foregrounded job. +exit status. In +.Tn POSIX +mode, the exit status is 0 if no errors occur; in +.Pf non- Tn POSIX +mode, the exit status is that of the last foregrounded job. .It .Ic getopts . -In POSIX mode, options must start with a +In +.Tn POSIX +mode, options must start with a .Ql - ; -in non-POSIX mode, options can start with either +in +.Pf non- Tn POSIX +mode, options can start with either .Ql - or .Ql + . .It -Brace expansion (also known as alternation). In POSIX mode, brace expansion is -disabled; in non-POSIX mode, brace expansion is enabled. Note that +Brace expansion (also known as alternation). In +.Tn POSIX +mode, brace expansion is +disabled; in +.Pf non- Tn POSIX +mode, brace expansion is enabled. Note that .Ic set Fl o Ic posix (or setting the .Ev POSIXLY_CORRECT parameter) automatically turns the .Ic braceexpand -option off, however, it can be explicitly turned on later. +option off, although it can be explicitly turned on later. .It .Ic set \&- . -In POSIX mode, this does not clear the +In +.Tn POSIX +mode, this does not clear the .Ic verbose or .Ic xtrace -options; in non-POSIX mode, it does. +options; in +.Pf non- Tn POSIX +mode, it does. .It .Ic set -exit status. In POSIX mode, the exit status of +exit status. In +.Tn POSIX +mode, the exit status of .Ic set -is 0 if there are no errors; in non-POSIX mode, the exit status is that of any +is 0 if there are no errors; in +.Pf non- Tn POSIX +mode, the exit status is that of any command substitutions performed in generating the .Ic set command. For example, .Ic set \&-\&- `false`; echo $? -prints 0 in POSIX mode, 1 in non-POSIX mode. This construct is used in most -shell scripts that use the old +prints 0 in +.Tn POSIX +mode, 1 in +.Pf non- Tn POSIX +mode. This construct is used in most shell scripts that use the old .Xr getopt 1 command. .It @@ -1803,16 +1858,30 @@ Argument expansion of .Ic readonly , and .Ic typeset -commands. In POSIX mode, normal argument expansion is done; in non-POSIX mode, +commands. In +.Tn POSIX +mode, normal argument expansion is done; in +.Pf non- Tn POSIX +mode, field splitting, file globbing, brace expansion, and (normal) tilde expansion are turned off, while assignment tilde expansion is turned on. .It -Signal specification. In POSIX mode, signals can be specified as digits, only -if signal numbers match POSIX values (i.e., HUP=1, INT=2, QUIT=3, ABRT=6, -KILL=9, ALRM=14, and TERM=15); in non-POSIX mode, signals can always be digits. +Signal specification. In +.Tn POSIX +mode, signals can be specified as digits, only +if signal numbers match +.Tn POSIX +values (i.e., HUP=1, INT=2, QUIT=3, ABRT=6, +KILL=9, ALRM=14, and TERM=15); in +.Pf non- Tn POSIX +mode, signals can always be digits. .It -Alias expansion. In POSIX mode, alias expansion is only carried out when -reading command words; in non-POSIX mode, alias expansion is carried out on any +Alias expansion. In +.Tn POSIX +mode, alias expansion is only carried out when +reading command words; in +.Pf non- Tn POSIX +mode, alias expansion is carried out on any word following an alias that ended in a space. For example, the following .Ic for loop @@ -1826,16 +1895,23 @@ loop .Pp uses parameter .Ic i -in POSIX mode, +in +.Tn POSIX +mode, .Ic j -in non-POSIX mode. +in +.Pf non- Tn POSIX +mode. .It -Test. In POSIX mode, the expression +Test. In +.Tn POSIX +mode, the expression .Ql Fl t (preceded by some number of .Ql Ic \&! -arguments) is always true as it is a non-zero length string; in non-POSIX mode, -it tests if file descriptor 1 is a tty (i.e., the +arguments) is always true as it is a non-zero length string; in +.Pf non- Tn POSIX +mode, it tests if file descriptor 1 is a tty (i.e., the .Ar fd argument to the .Fl t @@ -1843,8 +1919,8 @@ test may be left out and defaults to 1). .El .Ss Command execution After evaluation of command-line arguments, redirections and parameter -assignments, the type of command is determined; a special built-in, a function, -a regular built-in, or the name of a file to execute found using the +assignments, the type of command is determined: a special built-in, a +function, a regular built-in, or the name of a file to execute found using the .Ev PATH parameter. The checks are made in the above order. Special built-in commands differ from other commands in that the @@ -1863,7 +1939,9 @@ different only in that the .Ev PATH parameter is not used to find them. .Pp -The original ksh and POSIX differ somewhat in which commands are considered +The original ksh and +.Tn POSIX +differ somewhat in which commands are considered special or regular: .Pp POSIX special commands @@ -1894,7 +1972,9 @@ Additional ksh regular commands .Ic pwd , test , ulimit , whence .Pp In the future, the additional ksh special and regular commands may be treated -differently from the POSIX special and regular commands. +differently from the +.Tn POSIX +special and regular commands. .Pp Once the type of the command has been determined, any command-line parameter assignments are performed and exported for the duration of the command. @@ -2054,7 +2134,7 @@ directory. .Ar cmd Op Ar arg1 ... .Xc .Ar cmd -is executed exactly as if the +is executed exactly as if .Ic command had not been specified, with two exceptions. First, .Ar cmd @@ -2064,8 +2144,8 @@ exit, and command assignments are not permanent). If the .Fl p option is given, a default search path is used instead of the current value of .Ev PATH -(the actual value of the default path is system dependent; on POSIXish systems, -it is the value returned by +(the actual value of the default path is system dependent: on POSIXish +systems, it is the value returned by .Ic getconf CS_PATH ) . .It Ic continue Op Ar level Jumps to the beginning of the @@ -2106,7 +2186,8 @@ string which the shell then parses and executes in the current environment. .Xc The command is executed without forking, replacing the shell process. .Pp -If no arguments are given, and I/O redirection is permanent and the shell is +If no command is given except for I/O redirection, the I/O redirection is +permanent and the shell is not replaced. Any file descriptors which are opened or .Xr dup 2 Ns No 'd in this way are made available to other executed commands (note that the Korn @@ -2164,10 +2245,10 @@ parameters, if no arguments are given) and to check for legal options. contains the option letters that .Ic getopts is to recognize. If a letter is followed by a colon, the option is expected to -ahve an argument. Options that do not take arguments may be grouped in a single +have an argument. Options that do not take arguments may be grouped in a single argument. If an option takes an argument and the option character is not the last character of the argument it is found in, the remainder of the argument is -taken to be the option's argument, otherwise, the next argument is the option's +taken to be the option's argument; otherwise, the next argument is the option's argument. .Pp Each time @@ -2262,7 +2343,7 @@ a short description of them are printed. .Li | Fl R No [-en] Oc [argument\ ...] .Xc .Ic print -prints its arguments on the standard output, separated by spaces, and +prints its arguments on the standard output, separated by spaces and terminated with a newline. The .Fl n option suppresses the newline. By default, certain C escapes are translated. @@ -2569,7 +2650,9 @@ and .Ic pwd commands above for more details. .It Ic posix -Enable POSIX mode. See +Enable +.Tn POSIX +mode. See .Sx POSIX mode above. .It Ic vi @@ -2630,7 +2713,7 @@ defaults to 1. .Ic test evaluates the .Ar expression -and returns zero status if true, 1 status if fase, and greater than 1 if there +and returns zero status if true, 1 status if false, or greater than 1 if there was an error. It is normally used as the condition command of .Ic if and @@ -2694,7 +2777,7 @@ mode has sticky bit set. is not empty. .It Fl O Ar file .Ar file Ns 's -owned is the shell's effective user ID. +owner is the shell's effective user ID. .It Fl G Ar file .Ar file Ns 's group is the shell's effective group ID. @@ -2749,7 +2832,9 @@ is a tty device. If the option is not set, .Ar fd may be left out, in which case it is taken to be 1 (the behaviour differs due -to the special POSIX rules described below). +to the special +.Tn POSIX +rules described below). .It Ar string .Ar string is not empty. @@ -2783,11 +2868,14 @@ increasing order of precedence): .Pp .Bl -tag -width "expr -o expr" -compact .It Ar expr Fl o Ar expr -Logical OR. +Logical +.Tn OR . .It Ar expr Fl a Ar expr -Logical AND. +Logical +.Tn AND . .It Ic \&! Ar expr -Logical NOT. +Logical +.Tn NOT . .It Ic \&( Ar expr Ic \&) Grouping. .El @@ -2804,7 +2892,9 @@ test). For example, .Ic \&[ -w /dev/fd/2 \&] tests if file descriptor 2 is writable. .Pp -Note that some special rules are applied (courtesy of POSIX) if the number of +Note that some special rules are applied (courtesy of +.Tn POSIX ) +if the number of arguments to .Ic test or @@ -3097,7 +3187,7 @@ Display or set the file permission creation mask, or umask (see .Xr umask 2 ) . If the .Fl S -option is used, the mask displayed or set is symbolic, otherwise it is an +option is used, the mask displayed or set is symbolic; otherwise, it is an octal number. .Pp Symbolic masks are like those used by @@ -3377,7 +3467,9 @@ features whose syntax or semantics are incompatible with a traditional Bourne shell disabled. Since this leaves some .Nm ksh extensions exposed, caution should be used where backwards compatibility with -traditional Bourne or POSIX compliant shells is an issue. +traditional Bourne or +.Tn POSIX +compliant shells is an issue. .Sh BUGS Any bugs in .Nm pdksh |