1'\" te 2.\" Copyright (c) 1982-2007 AT&T Knowledge Ventures 3.\" To view license terms, see http://www.eclipse.org/org/documents/epl-v10.html 4.\" Portions Copyright (c) 2009, Sun Microsystems, Inc. 5.\" Portions Copyright 2021 OmniOS Community Edition (OmniOSce) Association. 6.Dd March 8, 2021 7.Dt KSH93 1 8.Os 9.Sh NAME 10.Nm ksh93 , 11.Nm rksh93 12.Nd Korn Shell, a standard and restricted command and programming language 13.Sh SYNOPSIS 14.Nm ksh93 15.Op Sy \&+ Ns Fl abcefhikmnoprstuvxBCD 16.Op Fl R Ar file 17.Op Sy \&+ Ns Fl o Ar option 18\&... 19.Op Fl 20.Op Ar arg No ... 21.Nm rksh93 22.Op Sy \&+ Ns Fl abcefhikmnoprstuvxBCD 23.Op Fl R Ar file 24.Op Sy \&+ Ns Fl o Ar option 25\&... 26.Op Fl 27.Op Ar arg No ... 28.Sh DESCRIPTION 29.Nm 30is a command and programming language that executes commands read 31from a terminal or a file. 32.Nm rksh93 33is a restricted version of the command interpreter 34.Nm ksh93 . 35.Nm rksh93 36is used to set up login names and execution environments whose capabilities are 37more controlled than those of the standard shell. 38.Pp 39See 40.Sx Invocation 41for the meaning of arguments to the shell. 42.Ss "Definitions" 43A 44.Sy metacharacter 45is defined as one of the following characters: 46.Pp 47.Dl ; & ( \ ) | < > NEWLINE SPACE TAB 48.Pp 49A 50.Sy blank 51is a TAB or a SPACE. 52.Pp 53An 54.Sy identifier 55is a sequence of letters, digits, or underscores starting with a letter or 56underscore. 57Identifiers are used as components of variable names. 58.Pp 59A 60.Sy vname 61is a sequence of one or more identifiers separated by a period 62.Pq Sy \&. 63and optionally preceded by a period 64.Pq Sy \&. . 65.Sy vname Ns s 66are used as function and variable names. 67.Pp 68A 69.Sy word 70is a sequence of characters from the character set defined by the current 71locale, excluding non-quoted 72.Sy metacharacter Ns s . 73.Pp 74A 75.Sy command 76is a sequence of characters in the syntax of the shell language. 77The shell reads each command and carries out the desired action either directly 78or by invoking separate utilities. 79A built-in command is a command that is carried out by the shell itself without 80creating a separate process. 81Some commands are built-in purely for convenience and are not documented in 82this manual page. 83Built-ins that cause side effects in the shell environment and built-ins that 84are found before performing a path search 85.Pq see Sx Execution 86are documented in this manual page. 87For historical reasons, some of these built-ins behave differently than other 88built-ins and are called special built-ins. 89.Ss "Commands" 90A 91.Sy simple-command 92is a list of variable assignments 93.Pq see Sx Variable Assignments 94or a sequence of 95.Sy blank Ns -separated 96words which can be preceded by a list of variable assignments. 97See the 98.Sx Environment 99section of this manual page. 100.Pp 101The first word specifies the name of the command to be executed. 102Except as specified in this section, the remaining words are passed as 103arguments to the invoked command. 104The command name is passed as argument 0. 105See 106.Xr exec 2 . 107The 108.Em value 109of a simple-command is its exit status. 110If it terminates normally, its value is between 111.Sy 0 112and 113.Sy 255 . 114If it terminates abnormally, its value is 115.Sy 256 + 116.Em signum . 117The name of the signal corresponding to the exit status can be obtained by way 118of the 119.Fl l 120option of the 121.Ic kill 122built-in utility. 123.Pp 124A 125.Sy pipeline 126is a sequence of one or more commands separated by 127.Sy \&| . 128The standard output of each command but the last is connected by a 129.Xr pipe 2 130to the standard input of the next command. 131Each command, except possibly the last, is run as a separate process. 132The shell waits for the last command to terminate. 133The exit status of a pipeline is the exit status of the last command unless the 134.Sy pipefail 135option is enabled. 136Each pipeline can be preceded by the reserved word 137.Sy \&! . 138This causes the exit status of the 139pipeline to become 140.Sy 0 141if the exit status of the last command is 142.Sy non-zero , 143and 144.Sy 1 145if the exit status of the last command is 146.Sy 0 . 147.Pp 148A 149.Sy list 150is a sequence of one or more pipelines separated by 151.Sy \&; , 152.Sy \&& , 153.Sy \&|& , 154.Sy \&&& , 155or 156.Sy \&| , 157and optionally terminated by 158.Sy \&; , 159.Sy \&& , 160or 161.Sy \&|& . 162Of these 163five symbols, 164.Sy \&; , 165.Sy \&& , 166and 167.Sy \&|& 168have equal precedence, which is lower than that of 169.Sy \&&& 170and 171.Sy || . 172The symbols 173.Sy \&&& 174and 175.Sy || 176have equal precedence. 177.Pp 178A semicolon 179.Pq Sy \&; 180causes sequential execution of the preceding pipeline. 181An ampersand 182.Pq Sy \&& 183causes asynchronous execution of the preceding pipeline, that is, the shell 184does 185.Em not 186wait for that pipeline to finish. 187The symbol 188.Sy \&|& 189causes asynchronous execution of the preceding pipeline with a two-way pipe 190established to the parent shell. 191The standard input and output of the spawned pipeline can be written to and 192read from by the parent shell by applying the redirection operators 193.Sy \&<& 194and 195.Sy \&>& 196with 197.Cm arg p 198to 199commands and by using 200.Fl p 201option of the built-in commands 202.Ic read 203and 204.Ic print . 205The symbol 206.Sy \&&& 207.Pq Sy || 208causes the 209.Ar list 210following it to be executed only if the preceding pipeline returns a zero 211.Pq non-zero 212value. 213One or more NEWLINEs can appear in a 214.Ar list 215instead of a semicolon, to delimit a command. 216The first 217.Ar item 218of the first 219.Ar pipeline 220of a 221.Ar list 222that is a simple command not beginning with a redirection, and not occurring 223within a 224.Ic while , 225.Ic until , 226or 227.Ic if 228.Ar list , 229can be preceded by a semicolon. 230This semicolon is ignored unless the 231.Sy showme 232option is enabled as described with the 233.Ic set 234built-in. 235.Pp 236A 237.Sy command 238is either a simple-command or one of commands in the following list. 239Unless otherwise stated, the value returned by a command is that of the 240last simple-command executed in the command. 241.Pp 242.Bl -tag -width Ds -compact 243.It Xo 244.Ic for Ar vname 245.Op Cm in Ar word No ... 246.Ic ;do Ar list Ic ;done 247.Xc 248.Pp 249Each time a 250.Ic for 251command is executed, 252.Ar vname 253is set to the next 254.Ar word 255taken from the 256.Ic in 257.Ar word 258list. 259If 260.Ic in 261.Ar word ... 262is omitted, the 263.Ic for 264command executes the 265.Ic do 266.Ar list 267once for each positional parameter that is set starting from 1. 268Execution ends when there are no more words in the list. 269See 270.Sx Parameter Expansion . 271.Pp 272.It Xo 273.Ic for 274.Sy (( 275.Op Ar expr1 276.Sy \&; Op Ar expr2 277.Sy \&; Op Ar expr3 278.Sy )) 279.Ic ;do Ar list Ic ;done 280.Xc 281.Pp 282The arithmetic expression 283.Ar expr1 284is evaluated first. 285The arithmetic expression 286.Ar expr2 287is repeatedly evaluated until it evaluates to 288.Sy zero 289and when 290.Sy non-zero , 291.Ar list 292is executed and the arithmetic expression 293.Ar expr3 294is evaluated. 295If any expression is omitted, then it behaves as if it evaluated to 296.Sy 1 . 297See 298.Sx Arithmetic Evaluation . 299.Pp 300.It Xo 301.Ic select Ar vname 302.Op Sy in Ar word No ... 303.Ic ;do Ar list Ic ;done 304.Xc 305.Pp 306A 307.Ic select 308command prints on standard error (file descriptor 2) the set of 309.Ar words , 310each preceded by a number. 311If 312.Ic in Ar word ... 313is omitted, the positional parameters starting from 314.Sy 1 315are used instead. 316See 317.Sx Parameter Expansion . 318The 319.Ev PS3 320prompt is printed and a line is read from the standard input. 321If this line consists of the number of one of the listed 322.Ar word Ns No s , 323then the value of the variable 324.Ar vname 325is set to the 326.Ar word 327corresponding to this number. 328If this line is empty, the selection list is printed again. 329Otherwise the value of the variable 330.Ar vname 331is set to 332.Dv NULL . 333The contents of the line read from standard input is saved in the variable 334.Ev REPLY . 335The 336.Ar list 337is executed for each selection until a break or 338.Dv EOF 339is encountered. 340If the 341.Ev REPLY 342variable is set to 343.Dv NULL 344by the execution of 345.Ar list , 346the selection list is printed before displaying the 347.Ev PS3 348prompt for the next selection. 349.Pp 350.It Xo 351.Ic case Ar word Ic in 352.Oo \& 353.Op Sy \&( 354.Ar pattern Oo \&| Ar pattern Oc No ... Sy \&) 355.Ar list Sy ;; 356.Oc No ... 357.Ic esac 358.Xc 359.Pp 360A 361.Ic case 362command executes the 363.Ar list 364associated with the first 365.Ar pattern 366that matches 367.Ar word . 368The form of the patterns is the same as that used for file name generation. 369See 370.Sx File Name Generation . 371.Pp 372The 373.Sy \&;\&; 374operator causes execution of 375.Ic case 376to terminate. 377If 378.Sy \&;& 379is used in place of 380.Sy \&;\&; 381the next subsequent list, if any, is executed. 382.Pp 383.It Xo 384.Ic if Ar list Ic ;then Ar list 385.Op Ic ;elif Ar list Ic ;then Ar list 386.No ... 387.Op Ic ;else Ar list 388.Ic ;fi 389.Xc 390.Pp 391The 392.Ar list 393following 394.Ic if 395is executed and, if it returns a 396.Sy zero 397exit status, the 398.Ar list 399following the first 400.Ic then 401is executed. 402Otherwise, the 403.Ar list 404following 405.Ic elif 406is executed, and, if its value is 407.Sy zero , 408the 409.Ar list 410following the next 411.Ic then 412is executed. 413Failing each successive 414.Ic elif 415.Ar list , 416the 417.Ic else 418.Ar list 419is executed. 420If the 421.Ic if 422.Ar list 423has 424.Sy non-zero 425exit status and there is no 426.Ic else 427.Ar list , 428then the 429.Ic if 430command returns a 431.Sy zero 432exit status. 433.Pp 434.It Ic while Ar list Ic ;do Ar list Ic ;done 435.It Ic until Ar list Ic ;do Ar list Ic ;done 436.Pp 437A 438.Ic while 439command repeatedly executes the while 440.Ar list 441and, if the exit status of the last command in the list is zero, executes the 442.Ic do 443.Ar list , 444otherwise the loop terminates. 445If no commands in the 446.Ic do 447.Ar list 448are executed, then the 449.Ic while 450command returns a 451.Sy zero 452exit status. 453.Ic until 454can be used in place of 455.Ic while 456to negate the loop termination test. 457.Pp 458.It Sy (( Ns Ar expression Ns Sy )) 459.Pp 460The 461.Ar expression is evaluated using the rules for arithmetic evaluation described 462in this manual page. 463If the value of the arithmetic expression is 464.Sy non-zero , 465the exit status is 466.Sy 0 . 467Otherwise the exit status is 468.Sy 1 . 469.Pp 470.It Sy \&( Ns Ar list Ns Sy \&) 471.Pp 472Execute 473.Ar list 474in a separate environment. 475If two adjacent open parentheses are needed for nesting, a SPACE must be 476inserted to avoid evaluation as an arithmetic command as described in this 477section. 478.Pp 479.It Sy { Ar list Ns Sy ;} 480.Pp 481.Ar list 482is simply executed. 483Unlike the metacharacters, 484.Sy \&( 485and 486.Sy \&) , 487.Sy \&{ 488and 489.Sy \&} 490are 491.Sy reserved words 492and must occur at the beginning of a line or after a 493.Sy \&; 494to be recognized. 495.Pp 496.It Sy [[ Ar expression Sy ]] 497.Pp 498Evaluates 499.Ar expression 500and returns a 501.Sy zero 502exit status when 503.Ar expression 504is true. 505See 506.Sx Conditional Expressions 507for a description of 508.Ar expression . 509.Pp 510.It Ic function Ar varname Sy { Ar list Sy ;} 511.It Ar varname Sy \&() Sy { Ar list Sy ;} 512.Pp 513Define a function which is referenced by 514.Ar varname . 515A function whose 516.Ar varname 517contains a dot 518.Pq Sy \&. 519is called a discipline function and the portion of the 520.Ar varname 521preceding the last 522.Sy \&. 523must refer to an existing variable. 524.Pp 525The body of the function is the 526.Ar list 527of commands between 528.Sy { 529and 530.Sy } . 531A function defined with the 532.Ic function 533.Ar varname 534syntax can also be used as an argument to the 535.Sy \&. 536special built-in command to get the equivalent behavior as if the 537.Ar varname 538.Sy () 539syntax were used to define it. 540See 541.Sx Functions . 542.Pp 543.It Ic namespace Ar identifier Sy { Ar list Sy }; 544.Pp 545Defines or uses the name space 546.Ar identifier 547and runs the commands in 548.Ar list 549in this name space. 550See 551.Sx Name Spaces . 552.Pp 553.It Ic time Op Ar pipeline 554.Pp 555If 556.Ar pipeline 557is omitted, the user and system time for the current shell and completed child 558processes is printed on standard error. 559Otherwise, 560.Ar pipeline 561is executed and the elapsed time as well as the user and system time are 562printed on standard error. 563The 564.Ev TIMEFORMAT 565variable can be set to a format string that specifies how the timing 566information should be displayed. 567See 568.Sx Shell Variables 569for a description of the 570.Ev TIMEFORMAT 571variable. 572.El 573.Pp 574The following reserved words are recognized as reserved only when they are the 575first word of a command and are not quoted: 576.Bl -column -offset Ds xxxxxxxxxxx xxxxxxxxxxx xxxxxxxxxxx xxxxxxxxxxx 577.It Cm case Ta Cm do Ta Cm done Ta Cm else 578.It Cm elif Ta Cm esac Ta Cm for Ta Cm fi 579.It Cm function Ta Cm if Ta Cm select Ta Cm then 580.It Cm time Ta Cm until Ta Cm while Ta Sy { } 581.It Sy [[ ]] Ta Sy \&! Ta Ta 582.El 583.Ss "Variable Assignments" 584One or more variable assignments can start a simple command or can be arguments 585to the 586.Ic typeset , 587.Ic enum , 588.Ic export , or 589.Ic readonly 590special built-in commands. 591The syntax for an 592.Ar assignment 593is of the form: 594.Pp 595.Bl -tag -width Ds -compact 596.Sm off 597.It Ar varname Sy = Ar word 598.It Ar varname Oo Ar word Oc Sy = Ar word 599.Sm on 600.Pp 601No space is permitted between 602.Ar varname 603and the 604.Sy \&= 605or between 606.Sy \&= 607and 608.Ar word . 609The variable 610.Ar varname 611is unset before the assignment. 612.Pp 613.Sm off 614.It Ar varname Sy =( Ar assignlist Sy \&) 615.Sm on 616.Pp 617No space is permitted between 618.Ar varname 619and the 620.Sy = . 621An 622.Ar assignlist 623can be one of the following: 624.Bl -tag -width Ds 625.It Ar word No ... 626.Pp 627Indexed array assignment. 628.Sm off 629.It Oo Ar word Oc Sy = Ar word \ No ... 630.Sm on 631.Pp 632Associative array assignment. 633If prefixed by 634.Ic typeset Fl a , 635creates an indexed array instead. 636.It Ar assignment No ... 637.Pp 638Compound variable assignment. 639This creates a compound variable 640.Ar varname 641with sub-variables of the form 642.Ar varname.name , 643where 644.Ar name 645is the name 646portion of assignment. 647The value of 648.Ar varname 649contains all the assignment elements. 650Additional assignments made to sub-variables of 651.Ar varname 652are also displayed as part of the value of 653.Ar varname . 654If no 655.Ar assignment Ns No s 656are specified, 657.Ar varname 658is a compound variable allowing subsequence child elements to be defined. 659.It Ic typeset Oo Ar options Oc Ar assignment No ... 660.Pp 661Nested variable assignment. 662Multiple assignments can be specified by separating each of them with a 663.Sy \&; . 664The previous value is unset before the assignment. 665.It Ic \&. Ar filename 666.Pp 667Include the assignment commands contained in 668.Ar filename . 669.El 670.Pp 671In addition, a 672.Sy += 673can be used in place of the 674.Sy \&= 675to signify adding to or appending to the previous value. 676When 677.Sy += 678is applied to an arithmetic type, 679.Ar word 680is evaluated as an arithmetic expression and added to the current value. 681When applied to a string variable, the value defined by 682.Ar word 683is appended to the value. 684For compound assignments, the previous value is not unset and the new values 685are appended to the current ones provided that the types are compatible. 686The right hand side of a variable assignment undergoes all the expansion listed 687below except word splitting, brace expansion, and file name generation. 688When the left hand side is an assignment is a compound variable and the right 689hand is the name of a compound variable, the compound variable on the right 690will be copied or appended to the compound variable on the left. 691.El 692.Ss "Comments" 693A word beginning with 694.Ic # 695causes that word and all the following characters up to a NEWLINE to be 696commented, or ignored. 697.Ss "Aliasing" 698The first word of each command is replaced by the text of an alias if an alias 699for this word has been defined. 700An alias name consists of any number of characters excluding metacharacters, 701quoting characters, file expansion characters, parameter expansion characters, 702command substitution characters, the characters 703.Sy / 704and 705.Sy = . 706The replacement string can contain any valid shell script including the 707metacharacters listed in the 708.Sx Commands 709section. 710The first word of each command in the replaced text, other than any that are in 711the process of being replaced, are tested for aliases. 712If the last character of the alias value is a BLANK then the word following the 713alias is also checked for alias substitution. 714.Pp 715Aliases can be used to redefine built-in commands but cannot be used to 716redefine the reserved words listed in the 717.Sx Commands 718section. 719Aliases can be created and listed with the 720.Ic alias 721command and can be removed with the 722.Ic unalias 723command. 724.Pp 725Aliasing is performed when scripts are read, not while they are executed. 726For an alias to take effect, the 727.Ic alias 728definition command has to be executed before the command which references the 729alias is read. 730The following aliases are compiled into the shell but can be unset or 731redefined: 732.Bd -literal -offset Ds 733autoload='typeset -fu' 734command='command ' 735compound='typeset -C' 736fc=hist 737float='typeset -lE' 738functions='typeset -f' 739hash='alias -t --' 740history='hist -l' 741integer='typeset -li' 742nameref='typeset -n' 743nohup='nohup ' 744r='hist -s' 745redirect='command exec' 746source='command .' 747stop='kill -s STOP' 748suspend='kill -s STOP $$' 749times='{ { time;} 2>&1;}' 750type='whence -v' 751.Ed 752.Ss "Tilde Substitution" 753After alias substitution is performed, each word is checked to see if it begins 754with an unquoted tilde 755.Pq Sy \&~ . 756For tilde substitution, 757.Ar word 758also refers to the 759.Ar word 760portion of parameter expansion. 761See 762.Sx Parameter Expansion . 763.Pp 764If it does, the word up to a 765.Sy / 766is checked to see if it matches a user name in the password database. 767If a match is found, the 768.Sy ~ 769and the matched login name are replaced by the login directory of the matched 770user. 771If no match is found, the original text is left unchanged. 772A 773.Sy ~ 774by itself, or in front of a 775.Sy / , 776is replaced by 777.Ev $HOME . 778A 779.Sy ~ 780followed by a 781.Sy + 782or 783.Sy - 784is replaced by the value of 785.Ev $PWD 786and 787.Ev $OLDPWD 788respectively. 789.Pp 790In addition, when expanding a 791.Ar variable assignment , 792tilde substitution is attempted when the value of the assignment begins with a 793.Sy ~ , 794and when a 795.Sy ~ 796appears after a colon 797.Pq Sy \&: . 798The 799.Sy \&: 800also terminates a 801.Sy ~ 802login name. 803.Ss "Command Substitution" 804The standard output from a command enclosed in parentheses preceded by a dollar 805sign - 806.Sy \&$ Ns Po Ar list Pc - 807or in a brace group preceded by a dollar 808sign - 809.Sy \&${ Ar list Ns Sy ;} , 810- or in a pair of grave accents - 811.Sy `` 812- can be used as part or all of a word. 813Trailing NEWLINEs are removed. 814In the second case, the 815.Sy { 816and 817.Sy } 818are treated as a reserved words so that 819.Sy { 820must be followed by a blank and 821.Sy } 822must appear at the beginning of 823the line or follow a 824.Sy \&; . 825In the third (obsolete) form, the string between the quotes is processed for 826special quoting characters before the command is executed. 827See 828.Sx Quoting . 829.Pp 830The command substitution 831.Sy $(cat file) 832can be replaced by the equivalent 833but faster 834.Sy $(<file) . 835The command substitution 836.Sy $( Ns Ar n Sy \&<\&#\&) 837expands to the current byte offset for file descriptor 838.Ar n . 839Except for the second form, the command list is run in a subshell so that no 840side effects are possible. 841For the second form, the final 842.Sy } 843will be recognized as a reserved word after any token. 844.Ss "Arithmetic Substitution" 845An arithmetic expression enclosed in double parentheses preceded by a dollar 846sign - 847.Sy $(( Ns Ar arithmetic_expression Ns Sy )) 848- is replaced by the value of the arithmetic expression within the double 849parentheses. 850.Ss "Process Substitution" 851Each command argument of the form 852.Sy <( Ns Ar list Ns Sy \&) 853or 854.Sy >( Ns Ar list Ns Sy \&) 855runs process 856.Ar list 857asynchronously connected to some file in 858.Pa /dev/fd . 859The name of this file becomes the argument to the command. 860If the form with 861.Sy > 862is selected then writing on this file provides input for 863.Ar list . 864If 865.Sy < 866is used, then the file passed as an argument contains the output of the 867.Ar list 868process. 869.Pp 870For example, 871.Bd -literal -offset Ds 872paste <(cut -f1 file1) <(cut -f3 file2) | tee \e 873 >(process1) >(process2) 874.Ed 875.Pp 876.Sy cut Ns No s 877fields 1 and 3 from the files 878.Ar file1 879and 880.Ar file2 881respectively, 882.Sy paste Ns No s 883the results together, and sends it to the processes 884.Ar process1 885and 886.Ar process2 . 887It also displays the results to the standard output. 888The file, which is passed as an argument to the command, is a UNIX 889.Xr pipe 2 . 890Programs that expect to 891.Xr lseek 2 892on the file do not work. 893.Pp 894Process substitution of the form 895.Sy <( Ns Ar list Ns Sy \&) 896can also be used 897with the 898.Sy < 899redirection operator which causes the output of list to be standard input or 900the input for whatever file descriptor is specified. 901.Ss "Parameter Expansion" 902A parameter is a variable, one or more digits, or any of the characters 903.Sy \&* , 904.Sy \&@ , 905.Sy \&# , 906.Sy \&? , 907.Sy \&- , 908.Sy \&$ , 909and 910.Sy \&! . 911A variable is denoted by a 912.Ar vname . 913To create a variable whose 914.Ar vname 915contains a 916.Sy \&. , 917a variable whose 918.Ar vname 919consists of everything before the last 920.Sy \&. 921must already exist. 922A variable has a value and zero or more attributes. 923Variables can be assigned values and attributes by using the 924.Ic typeset 925special built-in command. 926The attributes supported by the shell are described later with the 927.Ic typeset 928special built-in command. 929Exported variables pass values and attributes to the environment. 930.Pp 931The shell supports both indexed and associative arrays. 932An element of an array variable is referenced by a subscript. 933A subscript for an indexed array is denoted by an arithmetic expression, 934.Pq see Sx Arithmetic Evaluation , 935between a 936.Sy \&[ 937and a 938.Sy \&] . 939To assign values to an indexed array, use 940.Ar vname Ns Sy =( Ns Ar value No ... Ns Sy \&) 941or 942.Sy set Fl A Ar vname value No ... . 943The value of all subscripts must be in the range of 944.Sy 0 945to 946.Sy 4,194,303 . 947A negative subscript is treated as an offset from the maximum current index +1 948so that -1 refers to the last element. 949Indexed arrays can be declared with the 950.Fl a 951option to 952.Ic typeset . 953Indexed arrays need not be declared. 954Any reference to a variable with a valid subscript is legal and an array will 955be created if necessary. 956.Pp 957An associative array is created with the 958.Fl A 959option to 960.Ic typeset . 961A subscript for an associative array is denoted by a string enclosed between 962.Sy \&[ 963and 964.Sy \&] . 965.Pp 966Referencing any array without a subscript is equivalent to referencing the 967array with subscript 968.Sy 0 . 969.Pp 970The value of a variable can be assigned by: 971.Bd -ragged -offset Ds 972.Ar vname Ns Sy = Ns Ar value 973.Op Ar vname Ns Sy = Ns Ar value 974.No \&... 975.Ed 976.Pp 977or 978.Bd -ragged -offset Ds 979.Ar vname Ns [ Ns Ar subscript Ns ]= Ns Ar value 980.Op Ar vname Ns [ Ns Ar subscript Ns ]= Ns Ar value 981.No ... 982.Ed 983.Pp 984Note that no space is allowed before or after the 985.Sy = . 986.Pp 987Attributes assigned by the 988.Ic typeset 989special built-in command apply to all elements of the array. 990An array element can be a simple variable, a compound variable or an array 991variable. 992An element of an indexed array can be either an indexed array or an associative 993array. 994An element of an associative array can also be either. 995To refer to an array element that is part of an array element, concatenate the 996subscript in brackets. 997For example, to refer to the 998.Ar foobar 999element of an associative array that is defined as the third element of the 1000indexed array, use 1001.Sm off 1002.Sy ${ Ar vname Sy \&[ Ar 3 Sy ][ Ar foobar Sy ]} . 1003.Sm on 1004.Pp 1005A 1006.Ar nameref 1007is a variable that is a reference to another variable. 1008A 1009.Ar nameref 1010is created with the 1011.Fl n 1012attribute of 1013.Ic typeset . 1014The value of the variable at the time of the 1015.Ic typeset 1016command becomes the variable that is referenced whenever the 1017.Ar nameref 1018variable is used. 1019The name of a 1020.Ar nameref 1021cannot contain a dot 1022.Pq \&. . 1023When a variable or 1024function name contains a dot 1025.Pq \&. 1026and the portion of the name up to the first \&. matches the name of a 1027.Ar nameref , 1028the variable referred to is obtained by replacing the 1029.Ar nameref 1030portion with the name of the variable referenced by the 1031.Ar nameref . 1032If a 1033.Ar nameref 1034is used as the index of a 1035.Cm for 1036loop, a name reference is established for each item in the list. 1037A 1038.Ar nameref 1039provides a convenient way to refer to the variable inside a function whose name 1040is passed as an argument to a function. 1041For example, if the name of a variable is passed as the first argument to a 1042function, the command 1043.Bd -literal -offset Ds 1044typeset -n var=$1 1045.Ed 1046.Pp 1047inside the function causes references and assignments to 1048.Ar var 1049to be references and assignments to the variable whose name has been passed to 1050the function. 1051If any of the floating point attributes, 1052.Fl E , 1053.Fl F 1054or 1055.Fl X , 1056or the integer attribute, 1057.Fl i , 1058is set for 1059.Ar vname , 1060then the 1061.Ar value 1062is subject to arithmetic evaluation as described in this manual page. 1063Positional parameters, parameters denoted by a number, can be assigned values 1064with the 1065.Cm set 1066special built-in command. 1067Parameter 1068.Sy $0 1069is set from argument zero when the shell is invoked. 1070.Pp 1071The character 1072.Sy $ 1073is used to introduce substitutable parameters. 1074.Pp 1075.Bl -tag -width Ds -compact 1076.It Sy ${ Ns Ar parameter Ns Sy } 1077The shell reads all the characters from 1078.Sy ${ 1079to the matching 1080.Sy } 1081as part of the same word even if it contains braces or metacharacters. 1082The value, if any, of the parameter is substituted. 1083The braces are required when 1084.Ar parameter 1085is followed by a letter, digit, or underscore that is not to be interpreted as 1086part of its name or when the variable name contains a dot 1087.Pq Sy \&. . 1088The braces are also required when a variable is subscripted unless it is part 1089of an Arithmetic Expression or a Conditional Expression. 1090If 1091.Ar parameter 1092is one or more digits then it is a positional parameter. 1093A positional parameter of more than one digit must be enclosed in braces. 1094If 1095.Ar parameter 1096is 1097.Sy \&* 1098or 1099.Sy \&@ , 1100then all the positional parameters, starting with 1101.Sy $1 , 1102are substituted and separated by a field separator character. 1103If an array 1104.Ar vname 1105with last subscript 1106.Sy \&* 1107or 1108.Sy \&@ 1109is used, or for index arrays of the form 1110.Ar sub1 Ns Sy \&.. Ns Ar sub2 1111is used, then the value for each of the elements between 1112.Ar sub1 1113and 1114.Ar sub2 1115inclusive 1116.Pq or all elements for Sy \&* and Sy \&@ 1117is substituted, separated by the first character of the value of 1118.Ev IFS . 1119.Pp 1120.It Sy ${# Ns Ar parameter Ns Sy } 1121If 1122.Ar parameter 1123is 1124.Sy \&* 1125or 1126.Sy \&@ , 1127the number of positional parameters is substituted. 1128Otherwise, the length of the value of the 1129.Ar parameter 1130is substituted. 1131.Pp 1132.It Sy ${# Ns Ar vname Ns Sy [*]} 1133.It Sy ${# Ns Ar vname Ns Sy [@]} 1134The number of elements in the array 1135.Ar vname 1136is substituted. 1137.Pp 1138.It Sy ${@ Ns Ar vname Ns Sy } 1139Expands to the type name or attributes of the variable referred to by 1140.Ar vname . 1141See 1142.Sx Type Variables . 1143.Pp 1144.It Sy \&$\&{\&! Ns Ar vname Ns Sy } 1145Expands to the name of the variable referred to by 1146.Ar vname . 1147This is 1148.Ar vname 1149except when 1150.Ar vname 1151is a name reference. 1152.Pp 1153.It Sy \&$\&{\&! Ns Ar vname Ns Oo Ar subscript Oc Ns Sy } 1154Expands to name of the subscript unless 1155.Ar subscript 1156is 1157.Sy \&* 1158or 1159.Sy \&@ , 1160or of the form 1161.Ar sub1 Ns Sy \&.. Ns Ar sub2 . 1162When 1163.Ar subscript 1164is 1165.Sy \&* , 1166the list of array subscripts for 1167.Ar vname 1168is generated. 1169For a variable that is not an array, the value is 1170.Sy 0 1171if the variable is set, otherwise it is 1172.Sy null . 1173When 1174.Ar subscript 1175is 1176.Sy \&@ , 1177it is the same as 1178.Sy ${ Ar vname Ns Oo * Oc Ns Sy } , 1179except that when used in double quotes, each array subscript yields a separate 1180argument. 1181When subscript is of the form 1182.Ar sub1 Ns Sy \&.. Ns Ar sub2 1183it expands to the list of subscripts between 1184.Ar sub1 1185and 1186.Ar sub2 1187inclusive using the same quoting rules as 1188.Sy @ . 1189.Pp 1190.It Sy \&$\&{\&! Ns Ar prefix Ns Sy *} 1191Expands to the names of the variables whose names begin with 1192.Ar prefix . 1193.Pp 1194.It Sy ${ Ns Ar parameter Ns Sy \&:- Ns Ar word Ns Sy } 1195If 1196.Ar parameter 1197is set and is non-null then substitute its value. 1198Otherwise substitute 1199.Ar word . 1200.Pp 1201.It Sy ${ Ns Ar parameter Ns Sy \&:= Ns Ar word Ns Sy } 1202If 1203.Ar parameter 1204is not set or is 1205.Sy null , 1206set it to 1207.Ar word . 1208The value of the parameter is then substituted. 1209Positional parameters cannot be assigned to in this way. 1210.Pp 1211.It Sy ${ Ns Ar parameter Ns Sy \&:\&? Ns Ar word Ns Sy } 1212If 1213.Ar parameter 1214is set and is non-null, substitute its value. 1215Otherwise, print 1216.Ar word 1217and exit from the shell, if the shell is not interactive. 1218If 1219.Ar word 1220is omitted then a standard message is printed. 1221.Pp 1222.It Sy ${ Ns Ar parameter Ns Sy \&:+ Ns Ar word Ns Sy } 1223If 1224.Ar parameter 1225is set and is non-null, substitute 1226.Ar word . 1227Otherwise substitute nothing. 1228.El 1229.Pp 1230In the above, 1231.Ar word 1232is not evaluated unless it is to be used as the substituted string. 1233In the following example, 1234.Ic pwd 1235is executed only if 1236.Sy d 1237is not set or is 1238.Dv NULL : 1239.Bd -literal -offset Ds 1240print ${d:-$(pwd)} 1241.Ed 1242.Pp 1243If the colon 1244.Pq Sy \&: 1245is omitted from the expression, the shell only checks whether 1246.Ar parameter 1247is set or not. 1248.Pp 1249.Bl -tag -width Ds -compact 1250.Sm off 1251.It Sy ${ Ns Ar parameter Sy \&: Ar offset Sy \&: Ar length Sy } 1252.It Sy ${ Ns Ar parameter Sy \&: Ar offset Sy } 1253.Sm on 1254Expands to the portion of the value of 1255.Ar parameter 1256starting at the 1257character 1258.Pq counting from 0 1259determined by expanding 1260.Ar offset 1261as an arithmetic expression and consisting of the number of characters 1262determined by the arithmetic expression defined by 1263.Ar length . 1264.Pp 1265In the second form, the remainder of the value is used. 1266A negative offset counts backwards from the end of 1267.Ar parameter . 1268.Pp 1269One or more BLANKs is required in front of a minus sign to prevent the shell 1270from interpreting the operator as 1271.Sy \&:- . 1272If parameter is 1273.Sy \&* 1274or 1275.Sy \&@ , 1276or is an array name indexed by 1277.Sy \&* 1278or 1279.Sy \&@ , 1280then 1281.Ar offset 1282and 1283.Ar length 1284refer to the array index and number of elements respectively. 1285A negative 1286.Ar offset 1287is taken relative to one greater than the highest subscript for indexed arrays. 1288The order for associative arrays is unspecified. 1289.Pp 1290.Sm off 1291.It Sy ${ Ns Ar parameter Sy # Ar pattern Sy } 1292.It Sy ${ Ns Ar parameter Sy ## Ar pattern Sy } 1293.Sm on 1294If the shell 1295.Ar pattern 1296matches the beginning of the value of 1297.Ar parameter , 1298then the value of this expansion is the value of the 1299.Ar parameter 1300with the matched portion deleted. 1301Otherwise the value of this 1302.Ar parameter 1303is substituted. 1304In the first form the smallest matching 1305.Ar pattern 1306is deleted and in the second form the largest matching 1307.Ar pattern 1308is deleted. 1309When 1310.Ar parameter 1311is 1312.Sy \&@ , 1313.Sy \&* , 1314or an array variable with subscript 1315.Sy \&@ 1316or 1317.Sy \&* , 1318the substring operation is applied to each element in turn. 1319.Pp 1320.Sm off 1321.It Sy ${ Ns Ar parameter Sy % Ar pattern Sy } 1322.It Sy ${ Ns Ar parameter Sy %% Ar pattern Sy } 1323.Sm on 1324If the shell 1325.Ar pattern 1326matches the end of the value of 1327.Ar parameter , 1328then the value of this expansion is the value of the parameter with the matched 1329part deleted. 1330Otherwise substitute the value of 1331.Ar parameter . 1332In the first form the smallest matching pattern is deleted, and in the second 1333form the largest matching pattern is deleted. 1334When parameter is 1335.Sy \&@ , 1336.Sy \&* , 1337or an array variable with subscript 1338.Sy \&@ 1339or 1340.Sy \&* , 1341the substring operation is applied to each element in turn. 1342.Pp 1343.Sm off 1344.It Sy ${ Ns Ar parameter Sy / Ar pattern Sy / Ar string Sy } 1345.It Sy ${ Ns Ar parameter Sy // Ar pattern Sy / Ar string Sy } 1346.It Sy ${ Ns Ar parameter Sy /# Ar pattern Sy / Ar string Sy } 1347.It Sy ${ Ns Ar parameter Sy /% Ar pattern Sy / Ar string Sy } 1348.Sm on 1349Expands 1350.Ar parameter 1351and replaces the longest match of 1352.Ar pattern 1353with the specified 1354.Ar string . 1355Each occurrence of 1356.Sy \e Ns Ar n 1357in 1358.Ar string 1359is replaced by the portion of 1360.Ar parameter 1361that matches the 1362.Ar n Ns No th 1363sub-pattern. 1364.Pp 1365When 1366.Ar string 1367is null, the 1368.Ar pattern 1369is deleted and the 1370.Sy / 1371in front of string can be omitted. 1372When 1373.Ar parameter 1374is 1375.Sy \&@ , 1376.Sy \&* , 1377or an 1378array variable with subscript 1379.Sy \&@ 1380or 1381.Sy \&* , 1382the substitution operation is applied to each element in turn. 1383In this case, the 1384.Ar string 1385portion of 1386.Ar word 1387is re-evaluated for each element. 1388.Pp 1389In the first form, only the first occurrence of 1390.Ar pattern 1391is replaced. 1392.Pp 1393In the second form, each match for 1394.Ar pattern 1395is replaced by the specified 1396.Ar string . 1397.Pp 1398The third form restricts the pattern match to the beginning of the 1399.Ar string . 1400.Pp 1401The fourth form restricts the pattern match to the end of the 1402.Ar string . 1403.El 1404.Pp 1405The following parameters are automatically set by the shell: 1406.Bl -tag -width Ds 1407.It Sy # 1408The number of positional parameters in decimal. 1409.It Sy - 1410Options supplied to the shell on invocation or by the 1411.Ic set 1412command. 1413.It Sy \&? 1414The decimal value returned by the last executed command. 1415.It Sy $ 1416The process number of this shell. 1417.It Sy _ 1418Initially, the value of 1419.Sy _ 1420is the absolute pathname of the shell or script being executed as passed in the 1421environment. 1422It is subsequently assigned the last argument of the previous command. 1423.Pp 1424This parameter is not set for commands which are asynchronous. 1425This parameter is also used to hold the name of the matching 1426.Ev MAIL 1427file when checking for mail. 1428.It Sy \&! 1429The process id or the pool name and job number of the last background command 1430invoked or the most recent job put in the background with the 1431.Ic bg 1432built-in command. 1433Background jobs started in a named pool with be in the form 1434.Ar pool Ns \&. Ns Ar number 1435where 1436.Ar pool 1437is the pool name and 1438.Ar number 1439is the job number within that pool. 1440.It Sy \&.sh.command 1441When processing a 1442.Dv DEBUG 1443trap, this variable contains the current command line that is about to run. 1444.It Sy \&.sh.edchar 1445This variable contains the value of the keyboard character (or sequence of 1446characters if the first character is an ESC, 1447.Pq ASCII 033 1448that has been entered when processing a 1449.Dv KEYBD 1450trap. 1451If the value is changed as part of the trap action, then the new value replaces 1452the key (or key sequence) that caused the trap. 1453See the 1454.Sx Key Bindings 1455section of this manual page. 1456.It Sy \&.sh.edcol 1457The character position of the cursor at the time of the most recent 1458.Dv KEYBD 1459trap. 1460.It Sy \&.sh.edmode 1461The value is set to ESC when processing a 1462.Dv KEYBD 1463trap while in 1464.Sy vi 1465insert mode. 1466Otherwise, 1467.Sy \&.sh.edmode 1468is null when processing a 1469.Dv KEYBD 1470trap. 1471See the 1472.Sx vi Editing Mode 1473section of this manual page. 1474.It Sy \&.sh.edtext 1475The characters in the input buffer at the time of the most recent 1476.Dv KEYBD 1477trap. 1478The value is null when not processing a 1479.Dv KEYBD 1480trap. 1481.It Sy \&.sh.file 1482The pathname of the file than contains the current command. 1483.It Sy \&.sh.fun 1484The name of the current function that is being executed. 1485.It Sy \&.sh.match 1486An indexed array which stores the most recent match and sub-pattern matches 1487after conditional pattern matches that match and after variables expansions 1488using the operators 1489.Sy \&# , 1490.Sy \&% , or 1491.Sy \&/ . 1492The 1493.Sy 0 Ns No th 1494element stores the complete match and the 1495.Ar i Ns No th 1496element stores the 1497.Ar i Ns No th 1498sub-match. 1499The 1500.Sy \&.sh.match 1501variable is unset when the variable that has expanded is assigned a new value. 1502.It Sy \&.sh.math 1503Used for defining arithmetic functions 1504.Pq see Sx Arithmetic evaluation 1505and stores the list of user-defined arithmetic functions. 1506.It Sy \&.sh.name 1507Set to the name of the variable at the time that a discipline function is 1508invoked. 1509.It Sy \&.sh.subscript 1510Set to the name subscript of the variable at the time that a discipline 1511function is invoked. 1512.It Sy \&.sh.subshell 1513The current depth for sub-shells and command substitution. 1514.It Sy \&.sh.value 1515Set to the value of the variable at the time that the set or append discipline 1516function is invoked. 1517When a user-defined arithmetic function is invoked, the value of 1518.Sy .sh.value 1519is saved and 1520.Sy .sh.value 1521is set to long double precision floating point. 1522.Sy .sh.value 1523is restored when the function returns. 1524.It Sy \&.sh.version 1525Set to a value that identifies the version of this shell. 1526.It Sy LINENO 1527The current line number within the script or function being executed. 1528.It Sy OLDPWD 1529The previous working directory set by the 1530.Ic cd 1531command. 1532.It Sy OPTARG 1533The value of the last option argument processed by the 1534.Ic getopts 1535built-in command. 1536.It Sy OPTIND 1537The index of the last option argument processed by the 1538.Ic getopts 1539built-in command. 1540.It Sy PPID 1541The process number of the parent of the shell. 1542.It Sy PWD 1543The present working directory set by the 1544.Ic cd 1545command. 1546.It Sy RANDOM 1547Each time this variable is referenced, a random integer, uniformly distributed 1548between 1549.Sy 0 1550and 1551.Sy 32767 , 1552is generated. 1553The sequence of random numbers can be initialized by assigning a numeric value 1554to 1555.Ev RANDOM . 1556.It Sy REPLY 1557This variable is set by the 1558.Ic select 1559statement and by the 1560.Ic read 1561built-in command when no arguments are supplied. 1562.It Sy SECONDS 1563Each time this variable is referenced, the number of seconds since shell 1564invocation is returned. 1565If this variable is assigned a value, then the value returned upon reference is 1566the value that was assigned plus the number of seconds since the assignment. 1567.It Sy SHLVL 1568An integer variable the is incremented each time the shell is invoked and is 1569exported. 1570If 1571.Ev SHLVL 1572is not in the environment when the shell is invoked, it is set to 1. 1573.El 1574.Pp 1575The following variables are used by the shell: 1576.Bl -tag -width Ds 1577.It Sy CDPATH 1578Defines the search path for the 1579.Ic cd 1580command. 1581.It Sy COLUMNS 1582Defines the width of the edit window for the shell edit modes and for printing 1583select lists. 1584.It Sy EDITOR 1585If the 1586.Ev VISUAL 1587variable is not set, the value of this variable is checked for the patterns as 1588described with 1589.Ev VISUAL 1590and the corresponding editing option is turned on. 1591.Pp 1592See the 1593.Ic set 1594command in the 1595.Sx Special Commands 1596section of this manual page. 1597.It Sy ENV 1598Performs parameter expansion, command substitution, and arithmetic substitution 1599on the value to generate the pathname of the script that is executed when the 1600shell is invoked. 1601This file is typically used for alias and function definitions. 1602The default value is 1603.Sy $HOME/.kshrc . 1604.Pp 1605See the 1606.Sx Invocation 1607section of this manual page. 1608.Pp 1609.Ev ENV 1610is not set by the shell. 1611.It Sy FCEDIT 1612Obsolete name for the default editor name for the 1613.Ic hist 1614command. 1615.Ev FCEDIT 1616is not used when 1617.Ev HISTEDIT 1618is set. 1619.Pp 1620The shell specifies a default value to 1621.Ev FCEDIT . 1622.It Sy FIGNORE 1623A pattern that defines the set of file names that is ignored when performing 1624file name matching. 1625.It Sy FPATH 1626The search path for function definitions. 1627The directories in this path are searched for a file with the same name as the 1628function or command when a function with the 1629.Fl u 1630attribute is referenced and when a command is not found. 1631If an executable file with the name of that command is found, then it is read 1632and executed in the current environment. 1633Unlike 1634.Ev PATH , 1635the current directory must be represented explicitly by dot 1636.Pq Sy \&. 1637rather than by adjacent colon 1638.Pq Sy \&: 1639characters or a beginning or ending colon 1640.Pq Sy \&: . 1641.It Sy HISTCMD 1642The number of the current command in the history file. 1643.It Sy HISTEDIT 1644The name for the default editor name for the 1645.Ic hist 1646command. 1647.It Sy HISTFILE 1648If this variable is set when the shell is invoked, the value is the pathname of 1649the file that is used to store the command history. 1650See the 1651.Sx Command Re-entry 1652section of this manual page. 1653.It Sy HISTSIZE 1654If this variable is set when the shell is invoked, then the number of 1655previously entered commands that are accessible by this shell is greater than 1656or equal to this number. 1657The default is 1658.Sy 512 . 1659.It Sy HOME 1660The default argument (home directory) for the 1661.Ic cd 1662command. 1663.Pp 1664.Ev HOME 1665is not set by the shell. 1666.Ev HOME 1667is set by 1668.Xr login 1 . 1669.It Sy IFS 1670Internal field separators, normally SPACE, TAB, and NEWLINE that are used to 1671separate the results of command substitution or parameter expansion and to 1672separate fields with the built-in command read. 1673The first character of the 1674.Ev IFS 1675variable is used to separate arguments for the 1676.Dq Sy \&$* 1677substitution. 1678See the 1679.Sx Quoting 1680section of this manual page. 1681.Pp 1682Each single occurrence of an 1683.Ev IFS 1684character in the string to be split, that is not in the 1685.Sy issspace 1686character class, and any adjacent characters in 1687.Ev IFS 1688that are in the 1689.Sy issspace 1690character class, delimit a field. 1691One or more characters in 1692.Ev IFS 1693that belong to the 1694.Sy issspace 1695character class, delimit a field. 1696In addition, if the same 1697.Sy issspace 1698character appears consecutively inside 1699.Ev IFS , 1700this character is treated as if it were not in the 1701.Sy issspace 1702class, so that if 1703.Ev IFS 1704consists of two tab characters, then two adjacent tab characters delimit a null 1705field. 1706.Pp 1707The shell specifies a default value to 1708.Ev IFS . 1709.It Sy JOBMAX 1710This variable defines the maximum number running background jobs that can run 1711at a time. 1712When this limit is reached, the shell will wait for a job to complete before 1713starting a new job. 1714.It Sy LANG 1715This variable determines the locale category for any category not specifically 1716selected with a variable starting with 1717.Ev LC_ 1718or 1719.Ev LANG . 1720.It Sy LC_ALL 1721This variable overrides the value of the 1722.Ev LANG 1723variable and any other 1724.Ev LC_ 1725variable. 1726.It Sy LC_COLLATE 1727This variable determines the locale category for character collation 1728information. 1729.It Sy LC_CTYPE 1730This variable determines the locale category for character handling functions. 1731It determines the character classes for pattern matching. 1732See the 1733.Sx File Name Generation 1734section of this manual page. 1735.It Sy LC_NUMERIC 1736This variable determines the locale category for the decimal point character. 1737.It Sy LINES 1738If this variable is set, the value is used to determine the column length for 1739printing select lists. 1740Select lists prints vertically until about two-thirds of 1741.Ev LINES 1742lines are filled. 1743.It Sy MAIL 1744If this variable is set to the name of a mail file 1745.Em and 1746the 1747.Ev MAILPATH 1748variable is not set, then the shell informs the user of arrival of mail in the 1749specified file. 1750.Pp 1751.Ev MAIL 1752is not set by the shell. 1753On some systems, 1754.Ev MAIL 1755is set by 1756.Xr login 1 . 1757.It Sy MAILCHECK 1758Specifies how often in seconds the shell checks for changes in the modification 1759time of any of the files specified by the 1760.Ev MAILPATH 1761or 1762.Ev MAIL 1763variables. 1764The default value is 1765.Sy 600 1766seconds. 1767When the time has elapsed the shell checks before issuing the next prompt. 1768.Pp 1769The shell specifies a default value to 1770.Ev MAILCHECK . 1771.It Sy MAILPATH 1772A colon 1773.Pq Sy \&: 1774separated list of file names. 1775If this variable is set, then the shell informs the user of any modifications 1776to the specified files that have occurred within the last 1777.Ev MAILCHECK 1778seconds. 1779Each file name can be followed by a 1780.Sy \&? 1781and a message that is printed. 1782The message undergoes parameter expansion, command substitution, and arithmetic 1783substitution with the variable 1784.Sy $_ 1785defined as the name of the file that has changed. 1786The default message is 1787.Ql you have mail in $_ . 1788.It Sy PATH 1789The search path for commands. 1790Except in 1791.Pa .profile , 1792users cannot change 1793.Ev PATH 1794if executing under 1795.Nm rksh93 . 1796See the 1797.Sx Execution section 1798of this manual page. 1799.Pp 1800The shell specifies a default value to 1801.Ev PATH . 1802.It Sy PS1 1803The value of this variable is expanded for parameter expansion, command 1804substitution, and arithmetic substitution to define the primary prompt string 1805which by default is 1806.Sy $ . 1807The character 1808.Sy \&! 1809in the primary prompt string is replaced by the command number. 1810Two successive occurrences of 1811.Sy \&! 1812produces a single 1813.Sy \&! 1814when the prompt string is printed. 1815See the 1816.Sx Command Re-entry 1817section of this manual page. 1818.Pp 1819The shell specifies a default value to 1820.Ev PS1 . 1821.It Sy PS2 1822Secondary prompt string, by default, 1823.Sy \&> . 1824.Pp 1825The shell specifies a default value to 1826.Ev PS2 . 1827.It Sy PS3 1828Selection prompt string used within a select loop, by default 1829.Sy \&\&#\&? . 1830.Pp 1831The shell specifies a default value to 1832.Ev PS3 . 1833.It Sy PS4 1834The value of this variable is expanded for parameter evaluation, command 1835substitution, and arithmetic substitution and precedes each line of an 1836execution trace. 1837By default, 1838.Ev PS4 1839is 1840.Sy \&+ . 1841When 1842.Ev PS4 1843is unset, the execution trace prompt is also 1844.Sy \&+ . 1845.Pp 1846The shell specifies a default value to 1847.Ev PS4 . 1848.It Sy SHELL 1849The pathname of the shell is kept in the environment. 1850At invocation, if the basename of this variable is 1851.Sy rsh , 1852.Sy rksh , 1853.Sy rksh93 , 1854or 1855.Sy krsh , 1856the shell becomes restricted. 1857.Pp 1858.Ev SHELL 1859is not set by the shell. 1860On some systems, 1861.Ev SHELL 1862is set by 1863.Xr login 1 . 1864.It Sy TIMEFORMAT 1865The value of this parameter is used as a format string specifying how the 1866timing information for pipelines prefixed with the 1867.Ic time 1868reserved word should be displayed. 1869The 1870.Sy \&% 1871character introduces a format sequence that is expanded to a time value or 1872other information. 1873.Pp 1874The format sequences and their meanings are as follows. 1875.Bl -tag -width Ar 1876.It Sy %% 1877A literal 1878.Sy % . 1879.Sm off 1880.It Sy % Oo Ar p Oc Oo Cm l Oc Cm R 1881The elapsed time in seconds. 1882.It Sy % Oo Ar p Oc Oo Cm l Oc Cm U 1883The number of CPU seconds spent in user mode. 1884.It Sy % Oo Ar p Oc Oo Cm l Oc Cm S 1885The number of CPU seconds spent in system mode. 1886.It Sy % Ns Cm P 1887The CPU percentage, computed as 1888.Sy (U + S) / R . 1889.Sm on 1890.El 1891.Pp 1892The braces denote optional portions. 1893The optional 1894.Ar p 1895is a digit specifying 1896the 1897.Ar precision , 1898the number of fractional digits after a decimal point. 1899A value of 1900.Sy 0 1901causes no decimal point or fraction to be output. 1902At most three places after the decimal point can be displayed. 1903Values of 1904.Ar p 1905greater than 1906.Sy 3 1907are treated as 1908.Sy 3 . 1909If 1910.Ar p 1911is not specified, the value 1912.Sy 3 1913is used. 1914.Pp 1915The optional 1916.Cm l 1917specifies a longer format, including hours if greater than zero, minutes, and 1918seconds of the form 1919.Em HHhMMmSS.FFs . 1920The value of 1921.Ar p 1922determines whether or not the fraction is included. 1923.Pp 1924All other characters are output without change and a trailing NEWLINE is added. 1925If unset, the default value: 1926.Pp 1927.Dl $'\enreal\et%2lR\enuser\et%2lU\ensys%2lS' 1928.Pp 1929is used. 1930If the value is null, no timing information is displayed. 1931.It Sy TMOUT 1932If set to a value greater than zero, 1933.Ev TMOUT 1934is the default time-out value for the 1935.Ic read 1936built-in command. 1937The 1938.Ic select 1939compound command terminates after 1940.Ev TMOUT 1941seconds when input is from a terminal. 1942Otherwise, the shell terminates if a line is not entered within the prescribed 1943number of seconds while reading from a terminal. 1944The shell can be compiled with a maximum bound for this value which cannot be 1945exceeded. 1946.Pp 1947The shell specifies a default value to 1948.Ev TMOUT . 1949.It Sy VISUAL 1950If the value of this variable matches the pattern 1951.Sy *[Vv][Ii]* , 1952then the 1953.Sy vi 1954option is turned on. 1955See 1956.Sx Special Commands . 1957If the value matches the pattern 1958.Sy *gmacs* , 1959the 1960.Sy gmacs 1961option is turned on. 1962If the value matches the pattern 1963.Sy *macs* , 1964then the 1965.Sy emacs 1966option is turned on. 1967The value of 1968.Ev VISUAL 1969overrides the value of 1970.Ev EDITOR . 1971.El 1972.Ss "Field Splitting" 1973After parameter expansion and command substitution, the results of 1974substitutions are scanned for the field separator characters 1975.Pq those found in Ev IFS 1976and split into distinct fields where such characters are found. 1977Explicit null fields 1978.Pq Sy "" or Sy \&'' 1979are retained. 1980Implicit null fields, those resulting from parameters that have no values or 1981command substitutions with no output, are removed. 1982.Pp 1983If the 1984.Sy braceexpand 1985.Pq Fl B 1986option is set, each of the fields resulting from 1987.Ev IFS 1988are checked to see if they contain one or more of the brace patterns. 1989Valid brace patterns are: 1990.Pp 1991.Bl -item -offset Ds -compact 1992.Sm off 1993.It 1994.Brq Sy \&*,* Ns Oo Sy ,* Oc Ns No ... 1995.It 1996.Brq Ar l1 Sy \&.. Ar l2 1997.It 1998.Brq Ar n1 Sy \&.. Ar n2 1999.It 2000.Brq Ar n1 Sy \&.. Ar n2 Sy % Ar fmt 2001.It 2002.Brq Ar n1 Sy \&.. Ar n2 Sy \&.. Ar n3 2003.It 2004.Brq Ar n1 Sy \&.. Ar n2 Sy \&.. Ar n3 Sy % Ar fmt 2005.Sm on 2006.El 2007.Pp 2008where 2009.Sy * 2010represents any character, 2011.Ar l1 , 2012.Ar l2 2013are letters and 2014.Ar n1 , 2015.Ar n2 , 2016.Ar n3 2017are signed numbers and 2018.Ar fmt 2019is a format specified as used by 2020.Ic printf . 2021In each case, fields are created by prepending the characters before the 2022.Sy { 2023and appending the characters after 2024the 2025.Sy } 2026to each of the strings generated by the characters between the 2027.Sy { 2028and 2029.Sy } . 2030The resulting fields are checked to see if they have any brace patterns. 2031.Pp 2032In the first form, a field is created for each string between 2033.Sy { 2034and the first comma 2035.Pq Sq \&, , 2036between a pair of commas 2037.Pq Sq \&, 2038and between 2039the last comma 2040.Pq Sq \&, 2041and the terminating 2042.Sy } . 2043The string 2044represented by 2045.Sy * 2046can contain embedded matching { and } without quoting. 2047Otherwise, each 2048.Sy { 2049and 2050.Sy } 2051within 2052.Sy * 2053must be quoted. 2054.Pp 2055In the second form, 2056.Ar l1 2057and 2058.Ar l2 2059must both be either upper case or both be lower case characters in the C 2060locale. 2061In this case a field is created for each character from 2062.Ar l1 2063to 2064.Ar l2 2065inclusive. 2066.Pp 2067In the remaining forms, a field is created for each number starting at 2068.Ar n1 . 2069This continues until it reaches 2070.Ar n2 2071and increments 2072.Ar n1 2073by 2074.Ar n3 . 2075The cases where 2076.Ar n3 2077is not specified behave as if 2078.Ar n3 2079were 1 if 2080.Ar n1 2081<= 2082.Ar n2 , 2083and -1 otherwise. 2084.Pp 2085In forms which specify 2086.Sy % Ns Ar fmt , 2087any format flags, widths and precisions can be specified and 2088.Ar fmt 2089can end in any of the specifiers 2090.Sy cdiouxX . 2091For example, 2092.Sy {a,z}{1..5..3%02d}{b..c}x 2093expands to the 8 fields, 2094.Sy a01bx , 2095.Sy a01cx , 2096.Sy a04bx , 2097.Sy a04cx , 2098.Sy z01bx , 2099.Sy z01cx , 2100.Sy z04bx , 2101and 2102.Sy z04cx . 2103.Ss "File Name Generation" 2104Following splitting, each field is scanned for the characters 2105.Sy \&* , 2106.Sy \&? , 2107.Sy \&( , 2108and 2109.Sy \&[ , 2110unless the 2111.Fl f 2112option has been set. 2113If one of these characters appears, then the word is regarded as a pattern. 2114.Pp 2115Each file name component that contains any pattern character is replaced with a 2116lexicographically sorted set of names that matches the pattern from that 2117directory. 2118If no file name is found that matches the pattern, then that component of the 2119file name is left unchanged unless the pattern is prefixed with 2120.Sy ~(N) 2121in which case it is removed. 2122If 2123.Ev FIGNORE 2124is set, then each file name component that matches the pattern defined by the 2125value of 2126.Ev FIGNORE 2127is ignored when generating the matching file names. 2128The names 2129.Sy \&. 2130and 2131.Sy \&.. 2132are also ignored. 2133If 2134.Ev FIGNORE 2135is not set, the character 2136.Sy \&. 2137at the start of each file name component is ignored unless the first character 2138of the pattern corresponding to this component is the character 2139.Sy \&. 2140itself. 2141For other uses of pattern matching the 2142.Sy / 2143and 2144.Sy \&. 2145are not specially treated. 2146.Bl -tag -width Ds 2147.It Sy * 2148Match any string, including the null string. 2149When used for file name expansion, if the 2150.Sy globstar 2151option is on, two adjacent 2152.Sy * Ns No s 2153by themselves match all files and zero or more directories and subdirectories. 2154If the two adjacent 2155.Sy * Ns No s 2156are followed by a 2157.Sy / , 2158only directories and subdirectories match. 2159.It Sy \&? 2160Matches any single character. 2161.It Sy [...] 2162Match any one of the enclosed characters. 2163A pair of characters separated by 2164.Sy - 2165matches any character lexically between the pair, inclusive. 2166If the first character following the opening 2167.Sy \&[ 2168is a 2169.Sy \&! 2170or 2171.Sy ^ , 2172any character not enclosed is matched. 2173A 2174.Sy - 2175can be included in the character set by putting it as the first or last 2176character. 2177Within 2178.Sy \&[ 2179and 2180.Sy \&] , 2181character classes can be specified with the syntax 2182.Sy [: Ns Ar class Ns Sy \&:\&] 2183where 2184.Ar class 2185is one of the following classes defined in the 2186.Sy ANSI-C 2187standard: 2188.Bl -column -offset indent xxxxxx xxxxxx xxxxxx xxxxxx xxxxxx xxxxxx 2189.It alnum Ta alpha Ta blank Ta cntrl Ta digit Ta graph 2190.It lower Ta print Ta punct Ta space Ta upper Ta word 2191.It xdigit Ta Ta Ta Ta Ta 2192.El 2193.Pp 2194.Ar word 2195is equivalent to 2196.Ar alnum 2197plus the character 2198.Sy _ . 2199Within 2200.Sy \&[ 2201and 2202.Sy \&] , 2203an equivalence class can be specified with the syntax 2204.Sy [= Ns Ar c Ns Sy =] 2205which matches all characters with the same primary collation weight (as defined 2206by the current locale) as the character 2207.Ar c . 2208Within 2209.Sy \&[ 2210and 2211.Sy \&] , 2212.Sm off 2213.Sy \&[ \&. Ar symbol Ns \&. Sy \&] 2214.Sm on 2215matches the collating symbol 2216.Ar symbol . 2217.El 2218.Pp 2219A 2220.Sy pattern-list 2221is a list of one or more patterns separated from each other with an 2222.Sy \&& 2223or 2224.Sy \&| . 2225An 2226.Sy \&& 2227signifies that all patterns must be matched whereas 2228.Sy \&| 2229requires that only one pattern be matched. 2230Composite patterns can be formed with one or more of the following 2231sub-patterns: 2232.Bl -tag -width xxxxxxxxxxxxxxxxxxxxx 2233.Sm off 2234.It Sy \&?( Ar pattern-list Sy \&) 2235Optionally matches any one of the specified patterns. 2236.It Sy \&*( Ar pattern-list Sy \&) 2237Matches zero or more occurrences of the specified patterns. 2238.It Sy \&+( Ar pattern-list Sy \&) 2239Matches one or more occurrences of the specified patterns. 2240.It Sy \&{ Ar n Sy \&} Sy \&( Ar pattern-list Sy \&) 2241.Sm on 2242Matches 2243.Ar n 2244occurrences of the specified patterns. 2245.Sm off 2246.It Sy \&{ Ar m Sy \&, Ar n Sy \&} Sy \&( Ar pattern-list Sy \&) 2247.Sm on 2248Matches from 2249.Ar m 2250to 2251.Ar n 2252occurrences of the specified patterns. 2253If 2254.Ar m 2255is omitted, 2256.Sy 0 2257is used. 2258If 2259.Ar n 2260is omitted at least 2261.Ar m 2262occurrences are matched. 2263.Sm off 2264.It Sy \&@( Ar pattern-list Sy \&) 2265Matches exactly one of the specified patterns. 2266.It Sy \&!( Ar pattern-list Sy \&) 2267Matches anything except one of the specified patterns. 2268.Sm on 2269.El 2270.Pp 2271By default, each pattern, or sub-pattern matches the longest string possible 2272consistent with generating the longest overall match. 2273If more than one match is possible, the one starting closest to the beginning 2274of the string is chosen. 2275However, for each of the compound patterns a 2276.Sy - 2277can be inserted in front 2278of the 2279.Sy \&( 2280to cause the shortest match to the specified 2281.Ar pattern-list 2282to be used. 2283.Pp 2284When 2285.Sy pattern-list 2286is contained within parentheses, the backslash 2287character 2288.Pq Sy \e 2289is treated specially even when inside a character class. 2290All 2291.Sy ANSI-C 2292character escapes are recognized and match the specified character. 2293In addition the following escape sequences are recognized: 2294.Bl -tag -width Ds 2295.It Sy \ed 2296Matches any character in the digit class. 2297.It Sy \eD 2298Matches any character not in the digit class. 2299.It Sy \es 2300Matches any character in the space class. 2301.It Sy \eS 2302Matches any character not in the space class. 2303.It Sy \ew 2304Matches any character in the word class. 2305.It Sy \eW 2306Matches any character not in the word class. 2307.El 2308.Pp 2309A pattern of the form 2310.Sy %( Ns Ar pattern-pairs Ns Sy \&) 2311is a sub-pattern that can be used to match nested character expressions. 2312Each 2313.Ar pattern-pair 2314is a two character sequence which cannot contain 2315.Sy \&& 2316or 2317.Sy \&| . 2318The first 2319.Ar pattern-pair 2320specifies the starting and ending characters for the match. 2321Each subsequent 2322.Ar pattern-pair 2323represents the beginning and ending characters of a nested group that is 2324skipped over when counting starting and ending character matches. 2325The behavior is unspecified when the first character of a 2326.Ar pattern-pair 2327is alphanumeric except for the following: 2328.Bl -tag -width Ds 2329.It Sy D 2330Causes the ending character to terminate the search for this pattern without 2331finding a match. 2332.It Sy E 2333Causes the ending character to be interpreted as an escape character. 2334.It Sy L 2335Causes the ending character to be interpreted as a quote character causing all 2336characters to be ignored when looking for a match. 2337.It Sy Q 2338Causes the ending character to be interpreted as a quote character causing all 2339characters other than any escape character to be ignored when looking for a 2340match. 2341.El 2342.Pp 2343.Sy %({}Q"E\e) , 2344matches characters starting at 2345.Sy { 2346until the matching 2347.Sy } 2348is found not counting any 2349.Sy { 2350or 2351.Sy } 2352that is inside a double quoted string or preceded by the escape character 2353.Pq Sy \e . 2354Without the 2355.Sy {} 2356this pattern matches any C language string. 2357.Pp 2358Each sub-pattern in a composite pattern is numbered, starting at 2359.Sy 1 , 2360by the location of the 2361.Sy \&( 2362within the pattern. 2363The sequence 2364.Sy \e Ns Ar n , 2365where 2366.Ar n 2367is a single digit and 2368.Sy \e Ns Ar n , 2369comes after the 2370.Ar n Ns No th 2371sub-pattern, matches the same string as the sub-pattern itself. 2372.Pp 2373A pattern can contain sub-patterns of the form 2374.Sm off 2375.Sy ~( Ar options Sy \&: Ar pattern-list Sy \&) , 2376.Sm on 2377where either 2378.Ar options 2379or 2380.Sy \&: Ns Ar pattern-list 2381can be omitted. 2382Unlike the other compound patterns, these sub-patterns are not counted in the 2383numbered sub-patterns. 2384.Sy \&: Ns Ar pattern-list 2385must be omitted for options 2386.Sy F , 2387.Sy G , 2388.Sy N 2389and 2390.Sy V 2391below. 2392If 2393.Ar options 2394is present, it can consist of one or more of the following: 2395.Bl -tag -width Ds 2396.It Sy + 2397Enable the following options. 2398This is the default. 2399.It Sy - 2400Disable the following options. 2401.It Sy E 2402The remainder of the pattern uses extended regular expression syntax like the 2403.Xr egrep 1 2404command. 2405.It Sy F 2406The remainder of the pattern uses 2407.Xr fgrep 1 2408expression syntax. 2409.It Sy g 2410File the longest match (greedy). 2411This is the default. 2412.It Sy G 2413The remainder of the pattern uses basic regular expression syntax like the 2414.Xr grep 1 2415command. 2416.It Sy i 2417Treat the match as case insensitive. 2418.It Sy K 2419The remainder of the pattern uses shell pattern syntax. 2420This is the default. 2421.It Sy l 2422Left anchor the pattern. 2423.Pp 2424This is the default for 2425.Sy K 2426style patterns. 2427.It Sy N 2428This is ignored. 2429However, when it is the first letter and is used with file name generation, and 2430no matches occur, the file pattern expands to the empty string. 2431.It Sy r 2432Right anchor the pattern. 2433.Pp 2434This is the default for 2435.Sy K 2436style patterns. 2437.It Sy X 2438The remainder of the pattern uses augmented regular expression syntax. 2439.It Sy P 2440The remainder of the pattern uses 2441.Xr perl 1 2442regular expression syntax. 2443Not all perl regular expression syntax is currently implemented. 2444.It Sy V 2445The remainder of the pattern uses System V regular expression syntax. 2446.El 2447.Pp 2448If both 2449.Ar options 2450and 2451.Sy \&: Ns Ar pattern-list 2452are specified, then the options apply only to 2453.Ar pattern-list . 2454Otherwise, these options remain in effect until they are disabled by a 2455subsequent 2456.Sy ~(...) 2457or at the end of 2458the sub-pattern containing 2459.Sy ~(...) . 2460.Ss "Quoting" 2461Each of the metacharacters listed in the 2462.Sx Definitions 2463section of this manual page has a special meaning to the shell and causes 2464termination of a word unless quoted. 2465A character can be quoted, that is, made to stand for itself, by preceding it 2466with a backslash 2467.Pq Sy \e . 2468The pair 2469.Sy \eNEWLINE 2470is removed. 2471All characters enclosed between a pair of single quote marks 2472.Pq Sy '' 2473that is not preceded by a 2474.Sy $ 2475are quoted. 2476A single quote cannot appear within the single quotes. 2477A single quoted string preceded by an unquoted 2478.Sy $ 2479is processed as an 2480.Sy ANSI-C 2481string except for the following: 2482.Bl -tag -width Ar 2483.It Sy \e0 2484Causes the remainder of the string to be ignored. 2485.It Sy \ec Ns Ar x 2486Expands to the character 2487.No CTRL- Ns Ar x . 2488.It Sy \eC[\&. Ns Ar name Ns Sy \&.\&] 2489Expands to the collating element 2490.Ar name . 2491.It Sy \ee 2492Equivalent to the escape character 2493.Pq ASCII 033 . 2494.It Sy \eE 2495Equivalent to the escape character 2496.Pq ASCII 033 . 2497.El 2498.Pp 2499Inside double quote marks 2500.Pq Sy \&"" , 2501parameter and command substitution occur and 2502.Sy \e 2503quotes the characters 2504.Sy \e , 2505.Sy \&` , 2506.Sy \&" , 2507and 2508.Sy \&$ . 2509A 2510.Sy \&$ 2511in front of a double quoted string is ignored in the 2512.Dv C 2513or 2514.Dv POSIX 2515locale, and might cause the string to be replaced by a locale specific string 2516otherwise. 2517The meaning of 2518.Sy $* 2519and 2520.Sy $@ 2521is identical when not quoted or when used as a variable assignment value or as 2522a file name. 2523However, when used as a command argument, 2524.Sy \&"$*" 2525is equivalent to 2526.Sm off 2527.Sy \&"$1 Ar d Sy $2 Ar d No ..." , 2528.Sm on 2529where 2530.Ar d 2531is the first character of the 2532.Ev IFS 2533variable, whereas 2534.Sy \&"$@" 2535is equivalent to 2536.Sy \&"$1" \&"$2" No ... 2537Inside grave quote marks 2538.Pq Sy `` , 2539.Sy \e 2540quotes the characters 2541.Sy \e , 2542.Sy ` , 2543and 2544.Sy $ . 2545If the grave quotes occur within double quotes, then 2546.Sy \e 2547also quotes the character 2548.Sy \&" . 2549.Pp 2550The special meaning of reserved words or aliases can be removed by quoting any 2551character of the reserved word. 2552The recognition of function names or built-in command names cannot be altered 2553by quoting them. 2554.Ss "Arithmetic Evaluation" 2555The shell performs arithmetic evaluation for arithmetic substitution, to 2556evaluate an arithmetic command, to evaluate an indexed array subscript, and to 2557evaluate arguments to the built-in commands 2558.Ic shift 2559and 2560.Ic let . 2561Arithmetic evaluation is also performed on argument operands of the built-in 2562command 2563.Ic printf 2564that correspond to numeric format specifiers in the format operand. 2565See 2566.Xr printf 1 . 2567Evaluations are performed using double precision floating point arithmetic or 2568long double precision floating point for systems that provide this data type. 2569Floating point constants follow the 2570.Sy ANSI-C 2571programming language floating point conventions. 2572The floating point constants 2573.Dv Nan 2574and 2575.Dv Inf 2576can be used to represent "not a number" and infinity respectively. 2577Integer constants follow the 2578.Sy ANSI-C 2579programming language integer constant conventions although only single byte 2580character constants are recognized and character casts are not recognized. 2581Constants can be of the form 2582.Oo Ar base Ns No \&# Oc Ns Ar n 2583where 2584.Ar base 2585is a decimal number between two and sixty-four representing the arithmetic base 2586and 2587.Ar n 2588is a number in that base. 2589The digits greater than 2590.Sy 9 2591are represented by the lower case letters, the upper case letters, 2592.Sy @ , 2593and 2594.Sy _ 2595respectively. 2596For bases less than or equal to 2597.Sy 36 , 2598upper and lower case characters can be used interchangeably. 2599.Pp 2600An arithmetic expression uses the same syntax, precedence, and associativity of 2601expression as the C language. 2602All the C language operators that apply to floating point quantities can be 2603used. 2604In addition, the operator 2605.Sy ** 2606can be used for exponentiation. 2607It has higher precedence than multiplication and is left associative. 2608When the value of an arithmetic variable or subexpression can be represented as 2609a long integer, all C language integer arithmetic operations can be performed. 2610Variables can be referenced by name within an arithmetic expression without 2611using the parameter expansion syntax. 2612When a variable is referenced, its value is evaluated as an arithmetic 2613expression. 2614.Pp 2615Any of the following math library functions that are in the C math library can 2616be used within an arithmetic expression: 2617.Pp 2618.Bl -inset -offset Ds -compact 2619.It rint round sin sinh sqrt tan tanh tgamma trunc abs 2620.It acos acosh asin asinh atan atan2 atanh cbrt ceil copysign 2621.It cos cosh erf erfc exp exp2 expm1 fabs fpclassify fdim 2622.It finite floor fma fmax fmin fmod hypot ilogb int isfinite 2623.It sinf isnan isnormal issubnormal issubordered iszero j0 2624.It j1 jn lgamma log log10 log2 logb nearbyint nextafter 2625.It nexttoward pow remainder rint round scanb signbit sin sinh 2626.It sqrt tan tanh tgamma trunc y0 y1 yn 2627.El 2628.Pp 2629In addition, arithmetic functions can be defined as shell functions with a 2630variant of the 2631.Ic function Ar name 2632syntax: 2633.Bd -ragged -offset Ds 2634.Sy function .sh.math\&. Ns Ar name Ar ident Sy { Ar list Sy ;} 2635.Ed 2636.Pp 2637where 2638.Ar name 2639is the function name used in the arithmetic expression and each identified 2640.Ar ident 2641is a name reference to the long double precision floating point argument. 2642The value of 2643.Sy .sh.value 2644when the function returns is the value of this function. 2645User defined functions can take up to 3 arguments and override C math library 2646functions. 2647.Pp 2648An internal representation of a 2649.Ar variable 2650as a double precision floating point can be specified with the 2651.Fl E Ns Op Ar n , 2652.Fl F Ns Op Ar n , 2653or 2654.Fl X Ns Op Ar n 2655options of the 2656.Ic typeset 2657special built-in command. 2658The 2659.Fl E 2660option causes the expansion of the value to be represented using scientific 2661notation when it is expanded. 2662The optional option argument 2663.Ar n 2664defines the number of significant figures. 2665The 2666.Fl F 2667option causes the expansion to be represented as a floating decimal number when 2668it is expanded. 2669The optional option argument 2670.Ar n 2671defines the number of places after the decimal point in this case. 2672The 2673.Fl X 2674option causes the expansion to be represented using the 2675.Sy %a 2676format defined by ISO C-99. 2677The optional option argument n defines the number of places after the decimal 2678(or radix) point in this case. 2679.Pp 2680An internal integer representation of a 2681.Ar variable 2682can be specified with 2683the 2684.Fl i Ns Op Ar n 2685option of the 2686.Ic typeset 2687special built-in command. 2688The optional option argument 2689.Ar n 2690specifies an arithmetic base to be used when expanding the variable. 2691If you do not specify an arithmetic base, base 10 is used. 2692.Pp 2693Arithmetic evaluation is performed on the value of each assignment to a 2694variable with the 2695.Fl E , 2696.Fl F , 2697.Fl X 2698or 2699.Fl i 2700option. 2701Assigning a floating point number to a variable whose type is an integer causes 2702the fractional part to be truncated. 2703.Ss "Prompting" 2704When used interactively, the shell prompts with the value of 2705.Ev PS1 2706after expanding it for parameter expansion, command substitution, and 2707arithmetic substitution, before reading a command. 2708In addition, each single 2709.Sy \&! 2710in the prompt is replaced by the command number. 2711A 2712.Sy \&!\&! 2713is required to place a literal 2714.Sy \&! 2715in the prompt. 2716If at any time a NEWLINE is typed and further input is needed to complete a 2717command, then the secondary prompt, that is, the value of 2718.Ev PS2 , 2719is issued. 2720.Ss "Conditional Expressions" 2721A 2722.Sy conditional expression 2723is used with the 2724.Sy [[ 2725compound command to test attributes of files and to compare strings. 2726Field splitting and file name generation are not performed on the words between 2727.Sy [[ 2728and 2729.Sy ]] . 2730.Pp 2731Each expression can be constructed from one or more of the following unary or 2732binary expressions: 2733.Bl -tag -width Ar 2734.It Fl a Ar file 2735True, if 2736.Ar file 2737exists. 2738.Pp 2739This option is the same as 2740.Fl e . 2741This option is obsolete. 2742.It Fl b Ar file 2743True, if 2744.Ar file 2745exists and is a block special file. 2746.It Fl c Ar file 2747True, if 2748.Ar file 2749exists and is a character special file. 2750.It Fl d Ar file 2751True, if 2752.Ar file 2753exists and is a directory. 2754.It Fl e Ar file 2755True, if 2756.Ar file 2757exists. 2758.It Fl f Ar file 2759True, if 2760.Ar file 2761exists and is an ordinary file. 2762.It Fl g Ar file 2763True, if 2764.Ar file 2765exists and it has its 2766.Sy setgid 2767bit set. 2768.It Fl G Ar file 2769True, if 2770.Ar file 2771exists and its group matches the effective group id of this process. 2772.It Fl h Ar file 2773True, if 2774.Ar file 2775exists and is a symbolic link. 2776.It Fl k Ar file 2777True, if 2778.Ar file 2779exists and it has its sticky bit set. 2780.It Fl L Ar file 2781True, if 2782.Ar file 2783exists and is a symbolic link. 2784.It Fl n Ar string 2785True, if length of 2786.Ar string 2787is 2788.Sy non-zero . 2789.It Fl N Ar file 2790True, if 2791.Ar file 2792exists and the modification time is greater than the last 2793access time. 2794.It Fl o Ar option 2795True, if option named 2796.Ar option 2797is on. 2798.It Fl o Sy \&? Ns Ar option 2799True, if option named 2800.Ar option 2801is a valid option name. 2802.It Fl O Ar file 2803True, if 2804.Ar file 2805exists and is owned by the effective user id of this process. 2806.It Fl p Ar file 2807True, if 2808.Ar file 2809exists and is a 2810.Sy FIFO 2811special file or a pipe. 2812.It Fl r Ar file 2813True, if 2814.Ar file 2815exists and is readable by current process. 2816.It Fl R Ar name 2817True if variable 2818.Ar name 2819is a name reference. 2820.It Fl s Ar file 2821True, if 2822.Ar file 2823exists and has size greater than zero. 2824.It Fl S Ar file 2825True, if 2826.Ar file 2827exists and is a socket. 2828.It Fl t Ar fildes 2829True, if file descriptor number 2830.Ar fildes 2831is open and associated with a terminal device. 2832.It Fl u Ar file 2833True, if 2834.Ar file 2835exists and it has its 2836.Sy setuid 2837bit set. 2838.It Fl v Ar name 2839True, if variable 2840.Ar name 2841is a valid variable name and is set. 2842.It Fl w Ar file 2843True, if 2844.Ar file 2845exists and is writable by current process. 2846.It Fl x Ar file 2847True, if 2848.Ar file 2849exists and is executable by current process. 2850If 2851.Ar file 2852exists and is a directory, then true if the current process has permission to 2853search in the directory. 2854.It Fl z Ar string 2855True, if length of 2856.Ar string 2857is zero. 2858.It Ar file1 Fl ef Ar file2 2859True, if 2860.Ar file1 2861and 2862.Ar file2 2863exist and refer to the same file. 2864.It Ar file1 Fl nt Ar file2 2865True, if 2866.Ar file1 2867exists and 2868.Ar file2 2869does not, or 2870.Ar file1 2871is newer 2872than 2873.Ar file2 . 2874.It Ar file1 Fl ot Ar file2 2875True, if 2876.Ar file2 2877exists and 2878.Ar file1 2879does not, or 2880.Ar file1 2881is older 2882than 2883.Ar file2 . 2884.It Ar string 2885True, if 2886.Ar string 2887is not null. 2888.It Ar string Sy == Ar pattern 2889True, if 2890.Ar string 2891matches 2892.Ar pattern . 2893Any part of 2894.Ar pattern 2895can be quoted to cause it to be matched as a string. 2896With a successful match to 2897.Ar pattern , the 2898.Ev \&.sh.match 2899array variable contains the match and sub-pattern matches. 2900.It Ar string Sy = Ar pattern 2901Same as 2902.Sy == , 2903but is obsolete. 2904.It Ar string Sy != Ar pattern 2905True, if 2906.Ar string 2907does not match 2908.Ar pattern . 2909When the 2910.Ar string 2911matches the 2912.Ar pattern 2913the 2914.Ev \&.sh.match 2915array variable contains the match and sub-pattern matches. 2916.It Ar string Sy =~ Ar ere 2917True if 2918.Ar string 2919matches the pattern 2920.Sy ~(E) Ns Ar ere 2921where 2922.Ar ere 2923is an extended regular expression. 2924.It Ar string1 Sy \&< Ar string2 2925True, if 2926.Ar string1 2927comes before 2928.Ar string2 2929based on 2930.Sy ASCII 2931value of their characters. 2932.It Ar string1 Sy \&> Ar string2 2933True, if 2934.Ar string1 2935comes after 2936.Ar string2 2937based on 2938.Sy ASCII 2939value of 2940their characters. 2941.El 2942.Pp 2943In each of the above expressions, if 2944.Ar file 2945is of the form 2946.Pa /dev/fd/ Ns Ar n , 2947where 2948.Ar n 2949is an integer, the test is applied to the open file whose descriptor number is 2950.Ar n . 2951.Pp 2952The following obsolete arithmetic comparisons are also supported: 2953.Bl -tag -width 18n 2954.It Ar exp1 Fl eq Ar exp2 2955True, if 2956.Ar exp1 2957is equal to 2958.Ar exp2 . 2959.It Ar exp1 Fl ge Ar exp2 2960True, if 2961.Ar exp1 2962is greater than or equal to 2963.Ar exp2 . 2964.It Ar exp1 Fl gt Ar exp2 2965True, if 2966.Ar exp1 2967is greater than 2968.Ar exp2 . 2969.It Ar exp1 Fl le Ar exp2 2970True, if 2971.Ar exp1 2972is less than or equal to 2973.Ar exp2 . 2974.It Ar exp1 Fl lt Ar exp2 2975True, if 2976.Ar exp1 2977is less than 2978.Ar exp2 . 2979.It Ar exp1 Fl ne Ar exp2 2980True, if 2981.Ar exp1 2982is not equal to 2983.Ar exp2 . 2984.El 2985.Pp 2986A compound expression can be constructed from these primitives by using any of 2987the following, listed in decreasing order of precedence: 2988.Bl -tag -width Ds 2989.It Sy \&( Ns Ar expression Ns Sy \&) 2990True, if 2991.Ar expression 2992is true. 2993Used to group expressions. 2994.It Sy \&! Ar expression 2995True, if 2996.Ar expression 2997is false. 2998.It Ar expression1 Sy \&&& Ar expression2 2999True, if 3000.Ar expression1 3001and 3002.Ar expression2 3003are both true. 3004.It Ar expression1 Sy \&|\&| Ar expression2 3005True, if either 3006.Ar expression1 3007or 3008.Ar expression2 3009is true. 3010.El 3011.Ss "Input and Output" 3012Before a command is executed, its input and output can be redirected using a 3013special notation interpreted by the shell. 3014The following can appear anywhere in 3015a simple command or can precede or follow a command and are 3016.Em not 3017passed on to the invoked command. 3018Command substitution, parameter expansion, and arithmetic substitution occur 3019before 3020.Ar word 3021or 3022.Ar digit 3023is used except as noted in this section. 3024File name generation occurs only if the shell is interactive and the pattern 3025matches a single file. 3026Field splitting is not performed. 3027.Pp 3028In each of the following redirections, if 3029.Ar file 3030is of the form 3031.Pa /dev/sctp/ Ar host Ns Sy / Ns Ar port , 3032.Pa /dev/tcp/ Ar host Ns Sy / Ns Ar port , 3033or 3034.Pa /dev/udp/ Ar host Ns Sy / Ns Ar port , 3035where 3036.Ar host 3037is a hostname or host address, and 3038.Ar port 3039is a service specified by name or an integer port number, then the redirection 3040attempts to make a 3041.Sy tcp , 3042.Sy sctp 3043or 3044.Sy udp 3045connection to the corresponding socket. 3046.Pp 3047No intervening space is allowed between the characters of redirection 3048operators. 3049.Bl -tag -width Ar 3050.It Sy \&< Ns Ar word 3051Use file 3052.Ar word 3053as standard input (file descriptor 0). 3054.It Sy \&> Ns Ar word 3055Use file 3056.Ar word 3057as standard output (file descriptor 1). 3058If the file does not exist then it is created. 3059If the file exists, and the 3060.Sy noclobber 3061option is on, this causes an error, otherwise, it is truncated to zero length. 3062.It Sy \&>\&| Ns Ar word 3063Same as 3064.Sy > , 3065except that it overrides the 3066.Sy noclobber 3067option. 3068.It Sy \&>\&; Ns Ar word 3069Write output to a temporary file. 3070If the command completes successfully rename it to word, otherwise, delete the 3071temporary file. 3072>;word cannot be used with the 3073.Xr exec 2 3074built-in. 3075.It Sy \&>> Ns Ar word 3076Use file 3077.Ar word 3078as standard output. 3079If the file exists, then output is appended to it (by first seeking to the 3080end-of-file), otherwise, the file is created. 3081.It Sy \&<> Ns Ar word 3082Open file 3083.Ar word 3084for reading and writing as standard input. 3085.It Sy \&<< Ns Oo Fl Oc Ns Ar word 3086The shell input is read up to a line that is the same as 3087.Ar word 3088after any quoting has been removed, or to an end-of-file. 3089No parameter substitution, command substitution, arithmetic substitution or 3090file name generation is performed on 3091.Ar word . 3092The resulting document, called a 3093.Sy here-document , 3094becomes the standard input. 3095If any character of 3096.Ar word 3097is quoted, then no interpretation is placed upon the characters of the 3098document. 3099Otherwise, parameter expansion, command substitution, and arithmetic 3100substitution occur, 3101\eNEWLINE is ignored, and \e must be used to quote the characters 3102.Sy \e , 3103.Sy $ 3104and 3105.Sy \&` . 3106If 3107.Sy - 3108is appended to 3109.Sy << , 3110then all 3111leading tabs are stripped from 3112.Ar word 3113and from the document. 3114If 3115.Sy # 3116is 3117appended to 3118.Sy << , 3119then leading SPACEs and TABs are stripped off the first line of the document 3120and up to an equivalent indentation is stripped from the remaining lines and 3121from 3122.Ar word . 3123A tab stop is assumed to occur at every 8 columns for the purposes of 3124determining the indentation. 3125.It Sy \&<<< Ns Ar word 3126A short form of here document in which 3127.Ar word 3128becomes the contents of the here-document after any parameter expansion, 3129command substitution, and arithmetic substitution occur. 3130.It Sy \&<& Ns Ar digit 3131The standard input is duplicated from file descriptor 3132.Ar digit , 3133and similarly for the standard output using 3134.Sy >& 3135.Ar digit . 3136See 3137.Xr dup 2 . 3138.It Sy \&<& Ns Ar digit Ns Sy - 3139The file descriptor specified by 3140.Ar digit 3141is moved to standard input. 3142Similarly for the standard output using 3143.Sy >& Ns Ar digit Ns Sy - . 3144.It Sy <&- 3145The standard input is closed. 3146Similarly for the standard output using 3147.Sy >&- . 3148.It Sy <&p 3149The input from the co-process is moved to standard input. 3150.It Sy >&p 3151The output to the co-process is moved to standard output. 3152.It Sy <#(( Ns Ar expr Ns Sy )) 3153Evaluate arithmetic expression 3154.Ar expr 3155and position file descriptor 0 to the resulting value bytes from the start of 3156the file. 3157The variables 3158.Ev CUR 3159and 3160.Ev EOF 3161evaluate to the current offset and end-of-file offset respectively when 3162evaluating 3163.Ar expr . 3164.It Sy >#(( Ns Ar expr Ns Sy )) 3165The same as 3166.Sy <# 3167except applies to file descriptor 1. 3168.It Sy <# Ns Ar pattern 3169Seek forward to the beginning of the next line containing pattern. 3170.It Sy <## Ns Ar pattern 3171The same as 3172.Sy <# , 3173except that the portion of the file that is skipped is copied to standard 3174output. 3175.El 3176.Pp 3177If one of the redirection operators is preceded by a digit, with no intervening 3178space, then the file descriptor number referred to is that specified by the 3179digit (instead of the default 0 or 1). 3180If one of the redirection operators 3181other than 3182.Sy >&- 3183and the 3184.Sy ># 3185and 3186.Sy <# 3187forms, is preceded by 3188.Sy \&{ Ns Ar varname Ns Sy \&} 3189with no intervening space, then a file descriptor 3190number 3191.Sy > 10 3192is selected by the shell and stored in the variable 3193.Ar varname . 3194If 3195.Sy >&- 3196or the any of the 3197.Sy ># 3198and 3199.Sy <# 3200forms is preceded by 3201.Sy \&{ Ns Ar varname Ns Sy \&} 3202the value of 3203.Ar varname 3204defines the file descriptor to close or position. 3205For example: 3206.Pp 3207.Dl ... 2>&1 3208.Pp 3209means file descriptor 2 is to be opened for writing as a duplicate of file 3210descriptor 1 and 3211.Pp 3212.Dl exec [n]<file 3213.Pp 3214means open 3215.Ar file 3216for reading and store the file descriptor number in variable 3217.Ar n . 3218The order in which redirections are specified is significant. 3219The shell evaluates each redirection in terms of the 3220.Pq Ar file_descriptor , Ar file 3221association at the time of evaluation. 3222For example: 3223.Pp 3224.Dl ... 1>fname 2>&1 3225.Pp 3226first associates file descriptor 1 with file 3227.Ar fname . 3228It then associates file descriptor 2 with the file associated with file 3229descriptor 1, that is, 3230.Ar fname . 3231If the order of redirections were reversed, file descriptor 2 would be 3232associated with the terminal (assuming file descriptor 1 had been) and then 3233file descriptor 1 would be associated with file 3234.Ar fname . 3235If a command is followed by 3236.Sy \&& 3237and job control is not active, the default standard input for the command is 3238the empty file 3239.Pa /dev/null . 3240Otherwise, the environment for the execution of a command contains the file 3241descriptors of the invoking shell as modified by input and output 3242specifications. 3243.Ss "Environment" 3244The 3245.Sy environment 3246is a list of name-value pairs that is passed to an executed program in the same 3247way as a normal argument list. 3248See 3249.Xr environ 5 . 3250.Pp 3251The names must be 3252.Ar identifiers 3253and the values are character strings. 3254The shell interacts with the environment in several ways. 3255On invocation, the shell scans the environment and creates a variable for each 3256name found, giving it the corresponding value and attributes and marking it 3257.Ic export . 3258Executed commands inherit the environment. 3259If the user modifies the values of these variables or creates new ones, using 3260the 3261.Ic export 3262or 3263.Ic typeset Fl x 3264commands, they become part of the environment. 3265The environment seen by any executed command is thus composed of any name-value 3266pairs originally inherited by the shell, whose values can be modified by the 3267current shell, plus any additions which must be noted in 3268.Ic export 3269or 3270.Ic typeset Fl x 3271commands. 3272The environment for any simple-command or function can be augmented by 3273prefixing it with one or more variable assignments. 3274A variable assignment argument is a word of the form 3275.Ar identifier Ns Sy = Ns Ar value . 3276Thus: 3277.Pp 3278.Dl TERM=450 cmd args 3279.Pp 3280and 3281.Pp 3282.Dl (export TERM; TERM=450; cmd args) 3283.Pp 3284are equivalent 3285.Pq as far as the execution of Ar cmd No is concerned 3286except for special built-in commands listed in the 3287.Sx Built-Ins 3288section, those that are preceded with a dagger. 3289If the obsolete 3290.Fl k 3291option is set, all variable assignment arguments are placed in the environment, 3292even if they occur after the command name. 3293.Pp 3294The following example first prints 3295.Sy a=b c 3296and then 3297.Sy c : 3298.Bd -literal -offset indent 3299echo a=b c 3300set -k 3301echo a=b c 3302.Ed 3303.Pp 3304This feature is intended for use with scripts written for early versions of the 3305shell and its use in new scripts is strongly discouraged. 3306.Ss "Functions" 3307For historical reasons, there are two ways to define functions, the 3308.Ar name Ns Sy () 3309syntax and the 3310.Ic function Ar name 3311syntax. 3312These are 3313described in the 3314.Sx Commands 3315section of this manual page. 3316.Pp 3317Shell functions are read in and stored internally. 3318Alias names are resolved when the function is read. 3319Functions are executed like commands with the arguments passed as positional 3320parameters. 3321See the 3322.Sx Execution 3323section of this manual page for details. 3324.Pp 3325Functions defined by the 3326.Ic function Ar name 3327syntax and called by name execute in the same process as the caller and share 3328all files and present working directory with the caller. 3329Traps caught by the caller are reset to their default action inside the 3330function. 3331A trap condition that is not caught or ignored by the function causes the 3332function to terminate and the condition to be passed on to the caller. 3333A trap on 3334.Sy EXIT 3335set inside a function is executed in the environment of the caller after the 3336function completes. 3337Ordinarily, variables are shared between the calling program and the function. 3338However, the 3339.Ic typeset 3340special built-in command used within a function defines local variables whose 3341scope includes the current function. 3342They can be passed to functions that they call in the variable assignment list 3343that precedes the call or as arguments passed as name references. 3344Errors within functions return control to the caller. 3345.Pp 3346Functions defined with the 3347.Ar name Ns Sy () 3348syntax and functions defined with the 3349.Ic function Ar name 3350syntax that are invoked with the 3351.Ic \&. 3352special built-in are executed in the caller's environment and share all 3353variables and traps with the caller. 3354Errors within these function executions cause the script that contains them to 3355abort. 3356.Pp 3357The special built-in command 3358.Ic return 3359is used to return from function calls. 3360.Pp 3361Function names can be listed with the 3362.Fl f 3363or 3364.Sy +f 3365option of the 3366.Ic typeset 3367special built-in command. 3368The text of functions, when available, is also listed with 3369.Fl f . 3370Functions can be undefined with the 3371.Fl f 3372option of the 3373.Ic unset 3374special built-in command. 3375.Pp 3376Ordinarily, functions are unset when the shell executes a shell script. 3377Functions that need to be defined across separate invocations of the shell 3378should be placed in a directory and the 3379.Ev FPATH 3380variable should contain the 3381name of this directory. 3382They can also be specified in the 3383.Ev ENV 3384file. 3385.Ss "Discipline Functions" 3386Each variable can have zero or more discipline functions associated with it. 3387The shell initially understands the discipline names 3388.Ic get , 3389.Ic set , 3390.Ic append , 3391and 3392.Ic unset 3393but on most systems others can be added at run time via the C programming 3394interface extension provided by the 3395.Ic builtin 3396built-in utility. 3397If the 3398.Ic get 3399discipline is defined for a variable, it is invoked whenever the specified 3400variable is referenced. 3401If the variable 3402.Sy \&.sh.value 3403is assigned a value inside the discipline function, the referenced variable is 3404evaluated to this value instead. 3405If the 3406.Ic set 3407discipline is defined for a variable, it is invoked whenever the specified 3408variable is assigned a value. 3409If the 3410.Ic append 3411discipline is defined for a variable, it is invoked whenever a value is 3412appended to the specified variable. 3413The variable 3414.Sy \&.sh.value 3415is specified the value of the variable before invoking the discipline, and the 3416variable is assigned the value of 3417.Sy \&.sh.value 3418after the discipline completes. 3419If 3420.Sy .sh.value 3421is 3422.Ic unset 3423inside the discipline, then that value is unchanged. 3424If the 3425.Ic unset 3426discipline is defined for a variable, it is invoked whenever the specified 3427variable is unset. 3428The variable is not unset unless it is unset explicitly from within this 3429discipline function. 3430.Pp 3431The variable 3432.Sy \&.sh.name 3433contains the name of the variable for which the discipline function is called, 3434.Sy \&.sh.subscript 3435is the subscript of the variable, and 3436.Sy \&.sh.value 3437contains the value being assigned inside the 3438.Ic set 3439discipline function. 3440For the 3441.Sy set 3442discipline, changing 3443.Sy \&.sh.value 3444changes the value that gets assigned. 3445The variable 3446.Sy _ 3447is a reference to the variable including the subscript if any. 3448For the 3449.Ic set 3450discipline, changing 3451.Sy \&.sh.value 3452will change the value that gets assigned. 3453Finally, the expansion 3454.Sy ${ Ns Ar var.name Ns Sy } , 3455when name is the name of a discipline, and there is no variable of this name, 3456is equivalent to the command substitution 3457.Sy ${ Ns Ar var.name Ns Sy ;} . 3458.Ss "Name Spaces" 3459Commands and functions that are executed as part of the 3460.Ar list 3461of a 3462.Ic namespace 3463command that modify variables or create new ones, create a new variable whose 3464name is the name of the name space as given by 3465.Ar identifier 3466preceded by two dots 3467.Pq Sy \&.. . 3468When a variable whose name is 3469.Ar name 3470is referenced, it is first searched for using 3471.Sy \&. Ns Ar identifier Ns Sy \&. Ns Ar name Ns Sy \&. 3472Similarly, a function defined by a command in the 3473.Ic namespace Ar list 3474is created using the name space name preceded by two dots 3475.Pq Sy \&.. . 3476.Pp 3477When the 3478.Ar list 3479of a 3480.Ic namespace 3481command contains a 3482.Ic namespace 3483command, the names of variables and functions that are created consist 3484of the variable or function name preceded by the list of 3485.Ar identifier Ns No s , 3486each preceded by two dots 3487.Pq Sy \&.. . 3488.Pp 3489Outside of a name space, a variable or function created inside a name space can 3490be referenced by preceding it with the name space name. 3491.Pp 3492By default, variables staring with 3493.Sy \&.sh 3494are in the 3495.Sy sh 3496name space. 3497.Ss "Typed Variables" 3498Typed variables provide a way to create data structure and objects. 3499A type can be defined either by a shared library, by the 3500.Ic enum 3501built-in command described below, or by using the 3502.Fl T 3503option of the 3504.Ic typeset 3505built-in command. 3506With the 3507.Fl T 3508option of 3509.Ic typeset , 3510the type name, specified as an option argument to 3511.Fl T , 3512is set with a compound variable assignment that defines the type. 3513Function definitions can appear inside the compound variable assignment and 3514these become discipline functions for this type and can be invoked or redefined 3515by each instance of the type. 3516The function name 3517.Sy create 3518is treated specially. 3519It is invoked for each instance of the type that is created but is not 3520inherited and cannot be redefined for each instance. 3521.Pp 3522When a type is defined a special built-in command of that name is added. 3523These built-ins are declaration commands and follow the same expansion rules as 3524all the special built-in commands defined below that are preceded by a dot 3525.Pq Sy \&. . 3526These commands can subsequently be used inside further type definitions. 3527The man page for these commands can be generated by using the 3528.Fl -man 3529option or any of the other 3530.Fl - 3531options described with 3532.Ic getopts . 3533The 3534.Fl r , 3535.Fl a , 3536.Fl A , 3537.Fl h 3538and 3539.Fl S 3540options of 3541.Ic typeset 3542are permitted with each of these new built-ins. 3543.Pp 3544An instance of a type is created by invoking the type name followed by one or 3545more instance names. 3546Each instance of the type is initialized with a copy of the sub-variables 3547except for sub-variables that are defined with the 3548.Fl s 3549option. 3550Variables defined with 3551.Fl S 3552are shared by all instances of the type. 3553Each instance can change the value of any sub-variable and can also define new 3554discipline functions of the same names as those defined by the type definition 3555as well as any standard discipline names. 3556No additional sub-variables can be defined for any instance. 3557.Pp 3558When defining a type, if the value of a sub-variable is not set and the 3559.Fl r 3560attribute is specified, it causes the sub-variable to be a required 3561sub-variable. 3562Whenever an instance of a type is created, all required sub-variables must be 3563specified. 3564These sub-variables become readonly in each instance. 3565.Pp 3566When 3567.Ic unset 3568is invoked on a sub-variable within a type, and the 3569.Fl r 3570attribute has not been specified for this field, the value is reset to the 3571default value associative with the type. 3572Invoking 3573.Ic unset 3574on a type instance not contained within another type deletes all sub-variables 3575and the variable itself. 3576A type definition can be derived from another type definition by defining the 3577first sub-variable name as 3578.Sy _ 3579and defining its type as the base type. 3580Any remaining definitions will be additions and modifications that apply to the 3581new type. 3582If the new type name is the same is that of the base type, the type will be 3583replaced and the original type will no longer be accessible. 3584.Pp 3585The 3586.Ic typeset 3587command with 3588.Fl T 3589and no option argument or operands will write all the type definitions to 3590standard output in a form that that can be read in to create all the types. 3591.Ss "Jobs" 3592If the monitor option of the 3593.Ic set 3594command is turned on, an interactive shell associates a job with each pipeline. 3595It keeps a table of current jobs, printed by the 3596.Ic jobs 3597command, and assigns them small integer numbers. 3598When a job is started asynchronously with 3599.Sy \&& , 3600the shell prints a line which looks like: 3601.Pp 3602.Dl [1] 1234 3603.Pp 3604indicating that the job which was started asynchronously was job number 1 and 3605had one (top-level) process, whose process id was 3606.Sy 1234 . 3607.Pp 3608If you are running a job and wish to stop it, CTRL-z sends a 3609.Sy STOP 3610signal to the current job. 3611The shell normally displays a message that the job has been stopped, and 3612displays another prompt. 3613You can then manipulate the state of this job, putting it in the background 3614with the 3615.Ic bg 3616command, or run some other commands and then eventually bring the job back into 3617the foreground with the foreground command 3618.Ic fg . 3619A CTRL-z takes effect immediately and is like an interrupt in that pending 3620output and unread input are discarded when it is typed. 3621.Pp 3622A job being run in the background stops if it tries to read from the terminal. 3623Background jobs are normally allowed to produce output, but this can be 3624disabled by giving the command 3625.Sy stty tostop . 3626If you set this 3627.Sy tty 3628option, then background jobs stop when they try to produce output like they do 3629when they try to read input. 3630.Pp 3631A job pool is a collection of jobs started with 3632.Ar list Sy & 3633associated with a name. 3634.Pp 3635There are several ways to refer to jobs in the shell. 3636A job can be referred to 3637by the process id of any process of the job or by one of the following: 3638.Bl -tag -width Ar 3639.It Sy % Ns Ar number 3640The job with the specified number. 3641.It Ar pool 3642All the jobs in the job pool named by 3643.Ar pool . 3644.It Ar pool Ns Sy \&. Ns Ar number 3645The job number 3646.Ar number 3647in the pool named by 3648.Ar pool . 3649.It Sy % Ns Ar string 3650Any job whose command line begins with 3651.Ar string . 3652.It Sy %? Ns Ar string 3653Any job whose command line contains 3654.Ar string . 3655.It Sy %% 3656Current job. 3657.It Sy %+ 3658Equivalent to 3659.Sy %% . 3660.It Sy %- 3661Previous job. 3662.El 3663.Pp 3664In addition, unless noted otherwise, wherever a job can be specified, the name 3665of a background job pool can be used to represent all the jobs in that pool. 3666.Pp 3667The shell learns immediately whenever a process changes state. 3668It normally informs you whenever a job becomes blocked so that no further 3669progress is possible, but only just before it prints a prompt. 3670This is done so that it does not otherwise disturb your work. 3671The notify option of the 3672.Ic set 3673command causes the shell to print these job change messages as soon as they 3674occur. 3675.Pp 3676When the 3677.Sy monitor 3678option is on, each background job that completes triggers any trap set for 3679.Dv CHLD . 3680.Pp 3681When you try to leave the shell while jobs are running or stopped, you are 3682warned that 3683.Pp 3684.D1 You have stopped(running) jobs. 3685.Pp 3686You can use the 3687.Ic jobs 3688command to see what they are. 3689If you immediately try to exit again, the shell does not warn you a second 3690time, and the stopped jobs are terminated. 3691When a login shell receives a 3692.Sy HUP 3693signal, it sends a 3694.Sy HUP 3695signal to each job that has not been disowned with the 3696.Ic disown 3697built-in command. 3698.Ss "Signals" 3699The 3700.Sy INT 3701and 3702.Sy QUIT 3703signals for an invoked command are ignored if the command is followed by 3704.Sy \&& 3705and the 3706.Sy monitor 3707option is not active. 3708Otherwise, signals have the values inherited by the shell from its parent. 3709See the 3710.Ic trap 3711built-in command. 3712.Ss "Execution" 3713Each time a command is read, the substitutions are carried out. 3714If the command name matches one of the ones in the 3715.Sx Special Built-in Commands 3716section of this manual page, it is executed within the current shell process. 3717Next, the command name is checked to see if it matches a user defined function. 3718If it does, the positional parameters are saved and then reset to the arguments 3719of the function call. 3720A function is also executed in the current shell process. 3721When the function completes or issues a return, the positional parameter list 3722is restored. 3723For functions defined with the 3724.Ic function Ar name 3725syntax, any trap set on 3726.Dv EXIT 3727within the function is executed. 3728The exit value of a function is the value of the last command executed. 3729If a command name is not a special built-in command or a user defined function, 3730but it is one of the built-in commands, it is executed in the current shell 3731process. 3732.Pp 3733The shell variables 3734.Ev PATH 3735and 3736.Ev FPATH 3737define the search path for the directory containing the command. 3738Alternative directory names are separated by a colon 3739.Pq Sy \&: . 3740The default path is 3741.Pa /bin Ns Sy \&: Ns Pa /usr/bin Ns Sy \&: , 3742specifying 3743.Pa /bin , 3744.Pa /usr/bin , 3745and the current directory in that order. 3746The current directory can be specified by two or more adjacent colons, or by a 3747colon at the beginning or end of the path list. 3748If the command name contains a slash 3749.Pq Sy \&/ , 3750the search path is not used. 3751Otherwise, each directory in the list of directories defined by 3752.Ev PATH 3753and 3754.Ev FPATH 3755is checked in order. 3756If the directory being searched is contained in the value of the 3757.Ev FPATH 3758variable and contains a file whose name matches the command being searched, 3759then this file is loaded into the current shell environment as if it were the 3760argument to the 3761.Ic \&. 3762command except that only preset aliases are expanded, and a function of the 3763specified name is executed as described in this manual page. 3764.Pp 3765If this directory is not in 3766.Ev FPATH , 3767the shell first determines whether there is a built-in version of a command 3768corresponding to a given pathname and, if so, it is invoked in the current 3769process. 3770If no built-in is found, the shell checks for a file named 3771.Pa \&.paths 3772in this directory. 3773If found and there is a line of the form: 3774.Pp 3775.D1 Ev FPATH Ns = Ns Ar path 3776.Pp 3777where 3778.Ar path 3779is an existing directory, then that directory is searched immediately after the 3780current directory as if it were found in the 3781.Ev FPATH 3782variable. 3783If 3784.Ar path 3785does not begin with 3786.Sy / , 3787it is checked for relative to the directory being searched. 3788.Pp 3789The 3790.Pa \&.paths 3791file is then checked for a line of the form: 3792.Pp 3793.D1 Ev PLUGIN_LIB Ns = Ns Ar libname Ns Oo Sy \&: Ns Ar libname Oc Ns No ... 3794.Pp 3795Each library named by 3796.Ar libname 3797will be searched for as if it were an option argument to 3798.Ic builtin Fl f 3799and, if it contains a built-in of the specified name, this is executed instead 3800of a command by this name. 3801.Pp 3802Any built-in loaded from a library found this way will be associated with the 3803directory containing the 3804.Pa \&.paths 3805file so it will only execute if not found in an earlier directory. 3806.Pp 3807Finally, the directory will be checked for a file of the given name. 3808If the file has execute permission but is not an 3809.Pa a.out 3810file, it is assumed to be a file containing shell commands. 3811A separate shell is spawned to read it. 3812All non-exported variables are removed in this case. 3813If the shell command file doesn't have read permission, and/or if the 3814.Sy setuid 3815and 3816.Sy setgid 3817bits are set on the file, then the shell executes an agent whose job it is to 3818set up the permissions and execute the shell with the shell command file passed 3819down as an open file. 3820If the 3821.Pa \&.paths 3822contains a line of the form: 3823.Pp 3824.D1 Sy name= Ns Ar value 3825.Pp 3826in the 3827first or second line, then the environment variable 3828.Ar name 3829is modified by prepending the directory specified by 3830.Ar value 3831to the directory list. 3832If 3833.Ar value 3834is not an absolute directory, then it specifies a directory relative to the 3835directory in which the executable was found. 3836If the environment variable 3837.Ev name 3838does not already exist it will be added to the environment list for the 3839specified command. 3840A parenthesized command is executed in a sub-shell without removing 3841non-exported variables. 3842.Ss "Command Re-entry" 3843The text of the last 3844.Ev HISTSIZE 3845.Pq default 512 3846commands entered from a terminal device is saved in a history file. 3847The file 3848.Pa $HOME/.sh_history 3849is used if the 3850.Ev HISTFILE 3851variable is not set or if the file it names is not writable. 3852A shell can access the commands of all interactive shells which use the same 3853named 3854.Ev HISTFILE . 3855The built-in command 3856.Ic hist 3857is used to list or edit a portion of this file. 3858The portion of the file to be edited or listed can be selected by number or by 3859giving the first character or characters of the command. 3860A single command or range of commands can be specified. 3861If you do not specify an editor program as an argument to 3862.Ic hist 3863then the value of the variable 3864.Ev HISTEDIT 3865is used. 3866If 3867.Ev HISTEDIT 3868is unset, the obsolete variable 3869.Ev FCEDIT 3870is used. 3871If 3872.Ev FCEDIT 3873is not defined, then 3874.Pa /bin/ed 3875is used. 3876The edited commands are printed and executed again upon leaving the editor 3877unless you quit without writing. 3878The 3879.Fl s 3880option 3881.Pq and in obsolete versions, the editor name Sy \&- 3882is used to skip the editing phase and to re-execute the command. 3883In this case a substitution parameter of the form 3884.Ar old Ns Sy = Ns Ar new 3885can be used to modify the command before execution. 3886For example, with the preset alias 3887.Ic r , 3888which is aliased to 3889.Ic hist -s , 3890typing 3891.Sq r bad=good c 3892re-executes the most recent 3893command which starts with the letter 3894.Sy c , 3895replacing the first occurrence of the string 3896.Sq bad 3897with the string 3898.Sq good . 3899.Ss "Inline Editing Options" 3900Normally, each command line entered from a terminal device is simply typed 3901followed by a NEWLINE (RETURN or LINE FEED). 3902If either the 3903.Sy emacs , 3904.Sy gmacs , 3905or 3906.Sy vi 3907option is active, the user can edit the command line. 3908To be in either of these edit modes set the corresponding option. 3909An editing option is automatically selected each time the 3910.Ev VISUAL 3911or 3912.Ev EDITOR 3913variable is assigned a value ending in either of these option names. 3914.Pp 3915The editing features require that the user's terminal accept RETURN as carriage 3916return without line feed and that a SPACE must overwrite the current character 3917on the screen. 3918.Pp 3919Unless the 3920.Sy multiline 3921option is on, the editing modes implement a concept where the user is looking 3922through a window at the current line. 3923The window width is the value of 3924.Ev COLUMNS 3925if it is defined, otherwise 3926.Sy 80 . 3927If the window width is too small to display the prompt and leave at least 8 3928columns to enter input, the prompt is truncated from the left. 3929If the line is longer than the window width minus two, a mark is displayed at 3930the end of the window to notify the user. 3931As the cursor moves and reaches the window boundaries the window is centered 3932about the cursor. 3933The mark is a 3934.Sy > 3935.Pq Sy \&< Ns \&, Sy \&* 3936if the line extends on the right, left, or both sides of the window. 3937.Pp 3938The search commands in each edit mode provide access to the history file. 3939Only strings are matched, not patterns, although a leading 3940.Sy ^ 3941in the string restricts the match to begin at the first character in the line. 3942.Pp 3943Each of the edit modes has an operation to list the files or commands that 3944match a partially entered word. 3945When applied to the first word on the line, or the first word after a 3946.Sy \&; , 3947.Sy \&| , 3948.Sy \&& , 3949or 3950.Sy \&( , 3951and the word does not begin with 3952.Sy \&~ 3953or contain a 3954.Sy \&/ , 3955the list of aliases, functions, and executable commands defined by the 3956.Ev PATH 3957variable that could match the partial word is displayed. 3958Otherwise, the list of files that match the specified word is displayed. 3959If the partially entered word does not contain any file expansion characters, a 3960.Sy * 3961is appended before generating these lists. 3962After displaying the generated list, the input line is redrawn. 3963These operations are called command name listing and file name listing, 3964respectively. 3965There are additional operations, referred to as command name completion and 3966file name completion, which compute the list of matching commands or files, but 3967instead of printing the list, replace the current word with a complete or 3968partial match. 3969For file name completion, if the match is unique, a 3970.Sy / 3971is appended if the file is a directory and a space is appended if the file is 3972not a directory. 3973Otherwise, the longest common prefix for all the matching files replaces the 3974word. 3975For command name completion, only the portion of the file names after the last 3976.Sy / 3977are used to find the longest command prefix. 3978If only a single name matches this prefix, then the word is replaced with the 3979command name followed by a space. 3980When using a 3981.Dv TAB 3982for completion that does not yield a unique match, a subsequent 3983.Dv TAB 3984provides a numbered list of matching alternatives. 3985A specific selection can be made by entering the selection number followed by a 3986.Dv TAB . 3987.Ss "Key Bindings" 3988The 3989.Sy KEYBD 3990trap can be used to intercept keys as they are typed and change the characters 3991that are actually seen by the shell. 3992This trap is executed after each character (or sequence of characters when the 3993first character is ESC) is entered while reading from a terminal. 3994.Pp 3995The variable 3996.Sy \&.sh.edchar 3997contains the character or character sequence which generated the trap. 3998Changing the value of 3999.Sy \&.sh.edchar 4000in the trap action causes the shell to behave as if the new value were entered 4001from the keyboard rather than the original value. 4002The variable 4003.Sy \&.sh.edcol 4004is set to the input column number of the cursor at the time of the input. 4005The variable 4006.Sy \&.sh.edmode 4007is set to 4008.Sy ESC 4009when in 4010.Sy vi 4011insert mode and is null otherwise. 4012By prepending 4013.Sy ${.sh.editmode} 4014to a value assigned to 4015.Sy \&.sh.edchar 4016it causes the shell to change to control mode if it is not already in this 4017mode. 4018.Pp 4019This trap is not invoked for characters entered as arguments to editing 4020directives, or while reading input for a character search. 4021.Ss "emacs Editing Mode" 4022This mode is entered by enabling either the 4023.Sy emacs 4024or 4025.Sy gmacs 4026option. 4027The only difference between these two modes is the way they handle 4028.Sy ^T . 4029To edit, the user moves the cursor to the point needing correction and then 4030inserts or deletes characters or words as needed. 4031All the editing commands are control characters or escape sequences. 4032.Pp 4033The notation for control characters is caret 4034.Pq Sy ^ 4035followed by the character. 4036.Pp 4037For example, 4038.Sy ^F 4039is the notation for CTRL/F. 4040This is entered by depressing 4041.Sy f 4042while holding down the CTRL (control) key. 4043The SHIFT key is not depressed. 4044(The notation 4045.Sy ^? 4046indicates the DEL (delete) key). 4047.Pp 4048The notation for escape sequences is 4049.Sy M- 4050followed by a character. 4051For example, 4052.Sy M-f 4053.Pq pronounced Sy Meta f 4054is entered by depressing ESC 4055.Pq Sy ASCII 033 4056followed by 4057.Ql f . 4058.Sy M-F 4059is the notation for ESC followed by 4060.Ql F . 4061.Pp 4062All edit commands operate from any place on the line, not just at the 4063beginning. 4064The RETURN or the LINE FEED key is not entered after edit commands except when 4065noted. 4066.Bl -tag -width Ar 4067.It Sy ^F 4068Move the cursor forward (right) one character. 4069.It Sy M-[C 4070Move the cursor forward (right) one character. 4071.It Sy M-f 4072Move the cursor forward one word. 4073The 4074.Sy emacs 4075editor's idea of a word is a string of characters consisting of only letters, 4076digits and underscores. 4077.It Sy ^B 4078Move the cursor backward (left) one character. 4079.It Sy M-[D 4080Move the cursor backward (left) one character. 4081.It Sy M-b 4082Move the cursor backward one word. 4083.It Sy ^A 4084Move the cursor to the beginning of the line. 4085.It Sy M-[H 4086Move the cursor to the beginning of the line. 4087.It Sy ^E 4088Move the cursor to the end of the line. 4089.It Sy M-[Y 4090Move the cursor to the end of line. 4091.It Sy ^] Ns Ar char 4092Move the cursor forward to the character 4093.Ar char 4094on the current line. 4095.It Sy M-^\&] Ns Ar char 4096Move the cursor backwards to the character 4097.Ar char 4098on the current line. 4099.It Sy ^X^X 4100Interchange the cursor and the mark. 4101.It Ar erase 4102Delete the previous character. 4103The user-defined erase character is defined by the 4104.Xr stty 1 4105command, and is usually 4106.Sy ^H 4107or 4108.Sy # . 4109.It Ar lnext 4110Removes the next character's editing features. 4111The user-defined literal next character is defined by the 4112.Xr stty 1 4113command, or is 4114.Sy ^V 4115if not defined. 4116.It Sy ^D 4117Delete the current character. 4118.It Sy M-d 4119Delete the current word. 4120.It Sy M-^H 4121MetaBACKSPACE. 4122Delete the previous word. 4123.It Sy M-h 4124Delete the previous word. 4125.It Sy M-^\&? 4126MetaDEL. 4127Delete the previous word. 4128If your interrupt character is 4129.Sy ^? 4130(DEL, the default), this command does not work. 4131.It Sy ^T 4132Transpose the current character with the previous character, and advance the 4133cursor in 4134.Sy emacs 4135mode. 4136Transpose two previous characters in 4137.Sy gmacs 4138mode. 4139.It Sy ^C 4140Capitalize the current character. 4141.It Sy M-c 4142Capitalize the current word. 4143.It Sy M-l 4144Change the current word to lower case. 4145.It Sy ^K 4146Delete from the cursor to the end of the line. 4147If preceded by a numerical parameter whose value is less than the current 4148cursor position, delete from specified position up to the cursor. 4149If preceded by a numerical parameter whose value is greater than the current 4150cursor position, then delete from cursor up to specified cursor position. 4151.It Sy ^W 4152Kill from the cursor to the mark. 4153.It Sy M-p 4154Push the region from the cursor to the mark on the stack. 4155.It Ar kill 4156Kill the entire current line. 4157The user-defined kill character is defined by the 4158.Xr stty 1 4159command, usually a 4160.Sy ^G 4161or 4162.Sy @ . 4163If two kill characters are entered in succession, all kill characters from then 4164on cause a line feed. 4165This is useful when using paper terminals. 4166.It Sy ^Y 4167Restore the last item removed from line. 4168Yank the item back to the line. 4169.It Sy ^L 4170Line feed and print the current line. 4171.It Sy M-^L 4172Clear the screen. 4173.It Sy ^@ 4174Null character. 4175Set mark. 4176.It Sy M- Ns Ar space 4177MetaSPACE. 4178Set the mark. 4179.It Sy ^J 4180New line. 4181Execute the current line. 4182.It Sy ^M 4183Return. 4184Execute the current line. 4185.It Sy EOF 4186End-of-file character, normally 4187.Sy ^D , 4188is processed as an 4189.Sy end-of-file 4190only if the current line is null. 4191.It Sy ^P 4192Fetch the previous command. 4193Each time 4194.Sy ^P 4195is entered the previous command back in time is accessed. 4196Moves back one line when it is not on the first line of a multi-line command. 4197.It Sy M-[A 4198.ad 4199Equivalent to 4200.Sy ^P . 4201.It Sy M-< 4202Fetch the least recent (oldest) history line. 4203.It Sy M-> 4204Fetch the most recent (youngest) history line. 4205.It Sy ^N 4206Fetch the next command line. 4207Each time 4208.Sy ^N 4209is entered the next command line forward in time is accessed. 4210.It Sy M-[B 4211Equivalent to 4212.Sy ^N . 4213.It Sy ^R Ns Ar string 4214Reverse search history for a previous command line containing 4215.Ar string . 4216If a parameter of zero is specified, the search is forward. 4217.Ar string 4218is terminated by a RETURN or NEWLINE. 4219If string is preceded by a 4220.Sy ^ , 4221the matched line must begin with 4222.Ar string . 4223If 4224.Ar string 4225is omitted, then the next command line containing the most recent 4226.Ar string 4227is accessed. 4228In this case a parameter of zero reverses the direction of the search. 4229.It Sy ^O 4230Operate. 4231Execute the current line and fetch the next line relative to current line from 4232the history file. 4233.It Sy M- Ns Ar digits 4234Escape. 4235Define numeric parameter. 4236The digits are taken as a parameter to the next command. 4237The commands that accept a parameter are: 4238.Sy ^F , 4239.Sy ^B , 4240.Sy ERASE , 4241.Sy ^C , 4242.Sy ^D , 4243.Sy ^K , 4244.Sy ^R , 4245.Sy ^P , 4246.Sy ^N , 4247.Sy ^] , 4248.Sy M-\&. , 4249.Sy M- , 4250.Sy M-^\&] , 4251.Sy M-_ , 4252.Sy M-= , 4253.Sy M-b , 4254.Sy M-c , 4255.Sy M-d , 4256.Sy M-f , 4257.Sy M-h , 4258.Sy M-l , 4259and 4260.Sy M-^H . 4261.It Sy M- Ns Ar letter 4262Soft-key. 4263Search the alias list for an alias by the name 4264.Ar letter . 4265If an alias of 4266.Ar letter 4267is defined, insert its value on the input queue. 4268.Ar letter 4269must not be one of the metafunctions in this section. 4270.It Sy M-[ Ns Ar letter 4271Soft key. 4272Search the alias list for an alias by the name 4273.Ar letter . 4274If an alias of this name is defined, insert its value on the input queue. 4275This can be used to program function keys on many terminals. 4276.It Sy M-\&. 4277The last word of the previous command is inserted on the line. 4278If preceded by a numeric parameter, the value of this parameter determines 4279which word to insert rather than the last word. 4280.It Sy M-_ 4281Same as 4282.Sy M-\&. . 4283.It Sy M-* 4284Attempt filename generation on the current word. 4285As asterisk is appended if the word does not match any file or contain any 4286special pattern characters. 4287.It Sy M-ESC 4288Command or file name completion as described in this manual page. 4289.It Sy ^I Pq TAB 4290Attempts command or file name completion as described in this manual page. 4291If a partial completion occurs, repeating this behaves as if 4292.Sy M-= 4293were entered. 4294If no match is found or entered after SPACE, a TAB is inserted. 4295.It Sy M-= 4296If not preceded by a numeric parameter, generates the list of matching commands 4297or file names as described in this manual page. 4298Otherwise, the word under the cursor is replaced by the item corresponding to 4299the value of the numeric parameter from the most recently generated command or 4300file list. 4301If the cursor is not on a word, the word is inserted instead. 4302.It Sy ^U 4303Multiply parameter of next command by 4304.Sy 4 . 4305.It Sy \e 4306Escape the next character. 4307Editing characters, the user's erase, kill and interrupt 4308.Pq normally Sy ^? 4309characters can be entered in a command line or in a search string if preceded 4310by a 4311.Sy \e . 4312The 4313.Sy \e 4314removes the next character's editing features, if any. 4315.It Sy M-^V 4316Display the version of the shell. 4317.It Sy M-# 4318If the line does not begin with a 4319.Sy # , 4320a 4321.Sy # 4322is inserted at the beginning of the line and after each NEWLINE, and the line 4323is entered. 4324This causes a comment to be inserted in the history file. 4325If the line begins with a 4326.Sy # , 4327the 4328.Sy # 4329is deleted and one 4330.Sy # 4331after each NEWLINE is also deleted. 4332.El 4333.Ss vi Editing Mode 4334There are two typing modes. 4335Initially, when you enter a command you are in the input mode. 4336To edit, the user enters control mode by typing ESC (033) and moves the cursor 4337to the point needing correction and then inserts or deletes characters or words 4338as needed. 4339Most control commands accept an optional repeat 4340.Ar count 4341prior to the command. 4342.Pp 4343When in vi mode on most systems, canonical processing is initially enabled and 4344the command is echoed again if the speed is 1200 baud or greater and it 4345contains any control characters or less than one second has elapsed since the 4346prompt was printed. 4347The ESC character terminates canonical processing for the remainder of the 4348command and the user can then modify the command line. 4349This scheme has the advantages of canonical processing with the type-ahead 4350echoing of raw mode. 4351.Pp 4352If the option 4353.Sy viraw 4354is also set, the terminal is always have canonical processing disabled. 4355This mode is implicit for systems that do not support two alternate end of line 4356delimiters, and might be helpful for certain terminals. 4357.Ss "Input Edit Commands" 4358By default the editor is in input mode. 4359.Pp 4360The following input edit commands are supported: 4361.Bl -tag -width Ds 4362.It Sy ERASE 4363User defined erase character as defined by the 4364.Xr stty 1 4365command, usually 4366.Sy ^H 4367or 4368.Sy # . 4369Delete previous character. 4370.It Sy ^W 4371Delete the previous blank separated word. 4372On some systems the 4373.Sy viraw 4374option might be required for this to work. 4375.It Sy EOF 4376As the first character of the line causes the shell to terminate unless the 4377.Sy ignoreeof 4378option is set. 4379Otherwise this character is ignored. 4380.It Ar lnext 4381User defined literal next character as defined by 4382.Xr stty 1 4383or 4384.Sy ^V 4385if not defined. 4386Removes the next character's editing features, if any. 4387On some systems the 4388.Sy viraw 4389option might be required for this to work. 4390.It Sy \e 4391Escape the next ERASE or KILL character. 4392.It Sy ^I Pq TAB 4393Attempts command or file name completion as described in this manual page and 4394returns to input mode. 4395If a partial completion occurs, repeating this behaves as if 4396.Sy \&= 4397were entered from control mode. 4398If no match is found or entered after SPACE, a TAB is inserted. 4399.El 4400.Ss "Motion Edit Commands" 4401The motion edit commands move the cursor. 4402.Pp 4403The following motion edit commands are supported: 4404.Bl -tag -width Ar 4405.It Oo Ar count Oc Ns Sy l 4406Move the cursor forward (right) one character. 4407.It Oo Ar count Oc Ns Sy [C 4408Move the cursor forward (right) one character. 4409.It Oo Ar count Oc Ns Sy w 4410Move the cursor forward one alphanumeric word. 4411.It Oo Ar count Oc Ns Sy W 4412Move the cursor to the beginning of the next word that follows a blank. 4413.It Oo Ar count Oc Ns Sy e 4414Move the cursor to the end of the word. 4415.It Oo Ar count Oc Ns Sy E 4416Move the cursor to the end of the current blank delimited word. 4417.It Oo Ar count Oc Ns Sy h 4418Move the cursor backward (left) one character. 4419.It Oo Ar count Oc Ns Sy [D 4420Move the cursor backward (left) one character. 4421.It Oo Ar count Oc Ns Sy b 4422Move the cursor backward one word. 4423.It Oo Ar count Oc Ns Sy B 4424Move the cursor to the preceding blank separated word. 4425.It Oo Ar count Oc Ns Sy \&| 4426Move the cursor to column 4427.Ar count . 4428.It Oo Ar count Oc Ns Sy f Ns Ar c 4429Find the next character 4430.Ar c 4431in the current line. 4432.It Oo Ar count Oc Ns Sy F Ns Ar c 4433Find the previous character 4434.Ar c 4435in the current line. 4436.It Oo Ar count Oc Ns Sy f Ns Ar c 4437Equivalent to 4438.Sy f 4439followed by 4440.Sy h . 4441.It Oo Ar count Oc Ns Sy T Ns Ar c 4442Equivalent to 4443.Sy F 4444followed by 4445.Sy l . 4446.It Oo Ar count Oc Ns Sy \&; 4447Repeat 4448.Ar count 4449times the last single character find command: 4450.Sy f , 4451.Sy F , 4452.Sy t , 4453or 4454.Sy T . 4455.It Oo Ar count Oc Ns Sy \&, 4456Reverse the last single character find command 4457.Ar count 4458times. 4459.It Sy 0 Pq No zero 4460Move the cursor to the start of line. 4461.It Sy \&^ 4462Move the cursor to the first non-blank character in the line. 4463.It Sy [H 4464Move the cursor to the first non-blank character in the line. 4465.It Sy \&$ 4466Move the cursor to the end of the line. 4467.It Sy [Y 4468Move the cursor to the end of the line. 4469.It Sy \&% 4470Moves to the balancing 4471.Sy \&( , 4472.Sy \&) , 4473.Sy \&{ , 4474.Sy \&} , 4475.Sy \&[ , 4476or 4477.Sy \&] . 4478If cursor is not on one of the characters described in this section, the 4479remainder of the line is searched for the first occurrence of one of the 4480characters first. 4481.El 4482.Ss "Search Edit Commands" 4483The search edit commands access your command history. 4484.Pp 4485The following search edit commands are supported: 4486.Bl -tag -width Ar 4487.It Oo Ar count Oc Ns Sy k 4488Fetch the previous command. 4489Each time 4490.Sy k 4491is entered, the previous command back in time is accessed. 4492.It Oo Ar count Oc Ns Sy \&- 4493Fetch the previous command. 4494Each time 4495.Sy \&- 4496is entered, the previous command back in time is accessed. 4497Equivalent to 4498.Sy k . 4499.It Oo Ar count Oc Ns Sy [A 4500Fetch the previous command. 4501Each time 4502.Sy [A 4503is entered, the previous command back in time is accessed. 4504Equivalent to 4505.Sy k . 4506.It Oo Ar count Oc Ns Sy j 4507Fetch the next command. 4508Each time 4509.Sy j 4510is entered, the next command forward 4511in time is accessed. 4512.It Oo Ar count Oc Ns Sy \&+ 4513Fetch the next command. 4514Each time 4515.Sy \&+ 4516is entered, the next command forward in time is accessed. 4517Equivalent to 4518.Sy j . 4519.It Oo Ar count Oc Ns Sy [B 4520Fetch the next command. 4521Each time 4522.Sy [B 4523is entered, the next command forward in time is accessed. 4524Equivalent to 4525.Sy j . 4526.It Oo Ar count Oc Ns Sy G 4527Fetch command number 4528.Ar count . 4529The default is the least recent history command. 4530.It Sy / Ns Ar string 4531Search backward through history for a previous command containing 4532.Ar string . 4533.Ar string 4534is terminated by a RETURN or NEWLINE. 4535If string is preceded by a 4536.Sy ^ , 4537the matched line must begin with 4538.Ar string . 4539If 4540.Ar string 4541is null, the previous string is used. 4542.It Sy \&? Ns Ar string 4543Search forward through history for a previous command containing 4544.Ar string . 4545.Ar string 4546is terminated by a RETURN or NEWLINE. 4547If string is preceded by a 4548.Sy ^ , 4549the matched line must begin with 4550.Ar string . 4551If 4552.Ar string 4553is null, the previous string is used. 4554.Pp 4555Same as 4556.Sy / 4557except that search is in the forward direction. 4558.It Sy n 4559Search in the backwards direction for the next match of the last pattern to 4560.Sy / 4561or 4562.Sy \&? 4563commands. 4564.It Sy N 4565Search in the forward direction for next match of the last pattern to 4566.Sy / 4567or 4568.Sy \&? 4569commands. 4570.El 4571.Ss "Text Modification Edit Commands" 4572The following commands modify the line: 4573.Pp 4574.Bl -tag -width Ar -compact 4575.It Sy a 4576Enter input mode and enter text after the current character. 4577.Pp 4578.It Sy A 4579Append text to the end of the line. 4580Equivalent to 4581.Sy $a . 4582.Pp 4583.It Oo Ar count Oc Ns Sy c Ns Ar motion 4584.It Sy c Ns Oo Ar count Oc Ns Ar motion 4585Delete current character through to the character that 4586.Ar motion 4587would move the cursor to, and enter input mode. 4588If 4589.Ar motion 4590is 4591.Sy c , 4592the entire line is deleted and input mode is entered. 4593.Pp 4594.It Sy C 4595Delete the current character through to the end of line and enter input mode. 4596Equivalent to 4597.Sy c$ . 4598.Pp 4599.It Sy S 4600Equivalent to 4601.Sy cc . 4602.Pp 4603.It Oo Ar count Oc Ns Sy s 4604Replace characters under the cursor in input mode. 4605.Pp 4606.It Sy D Ns Oo Ar count Oc Ns Sy d Ns Ar motion 4607Delete the current character through to the end of line. 4608Equivalent to 4609.Sy d$ . 4610.Pp 4611.It Sy d Oo Ar count Oc Ns Ar motion 4612Delete current character through to the character that 4613.Ar motion 4614would move to. 4615If 4616.Ar motion 4617is 4618.Sy d , 4619the entire line is deleted. 4620.Pp 4621.It Sy i 4622Enter input mode and insert text before the current character. 4623.Pp 4624.It Sy I 4625Insert text before the beginning of the line. 4626Equivalent to 4627.Sy 0i . 4628.Pp 4629.It Oo Ar count Oc Ns Sy P 4630Place the previous text modification before the cursor. 4631.Pp 4632.It Oo Ar count Oc Ns Sy p 4633Place the previous text modification after the cursor. 4634.Pp 4635.It Sy R 4636Enter input mode and replace characters on the screen with characters you type 4637overlay fashion. 4638.Pp 4639.It Oo Ar count Oc Ns Sy r Ns Ar c 4640Replace the 4641.Ar count 4642characters starting at the current cursor position with 4643.Ar c , 4644and advance the cursor. 4645.Pp 4646.It Oo Ar count Oc Ns Sy x 4647Delete current character. 4648.Pp 4649.It Oo Ar count Oc Ns Sy X 4650Delete preceding character. 4651.Pp 4652.It Oo Ar count Oc Ns Sy \&. 4653Repeat the previous text modification command. 4654.Pp 4655.It Oo Ar count Oc Ns Sy \&~ 4656Invert the case of the 4657.Ar count 4658characters starting at the current cursor 4659position and advance the cursor. 4660.Pp 4661.It Oo Ar count Oc Ns Sy \&_ 4662Causes the 4663.Ar count 4664word of the previous command to be appended and input mode entered. 4665The last word is used if 4666.Ar count 4667is omitted. 4668.Pp 4669.It Sy \&* 4670Causes an 4671.Sy \&* 4672to be appended to the current word and file name generation attempted. 4673If no match is found, it rings the bell. 4674Otherwise, the word is replaced by the matching pattern and input mode is 4675entered. 4676.Pp 4677.It Sy \e 4678Command or file name completion as described in this manual page. 4679.El 4680.Ss "Other Edit Commands" 4681The following miscellaneous edit commands are supported: 4682.Pp 4683.Bl -tag -width Ar -compact 4684.It Oo Ar count Oc Ns Sy y Ns Ar motion 4685.It Sy y Ns Oo Ar count Oc Ns Ar motion 4686Yank the current character through to the character to which 4687.Ar motion 4688would move the cursor. 4689Put the yanked characters in the delete buffer. 4690The text and cursor position are unchanged. 4691.Pp 4692.It Sy yy 4693Yank the current line. 4694.Pp 4695.It Sy Y 4696Yank the current line from the current cursor location to the end of the line. 4697Equivalent to 4698.Sy y$ . 4699.Pp 4700.It Sy u 4701Undo the last text modifying command. 4702.Pp 4703.It Sy U 4704Undo all the text modifying commands performed on current line. 4705.Pp 4706.It Oo Ar count Oc Ns Sy V 4707Return the command: 4708.Pp 4709.D1 Ic hist Fl e No ${ Ns Ev VISUAL Ns :-${ Ns Ev EDITOR Ns :-vi}} Ar count 4710.Pp 4711in the input buffer. 4712If 4713.Ar count 4714is omitted, the current line is used. 4715.Pp 4716.It Sy ^L 4717Line feed and print the current line. 4718This command only works in control mode. 4719.Pp 4720.It Sy ^J 4721New line. 4722Execute the current line, regardless of mode. 4723.Pp 4724.It Sy ^M 4725Return. 4726Execute the current line, regardless of mode. 4727.Pp 4728.It Sy # 4729If the first character of the command is a 4730.Sy # , 4731delete this 4732.Sy # 4733and each 4734.Sy # 4735that follows a NEWLINE. 4736.Pp 4737Otherwise, send the line after inserting a 4738.Sy # 4739in front of each line in the command. 4740.Pp 4741This is command is useful for causing the current line to be inserted in the 4742history as a comment and un-commenting previously commented commands in the 4743history file. 4744.Pp 4745.It Oo Ar count Oc Ns Sy \&= 4746If 4747.Ar count 4748is not specified, generate the list of matching commands or file names as 4749described in this manual page. 4750.Pp 4751Otherwise, replace the word at the current cursor location with the 4752.Ar count 4753item from the most recently generated command or file list. 4754If the cursor is not on a word, it is inserted after the current cursor 4755location. 4756.Pp 4757.It Sy @ Ns Ar letter 4758Search your alias list for an alias by the name 4759.Ar letter . 4760If an alias of this name is defined, insert its value on the input queue for 4761processing. 4762.Pp 4763.It Sy ^V 4764Display version of the shell. 4765.El 4766.Ss "Built-in Commands" 4767The following simple-commands are executed in the shell process. 4768Input and output redirection is permitted. 4769Unless otherwise indicated, the output is written on file descriptor 4770.Sy 1 4771and the exit status, when there is no syntax error, is 4772.Sy 0 . 4773Except for 4774.Sy \&: , 4775.Sy true , 4776.Sy false , 4777.Sy echo , 4778.Sy newgrp , 4779and 4780.Sy login , 4781all built-in commands accept 4782.Fl - 4783to indicate the end of options. 4784They also interpret the option 4785.Fl -man 4786as a request to display the manual page onto standard error and 4787.Fl \&? 4788as a help request which prints a usage message on standard error. 4789.Pp 4790In the list below, commands that are preceded by one or two 4791.Sy \&+ 4792symbols are special built-in commands and are treated specially in the 4793following ways: 4794.Bl -enum -offset Ds 4795.It 4796Variable assignment lists preceding the command remain in effect when the 4797command completes. 4798.It 4799I/O redirections are processed after variable assignments. 4800.It 4801Errors cause a script that contains them to abort. 4802.It 4803They are not valid function names. 4804.It 4805Words following a command preceded by 4806.Sy ++ 4807that are in the format of a variable assignment are expanded with the same 4808rules as a variable assignment. 4809This means that tilde substitution is performed after the 4810.Sy \&= 4811sign and field splitting and file name generation are not performed. 4812.El 4813.Pp 4814.Bl -tag -width Ds -compact 4815.It Sy + Ic \&: Op Ar arg No ... 4816The command only expands parameters. 4817.Pp 4818.It Sy + Ic \&. Ar name Op Ar arg No ... 4819If 4820.Ar name 4821is a function defined with the 4822.Ic function Ar name 4823reserved word syntax, the function is executed in the current environment 4824.Pq as if it had been defined with the Ar name Ns Sy () No syntax . 4825Otherwise if 4826.Ar name 4827refers to a file, the file is read in its entirety and the commands are 4828executed in the current shell environment. 4829The search path specified by 4830.Ev PATH 4831is used to find the directory containing the file. 4832If any arguments 4833.Ar arg 4834are specified, they become the positional parameters while processing the 4835.Ic \&. 4836command and the original positional parameters are restored upon completion. 4837Otherwise the positional parameters are unchanged. 4838The exit status is the exit status of the last command executed. 4839.Pp 4840.It Sy ++ Ic alias Oo Fl ptx Oc Oo Ar name Ns Oo Sy = Ns Ar value Oc Oc No ... 4841.Ic alias 4842with no arguments prints the list of aliases in the form 4843.Ar name Ns Sy = Ns Ar value 4844on standard output. 4845The 4846.Fl p 4847option causes the word alias to be inserted before each one. 4848When one or more arguments are specified, an alias is defined for each 4849.Ar name 4850whose 4851.Ar value 4852is specified. 4853A trailing space in 4854.Ar value 4855causes the next word to be checked for alias substitution. 4856The obsolete 4857.Fl t 4858option is used to set and list tracked aliases. 4859The value of a tracked alias is the full pathname corresponding to the 4860specified 4861.Ar name . 4862The value becomes undefined when the value of 4863.Ev PATH 4864is reset but the alias remains tracked. 4865Without the 4866.Fl t 4867option, for each 4868.Ar name 4869in the argument list for which no 4870.Ar value 4871is specified, the name and value of the alias is printed. 4872The obsolete 4873.Fl x 4874option has no effect. 4875The exit status is 4876.Sy non-zero 4877if a 4878.Ar name 4879is specified, but no value, and no alias has been defined for the 4880.Ar name . 4881.Pp 4882.It Ic bg Op Ar job No ... 4883This command is only on systems that support job control. 4884Puts each specified 4885.Ar job 4886into the background. 4887The current job is put in the background if 4888.Ar job 4889is not specified. 4890See the 4891.Sx Jobs 4892section of this manual page for a description of the format of 4893.Ar job . 4894.Pp 4895.It Sy + Ic break Op Ar n 4896Exit from the enclosing 4897.Ic for , 4898.Ic while , 4899.Ic until , 4900or 4901.Ic select 4902loop, if any. 4903If 4904.Ar n 4905is specified, then break 4906.Ar n 4907levels. 4908.Pp 4909.It Ic builtin Oo Fl ds Oc Oo Fl f Ar file Oc Oo Ar name No ... Oc 4910If 4911.Ar name 4912is not specified, and no 4913.Fl f 4914option is specified, the built-ins are printed on standard output. 4915The 4916.Fl s 4917option prints only the special built-ins. 4918Otherwise, each 4919.Ar name 4920represents the pathname whose basename is the name of the built-in. 4921The entry point function name is determined by prepending 4922.Ar b_ 4923to the built-in name. 4924A built-in specified by a pathname will only be executed when that pathname 4925would be found during the path search. 4926Built-ins found in libraries loaded via the 4927.Pa \&.paths 4928file will be associated with the pathname of the directory containing the 4929.Pa \&.paths 4930file. 4931.Pp 4932The ISO C/C++ prototype is 4933.Ft int 4934.Fo b_mycommand 4935.Fa "int argc" 4936.Fa "char **argv" 4937.Fa "Shbltin_t *context" 4938.Fc 4939for the built-in command 4940.Ic mycommand 4941where 4942.Fa argv 4943is an array of 4944.Fa argc 4945elements and 4946.Fa context 4947is an optional pointer to a 4948.Vt Shbltin_t 4949structure as described in 4950.In ast/shell.h 4951Special built-ins cannot be bound to a pathname or deleted. 4952The 4953.Fl d 4954option deletes each of the specified built-ins. 4955On systems that support dynamic loading, the 4956.Fl f 4957option names a shared library containing the code for built-ins. 4958The shared library prefix and/or suffix, which depend on the system, can be 4959omitted. 4960Once a library is loaded, its symbols become available for subsequent 4961invocations of 4962.Ic builtin . 4963Multiple libraries can be specified with separate invocations of the 4964.Ic builtin 4965command. 4966Libraries are searched in the reverse order in which they are specified. 4967When a library is loaded, it looks for a function in the library whose name is 4968.Fn lib_init 4969and invokes this function with an argument of 4970.Sy 0 . 4971.Pp 4972.It Ic cd Oo Fl LP Oc Op Ar arg 4973.It Ic cd Oo Fl LP Oc Ar old Ar new 4974This command has two forms. 4975.Pp 4976In the first form it changes the current directory to 4977.Ar arg . 4978If 4979.Ar arg 4980is a literal 4981.Sy \&- , 4982the directory is changed to the previous directory. 4983The shell variable 4984.Ev HOME 4985is the default 4986.Ar arg . 4987The variable 4988.Ev PWD 4989is set to the current directory. 4990The shell variable 4991.Ev CDPATH 4992defines the search path for the directory containing 4993.Ar arg . 4994Alternative directory names are 4995separated by a colon 4996.Pq Sy \&: . 4997The default path is 4998.Dv NULL 4999(specifying the current directory). 5000The current directory is specified by a null path name, which can appear 5001immediately after the equal sign or between the colon delimiters anywhere else 5002in the path list. 5003If 5004.Ar arg 5005begins with a 5006.Sy / , 5007the search path is not used. 5008Otherwise, each directory in the path is searched for 5009.Ar arg . 5010.Pp 5011The second form of 5012.Ic cd 5013substitutes the string 5014.Ar new 5015for the string 5016.Ar old 5017in the current directory name, 5018.Ev PWD , 5019and tries to change to this new directory. 5020.Pp 5021By default, symbolic link names are treated literally when finding the 5022directory name. 5023This is equivalent to the 5024.Fl L 5025option. 5026The 5027.Fl P 5028option causes symbolic links to be resolved when determining the directory. 5029The last instance of 5030.Fl L 5031or 5032.Fl P 5033on the command line determines which method is used. 5034The 5035.Ic cd 5036command cannot be executed by 5037.Nm rksh93 . 5038.Pp 5039.It Ic command Oo Fl pvVx Oc Ar name Op Ar arg No ... 5040Without the 5041.Fl v 5042or 5043.Fl V 5044options, executes 5045.Ar name 5046with the arguments specified by 5047.Ar arg . 5048.Pp 5049The 5050.Fl p 5051option causes a default path to be searched rather than the one defined by the 5052value of 5053.Ev PATH . 5054Functions are not searched when finding 5055.Ar name . 5056In addition, if 5057.Ar name 5058refers to a special built-in, none of the special properties associated with 5059the leading daggers are honored. 5060For example, the predefined alias 5061.Sy redirect='command exec' 5062prevents a script from terminating when an invalid redirection is specified. 5063.Pp 5064With the 5065.Fl x 5066option, if command execution would result in a failure because there are too 5067many arguments, 5068.Er E2BIG , 5069the shell invokes command 5070.Ar name 5071multiple times with a subset of the arguments on each invocation. 5072Arguments that occur prior to the first word that expands to multiple arguments 5073and after the last word that expands to multiple arguments are passed on each 5074invocation. 5075The exit status is the maximum invocation exit status. 5076.Pp 5077With the 5078.Fl v 5079option, 5080.Ic command 5081is equivalent to the built-in 5082.Ic whence 5083command described in this section. 5084The 5085.Fl V 5086option causes 5087.Ic command 5088to act like 5089.Ic whence -v . 5090.Pp 5091.It Sy + Ic continue Op Ar n 5092Resumes the next iteration of the enclosing 5093.Ic for , 5094.Ic while , 5095.Ic until , 5096or 5097.Ic select 5098loop. 5099If 5100.Ar n 5101is specified, then resume at the 5102.Ar n Ns No th 5103enclosing loop. 5104.Pp 5105.It Ic disown Op Ar job No ... 5106Causes the shell not to send a 5107.Sy HUP 5108signal to each specified 5109.Ar job , 5110or all active jobs if 5111.Ar job 5112is omitted, when a login shell terminates. 5113.Pp 5114.It Ic echo Op arg No ... 5115When the first 5116.Ar arg 5117does not begin with a 5118.Sy - , 5119and none of the arguments contain a backslash 5120.Pq Sy \e , 5121prints each of its arguments separated by a SPACE and terminated by a NEWLINE. 5122Otherwise, the behavior of 5123.Ic echo 5124is system dependent and 5125.Ic print 5126or 5127.Ic printf 5128described in this section should be used. 5129See 5130.Xr echo 1 5131for usage and description. 5132.Pp 5133.It Sy ++ Ic enum Oo Fl i Oc Ar type Ns Op Sy =( Ns Ar value No ... Ns Sy \&) 5134Creates a declaration command named type that is an integer type that allows 5135one of the specified values as enumeration names. 5136If 5137.Sy =( Ns Ar value No ... Ns Sy \&) 5138is omitted, then type must be an indexed array variable with at least two 5139elements and the values are taken from this array variable. 5140If 5141.Fl i 5142is specified the values are case insensitive. 5143.Pp 5144.It Sy + Ic eval Op arg No ... 5145The arguments are read as input to the shell and the resulting commands are 5146executed. 5147.Pp 5148.It Sy + Ic exec Oo Fl c Oc Oo Fl a Ar name No ... Oc Op Ar arg No ... 5149If 5150.Ar arg 5151is specified, the command specified by the arguments is executed in place of 5152this shell without creating a new process. 5153The 5154.Fl c 5155option causes the environment to be cleared before applying variable 5156assignments associated with the exec invocation. 5157The 5158.Fl a 5159option causes 5160.Ar name 5161rather than the first 5162.Ar arg , 5163to become 5164.Fa argv[0] 5165for the new process. 5166Input and output arguments can appear and affect the current process. 5167If 5168.Ar arg 5169is not specified, the effect of this command is to modify file descriptors as 5170prescribed by the input/output redirection list. 5171In this case, any file descriptor numbers greater than 5172.Sy 2 5173that are opened with this mechanism are closed when invoking another program. 5174.Pp 5175.It Sy + Ic exit Op Ar n 5176Causes the shell to exit with the exit status specified by 5177.Ar n . 5178The value is the least significant 8 bits of the specified status. 5179If 5180.Ar n 5181is omitted, then the exit status is that of the last command executed. 5182An end-of-file also causes the shell to exit except for a shell which has the 5183.Sy ignoreeof 5184option turned on. 5185See 5186.Ic set . 5187.Pp 5188.It Sy ++ Ic export Oo Fl p Oc Oo Ar name Ns Oo Sy = Ns Ar value Oc Oc No ... 5189If 5190.Ar name 5191is not specified, the names and values of each variable with the export 5192attribute are printed with the values quoted in a manner that allows them to be 5193re-entered. 5194The 5195.Ic export 5196command is the same as 5197.Ic typeset -x 5198except that if you use 5199.Ic export 5200within a function, no local variable is created. 5201The 5202.Fl p 5203option causes the word export to be inserted before each one. 5204Otherwise, the specified 5205.Ar name 5206s are marked for automatic export to the environment of subsequently-executed 5207commands. 5208.Pp 5209.It Ic false 5210Does nothing, and exits 5211.Sy 1 . 5212Used with 5213.Ic until 5214for infinite loops. 5215.Pp 5216.It Ic fg Op Ar job No ... 5217This command is only on systems that support job control. 5218Each 5219.Ar job 5220specified is brought to the foreground and waited for in the specified order. 5221Otherwise, the current job is brought into the foreground. 5222See 5223.Sx Jobs 5224for a description of the format of 5225.Ar job . 5226.Pp 5227.It Ic getconf Oo Ar name Oo Ar pathname Oc Oc 5228Prints the current value of the configuration parameter specified by 5229.Ar name . 5230The configuration parameters are defined by the IEEE POSIX 1003.1 5231and IEEE POSIX 1003.2 standards. 5232See 5233.Xr pathconf 2 5234and 5235.Xr sysconf 3C . 5236.Pp 5237The 5238.Ar pathname 5239argument is required for parameters whose value depends on the location in the 5240file system. 5241If no arguments are specified, 5242.Ic getconf 5243prints the names and values of the current configuration parameters. 5244The pathname 5245.Pa / 5246is used for each of the parameters that requires 5247.Ar pathname . 5248.Pp 5249.It Ic getopts Oo Fl a Ar name Oc Ar optstring Ar vname Op Ar arg No ... 5250Checks 5251.Ar arg 5252for legal options. 5253If 5254.Ar arg 5255is omitted, the positional parameters are used. 5256An option argument begins with a 5257.Sy \&+ 5258or a 5259.Sy \&- . 5260An option that does not begin with 5261.Sy \&+ 5262or 5263.Sy \&- 5264or the argument 5265.Fl \- 5266ends the options. 5267Options beginning with 5268.Sy \&+ 5269are only recognized when 5270.Ar optstring 5271begins with a 5272.Sy \&+ . 5273.Ar optstring 5274contains the letters that 5275.Sy getopts 5276recognizes. 5277If a letter is followed by a 5278.Sy \&: , 5279that option is expected to have an argument. 5280The options can be separated from the argument by blanks. 5281The option 5282.Fl \&? 5283causes 5284.Ic getopts 5285to generate a usage message on standard error. 5286The 5287.Fl a 5288option can be used to specify the name to use for the usage message, which 5289defaults to 5290.Sy $0 . 5291.Ic getopts 5292places the next option letter it finds inside variable 5293.Ar vname 5294each time it is invoked. 5295The option letter is prepended with a 5296.Sy \&+ 5297when 5298.Ar arg 5299begins with a 5300.Sy \&+ . 5301The index of the next 5302.Ar arg 5303is stored in 5304.Ev OPTIND . 5305The option argument, if any, gets stored in 5306.Ev OPTARG . 5307A leading \&: in 5308.Ar optstring 5309causes 5310.Ic getopts 5311to store the letter of an invalid option in 5312.Ev OPTARG , 5313and to set 5314.Ar vname 5315to 5316.Sy \&? 5317for an unknown option and to 5318.Sy \&: 5319when a required option argument is missing. 5320Otherwise, 5321.Ic getopts 5322prints an error message. 5323The exit status is 5324.Sy non-zero 5325when there are no more options. 5326There is no way to specify any of the options 5327.Sy \&: , 5328.Sy \&+ , 5329.Sy \&- , 5330.Sy \&? , 5331.Sy \&[ , 5332and 5333.Sy \&] . 5334The option 5335.Sy \&# 5336can only be specified as the first option. 5337.Pp 5338.It Ic hist Oo Fl e Ar ename Oc Oo Fl nlr Oc Oo Ar first Oo Ar last Oc Oc 5339.It Ic hist Fl s Oo Ar old Ns Sy = Ns Ar new Oc Oo Ar command Oc 5340In the first form, a range of commands from 5341.Ar first 5342to 5343.Ar last 5344is selected from the last 5345.Ev HISTSIZE 5346commands that were typed at the terminal. 5347The arguments 5348.Ar first 5349and 5350.Ar last 5351can be specified as a number or as a string. 5352A string is used to locate the most recent command starting with the 5353specified string. 5354A negative number is used as an offset to the current command number. 5355If the 5356.Fl l 5357option is selected, the commands are listed on standard output. 5358Otherwise, the editor program 5359.Ar ename 5360is invoked on a file containing these keyboard commands. 5361If 5362.Ar ename 5363is not supplied, then the value of the variable 5364.Ev HISTEDIT 5365is used. 5366If 5367.Ev HISTEDIT 5368is not set, then 5369.Ev FCEDIT 5370.Pq default Pa /bin/ed 5371is used as the editor. 5372When editing is complete, the edited command(s) is executed if the changes have 5373been saved. 5374If 5375.Ar last 5376is not specified, then it is set to 5377.Ar first . 5378If 5379.Ar first 5380is not specified, the default is the previous command for editing and 5381.Fl 16 5382for listing. 5383The option 5384.Fl r 5385reverses the order of the commands and the option 5386.Fl n 5387suppresses command numbers when listing. 5388In the second form, 5389.Ar command 5390is interpreted as 5391.Ar first 5392described in this section and defaults to the last command executed. 5393The resulting command is executed after the optional substitution 5394.Ar old Ns Sy = Ns Ar new 5395is performed. 5396.Pp 5397.It Ic jobs Fl lnp Op Ar job No ... 5398Lists information about each specified job, or all active jobs if 5399.Ar job 5400is omitted. 5401The 5402.Fl l 5403option lists process ids in addition to the normal information. 5404The 5405.Fl n 5406option only displays jobs that have stopped or exited since last notified. 5407The 5408.Fl p 5409option causes only the process group to be listed. 5410See 5411.Sx Jobs 5412for a description of the format of 5413.Ar job . 5414.Pp 5415.It Ic kill Oo Fl s Ar signame Oc Ar job No ... 5416.It Ic kill Oo Fl n Ar signum Oc Ar job No ... 5417.It Ic kill Fl Ll Op Ar sig No ... 5418Sends either the 5419.Sy TERM 5420(terminate) signal or the specified signal to the specified jobs or processes. 5421Signals are either specified by number with the 5422.Fl n 5423option or by name with the 5424.Fl s 5425option 5426.Po 5427as specified in 5428.In signal.h , 5429stripped of the prefix 5430.Ql SIG 5431with the exception that 5432.Sy SIGCLD 5433is named 5434.Sy CHLD 5435.Pc . 5436For backwards compatibility, the 5437.Sy n 5438and 5439.Sy s 5440can be omitted and the number or name placed immediately after the 5441.Fl . 5442If the signal being sent is 5443.Sy TERM 5444(terminate) or 5445.Sy HUP 5446(hang up), then the job or process is sent a 5447.Sy CONT 5448(continue) signal if it is stopped. 5449The argument 5450.Ar job 5451can be the process id of a process that is not a member of one of the active 5452jobs. 5453See 5454.Sx Jobs 5455for a description of the format of 5456.Ar job . 5457In the third form, 5458.Ic kill Fl l 5459or 5460.Ic kill Fl L , 5461if 5462.Ar sig 5463is not specified, the signal names are listed. 5464The 5465.Fl l 5466option 5467lists only the signal names whereas 5468.Fl L 5469lists each signal name and corresponding number. 5470Otherwise, for each 5471.Ar sig 5472that is a name, the corresponding signal number is listed. 5473For each 5474.Ar sig 5475that is a number, the signal name corresponding to the least significant 8 bits 5476of 5477.Ar sig 5478is listed. 5479.Pp 5480.It Ic let Op Ar arg No ... 5481Each 5482.Ar arg 5483is a separate arithmetic expression to be evaluated. 5484.Ic let 5485only recognizes octal constants starting with 5486.Sy 0 5487when the 5488.Ic set 5489option 5490.Sy letoctal 5491is on. 5492See the 5493.Sx Arithmetic Evaluation 5494section of this manual page for a description of arithmetic expression 5495evaluation. 5496The exit status is 5497.Sy 0 5498if the value of the last expression is 5499.Sy non-zero , 5500and 5501.Sy 1 5502otherwise. 5503.Pp 5504.It Sy + Ic newgrp Op arg No ... 5505Equivalent to 5506.Ic exec Pa /bin/newgrp Ar arg No ... 5507.Pp 5508.It Xo 5509.Ic print 5510.Op Fl CRenprsv 5511.Op Fl u Ar unit 5512.Op Fl f Ar format 5513.Op Ar arg No ... 5514.Xc 5515With no options or with option 5516.Sy - 5517or 5518.Fl \- , 5519each 5520.Ar arg 5521is printed on standard output. 5522The 5523.Fl f 5524option causes the arguments to be printed as described by 5525.Ic printf . 5526In this case, any 5527.Fl e , 5528.Fl n , 5529.Fl r , 5530or 5531.Fl R 5532options are ignored. 5533Otherwise, unless the 5534.Fl R 5535or 5536.Fl r 5537options are specified, the following escape conventions are applied: 5538.Bl -tag -width Ds 5539.It Sy \ea 5540Alert character 5541.Pq Sy ASCII 007 5542.It Sy \eb 5543Backspace character 5544.Pq Sy ASCII 010 5545.It Sy \ec 5546Causes print to end without processing more arguments and not adding a NEWLINE 5547.It Sy \ef 5548Form-feed character 5549.Pq Sy ASCII 014 5550.It Sy \en 5551NEWLINE character 5552.Pq Sy ASCII 012 5553.It Sy \er 5554RETURN character 5555.Pq Sy ASCII 015 5556.It Sy \et 5557TAB character 5558.Pq Sy ASCII 011 5559.It Sy \ev 5560Vertical TAB character 5561.Pq Sy ASCII 013 5562.It Sy \eE 5563Escape character 5564.Pq Sy ASCII 033 5565.It Sy \e\e 5566Backslash character 5567.Sy \e 5568.It Sy \e0 Ns Ar x 5569Character defined by the 1, 2, or 3-digit octal string specified by 5570.Ar x 5571.El 5572.Pp 5573The 5574.Fl R 5575option prints all subsequent arguments and options other than 5576.Fl n . 5577The 5578.Fl e 5579causes the escape conventions to be applied. 5580This is the default behavior. 5581It reverses the effect of an earlier 5582.Fl r . 5583The 5584.Fl p 5585option causes the arguments to be written onto the pipe of the process spawned 5586with 5587.Sy |& 5588instead of standard output. 5589The 5590.Fl v 5591option treats each 5592.Ar arg 5593as a variable name and writes the value in the 5594.Ic printf Cm \&%B 5595format. 5596The 5597.Fl C 5598option treats each 5599.Ar arg 5600as a variable name and writes the values in the 5601.Ic printf Cm \&%#B 5602format. 5603The 5604.Fl s 5605option causes the arguments to be written onto the history file instead of 5606standard output. 5607The 5608.Fl u 5609option can be used to specify a one digit file descriptor unit number 5610.Ar unit 5611on which the output is placed. 5612The default is 5613.Sy 1 . 5614If the option 5615.Fl n 5616is used, no NEWLINE is added to the output. 5617.Pp 5618.It Ic printf Ar format Op Ar arg No ... 5619The arguments 5620.Ar arg 5621are printed on standard output in accordance with the 5622.Sy ANSI-C 5623formatting rules associated with the format string 5624.Ar format . 5625If the number of arguments exceeds the number of format specifications, the 5626format string is reused to format remaining arguments. 5627The following extensions can also be used: 5628.Bl -tag -width Ds 5629.It Sy %b 5630A 5631.Sy %b 5632format can be used instead of 5633.Sy %s 5634to cause escape sequences in the corresponding 5635.Ar arg 5636to be expanded as described in 5637.Ic print . 5638.It Sy \&%B 5639A 5640.Sy \&%B 5641option causes each of the arguments to be treated as variable names and the 5642binary value of the variables is printed. 5643This is most useful for variables with an attribute of b. 5644.It Sy \&%H 5645A 5646.Sy \&%H 5647format can be used instead of 5648.Sy %s 5649to cause characters in 5650.Ar arg 5651that are special in 5652.Sy HTML 5653and 5654.Sy XML 5655to be output as their entity name. 5656The alternate flag 5657.Sy # 5658formats the output for use as a URI. 5659.It Sy \&%P 5660A 5661.Sy \&%P 5662format can be used instead of 5663.Sy \&%s 5664to cause 5665.Ar arg 5666to be interpreted as an extended regular expression and be printed as a shell 5667pattern. 5668.It Sy \&%R 5669A 5670.Sy \&%R 5671format can be used instead of 5672.Sy \&%s 5673to cause 5674.Ar arg 5675to be interpreted as a shell pattern and to be printed as an extended regular 5676expression. 5677.It Sy \&%q 5678A 5679.Sy \&%q 5680format can be used instead of 5681.Sy \&% 5682s to cause the resulting string to be quoted in a manner than can be input 5683again to the shell. 5684When 5685.Sy q 5686is preceded by the alternative format specifier, 5687.Sy # , 5688the string is quoted in manner suitable for a field in a 5689.Sy .csv 5690format file. 5691.It Sy \&% Ns Oo Sy \&( Ns Ar date-format Ns Sy \&) Oc Ns Sy T 5692A 5693.Sy \&% Ns Oo Sy \&( Ns Ar date-format Ns Sy \&) Oc Ns Sy T 5694format can be used to treat an argument as a date/time string and to format the 5695date/time according to the 5696.Ar date-format 5697as defined for the 5698.Xr date 1 5699command. 5700For example, 5701.Sq printf '%(%s)T' now 5702would print the current time in UNIX timestamp format 5703.Pq seconds since 00:00:00 UTC, January 1, 1970 . 5704.It Sy %Z 5705A 5706.Sy %Z 5707format outputs a byte whose value is 0. 5708.It Sy %d 5709The precision field of the %d format can be followed by a \&. and the output 5710base. 5711In this case, the 5712.Sy # 5713flag character causes 5714.Sy base Ar # 5715to be prepended. 5716.It Sy # 5717The 5718.Sy # 5719flag, when used with the 5720.Sy %d 5721format without an output base, displays the output in powers of 1000 indicated 5722by one of the following suffixes: 5723.Sy k M G T P E , 5724and when used with the 5725.Sy %i 5726format displays the output in powers of 1024 indicated by one of the following 5727suffixes: 5728.Sy Ki Mi Gi Ti Pi Ei . 5729.It Sy = 5730The 5731.Sy = 5732flag centers the output within the specified field width. 5733.It Sy L 5734The 5735.Sy L 5736flag, when used with the 5737.Sy %c 5738or 5739.Sy %s 5740formats, treats precision as character width instead of byte count. 5741.It Sy \&, 5742The 5743.Sy \&, 5744flag, when used with the 5745.Sy %d 5746or 5747.Sy %f 5748formats, separates groups of digits with the grouping delimiter 5749.Po Sq Sy \&, 5750in groups of 3 in the C locale 5751.Pc . 5752.El 5753.Pp 5754.It Ic pwd Op Fl LP 5755Outputs the value of the current working directory. 5756The 5757.Fl L 5758option is the default. 5759It prints the logical name of the current directory. 5760If the 5761.Fl P 5762option is specified, all symbolic links are resolved from the name. 5763The last instance of 5764.Fl L 5765or 5766.Fl P 5767on the command line determines which method is used. 5768.Pp 5769.It Xo 5770.Bk -words 5771.Ic read Op Fl ACSprsv 5772.Op Fl d Ar delim 5773.Op Fl n Ar n | Fl N Ar n 5774.Op Fl t Ar timeout 5775.Op Fl u Ar unit 5776.Op Ar vname Ns Sy \&? Ns Ar prompt 5777.Op Ar name No ... 5778.Ek 5779.Xc 5780.Pp 5781The shell input mechanism. 5782One line is read and is broken up into fields using the characters in 5783.Ev IFS 5784as separators. 5785The escape character, 5786.Sy \e , 5787is used to remove any special meaning for the next character and for line 5788continuation. 5789The 5790.Fl d 5791option causes the read to continue to the first character of 5792.Ar delim 5793rather than NEWLINE. 5794The 5795.Fl n 5796option causes at most 5797.Ar n 5798bytes to read rather a full line but returns when reading from a slow device as 5799soon as any characters have been read. 5800The 5801.Fl N 5802option causes exactly 5803.Ar n 5804to be read unless an end-of-file has been encountered or the read times out 5805because of the 5806.Fl t 5807option. 5808In raw mode, 5809.Fl r , 5810the 5811.Sy \e 5812character is not treated specially. 5813The first field is assigned to the first 5814.Ar vname , 5815the second field to the second 5816.Ar vname , 5817etc., with leftover fields assigned to the last 5818.Ar vname . 5819When 5820.Ar vname 5821has the binary attribute and 5822.Fl n 5823or 5824.Fl N 5825is specified, the bytes that are read are stored directly into the variable. 5826If 5827.Fl v 5828is specified, then the value of the first 5829.Ar vname 5830is used as a default value when reading from a terminal device. 5831The 5832.Fl A 5833option causes the variable 5834.Ar vname 5835to be unset and each field that is read to be stored in successive elements of 5836the indexed array 5837.Ar vname . 5838The 5839.Fl C 5840option causes the variable vname to be read as a compound variable. 5841Blanks will be ignored when finding the beginning open parenthesis. 5842The 5843.Fl S 5844option causes the line to be treated like a record in a .csv format file so 5845that double quotes can be used to allow the delimiter character and the 5846new-line character to appear within a field. 5847The 5848.Fl p 5849option causes the input line to be taken from the input pipe of a process 5850spawned by the shell using 5851.Sy |& . 5852If the 5853.Fl s 5854option is present, the input is saved as a command in the history file. 5855The option 5856.Fl u 5857can be used to specify a one digit file descriptor unit 5858.Ar unit 5859to read from. 5860The file descriptor can be opened with the 5861.Ic exec 5862special built-in command. 5863The default value of unit 5864.Ar n 5865is 5866.Sy 0 . 5867The option 5868.Fl t 5869is used to specify a time out in seconds when reading from a terminal or pipe. 5870If 5871.Ar vname 5872is omitted, then 5873.Ev REPLY 5874is used as the default 5875.Ar vname . 5876An end-of-file with the 5877.Fl p 5878option causes cleanup for this process so that another can be spawned. 5879If the first argument contains a 5880.Sy \&? , 5881the remainder of this word is used as a prompt on standard error when the shell 5882is interactive. 5883The exit status is 5884.Sy 0 5885unless an end-of-file is encountered or read has timed out. 5886.Pp 5887.It Xo 5888.Sy ++ Ic readonly 5889.Op Fl p 5890.Oo Ar vname Ns Oo Sy = Ns Ar value Oc Oc ... 5891.Xc 5892If 5893.Ar vname 5894is not specified, the names and values of each variable with the read-only 5895attribute is printed with the values quoted in a manner that allows them to be 5896input again. 5897The 5898.Fl p 5899option causes the word 5900.Ic readonly 5901to be inserted before each one. 5902Otherwise, the specified 5903.Ar vname Ns No s 5904are marked 5905.Ic readonly 5906and these names cannot be changed by subsequent assignment. 5907.Pp 5908.It Sy + Ic return Op Ar n 5909Causes a shell function or script to return to the invoking script with the 5910exit status specified by 5911.Ar n . 5912The value is the least significant 8 bits of the specified status. 5913If 5914.Sy n 5915is omitted, then the return status is that of the last command executed. 5916If return is invoked while not in a function or a script, then it behaves the 5917same as exit. 5918.Pp 5919.It Xo 5920.Sy + Ic set 5921.Op Sy + Ns Fl BCGabefhkmnoprstuvx 5922.Oo Sy + Ns Fl o Oo Ar option Oc Oc ... 5923.Op Sy + Ns Fl A Ar vname 5924.Op Ar arg No ... 5925.Xc 5926The 5927.Ic set 5928command supports the following options: 5929.Bl -tag -width Ds 5930.It Fl a 5931All subsequent variables that are defined are automatically exported. 5932.It Fl A 5933Array assignment. 5934Unset the variable 5935.Ar vname 5936and assign values sequentially from the 5937.Ar arg 5938list. 5939If 5940.Sy +A 5941is used, the variable 5942.Ar vname 5943is not unset first. 5944.It Fl b 5945Prints job completion messages as soon as a background job changes state rather 5946than waiting for the next prompt. 5947.It Fl B 5948Enable brace pattern field generation. 5949This is the default behavior. 5950.It Fl C 5951Prevents redirection 5952.Pq Sy \&> 5953from truncating existing files. 5954Files that are created are opened with the 5955.Sy O_EXCL 5956mode. 5957Requires 5958.Sy >| 5959to truncate a file when turned on. 5960.It Fl e 5961Unless contained in a 5962.Sy || 5963or 5964.Sy && 5965command, or the command following an 5966.Ic if , 5967.Ic while 5968or 5969.Ic until 5970command or in the pipeline following 5971.Sy \&! , 5972if a command has a non-zero exit status, execute the 5973.Sy ERR 5974trap, if set, and exit. 5975This mode is disabled while reading profiles. 5976.It Fl f 5977Disables file name generation. 5978.It Fl G 5979Causes the pattern 5980.Sy \&** 5981by itself to match files and zero or more directories and subdirectories when 5982used for file name generation. 5983If followed by a 5984.Sy / 5985only directories and subdirectories are matched. 5986.It Fl h 5987Each command becomes a tracked alias when first encountered. 5988.It Fl k 5989Obsolete. 5990All variable assignment arguments are placed in the environment for a command, 5991not just those that precede the command name. 5992.It Fl m 5993Background jobs run in a separate process group and a line prints upon 5994completion. 5995The exit status of background jobs is reported in a completion message. 5996On systems with job control, this option is turned on automatically for 5997interactive shells. 5998.It Fl n 5999Read commands and check them for syntax errors, but do not execute them. 6000Ignored for interactive shells. 6001.It Fl o 6002If no option name is supplied, the list of options and their current settings 6003are written to standard output. 6004When invoked with a 6005.Sy \&+ , 6006the options are written in a format that can be input again to the shell to 6007restore the settings. 6008This option can be repeated to enable or disable multiple options. 6009.Pp 6010The following argument can be one of the following option names: 6011.Bl -tag -width Ar 6012.It Cm allexport 6013Same as 6014.Fl a . 6015.It Cm bgnice 6016All background jobs are run at a lower priority. 6017This is the default mode. 6018.It Cm braceexpand 6019Same as 6020.Fl B . 6021.It Cm emacs 6022Puts you in an 6023.Sy emacs 6024style inline editor for command entry. 6025.It Cm errexit 6026Same as 6027.Fl e . 6028.It Cm globstar 6029Same as 6030.Fl G . 6031.It Cm gmacs 6032Puts you in a 6033.Sy gmacs 6034style inline editor for command entry. 6035.It Cm ignoreeof 6036The shell does not exit on end-of-file. 6037The command 6038.Ic exit 6039must be used. 6040.It Cm keyword 6041Same as 6042.Fl k . 6043.It Cm letoctal 6044The 6045.Ic let 6046command allows octal constants starting with 6047.Sy 0 . 6048.It Cm markdirs 6049All directory names resulting from file name generation have a trailing / 6050appended. 6051.It Cm monitor 6052Same as 6053.Fl m . 6054.It Cm multiline 6055The built-in editors use multiple lines on the screen for lines that are longer 6056than the width of the screen. 6057This might not work for all terminals. 6058.It Cm noclobber 6059Same as 6060.Fl C . 6061.It Cm noexec 6062Same as 6063.Fl n . 6064.It Cm noglob 6065Same as 6066.Fl f . 6067.It Cm nolog 6068Do not save function definitions in the history file. 6069.It Cm notify 6070Same as 6071.Fl b . 6072.It Cm nounset 6073Same as 6074.Fl u . 6075.It Cm pipefail 6076A pipeline does not complete until all components of the pipeline have 6077completed, and the return value is the value of the last 6078.Sy non-zero 6079command to fail or zero if no command has failed. 6080.It Cm privileged 6081Same as 6082.Fl p . 6083.It Cm showme 6084When enabled, simple commands or pipelines preceded by a a semicolon 6085.Pq \&; 6086is displayed as if the 6087.Cm xtrace 6088option were enabled but is not executed. 6089Otherwise, the leading 6090.Sy \&; 6091is ignored. 6092.It Cm trackall 6093Same as 6094.Fl h . 6095.It Cm verbose 6096Same as 6097.Fl v . 6098.It Cm vi 6099Puts you in insert mode of a 6100.Sy vi 6101style inline editor until you hit the escape character 033. 6102This puts you in control mode. 6103A return sends the line. 6104.It Cm viraw 6105Each character is processed as it is typed in 6106.Sy vi 6107mode. 6108.It Cm xtrace 6109Same as 6110.Fl x . 6111.El 6112.Pp 6113If no option name is supplied, the current options settings are printed. 6114.It Fl p 6115Disables processing of the 6116.Pa $HOME/.profile 6117file and uses the file 6118.Pa /etc/suid_profile 6119instead of the 6120.Ev ENV 6121file. 6122This mode is on whenever the effective 6123.Sy uid Pq Sy gid 6124is not equal to the real 6125.Sy uid Pq Sy gid . 6126Turning this off causes the effective 6127.Sy uid 6128and 6129.Sy gid 6130to be set to the real 6131.Sy uid 6132and 6133.Sy gid . 6134.It Fl r 6135Enables the restricted shell. 6136This option cannot be unset once set. 6137.It Fl s 6138Sort the positional parameters lexicographically. 6139.It Fl t 6140Obsolete. 6141Exit after reading and executing one command. 6142.It Fl u 6143Treat 6144.Sy unset 6145parameters as an error when substituting. 6146.It Fl v 6147Print shell input lines as they are read. 6148.It Fl x 6149Print commands and their arguments as they are executed. 6150.It Fl \- 6151Do not change any of the options. 6152This is useful in setting 6153.Sy $1 6154to a value 6155beginning with 6156.Sy \- . 6157If no arguments follow this option then the positional parameters are unset. 6158.El 6159.Pp 6160As an obsolete feature, if the first 6161.Ar arg 6162is 6163.Sy \- 6164then the 6165.Fl x 6166and 6167.Fl v 6168options are turned off and the next 6169.Ar arg 6170is treated as the first argument. 6171Using 6172.Sy \&+ 6173rather than 6174.Fl 6175causes these options to be turned off. 6176These options can also be used upon invocation of the shell. 6177The current set of options can be found in 6178.Sy $- . 6179Unless 6180.Fl A 6181is specified, the remaining arguments are positional parameters and are 6182assigned, in order, to 6183.Sy $1 $2 \&... . 6184If no arguments are specified, then 6185the names and values of all variables are printed on the standard output. 6186.Pp 6187.It Sy + Ic shift Op Ar n 6188The positional parameters from 6189.Sy $ Ns Ar n Ns Sy +1 6190are renamed 6191.Sy $1 \&... , 6192the default 6193.Ar n 6194is 6195.Sy 1 . 6196The parameter 6197.Ar n 6198can be any arithmetic expression that evaluates to a non-negative number less 6199than or equal to 6200.Sy $# . 6201.Pp 6202.It Ic sleep Ar seconds 6203Suspends execution for the number of decimal seconds or fractions of a second 6204specified by 6205.Ar seconds . 6206.Pp 6207.It Sy + Ic trap Oo Fl p Oc Oo Ar action Oc Oo Ar sig Oc ... 6208The 6209.Fl p 6210option causes the trap action associated with each trap as specified by the 6211arguments to be printed with appropriate quoting. 6212Otherwise, 6213.Ar action 6214is processed as if it were an argument to 6215.Ic eval 6216when the shell receives signal(s) 6217.Ar sig . 6218Each 6219.Ar sig 6220can be specified as a number or as the name of the signal. 6221Trap commands are executed in order of signal number. 6222Any attempt to set a trap on a signal that was ignored on entry to the current 6223shell is ineffective. 6224If 6225.Ar action 6226is omitted and the first 6227.Ar sig 6228is a number, or if 6229.Ar action 6230is 6231.Sy - , 6232then the trap(s) for each 6233.Ar sig 6234are reset to their original values. 6235If 6236.Ar action 6237is the null string then this signal is ignored by the shell and by the commands 6238it invokes. 6239If 6240.Ar sig 6241is 6242.Sy ERR 6243then 6244.Ar action 6245is executed whenever a command has a 6246.Sy non-zero 6247exit status. 6248If 6249.Ar sig 6250is 6251.Sy DEBUG 6252then 6253.Ar action 6254is executed before each command. 6255The variable 6256.Sy \&.sh.command 6257contains the contents of the current command line when 6258.Ar action 6259is running. 6260If 6261.Ar sig 6262is 6263.Sy 0 6264or 6265.Sy EXIT 6266and the trap statement is executed inside the body of a function defined with 6267the 6268.Ic function Ar name 6269syntax, then the command 6270.Ar action 6271is executed after the function completes. 6272If 6273.Ar sig 6274is 6275.Sy 0 6276or 6277.Sy EXIT 6278for a trap set outside any function then the command 6279.Ar action 6280is executed on exit from the shell. 6281If 6282.Ar sig 6283is 6284.Sy KEYBD , 6285then 6286.Ar action 6287is executed whenever a key is read while in 6288.Sy emacs , 6289.Sy gmacs , 6290or 6291.Sy vi 6292mode. 6293The 6294.Sy trap 6295command with no arguments prints a list of commands associated with each signal 6296number. 6297.Pp 6298.It Ic true 6299Does nothing, and exits 6300.Sy 0 . 6301Used with while for infinite loops. 6302.Pp 6303.It Xo 6304.Bk -words 6305.Sy ++ Ic typeset 6306.Op Sy + Ns Fl ACHSfblmnprtux 6307.Op Sy + Ns Fl EFLRXZi Ns Op Ar n 6308.Op Sy + Ns Fl M Op Ar mapname 6309.Op Fl T Op Ar tname Ns Sy =( Ns Ar assign_list Ns Sy \&) 6310.Op Fl h Ar str 6311.Op Fl a Op Ar type 6312.Op Ar vname Ns Op Sy = Ns Ar value 6313.Ek 6314.Xc 6315.Pp 6316Sets attributes and values for shell variables and functions. 6317When invoked inside a function defined with the 6318.Sy function Ar name 6319syntax, a new instance of the variable 6320.Ar vname 6321is created, and the variable's value and type are restored when the function 6322completes. 6323.Pp 6324Using 6325.Sy + 6326rather than 6327.Fl 6328causes these options to be turned off. 6329If no 6330.Ar vname 6331arguments are specified, a list of 6332.Ar vname Ns No s 6333.Po and optionally the 6334.Ar value Ns No s 6335.Pc 6336of the variables is printed. 6337Using 6338.Sy + 6339rather than 6340.Fl - 6341keeps the values from being printed. 6342The 6343.Fl p 6344option causes 6345.Ic typeset 6346followed by the option letters to be printed before each name rather than the 6347names of the options. 6348If any option other than 6349.Fl p 6350is specified, only those variables which have all of the specified options are 6351printed. 6352Otherwise, the 6353.Ar vname Ns No s 6354and 6355.Ar attribute Ns No s 6356of all variables that have attributes are printed. 6357.Pp 6358The following list of attributes can be specified: 6359.Bl -tag -width Ds 6360.It Fl a 6361Declares 6362.Ar vname 6363to be an indexed array. 6364This is optional unless except for compound variable assignments. 6365.It Fl A 6366Declares 6367.Ar vname 6368to be an associative array. 6369Sub-scripts are strings rather than arithmetic expressions. 6370.It Fl b 6371The variable can hold any number of bytes of data. 6372The data can be text or binary. 6373The value is represented by the 6374.Sy base64 6375encoding of the data. 6376If 6377.Fl Z 6378is also specified, the size in bytes of the data in the buffer is determined by 6379the size associated with the 6380.Fl Z . 6381If the 6382.Sy base64 6383string assigned results in more data, it is truncated. 6384Otherwise, it is filled with bytes whose value is zero. 6385The 6386.Ic printf 6387format 6388.Cm \&%B 6389can be used to output the actual data in this buffer instead of the 6390.Sy base64 6391encoding of the data. 6392.It Fl C 6393Causes each 6394.Ar vname 6395to be a compound variable. 6396If 6397.Ar value 6398names a compound variable it is copied into 6399.Ar vname . 6400Otherwise, it unsets each 6401.Ar vname . 6402.It Fl E 6403Declares 6404.Ar vname 6405to be a double precision floating point number. 6406If 6407.Ar n 6408is 6409.Sy non-zero , 6410it defines the number of significant figures that are used when expanding 6411.Ar vname . 6412Otherwise, ten significant figures is used. 6413.It Fl f 6414The names refer to function names rather than variable names. 6415No assignments can be made and the only other valid options are 6416.Fl t , 6417.Fl u , 6418and 6419.Fl x . 6420The 6421.Fl t 6422option turns on execution tracing for this function. 6423The 6424.Fl u 6425option causes this function to be marked undefined. 6426The 6427.Ev FPATH 6428variable is searched to find the function definition when the function is 6429referenced. 6430If no options other than 6431.Fl f 6432are specified, then the function definition is displayed on standard output. 6433If 6434.Sy +f 6435is specified, then a line containing the function name followed by a shell 6436comment containing the line number and path name of the file where this 6437function was defined, if any, is displayed. 6438The names refer to function names rather than variable names. 6439No assignments can be made and the only other valid options are 6440.Fl S , 6441.Fl t , 6442.Fl u 6443and 6444.Fl x . 6445The 6446.Fl S 6447option can be used with discipline functions defined in a type to indicate that 6448the function is static. 6449For a static function, the same method will be used by all instances of that 6450type no matter which instance references it. 6451In addition, it can only use value of variables from the original type 6452definition. 6453These discipline functions cannot be redefined in any type instance. 6454The 6455.Fl t 6456option turns on execution tracing for this function. 6457The 6458.Fl u 6459option causes this function to be marked undefined. 6460The 6461.Ev FPATH 6462variable will be searched to find the function definition when the function is 6463referenced. 6464If no options other than 6465.Fl f 6466are specified, then the function definition will be displayed on standard 6467output. 6468If 6469.Sy +f 6470is specified, then a line containing the function name followed by a shell 6471comment containing the line number and path name of the file where this 6472function was defined, if any, is displayed. 6473The exit status can be used to determine whether the function is defined so 6474that 6475.Ic typeset Fl f Sy .sh.math\&. Ns Ar name 6476will return 6477.Sy 0 6478when math function 6479.Ar name 6480is defined and non-zero otherwise. 6481.Pp 6482The 6483.Fl i 6484attribute cannot be specified with 6485.Fl f . 6486.It Fl F 6487Declares 6488.Ar vname 6489to be a double precision floating point number. 6490If 6491.Ar n 6492is 6493.Sy non-zero , 6494it defines the number of places after the decimal point that are used when 6495expanding 6496.Ar vname . 6497Otherwise ten places after the decimal point is used. 6498.It Fl h 6499Used within type definitions to add information when generating information 6500about the sub-variable on the man page. 6501It is ignored when used outside of a type definition. 6502When used with 6503.Fl f 6504the information is associated with the corresponding discipline function. 6505.It Fl H 6506This option provides UNIX to hostname file mapping on non-UNIX machines. 6507.It Fl i 6508Declares 6509.Ar vname 6510to be represented internally as integer. 6511The right hand side of an assignment is evaluated as an arithmetic expression 6512when assigning to an integer. 6513If 6514.Ar n 6515is 6516.Sy non-zero , 6517it defines the output arithmetic base, otherwise the output base is ten. 6518.Pp 6519The 6520.Fl i 6521attribute cannot be specified along with 6522.Fl R , 6523.Fl L , 6524.Fl Z , 6525or 6526.Fl f . 6527.It Fl l 6528Used with 6529.Fl i , 6530.Fl E 6531or 6532.Fl F 6533to indicate long integer, or long float. 6534Otherwise, all upper-case characters are converted to lower-case. 6535The upper-case option, 6536.Fl u , 6537is turned off. 6538Equivalent to 6539.Fl M Cm tolower . 6540.It Fl L 6541Left justify and remove leading blanks from 6542.Ar value . 6543If 6544.Ar n 6545is 6546.Sy non-zero , 6547it defines the width of the field, otherwise it is determined by the width of 6548the value of first assignment. 6549When the variable is assigned to, it is filled on the right with blanks or 6550truncated, if necessary, to fit into the field. 6551The 6552.Fl R 6553option is turned off. 6554.Pp 6555The 6556.Fl i 6557attribute cannot be specified with 6558.Fl L . 6559.It Fl m 6560moves or renames the variable. 6561The value is the name of a variable whose value will be moved to 6562.Ar vname . 6563The original variable will be unset. 6564Cannot be used with any other options. 6565.It Fl M 6566Use the character mapping 6567.Ar mapping 6568such as 6569.Sy tolower 6570and 6571.Sy toupper 6572when assigning a value to each of the specified operands. 6573When 6574.Ar mapping 6575is specified and there are not operands, all variables that use this mapping 6576are written to standard output. 6577When 6578.Ar mapping 6579is omitted and there are no operands, all mapped variables are written to 6580standard output. 6581.It Fl n 6582Declares 6583.Ar vname 6584to be a reference to the variable whose name is defined by the value of 6585variable 6586.Ar vname . 6587This is usually used to reference a variable inside a function whose name has 6588been passed as an argument. 6589.It Fl p 6590The name, attributes and values for the given 6591.Ar vname 6592are written on standard output in a form that can be used as shell input. 6593If 6594.Sy +p 6595is specified, then the values are not displayed. 6596.It Fl R 6597Right justify and fill with leading blanks. 6598If 6599.Ar n 6600is 6601.Sy non-zero , 6602it defines the width of the field, otherwise it is determined by the width of 6603the value of first assignment. 6604The field is left filled with blanks or truncated from the end if the variable 6605is reassigned. 6606The 6607.Fl L 6608option is turned off. 6609.Pp 6610The 6611.Fl i 6612attribute cannot be specified with 6613.Fl R . 6614.It Fl r 6615The specified 6616.Ar vname Ns No s 6617are marked read-only and these names cannot be changed by subsequent 6618assignment. 6619.It Fl S 6620When used within the 6621.Ar assign_list 6622of a type definition, it causes the specified sub-variable to be shared by all 6623instances of the type. 6624When used inside a function defined with the 6625.Ic function 6626reserved word, the specified variables will have 6627.Em function static 6628scope. 6629Otherwise, the variable is unset prior to processing the assignment list. 6630.It Fl t 6631Tags the variables. 6632Tags are user definable and have no special meaning to the shell. 6633.It Fl T 6634If followed by 6635.Ar tname , 6636it creates a type named by 6637.Ar tname 6638using the compound assignment 6639.Ar assign_list 6640to 6641.Ar tname . 6642Otherwise, it writes all 6643the type definitions to standard output. 6644.It Fl u 6645When given along with 6646.Fl i 6647specifies unsigned integer. 6648Otherwise, all lower-case characters are converted to upper-case. 6649The lower-case option, 6650.Fl l , 6651is turned off. 6652Equivalent to 6653.Fl M Cm toupper . 6654.It Fl x 6655The specified 6656.Ar vname Ns No s 6657are marked for automatic export to the environment of subsequently-executed 6658commands. 6659Variables whose names contain a 6660.Sy \&. 6661cannot be exported. 6662.It Fl X 6663Declares 6664.Ar vname 6665to be a double precision floating point number and expands using the 6666.Cm %a 6667format of ISO-C99. 6668If 6669.Ar n 6670is non-zero, it defines the number of hex digits after the radix point that is 6671used when expanding 6672.Ar vname . 6673The default is 10. 6674.It Fl Z 6675Right justify and fill with leading zeros if the first non-blank character is a 6676digit and the 6677.Fl L 6678option has not been set. 6679Remove leading zeros if the 6680.Fl L 6681option is also set. 6682If 6683.Ar n 6684is 6685.Sy non-zero , 6686it defines the width of the field, otherwise it is determined by the width of 6687the value of first assignment. 6688.Pp 6689The 6690.Fl i 6691attribute cannot be specified with 6692.Fl Z . 6693.El 6694.Pp 6695.It Ic ulimit Oo Fl HSacdfmnpstv Oc Op Ar limit 6696Set or display a resource limit. 6697Many systems do not support one or more of these limits. 6698The limit for a specified resource is set when 6699.Ar limit 6700is specified. 6701The value of 6702.Ar limit 6703can be a number in the unit specified with each resource, or the value 6704unlimited. 6705When more than one resource is specified, then the limit name and unit is 6706printed before the value. 6707.Pp 6708If no option is specified, 6709.Fl f 6710is assumed. 6711.Pp 6712The following are the available resource limits: 6713.Bl -tag -width Ds 6714.It Fl a 6715Lists all of the current resource limits. 6716.It Fl c 6717The number of 512-byte blocks on the size of core dumps. 6718.It Fl d 6719The number of Kbytes on the size of the data area. 6720.It Fl f 6721The number of 512-byte blocks on files that can be written by the current 6722process or by child processes (files of any size can be read). 6723.It Fl H 6724Specifies a hard limit for the specified resource. 6725.Pp 6726A hard limit cannot be increased once it is set. 6727.Pp 6728If neither the 6729.Fl H 6730nor 6731.Fl S 6732option is specified, the limit applies to 6733both. 6734The current resource limit is printed when 6735.Ar limit 6736is omitted. 6737In this case, the soft limit is printed unless 6738.Fl H 6739is specified. 6740.It Fl m 6741The number of Kbytes on the size of physical memory. 6742.It Fl n 6743The number of file descriptors plus 1. 6744.It Fl p 6745The number of 512-byte blocks for pipe buffering. 6746.It Fl s 6747The number of Kbytes on the size of the stack area. 6748.It Fl S 6749Specifies a soft limit for the specified resource. 6750.Pp 6751A soft limit can be increased up to the value of the hard limit. 6752.Pp 6753If neither the 6754.Fl H 6755nor 6756.Fl S 6757option is specified, the limit applies to both. 6758The current resource limit is printed when 6759.Ar limit 6760is omitted. 6761In this case, the soft limit is printed unless 6762.Fl H 6763is specified. 6764.It Fl t 6765The number of CPU seconds to be used by each process. 6766.It Fl v 6767The number of Kbytes for virtual memory. 6768.El 6769.Pp 6770.It Ic umask Oo Fl S Oc Op Ar mask 6771The user file-creation mask is set to 6772.Ar mask . 6773.Ar mask 6774can either be an octal number or a symbolic value as described in 6775.Xr chmod 1 . 6776.Pp 6777If a symbolic value is specified, the new 6778.Sy umask 6779value is the complement of the result of applying 6780.Ar mask 6781to the complement of the previous 6782.Sy umask 6783value. 6784If 6785.Ar mask 6786is omitted, the current value of the mask is printed. 6787The 6788.Fl S 6789option causes the mode to be printed as a symbolic value. 6790Otherwise, the mask is printed in octal. 6791.Pp 6792See 6793.Xr umask 2 6794.Pp 6795.It Sy + Ic unalias Oo Fl a Oc Ar name No ... 6796The aliases specified by the list of 6797.Ar name Ns No s 6798are removed from the alias list. 6799The 6800.Fl a 6801option causes all the aliases to be unset. 6802.Pp 6803.It Sy + Ic unset Oo Fl fnv Oc Ar vname No ... 6804The variables specified by the list of 6805.Ar vname Ns No s 6806are unassigned, i.e., their values and attributes are erased. 6807Read-only variables cannot be unset. 6808If the 6809.Fl f 6810option is set, then the names refer to function names. 6811If the 6812.Fl v 6813option is set, then the names refer to variable names. 6814The 6815.Fl f 6816option overrides 6817.Fl v . 6818If 6819.Fl n 6820is set and 6821.Ar name 6822is a name reference, then 6823.Ar name 6824is unset rather than the variable that it references. 6825The default is equivalent to 6826.Fl v . 6827Unsetting 6828.Ev LINENO , 6829.Ev MAILCHECK , 6830.Ev OPTARG , 6831.Ev OPTIND , 6832.Ev RANDOM , 6833.Ev SECONDS , 6834.Ev TMOUT , 6835and 6836.Ev _ 6837removes their special meaning even if they are subsequently assigned to. 6838.Pp 6839.It Ic wait Op Ar job 6840Wait for the specified job and report its termination status. 6841If 6842.Ar job 6843is not specified, then all currently active child processes are waited for. 6844The exit status from this command is that of the last process waited for if 6845.Ar job 6846is specified; otherwise it is zero. 6847See 6848.Sx Jobs 6849for a description of the format of 6850.Ar job . 6851.Pp 6852.It Ic whence Oo Fl afpv Oc Ar name No ... 6853For each 6854.Ar name , 6855indicate how it would be interpreted if used as a command name. 6856The 6857.Fl v 6858option produces a more verbose report. 6859The 6860.Fl f 6861option skips the search for functions. 6862The 6863.Fl p 6864option does a path search for 6865.Ar name 6866even if name is an alias, a function, or a reserved word. 6867The 6868.Fl a 6869option is similar to the 6870.Fl v 6871option but causes all interpretations of the specified name to be reported. 6872.El 6873.Ss "Invocation" 6874If the shell is invoked by 6875.Xr exec 2 , 6876and the first character of argument zero 6877.Pq Sy $0 6878is 6879.Sy - , 6880then the shell is assumed to be a login shell and commands are read from 6881.Pa /etc/profile 6882and then from either 6883.Pa .profile 6884in the current directory or 6885.Pa $HOME/.profile , 6886if either file exists. 6887Next, for interactive shells, commands are read first from 6888.Pa /etc/ksh.kshrc , 6889and then from the file named by performing parameter expansion, command 6890substitution, and arithmetic substitution on the value of the environment 6891variable 6892.Ev ENV , 6893if the file exists. 6894If the 6895.Fl s 6896option is not present and 6897.Ar arg 6898is specified and a file by the name of 6899.Ar arg 6900exists, then it reads and executes this script. 6901Otherwise, if the first 6902.Ar arg 6903does not contain a 6904.Sy / , 6905a path search is performed on the first 6906.Ar arg 6907to determine the name of the script to execute. 6908The script 6909.Ar arg 6910must have execute permission and any 6911.Sy setuid 6912and 6913.Sy setgid 6914settings are ignored. 6915If the script is not found on the path, 6916.Ar arg 6917is processed as if it named a built-in command or function. 6918.Pp 6919Commands are then read as described, and the following options are interpreted 6920by the shell when it is invoked: 6921.Bl -tag -width Ds 6922.It Fl c 6923If the 6924.Fl c 6925option is present, then commands are read from the first 6926.Ar arg . 6927Any remaining arguments become positional parameters starting at 6928.Sy 0 . 6929.It Fl D 6930A list of all double quoted strings that are preceded by a 6931.Sy $ 6932is printed on standard output and the shell exits. 6933This set of strings is subject to language translation when the locale is not C 6934or POSIX. 6935No commands are executed. 6936.It Fl E 6937Reads the file named by the 6938.Ev ENV 6939variable or by 6940.Pa $HOME/.kshrc 6941if not defined after the profiles. 6942.It Fl i 6943If the 6944.Fl i 6945option is present or if the shell input and output are attached to a terminal 6946.Pq as told by Xr tcgetattr 3C ) , 6947this shell is interactive. 6948In this case 6949.Sy TERM 6950is ignored 6951.Po so that 6952.Ic kill Ar 0 6953does not kill an 6954interactive shell 6955.Pc 6956and 6957.Sy INTR 6958is caught and ignored 6959.Pq so that wait is interruptible . 6960In all cases, 6961.Sy QUIT 6962is ignored by the shell. 6963.It Fl R Ar filename 6964The 6965.Fl R Ar filename 6966option is used to generate a cross reference database that can be used by a 6967separate utility to find definitions and references for variables and commands. 6968.It Fl r 6969If the 6970.Fl r 6971option is present, the shell is a restricted shell. 6972.It Fl s 6973If the 6974.Fl s 6975option is present or if no arguments remain, then commands are read from the 6976standard input. 6977Shell output, except for the output of the 6978.Sx Special Commands 6979listed, is written to file descriptor 2. 6980.El 6981.Pp 6982The remaining options and arguments are described under the 6983.Ic set 6984command. 6985An optional 6986.Fl 6987as the first argument is ignored. 6988.Ss rksh93 Only 6989.Sy rksh93 6990is used to set up login names and execution environments whose capabilities are 6991more controlled than those of the standard shell. 6992.Pp 6993The actions of 6994.Nm rksh93 6995are identical to those of 6996.Nm ksh93 , 6997except that the following are disallowed: 6998.Bl -bullet -width Ds 6999.It 7000Unsetting the restricted option 7001.It 7002Changing directory. 7003See 7004.Xr cd 1 . 7005.It 7006Setting or unsetting the value or attributes of 7007.Ev SHELL , 7008.Ev ENV , 7009.Ev FPATH , 7010or 7011.Ev PATH 7012.It 7013Specifying path or command names containing 7014.Sy / 7015.It 7016Redirecting output 7017.Po 7018.Sy \&> , 7019.Sy \&> , 7020.Sy \&| , 7021.Sy \&>\&; , 7022.Sy \&<> , 7023and 7024.Sy \&>> 7025.Pc . 7026.It 7027Adding or deleting built-in commands. 7028.It 7029Using 7030.Ic command Fl p 7031to invoke a command. 7032.El 7033.Pp 7034These restrictions are enforced after 7035.Pa .profile 7036and the 7037.Ev ENV 7038files are interpreted. 7039.Pp 7040When a command to be executed is found to be a shell procedure, 7041.Nm rksh93 7042invokes 7043.Nm ksh93 7044to execute it. 7045Thus, it is possible to provide to the end-user shell procedures that have 7046access to the full power of the standard shell, while imposing a limited menu 7047of commands. 7048This scheme assumes that the end-user does not have write and execute 7049permissions in the same directory. 7050The net effect of these rules is that the writer of the 7051.Pa .profile 7052has complete control over user actions, by performing guaranteed setup actions 7053and leaving the user in an appropriate directory (probably not the login 7054directory). 7055The system administrator often sets up a directory of commands, for example, 7056.Pa /usr/rbin , 7057that can be safely invoked by 7058.Nm rksh93 . 7059.Sh USAGE 7060See 7061.Xr largefile 5 7062for the description of the behavior of 7063.Nm ksh93 7064and 7065.Nm rksh93 7066when encountering files greater than or equal to 2 Gbyte ( 2^31 bytes). 7067.Sh FILES 7068.Bl -tag -width Ds 7069.It Pa /etc/profile 7070The system initialization file, executed for login shells. 7071.It Pa /etc/ksh.kshrc 7072The system wide startup file, executed for interactive shells. 7073.It Pa $HOME/.profile 7074The personal initialization file, executed for login shells after 7075.Pa /etc/profile . 7076.It Pa $HOME/.kshrc 7077Default personal initialization file, executed after 7078.Pa /etc/ksh.kshrc , 7079for interactive shells when 7080.Ev ENV 7081is not set. 7082.It Pa /etc/suid-profile 7083Alternative initialization file, executed instead of the personal 7084initialization file when the real and effective user or group id do not match. 7085.It Pa /dev/null 7086NULL device. 7087.El 7088.Sh EXIT STATUS 7089The following exit values are returned: 7090.Bl -tag -width Ds 7091.It Sy non-zero 7092Returns 7093.Sy non-zero 7094when errors, such as syntax errors, are detected by the shell. 7095.Pp 7096If the shell is being used non-interactively, then execution of the shell file 7097is abandoned unless the error occurs inside a sub-shell in which case the 7098sub-shell is abandoned. 7099.It Em exit-status-of-last-command-executed 7100Returns the exit status of the last command executed. 7101.Pp 7102Run time errors detected by the shell are reported by printing the command or 7103function name and the error condition. 7104If the line number that the error occurred on is greater than one, then the 7105line number is also printed in square brackets 7106.Pq Sy [] 7107after the command or function name. 7108.Pp 7109See the 7110.Nm ksh93 Ic exit 7111command for additional details. 7112.El 7113.Sh INTERFACE STABILITY 7114The scripting interface is 7115.Sy Uncommitted . 7116The environment variables, 7117.Pa \&.paths 7118feature, and editing modes are 7119.Sy Volatile . 7120.Sh SEE ALSO 7121.Xr cat 1 , 7122.Xr cd 1 , 7123.Xr chmod 1 , 7124.Xr cut 1 , 7125.Xr date 1 , 7126.Xr echo 1 , 7127.Xr egrep 1 , 7128.Xr env 1 , 7129.Xr fgrep 1 , 7130.Xr grep 1 , 7131.Xr login 1 , 7132.Xr newgrp 1 , 7133.Xr paste 1 , 7134.Xr perl 1 , 7135.Xr printf 1 , 7136.Xr stty 1 , 7137.Xr test 1 , 7138.Xr umask 1 , 7139.Xr vi 1 , 7140.Xr dup 2 , 7141.Xr exec 2 , 7142.Xr fork 2 , 7143.Xr ioctl 2 , 7144.Xr lseek 2 , 7145.Xr pathconf 2 , 7146.Xr pipe 2 , 7147.Xr ulimit 2 , 7148.Xr umask 2 , 7149.Xr rand 3C , 7150.Xr sysconf 3C , 7151.Xr tcgetattr 3C , 7152.Xr wait 3C , 7153.Xr a.out 4 , 7154.Xr profile 4 , 7155.Xr attributes 5 , 7156.Xr environ 5 , 7157.Xr largefile 5 , 7158.Xr standards 5 7159.Pp 7160.Rs 7161.%A Bolsky, Morris I. 7162.%A Korn, David G. 7163.%B The New KornShell Command and Programming Language 7164.%I Prentice Hall 7165.%D 1995 . 7166.Re 7167.Rs 7168.%B POSIX-Part 2: Shell and Utilities, IEEE Std 1003.2-1992, ISO/IEC 9945-2 7169.%I IEEE 7170.%D 1993 . 7171.Re 7172.Sh NOTES 7173.Nm ksh93 7174scripts should choose shell function names outside the namespace used by 7175reserved keywords of the ISO C99, C++ and JAVA languages to avoid collisions 7176with future enhancements to 7177.Nm ksh93 . 7178.Pp 7179If a command is executed, and then a command with the same name is installed in 7180a directory in the search path before the directory where the original command 7181was found, the shell continues to 7182.Ic exec 7183the original command. 7184Use the 7185.Fl t 7186option of the alias command to correct this situation. 7187.Pp 7188Some very old shell scripts contain a caret 7189.Pq Sy ^ 7190as a synonym for the pipe character 7191.Pq Sy \&| . 7192.Pp 7193Using the 7194.Ic hist 7195built-in command within a compound command causes the whole command to 7196disappear from the history file. 7197.Pp 7198The built-in command 7199.Ic \&. Ar file 7200reads the whole file before any commands are executed. 7201.Ic alias 7202and 7203.Ic unalias 7204commands in the file do not apply to any commands defined in the file. 7205.Pp 7206Traps are not processed while a job is waiting for a foreground process. 7207Thus, a trap on 7208.Sy CHLD 7209is not executed until the foreground job terminates. 7210.Pp 7211It is a good idea to leave a space after the comma operator in arithmetic 7212expressions to prevent the comma from being interpreted as the decimal point 7213character in certain locales. 7214.Pp 7215There might be some restrictions on creating a 7216.Pa \&.paths 7217file which is portable across other operating systems. 7218.Pp 7219If the system supports the 64-bit instruction set, 7220.Pa /bin/ksh93 7221executes the 64-bit version of 7222.Nm ksh93 . 7223