3 .\"{{{ Notes about man page
4 .\" - use the pseudo-macros .sh( and .sh) to begin and end sh-specific
5 .\" text and .ksh( and .ksh) for ksh specific text.
6 .\" - put i.e., e.g. and etc. in italics
9 .\" todo: Things not covered that should be:
10 .\" - distinguish (POSIX) special built-in's, (POSIX) regular built-in's,
11 .\" and sh/ksh weirdo built-in's (put S,R,X superscripts after command
12 .\" name in built-in commands section?)
13 .\" - need to be consistent about notation for `See section-name', `
14 .\" See description of foobar command', `See section section-name', etc.
15 .\" - need to use the term `external command' meaning `a command that is
16 .\" executed using execve(2)' (as opposed to a built-in command or
17 .\" function) for more clear description.
21 .TH KSH 1 "August 19, 1996" "" "User commands"
24 .TH SH 1 "August 19, 1996" "" "User commands"
30 ksh \- Public domain Korn shell
33 sh \- Public domain Bourne shell
45 [\fB\(+-abCefhikmnprsuvxX\fP] [\fB\(+-o\fP \fIoption\fP] [ [ \fB\-c\fP \fIcommand-string\fP [\fIcommand-name\fP] | \fB\-s\fP | \fIfile\fP ] [\fIargument\fP ...] ]
51 \fBksh\fP is a command interpreter that is intended for both
52 interactive and shell script use. Its command language is a superset
53 of the \fIsh\fP(1) shell language.
56 \fBsh\fP is a reimplementation of the Bourne shell, a command
57 interpreter for both interactive and script use.
61 The following options can be specified only on the command line:
62 .IP "\fB\-c\fP \fIcommand-string\fP"
63 the shell executes the command(s) contained in \fIcommand-string\fP
65 interactive mode \(em see below
67 login shell \(em see below
68 interactive mode \(em see below
70 the shell reads commands from standard input; all non-option arguments
71 are positional parameters
73 restricted mode \(em see below
75 In addition to the above, the options described in the \fBset\fP built-in
76 command can also be used on the command line.
78 If neither the \fB\-c\fP nor the \fB\-s\fP options are specified, the
79 first non-option argument specifies the name of a file the shell reads
80 commands from; if there are no non-option arguments, the shell reads
81 commands from standard input.
82 The name of the shell (\fIi.e.\fP, the contents of the \fB$0\fP) parameter
83 is determined as follows: if the \fB\-c\fP option is used and there is
84 a non-option argument, it is used as the name; if commands are being
85 read from a file, the file is used as the name; otherwise the name
86 the shell was called with (\fIi.e.\fP, argv[0]) is used.
88 A shell is \fBinteractive\fP if the \fB\-i\fP option is used or
89 if both standard input and standard error are attached to a tty.
90 An interactive shell has job control enabled (if available),
91 ignores the INT, QUIT and TERM signals, and prints prompts before
92 reading input (see \fBPS1\fP and \fBPS2\fP parameters).
93 For non-interactive shells, the \fBtrackall\fP option is on by default
94 (see \fBset\fP command below).
96 A shell is \fBrestricted\fP if the \fB\-r\fP option is used or if either
97 the basename of the name the shell is invoked with or the \fBSHELL\fP
98 parameter match the pattern *r*sh (\fIe.g.\fP, rsh, rksh, rpdksh, \fIetc.\fP).
99 The following restrictions come into effect after the shell processes
100 any profile and \fB$ENV\fP files:
104 the \fBcd\fP command is disabled
106 the \fBSHELL\fP, \fBENV\fP and \fBPATH\fP parameters can't be changed
108 command names can't be specified with absolute or relative paths
110 the \fB\-p\fP option of the \fBcommand\fP built-in can't be used
112 redirections that create files can't be used (\fIi.e.\fP, \fB>\fP,
113 \fB>|\fP, \fB>>\fP, \fB<>\fP)
116 A shell is \fBprivileged\fP if the \fB\-p\fP option is used or if
117 the real user-id or group-id does not match the effective user-id
118 or group-id (see \fIgetuid\fP(2), \fIgetgid\fP(2)).
119 A privileged shell does not process $HOME/.profile nor the \fBENV\fP
120 parameter (see below), instead the file /etc/suid_profile is processed.
121 Clearing the privileged option causes the shell to set its effective
122 user-id (group-id) to its real user-id (group-id).
124 If the basename of the name the shell is called with (\fIi.e.\fP, argv[0])
125 starts with \fB\-\fP or if the \fB\-l\fP option is used, the shell is assumed
126 to be a login shell and the shell reads and executes the contents of
127 \fB/etc/profile\fP and \fB$HOME/.profile\fP if they exist and are readable.
129 If the \fBENV\fP parameter is set when the shell starts (or, in the
130 case of login shells, after any profiles are processed), its value
131 is subjected to parameter, command, arithmetic and tilde substitution and
132 the resulting file (if any) is read and executed.
133 If \fBENV\fP parameter is not set (and not null) and pdksh was compiled
134 with the \fBDEFAULT_ENV\fP macro defined, the file named in that macro
135 is included (after the above mentioned substitutions have been performed).
137 The exit status of the shell is 127 if the command file specified
138 on the command line could not be opened, or non-zero if a fatal syntax
139 error occurred during the execution of a script.
140 In the absence of fatal errors, the exit status is that of the last
141 command executed, or zero, if no command is executed.
143 .\"{{{ Command Syntax
145 .\"{{{ words and tokens
146 The shell begins parsing its input by breaking it into \fIword\fPs.
147 Words, which are sequences of characters, are delimited by unquoted
148 \fIwhite-space\fP characters (space, tab and newline) or \fImeta-characters\fP
149 (\fB<\fP, \fB>\fP, \fB|\fP, \fB;\fP, \fB&\fP, \fB(\fP and \fB)\fP).
150 Aside from delimiting words, spaces and tabs are ignored, while
151 newlines usually delimit commands.
152 The meta-characters are used in building the following tokens:
153 \fB<\fP, \fB<&\fP, \fB<<\fP, \fB>\fP, \fB>&\fP, \fB>>\fP, \fIetc.\fP are
154 used to specify redirections (see Input/Output Redirection below);
155 \fB|\fP is used to create pipelines;
157 \fB|&\fP is used to create co-processes (see Co-Processes below);
159 \fB;\fP is used to separate commands;
160 \fB&\fP is used to create asynchronous pipelines;
161 \fB&&\fP and \fB||\fP are used to specify conditional execution;
162 \fB;;\fP is used in \fBcase\fP statements;
164 \fB((\fP .. \fB))\fP are used in arithmetic expressions;
167 \fB(\fP .. \fB)\fP are used to create subshells.
169 White-space and meta-characters can be quoted individually using
170 backslash (\fB\e\fP), or in groups using double (\fB"\fP) or single (\fB'\fP)
172 Note that the following characters are also treated specially by the shell and
173 must be quoted if they are to represent themselves:
174 \fB\e\fP, \fB"\fP, \fB'\fP, \fB#\fP, \fB$\fP, \fB`\fP, \fB~\fP, \fB{\fP,
175 \fB}\fP, \fB*\fP, \fB?\fP and \fB[\fP.
176 The first three of these are the above mentioned quoting characters
178 \fB#\fP, if used at the beginning of a word, introduces a comment \(em everything
179 after the \fB#\fP up to the nearest newline is ignored;
180 \fB$\fP is used to introduce parameter, command and arithmetic substitutions
181 (see Substitution below);
182 \fB`\fP introduces an old-style command substitution
183 (see Substitution below);
184 \fB~\fP begins a directory expansion (see Tilde Expansion below);
185 \fB{\fP and \fB}\fP delimit \fIcsh\fP(1) style alternations
186 (see Brace Expansion below);
187 and, finally, \fB*\fP, \fB?\fP and \fB[\fP are used in file name generation
188 (see File Name Patterns below).
190 .\"{{{ simple-command
192 As words and tokens are parsed, the shell builds commands, of which
193 there are two basic types: \fIsimple-commands\fP, typically programs
194 that are executed, and \fIcompound-commands\fP, such as \fBfor\fP and
195 \fBif\fP statements, grouping constructs and function definitions.
197 A simple-command consists of some combination of parameter assignments (see
198 Parameters below), input/output redirections (see Input/Output Redirections
199 below), and command words; the only restriction is that parameter assignments
200 come before any command words.
201 The command words, if any, define the command that is to be executed and its
203 The command may be a shell built-in command, a function or an \fIexternal
204 command\fP, \fIi.e.\fP, a separate executable file that is located using the
205 \fBPATH\fP parameter (see Command Execution below).
206 Note that all command constructs have an \fIexit status\fP: for external
207 commands, this is related to the status returned by \fIwait\fP(2) (if the
208 command could not be found, the exit status is 127, if it could not be
209 executed, the exit status is 126);
210 the exit status of other command constructs (built-in commands, functions,
211 compound-commands, pipelines, lists, \fIetc.\fP) are all well defined and are
212 described where the construct is described.
213 The exit status of a command consisting only of parameter assignments is that
214 of the last command substitution performed during the parameter assignment
215 or zero if there were no command substitutions.
219 Commands can be chained together using the \fB|\fP token to
220 form \fIpipelines\fP, in which the standard output of each command but
221 the last is piped (see \fIpipe\fP(2)) to the standard input of the following
223 The exit status of a pipeline is that of its last command.
224 A pipeline may be prefixed by the \fB!\fP reserved word which
225 causes the exit status of the pipeline to be logically
226 complemented: if the original status was 0 the complemented status will
227 be 1, and if the original status was not 0, then the complemented
232 \fILists\fP of commands can be created by separating pipelines by
233 any of the following tokens: \fB&&\fP, \fB||\fP, \fB&\fP, \fB|&\fP and \fB;\fP.
234 The first two are for conditional execution: \fIcmd1\fP \fB&&\fP \fIcmd2\fP
235 executes \fIcmd2\fP only if the exit status of \fIcmd1\fP is zero;
236 \fB||\fP is the opposite \(em \fIcmd2\fP is executed only if the exit status
237 of \fIcmd1\fP is non-zero.
238 \fB&&\fP and \fB||\fP have equal precedence which is higher than that of
239 \fB&\fP, \fB|&\fP and \fB;\fP, which also have equal precedence.
240 The \fB&\fP token causes the preceding command to be executed asynchronously,
241 that is, the shell starts the command, but does not wait for it to complete
242 (the shell does keep track of the status of asynchronous commands \(em see
244 When an asynchronous command is started when job control is disabled
245 (\fIi.e.\fP, in most scripts), the command is started with signals INT
246 and QUIT ignored and with input redirected from /dev/null
247 (however, redirections specified in the asynchronous command have precedence).
249 The \fB|&\fP operator starts a \fIco-process\fP which is special kind of
250 asynchronous process (see Co-Processes below).
252 Note that a command must follow the \fB&&\fP and \fB||\fP operators, while
253 a command need not follow \fB&\fP, \fB|&\fP and \fB;\fP.
254 The exit status of a list is that of the last command executed, with the
255 exception of asynchronous lists, for which the exit status is 0.
257 .\"{{{ compound-commands
259 Compound commands are created using the following reserved words \(em these
260 words are only recognized if they are unquoted and if they are used as
261 the first word of a command (\fIi.e.\fP, they can't be preceded by parameter
262 assignments or redirections):
265 lfB lfB lfB lfB lfB .
266 case else function then !
269 elif for select while }
271 \fBNote:\fP Some shells (but not this one) execute control structure commands
272 in a subshell when one or more of their file descriptors are redirected, so
273 any environment changes inside them may fail.
274 To be portable, the \fBexec\fP statement should be used instead to redirect
275 file descriptors before the control structure.
277 In the following compound command descriptions, command lists (denoted as
278 \fIlist\fP) that are followed by reserved words must end with a
279 semi-colon, a newline or a (syntactically correct) reserved word.
282 \fB{ echo foo; echo bar; }\fP
284 \fB{ echo foo; echo bar<newline>}\fP
286 \fB{ { echo foo; echo bar; } }\fP
290 \fB{ echo foo; echo bar }\fP
294 .IP "\fB(\fP \fIlist\fP \fB)\fP"
295 Execute \fIlist\fP in a subshell. There is no implicit way to pass
296 environment changes from a subshell back to its parent.
299 .IP "\fB{\fP \fIlist\fP \fB}\fP"
300 Compound construct; \fIlist\fP is executed, but not in a subshell.
301 Note that \fB{\fP and \fB}\fP are reserved words, not meta-characters.
303 .\"{{{ case word in [ [ ( ] pattern [ | pattern ] ... ) list ;; ] ... esac
304 .IP "\fBcase\fP \fIword\fP \fBin\fP [ [\fB(\fP] \fIpattern\fP [\fB|\fP \fIpattern\fP] ... \fB)\fP \fIlist\fP \fB;;\fP ] ... \fBesac\fP"
305 The \fBcase\fP statement attempts to match \fIword\fP against the specified
306 \fIpattern\fPs; the \fIlist\fP associated with the first successfully matched
307 pattern is executed. Patterns used in \fBcase\fP statements are the same as
308 those used for file name patterns except that the restrictions regarding
309 \fB\&.\fP and \fB/\fP are dropped. Note that any unquoted space before and
310 after a pattern is stripped; any space with a pattern must be quoted. Both the
311 word and the patterns are subject to parameter, command, and arithmetic
312 substitution as well as tilde substitution.
313 For historical reasons, open and close braces may be used instead
314 of \fBin\fP and \fBesac\fP (\fIe.g.\fP, \fBcase $foo { *) echo bar; }\fP).
315 The exit status of a \fBcase\fP statement is that of the executed \fIlist\fP;
316 if no \fIlist\fP is executed, the exit status is zero.
318 .\"{{{ for name [ in word ... term ] do list done
319 .IP "\fBfor\fP \fIname\fP [ \fBin\fP \fIword\fP ... \fIterm\fP ] \fBdo\fP \fIlist\fP \fBdone\fP"
320 where \fIterm\fP is either a newline or a \fB;\fP.
321 For each \fIword\fP in the specified word list, the parameter \fIname\fP is
322 set to the word and \fIlist\fP is executed. If \fBin\fP is not used to
323 specify a word list, the positional parameters (\fB"$1"\fP, \fB"$2"\fP,
324 \fIetc.\fP) are used instead.
325 For historical reasons, open and close braces may be used instead
326 of \fBdo\fP and \fBdone\fP (\fIe.g.\fP, \fBfor i; { echo $i; }\fP).
327 The exit status of a \fBfor\fP statement is the last exit status
328 of \fIlist\fP; if \fIlist\fP is never executed, the exit status is zero.
330 .\"{{{ if list then list [ elif list then list ] ... [ else list ] fi
331 .IP "\fBif\fP \fIlist\fP \fBthen\fP \fIlist\fP [\fBelif\fP \fIlist\fP \fBthen\fP \fIlist\fP] ... [\fBelse\fP \fIlist\fP] \fBfi\fP"
332 If the exit status of the first \fIlist\fP is zero, the second \fIlist\fP
333 is executed; otherwise the \fIlist\fP following the \fBelif\fP, if any, is
334 executed with similar consequences. If all the lists following the \fBif\fP
335 and \fBelif\fPs fail (\fIi.e.\fP, exit with non-zero status), the \fIlist\fP
336 following the \fBelse\fP is executed.
337 The exit status of an \fBif\fP statement is that
338 of non-conditional \fIlist\fP that is executed; if no non-conditional
339 \fIlist\fP is executed, the exit status is zero.
341 .\"{{{ select name [ in word ... ] do list done
343 .IP "\fBselect\fP \fIname\fP [ \fBin\fP \fIword\fP ... \fIterm\fP ] \fBdo\fP \fIlist\fP \fBdone\fP"
344 where \fIterm\fP is either a newline or a \fB;\fP.
345 The \fBselect\fP statement provides an automatic method of presenting
346 the user with a menu and selecting from it.
347 An enumerated list of the specified \fIwords\fP is printed on standard
348 error, followed by a prompt (\fBPS3\fP, normally `\fB#? \fP').
349 A number corresponding to one of the enumerated words is then read
350 from standard input, \fIname\fP is set to the selected word (or is
351 unset if the selection is not valid), \fBREPLY\fP
352 is set to what was read (leading/trailing space is stripped),
353 and \fIlist\fP is executed.
354 If a blank line (\fIi.e.\fP, zero or more \fBIFS\fP characters) is entered,
355 the menu is re-printed without executing \fIlist\fP.
356 When \fIlist\fP completes, the enumerated list is printed if \fBREPLY\fP
357 is null, the prompt is printed and so on.
358 This process is continues until an end-of-file is read, an interrupt is
359 received or a break statement is executed inside the loop.
360 If \fBin\fP \fIword\fP \fB\&...\fP is omitted, the positional parameters
361 are used (\fIi.e.\fP, \fB"$1"\fP, \fB"$2"\fP, \fIetc.\fP).
362 For historical reasons, open and close braces may be used instead
363 of \fBdo\fP and \fBdone\fP (\fIe.g.\fP, \fBselect i; { echo $i; }\fP).
364 The exit status of a \fBselect\fP statement is zero if a break statement
365 is used to exit the loop, non-zero otherwise.
368 .\"{{{ until list do list done
369 .IP "\fBuntil\fP \fIlist\fP \fBdo\fP \fIlist\fP \fBdone\fP"
370 This works like \fBwhile\fP, except that the body is executed only while the
371 exit status of the first \fIlist\fP is non-zero.
373 .\"{{{ while list do list done
374 .IP "\fBwhile\fP \fIlist\fP \fBdo\fP \fIlist\fP \fBdone\fP"
375 A \fBwhile\fP is a prechecked loop. Its body is executed as often
376 as the exit status of the first \fIlist\fP is zero.
377 The exit status of a \fBwhile\fP statement is the last exit status
378 of the \fIlist\fP in the body of the loop; if the body is not executed,
379 the exit status is zero.
381 .\"{{{ function name { list }
382 .IP "\fBfunction\fP \fIname\fP \fB{\fP \fIlist\fP \fB}\fP"
383 Defines the function \fIname\fP.
385 Note that redirections specified after a function definition are
386 performed whenever the function is executed, not when the function
387 definition is executed.
389 .\"{{{ name () command
390 .IP "\fIname\fP \fB()\fP \fIcommand\fP"
391 Mostly the same as \fBfunction\fP.
394 .\"{{{ time [-p] [ pipeline ]
395 .IP "\fBtime\fP [ \fB-p\fP ] [ \fIpipeline\fP ]"
396 The \fBtime\fP reserved word is described in the Command Execution section.
398 .\"{{{ (( expression ))
400 .IP "\fB((\fP \fIexpression\fP \fB))\fP"
401 The arithmetic expression \fIexpression\fP is evaluated;
402 equivalent to \fBlet "\fP\fIexpression\fP\fB"\fP.
403 See Arithmetic Expressions and the \fBlet\fP command below.
406 .\"{{{ [[ expression ]]
408 .IP "\fB[[\fP \fIexpression\fP \fB]]\fP"
409 Similar to the \fBtest\fP and \fB[\fP \&... \fB]\fP commands (described later),
410 with the following exceptions:
415 Field splitting and file name generation are not performed on
418 The \fB\-a\fP (and) and \fB\-o\fP (or) operators are replaced with
419 \fB&&\fP and \fB||\fP, respectively.
421 Operators (\fIe.g.\fP, \fB\-f\fP, \fB=\fP, \fB!\fP, \fIetc.\fP) must be unquoted.
423 The second operand of \fB!=\fP and \fB=\fP
424 expressions are patterns (\fIe.g.\fP, the comparison in
426 \fB[[ foobar = f*r ]]\fP
429 There are two additional binary operators: \fB<\fP and \fB>\fP
430 which return true if their first string operand is less than,
431 or greater than, their second string operand, respectively.
433 The single argument form
434 of \fBtest\fP, which tests if the argument has non-zero length, is not valid
435 - explicit operators must be always be used, \fIe.g.\fP, instead of
437 \fB[\fP \fIstr\fP \fB]\fP
440 \fB[[ \-n \fP\fIstr\fP\fB ]]\fP
442 Parameter, command and arithmetic substitutions are performed as
443 expressions are evaluated and lazy expression evaluation is used for
444 the \fB&&\fP and \fB||\fP operators.
445 This means that in the statement
447 \fB[[ -r foo && $(< foo) = b*r ]]\fP
448 the \fB$(< foo)\fP is evaluated if and only if the file \fBfoo\fP exists
458 Quoting is used to prevent the shell from treating characters or words
460 There are three methods of quoting: First, \fB\e\fP quotes
461 the following character, unless it is at the end of a line, in which
462 case both the \fB\e\fP and the newline are stripped.
463 Second, a single quote (\fB'\fP) quotes everything up to the next single
464 quote (this may span lines).
465 Third, a double quote (\fB"\fP) quotes all characters,
466 except \fB$\fP, \fB`\fP and \fB\e\fP, up to the next unquoted double quote.
467 \fB$\fP and \fB`\fP inside double quotes have their usual meaning (\fIi.e.\fP,
468 parameter, command or arithmetic substitution) except no field splitting
469 is carried out on the results of double-quoted substitutions.
470 If a \fB\e\fP inside a double-quoted string is followed by \fB\e\fP, \fB$\fP,
471 \fB`\fP or \fB"\fP, it is replaced by the second character; if it is
472 followed by a newline, both the \fB\e\fP and the newline are stripped;
473 otherwise, both the \fB\e\fP and the character following are unchanged.
475 Note: see POSIX Mode below for a special rule regarding sequences
476 of the form \fB"\fP...\fB`\fP...\fB\e"\fP...\fB`\fP..\fB"\fP.
480 There are two types of aliases: normal command aliases and tracked
481 aliases. Command aliases are normally used as a short hand for a long
482 or often used command. The shell expands command aliases (\fIi.e.\fP,
483 substitutes the alias name for its value) when it reads the first word
484 of a command. An expanded alias is re-processed to check for more
485 aliases. If a command alias ends in a space or tab, the following word
486 is also checked for alias expansion. The alias expansion process stops
487 when a word that is not an alias is found, when a quoted word is found
488 or when an alias word that is currently being expanded is found.
490 The following command aliases are defined automatically by the shell:
494 autoload='typeset \-fu'
496 functions='typeset \-f'
504 integer='typeset \-i'
518 suspend='kill \-STOP $$'
525 Tracked aliases allow the shell to remember where it found a particular
526 command. The first time the shell does a path search for a command that
527 is marked as a tracked alias, it saves the full path of the command.
528 The next time the command is executed, the shell checks the saved path
529 to see that it is still valid, and if so, avoids repeating the path
530 search. Tracked aliases can be listed and created using \fBalias
531 \-t\fP. Note that changing the \fBPATH\fP parameter clears the saved
532 paths for all tracked aliases. If the \fBtrackall\fP option is set (\fIi.e.\fP,
533 \fBset \-o trackall\fP or \fBset \-h\fP), the shell tracks all
534 commands. This option is set automatically for non-interactive shells.
535 For interactive shells, only the following commands are automatically
536 tracked: \fBcat\fP, \fBcc\fP, \fBchmod\fP, \fBcp\fP, \fBdate\fP, \fBed\fP,
537 \fBemacs\fP, \fBgrep\fP, \fBls\fP, \fBmail\fP, \fBmake\fP, \fBmv\fP,
538 \fBpr\fP, \fBrm\fP, \fBsed\fP, \fBsh\fP, \fBvi\fP and \fBwho\fP.
542 The first step the shell takes in executing a simple-command is to
543 perform substitutions on the words of the command.
544 There are three kinds of substitution: parameter, command and arithmetic.
545 Parameter substitutions, which are described in detail in the next section,
546 take the form \fB$name\fP or \fB${\fP...\fB}\fP; command substitutions take
547 the form \fB$(\fP\fIcommand\fP\fB)\fP or \fB`\fP\fIcommand\fP\fB`\fP;
548 and arithmetic substitutions take the form \fB$((\fP\fIexpression\fP\fB))\fP.
550 If a substitution appears outside of double quotes, the results of the
551 substitution are generally subject to word or field splitting according to
552 the current value of the \fBIFS\fP parameter.
553 The \fBIFS\fP parameter specifies a list of characters which
554 are used to break a string up into several words;
555 any characters from the set space, tab and newline that appear in the
556 IFS characters are called \fIIFS white space\fP.
557 Sequences of one or more IFS white space characters, in combination with
558 zero or one non-IFS white space characters delimit a field.
559 As a special case, leading and trailing IFS white space is stripped (\fIi.e.\fP,
560 no leading or trailing empty field is created by it); leading or trailing
561 non-IFS white space does create an empty field.
562 Example: if \fBIFS\fP is set to `<space>:', the sequence of characters
563 `<space>A<space>:<space><space>B::D' contains four fields: `A', `B', `' and `D'.
564 Note that if the \fBIFS\fP parameter is set to the null string, no
565 field splitting is done; if the parameter is unset, the default value
566 of space, tab and newline is used.
568 The results of substitution are, unless otherwise specified, also subject
569 to brace expansion and file name expansion (see the relevant sections
572 A command substitution is replaced by the output generated by the specified
573 command, which is run in a subshell.
574 For \fB$(\fP\fIcommand\fP\fB)\fP substitutions, normal quoting rules
575 are used when \fIcommand\fP is parsed, however, for the
576 \fB`\fP\fIcommand\fP\fB`\fP form, a \fB\e\fP followed by any of
577 \fB$\fP, \fB`\fP or \fB\e\fP is stripped (a \fB\e\fP followed by any other
578 character is unchanged).
579 As a special case in command substitutions, a command of the form
580 \fB<\fP \fIfile\fP is interpreted to mean substitute the contents
581 of \fIfile\fP ($(< foo) has the same effect as $(cat foo), but it
582 is carried out more efficiently because no process is started).
584 .\"todo: fix this( $(..) parenthesis counting).
585 NOTE: \fB$(\fP\fIcommand\fP\fB)\fP expressions are currently parsed by
586 finding the matching parenthesis, regardless of quoting. This will hopefully
589 Arithmetic substitutions are replaced by the value of the specified
591 For example, the command \fBecho $((2+3*4))\fP prints 14.
592 See Arithmetic Expressions for a description of an \fIexpression\fP.
596 Parameters are shell variables; they can be assigned values and
597 their values can be accessed using a parameter substitution.
598 A parameter name is either one of the special single punctuation or digit
599 character parameters described below, or a letter followed by zero or more
600 letters or digits (`_' counts as a letter).
601 The later form can be treated as arrays by appending an array
602 index of the form: \fB[\fP\fIexpr\fP\fB]\fP where \fIexpr\fP is
603 an arithmetic expression.
604 Array indicies are currently limited to the range 0 through 1023, inclusive.
605 Parameter substitutions take the form \fB$\fP\fIname\fP,
606 \fB${\fP\fIname\fP\fB}\fP or
607 \fB${\fP\fIname\fP\fB[\fP\fIexpr\fP\fB]}\fP, where \fIname\fP is a
609 If substitution is performed on a parameter (or an array parameter element)
610 that is not set, a null
611 string is substituted unless the \fBnounset\fP option (\fBset \-o nounset\fP
612 or \fBset \-u\fP) is set, in which case an error occurs.
614 .\"{{{ parameter assignment
615 Parameters can be assigned values in a number of ways.
616 First, the shell implicitly sets some parameters like \fB#\fP, \fBPWD\fP,
617 etc.; this is the only way the special single character parameters are
619 Second, parameters are imported from the shell's environment at startup.
620 Third, parameters can be assigned values on the command line, for example,
621 `\fBFOO=bar\fP' sets the parameter FOO to bar; multiple parameter
622 assignments can be given on a single command line and they can
623 be followed by a simple-command, in which case the assignments are
624 in effect only for the duration of the command (such assignments are
625 also exported, see below for implications of this).
626 Note that both the parameter name and the \fB=\fP must be unquoted for
627 the shell to recognize a parameter assignment.
628 The fourth way of setting a parameter is with the \fBexport\fP, \fBreadonly\fP
629 and \fBtypeset\fP commands; see their descriptions in the Command Execution
631 Fifth, \fBfor\fP and \fBselect\fP loops set parameters as well as
632 the \fBgetopts\fP, \fBread\fP and \fBset \-A\fP commands.
633 Lastly, parameters can be assigned values using assignment operators
634 inside arithmetic expressions (see Arithmetic Expressions below) or
635 using the \fB${\fP\fIname\fP\fB=\fP\fIvalue\fP\fB}\fP form
636 of parameter substitution (see below).
640 Parameters with the export attribute (set using the \fBexport\fP or
641 \fBtypeset \-x\fP commands, or by parameter assignments followed by simple
642 commands) are put in the environment (see \fIenviron\fP(5)) of commands
643 run by the shell as \fIname\fP\fB=\fP\fIvalue\fP pairs.
644 The order in which parameters appear in the environment of a command
646 When the shell starts up, it extracts parameters and their values from its
647 environment and automatically sets the export attribute for those parameters.
649 .\"{{{ ${name[:][-+=?]word}
651 Modifiers can be applied to the \fB${\fP\fIname\fP\fB}\fP form of parameter
653 .IP \fB${\fP\fIname\fP\fB:-\fP\fIword\fP\fB}\fP
654 if \fIname\fP is set and not null, it is substituted, otherwise \fIword\fP is
656 .IP \fB${\fP\fIname\fP\fB:+\fP\fIword\fP\fB}\fP
657 if \fIname\fP is set and not null, \fIword\fP is substituted, otherwise nothing is substituted.
658 .IP \fB${\fP\fIname\fP\fB:=\fP\fIword\fP\fB}\fP
659 if \fIname\fP is set and not null, it is substituted, otherwise it is
660 assigned \fIword\fP and the resulting value of \fIname\fP is substituted.
661 .IP \fB${\fP\fIname\fP\fB:?\fP\fIword\fP\fB}\fP
662 if \fIname\fP is set and not null, it is substituted, otherwise \fIword\fP
663 is printed on standard error (preceded by \fIname\fP:) and an error occurs
664 (normally causing termination of a shell script, function or \&.-script).
665 If word is omitted the string `parameter null or not set' is used instead.
667 In the above modifiers, the \fB:\fP can be omitted, in which case the
668 conditions only depend on \fIname\fP being set (as opposed to set and
670 If \fIword\fP is needed, parameter, command, arithmetic and tilde substitution
671 are performed on it; if \fIword\fP is not needed, it is not evaluated.
674 The following forms of parameter substitution can also be used:
676 .IP \fB${#\fP\fIname\fP\fB}\fP
677 The number of positional parameters if \fIname\fP is \fB*\fP, \fB@\fP or
679 or the length of the string value of parameter \fIname\fP.
681 .\"{{{ ${#name[*]}, ${#name[@]}
682 .IP "\fB${#\fP\fIname\fP\fB[*]}\fP, \fB${#\fP\fIname\fP\fB[@]}\fP"
683 The number of elements in the array \fIname\fP.
685 .\"{{{ ${name#pattern}, ${name##pattern}
686 .IP "\fB${\fP\fIname\fP\fB#\fP\fIpattern\fP\fB}\fP, \fB${\fP\fIname\fP\fB##\fP\fIpattern\fP\fB}\fP"
687 If \fIpattern\fP matches the beginning of the value of parameter \fIname\fP,
688 the matched text is deleted from the result of substitution. A single
689 \fB#\fP results in the shortest match, two \fB#\fP's results in the
692 .\"{{{ ${name%pattern}, ${name%%pattern}
693 .IP "\fB${\fP\fIname\fP\fB%\fP\fIpattern\fP\fB}\fP, \fB${\fP\fIname\fP\fB%%\fP\fIpattern\fP\fB}\fP"
694 Like \fB${\fP..\fB#\fP..\fB}\fP substitution, but it deletes from the end of the
697 .\"{{{ special shell parameters
699 The following special parameters are implicitly set by the shell and cannot be
700 set directly using assignments:
703 Process id of the last background process started. If no background
704 processes have been started, the parameter is not set.
708 The number of positional parameters (\fIi.e.\fP, \fB$1\fP, \fB$2\fP,
713 The process ID of the shell, or the PID of the original shell if
718 The concatenation of the current single letter options
719 (see \fBset\fP command below for list of options).
723 The exit status of the last non-asynchronous command executed.
724 If the last command was killed by a signal, \fB$?\fP is set to 128 plus
729 The name the shell was invoked with (\fIi.e.\fP, \fBargv[0]\fP), or the
730 \fBcommand-name\fP if it was invoked with the \fB\-c\fP option and the
731 \fBcommand-name\fP was supplied, or the \fIfile\fP argument, if it was
733 If the \fBposix\fP option is not set, \fB$0\fP is the name of the current
737 .IP "\fB1\fP ... \fB9\fP"
738 The first nine positional parameters that were supplied to the shell,
739 function or \fB.\fP-script.
740 Further positional parameters may be accessed using
741 \fB${\fP\fInumber\fP\fB}\fP.
745 All positional parameters (except parameter 0),
746 \fIi.e.\fP, \fB$1 $2 $3\fP....
747 If used outside of double quotes, parameters are separate words
748 (which are subjected to word splitting); if used within double quotes,
749 parameters are separated by the first character of the \fBIFS\fP parameter
750 (or the empty string if \fBIFS\fP is null).
754 Same as \fB$*\fP, unless it is used inside double quotes, in which case
755 a separate word is generated for each positional parameter \- if there
756 are no positional parameters, no word is generated ("$@" can be used
757 to access arguments, verbatim, without loosing null arguments or
758 splitting arguments with spaces).
761 .\"{{{ general shell parameters
763 The following parameters are set and/or used by the shell:
766 .IP "\fB_\fP \fI(underscore)\fP"
767 When an external command is executed by the shell, this parameter is
768 set in the environment of the new process to the path of the executed
770 In interactive use, this parameter is also set in the parent shell to
771 the last word of the previous command.
772 When \fBMAILPATH\fP messages are evaluated, this parameter contains
773 the name of the file that changed (see \fBMAILPATH\fP parameter below).
778 Search path for the \fBcd\fP built-in command. Works the same way as
779 \fBPATH\fP for those directories not beginning with \fB/\fP in \fBcd\fP
781 Note that if CDPATH is set and does not contain \fB.\fP nor an empty path,
782 the current directory is not searched.
786 Set to the number of columns on the terminal or window.
787 Currently set to the \fBcols\fP value as reported by \fIstty\fP(1) if that
789 This parameter is used by the interactive line editing modes, and by
790 \fBselect\fP, \fBset \-o\fP and \fBkill \-l\fP commands
791 to format information in columns.
796 If the \fBVISUAL\fP parameter is not set, this parameter controls the
797 command line editing mode for interactive shells.
798 See \fBVISUAL\fP parameter below for how this works.
803 If this parameter is found to be set after any profile files are
804 executed, the expanded value is used as a shell start-up file. It
805 typically contains function and alias definitions.
809 Integer value of the shell's errno variable \(em indicates the reason
810 the last system call failed.
811 .\" todo: ERRNO variable
817 If set, this parameter is assumed to contain the shell that is to be
818 used to execute commands that \fIexecve\fP(2) fails to execute and
819 which do not start with a `\fB#!\fP \fIshell\fP' sequence.
823 The editor used by the \fBfc\fP command (see below).
827 Like \fBPATH\fP, but used when an undefined function is executed to locate
828 the file defining the function.
829 It is also searched when a command can't be found using \fBPATH\fP.
830 See Functions below for more information.
835 The name of the file used to store history.
836 When assigned to, history is loaded from the specified file.
837 Also, several invocations of the
838 shell running on the same machine will share history if their
839 \fBHISTFILE\fP parameters all point at the same file.
841 NOTE: if HISTFILE isn't set, no history file is used. This is
842 different from the original Korn shell, which uses \fB$HOME/.sh_history\fP;
843 in future, pdksh may also use a default history file.
849 The number of commands normally stored for history, default 128.
854 The default directory for the \fBcd\fP command and the value
855 substituted for an unqualified \fB~\fP (see Tilde Expansion below).
859 Internal field separator, used during substitution and by the \fBread\fP
860 command, to split values into distinct arguments; normally set to
861 space, tab and newline. See Substitution above for details.
863 \fBNote:\fP this parameter is not imported from the environment
864 when the shell is started.
868 .IP \fBKSH_VERSION\fP
869 The version of shell and the date the version was created (readonly).
870 See also the version commands in Emacs Editing Mode
871 and Vi Editing Mode sections, below.
877 The version of shell and the date the version was created (readonly).
882 The line number of the function or shell script that is currently being
887 Set to the number of lines on the terminal or window.
888 .\"Currently set to the \fBrows\fP value as reported by \fIstty\fP(1) if that
889 .\"value is non-zero.
890 .\" todo: LINES variable
897 If set, the user will be informed of the arrival of mail in the named
898 file. This parameter is ignored if the \fBMAILPATH\fP parameter is set.
904 How often, in seconds, the shell will check for mail in the file(s)
905 specified by \fBMAIL\fP or \fBMAILPATH\fP. If 0, the shell checks
906 before each prompt. The default is 600 (10 minutes).
912 A list of files to be checked for mail. The list is colon separated,
913 and each file may be followed by a \fB?\fP and a message to be printed
914 if new mail has arrived. Command, parameter and arithmetic substitution is
915 performed on the message, and, during substitution, the parameter \fB$_\fP
916 contains the name of the file.
917 The default message is \fByou have mail in $_\fP.
922 The previous working directory.
923 Unset if \fBcd\fP has not successfully changed directories since the
924 shell started, or if the shell doesn't know where it is.
928 When using \fBgetopts\fP, it contains the argument for a parsed option,
933 The index of the last argument processed when using \fBgetopts\fP.
934 Assigning 1 to this parameter causes \fBgetopts\fP to
935 process arguments from the beginning the next time it is invoked.
939 A colon separated list of directories that are searched when looking
940 for commands and \fB.\fP'd files.
941 An empty string resulting from a leading or trailing colon, or two adjacent
942 colons is treated as a `.', the current directory.
944 .\"{{{ POSIXLY_CORRECT
945 .IP \fBPOSIXLY_CORRECT\fP
946 If set, this parameter causes the \fBposix\fP option to be enabled.
947 See POSIX Mode below.
951 The process ID of the shell's parent (readonly).
955 \fBPS1\fP is the primary prompt for interactive shells.
957 Parameter, command and arithmetic substitutions are performed, and
958 \fB!\fP is replaced with the current command number (see \fBfc\fP
959 command below). A literal ! can be put in the prompt by placing !! in PS1.
960 Note that since the command line editors try to figure out how long the
961 prompt is (so they know how far it is to edge of the screen),
962 escape codes in the prompt tend to mess things up.
963 You can tell the shell not to count certain sequences (such as escape codes)
964 by prefixing your prompt with a non-printing character (such as control-A)
965 followed by a carriage return and then delimiting the escape codes with
966 this non-printing character.
967 If you don't have any non-printing characters, you're out of luck...
968 BTW, don't blame me for this hack; it's in the original ksh.
971 The prompt is printed verbatim (\fIi.e.\fP, no substitutions are done).
973 Default is `\fB$\ \fP' for non-root users, `\fB#\ \fP' for root..
977 Secondary prompt string, by default `\fB>\fP ', used when more input is
978 needed to complete a command.
983 Prompt used by \fBselect\fP statement when reading a menu selection.
984 Default is `\fB#?\ \fP'.
989 Used to prefix commands that are printed during execution tracing
990 (see \fBset \-x\fP command below).
992 Parameter, command and arithmetic substitutions are performed
993 before it is printed.
996 The prompt is printed verbatim (\fIi.e.\fP, no substitutions are done).
998 Default is `\fB+\ \fP'.
1002 The current working directory. Maybe unset or null if shell doesn't
1008 A simple random number generator. Every time \fBRANDOM\fP is
1009 referenced, it is assigned the next number in a random number series.
1010 The point in the series can be set by assigning a number to
1011 \fBRANDOM\fP (see \fIrand\fP(3)).
1016 Default parameter for the \fBread\fP command if no names are given.
1017 Also used in \fBselect\fP loops to store the value that is read from
1023 The number of seconds since the shell started or, if the parameter has been
1024 assigned an integer value, the number of seconds since the assignment plus
1025 the value that was assigned.
1031 If set to a positive integer in an interactive shell, it specifies
1032 the maximum number of seconds the shell will wait for input after
1033 printing the primary prompt (\fBPS1\fP). If the time is exceeded, the
1039 The directory shell temporary files are created in. If this parameter
1040 is not set, or does not contain the absolute path of a writable
1041 directory, temporary files are created in \fB/tmp\fP.
1046 If set, this parameter controls the command line editing mode for
1047 interactive shells. If the last component of the path specified in this
1048 parameter contains the string \fBvi\fP, \fBemacs\fP or \fBgmacs\fP, the
1049 vi, emacs or gmacs (Gosling emacs) editing mode is enabled, respectively.
1054 .\"{{{ Tilde Expansion
1055 .SS "Tilde Expansion"
1056 Tilde expansion, which is done in parallel with parameter substitution,
1057 is done on words starting with an unquoted \fB~\fP. The characters
1058 following the tilde, up to the first \fB/\fP, if any, are assumed to be
1059 a login name. If the login name is empty, \fB+\fP or \fB\-\fP, the
1060 value of the \fBHOME\fP, \fBPWD\fP, or \fBOLDPWD\fP parameter is
1061 substituted, respectively. Otherwise, the password file is searched for
1062 the login name, and the tilde expression is substituted with the
1063 user's home directory. If the login name is not found in the password
1064 file or if any quoting or parameter substitution occurs in the login name,
1065 no substitution is performed.
1067 In parameter assignments (those preceding a simple-command or those
1068 occurring in the arguments of \fBalias\fP, \fBexport\fP, \fBreadonly\fP,
1069 and \fBtypeset\fP), tilde expansion is done after any unquoted colon
1070 (\fB:\fP), and login names are also delimited by colons.
1072 The home directory of previously expanded login names are cached and
1073 re-used. The \fBalias \-d\fP command may be used to list, change and
1074 add to this cache (\fIe.g.\fP, `alias \-d fac=/usr/local/facilities; cd
1077 .\"{{{ Brace Expansion
1079 .SS "Brace Expansion (alternation)"
1080 Brace expressions, which take the form
1082 \fIprefix\fP\fB{\fP\fIstr\fP1\fB,\fP...\fB,\fP\fIstr\fPN\fB}\fP\fIsuffix\fP
1084 are expanded to N words, each of which is the concatenation of
1085 \fIprefix\fP, \fIstr\fPi and \fIsuffix\fP
1086 (\fIe.g.\fP, `a{c,b{X,Y},d}e' expands to four word: ace, abXe, abYe, and ade).
1087 As noted in the example, brace expressions can be nested and the resulting
1088 words are not sorted.
1089 Brace expressions must contain an unquoted comma (\fB,\fP) for expansion
1090 to occur (\fIi.e.\fP, \fB{}\fP and \fB{foo}\fP are not expanded).
1091 Brace expansion is carried out after parameter substitution and before
1092 file name generation.
1095 .\"{{{ File Name Patterns
1096 .SS "File Name Patterns"
1098 A file name pattern is a word containing one or more unquoted \fB?\fP or
1099 \fB*\fP characters or \fB[\fP..\fB]\fP sequences. Once brace expansion has
1100 been performed, the shell replaces file name patterns with the sorted names
1101 of all the files that match the pattern (if no files match, the word is
1102 left unchanged). The pattern elements have the following meaning:
1104 matches any single character.
1106 matches any sequence of characters.
1107 .IP \fB[\fP..\fB]\fP
1108 matches any of the characters inside the brackets. Ranges of characters
1109 can be specified by separating two characters by a \fB\-\fP, \fIe.g.\fP,
1110 \fB[a0\-9]\fP matches the letter \fBa\fP or any digit.
1111 In order to represent itself, a
1112 \fB\-\fP must either be quoted or the first or last character in the character
1113 list. Similarly, a \fB]\fP must be quoted or the first character in the list
1114 if it is represent itself instead of the end of the list. Also, a \fB!\fP
1115 appearing at the start of the list has special meaning (see below), so to
1116 represent itself it must be quoted or appear later in the list.
1117 .IP \fB[!\fP..\fB]\fP
1118 like \fB[\fP..\fB]\fP, except it matches any character not inside the brackets.
1120 .IP "\fB*(\fP\fIpattern\fP\fB|\fP ... \fP|\fP\fIpattern\fP\fB)\fP"
1121 matches any string of characters that matches zero or more occurances
1122 of the specified patterns.
1123 Example: the pattern \fB*(foo|bar)\fP matches the strings
1124 `', `foo', `bar', `foobarfoo', \fIetc.\fP.
1125 .IP "\fB+(\fP\fIpattern\fP\fB|\fP ... \fP|\fP\fIpattern\fP\fB)\fP"
1126 matches any string of characters that matches one or more occurances
1127 of the specified patterns.
1128 Example: the pattern \fB+(foo|bar)\fP matches the strings
1129 `foo', `bar', `foobarfoo', \fIetc.\fP.
1130 .IP "\fB?(\fP\fIpattern\fP\fB|\fP ... \fP|\fP\fIpattern\fP\fB)\fP"
1131 matches the empty string or a string that matches one of the
1133 Example: the pattern \fB?(foo|bar)\fP only matches the strings
1134 `', `foo' and `bar'.
1135 .IP "\fB@(\fP\fIpattern\fP\fB|\fP ... \fP|\fP\fIpattern\fP\fB)\fP"
1136 matches a string that matches one of the
1138 Example: the pattern \fB@(foo|bar)\fP only matches the strings
1140 .IP "\fB!(\fP\fIpattern\fP\fB|\fP ... \fP|\fP\fIpattern\fP\fB)\fP"
1141 matches any string that does not match one of the specified
1143 Examples: the pattern \fB!(foo|bar)\fP matches all strings except
1144 `foo' and `bar'; the pattern \fB!(*)\fP matches no strings;
1145 the pattern \fB!(?)*\fP matches all strings (think about it).
1148 Note that pdksh currently never matches \fB.\fP and \fB..\fP, but the original
1149 ksh, Bourne sh and bash do, so this may have to change (too bad).
1151 Note that none of the above pattern elements match either a period (\fB.\fP)
1152 at the start of a file name or a slash (\fB/\fP), even if they are explicitly
1153 used in a \fB[\fP..\fB]\fP sequence; also, the names \fB.\fP and \fB..\fP
1154 are never matched, even by the pattern \fB.*\fP.
1156 If the \fBmarkdirs\fP option is set, any directories that result from
1157 file name generation are marked with a trailing \fB/\fP.
1159 .\" todo: implement this ([[:alpha:]], \fIetc.\fP)
1160 The POSIX character classes (\fIi.e.\fP,
1161 \fB[:\fP\fIclass-name\fP\fB:]\fP inside a \fB[\fP..\fB]\fP expression)
1162 are not yet implemented.
1164 .\"{{{ Input/Output Redirection
1165 .SS "Input/Output Redirection"
1166 When a command is executed, its standard input, standard output and
1167 standard error (file descriptors 0, 1 and 2, respectively) are normally
1168 inherited from the shell.
1169 Three exceptions to this are commands in pipelines, for which standard input
1170 and/or standard output are those set up by the pipeline, asynchronous commands
1171 created when job control is disabled, for which standard input is initially
1172 set to be from \fB/dev/null\fP, and commands for which any of the following
1173 redirections have been specified:
1174 .IP "\fB>\fP \fIfile\fP"
1175 standard output is redirected to \fIfile\fP. If \fIfile\fP does not exist,
1176 it is created; if it does exist, is a regular file and the \fBnoclobber\fP
1177 option is set, an error occurs, otherwise the file is truncated.
1178 Note that this means the command \fIcmd < foo > foo\fP will open
1179 \fIfoo\fP for reading and then truncate it when it opens it for writing,
1180 before \fIcmd\fP gets a chance to actually read \fIfoo\fP.
1181 .IP "\fB>|\fP \fIfile\fP"
1182 same as \fB>\fP, except the file is truncated, even if the \fBnoclobber\fP
1184 .IP "\fB>>\fP \fIfile\fP"
1185 same as \fB>\fP, except the file an existing file is appended to instead
1186 of being truncated. Also, the file is opened in append mode, so writes
1187 always go to the end of the file (see \fIopen\fP(2)).
1188 .IP "\fB<\fP \fIfile\fP"
1189 standard input is redirected from \fIfile\fP, which is opened for reading.
1190 .IP "\fB<>\fP \fIfile\fP"
1191 same as \fB<\fP, except the file is opened for reading and writing.
1192 .IP "\fB<<\fP \fImarker\fP"
1193 after reading the command line containing this kind of redirection (called a
1194 here document), the shell copies lines from the command source into a temporary
1195 file until a line matching \fImarker\fP is read.
1196 When the command is executed, standard input is redirected from the temporary
1198 If \fImarker\fP contains no quoted characters, the contents of the
1199 temporary file are processed as if enclosed in double quotes each time
1200 the command is executed, so parameter, command and arithmetic substitutions
1201 are performed, along with backslash (\fB\e\fP) escapes for
1202 \fB$\fP, \fB`\fP, \fB\e\fP and \fB\enewline\fP.
1203 If multiple here documents are used on the same command line, they are
1205 .IP "\fB<<-\fP \fImarker\fP"
1206 same as \fB<<\fP, except leading tabs are stripped from lines in the
1208 .IP "\fB<&\fP \fIfd\fP"
1209 standard input is duplicated from file descriptor \fIfd\fP.
1210 \fIfd\fP can be a single digit, indicating the number of an existing
1211 file descriptor, the letter \fBp\fP, indicating the file descriptor
1212 associated with the output of the current co-process, or
1213 the character \fB\-\fP, indicating standard input is to be closed.
1214 .IP "\fB>&\fP \fIfd\fP"
1215 same as \fB<&\fP, except the operation is done on standard output.
1217 In any of the above redirections, the file descriptor that is redirected
1218 (\fIi.e.\fP, standard input or standard output) can be explicitly given by
1219 preceding the redirection with a single digit.
1220 Parameter, command and arithmetic substitutions, tilde substitutions and
1221 (if the shell is interactive) file name generation are all performed
1222 on the \fIfile\fP, \fImarker\fP and \fIfd\fP arguments of redirections.
1223 Note however, that the results of any file name generation are only used
1224 if a single file is matched; if multiple files match, the word with the
1225 unexpanded file name generation characters is used.
1226 Note that in restricted shells, redirections which can create files cannot
1229 For simple-commands, redirections may appear anywhere in the command, for
1230 compound-commands (\fBif\fP statements, \fIetc.\fP), any redirections must
1232 Redirections are processed after pipelines are created and in the order they
1235 \fBcat /foo/bar 2>&1 > /dev/null | cat \-n\fP
1237 will print an error with a line number prepended to it.
1239 .\"{{{ Arithmetic Expressions
1240 .SS "Arithmetic Expressions"
1241 Integer arithmetic expressions can be used
1243 with the \fBlet\fP command,
1245 inside \fB$((\fP..\fB))\fP expressions,
1246 inside array references (\fIe.g.\fP, \fIname\fP\fB[\fP\fIexpr\fP\fB]\fP),
1247 as numeric arguments to the \fBtest\fP command,
1248 and as the value of an assignment to an integer parameter.
1250 Expression may contain alpha-numeric parameter identifiers, array
1251 references, and integer constants and may be combined with the
1252 following C operators (listed and grouped in increasing order of precedence).
1255 \fB+ \- ! ~ ++ --\fP
1260 \fB= *= /= %= += \-= <<= >>= &= ^= |=\fP
1283 \fB?:\fP (precedence is immediately higher than assignment)
1288 Integer constants may be specified with arbitrary bases using the notation
1289 \fIbase\fP\fB#\fP\fInumber\fP, where \fIbase\fP is a decimal integer specifying
1290 the base, and \fInumber\fP is a number in the specified base.
1292 The operators are evaluated as follows:
1295 result is the argument (included for completeness).
1296 .IP "unary \fB\-\fP"
1299 logical not; the result is 1 if argument is zero, 0 if not.
1301 arithmetic (bit-wise) not.
1303 increment; must be applied to a parameter (not a literal or other
1304 expression) - the parameter is incremented by 1.
1305 When used as a prefix operator, the result is the incremented value of
1306 the parameter, when used as a postfix operator, the result is the
1307 original value of the parameter.
1309 similar to \fB++\fP, except the paramter is decremented by 1.
1311 separates two arithmetic expressions; the left hand side is evaluated first,
1312 then the right. The result is value of the expression on the right hand side.
1314 assignment; variable on the left is set to the value on the right.
1315 .IP "\fB*= /= %= += \-= <<= >>= &= ^= |=\fP"
1316 assignment operators; \fI<var> <op>\fP\fB=\fP \fI<expr>\fP is the same as
1317 \fI<var>\fP \fB=\fP \fI<var> <op>\fP \fB(\fP \fI<expr>\fP \fB)\fP.
1319 logical or; the result is 1 if either argument is non-zero, 0 if not.
1320 The right argument is evaluated only if the left argument is zero.
1322 logical and; the result is 1 if both arguments are non-zero, 0 if not.
1323 The right argument is evaluated only if the left argument is non-zero.
1325 arithmetic (bit-wise) or.
1327 arithmetic (bit-wise) exclusive-or.
1329 arithmetic (bit-wise) and.
1331 equal; the result is 1 if both arguments are equal, 0 if not.
1333 not equal; the result is 0 if both arguments are equal, 1 if not.
1335 less than; the result is 1 if the left argument is less than the right,
1338 less than or equal, greater than or equal, greater than. See <.
1340 shift left (right); the result is the left argument with its bits shifted
1341 left (right) by the amount given in the right argument.
1343 addition, subtraction, multiplication, and division.
1345 remainder; the result is the remainder of the division of the left argument
1346 by the right. The sign of the result is unspecified if either argument
1348 .IP "\fI<arg1>\fP \fB?\fP \fI<arg2>\fP \fB:\fP \fI<arg3>\fP"
1349 if \fI<arg1>\fP is non-zero, the result is \fI<arg2>\fP,
1350 otherwise \fI<arg3>\fP.
1356 A co-process, which is a pipeline created with the \fB|&\fP operator,
1357 is an asynchronous process that the shell can both write to
1358 (using \fBprint \-p\fP) and read from (using \fBread \-p\fP).
1359 The input and output of the co-process can also be manipulated
1360 using \fB>&p\fP and \fB<&p\fP redirections, respectively.
1361 Once a co-process has been started, another can't be started until
1362 the co-process exits, or until the co-process input has been redirected using
1363 an \fBexec \fP\fIn\fP\fB>&p\fP redirection.
1364 If a co-process's input is redirected in this way, the next
1365 co-process to be started will share the output with the first co-process,
1366 unless the output of the initial co-process has been redirected using an
1367 \fBexec \fP\fIn\fP\fB<&p\fP redirection.
1369 Some notes concerning co-processes:
1373 the only way to close the co-process input (so the co-process reads
1374 an end-of-file) is to redirect the input to a numbered file descriptor
1375 and then close that file descriptor (\fIe.g.\fP, \fBexec 3>&p;exec 3>&-\fP).
1377 in order for co-processes to share a common output, the shell must keep
1378 the write portion of the output pipe open.
1379 This means that end of file will not be detected until all co-processes
1380 sharing the co-process output have exited (when they all exit, the shell
1381 closes its copy of the pipe).
1382 This can be avoided by redirecting the output to a numbered
1383 file descriptor (as this also causes the shell to close its copy).
1384 Note that this behaviour is slightly different from the original Korn shell
1385 which closes its copy of the write portion of the co-processs output when the
1386 most recently started co-process (instead of when all sharing co-processes)
1389 \fBprint \-p\fP will ignore SIGPIPE signals during writes
1390 if the signal is not being trapped or ignored; the same is not true if
1391 the co-process input has been duplicated to another file descriptor and
1392 \fBprint \-u\fP\fIn\fP is used.
1398 Functions are defined using either Korn shell \fBfunction\fP \fIname\fP
1399 syntax or the Bourne/POSIX shell \fIname\fP\fB()\fP syntax
1400 (see below for the difference between the two forms).
1401 Functions are like \fB.\fP-scripts in that they are executed in
1402 the current environment, however, unlike \fB.\fP-scripts, shell arguments
1403 (\fIi.e.\fP, positional parameters, \fB$1\fP, \fIetc.\fP) are never visible
1405 When the shell is determining the location of a command, functions are
1406 searched after special built-in commands, and before regular and non-regular
1407 built-ins, and before the \fBPATH\fP is searched.
1409 An existing function may be deleted using \fBunset \-f\fP \fIfunction-name\fP.
1410 A list of functions can be obtained using \fBtypeset +f\fP and the
1411 function definitions can be listed using \fBtypeset \-f\fP.
1412 \fBautoload\fP (which is an alias for \fBtypeset \-fu\fP) may be used to
1413 create undefined functions; when an undefined function is executed, the
1414 shell searches the path specified in the \fBFPATH\fP parameter for a file
1415 with the same name as the function, which, if found is read and executed.
1416 If after executing the file, the named function is found to be defined, the
1417 function is executed, otherwise, the normal command search is continued
1418 (\fIi.e.\fP, the shell searches the regular built-in command table
1420 Note that if a command is not found using \fBPATH\fP, an attempt is
1421 made to autoload a function using \fBFPATH\fP (this is an undocumented
1422 feature of the original Korn shell).
1424 Functions can have two attributes, trace and export, which can be set
1425 with \fBtypeset \-ft\fP and \fBtypeset \-fx\fP, respectively.
1426 When a traced function is executed, the shell's \fBxtrace\fP option is turned
1427 on for the functions duration, otherwise the \fBxtrace\fP option is turned off.
1428 The export attribute of functions is currently not used. In the original
1429 Korn shell, exported functions are visible to shell scripts that are executed.
1431 Since functions are executed in the current shell environment, parameter
1432 assignments made inside functions are visible after the function completes.
1433 If this is not the desired effect, the \fBtypeset\fP command can be used
1434 inside a function to create a local parameter.
1435 Note that special parameters (\fIe.g.\fP, \fB$$\fP, \fB$!\fP) can't be
1438 The exit status of a function is that of the last command executed in
1440 A function can be made to finish immediately using the \fBreturn\fP command;
1441 this may also be used to explicitly specify the exit status.
1443 Functions defined with the \fBfunction\fP reserved word are
1444 treated differently in the following ways from functions defined with
1445 the \fB()\fP notation:
1449 the \fB$0\fP parameter is set to the name of the function
1450 (Bourne-style functions leave \fB$0\fP untouched).
1452 parameter assignments preceeding function calls are not kept in
1453 the shell environment
1454 (executing Bourne-style functions will keep assignments).
1456 \fBOPTIND\fP is saved/reset and restored on entry and exit from the function
1457 so \fBgetopts\fP can be used properly both inside and outside the function
1458 (Bourne-style functions leave \fBOPTIND\fP untouched, so using \fBgetopts\fP
1459 inside a function interferes with using \fBgetopts\fP outside the function).
1461 In the future, the following differences will also be added:
1465 A separate trap/signal environment will be used during the execution of
1467 This will mean that traps set inside a function will not affect the shell's
1468 traps and signals that are not ignored in the shell (but may be trapped) will
1469 have their default effect in a function.
1471 The EXIT trap, if set in a function, will be executed after the function
1477 The shell is intended to be POSIX compliant, however, in some cases, POSIX
1478 behaviour is contrary either to the original Korn shell behaviour or to
1480 How the shell behaves in these cases is determined by the state of
1481 the posix option (\fBset \-o posix\fP) \(em if it is on, the POSIX behaviour
1482 is followed, otherwise it is not.
1483 The \fBposix\fP option is set automatically when the shell starts up
1484 if the environment contains the \fBPOSIXLY_CORRECT\fP parameter.
1485 (The shell can also be compiled so that it is in POSIX mode by default,
1486 however this is usually not desirable).
1488 The following is a list of things that are affected by the state of
1489 the \fBposix\fP option:
1494 reading of \fB$ENV\fP: if not in posix mode, the \fBENV\fP parameter
1495 is not expanded and included when the shell starts.
1498 \fB\e"\fP inside double quoted \fB`\fP..\fB`\fP command substitutions:
1499 in posix mode, the \fB\e"\fP is interpreted when the command is interpreted;
1500 in non-posix mode, the backslash is stripped before the command substitution
1501 is interpreted. For example, \fBecho "`echo \e"hi\e"`"\fP produces `"hi"' in
1502 posix mode, `hi' in non-posix mode. To avoid problems, use the \fB$(...\fP)
1503 form of command substitution.
1505 \fBkill \-l\fP output: in posix mode, signal names are listed one a single line;
1506 in non-posix mode, signal numbers, names and descriptions are printed in
1508 In future, a new option (\fB\-v\fP perhaps) will be added to distinguish
1511 \fBfg\fP exit status: in posix mode, the exit status is 0 if no errors occur;
1512 in non-posix mode, the exit status is that of the last foregrounded job.
1514 \fBeval\fP exit status: if eval gets to see an empty command (\fIe.g.\fP,
1515 \fBeval "`false`"\fP), its exit status in posix mode will be 0.
1516 In non-posix mode, it will be the exit status of the last
1517 command substitution that was done in the processing of the arguments to eval
1518 (or 0 if there were no command substitutions).
1520 \fBgetopts\fP: in posix mode, options must start with a \fB\-\fP; in non-posix
1521 mode, options can start with either \fB\-\fP or \fB+\fP.
1523 brace expansion (also known as alternation): in posix mode, brace expansion
1524 is disabled; in non-posix mode, brace expansion enabled.
1525 Note that \fBset \-o posix\fP (or setting the \fBPOSIXLY_CORRECT\fP parameter)
1526 automatically turns the \fBbraceexpand\fP option off, however it can be
1527 explicitly turned on later.
1529 \fBset \-\fP: in posix mode, this does not clear the \fBverbose\fP or
1530 \fBxtrace\fP options; in non-posix mode, it does.
1532 \fBset\fP exit status: in posix mode, the exit status of set is 0
1533 if there are no errors; in non-posix mode, the exit status is that of
1534 any command substitutions performed in generating the set command.
1535 For example, `\fBset \-\- `false`; echo $?\fP' prints 0 in posix mode,
1536 1 in non-posix mode. This construct is used in most shell scripts that
1537 use the old \fIgetopt\fP(1) command.
1539 argument expansion of \fBalias\fP, \fBexport\fP, \fBreadonly\fP, and
1540 \fBtypeset\fP commands: in posix mode, normal argument expansion done;
1541 in non-posix mode, field splitting, file globing, brace expansion and
1542 (normal) tilde expansion are turned off, and assignment tilde expansion
1545 signal specification: in posix mode, signals can be specified as digits only
1546 if signal numbers match POSIX values (\fIi.e.\fP, HUP=1, INT=2, QUIT=3, ABRT=6,
1547 KILL=9, ALRM=14, and TERM=15); in non-posix mode, signals can be always digits.
1549 alias expansion: in posix mode, alias expansion is only carried out when
1550 reading command words; in non-posix mode, alias expansion is carried out
1551 on any word following an alias that ended in a space.
1552 For example, the following for loop
1555 alias a='for ' i='j'
1557 a i in 1 2; do echo i=$i j=$j; done
1560 uses parameter \fBi\fP in posix mode, \fBj\fP in non-posix mode.
1562 test: in posix mode, the expression "\fB-t\fP" (preceded by
1563 some number of "\fB!\fP" arguments) is always true as it is a non-zero length
1564 string; in non-posix mode, it tests if file descriptor 1 is a tty (\fIi.e.\fP,
1565 the \fIfd\fP argument to the \fB-t\fP test may be left out and defaults to 1).
1568 .\"{{{ Command Execution (built-in commands)
1569 .SS "Command Execution"
1570 After evaluation of command line arguments, redirections and parameter
1571 assignments, the type of command is determined: a special built-in,
1572 a function, a regular built-in or the name of a file to execute found
1573 using the \fBPATH\fP parameter.
1574 The checks are made in the above order.
1575 Special built-in commands differ from other commands in that
1576 the \fBPATH\fP parameter is not used to find them, an error
1577 during their execution can cause a non-interactive shell to exit and
1578 parameter assignments that are specified before the command are
1579 kept after the command completes.
1580 Just to confuse things, if the posix option is turned off (see \fBset\fP
1581 command below) some special commands are very special in that
1582 no field splitting, file globing, brace expansion nor tilde expansion
1583 is preformed on arguments that look like assignments.
1584 Regular built-in commands are different only in that the \fBPATH\fP
1585 parameter is not used to find them.
1587 The original ksh and POSIX differ somewhat in which commands are considered
1589 .IP "POSIX special commands"
1591 lw(8m)fB lw(8m)fB lw(8m)fB lw(8m)fB lw(8m)fB .
1592 \&. continue exit return trap
1593 : eval export set unset
1594 break exec readonly shift
1596 .IP "Additional ksh special commands"
1598 lw(8m)fB lw(8m)fB lw(8m)fB lw(8m)fB lw(8m)fB .
1599 builtin times typeset
1601 .IP "Very special commands (non-posix mode)"
1603 lw(8m)fB lw(8m)fB lw(8m)fB lw(8m)fB lw(8m)fB .
1604 alias readonly set typeset
1606 .IP "POSIX regular commands"
1608 lw(8m)fB lw(8m)fB lw(8m)fB lw(8m)fB lw(8m)fB .
1609 alias command fg kill umask
1610 bg false getopts read unalias
1611 cd fc jobs true wait
1613 .IP "Additional ksh regular commands"
1615 lw(8m)fB lw(8m)fB lw(8m)fB lw(8m)fB lw(8m)fB .
1617 echo print test whence
1620 In the future, the additional ksh special and regular commands may
1621 be treated differently from the POSIX special and regular commands.
1623 Once the type of the command has been determined, any command line parameter
1624 assignments are performed and exported for the duration of the command.
1626 The following describes the special and regular built-in commands:
1627 .\"{{{ . file [ arg1 ... ]
1628 .IP "\fB\&.\fP \fIfile\fP [\fIarg1\fP ...]"
1629 Execute the commands in \fIfile\fP in the current environment.
1630 The file is searched for in the directories of \fBPATH\fP.
1631 If arguments are given, the positional parameters may be used to
1632 access them while \fIfile\fP is being executed.
1633 If no arguments are given, the positional parameters are those of the
1634 environment the command is used in.
1637 .IP "\fB:\fP [ ... ]"
1639 Exit status is set to zero.
1641 .\"{{{ alias [ -d | +-t [ -r ] ] [+-px] [+-] [name1[=value1] ...]
1642 .IP "\fBalias\fP [ \fB\-d\fP | \fB\(+-t\fP [\fB\-r\fP] ] [\fB\(+-px\fP] [\fB\(+-\fP] [\fIname1\fP[\fB=\fP\fIvalue1\fP] ...]"
1643 Without arguments, \fBalias\fP lists all aliases.
1644 For any name without a value, the existing alias is listed.
1645 Any name with a value defines an alias (see Aliases above).
1647 When listing aliases, one of two formats is used:
1648 normally, aliases are listed as \fIname\fP\fB=\fP\fIvalue\fP, where
1649 \fIvalue\fP is quoted; if options were preceded with \fB+\fP
1650 or a lone \fB+\fP is given on the command line, only \fIname\fP
1652 In addition, if the \fB\-p\fP option is used, each alias
1653 is prefixed with the string "\fBalias\fP\ ".
1655 The \fB\-x\fP option sets (\fB+x\fP clears) the export attribute of an alias,
1656 or, if no names are given, lists the aliases with the export attribute
1657 (exporting an alias has no affect).
1659 The \fB\-t\fP option indicates that tracked aliases are to be listed/set
1660 (values specified on the command line are ignored for tracked aliases).
1661 The \fB\-r\fP option indicates that all tracked aliases are to be reset.
1663 The \fB\-d\fP causes directory aliases, which are used in tilde expansion,
1664 to be listed or set (see Tilde Expansion above).
1667 .IP "\fBbg\fP [\fIjob\fP ...]"
1668 Resume the specified stopped job(s) in the background.
1669 If no jobs are specified, \fB%+\fP is assumed.
1670 This command is only available on systems which support job control.
1671 See Job Control below for more information.
1673 .\"{{{ bind [-l] [-m] [key[=editing-command] ...]
1674 .IP "\fBbind\fP [\fB\-m\fP] [\fIkey\fP[\fB=\fP\fIediting-command\fP] ...]"
1675 Set or view the current emacs command editing key bindings/macros.
1676 See Emacs Editing Mode below for a complete description.
1678 .\"{{{ break [level]
1679 .IP "\fBbreak\fP [\fIlevel\fP]"
1680 \fBbreak\fP exits the \fIlevel\fPth inner most for, select, until, or while
1682 \fIlevel\fP defaults to 1.
1684 .\"{{{ builtin command [arg1 ...]
1685 .IP "\fBbuiltin\fP \fIcommand\fP [\fIarg1\fP ...]"
1686 Execute the built-in command \fIcommand\fP.
1688 .\"{{{ cd [-LP] [dir]
1689 .IP "\fBcd\fP [\fB\-LP\fP] [\fIdir\fP]"
1690 Set the working directory to \fIdir\fP. If the parameter \fBCDPATH\fP
1691 is set, it lists directories to search in for \fIdir\fP.
1692 \fIdir\fP. An empty entry in the \fBCDPATH\fP entry means the current
1694 If a non-empty directory from \fBCDPATH\fP is used, the resulting full
1695 path is printed to standard output.
1697 missing, the home directory \fB$HOME\fP is used. If \fIdir\fP is
1698 \fB\-\fP, the previous working directory is used (see OLDPWD parameter).
1699 If \fB\-L\fP option (logical path) is used or if the \fBphysical\fP option
1700 (see \fBset\fP command below) isn't set, references to \fB..\fP in \fIdir\fP
1701 are relative to the path used get to the directory.
1702 If \fB\-P\fP option (physical path) is used or if the \fBphysical\fP option
1703 is set, \fB..\fP is relative to the filesystem directory tree.
1704 The \fBPWD\fP and \fBOLDPWD\fP parameters are updated to reflect the
1705 current and old wording directory, respectively.
1707 .\"{{{ cd [-LP] old new
1708 .IP "\fBcd\fP [\fB\-LP\fP] \fIold new\fP"
1709 The string \fInew\fP is substituted for \fIold\fP in the current
1710 directory, and the shell attempts to change to the new directory.
1712 .\"{{{ command [ -pvV ] cmd [arg1 ...]
1714 .IP "\fBcommand\fP [\fB\-pvV\fP] \fIcmd\fP [\fIarg1\fP ...]"
1715 If neither the \fB\-v\fP nor \fB\-V\fP options are given,
1718 .IP "\fBcommand\fP [\fB\-p\fP] \fIcmd\fP [\fIarg1\fP ...]"
1721 is executed exactly as if the \fBcommand\fP had not been specified,
1722 with two exceptions: first, \fIcmd\fP cannot be a shell function, and
1723 second, special built-in commands lose their specialness (\fIi.e.\fP,
1724 redirection and utility errors do not cause the shell to exit, and command
1725 assignments are not permanent).
1726 If the \fB\-p\fP option is given, a default search path is used instead of
1727 the current value of \fBPATH\fP (the actual value of the default path is
1728 system dependent: on POSIXish systems, it is the value returned by
1730 \fBgetconf CS_PATH\fP
1734 If the \fB\-v\fP option is given, instead of executing \fIcmd\fP, information
1735 about what would be executed is given (and the same is done for
1737 for special and regular built-in commands and functions,
1738 their names are simply printed,
1739 for aliases, a command that defines them is printed,
1740 and for commands found by searching the \fBPATH\fP parameter,
1741 the full path of the command is printed.
1742 If no command is be found, (\fIi.e.\fP, the path search fails), nothing
1743 is printed and \fBcommand\fP exits with a non-zero status.
1744 The \fB\-V\fP option is like the \fB\-v\fP option, except it is more verbose.
1747 .\"{{{ continue [levels]
1748 .IP "\fBcontinue\fP [\fIlevels\fP]"
1749 \fBcontinue\fP jumps to the beginning of the \fIlevel\fPth inner most for,
1750 select, until, or while loop.
1751 \fIlevel\fP defaults to 1.
1753 .\"{{{ echo [-neE] [arg ...]
1754 .IP "\fBecho\fP [\fB\-neE\fP] [\fIarg\fP ...]"
1755 Prints its arguments (separated by spaces) followed by a newline, to
1757 The newline is suppressed if any of the arguments contain the backslash
1759 See \fBprint\fP command below for a list of other backslash sequences
1760 that are recognized.
1762 The options are provided for compatibility with BSD shell scripts:
1763 \fB\-n\fP suppresses the trailing newline, \fB\-e\fP enables backslash
1764 interpretation (a no-op, since this is normally done), and \fB\-E\fP which
1765 suppresses backslash interpretation.
1767 .\"{{{ eval command ...
1768 .IP "\fBeval\fP \fIcommand ...\fP"
1769 The arguments are concatenated (with spaces between them) to form
1770 a single string which the shell then parses and executes
1771 in the current environment.
1773 .\"{{{ exec [command [arg ...]]
1774 .IP "\fBexec\fP [\fIcommand\fP [\fIarg\fP ...]]"
1775 The command is executed without forking, replacing the shell process.
1777 If no arguments are given, any IO redirection is permanent and the shell
1780 Any file descriptors greater than 2 which are opened or \fIdup\fP(2)-ed
1782 made available to other executed commands (\fIi.e.\fP,
1783 commands that are not built-in to the shell).
1784 Note that the Bourne shell differs here: it does pass these
1785 file descriptors on.
1788 Any file descriptors which are opened or \fIdup\fP(2)-ed
1789 in this way are made available to other executed commands
1790 (note that the Korn shell differs here: it does not pass on
1791 file descriptors greater than 2).
1794 .\"{{{ exit [status]
1795 .IP "\fBexit\fP [\fIstatus\fP]"
1796 The shell exits with the specified exit status.
1797 If \fIstatus\fP is not specified, the exit status is the current
1798 value of the \fB?\fP parameter.
1800 .\"{{{ export [-p] [parameter[=value] ...]
1801 .IP "\fBexport\fP [\fB\-p\fP] [\fIparameter\fP[\fB=\fP\fIvalue\fP]] ..."
1802 Sets the export attribute of the named parameters.
1803 Exported parameters are passed in the environment to executed commands.
1804 If values are specified, the named parameters also assigned.
1806 If no parameters are specified, the names of all parameters with the export
1807 attribute are printed one per line, unless the \fB\-p\fP option is used,
1808 in which case \fBexport\fP commands defining all exported
1809 parameters, including their values, are printed.
1813 A command that exits with a non-zero status.
1815 .\"{{{ fc [-e editor | -l [-n]] [-r] [first [ last ]]
1817 .IP "\fBfc\fP [\fB\-e\fP \fIeditor\fP | \fB\-l\fP [\fB\-n\fP]] [\fB\-r\fP] [\fIfirst\fP [\fIlast\fP]]"
1818 \fIfirst\fP and \fIlast\fP select commands from the history.
1819 Commands can be selected by
1820 history number, or a string specifying the most recent command starting
1821 with that string. The \fB\-l\fP option lists the command on stdout,
1822 and \fB\-n\fP inhibits the default command numbers. The \fB\-r\fP
1823 option reverses the order of the list. Without \fB\-l\fP, the selected
1824 commands are edited by the editor specified with the \fB\-e\fP
1825 option, or if no \fB\-e\fP is specified, the editor specified by the
1826 \fBFCEDIT\fP parameter (if this parameter is not set, \fB/bin/ed\fP is used),
1827 and then executed by the shell.
1830 .\"{{{ fc [-e - | -s] [-g] [old=new] [prefix]
1831 .IP "\fBfc\fP [\fB\-e \-\fP | \fB\-s\fP] [\fB\-g\fP] [\fIold\fP\fB=\fP\fInew\fP] [\fIprefix\fP]"
1832 Re-execute the selected command (the previous command by default) after
1833 performing the optional substitution of \fIold\fP with \fInew\fP. If
1834 \fB\-g\fP is specified, all occurrences of \fIold\fP are replaced with
1835 \fInew\fP. This command is usually accessed with the predefined alias
1836 \fBr='fc \-e \-'\fP.
1839 .IP "\fBfg\fP [\fIjob\fP ...]"
1840 Resume the specified job(s) in the foreground.
1841 If no jobs are specified, \fB%+\fP is assumed.
1842 This command is only available on systems which support job control.
1843 See Job Control below for more information.
1845 .\"{{{ getopts optstring name [arg ...]
1846 .IP "\fBgetopts\fP \fIoptstring\fP \fIname\fP [\fIarg\fP ...]"
1847 \fBgetopts\fP is used by shell procedures to parse the specified arguments
1848 (or positional parameters, if no arguments are given) and to check for legal
1850 \fIoptstring\fP contains the option letters that
1851 \fBgetopts\fP is to recognize. If a letter is followed by a colon, the
1852 option is expected to have an argument.
1853 Options that do not take arguments may be grouped in a single argument.
1854 If an option takes an argument and the option character is not the last
1855 character of the argument it is found in, the remainder of the argument
1856 is taken to be the option's argument, otherwise, the next argument is
1857 the option's argument.
1859 Each time \fBgetopts\fP is invoked, it places the next option in
1860 the shell parameter \fIname\fP and the index of the next argument to be
1861 processed in the shell parameter \fBOPTIND\fP.
1862 If the option was introduced with a \fB+\fP, the option placed in
1863 \fIname\fP is prefixed with a \fB+\fP.
1864 When an option requires an argument, \fBgetopts\fP places it in the
1865 shell parameter \fBOPTARG\fP.
1866 When an illegal option or a missing option argument is
1867 encountered a question mark or a colon is placed in \fIname\fP
1868 (indicating an illegal option or missing argument, respectively)
1869 and \fBOPTARG\fP is set to the option character that caused the problem.
1870 An error message is also printed to standard error if \fIoptstring\fP
1871 does not begin with a colon.
1873 When the end of the options is encountered, \fBgetopts\fP exits with a
1874 non-zero exit status.
1875 Options end at the first (non-option argument) argument that does not
1876 start with a \-, or when a \fB\-\-\fP argument is encountered.
1878 Option parsing can be reset by setting \fBOPTIND\fP to 1 (this is done
1879 automatically whenever the shell or a shell procedure is invoked).
1881 Warning: Changing the value of the shell parameter \fBOPTIND\fP to
1882 a value other than 1, or parsing different sets of arguments without
1883 resetting \fBOPTIND\fP may lead to unexpected results.
1885 .\"{{{ hash [-r] [name ...]
1886 .IP "\fBhash\fP [\fB\-r\fP] [\fIname ...\fP]"
1887 Without arguments, any hashed executable command pathnames are listed.
1888 The \fB\-r\fP option causes all hashed commands to be removed
1889 from the hash table.
1890 Each \fIname\fP is searched as if it where a command name and added to the
1891 hash table if it is an executable command.
1893 .\"{{{ jobs [-lpn] [job ...]
1894 .IP "\fBjobs\fP [\fB\-lpn\fP] [\fIjob\fP ...]"
1895 Display information about the specified jobs; if no jobs are specified,
1896 all jobs are displayed.
1897 The \fB\-n\fP option causes information to be displayed only for jobs
1898 that have changed state since the last notification.
1899 If the \fB\-l\fP option is used, the process-id of each process in a job
1901 The \fB\-p\fP option causes only the process group of each job to be printed.
1902 See Job Control below for the format of \fIjob\fP and the displayed job.
1904 .\"{{{ kill [-s signame | -signum | -signame] { job | pid | -pgrp } ...
1905 .IP "\fBkill\fP [\fB\-s\fP \fIsigname\fP | \fB\-signum\fP | \fB\-signame\fP ] { \fIjob\fP | \fIpid\fP | \fB\-\fP\fIpgrp\fP } ..."
1906 Send the specified signal to the specified jobs, process ids, or process groups.
1907 If no signal is specified, the signal TERM is sent.
1908 If a job is specified, the signal is sent to the job's process group.
1909 See Job Control below for the format of \fIjob\fP.
1911 .\"{{{ kill -l [exit-status ...]
1912 .IP "\fBkill \-l\fP [\fIexit-status\fP ...]"
1913 Print the name of the signal that killed a process which exited with
1914 the specified \fIexit-status\fPes.
1915 If no arguments are specified, a list of all the signals, their numbers and
1916 a short description of them are printed.
1918 .\"{{{ let [expression ...]
1920 .IP "\fBlet\fP [\fIexpression\fP ...]"
1921 Each expression is evaluated, see Arithmetic Expressions above.
1922 If all expressions are successfully evaluated, the exit status
1923 is 0 (1) if the last expression evaluated to non-zero (zero).
1924 If an error occurs during the parsing or evaluation of an expression,
1925 the exit status is greater than 1.
1926 Since expressions may need to be
1927 quoted, \fB((\fP \fIexpr\fP \fB))\fP is syntactic sugar for \fBlet
1928 "\fP\fIexpr\fP\fB"\fP.
1931 .\"{{{ print [-nprsun | -R [-en]] [argument ...]
1932 .IP "\fBprint\fP [\fB\-nprsu\fP\fIn\fP | \fB\-R\fP [\fB\-en\fP]] [\fIargument ...\fP]"
1933 \fBPrint\fP prints its arguments on the standard output, separated by
1934 spaces, and terminated with a newline. The \fB\-n\fP option suppresses
1935 the newline. By default, certain C escapes are translated. These
1936 include \eb, \ef, \en, \er, \et, \ev, and \e0### (# is an octal digit, of
1937 which there may be 0 to 3).
1938 \ec is equivalent to using the \fB\-n\fP option. \e expansion may be
1939 inhibited with the \fB\-r\fP option.
1940 The \fB\-s\fP option prints to the history file instead of standard output,
1941 the \fB\-u\fP option prints to file descriptor \fIn\fP (\fIn\fP
1942 defaults to 1 if omitted), and the \fB\-p\fP option prints to the co-process
1943 (see Co-Processes above).
1945 The \fB\-R\fP option is used to emulate, to some degree, the BSD echo
1946 command, which does not process \e sequences unless the \fB\-e\fP option
1948 As above, the \fB\-n\fP option suppresses the trailing newline.
1951 .IP "\fBpwd\fP [\fB\-LP\fP]"
1952 Print the present working directory.
1953 If \fB\-L\fP option is used or if the \fBphysical\fP option
1954 (see \fBset\fP command below) isn't set, the logical path is printed
1955 (\fIi.e.\fP, the path used to \fBcd\fP to the current directory).
1956 If \fB\-P\fP option (physical path) is used or if the \fBphysical\fP option
1957 is set, the path determined from the filesystem (by following \fB..\fP
1958 directories to the root directory) is printed.
1960 .\"{{{ read [-prsun] [parameter ...]
1961 .IP "\fBread\fP [\fB\-prsu\fP\fIn\fP] [\fIparameter ...\fP]"
1962 Reads a line of input from standard input, separate the line into fields using
1963 the \fBIFS\fP parameter (see Substitution above), and assign each field to the
1964 specified parameters.
1965 If there are more parameters than fields, the extra parameters are set to null,
1966 or alternatively, if there are more fields than parameters, the last parameter
1967 is assigned the remaining fields (inclusive of any separating spaces).
1968 If no parameters are specified, the \fBREPLY\fP parameter is used.
1969 If the input line ends in a backslash and the \fB\-r\fP option was not used, the
1970 backslash and newline are stripped and more input is read.
1971 If no input is read, \fBread\fP exits with a non-zero status.
1973 The first parameter may have a question mark and a string appended to it, in
1974 which case the string is used as a prompt (printed to standard error before
1975 any input is read) if the input is a tty
1976 (\fIe.g.\fP, \fBread nfoo?'number of foos: '\fP).
1978 The \fB\-u\fP\fIn\fP and \fB\-p\fP options cause input to be read
1979 from file descriptor \fIn\fP or the current co-process (see Co-Processes above
1980 for comments on this), respectively.
1981 If the \fB\-s\fP option is used, input is saved to the history file.
1983 .\"{{{ readonly [-p] [parameter[=value] ...]
1984 .IP "\fBreadonly\fP [\fB\-p\fP] [\fIparameter\fP[\fB=\fP\fIvalue\fP]] ..."
1985 Sets the readonly attribute of the named parameters. If values are given,
1986 parameters are set to them before setting the attribute.
1987 Once a parameter is made readonly, it cannot be unset and its value cannot
1990 If no parameters are specified, the names of all parameters with the readonly
1991 attribute are printed one per line, unless the \fB\-p\fP option is used,
1992 in which case \fBreadonly\fP commands defining all readonly
1993 parameters, including their values, are printed.
1995 .\"{{{ return [status]
1996 .IP "\fBreturn\fP [\fIstatus\fP]"
1997 Returns from a function or \fB.\fP script, with exit status \fIstatus\fP.
1998 If no \fIstatus\fP is given, the exit status of the last executed command
2000 If used outside of a function or \fB.\fP script, it has the same effect
2002 Note that pdksh treats both profile and \fB$ENV\fP files as \fB.\fP scripts,
2003 while the original Korn shell only treats profiles as \fB.\fP scripts.
2005 .\"{{{ set [+-abCefhkmnpsuvxX] [+-o [option]] [+-A name] [--] [arg ...]
2006 .IP "\fBset\fP [\fB\(+-abCefhkmnpsuvxX\fP] [\fB\(+-o\fP [\fIoption\fP]] [\fB\(+-A\fP \fIname\fP] [\fB\-\-\fP] [\fIarg\fP ...]"
2007 The set command can be used to set (\fB\-\fP) or clear (\fB+\fP) shell options,
2008 set the positional parameters, or set an array parameter.
2009 Options can be changed using the \fB\(+-o\fP \fIoption\fP syntax,
2010 where \fIoption\fP is the long name of an option, or using
2011 the \fB\(+-\fP\fIletter\fP syntax, where \fIletter\fP is the
2012 option's single letter name (not all options have a single letter name).
2013 The following table lists both option letters (if they exist) and long names
2014 along with a description of what the option does.
2020 Sets the elements of the array parameter \fIname\fP to \fIarg\fP ...;
2021 If \fB\-A\fP is used, the array is reset (\fIi.e.\fP, emptied) first;
2022 if \fB+A\fP is used, the first N elements are set (where N is the number
2023 of \fIarg\fPs), the rest are left untouched.
2026 all new parameters are created with the export attribute
2029 Print job notification messages asynchronously, instead of just before the
2031 Only used if job control is enabled (\fB\-m\fP).
2034 Prevent \fB>\fP redirection from overwriting existing files (\fB>|\fP must
2035 be used to force an overwrite).
2038 Exit (after executing the \fBERR\fP trap) as soon as an error occurs or
2039 a command fails (\fIi.e.\fP, exits with a non-zero status).
2040 This does not apply to commands whose exit status is explicitly tested by a
2041 shell construct such as \fBif\fP, \fBuntil\fP, \fBwhile\fP, \fB&&\fP or
2042 \fB||\fP statements.
2045 Do not expand file name patterns.
2048 Create tracked aliases for all executed commands (see Aliases above).
2049 On by default for non-interactive shells.
2052 Enable interactive mode \- this can only be set/unset when the shell is
2056 Parameter assignments are recognized anywhere in a command.
2059 The shell is a login shell \- this can only be set/unset when the shell is
2060 invoked (see Shell Startup above).
2063 Enable job control (default for interactive shells).
2066 Do not execute any commands \- useful for checking the syntax of scripts
2067 (ignored if interactive).
2070 Set automatically if, when the shell starts, the read uid or gid does not
2071 match the effective uid or gid, respectively.
2072 See Shell Startup above for a description of what this
2076 Enable restricted mode \(em this option can only be used when the shell is
2077 invoked. See Shell Startup above for a description of what this
2081 If used when the shell is invoked, commands are read from standard input.
2082 Set automatically if the shell is invoked with no arguments.
2084 When \fB\-s\fP is used in the \fBset\fP command, it causes the specified
2085 arguments to be sorted before assigning them to the positional parameters
2086 (or to array \fIname\fP, if \fB\-A\fP is used).
2089 Referencing of an unset parameter is treated as an error, unless
2090 one of the \fB\-\fP, \fB+\fP or \fB=\fP modifiers is used.
2093 Write shell input to standard error as it is read.
2096 Print commands and parameter assignments when they are executed,
2097 preceded by the value of \fBPS4\fP.
2100 Mark directories with a trailing \fB/\fP during file name generation.
2103 Background jobs are run with lower priority.
2107 Enable brace expansion (aka, alternation).
2112 Enable BRL emacs-like command line editing (interactive shells only);
2113 see Emacs Editing Mode.
2116 Enable gmacs-like (Gosling emacs) command line editing (interactive shells
2118 currently identical to emacs editing except that transpose (^T) acts
2119 slightly differently.
2123 The shell will not (easily) exit on when end-of-file is read, \fBexit\fP must
2125 To avoid infinite loops, the shell will exit if eof is read 13 times in
2129 Do not kill running jobs with a \fBHUP\fP signal when a login shell exists.
2130 Currently set by default, but this will change in the future to be compatible
2131 with the original Korn shell (which doesn't have this option, but does
2132 send the \fBHUP\fP signal).
2135 No effect \- in the original Korn shell, this prevents function definitions
2136 from being stored in the history file.
2139 Causes the \fBcd\fP and \fBpwd\fP commands to use `physical'
2140 (\fIi.e.\fP, the filesystem's) \fB..\fP directories instead of `logical'
2141 directories (\fIi.e.\fP, the shell handles \fB..\fP, which allows the user
2142 to be obliveous of symlink links to directories).
2143 Clear by default. Note that setting
2144 this option does not effect the current value of the \fBPWD\fP parameter;
2145 only the \fBcd\fP command changes \fBPWD\fP.
2146 See the \fBcd\fP and \fBpwd\fP commands above for more details.
2149 Enable posix mode. See POSIX Mode above.
2152 Enable vi-like command line editing (interactive shells only).
2155 No effect \- in the original Korn shell, unless viraw was set, the vi command
2156 line mode would let the tty driver do the work until ESC (^[) was entered.
2157 pdksh is always in viraw mode.
2160 In vi command line editing, do command / file name completion when
2161 escape (^[) is entered in command mode.
2164 Prefix characters with the eighth bit set with `M-'.
2165 If this option is not set, characters in the range
2166 128-160 are printed as is, which may cause problems.
2169 In vi command line editing, do command / file name completion when
2170 tab (^I) is entered in insert mode.
2174 These options can also be used upon invocation of the shell. The current
2175 set of options (with single letter names) can be found in the
2177 \fBset -o\fP with no option name will list all the options and whether each
2178 is on or off; \fBset +o\fP will print the long names of all options that
2181 Remaining arguments, if any, are positional parameters and are assigned,
2183 positional parameters (\fIi.e.\fP, \fB1\fP, \fB2\fP, \fIetc.\fP).
2184 If options are ended with \fB\-\-\fP and there are no remaining arguments,
2185 all positional parameters are cleared.
2186 If no options or arguments are given, then the values of all names are printed.
2187 For unknown historical reasons, a lone \fB\-\fP option is treated specially:
2188 it clears both the \fB\-x\fP and \fB\-v\fP options.
2190 .\"{{{ shift [number]
2191 .IP "\fBshift\fP [\fInumber\fP]"
2192 The positional parameters \fInumber\fP+1, \fInumber\fP+2 \fIetc.\fP\& are
2193 renamed to \fB1\fP, \fB2\fP, \fIetc.\fP
2194 \fInumber\fP defaults to 1.
2196 .\"{{{ test expression, [ expression ]
2197 .IP "\fBtest\fP \fIexpression\fP"
2198 .IP "\fB[\fP \fIexpression\fP \fB]\fP"
2199 \fBtest\fP evaluates the \fIexpression\fP and returns zero status if
2200 true, and 1 status if false and greater than 1 if there was an error.
2201 It is normally used as the
2202 condition command of \fBif\fP and \fBwhile\fP statements.
2203 The following basic expressions are available:
2208 \fIstr\fP has non-zero length. Note that there is the potential
2209 for problems if \fIstr\fP turns out to be an operator (\fIe.g.\fP, \fB-r\fP)
2210 - it is generally better to use a test like
2212 \fB[ X"\fP\fIstr\fP\fB" != X ]\fP
2214 instead (double quotes are used in case \fIstr\fP contains spaces or file
2215 globing characters).
2218 \fIfile\fP exists and is readable.
2221 \fIfile\fP exists and is writable.
2224 \fIfile\fP exists and is executable.
2233 \fIfile\fP is a regular file.
2236 \fIfile\fP is a directory.
2239 \fIfile\fP is a character special device.
2242 \fIfile\fP is a block special device.
2245 \fIfile\fP is a named pipe.
2248 \fIfile\fP's mode has setuid bit set.
2251 \fIfile\fP's mode has setgid bit set.
2254 \fIfile\fP's mode has sticky bit set.
2257 \fIfile\fP is not empty.
2260 \fIfile\fP's owner is the shell's effective user-ID.
2263 \fIfile\fP's group is the shell's effective group-ID.
2266 \fIfile\fP is a symbolic link.
2269 \fIfile\fP is a context dependent directory (only useful on HP-UX).
2272 \fIfile\fP is a symbolic link.
2275 \fIfile\fP is a socket.
2278 shell \fIoption\fP is set (see \fBset\fP command above for list of options).
2279 As a non-standard extension, if the option starts with a \fB!\fP, the test
2280 is negated; the test always fails if option doesn't exist (thus
2282 \fB[ -o \fP\fIfoo\fP \fB-o -o !\fP\fIfoo\fP \fB]\fP
2284 returns true if and only if option \fIfoo\fP exists).
2286 \fIfile\fP \-nt \fIfile\fP T{
2287 first \fIfile\fP is newer than second \fIfile\fP or first
2288 \fIfile\fP exists and the second \fIfile\fP does not.
2290 \fIfile\fP \-ot \fIfile\fP T{
2291 first \fIfile\fP is older than second \fIfile\fP or second \fIfile\fP
2292 exists and the first \fIfile\fP does not.
2294 \fIfile\fP \-ef \fIfile\fP T{
2295 first \fIfile\fP is the same file as second \fIfile\fP.
2298 file descriptor is a tty device.
2299 If the posix option (\fBset \-o posix\fP, see POSIX Mode above) is not
2300 set, \fIfd\fP may be left out, in which case it is taken to be 1
2301 (the behaviour differs due to the special POSIX rules described below).
2304 \fIstring\fP is not empty.
2306 \-z\ \fIstring\fP T{
2307 \fIstring\fP is empty.
2309 \-n\ \fIstring\fP T{
2310 \fIstring\fP is not empty.
2312 \fIstring\fP\ =\ \fIstring\fP T{
2316 \fIstring\fP\ ==\ \fIstring\fP T{
2320 \fIstring\fP\ !=\ \fIstring\fP T{
2321 strings are not equal.
2323 \fInumber\fP\ \-eq\ \fInumber\fP T{
2324 numbers compare equal.
2326 \fInumber\fP\ \-ne\ \fInumber\fP T{
2327 numbers compare not equal.
2329 \fInumber\fP\ \-ge\ \fInumber\fP T{
2330 numbers compare greater than or equal.
2332 \fInumber\fP\ \-gt\ \fInumber\fP T{
2333 numbers compare greater than.
2335 \fInumber\fP\ \-le\ \fInumber\fP T{
2336 numbers compare less than or equal.
2338 \fInumber\fP\ \-lt\ \fInumber\fP T{
2339 numbers compare less than.
2343 The above basic expressions, in which unary operators have precedence over
2344 binary operators, may be combined with the following operators
2345 (listed in increasing order of precedence):
2349 \fIexpr\fP \-o \fIexpr\fP logical or
2350 \fIexpr\fP \-a \fIexpr\fP logical and
2351 ! \fIexpr\fP logical not
2352 ( \fIexpr\fP ) grouping
2355 On operating systems not supporting \fB/dev/fd/\fP\fIn\fP devices
2356 (where \fIn\fP is a file descriptor number),
2357 the \fBtest\fP command will attempt to fake it for all tests that
2358 operate on files (except the \fB-e\fP test).
2359 I.e., \fB[ -w /dev/fd/2 ]\fP tests if file descriptor 2 is writable.
2361 Note that some special rules are applied (courtesy of POSIX) if the
2362 number of arguments to \fBtest\fP or \fB[\fP \&... \fB]\fP is less than
2363 five: if leading \fB!\fP arguments can be stripped such that only one
2364 argument remains then a string length test is performed (again, even if
2365 the argument is a unary operator);
2366 if leading \fB!\fP arguments can be stripped such that three
2367 arguments remain and the second argument is a binary operator, then the
2368 binary operation is performed (even if first argument is a unary
2369 operator, including an unstripped \fB!\fP).
2371 \fBNote:\fP A common mistake is to use \fBif [ $foo = bar ]\fP which
2372 fails if parameter \fBfoo\fP is null or unset, if it has embedded spaces
2373 (\fIi.e.\fP, \fBIFS\fP characters), or if it is a unary operator like \fB!\fP or
2374 \fB\-n\fP. Use tests like \fBif [ "X$foo" = Xbar ]\fP instead.
2376 .\"{{{ time [-p] [pipeline]
2377 .IP "\fBtime\fP [\fB-p\fP] [ \fIpipeline\fP ]"
2378 If a pipeline is given, the times used to execute the pipeline are reported.
2379 If no pipeline is given, then the user and system time used by the shell
2380 itself, and all the commands it has run since it was started, are reported.
2381 The times reported are
2382 the real time (elapsed time from start to finish),
2383 the user cpu time (time spent running in user mode)
2384 and the system cpu time (time spent running in kernel mode).
2385 Times are reported to standard error; the format of the output is:
2387 0.00s real 0.00s user 0.00s system
2389 unless the -p option is given (only possible if \fIpipeline\fP is a simple
2390 command), in which case the output is slightly longer:
2396 (the number of digits after the decimal may vary from system to system).
2397 Note that simple redirections of standard error do not effect the output
2398 of the time command:
2400 \fBtime sleep 1 2> \fP\fIafile\fP
2402 \fB{ time sleep 1; } 2> \fP\fIafile\fP
2403 times for the first command do not go to \fIafile\fP, but those of the
2408 Print the accumulated user and system times used by the shell and by
2409 processes which have exited that the shell started.
2411 .\"{{{ trap [handler signal ...]
2412 .IP "\fBtrap\fP [\fIhandler\fP \fIsignal ...\fP]"
2413 Sets trap handler that is to be executed when any of the specified signals
2415 \fBHandler\fP is either a null string, indicating the signals are to
2416 be ignored, a minus (\fB\-\fP), indicating that the default action is to
2417 be taken for the signals (see signal(2 or 3)), or a string containing shell
2418 commands to be evaluated and executed at the first opportunity (\fIi.e.\fP,
2419 when the current command completes, or before printing the next \fBPS1\fP
2420 prompt) after receipt of one of the signals.
2421 \fBSignal\fP is the name of a signal (\fIe.g.\fP, PIPE or ALRM) or the number
2422 of the signal (see \fBkill \-l\fP command above).
2423 There are two special signals: \fBEXIT\fP (also known as \fB0\fP), which
2424 is executed when the shell is about to exit, and \fBERR\fP which is
2425 executed after an error occurs (an error is something that would cause
2426 the shell to exit if the \fB\-e\fP or \fBerrexit\fP option were set \(em
2427 see \fBset\fP command above).
2428 \fBEXIT\fP handlers are executed in the environment of the last executed
2430 Note that for non-interactive shells, the trap handler cannot be changed for
2431 signals that were ignored when the shell started.
2433 With no arguments, \fBtrap\fP lists, as a series of \fBtrap\fP commands,
2434 the current state of the traps that have been set since the shell started.
2435 Note that the output of \fBtrap\fP can not be usefully piped to another process
2436 (an artifact of the fact that traps are cleared when subprocesses are
2439 .\" todo: add these features (trap DEBUG, trap ERR/EXIT in function)
2440 The original Korn shell's \fBDEBUG\fP trap and the handling of \fBERR\fP and
2441 \fBEXIT\fP traps in functions are not yet implemented.
2445 A command that exits with a zero value.
2447 .\"{{{ typeset [[+-Ulprtux] [-L[n]] [-R[n]] [-Z[n]] [-i[n]] | -f [-tux]] [name[=value] ...]
2448 .IP "\fBtypeset\fP [[\(+-Ulprtux] [\fB\-L\fP[\fIn\fP]] [\fB\-R\fP[\fIn\fP]] [\fB\-Z\fP[\fIn\fP]] [\fB\-i\fP[\fIn\fP]] | \fB\-f\fP [\fB\-tux\fP]] [\fIname\fP[\fB=\fP\fIvalue\fP] ...]"
2449 Display or set parameter attributes.
2450 With no \fIname\fP arguments, parameter attributes are displayed: if no options
2451 arg used, the current attributes of all parameters are printed as typeset
2452 commands; if an option is given (or \fB\-\fP with no option letter)
2453 all parameters and their values with the specified attributes are printed;
2454 if options are introduced with \fB+\fP, parameter values are not printed.
2456 If \fIname\fP arguments are given, the attributes of the named parameters
2457 are set (\fB\-\fP) or cleared (\fB+\fP).
2458 Values for parameters may optionally be specified.
2459 If typeset is used inside a function, any newly created parameters are local
2462 When \fB\-f\fP is used, typeset operates on the attributes of functions.
2463 As with parameters, if no \fIname\fPs are given, functions are listed
2464 with their values (\fIi.e.\fP, definitions) unless options are introduced with
2465 \fB+\fP, in which case only the function names are reported.
2471 Left justify attribute: \fIn\fP specifies the field width.
2472 If \fIn\fP is not specified, the current width of a parameter (or the
2473 width of its first assigned value) is used.
2474 Leading white space (and zeros, if used with the \fB\-Z\fP option) is stripped.
2475 If necessary, values are either truncated or space padded to fit the
2479 Right justify attribute: \fIn\fP specifies the field width.
2480 If \fIn\fP is not specified, the current width of a parameter (or the
2481 width of its first assigned value) is used.
2482 Trailing white space are stripped.
2483 If necessary, values are either stripped of leading characters
2484 or space padded to make them fit the field width.
2487 Zero fill attribute: if not combined with \fB\-L\fP, this is the
2488 same as \fB\-R\fP, except zero padding is used instead of space padding.
2492 \fIn\fP specifies the base to use when displaying the integer
2493 (if not specified, the base given in the first assignment is used).
2494 Parameters with this attribute may be assigned values containing
2495 arithmetic expressions.
2498 unsigned integer attribute: integers are printed as unsigned values
2499 (only useful when combined with the \fB\-i\fP option).
2500 This option is not in the original Korn shell.
2503 Function mode: display or set functions and their attributes, instead of
2507 Lower case attribute: all upper case characters in values are converted to
2509 (In the original Korn shell, this parameter meant `long integer' when used
2510 with the \fB\-i\fP option).
2513 Print complete typeset commands that can be used to re-create the
2514 attributes (but not the values) of parameters.
2515 This is the default action (option exists for ksh93 compatability).
2518 Readonly attribute: parameters with the this attribute may not be assigned to
2520 Once this attribute is set, it can not be turned off.
2523 Tag attribute: has no meaning to the shell; provided for application use.
2525 For functions, \fB\-t\fP is the trace attribute.
2526 When functions with the trace attribute are executed, the \fBxtrace\fP (\fB\-x\fP) shell option is temporarily turned on.
2529 Upper case attribute: all lower case characters in values are converted to
2531 (In the original Korn shell, this parameter meant `unsigned integer' when used
2532 with the \fB\-i\fP option, which meant upper case letters would never be used
2533 for bases greater than 10. See the \fB\-U\fP option).
2535 For functions, \fB\-u\fP is the undefined attribute. See Functions above
2536 for the implications of this.
2539 Export attribute: parameters (or functions) are placed in the environment of
2540 any executed commands. Exported functions are not implemented yet.
2544 .\"{{{ ulimit [-acdfHlmnpsStvw] [value]
2545 .IP "\fBulimit\fP [\fB\-acdfHlmnpsStvw\fP] [\fIvalue\fP]"
2546 Display or set process limits.
2547 If no options are used, the file size limit (\fB\-f\fP) is assumed.
2548 \fBvalue\fP, if specified, may be either be an arithmetic expression or the
2549 word \fBunlimited\fP.
2550 The limits affect the shell and any processes created by the shell after
2552 Note that some systems may not allow limits to be increased once they
2554 Also note that the types of limits available are system dependent \- some
2555 systems have only the \fB\-f\fP limit.
2558 Displays all limits; unless \fB\-H\fP is used, soft limits are displayed.
2560 Set the hard limit only (default is to set both hard and soft limits).
2562 Set the soft limit only (default is to set both hard and soft limits).
2564 Impose a size limit of \fIn\fP blocks on the size of core dumps.
2566 Impose a size limit of \fIn\fP kbytes on the size of the data area.
2568 Impose a size limit of \fIn\fP blocks on files written by the shell and
2569 its child processes (files of any size may be read).
2571 Impose a limit of \fIn\fP kbytes on the amount of locked (wired) physical
2574 Impose a limit of \fIn\fP kbytes on the amount of physical memory used.
2576 Impose a limit of \fIn\fP file descriptors that can be open at once.
2578 Impose a limit of \fIn\fP processes that can be run by the user at any one
2581 Impose a size limit of \fIn\fP kbytes on the size of the stack area.
2583 Impose a time limit of \fIn\fP cpu seconds to be used by each process.
2585 Impose a limit of \fIn\fP kbytes on the amount of virtual memory used;
2586 on some systems this is the maximum allowable virtual address (in bytes,
2589 Impose a limit of \fIn\fP kbytes on the amount of swap space used.
2591 As far as \fBulimit\fP is concerned, a block is 512 bytes.
2594 .\"{{{ umask [-S] [mask]
2595 .IP "\fBumask\fP [\fB\-S\fP] [\fImask\fP]"
2597 Display or set the file permission creation mask, or umask (see \fIumask\fP(2)).
2598 If the \fB\-S\fP option is used, the mask displayed or set is symbolic,
2599 otherwise it is an octal number.
2601 Symbolic masks are like those used by \fIchmod\fP(1):
2603 [\fBugoa\fP]{{\fB=+-\fP}{\fBrwx\fP}*}+[\fB,\fP...]
2605 in which the first group of characters is the \fIwho\fP part, the second
2606 group is the \fIop\fP part, and the last group is the \fIperm\fP part.
2607 The \fIwho\fP part specifies which part of the umask is to be modified.
2611 the user permissions
2613 the group permissions
2615 the other permissions (non-user, non-group)
2617 all permissions (user, group and other)
2620 The \fIop\fP part indicates how the \fIwho\fP permissions are to be modified:
2630 The \fIperm\fP part specifies which permissions are to be set, added or removed:
2640 When symbolic masks are used, they describe what permissions may
2641 be made available (as opposed to octal masks in which a set bit means
2642 the corresponding bit is to be cleared).
2643 Example: `ug=rwx,o=' sets the mask so files will not be readable, writable
2644 or executable by `others', and is equivalent (on most systems) to the octal
2648 .\"{{{ unalias [-adt] name ...
2649 .IP "\fBunalias\fP [\fB\-adt\fP] [\fIname1\fP ...]"
2650 The aliases for the given names are removed.
2651 If the \fB\-a\fP option is used, all aliases are removed.
2652 If the \fB\-t\fP or \fB\-d\fP options are used, the indicated operations
2653 are carried out on tracked or directory aliases, respectively.
2655 .\"{{{ unset [-fv] parameter ...
2656 .IP "\fBunset\fP [\fB\-fv\fP] \fIparameter\fP ..."
2657 Unset the named parameters (\fB\-v\fP, the default) or functions (\fB\-f\fP).
2658 The exit status is non-zero if any of the parameters were already unset,
2662 .IP "\fBwait\fP [\fIjob\fP]"
2663 Wait for the specified job(s) to finish.
2664 The exit status of wait is that of the last specified job:
2665 if the last job is killed by a signal, the exit status is 128 + the
2666 number of the signal (see \fBkill \-l\fP \fIexit-status\fP above); if the last
2667 specified job can't be found (because it never existed, or had already
2668 finished), the exit status of wait is 127.
2669 See Job Control below for the format of \fIjob\fP.
2670 \fBWait\fP will return if a signal for which a trap has been set is received,
2671 or if a HUP, INT or QUIT signal is received.
2673 If no jobs are specified, \fBwait\fP waits for all currently running jobs
2674 (if any) to finish and exits with a zero status.
2675 If job monitoring is enabled, the completion status of jobs is
2676 printed (this is not the case when jobs are explicitly specified).
2678 .\"{{{ whence [-pv] [name ...]
2679 .IP "\fBwhence\fP [\fB\-pv\fP] [name ...]"
2680 For each name, the type of command is listed (reserved word, built-in, alias,
2681 function, tracked alias or executable).
2682 If the \fB\-p\fP option is used, a path search done even if \fIname\fP
2683 is a reserved word, alias, \fIetc.\fP
2684 Without the \fB\-v\fP option, \fBwhence\fP is similar to \fBcommand \-v\fP
2685 except that \fBwhence\fP will find reserved words and won't print aliases
2687 with the \fB\-v\fP option, \fBwhence\fP is the same as \fBcommand \-V\fP.
2688 Note that for \fBwhence\fP, the \fB\-p\fP option does not affect the search
2689 path used, as it does for \fBcommand\fP.
2690 If the type of one or more of the names could not be determined, the
2691 exit status is non-zero.
2694 .\"{{{ job control (and its built-in commands)
2696 Job control refers to the shell's ability to monitor and control \fBjobs\fP,
2697 which are processes or groups of processes created for commands or pipelines.
2698 At a minimum, the shell keeps track of the status of the background
2699 (\fIi.e.\fP, asynchronous) jobs that currently exist; this information can be
2700 displayed using the \fBjobs\fP command.
2701 If job control is fully enabled (using \fBset \-m\fP or
2702 \fBset \-o monitor\fP), as it is for interactive shells,
2703 the processes of a job are placed in their own process group,
2704 foreground jobs can be stopped by typing the suspend character from the
2705 terminal (normally ^Z),
2706 jobs can be restarted in either the foreground
2707 or background, using the \fBfg\fP and \fBbg\fP commands, respectively,
2708 and the state of the terminal is saved or restored when a foreground
2709 job is stopped or restarted, respectively.
2711 Note that only commands that create processes (\fIe.g.\fP,
2712 asynchronous commands, subshell commands, and non-built-in,
2713 non-function commands) can be stopped; commands like \fBread\fP cannot be.
2715 When a job is created, it is assigned a job-number.
2716 For interactive shells, this number is printed inside \fB[\fP..\fB]\fP,
2717 followed by the process-ids of the processes in the job when an asynchronous
2719 A job may be referred to in \fBbg\fP, \fBfg\fP, \fBjobs\fP, \fBkill\fP and
2720 \fBwait\fP commands either by the process id of the last process in the
2721 command pipeline (as stored in the \fB$!\fP parameter) or by prefixing the
2722 job-number with a percent sign (\fB%\fP).
2723 Other percent sequences can also be used to refer to jobs:
2729 The most recently stopped job, or, if there are no stopped jobs, the oldest
2736 The job that would be the \fB%+\fP job, if the later did not exist.
2739 The job with job-number \fIn\fP.
2742 The job containing the string \fIstring\fP (an error occurs if multiple jobs
2746 The job starting with string \fIstring\fP (an error occurs if multiple jobs
2751 When a job changes state (\fIe.g.\fP, a background job finishes or foreground
2752 job is stopped), the shell prints the following status information:
2754 \fB[\fP\fInumber\fP\fB]\fP \fIflag status command\fP
2757 .IP "\ \fInumber\fP"
2758 is the job-number of the job.
2760 is \fB+\fP or \fB-\fP if the job is the \fB%+\fP or \fB%-\fP job,
2761 respectively, or space if it is neither.
2762 .IP "\ \fIstatus\fP"
2763 indicates the current state of the job and can be
2766 the job has neither stopped or exited (note that running does not
2767 necessarily mean consuming CPU time \(em the process could be blocked waiting
2769 .IP "\fBDone\fP [\fB(\fP\fInumber\fP\fB)\fP]"
2770 the job exited. \fInumber\fP is the exit status of the job, which is
2771 omitted if the status is zero.
2772 .IP "\fBStopped\fP [\fB(\fP\fIsignal\fP\fB)\fP]"
2773 the job was stopped by the indicated \fIsignal\fP (if no signal is given,
2774 the job was stopped by SIGTSTP).
2775 .IP "\fIsignal-description\fP [\fB(core dumped)\fP]"
2776 the job was killed by a signal (\fIe.g.\fP, Memory\ fault,
2777 Hangup, \fIetc.\fP \(em use
2778 \fBkill \-l\fP for a list of signal descriptions).
2779 The \fB(core\ dumped)\fP message indicates the process created a core file.
2781 .IP "\ \fIcommand\fP"
2782 is the command that created the process.
2783 If there are multiple processes in the job, then each process will
2784 have a line showing its \fIcommand\fP and possibly its \fIstatus\fP,
2785 if it is different from the status of the previous process.
2787 When an attempt is made to exit the shell while there are jobs in
2788 the stopped state, the shell warns the user that there are stopped jobs
2790 If another attempt is immediately made to exit the shell, the stopped
2791 jobs are sent a \fBHUP\fP signal and the shell exits.
2792 Similarly, if the \fBnohup\fP option is not set and there are running
2793 jobs when an attempt is made to exit a login shell, the shell warns the
2794 user and does not exit.
2795 If another attempt is immediately made to exit the shell, the running
2796 jobs are sent a \fBHUP\fP signal and the shell exits.
2798 .\"{{{ Interactive Input Line Editing
2801 .SS "Interactive Input Line Editing"
2802 The shell supports three modes of reading command lines from a tty
2803 in an interactive session.
2804 Which is used is controlled by the \fBemacs\fP, \fBgmacs\fP and \fBvi\fP
2805 \fBset\fP options (at most one of these can be set at once).
2806 If none of these options is enabled, the shell simply reads lines
2807 using the normal tty driver.
2808 If the \fBemacs\fP or \fBgmacs\fP option is set, the shell allows
2809 emacs like editing of the command; similarly, if the \fBvi\fP option
2810 is set, the shell allows vi like editing of the command.
2811 These modes are described in detail in the following sections.
2815 In these editing modes, if a line is longer that the screen width
2816 (see \fBCOLUMNS\fP parameter),
2817 a \fB>\fP, \fB+\fP or \fB<\fP character is displayed in the last column
2818 indicating that there are more characters after, before and after, or
2819 before the current position, respectively.
2820 The line is scrolled horizontally as necessary.
2822 .\"{{{ Emacs Editing Mode
2823 .SS "Emacs Editing Mode"
2824 When the \fBemacs\fP option is set, interactive input line editing is
2825 enabled. \fBWarning\fP: This mode is slightly different from the emacs
2826 mode in the original Korn shell and the 8th bit is stripped in emacs mode.
2827 In this mode various editing commands (typically bound to one or more
2828 control characters) cause immediate actions without waiting for a
2829 new-line. Several editing commands are bound to particular control
2830 characters when the shell is invoked; these bindings can be changed
2831 using the following commands:
2834 The current bindings are listed.
2836 .\"{{{ bind string=[editing-command]
2837 .IP "\fBbind\fP \fIstring\fP\fB=\fP[\fIediting-command\fP]"
2838 The specified editing command is bound to the given \fBstring\fP, which
2839 should consist of a control character (which may be written using caret
2840 notation \fB^\fP\fIX\fP), optionally preceded by one of the two prefix
2841 characters. Future input of the \fIstring\fP will cause the editing
2842 command to be immediately invoked. Note that although only two prefix
2843 characters (usually ESC and ^X) are supported, some multi-character
2844 sequences can be supported. The following binds the arrow keys on
2845 an ANSI terminal, or xterm (these are in the default bindings). Of course
2846 some escape sequences won't work out quite this nicely:
2849 \fBbind '^[['=prefix\-2
2851 bind '^XA'=up\-history
2853 bind '^XB'=down\-history
2855 bind '^XC'=forward\-char
2857 bind '^XD'=backward\-char\fP
2861 .IP "\fBbind \-l\fP"
2862 Lists the names of the functions to which keys may be bound.
2864 .\"{{{ bind -m string=[substitute]
2865 .IP "\fBbind \-m\fP \fIstring\fP\fB=\fP[\fIsubstitute\fP]"
2866 The specified input \fIstring\fP will afterwards be immediately
2867 replaced by the given \fIsubstitute\fP string, which may contain
2871 The following is a list of editing commands available.
2872 Each description starts with the name of the command,
2873 a \fIn\fP, if the command can be prefixed with a count,
2874 and any keys the command is bound to by default (written using
2875 caret notation, \fIe.g.\fP, ASCII ESC character is written as ^[).
2876 A count prefix for a command is entered using the sequence
2877 \fB^[\fP\fIn\fP, where \fIn\fP is a sequence of 1 or more digits;
2878 unless otherwise specified, if a count is omitted, it defaults to 1.
2879 Note that editing command names are
2880 used only with the \fBbind\fP command. Furthermore, many editing
2881 commands are useful only on terminals with a visible cursor. The
2882 default bindings were chosen to resemble corresponding EMACS key
2883 bindings. The users tty characters (\fIe.g.\fP, ERASE) are bound to
2884 reasonable substitutes and override the default bindings.
2886 .IP "\fBabort ^G\fP"
2887 Useful as a response to a request for a \fBsearch-history\fP pattern in
2888 order to abort the search.
2890 .\"{{{ auto-insert n
2891 .IP "\fBauto-insert\fP \fIn\fP"
2892 Simply causes the character to appear as literal input. Most ordinary
2893 characters are bound to this.
2895 .\"{{{ backward-char n ^B
2896 .IP "\fBbackward-char\fP \fIn\fP \fB^B\fP"
2897 Moves the cursor backward \fIn\fP characters.
2899 .\"{{{ backward-word n ^[B
2900 .IP "\fBbackward-word\fP \fIn\fP \fB^[B\fP"
2901 Moves the cursor backward to the beginning of a word; words consist
2902 of alphanumerics, underscore (_) and dollar ($).
2904 .\"{{{ beginning-of-history ^[<
2905 .IP "\fBbeginning-of-history ^[<\fP"
2906 Moves to the beginning of the history.
2908 .\"{{{ beginning-of-line ^A
2909 .IP "\fBbeginning-of-line ^A\fP"
2910 Moves the cursor to the beginning of the edited input line.
2912 .\"{{{ capitalize-word n ^[c, ^[C
2913 .IP "\fBcapitalize-word\fP \fIn\fP \fB^[c\fP, \fB^[C\fP"
2914 Uppercase the first character in the next \fIn\fP words,
2915 leaving the cursor past the end of the last word.
2918 If the current line does not begin with a comment character, one
2919 is added at the beginning of the line and the line is entered (as if
2920 return had been pressed), otherwise the existing comment characters
2921 are removed and the cursor is placed at the beginning of the line.
2923 .\"{{{ complete ^[^[
2924 .IP "\fBcomplete ^[^[\fP"
2925 Automatically completes as much as is unique of the command name
2926 or the file name containing the cursor. If the entire remaining command
2927 or file name is unique a space is printed after its completion, unless
2928 it is a directory name in which case \fB/\fP is appended. If there is
2929 no command or file name with the current partial word as its
2930 prefix, a bell character is output (usually causing a audio beep).
2932 .\"{{{ complete-command ^X^[
2933 .IP "\fBcomplete-command ^X^[\fP"
2934 Automatically completes as much as is unique of the command name
2935 having the partial word up to the cursor as its prefix, as in the
2936 \fBcomplete\fP command described above.
2938 .\"{{{ complete-file ^[^X
2939 .IP "\fBcomplete-file ^[^X\fP"
2940 Automatically completes as much as is unique of the file name having
2941 the partial word up to the cursor as its prefix, as in the
2942 \fBcomplete\fP command described above.
2944 .\"{{{ complete-list ^[=
2945 .IP "\fBcomplete-list ^[=\fP"
2946 List the possible completions for the current word.
2948 .\"{{{ delete-char-backward n ERASE, ^?, ^H
2949 .IP "\fBdelete-char-backward\fP \fIn\fP \fBERASE\fP, \fB^?\fP, \fB^H\fP"
2950 Deletes \fIn\fP characters before the cursor.
2952 .\"{{{ delete-char-forward n
2953 .IP "\fBdelete-char-forward\fP \fIn\fP"
2954 Deletes \fIn\fP characters after the cursor.
2956 .\"{{{ delete-word-backward n ^[ERASE, ^[^?, ^[^H, ^[h
2957 .IP "\fBdelete-word-backward\fP \fIn\fP \fB^[ERASE\fP, \fB^[^?\fP, \fB^[^H\fP, \fB^[h\fP"
2958 Deletes \fIn\fP words before the cursor.
2960 .\"{{{ delete-word-forward n ^[d
2961 .IP "\fBdelete-word-forward\fP \fIn\fP \fB^[d\fP"
2962 Deletes characters after the cursor up to the end of \fIn\fP words.
2964 .\"{{{ down-history n ^N
2965 .IP "\fBdown-history\fP \fIn\fP \fB^N\fP"
2966 Scrolls the history buffer forward \fIn\fP lines (later). Each input line
2967 originally starts just after the last entry in the history buffer, so
2968 \fBdown-history\fP is not useful until either \fBsearch-history\fP or
2969 \fBup-history\fP has been performed.
2971 .\"{{{ downcase-word n ^[L, ^[l
2972 .IP "\fBdowncase-word\fP \fIn\fP \fB^[L\fP, \fB^[l\fP"
2973 Lowercases the next \fIn\fP words.
2975 .\"{{{ end-of-history ^[>
2976 .IP "\fBend-of-history ^[>\fP"
2977 Moves to the end of the history.
2979 .\"{{{ end-of-line ^E
2980 .IP "\fBend-of-line ^E\fP"
2981 Moves the cursor to the end of the input line.
2985 Acts as an end-of-file; this is useful because edit-mode input disables
2986 normal terminal input canonicalization.
2988 .\"{{{ eot-or-delete n ^D
2989 .IP "\fBeot-or-delete\fP \fIn\fP \fB^D\fP"
2990 Acts as eot if alone on a line; otherwise acts as delete-char-forward.
2994 Error (ring the bell).
2996 .\"{{{ exchange-point-and-mark ^X^X
2997 .IP "\fBexchange-point-and-mark ^X^X\fP"
2998 Places the cursor where the mark is, and sets the mark to where the
3001 .\"{{{ expand-file ^[*
3002 .IP "\fBexpand-file ^[*\fP"
3003 Appends a * to the current word and replaces the word with
3004 the result of performing file globbing on the word.
3005 If no files match the pattern, the bell is rung.
3007 .\"{{{ forward-char n ^F
3008 .IP "\fBforward-char\fP \fIn\fP \fB^F\fP"
3009 Moves the cursor forward \fIn\fP characters.
3011 .\"{{{ forward-word n ^[f
3012 .IP "\fBforward-word\fP \fIn\fP \fB^[f\fP"
3013 Moves the cursor forward to the end of the \fIn\fPth word.
3015 .\"{{{ goto-history n ^[g
3016 .IP "\fBgoto-history\fP \fIn\fP \fB^[g\fP"
3017 Goes to history number \fIn\fP.
3019 .\"{{{ kill-line KILL
3020 .IP "\fBkill-line KILL\fP"
3021 Deletes the entire input line.
3023 .\"{{{ kill-region ^W
3024 .IP "\fBkill-region ^W\fP"
3025 Deletes the input between the cursor and the mark.
3027 .\"{{{ kill-to-eol n ^K
3028 .IP "\fBkill-to-eol\fP \fIn\fP \fB^K\fP"
3029 Deletes the input from the cursor to the end of the line if \fIn\fP is
3030 not specified, otherwise deletes characters between the cursor and
3034 .IP "\fBlist ^[?\fP"
3035 Prints a sorted, columnated list of command names or file names
3036 (if any) that can complete the partial word containing the cursor.
3037 Directory names have \fB/\fP appended to them.
3039 .\"{{{ list-command ^X?
3040 .IP "\fBlist-command ^X?\fP"
3041 Prints a sorted, columnated list of command names (if any) that
3042 can complete the partial word containing the cursor.
3044 .\"{{{ list-file ^X^Y
3045 .IP "\fBlist-file ^X^Y\fP"
3046 Prints a sorted, columnated list of file names (if any) that can
3047 complete the partial word containing the cursor. File type indicators
3048 are appended as described under \fBlist\fP above.
3050 .\"{{{ newline ^J and ^M
3051 .IP "\fBnewline ^J\fP, \fB^M\fP"
3052 Causes the current input line to be processed by the shell. The
3053 current cursor position may be anywhere on the line.
3055 .\"{{{ newline-and-next ^O
3056 .IP "\fBnewline-and-next ^O\fP"
3057 Causes the current input line to be processed by the shell, and
3058 the next line from history becomes the current line. This is
3059 only useful after an up-history or search-history.
3062 .IP "\fBno-op QUIT\fP"
3066 .IP "\fBprefix-1 ^[\fP"
3067 Introduces a 2-character command sequence.
3069 .\"{{{ prefix-2 ^X and ^[[
3070 .IP "\fBprefix-2 ^X\fP"
3071 .IP "\fBprefix-2 ^[[\fP"
3072 Introduces a 2-character command sequence.
3074 .\"{{{ prev-hist-word ^[. ^[_
3075 .IP "\fBprev-hist-word\fP \fIn\fP \fB^[.\fP, \fB^[_\fP"
3076 The last (\fIn\fPth) word of the previous command is inserted at the cursor.
3079 .IP "\fBquote ^^\fP"
3080 The following character is taken literally rather than as an editing
3084 .IP "\fBredraw ^L\fP"
3085 Reprints the prompt string and the current input line.
3087 .\"{{{ search-character-backward n ^[^]
3088 .IP "\fBsearch-character-backward\fP \fIn\fP \fB^[^]\fP"
3089 Search backward in the current line for the \fIn\fPth occurance of the
3090 next character typed.
3092 .\"{{{ search-character-forward n ^]
3093 .IP "\fBsearch-character-forward\fP \fIn\fP \fB^]\fP"
3094 Search forward in the current line for the \fIn\fPth occurance of the
3095 next character typed.
3097 .\"{{{ search-history ^R
3098 .IP "\fBsearch-history ^R\fP"
3099 Enter incremental search mode. The internal history list is searched
3100 backwards for commands matching the input. An initial \fB^\fP in the
3101 search string anchors the search. The abort key will leave search mode.
3102 Other commands will be executed after leaving search mode. Successive
3103 \fBsearch-history\fP commands continue searching backward to the next
3104 previous occurrence of the pattern. The history buffer retains only a
3105 finite number of lines; the oldest are discarded as necessary.
3107 .\"{{{ set-mark-command ^[<space>
3108 .IP "\fBset-mark-command ^[\fP<space>"
3109 Set the mark at the cursor position.
3113 On systems supporting it, pushes the bound character back onto the
3114 terminal input where it may receive special processing by the terminal
3115 handler. This is useful for the BRL \fB^T\fP mini-systat feature, for
3119 .IP "\fBstuff-reset\fP"
3120 Acts like \fBstuff\fP, then aborts input the same as an interrupt.
3122 .\"{{{ transport-chars ^T
3123 .IP "\fBtranspose-chars ^T\fP"
3124 If at the end of line, or if the \fBgmacs\fP option is set,
3125 this exchanges the two previous characters; otherwise, it
3126 exchanges the previous and current characters and moves the cursor
3127 one character to the right.
3129 .\"{{{ up-history n ^P
3130 .IP "\fBup-history\fP \fIn\fP \fB^P\fP"
3131 Scrolls the history buffer backward \fIn\fP lines (earlier).
3133 .\"{{{ upcase-word n ^[U, ^[u
3134 .IP "\fBupcase-word\fP \fIn\fP \fB^[U\fP, \fB^[u\fP"
3135 Uppercases the next \fIn\fP words.
3138 .IP "\fBversion ^V\fP"
3139 Display the version of ksh. The current edit buffer is restored as soon
3140 as any key is pressed (the key is then processed, unless it is a space).
3144 Inserts the most recently killed text string at the current cursor position.
3147 .IP "\fByank-pop ^[y\fP"
3148 Immediately after a \fByank\fP, replaces the inserted text string with
3149 the next previous killed text string.
3152 .\"{{{ Vi Editing Mode
3154 .SS "Vi Editing Mode"
3155 The vi command line editor in ksh has basically the same commands as the
3156 vi editor (see \fIvi\fP(1)), with the following exceptions:
3159 you start out in insert mode,
3161 there are file name and command completion commands
3162 (\fB=\fP, \fB\e\fP, \fB*\fP, \fB^X\fP, \fB^E\fP, \fB^F\fP and,
3163 optionally, \fB<tab>\fP),
3165 the \fB_\fP command is different (in ksh it is the last argument command,
3166 in vi it goes to the start of the current line),
3168 the \fB/\fP and \fBG\fP commands move in the opposite direction as the \fBj\fP
3171 and commands which don't make sense in a single line editor are not available
3172 (\fIe.g.\fP, screen movement commands, ex \fB:\fP commands, \fIetc.\fP).
3175 Note that the \fB^X\fP stands for control-X; also \fB<esc>\fP, \fB<space>\fP
3176 and \fB<tab>\fP are used for escape, space and tab, respectively (no kidding).
3180 Like vi, there are two modes: insert mode and command mode.
3181 In insert mode, most characters are simply put in the buffer at the
3182 current cursor position as they are typed, however, some characters
3183 are treated specially.
3184 In particular, the following characters are taken from current tty settings
3185 (see \fIstty\fP(1)) and have their usual meaning (normal values are in
3187 kill (\fB^U\fP), erase (\fB^?\fP), werase (\fB^W\fP), eof (\fB^D\fP),
3188 intr (\fB^C\fP) and quit (\fB^\e\fP).
3189 In addition to the above, the following characters are also treated
3190 specially in insert mode:
3195 erases previous character
3198 literal next: the next character typed is not treated specially (can be
3199 used to insert the characters being described here)
3202 end of line: the current line is read, parsed and executed by the shell
3205 puts the editor in command mode (see below)
3208 command and file name enumeration (see below)
3211 command and file name completion (see below).
3212 If used twice in a row, the list of possible completions is displayed;
3213 if used a third time, the completion is undone.
3216 command and file name expansion (see below)
3219 optional file name and command completion (see \fB^F\fP above), enabled with
3220 \fBset \-o vi-tabcomplete\fP
3226 In command mode, each character is interpreted as a command.
3227 Characters that don't correspond to commands, are illegal combinations of
3228 commands or are commands that can't be carried out all cause beeps.
3229 In the following command descriptions, a \fIn\fP indicates the
3230 command may be prefixed by a number (\fIe.g.\fP, \fB10l\fP moves right 10
3231 characters); if no number prefix is used, \fIn\fP is assumed to be 1
3232 unless otherwise specified.
3233 The term `current position' refers to the position between the cursor
3234 and the character preceding the cursor.
3235 A `word' is a sequence of letters, digits and underscore characters or a
3236 sequence of non-letter, non-digit, non-underscore, non-white-space characters
3237 (\fIe.g.\fP, ab2*&^ contains two words) and a `big-word' is a sequence of
3238 non-white-space characters.
3239 .\"{{{ Special ksh vi commands
3240 .IP "Special ksh vi commands"
3241 The following commands are not in, or are different from, the normal vi file
3244 .IP "\fIn\fP\fB_\fP"
3245 insert a space followed by the \fIn\fPth big-word from the last command in the
3246 history at the current position and enter insert mode; if \fIn\fP is not
3247 specified, the last word is inserted.
3249 insert the comment character (\fB#\fP) at the start of the current line and
3250 return the line to the shell (equivalent to \fBI#^J\fP).
3251 .IP "\fIn\fP\fBg\fP"
3252 like \fBG\fP, except if \fIn\fP is not specified, it goes to the most recent
3254 .IP "\fIn\fP\fBv\fP"
3255 edit line \fIn\fP using the vi editor;
3256 if \fIn\fP is not specified, the current line is edited.
3257 The actual command executed is
3258 `\fBfc \-e ${VISUAL:-${EDITOR:-vi}}\fP \fIn\fP'.
3259 .IP "\fB*\fP and \fB^X\fP"
3260 command or file name expansion is applied to the current big-word
3261 (with an appended *, if the word contains no file globing characters) - the
3262 big-word is replaced with the resulting words.
3263 If the current big-word is the first on the line (or follows one
3264 of the following characters: \fB;\fP, \fB|\fP, \fB&\fP, \fB(\fP, \fB)\fP)
3265 and does not contain a slash (\fB/\fP) then command expansion is done,
3266 otherwise file name expansion is done.
3267 Command expansion will match the big-word against all aliases, functions
3268 and built-in commands as well as any executable files found by searching
3269 the directories in the \fBPATH\fP parameter.
3270 File name expansion matches the big-word against the files in the
3272 After expansion, the cursor is placed just past the last word and the editor
3274 .IP "\fIn\fP\fB\e\fP, \fIn\fP\fB^F\fP, \fIn\fP\fB<tab>\fP and \fIn\fP\fB<esc>\fP"
3275 command/file name completion:
3276 replace the current big-word with the longest unique
3277 match obtained after performing command/file name expansion.
3278 \fB<tab>\fP is only recognized if the \fBvi-tabcomplete\fP option is set,
3279 while \fB<esc>\fP is only recognized if the \fBvi-esccomplete\fP option
3280 is set (see \fBset \-o\fP).
3281 If \fIn\fP is specified, the \fIn\fPth possible
3282 completion is selected (as reported by the command/file name enumeration
3284 .IP "\fB=\fP and \fB^E\fP"
3285 command/file name enumeration: list all the commands or files that match
3286 the current big-word.
3288 display the version of pdksh; it is displayed until another key is pressed
3289 (this key is ignored).
3290 .IP "\fB@\fP\fIc\fP"
3291 macro expansion: execute the commands found in the alias _\fIc\fP.
3294 .\"{{{ Intra-line movement commands
3295 .IP "Intra-line movement commands"
3297 .IP "\fIn\fP\fBh\fP and \fIn\fP\fB^H\fP"
3298 move left \fIn\fP characters.
3299 .IP "\fIn\fP\fBl\fP and \fIn\fP\fB<space>\fP"
3300 move right \fIn\fP characters.
3304 move to the first non white-space character.
3305 .IP "\fIn\fP\fB|\fP"
3306 move to column \fIn\fP.
3308 move to the last character.
3309 .IP "\fIn\fP\fBb\fP"
3310 move back \fIn\fP words.
3311 .IP "\fIn\fP\fBB\fP"
3312 move back \fIn\fP big-words.
3313 .IP "\fIn\fP\fBe\fP"
3314 move forward to the end the word, \fIn\fP times.
3315 .IP "\fIn\fP\fBE\fP"
3316 move forward to the end the big-word, \fIn\fP times.
3317 .IP "\fIn\fP\fBw\fP"
3318 move forward \fIn\fP words.
3319 .IP "\fIn\fP\fBW\fP"
3320 move forward \fIn\fP big-words.
3322 find match: the editor looks forward for the nearest parenthesis,
3323 bracket or brace and then moves the to the matching parenthesis, bracket or
3325 .IP "\fIn\fP\fBf\fP\fIc\fP"
3326 move forward to the \fIn\fPth occurrence of the character \fIc\fP.
3327 .IP "\fIn\fP\fBF\fP\fIc\fP"
3328 move backward to the \fIn\fPth occurrence of the character \fIc\fP.
3329 .IP "\fIn\fP\fBt\fP\fIc\fP"
3330 move forward to just before the \fIn\fPth occurrence of the character \fIc\fP.
3331 .IP "\fIn\fP\fBT\fP\fIc\fP"
3332 move backward to just before the \fIn\fPth occurrence of the character \fIc\fP.
3333 .IP "\fIn\fP\fB;\fP"
3334 repeats the last \fBf\fP, \fBF\fP, \fBt\fP or \fBT\fP command.
3335 .IP "\fIn\fP\fB,\fP"
3336 repeats the last \fBf\fP, \fBF\fP, \fBt\fP or \fBT\fP command, but moves
3337 in the opposite direction.
3340 .\"{{{ Inter-line movement commands
3341 .IP "Inter-line movement commands"
3343 .IP "\fIn\fP\fBj\fP and \fIn\fP\fB+\fP and \fIn\fP\fB^N\fP"
3344 move to the \fIn\fPth next line in the history.
3345 .IP "\fIn\fP\fBk\fP and \fIn\fP\fB-\fP and \fIn\fP\fB^P\fP"
3346 move to the \fIn\fPth previous line in the history.
3347 .IP "\fIn\fP\fBG\fP"
3348 move to line \fIn\fP in the history; if \fIn\fP is not specified, the
3349 number first remembered line is used.
3350 .IP "\fIn\fP\fBg\fP"
3351 like \fBG\fP, except if \fIn\fP is not specified, it goes to the most recent
3353 .IP "\fIn\fP\fB/\fP\fIstring\fP"
3354 search backward through the history for the \fIn\fPth line containing
3355 \fIstring\fP; if \fIstring\fP starts with \fB^\fP, the remainder of the
3356 string must appear at the start of the history line for it to match.
3357 .IP "\fIn\fP\fB?\fP\fIstring\fP"
3358 same as \fB/\fP, except it searches forward through the history.
3359 .IP "\fIn\fP\fBn\fP"
3360 search for the \fIn\fPth occurrence of the last search string; the
3361 direction of the search is the same as the last search.
3362 .IP "\fIn\fP\fBN\fP"
3363 search for the \fIn\fPth occurrence of the last search string; the
3364 direction of the search is the opposite of the last search.
3367 .\"{{{ Edit commands
3370 .IP "\fIn\fP\fBa\fP"
3371 append text \fIn\fP times: goes into insert mode just after the current
3373 The append is only replicated if command mode is re-entered (\fIi.e.\fP,
3375 .IP "\fIn\fP\fBA\fP"
3376 same as \fBa\fP, except it appends at the end of the line.
3377 .IP "\fIn\fP\fBi\fP"
3378 insert text \fIn\fP times: goes into insert mode at the current
3380 The insertion is only replicated if command mode is re-entered (\fIi.e.\fP,
3382 .IP "\fIn\fP\fBI\fP"
3383 same as \fBi\fP, except the insertion is done just before the first non-blank
3385 .IP "\fIn\fP\fBs\fP"
3386 substitute the next \fIn\fP characters (\fIi.e.\fP, delete the characters
3387 and go into insert mode).
3389 substitute whole line: all characters from the first non-blank character
3390 to the end of line are deleted and insert mode is entered.
3391 .IP "\fIn\fP\fBc\fP\fImove-cmd\fP"
3392 change from the current position to the position resulting from \fIn\fP
3393 \fImove-cmd\fPs (\fIi.e.\fP, delete the indicated region and go into insert
3395 if \fImove-cmd\fP is \fBc\fP, the line starting from the first non-blank
3396 character is changed.
3398 change from the current position to the end of the line (\fIi.e.\fP, delete to
3399 the end of the line and go into insert mode).
3400 .IP "\fIn\fP\fBx\fP"
3401 delete the next \fIn\fP characters.
3402 .IP "\fIn\fP\fBX\fP"
3403 delete the previous \fIn\fP characters.
3405 delete to the end of the line.
3406 .IP "\fIn\fP\fBd\fP\fImove-cmd\fP"
3407 delete from the current position to the position resulting from
3408 \fIn\fP \fImove-cmd\fPs;
3409 \fImove-cmd\fP is a movement command (see above) or \fBd\fP, in which case
3410 the current line is deleted.
3411 .IP "\fIn\fP\fBr\fP\fIc\fP"
3412 replace the next \fIn\fP characters with the character \fIc\fP.
3413 .IP "\fIn\fP\fBR\fP"
3414 replace: enter insert mode but overwrite existing characters instead of
3415 inserting before existing characters. The replacement is repeated \fIn\fP
3417 .IP "\fIn\fP\fB~\fP"
3418 change the case of the next \fIn\fP characters.
3419 .IP "\fIn\fP\fBy\fP\fImove-cmd\fP"
3420 yank from the current position to the position resulting from \fIn\fP
3421 \fImove-cmd\fPs into the yank buffer; if \fImove-cmd\fP is \fBy\fP, the
3422 whole line is yanked.
3424 yank from the current position to the end of the line.
3425 .IP "\fIn\fP\fBp\fP"
3426 paste the contents of the yank buffer just after the current position,
3428 .IP "\fIn\fP\fBP\fP"
3429 same as \fBp\fP, except the buffer is pasted at the current position.
3432 .\"{{{ Miscellaneous vi commands
3433 .IP "Miscellaneous vi commands"
3435 .IP "\fB^J\fP and \fB^M\fP"
3436 the current line is read, parsed and executed by the shell.
3437 .IP "\fB^L\fP and \fB^R\fP"
3438 redraw the current line.
3439 .IP "\fIn\fP\fB.\fP"
3440 redo the last edit command \fIn\fP times.
3442 undo the last edit command.
3444 undo all changes that have been made to the current line.
3445 .IP "\fIintr\fP and \fIquit\fP"
3446 the interrupt and quit terminal characters cause the current line to
3447 be deleted and a new prompt to be printed.
3449 .\"Has all vi commands except:
3450 .\" movement: { } [[ ]] ^E ^Y ^U ^D ^F ^B H L M ()
3451 .\" tag commands: ^T ^]
3452 .\" mark commands: m ` '
3453 .\" named-buffer commands: " @
3454 .\" file/shell/ex-commands: Q ZZ ^^ : ! &
3455 .\" multi-line change commands: o O J
3456 .\" shift commands: << >>
3457 .\" status command: ^G
3474 Any bugs in pdksh should be reported to pdksh@cs.mun.ca. Please
3475 include the version of pdksh (echo $KSH_VERSION shows it), the machine,
3476 operating system and compiler you are using and a description of how to
3477 repeat the bug (a small shell script that demonstrates the bug is
3478 best). The following, if relevant (if you are not sure, include them),
3479 can also helpful: options you are using (both options.h options and set
3480 \-o options) and a copy of your config.h (the file generated by the
3481 configure script). New versions of pdksh can be obtained from
3482 ftp://ftp.cs.mun.ca/pub/pdksh/.
3484 BTW, the most frequently reported bug is
3486 \fB echo hi | read a; echo $a\fP\ \ \ # Does not print hi
3488 I'm aware of this and there is no need to report it.
3492 This page documents version
3494 @(#)PD KSH v5.2.14 99/07/13.2
3495 of the public domain korn shell.
3499 This shell is based on the public domain 7th edition Bourne shell clone by
3500 Charles Forsyth and parts of the BRL shell by Doug A.\& Gwyn, Doug Kingston,
3501 Ron Natalie, Arnold Robbins, Lou Salkind and others. The first release
3502 of pdksh was created by Eric Gisin, and it was subsequently maintained by
3503 John R.\& MacMillan (chance!john@sq.sq.com), and
3504 Simon J.\& Gerraty (sjg@zen.void.oz.au). The current maintainer is
3505 Michael Rendell (michael@cs.mun.ca).
3506 The CONTRIBUTORS file in the source distribution contains a more complete
3507 list of people and their part in the shell's development.
3518 csh(1), ed(1), getconf(1), getopt(1), sed(1), stty(1), vi(1),
3519 dup(2), execve(2), getgid(2), getuid(2), open(2), pipe(2), wait(2),
3520 getopt(3), rand(3), signal(3), system(3),
3523 .IR "The KornShell Command and Programming Language" ,
3524 Morris Bolsky and David Korn, 1989, ISBN 0-13-516972-0.
3526 .\" XXX ISBN missing
3527 .IR "UNIX Shell Programming" ,
3528 Stephen G.\& Kochan, Patrick H.\& Wood, Hayden.
3530 .IR "IEEE Standard for information Technology \- Portable Operating System Interface (POSIX) \- Part 2: Shell and Utilities" ,
3531 IEEE Inc, 1993, ISBN 1-55937-255-9.