1KSH(1) General Commands Manual KSH(1)
2
3
4
6 ksh, rksh, pfksh - KornShell, a standard/restricted command and pro‐
7 gramming language
8
10 Currently, rksh and pfksh are not available on macOS / Darwin.
11
13 ksh [ ±abcefhiknoprstuvxBCDP ] [ -R file ] [ ±o option ] ... [ - ] [
14 arg ... ]
15
17 Ksh is a command and programming language that executes commands read
18 from a terminal or a file. Rksh is a restricted version of the command
19 interpreter ksh; it is used to set up login names and execution envi‐
20 ronments whose capabilities are more controlled than those of the stan‐
21 dard shell. Rpfksh is a profile shell version of the command inter‐
22 preter ksh; it is used to execute commands with the attributes speci‐
23 fied by the user's profiles (see pfexec(1)). See Invocation below for
24 the meaning of arguments to the shell.
25
26 Definitions.
27 A metacharacter is one of the following characters:
28
29 ; & ( ) ⎪ < > new-line space tab
30
31 A blank is a tab or a space. An identifier is a sequence of letters,
32 digits, or underscores starting with a letter or underscore. Identi‐
33 fiers are used as components of variable names. A vname is a sequence
34 of one or more identifiers separated by a . and optionally preceded by
35 a .. Vnames are used as function and variable names. A word is a
36 sequence of characters from the character set defined by the current
37 locale, excluding non-quoted metacharacters.
38
39 A command is a sequence of characters in the syntax of the shell lan‐
40 guage. The shell reads each command and carries out the desired action
41 either directly or by invoking separate utilities. A built-in command
42 is a command that is carried out by the shell itself without creating a
43 separate process. Some commands are built-in purely for convenience
44 and are not documented here. Built-ins that cause side effects in the
45 shell environment and built-ins that are found before performing a path
46 search (see Execution below) are documented here. For historical rea‐
47 sons, some of these built-ins behave differently than other built-ins
48 and are called special built-ins.
49
50 Commands.
51 A simple-command is a list of variable assignments (see Variable
52 Assignments below) or a sequence of blank separated words which may be
53 preceded by a list of variable assignments (see Environment below).
54 The first word specifies the name of the command to be executed.
55 Except as specified below, the remaining words are passed as arguments
56 to the invoked command. The command name is passed as argument 0 (see
57 exec(2)). The value of a simple-command is its exit status; 0-255 if
58 it terminates normally; 256+signum if it terminates abnormally (the
59 name of the signal corresponding to the exit status can be obtained via
60 the -l option of the kill built-in utility).
61
62 A pipeline is a sequence of one or more commands separated by ⎪. The
63 standard output of each command but the last is connected by a pipe(2)
64 to the standard input of the next command. Each command, except possi‐
65 bly the last, is run as a separate process; the shell waits for the
66 last command to terminate. The exit status of a pipeline is the exit
67 status of the last command unless the pipefail option is enabled. Each
68 pipeline can be preceded by the reserved word ! which causes the exit
69 status of the pipeline to become 0 if the exit status of the last com‐
70 mand is non-zero, and 1 if the exit status of the last command is 0.
71
72 A list is a sequence of one or more pipelines separated by ;, &, ⎪&,
73 &&, or ⎪⎪, and optionally terminated by ;, &, or ⎪&. Of these five
74 symbols, ;, &, and ⎪& have equal precedence, which is lower than that
75 of && and ⎪⎪. The symbols && and ⎪⎪ also have equal precedence. A
76 semicolon (;) causes sequential execution of the preceding pipeline; an
77 ampersand (&) causes asynchronous execution of the preceding pipeline
78 (i.e., the shell does not wait for that pipeline to finish). The sym‐
79 bol ⎪& causes asynchronous execution of the preceding pipeline with a
80 two-way pipe established to the parent shell; the standard input and
81 output of the spawned pipeline can be written to and read from by the
82 parent shell by applying the redirection operators <& and >& with arg p
83 to commands and by using -p option of the built-in commands read and
84 print described later. The symbol && (⎪⎪) causes the list following it
85 to be executed only if the preceding pipeline returns a zero (non-zero)
86 value. One or more new-lines may appear in a list instead of a semi‐
87 colon, to delimit a command. The first item of the first pipeline of
88 a list that is a simple command not beginning with a redirection, and
89 not occurring within a while, until, or if list, can be preceded by a
90 semicolon. This semicolon is ignored unless the showme option is
91 enabled as described with the set built-in below.
92
93 A command is either a simple-command or one of the following. Unless
94 otherwise stated, the value returned by a command is that of the last
95 simple-command executed in the command.
96
97 for vname [ in word ... ] ;do list ;done
98 Each time a for command is executed, vname is set to the next
99 word taken from the in word list. If in word ... is omitted,
100 then the for command executes the do list once for each posi‐
101 tional parameter that is set starting from 1 (see Parameter
102 Expansion below). Execution ends when there are no more words
103 in the list.
104
105 for (( [expr1] ; [expr2] ; [expr3] )) ;do list ;done
106 The arithmetic expression expr1 is evaluated first (see Arith‐
107 metic evaluation below). The arithmetic expression expr2 is
108 repeatedly evaluated until it evaluates to zero and when non-
109 zero, list is executed and the arithmetic expression expr3 eval‐
110 uated. If any expression is omitted, then it behaves as if it
111 evaluated to 1.
112
113 select vname [ in word ... ] ;do list ;done
114 A select command prints on standard error (file descriptor 2)
115 the set of words, each preceded by a number. If in word ... is
116 omitted, then the positional parameters starting from 1 are used
117 instead (see Parameter Expansion below). The PS3 prompt is
118 printed and a line is read from the standard input. If this
119 line consists of the number of one of the listed words, then the
120 value of the variable vname is set to the word corresponding to
121 this number. If this line is empty, the selection list is
122 printed again. Otherwise the value of the variable vname is set
123 to null. The contents of the line read from standard input is
124 saved in the variable REPLY. The list is executed for each
125 selection until a break or end-of-file is encountered. If the
126 REPLY variable is set to null by the execution of list, then the
127 selection list is printed before displaying the PS3 prompt for
128 the next selection.
129
130 case word in [ [(]pattern [ ⎪ pattern ] ... ) list ;; ] ... esac
131 A case command executes the list associated with the first pat‐
132 tern that matches word. The form of the patterns is the same as
133 that used for file-name generation (see File Name Generation
134 below). The ;; operator causes execution of case to terminate.
135 If ;& is used in place of ;; the next subsequent list, if any,
136 is executed.
137
138 if list ;then list [ ;elif list ;then list ] ... [ ;else list ] ;fi
139 The list following if is executed and, if it returns a zero exit
140 status, the list following the first then is executed. Other‐
141 wise, the list following elif is executed and, if its value is
142 zero, the list following the next then is executed. Failing
143 each successive elif list, the else list is executed. If the if
144 list has non-zero exit status and there is no else list, then
145 the if command returns a zero exit status.
146
147 while list ;do list ;done
148 until list ;do list ;done
149 A while command repeatedly executes the while list and, if the
150 exit status of the last command in the list is zero, executes
151 the do list; otherwise the loop terminates. If no commands in
152 the do list are executed, then the while command returns a zero
153 exit status; until may be used in place of while to negate the
154 loop termination test.
155
156 ((expression))
157 The expression is evaluated using the rules for arithmetic eval‐
158 uation described below. If the value of the arithmetic expres‐
159 sion is non-zero, the exit status is 0, otherwise the exit sta‐
160 tus is 1.
161
162 (list)
163 Execute list in a separate environment. Note, that if two adja‐
164 cent open parentheses are needed for nesting, a space must be
165 inserted to avoid evaluation as an arithmetic command as
166 described above.
167
168 { list;}
169 list is simply executed. Note that unlike the metacharacters (
170 and ), { and } are reserved words and must occur at the begin‐
171 ning of a line or after a ; in order to be recognized.
172
173 [[ expression ]]
174 Evaluates expression and returns a zero exit status when expres‐
175 sion is true. See Conditional Expressions below, for a descrip‐
176 tion of expression.
177
178 function varname { list ;}
179 varname () { list ;}
180 Define a function which is referenced by varname. A function
181 whose varname contains a . is called a discipline function and
182 the portion of the varname preceding the last . must refer to
183 an existing variable. The body of the function is the list of
184 commands between { and }. A function defined with the function
185 varname syntax can also be used as an argument to the . special
186 built-in command to get the equivalent behavior as if the var‐
187 name() syntax were used to define it. (See Functions below.)
188
189 namespace varname { list ;}
190 Defines or uses the name space identifier and runs the commands
191 in list in this name space. (See Name Spaces below.)
192
193 & [ name [ arg... ] ]
194 Causes subsequent list commands terminated by & to be placed in
195 the background job pool name. If name is omitted a default
196 unnamed pool is used. Commands in a named background pool may
197 be executed remotely.
198
199 time [ pipeline ]
200 If pipeline is omitted the user and system time for the current
201 shell and completed child processes is printed on standard
202 error. Otherwise, pipeline is executed and the elapsed time as
203 well as the user and system time are printed on standard error.
204 The TIMEFORMAT variable may be set to a format string that spec‐
205 ifies how the timing information should be displayed. See Shell
206 Variables below for a description of the TIMEFORMAT variable.
207
208 The following reserved words are recognized as reserved only when they
209 are the first word of a command and are not quoted:
210
211 if then else elif fi case esac for while until do done { } function
212 select time [[ ]] !
213
214 Variable Assignments.
215 One or more variable assignments can start a simple command or can be
216 arguments to the typeset, enum, export, or readonly special built-in
217 commands as well as to other declaration commands created as types.
218 The syntax for an assignment is of the form:
219
220 varname=word
221 varname[word]=word
222 No space is permitted between varname and the = or between = and
223 word.
224
225 varname=(assign_list)
226 No space is permitted between varname and the =. The variable
227 varname is unset before the assignment. An assign_list can be
228 one of the following:
229 word ...
230 Indexed array assignment.
231 [word]=word ...
232 Associative array assignment. If preceded by
233 typeset -a this will create an indexed array
234 instead.
235 assignment ...
236 Compound variable assignment. This creates a
237 compound variable varname with sub-variables of
238 the form varname.name, where name is the name
239 portion of assignment. The value of varname will
240 contain all the assignment elements. Additional
241 assignments made to sub-variables of varname will
242 also be displayed as part of the value of var‐
243 name. If no assignments are specified, varname
244 will be a compound variable allowing subsequence
245 child elements to be defined.
246 typeset [options] assignment ...
247 Nested variable assignment. Multiple assignments
248 can be specified by separating each of them with
249 a ;. The previous value is unset before the
250 assignment. Other declaration commands such as
251 readonly, enum, and other declaration commands
252 can be used in place of typeset.
253 . filename
254 Include the assignment commands contained in
255 filename.
256
257 In addition, a += can be used in place of the = to signify adding to or
258 appending to the previous value. When += is applied to an arithmetic
259 type, word is evaluated as an arithmetic expression and added to the
260 current value. When applied to a string variable, the value defined by
261 word is appended to the value. For compound assignments, the previous
262 value is not unset and the new values are appended to the current ones
263 provided that the types are compatible.
264
265 The right hand side of a variable assignment undergoes all the expan‐
266 sion listed below except word splitting, brace expansion, and file name
267 generation. When the left hand side is an assignment is a compound
268 variable and the right hand is the name of a compound variable, the
269 compound variable on the right will be copied or appended to the com‐
270 pound variable on the left.
271
272 Comments.
273 A word beginning with # causes that word and all the following charac‐
274 ters up to a new-line to be ignored.
275 Aliasing.
276 The first word of each command is replaced by the text of an alias if
277 an alias for this word has been defined. An alias name consists of any
278 number of characters excluding metacharacters, quoting characters, file
279 expansion characters, parameter expansion and command substitution
280 characters, the characters / and =. The replacement string can contain
281 any valid shell script including the metacharacters listed above. The
282 first word of each command in the replaced text, other than any that
283 are in the process of being replaced, will be tested for aliases. If
284 the last character of the alias value is a blank then the word follow‐
285 ing the alias will also be checked for alias substitution. Aliases can
286 be used to redefine built-in commands but cannot be used to redefine
287 the reserved words listed above. Aliases can be created and listed
288 with the alias command and can be removed with the unalias command.
289 Aliasing is performed when scripts are read, not while they are exe‐
290 cuted. Therefore, for an alias to take effect, the alias definition
291 command has to be executed before the command which references the
292 alias is read.
293 The following aliases are compiled into the shell but can be unset or
294 redefined:
295 autoload=′typeset -fu′
296 bool=′_Bool′
297 command=′command ′
298 compound=′typeset -C′
299 fc=hist
300 float=′typeset -lE′
301 functions=′typeset -f′
302 hash=′alias -t --′
303 history=′hist -l′
304 integer=′typeset -li′
305 nameref=′typeset -n′
306 nohup=′nohup ′
307 r=′hist -s′
308 redirect=′command exec′
309 source=′command .′
310 stop=′kill -s STOP′
311 suspend=′kill -s STOP "$$"′
312 times=′{ { time;} 2>&1;}′
313 type=′whence -v′
314
315 Tilde Substitution.
316 After alias substitution is performed, each word is checked to see if
317 it begins with an unquoted ∼. For tilde substitution, word also refers
318 to the word portion of parameter expansion (see Parameter Expansion
319 below). If it does, then the word up to a / is checked to see if it
320 matches a user name in the password database (See getpwname(3).) If a
321 match is found, the ∼ and the matched login name are replaced by the
322 login directory of the matched user. If no match is found, the origi‐
323 nal text is left unchanged. A ∼ by itself, or in front of a /, is
324 replaced by $HOME. A ∼ followed by a + or - is replaced by the value
325 of $PWD and $OLDPWD respectively. A ∼ followed by {fd} where fd is a
326 file descriptor number or the name of a variable whose value is a file
327 descriptor, is replaced by a string that is the equivalent to the path
328 name of the file or directory corresponding to this file descriptor.
329
330 In addition, when expanding a variable assignment, tilde substitution
331 is attempted when the value of the assignment begins with a ∼, and when
332 a ∼ appears after a :. The : also terminates a ∼ login name.
333
334 Command Substitution.
335 The standard output from a command list enclosed in parentheses pre‐
336 ceded by a dollar sign ( $(list) ), or in a brace group preceded by a
337 dollar sign ( ${ list;} ), or in a pair of grave accents (``) may be
338 used as part or all of a word; trailing new-lines are removed. In the
339 second case, the { and } are treated as a reserved words so that { must
340 be followed by a blank and } must appear at the beginning of the line
341 or follow a ;. In the third (obsolete) form, the string between the
342 quotes is processed for special quoting characters before the command
343 is executed (see Quoting below). The command substitution $(cat file)
344 can be replaced by the equivalent but faster $(<file). The command
345 substitution $(n<#) will expand to the current byte offset for file
346 descriptor n. Except for the second form, the command list is run in a
347 subshell so that no side effects are possible. For the second form,
348 the final } will be recognized as a reserved word after any token.
349
350 Arithmetic Substitution.
351 An arithmetic expression enclosed in double parentheses preceded by a
352 dollar sign ( $(()) ) is replaced by the value of the arithmetic
353 expression within the double parentheses.
354
355 Process Substitution.
356 Each command argument of the form <(list) or >(list) will run process
357 list asynchronously connected to some file in /dev/fd if this directory
358 exists, or else a fifo a temporary directory. The name of this file
359 will become the argument to the command. If the form with > is
360 selected then writing on this file will provide input for list. If <
361 is used, then the file passed as an argument will contain the output of
362 the list process. For example,
363
364 paste <(cut -f1 file1) <(cut -f3 file2) | tee >(process1)
365 >(process2)
366
367 cuts fields 1 and 3 from the files file1 and file2 respectively, pastes
368 the results together, and sends it to the processes process1 and
369 process2, as well as putting it onto the standard output. Note that
370 the file, which is passed as an argument to the command, is a UNIX
371 pipe(2) so programs that expect to lseek(2) on the file will not work.
372
373 Process substitution of the form <(list) can also be used with the <
374 redirection operator which causes the output of list to be standard
375 input or the input for whatever file descriptor is specified.
376
377 Parameter Expansion.
378 A parameter is a variable, one or more digits, or any of the characters
379 *, @, #, ?, -, $, and !. A variable is denoted by a vname. To create
380 a variable whose vname contains a ., a variable whose vname consists of
381 everything before the last . must already exist. A variable has a
382 value and zero or more attributes. Variables can be assigned values
383 and attributes by using the typeset special built-in command. The
384 attributes supported by the shell are described later with the typeset
385 special built-in command. Exported variables pass values and
386 attributes to the environment.
387
388 The shell supports both indexed and associative arrays. An element of
389 an array variable is referenced by a subscript. A subscript for an
390 indexed array is denoted by an arithmetic expression (see Arithmetic
391 evaluation below) between a [ and a ]. To assign values to an indexed
392 array, use vname=(value ...) or set -A vname value ... . The value of
393 all non-negative subscripts must be in the range of 0 through
394 4,194,303. A negative subscript is treated as an offset from the maxi‐
395 mum current index +1 so that -1 refers to the last element. Indexed
396 arrays can be declared with the -a option to typeset. Indexed arrays
397 need not be declared. Any reference to a variable with a valid sub‐
398 script is legal and an array will be created if necessary.
399
400 An associative array is created with the -A option to typeset. A sub‐
401 script for an associative array is denoted by a string enclosed between
402 [ and ].
403
404 Referencing any array without a subscript is equivalent to referencing
405 the array with subscript 0.
406
407 The value of a variable may be assigned by writing:
408
409 vname=value [ vname=value ] ...
410
411 or
412 vname[subscript]=value [ vname[subscript]=value ] ...
413 Note that no space is allowed before or after the =.
414 Attributes assigned by the typeset special built-in command apply to
415 all elements of the array. An array element can be a simple variable,
416 a compound variable or an array variable. An element of an indexed
417 array can be either an indexed array or an associative array. An ele‐
418 ment of an associative array can also be either. To refer to an array
419 element that is part of an array element, concatenate the subscript in
420 brackets. For example, to refer to the foobar element of an associa‐
421 tive array that is defined as the third element of the indexed array,
422 use ${vname[3][foobar]}
423 A nameref is a variable that is a reference to another variable. A
424 nameref is created with the -n attribute of typeset. The value of the
425 variable at the time of the typeset command becomes the variable that
426 will be referenced whenever the nameref variable is used. The name of
427 a nameref cannot contain a .. When a variable or function name con‐
428 tains a ., and the portion of the name up to the first . matches the
429 name of a nameref, the variable referred to is obtained by replacing
430 the nameref portion with the name of the variable referenced by the
431 nameref. If a nameref is used as the index of a for loop, a name ref‐
432 erence is established for each item in the list. A nameref provides a
433 convenient way to refer to the variable inside a function whose name is
434 passed as an argument to a function. For example, if the name of a
435 variable is passed as the first argument to a function, the command
436 typeset -n var=$1
437 inside the function causes references and assignments to var to be ref‐
438 erences and assignments to the variable whose name has been passed to
439 the function.
440 If any of the floating point attributes, -E, -F, or -X, or the integer
441 attribute, -i, is set for vname, then the value is subject to arith‐
442 metic evaluation as described below.
443 Positional parameters, parameters denoted by a number, may be assigned
444 values with the set special built-in command. Parameter $0 is set from
445 argument zero when the shell is invoked.
446 The character $ is used to introduce substitutable parameters.
447 ${parameter}
448 The shell reads all the characters from ${ to the matching } as
449 part of the same word even if it contains braces or metacharac‐
450 ters. The value, if any, of the parameter is substituted. The
451 braces are required when parameter is followed by a letter,
452 digit, or underscore that is not to be interpreted as part of
453 its name, when the variable name contains a .. The braces are
454 also required when a variable is subscripted unless it is part
455 of an Arithmetic Expression or a Conditional Expression. If
456 parameter is one or more digits then it is a positional parame‐
457 ter. A positional parameter of more than one digit must be
458 enclosed in braces. If parameter is * or @, then all the posi‐
459 tional parameters, starting with $1, are substituted (separated
460 by a field separator character). If an array vname with last
461 subscript * @, or for index arrays of the form sub1 .. sub2.
462 is used, then the value for each of the elements between sub1
463 and sub2 inclusive (or all elements for * and @) is substituted,
464 separated by the first character of the value of IFS.
465 ${#parameter}
466 If parameter is * or @, the number of positional parameters is
467 substituted. Otherwise, the length of the value of the parame‐
468 ter is substituted.
469 ${#vname[*]}
470 ${#vname[@]}
471 The number of elements in the array vname is substituted.
472
473 ${@vname}
474 Expands to the type name (See Type Variables below) or
475 attributes of the variable referred to by vname.
476 ${$parameter}
477 If $parameter expands to the name of a variable, this expands to
478 the value of that variable. Otherwise, it expands to the empty
479 string. It is undefined for special parameters.
480 ${!vname}
481 Expands to the name of the variable referred to by vname. This
482 will be vname except when vname is a name reference.
483 ${!vname[subscript]}
484 Expands to name of the subscript unless subscript is *, @. or
485 of the form sub1 .. sub2. When subscript is *, the list of
486 array subscripts for vname is generated. For a variable that is
487 not an array, the value is 0 if the variable is set. Otherwise
488 it is null. When subscript is @, same as above, except that
489 when used in double quotes, each array subscript yields a sepa‐
490 rate argument. When subscript is of the form sub1 .. sub2 it
491 expands to the list of subscripts between sub1 and sub2 inclu‐
492 sive using the same quoting rules as @.
493 ${!prefix*}
494 Expands to the names of the variables whose names begin with
495 prefix.
496 ${parameter:-word}
497 If parameter is set and is non-null then substitute its value;
498 otherwise substitute word.
499 ${parameter:=word}
500 If parameter is not set or is null then set it to word; the
501 value of the parameter is then substituted. Positional parame‐
502 ters may not be assigned to in this way.
503 ${parameter:?word}
504 If parameter is set and is non-null then substitute its value;
505 otherwise, print word and exit from the shell (if not interac‐
506 tive). If word is omitted then a standard message is printed.
507 ${parameter:+word}
508 If parameter is set and is non-null then substitute word; other‐
509 wise substitute nothing.
510 In the above, word is not evaluated unless it is to be used as the sub‐
511 stituted string, so that, in the following example, pwd is executed
512 only if d is not set or is null:
513 print ${d:-$(pwd)}
514 If the colon ( : ) is omitted from the above expressions, then the
515 shell only checks whether parameter is set or not.
516 ${parameter:offset:length}
517 ${parameter:offset}
518 Expands to the portion of the value of parameter starting at the
519 character (counting from 0) determined by expanding offset as an
520 arithmetic expression and consisting of the number of characters
521 determined by the arithmetic expression defined by length. In
522 the second form, the remainder of the value is used. If A nega‐
523 tive offset counts backwards from the end of parameter. Note
524 that one or more blanks is required in front of a minus sign to
525 prevent the shell from interpreting the operator as :-. If
526 parameter is * or @, or is an array name indexed by * or @, then
527 offset and length refer to the array index and number of ele‐
528 ments respectively. A negative offset is taken relative to one
529 greater than the highest subscript for indexed arrays. The
530 order for associate arrays is unspecified.
531 ${parameter#pattern}
532 ${parameter##pattern}
533 If the shell pattern matches the beginning of the value of
534 parameter, then the value of this expansion is the value of the
535 parameter with the matched portion deleted; otherwise the value
536 of this parameter is substituted. In the first form the small‐
537 est matching pattern is deleted and in the second form the
538 largest matching pattern is deleted. When parameter is @, *, or
539 an array variable with subscript @ or *, the substring operation
540 is applied to each element in turn.
541
542 ${parameter%pattern}
543 ${parameter%%pattern}
544 If the shell pattern matches the end of the value of parameter,
545 then the value of this expansion is the value of the parameter
546 with the matched part deleted; otherwise substitute the value of
547 parameter. In the first form the smallest matching pattern is
548 deleted and in the second form the largest matching pattern is
549 deleted. When parameter is @, *, or an array variable with sub‐
550 script @ or *, the substring operation is applied to each ele‐
551 ment in turn.
552
553 ${parameter/pattern/string}
554 ${parameter//pattern/string}
555 ${parameter/#pattern/string}
556 ${parameter/%pattern/string}
557 Expands parameter and replaces the longest match of pattern with
558 the given string. Each occurrence of \n in string is replaced
559 by the portion of parameter that matches the n-th sub-pattern.
560 In the first form, only the first occurrence of pattern is
561 replaced. In the second form, each match for pattern is
562 replaced by the given string. The third form restricts the pat‐
563 tern match to the beginning of the string while the fourth form
564 restricts the pattern match to the end of the string. When
565 string is null, the pattern will be deleted and the / in front
566 of string may be omitted. When parameter is @, *, or an array
567 variable with subscript @ or *, the substitution operation is
568 applied to each element in turn. In this case, the string por‐
569 tion of word will be re-evaluated for each element.
570
571 ${parameter^pattern}
572 ${parameter^^pattern}
573 ${parameter,pattern}
574 ${parameter,,pattern}
575 Case modification. This expansion modifies the case of alpha‐
576 betic characters in parameter. The pattern is expanded to pro‐
577 duce a pattern just as in pathname expansion. The ^ operator
578 converts lowercase characters matching pattern to uppercase.
579 The , operator converts matching uppercase characters to lower‐
580 case. The ^^ and ,, expansions convert all matched charac‐
581 ter in the expanded value. The ^ and , expansions match and
582 convert only the first character in the expanded value. If pat‐
583 tern is omitted it is treated like a ?, which matches every
584 character. If parameter is @ or *, or an array subscripted by @
585 or *, the case modification operation is applied to each ele‐
586 ment.
587
588
589 The following parameters are automatically set by the shell:
590 # The number of positional parameters in decimal.
591 - Options supplied to the shell on invocation or by the set
592 command.
593 ? The decimal value returned by the last executed command.
594 $ The process number of this shell.
595 _ Initially, the value of _ is an absolute pathname of the
596 shell or script being executed as passed in the environ‐
597 ment. Subsequently it is assigned the last argument of
598 the previous command. This parameter is not set for com‐
599 mands which are asynchronous. This parameter is also
600 used to hold the name of the matching MAIL file when
601 checking for mail. While defining a compound variable or
602 a type, _ is initialized as a reference to the compound
603 variable or type. When a discipline function is invoked,
604 _ is initialized as a reference to the variable associ‐
605 ated with the call to this function. Finally when _ is
606 used as the name of the first variable of a type defini‐
607 tion, the new type is derived from the type of the first
608 variable (See Type Variables below.).
609 ! The process id or the pool name and job number of the
610 last background command invoked or the most recent job
611 put in the background with the bg built-in command.
612 Background jobs started in a named pool will be in the
613 form pool.number where pool is the pool name and number
614 is the job number within that pool.
615 .sh.command
616 When processing a DEBUG trap, this variable contains the
617 current command line that is about to run.
618 .sh.edchar
619 This variable contains the value of the keyboard charac‐
620 ter (or sequence of characters if the first character is
621 an ESC, ascii 033) that has been entered when processing
622 a KEYBD trap (see Key Bindings below). If the value is
623 changed as part of the trap action, then the new value
624 replaces the key (or key sequence) that caused the trap.
625 .sh.edcol
626 The character position of the cursor at the time of the
627 most recent KEYBD trap.
628 .sh.edmode
629 The value is set to ESC when processing a KEYBD trap
630 while in vi insert mode. (See Vi Editing Mode below.)
631 Otherwise, .sh.edmode is null when processing a KEYBD
632 trap.
633 .sh.edtext
634 The characters in the input buffer at the time of the
635 most recent KEYBD trap. The value is null when not pro‐
636 cessing a KEYBD trap.
637 .sh.file
638 The pathname of the file than contains the current com‐
639 mand.
640 .sh.fun
641 The name of the current function that is being executed.
642 .sh.level
643 Set to the current function depth. This can be changed
644 inside a DEBUG trap and will set the context to the spec‐
645 ified level.
646 .sh.lineno
647 Set during a DEBUG trap to the line number for the caller
648 of each function.
649 .sh.match
650 An indexed array which stores the most recent match and
651 sub-pattern matches after conditional pattern matches
652 that match and after variables expansions using the oper‐
653 ators #, %, or /. The 0-th element stores the complete
654 match and the i-th. element stores the i-th submatch.
655 For // the array is two dimensional with the first sub‐
656 script indicating the most recent match and sub-pattern
657 match and the second script indicating which match with 0
658 representing the first match. The .sh.match variable
659 becomes unset when the variable that has expanded is
660 assigned a new value.
661 .sh.math
662 Used for defining arithmetic functions (see Arithmetic
663 evaluation below). and stores the list of user defined
664 arithmetic functions.
665 .sh.name
666 Set to the name of the variable at the time that a disci‐
667 pline function is invoked.
668 .sh.op_astbin
669 The directory where several shell built-in commands are
670 bound to. The default is /opt/ast/bin. When the value
671 is /bin, then builtins will be bound to /bin or /usr/bin
672 depending on where the executable is found. This vari‐
673 able can be set by including it in the SH_OPTIONS vari‐
674 able.
675 .sh.pgrp
676 The current process group of this shell.
677 .sh.pwdfd
678 The file descriptor number for the present working direc‐
679 tory.
680 .sh.sig
681 Set when executing a trap to the information contained in
682 the siginfo_t structure (See siginfo(2) for a description
683 of this structure.)
684 .sh.subscript
685 Set to the name subscript of the variable at the time
686 that a discipline function is invoked.
687 .sh.subshell
688 The current depth for subshells and command substitution.
689 .sh.value
690 Set to the value of the variable at the time that the set
691 or append discipline function is invoked. When a user
692 defined arithmetic function is invoked, the value of
693 .sh.value is saved and .sh.value is set to long double
694 precision floating point. .sh.value is restored when the
695 function returns.
696 .sh.version
697 Set to a value that identifies the version of this shell.
698 KSH_VERSION
699 A name reference to .sh.version.
700 LINENO The current line number within the script or function
701 being executed.
702 OLDPWD The previous working directory set by the cd command.
703 OPTARG The value of the last option argument processed by the
704 getopts built-in command.
705 OPTIND The index of the last option argument processed by the
706 getopts built-in command.
707 PPID The process number of the parent of the shell.
708 PWD The present working directory set by the cd command.
709 RANDOM Each time this variable is referenced, a random integer,
710 uniformly distributed between 0 and 32767, is generated.
711 The sequence of random numbers can be initialized by
712 assigning a numeric value to RANDOM.
713 REPLY This variable is set by the select statement and by the
714 read built-in command when no arguments are supplied.
715 SECONDS
716 Each time this variable is referenced, the number of sec‐
717 onds since shell invocation is returned. If this vari‐
718 able is assigned a value, then the value returned upon
719 reference will be the value that was assigned plus the
720 number of seconds since the assignment.
721 SHLVL An integer variable the is incremented each time the
722 shell is invoked and is exported. If SHLVL is not in the
723 environment when the shell is invoked, it is set to 1.
724
725 The following variables are used by the shell:
726 CDPATH The search path for the cd command.
727 COLUMNS
728 If this variable is set, the value is used to define the
729 width of the edit window for the shell edit modes and for
730 printing select lists.
731 EDITOR If the VISUAL variable is not set, the value of this
732 variable will be checked for the patterns as described
733 with VISUAL below and the corresponding editing option
734 (see Special Command set below) will be turned on.
735 ENV If this variable is set, then parameter expansion, com‐
736 mand substitution, and arithmetic substitution are per‐
737 formed on the value to generate the pathname of the
738 script that will be executed when the shell is invoked
739 interactively (see Invocation below). This file is typi‐
740 cally used for alias and function definitions. The
741 default value is $HOME/.kshrc. On systems that support a
742 system wide /etc/ksh.kshrc initialization file, if the
743 filename generated by the expansion of ENV begins with
744 /./ or ././ the system wide initialization file will not
745 be executed.
746 FCEDIT Obsolete name for the default editor name for the hist
747 command. FCEDIT is not used when HISTEDIT is set.
748 FIGNORE
749 A pattern that defines the set of filenames that will be
750 ignored when performing filename matching.
751 FPATH The search path for function definitions. The directo‐
752 ries in this path are searched for a file with the same
753 name as the function or command when a function with the
754 -u attribute is referenced and when a command is not
755 found. If an executable file with the name of that com‐
756 mand is found, then it is read and executed in the cur‐
757 rent environment. Unlike PATH, the current directory
758 must be represented explicitly by . rather than by adja‐
759 cent : characters or a beginning or ending :.
760 HISTCMD
761 Number of the current command in the history file.
762 HISTEDIT
763 Name for the default editor name for the hist command.
764 HISTFILE
765 If this variable is set when the shell is invoked, then
766 the value is the pathname of the file that will be used
767 to store the command history (see Command Re-entry
768 below).
769 HISTSIZE
770 If this variable is set when the shell is invoked, then
771 the number of previously entered commands that are acces‐
772 sible by this shell will be greater than or equal to this
773 number. The default is 512.
774 HOME The default argument (home directory) for the cd command.
775 IFS Internal field separators, normally space, tab, and new-
776 line that are used to separate the results of command
777 substitution or parameter expansion and to separate
778 fields with the built-in command read. The first charac‐
779 ter of the IFS variable is used to separate arguments for
780 the "$*" substitution (see Quoting below). Each single
781 occurrence of an IFS character in the string to be split,
782 that is not in the isspace character class, and any adja‐
783 cent characters in IFS that are in the isspace character
784 class, delimit a field. One or more characters in IFS
785 that belong to the isspace character class, delimit a
786 field. In addition, if the same isspace character
787 appears consecutively inside IFS, this character is
788 treated as if it were not in the isspace class, so that
789 if IFS consists of two tab characters, then two adjacent
790 tab characters delimit a null field.
791 JOBMAX This variable defines the maximum number running back‐
792 ground jobs that can run at a time. When this limit is
793 reached, the shell will wait for a job to complete before
794 staring a new job.
795 LANG This variable determines the locale category for any cat‐
796 egory not specifically selected with a variable starting
797 with LC_ or LANG.
798 LC_ALL This variable overrides the value of the LANG variable
799 and any other LC_ variable.
800 LC_COLLATE
801 This variable determines the locale category for charac‐
802 ter collation information.
803 LC_CTYPE
804 This variable determines the locale category for charac‐
805 ter handling functions. It determines the character
806 classes for pattern matching (see File Name Generation
807 below).
808 LC_NUMERIC
809 This variable determines the locale category for the dec‐
810 imal point character.
811 LINES If this variable is set, the value is used to determine
812 the column length for printing select lists. Select
813 lists will print vertically until about two-thirds of
814 LINES lines are filled.
815 MAIL If this variable is set to the name of a mail file and
816 the MAILPATH variable is not set, then the shell informs
817 the user of arrival of mail in the specified file.
818 MAILCHECK
819 This variable specifies how often (in seconds) the shell
820 will check for changes in the modification time of any of
821 the files specified by the MAILPATH or MAIL variables.
822 The default value is 600 seconds. When the time has
823 elapsed the shell will check before issuing the next
824 prompt.
825 MAILPATH
826 A colon ( : ) separated list of file names. If this
827 variable is set, then the shell informs the user of any
828 modifications to the specified files that have occurred
829 within the last MAILCHECK seconds. Each file name can be
830 followed by a ? and a message that will be printed. The
831 message will undergo parameter expansion, command substi‐
832 tution, and arithmetic substitution with the variable $_
833 defined as the name of the file that has changed. The
834 default message is you have mail in $_.
835 PATH The search path for commands (see Execution below). The
836 user may not change PATH if executing under rksh (except
837 in .profile).
838 PS1 The value of this variable is expanded for parameter
839 expansion, command substitution, and arithmetic substitu‐
840 tion to define the primary prompt string which by default
841 is ``$ ''. The character ! in the primary prompt string
842 is replaced by the command number (see Command Re-entry
843 below). Two successive occurrences of ! will produce a
844 single ! when the prompt string is printed.
845 PS2 Secondary prompt string, by default ``> ''.
846 PS3 Selection prompt string used within a select loop, by
847 default ``#? ''.
848 PS4 The value of this variable is expanded for parameter
849 evaluation, command substitution, and arithmetic substi‐
850 tution and precedes each line of an execution trace. By
851 default, PS4 is ``+ ''. In addition when PS4 is unset,
852 the execution trace prompt is also ``+ ''.
853 SH_OPTIONS
854 The value consists of blank separated name=value words.
855 For each name that is the name of a known option the
856 variable .sh.opt_name is assigned value. Currently the
857 only valid option name is astbin.
858 SHELL The pathname of the shell is kept in the environment. At
859 invocation, if the basename of this variable is rsh,
860 rksh, or krsh, then the shell becomes restricted. If it
861 is pfsh or pfksh, then the shell becomes a profile shell
862 (see pfexec(1)).
863 TIMEFORMAT
864 The value of this parameter is used as a format string
865 specifying how the timing information for pipelines pre‐
866 fixed with the time reserved word should be displayed.
867 The % character introduces a format sequence that is
868 expanded to a time value or other information. The for‐
869 mat sequences and their meanings are as follows.
870 %% A literal %.
871 %[p][l]R The elapsed time in seconds.
872 %[p][l]U The number of CPU seconds spent in user mode.
873 %[p][l]S The number of CPU seconds spent in system mode.
874 %P The CPU percentage, computed as (U + S) / R.
875
876 The brackets denote optional portions. The optional p is
877 a digit specifying the precision, the number of frac‐
878 tional digits after a decimal point. A value of 0 causes
879 no decimal point or fraction to be output. At most three
880 places after the decimal point can be displayed; values
881 of p greater than 3 are treated as 3. If p is not speci‐
882 fied, the value 3 is used.
883
884 The optional l specifies a longer format, including hours
885 if greater than zero, minutes, and seconds of the form
886 HHhMMmSS.FFs. The value of p determines whether or not
887 the fraction is included.
888
889 All other characters are output without change and a
890 trailing newline is added. If unset, the default value,
891 $'\nreal\t%2lR\nuser\t%2lU\nsys%2lS', is used. If the
892 value is null, no timing information is displayed.
893
894 TMOUT If set to a value greater than zero, TMOUT will be the
895 default timeout value for the read built-in command. The
896 select compound command terminates after TMOUT seconds
897 when input is from a terminal. Otherwise, the shell will
898 terminate if a line is not entered within the prescribed
899 number of seconds while reading from a terminal. (Note
900 that the shell can be compiled with a maximum bound for
901 this value which cannot be exceeded.)
902
903 VISUAL If the value of this variable matches the pattern
904 *[Vv][Ii]*, then the vi option (see Special Command set
905 below) is turned on. If the value matches the pattern
906 *gmacs* , the gmacs option is turned on. If the value
907 matches the pattern *macs*, then the emacs option will be
908 turned on. The value of VISUAL overrides the value of
909 EDITOR.
910
911 The shell gives default values to PATH, PS1, PS2, PS3, PS4, MAILCHECK,
912 FCEDIT, TMOUT and IFS, while HOME, SHELL, ENV, and MAIL are not set at
913 all by the shell (although HOME is set by login(1)). On some systems
914 MAIL and SHELL are also set by login(1).
915
916 Field Splitting.
917 After parameter expansion and command substitution, the results of sub‐
918 stitutions are scanned for the field separator characters (those found
919 in IFS) and split into distinct fields where such characters are found.
920 Explicit null fields ("" or ′′) are retained. Implicit null fields
921 (those resulting from parameters that have no values or command substi‐
922 tutions with no output) are removed.
923
924 If the braceexpand (-B) option is set then each of the fields resulting
925 from IFS are checked to see if they contain one or more of the brace
926 patterns {*,*}, {l1..l2} , {n1..n2} , {n1..n2% fmt} , {n1..n2 ..n3} ,
927 or {n1..n2 ..n3%fmt} , where * represents any character, l1,l2 are let‐
928 ters and n1,n2,n3 are signed numbers and fmt is a format specified as
929 used by printf. In each case, fields are created by prepending the
930 characters before the { and appending the characters after the } to
931 each of the strings generated by the characters between the { and }.
932 The resulting fields are checked to see if they have any brace pat‐
933 terns.
934
935 In the first form, a field is created for each string between { and ,,
936 between , and ,, and between , and }. The string represented by * can
937 contain embedded matching { and } without quoting. Otherwise, each {
938 and } with * must be quoted.
939
940 In the seconds form, l1 and l2 must both be either upper case or both
941 be lower case characters in the C locale. In this case a field is cre‐
942 ated for each character from l1 thru l2.
943
944 In the remaining forms, a field is created for each number starting at
945 n1 and continuing until it reaches n2 incrementing n1 by n3. The cases
946 where n3 is not specified behave as if n3 where 1 if n1<=n2 and -1 oth‐
947 erwise. If forms which specify %fmt any format flags, widths and pre‐
948 cisions can be specified and fmt can end in any of the specifiers
949 cdiouxX. For example, {a,z}{1..5..3%02d}{b..c}x expands to the 8
950 fields, a01bx, a01cx, a04bx, a04cx, z01bx, z01cx, z04bx and z4cx.
951
952 File Name Generation.
953 Following splitting, each field is scanned for the characters *, ?, (,
954 and [ unless the -f option has been set. If one of these characters
955 appears, then the word is regarded as a pattern. Each file name compo‐
956 nent that contains any pattern character is replaced with a lexico‐
957 graphically sorted set of names that matches the pattern from that
958 directory. If no file name is found that matches the pattern, then
959 that component of the filename is left unchanged unless the pattern is
960 prefixed with ∼(N) in which case it is removed as described below. If
961 FIGNORE is set, then each file name component that matches the pattern
962 defined by the value of FIGNORE is ignored when generating the matching
963 filenames. The names . and .. are also ignored. If FIGNORE is not
964 set, the character . at the start of each file name component will be
965 ignored unless the first character of the pattern corresponding to this
966 component is the character . itself. Note, that for other uses of
967 pattern matching the / and . are not treated specially.
968
969 * Matches any string, including the null string. When used
970 for filename expansion, if the globstar option is on, an
971 isolated pattern of two adjacent *'s will match all files
972 and zero or more directories and subdirectories. If fol‐
973 lowed by a / then only directories and subdirectories
974 will match.
975 ? Matches any single character.
976 [...] Matches any one of the enclosed characters. A pair of
977 characters separated by - matches any character lexically
978 between the pair, inclusive. If the first character fol‐
979 lowing the opening [ is a ! or ^ then any character not
980 enclosed is matched. A - can be included in the charac‐
981 ter set by putting it as the first or last character.
982 Within [ and ], character classes can be specified with
983 the syntax [:class:] where class is one of the following
984 classes defined in the ANSI-C standard: (Note that word
985 is equivalent to alnum plus the character _.)
986 alnum alpha blank cntrl digit graph lower print punct
987 space upper word xdigit
988 Within [ and ], an equivalence class can be specified
989 with the syntax [=c=] which matches all characters with
990 the same primary collation weight (as defined by the cur‐
991 rent locale) as the character c. Within [ and ], [.sym‐
992 bol.] matches the collating symbol symbol.
993 A pattern-list is a list of one or more patterns separated from each
994 other with a & or ⎪. A & signifies that all patterns must be matched
995 whereas ⎪ requires that only one pattern be matched. Composite pat‐
996 terns can be formed with one or more of the following sub-patterns:
997 ?(pattern-list)
998 Optionally matches any one of the given patterns.
999 *(pattern-list)
1000 Matches zero or more occurrences of the given patterns.
1001 +(pattern-list)
1002 Matches one or more occurrences of the given patterns.
1003 {n}(pattern-list)
1004 Matches n occurrences of the given patterns.
1005 {m,n}(pattern-list)
1006 Matches from m to n occurrences of the given patterns.
1007 If m is omitted, 0 will be used. If n is omitted at
1008 least m occurrences will be matched.
1009 @(pattern-list)
1010 Matches exactly one of the given patterns.
1011 !(pattern-list)
1012 Matches anything except one of the given patterns.
1013 By default, each pattern, or sub-pattern will match the longest string
1014 possible consistent with generating the longest overall match. If more
1015 than one match is possible, the one starting closest to the beginning
1016 of the string will be chosen. However, for each of the above compound
1017 patterns a - can be inserted in front of the ( to cause the shortest
1018 match to the specified pattern-list to be used.
1019
1020 When pattern-list is contained within parentheses, the backslash char‐
1021 acter \ is treated specially even when inside a character class. All
1022 ANSI-C character escapes are recognized and match the specified charac‐
1023 ter. In addition the following escape sequences are recognized:
1024 \d Matches any character in the digit class.
1025 \D Matches any character not in the digit class.
1026 \s Matches any character in the space class.
1027 \S Matches any character not in the space class.
1028 \w Matches any character in the word class.
1029 \W Matches any character not in the word class.
1030
1031 A pattern of the form %(pattern-pair(s)) is a sub-pattern that can be
1032 used to match nested character expressions. Each pattern-pair is a two
1033 character sequence which cannot contain & or ⎪. The first pattern-pair
1034 specifies the starting and ending characters for the match. Each sub‐
1035 sequent pattern-pair represents the beginning and ending characters of
1036 a nested group that will be skipped over when counting starting and
1037 ending character matches. The behavior is unspecified when the first
1038 character of a pattern-pair is alpha-numeric except for the following:
1039 D Causes the ending character to terminate the search for
1040 this pattern without finding a match.
1041 E Causes the ending character to be interpreted as an
1042 escape character.
1043 L Causes the ending character to be interpreted as a quote
1044 character causing all characters to be ignored when look‐
1045 ing for a match.
1046 Q Causes the ending character to be interpreted as a quote
1047 character causing all characters other than any escape
1048 character to be ignored when looking for a match.
1049 Thus, %({}Q"E\), matches characters starting at { until the matching }
1050 is found not counting any { or } that is inside a double quoted string
1051 or preceded by the escape character \. Without the {} this pattern
1052 matches any C language string.
1053
1054 Each sub-pattern in a composite pattern is numbered, starting at 1, by
1055 the location of the ( within the pattern. The sequence \n, where n is
1056 a single digit and \n comes after the n-th. sub-pattern, matches the
1057 same string as the sub-pattern itself.
1058
1059 Finally a pattern can contain sub-patterns of the form ∼(options:pat‐
1060 tern-list), where either options or :pattern-list can be omitted.
1061 Unlike the other compound patterns, these sub-patterns are not counted
1062 in the numbered sub-patterns. :pattern-list must be omitted for
1063 options F, G, N , and V below. If options is present, it can consist
1064 of one or more of the following:
1065 + Enable the following options. This is the default.
1066 - Disable the following options.
1067 E The remainder of the pattern uses extended regular
1068 expression syntax like the egrep(1) command.
1069 F The remainder of the pattern uses fgrep(1) expression
1070 syntax.
1071 G The remainder of the pattern uses basic regular expres‐
1072 sion syntax like the grep(1) command.
1073 K The remainder of the pattern uses shell pattern syntax.
1074 This is the default.
1075 N This is ignored. However, when it is the first letter
1076 and is used with file name generation, and no matches
1077 occur, the file pattern expands to the empty string.
1078 X The remainder of the pattern uses augmented regular
1079 expression syntax like the xgrep(1) command.
1080 P The remainder of the pattern uses perl(1) regular expres‐
1081 sion syntax. Not all perl regular expression syntax is
1082 currently implemented.
1083 V The remainder of the pattern uses System V regular
1084 expression syntax.
1085 i Treat the match as case insensitive.
1086 g File the longest match (greedy). This is the default.
1087 l Left anchor the pattern. This is the default for K style
1088 patterns.
1089 r Right anchor the pattern. This is the default for K
1090 style patterns.
1091 If both options and :pattern-list are specified, then the options apply
1092 only to pattern-list. Otherwise, these options remain in effect until
1093 they are disabled by a subsequent ∼(...) or at the end of the sub-pat‐
1094 tern containing ∼(...).
1095
1096 Quoting.
1097 Each of the metacharacters listed earlier (see Definitions above) has a
1098 special meaning to the shell and causes termination of a word unless
1099 quoted. A character may be quoted (i.e., made to stand for itself) by
1100 preceding it with a \. The pair \new-line is removed. All characters
1101 enclosed between a pair of single quote marks (′′) that is not preceded
1102 by a $ are quoted. A single quote cannot appear within the single
1103 quotes. A single quoted string preceded by an unquoted $ is processed
1104 as an ANSI-C string except for the following:
1105 \0 Causes the remainder of the string to be ignored.
1106 \E Equivalent to the escape character (ascii 033),
1107 \e Equivalent to the escape character (ascii 033),
1108 \cx Expands to the character control-x.
1109 \C[.name.]
1110 Expands to the collating element name.
1111
1112 Inside double quote marks (""), parameter and command substitution
1113 occur and \ quotes the characters \, `, ", and $. A $ in front of a
1114 double quoted string will be ignored in the "C" or "POSIX" locale, and
1115 may cause the string to be replaced by a locale specific string other‐
1116 wise. The meaning of $* and $@ is identical when not quoted or when
1117 used as a variable assignment value or as a file name. However, when
1118 used as a command argument, "$*" is equivalent to "$1d$2d...", where d
1119 is the first character of the IFS variable, whereas "$@" is equivalent
1120 to "$1" "$2" .... Inside grave quote marks (``), \ quotes the charac‐
1121 ters \, `, and $. If the grave quotes occur within double quotes, then
1122 \ also quotes the character ".
1123
1124 The special meaning of reserved words or aliases can be removed by
1125 quoting any character of the reserved word. The recognition of func‐
1126 tion names or built-in command names listed below cannot be altered by
1127 quoting them.
1128
1129 Arithmetic Evaluation.
1130 The shell performs arithmetic evaluation for arithmetic substitution,
1131 to evaluate an arithmetic command, to evaluate an indexed array sub‐
1132 script, and to evaluate arguments to the built-in commands shift and
1133 let. Evaluations are performed using double precision floating point
1134 arithmetic or long double precision floating point for systems that
1135 provide this data type. Floating point constants follow the ANSI-C
1136 programming language floating point conventions. The floating point
1137 constants Nan and Inf can be use to represent "not a number" and infin‐
1138 ity respectively. Integer constants follow the ANSI-C programming lan‐
1139 guage integer constant conventions although only single byte character
1140 constants are recognized and character casts are not recognized. In
1141 addition constants can be of the form [base#]n where base is a decimal
1142 number between two and sixty-four representing the arithmetic base and
1143 n is a number in that base. The digits above 9 are represented by the
1144 lower case letters, the upper case letters, @, and _ respectively. For
1145 bases less than or equal to 36, upper and lower case characters can be
1146 used interchangeably.
1147
1148 An arithmetic expression uses the same syntax, precedence, and associa‐
1149 tivity of expression as the C language. All the C language operators
1150 that apply to floating point quantities can be used. In addition, the
1151 operator ** can be used for exponentiation. It has higher precedence
1152 than multiplication and is left associative. In addition, when the
1153 value of an arithmetic variable or sub-expression can be represented as
1154 a long integer, all C language integer arithmetic operations can be
1155 performed. Variables can be referenced by name within an arithmetic
1156 expression without using the parameter expansion syntax. When a vari‐
1157 able is referenced, its value is evaluated as an arithmetic expression.
1158
1159 Any of the following math library functions that are in the C math
1160 library can be used within an arithmetic expression:
1161
1162 abs acos acosh asin asinh atan atan2 atanh cbrt ceil copysign cos cosh
1163 erf erfc exp exp2 expm1 fabs fpclassify fdim finite floor fma fmax fmin
1164 fmod hypot ilogb int isfinite sinf isnan isnormal issubnormal issubor‐
1165 dered iszero j0 j1 jn lgamma log log10 log2 logb nearbyint nextafter
1166 nexttoward pow remainder rint round scanb signbit sin sinh sqrt tan
1167 tanh tgamma trunc y0 y1 yn In addition, arithmetic functions can be
1168 defined as shell functions with a variant of the function name syntax,
1169
1170 function .sh.math.name ident ... { list ;}
1171 where name is the function name used in the arithmetic expres‐
1172 sion. If the calling argument corresponding to ident is the
1173 name of an array variable, then ident is a name reference to
1174 this array. Otherwise, ident is a reference to long double pre‐
1175 cision floating point variable containing the value from the
1176 caller. The value of .sh.value when the function returns is the
1177 value of this function. User defined functions can take up to 3
1178 arguments and override C math library functions.
1179
1180 An internal representation of a variable as a double precision floating
1181 point can be specified with the -E [n], -F [n], or -X [n] option of the
1182 typeset special built-in command. The -E option causes the expansion
1183 of the value to be represented using scientific notation when it is
1184 expanded. The optional option argument n defines the number of signif‐
1185 icant figures. The -F option causes the expansion to be represented as
1186 a floating decimal number when it is expanded. The -X option cause the
1187 expansion to be represented using the %a format defined by ISO C-99.
1188 The optional option argument n defines the number of places after the
1189 decimal (or radix) point in this case.
1190
1191 An internal integer representation of a variable can be specified with
1192 the -i [n] option of the typeset special built-in command. The
1193 optional option argument n specifies an arithmetic base to be used when
1194 expanding the variable. If you do not specify an arithmetic base, base
1195 10 will be used.
1196
1197 Arithmetic evaluation is performed on the value of each assignment to a
1198 variable with the -E, -F, -X, or -i attribute. Assigning a floating
1199 point number to a variable whose type is an integer causes the frac‐
1200 tional part to be truncated.
1201
1202 Inside an arithmetic expression, all integer and floating point vari‐
1203 ables can be following by .MIN, .MAX, or .DIG to give the maximum
1204 value, mininum value, or number of significant digits for variables of
1205 that type.
1206
1207 Floating point variables can be also followed by .INT_MAX or .INT_MIN
1208 to give the largest or smallest integers represented by that type.
1209
1210 Floating point variables can also be followed by .EPSILON to give the
1211 distance to the next floating point number of that type. Floating
1212 point variables can be followed by MAX_10_EXP to give the maximum base
1213 10 exponent that can be represented by that type.
1214
1215 Inside an arithmetic expression, the following constants are recong‐
1216 nized and are of type typeset-lE.
1217 NaN Not a number. It is case insensitive.
1218 Inf Infinity. It is case insensitive.
1219 E
1220 PI
1221 1_PI 1.0/PI.
1222 2_PI 2.0/PI.
1223 PI_2 PI/2.0
1224 PI_4 PI/4.0.
1225 SQRTPI sqrt(PI).
1226 SQRT2 sqrt(2.0).
1227 SQRT1_2
1228 sqrt(1./2.)
1229 LOGE log(E)
1230 LOG10E log10(E)
1231 LN2 log(2.0)
1232 LOG2E log2(E)
1233
1234 Array Sorting.
1235 The -s option of the set built-in command can be used to sort its argu‐
1236 ments or to sort indexed arrays, indexed arrays of compound variables,
1237 and indexed arrays of types (see "Type Variables" section below). By
1238 default the sort order is defined by the current locale. For compound
1239 variables and for types, the -K option for set can be followed by a
1240 comma separated list of sub-fields to sort on. Each field can be fol‐
1241 lowed by a : and the letter n for numerical sorting and/or r for
1242 reverse sorting. For an plain indexed array the -K option can be fol‐
1243 lowed by :n and :r for numerical or reverse sorting.
1244
1245 Prompting.
1246 When used interactively, the shell prompts with the value of PS1 after
1247 expanding it for parameter expansion, command substitution, and arith‐
1248 metic substitution, before reading a command. In addition, each single
1249 ! in the prompt is replaced by the command number. A !! is required
1250 to place ! in the prompt. If at any time a new-line is typed and fur‐
1251 ther input is needed to complete a command, then the secondary prompt
1252 (i.e., the value of PS2) is issued.
1253
1254 Conditional Expressions.
1255 A conditional expression is used with the [[ compound command to test
1256 attributes of files and to compare strings. Field splitting and file
1257 name generation are not performed on the words between [[ and ]]. Each
1258 expression can be constructed from one or more of the following unary
1259 or binary expressions:
1260 string True, if string is not null.
1261 -a file
1262 Same as -e below. This is obsolete.
1263 -b file
1264 True, if file exists and is a block special file.
1265 -c file
1266 True, if file exists and is a character special file.
1267 -d file
1268 True, if file exists and is a directory.
1269 -e file
1270 True, if file exists.
1271 -f file
1272 True, if file exists and is an ordinary file.
1273 -g file
1274 True, if file exists and it has its setgid bit set.
1275 -k file
1276 True, if file exists and it has its sticky bit set.
1277 -n string
1278 True, if length of string is non-zero.
1279 -o ?option
1280 True, if option named option is a valid option name.
1281 -o option
1282 True, if option named option is on.
1283 -p file
1284 True, if file exists and is a fifo special file or a pipe.
1285 -r file
1286 True, if file exists and is readable by current process.
1287 -s file
1288 True, if file exists and has size greater than zero.
1289 -t fildes
1290 True, if file descriptor number fildes is open and associated
1291 with a terminal device.
1292 -u file
1293 True, if file exists and it has its setuid bit set.
1294 -v name
1295 True, if variable name is a valid variable name and is set.
1296 -w file
1297 True, if file exists and is writable by current process.
1298 -x file
1299 True, if file exists and is executable by current process. If
1300 file exists and is a directory, then true if the current process
1301 has permission to search in the directory.
1302 -z string
1303 True, if length of string is zero.
1304 -L file
1305 True, if file exists and is a symbolic link.
1306 -h file
1307 True, if file exists and is a symbolic link.
1308 -N file
1309 True, if file exists and the modification time is greater than
1310 the last access time.
1311 -O file
1312 True, if file exists and is owned by the effective user id of
1313 this process.
1314 -G file
1315 True, if file exists and its group matches the effective group
1316 id of this process.
1317 -R name
1318 True if variable name is a name reference.
1319 -S file
1320 True, if file exists and is a socket.
1321 file1 -nt file2
1322 True, if file1 exists and file2 does not, or file1 is newer than
1323 file2.
1324 file1 -ot file2
1325 True, if file2 exists and file1 does not, or file1 is older than
1326 file2.
1327 file1 -ef file2
1328 True, if file1 and file2 exist and refer to the same file.
1329 string == pattern
1330 True, if string matches pattern. Any part of pattern can be
1331 quoted to cause it to be matched as a string. With a successful
1332 match to a pattern, the .sh.match array variable will contain
1333 the match and sub-pattern matches.
1334 string = pattern
1335 Same as == above, but is obsolete.
1336 string != pattern
1337 True, if string does not match pattern. When the string matches
1338 the pattern the .sh.match array variable will contain the match
1339 and sub-pattern matches.
1340 string =∼ ere
1341 True if string matches the pattern ∼(E)ere where ere is an
1342 extended regular expression.
1343 string1 < string2
1344 True, if string1 comes before string2 based on the current
1345 locale.
1346 string1 > string2
1347 True, if string1 comes after string2 based on the current
1348 locale.
1349 The following obsolete arithmetic comparisons are also permitted:
1350 exp1 -eq exp2
1351 True, if exp1 is equal to exp2.
1352 exp1 -ne exp2
1353 True, if exp1 is not equal to exp2.
1354 exp1 -lt exp2
1355 True, if exp1 is less than exp2.
1356 exp1 -gt exp2
1357 True, if exp1 is greater than exp2.
1358 exp1 -le exp2
1359 True, if exp1 is less than or equal to exp2.
1360 exp1 -ge exp2
1361 True, if exp1 is greater than or equal to exp2.
1362
1363 In each of the above expressions, if file is of the form /dev/fd/n,
1364 where n is an integer, then the test is applied to the open file whose
1365 descriptor number is n.
1366
1367 A compound expression can be constructed from these primitives by using
1368 any of the following, listed in decreasing order of precedence.
1369 (expression)
1370 True, if expression is true. Used to group expressions.
1371 ! expression
1372 True if expression is false.
1373 expression1 && expression2
1374 True, if expression1 and expression2 are both true.
1375 expression1 ⎪⎪ expression2
1376 True, if either expression1 or expression2 is true.
1377
1378 Input/Output.
1379 Before a command is executed, its input and output may be redirected
1380 using a special notation interpreted by the shell. The following may
1381 appear anywhere in a simple-command or may precede or follow a command
1382 and are not passed on to the invoked command. Command substitution,
1383 parameter expansion, and arithmetic substitution occur before word or
1384 digit is used except as noted below. File name generation occurs only
1385 if the shell is interactive and the pattern matches a single file.
1386 Field splitting is not performed.
1387
1388 In each of the following redirections, if file is of the form
1389 /dev/sctp/host/port, /dev/tcp/host/port, or /dev/udp/host/port, where
1390 host is a hostname or host address, and port is a service given by name
1391 or an integer port number, then the redirection attempts to make a tcp,
1392 sctp or udp connection to the corresponding socket.
1393
1394 No intervening space is allowed between the characters of redirection
1395 operators.
1396
1397 <word Use file word as standard input (file descriptor 0).
1398
1399 >word Use file word as standard output (file descriptor 1). If
1400 the file does not exist then it is created. If the file
1401 exists, and the noclobber option is on, this causes an
1402 error; otherwise, it is truncated to zero length.
1403
1404 >|word Same as >, except that it overrides the noclobber option.
1405
1406 >;word Write output to a temporary file. If the command com‐
1407 pletes successfully rename it to word, otherwise, delete
1408 the temporary file. >;word cannot be used with the
1409 exec(2). built-in.
1410
1411 >>word Use file word as standard output. If the file exists,
1412 then output is appended to it (by first seeking to the
1413 end-of-file); otherwise, the file is created.
1414
1415 <>word Open file word for reading and writing as standard input.
1416
1417 <>;word The same as <>word except that if the command completes
1418 successfully, word is truncated to the offset at command
1419 completion. <>;word cannot be used with the exec(2).
1420 built-in.
1421
1422 <<[-]word The shell input is read up to a line that is the same as
1423 word after any quoting has been removed, or to an end-of-
1424 file. No parameter substitution, command substitution,
1425 arithmetic substitution or file name generation is per‐
1426 formed on word. The resulting document, called a here-
1427 document, becomes the standard input. If any character
1428 of word is quoted, then no interpretation is placed upon
1429 the characters of the document; otherwise, parameter
1430 expansion, command substitution, and arithmetic substitu‐
1431 tion occur, \new-line is ignored, and \ must be used to
1432 quote the characters \, $, `. If - is appended to <<,
1433 then all leading tabs are stripped from word and from the
1434 document. If # is appended to <<, then leading spaces
1435 and tabs will be stripped off the first line of the docu‐
1436 ment and up to an equivalent indentation will be stripped
1437 from the remaining lines and from word. A tab stop is
1438 assumed to occur at every 8 columns for the purposes of
1439 determining the indentation.
1440
1441 <<<word A short form of here document in which word becomes the
1442 contents of the here-document after any parameter expan‐
1443 sion, command substitution, and arithmetic substitution
1444 occur.
1445
1446 <&digit The standard input is duplicated from file descriptor
1447 digit (see dup(2)). Similarly for the standard output
1448 using >&digit.
1449
1450 <&digit- The file descriptor given by digit is moved to standard
1451 input. Similarly for the standard output using >&digit-.
1452
1453 <&- The standard input is closed. Similarly for the standard
1454 output using >&-.
1455
1456 <&p The input from the co-process is moved to standard input.
1457
1458 >&p The output to the co-process is moved to standard output.
1459
1460 <#((expr)) Evaluate arithmetic expression expr and position file
1461 descriptor 0 to the resulting value bytes from the start
1462 of the file. The variables CUR and EOF evaluate to the
1463 current offset and end-of-file offset respectively when
1464 evaluating expr.
1465
1466 >#((offset)) The same as <# except applies to file descriptor 1.
1467
1468 <#pattern Seeks forward to the beginning of the next line contain‐
1469 ing pattern.
1470
1471 <##pattern The same as <# except that the portion of the file that
1472 is skipped is copied to standard output.
1473
1474 If one of the above is preceded by a digit, with no intervening space,
1475 then the file descriptor number referred to is that specified by the
1476 digit (instead of the default 0 or 1). If one of the above, other than
1477 >&- and the ># and <# forms, is preceded by {varname} with no interven‐
1478 ing space, then a file descriptor number > 10 will be selected by the
1479 shell and stored in the variable varname. If >&- or the any of the >#
1480 and <# forms is preceded by {varname} the value of varname defines the
1481 file descriptor to close or position. For example:
1482
1483 ... 2>&1
1484
1485 means file descriptor 2 is to be opened for writing as a duplicate of
1486 file descriptor 1 and
1487
1488 exec {n}<file
1489
1490 means open file named file for reading and store the file descriptor
1491 number in variable n.
1492
1493 The order in which redirections are specified is significant. The
1494 shell evaluates each redirection in terms of the (file descriptor,
1495 file) association at the time of evaluation. For example:
1496
1497 ... 1>fname 2>&1
1498
1499 first associates file descriptor 1 with file fname. It then associates
1500 file descriptor 2 with the file associated with file descriptor 1 (i.e.
1501 fname). If the order of redirections were reversed, file descriptor 2
1502 would be associated with the terminal (assuming file descriptor 1 had
1503 been) and then file descriptor 1 would be associated with file fname.
1504
1505 If a command is followed by & and job control is not active, then the
1506 default standard input for the command is the empty file /dev/null.
1507 Otherwise, the environment for the execution of a command contains the
1508 file descriptors of the invoking shell as modified by input/output
1509 specifications.
1510
1511 Environment.
1512 The environment (see environ(7)) is a list of name-value pairs that is
1513 passed to an executed program in the same way as a normal argument
1514 list. The names must be identifiers and the values are character
1515 strings. The shell interacts with the environment in several ways. On
1516 invocation, the shell scans the environment and creates a variable for
1517 each name found, giving it the corresponding value and attributes and
1518 marking it export. Executed commands inherit the environment. If the
1519 user modifies the values of these variables or creates new ones, using
1520 the export or typeset -x commands, they become part of the environment.
1521 The environment seen by any executed command is thus composed of any
1522 name-value pairs originally inherited by the shell, whose values may be
1523 modified by the current shell, plus any additions which must be noted
1524 in export or typeset -x commands.
1525
1526 The environment for any simple-command or function may be augmented by
1527 prefixing it with one or more variable assignments. A variable assign‐
1528 ment argument is a word of the form identifier=value. Thus:
1529
1530 TERM=450 cmd args and
1531 (export TERM; TERM=450; cmd args)
1532
1533 are equivalent (as far as the above execution of cmd is concerned
1534 except for special built-in commands listed below - those that are pre‐
1535 ceded with a dagger).
1536
1537 If the obsolete -k option is set, all variable assignment arguments are
1538 placed in the environment, even if they occur after the command name.
1539 The following first prints a=b c and then c:
1540
1541 echo a=b c
1542 set -k
1543 echo a=b c
1544 This feature is intended for use with scripts written for early ver‐
1545 sions of the shell and its use in new scripts is strongly discouraged.
1546 It is likely to disappear someday.
1547
1548 Functions.
1549 For historical reasons, there are two ways to define functions, the
1550 name() syntax and the function name syntax, described in the Commands
1551 section above. Shell functions are read in and stored internally.
1552 Alias names are resolved when the function is read. Functions are exe‐
1553 cuted like commands with the arguments passed as positional parameters.
1554 (See Execution below.)
1555
1556 Functions defined by the function name syntax and called by name exe‐
1557 cute in the same process as the caller and share all files and present
1558 working directory with the caller. Traps caught by the caller are
1559 reset to their default action inside the function. A trap condition
1560 that is not caught or ignored by the function causes the function to
1561 terminate and the condition to be passed on to the caller. A trap on
1562 EXIT set inside a function is executed in the environment of the caller
1563 after the function completes. Ordinarily, variables are shared between
1564 the calling program and the function. However, the typeset special
1565 built-in command used within a function defines local variables whose
1566 scope includes the current function. They can be passed to functions
1567 that they call in the variable assignment list that precedes the call
1568 or as arguments passed as name references. Errors within functions
1569 return control to the caller.
1570
1571 Functions defined with the name() syntax and functions defined with the
1572 function name syntax that are invoked with the . special built-in are
1573 executed in the caller's environment and share all variables and traps
1574 with the caller. Errors within these function executions cause the
1575 script that contains them to abort.
1576
1577 The special built-in command return is used to return from function
1578 calls.
1579
1580 Function names can be listed with the -f or +f option of the typeset
1581 special built-in command. The text of functions, when available, will
1582 also be listed with -f. Functions can be undefined with the -f option
1583 of the unset special built-in command.
1584
1585 Ordinarily, functions are unset when the shell executes a shell script.
1586 Functions that need to be defined across separate invocations of the
1587 shell should be placed in a directory and the FPATH variable should
1588 contain the name of this directory. They may also be specified in the
1589 ENV file.
1590
1591 Discipline Functions.
1592 Each variable can have zero or more discipline functions associated
1593 with it. The shell initially understands the discipline names get,
1594 set, append, and unset but can be added when defining new types. On
1595 most systems others can be added at run time via the C programming
1596 interface extension provided by the builtin built-in utility. If the
1597 get discipline is defined for a variable, it is invoked whenever the
1598 given variable is referenced. If the variable .sh.value is assigned a
1599 value inside the discipline function, the referenced variable will
1600 evaluate to this value instead. If the set discipline is defined for a
1601 variable, it is invoked whenever the given variable is assigned a
1602 value. If the append discipline is defined for a variable, it is
1603 invoked whenever a value is appended to the given variable. The vari‐
1604 able .sh.value is given the value of the variable before invoking the
1605 discipline, and the variable will be assigned the value of .sh.value
1606 after the discipline completes. If .sh.value is unset inside the dis‐
1607 cipline, then that value is unchanged. If the unset discipline is
1608 defined for a variable, it is invoked whenever the given variable is
1609 unset. The variable will not be unset unless it is unset explicitly
1610 from within this discipline function.
1611
1612 The variable .sh.name contains the name of the variable for which the
1613 discipline function is called, .sh.subscript is the subscript of the
1614 variable, and .sh.value will contain the value being assigned inside
1615 the set discipline function. The variable _ is a reference to the
1616 variable including the subscript if any. For the set discipline,
1617 changing .sh.value will change the value that gets assigned. Finally,
1618 the expansion ${var.name}, when name is the name of a discipline, and
1619 there is no variable of this name, is equivalent to the command substi‐
1620 tution ${ var.name;}.
1621
1622
1623 Name Spaces.
1624 Commands and functions that are executed as part of the list of a
1625 namespace command that modify variables or create new ones, create a
1626 new variable whose name is the name of the name space as given by iden‐
1627 tifier preceded by .. When a variable whose name is name is refer‐
1628 enced, it is first searched for using .identifier.name. Similarly, a
1629 function defined by a command in the namespace list is created using
1630 the name space name preceded by a ..
1631
1632 When the list of a namespace command contains a namespace command, the
1633 names of variables and functions that are created consist of the vari‐
1634 able or function name preceded by the list of identifiers each preceded
1635 by ..
1636
1637 Outside of a name space, a variable or function created inside a name
1638 space can be referenced by preceding it with the name space name.
1639
1640 By default, variables staring with .sh are in the sh name space.
1641
1642
1643 Type Variables.
1644 Typed variables provide a way to create data structure and objects. A
1645 type can be defined either by a shared library, by the enum built-in
1646 command described below, or by using the new -T option of the typeset
1647 built-in command. With the -T option of typeset, the type name, speci‐
1648 fied as an option argument to -T, is set with a compound variable
1649 assignment that defines the type. Function definitions can appear
1650 inside the compound variable assignment and these become discipline
1651 functions for this type and can be invoked or redefined by each
1652 instance of the type. The function name create is treated specially.
1653 It is invoked for each instance of the type that is created but is not
1654 inherited and cannot be redefined for each instance.
1655
1656 When a type is defined a special built-in command of that name is
1657 added. These built-ins are declaration commands and follow the same
1658 expansion rules as all the special built-in commands defined below that
1659 are preceded by ††. These commands can subsequently be used inside
1660 further type definitions. The man page for these commands can be gen‐
1661 erated by using the --man option or any of the other -- options
1662 described with getopts. The -r, -a, -A, -h, and -S options of typeset
1663 are permitted with each of these new built-ins.
1664
1665 An instance of a type is created by invoking the type name followed by
1666 one or more instance names. Each instance of the type is initialized
1667 with a copy of the sub-variables except for sub-variables that are
1668 defined with the -S option. Variables defined with the -S are shared
1669 by all instances of the type. Each instance can change the value of
1670 any sub-variable and can also define new discipline functions of the
1671 same names as those defined by the type definition as well as any stan‐
1672 dard discipline names. No additional sub-variables can be defined for
1673 any instance.
1674
1675 When defining a type, if the value of a sub-variable is not set and the
1676 -r attribute is specified, it causes the sub-variable to be a required
1677 sub-variable. Whenever an instance of a type is created, all required
1678 sub-variables must be specified. These sub-variables become readonly
1679 in each instance.
1680
1681 When unset is invoked on a sub-variable within a type, and the -r
1682 attribute has not been specified for this field, the value is reset to
1683 the default value associative with the type. Invoking unset on a type
1684 instance not contained within another type deletes all sub-variables
1685 and the variable itself.
1686
1687 A type definition can be derived from another type definition by defin‐
1688 ing the first sub-variable name as _ and defining its type as the base
1689 type. Any remaining definitions will be additions and modifications
1690 that apply to the new type. If the new type name is the same as that
1691 of the base type, the type will be replaced and the original type will
1692 no longer be accessible.
1693
1694 The typeset command with the -T and no option argument or operands will
1695 write all the type definitions to standard output in a form that can be
1696 read in to create all the types.
1697
1698 Jobs.
1699 If the monitor option of the set command is turned on, an interactive
1700 shell associates a job with each pipeline. It keeps a table of current
1701 jobs, printed by the jobs command, and assigns them small integer num‐
1702 bers. When a job is started asynchronously with &, the shell prints a
1703 line which looks like:
1704
1705 [1] 1234
1706
1707 indicating that the job which was started asynchronously was job number
1708 1 and had one (top-level) process, whose process id was 1234.
1709
1710 This paragraph and the next require features that are not in all ver‐
1711 sions of UNIX and may not apply. If you are running a job and wish to
1712 do something else you may hit the key ^Z (control-Z) which sends a STOP
1713 signal to the current job. The shell will then normally indicate that
1714 the job has been `Stopped', and print another prompt. You can then
1715 manipulate the state of this job, putting it in the background with the
1716 bg command, or run some other commands and then eventually bring the
1717 job back into the foreground with the foreground command fg. A ^Z
1718 takes effect immediately and is like an interrupt in that pending out‐
1719 put and unread input are discarded when it is typed.
1720
1721 A job being run in the background will stop if it tries to read from
1722 the terminal. Background jobs are normally allowed to produce output,
1723 but this can be disabled by giving the command stty tostop. If you set
1724 this tty option, then background jobs will stop when they try to pro‐
1725 duce output like they do when they try to read input.
1726
1727 A job pool is a collection of jobs started with list & associated with
1728 a name.
1729
1730 There are several ways to refer to jobs in the shell. A job can be
1731 referred to by the process id of any process of the job or by one of
1732 the following:
1733 %number
1734 The job with the given number.
1735 pool All the jobs in the job pool named by pool.
1736 pool.number
1737 The job number number in the job pool named by pool.
1738 %string
1739 Any job whose command line begins with string.
1740 %?string
1741 Any job whose command line contains string.
1742 %% Current job.
1743 %+ Equivalent to %%.
1744 %- Previous job. In addition, unless noted otherwise, wherever a
1745 job can be specified, the name of a background job pool can be
1746 used to represent all the jobs in that pool.
1747
1748 The shell learns immediately whenever a process changes state. It nor‐
1749 mally informs you whenever a job becomes blocked so that no further
1750 progress is possible, but only just before it prints a prompt. This is
1751 done so that it does not otherwise disturb your work. The notify
1752 option of the set command causes the shell to print these job change
1753 messages as soon as they occur.
1754
1755 When the monitor option is on, each background job that completes trig‐
1756 gers any trap set for CHLD.
1757
1758 When you try to leave the shell while jobs are running or stopped, you
1759 will be warned that `You have stopped(running) jobs.' You may use the
1760 jobs command to see what they are. If you immediately try to exit
1761 again, the shell will not warn you a second time, and the stopped jobs
1762 will be terminated. When a login shell receives a HUP signal, it sends
1763 a HUP signal to each job that has not been disowned with the disown
1764 built-in command described below.
1765
1766 Signals.
1767 The INT and QUIT signals for an invoked command are ignored if the com‐
1768 mand is followed by & and the monitor option is active. Otherwise,
1769 signals have the values inherited by the shell from its parent (but see
1770 also the trap built-in command below).
1771
1772 Execution.
1773 Each time a command is read, the above substitutions are carried out.
1774 If the command name matches one of the Special Built-in Commands listed
1775 below, it is executed within the current shell process. Next, the com‐
1776 mand name is checked to see if it matches a user defined function. If
1777 it does, the positional parameters are saved and then reset to the
1778 arguments of the function call. A function is also executed in the
1779 current shell process. When the function completes or issues a return,
1780 the positional parameter list is restored. For functions defined with
1781 the function name syntax, any trap set on EXIT within the function is
1782 executed. The exit value of a function is the value of the last com‐
1783 mand executed. If a command name is not a special built-in command or
1784 a user defined function, but it is one of the built-in commands listed
1785 below, it is executed in the current shell process.
1786
1787 The shell variables PATH followed by the variable FPATH defines the
1788 list of directories to search for the command name. Alternative direc‐
1789 tory names are separated by a colon (:). The default path is equal to
1790 getconf PATH output. The current directory can be specified by two or
1791 more adjacent colons, or by a colon at the beginning or end of the path
1792 list. If the command name contains a /, then the search path is not
1793 used. Otherwise, each directory in the list of directories defined by
1794 PATH and FPATH is checked in order. If the directory being searched is
1795 contained in FPATH and contains a file whose name matches the command
1796 being searched, then this file is loaded into the current shell envi‐
1797 ronment as if it were the argument to the . command except that only
1798 preset aliases are expanded, and a function of the given name is exe‐
1799 cuted as described above.
1800
1801 If this directory is not in FPATH the shell first determines whether
1802 there is a built-in version of a command corresponding to a given path‐
1803 name and if so it is invoked in the current process. If no built-in is
1804 found, the shell checks for a file named .paths in this directory. If
1805 found and there is a line of the form FPATH=path where path names an
1806 existing directory then that directory is searched immediately after
1807 the current directory as if it were found in the FPATH variable. If
1808 path does not begin with /, it is checked for relative to the directory
1809 being searched.
1810
1811 The .paths file is then checked for a line of the form PLUGIN_LIB=lib‐
1812 name [ : libname ] ... . Each library named by libname will be
1813 searched for as if it were an option argument to builtin -f, and if it
1814 contains a built-in of the specified name this will be executed instead
1815 of a command by this name. Any built-in loaded from a library found
1816 this way will be associated with the directory containing the .paths
1817 file so it will only execute if not found in an earlier directory.
1818
1819 Finally, the directory will be checked for a file of the given name.
1820 If the file has execute permission but is not an a.out file, it is
1821 assumed to be a file containing shell commands. A separate shell is
1822 spawned to read it. All non-exported variables are removed in this
1823 case. If the shell command file doesn't have read permission, or if
1824 the setuid and/or setgid bits are set on the file, then the shell exe‐
1825 cutes an agent whose job it is to set up the permissions and execute
1826 the shell with the shell command file passed down as an open file. If
1827 the .paths contains a line of the form name=value in the first or sec‐
1828 ond line, then the environment variable name is modified by prepending
1829 the directory specified by value to the directory list. If value is
1830 not an absolute directory, then it specifies a directory relative to
1831 the directory that the executable was found. If the environment vari‐
1832 able name does not already exist it will be added to the environment
1833 list for the specified command. A parenthesized command is executed in
1834 a sub-shell without removing non-exported variables.
1835
1836 Command Re-entry.
1837 The text of the last HISTSIZE (default 512) commands entered from a
1838 terminal device is saved in a history file. The file $HOME/.sh_history
1839 is used if the HISTFILE variable is not set or if the file it names is
1840 not writable. A shell can access the commands of all interactive
1841 shells which use the same named HISTFILE. The built-in command hist is
1842 used to list or edit a portion of this file. The portion of the file
1843 to be edited or listed can be selected by number or by giving the first
1844 character or characters of the command. A single command or range of
1845 commands can be specified. If you do not specify an editor program as
1846 an argument to hist then the value of the variable HISTEDIT is used.
1847 If HISTEDIT is unset, the obsolete variable FCEDIT is used. If FCEDIT
1848 is not defined, then /bin/ed is used. The edited command(s) is printed
1849 and re-executed upon leaving the editor unless you quit without writ‐
1850 ing. The -s option (and in obsolete versions, the editor name -) is
1851 used to skip the editing phase and to re-execute the command. In this
1852 case a substitution parameter of the form old=new can be used to modify
1853 the command before execution. For example, with the preset alias r,
1854 which is aliased to ′hist -s′, typing `r bad=good c' will re-execute
1855 the most recent command which starts with the letter c, replacing the
1856 first occurrence of the string bad with the string good.
1857
1858 In-line Editing Options.
1859 Normally, each command line entered from a terminal device is simply
1860 typed followed by a new-line (`RETURN' or `LINE FEED'). If either the
1861 emacs, gmacs, or vi option is active, the user can edit the command
1862 line. To be in either of these edit modes set the corresponding
1863 option. An editing option is automatically selected each time the VIS‐
1864 UAL or EDITOR variable is assigned a value ending in either of these
1865 option names.
1866
1867 The editing features require that the user's terminal accept `RETURN'
1868 as carriage return without line feed and that a space (` ') must over‐
1869 write the current character on the screen.
1870
1871 Unless the multiline option is on, the editing modes implement a con‐
1872 cept where the user is looking through a window at the current line.
1873 The window width is the value of COLUMNS if it is defined, otherwise
1874 80. If the window width is too small to display the prompt and leave
1875 at least 8 columns to enter input, the prompt is truncated from the
1876 left. If the line is longer than the window width minus two, a mark is
1877 displayed at the end of the window to notify the user. As the cursor
1878 moves and reaches the window boundaries the window will be centered
1879 about the cursor. The mark is a > (<, *) if the line extends on the
1880 right (left, both) side(s) of the window.
1881
1882 The search commands in each edit mode provide access to the history
1883 file. Only strings are matched, not patterns, although a leading ^ in
1884 the string restricts the match to begin at the first character in the
1885 line.
1886
1887 Each of the edit modes has an operation to list the files or commands
1888 that match a partially entered word. When applied to the first word on
1889 the line, or the first word after a ;, ⎪, &, or (, and the word does
1890 not begin with ∼ or contain a /, the list of aliases, functions, and
1891 executable commands defined by the PATH variable that could match the
1892 partial word is displayed. Otherwise, the list of files that match the
1893 given word is displayed. If the partially entered word does not con‐
1894 tain any file expansion characters, a * is appended before generating
1895 these lists. After displaying the generated list, the input line is
1896 redrawn. These operations are called command name listing and file
1897 name listing, respectively. There are additional operations, referred
1898 to as command name completion and file name completion, which compute
1899 the list of matching commands or files, but instead of printing the
1900 list, replace the current word with a complete or partial match. For
1901 file name completion, if the match is unique, a / is appended if the
1902 file is a directory and a space is appended if the file is not a direc‐
1903 tory. Otherwise, the longest common prefix for all the matching files
1904 replaces the word. For command name completion, only the portion of
1905 the file names after the last / are used to find the longest command
1906 prefix. If only a single name matches this prefix, then the word is
1907 replaced with the command name followed by a space. When using a tab
1908 for completion that does not yield a unique match, a subsequent tab
1909 will provide a numbered list of matching alternatives. A specific
1910 selection can be made by entering the selection number followed by a
1911 tab.
1912
1913 Key Bindings.
1914 The KEYBD trap can be used to intercept keys as they are typed and
1915 change the characters that are actually seen by the shell. This trap
1916 is executed after each character (or sequence of characters when the
1917 first character is ESC) is entered while reading from a terminal. The
1918 variable .sh.edchar contains the character or character sequence which
1919 generated the trap. Changing the value of .sh.edchar in the trap
1920 action causes the shell to behave as if the new value were entered from
1921 the keyboard rather than the original value.
1922
1923 The variable .sh.edcol is set to the input column number of the cursor
1924 at the time of the input. The variable .sh.edmode is set to ESC when
1925 in vi insert mode (see below) and is null otherwise. By prepending
1926 ${.sh.editmode} to a value assigned to .sh.edchar it will cause the
1927 shell to change to control mode if it is not already in this mode.
1928
1929 This trap is not invoked for characters entered as arguments to editing
1930 directives, or while reading input for a character search.
1931
1932 Emacs Editing Mode.
1933 This mode is entered by enabling either the emacs or gmacs option. The
1934 only difference between these two modes is the way they handle ^T. To
1935 edit, the user moves the cursor to the point needing correction and
1936 then inserts or deletes characters or words as needed. All the editing
1937 commands are control characters or escape sequences. The notation for
1938 control characters is caret (^) followed by the character. For exam‐
1939 ple, ^F is the notation for control F. This is entered by depressing
1940 `f' while holding down the `CTRL' (control) key. The `SHIFT' key is
1941 not depressed. (The notation ^? indicates the DEL (delete) key.)
1942
1943 The notation for escape sequences is M- followed by a character. For
1944 example, M-f (pronounced Meta f) is entered by depressing ESC (ascii
1945 033) followed by `f'. (M-F would be the notation for ESC followed by
1946 `SHIFT' (capital) `F'.)
1947
1948 All edit commands operate from any place on the line (not just at the
1949 beginning). Neither the `RETURN' nor the `LINE FEED' key is entered
1950 after edit commands except when noted.
1951
1952 ^F Move cursor forward (right) one character.
1953 M-[C Move cursor forward (right) one character.
1954 M-f Move cursor forward one word. (The emacs editor's idea of a
1955 word is a string of characters consisting of only letters,
1956 digits and underscores.)
1957 ^B Move cursor backward (left) one character.
1958 M-[D Move cursor backward (left) one character.
1959 M-b Move cursor backward one word.
1960 ^A Move cursor to start of line.
1961 M-[H Move cursor to start of line.
1962 ^E Move cursor to end of line.
1963 M-[Y Move cursor to end of line.
1964 ^]char Move cursor forward to character char on current line.
1965 M-^]char Move cursor backward to character char on current line.
1966 ^X^X Interchange the cursor and mark.
1967 erase (User defined erase character as defined by the stty(1) com‐
1968 mand, usually ^H or #.) Delete previous character.
1969 lnext (User defined literal next character as defined by the
1970 stty(1) command, or ^V if not defined.) Removes the next
1971 character's editing features (if any).
1972 ^D Delete current character.
1973 M-d Delete current word.
1974 M-^H (Meta-backspace) Delete previous word.
1975 M-h Delete previous word.
1976 M-^? (Meta-DEL) Delete previous word (if your interrupt character
1977 is ^? (DEL, the default) then this command will not work).
1978 ^T Transpose current character with previous character and
1979 advance the cursor in emacs mode. Transpose two previous
1980 characters in gmacs mode.
1981 ^C Capitalize current character.
1982 M-c Capitalize current word.
1983 M-l Change the current word to lower case.
1984 ^K Delete from the cursor to the end of the line. If preceded
1985 by a numerical parameter whose value is less than the current
1986 cursor position, then delete from given position up to the
1987 cursor. If preceded by a numerical parameter whose value is
1988 greater than the current cursor position, then delete from
1989 cursor up to given cursor position.
1990 ^W Kill from the cursor to the mark.
1991 M-p Push the region from the cursor to the mark on the stack.
1992 kill (User defined kill character as defined by the stty command,
1993 usually ^G or @.) Kill the entire current line. If two kill
1994 characters are entered in succession, all kill characters
1995 from then on cause a line feed (useful when using paper ter‐
1996 minals).
1997 ^Y Restore last item removed from line. (Yank item back to the
1998 line.)
1999 ^L Line feed and print current line.
2000 M-^L Clear the screen.
2001 ^@ (Null character) Set mark.
2002 M-space (Meta space) Set mark.
2003 ^J (New line) Execute the current line.
2004 ^M (Return) Execute the current line.
2005 eof End-of-file character, normally ^D, is processed as an End-
2006 of-file only if the current line is null.
2007 ^P Fetch previous command. Each time ^P is entered the previous
2008 command back in time is accessed. Moves back one line when
2009 not on the first line of a multi-line command.
2010 M-[A If the cursor is at the end of the line, it is equivalent to
2011 ^R with string set to the contents of the current line. Oth‐
2012 erwise, it is equivalent to ^P.
2013 M-< Fetch the least recent (oldest) history line.
2014 M-> Fetch the most recent (youngest) history line.
2015 ^N Fetch next command line. Each time ^N is entered the next
2016 command line forward in time is accessed.
2017 M-[B Equivalent to ^N.
2018 ^Rstring Reverse search history for a previous command line containing
2019 string. If a parameter of zero is given, the search is for‐
2020 ward. String is terminated by a `RETURN' or `NEW LINE'. If
2021 string is preceded by a ^, the matched line must begin with
2022 string. If string is omitted, then the next command line
2023 containing the most recent string is accessed. In this case
2024 a parameter of zero reverses the direction of the search.
2025 ^O Operate - Execute the current line and fetch the next line
2026 relative to current line from the history file.
2027 M-digits (Escape) Define numeric parameter, the digits are taken as a
2028 parameter to the next command. The commands that accept a
2029 parameter are ^F, ^B, erase, ^C, ^D, ^K, ^R, ^P, ^N, ^], M-.,
2030 M-^], M-_, M-=, M-b, M-c, M-d, M-f, M-h, M-l and M-^H.
2031 M-letter Soft-key - Your alias list is searched for an alias by the
2032 name _letter and if an alias of this name is defined, its
2033 value will be inserted on the input queue. The letter must
2034 not be one of the above meta-functions.
2035 M-[letter Soft-key - Your alias list is searched for an alias by the
2036 name __letter and if an alias of this name is defined, its
2037 value will be inserted on the input queue. This can be used
2038 to program function keys on many terminals.
2039 M-. The last word of the previous command is inserted on the
2040 line. If preceded by a numeric parameter, the value of this
2041 parameter determines which word to insert rather than the
2042 last word.
2043 M-_ Same as M-..
2044 M-* Attempt file name generation on the current word. An aster‐
2045 isk is appended if the word doesn't match any file or contain
2046 any special pattern characters.
2047 M-ESC Command or file name completion as described above.
2048 ^I tab Attempts command or file name completion as described above.
2049 If a partial completion occurs, repeating this will behave as
2050 if M-= were entered. If no match is found or entered after
2051 space, a tab is inserted.
2052 M-= If not preceded by a numeric parameter, it generates the list
2053 of matching commands or file names as described above. Oth‐
2054 erwise, the word under the cursor is replaced by the item
2055 corresponding to the value of the numeric parameter from the
2056 most recently generated command or file list. If the cursor
2057 is not on a word, it is inserted instead.
2058 ^U Multiply parameter of next command by 4.
2059 \ Escape next character. Editing characters, the user's erase,
2060 kill and interrupt (normally ^?) characters may be entered
2061 in a command line or in a search string if preceded by a \.
2062 The \ removes the next character's editing features (if any).
2063 M-^V Display version of the shell.
2064 M-# If the line does not begin with a #, a # is inserted at the
2065 beginning of the line and after each new-line, and the line
2066 is entered. This causes a comment to be inserted in the his‐
2067 tory file. If the line begins with a #, the # is deleted and
2068 one # after each new-line is also deleted.
2069
2070 Vi Editing Mode.
2071 There are two typing modes. Initially, when you enter a command you
2072 are in the input mode. To edit, the user enters control mode by typing
2073 ESC (033) and moves the cursor to the point needing correction and then
2074 inserts or deletes characters or words as needed. Most control com‐
2075 mands accept an optional repeat count prior to the command.
2076
2077 When in vi mode on most systems, canonical processing is initially
2078 enabled and the command will be echoed again if the speed is 1200 baud
2079 or greater and it contains any control characters or less than one sec‐
2080 ond has elapsed since the prompt was printed. The ESC character termi‐
2081 nates canonical processing for the remainder of the command and the
2082 user can then modify the command line. This scheme has the advantages
2083 of canonical processing with the type-ahead echoing of raw mode.
2084
2085 If the option viraw is also set, the terminal will always have canoni‐
2086 cal processing disabled. This mode is implicit for systems that do not
2087 support two alternate end of line delimiters, and may be helpful for
2088 certain terminals.
2089
2090 Input Edit Commands
2091 By default the editor is in input mode.
2092 erase (User defined erase character as defined by the stty
2093 command, usually ^H or #.) Delete previous character.
2094 ^W Delete the previous blank separated word.
2095 eof As the first character of the line causes the shell to
2096 terminate unless the ignoreeof option is set. Other‐
2097 wise this character is ignored.
2098 lnext (User defined literal next character as defined by the
2099 stty(1) or ^V if not defined.) Removes the next char‐
2100 acter's editing features (if any).
2101 \ Escape the next erase or kill character.
2102 ^I tab Attempts command or file name completion as described
2103 above and returns to input mode. If a partial comple‐
2104 tion occurs, repeating this will behave as if = were
2105 entered from control mode. If no match is found or
2106 entered after space, a tab is inserted.
2107 Motion Edit Commands
2108 These commands will move the cursor.
2109 [count]l Cursor forward (right) one character.
2110 [count][C Cursor forward (right) one character.
2111 [count]w Cursor forward one alpha-numeric word.
2112 [count]W Cursor to the beginning of the next word that follows
2113 a blank.
2114 [count]e Cursor to end of word.
2115 [count]E Cursor to end of the current blank delimited word.
2116 [count]h Cursor backward (left) one character.
2117 [count][D Cursor backward (left) one character.
2118 [count]b Cursor backward one word.
2119 [count]B Cursor to preceding blank separated word.
2120 [count]⎪ Cursor to column count.
2121 [count]fc Find the next character c in the current line.
2122 [count]Fc Find the previous character c in the current line.
2123 [count]tc Equivalent to f followed by h.
2124 [count]Tc Equivalent to F followed by l.
2125 [count]; Repeats count times, the last single character find
2126 command, f, F, t, or T.
2127 [count], Reverses the last single character find command count
2128 times.
2129 0 Cursor to start of line.
2130 ^ Cursor to start of line.
2131 [H Cursor to first non-blank character in line.
2132 $ Cursor to end of line.
2133 [Y Cursor to end of line.
2134 % Moves to balancing (, ), {, }, [, or ]. If cursor is
2135 not on one of the above characters, the remainder of
2136 the line is searched for the first occurrence of one
2137 of the above characters first.
2138 Search Edit Commands
2139 These commands access your command history.
2140 [count]k Fetch previous command. Each time k is entered the
2141 previous command back in time is accessed.
2142 [count]- Equivalent to k.
2143 [count][A If cursor is at the end of the line it is equivalent
2144 to / with string^set to the contents of the current
2145 line. Otherwise, it is equivalent to k.
2146 [count]j Fetch next command. Each time j is entered the next
2147 command forward in time is accessed.
2148 [count]+ Equivalent to j.
2149 [count][B Equivalent to j.
2150 [count]G The command number count is fetched. The default is
2151 the least recent history command.
2152 /string Search backward through history for a previous command
2153 containing string. String is terminated by a `RETURN'
2154 or `NEW LINE'. If string is preceded by a ^, the
2155 matched line must begin with string. If string is
2156 null, the previous string will be used.
2157 ?string Same as / except that search will be in the forward
2158 direction.
2159 n Search for next match of the last pattern to / or ?
2160 commands.
2161 N Search for next match of the last pattern to / or ?,
2162 but in reverse direction.
2163 Text Modification Edit Commands
2164 These commands will modify the line.
2165 a Enter input mode and enter text after the current
2166 character.
2167 A Append text to the end of the line. Equivalent to $a.
2168 [count]cmotion
2169 c[count]motion
2170 Delete current character through the character that
2171 motion would move the cursor to and enter input mode.
2172 If motion is c, the entire line will be deleted and
2173 input mode entered.
2174 C Delete the current character through the end of line
2175 and enter input mode. Equivalent to c$.
2176 S Equivalent to cc.
2177 [count]s Replace characters under the cursor in input mode.
2178 D Delete the current character through the end of line.
2179 Equivalent to d$.
2180 [count]dmotion
2181 d[count]motion
2182 Delete current character through the character that
2183 motion would move to. If motion is d , the entire
2184 line will be deleted.
2185 i Enter input mode and insert text before the current
2186 character.
2187 I Insert text before the beginning of the line. Equiva‐
2188 lent to 0i.
2189 [count]P Place the previous text modification before the cur‐
2190 sor.
2191 [count]p Place the previous text modification after the cursor.
2192 R Enter input mode and replace characters on the screen
2193 with characters you type overlay fashion.
2194 [count]rc Replace the count character(s) starting at the current
2195 cursor position with c, and advance the cursor.
2196 [count]x Delete current character.
2197 [count]X Delete preceding character.
2198 [count]. Repeat the previous text modification command.
2199 [count]∼ Invert the case of the count character(s) starting at
2200 the current cursor position and advance the cursor.
2201 [count]_ Causes the count word of the previous command to be
2202 appended and input mode entered. The last word is
2203 used if count is omitted.
2204 * Causes an * to be appended to the current word and
2205 file name generation attempted. If no match is found,
2206 it rings the bell. Otherwise, the word is replaced by
2207 the matching pattern and input mode is entered.
2208 \ Command or file name completion as described above.
2209 Other Edit Commands
2210 Miscellaneous commands.
2211 [count]ymotion
2212 y[count]motion
2213 Yank current character through character that motion
2214 would move the cursor to and puts them into the delete
2215 buffer. The text and cursor are unchanged.
2216 yy Yanks the entire line.
2217 Y Yanks from current position to end of line. Equiva‐
2218 lent to y$.
2219 u Undo the last text modifying command.
2220 U Undo all the text modifying commands performed on the
2221 line.
2222 [count]v Returns the command hist -e ${VISUAL:-${EDITOR:-vi}}
2223 count in the input buffer. If count is omitted, then
2224 the current line is used.
2225 ^L Line feed and print current line. Has effect only in
2226 control mode.
2227 ^J (New line) Execute the current line, regardless of
2228 mode.
2229 ^M (Return) Execute the current line, regardless of mode.
2230 # If the first character of the command is a #, then
2231 this command deletes this # and each # that follows a
2232 newline. Otherwise, sends the line after inserting a
2233 # in front of each line in the command. Useful for
2234 causing the current line to be inserted in the history
2235 as a comment and uncommenting previously commented
2236 commands in the history file.
2237 [count]= If count is not specified, it generates the list of
2238 matching commands or file names as described above.
2239 Otherwise, the word under the cursor is replaced by
2240 the count item from the most recently generated com‐
2241 mand or file list. If the cursor is not on a word, it
2242 is inserted instead.
2243 @letter Your alias list is searched for an alias by the name
2244 _letter and if an alias of this name is defined, its
2245 value will be inserted on the input queue for process‐
2246 ing.
2247 ^V Display version of the shell.
2248
2249 Programmable Completion.
2250 By default, hitting the tab key causes the current word to be matched
2251 against files starting with the characters you typed and adding as many
2252 characters that provide a unique match. If the matching prefix is not
2253 unique hitting tab again will output a numbered list with the choices
2254 and entering number tab will replace the current word with that selec‐
2255 tion.
2256
2257 Programmable completion allows you to control how words are expanded
2258 when you enter the tab key for one or more specified commands. The
2259 complete built-in command allows you to specify how to complete the
2260 current word of the specified command.
2261
2262 Built-in Commands.
2263 The following simple-commands are executed in the shell process.
2264 Input/Output redirection is permitted. Unless otherwise indicated, the
2265 output is written on file descriptor 1 and the exit status, when there
2266 is no syntax error, is zero. Except for :, true, false, echo, newgrp,
2267 and login, all built-in commands accept -- to indicate end of options.
2268 They also interpret the option --man as a request to display the man
2269 page onto standard error and -? as a help request which prints a usage
2270 message on standard error. Commands that are preceded by one or two †
2271 symbols are special built-in commands and are treated specially in the
2272 following ways:
2273 1. Variable assignment lists preceding the command remain in effect
2274 when the command completes.
2275 2. I/O redirections are processed after variable assignments.
2276 3. Errors cause a script that contains them to abort.
2277 4. They are not valid function names.
2278 5. Words following a command preceded by †† that are in the format
2279 of a variable assignment are expanded with the same rules as a
2280 variable assignment. This means that tilde substitution is per‐
2281 formed after the = sign and field splitting and file name gener‐
2282 ation are not performed. These are called declaration built-
2283 ins.
2284
2285 † : [ arg ... ]
2286 The command only expands parameters.
2287
2288 † . name [ arg ... ]
2289 If name is a function defined with the function name reserved
2290 word syntax, the function is executed in the current environment
2291 (as if it had been defined with the name() syntax.) Otherwise
2292 if name refers to a file, the file is read in its entirety and
2293 the commands are executed in the current shell environment. The
2294 search path specified by PATH is used to find the directory con‐
2295 taining the file. If any arguments arg are given, they become
2296 the positional parameters while processing the . command and
2297 the original positional parameters are restored upon completion.
2298 Otherwise the positional parameters are unchanged. The exit
2299 status is the exit status of the last command executed.
2300
2301 †† alias [ -ptx ] [ name[ =value ] ] ...
2302 alias with no arguments prints the list of aliases in the form
2303 name=value on standard output. The -p option causes the word
2304 alias to be inserted before each one. When one or more argu‐
2305 ments are given, an alias is defined for each name whose value
2306 is given. A trailing space in value causes the next word to be
2307 checked for alias substitution. The obsolete -t option is used
2308 to set and list tracked aliases. The value of a tracked alias
2309 is the full pathname corresponding to the given name. The value
2310 becomes undefined when the value of PATH is reset but the alias
2311 remains tracked. Without the -t option, for each name in the
2312 argument list for which no value is given, the name and value of
2313 the alias is printed. The obsolete -x option has no effect.
2314 The exit status is non-zero if a name is given, but no value,
2315 and no alias has been defined for the name.
2316
2317 bg [ job... ]
2318 This command is only on systems that support job control. Puts
2319 each specified job into the background. The current job is put
2320 in the background if job is not specified. See Jobs for a
2321 description of the format of job.
2322
2323 † break [ n ]
2324 Exit from the enclosing for, while, until, or select loop, if
2325 any. If n is specified, then break n levels.
2326
2327 builtin [ -dsp ] [ -f file ] [ name ... ]
2328 If name is not specified, and no -f option is specified, the
2329 built-ins are printed on standard output. The -s option prints
2330 only the special built-ins. Otherwise, each name represents the
2331 pathname whose basename is the name of the built-in. The entry
2332 point function name is determined by prepending b_ to the built-
2333 in name. A built-in specified by a pathname will only be exe‐
2334 cuted when that pathname would be found during the path search.
2335 Built-ins found in libraries loaded via the .paths file will be
2336 associate with the pathname of the directory containing the
2337 .paths file.
2338 The ISO C/C++ prototype is b_mycommand(int argc, char *argv[],
2339 void *context) for the builtin command mycommand where argv is
2340 array an of argc elements and context is an optional pointer to
2341 a Shell_t structure as described in <ast/shell.h>.
2342 Special built-ins cannot be bound to a pathname or deleted. The
2343 -d option deletes each of the given built-ins. On systems that
2344 support dynamic loading, the -f option names a shared library
2345 containing the code for built-ins. The shared library prefix
2346 and/or suffix, which depend on the system, can be omitted. Once
2347 a library is loaded, its symbols become available for subsequent
2348 invocations of builtin. Multiple libraries can be specified
2349 with separate invocations of the builtin command. Libraries are
2350 searched in the reverse order in which they are specified. When
2351 a library is loaded, it looks for a function in the library
2352 whose name is lib_init() and invokes this function with an argu‐
2353 ment of 0.
2354 The -p causes the output to be in a form of builtin commands
2355 that can be used as input to the shell to recreate the current
2356 set of builtins.
2357
2358 cd [ -LP ] [ arg ]
2359 cd [ -LP ] old new
2360 This command can be in either of two forms. In the first form
2361 it changes the current directory to arg. If arg is - the direc‐
2362 tory is changed to the previous directory. The shell variable
2363 HOME is the default arg. The variable PWD is set to the current
2364 directory. The shell variable CDPATH defines the search path
2365 for the directory containing arg. Alternative directory names
2366 are separated by a colon (:). The default path is <null> (spec‐
2367 ifying the current directory). Note that the current directory
2368 is specified by a null path name, which can appear immediately
2369 after the equal sign or between the colon delimiters anywhere
2370 else in the path list. If arg begins with a / then the search
2371 path is not used. Otherwise, each directory in the path is
2372 searched for arg.
2373 The second form of cd substitutes the string new for the string
2374 old in the current directory name, PWD, and tries to change to
2375 this new directory.
2376 By default, symbolic link names are treated literally when find‐
2377 ing the directory name. This is equivalent to the -L option.
2378 The -P option causes symbolic links to be resolved when deter‐
2379 mining the directory. The last instance of -L or -P on the com‐
2380 mand line determines which method is used.
2381 The cd command may not be executed by rksh.
2382
2383 command [ -pvxV ] name [ arg ... ]
2384 Without the -v or -V options, command executes name with the
2385 arguments given by arg. The -p option causes a default path to
2386 be searched rather than the one defined by the value of PATH.
2387 Functions will not be searched for when finding name. In addi‐
2388 tion, if name refers to a special built-in, none of the special
2389 properties associated with the leading daggers will be honored.
2390 (For example, the predefined alias redirect=′command exec′ pre‐
2391 vents a script from terminating when an invalid redirection is
2392 given.) With the -x option, if command execution would result
2393 in a failure because there are too many arguments, errno E2BIG,
2394 the shell will invoke command name multiple times with a subset
2395 of the arguments on each invocation. Arguments that occur prior
2396 to the first word that expands to multiple arguments and after
2397 the last word that expands to multiple arguments will be passed
2398 on each invocation. The exit status will be the maximum invoca‐
2399 tion exit status. With the -v option, command is equivalent to
2400 the built-in whence command described below. The -V option
2401 causes command to act like whence -v.
2402
2403 † continue [ n ]
2404 Resume the next iteration of the enclosing for, while, until, or
2405 select loop. If n is specified, then resume at the n-th enclos‐
2406 ing loop.
2407
2408 disown [ job... ]
2409 Causes the shell not to send a HUP signal to each given job, or
2410 all active jobs if job is omitted, when a login shell termi‐
2411 nates.
2412
2413 echo [ -n -e ] [ arg ... ]
2414 echo builtin prints all of its arguments separated by space and
2415 terminated by new-line. -n will skip putting a newline charac‐
2416 ter at the end of output. If -e is set, it will enable inter‐
2417 preting escape sequences.
2418
2419
2420 †† enum [ -i ] type[=(value ...) ]
2421 Creates a declaration command named type that is an integer type
2422 that allows one of the specified values as enumeration names.
2423 If =(value ...) is omitted, then type must be an indexed array
2424 variable with at least two elements and the values are taken
2425 from this array variable. If -i is specified the values are
2426 case insensitive.
2427 When an enumeration variable is used in arithmetic expression,
2428 its value is the index into the array that defined it starting
2429 from index 0. Enumeration strings can be used in an arithmetic
2430 expression when comparing against an enumeration variable.
2431 Also, each non-subscripted enumeration variable followed by
2432 .name where name is one of the enumeration names expands to the
2433 index corresponding to name.
2434 The enum _Bool is created with values true and false. The pre‐
2435 defined alias bool is defined as _Bool.
2436
2437 † eval [ arg ... ]
2438 The arguments are read as input to the shell and the resulting
2439 command(s) executed.
2440
2441 † exec [ -c ] [ -a name ] [ arg ... ]
2442 If arg is given, the command specified by the arguments is exe‐
2443 cuted in place of this shell without creating a new process.
2444 The -c option causes the environment to be cleared before apply‐
2445 ing variable assignments associated with the exec invocation.
2446 The -a option causes name rather than the first arg, to become
2447 argv[0] for the new process. Input/output arguments may appear
2448 and affect the current process. If arg is not given, the effect
2449 of this command is to modify file descriptors as prescribed by
2450 the input/output redirection list. In this case, any file
2451 descriptor numbers greater than 2 that are opened with this
2452 mechanism are closed when invoking another program.
2453
2454 † exit [ n ]
2455 Causes the shell to exit with the exit status specified by n.
2456 The value will be the least significant 8 bits of the specified
2457 status. If n is omitted, then the exit status is that of the
2458 last command executed. An end-of-file will also cause the shell
2459 to exit except for a shell which has the ignoreeof option (see
2460 set below) turned on.
2461
2462 †† export [ -p ] [ name[=value] ] ...
2463 If name is not given, the names and values of each variable with
2464 the export attribute are printed with the values quoted in a
2465 manner that allows them to be re-input. The export command is
2466 the same as typeset -x except that if you use export within a
2467 function, no local variable is created. The -p option causes
2468 the word export to be inserted before each one. Otherwise, the
2469 given names are marked for automatic export to the environment
2470 of subsequently-executed commands.
2471
2472 false Does nothing, and exits 1. Used with until for infinite loops.
2473
2474 fg [ job... ]
2475 This command is only on systems that support job control. Each
2476 job specified is brought to the foreground and waited for in the
2477 specified order. Otherwise, the current job is brought into the
2478 foreground. See Jobs for a description of the format of job.
2479
2480 getopts [ -a name ] optstring vname [ arg ... ]
2481 Checks arg for legal options. If arg is omitted, the positional
2482 parameters are used. An option argument begins with a + or a -.
2483 An option not beginning with + or - or the argument -- ends the
2484 options. Options beginning with + are only recognized when opt‐
2485 string begins with a +. optstring contains the letters that
2486 getopts recognizes. If a letter is followed by a :, that option
2487 is expected to have an argument. The options can be separated
2488 from the argument by blanks. The option -? causes getopts to
2489 generate a usage message on standard error. The -a argument can
2490 be used to specify the name to use for the usage message, which
2491 defaults to $0.
2492 getopts places the next option letter it finds inside variable
2493 vname each time it is invoked. The option letter will be
2494 prepended with a + when arg begins with a +. The index of the
2495 next arg is stored in OPTIND. The option argument, if any, gets
2496 stored in OPTARG.
2497 A leading : in optstring causes getopts to store the letter of
2498 an invalid option in OPTARG, and to set vname to ? for an
2499 unknown option and to : when a required option argument is miss‐
2500 ing. Otherwise, getopts prints an error message. The exit sta‐
2501 tus is non-zero when there are no more options.
2502 There is no way to specify any of the options :, +, -, ?, [, and
2503 ]. The option # can only be specified as the first option.
2504
2505 hist [ -e ename ] [ -nlr ] [ first [ last ] ]
2506 hist -s [ old=new ] [ command ]
2507 In the first form, a range of commands from first to last is
2508 selected from the last HISTSIZE commands that were typed at the
2509 terminal. The arguments first and last may be specified as a
2510 number or as a string. A string is used to locate the most
2511 recent command starting with the given string. A negative num‐
2512 ber is used as an offset to the current command number. If the
2513 -l option is selected, the commands are listed on standard out‐
2514 put. Otherwise, the editor program ename is invoked on a file
2515 containing these keyboard commands. If ename is not supplied,
2516 then the value of the variable HISTEDIT is used. If HISTEDIT is
2517 not set, then FCEDIT (default /bin/ed) is used as the editor.
2518 When editing is complete, the edited command(s) is executed if
2519 the changes have been saved. If last is not specified, then it
2520 will be set to first. If first is not specified, the default is
2521 the previous command for editing and -16 for listing. The
2522 option -r reverses the order of the commands and the option -n
2523 suppresses command numbers when listing. In the second form,
2524 command is interpreted as first described above and defaults to
2525 the last command executed. The resulting command is executed
2526 after the optional substitution old=new is performed.
2527
2528 jobs [ -lnp ] [ job ... ]
2529 Lists information about each given job; or all active jobs if
2530 job is omitted. The -l option lists process ids in addition to
2531 the normal information. The -n option only displays jobs that
2532 have stopped or exited since last notified. The -p option
2533 causes only the process group to be listed. See Jobs for a
2534 description of the format of job.
2535
2536 kill [ -s signame ] [ -q n ] job ...
2537 kill [ -n signum ] [ -q n ] job ...
2538 kill -Ll [ sig ... ]
2539 Sends either the TERM (terminate) signal or the specified signal
2540 to the specified jobs or processes. Signals are either given by
2541 number with the -n option or by name with the -s option (as
2542 given in <signal.h>, stripped of the prefix ``SIG'' with the
2543 exception that SIGCLD is named CHLD). For backward compatibil‐
2544 ity, the n and s can be omitted and the number or name placed
2545 immediately after the -. If the signal being sent is TERM (ter‐
2546 minate) or HUP (hangup), then the job or process will be sent a
2547 CONT (continue) signal if it is stopped. The argument job can
2548 be the process id of a process that is not a member of one of
2549 the active jobs. See Jobs for a description of the format of
2550 job. In the third form, kill -l, or kill -L, if sig is not
2551 specified, the signal names are listed. The -l option list only
2552 the signal names. -L options lists each signal name and corre‐
2553 sponding number. Otherwise, for each sig that is a name, the
2554 corresponding signal number is listed. For each sig that is a
2555 number, the signal name corresponding to the least significant 8
2556 bits of sig is listed.
2557 On systems that support sigqueue(2) the -q option can be used to
2558 send a queued signal with message number n. Each specified job
2559 must be a positive number. On systems that do not support
2560 sigqueue(2), a signal is sent without the message number n and
2561 the signal will not be queued. If the signal cannot be queued
2562 because of a return of EAGAIN, the exit status will be 2.
2563
2564 let arg ...
2565 Each arg is a separate arithmetic expression to be evaluated.
2566 let only recognizes octal constants starting with 0 when the set
2567 option letoctal is on. See Arithmetic Evaluation above, for a
2568 description of arithmetic expression evaluation.
2569 The exit status is 0 if the value of the last expression is non-
2570 zero, and 1 otherwise.
2571
2572 † newgrp [ arg ... ]
2573 Equivalent to exec /bin/newgrp arg ....
2574
2575 print [ -CRenprsv ] [ -u unit] [ -f format ] [ arg ... ]
2576 With no options or with option - or --, each arg is printed on
2577 standard output. The -f option causes the arguments to be
2578 printed as described by printf. In this case, any e, n, r, R
2579 options are ignored. Otherwise, unless the -C, -R, -r, or -v
2580 are specified, the following escape conventions will be applied:
2581 \a The alert character (ascii 07).
2582 \b The backspace character (ascii 010).
2583 \c Causes print to end without processing more arguments and
2584 not adding a new-line.
2585 \f The formfeed character (ascii 014).
2586 \n The new-line character (ascii 012).
2587 \r The carriage return character (ascii 015).
2588 \t The tab character (ascii 011).
2589 \v The vertical tab character (ascii 013).
2590 \E The escape character (ascii 033).
2591 \\ The backslash character \.
2592 \0x The character defined by the 1, 2, or 3-digit octal
2593 string given by x.
2594
2595 The -R option will print all subsequent arguments and options
2596 other than -n. The -e causes the above escape conventions to be
2597 applied. This is the default behavior. It reverses the effect
2598 of an earlier -r. The -p option causes the arguments to be
2599 written onto the pipe of the process spawned with ⎪& instead of
2600 standard output. The -v option treats each arg as a variable
2601 name and writes the value in the printf %B format. The -C
2602 option treats each arg as a variable name and writes the value
2603 in the printf %#B format. The -s option causes the arguments to
2604 be written onto the history file instead of standard output.
2605 The -u option can be used to specify a one digit file descriptor
2606 unit number unit on which the output will be placed. The
2607 default is 1. If the option -n is used, no new-line is added to
2608 the output.
2609
2610 printf [ -v varname ] format [ arg ... ]
2611 The arguments arg are printed on standard output in accordance
2612 with the ANSI-C formatting rules associated with the format
2613 string format. If the number of arguments exceeds the number of
2614 format specifications, the format string is reused to format
2615 remaining arguments. If the -v option is specified the output
2616 is assigned to the variable varname. The following extensions
2617 can also be used:
2618 %b A %b format can be used instead of %s to cause escape
2619 sequences in the corresponding arg to be expanded as
2620 described in print.
2621 %B A %B option causes each of the arguments to be treated as
2622 variable names and the binary value of variable will be
2623 printed. The alternate flag # causes a compound variable
2624 to be output on a single line. This is most useful for
2625 compound variables and variables whose attribute is -b.
2626 %H A %H format can be used instead of %s to cause characters
2627 in arg that are special in HTML and XML to be output as
2628 their entity name. The alternate flag # formats the out‐
2629 put for use as a URI.
2630 %P A %P format can be used instead of %s to cause arg to be
2631 interpreted as an extended regular expression and be
2632 printed as a shell pattern.
2633 %R A %R format can be used instead of %s to cause arg to be
2634 interpreted as a shell pattern and to be printed as an
2635 extended regular expression.
2636 %q A %q format can be used instead of %s to cause the
2637 resulting string to be quoted in a manner than can be
2638 reinput to the shell. When q is preceded by the alterna‐
2639 tive format specifier, #, the string is quoted in manner
2640 suitable as a field in a .csv format file.
2641 %(date-format)T
2642 A %(date-format)T format can be use to treat an argument
2643 as a date/time string and to format the date/time accord‐
2644 ing to the date-format as defined for the date(1) com‐
2645 mand. Values specified as digits are interpreted as
2646 described in the touch(1) command.
2647 %Z A %Z format will output a byte whose value is 0.
2648 %d The precision field of the %d format can be followed by a
2649 . and the output base. In this case, the # flag charac‐
2650 ter causes base# to be prepended.
2651 # The # flag, when used with the %d format without an out‐
2652 put base, displays the output in powers of 1000 indicated
2653 by one of the following suffixes: k M G T P E, and when
2654 used with the %i format displays the output in powers of
2655 1024 indicated by one of the following suffixes: Ki Mi Gi
2656 Ti Pi Ei.
2657 = The = flag centers the output within the specified field
2658 width.
2659 L The L flag, when used with the %c or %s formats, treats
2660 precision as character width instead of byte count.
2661 , The , flag, when used with the %d or %f formats, sepa‐
2662 rates groups of digits with the grouping delimiter (, on
2663 groups of 3 in the C locale.)
2664
2665 pwd [ -LP ] [ -f fd ]
2666 Outputs the value of the current working directory. The -L
2667 option is the default; it prints the logical name of the current
2668 directory. If the -P option is given, all symbolic links are
2669 resolved from the name. The last instance of -L or -P on the
2670 command line determines which method is used. If the -f option
2671 is specified, the directory name corresponding to file descrip‐
2672 tor fd is outputted.
2673
2674 read [ -AaCSprsv ] [ -d delim] [ -n n] [ -N n] [ -m method] [ -t time‐
2675 out] [ -u unit] [ vname?prompt ] [ vname ... ]
2676 The shell input mechanism. One line is read and is broken up
2677 into fields using the characters in IFS as separators. The
2678 escape character, \, is used to remove any special meaning for
2679 the next character and for line continuation. The -d option
2680 causes the read to continue to the first character of delim
2681 rather than new-line. The -n option causes at most n bytes to
2682 read rather a full line but will return when reading from a slow
2683 device as soon as any characters have been read. The -N option
2684 causes exactly n to be read unless an end-of-file has been
2685 encountered or the read times out because of the -t option. In
2686 raw mode, -r, the \ character is not treated specially. The
2687 first field is assigned to the first vname, the second field to
2688 the second vname, etc., with leftover fields assigned to the
2689 last vname. When vname has the binary attribute and -n or -N is
2690 specified, the bytes that are read are stored directly into the
2691 variable. If the -v is specified, then the value of the first
2692 vname will be used as a default value when reading from a termi‐
2693 nal device. The -A option causes the variable vname to be unset
2694 and each field that is read to be stored in successive elements
2695 of the indexed array vname. -a is an alias for -A. The -m
2696 option reads a compound variable with the read method defined by
2697 method. Currently, only the json and ksh methods exist. The -C
2698 option causes the variable vname to be read as a compound vari‐
2699 able. Blanks will be ignored when finding the beginning open
2700 parenthesis. This is equivalent to -m ksh. The -S option
2701 causes the line to be treated like a record in a .csv format
2702 file so that double quotes can be used to allow the delimiter
2703 character and the new-line character to appear within a field.
2704 The -p option causes the input line to be taken from the input
2705 pipe of a process spawned by the shell using ⎪&. If the -s
2706 option is present, the input will be saved as a command in the
2707 history file. The option -u can be used to specify a one digit
2708 file descriptor unit unit to read from. The file descriptor can
2709 be opened with the exec special built-in command. The default
2710 value of unit n is 0. The option -t is used to specify a time‐
2711 out in seconds when reading from a terminal or pipe. If vname
2712 is omitted, then REPLY is used as the default vname. An end-of-
2713 file with the -p option causes cleanup for this process so that
2714 another can be spawned. If the first argument contains a ?, the
2715 remainder of this word is used as a prompt on standard error
2716 when the shell is interactive. The exit status is 0 unless an
2717 end-of-file is encountered or read has timed out.
2718
2719 †† readonly [ -p ] [ vname[=value] ] ...
2720 If vname is not given, the names and values of each variable
2721 with the readonly attribute is printed with the values quoted in
2722 a manner that allows them to be re-inputted. The -p option
2723 causes the word readonly to be inserted before each one. Other‐
2724 wise, the given vnames are marked readonly and these names can‐
2725 not be changed by subsequent assignment. When defining a type,
2726 if the value of a readonly sub-variable is not defined the value
2727 is required when creating each instance.
2728
2729 † return [ n ]
2730 Causes a shell function or . script to return to the invoking
2731 script with the exit status specified by n. The value will be
2732 the least significant 8 bits of the specified status. If n is
2733 omitted, then the return status is that of the last command exe‐
2734 cuted. If return is invoked while not in a function or a .
2735 script, then it behaves the same as exit.
2736
2737 † set [ ±BCGabefhkmnoprstuvx ] [ ±o [ option ] ] ... [ ±A vname ] [ -K
2738 keylist ] [ arg ... ]
2739 The options for this command have meaning as follows:
2740 -A Array assignment. If arg is specified, unset the vari‐
2741 able vname and assign values sequentially from the arg
2742 list. If +A is used, the variable vname is not unset
2743 first.
2744 -B Enable brace group expansion. On by default.
2745 -C Prevents redirection > from truncating existing files.
2746 Files that are created are opened with the O_EXCL mode.
2747 Requires >⎪ to truncate a file when turned on.
2748 -G Causes the pattern ** by itself to match files and zero
2749 or more directories and sub-directories when used for
2750 file name generation. If followed by a / only directo‐
2751 ries and sub-directories are matched.
2752 -H Enable !-style history expansion similar to csh(1).
2753 -K When no arguments are specified, it is used along with
2754 -s to specify the sort fields and sort options for sort‐
2755 ing an array. (See "Array Sorting" above for the
2756 description of the keylist option.)
2757 -a All subsequent variables that are defined are automati‐
2758 cally exported.
2759 -b Prints job completion messages as soon as a background
2760 job changes state rather than waiting for the next
2761 prompt.
2762 -e Unless contained in a ⎪⎪ or && command, or the command
2763 following an if while or until command or in the pipe‐
2764 line following !, if a command has a non-zero exit sta‐
2765 tus, execute the ERR trap, if set, and exit. This mode
2766 is disabled while reading profiles.
2767 -f Disables file name generation.
2768 -h Each command becomes a tracked alias when first encoun‐
2769 tered.
2770 -k (Obsolete). All variable assignment arguments are placed
2771 in the environment for a command, not just those that
2772 precede the command name.
2773 -m Background jobs will run in a separate process group and
2774 a line will print upon completion. The exit status of
2775 background jobs is reported in a completion message. On
2776 systems with job control, this option is turned on auto‐
2777 matically for interactive shells.
2778 -n Read commands and check them for syntax errors, but do
2779 not execute them. Ignored for interactive shells.
2780 -o The following argument can be one of the following
2781 option names:
2782 allexport
2783 Same as -a.
2784 bgnice All background jobs are run at a lower priority.
2785 This is the default mode.
2786 braceexpand
2787 Same as -B.
2788 emacs Puts you in an emacs style in-line editor for
2789 command entry.
2790 errexit Same as -e.
2791 globstar
2792 Same as -G.
2793 gmacs Puts you in a gmacs style in-line editor for
2794 command entry.
2795 histexpand
2796 Same as -H.
2797 ignoreeof
2798 The shell will not exit on end-of-file. The
2799 command exit must be used.
2800 keyword Same as -k.
2801 letoctal
2802 The let command allows octal constants starting
2803 with 0.
2804 markdirs
2805 All directory names resulting from file name
2806 generation have a trailing / appended.
2807 monitor Same as -m.
2808 multiline
2809 The built-in editors will use multiple lines on
2810 the screen for lines that are longer than the
2811 width of the screen. This may not work for all
2812 terminals.
2813 noclobber
2814 Same as -C.
2815 noexec Same as -n.
2816 noglob Same as -f.
2817 nolog Do not save function definitions in the history
2818 file.
2819 notify Same as -b.
2820 nounset Same as -u.
2821 pipefail
2822 A pipeline will not complete until all compo‐
2823 nents of the pipeline have completed, and the
2824 return value will be the value of the last non-
2825 zero command to fail or zero if no command has
2826 failed.
2827 privileged
2828 Same as -p.
2829 showme When enabled, simple commands or pipelines pre‐
2830 ceded by a semicolon (;) will be displayed as if
2831 the xtrace option were enabled but will not be
2832 executed. Otherwise, the leading ; will be
2833 ignored.
2834 trackall
2835 Same as -h.
2836 verbose Same as -v.
2837 vi Puts you in insert mode of a vi style in-line
2838 editor until you hit the escape character 033.
2839 This puts you in control mode. A return sends
2840 the line.
2841 viraw Each character is processed as it is typed in vi
2842 mode. This is now always enabled. Disabling the
2843 option at run time has no effect.
2844 xtrace Same as -x.
2845 If no option name is supplied, then the current option
2846 settings are printed.
2847 -p Disables processing of the $HOME/.profile file and uses
2848 the file /etc/suid_profile instead of the ENV file.
2849 This mode is on whenever the effective uid (gid) is not
2850 equal to the real uid (gid). Turning this off causes
2851 the effective uid and gid to be set to the real uid and
2852 gid.
2853 -r Enables the restricted shell. This option cannot be
2854 unset once set.
2855 -s Sort the positional parameters lexicographically. When
2856 used with -A
2857 sorts the elements of the array.
2858 -t (Obsolete). Exit after reading and executing one
2859 command.
2860 -u Treat unset parameters as an error when substituting.
2861 -v Print shell input lines as they are read.
2862 -x Print commands and their arguments as they are executed.
2863 -- Do not change any of the options; useful in setting $1
2864 to a value beginning with -. If no arguments follow
2865 this option then the positional parameters are unset.
2866
2867 As an obsolete feature, if the first arg is - then the -x and -v
2868 options are turned off and the next arg is treated as the first
2869 argument. Using + rather than - causes these options to be
2870 turned off. These options can also be used upon invocation of
2871 the shell. The current set of options may be found in $-.
2872 Unless -A is specified, the remaining arguments are positional
2873 parameters and are assigned, in order, to $1 $2 .... If no
2874 arguments are given, then the names and values of all variables
2875 are printed on the standard output.
2876
2877 † shift [ n ]
2878 The positional parameters from $n+1 ... are renamed $1 ... ,
2879 default n is 1. The parameter n can be any arithmetic expres‐
2880 sion that evaluates to a non-negative number less than or equal
2881 to $#.
2882
2883 sleep seconds
2884 Suspends execution for the number of decimal seconds or frac‐
2885 tions of a second given by seconds. seconds A suffix of one of
2886 smhd can be used to indicate seconds, minutes, hours, and days
2887 respectively. Seconds can also be specified using a date/time
2888 format.
2889
2890 † trap [ -alp ] [ action ] [ sig ] ...
2891 The -p option causes the trap action associated with each trap
2892 as specified by the arguments to be printed with appropriate
2893 quoting. Otherwise, action will be processed as if it were an
2894 argument to eval when the shell receives signal(s) sig.
2895 The -a option causes the current trap setting to be appended to
2896 action. Each sig can be given as a number or as the name of the
2897 signal. Trap commands are executed in order of signal number.
2898 Any attempt to set a trap on a signal that was ignored on entry
2899 to the current shell is ineffective. If action is omitted and
2900 the first sig is a number, or if action is -, then the trap(s)
2901 for each sig are reset to their original values. If action is
2902 the null string then this signal is ignored by the shell and by
2903 the commands it invokes.
2904 If sig is ERR then action will be executed whenever a command
2905 has a non-zero exit status.
2906 If sig is DEBUG then action will be executed before each com‐
2907 mand. The variable .sh.command will contain the contents of the
2908 current command line when action is running. If the exit status
2909 of the trap is 2 the command will not be executed. If the exit
2910 status of the trap is 255 and inside a function or a dot script,
2911 the function or dot script will return.
2912 If sig is 0 or EXIT and the trap statement is executed inside
2913 the body of a function defined with the function name syntax,
2914 then the command action is executed after the function com‐
2915 pletes. For a trap set outside any function then the command
2916 action is executed on exit from the shell.
2917 If sig is KEYBD, then action will be executed whenever a key is
2918 read while in emacs, gmacs, or vi mode. The trap command with
2919 no arguments prints a list of commands associated with each sig‐
2920 nal number.
2921 An exit or return without an argument in a trap action will pre‐
2922 serve the exit status of the command that invoked the trap.
2923 action. Each sig can be given as a number or as the name of the
2924 signal. Trap commands are executed in order of signal number.
2925 Any attempt to set a trap on a signal that was ignored on entry
2926 to the current shell is ineffective. If action is omitted and
2927 the first sig is a number, or if action is -, then the trap(s)
2928 for each sig are reset to their original values. The -l option
2929 lists the signals and their numbers to standard output.
2930
2931 true Does nothing, and exits 0. Used with while for infinite loops.
2932
2933 †† typeset [ ±ACHSfblmnprstux ] [ ±EFLRXZi[n] ] [ +-M [ mapname ] ]
2934 [ -T [ tname=(assign_list) ] ] [ -h str ] [ -a [type] ] [ vname[=value
2935 ] ] ...
2936 Sets attributes and values for shell variables and functions.
2937 When invoked inside a function defined with the function name
2938 syntax, a new instance of the variable vname is created, and the
2939 variable's value and type are restored when the function com‐
2940 pletes. The following list of attributes may be specified:
2941 -A Declares vname to be an associative array. Subscripts
2942 are strings rather than arithmetic expressions.
2943 -C causes each vname to be a compound variable. value names
2944 a compound variable it is copied into vname. Otherwise,
2945 it unsets each vname.
2946 -a Declares vname to be an indexed array. If type is speci‐
2947 fied, it must be the name of an enumeration type created
2948 with the enum command and it allows enumeration constants
2949 to be used as subscripts.
2950 -E Declares vname to be a double precision floating point
2951 number. If n is non-zero, it defines the number of sig‐
2952 nificant figures that are used when expanding vname.
2953 Otherwise, ten significant figures will be used.
2954 -F Declares vname to be a double precision floating point
2955 number. If n is non-zero, it defines the number of
2956 places after the decimal point that are used when expand‐
2957 ing vname. Otherwise ten places after the decimal point
2958 will be used.
2959 -H This option provides UNIX to host-name file mapping on
2960 non-UNIX machines.
2961 -L Left justify and remove leading blanks from value. If n
2962 is non-zero, it defines the width of the field, otherwise
2963 it is determined by the width of the value of first
2964 assignment. When the variable is assigned to, it is
2965 filled on the right with blanks or truncated, if neces‐
2966 sary, to fit into the field. The -R option is turned
2967 off.
2968 -M Use the character mapping mapping defined by wctrans(3).
2969 such as tolower and toupper when assigning a value to
2970 each of the specified operands. When mapping is speci‐
2971 fied and there are not operands, all variables that use
2972 this mapping are written to standard output. When map‐
2973 ping is omitted and there are no operands, all mapped
2974 variables are written to standard output.
2975 -R Right justify and fill with leading blanks. If n is non-
2976 zero, it defines the width of the field, otherwise it is
2977 determined by the width of the value of first assignment.
2978 The field is left filled with blanks or truncated from
2979 the end if the variable is reassigned. The -L option is
2980 turned off.
2981 -S When used within the assign_list of a type definition, it
2982 causes the specified sub-variable to be shared by all
2983 instances of the type. When used inside a function
2984 defined with the function reserved word, the specified
2985 variables will have function static scope. Otherwise,
2986 the variable is unset prior to processing the assignment
2987 list.
2988 -T If followed by tname, it creates a type named by tname
2989 using the compound assignment assign_list to tname. Oth‐
2990 erwise, it writes all the type definitions to standard
2991 output.
2992 -X Declares vname to be a double precision floating point
2993 number and expands using the %a format of ISO-C99. If n
2994 is non-zero, it defines the number of hex digits after
2995 the radix point that is used when expanding vname. The
2996 default is 10.
2997 -Z Right justify and fill with leading zeros if the first
2998 non-blank character is a digit and the -L option has not
2999 been set. Remove leading zeros if the -L option is also
3000 set. If n is non-zero, it defines the width of the
3001 field, otherwise it is determined by the width of the
3002 value of first assignment.
3003 -f The names refer to function names rather than variable
3004 names. No assignments can be made and the only other
3005 valid options are -S, -t, -u and -x. The -S can be used
3006 with discipline functions defined in a type to indicate
3007 that the function is static. For a static function, the
3008 same method will be used by all instances of that type no
3009 matter which instance references it. In addition, it can
3010 only use value of variables from the original type defi‐
3011 nition. These discipline functions cannot be redefined
3012 in any type instance. The -t option turns on execution
3013 tracing for this function. The -u option causes this
3014 function to be marked undefined. The FPATH variable will
3015 be searched to find the function definition when the
3016 function is referenced. If no options other than -f is
3017 specified, then the function definition will be displayed
3018 on standard output. If +f is specified, then a line con‐
3019 taining the function name followed by a shell comment
3020 containing the line number and path name of the file
3021 where this function was defined, if any, is displayed.
3022 The exit status can be used to determine whether the
3023 function is defined so that typeset -f .sh.math.name will
3024 return 0 when math function name is defined and non-zero
3025 otherwise.
3026 -b The variable can hold any number of bytes of data. The
3027 data can be text or binary. The value is represented by
3028 the base64 encoding of the data. If -Z is also speci‐
3029 fied, the size in bytes of the data in the buffer will be
3030 determined by the size associated with the -Z. If the
3031 base64 string assigned results in more data, it will be
3032 truncated. Otherwise, it will be filled with bytes whose
3033 value is zero. The printf format %B can be used to out‐
3034 put the actual data in this buffer instead of the base64
3035 encoding of the data.
3036 -h Used within type definitions to add information when gen‐
3037 erating information about the sub-variable on the man
3038 page. It is ignored when used outside of a type defini‐
3039 tion. When used with -f the information is associated
3040 with the corresponding discipline function.
3041 -i Declares vname to be represented internally as integer.
3042 The right hand side of an assignment is evaluated as an
3043 arithmetic expression when assigning to an integer. If n
3044 is non-zero, it defines the output arithmetic base, oth‐
3045 erwise the output base will be ten.
3046 -l Used with -i, -E or -F, to indicate long integer, or long
3047 double. Otherwise, all upper-case characters are con‐
3048 verted to lower-case. The upper-case option, -u, is
3049 turned off. Equivalent to -M tolower .
3050 -m moves or renames the variable. The value is the name of
3051 a variable whose value will be moved to vname. The orig‐
3052 inal variable will be unset. Cannot be used with any
3053 other options.
3054 -n Declares vname to be a reference to the variable whose
3055 name is defined by the value of variable vname. This is
3056 usually used to reference a variable inside a function
3057 whose name has been passed as an argument. Cannot be
3058 used with any other options.
3059 -p The name, attributes and values for the given vnames are
3060 written on standard output in a form that can be used as
3061 shell input. If +p is specified, then the values are not
3062 displayed.
3063 -r The given vnames are marked readonly and these names can‐
3064 not be changed by subsequent assignment.
3065 -s Used with -i, -E or -F, to indicate short integer, or
3066 float.
3067 -t Tags the variables. Tags are user definable and have no
3068 special meaning to the shell.
3069 -u When given along with -i, specifies unsigned integer.
3070 Otherwise, all lower-case characters are converted to
3071 upper-case. The lower-case option, -l, is turned off.
3072 Equivalent to -M toupper .
3073 -x The given vnames are marked for automatic export to the
3074 environment of subsequently-executed commands. Variables
3075 whose names contain a . cannot be exported.
3076
3077 The -i attribute cannot be specified along with -R, -L, -Z, or
3078 -f.
3079
3080 Using + rather than - causes these options to be turned off. If
3081 no vname arguments are given, a list of vnames (and optionally
3082 the values) of the variables is printed. (Using + rather than -
3083 keeps the values from being printed.) The -p option causes
3084 typeset followed by the option letters to be printed before each
3085 name rather than the names of the options. If any option other
3086 than -p is given, only those variables which have all of the
3087 given options are printed. Otherwise, the vnames and attributes
3088 of all variables that have attributes are printed.
3089
3090 ulimit [ -HSacdfmnpstv ] [ limit ]
3091 Set or display a resource limit. The available resource limits
3092 are listed below. Many systems do not support one or more of
3093 these limits. The limit for a specified resource is set when
3094 limit is specified. The value of limit can be a number in the
3095 unit specified below with each resource, or the value unlimited.
3096 The -H and -S options specify whether the hard limit or the soft
3097 limit for the given resource is set. A hard limit cannot be
3098 increased once it is set. A soft limit can be increased up to
3099 the value of the hard limit. If neither the H nor S option is
3100 specified, the limit applies to both. The current resource
3101 limit is printed when limit is omitted. In this case, the soft
3102 limit is printed unless H is specified. When more than one
3103 resource is specified, then the limit name and unit is printed
3104 before the value.
3105 -a Lists all of the current resource limits.
3106 -c The number of 512-byte blocks on the size of core dumps.
3107 -d The number of K-bytes on the size of the data area.
3108 -f The number of 512-byte blocks on files that can be writ‐
3109 ten by the current process or by child processes (files
3110 of any size may be read).
3111 -m The number of K-bytes on the size of physical memory.
3112 -n The number of file descriptors plus 1.
3113 -p The number of 512-byte blocks for pipe buffering.
3114 -s The number of K-bytes on the size of the stack area.
3115 -t The number of CPU seconds to be used by each process.
3116 -v The number of K-bytes for virtual memory.
3117
3118 If no option is given, -f is assumed.
3119
3120 umask [ -pS ] [ mask ]
3121 The user file-creation mask is set to mask (see umask(2)). mask
3122 can either be an octal number or a symbolic value as described
3123 in chmod(1). If a symbolic value is given, the new umask value
3124 is the complement of the result of applying mask to the comple‐
3125 ment of the previous umask value. If mask is omitted, the cur‐
3126 rent value of the mask is printed. The -S option causes the
3127 mode to be printed as a symbolic value. Otherwise, the mask is
3128 printed in octal. The -p option cause the output to be in a
3129 form that can be use for reinput.
3130
3131 † unalias [ -a ] name ...
3132 The aliases given by the list of names are removed from the
3133 alias list. The -a option causes all the aliases to be unset.
3134
3135 †unset [ -fnv ] vname ...
3136 The variables given by the list of vnames are unassigned, i.e.,
3137 except for sub-variables within a type, their values and
3138 attributes are erased. For sub-variables of a type, the values
3139 are reset to the default value from the type definition. Read‐
3140 only variables cannot be unset. If the -f option is set, then
3141 the names refer to function names. If the -v option is set,
3142 then the names refer to variable names. The -f option overrides
3143 -v. If -n is set and name is a name reference, then name will
3144 be unset rather than the variable that it references. The
3145 default is equivalent to -v. Unsetting LINENO, MAILCHECK,
3146 OPTARG, OPTIND, RANDOM, SECONDS, TMOUT, and _ removes their spe‐
3147 cial meaning even if they are subsequently assigned to.
3148
3149 wait [ job ... ]
3150 Wait for the specified job and report its termination status.
3151 If job is not given, then all currently active child processes
3152 are waited for. The exit status from this command is that of
3153 the last process waited for if job is specified; otherwise it is
3154 zero. See Jobs for a description of the format of job.
3155
3156 whence [ -afpv ] name ...
3157 For each name, indicate how it would be interpreted if used as a
3158 command name.
3159 The -v option produces a more verbose report. The -f option
3160 skips the search for functions. The -p option does a path
3161 search for name even if name is an alias, a function, or a
3162 reserved word. The -p option turns off the -v option. The -a
3163 option is similar to the -v option but causes all interpreta‐
3164 tions of the given name to be reported.
3165
3166 Invocation.
3167 If the shell is invoked by exec(2), and the first character of argument
3168 zero ($0) is -, then the shell is assumed to be a login shell and com‐
3169 mands are read from /etc/profile and then from $HOME/.profile, if it
3170 exists. Alternatively, the option -l causes the shell to a treated as
3171 a login shell. Next, for interactive shells, commands are read from
3172 the file named by performing parameter expansion, command substitution,
3173 and arithmetic substitution on the value of the environment variable
3174 ENV if the file exists. If the -s option is not present and arg and a
3175 file by the name of arg exists, then it reads and executes this script.
3176 Otherwise, if the first arg does not contain a /, a path search is per‐
3177 formed on the first arg to determine the name of the script to execute.
3178 The script arg must have execute permission and any setuid and setgid
3179 settings will be ignored. If the script is not found on the path, arg
3180 is processed as if it named a built-in command or function. Commands
3181 are then read as described below; the following options are interpreted
3182 by the shell when it is invoked:
3183
3184 -D A list of all double quoted strings that are preceded by a $
3185 will be printed on standard output and the shell will exit.
3186 This set of strings will be subject to language translation
3187 when the locale is not C or POSIX. No commands will be exe‐
3188 cuted.
3189
3190 -E Reads the file named by the ENV variable or by $HOME/.kshrc if
3191 not defined after the profiles.
3192
3193 -c If the -c option is present, then commands are read from the
3194 first arg. Any remaining arguments become positional parame‐
3195 ters starting at 0.
3196
3197 -s If the -s option is present or if no arguments remain, then
3198 commands are read from the standard input. Shell output,
3199 except for the output of the Special Commands listed above, is
3200 written to file descriptor 2.
3201
3202 -i If the -i option is present or if the shell input and error
3203 output are attached to a terminal (as told by tcgetattr(2)),
3204 then this shell is interactive. In this case TERM is ignored
3205 (so that kill 0 does not kill an interactive shell) and INTR is
3206 caught and ignored (so that wait is interruptible). In all
3207 cases, QUIT is ignored by the shell.
3208
3209 -r If the -r option is present, the shell is a restricted shell.
3210
3211 -P If -P or -o profile is present, the shell is a profile shell
3212 (see pfexec(1)).
3213
3214 -R filename
3215 The -R filename option is used to generate a cross reference
3216 database that can be used by a separate utility to find defini‐
3217 tions and references for variables and commands. The filename
3218 argument specifies the generated database. A script file must
3219 be provided on the command line as well.
3220
3221 The remaining options and arguments are described under the set command
3222 above. An optional - as the first argument is ignored.
3223
3224 Rksh Only.
3225 Rksh is used to set up login names and execution environments whose
3226 capabilities are more controlled than those of the standard shell. The
3227 actions of rksh are identical to those of ksh, except that the follow‐
3228 ing are disallowed:
3229 Unsetting the restricted option.
3230 changing directory (see cd(1)),
3231 setting or unsetting the value or attributes of SHELL, ENV,
3232 FPATH, or PATH,
3233 specifying path or command names containing /,
3234 redirecting output (>, >|, <>, and >>).
3235 adding or deleting built-in commands.
3236 using command -p to invoke a command.
3237
3238 The restrictions above are enforced after .profile and the ENV files
3239 are interpreted.
3240
3241 When a command to be executed is found to be a shell procedure, rksh
3242 invokes ksh to execute it. Thus, it is possible to provide to the end-
3243 user shell procedures that have access to the full power of the stan‐
3244 dard shell, while imposing a limited menu of commands; this scheme
3245 assumes that the end-user does not have write and execute permissions
3246 in the same directory.
3247
3248 The net effect of these rules is that the writer of the .profile has
3249 complete control over user actions, by performing guaranteed setup
3250 actions and leaving the user in an appropriate directory (probably not
3251 the login directory).
3252
3253 The system administrator often sets up a directory of commands (e.g.,
3254 /usr/rbin) that can be safely invoked by rksh.
3255
3257 Errors detected by the shell, such as syntax errors, cause the shell to
3258 return a non-zero exit status. If the shell is being used non-interac‐
3259 tively, then execution of the shell file is abandoned unless the error
3260 occurs inside a subshell in which case the subshell is abandoned. Oth‐
3261 erwise, the shell returns the exit status of the last command executed
3262 (see also the exit command above). Run time errors detected by the
3263 shell are reported by printing the command or function name and the
3264 error condition. If the line number that the error occurred on is
3265 greater than one, then the line number is also printed in square brack‐
3266 ets ([]) after the command or function name.
3267
3269 /etc/profile
3270 The system wide initialization file, executed for login shells.
3271
3272 $HOME/.profile
3273 The personal initialization file, executed for login shells
3274 after /etc/profile.
3275
3276 $HOME/.kshrc
3277 Default personal initialization file, executed for interactive
3278 shells when ENV is not set.
3279
3280 /etc/suid_profile
3281 Alternative initialization file, executed instead of the per‐
3282 sonal initialization file when the real and effective user or
3283 group id do not match.
3284
3285 /dev/null
3286 NULL device
3287
3289 cat(1), cd(1), chmod(1), cut(1), date(1), egrep(1), echo(1), emacs(1),
3290 env(1), fgrep(1), gmacs(1), grep(1), newgrp(1), pfexec(1), stty(1),
3291 test(1), touch(1), umask(1), vi(1), dup(2), exec(2), fork(2), getpw‐
3292 nam(3), ioctl(2), lseek(2), paste(1), pathconf(2), pipe(2), sigset‐
3293 info(2), sysconf(2), umask(2), ulimit(2), wait(2), wctrans(3), rand(3),
3294 a.out(5), profile(5), environ(7).
3295
3296 Morris I. Bolsky and David G. Korn, The New KornShell Command and Pro‐
3297 gramming Language, Prentice Hall, 1995.
3298
3299 POSIX - Part 2: Shell and Utilities, IEEE Std 1003.2-1992, ISO/IEC
3300 9945-2, IEEE, 1993.
3301
3303 If a command is executed, and then a command with the same name is
3304 installed in a directory in the search path before the directory where
3305 the original command was found, the shell will continue to exec the
3306 original command. Use the -t option of the alias command to correct
3307 this situation.
3308
3309 Some very old shell scripts contain a ^ as a synonym for the pipe char‐
3310 acter ⎪.
3311
3312 Using the hist built-in command within a compound command will cause
3313 the whole command to disappear from the history file.
3314
3315 The built-in command . file reads the whole file before any commands
3316 are executed. Therefore, alias and unalias commands in the file will
3317 not apply to any commands defined in the file.
3318
3319 Traps are not processed while a job is waiting for a foreground
3320 process. Thus, a trap on CHLD won't be executed until the foreground
3321 job terminates.
3322
3323 It is a good idea to leave a space after the comma operator in arith‐
3324 metic expressions to prevent the comma from being interpreted as the
3325 decimal point character in certain locales.
3326
3327
3328
3329 KSH(1)