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