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

NAME

4     mksh, sh — MirBSD Korn shell
5

SYNOPSIS

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

DESCRIPTION

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

FILES

2799     ~/.mkshrc            User's startup script (interactive shells).  Used
2800                          only if ENV is unset or empty.
2801     ~/.profile           User's login profile.
2802     /etc/profile         System login profile.
2803     /etc/shells          Shell database.
2804     /etc/suid_profile    Privileged shell profile.
2805

SEEALSO

2807     awk(1), ed(1), getopt(1), sed(1), sh(1), stty(1), dup(2), execve(2),
2808     getgid(2), getuid(2), mknod(2), mkfifo(2), open(2), pipe(2), rename(2),
2809     wait(2), arc4random(3), getopt(3), nl_langinfo(3), rand(3), setlocale(3),
2810     signal(3), srand(3), system(3), tty(4), shells(5), environ(7), script(7),
2811     utf-8(7), mknod(8)
2812
2813     http://docsrv.sco.com:507/en/man/html.C/sh.C.html
2814
2815     MorrisBolsky, The KornShell Command and Programming Language, Prentice
2816     Hall PTR, xvi + 356 pages, 1989, ISBN 978-0-13-516972-8 (0-13-516972-0).
2817
2818     MorrisI.Bolsky and DavidG.Korn, The New KornShell Command and Programming
2819     Language (2nd Edition), Prentice Hall PTR, xvi + 400 pages, 1995, ISBN
2820     978-0-13-182700-4 (0-13-182700-6).
2821
2822     StephenG.Kochan and PatrickH.Wood, UNIX Shell Programming, Hayden,
2823     Revised Edition, xi + 490 pages, 1990, ISBN 978-0-672-48448-3
2824     (0-672-48448-X).
2825
2826     IEEE Inc., IEEE Standard for Information Technology  Portable Operating
2827     System Interface (POSIX), IEEE Press, Part 2: Shell and Utilities,
2828     xvii + 1195 pages, 1993, ISBN 978-1-55937-255-8 (1-55937-255-9).
2829
2830     BillRosenblatt, Learning the Korn Shell, O'Reilly, 360 pages, 1993, ISBN
2831     978-1-56592-054-5 (1-56592-054-6).
2832
2833     BillRosenblatt and ArnoldRobbins, Learning the Korn Shell, Second
2834     Edition, O'Reilly, 432 pages, 2002, ISBN 978-0-596-00195-7
2835     (0-596-00195-9).
2836
2837     BarryRosenberg, KornShell Programming Tutorial, Addison-Wesley
2838     Professional, xxi + 324 pages, 1991, ISBN 978-0-201-56324-5
2839     (0-201-56324-X).
2840

AUTHORS

2842     This shell is based upon the Public Domain Korn SHell.  It has been
2843     developed further by the MirOS project incorporating changes from the
2844     Debian and OpenBSD projects and patches and suggestions from users and
2845     many other persons, and is currently maintained by
2846     ThorstenGlaser<tg@mirbsd.de>.
2847

BUGS

2849     This document attempts to describe mksh R33c and up, compiled without any
2850     options impacting functionality, such as MKSH_SMALL, for an operating
2851     environment supporting all of its advanced needs.  Please report bugs in
2852     mksh to the ⟨miros-discuss@mirbsd.org⟩ mailing list or in the #!/bin/mksh
2853     (or#ksh) IRC channel at irc.freenode.net:6667.
2854
2855MirBSD                           April 1, 2008                          MirBSD
Impressum