1 .\" $OpenBSD: ksh.1,v 1.201 2018/06/18 17:03:58 millert Exp $
5 .Dd $Mdocdate: June 18 2018 $
11 .Nd public domain Korn shell
15 .Op Fl +abCefhiklmnpruvXx
17 .Op Fl c Ar string | Fl s | Ar file Op Ar argument ...
21 is a command interpreter intended for both interactive and shell
23 Its command language is a superset of the
27 The options are as follows:
31 will execute the command(s) contained in
38 option is used or if both standard input and standard error are attached
41 An interactive shell has job control enabled, ignores the
46 signals, and prints prompts before reading input (see the
51 For non-interactive shells, the
53 option is on by default (see the
58 If the basename the shell is called with (i.e. argv[0])
61 or if this option is used,
62 the shell is assumed to be a login shell and the shell reads and executes
67 if they exist and are readable.
72 if this option is used
73 or if the real user ID or group ID does not match the
74 effective user ID or group ID (see
78 A privileged shell does not process
82 parameter (see below).
86 Clearing the privileged option causes the shell to set
87 its effective user ID (group ID) to its real user ID (group ID).
94 if the basename the shell was invoked with was
100 The following restrictions come into effect after the shell processes any
116 parameters cannot be changed.
118 Command names can't be specified with absolute or relative paths.
122 option of the built-in command
126 Redirections that create files can't be used (i.e.\&
133 The shell reads commands from standard input; all non-option arguments
134 are positional parameters.
137 In addition to the above, the options described in the
139 built-in command can also be used on the command line:
141 .Op Fl +abCefhkmnuvXx
144 can be used for single letter or long options, respectively.
150 option is specified, the first non-option argument specifies the name
151 of a file the shell reads commands from.
152 If there are no non-option
153 arguments, the shell reads commands from the standard input.
154 The name of the shell (i.e. the contents of $0)
155 is determined as follows: if the
157 option is used and there is a non-option argument, it is used as the name;
158 if commands are being read from a file, the file is used as the name;
159 otherwise, the basename the shell was called with (i.e. argv[0]) is used.
163 parameter is set when an interactive shell starts (or,
164 in the case of login shells,
165 after any profiles are processed), its value is subjected to parameter,
166 command, arithmetic, and tilde
168 substitution and the resulting file
169 (if any) is read and executed.
170 In order to have an interactive (as opposed to login) shell
171 process a startup file,
173 may be set and exported (see below) in
175 \- future interactive shell invocations will process any file pointed to by
178 .Dl export ENV=$HOME/.kshrc
181 is then free to specify instructions for interactive shells.
182 For example, the global configuration file may be sourced:
183 .Bd -literal -offset indent
187 The above strategy may be employed to keep
188 setup procedures for login shells in
190 and setup procedures for interactive shells in
192 Of course, since login shells are also interactive,
193 any commands placed in
195 will be executed by login shells too.
197 The exit status of the shell is 127 if the command file specified on the
198 command line could not be opened, or non-zero if a fatal syntax error
199 occurred during the execution of a script.
200 In the absence of fatal errors,
201 the exit status is that of the last command executed, or zero, if no
204 The shell begins parsing its input by breaking it into
206 Words, which are sequences of characters, are delimited by unquoted whitespace
207 characters (space, tab, and newline) or meta-characters
218 Aside from delimiting words, spaces and tabs are ignored, while newlines
219 usually delimit commands.
220 The meta-characters are used in building the following
228 etc. are used to specify redirections (see
229 .Sx Input/output redirection
232 is used to create pipelines;
234 is used to create co-processes (see
238 is used to separate commands;
240 is used to create asynchronous pipelines;
244 are used to specify conditional execution;
250 is used in arithmetic expressions;
253 is used to create subshells.
255 Whitespace and meta-characters can be quoted individually using a backslash
257 or in groups using double
262 The following characters are also treated specially by the
263 shell and must be quoted if they are to represent themselves:
277 The first three of these are the above mentioned quoting characters (see
281 if used at the beginning of a word, introduces a comment \(em everything after
284 up to the nearest newline is ignored;
286 is used to introduce parameter, command, and arithmetic substitutions (see
290 introduces an old-style command substitution (see
294 begins a directory expansion (see
310 are used in file name generation (see
311 .Sx File name patterns
314 As words and tokens are parsed, the shell builds commands, of which there
316 .Em simple-commands ,
317 typically programs that are executed, and
318 .Em compound-commands ,
323 statements, grouping constructs, and function definitions.
325 A simple-command consists of some combination of parameter assignments
329 input/output redirections (see
330 .Sx Input/output redirections
332 and command words; the only restriction is that parameter assignments come
333 before any command words.
334 The command words, if any, define the command
335 that is to be executed and its arguments.
336 The command may be a shell built-in command, a function,
337 or an external command
338 (i.e. a separate executable file that is located using the
341 .Sx Command execution
344 All command constructs have an exit status.
345 For external commands,
346 this is related to the status returned by
348 (if the command could not be found, the exit status is 127; if it could not
349 be executed, the exit status is 126).
350 The exit status of other command
351 constructs (built-in commands, functions, compound-commands, pipelines, lists,
352 etc.) are all well-defined and are described where the construct is
354 The exit status of a command consisting only of parameter
355 assignments is that of the last command substitution performed during the
356 parameter assignment or 0 if there were no command substitutions.
358 Commands can be chained together using the
360 token to form pipelines, in which the standard output of each command but the
363 to the standard input of the following command.
364 The exit status of a pipeline is that of its last command.
365 A pipeline may be prefixed by the
367 reserved word, which causes the exit status of the pipeline to be logically
368 complemented: if the original status was 0, the complemented status will be 1;
369 if the original status was not 0, the complemented status will be 0.
372 of commands can be created by separating pipelines by any of the following
380 The first two are for conditional execution:
381 .Dq Ar cmd1 No && Ar cmd2
384 only if the exit status of
390 is executed only if the exit status of
396 have equal precedence which is higher than that of
401 which also have equal precedence.
407 .Qq left-associative .
408 For example, both of these commands will print only
410 .Bd -literal -offset indent
411 $ false && echo foo || echo bar
412 $ true || echo foo && echo bar
417 token causes the preceding command to be executed asynchronously; that is,
418 the shell starts the command but does not wait for it to complete (the shell
419 does keep track of the status of asynchronous commands; see
422 When an asynchronous command is started when job control is disabled
423 (i.e. in most scripts), the command is started with signals
427 ignored and with input redirected from
429 (however, redirections specified in the asynchronous command have precedence).
432 operator starts a co-process which is a special kind of asynchronous process
436 A command must follow the
440 operators, while it need not follow
445 The exit status of a list is that of the last command executed, with the
446 exception of asynchronous lists, for which the exit status is 0.
448 Compound commands are created using the following reserved words.
450 are only recognized if they are unquoted and if they are used as the first
451 word of a command (i.e. they can't be preceded by parameter assignments or
453 .Bd -literal -offset indent
454 case esac in until (( }
457 elif function then ( ]]
462 Some shells (but not this one) execute control structure commands in a
463 subshell when one or more of their file descriptors are redirected, so any
464 environment changes inside them may fail.
467 statement should be used instead to redirect file descriptors before the
470 In the following compound command descriptions, command lists (denoted as
472 that are followed by reserved words must end with a semicolon, a newline, or
473 a (syntactically correct) reserved word.
474 For example, the following are all valid:
475 .Bd -literal -offset indent
476 $ { echo foo; echo bar; }
477 $ { echo foo; echo bar<newline> }
478 $ { { echo foo; echo bar; } }
483 .Dl $ { echo foo; echo bar }
489 There is no implicit way to pass environment changes from a
490 subshell back to its parent.
494 is executed, but not in a subshell.
499 are reserved words, not meta-characters.
500 .It Xo Ic case Ar word Cm in
505 .Ar list No ;;\ \& Oc ... Cm esac
509 statement attempts to match
515 associated with the first successfully matched pattern is executed.
518 statements are the same as those used for file name patterns except that the
519 restrictions regarding
524 Note that any unquoted space before and after a pattern is
525 stripped; any space within a pattern must be quoted.
526 Both the word and the
527 patterns are subject to parameter, command, and arithmetic substitution, as
528 well as tilde substitution.
529 For historical reasons, open and close braces may be used instead of
534 .Ic case $foo { *) echo bar; } .
537 statement is that of the executed
541 is executed, the exit status is zero.
542 .It Xo Ic for Ar name
543 .Oo Cm in Ar word No ... Oc ;
544 .Cm do Ar list ; Cm done
548 in the specified word list, the parameter
550 is set to the word and
555 is not used to specify a word list, the positional parameters
558 For historical reasons, open and close braces may be used instead of
563 .Ic for i; { echo $i; } .
566 statement is the last exit status of
570 is never executed, the exit status is zero.
571 .It Xo Ic if Ar list ;
573 .Oo Cm elif Ar list ;
574 .Cm then Ar list ; Oc ...
575 .Oo Cm else Ar list ; Oc
578 If the exit status of the first
582 is executed; otherwise, the
586 if any, is executed with similar consequences.
587 If all the lists following the
591 fail (i.e. exit with non-zero status), the
596 The exit status of an
598 statement is that of non-conditional
600 that is executed; if no non-conditional
602 is executed, the exit status is zero.
603 .It Xo Ic select Ar name
604 .Oo Cm in Ar word No ... Oc ;
605 .Cm do Ar list ; Cm done
609 statement provides an automatic method of presenting the user with a menu and
611 An enumerated list of the specified
613 is printed on standard error, followed by a prompt
619 A number corresponding to one of the enumerated words is then read from
622 is set to the selected word (or unset if the selection is not valid),
624 is set to what was read (leading/trailing space is stripped), and
627 If a blank line (i.e. zero or more
629 characters) is entered, the menu is reprinted without executing
634 completes, the enumerated list is printed if
638 the prompt is printed, and so on.
639 This process continues until an end-of-file
640 is read, an interrupt is received, or a
642 statement is executed inside the loop.
645 is omitted, the positional parameters are used
647 For historical reasons, open and close braces may be used instead of
652 .Ic select i; { echo $i; } .
655 statement is zero if a
657 statement is used to exit the loop, non-zero otherwise.
658 .It Xo Ic until Ar list ;
664 except that the body is executed only while the exit status of the first
667 .It Xo Ic while Ar list ;
673 is a pre-checked loop.
674 Its body is executed as often as the exit status of the first
679 statement is the last exit status of the
681 in the body of the loop; if the body is not executed, the exit status is zero.
682 .It Xo Ic function Ar name
690 Note that redirections specified after a function definition are
691 performed whenever the function is executed, not when the function definition
693 .It Ar name Ns () Ar command
699 .It Xo Ic time Op Fl p
704 reserved word is described in the
705 .Sx Command execution
707 .It Ic (( Ar expression Cm ))
708 The arithmetic expression
710 is evaluated; equivalent to
711 .Ic let Ar expression
713 .Sx Arithmetic expressions
717 .It Ic [[ Ar expression Cm ]]
721 .Ic \&[ No ... Cm \&]
722 commands (described later), with the following exceptions:
723 .Bl -bullet -offset indent
725 Field splitting and file name generation are not performed on arguments.
733 operators are replaced with
745 The second operand of the
749 expressions are patterns (e.g. the comparison
750 .Ic [[ foobar = f*r ]]
753 There are two additional binary operators,
757 which return true if their first string operand is less than, or greater than,
758 their second string operand, respectively.
760 The single argument form of
762 which tests if the argument has a non-zero length, is not valid; explicit
763 operators must always be used e.g. instead of
764 .No \&[ Ar str No \&]
766 .No \&[[ -n Ar str No \&]] .
768 Parameter, command, and arithmetic substitutions are performed as expressions
769 are evaluated and lazy expression evaluation is used for the
774 This means that in the following statement,
776 is evaluated if and only if the file
778 exists and is readable:
779 .Bd -literal -offset indent
780 $ [[ -r foo && $(< foo) = b*r ]]
785 Quoting is used to prevent the shell from treating characters or words
787 There are three methods of quoting.
790 quotes the following character, unless it is at the end of a line, in which
793 and the newline are stripped.
794 Second, a single quote
796 quotes everything up to the next single quote (this may span lines).
797 Third, a double quote
799 quotes all characters, except
804 up to the next unquoted double quote.
808 inside double quotes have their usual meaning (i.e. parameter, command, or
809 arithmetic substitution) except no field splitting is carried out on the
810 results of double-quoted substitutions.
813 inside a double-quoted string is followed by
819 it is replaced by the second character; if it is followed by a newline, both
822 and the newline are stripped; otherwise, both the
824 and the character following are unchanged.
826 There are two types of aliases: normal command aliases and tracked aliases.
827 Command aliases are normally used as a short hand for a long or often used
829 The shell expands command aliases (i.e. substitutes the alias name
830 for its value) when it reads the first word of a command.
831 An expanded alias is re-processed to check for more aliases.
832 If a command alias ends in a
833 space or tab, the following word is also checked for alias expansion.
834 The alias expansion process stops when a word that is not an alias is found,
835 when a quoted word is found, or when an alias word that is currently being
838 The following command aliases are defined automatically by the shell:
840 .Bl -item -compact -offset indent
842 .Ic autoload Ns ='typeset -fu'
844 .Ic functions Ns ='typeset -f'
846 .Ic hash Ns ='alias -t'
848 .Ic history Ns ='fc -l'
850 .Ic integer Ns ='typeset -i'
852 .Ic local Ns ='typeset'
854 .Ic login Ns ='exec login'
856 .Ic nohup Ns ='nohup '
860 .Ic stop Ns ='kill -STOP'
863 Tracked aliases allow the shell to remember where it found a particular
865 The first time the shell does a path search for a command that is
866 marked as a tracked alias, it saves the full path of the command.
868 time the command is executed, the shell checks the saved path to see that it
869 is still valid, and if so, avoids repeating the path search.
870 Tracked aliases can be listed and created using
872 Note that changing the
874 parameter clears the saved paths for all tracked aliases.
877 option is set (i.e.\&
878 .Ic set -o Ic trackall
881 the shell tracks all commands.
882 This option is set automatically for non-interactive shells.
883 For interactive shells, only the following commands are
884 automatically tracked:
905 The first step the shell takes in executing a simple-command is to perform
906 substitutions on the words of the command.
907 There are three kinds of
908 substitution: parameter, command, and arithmetic.
909 Parameter substitutions,
910 which are described in detail in the next section, take the form
914 command substitutions take the form
917 .Pf ` Ar command Ns ` ;
918 and arithmetic substitutions take the form
919 .Pf $(( Ar expression ) ) .
921 If a substitution appears outside of double quotes, the results of the
922 substitution are generally subject to word or field splitting according to
923 the current value of the
928 parameter specifies a list of characters which are used to break a string up
929 into several words; any characters from the set space, tab, and newline that
932 characters are called
934 Sequences of one or more
936 whitespace characters, in combination with zero or one
939 characters, delimit a field.
940 As a special case, leading and trailing
942 whitespace is stripped (i.e. no leading or trailing empty field is created by
945 whitespace does create an empty field.
952 .Dq <space>A<space>:<space><space>B::D ,
953 the substitution for $VAR results in four fields:
962 parameter is set to the
964 string, no field splitting is done; if the parameter is unset, the default
965 value of space, tab, and newline is used.
967 Also, note that the field splitting applies only to the immediate result of
969 Using the previous example, the substitution for $VAR:E
970 results in the fields:
983 This behavior is POSIX compliant, but incompatible with some other shell
984 implementations which do field splitting on the word which contained the
987 as a general whitespace delimiter.
989 The results of substitution are, unless otherwise specified, also subject to
990 brace expansion and file name expansion (see the relevant sections below).
992 A command substitution is replaced by the output generated by the specified
993 command, which is run in a subshell.
996 substitutions, normal quoting rules are used when
998 is parsed; however, for the
999 .Pf ` Ar command Ns `
1009 followed by any other character is unchanged).
1010 As a special case in command substitutions, a command of the form
1012 is interpreted to mean substitute the contents of
1016 has the same effect as
1018 but it is carried out more efficiently because no process is started.
1020 Arithmetic substitutions are replaced by the value of the specified expression.
1021 For example, the command
1025 .Sx Arithmetic expressions
1026 for a description of an expression.
1028 Parameters are shell variables; they can be assigned values and their values
1029 can be accessed using a parameter substitution.
1030 A parameter name is either one
1031 of the special single punctuation or digit character parameters described
1032 below, or a letter followed by zero or more letters or digits
1037 The latter form can be treated as arrays by appending an array index of the
1042 is an arithmetic expression.
1043 Parameter substitutions take the form
1045 .Pf ${ Ar name Ns } ,
1048 .Pf ${ Ar name Bo Ar expr Bc }
1052 is a parameter name.
1057 then the named array is expanded using the same quoting rules as
1063 then the named array is expanded using the same quoting rules as
1065 If substitution is performed on a parameter
1066 (or an array parameter element)
1067 that is not set, a null string is substituted unless the
1071 .Ic set Fl o Ic nounset
1075 is set, in which case an error occurs.
1077 Parameters can be assigned values in a number of ways.
1078 First, the shell implicitly sets some parameters like
1083 this is the only way the special single character parameters are set.
1084 Second, parameters are imported from the shell's environment at startup.
1085 Third, parameters can be assigned values on the command line: for example,
1091 multiple parameter assignments can be given on a single command line and they
1092 can be followed by a simple-command, in which case the assignments are in
1093 effect only for the duration of the command (such assignments are also
1094 exported; see below for the implications of this).
1095 Note that both the parameter name and the
1097 must be unquoted for the shell to recognize a parameter assignment.
1098 The fourth way of setting a parameter is with the
1103 commands; see their descriptions in the
1104 .Sx Command execution
1110 loops set parameters as well as the
1116 Lastly, parameters can be assigned values using assignment operators
1117 inside arithmetic expressions (see
1118 .Sx Arithmetic expressions
1120 .Pf ${ Ar name Ns = Ns Ar value Ns }
1121 form of the parameter substitution (see below).
1123 Parameters with the export attribute (set using the
1127 commands, or by parameter assignments followed by simple commands) are put in
1128 the environment (see
1130 of commands run by the shell as
1131 .Ar name Ns = Ns Ar value
1133 The order in which parameters appear in the environment of a command is
1135 When the shell starts up, it extracts parameters and their values
1136 from its environment and automatically sets the export attribute for those
1139 Modifiers can be applied to the
1141 form of parameter substitution:
1144 .It ${ Ar name No :- Ar word No }
1150 it is substituted; otherwise,
1154 .It ${ Ar name No :+ Ar word No }
1161 is substituted; otherwise, nothing is substituted.
1163 .It ${ Ar name No := Ar word No }
1169 it is substituted; otherwise, it is assigned
1171 and the resulting value of
1175 .It ${ Ar name No :? Ar word No }
1181 it is substituted; otherwise,
1183 is printed on standard error (preceded by
1185 and an error occurs (normally causing termination of a shell script, function,
1186 or script sourced using the
1191 is omitted, the string
1192 .Dq parameter null or not set
1196 In the above modifiers, the
1198 can be omitted, in which case the conditions only depend on
1200 being set (as opposed to set and not
1204 is needed, parameter, command, arithmetic, and tilde substitution are performed
1207 is not needed, it is not evaluated.
1209 The following forms of parameter substitution can also be used:
1211 .Bl -tag -width Ds -compact
1212 .It Pf ${# Ar name Ns }
1213 The number of positional parameters if
1218 or not specified; otherwise the length of the string value of parameter
1221 .It Pf ${# Ar name Ns [*]}
1222 .It Pf ${# Ar name Ns [@]}
1223 The number of elements in the array
1226 .It Pf ${ Ar name Ns # Ns Ar pattern Ns }
1227 .It Pf ${ Ar name Ns ## Ns Ar pattern Ns }
1230 matches the beginning of the value of parameter
1232 the matched text is deleted from the result of substitution.
1235 results in the shortest match, and two
1236 of them result in the longest match.
1238 .It Pf ${ Ar name Ns % Ns Ar pattern Ns }
1239 .It Pf ${ Ar name Ns %% Ns Ar pattern Ns }
1240 Like ${..#..} substitution, but it deletes from the end of the value.
1243 The following special parameters are implicitly set by the shell and cannot be
1244 set directly using assignments:
1245 .Bl -tag -width "1 ... 9"
1247 Process ID of the last background process started.
1248 If no background processes have been started, the parameter is not set.
1250 The number of positional parameters ($1, $2, etc.).
1252 The PID of the shell, or the PID of the original shell if it is a subshell.
1255 use this mechanism for generating temporary file names; see
1259 The concatenation of the current single letter options (see the
1261 command below for a list of options).
1263 The exit status of the last non-asynchronous command executed.
1264 If the last command was killed by a signal,
1266 is set to 128 plus the signal number.
1268 The name of the shell, determined as follows:
1269 the first argument to
1271 if it was invoked with the
1273 option and arguments were given; otherwise the
1275 argument, if it was supplied;
1276 or else the basename the shell was invoked with (i.e.\&
1279 is also set to the name of the current script or
1280 the name of the current function, if it was defined with the
1282 keyword (i.e. a Korn shell style function).
1283 .It Ev 1 No ... Ev 9
1284 The first nine positional parameters that were supplied to the shell, function,
1285 or script sourced using the
1288 Further positional parameters may be accessed using
1289 .Pf ${ Ar number Ns } .
1291 All positional parameters (except parameter 0) i.e. $1, $2, $3, ...
1293 outside of double quotes, parameters are separate words (which are subjected
1294 to word splitting); if used within double quotes, parameters are separated
1295 by the first character of the
1297 parameter (or the empty string if
1304 unless it is used inside double quotes, in which case a separate word is
1305 generated for each positional parameter.
1306 If there are no positional parameters, no word is generated.
1308 can be used to access arguments, verbatim, without losing
1310 arguments or splitting arguments with spaces.
1313 The following parameters are set and/or used by the shell:
1314 .Bl -tag -width "EXECSHELL"
1315 .It Ev _ No (underscore)
1316 When an external command is executed by the shell, this parameter is set in the
1317 environment of the new process to the path of the executed command.
1318 In interactive use, this parameter is also set in the parent shell to the last
1319 word of the previous command.
1322 messages are evaluated, this parameter contains the name of the file that
1330 It works the same way as
1332 for those directories not beginning with
1341 is set and does not contain
1343 or contains an empty path, the current directory is not searched.
1346 built-in command will display the resulting directory when a match is found
1347 in any search path other than the empty path.
1349 Set to the number of columns on the terminal or window.
1350 Currently set to the
1352 value as reported by
1354 if that value is non-zero.
1355 This parameter is used by the interactive line editing modes, and by the
1360 commands to format information columns.
1364 parameter is not set, this parameter controls the command-line editing mode for
1368 parameter below for how this works.
1373 was used to specify the name of an (old-style) line editor, such as
1377 was used to specify a (new-style) screen editor, such as
1381 is set, it overrides
1384 If this parameter is found to be set after any profile files are executed, the
1385 expanded value is used as a shell startup file.
1386 It typically contains function and alias definitions.
1388 If set, this parameter is assumed to contain the shell that is to be used to
1389 execute commands that
1391 fails to execute and which do not start with a
1395 The editor used by the
1397 command (see below).
1401 but used when an undefined function is executed to locate the file defining the
1403 It is also searched when a command can't be found using
1407 below for more information.
1409 A colon separated list of history settings.
1412 is present, lines identical to the previous history line will not be saved.
1415 is present, lines starting with a space will not be saved.
1416 Unknown settings are ignored.
1418 The name of the file used to store command history.
1419 When assigned to, history is loaded from the specified file.
1420 Also, several invocations of the shell
1421 running on the same machine will share history if their
1423 parameters all point to the same file.
1428 isn't set, no history file is used.
1429 This is different from the original Korn shell, which uses
1430 .Pa $HOME/.sh_history .
1432 The number of commands normally stored for history.
1435 The default directory for the
1437 command and the value substituted for an unqualified
1443 Internal field separator, used during substitution and by the
1445 command, to split values into distinct arguments; normally set to space, tab,
1452 This parameter is not imported from the environment when the shell is
1455 The version of the shell and the date the version was created (read-only).
1457 The line number of the function or shell script that is currently being
1460 Set to the number of lines on the terminal or window.
1462 If set, the user will be informed of the arrival of mail in the named file.
1463 This parameter is ignored if the
1467 How often, in seconds, the shell will check for mail in the file(s) specified
1472 If set to 0, the shell checks before each prompt.
1473 The default is 600 (10 minutes).
1475 A list of files to be checked for mail.
1476 The list is colon separated, and each file may be followed by a
1478 and a message to be printed if new mail has arrived.
1479 Command, parameter, and
1480 arithmetic substitution is performed on the message and, during substitution,
1483 contains the name of the file.
1484 The default message is
1485 .Dq you have mail in $_ .
1487 The previous working directory.
1490 has not successfully changed directories since the shell started, or if the
1491 shell doesn't know where it is.
1495 it contains the argument for a parsed option, if it requires one.
1497 The index of the next argument to be processed when using
1499 Assigning 1 to this parameter causes
1501 to process arguments from the beginning the next time it is invoked.
1503 A colon separated list of directories that are searched when looking for
1504 commands and files sourced using the
1506 command (see below).
1507 An empty string resulting from a leading or trailing
1508 colon, or two adjacent colons, is treated as a
1510 (the current directory).
1511 .It Ev POSIXLY_CORRECT
1512 If set, this parameter causes the
1514 option to be enabled.
1519 The process ID of the shell's parent (read-only).
1521 The primary prompt for interactive shells.
1522 Parameter, command, and arithmetic
1523 substitutions are performed,
1524 and the prompt string can be customised using
1525 backslash-escaped special characters.
1527 Note that since the command-line editors try to figure out how long the prompt
1528 is (so they know how far it is to the edge of the screen), escape codes in
1529 the prompt tend to mess things up.
1530 You can tell the shell not to count certain
1531 sequences (such as escape codes) by using the
1532 .Li \e[ Ns Ar ... Ns Li \e]
1533 substitution (see below) or by prefixing your prompt with a non-printing
1534 character (such as control-A) followed by a carriage return and then delimiting
1535 the escape codes with this non-printing character.
1536 By the way, don't blame me for
1537 this hack; it's in the original
1540 The default prompt is the first part of the hostname, followed by
1546 The following backslash-escaped special characters can be used
1547 to customise the prompt:
1549 .Bl -tag -width "\eD{format}XX" -compact
1551 Insert an ASCII bell character.
1553 The current date, in the format
1557 .It Li \eD Ns Brq Ar format
1558 The current date, with
1562 The braces must be specified.
1564 Insert an ASCII escape character.
1566 The hostname, minus domain name.
1568 The full hostname, including domain name.
1570 Current number of jobs running
1575 The controlling terminal.
1577 Insert a newline character.
1579 Insert a carriage return character.
1581 The name of the shell.
1583 The current time, in 24-hour HH:MM:SS format.
1585 The current time, in 12-hour HH:MM:SS format.
1587 The current time, in 12-hour HH:MM:SS AM/PM format.
1589 The current time, in 24-hour HH:MM format.
1591 The current user's username.
1593 The current version of
1600 The current working directory.
1606 the current working directory.
1611 The current history number.
1614 will produce the current history number too,
1615 as per the POSIX specification.
1618 can be put in the prompt by placing
1623 The current command number.
1624 This could be different to the current history number,
1627 contains a history list from a previous session.
1629 The default prompt character i.e.\&
1631 if the effective UID is 0,
1634 Since the shell interprets
1636 as a special character within double quotes,
1637 it is safer in this case to escape the backslash
1638 than to try quoting it.
1643 Insert a single backslash character.
1645 Normally the shell keeps track of the number of characters in the prompt.
1646 Use of this sequence turns off that count.
1648 Use of this sequence turns the count back on.
1651 Note that the backslash itself may be interpreted by the shell.
1654 either escape the backslash itself,
1655 or use double quotes.
1656 The latter is more practical:
1657 .Bd -literal -offset indent
1661 This is a more complex example,
1662 which does not rely on the above backslash-escaped sequences.
1663 It embeds the current working directory,
1665 in the prompt string:
1666 .Bd -literal -offset indent
1668 PS1="$x$(print \e\er)$x$(tput so)$x\e$PWD$x$(tput se)$x> "
1671 Secondary prompt string, by default
1673 used when more input is needed to complete a command.
1677 statement when reading a menu selection.
1681 Used to prefix commands that are printed during execution tracing (see the
1684 Parameter, command, and arithmetic substitutions are performed
1685 before it is printed.
1689 The current working directory.
1692 if the shell doesn't know where it is.
1694 A random number generator.
1697 is referenced, it is assigned the next random number in the range
1701 is used to produce values.
1704 is assigned a value, the value is used as the seed to
1705 .Xr srand_deterministic 3
1706 and subsequent references of
1708 produce a predictable sequence.
1710 Default parameter for the
1712 command if no names are given.
1715 loops to store the value that is read from standard input.
1717 The number of seconds since the shell started or, if the parameter has been
1718 assigned an integer value, the number of seconds since the assignment plus the
1719 value that was assigned.
1721 The user's terminal type.
1722 If set, it will be used to determine the escape sequence used to
1725 If set to a positive integer in an interactive shell, it specifies the maximum
1726 number of seconds the shell will wait for input after printing the primary
1729 If the time is exceeded, the shell exits.
1731 The directory temporary shell files are created in.
1732 If this parameter is not
1733 set, or does not contain the absolute path of a writable directory, temporary
1734 files are created in
1737 If set, this parameter controls the command-line editing mode for interactive
1739 If the last component of the path specified in this parameter contains
1747 emacs, or gmacs (Gosling emacs) editing mode is enabled, respectively.
1753 Tilde expansion, which is done in parallel with parameter substitution, is done
1754 on words starting with an unquoted
1756 The characters following the tilde, up to the first
1758 if any, are assumed to be a login name.
1759 If the login name is empty,
1768 parameter is substituted, respectively.
1769 Otherwise, the password file is
1770 searched for the login name, and the tilde expression is substituted with the
1771 user's home directory.
1772 If the login name is not found in the password file or
1773 if any quoting or parameter substitution occurs in the login name, no
1774 substitution is performed.
1776 In parameter assignments
1777 (such as those preceding a simple-command or those occurring
1784 tilde expansion is done after any assignment
1785 (i.e. after the equals sign)
1786 or after an unquoted colon
1788 login names are also delimited by colons.
1790 The home directory of previously expanded login names are cached and re-used.
1793 command may be used to list, change, and add to this cache (e.g.\&
1794 .Ic alias -d fac=/usr/local/facilities; cd ~fac/bin ) .
1795 .Ss Brace expansion (alternation)
1796 Brace expressions take the following form:
1797 .Bd -unfilled -offset indent
1800 .Ar prefix No { Ar str1 No ,...,
1801 .Ar strN No } Ar suffix
1806 The expressions are expanded to
1808 words, each of which is the concatenation of
1815 expands to four words:
1821 As noted in the example, brace expressions can be nested and the resulting
1822 words are not sorted.
1823 Brace expressions must contain an unquoted comma
1825 for expansion to occur (e.g.\&
1830 Brace expansion is carried out after parameter substitution
1831 and before file name generation.
1832 .Ss File name patterns
1833 A file name pattern is a word containing one or more unquoted
1843 Once brace expansion has been performed, the shell replaces file
1844 name patterns with the sorted names of all the files that match the pattern
1845 (if no files match, the word is left unchanged).
1846 The pattern elements have the following meaning:
1849 Matches any single character.
1851 Matches any sequence of characters.
1853 Matches any of the characters inside the brackets.
1854 Ranges of characters can be
1855 specified by separating two characters by a
1862 In order to represent itself, a
1864 must either be quoted or the first or last character in the character list.
1867 must be quoted or the first character in the list if it is to represent itself
1868 instead of the end of the list.
1871 appearing at the start of the list has special meaning (see below), so to
1872 represent itself it must be quoted or appear later in the list.
1874 Within a bracket expression, the name of a
1880 stands for the list of all characters belonging to that class.
1881 Supported character classes:
1882 .Bd -literal -offset indent
1883 alnum cntrl lower space
1884 alpha digit print upper
1885 blank graph punct xdigit
1888 These match characters using the macros specified in
1892 A character class may not be used as an endpoint of a range.
1895 except it matches any character not inside the brackets.
1897 .It *( Ar pattern Ns | No ...| Ar pattern )
1899 Matches any string of characters that matches zero or more occurrences of the
1901 Example: The pattern
1910 .It +( Ar pattern Ns | No ...| Ar pattern )
1912 Matches any string of characters that matches one or more occurrences of the
1914 Example: The pattern
1922 .It ?( Ar pattern Ns | No ...| Ar pattern )
1924 Matches the empty string or a string that matches one of the specified
1926 Example: The pattern
1928 only matches the strings
1934 .It @( Ar pattern Ns | No ...| Ar pattern )
1936 Matches a string that matches one of the specified patterns.
1937 Example: The pattern
1939 only matches the strings
1944 .It !( Ar pattern Ns | No ...| Ar pattern )
1946 Matches any string that does not match one of the specified patterns.
1947 Examples: The pattern
1949 matches all strings except
1955 matches no strings; the pattern
1957 matches all strings (think about it).
1967 Note that none of the above pattern elements match either a period
1969 at the start of a file name or a slash
1971 even if they are explicitly used in a [..] sequence; also, the names
1975 are never matched, even by the pattern
1980 option is set, any directories that result from file name generation are marked
1983 .Ss Input/output redirection
1984 When a command is executed, its standard input, standard output, and standard
1985 error (file descriptors 0, 1, and 2, respectively) are normally inherited from
1987 Three exceptions to this are commands in pipelines, for which
1988 standard input and/or standard output are those set up by the pipeline,
1989 asynchronous commands created when job control is disabled, for which standard
1990 input is initially set to be from
1992 and commands for which any of the following redirections have been specified:
1995 Standard output is redirected to
1999 does not exist, it is created; if it does exist, is a regular file, and the
2001 option is set, an error occurs; otherwise, the file is truncated.
2002 Note that this means the command
2006 for reading and then truncate it when it opens it for writing, before
2008 gets a chance to actually read
2013 except the file is truncated, even if the
2021 exists it is appended to instead of being truncated.
2022 Also, the file is opened
2023 in append mode, so writes always go to the end of the file (see
2026 Standard input is redirected from
2028 which is opened for reading.
2032 except the file is opened for reading and writing.
2034 After reading the command line containing this kind of redirection (called a
2035 .Dq here document ) ,
2036 the shell copies lines from the command source into a temporary file until a
2040 When the command is executed, standard input is redirected from the
2044 contains no quoted characters, the contents of the temporary file are processed
2045 as if enclosed in double quotes each time the command is executed, so
2046 parameter, command, and arithmetic substitutions are performed, along with
2055 If multiple here documents are used on the same command line, they are saved in
2057 .It Cm <<- Ar marker
2060 except leading tabs are stripped from lines in the here document.
2062 Standard input is duplicated from file descriptor
2065 can be a single digit, indicating the number of an existing file descriptor;
2068 indicating the file descriptor associated with the output of the current
2069 co-process; or the character
2071 indicating standard input is to be closed.
2075 except the operation is done on standard output.
2078 In any of the above redirections, the file descriptor that is redirected
2079 (i.e. standard input or standard output)
2080 can be explicitly given by preceding the
2081 redirection with a single digit.
2082 Parameter, command, and arithmetic
2083 substitutions, tilde substitutions, and (if the shell is interactive)
2084 file name generation are all performed on the
2089 arguments of redirections.
2090 Note, however, that the results of any file name
2091 generation are only used if a single file is matched; if multiple files match,
2092 the word with the expanded file name generation characters is used.
2094 that in restricted shells, redirections which can create files cannot be used.
2096 For simple-commands, redirections may appear anywhere in the command; for
2102 any redirections must appear at the end.
2103 Redirections are processed after
2104 pipelines are created and in the order they are given, so the following
2105 will print an error with a line number prepended to it:
2107 .D1 $ cat /foo/bar 2>&1 > /dev/null | cat -n
2108 .Ss Arithmetic expressions
2109 Integer arithmetic expressions can be used with the
2111 command, inside $((..)) expressions, inside array references (e.g.\&
2112 .Ar name Ns Bq Ar expr ) ,
2113 as numeric arguments to the
2115 command, and as the value of an assignment to an integer parameter.
2117 Expressions may contain alpha-numeric parameter identifiers, array references,
2118 and integer constants and may be combined with the following C operators
2119 (listed and grouped in increasing order of precedence):
2122 .Bd -literal -offset indent
2127 .Bd -literal -offset indent
2129 = *= /= %= += -= <<= >>= &= ^= |=
2143 .Bd -literal -offset indent
2144 ?: (precedence is immediately higher than assignment)
2148 .Bd -literal -offset indent
2152 A parameter that is NULL or unset evaluates to 0.
2153 Integer constants may be specified with arbitrary bases using the notation
2154 .Ar base Ns # Ns Ar number ,
2157 is a decimal integer specifying the base, and
2159 is a number in the specified base.
2161 integers may be prefixed with
2165 (specifying base 16)
2169 in all forms of arithmetic expressions,
2170 except as numeric arguments to the
2174 The operators are evaluated as follows:
2175 .Bl -tag -width Ds -offset indent
2177 Result is the argument (included for completeness).
2182 the result is 1 if argument is zero, 0 if not.
2184 Arithmetic (bit-wise) NOT.
2186 Increment; must be applied to a parameter (not a literal or other expression).
2187 The parameter is incremented by 1.
2188 When used as a prefix operator, the result
2189 is the incremented value of the parameter; when used as a postfix operator, the
2190 result is the original value of the parameter.
2194 except the parameter is decremented by 1.
2196 Separates two arithmetic expressions; the left-hand side is evaluated first,
2198 The result is the value of the expression on the right-hand side.
2200 Assignment; the variable on the left is set to the value on the right.
2205 Assignment operators.
2220 with any operator precedence in
2225 is the same as specifying
2226 .Dq var1 = var1 * (5 + 3) .
2229 the result is 1 if either argument is non-zero, 0 if not.
2230 The right argument is evaluated only if the left argument is zero.
2233 the result is 1 if both arguments are non-zero, 0 if not.
2234 The right argument is evaluated only if the left argument is non-zero.
2236 Arithmetic (bit-wise) OR.
2238 Arithmetic (bit-wise) XOR
2241 Arithmetic (bit-wise) AND.
2243 Equal; the result is 1 if both arguments are equal, 0 if not.
2245 Not equal; the result is 0 if both arguments are equal, 1 if not.
2247 Less than; the result is 1 if the left argument is less than the right, 0 if
2250 Less than or equal, greater than or equal, greater than.
2254 Shift left (right); the result is the left argument with its bits shifted left
2255 (right) by the amount given in the right argument.
2257 Addition, subtraction, multiplication, and division.
2259 Remainder; the result is the remainder of the division of the left argument by
2261 The sign of the result is unspecified if either argument is negative.
2271 is non-zero, the result is
2273 otherwise the result is
2277 A co-process, which is a pipeline created with the
2279 operator, is an asynchronous process that the shell can both write to (using
2281 and read from (using
2283 The input and output of the co-process can also be manipulated using
2287 redirections, respectively.
2288 Once a co-process has been started, another can't
2289 be started until the co-process exits, or until the co-process's input has been
2291 .Ic exec Ar n Ns Cm >&p
2293 If a co-process's input is redirected in this way, the next
2294 co-process to be started will share the output with the first co-process,
2295 unless the output of the initial co-process has been redirected using an
2296 .Ic exec Ar n Ns Cm <&p
2299 Some notes concerning co-processes:
2302 The only way to close the co-process's input (so the co-process reads an
2303 end-of-file) is to redirect the input to a numbered file descriptor and then
2304 close that file descriptor e.g.\&
2305 .Ic exec 3>&p; exec 3>&- .
2307 In order for co-processes to share a common output, the shell must keep the
2308 write portion of the output pipe open.
2309 This means that end-of-file will not be
2310 detected until all co-processes sharing the co-process's output have exited
2311 (when they all exit, the shell closes its copy of the pipe).
2313 avoided by redirecting the output to a numbered file descriptor (as this also
2314 causes the shell to close its copy).
2315 Note that this behaviour is slightly
2316 different from the original Korn shell which closes its copy of the write
2317 portion of the co-process output when the most recently started co-process
2318 (instead of when all sharing co-processes) exits.
2323 signals during writes if the signal is not being trapped or ignored; the same
2324 is true if the co-process input has been duplicated to another file descriptor
2326 .Ic print -u Ns Ar n
2330 Functions are defined using either Korn shell
2331 .Ic function Ar function-name
2332 syntax or the Bourne/POSIX shell
2333 .Ar function-name Ns ()
2334 syntax (see below for the difference between the two forms).
2337 (i.e. scripts sourced using the
2340 in that they are executed in the current environment.
2343 shell arguments (i.e. positional parameters $1, $2, etc.)\&
2344 are never visible inside them.
2345 When the shell is determining the location of a command, functions
2346 are searched after special built-in commands, before regular and
2347 non-regular built-ins, and before the
2351 An existing function may be deleted using
2352 .Ic unset Fl f Ar function-name .
2353 A list of functions can be obtained using
2355 and the function definitions can be listed using
2359 command (which is an alias for
2361 may be used to create undefined functions: when an undefined function is
2362 executed, the shell searches the path specified in the
2364 parameter for a file with the same name as the function, which, if found, is
2366 If after executing the file the named function is found to
2367 be defined, the function is executed; otherwise, the normal command search is
2368 continued (i.e. the shell searches the regular built-in command table and
2370 Note that if a command is not found using
2372 an attempt is made to autoload a function using
2374 (this is an undocumented feature of the original Korn shell).
2376 Functions can have two attributes,
2380 which can be set with
2385 When a traced function is executed, the shell's
2387 option is turned on for the function's duration; otherwise, the
2389 option is turned off.
2392 attribute of functions is currently not used.
2393 In the original Korn shell,
2394 exported functions are visible to shell scripts that are executed.
2396 Since functions are executed in the current shell environment, parameter
2397 assignments made inside functions are visible after the function completes.
2398 If this is not the desired effect, the
2400 command can be used inside a function to create a local parameter.
2401 Note that special parameters (e.g.\&
2403 can't be scoped in this way.
2405 The exit status of a function is that of the last command executed in the
2407 A function can be made to finish immediately using the
2409 command; this may also be used to explicitly specify the exit status.
2411 Functions defined with the
2413 reserved word are treated differently in the following ways from functions
2419 The $0 parameter is set to the name of the function
2420 (Bourne-style functions leave $0 untouched).
2422 Parameter assignments preceding function calls are not kept in the shell
2423 environment (executing Bourne-style functions will keep assignments).
2426 is saved/reset and restored on entry and exit from the function so
2428 can be used properly both inside and outside the function (Bourne-style
2433 inside a function interferes with using
2435 outside the function).
2438 The shell is intended to be POSIX compliant;
2439 however, in some cases, POSIX behaviour is contrary either to
2440 the original Korn shell behaviour or to user convenience.
2441 How the shell behaves in these cases is determined by the state of the
2444 .Pq Ic set -o posix .
2445 If it is on, the POSIX behaviour is followed; otherwise, it is not.
2448 option is set automatically when the shell starts up if the environment
2452 The shell can also be compiled so that it is in POSIX mode by default;
2453 however, this is usually not desirable.
2455 The following is a list of things that are affected by the state of the
2462 In POSIX mode, only signal names are listed (in a single line);
2464 signal numbers, names, and descriptions are printed (in columns).
2472 are not treated as options, but printed like other arguments;
2473 in non-POSIX mode, these options control the interpretation
2474 of backslash sequences.
2478 In POSIX mode, the exit status is 0 if no errors occur;
2479 in non-POSIX mode, the exit status is that of the last foregrounded job.
2485 gets to see an empty command (i.e.\&
2486 .Ic eval `false` ) ,
2487 its exit status in POSIX mode will be 0.
2489 it will be the exit status of the last command substitution that was
2490 done in the processing of the arguments to
2492 (or 0 if there were no command substitutions).
2495 In POSIX mode, options must start with a
2497 in non-POSIX mode, options can start with either
2502 Brace expansion (also known as alternation).
2503 In POSIX mode, brace expansion is disabled;
2504 in non-POSIX mode, brace expansion is enabled.
2509 parameter) automatically turns the
2511 option off; however, it can be explicitly turned on later.
2514 In POSIX mode, this does not clear the
2518 options; in non-POSIX mode, it does.
2522 In POSIX mode, the exit status of
2524 is 0 if there are no errors;
2525 in non-POSIX mode, the exit status is that of any
2526 command substitutions performed in generating the
2530 .Ic set -- `false`; echo $?\&
2531 prints 0 in POSIX mode, 1 in non-POSIX mode.
2532 This construct is used in most shell scripts that use the old
2536 Argument expansion of the
2543 In POSIX mode, normal argument expansion is done; in non-POSIX mode,
2544 field splitting, file globbing, brace expansion, and (normal) tilde expansion
2545 are turned off, while assignment tilde expansion is turned on.
2547 Signal specification.
2548 In POSIX mode, signals can be specified as digits, only
2549 if signal numbers match POSIX values
2550 (i.e. HUP=1, INT=2, QUIT=3, ABRT=6, KILL=9, ALRM=14, and TERM=15);
2551 in non-POSIX mode, signals can always be digits.
2554 In POSIX mode, alias expansion is only carried out when reading command words;
2555 in non-POSIX mode, alias expansion is carried out on any
2556 word following an alias that ended in a space.
2557 For example, the following
2564 .Bd -literal -offset indent
2565 alias a='for ' i='j'
2566 a i in 1 2; do echo i=$i j=$j; done
2570 In POSIX mode, the expression
2572 (preceded by some number of
2574 arguments) is always true as it is a non-zero length string;
2575 in non-POSIX mode, it tests if file descriptor 1 is a
2581 test may be left out and defaults to 1).
2583 .Ss Strict Bourne shell mode
2586 option is enabled (see the
2592 in the following ways:
2601 the expanded alias' full program path after entering commands
2602 that are tracked aliases
2604 the last argument on the command line after entering external
2607 the file that changed when
2609 is set to monitor a mailbox
2612 File descriptors are left untouched when executing
2616 Backslash-escaped special characters are not substituted in
2621 are not interpreted as arithmetic expressions.
2623 .Ss Command execution
2624 After evaluation of command-line arguments, redirections, and parameter
2625 assignments, the type of command is determined: a special built-in, a
2626 function, a regular built-in, or the name of a file to execute found using the
2629 The checks are made in the above order.
2630 Special built-in commands differ from other commands in that the
2632 parameter is not used to find them, an error during their execution can
2633 cause a non-interactive shell to exit, and parameter assignments that are
2634 specified before the command are kept after the command completes.
2635 Just to confuse things, if the
2637 option is turned off (see the
2639 command below), some special commands are very special in that no field
2640 splitting, file globbing, brace expansion, nor tilde expansion is performed
2641 on arguments that look like assignments.
2642 Regular built-in commands are different only in that the
2644 parameter is not used to find them.
2648 and POSIX differ somewhat in which commands are considered
2651 POSIX special commands
2653 .Ic \&. , \&: , break , continue ,
2654 .Ic eval , exec , exit , export ,
2655 .Ic readonly , return , set , shift ,
2656 .Ic times , trap , unset
2662 .Ic builtin , typeset
2664 Very special commands
2665 .Pq when POSIX mode is off
2667 .Ic alias , readonly , set , typeset
2669 POSIX regular commands
2671 .Ic alias , bg , cd , command ,
2672 .Ic false , fc , fg , getopts ,
2673 .Ic jobs , kill , pwd , read ,
2674 .Ic true , umask , unalias , wait
2680 .Ic \&[ , echo , let ,
2681 .Ic print , suspend , test ,
2684 Once the type of command has been determined, any command-line parameter
2685 assignments are performed and exported for the duration of the command.
2687 The following describes the special and regular built-in commands:
2689 .Bl -tag -width Ds -compact
2690 .It Ic \&. Ar file Op Ar arg ...
2691 Execute the commands in
2693 in the current environment.
2694 The file is searched for in the directories of
2696 If arguments are given, the positional parameters may be used to access them
2700 If no arguments are given, the positional parameters are
2701 those of the environment the command is used in.
2703 .It Ic \&: Op Ar ...
2705 Exit status is set to zero.
2708 .Oo Fl d | t Oo Fl r Oc |
2713 .Op Ns = Ns Ar value
2719 For any name without a value, the existing alias is listed.
2720 Any name with a value defines an alias (see
2724 When listing aliases, one of two formats is used.
2725 Normally, aliases are listed as
2726 .Ar name Ns = Ns Ar value ,
2730 If options were preceded with
2734 is given on the command line, only
2740 option causes directory aliases, which are used in tilde expansion, to be
2747 option is used, each alias is prefixed with the string
2752 option indicates that tracked aliases are to be listed/set (values specified on
2753 the command line are ignored for tracked aliases).
2756 option indicates that all tracked aliases are to be reset.
2762 the export attribute of an alias or, if no names are given, lists the aliases
2763 with the export attribute (exporting an alias has no effect).
2765 .It Ic bg Op Ar job ...
2766 Resume the specified stopped job(s) in the background.
2767 If no jobs are specified,
2772 below for more information.
2775 The current bindings are listed.
2780 instead lists the names of the functions to which keys may be bound.
2782 .Sx Emacs editing mode
2783 for more information.
2785 .It Xo Ic bind Op Fl m
2786 .Ar string Ns = Ns Op Ar substitute
2790 .Ar string Ns = Ns Op Ar editing-command
2794 .Sx Emacs editing mode ,
2795 the specified editing command is bound to the given
2799 will cause the editing command to be immediately invoked.
2800 Bindings have no effect in
2801 .Sx Vi editing mode .
2805 flag is given, the specified input
2807 will afterwards be immediately replaced by the given
2809 string, which may contain editing commands.
2810 Control characters may be written using caret notation.
2811 For example, ^X represents Control-X.
2813 If a certain character occurs as the first character of any bound
2816 sequence, that character becomes a command prefix character.
2817 Any character sequence that starts with a command prefix character
2818 but that is not bound to a command or substitute
2819 is implicitly considered as bound to the
2822 By default, two command prefix characters exist:
2828 The following default bindings show how the arrow keys
2829 on an ANSI terminal or xterm are bound
2830 (of course some escape sequences won't work out quite this nicely):
2831 .Bd -literal -offset indent
2832 bind '^[[A'=up-history
2833 bind '^[[B'=down-history
2834 bind '^[[C'=forward-char
2835 bind '^[[D'=backward-char
2838 .It Ic break Op Ar level
2851 .It Ic builtin Ar command Op Ar arg ...
2852 Execute the built-in command
2860 Set the working directory to
2864 is set, it lists the search path for the directory containing
2868 path means the current directory.
2871 is found in any component of the
2873 search path other than the
2875 path, the name of the new working directory will be written to standard output.
2878 is missing, the home directory
2885 the previous working directory is used (see the
2891 option (logical path) is used or if the
2893 option isn't set (see the
2895 command below), references to
2899 are relative to the path used to get to the directory.
2902 option (physical path) is used or if the
2906 is relative to the filesystem directory tree.
2911 parameters are updated to reflect the current and old working directory,
2923 in the current directory, and the shell attempts to change to the new
2938 is executed exactly as if
2940 had not been specified, with two exceptions:
2943 cannot be an alias or a shell function;
2944 and secondly, special built-in commands lose their specialness
2945 (i.e. redirection and utility errors do not cause the shell to
2946 exit, and command assignments are not permanent).
2950 option is given, a default search path is used instead of the current value of
2952 (the actual value of the default path is system dependent: on
2953 POSIX-ish systems, it is the value returned by
2954 .Ic getconf PATH ) .
2955 Nevertheless, reserved words, aliases, shell functions, and
2956 builtin commands are still found before external commands.
2960 option is given, instead of executing
2962 information about what would be executed is given (and the same is done for
2964 For special and regular built-in commands and functions, their names are simply
2965 printed; for aliases, a command that defines them is printed; and for commands
2966 found by searching the
2968 parameter, the full path of the command is printed.
2969 If no command is found
2970 (i.e. the path search fails), nothing is printed and
2972 exits with a non-zero status.
2977 option, except it is more verbose.
2979 .It Ic continue Op Ar level
2980 Jumps to the beginning of the
2997 Prints its arguments (separated by spaces) followed by a newline, to the
2999 The newline is suppressed if any of the arguments contain the
3004 command below for a list of other backslash sequences that are recognized.
3006 The options are provided for compatibility with
3011 option suppresses the trailing newline,
3013 enables backslash interpretation (a no-op, since this is normally done), and
3015 suppresses backslash interpretation.
3018 option is set, only the first argument is treated as an option, and only
3022 .It Ic eval Ar command ...
3023 The arguments are concatenated (with spaces between them) to form a single
3024 string which the shell then parses and executes in the current environment.
3028 .Op Ar command Op Ar arg ...
3030 The command is executed without forking, replacing the shell process.
3032 If no command is given except for I/O redirection, the I/O redirection is
3033 permanent and the shell is
3035 Any file descriptors greater than 2 which are opened or
3037 in this way are not made available to other executed commands (i.e. commands
3038 that are not built-in to the shell).
3039 Note that the Bourne shell differs here;
3040 it does pass these file descriptors on.
3042 .It Ic exit Op Ar status
3043 The shell exits with the specified exit status.
3046 is not specified, the exit status is the current value of the
3053 .Op Ar parameter Ns Op = Ns Ar value
3055 Sets the export attribute of the named parameters.
3056 Exported parameters are passed in the environment to executed commands.
3057 If values are specified, the named parameters are also assigned.
3059 If no parameters are specified, the names of all parameters with the export
3060 attribute are printed one per line, unless the
3062 option is used, in which case
3064 commands defining all exported parameters, including their values, are printed.
3067 A command that exits with a non-zero status.
3076 .Op Ar first Op Ar last
3082 select commands from the history.
3083 Commands can be selected by history number
3084 or a string specifying the most recent command starting with that string.
3087 option lists the command on standard output, and
3089 inhibits the default command numbers.
3092 option reverses the order of the list.
3095 the selected commands are edited by the editor specified with the
3099 is specified, the editor specified by the
3101 parameter (if this parameter is not set,
3103 is used), and then executed by the shell.
3108 .Op Ar old Ns = Ns Ar new
3111 Re-execute the most recent command beginning with
3113 or the previous command if no
3116 performing the optional substitution of
3122 is specified, all occurrences of
3126 The editor is not invoked when the
3129 The obsolescent equivalent
3132 This command is usually accessed with the predefined
3133 .Ic alias r='fc -s' .
3135 .It Ic fg Op Ar job ...
3136 Resume the specified job(s) in the foreground.
3137 If no jobs are specified,
3142 below for more information.
3149 Used by shell procedures to parse the specified arguments (or positional
3150 parameters, if no arguments are given) and to check for legal options.
3152 contains the option letters that
3155 If a letter is followed by a colon, the option is expected to
3157 Options that do not take arguments may be grouped in a single argument.
3158 If an option takes an argument and the option character is not the
3159 last character of the argument it is found in, the remainder of the argument is
3160 taken to be the option's argument; otherwise, the next argument is the option's
3165 is invoked, it places the next option in the shell parameter
3167 and the index of the argument to be processed by the next call to
3169 in the shell parameter
3171 If the option was introduced with a
3173 the option placed in
3177 When an option requires an argument,
3179 places it in the shell parameter
3182 When an illegal option or a missing option argument is encountered, a question
3183 mark or a colon is placed in
3185 (indicating an illegal option or missing argument, respectively) and
3187 is set to the option character that caused the problem.
3190 does not begin with a colon, a question mark is placed in
3193 is unset, and an error message is printed to standard error.
3195 When the end of the options is encountered,
3197 exits with a non-zero exit status.
3198 Options end at the first (non-option
3199 argument) argument that does not start with a
3203 argument is encountered.
3205 Option parsing can be reset by setting
3207 to 1 (this is done automatically whenever the shell or a shell procedure is
3210 Warning: Changing the value of the shell parameter
3212 to a value other than 1, or parsing different sets of arguments without
3215 may lead to unexpected results.
3222 Without arguments, any hashed executable command pathnames are listed.
3225 option causes all hashed commands to be removed from the hash table.
3228 is searched as if it were a command name and added to the hash table if it is
3229 an executable command.
3236 Display information about the specified job(s); if no jobs are specified, all
3240 option causes information to be displayed only for jobs that have changed
3241 state since the last notification.
3244 option is used, the process ID of each process in a job is also listed.
3247 option causes only the process group of each job to be printed.
3250 below for the format of
3252 and the displayed job.
3256 .Oo Fl s Ar signame |
3257 .No - Ns Ar signum |
3258 .No - Ns Ar signame Oc
3259 .No { Ar job | pid | pgrp No }
3262 Send the specified signal to the specified jobs, process IDs, or process
3264 If no signal is specified, the
3267 If a job is specified, the signal is sent to the job's process group.
3270 below for the format of
3276 .Op Ar exit-status ...
3278 Print the signal name corresponding to
3280 If no arguments are specified, a list of all the signals, their numbers, and
3281 a short description of them are printed.
3283 .It Ic let Op Ar expression ...
3284 Each expression is evaluated (see
3285 .Sx Arithmetic expressions
3287 If all expressions are successfully evaluated, the exit status is 0 (1)
3288 if the last expression evaluated to non-zero (zero).
3289 If an error occurs during
3290 the parsing or evaluation of an expression, the exit status is greater than 1.
3291 Since expressions may need to be quoted,
3292 .No (( Ar expr No ))
3293 is syntactic sugar for
3294 .No let \&" Ns Ar expr Ns \&" .
3299 .Fl nprsu Ns Oo Ar n Oc |
3305 prints its arguments on the standard output, separated by spaces and
3306 terminated with a newline.
3309 option suppresses the newline.
3310 By default, certain C escapes are translated.
3322 is an octal digit, of which there may be 0 to 3
3325 is equivalent to using the
3329 expansion may be inhibited with the
3334 option prints to the history file instead of standard output; the
3336 option prints to file descriptor
3340 defaults to 1 if omitted
3344 option prints to the co-process (see
3350 option is used to emulate, to some degree, the
3353 command, which does not process
3355 sequences unless the
3360 option suppresses the trailing newline.
3363 Print the present working directory.
3366 option is used or if the
3368 option isn't set (see the
3370 command below), the logical path is printed (i.e. the path used to
3372 to the current directory).
3375 option (physical path) is used or if the
3377 option is set, the path determined from the filesystem (by following
3379 directories to the root directory) is printed.
3383 .Op Fl prsu Ns Op Ar n
3384 .Op Ar parameter ...
3386 Reads a line of input from the standard input, separates the line into fields
3391 above), and assigns each field to the specified parameters.
3392 If there are more parameters than fields, the extra parameters are set to
3394 or alternatively, if there are more fields than parameters, the last parameter
3395 is assigned the remaining fields (inclusive of any separating spaces).
3396 If no parameters are specified, the
3399 If the input line ends in a backslash and the
3401 option was not used, the backslash and the newline are stripped and more input
3403 If no input is read,
3405 exits with a non-zero status.
3407 The first parameter may have a question mark and a string appended to it, in
3408 which case the string is used as a prompt (printed to standard error before
3409 any input is read) if the input is a
3412 .Ic read nfoo?'number of foos: ' ) .
3418 options cause input to be read from file descriptor
3421 defaults to 0 if omitted)
3422 or the current co-process (see
3424 above for comments on this), respectively.
3427 option is used, input is saved to the history file.
3433 .Op Ns = Ns Ar value
3436 Sets the read-only attribute of the named parameters.
3437 If values are given,
3438 parameters are set to them before setting the attribute.
3440 made read-only, it cannot be unset and its value cannot be changed.
3442 If no parameters are specified, the names of all parameters with the read-only
3443 attribute are printed one per line, unless the
3445 option is used, in which case
3447 commands defining all read-only parameters, including their values, are
3450 .It Ic return Op Ar status
3451 Returns from a function or
3453 script, with exit status
3457 is given, the exit status of the last executed command is used.
3458 If used outside of a function or
3460 script, it has the same effect as
3464 treats both profile and
3468 scripts, while the original Korn shell only treats profiles as
3473 .Ic set Op Ic +-abCefhkmnpsuvXx
3474 .Op Ic +-o Ar option
3481 command can be used to set
3485 shell options, set the positional parameters, or set an array parameter.
3486 Options can be changed using the
3490 is the long name of an option, or using the
3494 is the option's single letter name (not all options have a single letter name).
3495 The following table lists both option letters (if they exist) and long names
3496 along with a description of what the option does:
3499 Sets the elements of the array parameter
3505 is used, the array is reset (i.e. emptied) first; if
3507 is used, the first N elements are set (where N is the number of arguments);
3508 the rest are left untouched.
3509 .It Fl a | Ic allexport
3510 All new parameters are created with the export attribute.
3511 .It Fl b | Ic notify
3512 Print job notification messages asynchronously, instead of just before the
3514 Only used if job control is enabled
3516 .It Fl C | Ic noclobber
3519 redirection from overwriting existing files.
3522 must be used to force an overwrite.
3523 .It Fl e | Ic errexit
3524 Exit (after executing the
3526 trap) as soon as an error occurs or a command fails (i.e. exits with a
3528 This does not apply to commands whose exit status is
3529 explicitly tested by a shell construct such as
3540 only the status of the last command is tested.
3541 .It Fl f | Ic noglob
3542 Do not expand file name patterns.
3543 .It Fl h | Ic trackall
3544 Create tracked aliases for all executed commands (see
3547 Enabled by default for non-interactive shells.
3548 .It Fl k | Ic keyword
3549 Parameter assignments are recognized anywhere in a command.
3550 .It Fl m | Ic monitor
3551 Enable job control (default for interactive shells).
3552 .It Fl n | Ic noexec
3553 Do not execute any commands.
3554 Useful for checking the syntax of scripts
3555 (ignored if interactive).
3556 .It Fl p | Ic privileged
3557 The shell is a privileged shell.
3558 It is set automatically if, when the shell starts,
3559 the real UID or GID does not match
3560 the effective UID (EUID) or GID (EGID), respectively.
3561 See above for a description of what this means.
3563 If used when the shell is invoked, commands are read from standard input.
3564 Set automatically if the shell is invoked with no arguments.
3570 command it causes the specified arguments to be sorted before assigning them to
3571 the positional parameters (or to array
3576 .It Fl u | Ic nounset
3577 Referencing of an unset parameter is treated as an error, unless one of the
3583 .It Fl v | Ic verbose
3584 Write shell input to standard error as it is read.
3585 .It Fl X | Ic markdirs
3586 Mark directories with a trailing
3588 during file name generation.
3589 .It Fl x | Ic xtrace
3590 Print commands and parameter assignments when they are executed, preceded by
3594 Background jobs are run with lower priority.
3596 Enable brace expansion (a.k.a. alternation).
3600 history editing using the
3604 Enable BRL emacs-like command-line editing (interactive shells only); see
3605 .Sx Emacs editing mode .
3607 Enable gmacs-like command-line editing (interactive shells only).
3608 Currently identical to emacs editing except that transpose (^T) acts slightly
3611 The shell will not (easily) exit when end-of-file is read;
3614 To avoid infinite loops, the shell will exit if
3616 is read 13 times in a row.
3618 The shell is an interactive shell.
3619 This option can only be used when the shell is invoked.
3620 See above for a description of what this means.
3622 The shell is a login shell.
3623 This option can only be used when the shell is invoked.
3624 See above for a description of what this means.
3626 Do not kill running jobs with a
3628 signal when a login shell exits.
3629 Currently set by default;
3630 this is different from the original Korn shell (which
3631 doesn't have this option, but does send the
3636 In the original Korn shell, this prevents function definitions from
3637 being stored in the history file.
3645 (i.e. the filesystem's)
3647 directories instead of
3649 directories (i.e. the shell handles
3651 which allows the user to be oblivious of symbolic links to directories).
3653 Note that setting this option does not affect the current value of the
3663 commands above for more details.
3670 The shell is a restricted shell.
3671 This option can only be used when the shell is invoked.
3672 See above for a description of what this means.
3674 Enable strict Bourne shell mode (see
3675 .Sx Strict Bourne shell mode
3680 command-line editing (interactive shells only).
3681 .It Ic vi-esccomplete
3682 In vi command-line editing, do command and file name completion when escape
3683 (^[) is entered in command mode.
3685 Prefix characters with the eighth bit set with
3687 If this option is not set, characters in the range 128\-160 are printed as is,
3688 which may cause problems.
3689 .It Ic vi-tabcomplete
3690 In vi command-line editing, do command and file name completion when tab (^I)
3691 is entered in insert mode.
3692 This is the default.
3695 In the original Korn shell, unless
3697 was set, the vi command-line mode would let the
3699 driver do the work until ESC (^[) was entered.
3701 is always in viraw mode.
3704 These options can also be used upon invocation of the shell.
3706 options (with single letter names) can be found in the parameter
3709 with no option name will list all the options and whether each is on or off;
3711 will print the current shell options in a form that
3712 can be reinput to the shell to achieve the same option settings.
3714 Remaining arguments, if any, are positional parameters and are assigned, in
3715 order, to the positional parameters (i.e. $1, $2, etc.).
3718 and there are no remaining arguments, all positional parameters are cleared.
3719 If no options or arguments are given, the values of all names are printed.
3720 For unknown historical reasons, a lone
3722 option is treated specially \- it clears both the
3728 .It Ic shift Op Ar number
3729 The positional parameters
3740 Stops the shell as if it had received the suspend character from
3742 It is not possible to suspend a login shell unless the parent process
3743 is a member of the same terminal session but is a member of a different
3745 As a general rule, if the shell was started by another shell or via
3747 it can be suspended.
3749 .It Ic test Ar expression
3750 .It Ic \&[ Ar expression Ic \&]
3754 and returns zero status if true, 1 if false, or greater than 1 if there
3756 It is normally used as the condition command of
3761 Symbolic links are followed for all
3768 The following basic expressions are available:
3775 is a block special device.
3778 is a character special device.
3790 group is the shell's effective group ID.
3793 mode has the setgid bit set.
3807 owner is the shell's effective user ID.
3813 command above for a list of options).
3814 As a non-standard extension, if the option starts with a
3816 the test is negated; the test always fails if
3818 doesn't exist (so [ -o foo -o -o !foo ] returns true if and only if option
3826 exists and is readable.
3830 .Xr unix 4 Ns -domain
3845 may be left out, in which case it is taken to be 1 (the behaviour differs due
3846 to the special POSIX rules described above).
3849 mode has the setuid bit set.
3852 exists and is writable.
3855 exists and is executable.
3856 .It Ar file1 Fl nt Ar file2
3865 .It Ar file1 Fl ot Ar file2
3874 .It Ar file1 Fl ef Ar file2
3880 has non-zero length.
3887 .It Ar string No = Ar string
3889 .It Ar string No == Ar string
3891 .It Ar string No != Ar string
3892 Strings are not equal.
3893 .It Ar number Fl eq Ar number
3894 Numbers compare equal.
3895 .It Ar number Fl ne Ar number
3896 Numbers compare not equal.
3897 .It Ar number Fl ge Ar number
3898 Numbers compare greater than or equal.
3899 .It Ar number Fl gt Ar number
3900 Numbers compare greater than.
3901 .It Ar number Fl le Ar number
3902 Numbers compare less than or equal.
3903 .It Ar number Fl \< Ar number
3904 Numbers compare less than.
3907 The above basic expressions, in which unary operators have precedence over
3908 binary operators, may be combined with the following operators (listed in
3909 increasing order of precedence):
3910 .Bd -literal -offset indent
3911 expr -o expr Logical OR.
3912 expr -a expr Logical AND.
3917 On operating systems not supporting
3918 .Pa /dev/fd/ Ns Ar n
3921 is a file descriptor number), the
3923 command will attempt to fake it for all tests that operate on files (except the
3927 [ -w /dev/fd/2 ] tests if file descriptor 2 is writable.
3929 Note that some special rules are applied (courtesy of POSIX)
3935 is less than five: if leading
3937 arguments can be stripped such that only one argument remains then a string
3938 length test is performed (again, even if the argument is a unary operator); if
3941 arguments can be stripped such that three arguments remain and the second
3942 argument is a binary operator, then the binary operation is performed (even
3943 if the first argument is a unary operator, including an unstripped
3947 A common mistake is to use
3948 .Dq if \&[ $foo = bar \&]
3949 which fails if parameter
3953 or unset, if it has embedded spaces (i.e.\&
3955 characters), or if it is a unary operator like
3960 .Dq if \&[ \&"X$foo\&" = Xbar \&]
3970 is given, the times used to execute the pipeline are reported.
3972 is given, then the user and system time used by the shell itself, and all the
3973 commands it has run since it was started, are reported.
3974 The times reported are the real time (elapsed time from start to finish),
3975 the user CPU time (time spent running in user mode), and the system CPU time
3976 (time spent running in kernel mode).
3977 Times are reported to standard error; the format of the output is:
3979 .Dl "0m0.00s real 0m0.00s user 0m0.00s system"
3983 option is given the output is slightly longer:
3984 .Bd -literal -offset indent
3990 It is an error to specify the
3994 is a simple command.
3996 Simple redirections of standard error do not affect the output of the
4000 .Dl $ time sleep 1 2> afile
4001 .Dl $ { time sleep 1; } 2> afile
4003 Times for the first command do not go to
4005 but those of the second command do.
4008 Print the accumulated user and system times used both by the shell
4009 and by processes that the shell started which have exited.
4010 The format of the output is:
4011 .Bd -literal -offset indent
4016 .It Ic trap Op Ar handler signal ...
4017 Sets a trap handler that is to be executed when any of the specified signals are
4022 string, indicating the signals are to be ignored, a minus sign
4024 indicating that the default action is to be taken for the signals (see
4026 or a string containing shell commands to be evaluated and executed at the first
4027 opportunity (i.e. when the current command completes, or before printing the
4030 prompt) after receipt of one of the signals.
4032 is the name of a signal (e.g.\&
4036 or the number of the signal (see the
4040 There are two special signals:
4042 (also known as 0), which is executed when the shell is about to exit, and
4044 which is executed after an error occurs (an error is something that would cause
4045 the shell to exit if the
4049 option were set \- see the
4053 handlers are executed in the environment of the last executed command.
4055 that for non-interactive shells, the trap handler cannot be changed for signals
4056 that were ignored when the shell started.
4060 lists, as a series of
4062 commands, the current state of the traps that have been set since the shell
4064 Note that the output of
4066 cannot be usefully piped to another process (an artifact of the fact that
4067 traps are cleared when subprocesses are created).
4069 The original Korn shell's
4071 trap and the handling of
4075 traps in functions are not yet implemented.
4078 A command that exits with a zero value.
4093 .No \&| Fl f Op Fl tux
4097 .Op Ns = Ns Ar value
4101 Display or set parameter attributes.
4104 arguments, parameter attributes are displayed; if no options are used, the
4105 current attributes of all parameters are printed as
4107 commands; if an option is given (or
4109 with no option letter), all parameters and their values with the specified
4110 attributes are printed; if options are introduced with
4112 parameter values are not printed.
4116 arguments are given, the attributes of the named parameters are set
4120 Values for parameters may optionally be specified.
4123 is used inside a function, any newly created parameters are local to the
4130 operates on the attributes of functions.
4131 As with parameters, if no
4133 arguments are given,
4134 functions are listed with their values (i.e. definitions) unless
4135 options are introduced with
4137 in which case only the function names are reported.
4141 Display or set functions and their attributes, instead of parameters.
4145 specifies the base to use when displaying the integer (if not specified, the
4146 base given in the first assignment is used).
4147 Parameters with this attribute may
4148 be assigned values containing arithmetic expressions.
4150 Left justify attribute.
4152 specifies the field width.
4155 is not specified, the current width of a parameter (or the width of its first
4156 assigned value) is used.
4157 Leading whitespace (and zeros, if used with the
4159 option) is stripped.
4160 If necessary, values are either truncated or space padded
4161 to fit the field width.
4163 Lower case attribute.
4164 All upper case characters in values are converted to lower case.
4165 (In the original Korn shell, this parameter meant
4173 commands that can be used to re-create the attributes (but not the values) of
4175 This is the default action (option exists for ksh93 compatibility).
4177 Right justify attribute.
4179 specifies the field width.
4182 is not specified, the current width of a parameter (or the width of its first
4183 assigned value) is used.
4184 Trailing whitespace is stripped.
4185 If necessary, values are either stripped of leading characters or space
4186 padded to make them fit the field width.
4188 Read-only attribute.
4189 Parameters with this attribute may not be assigned to or unset.
4190 Once this attribute is set, it cannot be turned off.
4193 Has no meaning to the shell; provided for application use.
4197 is the trace attribute.
4198 When functions with the trace attribute are executed, the
4201 shell option is temporarily turned on.
4203 Unsigned integer attribute.
4204 Integers are printed as unsigned values (only
4205 useful when combined with the
4208 This option is not in the original Korn shell.
4210 Upper case attribute.
4211 All lower case characters in values are converted to upper case.
4212 (In the original Korn shell, this parameter meant
4213 .Dq unsigned integer
4216 option, which meant upper case letters would never be used for bases greater
4224 is the undefined attribute.
4227 above for the implications of this.
4230 Parameters (or functions) are placed in the environment of
4231 any executed commands.
4232 Exported functions are not yet implemented.
4234 Zero fill attribute.
4235 If not combined with
4239 except zero padding is used instead of space padding.
4244 .Op Fl acdfHlmnpSst Op Ar value
4247 Display or set process limits.
4248 If no options are used, the file size limit
4252 if specified, may be either an arithmetic expression starting with a
4255 The limits affect the shell and any processes created by the shell after a
4256 limit is imposed; limits may not be increased once they are set.
4259 Display all limits; unless
4261 is used, soft limits are displayed.
4263 Impose a size limit of
4265 blocks on the size of core dumps.
4267 Impose a size limit of
4269 kilobytes on the size of the data area.
4271 Impose a size limit of
4273 blocks on files written by the shell and its child processes (files of any
4276 Set the hard limit only (the default is to set both hard and soft limits).
4280 kilobytes on the amount of locked (wired) physical memory.
4284 kilobytes on the amount of physical memory used.
4285 This limit is not enforced.
4289 file descriptors that can be open at once.
4293 processes that can be run by the user at any one time.
4295 Set the soft limit only (the default is to set both hard and soft limits).
4297 Impose a size limit of
4299 kilobytes on the size of the stack area.
4301 Impose a time limit of
4303 CPU seconds spent in user mode to be used by each process.
4305 .\"Impose a limit of
4307 .\"kilobytes on the amount of virtual memory used.
4312 is concerned, a block is 512 bytes.
4319 Display or set the file permission creation mask, or umask (see
4323 option is used, the mask displayed or set is symbolic; otherwise, it is an
4326 Symbolic masks are like those used by
4328 When used, they describe what permissions may be made available (as opposed to
4329 octal masks in which a set bit means the corresponding bit is to be cleared).
4332 sets the mask so files will not be readable, writable, or executable by
4334 and is equivalent (on most systems) to the octal mask
4342 The aliases for the given names are removed.
4345 option is used, all aliases are removed.
4350 options are used, the indicated operations are carried out on tracked or
4351 directory aliases, respectively.
4358 Unset the named parameters
4365 The exit status is non-zero if any of the parameters have the read-only
4366 attribute set, zero otherwise.
4368 .It Ic wait Op Ar job ...
4369 Wait for the specified job(s) to finish.
4372 is that of the last specified job; if the last job is killed by a signal, the
4373 exit status is 128 + the number of the signal (see
4374 .Ic kill -l Ar exit-status
4375 above); if the last specified job can't be found (because it never existed, or
4376 had already finished), the exit status of
4381 below for the format of
4384 will return if a signal for which a trap has been set is received, or if a
4391 If no jobs are specified,
4393 waits for all currently running jobs (if any) to finish and exits with a zero
4395 If job monitoring is enabled, the completion status of jobs is printed
4396 (this is not the case when jobs are explicitly specified).
4405 the type of command is listed (reserved word, built-in, alias,
4406 function, tracked alias, or executable).
4409 option is used, a path search is performed even if
4411 is a reserved word, alias, etc.
4420 won't print aliases as alias commands.
4431 option does not affect the search path used, as it does for
4433 If the type of one or more of the names could not be determined, the exit
4437 Job control refers to the shell's ability to monitor and control jobs, which
4438 are processes or groups of processes created for commands or pipelines.
4439 At a minimum, the shell keeps track of the status of the background (i.e.\&
4440 asynchronous) jobs that currently exist; this information can be displayed
4444 If job control is fully enabled (using
4447 .Ic set -o monitor ) ,
4448 as it is for interactive shells, the processes of a job are placed in their
4450 Foreground jobs can be stopped by typing the suspend
4451 character from the terminal (normally ^Z), jobs can be restarted in either the
4452 foreground or background using the
4456 commands, and the state of the terminal is saved or restored when a foreground
4457 job is stopped or restarted, respectively.
4459 Note that only commands that create processes (e.g. asynchronous commands,
4460 subshell commands, and non-built-in, non-function commands) can be stopped;
4465 When a job is created, it is assigned a job number.
4466 For interactive shells, this number is printed inside
4468 followed by the process IDs of the processes in the job when an asynchronous
4470 A job may be referred to in the
4477 commands either by the process ID of the last process in the command pipeline
4480 parameter) or by prefixing the job number with a percent
4483 Other percent sequences can also be used to refer to jobs:
4484 .Bl -tag -width "%+ | %% | %XX"
4486 The most recently stopped job or, if there are no stopped jobs, the oldest
4489 The job that would be the
4491 job if the latter did not exist.
4493 The job with job number
4496 The job with its command containing the string
4498 (an error occurs if multiple jobs are matched).
4500 The job with its command starting with the string
4502 (an error occurs if multiple jobs are matched).
4505 When a job changes state (e.g. a background job finishes or foreground job is
4506 stopped), the shell prints the following status information:
4508 .D1 [ Ns Ar number ] Ar flag status command
4511 .Bl -tag -width "command"
4513 is the job number of the job;
4519 character if the job is the
4523 job, respectively, or space if it is neither;
4525 indicates the current state of the job and can be:
4526 .Bl -tag -width "RunningXX"
4527 .It Done Op Ar number
4530 is the exit status of the job, which is omitted if the status is zero.
4532 The job has neither stopped nor exited (note that running does not necessarily
4533 mean consuming CPU time \-
4534 the process could be blocked waiting for some event).
4535 .It Stopped Op Ar signal
4536 The job was stopped by the indicated
4538 (if no signal is given, the job was stopped by
4540 .It Ar signal-description Op Dq core dumped
4541 The job was killed by a signal (e.g. memory fault, hangup); use
4543 for a list of signal descriptions.
4546 message indicates the process created a core file.
4549 is the command that created the process.
4550 If there are multiple processes in
4551 the job, each process will have a line showing its
4555 if it is different from the status of the previous process.
4558 When an attempt is made to exit the shell while there are jobs in the stopped
4559 state, the shell warns the user that there are stopped jobs and does not exit.
4560 If another attempt is immediately made to exit the shell, the stopped jobs are
4563 signal and the shell exits.
4566 option is not set and there are running jobs when an attempt is made to exit
4567 a login shell, the shell warns the user and does not exit.
4569 is immediately made to exit the shell, the running jobs are sent a
4571 signal and the shell exits.
4572 .Ss Interactive input line editing
4573 The shell supports three modes of reading command lines from a
4575 in an interactive session, controlled by the
4580 options (at most one of these can be set at once).
4583 Editing modes can be set explicitly using the
4585 built-in, or implicitly via the
4589 environment variables.
4590 If none of these options are enabled,
4591 the shell simply reads lines using the normal
4598 option is set, the shell allows emacs-like editing of the command; similarly,
4601 option is set, the shell allows vi-like editing of the command.
4602 These modes are described in detail in the following sections.
4604 In these editing modes, if a line is longer than the screen width (see the
4612 character is displayed in the last column indicating that there are more
4613 characters after, before and after, or before the current position,
4615 The line is scrolled horizontally as necessary.
4616 .Ss Emacs editing mode
4619 option is set, interactive input line editing is enabled.
4620 Warning: This mode is
4621 slightly different from the emacs mode in the original Korn shell.
4622 In this mode, various editing commands
4623 (typically bound to one or more control characters) cause immediate actions
4624 without waiting for a newline.
4625 Several editing commands are bound to particular
4626 control characters when the shell is invoked; these bindings can be changed
4631 The following is a list of available editing commands.
4632 Each description starts with the name of the command,
4633 suffixed with a colon;
4636 (if the command can be prefixed with a count); and any keys the command is
4637 bound to by default, written using caret notation
4638 e.g. the ASCII ESC character is written as ^[.
4639 ^[A-Z] sequences are not case sensitive.
4640 A count prefix for a command is entered using the sequence
4644 is a sequence of 1 or more digits.
4645 Unless otherwise specified, if a count is
4646 omitted, it defaults to 1.
4648 Note that editing command names are used only with the
4651 Furthermore, many editing commands are useful only on terminals with
4653 The default bindings were chosen to resemble corresponding
4660 reasonable substitutes and override the default bindings.
4663 Useful as a response to a request for a
4665 pattern in order to abort the search.
4666 .It auto-insert: Op Ar n
4667 Simply causes the character to appear as literal input.
4668 Most ordinary characters are bound to this.
4669 .It Xo backward-char:
4673 Moves the cursor backward
4676 .It Xo backward-word:
4680 Moves the cursor backward to the beginning of the word; words consist of
4681 alphanumerics, underscore
4686 .It beginning-of-history: ^[<
4687 Moves to the beginning of the history.
4688 .It beginning-of-line: ^A
4689 Moves the cursor to the beginning of the edited input line.
4690 .It Xo capitalize-word:
4694 Uppercase the first character in the next
4696 words, leaving the cursor past the end of the last word.
4698 Clears the screen if the
4700 parameter is set and the terminal supports clearing the screen, then
4701 reprints the prompt string and the current input line.
4703 If the current line does not begin with a comment character, one is added at
4704 the beginning of the line and the line is entered (as if return had been
4705 pressed); otherwise, the existing comment characters are removed and the cursor
4706 is placed at the beginning of the line.
4708 Automatically completes as much as is unique of the command name or the file
4709 name containing the cursor.
4710 If the entire remaining command or file name is
4711 unique, a space is printed after its completion, unless it is a directory name
4715 If there is no command or file name with the current partial word
4716 as its prefix, a bell character is output (usually causing a beep to be
4719 Custom completions may be configured by creating an array named
4720 .Ql complete_command ,
4721 optionally suffixed with an argument number to complete only for a single
4723 So defining an array named
4725 provides possible completions for any argument to the
4729 only completes the first argument.
4730 For example, the following command makes
4732 offer a selection of signal names for the first argument to
4735 .Dl set -A complete_kill_1 -- -9 -HUP -INFO -KILL -TERM
4736 .It complete-command: ^X^[
4737 Automatically completes as much as is unique of the command name having the
4738 partial word up to the cursor as its prefix, as in the
4741 .It complete-file: ^[^X
4742 Automatically completes as much as is unique of the file name having the
4743 partial word up to the cursor as its prefix, as in the
4745 command described above.
4746 .It complete-list: ^I, ^[=
4747 Complete as much as is possible of the current word,
4748 and list the possible completions for it.
4749 If only one completion is possible,
4753 .It Xo delete-char-backward:
4759 characters before the cursor.
4760 .It Xo delete-char-forward:
4766 characters after the cursor.
4767 .It Xo delete-word-backward:
4769 .No WERASE , ^[ERASE , ^W, ^[^? , ^[^H , ^[h
4773 words before the cursor.
4774 .It Xo delete-word-forward:
4780 words after the cursor.
4781 .It Xo down-history:
4785 Scrolls the history buffer forward
4788 Each input line originally starts just after the last entry
4789 in the history buffer, so
4791 is not useful until either
4796 .It Xo downcase-word:
4803 .It end-of-history: ^[>
4804 Moves to the end of the history.
4806 Moves the cursor to the end of the input line.
4808 Acts as an end-of-file; this is useful because edit-mode input disables
4809 normal terminal input canonicalization.
4810 .It Xo eot-or-delete:
4816 if alone on a line; otherwise acts as
4817 .Ic delete-char-forward .
4819 Error (ring the bell).
4820 .It exchange-point-and-mark: ^X^X
4821 Places the cursor where the mark is and sets the mark to where the cursor was.
4822 .It expand-file: ^[*
4825 to the current word and replaces the word with the result of performing file
4826 globbing on the word.
4827 If no files match the pattern, the bell is rung.
4828 .It Xo forward-char:
4832 Moves the cursor forward
4835 .It Xo forward-word:
4839 Moves the cursor forward to the end of the
4842 .It Xo goto-history:
4846 Goes to history number
4849 Deletes the entire input line.
4854 Deletes the input from the cursor to the end of the line if
4856 is not specified; otherwise deletes characters between the cursor and column
4859 Prints a sorted, columnated list of command names or file names (if any) that
4860 can complete the partial word containing the cursor.
4861 Directory names have
4864 .It list-command: ^X?
4865 Prints a sorted, columnated list of command names (if any) that can complete
4866 the partial word containing the cursor.
4868 Prints a sorted, columnated list of file names (if any) that can complete the
4869 partial word containing the cursor.
4870 File type indicators are appended as described under
4873 .It newline: ^J , ^M
4874 Causes the current input line to be processed by the shell.
4875 The current cursor position may be anywhere on the line.
4876 .It newline-and-next: ^O
4877 Causes the current input line to be processed by the shell, and the next line
4878 from history becomes the current line.
4879 This is only useful after an
4882 .Ic search-history .
4885 .It Xo prev-hist-word:
4891 word of the previous command is inserted at the cursor.
4893 The following character is taken literally rather than as an editing command.
4895 Reprints the prompt string and the current input line.
4896 .It Xo search-character-backward:
4900 Search backward in the current line for the
4902 occurrence of the next character typed.
4903 .It Xo search-character-forward:
4907 Search forward in the current line for the
4909 occurrence of the next character typed.
4910 .It search-history: ^R
4911 Enter incremental search mode.
4912 The internal history list is searched
4913 backwards for commands matching the input.
4916 in the search string anchors the search.
4917 The abort key will leave search mode.
4918 Other commands will be executed after leaving search mode.
4921 commands continue searching backward to the next previous occurrence of the
4923 The history buffer retains only a finite number of lines; the oldest
4924 are discarded as necessary.
4925 .It set-mark-command: ^[ Ns Aq space
4926 Set the mark at the cursor position.
4927 .It transpose-chars: ^T
4928 If at the end of line, or if the
4930 option is set, this exchanges the two previous characters; otherwise, it
4931 exchanges the previous and current characters and moves the cursor one
4932 character to the right.
4937 Scrolls the history buffer backward
4950 Inserts the most recently killed text string at the current cursor position.
4954 replaces the inserted text string with the next previously killed text string.
4957 The following editing commands lack default bindings but can be used with the
4962 Deletes the input between the cursor and the mark.
4965 The vi command-line editor in
4967 has basically the same commands as the
4969 editor with the following exceptions:
4972 You start out in insert mode.
4974 There are file name and command completion commands:
4975 =, \e, *, ^X, ^E, ^F, and, optionally,
4982 command is different (in
4984 it is the last argument command; in
4986 it goes to the start of the current line).
4992 commands move in the opposite direction to the
4996 Commands which don't make sense in a single line editor are not available
4997 (e.g. screen movement commands and
5004 Note that the ^X stands for control-X; also
5009 are used for escape, space, and tab, respectively (no kidding).
5013 there are two modes:
5018 In insert mode, most characters are simply put in the buffer at the
5019 current cursor position as they are typed; however, some characters are
5021 In particular, the following characters are taken from current
5026 and have their usual meaning (normal values are in parentheses): kill (^U),
5027 erase (^?), werase (^W), eof (^D), intr (^C), and quit (^\e).
5029 the above, the following characters are also treated specially in insert mode:
5032 Command and file name enumeration (see below).
5034 Command and file name completion (see below).
5035 If used twice in a row, the
5036 list of possible completions is displayed; if used a third time, the completion
5039 Erases previous character.
5042 The current line is read, parsed, and executed by the shell.
5045 The next character typed is not treated specially (can be used
5046 to insert the characters being described here).
5048 Command and file name expansion (see below).
5050 Puts the editor in command mode (see below).
5052 Optional file name and command completion (see
5054 above), enabled with
5055 .Ic set -o vi-tabcomplete .
5058 In command mode, each character is interpreted as a command.
5060 don't correspond to commands, are illegal combinations of commands, or are
5061 commands that can't be carried out, all cause beeps.
5062 In the following command descriptions, an
5064 indicates the command may be prefixed by a number (e.g.\&
5066 moves right 10 characters); if no number prefix is used,
5068 is assumed to be 1 unless otherwise specified.
5070 .Dq current position
5071 refers to the position between the cursor and the character preceding the
5075 is a sequence of letters, digits, and underscore characters or a sequence of
5076 non-letter, non-digit, non-underscore, and non-whitespace characters (e.g.\&
5078 contains two words) and a
5080 is a sequence of non-whitespace characters.
5086 The following commands are not in, or are different from, the normal vi file
5092 Insert a space followed by the
5094 big-word from the last command in the history at the current position and enter
5097 is not specified, the last word is inserted.
5099 Insert the comment character
5101 at the start of the current line and return the line to the shell (equivalent
5111 is not specified, it goes to the most recent remembered line.
5121 is not specified, the current line is edited.
5122 The actual command executed is
5123 .Ic fc -e ${VISUAL:-${EDITOR:-vi}} Ar n .
5125 Command or file name expansion is applied to the current big-word (with an
5128 if the word contains no file globbing characters) \- the big-word is replaced
5129 with the resulting words.
5130 If the current big-word is the first on the line
5131 or follows one of the characters
5138 and does not contain a slash
5140 then command expansion is done; otherwise file name expansion is done.
5141 Command expansion will match the big-word against all aliases, functions, and
5142 built-in commands as well as any executable files found by searching the
5146 File name expansion matches the big-word against the files in the
5148 After expansion, the cursor is placed just past the last
5149 word and the editor is in insert mode.
5153 .Oo Ar n Oc Ns Aq tab ,
5155 .Oo Ar n Oc Ns Aq esc
5157 Command/file name completion.
5158 Replace the current big-word with the
5159 longest unique match obtained after performing command and file name expansion.
5161 is only recognized if the
5163 option is set, while
5165 is only recognized if the
5173 possible completion is selected (as reported by the command/file name
5174 enumeration command).
5176 Command/file name enumeration.
5177 List all the commands or files that match the current big-word.
5180 Execute the commands found in the alias
5184 Intra-line movement commands:
5187 .Oo Ar n Oc Ns h and
5194 .Oo Ar n Oc Ns l and
5195 .Oo Ar n Oc Ns Aq space
5203 Move to the first non-whitespace character.
5210 Move to the last character.
5226 Move forward to the end of the word,
5232 Move forward to the end of the big-word,
5249 The editor looks forward for the nearest parenthesis, bracket, or
5250 brace and then moves the cursor to the matching parenthesis, bracket, or brace.
5252 .Oo Ar n Oc Ns f Ns Ar c
5256 occurrence of the character
5259 .Oo Ar n Oc Ns F Ns Ar c
5261 Move backward to the
5263 occurrence of the character
5266 .Oo Ar n Oc Ns t Ns Ar c
5268 Move forward to just before the
5270 occurrence of the character
5273 .Oo Ar n Oc Ns T Ns Ar c
5275 Move backward to just before the
5277 occurrence of the character
5294 command, but moves in the opposite direction.
5297 Inter-line movement commands:
5307 next line in the history.
5316 previous line in the history.
5324 is not specified, the number of the first remembered line is used.
5332 is not specified, it goes to the most recent remembered line.
5334 .Oo Ar n Oc Ns / Ns Ar string
5336 Search backward through the history for the
5344 the remainder of the string must appear at the start of the history line for
5347 .Oo Ar n Oc Ns \&? Ns Ar string
5351 except it searches forward through the history.
5357 occurrence of the last search string;
5358 the direction of the search is the same as the last search.
5364 occurrence of the last search string;
5365 the direction of the search is the opposite of the last search.
5375 times; goes into insert mode just after the current position.
5377 only replicated if command mode is re-entered i.e.\&
5385 except it appends at the end of the line.
5391 times; goes into insert mode at the current position.
5392 The insertion is only
5393 replicated if command mode is re-entered i.e.\&
5401 except the insertion is done just before the first non-blank character.
5407 characters (i.e. delete the characters and go into insert mode).
5409 Substitute whole line.
5410 All characters from the first non-blank character to the
5411 end of the line are deleted and insert mode is entered.
5413 .Oo Ar n Oc Ns c Ns Ar move-cmd
5415 Change from the current position to the position resulting from
5417 (i.e. delete the indicated region and go into insert mode); if
5421 the line starting from the first non-blank character is changed.
5423 Change from the current position to the end of the line (i.e. delete to the
5424 end of the line and go into insert mode).
5438 Delete to the end of the line.
5440 .Oo Ar n Oc Ns d Ns Ar move-cmd
5442 Delete from the current position to the position resulting from
5443 .Ar n move-cmd Ns s ;
5445 is a movement command (see above) or
5447 in which case the current line is deleted.
5449 .Oo Ar n Oc Ns r Ns Ar c
5453 characters with the character
5459 Enter insert mode but overwrite existing characters instead of
5460 inserting before existing characters.
5461 The replacement is repeated
5467 Change the case of the next
5471 .Oo Ar n Oc Ns y Ns Ar move-cmd
5473 Yank from the current position to the position resulting from
5475 into the yank buffer; if
5479 the whole line is yanked.
5481 Yank from the current position to the end of the line.
5485 Paste the contents of the yank buffer just after the current position,
5493 except the buffer is pasted at the current position.
5496 Miscellaneous vi commands
5499 The current line is read, parsed, and executed by the shell.
5501 Redraw the current line.
5505 Redo the last edit command
5509 Undo the last edit command.
5511 Undo all changes that have been made to the current line.
5512 .It Ar intr No and Ar quit
5513 The interrupt and quit terminal characters cause the current line to be
5514 deleted and a new prompt to be printed.
5517 .Bl -tag -width "/etc/suid_profileXX" -compact
5519 User's login profile.
5520 .It Pa /etc/ksh.kshrc
5521 Global configuration file.
5522 Not sourced by default.
5524 System login profile.
5527 .It Pa /etc/suid_profile
5528 Privileged shell profile.
5543 .%B The KornShell Command and Programming Language, 2nd Edition
5549 .%A Stephen G. Kochan
5551 .%B UNIX Shell Programming, 3rd Edition
5559 .%O ISBN 1-55937-266-9
5560 .%T IEEE Standard for Information Technology \- Portable Operating \
5561 System Interface (POSIX) \- Part 2: Shell and Utilities
5564 This page documents version @(#)PD KSH v5.2.14 99/07/13.2 of the public
5568 This shell is based on the public domain 7th edition Bourne shell clone by
5570 and parts of the BRL shell by
5574 .An Arnold Robbins ,
5577 The first release of
5581 and it was subsequently maintained by
5582 .An John R. MacMillan Aq Mt change!john@sq.sq.com ,
5583 .An Simon J. Gerraty Aq Mt sjg@zen.void.oz.au ,
5585 .An Michael Rendell Aq Mt michael@cs.mun.ca .
5588 file in the source distribution contains a more complete list of people and
5589 their part in the shell's development.
5592 expressions are currently parsed by finding the closest matching (unquoted)
5594 Thus constructs inside
5596 may produce an error.
5597 For example, the parenthesis in
5599 is interpreted as the closing parenthesis in
5600 .Ql $(case x in x);; *);; esac) .