110 semicolon, to delimit a command. The first item of the first pipeline
111 of a list that is a simple command not beginning with a redirection,
112 and not occurring within a while, until, or if list , can be preceded
113 by a semicolon. This semicolon is ignored unless the showme option is
114 enabled as described with the set built-in.
115
116
117 A command is either a simple-command or one of commands in the
118 following list. Unless otherwise stated, the value returned by a
119 command is that of the last simple-command executed in the command.
120
121 for vname [ in word ... ] ;do list ;done
122
123 Each time a for command is executed, vname is set to the next word
124 taken from the in word list. If in word ... is omitted, the for
125 command executes the do list once for each positional parameter
126 that is set starting from 1. Execution ends when there are no more
127 words in the list. See Parameter Expansion.
128
129
130 (( [expr1] ; [expr2] ; [expr3] )) ;do list ;done
131
132 The arithmetic expression expr1 is evaluated first. The arithmetic
133 expression expr2 is repeatedly evaluated until it evaluates to zero
134 and when non-zero, list is executed and the arithmetic expression
135 expr3 evaluated. If any expression is omitted, then it behaves as
136 if it evaluated to 1. See Arithmetic Evaluation.
137
138
139 select vname [ in word ... ] ;do list ;done
140
141 A select command prints on standard error (file descriptor 2) the
142 set of words, each preceded by a number. If in word... is omitted,
143 the positional parameters starting from 1 are used instead. See
144 Parameter Expansion. The PS3 prompt is printed and a line is read
145 from the standard input. If this line consists of the number of one
146 of the listed words, then the value of the variable vname is set to
147 the word corresponding to this number. If this line is empty, the
148 selection list is printed again. Otherwise the value of the
149 variable vname is set to null. The contents of the line read from
150 standard input is saved in the variable REPLY. The list is executed
177
178 while list ;do list ;done
179 until list ;do list ;done
180
181 A while command repeatedly executes the while list and, if the exit
182 status of the last command in the list is zero, executes the do
183 list, otherwise the loop terminates. If no commands in the do list
184 are executed, then the while command returns a zero exit status,
185 until can be used in place of while to negate the loop termination
186 test.
187
188
189 ((expression))
190
191 The expression is evaluated using the rules for arithmetic
192 evaluation described in this manual page. If the value of the
193 arithmetic expression is non-zero, the exit status is 0. Otherwise
194 the exit status is 1.
195
196
197 (list;)
198
199 Execute list in a separate environment. If two adjacent open
200 parentheses are needed for nesting, a SPACE must be inserted to
201 avoid evaluation as an arithmetic command as described in this
202 section.
203
204 list is simply executed. Unlike the metacharacters, ( and ), { and
205 } are reserved words and must occur at the beginning of a line or
206 after a ; to be recognized.
207
208
209 [[ expression ]]
210
211 Evaluates expression and returns a zero exit status when expression
212 is true. See Conditional Expressions for a description of
213 expression.
214
215
216 function varname { list ;}
217 varname () { list ;}
218
219 Define a function which is referenced by varname. A function whose
220 varname contains a . is called a discipline function and the
221 portion of the varname preceding the last . must refer to an
222 existing variable.
223
224 The body of the function is the list of commands between { and }. A
225 function defined with the function varname syntax can also be used
226 as an argument to the . special built-in command to get the
227 equivalent behavior as if the varname() syntax were used to define
228 it. See Functions.
229
230
231 time [ pipeline ]
232
233 If pipeline is omitted, the user and system time for the current
234 shell and completed child processes is printed on standard error.
235 Otherwise, pipeline is executed and the elapsed time as well as the
236 user and system time are printed on standard error. The TIMEFORMAT
237 variable can be set to a format string that specifies how the
238 timing information should be displayed. See Shell Variables for a
239 description of the TIMEFORMAT variable.
240
241
242
243 The following reserved words are recognized as reserved only when they
244 are the first word of a command and are not quoted:
245 case
246 do
247 done
248 else
249 elif
250 esac
251 for
252 fi
253 function
254 if
255 select
256 then
257 time
258 until
259 while
260 { }
261 [[ ]]
262 !
263
264 Variable Assignments
265 One or more variable assignments can start a simple command or can be
266 arguments to the typeset, export, or readonly special built-in
267 commands. The syntax for an assignment is of the form:
268
269 varname=word
270 varname[word]=word
271
272 No space is permitted between varname and the = or between = and
273 word.
274
275
276 varname=(assignlist)
277
278 No space is permitted between varname and the =. An assignlist can
279 be one of the following:
280
281 word ...
282
283 Indexed array assignment.
284
285
286 [word]=word ...
287
288 Associative array assignment. If prefixed by typeset -a,
289 creates an indexed array instead.
290
291
292 assignment ...
293
294 Compound variable assignment. This creates a compound variable
295 varname with sub-variables of the form varname.name, where name
296 is the name portion of assignment. The value of varname
297 contains all the assignment elements. Additional assignments
298 made to sub-variables of varname are also displayed as part of
299 the value of varname. If no assignments are specified, varname
300 is a compound variable allowing subsequence child elements to
301 be defined.
302
303
304 typeset [options] assignment ...
305
306 Nested variable assignment. Multiple assignments can be
307 specified by separating each of them with a ;. The previous
308 value is unset before the assignment.
309
310 In addition, a += can be used in place of the = to signify adding
311 to or appending to the previous value. When += is applied to an
312 arithmetic type, word is evaluated as an arithmetic expression and
313 added to the current value. When applied to a string variable, the
314 value defined by word is appended to the value. For compound
315 assignments, the previous value is not unset and the new values are
316 appended to the current ones provided that the types are
317 compatible.
318
319
320 Comments
321 A word beginning with # causes that word and all the following
322 characters up to a NEWLINE to be commented, or ignored.
323
324 Aliasing
325 The first word of each command is replaced by the text of an alias if
326 an alias for this word has been defined. An alias name consists of any
327 number of characters excluding metacharacters, quoting characters, file
328 expansion characters, parameter expansion characters, command
329 substitution characters, and =. The replacement string can contain any
330 valid shell script including the metacharacters listed in the Commands
331 section. The first word of each command in the replaced text, other
332 than any that are in the process of being replaced, are tested for
333 aliases. If the last character of the alias value is a BLANK then the
334 word following the alias is also checked for alias substitution.
335
336
337 Aliases can be used to redefine built-in commands but cannot be used to
338 redefine the reserved words listed in the Commands section. Aliases can
339 be created and listed with the alias command and can be removed with
340 the unalias command.
341
342
343 Aliasing is performed when scripts are read, not while they are
344 executed. For an alias to take effect, the alias definition command has
345 to be executed before the command which references the alias is read.
346 The following aliases are compiled into the shell but can be unset or
347 redefined:
348
349 autoload='typeset -fu'
350 command='command '
351 fc=hist
352 float='typeset -lE'
353 functions='typeset -f'
354 hash='alias -t --'
355 history='hist -l'
356 integer='typeset -li'
357 nameref='typeset -n'
358 nohup='nohup '
359 r='hist -s'
360 redirect='command exec'
361 source='command .'
362 stop='kill -s STOP'
363 suspend='kill -s STOP $$'
364 times='{ { time;} 2>&1;}'
365 type='whence -v'
366
367
368
369 Tilde Substitution
370 After alias substitution is performed, each word is checked to see if
371 it begins with an unquoted tilde (~). For tilde substitution, word also
372 refers to the word portion of parameter expansion. See Parameter
373 Expansion.
374
375
376 If it does, the word up to a / is checked to see if it matches a user
377 name in the password database. If a match is found, the ~ and the
378 matched login name are replaced by the login directory of the matched
379 user. If no match is found, the original text is left unchanged. A ~ by
380 itself, or in front of a /, is replaced by $HOME. A ~ followed by a +
381 or - is replaced by the value of $PWD and $OLDPWD respectively.
382
383
384 In addition, when expanding a variable assignment, tilde substitution
385 is attempted when the value of the assignment begins with a ~, and when
386 a ~ appears after a colon (:). The : also terminates a ~ login name.
387
388 Command Substitution
389 The standard output from a command enclosed in parentheses preceded by
390 a dollar sign ($) or a pair of grave accents (``) can be used as part
391 or all of a word. Trailing NEWLINEs are removed. In the second
392 (obsolete) form, the string between the quotes is processed for special
393 quoting characters before the command is executed. See Quoting.
394
395
396 The command substitution $(cat file) can be replaced by the equivalent
397 but faster $(<file). The command substitution $(n<#) expands to the
398 current byte offset for file descriptor n.
399
400 Arithmetic Substitution
401 An arithmetic expression enclosed in double parentheses preceded by a
402 dollar sign ( $((arithmetic_expression))) is replaced by the value of
403 the arithmetic expression within the double parentheses.
404
405 Process Substitution
406 Process substitution is only available on versions of the UNIX
407 operating system that support the /dev/fd directory for naming open
408 files.
409
410
411 Each command argument of the form <(list) or >(list) runs process list
412 asynchronously connected to some file in /dev/fd. The name of this file
413 becomes the argument to the command. If the form with > is selected
414 then writing on this file provides input for list. If < is used, then
415 the file passed as an argument contains the output of the list process.
416
417
418 For example,
419
420 paste <(cut -f1 file1) <(cut -f3 file2) | tee \
421 >(process1) >(process2)
422
423
424
425
426 cuts fields 1 and 3 from the files file1 and file2 respectively, pastes
427 the results together, and sends it to the processes process1 and
428 process2. It also displays the results to the standard output. The
429 file, which is passed as an argument to the command, is a UNIX pipe(2).
430 Programs that expect to lseek(2) on the file do not work.
431
432 Parameter Expansion
433 A parameter is a variable, one or more digits, or any of the characters
434 *, @, #, ?, -, $, and !. A variable is denoted by a vname. To create a
435 variable whose vname contains a ., a variable whose vname consists of
436 everything before the last . must already exist. A variable has a value
437 and zero or more attributes. Variables can be assigned values and
438 attributes by using the typeset special built-in command. The
439 attributes supported by the shell are described later with the typeset
440 special built-in command. Exported variables pass values and attributes
441 to the environment.
442
443
444 The shell supports both indexed and associative arrays. An element of
445 an array variable is referenced by a subscript. A subscript for an
446 indexed array is denoted by an arithmetic expression, (see Arithmetic
447 Evaluation), between a [ and a ]. Use set -A vname value ... to assign
448 values to an indexed array. The value of all subscripts must be in the
449 range of 0 through 1,048,575. Indexed arrays do not need to be
450 declared. Any reference to a variable with a valid subscript is legal
451 and an array is created if necessary.
452
453
454 An associative array is created with the -A option to typeset. A
455 subscript for an associative array is denoted by a string enclosed
456 between [ and ].
457
458
459 Referencing any array without a subscript is equivalent to referencing
460 the array with subscript 0.
461
462
463 The value of a variable can be assigned by:
464
465 vname=value [vname=value] ...
466
467
468
469
470 or
471
472 vname[subscript]=value [vname[subscript]=value] ...
473
474
475
476
477 No space is allowed before or after the =. A nameref is a variable that
478 is a reference to another variable. A nameref is created with the -n
479 attribute of typeset. The value of the variable at the time of the
480 typeset command becomes the variable that is referenced whenever the
481 nameref variable is used. The name of a nameref cannot contain a dot
482 (.). When a variable or function name contains a ., and the portion of
483 the name up to the first . matches the name of a nameref, the variable
484 referred to is obtained by replacing the nameref portion with the name
485 of the variable referenced by the nameref. If a nameref is used as the
486 index of a for loop, a name reference is established for each item in
487 the list. A nameref provides a convenient way to refer to the variable
488 inside a function whose name is passed as an argument to a function.
489 For example, if the name of a variable is passed as the first argument
490 to a function, the command
491
492 typeset -n var=$1
493
494
495
496
497 inside the function causes references and assignments to var to be
498 references and assignments to the variable whose name has been passed
499 to the function. If either of the floating point attributes, -E, or -F,
500 or the integer attribute, -i, is set for vname, then the value is
501 subject to arithmetic evaluation as described in this manual page.
502 Positional parameters, parameters denoted by a number, can be assigned
503 values with the set special built-in command. Parameter $0 is set from
504 argument zero when the shell is invoked. The character $ is used to
505 introduce substitutable parameters.
506
507 ${parameter}
508
509 The shell reads all the characters from ${ to the matching } as
510 part of the same word even if it contains braces or metacharacters.
511 The value, if any, of the parameter is substituted. The braces are
512 required when parameter is followed by a letter, digit, or
513 underscore that is not to be interpreted as part of its name, when
514 the variable name contains a ., or when a variable is subscripted.
515 If parameter is one or more digits then it is a positional
516 parameter. A positional parameter of more than one digit must be
517 enclosed in braces. If parameter is * or @, then all the positional
518 parameters, starting with $1, are substituted and separated by a
519 field separator character. If an array vname with subscript * or @
520 is used, then the value for each of the elements is substituted,
521 separated by the first character of the value of IFS.
522
523
524 ${#parameter}
525
526 If parameter is * or @, the number of positional parameters is
527 substituted. Otherwise, the length of the value of the parameter is
528 substituted.
529
530
531 ${#vname[*]}
532 ${#vname[@]}
533
534 The number of elements in the array vname is substituted.
535
536
537 ${!vname}
538
539 Expands to the name of the variable referred to by vname. This is
540 vname except when vname is a name reference.
541
542
543 ${!vname[subscript]}
544
545 Expands to name of the subscript unless subscript is * or @. When
546 subscript is *, the list of array subscripts for vname is
547 generated. For a variable that is not an array, the value is 0 if
548 the variable is set. Otherwise it is null. When subscript is @, it
549 is the same as $ {vname[*]}, except that when used in double
550 quotes, each array subscript yields a separate argument.
551
552
553 ${!prefix*}
554
555 Expands to the names of the variables whose names begin with
556 prefix.
557
558
559 ${parameter:-word}
560
561 If parameter is set and is non-null then substitute its value.
562 Otherwise substitute word.
563
564 word is not evaluated unless it is to be used as the substituted
565 string.
566
567 In the following example, pwd is executed only if d is not set or
568 is NULL:
569
570 print ${d:-$(pwd)}
571
572
573 If the colon (: ) is omitted from the expression, the shell only
574 checks whether parameter is set or not.
575
576
577 ${parameter:=word}
578
579 If parameter is not set or is null, set it to word. The value of
580 the parameter is then substituted. Positional parameters cannot be
581 assigned to in this way.
582
583 word is not evaluated unless it is to be used as the substituted
584 string.
585
586 In the following example, pwd is executed only if d is not set or
587 is NULL:
588
589 print ${d:-$(pwd)}
590
591
592 If the colon (:) is omitted from the expression, the shell only
593 checks whether parameter is set or not.
594
595
596 ${parameter:?word}
597
598 If parameter is set and is non-null, substitute its value.
599 Otherwise, print word and exit from the shell , if the shell is not
600 interactive. If word is omitted then a standard message is printed.
601
602 word is not evaluated unless it is to be used as the substituted
603 string.
604
605 In the following example, pwd is executed only if d is not set or
606 is NULL:
607
608 print ${d:-$(pwd)}
609
610
611 If the colon (: ) is omitted from the expression, the shell only
612 checks whether parameter is set or not.
613
614
615 ${parameter:+word}
616
617 If parameter is set and is non-null, substitute word. Otherwise
618 substitute nothing.
619
620 word is not evaluated unless it is to be used as the substituted
621 string.
622
623 In the following example, pwd is executed only if d is not set or
624 is NULL:
625
626 print ${d:-$(pwd)}
627
628
629 If the colon (:) is omitted from the expression, the shell only
630 checks whether parameter is set or not.
631
632
633 ${parameter:offset:length}
634 ${parameter:offset}
635
636 Expands to the portion of the value of parameter starting at the
637 character (counting from 0) determined by expanding offset as an
638 arithmetic expression and consisting of the number of characters
639 determined by the arithmetic expression defined by length.
640
641 In the second form, the remainder of the value is used. A negative
642 offset counts backwards from the end of parameter.
643
644 One or more BLANKs is required in front of a minus sign to prevent
645 the shell from interpreting the operator as :-. If parameter is *
646 or @, or is an array name indexed by * or @, then offset and length
647 refer to the array index and number of elements respectively. A
648 negative offset is taken relative to one greater than the highest
649 subscript for indexed arrays. The order for associative arrays is
650 unspecified.
721 command.
722
723
724 $
725 The process number of this shell.
726
727
728 _
729 Initially, the value of _ is the absolute pathname
730 of the shell or script being executed as passed in
731 the environment. It is subsequently assigned the
732 last argument of the previous command.
733
734 This parameter is not set for commands which are
735 asynchronous. This parameter is also used to hold
736 the name of the matching MAIL file when checking for
737 mail.
738
739
740 !
741 The process number of the last background command
742 invoked or the most recent job put in the background
743 with the bg built-in command.
744
745
746 .sh.command
747 When processing a DEBUG trap, this variable contains
748 the current command line that is about to run.
749
750
751 .sh.edchar
752 This variable contains the value of the keyboard
753 character (or sequence of characters if the first
754 character is an ESC, ASCII 033) that has been
755 entered when processing a KEYBD trap. If the value
756 is changed as part of the trap action, then the new
757 value replaces the key (or key sequence) that caused
758 the trap. See the Key Bindings section of this
759 manual page.
760
761
762 .sh.edcol
763 The character position of the cursor at the time of
781 The pathname of the file than contains the current
782 command.
783
784
785 .sh.fun
786 The name of the current function that is being
787 executed.
788
789
790 .sh.match
791 An indexed array which stores the most recent match
792 and sub-pattern matches after conditional pattern
793 matches that match and after variables expansions
794 using the operators #, %, or /. The 0th element
795 stores the complete match and the ith element stores
796 the ith sub-match. The .sh.match variable is unset
797 when the variable that has expanded is assigned a
798 new value.
799
800
801 .sh.name
802 Set to the name of the variable at the time that a
803 discipline function is invoked.
804
805
806 .sh.subscript
807 Set to the name subscript of the variable at the
808 time that a discipline function is invoked.
809
810
811 .sh.subshell
812 The current depth for sub-shells and command
813 substitution.
814
815
816 .sh.value
817 Set to the value of the variable at the time that
818 the set or append discipline function is invoked.
819
820
821 .sh.version
822 Set to a value that identifies the version of this
823 shell.
824
825
826 LINENO
827 The current line number within the script or
828 function being executed.
829
830
831 OLDPWD
832 The previous working directory set by the cd
833 command.
834
835
836 OPTARG
837 The value of the last option argument processed by
838 the getopts built-in command.
856 integer, uniformly distributed between 0 and 32767,
857 is generated. The sequence of random numbers can be
858 initialized by assigning a numeric value to RANDOM.
859
860
861 REPLY
862 This variable is set by the select statement and by
863 the read built-in command when no arguments are
864 supplied.
865
866
867 SECONDS
868 Each time this variable is referenced, the number of
869 seconds since shell invocation is returned. If this
870 variable is assigned a value, then the value
871 returned upon reference is the value that was
872 assigned plus the number of seconds since the
873 assignment.
874
875
876
877 The following variables are used by the shell:
878
879 CDPATH
880 Defines the search path for the cd command.
881
882
883 COLUMNS
884 Defines the width of the edit window for the shell edit
885 modes and for printing select lists.
886
887
888 EDITOR
889 If the VISUAL variable is not set, the value of this
890 variable is checked for the patterns as described with
891 VISUAL and the corresponding editing option is turned on.
892
893 See the set command in the Special Command section of
894 this manual page.
895
896
965 substitution or parameter expansion and to separate
966 fields with the built-in command read. The first
967 character of the IFS variable is used to separate
968 arguments for the "$*" substitution. See the Quoting
969 section of this manual page.
970
971 Each single occurrence of an IFS character in the string
972 to be split, that is not in the issspace character class,
973 and any adjacent characters in IFS that are in the
974 issspace character class, delimit a field. One or more
975 characters in IFS that belong to the issspace character
976 class, delimit a field. In addition, if the same issspace
977 character appears consecutively inside IFS, this
978 character is treated as if it were not in the issspace
979 class, so that if IFS consists of two tab characters,
980 then two adjacent tab characters delimit a null field.
981
982 The shell specifies a default value to IFS.
983
984
985 LANG
986 This variable determines the locale category for any
987 category not specifically selected with a variable
988 starting with LC_ or LANG.
989
990
991 LC_ALL
992 This variable overrides the value of the LANG variable
993 and any other LC_ variable.
994
995
996 LC_COLLATE
997 This variable determines the locale category for
998 character collation information.
999
1000
1001 LC_CTYPE
1002 This variable determines the locale category for
1003 character handling functions. It determines the
1004 character classes for pattern matching. See the File Name
1233 unless the first character of the pattern corresponding to this
1234 component is the character . itself. For other uses of pattern matching
1235 the / and . are not specially treated.
1236
1237 *
1238 Match any string, including the null string. When used for
1239 file name expansion, if the globstar option is on, two
1240 adjacent *s by themselves match all files and zero or more
1241 directories and subdirectories. If the two adjacent *s are
1242 followed by a /, only directories and subdirectories match.
1243
1244
1245 ?
1246 Matches any single character.
1247
1248
1249 [...]
1250 Match any one of the enclosed characters. A pair of
1251 characters separated by - matches any character lexically
1252 between the pair, inclusive. If the first character
1253 following the opening [ is a !, any character not enclosed
1254 is matched. A - can be included in the character set by
1255 putting it as the first or last character. Within [ and ],
1256 character classes can be specified with the syntax [:class:]
1257 where class is one of the following classes defined in the
1258 ANSI-C standard:
1259
1260 alnum alpha blank cntrl digit graph
1261 lower print punct space upper
1262 word xdigit
1263
1264
1265 word is equivalent to alnum plus the character _. Within [
1266 and ], an equivalence class can be specified with the syntax
1267 [=c=] which matches all characters with the same primary
1268 collation weight (as defined by the current locale) as the
1269 character c. Within [ and ], [.symbol.] matches the
1270 collating symbol symbol.
1271
1272
1273
1274 A pattern-list is a list of one or more patterns separated from each
1275 other with an & or |. An & signifies that all patterns must be matched
1276 whereas | requires that only one pattern be matched. Composite patterns
1277 can be formed with one or more of the following sub-patterns:
1278
1378 causing all characters other than any escape character to be
1379 ignored when looking for a match.
1380
1381
1382
1383 %({}Q"E\), matches characters starting at { until the matching } is
1384 found not counting any { or } that is inside a double quoted string or
1385 preceded by the escape character \. Without the {} this pattern matches
1386 any C language string.
1387
1388
1389 Each sub-pattern in a composite pattern is numbered, starting at 1, by
1390 the location of the ( within the pattern. The sequence \n, where n is a
1391 single digit and \n comes after the nth. sub-pattern, matches the same
1392 string as the sub-pattern itself.
1393
1394
1395 A pattern can contain sub-patterns of the form ~(options:pattern-list),
1396 where either options or :pattern-list can be omitted. Unlike the other
1397 compound patterns, these sub-patterns are not counted in the numbered
1398 sub-patterns. If options is present, it can consist of one or more of
1399 the following:
1400
1401 +
1402 Enable the following options. This is the default.
1403
1404
1405 -
1406 Disable the following options.
1407
1408
1409 E
1410 The remainder of the pattern uses extended regular expression
1411 syntax like the egrep(1) command.
1412
1413
1414 F
1415 The remainder of the pattern uses fgrep(1) expression syntax.
1416
1417
1418 g
1419 File the longest match (greedy).
1437
1438
1439 l
1440 Left anchor the pattern.
1441
1442 This is the default for K style patterns.
1443
1444
1445 N
1446 This is ignored. However, when it is the first letter and is used
1447 with file name generation, and no matches occur, the file pattern
1448 expands to the empty string.
1449
1450
1451 r
1452 Right anchor the pattern.
1453
1454 This is the default for K style patterns.
1455
1456
1457
1458 If both options and :pattern-list are specified, then the options apply
1459 only to pattern-list. Otherwise, these options remain in effect until
1460 they are disabled by a subsequent ~(...) or at the end of the sub-
1461 pattern containing ~(...).
1462
1463 Quoting
1464 Each of the metacharacters listed in the Definitions has a special
1465 meaning to the shell.
1466
1467 g
1468 File the longest match (greedy). This is the default.
1469
1470
1471 i
1472 Treat the match as case insensitive.
1473
1474
1475
1476 If both options and :pattern-list are specified, then the options apply
1477 only to pattern-list. Otherwise, the options remain in effect until
1478 they are disabled by a subsequent ~(...) or at the end of the sub-
1479 pattern containing ~(...).
1480
1481
1482 Each of the metacharacters listed in the Definitions section of this
1483 manual page has a special meaning to the shell and causes termination
1484 of a word unless quoted. A character can be quoted, that is, made to
1485 stand for itself, by preceding it with a backslash (\). The pair
1486 \NEWLINE is removed. All characters enclosed between a pair of single
1487 quote marks ('') that is not preceded by a $ are quoted. A single quote
1488 cannot appear within the single quotes. A single quoted string preceded
1489 by an unquoted $ is processed as an ANSI-C string except for the
1490 following:
1491
1492 \0
1493 Causes the remainder of the string to be ignored.
1494
1495
1496 \cx
1497 Expands to the character CTRL-x.
1498
1499
1500 \C[.name.]
1501 Expands to the collating element name.
1502
1503
1504 \e
1505 Equivalent to the escape character (ASCII 033),
1506
1507
1508 \E
1509 Equivalent to the escape character (ASCII 033),
1510
1511
1512
1513 Inside double quote marks (""), parameter and command substitution
1514 occur and \ quotes the characters \, `, ", and $. A $ in front of a
1515 double quoted string is ignored in the C or POSIX locale, and might
1516 cause the string to be replaced by a locale specific string otherwise.
1517 The meaning of $* and $@ is identical when not quoted or when used as a
1518 variable assignment value or as a file name. However, when used as a
1519 command argument, "$*" is equivalent to "$1d$2d...", where d is the
1520 first character of the IFS variable, whereas "$@" is equivalent to "$1"
1521 "$2" .... Inside grave quote marks (``), \fR quotes the characters \,
1522 `, and $. If the grave quotes occur within double quotes, then \ also
1523 quotes the character ".
1524
1525
1526 The special meaning of reserved words or aliases can be removed by
1527 quoting any character of the reserved word. The recognition of function
1528 names or built-in command names cannot be altered by quoting them.
1529
1530 Arithmetic Evaluation
1531 The shell performs arithmetic evaluation for arithmetic substitution,
1532 to evaluate an arithmetic command, to evaluate an indexed array
1533 subscript, and to evaluate arguments to the built-in commands shift and
1534 let. Arithmetic evaluation is also performed on argument operands of
1535 the built-in command printf that correspond to numeric format
1536 specifiers in the format operand. See printf(1). Evaluations are
1537 performed using double precision floating point arithmetic or long
1538 double precision floating point for systems that provide this data
1539 type. Floating point constants follow the ANSI-C programming language
1540 floating point conventions. Integer constants follow the ANSI-C
1541 programming language integer constant conventions although only single
1542 byte character constants are recognized and character casts are not
1543 recognized. Constants can be of the form [base#]n where base is a
1544 decimal number between two and sixty-four representing the arithmetic
1545 base and n is a number in that base. The digits greater than 9 are
1546 represented by the lower case letters, the upper case letters, @, and _
1547 respectively. For bases less than or equal to 36, upper and lower case
1548 characters can be used interchangeably.
1549
1550
1551 An arithmetic expression uses the same syntax, precedence, and
1552 associativity of expression as the C language. All the C language
1553 operators that apply to floating point quantities can be used. In
1554 addition, the operator ** can be used for exponentiation. It has higher
1555 precedence than multiplication and is left associative. When the value
1556 of an arithmetic variable or subexpression can be represented as a long
1557 integer, all C language integer arithmetic operations can be performed.
1558 Variables can be referenced by name within an arithmetic expression
1559 without using the parameter expansion syntax. When a variable is
1560 referenced, its value is evaluated as an arithmetic expression.
1561
1562
1563 Any of the following math library functions that are in the C math
1564 library can be used within an arithmetic expression:
1565
1566 abs acos acosh asin asinh atan atan2 atanh cbrt
1567 copysign cos cosh erf erfc exp exp2 expm1 fabs
1568 fdim finite floor fma fmax fmod hypot ilogb
1569 int isinf isnan lgamma log log2 logb
1570 nearbyint nextafter nexttoward pow remainder
1571 rint round sin sinh sqrt tan tanh tgamma trunc
1572
1573
1574
1575
1576 An internal representation of a variable as a double precision floating
1577 point can be specified with the -E [n] or -F [n] option of the typeset
1578 special built-in command. The -E option causes the expansion of the
1579 value to be represented using scientific notation when it is expanded.
1580 The optional option argument n defines the number of significant
1581 figures. The -F option causes the expansion to be represented as a
1582 floating decimal number when it is expanded. The optional option
1583 argument n defines the number of places after the decimal point in this
1584 case.
1585
1586
1587 An internal integer representation of a variable can be specified with
1588 the -i [n] option of the typeset special built-in command. The optional
1589 option argument n specifies an arithmetic base to be used when
1590 expanding the variable. If you do not specify an arithmetic base, base
1591 10 is used.
1592
1593
1594 Arithmetic evaluation is performed on the value of each assignment to a
1595 variable with the -E, -F, or -i option. Assigning a floating point
1596 number to a variable whose type is an integer causes the fractional
1597 part to be truncated.
1598
1599 Prompting
1600 When used interactively, the shell prompts with the value of PS1 after
1601 expanding it for parameter expansion, command substitution, and
1602 arithmetic substitution, before reading a command. In addition, each
1603 single ! in the prompt is replaced by the command number. A !! is
1604 required to place ! in the prompt. If at any time a NEWLINE is typed
1605 and further input is needed to complete a command, then the secondary
1606 prompt, that is, the value of PS2, is issued.
1607
1608 Conditional Expressions
1609 A conditional expression is used with the [[ compound command to test
1610 attributes of files and to compare strings. Field splitting and file
1611 name generation are not performed on the words between [[ and ]].
1612
1613
1614 Each expression can be constructed from one or more of the following
1615 unary or binary expressions:
1681 -o ?option
1682 True, if option named option is a valid option
1683 name.
1684
1685
1686 -O file
1687 True, if file exists and is owned by the effective
1688 user id of this process.
1689
1690
1691 -p file
1692 True, if file exists and is a FIFO special file or
1693 a pipe.
1694
1695
1696 -r file
1697 True, if file exists and is readable by current
1698 process.
1699
1700
1701 -s file
1702 True, if file exists and has size greater than
1703 zero.
1704
1705
1706 -S file
1707 True, if file exists and is a socket.
1708
1709
1710 -t fildes
1711 True, if file descriptor number fildes is open and
1712 associated with a terminal device.
1713
1714
1715 -u file
1716 True, if file exists and it has its setuid bit
1717 set.
1718
1719
1720 -w file
1721 True, if file exists and is writable by current
1722 process.
1723
1724
1725 -x file
1726 True, if file exists and is executable by current
1727 process. If file exists and is a directory, then
1728 true if the current process has permission to
1729 search in the directory.
1730
1731
1732 -z string
1733 True, if length of string is zero.
1734
1735
1736 file1 -ef file2
1737 True, if file1 and file2 exist and refer to the
1738 same file.
1739
1769 string matches the pattern the .sh.match array
1770 variable contains the match and sub-pattern
1771 matches.
1772
1773
1774 string =~ ere
1775 True if string matches the pattern ~(E)ere where
1776 ere is an extended regular expression.
1777
1778
1779 string1 < string2
1780 True, if string1 comes before string2 based on
1781 ASCII value of their characters.
1782
1783
1784 string1 > string2
1785 True, if string1 comes after string2 based on
1786 ASCII value of their characters.
1787
1788
1789
1790 In each of the following expressions, if file is of the form /dev/fd/n,
1791 where n is an integer, the test is applied to the open file whose
1792 descriptor number is n. The following obsolete arithmetic comparisons
1793 are supported:
1794
1795 exp1 -eq exp2
1796 True, if exp1 is equal to exp2.
1797
1798
1799 exp1 -ge exp2
1800 True, if exp1 is greater than or equal to exp2.
1801
1802
1803 exp1 -gt exp2
1804 True, if exp1 is greater than exp2.
1805
1806
1807 exp1 -le exp2
1808 True, if exp1 is less than or equal to exp2.
1809
1810
1811 exp1 -lt exp2
1812 True, if exp1 is less than exp2.
1813
1814
1858
1859
1860 No intervening space is allowed between the characters of redirection
1861 operators.
1862
1863 <word
1864 Use file word as standard input (file descriptor 0).
1865
1866
1867 >word
1868 Use file word as standard output (file descriptor 1). If
1869 the file does not exist then it is created. If the file
1870 exists, and the noclobber option is on, this causes an
1871 error. Otherwise, it is truncated to zero length.
1872
1873
1874 >|word
1875 Same as >, except that it overrides the noclobber option.
1876
1877
1878 >>word
1879 Use file word as standard output. If the file exists,
1880 then output is appended to it (by first seeking to the
1881 end-of-file). Otherwise, the file is created.
1882
1883
1884 <>word
1885 Open file word for reading and writing as standard input.
1886
1887
1888 <<[-]word
1889 The shell input is read up to a line that is the same as
1890 word after any quoting has been removed, or to an end-of-
1891 file. No parameter substitution, command substitution,
1892 arithmetic substitution or file name generation is
1893 performed on word. The resulting document, called a here-
1894 document, becomes the standard input. If any character of
1895 word is quoted, then no interpretation is placed upon the
1896 characters of the document. Otherwise, parameter
1897 expansion, command substitution, and arithmetic
2118 built-in utility. If the get discipline is defined for a variable, it
2119 is invoked whenever the specified variable is referenced. If the
2120 variable .sh.value is assigned a value inside the discipline function,
2121 the referenced variable is evaluated to this value instead. If the set
2122 discipline is defined for a variable, it is invoked whenever the
2123 specified variable is assigned a value. If the append discipline is
2124 defined for a variable, it is invoked whenever a value is appended to
2125 the specified variable. The variable .sh.value is specified the value
2126 of the variable before invoking the discipline, and the variable is
2127 assigned the value of .sh.value after the discipline completes. If
2128 .sh.value is unset inside the discipline, then that value is unchanged.
2129 If the unset discipline is defined for a variable, it is invoked
2130 whenever the specified variable is unset. The variable is not unset
2131 unless it is unset explicitly from within this discipline function.
2132
2133
2134 The variable .sh.name contains the name of the variable for which the
2135 discipline function is called, .sh.subscript is the subscript of the
2136 variable, and .sh.value contains the value being assigned inside the
2137 set discipline function. For the set discipline, changing .sh.value
2138 changes the value that gets assigned.
2139
2140 Jobs
2141 If the monitor option of the set command is turned on, an interactive
2142 shell associates a job with each pipeline. It keeps a table of current
2143 jobs, printed by the jobs command, and assigns them small integer
2144 numbers. When a job is started asynchronously with &, the shell prints
2145 a line which looks like:
2146
2147 [1] 1234
2148
2149
2150
2151
2152 indicating that the job which was started asynchronously was job number
2153 1 and had one (top-level) process, whose process id was 1234.
2154
2155
2156 If you are running a job and wish to stop it, CTRL-z sends a STOP
2157 signal to the current job. The shell normally displays a message that
2158 the job has been stopped, and displays another prompt. You can then
2159 manipulate the state of this job, putting it in the background with the
2160 bg command, or run some other commands and then eventually bring the
2161 job back into the foreground with the foreground command fg. A CTRL-z
2162 takes effect immediately and is like an interrupt in that pending
2163 output and unread input are discarded when it is typed.
2164
2165
2166 A job being run in the background stops if it tries to read from the
2167 terminal. Background jobs are normally allowed to produce output, but
2168 this can be disabled by giving the command sttytostop. If you set this
2169 tty option, then background jobs stop when they try to produce output
2170 like they do when they try to read input.
2171
2172
2173 There are several ways to refer to jobs in the shell. A job can be
2174 referred to by the process id of any process of the job or by one of
2175 the following:
2176
2177 %number
2178 The job with the specified number.
2179
2180
2181 %string
2182 Any job whose command line begins with string.
2183
2184
2185 %?string
2186 Any job whose command line contains string.
2187
2188
2189 %%
2190 Current job.
2191
2192
2193 %+
2194 Equivalent to %%.
2195
2196
2197 %-
2198 Previous job.
2199
2200
2201
2202 The shell learns immediately whenever a process changes state. It
2203 normally informs you whenever a job becomes blocked so that no further
2204 progress is possible, but only just before it prints a prompt. This is
2205 done so that it does not otherwise disturb your work. The notify option
2206 of the set command causes the shell to print these job change messages
2207 as soon as they occur.
2208
2209
2210 When the monitor option is on, each background job that completes
2211 triggers any trap set for CHLD.
2212
2213
2214 When you try to leave the shell while jobs are running or stopped, you
2215 are warned that You have stopped(running) jobs. You can use the jobs
2216 command to see what they are. If you immediately try to exit again, the
2217 shell does not warn you a second time, and the stopped jobs are
2218 terminated. When a login shell receives a HUP signal, it sends a HUP
2219 signal to each job that has not been disowned with the disown built-in
2220 command.
2221
2224 command is followed by & and the monitor option is not active.
2225 Otherwise, signals have the values inherited by the shell from its
2226 parent. See the trap built-in command.
2227
2228 Execution
2229 Each time a command is read, the substitutions are carried out. If the
2230 command name matches one of the ones in the Special Built-in Commands
2231 section of this manual page, it is executed within the current shell
2232 process. Next, the command name is checked to see if it matches a user
2233 defined function. If it does, the positional parameters are saved and
2234 then reset to the arguments of the function call. A function is also
2235 executed in the current shell process. When the function completes or
2236 issues a return, the positional parameter list is restored. For
2237 functions defined with the function name syntax, any trap set on EXIT
2238 within the function is executed. The exit value of a function is the
2239 value of the last command executed. If a command name is not a special
2240 built-in command or a user defined function, but it is one of the
2241 built-in commands, it is executed in the current shell process.
2242
2243
2244 The shell variable PATH defines the search path for the directory
2245 containing the command. Alternative directory names are separated by a
2246 colon (:). The default path is /bin:/usr/bin:, specifying /bin,
2247 /usr/bin, and the current directory in that order. The current
2248 directory can be specified by two or more adjacent colons, or by a
2249 colon at the beginning or end of the path list. If the command name
2250 contains a slash (/), the search path is not used. Otherwise, each
2251 directory in the path is searched for an executable file of the
2252 specified name that is not a directory. If found, and if the shell
2253 determines that there is a built-in version of a command corresponding
2254 to a specified pathname, this built-in is invoked in the current
2255 process. If found, and this directory is also contained in the value of
2256 the FPATH variable, then this file is loaded into the current shell
2257 environment as if it were the argument to the . command except that
2258 only preset aliases are expanded, and a function of the specified name
2259 is executed as described in this manual page. If not found, and the
2260 file .paths is found, and this file contains a line of the form
2261 FPATH=path where path is an existing directory, and this directory
2262 contains a file of the specified name, then this file is loaded into
2263 the current shell environment as if it were the argument to the .
2264 special built-in command and a function of the specified name is
2265 executed. Otherwise, if found, a process is created and an attempt is
2266 made to execute the command using exec(2).
2267
2268
2269 When an executable is found, the directory where it is found in is
2270 searched for a file named .paths. If this file is found and it contains
2271 a line of the form BUILTIN_LIB=value, the library named by value is
2272 searched for as if it were an option argument to builtin -f, and if it
2273 contains a built-in of the specified name this is executed instead of a
2274 command by this name. Otherwise, if this file is found and it contains
2275 a line of the form name=value in the first or second line, then the
2276 environment variable name is modified by prepending the directory
2277 specified by value to the directory list. If value is not an absolute
2278 directory, then it specifies a directory relative to the directory that
2279 the executable was found. If the environment variable name does not
2280 already exist it is added to the environment list for the specified
2281 command.
2282
2283
2284 If the file has execute permission but is not an a.out file, it is
2285 assumed to be a file containing shell commands. A separate shell is
2286 spawned to read it. All non-exported variables are removed in this
2287 case. If the shell command file doesn't have read permission, and/or if
2288 the setuid and setgid bits are set on the file, then the shell executes
2289 an agent whose job it is to set up the permissions and execute the
2290 shell with the shell command file passed down as an open file. A
2291 parenthesized command is executed in a sub-shell without removing non-
2292 exported variables.
2293
2294 Command Re-entry
2295 The text of the last HISTSIZE (default 512) commands entered from a
2296 terminal device is saved in a history file. The file $HOME/.sh_history
2297 is used if the HISTFILE variable is not set or if the file it names is
2298 not writable. A shell can access the commands of all interactive shells
2299 which use the same named HISTFILE. The built-in command hist is used to
2300 list or edit a portion of this file. The portion of the file to be
2301 edited or listed can be selected by number or by giving the first
2302 character or characters of the command. A single command or range of
2303 commands can be specified. If you do not specify an editor program as
2304 an argument to hist then the value of the variable HISTEDIT is used. If
2305 HISTEDIT is unset, the obsolete variable FCEDIT is used. If FCEDIT is
2306 not defined, then /bin/ed is used. The edited commands are printed and
2307 executed again upon leaving the editor unless you quit without writing.
2308 The -s option (and in obsolete versions, the editor name -) is used to
2309 skip the editing phase and to re-execute the command. In this case a
2310 substitution parameter of the form old=newcan be used to modify the
2311 command before execution. For example, with the preset alias r, which
2312 is aliased to 'hist -s', typing `r bad=good c' re-executes the most
2313 recent command which starts with the letter c, replacing the first
3225 bg [ job...]
3226
3227 This command is only on systems that support job control. Puts each
3228 specified job into the background. The current job is put in the
3229 background if job is not specified. See the Jobs section of this
3230 manual page for a description of the format of job.
3231
3232
3233 + break [n]
3234
3235 Exit from the enclosing for, while, until, or select loop, if any.
3236 If n is specified, then break n levels.
3237
3238
3239 builtin [-ds ] [-f file] [name ...]
3240
3241 If name is not specified, and no -f option is specified, the built-
3242 ins are printed on standard output. The -s option prints only the
3243 special built-ins. Otherwise, each name represents the pathname
3244 whose basename is the name of the built-in. The entry point
3245 function name is determined by prepending b to the built-in name.
3246 The ISO C/C++ prototype is bmycommand(int argc, char *argv[], void
3247 *context) for the built-in command mycommand where argv is an array
3248 of argc elements and context is an optional pointer to a Shell_t
3249 structure as described in <ast/shell.h> Special built-ins cannot be
3250 bound to a pathname or deleted. The -d option deletes each of the
3251 specified built-ins. On systems that support dynamic loading, the
3252 -f option names a shared library containing the code for built-ins.
3253 The shared library prefix and/or suffix, which depend on the
3254 system, can be omitted. Once a library is loaded, its symbols
3255 become available for subsequent invocations of builtin. Multiple
3256 libraries can be specified with separate invocations of the builtin
3257 command. Libraries are searched in the reverse order in which they
3258 are specified. When a library is loaded, it looks for a function in
3259 the library whose name is lib_init() and invokes this function with
3260 an argument of 0.
3261
3262
3263 cd [-LP] [arg]
3264 cd [-LP] old new
3265
3319 select loop. If n is specified, then resume at the nth enclosing
3320 loop.
3321
3322
3323 disown [job...]
3324
3325 Causes the shell not to send a HUP signal to each specified job, or
3326 all active jobs if job is omitted, when a login shell terminates.
3327
3328
3329 echo [arg ...]
3330
3331 When the first arg does not begin with a -, and none of the
3332 arguments contain a backslash (\), prints each of its arguments
3333 separated by a SPACE and terminated by a NEWLINE. Otherwise, the
3334 behavior of echo is system dependent and print or printf described
3335 in this section should be used. See echo(1) for usage and
3336 description.
3337
3338
3339 +eval [arg ...]
3340
3341 The arguments are read as input to the shell and the resulting
3342 commands are executed.
3343
3344
3345 +exec [-c] [-a name ...] [arg ...]
3346
3347 If arg is specified, the command specified by the arguments is
3348 executed in place of this shell without creating a new process. The
3349 -c option causes the environment to be cleared before applying
3350 variable assignments associated with the exec invocation. The -a
3351 option causes name rather than the first arg, to become argv[0] for
3352 the new process. Input and output arguments can appear and affect
3353 the current process. If arg is not specified, the effect of this
3354 command is to modify file descriptors as prescribed by the
3355 input/output redirection list. In this case, any file descriptor
3356 numbers greater than 2 that are opened with this mechanism are
3357 closed when invoking another program.
3358
3359
3360 +exit [n]
3361
3362 Causes the shell to exit with the exit status specified by n. The
3363 value is the least significant 8 bits of the specified status. If n
3364 is omitted, then the exit status is that of the last command
3365 executed. An end-of-file also causes the shell to exit except for a
3366 shell which has the ignoreeof option turned on. See set.
3367
3368
3369 ++export [-p] [name[=value]] ...
3370
3371 If name is not specified, the names and values of each variable
3372 with the export attribute are printed with the values quoted in a
3373 manner that allows them to be re-entered. The -p option causes the
3374 word export to be inserted before each one. Otherwise, the
3375 specified names are marked for automatic export to the environment
3376 of subsequently-executed commands.
3377
3378
3379 false
3380
3381 Does nothing, and exits 1. Used with until for infinite loops.
3382
3383
3384 fg [job ...]
3385
3386 This command is only on systems that support job control. Each job
3387 specified is brought to the foreground and waited for in the
3388 specified order. Otherwise, the current job is brought into the
3389 foreground. See Jobs for a description of the format of job.
3390
3391
3392 getconf [name [pathname]]
3393
3394 Prints the current value of the configuration parameter specified
3395 by name. The configuration parameters are defined by the IEEE POSIX
3396 1003.1 and IEEE POSIX 1003.2 standards. See pathconf(2) and
3447 for listing. The option -r reverses the order of the commands and
3448 the option -n suppresses command numbers when listing. In the
3449 second form, command is interpreted as first described in this
3450 section and defaults to the last command executed. The resulting
3451 command is executed after the optional substitution old=new is
3452 performed.
3453
3454
3455 jobs -lnp [job ...]
3456
3457 Lists information about each specified job, or all active jobs if
3458 job is omitted. The -l option lists process ids in addition to the
3459 normal information. The -n option only displays jobs that have
3460 stopped or exited since last notified. The -p option causes only
3461 the process group to be listed. See Jobs for a description of the
3462 format of job.
3463
3464
3465 kill [-s signame] job ...
3466 kill [-n signum] job ...
3467 kill -l [sig ...]
3468
3469 Sends either the TERM (terminate) signal or the specified signal to
3470 the specified jobs or processes. Signals are either specified by
3471 number with the -n option or by name with the -s option (as
3472 specified in <signal.h>, stripped of the prefix `SIG with the
3473 exception that SIGCLD is named CHLD). For backward compatibility,
3474 the n and s can be omitted and the number or name placed
3475 immediately after the -. If the signal being sent is TERM
3476 (terminate) or HUP (hang up), then the job or process is sent a
3477 CONT (continue) signal if it is stopped. The argument job can be
3478 the process id of a process that is not a member of one of the
3479 active jobs. See Jobs for a description of the format of job. In
3480 the third form, kill -l, if sig is not specified, the signal names
3481 are listed. Otherwise, for each sig that is a name, the
3482 corresponding signal number is listed. For each sig that is a
3483 number, the signal name corresponding to the least significant 8
3484 bits of sig is listed.
3485
3486
3487 let [arg ...]
3488
3489 Each arg is a separate arithmetic expression to be evaluated. See
3490 the Arithmetic Evaluation section of this manual page for a
3491 description of arithmetic expression evaluation. The exit status is
3492 0 if the value of the last expression is non-zero, and 1 otherwise.
3493
3494
3495 +newgrp [arg ...]
3496
3497 Equivalent to exec /bin/newgrp arg ...
3498
3499
3500 print [-Renprs] [ -u unit] [ -f format ] [ arg ...]
3501
3502 With no options or with option - or --, each arg is printed on
3503 standard output. The -f option causes the arguments to be printed
3504 as described by printf. In this case, any e, n, r, or R options are
3505 ignored. Otherwise, unless the -R or -r, are specified, the
3506 following escape conventions are applied:
3507
3508 \a
3509 Alert character (ASCII 07)
3510
3511
3512 \b
3513 Backspace character (ASCII 010)
3514
3515
3516 \c
3517 Causes print to end without processing more arguments and
3518 not adding a NEWLINE
3519
3520
3537 \v
3538 Vertical TAB character (ASCII 013)
3539
3540
3541 \E
3542 Escape character (ASCII 033)
3543
3544
3545 \\
3546 Backslash character \
3547
3548
3549 \0x
3550 Character defined by the 1, 2, or 3-digit octal string
3551 specified by x
3552
3553 The -R option prints all subsequent arguments and options other
3554 than -n. The -e causes the escape conventions to be applied This is
3555 the default behavior. It reverses the effect of an earlier -r. The
3556 -p option causes the arguments to be written onto the pipe of the
3557 process spawned with |& instead of standard output. The -s option
3558 causes the arguments to be written onto the history file instead of
3559 standard output. The -u option can be used to specify a one digit
3560 file descriptor unit number unit on which the output is placed. The
3561 default is 1. If the option -n is used, no NEWLINE is added to the
3562 output.
3563
3564
3565 printf format[arg ...]
3566
3567 The arguments arg are printed on standard output in accordance with
3568 the ANSI-C formatting rules associated with the format string
3569 format. If the number of arguments exceeds the number of format
3570 specifications, the format string is reused to format remaining
3571 arguments. The following extensions can also be used: A %b format
3572 can be used instead of %s to cause escape sequences in the
3573 corresponding arg to be expanded as described in print. A %B option
3574 causes each of the arguments to be treated as variable names and
3575 the binary value of the variables is printed. This is most useful
3576 for variables with an attribute of b. A %H format can be used
3577 instead of %s to cause characters in arg that are special in HTML
3578 and XML to be output as their entity name. A %P format can be used
3579 instead of %s to cause arg to be interpreted as an extended regular
3580 expression and be printed as a shell pattern. A %R format can be
3581 used instead of %s to cause arg to be interpreted as a shell
3582 pattern and to be printed as an extended regular expression. A %q
3583 format can be used instead of %s to cause the resulting string to
3584 be quoted in a manner than can be input again to the shell. A
3585 %(date-format)T format can be use to treat an argument as a
3586 date/time string and to format the date/time according to the date-
3587 format as defined for the date(1) command. A %Z format outputs a
3588 byte whose value is 0. The precision field of the %d format can be
3589 followed by a . and the output base. In this case, the # flag
3590 character causes base# to be prepended. The # flag when used with
3591 the d specifier without an output base, causes the output to be
3592 displayed in thousands units with one of the suffixes k M G T P E
3593 to indicate the unit. The # flag when used with the i specifier
3594 causes the output to be displayed in 1024 with one of the suffixes
3595 Ki Mi Gi Ti Pi Ei to indicate the unit. The = flag has been added
3596 to center the output within the specified field width.
3597
3598
3599 pwd [-LP]
3600
3601 Outputs the value of the current working directory. The -L option
3602 is the default. It prints the logical name of the current
3603 directory. If the -P option is specified, all symbolic links are
3604 resolved from the name. The last instance of -L or -P on the
3605 command line determines which method is used.
3606
3607
3608 read [-Aprs] [-d delim] [ -n n] [[ -N n] [[-t timeout] [-u unit]
3609 [vname?prompt] [ vname ... ]
3610
3611 The shell input mechanism. One line is read and is broken up into
3612 fields using the characters in IFS as separators. The escape
3613 character, \, is used to remove any special meaning for the next
3614 character and for line continuation. The -d option causes the read
3615 to continue to the first character of delim rather than NEWLINE.
3616 The -n option causes at most n bytes to read rather a full line but
3617 returns when reading from a slow device as soon as any characters
3618 have been read. The -N option causes exactly n to be read unless an
3619 end-of-file has been encountered or the read times out because of
3620 the -t option. In raw mode, -r, the \ character is not treated
3621 specially. The first field is assigned to the first vname, the
3622 second field to the second vname, etc., with leftover fields
3623 assigned to the last vname. When vname has the binary attribute and
3624 -n or -N is specified, the bytes that are read are stored directly
3625 into the variable. If the -v is specified, then the value of the
3626 first vname is used as a default value when reading from a terminal
3627 device. The -A option causes the variable vname to be unset and
3628 each field that is read to be stored in successive elements of the
3629 indexed array vname. The -p option causes the input line to be
3630 taken from the input pipe of a process spawned by the shell using
3631 |&. If the -s option is present, the input is saved as a command in
3632 the history file. The option -u can be used to specify a one digit
3633 file descriptor unit unit to read from. The file descriptor can be
3634 opened with the exec special built-in command. The default value of
3635 unit n is 0. The option -t is used to specify a time out in seconds
3636 when reading from a terminal or pipe. If vname is omitted, then
3637 REPLY is used as the default vname. An end-of-file with the -p
3638 option causes cleanup for this process so that another can be
3639 spawned. If the first argument contains a ?, the remainder of this
3640 word is used as a prompt on standard error when the shell is
3641 interactive. The exit status is 0 unless an end-of-file is
3642 encountered or read has timed out.
3643
3644
3645 ++readonly [-p] [ vname[=value]] ...
3646
3647 If vname is not specified, the names and values of each variable
3648 with the read-only attribute is printed with the values quoted in a
3649 manner that allows them to be input again. The -p option causes the
3650 word readonly to be inserted before each one. Otherwise, the
3651 specified vnames are marked readonly and these names cannot be
3652 changed by subsequent assignment.
3653
3654
3655 +return [n]
3656
3657 Causes a shell function or script to return to the invoking script
3658 with the exit status specified by n. The value is the least
3659 significant 8 bits of the specified status. If n is omitted, then
3660 the return status is that of the last command executed. If return
3661 is invoked while not in a function or a script, then it behaves the
3662 same as exit.
3684
3685 Prints job completion messages as soon as a background job
3686 changes state rather than waiting for the next prompt.
3687
3688
3689 -B
3690
3691 Enable brace pattern field generation. This is the default
3692 behavior.
3693
3694
3695 -C
3696
3697 Prevents redirection (>) from truncating existing files. Files
3698 that are created are opened with the O_EXCL mode. Requires >|
3699 to truncate a file when turned on.
3700
3701
3702 -e
3703
3704 If a command has a non-zero exit status, execute the ERR trap,
3705 if set, and exit. This mode is disabled while reading profiles.
3706
3707
3708 -f
3709
3710 Disables file name generation.
3711
3712
3713 -G
3714
3715 Causes the pattern ** by itself to match files and zero or more
3716 directories and subdirectories when used for file name
3717 generation. If followed by a / only directories and
3718 subdirectories are matched.
3719
3720
3721 -h
3722
3723 Each command becomes a tracked alias when first encountered.
3724
3725
3785
3786 Same as -G.
3787
3788
3789 gmacs
3790
3791 Puts you in a gmacs style inline editor for command entry.
3792
3793
3794 ignoreeof
3795
3796 The shell does not exit on end-of-file. The command exit
3797 must be used.
3798
3799
3800 keyword
3801
3802 Same as -k.
3803
3804
3805 markdirs
3806
3807 All directory names resulting from file name generation
3808 have a trailing / appended.
3809
3810
3811 monitor
3812
3813 Same as -m.
3814
3815
3816 multiline
3817
3818 The built-in editors use multiple lines on the screen for
3819 lines that are longer than the width of the screen. This
3820 might not work for all terminals.
3821
3822
3823 noclobber
3824
3986 If action is the null string then this signal is ignored by the
3987 shell and by the commands it invokes. If sig is ERR then action is
3988 executed whenever a command has a non-zero exit status. If sig is
3989 DEBUG then action is executed before each command. The variable
3990 .sh.command contains the contents of the current command line when
3991 action is running. If sig is 0 or EXIT and the trap statement is
3992 executed inside the body of a function defined with the function
3993 name syntax, then the command action is executed after the function
3994 completes. If sig is 0 or EXIT for a trap set outside any function
3995 then the command action is executed on exit from the shell. If sig
3996 is KEYBD, then action is executed whenever a key is read while in
3997 emacs, gmacs, or vi mode. The trap command with no arguments prints
3998 a list of commands associated with each signal number.
3999
4000
4001 true
4002
4003 Does nothing, and exits 0. Used with while for infinite loops.
4004
4005
4006 ++typeset [+-AHflabnprtux ] [ +-EFLRZi[n] ] [ vname[=value ] ]
4007
4008 Sets attributes and values for shell variables and functions. When
4009 invoked inside a function defined with the function name syntax, a
4010 new instance of the variable vname is created, and the variable's
4011 value and type are restored when the function completes.
4012
4013 Using + rather than - causes these options to be turned off. If no
4014 vname arguments are specified, a list of vnames (and optionally the
4015 values) of the variables is printed. Using + rather than - keeps
4016 the values from being printed.) The -p option causes typeset
4017 followed by the option letters to be printed before each name
4018 rather than the names of the options. If any option other than -p
4019 is specified, only those variables which have all of the specified
4020 options are printed. Otherwise, the vnames and attributes of all
4021 variables that have attributes are printed.
4022
4023 The following list of attributes can be specified:
4024
4025 -a
4026 Declares vname to be an indexed array. This is optional
4027 unless except for compound variable assignments.
4028
4029
4030 -A
4031 Declares vname to be an associative array. Sub-scripts are
4032 strings rather than arithmetic expressions.
4033
4034
4035 -b
4036 The variable can hold any number of bytes of data. The data
4037 can be text or binary. The value is represented by the base64
4038 encoding of the data. If -Z is also specified, the size in
4039 bytes of the data in the buffer is determined by the size
4040 associated with the -Z. If the base64 string assigned results
4041 in more data, it is truncated. Otherwise, it is filled with
4042 bytes whose value is zero. The printf format %B can be used
4043 to output the actual data in this buffer instead of the
4044 base64 encoding of the data.
4045
4046
4047 -E
4048 Declares vname to be a double precision floating point
4049 number. If n is non-zero, it defines the number of
4050 significant figures that are used when expanding vname.
4051 Otherwise, ten significant figures is used.
4052
4053
4054 -f
4055 The names refer to function names rather than variable names.
4056 No assignments can be made and the only other valid options
4057 are -t, -u, and -x. The -t option turns on execution tracing
4058 for this function. The -u option causes this function to be
4059 marked undefined. The FPATH variable is searched to find the
4060 function definition when the function is referenced. If no
4061 options other than -f is specified, then the function
4062 definition is displayed on standard output. If +f is
4063 specified, then a line containing the function name followed
4064 by a shell comment containing the line number and path name
4065 of the file where this function was defined, if any, is
4066 displayed.
4067
4068 The -i attribute cannot be specified with -f.
4069
4070
4071 -F
4072 Declares vname to be a double precision floating point
4073 number. If n is non-zero, it defines the number of places
4074 after the decimal point that are used when expanding vname.
4075 Otherwise ten places after the decimal point is used.
4076
4077
4078 -H
4079 This option provides UNIX to hostname file mapping on non-
4080 UNIX machines.
4081
4082
4083 -i
4084 Declares vname to be represented internally as integer. The
4085 right hand side of an assignment is evaluated as an
4086 arithmetic expression when assigning to an integer. If n is
4087 non-zero, it defines the output arithmetic base, otherwise
4088 the output base is ten.
4089
4090 The -i attribute cannot be specified along with -R, -L, -Z,
4091 or -f.
4092
4093
4094 -l
4095 All uppercase characters are converted to lowercase. The
4096 uppercase option, -u, is turned off.
4097
4098
4099 -L
4100 Left justify and remove leading blanks from value. If n is
4101 non-zero, it defines the width of the field, otherwise it is
4102 determined by the width of the value of first assignment.
4103 When the variable is assigned to, it is filled on the right
4104 with blanks or truncated, if necessary, to fit into the
4105 field. The -R option is turned off.
4106
4107 The -i attribute cannot be specified with -L.
4108
4109
4110 -n
4111 Declares vname to be a reference to the variable whose name
4112 is defined by the value of variable vname. This is usually
4113 used to reference a variable inside a function whose name has
4114 been passed as an argument.
4115
4116
4117 -R
4118 Right justify and fill with leading blanks. If n is non-zero,
4119 it defines the width of the field, otherwise it is determined
4120 by the width of the value of first assignment. The field is
4121 left filled with blanks or truncated from the end if the
4122 variable is reassigned. The -L option is turned off.
4123
4124 The -i attribute cannot be specified with -R.
4125
4126
4127 -r
4128 The specified vnames are marked read-only and these names
4129 cannot be changed by subsequent assignment.
4130
4131
4132 -t
4133 Tags the variables. Tags are user definable and have no
4134 special meaning to the shell.
4135
4136
4137 -u
4138 All lowercase characters are converted to uppercase. The
4139 lowercase option, -l, is turned off.
4140
4141
4142 -x
4143 The specified vnames are marked for automatic export to the
4144 environment of subsequently-executed commands. Variables
4145 whose names contain a . cannot be exported.
4146
4147
4148 -Z
4149 Right justify and fill with leading zeros if the first non-
4150 blank character is a digit and the -L option has not been
4151 set. Remove leading zeros if the -L option is also set. If n
4152 is non-zero, it defines the width of the field, otherwise it
4153 is determined by the width of the value of first assignment.
4154
4155 The -i attribute cannot be specified with -Z.
4156
4157
4158
4159 ulimit [-HSacdfmnpstv] [ limit]
4160
4161 Set or display a resource limit. Many systems do not support one or
4162 more of these limits. The limit for a specified resource is set
4163 when limit is specified. The value of limit can be a number in the
4164 unit specified with each resource, or the value unlimited. When
4165 more than one resource is specified, then the limit name and unit
4166 is printed before the value.
4167
4305 function.
4306
4307
4308 Commands are then read as described, and the following options are
4309 interpreted by the shell when it is invoked:
4310
4311 -c
4312 If the -c option is present, then commands are read from
4313 the first arg. Any remaining arguments become positional
4314 parameters starting at 0.
4315
4316
4317 -D
4318 A list of all double quoted strings that are preceded by
4319 a $ is printed on standard output and the shell exits.
4320 This set of strings is subject to language translation
4321 when the locale is not C or POSIX. No commands are
4322 executed.
4323
4324
4325 -i
4326 If the -i option is present or if the shell input and
4327 output are attached to a terminal (as told by
4328 tcgetattr(3C), this shell is interactive. In this case
4329 TERM is ignored (so that kill 0 does not kill an
4330 interactive shell) and INTR is caught and ignored (so
4331 that wait is interruptible). In all cases, QUIT is
4332 ignored by the shell.
4333
4334
4335 -R filename
4336 The -R filename option is used to generate a cross
4337 reference database that can be used by a separate
4338 utility to find definitions and references for variables
4339 and commands.
4340
4341
4342 -r
4343 If the -r option is present, the shell is a restricted
4344 shell.
4345
4346
4347 -s
4348 If the -s option is present or if no arguments remain,
4349 then commands are read from the standard input. Shell
4350 output, except for the output of the Special Commands
4351 listed, is written to file descriptor 2.
4352
4353
4354
4465 David Korn, dgk@research.att.com
4466
4467 ATTRIBUTES
4468 See attributes(5) for descriptions of the following attributes:
4469
4470
4471
4472
4473 +--------------------+-----------------+
4474 | ATTRIBUTE TYPE | ATTRIBUTE VALUE |
4475 +--------------------+-----------------+
4476 |Interface Stability | See below. |
4477 +--------------------+-----------------+
4478
4479
4480 The scripting interface is Uncommitted. The environment variables,
4481 .paths feature, and editing modes are Volatile.
4482
4483 SEE ALSO
4484 cat(1), cd(1), chmod(1), cut(1), date(1), egrep(1), echo(1), egrep(1),
4485 env(1), fgrep(1), grep(1), login(1), newgrp(1), paste(1), printf(1),
4486 stty(1), test(1), umask(1), vi(1), dup(2), exec(2), fork(2), ioctl(2),
4487 lseek(2), pathconf(2), pipe(2), sysconf(3C), ulimit(2), umask(2),
4488 rand(3C), tcgetattr(3C), wait(3C), a.out(4), profile(4), attributes(5),
4489 environ(5), largefile(5), standards(5)
4490
4491
4492 Bolsky, Morris I. and Korn, David G., The New KornShell Command and
4493 Programming Language, Prentice Hall, 1995.
4494
4495
4496 POSIX-Part 2: Shell and Utilities, IEEE Std 1003.2-1992, ISO/IEC
4497 9945-2, IEEE, 1993.
4498
4499 NOTES
4500 ksh93 scripts should choose shell function names outside the namespace
4501 used by reserved keywords of the ISO C99, C++ and JAVA languages to
4502 avoid collisions with future enhancements to ksh93.
4503
4504
4505 If a command is executed, and then a command with the same name is
4506 installed in a directory in the search path before the directory where
4507 the original command was found, the shell continues to exec the
4508 original command. Use the -t option of the alias command to correct
4509 this situation.
4524
4525 Traps are not processed while a job is waiting for a foreground
4526 process. Thus, a trap on CHLD is not executed until the foreground job
4527 terminates.
4528
4529
4530 It is a good idea to leave a space after the comma operator in
4531 arithmetic expressions to prevent the comma from being interpreted as
4532 the decimal point character in certain locales.
4533
4534
4535 There might be some restrictions on creating a .paths file which is
4536 portable across other operating systems.
4537
4538
4539 If the system supports the 64-bit instruction set, /bin/ksh93 executes
4540 the 64-bit version of ksh93.
4541
4542
4543
4544 June 27, 2018 KSH93(1)
|
110 semicolon, to delimit a command. The first item of the first pipeline
111 of a list that is a simple command not beginning with a redirection,
112 and not occurring within a while, until, or if list , can be preceded
113 by a semicolon. This semicolon is ignored unless the showme option is
114 enabled as described with the set built-in.
115
116
117 A command is either a simple-command or one of commands in the
118 following list. Unless otherwise stated, the value returned by a
119 command is that of the last simple-command executed in the command.
120
121 for vname [ in word ... ] ;do list ;done
122
123 Each time a for command is executed, vname is set to the next word
124 taken from the in word list. If in word ... is omitted, the for
125 command executes the do list once for each positional parameter
126 that is set starting from 1. Execution ends when there are no more
127 words in the list. See Parameter Expansion.
128
129
130 for (( [expr1] ; [expr2] ; [expr3] )) ;do list ;done
131
132 The arithmetic expression expr1 is evaluated first. The arithmetic
133 expression expr2 is repeatedly evaluated until it evaluates to zero
134 and when non-zero, list is executed and the arithmetic expression
135 expr3 evaluated. If any expression is omitted, then it behaves as
136 if it evaluated to 1. See Arithmetic Evaluation.
137
138
139 select vname [ in word ... ] ;do list ;done
140
141 A select command prints on standard error (file descriptor 2) the
142 set of words, each preceded by a number. If in word... is omitted,
143 the positional parameters starting from 1 are used instead. See
144 Parameter Expansion. The PS3 prompt is printed and a line is read
145 from the standard input. If this line consists of the number of one
146 of the listed words, then the value of the variable vname is set to
147 the word corresponding to this number. If this line is empty, the
148 selection list is printed again. Otherwise the value of the
149 variable vname is set to null. The contents of the line read from
150 standard input is saved in the variable REPLY. The list is executed
177
178 while list ;do list ;done
179 until list ;do list ;done
180
181 A while command repeatedly executes the while list and, if the exit
182 status of the last command in the list is zero, executes the do
183 list, otherwise the loop terminates. If no commands in the do list
184 are executed, then the while command returns a zero exit status,
185 until can be used in place of while to negate the loop termination
186 test.
187
188
189 ((expression))
190
191 The expression is evaluated using the rules for arithmetic
192 evaluation described in this manual page. If the value of the
193 arithmetic expression is non-zero, the exit status is 0. Otherwise
194 the exit status is 1.
195
196
197 (list)
198
199 Execute list in a separate environment. If two adjacent open
200 parentheses are needed for nesting, a SPACE must be inserted to
201 avoid evaluation as an arithmetic command as described in this
202 section.
203
204
205 { list;}
206
207 list is simply executed. Unlike the metacharacters, ( and ), { and
208 } are reserved words and must occur at the beginning of a line or
209 after a ; to be recognized.
210
211
212 [[ expression ]]
213
214 Evaluates expression and returns a zero exit status when expression
215 is true. See Conditional Expressions for a description of
216 expression.
217
218
219 function varname { list ;}
220 varname () { list ;}
221
222 Define a function which is referenced by varname. A function whose
223 varname contains a dot (.) is called a discipline function and the
224 portion of the varname preceding the last . must refer to an
225 existing variable.
226
227 The body of the function is the list of commands between { and }. A
228 function defined with the function varname syntax can also be used
229 as an argument to the . special built-in command to get the
230 equivalent behavior as if the varname() syntax were used to define
231 it. See Functions.
232
233
234 namespace identifier { list };
235
236 Defines or uses the name space identifier and runs the commands in
237 list in this name space. See Name Spaces.
238
239
240 time [ pipeline ]
241
242 If pipeline is omitted, the user and system time for the current
243 shell and completed child processes is printed on standard error.
244 Otherwise, pipeline is executed and the elapsed time as well as the
245 user and system time are printed on standard error. The TIMEFORMAT
246 variable can be set to a format string that specifies how the
247 timing information should be displayed. See Shell Variables for a
248 description of the TIMEFORMAT variable.
249
250
251
252 The following reserved words are recognized as reserved only when they
253 are the first word of a command and are not quoted:
254
255 case
256 do
257 done
258 else
259 elif
260 esac
261 for
262 fi
263 function
264 if
265 select
266 then
267 time
268 until
269 while
270 { }
271 [[ ]]
272 !
273
274 Variable Assignments
275 One or more variable assignments can start a simple command or can be
276 arguments to the typeset, enum, export, or readonly special built-in
277 commands. The syntax for an assignment is of the form:
278
279 varname=word
280 varname[word]=word
281
282 No space is permitted between varname and the = or between = and
283 word. The variable varname is unset before the assignment.
284
285
286 varname=(assignlist)
287
288 No space is permitted between varname and the =. An assignlist can
289 be one of the following:
290
291 word ...
292
293 Indexed array assignment.
294
295
296 [word]=word ...
297
298 Associative array assignment. If prefixed by typeset -a,
299 creates an indexed array instead.
300
301
302 assignment ...
303
304 Compound variable assignment. This creates a compound variable
305 varname with sub-variables of the form varname.name, where name
306 is the name portion of assignment. The value of varname
307 contains all the assignment elements. Additional assignments
308 made to sub-variables of varname are also displayed as part of
309 the value of varname. If no assignments are specified, varname
310 is a compound variable allowing subsequence child elements to
311 be defined.
312
313
314 typeset [options] assignment ...
315
316 Nested variable assignment. Multiple assignments can be
317 specified by separating each of them with a ;. The previous
318 value is unset before the assignment.
319
320
321 . filename
322
323 Include the assignment commands contained in filename.
324
325 In addition, a += can be used in place of the = to signify adding
326 to or appending to the previous value. When += is applied to an
327 arithmetic type, word is evaluated as an arithmetic expression and
328 added to the current value. When applied to a string variable, the
329 value defined by word is appended to the value. For compound
330 assignments, the previous value is not unset and the new values are
331 appended to the current ones provided that the types are
332 compatible.
333
334 The right hand side of a variable assignment undergoes all the
335 expansion listed below except word splitting, brace expansion, and
336 file name generation. When the left hand side is an assignment is
337 a compound variable and the right hand is the name of a compound
338 variable, the compound variable on the right will be copied or
339 appended to the compound variable on the left.
340
341
342
343 Comments
344 A word beginning with # causes that word and all the following
345 characters up to a NEWLINE to be commented, or ignored.
346
347 Aliasing
348 The first word of each command is replaced by the text of an alias if
349 an alias for this word has been defined. An alias name consists of any
350 number of characters excluding metacharacters, quoting characters, file
351 expansion characters, parameter expansion characters, command
352 substitution characters, the characters / and =. The replacement string
353 can contain any valid shell script including the metacharacters listed
354 in the Commands section. The first word of each command in the replaced
355 text, other than any that are in the process of being replaced, are
356 tested for aliases. If the last character of the alias value is a BLANK
357 then the word following the alias is also checked for alias
358 substitution.
359
360
361 Aliases can be used to redefine built-in commands but cannot be used to
362 redefine the reserved words listed in the Commands section. Aliases can
363 be created and listed with the alias command and can be removed with
364 the unalias command.
365
366
367 Aliasing is performed when scripts are read, not while they are
368 executed. For an alias to take effect, the alias definition command has
369 to be executed before the command which references the alias is read.
370 The following aliases are compiled into the shell but can be unset or
371 redefined:
372
373 autoload='typeset -fu'
374 command='command '
375 compound='typeset -C'
376 fc=hist
377 float='typeset -lE'
378 functions='typeset -f'
379 hash='alias -t --'
380 history='hist -l'
381 integer='typeset -li'
382 nameref='typeset -n'
383 nohup='nohup '
384 r='hist -s'
385 redirect='command exec'
386 source='command .'
387 stop='kill -s STOP'
388 suspend='kill -s STOP $$'
389 times='{ { time;} 2>&1;}'
390 type='whence -v'
391
392
393
394 Tilde Substitution
395 After alias substitution is performed, each word is checked to see if
396 it begins with an unquoted tilde (~). For tilde substitution, word also
397 refers to the word portion of parameter expansion. See Parameter
398 Expansion.
399
400
401 If it does, the word up to a / is checked to see if it matches a user
402 name in the password database. If a match is found, the ~ and the
403 matched login name are replaced by the login directory of the matched
404 user. If no match is found, the original text is left unchanged. A ~ by
405 itself, or in front of a /, is replaced by $HOME. A ~ followed by a +
406 or - is replaced by the value of $PWD and $OLDPWD respectively.
407
408
409 In addition, when expanding a variable assignment, tilde substitution
410 is attempted when the value of the assignment begins with a ~, and when
411 a ~ appears after a colon (:). The : also terminates a ~ login name.
412
413 Command Substitution
414 The standard output from a command enclosed in parentheses preceded by
415 a dollar sign ( $(list) ), or in a brace group preceded by a dollar
416 sign ( ${ list;} ), or in a pair of grave accents (``) can be used as
417 part or all of a word. Trailing NEWLINEs are removed. In the second
418 case, the { and } are treated as a reserved words so that { must be
419 followed by a blank and } must appear at the beginning of the line or
420 follow a ;. In the third (obsolete) form, the string between the quotes
421 is processed for special quoting characters before the command is
422 executed. See Quoting.
423
424
425 The command substitution $(cat file) can be replaced by the equivalent
426 but faster $(<file). The command substitution $(n<#) expands to the
427 current byte offset for file descriptor n. Except for the second form,
428 the command list is run in a subshell so that no side effects are
429 possible. For the second form, the final } will be recognized as a
430 reserved word after any token.
431
432 Arithmetic Substitution
433 An arithmetic expression enclosed in double parentheses preceded by a
434 dollar sign ( $((arithmetic_expression))) is replaced by the value of
435 the arithmetic expression within the double parentheses.
436
437 Process Substitution
438 Each command argument of the form <(list) or >(list) runs process list
439 asynchronously connected to some file in /dev/fd. The name of this file
440 becomes the argument to the command. If the form with > is selected
441 then writing on this file provides input for list. If < is used, then
442 the file passed as an argument contains the output of the list process.
443
444
445 For example,
446
447 paste <(cut -f1 file1) <(cut -f3 file2) | tee \
448 >(process1) >(process2)
449
450
451
452
453 cuts fields 1 and 3 from the files file1 and file2 respectively, pastes
454 the results together, and sends it to the processes process1 and
455 process2. It also displays the results to the standard output. The
456 file, which is passed as an argument to the command, is a UNIX pipe(2).
457 Programs that expect to lseek(2) on the file do not work.
458
459 Process substitution of the form <(list) can also be used with the <
460 redirection operator which causes the output of list to be standard
461 input or the input for whatever file descriptor is specified.
462
463 Parameter Expansion
464 A parameter is a variable, one or more digits, or any of the characters
465 *, @, #, ?, -, $, and !. A variable is denoted by a vname. To create a
466 variable whose vname contains a ., a variable whose vname consists of
467 everything before the last . must already exist. A variable has a value
468 and zero or more attributes. Variables can be assigned values and
469 attributes by using the typeset special built-in command. The
470 attributes supported by the shell are described later with the typeset
471 special built-in command. Exported variables pass values and attributes
472 to the environment.
473
474
475 The shell supports both indexed and associative arrays. An element of
476 an array variable is referenced by a subscript. A subscript for an
477 indexed array is denoted by an arithmetic expression, (see Arithmetic
478 Evaluation), between a [ and a ]. To assign values to an indexed
479 array, use vname=(value ...) or set -A vname value ... . The value of
480 all subscripts must be in the range of 0 through 4,194,303. A negative
481 subscript is treated as an offset from the maximum current index +1 so
482 that -1 refers to the last element. Indexed arrays can be declared
483 with the -a option to typeset. Indexed arrays need not be declared. Any
484 reference to a variable with a valid subscript is legal and an array
485 will be created if necessary.
486
487
488 An associative array is created with the -A option to typeset. A
489 subscript for an associative array is denoted by a string enclosed
490 between [ and ].
491
492
493 Referencing any array without a subscript is equivalent to referencing
494 the array with subscript 0.
495
496
497 The value of a variable can be assigned by:
498
499 vname=value [vname=value] ...
500
501
502
503
504 or
505
506 vname[subscript]=value [vname[subscript]=value] ...
507
508 Note that no space is allowed before or after the =.
509
510 Attributes assigned by the typeset special built-in command apply to
511 all elements of the array. An array element can be a simple variable,
512 a compound variable or an array variable. An element of an indexed
513 array can be either an indexed array or an associative array. An
514 element of an associative array can also be either. To refer to an
515 array element that is part of an array element, concatenate the
516 subscript in brackets. For example, to refer to the foobar element of
517 an associative array that is defined as the third element of the
518 indexed array, use ${vname[3][foobar]}
519
520
521 A nameref is a variable that is a reference to another variable. A
522 nameref is created with the -n attribute of typeset. The value of the
523 variable at the time of the typeset command becomes the variable that
524 is referenced whenever the nameref variable is used. The name of a
525 nameref cannot contain a dot (.). When a variable or function name
526 contains a dot (.) and the portion of the name up to the first .
527 matches the name of a nameref, the variable referred to is obtained by
528 replacing the nameref portion with the name of the variable referenced
529 by the nameref. If a nameref is used as the index of a for loop, a name
530 reference is established for each item in the list. A nameref provides
531 a convenient way to refer to the variable inside a function whose name
532 is passed as an argument to a function. For example, if the name of a
533 variable is passed as the first argument to a function, the command
534
535 typeset -n var=$1
536
537
538
539
540 inside the function causes references and assignments to var to be
541 references and assignments to the variable whose name has been passed
542 to the function. If any of the floating point attributes, -E,-F or -X,
543 or the integer attribute, -i, is set for vname, then the value is
544 subject to arithmetic evaluation as described in this manual page.
545 Positional parameters, parameters denoted by a number, can be assigned
546 values with the set special built-in command. Parameter $0 is set from
547 argument zero when the shell is invoked.
548
549 The character $ is used to introduce substitutable parameters.
550
551 ${parameter}
552
553 The shell reads all the characters from ${ to the matching } as
554 part of the same word even if it contains braces or metacharacters.
555 The value, if any, of the parameter is substituted. The braces are
556 required when parameter is followed by a letter, digit, or
557 underscore that is not to be interpreted as part of its name or
558 when the variable name contains a dot (.). The braces are also
559 required when a variable is subscripted unless it is part of an
560 Arithmetic Expression or a Conditional Expression. If parameter is
561 one or more digits then it is a positional parameter. A positional
562 parameter of more than one digit must be enclosed in braces. If
563 parameter is * or @, then all the positional parameters, starting
564 with $1, are substituted and separated by a field separator
565 character. If an array vname with last subscript * or @ is used, or
566 for index arrays of the form sub1 .. sub2 is used, then the value
567 for each of the elements between sub1 and sub2 inclusive (or all
568 elements for * and @) is substituted, separated by the first
569 character of the value of IFS.
570
571
572 ${#parameter}
573
574 If parameter is * or @, the number of positional parameters is
575 substituted. Otherwise, the length of the value of the parameter is
576 substituted.
577
578
579 ${#vname[*]}
580 ${#vname[@]}
581
582 The number of elements in the array vname is substituted.
583
584 ${@vname}
585
586 Expands to the type name or attributes of the variable referred to
587 by vname. See Type Variables.
588
589
590 ${!vname}
591
592 Expands to the name of the variable referred to by vname. This is
593 vname except when vname is a name reference.
594
595
596 ${!vname[subscript]}
597
598 Expands to name of the subscript unless subscript is * or @, or of
599 the form sub1 .. sub2. When subscript is *, the list of array
600 subscripts for vname is generated. For a variable that is not an
601 array, the value is 0 if the variable is set, otherwise it is null.
602 When subscript is @, it is the same as $ {vname[*]}, except that
603 when used in double quotes, each array subscript yields a separate
604 argument. When subscript is of the form sub1 .. sub2 it expands to
605 the list of subscripts between sub1 and sub2 inclusive using the
606 same quoting rules as @.
607
608
609 ${!prefix*}
610
611 Expands to the names of the variables whose names begin with
612 prefix.
613
614
615 ${parameter:-word}
616
617 If parameter is set and is non-null then substitute its value.
618 Otherwise substitute word.
619
620
621 ${parameter:=word}
622
623 If parameter is not set or is null, set it to word. The value of
624 the parameter is then substituted. Positional parameters cannot be
625 assigned to in this way.
626
627
628 ${parameter:?word}
629
630 If parameter is set and is non-null, substitute its value.
631 Otherwise, print word and exit from the shell , if the shell is not
632 interactive. If word is omitted then a standard message is printed.
633
634
635 ${parameter:+word}
636
637 If parameter is set and is non-null, substitute word. Otherwise
638 substitute nothing.
639
640 In the above, word is not evaluated unless it is to be used as the
641 substituted string. In the following example, pwd is executed only if d
642 is not set or is NULL:
643
644 print ${d:-$(pwd)}
645
646
647 If the colon (:) is omitted from the expression, the shell only checks
648 whether parameter is set or not.
649
650
651 ${parameter:offset:length}
652 ${parameter:offset}
653
654 Expands to the portion of the value of parameter starting at the
655 character (counting from 0) determined by expanding offset as an
656 arithmetic expression and consisting of the number of characters
657 determined by the arithmetic expression defined by length.
658
659 In the second form, the remainder of the value is used. A negative
660 offset counts backwards from the end of parameter.
661
662 One or more BLANKs is required in front of a minus sign to prevent
663 the shell from interpreting the operator as :-. If parameter is *
664 or @, or is an array name indexed by * or @, then offset and length
665 refer to the array index and number of elements respectively. A
666 negative offset is taken relative to one greater than the highest
667 subscript for indexed arrays. The order for associative arrays is
668 unspecified.
739 command.
740
741
742 $
743 The process number of this shell.
744
745
746 _
747 Initially, the value of _ is the absolute pathname
748 of the shell or script being executed as passed in
749 the environment. It is subsequently assigned the
750 last argument of the previous command.
751
752 This parameter is not set for commands which are
753 asynchronous. This parameter is also used to hold
754 the name of the matching MAIL file when checking for
755 mail.
756
757
758 !
759 The process id or the pool name and job number of
760 the last background command invoked or the most
761 recent job put in the background with the bg built-
762 in command. Background jobs started in a named pool
763 with be in the form pool.number where pool is the
764 pool name and number is the job number within that
765 pool.
766
767
768 .sh.command
769 When processing a DEBUG trap, this variable contains
770 the current command line that is about to run.
771
772
773 .sh.edchar
774 This variable contains the value of the keyboard
775 character (or sequence of characters if the first
776 character is an ESC, ASCII 033) that has been
777 entered when processing a KEYBD trap. If the value
778 is changed as part of the trap action, then the new
779 value replaces the key (or key sequence) that caused
780 the trap. See the Key Bindings section of this
781 manual page.
782
783
784 .sh.edcol
785 The character position of the cursor at the time of
803 The pathname of the file than contains the current
804 command.
805
806
807 .sh.fun
808 The name of the current function that is being
809 executed.
810
811
812 .sh.match
813 An indexed array which stores the most recent match
814 and sub-pattern matches after conditional pattern
815 matches that match and after variables expansions
816 using the operators #, %, or /. The 0th element
817 stores the complete match and the ith element stores
818 the ith sub-match. The .sh.match variable is unset
819 when the variable that has expanded is assigned a
820 new value.
821
822
823 .sh.math
824 Used for defining arithmetic functions (see
825 Arithmetic evaluation) and stores the list of user-
826 defined arithmetic functions.
827
828
829 .sh.name
830 Set to the name of the variable at the time that a
831 discipline function is invoked.
832
833
834 .sh.subscript
835 Set to the name subscript of the variable at the
836 time that a discipline function is invoked.
837
838
839 .sh.subshell
840 The current depth for sub-shells and command
841 substitution.
842
843
844 .sh.value
845 Set to the value of the variable at the time that
846 the set or append discipline function is invoked.
847 When a user-defined arithmetic function is invoked,
848 the value of .sh.value is saved and .sh.value is set
849 to long double precision floating point. .sh.value
850 is restored when the function returns.
851
852
853 .sh.version
854 Set to a value that identifies the version of this
855 shell.
856
857
858 LINENO
859 The current line number within the script or
860 function being executed.
861
862
863 OLDPWD
864 The previous working directory set by the cd
865 command.
866
867
868 OPTARG
869 The value of the last option argument processed by
870 the getopts built-in command.
888 integer, uniformly distributed between 0 and 32767,
889 is generated. The sequence of random numbers can be
890 initialized by assigning a numeric value to RANDOM.
891
892
893 REPLY
894 This variable is set by the select statement and by
895 the read built-in command when no arguments are
896 supplied.
897
898
899 SECONDS
900 Each time this variable is referenced, the number of
901 seconds since shell invocation is returned. If this
902 variable is assigned a value, then the value
903 returned upon reference is the value that was
904 assigned plus the number of seconds since the
905 assignment.
906
907
908 SHLVL
909 An integer variable the is incremented each time the
910 shell is invoked and is exported. If SHLVL is not
911 in the environment when the shell is invoked, it is
912 set to 1.
913
914
915
916 The following variables are used by the shell:
917
918 CDPATH
919 Defines the search path for the cd command.
920
921
922 COLUMNS
923 Defines the width of the edit window for the shell edit
924 modes and for printing select lists.
925
926
927 EDITOR
928 If the VISUAL variable is not set, the value of this
929 variable is checked for the patterns as described with
930 VISUAL and the corresponding editing option is turned on.
931
932 See the set command in the Special Command section of
933 this manual page.
934
935
1004 substitution or parameter expansion and to separate
1005 fields with the built-in command read. The first
1006 character of the IFS variable is used to separate
1007 arguments for the "$*" substitution. See the Quoting
1008 section of this manual page.
1009
1010 Each single occurrence of an IFS character in the string
1011 to be split, that is not in the issspace character class,
1012 and any adjacent characters in IFS that are in the
1013 issspace character class, delimit a field. One or more
1014 characters in IFS that belong to the issspace character
1015 class, delimit a field. In addition, if the same issspace
1016 character appears consecutively inside IFS, this
1017 character is treated as if it were not in the issspace
1018 class, so that if IFS consists of two tab characters,
1019 then two adjacent tab characters delimit a null field.
1020
1021 The shell specifies a default value to IFS.
1022
1023
1024 JOBMAX
1025 This variable defines the maximum number running
1026 background jobs that can run at a time. When this limit
1027 is reached, the shell will wait for a job to complete
1028 before staring a new job.
1029
1030
1031 LANG
1032 This variable determines the locale category for any
1033 category not specifically selected with a variable
1034 starting with LC_ or LANG.
1035
1036
1037 LC_ALL
1038 This variable overrides the value of the LANG variable
1039 and any other LC_ variable.
1040
1041
1042 LC_COLLATE
1043 This variable determines the locale category for
1044 character collation information.
1045
1046
1047 LC_CTYPE
1048 This variable determines the locale category for
1049 character handling functions. It determines the
1050 character classes for pattern matching. See the File Name
1279 unless the first character of the pattern corresponding to this
1280 component is the character . itself. For other uses of pattern matching
1281 the / and . are not specially treated.
1282
1283 *
1284 Match any string, including the null string. When used for
1285 file name expansion, if the globstar option is on, two
1286 adjacent *s by themselves match all files and zero or more
1287 directories and subdirectories. If the two adjacent *s are
1288 followed by a /, only directories and subdirectories match.
1289
1290
1291 ?
1292 Matches any single character.
1293
1294
1295 [...]
1296 Match any one of the enclosed characters. A pair of
1297 characters separated by - matches any character lexically
1298 between the pair, inclusive. If the first character
1299 following the opening [ is a ! or ^, any character not
1300 enclosed is matched. A - can be included in the character
1301 set by putting it as the first or last character. Within [
1302 and ], character classes can be specified with the syntax
1303 [:class:] where class is one of the following classes
1304 defined in the ANSI-C standard:
1305
1306 alnum alpha blank cntrl digit graph
1307 lower print punct space upper
1308 word xdigit
1309
1310
1311 word is equivalent to alnum plus the character _. Within [
1312 and ], an equivalence class can be specified with the syntax
1313 [=c=] which matches all characters with the same primary
1314 collation weight (as defined by the current locale) as the
1315 character c. Within [ and ], [.symbol.] matches the
1316 collating symbol symbol.
1317
1318
1319
1320 A pattern-list is a list of one or more patterns separated from each
1321 other with an & or |. An & signifies that all patterns must be matched
1322 whereas | requires that only one pattern be matched. Composite patterns
1323 can be formed with one or more of the following sub-patterns:
1324
1424 causing all characters other than any escape character to be
1425 ignored when looking for a match.
1426
1427
1428
1429 %({}Q"E\), matches characters starting at { until the matching } is
1430 found not counting any { or } that is inside a double quoted string or
1431 preceded by the escape character \. Without the {} this pattern matches
1432 any C language string.
1433
1434
1435 Each sub-pattern in a composite pattern is numbered, starting at 1, by
1436 the location of the ( within the pattern. The sequence \n, where n is a
1437 single digit and \n comes after the nth. sub-pattern, matches the same
1438 string as the sub-pattern itself.
1439
1440
1441 A pattern can contain sub-patterns of the form ~(options:pattern-list),
1442 where either options or :pattern-list can be omitted. Unlike the other
1443 compound patterns, these sub-patterns are not counted in the numbered
1444 sub-patterns. :pattern-list must be omitted for options F, G, N and V
1445 below. If options is present, it can consist of one or more of the
1446 following:
1447
1448 +
1449 Enable the following options. This is the default.
1450
1451
1452 -
1453 Disable the following options.
1454
1455
1456 E
1457 The remainder of the pattern uses extended regular expression
1458 syntax like the egrep(1) command.
1459
1460
1461 F
1462 The remainder of the pattern uses fgrep(1) expression syntax.
1463
1464
1465 g
1466 File the longest match (greedy).
1484
1485
1486 l
1487 Left anchor the pattern.
1488
1489 This is the default for K style patterns.
1490
1491
1492 N
1493 This is ignored. However, when it is the first letter and is used
1494 with file name generation, and no matches occur, the file pattern
1495 expands to the empty string.
1496
1497
1498 r
1499 Right anchor the pattern.
1500
1501 This is the default for K style patterns.
1502
1503
1504 X
1505 The remainder of the pattern uses augmented regular expression
1506 syntax.
1507
1508
1509 P
1510 The remainder of the pattern uses perl(1) regular expression
1511 syntax. Not all perl regular expression syntax is currently
1512 implemented.
1513
1514
1515 V
1516 The remainder of the pattern uses System V regular expression
1517 syntax.
1518
1519
1520
1521 If both options and :pattern-list are specified, then the options apply
1522 only to pattern-list. Otherwise, these options remain in effect until
1523 they are disabled by a subsequent ~(...) or at the end of the sub-
1524 pattern containing ~(...).
1525
1526 Quoting
1527 Each of the metacharacters listed in the Definitions section of this
1528 manual page has a special meaning to the shell and causes termination
1529 of a word unless quoted. A character can be quoted, that is, made to
1530 stand for itself, by preceding it with a backslash (\). The pair
1531 \NEWLINE is removed. All characters enclosed between a pair of single
1532 quote marks ('') that is not preceded by a $ are quoted. A single quote
1533 cannot appear within the single quotes. A single quoted string preceded
1534 by an unquoted $ is processed as an ANSI-C string except for the
1535 following:
1536
1537 \0
1538 Causes the remainder of the string to be ignored.
1539
1540
1541 \cx
1542 Expands to the character CTRL-x.
1543
1544
1545 \C[.name.]
1546 Expands to the collating element name.
1547
1548
1549 \e
1550 Equivalent to the escape character (ASCII 033),
1551
1552
1553 \E
1554 Equivalent to the escape character (ASCII 033),
1555
1556
1557
1558 Inside double quote marks (""), parameter and command substitution
1559 occur and \ quotes the characters \, `, ", and $. A $ in front of a
1560 double quoted string is ignored in the C or POSIX locale, and might
1561 cause the string to be replaced by a locale specific string otherwise.
1562 The meaning of $* and $@ is identical when not quoted or when used as a
1563 variable assignment value or as a file name. However, when used as a
1564 command argument, "$*" is equivalent to "$1d$2d...", where d is the
1565 first character of the IFS variable, whereas "$@" is equivalent to "$1"
1566 "$2" .... Inside grave quote marks (``), \ quotes the characters \, `,
1567 and $. If the grave quotes occur within double quotes, then \ also
1568 quotes the character ".
1569
1570
1571 The special meaning of reserved words or aliases can be removed by
1572 quoting any character of the reserved word. The recognition of function
1573 names or built-in command names cannot be altered by quoting them.
1574
1575 Arithmetic Evaluation
1576 The shell performs arithmetic evaluation for arithmetic substitution,
1577 to evaluate an arithmetic command, to evaluate an indexed array
1578 subscript, and to evaluate arguments to the built-in commands shift and
1579 let. Arithmetic evaluation is also performed on argument operands of
1580 the built-in command printf that correspond to numeric format
1581 specifiers in the format operand. See printf(1). Evaluations are
1582 performed using double precision floating point arithmetic or long
1583 double precision floating point for systems that provide this data
1584 type. Floating point constants follow the ANSI-C programming language
1585 floating point conventions. The floating point constants Nan and Inf
1586 can be used to represent "not a number" and infinity respectively.
1587 Integer constants follow the ANSI-C programming language integer
1588 constant conventions although only single byte character constants are
1589 recognized and character casts are not recognized. Constants can be of
1590 the form [base#]n where base is a decimal number between two and sixty-
1591 four representing the arithmetic base and n is a number in that base.
1592 The digits greater than 9 are represented by the lower case letters,
1593 the upper case letters, @, and _ respectively. For bases less than or
1594 equal to 36, upper and lower case characters can be used
1595 interchangeably.
1596
1597
1598 An arithmetic expression uses the same syntax, precedence, and
1599 associativity of expression as the C language. All the C language
1600 operators that apply to floating point quantities can be used. In
1601 addition, the operator ** can be used for exponentiation. It has higher
1602 precedence than multiplication and is left associative. When the value
1603 of an arithmetic variable or subexpression can be represented as a long
1604 integer, all C language integer arithmetic operations can be performed.
1605 Variables can be referenced by name within an arithmetic expression
1606 without using the parameter expansion syntax. When a variable is
1607 referenced, its value is evaluated as an arithmetic expression.
1608
1609
1610 Any of the following math library functions that are in the C math
1611 library can be used within an arithmetic expression:
1612
1613 rint round sin sinh sqrt tan tanh tgamma trunc abs acos
1614 acosh asin asinh atan atan2 atanh cbrt ceil copysign cos
1615 cosh erf erfc exp exp2 expm1 fabs fpclassify fdim finite
1616 floor fma fmax fmin fmod hypot ilogb int isfinite sinf isnan
1617 isnormal issubnormal issubor- dered iszero j0 j1 jn lgamma
1618 log log10 log2 logb nearbyint nextafter nexttoward pow
1619 remainder rint round scanb signbit sin sinh sqrt tan tanh
1620 tgamma trunc y0 y1 yn
1621
1622
1623
1624
1625 In addition, arithmetic functions can be defined as shell functions
1626 with a variant of the function name syntax:
1627
1628 function .sh.math.name ident ... { list ;}
1629 where name is the function name used in the arithmetic expression
1630 and each identified ident is a name reference to the long double
1631 precision floating point argument. The value of .sh.value when the
1632 function returns is the value of this function. User defined
1633 functions can take up to 3 arguments and override C math library
1634 functions.
1635
1636
1637
1638 An internal representation of a variable as a double precision floating
1639 point can be specified with the -E [n], -F [n], or -X [n] options of
1640 the typeset special built-in command. The -E option causes the
1641 expansion of the value to be represented using scientific notation when
1642 it is expanded. The optional option argument n defines the number of
1643 significant figures. The -F option causes the expansion to be
1644 represented as a floating decimal number when it is expanded. The
1645 optional option argument n defines the number of places after the
1646 decimal point in this case. The -X option causes the expansion to be
1647 represented using the %a format defined by ISO C-99. The optional
1648 option argument n defines the number of places after the decimal (or
1649 radix) point in this case.
1650
1651
1652
1653 An internal integer representation of a variable can be specified with
1654 the -i [n] option of the typeset special built-in command. The optional
1655 option argument n specifies an arithmetic base to be used when
1656 expanding the variable. If you do not specify an arithmetic base, base
1657 10 is used.
1658
1659
1660 Arithmetic evaluation is performed on the value of each assignment to a
1661 variable with the -E, -F, -X or -i option. Assigning a floating point
1662 number to a variable whose type is an integer causes the fractional
1663 part to be truncated.
1664
1665 Prompting
1666 When used interactively, the shell prompts with the value of PS1 after
1667 expanding it for parameter expansion, command substitution, and
1668 arithmetic substitution, before reading a command. In addition, each
1669 single ! in the prompt is replaced by the command number. A !! is
1670 required to place ! in the prompt. If at any time a NEWLINE is typed
1671 and further input is needed to complete a command, then the secondary
1672 prompt, that is, the value of PS2, is issued.
1673
1674 Conditional Expressions
1675 A conditional expression is used with the [[ compound command to test
1676 attributes of files and to compare strings. Field splitting and file
1677 name generation are not performed on the words between [[ and ]].
1678
1679
1680 Each expression can be constructed from one or more of the following
1681 unary or binary expressions:
1747 -o ?option
1748 True, if option named option is a valid option
1749 name.
1750
1751
1752 -O file
1753 True, if file exists and is owned by the effective
1754 user id of this process.
1755
1756
1757 -p file
1758 True, if file exists and is a FIFO special file or
1759 a pipe.
1760
1761
1762 -r file
1763 True, if file exists and is readable by current
1764 process.
1765
1766
1767 -R name
1768 True if variable name is a name reference.
1769
1770
1771 -s file
1772 True, if file exists and has size greater than
1773 zero.
1774
1775
1776 -S file
1777 True, if file exists and is a socket.
1778
1779
1780 -t fildes
1781 True, if file descriptor number fildes is open and
1782 associated with a terminal device.
1783
1784
1785 -u file
1786 True, if file exists and it has its setuid bit
1787 set.
1788
1789
1790 -v name
1791 True, if variable name is a valid variable name
1792 and is set.
1793
1794
1795 -w file
1796 True, if file exists and is writable by current
1797 process.
1798
1799
1800 -x file
1801 True, if file exists and is executable by current
1802 process. If file exists and is a directory, then
1803 true if the current process has permission to
1804 search in the directory.
1805
1806
1807 -z string
1808 True, if length of string is zero.
1809
1810
1811 file1 -ef file2
1812 True, if file1 and file2 exist and refer to the
1813 same file.
1814
1844 string matches the pattern the .sh.match array
1845 variable contains the match and sub-pattern
1846 matches.
1847
1848
1849 string =~ ere
1850 True if string matches the pattern ~(E)ere where
1851 ere is an extended regular expression.
1852
1853
1854 string1 < string2
1855 True, if string1 comes before string2 based on
1856 ASCII value of their characters.
1857
1858
1859 string1 > string2
1860 True, if string1 comes after string2 based on
1861 ASCII value of their characters.
1862
1863
1864 In each of the above expressions, if file is of the form /dev/fd/n,
1865 where n is an integer, the test is applied to the open file whose
1866 descriptor number is n.
1867
1868
1869 The following obsolete arithmetic comparisons are also supported:
1870
1871 exp1 -eq exp2
1872 True, if exp1 is equal to exp2.
1873
1874
1875 exp1 -ge exp2
1876 True, if exp1 is greater than or equal to exp2.
1877
1878
1879 exp1 -gt exp2
1880 True, if exp1 is greater than exp2.
1881
1882
1883 exp1 -le exp2
1884 True, if exp1 is less than or equal to exp2.
1885
1886
1887 exp1 -lt exp2
1888 True, if exp1 is less than exp2.
1889
1890
1934
1935
1936 No intervening space is allowed between the characters of redirection
1937 operators.
1938
1939 <word
1940 Use file word as standard input (file descriptor 0).
1941
1942
1943 >word
1944 Use file word as standard output (file descriptor 1). If
1945 the file does not exist then it is created. If the file
1946 exists, and the noclobber option is on, this causes an
1947 error. Otherwise, it is truncated to zero length.
1948
1949
1950 >|word
1951 Same as >, except that it overrides the noclobber option.
1952
1953
1954 >;word
1955 Write output to a temporary file. If the command
1956 completes successfully rename it to word, otherwise,
1957 delete the temporary file. >;word cannot be used with
1958 the exec(2) built-in.
1959
1960
1961 >>word
1962 Use file word as standard output. If the file exists,
1963 then output is appended to it (by first seeking to the
1964 end-of-file). Otherwise, the file is created.
1965
1966
1967 <>word
1968 Open file word for reading and writing as standard input.
1969
1970
1971 <<[-]word
1972 The shell input is read up to a line that is the same as
1973 word after any quoting has been removed, or to an end-of-
1974 file. No parameter substitution, command substitution,
1975 arithmetic substitution or file name generation is
1976 performed on word. The resulting document, called a here-
1977 document, becomes the standard input. If any character of
1978 word is quoted, then no interpretation is placed upon the
1979 characters of the document. Otherwise, parameter
1980 expansion, command substitution, and arithmetic
2201 built-in utility. If the get discipline is defined for a variable, it
2202 is invoked whenever the specified variable is referenced. If the
2203 variable .sh.value is assigned a value inside the discipline function,
2204 the referenced variable is evaluated to this value instead. If the set
2205 discipline is defined for a variable, it is invoked whenever the
2206 specified variable is assigned a value. If the append discipline is
2207 defined for a variable, it is invoked whenever a value is appended to
2208 the specified variable. The variable .sh.value is specified the value
2209 of the variable before invoking the discipline, and the variable is
2210 assigned the value of .sh.value after the discipline completes. If
2211 .sh.value is unset inside the discipline, then that value is unchanged.
2212 If the unset discipline is defined for a variable, it is invoked
2213 whenever the specified variable is unset. The variable is not unset
2214 unless it is unset explicitly from within this discipline function.
2215
2216
2217 The variable .sh.name contains the name of the variable for which the
2218 discipline function is called, .sh.subscript is the subscript of the
2219 variable, and .sh.value contains the value being assigned inside the
2220 set discipline function. For the set discipline, changing .sh.value
2221 changes the value that gets assigned. The variable _ is a reference to
2222 the variable including the subscript if any. For the set discipline,
2223 changing .sh.value will change the value that gets assigned. Finally,
2224 the expansion ${ var.name}, when name is the name of a discipline, and
2225 there is no variable of this name, is equivalent to the command
2226 substitution ${var.name;}.
2227
2228
2229 Name Spaces
2230 Commands and functions that are executed as part of the list of a
2231 namespace command that modify variables or create new ones, create a
2232 new variable whose name is the name of the name space as given by
2233 identifier preceded by two dots (..). When a variable whose name is
2234 name is referenced, it is first searched for using .identifier.name.
2235 Similarly, a function defined by a command in the namespace list is
2236 created using the name space name preceded by two dots (..).
2237
2238 When the list of a namespace command contains a namespace command, the
2239 names of variables and functions that are created consist of the
2240 variable or function name preceded by the list of identifiers each
2241 preceded by two dots (..).
2242
2243 Outside of a name space, a variable or function created inside a name
2244 space can be referenced by preceding it with the name space name.
2245
2246 By default, variables staring with .sh are in the sh name space.
2247
2248
2249 Typed Variables
2250 Typed variables provide a way to create data structure and objects. A
2251 type can be defined either by a shared library, by the enum built-in
2252 command described below, or by using the new -T option of the typeset
2253 built-in command. With the -T option of typeset, the type name,
2254 specified as an option argument to -T, is set with a compound variable
2255 assignment that defines the type. Function definitions can appear
2256 inside the compound variable assignment and these become discipline
2257 functions for this type and can be invoked or redefined by each
2258 instance of the type. The function name create is treated specially. It
2259 is invoked for each instance of the type that is created but is not
2260 inherited and cannot be redefined for each instance.
2261
2262 When a type is defined a special built-in command of that name is
2263 added. These built-ins are declaration commands and follow the same
2264 expansion rules as all the special built-in commands defined below that
2265 are preceded by a dot (.). These commands can subsequently be used
2266 inside further type definitions. The man page for these commands can be
2267 generated by using the --man option or any of the other -- options
2268 described with getopts. The -r, -a, -A, -h and -S options of typeset
2269 are permitted with each of these new built-ins.
2270
2271 An instance of a type is created by invoking the type name followed by
2272 one or more instance names. Each instance of the type is initialized
2273 with a copy of the sub-variables except for sub-variables that are
2274 defined with the -s option. Variables defined with -S are shared by all
2275 instances of the type. Each instance can change the value of any sub-
2276 variable and can also define new discipline functions of the same names
2277 as those defined by the type definition as well as any standard
2278 discipline names. No additional sub-variables can be defined for any
2279 instance.
2280
2281 When defining a type, if the value of a sub-variable is not set and the
2282 -r attribute is specified, it causes the sub-variable to be a required
2283 sub-variable. Whenever an instance of a type is created, all required
2284 sub-variables must be specified. These sub-variables become readonly in
2285 each instance.
2286
2287 When unset is invoked on a sub-variable within a type, and the -r
2288 attribute has not been specified for this field, the value is reset to
2289 the default value associative with the type. Invoking unset on a type
2290 instance not contained within another type deletes all sub-variables
2291 and the variable itself.
2292
2293 A type definition can be derived from another type definition by
2294 defining the first sub-variable name as _ and defining its type as the
2295 base type. Any remaining definitions will be additions and
2296 modifications that apply to the new type. If the new type name is the
2297 same is that of the base type, the type will be replaced and the
2298 original type will no longer be accessible.
2299
2300 The typeset command with -T and no option argument or operands will
2301 write all the type definitions to standard output in a form that that
2302 can be read in to create all the types.
2303
2304
2305 Jobs
2306 If the monitor option of the set command is turned on, an interactive
2307 shell associates a job with each pipeline. It keeps a table of current
2308 jobs, printed by the jobs command, and assigns them small integer
2309 numbers. When a job is started asynchronously with &, the shell prints
2310 a line which looks like:
2311
2312 [1] 1234
2313
2314
2315
2316
2317 indicating that the job which was started asynchronously was job number
2318 1 and had one (top-level) process, whose process id was 1234.
2319
2320
2321 If you are running a job and wish to stop it, CTRL-z sends a STOP
2322 signal to the current job. The shell normally displays a message that
2323 the job has been stopped, and displays another prompt. You can then
2324 manipulate the state of this job, putting it in the background with the
2325 bg command, or run some other commands and then eventually bring the
2326 job back into the foreground with the foreground command fg. A CTRL-z
2327 takes effect immediately and is like an interrupt in that pending
2328 output and unread input are discarded when it is typed.
2329
2330
2331 A job being run in the background stops if it tries to read from the
2332 terminal. Background jobs are normally allowed to produce output, but
2333 this can be disabled by giving the command sttytostop. If you set this
2334 tty option, then background jobs stop when they try to produce output
2335 like they do when they try to read input.
2336
2337
2338 A job pool is a collection of jobs started with list & associated with
2339 a name.
2340
2341
2342 There are several ways to refer to jobs in the shell. A job can be
2343 referred to by the process id of any process of the job or by one of
2344 the following:
2345
2346 %number
2347 The job with the specified number.
2348
2349
2350 pool
2351 All the jobs in the job pool named by pool.
2352
2353
2354 pool.number
2355 The job number number in the pool named by pool.
2356
2357
2358 %string
2359 Any job whose command line begins with string.
2360
2361
2362 %?string
2363 Any job whose command line contains string.
2364
2365
2366 %%
2367 Current job.
2368
2369
2370 %+
2371 Equivalent to %%.
2372
2373
2374 %-
2375 Previous job.
2376
2377
2378 In addition, unless noted otherwise, wherever a job can be specified,
2379 the name of a background job pool can be used to represent all the jobs
2380 in that pool.
2381
2382
2383
2384 The shell learns immediately whenever a process changes state. It
2385 normally informs you whenever a job becomes blocked so that no further
2386 progress is possible, but only just before it prints a prompt. This is
2387 done so that it does not otherwise disturb your work. The notify option
2388 of the set command causes the shell to print these job change messages
2389 as soon as they occur.
2390
2391
2392 When the monitor option is on, each background job that completes
2393 triggers any trap set for CHLD.
2394
2395
2396 When you try to leave the shell while jobs are running or stopped, you
2397 are warned that You have stopped(running) jobs. You can use the jobs
2398 command to see what they are. If you immediately try to exit again, the
2399 shell does not warn you a second time, and the stopped jobs are
2400 terminated. When a login shell receives a HUP signal, it sends a HUP
2401 signal to each job that has not been disowned with the disown built-in
2402 command.
2403
2406 command is followed by & and the monitor option is not active.
2407 Otherwise, signals have the values inherited by the shell from its
2408 parent. See the trap built-in command.
2409
2410 Execution
2411 Each time a command is read, the substitutions are carried out. If the
2412 command name matches one of the ones in the Special Built-in Commands
2413 section of this manual page, it is executed within the current shell
2414 process. Next, the command name is checked to see if it matches a user
2415 defined function. If it does, the positional parameters are saved and
2416 then reset to the arguments of the function call. A function is also
2417 executed in the current shell process. When the function completes or
2418 issues a return, the positional parameter list is restored. For
2419 functions defined with the function name syntax, any trap set on EXIT
2420 within the function is executed. The exit value of a function is the
2421 value of the last command executed. If a command name is not a special
2422 built-in command or a user defined function, but it is one of the
2423 built-in commands, it is executed in the current shell process.
2424
2425
2426 The shell variables PATH and FPATH define the search path for the
2427 directory containing the command. Alternative directory names are
2428 separated by a colon (:). The default path is /bin:/usr/bin:,
2429 specifying /bin, /usr/bin, and the current directory in that order. The
2430 current directory can be specified by two or more adjacent colons, or
2431 by a colon at the beginning or end of the path list. If the command
2432 name contains a slash (/), the search path is not used. Otherwise, each
2433 directory in the list of directories defined by PATH and FPATH is
2434 checked in order. If the directory being searched is contained in the
2435 value of the FPATH variable and contains a file whose name matches the
2436 command being searched, then this file is loaded into the current shell
2437 environment as if it were the argument to the . command except that
2438 only preset aliases are expanded, and a function of the specified name
2439 is executed as described in this manual page.
2440
2441
2442 If this directory is not in FPATH, the shell first determines whether
2443 there is a built-in version of a command corresponding to a given
2444 pathname and, if so, it is invoked in the current process. If no built-
2445 in is found, the shell checks for a file named .paths in this
2446 directory. If found and there is a line of the form:
2447
2448 FPATH=path
2449
2450 where path is an existing directory, then that directory is searched
2451 immediately after the current directory as if it were found in the
2452 FPATH variable. If path does not begin with /, it is checked for
2453 relative to the directory being searched.
2454
2455
2456 The .paths file is then checked for a line of the form:
2457
2458 PLUGIN_LIB=libname [ : libname ] ...
2459
2460 Each library named by libname will be searched for as if it were an
2461 option argument to builtin -f and, if it contains a built-in of the
2462 specified name, this is executed instead of a command by this name.
2463
2464
2465 Any built-in loaded from a library found this way will be associated
2466 with the directory containing the .paths file so it will only execute
2467 if not found in an earlier directory.
2468
2469
2470 Finally, the directory will be checked for a file of the given name.
2471 If the file has execute permission but is not an a.out file, it is
2472 assumed to be a file containing shell commands. A separate shell is
2473 spawned to read it. All non-exported variables are removed in this
2474 case. If the shell command file doesn't have read permission, and/or if
2475 the setuid and setgid bits are set on the file, then the shell executes
2476 an agent whose job it is to set up the permissions and execute the
2477 shell with the shell command file passed down as an open file.
2478
2479 If the .paths contains a line of the form:
2480
2481 name=value
2482
2483 in the first or second line, then the environment variable name is
2484 modified by prepending the directory specified by value to the
2485 directory list. If value is not an absolute directory, then it
2486 specifies a directory relative to the directory in which the executable
2487 was found. If the environment variable name does not already exist it
2488 will be added to the environment list for the specified command.
2489
2490 A parenthesized command is executed in a sub-shell without removing
2491 non-exported variables.
2492
2493
2494 Command Re-entry
2495 The text of the last HISTSIZE (default 512) commands entered from a
2496 terminal device is saved in a history file. The file $HOME/.sh_history
2497 is used if the HISTFILE variable is not set or if the file it names is
2498 not writable. A shell can access the commands of all interactive shells
2499 which use the same named HISTFILE. The built-in command hist is used to
2500 list or edit a portion of this file. The portion of the file to be
2501 edited or listed can be selected by number or by giving the first
2502 character or characters of the command. A single command or range of
2503 commands can be specified. If you do not specify an editor program as
2504 an argument to hist then the value of the variable HISTEDIT is used. If
2505 HISTEDIT is unset, the obsolete variable FCEDIT is used. If FCEDIT is
2506 not defined, then /bin/ed is used. The edited commands are printed and
2507 executed again upon leaving the editor unless you quit without writing.
2508 The -s option (and in obsolete versions, the editor name -) is used to
2509 skip the editing phase and to re-execute the command. In this case a
2510 substitution parameter of the form old=newcan be used to modify the
2511 command before execution. For example, with the preset alias r, which
2512 is aliased to 'hist -s', typing `r bad=good c' re-executes the most
2513 recent command which starts with the letter c, replacing the first
3425 bg [ job...]
3426
3427 This command is only on systems that support job control. Puts each
3428 specified job into the background. The current job is put in the
3429 background if job is not specified. See the Jobs section of this
3430 manual page for a description of the format of job.
3431
3432
3433 + break [n]
3434
3435 Exit from the enclosing for, while, until, or select loop, if any.
3436 If n is specified, then break n levels.
3437
3438
3439 builtin [-ds ] [-f file] [name ...]
3440
3441 If name is not specified, and no -f option is specified, the built-
3442 ins are printed on standard output. The -s option prints only the
3443 special built-ins. Otherwise, each name represents the pathname
3444 whose basename is the name of the built-in. The entry point
3445 function name is determined by prepending b_ to the built-in name.
3446 A built-in specified by a pathname will only be executed when that
3447 pathname would be found during the path search. Built-ins found in
3448 libraries loaded via the .paths file will be associate with the
3449 pathname of the directory containing the .paths file.
3450
3451 The ISO C/C++ prototype is bmycommand(int argc, char *argv[], void
3452 *context) for the built-in command mycommand where argv is an array
3453 of argc elements and context is an optional pointer to a Shell_t
3454 structure as described in <ast/shell.h> Special built-ins cannot be
3455 bound to a pathname or deleted. The -d option deletes each of the
3456 specified built-ins. On systems that support dynamic loading, the
3457 -f option names a shared library containing the code for built-ins.
3458 The shared library prefix and/or suffix, which depend on the
3459 system, can be omitted. Once a library is loaded, its symbols
3460 become available for subsequent invocations of builtin. Multiple
3461 libraries can be specified with separate invocations of the builtin
3462 command. Libraries are searched in the reverse order in which they
3463 are specified. When a library is loaded, it looks for a function in
3464 the library whose name is lib_init() and invokes this function with
3465 an argument of 0.
3466
3467
3468 cd [-LP] [arg]
3469 cd [-LP] old new
3470
3524 select loop. If n is specified, then resume at the nth enclosing
3525 loop.
3526
3527
3528 disown [job...]
3529
3530 Causes the shell not to send a HUP signal to each specified job, or
3531 all active jobs if job is omitted, when a login shell terminates.
3532
3533
3534 echo [arg ...]
3535
3536 When the first arg does not begin with a -, and none of the
3537 arguments contain a backslash (\), prints each of its arguments
3538 separated by a SPACE and terminated by a NEWLINE. Otherwise, the
3539 behavior of echo is system dependent and print or printf described
3540 in this section should be used. See echo(1) for usage and
3541 description.
3542
3543
3544 ++enum [ -i ] type[=(value ...) ]
3545
3546 Creates a declaration command named type that is an integer type
3547 that allows one of the specified values as enumeration names. If
3548 =(value ...) is omitted, then type must be an indexed array
3549 variable with at least two elements and the values are taken from
3550 this array variable. If -i is specified the values are case
3551 insensitive.
3552
3553
3554 +eval [arg ...]
3555
3556 The arguments are read as input to the shell and the resulting
3557 commands are executed.
3558
3559
3560 +exec [-c] [-a name ...] [arg ...]
3561
3562 If arg is specified, the command specified by the arguments is
3563 executed in place of this shell without creating a new process. The
3564 -c option causes the environment to be cleared before applying
3565 variable assignments associated with the exec invocation. The -a
3566 option causes name rather than the first arg, to become argv[0] for
3567 the new process. Input and output arguments can appear and affect
3568 the current process. If arg is not specified, the effect of this
3569 command is to modify file descriptors as prescribed by the
3570 input/output redirection list. In this case, any file descriptor
3571 numbers greater than 2 that are opened with this mechanism are
3572 closed when invoking another program.
3573
3574
3575 +exit [n]
3576
3577 Causes the shell to exit with the exit status specified by n. The
3578 value is the least significant 8 bits of the specified status. If n
3579 is omitted, then the exit status is that of the last command
3580 executed. An end-of-file also causes the shell to exit except for a
3581 shell which has the ignoreeof option turned on. See set.
3582
3583
3584 ++export [-p] [name[=value]] ...
3585
3586 If name is not specified, the names and values of each variable
3587 with the export attribute are printed with the values quoted in a
3588 manner that allows them to be re-entered. The export command is the
3589 same as typeset -x except that if you use export within a function,
3590 no local variable is created. The -p option causes the word export
3591 to be inserted before each one. Otherwise, the specified names are
3592 marked for automatic export to the environment of subsequently-
3593 executed commands.
3594
3595
3596 false
3597
3598 Does nothing, and exits 1. Used with until for infinite loops.
3599
3600
3601 fg [job ...]
3602
3603 This command is only on systems that support job control. Each job
3604 specified is brought to the foreground and waited for in the
3605 specified order. Otherwise, the current job is brought into the
3606 foreground. See Jobs for a description of the format of job.
3607
3608
3609 getconf [name [pathname]]
3610
3611 Prints the current value of the configuration parameter specified
3612 by name. The configuration parameters are defined by the IEEE POSIX
3613 1003.1 and IEEE POSIX 1003.2 standards. See pathconf(2) and
3664 for listing. The option -r reverses the order of the commands and
3665 the option -n suppresses command numbers when listing. In the
3666 second form, command is interpreted as first described in this
3667 section and defaults to the last command executed. The resulting
3668 command is executed after the optional substitution old=new is
3669 performed.
3670
3671
3672 jobs -lnp [job ...]
3673
3674 Lists information about each specified job, or all active jobs if
3675 job is omitted. The -l option lists process ids in addition to the
3676 normal information. The -n option only displays jobs that have
3677 stopped or exited since last notified. The -p option causes only
3678 the process group to be listed. See Jobs for a description of the
3679 format of job.
3680
3681
3682 kill [-s signame] job ...
3683 kill [-n signum] job ...
3684 kill -Ll [sig ...]
3685
3686 Sends either the TERM (terminate) signal or the specified signal to
3687 the specified jobs or processes. Signals are either specified by
3688 number with the -n option or by name with the -s option (as
3689 specified in <signal.h>, stripped of the prefix `SIG with the
3690 exception that SIGCLD is named CHLD). For backward compatibility,
3691 the n and s can be omitted and the number or name placed
3692 immediately after the -. If the signal being sent is TERM
3693 (terminate) or HUP (hang up), then the job or process is sent a
3694 CONT (continue) signal if it is stopped. The argument job can be
3695 the process id of a process that is not a member of one of the
3696 active jobs. See Jobs for a description of the format of job. In
3697 the third form, kill -l or kill -L, if sig is not specified, the
3698 signal names are listed. The -l option lists only the signal names
3699 whereas -L lists each signal name and corresponding number.
3700 Otherwise, for each sig that is a name, the corresponding signal
3701 number is listed. For each sig that is a number, the signal name
3702 corresponding to the least significant 8 bits of sig is listed.
3703
3704
3705 let [arg ...]
3706
3707 Each arg is a separate arithmetic expression to be evaluated. let
3708 only recognizes octal constants starting with 0 when the set option
3709 letoctal is on. See the Arithmetic Evaluation section of this
3710 manual page for a description of arithmetic expression evaluation.
3711 The exit status is 0 if the value of the last expression is non-
3712 zero, and 1 otherwise.
3713
3714
3715 +newgrp [arg ...]
3716
3717 Equivalent to exec /bin/newgrp arg ...
3718
3719
3720 print [-CRenprsv] [ -u unit] [ -f format ] [ arg ...]
3721
3722 With no options or with option - or --, each arg is printed on
3723 standard output. The -f option causes the arguments to be printed
3724 as described by printf. In this case, any e, n, r, or R options are
3725 ignored. Otherwise, unless the -R or -r, are specified, the
3726 following escape conventions are applied:
3727
3728 \a
3729 Alert character (ASCII 07)
3730
3731
3732 \b
3733 Backspace character (ASCII 010)
3734
3735
3736 \c
3737 Causes print to end without processing more arguments and
3738 not adding a NEWLINE
3739
3740
3757 \v
3758 Vertical TAB character (ASCII 013)
3759
3760
3761 \E
3762 Escape character (ASCII 033)
3763
3764
3765 \\
3766 Backslash character \
3767
3768
3769 \0x
3770 Character defined by the 1, 2, or 3-digit octal string
3771 specified by x
3772
3773 The -R option prints all subsequent arguments and options other
3774 than -n. The -e causes the escape conventions to be applied This is
3775 the default behavior. It reverses the effect of an earlier -r. The
3776 -p option causes the arguments to be written onto the pipe of the
3777 process spawned with |& instead of standard output. The -v option
3778 treats each arg as a variable name and writes the value in the
3779 printf %B format. The -C option treats each arg as a variable name
3780 and writes the values in the printf %#B format. The -s option
3781 causes the arguments to be written onto the history file instead of
3782 standard output. The -u option can be used to specify a one digit
3783 file descriptor unit number unit on which the output is placed. The
3784 default is 1. If the option -n is used, no NEWLINE is added to the
3785 output.
3786
3787
3788 printf format [arg ...]
3789
3790 The arguments arg are printed on standard output in accordance with
3791 the ANSI-C formatting rules associated with the format string
3792 format. If the number of arguments exceeds the number of format
3793 specifications, the format string is reused to format remaining
3794 arguments. The following extensions can also be used:
3795
3796
3797 %b
3798
3799 A %b format can be used instead of %s to cause escape sequences
3800 in the corresponding arg to be expanded as described in print.
3801
3802
3803 %B
3804
3805 A %B option causes each of the arguments to be treated as
3806 variable names and the binary value of the variables is
3807 printed. This is most useful for variables with an attribute of
3808 b.
3809
3810
3811 %H
3812
3813 A %H format can be used instead of %s to cause characters in
3814 arg that are special in HTML and XML to be output as their
3815 entity name. The alternate flag # formats the output for use as
3816 a URI.
3817
3818
3819 %P
3820
3821 A %P format can be used instead of %s to cause arg to be
3822 interpreted as an extended regular expression and be printed as
3823 a shell pattern.
3824
3825
3826
3827 %R
3828
3829 A %R format can be used instead of %s to cause arg to be
3830 interpreted as a shell pattern and to be printed as an extended
3831 regular expression.
3832
3833
3834 %q
3835
3836 A %q format can be used instead of %s to cause the resulting
3837 string to be quoted in a manner than can be input again to the
3838 shell. When q is preceded by the alternative format specifier,
3839 #, the string is quoted in manner suitable as a field in a .csv
3840 format file.
3841
3842
3843 %(date-format)
3844
3845 A %(date-format)T format can be use to treat an argument as a
3846 date/time string and to format the date/time according to the
3847 date-format as defined for the date(1) command.
3848
3849
3850
3851 %Z
3852
3853 A %Z format outputs a byte whose value is 0.
3854
3855
3856 %d
3857
3858 The precision field of the %d format can be followed by a . and
3859 the output base. In this case, the # flag character causes
3860 base# to be prepended.
3861
3862
3863 #
3864
3865 The # flag, when used with the %d format without an output
3866 base, displays the output in powers of 1000 indicated by one of
3867 the following suffixes: k M G T P E, and when used with the %i
3868 format displays the output in powers of 1024 indicated by one
3869 of the following suffixes: Ki Mi Gi Ti Pi Ei.
3870
3871
3872
3873 =
3874
3875 The = flag centers the output within the specified field width.
3876
3877
3878 L
3879
3880 The L flag, when used with the %c or %s formats, treats
3881 precision as character width instead of byte count.
3882
3883
3884 ,
3885
3886 The , flag, when used with the %d or %f formats, separates
3887 groups of digits with the grouping delimiter (, in groups of 3
3888 in the C locale).
3889
3890
3891
3892
3893 pwd [-LP]
3894
3895 Outputs the value of the current working directory. The -L option
3896 is the default. It prints the logical name of the current
3897 directory. If the -P option is specified, all symbolic links are
3898 resolved from the name. The last instance of -L or -P on the
3899 command line determines which method is used.
3900
3901
3902 read [-ACSprsv] [-d delim] [ -n n] [[ -N n] [[-t timeout] [-u unit]
3903 [vname?prompt] [ vname ... ]
3904
3905 The shell input mechanism. One line is read and is broken up into
3906 fields using the characters in IFS as separators. The escape
3907 character, \, is used to remove any special meaning for the next
3908 character and for line continuation. The -d option causes the read
3909 to continue to the first character of delim rather than NEWLINE.
3910 The -n option causes at most n bytes to read rather a full line but
3911 returns when reading from a slow device as soon as any characters
3912 have been read. The -N option causes exactly n to be read unless an
3913 end-of-file has been encountered or the read times out because of
3914 the -t option. In raw mode, -r, the \ character is not treated
3915 specially. The first field is assigned to the first vname, the
3916 second field to the second vname, etc., with leftover fields
3917 assigned to the last vname. When vname has the binary attribute and
3918 -n or -N is specified, the bytes that are read are stored directly
3919 into the variable. If the -v is specified, then the value of the
3920 first vname is used as a default value when reading from a terminal
3921 device. The -A option causes the variable vname to be unset and
3922 each field that is read to be stored in successive elements of the
3923 indexed array vname. The -C option causes the variable vname to be
3924 read as a compound variable. Blanks will be ignored when finding
3925 the beginning open parenthesis. The -S option causes the line to be
3926 treated like a record in a .csv format file so that double quotes
3927 can be used to allow the delimiter character and the new-line
3928 character to appear within a field. The -p option causes the input
3929 line to be taken from the input pipe of a process spawned by the
3930 shell using |&. If the -s option is present, the input is saved as
3931 a command in the history file. The option -u can be used to specify
3932 a one digit file descriptor unit unit to read from. The file
3933 descriptor can be opened with the exec special built-in command.
3934 The default value of unit n is 0. The option -t is used to specify
3935 a time out in seconds when reading from a terminal or pipe. If
3936 vname is omitted, then REPLY is used as the default vname. An end-
3937 of-file with the -p option causes cleanup for this process so that
3938 another can be spawned. If the first argument contains a ?, the
3939 remainder of this word is used as a prompt on standard error when
3940 the shell is interactive. The exit status is 0 unless an end-of-
3941 file is encountered or read has timed out.
3942
3943
3944 ++readonly [-p] [ vname[=value]] ...
3945
3946 If vname is not specified, the names and values of each variable
3947 with the read-only attribute is printed with the values quoted in a
3948 manner that allows them to be input again. The -p option causes the
3949 word readonly to be inserted before each one. Otherwise, the
3950 specified vnames are marked readonly and these names cannot be
3951 changed by subsequent assignment.
3952
3953
3954 +return [n]
3955
3956 Causes a shell function or script to return to the invoking script
3957 with the exit status specified by n. The value is the least
3958 significant 8 bits of the specified status. If n is omitted, then
3959 the return status is that of the last command executed. If return
3960 is invoked while not in a function or a script, then it behaves the
3961 same as exit.
3983
3984 Prints job completion messages as soon as a background job
3985 changes state rather than waiting for the next prompt.
3986
3987
3988 -B
3989
3990 Enable brace pattern field generation. This is the default
3991 behavior.
3992
3993
3994 -C
3995
3996 Prevents redirection (>) from truncating existing files. Files
3997 that are created are opened with the O_EXCL mode. Requires >|
3998 to truncate a file when turned on.
3999
4000
4001 -e
4002
4003 Unless contained in a || or && command, or the command
4004 following an if, while or until command or in the pipeline
4005 following !, if a command has a non-zero exit status, execute
4006 the ERR trap, if set, and exit. This mode is disabled while
4007 reading profiles.
4008
4009
4010 -f
4011
4012 Disables file name generation.
4013
4014
4015 -G
4016
4017 Causes the pattern ** by itself to match files and zero or more
4018 directories and subdirectories when used for file name
4019 generation. If followed by a / only directories and
4020 subdirectories are matched.
4021
4022
4023 -h
4024
4025 Each command becomes a tracked alias when first encountered.
4026
4027
4087
4088 Same as -G.
4089
4090
4091 gmacs
4092
4093 Puts you in a gmacs style inline editor for command entry.
4094
4095
4096 ignoreeof
4097
4098 The shell does not exit on end-of-file. The command exit
4099 must be used.
4100
4101
4102 keyword
4103
4104 Same as -k.
4105
4106
4107 letoctal
4108
4109 The let command allows octal constants starting with 0.
4110
4111
4112 markdirs
4113
4114 All directory names resulting from file name generation
4115 have a trailing / appended.
4116
4117
4118 monitor
4119
4120 Same as -m.
4121
4122
4123 multiline
4124
4125 The built-in editors use multiple lines on the screen for
4126 lines that are longer than the width of the screen. This
4127 might not work for all terminals.
4128
4129
4130 noclobber
4131
4293 If action is the null string then this signal is ignored by the
4294 shell and by the commands it invokes. If sig is ERR then action is
4295 executed whenever a command has a non-zero exit status. If sig is
4296 DEBUG then action is executed before each command. The variable
4297 .sh.command contains the contents of the current command line when
4298 action is running. If sig is 0 or EXIT and the trap statement is
4299 executed inside the body of a function defined with the function
4300 name syntax, then the command action is executed after the function
4301 completes. If sig is 0 or EXIT for a trap set outside any function
4302 then the command action is executed on exit from the shell. If sig
4303 is KEYBD, then action is executed whenever a key is read while in
4304 emacs, gmacs, or vi mode. The trap command with no arguments prints
4305 a list of commands associated with each signal number.
4306
4307
4308 true
4309
4310 Does nothing, and exits 0. Used with while for infinite loops.
4311
4312
4313 ++typeset [+-ACHSfblmnprtux ] [ +-EFLRXZi[n] ] [ +-M [ mapname ] ] [ -T
4314 [ tname=(assign_list) ] ] [ -h str ] [ -a [type] ] [ vname[=value ] ]
4315
4316 Sets attributes and values for shell variables and functions. When
4317 invoked inside a function defined with the function name syntax, a
4318 new instance of the variable vname is created, and the variable's
4319 value and type are restored when the function completes.
4320
4321 Using + rather than - causes these options to be turned off. If no
4322 vname arguments are specified, a list of vnames (and optionally the
4323 values) of the variables is printed. Using + rather than - keeps
4324 the values from being printed.) The -p option causes typeset
4325 followed by the option letters to be printed before each name
4326 rather than the names of the options. If any option other than -p
4327 is specified, only those variables which have all of the specified
4328 options are printed. Otherwise, the vnames and attributes of all
4329 variables that have attributes are printed.
4330
4331 The following list of attributes can be specified:
4332
4333 -a
4334 Declares vname to be an indexed array. This is optional
4335 unless except for compound variable assignments.
4336
4337
4338 -A
4339 Declares vname to be an associative array. Sub-scripts are
4340 strings rather than arithmetic expressions.
4341
4342
4343 -b
4344 The variable can hold any number of bytes of data. The data
4345 can be text or binary. The value is represented by the base64
4346 encoding of the data. If -Z is also specified, the size in
4347 bytes of the data in the buffer is determined by the size
4348 associated with the -Z. If the base64 string assigned results
4349 in more data, it is truncated. Otherwise, it is filled with
4350 bytes whose value is zero. The printf format %B can be used
4351 to output the actual data in this buffer instead of the
4352 base64 encoding of the data.
4353
4354
4355 -C
4356 Causes each vname to be a compound variable. If value names a
4357 compound variable it is copied into vname. Otherwise, it
4358 unsets each vname.
4359
4360
4361 -E
4362 Declares vname to be a double precision floating point
4363 number. If n is non-zero, it defines the number of
4364 significant figures that are used when expanding vname.
4365 Otherwise, ten significant figures is used.
4366
4367
4368 -f
4369 The names refer to function names rather than variable names.
4370 No assignments can be made and the only other valid options
4371 are -t, -u, and -x. The -t option turns on execution tracing
4372 for this function. The -u option causes this function to be
4373 marked undefined. The FPATH variable is searched to find the
4374 function definition when the function is referenced. If no
4375 options other than -f is specified, then the function
4376 definition is displayed on standard output. If +f is
4377 specified, then a line containing the function name followed
4378 by a shell comment containing the line number and path name
4379 of the file where this function was defined, if any, is
4380 displayed. The names refer to function names rather than
4381 variable names. No assignments can be made and the only
4382 other valid options are -S, -t, -u and -x. The -S can be
4383 used with discipline functions defined in a type to indicate
4384 that the function is static. For a static function, the same
4385 method will be used by all instances of that type no matter
4386 which instance references it. In addition, it can only use
4387 value of variables from the original type definition. These
4388 discipline functions cannot be redefined in any type
4389 instance. The -t option turns on execution tracing for this
4390 function. The -u option causes this function to be marked
4391 undefined. The FPATH variable will be searched to find the
4392 function definition when the function is referenced. If no
4393 options other than -f is specified, then the function
4394 definition will be displayed on standard output. If +f is
4395 specified, then a line containing the function name followed
4396 by a shell comment containing the line number and path name
4397 of the file where this function was defined, if any, is
4398 displayed. The exit status can be used to determine whether
4399 the function is defined so that typeset -f .sh.math. name
4400 will return 0 when math function name is defined and non-zero
4401 otherwise.
4402
4403 The -i attribute cannot be specified with -f.
4404
4405
4406 -F
4407 Declares vname to be a double precision floating point
4408 number. If n is non-zero, it defines the number of places
4409 after the decimal point that are used when expanding vname.
4410 Otherwise ten places after the decimal point is used.
4411
4412
4413 -h
4414 Used within type definitions to add information when
4415 generating information about the sub-variable on the man
4416 page. It is ignored when used outside of a type definition.
4417 When used with -f the information is associated with the
4418 corresponding discipline function.
4419
4420
4421 -H
4422 This option provides UNIX to hostname file mapping on non-
4423 UNIX machines.
4424
4425
4426 -i
4427 Declares vname to be represented internally as integer. The
4428 right hand side of an assignment is evaluated as an
4429 arithmetic expression when assigning to an integer. If n is
4430 non-zero, it defines the output arithmetic base, otherwise
4431 the output base is ten.
4432
4433 The -i attribute cannot be specified along with -R, -L, -Z,
4434 or -f.
4435
4436
4437 -l
4438 Used with -i, -E or -F to indicate long integer, or long
4439 float. Otherwise, all upper-case characters are converted to
4440 lower-case. The upper-case option, -u, is turned off.
4441 Equivalent to -M tolower.
4442
4443
4444 -L
4445 Left justify and remove leading blanks from value. If n is
4446 non-zero, it defines the width of the field, otherwise it is
4447 determined by the width of the value of first assignment.
4448 When the variable is assigned to, it is filled on the right
4449 with blanks or truncated, if necessary, to fit into the
4450 field. The -R option is turned off.
4451
4452 The -i attribute cannot be specified with -L.
4453
4454
4455 -m
4456 moves or renames the variable. The value is the name of a
4457 variable whose value will be moved to vname. The original
4458 variable will be unset. Cannot be used with any other
4459 options.
4460
4461
4462 -M
4463 Use the character mapping mapping such as tolower and toupper
4464 when assigning a value to each of the specified operands.
4465 When mapping is specified and there are not operands, all
4466 variables that use this mapping are written to standard
4467 output. When mapping is omitted and there are no operands,
4468 all mapped variables are written to standard output.
4469
4470
4471 -n
4472 Declares vname to be a reference to the variable whose name
4473 is defined by the value of variable vname. This is usually
4474 used to reference a variable inside a function whose name has
4475 been passed as an argument.
4476
4477
4478 -p
4479 The name, attributes and values for the given vname are
4480 written on standard output in a form that can be used as
4481 shell input. If +p is specified, then the values are not
4482 displayed.
4483
4484
4485 -R
4486 Right justify and fill with leading blanks. If n is non-zero,
4487 it defines the width of the field, otherwise it is determined
4488 by the width of the value of first assignment. The field is
4489 left filled with blanks or truncated from the end if the
4490 variable is reassigned. The -L option is turned off.
4491
4492 The -i attribute cannot be specified with -R.
4493
4494
4495 -r
4496 The specified vnames are marked read-only and these names
4497 cannot be changed by subsequent assignment.
4498
4499
4500 -S
4501 When used within the assign_list of a type definition, it
4502 causes the specified sub-variable to be shared by all
4503 instances of the type. When used inside a function defined
4504 with the function reserved word, the specified variables will
4505 have function static scope. Otherwise, the variable is unset
4506 prior to processing the assignment list.
4507
4508
4509 -t
4510 Tags the variables. Tags are user definable and have no
4511 special meaning to the shell.
4512
4513
4514 -T
4515 If followed by tname, it creates a type named by tname using
4516 the compound assignment assign_list to tname. Otherwise, it
4517 writes all the type definitions to standard output.
4518
4519
4520 -u
4521 When given along with -i specifies unsigned integer.
4522 Otherwise, all lower-case characters are converted to upper-
4523 case. The lower-case option, -l, is turned off. Equivalent
4524 to -M toupper.
4525
4526
4527 -x
4528 The specified vnames are marked for automatic export to the
4529 environment of subsequently-executed commands. Variables
4530 whose names contain a . cannot be exported.
4531
4532
4533 -X
4534 Declares vname to be a double precision floating point number
4535 and expands using the %a format of ISO-C99. If n is non-
4536 zero, it defines the number of hex digits after the radix
4537 point that is used when expanding vname. The default is 10.
4538
4539
4540 -Z
4541 Right justify and fill with leading zeros if the first non-
4542 blank character is a digit and the -L option has not been
4543 set. Remove leading zeros if the -L option is also set. If n
4544 is non-zero, it defines the width of the field, otherwise it
4545 is determined by the width of the value of first assignment.
4546
4547 The -i attribute cannot be specified with -Z.
4548
4549
4550
4551 ulimit [-HSacdfmnpstv] [ limit]
4552
4553 Set or display a resource limit. Many systems do not support one or
4554 more of these limits. The limit for a specified resource is set
4555 when limit is specified. The value of limit can be a number in the
4556 unit specified with each resource, or the value unlimited. When
4557 more than one resource is specified, then the limit name and unit
4558 is printed before the value.
4559
4697 function.
4698
4699
4700 Commands are then read as described, and the following options are
4701 interpreted by the shell when it is invoked:
4702
4703 -c
4704 If the -c option is present, then commands are read from
4705 the first arg. Any remaining arguments become positional
4706 parameters starting at 0.
4707
4708
4709 -D
4710 A list of all double quoted strings that are preceded by
4711 a $ is printed on standard output and the shell exits.
4712 This set of strings is subject to language translation
4713 when the locale is not C or POSIX. No commands are
4714 executed.
4715
4716
4717 -E
4718 Reads the file named by the ENV variable or by
4719 $HOME/.kshrc if not defined after the profiles.
4720
4721
4722 -i
4723 If the -i option is present or if the shell input and
4724 output are attached to a terminal (as told by
4725 tcgetattr(3C), this shell is interactive. In this case
4726 TERM is ignored (so that kill 0 does not kill an
4727 interactive shell) and INTR is caught and ignored (so
4728 that wait is interruptible). In all cases, QUIT is
4729 ignored by the shell.
4730
4731
4732 -P
4733 If -P or -o profile is present, the shell is a profile
4734 shell (see pfexec(1)).
4735
4736
4737 -R filename
4738 The -R filename option is used to generate a cross
4739 reference database that can be used by a separate
4740 utility to find definitions and references for variables
4741 and commands.
4742
4743
4744 -r
4745 If the -r option is present, the shell is a restricted
4746 shell.
4747
4748
4749 -s
4750 If the -s option is present or if no arguments remain,
4751 then commands are read from the standard input. Shell
4752 output, except for the output of the Special Commands
4753 listed, is written to file descriptor 2.
4754
4755
4756
4867 David Korn, dgk@research.att.com
4868
4869 ATTRIBUTES
4870 See attributes(5) for descriptions of the following attributes:
4871
4872
4873
4874
4875 +--------------------+-----------------+
4876 | ATTRIBUTE TYPE | ATTRIBUTE VALUE |
4877 +--------------------+-----------------+
4878 |Interface Stability | See below. |
4879 +--------------------+-----------------+
4880
4881
4882 The scripting interface is Uncommitted. The environment variables,
4883 .paths feature, and editing modes are Volatile.
4884
4885 SEE ALSO
4886 cat(1), cd(1), chmod(1), cut(1), date(1), egrep(1), echo(1), egrep(1),
4887 env(1), fgrep(1), grep(1), login(1), newgrp(1), paste(1), pfexec(1),
4888 printf(1), stty(1), test(1), umask(1), vi(1), dup(2), exec(2), fork(2),
4889 ioctl(2), lseek(2), pathconf(2), pipe(2), sysconf(3C), ulimit(2),
4890 umask(2), rand(3C), tcgetattr(3C), wait(3C), a.out(4), profile(4),
4891 attributes(5), environ(5), largefile(5), standards(5)
4892
4893
4894 Bolsky, Morris I. and Korn, David G., The New KornShell Command and
4895 Programming Language, Prentice Hall, 1995.
4896
4897
4898 POSIX-Part 2: Shell and Utilities, IEEE Std 1003.2-1992, ISO/IEC
4899 9945-2, IEEE, 1993.
4900
4901 NOTES
4902 ksh93 scripts should choose shell function names outside the namespace
4903 used by reserved keywords of the ISO C99, C++ and JAVA languages to
4904 avoid collisions with future enhancements to ksh93.
4905
4906
4907 If a command is executed, and then a command with the same name is
4908 installed in a directory in the search path before the directory where
4909 the original command was found, the shell continues to exec the
4910 original command. Use the -t option of the alias command to correct
4911 this situation.
4926
4927 Traps are not processed while a job is waiting for a foreground
4928 process. Thus, a trap on CHLD is not executed until the foreground job
4929 terminates.
4930
4931
4932 It is a good idea to leave a space after the comma operator in
4933 arithmetic expressions to prevent the comma from being interpreted as
4934 the decimal point character in certain locales.
4935
4936
4937 There might be some restrictions on creating a .paths file which is
4938 portable across other operating systems.
4939
4940
4941 If the system supports the 64-bit instruction set, /bin/ksh93 executes
4942 the 64-bit version of ksh93.
4943
4944
4945
4946 January 6, 2020 KSH93(1)
|