Do not use .Xo/.Xc to work around ancient roff limits.
[netbsd-mini2440.git] / bin / ksh / ksh.Man
blob85794de108d17be34aa29721482cd56869476053
1 '\" t
2 .\" $NetBSD: ksh.Man,v 1.21 2008/10/27 19:52:28 apb Exp $
3 .\"{{{}}}
4 .\"{{{  Notes about man page
5 .\"     - use the pseudo-macros .sh( and .sh) to begin and end sh-specific
6 .\"       text and .ksh( and .ksh) for ksh specific text.
7 .\"     - put i.e., e.g. and etc. in italics
8 .\"}}}
9 .\"{{{  To do
10 .\" todo: Things not covered that should be:
11 .\"     - distinguish (POSIX) special built-in's, (POSIX) regular built-in's,
12 .\"       and sh/ksh weirdo built-in's (put S,R,X superscripts after command
13 .\"       name in built-in commands section?)
14 .\"     - need to be consistent about notation for `See section-name', `
15 .\"       See description of foobar command', `See section section-name', etc.
16 .\"     - need to use the term `external command' meaning `a command that is
17 .\"       executed using execve(2)' (as opposed to a built-in command or
18 .\"       function) for more clear description.
19 .\"}}}
20 .\"{{{  Title
21 .ksh(
22 .TH KSH 1 "August 19, 1996" "" "User commands"
23 .ksh)
24 .sh(
25 .TH SH 1 "August 19, 1996" "" "User commands"
26 .sh)
27 .\"}}}
28 .\"{{{  Name
29 .SH NAME
30 .ksh(
31 ksh \- Public domain Korn shell
32 .ksh)
33 .sh(
34 sh \- Public domain Bourne shell
35 .sh)
36 .\"}}}
37 .\"{{{  Synopsis
38 .SH SYNOPSIS
39 .ad l
40 .ksh(
41 \fBksh\fP
42 .ksh)
43 .sh(
44 \fBsh\fP
45 .sh)
46 [\fB\(+-abCefhikmnprsuvxX\fP] [\fB\(+-o\fP \fIoption\fP] [ [ \fB\-c\fP \fIcommand-string\fP [\fIcommand-name\fP] | \fB\-s\fP | \fIfile\fP ] [\fIargument\fP ...] ]
47 .ad b
48 .\"}}}
49 .\"{{{  Description
50 .SH DESCRIPTION
51 .ksh(
52 \fBksh\fP is a command interpreter that is intended for both
53 interactive and shell script use.
54 Its command language is a superset of the \fIsh\fP(1) shell language.
55 .ksh)
56 .sh(
57 \fBsh\fP is a re-implementation of the Bourne shell, a command
58 interpreter for both interactive and script use.
59 .sh)
60 .\"{{{  Shell Startup
61 .SS "Shell Startup"
62 The following options can be specified only on the command line:
63 .IP "\fB\-c\fP \fIcommand-string\fP"
64 the shell executes the command(s) contained in \fIcommand-string\fP
65 .IP \fB\-i\fP
66 interactive mode \(em see below
67 .IP \fB\-l\fP
68 login shell \(em see below
69 interactive mode \(em see below
70 .IP \fB\-s\fP
71 the shell reads commands from standard input; all non-option arguments
72 are positional parameters
73 .IP \fB\-r\fP
74 restricted mode \(em see below
75 .PP
76 In addition to the above, the options described in the \fBset\fP built-in
77 command can also be used on the command line.
78 .PP
79 If neither the \fB\-c\fP nor the \fB\-s\fP options are specified, the
80 first non-option argument specifies the name of a file the shell reads
81 commands from; if there are no non-option arguments, the shell reads
82 commands from standard input.
83 The name of the shell (\fIi.e.\fP, the contents of the \fB$0\fP) parameter
84 is determined as follows: if the \fB\-c\fP option is used and there is
85 a non-option argument, it is used as the name; if commands are being
86 read from a file, the file is used as the name; otherwise the name
87 the shell was called with (\fIi.e.\fP, argv[0]) is used.
88 .PP
89 A shell is \fBinteractive\fP if the \fB\-i\fP option is used or
90 if both standard input and standard error are attached to a tty.
91 An interactive shell has job control enabled (if available),
92 ignores the INT, QUIT and TERM signals, and prints prompts before
93 reading input (see \fBPS1\fP and \fBPS2\fP parameters).
94 For non-interactive shells, the \fBtrackall\fP option is on by default
95 (see \fBset\fP command below).
96 .PP
97 A shell is \fBrestricted\fP if the \fB\-r\fP option is used or if either
98 the basename of the name the shell is invoked with or the \fBSHELL\fP
99 parameter match the pattern *r*sh (\fIe.g.\fP, rsh, rksh, rpdksh, \fIetc.\fP).
100 The following restrictions come into effect after the shell processes
101 any profile and \fB$ENV\fP files:
102 .nr P2 \n(PD
103 .nr PD 0
104 .IP \ \ \(bu
105 the \fBcd\fP command is disabled
106 .IP \ \ \(bu
107 the \fBSHELL\fP, \fBENV\fP and \fBPATH\fP parameters can't be changed
108 .IP \ \ \(bu
109 command names can't be specified with absolute or relative paths
110 .IP \ \ \(bu
111 the \fB\-p\fP option of the \fBcommand\fP built-in can't be used
112 .IP \ \ \(bu
113 redirections that create files can't be used (\fIi.e.\fP, \fB>\fP,
114 \fB>|\fP, \fB>>\fP, \fB<>\fP)
115 .nr PD \n(P2
117 A shell is \fBprivileged\fP if the \fB\-p\fP option is used or if
118 the real user-id or group-id does not match the effective user-id
119 or group-id (see \fIgetuid\fP(2), \fIgetgid\fP(2)).
120 A privileged shell does not process $HOME/.profile nor the \fBENV\fP
121 parameter (see below), instead the file /etc/suid_profile is processed.
122 Clearing the privileged option causes the shell to set its effective
123 user-id (group-id) to its real user-id (group-id).
125 If the basename of the name the shell is called with (\fIi.e.\fP, argv[0])
126 starts with \fB\-\fP or if the \fB\-l\fP option is used, the shell is assumed
127 to be a login shell and the shell reads and executes the contents of
128 \fB/etc/profile\fP, \fB$HOME/.profile\fP and \fB$ENV\fP if they exist and are
129 readable.
131 If the \fBENV\fP parameter is set when the shell starts (or, in the
132 case of login shells, after any profiles are processed), its value
133 is subjected to parameter, command, arithmetic and tilde substitution and
134 the resulting file (if any) is read and executed.
135 If the \fBENV\fP parameter is not set (and not null) the file \fB$HOME/.kshrc\fP 
136 is included (after the above mentioned substitutions have been performed).
138 The exit status of the shell is 127 if the command file specified
139 on the command line could not be opened, or non-zero if a fatal syntax
140 error occurred during the execution of a script.
141 In the absence of fatal errors, the exit status is that of the last
142 command executed, or zero, if no command is executed.
143 .\"}}}
144 .\"{{{  Command Syntax
145 .SS "Command Syntax"
146 .\"{{{  words and tokens
147 The shell begins parsing its input by breaking it into \fIword\fPs.
148 Words, which are sequences of characters, are delimited by unquoted
149 \fIwhite-space\fP characters (space, tab and newline) or \fImeta-characters\fP
150 (\fB<\fP, \fB>\fP, \fB|\fP, \fB;\fP, \fB&\fP, \fB(\fP and \fB)\fP).
151 Aside from delimiting words, spaces and tabs are ignored, while
152 newlines usually delimit commands.
153 The meta-characters are used in building the following tokens:
154 \fB<\fP, \fB<&\fP, \fB<<\fP, \fB>\fP, \fB>&\fP, \fB>>\fP, \fIetc.\fP are
155 used to specify redirections (see Input/Output Redirection below);
156 \fB|\fP is used to create pipelines;
157 .ksh(
158 \fB|&\fP is used to create co-processes (see Co-Processes below);
159 .ksh)
160 \fB;\fP is used to separate commands;
161 \fB&\fP is used to create asynchronous pipelines;
162 \fB&&\fP and \fB||\fP are used to specify conditional execution;
163 \fB;;\fP is used in \fBcase\fP statements;
164 .ksh(
165 \fB((\fP .. \fB))\fP are used in arithmetic expressions;
166 .ksh)
167 and lastly,
168 \fB(\fP .. \fB)\fP are used to create subshells.
170 White-space and meta-characters can be quoted individually using
171 backslash (\fB\e\fP), or in groups using double (\fB"\fP) or single (\fB'\fP)
172 quotes.
173 Note that the following characters are also treated specially by the shell and
174 must be quoted if they are to represent themselves:
175 \fB\e\fP, \fB"\fP, \fB'\fP, \fB#\fP, \fB$\fP, \fB`\fP, \fB~\fP, \fB{\fP,
176 \fB}\fP, \fB*\fP, \fB?\fP and \fB[\fP.
177 The first three of these are the above mentioned quoting characters
178 (see Quoting below);
179 \fB#\fP, if used at the beginning of a word, introduces a comment \(em everything
180 after the \fB#\fP up to the nearest newline is ignored;
181 \fB$\fP is used to introduce parameter, command and arithmetic substitutions
182 (see Substitution below);
183 \fB`\fP introduces an old-style command substitution
184 (see Substitution below);
185 \fB~\fP begins a directory expansion (see Tilde Expansion below);
186 \fB{\fP and \fB}\fP delimit \fIcsh\fP(1) style alternations
187 (see Brace Expansion below);
188 and, finally, \fB*\fP, \fB?\fP and \fB[\fP are used in file name generation
189 (see File Name Patterns below).
190 .\"}}}
191 .\"{{{  simple-command
193 As words and tokens are parsed, the shell builds commands, of which
194 there are two basic types: \fIsimple-commands\fP, typically programs
195 that are executed, and \fIcompound-commands\fP, such as \fBfor\fP and
196 \fBif\fP statements, grouping constructs and function definitions.
198 A simple-command consists of some combination of parameter assignments (see
199 Parameters below), input/output redirections (see Input/Output Redirections
200 below), and command words; the only restriction is that parameter assignments
201 come before any command words.
202 The command words, if any, define the command that is to be executed and its
203 arguments.
204 The command may be a shell built-in command, a function or an \fIexternal
205 command\fP, \fIi.e.\fP, a separate executable file that is located using the
206 \fBPATH\fP parameter (see Command Execution below).
207 Note that all command constructs have an \fIexit status\fP: for external
208 commands, this is related to the status returned by \fIwait\fP(2) (if the
209 command could not be found, the exit status is 127, if it could not be
210 executed, the exit status is 126);
211 the exit status of other command constructs (built-in commands, functions,
212 compound-commands, pipelines, lists, \fIetc.\fP) are all well defined and are
213 described where the construct is described.
214 The exit status of a command consisting only of parameter assignments is that
215 of the last command substitution performed during the parameter assignment
216 or zero if there were no command substitutions.
217 .\"}}}
218 .\"{{{  pipeline
220 Commands can be chained together using the \fB|\fP token to
221 form \fIpipelines\fP, in which the standard output of each command but
222 the last is piped (see \fIpipe\fP(2)) to the standard input of the following
223 command.
224 The exit status of a pipeline is that of its last command.
225 A pipeline may be prefixed by the \fB!\fP reserved word which
226 causes the exit status of the pipeline to be logically
227 complemented: if the original status was 0 the complemented status will
228 be 1, and if the original status was not 0, then the complemented
229 status will be 0.
230 .\"}}}
231 .\"{{{  lists
233 \fILists\fP of commands can be created by separating pipelines by
234 any of the following tokens: \fB&&\fP, \fB||\fP, \fB&\fP, \fB|&\fP and \fB;\fP.
235 The first two are for conditional execution: \fIcmd1\fP \fB&&\fP \fIcmd2\fP
236 executes \fIcmd2\fP only if the exit status of \fIcmd1\fP is zero;
237 \fB||\fP is the opposite \(em \fIcmd2\fP is executed only if the exit status
238 of \fIcmd1\fP is non-zero.
239 \fB&&\fP and \fB||\fP have equal precedence which is higher than that of
240 \fB&\fP, \fB|&\fP and \fB;\fP, which also have equal precedence.
241 The \fB&\fP token causes the preceding command to be executed asynchronously,
242 that is, the shell starts the command, but does not wait for it to complete
243 (the shell does keep track of the status of asynchronous commands \(em see
244 Job Control below).
245 When an asynchronous command is started when job control is disabled
246 (\fIi.e.\fP, in most scripts), the command is started with signals INT
247 and QUIT ignored and with input redirected from /dev/null
248 (however, redirections specified in the asynchronous command have precedence).
249 .ksh(
250 The \fB|&\fP operator starts a \fIco-process\fP which is special kind of
251 asynchronous process (see Co-Processes below).
252 .ksh)
253 Note that a command must follow the \fB&&\fP and \fB||\fP operators, while
254 a command need not follow \fB&\fP, \fB|&\fP and \fB;\fP.
255 The exit status of a list is that of the last command executed, with the
256 exception of asynchronous lists, for which the exit status is 0.
257 .\"}}}
258 .\"{{{  compound-commands
260 Compound commands are created using the following reserved words \(em these
261 words are only recognized if they are unquoted and if they are used as
262 the first word of a command (\fIi.e.\fP, they can't be preceded by parameter
263 assignments or redirections):
265 center;
266 lfB lfB lfB lfB lfB .
267 case    else    function        then    !
268 do      esac    if      time    [[
269 done    fi      in      until   {
270 elif    for     select  while   }
272 \fBNote:\fP Some shells (but not this one) execute control structure commands
273 in a subshell when one or more of their file descriptors are redirected, so
274 any environment changes inside them may fail.
275 To be portable, the \fBexec\fP statement should be used instead to redirect
276 file descriptors before the control structure.
278 In the following compound command descriptions, command lists (denoted as
279 \fIlist\fP) that are followed by reserved words must end with a
280 semi-colon, a newline or a (syntactically correct) reserved word.
281 For example,
283 \fB{ echo foo; echo bar; }\fP
285 \fB{ echo foo; echo bar<newline>}\fP
287 \fB{ { echo foo; echo bar; } }\fP
289 are all valid, but
291 \fB{ echo foo; echo bar }\fP
293 is not.
294 .\"{{{  ( list )
295 .IP "\fB(\fP \fIlist\fP \fB)\fP"
296 Execute \fIlist\fP in a subshell.
297 There is no implicit way to pass
298 environment changes from a subshell back to its parent.
299 .\"}}}
300 .\"{{{  { list }
301 .IP "\fB{\fP \fIlist\fP \fB}\fP"
302 Compound construct; \fIlist\fP is executed, but not in a subshell.
303 Note that \fB{\fP and \fB}\fP are reserved words, not meta-characters.
304 .\"}}}
305 .\"{{{  case word in [ [ ( ] pattern [ | pattern ] ... ) list ;; ] ... esac
306 .IP "\fBcase\fP \fIword\fP \fBin\fP [ [\fB(\fP] \fIpattern\fP [\fB|\fP \fIpattern\fP] ... \fB)\fP \fIlist\fP \fB;;\fP ] ... \fBesac\fP"
307 The \fBcase\fP statement attempts to match \fIword\fP against the specified
308 \fIpattern\fPs; the \fIlist\fP associated with the first successfully matched
309 pattern is executed.
310 Patterns used in \fBcase\fP statements are the same as
311 those used for file name patterns except that the restrictions regarding
312 \fB\&.\fP and \fB/\fP are dropped.
313 Note that any unquoted space before and
314 after a pattern is stripped; any space with a pattern must be quoted.
315 Both the word and the patterns are subject to parameter, command, and
316 arithmetic substitution as well as tilde substitution.
317 For historical reasons, open and close braces may be used instead
318 of \fBin\fP and \fBesac\fP (\fIe.g.\fP, \fBcase $foo { *) echo bar; }\fP).
319 The exit status of a \fBcase\fP statement is that of the executed \fIlist\fP;
320 if no \fIlist\fP is executed, the exit status is zero.
321 .\"}}}
322 .\"{{{  for name [ in word ... term ] do list done
323 .IP "\fBfor\fP \fIname\fP [ \fBin\fP \fIword\fP ... \fIterm\fP ] \fBdo\fP \fIlist\fP \fBdone\fP"
324 where \fIterm\fP is either a newline or a \fB;\fP.
325 For each \fIword\fP in the specified word list, the parameter \fIname\fP is
326 set to the word and \fIlist\fP is executed.
327 If \fBin\fP is not used to
328 specify a word list, the positional parameters (\fB"$1"\fP, \fB"$2"\fP,
329 \fIetc.\fP) are used instead.
330 For historical reasons, open and close braces may be used instead
331 of \fBdo\fP and \fBdone\fP (\fIe.g.\fP, \fBfor i; { echo $i; }\fP).
332 The exit status of a \fBfor\fP statement is the last exit status
333 of \fIlist\fP; if \fIlist\fP is never executed, the exit status is zero.
334 .\"}}}
335 .\"{{{  if list then list [ elif list then list ] ... [ else list ] fi
336 .IP "\fBif\fP \fIlist\fP \fBthen\fP \fIlist\fP [\fBelif\fP \fIlist\fP \fBthen\fP \fIlist\fP] ... [\fBelse\fP \fIlist\fP] \fBfi\fP"
337 If the exit status of the first \fIlist\fP is zero, the second \fIlist\fP
338 is executed; otherwise the \fIlist\fP following the \fBelif\fP, if any, is
339 executed with similar consequences.
340 If all the lists following the \fBif\fP
341 and \fBelif\fPs fail (\fIi.e.\fP, exit with non-zero status), the \fIlist\fP
342 following the \fBelse\fP is executed.
343 The exit status of an \fBif\fP statement is that
344 of non-conditional \fIlist\fP that is executed; if no non-conditional
345 \fIlist\fP is executed, the exit status is zero.
346 .\"}}}
347 .\"{{{  select name [ in word ... ] do list done
348 .ksh(
349 .IP "\fBselect\fP \fIname\fP [ \fBin\fP \fIword\fP ... \fIterm\fP ] \fBdo\fP \fIlist\fP \fBdone\fP"
350 where \fIterm\fP is either a newline or a \fB;\fP.
351 The \fBselect\fP statement provides an automatic method of presenting
352 the user with a menu and selecting from it.
353 An enumerated list of the specified \fIwords\fP is printed on standard
354 error, followed by a prompt (\fBPS3\fP, normally `\fB#? \fP').
355 A number corresponding to one of the enumerated words is then read
356 from standard input, \fIname\fP is set to the selected word (or is
357 unset if the selection is not valid), \fBREPLY\fP
358 is set to what was read (leading/trailing space is stripped),
359 and \fIlist\fP is executed.
360 If a blank line (\fIi.e.\fP, zero or more \fBIFS\fP characters) is entered,
361 the menu is re-printed without executing \fIlist\fP.
362 When \fIlist\fP completes, the enumerated list is printed if \fBREPLY\fP
363 is null, the prompt is printed and so on.
364 This process is continues until an end-of-file is read, an interrupt is
365 received or a break statement is executed inside the loop.
366 If \fBin\fP \fIword\fP \fB\&...\fP is omitted, the positional parameters
367 are used (\fIi.e.\fP, \fB"$1"\fP, \fB"$2"\fP, \fIetc.\fP).
368 For historical reasons, open and close braces may be used instead
369 of \fBdo\fP and \fBdone\fP (\fIe.g.\fP, \fBselect i; { echo $i; }\fP).
370 The exit status of a \fBselect\fP statement is zero if a break statement
371 is used to exit the loop, non-zero otherwise.
372 .ksh)
373 .\"}}}
374 .\"{{{  until list do list done
375 .IP "\fBuntil\fP \fIlist\fP \fBdo\fP \fIlist\fP \fBdone\fP"
376 This works like \fBwhile\fP, except that the body is executed only while the
377 exit status of the first \fIlist\fP is non-zero.
378 .\"}}}
379 .\"{{{  while list do list done
380 .IP "\fBwhile\fP \fIlist\fP \fBdo\fP \fIlist\fP \fBdone\fP"
381 A \fBwhile\fP is a prechecked loop.
382 Its body is executed as often
383 as the exit status of the first \fIlist\fP is zero.
384 The exit status of a \fBwhile\fP statement is the last exit status
385 of the \fIlist\fP in the body of the loop; if the body is not executed,
386 the exit status is zero.
387 .\"}}}
388 .\"{{{  function name { list }
389 .IP "\fBfunction\fP \fIname\fP \fB{\fP \fIlist\fP \fB}\fP"
390 Defines the function \fIname\fP.
391 See Functions below.
392 Note that redirections specified after a function definition are
393 performed whenever the function is executed, not when the function
394 definition is executed.
395 .\"}}}
396 .\"{{{  name () command
397 .IP "\fIname\fP \fB()\fP \fIcommand\fP"
398 Mostly the same as \fBfunction\fP.
399 See Functions below.
400 .\"}}}
401 .\"{{{  time [-p] [ pipeline ]
402 .IP "\fBtime\fP [ \fB-p\fP ] [ \fIpipeline\fP ]"
403 The \fBtime\fP reserved word is described in the Command Execution section.
404 .\"}}}
405 .\"{{{  (( expression ))
406 .ksh(
407 .IP "\fB((\fP \fIexpression\fP \fB))\fP"
408 The arithmetic expression \fIexpression\fP is evaluated;
409 equivalent to \fBlet "\fP\fIexpression\fP\fB"\fP.
410 See Arithmetic Expressions and the \fBlet\fP command below.
411 .ksh)
412 .\"}}}
413 .\"{{{  [[ expression ]]
414 .ksh(
415 .IP "\fB[[\fP \fIexpression\fP \fB]]\fP"
416 Similar to the \fBtest\fP and \fB[\fP \&... \fB]\fP commands (described later),
417 with the following exceptions:
419 .nr P2 \n(PD
420 .nr PD 0
421 .IP \ \ \(bu
422 Field splitting and file name generation are not performed on
423 arguments.
424 .IP \ \ \(bu
425 The \fB\-a\fP (and) and \fB\-o\fP (or) operators are replaced with
426 \fB&&\fP and \fB||\fP, respectively.
427 .IP \ \ \(bu
428 Operators (\fIe.g.\fP, \fB\-f\fP, \fB=\fP, \fB!\fP, \fIetc.\fP) must be unquoted.
429 .IP \ \ \(bu
430 The second operand of \fB!=\fP and \fB=\fP
431 expressions are patterns (\fIe.g.\fP, the comparison in
433 \fB[[ foobar = f*r ]]\fP
434 succeeds).
435 .IP \ \ \(bu
436 There are two additional binary operators: \fB<\fP and \fB>\fP
437 which return true if their first string operand is less than,
438 or greater than, their second string operand, respectively.
439 .IP \ \ \(bu
440 The single argument form
441 of \fBtest\fP, which tests if the argument has non-zero length, is not valid
442 - explicit operators must always be used, \fIe.g.\fP, instead of
444 \fB[\fP \fIstr\fP \fB]\fP
447 \fB[[ \-n \fP\fIstr\fP\fB ]]\fP
448 .IP \ \ \(bu
449 Parameter, command and arithmetic substitutions are performed as
450 expressions are evaluated and lazy expression evaluation is used for
451 the \fB&&\fP and \fB||\fP operators.
452 This means that in the statement
454 \fB[[ -r foo && $(< foo) = b*r ]]\fP
455 the \fB$(< foo)\fP is evaluated if and only if the file \fBfoo\fP exists
456 and is readable.
457 .nr PD \n(P2
459 .ksh)
460 .\"}}}
461 .\"}}}
462 .\"}}}
463 .\"{{{  Quoting
464 .SS Quoting
465 Quoting is used to prevent the shell from treating characters or words
466 specially.
467 There are three methods of quoting: First, \fB\e\fP quotes
468 the following character, unless it is at the end of a line, in which
469 case both the \fB\e\fP and the newline are stripped.
470 Second, a single quote (\fB'\fP) quotes everything up to the next single
471 quote (this may span lines).
472 Third, a double quote (\fB"\fP) quotes all characters,
473 except \fB$\fP, \fB`\fP and \fB\e\fP, up to the next unquoted double quote.
474 \fB$\fP and \fB`\fP inside double quotes have their usual meaning (\fIi.e.\fP,
475 parameter, command or arithmetic substitution) except no field splitting
476 is carried out on the results of double-quoted substitutions.
477 If a \fB\e\fP inside a double-quoted string is followed by \fB\e\fP, \fB$\fP,
478 \fB`\fP or \fB"\fP, it is replaced by the second character; if it is
479 followed by a newline, both the \fB\e\fP and the newline are stripped;
480 otherwise, both the \fB\e\fP and the character following are unchanged.
482 Note: An earlier version of ksh(1) changed the interpretation of sequences
483 of the form \fB"\fP...\fB`\fP...\fB\e"\fP...\fB`\fP..\fB"\fP
484 according to whether or not POSIX mode was in effect.
485 In the current implementation, the backslash in \fB\e"\fP
486 is seen and removed by the outer \fB"\fP...\fB"\fP,
487 so the backslash is not seen by the inner \fB`\fP...\fB`\fP.
488 .\"}}}
489 .\"{{{  Aliases
490 .SS "Aliases"
491 There are two types of aliases: normal command aliases and tracked aliases.
492 Command aliases are normally used as a short hand for a long
493 or often used command.
494 The shell expands command aliases (\fIi.e.\fP,
495 substitutes the alias name for its value) when it reads the first word
496 of a command.
497 An expanded alias is re-processed to check for more
498 aliases.
499 If a command alias ends in a space or tab, the following word
500 is also checked for alias expansion.
501 The alias expansion process stops
502 when a word that is not an alias is found, when a quoted word is found
503 or when an alias word that is currently being expanded is found.
505 The following command aliases are defined automatically by the shell:
506 .ft B
508 .ksh(
509 autoload='typeset \-fu'
511 functions='typeset \-f'
513 .ksh)
514 hash='alias \-t'
515 .ksh(
517 history='fc \-l'
519 integer='typeset \-i'
521 local='typeset'
523 login='exec login'
524 .\" ifndef __NetBSD__
525 .\" .br
526 .\" newgrp='exec newgrp'
527 .\" endif
529 nohup='nohup '
531 r='fc \-e \-'
533 stop='kill \-STOP'
535 suspend='kill \-STOP $$'
536 .ksh)
538 type='whence \-v'
540 .ft P
542 Tracked aliases allow the shell to remember where it found a particular
543 command.
544 The first time the shell does a path search for a command that
545 is marked as a tracked alias, it saves the full path of the command.
546 The next time the command is executed, the shell checks the saved path
547 to see that it is still valid, and if so, avoids repeating the path search.
548 Tracked aliases can be listed and created using \fBalias \-t\fP.
549 Note that changing the \fBPATH\fP parameter clears the saved
550 paths for all tracked aliases.
551 If the \fBtrackall\fP option is set (\fIi.e.\fP,
552 \fBset \-o trackall\fP or \fBset \-h\fP), the shell tracks all commands.
553 This option is set automatically for non-interactive shells.
554 For interactive shells, only the following commands are automatically
555 tracked: \fBcat\fP, \fBcc\fP, \fBchmod\fP, \fBcp\fP, \fBdate\fP, \fBed\fP,
556 \fBemacs\fP, \fBgrep\fP, \fBls\fP, \fBmail\fP, \fBmake\fP, \fBmv\fP,
557 \fBpr\fP, \fBrm\fP, \fBsed\fP, \fBsh\fP, \fBvi\fP and \fBwho\fP.
558 .\"}}}
559 .\"{{{  Substitution
560 .SS "Substitution"
561 The first step the shell takes in executing a simple-command is to
562 perform substitutions on the words of the command.
563 There are three kinds of substitution: parameter, command and arithmetic.
564 Parameter substitutions, which are described in detail in the next section,
565 take the form \fB$name\fP or \fB${\fP...\fB}\fP; command substitutions take
566 the form \fB$(\fP\fIcommand\fP\fB)\fP or \fB`\fP\fIcommand\fP\fB`\fP;
567 and arithmetic substitutions take the form \fB$((\fP\fIexpression\fP\fB))\fP.
569 If a substitution appears outside of double quotes, the results of the
570 substitution are generally subject to word or field splitting according to
571 the current value of the \fBIFS\fP parameter.
572 The \fBIFS\fP parameter specifies a list of characters which
573 are used to break a string up into several words;
574 any characters from the set space, tab and newline that appear in the
575 IFS characters are called \fIIFS white space\fP.
576 Sequences of one or more IFS white space characters, in combination with
577 zero or one non-IFS white space characters delimit a field.
578 As a special case, leading and trailing IFS white space is stripped (\fIi.e.\fP,
579 no leading or trailing empty field is created by it); leading or trailing
580 non-IFS white space does create an empty field.
581 Example: if \fBIFS\fP is set to `<space>:', the sequence of characters
582 `<space>A<space>:<space><space>B::D' contains four fields: `A', `B', `' and `D'.
583 Note that if the \fBIFS\fP parameter is set to the null string, no
584 field splitting is done; if the parameter is unset, the default value
585 of space, tab and newline is used.
587 The results of substitution are, unless otherwise specified, also subject
588 to brace expansion and file name expansion (see the relevant sections
589 below).
591 A command substitution is replaced by the output generated by the specified
592 command, which is run in a subshell.
593 For \fB$(\fP\fIcommand\fP\fB)\fP substitutions, normal quoting rules
594 are used when \fIcommand\fP is parsed, however, for the
595 \fB`\fP\fIcommand\fP\fB`\fP form, a \fB\e\fP followed by any of
596 \fB$\fP, \fB`\fP or \fB\e\fP is stripped (a \fB\e\fP followed by any other
597 character is unchanged).
598 As a special case in command substitutions, a command of the form
599 \fB<\fP \fIfile\fP is interpreted to mean substitute the contents
600 of \fIfile\fP ($(< foo) has the same effect as $(cat foo), but it
601 is carried out more efficiently because no process is started).
603 .\"todo: fix this( $(..) parenthesis counting).
604 NOTE: \fB$(\fP\fIcommand\fP\fB)\fP expressions are currently parsed by
605 finding the matching parenthesis, regardless of quoting.
606 This will hopefully be fixed soon.
608 Arithmetic substitutions are replaced by the value of the specified
609 expression.
610 For example, the command \fBecho $((2+3*4))\fP prints 14.
611 See Arithmetic Expressions for a description of an \fIexpression\fP.
612 .\"}}}
613 .\"{{{  Parameters
614 .SS "Parameters"
615 Parameters are shell variables; they can be assigned values and
616 their values can be accessed using a parameter substitution.
617 A parameter name is either one of the special single punctuation or digit
618 character parameters described below, or a letter followed by zero or more
619 letters or digits (`_' counts as a letter).
620 The later form can be treated as arrays by appending an array
621 index of the form: \fB[\fP\fIexpr\fP\fB]\fP where \fIexpr\fP is
622 an arithmetic expression.
623 Array indices are currently limited to the range 0 through 1023, inclusive.
624 Parameter substitutions take the form \fB$\fP\fIname\fP,
625 \fB${\fP\fIname\fP\fB}\fP or
626 \fB${\fP\fIname\fP\fB[\fP\fIexpr\fP\fB]}\fP, where \fIname\fP is a
627 parameter name.
628 If substitution is performed on a parameter (or an array parameter element)
629 that is not set, a null
630 string is substituted unless the \fBnounset\fP option (\fBset \-o nounset\fP
631 or \fBset \-u\fP) is set, in which case an error occurs.
633 .\"{{{  parameter assignment
634 Parameters can be assigned values in a number of ways.
635 First, the shell implicitly sets some parameters like \fB#\fP, \fBPWD\fP,
636 etc.; this is the only way the special single character parameters are
637 set.
638 Second, parameters are imported from the shell's environment at startup.
639 Third, parameters can be assigned values on the command line, for example,
640 `\fBFOO=bar\fP' sets the parameter FOO to bar; multiple parameter
641 assignments can be given on a single command line and they can
642 be followed by a simple-command, in which case the assignments are
643 in effect only for the duration of the command (such assignments are
644 also exported, see below for implications of this).
645 Note that both the parameter name and the \fB=\fP must be unquoted for
646 the shell to recognize a parameter assignment.
647 The fourth way of setting a parameter is with the \fBexport\fP, \fBreadonly\fP
648 and \fBtypeset\fP commands; see their descriptions in the Command Execution
649 section.
650 Fifth, \fBfor\fP and \fBselect\fP loops set parameters as well as
651 the \fBgetopts\fP, \fBread\fP and \fBset \-A\fP commands.
652 Lastly, parameters can be assigned values using assignment operators
653 inside arithmetic expressions (see Arithmetic Expressions below) or
654 using the \fB${\fP\fIname\fP\fB=\fP\fIvalue\fP\fB}\fP form
655 of parameter substitution (see below).
656 .\"}}}
658 .\"{{{  environment
659 Parameters with the export attribute (set using the \fBexport\fP or
660 \fBtypeset \-x\fP commands, or by parameter assignments followed by simple
661 commands) are put in the environment (see \fIenviron\fP(7)) of commands
662 run by the shell as \fIname\fP\fB=\fP\fIvalue\fP pairs.
663 The order in which parameters appear in the environment of a command
664 is unspecified.
665 When the shell starts up, it extracts parameters and their values from its
666 environment and automatically sets the export attribute for those parameters.
667 .\"}}}
668 .\"{{{  ${name[:][-+=?]word}
670 Modifiers can be applied to the \fB${\fP\fIname\fP\fB}\fP form of parameter
671 substitution:
672 .IP \fB${\fP\fIname\fP\fB:-\fP\fIword\fP\fB}\fP
673 if \fIname\fP is set and not null, it is substituted, otherwise \fIword\fP is
674 substituted.
675 .IP \fB${\fP\fIname\fP\fB:+\fP\fIword\fP\fB}\fP
676 if \fIname\fP is set and not null, \fIword\fP is substituted, otherwise nothing is substituted.
677 .IP \fB${\fP\fIname\fP\fB:=\fP\fIword\fP\fB}\fP
678 if \fIname\fP is set and not null, it is substituted, otherwise it is
679 assigned \fIword\fP and the resulting value of \fIname\fP is substituted.
680 .IP \fB${\fP\fIname\fP\fB:?\fP\fIword\fP\fB}\fP
681 if \fIname\fP is set and not null, it is substituted, otherwise \fIword\fP
682 is printed on standard error (preceded by \fIname\fP:) and an error occurs
683 (normally causing termination of a shell script, function or \&.-script).
684 If word is omitted the string `parameter null or not set' is used instead.
686 In the above modifiers, the \fB:\fP can be omitted, in which case the
687 conditions only depend on \fIname\fP being set (as opposed to set and
688 not null).
689 If \fIword\fP is needed, parameter, command, arithmetic and tilde substitution
690 are performed on it; if \fIword\fP is not needed, it is not evaluated.
691 .\"}}}
693 The following forms of parameter substitution can also be used:
694 .\"{{{  ${#name}
695 .IP \fB${#\fP\fIname\fP\fB}\fP
696 The number of positional parameters if \fIname\fP is \fB*\fP, \fB@\fP or
697 is not specified,
698 or the length of the string value of parameter \fIname\fP.
699 .\"}}}
700 .\"{{{  ${#name[*]}, ${#name[@]}
701 .IP "\fB${#\fP\fIname\fP\fB[*]}\fP, \fB${#\fP\fIname\fP\fB[@]}\fP"
702 The number of elements in the array \fIname\fP.
703 .\"}}}
704 .\"{{{  ${name#pattern}, ${name##pattern}
705 .IP "\fB${\fP\fIname\fP\fB#\fP\fIpattern\fP\fB}\fP, \fB${\fP\fIname\fP\fB##\fP\fIpattern\fP\fB}\fP"
706 If \fIpattern\fP matches the beginning of the value of parameter \fIname\fP,
707 the matched text is deleted from the result of substitution.
708 A single \fB#\fP results in the shortest match, two \fB#\fP's results in the
709 longest match.
710 .\"}}}
711 .\"{{{  ${name%pattern}, ${name%%pattern}
712 .IP "\fB${\fP\fIname\fP\fB%\fP\fIpattern\fP\fB}\fP, \fB${\fP\fIname\fP\fB%%\fP\fIpattern\fP\fB}\fP"
713 Like \fB${\fP..\fB#\fP..\fB}\fP substitution, but it deletes from the end of the
714 value.
715 .\"}}}
716 .\"{{{  special shell parameters
718 The following special parameters are implicitly set by the shell and cannot be
719 set directly using assignments:
720 .\"{{{  !
721 .IP \fB!\fP
722 Process id of the last background process started.
723 If no background processes have been started, the parameter is not set.
724 .\"}}}
725 .\"{{{  #
726 .IP \fB#\fP
727 The number of positional parameters (\fIi.e.\fP, \fB$1\fP, \fB$2\fP,
728 \fIetc.\fP).
729 .\"}}}
730 .\"{{{  $
731 .IP \fB$\fP
732 The process ID of the shell, or the PID of the original shell if
733 it is a subshell.
734 .\"}}}
735 .\"{{{  -
736 .IP \fB\-\fP
737 The concatenation of the current single letter options
738 (see \fBset\fP command below for list of options).
739 .\"}}}
740 .\"{{{  ?
741 .IP \fB?\fP
742 The exit status of the last non-asynchronous command executed.
743 If the last command was killed by a signal, \fB$?\fP is set to 128 plus
744 the signal number.
745 .\"}}}
746 .\"{{{  0
747 .IP "\fB0\fP"
748 The name the shell was invoked with (\fIi.e.\fP, \fBargv[0]\fP), or the
749 \fBcommand-name\fP if it was invoked with the \fB\-c\fP option and the
750 \fBcommand-name\fP was supplied, or the \fIfile\fP argument, if it was
751 supplied.
752 If the \fBposix\fP option is not set, \fB$0\fP is the name of the current
753 function or script.
754 .\"}}}
755 .\"{{{  1-9
756 .IP "\fB1\fP ... \fB9\fP"
757 The first nine positional parameters that were supplied to the shell,
758 function or \fB.\fP-script.
759 Further positional parameters may be accessed using
760 \fB${\fP\fInumber\fP\fB}\fP.
761 .\"}}}
762 .\"{{{  *
763 .IP \fB*\fP
764 All positional parameters (except parameter 0),
765 \fIi.e.\fP, \fB$1 $2 $3\fP....
766 If used outside of double quotes, parameters are separate words
767 (which are subjected to word splitting); if used within double quotes,
768 parameters are separated by the first character of the \fBIFS\fP parameter
769 (or the empty string if \fBIFS\fP is null).
770 .\"}}}
771 .\"{{{  @
772 .IP \fB@\fP
773 Same as \fB$*\fP, unless it is used inside double quotes, in which case
774 a separate word is generated for each positional parameter \- if there
775 are no positional parameters, no word is generated ("$@" can be used
776 to access arguments, verbatim, without losing null arguments or
777 splitting arguments with spaces).
778 .\"}}}
779 .\"}}}
780 .\"{{{  general shell parameters
782 The following parameters are set and/or used by the shell:
783 .\"{{{  _
784 .ksh(
785 .IP "\fB_\fP \fI(underscore)\fP"
786 When an external command is executed by the shell, this parameter is
787 set in the environment of the new process to the path of the executed
788 command.
789 In interactive use, this parameter is also set in the parent shell to
790 the last word of the previous command.
791 When \fBMAILPATH\fP messages are evaluated, this parameter contains
792 the name of the file that changed (see \fBMAILPATH\fP parameter below).
793 .ksh)
794 .\"}}}
795 .\"{{{  CDPATH
796 .IP \fBCDPATH\fP
797 Search path for the \fBcd\fP built-in command.
798 Works the same way as
799 \fBPATH\fP for those directories not beginning with \fB/\fP in \fBcd\fP
800 commands.
801 Note that if CDPATH is set and does not contain \fB.\fP nor an empty path,
802 the current directory is not searched.
803 .\"}}}
804 .\"{{{  COLUMNS
805 .IP \fBCOLUMNS\fP
806 Set to the number of columns on the terminal or window.
807 Currently set to the \fBcols\fP value as reported by \fIstty\fP(1) if that
808 value is non-zero.
809 This parameter is used by the interactive line editing modes, and by
810 \fBselect\fP, \fBset \-o\fP and \fBkill \-l\fP commands
811 to format information in columns.
812 .\"}}}
813 .\"{{{  EDITOR
814 .ksh(
815 .IP \fBEDITOR\fP
816 If the \fBVISUAL\fP parameter is not set, this parameter controls the
817 command line editing mode for interactive shells.
818 See \fBVISUAL\fP parameter below for how this works.
819 .ksh)
820 .\"}}}
821 .\"{{{  ENV
822 .IP \fBENV\fP
823 If this parameter is found to be set after any profile files are
824 executed, the expanded value is used as a shell start-up file.
825 It typically contains function and alias definitions.
826 .\"}}}
827 .\"{{{  ERRNO
828 .IP \fBERRNO\fP
829 Integer value of the shell's errno variable \(em indicates the reason
830 the last system call failed.
831 .\" todo: ERRNO variable
833 Not implemented yet.
834 .\"}}}
835 .\"{{{  EXECSHELL
836 .IP \fBEXECSHELL\fP
837 If set, this parameter is assumed to contain the shell that is to be
838 used to execute commands that \fIexecve\fP(2) fails to execute and
839 which do not start with a `\fB#!\fP \fIshell\fP' sequence.
840 .\"}}}
841 .\"{{{  FCEDIT
842 .IP \fBFCEDIT\fP
843 The editor used by the \fBfc\fP command (see below).
844 .\"}}}
845 .\"{{{  FPATH
846 .IP \fBFPATH\fP
847 Like \fBPATH\fP, but used when an undefined function is executed to locate
848 the file defining the function.
849 It is also searched when a command can't be found using \fBPATH\fP.
850 See Functions below for more information.
851 .\"}}}
852 .\"{{{  HISTFILE
853 .ksh(
854 .IP \fBHISTFILE\fP
855 The name of the file used to store history.
856 When assigned to, history is loaded from the specified file.
857 Also, several invocations of the
858 shell running on the same machine will share history if their
859 \fBHISTFILE\fP parameters all point at the same file.
861 NOTE: if HISTFILE isn't set, no history file is used.
862 This is
863 different from the original Korn shell, which uses \fB$HOME/.sh_history\fP;
864 in future, pdksh may also use a default history file.
865 .ksh)
866 .\"}}}
867 .\"{{{  HISTSIZE
868 .ksh(
869 .IP \fBHISTSIZE\fP
870 The number of commands normally stored for history, default 128.
871 .ksh)
872 .\"}}}
873 .\"{{{  HOME
874 .IP \fBHOME\fP
875 The default directory for the \fBcd\fP command and the value
876 substituted for an unqualified \fB~\fP (see Tilde Expansion below).
877 .\"}}}
878 .\"{{{  IFS
879 .IP \fBIFS\fP
880 Internal field separator, used during substitution and by the \fBread\fP
881 command, to split values into distinct arguments; normally set to
882 space, tab and newline.
883 See Substitution above for details.
885 \fBNote:\fP this parameter is not imported from the environment
886 when the shell is started.
887 .\"}}}
888 .\"{{{  KSH_VERSION
889 .ksh(
890 .IP \fBKSH_VERSION\fP
891 The version of shell and the date the version was created (readonly).
892 See also the version commands in Emacs Editing Mode
893 and Vi Editing Mode sections, below.
894 .ksh)
895 .\"}}}
896 .\"{{{  SH_VERSION
897 .sh(
898 .IP \fBSH_VERSION\fP
899 The version of shell and the date the version was created (readonly).
900 .sh)
901 .\"}}}
902 .\"{{{  LINENO
903 .IP \fBLINENO\fP
904 The line number of the function or shell script that is currently being
905 executed.
906 .\"}}}
907 .\"{{{  LINES
908 .IP \fBLINES\fP
909 Set to the number of lines on the terminal or window.
910 .\"Currently set to the \fBrows\fP value as reported by \fIstty\fP(1) if that
911 .\"value is non-zero.
912 .\" todo: LINES variable
914 Not implemented yet.
915 .\"}}}
916 .\"{{{  MAIL
917 .ksh(
918 .IP \fBMAIL\fP
919 If set, the user will be informed of the arrival of mail in the named file.
920 This parameter is ignored if the \fBMAILPATH\fP parameter is set.
921 .ksh)
922 .\"}}}
923 .\"{{{  MAILCHECK
924 .ksh(
925 .IP \fBMAILCHECK\fP
926 How often, in seconds, the shell will check for mail in the file(s)
927 specified by \fBMAIL\fP or \fBMAILPATH\fP.
928 If 0, the shell checks before each prompt.
929 The default is 600 (10 minutes).
930 .ksh)
931 .\"}}}
932 .\"{{{  MAILPATH
933 .ksh(
934 .IP \fBMAILPATH\fP
935 A list of files to be checked for mail.
936 The list is colon separated,
937 and each file may be followed by a \fB?\fP and a message to be printed
938 if new mail has arrived.
939 Command, parameter and arithmetic substitution is
940 performed on the message, and, during substitution, the parameter \fB$_\fP
941 contains the name of the file.
942 The default message is \fByou have mail in $_\fP.
943 .ksh)
944 .\"}}}
945 .\"{{{  OLDPWD
946 .IP \fBOLDPWD\fP
947 The previous working directory.
948 Unset if \fBcd\fP has not successfully changed directories since the
949 shell started, or if the shell doesn't know where it is.
950 .\"}}}
951 .\"{{{  OPTARG
952 .IP \fBOPTARG\fP
953 When using \fBgetopts\fP, it contains the argument for a parsed option,
954 if it requires one.
955 .\"}}}
956 .\"{{{  OPTIND
957 .IP \fBOPTIND\fP
958 The index of the last argument processed when using \fBgetopts\fP.
959 Assigning 1 to this parameter causes \fBgetopts\fP to
960 process arguments from the beginning the next time it is invoked.
961 .\"}}}
962 .\"{{{  PATH
963 .IP \fBPATH\fP
964 A colon separated list of directories that are searched when looking
965 for commands and \fB.\fP'd files.
966 An empty string resulting from a leading or trailing colon, or two adjacent
967 colons is treated as a `.', the current directory.
968 .\"}}}
969 .\"{{{  POSIXLY_CORRECT
970 .IP \fBPOSIXLY_CORRECT\fP
971 If set, this parameter causes the \fBposix\fP option to be enabled.
972 See POSIX Mode below.
973 .\"}}}
974 .\"{{{  PPID
975 .IP \fBPPID\fP
976 The process ID of the shell's parent (readonly).
977 .\"}}}
978 .\"{{{  PS1
979 .IP \fBPS1\fP
980 \fBPS1\fP is the primary prompt for interactive shells.
981 .ksh(
982 Parameter, command and arithmetic substitutions are performed, and
983 \fB!\fP is replaced with the current command number (see \fBfc\fP
984 command below).
985 A literal ! can be put in the prompt by placing !! in PS1.
986 Note that since the command line editors try to figure out how long the
987 prompt is (so they know how far it is to edge of the screen),
988 escape codes in the prompt tend to mess things up.
989 You can tell the shell not to count certain sequences (such as escape codes)
990 by prefixing your prompt with a non-printing character (such as control-A)
991 followed by a carriage return and then delimiting the escape codes with
992 this non-printing character.
993 If you don't have any non-printing characters, you're out of luck...
994 BTW, don't blame me for this hack; it's in the original ksh.
995 .ksh)
996 .sh(
997 The prompt is printed verbatim (\fIi.e.\fP, no substitutions are done).
998 .sh)
999 Default is `\fB$\ \fP' for non-root users, `\fB#\ \fP' for root..
1000 .\"}}}
1001 .\"{{{  PS2
1002 .IP \fBPS2\fP
1003 Secondary prompt string, by default `\fB>\fP ', used when more input is
1004 needed to complete a command.
1005 .\"}}}
1006 .\"{{{  PS3
1007 .ksh(
1008 .IP \fBPS3\fP
1009 Prompt used by \fBselect\fP statement when reading a menu selection.
1010 Default is `\fB#?\ \fP'.
1011 .ksh)
1012 .\"}}}
1013 .\"{{{  PS4
1014 .IP \fBPS4\fP
1015 Used to prefix commands that are printed during execution tracing
1016 (see \fBset \-x\fP command below).
1017 .ksh(
1018 Parameter, command and arithmetic substitutions are performed
1019 before it is printed.
1020 .ksh)
1021 .sh(
1022 The prompt is printed verbatim (\fIi.e.\fP, no substitutions are done).
1023 .sh)
1024 Default is `\fB+\ \fP'.
1025 .\"}}}
1026 .\"{{{  PWD
1027 .IP \fBPWD\fP
1028 The current working directory.
1029 Maybe unset or null if shell doesn't know where it is.
1030 .\"}}}
1031 .\"{{{  RANDOM
1032 .ksh(
1033 .IP \fBRANDOM\fP
1034 A simple random number generator.
1035 Every time \fBRANDOM\fP is
1036 referenced, it is assigned the next number in a random number series.
1037 The point in the series can be set by assigning a number to
1038 \fBRANDOM\fP (see \fIrand\fP(3)).
1039 .ksh)
1040 .\"}}}
1041 .\"{{{  REPLY
1042 .IP \fBREPLY\fP
1043 Default parameter for the \fBread\fP command if no names are given.
1044 Also used in \fBselect\fP loops to store the value that is read from
1045 standard input.
1046 .\"}}}
1047 .\"{{{  SECONDS
1048 .ksh(
1049 .IP \fBSECONDS\fP
1050 The number of seconds since the shell started or, if the parameter has been
1051 assigned an integer value, the number of seconds since the assignment plus
1052 the value that was assigned.
1053 .ksh)
1054 .\"}}}
1055 .\"{{{  TMOUT
1056 .ksh(
1057 .IP \fBTMOUT\fP
1058 If set to a positive integer in an interactive shell, it specifies
1059 the maximum number of seconds the shell will wait for input after
1060 printing the primary prompt (\fBPS1\fP).
1061 If the time is exceeded, the shell exits.
1062 .ksh)
1063 .\"}}}
1064 .\"{{{  TMPDIR
1065 .IP \fBTMPDIR\fP
1066 The directory shell temporary files are created in.
1067 If this parameter is not set, or does not contain the absolute path of a
1068 writable directory, temporary files are created in \fB/tmp\fP.
1069 .\"}}}
1070 .\"{{{  VISUAL
1071 .ksh(
1072 .IP \fBVISUAL\fP
1073 If set, this parameter controls the command line editing mode for
1074 interactive shells.
1075 If the last component of the path specified in this
1076 parameter contains the string \fBvi\fP, \fBemacs\fP or \fBgmacs\fP, the
1077 vi, emacs or gmacs (Gosling emacs) editing mode is enabled, respectively.
1078 .ksh)
1079 .\"}}}
1080 .\"}}}
1081 .\"}}}
1082 .\"{{{  Tilde Expansion
1083 .SS "Tilde Expansion"
1084 Tilde expansion, which is done in parallel with parameter substitution,
1085 is done on words starting with an unquoted \fB~\fP.
1086 The characters following the tilde, up to the first \fB/\fP, if any,
1087 are assumed to be a login name.
1088 If the login name is empty, \fB+\fP or \fB\-\fP, the
1089 value of the \fBHOME\fP, \fBPWD\fP, or \fBOLDPWD\fP parameter is
1090 substituted, respectively.
1091 Otherwise, the password file is searched for the login name, and the
1092 tilde expression is substituted with the user's home directory.
1093 If the login name is not found in the password
1094 file or if any quoting or parameter substitution occurs in the login name,
1095 no substitution is performed.
1097 In parameter assignments (those preceding a simple-command or those
1098 occurring in the arguments of \fBalias\fP, \fBexport\fP, \fBreadonly\fP,
1099 and \fBtypeset\fP), tilde expansion is done after any unquoted colon
1100 (\fB:\fP), and login names are also delimited by colons.
1102 The home directory of previously expanded login names are cached and
1103 re-used.
1104 The \fBalias \-d\fP command may be used to list, change and
1105 add to this cache (\fIe.g.\fP, `alias \-d fac=/usr/local/facilities; cd
1106 ~fac/bin').
1107 .\"}}}
1108 .\"{{{  Brace Expansion
1109 .ksh(
1110 .SS "Brace Expansion (alternation)"
1111 Brace expressions, which take the form
1113 \fIprefix\fP\fB{\fP\fIstr\fP1\fB,\fP...\fB,\fP\fIstr\fPN\fB}\fP\fIsuffix\fP
1115 are expanded to N words, each of which is the concatenation of
1116 \fIprefix\fP, \fIstr\fPi and \fIsuffix\fP
1117 (\fIe.g.\fP, `a{c,b{X,Y},d}e' expands to four word: ace, abXe, abYe, and ade).
1118 As noted in the example, brace expressions can be nested and the resulting
1119 words are not sorted.
1120 Brace expressions must contain an unquoted comma (\fB,\fP) for expansion
1121 to occur (\fIi.e.\fP, \fB{}\fP and \fB{foo}\fP are not expanded).
1122 Brace expansion is carried out after parameter substitution and before
1123 file name generation.
1124 .ksh)
1125 .\"}}}
1126 .\"{{{  File Name Patterns
1127 .SS "File Name Patterns"
1129 A file name pattern is a word containing one or more unquoted \fB?\fP or
1130 \fB*\fP characters or \fB[\fP..\fB]\fP sequences.
1131 Once brace expansion has
1132 been performed, the shell replaces file name patterns with the sorted names
1133 of all the files that match the pattern (if no files match, the word is
1134 left unchanged).
1135 The pattern elements have the following meaning:
1136 .IP \fB?\fP
1137 matches any single character.
1138 .IP \fB*\fP
1139 matches any sequence of characters.
1140 .IP \fB[\fP..\fB]\fP
1141 matches any of the characters inside the brackets.
1142 Ranges of characters
1143 can be specified by separating two characters by a \fB\-\fP, \fIe.g.\fP,
1144 \fB[a0\-9]\fP matches the letter \fBa\fP or any digit.
1145 In order to represent itself, a
1146 \fB\-\fP must either be quoted or the first or last character in the character
1147 list.
1148 Similarly, a \fB]\fP must be quoted or the first character in the list
1149 if it is represent itself instead of the end of the list.
1150 Also, a \fB!\fP
1151 appearing at the start of the list has special meaning (see below), so to
1152 represent itself it must be quoted or appear later in the list.
1153 .IP \fB[!\fP..\fB]\fP
1154 like \fB[\fP..\fB]\fP, except it matches any character not inside the brackets.
1155 .ksh(
1156 .IP "\fB*(\fP\fIpattern\fP\fB|\fP ... \fP|\fP\fIpattern\fP\fB)\fP"
1157 matches any string of characters that matches zero or more occurrences
1158 of the specified patterns.
1159 Example: the pattern \fB*(foo|bar)\fP matches the strings
1160 `', `foo', `bar', `foobarfoo', \fIetc.\fP.
1161 .IP "\fB+(\fP\fIpattern\fP\fB|\fP ... \fP|\fP\fIpattern\fP\fB)\fP"
1162 matches any string of characters that matches one or more occurrences
1163 of the specified patterns.
1164 Example: the pattern \fB+(foo|bar)\fP matches the strings
1165 `foo', `bar', `foobarfoo', \fIetc.\fP.
1166 .IP "\fB?(\fP\fIpattern\fP\fB|\fP ... \fP|\fP\fIpattern\fP\fB)\fP"
1167 matches the empty string or a string that matches one of the
1168 specified patterns.
1169 Example: the pattern \fB?(foo|bar)\fP only matches the strings
1170 `', `foo' and `bar'.
1171 .IP "\fB@(\fP\fIpattern\fP\fB|\fP ... \fP|\fP\fIpattern\fP\fB)\fP"
1172 matches a string that matches one of the
1173 specified patterns.
1174 Example: the pattern \fB@(foo|bar)\fP only matches the strings
1175 `foo' and `bar'.
1176 .IP "\fB!(\fP\fIpattern\fP\fB|\fP ... \fP|\fP\fIpattern\fP\fB)\fP"
1177 matches any string that does not match one of the specified
1178 patterns.
1179 Examples: the pattern \fB!(foo|bar)\fP matches all strings except
1180 `foo' and `bar'; the pattern \fB!(*)\fP matches no strings;
1181 the pattern \fB!(?)*\fP matches all strings (think about it).
1182 .ksh)
1184 Note that pdksh currently never matches \fB.\fP and \fB..\fP, but the original
1185 ksh, Bourne sh and bash do, so this may have to change (too bad).
1187 Note that none of the above pattern elements match either a period (\fB.\fP)
1188 at the start of a file name or a slash (\fB/\fP), even if they are explicitly
1189 used in a \fB[\fP..\fB]\fP sequence; also, the names \fB.\fP and \fB..\fP
1190 are never matched, even by the pattern \fB.*\fP.
1192 If the \fBmarkdirs\fP option is set, any directories that result from
1193 file name generation are marked with a trailing \fB/\fP.
1195 .\" todo: implement this ([[:alpha:]], \fIetc.\fP)
1196 The POSIX character classes (\fIi.e.\fP,
1197 \fB[:\fP\fIclass-name\fP\fB:]\fP inside a \fB[\fP..\fB]\fP expression)
1198 are not yet implemented.
1199 .\"}}}
1200 .\"{{{  Input/Output Redirection
1201 .SS "Input/Output Redirection"
1202 When a command is executed, its standard input, standard output and
1203 standard error (file descriptors 0, 1 and 2, respectively) are normally
1204 inherited from the shell.
1205 Three exceptions to this are commands in pipelines, for which standard input
1206 and/or standard output are those set up by the pipeline, asynchronous commands
1207 created when job control is disabled, for which standard input is initially
1208 set to be from \fB/dev/null\fP, and commands for which any of the following
1209 redirections have been specified:
1210 .IP "\fB>\fP \fIfile\fP"
1211 standard output is redirected to \fIfile\fP.
1212 If \fIfile\fP does not exist,
1213 it is created; if it does exist, is a regular file and the \fBnoclobber\fP
1214 option is set, an error occurs, otherwise the file is truncated.
1215 Note that this means the command \fIcmd < foo > foo\fP will open
1216 \fIfoo\fP for reading and then truncate it when it opens it for writing,
1217 before \fIcmd\fP gets a chance to actually read \fIfoo\fP.
1218 .IP "\fB>|\fP \fIfile\fP"
1219 same as \fB>\fP, except the file is truncated, even if the \fBnoclobber\fP
1220 option is set.
1221 .IP "\fB>>\fP \fIfile\fP"
1222 same as \fB>\fP, except the file an existing file is appended to instead
1223 of being truncated.
1224 Also, the file is opened in append mode, so writes
1225 always go to the end of the file (see \fIopen\fP(2)).
1226 .IP "\fB<\fP \fIfile\fP"
1227 standard input is redirected from \fIfile\fP, which is opened for reading.
1228 .IP "\fB<>\fP \fIfile\fP"
1229 same as \fB<\fP, except the file is opened for reading and writing.
1230 .IP "\fB<<\fP \fImarker\fP"
1231 after reading the command line containing this kind of redirection (called a
1232 here document), the shell copies lines from the command source into a temporary
1233 file until a line matching \fImarker\fP is read.
1234 When the command is executed, standard input is redirected from the temporary
1235 file.
1236 If \fImarker\fP contains no quoted characters, the contents of the
1237 temporary file are processed as if enclosed in double quotes each time
1238 the command is executed, so parameter, command and arithmetic substitutions
1239 are performed, along with backslash (\fB\e\fP) escapes for
1240 \fB$\fP, \fB`\fP, \fB\e\fP and \fB\enewline\fP.
1241 If multiple here documents are used on the same command line, they are
1242 saved in order.
1243 .IP "\fB<<-\fP \fImarker\fP"
1244 same as \fB<<\fP, except leading tabs are stripped from lines in the
1245 here document.
1246 .IP "\fB<&\fP \fIfd\fP"
1247 standard input is duplicated from file descriptor \fIfd\fP.
1248 \fIfd\fP can be a single digit, indicating the number of an existing
1249 file descriptor, the letter \fBp\fP, indicating the file descriptor
1250 associated with the output of the current co-process, or
1251 the character \fB\-\fP, indicating standard input is to be closed.
1252 .IP "\fB>&\fP \fIfd\fP"
1253 same as \fB<&\fP, except the operation is done on standard output.
1255 In any of the above redirections, the file descriptor that is redirected
1256 (\fIi.e.\fP, standard input or standard output) can be explicitly given by
1257 preceding the redirection with a single digit.
1258 Parameter, command and arithmetic substitutions, tilde substitutions and
1259 (if the shell is interactive) file name generation are all performed
1260 on the \fIfile\fP, \fImarker\fP and \fIfd\fP arguments of redirections.
1261 Note however, that the results of any file name generation are only used
1262 if a single file is matched; if multiple files match, the word with the
1263 unexpanded file name generation characters is used.
1264 Note that in restricted shells, redirections which can create files cannot
1265 be used.
1267 For simple-commands, redirections may appear anywhere in the command, for
1268 compound-commands (\fBif\fP statements, \fIetc.\fP), any redirections must
1269 appear at the end.
1270 Redirections are processed after pipelines are created and in the order they
1271 are given, so
1273 \fBcat /foo/bar 2>&1 > /dev/null | cat \-n\fP
1275 will print an error with a line number prepended to it.
1276 .\"}}}
1277 .\"{{{  Arithmetic Expressions
1278 .SS "Arithmetic Expressions"
1279 Integer arithmetic expressions can be used
1280 .ksh(
1281 with the \fBlet\fP command,
1282 .ksh)
1283 inside \fB$((\fP..\fB))\fP expressions,
1284 inside array references (\fIe.g.\fP, \fIname\fP\fB[\fP\fIexpr\fP\fB]\fP),
1285 as numeric arguments to the \fBtest\fP command,
1286 and as the value of an assignment to an integer parameter.
1288 Expression may contain alpha-numeric parameter identifiers, array
1289 references, and integer constants and may be combined with the
1290 following C operators (listed and grouped in increasing order of precedence).
1292 Unary operators:
1293 \fB+ \- ! ~ ++ --\fP
1295 Binary operators:
1296 \fB,\fP
1298 \fB= *= /= %= += \-= <<= >>= &= ^= |=\fP
1300 \fB||\fP
1302 \fB&&\fP
1304 \fB|\fP
1306 \fB^\fP
1308 \fB&\fP
1310 \fB== !=\fP
1312 \fB< <= >= >\fP
1314 \fB<< >>\fP
1316 \fB+ \-\fP
1318 \fB* / %\fP
1320 Ternary operator:
1321 \fB?:\fP (precedence is immediately higher than assignment)
1323 Grouping operators:
1324 \fB( )\fP
1326 Integer constants may be specified with arbitrary bases using the notation
1327 \fIbase\fP\fB#\fP\fInumber\fP, where \fIbase\fP is a decimal integer specifying
1328 the base, and \fInumber\fP is a number in the specified base.
1330 The operators are evaluated as follows:
1332 .IP "unary \fB+\fP"
1333 result is the argument (included for completeness).
1334 .IP "unary \fB\-\fP"
1335 negation.
1336 .IP "\fB!\fP"
1337 logical not; the result is 1 if argument is zero, 0 if not.
1338 .IP "\fB~\fP"
1339 arithmetic (bit-wise) not.
1340 .IP "\fB++\fP"
1341 increment; must be applied to a parameter (not a literal or other
1342 expression) - the parameter is incremented by 1.
1343 When used as a prefix operator, the result is the incremented value of
1344 the parameter, when used as a postfix operator, the result is the
1345 original value of the parameter.
1346 .IP "\fB--\fP"
1347 similar to \fB++\fP, except the parameter is decremented by 1.
1348 .IP "\fB,\fP"
1349 separates two arithmetic expressions; the left hand side is evaluated first,
1350 then the right.
1351 The result is value of the expression on the right hand side.
1352 .IP "\fB=\fP"
1353 assignment; variable on the left is set to the value on the right.
1354 .IP "\fB*= /= %= += \-= <<= >>= &= ^= |=\fP"
1355 assignment operators; \fI<var> <op>\fP\fB=\fP \fI<expr>\fP is the same as
1356 \fI<var>\fP \fB=\fP \fI<var> <op>\fP \fB(\fP \fI<expr>\fP \fB)\fP.
1357 .IP "\fB||\fP"
1358 logical or; the result is 1 if either argument is non-zero, 0 if not.
1359 The right argument is evaluated only if the left argument is zero.
1360 .IP "\fB&&\fP"
1361 logical and; the result is 1 if both arguments are non-zero, 0 if not.
1362 The right argument is evaluated only if the left argument is non-zero.
1363 .IP "\fB|\fP"
1364 arithmetic (bit-wise) or.
1365 .IP "\fB^\fP"
1366 arithmetic (bit-wise) exclusive-or.
1367 .IP "\fB&\fP"
1368 arithmetic (bit-wise) and.
1369 .IP "\fB==\fP"
1370 equal; the result is 1 if both arguments are equal, 0 if not.
1371 .IP "\fB!=\fP"
1372 not equal; the result is 0 if both arguments are equal, 1 if not.
1373 .IP "\fB<\fP"
1374 less than; the result is 1 if the left argument is less than the right,
1375 0 if not.
1376 .IP "\fB<= >= >\fP"
1377 less than or equal, greater than or equal, greater than.
1378 See <.
1379 .IP "\fB<< >>\fP"
1380 shift left (right); the result is the left argument with its bits shifted
1381 left (right) by the amount given in the right argument.
1382 .IP "\fB+ - * /\fP"
1383 addition, subtraction, multiplication, and division.
1384 .IP "\fB%\fP"
1385 remainder; the result is the remainder of the division of the left argument
1386 by the right.
1387 The sign of the result is unspecified if either argument is negative.
1388 .IP "\fI<arg1>\fP \fB?\fP \fI<arg2>\fP \fB:\fP \fI<arg3>\fP"
1389 if \fI<arg1>\fP is non-zero, the result is \fI<arg2>\fP,
1390 otherwise \fI<arg3>\fP.
1392 .\"}}}
1393 .\"{{{  Co-Processes
1394 .ksh(
1395 .SS "Co-Processes"
1396 A co-process, which is a pipeline created with the \fB|&\fP operator,
1397 is an asynchronous process that the shell can both write to
1398 (using \fBprint \-p\fP) and read from (using \fBread \-p\fP).
1399 The input and output of the co-process can also be manipulated
1400 using \fB>&p\fP and \fB<&p\fP redirections, respectively.
1401 Once a co-process has been started, another can't be started until
1402 the co-process exits, or until the co-process input has been redirected using
1403 an \fBexec \fP\fIn\fP\fB>&p\fP redirection.
1404 If a co-process's input is redirected in this way, the next
1405 co-process to be started will share the output with the first co-process,
1406 unless the output of the initial co-process has been redirected using an
1407 \fBexec \fP\fIn\fP\fB<&p\fP redirection.
1409 Some notes concerning co-processes:
1410 .nr P2 \n(PD
1411 .nr PD 0
1412 .IP \ \ \(bu
1413 the only way to close the co-process input (so the co-process reads
1414 an end-of-file) is to redirect the input to a numbered file descriptor
1415 and then close that file descriptor (\fIe.g.\fP, \fBexec 3>&p;exec 3>&-\fP).
1416 .IP \ \ \(bu
1417 in order for co-processes to share a common output, the shell must keep
1418 the write portion of the output pipe open.
1419 This means that end of file will not be detected until all co-processes
1420 sharing the co-process output have exited (when they all exit, the shell
1421 closes its copy of the pipe).
1422 This can be avoided by redirecting the output to a numbered
1423 file descriptor (as this also causes the shell to close its copy).
1424 Note that this behaviour is slightly different from the original Korn shell
1425 which closes its copy of the write portion of the co-processes' output when the
1426 most recently started co-process (instead of when all sharing co-processes)
1427 exits.
1428 .IP \ \ \(bu
1429 \fBprint \-p\fP will ignore SIGPIPE signals during writes
1430 if the signal is not being trapped or ignored; the same is not true if
1431 the co-process input has been duplicated to another file descriptor and
1432 \fBprint \-u\fP\fIn\fP is used.
1433 .nr PD \n(P2
1434 .ksh)
1435 .\"}}}
1436 .\"{{{  Functions
1437 .SS "Functions"
1438 Functions are defined using either Korn shell \fBfunction\fP \fIname\fP
1439 syntax or the Bourne/POSIX shell \fIname\fP\fB()\fP syntax
1440 (see below for the difference between the two forms).
1441 Functions are like \fB.\fP-scripts in that they are executed in
1442 the current environment, however, unlike \fB.\fP-scripts, shell arguments
1443 (\fIi.e.\fP, positional parameters, \fB$1\fP, \fIetc.\fP) are never visible
1444 inside them.
1445 When the shell is determining the location of a command, functions are
1446 searched after special built-in commands, and before regular and non-regular
1447 built-ins, and before the \fBPATH\fP is searched.
1449 An existing function may be deleted using \fBunset \-f\fP \fIfunction-name\fP.
1450 A list of functions can be obtained using \fBtypeset +f\fP and the
1451 function definitions can be listed using \fBtypeset \-f\fP.
1452 \fBautoload\fP (which is an alias for \fBtypeset \-fu\fP) may be used to
1453 create undefined functions; when an undefined function is executed, the
1454 shell searches the path specified in the \fBFPATH\fP parameter for a file
1455 with the same name as the function, which, if found is read and executed.
1456 If after executing the file, the named function is found to be defined, the
1457 function is executed, otherwise, the normal command search is continued
1458 (\fIi.e.\fP, the shell searches the regular built-in command table
1459 and \fBPATH\fP).
1460 Note that if a command is not found using \fBPATH\fP, an attempt is
1461 made to autoload a function using \fBFPATH\fP (this is an undocumented
1462 feature of the original Korn shell).
1464 Functions can have two attributes, trace and export, which can be set
1465 with \fBtypeset \-ft\fP and \fBtypeset \-fx\fP, respectively.
1466 When a traced function is executed, the shell's \fBxtrace\fP option is turned
1467 on for the functions duration, otherwise the \fBxtrace\fP option is turned off.
1468 The export attribute of functions is currently not used.
1469 In the original
1470 Korn shell, exported functions are visible to shell scripts that are executed.
1472 Since functions are executed in the current shell environment, parameter
1473 assignments made inside functions are visible after the function completes.
1474 If this is not the desired effect, the \fBtypeset\fP command can be used
1475 inside a function to create a local parameter.
1476 Note that special parameters (\fIe.g.\fP, \fB$$\fP, \fB$!\fP) can't be
1477 scoped in this way.
1479 The exit status of a function is that of the last command executed in
1480 the function.
1481 A function can be made to finish immediately using the \fBreturn\fP command;
1482 this may also be used to explicitly specify the exit status.
1484 Functions defined with the \fBfunction\fP reserved word are
1485 treated differently in the following ways from functions defined with
1486 the \fB()\fP notation:
1487 .nr P2 \n(PD
1488 .nr PD 0
1489 .IP \ \ \(bu
1490 the \fB$0\fP parameter is set to the name of the function
1491 (Bourne-style functions leave \fB$0\fP untouched).
1492 .IP \ \ \(bu
1493 parameter assignments preceding function calls are not kept in
1494 the shell environment
1495 (executing Bourne-style functions will keep assignments).
1496 .IP \ \ \(bu
1497 \fBOPTIND\fP is saved/reset and restored on entry and exit from the function
1498 so \fBgetopts\fP can be used properly both inside and outside the function
1499 (Bourne-style functions leave \fBOPTIND\fP untouched, so using \fBgetopts\fP
1500 inside a function interferes with using \fBgetopts\fP outside the function).
1501 .nr PD \n(P2
1502 In the future, the following differences will also be added:
1503 .nr P2 \n(PD
1504 .nr PD 0
1505 .IP \ \ \(bu
1506 A separate trap/signal environment will be used during the execution of
1507 functions.
1508 This will mean that traps set inside a function will not affect the shell's
1509 traps and signals that are not ignored in the shell (but may be trapped) will
1510 have their default effect in a function.
1511 .IP \ \ \(bu
1512 The EXIT trap, if set in a function, will be executed after the function
1513 returns.
1514 .nr PD \n(P2
1515 .\"}}}
1516 .\"{{{  POSIX mode
1517 .SS "POSIX Mode"
1518 The shell is intended to be POSIX compliant, however, in some cases, POSIX
1519 behaviour is contrary either to the original Korn shell behaviour or to
1520 user convenience.
1521 How the shell behaves in these cases is determined by the state of
1522 the posix option (\fBset \-o posix\fP) \(em if it is on, the POSIX behaviour
1523 is followed, otherwise it is not.
1524 The \fBposix\fP option is set automatically when the shell starts up
1525 if the environment contains the \fBPOSIXLY_CORRECT\fP parameter.
1526 (The shell can also be compiled so that it is in POSIX mode by default,
1527 however this is usually not desirable).
1529 The following is a list of things that are affected by the state of
1530 the \fBposix\fP option:
1531 .nr P2 \n(PD
1532 .nr PD 0
1533 .sh(
1534 .IP \ \ \(bu
1535 reading of \fB$ENV\fP: if not in posix mode, the \fBENV\fP parameter
1536 is not expanded and included when the shell starts.
1537 .sh)
1538 .\" The following behaviour is not useful and has been removed in NetBSD
1539 .\" .IP \ \ \(bu
1540 .\" \fB\e"\fP inside double quoted \fB`\fP..\fB`\fP command substitutions:
1541 .\" in posix mode, the \fB\e"\fP is interpreted when the command is interpreted;
1542 .\" in non-posix mode, the backslash is stripped before the command substitution
1543 .\" is interpreted.
1544 .\" For example, \fBecho "`echo \e"hi\e"`"\fP produces `"hi"' in
1545 .\" posix mode, `hi' in non-posix mode.
1546 .\" To avoid problems, use the \fB$(...\fP)
1547 .\" form of command substitution.
1548 .IP \ \ \(bu
1549 \fBkill \-l\fP output: in posix mode, signal names are listed one a single line;
1550 in non-posix mode, signal numbers, names and descriptions are printed in
1551 columns.
1552 In future, a new option (\fB\-v\fP perhaps) will be added to distinguish
1553 the two behaviours.
1554 .IP \ \ \(bu
1555 \fBfg\fP exit status: in posix mode, the exit status is 0 if no errors occur;
1556 in non-posix mode, the exit status is that of the last foregrounded job.
1557 .IP \ \ \(bu
1558 \fBeval\fP exit status: if eval gets to see an empty command (\fIe.g.\fP,
1559 \fBeval "`false`"\fP), its exit status in posix mode will be 0.
1560 In non-posix mode, it will be the exit status of the last
1561 command substitution that was done in the processing of the arguments to eval
1562 (or 0 if there were no command substitutions).
1563 .IP \ \ \(bu
1564 \fBgetopts\fP: in posix mode, options must start with a \fB\-\fP; in non-posix
1565 mode, options can start with either \fB\-\fP or \fB+\fP.
1566 .IP \ \ \(bu
1567 brace expansion (also known as alternation): in posix mode, brace expansion
1568 is disabled; in non-posix mode, brace expansion enabled.
1569 Note that \fBset \-o posix\fP (or setting the \fBPOSIXLY_CORRECT\fP parameter)
1570 automatically turns the \fBbraceexpand\fP option off, however it can be
1571 explicitly turned on later.
1572 .IP \ \ \(bu
1573 \fBset \-\fP: in posix mode, this does not clear the \fBverbose\fP or
1574 \fBxtrace\fP options; in non-posix mode, it does.
1575 .IP \ \ \(bu
1576 \fBset\fP exit status: in posix mode, the exit status of set is 0
1577 if there are no errors; in non-posix mode, the exit status is that of
1578 any command substitutions performed in generating the set command.
1579 For example, `\fBset \-\- `false`; echo $?\fP' prints 0 in posix mode,
1580 1 in non-posix mode.
1581 This construct is used in most shell scripts that
1582 use the old \fIgetopt\fP(1) command.
1583 .IP \ \ \(bu
1584 argument expansion of \fBalias\fP, \fBexport\fP, \fBreadonly\fP, and
1585 \fBtypeset\fP commands: in posix mode, normal argument expansion done;
1586 in non-posix mode, field splitting, file globing, brace expansion and
1587 (normal) tilde expansion are turned off, and assignment tilde expansion
1588 is turned on.
1589 .IP \ \ \(bu
1590 signal specification: in posix mode, signals can be specified as digits only
1591 if signal numbers match POSIX values (\fIi.e.\fP, HUP=1, INT=2, QUIT=3, ABRT=6,
1592 KILL=9, ALRM=14, and TERM=15); in non-posix mode, signals can be always digits.
1593 .IP \ \ \(bu
1594 alias expansion: in posix mode, alias expansion is only carried out when
1595 reading command words; in non-posix mode, alias expansion is carried out
1596 on any word following an alias that ended in a space.
1597 For example, the following for loop
1599 .ft B
1600 alias a='for ' i='j'
1602 a i in 1 2; do echo i=$i j=$j; done
1603 .ft P
1605 uses parameter \fBi\fP in posix mode, \fBj\fP in non-posix mode.
1606 .IP \ \ \(bu
1607 test: in posix mode, the expression "\fB-t\fP" (preceded by
1608 some number of "\fB!\fP" arguments) is always true as it is a non-zero length
1609 string; in non-posix mode, it tests if file descriptor 1 is a tty (\fIi.e.\fP,
1610 the \fIfd\fP argument to the \fB-t\fP test may be left out and defaults to 1).
1611 .nr PD \n(P2
1612 .\"}}}
1613 .\"{{{  Command Execution (built-in commands)
1614 .SS "Command Execution"
1615 After evaluation of command line arguments, redirections and parameter
1616 assignments, the type of command is determined: a special built-in,
1617 a function, a regular built-in or the name of a file to execute found
1618 using the \fBPATH\fP parameter.
1619 The checks are made in the above order.
1620 Special built-in commands differ from other commands in that
1621 the \fBPATH\fP parameter is not used to find them, an error
1622 during their execution can cause a non-interactive shell to exit and
1623 parameter assignments that are specified before the command are
1624 kept after the command completes.
1625 Just to confuse things, if the posix option is turned off (see \fBset\fP
1626 command below) some special commands are very special in that
1627 no field splitting, file globing, brace expansion nor tilde expansion
1628 is performed on arguments that look like assignments.
1629 Regular built-in commands are different only in that the \fBPATH\fP
1630 parameter is not used to find them.
1632 The original ksh and POSIX differ somewhat in which commands are considered
1633 special or regular:
1634 .IP "POSIX special commands"
1636 lw(8m)fB lw(8m)fB lw(8m)fB lw(8m)fB lw(8m)fB .
1637 \&.     continue        exit    return  trap
1638 :       eval    export  set     unset
1639 break   exec    readonly        shift
1641 .IP "Additional ksh special commands"
1643 lw(8m)fB lw(8m)fB lw(8m)fB lw(8m)fB lw(8m)fB .
1644 builtin times   typeset
1646 .IP "Very special commands (non-posix mode)"
1648 lw(8m)fB lw(8m)fB lw(8m)fB lw(8m)fB lw(8m)fB .
1649 alias   readonly        set     typeset
1651 .IP "POSIX regular commands"
1653 lw(8m)fB lw(8m)fB lw(8m)fB lw(8m)fB lw(8m)fB .
1654 alias   command fg      kill    umask
1655 bg      false   getopts read    unalias
1656 cd      fc      jobs    true    wait
1658 .IP "Additional ksh regular commands"
1660 lw(8m)fB lw(8m)fB lw(8m)fB lw(8m)fB lw(8m)fB .
1661 [       let     pwd     ulimit
1662 echo    print   test    whence
1665 In the future, the additional ksh special and regular commands may
1666 be treated differently from the POSIX special and regular commands.
1668 Once the type of the command has been determined, any command line parameter
1669 assignments are performed and exported for the duration of the command.
1671 The following describes the special and regular built-in commands:
1672 .\"{{{  . file [ arg1 ... ]
1673 .IP "\fB\&.\fP \fIfile\fP [\fIarg1\fP ...]"
1674 Execute the commands in \fIfile\fP in the current environment.
1675 The file is searched for in the directories of \fBPATH\fP.
1676 If arguments are given, the positional parameters may be used to
1677 access them while \fIfile\fP is being executed.
1678 If no arguments are given, the positional parameters are those of the
1679 environment the command is used in.
1680 .\"}}}
1681 .\"{{{  : [ ... ]
1682 .IP "\fB:\fP [ ... ]"
1683 The null command.
1684 Exit status is set to zero.
1685 .\"}}}
1686 .\"{{{  alias [ -d | +-t [ -r ] ] [+-px] [+-] [name1[=value1] ...]
1687 .IP "\fBalias\fP [ \fB\-d\fP | \fB\(+-t\fP [\fB\-r\fP] ] [\fB\(+-px\fP] [\fB\(+-\fP] [\fIname1\fP[\fB=\fP\fIvalue1\fP] ...]"
1688 Without arguments, \fBalias\fP lists all aliases.
1689 For any name without a value, the existing alias is listed.
1690 Any name with a value defines an alias (see Aliases above).
1692 When listing aliases, one of two formats is used:
1693 normally, aliases are listed as \fIname\fP\fB=\fP\fIvalue\fP, where
1694 \fIvalue\fP is quoted; if options were preceded with \fB+\fP
1695 or a lone \fB+\fP is given on the command line, only \fIname\fP
1696 is printed.
1697 In addition, if the \fB\-p\fP option is used, each alias
1698 is prefixed with the string "\fBalias\fP\ ".
1700 The \fB\-x\fP option sets (\fB+x\fP clears) the export attribute of an alias,
1701 or, if no names are given, lists the aliases with the export attribute
1702 (exporting an alias has no affect).
1704 The \fB\-t\fP option indicates that tracked aliases are to be listed/set
1705 (values specified on the command line are ignored for tracked aliases).
1706 The \fB\-r\fP option indicates that all tracked aliases are to be reset.
1708 The \fB\-d\fP causes directory aliases, which are used in tilde expansion,
1709 to be listed or set (see Tilde Expansion above).
1710 .\"}}}
1711 .\"{{{  bg [job ...]
1712 .IP "\fBbg\fP [\fIjob\fP ...]"
1713 Resume the specified stopped job(s) in the background.
1714 If no jobs are specified, \fB%+\fP is assumed.
1715 This command is only available on systems which support job control.
1716 See Job Control below for more information.
1717 .\"}}}
1718 .\"{{{  bind [-l] [-m] [key[=editing-command] ...]
1719 .IP "\fBbind\fP [\fB\-l\fP] [\fB\-m\fP] [\fIkey\fP[\fB=\fP\fIediting-command\fP] ...]"
1720 Set or view the current emacs command editing key bindings/macros.
1721 See Emacs Editing Mode below for a complete description.
1722 .\"}}}
1723 .\"{{{  break [level]
1724 .IP "\fBbreak\fP [\fIlevel\fP]"
1725 \fBbreak\fP exits the \fIlevel\fPth inner most for, select, until, or while
1726 loop.
1727 \fIlevel\fP defaults to 1.
1728 .\"}}}
1729 .\"{{{  builtin command [arg1 ...]
1730 .IP "\fBbuiltin\fP \fIcommand\fP [\fIarg1\fP ...]"
1731 Execute the built-in command \fIcommand\fP.
1732 .\"}}}
1733 .\"{{{  cd [-LP] [dir]
1734 .IP "\fBcd\fP [\fB\-LP\fP] [\fIdir\fP]"
1735 Set the working directory to \fIdir\fP.
1736 If the parameter \fBCDPATH\fP
1737 is set, it lists directories to search in for \fIdir\fP.
1738 An empty entry in the \fBCDPATH\fP entry means the current directory.
1739 If a non-empty directory from \fBCDPATH\fP is used, the resulting full
1740 path is printed to standard output.
1741 If \fIdir\fP is
1742 missing, the home directory \fB$HOME\fP is used.
1743 If \fIdir\fP is
1744 \fB\-\fP, the previous working directory is used (see OLDPWD parameter).
1745 If \fB\-L\fP option (logical path) is used or if the \fBphysical\fP option
1746 (see \fBset\fP command below) isn't set, references to \fB..\fP in \fIdir\fP
1747 are relative to the path used get to the directory.
1748 If \fB\-P\fP option (physical path) is used or if the \fBphysical\fP option
1749 is set, \fB..\fP is relative to the filesystem directory tree.
1750 The \fBPWD\fP and \fBOLDPWD\fP parameters are updated to reflect the
1751 current and old wording directory, respectively.
1752 .\"}}}
1753 .\"{{{  cd [-LP] old new
1754 .IP "\fBcd\fP [\fB\-LP\fP] \fIold new\fP"
1755 The string \fInew\fP is substituted for \fIold\fP in the current
1756 directory, and the shell attempts to change to the new directory.
1757 .\"}}}
1758 .\"{{{  command [ -pvV ] cmd [arg1 ...]
1759 .ksh(
1760 .IP "\fBcommand\fP [\fB\-pvV\fP] \fIcmd\fP [\fIarg1\fP ...]"
1761 If neither the \fB\-v\fP nor \fB\-V\fP options are given,
1762 .ksh)
1763 .sh(
1764 .IP "\fBcommand\fP [\fB\-p\fP] \fIcmd\fP [\fIarg1\fP ...]"
1765 .sh)
1766 \fIcmd\fP
1767 is executed exactly as if the \fBcommand\fP had not been specified,
1768 with two exceptions: first, \fIcmd\fP cannot be a shell function, and
1769 second, special built-in commands lose their specialness (\fIi.e.\fP,
1770 redirection and utility errors do not cause the shell to exit, and command
1771 assignments are not permanent).
1772 If the \fB\-p\fP option is given, a default search path is used instead of
1773 the current value of \fBPATH\fP (the actual value of the default path is
1774 system dependent: on POSIXish systems, it is the value returned by
1776 \fBgetconf CS_PATH\fP
1779 .ksh(
1780 If the \fB\-v\fP option is given, instead of executing \fIcmd\fP, information
1781 about what would be executed is given (and the same is done for
1782 \fIarg1\fP ...):
1783 for special and regular built-in commands and functions,
1784 their names are simply printed,
1785 for aliases, a command that defines them is printed,
1786 and for commands found by searching the \fBPATH\fP parameter,
1787 the full path of the command is printed.
1788 If no command is found, (\fIi.e.\fP, the path search fails), nothing
1789 is printed and \fBcommand\fP exits with a non-zero status.
1790 The \fB\-V\fP option is like the \fB\-v\fP option, except it is more verbose.
1791 .ksh)
1792 .\"}}}
1793 .\"{{{  continue [levels]
1794 .IP "\fBcontinue\fP [\fIlevels\fP]"
1795 \fBcontinue\fP jumps to the beginning of the \fIlevel\fPth inner most for,
1796 select, until, or while loop.
1797 \fIlevel\fP defaults to 1.
1798 .\"}}}
1799 .\"{{{  echo [-neE] [arg ...]
1800 .IP "\fBecho\fP [\fB\-neE\fP] [\fIarg\fP ...]"
1801 Prints its arguments (separated by spaces) followed by a newline, to
1802 standard out.
1803 The newline is suppressed if any of the arguments contain the backslash
1804 sequence \fB\ec\fP.
1805 See \fBprint\fP command below for a list of other backslash sequences
1806 that are recognized.
1808 The options are provided for compatibility with BSD shell scripts:
1809 \fB\-n\fP suppresses the trailing newline, \fB\-e\fP enables backslash
1810 interpretation (a no-op, since this is normally done), and \fB\-E\fP
1811 suppresses backslash interpretation.
1812 .\"}}}
1813 .\"{{{  eval command ...
1814 .IP "\fBeval\fP \fIcommand ...\fP"
1815 The arguments are concatenated (with spaces between them) to form
1816 a single string which the shell then parses and executes
1817 in the current environment.
1818 .\"}}}
1819 .\"{{{  exec [command [arg ...]]
1820 .IP "\fBexec\fP [\fIcommand\fP [\fIarg\fP ...]]"
1821 The command is executed without forking, replacing the shell process.
1823 If no arguments are given, any IO redirection is permanent and the shell
1824 is not replaced.
1825 .ksh(
1826 Any file descriptors greater than 2 which are opened or \fIdup\fP(2)-ed
1827 in this way are not
1828 made available to other executed commands (\fIi.e.\fP,
1829 commands that are not built-in to the shell).
1830 Note that the Bourne shell differs here: it does pass these
1831 file descriptors on.
1832 .ksh)
1833 .sh(
1834 Any file descriptors which are opened or \fIdup\fP(2)-ed
1835 in this way are made available to other executed commands
1836 (note that the Korn shell differs here: it does not pass on
1837 file descriptors greater than 2).
1838 .sh)
1839 .\"}}}
1840 .\"{{{  exit [status]
1841 .IP "\fBexit\fP [\fIstatus\fP]"
1842 The shell exits with the specified exit status.
1843 If \fIstatus\fP is not specified, the exit status is the current
1844 value of the \fB?\fP parameter.
1845 .\"}}}
1846 .\"{{{  export [-p] [parameter[=value] ...]
1847 .IP "\fBexport\fP [\fB\-p\fP] [\fIparameter\fP[\fB=\fP\fIvalue\fP]] ..."
1848 Sets the export attribute of the named parameters.
1849 Exported parameters are passed in the environment to executed commands.
1850 If values are specified, the named parameters also assigned.
1852 If no parameters are specified, the names of all parameters with the export
1853 attribute are printed one per line, unless the \fB\-p\fP option is used,
1854 in which case \fBexport\fP commands defining all exported
1855 parameters, including their values, are printed.
1856 .\"}}}
1857 .\"{{{  false
1858 .IP "\fBfalse\fP"
1859 A command that exits with a non-zero status.
1860 .\"}}}
1861 .\"{{{  fc [-e editor | -l [-n]] [-r] [first [ last ]]
1862 .ksh(
1863 .IP "\fBfc\fP [\fB\-e\fP \fIeditor\fP | \fB\-l\fP [\fB\-n\fP]] [\fB\-r\fP] [\fIfirst\fP [\fIlast\fP]]"
1864 \fIfirst\fP and \fIlast\fP select commands from the history.
1865 Commands can be selected by
1866 history number, or a string specifying the most recent command starting
1867 with that string.
1868 The \fB\-l\fP option lists the command on stdout,
1869 and \fB\-n\fP inhibits the default command numbers.
1870 The \fB\-r\fP option reverses the order of the list.
1871 Without \fB\-l\fP, the selected
1872 commands are edited by the editor specified with the \fB\-e\fP
1873 option, or if no \fB\-e\fP is specified, the editor specified by the
1874 \fBFCEDIT\fP parameter (if this parameter is not set, \fB/bin/ed\fP is used),
1875 and then executed by the shell.
1876 .ksh)
1877 .\"}}}
1878 .\"{{{  fc [-e - | -s] [-g] [old=new] [prefix]
1879 .IP "\fBfc\fP [\fB\-e \-\fP | \fB\-s\fP] [\fB\-g\fP] [\fIold\fP\fB=\fP\fInew\fP] [\fIprefix\fP]"
1880 Re-execute the selected command (the previous command by default) after
1881 performing the optional substitution of \fIold\fP with \fInew\fP.
1882 If \fB\-g\fP is specified, all occurrences of \fIold\fP are replaced with
1883 \fInew\fP.
1884 This command is usually accessed with the predefined alias
1885 \fBr='fc \-e \-'\fP.
1886 .\"}}}
1887 .\"{{{  fg [job ...]
1888 .IP "\fBfg\fP [\fIjob\fP ...]"
1889 Resume the specified job(s) in the foreground.
1890 If no jobs are specified, \fB%+\fP is assumed.
1891 This command is only available on systems which support job control.
1892 See Job Control below for more information.
1893 .\"}}}
1894 .\"{{{  getopts optstring name [arg ...]
1895 .IP "\fBgetopts\fP \fIoptstring\fP \fIname\fP [\fIarg\fP ...]"
1896 \fBgetopts\fP is used by shell procedures to parse the specified arguments
1897 (or positional parameters, if no arguments are given) and to check for legal
1898 options.
1899 \fIoptstring\fP contains the option letters that
1900 \fBgetopts\fP is to recognize.
1901 If a letter is followed by a colon, the option is expected to have an argument.
1902 Options that do not take arguments may be grouped in a single argument.
1903 If an option takes an argument and the option character is not the last
1904 character of the argument it is found in, the remainder of the argument
1905 is taken to be the option's argument, otherwise, the next argument is
1906 the option's argument.
1908 Each time \fBgetopts\fP is invoked, it places the next option in
1909 the shell parameter \fIname\fP and the index of the next argument to be
1910 processed in the shell parameter \fBOPTIND\fP.
1911 If the option was introduced with a \fB+\fP, the option placed in
1912 \fIname\fP is prefixed with a \fB+\fP.
1913 When an option requires an argument, \fBgetopts\fP places it in the
1914 shell parameter \fBOPTARG\fP.
1915 When an illegal option or a missing option argument is
1916 encountered a question mark or a colon is placed in \fIname\fP
1917 (indicating an illegal option or missing argument, respectively)
1918 and \fBOPTARG\fP is set to the option character that caused the problem.
1919 An error message is also printed to standard error if \fIoptstring\fP
1920 does not begin with a colon.
1922 When the end of the options is encountered, \fBgetopts\fP exits with a
1923 non-zero exit status.
1924 Options end at the first (non-option) argument that does not
1925 start with a \-, or when a \fB\-\-\fP argument is encountered.
1927 Option parsing can be reset by setting \fBOPTIND\fP to 1 (this is done
1928 automatically whenever the shell or a shell procedure is invoked).
1930 Warning: Changing the value of the shell parameter \fBOPTIND\fP to
1931 a value other than 1, or parsing different sets of arguments without
1932 resetting \fBOPTIND\fP may lead to unexpected results.
1933 .\"}}}
1934 .\"{{{  hash [-r] [name ...]
1935 .IP "\fBhash\fP [\fB\-r\fP] [\fIname ...\fP]"
1936 Without arguments, any hashed executable command pathnames are listed.
1937 The \fB\-r\fP option causes all hashed commands to be removed
1938 from the hash table.
1939 Each \fIname\fP is searched as if it where a command name and added to the
1940 hash table if it is an executable command.
1941 .\"}}}
1942 .\"{{{  jobs [-lpn] [job ...]
1943 .IP "\fBjobs\fP [\fB\-lpn\fP] [\fIjob\fP ...]"
1944 Display information about the specified jobs; if no jobs are specified,
1945 all jobs are displayed.
1946 The \fB\-n\fP option causes information to be displayed only for jobs
1947 that have changed state since the last notification.
1948 If the \fB\-l\fP option is used, the process-id of each process in a job
1949 is also listed.
1950 The \fB\-p\fP option causes only the process group of each job to be printed.
1951 See Job Control below for the format of \fIjob\fP and the displayed job.
1952 .\"}}}
1953 .\"{{{  kill [-s signame | -signum | -signame] { job | pid | -pgrp } ...
1954 .IP "\fBkill\fP [\fB\-s\fP \fIsigname\fP | \fB\-signum\fP | \fB\-signame\fP ] { \fIjob\fP | \fIpid\fP | \fB\-\fP\fIpgrp\fP } ..."
1955 Send the specified signal to the specified jobs, process ids, or process groups.
1956 If no signal is specified, the signal TERM is sent.
1957 If a job is specified, the signal is sent to the job's process group.
1958 See Job Control below for the format of \fIjob\fP.
1959 .\"}}}
1960 .\"{{{  kill -l [exit-status ...]
1961 .IP "\fBkill \-l\fP [\fIexit-status\fP ...]"
1962 Print the name of the signal that killed a process which exited with
1963 the specified \fIexit-status\fPes.
1964 If no arguments are specified, a list of all the signals, their numbers and
1965 a short description of them are printed.
1966 .\"}}}
1967 .\"{{{  let [expression ...]
1968 .ksh(
1969 .IP "\fBlet\fP [\fIexpression\fP ...]"
1970 Each expression is evaluated, see Arithmetic Expressions above.
1971 If all expressions are successfully evaluated, the exit status
1972 is 0 (1) if the last expression evaluated to non-zero (zero).
1973 If an error occurs during the parsing or evaluation of an expression,
1974 the exit status is greater than 1.
1975 Since expressions may need to be
1976 quoted, \fB((\fP \fIexpr\fP \fB))\fP is syntactic sugar for \fBlet
1977 "\fP\fIexpr\fP\fB"\fP.
1978 .ksh)
1979 .\"}}}
1980 .\"{{{  print [-nprsun | -R [-en]] [argument ...]
1981 .IP "\fBprint\fP [\fB\-nprsu\fP\fIn\fP | \fB\-R\fP [\fB\-en\fP]] [\fIargument ...\fP]"
1982 \fBPrint\fP prints its arguments on the standard output, separated by
1983 spaces, and terminated with a newline.
1984 The \fB\-n\fP option suppresses the newline.
1985 By default, certain C escapes are translated.
1986 These include \eb, \ef, \en, \er, \et, \ev, and \e0### (# is an octal digit,
1987 of which there may be 0 to 3).
1988 \ec is equivalent to using the \fB\-n\fP option.
1989 \e expansion may be inhibited with the \fB\-r\fP option.
1990 The \fB\-s\fP option prints to the history file instead of standard output,
1991 the \fB\-u\fP option prints to file descriptor \fIn\fP (\fIn\fP
1992 defaults to 1 if omitted), and the \fB\-p\fP option prints to the co-process
1993 (see Co-Processes above).
1995 The \fB\-R\fP option is used to emulate, to some degree, the BSD echo
1996 command, which does not process \e sequences unless the \fB\-e\fP option
1997 is given.
1998 As above, the \fB\-n\fP option suppresses the trailing newline.
1999 .\"}}}
2000 .\"{{{  pwd [-LP]
2001 .IP "\fBpwd\fP [\fB\-LP\fP]"
2002 Print the present working directory.
2003 If \fB\-L\fP option is used or if the \fBphysical\fP option
2004 (see \fBset\fP command below) isn't set, the logical path is printed
2005 (\fIi.e.\fP, the path used to \fBcd\fP to the current directory).
2006 If \fB\-P\fP option (physical path) is used or if the \fBphysical\fP option
2007 is set, the path determined from the filesystem (by following \fB..\fP
2008 directories to the root directory) is printed.
2009 .\"}}}
2010 .\"{{{  read [-prsun] [parameter ...]
2011 .IP "\fBread\fP [\fB\-prsu\fP\fIn\fP] [\fIparameter ...\fP]"
2012 Reads a line of input from standard input, separate the line into fields using
2013 the \fBIFS\fP parameter (see Substitution above), and assign each field to the
2014 specified parameters.
2015 If there are more parameters than fields, the extra parameters are set to null,
2016 or alternatively, if there are more fields than parameters, the last parameter
2017 is assigned the remaining fields (inclusive of any separating spaces).
2018 If no parameters are specified, the \fBREPLY\fP parameter is used.
2019 If the input line ends in a backslash and the \fB\-r\fP option was not used, the
2020 backslash and newline are stripped and more input is read.
2021 If no input is read, \fBread\fP exits with a non-zero status.
2023 The first parameter may have a question mark and a string appended to it, in
2024 which case the string is used as a prompt (printed to standard error before
2025 any input is read) if the input is a tty
2026 (\fIe.g.\fP, \fBread nfoo?'number of foos: '\fP).
2028 The \fB\-u\fP\fIn\fP and \fB\-p\fP options cause input to be read
2029 from file descriptor \fIn\fP or the current co-process (see Co-Processes above
2030 for comments on this), respectively.
2031 If the \fB\-s\fP option is used, input is saved to the history file.
2032 .\"}}}
2033 .\"{{{  readonly [-p] [parameter[=value] ...]
2034 .IP "\fBreadonly\fP [\fB\-p\fP] [\fIparameter\fP[\fB=\fP\fIvalue\fP]] ..."
2035 Sets the readonly attribute of the named parameters.
2036 If values are given,
2037 parameters are set to them before setting the attribute.
2038 Once a parameter is made readonly, it cannot be unset and its value cannot
2039 be changed.
2041 If no parameters are specified, the names of all parameters with the readonly
2042 attribute are printed one per line, unless the \fB\-p\fP option is used,
2043 in which case \fBreadonly\fP commands defining all readonly
2044 parameters, including their values, are printed.
2045 .\"}}}
2046 .\"{{{  return [status]
2047 .IP "\fBreturn\fP [\fIstatus\fP]"
2048 Returns from a function or \fB.\fP script, with exit status \fIstatus\fP.
2049 If no \fIstatus\fP is given, the exit status of the last executed command
2050 is used.
2051 If used outside of a function or \fB.\fP script, it has the same effect
2052 as \fBexit\fP.
2053 Note that pdksh treats both profile and \fB$ENV\fP files as \fB.\fP scripts,
2054 while the original Korn shell only treats profiles as \fB.\fP scripts.
2055 .\"}}}
2056 .\"{{{  set [+-abCefhkmnpsuvxX] [+-o [option]] [+-A name] [--] [arg ...]
2057 .IP "\fBset\fP [\fB\(+-abCefhkmnpsuvxX\fP] [\fB\(+-o\fP [\fIoption\fP]] [\fB\(+-A\fP \fIname\fP] [\fB\-\-\fP] [\fIarg\fP ...]"
2058 The set command can be used to set (\fB\-\fP) or clear (\fB+\fP) shell options,
2059 set the positional parameters, or set an array parameter.
2060 Options can be changed using the \fB\(+-o\fP \fIoption\fP syntax,
2061 where \fIoption\fP is the long name of an option, or using
2062 the \fB\(+-\fP\fIletter\fP syntax, where \fIletter\fP is the
2063 option's single letter name (not all options have a single letter name).
2064 The following table lists both option letters (if they exist) and long names
2065 along with a description of what the option does.
2068 expand;
2069 afB lfB lw(3i).
2070 \-A             T{
2071 Sets the elements of the array parameter \fIname\fP to \fIarg\fP ...;
2072 If \fB\-A\fP is used, the array is reset (\fIi.e.\fP, emptied) first;
2073 if \fB+A\fP is used, the first N elements are set (where N is the number
2074 of \fIarg\fPs), the rest are left untouched.
2076 \-a     allexport       T{
2077 all new parameters are created with the export attribute
2079 \-b     notify  T{
2080 Print job notification messages asynchronously, instead of just before the
2081 prompt.
2082 Only used if job control is enabled (\fB\-m\fP).
2084 \-C     noclobber       T{
2085 Prevent \fB>\fP redirection from overwriting existing files (\fB>|\fP must
2086 be used to force an overwrite).
2088 \-e     errexit T{
2089 Exit (after executing the \fBERR\fP trap) as soon as an error occurs or
2090 a command fails (\fIi.e.\fP, exits with a non-zero status).
2091 This does not apply to commands whose exit status is explicitly tested by a
2092 shell construct such as \fBif\fP, \fBuntil\fP, \fBwhile\fP, \fB&&\fP or
2093 \fB||\fP statements.
2095 \-f     noglob  T{
2096 Do not expand file name patterns.
2098 \-h     trackall        T{
2099 Create tracked aliases for all executed commands (see Aliases above).
2100 On by default for non-interactive shells.
2102 \-i     interactive     T{
2103 Enable interactive mode \- this can only be set/unset when the shell is
2104 invoked.
2106 \-k     keyword T{
2107 Parameter assignments are recognized anywhere in a command.
2109 \-l     login   T{
2110 The shell is a login shell \- this can only be set/unset when the shell is
2111 invoked (see Shell Startup above).
2113 \-m     monitor T{
2114 Enable job control (default for interactive shells).
2116 \-n     noexec  T{
2117 Do not execute any commands \- useful for checking the syntax of scripts
2118 (ignored if interactive).
2120 \-p     privileged      T{
2121 Set automatically if, when the shell starts, the real uid or gid does not
2122 match the effective uid or gid, respectively.
2123 See Shell Startup above for a description of what this means.
2125 -r      restricted      T{
2126 Enable restricted mode \(em this option can only be used when the shell is
2127 invoked.
2128 See Shell Startup above for a description of what this
2129 means.
2131 \-s     stdin   T{
2132 If used when the shell is invoked, commands are read from standard input.
2133 Set automatically if the shell is invoked with no arguments.
2135 When \fB\-s\fP is used in the \fBset\fP command, it causes the specified
2136 arguments to be sorted before assigning them to the positional parameters
2137 (or to array \fIname\fP, if \fB\-A\fP is used).
2139 \-u     nounset T{
2140 Referencing of an unset parameter is treated as an error, unless
2141 one of the \fB\-\fP, \fB+\fP or \fB=\fP modifiers is used.
2143 \-v     verbose T{
2144 Write shell input to standard error as it is read.
2146 \-x     xtrace  T{
2147 Print commands and parameter assignments when they are executed,
2148 preceded by the value of \fBPS4\fP.
2150 \-X     markdirs        T{
2151 Mark directories with a trailing \fB/\fP during file name generation.
2153         bgnice  T{
2154 Background jobs are run with lower priority.
2156 .ksh(
2157         braceexpand     T{
2158 Enable brace expansion (aka, alternation).
2160 .ksh)
2161 .ksh(
2162         emacs   T{
2163 Enable BRL emacs-like command line editing (interactive shells only);
2164 see Emacs Editing Mode.
2166         emacs-usemeta   T{
2167 In emacs command-line editing, use the 8th bit
2168 as meta (^[) prefix.  This is the default if 
2169 LC_CTYPE is unset or POSIX respectively C.
2172         gmacs   T{
2173 Enable gmacs-like (Gosling emacs) command line editing (interactive shells
2174 only);
2175 currently identical to emacs editing except that transpose (^T) acts
2176 slightly differently.
2178 .ksh)
2179         ignoreeof       T{
2180 The shell will not (easily) exit on when end-of-file is read, \fBexit\fP must
2181 be used.
2182 To avoid infinite loops, the shell will exit if eof is read 13 times in
2183 a row.
2185         nohup   T{
2186 Do not kill running jobs with a \fBHUP\fP signal when a login shell exists.
2187 Currently set by default, but this will change in the future to be compatible
2188 with the original Korn shell (which doesn't have this option, but does
2189 send the \fBHUP\fP signal).
2191         nolog   T{
2192 No effect \- in the original Korn shell, this prevents function definitions
2193 from being stored in the history file.
2195         physical        T{
2196 Causes the \fBcd\fP and \fBpwd\fP commands to use `physical'
2197 (\fIi.e.\fP, the filesystem's) \fB..\fP directories instead of `logical'
2198 directories (\fIi.e.\fP,  the shell handles \fB..\fP, which allows the user
2199 to be oblivious of symlink links to directories).
2200 Clear by default.
2201 Note that setting
2202 this option does not effect the current value of the \fBPWD\fP parameter;
2203 only the \fBcd\fP command changes \fBPWD\fP.
2204 See the \fBcd\fP and \fBpwd\fP commands above for more details.
2206         posix   T{
2207 Enable posix mode.
2208 See POSIX Mode above.
2210         vi      T{
2211 Enable vi-like command line editing (interactive shells only).
2213         viraw   T{
2214 No effect \- in the original Korn shell, unless viraw was set, the vi command
2215 line mode would let the tty driver do the work until ESC (^[) was entered.
2216 pdksh is always in viraw mode.
2218         vi-esccomplete  T{
2219 In vi command line editing, do command / file name completion when
2220 escape (^[) is entered in command mode.
2222         vi-show8        T{
2223 Prefix characters with the eighth bit set with `M-'.
2224 If this option is not set, characters in the range
2225 128-160 are printed as is, which may cause problems.
2227         vi-tabcomplete  T{
2228 In vi command line editing, do command / file name completion when
2229 tab (^I) is entered in insert mode.  This is the default.
2233 These options can also be used upon invocation of the shell.
2234 The current set of options (with single letter names) can be found in the
2235 parameter \fB\-\fP.
2236 \fBset -o\fP with no option name will list all the options and whether each
2237 is on or off; \fBset +o\fP will print the long names of all options that
2238 are currently on.
2240 Remaining arguments, if any, are positional parameters and are assigned,
2241 in order, to the
2242 positional parameters (\fIi.e.\fP, \fB1\fP, \fB2\fP, \fIetc.\fP).
2243 If options are ended with \fB\-\-\fP and there are no remaining arguments,
2244 all positional parameters are cleared.
2245 If no options or arguments are given, then the values of all names are printed.
2246 For unknown historical reasons, a lone \fB\-\fP option is treated specially:
2247 it clears both the \fB\-x\fP and \fB\-v\fP options.
2248 .\"}}}
2249 .\"{{{  shift [number]
2250 .IP "\fBshift\fP [\fInumber\fP]"
2251 The positional parameters \fInumber\fP+1, \fInumber\fP+2 \fIetc.\fP\& are
2252 renamed to \fB1\fP, \fB2\fP, \fIetc.\fP
2253 \fInumber\fP defaults to 1.
2254 .\"}}}
2255 .\"{{{  test expression, [ expression ]
2256 .IP "\fBtest\fP \fIexpression\fP"
2257 .IP "\fB[\fP \fIexpression\fP \fB]\fP"
2258 \fBtest\fP evaluates the \fIexpression\fP and returns zero status if
2259 true, 1 if false, and greater than 1 if there was an error.
2260 It is normally used as the
2261 condition command of \fBif\fP and \fBwhile\fP statements.
2262 The following basic expressions are available:
2265 afB ltw(3.2i).
2266 \fIstr\fP       T{
2267 \fIstr\fP has non-zero length.
2268 Note that there is the potential
2269 for problems if \fIstr\fP turns out to be an operator (\fIe.g.\fP, \fB-r\fP)
2270 - it is generally better to use a test like
2272 \fB[ X"\fP\fIstr\fP\fB" != X ]\fP
2273 instead (double quotes are used in case \fIstr\fP contains spaces or file
2274 globing characters).
2276 \-r \fIfile\fP  T{
2277 \fIfile\fP exists and is readable.
2279 \-w \fIfile\fP  T{
2280 \fIfile\fP exists and is writable.
2282 \-x \fIfile\fP  T{
2283 \fIfile\fP exists and is executable.
2285 \-a \fIfile\fP  T{
2286 \fIfile\fP exists.
2288 \-e \fIfile\fP  T{
2289 \fIfile\fP exists.
2291 \-f \fIfile\fP  T{
2292 \fIfile\fP is a regular file.
2294 \-d \fIfile\fP  T{
2295 \fIfile\fP is a directory.
2297 \-c \fIfile\fP  T{
2298 \fIfile\fP is a character special device.
2300 \-b \fIfile\fP  T{
2301 \fIfile\fP is a block special device.
2303 \-p \fIfile\fP  T{
2304 \fIfile\fP is a named pipe.
2306 \-u \fIfile\fP  T{
2307 \fIfile\fP's mode has setuid bit set.
2309 \-g \fIfile\fP  T{
2310 \fIfile\fP's mode has setgid bit set.
2312 \-k \fIfile\fP  T{
2313 \fIfile\fP's mode has sticky bit set.
2315 \-s \fIfile\fP  T{
2316 \fIfile\fP is not empty.
2318 \-O \fIfile\fP  T{
2319 \fIfile\fP's owner is the shell's effective user-ID.
2321 \-G \fIfile\fP  T{
2322 \fIfile\fP's group is the shell's effective group-ID.
2324 \-h \fIfile\fP  T{
2325 \fIfile\fP is a symbolic link.
2327 \-H \fIfile\fP  T{
2328 \fIfile\fP is a context dependent directory (only useful on HP-UX).
2330 \-L \fIfile\fP  T{
2331 \fIfile\fP is a symbolic link.
2333 \-S \fIfile\fP  T{
2334 \fIfile\fP is a socket.
2336 \-o \fIoption\fP        T{
2337 shell \fIoption\fP is set (see \fBset\fP command above for list of options).
2338 As a non-standard extension, if the option starts with a \fB!\fP, the test
2339 is negated; the test always fails if option doesn't exist (thus
2341 \fB[ -o \fP\fIfoo\fP \fB-o -o !\fP\fIfoo\fP \fB]\fP
2342 returns true if and only if option \fIfoo\fP exists).
2344 \fIfile\fP \-nt \fIfile\fP      T{
2345 first \fIfile\fP is newer than second \fIfile\fP or first
2346 \fIfile\fP exists and the second \fIfile\fP does not.
2348 \fIfile\fP \-ot \fIfile\fP      T{
2349 first \fIfile\fP is older than second \fIfile\fP or second \fIfile\fP
2350 exists and the first \fIfile\fP does not.
2352 \fIfile\fP \-ef \fIfile\fP      T{
2353 first \fIfile\fP is the same file as second \fIfile\fP.
2355 \-t\ [\fIfd\fP] T{
2356 file descriptor is a tty device.
2357 If the posix option (\fBset \-o posix\fP, see POSIX Mode above) is not
2358 set, \fIfd\fP may be left out, in which case it is taken to be 1
2359 (the behaviour differs due to the special POSIX rules described below).
2361 \fIstring\fP    T{
2362 \fIstring\fP is not empty.
2364 \-z\ \fIstring\fP       T{
2365 \fIstring\fP is empty.
2367 \-n\ \fIstring\fP       T{
2368 \fIstring\fP is not empty.
2370 \fIstring\fP\ =\ \fIstring\fP   T{
2371 strings are equal.
2373 .ksh(
2374 \fIstring\fP\ ==\ \fIstring\fP  T{
2375 strings are equal.
2377 .ksh)
2378 \fIstring\fP\ !=\ \fIstring\fP  T{
2379 strings are not equal.
2381 \fInumber\fP\ \-eq\ \fInumber\fP        T{
2382 numbers compare equal.
2384 \fInumber\fP\ \-ne\ \fInumber\fP        T{
2385 numbers compare not equal.
2387 \fInumber\fP\ \-ge\ \fInumber\fP        T{
2388 numbers compare greater than or equal.
2390 \fInumber\fP\ \-gt\ \fInumber\fP        T{
2391 numbers compare greater than.
2393 \fInumber\fP\ \-le\ \fInumber\fP        T{
2394 numbers compare less than or equal.
2396 \fInumber\fP\ \-lt\ \fInumber\fP        T{
2397 numbers compare less than.
2401 The above basic expressions, in which unary operators have precedence over
2402 binary operators, may be combined with the following operators
2403 (listed in increasing order of precedence):
2406 afB l.
2407 \fIexpr\fP \-o \fIexpr\fP       logical or
2408 \fIexpr\fP \-a \fIexpr\fP       logical and
2409 ! \fIexpr\fP    logical not
2410 ( \fIexpr\fP )  grouping
2413 On operating systems not supporting \fB/dev/fd/\fP\fIn\fP devices
2414 (where \fIn\fP is a file descriptor number),
2415 the \fBtest\fP command will attempt to fake it for all tests that
2416 operate on files (except the \fB-e\fP test).
2417 I.e., \fB[ -w /dev/fd/2 ]\fP tests if file descriptor 2 is writable.
2419 Note that some special rules are applied (courtesy of POSIX) if the
2420 number of arguments to \fBtest\fP or \fB[\fP \&... \fB]\fP is less than
2421 five: if leading \fB!\fP arguments can be stripped such that only one
2422 argument remains then a string length test is performed (again, even if
2423 the argument is a unary operator);
2424 if leading \fB!\fP arguments can be stripped such that three
2425 arguments remain and the second argument is a binary operator, then the
2426 binary operation is performed (even if first argument is a unary
2427 operator, including an unstripped \fB!\fP).
2429 \fBNote:\fP A common mistake is to use \fBif [ $foo = bar ]\fP which
2430 fails if parameter \fBfoo\fP is null or unset, if it has embedded spaces
2431 (\fIi.e.\fP, \fBIFS\fP characters), or if it is a unary operator like \fB!\fP or
2432 \fB\-n\fP.
2433 Use tests like \fBif [ "X$foo" = Xbar ]\fP instead.
2434 .\"}}}
2435 .\"{{{  time [-p] [pipeline]
2436 .IP "\fBtime\fP [\fB-p\fP] [ \fIpipeline\fP ]"
2437 If a pipeline is given, the times used to execute the pipeline are reported.
2438 If no pipeline is given, then the user and system time used by the shell
2439 itself, and all the commands it has run since it was started, are reported.
2440 The times reported are
2441 the real time (elapsed time from start to finish),
2442 the user CPU time (time spent running in user mode)
2443 and the system CPU time (time spent running in kernel mode).
2444 Times are reported to standard error; the format of the output is:
2446     0.00s real     0.00s user     0.00s system
2448 unless the -p option is given (only possible if \fIpipeline\fP is a simple
2449 command), in which case the output is slightly longer:
2451     real   0.00
2452     user   0.00
2453     sys    0.00
2455 (the number of digits after the decimal may vary from system to system).
2456 Note that simple redirections of standard error do not effect the output
2457 of the time command:
2459 \fBtime sleep 1 2> \fP\fIafile\fP
2461 \fB{ time sleep 1; } 2> \fP\fIafile\fP
2462 times for the first command do not go to \fIafile\fP, but those of the
2463 second command do.
2464 .\"}}}
2465 .\"{{{  times
2466 .IP \fBtimes\fP
2467 Print the accumulated user and system times used by the shell and by
2468 processes which have exited that the shell started.
2469 .\"}}}
2470 .\"{{{  trap [handler signal ...]
2471 .IP "\fBtrap\fP [\fIhandler\fP \fIsignal ...\fP]"
2472 Sets trap handler that is to be executed when any of the specified signals
2473 are received.
2474 \fBHandler\fP is either a null string, indicating the signals are to
2475 be ignored, a minus (\fB\-\fP), indicating that the default action is to
2476 be taken for the signals (see signal(3)), or a string containing shell
2477 commands to be evaluated and executed at the first opportunity (\fIi.e.\fP,
2478 when the current command completes, or before printing the next \fBPS1\fP
2479 prompt) after receipt of one of the signals.
2480 \fBSignal\fP is the name of a signal (\fIe.g.\fP, PIPE or ALRM) or the number
2481 of the signal (see \fBkill \-l\fP command above).
2482 There are two special signals: \fBEXIT\fP (also known as \fB0\fP), which
2483 is executed when the shell is about to exit, and \fBERR\fP which is
2484 executed after an error occurs (an error is something that would cause
2485 the shell to exit if the \fB\-e\fP or \fBerrexit\fP option were set \(em
2486 see \fBset\fP command above).
2487 \fBEXIT\fP handlers are executed in the environment of the last executed
2488 command.
2489 Note that for non-interactive shells, the trap handler cannot be changed for
2490 signals that were ignored when the shell started.
2492 With no arguments, \fBtrap\fP lists, as a series of \fBtrap\fP commands,
2493 the current state of the traps that have been set since the shell started.
2494 Note that the output of \fBtrap\fP can not be usefully piped to another process
2495 (an artifact of the fact that traps are cleared when subprocesses are
2496 created).
2498 .\" todo: add these features (trap DEBUG, trap ERR/EXIT in function)
2499 The original Korn shell's \fBDEBUG\fP trap and the handling of \fBERR\fP and
2500 \fBEXIT\fP traps in functions are not yet implemented.
2501 .\"}}}
2502 .\"{{{  true
2503 .IP \fBtrue\fP
2504 A command that exits with a zero value.
2505 .\"}}}
2506 .\"{{{  typeset [[+-Ulprtux] [-L[n]] [-R[n]] [-Z[n]] [-i[n]] | -f [-tux]] [name[=value] ...]
2507 .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] ...]"
2508 Display or set parameter attributes.
2509 With no \fIname\fP arguments, parameter attributes are displayed: if no options
2510 arg used, the current attributes of all parameters are printed as typeset
2511 commands; if an option is given (or \fB\-\fP with no option letter)
2512 all parameters and their values with the specified attributes are printed;
2513 if options are introduced with \fB+\fP, parameter values are not printed.
2515 If \fIname\fP arguments are given, the attributes of the named parameters
2516 are set (\fB\-\fP) or cleared (\fB+\fP).
2517 Values for parameters may optionally be specified.
2518 If typeset is used inside a function, any newly created parameters are local
2519 to the function.
2521 When \fB\-f\fP is used, typeset operates on the attributes of functions.
2522 As with parameters, if no \fIname\fPs are given, functions are listed
2523 with their values (\fIi.e.\fP, definitions) unless options are introduced with
2524 \fB+\fP, in which case only the function names are reported.
2527 expand;
2528 afB lw(4.5i).
2529 \-L\fIn\fP      T{
2530 Left justify attribute: \fIn\fP specifies the field width.
2531 If \fIn\fP is not specified, the current width of a parameter (or the
2532 width of its first assigned value) is used.
2533 Leading white space (and zeros, if used with the \fB\-Z\fP option) is stripped.
2534 If necessary, values are either truncated or space padded to fit the
2535 field width.
2537 \-R\fIn\fP      T{
2538 Right justify attribute: \fIn\fP specifies the field width.
2539 If \fIn\fP is not specified, the current width of a parameter (or the
2540 width of its first assigned value) is used.
2541 Trailing white space are stripped.
2542 If necessary, values are either stripped of leading characters
2543 or space padded to make them fit the field width.
2545 \-Z\fIn\fP      T{
2546 Zero fill attribute: if not combined with \fB\-L\fP, this is the
2547 same as \fB\-R\fP, except zero padding is used instead of space padding.
2549 \-i\fIn\fP      T{
2550 integer attribute:
2551 \fIn\fP specifies the base to use when displaying the integer
2552 (if not specified, the base given in the first assignment is used).
2553 Parameters with this attribute may be assigned values containing
2554 arithmetic expressions.
2556 \-U     T{
2557 unsigned integer attribute: integers are printed as unsigned values
2558 (only useful when combined with the \fB\-i\fP option).
2559 This option is not in the original Korn shell.
2561 \-f     T{
2562 Function mode: display or set functions and their attributes, instead of
2563 parameters.
2565 \-l     T{
2566 Lower case attribute: all  upper case characters in values are converted to
2567 lower case.
2568 (In the original Korn shell, this parameter meant `long integer' when used
2569 with the \fB\-i\fP option).
2571 \-p     T{
2572 Print complete typeset commands that can be used to re-create the
2573 attributes (but not the values) of parameters.
2574 This is the default action (option exists for ksh93 compatibility).
2576 \-r     T{
2577 Readonly attribute: parameters with the this attribute may not be assigned to
2578 or unset.
2579 Once this attribute is set, it can not be turned off.
2581 \-t     T{
2582 Tag attribute: has no meaning to the shell; provided for application use.
2584 For functions, \fB\-t\fP is the trace attribute.
2585 When functions with the trace attribute are executed, the \fBxtrace\fP (\fB\-x\fP) shell option is temporarily turned on.
2587 \-u     T{
2588 Upper case attribute: all lower case characters in values are converted to
2589 upper case.
2590 (In the original Korn shell, this parameter meant `unsigned integer' when used
2591 with the \fB\-i\fP option, which meant upper case letters would never be used
2592 for bases greater than 10.
2593 See the \fB\-U\fP option).
2595 For functions, \fB\-u\fP is the undefined attribute.
2596 See Functions above for the implications of this.
2598 \-x     T{
2599 Export attribute: parameters (or functions) are placed in the environment of
2600 any executed commands.
2601 Exported functions are not implemented yet.
2604 .\"}}}
2605 .\"{{{  ulimit [-abcdfHlmnpsStvw] [value]
2606 .IP "\fBulimit\fP [\fB\-abcdfHlmnpsStvw\fP] [\fIvalue\fP]"
2607 Display or set process limits.
2608 If no options are used, the file size limit (\fB\-f\fP) is assumed.
2609 \fBvalue\fP, if specified, may be either be an arithmetic expression or the
2610 word \fBunlimited\fP.
2611 The limits affect the shell and any processes created by the shell after
2612 a limit is imposed.
2613 Note that some systems may not allow limits to be increased once they
2614 are set.
2615 Also note that the types of limits available are system dependent \- some
2616 systems have only the \fB\-f\fP limit.
2618 .IP \fB\-a\fP
2619 Displays all limits; unless \fB\-H\fP is used, soft limits are displayed.
2620 .IP \fB\-H\fP
2621 Set the hard limit only (default is to set both hard and soft limits).
2622 .IP \fB\-S\fP
2623 Set the soft limit only (default is to set both hard and soft limits).
2624 .IP \fB\-b\fP
2625 Impose a size limit of \fIn\fP bytes on the size of socket buffers.
2626 .IP \fB\-c\fP
2627 Impose a size limit of \fIn\fP blocks on the size of core dumps.
2628 .IP \fB\-d\fP
2629 Impose a size limit of \fIn\fP kbytes on the size of the data area.
2630 .IP \fB\-f\fP
2631 Impose a size limit of \fIn\fP blocks on files written by the shell and
2632 its child processes (files of any size may be read).
2633 .IP \fB\-l\fP
2634 Impose a limit of \fIn\fP kbytes on the amount of locked (wired) physical
2635 memory.
2636 .IP \fB\-m\fP
2637 Impose a limit of \fIn\fP kbytes on the amount of physical memory used.
2638 .IP \fB\-n\fP
2639 Impose a limit of \fIn\fP file descriptors that can be open at once.
2640 .IP \fB\-p\fP
2641 Impose a limit of \fIn\fP processes that can be run by the user at any one
2642 time.
2643 .IP \fB\-s\fP
2644 Impose a size limit of \fIn\fP kbytes on the size of the stack area.
2645 .IP \fB\-t\fP
2646 Impose a time limit of \fIn\fP CPU seconds to be used by each process.
2647 .IP \fB\-v\fP
2648 Impose a limit of \fIn\fP kbytes on the amount of virtual memory used;
2649 on some systems this is the maximum allowable virtual address (in bytes,
2650 not kbytes).
2651 .IP \fB\-w\fP
2652 Impose a limit of \fIn\fP kbytes on the amount of swap space used.
2654 As far as \fBulimit\fP is concerned, a block is 512 bytes.
2656 .\"}}}
2657 .\"{{{  umask [-S] [mask]
2658 .IP "\fBumask\fP [\fB\-S\fP] [\fImask\fP]"
2660 Display or set the file permission creation mask, or umask (see \fIumask\fP(2)).
2661 If the \fB\-S\fP option is used, the mask displayed or set is symbolic,
2662 otherwise it is an octal number.
2664 Symbolic masks are like those used by \fIchmod\fP(1):
2666 [\fBugoa\fP]{{\fB=+-\fP}{\fBrwx\fP}*}+[\fB,\fP...]
2668 in which the first group of characters is the \fIwho\fP part, the second
2669 group is the \fIop\fP part, and the last group is the \fIperm\fP part.
2670 The \fIwho\fP part specifies which part of the umask is to be modified.
2671 The letters mean:
2673 .IP \fBu\fP
2674 the user permissions
2675 .IP \fBg\fP
2676 the group permissions
2677 .IP \fBo\fP
2678 the other permissions (non-user, non-group)
2679 .IP \fBa\fP
2680 all permissions (user, group and other)
2683 The \fIop\fP part indicates how the \fIwho\fP permissions are to be modified:
2685 .IP \fB=\fP
2687 .IP \fB+\fP
2688 added to
2689 .IP \fB\-\fP
2690 removed from
2693 The \fIperm\fP part specifies which permissions are to be set, added or removed:
2695 .IP \fBr\fP
2696 read permission
2697 .IP \fBw\fP
2698 write permission
2699 .IP \fBx\fP
2700 execute permission
2703 When symbolic masks are used, they describe what permissions may
2704 be made available (as opposed to octal masks in which a set bit means
2705 the corresponding bit is to be cleared).
2706 Example: `ug=rwx,o=' sets the mask so files will not be readable, writable
2707 or executable by `others', and is equivalent (on most systems) to the octal
2708 mask `07'.
2710 .\"}}}
2711 .\"{{{  unalias [-adt] name ...
2712 .IP "\fBunalias\fP [\fB\-adt\fP] [\fIname1\fP ...]"
2713 The aliases for the given names are removed.
2714 If the \fB\-a\fP option is used, all aliases are removed.
2715 If the \fB\-t\fP or \fB\-d\fP options are used, the indicated operations
2716 are carried out on tracked or directory aliases, respectively.
2717 .\"}}}
2718 .\"{{{  unset [-fv] parameter ...
2719 .IP "\fBunset\fP [\fB\-fv\fP] \fIparameter\fP ..."
2720 Unset the named parameters (\fB\-v\fP, the default) or functions (\fB\-f\fP).
2721 The exit status is non-zero if any of the parameters were already unset,
2722 zero otherwise.
2723 .\"}}}
2724 .\"{{{  wait [job]
2725 .IP "\fBwait\fP [\fIjob\fP]"
2726 Wait for the specified job(s) to finish.
2727 The exit status of wait is that of the last specified job:
2728 if the last job is killed by a signal, the exit status is 128 + the
2729 number of the signal (see \fBkill \-l\fP \fIexit-status\fP above); if the last
2730 specified job can't be found (because it never existed, or had already
2731 finished), the exit status of wait is 127.
2732 See Job Control below for the format of \fIjob\fP.
2733 \fBWait\fP will return if a signal for which a trap has been set is received,
2734 or if a HUP, INT or QUIT signal is received.
2736 If no jobs are specified, \fBwait\fP waits for all currently running jobs
2737 (if any) to finish and exits with a zero status.
2738 If job monitoring is enabled, the completion status of jobs is
2739 printed (this is not the case when jobs are explicitly specified).
2740 .\"}}}
2741 .\"{{{  whence [-pv] [name ...]
2742 .IP "\fBwhence\fP [\fB\-pv\fP] [name ...]"
2743 For each name, the type of command is listed (reserved word, built-in, alias,
2744 function, tracked alias or executable).
2745 If the \fB\-p\fP option is used, a path search done even if \fIname\fP
2746 is a reserved word, alias, \fIetc.\fP
2747 Without the \fB\-v\fP option, \fBwhence\fP is similar to \fBcommand \-v\fP
2748 except that \fBwhence\fP will find reserved words and won't print aliases
2749 as alias commands;
2750 with the \fB\-v\fP option, \fBwhence\fP is the same as \fBcommand \-V\fP.
2751 Note that for \fBwhence\fP, the \fB\-p\fP option does not affect the search
2752 path used, as it does for \fBcommand\fP.
2753 If the type of one or more of the names could not be determined, the
2754 exit status is non-zero.
2755 .\"}}}
2756 .\"}}}
2757 .\"{{{  job control (and its built-in commands)
2758 .SS "Job Control"
2759 Job control refers to the shell's ability to monitor and control \fBjobs\fP,
2760 which are processes or groups of processes created for commands or pipelines.
2761 At a minimum, the shell keeps track of the status of the background
2762 (\fIi.e.\fP, asynchronous) jobs that currently exist; this information can be
2763 displayed using the \fBjobs\fP command.
2764 If job control is fully enabled (using \fBset \-m\fP or
2765 \fBset \-o monitor\fP), as it is for interactive shells,
2766 the processes of a job are placed in their own process group,
2767 foreground jobs can be stopped by typing the suspend character from the
2768 terminal (normally ^Z),
2769 jobs can be restarted in either the foreground
2770 or background, using the \fBfg\fP and \fBbg\fP commands, respectively,
2771 and the state of the terminal is saved or restored when a foreground
2772 job is stopped or restarted, respectively.
2774 Note that only commands that create processes (\fIe.g.\fP,
2775 asynchronous commands, subshell commands, and non-built-in,
2776 non-function commands) can be stopped; commands like \fBread\fP cannot be.
2778 When a job is created, it is assigned a job-number.
2779 For interactive shells, this number is printed inside \fB[\fP..\fB]\fP,
2780 followed by the process-ids of the processes in the job when an asynchronous
2781 command is run.
2782 A job may be referred to in \fBbg\fP, \fBfg\fP, \fBjobs\fP, \fBkill\fP and
2783 \fBwait\fP commands either by the process id of the last process in the
2784 command pipeline (as stored in the \fB$!\fP parameter) or by prefixing the
2785 job-number with a percent sign (\fB%\fP).
2786 Other percent sequences can also be used to refer to jobs:
2789 expand;
2790 afB lw(4.5i).
2791 %+      T{
2792 The most recently stopped job, or, if there are no stopped jobs, the oldest
2793 running job.
2795 %%\fR, \fP%     T{
2796 Same as \fB%+\fP.
2798 %\-     T{
2799 The job that would be the \fB%+\fP job, if the later did not exist.
2801 %\fIn\fP        T{
2802 The job with job-number \fIn\fP.
2804 %?\fIstring\fP  T{
2805 The job containing the string \fIstring\fP (an error occurs if multiple jobs
2806 are matched).
2808 %\fIstring\fP   T{
2809 The job starting with string \fIstring\fP (an error occurs if multiple jobs
2810 are matched).
2814 When a job changes state (\fIe.g.\fP, a background job finishes or foreground
2815 job is stopped), the shell prints the following status information:
2817 \fB[\fP\fInumber\fP\fB]\fP \fIflag status command\fP
2819 where
2820 .IP "\ \fInumber\fP"
2821 is the job-number of the job.
2822 .IP "\ \fIflag\fP"
2823 is \fB+\fP or \fB-\fP if the job is the \fB%+\fP or \fB%-\fP job,
2824 respectively, or space if it is neither.
2825 .IP "\ \fIstatus\fP"
2826 indicates the current state of the job and can be
2828 .IP "\fBRunning\fP"
2829 the job has neither stopped or exited (note that running does not
2830 necessarily mean consuming CPU time \(em the process could be blocked waiting
2831 for some event).
2832 .IP "\fBDone\fP [\fB(\fP\fInumber\fP\fB)\fP]"
2833 the job exited.
2834 \fInumber\fP is the exit status of the job, which is
2835 omitted if the status is zero.
2836 .IP "\fBStopped\fP [\fB(\fP\fIsignal\fP\fB)\fP]"
2837 the job was stopped by the indicated \fIsignal\fP (if no signal is given,
2838 the job was stopped by SIGTSTP).
2839 .IP "\fIsignal-description\fP [\fB(core dumped)\fP]"
2840 the job was killed by a signal (\fIe.g.\fP, Memory\ fault,
2841 Hangup, \fIetc.\fP \(em use
2842 \fBkill \-l\fP for a list of signal descriptions).
2843 The \fB(core\ dumped)\fP message indicates the process created a core file.
2845 .IP "\ \fIcommand\fP"
2846 is the command that created the process.
2847 If there are multiple processes in the job, then each process will
2848 have a line showing its \fIcommand\fP and possibly its \fIstatus\fP,
2849 if it is different from the status of the previous process.
2851 When an attempt is made to exit the shell while there are jobs in
2852 the stopped state, the shell warns the user that there are stopped jobs
2853 and does not exit.
2854 If another attempt is immediately made to exit the shell, the stopped
2855 jobs are sent a \fBHUP\fP signal and the shell exits.
2856 Similarly, if the \fBnohup\fP option is not set and there are running
2857 jobs when an attempt is made to exit a login shell, the shell warns the
2858 user and does not exit.
2859 If another attempt is immediately made to exit the shell, the running
2860 jobs are sent a \fBHUP\fP signal and the shell exits.
2861 .\"}}}
2862 .\"{{{  Interactive Input Line Editing
2863 .ksh(
2864 .\"{{{  introduction
2865 .SS "Interactive Input Line Editing"
2866 The shell supports three modes of reading command lines from a tty
2867 in an interactive session.
2868 Which is used is controlled by the \fBemacs\fP, \fBgmacs\fP and \fBvi\fP
2869 \fBset\fP options (at most one of these can be set at once).
2870 If none of these options is enabled, the shell simply reads lines
2871 using the normal tty driver.
2872 If the \fBemacs\fP or \fBgmacs\fP option is set, the shell allows
2873 emacs like editing of the command; similarly, if the \fBvi\fP option
2874 is set, the shell allows vi like editing of the command.
2875 These modes are described in detail in the following sections.
2876 .\"}}}
2877 .\"{{{  display
2879 In these editing modes, if a line is longer that the screen width
2880 (see \fBCOLUMNS\fP parameter),
2881 a \fB>\fP, \fB+\fP or \fB<\fP character is displayed in the last column
2882 indicating that there are more characters after, before and after, or
2883 before the current position, respectively.
2884 The line is scrolled horizontally as necessary.
2885 .\"}}}
2886 .\"{{{  Emacs Editing Mode
2887 .SS "Emacs Editing Mode"
2888 When the \fBemacs\fP option is set, interactive input line editing is
2889 enabled.
2890 \fBWarning\fP: This mode is slightly different from the emacs
2891 mode in the original Korn shell and the 8th bit is stripped in emacs mode.
2892 In this mode various editing commands (typically bound to one or more
2893 control characters) cause immediate actions without waiting for a
2894 new-line.
2895 Several editing commands are bound to particular control
2896 characters when the shell is invoked; these bindings can be changed
2897 using the following commands:
2898 .\"{{{  bind
2899 .IP \fBbind\fP
2900 The current bindings are listed.
2901 .\"}}}
2902 .\"{{{  bind string=[editing-command]
2903 .IP "\fBbind\fP \fIstring\fP\fB=\fP[\fIediting-command\fP]"
2904 The specified editing command is bound to the given \fBstring\fP, which
2905 should consist of a control character (which may be written using caret
2906 notation \fB^\fP\fIX\fP), optionally preceded by one of the two prefix
2907 characters.
2908 Future input of the \fIstring\fP will cause the editing
2909 command to be immediately invoked.
2910 Note that although only two prefix
2911 characters (usually ESC and ^X) are supported, some multi-character
2912 sequences can be supported.
2913 The following binds the arrow keys on
2914 an ANSI terminal, or xterm (these are in the default bindings).
2915 Of course some escape sequences won't work out quite this nicely:
2918 \fBbind '^[['=prefix\-2
2920 bind '^XA'=up\-history
2922 bind '^XB'=down\-history
2924 bind '^XC'=forward\-char
2926 bind '^XD'=backward\-char\fP
2928 .\"}}}
2929 .\"{{{  bind -l
2930 .IP "\fBbind \-l\fP"
2931 Lists the names of the functions to which keys may be bound.
2932 .\"}}}
2933 .\"{{{  bind -m string=[substitute]
2934 .IP "\fBbind \-m\fP \fIstring\fP\fB=\fP[\fIsubstitute\fP]"
2935 The specified input \fIstring\fP will afterwards be immediately
2936 replaced by the given \fIsubstitute\fP string, which may contain
2937 editing commands.
2938 .\"}}}
2940 The following is a list of editing commands available.
2941 Each description starts with the name of the command,
2942 a \fIn\fP, if the command can be prefixed with a count,
2943 and any keys the command is bound to by default (written using
2944 caret notation, \fIe.g.\fP, ASCII ESC character is written as ^[).
2945 A count prefix for a command is entered using the sequence
2946 \fB^[\fP\fIn\fP, where \fIn\fP is a sequence of 1 or more digits;
2947 unless otherwise specified, if a count is omitted, it defaults to 1.
2948 Note that editing command names are
2949 used only with the \fBbind\fP command.
2950 Furthermore, many editing
2951 commands are useful only on terminals with a visible cursor.
2952 The default bindings were chosen to resemble corresponding EMACS key
2953 bindings.
2954 The users tty characters (\fIe.g.\fP, ERASE) are bound to
2955 reasonable substitutes and override the default bindings.
2956 .\"{{{  abort ^G
2957 .IP "\fBabort ^G\fP"
2958 Useful as a response to a request for a \fBsearch-history\fP pattern in
2959 order to abort the search.
2960 .\"}}}
2961 .\"{{{  auto-insert n
2962 .IP "\fBauto-insert\fP \fIn\fP"
2963 Simply causes the character to appear as literal input.
2964 Most ordinary characters are bound to this.
2965 .\"}}}
2966 .\"{{{  backward-char   n ^B
2967 .IP "\fBbackward-char\fP  \fIn\fP \fB^B\fP"
2968 Moves the cursor backward \fIn\fP characters.
2969 .\"}}}
2970 .\"{{{  backward-word  n ^[B
2971 .IP "\fBbackward-word\fP  \fIn\fP \fB^[B\fP"
2972 Moves the cursor backward to the beginning of a word; words consist
2973 of alphanumerics, underscore (_) and dollar ($).
2974 .\"}}}
2975 .\"{{{  beginning-of-history ^[<
2976 .IP "\fBbeginning-of-history ^[<\fP"
2977 Moves to the beginning of the history.
2978 .\"}}}
2979 .\"{{{  beginning-of-line ^A
2980 .IP "\fBbeginning-of-line ^A\fP"
2981 Moves the cursor to the beginning of the edited input line.
2982 .\"}}}
2983 .\"{{{  capitalize-word n ^[c, ^[C
2984 .IP "\fBcapitalize-word\fP \fIn\fP \fB^[c\fP, \fB^[C\fP"
2985 Uppercase the first character in the next \fIn\fP words,
2986 leaving the cursor past the end of the last word.
2987 .\"}}}
2988 .\"{{{  comment ^[#
2989 If the current line does not begin with a comment character, one
2990 is added at the beginning of the line and the line is entered (as if
2991 return had been pressed), otherwise the existing comment characters
2992 are removed and the cursor is placed at the beginning of the line.
2993 .\"}}}
2994 .\"{{{  complete ^[^[
2995 .IP "\fBcomplete ^[^[\fP"
2996 .IP "\fBcomplete ^I\fP"
2997 Automatically completes as much as is unique of the command name
2998 or the file name containing the cursor.
2999 If the entire remaining command
3000 or file name is unique a space is printed after its completion, unless
3001 it is a directory name in which case \fB/\fP is appended.
3002 If there is no command or file name with the current partial word as its
3003 prefix, a bell character is output (usually causing a audio beep).
3004 .\"}}}
3005 .\"{{{  complete-command ^X^[
3006 .IP "\fBcomplete-command ^X^[\fP"
3007 Automatically completes as much as is unique of the command name
3008 having the partial word up to the cursor as its prefix, as in the
3009 \fBcomplete\fP command described above.
3010 .\"}}}
3011 .\"{{{  complete-file ^[^X
3012 .IP "\fBcomplete-file ^[^X\fP"
3013 Automatically completes as much as is unique of the file name having
3014 the partial word up to the cursor as its prefix, as in the
3015 \fBcomplete\fP command described above.
3016 .\"}}}
3017 .\"{{{  complete-list ^[=
3018 .IP "\fBcomplete-list ^[=\fP"
3019 List the possible completions for the current word.
3020 .\"}}}
3021 .\"{{{  delete-char-backward n ERASE, ^?, ^H
3022 .IP "\fBdelete-char-backward\fP \fIn\fP \fBERASE\fP, \fB^?\fP, \fB^H\fP"
3023 Deletes \fIn\fP characters before the cursor.
3024 .\"}}}
3025 .\"{{{  delete-char-forward n
3026 .IP "\fBdelete-char-forward\fP \fIn\fP"
3027 Deletes \fIn\fP characters after the cursor.
3028 .\"}}}
3029 .\"{{{  delete-word-backward n ^[ERASE, ^[^?, ^[^H, ^[h
3030 .IP "\fBdelete-word-backward\fP \fIn\fP \fB^[ERASE\fP, \fB^[^?\fP, \fB^[^H\fP, \fB^[h\fP"
3031 Deletes \fIn\fP words before the cursor.
3032 .\"}}}
3033 .\"{{{  delete-word-forward n ^[d
3034 .IP "\fBdelete-word-forward\fP \fIn\fP \fB^[d\fP"
3035 Deletes characters after the cursor up to the end of \fIn\fP words.
3036 .\"}}}
3037 .\"{{{  down-history n ^N
3038 .IP "\fBdown-history\fP \fIn\fP \fB^N\fP"
3039 Scrolls the history buffer forward \fIn\fP lines (later).
3040 Each input line
3041 originally starts just after the last entry in the history buffer, so
3042 \fBdown-history\fP is not useful until either \fBsearch-history\fP or
3043 \fBup-history\fP has been performed.
3044 .\"}}}
3045 .\"{{{  downcase-word n ^[L, ^[l
3046 .IP "\fBdowncase-word\fP \fIn\fP \fB^[L\fP, \fB^[l\fP"
3047 Lowercases the next \fIn\fP words.
3048 .\"}}}
3049 .\"{{{  end-of-history ^[>
3050 .IP "\fBend-of-history ^[>\fP"
3051 Moves to the end of the history.
3052 .\"}}}
3053 .\"{{{  end-of-line ^E
3054 .IP "\fBend-of-line ^E\fP"
3055 Moves the cursor to the end of the input line.
3056 .\"}}}
3057 .\"{{{  eot ^_
3058 .IP "\fBeot ^_\fP"
3059 Acts as an end-of-file; this is useful because edit-mode input disables
3060 normal terminal input canonicalization.
3061 .\"}}}
3062 .\"{{{  eot-or-delete n ^D
3063 .IP "\fBeot-or-delete\fP \fIn\fP \fB^D\fP"
3064 Acts as eot if alone on a line; otherwise acts as delete-char-forward.
3065 .\"}}}
3066 .\"{{{  error
3067 .IP "\fBerror\fP"
3068 Error (ring the bell).
3069 .\"}}}
3070 .\"{{{  exchange-point-and-mark ^X^X
3071 .IP "\fBexchange-point-and-mark ^X^X\fP"
3072 Places the cursor where the mark is, and sets the mark to where the
3073 cursor was.
3074 .\"}}}
3075 .\"{{{  expand-file ^[*
3076 .IP "\fBexpand-file ^[*\fP"
3077 Appends a * to the current word and replaces the word with
3078 the result of performing file globbing on the word.
3079 If no files match the pattern, the bell is rung.
3080 .\"}}}
3081 .\"{{{  forward-char n ^F
3082 .IP "\fBforward-char\fP \fIn\fP \fB^F\fP"
3083 Moves the cursor forward \fIn\fP characters.
3084 .\"}}}
3085 .\"{{{  forward-word n ^[f
3086 .IP "\fBforward-word\fP \fIn\fP \fB^[f\fP"
3087 Moves the cursor forward to the end of the \fIn\fPth word.
3088 .\"}}}
3089 .\"{{{  goto-history n ^[g
3090 .IP "\fBgoto-history\fP \fIn\fP \fB^[g\fP"
3091 Goes to history number \fIn\fP.
3092 .\"}}}
3093 .\"{{{  kill-line KILL
3094 .IP "\fBkill-line KILL\fP"
3095 Deletes the entire input line.
3096 .\"}}}
3097 .\"{{{  kill-region ^W
3098 .IP "\fBkill-region ^W\fP"
3099 Deletes the input between the cursor and the mark.
3100 .\"}}}
3101 .\"{{{  kill-to-eol n ^K
3102 .IP "\fBkill-to-eol\fP \fIn\fP \fB^K\fP"
3103 Deletes the input from the cursor to the end of the line if \fIn\fP is
3104 not specified, otherwise deletes characters between the cursor and
3105 column \fIn\fP.
3106 .\"}}}
3107 .\"{{{  list ^[?
3108 .IP "\fBlist ^[?\fP"
3109 Prints a sorted, columnated list of command names or file names
3110 (if any) that can complete the partial word containing the cursor.
3111 Directory names have \fB/\fP appended to them.
3112 .\"}}}
3113 .\"{{{  list-command ^X?
3114 .IP "\fBlist-command ^X?\fP"
3115 Prints a sorted, columnated list of command names (if any) that
3116 can complete the partial word containing the cursor.
3117 .\"}}}
3118 .\"{{{  list-file ^X^Y
3119 .IP "\fBlist-file ^X^Y\fP"
3120 Prints a sorted, columnated list of file names (if any) that can
3121 complete the partial word containing the cursor.
3122 File type indicators
3123 are appended as described under \fBlist\fP above.
3124 .\"}}}
3125 .\"{{{  newline ^J and ^M
3126 .IP "\fBnewline ^J\fP, \fB^M\fP"
3127 Causes the current input line to be processed by the shell.
3128 The current cursor position may be anywhere on the line.
3129 .\"}}}
3130 .\"{{{  newline-and-next ^O
3131 .IP "\fBnewline-and-next ^O\fP"
3132 Causes the current input line to be processed by the shell, and
3133 the next line from history becomes the current line.
3134 This is only useful after an up-history or search-history.
3135 .\"}}}
3136 .\"{{{  no-op QUIT
3137 .IP "\fBno-op QUIT\fP"
3138 This does nothing.
3139 .\"}}}
3140 .\"{{{  prefix-1 ^[
3141 .IP "\fBprefix-1 ^[\fP"
3142 Introduces a 2-character command sequence.
3143 .\"}}}
3144 .\"{{{  prefix-2 ^X and ^[[
3145 .IP "\fBprefix-2 ^X\fP"
3146 .IP "\fBprefix-2 ^[[\fP"
3147 Introduces a 2-character command sequence.
3148 .\"}}}
3149 .\"{{{  prev-hist-word ^[. ^[_
3150 .IP "\fBprev-hist-word\fP \fIn\fP \fB^[.\fP, \fB^[_\fP"
3151 The last (\fIn\fPth) word of the previous command is inserted at the cursor.
3152 .\"}}}
3153 .\"{{{  quote ^^
3154 .IP "\fBquote ^^\fP"
3155 The following character is taken literally rather than as an editing
3156 command.
3157 .\"}}}
3158 .\"{{{  redraw ^L
3159 .IP "\fBredraw ^L\fP"
3160 Reprints the prompt string and the current input line.
3161 .\"}}}
3162 .\"{{{  search-character-backward n ^[^]
3163 .IP "\fBsearch-character-backward\fP \fIn\fP \fB^[^]\fP"
3164 Search backward in the current line for the \fIn\fPth occurrence of the
3165 next character typed.
3166 .\"}}}
3167 .\"{{{  search-character-forward n ^]
3168 .IP "\fBsearch-character-forward\fP \fIn\fP \fB^]\fP"
3169 Search forward in the current line for the \fIn\fPth occurrence of the
3170 next character typed.
3171 .\"}}}
3172 .\"{{{  search-history ^R
3173 .IP "\fBsearch-history ^R\fP"
3174 Enter incremental search mode.
3175 The internal history list is searched
3176 backwards for commands matching the input.
3177 An initial \fB^\fP in the search string anchors the search.
3178 The abort key will leave search mode.
3179 Other commands will be executed after leaving search mode.
3180 Successive \fBsearch-history\fP commands continue searching backward to
3181 the next previous occurrence of the pattern.
3182 The history buffer retains only a
3183 finite number of lines; the oldest are discarded as necessary.
3184 .\"}}}
3185 .\"{{{  set-mark-command ^[<space>
3186 .IP "\fBset-mark-command ^[\fP<space>"
3187 Set the mark at the cursor position.
3188 .\"}}}
3189 .\"{{{  stuff
3190 .IP "\fBstuff\fP"
3191 On systems supporting it, pushes the bound character back onto the
3192 terminal input where it may receive special processing by the terminal
3193 handler.
3194 This is useful for the BRL \fB^T\fP mini-systat feature, for example.
3195 .\"}}}
3196 .\"{{{  stuff-reset
3197 .IP "\fBstuff-reset\fP"
3198 Acts like \fBstuff\fP, then aborts input the same as an interrupt.
3199 .\"}}}
3200 .\"{{{  transport-chars ^T
3201 .IP "\fBtranspose-chars ^T\fP"
3202 If at the end of line, or if the \fBgmacs\fP option is set,
3203 this exchanges the two previous characters; otherwise, it
3204 exchanges the previous and current characters and moves the cursor
3205 one character to the right.
3206 .\"}}}
3207 .\"{{{  up-history n ^P
3208 .IP "\fBup-history\fP \fIn\fP \fB^P\fP"
3209 Scrolls the history buffer backward \fIn\fP lines (earlier).
3210 .\"}}}
3211 .\"{{{  upcase-word n ^[U, ^[u
3212 .IP "\fBupcase-word\fP \fIn\fP \fB^[U\fP, \fB^[u\fP"
3213 Uppercases the next \fIn\fP words.
3214 .\"}}}
3215 .\"{{{  version ^V
3216 .IP "\fBversion ^V\fP"
3217 Display the version of ksh.
3218 The current edit buffer is restored as soon
3219 as any key is pressed (the key is then processed, unless it is a space).
3220 .\"}}}
3221 .\"{{{  yank ^Y
3222 .IP "\fByank ^Y\fP"
3223 Inserts the most recently killed text string at the current cursor position.
3224 .\"}}}
3225 .\"{{{  yank-pop ^[y
3226 .IP "\fByank-pop ^[y\fP"
3227 Immediately after a \fByank\fP, replaces the inserted text string with
3228 the next previous killed text string.
3229 .\"}}}
3230 .\"}}}
3231 .\"{{{  Vi Editing Mode
3232 .\"{{{  introduction
3233 .SS "Vi Editing Mode"
3234 The vi command line editor in ksh has basically the same commands as the
3235 vi editor (see \fIvi\fP(1)), with the following exceptions:
3236 .nr P2 \n(PD
3237 .IP \ \ \(bu
3238 you start out in insert mode,
3239 .IP \ \ \(bu
3240 there are file name and command completion commands
3241 (\fB=\fP, \fB\e\fP, \fB*\fP, \fB^X\fP, \fB^E\fP, \fB^F\fP and,
3242 optionally, \fB<tab>\fP),
3243 .IP \ \ \(bu
3244 the \fB_\fP command is different (in ksh it is the last argument command,
3245 in vi it goes to the start of the current line),
3246 .IP \ \ \(bu
3247 the \fB/\fP and \fBG\fP commands move in the opposite direction as the \fBj\fP
3248 command
3249 .IP \ \ \(bu
3250 and commands which don't make sense in a single line editor are not available
3251 (\fIe.g.\fP, screen movement commands, ex \fB:\fP commands, \fIetc.\fP).
3252 .nr PD \n(P2
3254 Note that the \fB^X\fP stands for control-X; also \fB<esc>\fP, \fB<space>\fP
3255 and \fB<tab>\fP are used for escape, space and tab, respectively (no kidding).
3256 .\"}}}
3257 .\"{{{  modes
3259 Like vi, there are two modes: insert mode and command mode.
3260 In insert mode, most characters are simply put in the buffer at the
3261 current cursor position as they are typed, however, some characters
3262 are treated specially.
3263 In particular, the following characters are taken from current tty settings
3264 (see \fIstty\fP(1)) and have their usual meaning (normal values are in
3265 parentheses):
3266 kill (\fB^U\fP), erase (\fB^?\fP), werase (\fB^W\fP), eof (\fB^D\fP),
3267 intr (\fB^C\fP) and quit (\fB^\e\fP).
3268 In addition to the above, the following characters are also treated
3269 specially in insert mode:
3271 expand;
3272 afB lw(4.5i).
3273 ^H      T{
3274 erases previous character
3276 ^V      T{
3277 literal next: the next character typed is not treated specially (can be
3278 used to insert the characters being described here)
3280 ^J ^M   T{
3281 end of line: the current line is read, parsed and executed by the shell
3283 <esc>   T{
3284 puts the editor in command mode (see below)
3286 ^E      T{
3287 command and file name enumeration (see below)
3289 ^F      T{
3290 command and file name completion (see below).
3291 If used twice in a row, the list of possible completions is displayed;
3292 if used a third time, the completion is undone.
3294 ^X      T{
3295 command and file name expansion (see below)
3297 <tab>   T{
3298 optional file name and command completion (see \fB^F\fP above), enabled with
3299 \fBset \-o vi-tabcomplete\fP
3302 .\"}}}
3303 .\"{{{  command mode
3305 In command mode, each character is interpreted as a command.
3306 Characters that don't correspond to commands, are illegal combinations of
3307 commands or are commands that can't be carried out all cause beeps.
3308 In the following command descriptions, a \fIn\fP indicates the
3309 command may be prefixed by a number (\fIe.g.\fP, \fB10l\fP moves right 10
3310 characters); if no number prefix is used, \fIn\fP is assumed to be 1
3311 unless otherwise specified.
3312 The term `current position' refers to the position between the cursor
3313 and the character preceding the cursor.
3314 A `word' is a sequence of letters, digits and underscore characters or a
3315 sequence of non-letter, non-digit, non-underscore, non-white-space characters
3316 (\fIe.g.\fP, ab2*&^ contains two words) and a `big-word' is a sequence of
3317 non-white-space characters.
3318 .\"{{{  Special ksh vi commands
3319 .IP "Special ksh vi commands"
3320 The following commands are not in, or are different from, the normal vi file
3321 editor:
3323 .IP "\fIn\fP\fB_\fP"
3324 insert a space followed by the \fIn\fPth big-word from the last command in the
3325 history at the current position and enter insert mode; if \fIn\fP is not
3326 specified, the last word is inserted.
3327 .IP "\fB#\fP"
3328 insert the comment character (\fB#\fP) at the start of the current line and
3329 return the line to the shell (equivalent to \fBI#^J\fP).
3330 .IP "\fIn\fP\fBg\fP"
3331 like \fBG\fP, except if \fIn\fP is not specified, it goes to the most recent
3332 remembered line.
3333 .IP "\fIn\fP\fBv\fP"
3334 edit line \fIn\fP using the vi editor;
3335 if \fIn\fP is not specified, the current line is edited.
3336 The actual command executed is
3337 `\fBfc \-e ${VISUAL:-${EDITOR:-vi}}\fP \fIn\fP'.
3338 .IP "\fB*\fP and \fB^X\fP"
3339 command or file name expansion is applied to the current big-word
3340 (with an appended *, if the word contains no file globing characters) - the
3341 big-word is replaced with the resulting words.
3342 If the current big-word is the first on the line (or follows one
3343 of the following characters: \fB;\fP, \fB|\fP, \fB&\fP, \fB(\fP, \fB)\fP)
3344 and does not contain a slash (\fB/\fP) then command expansion is done,
3345 otherwise file name expansion is done.
3346 Command expansion will match the big-word against all aliases, functions
3347 and built-in commands as well as any executable files found by searching
3348 the directories in the \fBPATH\fP parameter.
3349 File name expansion matches the big-word against the files in the
3350 current directory.
3351 After expansion, the cursor is placed just past the last word and the editor
3352 is in insert mode.
3353 .IP "\fIn\fP\fB\e\fP, \fIn\fP\fB^F\fP, \fIn\fP\fB<tab>\fP and \fIn\fP\fB<esc>\fP"
3354 command/file name completion:
3355 replace the current big-word with the longest unique
3356 match obtained after performing command/file name expansion.
3357 \fB<tab>\fP is only recognized if the \fBvi-tabcomplete\fP option is set,
3358 while \fB<esc>\fP is only recognized if the \fBvi-esccomplete\fP option
3359 is set (see \fBset \-o\fP).
3360 If \fIn\fP is specified, the \fIn\fPth possible
3361 completion is selected (as reported by the command/file name enumeration
3362 command).
3363 .IP "\fB=\fP and \fB^E\fP"
3364 command/file name enumeration: list all the commands or files that match
3365 the current big-word.
3366 .IP "\fB^V\fP"
3367 display the version of pdksh; it is displayed until another key is pressed
3368 (this key is ignored).
3369 .IP "\fB@\fP\fIc\fP"
3370 macro expansion: execute the commands found in the alias _\fIc\fP.
3372 .\"}}}
3373 .\"{{{  Intra-line movement commands
3374 .IP "Intra-line movement commands"
3376 .IP "\fIn\fP\fBh\fP and \fIn\fP\fB^H\fP"
3377 move left \fIn\fP characters.
3378 .IP "\fIn\fP\fBl\fP and \fIn\fP\fB<space>\fP"
3379 move right \fIn\fP characters.
3380 .IP "\fB0\fP"
3381 move to column 0.
3382 .IP "\fB^\fP"
3383 move to the first non white-space character.
3384 .IP "\fIn\fP\fB|\fP"
3385 move to column \fIn\fP.
3386 .IP "\fB$\fP"
3387 move to the last character.
3388 .IP "\fIn\fP\fBb\fP"
3389 move back \fIn\fP words.
3390 .IP "\fIn\fP\fBB\fP"
3391 move back \fIn\fP big-words.
3392 .IP "\fIn\fP\fBe\fP"
3393 move forward to the end the word, \fIn\fP times.
3394 .IP "\fIn\fP\fBE\fP"
3395 move forward to the end the big-word, \fIn\fP times.
3396 .IP "\fIn\fP\fBw\fP"
3397 move forward \fIn\fP words.
3398 .IP "\fIn\fP\fBW\fP"
3399 move forward \fIn\fP big-words.
3400 .IP "\fB%\fP"
3401 find match: the editor looks forward for the nearest parenthesis,
3402 bracket or brace and then moves the to the matching parenthesis, bracket or
3403 brace.
3404 .IP "\fIn\fP\fBf\fP\fIc\fP"
3405 move forward to the \fIn\fPth occurrence of the character \fIc\fP.
3406 .IP "\fIn\fP\fBF\fP\fIc\fP"
3407 move backward to the \fIn\fPth occurrence of the character \fIc\fP.
3408 .IP "\fIn\fP\fBt\fP\fIc\fP"
3409 move forward to just before the \fIn\fPth occurrence of the character \fIc\fP.
3410 .IP "\fIn\fP\fBT\fP\fIc\fP"
3411 move backward to just before the \fIn\fPth occurrence of the character \fIc\fP.
3412 .IP "\fIn\fP\fB;\fP"
3413 repeats the last \fBf\fP, \fBF\fP, \fBt\fP or \fBT\fP command.
3414 .IP "\fIn\fP\fB,\fP"
3415 repeats the last \fBf\fP, \fBF\fP, \fBt\fP or \fBT\fP command, but moves
3416 in the opposite direction.
3418 .\"}}}
3419 .\"{{{  Inter-line movement commands
3420 .IP "Inter-line movement commands"
3422 .IP "\fIn\fP\fBj\fP and \fIn\fP\fB+\fP and \fIn\fP\fB^N\fP"
3423 move to the \fIn\fPth next line in the history.
3424 .IP "\fIn\fP\fBk\fP and \fIn\fP\fB-\fP and \fIn\fP\fB^P\fP"
3425 move to the \fIn\fPth previous line in the history.
3426 .IP "\fIn\fP\fBG\fP"
3427 move to line \fIn\fP in the history; if \fIn\fP is not specified, the
3428 number first remembered line is used.
3429 .IP "\fIn\fP\fBg\fP"
3430 like \fBG\fP, except if \fIn\fP is not specified, it goes to the most recent
3431 remembered line.
3432 .IP "\fIn\fP\fB/\fP\fIstring\fP"
3433 search backward through the history for the \fIn\fPth line containing
3434 \fIstring\fP; if \fIstring\fP starts with \fB^\fP, the remainder of the
3435 string must appear at the start of the history line for it to match.
3436 .IP "\fIn\fP\fB?\fP\fIstring\fP"
3437 same as \fB/\fP, except it searches forward through the history.
3438 .IP "\fIn\fP\fBn\fP"
3439 search for the \fIn\fPth occurrence of the last search string; the
3440 direction of the search is the same as the last search.
3441 .IP "\fIn\fP\fBN\fP"
3442 search for the \fIn\fPth occurrence of the last search string; the
3443 direction of the search is the opposite of the last search.
3445 .\"}}}
3446 .\"{{{  Edit commands
3447 .IP "Edit commands"
3449 .IP "\fIn\fP\fBa\fP"
3450 append text \fIn\fP times: goes into insert mode just after the current
3451 position.
3452 The append is only replicated if command mode is re-entered (\fIi.e.\fP,
3453 <esc> is used).
3454 .IP "\fIn\fP\fBA\fP"
3455 same as \fBa\fP, except it appends at the end of the line.
3456 .IP "\fIn\fP\fBi\fP"
3457 insert text \fIn\fP times: goes into insert mode at the current
3458 position.
3459 The insertion is only replicated if command mode is re-entered (\fIi.e.\fP,
3460 <esc> is used).
3461 .IP "\fIn\fP\fBI\fP"
3462 same as \fBi\fP, except the insertion is done just before the first non-blank
3463 character.
3464 .IP "\fIn\fP\fBs\fP"
3465 substitute the next \fIn\fP characters (\fIi.e.\fP, delete the characters
3466 and go into insert mode).
3467 .IP "\fBS\fP"
3468 substitute whole line: all characters from the first non-blank character
3469 to the end of line are deleted and insert mode is entered.
3470 .IP "\fIn\fP\fBc\fP\fImove-cmd\fP"
3471 change from the current position to the position resulting from \fIn\fP
3472 \fImove-cmd\fPs (\fIi.e.\fP, delete the indicated region and go into insert
3473 mode);
3474 if \fImove-cmd\fP is \fBc\fP, the line starting from the first non-blank
3475 character is changed.
3476 .IP "\fBC\fP"
3477 change from the current position to the end of the line (\fIi.e.\fP, delete to
3478 the end of the line and go into insert mode).
3479 .IP "\fIn\fP\fBx\fP"
3480 delete the next \fIn\fP characters.
3481 .IP "\fIn\fP\fBX\fP"
3482 delete the previous \fIn\fP characters.
3483 .IP "\fBD\fP"
3484 delete to the end of the line.
3485 .IP "\fIn\fP\fBd\fP\fImove-cmd\fP"
3486 delete from the current position to the position resulting from
3487 \fIn\fP \fImove-cmd\fPs;
3488 \fImove-cmd\fP is a movement command (see above) or \fBd\fP, in which case
3489 the current line is deleted.
3490 .IP "\fIn\fP\fBr\fP\fIc\fP"
3491 replace the next \fIn\fP characters with the character \fIc\fP.
3492 .IP "\fIn\fP\fBR\fP"
3493 replace: enter insert mode but overwrite existing characters instead of
3494 inserting before existing characters.
3495 The replacement is repeated \fIn\fP times.
3496 .IP "\fIn\fP\fB~\fP"
3497 change the case of the next \fIn\fP characters.
3498 .IP "\fIn\fP\fBy\fP\fImove-cmd\fP"
3499 yank from the current position to the position resulting from \fIn\fP
3500 \fImove-cmd\fPs into the yank buffer; if \fImove-cmd\fP is \fBy\fP, the
3501 whole line is yanked.
3502 .IP "\fBY\fP"
3503 yank from the current position to the end of the line.
3504 .IP "\fIn\fP\fBp\fP"
3505 paste the contents of the yank buffer just after the current position,
3506 \fIn\fP times.
3507 .IP "\fIn\fP\fBP\fP"
3508 same as \fBp\fP, except the buffer is pasted at the current position.
3510 .\"}}}
3511 .\"{{{  Miscellaneous vi commands
3512 .IP "Miscellaneous vi commands"
3514 .IP "\fB^J\fP and \fB^M\fP"
3515 the current line is read, parsed and executed by the shell.
3516 .IP "\fB^L\fP and \fB^R\fP"
3517 redraw the current line.
3518 .IP "\fIn\fP\fB.\fP"
3519 redo the last edit command \fIn\fP times.
3520 .IP "\fBu\fP"
3521 undo the last edit command.
3522 .IP "\fBU\fP"
3523 undo all changes that have been made to the current line.
3524 .IP "\fIintr\fP and \fIquit\fP"
3525 the interrupt and quit terminal characters cause the current line to
3526 be deleted and a new prompt to be printed.
3528 .\"Has all vi commands except:
3529 .\"    movement: { } [[ ]] ^E ^Y ^U ^D ^F ^B H L M ()
3530 .\"    tag commands: ^T ^]
3531 .\"    mark commands: m ` '
3532 .\"    named-buffer commands: " @
3533 .\"    file/shell/ex-commands: Q ZZ ^^ : ! &
3534 .\"    multi-line change commands: o O J
3535 .\"    shift commands: << >>
3536 .\"    status command: ^G
3537 .\"}}}
3538 .\"}}}
3539 .\"}}}
3540 .ksh)
3541 .\"}}}
3542 .\"}}}
3543 .\"{{{  Files
3544 .SH FILES
3545 ~/.kshrc
3547 ~/.profile
3549 /etc/profile
3551 /etc/suid_profile
3552 .\"}}}
3553 .\"{{{  Bugs
3554 .SH BUGS
3555 Any bugs in pdksh should be reported to pdksh@cs.mun.ca.
3556 Please
3557 include the version of pdksh (echo $KSH_VERSION shows it), the machine,
3558 operating system and compiler you are using and a description of how to
3559 repeat the bug (a small shell script that demonstrates the bug is
3560 best).
3561 The following, if relevant (if you are not sure, include them),
3562 can also helpful: options you are using (both options.h options and set
3563 \-o options) and a copy of your config.h (the file generated by the
3564 configure script).
3565 New versions of pdksh can be obtained from
3566 ftp://ftp.cs.mun.ca/pub/pdksh/.
3568 BTW, the most frequently reported bug is
3570 \fB echo hi | read a; echo $a\fP\ \ \ # Does not print hi
3572 I'm aware of this and there is no need to report it.
3573 .\"}}}
3574 .\"{{{  Version
3575 .SH VERSION
3576 This page documents version
3578  @(#)PD KSH v5.2.14 99/07/13.2
3579 of the public domain korn shell.
3580 .\"}}}
3581 .\"{{{  Authors
3582 .SH AUTHORS
3583 This shell is based on the public domain 7th edition Bourne shell clone by
3584 Charles Forsyth and parts of the BRL shell by Doug A.\& Gwyn, Doug Kingston,
3585 Ron Natalie, Arnold Robbins, Lou Salkind and others.
3586 The first release
3587 of pdksh was created by Eric Gisin, and it was subsequently maintained by
3588 John R.\& MacMillan (chance!john@sq.sq.com), and
3589 Simon J.\& Gerraty (sjg@zen.void.oz.au).
3590 The current maintainer is Michael Rendell (michael@cs.mun.ca).
3591 The CONTRIBUTORS file in the source distribution contains a more complete
3592 list of people and their part in the shell's development.
3593 .\"}}}
3594 .\"{{{  See also
3595 .SH "SEE ALSO"
3596 awk(1),
3597 .ksh(
3598 sh(1),
3599 .ksh)
3600 .sh(
3601 ksh(1),
3602 .sh)
3603 csh(1), ed(1), getconf(1), getopt(1), sed(1), stty(1), vi(1),
3604 dup(2), execve(2), getgid(2), getuid(2), open(2), pipe(2), wait(2),
3605 getopt(3), rand(3), signal(3), system(3),
3606 environ(7)
3608 .IR "The KornShell Command and Programming Language" ,
3609 Morris Bolsky and David Korn, 1989, ISBN 0-13-516972-0.
3611 .\" XXX ISBN missing
3612 .IR "UNIX Shell Programming" ,
3613 Stephen G.\& Kochan, Patrick H.\& Wood, Hayden.
3615 .IR "IEEE Standard for information Technology \- Portable Operating System Interface (POSIX) \- Part 2: Shell and Utilities" ,
3616 IEEE Inc, 1993, ISBN 1-55937-255-9.
3617 .\"}}}