1ksh93(1) User Commands ksh93(1)
2
3
4
6 ksh93, rksh93 - Korn Shell, a standard and restricted command and pro‐
7 gramming language
8
10 ksh93 [±abcefhikmnoprstuvxBCD] [-R file] [ ±o option] ...
11 [-] [arg ...]
12
13
14 rksh93 [±abcefhikmnoprstuvxBCD] [-R file] [±o option] ...
15 [-] [arg ...]
16
17
19 ksh93 is a command and programming language that executes commands read
20 from a terminal or a file. rksh93 is a restricted version of the com‐
21 mand interpreter ksh93. rksh93 is used to set up login names and execu‐
22 tion environments whose capabilities are more controlled than those of
23 the standard shell.
24
25
26 See Invocation for the meaning of arguments to the shell.
27
28 Definitions
29 A metacharacter is defined as one of the following characters:
30
31 ; & ( ) | < > NEWLINE SPACE TAB
32
33
34
35
36 A blank is a TAB or a SPACE.
37
38
39 An identifier is a sequence of letters, digits, or underscores starting
40 with a letter or underscore. Identifiers are used as components of
41 variable names.
42
43
44 A vname is a sequence of one or more identifiers separated by a period
45 (.) and optionally preceded by a period (.). vnames are used as func‐
46 tion and variable names.
47
48
49 A word is a sequence of characters from the character set defined by
50 the current locale, excluding non-quoted metacharacters.
51
52
53 A command is a sequence of characters in the syntax of the shell lan‐
54 guage. The shell reads each command and carries out the desired action
55 either directly or by invoking separate utilities. A built-in command
56 is a command that is carried out by the shell itself without creating a
57 separate process. Some commands are built-in purely for convenience and
58 are not documented in this manual page. Built-ins that cause side
59 effects in the shell environment and built-ins that are found before
60 performing a path search (see Execution) are documented in this manual
61 page. For historical reasons, some of these built-ins behave differ‐
62 ently than other built-ins and are called special built-ins.
63
64 Commands
65 A simple-command is a list of variable assignments (see Variable
66 Assignments) or a sequence of blank-separated words which can be pre‐
67 ceded by a list of variable assignments. See the Environment section of
68 this manual page.
69
70
71 The first word specifies the name of the command to be executed. Except
72 as specified in this section, the remaining words are passed as argu‐
73 ments to the invoked command. The command name is passed as argument 0.
74 See exec(2). The value of a simple-command is its exit status. If it
75 terminates normally, its value is 0-255. If it terminates abnormally,
76 its value is 256+signum. The name of the signal corresponding to the
77 exit status can be obtained by way of the -l option of the kill built-
78 in utility.
79
80
81 A pipeline is a sequence of one or more commands separated by |. The
82 standard output of each command but the last is connected by a pipe(2)
83 to the standard input of the next command. Each command, except possi‐
84 bly the last, is run as a separate process. The shell waits for the
85 last command to terminate. The exit status of a pipeline is the exit
86 status of the last command unless the pipefail option is enabled. Each
87 pipeline can be preceded by the reserved word!. This causes the exit
88 status of the pipeline to become 0 if the exit status of the last com‐
89 mand is non-zero, and 1 if the exit status of the last command is 0.
90
91
92 A list is a sequence of one or more pipelines separated by ;, &, |&,
93 &&, or |, and optionally terminated by ;, &, or |&. Of these five sym‐
94 bols, ;, &, and |& have equal precedence, which is lower than that of
95 && and ||. The symbols && and || also have equal precedence.
96
97
98 A semicolon (;) causes sequential execution of the preceding pipeline.
99 An ampersand (&) causes asynchronous execution of the preceding pipe‐
100 line, that is, the shell does not wait for that pipeline to finish. The
101 symbol |& causes asynchronous execution of the preceding pipeline with
102 a two-way pipe established to the parent shell. The standard input and
103 output of the spawned pipeline can be written to and read from by the
104 parent shell by applying the redirection operators <& and >& with arg p
105 to commands and by using -p option of the built-in commands read and
106 print. The symbol && (||) causes the list following it to be executed
107 only if the preceding pipeline returns a zero (non-zero) value. One or
108 more NEWLINEs can appear in a list instead of a semicolon, to delimit a
109 command. The first item of the first pipeline of a list that is a sim‐
110 ple command not beginning with a redirection, and not occurring within
111 a while, until, or if list , can be preceded by a semicolon. This semi‐
112 colon is ignored unless the showme option is enabled as described with
113 the set built-in.
114
115
116 A command is either a simple-command or one of commands in the follow‐
117 ing list. Unless otherwise stated, the value returned by a command is
118 that of the last simple-command executed in the command.
119
120 for vname [ in word ... ] ;do list ;done
121
122 Each time a for command is executed, vname is set to the next word
123 taken from the in word list. If in word ... is omitted, the for
124 command executes the do list once for each positional parameter
125 that is set starting from 1. Execution ends when there are no more
126 words in the list. See Parameter Expansion.
127
128
129 (( [expr1] ; [expr2] ; [expr3] )) ;do list ;done
130
131 The arithmetic expression expr1 is evaluated first. The arithmetic
132 expression expr2 is repeatedly evaluated until it evaluates to zero
133 and when non-zero, list is executed and the arithmetic expression
134 expr3 evaluated. If any expression is omitted, then it behaves as
135 if it evaluated to 1. See Arithmetic Evaluation.
136
137
138 select vname [ in word ... ] ;do list ;done
139
140 A select command prints on standard error (file descriptor 2) the
141 set of words, each preceded by a number. If in word... is omitted,
142 the positional parameters starting from 1 are used instead. See
143 Parameter Expansion. The PS3 prompt is printed and a line is read
144 from the standard input. If this line consists of the number of one
145 of the listed words, then the value of the variable vname is set to
146 the word corresponding to this number. If this line is empty, the
147 selection list is printed again. Otherwise the value of the vari‐
148 able vname is set to null. The contents of the line read from stan‐
149 dard input is saved in the variable REPLY. The list is executed for
150 each selection until a break or EOF is encountered. If the REPLY
151 variable is set to null by the execution of list, the selection
152 list is printed before displaying the PS3 prompt for the next
153 selection.
154
155
156 case word in [ [(] pattern [ | pattern ] ... ) list ;; ] ... esac
157
158 A case command executes the list associated with the first pattern
159 that matches word. The form of the patterns is the same as that
160 used for file name generation. See File Name Generation.
161
162 The ;; operator causes execution of case to terminate. If ;& is
163 used in place of ;; the next subsequent list, if any, is executed.
164
165
166 if list ;then list [ ;elif list ;then list ] ... [ ;else list ] ;fi
167
168 The list following if is executed and, if it returns a zero exit
169 status, the list following the first then is executed. Otherwise,
170 the list following elif is executed, and, if its value is zero, the
171 list following the next then is executed. Failing each successive
172 elif list, the else list is executed. If the if list has non-zero
173 exit status and there is no else list, then the if command returns
174 a zero exit status.
175
176
177 while list ;do list ;done
178 until list ;do list ;done
179
180 A while command repeatedly executes the while list and, if the exit
181 status of the last command in the list is zero, executes the do
182 list, otherwise the loop terminates. If no commands in the do list
183 are executed, then the while command returns a zero exit status,
184 until can be used in place of while to negate the loop termination
185 test.
186
187
188 ((expression))
189
190 The expression is evaluated using the rules for arithmetic evalua‐
191 tion described in this manual page. If the value of the arithmetic
192 expression is non-zero, the exit status is 0. Otherwise the exit
193 status is 1.
194
195
196 (list;)
197
198 Execute list in a separate environment. If two adjacent open paren‐
199 theses are needed for nesting, a SPACE must be inserted to avoid
200 evaluation as an arithmetic command as described in this section.
201
202 list is simply executed. Unlike the metacharacters, ( and ), { and
203 } are reserved words and must occur at the beginning of a line or
204 after a ; to be recognized.
205
206
207 [[ expression ]]
208
209 Evaluates expression and returns a zero exit status when expression
210 is true. See Conditional Expressions for a description of expres‐
211 sion.
212
213
214 function varname { list ;}
215 varname () { list ;}
216
217 Define a function which is referenced by varname. A function whose
218 varname contains a . is called a discipline function and the por‐
219 tion of the varname preceding the last . must refer to an existing
220 variable.
221
222 The body of the function is the list of commands between { and }. A
223 function defined with the function varname syntax can also be used
224 as an argument to the . special built-in command to get the equiva‐
225 lent behavior as if the varname() syntax were used to define it.
226 See Functions.
227
228
229 time [ pipeline ]
230
231 If pipeline is omitted, the user and system time for the current
232 shell and completed child processes is printed on standard error.
233 Otherwise, pipeline is executed and the elapsed time as well as the
234 user and system time are printed on standard error. The TIMEFORMAT
235 variable can be set to a format string that specifies how the tim‐
236 ing information should be displayed. See Shell Variables for a
237 description of the TIMEFORMAT variable.
238
239
240
241 The following reserved words are recognized as reserved only when they
242 are the first word of a command and are not quoted:
243 case
244 do
245 done
246 else
247 elif
248 esac
249 for
250 fi
251 function
252 if
253 select
254 then
255 time
256 until
257 while
258 { }
259 [[ ]]
260 !
261
262 Variable Assignments
263 One or more variable assignments can start a simple command or can be
264 arguments to the typeset, export, or readonly special built-in com‐
265 mands. The syntax for an assignment is of the form:
266
267 varname=word
268 varname[word]=word
269
270 No space is permitted between varname and the = or between = and
271 word.
272
273
274 varname=(assignlist)
275
276 No space is permitted between varname and the =. An assignlist can
277 be one of the following:
278
279 word ...
280
281 Indexed array assignment.
282
283
284 [word]=word ...
285
286 Associative array assignment. If prefixed by typeset -a, cre‐
287 ates an indexed array instead.
288
289
290 assignment ...
291
292 Compound variable assignment. This creates a compound variable
293 varname with sub-variables of the form varname.name, where name
294 is the name portion of assignment. The value of varname con‐
295 tains all the assignment elements. Additional assignments made
296 to sub-variables of varname are also displayed as part of the
297 value of varname. If no assignments are specified, varname is a
298 compound variable allowing subsequence child elements to be
299 defined.
300
301
302 typeset [options] assignment ...
303
304 Nested variable assignment. Multiple assignments can be speci‐
305 fied by separating each of them with a ;. The previous value is
306 unset before the assignment.
307
308 In addition, a += can be used in place of the = to signify adding
309 to or appending to the previous value. When += is applied to an
310 arithmetic type, word is evaluated as an arithmetic expression and
311 added to the current value. When applied to a string variable, the
312 value defined by word is appended to the value. For compound
313 assignments, the previous value is not unset and the new values are
314 appended to the current ones provided that the types are compati‐
315 ble.
316
317
318 Comments
319 A word beginning with # causes that word and all the following charac‐
320 ters up to a NEWLINE to be commented, or ignored.
321
322 Aliasing
323 The first word of each command is replaced by the text of an alias if
324 an alias for this word has been defined. An alias name consists of any
325 number of characters excluding metacharacters, quoting characters, file
326 expansion characters, parameter expansion characters, command substitu‐
327 tion characters, and =. The replacement string can contain any valid
328 shell script including the metacharacters listed in the Commands sec‐
329 tion. The first word of each command in the replaced text, other than
330 any that are in the process of being replaced, are tested for aliases.
331 If the last character of the alias value is a BLANK then the word fol‐
332 lowing the alias is also checked for alias substitution.
333
334
335 Aliases can be used to redefine built-in commands but cannot be used to
336 redefine the reserved words listed in the Commands section. Aliases can
337 be created and listed with the alias command and can be removed with
338 the unalias command.
339
340
341 Aliasing is performed when scripts are read, not while they are exe‐
342 cuted. For an alias to take effect, the alias definition command has to
343 be executed before the command which references the alias is read. The
344 following aliases are compiled into the shell but can be unset or rede‐
345 fined:
346
347 autoload='typeset -fu'
348 command='command '
349 fc=hist
350 float='typeset -lE'
351 functions='typeset -f'
352 hash='alias -t --'
353 history='hist -l'
354 integer='typeset -li'
355 nameref='typeset -n'
356 nohup='nohup '
357 r='hist -s'
358 redirect='command exec'
359 source='command .'
360 stop='kill -s STOP'
361 suspend='kill -s STOP $$'
362 times='{ { time;} 2>&1;}'
363 type='whence -v'
364
365
366
367 Tilde Substitution
368 After alias substitution is performed, each word is checked to see if
369 it begins with an unquoted tilde (~). For tilde substitution, word also
370 refers to the word portion of parameter expansion. See Parameter Expan‐
371 sion.
372
373
374 If it does, the word up to a / is checked to see if it matches a user
375 name in the password database. If a match is found, the ~ and the
376 matched login name are replaced by the login directory of the matched
377 user. If no match is found, the original text is left unchanged. A ~ by
378 itself, or in front of a /, is replaced by $HOME. A ~ followed by a +
379 or - is replaced by the value of $PWD and $OLDPWD respectively.
380
381
382 In addition, when expanding a variable assignment, tilde substitution
383 is attempted when the value of the assignment begins with a ~, and when
384 a ~ appears after a colon (:). The : also terminates a ~ login name.
385
386 Command Substitution
387 The standard output from a command enclosed in parentheses preceded by
388 a dollar sign ($) or a pair of grave accents (``) can be used as part
389 or all of a word. Trailing NEWLINEs are removed. In the second (obso‐
390 lete) form, the string between the quotes is processed for special
391 quoting characters before the command is executed. See Quoting.
392
393
394 The command substitution $(cat file) can be replaced by the equivalent
395 but faster $(<file). The command substitution $(n<#) expands to the
396 current byte offset for file descriptor n.
397
398 Arithmetic Substitution
399 An arithmetic expression enclosed in double parentheses preceded by a
400 dollar sign ( $((arithmetic_expression))) is replaced by the value of
401 the arithmetic expression within the double parentheses.
402
403 Process Substitution
404 Process substitution is only available on versions of the UNIX operat‐
405 ing system that support the /dev/fd directory for naming open files.
406
407
408 Each command argument of the form <(list) or >(list) runs process list
409 asynchronously connected to some file in /dev/fd. The name of this file
410 becomes the argument to the command. If the form with > is selected
411 then writing on this file provides input for list. If < is used, then
412 the file passed as an argument contains the output of the list process.
413
414
415 For example,
416
417 paste <(cut -f1 file1) <(cut -f3 file2) | tee \
418 >(process1) >(process2)
419
420
421
422
423 cuts fields 1 and 3 from the files file1 and file2 respectively, pastes
424 the results together, and sends it to the processes process1 and
425 process2. It also displays the results to the standard output. The
426 file, which is passed as an argument to the command, is a UNIX pipe(2).
427 Programs that expect to lseek(2) on the file do not work.
428
429 Parameter Expansion
430 A parameter is a variable, one or more digits, or any of the characters
431 *, @, #, ?, -, $, and !. A variable is denoted by a vname. To create a
432 variable whose vname contains a ., a variable whose vname consists of
433 everything before the last . must already exist. A variable has a value
434 and zero or more attributes. Variables can be assigned values and
435 attributes by using the typeset special built-in command. The
436 attributes supported by the shell are described later with the typeset
437 special built-in command. Exported variables pass values and attributes
438 to the environment.
439
440
441 The shell supports both indexed and associative arrays. An element of
442 an array variable is referenced by a subscript. A subscript for an
443 indexed array is denoted by an arithmetic expression, (see Arithmetic
444 Evaluation), between a [ and a ]. Use set -A vname value ... to assign
445 values to an indexed array. The value of all subscripts must be in the
446 range of 0 through 1,048,575. Indexed arrays do not need to be
447 declared. Any reference to a variable with a valid subscript is legal
448 and an array is created if necessary.
449
450
451 An associative array is created with the -A option to typeset. A sub‐
452 script for an associative array is denoted by a string enclosed between
453 [ and ].
454
455
456 Referencing any array without a subscript is equivalent to referencing
457 the array with subscript 0.
458
459
460 The value of a variable can be assigned by:
461
462 vname=value [vname=value] ...
463
464
465
466
467 or
468
469 vname[subscript]=value [vname[subscript]=value] ...
470
471
472
473
474 No space is allowed before or after the =. A nameref is a variable that
475 is a reference to another variable. A nameref is created with the -n
476 attribute of typeset. The value of the variable at the time of the
477 typeset command becomes the variable that is referenced whenever the
478 nameref variable is used. The name of a nameref cannot contain a dot
479 (.). When a variable or function name contains a ., and the portion of
480 the name up to the first . matches the name of a nameref, the variable
481 referred to is obtained by replacing the nameref portion with the name
482 of the variable referenced by the nameref. If a nameref is used as the
483 index of a for loop, a name reference is established for each item in
484 the list. A nameref provides a convenient way to refer to the variable
485 inside a function whose name is passed as an argument to a function.
486 For example, if the name of a variable is passed as the first argument
487 to a function, the command
488
489 typeset -n var=$1
490
491
492
493
494 inside the function causes references and assignments to var to be ref‐
495 erences and assignments to the variable whose name has been passed to
496 the function. If either of the floating point attributes, -E, or -F, or
497 the integer attribute, -i, is set for vname, then the value is subject
498 to arithmetic evaluation as described in this manual page. Positional
499 parameters, parameters denoted by a number, can be assigned values with
500 the set special built-in command. Parameter $0 is set from argument
501 zero when the shell is invoked. The character $ is used to introduce
502 substitutable parameters.
503
504 ${parameter}
505
506 The shell reads all the characters from ${ to the matching } as
507 part of the same word even if it contains braces or metacharacters.
508 The value, if any, of the parameter is substituted. The braces are
509 required when parameter is followed by a letter, digit, or under‐
510 score that is not to be interpreted as part of its name, when the
511 variable name contains a ., or when a variable is subscripted. If
512 parameter is one or more digits then it is a positional parameter.
513 A positional parameter of more than one digit must be enclosed in
514 braces. If parameter is * or @, then all the positional parameters,
515 starting with $1, are substituted and separated by a field separa‐
516 tor character. If an array vname with subscript * or @ is used,
517 then the value for each of the elements is substituted, separated
518 by the first character of the value of IFS.
519
520
521 ${#parameter}
522
523 If parameter is * or @, the number of positional parameters is sub‐
524 stituted. Otherwise, the length of the value of the parameter is
525 substituted.
526
527
528 ${#vname[*]}
529 ${#vname[@]}
530
531 The number of elements in the array vname is substituted.
532
533
534 ${!vname}
535
536 Expands to the name of the variable referred to by vname. This is
537 vname except when vname is a name reference.
538
539
540 ${!vname[subscript]}
541
542 Expands to name of the subscript unless subscript is * or @. When
543 subscript is *, the list of array subscripts for vname is gener‐
544 ated. For a variable that is not an array, the value is 0 if the
545 variable is set. Otherwise it is null. When subscript is @, it is
546 the same as $ {vname[*]}, except that when used in double quotes,
547 each array subscript yields a separate argument.
548
549
550 ${!prefix*}
551
552 Expands to the names of the variables whose names begin with pre‐
553 fix.
554
555
556 ${parameter:-word}
557
558 If parameter is set and is non-null then substitute its value. Oth‐
559 erwise substitute word.
560
561 word is not evaluated unless it is to be used as the substituted
562 string.
563
564 In the following example, pwd is executed only if d is not set or
565 is NULL:
566
567 print ${d:-$(pwd)}
568
569
570 If the colon (: ) is omitted from the expression, the shell only
571 checks whether parameter is set or not.
572
573
574 ${parameter:=word}
575
576 If parameter is not set or is null, set it to word. The value of
577 the parameter is then substituted. Positional parameters cannot be
578 assigned to in this way.
579
580 word is not evaluated unless it is to be used as the substituted
581 string.
582
583 In the following example, pwd is executed only if d is not set or
584 is NULL:
585
586 print ${d:-$(pwd)}
587
588
589 If the colon (:) is omitted from the expression, the shell only
590 checks whether parameter is set or not.
591
592
593 ${parameter:?word}
594
595 If parameter is set and is non-null, substitute its value. Other‐
596 wise, print word and exit from the shell , if the shell is not
597 interactive. If word is omitted then a standard message is printed.
598
599 word is not evaluated unless it is to be used as the substituted
600 string.
601
602 In the following example, pwd is executed only if d is not set or
603 is NULL:
604
605 print ${d:-$(pwd)}
606
607
608 If the colon (: ) is omitted from the expression, the shell only
609 checks whether parameter is set or not.
610
611
612 ${parameter:+word}
613
614 If parameter is set and is non-null, substitute word. Otherwise
615 substitute nothing.
616
617 word is not evaluated unless it is to be used as the substituted
618 string.
619
620 In the following example, pwd is executed only if d is not set or
621 is NULL:
622
623 print ${d:-$(pwd)}
624
625
626 If the colon (:) is omitted from the expression, the shell only
627 checks whether parameter is set or not.
628
629
630 ${parameter:offset:length}
631 ${parameter:offset}
632
633 Expands to the portion of the value of parameter starting at the
634 character (counting from 0) determined by expanding offset as an
635 arithmetic expression and consisting of the number of characters
636 determined by the arithmetic expression defined by length.
637
638 In the second form, the remainder of the value is used. A negative
639 offset counts backwards from the end of parameter.
640
641 One or more BLANKs is required in front of a minus sign to prevent
642 the shell from interpreting the operator as :-. If parameter is *
643 or @, or is an array name indexed by * or @, then offset and length
644 refer to the array index and number of elements respectively. A
645 negative offset is taken relative to one greater than the highest
646 subscript for indexed arrays. The order for associative arrays is
647 unspecified.
648
649
650 ${parameter#pattern}
651 ${parameter##pattern}
652
653 If the shell pattern matches the beginning of the value of parame‐
654 ter, then the value of this expansion is the value of the parameter
655 with the matched portion deleted. Otherwise the value of this
656 parameter is substituted. In the first form the smallest matching
657 pattern is deleted and in the second form the largest matching pat‐
658 tern is deleted. When parameter is @, *, or an array variable with
659 subscript @ or *, the substring operation is applied to each ele‐
660 ment in turn.
661
662
663 ${parameter%pattern}
664 ${parameter%%pattern}
665
666 If the shell pattern matches the end of the value of parameter,
667 then the value of this expansion is the value of the parameter with
668 the matched part deleted. Otherwise substitute the value of parame‐
669 ter. In the first form the smallest matching pattern is deleted,
670 and in the second form the largest matching pattern is deleted.
671 When parameter is @, *, or an array variable with subscript @ or *,
672 the substring operation is applied to each element in turn.
673
674
675 ${parameter/pattern/string}
676 ${parameter//pattern/string}
677 ${parameter/#pattern/string}
678 ${parameter/%pattern/string}
679
680 Expands parameter and replaces the longest match of pattern with
681 the specified string. Each occurrence of \n in string is replaced
682 by the portion of parameter that matches the nth sub-pattern.
683
684 When string is null, the pattern is deleted and the / in front of
685 string can be omitted. When parameter is @, *, or an array variable
686 with subscript @ or *, the substitution operation is applied to
687 each element in turn. In this case, the string portion of word is
688 re-evaluated for each element.
689
690 In the first form, only the first occurrence of pattern is
691 replaced.
692
693 In the second form, each match for pattern is replaced by the spec‐
694 ified string.
695
696 The third form restricts the pattern match to the beginning of the
697 string.
698
699 The fourth form restricts the pattern match to the end of the
700 string.
701
702
703
704 The following parameters are automatically set by the shell:
705
706 # The number of positional parameters in decimal.
707
708
709 - Options supplied to the shell on invocation or by
710 the set command.
711
712
713 ? The decimal value returned by the last executed com‐
714 mand.
715
716
717 $ The process number of this shell.
718
719
720 _ Initially, the value of _ is the absolute pathname
721 of the shell or script being executed as passed in
722 the environment. It is subsequently assigned the
723 last argument of the previous command.
724
725 This parameter is not set for commands which are
726 asynchronous. This parameter is also used to hold
727 the name of the matching MAIL file when checking for
728 mail.
729
730
731 ! The process number of the last background command
732 invoked or the most recent job put in the background
733 with the bg built-in command.
734
735
736 .sh.command When processing a DEBUG trap, this variable contains
737 the current command line that is about to run.
738
739
740 .sh.edchar This variable contains the value of the keyboard
741 character (or sequence of characters if the first
742 character is an ESC, ASCII 033) that has been
743 entered when processing a KEYBD trap. If the value
744 is changed as part of the trap action, then the new
745 value replaces the key (or key sequence) that caused
746 the trap. See the Key Bindings section of this man‐
747 ual page.
748
749
750 .sh.edcol The character position of the cursor at the time of
751 the most recent KEYBD trap.
752
753
754 .sh.edmode The value is set to ESC when processing a KEYBD trap
755 while in vi insert mode. Otherwise, .sh.edmode is
756 null when processing a KEYBD trap. See the vi Edit‐
757 ing Mode section of this manual page.
758
759
760 .sh.edtext The characters in the input buffer at the time of
761 the most recent KEYBD trap. The value is null when
762 not processing a KEYBD trap.
763
764
765 .sh.file The pathname of the file than contains the current
766 command.
767
768
769 .sh.fun The name of the current function that is being exe‐
770 cuted.
771
772
773 .sh.match An indexed array which stores the most recent match
774 and sub-pattern matches after conditional pattern
775 matches that match and after variables expansions
776 using the operators #, %, or /. The 0th element
777 stores the complete match and the ith element stores
778 the ith sub-match. The .sh.match variable is unset
779 when the variable that has expanded is assigned a
780 new value.
781
782
783 .sh.name Set to the name of the variable at the time that a
784 discipline function is invoked.
785
786
787 .sh.subscript Set to the name subscript of the variable at the
788 time that a discipline function is invoked.
789
790
791 .sh.subshell The current depth for sub-shells and command substi‐
792 tution.
793
794
795 .sh.value Set to the value of the variable at the time that
796 the set or append discipline function is invoked.
797
798
799 .sh.version Set to a value that identifies the version of this
800 shell.
801
802
803 LINENO The current line number within the script or func‐
804 tion being executed.
805
806
807 OLDPWD The previous working directory set by the cd com‐
808 mand.
809
810
811 OPTARG The value of the last option argument processed by
812 the getopts built-in command.
813
814
815 OPTIND The index of the last option argument processed by
816 the getopts built-in command.
817
818
819 PPID The process number of the parent of the shell.
820
821
822 PWD The present working directory set by the cd command.
823
824
825 RANDOM Each time this variable is referenced, a random
826 integer, uniformly distributed between 0 and 32767,
827 is generated. The sequence of random numbers can be
828 initialized by assigning a numeric value to RANDOM.
829
830
831 REPLY This variable is set by the select statement and by
832 the read built-in command when no arguments are sup‐
833 plied.
834
835
836 SECONDS Each time this variable is referenced, the number of
837 seconds since shell invocation is returned. If this
838 variable is assigned a value, then the value
839 returned upon reference is the value that was
840 assigned plus the number of seconds since the
841 assignment.
842
843
844
845 The following variables are used by the shell:
846
847 CDPATH Defines the search path for the cd command.
848
849
850 COLUMNS Defines the width of the edit window for the shell edit
851 modes and for printing select lists.
852
853
854 EDITOR If the VISUAL variable is not set, the value of this
855 variable is checked for the patterns as described with
856 VISUAL and the corresponding editing option is turned on.
857
858 See the set command in the Special Command section of
859 this manual page.
860
861
862 ENV Performs parameter expansion, command substitution, and
863 arithmetic substitution on the value to generate the
864 pathname of the script that is executed when the shell is
865 invoked. This file is typically used for alias and func‐
866 tion definitions. The default value is $HOME/.kshrc.
867
868 See the Invocation section of this manual page.
869
870 ENV is not set by the shell.
871
872
873 FCEDIT Obsolete name for the default editor name for the hist
874 command. FCEDIT is not used when HISTEDIT is set.
875
876 The shell specifies a default value to FCEDIT.
877
878
879 FIGNORE A pattern that defines the set of file names that is
880 ignored when performing file name matching.
881
882
883 FPATH The search path for function definitions. The directories
884 in this path are searched for a file with the same name
885 as the function or command when a function with the -u
886 attribute is referenced and when a command is not found.
887 If an executable file with the name of that command is
888 found, then it is read and executed in the current envi‐
889 ronment. Unlike PATH, the current directory must be rep‐
890 resented explicitly by dot (.) rather than by adjacent
891 colon (:) characters or a beginning or ending colon (:).
892
893
894 HISTCMD The number of the current command in the history file.
895
896
897 HISTEDIT The name for the default editor name for the hist com‐
898 mand.
899
900
901 HISTFILE If this variable is set when the shell is invoked, the
902 value is the pathname of the file that is used to store
903 the command history. See the Command Re-entry section of
904 this manual page.
905
906
907 HISTSIZE If this variable is set when the shell is invoked, then
908 the number of previously entered commands that are acces‐
909 sible by this shell is greater than or equal to this num‐
910 ber. The default is 512.
911
912
913 HOME The default argument (home directory) for the cd command.
914
915 HOME is not set by the shell. HOME is set by login(1).
916
917
918 IFS Internal field separators, normally SPACE, TAB, and NEW‐
919 LINE that are used to separate the results of command
920 substitution or parameter expansion and to separate
921 fields with the built-in command read. The first charac‐
922 ter of the IFS variable is used to separate arguments for
923 the "$*" substitution. See the Quoting section of this
924 manual page.
925
926 Each single occurrence of an IFS character in the string
927 to be split, that is not in the issspace character class,
928 and any adjacent characters in IFS that are in the isss‐
929 pace character class, delimit a field. One or more char‐
930 acters in IFS that belong to the issspace character
931 class, delimit a field. In addition, if the same issspace
932 character appears consecutively inside IFS, this charac‐
933 ter is treated as if it were not in the issspace class,
934 so that if IFS consists of two tab characters, then two
935 adjacent tab characters delimit a null field.
936
937 The shell specifies a default value to IFS.
938
939
940 LANG This variable determines the locale category for any cat‐
941 egory not specifically selected with a variable starting
942 with LC_ or LANG.
943
944
945 LC_ALL This variable overrides the value of the LANG variable
946 and any other LC_ variable.
947
948
949 LC_COLLATE This variable determines the locale category for charac‐
950 ter collation information.
951
952
953 LC_CTYPE This variable determines the locale category for charac‐
954 ter handling functions. It determines the character
955 classes for pattern matching. See the File Name Genera‐
956 tion section of this manual page.
957
958
959 LC_NUMERIC This variable determines the locale category for the dec‐
960 imal point character.
961
962
963 LINES If this variable is set, the value is used to determine
964 the column length for printing select lists. Select lists
965 prints vertically until about two-thirds of LINES lines
966 are filled.
967
968
969 MAIL If this variable is set to the name of a mail file and
970 the MAILPATH variable is not set, then the shell informs
971 the user of arrival of mail in the specified file.
972
973 MAIL is not set by the shell. On some systems, MAIL is
974 set by login(1).
975
976
977 MAILCHECK Specifies how often in seconds the shell checks for
978 changes in the modification time of any of the files
979 specified by the MAILPATH or MAIL variables. The default
980 value is 600 seconds. When the time has elapsed the shell
981 checks before issuing the next prompt.
982
983 The shell specifies a default value to MAILCHECK.
984
985
986 MAILPATH A colon ( : ) separated list of file names. If this vari‐
987 able is set, then the shell informs the user of any modi‐
988 fications to the specified files that have occurred
989 within the last MAILCHECK seconds. Each file name can be
990 followed by a ? and a message that is printed. The mes‐
991 sage undergoes parameter expansion, command substitution,
992 and arithmetic substitution with the variable $_ defined
993 as the name of the file that has changed. The default
994 message is you have mail in $_.
995
996
997 PATH The search path for commands. Except in .profile, users
998 cannot change PATH if executing under rksh93. See the
999 Execution section of this manual page.
1000
1001 The shell specifies a default value to PATH.
1002
1003
1004 PS1 The value of this variable is expanded for parameter
1005 expansion, command substitution, and arithmetic substitu‐
1006 tion to define the primary prompt string which by default
1007 is $. The character ! in the primary prompt string is
1008 replaced by the command number. Two successive occur‐
1009 rences of ! produces a single ! when the prompt string is
1010 printed. See the Command Re-entry section of this manual
1011 page.
1012
1013 The shell specifies a default value to PS1.
1014
1015
1016 PS2 Secondary prompt string, by default, >.
1017
1018 The shell specifies a default value to PS2.
1019
1020
1021 PS3 Selection prompt string used within a select loop, by
1022 default #?.
1023
1024 The shell specifies a default value to PS3.
1025
1026
1027 PS4 The value of this variable is expanded for parameter
1028 evaluation, command substitution, and arithmetic substi‐
1029 tution and precedes each line of an execution trace. By
1030 default, PS4 is +. When PS4 is unset, the execution trace
1031 prompt is also + .
1032
1033 The shell specifies a default value to PS4.
1034
1035
1036 SHELL The pathname of the shell is kept in the environment. At
1037 invocation, if the basename of this variable is rsh,
1038 rksh, rksh93, or krsh, the shell becomes restricted.
1039
1040 SHELL is not set by the shell. On some systems, SHELL is
1041 set by login(1).
1042
1043
1044 TIMEFORMAT The value of this parameter is used as a format string
1045 specifying how the timing information for pipelines pre‐
1046 fixed with the time reserved word should be displayed.
1047 The % character introduces a format sequence that is
1048 expanded to a time value or other information.
1049
1050 The format sequences and their meanings are as follows.
1051
1052 %%
1053
1054 A literal %.
1055
1056
1057 %[p][l]R
1058
1059 The elapsed time in seconds.
1060
1061
1062 %[p][l]U
1063
1064 The number of CPU seconds spent in user mode.
1065
1066
1067 %[p][l]S
1068
1069 The number of CPU seconds spent in system mode.
1070
1071
1072 %P
1073
1074 The CPU percentage, computed as (U + S) / R.
1075
1076 The braces denote optional portions. The optional p is a
1077 digit specifying the precision, the number of fractional
1078 digits after a decimal point. A value of 0 causes no dec‐
1079 imal point or fraction to be output. At most three places
1080 after the decimal point can be displayed. Values of p
1081 greater than 3 are treated as 3. If p is not specified,
1082 the value 3 is used.
1083
1084 The optional l specifies a longer format, including hours
1085 if greater than zero, minutes, and seconds of the form
1086 HHhMMmSS.FFs. The value of p determines whether or not
1087 the fraction is included.
1088
1089 All other characters are output without change and a
1090 trailing NEWLINE is added. If unset, the default value,
1091 $'0eal%2lR0ser%2lU0ys%2lS', is used. If the value is
1092 null, no timing information is displayed.
1093
1094
1095 TMOUT If set to a value greater than zero, TMOUT is the default
1096 time-out value for the read built-in command. The select
1097 compound command terminates after TMOUT seconds when
1098 input is from a terminal. Otherwise, the shell terminates
1099 if a line is not entered within the prescribed number of
1100 seconds while reading from a terminal. The shell can be
1101 compiled with a maximum bound for this value which cannot
1102 be exceeded.
1103
1104 The shell specifies a default value to TMOUT.
1105
1106
1107 VISUAL If the value of this variable matches the pattern
1108 *[Vv][Ii]*, then the vi option is turned on. See Special
1109 Commands. If the value matches the pattern *gmacs* , the
1110 gmacs option is turned on. If the value matches the pat‐
1111 tern *macs*, then the emacs option is turned on. The
1112 value of VISUAL overrides the value of EDITOR.
1113
1114
1115 Field Splitting
1116 After parameter expansion and command substitution, the results of sub‐
1117 stitutions are scanned for the field separator characters (those found
1118 in IFS) and split into distinct fields where such characters are found.
1119 Explicit null fields ("" or '') are retained. Implicit null fields,
1120 those resulting from parameters that have no values or command substi‐
1121 tutions with no output, are removed.
1122
1123
1124 If the braceexpand (-B) option is set, each of the fields resulting
1125 from IFS are checked to see if they contain one or more of the brace
1126 patterns. Valid brace patterns: {*,*}, {l1..l2} , {n1..n2},
1127 {n1..n2%fmt} {n1..n2 ..n3}, or {n1..n2 ..n3%fmt} , where * represents
1128 any character, l1,l2 are letters and n1,n2,n3 are signed numbers and
1129 fmt is a format specified as used by printf. In each case, fields are
1130 created by prepending the characters before the { and appending the
1131 characters after the } to each of the strings generated by the charac‐
1132 ters between the { and }. The resulting fields are checked to see if
1133 they have any brace patterns.
1134
1135
1136 In the first form, a field is created for each string between { and ,,
1137 between , and ,, and between , and }. The string represented by * can
1138 contain embedded matching { and } without quoting. Otherwise, each {
1139 and } with * must be quoted.
1140
1141
1142 In the second form, l1 and l2 must both be either upper case or both be
1143 lower case characters in the C locale. In this case a field is created
1144 for each character from l1 through l2.
1145
1146
1147 In the remaining forms, a field is created for each number starting at
1148 n1. This continues until it reaches n2 and increments n1 by n3. The
1149 cases where n3 is not specified behave as if n3 were 1 if n1<=n2, and
1150 -1 otherwise. In forms which specify %fmt, any format flags, widths and
1151 precisions can be specified and fmt can end in any of the specifiers
1152 cdiouxX. For example, {a,z}{1..5..3%02d}{b..c}x expands to the 8
1153 fields, a01bx, a01cx, a04bx, a04cx, z01bx, z01cx, z04bx, and z4cx.
1154
1155 File Name Generation
1156 Following splitting, each field is scanned for the characters *, ?, (,
1157 and [, unless the -f option has been set. If one of these characters
1158 appears, then the word is regarded as a pattern.
1159
1160
1161 Each file name component that contains any pattern character is
1162 replaced with a lexicographically sorted set of names that matches the
1163 pattern from that directory. If no file name is found that matches the
1164 pattern, then that component of the file name is left unchanged unless
1165 the pattern is prefixed with ~(N) in which case it is removed. If FIG‐
1166 NORE is set, then each file name component that matches the pattern
1167 defined by the value of FIGNORE is ignored when generating the matching
1168 file names. The names . and .. are also ignored. If FIGNORE is not set,
1169 the character . at the start of each file name component is ignored
1170 unless the first character of the pattern corresponding to this compo‐
1171 nent is the character . itself. For other uses of pattern matching the
1172 / and . are not specially treated.
1173
1174 * Match any string, including the null string. When used for
1175 file name expansion, if the globstar option is on, two adja‐
1176 cent *s by themselves match all files and zero or more
1177 directories and subdirectories. If the two adjacent *s are
1178 followed by a /, only directories and subdirectories match.
1179
1180
1181 ? Matches any single character.
1182
1183
1184 [...] Match any one of the enclosed characters. A pair of charac‐
1185 ters separated by - matches any character lexically between
1186 the pair, inclusive. If the first character following the
1187 opening [ is a !, any character not enclosed is matched. A -
1188 can be included in the character set by putting it as the
1189 first or last character. Within [ and ], character classes
1190 can be specified with the syntax [:class:] where class is
1191 one of the following classes defined in the ANSI-C standard:
1192
1193 alnum alpha blank cntrl digit graph
1194 lower print punct space upper
1195 word xdigit
1196
1197
1198 word is equivalent to alnum plus the character _. Within [
1199 and ], an equivalence class can be specified with the syntax
1200 [=c=] which matches all characters with the same primary
1201 collation weight (as defined by the current locale) as the
1202 character c. Within [ and ], [.symbol.] matches the collat‐
1203 ing symbol symbol.
1204
1205
1206
1207 A pattern-list is a list of one or more patterns separated from each
1208 other with an & or |. An & signifies that all patterns must be matched
1209 whereas | requires that only one pattern be matched. Composite patterns
1210 can be formed with one or more of the following sub-patterns:
1211
1212 ?(pattern-list) Optionally matches any one of the specified pat‐
1213 terns.
1214
1215
1216 *(pattern-list) Matches zero or more occurrences of the specified
1217 patterns.
1218
1219
1220 +(pattern-list) Matches one or more occurrences of the specified
1221 patterns.
1222
1223
1224 {n(pattern-list) Matches n occurrences of the specified patterns.
1225
1226
1227 {m,n(pattern-list) Matches from m to n occurrences of the specified
1228 patterns. If m is omitted, 0 is used. If n is
1229 omitted at least m occurrences are matched.
1230
1231
1232 @(pattern-list) Matches exactly one of the specified patterns.
1233
1234
1235 !(pattern-list) Matches anything except one of the specified pat‐
1236 terns.
1237
1238
1239
1240 By default, each pattern, or sub-pattern matches the longest string
1241 possible consistent with generating the longest overall match. If more
1242 than one match is possible, the one starting closest to the beginning
1243 of the string is chosen. However, for each of the compound patterns a -
1244 can be inserted in front of the ( to cause the shortest match to the
1245 specified pattern-list to be used.
1246
1247
1248 When pattern-list is contained within parentheses, the backslash char‐
1249 acter \ is treated specially even when inside a character class. All
1250 ANSI-C character escapes are recognized and match the specified charac‐
1251 ter. In addition the following escape sequences are recognized:
1252
1253 \d Matches any character in the digit class.
1254
1255
1256 \D Matches any character not in the digit class.
1257
1258
1259 \s Matches any character in the space class.
1260
1261
1262 \S Matches any character not in the space class.
1263
1264
1265 \w Matches any character in the word class.
1266
1267
1268 \W Matches any character not in the word class.
1269
1270
1271
1272 A pattern of the form %(pattern-pairs) is a sub-pattern that can be
1273 used to match nested character expressions. Each pattern-pair is a two
1274 character sequence which cannot contain & or |. The first pattern-pair
1275 specifies the starting and ending characters for the match. Each subse‐
1276 quent pattern-pair represents the beginning and ending characters of a
1277 nested group that is skipped over when counting starting and ending
1278 character matches. The behavior is unspecified when the first character
1279 of a pattern-pair is alphanumeric except for the following:
1280
1281 D Causes the ending character to terminate the search for this pat‐
1282 tern without finding a match.
1283
1284
1285 E Causes the ending character to be interpreted as an escape charac‐
1286 ter.
1287
1288
1289 L Causes the ending character to be interpreted as a quote character
1290 causing all characters to be ignored when looking for a match.
1291
1292
1293 Q Causes the ending character to be interpreted as a quote character
1294 causing all characters other than any escape character to be
1295 ignored when looking for a match.
1296
1297
1298
1299 %({}Q"E\), matches characters starting at { until the matching } is
1300 found not counting any { or } that is inside a double quoted string or
1301 preceded by the escape character \. Without the {} this pattern matches
1302 any C language string.
1303
1304
1305 Each sub-pattern in a composite pattern is numbered, starting at 1, by
1306 the location of the ( within the pattern. The sequence \n, where n is a
1307 single digit and \n comes after the nth. sub-pattern, matches the same
1308 string as the sub-pattern itself.
1309
1310
1311 A pattern can contain sub-patterns of the form ~(options:pattern-list),
1312 where either options or :pattern-list can be omitted. Unlike the other
1313 compound patterns, these sub-patterns are not counted in the numbered
1314 sub-patterns. If options is present, it can consist of one or more of
1315 the following:
1316
1317 + Enable the following options. This is the default.
1318
1319
1320 - Disable the following options.
1321
1322
1323 E The remainder of the pattern uses extended regular expression syn‐
1324 tax like the egrep(1) command.
1325
1326
1327 F The remainder of the pattern uses fgrep(1) expression syntax.
1328
1329
1330 g File the longest match (greedy).
1331
1332 This is the default.
1333
1334
1335 G The remainder of the pattern uses basic regular expression syntax
1336 like the grep(1) command.
1337
1338
1339 i Treat the match as case insensitive.
1340
1341
1342 K The remainder of the pattern uses shell pattern syntax.
1343
1344 This is the default.
1345
1346
1347 l Left anchor the pattern.
1348
1349 This is the default for K style patterns.
1350
1351
1352 N This is ignored. However, when it is the first letter and is used
1353 with file name generation, and no matches occur, the file pattern
1354 expands to the empty string.
1355
1356
1357 r Right anchor the pattern.
1358
1359 This is the default for K style patterns.
1360
1361
1362
1363 If both options and :pattern-list are specified, then the options apply
1364 only to pattern-list. Otherwise, these options remain in effect until
1365 they are disabled by a subsequent ~(...) or at the end of the sub-pat‐
1366 tern containing ~(...).
1367
1368 Quoting
1369 Each of the metacharacters listed in the Definitions has a special
1370 meaning to the shell.
1371
1372 g File the longest match (greedy). This is the default.
1373
1374
1375 i Treat the match as case insensitive.
1376
1377
1378
1379 If both options and :pattern-list are specified, then the options apply
1380 only to pattern-list. Otherwise, the options remain in effect until
1381 they are disabled by a subsequent ~(...) or at the end of the sub-pat‐
1382 tern containing ~(...).
1383
1384
1385 Each of the metacharacters listed in the Definitions section of this
1386 manual page has a special meaning to the shell and causes termination
1387 of a word unless quoted. A character can be quoted, that is, made to
1388 stand for itself, by preceding it with a backslash (\). The pair \NEW‐
1389 LINE is removed. All characters enclosed between a pair of single quote
1390 marks ('') that is not preceded by a $ are quoted. A single quote can‐
1391 not appear within the single quotes. A single quoted string preceded by
1392 an unquoted $ is processed as an ANSI-C string except for the follow‐
1393 ing:
1394
1395 \0 Causes the remainder of the string to be ignored.
1396
1397
1398 \cx Expands to the character CTRL-x.
1399
1400
1401 \C[.name.] Expands to the collating element name.
1402
1403
1404 \e Equivalent to the escape character (ASCII 033),
1405
1406
1407 \E Equivalent to the escape character (ASCII 033),
1408
1409
1410
1411 Inside double quote marks (""), parameter and command substitution
1412 occur and \ quotes the characters \, `, ", and $. A $ in front of a
1413 double quoted string is ignored in the C or POSIX locale, and might
1414 cause the string to be replaced by a locale specific string otherwise.
1415 The meaning of $* and $@ is identical when not quoted or when used as a
1416 variable assignment value or as a file name. However, when used as a
1417 command argument, "$*" is equivalent to "$1d$2d...", where d is the
1418 first character of the IFS variable, whereas "$@" is equivalent to "$1"
1419 "$2" .... Inside grave quote marks (``), \fR quotes the characters \,
1420 `, and $. If the grave quotes occur within double quotes, then \ also
1421 quotes the character ".
1422
1423
1424 The special meaning of reserved words or aliases can be removed by
1425 quoting any character of the reserved word. The recognition of function
1426 names or built-in command names cannot be altered by quoting them.
1427
1428 Arithmetic Evaluation
1429 The shell performs arithmetic evaluation for arithmetic substitution,
1430 to evaluate an arithmetic command, to evaluate an indexed array sub‐
1431 script, and to evaluate arguments to the built-in commands shift and
1432 let. Arithmetic evaluation is also performed on argument operands of
1433 the built-in command printf that correspond to numeric format speci‐
1434 fiers in the format operand. See printf(1). Evaluations are performed
1435 using double precision floating point arithmetic or long double preci‐
1436 sion floating point for systems that provide this data type. Floating
1437 point constants follow the ANSI-C programming language floating point
1438 conventions. Integer constants follow the ANSI-C programming language
1439 integer constant conventions although only single byte character con‐
1440 stants are recognized and character casts are not recognized. Constants
1441 can be of the form [base#]n where base is a decimal number between two
1442 and sixty-four representing the arithmetic base and n is a number in
1443 that base. The digits greater than 9 are represented by the lower case
1444 letters, the upper case letters, @, and _ respectively. For bases less
1445 than or equal to 36, upper and lower case characters can be used inter‐
1446 changeably.
1447
1448
1449 An arithmetic expression uses the same syntax, precedence, and associa‐
1450 tivity of expression as the C language. All the C language operators
1451 that apply to floating point quantities can be used. In addition, the
1452 operator ** can be used for exponentiation. It has higher precedence
1453 than multiplication and is left associative. When the value of an
1454 arithmetic variable or subexpression can be represented as a long inte‐
1455 ger, all C language integer arithmetic operations can be performed.
1456 Variables can be referenced by name within an arithmetic expression
1457 without using the parameter expansion syntax. When a variable is refer‐
1458 enced, its value is evaluated as an arithmetic expression.
1459
1460
1461 Any of the following math library functions that are in the C math
1462 library can be used within an arithmetic expression:
1463
1464 abs acos acosh asin asinh atan atan2 atanh cbrt
1465 copysign cos cosh erf erfc exp exp2 expm1 fabs
1466 fdim finite floor fma fmax fmod hypot ilogb
1467 int isinf isnan lgamma log log2 logb
1468 nearbyint nextafter nexttoward pow remainder
1469 rint round sin sinh sqrt tan tanh tgamma trunc
1470
1471
1472
1473
1474 An internal representation of a variable as a double precision floating
1475 point can be specified with the -E [n] or -F [n] option of the typeset
1476 special built-in command. The -E option causes the expansion of the
1477 value to be represented using scientific notation when it is expanded.
1478 The optional option argument n defines the number of significant fig‐
1479 ures. The -F option causes the expansion to be represented as a float‐
1480 ing decimal number when it is expanded. The optional option argument n
1481 defines the number of places after the decimal point in this case.
1482
1483
1484 An internal integer representation of a variable can be specified with
1485 the -i [n] option of the typeset special built-in command. The optional
1486 option argument n specifies an arithmetic base to be used when expand‐
1487 ing the variable. If you do not specify an arithmetic base, base 10 is
1488 used.
1489
1490
1491 Arithmetic evaluation is performed on the value of each assignment to a
1492 variable with the -E, -F, or -i option. Assigning a floating point num‐
1493 ber to a variable whose type is an integer causes the fractional part
1494 to be truncated.
1495
1496 Prompting
1497 When used interactively, the shell prompts with the value of PS1 after
1498 expanding it for parameter expansion, command substitution, and arith‐
1499 metic substitution, before reading a command. In addition, each single
1500 ! in the prompt is replaced by the command number. A !! is required to
1501 place ! in the prompt. If at any time a NEWLINE is typed and further
1502 input is needed to complete a command, then the secondary prompt, that
1503 is, the value of PS2, is issued.
1504
1505 Conditional Expressions
1506 A conditional expression is used with the [[ compound command to test
1507 attributes of files and to compare strings. Field splitting and file
1508 name generation are not performed on the words between [[ and ]].
1509
1510
1511 Each expression can be constructed from one or more of the following
1512 unary or binary expressions:
1513
1514 -a file True, if file exists.
1515
1516 This option is the same as -e. This option is
1517 obsolete.
1518
1519
1520 -b file True, if file exists and is a block special file.
1521
1522
1523 -c file True, if file exists and is a character special
1524 file.
1525
1526
1527 -d file True, if file exists and is a directory.
1528
1529
1530 -e file True, if file exists.
1531
1532
1533 -f file True, if file exists and is an ordinary file.
1534
1535
1536 -g file True, if file exists and it has its setgid bit
1537 set.
1538
1539
1540 -G file True, if file exists and its group matches the
1541 effective group id of this process.
1542
1543
1544 -h file True, if file exists and is a symbolic link.
1545
1546
1547 -k file True, if file exists and it has its sticky bit
1548 set.
1549
1550
1551 -L file True, if file exists and is a symbolic link.
1552
1553
1554 -n string True, if length of string is non-zero.
1555
1556
1557 -N file True, if file exists and the modification time is
1558 greater than the last access time.
1559
1560
1561 -o option True, if option named option is on.
1562
1563
1564 -o ?option True, if option named option is a valid option
1565 name.
1566
1567
1568 -O file True, if file exists and is owned by the effective
1569 user id of this process.
1570
1571
1572 -p file True, if file exists and is a FIFO special file or
1573 a pipe.
1574
1575
1576 -r file True, if file exists and is readable by current
1577 process.
1578
1579
1580 -s file True, if file exists and has size greater than
1581 zero.
1582
1583
1584 -S file True, if file exists and is a socket.
1585
1586
1587 -t fildes True, if file descriptor number fildes is open and
1588 associated with a terminal device.
1589
1590
1591 -u file True, if file exists and it has its setuid bit
1592 set.
1593
1594
1595 -w file True, if file exists and is writable by current
1596 process.
1597
1598
1599 -x file True, if file exists and is executable by current
1600 process. If file exists and is a directory, then
1601 true if the current process has permission to
1602 search in the directory.
1603
1604
1605 -z string True, if length of string is zero.
1606
1607
1608 file1 -ef file2 True, if file1 and file2 exist and refer to the
1609 same file.
1610
1611
1612 file1 -nt file2 True, if file1 exists and file2 does not, or file1
1613 is newer than file2.
1614
1615
1616 file1 -ot file2 True, if file2 exists and file1 does not, or file1
1617 is older than file2.
1618
1619
1620 string True, if string is not null.
1621
1622
1623 string == pattern True, if string matches pattern. Any part of pat‐
1624 tern can be quoted to cause it to be matched as a
1625 string. With a successful match to pattern, the
1626 .sh.match array variable contains the match and
1627 sub-pattern matches.
1628
1629
1630 string = pattern Same as ==, but is obsolete.
1631
1632
1633 string != pattern True, if string does not match pattern. When the
1634 string matches the pattern the .sh.match array
1635 variable contains the match and sub-pattern
1636 matches.
1637
1638
1639 string =~ ere True if string matches the pattern ~(E)ere where
1640 ere is an extended regular expression.
1641
1642
1643 string1 < string2 True, if string1 comes before string2 based on
1644 ASCII value of their characters.
1645
1646
1647 string1 > string2 True, if string1 comes after string2 based on
1648 ASCII value of their characters.
1649
1650
1651
1652 In each of the following expressions, if file is of the form /dev/fd/n,
1653 where n is an integer, the test is applied to the open file whose
1654 descriptor number is n. The following obsolete arithmetic comparisons
1655 are supported:
1656
1657 exp1 -eq exp2 True, if exp1 is equal to exp2.
1658
1659
1660 exp1 -ge exp2 True, if exp1 is greater than or equal to exp2.
1661
1662
1663 exp1 -gt exp2 True, if exp1 is greater than exp2.
1664
1665
1666 exp1 -le exp2 True, if exp1 is less than or equal to exp2.
1667
1668
1669 exp1 -lt exp2 True, if exp1 is less than exp2.
1670
1671
1672 exp1 -ne exp2 True, if exp1 is not equal to exp2.
1673
1674
1675
1676 A compound expression can be constructed from these primitives by using
1677 any of the following, listed in decreasing order of precedence:
1678
1679 (expression) True, if expression is true. Used to
1680 group expressions.
1681
1682
1683 ! expression True, if expression is false.
1684
1685
1686 expression1 && expression2 True, if expression1 and expression2 are
1687 both true.
1688
1689
1690 expression1 || expression2 True, if either expression1 or expres‐
1691 sion2 is true.
1692
1693
1694 Input and Output
1695 Before a command is executed, its input and output can be redirected
1696 using a special notation interpreted by the shell. The following can
1697 appear anywhere in a simple command or can precede or follow a command
1698 and are not passed on to the invoked command. Command substitution,
1699 parameter expansion, and arithmetic substitution occur before word or
1700 digit is used except as noted in this section. File name generation
1701 occurs only if the shell is interactive and the pattern matches a sin‐
1702 gle file. Field splitting is not performed.
1703
1704
1705 In each of the following redirections, if file is of the form
1706 /dev/sctp/host/port, /dev/tcp/host/port, or /dev/udp/host/port, where
1707 host is a hostname or host address, and port is a service specified by
1708 name or an integer port number, then the redirection attempts to make a
1709 tcp, sctp or udp connection to the corresponding socket.
1710
1711
1712 No intervening space is allowed between the characters of redirection
1713 operators.
1714
1715 <word Use file word as standard input (file descriptor 0).
1716
1717
1718 >word Use file word as standard output (file descriptor 1). If
1719 the file does not exist then it is created. If the file
1720 exists, and the noclobber option is on, this causes an
1721 error. Otherwise, it is truncated to zero length.
1722
1723
1724 >|word Same as >, except that it overrides the noclobber option.
1725
1726
1727 >>word Use file word as standard output. If the file exists,
1728 then output is appended to it (by first seeking to the
1729 end-of-file). Otherwise, the file is created.
1730
1731
1732 <>word Open file word for reading and writing as standard input.
1733
1734
1735 <<[-]word The shell input is read up to a line that is the same as
1736 word after any quoting has been removed, or to an end-of-
1737 file. No parameter substitution, command substitution,
1738 arithmetic substitution or file name generation is per‐
1739 formed on word. The resulting document, called a here-
1740 document, becomes the standard input. If any character of
1741 word is quoted, then no interpretation is placed upon the
1742 characters of the document. Otherwise, parameter expan‐
1743 sion, command substitution, and arithmetic substitution
1744 occur, \NEWLINE is ignored, and \ must be used to quote
1745 the characters \, $, `. If - is appended to <<, then all
1746 leading tabs are stripped from word and from the docu‐
1747 ment. If # is appended to <<, then leading SPACEs and
1748 TABs are stripped off the first line of the document and
1749 up to an equivalent indentation is stripped from the
1750 remaining lines and from word. A tab stop is assumed to
1751 occur at every 8 columns for the purposes of determining
1752 the indentation.
1753
1754
1755 <<<word A short form of here document in which word becomes the
1756 contents of the here-document after any parameter expan‐
1757 sion, command substitution, and arithmetic substitution
1758 occur.
1759
1760
1761 <&digit The standard input is duplicated from file descriptor
1762 digit, and similarly for the standard output using
1763 >&digit. See dup(2).
1764
1765
1766 <&digit- The file descriptor specified by digit is moved to stan‐
1767 dard input. Similarly for the standard output using
1768 >&digit-.
1769
1770
1771 <&- The standard input is closed. Similarly for the standard
1772 output using >&-.
1773
1774
1775 <&p The input from the co-process is moved to standard input.
1776
1777
1778 >&p The output to the co-process is moved to standard output.
1779
1780
1781 <#((expr)) Evaluate arithmetic expression expr and position file
1782 descriptor 0 to the resulting value bytes from the start
1783 of the file. The variables CUR and EOF evaluate to the
1784 current offset and end-of-file offset respectively when
1785 evaluating expr.
1786
1787
1788 >#((expr)) The same as <# except applies to file descriptor 1.
1789
1790
1791 <#pattern Seek forward to the beginning of the next line containing
1792 pattern.
1793
1794
1795 <##pattern The same as <#, except that the portion of the file that
1796 is skipped is copied to standard output.
1797
1798
1799
1800 If one of the redirection operators is preceded by a digit, with no
1801 intervening space, then the file descriptor number referred to is that
1802 specified by the digit (instead of the default 0 or 1). If one of the
1803 redirection operators other than >&- and the ># and <# forms, is pre‐
1804 ceded by {varname} with no intervening space, then a file descriptor
1805 number > 10 is selected by the shell and stored in the variable var‐
1806 name. If >&- or the any of the ># and <# forms is preceded by {varname}
1807 the value of varname defines the file descriptor to close or position.
1808 For example:
1809
1810 ... 2>&1
1811
1812
1813
1814
1815 means file descriptor 2 is to be opened for writing as a duplicate of
1816 file descriptor 1 and
1817
1818 exec [n]<file
1819
1820
1821
1822
1823 means open file for reading and store the file descriptor number in
1824 variable n. The order in which redirections are specified is signifi‐
1825 cant. The shell evaluates each redirection in terms of the
1826 (file_descriptor, file) association at the time of evaluation. For
1827 example:
1828
1829 ... 1>fname 2>&1
1830
1831
1832
1833
1834 first associates file descriptor 1 with file fname. It then associates
1835 file descriptor 2 with the file associated with file descriptor 1, that
1836 is, fname. If the order of redirections were reversed, file descriptor
1837 2 would be associated with the terminal (assuming file descriptor 1 had
1838 been) and then file descriptor 1 would be associated with file fname.
1839 If a command is followed by & and job control is not active, the
1840 default standard input for the command is the empty file /dev/null.
1841 Otherwise, the environment for the execution of a command contains the
1842 file descriptors of the invoking shell as modified by input and output
1843 specifications.
1844
1845 Environment
1846 The environment is a list of name-value pairs that is passed to an exe‐
1847 cuted program in the same way as a normal argument list. See envi‐
1848 ron(5).
1849
1850
1851 The names must be identifiers and the values are character strings. The
1852 shell interacts with the environment in several ways. On invocation,
1853 the shell scans the environment and creates a variable for each name
1854 found, giving it the corresponding value and attributes and marking it
1855 export. Executed commands inherit the environment. If the user modifies
1856 the values of these variables or creates new ones, using the export or
1857 typeset -x commands, they become part of the environment. The environ‐
1858 ment seen by any executed command is thus composed of any name-value
1859 pairs originally inherited by the shell, whose values can be modified
1860 by the current shell, plus any additions which must be noted in export
1861 or typeset -x commands. The environment for any simple-command or func‐
1862 tion can be augmented by prefixing it with one or more variable assign‐
1863 ments. A variable assignment argument is a word of the form identi‐
1864 fier=value. Thus:
1865
1866 TERM=450 cmd args
1867
1868
1869
1870
1871 and
1872
1873 (export TERM; TERM=450; cmd args)
1874
1875
1876
1877
1878 are equivalent (as far as the execution of cmd is concerned except for
1879 special built-in commands listed in the Built-Ins section, those that
1880 are preceded with a dagger. If the obsolete -k option is set, all vari‐
1881 able assignment arguments are placed in the environment, even if they
1882 occur after the command name.
1883
1884
1885 The following example first prints a=b c and then c:
1886
1887 echo a=b c
1888 set -k
1889 echo a=b c
1890
1891
1892
1893
1894 This feature is intended for use with scripts written for early ver‐
1895 sions of the shell and its use in new scripts is strongly discouraged.
1896
1897 Functions
1898 For historical reasons, there are two ways to define functions, the
1899 name() syntax and the function name syntax. These are described in the
1900 Commands section of this manual page.
1901
1902
1903 Shell functions are read in and stored internally. Alias names are
1904 resolved when the function is read. Functions are executed like com‐
1905 mands with the arguments passed as positional parameters. See the Exe‐
1906 cution section of this manual page for details.
1907
1908
1909 Functions defined by the function name syntax and called by name exe‐
1910 cute in the same process as the caller and share all files and present
1911 working directory with the caller. Traps caught by the caller are reset
1912 to their default action inside the function. A trap condition that is
1913 not caught or ignored by the function causes the function to terminate
1914 and the condition to be passed on to the caller. A trap on EXIT set
1915 inside a function is executed in the environment of the caller after
1916 the function completes. Ordinarily, variables are shared between the
1917 calling program and the function. However, the typeset special built-in
1918 command used within a function defines local variables whose scope
1919 includes the current function. They can be passed to functions that
1920 they call in the variable assignment list that precedes the call or as
1921 arguments passed as name references. Errors within functions return
1922 control to the caller.
1923
1924
1925 Functions defined with the name() syntax and functions defined with the
1926 function name syntax that are invoked with the . special built-in are
1927 executed in the caller's environment and share all variables and traps
1928 with the caller. Errors within these function executions cause the
1929 script that contains them to abort.
1930
1931
1932 The special built-in command return is used to return from function
1933 calls.
1934
1935
1936 Function names can be listed with the -f or +f option of the typeset
1937 special built-in command. The text of functions, when available, is
1938 also listed with -f. Functions can be undefined with the -f option of
1939 the unset special built-in command.
1940
1941
1942 Ordinarily, functions are unset when the shell executes a shell script.
1943 Functions that need to be defined across separate invocations of the
1944 shell should be placed in a directory and the FPATH variable should
1945 contain the name of this directory. They can also be specified in the
1946 ENV file.
1947
1948 Discipline Functions
1949 Each variable can have zero or more discipline functions associated
1950 with it. The shell initially understands the discipline names get, set,
1951 append, and unset but on most systems others can be added at run time
1952 via the C programming interface extension provided by the builtin
1953 built-in utility. If the get discipline is defined for a variable, it
1954 is invoked whenever the specified variable is referenced. If the vari‐
1955 able .sh.value is assigned a value inside the discipline function, the
1956 referenced variable is evaluated to this value instead. If the set dis‐
1957 cipline is defined for a variable, it is invoked whenever the specified
1958 variable is assigned a value. If the append discipline is defined for a
1959 variable, it is invoked whenever a value is appended to the specified
1960 variable. The variable .sh.value is specified the value of the variable
1961 before invoking the discipline, and the variable is assigned the value
1962 of .sh.value after the discipline completes. If .sh.value is unset
1963 inside the discipline, then that value is unchanged. If the unset dis‐
1964 cipline is defined for a variable, it is invoked whenever the specified
1965 variable is unset. The variable is not unset unless it is unset explic‐
1966 itly from within this discipline function.
1967
1968
1969 The variable .sh.name contains the name of the variable for which the
1970 discipline function is called, .sh.subscript is the subscript of the
1971 variable, and .sh.value contains the value being assigned inside the
1972 set discipline function. For the set discipline, changing .sh.value
1973 changes the value that gets assigned.
1974
1975 Jobs
1976 If the monitor option of the set command is turned on, an interactive
1977 shell associates a job with each pipeline. It keeps a table of current
1978 jobs, printed by the jobs command, and assigns them small integer num‐
1979 bers. When a job is started asynchronously with &, the shell prints a
1980 line which looks like:
1981
1982 [1] 1234
1983
1984
1985
1986
1987 indicating that the job which was started asynchronously was job number
1988 1 and had one (top-level) process, whose process id was 1234.
1989
1990
1991 If you are running a job and wish to stop it, CTRL-z sends a STOP sig‐
1992 nal to the current job. The shell normally displays a message that the
1993 job has been stopped, and displays another prompt. You can then manipu‐
1994 late the state of this job, putting it in the background with the bg
1995 command, or run some other commands and then eventually bring the job
1996 back into the foreground with the foreground command fg. A CTRL-z takes
1997 effect immediately and is like an interrupt in that pending output and
1998 unread input are discarded when it is typed.
1999
2000
2001 A job being run in the background stops if it tries to read from the
2002 terminal. Background jobs are normally allowed to produce output, but
2003 this can be disabled by giving the command sttytostop. If you set this
2004 tty option, then background jobs stop when they try to produce output
2005 like they do when they try to read input.
2006
2007
2008 There are several ways to refer to jobs in the shell. A job can be
2009 referred to by the process id of any process of the job or by one of
2010 the following:
2011
2012 %number The job with the specified number.
2013
2014
2015 %string Any job whose command line begins with string.
2016
2017
2018 %?string Any job whose command line contains string.
2019
2020
2021 %% Current job.
2022
2023
2024 %+ Equivalent to %%.
2025
2026
2027 %- Previous job.
2028
2029
2030
2031 The shell learns immediately whenever a process changes state. It nor‐
2032 mally informs you whenever a job becomes blocked so that no further
2033 progress is possible, but only just before it prints a prompt. This is
2034 done so that it does not otherwise disturb your work. The notify option
2035 of the set command causes the shell to print these job change messages
2036 as soon as they occur.
2037
2038
2039 When the monitor option is on, each background job that completes trig‐
2040 gers any trap set for CHLD.
2041
2042
2043 When you try to leave the shell while jobs are running or stopped, you
2044 are warned that You have stopped(running) jobs. You can use the jobs
2045 command to see what they are. If you immediately try to exit again, the
2046 shell does not warn you a second time, and the stopped jobs are termi‐
2047 nated. When a login shell receives a HUP signal, it sends a HUP signal
2048 to each job that has not been disowned with the disown built-in com‐
2049 mand.
2050
2051 Signals
2052 The INT and QUIT signals for an invoked command are ignored if the com‐
2053 mand is followed by & and the monitor option is not active. Otherwise,
2054 signals have the values inherited by the shell from its parent. See the
2055 trap built-in command.
2056
2057 Execution
2058 Each time a command is read, the substitutions are carried out. If the
2059 command name matches one of the ones in the Special Built-in Commands
2060 section of this manual page, it is executed within the current shell
2061 process. Next, the command name is checked to see if it matches a user
2062 defined function. If it does, the positional parameters are saved and
2063 then reset to the arguments of the function call. A function is also
2064 executed in the current shell process. When the function completes or
2065 issues a return, the positional parameter list is restored. For func‐
2066 tions defined with the function name syntax, any trap set on EXIT
2067 within the function is executed. The exit value of a function is the
2068 value of the last command executed. If a command name is not a special
2069 built-in command or a user defined function, but it is one of the
2070 built-in commands, it is executed in the current shell process.
2071
2072
2073 The shell variable PATH defines the search path for the directory con‐
2074 taining the command. Alternative directory names are separated by a
2075 colon (:). The default path is /bin:/usr/bin:, specifying /bin,
2076 /usr/bin, and the current directory in that order. The current direc‐
2077 tory can be specified by two or more adjacent colons, or by a colon at
2078 the beginning or end of the path list. If the command name contains a
2079 slash (/), the search path is not used. Otherwise, each directory in
2080 the path is searched for an executable file of the specified name that
2081 is not a directory. If found, and if the shell determines that there is
2082 a built-in version of a command corresponding to a specified pathname,
2083 this built-in is invoked in the current process. If found, and this
2084 directory is also contained in the value of the FPATH variable, then
2085 this file is loaded into the current shell environment as if it were
2086 the argument to the . command except that only preset aliases are
2087 expanded, and a function of the specified name is executed as described
2088 in this manual page. If not found, and the file .paths is found, and
2089 this file contains a line of the form FPATH=path where path is an
2090 existing directory, and this directory contains a file of the specified
2091 name, then this file is loaded into the current shell environment as if
2092 it were the argument to the . special built-in command and a function
2093 of the specified name is executed. Otherwise, if found, a process is
2094 created and an attempt is made to execute the command using exec(2).
2095
2096
2097 When an executable is found, the directory where it is found in is
2098 searched for a file named .paths. If this file is found and it contains
2099 a line of the form BUILTIN_LIB=value, the library named by value is
2100 searched for as if it were an option argument to builtin -f, and if it
2101 contains a built-in of the specified name this is executed instead of a
2102 command by this name. Otherwise, if this file is found and it contains
2103 a line of the form name=value in the first or second line, then the
2104 environment variable name is modified by prepending the directory spec‐
2105 ified by value to the directory list. If value is not an absolute
2106 directory, then it specifies a directory relative to the directory that
2107 the executable was found. If the environment variable name does not
2108 already exist it is added to the environment list for the specified
2109 command.
2110
2111
2112 If the file has execute permission but is not an a.out file, it is
2113 assumed to be a file containing shell commands. A separate shell is
2114 spawned to read it. All non-exported variables are removed in this
2115 case. If the shell command file doesn't have read permission, and/or if
2116 the setuid and setgid bits are set on the file, then the shell executes
2117 an agent whose job it is to set up the permissions and execute the
2118 shell with the shell command file passed down as an open file. A paren‐
2119 thesized command is executed in a sub-shell without removing non-
2120 exported variables.
2121
2122 Command Re-entry
2123 The text of the last HISTSIZE (default 512) commands entered from a
2124 terminal device is saved in a history file. The file $HOME/.sh_history
2125 is used if the HISTFILE variable is not set or if the file it names is
2126 not writable. A shell can access the commands of all interactive shells
2127 which use the same named HISTFILE. The built-in command hist is used to
2128 list or edit a portion of this file. The portion of the file to be
2129 edited or listed can be selected by number or by giving the first char‐
2130 acter or characters of the command. A single command or range of com‐
2131 mands can be specified. If you do not specify an editor program as an
2132 argument to hist then the value of the variable HISTEDIT is used. If
2133 HISTEDIT is unset, the obsolete variable FCEDIT is used. If FCEDIT is
2134 not defined, then /bin/ed is used. The edited commands are printed and
2135 executed again upon leaving the editor unless you quit without writing.
2136 The -s option (and in obsolete versions, the editor name -) is used to
2137 skip the editing phase and to re-execute the command. In this case a
2138 substitution parameter of the form old=newcan be used to modify the
2139 command before execution. For example, with the preset alias r, which
2140 is aliased to 'hist -s', typing `r bad=good c' re-executes the most
2141 recent command which starts with the letter c, replacing the first
2142 occurrence of the string bad with the string good.
2143
2144 Inline Editing Options
2145 Normally, each command line entered from a terminal device is simply
2146 typed followed by a NEWLINE (RETURN or LINE FEED). If either the emacs,
2147 gmacs, or vi option is active, the user can edit the command line. To
2148 be in either of these edit modes set the corresponding option. An edit‐
2149 ing option is automatically selected each time the VISUAL or EDITOR
2150 variable is assigned a value ending in either of these option names.
2151
2152
2153 The editing features require that the user's terminal accept RETURN as
2154 carriage return without line feed and that a SPACE must overwrite the
2155 current character on the screen.
2156
2157
2158 Unless the multiline option is on, the editing modes implement a con‐
2159 cept where the user is looking through a window at the current line.
2160 The window width is the value of COLUMNS if it is defined, otherwise
2161 80. If the window width is too small to display the prompt and leave at
2162 least 8 columns to enter input, the prompt is truncated from the left.
2163 If the line is longer than the window width minus two, a mark is dis‐
2164 played at the end of the window to notify the user. As the cursor moves
2165 and reaches the window boundaries the window is centered about the cur‐
2166 sor. The mark is a > (<, *) if the line extends on the right , left, or
2167 both sides of the window.
2168
2169
2170 The search commands in each edit mode provide access to the history
2171 file. Only strings are matched, not patterns, although a leading ^ in
2172 the string restricts the match to begin at the first character in the
2173 line.
2174
2175
2176 Each of the edit modes has an operation to list the files or commands
2177 that match a partially entered word. When applied to the first word on
2178 the line, or the first word after a ;, |, &, or (, and the word does
2179 not begin with ~ or contain a /, the list of aliases, functions, and
2180 executable commands defined by the PATH variable that could match the
2181 partial word is displayed. Otherwise, the list of files that match the
2182 specified word is displayed. If the partially entered word does not
2183 contain any file expansion characters, a * is appended before generat‐
2184 ing these lists. After displaying the generated list, the input line is
2185 redrawn. These operations are called command name listing and file name
2186 listing, respectively. There are additional operations, referred to as
2187 command name completion and file name completion, which compute the
2188 list of matching commands or files, but instead of printing the list,
2189 replace the current word with a complete or partial match. For file
2190 name completion, if the match is unique, a / is appended if the file is
2191 a directory and a space is appended if the file is not a directory.
2192 Otherwise, the longest common prefix for all the matching files
2193 replaces the word. For command name completion, only the portion of the
2194 file names after the last / are used to find the longest command pre‐
2195 fix. If only a single name matches this prefix, then the word is
2196 replaced with the command name followed by a space. When using a TAB
2197 for completion that does not yield a unique match, a subsequent TAB
2198 provides a numbered list of matching alternatives. A specific selection
2199 can be made by entering the selection number followed by a TAB.
2200
2201 Key Bindings
2202 The KEYBD trap can be used to intercept keys as they are typed and
2203 change the characters that are actually seen by the shell. This trap is
2204 executed after each character (or sequence of characters when the first
2205 character is ESC) is entered while reading from a terminal.
2206
2207
2208 The variable .sh.edchar contains the character or character sequence
2209 which generated the trap. Changing the value of .sh.edchar in the trap
2210 action causes the shell to behave as if the new value were entered from
2211 the keyboard rather than the original value. The variable .sh.edcol is
2212 set to the input column number of the cursor at the time of the input.
2213 The variable .sh.edmode is set to ESC when in vi insert mode and is
2214 null otherwise. By prepending ${.sh.editmode} to a value assigned to
2215 .sh.edchar it causes the shell to change to control mode if it is not
2216 already in this mode.
2217
2218
2219 This trap is not invoked for characters entered as arguments to editing
2220 directives, or while reading input for a character search.
2221
2222 emacs Editing Mode
2223 This mode is entered by enabling either the emacs or gmacs option. The
2224 only difference between these two modes is the way they handle ^T. To
2225 edit, the user moves the cursor to the point needing correction and
2226 then inserts or deletes characters or words as needed. All the editing
2227 commands are control characters or escape sequences. The notation for
2228 control characters is caret (^) followed by the character.
2229
2230
2231 For example, ^F is the notation for CTRL/F. This is entered by depress‐
2232 ing f while holding down the CTRL (control) key. The SHIFT key is not
2233 depressed. (The notation ^? indicates the DEL (delete) key.)
2234
2235
2236 The notation for escape sequences is M- followed by a character. For
2237 example, M-f (pronounced Meta f) is entered by depressing ESC (ASCII
2238 033) followed by f. M-F is the notation for ESC followed by F.
2239
2240
2241 All edit commands operate from any place on the line, not just at the
2242 beginning. The RETURN or the LINE FEED key is not entered after edit
2243 commands except when noted.
2244
2245 ^F Move the cursor forward (right) one character.
2246
2247
2248 M-[C Move the cursor forward (right) one character.
2249
2250
2251 M-f Move the cursor forward one word. The emacs editor's idea
2252 of a word is a string of characters consisting of only
2253 letters, digits and underscores.
2254
2255
2256 ^B Move the cursor backward (left) one character.
2257
2258
2259 M-[D Move the cursor backward (left) one character.
2260
2261
2262 M-b Move the cursor backward one word.
2263
2264
2265 ^A Move the cursor to the beginning of the line.
2266
2267
2268 M-[H Move the cursor to the beginning of the line.
2269
2270
2271 ^E Move the cursor to the end of the line.
2272
2273
2274 M-[Y Move the cursor to the end of line.
2275
2276
2277 ^]char Move the cursor forward to the character char on the cur‐
2278 rent line.
2279
2280
2281 M-^]char Move the cursor backwards to the character char on the
2282 current line.
2283
2284
2285 ^X^X Interchange the cursor and the mark.
2286
2287
2288 erase Delete the previous character. The user-defined erase
2289 character is defined by the stty(1) command, and is usu‐
2290 ally ^H or #.
2291
2292
2293 lnext Removes the next character's editing features. The user-
2294 defined literal next character is defined by the stty(1)
2295 command, or is ^V if not defined.
2296
2297
2298 ^D Delete the current character.
2299
2300
2301 M-d Delete the current word.
2302
2303
2304 M-^H MetaBACKSPACE. Delete the previous word.
2305
2306
2307 M-h Delete the previous word.
2308
2309
2310 M-^? MetaDEL. Delete the previous word. If your interrupt char‐
2311 acter is ^? (DEL, the default), this command does not
2312 work.
2313
2314
2315 ^T Transpose the current character with the previous charac‐
2316 ter, and advance the cursor in emacs mode. Transpose two
2317 previous characters in gmacs mode.
2318
2319
2320 ^C Capitalize the current character.
2321
2322
2323 M-c Capitalize the current word.
2324
2325
2326 M-l Change the current word to lower case.
2327
2328
2329 ^K Delete from the cursor to the end of the line. If preceded
2330 by a numerical parameter whose value is less than the cur‐
2331 rent cursor position, delete from specified position up to
2332 the cursor. If preceded by a numerical parameter whose
2333 value is greater than the current cursor position, then
2334 delete from cursor up to specified cursor position.
2335
2336
2337 ^W Kill from the cursor to the mark.
2338
2339
2340 M-p Push the region from the cursor to the mark on the stack.
2341
2342
2343 kill Kill the entire current line. The user-defined kill char‐
2344 acter is defined by the stty(1) command, usually a ^G or
2345 @. If two kill characters are entered in succession, all
2346 kill characters from then on cause a line feed. This is
2347 useful when using paper terminals.
2348
2349
2350 ^Y Restore the last item removed from line. Yank the item
2351 back to the line.
2352
2353
2354 ^L Line feed and print the current line.
2355
2356
2357 M-^L Clear the screen.
2358
2359
2360 ^@ Null character. Set mark.
2361
2362
2363 M-space MetaSPACE. Set the mark.
2364
2365
2366 ^J New line. Execute the current line.
2367
2368
2369 ^M Return. Execute the current line.
2370
2371
2372 EOF End-of-file character, normally ^D, is processed as an
2373 end-of-file only if the current line is null.
2374
2375
2376 ^P Fetch the previous command. Each time ^P is entered the
2377 previous command back in time is accessed. Moves back one
2378 line when it is not on the first line of a multi-line com‐
2379 mand.
2380
2381
2382 M-[A Equivalent to ^P.
2383
2384
2385 M-< Fetch the least recent (oldest) history line.
2386
2387
2388 M-> Fetch the most recent (youngest) history line.
2389
2390
2391 ^N Fetch the next command line. Each time ^N is entered the
2392 next command line forward in time is accessed.
2393
2394
2395 M-[B Equivalent to ^N.
2396
2397
2398 ^Rstring Reverse search history for a previous command line con‐
2399 taining string. If a parameter of zero is specified, the
2400 search is forward. string is terminated by a RETURN or
2401 NEWLINE. If string is preceded by a ^, the matched line
2402 must begin with string. If string is omitted, then the
2403 next command line containing the most recent string is
2404 accessed. In this case a parameter of zero reverses the
2405 direction of the search.
2406
2407
2408 ^O Operate. Execute the current line and fetch the next line
2409 relative to current line from the history file.
2410
2411
2412 M-digits Escape. Define numeric parameter. The digits are taken as
2413 a parameter to the next command. The commands that accept
2414 a parameter are: ^F, ^B, ERASE, ^C, ^D, ^K, ^R, ^P, ^N,
2415 ^], M-., M-, M-^], M-_, M-=, M-b, M-c, M-d, M-f, M-h, M-l,
2416 and M-^H.
2417
2418
2419 M-letter Soft-key. Search the alias list for an alias by the name
2420 letter. If an alias of letter is defined, insert its value
2421 on the input queue. letter must not be one of the meta‐
2422 functions in this section.
2423
2424
2425 M-[letter Soft key. Search the alias list for an alias by the name
2426 letter. If an alias of this name is defined, insert its
2427 value on the input queue. This can be used to program
2428 function keys on many terminals.
2429
2430
2431 M-. The last word of the previous command is inserted on the
2432 line. If preceded by a numeric parameter, the value of
2433 this parameter determines which word to insert rather than
2434 the last word.
2435
2436
2437 M-_ Same as M-..
2438
2439
2440 M-* Attempt filename generation on the current word. As aster‐
2441 isk is appended if the word does not match any file or
2442 contain any special pattern characters.
2443
2444
2445 M-ESC Command or file name completion as described in this man‐
2446 ual page.
2447
2448
2449 ^ITAB Attempts command or file name completion as described in
2450 this manual page. If a partial completion occurs, repeat‐
2451 ing this behaves as if M-= were entered. If no match is
2452 found or entered after SPACE, a TAB is inserted.
2453
2454
2455 M-= If not preceded by a numeric parameter, generates the list
2456 of matching commands or file names as described in this
2457 manual page. Otherwise, the word under the cursor is
2458 replaced by the item corresponding to the value of the
2459 numeric parameter from the most recently generated command
2460 or file list. If the cursor is not on a word, the word is
2461 inserted instead.
2462
2463
2464 ^U Multiply parameter of next command by 4.
2465
2466
2467 \ Escape the next character. Editing characters, the user's
2468 erase, kill and interrupt (normally ^?) characters can be
2469 entered in a command line or in a search string if pre‐
2470 ceded by a \. The \ removes the next character's editing
2471 features, if any.
2472
2473
2474 M-^V Display the version of the shell.
2475
2476
2477 M-# If the line does not begin with a #, a # is inserted at
2478 the beginning of the line and after each NEWLINE, and the
2479 line is entered. This causes a comment to be inserted in
2480 the history file. If the line begins with a #, the # is
2481 deleted and one # after each NEWLINE is also deleted.
2482
2483
2484 vi Editing Mode
2485 There are two typing modes. Initially, when you enter a command you are
2486 in the input mode. To edit, the user enters control mode by typing ESC
2487 (033) and moves the cursor to the point needing correction and then
2488 inserts or deletes characters or words as needed. Most control commands
2489 accept an optional repeat count prior to the command.
2490
2491
2492 When in vi mode on most systems, canonical processing is initially
2493 enabled and the command is echoed again if the speed is 1200 baud or
2494 greater and it contains any control characters or less than one second
2495 has elapsed since the prompt was printed. The ESC character terminates
2496 canonical processing for the remainder of the command and the user can
2497 then modify the command line. This scheme has the advantages of canoni‐
2498 cal processing with the type-ahead echoing of raw mode.
2499
2500
2501 If the option viraw is also set, the terminal is always have canonical
2502 processing disabled. This mode is implicit for systems that do not sup‐
2503 port two alternate end of line delimiters, and might be helpful for
2504 certain terminals.
2505
2506 Input Edit Commands
2507 By default the editor is in input mode.
2508
2509
2510 The following input edit commands are supported:
2511
2512 ERASE User defined erase character as defined by the stty command,
2513 usually ^H or #. Delete previous character.
2514
2515
2516 ^W Delete the previous blank separated word. On some systems the
2517 viraw option might be required for this to work.
2518
2519
2520 EOF As the first character of the line causes the shell to termi‐
2521 nate unless the ignoreeof option is set. Otherwise this char‐
2522 acter is ignored.
2523
2524
2525 lnext User defined literal next character as defined by the stty(1)
2526 or ^V if not defined. Removes the next character's editing
2527 features, if any. On some systems the viraw option might be
2528 required for this to work.
2529
2530
2531 \ Escape the next ERASE or KILL character.
2532
2533
2534 ^I TAB Attempts command or file name completion as described in this
2535 manual page and returns to input mode. If a partial comple‐
2536 tion occurs, repeating this behaves as if = were entered from
2537 control mode. If no match is found or entered after SPACE, a
2538 TAB is inserted.
2539
2540
2541 Motion Edit Commands
2542 The motion edit commands move the cursor.
2543
2544
2545 The following motion edit commands are supported:
2546
2547 [count]l Move the cursor forward (right) one character.
2548
2549
2550 [count][C Move the cursor forward (right) one character.
2551
2552
2553 [count]w Move the cursor forward one alphanumeric word.
2554
2555
2556 [count]W Move the cursor to the beginning of the next word that
2557 follows a blank.
2558
2559
2560 [count]e Move the cursor to the end of the word.
2561
2562
2563 [count]E Move the cursor to the end of the current blank delimited
2564 word.
2565
2566
2567 [count]h Move the cursor backward (left) one character.
2568
2569
2570 [count][D Move the cursor backward (left) one character.
2571
2572
2573 [count]b Move the cursor backward one word.
2574
2575
2576 [count]B Move the cursor to the preceding blank separated word.
2577
2578
2579 [count]| Move the cursor to column count.
2580
2581
2582 [count]fc Find the next character c in the current line.
2583
2584
2585 [count]Fc Find the previous character c in the current line.
2586
2587
2588 [count]tC Equivalent to f followed by h.
2589
2590
2591 [count]Tc Equivalent to F followed by l.
2592
2593
2594 [count]; Repeat count times the last single character find command:
2595 f, F, t, or T.
2596
2597
2598 [count], Reverse the last single character find command count
2599 times.
2600
2601
2602 0 Move the cursor to the start of line.
2603
2604
2605 ^ Move the cursor to start of line.
2606
2607
2608 [H Move the cursor to the first non-blank character in the
2609 line.
2610
2611
2612 $ Move the cursor to the end of the line.
2613
2614
2615 [Y Move the cursor to the end of the line.
2616
2617
2618 % Moves to balancing (, ), {, }, [, or ]. If cursor is not
2619 on one of the characters described in this section, the
2620 remainder of the line is searched for the first occurrence
2621 of one of the characters first.
2622
2623
2624 Search Edit Commands
2625 The search edit commands access your command history.
2626
2627
2628 The following search edit commands are supported:
2629
2630 [count]k Fetch the previous command. Each time k is entered, the
2631 previous command back in time is accessed.
2632
2633
2634 [count]- Fetch the previous command. Each time k is entered, the
2635 previous command back in time is accessed.
2636
2637 Equivalent to k.
2638
2639
2640 [count][A Fetch the previous command. Each time k is entered, the
2641 previous command back in time is accessed.
2642
2643 Equivalent to k.
2644
2645
2646 [count]j Fetch the next command. Each time j is entered, the next
2647 command forward in time is accessed.
2648
2649
2650 [count]+ Fetch the next command. Each time j is entered, the next
2651 command forward in time is accessed.
2652
2653 Equivalent to j.
2654
2655
2656 [count][B Fetch the next command. Each time j is entered, the next
2657 command forward in time is accessed.
2658
2659 Equivalent to j.
2660
2661
2662 [count]G Fetch command number count. The default is the least
2663 recent history command.
2664
2665
2666 /string Search backward through history for a previous command
2667 containing string. string is terminated by a RETURN or
2668 NEWLINE. If string is preceded by a ^, the matched line
2669 must begin with string. If string is null, the previous
2670 string is used.
2671
2672
2673 ?string Search forward through history for a previous command con‐
2674 taining string. string is terminated by a RETURN or NEW‐
2675 LINE. If string is preceded by a ^, the matched line must
2676 begin with string. If string is null, the previous string
2677 is used.
2678
2679 Same as / except that search is in the forward direction.
2680
2681
2682 n Search in the backwards direction for the next match of
2683 the last pattern to / or ? commands.
2684
2685
2686 N Search in the forward direction for next match of the last
2687 pattern to / or ?.
2688
2689
2690 Text Modification Edit Commands
2691 The following commands modify the line:
2692
2693 a Enter input mode and enter text after the current
2694 character.
2695
2696
2697 A Append text to the end of the line. Equivalent to
2698 $a.
2699
2700
2701 [count]cmotion Delete current character through the character that
2702 c[count]motion motion would move the cursor to and enter input
2703 mode. If motion is c, the entire line is deleted and
2704 input mode entered.
2705
2706
2707 C Delete the current character through the end of line
2708 and enter input mode. Equivalent to c$.
2709
2710
2711 S Equivalent to cc.
2712
2713
2714 [count]s Replace characters under the cursor in input mode.
2715
2716
2717 D[count]dmotion Delete the current character through the end of
2718 line. Equivalent to d$.
2719
2720
2721 d[count]motion Delete current character through the character that
2722 motion would move to. If motion is d , the entire
2723 line is deleted.
2724
2725
2726 i Enter input mode and insert text before the current
2727 character.
2728
2729
2730 I Insert text before the beginning of the line. Equiv‐
2731 alent to 0i.
2732
2733
2734 [count]P Place the previous text modification before the cur‐
2735 sor.
2736
2737
2738 [count]p Place the previous text modification after the cur‐
2739 sor.
2740
2741
2742 R Enter input mode and replace characters on the
2743 screen with characters you type overlay fashion.
2744
2745
2746 [count]rc Replace the count characters starting at the current
2747 cursor position with c, and advance the cursor.
2748
2749
2750 [count]x Delete current character.
2751
2752
2753 [count]X Delete preceding character.
2754
2755
2756 [count]. Repeat the previous text modification command.
2757
2758
2759 [count]~ Invert the case of the count characters starting at
2760 the current cursor position and advance the cursor.
2761
2762
2763 [count]_ Causes the count word of the previous command to be
2764 appended and input mode entered. The last word is
2765 used if count is omitted.
2766
2767
2768 * Causes an * to be appended to the current word and
2769 file name generation attempted. If no match is
2770 found, it rings the bell. Otherwise, the word is
2771 replaced by the matching pattern and input mode is
2772 entered.
2773
2774
2775 \ Command or file name completion as described in this
2776 manual page.
2777
2778
2779 Other Edit Commands
2780 The following miscellaneous edit commands are supported:
2781
2782 [count]ymotion Yank the current character through the character to
2783 y[count]motion which motion would move the cursor. Put the yanked
2784 characters in the delete buffer. The text and cursor
2785 position are unchanged.
2786
2787
2788 yy Yank the current line.
2789
2790
2791 Y Yank the current line from the current cursor loca‐
2792 tion to the end of the line. Equivalent to y$.
2793
2794
2795 u Undo the last text modifying command.
2796
2797
2798 U Undo all the text modifying commands performed on
2799 current line.
2800
2801
2802 [count]V Return the command :
2803
2804 hist -e ${VISUAL:-${EDITOR:-vi}} count
2805
2806
2807 in the input buffer. If count is omitted, the current
2808 line is used.
2809
2810
2811 ^L Line feed and print the current line. This command
2812 only works in control mode.
2813
2814
2815 ^J New line. Execute the current line, regardless of
2816 mode.
2817
2818
2819 ^M Return. Execute the current line, regardless of mode.
2820
2821
2822 # If the first character of the command is a # , delete
2823 this # and each # that follows a NEWLINE.
2824
2825 Otherwise, send the line after inserting a # in front
2826 of each line in the command.
2827
2828 This is command is useful for causing the current
2829 line to be inserted in the history as a comment and
2830 un-commenting previously commented commands in the
2831 history file.
2832
2833
2834 [count]= If count is not specified, generate the list of
2835 matching commands or file names as described in this
2836 manual page.
2837
2838 Otherwise, replace the word at the current cursor
2839 location with the count item from the most recently
2840 generated command or file list. If the cursor is not
2841 on a word, it is inserted after the current cursor
2842 location.
2843
2844
2845 @letter Search your alias list for an alias by the name let‐
2846 ter. If an alias of this name is defined, insert its
2847 value on the input queue for processing.
2848
2849
2850 ^V Display version of the shell.
2851
2852
2853 Built-in Commands
2854 The following simple-commands are executed in the shell process. Input
2855 and output redirection is permitted. Unless otherwise indicated, the
2856 output is written on file descriptor 1 and the exit status, when there
2857 is no syntax error, is 0. Except for :, true, false, echo, newgrp, and
2858 login, all built-in commands accept -- to indicate the end of options.
2859 They also interpret the option --man as a request to display the manual
2860 page onto standard error and -? as a help request which prints a usage
2861 message on standard error.
2862
2863
2864 Commands that are preceded by one or two ++ symbols are special built-
2865 in commands and are treated specially in the following ways:
2866
2867 1. Variable assignment lists preceding the command remain in
2868 effect when the command completes.
2869
2870 2. I/O redirections are processed after variable assignments.
2871
2872 3. Errors cause a script that contains them to abort.
2873
2874 4. They are not valid function names.
2875
2876 5. Words following a command preceded by ++ that are in the
2877 format of a variable assignment are expanded with the same
2878 rules as a variable assignment. This means that tilde sub‐
2879 stitution is performed after the = sign and field splitting
2880 and file name generation are not performed.
2881
2882 + : [arg ...]
2883
2884 The command only expands parameters.
2885
2886
2887 + . name [arg ...]
2888
2889 If name is a function defined with the function name reserved word
2890 syntax, the function is executed in the current environment (as if
2891 it had been defined with the name() syntax.) Otherwise if name
2892 refers to a file, the file is read in its entirety and the commands
2893 are executed in the current shell environment. The search path
2894 specified by PATH is used to find the directory containing the
2895 file. If any arguments arg are specified, they become the posi‐
2896 tional parameters while processing the . command and the original
2897 positional parameters are restored upon completion. Otherwise the
2898 positional parameters are unchanged. The exit status is the exit
2899 status of the last command executed.
2900
2901
2902 ++ alias [-ptx] [name[ =value]] ...
2903
2904 alias with no arguments prints the list of aliases in the form
2905 name=value on standard output. The -p option causes the word alias
2906 to be inserted before each one. When one or more arguments are
2907 specified, an alias is defined for each name whose value is speci‐
2908 fied. A trailing space in value causes the next word to be checked
2909 for alias substitution. The obsolete -t option is used to set and
2910 list tracked aliases. The value of a tracked alias is the full
2911 pathname corresponding to the specified name. The value becomes
2912 undefined when the value of PATH is reset but the alias remains
2913 tracked. Without the -t option, for each name in the argument list
2914 for which no value is specified, the name and value of the alias is
2915 printed. The obsolete -x option has no effect. The exit status is
2916 non-zero if a name is specified, but no value, and no alias has
2917 been defined for the name.
2918
2919
2920 bg [ job...]
2921
2922 This command is only on systems that support job control. Puts each
2923 specified job into the background. The current job is put in the
2924 background if job is not specified. See the Jobs section of this
2925 manual page for a description of the format of job.
2926
2927
2928 + break [n]
2929
2930 Exit from the enclosing for, while, until, or select loop, if any.
2931 If n is specified, then break n levels.
2932
2933
2934 builtin [-ds ] [-f file] [name ...]
2935
2936 If name is not specified, and no -f option is specified, the built-
2937 ins are printed on standard output. The -s option prints only the
2938 special built-ins. Otherwise, each name represents the pathname
2939 whose basename is the name of the built-in. The entry point func‐
2940 tion name is determined by prepending b to the built-in name. The
2941 ISO C/C++ prototype is bmycommand(int argc, char *argv[], void
2942 *context) for the built-in command mycommand where argv is an array
2943 of argc elements and context is an optional pointer to a Shell_t
2944 structure as described in <ast/shell.h> Special built-ins cannot be
2945 bound to a pathname or deleted. The -d option deletes each of the
2946 specified built-ins. On systems that support dynamic loading, the
2947 -f option names a shared library containing the code for built-ins.
2948 The shared library prefix and/or suffix, which depend on the sys‐
2949 tem, can be omitted. Once a library is loaded, its symbols become
2950 available for subsequent invocations of builtin. Multiple libraries
2951 can be specified with separate invocations of the builtin command.
2952 Libraries are searched in the reverse order in which they are spec‐
2953 ified. When a library is loaded, it looks for a function in the
2954 library whose name is lib_init() and invokes this function with an
2955 argument of 0.
2956
2957
2958 cd [-LP] [arg]
2959 cd [-LP] old new
2960
2961 This command has two forms.
2962
2963 In the first form it changes the current directory to arg. If arg
2964 is a -, the directory is changed to the previous directory. The
2965 shell variable HOME is the default arg. The variable PWD is set to
2966 the current directory. The shell variable CDPATH defines the search
2967 path for the directory containing arg. Alternative directory names
2968 are separated by a colon (:). The default path is NULL (specifying
2969 the current directory). The current directory is specified by a
2970 null path name, which can appear immediately after the equal sign
2971 or between the colon delimiters anywhere else in the path list. If
2972 arg begins with a /, the search path is not used. Otherwise, each
2973 directory in the path is searched for arg.
2974
2975 The second form of cd substitutes the string new for the string old
2976 in the current directory name, PWD, and tries to change to this new
2977 directory. By default, symbolic link names are treated literally
2978 when finding the directory name. This is equivalent to the -L
2979 option. The -P option causes symbolic links to be resolved when
2980 determining the directory. The last instance of -L or -P on the
2981 command line determines which method is used. The cd command cannot
2982 be executed by rksh93.
2983
2984
2985 command [-pvVx] name [arg ...]
2986
2987 Without the -v or -V options, executes name with the arguments
2988 specified by arg.
2989
2990 The -p option causes a default path to be searched rather than the
2991 one defined by the value of PATH. Functions are not searched when
2992 finding name. In addition, if name refers to a special built-in,
2993 none of the special properties associated with the leading daggers
2994 are honored. For example, the predefined alias redirect='command
2995 exec' prevents a script from terminating when an invalid redirect‐
2996 ion is specified.
2997
2998 With the -x option, if command execution would result in a failure
2999 because there are too many arguments, errno E2BIG, the shell
3000 invokes command name multiple times with a subset of the arguments
3001 on each invocation. Arguments that occur prior to the first word
3002 that expands to multiple arguments and after the last word that
3003 expands to multiple arguments are passed on each invocation. The
3004 exit status is the maximum invocation exit status.
3005
3006 With the -v option, command is equivalent to the built-in whence
3007 command described in this section. The -V option causes command to
3008 act like whence -v.
3009
3010
3011 +continue [n]
3012
3013 Resumes the next iteration of the enclosing for, while, until, or
3014 select loop. If n is specified, then resume at the nth enclosing
3015 loop.
3016
3017
3018 disown [job...]
3019
3020 Causes the shell not to send a HUP signal to each specified job, or
3021 all active jobs if job is omitted, when a login shell terminates.
3022
3023
3024 echo [arg ...]
3025
3026 When the first arg does not begin with a -, and none of the argu‐
3027 ments contain a backslash (\), prints each of its arguments sepa‐
3028 rated by a SPACE and terminated by a NEWLINE. Otherwise, the behav‐
3029 ior of echo is system dependent and print or printf described in
3030 this section should be used. See echo(1) for usage and description.
3031
3032
3033 +eval [arg ...]
3034
3035 The arguments are read as input to the shell and the resulting com‐
3036 mands are executed.
3037
3038
3039 +exec [-c] [-a name ...] [arg ...]
3040
3041 If arg is specified, the command specified by the arguments is exe‐
3042 cuted in place of this shell without creating a new process. The -c
3043 option causes the environment to be cleared before applying vari‐
3044 able assignments associated with the exec invocation. The -a option
3045 causes name rather than the first arg, to become argv[0] for the
3046 new process. Input and output arguments can appear and affect the
3047 current process. If arg is not specified, the effect of this com‐
3048 mand is to modify file descriptors as prescribed by the input/out‐
3049 put redirection list. In this case, any file descriptor numbers
3050 greater than 2 that are opened with this mechanism are closed when
3051 invoking another program.
3052
3053
3054 +exit [n]
3055
3056 Causes the shell to exit with the exit status specified by n. The
3057 value is the least significant 8 bits of the specified status. If n
3058 is omitted, then the exit status is that of the last command exe‐
3059 cuted. An end-of-file also causes the shell to exit except for a
3060 shell which has the ignoreeof option turned on. See set.
3061
3062
3063 ++export [-p] [name[=value]] ...
3064
3065 If name is not specified, the names and values of each variable
3066 with the export attribute are printed with the values quoted in a
3067 manner that allows them to be re-entered. The -p option causes the
3068 word export to be inserted before each one. Otherwise, the speci‐
3069 fied names are marked for automatic export to the environment of
3070 subsequently-executed commands.
3071
3072
3073 false
3074
3075 Does nothing, and exits 1. Used with until for infinite loops.
3076
3077
3078 fg [job ...]
3079
3080 This command is only on systems that support job control. Each job
3081 specified is brought to the foreground and waited for in the speci‐
3082 fied order. Otherwise, the current job is brought into the fore‐
3083 ground. See Jobs for a description of the format of job.
3084
3085
3086 getconf [name [pathname]]
3087
3088 Prints the current value of the configuration parameter specified
3089 by name. The configuration parameters are defined by the IEEE POSIX
3090 1003.1 and IEEE POSIX 1003.2 standards. See pathconf(2) and
3091 sysconf(3C).
3092
3093 The pathname argument is required for parameters whose value
3094 depends on the location in the file system. If no arguments are
3095 specified, getconf prints the names and values of the current con‐
3096 figuration parameters. The pathname / is used for each of the
3097 parameters that requires pathname.
3098
3099
3100 getopts [ -a name] optstring vname [arg ...]
3101
3102 Checks arg for legal options. If arg is omitted, the positional
3103 parameters are used. An option argument begins with a + or a -. An
3104 option that does not begin with + or - or the argument -- ends the
3105 options. Options beginning with + are only recognized when opt‐
3106 string begins with a +. optstring contains the letters that getopts
3107 recognizes. If a letter is followed by a :, that option is expected
3108 to have an argument. The options can be separated from the argument
3109 by blanks. The option -?causes getopts to generate a usage message
3110 on standard error. The -a option can be used to specify the name to
3111 use for the usage message, which defaults to $0. getopts places the
3112 next option letter it finds inside variable vname each time it is
3113 invoked. The option letter is prepended with a + when arg begins
3114 with a +. The index of the next arg is stored in OPTIND. The option
3115 argument, if any, gets stored in OPTARG. A leading : in optstring
3116 causes getopts to store the letter of an invalid option in OPTARG,
3117 and to set vname to ? for an unknown option and to: when a required
3118 option argument is missing. Otherwise, getopts prints an error mes‐
3119 sage. The exit status is non-zero when there are no more options.
3120 There is no way to specify any of the options :, +, -, ?, [, and ].
3121 The option # can only be specified as the first option.
3122
3123
3124 hist [ -e ename][-nlr] [ first[last ] ]
3125
3126 hist -s [ old=new ] [ command]
3127
3128 In the first form, a range of commands from first to last is
3129 selected from the last HISTSIZE commands that were typed at the
3130 terminal. The arguments first and last can be specified as a number
3131 or as a string. A string is used to locate the most recent command
3132 starting with the specified string. A negative number is used as an
3133 offset to the current command number. If the -l option is selected,
3134 the commands are listed on standard output. Otherwise, the editor
3135 program ename is invoked on a file containing these keyboard com‐
3136 mands. If ename is not supplied, then the value of the variable
3137 HISTEDIT is used. If HISTEDIT is not set, then FCEDIT (default
3138 /bin/ed) is used as the editor. When editing is complete, the
3139 edited command(s) is executed if the changes have been saved. If
3140 last is not specified, then it is set to first. If first is not
3141 specified, the default is the previous command for editing and -16
3142 for listing. The option -r reverses the order of the commands and
3143 the option -n suppresses command numbers when listing. In the sec‐
3144 ond form, command is interpreted as first described in this section
3145 and defaults to the last command executed. The resulting command is
3146 executed after the optional substitution old=new is performed.
3147
3148
3149 jobs -lnp [job ...]
3150
3151 Lists information about each specified job, or all active jobs if
3152 job is omitted. The -l option lists process ids in addition to the
3153 normal information. The -n option only displays jobs that have
3154 stopped or exited since last notified. The -p option causes only
3155 the process group to be listed. See Jobs for a description of the
3156 format of job.
3157
3158
3159 kill [-s signame] job ...
3160 kill [-n signum] job ...
3161 kill -l [sig ...]
3162
3163 Sends either the TERM (terminate) signal or the specified signal to
3164 the specified jobs or processes. Signals are either specified by
3165 number with the -n option or by name with the -s option (as speci‐
3166 fied in <signal.h>, stripped of the prefix `SIG with the exception
3167 that SIGCLD is named CHLD). For backward compatibility, the n and s
3168 can be omitted and the number or name placed immediately after the
3169 -. If the signal being sent is TERM (terminate) or HUP (hang up),
3170 then the job or process is sent a CONT (continue) signal if it is
3171 stopped. The argument job can be the process id of a process that
3172 is not a member of one of the active jobs. See Jobs for a descrip‐
3173 tion of the format of job. In the third form, kill -l, if sig is
3174 not specified, the signal names are listed. Otherwise, for each sig
3175 that is a name, the corresponding signal number is listed. For each
3176 sig that is a number, the signal name corresponding to the least
3177 significant 8 bits of sig is listed.
3178
3179
3180 let [arg ...]
3181
3182 Each arg is a separate arithmetic expression to be evaluated. See
3183 the Arithmetic Evaluation section of this manual page for a
3184 description of arithmetic expression evaluation. The exit status is
3185 0 if the value of the last expression is non-zero, and 1 otherwise.
3186
3187
3188 +newgrp [arg ...]
3189
3190 Equivalent to exec /bin/newgrp arg ...
3191
3192
3193 print [-Renprs] [ -u unit] [ -f format ] [ arg ...]
3194
3195 With no options or with option - or --, each arg is printed on
3196 standard output. The -f option causes the arguments to be printed
3197 as described by printf. In this case, any e, n, r, or R options are
3198 ignored. Otherwise, unless the -R or -r, are specified, the follow‐
3199 ing escape conventions are applied:
3200
3201 \a Alert character (ASCII 07)
3202
3203
3204 \b Backspace character (ASCII 010)
3205
3206
3207 \c Causes print to end without processing more arguments and
3208 not adding a NEWLINE
3209
3210
3211 \f Form-feed character (ASCII 014)
3212
3213
3214 \n NEWLINE character (ASCII 012)
3215
3216
3217 \r RETURN character (ASCII 015)
3218
3219
3220 \t TAB character (ASCII 011)
3221
3222
3223 \v Vertical TAB character (ASCII 013)
3224
3225
3226 \E Escape character (ASCII 033)
3227
3228
3229 \\ Backslash character \
3230
3231
3232 \0x Character defined by the 1, 2, or 3-digit octal string
3233 specified by x
3234
3235 The -R option prints all subsequent arguments and options other
3236 than -n. The -e causes the escape conventions to be applied This is
3237 the default behavior. It reverses the effect of an earlier -r. The
3238 -p option causes the arguments to be written onto the pipe of the
3239 process spawned with |& instead of standard output. The -s option
3240 causes the arguments to be written onto the history file instead of
3241 standard output. The -u option can be used to specify a one digit
3242 file descriptor unit number unit on which the output is placed. The
3243 default is 1. If the option -n is used, no NEWLINE is added to the
3244 output.
3245
3246
3247 printf format[arg ...]
3248
3249 The arguments arg are printed on standard output in accordance with
3250 the ANSI-C formatting rules associated with the format string for‐
3251 mat. If the number of arguments exceeds the number of format speci‐
3252 fications, the format string is reused to format remaining argu‐
3253 ments. The following extensions can also be used: A %b format can
3254 be used instead of %s to cause escape sequences in the correspond‐
3255 ing arg to be expanded as described in print. A %B option causes
3256 each of the arguments to be treated as variable names and the
3257 binary value of the variables is printed. This is most useful for
3258 variables with an attribute of b. A %H format can be used instead
3259 of %s to cause characters in arg that are special in HTML and XML
3260 to be output as their entity name. A %P format can be used instead
3261 of %s to cause arg to be interpreted as an extended regular expres‐
3262 sion and be printed as a shell pattern. A %R format can be used
3263 instead of %s to cause arg to be interpreted as a shell pattern and
3264 to be printed as an extended regular expression. A %q format can be
3265 used instead of %s to cause the resulting string to be quoted in a
3266 manner than can be input again to the shell. A %(date-format)T for‐
3267 mat can be use to treat an argument as a date/time string and to
3268 format the date/time according to the date-format as defined for
3269 the date(1) command. A %Z format outputs a byte whose value is 0.
3270 The precision field of the %d format can be followed by a . and the
3271 output base. In this case, the # flag character causes base# to be
3272 prepended. The # flag when used with the d specifier without an
3273 output base, causes the output to be displayed in thousands units
3274 with one of the suffixes k M G T P E to indicate the unit. The #
3275 flag when used with the i specifier causes the output to be dis‐
3276 played in 1024 with one of the suffixes Ki Mi Gi Ti Pi Ei to indi‐
3277 cate the unit. The = flag has been added to center the output
3278 within the specified field width.
3279
3280
3281 pwd [-LP]
3282
3283 Outputs the value of the current working directory. The -L option
3284 is the default. It prints the logical name of the current direc‐
3285 tory. If the -P option is specified, all symbolic links are
3286 resolved from the name. The last instance of -L or -P on the com‐
3287 mand line determines which method is used.
3288
3289
3290 read [-Aprs] [-d delim] [ -n n] [[ -N n] [[-t timeout] [-u unit]
3291 [vname?prompt] [ vname ... ]
3292
3293 The shell input mechanism. One line is read and is broken up into
3294 fields using the characters in IFS as separators. The escape char‐
3295 acter, \, is used to remove any special meaning for the next char‐
3296 acter and for line continuation. The -d option causes the read to
3297 continue to the first character of delim rather than NEWLINE. The
3298 -n option causes at most n bytes to read rather a full line but
3299 returns when reading from a slow device as soon as any characters
3300 have been read. The -N option causes exactly n to be read unless an
3301 end-of-file has been encountered or the read times out because of
3302 the -t option. In raw mode, -r, the \ character is not treated spe‐
3303 cially. The first field is assigned to the first vname, the second
3304 field to the second vname, etc., with leftover fields assigned to
3305 the last vname. When vname has the binary attribute and -n or -N is
3306 specified, the bytes that are read are stored directly into the
3307 variable. If the -v is specified, then the value of the first vname
3308 is used as a default value when reading from a terminal device. The
3309 -A option causes the variable vname to be unset and each field that
3310 is read to be stored in successive elements of the indexed array
3311 vname. The -p option causes the input line to be taken from the
3312 input pipe of a process spawned by the shell using |&. If the -s
3313 option is present, the input is saved as a command in the history
3314 file. The option -u can be used to specify a one digit file
3315 descriptor unit unit to read from. The file descriptor can be
3316 opened with the exec special built-in command. The default value of
3317 unit n is 0. The option -t is used to specify a time out in seconds
3318 when reading from a terminal or pipe. If vname is omitted, then
3319 REPLY is used as the default vname. An end-of-file with the -p
3320 option causes cleanup for this process so that another can be
3321 spawned. If the first argument contains a ?, the remainder of this
3322 word is used as a prompt on standard error when the shell is inter‐
3323 active. The exit status is 0 unless an end-of-file is encountered
3324 or read has timed out.
3325
3326
3327 ++readonly [-p] [ vname[=value]] ...
3328
3329 If vname is not specified, the names and values of each variable
3330 with the read-only attribute is printed with the values quoted in a
3331 manner that allows them to be input again. The -p option causes the
3332 word readonly to be inserted before each one. Otherwise, the speci‐
3333 fied vnames are marked readonly and these names cannot be changed
3334 by subsequent assignment.
3335
3336
3337 +return [n]
3338
3339 Causes a shell function or script to return to the invoking script
3340 with the exit status specified by n. The value is the least signif‐
3341 icant 8 bits of the specified status. If n is omitted, then the
3342 return status is that of the last command executed. If return is
3343 invoked while not in a function or a script, then it behaves the
3344 same as exit.
3345
3346
3347 +set [ ±BCGabefhkmnoprstuvx] [±o [ option ] ] ... [ ±A vname] [arg...]
3348
3349 The set command supports the following options:
3350
3351 -a
3352
3353 All subsequent variables that are defined are automatically
3354 exported.
3355
3356
3357 -A
3358
3359 Array assignment. Unset the variable vname and assign values
3360 sequentially from the arg list. If +A is used, the variable
3361 vname is not unset first.
3362
3363
3364 -b
3365
3366 Prints job completion messages as soon as a background job
3367 changes state rather than waiting for the next prompt.
3368
3369
3370 -B
3371
3372 Enable brace pattern field generation. This is the default
3373 behavior.
3374
3375
3376 -C
3377
3378 Prevents redirection (>) from truncating existing files. Files
3379 that are created are opened with the O_EXCL mode. Requires >|
3380 to truncate a file when turned on.
3381
3382
3383 -e
3384
3385 If a command has a non-zero exit status, execute the ERR trap,
3386 if set, and exit. This mode is disabled while reading profiles.
3387
3388
3389 -f
3390
3391 Disables file name generation.
3392
3393
3394 -G
3395
3396 Causes the pattern ** by itself to match files and zero or more
3397 directories and subdirectories when used for file name genera‐
3398 tion. If followed by a / only directories and subdirectories
3399 are matched.
3400
3401
3402 -h
3403
3404 Each command becomes a tracked alias when first encountered.
3405
3406
3407 -k
3408
3409 Obsolete. All variable assignment arguments are placed in the
3410 environment for a command, not just those that precede the com‐
3411 mand name.
3412
3413
3414 -m
3415
3416 Background jobs run in a separate process group and a line
3417 prints upon completion. The exit status of background jobs is
3418 reported in a completion message. On systems with job control,
3419 this option is turned on automatically for interactive shells.
3420
3421
3422 -n
3423
3424 Read commands and check them for syntax errors, but do not exe‐
3425 cute them. Ignored for interactive shells.
3426
3427
3428 -o
3429
3430 If no option name is supplied, the list of options and their
3431 current settings are written to standard output. When invoked
3432 with a +, the options are written in a format that can be input
3433 again to the shell to restore the settings. This option can be
3434 repeated to enable or disable multiple options.
3435
3436 The following argument can be one of the following option
3437 names:
3438
3439 allexport
3440
3441 Same as -a.
3442
3443
3444 bgnice
3445
3446 All background jobs are run at a lower priority. This is
3447 the default mode.
3448
3449
3450 braceexpand
3451
3452 Same as -B.
3453
3454
3455 emacs
3456
3457 Puts you in an emacs style inline editor for command entry.
3458
3459
3460 errexit
3461
3462 Same as -e.
3463
3464
3465 globstar
3466
3467 Same as -G.
3468
3469
3470 gmacs
3471
3472 Puts you in a gmacs style inline editor for command entry.
3473
3474
3475 ignoreeof
3476
3477 The shell does not exit on end-of-file. The command exit
3478 must be used.
3479
3480
3481 keyword
3482
3483 Same as -k.
3484
3485
3486 markdirs
3487
3488 All directory names resulting from file name generation
3489 have a trailing / appended.
3490
3491
3492 monitor
3493
3494 Same as -m.
3495
3496
3497 multiline
3498
3499 The built-in editors use multiple lines on the screen for
3500 lines that are longer than the width of the screen. This
3501 might not work for all terminals.
3502
3503
3504 noclobber
3505
3506 Same as -C.
3507
3508
3509 noexec
3510
3511 Same as -n.
3512
3513
3514 noglob
3515
3516 Same as -f.
3517
3518
3519 nolog
3520
3521 Do not save function definitions in the history file.
3522
3523
3524 notify
3525
3526 Same as -b.
3527
3528
3529 nounset
3530
3531 Same as -u.
3532
3533
3534 pipefail
3535
3536 A pipeline does not complete until all components of the
3537 pipeline have completed, and the return value is the value
3538 of the last non-zero command to fail or zero if no command
3539 has failed.
3540
3541
3542 privileged
3543
3544 Same as -p.
3545
3546
3547 showme
3548
3549 When enabled, simple commands or pipelines preceded by a a
3550 semicolon (;) is displayed as if the xtrace option were
3551 enabled but is not executed. Otherwise, the leading ; is
3552 ignored.
3553
3554
3555 trackall
3556
3557 Same as -h.
3558
3559
3560 verbose
3561
3562 Same as -v.
3563
3564
3565 vi
3566
3567 Puts you in insert mode of a vi style inline editor until
3568 you hit the escape character 033. This puts you in control
3569 mode. A return sends the line.
3570
3571
3572 viraw
3573
3574 Each character is processed as it is typed in vi mode.
3575
3576
3577 xtrace
3578
3579 Same as -x.
3580
3581 If no option name is supplied, the current options settings
3582 are printed.
3583
3584
3585
3586 -p
3587
3588 Disables processing of the $HOME/.profile file and uses the
3589 file /etc/suid_profile instead of the ENV file. This mode is on
3590 whenever the effective uid (gid) is not equal to the real uid
3591 (gid). Turning this off causes the effective uid and gid to be
3592 set to the real uid and gid.
3593
3594
3595 -r
3596
3597 Enables the restricted shell. This option cannot be unset once
3598 set.
3599
3600
3601 -s
3602
3603 Sort the positional parameters lexicographically.
3604
3605
3606 -t
3607
3608 Obsolete. Exit after reading and executing one command.
3609
3610
3611 -u
3612
3613 Treat unset parameters as an error when substituting.
3614
3615
3616 -v
3617
3618 Print shell input lines as they are read.
3619
3620
3621 -x
3622
3623 Print commands and their arguments as they are executed.
3624
3625
3626 --
3627
3628 Do not change any of the options. This is useful in setting $1
3629 to a value beginning with -. If no arguments follow this option
3630 then the positional parameters are unset.
3631
3632 As an obsolete feature, if the first arg is - then the -x and -v
3633 options are turned off and the next arg is treated as the first
3634 argument. Using + rather than - causes these options to be turned
3635 off. These options can also be used upon invocation of the shell.
3636 The current set of options can be found in $-. Unless -A is speci‐
3637 fied, the remaining arguments are positional parameters and are
3638 assigned, in order, to $1 $2 .... If no arguments are specified,
3639 then the names and values of all variables are printed on the stan‐
3640 dard output.
3641
3642
3643 +shift [n]
3644
3645 The positional parameters from $n+1 ... are renamed $1 ..., the
3646 default n is 1. The parameter n can be any arithmetic expression
3647 that evaluates to a non-negative number less than or equal to $#.
3648
3649
3650 sleep seconds
3651
3652 Suspends execution for the number of decimal seconds or fractions
3653 of a second specified by seconds.
3654
3655
3656 +trap -p [action] [sig] ...
3657
3658 The -p option causes the trap action associated with each trap as
3659 specified by the arguments to be printed with appropriate quoting.
3660 Otherwise, action is processed as if it were an argument to eval
3661 when the shell receives signal(s) sig. Each sig can be specified as
3662 a number or as the name of the signal. Trap commands are executed
3663 in order of signal number. Any attempt to set a trap on a signal
3664 that was ignored on entry to the current shell is ineffective. If
3665 action is omitted and the first sig is a number, or if action is -,
3666 then the trap(s) for each sig are reset to their original values.
3667 If action is the null string then this signal is ignored by the
3668 shell and by the commands it invokes. If sig is ERR then action is
3669 executed whenever a command has a non-zero exit status. If sig is
3670 DEBUG then action is executed before each command. The variable
3671 .sh.command contains the contents of the current command line when
3672 action is running. If sig is 0 or EXIT and the trap statement is
3673 executed inside the body of a function defined with the function
3674 name syntax, then the command action is executed after the function
3675 completes. If sig is 0 or EXIT for a trap set outside any function
3676 then the command action is executed on exit from the shell. If sig
3677 is KEYBD, then action is executed whenever a key is read while in
3678 emacs, gmacs, or vi mode. The trap command with no arguments prints
3679 a list of commands associated with each signal number.
3680
3681
3682 true
3683
3684 Does nothing, and exits 0. Used with while for infinite loops.
3685
3686
3687 ++typeset [±AHflabnprtux ] [ ±EFLRZi[n] ] [ vname[=value ] ]
3688
3689 Sets attributes and values for shell variables and functions. When
3690 invoked inside a function defined with the function name syntax, a
3691 new instance of the variable vname is created, and the variable's
3692 value and type are restored when the function completes.
3693
3694 Using + rather than - causes these options to be turned off. If no
3695 vname arguments are specified, a list of vnames (and optionally the
3696 values) of the variables is printed. Using + rather than - keeps
3697 the values from being printed.) The -p option causes typeset fol‐
3698 lowed by the option letters to be printed before each name rather
3699 than the names of the options. If any option other than -p is spec‐
3700 ified, only those variables which have all of the specified options
3701 are printed. Otherwise, the vnames and attributes of all variables
3702 that have attributes are printed.
3703
3704 The following list of attributes can be specified:
3705
3706 -a Declares vname to be an indexed array. This is optional
3707 unless except for compound variable assignments.
3708
3709
3710 -A Declares vname to be an associative array. Sub-scripts are
3711 strings rather than arithmetic expressions.
3712
3713
3714 -b The variable can hold any number of bytes of data. The data
3715 can be text or binary. The value is represented by the base64
3716 encoding of the data. If -Z is also specified, the size in
3717 bytes of the data in the buffer is determined by the size
3718 associated with the -Z. If the base64 string assigned results
3719 in more data, it is truncated. Otherwise, it is filled with
3720 bytes whose value is zero. The printf format %B can be used
3721 to output the actual data in this buffer instead of the
3722 base64 encoding of the data.
3723
3724
3725 -E Declares vname to be a double precision floating point num‐
3726 ber. If n is non-zero, it defines the number of significant
3727 figures that are used when expanding vname. Otherwise, ten
3728 significant figures is used.
3729
3730
3731 -f The names refer to function names rather than variable names.
3732 No assignments can be made and the only other valid options
3733 are -t, -u, and -x. The -t option turns on execution tracing
3734 for this function. The -u option causes this function to be
3735 marked undefined. The FPATH variable is searched to find the
3736 function definition when the function is referenced. If no
3737 options other than -f is specified, then the function defini‐
3738 tion is displayed on standard output. If +f is specified,
3739 then a line containing the function name followed by a shell
3740 comment containing the line number and path name of the file
3741 where this function was defined, if any, is displayed.
3742
3743 The -i attribute cannot be specified with -f.
3744
3745
3746 -F Declares vname to be a double precision floating point num‐
3747 ber. If n is non-zero, it defines the number of places after
3748 the decimal point that are used when expanding vname. Other‐
3749 wise ten places after the decimal point is used.
3750
3751
3752 -H This option provides UNIX to hostname file mapping on non-
3753 UNIX machines.
3754
3755
3756 -i Declares vname to be represented internally as integer. The
3757 right hand side of an assignment is evaluated as an arith‐
3758 metic expression when assigning to an integer. If n is non-
3759 zero, it defines the output arithmetic base, otherwise the
3760 output base is ten.
3761
3762 The -i attribute cannot be specified along with -R, -L, -Z,
3763 or -f.
3764
3765
3766 -l All uppercase characters are converted to lowercase. The
3767 uppercase option, -u, is turned off.
3768
3769
3770 -L Left justify and remove leading blanks from value. If n is
3771 non-zero, it defines the width of the field, otherwise it is
3772 determined by the width of the value of first assignment.
3773 When the variable is assigned to, it is filled on the right
3774 with blanks or truncated, if necessary, to fit into the
3775 field. The -R option is turned off.
3776
3777 The -i attribute cannot be specified with -L.
3778
3779
3780 -n Declares vname to be a reference to the variable whose name
3781 is defined by the value of variable vname. This is usually
3782 used to reference a variable inside a function whose name has
3783 been passed as an argument.
3784
3785
3786 -R Right justify and fill with leading blanks. If n is non-zero,
3787 it defines the width of the field, otherwise it is determined
3788 by the width of the value of first assignment. The field is
3789 left filled with blanks or truncated from the end if the
3790 variable is reassigned. The -L option is turned off.
3791
3792 The -i attribute cannot be specified with -R.
3793
3794
3795 -r The specified vnames are marked read-only and these names
3796 cannot be changed by subsequent assignment.
3797
3798
3799 -t Tags the variables. Tags are user definable and have no spe‐
3800 cial meaning to the shell.
3801
3802
3803 -u All lowercase characters are converted to uppercase. The low‐
3804 ercase option, -l, is turned off.
3805
3806
3807 -x The specified vnames are marked for automatic export to the
3808 environment of subsequently-executed commands. Variables
3809 whose names contain a . cannot be exported.
3810
3811
3812 -Z Right justify and fill with leading zeros if the first non-
3813 blank character is a digit and the -L option has not been
3814 set. Remove leading zeros if the -L option is also set. If n
3815 is non-zero, it defines the width of the field, otherwise it
3816 is determined by the width of the value of first assignment.
3817
3818 The -i attribute cannot be specified with -Z.
3819
3820
3821
3822 ulimit [-HSacdfmnpstv] [ limit]
3823
3824 Set or display a resource limit. Many systems do not support one or
3825 more of these limits. The limit for a specified resource is set
3826 when limit is specified. The value of limit can be a number in the
3827 unit specified with each resource, or the value unlimited. When
3828 more than one resource is specified, then the limit name and unit
3829 is printed before the value.
3830
3831 If no option is specified, -f is assumed.
3832
3833 The following are the available resource limits:
3834
3835 -a Lists all of the current resource limits.
3836
3837
3838 -c The number of 512-byte blocks on the size of core dumps.
3839
3840
3841 -d The number of Kbytes on the size of the data area.
3842
3843
3844 -f The number of 512-byte blocks on files that can be written by
3845 the current process or by child processes (files of any size
3846 can be read).
3847
3848
3849 -H Specifies a hard limit for the specified resource.
3850
3851 A hard limit cannot be increased once it is set.
3852
3853 If neither the -H nor -S option is specified, the limit
3854 applies to both. The current resource limit is printed when
3855 limit is omitted. In this case, the soft limit is printed
3856 unless -H is specified.
3857
3858
3859 -m The number of Kbytes on the size of physical memory.
3860
3861
3862 -n The number of file descriptors plus 1.
3863
3864
3865 -p The number of 512-byte blocks for pipe buffering.
3866
3867
3868 -s The number of Kbytes on the size of the stack area.
3869
3870
3871 -S Specifies a soft limit for the specified resource.
3872
3873 A soft limit can be increased up to the value of the hard
3874 limit.
3875
3876 If neither the -H nor -S option is specified, the limit
3877 applies to both. The current resource limit is printed when
3878 limit is omitted. In this case, the soft limit is printed
3879 unless -H is specified.
3880
3881
3882 -t The number of CPU seconds to be used by each process.
3883
3884
3885 -v The number of Kbytes for virtual memory.
3886
3887
3888
3889 umask [-S][mask]
3890
3891 The user file-creation mask is set to mask. mask can either be an
3892 octal number or a symbolic value as described in chmod(1).
3893
3894 If a symbolic value is specified, the new umask value is the com‐
3895 plement of the result of applying mask to the complement of the
3896 previous umask value. If mask is omitted, the current value of the
3897 mask is printed. The -S option causes the mode to be printed as a
3898 symbolic value. Otherwise, the mask is printed in octal.
3899
3900 See umask(2)
3901
3902
3903 +unalias [-a] name
3904
3905 The aliases specified by the list of names are removed from the
3906 alias list. The -a option causes all the aliases to be unset.
3907
3908
3909 +unset [-fnv] vname
3910
3911 The variables specified by the list of vnames are unassigned, i.e.,
3912 their values and attributes are erased. Read-only variables cannot
3913 be unset. If the -f option is set, then the names refer to function
3914 names. If the -v option is set, then the names refer to variable
3915 names. The -f option overrides -v. If -n is set and name is a name
3916 reference, then name is unset rather than the variable that it ref‐
3917 erences. The default is equivalent to -v. Unsetting LINENO,
3918 MAILCHECK, OPTARG, OPTIND, RANDOM, SECONDS, TMOUT, and _ removes
3919 their special meaning even if they are subsequently assigned to.
3920
3921
3922 wait [job]
3923
3924 Wait for the specified job and report its termination status. If
3925 job is not specified, then all currently active child processes are
3926 waited for. The exit status from this command is that of the last
3927 process waited for if job is specified; otherwise it is zero. See
3928 Jobs for a description of the format of job.
3929
3930
3931 whence [-afpv] name ...
3932
3933 For each name, indicate how it would be interpreted if used as a
3934 command name. The -v option produces a more verbose report. The -f
3935 option skips the search for functions. The -p option does a path
3936 search for name even if name is an alias, a function, or a reserved
3937 word. The -a option is similar to the -v option but causes all
3938 interpretations of the specified name to be reported.
3939
3940
3941 Invocation
3942 If the shell is invoked by exec(2), and the first character of argument
3943 zero ($0) is -, then the shell is assumed to be a login shell and com‐
3944 mands are read from /etc/profile and then from either .profile in the
3945 current directory or $HOME/.profile, if either file exists. Next, for
3946 interactive shells, commands are read first from /etc/ksh.kshrc, and
3947 then from the file named by performing parameter expansion, command
3948 substitution, and arithmetic substitution on the value of the environ‐
3949 ment variable ENV if the file exists. If the -s option is not present
3950 and arg and a file by the name of arg exists, then it reads and exe‐
3951 cutes this script. Otherwise, if the first arg does not contain a /, a
3952 path search is performed on the first arg to determine the name of the
3953 script to execute. The script arg must have execute permission and any
3954 setuid and setgid settings are ignored. If the script is not found on
3955 the path, arg is processed as if it named a built-in command or func‐
3956 tion.
3957
3958
3959 Commands are then read as described, and the following options are
3960 interpreted by the shell when it is invoked:
3961
3962 -c If the -c option is present, then commands are read from
3963 the first arg. Any remaining arguments become positional
3964 parameters starting at 0.
3965
3966
3967 -D A list of all double quoted strings that are preceded by
3968 a $ is printed on standard output and the shell exits.
3969 This set of strings is subject to language translation
3970 when the locale is not C or POSIX. No commands are exe‐
3971 cuted.
3972
3973
3974 -i If the -i option is present or if the shell input and
3975 output are attached to a terminal (as told by tcge‐
3976 tattr(3C), this shell is interactive. In this case TERM
3977 is ignored (so that kill 0 does not kill an interactive
3978 shell) and INTR is caught and ignored (so that wait is
3979 interruptible). In all cases, QUIT is ignored by the
3980 shell.
3981
3982
3983 -R filename The -R filename option is used to generate a cross ref‐
3984 erence database that can be used by a separate utility
3985 to find definitions and references for variables and
3986 commands.
3987
3988
3989 -r If the -r option is present, the shell is a restricted
3990 shell.
3991
3992
3993 -s If the -s option is present or if no arguments remain,
3994 then commands are read from the standard input. Shell
3995 output, except for the output of the Special Commands
3996 listed, is written to file descriptor 2.
3997
3998
3999
4000 The remaining options and arguments are described under the set com‐
4001 mand. An optional - as the first argument is ignored.
4002
4003 rksh93 Only
4004 rksh93 is used to set up login names and execution environments whose
4005 capabilities are more controlled than those of the standard shell.
4006
4007
4008 The actions of rksh93 are identical to those of ksh93, except that the
4009 following are disallowed:
4010
4011 o Unsetting the restricted option
4012
4013 o Changing directory. See cd(1).
4014
4015 o Setting or unsetting the value or attributes of SHELL, ENV,
4016 FPATH, or PATH
4017
4018 o Specifying path or command names containing /,
4019
4020 o Redirecting output (>, >|, <>, and >>).
4021
4022 o Adding or deleting built-in commands.
4023
4024 o Using command -p to invoke a command.
4025
4026
4027 These restrictions are enforced after .profile and the ENV files are
4028 interpreted.
4029
4030
4031 When a command to be executed is found to be a shell procedure, rksh93
4032 invokes ksh93 to execute it. Thus, it is possible to provide to the
4033 end-user shell procedures that have access to the full power of the
4034 standard shell, while imposing a limited menu of commands. This scheme
4035 assumes that the end-user does not have write and execute permissions
4036 in the same directory. The net effect of these rules is that the writer
4037 of the .profile has complete control over user actions, by performing
4038 guaranteed setup actions and leaving the user in an appropriate direc‐
4039 tory (probably not the login directory). The system administrator often
4040 sets up a directory of commands, for example, /usr/rbin, that can be
4041 safely invoked by rksh.
4042
4044 See largefile(5) for the description of the behavior of ksh93 and
4045 rksh93 when encountering files greater than or equal to 2 Gbyte ( 2^31
4046 bytes).
4047
4049 The following exit values are returned:
4050
4051 non-zero
4052
4053 Returns non-zero when errors, such as syntax errors, are detected
4054 by the shell.
4055
4056 If the shell is being used non-interactively, then execution of the
4057 shell file is abandoned unless the error occurs inside a sub-shell
4058 in which case the sub-shell is abandoned.
4059
4060
4061 exit status of last command executed
4062
4063 Returns the exit status of the last command executed.
4064
4065 Run time errors detected by the shell are reported by printing the
4066 command or function name and the error condition. If the line num‐
4067 ber that the error occurred on is greater than one, then the line
4068 number is also printed in square brackets ([]) after the command or
4069 function name.
4070
4071 See the ksh93 exit command for additional details.
4072
4073
4075 /etc/profile
4076
4077 The system initialization file, executed for login shells.
4078
4079
4080 /etc/ksh.kshrc
4081
4082 The system wide startup file, executed for interactive shells.
4083
4084
4085 $HOME/.profile
4086
4087 The personal initialization file, executed for login shells after
4088 /etc/profile.
4089
4090
4091 $HOME/.kshrc
4092
4093 Default personal initialization file, executed after
4094 /etc/ksh.kshrc, for interactive shells when ENV is not set.
4095
4096
4097 /etc/suid-profile
4098
4099 Alternative initialization file, executed instead of the personal
4100 initialization file when the real and effective user or group id do
4101 not match.
4102
4103
4104 /dev/null
4105
4106 NULL device.
4107
4108
4110 David Korn, dgk@research.att.com
4111
4113 See attributes(5) for descriptions of the following attributes:
4114
4115
4116
4117
4118 ┌─────────────────────────────┬─────────────────────────────┐
4119 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
4120 ├─────────────────────────────┼─────────────────────────────┤
4121 │Availability │SUNWcsu │
4122 ├─────────────────────────────┼─────────────────────────────┤
4123 │Interface Stability │See below. │
4124 └─────────────────────────────┴─────────────────────────────┘
4125
4126
4127 The scripting interface is Uncommitted. The environment variables,
4128 .paths feature, and editing modes are Volatile.
4129
4131 cat(1), cd(1), chmod(1), cut(1), date(1), egrep(1), echo(1), egrep(1),
4132 env(1), fgrep(1), grep(1), login(1), newgrp(1), paste(1), printf(1),
4133 stty(1), test(1), umask(1), vi(1), dup(2), exec(2), fork(2), ioctl(2),
4134 lseek(2), pathconf(2), pipe(2), sysconf(3C), ulimit(2), umask(2),
4135 rand(3C)tcgetattr(3C), wait(3C), a.out(4), profile(4), attributes(5),
4136 environ(5), largefile(5), standards(5)
4137
4138
4139 Bolsky, Morris I. and Korn, David G., The New KornShell Command and
4140 Programming Language, Prentice Hall, 1995.
4141
4142
4143 POSIX-Part 2: Shell and Utilities, IEEE Std 1003.2-1992, ISO/IEC
4144 9945-2, IEEE, 1993.
4145
4147 ksh93 scripts should choose shell function names outside the namespace
4148 used by reserved keywords of the ISO C99, C++ and JAVA languages to
4149 avoid collisions with future enhancements to ksh93.
4150
4151
4152 If a command is executed, and then a command with the same name is
4153 installed in a directory in the search path before the directory where
4154 the original command was found, the shell continues to exec the origi‐
4155 nal command. Use the -t option of the alias command to correct this
4156 situation.
4157
4158
4159 Some very old shell scripts contain a caret (^) as a synonym for the
4160 pipe character (|).
4161
4162
4163 Using the hist built-in command within a compound command causes the
4164 whole command to disappear from the history file.
4165
4166
4167 The built-in command . file reads the whole file before any commands
4168 are executed. alias and unalias commands in the file do not apply to
4169 any commands defined in the file.
4170
4171
4172 Traps are not processed while a job is waiting for a foreground
4173 process. Thus, a trap on CHLD is not executed until the foreground job
4174 terminates.
4175
4176
4177 It is a good idea to leave a space after the comma operator in arith‐
4178 metic expressions to prevent the comma from being interpreted as the
4179 decimal point character in certain locales.
4180
4181
4182 There might be some restrictions on creating a .paths file which is
4183 portable across other operating systems.
4184
4185
4186 If the system supports the 64-bit instruction set, /bin/ksh93 executes
4187 the 64-bit version of ksh93.
4188
4189
4190
4191SunOS 5.11 11 Aug sam2009 ksh93(1)