1 .\" $MirOS: src/bin/mksh/mksh.1,v 1.442 2017/04/12 18:30:58 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, 2017
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 \& *before* a punctuation char that is to not
33 .\" be interpreted as punctuation, and especially with two-letter words
34 .\" but also (after) a period that does not end a sentence (“e.g.\&”).
35 .\" The section after the "doc" macropackage has been loaded contains
36 .\" additional code to convene between the UCB mdoc macropackage (and
37 .\" its variant as BSD mdoc in groff) and the GNU mdoc macropackage.
40 . if
\ 1\*[.T]
\ 1ascii
\ 1 .tr \-\N'45'
41 . if
\ 1\*[.T]
\ 1latin1
\ 1 .tr \-\N'45'
42 . if
\ 1\*[.T]
\ 1utf8
\ 1 .tr \-\N'45'
49 . if
\ 1\*[.T]
\ 1utf8
\ 1 .ds sL `
50 . if
\ 1\*[.T]
\ 1ps
\ 1 .ds sL `
51 . if
\ 1\*[.T]
\ 1utf8
\ 1 .ds sR '
52 . if
\ 1\*[.T]
\ 1ps
\ 1 .ds sR '
65 .\" Implement .Dd with the Mdocdate RCS keyword
69 .ie
\a\\$1
\a$Mdocdate:
\a \{\
72 .el .xD \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8
75 .\" .Dd must come before definition of .Mx, because when called
76 .\" with -mandoc, it might implement .Mx itself, but we want to
77 .\" use our own definition. And .Dd must come *first*, always.
79 .Dd $Mdocdate: April 12 2017 $
81 .\" Check which macro package we use, and do other -mdoc setup.
84 . if
\ 1\*[.T]
\ 1utf8
\ 1 .tr \[la]\*(Lt
85 . if
\ 1\*[.T]
\ 1utf8
\ 1 .tr \[ra]\*(Gt
86 . ie d volume-ds-1 .ds tT gnu
91 .\" Implement .Mx (MirBSD)
97 . nr curr-size \n[.ps]
98 . ds str-Mx \f[\n[curr-font]]\s[\n[curr-size]u]
99 . ds str-Mx1 \*[Tn-font-size]\%MirOS\*[str-Mx]
100 . if !\n[arg-limit] \
105 . if (\n[arg-limit] > \n[arg-ptr]) \{\
107 . ie (\n[type\n[arg-ptr]] == 2) \
108 . as str-Mx1 \~\*[arg\n[arg-ptr]]
112 . ds arg\n[arg-ptr] "\*[str-Mx1]
113 . nr type\n[arg-ptr] 2
114 . ds space\n[arg-ptr] "\*[space]
115 . nr num-args (\n[arg-limit] - \n[arg-ptr])
116 . nr arg-limit \n[arg-ptr]
123 . ds tN \*[Tn-font-size]
129 . ds aa \&\f\\n(cF\s\\n(cZ
131 . ie \\n(.$==0 \&MirOS\\*(aa
132 . el .aV \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
134 . if \\n(aC>\\n(aP \{\
136 . ie \\n(C\\n(aP==2 \{\
137 . as b1 \&MirOS\ #\&\\*(A\\n(aP\\*(aa
138 . ie \\n(aC>\\n(aP \{\
145 . as b1 \&MirOS\\*(aa
157 .Nd MirBSD Korn shell
161 .Op Fl +abCefhiklmnprUuvXx
163 .Fl T Oo Ar \&! Oc Ns Ar tty
169 .Fl c Ar string \*(Ba
179 is a command interpreter intended for both interactive and shell
181 Its command language is a superset of the
183 shell language and largely compatible to the original Korn shell.
184 At times, this manual page may give scripting advice; while it
185 sometimes does take portable shell scripting or various standards
186 into account all information is first and foremost presented with
188 in mind and should be taken as such.
189 .Ss I use Android, OS/2, etc. so what...?
190 Please see the FAQ at the end of this document.
192 Most builtins can be called directly, for example if a link points from its
193 name to the shell; not all make sense, have been tested or work at all though.
195 The options are as follows:
196 .Bl -tag -width XcXstring
199 will execute the command(s) contained in
203 A shell that reads commands from standard input is
206 option is used or if both standard input and standard error are attached
209 An interactive shell has job control enabled, ignores the
214 signals, and prints prompts before reading input (see the
219 It also processes the
224 For non-interactive shells, the
226 option is on by default (see the
231 If the basename the shell is called with (i.e. argv[0])
234 or if this option is used,
235 the shell is assumed to be a login shell; see
242 if the real user ID or group ID does not match the
243 effective user ID or group ID (see
247 Clearing the privileged option causes the shell to set
248 its effective user ID (group ID) to its real user ID (group ID).
249 For further implications, see
251 If the shell is privileged and this flag is not explicitly set, the
253 option is cleared automatically after processing the startup files.
260 The following restrictions come into effect after the shell processes any
277 parameters cannot be changed.
279 Command names can't be specified with absolute or relative paths.
283 option of the built-in command
287 Redirections that create files can't be used (i.e.\&
291 .Dq Li \*(Lt\*(Gt ) .
294 The shell reads commands from standard input; all non-option arguments
295 are positional parameters.
304 .Pa /dev/ttyC Ns Ar name
306 .Pa /dev/tty Ns Ar name
307 are attempted in order.
310 begins with an exclamation mark
312 this is done in a subshell and returns immediately.
317 detach from controlling terminal (daemonise) instead.
320 In addition to the above, the options described in the
322 built-in command can also be used on the command line:
324 .Op Fl +abCefhkmnuvXx
327 can be used for single letter or long options, respectively.
333 option is specified, the first non-option argument specifies the name
334 of a file the shell reads commands from.
335 If there are no non-option
336 arguments, the shell reads commands from the standard input.
337 The name of the shell (i.e. the contents of $0)
338 is determined as follows: if the
340 option is used and there is a non-option argument, it is used as the name;
341 if commands are being read from a file, the file is used as the name;
342 otherwise, the basename the shell was called with (i.e. argv[0]) is used.
344 The exit status of the shell is 127 if the command file specified on the
345 command line could not be opened, or non-zero if a fatal syntax error
346 occurred during the execution of a script.
347 In the absence of fatal errors,
348 the exit status is that of the last command executed, or zero if no
351 For the actual location of these files, see
353 A login shell processes the system profile first.
354 A privileged shell then processes the suid profile.
355 A non-privileged login shell processes the user profile next.
356 A non-privileged interactive shell checks the value of the
358 parameter after subjecting it to parameter, command, arithmetic and tilde
360 substitution; if unset or empty, the user mkshrc profile is processed;
361 otherwise, if a file whose name is the substitution result exists,
362 it is processed; non-existence is silently ignored.
363 A privileged shell then drops privileges if neither was the
365 option given on the command line nor set during execution of the startup files.
367 The shell begins parsing its input by removing any backslash-newline
368 combinations, then breaking it into
370 Words (which are sequences of characters) are delimited by unquoted whitespace
371 characters (space, tab and newline) or meta-characters
382 Aside from delimiting words, spaces and tabs are ignored, while newlines
383 usually delimit commands.
384 The meta-characters are used in building the following
389 .Dq Li \*(Lt\*(Lt\*(Lt ,
394 etc. are used to specify redirections (see
395 .Sx Input/output redirection
398 is used to create pipelines;
400 is used to create co-processes (see
404 is used to separate commands;
406 is used to create asynchronous pipelines;
410 are used to specify conditional execution;
419 is used in arithmetic expressions;
422 is used to create subshells.
424 Whitespace and meta-characters can be quoted individually using a backslash
426 or in groups using double
431 Note that the following characters are also treated specially by the
432 shell and must be quoted if they are to represent themselves:
446 The first three of these are the above mentioned quoting characters (see
450 if used at the beginning of a word, introduces a comment \*(en everything after
453 up to the nearest newline is ignored;
455 is used to introduce parameter, command and arithmetic substitutions (see
459 introduces an old-style command substitution (see
463 begins a directory expansion (see
479 are used in file name generation (see
480 .Sx File name patterns
483 As words and tokens are parsed, the shell builds commands, of which there
485 .Em simple-commands ,
486 typically programmes that are executed, and
487 .Em compound-commands ,
492 statements, grouping constructs and function definitions.
494 A simple-command consists of some combination of parameter assignments
498 input/output redirections (see
499 .Sx Input/output redirections
501 and command words; the only restriction is that parameter assignments come
502 before any command words.
503 The command words, if any, define the command
504 that is to be executed and its arguments.
505 The command may be a shell built-in command, a function
506 or an external command
507 (i.e. a separate executable file that is located using the
510 .Sx Command execution
512 Note that all command constructs have an exit status: for external commands,
513 this is related to the status returned by
515 (if the command could not be found, the exit status is 127; if it could not
516 be executed, the exit status is 126); the exit status of other command
517 constructs (built-in commands, functions, compound-commands, pipelines, lists,
518 etc.) are all well-defined and are described where the construct is
520 The exit status of a command consisting only of parameter
521 assignments is that of the last command substitution performed during the
522 parameter assignment or 0 if there were no command substitutions.
524 Commands can be chained together using the
526 token to form pipelines, in which the standard output of each command but the
529 to the standard input of the following command.
530 The exit status of a pipeline is that of its last command, unless the
532 option is set (see there).
533 All commands of a pipeline are executed in separate subshells;
534 this is allowed by POSIX but differs from both variants of
537 where all but the last command were executed in subshells; see the
539 builtin's description for implications and workarounds.
540 A pipeline may be prefixed by the
542 reserved word which causes the exit status of the pipeline to be logically
543 complemented: if the original status was 0, the complemented status will be 1;
544 if the original status was not 0, the complemented status will be 0.
547 of commands can be created by separating pipelines by any of the following
555 The first two are for conditional execution:
556 .Dq Ar cmd1 No && Ar cmd2
559 only if the exit status of
563 is the opposite \*(en
565 is executed only if the exit status of
571 have equal precedence which is higher than that of
576 which also have equal precedence.
582 .Qq left-associative .
583 For example, both of these commands will print only
585 .Bd -literal -offset indent
586 $ false && echo foo \*(Ba\*(Ba echo bar
587 $ true \*(Ba\*(Ba echo foo && echo bar
592 token causes the preceding command to be executed asynchronously; that is,
593 the shell starts the command but does not wait for it to complete (the shell
594 does keep track of the status of asynchronous commands; see
597 When an asynchronous command is started when job control is disabled
598 (i.e. in most scripts), the command is started with signals
602 ignored and with input redirected from
604 (however, redirections specified in the asynchronous command have precedence).
607 operator starts a co-process which is a special kind of asynchronous process
611 Note that a command must follow the
615 operators, while it need not follow
620 The exit status of a list is that of the last command executed, with the
621 exception of asynchronous lists, for which the exit status is 0.
623 Compound commands are created using the following reserved words.
625 are only recognised if they are unquoted and if they are used as the first
626 word of a command (i.e. they can't be preceded by parameter assignments or
628 .Bd -literal -offset indent
629 case else function then ! (
630 do esac if time [[ ((
632 elif for select while }
635 In the following compound command descriptions, command lists (denoted as
637 that are followed by reserved words must end with a semicolon, a newline or
638 a (syntactically correct) reserved word.
639 For example, the following are all valid:
640 .Bd -literal -offset indent
641 $ { echo foo; echo bar; }
642 $ { echo foo; echo bar\*(Ltnewline\*(Gt}
643 $ { { echo foo; echo bar; } }
648 .Dl $ { echo foo; echo bar }
654 There is no implicit way to pass environment changes from a
655 subshell back to its parent.
659 is executed, but not in a subshell.
664 are reserved words, not meta-characters.
665 .It Xo case Ar word No in
676 statement attempts to match
682 associated with the first successfully matched pattern is executed.
685 statements are the same as those used for file name patterns except that the
686 restrictions regarding
691 Note that any unquoted space before and after a pattern is
692 stripped; any space within a pattern must be quoted.
693 Both the word and the
694 patterns are subject to parameter, command and arithmetic substitution, as
695 well as tilde substitution.
697 For historical reasons, open and close braces may be used instead of
702 .Ic case $foo { *) echo bar ;; } .
709 Terminate after the list.
711 Fall through into the next list.
713 Evaluate the remaining pattern-list tuples.
718 statement is that of the executed
722 is executed, the exit status is zero.
724 .Oo in Ar word No ... Oc ;
725 .No do Ar list ; No done
729 in the specified word list, the parameter
731 is set to the word and
736 is not used to specify a word list, the positional parameters ($1, $2,
737 etc.) are used instead.
738 For historical reasons, open and close braces may be used instead of
743 .Ic for i; { echo $i; } .
746 statement is the last exit status of
750 is never executed, the exit status is zero.
754 .No then Ar list ; Oc
756 .Oo else Ar list ; Oc
759 If the exit status of the first
763 is executed; otherwise, the
767 if any, is executed with similar consequences.
768 If all the lists following the
772 fail (i.e. exit with non-zero status), the
777 The exit status of an
779 statement is that of non-conditional
781 that is executed; if no non-conditional
783 is executed, the exit status is zero.
784 .It Xo select Ar name
785 .Oo in Ar word No ... Oc ;
786 .No do Ar list ; No done
790 statement provides an automatic method of presenting the user with a menu and
792 An enumerated list of the specified
794 is printed on standard error, followed by a prompt
800 A number corresponding to one of the enumerated words is then read from
803 is set to the selected word (or unset if the selection is not valid),
805 is set to what was read (leading/trailing space is stripped), and
808 If a blank line (i.e. zero or more
810 octets) is entered, the menu is reprinted without executing
815 completes, the enumerated list is printed if
817 is empty, the prompt is printed, and so on.
818 This process continues until an end-of-file
819 is read, an interrupt is received, or a
821 statement is executed inside the loop.
824 is omitted, the positional parameters are used
826 For historical reasons, open and close braces may be used instead of
831 .Ic select i; { echo $i; } .
834 statement is zero if a
836 statement is used to exit the loop, non-zero otherwise.
837 .It Xo until Ar list ;
843 except that the body is executed only while the exit status of the first
846 .It Xo while Ar list ;
852 is a pre-checked loop.
853 Its body is executed as often as the exit status of the first
858 statement is the last exit status of the
860 in the body of the loop; if the body is not executed, the exit status is zero.
861 .It Xo function Ar name
869 Note that redirections specified after a function definition are
870 performed whenever the function is executed, not when the function definition
872 .It Ar name Ns \&() Ar command
878 Whitespace (space or tab) after
880 will be ignored most of the time.
881 .It Xo function Ar name Ns \&()
890 .It Xo Ic time Op Fl p
894 .Sx Command execution
895 section describes the
898 .It \&(( Ar expression No ))
899 The arithmetic expression
901 is evaluated; equivalent to
902 .Dq Li let \&" Ns Ar expression Ns \&"
904 .Sx Arithmetic expressions
907 command, below) in a compound construct.
908 .It Bq Bq Ar \ \&expression\ \&
913 commands (described later), with the following exceptions:
916 Field splitting and file name generation are not performed on arguments.
924 operators are replaced with
936 Parameter, command and arithmetic substitutions are performed as expressions
937 are evaluated and lazy expression evaluation is used for the
942 This means that in the following statement,
944 is evaluated if and only if the file
946 exists and is readable:
947 .Bd -literal -offset indent
948 $ [[ \-r foo && $(\*(Ltfoo) = b*r ]]
951 The second operand of the
955 expressions are a subset of patterns (e.g. the comparison
956 .Ic \&[[ foobar = f*r ]]
958 This even works indirectly:
959 .Bd -literal -offset indent
960 $ bar=foobar; baz=\*(aqf*r\*(aq
961 $ [[ $bar = $baz ]]; echo $?
962 $ [[ $bar = \&"$baz" ]]; echo $?
965 Perhaps surprisingly, the first comparison succeeds,
966 whereas the second doesn't.
967 This does not apply to all extglob metacharacters, currently.
971 Quoting is used to prevent the shell from treating characters or words
973 There are three methods of quoting.
976 quotes the following character, unless it is at the end of a line, in which
979 and the newline are stripped.
980 Second, a single quote
982 quotes everything up to the next single quote (this may span lines).
983 Third, a double quote
985 quotes all characters, except
990 up to the next unescaped double quote.
994 inside double quotes have their usual meaning (i.e. parameter, arithmetic
995 or command substitution) except no field splitting is carried out on the
996 results of double-quoted substitutions, and the old-style form of command
997 substitution has backslash-quoting for double quotes enabled.
1000 inside a double-quoted string is followed by
1008 is removed, i.e. the combination is replaced by the second character;
1009 if it is followed by a newline, both the
1011 and the newline are stripped; otherwise, both the
1013 and the character following are unchanged.
1015 If a single-quoted string is preceded by an unquoted
1017 C style backslash expansion (see below) is applied (even single quote
1018 characters inside can be escaped and do not terminate the string then);
1019 the expanded result is treated as any other single-quoted string.
1020 If a double-quoted string is preceded by an unquoted
1025 .Ss Backslash expansion
1026 In places where backslashes are expanded, certain C and
1031 style escapes are translated.
1039 .Dq Li \eU######## ,
1048 means a hexadecimal digit, of which there may be none up to four or eight;
1049 these escapes translate a Unicode codepoint to UTF-8.
1054 expand to the escape character.
1063 are explicitly excluded;
1064 octal sequences must have the none up to three octal digits
1066 prefixed with the digit zero
1068 hexadecimal sequences
1070 are limited to none up to two hexadecimal digits
1072 both octal and hexadecimal sequences convert to raw octets;
1074 where # is none of the above, translates to \e# (backslashes are retained).
1076 Backslash expansion in the C style mode slightly differs: octal sequences
1078 must have no digit zero prefixing the one up to three octal digits
1080 and yield raw octets; hexadecimal sequences
1082 greedily eat up as many hexadecimal digits
1084 as they can and terminate with the first non-hexadecimal digit;
1085 these translate a Unicode codepoint to UTF-8.
1090 is any octet, translates to Ctrl-# (which basically means,
1092 becomes DEL, everything else is bitwise ANDed with 0x1F).
1095 where # is none of the above, translates to # (has the backslash trimmed),
1096 even if it is a newline.
1098 There are two types of aliases: normal command aliases and tracked aliases.
1099 Command aliases are normally used as a short hand for a long or often used
1101 The shell expands command aliases (i.e. substitutes the alias name
1102 for its value) when it reads the first word of a command.
1103 An expanded alias is re-processed to check for more aliases.
1104 If a command alias ends in a
1105 space or tab, the following word is also checked for alias expansion.
1106 The alias expansion process stops when a word that is not an alias is found,
1107 when a quoted word is found, or when an alias word that is currently being
1109 Aliases are specifically an interactive feature: while they do happen
1110 to work in scripts and on the command line in some cases, aliases are
1111 expanded during lexing, so their use must be in a separate command tree
1112 from their definition; otherwise, the alias will not be found.
1113 Noticeably, command lists (separated by semicolon, in command substitutions
1114 also by newline) may be one same parse tree.
1116 The following command aliases are defined automatically by the shell:
1117 .Bd -literal -offset indent
1118 autoload=\*(aq\e\ebuiltin typeset \-fu\*(aq
1119 functions=\*(aq\e\ebuiltin typeset \-f\*(aq
1120 hash=\*(aq\e\ebuiltin alias \-t\*(aq
1121 history=\*(aq\e\ebuiltin fc \-l\*(aq
1122 integer=\*(aq\e\ebuiltin typeset \-i\*(aq
1123 local=\*(aq\e\ebuiltin typeset\*(aq
1124 login=\*(aq\e\ebuiltin exec login\*(aq
1125 nameref=\*(aq\e\ebuiltin typeset \-n\*(aq
1126 nohup=\*(aqnohup \*(aq
1127 r=\*(aq\e\ebuiltin fc \-e \-\*(aq
1128 type=\*(aq\e\ebuiltin whence \-v\*(aq
1131 Tracked aliases allow the shell to remember where it found a particular
1133 The first time the shell does a path search for a command that is
1134 marked as a tracked alias, it saves the full path of the command.
1136 time the command is executed, the shell checks the saved path to see that it
1137 is still valid, and if so, avoids repeating the path search.
1138 Tracked aliases can be listed and created using
1140 Note that changing the
1142 parameter clears the saved paths for all tracked aliases.
1145 option is set (i.e.\&
1146 .Ic set Fl o Ic trackall
1149 the shell tracks all commands.
1150 This option is set automatically for non-interactive shells.
1151 For interactive shells, only the following commands are
1152 automatically tracked:
1172 The first step the shell takes in executing a simple-command is to perform
1173 substitutions on the words of the command.
1174 There are three kinds of
1175 substitution: parameter, command and arithmetic.
1176 Parameter substitutions,
1177 which are described in detail in the next section, take the form
1180 .Pf ${ Ns Ar ... Ns } ;
1181 command substitutions take the form
1182 .Pf $( Ns Ar command Ns \&)
1184 .Pf \` Ns Ar command Ns \`
1185 or (executed in the current environment)
1186 .Pf ${\ \& Ar command Ns \&;}
1187 and strip trailing newlines;
1188 and arithmetic substitutions take the form
1189 .Pf $(( Ns Ar expression Ns )) .
1190 Parsing the current-environment command substitution requires a space,
1191 tab or newline after the opening brace and that the closing brace be
1192 recognised as a keyword (i.e. is preceded by a newline or semicolon).
1193 They are also called funsubs (function substitutions) and behave like
1200 terminates the parent shell; shell options are shared.
1202 Another variant of substitution are the valsubs (value substitutions)
1203 .Pf ${\*(Ba\& Ns Ar command Ns \&;}
1204 which are also executed in the current environment, like funsubs, but
1205 share their I/O with the parent; instead, they evaluate to whatever
1206 the, initially empty, expression-local variable
1208 is set to within the
1211 If a substitution appears outside of double quotes, the results of the
1212 substitution are generally subject to word or field splitting according to
1213 the current value of the
1218 parameter specifies a list of octets which are used to break a string up
1219 into several words; any octets from the set space, tab and newline that
1223 .Dq IFS whitespace .
1224 Sequences of one or more
1226 whitespace octets, in combination with zero or one
1228 whitespace octets, delimit a field.
1229 As a special case, leading and trailing
1231 whitespace is stripped (i.e. no leading or trailing empty field
1232 is created by it); leading or trailing
1234 whitespace does create an empty field.
1239 .Dq Li \*(Ltspace\*(Gt:
1241 .Dq Li \*(Ltspace\*(GtA\*(Ltspace\*(Gt:\*(Ltspace\*(Gt\*(Ltspace\*(GtB::D ,
1242 the substitution for $VAR results in four fields:
1246 (an empty field) and
1250 parameter is set to the empty string, no field splitting is done;
1251 if it is unset, the default value of space, tab and newline is used.
1253 Also, note that the field splitting applies only to the immediate result of
1255 Using the previous example, the substitution for $VAR:E
1256 results in the fields:
1269 This behavior is POSIX compliant, but incompatible with some other shell
1270 implementations which do field splitting on the word which contained the
1273 as a general whitespace delimiter.
1275 The results of substitution are, unless otherwise specified, also subject to
1276 brace expansion and file name expansion (see the relevant sections below).
1278 A command substitution is replaced by the output generated by the specified
1279 command which is run in a subshell.
1281 .Pf $( Ns Ar command Ns \&)
1283 .Pf ${\*(Ba\& Ns Ar command Ns \&;}
1285 .Pf ${\ \& Ar command Ns \&;}
1286 substitutions, normal quoting rules are used when
1288 is parsed; however, for the deprecated
1289 .Pf \` Ns Ar command Ns \`
1299 when the substitution is part of a double-quoted string); a backslash
1301 followed by any other character is unchanged.
1302 As a special case in command substitutions, a command of the form
1304 is interpreted to mean substitute the contents of
1308 has the same effect as
1311 Note that some shells do not use a recursive parser for command substitutions,
1312 leading to failure for certain constructs; to be portable, use as workaround
1313 .Dq Li x=$(cat) \*(Lt\*(Lt\eEOF
1314 (or the newline-keeping
1315 .Dq Li x=\*(Lt\*(Lt\eEOF
1316 extension) instead to merely slurp the string.
1318 recommends using case statements of the form
1319 .Li "x=$(case $foo in (bar) echo $bar ;; (*) echo $baz ;; esac)"
1320 instead, which would work but not serve as example for this portability issue.
1321 .Bd -literal -offset indent
1322 x=$(case $foo in bar) echo $bar ;; *) echo $baz ;; esac)
1323 # above fails to parse on old shells; below is the workaround
1324 x=$(eval $(cat)) \*(Lt\*(Lt\eEOF
1325 case $foo in bar) echo $bar ;; *) echo $baz ;; esac
1329 Arithmetic substitutions are replaced by the value of the specified expression.
1330 For example, the command
1331 .Ic print $((2+3*4))
1334 .Sx Arithmetic expressions
1335 for a description of an expression.
1337 Parameters are shell variables; they can be assigned values and their values
1338 can be accessed using a parameter substitution.
1339 A parameter name is either one
1340 of the special single punctuation or digit character parameters described
1341 below, or a letter followed by zero or more letters or digits
1346 The latter form can be treated as arrays by appending an array index of the
1351 is an arithmetic expression.
1354 are limited to the range 0 through 4294967295, inclusive.
1355 That is, they are a 32-bit unsigned integer.
1357 Parameter substitutions take the form
1359 .Pf ${ Ns Ar name Ns }
1362 .Pf ${ Ar name Oo Ar expr Oc }
1366 is a parameter name.
1367 Substitution of all array elements with
1368 .Pf ${ Ns Ar name Ns \&[*]}
1370 .Pf ${ Ns Ar name Ns \&[@]}
1371 works equivalent to $* and $@ for positional parameters.
1372 If substitution is performed on a parameter
1373 (or an array parameter element)
1374 that is not set, an empty string is substituted unless the
1378 is set, in which case an error occurs.
1380 Parameters can be assigned values in a number of ways.
1381 First, the shell implicitly sets some parameters like
1386 this is the only way the special single character parameters are set.
1387 Second, parameters are imported from the shell's environment at startup.
1388 Third, parameters can be assigned values on the command line: for example,
1394 multiple parameter assignments can be given on a single command line and they
1395 can be followed by a simple-command, in which case the assignments are in
1396 effect only for the duration of the command (such assignments are also
1397 exported; see below for the implications of this).
1398 Note that both the parameter name and the
1400 must be unquoted for the shell to recognise a parameter assignment.
1403 is also recognised; the old and new values are immediately concatenated.
1404 The fourth way of setting a parameter is with the
1410 commands; see their descriptions in the
1411 .Sx Command execution
1417 loops set parameters as well as the
1423 Lastly, parameters can be assigned values using assignment operators
1424 inside arithmetic expressions (see
1425 .Sx Arithmetic expressions
1428 .Pf ${ Ar name No = Ar value No }
1430 form of the parameter substitution (see below).
1432 Parameters with the export attribute (set using the
1436 commands, or by parameter assignments followed by simple commands) are put in
1437 the environment (see
1439 of commands run by the shell as
1440 .Ar name Ns = Ns Ar value
1442 The order in which parameters appear in the environment of a command is
1444 When the shell starts up, it extracts parameters and their values
1445 from its environment and automatically sets the export attribute for those
1448 Modifiers can be applied to the
1449 .Pf ${ Ns Ar name Ns }
1450 form of parameter substitution:
1453 .It ${ Ar name No :\- Ar word No }
1457 is set and not empty,
1458 it is substituted; otherwise,
1462 .It ${ Ar name No :+ Ar word No }
1466 is set and not empty,
1468 is substituted; otherwise, nothing is substituted.
1470 .It ${ Ar name No := Ar word No }
1474 is set and not empty,
1475 it is substituted; otherwise, it is assigned
1477 and the resulting value of
1481 .It ${ Ar name No :? Ar word No }
1485 is set and not empty,
1486 it is substituted; otherwise,
1488 is printed on standard error (preceded by
1490 and an error occurs (normally causing termination of a shell script, function,
1491 or a script sourced using the
1496 is omitted, the string
1497 .Dq Li parameter null or not set
1501 Note that, for all of the above,
1503 is actually considered quoted, and special parsing rules apply.
1504 The parsing rules also differ on whether the expression is double-quoted:
1506 then uses double-quoting rules, except for the double quote itself
1508 and the closing brace, which, if backslash escaped, gets quote removal applied.
1510 In the above modifiers, the
1512 can be omitted, in which case the conditions only depend on
1514 being set (as opposed to set and not empty).
1517 is needed, parameter, command, arithmetic and tilde substitution are performed
1520 is not needed, it is not evaluated.
1522 The following forms of parameter substitution can also be used (if
1524 is an array, the element with the key
1526 will be substituted in scalar context):
1528 .Bl -tag -width Ds -compact
1529 .It Pf ${# Ns Ar name Ns \&}
1530 The number of positional parameters if
1535 or not specified; otherwise the length
1537 of the string value of parameter
1540 .It Pf ${# Ns Ar name Ns \&[*]}
1541 .It Pf ${# Ns Ar name Ns \&[@]}
1542 The number of elements in the array
1545 .It Pf ${% Ns Ar name Ns \&}
1547 .Pq in screen columns
1548 of the string value of parameter
1551 .Pf ${ Ns Ar name Ns }
1552 contains a control character.
1554 .It Pf ${! Ns Ar name Ns }
1555 The name of the variable referred to by
1561 is a name reference (bound variable), created by the
1563 command (which is an alias for
1564 .Ic typeset Fl n ) .
1566 cannot be one of most special parameters (see below).
1568 .It Pf ${! Ns Ar name Ns \&[*]}
1569 .It Pf ${! Ns Ar name Ns \&[@]}
1570 The names of indices (keys) in the array
1576 .Pf # Ar pattern No }
1580 .Pf ## Ar pattern No }
1585 matches the beginning of the value of parameter
1587 the matched text is deleted from the result of substitution.
1590 results in the shortest match, and two
1591 of them result in the longest match.
1592 Cannot be applied to a vector
1593 .Pq ${*} or ${@} or ${array[*]} or ${array[@]} .
1598 .Pf % Ar pattern No }
1602 .Pf %% Ar pattern No }
1605 Like ${...#...} substitution, but it deletes from the end of the value.
1606 Cannot be applied to a vector.
1611 .Pf / Ar pattern / Ar string No }
1615 .Pf /# Ar pattern / Ar string No }
1619 .Pf /% Ar pattern / Ar string No }
1623 .Pf // Ar pattern / Ar string No }
1626 The longest match of
1628 in the value of parameter
1634 is empty; the trailing slash
1636 may be omitted in that case).
1637 A leading slash followed by
1641 causes the pattern to be anchored at the beginning or end of
1642 the value, respectively; empty unanchored
1644 cause no replacement; a single leading slash or use of a
1646 that matches the empty string causes the replacement to
1647 happen only once; two leading slashes cause all occurrences
1648 of matches in the value to be replaced.
1649 Cannot be applied to a vector.
1650 Inefficiently implemented, may be slow.
1655 .Pf @/ Ar pattern / Ar string No }
1662 .Pf // Ar pattern / Ar string No } ,
1669 are expanded anew for each iteration.
1673 .Pf ${ Ar name : Ns Ar pos
1674 .Pf : Ns Ar len Ns }
1681 starting at position
1691 is negative, counting starts at the end of the string; if it
1692 is omitted, it defaults to 0.
1695 is omitted or greater than the length of the remaining string,
1696 all of it is substituted.
1701 are evaluated as arithmetic expressions.
1704 must start with a space, opening parenthesis or digit to be recognised.
1705 Cannot be applied to a vector.
1707 .It Pf ${ Ns Ar name Ns @#}
1708 The hash (using the BAFH algorithm) of the expansion of
1710 This is also used internally for the shell's hashtables.
1712 .It Pf ${ Ns Ar name Ns @Q}
1713 A quoted expression safe for re-entry, whose value is the value of the
1715 parameter, is substituted.
1720 may need extended globbing pattern
1723 .Pq \&\*(aq...\&\*(aq
1726 quote escaping unless
1730 The following special parameters are implicitly set by the shell and cannot be
1731 set directly using assignments:
1732 .Bl -tag -width "1 .. 9"
1734 Process ID of the last background process started.
1735 If no background processes have been started, the parameter is not set.
1737 The number of positional parameters ($1, $2, etc.).
1739 The PID of the shell or, if it is a subshell, the PID of the original shell.
1742 use this mechanism for generating temporary file names; see
1746 The concatenation of the current single letter options (see the
1748 command below for a list of options).
1750 The exit status of the last non-asynchronous command executed.
1751 If the last command was killed by a signal,
1753 is set to 128 plus the signal number, but at most 255.
1755 The name of the shell, determined as follows:
1756 the first argument to
1758 if it was invoked with the
1760 option and arguments were given; otherwise the
1762 argument, if it was supplied;
1763 or else the basename the shell was invoked with (i.e.\&
1766 is also set to the name of the current script or
1767 the name of the current function, if it was defined with the
1769 keyword (i.e. a Korn shell style function).
1771 The first nine positional parameters that were supplied to the shell, function,
1772 or script sourced using the
1775 Further positional parameters may be accessed using
1776 .Pf ${ Ar number Ns } .
1778 All positional parameters (except 0), i.e. $1, $2, $3, ...
1781 outside of double quotes, parameters are separate words (which are subjected
1782 to word splitting); if used within double quotes, parameters are separated
1783 by the first character of the
1785 parameter (or the empty string if
1791 unless it is used inside double quotes, in which case a separate word is
1792 generated for each positional parameter.
1793 If there are no positional parameters, no word is generated.
1795 can be used to access arguments, verbatim, without losing
1796 empty arguments or splitting arguments with spaces (IFS, actually).
1799 The following parameters are set and/or used by the shell:
1800 .Bl -tag -width "KSH_VERSION"
1803 When an external command is executed by the shell, this parameter is set in the
1804 environment of the new process to the path of the executed command.
1805 In interactive use, this parameter is also set in the parent shell to the last
1806 word of the previous command.
1808 The PID of the shell or subshell.
1812 but used to resolve the argument to the
1817 is set and does not contain
1819 or an empty string element, the current directory is not searched.
1822 built-in command will display the resulting directory when a match is found
1823 in any search path other than the empty path.
1825 Set to the number of columns on the terminal or window.
1826 Always set, defaults to 80, unless the
1827 value as reported by
1829 is non-zero and sane enough (minimum is 12x3); similar for
1831 This parameter is used by the interactive line editing modes and by the
1836 commands to format information columns.
1837 Importing from the environment or unsetting this parameter removes the
1838 binding to the actual terminal size in favour of the provided value.
1840 If this parameter is found to be set after any profile files are executed, the
1841 expanded value is used as a shell startup file.
1842 It typically contains function and alias definitions.
1843 .It Ev EPOCHREALTIME
1844 Time since the epoch, as returned by
1845 .Xr gettimeofday 2 ,
1846 formatted as decimal
1852 padded to exactly six decimal digits.
1854 If set, this parameter is assumed to contain the shell that is to be used to
1855 execute commands that
1857 fails to execute and which do not start with a
1858 .Dq Li #! Ns Ar shell
1861 The editor used by the
1863 command (see below).
1867 but used when an undefined function is executed to locate the file defining the
1869 It is also searched when a command can't be found using
1873 below for more information.
1875 The name of the file used to store command history.
1876 When assigned to or unset, the file is opened, history is truncated
1877 then loaded from the file; subsequent new commands (possibly consisting
1878 of several lines) are appended once they successfully compiled.
1879 Also, several invocations of the shell will share history if their
1881 parameters all point to the same file.
1886 is unset or empty, no history file is used.
1887 This is different from
1891 The number of commands normally stored for history.
1892 The default is 2047.
1893 Do not set this value to insanely high values such as 1000000000 because
1895 can then not allocate enough memory for the history and will not start.
1897 The default directory for the
1899 command and the value substituted for an unqualified
1905 Internal field separator, used during substitution and by the
1907 command, to split values into distinct arguments; normally set to space, tab
1914 This parameter is not imported from the environment when the shell is
1917 The effective group id of the shell.
1919 The real group id of the shell.
1921 The real user id of the shell.
1923 The last matched string.
1924 In a future version, this will be an indexed array,
1925 with indexes 1 and up capturing matching groups.
1926 Set by string comparisons (== and !=) in double-bracket test
1927 expressions when a match is found (when != returns false), by
1929 when a match is encountered, and by the substitution operations
1939 .Pf ## Ar pat No } ,
1951 .Pf %% Ar pat No } ,
1957 .Pf / Ar pat / Ar rpl No } ,
1963 .Pf /# Ar pat / Ar rpl No } ,
1969 .Pf /% Ar pat / Ar rpl No } ,
1975 .Pf // Ar pat / Ar rpl No } ,
1982 .Pf @/ Ar pat / Ar rpl No } .
1985 See the end of the Emacs editing mode documentation for an example.
1987 The name and version of the shell (read-only).
1988 See also the version commands in
1989 .Sx Emacs editing mode
1994 The line number of the function or shell script that is currently being
1997 Set to the number of lines on the terminal or window.
1998 Always set, defaults to 24.
2002 The previous working directory.
2005 has not successfully changed directories since the shell started or if the
2006 shell doesn't know where it is.
2010 it contains the argument for a parsed option, if it requires one.
2012 The index of the next argument to be processed when using
2014 Assigning 1 to this parameter causes
2016 to process arguments from the beginning the next time it is invoked.
2018 A colon (semicolon on OS/2) separated list of directories that are
2019 searched when looking for commands and files sourced using the
2021 command (see below).
2022 An empty string resulting from a leading or trailing
2023 (semi)colon, or two adjacent ones, is treated as a
2025 (the current directory).
2027 A colon (semicolon on OS/2), for the user's convenience.
2029 The process ID of the shell's process group leader.
2031 An array containing the errorlevel (exit status) codes,
2032 one by one, of the last pipeline run in the foreground.
2034 The process ID of the shell's parent.
2036 The primary prompt for interactive shells.
2037 Parameter, command and arithmetic
2038 substitutions are performed, and
2040 is replaced with the current command number (see the
2045 can be put in the prompt by placing
2050 The default prompt is
2057 is invoked by root and
2061 character, the default value will be used even if
2063 already exists in the environment.
2067 distribution comes with a sample
2069 containing a sophisticated example, but you might like the following one
2070 (note that ${HOSTNAME:=$(hostname)} and the
2071 root-vs-user distinguishing clause are (in this example) executed at
2073 assignment time, while the $USER and $PWD are escaped
2074 and thus will be evaluated each time a prompt is displayed):
2076 PS1=\*(aq${USER:=$(id \-un)}\*(aq"@${HOSTNAME:=$(hostname)}:\e$PWD $(
2077 if (( USER_ID )); then print \e$; else print \e#; fi) "
2080 Note that since the command-line editors try to figure out how long the prompt
2081 is (so they know how far it is to the edge of the screen), escape codes in
2082 the prompt tend to mess things up.
2083 You can tell the shell not to count certain
2084 sequences (such as escape codes) by prefixing your prompt with a
2085 character (such as Ctrl-A) followed by a carriage return and then delimiting
2086 the escape codes with this character.
2087 Any occurrences of that character in the prompt are not printed.
2088 By the way, don't blame me for
2089 this hack; it's derived from the original
2091 which did print the delimiter character so you were out of luck
2092 if you did not have any non-printing characters.
2094 Since Backslashes and other special characters may be
2095 interpreted by the shell, to set
2097 either escape the backslash itself
2098 or use double quotes.
2099 The latter is more practical.
2100 This is a more complex example,
2101 avoiding to directly enter special characters (for example with
2103 in the emacs editing mode),
2104 which embeds the current working directory,
2106 .Pq colour would work, too ,
2107 in the prompt string:
2108 .Bd -literal -offset indent
2110 PS1="$x$(print \e\er)$x$(tput so)$x\e$PWD$x$(tput se)$x\*(Gt "
2113 Due to a strong suggestion from David G. Korn,
2115 now also supports the following form:
2116 .Bd -literal -offset indent
2117 PS1=$\*(aq\e1\er\e1\ee[7m\e1$PWD\e1\ee[0m\e1\*(Gt \*(aq
2120 Secondary prompt string, by default
2122 used when more input is needed to complete a command.
2126 statement when reading a menu selection.
2130 Used to prefix commands that are printed during execution tracing (see the
2133 Parameter, command and arithmetic substitutions are performed
2134 before it is printed.
2137 You may want to set it to
2138 .Dq Li \&[$EPOCHREALTIME]\ \&
2139 instead, to include timestamps.
2141 The current working directory.
2142 May be unset or empty if the shell doesn't know where it is.
2146 is referenced, it is assigned a number between 0 and 32767 from
2147 a Linear Congruential PRNG first.
2149 Default parameter for the
2151 command if no names are given.
2154 loops to store the value that is read from standard input.
2156 The number of seconds since the shell started or, if the parameter has been
2157 assigned an integer value, the number of seconds since the assignment plus the
2158 value that was assigned.
2160 If set to a positive integer in an interactive shell, it specifies the maximum
2161 number of seconds the shell will wait for input after printing the primary
2164 If the time is exceeded, the shell exits.
2166 The directory temporary shell files are created in.
2167 If this parameter is not
2168 set or does not contain the absolute path of a writable directory, temporary
2169 files are created in
2172 The effective user id of the shell.
2175 Tilde expansion, which is done in parallel with parameter substitution,
2176 is applied to words starting with an unquoted
2178 In parameter assignments (such as those preceding a simple-command or those
2179 occurring in the arguments of a declaration utility), tilde expansion is done
2180 after any assignment (i.e. after the equals sign) or after an unquoted colon
2182 login names are also delimited by colons.
2183 The Korn shell, except in POSIX mode, always expands tildes after unquoted
2184 equals signs, not just in assignment context (see below), and enables tab
2185 completion for tildes after all unquoted colons during command line editing.
2187 The characters following the tilde, up to the first
2189 if any, are assumed to be a login name.
2190 If the login name is empty,
2194 the simplified value of the
2199 parameter is substituted, respectively.
2200 Otherwise, the password file is
2201 searched for the login name, and the tilde expression is substituted with the
2202 user's home directory.
2203 If the login name is not found in the password file or
2204 if any quoting or parameter substitution occurs in the login name, no
2205 substitution is performed.
2207 The home directory of previously expanded login names are cached and re-used.
2210 command may be used to list, change and add to this cache (e.g.\&
2211 .Ic alias \-d fac=/usr/local/facilities; cd \*(TIfac/bin ) .
2212 .Ss Brace expansion (alternation)
2213 Brace expressions take the following form:
2214 .Bd -unfilled -offset indent
2217 .Ar prefix No { Ar str1 No ,...,
2218 .Ar strN No } Ar suffix
2223 The expressions are expanded to
2225 words, each of which is the concatenation of
2231 .Dq Li a{c,b{X,Y},d}e
2232 expands to four words:
2238 As noted in the example, brace expressions can be nested and the resulting
2239 words are not sorted.
2240 Brace expressions must contain an unquoted comma
2242 for expansion to occur (e.g.\&
2247 Brace expansion is carried out after parameter substitution
2248 and before file name generation.
2249 .Ss File name patterns
2250 A file name pattern is a word containing one or more unquoted
2260 Once brace expansion has been performed, the shell replaces file
2261 name patterns with the sorted names of all the files that match the pattern
2262 (if no files match, the word is left unchanged).
2263 The pattern elements have the following meaning:
2266 Matches any single character.
2268 Matches any sequence of octets.
2270 Matches any of the octets inside the brackets.
2271 Ranges of octets can be specified by separating two octets by a
2278 In order to represent itself, a
2280 must either be quoted or the first or last octet in the octet list.
2283 must be quoted or the first octet in the list if it is to represent itself
2284 instead of the end of the list.
2287 appearing at the start of the list has special meaning (see below), so to
2288 represent itself it must be quoted or appear later in the list.
2291 except it matches any octet not inside the brackets.
2293 .It *( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
2295 Matches any string of octets that matches zero or more occurrences of the
2297 Example: The pattern
2306 .It +( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
2308 Matches any string of octets that matches one or more occurrences of the
2310 Example: The pattern
2318 .It ?( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
2320 Matches the empty string or a string that matches one of the specified
2322 Example: The pattern
2324 only matches the strings
2330 .It @( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
2332 Matches a string that matches one of the specified patterns.
2333 Example: The pattern
2335 only matches the strings
2340 .It !( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
2342 Matches any string that does not match one of the specified patterns.
2343 Examples: The pattern
2345 matches all strings except
2351 matches no strings; the pattern
2353 matches all strings (think about it).
2356 Note that complicated globbing, especially with alternatives,
2357 is slow; using separate comparisons may (or may not) be faster.
2375 Note that none of the above pattern elements match either a period
2377 at the start of a file name or a slash
2379 even if they are explicitly used in a [...] sequence; also, the names
2383 are never matched, even by the pattern
2388 option is set, any directories that result from file name generation are marked
2391 .Ss Input/output redirection
2392 When a command is executed, its standard input, standard output and standard
2393 error (file descriptors 0, 1 and 2, respectively) are normally inherited from
2395 Three exceptions to this are commands in pipelines, for which
2396 standard input and/or standard output are those set up by the pipeline,
2397 asynchronous commands created when job control is disabled, for which standard
2398 input is initially set to
2400 and commands for which any of the following redirections have been specified:
2401 .Bl -tag -width XXxxmarker
2402 .It \*(Gt Ns Ar file
2403 Standard output is redirected to
2407 does not exist, it is created; if it does exist, is a regular file, and the
2409 option is set, an error occurs; otherwise, the file is truncated.
2410 Note that this means the command
2411 .Ic cmd \*(Ltfoo \*(Gtfoo
2414 for reading and then truncate it when it opens it for writing, before
2416 gets a chance to actually read
2418 .It \*(Gt\*(Ba Ns Ar file
2421 except the file is truncated, even if the
2424 .It \*(Gt\*(Gt Ns Ar file
2429 exists it is appended to instead of being truncated.
2430 Also, the file is opened
2431 in append mode, so writes always go to the end of the file (see
2433 .It \*(Lt Ns Ar file
2434 Standard input is redirected from
2436 which is opened for reading.
2437 .It \*(Lt\*(Gt Ns Ar file
2440 except the file is opened for reading and writing.
2441 .It \*(Lt\*(Lt Ns Ar marker
2442 After reading the command line containing this kind of redirection (called a
2443 .Dq here document ) ,
2444 the shell copies lines from the command source into a temporary file until a
2448 When the command is executed, standard input is redirected from the
2452 contains no quoted characters, the contents of the temporary file are processed
2453 as if enclosed in double quotes each time the command is executed, so
2454 parameter, command and arithmetic substitutions are performed, along with
2465 If multiple here documents are used on the same command line, they are saved in
2470 is given, the here document ends at the next
2472 and substitution will be performed.
2475 is only a set of either single
2479 quotes with nothing in between, the here document ends at the next empty line
2480 and substitution will not be performed.
2481 .It \*(Lt\*(Lt\- Ns Ar marker
2484 except leading tabs are stripped from lines in the here document.
2485 .It \*(Lt\*(Lt\*(Lt Ns Ar word
2492 This is called a here string.
2494 Standard input is duplicated from file descriptor
2497 can be a single digit, indicating the number of an existing file descriptor;
2500 indicating the file descriptor associated with the output of the current
2501 co-process; or the character
2503 indicating standard input is to be closed.
2507 except the operation is done on standard output.
2508 .It &\*(Gt Ns Ar file
2510 .Ic \*(Gt Ns Ar file 2\*(Gt&1 .
2511 This is a deprecated (legacy) GNU
2513 extension supported by
2515 which also supports the preceding explicit fd digit, for example,
2516 .Ic 3&\*(Gt Ns Ar file
2518 .Ic 3\*(Gt Ns Ar file 2\*(Gt&3
2521 but a syntax error in GNU
2524 .No &\*(Gt\*(Ba Ns Ar file ,
2525 .No &\*(Gt\*(Gt Ns Ar file ,
2526 .No &\*(Gt& Ns Ar fd
2529 .Ic \*(Gt\*(Ba Ns Ar file ,
2530 .Ic \*(Gt\*(Gt Ns Ar file
2532 .Ic \*(Gt& Ns Ar fd ,
2541 In any of the above redirections, the file descriptor that is redirected
2542 (i.e. standard input or standard output)
2543 can be explicitly given by preceding the
2544 redirection with a single digit.
2545 Parameter, command and arithmetic
2546 substitutions, tilde substitutions, and, if the shell is interactive,
2547 file name generation are all performed on the
2552 arguments of redirections.
2553 Note, however, that the results of any file name
2554 generation are only used if a single file is matched; if multiple files match,
2555 the word with the expanded file name generation characters is used.
2557 that in restricted shells, redirections which can create files cannot be used.
2559 For simple-commands, redirections may appear anywhere in the command; for
2565 any redirections must appear at the end.
2566 Redirections are processed after
2567 pipelines are created and in the order they are given, so the following
2568 will print an error with a line number prepended to it:
2570 .Dl $ cat /foo/bar 2\*(Gt&1 \*(Gt/dev/null \*(Ba pr \-n \-t
2572 File descriptors created by I/O redirections are private to the shell.
2573 .Ss Arithmetic expressions
2574 Integer arithmetic expressions can be used with the
2576 command, inside $((...)) expressions, inside array references (e.g.\&
2577 .Ar name Ns Bq Ar expr ) ,
2578 as numeric arguments to the
2580 command, and as the value of an assignment to an integer parameter.
2582 This also affects implicit conversion to integer, for example as done by the
2586 use unchecked user input, e.g. from the environment, in an arithmetic context!
2588 Expressions are calculated using signed arithmetic and the
2590 type (a 32-bit signed integer), unless they begin with a sole
2592 character, in which case they use
2594 .Po a 32-bit unsigned integer Pc .
2596 Expressions may contain alpha-numeric parameter identifiers, array references
2597 and integer constants and may be combined with the following C operators
2598 (listed and grouped in increasing order of precedence):
2601 .Bd -literal -offset indent
2602 + \- ! \*(TI ++ \-\-
2606 .Bd -literal -offset indent
2608 = += \-= *= /= %= \*(Lt\*(Lt= \*(Gt\*(Gt= \*(ha\*(Lt= \*(ha\*(Gt= &= \*(ha= \*(Ba=
2615 \*(Lt \*(Lt= \*(Gt \*(Gt=
2616 \*(Lt\*(Lt \*(Gt\*(Gt \*(ha\*(Lt \*(ha\*(Gt
2622 .Bd -literal -offset indent
2623 ?: (precedence is immediately higher than assignment)
2627 .Bd -literal -offset indent
2631 Integer constants and expressions are calculated using an exactly 32-bit
2632 wide, signed or unsigned, type with silent wraparound on integer overflow.
2633 Integer constants may be specified with arbitrary bases using the notation
2634 .Ar base Ns # Ns Ar number ,
2637 is a decimal integer specifying the base (up to 36), and
2639 is a number in the specified base.
2640 Additionally, base-16 integers may be specified by prefixing them with
2642 .Pq case-insensitive
2643 in all forms of arithmetic expressions, except as numeric arguments to the
2646 Prefixing numbers with a sole digit zero
2648 does not cause interpretation as octal (except in POSIX mode,
2649 as required by the standard), as that's unsafe to do.
2653 extension, numbers to the base of one are treated as either (8-bit
2654 transparent) ASCII or Unicode codepoints, depending on the shell's
2656 flag (current setting).
2665 Note that NUL bytes (integral value of zero) cannot be used.
2666 An unset or empty parameter evaluates to 0 in integer context.
2667 In Unicode mode, raw octets are mapped into the range EF80..EFFF as in
2668 OPTU-8, which is in the PUA and has been assigned by CSUR for this use.
2669 If more than one octet in ASCII mode, or a sequence of more than one
2670 octet not forming a valid and minimal CESU-8 sequence is passed, the
2671 behaviour is undefined (usually, the shell aborts with a parse error,
2672 but rarely, it succeeds, e.g. on the sequence C2 20).
2673 That's why you should always use ASCII mode unless you know that the
2674 input is well-formed UTF-8 in the range of 0000..FFFD if you use this
2675 feature, as opposed to
2678 The operators are evaluated as follows:
2679 .Bl -tag -width Ds -offset indent
2681 Result is the argument (included for completeness).
2686 the result is 1 if argument is zero, 0 if not.
2688 Arithmetic (bit-wise) NOT.
2690 Increment; must be applied to a parameter (not a literal or other expression).
2691 The parameter is incremented by 1.
2692 When used as a prefix operator, the result
2693 is the incremented value of the parameter; when used as a postfix operator, the
2694 result is the original value of the parameter.
2698 except the parameter is decremented by 1.
2700 Separates two arithmetic expressions; the left-hand side is evaluated first,
2702 The result is the value of the expression on the right-hand side.
2704 Assignment; the variable on the left is set to the value on the right.
2706 .No += \-= *= /= %= \*(Lt\*(Lt= \*(Gt\*(Gt=
2707 .No \*(ha\*(Lt= \*(ha\*(Gt= &= \*(ha= \*(Ba=
2709 Assignment operators.
2724 with any operator precedence in
2728 .Dq Li var1 *= 5 + 3
2729 is the same as specifying
2730 .Dq Li var1 = var1 * (5 + 3) .
2733 the result is 1 if either argument is non-zero, 0 if not.
2734 The right argument is evaluated only if the left argument is zero.
2737 the result is 1 if both arguments are non-zero, 0 if not.
2738 The right argument is evaluated only if the left argument is non-zero.
2740 Arithmetic (bit-wise) OR.
2742 Arithmetic (bit-wise) XOR
2745 Arithmetic (bit-wise) AND.
2747 Equal; the result is 1 if both arguments are equal, 0 if not.
2749 Not equal; the result is 0 if both arguments are equal, 1 if not.
2751 Less than; the result is 1 if the left argument is less than the right, 0 if
2753 .It \*(Lt= \*(Gt \*(Gt=
2754 Less than or equal, greater than, greater than or equal.
2757 .It \*(Lt\*(Lt \*(Gt\*(Gt
2758 Shift left (right); the result is the left argument with its bits
2759 arithmetically (signed operation) or logically (unsigned expression)
2760 shifted left (right) by the amount given in the right argument.
2761 .It \*(ha\*(Lt \*(ha\*(Gt
2762 Rotate left (right); the result is similar to shift,
2763 except that the bits shifted out at one end are shifted in
2764 at the other end, instead of zero or sign bits.
2766 Addition, subtraction, multiplication and division.
2768 Remainder; the result is the symmetric remainder of the division of the left
2769 argument by the right.
2770 To get the mathematical modulus of
2786 is non-zero, the result is
2788 otherwise the result is
2790 The non-result argument is not evaluated.
2793 A co-process (which is a pipeline created with the
2795 operator) is an asynchronous process that the shell can both write to (using
2797 and read from (using
2799 The input and output of the co-process can also be manipulated using
2803 redirections, respectively.
2804 Once a co-process has been started, another can't
2805 be started until the co-process exits, or until the co-process's input has been
2807 .Ic exec Ar n Ns Ic \*(Gt&p
2809 If a co-process's input is redirected in this way, the next
2810 co-process to be started will share the output with the first co-process,
2811 unless the output of the initial co-process has been redirected using an
2812 .Ic exec Ar n Ns Ic \*(Lt&p
2815 Some notes concerning co-processes:
2818 The only way to close the co-process's input (so the co-process reads an
2819 end-of-file) is to redirect the input to a numbered file descriptor and then
2820 close that file descriptor:
2821 .Ic exec 3\*(Gt&p; exec 3\*(Gt&\-
2823 In order for co-processes to share a common output, the shell must keep the
2824 write portion of the output pipe open.
2825 This means that end-of-file will not be
2826 detected until all co-processes sharing the co-process's output have exited
2827 (when they all exit, the shell closes its copy of the pipe).
2829 avoided by redirecting the output to a numbered file descriptor (as this also
2830 causes the shell to close its copy).
2831 Note that this behaviour is slightly
2832 different from the original Korn shell which closes its copy of the write
2833 portion of the co-process output when the most recently started co-process
2834 (instead of when all sharing co-processes) exits.
2839 signals during writes if the signal is not being trapped or ignored; the same
2840 is true if the co-process input has been duplicated to another file descriptor
2842 .Ic print Fl u Ns Ar n
2846 Functions are defined using either Korn shell
2847 .Ic function Ar function-name
2848 syntax or the Bourne/POSIX shell
2849 .Ar function-name Ns \&()
2850 syntax (see below for the difference between the two forms).
2853 (i.e. scripts sourced using the
2856 in that they are executed in the current environment.
2859 shell arguments (i.e. positional parameters $1, $2, etc.)\&
2860 are never visible inside them.
2861 When the shell is determining the location of a command, functions
2862 are searched after special built-in commands, before builtins and the
2866 An existing function may be deleted using
2867 .Ic unset Fl f Ar function-name .
2868 A list of functions can be obtained using
2870 and the function definitions can be listed using
2874 command (which is an alias for
2876 may be used to create undefined functions: when an undefined function is
2877 executed, the shell searches the path specified in the
2879 parameter for a file with the same name as the function which, if found, is
2881 If after executing the file the named function is found to
2882 be defined, the function is executed; otherwise, the normal command search is
2883 continued (i.e. the shell searches the regular built-in command table and
2885 Note that if a command is not found using
2887 an attempt is made to autoload a function using
2889 (this is an undocumented feature of the original Korn shell).
2891 Functions can have two attributes,
2895 which can be set with
2900 When a traced function is executed, the shell's
2902 option is turned on for the function's duration.
2905 attribute of functions is currently not used.
2906 In the original Korn shell,
2907 exported functions are visible to shell scripts that are executed.
2909 Since functions are executed in the current shell environment, parameter
2910 assignments made inside functions are visible after the function completes.
2911 If this is not the desired effect, the
2913 command can be used inside a function to create a local parameter.
2917 uses static scoping (one global scope, one local scope per function)
2918 and allows local variables only on Korn style functions, whereas
2920 uses dynamic scoping (nested scopes of varying locality).
2921 Note that special parameters (e.g.\&
2923 can't be scoped in this way.
2925 The exit status of a function is that of the last command executed in the
2927 A function can be made to finish immediately using the
2929 command; this may also be used to explicitly specify the exit status.
2930 Note that when called in a subshell,
2932 will only exit that subshell and will not cause the original shell to exit
2933 a running function (see the
2934 .Ic while Ns Li \&... Ns Ic read
2937 Functions defined with the
2939 reserved word are treated differently in the following ways from functions
2945 The $0 parameter is set to the name of the function
2946 (Bourne-style functions leave $0 untouched).
2948 Parameter assignments preceding function calls are not kept in the shell
2949 environment (executing Bourne-style functions will keep assignments).
2952 is saved/reset and restored on entry and exit from the function so
2954 can be used properly both inside and outside the function (Bourne-style
2959 inside a function interferes with using
2961 outside the function).
2965 have local scope, i.e. changes inside a function are reset upon its exit.
2968 In the future, the following differences may also be added:
2971 A separate trap/signal environment will be used during the execution of
2973 This will mean that traps set inside a function will not affect the
2974 shell's traps and signals that are not ignored in the shell (but may be
2975 trapped) will have their default effect in a function.
2977 The EXIT trap, if set in a function, will be executed after the function
2980 .Ss Command execution
2981 After evaluation of command-line arguments, redirections and parameter
2982 assignments, the type of command is determined: a special built-in command,
2983 a function, a normal builtin or the name of a file to execute found using the
2986 The checks are made in the above order.
2987 Special built-in commands differ from other commands in that the
2989 parameter is not used to find them, an error during their execution can
2990 cause a non-interactive shell to exit, and parameter assignments that are
2991 specified before the command are kept after the command completes.
2992 Regular built-in commands are different only in that the
2994 parameter is not used to find them.
2998 and POSIX differ somewhat in which commands are considered
3001 POSIX special built-in utilities:
3003 .Ic \&. , \&: , break , continue ,
3004 .Ic eval , exec , exit , export ,
3005 .Ic readonly , return , set , shift ,
3006 .Ic times , trap , unset
3010 commands keeping assignments:
3012 .Ic global , source , typeset
3014 Builtins that are not special:
3016 .Ic [ , alias , bg , bind ,
3017 .Ic builtin , cat , cd , command ,
3018 .Ic echo , false , fc , fg ,
3019 .Ic getopts , jobs , kill , let ,
3020 .Ic print , pwd , read , realpath ,
3021 .Ic rename , sleep , suspend , test ,
3022 .Ic true , ulimit , umask , unalias ,
3025 Once the type of command has been determined, any command-line parameter
3026 assignments are performed and exported for the duration of the command.
3028 The following describes the special and regular built-in commands and
3029 builtin-like reserved words:
3031 .Bl -tag -width false -compact
3032 .It Ic \&. Ar file Op Ar arg ...
3036 Execute the commands in
3038 in the current environment.
3039 The file is searched for in the directories of
3041 If arguments are given, the positional parameters may be used to access them
3045 If no arguments are given, the positional parameters are
3046 those of the environment the command is used in.
3048 .It Ic \&: Op Ar ...
3050 Exit status is set to zero.
3052 .It Ic \&[ Ar expression Ic \&]
3057 .Oo Fl d \*(Ba t Oo Fl r Oc \*(Ba
3062 .Op Ns = Ns Ar value
3068 For any name without a value, the existing alias is listed.
3069 Any name with a value defines an alias (see
3072 .Li \&[A\-Za\-z0\-9_!%,@\-]
3073 are valid in names except they may not begin with a hyphen-minus.
3075 When listing aliases, one of two formats is used.
3076 Normally, aliases are listed as
3077 .Ar name Ns = Ns Ar value ,
3081 If options were preceded with
3085 is given on the command line, only
3091 option causes directory aliases which are used in tilde expansion to be
3098 option is used, each alias is prefixed with the string
3103 option indicates that tracked aliases are to be listed/set (values specified on
3104 the command line are ignored for tracked aliases).
3107 option indicates that all tracked aliases are to be reset.
3113 the export attribute of an alias, or, if no names are given, lists the aliases
3114 with the export attribute (exporting an alias has no effect).
3116 .It Ic bg Op Ar job ...
3117 Resume the specified stopped job(s) in the background.
3118 If no jobs are specified,
3123 below for more information.
3126 The current bindings are listed.
3131 instead lists the names of the functions to which keys may be bound.
3133 .Sx Emacs editing mode
3134 for more information.
3136 .It Xo Ic bind Op Fl m
3137 .Ar string Ns = Ns Op Ar substitute
3141 .Ar string Ns = Ns Op Ar editing-command
3144 The specified editing command is bound to the given
3146 which should consist of a control character
3147 optionally preceded by one of the two prefix characters
3148 and optionally succeeded by a tilde character.
3151 will cause the editing command to be immediately invoked.
3154 flag is given, the specified input
3156 will afterwards be immediately replaced by the given
3158 string which may contain editing commands but not other macros.
3159 If a tilde postfix is given, a tilde trailing the one or
3160 two prefices and the control character is ignored, any
3161 other trailing character will be processed afterwards.
3163 Control characters may be written using caret notation
3164 i.e. \*(haX represents Ctrl-X.
3165 Note that although only two prefix characters (usually ESC and \*(haX)
3166 are supported, some multi-character sequences can be supported.
3168 The following default bindings show how the arrow keys, the home, end and
3169 delete key on a BSD wsvt25, xterm\-xfree86 or GNU screen terminal are bound
3170 (of course some escape sequences won't work out quite this nicely):
3171 .Bd -literal -offset indent
3172 bind \*(aq\*(haX\*(aq=prefix\-2
3173 bind \*(aq\*(ha[[\*(aq=prefix\-2
3174 bind \*(aq\*(haXA\*(aq=up\-history
3175 bind \*(aq\*(haXB\*(aq=down\-history
3176 bind \*(aq\*(haXC\*(aq=forward\-char
3177 bind \*(aq\*(haXD\*(aq=backward\-char
3178 bind \*(aq\*(haX1\*(TI\*(aq=beginning\-of\-line
3179 bind \*(aq\*(haX7\*(TI\*(aq=beginning\-of\-line
3180 bind \*(aq\*(haXH\*(aq=beginning\-of\-line
3181 bind \*(aq\*(haX4\*(TI\*(aq=end\-of\-line
3182 bind \*(aq\*(haX8\*(TI\*(aq=end\-of\-line
3183 bind \*(aq\*(haXF\*(aq=end\-of\-line
3184 bind \*(aq\*(haX3\*(TI\*(aq=delete\-char\-forward
3187 .It Ic break Op Ar level
3203 .Ar command Op Ar arg ...
3205 Execute the built-in command
3210 .Ar command Op Ar arg ...
3214 Additionally acts as declaration utility forwarder, i.e. this is a
3215 declaration utility (see
3216 .Sx Tilde expansion )
3218 is a declaration utility.
3225 Read files sequentially, in command line order, and write them to
3231 or absent, read from standard input.
3232 For direct builtin calls, the
3235 option is supported as a no-op.
3236 For calls from shell, if any options are given, an external
3238 utility is preferred over the builtin.
3255 Set the working directory to
3259 is set, it lists the search path for the directory containing
3261 An unset or empty path means the current directory.
3264 is found in any component of the
3266 search path other than an unset or empty path,
3267 the name of the new working directory will be written to standard output.
3270 is missing, the home directory
3277 the previous working directory is used (see the
3283 option (logical path) is used or if the
3285 option isn't set (see the
3287 command below), references to
3291 are relative to the path used to get to the directory.
3294 option (physical path) is used or if the
3298 is relative to the filesystem directory tree.
3303 parameters are updated to reflect the current and old working directory,
3307 option is set for physical filesystem traversal and
3309 could not be set, the exit code is 1; greater than 1 if an
3310 error occurred, 0 otherwise.
3326 in the current directory, and the shell attempts to change to the new
3341 is executed exactly as if
3343 had not been specified, with two exceptions:
3346 cannot be a shell function;
3347 and secondly, special built-in commands lose their specialness
3348 (i.e. redirection and utility errors do not cause the shell to
3349 exit, and command assignments are not permanent).
3350 The declaration utility property is not reset.
3354 option is given, a default search path is used instead of the current value of
3356 the actual value of which is system dependent.
3360 option is given, instead of executing
3362 information about what would be executed is given (and the same is done for
3364 For builtins, functions and keywords, their names are simply printed;
3365 for aliases, a command that defines them is printed;
3366 for utilities found by searching the
3368 parameter, the full path of the command is printed.
3369 If no command is found
3370 (i.e. the path search fails), nothing is printed and
3372 exits with a non-zero status.
3377 option, except it is more verbose.
3379 .It Ic continue Op Ar level
3380 Jumps to the beginning of the
3398 this utility is not portable; use the Korn shell builtin
3402 Prints its arguments (separated by spaces) followed by a newline, to the
3404 The newline is suppressed if any of the arguments contain the
3409 command below for a list of other backslash sequences that are recognised.
3411 The options are provided for compatibility with
3416 option suppresses the trailing newline,
3418 enables backslash interpretation (a no-op, since this is normally done), and
3420 suppresses backslash interpretation.
3426 option is set or this is a direct builtin call or
3429 only the first argument is treated as an option, and only if it is exactly
3431 Backslash interpretation is disabled.
3433 .It Ic eval Ar command ...
3434 The arguments are concatenated (with spaces between them) to form a single
3435 string which the shell then parses and executes in the current environment.
3441 .Op Ar command Op Ar arg ...
3443 The command is executed without forking, replacing the shell process.
3444 This is currently absolute, i.e.\&
3446 never returns, even if the
3451 option permits setting a different
3455 clears the environment before executing the child process, except for the
3457 variable and direct assignments.
3459 If no command is given except for I/O redirection, the I/O redirection is
3460 permanent and the shell is
3462 Any file descriptors greater than 2 which are opened or
3464 in this way are not made available to other executed commands (i.e. commands
3465 that are not built-in to the shell).
3466 Note that the Bourne shell differs here;
3467 it does pass these file descriptors on.
3469 .It Ic exit Op Ar status
3470 The shell or subshell exits with the specified exit status.
3473 is not specified, the exit status is the current value of the
3480 .Op Ar parameter Ns Op = Ns Ar value
3482 Sets the export attribute of the named parameters.
3483 Exported parameters are passed in the environment to executed commands.
3484 If values are specified, the named parameters are also assigned.
3485 This is a declaration utility.
3487 If no parameters are specified, all parameters with the export attribute
3488 set are printed one per line; either their names, or, if a
3490 with no option letter is specified, name=value pairs, or, with
3493 commands suitable for re-entry.
3496 A command that exits with a non-zero status.
3500 .Oo Fl e Ar editor \*(Ba
3503 .Op Ar first Op Ar last
3508 select commands from the history.
3509 Commands can be selected by history number
3510 (negative numbers go backwards from the current, most recent, line)
3511 or a string specifying the most recent command starting with that string.
3514 option lists the command on standard output, and
3516 inhibits the default command numbers.
3519 option reverses the order of the list.
3522 the selected commands are edited by the editor specified with the
3526 is specified, the editor specified by the
3528 parameter (if this parameter is not set,
3530 is used), and then executed by the shell.
3534 .Cm \-e \- \*(Ba Fl s
3536 .Op Ar old Ns = Ns Ar new
3539 Re-execute the selected command (the previous command by default) after
3540 performing the optional substitution of
3546 is specified, all occurrences of
3554 is identical: re-execute the selected command without invoking an editor.
3555 This command is usually accessed with the predefined:
3556 .Ic alias r=\*(aqfc \-e \-\*(aq
3558 .It Ic fg Op Ar job ...
3559 Resume the specified job(s) in the foreground.
3560 If no jobs are specified,
3565 below for more information.
3572 Used by shell procedures to parse the specified arguments (or positional
3573 parameters, if no arguments are given) and to check for legal options.
3575 contains the option letters that
3578 If a letter is followed by a colon, the option is expected to
3580 Options that do not take arguments may be grouped in a single argument.
3581 If an option takes an argument and the option character is not the
3582 last character of the argument it is found in, the remainder of the argument is
3583 taken to be the option's argument; otherwise, the next argument is the option's
3588 is invoked, it places the next option in the shell parameter
3590 and the index of the argument to be processed by the next call to
3592 in the shell parameter
3594 If the option was introduced with a
3596 the option placed in
3600 When an option requires an argument,
3602 places it in the shell parameter
3605 When an illegal option or a missing option argument is encountered, a question
3606 mark or a colon is placed in
3608 (indicating an illegal option or missing argument, respectively) and
3610 is set to the option character that caused the problem.
3613 does not begin with a colon, a question mark is placed in
3616 is unset, and an error message is printed to standard error.
3618 When the end of the options is encountered,
3620 exits with a non-zero exit status.
3621 Options end at the first (non-option
3622 argument) argument that does not start with a
3626 argument is encountered.
3628 Option parsing can be reset by setting
3630 to 1 (this is done automatically whenever the shell or a shell procedure is
3633 Warning: Changing the value of the shell parameter
3635 to a value other than 1 or parsing different sets of arguments without
3638 may lead to unexpected results.
3642 .Op Ic +\-aglpnrtUux
3644 .No \*(Ba Fl R Ns Op Ar n
3645 .No \*(Ba Fl Z Ns Op Ar n Oc
3648 .Op Ns = Ns Ar value
3653 .No Deprecated , Em will
3654 be removed from a future version of
3662 Without arguments, any hashed executable command pathnames are listed.
3665 option causes all hashed commands to be removed from the hash table.
3668 is searched as if it were a command name and added to the hash table if it is
3669 an executable command.
3676 Display information about the specified job(s); if no jobs are specified, all
3680 option causes information to be displayed only for jobs that have changed
3681 state since the last notification.
3684 option is used, the process ID of each process in a job is also listed.
3687 option causes only the process group of each job to be printed.
3690 below for the format of
3692 and the displayed job.
3696 .Oo Fl s Ar signame \*(Ba
3697 .No \- Ns Ar signum \*(Ba
3698 .No \- Ns Ar signame Oc
3699 .No { Ar job \*(Ba pid \*(Ba pgrp No }
3702 Send the specified signal to the specified jobs, process IDs or process
3704 If no signal is specified, the
3707 If a job is specified, the signal is sent to the job's process group.
3710 below for the format of
3716 .Op Ar exit-status ...
3718 Print the signal name corresponding to
3720 If no arguments are specified, a list of all the signals with their numbers
3721 and a short description of each are printed.
3723 .It Ic let Op Ar expression ...
3724 Each expression is evaluated (see
3725 .Sx Arithmetic expressions
3727 If all expressions are successfully evaluated, the exit status is 0 (1)
3728 if the last expression evaluated to non-zero (zero).
3729 If an error occurs during
3730 the parsing or evaluation of an expression, the exit status is greater than 1.
3731 Since expressions may need to be quoted,
3732 .No \&(( Ar expr No ))
3733 is syntactic sugar for:
3734 .Dl "{ \e\ebuiltin let \*(aq" Ns Ar expr Ns "\*(aq; }"
3749 Create a device special file.
3750 The file type may be
3752 (block type device),
3754 (character type device)
3757 .Pq named pipe , Tn FIFO .
3758 The file created may be modified according to its
3764 (major device number),
3767 (minor device number).
3768 This is not normally part of
3770 however, distributors may have added this as builtin as a speed hack.
3774 .Oo Fl AcelNnprsu Ns Oo Ar n Oc \*(Ba
3778 Print the specified argument(s) on the standard output,
3779 separated by spaces, terminated with a newline.
3780 The escapes mentioned in
3781 .Sx Backslash expansion
3784 which is equivalent to using the
3786 option, are interpreted.
3788 The options are as follows:
3793 is arithmetically evaluated; the character corresponding to the
3794 resulting value is printed.
3797 separate input words.
3799 The output is printed columnised, line by line, similar to how the
3801 utility, tab completion, the
3803 built-in utility and the
3807 Restore backslash expansion after a previous
3810 Change the output word separator to newline.
3812 Change the output word and line separator to ASCII NUL.
3814 Do not print the trailing line separator.
3816 Print to the co-process (see
3820 Inhibit backslash expansion.
3822 Print to the history file instead of standard output.
3824 Print to the file descriptor
3825 .Ar n Pq defaults to 1 if omitted
3826 instead of standard output.
3831 option mostly emulates the
3834 command which does not expand backslashes and interprets
3835 its first argument as option only if it is exactly
3837 .Pq to suppress the trailing newline .
3840 Print the present working directory.
3843 option is used or if the
3845 option isn't set (see the
3847 command below), the logical path is printed (i.e. the path used to
3849 to the current directory).
3852 option (physical path) is used or if the
3854 option is set, the path determined from the filesystem (by following
3856 directories to the root directory) is printed.
3870 Reads a line of input, separates the input into fields using the
3874 above), and assigns each field to the specified parameters
3876 If no parameters are specified, the
3878 parameter is used to store the result.
3883 options, only no or one parameter is accepted.
3884 If there are more parameters than fields, the extra parameters are set to
3885 the empty string or 0; if there are more fields than parameters, the last
3886 parameter is assigned the remaining fields (including the word separators).
3888 The options are as follows:
3889 .Bl -tag -width XuXnX
3891 Store the result into the parameter
3897 Store the result without word splitting into the parameter
3901 as array of characters (wide characters if the
3903 option is enacted, octets otherwise); the codepoints are
3904 encoded as decimal numbers by default.
3906 Use the first byte of
3909 if empty, instead of the ASCII newline character as input line delimiter.
3911 Instead of reading till end-of-line, read exactly
3914 Upon EOF, a partial read is returned with exit status 1.
3915 After timeout, a partial read is returned with an exit status as if
3919 Instead of reading till end-of-line, read up to
3921 bytes but return as soon as any bytes are read, e.g.\& from a
3922 slow terminal device, or if EOF or a timeout occurs.
3924 Read from the currently active co-process, see
3926 above for details on this.
3928 Read from the file descriptor
3930 (defaults to 0, i.e.\& standard input).
3931 The argument must immediately follow the option character.
3933 Interrupt reading after
3935 seconds (specified as positive decimal value with an optional fractional part).
3940 were caught if the timeout occurred, but partial reads may still be returned.
3942 Normally, the ASCII backslash character escapes the special
3943 meaning of the following character and is stripped from the input;
3945 does not stop when encountering a backslash-newline sequence and
3946 does not store that newline in the result.
3947 This option enables raw mode, in which backslashes are not processed.
3949 The input line is saved to the history.
3952 If the input is a terminal, both the
3956 options set it into raw mode;
3957 they read an entire file if \-1 is passed as
3961 The first parameter may have a question mark and a string appended to it, in
3962 which case the string is used as a prompt (printed to standard error before
3963 any input is read) if the input is a
3966 .Ic read nfoo?\*(aqnumber of foos: \*(aq ) .
3968 If no input is read or a timeout occurred,
3970 exits with a non-zero status.
3976 .Op Ns = Ns Ar value
3979 Sets the read-only attribute of the named parameters.
3980 This is a declaration utility.
3981 If values are given,
3982 parameters are set to them before setting the attribute.
3984 made read-only, it cannot be unset and its value cannot be changed.
3986 If no parameters are specified, the names of all parameters with the read-only
3987 attribute are printed one per line, unless the
3989 option is used, in which case
3991 commands defining all read-only parameters, including their values, are
3999 Prints the resolved absolute pathname corresponding to
4005 it's also checked for existence and whether it is a directory; otherwise,
4007 returns 0 if the pathname either exists or can be created immediately,
4008 i.e. all but the last component exist and are directories.
4009 For calls from the shell, if any options are given, an external
4011 utility is preferred over the builtin.
4022 Both must be complete pathnames and on the same device.
4023 An external utility is preferred over this builtin,
4024 which is intended for emergency situations
4025 .Pq where Pa /bin/mv No becomes unusable
4029 .It Ic return Op Ar status
4030 Returns from a function or
4032 script, with exit status
4036 is given, the exit status of the last executed command is used.
4037 If used outside of a function or
4039 script, it has the same effect as
4043 treats both profile and
4047 scripts, while the original Korn shell only treats profiles as
4052 .Ic set Op Ic +\-abCefhiklmnprsUuvXx
4053 .Op Ic +\-o Ar option
4060 command can be used to set
4064 shell options, set the positional parameters, or set an array parameter.
4065 Options can be changed using the
4069 is the long name of an option, or using the
4070 .Cm +\- Ns Ar letter
4073 is the option's single letter name (not all options have a single letter name).
4074 The following table lists both option letters (if they exist) and long names
4075 along with a description of what the option does:
4078 Sets the elements of the array parameter
4084 is used, the array is reset (i.e. emptied) first; if
4086 is used, the first N elements are set (where N is the number of arguments);
4087 the rest are left untouched.
4089 An alternative syntax for the command
4090 .Ic set \-A foo \-\- a b c
4091 which is compatible to
4094 and also supported by
4098 .Ic foo=(a b c); foo+=(d e)
4099 .It Fl a \*(Ba Fl o Ic allexport
4100 All new parameters are created with the export attribute.
4101 .It Fl b \*(Ba Fl o Ic notify
4102 Print job notification messages asynchronously, instead of just before the
4104 Only used if job control is enabled
4106 .It Fl C \*(Ba Fl o Ic noclobber
4107 Prevent \*(Gt redirection from overwriting existing files.
4108 Instead, \*(Gt\*(Ba must be used to force an overwrite.
4109 Note that this is not safe to use for creation of temporary files or
4110 lockfiles due to a TOCTOU in a check allowing one to redirect output to
4112 or other device files even in
4115 .It Fl e \*(Ba Fl o Ic errexit
4116 Exit (after executing the
4118 trap) as soon as an error occurs or a command fails (i.e. exits with a
4120 This does not apply to commands whose exit status is
4121 explicitly tested by a shell construct such as
4132 only the status of the last command is tested.
4133 .It Fl f \*(Ba Fl o Ic noglob
4134 Do not expand file name patterns.
4135 .It Fl h \*(Ba Fl o Ic trackall
4136 Create tracked aliases for all executed commands (see
4139 Enabled by default for non-interactive shells.
4140 .It Fl i \*(Ba Fl o Ic interactive
4141 The shell is an interactive shell.
4142 This option can only be used when the shell is invoked.
4143 See above for a description of what this means.
4144 .It Fl k \*(Ba Fl o Ic keyword
4145 Parameter assignments are recognised anywhere in a command.
4146 .It Fl l \*(Ba Fl o Ic login
4147 The shell is a login shell.
4148 This option can only be used when the shell is invoked.
4149 See above for a description of what this means.
4150 .It Fl m \*(Ba Fl o Ic monitor
4151 Enable job control (default for interactive shells).
4152 .It Fl n \*(Ba Fl o Ic noexec
4153 Do not execute any commands.
4154 Useful for checking the syntax of scripts
4155 (ignored if interactive).
4156 .It Fl p \*(Ba Fl o Ic privileged
4157 The shell is a privileged shell.
4158 It is set automatically if, when the shell starts,
4159 the real UID or GID does not match
4160 the effective UID (EUID) or GID (EGID), respectively.
4161 See above for a description of what this means.
4162 .It Fl r \*(Ba Fl o Ic restricted
4163 The shell is a restricted shell.
4164 This option can only be used when the shell is invoked.
4165 See above for a description of what this means.
4166 .It Fl s \*(Ba Fl o Ic stdin
4167 If used when the shell is invoked, commands are read from standard input.
4168 Set automatically if the shell is invoked with no arguments.
4174 command it causes the specified arguments to be sorted before assigning them to
4175 the positional parameters (or to array
4180 .It Fl U \*(Ba Fl o Ic utf8\-mode
4181 Enable UTF-8 support in the
4182 .Sx Emacs editing mode
4183 and internal string handling functions.
4184 This flag is disabled by default, but can be enabled by setting it on the
4185 shell command line; is enabled automatically for interactive shells if
4186 requested at compile time, your system supports
4187 .Fn setlocale LC_CTYPE \&""
4189 .Fn nl_langinfo CODESET ,
4195 environment variables,
4196 and at least one of these returns something that matches
4200 case-insensitively; for direct builtin calls depending on the
4201 aforementioned environment variables; or for stdin or scripts,
4202 if the input begins with a UTF-8 Byte Order Mark.
4204 In near future, locale tracking will be implemented, which means that
4206 is changed whenever one of the
4208 locale-related environment variables changes.
4209 .It Fl u \*(Ba Fl o Ic nounset
4210 Referencing of an unset parameter, other than
4214 is treated as an error, unless one of the
4220 .It Fl v \*(Ba Fl o Ic verbose
4221 Write shell input to standard error as it is read.
4222 .It Fl X \*(Ba Fl o Ic markdirs
4223 Mark directories with a trailing
4225 during file name generation.
4226 .It Fl x \*(Ba Fl o Ic xtrace
4227 Print command trees when they are executed, preceded by
4231 Background jobs are run with lower priority.
4232 .It Fl o Ic braceexpand
4233 Enable brace expansion (a.k.a. alternation).
4234 This is enabled by default.
4236 Enable BRL emacs-like command-line editing (interactive shells only); see
4237 .Sx Emacs editing mode .
4239 Enable gmacs-like command-line editing (interactive shells only).
4240 Currently identical to emacs editing except that transpose\-chars (\*(haT) acts
4241 slightly differently.
4242 .It Fl o Ic ignoreeof
4243 The shell will not (easily) exit when end-of-file is read;
4246 To avoid infinite loops, the shell will exit if
4248 is read 13 times in a row.
4249 .It Fl o Ic inherit\-xtrace
4252 upon entering functions.
4253 This is enabled by default.
4255 Do not kill running jobs with a
4257 signal when a login shell exits.
4258 Currently set by default, but this may
4259 change in the future to be compatible with
4263 doesn't have this option, but does send the
4268 In the original Korn shell, this prevents function definitions from
4269 being stored in the history file.
4270 .It Fl o Ic physical
4277 (i.e. the filesystem's)
4279 directories instead of
4281 directories (i.e. the shell handles
4283 which allows the user to be oblivious of symbolic links to directories).
4285 Note that setting this option does not affect the current value of the
4295 commands above for more details.
4296 .It Fl o Ic pipefail
4297 Make the exit status of a pipeline (before logically complementing) the
4298 rightmost non-zero errorlevel, or zero if all commands exited with zero.
4300 Behave closer to the standards
4304 Automatically enabled if the basename of the shell invocation begins with
4306 and this autodetection feature is compiled in
4308 As a side effect, setting this flag turns off
4310 mode, which can be turned back on manually, and
4312 mode (unless both are enabled at the same time).
4319 Automatically enabled if the basename of the shell invocation begins with
4321 and this autodetection feature is compiled in
4323 As a side effect, setting this flag turns off
4325 mode, which can be turned back on manually, and
4327 mode (unless both are enabled at the same time).
4331 command-line editing (interactive shells only).
4334 for documentation and limitations.
4335 .It Fl o Ic vi\-esccomplete
4336 In vi command-line editing, do command and file name completion when escape
4337 (\*(ha[) is entered in command mode.
4338 .It Fl o Ic vi\-tabcomplete
4339 In vi command-line editing, do command and file name completion when tab (\*(haI)
4340 is entered in insert mode.
4341 This is the default.
4344 In the original Korn shell, unless
4346 was set, the vi command-line mode would let the
4348 driver do the work until ESC (\*(ha[) was entered.
4350 is always in viraw mode.
4353 These options can also be used upon invocation of the shell.
4355 options (with single letter names) can be found in the parameter
4358 with no option name will list all the options and whether each is on or off;
4360 will print the long names of all options that are currently on.
4361 In a future version,
4365 compliant and print commands to restore the current options instead.
4367 Remaining arguments, if any, are positional parameters and are assigned, in
4368 order, to the positional parameters (i.e. $1, $2, etc.).
4371 and there are no remaining arguments, all positional parameters are cleared.
4372 If no options or arguments are given, the values of all names are printed.
4373 For unknown historical reasons, a lone
4375 option is treated specially \*(en it clears both the
4381 .It Ic shift Op Ar number
4382 The positional parameters
4385 etc. are renamed to 1, 2, etc.
4389 .It Ic sleep Ar seconds
4390 Suspends execution for a minimum of the
4392 specified as positive decimal value with an optional fractional part.
4393 Signal delivery may continue execution earlier.
4395 .It Ic source Ar file Op Ar arg ...
4397 .Ic \&. Po Do dot Dc Pc ,
4398 except that the current working directory is appended to the
4404 Stops the shell as if it had received the suspend character from
4406 It is not possible to suspend a login shell unless the parent process
4407 is a member of the same terminal session but is a member of a different
4409 As a general rule, if the shell was started by another shell or via
4411 it can be suspended.
4413 .It Ic test Ar expression
4414 .It Ic \&[ Ar expression Ic \&]
4418 and returns zero status if true, 1 if false, or greater than 1 if there
4420 It is normally used as the condition command of
4425 Symbolic links are followed for all
4432 The following basic expressions are available:
4439 is a block special device.
4442 is a character special device.
4454 group is the shell's effective group ID.
4457 mode has the setgid bit set.
4460 is a context dependent directory (only useful on HP-UX).
4474 owner is the shell's effective user ID.
4481 exists and is readable.
4485 .Xr unix 4 Ns -domain
4498 mode has the setuid bit set.
4501 exists and is writable.
4504 exists and is executable.
4505 .It Ar file1 Fl nt Ar file2
4514 .It Ar file1 Fl ot Ar file2
4523 .It Ar file1 Fl ef Ar file2
4529 has non-zero length.
4545 command above for a list of options).
4546 As a non-standard extension, if the option starts with a
4548 the test is negated; the test always fails if
4550 doesn't exist (so [ \-o foo \-o \-o !foo ] returns true if and only if option
4553 The same can be achieved with [ \-o ?foo ] like in
4557 can also be the short flag led by either
4561 .Pq no logical negation ,
4568 .It Ar string No = Ar string
4570 .It Ar string No == Ar string
4572 .It Ar string No \*(Gt Ar string
4573 First string operand is greater than second string operand.
4574 .It Ar string No \*(Lt Ar string
4575 First string operand is less than second string operand.
4576 .It Ar string No != Ar string
4577 Strings are not equal.
4578 .It Ar number Fl eq Ar number
4579 Numbers compare equal.
4580 .It Ar number Fl ne Ar number
4581 Numbers compare not equal.
4582 .It Ar number Fl ge Ar number
4583 Numbers compare greater than or equal.
4584 .It Ar number Fl gt Ar number
4585 Numbers compare greater than.
4586 .It Ar number Fl le Ar number
4587 Numbers compare less than or equal.
4588 .It Ar number Fl \< Ar number
4589 Numbers compare less than.
4592 The above basic expressions, in which unary operators have precedence over
4593 binary operators, may be combined with the following operators (listed in
4594 increasing order of precedence):
4595 .Bd -literal -offset indent
4596 expr \-o expr Logical OR.
4597 expr \-a expr Logical AND.
4602 Note that a number actually may be an arithmetic expression, such as
4603 a mathematical term or the name of an integer variable:
4604 .Bd -literal -offset indent
4605 x=1; [ "x" \-eq 1 ] evaluates to true
4608 Note that some special rules are applied (courtesy of
4610 ) if the number of arguments to
4612 or inside the brackets
4614 is less than five: if leading
4616 arguments can be stripped such that only one to three arguments remain,
4617 then the lowered comparison is executed; (thanks to XSI) parentheses
4619 lower four- and three-argument forms to two- and one-argument forms,
4620 respectively; three-argument forms ultimately prefer binary operations,
4621 followed by negation and parenthesis lowering; two- and four-argument forms
4622 prefer negation followed by parenthesis; the one-argument form always implies
4626 A common mistake is to use
4627 .Dq Li if \&[ $foo = bar \&]
4628 which fails if parameter
4630 is empty or unset, if it has embedded spaces (i.e.\&
4632 octets) or if it is a unary operator like
4637 .Dq Li if \&[ x\&"$foo\&" = x"bar" \&]
4638 instead, or the double-bracket operator
4639 .Dq Li if \&[[ $foo = bar \&]]
4640 or, to avoid pattern matching (see
4643 .Dq Li if \&[[ $foo = \&"$bar" \&]]
4647 construct is not only more secure to use but also often faster.
4656 is given, the times used to execute the pipeline are reported.
4658 is given, then the user and system time used by the shell itself, and all the
4659 commands it has run since it was started, are reported.
4660 The times reported are the real time (elapsed time from start to finish),
4661 the user CPU time (time spent running in user mode), and the system CPU time
4662 (time spent running in kernel mode).
4663 Times are reported to standard error; the format of the output is:
4665 .Dl "0m0.00s real 0m0.00s user 0m0.00s system"
4669 option is given the output is slightly longer:
4670 .Bd -literal -offset indent
4676 It is an error to specify the
4680 is a simple command.
4682 Simple redirections of standard error do not affect the output of the
4686 .Dl $ time sleep 1 2\*(Gtafile
4687 .Dl $ { time sleep 1; } 2\*(Gtafile
4689 Times for the first command do not go to
4691 but those of the second command do.
4694 Print the accumulated user and system times used both by the shell
4695 and by processes that the shell started which have exited.
4696 The format of the output is:
4697 .Bd -literal -offset indent
4702 .It Ic trap Ar n Op Ar signal ...
4703 If the first operand is a decimal unsigned integer, this resets all
4704 specified signals to the default action, i.e. is the same as calling
4710 followed by the arguments
4711 .Pq Ar n Op Ar signal ... ,
4712 all of which are treated as signals.
4714 .It Ic trap Op Ar handler signal ...
4715 Sets a trap handler that is to be executed when any of the specified
4719 is either an empty string, indicating the signals are to be ignored, a dash
4721 indicating that the default action is to be taken for the signals
4722 .Pq see Xr signal 3 ,
4723 or a string containing shell commands to be executed at the first opportunity
4724 (i.e. when the current command completes or before printing the next
4726 prompt) after receipt of one of the signals.
4728 is the name of a signal
4729 .Pq e.g.\& Dv PIPE or Dv ALRM
4730 or the number of the signal (see the
4734 There are two special signals:
4736 .Pq also known as 0 ,
4737 which is executed when the shell is about to exit, and
4739 which is executed after an error occurs; an error is something
4740 that would cause the shell to exit if the
4743 .Ic set Fl o Ic errexit
4746 handlers are executed in the environment of the last executed command.
4748 Note that, for non-interactive shells, the trap handler cannot be changed
4749 for signals that were ignored when the shell started.
4751 With no arguments, the current state of the traps that have been set since
4752 the shell started is shown as a series of
4755 Note that the output of
4757 cannot be usefully piped to another process (an artifact of the fact that
4758 traps are cleared when subprocesses are created).
4760 The original Korn shell's
4762 trap and the handling of
4766 traps in functions are not yet implemented.
4769 A command that exits with a zero value.
4773 .Op Ic +\-aglpnrtUux
4775 .No \*(Ba Fl R Ns Op Ar n
4776 .No \*(Ba Fl Z Ns Op Ar n Oc
4779 .Op Ns = Ns Ar value
4787 Display or set parameter attributes.
4788 This is a declaration utility.
4791 arguments, parameter attributes are displayed; if no options are used, the
4792 current attributes of all parameters are printed as
4794 commands; if an option is given (or
4796 with no option letter), all parameters and their values with the specified
4797 attributes are printed; if options are introduced with
4799 parameter values are not printed.
4803 arguments are given, the attributes of the named parameters are set
4807 inside a function, this will cause the parameters to be created
4808 (with no value) in the local scope (but see
4810 Values for parameters may optionally be specified.
4813 the change affects all elements of the array, and no value may be specified.
4819 operates on the attributes of functions.
4820 As with parameters, if no
4822 arguments are given,
4823 functions are listed with their values (i.e. definitions) unless
4824 options are introduced with
4826 in which case only the function names are reported.
4829 Indexed array attribute.
4832 Display or set functions and their attributes, instead of parameters.
4834 Do not cause named parameters to be created in
4835 the local scope when called inside a function.
4839 specifies the base to use when displaying the integer (if not specified, the
4840 base given in the first assignment is used).
4841 Parameters with this attribute may
4842 be assigned values containing arithmetic expressions.
4844 Left justify attribute.
4846 specifies the field width.
4849 is not specified, the current width of a parameter (or the width of its first
4850 assigned value) is used.
4851 Leading whitespace (and zeros, if used with the
4853 option) is stripped.
4854 If necessary, values are either truncated or space padded
4855 to fit the field width.
4857 Lower case attribute.
4858 All upper case ASCII characters in values are converted to lower case.
4859 (In the original Korn shell, this parameter meant
4865 Create a bound variable (name reference): any access to the variable
4867 will access the variable
4869 in the current scope (this is different from
4878 is lazily evaluated at the time
4881 This can be used by functions to access variables whose names are
4882 passed as parameters, instead of using
4887 commands that can be used to re-create the attributes and values of
4890 Right justify attribute.
4892 specifies the field width.
4895 is not specified, the current width of a parameter (or the width of its first
4896 assigned value) is used.
4897 Trailing whitespace is stripped.
4898 If necessary, values are either stripped of leading characters or space
4899 padded to make them fit the field width.
4901 Read-only attribute.
4902 Parameters with this attribute may not be assigned to or unset.
4903 Once this attribute is set, it cannot be turned off.
4906 Has no meaning to the shell; provided for application use.
4910 is the trace attribute.
4911 When functions with the trace attribute are executed, the
4914 shell option is temporarily turned on.
4916 Unsigned integer attribute.
4917 Integers are printed as unsigned values (combine with the
4920 This option is not in the original Korn shell.
4922 Upper case attribute.
4923 All lower case ASCII characters in values are converted to upper case.
4924 (In the original Korn shell, this parameter meant
4925 .Dq unsigned integer
4928 option which meant upper case letters would never be used for bases greater
4936 is the undefined attribute.
4939 above for the implications of this.
4942 Parameters (or functions) are placed in the environment of
4943 any executed commands.
4944 Exported functions are not yet implemented.
4946 Zero fill attribute.
4947 If not combined with
4951 except zero padding is used instead of space padding.
4952 For integers, the number instead of the base is padded.
4965 options are changed, all others from this set are cleared,
4966 unless they are also given on the same command line.
4970 .Op Fl aBCcdefHilMmnOPpqrSsTtVvw
4973 Display or set process limits.
4974 If no options are used, the file size limit
4978 if specified, may be either an arithmetic expression or the word
4980 The limits affect the shell and any processes created by the shell after a
4982 Note that some systems may not allow limits to be increased
4984 Also note that the types of limits available are system
4985 dependent \*(en some systems have only the
4987 limit, or not even that, or can set only the soft limits
4990 Display all limits; unless
4992 is used, soft limits are displayed.
4994 Set the socket buffer size to
4998 Set the number of cached threads to
5001 Impose a size limit of
5003 blocks on the size of core dumps.
5005 Impose a size limit of
5007 kibibytes on the size of the data area.
5009 Set the maximum niceness to
5012 Impose a size limit of
5014 blocks on files written by the shell and its child processes (files of any
5017 Set the hard limit only (the default is to set both hard and soft limits).
5019 Set the number of pending signals to
5024 kibibytes on the amount of locked (wired) physical memory.
5026 Set the AIO locked memory to
5032 kibibytes on the amount of physical memory used.
5036 file descriptors that can be open at once.
5038 Set the number of AIO operations to
5041 Limit the number of threads per process to
5046 processes that can be run by the user at any one time.
5054 Set the maximum real-time priority to
5057 Set the soft limit only (the default is to set both hard and soft limits).
5059 Impose a size limit of
5061 kibibytes on the size of the stack area.
5063 Impose a time limit of
5065 real seconds to be used by each process.
5067 Impose a time limit of
5069 CPU seconds spent in user mode to be used by each process.
5071 Set the number of vnode monitors on Haiku to
5076 kibibytes on the amount of virtual memory (address space) used.
5080 kibibytes on the amount of swap space used.
5085 is concerned, a block is 512 bytes.
5092 Display or set the file permission creation mask or umask (see
5096 option is used, the mask displayed or set is symbolic; otherwise, it is an
5099 Symbolic masks are like those used by
5101 When used, they describe what permissions may be made available (as opposed to
5102 octal masks in which a set bit means the corresponding bit is to be cleared).
5105 sets the mask so files will not be readable, writable or executable by
5107 and is equivalent (on most systems) to the octal mask
5115 The aliases for the given names are removed.
5118 option is used, all aliases are removed.
5123 options are used, the indicated operations are carried out on tracked or
5124 directory aliases, respectively.
5131 Unset the named parameters
5139 .Ar parameter Ns \&[*] ,
5140 attributes are kept, only values are unset.
5142 The exit status is non-zero if any of the parameters have the read-only
5143 attribute set, zero otherwise.
5145 .It Ic wait Op Ar job ...
5146 Wait for the specified job(s) to finish.
5149 is that of the last specified job; if the last job is killed by a signal, the
5150 exit status is 128 + the number of the signal (see
5151 .Ic kill Fl l Ar exit-status
5152 above); if the last specified job can't be found (because it never existed or
5153 had already finished), the exit status of
5158 below for the format of
5161 will return if a signal for which a trap has been set is received or if a
5168 If no jobs are specified,
5170 waits for all currently running jobs (if any) to finish and exits with a zero
5172 If job monitoring is enabled, the completion status of jobs is printed
5173 (this is not the case when jobs are explicitly specified).
5182 option, it is the same as
5184 except aliases are not printed as alias command.
5187 option, it is exactly the same as
5191 option differs: the search path is not affected in
5193 but the search is restricted to the path.
5196 Job control refers to the shell's ability to monitor and control jobs which
5197 are processes or groups of processes created for commands or pipelines.
5198 At a minimum, the shell keeps track of the status of the background (i.e.\&
5199 asynchronous) jobs that currently exist; this information can be displayed
5203 If job control is fully enabled (using
5206 .Ic set Fl o Ic monitor ) ,
5207 as it is for interactive shells, the processes of a job are placed in their
5209 Foreground jobs can be stopped by typing the suspend
5210 character from the terminal (normally \*(haZ), jobs can be restarted in either the
5211 foreground or background using the
5215 commands, and the state of the terminal is saved or restored when a foreground
5216 job is stopped or restarted, respectively.
5218 Note that only commands that create processes (e.g. asynchronous commands,
5219 subshell commands and non-built-in, non-function commands) can be stopped;
5224 When a job is created, it is assigned a job number.
5225 For interactive shells, this number is printed inside
5227 followed by the process IDs of the processes in the job when an asynchronous
5229 A job may be referred to in the
5236 commands either by the process ID of the last process in the command pipeline
5239 parameter) or by prefixing the job number with a percent sign
5241 Other percent sequences can also be used to refer to jobs:
5242 .Bl -tag -width "%+ x %% x %XX"
5243 .It %+ \*(Ba %% \*(Ba %
5244 The most recently stopped job or, if there are no stopped jobs, the oldest
5247 The job that would be the
5249 job if the latter did not exist.
5251 The job with job number
5254 The job with its command containing the string
5256 (an error occurs if multiple jobs are matched).
5258 The job with its command starting with the string
5260 (an error occurs if multiple jobs are matched).
5263 When a job changes state (e.g. a background job finishes or foreground job is
5264 stopped), the shell prints the following status information:
5266 .D1 [ Ns Ar number ] Ar flag status command
5269 .Bl -tag -width "command"
5271 is the job number of the job;
5277 character if the job is the
5281 job, respectively, or space if it is neither;
5283 indicates the current state of the job and can be:
5284 .Bl -tag -width "RunningXX"
5285 .It Done Op Ar number
5288 is the exit status of the job which is omitted if the status is zero.
5290 The job has neither stopped nor exited (note that running does not necessarily
5291 mean consuming CPU time \*(en
5292 the process could be blocked waiting for some event).
5293 .It Stopped Op Ar signal
5294 The job was stopped by the indicated
5296 (if no signal is given, the job was stopped by
5298 .It Ar signal-description Op Dq core dumped
5299 The job was killed by a signal (e.g. memory fault, hangup); use
5301 for a list of signal descriptions.
5304 message indicates the process created a core file.
5307 is the command that created the process.
5308 If there are multiple processes in
5309 the job, each process will have a line showing its
5313 if it is different from the status of the previous process.
5316 When an attempt is made to exit the shell while there are jobs in the stopped
5317 state, the shell warns the user that there are stopped jobs and does not exit.
5318 If another attempt is immediately made to exit the shell, the stopped jobs are
5321 signal and the shell exits.
5324 option is not set and there are running jobs when an attempt is made to exit
5325 a login shell, the shell warns the user and does not exit.
5327 is immediately made to exit the shell, the running jobs are sent a
5329 signal and the shell exits.
5332 .Ic set Fl o Ic posix
5337 compliant in places where the defaults or opinions differ.
5340 will still operate with unsigned 32-bit arithmetic; use
5342 if arithmetic on the host
5344 data type, complete with ISO C Undefined Behaviour, is required;
5347 manual page for details.
5348 Most other historic,
5350 .Nm ksh Ns -compatible
5351 or opinionated differences can be disabled by using this mode; these are:
5354 The incompatible GNU
5357 .Ic &\*(Gt Ns Ar file
5360 File descriptors created by I/O redirections are inherited by
5363 Numbers with a leading digit zero are interpreted as octal.
5367 builtin does not interpret backslashes and only supports the exact option
5370 Alias expansion with a trailing space only reruns on command words.
5372 Tilde expansion follows POSIX instead of Korn shell rules.
5380 only lists signal names, all in one line.
5383 does not accept options with a leading
5387 Compatibility mode; intended for use with legacy scripts that
5388 cannot easily be fixed; the changes are as follows:
5391 The incompatible GNU
5394 .Ic &\*(Gt Ns Ar file
5397 File descriptors created by I/O redirections are inherited by
5402 builtin does not interpret backslashes and only supports the exact option
5405 .Ev \-DMKSH_MIDNIGHTBSD01ASH_COMPAT .
5407 The substitution operations
5417 .Pf ## Ar pat No } ,
5433 wrongly do not require a parenthesis to be escaped and do not parse extglobs.
5435 The getopt construct from
5437 passes through the errorlevel.
5444 .Ev \-DMKSH_MIDNIGHTBSD01ASH_COMPAT .
5446 .Ss Interactive input line editing
5447 The shell supports three modes of reading command lines from a
5449 in an interactive session, controlled by the
5454 options (at most one of these can be set at once).
5457 Editing modes can be set explicitly using the
5460 If none of these options are enabled,
5461 the shell simply reads lines using the normal
5468 option is set, the shell allows emacs-like editing of the command; similarly,
5471 option is set, the shell allows vi-like editing of the command.
5472 These modes are described in detail in the following sections.
5474 In these editing modes, if a line is longer than the screen width (see the
5482 character is displayed in the last column indicating that there are more
5483 characters after, before and after, or before the current position,
5485 The line is scrolled horizontally as necessary.
5487 Completed lines are pushed into the history, unless they begin with an
5488 IFS octet or IFS white space or are the same as the previous line.
5489 .Ss Emacs editing mode
5492 option is set, interactive input line editing is enabled.
5493 Warning: This mode is
5494 slightly different from the emacs mode in the original Korn shell.
5495 In this mode, various editing commands
5496 (typically bound to one or more control characters) cause immediate actions
5497 without waiting for a newline.
5498 Several editing commands are bound to particular
5499 control characters when the shell is invoked; these bindings can be changed
5504 The following is a list of available editing commands.
5505 Each description starts with the name of the command,
5506 suffixed with a colon;
5509 (if the command can be prefixed with a count); and any keys the command is
5510 bound to by default, written using caret notation
5511 e.g. the ASCII ESC character is written as \*(ha[.
5512 These control sequences are not case sensitive.
5513 A count prefix for a command is entered using the sequence
5514 .Pf \*(ha[ Ns Ar n ,
5517 is a sequence of 1 or more digits.
5518 Unless otherwise specified, if a count is
5519 omitted, it defaults to 1.
5521 Note that editing command names are used only with the
5524 Furthermore, many editing commands are useful only on terminals with
5531 reasonable substitutes and override the default bindings;
5532 their customary values are shown in parentheses below.
5533 The default bindings were chosen to resemble corresponding
5537 .No INTR Pq \*(haC ,
5540 Abort the current command, empty the line buffer and
5541 set the exit state to interrupted.
5542 .It auto\-insert: Op Ar n
5543 Simply causes the character to appear as literal input.
5544 Most ordinary characters are bound to this.
5545 .It Xo backward\-char:
5547 .No \*(haB , \*(haXD , ANSI-CurLeft , PC-CurLeft
5549 Moves the cursor backward
5552 .It Xo backward\-word:
5554 .No \*(ha[b , ANSI-Ctrl-CurLeft , ANSI-Alt-CurLeft
5556 Moves the cursor backward to the beginning of the word; words consist of
5557 alphanumerics, underscore
5562 .It beginning\-of\-history: \*(ha[\*(Lt
5563 Moves to the beginning of the history.
5564 .It beginning\-of\-line: \*(haA, ANSI-Home, PC-Home
5565 Moves the cursor to the beginning of the edited input line.
5566 .It Xo capitalise\-word:
5568 .No \*(ha[C , \*(ha[c
5570 Uppercase the first ASCII character in the next
5572 words, leaving the cursor past the end of the last word.
5573 .It clear\-screen: \*(ha[\*(haL
5574 Prints a compile-time configurable sequence to clear the screen and home
5575 the cursor, redraws the entire prompt and the currently edited input line.
5576 The default sequence works for almost all standard terminals.
5577 .It comment: \*(ha[#
5578 If the current line does not begin with a comment character, one is added at
5579 the beginning of the line and the line is entered (as if return had been
5580 pressed); otherwise, the existing comment characters are removed and the cursor
5581 is placed at the beginning of the line.
5582 .It complete: \*(ha[\*(ha[
5583 Automatically completes as much as is unique of the command name or the file
5584 name containing the cursor.
5585 If the entire remaining command or file name is
5586 unique, a space is printed after its completion, unless it is a directory name
5590 If there is no command or file name with the current partial word
5591 as its prefix, a bell character is output (usually causing a beep to be
5593 .It complete\-command: \*(haX\*(ha[
5594 Automatically completes as much as is unique of the command name having the
5595 partial word up to the cursor as its prefix, as in the
5598 .It complete\-file: \*(ha[\*(haX
5599 Automatically completes as much as is unique of the file name having the
5600 partial word up to the cursor as its prefix, as in the
5602 command described above.
5603 .It complete\-list: \*(haI, \*(ha[=
5604 Complete as much as is possible of the current word
5605 and list the possible completions for it.
5606 If only one completion is possible,
5610 Note that \*(haI is usually generated by the TAB (tabulator) key.
5611 .It Xo delete\-char\-backward:
5613 .No ERASE Pq \*(haH ,
5618 characters before the cursor.
5619 .It Xo delete\-char\-forward:
5621 .No ANSI-Del , PC-Del
5625 characters after the cursor.
5626 .It Xo delete\-word\-backward:
5628 .No Pfx1+ERASE Pq \*(ha[\*(haH ,
5629 .No WERASE Pq \*(haW ,
5630 .No \*(ha[\*(ha? , \*(ha[\*(haH , \*(ha[h
5634 words before the cursor.
5635 .It Xo delete\-word\-forward:
5639 Deletes characters after the cursor up to the end of
5642 .It Xo down\-history:
5644 .No \*(haN , \*(haXB , ANSI-CurDown , PC-CurDown
5646 Scrolls the history buffer forward
5649 Each input line originally starts just after the last entry
5650 in the history buffer, so
5652 is not useful until either
5653 .Ic search\-history ,
5654 .Ic search\-history\-up
5658 .It Xo downcase\-word:
5660 .No \*(ha[L , \*(ha[l
5671 or the current line, if not specified, interactively.
5672 The actual command executed is
5673 .Ic fc \-e ${VISUAL:\-${EDITOR:\-vi}} Ar n .
5674 .It end\-of\-history: \*(ha[\*(Gt
5675 Moves to the end of the history.
5676 .It end\-of\-line: \*(haE, ANSI-End, PC-End
5677 Moves the cursor to the end of the input line.
5679 Acts as an end-of-file; this is useful because edit-mode input disables
5680 normal terminal input canonicalisation.
5681 .It Xo eot\-or\-delete:
5685 If alone on a line, same as
5688 .Ic delete\-char\-forward .
5689 .It error: (not bound)
5690 Error (ring the bell).
5691 .It evaluate\-region: \*(ha[\*(haE
5692 Evaluates the text between the mark and the cursor position
5693 .Pq the entire line if no mark is set
5694 as function substitution (if it cannot be parsed, the editing state is
5695 unchanged and the bell is rung to signal an error); $? is updated accordingly.
5696 .It exchange\-point\-and\-mark: \*(haX\*(haX
5697 Places the cursor where the mark is and sets the mark to where the cursor was.
5698 .It expand\-file: \*(ha[*
5701 to the current word and replaces the word with the result of performing file
5702 globbing on the word.
5703 If no files match the pattern, the bell is rung.
5704 .It Xo forward\-char:
5706 .No \*(haF , \*(haXC , ANSI-CurRight , PC-CurRight
5708 Moves the cursor forward
5711 .It Xo forward\-word:
5713 .No \*(ha[f , ANSI-Ctrl-CurRight , ANSI-Alt-CurRight
5715 Moves the cursor forward to the end of the
5718 .It Xo goto\-history:
5722 Goes to history number
5727 Deletes the entire input line.
5728 .It kill\-region: \*(haW
5729 Deletes the input between the cursor and the mark.
5730 .It Xo kill\-to\-eol:
5734 Deletes the input from the cursor to the end of the line if
5736 is not specified; otherwise deletes characters between the cursor and column
5739 Prints a sorted, columnated list of command names or file names (if any) that
5740 can complete the partial word containing the cursor.
5741 Directory names have
5744 .It list\-command: \*(haX?
5745 Prints a sorted, columnated list of command names (if any) that can complete
5746 the partial word containing the cursor.
5747 .It list\-file: \*(haX\*(haY
5748 Prints a sorted, columnated list of file names (if any) that can complete the
5749 partial word containing the cursor.
5750 File type indicators are appended as described under
5753 .It newline: \*(haJ , \*(haM
5754 Causes the current input line to be processed by the shell.
5755 The current cursor position may be anywhere on the line.
5756 .It newline\-and\-next: \*(haO
5757 Causes the current input line to be processed by the shell, and the next line
5758 from history becomes the current line.
5759 This is only useful after an
5763 .Ic search\-history\-up .
5768 .It prefix\-1: \*(ha[
5769 Introduces a 2-character command sequence.
5770 .It prefix\-2: \*(haX , \*(ha[[ , \*(ha[O
5771 Introduces a multi-character command sequence.
5772 .It Xo prev\-hist\-word:
5774 .No \*(ha[. , \*(ha[_
5776 The last word or, if given, the
5778 word (zero-based) of the previous (on repeated execution, second-last,
5779 third-last, etc.) command is inserted at the cursor.
5780 Use of this editing command trashes the mark.
5781 .It quote: \*(ha\*(ha , \*(haV
5782 The following character is taken literally rather than as an editing command.
5784 Reprints the last line of the prompt string and the current input line
5786 .It Xo search\-character\-backward:
5790 Search backward in the current line for the
5792 occurrence of the next character typed.
5793 .It Xo search\-character\-forward:
5797 Search forward in the current line for the
5799 occurrence of the next character typed.
5800 .It search\-history: \*(haR
5801 Enter incremental search mode.
5802 The internal history list is searched
5803 backwards for commands matching the input.
5806 in the search string anchors the search.
5807 The escape key will leave search mode.
5808 Other commands, including sequences of escape as
5814 key will be executed after leaving search mode.
5817 command will restore the input line before search started.
5820 commands continue searching backward to the next previous occurrence of the
5822 The history buffer retains only a finite number of lines; the oldest
5823 are discarded as necessary.
5824 .It search\-history\-up: ANSI-PgUp, PC-PgUp
5825 Search backwards through the history buffer for commands whose beginning match
5826 the portion of the input line before the cursor.
5827 When used on an empty line, this has the same effect as
5829 .It search\-history\-down: ANSI-PgDn, PC-PgDn
5830 Search forwards through the history buffer for commands whose beginning match
5831 the portion of the input line before the cursor.
5832 When used on an empty line, this has the same effect as
5834 This is only useful after an
5838 .Ic search\-history\-up .
5839 .It set\-mark\-command: \*(ha[ Ns Aq space
5840 Set the mark at the cursor position.
5841 .It transpose\-chars: \*(haT
5842 If at the end of line or, if the
5844 option is set, this exchanges the two previous characters; otherwise, it
5845 exchanges the previous and current characters and moves the cursor one
5846 character to the right.
5849 .No \*(haP , \*(haXA , ANSI-CurUp , PC-CurUp
5851 Scrolls the history buffer backward
5854 .It Xo upcase\-word:
5856 .No \*(ha[U , \*(ha[u
5861 .It version: \*(ha[\*(haV
5862 Display the version of
5864 The current edit buffer is restored as soon as a key is pressed.
5865 The restoring keypress is processed, unless it is a space.
5867 Inserts the most recently killed text string at the current cursor position.
5868 .It yank\-pop: \*(ha[y
5871 replaces the inserted text string with the next previously killed text string.
5874 The tab completion escapes characters the same way as the following code:
5876 print \-nr \-\- "${x@/[\e"\-\e$\e&\-*:\-?[\e\e\e\`{\-\e}${IFS\-$\*(aq \et\en\*(aq}]/\e\e$KSH_MATCH}"
5880 The vi command-line editing mode is orphaned, yet still functional.
5881 It is 8-bit clean but specifically does not support UTF-8 or MBCS.
5883 The vi command-line editor in
5885 has basically the same commands as the
5887 editor with the following exceptions:
5890 You start out in insert mode.
5892 There are file name and command completion commands:
5893 =, \e, *, \*(haX, \*(haE, \*(haF and, optionally,
5900 command is different (in
5902 it is the last argument command; in
5904 it goes to the start of the current line).
5910 commands move in the opposite direction to the
5914 Commands which don't make sense in a single line editor are not available
5915 (e.g. screen movement commands and
5924 there are two modes:
5929 In insert mode, most characters are simply put in the buffer at the
5930 current cursor position as they are typed; however, some characters are
5932 In particular, the following characters are taken from current
5937 and have their usual meaning (normal values are in parentheses): kill (\*(haU),
5938 erase (\*(ha?), werase (\*(haW), eof (\*(haD), intr (\*(haC) and quit (\*(ha\e).
5940 the above, the following characters are also treated specially in insert mode:
5941 .Bl -tag -width XJXXXXM
5943 Command and file name enumeration (see below).
5945 Command and file name completion (see below).
5946 If used twice in a row, the
5947 list of possible completions is displayed; if used a third time, the completion
5950 Erases previous character.
5951 .It \*(haJ \*(Ba \*(haM
5953 The current line is read, parsed and executed by the shell.
5956 The next character typed is not treated specially (can be used
5957 to insert the characters being described here).
5959 Command and file name expansion (see below).
5961 Puts the editor in command mode (see below).
5963 Optional file name and command completion (see
5965 above), enabled with
5966 .Ic set Fl o Ic vi\-tabcomplete .
5969 In command mode, each character is interpreted as a command.
5971 don't correspond to commands, are illegal combinations of commands, or are
5972 commands that can't be carried out, all cause beeps.
5973 In the following command descriptions, an
5975 indicates the command may be prefixed by a number (e.g.\&
5977 moves right 10 characters); if no number prefix is used,
5979 is assumed to be 1 unless otherwise specified.
5981 .Dq current position
5982 refers to the position between the cursor and the character preceding the
5986 is a sequence of letters, digits and underscore characters or a sequence of
5987 non-letter, non-digit, non-underscore and non-whitespace characters (e.g.\&
5989 contains two words) and a
5991 is a sequence of non-whitespace characters.
5997 The following commands are not in, or are different from, the normal vi file
6003 Insert a space followed by the
6005 big-word from the last command in the history at the current position and enter
6008 is not specified, the last word is inserted.
6010 Insert the comment character
6012 at the start of the current line and return the line to the shell (equivalent
6022 is not specified, it goes to the most recent remembered line.
6032 is not specified, the current line is edited.
6033 The actual command executed is
6034 .Ic fc \-e ${VISUAL:\-${EDITOR:\-vi}} Ar n .
6036 Command or file name expansion is applied to the current big-word (with an
6039 if the word contains no file globbing characters) \*(en the big-word is replaced
6040 with the resulting words.
6041 If the current big-word is the first on the line
6042 or follows one of the characters
6049 and does not contain a slash
6051 then command expansion is done; otherwise file name expansion is done.
6052 Command expansion will match the big-word against all aliases, functions and
6053 built-in commands as well as any executable files found by searching the
6057 File name expansion matches the big-word against the files in the
6059 After expansion, the cursor is placed just past the last
6060 word and the editor is in insert mode.
6063 .Oo Ar n Oc Ns \*(haF ,
6064 .Oo Ar n Oc Ns Aq tab ,
6066 .Oo Ar n Oc Ns Aq esc
6068 Command/file name completion.
6069 Replace the current big-word with the
6070 longest unique match obtained after performing command and file name expansion.
6072 is only recognised if the
6074 option is set, while
6076 is only recognised if the
6084 possible completion is selected (as reported by the command/file name
6085 enumeration command).
6087 Command/file name enumeration.
6088 List all the commands or files that match the current big-word.
6090 Display the version of
6092 The current edit buffer is restored as soon as a key is pressed.
6093 The restoring keypress is ignored.
6096 Execute the commands found in the alias
6100 Intra-line movement commands:
6103 .Oo Ar n Oc Ns h and
6104 .Oo Ar n Oc Ns \*(haH
6110 .Oo Ar n Oc Ns l and
6111 .Oo Ar n Oc Ns Aq space
6119 Move to the first non-whitespace character.
6121 .Oo Ar n Oc Ns \*(Ba
6126 Move to the last character.
6142 Move forward to the end of the word,
6148 Move forward to the end of the big-word,
6165 The editor looks forward for the nearest parenthesis, bracket or
6166 brace and then moves the cursor to the matching parenthesis, bracket or brace.
6168 .Oo Ar n Oc Ns f Ns Ar c
6172 occurrence of the character
6175 .Oo Ar n Oc Ns F Ns Ar c
6177 Move backward to the
6179 occurrence of the character
6182 .Oo Ar n Oc Ns t Ns Ar c
6184 Move forward to just before the
6186 occurrence of the character
6189 .Oo Ar n Oc Ns T Ns Ar c
6191 Move backward to just before the
6193 occurrence of the character
6210 command, but moves in the opposite direction.
6213 Inter-line movement commands:
6219 .Oo Ar n Oc Ns \*(haN
6223 next line in the history.
6228 .Oo Ar n Oc Ns \*(haP
6232 previous line in the history.
6240 is not specified, the number of the first remembered line is used.
6248 is not specified, it goes to the most recent remembered line.
6250 .Oo Ar n Oc Ns / Ns Ar string
6252 Search backward through the history for the
6260 the remainder of the string must appear at the start of the history line for
6263 .Oo Ar n Oc Ns \&? Ns Ar string
6267 except it searches forward through the history.
6273 occurrence of the last search string;
6274 the direction of the search is the same as the last search.
6280 occurrence of the last search string;
6281 the direction of the search is the opposite of the last search.
6282 .It Ar ANSI-CurUp , PC-PgUp
6283 Take the characters from the beginning of the line to the current
6284 cursor position as search string and do a backwards history search
6285 for lines beginning with this string; keep the cursor position.
6286 This works only in insert mode and keeps it enabled.
6296 times; goes into insert mode just after the current position.
6298 only replicated if command mode is re-entered i.e.\&
6306 except it appends at the end of the line.
6312 times; goes into insert mode at the current position.
6313 The insertion is only
6314 replicated if command mode is re-entered i.e.\&
6322 except the insertion is done just before the first non-blank character.
6328 characters (i.e. delete the characters and go into insert mode).
6330 Substitute whole line.
6331 All characters from the first non-blank character to the
6332 end of the line are deleted and insert mode is entered.
6334 .Oo Ar n Oc Ns c Ns Ar move-cmd
6336 Change from the current position to the position resulting from
6338 (i.e. delete the indicated region and go into insert mode); if
6342 the line starting from the first non-blank character is changed.
6344 Change from the current position to the end of the line (i.e. delete to the
6345 end of the line and go into insert mode).
6359 Delete to the end of the line.
6361 .Oo Ar n Oc Ns d Ns Ar move-cmd
6363 Delete from the current position to the position resulting from
6364 .Ar n move-cmd Ns s ;
6366 is a movement command (see above) or
6368 in which case the current line is deleted.
6370 .Oo Ar n Oc Ns r Ns Ar c
6374 characters with the character
6380 Enter insert mode but overwrite existing characters instead of
6381 inserting before existing characters.
6382 The replacement is repeated
6386 .Oo Ar n Oc Ns \*(TI
6388 Change the case of the next
6392 .Oo Ar n Oc Ns y Ns Ar move-cmd
6394 Yank from the current position to the position resulting from
6396 into the yank buffer; if
6400 the whole line is yanked.
6402 Yank from the current position to the end of the line.
6406 Paste the contents of the yank buffer just after the current position,
6414 except the buffer is pasted at the current position.
6417 Miscellaneous vi commands
6419 .It \*(haJ and \*(haM
6420 The current line is read, parsed and executed by the shell.
6421 .It \*(haL and \*(haR
6422 Redraw the current line.
6426 Redo the last edit command
6430 Undo the last edit command.
6432 Undo all changes that have been made to the current line.
6433 .It PC Home, End, Del and cursor keys
6434 They move as expected, both in insert and command mode.
6435 .It Ar intr No and Ar quit
6436 The interrupt and quit terminal characters cause the current line to be
6437 deleted and a new prompt to be printed.
6440 .Bl -tag -width XetcXsuid_profile -compact
6441 .It Pa \*(TI/.mkshrc
6442 User mkshrc profile (non-privileged interactive shells); see
6444 The location can be changed at compile time (for embedded systems);
6445 AOSP Android builds use
6446 .Pa /system/etc/mkshrc .
6447 .It Pa \*(TI/.profile
6448 User profile (non-privileged login shells); see
6450 near the top of this manual.
6452 System profile (login shells); see
6456 .It Pa /etc/suid_profile
6457 Suid profile (privileged shells); see
6463 contains the system and suid profile.
6495 .Pa http://www.mirbsd.org/ksh\-chan.htm
6498 .%B "The KornShell Command and Programming Language"
6500 .%I "Prentice Hall PTR"
6501 .%P "xvi\ +\ 356 pages"
6502 .%O "ISBN 978\-0\-13\-516972\-8 (0\-13\-516972\-0)"
6505 .%A Morris I. Bolsky
6507 .%B "The New KornShell Command and Programming Language (2nd Edition)"
6509 .%I "Prentice Hall PTR"
6510 .%P "xvi\ +\ 400 pages"
6511 .%O "ISBN 978\-0\-13\-182700\-4 (0\-13\-182700\-6)"
6514 .%A Stephen G. Kochan
6516 .%B "\\*(tNUNIX\\*(sP Shell Programming"
6520 .%P "xiii\ +\ 437 pages"
6521 .%O "ISBN 978\-0\-672\-32490\-1 (0\-672\-32490\-3)"
6525 .%T "\\*(tNIEEE\\*(sP Standard for Information Technology \*(en Portable Operating System Interface (POSIX)"
6526 .%V "Part 2: Shell and Utilities"
6529 .%P "xvii\ +\ 1195 pages"
6530 .%O "ISBN 978\-1\-55937\-255\-8 (1\-55937\-255\-9)"
6534 .%B "Learning the Korn Shell"
6538 .%O "ISBN 978\-1\-56592\-054\-5 (1\-56592\-054\-6)"
6543 .%B "Learning the Korn Shell, Second Edition"
6547 .%O "ISBN 978\-0\-596\-00195\-7 (0\-596\-00195\-9)"
6551 .%B "KornShell Programming Tutorial"
6553 .%I "Addison-Wesley Professional"
6554 .%P "xxi\ +\ 324 pages"
6555 .%O "ISBN 978\-0\-201\-56324\-5 (0\-201\-56324\-X)"
6559 .Nm "The MirBSD Korn Shell"
6561 .An mirabilos Aq Mt m@mirbsd.org
6562 as part of The MirOS Project.
6563 This shell is based on the public domain 7th edition Bourne shell clone by
6564 .An Charles Forsyth ,
6565 who kindly agreed to, in countries where the Public Domain status of the work
6566 may not be valid, grant a copyright licence to the general public to deal in
6567 the work without restriction and permission to sublicence derivatives under
6568 the terms of any (OSI approved) Open Source licence,
6569 and parts of the BRL shell by
6573 .An Arnold Robbins ,
6576 The first release of
6580 and it was subsequently maintained by
6581 .An John R. MacMillan ,
6582 .An Simon J. Gerraty
6584 .An Michael Rendell .
6585 The effort of several projects, such as Debian and OpenBSD, and other
6586 contributors including our users, to improve the shell is appreciated.
6587 See the documentation, web site and CVS for details.
6591 .An KO Myung-Hun Aq Mt komh@chollian.net .
6595 .An Michael Langguth Aq Mt lan@scalaris.com .
6597 The BSD daemon is Copyright \(co Marshall Kirk McKusick.
6598 The complete legalese is at:
6599 .Pa http://www.mirbsd.org/TaC\-mksh.txt
6601 .\" This boils down to: feel free to use mksh.ico as application icon
6602 .\" or shortcut for mksh or mksh/Win32 or OS/2; distro patches are ok
6603 .\" (but we request they amend $KSH_VERSION when modifying mksh).
6604 .\" Authors are Marshall Kirk McKusick (UCB), Rick Collette (ekkoBSD),
6605 .\" mirabilos, Benny Siegert (MirBSD), Michael Langguth (mksh/Win32),
6606 .\" KO Myung-Hun (mksh for OS/2).
6608 .\" As far as MirBSD is concerned, the files themselves are free
6609 .\" to modification and distribution under BSD/MirOS Licence, the
6610 .\" restriction on use stems only from trademark law's requirement
6611 .\" to protect it or lose it, which McKusick almost did.
6615 provides a consistent 32-bit integer arithmetic implementation, both
6616 signed and unsigned, with sign of the result of a remainder operation
6617 and wraparound defined, even (defying POSIX) on 36-bit and 64-bit systems.
6620 provides a consistent, clear interface normally.
6621 This may deviate from POSIX in historic or opinionated places.
6622 .Ic set Fl o Ic posix
6626 will cause the shell to behave more conformant.
6636 only supports the Unicode BMP (Basic Multilingual Plane) and maps
6637 raw octets into the U+EF80..U+EFFF wide character range; compare
6638 .Sx Arithmetic expressions .
6644 option dependent on the current
6646 locale for mksh to allow using the UTF-8 mode, within the constraints
6647 outlined above, in code portable across various shell implementations:
6648 .Bd -literal -offset indent
6649 case ${KSH_VERSION:\-} in
6650 *MIRBSD\ KSH*\*(Ba*LEGACY\ KSH*)
6651 case ${LC_ALL:\-${LC_CTYPE:\-${LANG:\-}}} in
6652 *[Uu][Tt][Ff]8*\*(Ba*[Uu][Tt][Ff]\-8*) set \-U ;;
6657 In near future, (Unicode) locale tracking will be implemented though.
6659 See also the FAQ below.
6661 Suspending (using \*(haZ) pipelines like the one below will only suspend
6662 the currently running part of the pipeline; in this example,
6664 is immediately printed on suspension (but not later after an
6666 .Bd -literal -offset indent
6667 $ /bin/sleep 666 && echo fubar
6670 The truncation process involved when changing
6672 does not free old history entries (leaks memory) and leaks
6673 old entries into the new history if their line numbers are
6674 not overwritten by same-number entries from the persistent
6675 history file; truncating the on-disc file to
6677 lines has always been broken and prone to history file corruption
6678 when multiple shells are accessing the file; the rollover process
6679 for the in-memory portion of the history is slow, should use
6682 This document attempts to describe
6685 .\" with vendor patches from insert-your-name-here,
6686 compiled without any options impacting functionality, such as
6690 which, on some systems only, enables
6691 .Ic set Fl o Ic posix
6694 automatically (whose behaviour differs across targets),
6695 for an operating environment supporting all of its advanced needs.
6697 Please report bugs in
6700 .Aq Mt miros\-mksh@mirbsd.org
6706 .Pa irc.freenode.net
6707 .Pq Port 6697 SSL, 6667 unencrypted ,
6709 .Pa https://launchpad.net/mksh
6710 .Sh FREQUENTLY ASKED QUESTIONS
6711 This FAQ attempts to document some of the questions users of
6713 or readers of this manual page may encounter.
6714 .Ss I'm an Android user, so what's mksh?
6718 shell / command interpreter, similar to
6722 which has been included with
6723 .Tn Android Open Source Project
6725 Basically, it's a program that runs in a terminal (console window),
6726 takes user input and runs commands or scripts, which it can also
6727 be asked to do by other programs, even in the background.
6728 Any privilege pop-ups you might be encountering are thus not
6730 issues but questions by some other program utilising it.
6731 .Ss "I'm an OS/2 user, what do I need to know?"
6732 Unlike the native command prompt, the current working directory is,
6733 for security reasons common on Unix systems which the shell is designed for,
6734 not in the search path at all; if you really need this, run the command
6735 .Li PATH=.$PATHSEP$PATH
6736 or add that to a suitable initialisation file.
6738 There are two different newline modes for mksh-os2: standard (Unix) mode,
6739 in which only LF (0A hex) is supported as line separator, and "textmode",
6740 which also accepts ASCII newlines (CR+LF), like most other tools on OS/2,
6741 but creating an incompatibility with standard
6743 If you compiled mksh from source, you will get the standard Unix mode unless
6745 is added during compilation; you will most likely have gotten this shell
6746 through komh's port on Hobbes, or from his OS/2 Factory on eComStation
6747 Korea, which uses "textmode", though.
6748 Most OS/2 users will want to use "textmode" unless they need absolute
6749 compatibility with Unix
6751 .Ss "How do I start mksh on a specific terminal?"
6753 .Dl mksh \-T/dev/tty2
6755 However, if you want for it to return (e.g. for an embedded
6756 system rescue shell), use this on your real console device instead:
6757 .Dl mksh \-T!/dev/ttyACM0
6760 can also daemonise (send to the background):
6761 .Dl mksh \-T\- \-c \*(aqexec cdio lock\*(aq
6763 Run the shell in POSIX mode (and possibly
6768 .Ss "My prompt from <some other shell> does not work!"
6769 Contact us on the mailing list or on IRC, we'll convert it for you.
6770 .Ss "Something is going wrong with my while...read loop"
6771 Most likely, you've encountered the problem in which the shell runs
6772 all parts of a pipeline as subshell.
6773 The inner loop will be executed in a subshell and variable changes
6774 cannot be propagated if run in a pipeline:
6775 .Bd -literal -offset indent
6776 bar \*(Ba baz \*(Ba while read foo; do ...; done
6781 in the inner loop will only exit the subshell and not the original shell.
6782 Likewise, if the code is inside a function,
6784 in the inner loop will only exit the subshell and won't terminate the function.
6786 Use co-processes instead:
6787 .Bd -literal -offset indent
6788 bar \*(Ba baz \*(Ba&
6789 while read \-p foo; do ...; done
6790 exec 3\*(Gt&p; exec 3\*(Gt&\-
6795 is run in a loop such as
6796 .Ic while read foo; do ...; done
6797 then leading whitespace will be removed (IFS) and backslashes processed.
6798 You might want to use
6799 .Ic while IFS= read \-r foo; do ...; done
6801 Similarly, when using the
6805 option might be prudent
6806 .Pq Dq Li read \-raN\-1 arr \*(Ltfile ;
6807 the same applies for NUL-terminated lines:
6808 .Bd -literal -offset indent
6809 find . \-type f \-print0 \*(Ba& \e
6810 while IFS= read \-d \*(aq\*(aq \-pr filename; do
6811 print \-r \-\- "found \*(Lt${filename#./}\*(Gt"
6815 .Ss "What differences in function-local scopes are there?"
6817 has a different scope model from
6820 which leads to subtle differences in semantics for identical builtins.
6821 This can cause issues with a
6823 to suddenly point to a local variable by accident.
6827 allows unsetting local variables; in
6829 doing so in a function allows back access to the global variable
6830 (actually the one in the next scope up) with the same name.
6831 The following code, when run before the function definitions, changes
6834 to behave like other shells (the alias can be removed after the definitions):
6835 .Bd -literal -offset indent
6836 case ${KSH_VERSION:\-} in
6837 *MIRBSD\ KSH*\*(Ba*LEGACY\ KSH*)
6838 function unset_compat {
6839 \e\ebuiltin typeset unset_compat_x
6841 for unset_compat_x in "$@"; do
6842 eval "\e\e\e\ebuiltin unset $unset_compat_x[*]"
6845 \e\ebuiltin alias unset=unset_compat
6850 When a local variable is created (e.g. using
6854 .Ic \e\ebuiltin typeset )
6855 it does not, like in other shells, inherit the value from the global
6856 (next scope up) variable with the same name; it is rather created
6857 without any value (unset but defined).
6858 .Ss "I get an error in this regex comparison"
6859 Use extglobs instead of regexes:
6860 .Dl "[[ foo =~ (foo\*(Babar).*baz ]] # becomes"
6861 .Dl "[[ foo = *@(foo\*(Babar)*baz* ]] # instead"
6862 .Ss "Are there any extensions to avoid?"
6867 .Pq and Dq Li \*(Ba&
6868 to redirect both stdout and stderr in one go, but this breaks POSIX
6869 and Korn Shell syntax; use POSIX redirections instead:
6870 .Dl "foo \*(Ba& bar \*(Ba& baz &\*(Gtlog # GNU bash"
6871 .Dl "foo 2\*(Gt&1 \*(Ba bar 2\*(Gt&1 \*(Ba baz \*(Gtlog 2\*(Gt&1 # POSIX"
6872 .Ss "\*(haL (Ctrl-L) does not clear the screen"
6873 Use \*(ha[\*(haL (Escape+Ctrl-L) or rebind it:
6874 .Dl bind \*(aq\*(haL=clear-screen\*(aq
6875 .Ss "\*(haU (Ctrl-U) clears the entire line"
6876 If it should only delete the line up to the cursor, use:
6877 .Dl bind \-m \*(haU=\*(aq\*(ha[0\*(haK\*(aq
6878 .Ss "Cursor Up behaves differently from zsh"
6879 Some shells make Cursor Up search in the history only for
6880 commands starting with what was already entered.
6882 separates the shortcuts: Cursor Up goes up one command
6883 and PgUp searches the history as described above.