1 .\" $MirOS: src/bin/mksh/mksh.1,v 1.388 2016/01/20 22:04:54 tg Exp $
2 .\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $
4 .\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
5 .\" 2010, 2011, 2012, 2013, 2014, 2015, 2016
6 .\" mirabilos <m@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: January 20 2016 $
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 At times, this manual page may give scripting advice; while it
183 sometimes does take portable shell scripting or various standards
184 into account all information is first and foremost presented with
186 in mind and should be taken as such.
187 .Ss I'm an Android user, so what's mksh?
191 shell / command interpreter, similar to
195 which has been included with
196 .Tn Android Open Source Project
198 Basically, it's a program that runs in a terminal (console window),
199 takes user input and runs commands or scripts, which it can also
200 be asked to do by other programs, even in the background.
201 Any privilege pop-ups you might be encountering are thus not
203 issues but questions by some other program utilising it.
205 Most builtins can be called directly, for example if a link points from its
206 name to the shell; not all make sense, have been tested or work at all though.
208 The options are as follows:
209 .Bl -tag -width XcXstring
212 will execute the command(s) contained in
216 A shell that reads commands from standard input is
219 option is used or if both standard input and standard error are attached
222 An interactive shell has job control enabled, ignores the
227 signals, and prints prompts before reading input (see the
232 It also processes the
237 For non-interactive shells, the
239 option is on by default (see the
244 If the basename the shell is called with (i.e. argv[0])
247 or if this option is used,
248 the shell is assumed to be a login shell; see
255 if the real user ID or group ID does not match the
256 effective user ID or group ID (see
260 Clearing the privileged option causes the shell to set
261 its effective user ID (group ID) to its real user ID (group ID).
262 For further implications, see
264 If the shell is privileged and this flag is not explicitly set, the
266 option is cleared automatically after processing the startup files.
273 The following restrictions come into effect after the shell processes any
290 parameters cannot be changed.
292 Command names can't be specified with absolute or relative paths.
296 option of the built-in command
300 Redirections that create files can't be used (i.e.\&
307 The shell reads commands from standard input; all non-option arguments
308 are positional parameters.
317 .Pa /dev/ttyC Ns Ar name
319 .Pa /dev/tty Ns Ar name
320 are attempted in order.
323 begins with an exclamation mark
325 this is done in a subshell and returns immediately.
330 detach from controlling terminal (daemonise) instead.
333 In addition to the above, the options described in the
335 built-in command can also be used on the command line:
337 .Op Fl +abCefhkmnuvXx
340 can be used for single letter or long options, respectively.
346 option is specified, the first non-option argument specifies the name
347 of a file the shell reads commands from.
348 If there are no non-option
349 arguments, the shell reads commands from the standard input.
350 The name of the shell (i.e. the contents of $0)
351 is determined as follows: if the
353 option is used and there is a non-option argument, it is used as the name;
354 if commands are being read from a file, the file is used as the name;
355 otherwise, the basename the shell was called with (i.e. argv[0]) is used.
357 The exit status of the shell is 127 if the command file specified on the
358 command line could not be opened, or non-zero if a fatal syntax error
359 occurred during the execution of a script.
360 In the absence of fatal errors,
361 the exit status is that of the last command executed, or zero, if no
364 For the actual location of these files, see
366 A login shell processes the system profile first.
367 A privileged shell then processes the suid profile.
368 A non-privileged login shell processes the user profile next.
369 A non-privileged interactive shell checks the value of the
371 parameter after subjecting it to parameter, command, arithmetic and tilde
373 substitution; if unset or empty, the user mkshrc profile is processed;
374 otherwise, if a file whose name is the substitution result exists,
375 it is processed; non-existence is silently ignored.
376 A privileged shell then drops privileges if neither was the
378 option given on the command line nor set during execution of the startup files.
380 The shell begins parsing its input by removing any backslash-newline
381 combinations, then breaking it into
383 Words (which are sequences of characters) are delimited by unquoted whitespace
384 characters (space, tab, and newline) or meta-characters
395 Aside from delimiting words, spaces and tabs are ignored, while newlines
396 usually delimit commands.
397 The meta-characters are used in building the following
402 .Ql \*(Lt\*(Lt\*(Lt ,
407 etc. are used to specify redirections (see
408 .Sx Input/output redirection
411 is used to create pipelines;
413 is used to create co-processes (see
417 is used to separate commands;
419 is used to create asynchronous pipelines;
423 are used to specify conditional execution;
432 is used in arithmetic expressions;
435 is used to create subshells.
437 Whitespace and meta-characters can be quoted individually using a backslash
439 or in groups using double
444 Note that the following characters are also treated specially by the
445 shell and must be quoted if they are to represent themselves:
459 The first three of these are the above mentioned quoting characters (see
463 if used at the beginning of a word, introduces a comment \*(en everything after
466 up to the nearest newline is ignored;
468 is used to introduce parameter, command, and arithmetic substitutions (see
472 introduces an old-style command substitution (see
476 begins a directory expansion (see
492 are used in file name generation (see
493 .Sx File name patterns
496 As words and tokens are parsed, the shell builds commands, of which there
498 .Em simple-commands ,
499 typically programmes that are executed, and
500 .Em compound-commands ,
505 statements, grouping constructs, and function definitions.
507 A simple-command consists of some combination of parameter assignments
511 input/output redirections (see
512 .Sx Input/output redirections
514 and command words; the only restriction is that parameter assignments come
515 before any command words.
516 The command words, if any, define the command
517 that is to be executed and its arguments.
518 The command may be a shell built-in command, a function,
519 or an external command
520 (i.e. a separate executable file that is located using the
523 .Sx Command execution
525 Note that all command constructs have an exit status: for external commands,
526 this is related to the status returned by
528 (if the command could not be found, the exit status is 127; if it could not
529 be executed, the exit status is 126); the exit status of other command
530 constructs (built-in commands, functions, compound-commands, pipelines, lists,
531 etc.) are all well-defined and are described where the construct is
533 The exit status of a command consisting only of parameter
534 assignments is that of the last command substitution performed during the
535 parameter assignment or 0 if there were no command substitutions.
537 Commands can be chained together using the
539 token to form pipelines, in which the standard output of each command but the
542 to the standard input of the following command.
543 The exit status of a pipeline is that of its last command, unless the
545 option is set (see there).
546 All commands of a pipeline are executed in separate subshells;
547 this is allowed by POSIX but differs from both variants of
550 where all but the last command were executed in subshells; see the
552 builtin's description for implications and workarounds.
553 A pipeline may be prefixed by the
555 reserved word which causes the exit status of the pipeline to be logically
556 complemented: if the original status was 0, the complemented status will be 1;
557 if the original status was not 0, the complemented status will be 0.
560 of commands can be created by separating pipelines by any of the following
568 The first two are for conditional execution:
569 .Dq Ar cmd1 No && Ar cmd2
572 only if the exit status of
576 is the opposite \*(en
578 is executed only if the exit status of
584 have equal precedence which is higher than that of
589 which also have equal precedence.
595 .Qq left-associative .
596 For example, both of these commands will print only
598 .Bd -literal -offset indent
599 $ false && echo foo \*(Ba\*(Ba echo bar
600 $ true \*(Ba\*(Ba echo foo && echo bar
605 token causes the preceding command to be executed asynchronously; that is,
606 the shell starts the command but does not wait for it to complete (the shell
607 does keep track of the status of asynchronous commands; see
610 When an asynchronous command is started when job control is disabled
611 (i.e. in most scripts), the command is started with signals
615 ignored and with input redirected from
617 (however, redirections specified in the asynchronous command have precedence).
620 operator starts a co-process which is a special kind of asynchronous process
624 Note that a command must follow the
628 operators, while it need not follow
633 The exit status of a list is that of the last command executed, with the
634 exception of asynchronous lists, for which the exit status is 0.
636 Compound commands are created using the following reserved words.
638 are only recognised if they are unquoted and if they are used as the first
639 word of a command (i.e. they can't be preceded by parameter assignments or
641 .Bd -literal -offset indent
642 case else function then ! (
643 do esac if time [[ ((
645 elif for select while }
648 In the following compound command descriptions, command lists (denoted as
650 that are followed by reserved words must end with a semicolon, a newline, or
651 a (syntactically correct) reserved word.
652 For example, the following are all valid:
653 .Bd -literal -offset indent
654 $ { echo foo; echo bar; }
655 $ { echo foo; echo bar\*(Ltnewline\*(Gt}
656 $ { { echo foo; echo bar; } }
661 .Dl $ { echo foo; echo bar }
667 There is no implicit way to pass environment changes from a
668 subshell back to its parent.
672 is executed, but not in a subshell.
677 are reserved words, not meta-characters.
678 .It Xo case Ar word No in
689 statement attempts to match
695 associated with the first successfully matched pattern is executed.
698 statements are the same as those used for file name patterns except that the
699 restrictions regarding
704 Note that any unquoted space before and after a pattern is
705 stripped; any space within a pattern must be quoted.
706 Both the word and the
707 patterns are subject to parameter, command, and arithmetic substitution, as
708 well as tilde substitution.
710 For historical reasons, open and close braces may be used instead of
715 .Ic case $foo { *) echo bar ;; } .
722 Terminate after the list.
724 Fall through into the next list.
726 Evaluate the remaining pattern-list tuples.
731 statement is that of the executed
735 is executed, the exit status is zero.
737 .Oo in Ar word No ... Oc ;
738 .No do Ar list ; No done
742 in the specified word list, the parameter
744 is set to the word and
749 is not used to specify a word list, the positional parameters
752 For historical reasons, open and close braces may be used instead of
757 .Ic for i; { echo $i; } .
760 statement is the last exit status of
764 is never executed, the exit status is zero.
768 .No then Ar list ; Oc
770 .Oo else Ar list ; Oc
773 If the exit status of the first
777 is executed; otherwise, the
781 if any, is executed with similar consequences.
782 If all the lists following the
786 fail (i.e. exit with non-zero status), the
791 The exit status of an
793 statement is that of non-conditional
795 that is executed; if no non-conditional
797 is executed, the exit status is zero.
798 .It Xo select Ar name
799 .Oo in Ar word No ... Oc ;
800 .No do Ar list ; No done
804 statement provides an automatic method of presenting the user with a menu and
806 An enumerated list of the specified
808 is printed on standard error, followed by a prompt
813 A number corresponding to one of the enumerated words is then read from
816 is set to the selected word (or unset if the selection is not valid),
818 is set to what was read (leading/trailing space is stripped), and
821 If a blank line (i.e. zero or more
823 octets) is entered, the menu is reprinted without executing
828 completes, the enumerated list is printed if
832 the prompt is printed, and so on.
833 This process continues until an end-of-file
834 is read, an interrupt is received, or a
836 statement is executed inside the loop.
839 is omitted, the positional parameters are used
841 For historical reasons, open and close braces may be used instead of
846 .Ic select i; { echo $i; } .
849 statement is zero if a
851 statement is used to exit the loop, non-zero otherwise.
852 .It Xo until Ar list ;
858 except that the body is executed only while the exit status of the first
861 .It Xo while Ar list ;
867 is a pre-checked loop.
868 Its body is executed as often as the exit status of the first
873 statement is the last exit status of the
875 in the body of the loop; if the body is not executed, the exit status is zero.
876 .It Xo function Ar name
884 Note that redirections specified after a function definition are
885 performed whenever the function is executed, not when the function definition
887 .It Ar name Ns \&() Ar command
893 Whitespace (space or tab) after
895 will be ignored most of the time.
896 .It Xo function Ar name Ns \&()
905 .It Xo Ic time Op Fl p
909 .Sx Command execution
910 section describes the
913 .It \&(( Ar expression No ))
914 The arithmetic expression
916 is evaluated; equivalent to
919 .Sx Arithmetic expressions
922 command, below) in a compound construct.
923 .It Bq Bq Ar \ \&expression\ \&
928 commands (described later), with the following exceptions:
931 Field splitting and file name generation are not performed on arguments.
939 operators are replaced with
951 Parameter, command, and arithmetic substitutions are performed as expressions
952 are evaluated and lazy expression evaluation is used for the
957 This means that in the following statement,
959 is evaluated if and only if the file
961 exists and is readable:
962 .Bd -literal -offset indent
963 $ [[ \-r foo && $(\*(Ltfoo) = b*r ]]
966 The second operand of the
970 expressions are a subset of patterns (e.g. the comparison
971 .Ic \&[[ foobar = f*r ]]
973 This even works indirectly:
974 .Bd -literal -offset indent
975 $ bar=foobar; baz=\*(aqf*r\*(aq
976 $ [[ $bar = $baz ]]; echo $?
977 $ [[ $bar = \&"$baz" ]]; echo $?
980 Perhaps surprisingly, the first comparison succeeds,
981 whereas the second doesn't.
982 This does not apply to all extglob metacharacters, currently.
986 Quoting is used to prevent the shell from treating characters or words
988 There are three methods of quoting.
991 quotes the following character, unless it is at the end of a line, in which
994 and the newline are stripped.
995 Second, a single quote
997 quotes everything up to the next single quote (this may span lines).
998 Third, a double quote
1000 quotes all characters, except
1005 up to the next unquoted double quote.
1009 inside double quotes have their usual meaning (i.e. parameter, arithmetic,
1010 or command substitution) except no field splitting is carried out on the
1011 results of double-quoted substitutions.
1014 inside a double-quoted string is followed by
1020 it is replaced by the second character; if it is followed by a newline, both
1023 and the newline are stripped; otherwise, both the
1025 and the character following are unchanged.
1027 If a single-quoted string is preceded by an unquoted
1029 C style backslash expansion (see below) is applied (even single quote
1030 characters inside can be escaped and do not terminate the string then);
1031 the expanded result is treated as any other single-quoted string.
1032 If a double-quoted string is preceded by an unquoted
1037 .Ss Backslash expansion
1038 In places where backslashes are expanded, certain C and
1043 style escapes are translated.
1060 means a hexadecimal digit, of thich there may be none up to four or eight;
1061 these escapes translate a Unicode codepoint to UTF-8.
1066 expand to the escape character.
1075 are explicitly excluded;
1076 octal sequences must have the none up to three octal digits
1078 prefixed with the digit zero
1080 hexadecimal sequences
1082 are limited to none up to two hexadecimal digits
1084 both octal and hexadecimal sequences convert to raw octets;
1086 where # is none of the above, translates to \e# (backslashes are retained).
1088 Backslash expansion in the C style mode slightly differs: octal sequences
1090 must have no digit zero prefixing the one up to three octal digits
1092 and yield raw octets; hexadecimal sequences
1094 greedily eat up as many hexadecimal digits
1096 as they can and terminate with the first non-hexadecimal digit;
1097 these translate a Unicode codepoint to UTF-8.
1102 is any octet, translates to Ctrl-# (which basically means,
1104 becomes DEL, everything else is bitwise ANDed with 0x1F).
1107 where # is none of the above, translates to # (has the backslash trimmed),
1108 even if it is a newline.
1110 There are two types of aliases: normal command aliases and tracked aliases.
1111 Command aliases are normally used as a short hand for a long or often used
1113 The shell expands command aliases (i.e. substitutes the alias name
1114 for its value) when it reads the first word of a command.
1115 An expanded alias is re-processed to check for more aliases.
1116 If a command alias ends in a
1117 space or tab, the following word is also checked for alias expansion.
1118 The alias expansion process stops when a word that is not an alias is found,
1119 when a quoted word is found, or when an alias word that is currently being
1121 Aliases are specifically an interactive feature: while they do happen
1122 to work in scripts and on the command line in some cases, aliases are
1123 expanded during lexing, so their use must be in a separate command tree
1124 from their definition; otherwise, the alias will not be found.
1125 Noticeably, command lists (separated by semicolon, in command substitutions
1126 also by newline) may be one same parse tree.
1128 The following command aliases are defined automatically by the shell:
1129 .Bd -literal -offset indent
1130 autoload=\*(aq\etypeset \-fu\*(aq
1131 functions=\*(aq\etypeset \-f\*(aq
1132 hash=\*(aq\ebuiltin alias \-t\*(aq
1133 history=\*(aq\ebuiltin fc \-l\*(aq
1134 integer=\*(aq\etypeset \-i\*(aq
1135 local=\*(aq\etypeset\*(aq
1136 login=\*(aq\eexec login\*(aq
1137 nameref=\*(aq\etypeset \-n\*(aq
1138 nohup=\*(aqnohup \*(aq
1139 r=\*(aq\ebuiltin fc \-e \-\*(aq
1140 type=\*(aq\ebuiltin whence \-v\*(aq
1143 Tracked aliases allow the shell to remember where it found a particular
1145 The first time the shell does a path search for a command that is
1146 marked as a tracked alias, it saves the full path of the command.
1148 time the command is executed, the shell checks the saved path to see that it
1149 is still valid, and if so, avoids repeating the path search.
1150 Tracked aliases can be listed and created using
1152 Note that changing the
1154 parameter clears the saved paths for all tracked aliases.
1157 option is set (i.e.\&
1158 .Ic set Fl o Ic trackall
1161 the shell tracks all commands.
1162 This option is set automatically for non-interactive shells.
1163 For interactive shells, only the following commands are
1164 automatically tracked:
1184 The first step the shell takes in executing a simple-command is to perform
1185 substitutions on the words of the command.
1186 There are three kinds of
1187 substitution: parameter, command, and arithmetic.
1188 Parameter substitutions,
1189 which are described in detail in the next section, take the form
1192 .Pf ${ Ns Ar ... Ns } ;
1193 command substitutions take the form
1194 .Pf $( Ns Ar command Ns \&)
1196 .Pf \` Ns Ar command Ns \`
1197 or (executed in the current environment)
1198 .Pf ${\ \& Ar command Ns \&;}
1199 and strip trailing newlines;
1200 and arithmetic substitutions take the form
1201 .Pf $(( Ns Ar expression Ns )) .
1202 Parsing the current-environment command substitution requires a space,
1203 tab or newline after the opening brace and that the closing brace be
1204 recognised as a keyword (i.e. is preceded by a newline or semicolon).
1205 They are also called funsubs (function substitutions) and behave like
1212 terminates the parent shell; shell options are shared.
1214 Another variant of substitution are the valsubs (value substitutions)
1215 .Pf ${\*(Ba\& Ns Ar command Ns \&;}
1216 which are also executed in the current environment, like funsubs, but
1217 share their I/O with the parent; instead, they evaluate to whatever
1218 the, initially empty, expression-local variable
1220 is set to within the
1223 If a substitution appears outside of double quotes, the results of the
1224 substitution are generally subject to word or field splitting according to
1225 the current value of the
1230 parameter specifies a list of octets which are used to break a string up
1231 into several words; any octets from the set space, tab, and newline that
1235 .Dq IFS whitespace .
1236 Sequences of one or more
1238 whitespace octets, in combination with zero or one
1240 whitespace octets, delimit a field.
1241 As a special case, leading and trailing
1243 whitespace is stripped (i.e. no leading or trailing empty field
1244 is created by it); leading or trailing
1246 whitespace does create an empty field.
1251 .Dq \*(Ltspace\*(Gt: ,
1253 .Dq \*(Ltspace\*(GtA\*(Ltspace\*(Gt:\*(Ltspace\*(Gt\*(Ltspace\*(GtB::D ,
1254 the substitution for $VAR results in four fields:
1263 parameter is set to the empty string, no field splitting is done;
1264 if it is unset, the default value of space, tab, and newline is used.
1266 Also, note that the field splitting applies only to the immediate result of
1268 Using the previous example, the substitution for $VAR:E
1269 results in the fields:
1282 This behavior is POSIX compliant, but incompatible with some other shell
1283 implementations which do field splitting on the word which contained the
1286 as a general whitespace delimiter.
1288 The results of substitution are, unless otherwise specified, also subject to
1289 brace expansion and file name expansion (see the relevant sections below).
1291 A command substitution is replaced by the output generated by the specified
1292 command which is run in a subshell.
1294 .Pf $( Ns Ar command Ns \&)
1296 .Pf ${\*(Ba\& Ns Ar command Ns \&;}
1298 .Pf ${\ \& Ar command Ns \&;}
1299 substitutions, normal quoting rules are used when
1301 is parsed; however, for the deprecated
1302 .Pf \` Ns Ar command Ns \`
1309 .Pq currently, and violating Tn POSIX ,
1314 followed by any other character is unchanged).
1315 As a special case in command substitutions, a command of the form
1317 is interpreted to mean substitute the contents of
1321 has the same effect as
1324 Note that some shells do not use a recursive parser for command substitutions,
1325 leading to failure for certain constructs; to be portable, use as workaround
1326 .Ql x=$(cat) \*(Lt\*(Lt"EOF"
1327 (or the newline-keeping
1328 .Ql x=\*(Lt\*(Lt"EOF"
1329 extension) instead to merely slurp the string.
1331 recommends to use case statements of the form
1332 .Ql "x=$(case $foo in (bar) echo $bar ;; (*) echo $baz ;; esac)"
1333 instead, which would work but not serve as example for this portability issue.
1334 .Bd -literal -offset indent
1335 x=$(case $foo in bar) echo $bar ;; *) echo $baz ;; esac)
1336 # above fails to parse on old shells; below is the workaround
1337 x=$(eval $(cat)) \*(Lt\*(Lt"EOF"
1338 case $foo in bar) echo $bar ;; *) echo $baz ;; esac
1342 Arithmetic substitutions are replaced by the value of the specified expression.
1343 For example, the command
1344 .Ic print $((2+3*4))
1347 .Sx Arithmetic expressions
1348 for a description of an expression.
1350 Parameters are shell variables; they can be assigned values and their values
1351 can be accessed using a parameter substitution.
1352 A parameter name is either one
1353 of the special single punctuation or digit character parameters described
1354 below, or a letter followed by zero or more letters or digits
1359 The latter form can be treated as arrays by appending an array index of the
1364 is an arithmetic expression.
1367 are limited to the range 0 through 4294967295, inclusive.
1368 That is, they are a 32-bit unsigned integer.
1370 Parameter substitutions take the form
1372 .Pf ${ Ns Ar name Ns } ,
1375 .Pf ${ Ar name Oo Ar expr Oc }
1379 is a parameter name.
1380 Substitution of all array elements with
1381 .Pf ${ Ns Ar name Ns \&[*]}
1383 .Pf ${ Ns Ar name Ns \&[@]}
1384 works equivalent to $* and $@ for positional parameters.
1385 If substitution is performed on a parameter
1386 (or an array parameter element)
1387 that is not set, a null string is substituted unless the
1391 .Ic set Fl o Ic nounset
1395 is set, in which case an error occurs.
1397 Parameters can be assigned values in a number of ways.
1398 First, the shell implicitly sets some parameters like
1403 this is the only way the special single character parameters are set.
1404 Second, parameters are imported from the shell's environment at startup.
1405 Third, parameters can be assigned values on the command line: for example,
1411 multiple parameter assignments can be given on a single command line and they
1412 can be followed by a simple-command, in which case the assignments are in
1413 effect only for the duration of the command (such assignments are also
1414 exported; see below for the implications of this).
1415 Note that both the parameter name and the
1417 must be unquoted for the shell to recognise a parameter assignment.
1420 is also recognised; the old and new values are immediately concatenated.
1421 The fourth way of setting a parameter is with the
1427 commands; see their descriptions in the
1428 .Sx Command execution
1434 loops set parameters as well as the
1440 Lastly, parameters can be assigned values using assignment operators
1441 inside arithmetic expressions (see
1442 .Sx Arithmetic expressions
1445 .Pf ${ Ar name No = Ar value No }
1447 form of the parameter substitution (see below).
1449 Parameters with the export attribute (set using the
1453 commands, or by parameter assignments followed by simple commands) are put in
1454 the environment (see
1456 of commands run by the shell as
1457 .Ar name Ns = Ns Ar value
1459 The order in which parameters appear in the environment of a command is
1461 When the shell starts up, it extracts parameters and their values
1462 from its environment and automatically sets the export attribute for those
1465 Modifiers can be applied to the
1466 .Pf ${ Ns Ar name Ns }
1467 form of parameter substitution:
1470 .It ${ Ar name No :\- Ar word No }
1476 it is substituted; otherwise,
1480 .It ${ Ar name No :+ Ar word No }
1487 is substituted; otherwise, nothing is substituted.
1489 .It ${ Ar name No := Ar word No }
1495 it is substituted; otherwise, it is assigned
1497 and the resulting value of
1501 .It ${ Ar name No :? Ar word No }
1507 it is substituted; otherwise,
1509 is printed on standard error (preceded by
1511 and an error occurs (normally causing termination of a shell script, function,
1512 or script sourced using the
1517 is omitted, the string
1518 .Dq parameter null or not set
1522 is a variable which expands to the null string, the
1523 error message is also printed.
1526 Note that, for all of the above,
1528 is actually considered quoted, and special parsing rules apply.
1529 The parsing rules also differ on whether the expression is double-quoted:
1531 then uses double-quoting rules, except for the double quote itself
1533 and the closing brace, which, if backslash escaped, gets quote removal applied.
1535 In the above modifiers, the
1537 can be omitted, in which case the conditions only depend on
1539 being set (as opposed to set and not
1543 is needed, parameter, command, arithmetic, and tilde substitution are performed
1546 is not needed, it is not evaluated.
1548 The following forms of parameter substitution can also be used (if
1550 is an array, the element with the key
1552 will be substituted in scalar context):
1554 .Bl -tag -width Ds -compact
1555 .It Pf ${# Ns Ar name Ns \&}
1556 The number of positional parameters if
1561 or not specified; otherwise the length
1563 of the string value of parameter
1566 .It Pf ${# Ns Ar name Ns \&[*]}
1567 .It Pf ${# Ns Ar name Ns \&[@]}
1568 The number of elements in the array
1571 .It Pf ${% Ns Ar name Ns \&}
1573 .Pq in screen columns
1574 of the string value of parameter
1577 .Pf ${ Ns Ar name Ns }
1578 contains a control character.
1580 .It Pf ${! Ns Ar name Ns }
1581 The name of the variable referred to by
1587 is a name reference (bound variable), created by the
1589 command (which is an alias for
1590 .Ic typeset Fl n ) .
1592 .It Pf ${! Ns Ar name Ns \&[*]}
1593 .It Pf ${! Ns Ar name Ns \&[@]}
1594 The names of indices (keys) in the array
1600 .Pf # Ar pattern No }
1604 .Pf ## Ar pattern No }
1609 matches the beginning of the value of parameter
1611 the matched text is deleted from the result of substitution.
1614 results in the shortest match, and two
1615 of them result in the longest match.
1616 Cannot be applied to a vector
1617 .Pq ${*} or ${@} or ${array[*]} or ${array[@]} .
1622 .Pf % Ar pattern No }
1626 .Pf %% Ar pattern No }
1629 Like ${..#..} substitution, but it deletes from the end of the value.
1630 Cannot be applied to a vector.
1635 .Pf / Ar pattern / Ar string No }
1639 .Pf /# Ar pattern / Ar string No }
1643 .Pf /% Ar pattern / Ar string No }
1647 .Pf // Ar pattern / Ar string No }
1650 The longest match of
1652 in the value of parameter
1658 is empty; the trailing slash
1660 may be omitted in that case).
1661 A leading slash followed by
1665 causes the pattern to be anchored at the beginning or end of
1666 the value, respectively; empty unanchored
1668 cause no replacement; a single leading slash or use of a
1670 that matches the empty string causes the replacement to
1671 happen only once; two leading slashes cause all occurrences
1672 of matches in the value to be replaced.
1673 Cannot be applied to a vector.
1674 Inefficiently implemented, may be slow.
1678 .Pf ${ Ar name : Ns Ar pos
1679 .Pf : Ns Ar len Ns }
1686 starting at position
1696 is negative, counting starts at the end of the string; if it
1697 is omitted, it defaults to 0.
1700 is omitted or greater than the length of the remaining string,
1701 all of it is substituted.
1706 are evaluated as arithmetic expressions.
1709 must start with a space, opening parenthesis or digit to be recognised.
1710 Cannot be applied to a vector.
1712 .It Pf ${ Ns Ar name Ns @#}
1713 The hash (using the BAFH algorithm) of the expansion of
1715 This is also used internally for the shell's hashtables.
1717 .It Pf ${ Ns Ar name Ns @Q}
1718 A quoted expression safe for re-entry, whose value is the value of the
1720 parameter, is substituted.
1725 may need extended globbing pattern
1728 .Pq \&\*(aq...\&\*(aq
1731 quote escaping unless
1735 The following special parameters are implicitly set by the shell and cannot be
1736 set directly using assignments:
1737 .Bl -tag -width "1 .. 9"
1739 Process ID of the last background process started.
1740 If no background processes have been started, the parameter is not set.
1742 The number of positional parameters ($1, $2, etc.).
1744 The PID of the shell, or the PID of the original shell if it is a subshell.
1747 use this mechanism for generating temporary file names; see
1751 The concatenation of the current single letter options (see the
1753 command below for a list of options).
1755 The exit status of the last non-asynchronous command executed.
1756 If the last command was killed by a signal,
1758 is set to 128 plus the signal number, but at most 255.
1760 The name of the shell, determined as follows:
1761 the first argument to
1763 if it was invoked with the
1765 option and arguments were given; otherwise the
1767 argument, if it was supplied;
1768 or else the basename the shell was invoked with (i.e.\&
1771 is also set to the name of the current script or
1772 the name of the current function, if it was defined with the
1774 keyword (i.e. a Korn shell style function).
1776 The first nine positional parameters that were supplied to the shell, function,
1777 or script sourced using the
1780 Further positional parameters may be accessed using
1781 .Pf ${ Ar number Ns } .
1783 All positional parameters (except 0), i.e. $1, $2, $3, ...
1786 outside of double quotes, parameters are separate words (which are subjected
1787 to word splitting); if used within double quotes, parameters are separated
1788 by the first character of the
1790 parameter (or the empty string if
1797 unless it is used inside double quotes, in which case a separate word is
1798 generated for each positional parameter.
1799 If there are no positional parameters, no word is generated.
1801 can be used to access arguments, verbatim, without losing
1803 arguments or splitting arguments with spaces.
1806 The following parameters are set and/or used by the shell:
1807 .Bl -tag -width "KSH_VERSION"
1810 When an external command is executed by the shell, this parameter is set in the
1811 environment of the new process to the path of the executed command.
1812 In interactive use, this parameter is also set in the parent shell to the last
1813 word of the previous command.
1815 The PID of the shell or subshell.
1819 but used to resolve the argument to the
1824 is set and does not contain
1826 or an empty string element, the current directory is not searched.
1829 built-in command will display the resulting directory when a match is found
1830 in any search path other than the empty path.
1832 Set to the number of columns on the terminal or window.
1833 Always set, defaults to 80, unless the
1834 value as reported by
1836 is non-zero and sane enough (minimum is 12x3); similar for
1838 This parameter is used by the interactive line editing modes, and by the
1843 commands to format information columns.
1844 Importing from the environment or unsetting this parameter removes the
1845 binding to the actual terminal size in favour of the provided value.
1847 If this parameter is found to be set after any profile files are executed, the
1848 expanded value is used as a shell startup file.
1849 It typically contains function and alias definitions.
1851 Integer value of the shell's
1854 It indicates the reason the last system call failed.
1855 Not yet implemented.
1857 If set, this parameter is assumed to contain the shell that is to be used to
1858 execute commands that
1860 fails to execute and which do not start with a
1864 The editor used by the
1866 command (see below).
1870 but used when an undefined function is executed to locate the file defining the
1872 It is also searched when a command can't be found using
1876 below for more information.
1878 The name of the file used to store command history.
1879 When assigned to or unset, the file is opened, history is truncated
1880 then loaded from the file; subsequent new commands (possibly consisting
1881 of several lines) are appended once they successfully compiled.
1882 Also, several invocations of the shell will share history if their
1884 parameters all point to the same file.
1889 is unset or empty, no history file is used.
1890 This is different from
1894 The number of commands normally stored for history.
1895 The default is 2047.
1896 Do not set this value to insanely high values such as 1000000000 because
1898 can then not allocate enough memory for the history and will not start.
1900 The default directory for the
1902 command and the value substituted for an unqualified
1908 Internal field separator, used during substitution and by the
1910 command, to split values into distinct arguments; normally set to space, tab,
1917 This parameter is not imported from the environment when the shell is
1920 The effective group id of the shell.
1922 The real group id of the shell.
1924 The real user id of the shell.
1926 The name and version of the shell (read-only).
1927 See also the version commands in
1928 .Sx Emacs editing mode
1933 The line number of the function or shell script that is currently being
1936 Set to the number of lines on the terminal or window.
1937 Always set, defaults to 24.
1940 .It Ev EPOCHREALTIME
1941 Time since the epoch, as returned by
1942 .Xr gettimeofday 2 ,
1943 formatted as decimal
1949 padded to exactly six decimal digits.
1951 The previous working directory.
1954 has not successfully changed directories since the shell started, or if the
1955 shell doesn't know where it is.
1959 it contains the argument for a parsed option, if it requires one.
1961 The index of the next argument to be processed when using
1963 Assigning 1 to this parameter causes
1965 to process arguments from the beginning the next time it is invoked.
1967 A colon (semicolon on OS/2) separated list of directories that are
1968 searched when looking for commands and files sourced using the
1970 command (see below).
1971 An empty string resulting from a leading or trailing
1972 colon, or two adjacent colons, is treated as a
1974 (the current directory).
1976 The process ID of the shell's process group leader.
1978 An array containing the errorlevel (exit status) codes,
1979 one by one, of the last pipeline run in the foreground.
1981 The process ID of the shell's parent.
1983 The primary prompt for interactive shells.
1984 Parameter, command, and arithmetic
1985 substitutions are performed, and
1987 is replaced with the current command number (see the
1992 can be put in the prompt by placing
1997 The default prompt is
2004 is invoked by root and
2008 character, the default value will be used even if
2010 already exists in the environment.
2014 distribution comes with a sample
2016 containing a sophisticated example, but you might like the following one
2017 (note that ${HOSTNAME:=$(hostname)} and the
2018 root-vs-user distinguishing clause are (in this example) executed at
2020 assignment time, while the $USER and $PWD are escaped
2021 and thus will be evaluated each time a prompt is displayed):
2023 PS1=\*(aq${USER:=$(id \-un)}\*(aq"@${HOSTNAME:=$(hostname)}:\e$PWD $(
2024 if (( USER_ID )); then print \e$; else print \e#; fi) "
2027 Note that since the command-line editors try to figure out how long the prompt
2028 is (so they know how far it is to the edge of the screen), escape codes in
2029 the prompt tend to mess things up.
2030 You can tell the shell not to count certain
2031 sequences (such as escape codes) by prefixing your prompt with a
2032 character (such as Ctrl-A) followed by a carriage return and then delimiting
2033 the escape codes with this character.
2034 Any occurrences of that character in the prompt are not printed.
2035 By the way, don't blame me for
2036 this hack; it's derived from the original
2038 which did print the delimiter character so you were out of luck
2039 if you did not have any non-printing characters.
2041 Since Backslashes and other special characters may be
2042 interpreted by the shell, to set
2044 either escape the backslash itself,
2045 or use double quotes.
2046 The latter is more practical.
2047 This is a more complex example,
2048 avoiding to directly enter special characters (for example with
2050 in the emacs editing mode),
2051 which embeds the current working directory,
2053 .Pq colour would work, too ,
2054 in the prompt string:
2055 .Bd -literal -offset indent
2057 PS1="$x$(print \e\er)$x$(tput so)$x\e$PWD$x$(tput se)$x\*(Gt "
2060 Due to a strong suggestion from David G. Korn,
2062 now also supports the following form:
2063 .Bd -literal -offset indent
2064 PS1=$'\e1\er\e1\ee[7m\e1$PWD\e1\ee[0m\e1\*(Gt '
2067 Secondary prompt string, by default
2069 used when more input is needed to complete a command.
2073 statement when reading a menu selection.
2077 Used to prefix commands that are printed during execution tracing (see the
2080 Parameter, command, and arithmetic substitutions are performed
2081 before it is printed.
2084 You may want to set it to
2085 .Sq \&[$EPOCHREALTIME]\ \&
2086 instead, to include timestamps.
2088 The current working directory.
2091 if the shell doesn't know where it is.
2095 is referenced, it is assigned a number between 0 and 32767 from
2096 a Linear Congruential PRNG first.
2098 Default parameter for the
2100 command if no names are given.
2103 loops to store the value that is read from standard input.
2105 The number of seconds since the shell started or, if the parameter has been
2106 assigned an integer value, the number of seconds since the assignment plus the
2107 value that was assigned.
2109 If set to a positive integer in an interactive shell, it specifies the maximum
2110 number of seconds the shell will wait for input after printing the primary
2113 If the time is exceeded, the shell exits.
2115 The directory temporary shell files are created in.
2116 If this parameter is not
2117 set, or does not contain the absolute path of a writable directory, temporary
2118 files are created in
2121 The effective user id of the shell.
2124 Tilde expansion which is done in parallel with parameter substitution, is done
2125 on words starting with an unquoted
2127 The characters following the tilde, up to the first
2129 if any, are assumed to be a login name.
2130 If the login name is empty,
2139 parameter is substituted, respectively.
2140 Otherwise, the password file is
2141 searched for the login name, and the tilde expression is substituted with the
2142 user's home directory.
2143 If the login name is not found in the password file or
2144 if any quoting or parameter substitution occurs in the login name, no
2145 substitution is performed.
2147 In parameter assignments
2148 (such as those preceding a simple-command or those occurring
2156 tilde expansion is done after any assignment
2157 (i.e. after the equals sign)
2158 or after an unquoted colon
2160 login names are also delimited by colons.
2162 The home directory of previously expanded login names are cached and re-used.
2165 command may be used to list, change, and add to this cache (e.g.\&
2166 .Ic alias \-d fac=/usr/local/facilities; cd \*(TIfac/bin ) .
2167 .Ss Brace expansion (alternation)
2168 Brace expressions take the following form:
2169 .Bd -unfilled -offset indent
2172 .Ar prefix No { Ar str1 No ,...,
2173 .Ar strN No } Ar suffix
2178 The expressions are expanded to
2180 words, each of which is the concatenation of
2187 expands to four words:
2193 As noted in the example, brace expressions can be nested and the resulting
2194 words are not sorted.
2195 Brace expressions must contain an unquoted comma
2197 for expansion to occur (e.g.\&
2202 Brace expansion is carried out after parameter substitution
2203 and before file name generation.
2204 .Ss File name patterns
2205 A file name pattern is a word containing one or more unquoted
2215 Once brace expansion has been performed, the shell replaces file
2216 name patterns with the sorted names of all the files that match the pattern
2217 (if no files match, the word is left unchanged).
2218 The pattern elements have the following meaning:
2221 Matches any single character.
2223 Matches any sequence of octets.
2225 Matches any of the octets inside the brackets.
2226 Ranges of octets can be specified by separating two octets by a
2233 In order to represent itself, a
2235 must either be quoted or the first or last octet in the octet list.
2238 must be quoted or the first octet in the list if it is to represent itself
2239 instead of the end of the list.
2242 appearing at the start of the list has special meaning (see below), so to
2243 represent itself it must be quoted or appear later in the list.
2246 except it matches any octet not inside the brackets.
2248 .It *( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
2250 Matches any string of octets that matches zero or more occurrences of the
2252 Example: The pattern
2261 .It +( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
2263 Matches any string of octets that matches one or more occurrences of the
2265 Example: The pattern
2273 .It ?( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
2275 Matches the empty string or a string that matches one of the specified
2277 Example: The pattern
2279 only matches the strings
2285 .It @( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
2287 Matches a string that matches one of the specified patterns.
2288 Example: The pattern
2290 only matches the strings
2295 .It !( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
2297 Matches any string that does not match one of the specified patterns.
2298 Examples: The pattern
2300 matches all strings except
2306 matches no strings; the pattern
2308 matches all strings (think about it).
2311 Note that complicated globbing, especially with alternatives,
2312 is slow; using separate comparisons may (or may not) be faster.
2330 Note that none of the above pattern elements match either a period
2332 at the start of a file name or a slash
2334 even if they are explicitly used in a [..] sequence; also, the names
2338 are never matched, even by the pattern
2343 option is set, any directories that result from file name generation are marked
2346 .Ss Input/output redirection
2347 When a command is executed, its standard input, standard output, and standard
2348 error (file descriptors 0, 1, and 2, respectively) are normally inherited from
2350 Three exceptions to this are commands in pipelines, for which
2351 standard input and/or standard output are those set up by the pipeline,
2352 asynchronous commands created when job control is disabled, for which standard
2353 input is initially set to be from
2355 and commands for which any of the following redirections have been specified:
2356 .Bl -tag -width XXxxmarker
2357 .It \*(Gt Ns Ar file
2358 Standard output is redirected to
2362 does not exist, it is created; if it does exist, is a regular file, and the
2364 option is set, an error occurs; otherwise, the file is truncated.
2365 Note that this means the command
2366 .Ic cmd \*(Ltfoo \*(Gtfoo
2369 for reading and then truncate it when it opens it for writing, before
2371 gets a chance to actually read
2373 .It \*(Gt\*(Ba Ns Ar file
2376 except the file is truncated, even if the
2379 .It \*(Gt\*(Gt Ns Ar file
2384 exists it is appended to instead of being truncated.
2385 Also, the file is opened
2386 in append mode, so writes always go to the end of the file (see
2388 .It \*(Lt Ns Ar file
2389 Standard input is redirected from
2391 which is opened for reading.
2392 .It \*(Lt\*(Gt Ns Ar file
2395 except the file is opened for reading and writing.
2396 .It \*(Lt\*(Lt Ns Ar marker
2397 After reading the command line containing this kind of redirection (called a
2398 .Dq here document ) ,
2399 the shell copies lines from the command source into a temporary file until a
2403 When the command is executed, standard input is redirected from the
2407 contains no quoted characters, the contents of the temporary file are processed
2408 as if enclosed in double quotes each time the command is executed, so
2409 parameter, command, and arithmetic substitutions are performed, along with
2420 If multiple here documents are used on the same command line, they are saved in
2425 is given, the here document ends at the next
2427 and substitution will be performed.
2430 is only a set of either single
2434 quotes with nothing in between, the here document ends at the next empty line
2435 and substitution will not be performed.
2436 .It \*(Lt\*(Lt\- Ns Ar marker
2439 except leading tabs are stripped from lines in the here document.
2440 .It \*(Lt\*(Lt\*(Lt Ns Ar word
2447 This is called a here string.
2449 Standard input is duplicated from file descriptor
2452 can be a number, indicating the number of an existing file descriptor;
2455 indicating the file descriptor associated with the output of the current
2456 co-process; or the character
2458 indicating standard input is to be closed.
2461 is limited to a single digit in most shell implementations.
2465 except the operation is done on standard output.
2466 .It &\*(Gt Ns Ar file
2468 .Ic \*(Gt Ns Ar file 2\*(Gt&1 .
2469 This is a deprecated (legacy) GNU
2471 extension supported by
2473 which also supports the preceding explicit fd number, for example,
2474 .Ic 3&\*(Gt Ns Ar file
2476 .Ic 3\*(Gt Ns Ar file 2\*(Gt&3
2479 but a syntax error in GNU
2482 .No &\*(Gt\*(Ba Ns Ar file ,
2483 .No &\*(Gt\*(Gt Ns Ar file ,
2484 .No &\*(Gt& Ns Ar fd
2487 .Ic \*(Gt\*(Ba Ns Ar file ,
2488 .Ic \*(Gt\*(Gt Ns Ar file ,
2490 .Ic \*(Gt& Ns Ar fd ,
2499 In any of the above redirections, the file descriptor that is redirected
2500 (i.e. standard input or standard output)
2501 can be explicitly given by preceding the
2502 redirection with a number (portably, only a single digit).
2503 Parameter, command, and arithmetic
2504 substitutions, tilde substitutions, and (if the shell is interactive)
2505 file name generation are all performed on the
2510 arguments of redirections.
2511 Note, however, that the results of any file name
2512 generation are only used if a single file is matched; if multiple files match,
2513 the word with the expanded file name generation characters is used.
2515 that in restricted shells, redirections which can create files cannot be used.
2517 For simple-commands, redirections may appear anywhere in the command; for
2523 any redirections must appear at the end.
2524 Redirections are processed after
2525 pipelines are created and in the order they are given, so the following
2526 will print an error with a line number prepended to it:
2528 .D1 $ cat /foo/bar 2\*(Gt&1 \*(Gt/dev/null \*(Ba pr \-n \-t
2530 File descriptors created by I/O redirections are private to the shell.
2531 .Ss Arithmetic expressions
2532 Integer arithmetic expressions can be used with the
2534 command, inside $((..)) expressions, inside array references (e.g.\&
2535 .Ar name Ns Bq Ar expr ) ,
2536 as numeric arguments to the
2538 command, and as the value of an assignment to an integer parameter.
2540 This also affects implicit conversion to integer, for example as done by the
2544 use unchecked user input, e.g. from the environment, in arithmetics!
2546 Expressions are calculated using signed arithmetic and the
2548 type (a 32-bit signed integer), unless they begin with a sole
2550 character, in which case they use
2552 .Po a 32-bit unsigned integer Pc .
2554 Expressions may contain alpha-numeric parameter identifiers, array references,
2555 and integer constants and may be combined with the following C operators
2556 (listed and grouped in increasing order of precedence):
2559 .Bd -literal -offset indent
2560 + \- ! \*(TI ++ \-\-
2564 .Bd -literal -offset indent
2566 = += \-= *= /= %= \*(Lt\*(Lt\*(Lt= \*(Gt\*(Gt\*(Gt= \*(Lt\*(Lt= \*(Gt\*(Gt= &= \*(ha= \*(Ba=
2573 \*(Lt \*(Lt= \*(Gt \*(Gt=
2574 \*(Lt\*(Lt\*(Lt \*(Gt\*(Gt\*(Gt \*(Lt\*(Lt \*(Gt\*(Gt
2580 .Bd -literal -offset indent
2581 ?: (precedence is immediately higher than assignment)
2585 .Bd -literal -offset indent
2589 Integer constants and expressions are calculated using an exactly 32-bit
2590 wide, signed or unsigned, type with silent wraparound on integer overflow.
2591 Integer constants may be specified with arbitrary bases using the notation
2592 .Ar base Ns # Ns Ar number ,
2595 is a decimal integer specifying the base, and
2597 is a number in the specified base.
2598 Additionally, base-16 integers may be specified by prefixing them with
2600 .Pq case-insensitive
2601 in all forms of arithmetic expressions, except as numeric arguments to the
2604 Prefixing numbers with a sole digit zero
2606 does not cause interpretation as octal, as that's unsafe to do.
2610 extension, numbers to the base of one are treated as either (8-bit
2611 transparent) ASCII or Unicode codepoints, depending on the shell's
2613 flag (current setting).
2622 Note that NUL bytes (integral value of zero) cannot be used.
2623 An unset or empty parameter evaluates to 0 in integer context.
2624 In Unicode mode, raw octets are mapped into the range EF80..EFFF as in
2625 OPTU-8, which is in the PUA and has been assigned by CSUR for this use.
2626 If more than one octet in ASCII mode, or a sequence of more than one
2627 octet not forming a valid and minimal CESU-8 sequence is passed, the
2628 behaviour is undefined (usually, the shell aborts with a parse error,
2629 but rarely, it succeeds, e.g. on the sequence C2 20).
2630 That's why you should always use ASCII mode unless you know that the
2631 input is well-formed UTF-8 in the range of 0000..FFFD if you use this
2632 feature, as opposed to
2635 The operators are evaluated as follows:
2636 .Bl -tag -width Ds -offset indent
2638 Result is the argument (included for completeness).
2643 the result is 1 if argument is zero, 0 if not.
2645 Arithmetic (bit-wise) NOT.
2647 Increment; must be applied to a parameter (not a literal or other expression).
2648 The parameter is incremented by 1.
2649 When used as a prefix operator, the result
2650 is the incremented value of the parameter; when used as a postfix operator, the
2651 result is the original value of the parameter.
2655 except the parameter is decremented by 1.
2657 Separates two arithmetic expressions; the left-hand side is evaluated first,
2659 The result is the value of the expression on the right-hand side.
2661 Assignment; the variable on the left is set to the value on the right.
2663 .No += \-= *= /= %= \*(Lt\*(Lt\*(Lt= \*(Gt\*(Gt\*(Gt=
2664 .No \*(Lt\*(Lt= \*(Gt\*(Gt= &= \*(ha= \*(Ba=
2666 Assignment operators.
2681 with any operator precedence in
2686 is the same as specifying
2687 .Dq var1 = var1 * (5 + 3) .
2690 the result is 1 if either argument is non-zero, 0 if not.
2691 The right argument is evaluated only if the left argument is zero.
2694 the result is 1 if both arguments are non-zero, 0 if not.
2695 The right argument is evaluated only if the left argument is non-zero.
2697 Arithmetic (bit-wise) OR.
2699 Arithmetic (bit-wise) XOR
2702 Arithmetic (bit-wise) AND.
2704 Equal; the result is 1 if both arguments are equal, 0 if not.
2706 Not equal; the result is 0 if both arguments are equal, 1 if not.
2708 Less than; the result is 1 if the left argument is less than the right, 0 if
2710 .It \*(Lt= \*(Gt \*(Gt=
2711 Less than or equal, greater than, greater than or equal.
2714 .It \*(Lt\*(Lt\*(Lt \*(Gt\*(Gt\*(Gt
2715 Rotate left (right); the result is similar to shift (see
2717 except that the bits shifted out at one end are shifted in
2718 at the other end, instead of zero or sign bits.
2719 .It \*(Lt\*(Lt \*(Gt\*(Gt
2720 Shift left (right); the result is the left argument with its bits shifted left
2721 (right) by the amount given in the right argument.
2723 Addition, subtraction, multiplication, and division.
2725 Remainder; the result is the symmetric remainder of the division of the left
2726 argument by the right.
2727 To get the mathematical modulus of
2743 is non-zero, the result is
2745 otherwise the result is
2747 The non-result argument is not evaluated.
2750 A co-process (which is a pipeline created with the
2752 operator) is an asynchronous process that the shell can both write to (using
2754 and read from (using
2756 The input and output of the co-process can also be manipulated using
2760 redirections, respectively.
2761 Once a co-process has been started, another can't
2762 be started until the co-process exits, or until the co-process's input has been
2764 .Ic exec Ar n Ns Ic \*(Gt&p
2766 If a co-process's input is redirected in this way, the next
2767 co-process to be started will share the output with the first co-process,
2768 unless the output of the initial co-process has been redirected using an
2769 .Ic exec Ar n Ns Ic \*(Lt&p
2772 Some notes concerning co-processes:
2775 The only way to close the co-process's input (so the co-process reads an
2776 end-of-file) is to redirect the input to a numbered file descriptor and then
2777 close that file descriptor:
2778 .Ic exec 3\*(Gt&p; exec 3\*(Gt&\-
2780 In order for co-processes to share a common output, the shell must keep the
2781 write portion of the output pipe open.
2782 This means that end-of-file will not be
2783 detected until all co-processes sharing the co-process's output have exited
2784 (when they all exit, the shell closes its copy of the pipe).
2786 avoided by redirecting the output to a numbered file descriptor (as this also
2787 causes the shell to close its copy).
2788 Note that this behaviour is slightly
2789 different from the original Korn shell which closes its copy of the write
2790 portion of the co-process output when the most recently started co-process
2791 (instead of when all sharing co-processes) exits.
2796 signals during writes if the signal is not being trapped or ignored; the same
2797 is true if the co-process input has been duplicated to another file descriptor
2799 .Ic print Fl u Ns Ar n
2803 Functions are defined using either Korn shell
2804 .Ic function Ar function-name
2805 syntax or the Bourne/POSIX shell
2806 .Ar function-name Ns \&()
2807 syntax (see below for the difference between the two forms).
2810 (i.e. scripts sourced using the
2813 in that they are executed in the current environment.
2816 shell arguments (i.e. positional parameters $1, $2, etc.)\&
2817 are never visible inside them.
2818 When the shell is determining the location of a command, functions
2819 are searched after special built-in commands, before builtins and the
2823 An existing function may be deleted using
2824 .Ic unset Fl f Ar function-name .
2825 A list of functions can be obtained using
2827 and the function definitions can be listed using
2831 command (which is an alias for
2833 may be used to create undefined functions: when an undefined function is
2834 executed, the shell searches the path specified in the
2836 parameter for a file with the same name as the function which, if found, is
2838 If after executing the file the named function is found to
2839 be defined, the function is executed; otherwise, the normal command search is
2840 continued (i.e. the shell searches the regular built-in command table and
2842 Note that if a command is not found using
2844 an attempt is made to autoload a function using
2846 (this is an undocumented feature of the original Korn shell).
2848 Functions can have two attributes,
2852 which can be set with
2857 When a traced function is executed, the shell's
2859 option is turned on for the function's duration.
2862 attribute of functions is currently not used.
2863 In the original Korn shell,
2864 exported functions are visible to shell scripts that are executed.
2866 Since functions are executed in the current shell environment, parameter
2867 assignments made inside functions are visible after the function completes.
2868 If this is not the desired effect, the
2870 command can be used inside a function to create a local parameter.
2874 uses static scoping (one global scope, one local scope per function)
2875 and allows local variables only on Korn style functions, whereas
2877 uses dynamic scoping (nested scopes of varying locality).
2878 Note that special parameters (e.g.\&
2880 can't be scoped in this way.
2882 The exit status of a function is that of the last command executed in the
2884 A function can be made to finish immediately using the
2886 command; this may also be used to explicitly specify the exit status.
2888 Functions defined with the
2890 reserved word are treated differently in the following ways from functions
2896 The $0 parameter is set to the name of the function
2897 (Bourne-style functions leave $0 untouched).
2899 Parameter assignments preceding function calls are not kept in the shell
2900 environment (executing Bourne-style functions will keep assignments).
2903 is saved/reset and restored on entry and exit from the function so
2905 can be used properly both inside and outside the function (Bourne-style
2910 inside a function interferes with using
2912 outside the function).
2916 have local scope, i.e. changes inside a function are reset upon its exit.
2919 In the future, the following differences may also be added:
2922 A separate trap/signal environment will be used during the execution of
2924 This will mean that traps set inside a function will not affect the
2925 shell's traps and signals that are not ignored in the shell (but may be
2926 trapped) will have their default effect in a function.
2928 The EXIT trap, if set in a function, will be executed after the function
2931 .Ss Command execution
2932 After evaluation of command-line arguments, redirections, and parameter
2933 assignments, the type of command is determined: a special built-in command,
2934 a function, a normal builtin, or the name of a file to execute found using the
2937 The checks are made in the above order.
2938 Special built-in commands differ from other commands in that the
2940 parameter is not used to find them, an error during their execution can
2941 cause a non-interactive shell to exit, and parameter assignments that are
2942 specified before the command are kept after the command completes.
2943 Regular built-in commands are different only in that the
2945 parameter is not used to find them.
2949 and POSIX differ somewhat in which commands are considered
2952 POSIX special built-in utilities:
2954 .Ic \&. , \&: , break , continue ,
2955 .Ic eval , exec , exit , export ,
2956 .Ic readonly , return , set , shift ,
2957 .Ic times , trap , unset
2961 commands keeping assignments:
2963 .Ic builtin , global , source , typeset ,
2966 Builtins that are not special:
2968 .Ic [ , alias , bg , bind ,
2969 .Ic cat , cd , command , echo ,
2970 .Ic false , fc , fg , getopts ,
2971 .Ic jobs , kill , let , print ,
2972 .Ic pwd , read , realpath , rename ,
2973 .Ic sleep , suspend , test , true ,
2974 .Ic ulimit , umask , unalias , whence
2976 Once the type of command has been determined, any command-line parameter
2977 assignments are performed and exported for the duration of the command.
2979 The following describes the special and regular built-in commands and
2980 builtin-like reserved words:
2982 .Bl -tag -width false -compact
2983 .It Ic \&. Ar file Op Ar arg ...
2987 Execute the commands in
2989 in the current environment.
2990 The file is searched for in the directories of
2992 If arguments are given, the positional parameters may be used to access them
2996 If no arguments are given, the positional parameters are
2997 those of the environment the command is used in.
2999 .It Ic \&: Op Ar ...
3001 Exit status is set to zero.
3003 .It Ic \&[ Ar expression Ic \&]
3008 .Oo Fl d \*(Ba t Oo Fl r Oc \*(Ba
3013 .Op Ns = Ns Ar value
3019 For any name without a value, the existing alias is listed.
3020 Any name with a value defines an alias (see
3024 When listing aliases, one of two formats is used.
3025 Normally, aliases are listed as
3026 .Ar name Ns = Ns Ar value ,
3030 If options were preceded with
3034 is given on the command line, only
3040 option causes directory aliases which are used in tilde expansion to be
3047 option is used, each alias is prefixed with the string
3052 option indicates that tracked aliases are to be listed/set (values specified on
3053 the command line are ignored for tracked aliases).
3056 option indicates that all tracked aliases are to be reset.
3062 the export attribute of an alias, or, if no names are given, lists the aliases
3063 with the export attribute (exporting an alias has no effect).
3065 .It Ic bg Op Ar job ...
3066 Resume the specified stopped job(s) in the background.
3067 If no jobs are specified,
3072 below for more information.
3075 The current bindings are listed.
3080 instead lists the names of the functions to which keys may be bound.
3082 .Sx Emacs editing mode
3083 for more information.
3085 .It Xo Ic bind Op Fl m
3086 .Ar string Ns = Ns Op Ar substitute
3090 .Ar string Ns = Ns Op Ar editing-command
3093 The specified editing command is bound to the given
3095 which should consist of a control character
3096 optionally preceded by one of the two prefix characters
3097 and optionally succeded by a tilde character.
3100 will cause the editing command to be immediately invoked.
3103 flag is given, the specified input
3105 will afterwards be immediately replaced by the given
3107 string which may contain editing commands but not other macros.
3108 If a tilde postfix is given, a tilde trailing the one or
3109 two prefices and the control character is ignored, any
3110 other trailing character will be processed afterwards.
3112 Control characters may be written using caret notation
3113 i.e. \*(haX represents Ctrl-X.
3114 Note that although only two prefix characters (usually ESC and \*(haX)
3115 are supported, some multi-character sequences can be supported.
3117 The following default bindings show how the arrow keys, the home, end and
3118 delete key on a BSD wsvt25, xterm\-xfree86 or GNU screen terminal are bound
3119 (of course some escape sequences won't work out quite this nicely):
3120 .Bd -literal -offset indent
3121 bind \*(aq\*(haX\*(aq=prefix\-2
3122 bind \*(aq\*(ha[[\*(aq=prefix\-2
3123 bind \*(aq\*(haXA\*(aq=up\-history
3124 bind \*(aq\*(haXB\*(aq=down\-history
3125 bind \*(aq\*(haXC\*(aq=forward\-char
3126 bind \*(aq\*(haXD\*(aq=backward\-char
3127 bind \*(aq\*(haX1\*(TI\*(aq=beginning\-of\-line
3128 bind \*(aq\*(haX7\*(TI\*(aq=beginning\-of\-line
3129 bind \*(aq\*(haXH\*(aq=beginning\-of\-line
3130 bind \*(aq\*(haX4\*(TI\*(aq=end\-of\-line
3131 bind \*(aq\*(haX8\*(TI\*(aq=end\-of\-line
3132 bind \*(aq\*(haXF\*(aq=end\-of\-line
3133 bind \*(aq\*(haX3\*(TI\*(aq=delete\-char\-forward
3136 .It Ic break Op Ar level
3152 .Ar command Op Ar arg ...
3154 Execute the built-in command
3162 Read files sequentially, in command line order, and write them to
3168 or absent, read from standard input.
3169 For direct builtin calls, the
3172 option is supported as a no-op.
3173 For calls from shell, if any options are given, an external
3175 utility is preferred over the builtin.
3192 Set the working directory to
3196 is set, it lists the search path for the directory containing
3200 path means the current directory.
3203 is found in any component of the
3205 search path other than the
3207 path, the name of the new working directory will be written to standard output.
3210 is missing, the home directory
3217 the previous working directory is used (see the
3223 option (logical path) is used or if the
3225 option isn't set (see the
3227 command below), references to
3231 are relative to the path used to get to the directory.
3234 option (physical path) is used or if the
3238 is relative to the filesystem directory tree.
3243 parameters are updated to reflect the current and old working directory,
3247 option is set for physical filesystem traversal, and
3249 could not be set, the exit code is 1; greater than 1 if an
3250 error occurred, 0 otherwise.
3266 in the current directory, and the shell attempts to change to the new
3281 is executed exactly as if
3283 had not been specified, with two exceptions:
3286 cannot be a shell function;
3287 and secondly, special built-in commands lose their specialness
3288 (i.e. redirection and utility errors do not cause the shell to
3289 exit, and command assignments are not permanent).
3293 option is given, a default search path is used instead of the current value of
3295 the actual value of which is system dependent.
3299 option is given, instead of executing
3301 information about what would be executed is given (and the same is done for
3303 For builtins, functions and keywords, their names are simply printed;
3304 for aliases, a command that defines them is printed;
3305 for utilities found by searching the
3307 parameter, the full path of the command is printed.
3308 If no command is found
3309 (i.e. the path search fails), nothing is printed and
3311 exits with a non-zero status.
3316 option, except it is more verbose.
3318 .It Ic continue Op Ar level
3319 Jumps to the beginning of the
3337 this utility is not portable; use the Korn shell builtin
3341 Prints its arguments (separated by spaces) followed by a newline, to the
3343 The newline is suppressed if any of the arguments contain the
3348 command below for a list of other backslash sequences that are recognised.
3350 The options are provided for compatibility with
3355 option suppresses the trailing newline,
3357 enables backslash interpretation (a no-op, since this is normally done), and
3359 suppresses backslash interpretation.
3365 option is set or this is a direct builtin call, only the first argument
3366 is treated as an option, and only if it is exactly
3368 Backslash interpretation is disabled.
3370 .It Ic eval Ar command ...
3371 The arguments are concatenated (with spaces between them) to form a single
3372 string which the shell then parses and executes in the current environment.
3378 .Op Ar command Op Ar arg ...
3380 The command is executed without forking, replacing the shell process.
3381 This is currently absolute, i.e.\&
3383 never returns, even if the
3388 option permits setting a different
3392 clears the environment before executing the child process, except for the
3394 variable and direct assignments.
3396 If no command is given except for I/O redirection, the I/O redirection is
3397 permanent and the shell is
3399 Any file descriptors greater than 2 which are opened or
3401 in this way are not made available to other executed commands (i.e. commands
3402 that are not built-in to the shell).
3403 Note that the Bourne shell differs here;
3404 it does pass these file descriptors on.
3406 .It Ic exit Op Ar status
3407 The shell exits with the specified exit status.
3410 is not specified, the exit status is the current value of the
3417 .Op Ar parameter Ns Op = Ns Ar value
3419 Sets the export attribute of the named parameters.
3420 Exported parameters are passed in the environment to executed commands.
3421 If values are specified, the named parameters are also assigned.
3423 If no parameters are specified, all parameters with the export attribute
3424 set are printed one per line; either their names, or, if a
3426 with no option letter is specified, name=value pairs, or, with
3429 commands suitable for re-entry.
3432 A command that exits with a non-zero status.
3436 .Oo Fl e Ar editor \*(Ba
3439 .Op Ar first Op Ar last
3444 select commands from the history.
3445 Commands can be selected by history number
3446 (negative numbers go backwards from the current, most recent, line)
3447 or a string specifying the most recent command starting with that string.
3450 option lists the command on standard output, and
3452 inhibits the default command numbers.
3455 option reverses the order of the list.
3458 the selected commands are edited by the editor specified with the
3462 is specified, the editor specified by the
3464 parameter (if this parameter is not set,
3466 is used), and then executed by the shell.
3470 .Cm \-e \- \*(Ba Fl s
3472 .Op Ar old Ns = Ns Ar new
3475 Re-execute the selected command (the previous command by default) after
3476 performing the optional substitution of
3482 is specified, all occurrences of
3490 is identical: re-execute the selected command without invoking an editor.
3491 This command is usually accessed with the predefined:
3492 .Ic alias r=\*(aqfc \-e \-\*(aq
3494 .It Ic fg Op Ar job ...
3495 Resume the specified job(s) in the foreground.
3496 If no jobs are specified,
3501 below for more information.
3508 Used by shell procedures to parse the specified arguments (or positional
3509 parameters, if no arguments are given) and to check for legal options.
3511 contains the option letters that
3514 If a letter is followed by a colon, the option is expected to
3516 Options that do not take arguments may be grouped in a single argument.
3517 If an option takes an argument and the option character is not the
3518 last character of the argument it is found in, the remainder of the argument is
3519 taken to be the option's argument; otherwise, the next argument is the option's
3524 is invoked, it places the next option in the shell parameter
3526 and the index of the argument to be processed by the next call to
3528 in the shell parameter
3530 If the option was introduced with a
3532 the option placed in
3536 When an option requires an argument,
3538 places it in the shell parameter
3541 When an illegal option or a missing option argument is encountered, a question
3542 mark or a colon is placed in
3544 (indicating an illegal option or missing argument, respectively) and
3546 is set to the option character that caused the problem.
3549 does not begin with a colon, a question mark is placed in
3552 is unset, and an error message is printed to standard error.
3554 When the end of the options is encountered,
3556 exits with a non-zero exit status.
3557 Options end at the first (non-option
3558 argument) argument that does not start with a
3562 argument is encountered.
3564 Option parsing can be reset by setting
3566 to 1 (this is done automatically whenever the shell or a shell procedure is
3569 Warning: Changing the value of the shell parameter
3571 to a value other than 1, or parsing different sets of arguments without
3574 may lead to unexpected results.
3585 Without arguments, any hashed executable command pathnames are listed.
3588 option causes all hashed commands to be removed from the hash table.
3591 is searched as if it were a command name and added to the hash table if it is
3592 an executable command.
3599 Display information about the specified job(s); if no jobs are specified, all
3603 option causes information to be displayed only for jobs that have changed
3604 state since the last notification.
3607 option is used, the process ID of each process in a job is also listed.
3610 option causes only the process group of each job to be printed.
3613 below for the format of
3615 and the displayed job.
3619 .Oo Fl s Ar signame \*(Ba
3620 .No \- Ns Ar signum \*(Ba
3621 .No \- Ns Ar signame Oc
3622 .No { Ar job \*(Ba pid \*(Ba pgrp No }
3625 Send the specified signal to the specified jobs, process IDs, or process
3627 If no signal is specified, the
3630 If a job is specified, the signal is sent to the job's process group.
3633 below for the format of
3639 .Op Ar exit-status ...
3641 Print the signal name corresponding to
3643 If no arguments are specified, a list of all the signals, their numbers, and
3644 a short description of them are printed.
3646 .It Ic let Op Ar expression ...
3647 Each expression is evaluated (see
3648 .Sx Arithmetic expressions
3650 If all expressions are successfully evaluated, the exit status is 0 (1)
3651 if the last expression evaluated to non-zero (zero).
3652 If an error occurs during
3653 the parsing or evaluation of an expression, the exit status is greater than 1.
3654 Since expressions may need to be quoted,
3655 .No \&(( Ar expr No ))
3656 is syntactic sugar for
3657 .No "{ let '" Ns Ar expr Ns "'; }" .
3660 Internally used alias for
3676 Create a device special file.
3677 The file type may be
3679 (block type device),
3681 (character type device),
3684 .Pq named pipe , Tn FIFO .
3685 The file created may be modified according to its
3691 (major device number),
3694 (minor device number).
3695 This is not normally part of
3697 however, distributors may have added this as builtin as a speed hack.
3701 .Oo Fl nprsu Ns Oo Ar n Oc \*(Ba
3706 prints its arguments on the standard output, separated by spaces and
3707 terminated with a newline.
3710 option suppresses the newline.
3711 By default, certain C escapes are translated.
3712 These include these mentioned in
3713 .Sx Backslash expansion
3716 which is equivalent to using the
3719 Backslash expansion may be inhibited with the
3724 option prints to the history file instead of standard output; the
3726 option prints to file descriptor
3730 defaults to 1 if omitted
3734 option prints to the co-process (see
3740 option is used to emulate, to some degree, the
3743 command which does not process
3745 sequences unless the
3750 option suppresses the trailing newline.
3752 .It Ic printf Ar format Op Ar arguments ...
3754 Approximately the same as the
3756 utility, except it uses the same
3757 .Sx Backslash expansion
3758 and I/O code and does not handle floating point as the rest of
3760 An external utility is preferred over the builtin.
3761 This is not normally part of
3763 however, distributors may have added this as builtin as a speed hack.
3764 Do not use in new code.
3767 Print the present working directory.
3770 option is used or if the
3772 option isn't set (see the
3774 command below), the logical path is printed (i.e. the path used to
3776 to the current directory).
3779 option (physical path) is used or if the
3781 option is set, the path determined from the filesystem (by following
3783 directories to the root directory) is printed.
3797 Reads a line of input, separates the input into fields using the
3801 above), and assigns each field to the specified parameters
3803 If no parameters are specified, the
3805 parameter is used to store the result.
3810 options, only no or one parameter is accepted.
3811 If there are more parameters than fields, the extra parameters are set to
3812 the empty string or 0; if there are more fields than parameters, the last
3813 parameter is assigned the remaining fields (including the word separators).
3815 The options are as follows:
3816 .Bl -tag -width XuXnX
3818 Store the result into the parameter
3824 Store the result without word splitting into the parameter
3828 as array of characters (wide characters if the
3830 option is enacted, octets otherwise); the codepoints are
3831 encoded as decimal numbers by default.
3833 Use the first byte of
3836 if empty, instead of the ASCII newline character as input line delimiter.
3838 Instead of reading till end-of-line, read exactly
3841 If EOF or a timeout occurs, a partial read is returned with exit status 1.
3843 Instead of reading till end-of-line, read up to
3845 bytes but return as soon as any bytes are read, e.g.\& from a
3846 slow terminal device, or if EOF or a timeout occurs.
3848 Read from the currently active co-process, see
3850 above for details on this.
3852 Read from the file descriptor
3854 (defaults to 0, i.e.\& standard input).
3855 The argument must immediately follow the option character.
3857 Interrupt reading after
3859 seconds (specified as positive decimal value with an optional fractional part).
3862 is 1 if the timeout occurred, but partial reads may still be returned.
3864 Normally, the ASCII backslash character escapes the special
3865 meaning of the following character and is stripped from the input;
3867 does not stop when encountering a backslash-newline sequence and
3868 does not store that newline in the result.
3869 This option enables raw mode, in which backslashes are not processed.
3871 The input line is saved to the history.
3874 If the input is a terminal, both the
3878 options set it into raw mode;
3879 they read an entire file if \-1 is passed as
3883 The first parameter may have a question mark and a string appended to it, in
3884 which case the string is used as a prompt (printed to standard error before
3885 any input is read) if the input is a
3888 .Ic read nfoo?\*(aqnumber of foos: \*(aq ) .
3890 If no input is read or a timeout occurred,
3892 exits with a non-zero status.
3894 Another handy set of tricks:
3897 is run in a loop such as
3898 .Ic while read foo; do ...; done
3899 then leading whitespace will be removed (IFS) and backslashes processed.
3900 You might want to use
3901 .Ic while IFS= read \-r foo; do ...; done
3903 Similarily, when using the
3907 option might be prudent; the same applies for:
3908 .Bd -literal -offset indent
3909 find . \-type f \-print0 \*(Ba& \e
3910 while IFS= read \-d \*(aq\*(aq \-pr filename; do
3911 print \-r \-\- "found \*(Lt${filename#./}\*(Gt"
3915 The inner loop will be executed in a subshell and variable changes
3916 cannot be propagated if executed in a pipeline:
3917 .Bd -literal -offset indent
3918 bar \*(Ba baz \*(Ba while read foo; do ...; done
3921 Use co-processes instead:
3922 .Bd -literal -offset indent
3923 bar \*(Ba baz \*(Ba&
3924 while read \-p foo; do ...; done
3925 exec 3\*(Gt&p; exec 3\*(Gt&\-
3932 .Op Ns = Ns Ar value
3935 Sets the read-only attribute of the named parameters.
3936 If values are given,
3937 parameters are set to them before setting the attribute.
3939 made read-only, it cannot be unset and its value cannot be changed.
3941 If no parameters are specified, the names of all parameters with the read-only
3942 attribute are printed one per line, unless the
3944 option is used, in which case
3946 commands defining all read-only parameters, including their values, are
3954 Prints the resolved absolute pathname corresponding to
3960 it's also checked for existence and whether it is a directory; otherwise,
3962 returns 0 if the pathname either exists or can be created immediately,
3963 i.e. all but the last component exist and are directories.
3974 Both must be complete pathnames and on the same device.
3975 This builtin is intended for emergency situations where
3977 becomes unusable, and directly calls
3980 .It Ic return Op Ar status
3981 Returns from a function or
3983 script, with exit status
3987 is given, the exit status of the last executed command is used.
3988 If used outside of a function or
3990 script, it has the same effect as
3994 treats both profile and
3998 scripts, while the original Korn shell only treats profiles as
4003 .Ic set Op Ic +\-abCefhiklmnprsUuvXx
4004 .Op Ic +\-o Ar option
4011 command can be used to set
4015 shell options, set the positional parameters, or set an array parameter.
4016 Options can be changed using the
4020 is the long name of an option, or using the
4021 .Cm +\- Ns Ar letter
4024 is the option's single letter name (not all options have a single letter name).
4025 The following table lists both option letters (if they exist) and long names
4026 along with a description of what the option does:
4029 Sets the elements of the array parameter
4035 is used, the array is reset (i.e. emptied) first; if
4037 is used, the first N elements are set (where N is the number of arguments);
4038 the rest are left untouched.
4040 An alternative syntax for the command
4041 .Ic set \-A foo \-\- a b c
4042 which is compatible to
4045 and also supported by
4049 .Ic foo=(a b c); foo+=(d e)
4050 .It Fl a \*(Ba Fl o Ic allexport
4051 All new parameters are created with the export attribute.
4052 .It Fl b \*(Ba Fl o Ic notify
4053 Print job notification messages asynchronously, instead of just before the
4055 Only used if job control is enabled
4057 .It Fl C \*(Ba Fl o Ic noclobber
4058 Prevent \*(Gt redirection from overwriting existing files.
4059 Instead, \*(Gt\*(Ba must be used to force an overwrite.
4060 Note that this is not safe to use for creation of temporary files or
4061 lockfiles due to a TOCTOU in a check allowing one to redirect output to
4063 or other device files even in
4066 .It Fl e \*(Ba Fl o Ic errexit
4067 Exit (after executing the
4069 trap) as soon as an error occurs or a command fails (i.e. exits with a
4071 This does not apply to commands whose exit status is
4072 explicitly tested by a shell construct such as
4083 only the status of the last command is tested.
4084 .It Fl f \*(Ba Fl o Ic noglob
4085 Do not expand file name patterns.
4086 .It Fl h \*(Ba Fl o Ic trackall
4087 Create tracked aliases for all executed commands (see
4090 Enabled by default for non-interactive shells.
4091 .It Fl i \*(Ba Fl o Ic interactive
4092 The shell is an interactive shell.
4093 This option can only be used when the shell is invoked.
4094 See above for a description of what this means.
4095 .It Fl k \*(Ba Fl o Ic keyword
4096 Parameter assignments are recognised anywhere in a command.
4097 .It Fl l \*(Ba Fl o Ic login
4098 The shell is a login shell.
4099 This option can only be used when the shell is invoked.
4100 See above for a description of what this means.
4101 .It Fl m \*(Ba Fl o Ic monitor
4102 Enable job control (default for interactive shells).
4103 .It Fl n \*(Ba Fl o Ic noexec
4104 Do not execute any commands.
4105 Useful for checking the syntax of scripts
4106 (ignored if interactive).
4107 .It Fl p \*(Ba Fl o Ic privileged
4108 The shell is a privileged shell.
4109 It is set automatically if, when the shell starts,
4110 the real UID or GID does not match
4111 the effective UID (EUID) or GID (EGID), respectively.
4112 See above for a description of what this means.
4113 .It Fl r \*(Ba Fl o Ic restricted
4114 The shell is a restricted shell.
4115 This option can only be used when the shell is invoked.
4116 See above for a description of what this means.
4117 .It Fl s \*(Ba Fl o Ic stdin
4118 If used when the shell is invoked, commands are read from standard input.
4119 Set automatically if the shell is invoked with no arguments.
4125 command it causes the specified arguments to be sorted before assigning them to
4126 the positional parameters (or to array
4131 .It Fl U \*(Ba Fl o Ic utf8\-mode
4132 Enable UTF-8 support in the
4133 .Sx Emacs editing mode
4134 and internal string handling functions.
4135 This flag is disabled by default, but can be enabled by setting it on the
4136 shell command line; is enabled automatically for interactive shells if
4137 requested at compile time, your system supports
4138 .Fn setlocale LC_CTYPE \&""
4140 .Fn nl_langinfo CODESET ,
4146 environment variables,
4147 and at least one of these returns something that matches
4151 case-insensitively; for direct builtin calls depending on the
4152 aforementioned environment variables; or for stdin or scripts,
4153 if the input begins with a UTF-8 Byte Order Mark.
4155 In near future, locale tracking will be implemented, which means that
4157 is changed whenever one of the
4159 locale-related environment variables changes.
4160 .It Fl u \*(Ba Fl o Ic nounset
4161 Referencing of an unset parameter, other than
4165 is treated as an error, unless one of the
4171 .It Fl v \*(Ba Fl o Ic verbose
4172 Write shell input to standard error as it is read.
4173 .It Fl X \*(Ba Fl o Ic markdirs
4174 Mark directories with a trailing
4176 during file name generation.
4177 .It Fl x \*(Ba Fl o Ic xtrace
4178 Print command trees when they are executed, preceded by
4182 Background jobs are run with lower priority.
4183 .It Fl o Ic braceexpand
4184 Enable brace expansion (a.k.a. alternation).
4185 This is enabled by default.
4186 If disabled, tilde expansion after an equals sign is disabled as a side effect.
4188 Enable BRL emacs-like command-line editing (interactive shells only); see
4189 .Sx Emacs editing mode .
4191 Enable gmacs-like command-line editing (interactive shells only).
4192 Currently identical to emacs editing except that transpose\-chars (\*(haT) acts
4193 slightly differently.
4194 .It Fl o Ic ignoreeof
4195 The shell will not (easily) exit when end-of-file is read;
4198 To avoid infinite loops, the shell will exit if
4200 is read 13 times in a row.
4201 .It Fl o Ic inherit\-xtrace
4204 upon entering functions.
4205 This is enabled by default.
4207 Do not kill running jobs with a
4209 signal when a login shell exits.
4210 Currently set by default, but this may
4211 change in the future to be compatible with
4215 doesn't have this option, but does send the
4220 In the original Korn shell, this prevents function definitions from
4221 being stored in the history file.
4222 .It Fl o Ic physical
4229 (i.e. the filesystem's)
4231 directories instead of
4233 directories (i.e. the shell handles
4235 which allows the user to be oblivious of symbolic links to directories).
4237 Note that setting this option does not affect the current value of the
4247 commands above for more details.
4248 .It Fl o Ic pipefail
4249 Make the exit status of a pipeline (before logically complementing) the
4250 rightmost non-zero errorlevel, or zero if all commands exited with zero.
4252 Behave closer to the standards
4256 Automatically enabled if the basename of the shell invocation begins with
4258 and this autodetection feature is compiled in
4260 As a side effect, setting this flag turns off
4262 mode, which can be turned back on manually, and
4264 mode (unless both are enabled at the same time).
4271 Automatically enabled if the basename of the shell invocation begins with
4273 and this autodetection feature is compiled in
4275 As a side effect, setting this flag turns off
4277 mode, which can be turned back on manually, and
4279 mode (unless both are enabled at the same time).
4283 command-line editing (interactive shells only).
4286 for documentation and limitations.
4287 .It Fl o Ic vi\-esccomplete
4288 In vi command-line editing, do command and file name completion when escape
4289 (\*(ha[) is entered in command mode.
4290 .It Fl o Ic vi\-tabcomplete
4291 In vi command-line editing, do command and file name completion when tab (\*(haI)
4292 is entered in insert mode.
4293 This is the default.
4296 In the original Korn shell, unless
4298 was set, the vi command-line mode would let the
4300 driver do the work until ESC (\*(ha[) was entered.
4302 is always in viraw mode.
4305 These options can also be used upon invocation of the shell.
4307 options (with single letter names) can be found in the parameter
4310 with no option name will list all the options and whether each is on or off;
4312 will print the long names of all options that are currently on.
4314 Remaining arguments, if any, are positional parameters and are assigned, in
4315 order, to the positional parameters (i.e. $1, $2, etc.).
4318 and there are no remaining arguments, all positional parameters are cleared.
4319 If no options or arguments are given, the values of all names are printed.
4320 For unknown historical reasons, a lone
4322 option is treated specially \*(en it clears both the
4328 .It Ic shift Op Ar number
4329 The positional parameters
4339 .It Ic sleep Ar seconds
4340 Suspends execution for a minimum of the
4342 specified as positive decimal value with an optional fractional part.
4343 Signal delivery may continue execution earlier.
4345 .It Ic source Ar file Op Ar arg ...
4347 .Ic \&. Po Do dot Dc Pc ,
4348 except that the current working directory is appended to the
4354 Stops the shell as if it had received the suspend character from
4356 It is not possible to suspend a login shell unless the parent process
4357 is a member of the same terminal session but is a member of a different
4359 As a general rule, if the shell was started by another shell or via
4361 it can be suspended.
4363 .It Ic test Ar expression
4364 .It Ic \&[ Ar expression Ic \&]
4368 and returns zero status if true, 1 if false, or greater than 1 if there
4370 It is normally used as the condition command of
4375 Symbolic links are followed for all
4382 The following basic expressions are available:
4389 is a block special device.
4392 is a character special device.
4404 group is the shell's effective group ID.
4407 mode has the setgid bit set.
4410 is a context dependent directory (only useful on HP-UX).
4424 owner is the shell's effective user ID.
4430 command above for a list of options).
4431 As a non-standard extension, if the option starts with a
4433 the test is negated; the test always fails if
4435 doesn't exist (so [ \-o foo \-o \-o !foo ] returns true if and only if option
4438 The same can be achieved with [ \-o ?foo ] like in
4442 can also be the short flag led by either
4446 .Pq no logical negation ,
4459 exists and is readable.
4463 .Xr unix 4 Ns -domain
4476 mode has the setuid bit set.
4479 exists and is writable.
4482 exists and is executable.
4483 .It Ar file1 Fl nt Ar file2
4492 .It Ar file1 Fl ot Ar file2
4501 .It Ar file1 Fl ef Ar file2
4507 has non-zero length.
4514 .It Ar string No = Ar string
4516 .It Ar string No == Ar string
4518 .It Ar string No \*(Gt Ar string
4519 First string operand is greater than second string operand.
4520 .It Ar string No \*(Lt Ar string
4521 First string operand is less than second string operand.
4522 .It Ar string No != Ar string
4523 Strings are not equal.
4524 .It Ar number Fl eq Ar number
4525 Numbers compare equal.
4526 .It Ar number Fl ne Ar number
4527 Numbers compare not equal.
4528 .It Ar number Fl ge Ar number
4529 Numbers compare greater than or equal.
4530 .It Ar number Fl gt Ar number
4531 Numbers compare greater than.
4532 .It Ar number Fl le Ar number
4533 Numbers compare less than or equal.
4534 .It Ar number Fl \< Ar number
4535 Numbers compare less than.
4538 The above basic expressions, in which unary operators have precedence over
4539 binary operators, may be combined with the following operators (listed in
4540 increasing order of precedence):
4541 .Bd -literal -offset indent
4542 expr \-o expr Logical OR.
4543 expr \-a expr Logical AND.
4548 Note that a number actually may be an arithmetic expression, such as
4549 a mathematical term or the name of an integer variable:
4550 .Bd -literal -offset indent
4551 x=1; [ "x" \-eq 1 ] evaluates to true
4554 Note that some special rules are applied (courtesy of
4556 ) if the number of arguments to
4558 or inside the brackets
4560 is less than five: if leading
4562 arguments can be stripped such that only one to three arguments remain,
4563 then the lowered comparison is executed; (thanks to XSI) parentheses
4565 lower four- and three-argument forms to two- and one-argument forms,
4566 respectively; three-argument forms ultimately prefer binary operations,
4567 followed by negation and parenthesis lowering; two- and four-argument forms
4568 prefer negation followed by parenthesis; the one-argument form always implies
4572 A common mistake is to use
4573 .Dq if \&[ $foo = bar \&]
4574 which fails if parameter
4578 or unset, if it has embedded spaces (i.e.\&
4580 octets), or if it is a unary operator like
4585 .Dq if \&[ x\&"$foo\&" = x"bar" \&]
4586 instead, or the double-bracket operator
4587 .Dq if \&[[ $foo = bar \&]]
4588 or, to avoid pattern matching (see
4591 .Dq if \&[[ $foo = \&"$bar" \&]]
4595 construct is not only more secure to use but also often faster.
4604 is given, the times used to execute the pipeline are reported.
4606 is given, then the user and system time used by the shell itself, and all the
4607 commands it has run since it was started, are reported.
4608 The times reported are the real time (elapsed time from start to finish),
4609 the user CPU time (time spent running in user mode), and the system CPU time
4610 (time spent running in kernel mode).
4611 Times are reported to standard error; the format of the output is:
4613 .Dl "0m0.00s real 0m0.00s user 0m0.00s system"
4617 option is given the output is slightly longer:
4618 .Bd -literal -offset indent
4624 It is an error to specify the
4628 is a simple command.
4630 Simple redirections of standard error do not affect the output of the
4634 .Dl $ time sleep 1 2\*(Gtafile
4635 .Dl $ { time sleep 1; } 2\*(Gtafile
4637 Times for the first command do not go to
4639 but those of the second command do.
4642 Print the accumulated user and system times used both by the shell
4643 and by processes that the shell started which have exited.
4644 The format of the output is:
4645 .Bd -literal -offset indent
4650 .It Ic trap Ar n Op Ar signal ...
4651 If the first operand is a decimal unsigned integer, this resets all
4652 specified signals to the default action, i.e. is the same as calling
4658 followed by the arguments
4659 .Pq Ar n Op Ar signal ... ,
4660 all of which are treated as signals.
4662 .It Ic trap Op Ar handler signal ...
4663 Sets a trap handler that is to be executed when any of the specified
4667 is either an empty string, indicating the signals are to be ignored,
4670 indicating that the default action is to be taken for the signals
4671 .Pq see Xr signal 3 ,
4672 or a string containing shell commands to be executed at the first opportunity
4673 (i.e. when the current command completes, or before printing the next
4675 prompt) after receipt of one of the signals.
4677 is the name of a signal
4678 .Pq e.g.\& Dv PIPE or Dv ALRM
4679 or the number of the signal (see the
4683 There are two special signals:
4685 .Pq also known as 0 ,
4686 which is executed when the shell is about to exit, and
4688 which is executed after an error occurs; an error is something
4689 that would cause the shell to exit if the
4692 .Ic set Fl o Ic errexit
4695 handlers are executed in the environment of the last executed command.
4697 Note that, for non-interactive shells, the trap handler cannot be changed
4698 for signals that were ignored when the shell started.
4700 With no arguments, the current state of the traps that have been set since
4701 the shell started is shown as a series of
4704 Note that the output of
4706 cannot be usefully piped to another process (an artifact of the fact that
4707 traps are cleared when subprocesses are created).
4709 The original Korn shell's
4711 trap and the handling of
4715 traps in functions are not yet implemented.
4718 A command that exits with a zero value.
4722 .Oo Op Ic +\-alpnrtUux
4727 .No \*(Ba Fl f Op Fl tux Oc
4729 .Op Ns = Ns Ar value
4734 .Oo Op Ic +\-alpnrtUux
4735 .Op Fl LRZ Ns Op Ar n
4737 .No \*(Ba Fl f Op Fl tux Oc
4739 .Op Ns = Ns Ar value
4742 Display or set parameter attributes.
4745 arguments, parameter attributes are displayed; if no options are used, the
4746 current attributes of all parameters are printed as
4748 commands; if an option is given (or
4750 with no option letter), all parameters and their values with the specified
4751 attributes are printed; if options are introduced with
4753 parameter values are not printed.
4757 arguments are given, the attributes of the named parameters are set
4761 Values for parameters may optionally be specified.
4764 the change affects the entire array, and no value may be specified.
4768 is used inside a function, any parameters specified are localised.
4769 This is not done by the otherwise identical
4776 equivalent to other programming languages' as it does not allow a
4777 function called from another function to access a parameter at truly
4778 global scope, but only prevents putting an accessed one into local scope.
4784 operates on the attributes of functions.
4785 As with parameters, if no
4787 arguments are given,
4788 functions are listed with their values (i.e. definitions) unless
4789 options are introduced with
4791 in which case only the function names are reported.
4794 Indexed array attribute.
4797 Display or set functions and their attributes, instead of parameters.
4801 specifies the base to use when displaying the integer (if not specified, the
4802 base given in the first assignment is used).
4803 Parameters with this attribute may
4804 be assigned values containing arithmetic expressions.
4806 Left justify attribute.
4808 specifies the field width.
4811 is not specified, the current width of a parameter (or the width of its first
4812 assigned value) is used.
4813 Leading whitespace (and zeros, if used with the
4815 option) is stripped.
4816 If necessary, values are either truncated or space padded
4817 to fit the field width.
4819 Lower case attribute.
4820 All upper case characters in values are converted to lower case.
4821 (In the original Korn shell, this parameter meant
4827 Create a bound variable (name reference): any access to the variable
4829 will access the variable
4831 in the current scope (this is different from
4840 is lazily evaluated at the time
4843 This can be used by functions to access variables whose names are
4844 passed as parametres, instead of using
4849 commands that can be used to re-create the attributes and values of
4852 Right justify attribute.
4854 specifies the field width.
4857 is not specified, the current width of a parameter (or the width of its first
4858 assigned value) is used.
4859 Trailing whitespace is stripped.
4860 If necessary, values are either stripped of leading characters or space
4861 padded to make them fit the field width.
4863 Read-only attribute.
4864 Parameters with this attribute may not be assigned to or unset.
4865 Once this attribute is set, it cannot be turned off.
4868 Has no meaning to the shell; provided for application use.
4872 is the trace attribute.
4873 When functions with the trace attribute are executed, the
4876 shell option is temporarily turned on.
4878 Unsigned integer attribute.
4879 Integers are printed as unsigned values (combine with the
4882 This option is not in the original Korn shell.
4884 Upper case attribute.
4885 All lower case characters in values are converted to upper case.
4886 (In the original Korn shell, this parameter meant
4887 .Dq unsigned integer
4890 option which meant upper case letters would never be used for bases greater
4898 is the undefined attribute.
4901 above for the implications of this.
4904 Parameters (or functions) are placed in the environment of
4905 any executed commands.
4906 Exported functions are not yet implemented.
4908 Zero fill attribute.
4909 If not combined with
4913 except zero padding is used instead of space padding.
4914 For integers, the number instead of the base is padded.
4927 options are changed, all others from this set are cleared,
4928 unless they are also given on the same command line.
4932 .Op Fl aBCcdefHilMmnOPpqrSsTtVvw
4935 Display or set process limits.
4936 If no options are used, the file size limit
4940 if specified, may be either an arithmetic expression or the word
4942 The limits affect the shell and any processes created by the shell after a
4944 Note that some systems may not allow limits to be increased
4946 Also note that the types of limits available are system
4947 dependent \*(en some systems have only the
4952 Display all limits; unless
4954 is used, soft limits are displayed.
4956 Set the socket buffer size to
4960 Set the number of cached threads to
4963 Impose a size limit of
4965 blocks on the size of core dumps.
4967 Impose a size limit of
4969 kibibytes on the size of the data area.
4971 Set the maximum niceness to
4974 Impose a size limit of
4976 blocks on files written by the shell and its child processes (files of any
4979 Set the hard limit only (the default is to set both hard and soft limits).
4981 Set the number of pending signals to
4986 kibibytes on the amount of locked (wired) physical memory.
4988 Set the AIO locked memory to
4994 kibibytes on the amount of physical memory used.
4998 file descriptors that can be open at once.
5000 Set the number of AIO operations to
5003 Limit the number of threads per process to
5008 processes that can be run by the user at any one time.
5016 Set the maximum real-time priority to
5019 Set the soft limit only (the default is to set both hard and soft limits).
5021 Impose a size limit of
5023 kibibytes on the size of the stack area.
5025 Impose a time limit of
5027 real seconds to be used by each process.
5029 Impose a time limit of
5031 CPU seconds spent in user mode to be used by each process.
5033 Set the number of vnode monitors on Haiku to
5038 kibibytes on the amount of virtual memory (address space) used.
5042 kibibytes on the amount of swap space used.
5047 is concerned, a block is 512 bytes.
5054 Display or set the file permission creation mask, or umask (see
5058 option is used, the mask displayed or set is symbolic; otherwise, it is an
5061 Symbolic masks are like those used by
5063 When used, they describe what permissions may be made available (as opposed to
5064 octal masks in which a set bit means the corresponding bit is to be cleared).
5067 sets the mask so files will not be readable, writable, or executable by
5069 and is equivalent (on most systems) to the octal mask
5077 The aliases for the given names are removed.
5080 option is used, all aliases are removed.
5085 options are used, the indicated operations are carried out on tracked or
5086 directory aliases, respectively.
5093 Unset the named parameters
5101 .Ar parameter Ns \&[*] ,
5102 attributes are kept, only values are unset.
5104 The exit status is non-zero if any of the parameters have the read-only
5105 attribute set, zero otherwise.
5107 .It Ic wait Op Ar job ...
5108 Wait for the specified job(s) to finish.
5111 is that of the last specified job; if the last job is killed by a signal, the
5112 exit status is 128 + the number of the signal (see
5113 .Ic kill Fl l Ar exit-status
5114 above); if the last specified job can't be found (because it never existed, or
5115 had already finished), the exit status of
5120 below for the format of
5123 will return if a signal for which a trap has been set is received, or if a
5130 If no jobs are specified,
5132 waits for all currently running jobs (if any) to finish and exits with a zero
5134 If job monitoring is enabled, the completion status of jobs is printed
5135 (this is not the case when jobs are explicitly specified).
5144 the type of command is listed (reserved word, built-in, alias,
5145 function, tracked alias, or executable).
5148 option is used, a path search is performed even if
5150 is a reserved word, alias, etc.
5159 will find reserved words and won't print aliases as alias commands.
5170 option does not affect the search path used, as it does for
5172 If the type of one or more of the names could not be determined, the exit
5176 Job control refers to the shell's ability to monitor and control jobs which
5177 are processes or groups of processes created for commands or pipelines.
5178 At a minimum, the shell keeps track of the status of the background (i.e.\&
5179 asynchronous) jobs that currently exist; this information can be displayed
5183 If job control is fully enabled (using
5186 .Ic set Fl o Ic monitor ) ,
5187 as it is for interactive shells, the processes of a job are placed in their
5189 Foreground jobs can be stopped by typing the suspend
5190 character from the terminal (normally \*(haZ), jobs can be restarted in either the
5191 foreground or background using the
5195 commands, and the state of the terminal is saved or restored when a foreground
5196 job is stopped or restarted, respectively.
5198 Note that only commands that create processes (e.g. asynchronous commands,
5199 subshell commands, and non-built-in, non-function commands) can be stopped;
5204 When a job is created, it is assigned a job number.
5205 For interactive shells, this number is printed inside
5207 followed by the process IDs of the processes in the job when an asynchronous
5209 A job may be referred to in the
5216 commands either by the process ID of the last process in the command pipeline
5219 parameter) or by prefixing the job number with a percent
5222 Other percent sequences can also be used to refer to jobs:
5223 .Bl -tag -width "%+ x %% x %XX"
5224 .It %+ \*(Ba %% \*(Ba %
5225 The most recently stopped job, or, if there are no stopped jobs, the oldest
5228 The job that would be the
5230 job if the latter did not exist.
5232 The job with job number
5235 The job with its command containing the string
5237 (an error occurs if multiple jobs are matched).
5239 The job with its command starting with the string
5241 (an error occurs if multiple jobs are matched).
5244 When a job changes state (e.g. a background job finishes or foreground job is
5245 stopped), the shell prints the following status information:
5247 .D1 [ Ns Ar number ] Ar flag status command
5250 .Bl -tag -width "command"
5252 is the job number of the job;
5258 character if the job is the
5262 job, respectively, or space if it is neither;
5264 indicates the current state of the job and can be:
5265 .Bl -tag -width "RunningXX"
5266 .It Done Op Ar number
5269 is the exit status of the job which is omitted if the status is zero.
5271 The job has neither stopped nor exited (note that running does not necessarily
5272 mean consuming CPU time \*(en
5273 the process could be blocked waiting for some event).
5274 .It Stopped Op Ar signal
5275 The job was stopped by the indicated
5277 (if no signal is given, the job was stopped by
5279 .It Ar signal-description Op Dq core dumped
5280 The job was killed by a signal (e.g. memory fault, hangup); use
5282 for a list of signal descriptions.
5285 message indicates the process created a core file.
5288 is the command that created the process.
5289 If there are multiple processes in
5290 the job, each process will have a line showing its
5294 if it is different from the status of the previous process.
5297 When an attempt is made to exit the shell while there are jobs in the stopped
5298 state, the shell warns the user that there are stopped jobs and does not exit.
5299 If another attempt is immediately made to exit the shell, the stopped jobs are
5302 signal and the shell exits.
5305 option is not set and there are running jobs when an attempt is made to exit
5306 a login shell, the shell warns the user and does not exit.
5308 is immediately made to exit the shell, the running jobs are sent a
5310 signal and the shell exits.
5313 .Ic set Fl o Ic posix
5318 compliant in places where the defaults or opinions differ.
5321 will still operate with unsigned 32-bit arithmetics; use
5323 if arithmetics on the host
5325 data type, complete with ISO C Undefined Behaviour, are required;
5328 manual page for details.
5329 Most other historic,
5331 .Nm ksh Ns -compatible ,
5332 or opinionated differences can be disabled by using this mode; these are:
5338 .Ic &\*(Gt Ns Ar file
5339 is no longer supported.
5341 File descriptors created by I/O redirections are inherited by
5344 Numbers with a leading digit zero are interpreted as octal.
5348 builtin does not interpret backslashes and only supports the exact option
5351 \&... (list is incomplete and may change for R53)
5354 Compatibility mode; intended for use with legacy scripts that
5355 cannot easily be fixed; the changes are as follows:
5361 .Ic &\*(Gt Ns Ar file
5362 is no longer supported.
5364 File descriptors created by I/O redirections are inherited by
5369 builtin does not interpret backslashes and only supports the exact option
5372 \&... (list is incomplete and may change for R53)
5374 .Ss Interactive input line editing
5375 The shell supports three modes of reading command lines from a
5377 in an interactive session, controlled by the
5382 options (at most one of these can be set at once).
5385 Editing modes can be set explicitly using the
5388 If none of these options are enabled,
5389 the shell simply reads lines using the normal
5396 option is set, the shell allows emacs-like editing of the command; similarly,
5399 option is set, the shell allows vi-like editing of the command.
5400 These modes are described in detail in the following sections.
5402 In these editing modes, if a line is longer than the screen width (see the
5410 character is displayed in the last column indicating that there are more
5411 characters after, before and after, or before the current position,
5413 The line is scrolled horizontally as necessary.
5415 Completed lines are pushed into the history, unless they begin with an
5416 IFS octet or IFS white space, or are the same as the previous line.
5417 .Ss Emacs editing mode
5420 option is set, interactive input line editing is enabled.
5421 Warning: This mode is
5422 slightly different from the emacs mode in the original Korn shell.
5423 In this mode, various editing commands
5424 (typically bound to one or more control characters) cause immediate actions
5425 without waiting for a newline.
5426 Several editing commands are bound to particular
5427 control characters when the shell is invoked; these bindings can be changed
5432 The following is a list of available editing commands.
5433 Each description starts with the name of the command,
5434 suffixed with a colon;
5437 (if the command can be prefixed with a count); and any keys the command is
5438 bound to by default, written using caret notation
5439 e.g. the ASCII ESC character is written as \*(ha[.
5440 These control sequences are not case sensitive.
5441 A count prefix for a command is entered using the sequence
5442 .Pf \*(ha[ Ns Ar n ,
5445 is a sequence of 1 or more digits.
5446 Unless otherwise specified, if a count is
5447 omitted, it defaults to 1.
5449 Note that editing command names are used only with the
5452 Furthermore, many editing commands are useful only on terminals with
5454 The default bindings were chosen to resemble corresponding
5461 reasonable substitutes and override the default bindings.
5463 .It abort: \*(haC, \*(haG
5464 Abort the current command, empty the line buffer and
5465 set the exit state to interrupted.
5466 .It auto\-insert: Op Ar n
5467 Simply causes the character to appear as literal input.
5468 Most ordinary characters are bound to this.
5469 .It Xo backward\-char:
5471 .No \*(haB , \*(haXD , ANSI-CurLeft , PC-CurLeft
5473 Moves the cursor backward
5476 .It Xo backward\-word:
5478 .No \*(ha[b , ANSI-Ctrl-CurLeft , ANSI-Alt-CurLeft
5480 Moves the cursor backward to the beginning of the word; words consist of
5481 alphanumerics, underscore
5486 .It beginning\-of\-history: \*(ha[\*(Lt
5487 Moves to the beginning of the history.
5488 .It beginning\-of\-line: \*(haA, ANSI-Home, PC-Home
5489 Moves the cursor to the beginning of the edited input line.
5490 .It Xo capitalise\-word:
5492 .No \*(ha[C , \*(ha[c
5494 Uppercase the first character in the next
5496 words, leaving the cursor past the end of the last word.
5497 .It clear\-screen: \*(ha[\*(haL
5498 Prints a compile-time configurable sequence to clear the screen and home
5499 the cursor, redraws the entire prompt and the currently edited input line.
5500 The default sequence works for almost all standard terminals.
5501 .It comment: \*(ha[#
5502 If the current line does not begin with a comment character, one is added at
5503 the beginning of the line and the line is entered (as if return had been
5504 pressed); otherwise, the existing comment characters are removed and the cursor
5505 is placed at the beginning of the line.
5506 .It complete: \*(ha[\*(ha[
5507 Automatically completes as much as is unique of the command name or the file
5508 name containing the cursor.
5509 If the entire remaining command or file name is
5510 unique, a space is printed after its completion, unless it is a directory name
5514 If there is no command or file name with the current partial word
5515 as its prefix, a bell character is output (usually causing a beep to be
5517 .It complete\-command: \*(haX\*(ha[
5518 Automatically completes as much as is unique of the command name having the
5519 partial word up to the cursor as its prefix, as in the
5522 .It complete\-file: \*(ha[\*(haX
5523 Automatically completes as much as is unique of the file name having the
5524 partial word up to the cursor as its prefix, as in the
5526 command described above.
5527 .It complete\-list: \*(haI, \*(ha[=
5528 Complete as much as is possible of the current word,
5529 and list the possible completions for it.
5530 If only one completion is possible,
5534 Note that \*(haI is usually generated by the TAB (tabulator) key.
5535 .It Xo delete\-char\-backward:
5537 .No ERASE , \*(ha? , \*(haH
5541 characters before the cursor.
5542 .It Xo delete\-char\-forward:
5544 .No ANSI-Del , PC-Del
5548 characters after the cursor.
5549 .It Xo delete\-word\-backward:
5551 .No WERASE , \*(ha[\*(ha? , \*(ha[\*(haH , \*(ha[h
5555 words before the cursor.
5556 .It Xo delete\-word\-forward:
5560 Deletes characters after the cursor up to the end of
5563 .It Xo down\-history:
5565 .No \*(haN , \*(haXB , ANSI-CurDown , PC-CurDown
5567 Scrolls the history buffer forward
5570 Each input line originally starts just after the last entry
5571 in the history buffer, so
5573 is not useful until either
5574 .Ic search\-history ,
5575 .Ic search\-history\-up
5579 .It Xo downcase\-word:
5581 .No \*(ha[L , \*(ha[l
5592 or the current line, if not specified, interactively.
5593 The actual command executed is
5594 .Ic fc \-e ${VISUAL:\-${EDITOR:\-vi}} Ar n .
5595 .It end\-of\-history: \*(ha[\*(Gt
5596 Moves to the end of the history.
5597 .It end\-of\-line: \*(haE, ANSI-End, PC-End
5598 Moves the cursor to the end of the input line.
5600 Acts as an end-of-file; this is useful because edit-mode input disables
5601 normal terminal input canonicalization.
5602 .It Xo eot\-or\-delete:
5608 if alone on a line; otherwise acts as
5609 .Ic delete\-char\-forward .
5610 .It error: (not bound)
5611 Error (ring the bell).
5612 .It exchange\-point\-and\-mark: \*(haX\*(haX
5613 Places the cursor where the mark is and sets the mark to where the cursor was.
5614 .It expand\-file: \*(ha[*
5617 to the current word and replaces the word with the result of performing file
5618 globbing on the word.
5619 If no files match the pattern, the bell is rung.
5620 .It Xo forward\-char:
5622 .No \*(haF , \*(haXC , ANSI-CurRight , PC-CurRight
5624 Moves the cursor forward
5627 .It Xo forward\-word:
5629 .No \*(ha[f , ANSI-Ctrl-CurRight , ANSI-Alt-CurRight
5631 Moves the cursor forward to the end of the
5634 .It Xo goto\-history:
5638 Goes to history number
5640 .It kill\-line: KILL
5641 Deletes the entire input line.
5642 .It kill\-region: \*(haW
5643 Deletes the input between the cursor and the mark.
5644 .It Xo kill\-to\-eol:
5648 Deletes the input from the cursor to the end of the line if
5650 is not specified; otherwise deletes characters between the cursor and column
5653 Prints a sorted, columnated list of command names or file names (if any) that
5654 can complete the partial word containing the cursor.
5655 Directory names have
5658 .It list\-command: \*(haX?
5659 Prints a sorted, columnated list of command names (if any) that can complete
5660 the partial word containing the cursor.
5661 .It list\-file: \*(haX\*(haY
5662 Prints a sorted, columnated list of file names (if any) that can complete the
5663 partial word containing the cursor.
5664 File type indicators are appended as described under
5667 .It newline: \*(haJ , \*(haM
5668 Causes the current input line to be processed by the shell.
5669 The current cursor position may be anywhere on the line.
5670 .It newline\-and\-next: \*(haO
5671 Causes the current input line to be processed by the shell, and the next line
5672 from history becomes the current line.
5673 This is only useful after an
5677 .Ic search\-history\-up .
5680 .It prefix\-1: \*(ha[
5681 Introduces a 2-character command sequence.
5682 .It prefix\-2: \*(haX , \*(ha[[ , \*(ha[O
5683 Introduces a 2-character command sequence.
5684 .It Xo prev\-hist\-word:
5686 .No \*(ha[. , \*(ha[_
5688 The last word, or, if given, the
5690 word (zero-based) of the previous (on repeated execution, second-last,
5691 third-last, etc.) command is inserted at the cursor.
5692 Use of this editing command trashes the mark.
5693 .It quote: \*(ha\*(ha , \*(haV
5694 The following character is taken literally rather than as an editing command.
5696 Reprints the last line of the prompt string and the current input line
5698 .It Xo search\-character\-backward:
5702 Search backward in the current line for the
5704 occurrence of the next character typed.
5705 .It Xo search\-character\-forward:
5709 Search forward in the current line for the
5711 occurrence of the next character typed.
5712 .It search\-history: \*(haR
5713 Enter incremental search mode.
5714 The internal history list is searched
5715 backwards for commands matching the input.
5718 in the search string anchors the search.
5719 The escape key will leave search mode.
5720 Other commands, including sequences of escape as
5726 key will be executed after leaving search mode.
5729 command will restore the input line before search started.
5732 commands continue searching backward to the next previous occurrence of the
5734 The history buffer retains only a finite number of lines; the oldest
5735 are discarded as necessary.
5736 .It search\-history\-up: ANSI-PgUp, PC-PgUp
5737 Search backwards through the history buffer for commands whose beginning match
5738 the portion of the input line before the cursor.
5739 When used on an empty line, this has the same effect as
5741 .It search\-history\-down: ANSI-PgDn, PC-PgDn
5742 Search forwards through the history buffer for commands whose beginning match
5743 the portion of the input line before the cursor.
5744 When used on an empty line, this has the same effect as
5746 This is only useful after an
5750 .Ic search\-history\-up .
5751 .It set\-mark\-command: \*(ha[ Ns Aq space
5752 Set the mark at the cursor position.
5753 .It transpose\-chars: \*(haT
5754 If at the end of line, or if the
5756 option is set, this exchanges the two previous characters; otherwise, it
5757 exchanges the previous and current characters and moves the cursor one
5758 character to the right.
5761 .No \*(haP , \*(haXA , ANSI-CurUp , PC-CurUp
5763 Scrolls the history buffer backward
5766 .It Xo upcase\-word:
5768 .No \*(ha[U , \*(ha[u
5773 .It version: \*(ha[\*(haV
5774 Display the version of
5776 The current edit buffer is restored as soon as a key is pressed.
5777 The restoring keypress is processed, unless it is a space.
5779 Inserts the most recently killed text string at the current cursor position.
5780 .It yank\-pop: \*(ha[y
5783 replaces the inserted text string with the next previously killed text string.
5787 The vi command-line editing mode is orphaned, yet still functional.
5788 It is 8-bit clean but specifically does not support UTF-8 or MBCS.
5790 The vi command-line editor in
5792 has basically the same commands as the
5794 editor with the following exceptions:
5797 You start out in insert mode.
5799 There are file name and command completion commands:
5800 =, \e, *, \*(haX, \*(haE, \*(haF, and, optionally,
5807 command is different (in
5809 it is the last argument command; in
5811 it goes to the start of the current line).
5817 commands move in the opposite direction to the
5821 Commands which don't make sense in a single line editor are not available
5822 (e.g. screen movement commands and
5831 there are two modes:
5836 In insert mode, most characters are simply put in the buffer at the
5837 current cursor position as they are typed; however, some characters are
5839 In particular, the following characters are taken from current
5844 and have their usual meaning (normal values are in parentheses): kill (\*(haU),
5845 erase (\*(ha?), werase (\*(haW), eof (\*(haD), intr (\*(haC), and quit (\*(ha\e).
5847 the above, the following characters are also treated specially in insert mode:
5848 .Bl -tag -width XJXXXXM
5850 Command and file name enumeration (see below).
5852 Command and file name completion (see below).
5853 If used twice in a row, the
5854 list of possible completions is displayed; if used a third time, the completion
5857 Erases previous character.
5858 .It \*(haJ \*(Ba \*(haM
5860 The current line is read, parsed, and executed by the shell.
5863 The next character typed is not treated specially (can be used
5864 to insert the characters being described here).
5866 Command and file name expansion (see below).
5868 Puts the editor in command mode (see below).
5870 Optional file name and command completion (see
5872 above), enabled with
5873 .Ic set Fl o Ic vi\-tabcomplete .
5876 In command mode, each character is interpreted as a command.
5878 don't correspond to commands, are illegal combinations of commands, or are
5879 commands that can't be carried out, all cause beeps.
5880 In the following command descriptions, an
5882 indicates the command may be prefixed by a number (e.g.\&
5884 moves right 10 characters); if no number prefix is used,
5886 is assumed to be 1 unless otherwise specified.
5888 .Dq current position
5889 refers to the position between the cursor and the character preceding the
5893 is a sequence of letters, digits, and underscore characters or a sequence of
5894 non-letter, non-digit, non-underscore, and non-whitespace characters (e.g.\&
5896 contains two words) and a
5898 is a sequence of non-whitespace characters.
5904 The following commands are not in, or are different from, the normal vi file
5910 Insert a space followed by the
5912 big-word from the last command in the history at the current position and enter
5915 is not specified, the last word is inserted.
5917 Insert the comment character
5919 at the start of the current line and return the line to the shell (equivalent
5929 is not specified, it goes to the most recent remembered line.
5939 is not specified, the current line is edited.
5940 The actual command executed is
5941 .Ic fc \-e ${VISUAL:\-${EDITOR:\-vi}} Ar n .
5943 Command or file name expansion is applied to the current big-word (with an
5946 if the word contains no file globbing characters) \*(en the big-word is replaced
5947 with the resulting words.
5948 If the current big-word is the first on the line
5949 or follows one of the characters
5956 and does not contain a slash
5958 then command expansion is done; otherwise file name expansion is done.
5959 Command expansion will match the big-word against all aliases, functions, and
5960 built-in commands as well as any executable files found by searching the
5964 File name expansion matches the big-word against the files in the
5966 After expansion, the cursor is placed just past the last
5967 word and the editor is in insert mode.
5970 .Oo Ar n Oc Ns \*(haF ,
5971 .Oo Ar n Oc Ns Aq tab ,
5973 .Oo Ar n Oc Ns Aq esc
5975 Command/file name completion.
5976 Replace the current big-word with the
5977 longest unique match obtained after performing command and file name expansion.
5979 is only recognised if the
5981 option is set, while
5983 is only recognised if the
5991 possible completion is selected (as reported by the command/file name
5992 enumeration command).
5994 Command/file name enumeration.
5995 List all the commands or files that match the current big-word.
5997 Display the version of
5999 The current edit buffer is restored as soon as a key is pressed.
6000 The restoring keypress is ignored.
6003 Execute the commands found in the alias
6007 Intra-line movement commands:
6010 .Oo Ar n Oc Ns h and
6011 .Oo Ar n Oc Ns \*(haH
6017 .Oo Ar n Oc Ns l and
6018 .Oo Ar n Oc Ns Aq space
6026 Move to the first non-whitespace character.
6028 .Oo Ar n Oc Ns \*(Ba
6033 Move to the last character.
6049 Move forward to the end of the word,
6055 Move forward to the end of the big-word,
6072 The editor looks forward for the nearest parenthesis, bracket, or
6073 brace and then moves the cursor to the matching parenthesis, bracket, or brace.
6075 .Oo Ar n Oc Ns f Ns Ar c
6079 occurrence of the character
6082 .Oo Ar n Oc Ns F Ns Ar c
6084 Move backward to the
6086 occurrence of the character
6089 .Oo Ar n Oc Ns t Ns Ar c
6091 Move forward to just before the
6093 occurrence of the character
6096 .Oo Ar n Oc Ns T Ns Ar c
6098 Move backward to just before the
6100 occurrence of the character
6117 command, but moves in the opposite direction.
6120 Inter-line movement commands:
6126 .Oo Ar n Oc Ns \*(haN
6130 next line in the history.
6135 .Oo Ar n Oc Ns \*(haP
6139 previous line in the history.
6147 is not specified, the number of the first remembered line is used.
6155 is not specified, it goes to the most recent remembered line.
6157 .Oo Ar n Oc Ns / Ns Ar string
6159 Search backward through the history for the
6167 the remainder of the string must appear at the start of the history line for
6170 .Oo Ar n Oc Ns \&? Ns Ar string
6174 except it searches forward through the history.
6180 occurrence of the last search string;
6181 the direction of the search is the same as the last search.
6187 occurrence of the last search string;
6188 the direction of the search is the opposite of the last search.
6189 .It Ar ANSI-CurUp , PC-PgUp
6190 Take the characters from the beginning of the line to the current
6191 cursor position as search string and do a backwards history search
6192 for lines beginning with this string; keep the cursor position.
6193 This works only in insert mode and keeps it enabled.
6203 times; goes into insert mode just after the current position.
6205 only replicated if command mode is re-entered i.e.\&
6213 except it appends at the end of the line.
6219 times; goes into insert mode at the current position.
6220 The insertion is only
6221 replicated if command mode is re-entered i.e.\&
6229 except the insertion is done just before the first non-blank character.
6235 characters (i.e. delete the characters and go into insert mode).
6237 Substitute whole line.
6238 All characters from the first non-blank character to the
6239 end of the line are deleted and insert mode is entered.
6241 .Oo Ar n Oc Ns c Ns Ar move-cmd
6243 Change from the current position to the position resulting from
6245 (i.e. delete the indicated region and go into insert mode); if
6249 the line starting from the first non-blank character is changed.
6251 Change from the current position to the end of the line (i.e. delete to the
6252 end of the line and go into insert mode).
6266 Delete to the end of the line.
6268 .Oo Ar n Oc Ns d Ns Ar move-cmd
6270 Delete from the current position to the position resulting from
6271 .Ar n move-cmd Ns s ;
6273 is a movement command (see above) or
6275 in which case the current line is deleted.
6277 .Oo Ar n Oc Ns r Ns Ar c
6281 characters with the character
6287 Enter insert mode but overwrite existing characters instead of
6288 inserting before existing characters.
6289 The replacement is repeated
6293 .Oo Ar n Oc Ns \*(TI
6295 Change the case of the next
6299 .Oo Ar n Oc Ns y Ns Ar move-cmd
6301 Yank from the current position to the position resulting from
6303 into the yank buffer; if
6307 the whole line is yanked.
6309 Yank from the current position to the end of the line.
6313 Paste the contents of the yank buffer just after the current position,
6321 except the buffer is pasted at the current position.
6324 Miscellaneous vi commands
6326 .It \*(haJ and \*(haM
6327 The current line is read, parsed, and executed by the shell.
6328 .It \*(haL and \*(haR
6329 Redraw the current line.
6333 Redo the last edit command
6337 Undo the last edit command.
6339 Undo all changes that have been made to the current line.
6340 .It PC Home, End, Del, and cursor keys
6341 They move as expected, both in insert and command mode.
6342 .It Ar intr No and Ar quit
6343 The interrupt and quit terminal characters cause the current line to be
6344 deleted and a new prompt to be printed.
6347 .Bl -tag -width XetcXsuid_profile -compact
6348 .It Pa \*(TI/.mkshrc
6349 User mkshrc profile (non-privileged interactive shells); see
6351 The location can be changed at compile time (for embedded systems);
6352 AOSP Android builds use
6353 .Pa /system/etc/mkshrc .
6354 .It Pa \*(TI/.profile
6355 User profile (non-privileged login shells); see
6357 near the top of this manual.
6359 System profile (login shells); see
6363 .It Pa /etc/suid_profile
6364 Suid profile (privileged shells); see
6370 contains the system and suid profile.
6402 .Pa https://www.mirbsd.org/ksh\-chan.htm
6405 .%B "The KornShell Command and Programming Language"
6407 .%I "Prentice Hall PTR"
6408 .%P "xvi\ +\ 356 pages"
6409 .%O "ISBN 978\-0\-13\-516972\-8 (0\-13\-516972\-0)"
6412 .%A Morris I. Bolsky
6414 .%B "The New KornShell Command and Programming Language (2nd Edition)"
6416 .%I "Prentice Hall PTR"
6417 .%P "xvi\ +\ 400 pages"
6418 .%O "ISBN 978\-0\-13\-182700\-4 (0\-13\-182700\-6)"
6421 .%A Stephen G. Kochan
6423 .%B "\\*(tNUNIX\\*(sP Shell Programming"
6427 .%P "xiii\ +\ 437 pages"
6428 .%O "ISBN 978\-0\-672\-32490\-1 (0\-672\-32490\-3)"
6432 .%T "\\*(tNIEEE\\*(sP Standard for Information Technology \*(en Portable Operating System Interface (POSIX)"
6433 .%V "Part 2: Shell and Utilities"
6436 .%P "xvii\ +\ 1195 pages"
6437 .%O "ISBN 978\-1\-55937\-255\-8 (1\-55937\-255\-9)"
6441 .%B "Learning the Korn Shell"
6445 .%O "ISBN 978\-1\-56592\-054\-5 (1\-56592\-054\-6)"
6450 .%B "Learning the Korn Shell, Second Edition"
6454 .%O "ISBN 978\-0\-596\-00195\-7 (0\-596\-00195\-9)"
6458 .%B "KornShell Programming Tutorial"
6460 .%I "Addison-Wesley Professional"
6461 .%P "xxi\ +\ 324 pages"
6462 .%O "ISBN 978\-0\-201\-56324\-5 (0\-201\-56324\-X)"
6466 .Nm "The MirBSD Korn Shell"
6468 .An mirabilos Aq Mt m@mirbsd.org
6469 as part of The MirOS Project.
6470 This shell is based on the public domain 7th edition Bourne shell clone by
6471 .An Charles Forsyth ,
6472 who kindly agreed to, in countries where the Public Domain status of the work
6473 may not be valid, grant a copyright licence to the general public to deal in
6474 the work without restriction and permission to sublicence derivates under the
6475 terms of any (OSI approved) Open Source licence,
6476 and parts of the BRL shell by
6480 .An Arnold Robbins ,
6483 The first release of
6487 and it was subsequently maintained by
6488 .An John R. MacMillan ,
6489 .An Simon J. Gerraty ,
6491 .An Michael Rendell .
6492 The effort of several projects, such as Debian and OpenBSD, and other
6493 contributors including our users, to improve the shell is appreciated.
6494 See the documentation, CVS, and web site for details.
6496 The BSD daemon is Copyright \(co Marshall Kirk McKusick.
6497 The complete legalese is at:
6498 .Pa https://www.mirbsd.org/TaC\-mksh.txt
6500 .\" This boils down to: feel free to use mksh.ico as application icon
6501 .\" or shortcut for mksh or mksh/Win32 or OS/2; distro patches are ok
6502 .\" (but we request they amend $KSH_VERSION when modifying mksh).
6503 .\" Authors are Marshall Kirk McKusick (UCB), Rick Collette (ekkoBSD),
6504 .\" mirabilos, Benny Siegert (MirBSD), Michael Langguth (mksh/Win32),
6505 .\" KO Myung-Hun (mksh for OS/2).
6507 .\" As far as MirBSD is concerned, the files themselves are free
6508 .\" to modification and distribution under BSD/MirOS Licence, the
6509 .\" restriction on use stems only from trademark law's requirement
6510 .\" to protect it or lose it, which McKusick almost did.
6514 has a different scope model from
6517 which leads to subtile differences in semantics for identical builtins.
6518 This can cause issues with a
6520 to suddenly point to a local variable by accident; fixing this is hard.
6522 The parts of a pipeline, like below, are executed in subshells.
6523 Thus, variable assignments inside them are not visible in the
6524 surrounding execution environment.
6525 Use co-processes instead.
6526 .Bd -literal -offset indent
6527 foo \*(Ba bar \*(Ba read baz # will not change $baz
6528 foo \*(Ba bar \*(Ba& read \-p baz # will, however, do so
6532 provides a consistent set of 32-bit integer arithmetics, both signed
6533 and unsigned, with defined wraparound and sign of the result of a
6534 remainder operation, even (defying POSIX) on 36-bit and 64-bit systems.
6537 provides a consistent, clear interface normally.
6538 This may deviate from POSIX in historic or opinionated places.
6539 .Ic set Fl o Ic posix
6543 will cause the shell to behave more conformant.
6553 only supports the Unicode BMP (Basic Multilingual Plane) and maps
6554 raw octets into the U+EF80..U+EFFF wide character range; compare
6555 .Sx Arithmetic expressions .
6561 option dependent on the current
6563 locale for mksh to allow using the UTF-8 mode, within the constraints
6564 outlined above, in code portable across various shell implementations:
6565 .Bd -literal -offset indent
6566 case ${KSH_VERSION:\-} in
6567 *MIRBSD\ KSH*\*(Ba*LEGACY\ KSH*)
6568 case ${LC_ALL:\-${LC_CTYPE:\-${LANG:\-}}} in
6569 *[Uu][Tt][Ff]8*\*(Ba*[Uu][Tt][Ff]\-8*) set \-U ;;
6574 In near future, (Unicode) locale tracking will be implemented though.
6576 Suspending (using \*(haZ) pipelines like the one below will only suspend
6577 the currently running part of the pipeline; in this example,
6579 is immediately printed on suspension (but not later after an
6581 .Bd -literal -offset indent
6582 $ /bin/sleep 666 && echo fubar
6585 The truncation process involved when changing
6587 does not free old history entries (leaks memory) and leaks
6588 old entries into the new history if their line numbers are
6589 not overwritten by same-numer entries from the persistent
6590 history file; truncating the on-disc file to
6592 lines has always been broken and prone to history file corruption
6593 when multiple shells are accessing the file; the rollover process
6594 for the in-memory portion of the history is slow, should use
6597 Handling of backslash plus double-quote inside the (deprecated)
6598 .Pf \` Ns Ar command Ns \`
6599 form of command substitution when the substitution itself is
6600 also inside double quotes currently deliberately violates
6604 mode until Austin group bug 1015 has been resolved either way,
6605 as the current wording of the standard prohibits the current
6606 and historic practice of several shells which several scripts
6607 (admittedly wrongly) depend on.
6609 This document attempts to describe
6612 .\" with vendor patches from insert-your-name-here,
6613 compiled without any options impacting functionality, such as
6617 which, on some systems only, enables
6618 .Ic set Fl o Ic posix
6621 automatically (whose behaviour differs across targets),
6622 for an operating environment supporting all of its advanced needs.
6624 Please report bugs in
6629 .Aq Mt miros\-mksh@mirbsd.org
6634 .Pa irc.freenode.net
6635 .Pq Port 6697 SSL, 6667 unencrypted ,
6637 .Pa https://launchpad.net/mksh