1MKSH(1)                   BSD General Commands Manual                  MKSH(1)
2

NAME

4     mksh, sh — MirBSD Korn shell
5

SYNOPSIS

7     mksh [-+abCefhiklmnprUuvXx] [-T /dev/ttyCn | -] [-+o option] [-c string |
8          -s | file [argument ...]]
9     builtin-name [argument ...]
10

DESCRIPTION

12     mksh is a command interpreter intended for both interactive and shell
13     script use.  Its command language is a superset of the sh(C) shell lan‐
14     guage and largely compatible to the original Korn shell.
15
16     Most builtins can be called directly, for example if a link points from
17     its name to the shell; not all make sense, have been tested or work at
18     all though.
19
20     The options are as follows:
21
22     -c string  mksh will execute the command(s) contained in string.
23
24     -i         Interactive shell.  A shell is “interactive” if this option is
25                used or if both standard input and standard error are attached
26                to a tty(4).  An interactive shell has job control enabled,
27                ignores the SIGINT, SIGQUIT, and SIGTERM signals, and prints
28                prompts before reading input (see the PS1 and PS2 parameters).
29                It also processes the ENV parameter or the mkshrc file (see
30                below).  For non-interactive shells, the trackall option is on
31                by default (see the set command below).
32
33     -l         Login shell.  If the basename the shell is called with (i.e.
34                argv[0]) starts with ‘-’ or if this option is used, the shell
35                is assumed to be a login shell; see Startup files below.
36
37     -p         Privileged shell.  A shell is “privileged” if this option is
38                used or if the real user ID or group ID does not match the
39                effective user ID or group ID (see getuid(2) and getgid(2)).
40                Clearing the privileged option causes the shell to set its
41                effective user ID (group ID) to its real user ID (group ID).
42                For further implications, see Startup files.
43
44     -r         Restricted shell.  A shell is “restricted” if this option is
45                used.  The following restrictions come into effect after the
46                shell processes any profile and ENV files:
47
48                ·   The cd (and chdir) command is disabled.
49                ·   The SHELL, ENV, and PATH parameters cannot be changed.
50                ·   Command names can't be specified with absolute or relative
51                    paths.
52                ·   The -p option of the built-in command command can't be
53                    used.
54                ·   Redirections that create files can't be used (i.e. ‘>’,
55                    ‘>|’, ‘>>’, ‘<>’).
56
57     -s         The shell reads commands from standard input; all non-option
58                arguments are positional parameters.
59
60     -T tty     Spawn mksh on the tty(4) device given.  Superuser only.  If
61                tty is a dash, detach from controlling terminal (daemonise)
62                instead.
63
64     In addition to the above, the options described in the set built-in com‐
65     mand can also be used on the command line: both [-+abCefhkmnuvXx] and
66     [-+o option] can be used for single letter or long options, respectively.
67
68     If neither the -c nor the -s option is specified, the first non-option
69     argument specifies the name of a file the shell reads commands from.  If
70     there are no non-option arguments, the shell reads commands from the
71     standard input.  The name of the shell (i.e. the contents of $0) is
72     determined as follows: if the -c option is used and there is a non-option
73     argument, it is used as the name; if commands are being read from a file,
74     the file is used as the name; otherwise, the basename the shell was
75     called with (i.e. argv[0]) is used.
76
77     The exit status of the shell is 127 if the command file specified on the
78     command line could not be opened, or non-zero if a fatal syntax error
79     occurred during the execution of a script.  In the absence of fatal
80     errors, the exit status is that of the last command executed, or zero, if
81     no command is executed.
82
83   Startup files
84     For the actual location of these files, see FILES.  A login shell pro‐
85     cesses the system profile first.  A privileged shell then processes the
86     suid profile.  A non-privileged login shell processes the user profile
87     next.  A non-privileged interactive shell checks the value of the ENV
88     parameter after subjecting it to parameter, command, arithmetic and tilde
89     (‘~’) substitution; if unset or empty, the user mkshrc profile is pro‐
90     cessed; otherwise, if a file whose name is the substitution result
91     exists, it is processed; non-existence is silently ignored.
92
93   Command syntax
94     The shell begins parsing its input by removing any backslash-newline com‐
95     binations, then breaking it into words.  Words (which are sequences of
96     characters) are delimited by unquoted whitespace characters (space, tab,
97     and newline) or meta-characters (‘<’, ‘>’, ‘|’, ‘;’, ‘(’, ‘)’, and ‘&’).
98     Aside from delimiting words, spaces and tabs are ignored, while newlines
99     usually delimit commands.  The meta-characters are used in building the
100     following tokens: ‘<’, ‘<&’, ‘<<’, ‘<<<’, ‘>’, ‘>&’, ‘>>’, ‘&>’, etc. are
101     used to specify redirections (see Input/output redirection below); ‘|’ is
102     used to create pipelines; ‘|&’ is used to create co-processes (see
103     Co-processes below); ‘;’ is used to separate commands; ‘&’ is used to
104     create asynchronous pipelines; ‘&&’ and ‘||’ are used to specify condi‐
105     tional execution; ‘;;’, ‘;&’ and ‘;|’ are used in case statements; ‘(( ..
106     ))’ is used in arithmetic expressions; and lastly, ‘( .. )’ is used to
107     create subshells.
108
109     Whitespace and meta-characters can be quoted individually using a back‐
110     slash (‘\’), or in groups using double (‘"’) or single (‘'’) quotes.
111     Note that the following characters are also treated specially by the
112     shell and must be quoted if they are to represent themselves: ‘\’, ‘"’,
113     ‘'’, ‘#’, ‘$’, ‘`’, ‘~’, ‘{’, ‘}’, ‘*’, ‘?’, and ‘[’.  The first three of
114     these are the above mentioned quoting characters (see Quoting below);
115     ‘#’, if used at the beginning of a word, introduces a comment – every‐
116     thing after the ‘#’ up to the nearest newline is ignored; ‘$’ is used to
117     introduce parameter, command, and arithmetic substitutions (see
118     Substitution below); ‘`’ introduces an old-style command substitution
119     (see Substitution below); ‘~’ begins a directory expansion (see Tilde
120     expansion below); ‘{’ and ‘}’ delimit csh(1)-style alterations (see Brace
121     expansion below); and finally, ‘*’, ‘?’, and ‘[’ are used in file name
122     generation (see File name patterns below).
123
124     As words and tokens are parsed, the shell builds commands, of which there
125     are two basic types: simple-commands, typically programmes that are exe‐
126     cuted, and compound-commands, such as for and if statements, grouping
127     constructs, and function definitions.
128
129     A simple-command consists of some combination of parameter assignments
130     (see Parameters below), input/output redirections (see Input/output
131     redirections below), and command words; the only restriction is that
132     parameter assignments come before any command words.  The command words,
133     if any, define the command that is to be executed and its arguments.  The
134     command may be a shell built-in command, a function, or an external com‐
135     mand (i.e. a separate executable file that is located using the PATH
136     parameter; see Command execution below).  Note that all command con‐
137     structs have an exit status: for external commands, this is related to
138     the status returned by wait(2) (if the command could not be found, the
139     exit status is 127; if it could not be executed, the exit status is 126);
140     the exit status of other command constructs (built-in commands, func‐
141     tions, compound-commands, pipelines, lists, etc.) are all well-defined
142     and are described where the construct is described.  The exit status of a
143     command consisting only of parameter assignments is that of the last com‐
144     mand substitution performed during the parameter assignment or 0 if there
145     were no command substitutions.
146
147     Commands can be chained together using the ‘|’ token to form pipelines,
148     in which the standard output of each command but the last is piped (see
149     pipe(2)) to the standard input of the following command.  The exit status
150     of a pipeline is that of its last command.  All commands of a pipeline
151     are executed in separate subshells; this is allowed by POSIX but differs
152     from both variants of AT&T UNIX ksh, where all but the last command were
153     executed in subshells; see the read builtin's description for implica‐
154     tions and workarounds.  A pipeline may be prefixed by the ‘!’ reserved
155     word which causes the exit status of the pipeline to be logically comple‐
156     mented: if the original status was 0, the complemented status will be 1;
157     if the original status was not 0, the complemented status will be 0.
158
159     Lists of commands can be created by separating pipelines by any of the
160     following tokens: ‘&&’, ‘||’, ‘&’, ‘|&’, and ‘;’.  The first two are for
161     conditional execution: “cmd1 && cmd2” executes cmd2 only if the exit sta‐
162     tus of cmd1 is zero; ‘||’ is the opposite – cmd2 is executed only if the
163     exit status of cmd1 is non-zero.  ‘&&’ and ‘||’ have equal precedence
164     which is higher than that of ‘&’, ‘|&’, and ‘;’, which also have equal
165     precedence.  Note that the ‘&&’ and ‘||’ operators are
166     "left-associative".  For example, both of these commands will print only
167     "bar":
168
169           $ false && echo foo || echo bar
170           $ true || echo foo && echo bar
171
172     The ‘&’ token causes the preceding command to be executed asynchronously;
173     that is, the shell starts the command but does not wait for it to com‐
174     plete (the shell does keep track of the status of asynchronous commands;
175     see Job control below).  When an asynchronous command is started when job
176     control is disabled (i.e. in most scripts), the command is started with
177     signals SIGINT and SIGQUIT ignored and with input redirected from
178     /dev/null (however, redirections specified in the asynchronous command
179     have precedence).  The ‘|&’ operator starts a co-process which is a spe‐
180     cial kind of asynchronous process (see Co-processes below).  Note that a
181     command must follow the ‘&&’ and ‘||’ operators, while it need not follow
182     ‘&’, ‘|&’, or ‘;’.  The exit status of a list is that of the last command
183     executed, with the exception of asynchronous lists, for which the exit
184     status is 0.
185
186     Compound commands are created using the following reserved words.  These
187     words are only recognised if they are unquoted and if they are used as
188     the first word of a command (i.e. they can't be preceded by parameter
189     assignments or redirections):
190
191           case     else     function     then      !       (
192           do       esac     if           time      [[      ((
193           done     fi       in           until     {
194           elif     for      select       while     }
195
196     In the following compound command descriptions, command lists (denoted as
197     list) that are followed by reserved words must end with a semicolon, a
198     newline, or a (syntactically correct) reserved word.  For example, the
199     following are all valid:
200
201           $ { echo foo; echo bar; }
202           $ { echo foo; echo bar<newline>}
203           $ { { echo foo; echo bar; } }
204
205     This is not valid:
206
207           $ { echo foo; echo bar }
208
209     (list)
210           Execute list in a subshell.  There is no implicit way to pass envi‐
211           ronment changes from a subshell back to its parent.
212
213     { list; }
214           Compound construct; list is executed, but not in a subshell.  Note
215           that ‘{’ and ‘}’ are reserved words, not meta-characters.
216
217     case word in [[(] pattern [| pat] ...) list [;; | ;& | ;| ]] ... esac
218           The case statement attempts to match word against a specified
219           pattern; the list associated with the first successfully matched
220           pattern is executed.  Patterns used in case statements are the same
221           as those used for file name patterns except that the restrictions
222           regarding ‘.’ and ‘/’ are dropped.  Note that any unquoted space
223           before and after a pattern is stripped; any space within a pattern
224           must be quoted.  Both the word and the patterns are subject to
225           parameter, command, and arithmetic substitution, as well as tilde
226           substitution.
227
228           For historical reasons, open and close braces may be used instead
229           of in and esac e.g. case $foo { *) echo bar;; }.
230
231           The list terminators are:
232
233           ‘;;’  Terminate after the list.
234
235           ‘;&’  Fall through into the next list.
236
237           ‘;|’  Evaluate the remaining pattern-list tuples.
238
239           The exit status of a case statement is that of the executed list;
240           if no list is executed, the exit status is zero.
241
242     for name [in word ...]; do list; done
243           For each word in the specified word list, the parameter name is set
244           to the word and list is executed.  If in is not used to specify a
245           word list, the positional parameters ($1, $2, etc.) are used
246           instead.  For historical reasons, open and close braces may be used
247           instead of do and done e.g. for i; { echo $i; }.  The exit status
248           of a for statement is the last exit status of list; if list is
249           never executed, the exit status is zero.
250
251     if list; then list; [elif list; then list;] ... [else list;] fi
252           If the exit status of the first list is zero, the second list is
253           executed; otherwise, the list following the elif, if any, is exe‐
254           cuted with similar consequences.  If all the lists following the if
255           and elifs fail (i.e. exit with non-zero status), the list following
256           the else is executed.  The exit status of an if statement is that
257           of non-conditional list that is executed; if no non-conditional
258           list is executed, the exit status is zero.
259
260     select name [in word ...]; do list; done
261           The select statement provides an automatic method of presenting the
262           user with a menu and selecting from it.  An enumerated list of the
263           specified word(s) is printed on standard error, followed by a
264           prompt (PS3: normally ‘#? ’).  A number corresponding to one of the
265           enumerated words is then read from standard input, name is set to
266           the selected word (or unset if the selection is not valid), REPLY
267           is set to what was read (leading/trailing space is stripped), and
268           list is executed.  If a blank line (i.e. zero or more IFS octets)
269           is entered, the menu is reprinted without executing list.
270
271           When list completes, the enumerated list is printed if REPLY is
272           NULL, the prompt is printed, and so on.  This process continues
273           until an end-of-file is read, an interrupt is received, or a break
274           statement is executed inside the loop.  If “in word ...” is omit‐
275           ted, the positional parameters are used (i.e. $1, $2, etc.).  For
276           historical reasons, open and close braces may be used instead of do
277           and done e.g. select i; { echo $i; }.  The exit status of a select
278           statement is zero if a break statement is used to exit the loop,
279           non-zero otherwise.
280
281     until list; do list; done
282           This works like while, except that the body is executed only while
283           the exit status of the first list is non-zero.
284
285     while list; do list; done
286           A while is a pre-checked loop.  Its body is executed as often as
287           the exit status of the first list is zero.  The exit status of a
288           while statement is the last exit status of the list in the body of
289           the loop; if the body is not executed, the exit status is zero.
290
291     function name { list; }
292           Defines the function name (see Functions below).  Note that redi‐
293           rections specified after a function definition are performed when‐
294           ever the function is executed, not when the function definition is
295           executed.
296
297     name() command
298           Mostly the same as function (see Functions below).  Whitespace
299           (space or tab) after name will be ignored most of the time.
300
301     function name() { list; }
302           The same as name() (bashism).  The function keyword is ignored.
303
304     time [-p] [pipeline]
305           The Command execution section describes the time reserved word.
306
307     (( expression ))
308           The arithmetic expression expression is evaluated; equivalent to
309           “let expression” (see Arithmetic expressions and the let command,
310           below).
311
312     [[ expression ]]
313           Similar to the test and [ ... ] commands (described later), with
314           the following exceptions:
315
316           ·   Field splitting and file name generation are not performed on
317               arguments.
318
319           ·   The -a (AND) and -o (OR) operators are replaced with ‘&&’ and
320               ‘||’, respectively.
321
322           ·   Operators (e.g. ‘-f’, ‘=’, ‘!’) must be unquoted.
323
324           ·   Parameter, command, and arithmetic substitutions are performed
325               as expressions are evaluated and lazy expression evaluation is
326               used for the ‘&&’ and ‘||’ operators.  This means that in the
327               following statement, $(<foo) is evaluated if and only if the
328               file foo exists and is readable:
329
330                     $ [[ -r foo && $(<foo) = b*r ]]
331
332           ·   The second operand of the ‘!=’ and ‘=’ expressions are patterns
333               (e.g. the comparison [[ foobar = f*r ]] succeeds).  This even
334               works indirectly:
335
336                     $ bar=foobar; baz='f*r'
337                     $ [[ $bar = $baz ]]; echo $?
338                     $ [[ $bar = "$baz" ]]; echo $?
339
340               Perhaps surprisingly, the first comparison succeeds, whereas
341               the second doesn't.
342
343   Quoting
344     Quoting is used to prevent the shell from treating characters or words
345     specially.  There are three methods of quoting.  First, ‘\’ quotes the
346     following character, unless it is at the end of a line, in which case
347     both the ‘\’ and the newline are stripped.  Second, a single quote (‘'’)
348     quotes everything up to the next single quote (this may span lines).
349     Third, a double quote (‘"’) quotes all characters, except ‘$’, ‘`’ and
350     ‘\’, up to the next unquoted double quote.  ‘$’ and ‘`’ inside double
351     quotes have their usual meaning (i.e. parameter, command, or arithmetic
352     substitution) except no field splitting is carried out on the results of
353     double-quoted substitutions.  If a ‘\’ inside a double-quoted string is
354     followed by ‘\’, ‘$’, ‘`’, or ‘"’, it is replaced by the second charac‐
355     ter; if it is followed by a newline, both the ‘\’ and the newline are
356     stripped; otherwise, both the ‘\’ and the character following are
357     unchanged.
358
359     If a single-quoted string is preceded by an unquoted ‘$’, C style back‐
360     slash expansion (see below) is applied (even single quote characters
361     inside can be escaped and do not terminate the string then); the expanded
362     result is treated as any other single-quoted string.  If a double-quoted
363     string is preceded by an unquoted ‘$’, the latter is ignored.
364
365   Backslash expansion
366     In places where backslashes are expanded, certain C and AT&T UNIX ksh or
367     GNU bash style escapes are translated.  These include ‘\a’, ‘\b’, ‘\f’,
368     ‘\n’, ‘\r’, ‘\t’, ‘\U########’, ‘\u####’, and ‘\v’.  For ‘\U########’ and
369     ‘\u####’, “#” means a hexadecimal digit, of thich there may be none up to
370     four or eight; these escapes translate a Unicode codepoint to UTF-8.
371     Furthermore, ‘\E’ and ‘\e’ expand to the escape character.
372
373     In the print builtin mode, ‘\"’, ‘\'’, and ‘\?’ are explicitly excluded;
374     octal sequences must have the none up to three octal digits “#” prefixed
375     with the digit zero (‘\0###’); hexadecimal sequences ‘\x##’ are limited
376     to none up to two hexadecimal digits “#”; both octal and hexadecimal
377     sequences convert to raw octets; ‘\#’, where # is none of the above,
378     translates to \# (backslashes are retained).
379
380     Backslash expansion in the C style mode slightly differs: octal sequences
381     ‘\###’ must have no digit zero prefixing the one up to three octal digits
382     “#” and yield raw octets; hexadecimal sequences ‘\x#*’ greedily eat up as
383     many hexadecimal digits “#” as they can and terminate with the first non-
384     hexadecimal digit; these translate a Unicode codepoint to UTF-8.  The
385     sequence ‘\c#’, where “#” is any octet, translates to Ctrl-# (which basi‐
386     cally means, ‘\c?’ becomes DEL, everything else is bitwise ANDed with
387     0x1F).  Finally, ‘\#’, where # is none of the above, translates to # (has
388     the backslash trimmed), even if it is a newline.
389
390   Aliases
391     There are two types of aliases: normal command aliases and tracked
392     aliases.  Command aliases are normally used as a short hand for a long or
393     often used command.  The shell expands command aliases (i.e. substitutes
394     the alias name for its value) when it reads the first word of a command.
395     An expanded alias is re-processed to check for more aliases.  If a com‐
396     mand alias ends in a space or tab, the following word is also checked for
397     alias expansion.  The alias expansion process stops when a word that is
398     not an alias is found, when a quoted word is found, or when an alias word
399     that is currently being expanded is found.
400
401     The following command aliases are defined automatically by the shell:
402
403           autoload='typeset -fu'
404           functions='typeset -f'
405           hash='alias -t'
406           history='fc -l'
407           integer='typeset -i'
408           local='typeset'
409           login='exec login'
410           nameref='typeset -n'
411           nohup='nohup '
412           r='fc -e -'
413           stop='kill -STOP'
414           suspend='kill -STOP $$'
415           type='whence -v'
416
417     Tracked aliases allow the shell to remember where it found a particular
418     command.  The first time the shell does a path search for a command that
419     is marked as a tracked alias, it saves the full path of the command.  The
420     next time the command is executed, the shell checks the saved path to see
421     that it is still valid, and if so, avoids repeating the path search.
422     Tracked aliases can be listed and created using alias -t.  Note that
423     changing the PATH parameter clears the saved paths for all tracked
424     aliases.  If the trackall option is set (i.e. set -o trackall or set -h),
425     the shell tracks all commands.  This option is set automatically for non-
426     interactive shells.  For interactive shells, only the following commands
427     are automatically tracked: cat(1), cc(1), chmod(1), cp(1), date(1),
428     ed(1), emacs(1), grep(1), ls(1), make(1), mv(1), pr(1), rm(1), sed(1),
429     sh(1), vi(1), and who(1).
430
431   Substitution
432     The first step the shell takes in executing a simple-command is to per‐
433     form substitutions on the words of the command.  There are three kinds of
434     substitution: parameter, command, and arithmetic.  Parameter substitu‐
435     tions, which are described in detail in the next section, take the form
436     $name or ${...}; command substitutions take the form $(command) or (dep‐
437     recated) `command`; and arithmetic substitutions take the form
438     $((expression)).
439
440     If a substitution appears outside of double quotes, the results of the
441     substitution are generally subject to word or field splitting according
442     to the current value of the IFS parameter.  The IFS parameter specifies a
443     list of octets which are used to break a string up into several words;
444     any octets from the set space, tab, and newline that appear in the IFS
445     octets are called “IFS whitespace”.  Sequences of one or more IFS white‐
446     space octets, in combination with zero or one non-IFS whitespace octets,
447     delimit a field.  As a special case, leading and trailing IFS whitespace
448     and trailing IFS non-whitespace are stripped (i.e. no leading or trailing
449     empty field is created by it); leading non-IFS whitespace does create an
450     empty field.
451
452     Example: If IFS is set to “<space>:”, and VAR is set to
453     “<space>A<space>:<space><space>B::D”, the substitution for $VAR results
454     in four fields: ‘A’, ‘B’, ‘’ (an empty field), and ‘D’.  Note that if the
455     IFS parameter is set to the NULL string, no field splitting is done; if
456     the parameter is unset, the default value of space, tab, and newline is
457     used.
458
459     Also, note that the field splitting applies only to the immediate result
460     of the substitution.  Using the previous example, the substitution for
461     $VAR:E results in the fields: ‘A’, ‘B’, ‘’, and ‘D:E’, not ‘A’, ‘B’, ‘’,
462     ‘D’, and ‘E’.  This behavior is POSIX compliant, but incompatible with
463     some other shell implementations which do field splitting on the word
464     which contained the substitution or use IFS as a general whitespace
465     delimiter.
466
467     The results of substitution are, unless otherwise specified, also subject
468     to brace expansion and file name expansion (see the relevant sections
469     below).
470
471     A command substitution is replaced by the output generated by the speci‐
472     fied command which is run in a subshell.  For $(command) substitutions,
473     normal quoting rules are used when command is parsed; however, for the
474     deprecated `command` form, a ‘\’ followed by any of ‘$’, ‘`’, or ‘\’ is
475     stripped (a ‘\’ followed by any other character is unchanged).  As a spe‐
476     cial case in command substitutions, a command of the form <file is inter‐
477     preted to mean substitute the contents of file.  Note that $(<foo) has
478     the same effect as $(cat foo).
479
480     Note that some shells do not use a recursive parser for command substitu‐
481     tions, leading to failure for certain constructs; to be portable, use as
482     workaround ‘x=$(cat) <<"EOF"’ (or the newline-keeping ‘x=<<"EOF"’ exten‐
483     sion) instead to merely slurp the string.  IEEE Std 1003.1 (“POSIX.1”)
484     recommends to use case statements of the form ‘x=$(case $foo in (bar)
485     echo $bar ;; (*) echo $baz ;; esac)’ instead, which would work but not
486     serve as example for this portability issue.
487
488           x=$(case $foo in bar) echo $bar ;; *) echo $baz ;; esac)
489           # above fails to parse on old shells; below is the workaround
490           x=$(eval $(cat)) <<"EOF"
491           case $foo in bar) echo $bar ;; *) echo $baz ;; esac
492           EOF
493
494     Arithmetic substitutions are replaced by the value of the specified
495     expression.  For example, the command print $((2+3*4)) displays 14.  See
496     Arithmetic expressions for a description of an expression.
497
498   Parameters
499     Parameters are shell variables; they can be assigned values and their
500     values can be accessed using a parameter substitution.  A parameter name
501     is either one of the special single punctuation or digit character param‐
502     eters described below, or a letter followed by zero or more letters or
503     digits (‘_’ counts as a letter).  The latter form can be treated as
504     arrays by appending an array index of the form [expr] where expr is an
505     arithmetic expression.  Array indices in mksh are limited to the range 0
506     through 4294967295, inclusive.  That is, they are a 32-bit unsigned inte‐
507     ger.
508
509     Parameter substitutions take the form $name, ${name}, or ${name[expr]}
510     where name is a parameter name.  Substitution of all array elements with
511     ${name[*]} and ${name[@]} works equivalent to $* and $@ for positional
512     parameters.  If substitution is performed on a parameter (or an array
513     parameter element) that is not set, a null string is substituted unless
514     the nounset option (set -o nounset or set -u) is set, in which case an
515     error occurs.
516
517     Parameters can be assigned values in a number of ways.  First, the shell
518     implicitly sets some parameters like ‘#’, ‘PWD’, and ‘$’; this is the
519     only way the special single character parameters are set.  Second, param‐
520     eters are imported from the shell's environment at startup.  Third,
521     parameters can be assigned values on the command line: for example,
522     FOO=bar sets the parameter “FOO” to “bar”; multiple parameter assignments
523     can be given on a single command line and they can be followed by a sim‐
524     ple-command, in which case the assignments are in effect only for the
525     duration of the command (such assignments are also exported; see below
526     for the implications of this).  Note that both the parameter name and the
527     ‘=’ must be unquoted for the shell to recognise a parameter assignment.
528     The construct FOO+=baz is also recognised; the old and new values are
529     immediately concatenated.  The fourth way of setting a parameter is with
530     the export, global, readonly, and typeset commands; see their descrip‐
531     tions in the Command execution section.  Fifth, for and select loops set
532     parameters as well as the getopts, read, and set -A commands.  Lastly,
533     parameters can be assigned values using assignment operators inside
534     arithmetic expressions (see Arithmetic expressions below) or using the
535     ${name=value} form of the parameter substitution (see below).
536
537     Parameters with the export attribute (set using the export or typeset -x
538     commands, or by parameter assignments followed by simple commands) are
539     put in the environment (see environ(7)) of commands run by the shell as
540     name=value pairs.  The order in which parameters appear in the environ‐
541     ment of a command is unspecified.  When the shell starts up, it extracts
542     parameters and their values from its environment and automatically sets
543     the export attribute for those parameters.
544
545     Modifiers can be applied to the ${name} form of parameter substitution:
546
547     ${name:-word}
548             If name is set and not NULL, it is substituted; otherwise, word
549             is substituted.
550
551     ${name:+word}
552             If name is set and not NULL, word is substituted; otherwise,
553             nothing is substituted.
554
555     ${name:=word}
556             If name is set and not NULL, it is substituted; otherwise, it is
557             assigned word and the resulting value of name is substituted.
558
559     ${name:?word}
560             If name is set and not NULL, it is substituted; otherwise, word
561             is printed on standard error (preceded by name:) and an error
562             occurs (normally causing termination of a shell script, function,
563             or script sourced using the ‘.’ built-in).  If word is omitted,
564             the string “parameter null or not set” is used instead.  Cur‐
565             rently a bug, if word is a variable which expands to the null
566             string, the error message is also printed.
567
568     Note that, for all of the above, word is actually considered quoted, and
569     special parsing rules apply.  The parsing rules also differ on whether
570     the expression is double-quoted: word then uses double-quoting rules,
571     except for the double quote itself (‘"’) and the closing brace, which, if
572     backslash escaped, gets quote removal applied.
573
574     In the above modifiers, the ‘:’ can be omitted, in which case the condi‐
575     tions only depend on name being set (as opposed to set and not NULL).  If
576     word is needed, parameter, command, arithmetic, and tilde substitution
577     are performed on it; if word is not needed, it is not evaluated.
578
579     The following forms of parameter substitution can also be used (if name
580     is an array, its element #0 will be substituted in a scalar context):
581
582     ${#name}
583             The number of positional parameters if name is ‘*’, ‘@’, or not
584             specified; otherwise the length (in characters) of the string
585             value of parameter name.
586
587     ${#name[*]}
588     ${#name[@]}
589             The number of elements in the array name.
590
591     ${%name}
592             The width (in screen columns) of the string value of parameter
593             name, or -1 if ${name} contains a control character.
594
595     ${!name}
596             The name of the variable referred to by name.  This will be name
597             except when name is a name reference (bound variable), created by
598             the nameref command (which is an alias for typeset -n).
599
600     ${!name[*]}
601     ${!name[@]}
602             The names of indices (keys) in the array name.
603
604     ${name#pattern}
605     ${name##pattern}
606             If pattern matches the beginning of the value of parameter name,
607             the matched text is deleted from the result of substitution.  A
608             single ‘#’ results in the shortest match, and two of them result
609             in the longest match.  Cannot be applied to a vector (${*} or
610             ${@} or ${array[*]} or ${array[@]}).
611
612     ${name%pattern}
613     ${name%%pattern}
614             Like ${..#..} substitution, but it deletes from the end of the
615             value.  Cannot be applied to a vector.
616
617     ${name/pattern/string}
618     ${name//pattern/string}
619             Like ${..#..} substitution, but it replaces the longest match of
620             pattern, anchored anywhere in the value, with string.  If pattern
621             begins with ‘#’, it is anchored at the beginning of the value; if
622             it begins with ‘%’, it is anchored at the end.  A single ‘/’
623             replaces the first occurence of the search pattern, and two of
624             them replace all occurences.  If /string is omitted, the pattern
625             is replaced by the empty string, i.e. deleted.  Cannot be applied
626             to a vector.  Inefficiently implemented.
627
628     ${name:pos:len}
629             The first len characters of name, starting at position pos, are
630             substituted.  Both pos and :len are optional.  If pos is nega‐
631             tive, counting starts at the end of the string; if it is omitted,
632             it defaults to 0.  If len is omitted or greater than the length
633             of the remaining string, all of it is substituted.  Both pos and
634             len are evaluated as arithmetic expressions.  Currently, pos must
635             start with a space, opening parenthesis or digit to be recog‐
636             nised.  Cannot be applied to a vector.
637
638     ${name@#}
639             The internal hash of the expansion of name.  At the moment, this
640             is OAAT1 (Bob Jenkins' one-at-a-time hash with an initialisation
641             value of 0x00000100), this will change for R41.  This is the hash
642             the shell uses internally for its associative arrays.
643
644     Note that pattern may need extended globbing pattern (@(...)), single
645     ('...') or double ("...") quote escaping unless -o sh is set.
646
647     The following special parameters are implicitly set by the shell and can‐
648     not be set directly using assignments:
649
650     !       Process ID of the last background process started.  If no back‐
651             ground processes have been started, the parameter is not set.
652
653     #       The number of positional parameters ($1, $2, etc.).
654
655     $       The PID of the shell, or the PID of the original shell if it is a
656             subshell.  Do NOT use this mechanism for generating temporary
657             file names; see mktemp(1) instead.
658
659     -       The concatenation of the current single letter options (see the
660             set command below for a list of options).
661
662     ?       The exit status of the last non-asynchronous command executed.
663             If the last command was killed by a signal, $? is set to 128 plus
664             the signal number.
665
666     0       The name of the shell, determined as follows: the first argument
667             to mksh if it was invoked with the -c option and arguments were
668             given; otherwise the file argument, if it was supplied; or else
669             the basename the shell was invoked with (i.e. argv[0]).  $0 is
670             also set to the name of the current script or the name of the
671             current function, if it was defined with the function keyword
672             (i.e. a Korn shell style function).
673
674     1 .. 9  The first nine positional parameters that were supplied to the
675             shell, function, or script sourced using the ‘.’ built-in.  Fur‐
676             ther positional parameters may be accessed using ${number}.
677
678     *       All positional parameters (except 0), i.e. $1, $2, $3, ...
679             If used outside of double quotes, parameters are separate words
680             (which are subjected to word splitting); if used within double
681             quotes, parameters are separated by the first character of the
682             IFS parameter (or the empty string if IFS is NULL).
683
684     @       Same as $*, unless it is used inside double quotes, in which case
685             a separate word is generated for each positional parameter.  If
686             there are no positional parameters, no word is generated.  $@ can
687             be used to access arguments, verbatim, without losing NULL argu‐
688             ments or splitting arguments with spaces.
689
690     The following parameters are set and/or used by the shell:
691
692     _            (underscore) When an external command is executed by the
693                  shell, this parameter is set in the environment of the new
694                  process to the path of the executed command.  In interactive
695                  use, this parameter is also set in the parent shell to the
696                  last word of the previous command.
697
698     CDPATH       Search path for the cd built-in command.  It works the same
699                  way as PATH for those directories not beginning with ‘/’ in
700                  cd commands.  Note that if CDPATH is set and does not con‐
701                  tain ‘.’ or contains an empty path, the current directory is
702                  not searched.  Also, the cd built-in command will display
703                  the resulting directory when a match is found in any search
704                  path other than the empty path.
705
706     COLUMNS      Set to the number of columns on the terminal or window.
707                  Always set, defaults to 80, unless the value as reported by
708                  stty(1) is non-zero and sane enough; similar for LINES.
709                  This parameter is used by the interactive line editing
710                  modes, and by the select, set -o, and kill -l commands to
711                  format information columns.
712
713     ENV          If this parameter is found to be set after any profile files
714                  are executed, the expanded value is used as a shell startup
715                  file.  It typically contains function and alias definitions.
716
717     ERRNO        Integer value of the shell's errno variable.  It indicates
718                  the reason the last system call failed.  Not yet imple‐
719                  mented.
720
721     EXECSHELL    If set, this parameter is assumed to contain the shell that
722                  is to be used to execute commands that execve(2) fails to
723                  execute and which do not start with a “#!shell” sequence.
724
725     FCEDIT       The editor used by the fc command (see below).
726
727     FPATH        Like PATH, but used when an undefined function is executed
728                  to locate the file defining the function.  It is also
729                  searched when a command can't be found using PATH.  See
730                  Functions below for more information.
731
732     HISTFILE     The name of the file used to store command history.  When
733                  assigned to, history is loaded from the specified file.
734                  Also, several invocations of the shell will share history if
735                  their HISTFILE parameters all point to the same file.
736
737                  Note: If HISTFILE isn't set, no history file is used.  This
738                  is different from AT&T UNIX ksh.
739
740     HISTSIZE     The number of commands normally stored for history.  The
741                  default is 500.
742
743     HOME         The default directory for the cd command and the value sub‐
744                  stituted for an unqualified ~ (see Tilde expansion below).
745
746     IFS          Internal field separator, used during substitution and by
747                  the read command, to split values into distinct arguments;
748                  normally set to space, tab, and newline.  See Substitution
749                  above for details.
750
751                  Note: This parameter is not imported from the environment
752                  when the shell is started.
753
754     KSHEGID      The effective group id of the shell.
755
756     KSHGID       The real group id of the shell.
757
758     KSHUID       The real user id of the shell.
759
760     KSH_VERSION  The name and version of the shell (read-only).  See also the
761                  version commands in Emacs editing mode and Vi editing mode
762                  sections, below.
763
764     LINENO       The line number of the function or shell script that is cur‐
765                  rently being executed.
766
767     LINES        Set to the number of lines on the terminal or window.
768                  Always set, defaults to 24.
769
770     OLDPWD       The previous working directory.  Unset if cd has not suc‐
771                  cessfully changed directories since the shell started, or if
772                  the shell doesn't know where it is.
773
774     OPTARG       When using getopts, it contains the argument for a parsed
775                  option, if it requires one.
776
777     OPTIND       The index of the next argument to be processed when using
778                  getopts.  Assigning 1 to this parameter causes getopts to
779                  process arguments from the beginning the next time it is
780                  invoked.
781
782     PATH         A colon separated list of directories that are searched when
783                  looking for commands and files sourced using the ‘.’ command
784                  (see below).  An empty string resulting from a leading or
785                  trailing colon, or two adjacent colons, is treated as a ‘.’
786                  (the current directory).
787
788     PGRP         The process ID of the shell's process group leader.
789
790     PIPESTATUS   An array containing the errorlevel (exit status) codes, one
791                  by one, of the last pipeline run in the foreground.
792
793     PPID         The process ID of the shell's parent.
794
795     PS1          The primary prompt for interactive shells.  Parameter, com‐
796                  mand, and arithmetic substitutions are performed, and ‘!’ is
797                  replaced with the current command number (see the fc command
798                  below).  A literal ‘!’ can be put in the prompt by placing
799                  ‘!!’ in PS1.
800
801                  The default prompt is ‘$ ’ for non-root users, ‘# ’ for
802                  root.  If mksh is invoked by root and PS1 does not contain a
803                  ‘#’ character, the default value will be used even if PS1
804                  already exists in the environment.
805
806                  The mksh distribution comes with a sample dot.mkshrc con‐
807                  taining a sophisticated example, but you might like the fol‐
808                  lowing one (note that ${HOSTNAME:=$(hostname)} and the root-
809                  vs-user distinguishing clause are (in this example) executed
810                  at PS1 assignment time, while the $USER and $PWD are escaped
811                  and thus will be evaluated each time a prompt is displayed):
812
813                  PS1='${USER:=$(id -un)}'"@${HOSTNAME:=$(hostname)}:\$PWD $(
814                          if (( USER_ID )); then print \$; else print \#; fi) "
815
816                  Note that since the command-line editors try to figure out
817                  how long the prompt is (so they know how far it is to the
818                  edge of the screen), escape codes in the prompt tend to mess
819                  things up.  You can tell the shell not to count certain
820                  sequences (such as escape codes) by prefixing your prompt
821                  with a character (such as Ctrl-A) followed by a carriage
822                  return and then delimiting the escape codes with this char‐
823                  acter.  Any occurences of that character in the prompt are
824                  not printed.  By the way, don't blame me for this hack; it's
825                  derived from the original ksh88(1), which did print the
826                  delimiter character so you were out of luck if you did not
827                  have any non-printing characters.
828
829                  Since Backslashes and other special characters may be inter‐
830                  preted by the shell, to set PS1 either escape the backslash
831                  itself, or use double quotes.  The latter is more practical.
832                  This is a more complex example, avoiding to directly enter
833                  special characters (for example with ^V in the emacs editing
834                  mode), which embeds the current working directory, in
835                  reverse video (colour would work, too), in the prompt
836                  string:
837
838                        x=$(print \\001)
839                        PS1="$x$(print \\r)$x$(tput smso)$x\$PWD$x$(tput rmso)$x> "
840
841                  Due to pressure from David G. Korn, mksh now also supports
842                  the following form:
843
844                        PS1=$'\1\r\1\e[7m\1$PWD\1\e[0m\1> '
845
846     PS2          Secondary prompt string, by default ‘> ’, used when more
847                  input is needed to complete a command.
848
849     PS3          Prompt used by the select statement when reading a menu
850                  selection.  The default is ‘#? ’.
851
852     PS4          Used to prefix commands that are printed during execution
853                  tracing (see the set -x command below).  Parameter, command,
854                  and arithmetic substitutions are performed before it is
855                  printed.  The default is ‘+ ’.
856
857     PWD          The current working directory.  May be unset or NULL if the
858                  shell doesn't know where it is.
859
860     RANDOM       Each time RANDOM is referenced, it is assigned a number
861                  between 0 and 32767 from a Linear Congruential PRNG first.
862
863     REPLY        Default parameter for the read command if no names are
864                  given.  Also used in select loops to store the value that is
865                  read from standard input.
866
867     SECONDS      The number of seconds since the shell started or, if the
868                  parameter has been assigned an integer value, the number of
869                  seconds since the assignment plus the value that was
870                  assigned.
871
872     TMOUT        If set to a positive integer in an interactive shell, it
873                  specifies the maximum number of seconds the shell will wait
874                  for input after printing the primary prompt (PS1).  If the
875                  time is exceeded, the shell exits.
876
877     TMPDIR       The directory temporary shell files are created in.  If this
878                  parameter is not set, or does not contain the absolute path
879                  of a writable directory, temporary files are created in
880                  /tmp.
881
882     USER_ID      The effective user id of the shell.
883
884   Tilde expansion
885     Tilde expansion which is done in parallel with parameter substitution, is
886     done on words starting with an unquoted ‘~’.  The characters following
887     the tilde, up to the first ‘/’, if any, are assumed to be a login name.
888     If the login name is empty, ‘+’, or ‘-’, the value of the HOME, PWD, or
889     OLDPWD parameter is substituted, respectively.  Otherwise, the password
890     file is searched for the login name, and the tilde expression is substi‐
891     tuted with the user's home directory.  If the login name is not found in
892     the password file or if any quoting or parameter substitution occurs in
893     the login name, no substitution is performed.
894
895     In parameter assignments (such as those preceding a simple-command or
896     those occurring in the arguments of alias, export, global, readonly, and
897     typeset), tilde expansion is done after any assignment (i.e. after the
898     equals sign) or after an unquoted colon (‘:’); login names are also
899     delimited by colons.
900
901     The home directory of previously expanded login names are cached and re-
902     used.  The alias -d command may be used to list, change, and add to this
903     cache (e.g. alias -d fac=/usr/local/facilities; cd ~fac/bin).
904
905   Brace expansion (alteration)
906     Brace expressions take the following form:
907
908           prefix{str1,...,strN}suffix
909
910     The expressions are expanded to N words, each of which is the concatena‐
911     tion of prefix, stri, and suffix (e.g. “a{c,b{X,Y},d}e” expands to four
912     words: “ace”, “abXe”, “abYe”, and “ade”).  As noted in the example, brace
913     expressions can be nested and the resulting words are not sorted.  Brace
914     expressions must contain an unquoted comma (‘,’) for expansion to occur
915     (e.g. {} and {foo} are not expanded).  Brace expansion is carried out
916     after parameter substitution and before file name generation.
917
918   File name patterns
919     A file name pattern is a word containing one or more unquoted ‘?’, ‘*’,
920     ‘+’, ‘@’, or ‘!’ characters or “[..]” sequences.  Once brace expansion
921     has been performed, the shell replaces file name patterns with the sorted
922     names of all the files that match the pattern (if no files match, the
923     word is left unchanged).  The pattern elements have the following mean‐
924     ing:
925
926     ?       Matches any single character.
927
928     *       Matches any sequence of octets.
929
930     [..]    Matches any of the octets inside the brackets.  Ranges of octets
931             can be specified by separating two octets by a ‘-’ (e.g. “[a0-9]”
932             matches the letter ‘a’ or any digit).  In order to represent
933             itself, a ‘-’ must either be quoted or the first or last octet in
934             the octet list.  Similarly, a ‘]’ must be quoted or the first
935             octet in the list if it is to represent itself instead of the end
936             of the list.  Also, a ‘!’ appearing at the start of the list has
937             special meaning (see below), so to represent itself it must be
938             quoted or appear later in the list.
939
940     [!..]   Like [..], except it matches any octet not inside the brackets.
941
942     *(pattern|...|pattern)
943             Matches any string of octets that matches zero or more occur‐
944             rences of the specified patterns.  Example: The pattern
945             *(foo|bar) matches the strings “”, “foo”, “bar”, “foobarfoo”,
946             etc.
947
948     +(pattern|...|pattern)
949             Matches any string of octets that matches one or more occurrences
950             of the specified patterns.  Example: The pattern +(foo|bar)
951             matches the strings “foo”, “bar”, “foobar”, etc.
952
953     ?(pattern|...|pattern)
954             Matches the empty string or a string that matches one of the
955             specified patterns.  Example: The pattern ?(foo|bar) only matches
956             the strings “”, “foo”, and “bar”.
957
958     @(pattern|...|pattern)
959             Matches a string that matches one of the specified patterns.
960             Example: The pattern @(foo|bar) only matches the strings “foo”
961             and “bar”.
962
963     !(pattern|...|pattern)
964             Matches any string that does not match one of the specified pat‐
965             terns.  Examples: The pattern !(foo|bar) matches all strings
966             except “foo” and “bar”; the pattern !(*) matches no strings; the
967             pattern !(?)* matches all strings (think about it).
968
969     Note that mksh (and pdksh) never matches ‘.’ and ‘..’, but AT&T UNIX ksh,
970     Bourne sh, and GNU bash do.
971
972     Note that none of the above pattern elements match either a period (‘.’)
973     at the start of a file name or a slash (‘/’), even if they are explicitly
974     used in a [..] sequence; also, the names ‘.’ and ‘..’ are never matched,
975     even by the pattern ‘.*’.
976
977     If the markdirs option is set, any directories that result from file name
978     generation are marked with a trailing ‘/’.
979
980   Input/output redirection
981     When a command is executed, its standard input, standard output, and
982     standard error (file descriptors 0, 1, and 2, respectively) are normally
983     inherited from the shell.  Three exceptions to this are commands in pipe‐
984     lines, for which standard input and/or standard output are those set up
985     by the pipeline, asynchronous commands created when job control is dis‐
986     abled, for which standard input is initially set to be from /dev/null,
987     and commands for which any of the following redirections have been speci‐
988     fied:
989
990     > file      Standard output is redirected to file.  If file does not
991                 exist, it is created; if it does exist, is a regular file,
992                 and the noclobber option is set, an error occurs; otherwise,
993                 the file is truncated.  Note that this means the command cmd
994                 <foo >foo will open foo for reading and then truncate it when
995                 it opens it for writing, before cmd gets a chance to actually
996                 read foo.
997
998     >| file     Same as >, except the file is truncated, even if the
999                 noclobber option is set.
1000
1001     >> file     Same as >, except if file exists it is appended to instead of
1002                 being truncated.  Also, the file is opened in append mode, so
1003                 writes always go to the end of the file (see open(2)).
1004
1005     < file      Standard input is redirected from file, which is opened for
1006                 reading.
1007
1008     <> file     Same as <, except the file is opened for reading and writing.
1009
1010     << marker   After reading the command line containing this kind of redi‐
1011                 rection (called a “here document”), the shell copies lines
1012                 from the command source into a temporary file until a line
1013                 matching marker is read.  When the command is executed, stan‐
1014                 dard input is redirected from the temporary file.  If marker
1015                 contains no quoted characters, the contents of the temporary
1016                 file are processed as if enclosed in double quotes each time
1017                 the command is executed, so parameter, command, and arith‐
1018                 metic substitutions are performed, along with backslash (‘\’)
1019                 escapes for ‘$’, ‘`’, ‘\’, and ‘\newline’, but not for ‘"’.
1020                 If multiple here documents are used on the same command line,
1021                 they are saved in order.
1022
1023                 If no marker is given, the here document ends at the next <<
1024                 and substitution will be performed.  If marker is only a set
1025                 of either single “''” or double ‘""’ quotes with nothing in
1026                 between, the here document ends at the next empty line and
1027                 substitution will not be performed.
1028
1029     <<- marker  Same as <<, except leading tabs are stripped from lines in
1030                 the here document.
1031
1032     <<< word    Same as <<, except that word is the here document.  This is
1033                 called a here string.
1034
1035     <& fd       Standard input is duplicated from file descriptor fd.  fd can
1036                 be a number, indicating the number of an existing file
1037                 descriptor; the letter ‘p’, indicating the file descriptor
1038                 associated with the output of the current co-process; or the
1039                 character ‘-’, indicating standard input is to be closed.
1040                 Note that fd is limited to a single digit in most shell
1041                 implementations.
1042
1043     >& fd       Same as <&, except the operation is done on standard output.
1044
1045     &> file     Same as > file 2>&1.  This is a GNU bash extension supported
1046                 by mksh which also supports the preceding explicit fd number,
1047                 for example, 3&> file is the same as 3> file 2>&3 in mksh but
1048                 a syntax error in GNU bash.
1049
1050     &>| file, &>> file, &>& fd
1051                 Same as >| file, >> file, or >& fd, followed by 2>&1, as
1052                 above.  These are mksh extensions.
1053
1054     In any of the above redirections, the file descriptor that is redirected
1055     (i.e. standard input or standard output) can be explicitly given by pre‐
1056     ceding the redirection with a number (portably, only a single digit).
1057     Parameter, command, and arithmetic substitutions, tilde substitutions,
1058     and (if the shell is interactive) file name generation are all performed
1059     on the file, marker, and fd arguments of redirections.  Note, however,
1060     that the results of any file name generation are only used if a single
1061     file is matched; if multiple files match, the word with the expanded file
1062     name generation characters is used.  Note that in restricted shells,
1063     redirections which can create files cannot be used.
1064
1065     For simple-commands, redirections may appear anywhere in the command; for
1066     compound-commands (if statements, etc.), any redirections must appear at
1067     the end.  Redirections are processed after pipelines are created and in
1068     the order they are given, so the following will print an error with a
1069     line number prepended to it:
1070
1071           $ cat /foo/bar 2>&1 >/dev/null | pr -n -t
1072
1073     File descriptors created by input/output redirections are private to the
1074     Korn shell, but passed to sub-processes if -o posix or -o sh is set.
1075
1076   Arithmetic expressions
1077     Integer arithmetic expressions can be used with the let command, inside
1078     $((..)) expressions, inside array references (e.g. name[expr]), as
1079     numeric arguments to the test command, and as the value of an assignment
1080     to an integer parameter.
1081
1082     Expressions are calculated using signed arithmetic and the mksh_ari_t
1083     type (a 32-bit signed integer), unless they begin with a sole ‘#’ charac‐
1084     ter, in which case they use mksh_uari_t (a 32-bit unsigned integer).
1085
1086     Expressions may contain alpha-numeric parameter identifiers, array refer‐
1087     ences, and integer constants and may be combined with the following C
1088     operators (listed and grouped in increasing order of precedence):
1089
1090     Unary operators:
1091
1092           + - ! ~ ++ --
1093
1094     Binary operators:
1095
1096           ,
1097           = *= /= %= += -= <<= >>= &= ^= |=
1098           ||
1099           &&
1100           |
1101           ^
1102           &
1103           == !=
1104           < <= >= >
1105           << >>
1106           + -
1107           * / %
1108
1109     Ternary operators:
1110
1111           ?: (precedence is immediately higher than assignment)
1112
1113     Grouping operators:
1114
1115           ( )
1116
1117     Integer constants and expressions are calculated using the mksh_ari_t (if
1118     signed) or mksh_uari_t (if unsigned) type, and are limited to 32 bits.
1119     Overflows wrap silently.  Integer constants may be specified with arbi‐
1120     trary bases using the notation base#number, where base is a decimal inte‐
1121     ger specifying the base, and number is a number in the specified base.
1122     Additionally, integers may be prefixed with ‘0X’ or ‘0x’ (specifying base
1123     16), similar to AT&T UNIX ksh, or ‘0’ (base 8), as an mksh extension, in
1124     all forms of arithmetic expressions, except as numeric arguments to the
1125     test command.  As a special mksh extension, numbers to the base of one
1126     are treated as either (8-bit transparent) ASCII or Unicode codepoints,
1127     depending on the shell's utf8-mode flag (current setting).  The AT&T UNIX
1128     ksh93 syntax of “'x'” instead of “1#x” is also supported.  Note that NUL
1129     bytes (integral value of zero) cannot be used.  In Unicode mode, raw
1130     octets are mapped into the range EF80..EFFF as in OPTU-8, which is in the
1131     PUA and has been assigned by CSUR for this use.  If more than one octet
1132     in ASCII mode, or a sequence of more than one octet not forming a valid
1133     and minimal CESU-8 sequence is passed, the behaviour is undefined (usu‐
1134     ally, the shell aborts with a parse error, but rarely, it succeeds, e.g.
1135     on the sequence C2 20).  That's why you should always use ASCII mode
1136     unless you know that the input is well-formed UTF-8 in the range of
1137     0000..FFFD.
1138
1139     The operators are evaluated as follows:
1140
1141           unary +
1142                   Result is the argument (included for completeness).
1143
1144           unary -
1145                   Negation.
1146
1147           !       Logical NOT; the result is 1 if argument is zero, 0 if not.
1148
1149           ~       Arithmetic (bit-wise) NOT.
1150
1151           ++      Increment; must be applied to a parameter (not a literal or
1152                   other expression).  The parameter is incremented by 1.
1153                   When used as a prefix operator, the result is the incre‐
1154                   mented value of the parameter; when used as a postfix oper‐
1155                   ator, the result is the original value of the parameter.
1156
1157           --      Similar to ++, except the parameter is decremented by 1.
1158
1159           ,       Separates two arithmetic expressions; the left-hand side is
1160                   evaluated first, then the right.  The result is the value
1161                   of the expression on the right-hand side.
1162
1163           =       Assignment; the variable on the left is set to the value on
1164                   the right.
1165
1166           *= /= += -= <<= >>= &= ^= |=
1167                   Assignment operators.  ⟨var⟩⟨op⟩=⟨expr⟩ is the same as
1168var⟩=⟨var⟩⟨op⟩⟨expr⟩, with any operator precedence in
1169expr⟩ preserved.  For example, “var1 *= 5 + 3” is the same
1170                   as specifying “var1 = var1 * (5 + 3)”.
1171
1172           ||      Logical OR; the result is 1 if either argument is non-zero,
1173                   0 if not.  The right argument is evaluated only if the left
1174                   argument is zero.
1175
1176           &&      Logical AND; the result is 1 if both arguments are non-
1177                   zero, 0 if not.  The right argument is evaluated only if
1178                   the left argument is non-zero.
1179
1180           |       Arithmetic (bit-wise) OR.
1181
1182           ^       Arithmetic (bit-wise) XOR (exclusive-OR).
1183
1184           &       Arithmetic (bit-wise) AND.
1185
1186           ==      Equal; the result is 1 if both arguments are equal, 0 if
1187                   not.
1188
1189           !=      Not equal; the result is 0 if both arguments are equal, 1
1190                   if not.
1191
1192           <       Less than; the result is 1 if the left argument is less
1193                   than the right, 0 if not.
1194
1195           <= >= >
1196                   Less than or equal, greater than or equal, greater than.
1197                   See <.
1198
1199           << >>   Shift left (right); the result is the left argument with
1200                   its bits shifted left (right) by the amount given in the
1201                   right argument.
1202
1203           + - * /
1204                   Addition, subtraction, multiplication, and division.
1205
1206           %       Remainder; the result is the remainder of the division of
1207                   the left argument by the right.  The sign of the result is
1208                   unspecified if either argument is negative.
1209
1210arg1⟩?⟨arg2⟩:⟨arg3
1211                   If ⟨arg1⟩ is non-zero, the result is ⟨arg2⟩; otherwise the
1212                   result is ⟨arg3⟩.
1213
1214   Co-processes
1215     A co-process (which is a pipeline created with the ‘|&’ operator) is an
1216     asynchronous process that the shell can both write to (using print -p)
1217     and read from (using read -p).  The input and output of the co-process
1218     can also be manipulated using >&p and <&p redirections, respectively.
1219     Once a co-process has been started, another can't be started until the
1220     co-process exits, or until the co-process's input has been redirected
1221     using an exec n>&p redirection.  If a co-process's input is redirected in
1222     this way, the next co-process to be started will share the output with
1223     the first co-process, unless the output of the initial co-process has
1224     been redirected using an exec n<&p redirection.
1225
1226     Some notes concerning co-processes:
1227
1228     ·   The only way to close the co-process's input (so the co-process reads
1229         an end-of-file) is to redirect the input to a numbered file descrip‐
1230         tor and then close that file descriptor: exec 3>&p; exec 3>&-
1231
1232     ·   In order for co-processes to share a common output, the shell must
1233         keep the write portion of the output pipe open.  This means that end-
1234         of-file will not be detected until all co-processes sharing the co-
1235         process's output have exited (when they all exit, the shell closes
1236         its copy of the pipe).  This can be avoided by redirecting the output
1237         to a numbered file descriptor (as this also causes the shell to close
1238         its copy).  Note that this behaviour is slightly different from the
1239         original Korn shell which closes its copy of the write portion of the
1240         co-process output when the most recently started co-process (instead
1241         of when all sharing co-processes) exits.
1242
1243     ·   print -p will ignore SIGPIPE signals during writes if the signal is
1244         not being trapped or ignored; the same is true if the co-process
1245         input has been duplicated to another file descriptor and print -un is
1246         used.
1247
1248   Functions
1249     Functions are defined using either Korn shell function function-name syn‐
1250     tax or the Bourne/POSIX shell function-name() syntax (see below for the
1251     difference between the two forms).  Functions are like .‐scripts (i.e.
1252     scripts sourced using the ‘.’ built-in) in that they are executed in the
1253     current environment.  However, unlike .‐scripts, shell arguments (i.e.
1254     positional parameters $1, $2, etc.) are never visible inside them.  When
1255     the shell is determining the location of a command, functions are
1256     searched after special built-in commands, before regular and non-regular
1257     built-ins, and before the PATH is searched.
1258
1259     An existing function may be deleted using unset -f function-name.  A list
1260     of functions can be obtained using typeset +f and the function defini‐
1261     tions can be listed using typeset -f.  The autoload command (which is an
1262     alias for typeset -fu) may be used to create undefined functions: when an
1263     undefined function is executed, the shell searches the path specified in
1264     the FPATH parameter for a file with the same name as the function which,
1265     if found, is read and executed.  If after executing the file the named
1266     function is found to be defined, the function is executed; otherwise, the
1267     normal command search is continued (i.e. the shell searches the regular
1268     built-in command table and PATH).  Note that if a command is not found
1269     using PATH, an attempt is made to autoload a function using FPATH (this
1270     is an undocumented feature of the original Korn shell).
1271
1272     Functions can have two attributes, “trace” and “export”, which can be set
1273     with typeset -ft and typeset -fx, respectively.  When a traced function
1274     is executed, the shell's xtrace option is turned on for the function's
1275     duration.  The “export” attribute of functions is currently not used.  In
1276     the original Korn shell, exported functions are visible to shell scripts
1277     that are executed.
1278
1279     Since functions are executed in the current shell environment, parameter
1280     assignments made inside functions are visible after the function com‐
1281     pletes.  If this is not the desired effect, the typeset command can be
1282     used inside a function to create a local parameter.  Note that AT&T UNIX
1283     ksh93 uses static scoping (one global scope, one local scope per func‐
1284     tion), whereas mksh uses dynamic scoping (nested scopes of varying local‐
1285     ity).  Note that special parameters (e.g. $$, $!) can't be scoped in this
1286     way.
1287
1288     The exit status of a function is that of the last command executed in the
1289     function.  A function can be made to finish immediately using the return
1290     command; this may also be used to explicitly specify the exit status.
1291
1292     Functions defined with the function reserved word are treated differently
1293     in the following ways from functions defined with the () notation:
1294
1295     ·   The $0 parameter is set to the name of the function (Bourne-style
1296         functions leave $0 untouched).
1297
1298     ·   Parameter assignments preceding function calls are not kept in the
1299         shell environment (executing Bourne-style functions will keep assign‐
1300         ments).
1301
1302     ·   OPTIND is saved/reset and restored on entry and exit from the func‐
1303         tion so getopts can be used properly both inside and outside the
1304         function (Bourne-style functions leave OPTIND untouched, so using
1305         getopts inside a function interferes with using getopts outside the
1306         function).
1307
1308     ·   Bourne-style function definitions take precedence over alias derefer‐
1309         ences and remove alias definitions upon encounter, while aliases take
1310         precedence over Korn-style functions.
1311
1312     In the future, the following differences will also be added:
1313
1314     ·   A separate trap/signal environment will be used during the execution
1315         of functions.  This will mean that traps set inside a function will
1316         not affect the shell's traps and signals that are not ignored in the
1317         shell (but may be trapped) will have their default effect in a func‐
1318         tion.
1319
1320     ·   The EXIT trap, if set in a function, will be executed after the func‐
1321         tion returns.
1322
1323   Command execution
1324     After evaluation of command-line arguments, redirections, and parameter
1325     assignments, the type of command is determined: a special built-in, a
1326     function, a regular built-in, or the name of a file to execute found
1327     using the PATH parameter.  The checks are made in the above order.  Spe‐
1328     cial built-in commands differ from other commands in that the PATH param‐
1329     eter is not used to find them, an error during their execution can cause
1330     a non-interactive shell to exit, and parameter assignments that are spec‐
1331     ified before the command are kept after the command completes.  Regular
1332     built-in commands are different only in that the PATH parameter is not
1333     used to find them.
1334
1335     The original ksh and POSIX differ somewhat in which commands are consid‐
1336     ered special or regular:
1337
1338     POSIX special commands
1339
1340     ., :, break, continue, eval, exec, exit, export, readonly, return, set,
1341     shift, trap, unset, wait
1342
1343     Additional mksh special commands
1344
1345     builtin, global, times, typeset
1346
1347     Very special commands (non-POSIX)
1348
1349     alias, readonly, set, typeset
1350
1351     POSIX regular commands
1352
1353     alias, bg, cd, command, false, fc, fg, getopts, jobs, kill, read, true,
1354     umask, unalias
1355
1356     Additional mksh regular commands
1357
1358     [, chdir, bind, cat, echo, let, mknod, print, printf, pwd, realpath,
1359     rename, sleep, test, ulimit, whence
1360
1361     In the future, the additional mksh special and regular commands may be
1362     treated differently from the POSIX special and regular commands.
1363
1364     Once the type of command has been determined, any command-line parameter
1365     assignments are performed and exported for the duration of the command.
1366
1367     The following describes the special and regular built-in commands:
1368
1369     . file [arg ...]
1370            This is called the “dot” command.  Execute the commands in file in
1371            the current environment.  The file is searched for in the directo‐
1372            ries of PATH.  If arguments are given, the positional parameters
1373            may be used to access them while file is being executed.  If no
1374            arguments are given, the positional parameters are those of the
1375            environment the command is used in.
1376
1377     : [...]
1378            The null command.  Exit status is set to zero.
1379
1380     alias [-d | -t [-r] | +-x] [-p] [+] [name [=value] ...]
1381            Without arguments, alias lists all aliases.  For any name without
1382            a value, the existing alias is listed.  Any name with a value
1383            defines an alias (see Aliases above).
1384
1385            When listing aliases, one of two formats is used.  Normally,
1386            aliases are listed as name=value, where value is quoted.  If
1387            options were preceded with ‘+’, or a lone ‘+’ is given on the com‐
1388            mand line, only name is printed.
1389
1390            The -d option causes directory aliases which are used in tilde
1391            expansion to be listed or set (see Tilde expansion above).
1392
1393            If the -p option is used, each alias is prefixed with the string
1394            “alias ”.
1395
1396            The -t option indicates that tracked aliases are to be listed/set
1397            (values specified on the command line are ignored for tracked
1398            aliases).  The -r option indicates that all tracked aliases are to
1399            be reset.
1400
1401            The -x option sets (+x clears) the export attribute of an alias,
1402            or, if no names are given, lists the aliases with the export
1403            attribute (exporting an alias has no effect).
1404
1405     bg [job ...]
1406            Resume the specified stopped job(s) in the background.  If no jobs
1407            are specified, %+ is assumed.  See Job control below for more
1408            information.
1409
1410     bind [-l]
1411            The current bindings are listed.  If the -l flag is given, bind
1412            instead lists the names of the functions to which keys may be
1413            bound.  See Emacs editing mode for more information.
1414
1415     bind [-m] string=[substitute] ...
1416     bind string=[editing-command] ...
1417            The specified editing command is bound to the given string, which
1418            should consist of a control character optionally preceded by one
1419            of the two prefix characters and optionally succeded by a tilde
1420            character.  Future input of the string will cause the editing com‐
1421            mand to be immediately invoked.  If the -m flag is given, the
1422            specified input string will afterwards be immediately replaced by
1423            the given substitute string which may contain editing commands but
1424            not other macros.  If a tilde postfix is given, a tilde trailing
1425            the one or two prefices and the control character is ignored, any
1426            other trailing character will be processed afterwards.
1427
1428            Control characters may be written using caret notation i.e. ^X
1429            represents Ctrl-X.  Note that although only two prefix characters
1430            (usually ESC and ^X) are supported, some multi-character sequences
1431            can be supported.
1432
1433            The following default bindings show how the arrow keys, the home,
1434            end and delete key on a BSD wsvt25, xterm-xfree86 or GNU screen
1435            terminal are bound (of course some escape sequences won't work out
1436            quite this nicely):
1437
1438                  bind '^X'=prefix-2
1439                  bind '^[['=prefix-2
1440                  bind '^XA'=up-history
1441                  bind '^XB'=down-history
1442                  bind '^XC'=forward-char
1443                  bind '^XD'=backward-char
1444                  bind '^X1~'=beginning-of-line
1445                  bind '^X7~'=beginning-of-line
1446                  bind '^XH'=beginning-of-line
1447                  bind '^X4~'=end-of-line
1448                  bind '^X8~'=end-of-line
1449                  bind '^XF'=end-of-line
1450                  bind '^X3~'=delete-char-forward
1451
1452     break [level]
1453            Exit the levelth inner-most for, select, until, or while loop.
1454            level defaults to 1.
1455
1456     builtin [--] command [arg ...]
1457            Execute the built-in command command.
1458
1459     cat [-u] [file ...]
1460            Read files sequentially, in command line order, and write them to
1461            standard output.  If a file is a single dash (‘-’) or absent, read
1462            from standard input.  Unless compiled with MKSH_NO_EXTERNAL_CAT,
1463            if any options are given, an external cat(1) utility is invoked
1464            instead if called from the shell.  For direct builtin calls, the
1465            POSIX -u option is supported as a no-op.
1466
1467     cd [-L] [dir]
1468     cd -P [-e] [dir]
1469     chdir [-eLP] [dir]
1470            Set the working directory to dir.  If the parameter CDPATH is set,
1471            it lists the search path for the directory containing dir.  A NULL
1472            path means the current directory.  If dir is found in any compo‐
1473            nent of the CDPATH search path other than the NULL path, the name
1474            of the new working directory will be written to standard output.
1475            If dir is missing, the home directory HOME is used.  If dir is
1476            ‘-’, the previous working directory is used (see the OLDPWD param‐
1477            eter).
1478
1479            If the -L option (logical path) is used or if the physical option
1480            isn't set (see the set command below), references to ‘..’ in dir
1481            are relative to the path used to get to the directory.  If the -P
1482            option (physical path) is used or if the physical option is set,
1483            ‘..’ is relative to the filesystem directory tree.  The PWD and
1484            OLDPWD parameters are updated to reflect the current and old work‐
1485            ing directory, respectively.  If the -e option is set for physical
1486            filesystem traversal, and PWD could not be set, the exit code is
1487            1; greater than 1 if an error occurred, 0 otherwise.
1488
1489     cd [-eLP] old new
1490     chdir [-eLP] old new
1491            The string new is substituted for old in the current directory,
1492            and the shell attempts to change to the new directory.
1493
1494     command [-pVv] cmd [arg ...]
1495            If neither the -v nor -V option is given, cmd is executed exactly
1496            as if command had not been specified, with two exceptions:
1497            firstly, cmd cannot be a shell function; and secondly, special
1498            built-in commands lose their specialness (i.e. redirection and
1499            utility errors do not cause the shell to exit, and command assign‐
1500            ments are not permanent).
1501
1502            If the -p option is given, a default search path is used instead
1503            of the current value of PATH, the actual value of which is system
1504            dependent.
1505
1506            If the -v option is given, instead of executing cmd, information
1507            about what would be executed is given (and the same is done for
1508            arg ...).  For special and regular built-in commands and func‐
1509            tions, their names are simply printed; for aliases, a command that
1510            defines them is printed; and for commands found by searching the
1511            PATH parameter, the full path of the command is printed.  If no
1512            command is found (i.e. the path search fails), nothing is printed
1513            and command exits with a non-zero status.  The -V option is like
1514            the -v option, except it is more verbose.
1515
1516     continue [level]
1517            Jumps to the beginning of the levelth inner-most for, select,
1518            until, or while loop.  level defaults to 1.
1519
1520     echo [-Een] [arg ...]
1521            Warning: this utility is not portable; use the Korn shell builtin
1522            print or the much slower POSIX utility printf instead.
1523
1524            Prints its arguments (separated by spaces) followed by a newline,
1525            to the standard output.  The newline is suppressed if any of the
1526            arguments contain the backslash sequence ‘\c’.  See the print com‐
1527            mand below for a list of other backslash sequences that are recog‐
1528            nised.
1529
1530            The options are provided for compatibility with BSD shell scripts.
1531            The -n option suppresses the trailing newline, -e enables back‐
1532            slash interpretation (a no-op, since this is normally done), and
1533            -E suppresses backslash interpretation.
1534
1535            If the posix or sh option is set or this is a direct builtin call,
1536            only the first argument is treated as an option, and only if it is
1537            exactly “-n”.  Backslash interpretation is disabled.
1538
1539     eval command ...
1540            The arguments are concatenated (with spaces between them) to form
1541            a single string which the shell then parses and executes in the
1542            current environment.
1543
1544     exec [command [arg ...]]
1545            The command is executed without forking, replacing the shell
1546            process.
1547
1548            If no command is given except for I/O redirection, the I/O redi‐
1549            rection is permanent and the shell is not replaced.  Any file
1550            descriptors greater than 2 which are opened or dup(2)'d in this
1551            way are not made available to other executed commands (i.e. com‐
1552            mands that are not built-in to the shell).  Note that the Bourne
1553            shell differs here; it does pass these file descriptors on.
1554
1555     exit [status]
1556            The shell exits with the specified exit status.  If status is not
1557            specified, the exit status is the current value of the $? parame‐
1558            ter.
1559
1560     export [-p] [parameter[=value]]
1561            Sets the export attribute of the named parameters.  Exported
1562            parameters are passed in the environment to executed commands.  If
1563            values are specified, the named parameters are also assigned.
1564
1565            If no parameters are specified, all parameters with the export
1566            attribute set are printed one per line; either their names, or, if
1567            a ‘-’ with no option letter is specified, name=value pairs, or,
1568            with -p, export commands defining all exported parameters, includ‐
1569            ing their values.
1570
1571     false  A command that exits with a non-zero status.
1572
1573     fc [-e editor | -l [-n]] [-r] [first [last]]
1574            first and last select commands from the history.  Commands can be
1575            selected by history number or a string specifying the most recent
1576            command starting with that string.  The -l option lists the com‐
1577            mand on standard output, and -n inhibits the default command num‐
1578            bers.  The -r option reverses the order of the list.  Without -l,
1579            the selected commands are edited by the editor specified with the
1580            -e option, or if no -e is specified, the editor specified by the
1581            FCEDIT parameter (if this parameter is not set, /bin/ed is used),
1582            and then executed by the shell.
1583
1584     fc -e - | -s [-g] [old=new] [prefix]
1585            Re-execute the selected command (the previous command by default)
1586            after performing the optional substitution of old with new.  If -g
1587            is specified, all occurrences of old are replaced with new.  The
1588            meaning of -e - and -s is identical: re-execute the selected com‐
1589            mand without invoking an editor.  This command is usually accessed
1590            with the predefined alias r='fc -e -' or (deprecated; will be
1591            removed RSN) by prefixing an interactive mode input line with ‘!’
1592            (wbx extension).
1593
1594     fg [job ...]
1595            Resume the specified job(s) in the foreground.  If no jobs are
1596            specified, %+ is assumed.  See Job control below for more informa‐
1597            tion.
1598
1599     getopts optstring name [arg ...]
1600            Used by shell procedures to parse the specified arguments (or
1601            positional parameters, if no arguments are given) and to check for
1602            legal options.  optstring contains the option letters that getopts
1603            is to recognise.  If a letter is followed by a colon, the option
1604            is expected to have an argument.  Options that do not take argu‐
1605            ments may be grouped in a single argument.  If an option takes an
1606            argument and the option character is not the last character of the
1607            argument it is found in, the remainder of the argument is taken to
1608            be the option's argument; otherwise, the next argument is the
1609            option's argument.
1610
1611            Each time getopts is invoked, it places the next option in the
1612            shell parameter name and the index of the argument to be processed
1613            by the next call to getopts in the shell parameter OPTIND.  If the
1614            option was introduced with a ‘+’, the option placed in name is
1615            prefixed with a ‘+’.  When an option requires an argument, getopts
1616            places it in the shell parameter OPTARG.
1617
1618            When an illegal option or a missing option argument is encoun‐
1619            tered, a question mark or a colon is placed in name (indicating an
1620            illegal option or missing argument, respectively) and OPTARG is
1621            set to the option character that caused the problem.  Furthermore,
1622            if optstring does not begin with a colon, a question mark is
1623            placed in name, OPTARG is unset, and an error message is printed
1624            to standard error.
1625
1626            When the end of the options is encountered, getopts exits with a
1627            non-zero exit status.  Options end at the first (non-option argu‐
1628            ment) argument that does not start with a ‘-’, or when a ‘--’
1629            argument is encountered.
1630
1631            Option parsing can be reset by setting OPTIND to 1 (this is done
1632            automatically whenever the shell or a shell procedure is invoked).
1633
1634            Warning: Changing the value of the shell parameter OPTIND to a
1635            value other than 1, or parsing different sets of arguments without
1636            resetting OPTIND, may lead to unexpected results.
1637
1638     hash [-r] [name ...]
1639            Without arguments, any hashed executable command pathnames are
1640            listed.  The -r option causes all hashed commands to be removed
1641            from the hash table.  Each name is searched as if it were a com‐
1642            mand name and added to the hash table if it is an executable com‐
1643            mand.
1644
1645     jobs [-lnp] [job ...]
1646            Display information about the specified job(s); if no jobs are
1647            specified, all jobs are displayed.  The -n option causes informa‐
1648            tion to be displayed only for jobs that have changed state since
1649            the last notification.  If the -l option is used, the process ID
1650            of each process in a job is also listed.  The -p option causes
1651            only the process group of each job to be printed.  See Job control
1652            below for the format of job and the displayed job.
1653
1654     kill [-s signame | -signum | -signame] { job | pid | pgrp } ...
1655            Send the specified signal to the specified jobs, process IDs, or
1656            process groups.  If no signal is specified, the TERM signal is
1657            sent.  If a job is specified, the signal is sent to the job's
1658            process group.  See Job control below for the format of job.
1659
1660     kill -l [exit-status ...]
1661            Print the signal name corresponding to exit-status.  If no argu‐
1662            ments are specified, a list of all the signals, their numbers, and
1663            a short description of them are printed.
1664
1665     let [expression ...]
1666            Each expression is evaluated (see Arithmetic expressions above).
1667            If all expressions are successfully evaluated, the exit status is
1668            0 (1) if the last expression evaluated to non-zero (zero).  If an
1669            error occurs during the parsing or evaluation of an expression,
1670            the exit status is greater than 1.  Since expressions may need to
1671            be quoted, (( expr )) is syntactic sugar for let "expr".
1672
1673     mknod [-m mode] name b|c major minor
1674     mknod [-m mode] name p
1675            Create a device special file.  The file type may be b (block type
1676            device), c (character type device), or p (named pipe).  The file
1677            created may be modified according to its mode (via the -m option),
1678            major (major device number), and minor (minor device number).
1679
1680            See mknod(8) for further information.
1681
1682     print [-nprsu[n] | -R [-en]] [argument ...]
1683            print prints its arguments on the standard output, separated by
1684            spaces and terminated with a newline.  The -n option suppresses
1685            the newline.  By default, certain C escapes are translated.  These
1686            include these mentioned in Backslash expansion above, as well as
1687            ‘\c’, which is equivalent to using the -n option.  Backslash
1688            expansion may be inhibited with the -r option.  The -s option
1689            prints to the history file instead of standard output; the -u
1690            option prints to file descriptor n (n defaults to 1 if omitted);
1691            and the -p option prints to the co-process (see Co-processes
1692            above).
1693
1694            The -R option is used to emulate, to some degree, the BSD echo(1)
1695            command which does not process ‘\’ sequences unless the -e option
1696            is given.  As above, the -n option suppresses the trailing new‐
1697            line.
1698
1699     printf format [arguments ...]
1700            Formatted output.  Approximately the same as the utility printf,
1701            except that it uses the same Backslash expansion and I/O code as
1702            the rest of mksh.  This is not normally part of mksh; however,
1703            distributors may have added this as builtin as a speed hack.
1704
1705     pwd [-LP]
1706            Print the present working directory.  If the -L option is used or
1707            if the physical option isn't set (see the set command below), the
1708            logical path is printed (i.e. the path used to cd to the current
1709            directory).  If the -P option (physical path) is used or if the
1710            physical option is set, the path determined from the filesystem
1711            (by following ‘..’ directories to the root directory) is printed.
1712
1713     read [-A | -a] [-d x] [-N z | -n z] [-p | -u[n]] [-t n] [-rs] [p ...]
1714            Reads a line of input, separates the input into fields using the
1715            IFS parameter (see Substitution above), and assigns each field to
1716            the specified parameters p.  If no parameters are specified, the
1717            REPLY parameter is used to store the result.  With the -A and -a
1718            options, only no or one parameter is accepted.  If there are more
1719            parameters than fields, the extra parameters are set to the empty
1720            string or 0; if there are more fields than parameters, the last
1721            parameter is assigned the remaining fields (including the word
1722            separators).
1723
1724            The options are as follows:
1725
1726            -A     Store the result into the parameter p (or REPLY) as array
1727                   of words.
1728
1729            -a     Store the result without word splitting into the parameter
1730                   p (or REPLY) as array of characters (wide characters if the
1731                   utf8-mode option is enacted, octets otherwise).
1732
1733            -d x   Use the first byte of x, NUL if empty, instead of the ASCII
1734                   newline character as input line delimiter.
1735
1736            -N z   Instead of reading till end-of-line, read exactly z bytes;
1737                   less if EOF or a timeout occurs.
1738
1739            -n z   Instead of reading till end-of-line, read up to z bytes but
1740                   return as soon as any bytes are read, e.g. from a slow ter‐
1741                   minal device, or if EOF or a timeout occurs.
1742
1743            -p     Read from the currently active co-process, see Co-processes
1744                   above for details on this.
1745
1746            -u[n]  Read from the file descriptor n (defaults to 0, i.e. stan‐
1747                   dard input).  The argument must immediately follow the
1748                   option character.
1749
1750            -t n   Interrupt reading after n seconds (specified as positive
1751                   decimal value with an optional fractional part).
1752
1753            -r     Normally, the ASCII backslash character escapes the special
1754                   meaning of the following character and is stripped from the
1755                   input; read does not stop when encountering a backslash-
1756                   newline sequence and does not store that newline in the
1757                   result.  This option enables raw mode, in which backslashes
1758                   are not processed.
1759
1760            -s     The input line is saved to the history.
1761
1762            If the input is a terminal, both the -N and -n options set it into
1763            raw mode; they read an entire file if -1 is passed as z argument.
1764
1765            The first parameter may have a question mark and a string appended
1766            to it, in which case the string is used as a prompt (printed to
1767            standard error before any input is read) if the input is a tty(4)
1768            (e.g. read nfoo?'number of foos: ').
1769
1770            If no input is read or a timeout occurred, read exits with a non-
1771            zero status.
1772
1773            Another handy set of tricks: If read is run in a loop such as
1774            while read foo; do ...; done then leading whitespace will be
1775            removed (IFS) and backslashes processed.  You might want to use
1776            while IFS= read -r foo; do ...; done for pristine I/O.  Similar‐
1777            ily, when using the -a option, use of the -r option might be pru‐
1778            dent; the same applies for:
1779
1780                  find . -type f -print0 | \
1781                      while IFS= read -d '' -r filename; do
1782                          print -r -- "found <${filename#./}>"
1783                  done
1784
1785            The inner loop will be executed in a subshell and variable changes
1786            cannot be propagated if executed in a pipeline:
1787
1788                  bar | baz | while read foo; do ...; done
1789
1790            Use co-processes instead:
1791
1792                  bar | baz |&
1793                  while read -p foo; do ...; done
1794                  exec 3>&p; exec 3>&-
1795
1796     readonly [-p] [parameter [=value] ...]
1797            Sets the read-only attribute of the named parameters.  If values
1798            are given, parameters are set to them before setting the
1799            attribute.  Once a parameter is made read-only, it cannot be unset
1800            and its value cannot be changed.
1801
1802            If no parameters are specified, the names of all parameters with
1803            the read-only attribute are printed one per line, unless the -p
1804            option is used, in which case readonly commands defining all read-
1805            only parameters, including their values, are printed.
1806
1807     realpath [--] name
1808            Prints the resolved absolute pathname corresponding to name.  If
1809            name ends with a slash (‘/’), it's also checked for existence and
1810            whether it is a directory; otherwise, realpath returns 0 if the
1811            pathname either exists or can be created immediately, i.e. all but
1812            the last component exist and are directories.
1813
1814     rename [--] from to
1815            Renames the file from to to.  Both must be complete pathnames and
1816            on the same device.  This builtin is intended for emergency situa‐
1817            tions where /bin/mv becomes unusable, and directly calls
1818            rename(2).
1819
1820     return [status]
1821            Returns from a function or . script, with exit status status.  If
1822            no status is given, the exit status of the last executed command
1823            is used.  If used outside of a function or . script, it has the
1824            same effect as exit.  Note that mksh treats both profile and ENV
1825            files as . scripts, while the original Korn shell only treats pro‐
1826            files as . scripts.
1827
1828     set [+-abCefhiklmnprsUuvXx] [+-o option] [+-A name] [--] [arg ...]
1829            The set command can be used to set (-) or clear (+) shell options,
1830            set the positional parameters, or set an array parameter.  Options
1831            can be changed using the +-o option syntax, where option is the
1832            long name of an option, or using the +-letter syntax, where letter
1833            is the option's single letter name (not all options have a single
1834            letter name).  The following table lists both option letters (if
1835            they exist) and long names along with a description of what the
1836            option does:
1837
1838            -A name
1839                 Sets the elements of the array parameter name to arg ... If
1840                 -A is used, the array is reset (i.e. emptied) first; if +A is
1841                 used, the first N elements are set (where N is the number of
1842                 arguments); the rest are left untouched.
1843
1844                 An alternative syntax for the command set -A foo -- a b c
1845                 which is compatible to GNU bash and also supported by AT&T
1846                 UNIX ksh93 is: foo=(a b c); foo+=(d e)
1847
1848                 Another AT&T UNIX ksh93 and GNU bash extension allows speci‐
1849                 fying the indices used for arg ... (from the above example, a
1850                 b c) like this: set -A foo -- [0]=a [1]=b [2]=c or foo=([0]=a
1851                 [1]=b [2]=c) which can also be written foo=([0]=a b c)
1852                 because indices are incremented automatically.
1853
1854            -a | -o allexport
1855                 All new parameters are created with the export attribute.
1856
1857            -b | -o notify
1858                 Print job notification messages asynchronously, instead of
1859                 just before the prompt.  Only used if job control is enabled
1860                 (-m).
1861
1862            -C | -o noclobber
1863                 Prevent > redirection from overwriting existing files.
1864                 Instead, >| must be used to force an overwrite.
1865
1866            -e | -o errexit
1867                 Exit (after executing the ERR trap) as soon as an error
1868                 occurs or a command fails (i.e. exits with a non-zero sta‐
1869                 tus).  This does not apply to commands whose exit status is
1870                 explicitly tested by a shell construct such as if, until,
1871                 while, &&, ||, or ! statements.
1872
1873            -f | -o noglob
1874                 Do not expand file name patterns.
1875
1876            -h | -o trackall
1877                 Create tracked aliases for all executed commands (see Aliases
1878                 above).  Enabled by default for non-interactive shells.
1879
1880            -i | -o interactive
1881                 The shell is an interactive shell.  This option can only be
1882                 used when the shell is invoked.  See above for a description
1883                 of what this means.
1884
1885            -k | -o keyword
1886                 Parameter assignments are recognised anywhere in a command.
1887
1888            -l | -o login
1889                 The shell is a login shell.  This option can only be used
1890                 when the shell is invoked.  See above for a description of
1891                 what this means.
1892
1893            -m | -o monitor
1894                 Enable job control (default for interactive shells).
1895
1896            -n | -o noexec
1897                 Do not execute any commands.  Useful for checking the syntax
1898                 of scripts (ignored if interactive).
1899
1900            -p | -o privileged
1901                 The shell is a privileged shell.  It is set automatically if,
1902                 when the shell starts, the real UID or GID does not match the
1903                 effective UID (EUID) or GID (EGID), respectively.  See above
1904                 for a description of what this means.
1905
1906            -r | -o restricted
1907                 The shell is a restricted shell.  This option can only be
1908                 used when the shell is invoked.  See above for a description
1909                 of what this means.
1910
1911            -s | -o stdin
1912                 If used when the shell is invoked, commands are read from
1913                 standard input.  Set automatically if the shell is invoked
1914                 with no arguments.
1915
1916                 When -s is used with the set command it causes the specified
1917                 arguments to be sorted before assigning them to the posi‐
1918                 tional parameters (or to array name, if -A is used).
1919
1920            -U | -o utf8-mode
1921                 Enable UTF-8 support in the Emacs editing mode and internal
1922                 string handling functions.  This flag is disabled by default,
1923                 but can be enabled by setting it on the shell command line;
1924                 is enabled automatically for interactive shells if requested
1925                 at compile time, your system supports setlocale(LC_CTYPE, "")
1926                 and optionally nl_langinfo(CODESET), or the LC_ALL, LC_CTYPE,
1927                 or LANG environment variables, and at least one of these
1928                 returns something that matches “UTF-8” or “utf8” case-insen‐
1929                 sitively; for direct builtin calls depending on the aforemen‐
1930                 tioned environment variables; or for stdin or scripts, if the
1931                 input begins with a UTF-8 Byte Order Mark.
1932
1933            -u | -o nounset
1934                 Referencing of an unset parameter, other than “$@” or “$*”,
1935                 is treated as an error, unless one of the ‘-’, ‘+’, or ‘=’
1936                 modifiers is used.
1937
1938            -v | -o verbose
1939                 Write shell input to standard error as it is read.
1940
1941            -X | -o markdirs
1942                 Mark directories with a trailing ‘/’ during file name genera‐
1943                 tion.
1944
1945            -x | -o xtrace
1946                 Print commands and parameter assignments when they are exe‐
1947                 cuted, preceded by the value of PS4.
1948
1949            -o arc4random
1950                 Deprecated, will be removed in mksh R41.  Do not use, emits a
1951                 warning to stderr.
1952
1953            -o bgnice
1954                 Background jobs are run with lower priority.
1955
1956            -o braceexpand
1957                 Enable brace expansion (a.k.a. alternation).  This is enabled
1958                 by default.  If disabled, tilde expansion after an equals
1959                 sign is disabled as a side effect.
1960
1961            -o emacs
1962                 Enable BRL emacs-like command-line editing (interactive
1963                 shells only); see Emacs editing mode.
1964
1965            -o gmacs
1966                 Enable gmacs-like command-line editing (interactive shells
1967                 only).  Currently identical to emacs editing except that
1968                 transpose-chars (^T) acts slightly differently.
1969
1970            -o ignoreeof
1971                 The shell will not (easily) exit when end-of-file is read;
1972                 exit must be used.  To avoid infinite loops, the shell will
1973                 exit if EOF is read 13 times in a row.
1974
1975            -o nohup
1976                 Do not kill running jobs with a SIGHUP signal when a login
1977                 shell exits.  Currently set by default, but this may change
1978                 in the future to be compatible with AT&T UNIX ksh, which
1979                 doesn't have this option, but does send the SIGHUP signal.
1980
1981            -o nolog
1982                 No effect.  In the original Korn shell, this prevents func‐
1983                 tion definitions from being stored in the history file.
1984
1985            -o physical
1986                 Causes the cd and pwd commands to use “physical” (i.e. the
1987                 filesystem's) ‘..’ directories instead of “logical” directo‐
1988                 ries (i.e. the shell handles ‘..’, which allows the user to
1989                 be oblivious of symbolic links to directories).  Clear by
1990                 default.  Note that setting this option does not affect the
1991                 current value of the PWD parameter; only the cd command
1992                 changes PWD.  See the cd and pwd commands above for more
1993                 details.
1994
1995            -o posix
1996                 Enable a somewhat more POSIXish mode.  As a side effect, set‐
1997                 ting this flag turns off braceexpand mode, which can be
1998                 turned back on manually, and sh mode.
1999
2000            -o sh
2001                 Enable /bin/sh (kludge) mode.  Automatically enabled if the
2002                 basename of the shell invocation begins with “sh” and this
2003                 autodetection feature is compiled in (not in MirBSD).  As a
2004                 side effect, setting this flag turns off braceexpand mode,
2005                 which can be turned back on manually, and posix mode.
2006
2007            -o vi
2008                 Enable vi(1)-like command-line editing (interactive shells
2009                 only).
2010
2011            -o vi-esccomplete
2012                 In vi command-line editing, do command and file name comple‐
2013                 tion when escape (^[) is entered in command mode.
2014
2015            -o vi-tabcomplete
2016                 In vi command-line editing, do command and file name comple‐
2017                 tion when tab (^I) is entered in insert mode.  This is the
2018                 default.
2019
2020            -o viraw
2021                 No effect.  In the original Korn shell, unless viraw was set,
2022                 the vi command-line mode would let the tty(4) driver do the
2023                 work until ESC (^[) was entered.  mksh is always in viraw
2024                 mode.
2025
2026            These options can also be used upon invocation of the shell.  The
2027            current set of options (with single letter names) can be found in
2028            the parameter ‘$-’.  set -o with no option name will list all the
2029            options and whether each is on or off; set +o will print the long
2030            names of all options that are currently on.
2031
2032            Remaining arguments, if any, are positional parameters and are
2033            assigned, in order, to the positional parameters (i.e. $1, $2,
2034            etc.).  If options end with ‘--’ and there are no remaining argu‐
2035            ments, all positional parameters are cleared.  If no options or
2036            arguments are given, the values of all names are printed.  For
2037            unknown historical reasons, a lone ‘-’ option is treated specially
2038            – it clears both the -v and -x options.
2039
2040     shift [number]
2041            The positional parameters number+1, number+2, etc. are renamed to
2042            ‘1’, ‘2’, etc.  number defaults to 1.
2043
2044     sleep seconds
2045            Suspends execution for a minimum of the seconds specified as posi‐
2046            tive decimal value with an optional fractional part.  Signal
2047            delivery may continue execution earlier.
2048
2049     source file [arg ...]
2050            Like . (“dot”), except that the current working directory is
2051            appended to the PATH in GNU bash and mksh.  In ksh93 and mksh,
2052            this is implemented as a shell alias instead of a builtin.
2053
2054     test expression
2055     [ expression ]
2056            test evaluates the expression and returns zero status if true, 1
2057            if false, or greater than 1 if there was an error.  It is normally
2058            used as the condition command of if and while statements.  Sym‐
2059            bolic links are followed for all file expressions except -h and
2060            -L.
2061
2062            The following basic expressions are available:
2063
2064            -a file            file exists.
2065
2066            -b file            file is a block special device.
2067
2068            -c file            file is a character special device.
2069
2070            -d file            file is a directory.
2071
2072            -e file            file exists.
2073
2074            -f file            file is a regular file.
2075
2076            -G file            file's group is the shell's effective group ID.
2077
2078            -g file            file's mode has the setgid bit set.
2079
2080            -H file            file is a context dependent directory (only
2081                               useful on HP-UX).
2082
2083            -h file            file is a symbolic link.
2084
2085            -k file            file's mode has the sticky(8) bit set.
2086
2087            -L file            file is a symbolic link.
2088
2089            -O file            file's owner is the shell's effective user ID.
2090
2091            -o option          Shell option is set (see the set command above
2092                               for a list of options).  As a non-standard
2093                               extension, if the option starts with a ‘!’, the
2094                               test is negated; the test always fails if
2095                               option doesn't exist (so [ -o foo -o -o !foo ]
2096                               returns true if and only if option foo exists).
2097                               The same can be achieved with [ -o ?foo ] like
2098                               in AT&T UNIX ksh93.  option can also be the
2099                               short flag led by either ‘-’ or ‘+’ (no logical
2100                               negation), for example ‘-x’ or ‘+x’ instead of
2101                               ‘xtrace’.
2102
2103            -p file            file is a named pipe.
2104
2105            -r file            file exists and is readable.
2106
2107            -S file            file is a unix(4)-domain socket.
2108
2109            -s file            file is not empty.
2110
2111            -t fd              File descriptor fd is a tty(4) device.
2112
2113            -u file            file's mode has the setuid bit set.
2114
2115            -w file            file exists and is writable.
2116
2117            -x file            file exists and is executable.
2118
2119            file1 -nt file2    file1 is newer than file2 or file1 exists and
2120                               file2 does not.
2121
2122            file1 -ot file2    file1 is older than file2 or file2 exists and
2123                               file1 does not.
2124
2125            file1 -ef file2    file1 is the same file as file2.
2126
2127            string             string has non-zero length.
2128
2129            -n string          string is not empty.
2130
2131            -z string          string is empty.
2132
2133            string = string    Strings are equal.
2134
2135            string == string   Strings are equal.
2136
2137            string > string    First string operand is greater than second
2138                               string operand.
2139
2140            string < string    First string operand is less than second string
2141                               operand.
2142
2143            string != string   Strings are not equal.
2144
2145            number -eq number  Numbers compare equal.
2146
2147            number -ne number  Numbers compare not equal.
2148
2149            number -ge number  Numbers compare greater than or equal.
2150
2151            number -gt number  Numbers compare greater than.
2152
2153            number -le number  Numbers compare less than or equal.
2154
2155            number -lt number  Numbers compare less than.
2156
2157            The above basic expressions, in which unary operators have prece‐
2158            dence over binary operators, may be combined with the following
2159            operators (listed in increasing order of precedence):
2160
2161                  expr -o expr            Logical OR.
2162                  expr -a expr            Logical AND.
2163                  ! expr                  Logical NOT.
2164                  ( expr )                Grouping.
2165
2166            Note that a number actually may be an arithmetic expression, such
2167            as a mathematical term or the name of an integer variable:
2168
2169                  x=1; [ "x" -eq 1 ]      evaluates to true
2170
2171            Note that some special rules are applied (courtesy of POSIX) if
2172            the number of arguments to test or [ ... ] is less than five: if
2173            leading ‘!’ arguments can be stripped such that only one argument
2174            remains then a string length test is performed (again, even if the
2175            argument is a unary operator); if leading ‘!’ arguments can be
2176            stripped such that three arguments remain and the second argument
2177            is a binary operator, then the binary operation is performed (even
2178            if the first argument is a unary operator, including an unstripped
2179            ‘!’).
2180
2181            Note: A common mistake is to use “if [ $foo = bar ]” which fails
2182            if parameter “foo” is NULL or unset, if it has embedded spaces
2183            (i.e. IFS octets), or if it is a unary operator like ‘!’ or ‘-n’.
2184            Use tests like “if [ x"$foo" = x"bar" ]” instead, or the double-
2185            bracket operator “if [[ $foo = bar ]]” or, to avoid pattern match‐
2186            ing (see [[ above): “if [[ $foo = "$bar" ]]”
2187
2188     time [-p] [pipeline]
2189            If a pipeline is given, the times used to execute the pipeline are
2190            reported.  If no pipeline is given, then the user and system time
2191            used by the shell itself, and all the commands it has run since it
2192            was started, are reported.  The times reported are the real time
2193            (elapsed time from start to finish), the user CPU time (time spent
2194            running in user mode), and the system CPU time (time spent running
2195            in kernel mode).  Times are reported to standard error; the format
2196            of the output is:
2197
2198                  0m0.00s real     0m0.00s user     0m0.00s system
2199
2200            If the -p option is given the output is slightly longer:
2201
2202                  real     0.00
2203                  user     0.00
2204                  sys      0.00
2205
2206            It is an error to specify the -p option unless pipeline is a sim‐
2207            ple command.
2208
2209            Simple redirections of standard error do not affect the output of
2210            the time command:
2211
2212                  $ time sleep 1 2>afile
2213                  $ { time sleep 1; } 2>afile
2214
2215            Times for the first command do not go to “afile”, but those of the
2216            second command do.
2217
2218     times  Print the accumulated user and system times used both by the shell
2219            and by processes that the shell started which have exited.  The
2220            format of the output is:
2221
2222                  0m0.00s 0m0.00s
2223                  0m0.00s 0m0.00s
2224
2225     trap [handler signal ...]
2226            Sets a trap handler that is to be executed when any of the speci‐
2227            fied signals are received.  handler is either a NULL string, indi‐
2228            cating the signals are to be ignored, a minus sign (‘-’), indicat‐
2229            ing that the default action is to be taken for the signals (see
2230            signal(3)), or a string containing shell commands to be evaluated
2231            and executed at the first opportunity (i.e. when the current com‐
2232            mand completes, or before printing the next PS1 prompt) after
2233            receipt of one of the signals.  signal is the name of a signal
2234            (e.g. PIPE or ALRM) or the number of the signal (see the kill -l
2235            command above).
2236
2237            There are two special signals: EXIT (also known as 0) which is
2238            executed when the shell is about to exit, and ERR, which is exe‐
2239            cuted after an error occurs (an error is something that would
2240            cause the shell to exit if the -e or errexit option were set – see
2241            the set command above).  EXIT handlers are executed in the envi‐
2242            ronment of the last executed command.  Note that for non-interac‐
2243            tive shells, the trap handler cannot be changed for signals that
2244            were ignored when the shell started.
2245
2246            With no arguments, trap lists, as a series of trap commands, the
2247            current state of the traps that have been set since the shell
2248            started.  Note that the output of trap cannot be usefully piped to
2249            another process (an artifact of the fact that traps are cleared
2250            when subprocesses are created).
2251
2252            The original Korn shell's DEBUG trap and the handling of ERR and
2253            EXIT traps in functions are not yet implemented.
2254
2255     true   A command that exits with a zero value.
2256
2257     global [[+-alpnrtUux] [-L[n]] [-R[n]] [-Z[n]] [-i[n]] | -f [-tux]] [name
2258            [=value] ...]
2259     typeset [[+-alpnrtUux] [-LRZ[n]] [-i[n]] | -f [-tux]] [name [=value] ...]
2260            Display or set parameter attributes.  With no name arguments,
2261            parameter attributes are displayed; if no options are used, the
2262            current attributes of all parameters are printed as typeset com‐
2263            mands; if an option is given (or ‘-’ with no option letter), all
2264            parameters and their values with the specified attributes are
2265            printed; if options are introduced with ‘+’, parameter values are
2266            not printed.
2267
2268            If name arguments are given, the attributes of the named parame‐
2269            ters are set (-) or cleared (+).  Values for parameters may
2270            optionally be specified.  For name[*], the change affects the
2271            entire array, and no value may be specified.
2272
2273            If typeset is used inside a function, any parameters specified are
2274            localised.  This is not done by the otherwise identical global.
2275
2276            When -f is used, typeset operates on the attributes of functions.
2277            As with parameters, if no name arguments are given, functions are
2278            listed with their values (i.e. definitions) unless options are
2279            introduced with ‘+’, in which case only the function names are
2280            reported.
2281
2282            -a      Indexed array attribute.
2283
2284            -f      Function mode.  Display or set functions and their
2285                    attributes, instead of parameters.
2286
2287            -i[n]   Integer attribute.  n specifies the base to use when dis‐
2288                    playing the integer (if not specified, the base given in
2289                    the first assignment is used).  Parameters with this
2290                    attribute may be assigned values containing arithmetic
2291                    expressions.
2292
2293            -L[n]   Left justify attribute.  n specifies the field width.  If
2294                    n is not specified, the current width of a parameter (or
2295                    the width of its first assigned value) is used.  Leading
2296                    whitespace (and zeros, if used with the -Z option) is
2297                    stripped.  If necessary, values are either truncated or
2298                    space padded to fit the field width.
2299
2300            -l      Lower case attribute.  All upper case characters in values
2301                    are converted to lower case.  (In the original Korn shell,
2302                    this parameter meant “long integer” when used with the -i
2303                    option.)
2304
2305            -n      Create a bound variable (name reference): any access to
2306                    the variable name will access the variable value in the
2307                    current scope (this is different from AT&T UNIX ksh93!)
2308                    instead.  Also different from AT&T UNIX ksh93 is that
2309                    value is lazily evaluated at the time name is accessed.
2310                    This can be used by functions to access variables whose
2311                    names are passed as parametres, instead of using eval.
2312
2313            -p      Print complete typeset commands that can be used to re-
2314                    create the attributes and values of parameters.
2315
2316            -R[n]   Right justify attribute.  n specifies the field width.  If
2317                    n is not specified, the current width of a parameter (or
2318                    the width of its first assigned value) is used.  Trailing
2319                    whitespace is stripped.  If necessary, values are either
2320                    stripped of leading characters or space padded to make
2321                    them fit the field width.
2322
2323            -r      Read-only attribute.  Parameters with this attribute may
2324                    not be assigned to or unset.  Once this attribute is set,
2325                    it cannot be turned off.
2326
2327            -t      Tag attribute.  Has no meaning to the shell; provided for
2328                    application use.
2329
2330                    For functions, -t is the trace attribute.  When functions
2331                    with the trace attribute are executed, the xtrace (-x)
2332                    shell option is temporarily turned on.
2333
2334            -U      Unsigned integer attribute.  Integers are printed as
2335                    unsigned values (combine with the -i option).  This option
2336                    is not in the original Korn shell.
2337
2338            -u      Upper case attribute.  All lower case characters in values
2339                    are converted to upper case.  (In the original Korn shell,
2340                    this parameter meant “unsigned integer” when used with the
2341                    -i option which meant upper case letters would never be
2342                    used for bases greater than 10.  See the -U option.)
2343
2344                    For functions, -u is the undefined attribute.  See
2345                    Functions above for the implications of this.
2346
2347            -x      Export attribute.  Parameters (or functions) are placed in
2348                    the environment of any executed commands.  Exported func‐
2349                    tions are not yet implemented.
2350
2351            -Z[n]   Zero fill attribute.  If not combined with -L, this is the
2352                    same as -R, except zero padding is used instead of space
2353                    padding.  For integers, the number instead of the base is
2354                    padded.
2355
2356            If any of the -i, -L, -l, -R, -U, -u, or -Z options are changed,
2357            all others from this set are cleared, unless they are also given
2358            on the same command line.
2359
2360     ulimit [-aBCcdefHiLlMmnOPpqrSsTtVvw] [value]
2361            Display or set process limits.  If no options are used, the file
2362            size limit (-f) is assumed.  value, if specified, may be either an
2363            arithmetic expression or the word “unlimited”.  The limits affect
2364            the shell and any processes created by the shell after a limit is
2365            imposed.  Note that some systems may not allow limits to be
2366            increased once they are set.  Also note that the types of limits
2367            available are system dependent – some systems have only the -f
2368            limit.
2369
2370            -a     Display all limits; unless -H is used, soft limits are dis‐
2371                   played.
2372
2373            -B n   Set the socket buffer size to n kibibytes.
2374
2375            -C n   Set the number of cached threads to n.
2376
2377            -c n   Impose a size limit of n blocks on the size of core dumps.
2378
2379            -d n   Impose a size limit of n kibibytes on the size of the data
2380                   area.
2381
2382            -e n   Set the maximum niceness to n.
2383
2384            -f n   Impose a size limit of n blocks on files written by the
2385                   shell and its child processes (files of any size may be
2386                   read).
2387
2388            -H     Set the hard limit only (the default is to set both hard
2389                   and soft limits).
2390
2391            -i n   Set the number of pending signals to n.
2392
2393            -L n   Control flocks; documentation is missing.
2394
2395            -l n   Impose a limit of n kibibytes on the amount of locked
2396                   (wired) physical memory.
2397
2398            -M n   Set the AIO locked memory to n kibibytes.
2399
2400            -m n   Impose a limit of n kibibytes on the amount of physical
2401                   memory used.
2402
2403            -n n   Impose a limit of n file descriptors that can be open at
2404                   once.
2405
2406            -O n   Set the number of AIO operations to n.
2407
2408            -P n   Limit the number of threads per process to n.
2409
2410            -p n   Impose a limit of n processes that can be run by the user
2411                   at any one time.
2412
2413            -q n   Limit the size of POSIX message queues to n bytes.
2414
2415            -r n   Set the maximum real-time priority to n.
2416
2417            -S     Set the soft limit only (the default is to set both hard
2418                   and soft limits).
2419
2420            -s n   Impose a size limit of n kibibytes on the size of the stack
2421                   area.
2422
2423            -T n   Impose a time limit of n real seconds to be used by each
2424                   process.
2425
2426            -t n   Impose a time limit of n CPU seconds spent in user mode to
2427                   be used by each process.
2428
2429            -V n   Set the number of vnode monitors on Haiku to n.
2430
2431            -v n   Impose a limit of n kibibytes on the amount of virtual mem‐
2432                   ory (address space) used.
2433
2434            -w n   Impose a limit of n kibibytes on the amount of swap space
2435                   used.
2436
2437            As far as ulimit is concerned, a block is 512 bytes.
2438
2439     umask [-S] [mask]
2440            Display or set the file permission creation mask, or umask (see
2441            umask(2)).  If the -S option is used, the mask displayed or set is
2442            symbolic; otherwise, it is an octal number.
2443
2444            Symbolic masks are like those used by chmod(1).  When used, they
2445            describe what permissions may be made available (as opposed to
2446            octal masks in which a set bit means the corresponding bit is to
2447            be cleared).  For example, “ug=rwx,o=” sets the mask so files will
2448            not be readable, writable, or executable by “others”, and is
2449            equivalent (on most systems) to the octal mask “007”.
2450
2451     unalias [-adt] [name ...]
2452            The aliases for the given names are removed.  If the -a option is
2453            used, all aliases are removed.  If the -t or -d options are used,
2454            the indicated operations are carried out on tracked or directory
2455            aliases, respectively.
2456
2457     unset [-fv] parameter ...
2458            Unset the named parameters (-v, the default) or functions (-f).
2459            With parameter[*], attributes are kept, only values are unset.
2460
2461            The exit status is non-zero if any of the parameters have the
2462            read-only attribute set, zero otherwise.
2463
2464     wait [job ...]
2465            Wait for the specified job(s) to finish.  The exit status of wait
2466            is that of the last specified job; if the last job is killed by a
2467            signal, the exit status is 128 + the number of the signal (see
2468            kill -l exit-status above); if the last specified job can't be
2469            found (because it never existed, or had already finished), the
2470            exit status of wait is 127.  See Job control below for the format
2471            of job.  wait will return if a signal for which a trap has been
2472            set is received, or if a SIGHUP, SIGINT, or SIGQUIT signal is
2473            received.
2474
2475            If no jobs are specified, wait waits for all currently running
2476            jobs (if any) to finish and exits with a zero status.  If job mon‐
2477            itoring is enabled, the completion status of jobs is printed (this
2478            is not the case when jobs are explicitly specified).
2479
2480     whence [-pv] [name ...]
2481            For each name, the type of command is listed (reserved word,
2482            built-in, alias, function, tracked alias, or executable).  If the
2483            -p option is used, a path search is performed even if name is a
2484            reserved word, alias, etc.  Without the -v option, whence is simi‐
2485            lar to command -v except that whence will find reserved words and
2486            won't print aliases as alias commands.  With the -v option, whence
2487            is the same as command -V.  Note that for whence, the -p option
2488            does not affect the search path used, as it does for command.  If
2489            the type of one or more of the names could not be determined, the
2490            exit status is non-zero.
2491
2492   Job control
2493     Job control refers to the shell's ability to monitor and control jobs
2494     which are processes or groups of processes created for commands or pipe‐
2495     lines.  At a minimum, the shell keeps track of the status of the back‐
2496     ground (i.e. asynchronous) jobs that currently exist; this information
2497     can be displayed using the jobs commands.  If job control is fully
2498     enabled (using set -m or set -o monitor), as it is for interactive
2499     shells, the processes of a job are placed in their own process group.
2500     Foreground jobs can be stopped by typing the suspend character from the
2501     terminal (normally ^Z), jobs can be restarted in either the foreground or
2502     background using the fg and bg commands, and the state of the terminal is
2503     saved or restored when a foreground job is stopped or restarted, respec‐
2504     tively.
2505
2506     Note that only commands that create processes (e.g. asynchronous com‐
2507     mands, subshell commands, and non-built-in, non-function commands) can be
2508     stopped; commands like read cannot be.
2509
2510     When a job is created, it is assigned a job number.  For interactive
2511     shells, this number is printed inside “[..]”, followed by the process IDs
2512     of the processes in the job when an asynchronous command is run.  A job
2513     may be referred to in the bg, fg, jobs, kill, and wait commands either by
2514     the process ID of the last process in the command pipeline (as stored in
2515     the $! parameter) or by prefixing the job number with a percent sign
2516     (‘%’).  Other percent sequences can also be used to refer to jobs:
2517
2518     %+ | %% | %    The most recently stopped job, or, if there are no stopped
2519                    jobs, the oldest running job.
2520
2521     %-             The job that would be the %+ job if the latter did not
2522                    exist.
2523
2524     %n             The job with job number n.
2525
2526     %?string       The job with its command containing the string string (an
2527                    error occurs if multiple jobs are matched).
2528
2529     %string        The job with its command starting with the string string
2530                    (an error occurs if multiple jobs are matched).
2531
2532     When a job changes state (e.g. a background job finishes or foreground
2533     job is stopped), the shell prints the following status information:
2534
2535           [number] flag status command
2536
2537     where...
2538
2539     number   is the job number of the job;
2540
2541     flag     is the ‘+’ or ‘-’ character if the job is the %+ or %- job,
2542              respectively, or space if it is neither;
2543
2544     status   indicates the current state of the job and can be:
2545
2546              Done [number]
2547                         The job exited.  number is the exit status of the job
2548                         which is omitted if the status is zero.
2549
2550              Running    The job has neither stopped nor exited (note that
2551                         running does not necessarily mean consuming CPU time
2552                         – the process could be blocked waiting for some
2553                         event).
2554
2555              Stopped [signal]
2556                         The job was stopped by the indicated signal (if no
2557                         signal is given, the job was stopped by SIGTSTP).
2558
2559              signal-description [“core dumped”]
2560                         The job was killed by a signal (e.g. memory fault,
2561                         hangup); use kill -l for a list of signal descrip‐
2562                         tions.  The “core dumped” message indicates the
2563                         process created a core file.
2564
2565     command  is the command that created the process.  If there are multiple
2566              processes in the job, each process will have a line showing its
2567              command and possibly its status, if it is different from the
2568              status of the previous process.
2569
2570     When an attempt is made to exit the shell while there are jobs in the
2571     stopped state, the shell warns the user that there are stopped jobs and
2572     does not exit.  If another attempt is immediately made to exit the shell,
2573     the stopped jobs are sent a SIGHUP signal and the shell exits.  Simi‐
2574     larly, if the nohup option is not set and there are running jobs when an
2575     attempt is made to exit a login shell, the shell warns the user and does
2576     not exit.  If another attempt is immediately made to exit the shell, the
2577     running jobs are sent a SIGHUP signal and the shell exits.
2578
2579   Interactive input line editing
2580     The shell supports three modes of reading command lines from a tty(4) in
2581     an interactive session, controlled by the emacs, gmacs, and vi options
2582     (at most one of these can be set at once).  The default is emacs.  Edit‐
2583     ing modes can be set explicitly using the set built-in.  If none of these
2584     options are enabled, the shell simply reads lines using the normal tty(4)
2585     driver.  If the emacs or gmacs option is set, the shell allows emacs-like
2586     editing of the command; similarly, if the vi option is set, the shell
2587     allows vi-like editing of the command.  These modes are described in
2588     detail in the following sections.
2589
2590     In these editing modes, if a line is longer than the screen width (see
2591     the COLUMNS parameter), a ‘>’, ‘+’, or ‘<’ character is displayed in the
2592     last column indicating that there are more characters after, before and
2593     after, or before the current position, respectively.  The line is
2594     scrolled horizontally as necessary.
2595
2596     Completed lines are pushed into the history, unless they begin with an
2597     IFS octet or IFS white space, or are the same as the previous line.
2598
2599   Emacs editing mode
2600     When the emacs option is set, interactive input line editing is enabled.
2601     Warning: This mode is slightly different from the emacs mode in the orig‐
2602     inal Korn shell.  In this mode, various editing commands (typically bound
2603     to one or more control characters) cause immediate actions without wait‐
2604     ing for a newline.  Several editing commands are bound to particular con‐
2605     trol characters when the shell is invoked; these bindings can be changed
2606     using the bind command.
2607
2608     The following is a list of available editing commands.  Each description
2609     starts with the name of the command, suffixed with a colon; an [n] (if
2610     the command can be prefixed with a count); and any keys the command is
2611     bound to by default, written using caret notation e.g. the ASCII ESC
2612     character is written as ^[.  These control sequences are not case sensi‐
2613     tive.  A count prefix for a command is entered using the sequence ^[n,
2614     where n is a sequence of 1 or more digits.  Unless otherwise specified,
2615     if a count is omitted, it defaults to 1.
2616
2617     Note that editing command names are used only with the bind command.
2618     Furthermore, many editing commands are useful only on terminals with a
2619     visible cursor.  The default bindings were chosen to resemble correspond‐
2620     ing Emacs key bindings.  The user's tty(4) characters (e.g. ERASE) are
2621     bound to reasonable substitutes and override the default bindings.
2622
2623     abort: ^C, ^G
2624             Abort the current command, empty the line buffer and set the exit
2625             state to interrupted.
2626
2627     auto-insert: [n]
2628             Simply causes the character to appear as literal input.  Most
2629             ordinary characters are bound to this.
2630
2631     backward-char: [n] ^B, ^XD, ANSI-CurLeft
2632             Moves the cursor backward n characters.
2633
2634     backward-word: [n] ^[b, ANSI-Ctrl-CurLeft, ANSI-Alt-CurLeft
2635             Moves the cursor backward to the beginning of the word; words
2636             consist of alphanumerics, underscore (‘_’), and dollar sign (‘$’)
2637             characters.
2638
2639     beginning-of-history: ^[<
2640             Moves to the beginning of the history.
2641
2642     beginning-of-line: ^A, ANSI-Home
2643             Moves the cursor to the beginning of the edited input line.
2644
2645     capitalise-word: [n] ^[C, ^[c
2646             Uppercase the first character in the next n words, leaving the
2647             cursor past the end of the last word.
2648
2649     clear-screen: ^[^L
2650             Prints a compile-time configurable sequence to clear the screen
2651             and home the cursor, redraws the entire prompt and the currently
2652             edited input line.  The default sequence works for almost all
2653             standard terminals.
2654
2655     comment: ^[#
2656             If the current line does not begin with a comment character, one
2657             is added at the beginning of the line and the line is entered (as
2658             if return had been pressed); otherwise, the existing comment
2659             characters are removed and the cursor is placed at the beginning
2660             of the line.
2661
2662     complete: ^[^[
2663             Automatically completes as much as is unique of the command name
2664             or the file name containing the cursor.  If the entire remaining
2665             command or file name is unique, a space is printed after its com‐
2666             pletion, unless it is a directory name in which case ‘/’ is
2667             appended.  If there is no command or file name with the current
2668             partial word as its prefix, a bell character is output (usually
2669             causing a beep to be sounded).
2670
2671     complete-command: ^X^[
2672             Automatically completes as much as is unique of the command name
2673             having the partial word up to the cursor as its prefix, as in the
2674             complete command above.
2675
2676     complete-file: ^[^X
2677             Automatically completes as much as is unique of the file name
2678             having the partial word up to the cursor as its prefix, as in the
2679             complete command described above.
2680
2681     complete-list: ^I, ^[=
2682             Complete as much as is possible of the current word, and list the
2683             possible completions for it.  If only one completion is possible,
2684             match as in the complete command above.  Note that ^I is usually
2685             generated by the TAB (tabulator) key.
2686
2687     delete-char-backward: [n] ERASE, ^?, ^H
2688             Deletes n characters before the cursor.
2689
2690     delete-char-forward: [n] ANSI-Del
2691             Deletes n characters after the cursor.
2692
2693     delete-word-backward: [n] WERASE, ^[^?, ^[^H, ^[h
2694             Deletes n words before the cursor.
2695
2696     delete-word-forward: [n] ^[d
2697             Deletes characters after the cursor up to the end of n words.
2698
2699     down-history: [n] ^N, ^XB, ANSI-CurDown
2700             Scrolls the history buffer forward n lines (later).  Each input
2701             line originally starts just after the last entry in the history
2702             buffer, so down-history is not useful until either
2703             search-history, search-history-up or up-history has been per‐
2704             formed.
2705
2706     downcase-word: [n] ^[L, ^[l
2707             Lowercases the next n words.
2708
2709     edit-line: [n] ^Xe
2710             Edit line n or the current line, if not specified, interactively.
2711             The actual command executed is fc -e ${VISUAL:-${EDITOR:-vi}} n.
2712
2713     end-of-history: ^[>
2714             Moves to the end of the history.
2715
2716     end-of-line: ^E, ANSI-End
2717             Moves the cursor to the end of the input line.
2718
2719     eot: ^_
2720             Acts as an end-of-file; this is useful because edit-mode input
2721             disables normal terminal input canonicalization.
2722
2723     eot-or-delete: [n] ^D
2724             Acts as eot if alone on a line; otherwise acts as
2725             delete-char-forward.
2726
2727     error: (not bound)
2728             Error (ring the bell).
2729
2730     exchange-point-and-mark: ^X^X
2731             Places the cursor where the mark is and sets the mark to where
2732             the cursor was.
2733
2734     expand-file: ^[*
2735             Appends a ‘*’ to the current word and replaces the word with the
2736             result of performing file globbing on the word.  If no files
2737             match the pattern, the bell is rung.
2738
2739     forward-char: [n] ^F, ^XC, ANSI-CurRight
2740             Moves the cursor forward n characters.
2741
2742     forward-word: [n] ^[f, ANSI-Ctrl-CurRight, ANSI-Alt-CurRight
2743             Moves the cursor forward to the end of the nth word.
2744
2745     goto-history: [n] ^[g
2746             Goes to history number n.
2747
2748     kill-line: KILL
2749             Deletes the entire input line.
2750
2751     kill-region: ^W
2752             Deletes the input between the cursor and the mark.
2753
2754     kill-to-eol: [n] ^K
2755             Deletes the input from the cursor to the end of the line if n is
2756             not specified; otherwise deletes characters between the cursor
2757             and column n.
2758
2759     list: ^[?
2760             Prints a sorted, columnated list of command names or file names
2761             (if any) that can complete the partial word containing the cur‐
2762             sor.  Directory names have ‘/’ appended to them.
2763
2764     list-command: ^X?
2765             Prints a sorted, columnated list of command names (if any) that
2766             can complete the partial word containing the cursor.
2767
2768     list-file: ^X^Y
2769             Prints a sorted, columnated list of file names (if any) that can
2770             complete the partial word containing the cursor.  File type indi‐
2771             cators are appended as described under list above.
2772
2773     newline: ^J, ^M
2774             Causes the current input line to be processed by the shell.  The
2775             current cursor position may be anywhere on the line.
2776
2777     newline-and-next: ^O
2778             Causes the current input line to be processed by the shell, and
2779             the next line from history becomes the current line.  This is
2780             only useful after an up-history, search-history or
2781             search-history-up.
2782
2783     no-op: QUIT
2784             This does nothing.
2785
2786     prefix-1: ^[
2787             Introduces a 2-character command sequence.
2788
2789     prefix-2: ^X, ^[[, ^[O
2790             Introduces a 2-character command sequence.
2791
2792     prev-hist-word: [n] ^[., ^[_
2793             The last word, or, if given, the nth word (zero-based) of the
2794             previous (on repeated execution, second-last, third-last, etc.)
2795             command is inserted at the cursor.  Use of this editing command
2796             trashes the mark.
2797
2798     quote: ^^, ^V
2799             The following character is taken literally rather than as an
2800             editing command.
2801
2802     redraw: ^L
2803             Reprints the last line of the prompt string and the current input
2804             line on a new line.
2805
2806     search-character-backward: [n] ^[^]
2807             Search backward in the current line for the nth occurrence of the
2808             next character typed.
2809
2810     search-character-forward: [n] ^]
2811             Search forward in the current line for the nth occurrence of the
2812             next character typed.
2813
2814     search-history: ^R
2815             Enter incremental search mode.  The internal history list is
2816             searched backwards for commands matching the input.  An initial
2817             ‘^’ in the search string anchors the search.  The escape key will
2818             leave search mode.  Other commands, including sequences of escape
2819             as prefix-1 followed by a prefix-1 or prefix-2 key will be exe‐
2820             cuted after leaving search mode.  The abort (^G) command will
2821             restore the input line before search started.  Successive
2822             search-history commands continue searching backward to the next
2823             previous occurrence of the pattern.  The history buffer retains
2824             only a finite number of lines; the oldest are discarded as neces‐
2825             sary.
2826
2827     search-history-up: ANSI-PgUp
2828             Search backwards through the history buffer for commands whose
2829             beginning match the portion of the input line before the cursor.
2830             When used on an empty line, this has the same effect as
2831             up-history.
2832
2833     search-history-down: ANSI-PgDn
2834             Search forwards through the history buffer for commands whose
2835             beginning match the portion of the input line before the cursor.
2836             When used on an empty line, this has the same effect as
2837             down-history.  This is only useful after an up-history,
2838             search-history or search-history-up.
2839
2840     set-mark-command: ^[⟨space⟩
2841             Set the mark at the cursor position.
2842
2843     transpose-chars: ^T
2844             If at the end of line, or if the gmacs option is set, this
2845             exchanges the two previous characters; otherwise, it exchanges
2846             the previous and current characters and moves the cursor one
2847             character to the right.
2848
2849     up-history: [n] ^P, ^XA, ANSI-CurUp
2850             Scrolls the history buffer backward n lines (earlier).
2851
2852     upcase-word: [n] ^[U, ^[u
2853             Uppercase the next n words.
2854
2855     version: ^[^V
2856             Display the version of mksh.  The current edit buffer is restored
2857             as soon as a key is pressed.  The restoring keypress is pro‐
2858             cessed, unless it is a space.
2859
2860     yank: ^Y
2861             Inserts the most recently killed text string at the current cur‐
2862             sor position.
2863
2864     yank-pop: ^[y
2865             Immediately after a yank, replaces the inserted text string with
2866             the next previously killed text string.
2867
2868   Vi editing mode
2869     Note: The vi command-line editing mode is orphaned, yet still functional.
2870
2871     The vi command-line editor in mksh has basically the same commands as the
2872     vi(1) editor with the following exceptions:
2873
2874     ·   You start out in insert mode.
2875
2876     ·   There are file name and command completion commands: =, \, *, ^X, ^E,
2877         ^F, and, optionally, ⟨tab⟩ and ⟨esc⟩.
2878
2879     ·   The _ command is different (in mksh, it is the last argument command;
2880         in vi(1) it goes to the start of the current line).
2881
2882     ·   The / and G commands move in the opposite direction to the j command.
2883
2884     ·   Commands which don't make sense in a single line editor are not
2885         available (e.g. screen movement commands and ex(1)-style colon (:)
2886         commands).
2887
2888     Like vi(1), there are two modes: “insert” mode and “command” mode.  In
2889     insert mode, most characters are simply put in the buffer at the current
2890     cursor position as they are typed; however, some characters are treated
2891     specially.  In particular, the following characters are taken from cur‐
2892     rent tty(4) settings (see stty(1)) and have their usual meaning (normal
2893     values are in parentheses): kill (^U), erase (^?), werase (^W), eof (^D),
2894     intr (^C), and quit (^\).  In addition to the above, the following char‐
2895     acters are also treated specially in insert mode:
2896
2897     ^E       Command and file name enumeration (see below).
2898
2899     ^F       Command and file name completion (see below).  If used twice in
2900              a row, the list of possible completions is displayed; if used a
2901              third time, the completion is undone.
2902
2903     ^H       Erases previous character.
2904
2905     ^J | ^M  End of line.  The current line is read, parsed, and executed by
2906              the shell.
2907
2908     ^V       Literal next.  The next character typed is not treated specially
2909              (can be used to insert the characters being described here).
2910
2911     ^X       Command and file name expansion (see below).
2912
2913     ⟨esc⟩    Puts the editor in command mode (see below).
2914
2915     ⟨tab⟩    Optional file name and command completion (see ^F above),
2916              enabled with set -o vi-tabcomplete.
2917
2918     In command mode, each character is interpreted as a command.  Characters
2919     that don't correspond to commands, are illegal combinations of commands,
2920     or are commands that can't be carried out, all cause beeps.  In the fol‐
2921     lowing command descriptions, an [n] indicates the command may be prefixed
2922     by a number (e.g. 10l moves right 10 characters); if no number prefix is
2923     used, n is assumed to be 1 unless otherwise specified.  The term “current
2924     position” refers to the position between the cursor and the character
2925     preceding the cursor.  A “word” is a sequence of letters, digits, and
2926     underscore characters or a sequence of non-letter, non-digit, non-under‐
2927     score, and non-whitespace characters (e.g. “ab2*&^” contains two words)
2928     and a “big-word” is a sequence of non-whitespace characters.
2929
2930     Special mksh vi commands:
2931
2932     The following commands are not in, or are different from, the normal vi
2933     file editor:
2934
2935     [n]_        Insert a space followed by the nth big-word from the last
2936                 command in the history at the current position and enter
2937                 insert mode; if n is not specified, the last word is
2938                 inserted.
2939
2940     #           Insert the comment character (‘#’) at the start of the cur‐
2941                 rent line and return the line to the shell (equivalent to
2942                 I#^J).
2943
2944     [n]g        Like G, except if n is not specified, it goes to the most
2945                 recent remembered line.
2946
2947     [n]v        Edit line n using the vi(1) editor; if n is not specified,
2948                 the current line is edited.  The actual command executed is
2949                 fc -e ${VISUAL:-${EDITOR:-vi}} n.
2950
2951     * and ^X    Command or file name expansion is applied to the current big-
2952                 word (with an appended ‘*’ if the word contains no file glob‐
2953                 bing characters) – the big-word is replaced with the result‐
2954                 ing words.  If the current big-word is the first on the line
2955                 or follows one of the characters ‘;’, ‘|’, ‘&’, ‘(’, or ‘)’,
2956                 and does not contain a slash (‘/’), then command expansion is
2957                 done; otherwise file name expansion is done.  Command expan‐
2958                 sion will match the big-word against all aliases, functions,
2959                 and built-in commands as well as any executable files found
2960                 by searching the directories in the PATH parameter.  File
2961                 name expansion matches the big-word against the files in the
2962                 current directory.  After expansion, the cursor is placed
2963                 just past the last word and the editor is in insert mode.
2964
2965     [n]\, [n]^F, [n]⟨tab⟩, and [n]⟨esc⟩
2966                 Command/file name completion.  Replace the current big-word
2967                 with the longest unique match obtained after performing com‐
2968                 mand and file name expansion.  ⟨tab⟩ is only recognised if
2969                 the vi-tabcomplete option is set, while ⟨esc⟩ is only recog‐
2970                 nised if the vi-esccomplete option is set (see set -o).  If n
2971                 is specified, the nth possible completion is selected (as
2972                 reported by the command/file name enumeration command).
2973
2974     = and ^E    Command/file name enumeration.  List all the commands or
2975                 files that match the current big-word.
2976
2977     ^V          Display the version of mksh.  The current edit buffer is
2978                 restored as soon as a key is pressed.  The restoring keypress
2979                 is ignored.
2980
2981     @c          Macro expansion.  Execute the commands found in the alias c.
2982
2983     Intra-line movement commands:
2984
2985     [n]h and [n]^H
2986             Move left n characters.
2987
2988     [n]l and [n]⟨space⟩
2989             Move right n characters.
2990
2991     0       Move to column 0.
2992
2993     ^       Move to the first non-whitespace character.
2994
2995     [n]|    Move to column n.
2996
2997     $       Move to the last character.
2998
2999     [n]b    Move back n words.
3000
3001     [n]B    Move back n big-words.
3002
3003     [n]e    Move forward to the end of the word, n times.
3004
3005     [n]E    Move forward to the end of the big-word, n times.
3006
3007     [n]w    Move forward n words.
3008
3009     [n]W    Move forward n big-words.
3010
3011     %       Find match.  The editor looks forward for the nearest parenthe‐
3012             sis, bracket, or brace and then moves the cursor to the matching
3013             parenthesis, bracket, or brace.
3014
3015     [n]fc   Move forward to the nth occurrence of the character c.
3016
3017     [n]Fc   Move backward to the nth occurrence of the character c.
3018
3019     [n]tc   Move forward to just before the nth occurrence of the character
3020             c.
3021
3022     [n]Tc   Move backward to just before the nth occurrence of the character
3023             c.
3024
3025     [n];    Repeats the last f, F, t, or T command.
3026
3027     [n],    Repeats the last f, F, t, or T command, but moves in the opposite
3028             direction.
3029
3030     Inter-line movement commands:
3031
3032     [n]j, [n]+, and [n]^N
3033             Move to the nth next line in the history.
3034
3035     [n]k, [n]-, and [n]^P
3036             Move to the nth previous line in the history.
3037
3038     [n]G    Move to line n in the history; if n is not specified, the number
3039             of the first remembered line is used.
3040
3041     [n]g    Like G, except if n is not specified, it goes to the most recent
3042             remembered line.
3043
3044     [n]/string
3045             Search backward through the history for the nth line containing
3046             string; if string starts with ‘^’, the remainder of the string
3047             must appear at the start of the history line for it to match.
3048
3049     [n]?string
3050             Same as /, except it searches forward through the history.
3051
3052     [n]n    Search for the nth occurrence of the last search string; the
3053             direction of the search is the same as the last search.
3054
3055     [n]N    Search for the nth occurrence of the last search string; the
3056             direction of the search is the opposite of the last search.
3057
3058     Edit commands
3059
3060     [n]a    Append text n times; goes into insert mode just after the current
3061             position.  The append is only replicated if command mode is re-
3062             entered i.e. ⟨esc⟩ is used.
3063
3064     [n]A    Same as a, except it appends at the end of the line.
3065
3066     [n]i    Insert text n times; goes into insert mode at the current posi‐
3067             tion.  The insertion is only replicated if command mode is re-
3068             entered i.e. ⟨esc⟩ is used.
3069
3070     [n]I    Same as i, except the insertion is done just before the first
3071             non-blank character.
3072
3073     [n]s    Substitute the next n characters (i.e. delete the characters and
3074             go into insert mode).
3075
3076     S       Substitute whole line.  All characters from the first non-blank
3077             character to the end of the line are deleted and insert mode is
3078             entered.
3079
3080     [n]cmove-cmd
3081             Change from the current position to the position resulting from n
3082             move-cmds (i.e. delete the indicated region and go into insert
3083             mode); if move-cmd is c, the line starting from the first non-
3084             blank character is changed.
3085
3086     C       Change from the current position to the end of the line (i.e.
3087             delete to the end of the line and go into insert mode).
3088
3089     [n]x    Delete the next n characters.
3090
3091     [n]X    Delete the previous n characters.
3092
3093     D       Delete to the end of the line.
3094
3095     [n]dmove-cmd
3096             Delete from the current position to the position resulting from n
3097             move-cmds; move-cmd is a movement command (see above) or d, in
3098             which case the current line is deleted.
3099
3100     [n]rc   Replace the next n characters with the character c.
3101
3102     [n]R    Replace.  Enter insert mode but overwrite existing characters
3103             instead of inserting before existing characters.  The replacement
3104             is repeated n times.
3105
3106     [n]~    Change the case of the next n characters.
3107
3108     [n]ymove-cmd
3109             Yank from the current position to the position resulting from n
3110             move-cmds into the yank buffer; if move-cmd is y, the whole line
3111             is yanked.
3112
3113     Y       Yank from the current position to the end of the line.
3114
3115     [n]p    Paste the contents of the yank buffer just after the current
3116             position, n times.
3117
3118     [n]P    Same as p, except the buffer is pasted at the current position.
3119
3120     Miscellaneous vi commands
3121
3122     ^J and ^M
3123             The current line is read, parsed, and executed by the shell.
3124
3125     ^L and ^R
3126             Redraw the current line.
3127
3128     [n].    Redo the last edit command n times.
3129
3130     u       Undo the last edit command.
3131
3132     U       Undo all changes that have been made to the current line.
3133
3134     intr and quit
3135             The interrupt and quit terminal characters cause the current line
3136             to be deleted and a new prompt to be printed.
3137

FILES

3139     ~/.mkshrc          User mkshrc profile (non-privileged interactive
3140                        shells); see Startup files. The location can be
3141                        changed at compile time (for embedded systems); AOSP
3142                        Android builds use /system/etc/mkshrc.
3143     ~/.profile         User profile (non-privileged login shells); see
3144                        Startup files near the top of this manual.
3145     /etc/profile       System profile (login shells); see Startup files.
3146     /etc/shells        Shell database.
3147     /etc/suid_profile  Suid profile (privileged shells); see Startup files.
3148
3149     Note: On Android, /system/etc/ contains the system and suid profile.
3150

SEE ALSO

3152     awk(1), cat(1), ed(1), getopt(1), printf(1), sed(1), sh(1), stty(1),
3153     dup(2), execve(2), getgid(2), getuid(2), mknod(2), mkfifo(2), open(2),
3154     pipe(2), rename(2), wait(2), getopt(3), nl_langinfo(3), setlocale(3),
3155     signal(3), system(3), tty(4), shells(5), environ(7), script(7), utf-8(7),
3156     mknod(8)
3157
3158     http://docsrv.sco.com:507/en/man/html.C/sh.C.html
3159
3160     Morris Bolsky, The KornShell Command and Programming Language, Prentice
3161     Hall PTR, xvi + 356 pages, 1989, ISBN 978-0-13-516972-8 (0-13-516972-0).
3162
3163     Morris I. Bolsky and David G. Korn, The New KornShell Command and
3164     Programming Language (2nd Edition), Prentice Hall PTR, xvi + 400 pages,
3165     1995, ISBN 978-0-13-182700-4 (0-13-182700-6).
3166
3167     Stephen G. Kochan and Patrick H. Wood, UNIX Shell Programming, Hayden,
3168     Revised Edition, xi + 490 pages, 1990, ISBN 978-0-672-48448-3
3169     (0-672-48448-X).
3170
3171     IEEE Inc., IEEE Standard for Information Technology  Portable Operating
3172     System Interface (POSIX), IEEE Press, Part 2: Shell and Utilities,
3173     xvii + 1195 pages, 1993, ISBN 978-1-55937-255-8 (1-55937-255-9).
3174
3175     Bill Rosenblatt, Learning the Korn Shell, O'Reilly, 360 pages, 1993, ISBN
3176     978-1-56592-054-5 (1-56592-054-6).
3177
3178     Bill Rosenblatt and Arnold Robbins, Learning the Korn Shell, Second
3179     Edition, O'Reilly, 432 pages, 2002, ISBN 978-0-596-00195-7
3180     (0-596-00195-9).
3181
3182     Barry Rosenberg, KornShell Programming Tutorial, Addison-Wesley
3183     Professional, xxi + 324 pages, 1991, ISBN 978-0-201-56324-5
3184     (0-201-56324-X).
3185

AUTHORS

3187     The MirBSD Korn Shell is developed by Thorsten Glaser <tg@mirbsd.org> and
3188     currently maintained as part of The MirOS Project.  This shell is based
3189     upon the Public Domain Korn SHell.  The developer of mksh recognises the
3190     efforts of the pdksh authors, who had dedicated their work into Public
3191     Domain, our users, and all contributors, such as the Debian and OpenBSD
3192     projects.  See the documentation, CVS, and web site for details.
3193

CAVEATS

3195     mksh only supports the Unicode BMP (Basic Multilingual Plane).  It has a
3196     different scope model from AT&T UNIX ksh, which leads to subtile differ‐
3197     ences in semantics for identical builtins.
3198
3199     The parts of a pipeline, like below, are executed in subshells.  Thus,
3200     variable assignments inside them fail.  Use co-processes instead.
3201
3202           foo | bar | read baz            # will not change $baz
3203           foo | bar |& read -p baz        # will, however, do so
3204

BUGS

3206     Suspending (using ^Z) pipelines like the one below will only suspend the
3207     currently running part of the pipeline; in this example, “fubar” is imme‐
3208     diately printed on suspension (but not later after an fg).
3209
3210           $ /bin/sleep 666 && echo fubar
3211
3212     This document attempts to describe mksh R40c and up, compiled without any
3213     options impacting functionality, such as MKSH_SMALL, for an operating
3214     environment supporting all of its advanced needs.  Please report bugs in
3215     mksh to the MirOS mailing list at ⟨miros-discuss@mirbsd.org⟩ or in the
3216     #!/bin/mksh (or #ksh) IRC channel at irc.freenode.net:6667.
3217
3218MirBSD                         November 19, 2011                        MirBSD
Impressum