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

NAME

4     mksh, sh — MirBSD Korn shell
5

SYNOPSIS

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

FILES

3408     ~/.mkshrc          User mkshrc profile (non-privileged interactive
3409                        shells); see Startup files. The location can be
3410                        changed at compile time (e.g. for embedded systems);
3411                        AOSP Android builds use /system/etc/mkshrc.
3412     ~/.profile         User profile (non-privileged login shells); see
3413                        Startup files near the top of this manual.
3414     /etc/profile       System profile (login shells); see Startup files.
3415     /etc/shells        Shell database.
3416     /etc/suid_profile  Privileged shells' profile (sugid); see Startup files.
3417
3418     Note: On Android, /system/etc/ contains the system and suid profile.
3419

SEE ALSO

3421     awk(1), cat(1), ed(1), getopt(1), lksh(1), sed(1), sh(1), stty(1),
3422     dup(2), execve(2), getgid(2), getuid(2), mknod(2), mkfifo(2), open(2),
3423     pipe(2), rename(2), wait(2), getopt(3), nl_langinfo(3), setlocale(3),
3424     signal(3), system(3), tty(4), shells(5), environ(7), script(7), utf-8(7),
3425     mknod(8)
3426
3427     The FAQ at http://www.mirbsd.org/mksh-faq.htm or in the mksh.faq file.
3428
3429     http://www.mirbsd.org/ksh-chan.htm
3430
3431     Morris Bolsky, The KornShell Command and Programming Language, Prentice
3432     Hall PTR, xvi + 356 pages, 1989, ISBN 978-0-13-516972-8 (0-13-516972-0).
3433
3434     Morris I. Bolsky and David G. Korn, The New KornShell Command and
3435     Programming Language (2nd Edition), Prentice Hall PTR, xvi + 400 pages,
3436     1995, ISBN 978-0-13-182700-4 (0-13-182700-6).
3437
3438     Stephen G. Kochan and Patrick H. Wood, UNIX Shell Programming, Sams, 3rd
3439     Edition, xiii + 437 pages, 2003, ISBN 978-0-672-32490-1 (0-672-32490-3).
3440
3441     IEEE Inc., IEEE Standard for Information Technology  Portable Operating
3442     System Interface (POSIX), IEEE Press, Part 2: Shell and Utilities,
3443     xvii + 1195 pages, 1993, ISBN 978-1-55937-255-8 (1-55937-255-9).
3444
3445     Bill Rosenblatt, Learning the Korn Shell, O'Reilly, 360 pages, 1993, ISBN
3446     978-1-56592-054-5 (1-56592-054-6).
3447
3448     Bill Rosenblatt and Arnold Robbins, Learning the Korn Shell, Second
3449     Edition, O'Reilly, 432 pages, 2002, ISBN 978-0-596-00195-7
3450     (0-596-00195-9).
3451
3452     Barry Rosenberg, KornShell Programming Tutorial, Addison-Wesley
3453     Professional, xxi + 324 pages, 1991, ISBN 978-0-201-56324-5
3454     (0-201-56324-X).
3455

AUTHORS

3457     The MirBSD Korn Shell is developed by mirabilos <m@mirbsd.org> as part of
3458     The MirOS Project.  This shell is based on the public domain 7th edition
3459     Bourne shell clone by Charles Forsyth, who kindly agreed to, in countries
3460     where the Public Domain status of the work may not be valid, grant a
3461     copyright licence to the general public to deal in the work without
3462     restriction and permission to sublicence derivatives under the terms of
3463     any (OSI approved) Open Source licence, and parts of the BRL shell by
3464     Doug A. Gwyn, Doug Kingston, Ron Natalie, Arnold Robbins, Lou Salkind and
3465     others.  The first release of pdksh was created by Eric Gisin, and it was
3466     subsequently maintained by John R. MacMillan, Simon J. Gerraty and
3467     Michael Rendell.  The effort of several projects, such as Debian and
3468     OpenBSD, and other contributors including our users, to improve the shell
3469     is appreciated.  See the documentation, website and source code (CVS) for
3470     details.
3471
3472     mksh-os2 is developed by KO Myung-Hun <komh@chollian.net>.
3473
3474     mksh-w32 is developed by Michael Langguth <lan@scalaris.com>.
3475
3476     mksh/z/OS is contributed by Daniel Richard G. <skunk@iSKUNK.ORG>.
3477
3478     The BSD daemon is Copyright © Marshall Kirk McKusick.  The complete
3479     legalese is at: http://www.mirbsd.org/TaC-mksh.txt
3480

CAVEATS

3482     mksh provides a consistent, clear interface normally.  This may deviate
3483     from POSIX in historic or opinionated places.  set -o posix (see POSIX
3484     mode for details) will make the shell more conformant, but mind the FAQ
3485     (see SEE ALSO), especially regarding locales.  mksh (but not lksh) pro‐
3486     vides a consistent 32-bit integer arithmetic implementation, both signed
3487     and unsigned, with sign of the result of a remainder operation and wrap‐
3488     around defined, even (defying POSIX) on 36-bit and 64-bit systems.
3489
3490     mksh currently uses OPTU-16 internally, which is the same as UTF-8 and
3491     CESU-8 with 0000..FFFD being valid codepoints; raw octets are mapped into
3492     the PUA range EF80..EFFF, which is assigned by CSUR for this purpose.
3493

BUGS

3495     Suspending (using ^Z) pipelines like the one below will only suspend the
3496     currently running part of the pipeline; in this example, “fubar” is imme‐
3497     diately printed on suspension (but not later after an fg).
3498
3499           $ /bin/sleep 666 && echo fubar
3500
3501     The truncation process involved when changing HISTFILE does not free old
3502     history entries (leaks memory) and leaks old entries into the new history
3503     if their line numbers are not overwritten by same-number entries from the
3504     persistent history file; truncating the on-disc file to HISTSIZE lines
3505     has always been broken and prone to history file corruption when multiple
3506     shells are accessing the file; the rollover process for the in-memory
3507     portion of the history is slow, should use memmove(3).
3508
3509     This document attempts to describe mksh R59 and up, compiled without any
3510     options impacting functionality, such as MKSH_SMALL, when not called as
3511     /bin/sh which, on some systems only, enables set -o posix or set -o sh
3512     automatically (whose behaviour differs across targets), for an operating
3513     environment supporting all of its advanced needs.
3514
3515     Please report bugs in mksh to the public development mailing list at
3516     <miros-mksh@mirbsd.org> (please note the EU-DSGVO/GDPR notice on
3517     http://www.mirbsd.org/rss.htm#lists and in the SMTP banner!) or in the
3518     #!/bin/mksh (or #ksh) IRC channel at irc.freenode.net (Port 6697 SSL,
3519     6667 unencrypted), or at: https://launchpad.net/mksh
3520
3521MirBSD                          April 14, 2020                          MirBSD
Impressum