1 .\" $MirOS: src/bin/mksh/mksh.1,v 1.275 2011/10/07 19:51:29 tg Exp $
2 .\" $OpenBSD: ksh.1,v 1.141 2011/09/03 22:59:08 jmc Exp $
4 .\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
6 .\" Thorsten Glaser <tg@mirbsd.org>
8 .\" Provided that these terms and disclaimer and all copyright notices
9 .\" are retained or reproduced in an accompanying document, permission
10 .\" is granted to deal in this work without restriction, including un‐
11 .\" limited rights to use, publicly perform, distribute, sell, modify,
12 .\" merge, give away, or sublicence.
14 .\" This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
15 .\" the utmost extent permitted by applicable law, neither express nor
16 .\" implied; without malicious intent or gross negligence. In no event
17 .\" may a licensor, author or contributor be held liable for indirect,
18 .\" direct, other damage, loss, or other issues arising in any way out
19 .\" of dealing in the work, even if advised of the possibility of such
20 .\" damage or existence of a defect, except proven that it results out
21 .\" of said person’s immediate fault when using the work as intended.
23 .\" Try to make GNU groff and AT&T nroff more compatible
24 .\" * ` generates ‘ in gnroff, so use \`
25 .\" * ' generates ’ in gnroff, \' generates ´, so use \*(aq
26 .\" * - generates ‐ in gnroff, \- generates −, so .tr it to -
27 .\" thus use - for hyphens and \- for minus signs and option dashes
28 .\" * ~ is size-reduced and placed atop in groff, so use \*(TI
29 .\" * ^ is size-reduced and placed atop in groff, so use \*(ha
30 .\" * \(en does not work in nroff, so use \*(en
31 .\" The section after the "doc" macropackage has been loaded contains
32 .\" additional code to convene between the UCB mdoc macropackage (and
33 .\" its variant as BSD mdoc in groff) and the GNU mdoc macropackage.
36 . if
\ 1\*[.T]
\ 1ascii
\ 1 .tr \-\N'45'
37 . if
\ 1\*[.T]
\ 1latin1
\ 1 .tr \-\N'45'
38 . if
\ 1\*[.T]
\ 1utf8
\ 1 .tr \-\N'45'
45 . if
\ 1\*[.T]
\ 1utf8
\ 1 .ds sL `
46 . if
\ 1\*[.T]
\ 1ps
\ 1 .ds sL `
47 . if
\ 1\*[.T]
\ 1utf8
\ 1 .ds sR '
48 . if
\ 1\*[.T]
\ 1ps
\ 1 .ds sR '
61 .\" Implement .Dd with the Mdocdate RCS keyword
65 .ie
\a\\$1
\a$Mdocdate:
\a \{\
68 .el .xD \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8
71 .\" .Dd must come before definition of .Mx, because when called
72 .\" with -mandoc, it might implement .Mx itself, but we want to
73 .\" use our own definition. And .Dd must come *first*, always.
75 .Dd $Mdocdate: October 7 2011 $
77 .\" Check which macro package we use
80 . ie d volume-ds-1 .ds tT gnu
85 .\" Implement .Mx (MirBSD)
91 . nr curr-size \n[.ps]
92 . ds str-Mx \f[\n[curr-font]]\s[\n[curr-size]u]
93 . ds str-Mx1 \*[Tn-font-size]\%MirOS\*[str-Mx]
99 . if (\n[arg-limit] > \n[arg-ptr]) \{\
101 . ie (\n[type\n[arg-ptr]] == 2) \
102 . as str-Mx1 \~\*[arg\n[arg-ptr]]
106 . ds arg\n[arg-ptr] "\*[str-Mx1]
107 . nr type\n[arg-ptr] 2
108 . ds space\n[arg-ptr] "\*[space]
109 . nr num-args (\n[arg-limit] - \n[arg-ptr])
110 . nr arg-limit \n[arg-ptr]
117 . ds tN \*[Tn-font-size]
123 . ds aa \&\f\\n(cF\s\\n(cZ
125 . ie \\n(.$==0 \&MirOS\\*(aa
126 . el .aV \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
128 . if \\n(aC>\\n(aP \{\
130 . ie \\n(C\\n(aP==2 \{\
131 . as b1 \&MirOS\ #\&\\*(A\\n(aP\\*(aa
132 . ie \\n(aC>\\n(aP \{\
139 . as b1 \&MirOS\\*(aa
151 .Nd MirBSD Korn shell
155 .Op Fl +abCefhiklmnprUuvXx
156 .Op Fl T Ar /dev/ttyCn | \-
159 .Fl c Ar string \*(Ba
169 is a command interpreter intended for both interactive and shell
171 Its command language is a superset of the
173 shell language and largely compatible to the original Korn shell.
175 Most builtins can be called directly, for example if a link points from its
176 name to the shell; not all make sense, have been tested or work at all though.
178 The options are as follows:
179 .Bl -tag -width XcXstring
182 will execute the command(s) contained in
189 option is used or if both standard input and standard error are attached
192 An interactive shell has job control enabled, ignores the
197 signals, and prints prompts before reading input (see the
202 It also processes the
207 For non-interactive shells, the
209 option is on by default (see the
214 If the basename the shell is called with (i.e. argv[0])
217 or if this option is used,
218 the shell is assumed to be a login shell; see
225 if this option is used
226 or if the real user ID or group ID does not match the
227 effective user ID or group ID (see
231 Clearing the privileged option causes the shell to set
232 its effective user ID (group ID) to its real user ID (group ID).
233 For further implications, see
241 The following restrictions come into effect after the shell processes any
258 parameters cannot be changed.
260 Command names can't be specified with absolute or relative paths.
264 option of the built-in command
268 Redirections that create files can't be used (i.e.\&
275 The shell reads commands from standard input; all non-option arguments
276 are positional parameters.
286 is a dash, detach from controlling terminal (daemonise) instead.
289 In addition to the above, the options described in the
291 built-in command can also be used on the command line:
293 .Op Fl +abCefhkmnuvXx
296 can be used for single letter or long options, respectively.
302 option is specified, the first non-option argument specifies the name
303 of a file the shell reads commands from.
304 If there are no non-option
305 arguments, the shell reads commands from the standard input.
306 The name of the shell (i.e. the contents of $0)
307 is determined as follows: if the
309 option is used and there is a non-option argument, it is used as the name;
310 if commands are being read from a file, the file is used as the name;
311 otherwise, the basename the shell was called with (i.e. argv[0]) is used.
313 The exit status of the shell is 127 if the command file specified on the
314 command line could not be opened, or non-zero if a fatal syntax error
315 occurred during the execution of a script.
316 In the absence of fatal errors,
317 the exit status is that of the last command executed, or zero, if no
320 For the actual location of these files, see
322 A login shell processes the system profile first.
323 A privileged shell then processes the suid profile.
324 A non-privileged login shell processes the user profile next.
325 A non-privileged interactive shell checks the value of the
327 parameter after subjecting it to parameter, command, arithmetic and tilde
329 substitution; if unset or empty, the user mkshrc profile is processed;
330 otherwise, if a file whose name is the substitution result exists,
331 it is processed; non-existence is silently ignored.
333 The shell begins parsing its input by removing any backslash-newline
334 combinations, then breaking it into
336 Words (which are sequences of characters) are delimited by unquoted whitespace
337 characters (space, tab, and newline) or meta-characters
348 Aside from delimiting words, spaces and tabs are ignored, while newlines
349 usually delimit commands.
350 The meta-characters are used in building the following
355 .Ql \*(Lt\*(Lt\*(Lt ,
360 etc. are used to specify redirections (see
361 .Sx Input/output redirection
364 is used to create pipelines;
366 is used to create co-processes (see
370 is used to separate commands;
372 is used to create asynchronous pipelines;
376 are used to specify conditional execution;
385 is used in arithmetic expressions;
388 is used to create subshells.
390 Whitespace and meta-characters can be quoted individually using a backslash
392 or in groups using double
397 Note that the following characters are also treated specially by the
398 shell and must be quoted if they are to represent themselves:
412 The first three of these are the above mentioned quoting characters (see
416 if used at the beginning of a word, introduces a comment \*(en everything after
419 up to the nearest newline is ignored;
421 is used to introduce parameter, command, and arithmetic substitutions (see
425 introduces an old-style command substitution (see
429 begins a directory expansion (see
445 are used in file name generation (see
446 .Sx File name patterns
449 As words and tokens are parsed, the shell builds commands, of which there
451 .Em simple-commands ,
452 typically programmes that are executed, and
453 .Em compound-commands ,
458 statements, grouping constructs, and function definitions.
460 A simple-command consists of some combination of parameter assignments
464 input/output redirections (see
465 .Sx Input/output redirections
467 and command words; the only restriction is that parameter assignments come
468 before any command words.
469 The command words, if any, define the command
470 that is to be executed and its arguments.
471 The command may be a shell built-in command, a function,
472 or an external command
473 (i.e. a separate executable file that is located using the
476 .Sx Command execution
478 Note that all command constructs have an exit status: for external commands,
479 this is related to the status returned by
481 (if the command could not be found, the exit status is 127; if it could not
482 be executed, the exit status is 126); the exit status of other command
483 constructs (built-in commands, functions, compound-commands, pipelines, lists,
484 etc.) are all well-defined and are described where the construct is
486 The exit status of a command consisting only of parameter
487 assignments is that of the last command substitution performed during the
488 parameter assignment or 0 if there were no command substitutions.
490 Commands can be chained together using the
492 token to form pipelines, in which the standard output of each command but the
495 to the standard input of the following command.
496 The exit status of a pipeline is that of its last command.
497 All commands of a pipeline are executed in separate subshells;
498 this is allowed by POSIX but differs from both variants of
501 where all but the last command were executed in subshells; see the
503 builtin's description for implications and workarounds.
504 A pipeline may be prefixed by the
506 reserved word which causes the exit status of the pipeline to be logically
507 complemented: if the original status was 0, the complemented status will be 1;
508 if the original status was not 0, the complemented status will be 0.
511 of commands can be created by separating pipelines by any of the following
519 The first two are for conditional execution:
520 .Dq Ar cmd1 No && Ar cmd2
523 only if the exit status of
527 is the opposite \*(en
529 is executed only if the exit status of
535 have equal precedence which is higher than that of
540 which also have equal precedence.
546 .Qq left-associative .
547 For example, both of these commands will print only
549 .Bd -literal -offset indent
550 $ false && echo foo \*(Ba\*(Ba echo bar
551 $ true \*(Ba\*(Ba echo foo && echo bar
556 token causes the preceding command to be executed asynchronously; that is,
557 the shell starts the command but does not wait for it to complete (the shell
558 does keep track of the status of asynchronous commands; see
561 When an asynchronous command is started when job control is disabled
562 (i.e. in most scripts), the command is started with signals
566 ignored and with input redirected from
568 (however, redirections specified in the asynchronous command have precedence).
571 operator starts a co-process which is a special kind of asynchronous process
575 Note that a command must follow the
579 operators, while it need not follow
584 The exit status of a list is that of the last command executed, with the
585 exception of asynchronous lists, for which the exit status is 0.
587 Compound commands are created using the following reserved words.
589 are only recognised if they are unquoted and if they are used as the first
590 word of a command (i.e. they can't be preceded by parameter assignments or
592 .Bd -literal -offset indent
593 case else function then ! (
594 do esac if time [[ ((
596 elif for select while }
599 In the following compound command descriptions, command lists (denoted as
601 that are followed by reserved words must end with a semicolon, a newline, or
602 a (syntactically correct) reserved word.
603 For example, the following are all valid:
604 .Bd -literal -offset indent
605 $ { echo foo; echo bar; }
606 $ { echo foo; echo bar\*(Ltnewline\*(Gt}
607 $ { { echo foo; echo bar; } }
612 .Dl $ { echo foo; echo bar }
618 There is no implicit way to pass environment changes from a
619 subshell back to its parent.
623 is executed, but not in a subshell.
628 are reserved words, not meta-characters.
629 .It Xo case Ar word No in
635 .Op ;; \*(Ba ;&\& \*(Ba ;\*(Ba\ \&
640 statement attempts to match
646 associated with the first successfully matched pattern is executed.
649 statements are the same as those used for file name patterns except that the
650 restrictions regarding
655 Note that any unquoted space before and after a pattern is
656 stripped; any space within a pattern must be quoted.
657 Both the word and the
658 patterns are subject to parameter, command, and arithmetic substitution, as
659 well as tilde substitution.
661 For historical reasons, open and close braces may be used instead of
666 .Ic case $foo { *) echo bar;; } .
668 The list terminators are:
671 Terminate after the list.
673 Fall through into the next list.
675 Evaluate the remaining pattern-list tuples.
680 statement is that of the executed
684 is executed, the exit status is zero.
686 .Oo in Ar word No ... Oc ;
687 .No do Ar list ; No done
691 in the specified word list, the parameter
693 is set to the word and
698 is not used to specify a word list, the positional parameters
701 For historical reasons, open and close braces may be used instead of
706 .Ic for i; { echo $i; } .
709 statement is the last exit status of
713 is never executed, the exit status is zero.
717 .No then Ar list ; Oc
719 .Oo else Ar list ; Oc
722 If the exit status of the first
726 is executed; otherwise, the
730 if any, is executed with similar consequences.
731 If all the lists following the
735 fail (i.e. exit with non-zero status), the
740 The exit status of an
742 statement is that of non-conditional
744 that is executed; if no non-conditional
746 is executed, the exit status is zero.
747 .It Xo select Ar name
748 .Oo in Ar word No ... Oc ;
749 .No do Ar list ; No done
753 statement provides an automatic method of presenting the user with a menu and
755 An enumerated list of the specified
757 is printed on standard error, followed by a prompt
762 A number corresponding to one of the enumerated words is then read from
765 is set to the selected word (or unset if the selection is not valid),
767 is set to what was read (leading/trailing space is stripped), and
770 If a blank line (i.e. zero or more
772 octets) is entered, the menu is reprinted without executing
777 completes, the enumerated list is printed if
781 the prompt is printed, and so on.
782 This process continues until an end-of-file
783 is read, an interrupt is received, or a
785 statement is executed inside the loop.
788 is omitted, the positional parameters are used
790 For historical reasons, open and close braces may be used instead of
795 .Ic select i; { echo $i; } .
798 statement is zero if a
800 statement is used to exit the loop, non-zero otherwise.
801 .It Xo until Ar list ;
807 except that the body is executed only while the exit status of the first
810 .It Xo while Ar list ;
816 is a pre-checked loop.
817 Its body is executed as often as the exit status of the first
822 statement is the last exit status of the
824 in the body of the loop; if the body is not executed, the exit status is zero.
825 .It Xo function Ar name
833 Note that redirections specified after a function definition are
834 performed whenever the function is executed, not when the function definition
836 .It Ar name Ns \&() Ar command
842 Whitespace (space or tab) after
844 will be ignored most of the time.
845 .It Xo function Ar name Ns \&()
854 .It Xo Ic time Op Fl p
858 .Sx Command execution
859 section describes the
862 .It \&(( Ar expression No ))
863 The arithmetic expression
865 is evaluated; equivalent to
868 .Sx Arithmetic expressions
872 .It Bq Bq Ar \ \&expression\ \&
877 commands (described later), with the following exceptions:
880 Field splitting and file name generation are not performed on arguments.
888 operators are replaced with
900 Parameter, command, and arithmetic substitutions are performed as expressions
901 are evaluated and lazy expression evaluation is used for the
906 This means that in the following statement,
908 is evaluated if and only if the file
910 exists and is readable:
911 .Bd -literal -offset indent
912 $ [[ \-r foo && $(\*(Ltfoo) = b*r ]]
915 The second operand of the
919 expressions are patterns (e.g. the comparison
920 .Ic \&[[ foobar = f*r ]]
922 This even works indirectly:
923 .Bd -literal -offset indent
924 $ bar=foobar; baz=\*(aqf*r\*(aq
925 $ [[ $bar = $baz ]]; echo $?
926 $ [[ $bar = "$baz" ]]; echo $?
929 Perhaps surprisingly, the first comparison succeeds,
930 whereas the second doesn't.
934 Quoting is used to prevent the shell from treating characters or words
936 There are three methods of quoting.
939 quotes the following character, unless it is at the end of a line, in which
942 and the newline are stripped.
943 Second, a single quote
945 quotes everything up to the next single quote (this may span lines).
946 Third, a double quote
948 quotes all characters, except
953 up to the next unquoted double quote.
957 inside double quotes have their usual meaning (i.e. parameter, command, or
958 arithmetic substitution) except no field splitting is carried out on the
959 results of double-quoted substitutions.
962 inside a double-quoted string is followed by
968 it is replaced by the second character; if it is followed by a newline, both
971 and the newline are stripped; otherwise, both the
973 and the character following are unchanged.
975 If a single-quoted string is preceded by an unquoted
977 C style backslash expansion (see below) is applied (even single quote
978 characters inside can be escaped and do not terminate the string then);
979 the expanded result is treated as any other single-quoted string.
980 If a double-quoted string is preceded by an unquoted
982 the latter is ignored.
983 .Ss Backslash expansion
984 In places where backslashes are expanded, certain C and
989 style escapes are translated.
1006 means a hexadecimal digit, of thich there may be none up to four or eight;
1007 these escapes translate a Unicode codepoint to UTF-8.
1012 expand to the escape character.
1021 are explicitly excluded;
1022 octal sequences must have the none up to three octal digits
1024 prefixed with the digit zero
1026 hexadecimal sequences
1028 are limited to none up to two hexadecimal digits
1030 both octal and hexadecimal sequences convert to raw octets;
1032 where # is none of the above, translates to \e# (backslashes are retained).
1034 Backslash expansion in the C style mode slightly differs: octal sequences
1036 must have no digit zero prefixing the one up to three octal digits
1038 and yield raw octets; hexadecimal sequences
1040 greedily eat up as many hexadecimal digits
1042 as they can and terminate with the first non-hexadecimal digit;
1043 these translate a Unicode codepoint to UTF-8.
1048 is any octet, translates to Ctrl-# (which basically means,
1050 becomes DEL, everything else is bitwise ANDed with 0x1F).
1053 where # is none of the above, translates to # (has the backslash trimmed),
1054 even if it is a newline.
1056 There are two types of aliases: normal command aliases and tracked aliases.
1057 Command aliases are normally used as a short hand for a long or often used
1059 The shell expands command aliases (i.e. substitutes the alias name
1060 for its value) when it reads the first word of a command.
1061 An expanded alias is re-processed to check for more aliases.
1062 If a command alias ends in a
1063 space or tab, the following word is also checked for alias expansion.
1064 The alias expansion process stops when a word that is not an alias is found,
1065 when a quoted word is found, or when an alias word that is currently being
1068 The following command aliases are defined automatically by the shell:
1069 .Bd -literal -offset indent
1070 autoload=\*(aqtypeset \-fu\*(aq
1071 functions=\*(aqtypeset \-f\*(aq
1072 hash=\*(aqalias \-t\*(aq
1073 history=\*(aqfc \-l\*(aq
1074 integer=\*(aqtypeset \-i\*(aq
1075 local=\*(aqtypeset\*(aq
1076 login=\*(aqexec login\*(aq
1077 nameref=\*(aqtypeset \-n\*(aq
1078 nohup=\*(aqnohup \*(aq
1079 r=\*(aqfc \-e \-\*(aq
1080 stop=\*(aqkill \-STOP\*(aq
1081 suspend=\*(aqkill \-STOP $$\*(aq
1082 type=\*(aqwhence \-v\*(aq
1085 Tracked aliases allow the shell to remember where it found a particular
1087 The first time the shell does a path search for a command that is
1088 marked as a tracked alias, it saves the full path of the command.
1090 time the command is executed, the shell checks the saved path to see that it
1091 is still valid, and if so, avoids repeating the path search.
1092 Tracked aliases can be listed and created using
1094 Note that changing the
1096 parameter clears the saved paths for all tracked aliases.
1099 option is set (i.e.\&
1100 .Ic set \-o Ic trackall
1103 the shell tracks all commands.
1104 This option is set automatically for non-interactive shells.
1105 For interactive shells, only the following commands are
1106 automatically tracked:
1126 The first step the shell takes in executing a simple-command is to perform
1127 substitutions on the words of the command.
1128 There are three kinds of
1129 substitution: parameter, command, and arithmetic.
1130 Parameter substitutions,
1131 which are described in detail in the next section, take the form
1134 .Pf ${ Ns Ar ... Ns } ;
1135 command substitutions take the form
1136 .Pf $( Ns Ar command Ns \&)
1138 .Pf \` Ns Ar command Ns \` ;
1139 and arithmetic substitutions take the form
1140 .Pf $(( Ns Ar expression Ns )) .
1142 If a substitution appears outside of double quotes, the results of the
1143 substitution are generally subject to word or field splitting according to
1144 the current value of the
1149 parameter specifies a list of octets which are used to break a string up
1150 into several words; any octets from the set space, tab, and newline that
1154 .Dq IFS whitespace .
1155 Sequences of one or more
1157 whitespace octets, in combination with zero or one
1159 whitespace octets, delimit a field.
1160 As a special case, leading and trailing
1162 whitespace and trailing
1164 non-whitespace are stripped (i.e. no leading or trailing empty field
1165 is created by it); leading
1167 whitespace does create an empty field.
1172 .Dq \*(Ltspace\*(Gt: ,
1174 .Dq \*(Ltspace\*(GtA\*(Ltspace\*(Gt:\*(Ltspace\*(Gt\*(Ltspace\*(GtB::D ,
1175 the substitution for $VAR results in four fields:
1184 parameter is set to the
1186 string, no field splitting is done; if the parameter is unset, the default
1187 value of space, tab, and newline is used.
1189 Also, note that the field splitting applies only to the immediate result of
1191 Using the previous example, the substitution for $VAR:E
1192 results in the fields:
1205 This behavior is POSIX compliant, but incompatible with some other shell
1206 implementations which do field splitting on the word which contained the
1209 as a general whitespace delimiter.
1211 The results of substitution are, unless otherwise specified, also subject to
1212 brace expansion and file name expansion (see the relevant sections below).
1214 A command substitution is replaced by the output generated by the specified
1215 command which is run in a subshell.
1217 .Pf $( Ns Ar command Ns \&)
1218 substitutions, normal quoting rules are used when
1220 is parsed; however, for the deprecated
1221 .Pf \` Ns Ar command Ns \`
1231 followed by any other character is unchanged).
1232 As a special case in command substitutions, a command of the form
1234 is interpreted to mean substitute the contents of
1238 has the same effect as
1241 Note that some shells do not use a recursive parser for command substitutions,
1242 leading to failure for certain constructs; to be portable, use as workaround
1243 .Ql x=$(cat) \*(Lt\*(Lt"EOF"
1244 (or the newline-keeping
1245 .Ql x=\*(Lt\*(Lt"EOF"
1246 extension) instead to merely slurp the string.
1248 recommends to use case statements of the form
1249 .Ql "x=$(case $foo in (bar) echo $bar ;; (*) echo $baz ;; esac)"
1250 instead, which would work but not serve as example for this portability issue.
1251 .Bd -literal -offset indent
1252 x=$(case $foo in bar) echo $bar ;; *) echo $baz ;; esac)
1253 # above fails to parse on old shells; below is the workaround
1254 x=$(eval $(cat)) \*(Lt\*(Lt"EOF"
1255 case $foo in bar) echo $bar ;; *) echo $baz ;; esac
1259 Arithmetic substitutions are replaced by the value of the specified expression.
1260 For example, the command
1261 .Ic print $((2+3*4))
1264 .Sx Arithmetic expressions
1265 for a description of an expression.
1267 Parameters are shell variables; they can be assigned values and their values
1268 can be accessed using a parameter substitution.
1269 A parameter name is either one
1270 of the special single punctuation or digit character parameters described
1271 below, or a letter followed by zero or more letters or digits
1276 The latter form can be treated as arrays by appending an array index of the
1281 is an arithmetic expression.
1284 are limited to the range 0 through 4294967295, inclusive.
1285 That is, they are a 32-bit unsigned integer.
1287 Parameter substitutions take the form
1289 .Pf ${ Ns Ar name Ns } ,
1292 .Pf ${ Ar name Oo Ar expr Oc }
1296 is a parameter name.
1297 Substitution of all array elements with
1298 .Pf ${ Ns Ar name Ns \&[*]}
1300 .Pf ${ Ns Ar name Ns \&[@]}
1301 works equivalent to $* and $@ for positional parameters.
1302 If substitution is performed on a parameter
1303 (or an array parameter element)
1304 that is not set, a null string is substituted unless the
1308 .Ic set Fl o Ic nounset
1312 is set, in which case an error occurs.
1314 Parameters can be assigned values in a number of ways.
1315 First, the shell implicitly sets some parameters like
1320 this is the only way the special single character parameters are set.
1321 Second, parameters are imported from the shell's environment at startup.
1322 Third, parameters can be assigned values on the command line: for example,
1328 multiple parameter assignments can be given on a single command line and they
1329 can be followed by a simple-command, in which case the assignments are in
1330 effect only for the duration of the command (such assignments are also
1331 exported; see below for the implications of this).
1332 Note that both the parameter name and the
1334 must be unquoted for the shell to recognise a parameter assignment.
1337 is also recognised; the old and new values are immediately concatenated.
1338 The fourth way of setting a parameter is with the
1344 commands; see their descriptions in the
1345 .Sx Command execution
1351 loops set parameters as well as the
1357 Lastly, parameters can be assigned values using assignment operators
1358 inside arithmetic expressions (see
1359 .Sx Arithmetic expressions
1362 .Pf ${ Ar name No = Ar value No }
1364 form of the parameter substitution (see below).
1366 Parameters with the export attribute (set using the
1370 commands, or by parameter assignments followed by simple commands) are put in
1371 the environment (see
1373 of commands run by the shell as
1374 .Ar name Ns = Ns Ar value
1376 The order in which parameters appear in the environment of a command is
1378 When the shell starts up, it extracts parameters and their values
1379 from its environment and automatically sets the export attribute for those
1382 Modifiers can be applied to the
1383 .Pf ${ Ns Ar name Ns }
1384 form of parameter substitution:
1387 .It ${ Ar name No :\- Ar word No }
1393 it is substituted; otherwise,
1397 .It ${ Ar name No :+ Ar word No }
1404 is substituted; otherwise, nothing is substituted.
1406 .It ${ Ar name No := Ar word No }
1412 it is substituted; otherwise, it is assigned
1414 and the resulting value of
1418 .It ${ Ar name No :? Ar word No }
1424 it is substituted; otherwise,
1426 is printed on standard error (preceded by
1428 and an error occurs (normally causing termination of a shell script, function,
1429 or script sourced using the
1434 is omitted, the string
1435 .Dq parameter null or not set
1439 is a variable which expands to the null string, the
1440 error message is also printed.
1443 Note that, for all of the above,
1445 is actually considered quoted, and special parsing rules apply.
1446 The parsing rules also differ on whether the expression is double-quoted:
1448 then uses double-quoting rules, except for the double quote itself
1450 and the closing brace, which, if backslash escaped, gets quote removal applied.
1452 In the above modifiers, the
1454 can be omitted, in which case the conditions only depend on
1456 being set (as opposed to set and not
1460 is needed, parameter, command, arithmetic, and tilde substitution are performed
1463 is not needed, it is not evaluated.
1465 The following forms of parameter substitution can also be used (if
1467 is an array, its element #0 will be substituted in a scalar context):
1469 .Bl -tag -width Ds -compact
1470 .It Pf ${# Ns Ar name Ns \&}
1471 The number of positional parameters if
1476 or not specified; otherwise the length
1478 of the string value of parameter
1481 .It Pf ${# Ns Ar name Ns \&[*]}
1482 .It Pf ${# Ns Ar name Ns \&[@]}
1483 The number of elements in the array
1486 .It Pf ${% Ns Ar name Ns \&}
1488 .Pq in screen columns
1489 of the string value of parameter
1492 .Pf ${ Ns Ar name Ns }
1493 contains a control character.
1495 .It Pf ${! Ns Ar name Ns }
1496 The name of the variable referred to by
1502 is a name reference (bound variable), created by the
1504 command (which is an alias for
1505 .Ic typeset Fl n ) .
1507 .It Pf ${! Ns Ar name Ns \&[*]}
1508 .It Pf ${! Ns Ar name Ns \&[@]}
1509 The names of indices (keys) in the array
1515 .Pf # Ar pattern No }
1519 .Pf ## Ar pattern No }
1524 matches the beginning of the value of parameter
1526 the matched text is deleted from the result of substitution.
1529 results in the shortest match, and two
1530 of them result in the longest match.
1531 Cannot be applied to a vector
1532 .Pq ${*} or ${@} or ${array[*]} or ${array[@]} .
1537 .Pf % Ar pattern No }
1541 .Pf %% Ar pattern No }
1544 Like ${..#..} substitution, but it deletes from the end of the value.
1545 Cannot be applied to a vector.
1550 .Pf / Ar pattern / Ar string No }
1554 .Pf // Ar pattern / Ar string No }
1557 Like ${..#..} substitution, but it replaces the longest match of
1559 anchored anywhere in the value, with
1565 it is anchored at the beginning of the value; if it begins with
1567 it is anchored at the end.
1570 replaces the first occurence of the search
1572 and two of them replace all occurences.
1577 is replaced by the empty string, i.e. deleted.
1578 Cannot be applied to a vector.
1579 Inefficiently implemented.
1583 .Pf ${ Ar name : Ns Ar pos
1584 .Pf : Ns Ar len Ns }
1591 starting at position
1601 is negative, counting starts at the end of the string; if it
1602 is omitted, it defaults to 0.
1605 is omitted or greater than the length of the remaining string,
1606 all of it is substituted.
1611 are evaluated as arithmetic expressions.
1614 must start with a space, opening parenthesis or digit to be recognised.
1615 Cannot be applied to a vector.
1617 .It Pf ${ Ns Ar name Ns @#}
1618 The internal hash of the expansion of
1620 At the moment, this is NZAT (a never-zero 32-bit hash based on
1621 Bob Jenkins' one-at-a-time hash), but this is not set.
1622 This is the hash the shell uses internally for its associative arrays.
1627 may need extended globbing pattern
1630 .Pq \&\*(aq...\&\*(aq
1633 quote escaping unless
1637 The following special parameters are implicitly set by the shell and cannot be
1638 set directly using assignments:
1639 .Bl -tag -width "1 .. 9"
1641 Process ID of the last background process started.
1642 If no background processes have been started, the parameter is not set.
1644 The number of positional parameters ($1, $2, etc.).
1646 The PID of the shell, or the PID of the original shell if it is a subshell.
1649 use this mechanism for generating temporary file names; see
1653 The concatenation of the current single letter options (see the
1655 command below for a list of options).
1657 The exit status of the last non-asynchronous command executed.
1658 If the last command was killed by a signal,
1660 is set to 128 plus the signal number.
1662 The name of the shell, determined as follows:
1663 the first argument to
1665 if it was invoked with the
1667 option and arguments were given; otherwise the
1669 argument, if it was supplied;
1670 or else the basename the shell was invoked with (i.e.\&
1673 is also set to the name of the current script or
1674 the name of the current function, if it was defined with the
1676 keyword (i.e. a Korn shell style function).
1678 The first nine positional parameters that were supplied to the shell, function,
1679 or script sourced using the
1682 Further positional parameters may be accessed using
1683 .Pf ${ Ar number Ns } .
1685 All positional parameters (except 0), i.e. $1, $2, $3, ...
1688 outside of double quotes, parameters are separate words (which are subjected
1689 to word splitting); if used within double quotes, parameters are separated
1690 by the first character of the
1692 parameter (or the empty string if
1699 unless it is used inside double quotes, in which case a separate word is
1700 generated for each positional parameter.
1701 If there are no positional parameters, no word is generated.
1703 can be used to access arguments, verbatim, without losing
1705 arguments or splitting arguments with spaces.
1708 The following parameters are set and/or used by the shell:
1709 .Bl -tag -width "KSH_VERSION"
1712 When an external command is executed by the shell, this parameter is set in the
1713 environment of the new process to the path of the executed command.
1714 In interactive use, this parameter is also set in the parent shell to the last
1715 word of the previous command.
1720 It works the same way as
1722 for those directories not beginning with
1729 is set and does not contain
1731 or contains an empty path, the current directory is not searched.
1734 built-in command will display the resulting directory when a match is found
1735 in any search path other than the empty path.
1737 Set to the number of columns on the terminal or window.
1738 Always set, defaults to 80, unless the
1739 value as reported by
1741 is non-zero and sane enough; similar for
1743 This parameter is used by the interactive line editing modes, and by the
1748 commands to format information columns.
1750 If this parameter is found to be set after any profile files are executed, the
1751 expanded value is used as a shell startup file.
1752 It typically contains function and alias definitions.
1754 Integer value of the shell's
1757 It indicates the reason the last system call failed.
1758 Not yet implemented.
1760 If set, this parameter is assumed to contain the shell that is to be used to
1761 execute commands that
1763 fails to execute and which do not start with a
1767 The editor used by the
1769 command (see below).
1773 but used when an undefined function is executed to locate the file defining the
1775 It is also searched when a command can't be found using
1779 below for more information.
1781 The name of the file used to store command history.
1782 When assigned to, history is loaded from the specified file.
1783 Also, several invocations of the shell will share history if their
1785 parameters all point to the same file.
1790 isn't set, no history file is used.
1791 This is different from
1795 The number of commands normally stored for history.
1798 The default directory for the
1800 command and the value substituted for an unqualified
1806 Internal field separator, used during substitution and by the
1808 command, to split values into distinct arguments; normally set to space, tab,
1815 This parameter is not imported from the environment when the shell is
1818 The effective group id of the shell.
1820 The real group id of the shell.
1822 The real user id of the shell.
1824 The name and version of the shell (read-only).
1825 See also the version commands in
1826 .Sx Emacs editing mode
1831 The line number of the function or shell script that is currently being
1834 Set to the number of lines on the terminal or window.
1835 Always set, defaults to 24.
1837 The previous working directory.
1840 has not successfully changed directories since the shell started, or if the
1841 shell doesn't know where it is.
1845 it contains the argument for a parsed option, if it requires one.
1847 The index of the next argument to be processed when using
1849 Assigning 1 to this parameter causes
1851 to process arguments from the beginning the next time it is invoked.
1853 A colon separated list of directories that are searched when looking for
1854 commands and files sourced using the
1856 command (see below).
1857 An empty string resulting from a leading or trailing
1858 colon, or two adjacent colons, is treated as a
1860 (the current directory).
1862 The process ID of the shell's process group leader.
1864 An array containing the errorlevel (exit status) codes,
1865 one by one, of the last pipeline run in the foreground.
1867 The process ID of the shell's parent.
1869 The primary prompt for interactive shells.
1870 Parameter, command, and arithmetic
1871 substitutions are performed, and
1873 is replaced with the current command number (see the
1878 can be put in the prompt by placing
1883 The default prompt is
1890 is invoked by root and
1894 character, the default value will be used even if
1896 already exists in the environment.
1900 distribution comes with a sample
1902 containing a sophisticated example, but you might like the following one
1903 (note that ${HOSTNAME:=$(hostname)} and the
1904 root-vs-user distinguishing clause are (in this example) executed at
1906 assignment time, while the $USER and $PWD are escaped
1907 and thus will be evaluated each time a prompt is displayed):
1909 PS1=\*(aq${USER:=$(id \-un)}\*(aq"@${HOSTNAME:=$(hostname)}:\e$PWD $(
1910 if (( USER_ID )); then print \e$; else print \e#; fi) "
1913 Note that since the command-line editors try to figure out how long the prompt
1914 is (so they know how far it is to the edge of the screen), escape codes in
1915 the prompt tend to mess things up.
1916 You can tell the shell not to count certain
1917 sequences (such as escape codes) by prefixing your prompt with a
1918 character (such as Ctrl-A) followed by a carriage return and then delimiting
1919 the escape codes with this character.
1920 Any occurences of that character in the prompt are not printed.
1921 By the way, don't blame me for
1922 this hack; it's derived from the original
1924 which did print the delimiter character so you were out of luck
1925 if you did not have any non-printing characters.
1927 Since Backslashes and other special characters may be
1928 interpreted by the shell, to set
1930 either escape the backslash itself,
1931 or use double quotes.
1932 The latter is more practical.
1933 This is a more complex example,
1934 avoiding to directly enter special characters (for example with
1936 in the emacs editing mode),
1937 which embeds the current working directory,
1939 .Pq colour would work, too ,
1940 in the prompt string:
1941 .Bd -literal -offset indent
1943 PS1="$x$(print \e\er)$x$(tput smso)$x\e$PWD$x$(tput rmso)$x\*(Gt "
1946 Due to pressure from David G. Korn,
1948 now also supports the following form:
1949 .Bd -literal -offset indent
1950 PS1=$'\e1\er\e1\ee[7m\e1$PWD\e1\ee[0m\e1\*(Gt '
1953 Secondary prompt string, by default
1955 used when more input is needed to complete a command.
1959 statement when reading a menu selection.
1963 Used to prefix commands that are printed during execution tracing (see the
1966 Parameter, command, and arithmetic substitutions are performed
1967 before it is printed.
1971 The current working directory.
1974 if the shell doesn't know where it is.
1978 is referenced, it is assigned a number between 0 and 32767 from
1979 a Linear Congruential PRNG first.
1981 Default parameter for the
1983 command if no names are given.
1986 loops to store the value that is read from standard input.
1988 The number of seconds since the shell started or, if the parameter has been
1989 assigned an integer value, the number of seconds since the assignment plus the
1990 value that was assigned.
1992 If set to a positive integer in an interactive shell, it specifies the maximum
1993 number of seconds the shell will wait for input after printing the primary
1996 If the time is exceeded, the shell exits.
1998 The directory temporary shell files are created in.
1999 If this parameter is not
2000 set, or does not contain the absolute path of a writable directory, temporary
2001 files are created in
2004 The effective user id of the shell.
2007 Tilde expansion which is done in parallel with parameter substitution, is done
2008 on words starting with an unquoted
2010 The characters following the tilde, up to the first
2012 if any, are assumed to be a login name.
2013 If the login name is empty,
2022 parameter is substituted, respectively.
2023 Otherwise, the password file is
2024 searched for the login name, and the tilde expression is substituted with the
2025 user's home directory.
2026 If the login name is not found in the password file or
2027 if any quoting or parameter substitution occurs in the login name, no
2028 substitution is performed.
2030 In parameter assignments
2031 (such as those preceding a simple-command or those occurring
2039 tilde expansion is done after any assignment
2040 (i.e. after the equals sign)
2041 or after an unquoted colon
2043 login names are also delimited by colons.
2045 The home directory of previously expanded login names are cached and re-used.
2048 command may be used to list, change, and add to this cache (e.g.\&
2049 .Ic alias \-d fac=/usr/local/facilities; cd \*(TIfac/bin ) .
2050 .Ss Brace expansion (alteration)
2051 Brace expressions take the following form:
2052 .Bd -unfilled -offset indent
2055 .Ar prefix No { Ar str1 No ,...,
2056 .Ar strN No } Ar suffix
2061 The expressions are expanded to
2063 words, each of which is the concatenation of
2070 expands to four words:
2076 As noted in the example, brace expressions can be nested and the resulting
2077 words are not sorted.
2078 Brace expressions must contain an unquoted comma
2080 for expansion to occur (e.g.\&
2085 Brace expansion is carried out after parameter substitution
2086 and before file name generation.
2087 .Ss File name patterns
2088 A file name pattern is a word containing one or more unquoted
2098 Once brace expansion has been performed, the shell replaces file
2099 name patterns with the sorted names of all the files that match the pattern
2100 (if no files match, the word is left unchanged).
2101 The pattern elements have the following meaning:
2104 Matches any single character.
2106 Matches any sequence of octets.
2108 Matches any of the octets inside the brackets.
2109 Ranges of octets can be specified by separating two octets by a
2116 In order to represent itself, a
2118 must either be quoted or the first or last octet in the octet list.
2121 must be quoted or the first octet in the list if it is to represent itself
2122 instead of the end of the list.
2125 appearing at the start of the list has special meaning (see below), so to
2126 represent itself it must be quoted or appear later in the list.
2129 except it matches any octet not inside the brackets.
2131 .It *( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
2133 Matches any string of octets that matches zero or more occurrences of the
2135 Example: The pattern
2144 .It +( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
2146 Matches any string of octets that matches one or more occurrences of the
2148 Example: The pattern
2156 .It ?( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
2158 Matches the empty string or a string that matches one of the specified
2160 Example: The pattern
2162 only matches the strings
2168 .It @( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
2170 Matches a string that matches one of the specified patterns.
2171 Example: The pattern
2173 only matches the strings
2178 .It !( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
2180 Matches any string that does not match one of the specified patterns.
2181 Examples: The pattern
2183 matches all strings except
2189 matches no strings; the pattern
2191 matches all strings (think about it).
2210 Note that none of the above pattern elements match either a period
2212 at the start of a file name or a slash
2214 even if they are explicitly used in a [..] sequence; also, the names
2218 are never matched, even by the pattern
2223 option is set, any directories that result from file name generation are marked
2226 .Ss Input/output redirection
2227 When a command is executed, its standard input, standard output, and standard
2228 error (file descriptors 0, 1, and 2, respectively) are normally inherited from
2230 Three exceptions to this are commands in pipelines, for which
2231 standard input and/or standard output are those set up by the pipeline,
2232 asynchronous commands created when job control is disabled, for which standard
2233 input is initially set to be from
2235 and commands for which any of the following redirections have been specified:
2236 .Bl -tag -width XXxxmarker
2238 Standard output is redirected to
2242 does not exist, it is created; if it does exist, is a regular file, and the
2244 option is set, an error occurs; otherwise, the file is truncated.
2245 Note that this means the command
2246 .Ic cmd \*(Ltfoo \*(Gtfoo
2249 for reading and then truncate it when it opens it for writing, before
2251 gets a chance to actually read
2253 .It \*(Gt\*(Ba Ar file
2256 except the file is truncated, even if the
2259 .It \*(Gt\*(Gt Ar file
2264 exists it is appended to instead of being truncated.
2265 Also, the file is opened
2266 in append mode, so writes always go to the end of the file (see
2269 Standard input is redirected from
2271 which is opened for reading.
2272 .It \*(Lt\*(Gt Ar file
2275 except the file is opened for reading and writing.
2276 .It \*(Lt\*(Lt Ar marker
2277 After reading the command line containing this kind of redirection (called a
2278 .Dq here document ) ,
2279 the shell copies lines from the command source into a temporary file until a
2283 When the command is executed, standard input is redirected from the
2287 contains no quoted characters, the contents of the temporary file are processed
2288 as if enclosed in double quotes each time the command is executed, so
2289 parameter, command, and arithmetic substitutions are performed, along with
2300 If multiple here documents are used on the same command line, they are saved in
2305 is given, the here document ends at the next
2307 and substitution will be performed.
2310 is only a set of either single
2314 quotes with nothing in between, the here document ends at the next empty line
2315 and substitution will not be performed.
2316 .It \*(Lt\*(Lt\- Ar marker
2319 except leading tabs are stripped from lines in the here document.
2320 .It \*(Lt\*(Lt\*(Lt Ar word
2327 This is called a here string.
2329 Standard input is duplicated from file descriptor
2332 can be a number, indicating the number of an existing file descriptor;
2335 indicating the file descriptor associated with the output of the current
2336 co-process; or the character
2338 indicating standard input is to be closed.
2341 is limited to a single digit in most shell implementations.
2345 except the operation is done on standard output.
2348 .Ic \*(Gt Ar file 2\*(Gt&1 .
2351 extension supported by
2353 which also supports the preceding explicit fd number, for example,
2356 .Ic 3\*(Gt Ar file 2\*(Gt&3
2359 but a syntax error in GNU
2362 .No &\*(Gt\*(Ba Ar file ,
2363 .No &\*(Gt\*(Gt Ar file ,
2367 .Ic \*(Gt\*(Ba Ar file ,
2368 .Ic \*(Gt\*(Gt Ar file ,
2379 In any of the above redirections, the file descriptor that is redirected
2380 (i.e. standard input or standard output)
2381 can be explicitly given by preceding the
2382 redirection with a number (portably, only a single digit).
2383 Parameter, command, and arithmetic
2384 substitutions, tilde substitutions, and (if the shell is interactive)
2385 file name generation are all performed on the
2390 arguments of redirections.
2391 Note, however, that the results of any file name
2392 generation are only used if a single file is matched; if multiple files match,
2393 the word with the expanded file name generation characters is used.
2395 that in restricted shells, redirections which can create files cannot be used.
2397 For simple-commands, redirections may appear anywhere in the command; for
2403 any redirections must appear at the end.
2404 Redirections are processed after
2405 pipelines are created and in the order they are given, so the following
2406 will print an error with a line number prepended to it:
2408 .D1 $ cat /foo/bar 2\*(Gt&1 \*(Gt/dev/null \*(Ba pr \-n \-t
2410 File descriptors created by input/output redirections are private to the
2411 Korn shell, but passed to sub-processes if
2416 .Ss Arithmetic expressions
2417 Integer arithmetic expressions can be used with the
2419 command, inside $((..)) expressions, inside array references (e.g.\&
2420 .Ar name Ns Bq Ar expr ) ,
2421 as numeric arguments to the
2423 command, and as the value of an assignment to an integer parameter.
2425 Expressions are calculated using signed arithmetic and the
2427 type (a 32-bit signed integer), unless they begin with a sole
2429 character, in which case they use
2431 .Po a 32-bit unsigned integer Pc .
2433 Expressions may contain alpha-numeric parameter identifiers, array references,
2434 and integer constants and may be combined with the following C operators
2435 (listed and grouped in increasing order of precedence):
2438 .Bd -literal -offset indent
2439 + \- ! \*(TI ++ \-\-
2443 .Bd -literal -offset indent
2445 = *= /= %= += \-= \*(Lt\*(Lt= \*(Gt\*(Gt= &= \*(ha= \*(Ba=
2452 \*(Lt \*(Lt= \*(Gt= \*(Gt
2453 \*(Lt\*(Lt \*(Gt\*(Gt
2459 .Bd -literal -offset indent
2460 ?: (precedence is immediately higher than assignment)
2464 .Bd -literal -offset indent
2468 Integer constants and expressions are calculated using the
2474 type, and are limited to 32 bits.
2475 Overflows wrap silently.
2476 Integer constants may be specified with arbitrary bases using the notation
2477 .Ar base Ns # Ns Ar number ,
2480 is a decimal integer specifying the base, and
2482 is a number in the specified base.
2484 integers may be prefixed with
2488 (specifying base 16), similar to
2495 extension, in all forms of arithmetic expressions,
2496 except as numeric arguments to the
2501 extension, numbers to the base of one are treated as either (8-bit
2502 transparent) ASCII or Unicode codepoints, depending on the shell's
2504 flag (current setting).
2513 Note that NUL bytes (integral value of zero) cannot be used.
2514 In Unicode mode, raw octets are mapped into the range EF80..EFFF as in
2515 OPTU-8, which is in the PUA and has been assigned by CSUR for this use.
2516 If more than one octet in ASCII mode, or a sequence of more than one
2517 octet not forming a valid and minimal CESU-8 sequence is passed, the
2518 behaviour is undefined (usually, the shell aborts with a parse error,
2519 but rarely, it succeeds, e.g. on the sequence C2 20).
2520 That's why you should always use ASCII mode unless you know that the
2521 input is well-formed UTF-8 in the range of 0000..FFFD.
2523 The operators are evaluated as follows:
2524 .Bl -tag -width Ds -offset indent
2526 Result is the argument (included for completeness).
2531 the result is 1 if argument is zero, 0 if not.
2533 Arithmetic (bit-wise) NOT.
2535 Increment; must be applied to a parameter (not a literal or other expression).
2536 The parameter is incremented by 1.
2537 When used as a prefix operator, the result
2538 is the incremented value of the parameter; when used as a postfix operator, the
2539 result is the original value of the parameter.
2543 except the parameter is decremented by 1.
2545 Separates two arithmetic expressions; the left-hand side is evaluated first,
2547 The result is the value of the expression on the right-hand side.
2549 Assignment; the variable on the left is set to the value on the right.
2551 .No *= /= += \-= \*(Lt\*(Lt=
2552 .No \*(Gt\*(Gt= &= \*(ha= \*(Ba=
2554 Assignment operators.
2569 with any operator precedence in
2574 is the same as specifying
2575 .Dq var1 = var1 * (5 + 3) .
2578 the result is 1 if either argument is non-zero, 0 if not.
2579 The right argument is evaluated only if the left argument is zero.
2582 the result is 1 if both arguments are non-zero, 0 if not.
2583 The right argument is evaluated only if the left argument is non-zero.
2585 Arithmetic (bit-wise) OR.
2587 Arithmetic (bit-wise) XOR
2590 Arithmetic (bit-wise) AND.
2592 Equal; the result is 1 if both arguments are equal, 0 if not.
2594 Not equal; the result is 0 if both arguments are equal, 1 if not.
2596 Less than; the result is 1 if the left argument is less than the right, 0 if
2598 .It \*(Lt= \*(Gt= \*(Gt
2599 Less than or equal, greater than or equal, greater than.
2602 .It \*(Lt\*(Lt \*(Gt\*(Gt
2603 Shift left (right); the result is the left argument with its bits shifted left
2604 (right) by the amount given in the right argument.
2606 Addition, subtraction, multiplication, and division.
2608 Remainder; the result is the remainder of the division of the left argument by
2610 The sign of the result is unspecified if either argument is negative.
2620 is non-zero, the result is
2622 otherwise the result is
2626 A co-process (which is a pipeline created with the
2628 operator) is an asynchronous process that the shell can both write to (using
2630 and read from (using
2632 The input and output of the co-process can also be manipulated using
2636 redirections, respectively.
2637 Once a co-process has been started, another can't
2638 be started until the co-process exits, or until the co-process's input has been
2640 .Ic exec Ar n Ns Ic \*(Gt&p
2642 If a co-process's input is redirected in this way, the next
2643 co-process to be started will share the output with the first co-process,
2644 unless the output of the initial co-process has been redirected using an
2645 .Ic exec Ar n Ns Ic \*(Lt&p
2648 Some notes concerning co-processes:
2651 The only way to close the co-process's input (so the co-process reads an
2652 end-of-file) is to redirect the input to a numbered file descriptor and then
2653 close that file descriptor:
2654 .Ic exec 3\*(Gt&p; exec 3\*(Gt&\-
2656 In order for co-processes to share a common output, the shell must keep the
2657 write portion of the output pipe open.
2658 This means that end-of-file will not be
2659 detected until all co-processes sharing the co-process's output have exited
2660 (when they all exit, the shell closes its copy of the pipe).
2662 avoided by redirecting the output to a numbered file descriptor (as this also
2663 causes the shell to close its copy).
2664 Note that this behaviour is slightly
2665 different from the original Korn shell which closes its copy of the write
2666 portion of the co-process output when the most recently started co-process
2667 (instead of when all sharing co-processes) exits.
2672 signals during writes if the signal is not being trapped or ignored; the same
2673 is true if the co-process input has been duplicated to another file descriptor
2675 .Ic print \-u Ns Ar n
2679 Functions are defined using either Korn shell
2680 .Ic function Ar function-name
2681 syntax or the Bourne/POSIX shell
2682 .Ar function-name Ns \&()
2683 syntax (see below for the difference between the two forms).
2686 (i.e. scripts sourced using the
2689 in that they are executed in the current environment.
2692 shell arguments (i.e. positional parameters $1, $2, etc.)\&
2693 are never visible inside them.
2694 When the shell is determining the location of a command, functions
2695 are searched after special built-in commands, before regular and
2696 non-regular built-ins, and before the
2700 An existing function may be deleted using
2701 .Ic unset Fl f Ar function-name .
2702 A list of functions can be obtained using
2704 and the function definitions can be listed using
2708 command (which is an alias for
2710 may be used to create undefined functions: when an undefined function is
2711 executed, the shell searches the path specified in the
2713 parameter for a file with the same name as the function which, if found, is
2715 If after executing the file the named function is found to
2716 be defined, the function is executed; otherwise, the normal command search is
2717 continued (i.e. the shell searches the regular built-in command table and
2719 Note that if a command is not found using
2721 an attempt is made to autoload a function using
2723 (this is an undocumented feature of the original Korn shell).
2725 Functions can have two attributes,
2729 which can be set with
2734 When a traced function is executed, the shell's
2736 option is turned on for the function's duration.
2739 attribute of functions is currently not used.
2740 In the original Korn shell,
2741 exported functions are visible to shell scripts that are executed.
2743 Since functions are executed in the current shell environment, parameter
2744 assignments made inside functions are visible after the function completes.
2745 If this is not the desired effect, the
2747 command can be used inside a function to create a local parameter.
2751 uses static scoping (one global scope, one local scope per function), whereas
2753 uses dynamic scoping (nested scopes of varying locality).
2754 Note that special parameters (e.g.\&
2756 can't be scoped in this way.
2758 The exit status of a function is that of the last command executed in the
2760 A function can be made to finish immediately using the
2762 command; this may also be used to explicitly specify the exit status.
2764 Functions defined with the
2766 reserved word are treated differently in the following ways from functions
2772 The $0 parameter is set to the name of the function
2773 (Bourne-style functions leave $0 untouched).
2775 Parameter assignments preceding function calls are not kept in the shell
2776 environment (executing Bourne-style functions will keep assignments).
2779 is saved/reset and restored on entry and exit from the function so
2781 can be used properly both inside and outside the function (Bourne-style
2786 inside a function interferes with using
2788 outside the function).
2790 Bourne-style function definitions take precedence over alias dereferences
2791 and remove alias definitions upon encounter, while aliases take precedence
2792 over Korn-style functions.
2795 In the future, the following differences will also be added:
2798 A separate trap/signal environment will be used during the execution of
2800 This will mean that traps set inside a function will not affect the
2801 shell's traps and signals that are not ignored in the shell (but may be
2802 trapped) will have their default effect in a function.
2804 The EXIT trap, if set in a function, will be executed after the function
2807 .Ss Command execution
2808 After evaluation of command-line arguments, redirections, and parameter
2809 assignments, the type of command is determined: a special built-in, a
2810 function, a regular built-in, or the name of a file to execute found using the
2813 The checks are made in the above order.
2814 Special built-in commands differ from other commands in that the
2816 parameter is not used to find them, an error during their execution can
2817 cause a non-interactive shell to exit, and parameter assignments that are
2818 specified before the command are kept after the command completes.
2819 Regular built-in commands are different only in that the
2821 parameter is not used to find them.
2825 and POSIX differ somewhat in which commands are considered
2828 POSIX special commands
2830 .Ic \&. , \&: , break , continue ,
2831 .Ic eval , exec , exit , export ,
2832 .Ic readonly , return , set , shift ,
2833 .Ic trap , unset , wait
2839 .Ic builtin , global , times , typeset
2841 Very special commands
2844 .Ic alias , readonly , set , typeset
2846 POSIX regular commands
2848 .Ic alias , bg , cd , command ,
2849 .Ic false , fc , fg , getopts ,
2850 .Ic jobs , kill , read , true ,
2857 .Ic \&[ , chdir , bind , cat ,
2858 .Ic echo , let , mknod , print ,
2859 .Ic printf , pwd , realpath , rename ,
2860 .Ic sleep , test , ulimit , whence
2862 In the future, the additional
2864 special and regular commands may be treated
2865 differently from the POSIX special and regular commands.
2867 Once the type of command has been determined, any command-line parameter
2868 assignments are performed and exported for the duration of the command.
2870 The following describes the special and regular built-in commands:
2872 .Bl -tag -width false -compact
2873 .It Ic \&. Ar file Op Ar arg ...
2877 Execute the commands in
2879 in the current environment.
2880 The file is searched for in the directories of
2882 If arguments are given, the positional parameters may be used to access them
2886 If no arguments are given, the positional parameters are
2887 those of the environment the command is used in.
2889 .It Ic \&: Op Ar ...
2891 Exit status is set to zero.
2894 .Oo Fl d \*(Ba t Oo Fl r Oc \*(Ba
2899 .Op Ns = Ns Ar value
2905 For any name without a value, the existing alias is listed.
2906 Any name with a value defines an alias (see
2910 When listing aliases, one of two formats is used.
2911 Normally, aliases are listed as
2912 .Ar name Ns = Ns Ar value ,
2916 If options were preceded with
2920 is given on the command line, only
2926 option causes directory aliases which are used in tilde expansion to be
2933 option is used, each alias is prefixed with the string
2938 option indicates that tracked aliases are to be listed/set (values specified on
2939 the command line are ignored for tracked aliases).
2942 option indicates that all tracked aliases are to be reset.
2948 the export attribute of an alias, or, if no names are given, lists the aliases
2949 with the export attribute (exporting an alias has no effect).
2951 .It Ic bg Op Ar job ...
2952 Resume the specified stopped job(s) in the background.
2953 If no jobs are specified,
2958 below for more information.
2961 The current bindings are listed.
2966 instead lists the names of the functions to which keys may be bound.
2968 .Sx Emacs editing mode
2969 for more information.
2971 .It Xo Ic bind Op Fl m
2972 .Ar string Ns = Ns Op Ar substitute
2976 .Ar string Ns = Ns Op Ar editing-command
2979 The specified editing command is bound to the given
2981 which should consist of a control character
2982 optionally preceded by one of the two prefix characters
2983 and optionally succeded by a tilde character.
2986 will cause the editing command to be immediately invoked.
2989 flag is given, the specified input
2991 will afterwards be immediately replaced by the given
2993 string which may contain editing commands but not other macros.
2994 If a tilde postfix is given, a tilde trailing the one or
2995 two prefices and the control character is ignored, any
2996 other trailing character will be processed afterwards.
2998 Control characters may be written using caret notation
2999 i.e. \*(haX represents Ctrl-X.
3000 Note that although only two prefix characters (usually ESC and \*(haX)
3001 are supported, some multi-character sequences can be supported.
3003 The following default bindings show how the arrow keys, the home, end and
3004 delete key on a BSD wsvt25, xterm\-xfree86 or GNU screen terminal are bound
3005 (of course some escape sequences won't work out quite this nicely):
3006 .Bd -literal -offset indent
3007 bind \*(aq\*(haX\*(aq=prefix\-2
3008 bind \*(aq\*(ha[[\*(aq=prefix\-2
3009 bind \*(aq\*(haXA\*(aq=up\-history
3010 bind \*(aq\*(haXB\*(aq=down\-history
3011 bind \*(aq\*(haXC\*(aq=forward\-char
3012 bind \*(aq\*(haXD\*(aq=backward\-char
3013 bind \*(aq\*(haX1\*(TI\*(aq=beginning\-of\-line
3014 bind \*(aq\*(haX7\*(TI\*(aq=beginning\-of\-line
3015 bind \*(aq\*(haXH\*(aq=beginning\-of\-line
3016 bind \*(aq\*(haX4\*(TI\*(aq=end\-of\-line
3017 bind \*(aq\*(haX8\*(TI\*(aq=end\-of\-line
3018 bind \*(aq\*(haXF\*(aq=end\-of\-line
3019 bind \*(aq\*(haX3\*(TI\*(aq=delete\-char\-forward
3022 .It Ic break Op Ar level
3038 .Ar command Op Ar arg ...
3040 Execute the built-in command
3048 Read files sequentially, in command line order, and write them to
3054 or absent, read from standard input.
3055 Unless compiled with
3056 .Dv MKSH_NO_EXTERNAL_CAT ,
3057 if any options are given, an external
3059 utility is invoked instead if called from the shell.
3060 For direct builtin calls, the
3063 option is supported as a no-op.
3080 Set the working directory to
3084 is set, it lists the search path for the directory containing
3088 path means the current directory.
3091 is found in any component of the
3093 search path other than the
3095 path, the name of the new working directory will be written to standard output.
3098 is missing, the home directory
3105 the previous working directory is used (see the
3111 option (logical path) is used or if the
3113 option isn't set (see the
3115 command below), references to
3119 are relative to the path used to get to the directory.
3122 option (physical path) is used or if the
3126 is relative to the filesystem directory tree.
3131 parameters are updated to reflect the current and old working directory,
3135 option is set for physical filesystem traversal, and
3137 could not be set, the exit code is 1; greater than 1 if an
3138 error occurred, 0 otherwise.
3154 in the current directory, and the shell attempts to change to the new
3169 is executed exactly as if
3171 had not been specified, with two exceptions:
3174 cannot be a shell function;
3175 and secondly, special built-in commands lose their specialness
3176 (i.e. redirection and utility errors do not cause the shell to
3177 exit, and command assignments are not permanent).
3181 option is given, a default search path is used instead of the current value of
3183 the actual value of which is system dependent.
3187 option is given, instead of executing
3189 information about what would be executed is given (and the same is done for
3191 For special and regular built-in commands and functions, their names are simply
3192 printed; for aliases, a command that defines them is printed; and for commands
3193 found by searching the
3195 parameter, the full path of the command is printed.
3196 If no command is found
3197 (i.e. the path search fails), nothing is printed and
3199 exits with a non-zero status.
3204 option, except it is more verbose.
3206 .It Ic continue Op Ar level
3207 Jumps to the beginning of the
3225 this utility is not portable; use the Korn shell builtin
3227 or the much slower POSIX utility
3231 Prints its arguments (separated by spaces) followed by a newline, to the
3233 The newline is suppressed if any of the arguments contain the
3238 command below for a list of other backslash sequences that are recognised.
3240 The options are provided for compatibility with
3245 option suppresses the trailing newline,
3247 enables backslash interpretation (a no-op, since this is normally done), and
3249 suppresses backslash interpretation.
3255 option is set or this is a direct builtin call, only the first argument
3256 is treated as an option, and only if it is exactly
3258 Backslash interpretation is disabled.
3260 .It Ic eval Ar command ...
3261 The arguments are concatenated (with spaces between them) to form a single
3262 string which the shell then parses and executes in the current environment.
3266 .Op Ar command Op Ar arg ...
3268 The command is executed without forking, replacing the shell process.
3270 If no command is given except for I/O redirection, the I/O redirection is
3271 permanent and the shell is
3273 Any file descriptors greater than 2 which are opened or
3275 in this way are not made available to other executed commands (i.e. commands
3276 that are not built-in to the shell).
3277 Note that the Bourne shell differs here;
3278 it does pass these file descriptors on.
3280 .It Ic exit Op Ar status
3281 The shell exits with the specified exit status.
3284 is not specified, the exit status is the current value of the
3291 .Op Ar parameter Ns Op = Ns Ar value
3293 Sets the export attribute of the named parameters.
3294 Exported parameters are passed in the environment to executed commands.
3295 If values are specified, the named parameters are also assigned.
3297 If no parameters are specified, the names of all parameters with the export
3298 attribute are printed one per line, unless the
3300 option is used, in which case
3302 commands defining all exported parameters, including their values, are printed.
3305 A command that exits with a non-zero status.
3309 .Oo Fl e Ar editor \*(Ba
3312 .Op Ar first Op Ar last
3317 select commands from the history.
3318 Commands can be selected by history number
3319 or a string specifying the most recent command starting with that string.
3322 option lists the command on standard output, and
3324 inhibits the default command numbers.
3327 option reverses the order of the list.
3330 the selected commands are edited by the editor specified with the
3334 is specified, the editor specified by the
3336 parameter (if this parameter is not set,
3338 is used), and then executed by the shell.
3342 .Cm \-e \- \*(Ba Fl s
3344 .Op Ar old Ns = Ns Ar new
3347 Re-execute the selected command (the previous command by default) after
3348 performing the optional substitution of
3354 is specified, all occurrences of
3362 is identical: re-execute the selected command without invoking an editor.
3363 This command is usually accessed with the predefined
3364 .Ic alias r=\*(aqfc \-e \-\*(aq
3365 or by prefixing an interactive mode input line with
3369 .It Ic fg Op Ar job ...
3370 Resume the specified job(s) in the foreground.
3371 If no jobs are specified,
3376 below for more information.
3383 Used by shell procedures to parse the specified arguments (or positional
3384 parameters, if no arguments are given) and to check for legal options.
3386 contains the option letters that
3389 If a letter is followed by a colon, the option is expected to
3391 Options that do not take arguments may be grouped in a single argument.
3392 If an option takes an argument and the option character is not the
3393 last character of the argument it is found in, the remainder of the argument is
3394 taken to be the option's argument; otherwise, the next argument is the option's
3399 is invoked, it places the next option in the shell parameter
3401 and the index of the argument to be processed by the next call to
3403 in the shell parameter
3405 If the option was introduced with a
3407 the option placed in
3411 When an option requires an argument,
3413 places it in the shell parameter
3416 When an illegal option or a missing option argument is encountered, a question
3417 mark or a colon is placed in
3419 (indicating an illegal option or missing argument, respectively) and
3421 is set to the option character that caused the problem.
3424 does not begin with a colon, a question mark is placed in
3427 is unset, and an error message is printed to standard error.
3429 When the end of the options is encountered,
3431 exits with a non-zero exit status.
3432 Options end at the first (non-option
3433 argument) argument that does not start with a
3437 argument is encountered.
3439 Option parsing can be reset by setting
3441 to 1 (this is done automatically whenever the shell or a shell procedure is
3444 Warning: Changing the value of the shell parameter
3446 to a value other than 1, or parsing different sets of arguments without
3449 may lead to unexpected results.
3456 Without arguments, any hashed executable command pathnames are listed.
3459 option causes all hashed commands to be removed from the hash table.
3462 is searched as if it were a command name and added to the hash table if it is
3463 an executable command.
3470 Display information about the specified job(s); if no jobs are specified, all
3474 option causes information to be displayed only for jobs that have changed
3475 state since the last notification.
3478 option is used, the process ID of each process in a job is also listed.
3481 option causes only the process group of each job to be printed.
3484 below for the format of
3486 and the displayed job.
3490 .Oo Fl s Ar signame \*(Ba
3491 .No \- Ns Ar signum \*(Ba
3492 .No \- Ns Ar signame Oc
3493 .No { Ar job \*(Ba pid \*(Ba pgrp No }
3496 Send the specified signal to the specified jobs, process IDs, or process
3498 If no signal is specified, the
3501 If a job is specified, the signal is sent to the job's process group.
3504 below for the format of
3510 .Op Ar exit-status ...
3512 Print the signal name corresponding to
3514 If no arguments are specified, a list of all the signals, their numbers, and
3515 a short description of them are printed.
3517 .It Ic let Op Ar expression ...
3518 Each expression is evaluated (see
3519 .Sx Arithmetic expressions
3521 If all expressions are successfully evaluated, the exit status is 0 (1)
3522 if the last expression evaluated to non-zero (zero).
3523 If an error occurs during
3524 the parsing or evaluation of an expression, the exit status is greater than 1.
3525 Since expressions may need to be quoted,
3526 .No \&(( Ar expr No ))
3527 is syntactic sugar for
3528 .No let \&" Ns Ar expr Ns \&" .
3543 Create a device special file.
3544 The file type may be
3546 (block type device),
3548 (character type device),
3552 The file created may be modified according to its
3558 (major device number),
3561 (minor device number).
3565 for further information.
3569 .Oo Fl nprsu Ns Oo Ar n Oc \*(Ba
3574 prints its arguments on the standard output, separated by spaces and
3575 terminated with a newline.
3578 option suppresses the newline.
3579 By default, certain C escapes are translated.
3580 These include these mentioned in
3581 .Sx Backslash expansion
3584 which is equivalent to using the
3587 Backslash expansion may be inhibited with the
3592 option prints to the history file instead of standard output; the
3594 option prints to file descriptor
3598 defaults to 1 if omitted
3602 option prints to the co-process (see
3608 option is used to emulate, to some degree, the
3611 command which does not process
3613 sequences unless the
3618 option suppresses the trailing newline.
3620 .It Ic printf Ar format Op Ar arguments ...
3622 Approximately the same as the utility
3624 except that it uses the same
3625 .Sx Backslash expansion
3626 and I/O code as the rest of
3628 This is not normally part of
3630 however, distributors may have added this as builtin as a speed hack.
3633 Print the present working directory.
3636 option is used or if the
3638 option isn't set (see the
3640 command below), the logical path is printed (i.e. the path used to
3642 to the current directory).
3645 option (physical path) is used or if the
3647 option is set, the path determined from the filesystem (by following
3649 directories to the root directory) is printed.
3663 Reads a line of input, separates the input into fields using the
3667 above), and assigns each field to the specified parameters
3669 If no parameters are specified, the
3671 parameter is used to store the result.
3676 options, only no or one parameter is accepted.
3677 If there are more parameters than fields, the extra parameters are set to
3678 the empty string or 0; if there are more fields than parameters, the last
3679 parameter is assigned the remaining fields (including the word separators).
3681 The options are as follows:
3682 .Bl -tag -width XuXnX
3684 Store the result into the parameter
3690 Store the result without word splitting into the parameter
3694 as array of characters (wide characters if the
3696 option is enacted, octets otherwise).
3698 Use the first byte of
3701 if empty, instead of the ASCII newline character as input line delimiter.
3703 Instead of reading till end-of-line, read exactly
3705 bytes; less if EOF or a timeout occurs.
3707 Instead of reading till end-of-line, read up to
3709 bytes but return as soon as any bytes are read, e.g.\& from a
3710 slow terminal device, or if EOF or a timeout occurs.
3712 Read from the currently active co-process, see
3714 above for details on this.
3716 Read from the file descriptor
3718 (defaults to 0, i.e.\& standard input).
3719 The argument must immediately follow the option character.
3721 Interrupt reading after
3723 seconds (specified as positive decimal value with an optional fractional part).
3725 Normally, the ASCII backslash character escapes the special
3726 meaning of the following character and is stripped from the input;
3728 does not stop when encountering a backslash-newline sequence and
3729 does not store that newline in the result.
3730 This option enables raw mode, in which backslashes are not processed.
3732 The input line is saved to the history.
3735 If the input is a terminal, both the
3739 options set it into raw mode;
3740 they read an entire file if \-1 is passed as
3744 The first parameter may have a question mark and a string appended to it, in
3745 which case the string is used as a prompt (printed to standard error before
3746 any input is read) if the input is a
3749 .Ic read nfoo?\*(aqnumber of foos: \*(aq ) .
3751 If no input is read or a timeout occurred,
3753 exits with a non-zero status.
3755 Another handy set of tricks:
3758 is run in a loop such as
3759 .Ic while read foo; do ...; done
3760 then leading whitespace will be removed (IFS) and backslashes processed.
3761 You might want to use
3762 .Ic while IFS= read \-r foo; do ...; done
3764 Similarily, when using the
3768 option might be prudent; the same applies for:
3769 .Bd -literal -offset indent
3770 find . \-type f \-print0 \*(Ba \e
3771 while IFS= read \-d \*(aq\*(aq \-r filename; do
3772 print \-r \-\- "found <${filename#./}>"
3776 The inner loop will be executed in a subshell and variable changes
3777 cannot be propagated if executed in a pipeline:
3778 .Bd -literal -offset indent
3779 bar \*(Ba baz \*(Ba while read foo; do ...; done
3782 Use co-processes instead:
3783 .Bd -literal -offset indent
3784 bar \*(Ba baz \*(Ba&
3785 while read \-p foo; do ...; done
3786 exec 3\*(Gt&p; exec 3\*(Gt&\-
3793 .Op Ns = Ns Ar value
3796 Sets the read-only attribute of the named parameters.
3797 If values are given,
3798 parameters are set to them before setting the attribute.
3800 made read-only, it cannot be unset and its value cannot be changed.
3802 If no parameters are specified, the names of all parameters with the read-only
3803 attribute are printed one per line, unless the
3805 option is used, in which case
3807 commands defining all read-only parameters, including their values, are
3815 Prints the resolved absolute pathname corresponding to
3821 it's also checked for existence and whether it is a directory; otherwise,
3823 returns 0 if the pathname either exists or can be created immediately,
3824 i.e. all but the last component exist and are directories.
3835 Both must be complete pathnames and on the same device.
3836 This builtin is intended for emergency situations where
3838 becomes unusable, and directly calls
3841 .It Ic return Op Ar status
3842 Returns from a function or
3844 script, with exit status
3848 is given, the exit status of the last executed command is used.
3849 If used outside of a function or
3851 script, it has the same effect as
3855 treats both profile and
3859 scripts, while the original Korn shell only treats profiles as
3864 .Ic set Op Ic +\-abCefhiklmnprsUuvXx
3865 .Op Ic +\-o Ar option
3872 command can be used to set
3876 shell options, set the positional parameters, or set an array parameter.
3877 Options can be changed using the
3881 is the long name of an option, or using the
3882 .Cm +\- Ns Ar letter
3885 is the option's single letter name (not all options have a single letter name).
3886 The following table lists both option letters (if they exist) and long names
3887 along with a description of what the option does:
3890 Sets the elements of the array parameter
3896 is used, the array is reset (i.e. emptied) first; if
3898 is used, the first N elements are set (where N is the number of arguments);
3899 the rest are left untouched.
3901 An alternative syntax for the command
3902 .Ic set \-A foo \-\- a b c
3903 which is compatible to
3906 and also supported by
3910 .Ic foo=(a b c); foo+=(d e)
3918 extension allows specifying the indices used for
3920 .Pq from the above example, Ic a b c
3922 .Ic set \-A foo \-\- [0]=a [1]=b [2]=c
3924 .Ic foo=([0]=a [1]=b [2]=c)
3925 which can also be written
3927 because indices are incremented automatically.
3928 .It Fl a \*(Ba Fl o Ic allexport
3929 All new parameters are created with the export attribute.
3930 .It Fl b \*(Ba Fl o Ic notify
3931 Print job notification messages asynchronously, instead of just before the
3933 Only used if job control is enabled
3935 .It Fl C \*(Ba Fl o Ic noclobber
3936 Prevent \*(Gt redirection from overwriting existing files.
3937 Instead, \*(Gt\*(Ba must be used to force an overwrite.
3938 .It Fl e \*(Ba Fl o Ic errexit
3939 Exit (after executing the
3941 trap) as soon as an error occurs or a command fails (i.e. exits with a
3943 This does not apply to commands whose exit status is
3944 explicitly tested by a shell construct such as
3953 .It Fl f \*(Ba Fl o Ic noglob
3954 Do not expand file name patterns.
3955 .It Fl h \*(Ba Fl o Ic trackall
3956 Create tracked aliases for all executed commands (see
3959 Enabled by default for non-interactive shells.
3960 .It Fl i \*(Ba Fl o Ic interactive
3961 The shell is an interactive shell.
3962 This option can only be used when the shell is invoked.
3963 See above for a description of what this means.
3964 .It Fl k \*(Ba Fl o Ic keyword
3965 Parameter assignments are recognised anywhere in a command.
3966 .It Fl l \*(Ba Fl o Ic login
3967 The shell is a login shell.
3968 This option can only be used when the shell is invoked.
3969 See above for a description of what this means.
3970 .It Fl m \*(Ba Fl o Ic monitor
3971 Enable job control (default for interactive shells).
3972 .It Fl n \*(Ba Fl o Ic noexec
3973 Do not execute any commands.
3974 Useful for checking the syntax of scripts
3975 (ignored if interactive).
3976 .It Fl p \*(Ba Fl o Ic privileged
3977 The shell is a privileged shell.
3978 It is set automatically if, when the shell starts,
3979 the real UID or GID does not match
3980 the effective UID (EUID) or GID (EGID), respectively.
3981 See above for a description of what this means.
3982 .It Fl r \*(Ba Fl o Ic restricted
3983 The shell is a restricted shell.
3984 This option can only be used when the shell is invoked.
3985 See above for a description of what this means.
3986 .It Fl s \*(Ba Fl o Ic stdin
3987 If used when the shell is invoked, commands are read from standard input.
3988 Set automatically if the shell is invoked with no arguments.
3994 command it causes the specified arguments to be sorted before assigning them to
3995 the positional parameters (or to array
4000 .It Fl U \*(Ba Fl o Ic utf8\-mode
4001 Enable UTF-8 support in the
4002 .Sx Emacs editing mode
4003 and internal string handling functions.
4004 This flag is disabled by default, but can be enabled by setting it on the
4005 shell command line; is enabled automatically for interactive shells if
4006 requested at compile time, your system supports
4007 .Fn setlocale LC_CTYPE \&""
4009 .Fn nl_langinfo CODESET ,
4015 environment variables,
4016 and at least one of these returns something that matches
4020 case-insensitively; for direct builtin calls depending on the
4021 aforementioned environment variables; or for stdin or scripts,
4022 if the input begins with a UTF-8 Byte Order Mark.
4023 .It Fl u \*(Ba Fl o Ic nounset
4024 Referencing of an unset parameter, other than
4028 is treated as an error, unless one of the
4034 .It Fl v \*(Ba Fl o Ic verbose
4035 Write shell input to standard error as it is read.
4036 .It Fl X \*(Ba Fl o Ic markdirs
4037 Mark directories with a trailing
4039 during file name generation.
4040 .It Fl x \*(Ba Fl o Ic xtrace
4041 Print commands and parameter assignments when they are executed, preceded by
4045 Background jobs are run with lower priority.
4046 .It Fl o Ic braceexpand
4047 Enable brace expansion (a.k.a. alternation).
4048 This is enabled by default.
4049 If disabled, tilde expansion after an equals sign is disabled as a side effect.
4051 Enable BRL emacs-like command-line editing (interactive shells only); see
4052 .Sx Emacs editing mode .
4054 Enable gmacs-like command-line editing (interactive shells only).
4055 Currently identical to emacs editing except that transpose\-chars (\*(haT) acts
4056 slightly differently.
4057 .It Fl o Ic ignoreeof
4058 The shell will not (easily) exit when end-of-file is read;
4061 To avoid infinite loops, the shell will exit if
4063 is read 13 times in a row.
4065 Do not kill running jobs with a
4067 signal when a login shell exits.
4068 Currently set by default, but this may
4069 change in the future to be compatible with
4073 doesn't have this option, but does send the
4078 In the original Korn shell, this prevents function definitions from
4079 being stored in the history file.
4080 .It Fl o Ic physical
4087 (i.e. the filesystem's)
4089 directories instead of
4091 directories (i.e. the shell handles
4093 which allows the user to be oblivious of symbolic links to directories).
4095 Note that setting this option does not affect the current value of the
4105 commands above for more details.
4107 Enable a somewhat more
4110 As a side effect, setting this flag turns off
4112 mode, which can be turned back on manually, and
4120 Automatically enabled if the basename of the shell invocation begins with
4122 and this autodetection feature is compiled in
4124 As a side effect, setting this flag turns off
4126 mode, which can be turned back on manually, and
4132 command-line editing (interactive shells only).
4133 .It Fl o Ic vi\-esccomplete
4134 In vi command-line editing, do command and file name completion when escape
4135 (\*(ha[) is entered in command mode.
4136 .It Fl o Ic vi\-tabcomplete
4137 In vi command-line editing, do command and file name completion when tab (\*(haI)
4138 is entered in insert mode.
4139 This is the default.
4142 In the original Korn shell, unless
4144 was set, the vi command-line mode would let the
4146 driver do the work until ESC (\*(ha[) was entered.
4148 is always in viraw mode.
4151 These options can also be used upon invocation of the shell.
4153 options (with single letter names) can be found in the parameter
4156 with no option name will list all the options and whether each is on or off;
4158 will print the long names of all options that are currently on.
4160 Remaining arguments, if any, are positional parameters and are assigned, in
4161 order, to the positional parameters (i.e. $1, $2, etc.).
4164 and there are no remaining arguments, all positional parameters are cleared.
4165 If no options or arguments are given, the values of all names are printed.
4166 For unknown historical reasons, a lone
4168 option is treated specially \*(en it clears both the
4174 .It Ic shift Op Ar number
4175 The positional parameters
4185 .It Ic sleep Ar seconds
4186 Suspends execution for a minimum of the
4188 specified as positive decimal value with an optional fractional part.
4189 Signal delivery may continue execution earlier.
4191 .It Ic source Ar file Op Ar arg ...
4193 .Ic \&. Po Do dot Dc Pc ,
4194 except that the current working directory is appended to the
4204 this is implemented as a shell alias instead of a builtin.
4206 .It Ic test Ar expression
4207 .It Ic \&[ Ar expression Ic \&]
4211 and returns zero status if true, 1 if false, or greater than 1 if there
4213 It is normally used as the condition command of
4218 Symbolic links are followed for all
4225 The following basic expressions are available:
4232 is a block special device.
4235 is a character special device.
4247 group is the shell's effective group ID.
4250 mode has the setgid bit set.
4253 is a context dependent directory (only useful on HP-UX).
4267 owner is the shell's effective user ID.
4273 command above for a list of options).
4274 As a non-standard extension, if the option starts with a
4276 the test is negated; the test always fails if
4278 doesn't exist (so [ \-o foo \-o \-o !foo ] returns true if and only if option
4281 The same can be achieved with [ \-o ?foo ] like in
4285 can also be the short flag led by either
4289 .Pq no logical negation ,
4301 exists and is readable.
4305 .Xr unix 4 Ns -domain
4318 mode has the setuid bit set.
4321 exists and is writable.
4324 exists and is executable.
4325 .It Ar file1 Fl nt Ar file2
4334 .It Ar file1 Fl ot Ar file2
4343 .It Ar file1 Fl ef Ar file2
4349 has non-zero length.
4356 .It Ar string No = Ar string
4358 .It Ar string No == Ar string
4360 .It Ar string No \*(Gt Ar string
4361 First string operand is greater than second string operand.
4362 .It Ar string No \*(Lt Ar string
4363 First string operand is less than second string operand.
4364 .It Ar string No != Ar string
4365 Strings are not equal.
4366 .It Ar number Fl eq Ar number
4367 Numbers compare equal.
4368 .It Ar number Fl ne Ar number
4369 Numbers compare not equal.
4370 .It Ar number Fl ge Ar number
4371 Numbers compare greater than or equal.
4372 .It Ar number Fl gt Ar number
4373 Numbers compare greater than.
4374 .It Ar number Fl le Ar number
4375 Numbers compare less than or equal.
4376 .It Ar number Fl \< Ar number
4377 Numbers compare less than.
4380 The above basic expressions, in which unary operators have precedence over
4381 binary operators, may be combined with the following operators (listed in
4382 increasing order of precedence):
4383 .Bd -literal -offset indent
4384 expr \-o expr Logical OR.
4385 expr \-a expr Logical AND.
4390 Note that a number actually may be an arithmetic expression, such as
4391 a mathematical term or the name of an integer variable:
4392 .Bd -literal -offset indent
4393 x=1; [ "x" \-eq 1 ] evaluates to true
4396 Note that some special rules are applied (courtesy of POSIX)
4402 is less than five: if leading
4404 arguments can be stripped such that only one argument remains then a string
4405 length test is performed (again, even if the argument is a unary operator); if
4408 arguments can be stripped such that three arguments remain and the second
4409 argument is a binary operator, then the binary operation is performed (even
4410 if the first argument is a unary operator, including an unstripped
4414 A common mistake is to use
4415 .Dq if \&[ $foo = bar \&]
4416 which fails if parameter
4420 or unset, if it has embedded spaces (i.e.\&
4422 octets), or if it is a unary operator like
4427 .Dq if \&[ x\&"$foo\&" = x"bar" \&]
4428 instead, or the double-bracket operator
4429 .Dq if \&[[ $foo = bar \&]]
4430 or, to avoid pattern matching (see
4433 .Dq if \&[[ $foo = "$bar" \&]]
4442 is given, the times used to execute the pipeline are reported.
4444 is given, then the user and system time used by the shell itself, and all the
4445 commands it has run since it was started, are reported.
4446 The times reported are the real time (elapsed time from start to finish),
4447 the user CPU time (time spent running in user mode), and the system CPU time
4448 (time spent running in kernel mode).
4449 Times are reported to standard error; the format of the output is:
4451 .Dl "0m0.00s real 0m0.00s user 0m0.00s system"
4455 option is given the output is slightly longer:
4456 .Bd -literal -offset indent
4462 It is an error to specify the
4466 is a simple command.
4468 Simple redirections of standard error do not affect the output of the
4472 .Dl $ time sleep 1 2\*(Gtafile
4473 .Dl $ { time sleep 1; } 2\*(Gtafile
4475 Times for the first command do not go to
4477 but those of the second command do.
4480 Print the accumulated user and system times used both by the shell
4481 and by processes that the shell started which have exited.
4482 The format of the output is:
4483 .Bd -literal -offset indent
4488 .It Ic trap Op Ar handler signal ...
4489 Sets a trap handler that is to be executed when any of the specified signals are
4494 string, indicating the signals are to be ignored, a minus sign
4496 indicating that the default action is to be taken for the signals (see
4498 or a string containing shell commands to be evaluated and executed at the first
4499 opportunity (i.e. when the current command completes, or before printing the
4502 prompt) after receipt of one of the signals.
4504 is the name of a signal (e.g.\&
4508 or the number of the signal (see the
4512 There are two special signals:
4514 (also known as 0) which is executed when the shell is about to exit, and
4516 which is executed after an error occurs (an error is something that would cause
4517 the shell to exit if the
4521 option were set \*(en see the
4525 handlers are executed in the environment of the last executed command.
4527 that for non-interactive shells, the trap handler cannot be changed for signals
4528 that were ignored when the shell started.
4532 lists, as a series of
4534 commands, the current state of the traps that have been set since the shell
4536 Note that the output of
4538 cannot be usefully piped to another process (an artifact of the fact that
4539 traps are cleared when subprocesses are created).
4541 The original Korn shell's
4543 trap and the handling of
4547 traps in functions are not yet implemented.
4550 A command that exits with a zero value.
4554 .Oo Op Ic +\-alpnrtUux
4559 .No \*(Ba Fl f Op Fl tux Oc
4561 .Op Ns = Ns Ar value
4566 .Oo Op Ic +\-alpnrtUux
4567 .Op Fl LRZ Ns Op Ar n
4569 .No \*(Ba Fl f Op Fl tux Oc
4571 .Op Ns = Ns Ar value
4574 Display or set parameter attributes.
4577 arguments, parameter attributes are displayed; if no options are used, the
4578 current attributes of all parameters are printed as
4580 commands; if an option is given (or
4582 with no option letter), all parameters and their values with the specified
4583 attributes are printed; if options are introduced with
4585 parameter values are not printed.
4589 arguments are given, the attributes of the named parameters are set
4593 Values for parameters may optionally be specified.
4596 the change affects the entire array, and no value may be specified.
4600 is used inside a function, any parameters specified are localised.
4601 This is not done by the otherwise identical
4608 operates on the attributes of functions.
4609 As with parameters, if no
4611 arguments are given,
4612 functions are listed with their values (i.e. definitions) unless
4613 options are introduced with
4615 in which case only the function names are reported.
4618 Indexed array attribute.
4621 Display or set functions and their attributes, instead of parameters.
4625 specifies the base to use when displaying the integer (if not specified, the
4626 base given in the first assignment is used).
4627 Parameters with this attribute may
4628 be assigned values containing arithmetic expressions.
4630 Left justify attribute.
4632 specifies the field width.
4635 is not specified, the current width of a parameter (or the width of its first
4636 assigned value) is used.
4637 Leading whitespace (and zeros, if used with the
4639 option) is stripped.
4640 If necessary, values are either truncated or space padded
4641 to fit the field width.
4643 Lower case attribute.
4644 All upper case characters in values are converted to lower case.
4645 (In the original Korn shell, this parameter meant
4651 Create a bound variable (name reference): any access to the variable
4653 will access the variable
4655 in the current scope (this is different from
4664 is lazily evaluated at the time
4667 This can be used by functions to access variables whose names are
4668 passed as parametres, instead of using
4673 commands that can be used to re-create the attributes and values of
4676 Right justify attribute.
4678 specifies the field width.
4681 is not specified, the current width of a parameter (or the width of its first
4682 assigned value) is used.
4683 Trailing whitespace is stripped.
4684 If necessary, values are either stripped of leading characters or space
4685 padded to make them fit the field width.
4687 Read-only attribute.
4688 Parameters with this attribute may not be assigned to or unset.
4689 Once this attribute is set, it cannot be turned off.
4692 Has no meaning to the shell; provided for application use.
4696 is the trace attribute.
4697 When functions with the trace attribute are executed, the
4700 shell option is temporarily turned on.
4702 Unsigned integer attribute.
4703 Integers are printed as unsigned values (combine with the
4706 This option is not in the original Korn shell.
4708 Upper case attribute.
4709 All lower case characters in values are converted to upper case.
4710 (In the original Korn shell, this parameter meant
4711 .Dq unsigned integer
4714 option which meant upper case letters would never be used for bases greater
4722 is the undefined attribute.
4725 above for the implications of this.
4728 Parameters (or functions) are placed in the environment of
4729 any executed commands.
4730 Exported functions are not yet implemented.
4732 Zero fill attribute.
4733 If not combined with
4737 except zero padding is used instead of space padding.
4738 For integers, the number instead of the base is padded.
4751 options are changed, all others from this set are cleared,
4752 unless they are also given on the same command line.
4756 .Op Fl aBCcdefHiLlMmnOPpqrSsTtVvw
4759 Display or set process limits.
4760 If no options are used, the file size limit
4764 if specified, may be either an arithmetic expression or the word
4766 The limits affect the shell and any processes created by the shell after a
4768 Note that some systems may not allow limits to be increased
4770 Also note that the types of limits available are system
4771 dependent \*(en some systems have only the
4776 Display all limits; unless
4778 is used, soft limits are displayed.
4780 Set the socket buffer size to
4784 Set the number of cached threads to
4787 Impose a size limit of
4789 blocks on the size of core dumps.
4791 Impose a size limit of
4793 kibibytes on the size of the data area.
4795 Set the maximum niceness to
4798 Impose a size limit of
4800 blocks on files written by the shell and its child processes (files of any
4803 Set the hard limit only (the default is to set both hard and soft limits).
4805 Set the number of pending signals to
4808 Control flocks; documentation is missing.
4812 kibibytes on the amount of locked (wired) physical memory.
4814 Set the AIO locked memory to
4820 kibibytes on the amount of physical memory used.
4824 file descriptors that can be open at once.
4826 Set the number of AIO operations to
4829 Limit the number of threads per process to
4834 processes that can be run by the user at any one time.
4842 Set the maximum real-time priority to
4845 Set the soft limit only (the default is to set both hard and soft limits).
4847 Impose a size limit of
4849 kibibytes on the size of the stack area.
4851 Impose a time limit of
4853 real seconds to be used by each process.
4855 Impose a time limit of
4857 CPU seconds spent in user mode to be used by each process.
4859 Set the number of vnode monitors on Haiku to
4864 kibibytes on the amount of virtual memory (address space) used.
4868 kibibytes on the amount of swap space used.
4873 is concerned, a block is 512 bytes.
4880 Display or set the file permission creation mask, or umask (see
4884 option is used, the mask displayed or set is symbolic; otherwise, it is an
4887 Symbolic masks are like those used by
4889 When used, they describe what permissions may be made available (as opposed to
4890 octal masks in which a set bit means the corresponding bit is to be cleared).
4893 sets the mask so files will not be readable, writable, or executable by
4895 and is equivalent (on most systems) to the octal mask
4903 The aliases for the given names are removed.
4906 option is used, all aliases are removed.
4911 options are used, the indicated operations are carried out on tracked or
4912 directory aliases, respectively.
4919 Unset the named parameters
4927 .Ar parameter Ns \&[*] ,
4928 attributes are kept, only values are unset.
4930 The exit status is non-zero if any of the parameters have the read-only
4931 attribute set, zero otherwise.
4933 .It Ic wait Op Ar job ...
4934 Wait for the specified job(s) to finish.
4937 is that of the last specified job; if the last job is killed by a signal, the
4938 exit status is 128 + the number of the signal (see
4939 .Ic kill \-l Ar exit-status
4940 above); if the last specified job can't be found (because it never existed, or
4941 had already finished), the exit status of
4946 below for the format of
4949 will return if a signal for which a trap has been set is received, or if a
4956 If no jobs are specified,
4958 waits for all currently running jobs (if any) to finish and exits with a zero
4960 If job monitoring is enabled, the completion status of jobs is printed
4961 (this is not the case when jobs are explicitly specified).
4970 the type of command is listed (reserved word, built-in, alias,
4971 function, tracked alias, or executable).
4974 option is used, a path search is performed even if
4976 is a reserved word, alias, etc.
4985 will find reserved words and won't print aliases as alias commands.
4996 option does not affect the search path used, as it does for
4998 If the type of one or more of the names could not be determined, the exit
5002 Job control refers to the shell's ability to monitor and control jobs which
5003 are processes or groups of processes created for commands or pipelines.
5004 At a minimum, the shell keeps track of the status of the background (i.e.\&
5005 asynchronous) jobs that currently exist; this information can be displayed
5009 If job control is fully enabled (using
5012 .Ic set \-o monitor ) ,
5013 as it is for interactive shells, the processes of a job are placed in their
5015 Foreground jobs can be stopped by typing the suspend
5016 character from the terminal (normally \*(haZ), jobs can be restarted in either the
5017 foreground or background using the
5021 commands, and the state of the terminal is saved or restored when a foreground
5022 job is stopped or restarted, respectively.
5024 Note that only commands that create processes (e.g. asynchronous commands,
5025 subshell commands, and non-built-in, non-function commands) can be stopped;
5030 When a job is created, it is assigned a job number.
5031 For interactive shells, this number is printed inside
5033 followed by the process IDs of the processes in the job when an asynchronous
5035 A job may be referred to in the
5042 commands either by the process ID of the last process in the command pipeline
5045 parameter) or by prefixing the job number with a percent
5048 Other percent sequences can also be used to refer to jobs:
5049 .Bl -tag -width "%+ x %% x %XX"
5050 .It %+ \*(Ba %% \*(Ba %
5051 The most recently stopped job, or, if there are no stopped jobs, the oldest
5054 The job that would be the
5056 job if the latter did not exist.
5058 The job with job number
5061 The job with its command containing the string
5063 (an error occurs if multiple jobs are matched).
5065 The job with its command starting with the string
5067 (an error occurs if multiple jobs are matched).
5070 When a job changes state (e.g. a background job finishes or foreground job is
5071 stopped), the shell prints the following status information:
5073 .D1 [ Ns Ar number ] Ar flag status command
5076 .Bl -tag -width "command"
5078 is the job number of the job;
5084 character if the job is the
5088 job, respectively, or space if it is neither;
5090 indicates the current state of the job and can be:
5091 .Bl -tag -width "RunningXX"
5092 .It Done Op Ar number
5095 is the exit status of the job which is omitted if the status is zero.
5097 The job has neither stopped nor exited (note that running does not necessarily
5098 mean consuming CPU time \*(en
5099 the process could be blocked waiting for some event).
5100 .It Stopped Op Ar signal
5101 The job was stopped by the indicated
5103 (if no signal is given, the job was stopped by
5105 .It Ar signal-description Op Dq core dumped
5106 The job was killed by a signal (e.g. memory fault, hangup); use
5108 for a list of signal descriptions.
5111 message indicates the process created a core file.
5114 is the command that created the process.
5115 If there are multiple processes in
5116 the job, each process will have a line showing its
5120 if it is different from the status of the previous process.
5123 When an attempt is made to exit the shell while there are jobs in the stopped
5124 state, the shell warns the user that there are stopped jobs and does not exit.
5125 If another attempt is immediately made to exit the shell, the stopped jobs are
5128 signal and the shell exits.
5131 option is not set and there are running jobs when an attempt is made to exit
5132 a login shell, the shell warns the user and does not exit.
5134 is immediately made to exit the shell, the running jobs are sent a
5136 signal and the shell exits.
5137 .Ss Interactive input line editing
5138 The shell supports three modes of reading command lines from a
5140 in an interactive session, controlled by the
5145 options (at most one of these can be set at once).
5148 Editing modes can be set explicitly using the
5151 If none of these options are enabled,
5152 the shell simply reads lines using the normal
5159 option is set, the shell allows emacs-like editing of the command; similarly,
5162 option is set, the shell allows vi-like editing of the command.
5163 These modes are described in detail in the following sections.
5165 In these editing modes, if a line is longer than the screen width (see the
5173 character is displayed in the last column indicating that there are more
5174 characters after, before and after, or before the current position,
5176 The line is scrolled horizontally as necessary.
5178 Completed lines are pushed into the history, unless they begin with an
5179 IFS octet or IFS white space, or are the same as the previous line.
5180 .Ss Emacs editing mode
5183 option is set, interactive input line editing is enabled.
5184 Warning: This mode is
5185 slightly different from the emacs mode in the original Korn shell.
5186 In this mode, various editing commands
5187 (typically bound to one or more control characters) cause immediate actions
5188 without waiting for a newline.
5189 Several editing commands are bound to particular
5190 control characters when the shell is invoked; these bindings can be changed
5195 The following is a list of available editing commands.
5196 Each description starts with the name of the command,
5197 suffixed with a colon;
5200 (if the command can be prefixed with a count); and any keys the command is
5201 bound to by default, written using caret notation
5202 e.g. the ASCII ESC character is written as \*(ha[.
5203 These control sequences are not case sensitive.
5204 A count prefix for a command is entered using the sequence
5205 .Pf \*(ha[ Ns Ar n ,
5208 is a sequence of 1 or more digits.
5209 Unless otherwise specified, if a count is
5210 omitted, it defaults to 1.
5212 Note that editing command names are used only with the
5215 Furthermore, many editing commands are useful only on terminals with
5217 The default bindings were chosen to resemble corresponding
5224 reasonable substitutes and override the default bindings.
5226 .It abort: \*(haC, \*(haG
5227 Abort the current command, empty the line buffer and
5228 set the exit state to interrupted.
5229 .It auto\-insert: Op Ar n
5230 Simply causes the character to appear as literal input.
5231 Most ordinary characters are bound to this.
5232 .It Xo backward\-char:
5234 .No \*(haB , \*(haXD , ANSI-CurLeft
5236 Moves the cursor backward
5239 .It Xo backward\-word:
5241 .No \*(ha[b , ANSI-Ctrl-CurLeft , ANSI-Alt-CurLeft
5243 Moves the cursor backward to the beginning of the word; words consist of
5244 alphanumerics, underscore
5249 .It beginning\-of\-history: \*(ha[\*(Lt
5250 Moves to the beginning of the history.
5251 .It beginning\-of\-line: \*(haA, ANSI-Home
5252 Moves the cursor to the beginning of the edited input line.
5253 .It Xo capitalise\-word:
5255 .No \*(ha[C , \*(ha[c
5257 Uppercase the first character in the next
5259 words, leaving the cursor past the end of the last word.
5260 .It clear\-screen: \*(ha[\*(haL
5261 Prints a compile-time configurable sequence to clear the screen and home
5262 the cursor, redraws the entire prompt and the currently edited input line.
5263 The default sequence works for almost all standard terminals.
5264 .It comment: \*(ha[#
5265 If the current line does not begin with a comment character, one is added at
5266 the beginning of the line and the line is entered (as if return had been
5267 pressed); otherwise, the existing comment characters are removed and the cursor
5268 is placed at the beginning of the line.
5269 .It complete: \*(ha[\*(ha[
5270 Automatically completes as much as is unique of the command name or the file
5271 name containing the cursor.
5272 If the entire remaining command or file name is
5273 unique, a space is printed after its completion, unless it is a directory name
5277 If there is no command or file name with the current partial word
5278 as its prefix, a bell character is output (usually causing a beep to be
5280 .It complete\-command: \*(haX\*(ha[
5281 Automatically completes as much as is unique of the command name having the
5282 partial word up to the cursor as its prefix, as in the
5285 .It complete\-file: \*(ha[\*(haX
5286 Automatically completes as much as is unique of the file name having the
5287 partial word up to the cursor as its prefix, as in the
5289 command described above.
5290 .It complete\-list: \*(haI, \*(ha[=
5291 Complete as much as is possible of the current word,
5292 and list the possible completions for it.
5293 If only one completion is possible,
5297 Note that \*(haI is usually generated by the TAB (tabulator) key.
5298 .It Xo delete\-char\-backward:
5300 .No ERASE , \*(ha? , \*(haH
5304 characters before the cursor.
5305 .It Xo delete\-char\-forward:
5311 characters after the cursor.
5312 .It Xo delete\-word\-backward:
5314 .No WERASE , \*(ha[\*(ha? , \*(ha[\*(haH , \*(ha[h
5318 words before the cursor.
5319 .It Xo delete\-word\-forward:
5323 Deletes characters after the cursor up to the end of
5326 .It Xo down\-history:
5328 .No \*(haN , \*(haXB , ANSI-CurDown
5330 Scrolls the history buffer forward
5333 Each input line originally starts just after the last entry
5334 in the history buffer, so
5336 is not useful until either
5337 .Ic search\-history ,
5338 .Ic search\-history\-up
5342 .It Xo downcase\-word:
5344 .No \*(ha[L , \*(ha[l
5355 or the current line, if not specified, interactively.
5356 The actual command executed is
5357 .Ic fc \-e ${VISUAL:\-${EDITOR:\-vi}} Ar n .
5358 .It end\-of\-history: \*(ha[\*(Gt
5359 Moves to the end of the history.
5360 .It end\-of\-line: \*(haE, ANSI-End
5361 Moves the cursor to the end of the input line.
5363 Acts as an end-of-file; this is useful because edit-mode input disables
5364 normal terminal input canonicalization.
5365 .It Xo eot\-or\-delete:
5371 if alone on a line; otherwise acts as
5372 .Ic delete\-char\-forward .
5373 .It error: (not bound)
5374 Error (ring the bell).
5375 .It exchange\-point\-and\-mark: \*(haX\*(haX
5376 Places the cursor where the mark is and sets the mark to where the cursor was.
5377 .It expand\-file: \*(ha[*
5380 to the current word and replaces the word with the result of performing file
5381 globbing on the word.
5382 If no files match the pattern, the bell is rung.
5383 .It Xo forward\-char:
5385 .No \*(haF , \*(haXC , ANSI-CurRight
5387 Moves the cursor forward
5390 .It Xo forward\-word:
5392 .No \*(ha[f , ANSI-Ctrl-CurRight , ANSI-Alt-CurRight
5394 Moves the cursor forward to the end of the
5397 .It Xo goto\-history:
5401 Goes to history number
5403 .It kill\-line: KILL
5404 Deletes the entire input line.
5405 .It kill\-region: \*(haW
5406 Deletes the input between the cursor and the mark.
5407 .It Xo kill\-to\-eol:
5411 Deletes the input from the cursor to the end of the line if
5413 is not specified; otherwise deletes characters between the cursor and column
5416 Prints a sorted, columnated list of command names or file names (if any) that
5417 can complete the partial word containing the cursor.
5418 Directory names have
5421 .It list\-command: \*(haX?
5422 Prints a sorted, columnated list of command names (if any) that can complete
5423 the partial word containing the cursor.
5424 .It list\-file: \*(haX\*(haY
5425 Prints a sorted, columnated list of file names (if any) that can complete the
5426 partial word containing the cursor.
5427 File type indicators are appended as described under
5430 .It newline: \*(haJ , \*(haM
5431 Causes the current input line to be processed by the shell.
5432 The current cursor position may be anywhere on the line.
5433 .It newline\-and\-next: \*(haO
5434 Causes the current input line to be processed by the shell, and the next line
5435 from history becomes the current line.
5436 This is only useful after an
5440 .Ic search\-history\-up .
5443 .It prefix\-1: \*(ha[
5444 Introduces a 2-character command sequence.
5445 .It prefix\-2: \*(haX , \*(ha[[ , \*(ha[O
5446 Introduces a 2-character command sequence.
5447 .It Xo prev\-hist\-word:
5449 .No \*(ha[. , \*(ha[_
5451 The last word, or, if given, the
5453 word (zero-based) of the previous (on repeated execution, second-last,
5454 third-last, etc.) command is inserted at the cursor.
5455 Use of this editing command trashes the mark.
5456 .It quote: \*(ha\*(ha , \*(haV
5457 The following character is taken literally rather than as an editing command.
5459 Reprints the last line of the prompt string and the current input line
5461 .It Xo search\-character\-backward:
5465 Search backward in the current line for the
5467 occurrence of the next character typed.
5468 .It Xo search\-character\-forward:
5472 Search forward in the current line for the
5474 occurrence of the next character typed.
5475 .It search\-history: \*(haR
5476 Enter incremental search mode.
5477 The internal history list is searched
5478 backwards for commands matching the input.
5481 in the search string anchors the search.
5482 The escape key will leave search mode.
5483 Other commands, including sequences of escape as
5489 key will be executed after leaving search mode.
5492 command will restore the input line before search started.
5495 commands continue searching backward to the next previous occurrence of the
5497 The history buffer retains only a finite number of lines; the oldest
5498 are discarded as necessary.
5499 .It search\-history\-up: ANSI-PgUp
5500 Search backwards through the history buffer for commands whose beginning match
5501 the portion of the input line before the cursor.
5502 When used on an empty line, this has the same effect as
5504 .It search\-history\-down: ANSI-PgDn
5505 Search forwards through the history buffer for commands whose beginning match
5506 the portion of the input line before the cursor.
5507 When used on an empty line, this has the same effect as
5509 This is only useful after an
5513 .Ic search\-history\-up .
5514 .It set\-mark\-command: \*(ha[ Ns Aq space
5515 Set the mark at the cursor position.
5516 .It transpose\-chars: \*(haT
5517 If at the end of line, or if the
5519 option is set, this exchanges the two previous characters; otherwise, it
5520 exchanges the previous and current characters and moves the cursor one
5521 character to the right.
5524 .No \*(haP , \*(haXA , ANSI-CurUp
5526 Scrolls the history buffer backward
5529 .It Xo upcase\-word:
5531 .No \*(ha[U , \*(ha[u
5536 .It version: \*(ha[\*(haV
5537 Display the version of
5539 The current edit buffer is restored as soon as a key is pressed.
5540 The restoring keypress is processed, unless it is a space.
5542 Inserts the most recently killed text string at the current cursor position.
5543 .It yank\-pop: \*(ha[y
5546 replaces the inserted text string with the next previously killed text string.
5550 The vi command-line editing mode is orphaned, yet still functional.
5552 The vi command-line editor in
5554 has basically the same commands as the
5556 editor with the following exceptions:
5559 You start out in insert mode.
5561 There are file name and command completion commands:
5562 =, \e, *, \*(haX, \*(haE, \*(haF, and, optionally,
5569 command is different (in
5571 it is the last argument command; in
5573 it goes to the start of the current line).
5579 commands move in the opposite direction to the
5583 Commands which don't make sense in a single line editor are not available
5584 (e.g. screen movement commands and
5593 there are two modes:
5598 In insert mode, most characters are simply put in the buffer at the
5599 current cursor position as they are typed; however, some characters are
5601 In particular, the following characters are taken from current
5606 and have their usual meaning (normal values are in parentheses): kill (\*(haU),
5607 erase (\*(ha?), werase (\*(haW), eof (\*(haD), intr (\*(haC), and quit (\*(ha\e).
5609 the above, the following characters are also treated specially in insert mode:
5610 .Bl -tag -width XJXXXXM
5612 Command and file name enumeration (see below).
5614 Command and file name completion (see below).
5615 If used twice in a row, the
5616 list of possible completions is displayed; if used a third time, the completion
5619 Erases previous character.
5620 .It \*(haJ \*(Ba \*(haM
5622 The current line is read, parsed, and executed by the shell.
5625 The next character typed is not treated specially (can be used
5626 to insert the characters being described here).
5628 Command and file name expansion (see below).
5630 Puts the editor in command mode (see below).
5632 Optional file name and command completion (see
5634 above), enabled with
5635 .Ic set \-o vi\-tabcomplete .
5638 In command mode, each character is interpreted as a command.
5640 don't correspond to commands, are illegal combinations of commands, or are
5641 commands that can't be carried out, all cause beeps.
5642 In the following command descriptions, an
5644 indicates the command may be prefixed by a number (e.g.\&
5646 moves right 10 characters); if no number prefix is used,
5648 is assumed to be 1 unless otherwise specified.
5650 .Dq current position
5651 refers to the position between the cursor and the character preceding the
5655 is a sequence of letters, digits, and underscore characters or a sequence of
5656 non-letter, non-digit, non-underscore, and non-whitespace characters (e.g.\&
5658 contains two words) and a
5660 is a sequence of non-whitespace characters.
5666 The following commands are not in, or are different from, the normal vi file
5672 Insert a space followed by the
5674 big-word from the last command in the history at the current position and enter
5677 is not specified, the last word is inserted.
5679 Insert the comment character
5681 at the start of the current line and return the line to the shell (equivalent
5691 is not specified, it goes to the most recent remembered line.
5701 is not specified, the current line is edited.
5702 The actual command executed is
5703 .Ic fc \-e ${VISUAL:\-${EDITOR:\-vi}} Ar n .
5705 Command or file name expansion is applied to the current big-word (with an
5708 if the word contains no file globbing characters) \*(en the big-word is replaced
5709 with the resulting words.
5710 If the current big-word is the first on the line
5711 or follows one of the characters
5718 and does not contain a slash
5720 then command expansion is done; otherwise file name expansion is done.
5721 Command expansion will match the big-word against all aliases, functions, and
5722 built-in commands as well as any executable files found by searching the
5726 File name expansion matches the big-word against the files in the
5728 After expansion, the cursor is placed just past the last
5729 word and the editor is in insert mode.
5732 .Oo Ar n Oc Ns \*(haF ,
5733 .Oo Ar n Oc Ns Aq tab ,
5735 .Oo Ar n Oc Ns Aq esc
5737 Command/file name completion.
5738 Replace the current big-word with the
5739 longest unique match obtained after performing command and file name expansion.
5741 is only recognised if the
5743 option is set, while
5745 is only recognised if the
5753 possible completion is selected (as reported by the command/file name
5754 enumeration command).
5756 Command/file name enumeration.
5757 List all the commands or files that match the current big-word.
5759 Display the version of
5761 The current edit buffer is restored as soon as a key is pressed.
5762 The restoring keypress is ignored.
5765 Execute the commands found in the alias
5769 Intra-line movement commands:
5772 .Oo Ar n Oc Ns h and
5773 .Oo Ar n Oc Ns \*(haH
5779 .Oo Ar n Oc Ns l and
5780 .Oo Ar n Oc Ns Aq space
5788 Move to the first non-whitespace character.
5790 .Oo Ar n Oc Ns \*(Ba
5795 Move to the last character.
5811 Move forward to the end of the word,
5817 Move forward to the end of the big-word,
5834 The editor looks forward for the nearest parenthesis, bracket, or
5835 brace and then moves the cursor to the matching parenthesis, bracket, or brace.
5837 .Oo Ar n Oc Ns f Ns Ar c
5841 occurrence of the character
5844 .Oo Ar n Oc Ns F Ns Ar c
5846 Move backward to the
5848 occurrence of the character
5851 .Oo Ar n Oc Ns t Ns Ar c
5853 Move forward to just before the
5855 occurrence of the character
5858 .Oo Ar n Oc Ns T Ns Ar c
5860 Move backward to just before the
5862 occurrence of the character
5879 command, but moves in the opposite direction.
5882 Inter-line movement commands:
5888 .Oo Ar n Oc Ns \*(haN
5892 next line in the history.
5897 .Oo Ar n Oc Ns \*(haP
5901 previous line in the history.
5909 is not specified, the number of the first remembered line is used.
5917 is not specified, it goes to the most recent remembered line.
5919 .Oo Ar n Oc Ns / Ns Ar string
5921 Search backward through the history for the
5929 the remainder of the string must appear at the start of the history line for
5932 .Oo Ar n Oc Ns \&? Ns Ar string
5936 except it searches forward through the history.
5942 occurrence of the last search string;
5943 the direction of the search is the same as the last search.
5949 occurrence of the last search string;
5950 the direction of the search is the opposite of the last search.
5960 times; goes into insert mode just after the current position.
5962 only replicated if command mode is re-entered i.e.\&
5970 except it appends at the end of the line.
5976 times; goes into insert mode at the current position.
5977 The insertion is only
5978 replicated if command mode is re-entered i.e.\&
5986 except the insertion is done just before the first non-blank character.
5992 characters (i.e. delete the characters and go into insert mode).
5994 Substitute whole line.
5995 All characters from the first non-blank character to the
5996 end of the line are deleted and insert mode is entered.
5998 .Oo Ar n Oc Ns c Ns Ar move-cmd
6000 Change from the current position to the position resulting from
6002 (i.e. delete the indicated region and go into insert mode); if
6006 the line starting from the first non-blank character is changed.
6008 Change from the current position to the end of the line (i.e. delete to the
6009 end of the line and go into insert mode).
6023 Delete to the end of the line.
6025 .Oo Ar n Oc Ns d Ns Ar move-cmd
6027 Delete from the current position to the position resulting from
6028 .Ar n move-cmd Ns s ;
6030 is a movement command (see above) or
6032 in which case the current line is deleted.
6034 .Oo Ar n Oc Ns r Ns Ar c
6038 characters with the character
6044 Enter insert mode but overwrite existing characters instead of
6045 inserting before existing characters.
6046 The replacement is repeated
6050 .Oo Ar n Oc Ns \*(TI
6052 Change the case of the next
6056 .Oo Ar n Oc Ns y Ns Ar move-cmd
6058 Yank from the current position to the position resulting from
6060 into the yank buffer; if
6064 the whole line is yanked.
6066 Yank from the current position to the end of the line.
6070 Paste the contents of the yank buffer just after the current position,
6078 except the buffer is pasted at the current position.
6081 Miscellaneous vi commands
6083 .It \*(haJ and \*(haM
6084 The current line is read, parsed, and executed by the shell.
6085 .It \*(haL and \*(haR
6086 Redraw the current line.
6090 Redo the last edit command
6094 Undo the last edit command.
6096 Undo all changes that have been made to the current line.
6097 .It Ar intr No and Ar quit
6098 The interrupt and quit terminal characters cause the current line to be
6099 deleted and a new prompt to be printed.
6102 .Bl -tag -width XetcXsuid_profile -compact
6103 .It Pa \*(TI/.mkshrc
6104 User mkshrc profile (non-privileged interactive shells); see
6106 The location can be changed at compile time (for embedded systems);
6107 AOSP Android builds use
6108 .Pa /system/etc/mkshrc .
6109 .It Pa \*(TI/.profile
6110 User profile (non-privileged login shells); see
6112 near the top of this manual.
6114 System profile (login shells); see
6118 .It Pa /etc/suid_profile
6119 Suid profile (privileged shells); see
6125 contains the system and suid profile.
6157 .Pa http://docsrv.sco.com:507/en/man/html.C/sh.C.html
6160 .%B "The KornShell Command and Programming Language"
6162 .%I "Prentice Hall PTR"
6163 .%P "xvi\ +\ 356 pages"
6164 .%O "ISBN 978\-0\-13\-516972\-8 (0\-13\-516972\-0)"
6167 .%A Morris I. Bolsky
6169 .%B "The New KornShell Command and Programming Language (2nd Edition)"
6171 .%I "Prentice Hall PTR"
6172 .%P "xvi\ +\ 400 pages"
6173 .%O "ISBN 978\-0\-13\-182700\-4 (0\-13\-182700\-6)"
6176 .%A Stephen G. Kochan
6178 .%B "\\*(tNUNIX\\*(sP Shell Programming"
6179 .%V "Revised Edition"
6182 .%P "xi\ +\ 490 pages"
6183 .%O "ISBN 978\-0\-672\-48448\-3 (0\-672\-48448\-X)"
6187 .%B "\\*(tNIEEE\\*(sP Standard for Information Technology \*(en Portable Operating System Interface (POSIX)"
6188 .%V "Part 2: Shell and Utilities"
6191 .%P "xvii\ +\ 1195 pages"
6192 .%O "ISBN 978\-1\-55937\-255\-8 (1\-55937\-255\-9)"
6196 .%B "Learning the Korn Shell"
6200 .%O "ISBN 978\-1\-56592\-054\-5 (1\-56592\-054\-6)"
6205 .%B "Learning the Korn Shell, Second Edition"
6209 .%O "ISBN 978\-0\-596\-00195\-7 (0\-596\-00195\-9)"
6213 .%B "KornShell Programming Tutorial"
6215 .%I "Addison-Wesley Professional"
6216 .%P "xxi\ +\ 324 pages"
6217 .%O "ISBN 978\-0\-201\-56324\-5 (0\-201\-56324\-X)"
6220 .Nm "The MirBSD Korn Shell"
6222 .An Thorsten Glaser Aq tg@mirbsd.org
6223 and currently maintained as part of The MirOS Project.
6224 This shell is based upon the Public Domain Korn SHell.
6225 The developer of mksh recognises the efforts of the pdksh authors,
6226 who had dedicated their work into Public Domain, our users, and
6227 all contributors, such as the Debian and OpenBSD projects.
6229 .\" Charles Forsyth, author of the (Public Domain) Bourne Shell clone,
6230 .\" which mksh is derived from, agreed to the following:
6232 .\" In countries where the Public Domain status of the work may not be
6233 .\" valid, its primary author hereby grants a copyright licence to the
6234 .\" general public to deal in the work without restriction and permis-
6235 .\" sion to sublicence derivates under the terms of any (OSI approved)
6236 .\" Open Source licence.
6238 See the documentation, CVS, and web site for details.
6241 only supports the Unicode BMP (Basic Multilingual Plane).
6242 It has a different scope model from
6245 which leads to subtile differences in semantics for identical builtins.
6247 The parts of a pipeline, like below, are executed in subshells.
6248 Thus, variable assignments inside them fail.
6249 Use co-processes instead.
6250 .Bd -literal -offset indent
6251 foo \*(Ba bar \*(Ba read baz # will not change $baz
6252 foo \*(Ba bar \*(Ba& read \-p baz # will, however, do so
6255 Suspending (using \*(haZ) pipelines like the one below will only suspend
6256 the currently running part of the pipeline; in this example,
6258 is immediately printed on suspension (but not later after an
6260 .Bd -literal -offset indent
6261 $ /bin/sleep 666 && echo fubar
6264 This document attempts to describe
6267 compiled without any options impacting functionality, such as
6269 for an operating environment supporting all of its advanced needs.
6270 Please report bugs in
6275 .Aq miros\-discuss@mirbsd.org
6280 .Pa irc.freenode.net:6667 .