1 .\" $MirOS: src/bin/mksh/mksh.1,v 1.344 2014/10/07 15:30:12 tg Exp $
2 .\" $OpenBSD: ksh.1,v 1.153 2014/08/17 07:15:41 jmc Exp $
4 .\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
5 .\" 2010, 2011, 2012, 2013, 2014
6 .\" Thorsten Glaser <tg@mirbsd.org>
8 .\" Provided that these terms and disclaimer and all copyright notices
9 .\" are retained or reproduced in an accompanying document, permission
10 .\" is granted to deal in this work without restriction, including un‐
11 .\" limited rights to use, publicly perform, distribute, sell, modify,
12 .\" merge, give away, or sublicence.
14 .\" This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
15 .\" the utmost extent permitted by applicable law, neither express nor
16 .\" implied; without malicious intent or gross negligence. In no event
17 .\" may a licensor, author or contributor be held liable for indirect,
18 .\" direct, other damage, loss, or other issues arising in any way out
19 .\" of dealing in the work, even if advised of the possibility of such
20 .\" damage or existence of a defect, except proven that it results out
21 .\" of said person’s immediate fault when using the work as intended.
23 .\" Try to make GNU groff and AT&T nroff more compatible
24 .\" * ` generates ‘ in gnroff, so use \`
25 .\" * ' generates ’ in gnroff, \' generates ´, so use \*(aq
26 .\" * - generates ‐ in gnroff, \- generates −, so .tr it to -
27 .\" thus use - for hyphens and \- for minus signs and option dashes
28 .\" * ~ is size-reduced and placed atop in groff, so use \*(TI
29 .\" * ^ is size-reduced and placed atop in groff, so use \*(ha
30 .\" * \(en does not work in nroff, so use \*(en
31 .\" * <>| are problematic, so redefine and use \*(Lt\*(Gt\*(Ba
32 .\" Also make sure to use \& especially with two-letter words.
33 .\" The section after the "doc" macropackage has been loaded contains
34 .\" additional code to convene between the UCB mdoc macropackage (and
35 .\" its variant as BSD mdoc in groff) and the GNU mdoc macropackage.
38 . if
\ 1\*[.T]
\ 1ascii
\ 1 .tr \-\N'45'
39 . if
\ 1\*[.T]
\ 1latin1
\ 1 .tr \-\N'45'
40 . if
\ 1\*[.T]
\ 1utf8
\ 1 .tr \-\N'45'
47 . if
\ 1\*[.T]
\ 1utf8
\ 1 .ds sL `
48 . if
\ 1\*[.T]
\ 1ps
\ 1 .ds sL `
49 . if
\ 1\*[.T]
\ 1utf8
\ 1 .ds sR '
50 . if
\ 1\*[.T]
\ 1ps
\ 1 .ds sR '
63 .\" Implement .Dd with the Mdocdate RCS keyword
67 .ie
\a\\$1
\a$Mdocdate:
\a \{\
70 .el .xD \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8
73 .\" .Dd must come before definition of .Mx, because when called
74 .\" with -mandoc, it might implement .Mx itself, but we want to
75 .\" use our own definition. And .Dd must come *first*, always.
77 .Dd $Mdocdate: October 7 2014 $
79 .\" Check which macro package we use, and do other -mdoc setup.
82 . if
\ 1\*[.T]
\ 1utf8
\ 1 .tr \[la]\*(Lt
83 . if
\ 1\*[.T]
\ 1utf8
\ 1 .tr \[ra]\*(Gt
84 . ie d volume-ds-1 .ds tT gnu
89 .\" Implement .Mx (MirBSD)
95 . nr curr-size \n[.ps]
96 . ds str-Mx \f[\n[curr-font]]\s[\n[curr-size]u]
97 . ds str-Mx1 \*[Tn-font-size]\%MirOS\*[str-Mx]
103 . if (\n[arg-limit] > \n[arg-ptr]) \{\
105 . ie (\n[type\n[arg-ptr]] == 2) \
106 . as str-Mx1 \~\*[arg\n[arg-ptr]]
110 . ds arg\n[arg-ptr] "\*[str-Mx1]
111 . nr type\n[arg-ptr] 2
112 . ds space\n[arg-ptr] "\*[space]
113 . nr num-args (\n[arg-limit] - \n[arg-ptr])
114 . nr arg-limit \n[arg-ptr]
121 . ds tN \*[Tn-font-size]
127 . ds aa \&\f\\n(cF\s\\n(cZ
129 . ie \\n(.$==0 \&MirOS\\*(aa
130 . el .aV \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
132 . if \\n(aC>\\n(aP \{\
134 . ie \\n(C\\n(aP==2 \{\
135 . as b1 \&MirOS\ #\&\\*(A\\n(aP\\*(aa
136 . ie \\n(aC>\\n(aP \{\
143 . as b1 \&MirOS\\*(aa
155 .Nd MirBSD Korn shell
159 .Op Fl +abCefhiklmnprUuvXx
161 .Fl T Oo Ar \&! Oc Ns Ar tty
167 .Fl c Ar string \*(Ba
177 is a command interpreter intended for both interactive and shell
179 Its command language is a superset of the
181 shell language and largely compatible to the original Korn shell.
182 .Ss I'm an Android user, so what's mksh?
186 shell / command interpreter, similar to
190 which has been included with
191 .Tn Android Open Source Project
193 Basically, it's a program that runs in a terminal (console window),
194 takes user input and runs commands or scripts, which it can also
195 be asked to do by other programs, even in the background.
196 Any privilege pop-ups you might be encountering are thus not
198 issues but questions by some other program utilising it.
200 Most builtins can be called directly, for example if a link points from its
201 name to the shell; not all make sense, have been tested or work at all though.
203 The options are as follows:
204 .Bl -tag -width XcXstring
207 will execute the command(s) contained in
211 A shell that reads commands from standard input is
214 option is used or if both standard input and standard error are attached
217 An interactive shell has job control enabled, ignores the
222 signals, and prints prompts before reading input (see the
227 It also processes the
232 For non-interactive shells, the
234 option is on by default (see the
239 If the basename the shell is called with (i.e. argv[0])
242 or if this option is used,
243 the shell is assumed to be a login shell; see
250 if the real user ID or group ID does not match the
251 effective user ID or group ID (see
255 Clearing the privileged option causes the shell to set
256 its effective user ID (group ID) to its real user ID (group ID).
257 For further implications, see
259 If the shell is privileged and this flag is not explicitly set, the
261 option is cleared automatically after processing the startup files.
268 The following restrictions come into effect after the shell processes any
285 parameters cannot be changed.
287 Command names can't be specified with absolute or relative paths.
291 option of the built-in command
295 Redirections that create files can't be used (i.e.\&
302 The shell reads commands from standard input; all non-option arguments
303 are positional parameters.
312 .Pa /dev/ttyC Ns Ar name
314 .Pa /dev/tty Ns Ar name
315 are attempted in order.
318 begins with an exclamation mark
320 this is done in a subshell and returns immediately.
325 detach from controlling terminal (daemonise) instead.
328 In addition to the above, the options described in the
330 built-in command can also be used on the command line:
332 .Op Fl +abCefhkmnuvXx
335 can be used for single letter or long options, respectively.
341 option is specified, the first non-option argument specifies the name
342 of a file the shell reads commands from.
343 If there are no non-option
344 arguments, the shell reads commands from the standard input.
345 The name of the shell (i.e. the contents of $0)
346 is determined as follows: if the
348 option is used and there is a non-option argument, it is used as the name;
349 if commands are being read from a file, the file is used as the name;
350 otherwise, the basename the shell was called with (i.e. argv[0]) is used.
352 The exit status of the shell is 127 if the command file specified on the
353 command line could not be opened, or non-zero if a fatal syntax error
354 occurred during the execution of a script.
355 In the absence of fatal errors,
356 the exit status is that of the last command executed, or zero, if no
359 For the actual location of these files, see
361 A login shell processes the system profile first.
362 A privileged shell then processes the suid profile.
363 A non-privileged login shell processes the user profile next.
364 A non-privileged interactive shell checks the value of the
366 parameter after subjecting it to parameter, command, arithmetic and tilde
368 substitution; if unset or empty, the user mkshrc profile is processed;
369 otherwise, if a file whose name is the substitution result exists,
370 it is processed; non-existence is silently ignored.
371 A privileged shell then drops privileges if neither was the
373 option given on the command line nor set during execution of the startup files.
375 The shell begins parsing its input by removing any backslash-newline
376 combinations, then breaking it into
378 Words (which are sequences of characters) are delimited by unquoted whitespace
379 characters (space, tab, and newline) or meta-characters
390 Aside from delimiting words, spaces and tabs are ignored, while newlines
391 usually delimit commands.
392 The meta-characters are used in building the following
397 .Ql \*(Lt\*(Lt\*(Lt ,
402 etc. are used to specify redirections (see
403 .Sx Input/output redirection
406 is used to create pipelines;
408 is used to create co-processes (see
412 is used to separate commands;
414 is used to create asynchronous pipelines;
418 are used to specify conditional execution;
427 is used in arithmetic expressions;
430 is used to create subshells.
432 Whitespace and meta-characters can be quoted individually using a backslash
434 or in groups using double
439 Note that the following characters are also treated specially by the
440 shell and must be quoted if they are to represent themselves:
454 The first three of these are the above mentioned quoting characters (see
458 if used at the beginning of a word, introduces a comment \*(en everything after
461 up to the nearest newline is ignored;
463 is used to introduce parameter, command, and arithmetic substitutions (see
467 introduces an old-style command substitution (see
471 begins a directory expansion (see
487 are used in file name generation (see
488 .Sx File name patterns
491 As words and tokens are parsed, the shell builds commands, of which there
493 .Em simple-commands ,
494 typically programmes that are executed, and
495 .Em compound-commands ,
500 statements, grouping constructs, and function definitions.
502 A simple-command consists of some combination of parameter assignments
506 input/output redirections (see
507 .Sx Input/output redirections
509 and command words; the only restriction is that parameter assignments come
510 before any command words.
511 The command words, if any, define the command
512 that is to be executed and its arguments.
513 The command may be a shell built-in command, a function,
514 or an external command
515 (i.e. a separate executable file that is located using the
518 .Sx Command execution
520 Note that all command constructs have an exit status: for external commands,
521 this is related to the status returned by
523 (if the command could not be found, the exit status is 127; if it could not
524 be executed, the exit status is 126); the exit status of other command
525 constructs (built-in commands, functions, compound-commands, pipelines, lists,
526 etc.) are all well-defined and are described where the construct is
528 The exit status of a command consisting only of parameter
529 assignments is that of the last command substitution performed during the
530 parameter assignment or 0 if there were no command substitutions.
532 Commands can be chained together using the
534 token to form pipelines, in which the standard output of each command but the
537 to the standard input of the following command.
538 The exit status of a pipeline is that of its last command, unless the
540 option is set (see there).
541 All commands of a pipeline are executed in separate subshells;
542 this is allowed by POSIX but differs from both variants of
545 where all but the last command were executed in subshells; see the
547 builtin's description for implications and workarounds.
548 A pipeline may be prefixed by the
550 reserved word which causes the exit status of the pipeline to be logically
551 complemented: if the original status was 0, the complemented status will be 1;
552 if the original status was not 0, the complemented status will be 0.
555 of commands can be created by separating pipelines by any of the following
563 The first two are for conditional execution:
564 .Dq Ar cmd1 No && Ar cmd2
567 only if the exit status of
571 is the opposite \*(en
573 is executed only if the exit status of
579 have equal precedence which is higher than that of
584 which also have equal precedence.
590 .Qq left-associative .
591 For example, both of these commands will print only
593 .Bd -literal -offset indent
594 $ false && echo foo \*(Ba\*(Ba echo bar
595 $ true \*(Ba\*(Ba echo foo && echo bar
600 token causes the preceding command to be executed asynchronously; that is,
601 the shell starts the command but does not wait for it to complete (the shell
602 does keep track of the status of asynchronous commands; see
605 When an asynchronous command is started when job control is disabled
606 (i.e. in most scripts), the command is started with signals
610 ignored and with input redirected from
612 (however, redirections specified in the asynchronous command have precedence).
615 operator starts a co-process which is a special kind of asynchronous process
619 Note that a command must follow the
623 operators, while it need not follow
628 The exit status of a list is that of the last command executed, with the
629 exception of asynchronous lists, for which the exit status is 0.
631 Compound commands are created using the following reserved words.
633 are only recognised if they are unquoted and if they are used as the first
634 word of a command (i.e. they can't be preceded by parameter assignments or
636 .Bd -literal -offset indent
637 case else function then ! (
638 do esac if time [[ ((
640 elif for select while }
643 In the following compound command descriptions, command lists (denoted as
645 that are followed by reserved words must end with a semicolon, a newline, or
646 a (syntactically correct) reserved word.
647 For example, the following are all valid:
648 .Bd -literal -offset indent
649 $ { echo foo; echo bar; }
650 $ { echo foo; echo bar\*(Ltnewline\*(Gt}
651 $ { { echo foo; echo bar; } }
656 .Dl $ { echo foo; echo bar }
662 There is no implicit way to pass environment changes from a
663 subshell back to its parent.
667 is executed, but not in a subshell.
672 are reserved words, not meta-characters.
673 .It Xo case Ar word No in
679 .Op ;; \*(Ba ;&\& \*(Ba ;\*(Ba\ \&
684 statement attempts to match
690 associated with the first successfully matched pattern is executed.
693 statements are the same as those used for file name patterns except that the
694 restrictions regarding
699 Note that any unquoted space before and after a pattern is
700 stripped; any space within a pattern must be quoted.
701 Both the word and the
702 patterns are subject to parameter, command, and arithmetic substitution, as
703 well as tilde substitution.
705 For historical reasons, open and close braces may be used instead of
710 .Ic case $foo { *) echo bar;; } .
712 The list terminators are:
715 Terminate after the list.
717 Fall through into the next list.
719 Evaluate the remaining pattern-list tuples.
724 statement is that of the executed
728 is executed, the exit status is zero.
730 .Oo in Ar word No ... Oc ;
731 .No do Ar list ; No done
735 in the specified word list, the parameter
737 is set to the word and
742 is not used to specify a word list, the positional parameters
745 For historical reasons, open and close braces may be used instead of
750 .Ic for i; { echo $i; } .
753 statement is the last exit status of
757 is never executed, the exit status is zero.
761 .No then Ar list ; Oc
763 .Oo else Ar list ; Oc
766 If the exit status of the first
770 is executed; otherwise, the
774 if any, is executed with similar consequences.
775 If all the lists following the
779 fail (i.e. exit with non-zero status), the
784 The exit status of an
786 statement is that of non-conditional
788 that is executed; if no non-conditional
790 is executed, the exit status is zero.
791 .It Xo select Ar name
792 .Oo in Ar word No ... Oc ;
793 .No do Ar list ; No done
797 statement provides an automatic method of presenting the user with a menu and
799 An enumerated list of the specified
801 is printed on standard error, followed by a prompt
806 A number corresponding to one of the enumerated words is then read from
809 is set to the selected word (or unset if the selection is not valid),
811 is set to what was read (leading/trailing space is stripped), and
814 If a blank line (i.e. zero or more
816 octets) is entered, the menu is reprinted without executing
821 completes, the enumerated list is printed if
825 the prompt is printed, and so on.
826 This process continues until an end-of-file
827 is read, an interrupt is received, or a
829 statement is executed inside the loop.
832 is omitted, the positional parameters are used
834 For historical reasons, open and close braces may be used instead of
839 .Ic select i; { echo $i; } .
842 statement is zero if a
844 statement is used to exit the loop, non-zero otherwise.
845 .It Xo until Ar list ;
851 except that the body is executed only while the exit status of the first
854 .It Xo while Ar list ;
860 is a pre-checked loop.
861 Its body is executed as often as the exit status of the first
866 statement is the last exit status of the
868 in the body of the loop; if the body is not executed, the exit status is zero.
869 .It Xo function Ar name
877 Note that redirections specified after a function definition are
878 performed whenever the function is executed, not when the function definition
880 .It Ar name Ns \&() Ar command
886 Whitespace (space or tab) after
888 will be ignored most of the time.
889 .It Xo function Ar name Ns \&()
898 .It Xo Ic time Op Fl p
902 .Sx Command execution
903 section describes the
906 .It \&(( Ar expression No ))
907 The arithmetic expression
909 is evaluated; equivalent to
912 .Sx Arithmetic expressions
916 .It Bq Bq Ar \ \&expression\ \&
921 commands (described later), with the following exceptions:
924 Field splitting and file name generation are not performed on arguments.
932 operators are replaced with
944 Parameter, command, and arithmetic substitutions are performed as expressions
945 are evaluated and lazy expression evaluation is used for the
950 This means that in the following statement,
952 is evaluated if and only if the file
954 exists and is readable:
955 .Bd -literal -offset indent
956 $ [[ \-r foo && $(\*(Ltfoo) = b*r ]]
959 The second operand of the
963 expressions are a subset of patterns (e.g. the comparison
964 .Ic \&[[ foobar = f*r ]]
966 This even works indirectly:
967 .Bd -literal -offset indent
968 $ bar=foobar; baz=\*(aqf*r\*(aq
969 $ [[ $bar = $baz ]]; echo $?
970 $ [[ $bar = \&"$baz" ]]; echo $?
973 Perhaps surprisingly, the first comparison succeeds,
974 whereas the second doesn't.
975 This does not apply to all extglob metacharacters, currently.
979 Quoting is used to prevent the shell from treating characters or words
981 There are three methods of quoting.
984 quotes the following character, unless it is at the end of a line, in which
987 and the newline are stripped.
988 Second, a single quote
990 quotes everything up to the next single quote (this may span lines).
991 Third, a double quote
993 quotes all characters, except
998 up to the next unquoted double quote.
1002 inside double quotes have their usual meaning (i.e. parameter, command, or
1003 arithmetic substitution) except no field splitting is carried out on the
1004 results of double-quoted substitutions.
1007 inside a double-quoted string is followed by
1013 it is replaced by the second character; if it is followed by a newline, both
1016 and the newline are stripped; otherwise, both the
1018 and the character following are unchanged.
1020 If a single-quoted string is preceded by an unquoted
1022 C style backslash expansion (see below) is applied (even single quote
1023 characters inside can be escaped and do not terminate the string then);
1024 the expanded result is treated as any other single-quoted string.
1025 If a double-quoted string is preceded by an unquoted
1027 the latter is ignored.
1028 .Ss Backslash expansion
1029 In places where backslashes are expanded, certain C and
1034 style escapes are translated.
1051 means a hexadecimal digit, of thich there may be none up to four or eight;
1052 these escapes translate a Unicode codepoint to UTF-8.
1057 expand to the escape character.
1066 are explicitly excluded;
1067 octal sequences must have the none up to three octal digits
1069 prefixed with the digit zero
1071 hexadecimal sequences
1073 are limited to none up to two hexadecimal digits
1075 both octal and hexadecimal sequences convert to raw octets;
1077 where # is none of the above, translates to \e# (backslashes are retained).
1079 Backslash expansion in the C style mode slightly differs: octal sequences
1081 must have no digit zero prefixing the one up to three octal digits
1083 and yield raw octets; hexadecimal sequences
1085 greedily eat up as many hexadecimal digits
1087 as they can and terminate with the first non-hexadecimal digit;
1088 these translate a Unicode codepoint to UTF-8.
1093 is any octet, translates to Ctrl-# (which basically means,
1095 becomes DEL, everything else is bitwise ANDed with 0x1F).
1098 where # is none of the above, translates to # (has the backslash trimmed),
1099 even if it is a newline.
1101 There are two types of aliases: normal command aliases and tracked aliases.
1102 Command aliases are normally used as a short hand for a long or often used
1104 The shell expands command aliases (i.e. substitutes the alias name
1105 for its value) when it reads the first word of a command.
1106 An expanded alias is re-processed to check for more aliases.
1107 If a command alias ends in a
1108 space or tab, the following word is also checked for alias expansion.
1109 The alias expansion process stops when a word that is not an alias is found,
1110 when a quoted word is found, or when an alias word that is currently being
1112 Aliases are specifically an interactive feature: while they do happen
1113 to work in scripts and on the command line in some cases, aliases are
1114 expanded during lexing, so their use must be in a separate command tree
1115 from their definition; otherwise, the alias will not be found.
1116 Noticeably, command lists (separated by semicolon, in command substitutions
1117 also by newline) may be one same parse tree.
1119 The following command aliases are defined automatically by the shell:
1120 .Bd -literal -offset indent
1121 autoload=\*(aqtypeset \-fu\*(aq
1122 functions=\*(aqtypeset \-f\*(aq
1123 hash=\*(aqalias \-t\*(aq
1124 history=\*(aqfc \-l\*(aq
1125 integer=\*(aqtypeset \-i\*(aq
1126 local=\*(aqtypeset\*(aq
1127 login=\*(aqexec login\*(aq
1128 nameref=\*(aqtypeset \-n\*(aq
1129 nohup=\*(aqnohup \*(aq
1130 r=\*(aqfc \-e \-\*(aq
1131 stop=\*(aqkill \-STOP\*(aq
1132 type=\*(aqwhence \-v\*(aq
1135 Tracked aliases allow the shell to remember where it found a particular
1137 The first time the shell does a path search for a command that is
1138 marked as a tracked alias, it saves the full path of the command.
1140 time the command is executed, the shell checks the saved path to see that it
1141 is still valid, and if so, avoids repeating the path search.
1142 Tracked aliases can be listed and created using
1144 Note that changing the
1146 parameter clears the saved paths for all tracked aliases.
1149 option is set (i.e.\&
1150 .Ic set \-o Ic trackall
1153 the shell tracks all commands.
1154 This option is set automatically for non-interactive shells.
1155 For interactive shells, only the following commands are
1156 automatically tracked:
1176 The first step the shell takes in executing a simple-command is to perform
1177 substitutions on the words of the command.
1178 There are three kinds of
1179 substitution: parameter, command, and arithmetic.
1180 Parameter substitutions,
1181 which are described in detail in the next section, take the form
1184 .Pf ${ Ns Ar ... Ns } ;
1185 command substitutions take the form
1186 .Pf $( Ns Ar command Ns \&)
1188 .Pf \` Ns Ar command Ns \`
1189 or (executed in the current environment)
1190 .Pf ${\ \& Ar command Ns \&;}
1191 and strip trailing newlines;
1192 and arithmetic substitutions take the form
1193 .Pf $(( Ns Ar expression Ns )) .
1194 Parsing the current-environment command substitution requires a space,
1195 tab or newline after the opening brace and that the closing brace be
1196 recognised as a keyword (i.e. is preceded by a newline or semicolon).
1197 They are also called funsubs (function substitutions) and behave like
1204 terminates the parent shell.
1206 Another variant of substitution are the valsubs (value substitutions)
1207 .Pf ${\*(Ba\& Ns Ar command Ns \&;}
1208 which are also executed in the current environment, like funsubs, but
1209 share their I/O with the parent; instead, they evaluate to whatever
1210 the, initially empty, expression-local variable
1212 is set to within the
1213 .Ar command Ns No s .
1215 If a substitution appears outside of double quotes, the results of the
1216 substitution are generally subject to word or field splitting according to
1217 the current value of the
1222 parameter specifies a list of octets which are used to break a string up
1223 into several words; any octets from the set space, tab, and newline that
1227 .Dq IFS whitespace .
1228 Sequences of one or more
1230 whitespace octets, in combination with zero or one
1232 whitespace octets, delimit a field.
1233 As a special case, leading and trailing
1235 whitespace is stripped (i.e. no leading or trailing empty field
1236 is created by it); leading or trailing
1238 whitespace does create an empty field.
1243 .Dq \*(Ltspace\*(Gt: ,
1245 .Dq \*(Ltspace\*(GtA\*(Ltspace\*(Gt:\*(Ltspace\*(Gt\*(Ltspace\*(GtB::D ,
1246 the substitution for $VAR results in four fields:
1255 parameter is set to the
1257 string, no field splitting is done; if the parameter is unset, the default
1258 value of space, tab, and newline is used.
1260 Also, note that the field splitting applies only to the immediate result of
1262 Using the previous example, the substitution for $VAR:E
1263 results in the fields:
1276 This behavior is POSIX compliant, but incompatible with some other shell
1277 implementations which do field splitting on the word which contained the
1280 as a general whitespace delimiter.
1282 The results of substitution are, unless otherwise specified, also subject to
1283 brace expansion and file name expansion (see the relevant sections below).
1285 A command substitution is replaced by the output generated by the specified
1286 command which is run in a subshell.
1288 .Pf $( Ns Ar command Ns \&)
1290 .Pf ${\ \& Ar command Ns \&;}
1291 substitutions, normal quoting rules are used when
1293 is parsed; however, for the deprecated
1294 .Pf \` Ns Ar command Ns \`
1304 followed by any other character is unchanged).
1305 As a special case in command substitutions, a command of the form
1307 is interpreted to mean substitute the contents of
1311 has the same effect as
1314 Note that some shells do not use a recursive parser for command substitutions,
1315 leading to failure for certain constructs; to be portable, use as workaround
1316 .Ql x=$(cat) \*(Lt\*(Lt"EOF"
1317 (or the newline-keeping
1318 .Ql x=\*(Lt\*(Lt"EOF"
1319 extension) instead to merely slurp the string.
1321 recommends to use case statements of the form
1322 .Ql "x=$(case $foo in (bar) echo $bar ;; (*) echo $baz ;; esac)"
1323 instead, which would work but not serve as example for this portability issue.
1324 .Bd -literal -offset indent
1325 x=$(case $foo in bar) echo $bar ;; *) echo $baz ;; esac)
1326 # above fails to parse on old shells; below is the workaround
1327 x=$(eval $(cat)) \*(Lt\*(Lt"EOF"
1328 case $foo in bar) echo $bar ;; *) echo $baz ;; esac
1332 Arithmetic substitutions are replaced by the value of the specified expression.
1333 For example, the command
1334 .Ic print $((2+3*4))
1337 .Sx Arithmetic expressions
1338 for a description of an expression.
1340 Parameters are shell variables; they can be assigned values and their values
1341 can be accessed using a parameter substitution.
1342 A parameter name is either one
1343 of the special single punctuation or digit character parameters described
1344 below, or a letter followed by zero or more letters or digits
1349 The latter form can be treated as arrays by appending an array index of the
1354 is an arithmetic expression.
1357 are limited to the range 0 through 4294967295, inclusive.
1358 That is, they are a 32-bit unsigned integer.
1360 Parameter substitutions take the form
1362 .Pf ${ Ns Ar name Ns } ,
1365 .Pf ${ Ar name Oo Ar expr Oc }
1369 is a parameter name.
1370 Substitution of all array elements with
1371 .Pf ${ Ns Ar name Ns \&[*]}
1373 .Pf ${ Ns Ar name Ns \&[@]}
1374 works equivalent to $* and $@ for positional parameters.
1375 If substitution is performed on a parameter
1376 (or an array parameter element)
1377 that is not set, a null string is substituted unless the
1381 .Ic set Fl o Ic nounset
1385 is set, in which case an error occurs.
1387 Parameters can be assigned values in a number of ways.
1388 First, the shell implicitly sets some parameters like
1393 this is the only way the special single character parameters are set.
1394 Second, parameters are imported from the shell's environment at startup.
1395 Third, parameters can be assigned values on the command line: for example,
1401 multiple parameter assignments can be given on a single command line and they
1402 can be followed by a simple-command, in which case the assignments are in
1403 effect only for the duration of the command (such assignments are also
1404 exported; see below for the implications of this).
1405 Note that both the parameter name and the
1407 must be unquoted for the shell to recognise a parameter assignment.
1410 is also recognised; the old and new values are immediately concatenated.
1411 The fourth way of setting a parameter is with the
1417 commands; see their descriptions in the
1418 .Sx Command execution
1424 loops set parameters as well as the
1430 Lastly, parameters can be assigned values using assignment operators
1431 inside arithmetic expressions (see
1432 .Sx Arithmetic expressions
1435 .Pf ${ Ar name No = Ar value No }
1437 form of the parameter substitution (see below).
1439 Parameters with the export attribute (set using the
1443 commands, or by parameter assignments followed by simple commands) are put in
1444 the environment (see
1446 of commands run by the shell as
1447 .Ar name Ns = Ns Ar value
1449 The order in which parameters appear in the environment of a command is
1451 When the shell starts up, it extracts parameters and their values
1452 from its environment and automatically sets the export attribute for those
1455 Modifiers can be applied to the
1456 .Pf ${ Ns Ar name Ns }
1457 form of parameter substitution:
1460 .It ${ Ar name No :\- Ar word No }
1466 it is substituted; otherwise,
1470 .It ${ Ar name No :+ Ar word No }
1477 is substituted; otherwise, nothing is substituted.
1479 .It ${ Ar name No := Ar word No }
1485 it is substituted; otherwise, it is assigned
1487 and the resulting value of
1491 .It ${ Ar name No :? Ar word No }
1497 it is substituted; otherwise,
1499 is printed on standard error (preceded by
1501 and an error occurs (normally causing termination of a shell script, function,
1502 or script sourced using the
1507 is omitted, the string
1508 .Dq parameter null or not set
1512 is a variable which expands to the null string, the
1513 error message is also printed.
1516 Note that, for all of the above,
1518 is actually considered quoted, and special parsing rules apply.
1519 The parsing rules also differ on whether the expression is double-quoted:
1521 then uses double-quoting rules, except for the double quote itself
1523 and the closing brace, which, if backslash escaped, gets quote removal applied.
1525 In the above modifiers, the
1527 can be omitted, in which case the conditions only depend on
1529 being set (as opposed to set and not
1533 is needed, parameter, command, arithmetic, and tilde substitution are performed
1536 is not needed, it is not evaluated.
1538 The following forms of parameter substitution can also be used (if
1540 is an array, its element #0 will be substituted in a scalar context):
1542 .Bl -tag -width Ds -compact
1543 .It Pf ${# Ns Ar name Ns \&}
1544 The number of positional parameters if
1549 or not specified; otherwise the length
1551 of the string value of parameter
1554 .It Pf ${# Ns Ar name Ns \&[*]}
1555 .It Pf ${# Ns Ar name Ns \&[@]}
1556 The number of elements in the array
1559 .It Pf ${% Ns Ar name Ns \&}
1561 .Pq in screen columns
1562 of the string value of parameter
1565 .Pf ${ Ns Ar name Ns }
1566 contains a control character.
1568 .It Pf ${! Ns Ar name Ns }
1569 The name of the variable referred to by
1575 is a name reference (bound variable), created by the
1577 command (which is an alias for
1578 .Ic typeset Fl n ) .
1580 .It Pf ${! Ns Ar name Ns \&[*]}
1581 .It Pf ${! Ns Ar name Ns \&[@]}
1582 The names of indices (keys) in the array
1588 .Pf # Ar pattern No }
1592 .Pf ## Ar pattern No }
1597 matches the beginning of the value of parameter
1599 the matched text is deleted from the result of substitution.
1602 results in the shortest match, and two
1603 of them result in the longest match.
1604 Cannot be applied to a vector
1605 .Pq ${*} or ${@} or ${array[*]} or ${array[@]} .
1610 .Pf % Ar pattern No }
1614 .Pf %% Ar pattern No }
1617 Like ${..#..} substitution, but it deletes from the end of the value.
1618 Cannot be applied to a vector.
1623 .Pf / Ar pattern / Ar string No }
1627 .Pf // Ar pattern / Ar string No }
1630 Like ${..#..} substitution, but it replaces the longest match of
1632 anchored anywhere in the value, with
1638 it is anchored at the beginning of the value; if it begins with
1640 it is anchored at the end.
1641 Patterns that are empty or consist only of wildcards are invalid.
1644 replaces the first occurence of the search
1646 and two of them replace all occurences.
1651 is replaced by the empty string, i.e. deleted.
1652 Cannot be applied to a vector.
1653 Inefficiently implemented, may be slow.
1657 .Pf ${ Ar name : Ns Ar pos
1658 .Pf : Ns Ar len Ns }
1665 starting at position
1675 is negative, counting starts at the end of the string; if it
1676 is omitted, it defaults to 0.
1679 is omitted or greater than the length of the remaining string,
1680 all of it is substituted.
1685 are evaluated as arithmetic expressions.
1688 must start with a space, opening parenthesis or digit to be recognised.
1689 Cannot be applied to a vector.
1691 .It Pf ${ Ns Ar name Ns @#}
1692 The hash (using the BAFH algorithm) of the expansion of
1694 This is also used internally for the shell's hashtables.
1696 .It Pf ${ Ns Ar name Ns @Q}
1697 A quoted expression safe for re-entry, whose value is the value of the
1699 parameter, is substituted.
1704 may need extended globbing pattern
1707 .Pq \&\*(aq...\&\*(aq
1710 quote escaping unless
1714 The following special parameters are implicitly set by the shell and cannot be
1715 set directly using assignments:
1716 .Bl -tag -width "1 .. 9"
1718 Process ID of the last background process started.
1719 If no background processes have been started, the parameter is not set.
1721 The number of positional parameters ($1, $2, etc.).
1723 The PID of the shell, or the PID of the original shell if it is a subshell.
1726 use this mechanism for generating temporary file names; see
1730 The concatenation of the current single letter options (see the
1732 command below for a list of options).
1734 The exit status of the last non-asynchronous command executed.
1735 If the last command was killed by a signal,
1737 is set to 128 plus the signal number.
1739 The name of the shell, determined as follows:
1740 the first argument to
1742 if it was invoked with the
1744 option and arguments were given; otherwise the
1746 argument, if it was supplied;
1747 or else the basename the shell was invoked with (i.e.\&
1750 is also set to the name of the current script or
1751 the name of the current function, if it was defined with the
1753 keyword (i.e. a Korn shell style function).
1755 The first nine positional parameters that were supplied to the shell, function,
1756 or script sourced using the
1759 Further positional parameters may be accessed using
1760 .Pf ${ Ar number Ns } .
1762 All positional parameters (except 0), i.e. $1, $2, $3, ...
1765 outside of double quotes, parameters are separate words (which are subjected
1766 to word splitting); if used within double quotes, parameters are separated
1767 by the first character of the
1769 parameter (or the empty string if
1776 unless it is used inside double quotes, in which case a separate word is
1777 generated for each positional parameter.
1778 If there are no positional parameters, no word is generated.
1780 can be used to access arguments, verbatim, without losing
1782 arguments or splitting arguments with spaces.
1785 The following parameters are set and/or used by the shell:
1786 .Bl -tag -width "KSH_VERSION"
1789 When an external command is executed by the shell, this parameter is set in the
1790 environment of the new process to the path of the executed command.
1791 In interactive use, this parameter is also set in the parent shell to the last
1792 word of the previous command.
1794 The PID of the shell or subshell.
1799 It works the same way as
1801 for those directories not beginning with
1808 is set and does not contain
1810 or contains an empty path, the current directory is not searched.
1813 built-in command will display the resulting directory when a match is found
1814 in any search path other than the empty path.
1816 Set to the number of columns on the terminal or window.
1817 Always set, defaults to 80, unless the
1818 value as reported by
1820 is non-zero and sane enough (minimum is 12x3); similar for
1822 This parameter is used by the interactive line editing modes, and by the
1827 commands to format information columns.
1828 Importing from the environment or unsetting this parameter removes the
1829 binding to the actual terminal size in favour of the provided value.
1831 If this parameter is found to be set after any profile files are executed, the
1832 expanded value is used as a shell startup file.
1833 It typically contains function and alias definitions.
1835 Integer value of the shell's
1838 It indicates the reason the last system call failed.
1839 Not yet implemented.
1841 If set, this parameter is assumed to contain the shell that is to be used to
1842 execute commands that
1844 fails to execute and which do not start with a
1848 The editor used by the
1850 command (see below).
1854 but used when an undefined function is executed to locate the file defining the
1856 It is also searched when a command can't be found using
1860 below for more information.
1862 The name of the file used to store command history.
1863 When assigned to, history is loaded from the specified file.
1864 Also, several invocations of the shell will share history if their
1866 parameters all point to the same file.
1871 isn't set, no history file is used.
1872 This is different from
1876 The number of commands normally stored for history.
1877 The default is 2047.
1878 Do not set this value to insanely high values such as 1000000000 because
1880 can then not allocate enough memory for the history and will not start.
1882 The default directory for the
1884 command and the value substituted for an unqualified
1890 Internal field separator, used during substitution and by the
1892 command, to split values into distinct arguments; normally set to space, tab,
1899 This parameter is not imported from the environment when the shell is
1902 The effective group id of the shell.
1904 The real group id of the shell.
1906 The real user id of the shell.
1908 The name and version of the shell (read-only).
1909 See also the version commands in
1910 .Sx Emacs editing mode
1915 The line number of the function or shell script that is currently being
1918 Set to the number of lines on the terminal or window.
1919 Always set, defaults to 24.
1922 .It Ev EPOCHREALTIME
1923 Time since the epoch, as returned by
1924 .Xr gettimeofday 2 ,
1925 formatted as decimal
1931 padded to exactly six decimal digits.
1933 The previous working directory.
1936 has not successfully changed directories since the shell started, or if the
1937 shell doesn't know where it is.
1941 it contains the argument for a parsed option, if it requires one.
1943 The index of the next argument to be processed when using
1945 Assigning 1 to this parameter causes
1947 to process arguments from the beginning the next time it is invoked.
1949 A colon separated list of directories that are searched when looking for
1950 commands and files sourced using the
1952 command (see below).
1953 An empty string resulting from a leading or trailing
1954 colon, or two adjacent colons, is treated as a
1956 (the current directory).
1958 The process ID of the shell's process group leader.
1960 An array containing the errorlevel (exit status) codes,
1961 one by one, of the last pipeline run in the foreground.
1963 The process ID of the shell's parent.
1965 The primary prompt for interactive shells.
1966 Parameter, command, and arithmetic
1967 substitutions are performed, and
1969 is replaced with the current command number (see the
1974 can be put in the prompt by placing
1979 The default prompt is
1986 is invoked by root and
1990 character, the default value will be used even if
1992 already exists in the environment.
1996 distribution comes with a sample
1998 containing a sophisticated example, but you might like the following one
1999 (note that ${HOSTNAME:=$(hostname)} and the
2000 root-vs-user distinguishing clause are (in this example) executed at
2002 assignment time, while the $USER and $PWD are escaped
2003 and thus will be evaluated each time a prompt is displayed):
2005 PS1=\*(aq${USER:=$(id \-un)}\*(aq"@${HOSTNAME:=$(hostname)}:\e$PWD $(
2006 if (( USER_ID )); then print \e$; else print \e#; fi) "
2009 Note that since the command-line editors try to figure out how long the prompt
2010 is (so they know how far it is to the edge of the screen), escape codes in
2011 the prompt tend to mess things up.
2012 You can tell the shell not to count certain
2013 sequences (such as escape codes) by prefixing your prompt with a
2014 character (such as Ctrl-A) followed by a carriage return and then delimiting
2015 the escape codes with this character.
2016 Any occurences of that character in the prompt are not printed.
2017 By the way, don't blame me for
2018 this hack; it's derived from the original
2020 which did print the delimiter character so you were out of luck
2021 if you did not have any non-printing characters.
2023 Since Backslashes and other special characters may be
2024 interpreted by the shell, to set
2026 either escape the backslash itself,
2027 or use double quotes.
2028 The latter is more practical.
2029 This is a more complex example,
2030 avoiding to directly enter special characters (for example with
2032 in the emacs editing mode),
2033 which embeds the current working directory,
2035 .Pq colour would work, too ,
2036 in the prompt string:
2037 .Bd -literal -offset indent
2039 PS1="$x$(print \e\er)$x$(tput so)$x\e$PWD$x$(tput se)$x\*(Gt "
2042 Due to a strong suggestion from David G. Korn,
2044 now also supports the following form:
2045 .Bd -literal -offset indent
2046 PS1=$'\e1\er\e1\ee[7m\e1$PWD\e1\ee[0m\e1\*(Gt '
2049 Secondary prompt string, by default
2051 used when more input is needed to complete a command.
2055 statement when reading a menu selection.
2059 Used to prefix commands that are printed during execution tracing (see the
2062 Parameter, command, and arithmetic substitutions are performed
2063 before it is printed.
2066 You may want to set it to
2067 .Sq \&[$EPOCHREALTIME]\ \&
2068 instead, to include timestamps.
2070 The current working directory.
2073 if the shell doesn't know where it is.
2077 is referenced, it is assigned a number between 0 and 32767 from
2078 a Linear Congruential PRNG first.
2080 Default parameter for the
2082 command if no names are given.
2085 loops to store the value that is read from standard input.
2087 The number of seconds since the shell started or, if the parameter has been
2088 assigned an integer value, the number of seconds since the assignment plus the
2089 value that was assigned.
2091 If set to a positive integer in an interactive shell, it specifies the maximum
2092 number of seconds the shell will wait for input after printing the primary
2095 If the time is exceeded, the shell exits.
2097 The directory temporary shell files are created in.
2098 If this parameter is not
2099 set, or does not contain the absolute path of a writable directory, temporary
2100 files are created in
2103 The effective user id of the shell.
2106 Tilde expansion which is done in parallel with parameter substitution, is done
2107 on words starting with an unquoted
2109 The characters following the tilde, up to the first
2111 if any, are assumed to be a login name.
2112 If the login name is empty,
2121 parameter is substituted, respectively.
2122 Otherwise, the password file is
2123 searched for the login name, and the tilde expression is substituted with the
2124 user's home directory.
2125 If the login name is not found in the password file or
2126 if any quoting or parameter substitution occurs in the login name, no
2127 substitution is performed.
2129 In parameter assignments
2130 (such as those preceding a simple-command or those occurring
2138 tilde expansion is done after any assignment
2139 (i.e. after the equals sign)
2140 or after an unquoted colon
2142 login names are also delimited by colons.
2144 The home directory of previously expanded login names are cached and re-used.
2147 command may be used to list, change, and add to this cache (e.g.\&
2148 .Ic alias \-d fac=/usr/local/facilities; cd \*(TIfac/bin ) .
2149 .Ss Brace expansion (alteration)
2150 Brace expressions take the following form:
2151 .Bd -unfilled -offset indent
2154 .Ar prefix No { Ar str1 No ,...,
2155 .Ar strN No } Ar suffix
2160 The expressions are expanded to
2162 words, each of which is the concatenation of
2169 expands to four words:
2175 As noted in the example, brace expressions can be nested and the resulting
2176 words are not sorted.
2177 Brace expressions must contain an unquoted comma
2179 for expansion to occur (e.g.\&
2184 Brace expansion is carried out after parameter substitution
2185 and before file name generation.
2186 .Ss File name patterns
2187 A file name pattern is a word containing one or more unquoted
2197 Once brace expansion has been performed, the shell replaces file
2198 name patterns with the sorted names of all the files that match the pattern
2199 (if no files match, the word is left unchanged).
2200 The pattern elements have the following meaning:
2203 Matches any single character.
2205 Matches any sequence of octets.
2207 Matches any of the octets inside the brackets.
2208 Ranges of octets can be specified by separating two octets by a
2215 In order to represent itself, a
2217 must either be quoted or the first or last octet in the octet list.
2220 must be quoted or the first octet in the list if it is to represent itself
2221 instead of the end of the list.
2224 appearing at the start of the list has special meaning (see below), so to
2225 represent itself it must be quoted or appear later in the list.
2228 except it matches any octet not inside the brackets.
2230 .It *( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
2232 Matches any string of octets that matches zero or more occurrences of the
2234 Example: The pattern
2243 .It +( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
2245 Matches any string of octets that matches one or more occurrences of the
2247 Example: The pattern
2255 .It ?( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
2257 Matches the empty string or a string that matches one of the specified
2259 Example: The pattern
2261 only matches the strings
2267 .It @( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
2269 Matches a string that matches one of the specified patterns.
2270 Example: The pattern
2272 only matches the strings
2277 .It !( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
2279 Matches any string that does not match one of the specified patterns.
2280 Examples: The pattern
2282 matches all strings except
2288 matches no strings; the pattern
2290 matches all strings (think about it).
2293 Note that complicated globbing, especially with alternatives,
2294 is slow; using separate comparisons may (or may not) be faster.
2312 Note that none of the above pattern elements match either a period
2314 at the start of a file name or a slash
2316 even if they are explicitly used in a [..] sequence; also, the names
2320 are never matched, even by the pattern
2325 option is set, any directories that result from file name generation are marked
2328 .Ss Input/output redirection
2329 When a command is executed, its standard input, standard output, and standard
2330 error (file descriptors 0, 1, and 2, respectively) are normally inherited from
2332 Three exceptions to this are commands in pipelines, for which
2333 standard input and/or standard output are those set up by the pipeline,
2334 asynchronous commands created when job control is disabled, for which standard
2335 input is initially set to be from
2337 and commands for which any of the following redirections have been specified:
2338 .Bl -tag -width XXxxmarker
2340 Standard output is redirected to
2344 does not exist, it is created; if it does exist, is a regular file, and the
2346 option is set, an error occurs; otherwise, the file is truncated.
2347 Note that this means the command
2348 .Ic cmd \*(Ltfoo \*(Gtfoo
2351 for reading and then truncate it when it opens it for writing, before
2353 gets a chance to actually read
2355 .It \*(Gt\*(Ba Ar file
2358 except the file is truncated, even if the
2361 .It \*(Gt\*(Gt Ar file
2366 exists it is appended to instead of being truncated.
2367 Also, the file is opened
2368 in append mode, so writes always go to the end of the file (see
2371 Standard input is redirected from
2373 which is opened for reading.
2374 .It \*(Lt\*(Gt Ar file
2377 except the file is opened for reading and writing.
2378 .It \*(Lt\*(Lt Ar marker
2379 After reading the command line containing this kind of redirection (called a
2380 .Dq here document ) ,
2381 the shell copies lines from the command source into a temporary file until a
2385 When the command is executed, standard input is redirected from the
2389 contains no quoted characters, the contents of the temporary file are processed
2390 as if enclosed in double quotes each time the command is executed, so
2391 parameter, command, and arithmetic substitutions are performed, along with
2402 If multiple here documents are used on the same command line, they are saved in
2407 is given, the here document ends at the next
2409 and substitution will be performed.
2412 is only a set of either single
2416 quotes with nothing in between, the here document ends at the next empty line
2417 and substitution will not be performed.
2418 .It \*(Lt\*(Lt\- Ar marker
2421 except leading tabs are stripped from lines in the here document.
2422 .It \*(Lt\*(Lt\*(Lt Ar word
2429 This is called a here string.
2431 Standard input is duplicated from file descriptor
2434 can be a number, indicating the number of an existing file descriptor;
2437 indicating the file descriptor associated with the output of the current
2438 co-process; or the character
2440 indicating standard input is to be closed.
2443 is limited to a single digit in most shell implementations.
2447 except the operation is done on standard output.
2450 .Ic \*(Gt Ar file 2\*(Gt&1 .
2453 extension supported by
2455 which also supports the preceding explicit fd number, for example,
2458 .Ic 3\*(Gt Ar file 2\*(Gt&3
2461 but a syntax error in GNU
2467 shell options disable parsing of this redirection;
2468 it's a compatibility feature to legacy scripts, to
2469 not be used when writing new shell code.
2471 .No &\*(Gt\*(Ba Ar file ,
2472 .No &\*(Gt\*(Gt Ar file ,
2476 .Ic \*(Gt\*(Ba Ar file ,
2477 .Ic \*(Gt\*(Gt Ar file ,
2488 In any of the above redirections, the file descriptor that is redirected
2489 (i.e. standard input or standard output)
2490 can be explicitly given by preceding the
2491 redirection with a number (portably, only a single digit).
2492 Parameter, command, and arithmetic
2493 substitutions, tilde substitutions, and (if the shell is interactive)
2494 file name generation are all performed on the
2499 arguments of redirections.
2500 Note, however, that the results of any file name
2501 generation are only used if a single file is matched; if multiple files match,
2502 the word with the expanded file name generation characters is used.
2504 that in restricted shells, redirections which can create files cannot be used.
2506 For simple-commands, redirections may appear anywhere in the command; for
2512 any redirections must appear at the end.
2513 Redirections are processed after
2514 pipelines are created and in the order they are given, so the following
2515 will print an error with a line number prepended to it:
2517 .D1 $ cat /foo/bar 2\*(Gt&1 \*(Gt/dev/null \*(Ba pr \-n \-t
2519 File descriptors created by input/output redirections are private to the
2520 Korn shell, but passed to sub-processes if
2525 .Ss Arithmetic expressions
2526 Integer arithmetic expressions can be used with the
2528 command, inside $((..)) expressions, inside array references (e.g.\&
2529 .Ar name Ns Bq Ar expr ) ,
2530 as numeric arguments to the
2532 command, and as the value of an assignment to an integer parameter.
2534 This also affects implicit conversion to integer, for example as done by the
2538 use unchecked user input, e.g. from the environment, in arithmetics!
2540 Expressions are calculated using signed arithmetic and the
2542 type (a 32-bit signed integer), unless they begin with a sole
2544 character, in which case they use
2546 .Po a 32-bit unsigned integer Pc .
2548 Expressions may contain alpha-numeric parameter identifiers, array references,
2549 and integer constants and may be combined with the following C operators
2550 (listed and grouped in increasing order of precedence):
2553 .Bd -literal -offset indent
2554 + \- ! \*(TI ++ \-\-
2558 .Bd -literal -offset indent
2560 = += \-= *= /= %= \*(Lt\*(Lt\*(Lt= \*(Gt\*(Gt\*(Gt= \*(Lt\*(Lt= \*(Gt\*(Gt= &= \*(ha= \*(Ba=
2567 \*(Lt \*(Lt= \*(Gt \*(Gt=
2568 \*(Lt\*(Lt\*(Lt \*(Gt\*(Gt\*(Gt \*(Lt\*(Lt \*(Gt\*(Gt
2574 .Bd -literal -offset indent
2575 ?: (precedence is immediately higher than assignment)
2579 .Bd -literal -offset indent
2583 Integer constants and expressions are calculated using an exactly 32-bit
2584 wide, signed or unsigned, type with silent wraparound on integer overflow.
2585 Integer constants may be specified with arbitrary bases using the notation
2586 .Ar base Ns # Ns Ar number ,
2589 is a decimal integer specifying the base, and
2591 is a number in the specified base.
2592 Additionally, base-16 integers may be specified by prefixing them with
2594 .Pq case-insensitive
2595 in all forms of arithmetic expressions, except as numeric arguments to the
2598 Prefixing numbers with a sole digit zero
2600 leads to the shell interpreting it as base-8 (octal) integer in
2604 historically, (pd)ksh has never done so either anyway,
2605 and it's unsafe to do that, but POSIX demands it nowadays.
2608 extension, numbers to the base of one are treated as either (8-bit
2609 transparent) ASCII or Unicode codepoints, depending on the shell's
2611 flag (current setting).
2620 Note that NUL bytes (integral value of zero) cannot be used.
2621 An unset or empty parameter evaluates to 0 in integer context.
2622 In Unicode mode, raw octets are mapped into the range EF80..EFFF as in
2623 OPTU-8, which is in the PUA and has been assigned by CSUR for this use.
2624 If more than one octet in ASCII mode, or a sequence of more than one
2625 octet not forming a valid and minimal CESU-8 sequence is passed, the
2626 behaviour is undefined (usually, the shell aborts with a parse error,
2627 but rarely, it succeeds, e.g. on the sequence C2 20).
2628 That's why you should always use ASCII mode unless you know that the
2629 input is well-formed UTF-8 in the range of 0000..FFFD.
2631 The operators are evaluated as follows:
2632 .Bl -tag -width Ds -offset indent
2634 Result is the argument (included for completeness).
2639 the result is 1 if argument is zero, 0 if not.
2641 Arithmetic (bit-wise) NOT.
2643 Increment; must be applied to a parameter (not a literal or other expression).
2644 The parameter is incremented by 1.
2645 When used as a prefix operator, the result
2646 is the incremented value of the parameter; when used as a postfix operator, the
2647 result is the original value of the parameter.
2651 except the parameter is decremented by 1.
2653 Separates two arithmetic expressions; the left-hand side is evaluated first,
2655 The result is the value of the expression on the right-hand side.
2657 Assignment; the variable on the left is set to the value on the right.
2659 .No += \-= *= /= %= \*(Lt\*(Lt\*(Lt= \*(Gt\*(Gt\*(Gt=
2660 .No \*(Lt\*(Lt= \*(Gt\*(Gt= &= \*(ha= \*(Ba=
2662 Assignment operators.
2677 with any operator precedence in
2682 is the same as specifying
2683 .Dq var1 = var1 * (5 + 3) .
2686 the result is 1 if either argument is non-zero, 0 if not.
2687 The right argument is evaluated only if the left argument is zero.
2690 the result is 1 if both arguments are non-zero, 0 if not.
2691 The right argument is evaluated only if the left argument is non-zero.
2693 Arithmetic (bit-wise) OR.
2695 Arithmetic (bit-wise) XOR
2698 Arithmetic (bit-wise) AND.
2700 Equal; the result is 1 if both arguments are equal, 0 if not.
2702 Not equal; the result is 0 if both arguments are equal, 1 if not.
2704 Less than; the result is 1 if the left argument is less than the right, 0 if
2706 .It \*(Lt= \*(Gt \*(Gt=
2707 Less than or equal, greater than, greater than or equal.
2710 .It \*(Lt\*(Lt\*(Lt \*(Gt\*(Gt\*(Gt
2711 Rotate left (right); the result is similar to shift (see
2713 except that the bits shifted out at one end are shifted in
2714 at the other end, instead of zero or sign bits.
2715 .It \*(Lt\*(Lt \*(Gt\*(Gt
2716 Shift left (right); the result is the left argument with its bits shifted left
2717 (right) by the amount given in the right argument.
2719 Addition, subtraction, multiplication, and division.
2721 Remainder; the result is the symmetric remainder of the division of the left
2722 argument by the right.
2723 To get the mathematical modulus of
2739 is non-zero, the result is
2741 otherwise the result is
2743 The non-result argument is not evaluated.
2746 A co-process (which is a pipeline created with the
2748 operator) is an asynchronous process that the shell can both write to (using
2750 and read from (using
2752 The input and output of the co-process can also be manipulated using
2756 redirections, respectively.
2757 Once a co-process has been started, another can't
2758 be started until the co-process exits, or until the co-process's input has been
2760 .Ic exec Ar n Ns Ic \*(Gt&p
2762 If a co-process's input is redirected in this way, the next
2763 co-process to be started will share the output with the first co-process,
2764 unless the output of the initial co-process has been redirected using an
2765 .Ic exec Ar n Ns Ic \*(Lt&p
2768 Some notes concerning co-processes:
2771 The only way to close the co-process's input (so the co-process reads an
2772 end-of-file) is to redirect the input to a numbered file descriptor and then
2773 close that file descriptor:
2774 .Ic exec 3\*(Gt&p; exec 3\*(Gt&\-
2776 In order for co-processes to share a common output, the shell must keep the
2777 write portion of the output pipe open.
2778 This means that end-of-file will not be
2779 detected until all co-processes sharing the co-process's output have exited
2780 (when they all exit, the shell closes its copy of the pipe).
2782 avoided by redirecting the output to a numbered file descriptor (as this also
2783 causes the shell to close its copy).
2784 Note that this behaviour is slightly
2785 different from the original Korn shell which closes its copy of the write
2786 portion of the co-process output when the most recently started co-process
2787 (instead of when all sharing co-processes) exits.
2792 signals during writes if the signal is not being trapped or ignored; the same
2793 is true if the co-process input has been duplicated to another file descriptor
2795 .Ic print \-u Ns Ar n
2799 Functions are defined using either Korn shell
2800 .Ic function Ar function-name
2801 syntax or the Bourne/POSIX shell
2802 .Ar function-name Ns \&()
2803 syntax (see below for the difference between the two forms).
2806 (i.e. scripts sourced using the
2809 in that they are executed in the current environment.
2812 shell arguments (i.e. positional parameters $1, $2, etc.)\&
2813 are never visible inside them.
2814 When the shell is determining the location of a command, functions
2815 are searched after special built-in commands, before builtins and the
2819 An existing function may be deleted using
2820 .Ic unset Fl f Ar function-name .
2821 A list of functions can be obtained using
2823 and the function definitions can be listed using
2827 command (which is an alias for
2829 may be used to create undefined functions: when an undefined function is
2830 executed, the shell searches the path specified in the
2832 parameter for a file with the same name as the function which, if found, is
2834 If after executing the file the named function is found to
2835 be defined, the function is executed; otherwise, the normal command search is
2836 continued (i.e. the shell searches the regular built-in command table and
2838 Note that if a command is not found using
2840 an attempt is made to autoload a function using
2842 (this is an undocumented feature of the original Korn shell).
2844 Functions can have two attributes,
2848 which can be set with
2853 When a traced function is executed, the shell's
2855 option is turned on for the function's duration.
2858 attribute of functions is currently not used.
2859 In the original Korn shell,
2860 exported functions are visible to shell scripts that are executed.
2862 Since functions are executed in the current shell environment, parameter
2863 assignments made inside functions are visible after the function completes.
2864 If this is not the desired effect, the
2866 command can be used inside a function to create a local parameter.
2870 uses static scoping (one global scope, one local scope per function)
2871 and allows local variables only on Korn style functions, whereas
2873 uses dynamic scoping (nested scopes of varying locality).
2874 Note that special parameters (e.g.\&
2876 can't be scoped in this way.
2878 The exit status of a function is that of the last command executed in the
2880 A function can be made to finish immediately using the
2882 command; this may also be used to explicitly specify the exit status.
2884 Functions defined with the
2886 reserved word are treated differently in the following ways from functions
2892 The $0 parameter is set to the name of the function
2893 (Bourne-style functions leave $0 untouched).
2895 Parameter assignments preceding function calls are not kept in the shell
2896 environment (executing Bourne-style functions will keep assignments).
2899 is saved/reset and restored on entry and exit from the function so
2901 can be used properly both inside and outside the function (Bourne-style
2906 inside a function interferes with using
2908 outside the function).
2910 Bourne-style function definitions take precedence over alias dereferences
2911 and remove alias definitions upon encounter, while aliases take precedence
2912 over Korn-style functions.
2915 In the future, the following differences may also be added:
2918 A separate trap/signal environment will be used during the execution of
2920 This will mean that traps set inside a function will not affect the
2921 shell's traps and signals that are not ignored in the shell (but may be
2922 trapped) will have their default effect in a function.
2924 The EXIT trap, if set in a function, will be executed after the function
2927 .Ss Command execution
2928 After evaluation of command-line arguments, redirections, and parameter
2929 assignments, the type of command is determined: a special built-in command,
2930 a function, a normal builtin, or the name of a file to execute found using the
2933 The checks are made in the above order.
2934 Special built-in commands differ from other commands in that the
2936 parameter is not used to find them, an error during their execution can
2937 cause a non-interactive shell to exit, and parameter assignments that are
2938 specified before the command are kept after the command completes.
2939 Regular built-in commands are different only in that the
2941 parameter is not used to find them.
2945 and POSIX differ somewhat in which commands are considered
2948 POSIX special built-in utilities:
2950 .Ic \&. , \&: , break , continue ,
2951 .Ic eval , exec , exit , export ,
2952 .Ic readonly , return , set , shift ,
2953 .Ic times , trap , unset
2957 commands keeping assignments:
2959 .Ic builtin , global , typeset , wait
2961 Builtins that are not special:
2963 .Ic [ , alias , bg , bind ,
2964 .Ic cat , cd , command , echo ,
2965 .Ic false , fc , fg , getopts ,
2966 .Ic jobs , kill , let , mknod ,
2967 .Ic print , pwd , read , realpath ,
2968 .Ic rename , sleep , suspend , test ,
2969 .Ic true , ulimit , umask , unalias ,
2972 Once the type of command has been determined, any command-line parameter
2973 assignments are performed and exported for the duration of the command.
2975 The following describes the special and regular built-in commands:
2977 .Bl -tag -width false -compact
2978 .It Ic \&. Ar file Op Ar arg ...
2982 Execute the commands in
2984 in the current environment.
2985 The file is searched for in the directories of
2987 If arguments are given, the positional parameters may be used to access them
2991 If no arguments are given, the positional parameters are
2992 those of the environment the command is used in.
2994 .It Ic \&: Op Ar ...
2996 Exit status is set to zero.
2998 .It Ic \&[ Ar expression Ic \&]
3003 .Oo Fl d \*(Ba t Oo Fl r Oc \*(Ba
3008 .Op Ns = Ns Ar value
3014 For any name without a value, the existing alias is listed.
3015 Any name with a value defines an alias (see
3019 When listing aliases, one of two formats is used.
3020 Normally, aliases are listed as
3021 .Ar name Ns = Ns Ar value ,
3025 If options were preceded with
3029 is given on the command line, only
3035 option causes directory aliases which are used in tilde expansion to be
3042 option is used, each alias is prefixed with the string
3047 option indicates that tracked aliases are to be listed/set (values specified on
3048 the command line are ignored for tracked aliases).
3051 option indicates that all tracked aliases are to be reset.
3057 the export attribute of an alias, or, if no names are given, lists the aliases
3058 with the export attribute (exporting an alias has no effect).
3060 .It Ic bg Op Ar job ...
3061 Resume the specified stopped job(s) in the background.
3062 If no jobs are specified,
3067 below for more information.
3070 The current bindings are listed.
3075 instead lists the names of the functions to which keys may be bound.
3077 .Sx Emacs editing mode
3078 for more information.
3080 .It Xo Ic bind Op Fl m
3081 .Ar string Ns = Ns Op Ar substitute
3085 .Ar string Ns = Ns Op Ar editing-command
3088 The specified editing command is bound to the given
3090 which should consist of a control character
3091 optionally preceded by one of the two prefix characters
3092 and optionally succeded by a tilde character.
3095 will cause the editing command to be immediately invoked.
3098 flag is given, the specified input
3100 will afterwards be immediately replaced by the given
3102 string which may contain editing commands but not other macros.
3103 If a tilde postfix is given, a tilde trailing the one or
3104 two prefices and the control character is ignored, any
3105 other trailing character will be processed afterwards.
3107 Control characters may be written using caret notation
3108 i.e. \*(haX represents Ctrl-X.
3109 Note that although only two prefix characters (usually ESC and \*(haX)
3110 are supported, some multi-character sequences can be supported.
3112 The following default bindings show how the arrow keys, the home, end and
3113 delete key on a BSD wsvt25, xterm\-xfree86 or GNU screen terminal are bound
3114 (of course some escape sequences won't work out quite this nicely):
3115 .Bd -literal -offset indent
3116 bind \*(aq\*(haX\*(aq=prefix\-2
3117 bind \*(aq\*(ha[[\*(aq=prefix\-2
3118 bind \*(aq\*(haXA\*(aq=up\-history
3119 bind \*(aq\*(haXB\*(aq=down\-history
3120 bind \*(aq\*(haXC\*(aq=forward\-char
3121 bind \*(aq\*(haXD\*(aq=backward\-char
3122 bind \*(aq\*(haX1\*(TI\*(aq=beginning\-of\-line
3123 bind \*(aq\*(haX7\*(TI\*(aq=beginning\-of\-line
3124 bind \*(aq\*(haXH\*(aq=beginning\-of\-line
3125 bind \*(aq\*(haX4\*(TI\*(aq=end\-of\-line
3126 bind \*(aq\*(haX8\*(TI\*(aq=end\-of\-line
3127 bind \*(aq\*(haXF\*(aq=end\-of\-line
3128 bind \*(aq\*(haX3\*(TI\*(aq=delete\-char\-forward
3131 .It Ic break Op Ar level
3147 .Ar command Op Ar arg ...
3149 Execute the built-in command
3157 Read files sequentially, in command line order, and write them to
3163 or absent, read from standard input.
3164 Unless compiled with
3165 .Dv MKSH_NO_EXTERNAL_CAT ,
3166 if any options are given, an external
3168 utility is invoked instead if called from the shell.
3169 For direct builtin calls, the
3172 option is supported as a no-op.
3189 Set the working directory to
3193 is set, it lists the search path for the directory containing
3197 path means the current directory.
3200 is found in any component of the
3202 search path other than the
3204 path, the name of the new working directory will be written to standard output.
3207 is missing, the home directory
3214 the previous working directory is used (see the
3220 option (logical path) is used or if the
3222 option isn't set (see the
3224 command below), references to
3228 are relative to the path used to get to the directory.
3231 option (physical path) is used or if the
3235 is relative to the filesystem directory tree.
3240 parameters are updated to reflect the current and old working directory,
3244 option is set for physical filesystem traversal, and
3246 could not be set, the exit code is 1; greater than 1 if an
3247 error occurred, 0 otherwise.
3263 in the current directory, and the shell attempts to change to the new
3278 is executed exactly as if
3280 had not been specified, with two exceptions:
3283 cannot be a shell function;
3284 and secondly, special built-in commands lose their specialness
3285 (i.e. redirection and utility errors do not cause the shell to
3286 exit, and command assignments are not permanent).
3290 option is given, a default search path is used instead of the current value of
3292 the actual value of which is system dependent.
3296 option is given, instead of executing
3298 information about what would be executed is given (and the same is done for
3300 For special and regular built-in commands and functions, their names are simply
3301 printed; for aliases, a command that defines them is printed; and for commands
3302 found by searching the
3304 parameter, the full path of the command is printed.
3305 If no command is found
3306 (i.e. the path search fails), nothing is printed and
3308 exits with a non-zero status.
3313 option, except it is more verbose.
3315 .It Ic continue Op Ar level
3316 Jumps to the beginning of the
3334 this utility is not portable; use the Korn shell builtin
3338 Prints its arguments (separated by spaces) followed by a newline, to the
3340 The newline is suppressed if any of the arguments contain the
3345 command below for a list of other backslash sequences that are recognised.
3347 The options are provided for compatibility with
3352 option suppresses the trailing newline,
3354 enables backslash interpretation (a no-op, since this is normally done), and
3356 suppresses backslash interpretation.
3362 option is set or this is a direct builtin call, only the first argument
3363 is treated as an option, and only if it is exactly
3365 Backslash interpretation is disabled.
3367 .It Ic eval Ar command ...
3368 The arguments are concatenated (with spaces between them) to form a single
3369 string which the shell then parses and executes in the current environment.
3373 .Op Ar command Op Ar arg ...
3375 The command is executed without forking, replacing the shell process.
3377 If no command is given except for I/O redirection, the I/O redirection is
3378 permanent and the shell is
3380 Any file descriptors greater than 2 which are opened or
3382 in this way are not made available to other executed commands (i.e. commands
3383 that are not built-in to the shell).
3384 Note that the Bourne shell differs here;
3385 it does pass these file descriptors on.
3387 .It Ic exit Op Ar status
3388 The shell exits with the specified exit status.
3391 is not specified, the exit status is the current value of the
3398 .Op Ar parameter Ns Op = Ns Ar value
3400 Sets the export attribute of the named parameters.
3401 Exported parameters are passed in the environment to executed commands.
3402 If values are specified, the named parameters are also assigned.
3404 If no parameters are specified, all parameters with the export attribute
3405 set are printed one per line; either their names, or, if a
3407 with no option letter is specified, name=value pairs, or, with
3410 commands suitable for re-entry.
3413 A command that exits with a non-zero status.
3417 .Oo Fl e Ar editor \*(Ba
3420 .Op Ar first Op Ar last
3425 select commands from the history.
3426 Commands can be selected by history number
3427 (negative numbers go backwards from the current, most recent, line)
3428 or a string specifying the most recent command starting with that string.
3431 option lists the command on standard output, and
3433 inhibits the default command numbers.
3436 option reverses the order of the list.
3439 the selected commands are edited by the editor specified with the
3443 is specified, the editor specified by the
3445 parameter (if this parameter is not set,
3447 is used), and then executed by the shell.
3451 .Cm \-e \- \*(Ba Fl s
3453 .Op Ar old Ns = Ns Ar new
3456 Re-execute the selected command (the previous command by default) after
3457 performing the optional substitution of
3463 is specified, all occurrences of
3471 is identical: re-execute the selected command without invoking an editor.
3472 This command is usually accessed with the predefined:
3473 .Ic alias r=\*(aqfc \-e \-\*(aq
3475 .It Ic fg Op Ar job ...
3476 Resume the specified job(s) in the foreground.
3477 If no jobs are specified,
3482 below for more information.
3489 Used by shell procedures to parse the specified arguments (or positional
3490 parameters, if no arguments are given) and to check for legal options.
3492 contains the option letters that
3495 If a letter is followed by a colon, the option is expected to
3497 Options that do not take arguments may be grouped in a single argument.
3498 If an option takes an argument and the option character is not the
3499 last character of the argument it is found in, the remainder of the argument is
3500 taken to be the option's argument; otherwise, the next argument is the option's
3505 is invoked, it places the next option in the shell parameter
3507 and the index of the argument to be processed by the next call to
3509 in the shell parameter
3511 If the option was introduced with a
3513 the option placed in
3517 When an option requires an argument,
3519 places it in the shell parameter
3522 When an illegal option or a missing option argument is encountered, a question
3523 mark or a colon is placed in
3525 (indicating an illegal option or missing argument, respectively) and
3527 is set to the option character that caused the problem.
3530 does not begin with a colon, a question mark is placed in
3533 is unset, and an error message is printed to standard error.
3535 When the end of the options is encountered,
3537 exits with a non-zero exit status.
3538 Options end at the first (non-option
3539 argument) argument that does not start with a
3543 argument is encountered.
3545 Option parsing can be reset by setting
3547 to 1 (this is done automatically whenever the shell or a shell procedure is
3550 Warning: Changing the value of the shell parameter
3552 to a value other than 1, or parsing different sets of arguments without
3555 may lead to unexpected results.
3566 Without arguments, any hashed executable command pathnames are listed.
3569 option causes all hashed commands to be removed from the hash table.
3572 is searched as if it were a command name and added to the hash table if it is
3573 an executable command.
3580 Display information about the specified job(s); if no jobs are specified, all
3584 option causes information to be displayed only for jobs that have changed
3585 state since the last notification.
3588 option is used, the process ID of each process in a job is also listed.
3591 option causes only the process group of each job to be printed.
3594 below for the format of
3596 and the displayed job.
3600 .Oo Fl s Ar signame \*(Ba
3601 .No \- Ns Ar signum \*(Ba
3602 .No \- Ns Ar signame Oc
3603 .No { Ar job \*(Ba pid \*(Ba pgrp No }
3606 Send the specified signal to the specified jobs, process IDs, or process
3608 If no signal is specified, the
3611 If a job is specified, the signal is sent to the job's process group.
3614 below for the format of
3620 .Op Ar exit-status ...
3622 Print the signal name corresponding to
3624 If no arguments are specified, a list of all the signals, their numbers, and
3625 a short description of them are printed.
3627 .It Ic let Op Ar expression ...
3628 Each expression is evaluated (see
3629 .Sx Arithmetic expressions
3631 If all expressions are successfully evaluated, the exit status is 0 (1)
3632 if the last expression evaluated to non-zero (zero).
3633 If an error occurs during
3634 the parsing or evaluation of an expression, the exit status is greater than 1.
3635 Since expressions may need to be quoted,
3636 .No \&(( Ar expr No ))
3637 is syntactic sugar for
3638 .No let \&" Ns Ar expr Ns \&" .
3641 Internally used alias for
3657 Create a device special file.
3658 The file type may be
3660 (block type device),
3662 (character type device),
3665 .Pq named pipe , Tn FIFO .
3666 The file created may be modified according to its
3672 (major device number),
3675 (minor device number).
3679 for further information.
3683 .Oo Fl nprsu Ns Oo Ar n Oc \*(Ba
3688 prints its arguments on the standard output, separated by spaces and
3689 terminated with a newline.
3692 option suppresses the newline.
3693 By default, certain C escapes are translated.
3694 These include these mentioned in
3695 .Sx Backslash expansion
3698 which is equivalent to using the
3701 Backslash expansion may be inhibited with the
3706 option prints to the history file instead of standard output; the
3708 option prints to file descriptor
3712 defaults to 1 if omitted
3716 option prints to the co-process (see
3722 option is used to emulate, to some degree, the
3725 command which does not process
3727 sequences unless the
3732 option suppresses the trailing newline.
3734 .It Ic printf Ar format Op Ar arguments ...
3736 Approximately the same as the
3738 utility, except it uses the same
3739 .Sx Backslash expansion
3740 and I/O code and does hot handle floating point as the rest of
3742 This is not normally part of
3744 however, distributors may have added this as builtin as a speed hack.
3745 Do not use in new code.
3748 Print the present working directory.
3751 option is used or if the
3753 option isn't set (see the
3755 command below), the logical path is printed (i.e. the path used to
3757 to the current directory).
3760 option (physical path) is used or if the
3762 option is set, the path determined from the filesystem (by following
3764 directories to the root directory) is printed.
3778 Reads a line of input, separates the input into fields using the
3782 above), and assigns each field to the specified parameters
3784 If no parameters are specified, the
3786 parameter is used to store the result.
3791 options, only no or one parameter is accepted.
3792 If there are more parameters than fields, the extra parameters are set to
3793 the empty string or 0; if there are more fields than parameters, the last
3794 parameter is assigned the remaining fields (including the word separators).
3796 The options are as follows:
3797 .Bl -tag -width XuXnX
3799 Store the result into the parameter
3805 Store the result without word splitting into the parameter
3809 as array of characters (wide characters if the
3811 option is enacted, octets otherwise).
3813 Use the first byte of
3816 if empty, instead of the ASCII newline character as input line delimiter.
3818 Instead of reading till end-of-line, read exactly
3820 bytes; less if EOF or a timeout occurs.
3822 Instead of reading till end-of-line, read up to
3824 bytes but return as soon as any bytes are read, e.g.\& from a
3825 slow terminal device, or if EOF or a timeout occurs.
3827 Read from the currently active co-process, see
3829 above for details on this.
3831 Read from the file descriptor
3833 (defaults to 0, i.e.\& standard input).
3834 The argument must immediately follow the option character.
3836 Interrupt reading after
3838 seconds (specified as positive decimal value with an optional fractional part).
3840 Normally, the ASCII backslash character escapes the special
3841 meaning of the following character and is stripped from the input;
3843 does not stop when encountering a backslash-newline sequence and
3844 does not store that newline in the result.
3845 This option enables raw mode, in which backslashes are not processed.
3847 The input line is saved to the history.
3850 If the input is a terminal, both the
3854 options set it into raw mode;
3855 they read an entire file if \-1 is passed as
3859 The first parameter may have a question mark and a string appended to it, in
3860 which case the string is used as a prompt (printed to standard error before
3861 any input is read) if the input is a
3864 .Ic read nfoo?\*(aqnumber of foos: \*(aq ) .
3866 If no input is read or a timeout occurred,
3868 exits with a non-zero status.
3870 Another handy set of tricks:
3873 is run in a loop such as
3874 .Ic while read foo; do ...; done
3875 then leading whitespace will be removed (IFS) and backslashes processed.
3876 You might want to use
3877 .Ic while IFS= read \-r foo; do ...; done
3879 Similarily, when using the
3883 option might be prudent; the same applies for:
3884 .Bd -literal -offset indent
3885 find . \-type f \-print0 \*(Ba \e
3886 while IFS= read \-d \*(aq\*(aq \-r filename; do
3887 print \-r \-\- "found \*(Lt${filename#./}\*(Gt"
3891 The inner loop will be executed in a subshell and variable changes
3892 cannot be propagated if executed in a pipeline:
3893 .Bd -literal -offset indent
3894 bar \*(Ba baz \*(Ba while read foo; do ...; done
3897 Use co-processes instead:
3898 .Bd -literal -offset indent
3899 bar \*(Ba baz \*(Ba&
3900 while read \-p foo; do ...; done
3901 exec 3\*(Gt&p; exec 3\*(Gt&\-
3908 .Op Ns = Ns Ar value
3911 Sets the read-only attribute of the named parameters.
3912 If values are given,
3913 parameters are set to them before setting the attribute.
3915 made read-only, it cannot be unset and its value cannot be changed.
3917 If no parameters are specified, the names of all parameters with the read-only
3918 attribute are printed one per line, unless the
3920 option is used, in which case
3922 commands defining all read-only parameters, including their values, are
3930 Prints the resolved absolute pathname corresponding to
3936 it's also checked for existence and whether it is a directory; otherwise,
3938 returns 0 if the pathname either exists or can be created immediately,
3939 i.e. all but the last component exist and are directories.
3950 Both must be complete pathnames and on the same device.
3951 This builtin is intended for emergency situations where
3953 becomes unusable, and directly calls
3956 .It Ic return Op Ar status
3957 Returns from a function or
3959 script, with exit status
3963 is given, the exit status of the last executed command is used.
3964 If used outside of a function or
3966 script, it has the same effect as
3970 treats both profile and
3974 scripts, while the original Korn shell only treats profiles as
3979 .Ic set Op Ic +\-abCefhiklmnprsUuvXx
3980 .Op Ic +\-o Ar option
3987 command can be used to set
3991 shell options, set the positional parameters, or set an array parameter.
3992 Options can be changed using the
3996 is the long name of an option, or using the
3997 .Cm +\- Ns Ar letter
4000 is the option's single letter name (not all options have a single letter name).
4001 The following table lists both option letters (if they exist) and long names
4002 along with a description of what the option does:
4005 Sets the elements of the array parameter
4011 is used, the array is reset (i.e. emptied) first; if
4013 is used, the first N elements are set (where N is the number of arguments);
4014 the rest are left untouched.
4016 An alternative syntax for the command
4017 .Ic set \-A foo \-\- a b c
4018 which is compatible to
4021 and also supported by
4025 .Ic foo=(a b c); foo+=(d e)
4033 extension allows specifying the indices used for
4035 .Pq from the above example, Ic a b c
4037 .Ic set \-A foo \-\- [0]=a [1]=b [2]=c
4039 .Ic foo=([0]=a [1]=b [2]=c)
4040 which can also be written
4042 because indices are incremented automatically.
4043 .It Fl a \*(Ba Fl o Ic allexport
4044 All new parameters are created with the export attribute.
4045 .It Fl b \*(Ba Fl o Ic notify
4046 Print job notification messages asynchronously, instead of just before the
4048 Only used if job control is enabled
4050 .It Fl C \*(Ba Fl o Ic noclobber
4051 Prevent \*(Gt redirection from overwriting existing files.
4052 Instead, \*(Gt\*(Ba must be used to force an overwrite.
4053 Note that this is not safe to use for creation of temporary files or
4054 lockfiles due to a TOCTOU in a check allowing one to redirect output to
4056 or other device files even in
4059 .It Fl e \*(Ba Fl o Ic errexit
4060 Exit (after executing the
4062 trap) as soon as an error occurs or a command fails (i.e. exits with a
4064 This does not apply to commands whose exit status is
4065 explicitly tested by a shell construct such as
4076 only the status of the last command is tested.
4077 .It Fl f \*(Ba Fl o Ic noglob
4078 Do not expand file name patterns.
4079 .It Fl h \*(Ba Fl o Ic trackall
4080 Create tracked aliases for all executed commands (see
4083 Enabled by default for non-interactive shells.
4084 .It Fl i \*(Ba Fl o Ic interactive
4085 The shell is an interactive shell.
4086 This option can only be used when the shell is invoked.
4087 See above for a description of what this means.
4088 .It Fl k \*(Ba Fl o Ic keyword
4089 Parameter assignments are recognised anywhere in a command.
4090 .It Fl l \*(Ba Fl o Ic login
4091 The shell is a login shell.
4092 This option can only be used when the shell is invoked.
4093 See above for a description of what this means.
4094 .It Fl m \*(Ba Fl o Ic monitor
4095 Enable job control (default for interactive shells).
4096 .It Fl n \*(Ba Fl o Ic noexec
4097 Do not execute any commands.
4098 Useful for checking the syntax of scripts
4099 (ignored if interactive).
4100 .It Fl p \*(Ba Fl o Ic privileged
4101 The shell is a privileged shell.
4102 It is set automatically if, when the shell starts,
4103 the real UID or GID does not match
4104 the effective UID (EUID) or GID (EGID), respectively.
4105 See above for a description of what this means.
4106 .It Fl r \*(Ba Fl o Ic restricted
4107 The shell is a restricted shell.
4108 This option can only be used when the shell is invoked.
4109 See above for a description of what this means.
4110 .It Fl s \*(Ba Fl o Ic stdin
4111 If used when the shell is invoked, commands are read from standard input.
4112 Set automatically if the shell is invoked with no arguments.
4118 command it causes the specified arguments to be sorted before assigning them to
4119 the positional parameters (or to array
4124 .It Fl U \*(Ba Fl o Ic utf8\-mode
4125 Enable UTF-8 support in the
4126 .Sx Emacs editing mode
4127 and internal string handling functions.
4128 This flag is disabled by default, but can be enabled by setting it on the
4129 shell command line; is enabled automatically for interactive shells if
4130 requested at compile time, your system supports
4131 .Fn setlocale LC_CTYPE \&""
4133 .Fn nl_langinfo CODESET ,
4139 environment variables,
4140 and at least one of these returns something that matches
4144 case-insensitively; for direct builtin calls depending on the
4145 aforementioned environment variables; or for stdin or scripts,
4146 if the input begins with a UTF-8 Byte Order Mark.
4147 .It Fl u \*(Ba Fl o Ic nounset
4148 Referencing of an unset parameter, other than
4152 is treated as an error, unless one of the
4158 .It Fl v \*(Ba Fl o Ic verbose
4159 Write shell input to standard error as it is read.
4160 .It Fl X \*(Ba Fl o Ic markdirs
4161 Mark directories with a trailing
4163 during file name generation.
4164 .It Fl x \*(Ba Fl o Ic xtrace
4165 Print command trees when they are executed, preceded by
4169 Background jobs are run with lower priority.
4170 .It Fl o Ic braceexpand
4171 Enable brace expansion (a.k.a. alternation).
4172 This is enabled by default.
4173 If disabled, tilde expansion after an equals sign is disabled as a side effect.
4175 Enable BRL emacs-like command-line editing (interactive shells only); see
4176 .Sx Emacs editing mode .
4178 Enable gmacs-like command-line editing (interactive shells only).
4179 Currently identical to emacs editing except that transpose\-chars (\*(haT) acts
4180 slightly differently.
4181 .It Fl o Ic ignoreeof
4182 The shell will not (easily) exit when end-of-file is read;
4185 To avoid infinite loops, the shell will exit if
4187 is read 13 times in a row.
4188 .It Fl o Ic inherit\-xtrace
4191 upon entering functions.
4192 This is enabled by default.
4194 Do not kill running jobs with a
4196 signal when a login shell exits.
4197 Currently set by default, but this may
4198 change in the future to be compatible with
4202 doesn't have this option, but does send the
4207 In the original Korn shell, this prevents function definitions from
4208 being stored in the history file.
4209 .It Fl o Ic physical
4216 (i.e. the filesystem's)
4218 directories instead of
4220 directories (i.e. the shell handles
4222 which allows the user to be oblivious of symbolic links to directories).
4224 Note that setting this option does not affect the current value of the
4234 commands above for more details.
4235 .It Fl o Ic pipefail
4236 Make the exit status of a pipeline (before logically complementing) the
4237 rightmost non-zero errorlevel, or zero if all commands exited with zero.
4239 Enable a somewhat more
4242 As a side effect, setting this flag turns off
4244 mode, which can be turned back on manually, and
4252 Automatically enabled if the basename of the shell invocation begins with
4254 and this autodetection feature is compiled in
4256 As a side effect, setting this flag turns off
4258 mode, which can be turned back on manually, and
4264 command-line editing (interactive shells only).
4267 for documentation and limitations.
4268 .It Fl o Ic vi\-esccomplete
4269 In vi command-line editing, do command and file name completion when escape
4270 (\*(ha[) is entered in command mode.
4271 .It Fl o Ic vi\-tabcomplete
4272 In vi command-line editing, do command and file name completion when tab (\*(haI)
4273 is entered in insert mode.
4274 This is the default.
4277 In the original Korn shell, unless
4279 was set, the vi command-line mode would let the
4281 driver do the work until ESC (\*(ha[) was entered.
4283 is always in viraw mode.
4286 These options can also be used upon invocation of the shell.
4288 options (with single letter names) can be found in the parameter
4291 with no option name will list all the options and whether each is on or off;
4293 will print the long names of all options that are currently on.
4295 Remaining arguments, if any, are positional parameters and are assigned, in
4296 order, to the positional parameters (i.e. $1, $2, etc.).
4299 and there are no remaining arguments, all positional parameters are cleared.
4300 If no options or arguments are given, the values of all names are printed.
4301 For unknown historical reasons, a lone
4303 option is treated specially \*(en it clears both the
4309 .It Ic shift Op Ar number
4310 The positional parameters
4320 .It Ic sleep Ar seconds
4321 Suspends execution for a minimum of the
4323 specified as positive decimal value with an optional fractional part.
4324 Signal delivery may continue execution earlier.
4326 .It Ic source Ar file Op Ar arg ...
4328 .Ic \&. Po Do dot Dc Pc ,
4329 except that the current working directory is appended to the
4339 this is implemented as a shell alias instead of a builtin.
4342 Stops the shell as if it had received the suspend character from
4344 It is not possible to suspend a login shell unless the parent process
4345 is a member of the same terminal session but is a member of a different
4347 As a general rule, if the shell was started by another shell or via
4349 it can be suspended.
4351 .It Ic test Ar expression
4352 .It Ic \&[ Ar expression Ic \&]
4356 and returns zero status if true, 1 if false, or greater than 1 if there
4358 It is normally used as the condition command of
4363 Symbolic links are followed for all
4370 The following basic expressions are available:
4377 is a block special device.
4380 is a character special device.
4392 group is the shell's effective group ID.
4395 mode has the setgid bit set.
4398 is a context dependent directory (only useful on HP-UX).
4412 owner is the shell's effective user ID.
4418 command above for a list of options).
4419 As a non-standard extension, if the option starts with a
4421 the test is negated; the test always fails if
4423 doesn't exist (so [ \-o foo \-o \-o !foo ] returns true if and only if option
4426 The same can be achieved with [ \-o ?foo ] like in
4430 can also be the short flag led by either
4434 .Pq no logical negation ,
4447 exists and is readable.
4451 .Xr unix 4 Ns -domain
4464 mode has the setuid bit set.
4467 exists and is writable.
4470 exists and is executable.
4471 .It Ar file1 Fl nt Ar file2
4480 .It Ar file1 Fl ot Ar file2
4489 .It Ar file1 Fl ef Ar file2
4495 has non-zero length.
4502 .It Ar string No = Ar string
4504 .It Ar string No == Ar string
4506 .It Ar string No \*(Gt Ar string
4507 First string operand is greater than second string operand.
4508 .It Ar string No \*(Lt Ar string
4509 First string operand is less than second string operand.
4510 .It Ar string No != Ar string
4511 Strings are not equal.
4512 .It Ar number Fl eq Ar number
4513 Numbers compare equal.
4514 .It Ar number Fl ne Ar number
4515 Numbers compare not equal.
4516 .It Ar number Fl ge Ar number
4517 Numbers compare greater than or equal.
4518 .It Ar number Fl gt Ar number
4519 Numbers compare greater than.
4520 .It Ar number Fl le Ar number
4521 Numbers compare less than or equal.
4522 .It Ar number Fl \< Ar number
4523 Numbers compare less than.
4526 The above basic expressions, in which unary operators have precedence over
4527 binary operators, may be combined with the following operators (listed in
4528 increasing order of precedence):
4529 .Bd -literal -offset indent
4530 expr \-o expr Logical OR.
4531 expr \-a expr Logical AND.
4536 Note that a number actually may be an arithmetic expression, such as
4537 a mathematical term or the name of an integer variable:
4538 .Bd -literal -offset indent
4539 x=1; [ "x" \-eq 1 ] evaluates to true
4542 Note that some special rules are applied (courtesy of
4544 ) if the number of arguments to
4546 or inside the brackets
4548 is less than five: if leading
4550 arguments can be stripped such that only one to three arguments remain,
4551 then the lowered comparison is executed; (thanks to XSI) parentheses
4553 lower four- and three-argument forms to two- and one-argument forms,
4554 respectively; three-argument forms ultimately prefer binary operations,
4555 followed by negation and parenthesis lowering; two- and four-argument forms
4556 prefer negation followed by parenthesis; the one-argument form always implies
4560 A common mistake is to use
4561 .Dq if \&[ $foo = bar \&]
4562 which fails if parameter
4566 or unset, if it has embedded spaces (i.e.\&
4568 octets), or if it is a unary operator like
4573 .Dq if \&[ x\&"$foo\&" = x"bar" \&]
4574 instead, or the double-bracket operator
4575 .Dq if \&[[ $foo = bar \&]]
4576 or, to avoid pattern matching (see
4579 .Dq if \&[[ $foo = \&"$bar" \&]]
4583 construct is not only more secure to use but also often faster.
4592 is given, the times used to execute the pipeline are reported.
4594 is given, then the user and system time used by the shell itself, and all the
4595 commands it has run since it was started, are reported.
4596 The times reported are the real time (elapsed time from start to finish),
4597 the user CPU time (time spent running in user mode), and the system CPU time
4598 (time spent running in kernel mode).
4599 Times are reported to standard error; the format of the output is:
4601 .Dl "0m0.00s real 0m0.00s user 0m0.00s system"
4605 option is given the output is slightly longer:
4606 .Bd -literal -offset indent
4612 It is an error to specify the
4616 is a simple command.
4618 Simple redirections of standard error do not affect the output of the
4622 .Dl $ time sleep 1 2\*(Gtafile
4623 .Dl $ { time sleep 1; } 2\*(Gtafile
4625 Times for the first command do not go to
4627 but those of the second command do.
4630 Print the accumulated user and system times used both by the shell
4631 and by processes that the shell started which have exited.
4632 The format of the output is:
4633 .Bd -literal -offset indent
4638 .It Ic trap Op Ar handler signal ...
4639 Sets a trap handler that is to be executed when any of the specified signals are
4644 string, indicating the signals are to be ignored, a minus sign
4646 indicating that the default action is to be taken for the signals (see
4648 or a string containing shell commands to be evaluated and executed at the first
4649 opportunity (i.e. when the current command completes, or before printing the
4652 prompt) after receipt of one of the signals.
4654 is the name of a signal (e.g.\&
4658 or the number of the signal (see the
4662 There are two special signals:
4664 (also known as 0) which is executed when the shell is about to exit, and
4666 which is executed after an error occurs (an error is something that would cause
4667 the shell to exit if the
4671 option were set \*(en see the
4675 handlers are executed in the environment of the last executed command.
4677 that for non-interactive shells, the trap handler cannot be changed for signals
4678 that were ignored when the shell started.
4682 lists, as a series of
4684 commands, the current state of the traps that have been set since the shell
4686 Note that the output of
4688 cannot be usefully piped to another process (an artifact of the fact that
4689 traps are cleared when subprocesses are created).
4691 The original Korn shell's
4693 trap and the handling of
4697 traps in functions are not yet implemented.
4700 A command that exits with a zero value.
4704 .Oo Op Ic +\-alpnrtUux
4709 .No \*(Ba Fl f Op Fl tux Oc
4711 .Op Ns = Ns Ar value
4716 .Oo Op Ic +\-alpnrtUux
4717 .Op Fl LRZ Ns Op Ar n
4719 .No \*(Ba Fl f Op Fl tux Oc
4721 .Op Ns = Ns Ar value
4724 Display or set parameter attributes.
4727 arguments, parameter attributes are displayed; if no options are used, the
4728 current attributes of all parameters are printed as
4730 commands; if an option is given (or
4732 with no option letter), all parameters and their values with the specified
4733 attributes are printed; if options are introduced with
4735 parameter values are not printed.
4739 arguments are given, the attributes of the named parameters are set
4743 Values for parameters may optionally be specified.
4746 the change affects the entire array, and no value may be specified.
4750 is used inside a function, any parameters specified are localised.
4751 This is not done by the otherwise identical
4758 equivalent to other programming languages' as it does not allow a
4759 function called from another function to access a parameter at truly
4760 global scope, but only prevents putting an accessed one into local scope.
4766 operates on the attributes of functions.
4767 As with parameters, if no
4769 arguments are given,
4770 functions are listed with their values (i.e. definitions) unless
4771 options are introduced with
4773 in which case only the function names are reported.
4776 Indexed array attribute.
4779 Display or set functions and their attributes, instead of parameters.
4783 specifies the base to use when displaying the integer (if not specified, the
4784 base given in the first assignment is used).
4785 Parameters with this attribute may
4786 be assigned values containing arithmetic expressions.
4788 Left justify attribute.
4790 specifies the field width.
4793 is not specified, the current width of a parameter (or the width of its first
4794 assigned value) is used.
4795 Leading whitespace (and zeros, if used with the
4797 option) is stripped.
4798 If necessary, values are either truncated or space padded
4799 to fit the field width.
4801 Lower case attribute.
4802 All upper case characters in values are converted to lower case.
4803 (In the original Korn shell, this parameter meant
4809 Create a bound variable (name reference): any access to the variable
4811 will access the variable
4813 in the current scope (this is different from
4822 is lazily evaluated at the time
4825 This can be used by functions to access variables whose names are
4826 passed as parametres, instead of using
4831 commands that can be used to re-create the attributes and values of
4834 Right justify attribute.
4836 specifies the field width.
4839 is not specified, the current width of a parameter (or the width of its first
4840 assigned value) is used.
4841 Trailing whitespace is stripped.
4842 If necessary, values are either stripped of leading characters or space
4843 padded to make them fit the field width.
4845 Read-only attribute.
4846 Parameters with this attribute may not be assigned to or unset.
4847 Once this attribute is set, it cannot be turned off.
4850 Has no meaning to the shell; provided for application use.
4854 is the trace attribute.
4855 When functions with the trace attribute are executed, the
4858 shell option is temporarily turned on.
4860 Unsigned integer attribute.
4861 Integers are printed as unsigned values (combine with the
4864 This option is not in the original Korn shell.
4866 Upper case attribute.
4867 All lower case characters in values are converted to upper case.
4868 (In the original Korn shell, this parameter meant
4869 .Dq unsigned integer
4872 option which meant upper case letters would never be used for bases greater
4880 is the undefined attribute.
4883 above for the implications of this.
4886 Parameters (or functions) are placed in the environment of
4887 any executed commands.
4888 Exported functions are not yet implemented.
4890 Zero fill attribute.
4891 If not combined with
4895 except zero padding is used instead of space padding.
4896 For integers, the number instead of the base is padded.
4909 options are changed, all others from this set are cleared,
4910 unless they are also given on the same command line.
4914 .Op Fl aBCcdefHilMmnOPpqrSsTtVvw
4917 Display or set process limits.
4918 If no options are used, the file size limit
4922 if specified, may be either an arithmetic expression or the word
4924 The limits affect the shell and any processes created by the shell after a
4926 Note that some systems may not allow limits to be increased
4928 Also note that the types of limits available are system
4929 dependent \*(en some systems have only the
4934 Display all limits; unless
4936 is used, soft limits are displayed.
4938 Set the socket buffer size to
4942 Set the number of cached threads to
4945 Impose a size limit of
4947 blocks on the size of core dumps.
4949 Impose a size limit of
4951 kibibytes on the size of the data area.
4953 Set the maximum niceness to
4956 Impose a size limit of
4958 blocks on files written by the shell and its child processes (files of any
4961 Set the hard limit only (the default is to set both hard and soft limits).
4963 Set the number of pending signals to
4968 kibibytes on the amount of locked (wired) physical memory.
4970 Set the AIO locked memory to
4976 kibibytes on the amount of physical memory used.
4980 file descriptors that can be open at once.
4982 Set the number of AIO operations to
4985 Limit the number of threads per process to
4990 processes that can be run by the user at any one time.
4998 Set the maximum real-time priority to
5001 Set the soft limit only (the default is to set both hard and soft limits).
5003 Impose a size limit of
5005 kibibytes on the size of the stack area.
5007 Impose a time limit of
5009 real seconds to be used by each process.
5011 Impose a time limit of
5013 CPU seconds spent in user mode to be used by each process.
5015 Set the number of vnode monitors on Haiku to
5020 kibibytes on the amount of virtual memory (address space) used.
5024 kibibytes on the amount of swap space used.
5029 is concerned, a block is 512 bytes.
5036 Display or set the file permission creation mask, or umask (see
5040 option is used, the mask displayed or set is symbolic; otherwise, it is an
5043 Symbolic masks are like those used by
5045 When used, they describe what permissions may be made available (as opposed to
5046 octal masks in which a set bit means the corresponding bit is to be cleared).
5049 sets the mask so files will not be readable, writable, or executable by
5051 and is equivalent (on most systems) to the octal mask
5059 The aliases for the given names are removed.
5062 option is used, all aliases are removed.
5067 options are used, the indicated operations are carried out on tracked or
5068 directory aliases, respectively.
5075 Unset the named parameters
5083 .Ar parameter Ns \&[*] ,
5084 attributes are kept, only values are unset.
5086 The exit status is non-zero if any of the parameters have the read-only
5087 attribute set, zero otherwise.
5089 .It Ic wait Op Ar job ...
5090 Wait for the specified job(s) to finish.
5093 is that of the last specified job; if the last job is killed by a signal, the
5094 exit status is 128 + the number of the signal (see
5095 .Ic kill \-l Ar exit-status
5096 above); if the last specified job can't be found (because it never existed, or
5097 had already finished), the exit status of
5102 below for the format of
5105 will return if a signal for which a trap has been set is received, or if a
5112 If no jobs are specified,
5114 waits for all currently running jobs (if any) to finish and exits with a zero
5116 If job monitoring is enabled, the completion status of jobs is printed
5117 (this is not the case when jobs are explicitly specified).
5126 the type of command is listed (reserved word, built-in, alias,
5127 function, tracked alias, or executable).
5130 option is used, a path search is performed even if
5132 is a reserved word, alias, etc.
5141 will find reserved words and won't print aliases as alias commands.
5152 option does not affect the search path used, as it does for
5154 If the type of one or more of the names could not be determined, the exit
5158 Job control refers to the shell's ability to monitor and control jobs which
5159 are processes or groups of processes created for commands or pipelines.
5160 At a minimum, the shell keeps track of the status of the background (i.e.\&
5161 asynchronous) jobs that currently exist; this information can be displayed
5165 If job control is fully enabled (using
5168 .Ic set \-o monitor ) ,
5169 as it is for interactive shells, the processes of a job are placed in their
5171 Foreground jobs can be stopped by typing the suspend
5172 character from the terminal (normally \*(haZ), jobs can be restarted in either the
5173 foreground or background using the
5177 commands, and the state of the terminal is saved or restored when a foreground
5178 job is stopped or restarted, respectively.
5180 Note that only commands that create processes (e.g. asynchronous commands,
5181 subshell commands, and non-built-in, non-function commands) can be stopped;
5186 When a job is created, it is assigned a job number.
5187 For interactive shells, this number is printed inside
5189 followed by the process IDs of the processes in the job when an asynchronous
5191 A job may be referred to in the
5198 commands either by the process ID of the last process in the command pipeline
5201 parameter) or by prefixing the job number with a percent
5204 Other percent sequences can also be used to refer to jobs:
5205 .Bl -tag -width "%+ x %% x %XX"
5206 .It %+ \*(Ba %% \*(Ba %
5207 The most recently stopped job, or, if there are no stopped jobs, the oldest
5210 The job that would be the
5212 job if the latter did not exist.
5214 The job with job number
5217 The job with its command containing the string
5219 (an error occurs if multiple jobs are matched).
5221 The job with its command starting with the string
5223 (an error occurs if multiple jobs are matched).
5226 When a job changes state (e.g. a background job finishes or foreground job is
5227 stopped), the shell prints the following status information:
5229 .D1 [ Ns Ar number ] Ar flag status command
5232 .Bl -tag -width "command"
5234 is the job number of the job;
5240 character if the job is the
5244 job, respectively, or space if it is neither;
5246 indicates the current state of the job and can be:
5247 .Bl -tag -width "RunningXX"
5248 .It Done Op Ar number
5251 is the exit status of the job which is omitted if the status is zero.
5253 The job has neither stopped nor exited (note that running does not necessarily
5254 mean consuming CPU time \*(en
5255 the process could be blocked waiting for some event).
5256 .It Stopped Op Ar signal
5257 The job was stopped by the indicated
5259 (if no signal is given, the job was stopped by
5261 .It Ar signal-description Op Dq core dumped
5262 The job was killed by a signal (e.g. memory fault, hangup); use
5264 for a list of signal descriptions.
5267 message indicates the process created a core file.
5270 is the command that created the process.
5271 If there are multiple processes in
5272 the job, each process will have a line showing its
5276 if it is different from the status of the previous process.
5279 When an attempt is made to exit the shell while there are jobs in the stopped
5280 state, the shell warns the user that there are stopped jobs and does not exit.
5281 If another attempt is immediately made to exit the shell, the stopped jobs are
5284 signal and the shell exits.
5287 option is not set and there are running jobs when an attempt is made to exit
5288 a login shell, the shell warns the user and does not exit.
5290 is immediately made to exit the shell, the running jobs are sent a
5292 signal and the shell exits.
5293 .Ss Interactive input line editing
5294 The shell supports three modes of reading command lines from a
5296 in an interactive session, controlled by the
5301 options (at most one of these can be set at once).
5304 Editing modes can be set explicitly using the
5307 If none of these options are enabled,
5308 the shell simply reads lines using the normal
5315 option is set, the shell allows emacs-like editing of the command; similarly,
5318 option is set, the shell allows vi-like editing of the command.
5319 These modes are described in detail in the following sections.
5321 In these editing modes, if a line is longer than the screen width (see the
5329 character is displayed in the last column indicating that there are more
5330 characters after, before and after, or before the current position,
5332 The line is scrolled horizontally as necessary.
5334 Completed lines are pushed into the history, unless they begin with an
5335 IFS octet or IFS white space, or are the same as the previous line.
5336 .Ss Emacs editing mode
5339 option is set, interactive input line editing is enabled.
5340 Warning: This mode is
5341 slightly different from the emacs mode in the original Korn shell.
5342 In this mode, various editing commands
5343 (typically bound to one or more control characters) cause immediate actions
5344 without waiting for a newline.
5345 Several editing commands are bound to particular
5346 control characters when the shell is invoked; these bindings can be changed
5351 The following is a list of available editing commands.
5352 Each description starts with the name of the command,
5353 suffixed with a colon;
5356 (if the command can be prefixed with a count); and any keys the command is
5357 bound to by default, written using caret notation
5358 e.g. the ASCII ESC character is written as \*(ha[.
5359 These control sequences are not case sensitive.
5360 A count prefix for a command is entered using the sequence
5361 .Pf \*(ha[ Ns Ar n ,
5364 is a sequence of 1 or more digits.
5365 Unless otherwise specified, if a count is
5366 omitted, it defaults to 1.
5368 Note that editing command names are used only with the
5371 Furthermore, many editing commands are useful only on terminals with
5373 The default bindings were chosen to resemble corresponding
5380 reasonable substitutes and override the default bindings.
5382 .It abort: \*(haC, \*(haG
5383 Abort the current command, empty the line buffer and
5384 set the exit state to interrupted.
5385 .It auto\-insert: Op Ar n
5386 Simply causes the character to appear as literal input.
5387 Most ordinary characters are bound to this.
5388 .It Xo backward\-char:
5390 .No \*(haB , \*(haXD , ANSI-CurLeft
5392 Moves the cursor backward
5395 .It Xo backward\-word:
5397 .No \*(ha[b , ANSI-Ctrl-CurLeft , ANSI-Alt-CurLeft
5399 Moves the cursor backward to the beginning of the word; words consist of
5400 alphanumerics, underscore
5405 .It beginning\-of\-history: \*(ha[\*(Lt
5406 Moves to the beginning of the history.
5407 .It beginning\-of\-line: \*(haA, ANSI-Home
5408 Moves the cursor to the beginning of the edited input line.
5409 .It Xo capitalise\-word:
5411 .No \*(ha[C , \*(ha[c
5413 Uppercase the first character in the next
5415 words, leaving the cursor past the end of the last word.
5416 .It clear\-screen: \*(ha[\*(haL
5417 Prints a compile-time configurable sequence to clear the screen and home
5418 the cursor, redraws the entire prompt and the currently edited input line.
5419 The default sequence works for almost all standard terminals.
5420 .It comment: \*(ha[#
5421 If the current line does not begin with a comment character, one is added at
5422 the beginning of the line and the line is entered (as if return had been
5423 pressed); otherwise, the existing comment characters are removed and the cursor
5424 is placed at the beginning of the line.
5425 .It complete: \*(ha[\*(ha[
5426 Automatically completes as much as is unique of the command name or the file
5427 name containing the cursor.
5428 If the entire remaining command or file name is
5429 unique, a space is printed after its completion, unless it is a directory name
5433 If there is no command or file name with the current partial word
5434 as its prefix, a bell character is output (usually causing a beep to be
5436 .It complete\-command: \*(haX\*(ha[
5437 Automatically completes as much as is unique of the command name having the
5438 partial word up to the cursor as its prefix, as in the
5441 .It complete\-file: \*(ha[\*(haX
5442 Automatically completes as much as is unique of the file name having the
5443 partial word up to the cursor as its prefix, as in the
5445 command described above.
5446 .It complete\-list: \*(haI, \*(ha[=
5447 Complete as much as is possible of the current word,
5448 and list the possible completions for it.
5449 If only one completion is possible,
5453 Note that \*(haI is usually generated by the TAB (tabulator) key.
5454 .It Xo delete\-char\-backward:
5456 .No ERASE , \*(ha? , \*(haH
5460 characters before the cursor.
5461 .It Xo delete\-char\-forward:
5467 characters after the cursor.
5468 .It Xo delete\-word\-backward:
5470 .No WERASE , \*(ha[\*(ha? , \*(ha[\*(haH , \*(ha[h
5474 words before the cursor.
5475 .It Xo delete\-word\-forward:
5479 Deletes characters after the cursor up to the end of
5482 .It Xo down\-history:
5484 .No \*(haN , \*(haXB , ANSI-CurDown
5486 Scrolls the history buffer forward
5489 Each input line originally starts just after the last entry
5490 in the history buffer, so
5492 is not useful until either
5493 .Ic search\-history ,
5494 .Ic search\-history\-up
5498 .It Xo downcase\-word:
5500 .No \*(ha[L , \*(ha[l
5511 or the current line, if not specified, interactively.
5512 The actual command executed is
5513 .Ic fc \-e ${VISUAL:\-${EDITOR:\-vi}} Ar n .
5514 .It end\-of\-history: \*(ha[\*(Gt
5515 Moves to the end of the history.
5516 .It end\-of\-line: \*(haE, ANSI-End
5517 Moves the cursor to the end of the input line.
5519 Acts as an end-of-file; this is useful because edit-mode input disables
5520 normal terminal input canonicalization.
5521 .It Xo eot\-or\-delete:
5527 if alone on a line; otherwise acts as
5528 .Ic delete\-char\-forward .
5529 .It error: (not bound)
5530 Error (ring the bell).
5531 .It exchange\-point\-and\-mark: \*(haX\*(haX
5532 Places the cursor where the mark is and sets the mark to where the cursor was.
5533 .It expand\-file: \*(ha[*
5536 to the current word and replaces the word with the result of performing file
5537 globbing on the word.
5538 If no files match the pattern, the bell is rung.
5539 .It Xo forward\-char:
5541 .No \*(haF , \*(haXC , ANSI-CurRight
5543 Moves the cursor forward
5546 .It Xo forward\-word:
5548 .No \*(ha[f , ANSI-Ctrl-CurRight , ANSI-Alt-CurRight
5550 Moves the cursor forward to the end of the
5553 .It Xo goto\-history:
5557 Goes to history number
5559 .It kill\-line: KILL
5560 Deletes the entire input line.
5561 .It kill\-region: \*(haW
5562 Deletes the input between the cursor and the mark.
5563 .It Xo kill\-to\-eol:
5567 Deletes the input from the cursor to the end of the line if
5569 is not specified; otherwise deletes characters between the cursor and column
5572 Prints a sorted, columnated list of command names or file names (if any) that
5573 can complete the partial word containing the cursor.
5574 Directory names have
5577 .It list\-command: \*(haX?
5578 Prints a sorted, columnated list of command names (if any) that can complete
5579 the partial word containing the cursor.
5580 .It list\-file: \*(haX\*(haY
5581 Prints a sorted, columnated list of file names (if any) that can complete the
5582 partial word containing the cursor.
5583 File type indicators are appended as described under
5586 .It newline: \*(haJ , \*(haM
5587 Causes the current input line to be processed by the shell.
5588 The current cursor position may be anywhere on the line.
5589 .It newline\-and\-next: \*(haO
5590 Causes the current input line to be processed by the shell, and the next line
5591 from history becomes the current line.
5592 This is only useful after an
5596 .Ic search\-history\-up .
5599 .It prefix\-1: \*(ha[
5600 Introduces a 2-character command sequence.
5601 .It prefix\-2: \*(haX , \*(ha[[ , \*(ha[O
5602 Introduces a 2-character command sequence.
5603 .It Xo prev\-hist\-word:
5605 .No \*(ha[. , \*(ha[_
5607 The last word, or, if given, the
5609 word (zero-based) of the previous (on repeated execution, second-last,
5610 third-last, etc.) command is inserted at the cursor.
5611 Use of this editing command trashes the mark.
5612 .It quote: \*(ha\*(ha , \*(haV
5613 The following character is taken literally rather than as an editing command.
5615 Reprints the last line of the prompt string and the current input line
5617 .It Xo search\-character\-backward:
5621 Search backward in the current line for the
5623 occurrence of the next character typed.
5624 .It Xo search\-character\-forward:
5628 Search forward in the current line for the
5630 occurrence of the next character typed.
5631 .It search\-history: \*(haR
5632 Enter incremental search mode.
5633 The internal history list is searched
5634 backwards for commands matching the input.
5637 in the search string anchors the search.
5638 The escape key will leave search mode.
5639 Other commands, including sequences of escape as
5645 key will be executed after leaving search mode.
5648 command will restore the input line before search started.
5651 commands continue searching backward to the next previous occurrence of the
5653 The history buffer retains only a finite number of lines; the oldest
5654 are discarded as necessary.
5655 .It search\-history\-up: ANSI-PgUp
5656 Search backwards through the history buffer for commands whose beginning match
5657 the portion of the input line before the cursor.
5658 When used on an empty line, this has the same effect as
5660 .It search\-history\-down: ANSI-PgDn
5661 Search forwards through the history buffer for commands whose beginning match
5662 the portion of the input line before the cursor.
5663 When used on an empty line, this has the same effect as
5665 This is only useful after an
5669 .Ic search\-history\-up .
5670 .It set\-mark\-command: \*(ha[ Ns Aq space
5671 Set the mark at the cursor position.
5672 .It transpose\-chars: \*(haT
5673 If at the end of line, or if the
5675 option is set, this exchanges the two previous characters; otherwise, it
5676 exchanges the previous and current characters and moves the cursor one
5677 character to the right.
5680 .No \*(haP , \*(haXA , ANSI-CurUp
5682 Scrolls the history buffer backward
5685 .It Xo upcase\-word:
5687 .No \*(ha[U , \*(ha[u
5692 .It version: \*(ha[\*(haV
5693 Display the version of
5695 The current edit buffer is restored as soon as a key is pressed.
5696 The restoring keypress is processed, unless it is a space.
5698 Inserts the most recently killed text string at the current cursor position.
5699 .It yank\-pop: \*(ha[y
5702 replaces the inserted text string with the next previously killed text string.
5706 The vi command-line editing mode is orphaned, yet still functional.
5707 It is 8-bit clean but specifically does not support UTF-8 or MBCS.
5709 The vi command-line editor in
5711 has basically the same commands as the
5713 editor with the following exceptions:
5716 You start out in insert mode.
5718 There are file name and command completion commands:
5719 =, \e, *, \*(haX, \*(haE, \*(haF, and, optionally,
5726 command is different (in
5728 it is the last argument command; in
5730 it goes to the start of the current line).
5736 commands move in the opposite direction to the
5740 Commands which don't make sense in a single line editor are not available
5741 (e.g. screen movement commands and
5750 there are two modes:
5755 In insert mode, most characters are simply put in the buffer at the
5756 current cursor position as they are typed; however, some characters are
5758 In particular, the following characters are taken from current
5763 and have their usual meaning (normal values are in parentheses): kill (\*(haU),
5764 erase (\*(ha?), werase (\*(haW), eof (\*(haD), intr (\*(haC), and quit (\*(ha\e).
5766 the above, the following characters are also treated specially in insert mode:
5767 .Bl -tag -width XJXXXXM
5769 Command and file name enumeration (see below).
5771 Command and file name completion (see below).
5772 If used twice in a row, the
5773 list of possible completions is displayed; if used a third time, the completion
5776 Erases previous character.
5777 .It \*(haJ \*(Ba \*(haM
5779 The current line is read, parsed, and executed by the shell.
5782 The next character typed is not treated specially (can be used
5783 to insert the characters being described here).
5785 Command and file name expansion (see below).
5787 Puts the editor in command mode (see below).
5789 Optional file name and command completion (see
5791 above), enabled with
5792 .Ic set \-o vi\-tabcomplete .
5795 In command mode, each character is interpreted as a command.
5797 don't correspond to commands, are illegal combinations of commands, or are
5798 commands that can't be carried out, all cause beeps.
5799 In the following command descriptions, an
5801 indicates the command may be prefixed by a number (e.g.\&
5803 moves right 10 characters); if no number prefix is used,
5805 is assumed to be 1 unless otherwise specified.
5807 .Dq current position
5808 refers to the position between the cursor and the character preceding the
5812 is a sequence of letters, digits, and underscore characters or a sequence of
5813 non-letter, non-digit, non-underscore, and non-whitespace characters (e.g.\&
5815 contains two words) and a
5817 is a sequence of non-whitespace characters.
5823 The following commands are not in, or are different from, the normal vi file
5829 Insert a space followed by the
5831 big-word from the last command in the history at the current position and enter
5834 is not specified, the last word is inserted.
5836 Insert the comment character
5838 at the start of the current line and return the line to the shell (equivalent
5848 is not specified, it goes to the most recent remembered line.
5858 is not specified, the current line is edited.
5859 The actual command executed is
5860 .Ic fc \-e ${VISUAL:\-${EDITOR:\-vi}} Ar n .
5862 Command or file name expansion is applied to the current big-word (with an
5865 if the word contains no file globbing characters) \*(en the big-word is replaced
5866 with the resulting words.
5867 If the current big-word is the first on the line
5868 or follows one of the characters
5875 and does not contain a slash
5877 then command expansion is done; otherwise file name expansion is done.
5878 Command expansion will match the big-word against all aliases, functions, and
5879 built-in commands as well as any executable files found by searching the
5883 File name expansion matches the big-word against the files in the
5885 After expansion, the cursor is placed just past the last
5886 word and the editor is in insert mode.
5889 .Oo Ar n Oc Ns \*(haF ,
5890 .Oo Ar n Oc Ns Aq tab ,
5892 .Oo Ar n Oc Ns Aq esc
5894 Command/file name completion.
5895 Replace the current big-word with the
5896 longest unique match obtained after performing command and file name expansion.
5898 is only recognised if the
5900 option is set, while
5902 is only recognised if the
5910 possible completion is selected (as reported by the command/file name
5911 enumeration command).
5913 Command/file name enumeration.
5914 List all the commands or files that match the current big-word.
5916 Display the version of
5918 The current edit buffer is restored as soon as a key is pressed.
5919 The restoring keypress is ignored.
5922 Execute the commands found in the alias
5926 Intra-line movement commands:
5929 .Oo Ar n Oc Ns h and
5930 .Oo Ar n Oc Ns \*(haH
5936 .Oo Ar n Oc Ns l and
5937 .Oo Ar n Oc Ns Aq space
5945 Move to the first non-whitespace character.
5947 .Oo Ar n Oc Ns \*(Ba
5952 Move to the last character.
5968 Move forward to the end of the word,
5974 Move forward to the end of the big-word,
5991 The editor looks forward for the nearest parenthesis, bracket, or
5992 brace and then moves the cursor to the matching parenthesis, bracket, or brace.
5994 .Oo Ar n Oc Ns f Ns Ar c
5998 occurrence of the character
6001 .Oo Ar n Oc Ns F Ns Ar c
6003 Move backward to the
6005 occurrence of the character
6008 .Oo Ar n Oc Ns t Ns Ar c
6010 Move forward to just before the
6012 occurrence of the character
6015 .Oo Ar n Oc Ns T Ns Ar c
6017 Move backward to just before the
6019 occurrence of the character
6036 command, but moves in the opposite direction.
6039 Inter-line movement commands:
6045 .Oo Ar n Oc Ns \*(haN
6049 next line in the history.
6054 .Oo Ar n Oc Ns \*(haP
6058 previous line in the history.
6066 is not specified, the number of the first remembered line is used.
6074 is not specified, it goes to the most recent remembered line.
6076 .Oo Ar n Oc Ns / Ns Ar string
6078 Search backward through the history for the
6086 the remainder of the string must appear at the start of the history line for
6089 .Oo Ar n Oc Ns \&? Ns Ar string
6093 except it searches forward through the history.
6099 occurrence of the last search string;
6100 the direction of the search is the same as the last search.
6106 occurrence of the last search string;
6107 the direction of the search is the opposite of the last search.
6109 Take the characters from the beginning of the line to the current
6110 cursor position as search string and do a backwards history search
6111 for lines beginning with this string; keep the cursor position.
6112 This works only in insert mode and keeps it enabled.
6122 times; goes into insert mode just after the current position.
6124 only replicated if command mode is re-entered i.e.\&
6132 except it appends at the end of the line.
6138 times; goes into insert mode at the current position.
6139 The insertion is only
6140 replicated if command mode is re-entered i.e.\&
6148 except the insertion is done just before the first non-blank character.
6154 characters (i.e. delete the characters and go into insert mode).
6156 Substitute whole line.
6157 All characters from the first non-blank character to the
6158 end of the line are deleted and insert mode is entered.
6160 .Oo Ar n Oc Ns c Ns Ar move-cmd
6162 Change from the current position to the position resulting from
6164 (i.e. delete the indicated region and go into insert mode); if
6168 the line starting from the first non-blank character is changed.
6170 Change from the current position to the end of the line (i.e. delete to the
6171 end of the line and go into insert mode).
6185 Delete to the end of the line.
6187 .Oo Ar n Oc Ns d Ns Ar move-cmd
6189 Delete from the current position to the position resulting from
6190 .Ar n move-cmd Ns s ;
6192 is a movement command (see above) or
6194 in which case the current line is deleted.
6196 .Oo Ar n Oc Ns r Ns Ar c
6200 characters with the character
6206 Enter insert mode but overwrite existing characters instead of
6207 inserting before existing characters.
6208 The replacement is repeated
6212 .Oo Ar n Oc Ns \*(TI
6214 Change the case of the next
6218 .Oo Ar n Oc Ns y Ns Ar move-cmd
6220 Yank from the current position to the position resulting from
6222 into the yank buffer; if
6226 the whole line is yanked.
6228 Yank from the current position to the end of the line.
6232 Paste the contents of the yank buffer just after the current position,
6240 except the buffer is pasted at the current position.
6243 Miscellaneous vi commands
6245 .It \*(haJ and \*(haM
6246 The current line is read, parsed, and executed by the shell.
6247 .It \*(haL and \*(haR
6248 Redraw the current line.
6252 Redo the last edit command
6256 Undo the last edit command.
6258 Undo all changes that have been made to the current line.
6259 .It Ar intr No and Ar quit
6260 The interrupt and quit terminal characters cause the current line to be
6261 deleted and a new prompt to be printed.
6264 .Bl -tag -width XetcXsuid_profile -compact
6265 .It Pa \*(TI/.mkshrc
6266 User mkshrc profile (non-privileged interactive shells); see
6268 The location can be changed at compile time (for embedded systems);
6269 AOSP Android builds use
6270 .Pa /system/etc/mkshrc .
6271 .It Pa \*(TI/.profile
6272 User profile (non-privileged login shells); see
6274 near the top of this manual.
6276 System profile (login shells); see
6280 .It Pa /etc/suid_profile
6281 Suid profile (privileged shells); see
6287 contains the system and suid profile.
6318 .Pa http://docsrv.sco.com:507/en/man/html.C/sh.C.html
6320 .Pa https://www.mirbsd.org/ksh\-chan.htm
6323 .%B "The KornShell Command and Programming Language"
6325 .%I "Prentice Hall PTR"
6326 .%P "xvi\ +\ 356 pages"
6327 .%O "ISBN 978\-0\-13\-516972\-8 (0\-13\-516972\-0)"
6330 .%A Morris I. Bolsky
6332 .%B "The New KornShell Command and Programming Language (2nd Edition)"
6334 .%I "Prentice Hall PTR"
6335 .%P "xvi\ +\ 400 pages"
6336 .%O "ISBN 978\-0\-13\-182700\-4 (0\-13\-182700\-6)"
6339 .%A Stephen G. Kochan
6341 .%B "\\*(tNUNIX\\*(sP Shell Programming"
6345 .%P "xiii\ +\ 437 pages"
6346 .%O "ISBN 978\-0\-672\-32490\-1 (0\-672\-32490\-3)"
6350 .%T "\\*(tNIEEE\\*(sP Standard for Information Technology \*(en Portable Operating System Interface (POSIX)"
6351 .%V "Part 2: Shell and Utilities"
6354 .%P "xvii\ +\ 1195 pages"
6355 .%O "ISBN 978\-1\-55937\-255\-8 (1\-55937\-255\-9)"
6359 .%B "Learning the Korn Shell"
6363 .%O "ISBN 978\-1\-56592\-054\-5 (1\-56592\-054\-6)"
6368 .%B "Learning the Korn Shell, Second Edition"
6372 .%O "ISBN 978\-0\-596\-00195\-7 (0\-596\-00195\-9)"
6376 .%B "KornShell Programming Tutorial"
6378 .%I "Addison-Wesley Professional"
6379 .%P "xxi\ +\ 324 pages"
6380 .%O "ISBN 978\-0\-201\-56324\-5 (0\-201\-56324\-X)"
6384 .Nm "The MirBSD Korn Shell"
6386 .An Thorsten Glaser Aq tg@mirbsd.org
6387 and currently maintained as part of The MirOS Project.
6388 This shell is based on the public domain 7th edition Bourne shell clone by
6389 .An Charles Forsyth ,
6390 who kindly agreed to, in countries where the Public Domain status of the work
6391 may not be valid, grant a copyright licence to the general public to deal in
6392 the work without restriction and permission to sublicence derivates under the
6393 terms of any (OSI approved) Open Source licence,
6394 and parts of the BRL shell by
6398 .An Arnold Robbins ,
6401 The first release of
6405 and it was subsequently maintained by
6406 .An John R. MacMillan Aq Mt change!john@sq.sq.com ,
6407 .An Simon J. Gerraty Aq Mt sjg@zen.void.oz.au ,
6409 .An Michael Rendell Aq Mt michael@cs.mun.ca .
6410 The effort of several projects, such as Debian and OpenBSD, and other
6411 contributors including our users, to improve the shell is appreciated.
6412 See the documentation, CVS, and web site for details.
6414 The BSD daemon is Copyright \(co Marshall Kirk McKusick.
6415 The complete legalese is at:
6416 .Pa https://www.mirbsd.org/TaC\-mksh.txt
6418 .\" This boils down to: feel free to use mksh.ico as application icon
6419 .\" or shortcut for mksh or mksh/Win32; distro patches are ok (but we
6420 .\" request they amend $KSH_VERSION when modifying mksh). Authors are
6421 .\" Marshall Kirk McKusick (UCB), Rick Collette (ekkoBSD), Thorsten
6422 .\" Glaser, Benny Siegert (MirBSD), Michael Langguth (mksh/Win32).
6424 .\" As far as MirBSD is concerned, the files themselves are free
6425 .\" to modification and distribution under BSD/MirOS Licence, the
6426 .\" restriction on use stems only from trademark law's requirement
6427 .\" to protect it or lose it, which McKusick almost did.
6431 only supports the Unicode BMP (Basic Multilingual Plane).
6434 has a different scope model from
6437 which leads to subtile differences in semantics for identical builtins.
6438 This can cause issues with a
6440 to suddenly point to a local variable by accident; fixing this is hard.
6442 The parts of a pipeline, like below, are executed in subshells.
6443 Thus, variable assignments inside them are not visible in the
6444 surrounding execution environment.
6445 Use co-processes instead.
6446 .Bd -literal -offset indent
6447 foo \*(Ba bar \*(Ba read baz # will not change $baz
6448 foo \*(Ba bar \*(Ba& read \-p baz # will, however, do so
6452 provides a consistent set of 32-bit integer arithmetics, both signed
6453 and unsigned, with defined wraparound and sign of the result of a
6454 remainder operation, even (defying POSIX) on 64-bit systems.
6455 If you require 64-bit integer arithmetics, use
6456 .Nm lksh Pq legacy mksh
6457 instead, but be aware that, in POSIX, it's legal for the OS to make
6458 .Li print $((2147483647 + 1))
6459 delete all files on your system, as it's Undefined Behaviour.
6461 Suspending (using \*(haZ) pipelines like the one below will only suspend
6462 the currently running part of the pipeline; in this example,
6464 is immediately printed on suspension (but not later after an
6466 .Bd -literal -offset indent
6467 $ /bin/sleep 666 && echo fubar
6470 This document attempts to describe
6473 compiled without any options impacting functionality, such as
6477 which, on some systems only, enables
6479 automatically (whose behaviour differs across targets),
6480 for an operating environment supporting all of its advanced needs.
6481 Please report bugs in
6486 .Aq miros\-mksh@mirbsd.org
6491 .Pa irc.freenode.net
6492 .Pq Port 6697 SSL, 6667 unencrypted ,
6494 .Pa https://launchpad.net/mksh