1 .\" $MirOS: src/bin/mksh/mksh.1,v 1.463 2019/03/01 16:17:31 tg Exp $
2 .\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $
4 .\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
5 .\" 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
7 .\" mirabilos <m@mirbsd.org>
9 .\" Provided that these terms and disclaimer and all copyright notices
10 .\" are retained or reproduced in an accompanying document, permission
11 .\" is granted to deal in this work without restriction, including un‐
12 .\" limited rights to use, publicly perform, distribute, sell, modify,
13 .\" merge, give away, or sublicence.
15 .\" This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
16 .\" the utmost extent permitted by applicable law, neither express nor
17 .\" implied; without malicious intent or gross negligence. In no event
18 .\" may a licensor, author or contributor be held liable for indirect,
19 .\" direct, other damage, loss, or other issues arising in any way out
20 .\" of dealing in the work, even if advised of the possibility of such
21 .\" damage or existence of a defect, except proven that it results out
22 .\" of said person’s immediate fault when using the work as intended.
24 .\" Try to make GNU groff and AT&T nroff more compatible
25 .\" * ` generates ‘ in gnroff, so use \`
26 .\" * ' generates ’ in gnroff, \' generates ´, so use \*(aq
27 .\" * - generates ‐ in gnroff, \- generates −, so .tr it to -
28 .\" thus use - for hyphens and \- for minus signs and option dashes
29 .\" * ~ is size-reduced and placed atop in groff, so use \*(TI
30 .\" * ^ is size-reduced and placed atop in groff, so use \*(ha
31 .\" * \(en does not work in nroff, so use \*(en
32 .\" * <>| are problematic, so redefine and use \*(Lt\*(Gt\*(Ba
33 .\" Also make sure to use \& *before* a punctuation char that is to not
34 .\" be interpreted as punctuation, and especially with two-letter words
35 .\" but also (after) a period that does not end a sentence (“e.g.\&”).
36 .\" The section after the "doc" macropackage has been loaded contains
37 .\" additional code to convene between the UCB mdoc macropackage (and
38 .\" its variant as BSD mdoc in groff) and the GNU mdoc macropackage.
41 . if
\ 1\*[.T]
\ 1ascii
\ 1 .tr \-\N'45'
42 . if
\ 1\*[.T]
\ 1latin1
\ 1 .tr \-\N'45'
43 . if
\ 1\*[.T]
\ 1utf8
\ 1 .tr \-\N'45'
50 . if
\ 1\*[.T]
\ 1utf8
\ 1 .ds sL `
51 . if
\ 1\*[.T]
\ 1ps
\ 1 .ds sL `
52 . if
\ 1\*[.T]
\ 1utf8
\ 1 .ds sR '
53 . if
\ 1\*[.T]
\ 1ps
\ 1 .ds sR '
66 .\" Implement .Dd with the Mdocdate RCS keyword
70 .ie
\a\\$1
\a$Mdocdate:
\a \{\
73 .el .xD \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8
76 .\" .Dd must come before definition of .Mx, because when called
77 .\" with -mandoc, it might implement .Mx itself, but we want to
78 .\" use our own definition. And .Dd must come *first*, always.
80 .Dd $Mdocdate: March 1 2019 $
82 .\" Check which macro package we use, and do other -mdoc setup.
85 . if
\ 1\*[.T]
\ 1utf8
\ 1 .tr \[la]\*(Lt
86 . if
\ 1\*[.T]
\ 1utf8
\ 1 .tr \[ra]\*(Gt
87 . ie d volume-ds-1 .ds tT gnu
88 . el .ie d doc-volume-ds-1 .ds tT gnp
93 .\" Implement .Mx (MirBSD)
99 . nr curr-size \n[.ps]
100 . ds str-Mx \f[\n[curr-font]]\s[\n[curr-size]u]
101 . ds str-Mx1 \*[Tn-font-size]\%MirBSD\*[str-Mx]
102 . if !\n[arg-limit] \
107 . if (\n[arg-limit] > \n[arg-ptr]) \{\
109 . ie (\n[type\n[arg-ptr]] == 2) \
110 . as str-Mx1 \~\*[arg\n[arg-ptr]]
114 . ds arg\n[arg-ptr] "\*[str-Mx1]
115 . nr type\n[arg-ptr] 2
116 . ds space\n[arg-ptr] "\*[space]
117 . nr num-args (\n[arg-limit] - \n[arg-ptr])
118 . nr arg-limit \n[arg-ptr]
125 . ds tN \*[Tn-font-size]
127 .el .ie "\*(tT"gnp" \{\
130 . nr doc-curr-font \n[.f]
131 . nr doc-curr-size \n[.ps]
132 . ds doc-str-Mx \f[\n[doc-curr-font]]\s[\n[doc-curr-size]u]
133 . ds doc-str-Mx1 \*[doc-Tn-font-size]\%MirBSD\*[doc-str-Mx]
134 . if !\n[doc-arg-limit] \
136 . ds doc-macro-name Mx
139 . if (\n[doc-arg-limit] > \n[doc-arg-ptr]) \{\
141 . ie (\n[doc-type\n[doc-arg-ptr]] == 2) \
142 . as doc-str-Mx1 \~\*[doc-arg\n[doc-arg-ptr]]
146 . ds doc-arg\n[doc-arg-ptr] "\*[doc-str-Mx1]
147 . nr doc-type\n[doc-arg-ptr] 2
148 . ds doc-space\n[doc-arg-ptr] "\*[doc-space]
149 . nr doc-num-args (\n[doc-arg-limit] - \n[doc-arg-ptr])
150 . nr doc-arg-limit \n[doc-arg-ptr]
151 . if \n[doc-num-args] \
152 . doc-parse-space-vector
153 . doc-print-recursive
157 . ds tN \*[doc-Tn-font-size]
163 . ds aa \&\f\\n(cF\s\\n(cZ
165 . ie \\n(.$==0 \&MirBSD\\*(aa
166 . el .aV \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
168 . if \\n(aC>\\n(aP \{\
170 . ie \\n(C\\n(aP==2 \{\
171 . as b1 \&MirBSD\ #\&\\*(A\\n(aP\\*(aa
172 . ie \\n(aC>\\n(aP \{\
179 . as b1 \&MirBSD\\*(aa
191 .Nd MirBSD Korn shell
195 .Op Fl +abCefhiklmnprUuvXx
197 .Fl T Oo Ar \&! Oc Ns Ar tty
203 .Fl c Ar string \*(Ba
213 is a command interpreter intended for both interactive and shell
215 Its command language is a superset of the
217 shell language and largely compatible to the original Korn shell.
218 At times, this manual page may give scripting advice; while it
219 sometimes does take portable shell scripting or various standards
220 into account all information is first and foremost presented with
222 in mind and should be taken as such.
223 .Ss I use Android, OS/2, etc. so what...?
224 Please see the FAQ at the end of this document.
226 Most builtins can be called directly, for example if a link points from its
227 name to the shell; not all make sense, have been tested or work at all though.
229 The options are as follows:
230 .Bl -tag -width XcXstring
233 will execute the command(s) contained in
237 A shell that reads commands from standard input is
240 option is used or if both standard input and standard error are attached
243 An interactive shell has job control enabled, ignores the
248 signals, and prints prompts before reading input (see the
253 It also processes the
258 For non-interactive shells, the
260 option is on by default (see the
265 If the basename the shell is called with (i.e. argv[0])
268 or if this option is used,
269 the shell is assumed to be a login shell; see
276 if the real user ID or group ID does not match the
277 effective user ID or group ID (see
281 Clearing the privileged option causes the shell to set
282 its effective user ID (group ID) to its real user ID (group ID).
283 For further implications, see
285 If the shell is privileged and this flag is not explicitly set, the
287 option is cleared automatically after processing the startup files.
294 The following restrictions come into effect after the shell processes any
311 parameters cannot be changed.
313 Command names can't be specified with absolute or relative paths.
317 option of the built-in command
321 Redirections that create files can't be used (i.e.\&
325 .Dq Li \*(Lt\*(Gt ) .
328 The shell reads commands from standard input; all non-option arguments
329 are positional parameters.
338 .Pa /dev/ttyC Ns Ar name
340 .Pa /dev/tty Ns Ar name
341 are attempted in order.
344 begins with an exclamation mark
346 this is done in a subshell and returns immediately.
351 detach from controlling terminal (daemonise) instead.
354 In addition to the above, the options described in the
356 built-in command can also be used on the command line:
358 .Op Fl +abCefhkmnuvXx
361 can be used for single letter or long options, respectively.
367 option is specified, the first non-option argument specifies the name
368 of a file the shell reads commands from.
369 If there are no non-option
370 arguments, the shell reads commands from the standard input.
371 The name of the shell (i.e. the contents of $0)
372 is determined as follows: if the
374 option is used and there is a non-option argument, it is used as the name;
375 if commands are being read from a file, the file is used as the name;
376 otherwise, the basename the shell was called with (i.e. argv[0]) is used.
378 The exit status of the shell is 127 if the command file specified on the
379 command line could not be opened, or non-zero if a fatal syntax error
380 occurred during the execution of a script.
381 In the absence of fatal errors,
382 the exit status is that of the last command executed, or zero if no
385 For the actual location of these files, see
387 A login shell processes the system profile first.
388 A privileged shell then processes the suid profile.
389 A non-privileged login shell processes the user profile next.
390 A non-privileged interactive shell checks the value of the
392 parameter after subjecting it to parameter, command, arithmetic and tilde
394 substitution; if unset or empty, the user mkshrc profile is processed;
395 otherwise, if a file whose name is the substitution result exists,
396 it is processed; non-existence is silently ignored.
397 A privileged shell then drops privileges if neither was the
399 option given on the command line nor set during execution of the startup files.
401 The shell begins parsing its input by removing any backslash-newline
402 combinations, then breaking it into
404 Words (which are sequences of characters) are delimited by unquoted whitespace
405 characters (space, tab and newline) or meta-characters
416 Aside from delimiting words, spaces and tabs are ignored, while newlines
417 usually delimit commands.
418 The meta-characters are used in building the following
423 .Dq Li \*(Lt\*(Lt\*(Lt ,
428 etc. are used to specify redirections (see
429 .Sx Input/output redirection
432 is used to create pipelines;
434 is used to create co-processes (see
438 is used to separate commands;
440 is used to create asynchronous pipelines;
444 are used to specify conditional execution;
453 is used in arithmetic expressions;
456 is used to create subshells.
458 Whitespace and meta-characters can be quoted individually using a backslash
460 or in groups using double
465 Note that the following characters are also treated specially by the
466 shell and must be quoted if they are to represent themselves:
480 The first three of these are the above mentioned quoting characters (see
484 if used at the beginning of a word, introduces a comment \*(en everything after
487 up to the nearest newline is ignored;
489 is used to introduce parameter, command and arithmetic substitutions (see
493 introduces an old-style command substitution (see
497 begins a directory expansion (see
513 are used in file name generation (see
514 .Sx File name patterns
517 As words and tokens are parsed, the shell builds commands, of which there
519 .Em simple-commands ,
520 typically programmes that are executed, and
521 .Em compound-commands ,
526 statements, grouping constructs and function definitions.
528 A simple-command consists of some combination of parameter assignments
532 input/output redirections (see
533 .Sx Input/output redirections
535 and command words; the only restriction is that parameter assignments come
536 before any command words.
537 The command words, if any, define the command
538 that is to be executed and its arguments.
539 The command may be a shell built-in command, a function
540 or an external command
541 (i.e. a separate executable file that is located using the
544 .Sx Command execution
546 Note that all command constructs have an exit status: for external commands,
547 this is related to the status returned by
549 (if the command could not be found, the exit status is 127; if it could not
550 be executed, the exit status is 126); the exit status of other command
551 constructs (built-in commands, functions, compound-commands, pipelines, lists,
552 etc.) are all well-defined and are described where the construct is
554 The exit status of a command consisting only of parameter
555 assignments is that of the last command substitution performed during the
556 parameter assignment or 0 if there were no command substitutions.
558 Commands can be chained together using the
560 token to form pipelines, in which the standard output of each command but the
563 to the standard input of the following command.
564 The exit status of a pipeline is that of its last command, unless the
566 option is set (see there).
567 All commands of a pipeline are executed in separate subshells;
568 this is allowed by POSIX but differs from both variants of
571 where all but the last command were executed in subshells; see the
573 builtin's description for implications and workarounds.
574 A pipeline may be prefixed by the
576 reserved word which causes the exit status of the pipeline to be logically
577 complemented: if the original status was 0, the complemented status will be 1;
578 if the original status was not 0, the complemented status will be 0.
581 of commands can be created by separating pipelines by any of the following
589 The first two are for conditional execution:
590 .Dq Ar cmd1 No && Ar cmd2
593 only if the exit status of
597 is the opposite \*(en
599 is executed only if the exit status of
605 have equal precedence which is higher than that of
610 which also have equal precedence.
616 .Qq left-associative .
617 For example, both of these commands will print only
619 .Bd -literal -offset indent
620 $ false && echo foo \*(Ba\*(Ba echo bar
621 $ true \*(Ba\*(Ba echo foo && echo bar
626 token causes the preceding command to be executed asynchronously; that is,
627 the shell starts the command but does not wait for it to complete (the shell
628 does keep track of the status of asynchronous commands; see
631 When an asynchronous command is started when job control is disabled
632 (i.e. in most scripts), the command is started with signals
636 ignored and with input redirected from
638 (however, redirections specified in the asynchronous command have precedence).
641 operator starts a co-process which is a special kind of asynchronous process
645 Note that a command must follow the
649 operators, while it need not follow
654 The exit status of a list is that of the last command executed, with the
655 exception of asynchronous lists, for which the exit status is 0.
657 Compound commands are created using the following reserved words.
659 are only recognised if they are unquoted and if they are used as the first
660 word of a command (i.e. they can't be preceded by parameter assignments or
662 .Bd -literal -offset indent
663 case else function then ! (
664 do esac if time [[ ((
666 elif for select while }
669 In the following compound command descriptions, command lists (denoted as
671 that are followed by reserved words must end with a semicolon, a newline or
672 a (syntactically correct) reserved word.
673 For example, the following are all valid:
674 .Bd -literal -offset indent
675 $ { echo foo; echo bar; }
676 $ { echo foo; echo bar\*(Ltnewline\*(Gt}
677 $ { { echo foo; echo bar; } }
682 .Dl $ { echo foo; echo bar }
688 There is no implicit way to pass environment changes from a
689 subshell back to its parent.
693 is executed, but not in a subshell.
698 are reserved words, not meta-characters.
699 .It Xo case Ar word No in
710 statement attempts to match
716 associated with the first successfully matched pattern is executed.
719 statements are the same as those used for file name patterns except that the
720 restrictions regarding
725 Note that any unquoted space before and after a pattern is
726 stripped; any space within a pattern must be quoted.
727 Both the word and the
728 patterns are subject to parameter, command and arithmetic substitution, as
729 well as tilde substitution.
731 For historical reasons, open and close braces may be used instead of
736 .Ic case $foo { *) echo bar ;; } .
743 Terminate after the list.
745 Fall through into the next list.
747 Evaluate the remaining pattern-list tuples.
752 statement is that of the executed
756 is executed, the exit status is zero.
758 .Oo in Ar word No ... Oc ;
759 .No do Ar list ; No done
763 in the specified word list, the parameter
765 is set to the word and
770 is not used to specify a word list, the positional parameters ($1, $2,
771 etc.) are used instead.
772 For historical reasons, open and close braces may be used instead of
777 .Ic for i; { echo $i; } .
780 statement is the last exit status of
784 is never executed, the exit status is zero.
788 .No then Ar list ; Oc
790 .Oo else Ar list ; Oc
793 If the exit status of the first
797 is executed; otherwise, the
801 if any, is executed with similar consequences.
802 If all the lists following the
806 fail (i.e. exit with non-zero status), the
811 The exit status of an
813 statement is that of non-conditional
815 that is executed; if no non-conditional
817 is executed, the exit status is zero.
818 .It Xo select Ar name
819 .Oo in Ar word No ... Oc ;
820 .No do Ar list ; No done
824 statement provides an automatic method of presenting the user with a menu and
826 An enumerated list of the specified
828 is printed on standard error, followed by a prompt
834 A number corresponding to one of the enumerated words is then read from
837 is set to the selected word (or unset if the selection is not valid),
839 is set to what was read (leading/trailing space is stripped), and
842 If a blank line (i.e. zero or more
844 octets) is entered, the menu is reprinted without executing
849 completes, the enumerated list is printed if
851 is empty, the prompt is printed, and so on.
852 This process continues until an end-of-file
853 is read, an interrupt is received, or a
855 statement is executed inside the loop.
858 is omitted, the positional parameters are used
860 For historical reasons, open and close braces may be used instead of
865 .Ic select i; { echo $i; } .
868 statement is zero if a
870 statement is used to exit the loop, non-zero otherwise.
871 .It Xo until Ar list ;
877 except that the body is executed only while the exit status of the first
880 .It Xo while Ar list ;
886 is a pre-checked loop.
887 Its body is executed as often as the exit status of the first
892 statement is the last exit status of the
894 in the body of the loop; if the body is not executed, the exit status is zero.
895 .It Xo function Ar name
903 Note that redirections specified after a function definition are
904 performed whenever the function is executed, not when the function definition
906 .It Ar name Ns \&() Ar command
912 Whitespace (space or tab) after
914 will be ignored most of the time.
915 .It Xo function Ar name Ns \&()
924 .It Xo Ic time Op Fl p
928 .Sx Command execution
929 section describes the
932 .It \&(( Ar expression No ))
933 The arithmetic expression
935 is evaluated; equivalent to
936 .Dq Li let \&" Ns Ar expression Ns \&"
938 .Sx Arithmetic expressions
941 command, below) in a compound construct.
942 .It Bq Bq Ar \ \&expression\ \&
947 commands (described later), with the following exceptions:
950 Field splitting and file name generation are not performed on arguments.
958 operators are replaced with
970 Parameter, command and arithmetic substitutions are performed as expressions
971 are evaluated and lazy expression evaluation is used for the
976 This means that in the following statement,
978 is evaluated if and only if the file
980 exists and is readable:
981 .Bd -literal -offset indent
982 $ [[ \-r foo && $(\*(Ltfoo) = b*r ]]
985 The second operand of the
989 expressions are a subset of patterns (e.g. the comparison
990 .Ic \&[[ foobar = f*r ]]
992 This even works indirectly:
993 .Bd -literal -offset indent
994 $ bar=foobar; baz=\*(aqf*r\*(aq
995 $ [[ $bar = $baz ]]; echo $?
996 $ [[ $bar = \&"$baz" ]]; echo $?
999 Perhaps surprisingly, the first comparison succeeds,
1000 whereas the second doesn't.
1001 This does not apply to all extglob metacharacters, currently.
1005 Quoting is used to prevent the shell from treating characters or words
1007 There are three methods of quoting.
1010 quotes the following character, unless it is at the end of a line, in which
1013 and the newline are stripped.
1014 Second, a single quote
1016 quotes everything up to the next single quote (this may span lines).
1017 Third, a double quote
1019 quotes all characters, except
1024 up to the next unescaped double quote.
1028 inside double quotes have their usual meaning (i.e. parameter, arithmetic
1029 or command substitution) except no field splitting is carried out on the
1030 results of double-quoted substitutions, and the old-style form of command
1031 substitution has backslash-quoting for double quotes enabled.
1034 inside a double-quoted string is followed by
1042 is removed, i.e. the combination is replaced by the second character;
1043 if it is followed by a newline, both the
1045 and the newline are stripped; otherwise, both the
1047 and the character following are unchanged.
1049 If a single-quoted string is preceded by an unquoted
1051 C style backslash expansion (see below) is applied (even single quote
1052 characters inside can be escaped and do not terminate the string then);
1053 the expanded result is treated as any other single-quoted string.
1054 If a double-quoted string is preceded by an unquoted
1059 .Ss Backslash expansion
1060 In places where backslashes are expanded, certain C and
1065 style escapes are translated.
1073 .Dq Li \eU######## ,
1082 means a hexadecimal digit, of which there may be none up to four or eight;
1083 these escapes translate a Universal Coded Character Set codepoint to UTF-8.
1088 expand to the escape character.
1097 are explicitly excluded;
1098 octal sequences must have the none up to three octal digits
1100 prefixed with the digit zero
1102 hexadecimal sequences
1104 are limited to none up to two hexadecimal digits
1106 both octal and hexadecimal sequences convert to raw octets;
1108 where # is none of the above, translates to \e# (backslashes are retained).
1110 Backslash expansion in the C style mode slightly differs: octal sequences
1112 must have no digit zero prefixing the one up to three octal digits
1114 and yield raw octets; hexadecimal sequences
1116 greedily eat up as many hexadecimal digits
1118 as they can and terminate with the first non-hexadecimal digit;
1119 these translate a Universal Coded Character Set codepoint to UTF-8.
1124 is any octet, translates to Ctrl-# (which basically means,
1126 becomes DEL, everything else is bitwise ANDed with 0x1F).
1129 where # is none of the above, translates to # (has the backslash trimmed),
1130 even if it is a newline.
1132 There are two types of aliases: normal command aliases and tracked aliases.
1133 Command aliases are normally used as a short hand for a long or often used
1135 The shell expands command aliases (i.e. substitutes the alias name
1136 for its value) when it reads the first word of a command.
1137 An expanded alias is re-processed to check for more aliases.
1138 If a command alias ends in a
1139 space or tab, the following word is also checked for alias expansion.
1140 The alias expansion process stops when a word that is not an alias is found,
1141 when a quoted word is found, or when an alias word that is currently being
1143 Aliases are specifically an interactive feature: while they do happen
1144 to work in scripts and on the command line in some cases, aliases are
1145 expanded during lexing, so their use must be in a separate command tree
1146 from their definition; otherwise, the alias will not be found.
1147 Noticeably, command lists (separated by semicolon, in command substitutions
1148 also by newline) may be one same parse tree.
1150 The following command aliases are defined automatically by the shell:
1151 .Bd -literal -offset indent
1152 autoload=\*(aq\e\ebuiltin typeset \-fu\*(aq
1153 functions=\*(aq\e\ebuiltin typeset \-f\*(aq
1154 hash=\*(aq\e\ebuiltin alias \-t\*(aq
1155 history=\*(aq\e\ebuiltin fc \-l\*(aq
1156 integer=\*(aq\e\ebuiltin typeset \-i\*(aq
1157 local=\*(aq\e\ebuiltin typeset\*(aq
1158 login=\*(aq\e\ebuiltin exec login\*(aq
1159 nameref=\*(aq\e\ebuiltin typeset \-n\*(aq
1160 nohup=\*(aqnohup \*(aq
1161 r=\*(aq\e\ebuiltin fc \-e \-\*(aq
1162 type=\*(aq\e\ebuiltin whence \-v\*(aq
1165 Tracked aliases allow the shell to remember where it found a particular
1167 The first time the shell does a path search for a command that is
1168 marked as a tracked alias, it saves the full path of the command.
1170 time the command is executed, the shell checks the saved path to see that it
1171 is still valid, and if so, avoids repeating the path search.
1172 Tracked aliases can be listed and created using
1174 Note that changing the
1176 parameter clears the saved paths for all tracked aliases.
1179 option is set (i.e.\&
1180 .Ic set Fl o Ic trackall
1183 the shell tracks all commands.
1184 This option is set automatically for non-interactive shells.
1185 For interactive shells, only the following commands are
1186 automatically tracked:
1206 The first step the shell takes in executing a simple-command is to perform
1207 substitutions on the words of the command.
1208 There are three kinds of
1209 substitution: parameter, command and arithmetic.
1210 Parameter substitutions,
1211 which are described in detail in the next section, take the form
1214 .Pf ${ Ns Ar ... Ns } ;
1215 command substitutions take the form
1216 .Pf $( Ns Ar command Ns \&)
1218 .Pf \` Ns Ar command Ns \`
1219 or (executed in the current environment)
1220 .Pf ${\ \& Ar command Ns \&;}
1221 and strip trailing newlines;
1222 and arithmetic substitutions take the form
1223 .Pf $(( Ns Ar expression Ns )) .
1224 Parsing the current-environment command substitution requires a space,
1225 tab or newline after the opening brace and that the closing brace be
1226 recognised as a keyword (i.e. is preceded by a newline or semicolon).
1227 They are also called funsubs (function substitutions) and behave like
1234 terminates the parent shell; shell options are shared.
1236 Another variant of substitution are the valsubs (value substitutions)
1237 .Pf ${\*(Ba\& Ns Ar command Ns \&;}
1238 which are also executed in the current environment, like funsubs, but
1239 share their I/O with the parent; instead, they evaluate to whatever
1240 the, initially empty, expression-local variable
1242 is set to within the
1245 If a substitution appears outside of double quotes, the results of the
1246 substitution are generally subject to word or field splitting according to
1247 the current value of the
1252 parameter specifies a list of octets which are used to break a string up
1253 into several words; any octets from the set space, tab and newline that
1257 .Dq IFS whitespace .
1258 Sequences of one or more
1260 whitespace octets, in combination with zero or one
1262 whitespace octets, delimit a field.
1263 As a special case, leading and trailing
1265 whitespace is stripped (i.e. no leading or trailing empty field
1266 is created by it); leading or trailing
1268 whitespace does create an empty field.
1273 .Dq Li \*(Ltspace\*(Gt:
1275 .Dq Li \*(Ltspace\*(GtA\*(Ltspace\*(Gt:\*(Ltspace\*(Gt\*(Ltspace\*(GtB::D ,
1276 the substitution for $VAR results in four fields:
1280 (an empty field) and
1284 parameter is set to the empty string, no field splitting is done;
1285 if it is unset, the default value of space, tab and newline is used.
1287 Also, note that the field splitting applies only to the immediate result of
1289 Using the previous example, the substitution for $VAR:E
1290 results in the fields:
1303 This behavior is POSIX compliant, but incompatible with some other shell
1304 implementations which do field splitting on the word which contained the
1307 as a general whitespace delimiter.
1309 The results of substitution are, unless otherwise specified, also subject to
1310 brace expansion and file name expansion (see the relevant sections below).
1312 A command substitution is replaced by the output generated by the specified
1313 command which is run in a subshell.
1315 .Pf $( Ns Ar command Ns \&)
1317 .Pf ${\*(Ba\& Ns Ar command Ns \&;}
1319 .Pf ${\ \& Ar command Ns \&;}
1320 substitutions, normal quoting rules are used when
1322 is parsed; however, for the deprecated
1323 .Pf \` Ns Ar command Ns \`
1333 when the substitution is part of a double-quoted string); a backslash
1335 followed by any other character is unchanged.
1336 As a special case in command substitutions, a command of the form
1338 is interpreted to mean substitute the contents of
1342 has the same effect as
1345 Note that some shells do not use a recursive parser for command substitutions,
1346 leading to failure for certain constructs; to be portable, use as workaround
1347 .Dq Li x=$(cat) \*(Lt\*(Lt\eEOF
1348 (or the newline-keeping
1349 .Dq Li x=\*(Lt\*(Lt\eEOF
1350 extension) instead to merely slurp the string.
1352 recommends using case statements of the form
1353 .Li "x=$(case $foo in (bar) echo $bar ;; (*) echo $baz ;; esac)"
1354 instead, which would work but not serve as example for this portability issue.
1355 .Bd -literal -offset indent
1356 x=$(case $foo in bar) echo $bar ;; *) echo $baz ;; esac)
1357 # above fails to parse on old shells; below is the workaround
1358 x=$(eval $(cat)) \*(Lt\*(Lt\eEOF
1359 case $foo in bar) echo $bar ;; *) echo $baz ;; esac
1363 Arithmetic substitutions are replaced by the value of the specified expression.
1364 For example, the command
1365 .Ic print $((2+3*4))
1368 .Sx Arithmetic expressions
1369 for a description of an expression.
1371 Parameters are shell variables; they can be assigned values and their values
1372 can be accessed using a parameter substitution.
1373 A parameter name is either one
1374 of the special single punctuation or digit character parameters described
1375 below, or a letter followed by zero or more letters or digits
1380 The latter form can be treated as arrays by appending an array index of the
1385 is an arithmetic expression.
1388 are limited to the range 0 through 4294967295, inclusive.
1389 That is, they are a 32-bit unsigned integer.
1391 Parameter substitutions take the form
1393 .Pf ${ Ns Ar name Ns }
1396 .Pf ${ Ar name Oo Ar expr Oc }
1400 is a parameter name.
1401 Substitutions of an an array in scalar context, i.e. without an
1403 in the latter form mentioned above, expand the element with the key
1405 Substitution of all array elements with
1406 .Pf ${ Ns Ar name Ns \&[*]}
1408 .Pf ${ Ns Ar name Ns \&[@]}
1409 works equivalent to $* and $@ for positional parameters.
1410 If substitution is performed on a parameter
1411 (or an array parameter element)
1412 that is not set, an empty string is substituted unless the
1416 is set, in which case an error occurs.
1418 Parameters can be assigned values in a number of ways.
1419 First, the shell implicitly sets some parameters like
1424 this is the only way the special single character parameters are set.
1425 Second, parameters are imported from the shell's environment at startup.
1426 Third, parameters can be assigned values on the command line: for example,
1432 multiple parameter assignments can be given on a single command line and they
1433 can be followed by a simple-command, in which case the assignments are in
1434 effect only for the duration of the command (such assignments are also
1435 exported; see below for the implications of this).
1436 Note that both the parameter name and the
1438 must be unquoted for the shell to recognise a parameter assignment.
1441 is also recognised; the old and new values are immediately concatenated.
1442 The fourth way of setting a parameter is with the
1448 commands; see their descriptions in the
1449 .Sx Command execution
1455 loops set parameters as well as the
1461 Lastly, parameters can be assigned values using assignment operators
1462 inside arithmetic expressions (see
1463 .Sx Arithmetic expressions
1466 .Pf ${ Ar name No = Ar value No }
1468 form of the parameter substitution (see below).
1470 Parameters with the export attribute (set using the
1474 commands, or by parameter assignments followed by simple commands) are put in
1475 the environment (see
1477 of commands run by the shell as
1478 .Ar name Ns = Ns Ar value
1480 The order in which parameters appear in the environment of a command is
1482 When the shell starts up, it extracts parameters and their values
1483 from its environment and automatically sets the export attribute for those
1486 Modifiers can be applied to the
1487 .Pf ${ Ns Ar name Ns }
1488 form of parameter substitution:
1491 .It ${ Ar name No :\- Ar word No }
1495 is set and not empty,
1496 it is substituted; otherwise,
1500 .It ${ Ar name No :+ Ar word No }
1504 is set and not empty,
1506 is substituted; otherwise, nothing is substituted.
1508 .It ${ Ar name No := Ar word No }
1512 is set and not empty,
1513 it is substituted; otherwise, it is assigned
1515 and the resulting value of
1519 .It ${ Ar name No :? Ar word No }
1523 is set and not empty,
1524 it is substituted; otherwise,
1526 is printed on standard error (preceded by
1528 and an error occurs (normally causing termination of a shell script, function,
1529 or a script sourced using the
1534 is omitted, the string
1535 .Dq Li parameter null or not set
1539 Note that, for all of the above,
1541 is actually considered quoted, and special parsing rules apply.
1542 The parsing rules also differ on whether the expression is double-quoted:
1544 then uses double-quoting rules, except for the double quote itself
1546 and the closing brace, which, if backslash escaped, gets quote removal applied.
1548 In the above modifiers, the
1550 can be omitted, in which case the conditions only depend on
1552 being set (as opposed to set and not empty).
1555 is needed, parameter, command, arithmetic and tilde substitution are performed
1558 is not needed, it is not evaluated.
1560 The following forms of parameter substitution can also be used:
1562 .Bl -tag -width Ds -compact
1563 .It Pf ${# Ns Ar name Ns \&}
1564 The number of positional parameters if
1569 or not specified; otherwise the length
1571 of the string value of parameter
1574 .It Pf ${# Ns Ar name Ns \&[*]}
1575 .It Pf ${# Ns Ar name Ns \&[@]}
1576 The number of elements in the array
1579 .It Pf ${% Ns Ar name Ns \&}
1581 .Pq in screen columns
1582 of the string value of parameter
1585 .Pf ${ Ns Ar name Ns }
1586 contains a control character.
1588 .It Pf ${! Ns Ar name Ns }
1589 The name of the variable referred to by
1595 is a name reference (bound variable), created by the
1597 command (which is an alias for
1598 .Ic typeset Fl n ) .
1600 cannot be one of most special parameters (see below).
1602 .It Pf ${! Ns Ar name Ns \&[*]}
1603 .It Pf ${! Ns Ar name Ns \&[@]}
1604 The names of indices (keys) in the array
1610 .Pf # Ar pattern No }
1614 .Pf ## Ar pattern No }
1619 matches the beginning of the value of parameter
1621 the matched text is deleted from the result of substitution.
1624 results in the shortest match, and two
1625 of them result in the longest match.
1626 Cannot be applied to a vector
1627 .Pq ${*} or ${@} or ${array[*]} or ${array[@]} .
1632 .Pf % Ar pattern No }
1636 .Pf %% Ar pattern No }
1639 Like ${...#...} substitution, but it deletes from the end of the value.
1640 Cannot be applied to a vector.
1645 .Pf / Ar pattern / Ar string No }
1649 .Pf /# Ar pattern / Ar string No }
1653 .Pf /% Ar pattern / Ar string No }
1657 .Pf // Ar pattern / Ar string No }
1660 The longest match of
1662 in the value of parameter
1668 is empty; the trailing slash
1670 may be omitted in that case).
1671 A leading slash followed by
1675 causes the pattern to be anchored at the beginning or end of
1676 the value, respectively; empty unanchored
1678 cause no replacement; a single leading slash or use of a
1680 that matches the empty string causes the replacement to
1681 happen only once; two leading slashes cause all occurrences
1682 of matches in the value to be replaced.
1683 Cannot be applied to a vector.
1684 Inefficiently implemented, may be slow.
1689 .Pf @/ Ar pattern / Ar string No }
1696 .Pf // Ar pattern / Ar string No } ,
1703 are expanded anew for each iteration.
1707 .Pf ${ Ar name : Ns Ar pos
1708 .Pf : Ns Ar len Ns }
1715 starting at position
1725 is negative, counting starts at the end of the string; if it
1726 is omitted, it defaults to 0.
1729 is omitted or greater than the length of the remaining string,
1730 all of it is substituted.
1735 are evaluated as arithmetic expressions.
1738 must start with a space, opening parenthesis or digit to be recognised.
1739 Cannot be applied to a vector.
1741 .It Pf ${ Ns Ar name Ns @#}
1742 The hash (using the BAFH algorithm) of the expansion of
1744 This is also used internally for the shell's hashtables.
1746 .It Pf ${ Ns Ar name Ns @Q}
1747 A quoted expression safe for re-entry, whose value is the value of the
1749 parameter, is substituted.
1754 may need extended globbing pattern
1757 .Pq \&\*(aq...\&\*(aq
1760 quote escaping unless
1764 The following special parameters are implicitly set by the shell and cannot be
1765 set directly using assignments:
1766 .Bl -tag -width "1 .. 9"
1768 Process ID of the last background process started.
1769 If no background processes have been started, the parameter is not set.
1771 The number of positional parameters ($1, $2, etc.).
1773 The PID of the shell or, if it is a subshell, the PID of the original shell.
1776 use this mechanism for generating temporary file names; see
1780 The concatenation of the current single letter options (see the
1782 command below for a list of options).
1784 The exit status of the last non-asynchronous command executed.
1785 If the last command was killed by a signal,
1787 is set to 128 plus the signal number, but at most 255.
1789 The name of the shell, determined as follows:
1790 the first argument to
1792 if it was invoked with the
1794 option and arguments were given; otherwise the
1796 argument, if it was supplied;
1797 or else the basename the shell was invoked with (i.e.\&
1800 is also set to the name of the current script or
1801 the name of the current function, if it was defined with the
1803 keyword (i.e. a Korn shell style function).
1805 The first nine positional parameters that were supplied to the shell, function,
1806 or script sourced using the
1809 Further positional parameters may be accessed using
1810 .Pf ${ Ar number Ns } .
1812 All positional parameters (except 0), i.e. $1, $2, $3, ...
1815 outside of double quotes, parameters are separate words (which are subjected
1816 to word splitting); if used within double quotes, parameters are separated
1817 by the first character of the
1819 parameter (or the empty string if
1825 unless it is used inside double quotes, in which case a separate word is
1826 generated for each positional parameter.
1827 If there are no positional parameters, no word is generated.
1829 can be used to access arguments, verbatim, without losing
1830 empty arguments or splitting arguments with spaces (IFS, actually).
1833 The following parameters are set and/or used by the shell:
1834 .Bl -tag -width "KSH_VERSION"
1837 When an external command is executed by the shell, this parameter is set in the
1838 environment of the new process to the path of the executed command.
1839 In interactive use, this parameter is also set in the parent shell to the last
1840 word of the previous command.
1842 The PID of the shell or subshell.
1846 but used to resolve the argument to the
1851 is set and does not contain
1853 or an empty string element, the current directory is not searched.
1856 built-in command will display the resulting directory when a match is found
1857 in any search path other than the empty path.
1859 Set to the number of columns on the terminal or window.
1860 If never unset and not imported, always set dynamically;
1861 unless the value as reported by
1863 is non-zero and sane enough (minimum is 12x3), defaults to 80; similar for
1865 This parameter is used by the interactive line editing modes and by the
1870 commands to format information columns.
1871 Importing from the environment or unsetting this parameter removes the
1872 binding to the actual terminal size in favour of the provided value.
1874 If this parameter is found to be set after any profile files are executed, the
1875 expanded value is used as a shell startup file.
1876 It typically contains function and alias definitions.
1877 .It Ev EPOCHREALTIME
1878 Time since the epoch, as returned by
1879 .Xr gettimeofday 2 ,
1880 formatted as decimal
1886 padded to exactly six decimal digits.
1888 If set, this parameter is assumed to contain the shell that is to be used to
1889 execute commands that
1891 fails to execute and which do not start with a
1892 .Dq Li #! Ns Ar shell
1895 The editor used by the
1897 command (see below).
1901 but used when an undefined function is executed to locate the file defining the
1903 It is also searched when a command can't be found using
1907 below for more information.
1909 The name of the file used to store command history.
1910 When assigned to or unset, the file is opened, history is truncated
1911 then loaded from the file; subsequent new commands (possibly consisting
1912 of several lines) are appended once they successfully compiled.
1913 Also, several invocations of the shell will share history if their
1915 parameters all point to the same file.
1920 is unset or empty, no history file is used.
1921 This is different from
1925 The number of commands normally stored for history.
1926 The default is 2047.
1927 Do not set this value to insanely high values such as 1000000000 because
1929 can then not allocate enough memory for the history and will not start.
1931 The default directory for the
1933 command and the value substituted for an unqualified
1939 Internal field separator, used during substitution and by the
1941 command, to split values into distinct arguments; normally set to space, tab
1948 This parameter is not imported from the environment when the shell is
1951 The effective group id of the shell.
1953 The real group id of the shell.
1955 The real user id of the shell.
1957 The last matched string.
1958 In a future version, this will be an indexed array,
1959 with indexes 1 and up capturing matching groups.
1960 Set by string comparisons (== and !=) in double-bracket test
1961 expressions when a match is found (when != returns false), by
1963 when a match is encountered, and by the substitution operations
1973 .Pf ## Ar pat No } ,
1985 .Pf %% Ar pat No } ,
1991 .Pf / Ar pat / Ar rpl No } ,
1997 .Pf /# Ar pat / Ar rpl No } ,
2003 .Pf /% Ar pat / Ar rpl No } ,
2009 .Pf // Ar pat / Ar rpl No } ,
2016 .Pf @/ Ar pat / Ar rpl No } .
2019 See the end of the Emacs editing mode documentation for an example.
2021 The name and version of the shell (read-only).
2022 See also the version commands in
2023 .Sx Emacs editing mode
2028 The line number of the function or shell script that is currently being
2031 Set to the number of lines on the terminal or window.
2032 Defaults to 24; always set, unless imported or unset.
2036 The previous working directory.
2039 has not successfully changed directories since the shell started or if the
2040 shell doesn't know where it is.
2044 it contains the argument for a parsed option, if it requires one.
2046 The index of the next argument to be processed when using
2048 Assigning 1 to this parameter causes
2050 to process arguments from the beginning the next time it is invoked.
2052 A colon (semicolon on OS/2) separated list of directories that are
2053 searched when looking for commands and files sourced using the
2055 command (see below).
2056 An empty string resulting from a leading or trailing
2057 (semi)colon, or two adjacent ones, is treated as a
2059 (the current directory).
2061 A colon (semicolon on OS/2), for the user's convenience.
2063 The process ID of the shell's process group leader.
2065 An array containing the errorlevel (exit status) codes,
2066 one by one, of the last pipeline run in the foreground.
2068 The process ID of the shell's parent.
2070 The primary prompt for interactive shells.
2071 Parameter, command and arithmetic
2072 substitutions are performed, and
2074 is replaced with the current command number (see the
2079 can be put in the prompt by placing
2084 The default prompt is
2091 is invoked by root and
2095 character, the default value will be used even if
2097 already exists in the environment.
2101 distribution comes with a sample
2103 containing a sophisticated example, but you might like the following one
2104 (note that ${HOSTNAME:=$(hostname)} and the
2105 root-vs-user distinguishing clause are (in this example) executed at
2107 assignment time, while the $USER and $PWD are escaped
2108 and thus will be evaluated each time a prompt is displayed):
2110 PS1=\*(aq${USER:=$(id \-un)}\*(aq"@${HOSTNAME:=$(hostname)}:\e$PWD $(
2111 if (( USER_ID )); then print \e$; else print \e#; fi) "
2114 Note that since the command-line editors try to figure out how long the prompt
2115 is (so they know how far it is to the edge of the screen), escape codes in
2116 the prompt tend to mess things up.
2117 You can tell the shell not to count certain
2118 sequences (such as escape codes) by prefixing your prompt with a
2119 character (such as Ctrl-A) followed by a carriage return and then delimiting
2120 the escape codes with this character.
2121 Any occurrences of that character in the prompt are not printed.
2122 By the way, don't blame me for
2123 this hack; it's derived from the original
2125 which did print the delimiter character so you were out of luck
2126 if you did not have any non-printing characters.
2128 Since backslashes and other special characters may be
2129 interpreted by the shell, to set
2131 either escape the backslash itself
2132 or use double quotes.
2133 The latter is more practical.
2134 This is a more complex example,
2135 avoiding to directly enter special characters (for example with
2137 in the emacs editing mode),
2138 which embeds the current working directory,
2140 .Pq colour would work, too ,
2141 in the prompt string:
2142 .Bd -literal -offset indent
2143 x=$(print \e\e001) # otherwise unused char
2144 PS1="$x$(print \e\er)$x$(tput so)$x\e$PWD$x$(tput se)$x\*(Gt "
2147 Due to a strong suggestion from David G. Korn,
2149 now also supports the following form:
2150 .Bd -literal -offset indent
2151 PS1=$\*(aq\e1\er\e1\ee[7m\e1$PWD\e1\ee[0m\e1\*(Gt \*(aq
2154 Secondary prompt string, by default
2156 used when more input is needed to complete a command.
2160 statement when reading a menu selection.
2164 Used to prefix commands that are printed during execution tracing (see the
2167 Parameter, command and arithmetic substitutions are performed
2168 before it is printed.
2171 You may want to set it to
2172 .Dq Li \&[$EPOCHREALTIME]\ \&
2173 instead, to include timestamps.
2175 The current working directory.
2176 May be unset or empty if the shell doesn't know where it is.
2180 is referenced, it is assigned a number between 0 and 32767 from
2181 a Linear Congruential PRNG first.
2183 Default parameter for the
2185 command if no names are given.
2188 loops to store the value that is read from standard input.
2190 The number of seconds since the shell started or, if the parameter has been
2191 assigned an integer value, the number of seconds since the assignment plus the
2192 value that was assigned.
2194 If set to a positive integer in an interactive shell, it specifies the maximum
2195 number of seconds the shell will wait for input after printing the primary
2198 If the time is exceeded, the shell exits.
2200 The directory temporary shell files are created in.
2201 If this parameter is not
2202 set or does not contain the absolute path of a writable directory, temporary
2203 files are created in
2206 The effective user id of the shell.
2209 Tilde expansion, which is done in parallel with parameter substitution,
2210 is applied to words starting with an unquoted
2212 In parameter assignments (such as those preceding a simple-command or those
2213 occurring in the arguments of a declaration utility), tilde expansion is done
2214 after any assignment (i.e. after the equals sign) or after an unquoted colon
2216 login names are also delimited by colons.
2217 The Korn shell, except in POSIX mode, always expands tildes after unquoted
2218 equals signs, not just in assignment context (see below), and enables tab
2219 completion for tildes after all unquoted colons during command line editing.
2221 The characters following the tilde, up to the first
2223 if any, are assumed to be a login name.
2224 If the login name is empty,
2228 the simplified value of the
2233 parameter is substituted, respectively.
2234 Otherwise, the password file is
2235 searched for the login name, and the tilde expression is substituted with the
2236 user's home directory.
2237 If the login name is not found in the password file or
2238 if any quoting or parameter substitution occurs in the login name, no
2239 substitution is performed.
2241 The home directory of previously expanded login names are cached and re-used.
2244 command may be used to list, change and add to this cache (e.g.\&
2245 .Ic alias \-d fac=/usr/local/facilities; cd \*(TIfac/bin ) .
2246 .Ss Brace expansion (alternation)
2247 Brace expressions take the following form:
2248 .Bd -unfilled -offset indent
2251 .Ar prefix No { Ar str1 No ,...,
2252 .Ar strN No } Ar suffix
2257 The expressions are expanded to
2259 words, each of which is the concatenation of
2265 .Dq Li a{c,b{X,Y},d}e
2266 expands to four words:
2272 As noted in the example, brace expressions can be nested and the resulting
2273 words are not sorted.
2274 Brace expressions must contain an unquoted comma
2276 for expansion to occur (e.g.\&
2281 Brace expansion is carried out after parameter substitution
2282 and before file name generation.
2283 .Ss File name patterns
2284 A file name pattern is a word containing one or more unquoted
2294 Once brace expansion has been performed, the shell replaces file
2295 name patterns with the sorted names of all the files that match the pattern
2296 (if no files match, the word is left unchanged).
2297 The pattern elements have the following meaning:
2300 Matches any single character.
2302 Matches any sequence of octets.
2304 Matches any of the octets inside the brackets.
2305 Ranges of octets can be specified by separating two octets by a
2312 In order to represent itself, a
2314 must either be quoted or the first or last octet in the octet list.
2317 must be quoted or the first octet in the list if it is to represent itself
2318 instead of the end of the list.
2321 appearing at the start of the list has special meaning (see below), so to
2322 represent itself it must be quoted or appear later in the list.
2325 except it matches any octet not inside the brackets.
2327 .It *( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
2329 Matches any string of octets that matches zero or more occurrences of the
2331 Example: The pattern
2340 .It +( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
2342 Matches any string of octets that matches one or more occurrences of the
2344 Example: The pattern
2352 .It ?( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
2354 Matches the empty string or a string that matches one of the specified
2356 Example: The pattern
2358 only matches the strings
2364 .It @( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
2366 Matches a string that matches one of the specified patterns.
2367 Example: The pattern
2369 only matches the strings
2374 .It !( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
2376 Matches any string that does not match one of the specified patterns.
2377 Examples: The pattern
2379 matches all strings except
2385 matches no strings; the pattern
2387 matches all strings (think about it).
2390 Note that complicated globbing, especially with alternatives,
2391 is slow; using separate comparisons may (or may not) be faster.
2409 Note that none of the above pattern elements match either a period
2411 at the start of a file name or a slash
2413 even if they are explicitly used in a [...] sequence; also, the names
2417 are never matched, even by the pattern
2422 option is set, any directories that result from file name generation are marked
2425 .Ss Input/output redirection
2426 When a command is executed, its standard input, standard output and standard
2427 error (file descriptors 0, 1 and 2, respectively) are normally inherited from
2429 Three exceptions to this are commands in pipelines, for which
2430 standard input and/or standard output are those set up by the pipeline,
2431 asynchronous commands created when job control is disabled, for which standard
2432 input is initially set to
2434 and commands for which any of the following redirections have been specified:
2435 .Bl -tag -width XXxxmarker
2436 .It \*(Gt Ns Ar file
2437 Standard output is redirected to
2441 does not exist, it is created; if it does exist, is a regular file, and the
2443 option is set, an error occurs; otherwise, the file is truncated.
2444 Note that this means the command
2445 .Ic cmd \*(Ltfoo \*(Gtfoo
2448 for reading and then truncate it when it opens it for writing, before
2450 gets a chance to actually read
2452 .It \*(Gt\*(Ba Ns Ar file
2455 except the file is truncated, even if the
2458 .It \*(Gt\*(Gt Ns Ar file
2463 exists it is appended to instead of being truncated.
2464 Also, the file is opened
2465 in append mode, so writes always go to the end of the file (see
2467 .It \*(Lt Ns Ar file
2468 Standard input is redirected from
2470 which is opened for reading.
2471 .It \*(Lt\*(Gt Ns Ar file
2474 except the file is opened for reading and writing.
2475 .It \*(Lt\*(Lt Ns Ar marker
2476 After reading the command line containing this kind of redirection (called a
2477 .Dq here document ) ,
2478 the shell copies lines from the command source into a temporary file until a
2482 When the command is executed, standard input is redirected from the
2486 contains no quoted characters, the contents of the temporary file are processed
2487 as if enclosed in double quotes each time the command is executed, so
2488 parameter, command and arithmetic substitutions are performed, along with
2499 If multiple here documents are used on the same command line, they are saved in
2504 is given, the here document ends at the next
2506 and substitution will be performed.
2509 is only a set of either single
2513 quotes with nothing in between, the here document ends at the next empty line
2514 and substitution will not be performed.
2515 .It \*(Lt\*(Lt\- Ns Ar marker
2518 except leading tabs are stripped from lines in the here document.
2519 .It \*(Lt\*(Lt\*(Lt Ns Ar word
2526 This is called a here string.
2528 Standard input is duplicated from file descriptor
2531 can be a single digit, indicating the number of an existing file descriptor;
2534 indicating the file descriptor associated with the output of the current
2535 co-process; or the character
2537 indicating standard input is to be closed.
2541 except the operation is done on standard output.
2542 .It &\*(Gt Ns Ar file
2544 .Ic \*(Gt Ns Ar file 2\*(Gt&1 .
2545 This is a deprecated (legacy) GNU
2547 extension supported by
2549 which also supports the preceding explicit fd digit, for example,
2550 .Ic 3&\*(Gt Ns Ar file
2552 .Ic 3\*(Gt Ns Ar file 2\*(Gt&3
2555 but a syntax error in GNU
2558 .No &\*(Gt\*(Ba Ns Ar file ,
2559 .No &\*(Gt\*(Gt Ns Ar file ,
2560 .No &\*(Gt& Ns Ar fd
2563 .Ic \*(Gt\*(Ba Ns Ar file ,
2564 .Ic \*(Gt\*(Gt Ns Ar file
2566 .Ic \*(Gt& Ns Ar fd ,
2575 In any of the above redirections, the file descriptor that is redirected
2576 (i.e. standard input or standard output)
2577 can be explicitly given by preceding the
2578 redirection with a single digit.
2579 Parameter, command and arithmetic
2580 substitutions, tilde substitutions, and, if the shell is interactive,
2581 file name generation are all performed on the
2586 arguments of redirections.
2587 Note, however, that the results of any file name
2588 generation are only used if a single file is matched; if multiple files match,
2589 the word with the expanded file name generation characters is used.
2591 that in restricted shells, redirections which can create files cannot be used.
2593 For simple-commands, redirections may appear anywhere in the command; for
2599 any redirections must appear at the end.
2600 Redirections are processed after
2601 pipelines are created and in the order they are given, so the following
2602 will print an error with a line number prepended to it:
2604 .Dl $ cat /foo/bar 2\*(Gt&1 \*(Gt/dev/null \*(Ba pr \-n \-t
2606 File descriptors created by I/O redirections are private to the shell.
2607 .Ss Arithmetic expressions
2608 Integer arithmetic expressions can be used with the
2610 command, inside $((...)) expressions, inside array references (e.g.\&
2611 .Ar name Ns Bq Ar expr ) ,
2612 as numeric arguments to the
2614 command, and as the value of an assignment to an integer parameter.
2616 This also affects implicit conversion to integer, for example as done by the
2620 use unchecked user input, e.g. from the environment, in an arithmetic context!
2622 Expressions are calculated using signed arithmetic and the
2624 type (a 32-bit signed integer), unless they begin with a sole
2626 character, in which case they use
2628 .Po a 32-bit unsigned integer Pc .
2630 Expressions may contain alpha-numeric parameter identifiers, array references
2631 and integer constants and may be combined with the following C operators
2632 (listed and grouped in increasing order of precedence):
2635 .Bd -literal -offset indent
2636 + \- ! \*(TI ++ \-\-
2640 .Bd -literal -offset indent
2642 = += \-= *= /= %= \*(Lt\*(Lt= \*(Gt\*(Gt= \*(ha\*(Lt= \*(ha\*(Gt= &= \*(ha= \*(Ba=
2649 \*(Lt \*(Lt= \*(Gt \*(Gt=
2650 \*(Lt\*(Lt \*(Gt\*(Gt \*(ha\*(Lt \*(ha\*(Gt
2656 .Bd -literal -offset indent
2657 ?: (precedence is immediately higher than assignment)
2661 .Bd -literal -offset indent
2665 Integer constants and expressions are calculated using an exactly 32-bit
2666 wide, signed or unsigned, type with silent wraparound on integer overflow.
2667 Integer constants may be specified with arbitrary bases using the notation
2668 .Ar base Ns # Ns Ar number ,
2671 is a decimal integer specifying the base (up to 36), and
2673 is a number in the specified base.
2674 Additionally, base-16 integers may be specified by prefixing them with
2676 .Pq case-insensitive
2677 in all forms of arithmetic expressions, except as numeric arguments to the
2680 Prefixing numbers with a sole digit zero
2682 does not cause interpretation as octal (except in POSIX mode,
2683 as required by the standard), as that's unsafe to do.
2687 extension, numbers to the base of one are treated as either (8-bit
2688 transparent) ASCII or Universal Coded Character Set codepoints,
2689 depending on the shell's
2691 flag (current setting).
2700 Note that NUL bytes (integral value of zero) cannot be used.
2701 An unset or empty parameter evaluates to 0 in integer context.
2702 In UTF-8 mode, raw octets are mapped into the range EF80..EFFF as in
2703 OPTU-8, which is in the PUA and has been assigned by CSUR for this use.
2704 If more than one octet in ASCII mode, or a sequence of more than one
2705 octet not forming a valid and minimal CESU-8 sequence is passed, the
2706 behaviour is undefined (usually, the shell aborts with a parse error,
2707 but rarely, it succeeds, e.g. on the sequence C2 20).
2708 That's why you should always use ASCII mode unless you know that the
2709 input is well-formed UTF-8 in the range of 0000..FFFD if you use this
2710 feature, as opposed to
2713 The operators are evaluated as follows:
2714 .Bl -tag -width Ds -offset indent
2716 Result is the argument (included for completeness).
2721 the result is 1 if argument is zero, 0 if not.
2723 Arithmetic (bit-wise) NOT.
2725 Increment; must be applied to a parameter (not a literal or other expression).
2726 The parameter is incremented by 1.
2727 When used as a prefix operator, the result
2728 is the incremented value of the parameter; when used as a postfix operator, the
2729 result is the original value of the parameter.
2733 except the parameter is decremented by 1.
2735 Separates two arithmetic expressions; the left-hand side is evaluated first,
2737 The result is the value of the expression on the right-hand side.
2739 Assignment; the variable on the left is set to the value on the right.
2741 .No += \-= *= /= %= \*(Lt\*(Lt= \*(Gt\*(Gt=
2742 .No \*(ha\*(Lt= \*(ha\*(Gt= &= \*(ha= \*(Ba=
2744 Assignment operators.
2759 with any operator precedence in
2763 .Dq Li var1 *= 5 + 3
2764 is the same as specifying
2765 .Dq Li var1 = var1 * (5 + 3) .
2768 the result is 1 if either argument is non-zero, 0 if not.
2769 The right argument is evaluated only if the left argument is zero.
2772 the result is 1 if both arguments are non-zero, 0 if not.
2773 The right argument is evaluated only if the left argument is non-zero.
2775 Arithmetic (bit-wise) OR.
2777 Arithmetic (bit-wise) XOR
2780 Arithmetic (bit-wise) AND.
2782 Equal; the result is 1 if both arguments are equal, 0 if not.
2784 Not equal; the result is 0 if both arguments are equal, 1 if not.
2786 Less than; the result is 1 if the left argument is less than the right, 0 if
2788 .It \*(Lt= \*(Gt \*(Gt=
2789 Less than or equal, greater than, greater than or equal.
2792 .It \*(Lt\*(Lt \*(Gt\*(Gt
2793 Shift left (right); the result is the left argument with its bits
2794 arithmetically (signed operation) or logically (unsigned expression)
2795 shifted left (right) by the amount given in the right argument.
2796 .It \*(ha\*(Lt \*(ha\*(Gt
2797 Rotate left (right); the result is similar to shift,
2798 except that the bits shifted out at one end are shifted in
2799 at the other end, instead of zero or sign bits.
2801 Addition, subtraction, multiplication and division.
2803 Remainder; the result is the symmetric remainder of the division of the left
2804 argument by the right.
2805 To get the mathematical modulus of
2821 is non-zero, the result is
2823 otherwise the result is
2825 The non-result argument is not evaluated.
2828 A co-process (which is a pipeline created with the
2830 operator) is an asynchronous process that the shell can both write to (using
2832 and read from (using
2834 The input and output of the co-process can also be manipulated using
2838 redirections, respectively.
2839 Once a co-process has been started, another can't
2840 be started until the co-process exits, or until the co-process's input has been
2842 .Ic exec Ar n Ns Ic \*(Gt&p
2844 If a co-process's input is redirected in this way, the next
2845 co-process to be started will share the output with the first co-process,
2846 unless the output of the initial co-process has been redirected using an
2847 .Ic exec Ar n Ns Ic \*(Lt&p
2850 Some notes concerning co-processes:
2853 The only way to close the co-process's input (so the co-process reads an
2854 end-of-file) is to redirect the input to a numbered file descriptor and then
2855 close that file descriptor:
2856 .Ic exec 3\*(Gt&p; exec 3\*(Gt&\-
2858 In order for co-processes to share a common output, the shell must keep the
2859 write portion of the output pipe open.
2860 This means that end-of-file will not be
2861 detected until all co-processes sharing the co-process's output have exited
2862 (when they all exit, the shell closes its copy of the pipe).
2864 avoided by redirecting the output to a numbered file descriptor (as this also
2865 causes the shell to close its copy).
2866 Note that this behaviour is slightly
2867 different from the original Korn shell which closes its copy of the write
2868 portion of the co-process output when the most recently started co-process
2869 (instead of when all sharing co-processes) exits.
2874 signals during writes if the signal is not being trapped or ignored; the same
2875 is true if the co-process input has been duplicated to another file descriptor
2877 .Ic print Fl u Ns Ar n
2881 Functions are defined using either Korn shell
2882 .Ic function Ar function-name
2883 syntax or the Bourne/POSIX shell
2884 .Ar function-name Ns \&()
2885 syntax (see below for the difference between the two forms).
2888 (i.e. scripts sourced using the
2891 in that they are executed in the current environment.
2894 shell arguments (i.e. positional parameters $1, $2, etc.)\&
2895 are never visible inside them.
2896 When the shell is determining the location of a command, functions
2897 are searched after special built-in commands, before builtins and the
2901 An existing function may be deleted using
2902 .Ic unset Fl f Ar function-name .
2903 A list of functions can be obtained using
2905 and the function definitions can be listed using
2909 command (which is an alias for
2911 may be used to create undefined functions: when an undefined function is
2912 executed, the shell searches the path specified in the
2914 parameter for a file with the same name as the function which, if found, is
2916 If after executing the file the named function is found to
2917 be defined, the function is executed; otherwise, the normal command search is
2918 continued (i.e. the shell searches the regular built-in command table and
2920 Note that if a command is not found using
2922 an attempt is made to autoload a function using
2924 (this is an undocumented feature of the original Korn shell).
2926 Functions can have two attributes,
2930 which can be set with
2935 When a traced function is executed, the shell's
2937 option is turned on for the function's duration.
2940 attribute of functions is currently not used.
2942 Since functions are executed in the current shell environment, parameter
2943 assignments made inside functions are visible after the function completes.
2944 If this is not the desired effect, the
2946 command can be used inside a function to create a local parameter.
2950 uses static scoping (one global scope, one local scope per function)
2951 and allows local variables only on Korn style functions, whereas
2953 uses dynamic scoping (nested scopes of varying locality).
2954 Note that special parameters (e.g.\&
2956 can't be scoped in this way.
2958 The exit status of a function is that of the last command executed in the
2960 A function can be made to finish immediately using the
2962 command; this may also be used to explicitly specify the exit status.
2963 Note that when called in a subshell,
2965 will only exit that subshell and will not cause the original shell to exit
2966 a running function (see the
2967 .Ic while Ns Li \&... Ns Ic read
2970 Functions defined with the
2972 reserved word are treated differently in the following ways from functions
2978 The $0 parameter is set to the name of the function
2979 (Bourne-style functions leave $0 untouched).
2981 Parameter assignments preceding function calls are not kept in the shell
2982 environment (executing Bourne-style functions will keep assignments).
2985 is saved/reset and restored on entry and exit from the function so
2987 can be used properly both inside and outside the function (Bourne-style
2992 inside a function interferes with using
2994 outside the function).
2998 have local scope, i.e. changes inside a function are reset upon its exit.
3001 In the future, the following differences may also be added:
3004 A separate trap/signal environment will be used during the execution of
3006 This will mean that traps set inside a function will not affect the
3007 shell's traps and signals that are not ignored in the shell (but may be
3008 trapped) will have their default effect in a function.
3010 The EXIT trap, if set in a function, will be executed after the function
3013 .Ss Command execution
3014 After evaluation of command-line arguments, redirections and parameter
3015 assignments, the type of command is determined: a special built-in command,
3016 a function, a normal builtin or the name of a file to execute found using the
3019 The checks are made in the above order.
3020 Special built-in commands differ from other commands in that the
3022 parameter is not used to find them, an error during their execution can
3023 cause a non-interactive shell to exit, and parameter assignments that are
3024 specified before the command are kept after the command completes.
3025 Regular built-in commands are different only in that the
3027 parameter is not used to find them.
3031 and POSIX differ somewhat in which commands are considered
3034 POSIX special built-in utilities:
3036 .Ic \&. , \&: , break , continue ,
3037 .Ic eval , exec , exit , export ,
3038 .Ic readonly , return , set , shift ,
3039 .Ic times , trap , unset
3043 commands keeping assignments:
3045 .Ic global , source , typeset
3047 Builtins that are not special:
3049 .Ic [ , alias , bg , bind ,
3050 .Ic builtin , cat , cd , command ,
3051 .Ic echo , false , fc , fg ,
3052 .Ic getopts , jobs , kill , let ,
3053 .Ic print , pwd , read , realpath ,
3054 .Ic rename , sleep , suspend , test ,
3055 .Ic true , ulimit , umask , unalias ,
3058 Once the type of command has been determined, any command-line parameter
3059 assignments are performed and exported for the duration of the command.
3061 The following describes the special and regular built-in commands and
3062 builtin-like reserved words:
3064 .Bl -tag -width false -compact
3065 .It Ic \&. Ar file Op Ar arg ...
3069 Execute the commands in
3071 in the current environment.
3072 The file is searched for in the directories of
3074 If arguments are given, the positional parameters may be used to access them
3078 If no arguments are given, the positional parameters are
3079 those of the environment the command is used in.
3081 .It Ic \&: Op Ar ...
3083 Exit status is set to zero.
3085 .It Ic \&[ Ar expression Ic \&]
3090 .Oo Fl d \*(Ba t Oo Fl r Oc \*(Ba
3095 .Op Ns = Ns Ar value
3101 For any name without a value, the existing alias is listed.
3102 Any name with a value defines an alias; see
3105 .Li \&[][A\-Za\-z0\-9_!%,.@:\-]
3106 are valid in names, except they may not begin with a hyphen-minus, and
3108 is not a valid alias name.
3110 When listing aliases, one of two formats is used.
3111 Normally, aliases are listed as
3112 .Ar name Ns = Ns Ar value ,
3116 If options were preceded with
3120 is given on the command line, only
3126 option causes directory aliases which are used in tilde expansion to be
3133 option is used, each alias is prefixed with the string
3138 option indicates that tracked aliases are to be listed/set (values specified on
3139 the command line are ignored for tracked aliases).
3142 option indicates that all tracked aliases are to be reset.
3148 the export attribute of an alias, or, if no names are given, lists the aliases
3149 with the export attribute (exporting an alias has no effect).
3151 .It Ic bg Op Ar job ...
3152 Resume the specified stopped job(s) in the background.
3153 If no jobs are specified,
3158 below for more information.
3161 The current bindings are listed.
3166 instead lists the names of the functions to which keys may be bound.
3168 .Sx Emacs editing mode
3169 for more information.
3171 .It Xo Ic bind Op Fl m
3172 .Ar string Ns = Ns Op Ar substitute
3176 .Ar string Ns = Ns Op Ar editing-command
3179 The specified editing command is bound to the given
3181 which should consist of a control character
3182 optionally preceded by one of the two prefix characters
3183 and optionally succeeded by a tilde character.
3186 will cause the editing command to be immediately invoked.
3189 flag is given, the specified input
3191 will afterwards be immediately replaced by the given
3193 string which may contain editing commands but not other macros.
3194 If a tilde postfix is given, a tilde trailing the one or
3195 two prefices and the control character is ignored, any
3196 other trailing character will be processed afterwards.
3198 Control characters may be written using caret notation
3199 i.e. \*(haX represents Ctrl-X.
3200 The caret itself can be escaped by a backslash, which also escapes itself.
3201 Note that although only three prefix characters (usually ESC, \*(haX and NUL)
3202 are supported, some multi-character sequences can be supported.
3204 The following default bindings show how the arrow keys, the home, end and
3205 delete key on a BSD wsvt25, xterm\-xfree86 or GNU screen terminal are bound
3206 (of course some escape sequences won't work out quite this nicely):
3207 .Bd -literal -offset indent
3208 bind \*(aq\*(haX\*(aq=prefix\-2
3209 bind \*(aq\*(ha[[\*(aq=prefix\-2
3210 bind \*(aq\*(haXA\*(aq=up\-history
3211 bind \*(aq\*(haXB\*(aq=down\-history
3212 bind \*(aq\*(haXC\*(aq=forward\-char
3213 bind \*(aq\*(haXD\*(aq=backward\-char
3214 bind \*(aq\*(haX1\*(TI\*(aq=beginning\-of\-line
3215 bind \*(aq\*(haX7\*(TI\*(aq=beginning\-of\-line
3216 bind \*(aq\*(haXH\*(aq=beginning\-of\-line
3217 bind \*(aq\*(haX4\*(TI\*(aq=end\-of\-line
3218 bind \*(aq\*(haX8\*(TI\*(aq=end\-of\-line
3219 bind \*(aq\*(haXF\*(aq=end\-of\-line
3220 bind \*(aq\*(haX3\*(TI\*(aq=delete\-char\-forward
3223 .It Ic break Op Ar level
3239 .Ar command Op Ar arg ...
3241 Execute the built-in command
3246 .Ar command Op Ar arg ...
3250 Additionally acts as declaration utility forwarder, i.e. this is a
3251 declaration utility (see
3252 .Sx Tilde expansion )
3254 is a declaration utility.
3261 Read files sequentially, in command line order, and write them to
3267 or absent, read from standard input.
3268 For direct builtin calls, the
3271 option is supported as a no-op.
3272 For calls from shell, if any options are given, an external
3274 utility is preferred over the builtin.
3291 Set the working directory to
3295 is set, it lists the search path for the directory containing
3297 An unset or empty path means the current directory.
3300 is found in any component of the
3302 search path other than an unset or empty path,
3303 the name of the new working directory will be written to standard output.
3306 is missing, the home directory
3313 the previous working directory is used (see the
3319 option (logical path) is used or if the
3321 option isn't set (see the
3323 command below), references to
3327 are relative to the path used to get to the directory.
3330 option (physical path) is used or if the
3334 is relative to the filesystem directory tree.
3339 parameters are updated to reflect the current and old working directory,
3343 option is set for physical filesystem traversal and
3345 could not be set, the exit code is 1; greater than 1 if an
3346 error occurred, 0 otherwise.
3362 in the current directory, and the shell attempts to change to the new
3377 is executed exactly as if
3379 had not been specified, with two exceptions:
3382 cannot be a shell function;
3383 and secondly, special built-in commands lose their specialness
3384 (i.e. redirection and utility errors do not cause the shell to
3385 exit, and command assignments are not permanent).
3386 The declaration utility property is not reset.
3390 option is given, a default search path is used instead of the current value of
3392 the actual value of which is system dependent.
3396 option is given, instead of executing
3398 information about what would be executed is given (and the same is done for
3400 For builtins, functions and keywords, their names are simply printed;
3401 for aliases, a command that defines them is printed;
3402 for utilities found by searching the
3404 parameter, the full path of the command is printed.
3405 If no command is found
3406 (i.e. the path search fails), nothing is printed and
3408 exits with a non-zero status.
3413 option, except it is more verbose.
3415 .It Ic continue Op Ar level
3416 Jumps to the beginning of the
3434 this utility is not portable; use the Korn shell builtin
3438 Prints its arguments (separated by spaces) followed by a newline, to the
3440 The newline is suppressed if any of the arguments contain the
3445 command below for a list of other backslash sequences that are recognised.
3447 The options are provided for compatibility with
3452 option suppresses the trailing newline,
3454 enables backslash interpretation (a no-op, since this is normally done), and
3456 suppresses backslash interpretation.
3462 option is set or this is a direct builtin call or
3465 only the first argument is treated as an option, and only if it is exactly
3467 Backslash interpretation is disabled.
3469 .It Ic eval Ar command ...
3470 The arguments are concatenated (with spaces between them) to form a single
3471 string which the shell then parses and executes in the current environment.
3477 .Op Ar command Op Ar arg ...
3479 The command is executed without forking, replacing the shell process.
3480 This is currently absolute, i.e.\&
3482 never returns, even if the
3487 option permits setting a different
3491 clears the environment before executing the child process, except for the
3493 variable and direct assignments.
3495 If no command is given except for I/O redirection, the I/O redirection is
3496 permanent and the shell is
3498 Any file descriptors greater than 2 which are opened or
3500 in this way are not made available to other executed commands (i.e. commands
3501 that are not built-in to the shell).
3502 Note that the Bourne shell differs here;
3503 it does pass these file descriptors on.
3505 .It Ic exit Op Ar status
3506 The shell or subshell exits with the specified exit status.
3509 is not specified, the exit status is the current value of the
3516 .Op Ar parameter Ns Op = Ns Ar value
3518 Sets the export attribute of the named parameters.
3519 Exported parameters are passed in the environment to executed commands.
3520 If values are specified, the named parameters are also assigned.
3521 This is a declaration utility.
3523 If no parameters are specified, all parameters with the export attribute
3524 set are printed one per line; either their names, or, if a
3526 with no option letter is specified, name=value pairs, or, with
3529 commands suitable for re-entry.
3532 A command that exits with a non-zero status.
3536 .Oo Fl e Ar editor \*(Ba
3539 .Op Ar first Op Ar last
3544 select commands from the history.
3545 Commands can be selected by history number
3546 (negative numbers go backwards from the current, most recent, line)
3547 or a string specifying the most recent command starting with that string.
3550 option lists the command on standard output, and
3552 inhibits the default command numbers.
3555 option reverses the order of the list.
3558 the selected commands are edited by the editor specified with the
3562 is specified, the editor specified by the
3564 parameter (if this parameter is not set,
3566 is used), and then executed by the shell.
3570 .Cm \-e \- \*(Ba Fl s
3572 .Op Ar old Ns = Ns Ar new
3575 Re-execute the selected command (the previous command by default) after
3576 performing the optional substitution of
3582 is specified, all occurrences of
3590 is identical: re-execute the selected command without invoking an editor.
3591 This command is usually accessed with the predefined:
3592 .Ic alias r=\*(aqfc \-e \-\*(aq
3594 .It Ic fg Op Ar job ...
3595 Resume the specified job(s) in the foreground.
3596 If no jobs are specified,
3601 below for more information.
3608 Used by shell procedures to parse the specified arguments (or positional
3609 parameters, if no arguments are given) and to check for legal options.
3611 contains the option letters that
3614 If a letter is followed by a colon, the option is expected to
3616 Options that do not take arguments may be grouped in a single argument.
3617 If an option takes an argument and the option character is not the
3618 last character of the argument it is found in, the remainder of the argument is
3619 taken to be the option's argument; otherwise, the next argument is the option's
3624 is invoked, it places the next option in the shell parameter
3626 and the index of the argument to be processed by the next call to
3628 in the shell parameter
3630 If the option was introduced with a
3632 the option placed in
3636 When an option requires an argument,
3638 places it in the shell parameter
3641 When an illegal option or a missing option argument is encountered, a question
3642 mark or a colon is placed in
3644 (indicating an illegal option or missing argument, respectively) and
3646 is set to the option character that caused the problem.
3649 does not begin with a colon, a question mark is placed in
3652 is unset, and an error message is printed to standard error.
3654 When the end of the options is encountered,
3656 exits with a non-zero exit status.
3657 Options end at the first (non-option
3658 argument) argument that does not start with a
3662 argument is encountered.
3664 Option parsing can be reset by setting
3666 to 1 (this is done automatically whenever the shell or a shell procedure is
3669 Warning: Changing the value of the shell parameter
3671 to a value other than 1 or parsing different sets of arguments without
3674 may lead to unexpected results.
3678 .Op Ic +\-aglpnrtUux
3680 .No \*(Ba Fl R Ns Op Ar n
3681 .No \*(Ba Fl Z Ns Op Ar n Oc
3684 .Op Ns = Ns Ar value
3689 .No Deprecated , Em will
3690 be removed from a future version of
3698 Without arguments, any hashed executable command pathnames are listed.
3701 option causes all hashed commands to be removed from the hash table.
3704 is searched as if it were a command name and added to the hash table if it is
3705 an executable command.
3712 Display information about the specified job(s); if no jobs are specified, all
3716 option causes information to be displayed only for jobs that have changed
3717 state since the last notification.
3720 option is used, the process ID of each process in a job is also listed.
3723 option causes only the process group of each job to be printed.
3726 below for the format of
3728 and the displayed job.
3732 .Oo Fl s Ar signame \*(Ba
3733 .No \- Ns Ar signum \*(Ba
3734 .No \- Ns Ar signame Oc
3735 .No { Ar job \*(Ba pid \*(Ba pgrp No }
3738 Send the specified signal to the specified jobs, process IDs or process
3740 If no signal is specified, the
3743 If a job is specified, the signal is sent to the job's process group.
3746 below for the format of
3752 .Op Ar exit-status ...
3754 Print the signal name corresponding to
3756 If no arguments are specified, a list of all the signals with their numbers
3757 and a short description of each are printed.
3759 .It Ic let Op Ar expression ...
3760 Each expression is evaluated (see
3761 .Sx Arithmetic expressions
3763 If all expressions are successfully evaluated, the exit status is 0 (1)
3764 if the last expression evaluated to non-zero (zero).
3765 If an error occurs during
3766 the parsing or evaluation of an expression, the exit status is greater than 1.
3767 Since expressions may need to be quoted,
3768 .No \&(( Ar expr No ))
3769 is syntactic sugar for:
3770 .Dl "{ \e\ebuiltin let \*(aq" Ns Ar expr Ns "\*(aq; }"
3785 Create a device special file.
3786 The file type may be
3788 (block type device),
3790 (character type device)
3793 .Pq named pipe , Tn FIFO .
3794 The file created may be modified according to its
3800 (major device number),
3803 (minor device number).
3804 This is not normally part of
3806 however, distributors may have added this as builtin as a speed hack.
3810 .Oo Fl AcelNnprsu Ns Oo Ar n Oc \*(Ba
3814 Print the specified argument(s) on the standard output,
3815 separated by spaces, terminated with a newline.
3816 The escapes mentioned in
3817 .Sx Backslash expansion
3820 which is equivalent to using the
3822 option, are interpreted.
3824 The options are as follows:
3829 is arithmetically evaluated; the character corresponding to the
3830 resulting value is printed.
3833 separate input words.
3835 The output is printed columnised, line by line, similar to how the
3837 utility, tab completion, the
3839 built-in utility and the
3843 Restore backslash expansion after a previous
3846 Change the output word separator to newline.
3848 Change the output word and line separator to ASCII NUL.
3850 Do not print the trailing line separator.
3852 Print to the co-process (see
3856 Inhibit backslash expansion.
3858 Print to the history file instead of standard output.
3860 Print to the file descriptor
3861 .Ar n Pq defaults to 1 if omitted
3862 instead of standard output.
3867 option mostly emulates the
3870 command which does not expand backslashes and interprets
3871 its first argument as option only if it is exactly
3873 .Pq to suppress the trailing newline .
3876 Print the present working directory.
3879 option is used or if the
3881 option isn't set (see the
3883 command below), the logical path is printed (i.e. the path used to
3885 to the current directory).
3888 option (physical path) is used or if the
3890 option is set, the path determined from the filesystem (by following
3892 directories to the root directory) is printed.
3906 Reads a line of input, separates the input into fields using the
3910 above), and assigns each field to the specified parameters
3912 If no parameters are specified, the
3914 parameter is used to store the result.
3919 options, only no or one parameter is accepted.
3920 If there are more parameters than fields, the extra parameters are set to
3921 the empty string or 0; if there are more fields than parameters, the last
3922 parameter is assigned the remaining fields (including the word separators).
3924 The options are as follows:
3925 .Bl -tag -width XuXnX
3927 Store the result into the parameter
3933 Store the result without word splitting into the parameter
3937 as array of characters (wide characters if the
3939 option is enacted, octets otherwise); the codepoints are
3940 encoded as decimal numbers by default.
3942 Use the first byte of
3945 if empty, instead of the ASCII newline character as input line delimiter.
3947 Instead of reading till end-of-line, read exactly
3950 Upon EOF, a partial read is returned with exit status 1.
3951 After timeout, a partial read is returned with an exit status as if
3955 Instead of reading till end-of-line, read up to
3957 bytes but return as soon as any bytes are read, e.g.\& from a
3958 slow terminal device, or if EOF or a timeout occurs.
3960 Read from the currently active co-process, see
3962 above for details on this.
3964 Read from the file descriptor
3966 (defaults to 0, i.e.\& standard input).
3967 The argument must immediately follow the option character.
3969 Interrupt reading after
3971 seconds (specified as positive decimal value with an optional fractional part).
3976 were caught if the timeout occurred, but partial reads may still be returned.
3978 Normally, the ASCII backslash character escapes the special
3979 meaning of the following character and is stripped from the input;
3981 does not stop when encountering a backslash-newline sequence and
3982 does not store that newline in the result.
3983 This option enables raw mode, in which backslashes are not processed.
3985 The input line is saved to the history.
3988 If the input is a terminal, both the
3992 options set it into raw mode;
3993 they read an entire file if \-1 is passed as
3997 The first parameter may have a question mark and a string appended to it, in
3998 which case the string is used as a prompt (printed to standard error before
3999 any input is read) if the input is a
4002 .Ic read nfoo?\*(aqnumber of foos: \*(aq ) .
4004 If no input is read or a timeout occurred,
4006 exits with a non-zero status.
4012 .Op Ns = Ns Ar value
4015 Sets the read-only attribute of the named parameters.
4016 This is a declaration utility.
4017 If values are given,
4018 parameters are set to them before setting the attribute.
4020 made read-only, it cannot be unset and its value cannot be changed.
4022 If no parameters are specified, the names of all parameters with the read-only
4023 attribute are printed one per line, unless the
4025 option is used, in which case
4027 commands defining all read-only parameters, including their values, are
4035 Prints the resolved absolute pathname corresponding to
4041 it's also checked for existence and whether it is a directory; otherwise,
4043 returns 0 if the pathname either exists or can be created immediately,
4044 i.e. all but the last component exist and are directories.
4045 For calls from the shell, if any options are given, an external
4047 utility is preferred over the builtin.
4058 Both must be complete pathnames and on the same device.
4059 An external utility is preferred over this builtin,
4060 which is intended for emergency situations
4061 .Pq where Pa /bin/mv No becomes unusable
4065 .It Ic return Op Ar status
4066 Returns from a function or
4068 script, with exit status
4072 is given, the exit status of the last executed command is used.
4073 If used outside of a function or
4075 script, it has the same effect as
4079 treats both profile and
4083 scripts, while the original Korn shell only treats profiles as
4088 .Ic set Op Ic +\-abCefhiklmnprsUuvXx
4089 .Op Ic +\-o Ar option
4096 command can be used to set
4100 shell options, set the positional parameters, or set an array parameter.
4101 Options can be changed using the
4105 is the long name of an option, or using the
4106 .Cm +\- Ns Ar letter
4109 is the option's single letter name (not all options have a single letter name).
4110 The following table lists both option letters (if they exist) and long names
4111 along with a description of what the option does:
4114 Sets the elements of the array parameter
4120 is used, the array is reset (i.e. emptied) first; if
4122 is used, the first N elements are set (where N is the number of arguments);
4123 the rest are left untouched.
4125 An alternative syntax for the command
4126 .Ic set \-A foo \-\- a b c
4127 which is compatible to
4130 and also supported by
4134 .Ic foo=(a b c); foo+=(d e)
4135 .It Fl a \*(Ba Fl o Ic allexport
4136 All new parameters are created with the export attribute.
4137 .It Fl b \*(Ba Fl o Ic notify
4138 Print job notification messages asynchronously, instead of just before the
4140 Only used if job control is enabled
4142 .It Fl C \*(Ba Fl o Ic noclobber
4143 Prevent \*(Gt redirection from overwriting existing files.
4144 Instead, \*(Gt\*(Ba must be used to force an overwrite.
4145 Note that this is not safe to use for creation of temporary files or
4146 lockfiles due to a TOCTOU in a check allowing one to redirect output to
4148 or other device files even in
4151 .It Fl e \*(Ba Fl o Ic errexit
4152 Exit (after executing the
4154 trap) as soon as an error occurs or a command fails (i.e. exits with a
4156 This does not apply to commands whose exit status is
4157 explicitly tested by a shell construct such as
4168 only the status of the last command is tested.
4169 .It Fl f \*(Ba Fl o Ic noglob
4170 Do not expand file name patterns.
4171 .It Fl h \*(Ba Fl o Ic trackall
4172 Create tracked aliases for all executed commands (see
4175 Enabled by default for non-interactive shells.
4176 .It Fl i \*(Ba Fl o Ic interactive
4177 The shell is an interactive shell.
4178 This option can only be used when the shell is invoked.
4179 See above for a description of what this means.
4180 .It Fl k \*(Ba Fl o Ic keyword
4181 Parameter assignments are recognised anywhere in a command.
4182 .It Fl l \*(Ba Fl o Ic login
4183 The shell is a login shell.
4184 This option can only be used when the shell is invoked.
4185 See above for a description of what this means.
4186 .It Fl m \*(Ba Fl o Ic monitor
4187 Enable job control (default for interactive shells).
4188 .It Fl n \*(Ba Fl o Ic noexec
4189 Do not execute any commands.
4190 Useful for checking the syntax of scripts
4191 (ignored if interactive).
4192 .It Fl p \*(Ba Fl o Ic privileged
4193 The shell is a privileged shell.
4194 It is set automatically if, when the shell starts,
4195 the real UID or GID does not match
4196 the effective UID (EUID) or GID (EGID), respectively.
4197 See above for a description of what this means.
4198 .It Fl r \*(Ba Fl o Ic restricted
4199 The shell is a restricted shell.
4200 This option can only be used when the shell is invoked.
4201 See above for a description of what this means.
4202 .It Fl s \*(Ba Fl o Ic stdin
4203 If used when the shell is invoked, commands are read from standard input.
4204 Set automatically if the shell is invoked with no arguments.
4210 command it causes the specified arguments to be sorted before assigning them to
4211 the positional parameters (or to array
4216 .It Fl U \*(Ba Fl o Ic utf8\-mode
4217 Enable UTF-8 support in the
4218 .Sx Emacs editing mode
4219 and internal string handling functions.
4220 This flag is disabled by default, but can be enabled by setting it on the
4221 shell command line; is enabled automatically for interactive shells if
4222 requested at compile time, your system supports
4223 .Fn setlocale LC_CTYPE \&""
4225 .Fn nl_langinfo CODESET ,
4231 environment variables,
4232 and at least one of these returns something that matches
4236 case-insensitively; for direct builtin calls depending on the
4237 aforementioned environment variables; or for stdin or scripts,
4238 if the input begins with a UTF-8 Byte Order Mark.
4240 In near future, locale tracking will be implemented, which means that
4242 is changed whenever one of the
4244 locale-related environment variables changes.
4245 .It Fl u \*(Ba Fl o Ic nounset
4246 Referencing of an unset parameter, other than
4250 is treated as an error, unless one of the
4256 .It Fl v \*(Ba Fl o Ic verbose
4257 Write shell input to standard error as it is read.
4258 .It Fl X \*(Ba Fl o Ic markdirs
4259 Mark directories with a trailing
4261 during file name generation.
4262 .It Fl x \*(Ba Fl o Ic xtrace
4263 Print command trees when they are executed, preceded by
4267 Background jobs are run with lower priority.
4268 .It Fl o Ic braceexpand
4269 Enable brace expansion (a.k.a. alternation).
4270 This is enabled by default.
4272 Enable BRL emacs-like command-line editing (interactive shells only); see
4273 .Sx Emacs editing mode .
4275 Enable gmacs-like command-line editing (interactive shells only).
4276 Currently identical to emacs editing except that transpose\-chars (\*(haT) acts
4277 slightly differently.
4278 .It Fl o Ic ignoreeof
4279 The shell will not (easily) exit when end-of-file is read;
4282 To avoid infinite loops, the shell will exit if
4284 is read 13 times in a row.
4285 .It Fl o Ic inherit\-xtrace
4288 upon entering functions.
4289 This is enabled by default.
4291 Do not kill running jobs with a
4293 signal when a login shell exits.
4294 Currently set by default, but this may
4295 change in the future to be compatible with
4299 doesn't have this option, but does send the
4304 In the original Korn shell, this prevents function definitions from
4305 being stored in the history file.
4306 .It Fl o Ic physical
4313 (i.e. the filesystem's)
4315 directories instead of
4317 directories (i.e. the shell handles
4319 which allows the user to be oblivious of symbolic links to directories).
4321 Note that setting this option does not affect the current value of the
4331 commands above for more details.
4332 .It Fl o Ic pipefail
4333 Make the exit status of a pipeline (before logically complementing) the
4334 rightmost non-zero errorlevel, or zero if all commands exited with zero.
4336 Behave closer to the standards
4340 Automatically enabled if the basename of the shell invocation begins with
4342 and this autodetection feature is compiled in
4344 As a side effect, setting this flag turns off the
4348 flags, which can be turned back on manually, and
4350 mode (unless both are enabled at the same time).
4357 Automatically enabled if the basename of the shell invocation begins with
4359 and this autodetection feature is compiled in
4361 As a side effect, setting this flag turns off
4363 mode, which can be turned back on manually, and
4365 mode (unless both are enabled at the same time).
4369 command-line editing (interactive shells only).
4372 for documentation and limitations.
4373 .It Fl o Ic vi\-esccomplete
4374 In vi command-line editing, do command and file name completion when escape
4375 (\*(ha[) is entered in command mode.
4376 .It Fl o Ic vi\-tabcomplete
4377 In vi command-line editing, do command and file name completion when tab (\*(haI)
4378 is entered in insert mode.
4379 This is the default.
4382 In the original Korn shell, unless
4384 was set, the vi command-line mode would let the
4386 driver do the work until ESC (\*(ha[) was entered.
4388 is always in viraw mode.
4391 These options can also be used upon invocation of the shell.
4393 options (with single letter names) can be found in the parameter
4396 with no option name will list all the options and whether each is on or off;
4398 will print the long names of all options that are currently on.
4399 In a future version,
4403 compliant and print commands to restore the current options instead.
4405 Remaining arguments, if any, are positional parameters and are assigned, in
4406 order, to the positional parameters (i.e. $1, $2, etc.).
4409 and there are no remaining arguments, all positional parameters are cleared.
4410 If no options or arguments are given, the values of all names are printed.
4411 For unknown historical reasons, a lone
4413 option is treated specially \*(en it clears both the
4419 .It Ic shift Op Ar number
4420 The positional parameters
4423 etc. are renamed to 1, 2, etc.
4427 .It Ic sleep Ar seconds
4428 Suspends execution for a minimum of the
4430 specified as positive decimal value with an optional fractional part.
4431 Signal delivery may continue execution earlier.
4433 .It Ic source Ar file Op Ar arg ...
4435 .Ic \&. Po Do dot Dc Pc ,
4436 except that the current working directory is appended to the
4442 Stops the shell as if it had received the suspend character from
4444 It is not possible to suspend a login shell unless the parent process
4445 is a member of the same terminal session but is a member of a different
4447 As a general rule, if the shell was started by another shell or via
4449 it can be suspended.
4451 .It Ic test Ar expression
4452 .It Ic \&[ Ar expression Ic \&]
4456 and returns zero status if true, 1 if false, or greater than 1 if there
4458 It is normally used as the condition command of
4463 Symbolic links are followed for all
4470 The following basic expressions are available:
4477 is a block special device.
4480 is a character special device.
4492 group is the shell's effective group ID.
4495 mode has the setgid bit set.
4498 is a context dependent directory (only useful on HP-UX).
4512 owner is the shell's effective user ID.
4519 exists and is readable.
4523 .Xr unix 4 Ns -domain
4536 mode has the setuid bit set.
4539 exists and is writable.
4542 exists and is executable.
4543 .It Ar file1 Fl nt Ar file2
4552 .It Ar file1 Fl ot Ar file2
4561 .It Ar file1 Fl ef Ar file2
4567 has non-zero length.
4583 command above for a list of options).
4584 As a non-standard extension, if the option starts with a
4586 the test is negated; the test always fails if
4588 doesn't exist (so [ \-o foo \-o \-o !foo ] returns true if and only if option
4591 The same can be achieved with [ \-o ?foo ] like in
4595 can also be the short flag led by either
4599 .Pq no logical negation ,
4606 .It Ar string No = Ar string
4608 .It Ar string No == Ar string
4610 .It Ar string No \*(Gt Ar string
4611 First string operand is greater than second string operand.
4612 .It Ar string No \*(Lt Ar string
4613 First string operand is less than second string operand.
4614 .It Ar string No != Ar string
4615 Strings are not equal.
4616 .It Ar number Fl eq Ar number
4617 Numbers compare equal.
4618 .It Ar number Fl ne Ar number
4619 Numbers compare not equal.
4620 .It Ar number Fl ge Ar number
4621 Numbers compare greater than or equal.
4622 .It Ar number Fl gt Ar number
4623 Numbers compare greater than.
4624 .It Ar number Fl le Ar number
4625 Numbers compare less than or equal.
4626 .It Ar number Fl \< Ar number
4627 Numbers compare less than.
4630 The above basic expressions, in which unary operators have precedence over
4631 binary operators, may be combined with the following operators (listed in
4632 increasing order of precedence):
4633 .Bd -literal -offset indent
4634 expr \-o expr Logical OR.
4635 expr \-a expr Logical AND.
4640 Note that a number actually may be an arithmetic expression, such as
4641 a mathematical term or the name of an integer variable:
4642 .Bd -literal -offset indent
4643 x=1; [ "x" \-eq 1 ] evaluates to true
4646 Note that some special rules are applied (courtesy of
4648 ) if the number of arguments to
4650 or inside the brackets
4652 is less than five: if leading
4654 arguments can be stripped such that only one to three arguments remain,
4655 then the lowered comparison is executed; (thanks to XSI) parentheses
4657 lower four- and three-argument forms to two- and one-argument forms,
4658 respectively; three-argument forms ultimately prefer binary operations,
4659 followed by negation and parenthesis lowering; two- and four-argument forms
4660 prefer negation followed by parenthesis; the one-argument form always implies
4664 A common mistake is to use
4665 .Dq Li if \&[ $foo = bar \&]
4666 which fails if parameter
4668 is empty or unset, if it has embedded spaces (i.e.\&
4670 octets) or if it is a unary operator like
4675 .Dq Li if \&[ x\&"$foo\&" = x"bar" \&]
4676 instead, or the double-bracket operator
4677 .Dq Li if \&[[ $foo = bar \&]]
4678 or, to avoid pattern matching (see
4681 .Dq Li if \&[[ $foo = \&"$bar" \&]]
4685 construct is not only more secure to use but also often faster.
4694 is given, the times used to execute the pipeline are reported.
4696 is given, then the user and system time used by the shell itself, and all the
4697 commands it has run since it was started, are reported.
4698 The times reported are the real time (elapsed time from start to finish),
4699 the user CPU time (time spent running in user mode), and the system CPU time
4700 (time spent running in kernel mode).
4701 Times are reported to standard error; the format of the output is:
4703 .Dl "0m0.03s real 0m0.02s user 0m0.01s system"
4707 option is given the output is slightly longer:
4708 .Bd -literal -offset indent
4714 It is an error to specify the
4718 is a simple command.
4720 Simple redirections of standard error do not affect the output of the
4724 .Dl $ time sleep 1 2\*(Gtafile
4725 .Dl $ { time sleep 1; } 2\*(Gtafile
4727 Times for the first command do not go to
4729 but those of the second command do.
4732 Print the accumulated user and system times used both by the shell
4733 and by processes that the shell started which have exited.
4734 The format of the output is:
4735 .Bd -literal -offset indent
4740 .It Ic trap Ar n Op Ar signal ...
4741 If the first operand is a decimal unsigned integer, this resets all
4742 specified signals to the default action, i.e. is the same as calling
4748 followed by the arguments
4749 .Pq Ar n Op Ar signal ... ,
4750 all of which are treated as signals.
4752 .It Ic trap Op Ar handler signal ...
4753 Sets a trap handler that is to be executed when any of the specified
4757 is either an empty string, indicating the signals are to be ignored, a dash
4759 indicating that the default action is to be taken for the signals
4760 .Pq see Xr signal 3 ,
4761 or a string containing shell commands to be executed at the first opportunity
4762 (i.e. when the current command completes or before printing the next
4764 prompt) after receipt of one of the signals.
4766 is the name of a signal
4767 .Pq e.g.\& Dv PIPE or Dv ALRM
4768 or the number of the signal (see the
4772 There are two special signals:
4774 .Pq also known as 0 ,
4775 which is executed when the shell is about to exit, and
4777 which is executed after an error occurs; an error is something
4778 that would cause the shell to exit if the
4781 .Ic set Fl o Ic errexit
4784 handlers are executed in the environment of the last executed command.
4786 Note that, for non-interactive shells, the trap handler cannot be changed
4787 for signals that were ignored when the shell started.
4789 With no arguments, the current state of the traps that have been set since
4790 the shell started is shown as a series of
4793 Note that the output of
4795 cannot be usefully piped to another process (an artifact of the fact that
4796 traps are cleared when subprocesses are created).
4798 The original Korn shell's
4800 trap and the handling of
4804 traps in functions are not yet implemented.
4807 A command that exits with a zero value.
4811 .Op Ic +\-aglpnrtUux
4813 .No \*(Ba Fl R Ns Op Ar n
4814 .No \*(Ba Fl Z Ns Op Ar n Oc
4817 .Op Ns = Ns Ar value
4825 Display or set parameter attributes.
4826 This is a declaration utility.
4829 arguments, parameter attributes are displayed; if no options are used, the
4830 current attributes of all parameters are printed as
4832 commands; if an option is given (or
4834 with no option letter), all parameters and their values with the specified
4835 attributes are printed; if options are introduced with
4837 parameter values are not printed.
4841 arguments are given, the attributes of the named parameters are set
4845 inside a function, this will cause the parameters to be created
4846 (with no value) in the local scope (but see
4848 Values for parameters may optionally be specified.
4851 the change affects all elements of the array, and no value may be specified.
4857 operates on the attributes of functions.
4858 As with parameters, if no
4860 arguments are given,
4861 functions are listed with their values (i.e. definitions) unless
4862 options are introduced with
4864 in which case only the function names are reported.
4867 Indexed array attribute.
4870 Display or set functions and their attributes, instead of parameters.
4872 Do not cause named parameters to be created in
4873 the local scope when called inside a function.
4877 specifies the base to use when displaying the integer (if not specified, the
4878 base given in the first assignment is used).
4879 Parameters with this attribute may
4880 be assigned values containing arithmetic expressions.
4882 Left justify attribute.
4884 specifies the field width.
4887 is not specified, the current width of a parameter (or the width of its first
4888 assigned value) is used.
4889 Leading whitespace (and zeros, if used with the
4891 option) is stripped.
4892 If necessary, values are either truncated or space padded
4893 to fit the field width.
4895 Lower case attribute.
4896 All upper case ASCII characters in values are converted to lower case.
4897 (In the original Korn shell, this parameter meant
4903 Create a bound variable (name reference): any access to the variable
4905 will access the variable
4907 in the current scope (this is different from
4916 is lazily evaluated at the time
4919 This can be used by functions to access variables whose names are
4920 passed as parameters, instead of using
4925 commands that can be used to re-create the attributes and values of
4928 Right justify attribute.
4930 specifies the field width.
4933 is not specified, the current width of a parameter (or the width of its first
4934 assigned value) is used.
4935 Trailing whitespace is stripped.
4936 If necessary, values are either stripped of leading characters or space
4937 padded to make them fit the field width.
4939 Read-only attribute.
4940 Parameters with this attribute may not be assigned to or unset.
4941 Once this attribute is set, it cannot be turned off.
4944 Has no meaning to the shell; provided for application use.
4948 is the trace attribute.
4949 When functions with the trace attribute are executed, the
4952 shell option is temporarily turned on.
4954 Unsigned integer attribute.
4955 Integers are printed as unsigned values (combine with the
4958 This option is not in the original Korn shell.
4960 Upper case attribute.
4961 All lower case ASCII characters in values are converted to upper case.
4962 (In the original Korn shell, this parameter meant
4963 .Dq unsigned integer
4966 option which meant upper case letters would never be used for bases greater
4974 is the undefined attribute.
4977 above for the implications of this.
4980 Parameters are placed in the environment of any executed commands.
4981 Functions cannot be exported for security reasons
4984 Zero fill attribute.
4985 If not combined with
4989 except zero padding is used instead of space padding.
4990 For integers, the number is padded, not the base.
5003 options are changed, all others from this set are cleared,
5004 unless they are also given on the same command line.
5008 .Op Fl aBCcdefHilMmnOPpqrSsTtVvw
5011 Display or set process limits.
5012 If no options are used, the file size limit
5016 if specified, may be either an arithmetic expression or the word
5018 The limits affect the shell and any processes created by the shell after a
5020 Note that some systems may not allow limits to be increased
5022 Also note that the types of limits available are system
5023 dependent \*(en some systems have only the
5025 limit, or not even that, or can set only the soft limits
5028 Display all limits; unless
5030 is used, soft limits are displayed.
5032 Set the socket buffer size to
5036 Set the number of cached threads to
5039 Impose a size limit of
5041 blocks on the size of core dumps.
5043 Impose a size limit of
5045 kibibytes on the size of the data area.
5047 Set the maximum niceness to
5050 Impose a size limit of
5052 blocks on files written by the shell and its child processes (files of any
5055 Set the hard limit only (the default is to set both hard and soft limits).
5057 Set the number of pending signals to
5062 kibibytes on the amount of locked (wired) physical memory.
5064 Set the AIO locked memory to
5070 kibibytes on the amount of physical memory used.
5074 file descriptors that can be open at once.
5076 Set the number of AIO operations to
5079 Limit the number of threads per process to
5084 processes that can be run by the user at any one time.
5092 Set the maximum real-time priority to
5095 Set the soft limit only (the default is to set both hard and soft limits).
5097 Impose a size limit of
5099 kibibytes on the size of the stack area.
5101 Impose a time limit of
5103 real seconds to be used by each process.
5105 Impose a time limit of
5107 CPU seconds spent in user mode to be used by each process.
5109 Set the number of vnode monitors on Haiku to
5114 kibibytes on the amount of virtual memory (address space) used.
5118 kibibytes on the amount of swap space used.
5123 is concerned, a block is 512 bytes.
5130 Display or set the file permission creation mask or umask (see
5134 option is used, the mask displayed or set is symbolic; otherwise, it is an
5137 Symbolic masks are like those used by
5139 When used, they describe what permissions may be made available (as opposed to
5140 octal masks in which a set bit means the corresponding bit is to be cleared).
5143 sets the mask so files will not be readable, writable or executable by
5145 and is equivalent (on most systems) to the octal mask
5153 The aliases for the given names are removed.
5156 option is used, all aliases are removed.
5161 options are used, the indicated operations are carried out on tracked or
5162 directory aliases, respectively.
5169 Unset the named parameters
5177 .Ar parameter Ns \&[*] ,
5178 attributes are kept, only values are unset.
5180 The exit status is non-zero if any of the parameters have the read-only
5181 attribute set, zero otherwise.
5183 .It Ic wait Op Ar job ...
5184 Wait for the specified job(s) to finish.
5187 is that of the last specified job; if the last job is killed by a signal, the
5188 exit status is 128 + the number of the signal (see
5189 .Ic kill Fl l Ar exit-status
5190 above); if the last specified job can't be found (because it never existed or
5191 had already finished), the exit status of
5196 below for the format of
5199 will return if a signal for which a trap has been set is received or if a
5206 If no jobs are specified,
5208 waits for all currently running jobs (if any) to finish and exits with a zero
5210 If job monitoring is enabled, the completion status of jobs is printed
5211 (this is not the case when jobs are explicitly specified).
5220 option, it is the same as
5222 except aliases are not printed as alias command.
5225 option, it is exactly the same as
5229 option differs: the search path is not affected in
5231 but the search is restricted to the path.
5234 Job control refers to the shell's ability to monitor and control jobs which
5235 are processes or groups of processes created for commands or pipelines.
5236 At a minimum, the shell keeps track of the status of the background (i.e.\&
5237 asynchronous) jobs that currently exist; this information can be displayed
5241 If job control is fully enabled (using
5244 .Ic set Fl o Ic monitor ) ,
5245 as it is for interactive shells, the processes of a job are placed in their
5247 Foreground jobs can be stopped by typing the suspend character from
5248 the terminal (normally \*(haZ); jobs can be restarted in either the
5249 foreground or background using the commands
5254 Note that only commands that create processes (e.g. asynchronous commands,
5255 subshell commands and non-built-in, non-function commands) can be stopped;
5260 When a job is created, it is assigned a job number.
5261 For interactive shells, this number is printed inside
5263 followed by the process IDs of the processes in the job when an asynchronous
5265 A job may be referred to in the
5272 commands either by the process ID of the last process in the command pipeline
5275 parameter) or by prefixing the job number with a percent sign
5277 Other percent sequences can also be used to refer to jobs:
5278 .Bl -tag -width "%+ x %% x %XX"
5279 .It %+ \*(Ba %% \*(Ba %
5280 The most recently stopped job or, if there are no stopped jobs, the oldest
5283 The job that would be the
5285 job if the latter did not exist.
5287 The job with job number
5290 The job with its command containing the string
5292 (an error occurs if multiple jobs are matched).
5294 The job with its command starting with the string
5296 (an error occurs if multiple jobs are matched).
5299 When a job changes state (e.g. a background job finishes or foreground job is
5300 stopped), the shell prints the following status information:
5302 .D1 [ Ns Ar number ] Ar flag status command
5305 .Bl -tag -width "command"
5307 is the job number of the job;
5313 character if the job is the
5317 job, respectively, or space if it is neither;
5319 indicates the current state of the job and can be:
5320 .Bl -tag -width "RunningXX"
5321 .It Done Op Ar number
5324 is the exit status of the job which is omitted if the status is zero.
5326 The job has neither stopped nor exited (note that running does not necessarily
5327 mean consuming CPU time \*(en
5328 the process could be blocked waiting for some event).
5329 .It Stopped Op Ar signal
5330 The job was stopped by the indicated
5332 (if no signal is given, the job was stopped by
5334 .It Ar signal-description Op Dq core dumped
5335 The job was killed by a signal (e.g. memory fault, hangup); use
5337 for a list of signal descriptions.
5340 message indicates the process created a core file.
5343 is the command that created the process.
5344 If there are multiple processes in
5345 the job, each process will have a line showing its
5349 if it is different from the status of the previous process.
5352 When an attempt is made to exit the shell while there are jobs in the stopped
5353 state, the shell warns the user that there are stopped jobs and does not exit.
5354 If another attempt is immediately made to exit the shell, the stopped jobs are
5357 signal and the shell exits.
5360 option is not set and there are running jobs when an attempt is made to exit
5361 a login shell, the shell warns the user and does not exit.
5363 is immediately made to exit the shell, the running jobs are sent a
5365 signal and the shell exits.
5367 The state of the controlling terminal can be modified by a command
5368 executed in the foreground, whether or not job control is enabled, but
5369 the modified terminal state is only kept past the job's lifetime and used
5370 for later command invocations if the command exits successfully (i.e.\&
5371 with an exit status of 0).
5372 When such a job is momentarily stopped or restarted, the terminal state
5373 is saved and restored, respectively, but it will not be kept afterwards.
5374 In interactive mode, when line editing is enabled, the terminal state is
5375 saved before being reconfigured by the shell for the line editor, then
5376 restored before running a command.
5379 .Ic set Fl o Ic posix
5384 compliant in places where the defaults or opinions differ.
5387 will still operate with unsigned 32-bit arithmetic; use
5389 if arithmetic on the host
5391 data type, complete with ISO C Undefined Behaviour, is required;
5394 manual page for details.
5395 Most other historic,
5397 .Nm ksh Ns -compatible
5398 or opinionated differences can be disabled by using this mode; these are:
5401 The incompatible GNU
5404 .Ic &\*(Gt Ns Ar file
5407 File descriptors created by I/O redirections are inherited by
5410 Numbers with a leading digit zero are interpreted as octal.
5414 builtin does not interpret backslashes and only supports the exact option
5417 Alias expansion with a trailing space only reruns on command words.
5419 Tilde expansion follows POSIX instead of Korn shell rules.
5427 only lists signal names, all in one line.
5430 does not accept options with a leading
5434 skips builtins, functions and other commands and uses a
5436 search to determine the utility to execute.
5439 Compatibility mode; intended for use with legacy scripts that
5440 cannot easily be fixed; the changes are as follows:
5443 The incompatible GNU
5446 .Ic &\*(Gt Ns Ar file
5449 File descriptors created by I/O redirections are inherited by
5454 builtin does not interpret backslashes and only supports the exact option
5457 .Ev \-DMKSH_MIDNIGHTBSD01ASH_COMPAT .
5459 The substitution operations
5469 .Pf ## Ar pat No } ,
5485 wrongly do not require a parenthesis to be escaped and do not parse extglobs.
5487 The getopt construct from
5489 passes through the errorlevel.
5496 .Ev \-DMKSH_MIDNIGHTBSD01ASH_COMPAT .
5498 .Ss Interactive input line editing
5499 The shell supports three modes of reading command lines from a
5501 in an interactive session, controlled by the
5506 options (at most one of these can be set at once).
5509 Editing modes can be set explicitly using the
5512 If none of these options are enabled,
5513 the shell simply reads lines using the normal
5520 option is set, the shell allows emacs-like editing of the command; similarly,
5523 option is set, the shell allows vi-like editing of the command.
5524 These modes are described in detail in the following sections.
5526 In these editing modes, if a line is longer than the screen width (see the
5534 character is displayed in the last column indicating that there are more
5535 characters after, before and after, or before the current position,
5537 The line is scrolled horizontally as necessary.
5539 Completed lines are pushed into the history, unless they begin with an
5540 IFS octet or IFS white space or are the same as the previous line.
5541 .Ss Emacs editing mode
5544 option is set, interactive input line editing is enabled.
5545 Warning: This mode is
5546 slightly different from the emacs mode in the original Korn shell.
5547 In this mode, various editing commands
5548 (typically bound to one or more control characters) cause immediate actions
5549 without waiting for a newline.
5550 Several editing commands are bound to particular
5551 control characters when the shell is invoked; these bindings can be changed
5556 The following is a list of available editing commands.
5557 Each description starts with the name of the command,
5558 suffixed with a colon;
5561 (if the command can be prefixed with a count); and any keys the command is
5562 bound to by default, written using caret notation
5563 e.g. the ASCII ESC character is written as \*(ha[.
5564 These control sequences are not case sensitive.
5565 A count prefix for a command is entered using the sequence
5566 .Pf \*(ha[ Ns Ar n ,
5569 is a sequence of 1 or more digits.
5570 Unless otherwise specified, if a count is
5571 omitted, it defaults to 1.
5573 Note that editing command names are used only with the
5576 Furthermore, many editing commands are useful only on terminals with
5583 reasonable substitutes and override the default bindings;
5584 their customary values are shown in parentheses below.
5585 The default bindings were chosen to resemble corresponding
5589 .No INTR Pq \*(haC ,
5592 Abort the current command, save it to the history, empty the line buffer and
5593 set the exit state to interrupted.
5594 .It auto\-insert: Op Ar n
5595 Simply causes the character to appear as literal input.
5596 Most ordinary characters are bound to this.
5597 .It Xo backward\-char:
5599 .No \*(haB , \*(haXD , ANSI-CurLeft , PC-CurLeft
5601 Moves the cursor backward
5604 .It Xo backward\-word:
5606 .No \*(ha[b , ANSI-Ctrl-CurLeft , ANSI-Alt-CurLeft
5608 Moves the cursor backward to the beginning of the word; words consist of
5609 alphanumerics, underscore
5614 .It beginning\-of\-history: \*(ha[\*(Lt
5615 Moves to the beginning of the history.
5616 .It beginning\-of\-line: \*(haA, ANSI-Home, PC-Home
5617 Moves the cursor to the beginning of the edited input line.
5618 .It Xo capitalise\-word:
5620 .No \*(ha[C , \*(ha[c
5622 Uppercase the first ASCII character in the next
5624 words, leaving the cursor past the end of the last word.
5625 .It clear\-screen: \*(ha[\*(haL
5626 Prints a compile-time configurable sequence to clear the screen and home
5627 the cursor, redraws the last line of the prompt string and the currently
5629 The default sequence works for almost all standard terminals.
5630 .It comment: \*(ha[#
5631 If the current line does not begin with a comment character, one is added at
5632 the beginning of the line and the line is entered (as if return had been
5633 pressed); otherwise, the existing comment characters are removed and the cursor
5634 is placed at the beginning of the line.
5635 .It complete: \*(ha[\*(ha[
5636 Automatically completes as much as is unique of the command name or the file
5637 name containing the cursor.
5638 If the entire remaining command or file name is
5639 unique, a space is printed after its completion, unless it is a directory name
5643 If there is no command or file name with the current partial word
5644 as its prefix, a bell character is output (usually causing a beep to be
5646 .It complete\-command: \*(haX\*(ha[
5647 Automatically completes as much as is unique of the command name having the
5648 partial word up to the cursor as its prefix, as in the
5651 .It complete\-file: \*(ha[\*(haX
5652 Automatically completes as much as is unique of the file name having the
5653 partial word up to the cursor as its prefix, as in the
5655 command described above.
5656 .It complete\-list: \*(haI, \*(ha[=
5657 Complete as much as is possible of the current word
5658 and list the possible completions for it.
5659 If only one completion is possible,
5663 Note that \*(haI is usually generated by the TAB (tabulator) key.
5664 .It Xo delete\-char\-backward:
5666 .No ERASE Pq \*(haH ,
5671 characters before the cursor.
5672 .It Xo delete\-char\-forward:
5674 .No ANSI-Del , PC-Del
5678 characters after the cursor.
5679 .It Xo delete\-word\-backward:
5681 .No Pfx1+ERASE Pq \*(ha[\*(haH ,
5682 .No WERASE Pq \*(haW ,
5683 .No \*(ha[\*(ha? , \*(ha[\*(haH , \*(ha[h
5687 words before the cursor.
5688 .It Xo delete\-word\-forward:
5692 Deletes characters after the cursor up to the end of
5695 .It Xo down\-history:
5697 .No \*(haN , \*(haXB , ANSI-CurDown , PC-CurDown
5699 Scrolls the history buffer forward
5702 Each input line originally starts just after the last entry
5703 in the history buffer, so
5705 is not useful until either
5706 .Ic search\-history ,
5707 .Ic search\-history\-up
5711 .It Xo downcase\-word:
5713 .No \*(ha[L , \*(ha[l
5724 or the current line, if not specified, interactively.
5725 The actual command executed is
5726 .Ic fc \-e ${VISUAL:\-${EDITOR:\-vi}} Ar n .
5727 .It end\-of\-history: \*(ha[\*(Gt
5728 Moves to the end of the history.
5729 .It end\-of\-line: \*(haE, ANSI-End, PC-End
5730 Moves the cursor to the end of the input line.
5732 Acts as an end-of-file; this is useful because edit-mode input disables
5733 normal terminal input canonicalisation.
5734 .It Xo eot\-or\-delete:
5738 If alone on a line, same as
5741 .Ic delete\-char\-forward .
5742 .It error: (not bound)
5743 Error (ring the bell).
5744 .It evaluate\-region: \*(ha[\*(haE
5745 Evaluates the text between the mark and the cursor position
5746 .Pq the entire line if no mark is set
5747 as function substitution (if it cannot be parsed, the editing state is
5748 unchanged and the bell is rung to signal an error); $? is updated accordingly.
5749 .It exchange\-point\-and\-mark: \*(haX\*(haX
5750 Places the cursor where the mark is and sets the mark to where the cursor was.
5751 .It expand\-file: \*(ha[*
5754 to the current word and replaces the word with the result of performing file
5755 globbing on the word.
5756 If no files match the pattern, the bell is rung.
5757 .It Xo forward\-char:
5759 .No \*(haF , \*(haXC , ANSI-CurRight , PC-CurRight
5761 Moves the cursor forward
5764 .It Xo forward\-word:
5766 .No \*(ha[f , ANSI-Ctrl-CurRight , ANSI-Alt-CurRight
5768 Moves the cursor forward to the end of the
5771 .It Xo goto\-history:
5775 Goes to history number
5780 Deletes the entire input line.
5781 .It kill\-region: \*(haW
5782 Deletes the input between the cursor and the mark.
5783 .It Xo kill\-to\-eol:
5787 Deletes the input from the cursor to the end of the line if
5789 is not specified; otherwise deletes characters between the cursor and column
5792 Prints a sorted, columnated list of command names or file names (if any) that
5793 can complete the partial word containing the cursor.
5794 Directory names have
5797 .It list\-command: \*(haX?
5798 Prints a sorted, columnated list of command names (if any) that can complete
5799 the partial word containing the cursor.
5800 .It list\-file: \*(haX\*(haY
5801 Prints a sorted, columnated list of file names (if any) that can complete the
5802 partial word containing the cursor.
5803 File type indicators are appended as described under
5806 .It newline: \*(haJ , \*(haM
5807 Causes the current input line to be processed by the shell.
5808 The current cursor position may be anywhere on the line.
5809 .It newline\-and\-next: \*(haO
5810 Causes the current input line to be processed by the shell, and the next line
5811 from history becomes the current line.
5812 This is only useful after an
5816 .Ic search\-history\-up .
5821 .It prefix\-1: \*(ha[
5822 Introduces a 2-character command sequence.
5823 .It prefix\-2: \*(haX , \*(ha[[ , \*(ha[O
5824 Introduces a multi-character command sequence.
5825 .It Xo prev\-hist\-word:
5827 .No \*(ha[. , \*(ha[_
5829 The last word or, if given, the
5831 word (zero-based) of the previous (on repeated execution, second-last,
5832 third-last, etc.) command is inserted at the cursor.
5833 Use of this editing command trashes the mark.
5834 .It quote: \*(ha\*(ha , \*(haV
5835 The following character is taken literally rather than as an editing command.
5837 Reprints the last line of the prompt string and the current input line
5839 .It Xo search\-character\-backward:
5843 Search backward in the current line for the
5845 occurrence of the next character typed.
5846 .It Xo search\-character\-forward:
5850 Search forward in the current line for the
5852 occurrence of the next character typed.
5853 .It search\-history: \*(haR
5854 Enter incremental search mode.
5855 The internal history list is searched
5856 backwards for commands matching the input.
5859 in the search string anchors the search.
5860 The escape key will leave search mode.
5861 Other commands, including sequences of escape as
5867 key will be executed after leaving search mode.
5870 command will restore the input line before search started.
5873 commands continue searching backward to the next previous occurrence of the
5875 The history buffer retains only a finite number of lines; the oldest
5876 are discarded as necessary.
5877 .It search\-history\-up: ANSI-PgUp, PC-PgUp
5878 Search backwards through the history buffer for commands whose beginning match
5879 the portion of the input line before the cursor.
5880 When used on an empty line, this has the same effect as
5882 .It search\-history\-down: ANSI-PgDn, PC-PgDn
5883 Search forwards through the history buffer for commands whose beginning match
5884 the portion of the input line before the cursor.
5885 When used on an empty line, this has the same effect as
5887 This is only useful after an
5891 .Ic search\-history\-up .
5892 .It set\-mark\-command: \*(ha[ Ns Aq space
5893 Set the mark at the cursor position.
5894 .It transpose\-chars: \*(haT
5895 If at the end of line or, if the
5897 option is set, this exchanges the two previous characters; otherwise, it
5898 exchanges the previous and current characters and moves the cursor one
5899 character to the right.
5902 .No \*(haP , \*(haXA , ANSI-CurUp , PC-CurUp
5904 Scrolls the history buffer backward
5907 .It Xo upcase\-word:
5909 .No \*(ha[U , \*(ha[u
5914 .It version: \*(ha[\*(haV
5915 Display the version of
5917 The current edit buffer is restored as soon as a key is pressed.
5918 The restoring keypress is processed, unless it is a space.
5920 Inserts the most recently killed text string at the current cursor position.
5921 .It yank\-pop: \*(ha[y
5924 replaces the inserted text string with the next previously killed text string.
5927 The tab completion escapes characters the same way as the following code:
5929 print \-nr \-\- "${x@/[\e"\-\e$\e&\-*:\-?[\e\e\e\`{\-\e}${IFS\-$\*(aq \et\en\*(aq}]/\e\e$KSH_MATCH}"
5933 The vi command-line editing mode is orphaned, yet still functional.
5934 It is 8-bit clean but specifically does not support UTF-8 or MBCS.
5936 The vi command-line editor in
5938 has basically the same commands as the
5940 editor with the following exceptions:
5943 You start out in insert mode.
5945 There are file name and command completion commands:
5946 =, \e, *, \*(haX, \*(haE, \*(haF and, optionally,
5953 command is different (in
5955 it is the last argument command; in
5957 it goes to the start of the current line).
5963 commands move in the opposite direction to the
5967 Commands which don't make sense in a single line editor are not available
5968 (e.g. screen movement commands and
5977 there are two modes:
5982 In insert mode, most characters are simply put in the buffer at the
5983 current cursor position as they are typed; however, some characters are
5985 In particular, the following characters are taken from current
5990 and have their usual meaning (normal values are in parentheses): kill (\*(haU),
5991 erase (\*(ha?), werase (\*(haW), eof (\*(haD), intr (\*(haC) and quit (\*(ha\e).
5993 the above, the following characters are also treated specially in insert mode:
5994 .Bl -tag -width XJXXXXM
5996 Command and file name enumeration (see below).
5998 Command and file name completion (see below).
5999 If used twice in a row, the
6000 list of possible completions is displayed; if used a third time, the completion
6003 Erases previous character.
6004 .It \*(haJ \*(Ba \*(haM
6006 The current line is read, parsed and executed by the shell.
6009 The next character typed is not treated specially (can be used
6010 to insert the characters being described here).
6012 Command and file name expansion (see below).
6014 Puts the editor in command mode (see below).
6016 Optional file name and command completion (see
6018 above), enabled with
6019 .Ic set Fl o Ic vi\-tabcomplete .
6022 In command mode, each character is interpreted as a command.
6024 don't correspond to commands, are illegal combinations of commands, or are
6025 commands that can't be carried out, all cause beeps.
6026 In the following command descriptions, an
6028 indicates the command may be prefixed by a number (e.g.\&
6030 moves right 10 characters); if no number prefix is used,
6032 is assumed to be 1 unless otherwise specified.
6034 .Dq current position
6035 refers to the position between the cursor and the character preceding the
6039 is a sequence of letters, digits and underscore characters or a sequence of
6040 non-letter, non-digit, non-underscore and non-whitespace characters (e.g.\&
6042 contains two words) and a
6044 is a sequence of non-whitespace characters.
6050 The following commands are not in, or are different from, the normal vi file
6056 Insert a space followed by the
6058 big-word from the last command in the history at the current position and enter
6061 is not specified, the last word is inserted.
6063 Insert the comment character
6065 at the start of the current line and return the line to the shell (equivalent
6075 is not specified, it goes to the most recent remembered line.
6085 is not specified, the current line is edited.
6086 The actual command executed is
6087 .Ic fc \-e ${VISUAL:\-${EDITOR:\-vi}} Ar n .
6089 Command or file name expansion is applied to the current big-word (with an
6092 if the word contains no file globbing characters) \*(en the big-word is replaced
6093 with the resulting words.
6094 If the current big-word is the first on the line
6095 or follows one of the characters
6102 and does not contain a slash
6104 then command expansion is done; otherwise file name expansion is done.
6105 Command expansion will match the big-word against all aliases, functions and
6106 built-in commands as well as any executable files found by searching the
6110 File name expansion matches the big-word against the files in the
6112 After expansion, the cursor is placed just past the last
6113 word and the editor is in insert mode.
6116 .Oo Ar n Oc Ns \*(haF ,
6117 .Oo Ar n Oc Ns Aq tab ,
6119 .Oo Ar n Oc Ns Aq esc
6121 Command/file name completion.
6122 Replace the current big-word with the
6123 longest unique match obtained after performing command and file name expansion.
6125 is only recognised if the
6127 option is set, while
6129 is only recognised if the
6137 possible completion is selected (as reported by the command/file name
6138 enumeration command).
6140 Command/file name enumeration.
6141 List all the commands or files that match the current big-word.
6143 Display the version of
6145 The current edit buffer is restored as soon as a key is pressed.
6146 The restoring keypress is ignored.
6149 Execute the commands found in the alias
6153 Intra-line movement commands:
6156 .Oo Ar n Oc Ns h and
6157 .Oo Ar n Oc Ns \*(haH
6163 .Oo Ar n Oc Ns l and
6164 .Oo Ar n Oc Ns Aq space
6172 Move to the first non-whitespace character.
6174 .Oo Ar n Oc Ns \*(Ba
6179 Move to the last character.
6195 Move forward to the end of the word,
6201 Move forward to the end of the big-word,
6218 The editor looks forward for the nearest parenthesis, bracket or
6219 brace and then moves the cursor to the matching parenthesis, bracket or brace.
6221 .Oo Ar n Oc Ns f Ns Ar c
6225 occurrence of the character
6228 .Oo Ar n Oc Ns F Ns Ar c
6230 Move backward to the
6232 occurrence of the character
6235 .Oo Ar n Oc Ns t Ns Ar c
6237 Move forward to just before the
6239 occurrence of the character
6242 .Oo Ar n Oc Ns T Ns Ar c
6244 Move backward to just before the
6246 occurrence of the character
6263 command, but moves in the opposite direction.
6266 Inter-line movement commands:
6272 .Oo Ar n Oc Ns \*(haN
6276 next line in the history.
6281 .Oo Ar n Oc Ns \*(haP
6285 previous line in the history.
6293 is not specified, the number of the first remembered line is used.
6301 is not specified, it goes to the most recent remembered line.
6303 .Oo Ar n Oc Ns / Ns Ar string
6305 Search backward through the history for the
6313 the remainder of the string must appear at the start of the history line for
6316 .Oo Ar n Oc Ns \&? Ns Ar string
6320 except it searches forward through the history.
6326 occurrence of the last search string;
6327 the direction of the search is the same as the last search.
6333 occurrence of the last search string;
6334 the direction of the search is the opposite of the last search.
6335 .It Ar ANSI-CurUp , PC-PgUp
6336 Take the characters from the beginning of the line to the current
6337 cursor position as search string and do a backwards history search
6338 for lines beginning with this string; keep the cursor position.
6339 This works only in insert mode and keeps it enabled.
6349 times; goes into insert mode just after the current position.
6351 only replicated if command mode is re-entered i.e.\&
6359 except it appends at the end of the line.
6365 times; goes into insert mode at the current position.
6366 The insertion is only
6367 replicated if command mode is re-entered i.e.\&
6375 except the insertion is done just before the first non-blank character.
6381 characters (i.e. delete the characters and go into insert mode).
6383 Substitute whole line.
6384 All characters from the first non-blank character to the
6385 end of the line are deleted and insert mode is entered.
6387 .Oo Ar n Oc Ns c Ns Ar move-cmd
6389 Change from the current position to the position resulting from
6391 (i.e. delete the indicated region and go into insert mode); if
6395 the line starting from the first non-blank character is changed.
6397 Change from the current position to the end of the line (i.e. delete to the
6398 end of the line and go into insert mode).
6412 Delete to the end of the line.
6414 .Oo Ar n Oc Ns d Ns Ar move-cmd
6416 Delete from the current position to the position resulting from
6417 .Ar n move-cmd Ns s ;
6419 is a movement command (see above) or
6421 in which case the current line is deleted.
6423 .Oo Ar n Oc Ns r Ns Ar c
6427 characters with the character
6433 Enter insert mode but overwrite existing characters instead of
6434 inserting before existing characters.
6435 The replacement is repeated
6439 .Oo Ar n Oc Ns \*(TI
6441 Change the case of the next
6445 .Oo Ar n Oc Ns y Ns Ar move-cmd
6447 Yank from the current position to the position resulting from
6449 into the yank buffer; if
6453 the whole line is yanked.
6455 Yank from the current position to the end of the line.
6459 Paste the contents of the yank buffer just after the current position,
6467 except the buffer is pasted at the current position.
6470 Miscellaneous vi commands
6472 .It \*(haJ and \*(haM
6473 The current line is read, parsed and executed by the shell.
6474 .It \*(haL and \*(haR
6475 Redraw the current line.
6479 Redo the last edit command
6483 Undo the last edit command.
6485 Undo all changes that have been made to the current line.
6486 .It PC Home, End, Del and cursor keys
6487 They move as expected, both in insert and command mode.
6488 .It Ar intr No and Ar quit
6489 The interrupt and quit terminal characters cause the current line to be
6490 removed to the history and a new prompt to be printed.
6493 .Bl -tag -width XetcXsuid_profile -compact
6494 .It Pa \*(TI/.mkshrc
6495 User mkshrc profile (non-privileged interactive shells); see
6497 The location can be changed at compile time (for embedded systems);
6498 AOSP Android builds use
6499 .Pa /system/etc/mkshrc .
6500 .It Pa \*(TI/.profile
6501 User profile (non-privileged login shells); see
6503 near the top of this manual.
6505 System profile (login shells); see
6509 .It Pa /etc/suid_profile
6510 Suid profile (privileged shells); see
6516 contains the system and suid profile.
6548 .Pa http://www.mirbsd.org/ksh\-chan.htm
6551 .%B "The KornShell Command and Programming Language"
6553 .%I "Prentice Hall PTR"
6554 .%P "xvi\ +\ 356 pages"
6555 .%O "ISBN 978\-0\-13\-516972\-8 (0\-13\-516972\-0)"
6558 .%A Morris I. Bolsky
6560 .%B "The New KornShell Command and Programming Language (2nd Edition)"
6562 .%I "Prentice Hall PTR"
6563 .%P "xvi\ +\ 400 pages"
6564 .%O "ISBN 978\-0\-13\-182700\-4 (0\-13\-182700\-6)"
6567 .%A Stephen G. Kochan
6569 .%B "\\*(tNUNIX\\*(sP Shell Programming"
6573 .%P "xiii\ +\ 437 pages"
6574 .%O "ISBN 978\-0\-672\-32490\-1 (0\-672\-32490\-3)"
6578 .%T "\\*(tNIEEE\\*(sP Standard for Information Technology \*(en Portable Operating System Interface (POSIX)"
6579 .%V "Part 2: Shell and Utilities"
6582 .%P "xvii\ +\ 1195 pages"
6583 .%O "ISBN 978\-1\-55937\-255\-8 (1\-55937\-255\-9)"
6587 .%B "Learning the Korn Shell"
6591 .%O "ISBN 978\-1\-56592\-054\-5 (1\-56592\-054\-6)"
6596 .%B "Learning the Korn Shell, Second Edition"
6600 .%O "ISBN 978\-0\-596\-00195\-7 (0\-596\-00195\-9)"
6604 .%B "KornShell Programming Tutorial"
6606 .%I "Addison-Wesley Professional"
6607 .%P "xxi\ +\ 324 pages"
6608 .%O "ISBN 978\-0\-201\-56324\-5 (0\-201\-56324\-X)"
6612 .Nm "The MirBSD Korn Shell"
6614 .An mirabilos Aq Mt m@mirbsd.org
6615 as part of The MirOS Project.
6616 This shell is based on the public domain 7th edition Bourne shell clone by
6617 .An Charles Forsyth ,
6618 who kindly agreed to, in countries where the Public Domain status of the work
6619 may not be valid, grant a copyright licence to the general public to deal in
6620 the work without restriction and permission to sublicence derivatives under
6621 the terms of any (OSI approved) Open Source licence,
6622 and parts of the BRL shell by
6626 .An Arnold Robbins ,
6629 The first release of
6633 and it was subsequently maintained by
6634 .An John R. MacMillan ,
6635 .An Simon J. Gerraty
6637 .An Michael Rendell .
6638 The effort of several projects, such as Debian and OpenBSD, and other
6639 contributors including our users, to improve the shell is appreciated.
6640 See the documentation, website and source code (CVS) for details.
6644 .An KO Myung-Hun Aq Mt komh@chollian.net .
6648 .An Michael Langguth Aq Mt lan@scalaris.com .
6650 .Nm mksh Ns / Ns Tn z/OS
6652 .An Daniel Richard G. Aq Mt skunk@iSKUNK.ORG .
6654 The BSD daemon is Copyright \(co Marshall Kirk McKusick.
6655 The complete legalese is at:
6656 .Pa http://www.mirbsd.org/TaC\-mksh.txt
6658 .\" This boils down to: feel free to use mksh.ico as application icon
6659 .\" or shortcut for mksh or mksh/Win32 or OS/2; distro patches are ok
6660 .\" (but we request they amend $KSH_VERSION when modifying mksh).
6661 .\" Authors are Marshall Kirk McKusick (UCB), Rick Collette (ekkoBSD),
6662 .\" mirabilos, Benny Siegert (MirBSD), Michael Langguth (mksh/Win32),
6663 .\" KO Myung-Hun (mksh for OS/2).
6665 .\" As far as MirBSD is concerned, the files themselves are free
6666 .\" to modification and distribution under BSD/MirOS Licence, the
6667 .\" restriction on use stems only from trademark law's requirement
6668 .\" to protect it or lose it, which McKusick almost did.
6672 provides a consistent 32-bit integer arithmetic implementation, both
6673 signed and unsigned, with sign of the result of a remainder operation
6674 and wraparound defined, even (defying POSIX) on 36-bit and 64-bit systems.
6677 provides a consistent, clear interface normally.
6678 This may deviate from POSIX in historic or opinionated places.
6679 .Ic set Fl o Ic posix
6683 will cause the shell to behave more conformant.
6694 be disabled in POSIX mode, and it
6695 only supports the BMP (Basic Multilingual Plane) of UCS and maps
6696 raw octets into the U+EF80..U+EFFF wide character range; compare
6697 .Sx Arithmetic expressions .
6700 .Nm sh Ns -compatible
6703 option dependent on the current
6705 locale for mksh to allow using the UTF-8 mode, within the constraints
6706 outlined above, in code portable across various shell implementations:
6707 .Bd -literal -offset indent
6708 case ${KSH_VERSION:\-} in
6709 *MIRBSD\ KSH*\*(Ba*LEGACY\ KSH*)
6710 case ${LC_ALL:\-${LC_CTYPE:\-${LANG:\-}}} in
6711 *[Uu][Tt][Ff]8*\*(Ba*[Uu][Tt][Ff]\-8*) set \-U ;;
6716 In near future, (UTF-8) locale tracking will be implemented though.
6719 .Ic set Fl o Ic pipefail
6720 makes the following construct error out:
6721 .Bd -literal -offset indent
6727 This is because, while the
6729 ensures that the inner command's failure is not taken, it sets
6730 the entire for..done loop's errorlevel, which is passed on by
6732 Invert the inner command:
6733 .Li true \*(Ba\*(Ba echo $x
6735 See also the FAQ below.
6737 Suspending (using \*(haZ) pipelines like the one below will only suspend
6738 the currently running part of the pipeline; in this example,
6740 is immediately printed on suspension (but not later after an
6742 .Bd -literal -offset indent
6743 $ /bin/sleep 666 && echo fubar
6746 The truncation process involved when changing
6748 does not free old history entries (leaks memory) and leaks
6749 old entries into the new history if their line numbers are
6750 not overwritten by same-number entries from the persistent
6751 history file; truncating the on-disc file to
6753 lines has always been broken and prone to history file corruption
6754 when multiple shells are accessing the file; the rollover process
6755 for the in-memory portion of the history is slow, should use
6758 This document attempts to describe
6761 .\" with vendor patches from insert-your-name-here,
6762 compiled without any options impacting functionality, such as
6766 which, on some systems only, enables
6767 .Ic set Fl o Ic posix
6770 automatically (whose behaviour differs across targets),
6771 for an operating environment supporting all of its advanced needs.
6773 Please report bugs in
6775 to the public development mailing list at
6776 .Aq Mt miros\-mksh@mirbsd.org
6777 (please note the EU-DSGVO/GDPR notice on
6778 .Pa http://www.mirbsd.org/rss.htm#lists
6779 and in the SMTP banner!) or in the
6783 .Pa irc.freenode.net
6784 .Pq Port 6697 SSL, 6667 unencrypted ,
6786 .Pa https://launchpad.net/mksh
6787 .Sh FREQUENTLY ASKED QUESTIONS
6788 This FAQ attempts to document some of the questions users of
6790 or readers of this manual page may encounter.
6791 .Ss I'm an Android user, so what's mksh?
6795 shell / command interpreter, similar to
6799 which has been included with
6800 .Tn Android Open Source Project
6802 Basically, it's a program that runs in a terminal (console window),
6803 takes user input and runs commands or scripts, which it can also
6804 be asked to do by other programs, even in the background.
6805 Any privilege pop-ups you might be encountering are thus not
6807 issues but questions by some other program utilising it.
6808 .Ss "I'm an OS/2 user, what do I need to know?"
6809 Unlike the native command prompt, the current working directory is,
6810 for security reasons common on Unix systems which the shell is designed for,
6811 not in the search path at all; if you really need this, run the command
6812 .Li PATH=.$PATHSEP$PATH
6813 or add that to a suitable initialisation file.
6815 There are two different newline modes for mksh-os2: standard (Unix) mode,
6816 in which only LF (0A hex) is supported as line separator, and "textmode",
6817 which also accepts ASCII newlines (CR+LF), like most other tools on OS/2,
6818 but creating an incompatibility with standard
6820 If you compiled mksh from source, you will get the standard Unix mode unless
6822 is added during compilation; you will most likely have gotten this shell
6823 through komh's port on Hobbes, or from his OS/2 Factory on eComStation
6824 Korea, which uses "textmode", though.
6825 Most OS/2 users will want to use "textmode" unless they need absolute
6826 compatibility with Unix
6828 .Ss "How do I start mksh on a specific terminal?"
6830 .Dl mksh \-T/dev/tty2
6832 However, if you want for it to return (e.g. for an embedded
6833 system rescue shell), use this on your real console device instead:
6834 .Dl mksh \-T!/dev/ttyACM0
6837 can also daemonise (send to the background):
6838 .Dl mksh \-T\- \-c \*(aqexec cdio lock\*(aq
6840 Run the shell in POSIX mode (and possibly
6845 .Ss "I forbid stat(2) in my SELinux policy, and some things do not work!"
6847 Read up on the GIGO principle.
6849 .Ss "My prompt from <some other shell> does not work!"
6850 Contact us on the mailing list or on IRC, we'll convert it for you.
6851 .Ss "Something is going wrong with my while...read loop"
6852 Most likely, you've encountered the problem in which the shell runs
6853 all parts of a pipeline as subshell.
6854 The inner loop will be executed in a subshell and variable changes
6855 cannot be propagated if run in a pipeline:
6856 .Bd -literal -offset indent
6857 bar \*(Ba baz \*(Ba while read foo; do ...; done
6862 in the inner loop will only exit the subshell and not the original shell.
6863 Likewise, if the code is inside a function,
6865 in the inner loop will only exit the subshell and won't terminate the function.
6867 Use co-processes instead:
6868 .Bd -literal -offset indent
6869 bar \*(Ba baz \*(Ba&
6870 while read \-p foo; do ...; done
6871 exec 3\*(Gt&p; exec 3\*(Gt&\-
6876 is run in a loop such as
6877 .Ic while read foo; do ...; done
6878 then leading whitespace will be removed (IFS) and backslashes processed.
6879 You might want to use
6880 .Ic while IFS= read \-r foo; do ...; done
6882 Similarly, when using the
6886 option might be prudent
6887 .Pq Dq Li read \-raN\-1 arr \*(Ltfile ;
6888 the same applies for NUL-terminated lines:
6889 .Bd -literal -offset indent
6890 find . \-type f \-print0 \*(Ba& \e
6891 while IFS= read \-d \*(aq\*(aq \-pr filename; do
6892 print \-r \-\- "found \*(Lt${filename#./}\*(Gt"
6896 .Ss "What differences in function-local scopes are there?"
6898 has a different scope model from
6901 which leads to subtle differences in semantics for identical builtins.
6902 This can cause issues with a
6904 to suddenly point to a local variable by accident.
6908 allows unsetting local variables; in
6910 doing so in a function allows back access to the global variable
6911 (actually the one in the next scope up) with the same name.
6912 The following code, when run before the function definitions, changes
6915 to behave like other shells (the alias can be removed after the definitions):
6916 .Bd -literal -offset indent
6917 case ${KSH_VERSION:\-} in
6918 *MIRBSD\ KSH*\*(Ba*LEGACY\ KSH*)
6919 function unset_compat {
6920 \e\ebuiltin typeset unset_compat_x
6922 for unset_compat_x in "$@"; do
6923 eval "\e\e\e\ebuiltin unset $unset_compat_x[*]"
6926 \e\ebuiltin alias unset=unset_compat
6931 When a local variable is created (e.g. using
6935 .Ic \e\ebuiltin typeset )
6936 it does not, like in other shells, inherit the value from the global
6937 (next scope up) variable with the same name; it is rather created
6938 without any value (unset but defined).
6939 .Ss "I get an error in this regex comparison"
6940 Use extglobs instead of regexes:
6941 .Dl "[[ foo =~ (foo\*(Babar).*baz ]] # becomes"
6942 .Dl "[[ foo = *@(foo\*(Babar)*baz* ]] # instead"
6943 .Ss "Are there any extensions to avoid?"
6948 .Pq and Dq Li \*(Ba&
6949 to redirect both stdout and stderr in one go, but this breaks POSIX
6950 and Korn Shell syntax; use POSIX redirections instead:
6951 .Dl "foo \*(Ba& bar \*(Ba& baz &\*(Gtlog # GNU bash"
6952 .Dl "foo 2\*(Gt&1 \*(Ba bar 2\*(Gt&1 \*(Ba baz \*(Gtlog 2\*(Gt&1 # POSIX"
6953 .Ss "\*(haL (Ctrl-L) does not clear the screen"
6954 Use \*(ha[\*(haL (Escape+Ctrl-L) or rebind it:
6955 .Dl bind \*(aq\*(haL=clear-screen\*(aq
6956 .Ss "\*(haU (Ctrl-U) clears the entire line"
6957 If it should only delete the line up to the cursor, use:
6958 .Dl bind \-m \*(haU=\*(aq\*(ha[0\*(haK\*(aq
6959 .Ss "Cursor Up behaves differently from zsh"
6960 Some shells make Cursor Up search in the history only for
6961 commands starting with what was already entered.
6963 separates the shortcuts: Cursor Up goes up one command
6964 and PgUp searches the history as described above.
6965 .Ss "My question is not answered here!"
6967 .Pa http://www.mirbsd.org/mksh\-faq.htm
6968 which contains a collection of frequently asked questions about
6970 in general, for packagers, etc. while these above are in user scope.