1.\" $OpenBSD: ksh.1,v 1.159 2015/03/25 12:10:52 jca Exp $ 2.\" 3.\" Public Domain 4.\" 5.Dd $Mdocdate: March 25 2015 $ 6.Dt KSH 1 7.Os 8.Sh NAME 9.Nm ksh 10.Nd public domain Korn shell 11.Sh SYNOPSIS 12.Nm ksh 13.Bk -words 14.Op Fl +abCefhiklmnpruvXx 15.Op Fl +o Ar option 16.Op Fl c Ar string \*(Ba Fl s \*(Ba Ar file Op Ar argument ... 17.Ek 18.Sh DESCRIPTION 19.Nm 20is a command interpreter intended for both interactive and shell 21script use. 22Its command language is a superset of the 23.Xr sh 1 24shell language. 25.Pp 26The options are as follows: 27.Bl -tag -width Ds 28.It Fl c Ar string 29.Nm 30will execute the command(s) contained in 31.Ar string . 32.It Fl i 33Interactive shell. 34A shell is 35.Dq interactive 36if this 37option is used or if both standard input and standard error are attached 38to a 39.Xr tty 4 . 40An interactive shell has job control enabled, ignores the 41.Dv SIGINT , 42.Dv SIGQUIT , 43and 44.Dv SIGTERM 45signals, and prints prompts before reading input (see the 46.Ev PS1 47and 48.Ev PS2 49parameters). 50For non-interactive shells, the 51.Ic trackall 52option is on by default (see the 53.Ic set 54command below). 55.It Fl l 56Login shell. 57If the basename the shell is called with (i.e. argv[0]) 58starts with 59.Ql - 60or if this option is used, 61the shell is assumed to be a login shell and the shell reads and executes 62the contents of 63.Pa /etc/profile 64and 65.Pa $HOME/.profile 66if they exist and are readable. 67.It Fl p 68Privileged shell. 69A shell is 70.Dq privileged 71if this option is used 72or if the real user ID or group ID does not match the 73effective user ID or group ID (see 74.Xr getuid 2 75and 76.Xr getgid 2 ) . 77A privileged shell does not process 78.Pa $HOME/.profile 79nor the 80.Ev ENV 81parameter (see below). 82Instead, the file 83.Pa /etc/suid_profile 84is processed. 85Clearing the privileged option causes the shell to set 86its effective user ID (group ID) to its real user ID (group ID). 87.It Fl r 88Restricted shell. 89A shell is 90.Dq restricted 91if this 92option is used; 93if the basename the shell was invoked with was 94.Dq rksh ; 95or if the 96.Ev SHELL 97parameter is set to 98.Dq rksh . 99The following restrictions come into effect after the shell processes any 100profile and 101.Ev ENV 102files: 103.Pp 104.Bl -bullet -compact 105.It 106The 107.Ic cd 108command is disabled. 109.It 110The 111.Ev SHELL , 112.Ev ENV , 113and 114.Ev PATH 115parameters cannot be changed. 116.It 117Command names can't be specified with absolute or relative paths. 118.It 119The 120.Fl p 121option of the built-in command 122.Ic command 123can't be used. 124.It 125Redirections that create files can't be used (i.e.\& 126.Ql \*(Gt , 127.Ql \*(Gt\*(Ba , 128.Ql \*(Gt\*(Gt , 129.Ql \*(Lt\*(Gt ) . 130.El 131.It Fl s 132The shell reads commands from standard input; all non-option arguments 133are positional parameters. 134.El 135.Pp 136In addition to the above, the options described in the 137.Ic set 138built-in command can also be used on the command line: 139both 140.Op Fl +abCefhkmnuvXx 141and 142.Op Fl +o Ar option 143can be used for single letter or long options, respectively. 144.Pp 145If neither the 146.Fl c 147nor the 148.Fl s 149option is specified, the first non-option argument specifies the name 150of a file the shell reads commands from. 151If there are no non-option 152arguments, the shell reads commands from the standard input. 153The name of the shell (i.e. the contents of $0) 154is determined as follows: if the 155.Fl c 156option is used and there is a non-option argument, it is used as the name; 157if commands are being read from a file, the file is used as the name; 158otherwise, the basename the shell was called with (i.e. argv[0]) is used. 159.Pp 160If the 161.Ev ENV 162parameter is set when an interactive shell starts (or, 163in the case of login shells, 164after any profiles are processed), its value is subjected to parameter, 165command, arithmetic, and tilde 166.Pq Sq ~ 167substitution and the resulting file 168(if any) is read and executed. 169In order to have an interactive (as opposed to login) shell 170process a startup file, 171.Ev ENV 172may be set and exported (see below) in 173.Pa $HOME/.profile 174\- future interactive shell invocations will process any file pointed to by 175.Ev $ENV : 176.Pp 177.Dl export ENV=$HOME/.kshrc 178.Pp 179.Pa $HOME/.kshrc 180is then free to specify instructions for interactive shells. 181For example, the global configuration file may be sourced: 182.Bd -literal -offset indent 183\&. /etc/ksh.kshrc 184.Ed 185.Pp 186The above strategy may be employed to keep 187setup procedures for login shells in 188.Pa $HOME/.profile 189and setup procedures for interactive shells in 190.Pa $HOME/.kshrc . 191Of course, since login shells are also interactive, 192any commands placed in 193.Pa $HOME/.kshrc 194will be executed by login shells too. 195.Pp 196The exit status of the shell is 127 if the command file specified on the 197command line could not be opened, or non-zero if a fatal syntax error 198occurred during the execution of a script. 199In the absence of fatal errors, 200the exit status is that of the last command executed, or zero, if no 201command is executed. 202.Ss Command syntax 203The shell begins parsing its input by breaking it into 204.Em words . 205Words, which are sequences of characters, are delimited by unquoted whitespace 206characters (space, tab, and newline) or meta-characters 207.Po 208.Ql \*(Lt , 209.Ql \*(Gt , 210.Ql \*(Ba , 211.Ql \&; , 212.Ql \&( , 213.Ql \&) , 214and 215.Ql & 216.Pc . 217Aside from delimiting words, spaces and tabs are ignored, while newlines 218usually delimit commands. 219The meta-characters are used in building the following 220.Em tokens : 221.Ql \*(Lt , 222.Ql \*(Lt& , 223.Ql \*(Lt\*(Lt , 224.Ql \*(Gt , 225.Ql \*(Gt& , 226.Ql \*(Gt\*(Gt , 227etc. are used to specify redirections (see 228.Sx Input/output redirection 229below); 230.Ql \*(Ba 231is used to create pipelines; 232.Ql \*(Ba& 233is used to create co-processes (see 234.Sx Co-processes 235below); 236.Ql \&; 237is used to separate commands; 238.Ql & 239is used to create asynchronous pipelines; 240.Ql && 241and 242.Ql || 243are used to specify conditional execution; 244.Ql ;; 245is used in 246.Ic case 247statements; 248.Ql (( .. )) 249is used in arithmetic expressions; 250and lastly, 251.Ql \&( .. )\& 252is used to create subshells. 253.Pp 254Whitespace and meta-characters can be quoted individually using a backslash 255.Pq Sq \e , 256or in groups using double 257.Pq Sq \&" 258or single 259.Pq Sq ' 260quotes. 261Note that the following characters are also treated specially by the 262shell and must be quoted if they are to represent themselves: 263.Ql \e , 264.Ql \&" , 265.Ql ' , 266.Ql # , 267.Ql $ , 268.Ql ` , 269.Ql ~ , 270.Ql { , 271.Ql } , 272.Ql * , 273.Ql \&? , 274and 275.Ql \&[ . 276The first three of these are the above mentioned quoting characters (see 277.Sx Quoting 278below); 279.Ql # , 280if used at the beginning of a word, introduces a comment \(em everything after 281the 282.Ql # 283up to the nearest newline is ignored; 284.Ql $ 285is used to introduce parameter, command, and arithmetic substitutions (see 286.Sx Substitution 287below); 288.Ql ` 289introduces an old-style command substitution (see 290.Sx Substitution 291below); 292.Ql ~ 293begins a directory expansion (see 294.Sx Tilde expansion 295below); 296.Ql { 297and 298.Ql } 299delimit 300.Xr csh 1 Ns -style 301alterations (see 302.Sx Brace expansion 303below); 304and finally, 305.Ql * , 306.Ql \&? , 307and 308.Ql \&[ 309are used in file name generation (see 310.Sx File name patterns 311below). 312.Pp 313As words and tokens are parsed, the shell builds commands, of which there 314are two basic types: 315.Em simple-commands , 316typically programs that are executed, and 317.Em compound-commands , 318such as 319.Ic for 320and 321.Ic if 322statements, grouping constructs, and function definitions. 323.Pp 324A simple-command consists of some combination of parameter assignments 325(see 326.Sx Parameters 327below), 328input/output redirections (see 329.Sx Input/output redirections 330below), 331and command words; the only restriction is that parameter assignments come 332before any command words. 333The command words, if any, define the command 334that is to be executed and its arguments. 335The command may be a shell built-in command, a function, 336or an external command 337(i.e. a separate executable file that is located using the 338.Ev PATH 339parameter; see 340.Sx Command execution 341below). 342Note that all command constructs have an exit status: for external commands, 343this is related to the status returned by 344.Xr wait 2 345(if the command could not be found, the exit status is 127; if it could not 346be executed, the exit status is 126); the exit status of other command 347constructs (built-in commands, functions, compound-commands, pipelines, lists, 348etc.) are all well-defined and are described where the construct is 349described. 350The exit status of a command consisting only of parameter 351assignments is that of the last command substitution performed during the 352parameter assignment or 0 if there were no command substitutions. 353.Pp 354Commands can be chained together using the 355.Ql | 356token to form pipelines, in which the standard output of each command but the 357last is piped (see 358.Xr pipe 2 ) 359to the standard input of the following command. 360The exit status of a pipeline is that of its last command. 361A pipeline may be prefixed by the 362.Ql \&! 363reserved word, which causes the exit status of the pipeline to be logically 364complemented: if the original status was 0, the complemented status will be 1; 365if the original status was not 0, the complemented status will be 0. 366.Pp 367.Em Lists 368of commands can be created by separating pipelines by any of the following 369tokens: 370.Ql && , 371.Ql || , 372.Ql & , 373.Ql |& , 374and 375.Ql \&; . 376The first two are for conditional execution: 377.Dq Ar cmd1 No && Ar cmd2 378executes 379.Ar cmd2 380only if the exit status of 381.Ar cmd1 382is zero; 383.Ql || 384is the opposite \(em 385.Ar cmd2 386is executed only if the exit status of 387.Ar cmd1 388is non-zero. 389.Ql && 390and 391.Ql || 392have equal precedence which is higher than that of 393.Ql & , 394.Ql |& , 395and 396.Ql \&; , 397which also have equal precedence. 398Note that the 399.Ql && 400and 401.Ql || 402operators are 403.Qq left-associative . 404For example, both of these commands will print only 405.Qq bar : 406.Bd -literal -offset indent 407$ false && echo foo || echo bar 408$ true || echo foo && echo bar 409.Ed 410.Pp 411The 412.Ql & 413token causes the preceding command to be executed asynchronously; that is, 414the shell starts the command but does not wait for it to complete (the shell 415does keep track of the status of asynchronous commands; see 416.Sx Job control 417below). 418When an asynchronous command is started when job control is disabled 419(i.e. in most scripts), the command is started with signals 420.Dv SIGINT 421and 422.Dv SIGQUIT 423ignored and with input redirected from 424.Pa /dev/null 425(however, redirections specified in the asynchronous command have precedence). 426The 427.Ql |& 428operator starts a co-process which is a special kind of asynchronous process 429(see 430.Sx Co-processes 431below). 432Note that a command must follow the 433.Ql && 434and 435.Ql || 436operators, while it need not follow 437.Ql & , 438.Ql |& , 439or 440.Ql \&; . 441The exit status of a list is that of the last command executed, with the 442exception of asynchronous lists, for which the exit status is 0. 443.Pp 444Compound commands are created using the following reserved words. 445These words 446are only recognized if they are unquoted and if they are used as the first 447word of a command (i.e. they can't be preceded by parameter assignments or 448redirections): 449.Bd -literal -offset indent 450case esac in until (( } 451do fi name while )) 452done for select ! [[ 453elif function then ( ]] 454else if time ) { 455.Ed 456.Pp 457.Sy Note : 458Some shells (but not this one) execute control structure commands in a 459subshell when one or more of their file descriptors are redirected, so any 460environment changes inside them may fail. 461To be portable, the 462.Ic exec 463statement should be used instead to redirect file descriptors before the 464control structure. 465.Pp 466In the following compound command descriptions, command lists (denoted as 467.Em list ) 468that are followed by reserved words must end with a semicolon, a newline, or 469a (syntactically correct) reserved word. 470For example, the following are all valid: 471.Bd -literal -offset indent 472$ { echo foo; echo bar; } 473$ { echo foo; echo bar\*(Ltnewline\*(Gt } 474$ { { echo foo; echo bar; } } 475.Ed 476.Pp 477This is not valid: 478.Pp 479.Dl $ { echo foo; echo bar } 480.Bl -tag -width Ds 481.It Pq Ar list 482Execute 483.Ar list 484in a subshell. 485There is no implicit way to pass environment changes from a 486subshell back to its parent. 487.It { Ar list ; No } 488Compound construct; 489.Ar list 490is executed, but not in a subshell. 491Note that 492.Ql { 493and 494.Ql } 495are reserved words, not meta-characters. 496.It Xo case Ar word No in 497.Oo Op \&( 498.Ar pattern 499.Op | Ar pattern 500.No ... ) 501.Ar list No ;;\ \& Oc ... esac 502.Xc 503The 504.Ic case 505statement attempts to match 506.Ar word 507against a specified 508.Ar pattern ; 509the 510.Ar list 511associated with the first successfully matched pattern is executed. 512Patterns used in 513.Ic case 514statements are the same as those used for file name patterns except that the 515restrictions regarding 516.Ql \&. 517and 518.Ql / 519are dropped. 520Note that any unquoted space before and after a pattern is 521stripped; any space within a pattern must be quoted. 522Both the word and the 523patterns are subject to parameter, command, and arithmetic substitution, as 524well as tilde substitution. 525For historical reasons, open and close braces may be used instead of 526.Ic in 527and 528.Ic esac 529e.g.\& 530.Ic case $foo { *) echo bar; } . 531The exit status of a 532.Ic case 533statement is that of the executed 534.Ar list ; 535if no 536.Ar list 537is executed, the exit status is zero. 538.It Xo for Ar name 539.Oo in Ar word No ... Oc ; 540.No do Ar list ; No done 541.Xc 542For each 543.Ar word 544in the specified word list, the parameter 545.Ar name 546is set to the word and 547.Ar list 548is executed. 549If 550.Ic in 551is not used to specify a word list, the positional parameters 552($1, $2, etc.)\& 553are used instead. 554For historical reasons, open and close braces may be used instead of 555.Ic do 556and 557.Ic done 558e.g.\& 559.Ic for i; { echo $i; } . 560The exit status of a 561.Ic for 562statement is the last exit status of 563.Ar list ; 564if 565.Ar list 566is never executed, the exit status is zero. 567.It Xo if Ar list ; 568.No then Ar list ; 569.Oo elif Ar list ; 570.No then Ar list ; Oc 571.No ... 572.Oo else Ar list ; Oc 573.No fi 574.Xc 575If the exit status of the first 576.Ar list 577is zero, the second 578.Ar list 579is executed; otherwise, the 580.Ar list 581following the 582.Ic elif , 583if any, is executed with similar consequences. 584If all the lists following the 585.Ic if 586and 587.Ic elif Ns s 588fail (i.e. exit with non-zero status), the 589.Ar list 590following the 591.Ic else 592is executed. 593The exit status of an 594.Ic if 595statement is that of non-conditional 596.Ar list 597that is executed; if no non-conditional 598.Ar list 599is executed, the exit status is zero. 600.It Xo select Ar name 601.Oo in Ar word No ... Oc ; 602.No do Ar list ; No done 603.Xc 604The 605.Ic select 606statement provides an automatic method of presenting the user with a menu and 607selecting from it. 608An enumerated list of the specified 609.Ar word Ns (s) 610is printed on standard error, followed by a prompt 611.Po 612.Ev PS3: normally 613.Sq #?\ \& 614.Pc . 615A number corresponding to one of the enumerated words is then read from 616standard input, 617.Ar name 618is set to the selected word (or unset if the selection is not valid), 619.Ev REPLY 620is set to what was read (leading/trailing space is stripped), and 621.Ar list 622is executed. 623If a blank line (i.e. zero or more 624.Ev IFS 625characters) is entered, the menu is reprinted without executing 626.Ar list . 627.Pp 628When 629.Ar list 630completes, the enumerated list is printed if 631.Ev REPLY 632is 633.Dv NULL , 634the prompt is printed, and so on. 635This process continues until an end-of-file 636is read, an interrupt is received, or a 637.Ic break 638statement is executed inside the loop. 639If 640.Dq in word ... 641is omitted, the positional parameters are used 642(i.e. $1, $2, etc.). 643For historical reasons, open and close braces may be used instead of 644.Ic do 645and 646.Ic done 647e.g.\& 648.Ic select i; { echo $i; } . 649The exit status of a 650.Ic select 651statement is zero if a 652.Ic break 653statement is used to exit the loop, non-zero otherwise. 654.It Xo until Ar list ; 655.No do Ar list ; 656.No done 657.Xc 658This works like 659.Ic while , 660except that the body is executed only while the exit status of the first 661.Ar list 662is non-zero. 663.It Xo while Ar list ; 664.No do Ar list ; 665.No done 666.Xc 667A 668.Ic while 669is a pre-checked loop. 670Its body is executed as often as the exit status of the first 671.Ar list 672is zero. 673The exit status of a 674.Ic while 675statement is the last exit status of the 676.Ar list 677in the body of the loop; if the body is not executed, the exit status is zero. 678.It Xo function Ar name 679.No { Ar list ; No } 680.Xc 681Defines the function 682.Ar name 683(see 684.Sx Functions 685below). 686Note that redirections specified after a function definition are 687performed whenever the function is executed, not when the function definition 688is executed. 689.It Ar name Ns () Ar command 690Mostly the same as 691.Ic function 692(see 693.Sx Functions 694below). 695.It Xo Ic time Op Fl p 696.Op Ar pipeline 697.Xc 698The 699.Ic time 700reserved word is described in the 701.Sx Command execution 702section. 703.It (( Ar expression No )) 704The arithmetic expression 705.Ar expression 706is evaluated; equivalent to 707.Dq let expression 708(see 709.Sx Arithmetic expressions 710and the 711.Ic let 712command, below). 713.It Bq Bq Ar \ \&expression\ \& 714Similar to the 715.Ic test 716and 717.Ic \&[ ... \&] 718commands (described later), with the following exceptions: 719.Bl -bullet -offset indent 720.It 721Field splitting and file name generation are not performed on arguments. 722.It 723The 724.Fl a 725.Pq AND 726and 727.Fl o 728.Pq OR 729operators are replaced with 730.Ql && 731and 732.Ql || , 733respectively. 734.It 735Operators (e.g.\& 736.Sq Fl f , 737.Sq = , 738.Sq \&! ) 739must be unquoted. 740.It 741The second operand of the 742.Sq != 743and 744.Sq = 745expressions are patterns (e.g. the comparison 746.Ic [[ foobar = f*r ]] 747succeeds). 748.It 749There are two additional binary operators, 750.Ql \*(Lt 751and 752.Ql \*(Gt , 753which return true if their first string operand is less than, or greater than, 754their second string operand, respectively. 755.It 756The single argument form of 757.Ic test , 758which tests if the argument has a non-zero length, is not valid; explicit 759operators must always be used e.g. instead of 760.No \&[ Ar str No \&] 761use 762.No \&[[ -n Ar str No \&]] . 763.It 764Parameter, command, and arithmetic substitutions are performed as expressions 765are evaluated and lazy expression evaluation is used for the 766.Ql && 767and 768.Ql || 769operators. 770This means that in the following statement, 771.Ic $(\*(Lt foo) 772is evaluated if and only if the file 773.Pa foo 774exists and is readable: 775.Bd -literal -offset indent 776$ [[ -r foo && $(\*(Lt foo) = b*r ]] 777.Ed 778.El 779.El 780.Ss Quoting 781Quoting is used to prevent the shell from treating characters or words 782specially. 783There are three methods of quoting. 784First, 785.Ql \e 786quotes the following character, unless it is at the end of a line, in which 787case both the 788.Ql \e 789and the newline are stripped. 790Second, a single quote 791.Pq Sq ' 792quotes everything up to the next single quote (this may span lines). 793Third, a double quote 794.Pq Sq \&" 795quotes all characters, except 796.Ql $ , 797.Ql ` 798and 799.Ql \e , 800up to the next unquoted double quote. 801.Ql $ 802and 803.Ql ` 804inside double quotes have their usual meaning (i.e. parameter, command, or 805arithmetic substitution) except no field splitting is carried out on the 806results of double-quoted substitutions. 807If a 808.Ql \e 809inside a double-quoted string is followed by 810.Ql \e , 811.Ql $ , 812.Ql ` , 813or 814.Ql \&" , 815it is replaced by the second character; if it is followed by a newline, both 816the 817.Ql \e 818and the newline are stripped; otherwise, both the 819.Ql \e 820and the character following are unchanged. 821.Pp 822.Sy Note : 823See 824.Sx POSIX mode 825below for a special rule regarding 826differences in quoting when the shell is in POSIX mode. 827.Ss Aliases 828There are two types of aliases: normal command aliases and tracked aliases. 829Command aliases are normally used as a short hand for a long or often used 830command. 831The shell expands command aliases (i.e. substitutes the alias name 832for its value) when it reads the first word of a command. 833An expanded alias is re-processed to check for more aliases. 834If a command alias ends in a 835space or tab, the following word is also checked for alias expansion. 836The alias expansion process stops when a word that is not an alias is found, 837when a quoted word is found, or when an alias word that is currently being 838expanded is found. 839.Pp 840The following command aliases are defined automatically by the shell: 841.Bd -literal -offset indent 842autoload='typeset -fu' 843functions='typeset -f' 844hash='alias -t' 845history='fc -l' 846integer='typeset -i' 847local='typeset' 848login='exec login' 849nohup='nohup ' 850r='fc -e -' 851stop='kill -STOP' 852type='whence -v' 853.Ed 854.Pp 855Tracked aliases allow the shell to remember where it found a particular 856command. 857The first time the shell does a path search for a command that is 858marked as a tracked alias, it saves the full path of the command. 859The next 860time the command is executed, the shell checks the saved path to see that it 861is still valid, and if so, avoids repeating the path search. 862Tracked aliases can be listed and created using 863.Ic alias -t . 864Note that changing the 865.Ev PATH 866parameter clears the saved paths for all tracked aliases. 867If the 868.Ic trackall 869option is set (i.e.\& 870.Ic set -o Ic trackall 871or 872.Ic set -h ) , 873the shell tracks all commands. 874This option is set automatically for non-interactive shells. 875For interactive shells, only the following commands are 876automatically tracked: 877.Xr cat 1 , 878.Xr cc 1 , 879.Xr chmod 1 , 880.Xr cp 1 , 881.Xr date 1 , 882.Xr ed 1 , 883.Xr emacs 1 , 884.Xr grep 1 , 885.Xr ls 1 , 886.Xr mail 1 , 887.Xr make 1 , 888.Xr mv 1 , 889.Xr pr 1 , 890.Xr rm 1 , 891.Xr sed 1 , 892.Xr sh 1 , 893.Xr vi 1 , 894and 895.Xr who 1 . 896.Ss Substitution 897The first step the shell takes in executing a simple-command is to perform 898substitutions on the words of the command. 899There are three kinds of 900substitution: parameter, command, and arithmetic. 901Parameter substitutions, 902which are described in detail in the next section, take the form 903.Pf $ Ns Ar name 904or 905.Pf ${ Ns Ar ... Ns } ; 906command substitutions take the form 907.Pf $( Ns Ar command Ns \&) 908or 909.Pf ` Ns Ar command Ns ` ; 910and arithmetic substitutions take the form 911.Pf $(( Ns Ar expression Ns )) . 912.Pp 913If a substitution appears outside of double quotes, the results of the 914substitution are generally subject to word or field splitting according to 915the current value of the 916.Ev IFS 917parameter. 918The 919.Ev IFS 920parameter specifies a list of characters which are used to break a string up 921into several words; any characters from the set space, tab, and newline that 922appear in the 923.Ev IFS 924characters are called 925.Dq IFS whitespace . 926Sequences of one or more 927.Ev IFS 928whitespace characters, in combination with zero or one 929.Pf non- Ev IFS 930whitespace 931characters, delimit a field. 932As a special case, leading and trailing 933.Ev IFS 934whitespace is stripped (i.e. no leading or trailing empty field is created by 935it); leading 936.Pf non- Ev IFS 937whitespace does create an empty field. 938.Pp 939Example: If 940.Ev IFS 941is set to 942.Dq \*(Ltspace\*(Gt: , 943and VAR is set to 944.Dq \*(Ltspace\*(GtA\*(Ltspace\*(Gt:\*(Ltspace\*(Gt\*(Ltspace\*(GtB::D , 945the substitution for $VAR results in four fields: 946.Sq A , 947.Sq B , 948.Sq 949(an empty field), 950and 951.Sq D . 952Note that if the 953.Ev IFS 954parameter is set to the 955.Dv NULL 956string, no field splitting is done; if the parameter is unset, the default 957value of space, tab, and newline is used. 958.Pp 959Also, note that the field splitting applies only to the immediate result of 960the substitution. 961Using the previous example, the substitution for $VAR:E 962results in the fields: 963.Sq A , 964.Sq B , 965.Sq , 966and 967.Sq D:E , 968not 969.Sq A , 970.Sq B , 971.Sq , 972.Sq D , 973and 974.Sq E . 975This behavior is POSIX compliant, but incompatible with some other shell 976implementations which do field splitting on the word which contained the 977substitution or use 978.Dv IFS 979as a general whitespace delimiter. 980.Pp 981The results of substitution are, unless otherwise specified, also subject to 982brace expansion and file name expansion (see the relevant sections below). 983.Pp 984A command substitution is replaced by the output generated by the specified 985command, which is run in a subshell. 986For 987.Pf $( Ns Ar command Ns \&) 988substitutions, normal quoting rules are used when 989.Ar command 990is parsed; however, for the 991.Pf ` Ns Ar command Ns ` 992form, a 993.Ql \e 994followed by any of 995.Ql $ , 996.Ql ` , 997or 998.Ql \e 999is stripped (a 1000.Ql \e 1001followed by any other character is unchanged). 1002As a special case in command substitutions, a command of the form 1003.Pf \*(Lt Ar file 1004is interpreted to mean substitute the contents of 1005.Ar file . 1006Note that 1007.Ic $(\*(Lt foo) 1008has the same effect as 1009.Ic $(cat foo) , 1010but it is carried out more efficiently because no process is started. 1011.Pp 1012.Sy Note : 1013.Pf $( Ns Ar command Ns \&) 1014expressions are currently parsed by finding the matching parenthesis, 1015regardless of quoting. 1016This should be fixed soon. 1017.Pp 1018Arithmetic substitutions are replaced by the value of the specified expression. 1019For example, the command 1020.Ic echo $((2+3*4)) 1021prints 14. 1022See 1023.Sx Arithmetic expressions 1024for a description of an expression. 1025.Ss Parameters 1026Parameters are shell variables; they can be assigned values and their values 1027can be accessed using a parameter substitution. 1028A parameter name is either one 1029of the special single punctuation or digit character parameters described 1030below, or a letter followed by zero or more letters or digits 1031.Po 1032.Ql _ 1033counts as a letter 1034.Pc . 1035The latter form can be treated as arrays by appending an array index of the 1036form 1037.Op Ar expr 1038where 1039.Ar expr 1040is an arithmetic expression. 1041Parameter substitutions take the form 1042.Pf $ Ns Ar name , 1043.Pf ${ Ns Ar name Ns } , 1044or 1045.Sm off 1046.Pf ${ Ar name Oo Ar expr Oc } 1047.Sm on 1048where 1049.Ar name 1050is a parameter name. 1051If 1052.Ar expr 1053is a literal 1054.Ql @ 1055then the named array is expanded using the same quoting rules as 1056.Ql $@ , 1057while if 1058.Ar expr 1059is a literal 1060.Ql * 1061then the named array is expanded using the same quoting rules as 1062.Ql $* . 1063If substitution is performed on a parameter 1064(or an array parameter element) 1065that is not set, a null string is substituted unless the 1066.Ic nounset 1067option 1068.Po 1069.Ic set Fl o Ic nounset 1070or 1071.Ic set Fl u 1072.Pc 1073is set, in which case an error occurs. 1074.Pp 1075Parameters can be assigned values in a number of ways. 1076First, the shell implicitly sets some parameters like 1077.Ql # , 1078.Ql PWD , 1079and 1080.Ql $ ; 1081this is the only way the special single character parameters are set. 1082Second, parameters are imported from the shell's environment at startup. 1083Third, parameters can be assigned values on the command line: for example, 1084.Ic FOO=bar 1085sets the parameter 1086.Dq FOO 1087to 1088.Dq bar ; 1089multiple parameter assignments can be given on a single command line and they 1090can be followed by a simple-command, in which case the assignments are in 1091effect only for the duration of the command (such assignments are also 1092exported; see below for the implications of this). 1093Note that both the parameter name and the 1094.Ql = 1095must be unquoted for the shell to recognize a parameter assignment. 1096The fourth way of setting a parameter is with the 1097.Ic export , 1098.Ic readonly , 1099and 1100.Ic typeset 1101commands; see their descriptions in the 1102.Sx Command execution 1103section. 1104Fifth, 1105.Ic for 1106and 1107.Ic select 1108loops set parameters as well as the 1109.Ic getopts , 1110.Ic read , 1111and 1112.Ic set -A 1113commands. 1114Lastly, parameters can be assigned values using assignment operators 1115inside arithmetic expressions (see 1116.Sx Arithmetic expressions 1117below) or using the 1118.Sm off 1119.Pf ${ Ar name No = Ar value No } 1120.Sm on 1121form of the parameter substitution (see below). 1122.Pp 1123Parameters with the export attribute (set using the 1124.Ic export 1125or 1126.Ic typeset Fl x 1127commands, or by parameter assignments followed by simple commands) are put in 1128the environment (see 1129.Xr environ 7 ) 1130of commands run by the shell as 1131.Ar name Ns = Ns Ar value 1132pairs. 1133The order in which parameters appear in the environment of a command is 1134unspecified. 1135When the shell starts up, it extracts parameters and their values 1136from its environment and automatically sets the export attribute for those 1137parameters. 1138.Pp 1139Modifiers can be applied to the 1140.Pf ${ Ns Ar name Ns } 1141form of parameter substitution: 1142.Bl -tag -width Ds 1143.Sm off 1144.It ${ Ar name No :- Ar word No } 1145.Sm on 1146If 1147.Ar name 1148is set and not 1149.Dv NULL , 1150it is substituted; otherwise, 1151.Ar word 1152is substituted. 1153.Sm off 1154.It ${ Ar name No :+ Ar word No } 1155.Sm on 1156If 1157.Ar name 1158is set and not 1159.Dv NULL , 1160.Ar word 1161is substituted; otherwise, nothing is substituted. 1162.Sm off 1163.It ${ Ar name No := Ar word No } 1164.Sm on 1165If 1166.Ar name 1167is set and not 1168.Dv NULL , 1169it is substituted; otherwise, it is assigned 1170.Ar word 1171and the resulting value of 1172.Ar name 1173is substituted. 1174.Sm off 1175.It ${ Ar name No :? Ar word No } 1176.Sm on 1177If 1178.Ar name 1179is set and not 1180.Dv NULL , 1181it is substituted; otherwise, 1182.Ar word 1183is printed on standard error (preceded by 1184.Ar name : ) 1185and an error occurs (normally causing termination of a shell script, function, 1186or script sourced using the 1187.Sq \&. 1188built-in). 1189If 1190.Ar word 1191is omitted, the string 1192.Dq parameter null or not set 1193is used instead. 1194.El 1195.Pp 1196In the above modifiers, the 1197.Ql \&: 1198can be omitted, in which case the conditions only depend on 1199.Ar name 1200being set (as opposed to set and not 1201.Dv NULL ) . 1202If 1203.Ar word 1204is needed, parameter, command, arithmetic, and tilde substitution are performed 1205on it; if 1206.Ar word 1207is not needed, it is not evaluated. 1208.Pp 1209The following forms of parameter substitution can also be used: 1210.Pp 1211.Bl -tag -width Ds -compact 1212.It Pf ${# Ns Ar name Ns \&} 1213The number of positional parameters if 1214.Ar name 1215is 1216.Ql * , 1217.Ql @ , 1218or not specified; otherwise the length of the string value of parameter 1219.Ar name . 1220.Pp 1221.It Pf ${# Ns Ar name Ns [*]} 1222.It Pf ${# Ns Ar name Ns [@]} 1223The number of elements in the array 1224.Ar name . 1225.Pp 1226.Sm off 1227.It Xo 1228.Pf ${ Ar name 1229.Pf # Ar pattern No } 1230.Xc 1231.It Xo 1232.Pf ${ Ar name 1233.Pf ## Ar pattern No } 1234.Xc 1235.Sm on 1236If 1237.Ar pattern 1238matches the beginning of the value of parameter 1239.Ar name , 1240the matched text is deleted from the result of substitution. 1241A single 1242.Ql # 1243results in the shortest match, and two 1244of them result in the longest match. 1245.Pp 1246.Sm off 1247.It Xo 1248.Pf ${ Ar name 1249.Pf % Ar pattern No } 1250.Xc 1251.It Xo 1252.Pf ${ Ar name 1253.Pf %% Ar pattern No } 1254.Xc 1255.Sm on 1256Like ${..#..} substitution, but it deletes from the end of the value. 1257.El 1258.Pp 1259The following special parameters are implicitly set by the shell and cannot be 1260set directly using assignments: 1261.Bl -tag -width "1 ... 9" 1262.It Ev \&! 1263Process ID of the last background process started. 1264If no background processes have been started, the parameter is not set. 1265.It Ev \&# 1266The number of positional parameters ($1, $2, etc.). 1267.It Ev \&$ 1268The PID of the shell, or the PID of the original shell if it is a subshell. 1269Do 1270.Em NOT 1271use this mechanism for generating temporary file names; see 1272.Xr mktemp 1 1273instead. 1274.It Ev - 1275The concatenation of the current single letter options (see the 1276.Ic set 1277command below for a list of options). 1278.It Ev \&? 1279The exit status of the last non-asynchronous command executed. 1280If the last command was killed by a signal, 1281.Ic $?\& 1282is set to 128 plus the signal number. 1283.It Ev 0 1284The name of the shell, determined as follows: 1285the first argument to 1286.Nm 1287if it was invoked with the 1288.Fl c 1289option and arguments were given; otherwise the 1290.Ar file 1291argument, if it was supplied; 1292or else the basename the shell was invoked with (i.e.\& 1293.Li argv[0] ) . 1294.Ev $0 1295is also set to the name of the current script or 1296the name of the current function, if it was defined with the 1297.Ic function 1298keyword (i.e. a Korn shell style function). 1299.It Ev 1 No ... Ev 9 1300The first nine positional parameters that were supplied to the shell, function, 1301or script sourced using the 1302.Sq \&. 1303built-in. 1304Further positional parameters may be accessed using 1305.Pf ${ Ar number Ns } . 1306.It Ev * 1307All positional parameters (except parameter 0) i.e. $1, $2, $3, ... 1308If used 1309outside of double quotes, parameters are separate words (which are subjected 1310to word splitting); if used within double quotes, parameters are separated 1311by the first character of the 1312.Ev IFS 1313parameter (or the empty string if 1314.Ev IFS 1315is 1316.Dv NULL ) . 1317.It Ev @ 1318Same as 1319.Ic $* , 1320unless it is used inside double quotes, in which case a separate word is 1321generated for each positional parameter. 1322If there are no positional parameters, no word is generated. 1323.Ic $@ 1324can be used to access arguments, verbatim, without losing 1325.Dv NULL 1326arguments or splitting arguments with spaces. 1327.El 1328.Pp 1329The following parameters are set and/or used by the shell: 1330.Bl -tag -width "EXECSHELL" 1331.It Ev _ No (underscore) 1332When an external command is executed by the shell, this parameter is set in the 1333environment of the new process to the path of the executed command. 1334In interactive use, this parameter is also set in the parent shell to the last 1335word of the previous command. 1336When 1337.Ev MAILPATH 1338messages are evaluated, this parameter contains the name of the file that 1339changed (see the 1340.Ev MAILPATH 1341parameter, below). 1342.It Ev CDPATH 1343Search path for the 1344.Ic cd 1345built-in command. 1346It works the same way as 1347.Ev PATH 1348for those directories not beginning with 1349.Ql / 1350or 1351.Ql .\& 1352in 1353.Ic cd 1354commands. 1355Note that if 1356.Ev CDPATH 1357is set and does not contain 1358.Sq \&. 1359or contains an empty path, the current directory is not searched. 1360Also, the 1361.Ic cd 1362built-in command will display the resulting directory when a match is found 1363in any search path other than the empty path. 1364.It Ev COLUMNS 1365Set to the number of columns on the terminal or window. 1366Currently set to the 1367.Dq cols 1368value as reported by 1369.Xr stty 1 1370if that value is non-zero. 1371This parameter is used by the interactive line editing modes, and by the 1372.Ic select , 1373.Ic set -o , 1374and 1375.Ic kill -l 1376commands to format information columns. 1377.It Ev EDITOR 1378If the 1379.Ev VISUAL 1380parameter is not set, this parameter controls the command-line editing mode for 1381interactive shells. 1382See the 1383.Ev VISUAL 1384parameter below for how this works. 1385.Pp 1386Note: 1387traditionally, 1388.Ev EDITOR 1389was used to specify the name of an (old-style) line editor, such as 1390.Xr ed 1 , 1391and 1392.Ev VISUAL 1393was used to specify a (new-style) screen editor, such as 1394.Xr vi 1 . 1395Hence if 1396.Ev VISUAL 1397is set, it overrides 1398.Ev EDITOR . 1399.It Ev ENV 1400If this parameter is found to be set after any profile files are executed, the 1401expanded value is used as a shell startup file. 1402It typically contains function and alias definitions. 1403.It Ev ERRNO 1404Integer value of the shell's 1405.Va errno 1406variable. 1407It indicates the reason the last system call failed. 1408Not yet implemented. 1409.It Ev EXECSHELL 1410If set, this parameter is assumed to contain the shell that is to be used to 1411execute commands that 1412.Xr execve 2 1413fails to execute and which do not start with a 1414.Dq #! Ns Ar shell 1415sequence. 1416.It Ev FCEDIT 1417The editor used by the 1418.Ic fc 1419command (see below). 1420.It Ev FPATH 1421Like 1422.Ev PATH , 1423but used when an undefined function is executed to locate the file defining the 1424function. 1425It is also searched when a command can't be found using 1426.Ev PATH . 1427See 1428.Sx Functions 1429below for more information. 1430.It Ev HISTFILE 1431The name of the file used to store command history. 1432When assigned to, history is loaded from the specified file. 1433Also, several invocations of the shell 1434running on the same machine will share history if their 1435.Ev HISTFILE 1436parameters all point to the same file. 1437.Pp 1438.Sy Note : 1439If 1440.Ev HISTFILE 1441isn't set, no history file is used. 1442This is different from the original Korn shell, which uses 1443.Pa $HOME/.sh_history ; 1444in the future, 1445.Nm pdksh 1446may also use a default history file. 1447.It Ev HISTSIZE 1448The number of commands normally stored for history. 1449The default is 500. 1450.It Ev HOME 1451The default directory for the 1452.Ic cd 1453command and the value substituted for an unqualified 1454.Ic ~ 1455(see 1456.Sx Tilde expansion 1457below). 1458.It Ev IFS 1459Internal field separator, used during substitution and by the 1460.Ic read 1461command, to split values into distinct arguments; normally set to space, tab, 1462and newline. 1463See 1464.Sx Substitution 1465above for details. 1466.Pp 1467.Sy Note : 1468This parameter is not imported from the environment when the shell is 1469started. 1470.It Ev KSH_VERSION 1471The version of the shell and the date the version was created (read-only). 1472.It Ev LINENO 1473The line number of the function or shell script that is currently being 1474executed. 1475.It Ev LINES 1476Set to the number of lines on the terminal or window. 1477.It Ev MAIL 1478If set, the user will be informed of the arrival of mail in the named file. 1479This parameter is ignored if the 1480.Ev MAILPATH 1481parameter is set. 1482.It Ev MAILCHECK 1483How often, in seconds, the shell will check for mail in the file(s) specified 1484by 1485.Ev MAIL 1486or 1487.Ev MAILPATH . 1488If set to 0, the shell checks before each prompt. 1489The default is 600 (10 minutes). 1490.It Ev MAILPATH 1491A list of files to be checked for mail. 1492The list is colon separated, and each file may be followed by a 1493.Ql \&? 1494and a message to be printed if new mail has arrived. 1495Command, parameter, and 1496arithmetic substitution is performed on the message and, during substitution, 1497the parameter 1498.Ic $_ 1499contains the name of the file. 1500The default message is 1501.Dq you have mail in $_ . 1502.It Ev OLDPWD 1503The previous working directory. 1504Unset if 1505.Ic cd 1506has not successfully changed directories since the shell started, or if the 1507shell doesn't know where it is. 1508.It Ev OPTARG 1509When using 1510.Ic getopts , 1511it contains the argument for a parsed option, if it requires one. 1512.It Ev OPTIND 1513The index of the next argument to be processed when using 1514.Ic getopts . 1515Assigning 1 to this parameter causes 1516.Ic getopts 1517to process arguments from the beginning the next time it is invoked. 1518.It Ev PATH 1519A colon separated list of directories that are searched when looking for 1520commands and files sourced using the 1521.Sq \&. 1522command (see below). 1523An empty string resulting from a leading or trailing 1524colon, or two adjacent colons, is treated as a 1525.Sq \&. 1526(the current directory). 1527.It Ev POSIXLY_CORRECT 1528If set, this parameter causes the 1529.Ic posix 1530option to be enabled. 1531See 1532.Sx POSIX mode 1533below. 1534.It Ev PPID 1535The process ID of the shell's parent (read-only). 1536.It Ev PS1 1537The primary prompt for interactive shells. 1538Parameter, command, and arithmetic 1539substitutions are performed, 1540and the prompt string can be customised using 1541backslash-escaped special characters. 1542.Pp 1543Note that since the command-line editors try to figure out how long the prompt 1544is (so they know how far it is to the edge of the screen), escape codes in 1545the prompt tend to mess things up. 1546You can tell the shell not to count certain 1547sequences (such as escape codes) by using the 1548.Li \e[ Ns Ar ... Ns Li \e] 1549substitution (see below) or by prefixing your prompt with a non-printing 1550character (such as control-A) followed by a carriage return and then delimiting 1551the escape codes with this non-printing character. 1552By the way, don't blame me for 1553this hack; it's in the original 1554.Nm . 1555.Pp 1556The default prompt is 1557.Sq $\ \& 1558for non-root users, 1559.Sq #\ \& 1560for root. 1561If 1562.Nm 1563is invoked by root and 1564.Ev PS1 1565does not contain a 1566.Sq # 1567character, the default value will be used even if 1568.Ev PS1 1569already exists in the environment. 1570.Pp 1571The following backslash-escaped special characters can be used 1572to customise the prompt: 1573.Pp 1574.Bl -tag -width "\eD{format}XX" -compact 1575.It Li \ea 1576Insert an ASCII bell character. 1577.It Li \ed 1578The current date, in the format 1579.Dq Day Month Date 1580for example 1581.Dq Wed Nov 03 . 1582.It Li \eD{ Ns Ar format Ns Li } 1583The current date, with 1584.Ar format 1585converted by 1586.Xr strftime 3 . 1587The braces must be specified. 1588.It Li \ee 1589Insert an ASCII escape character. 1590.It Li \eh 1591The hostname, minus domain name. 1592.It Li \eH 1593The full hostname, including domain name. 1594.It Li \ej 1595Current number of jobs running 1596(see 1597.Sx Job control 1598below). 1599.It Li \el 1600The controlling terminal. 1601.It Li \en 1602Insert a newline character. 1603.It Li \er 1604Insert a carriage return character. 1605.It Li \es 1606The name of the shell. 1607.It Li \et 1608The current time, in 24-hour HH:MM:SS format. 1609.It Li \eT 1610The current time, in 12-hour HH:MM:SS format. 1611.It Li \e@ 1612The current time, in 12-hour HH:MM:SS AM/PM format. 1613.It Li \eA 1614The current time, in 24-hour HH:MM format. 1615.It Li \eu 1616The current user's username. 1617.It Li \ev 1618The current version of 1619.Nm . 1620.It Li \eV 1621Like 1622.Sq \ev , 1623but more verbose. 1624.It Li \ew 1625The current working directory. 1626.Dv $HOME 1627is abbreviated as 1628.Sq ~ . 1629.It Li \eW 1630The basename of 1631the current working directory. 1632.Dv $HOME 1633is abbreviated as 1634.Sq ~ . 1635.It Li \e! 1636The current history number. 1637An unescaped 1638.Ql !\& 1639will produce the current history number too, 1640as per the POSIX specification. 1641A literal 1642.Ql \&! 1643can be put in the prompt by placing 1644.Ql !! 1645in 1646.Ev PS1 . 1647.It Li \e# 1648The current command number. 1649This could be different to the current history number, 1650if 1651.Ev HISTFILE 1652contains a history list from a previous session. 1653.It Li \e$ 1654The default prompt i.e.\& 1655.Sq # \& 1656if the effective UID is 0, 1657otherwise 1658.Sq $ \& . 1659Since the shell interprets 1660.Sq $ 1661as a special character within double quotes, 1662it is safer in this case to escape the backslash 1663than to try quoting it. 1664.It Li \e Ns Ar nnn 1665The octal character 1666.Ar nnn . 1667.It Li \e\e 1668Insert a single backslash character. 1669.It Li \e[ 1670Normally the shell keeps track of the number of characters in the prompt. 1671Use of this sequence turns off that count. 1672.It Li \e] 1673Use of this sequence turns the count back on. 1674.El 1675.Pp 1676Note that the backslash itself may be interpreted by the shell. 1677Hence, to set 1678.Ev PS1 1679either escape the backslash itself, 1680or use double quotes. 1681The latter is more practical: 1682.Bd -literal -offset indent 1683PS1="\eu " 1684.Ed 1685.Pp 1686This is a more complex example, 1687which does not rely on the above backslash-escaped sequences. 1688It embeds the current working directory, 1689in reverse video, 1690in the prompt string: 1691.Bd -literal -offset indent 1692x=$(print \e\e001) 1693PS1="$x$(print \e\er)$x$(tput so)$x\e$PWD$x$(tput se)$x\*(Gt " 1694.Ed 1695.It Ev PS2 1696Secondary prompt string, by default 1697.Sq \*(Gt\ \& , 1698used when more input is needed to complete a command. 1699.It Ev PS3 1700Prompt used by the 1701.Ic select 1702statement when reading a menu selection. 1703The default is 1704.Sq #?\ \& . 1705.It Ev PS4 1706Used to prefix commands that are printed during execution tracing (see the 1707.Ic set Fl x 1708command below). 1709Parameter, command, and arithmetic substitutions are performed 1710before it is printed. 1711The default is 1712.Sq +\ \& . 1713.It Ev PWD 1714The current working directory. 1715May be unset or 1716.Dv NULL 1717if the shell doesn't know where it is. 1718.It Ev RANDOM 1719A random number generator. 1720Every time 1721.Ev RANDOM 1722is referenced, it is assigned the next random number in the range 17230\-32767. 1724By default, 1725.Xr arc4random 3 1726is used to produce values. 1727If the variable 1728.Ev RANDOM 1729is assigned a value, the value is used as the seed to 1730.Xr srand 3 1731and subsequent references of 1732.Ev RANDOM 1733will use 1734.Xr rand 3 1735to produce values, resulting in a predictable sequence. 1736.It Ev REPLY 1737Default parameter for the 1738.Ic read 1739command if no names are given. 1740Also used in 1741.Ic select 1742loops to store the value that is read from standard input. 1743.It Ev SECONDS 1744The number of seconds since the shell started or, if the parameter has been 1745assigned an integer value, the number of seconds since the assignment plus the 1746value that was assigned. 1747.It Ev TMOUT 1748If set to a positive integer in an interactive shell, it specifies the maximum 1749number of seconds the shell will wait for input after printing the primary 1750prompt 1751.Pq Ev PS1 . 1752If the time is exceeded, the shell exits. 1753.It Ev TMPDIR 1754The directory temporary shell files are created in. 1755If this parameter is not 1756set, or does not contain the absolute path of a writable directory, temporary 1757files are created in 1758.Pa /tmp . 1759.It Ev VISUAL 1760If set, this parameter controls the command-line editing mode for interactive 1761shells. 1762If the last component of the path specified in this parameter contains 1763the string 1764.Dq vi , 1765.Dq emacs , 1766or 1767.Dq gmacs , 1768the 1769.Xr vi 1 , 1770emacs, or gmacs (Gosling emacs) editing mode is enabled, respectively. 1771See also the 1772.Ev EDITOR 1773parameter, above. 1774.El 1775.Ss Tilde expansion 1776Tilde expansion, which is done in parallel with parameter substitution, is done 1777on words starting with an unquoted 1778.Ql ~ . 1779The characters following the tilde, up to the first 1780.Ql / , 1781if any, are assumed to be a login name. 1782If the login name is empty, 1783.Ql + , 1784or 1785.Ql - , 1786the value of the 1787.Ev HOME , 1788.Ev PWD , 1789or 1790.Ev OLDPWD 1791parameter is substituted, respectively. 1792Otherwise, the password file is 1793searched for the login name, and the tilde expression is substituted with the 1794user's home directory. 1795If the login name is not found in the password file or 1796if any quoting or parameter substitution occurs in the login name, no 1797substitution is performed. 1798.Pp 1799In parameter assignments 1800(such as those preceding a simple-command or those occurring 1801in the arguments of 1802.Ic alias , 1803.Ic export , 1804.Ic readonly , 1805and 1806.Ic typeset ) , 1807tilde expansion is done after any assignment 1808(i.e. after the equals sign) 1809or after an unquoted colon 1810.Pq Sq \&: ; 1811login names are also delimited by colons. 1812.Pp 1813The home directory of previously expanded login names are cached and re-used. 1814The 1815.Ic alias -d 1816command may be used to list, change, and add to this cache (e.g.\& 1817.Ic alias -d fac=/usr/local/facilities; cd ~fac/bin ) . 1818.Ss Brace expansion (alteration) 1819Brace expressions take the following form: 1820.Bd -unfilled -offset indent 1821.Sm off 1822.Xo 1823.Ar prefix No { Ar str1 No ,..., 1824.Ar strN No } Ar suffix 1825.Xc 1826.Sm on 1827.Ed 1828.Pp 1829The expressions are expanded to 1830.Ar N 1831words, each of which is the concatenation of 1832.Ar prefix , 1833.Ar str Ns i , 1834and 1835.Ar suffix 1836(e.g.\& 1837.Dq a{c,b{X,Y},d}e 1838expands to four words: 1839.Dq ace , 1840.Dq abXe , 1841.Dq abYe , 1842and 1843.Dq ade ) . 1844As noted in the example, brace expressions can be nested and the resulting 1845words are not sorted. 1846Brace expressions must contain an unquoted comma 1847.Pq Sq \&, 1848for expansion to occur (e.g.\& 1849.Ic {} 1850and 1851.Ic {foo} 1852are not expanded). 1853Brace expansion is carried out after parameter substitution 1854and before file name generation. 1855.Ss File name patterns 1856A file name pattern is a word containing one or more unquoted 1857.Ql \&? , 1858.Ql * , 1859.Ql + , 1860.Ql @ , 1861or 1862.Ql \&! 1863characters or 1864.Dq [..] 1865sequences. 1866Once brace expansion has been performed, the shell replaces file 1867name patterns with the sorted names of all the files that match the pattern 1868(if no files match, the word is left unchanged). 1869The pattern elements have the following meaning: 1870.Bl -tag -width Ds 1871.It \&? 1872Matches any single character. 1873.It \&* 1874Matches any sequence of characters. 1875.It [..] 1876Matches any of the characters inside the brackets. 1877Ranges of characters can be 1878specified by separating two characters by a 1879.Ql - 1880(e.g.\& 1881.Dq [a0-9] 1882matches the letter 1883.Sq a 1884or any digit). 1885In order to represent itself, a 1886.Ql - 1887must either be quoted or the first or last character in the character list. 1888Similarly, a 1889.Ql \&] 1890must be quoted or the first character in the list if it is to represent itself 1891instead of the end of the list. 1892Also, a 1893.Ql \&! 1894appearing at the start of the list has special meaning (see below), so to 1895represent itself it must be quoted or appear later in the list. 1896.Pp 1897Within a bracket expression, the name of a 1898.Em character class 1899enclosed in 1900.Sq [: 1901and 1902.Sq :] 1903stands for the list of all characters belonging to that class. 1904Supported character classes: 1905.Bd -literal -offset indent 1906alnum cntrl lower space 1907alpha digit print upper 1908blank graph punct xdigit 1909.Ed 1910.Pp 1911These match characters using the macros specified in 1912.Xr isalnum 3 , 1913.Xr isalpha 3 , 1914and so on. 1915A character class may not be used as an endpoint of a range. 1916.It [!..] 1917Like [..], 1918except it matches any character not inside the brackets. 1919.Sm off 1920.It *( Ar pattern\*(Ba No ...\*(Ba Ar pattern ) 1921.Sm on 1922Matches any string of characters that matches zero or more occurrences of the 1923specified patterns. 1924Example: The pattern 1925.Ic *(foo|bar) 1926matches the strings 1927.Dq , 1928.Dq foo , 1929.Dq bar , 1930.Dq foobarfoo , 1931etc. 1932.Sm off 1933.It +( Ar pattern\*(Ba No ...\*(Ba Ar pattern ) 1934.Sm on 1935Matches any string of characters that matches one or more occurrences of the 1936specified patterns. 1937Example: The pattern 1938.Ic +(foo|bar) 1939matches the strings 1940.Dq foo , 1941.Dq bar , 1942.Dq foobar , 1943etc. 1944.Sm off 1945.It ?( Ar pattern\*(Ba No ...\*(Ba Ar pattern ) 1946.Sm on 1947Matches the empty string or a string that matches one of the specified 1948patterns. 1949Example: The pattern 1950.Ic ?(foo|bar) 1951only matches the strings 1952.Dq , 1953.Dq foo , 1954and 1955.Dq bar . 1956.Sm off 1957.It @( Ar pattern\*(Ba No ...\*(Ba Ar pattern ) 1958.Sm on 1959Matches a string that matches one of the specified patterns. 1960Example: The pattern 1961.Ic @(foo|bar) 1962only matches the strings 1963.Dq foo 1964and 1965.Dq bar . 1966.Sm off 1967.It !( Ar pattern\*(Ba No ...\*(Ba Ar pattern ) 1968.Sm on 1969Matches any string that does not match one of the specified patterns. 1970Examples: The pattern 1971.Ic !(foo|bar) 1972matches all strings except 1973.Dq foo 1974and 1975.Dq bar ; 1976the pattern 1977.Ic !(*) 1978matches no strings; the pattern 1979.Ic !(?)*\& 1980matches all strings (think about it). 1981.El 1982.Pp 1983Note that 1984.Nm pdksh 1985currently never matches 1986.Sq \&. 1987and 1988.Sq .. , 1989but the original 1990.Nm ksh , 1991Bourne 1992.Nm sh , 1993and bash do, so this may have to change (too bad). 1994.Pp 1995Note that none of the above pattern elements match either a period 1996.Pq Sq \&. 1997at the start of a file name or a slash 1998.Pq Sq / , 1999even if they are explicitly used in a [..] sequence; also, the names 2000.Sq \&. 2001and 2002.Sq .. 2003are never matched, even by the pattern 2004.Sq .* . 2005.Pp 2006If the 2007.Ic markdirs 2008option is set, any directories that result from file name generation are marked 2009with a trailing 2010.Ql / . 2011.Ss Input/output redirection 2012When a command is executed, its standard input, standard output, and standard 2013error (file descriptors 0, 1, and 2, respectively) are normally inherited from 2014the shell. 2015Three exceptions to this are commands in pipelines, for which 2016standard input and/or standard output are those set up by the pipeline, 2017asynchronous commands created when job control is disabled, for which standard 2018input is initially set to be from 2019.Pa /dev/null , 2020and commands for which any of the following redirections have been specified: 2021.Bl -tag -width Ds 2022.It \*(Gt Ar file 2023Standard output is redirected to 2024.Ar file . 2025If 2026.Ar file 2027does not exist, it is created; if it does exist, is a regular file, and the 2028.Ic noclobber 2029option is set, an error occurs; otherwise, the file is truncated. 2030Note that this means the command 2031.Ic cmd \*(Lt foo \*(Gt foo 2032will open 2033.Ar foo 2034for reading and then truncate it when it opens it for writing, before 2035.Ar cmd 2036gets a chance to actually read 2037.Ar foo . 2038.It \*(Gt\*(Ba Ar file 2039Same as 2040.Ic \*(Gt , 2041except the file is truncated, even if the 2042.Ic noclobber 2043option is set. 2044.It \*(Gt\*(Gt Ar file 2045Same as 2046.Ic \*(Gt , 2047except if 2048.Ar file 2049exists it is appended to instead of being truncated. 2050Also, the file is opened 2051in append mode, so writes always go to the end of the file (see 2052.Xr open 2 ) . 2053.It \*(Lt Ar file 2054Standard input is redirected from 2055.Ar file , 2056which is opened for reading. 2057.It \*(Lt\*(Gt Ar file 2058Same as 2059.Ic \*(Lt , 2060except the file is opened for reading and writing. 2061.It \*(Lt\*(Lt Ar marker 2062After reading the command line containing this kind of redirection (called a 2063.Dq here document ) , 2064the shell copies lines from the command source into a temporary file until a 2065line matching 2066.Ar marker 2067is read. 2068When the command is executed, standard input is redirected from the 2069temporary file. 2070If 2071.Ar marker 2072contains no quoted characters, the contents of the temporary file are processed 2073as if enclosed in double quotes each time the command is executed, so 2074parameter, command, and arithmetic substitutions are performed, along with 2075backslash 2076.Pq Sq \e 2077escapes for 2078.Ql $ , 2079.Ql ` , 2080.Ql \e , 2081and 2082.Ql \enewline . 2083If multiple here documents are used on the same command line, they are saved in 2084order. 2085.It \*(Lt\*(Lt- Ar marker 2086Same as 2087.Ic \*(Lt\*(Lt , 2088except leading tabs are stripped from lines in the here document. 2089.It \*(Lt& Ar fd 2090Standard input is duplicated from file descriptor 2091.Ar fd . 2092.Ar fd 2093can be a single digit, indicating the number of an existing file descriptor; 2094the letter 2095.Ql p , 2096indicating the file descriptor associated with the output of the current 2097co-process; or the character 2098.Ql - , 2099indicating standard input is to be closed. 2100.It \*(Gt& Ar fd 2101Same as 2102.Ic \*(Lt& , 2103except the operation is done on standard output. 2104.El 2105.Pp 2106In any of the above redirections, the file descriptor that is redirected 2107(i.e. standard input or standard output) 2108can be explicitly given by preceding the 2109redirection with a single digit. 2110Parameter, command, and arithmetic 2111substitutions, tilde substitutions, and (if the shell is interactive) 2112file name generation are all performed on the 2113.Ar file , 2114.Ar marker , 2115and 2116.Ar fd 2117arguments of redirections. 2118Note, however, that the results of any file name 2119generation are only used if a single file is matched; if multiple files match, 2120the word with the expanded file name generation characters is used. 2121Note 2122that in restricted shells, redirections which can create files cannot be used. 2123.Pp 2124For simple-commands, redirections may appear anywhere in the command; for 2125compound-commands 2126.Po 2127.Ic if 2128statements, etc. 2129.Pc , 2130any redirections must appear at the end. 2131Redirections are processed after 2132pipelines are created and in the order they are given, so the following 2133will print an error with a line number prepended to it: 2134.Pp 2135.D1 $ cat /foo/bar 2\*(Gt&1 \*(Gt /dev/null \*(Ba cat -n 2136.Ss Arithmetic expressions 2137Integer arithmetic expressions can be used with the 2138.Ic let 2139command, inside $((..)) expressions, inside array references (e.g.\& 2140.Ar name Ns Bq Ar expr ) , 2141as numeric arguments to the 2142.Ic test 2143command, and as the value of an assignment to an integer parameter. 2144.Pp 2145Expressions may contain alpha-numeric parameter identifiers, array references, 2146and integer constants and may be combined with the following C operators 2147(listed and grouped in increasing order of precedence): 2148.Pp 2149Unary operators: 2150.Bd -literal -offset indent 2151+ - ! ~ ++ -- 2152.Ed 2153.Pp 2154Binary operators: 2155.Bd -literal -offset indent 2156, 2157= *= /= %= += -= \*(Lt\*(Lt= \*(Gt\*(Gt= &= ^= \*(Ba= 2158\*(Ba\*(Ba 2159&& 2160\*(Ba 2161^ 2162& 2163== != 2164\*(Lt \*(Lt= \*(Gt= \*(Gt 2165\*(Lt\*(Lt \*(Gt\*(Gt 2166+ - 2167* / % 2168.Ed 2169.Pp 2170Ternary operators: 2171.Bd -literal -offset indent 2172?: (precedence is immediately higher than assignment) 2173.Ed 2174.Pp 2175Grouping operators: 2176.Bd -literal -offset indent 2177( ) 2178.Ed 2179.Pp 2180A parameter that is NULL or unset evaluates to 0. 2181Integer constants may be specified with arbitrary bases using the notation 2182.Ar base Ns # Ns Ar number , 2183where 2184.Ar base 2185is a decimal integer specifying the base, and 2186.Ar number 2187is a number in the specified base. 2188Additionally, 2189integers may be prefixed with 2190.Sq 0X 2191or 2192.Sq 0x 2193(specifying base 16) 2194or 2195.Sq 0 2196(base 8) 2197in all forms of arithmetic expressions, 2198except as numeric arguments to the 2199.Ic test 2200command. 2201.Pp 2202The operators are evaluated as follows: 2203.Bl -tag -width Ds -offset indent 2204.It unary + 2205Result is the argument (included for completeness). 2206.It unary - 2207Negation. 2208.It \&! 2209Logical NOT; 2210the result is 1 if argument is zero, 0 if not. 2211.It ~ 2212Arithmetic (bit-wise) NOT. 2213.It ++ 2214Increment; must be applied to a parameter (not a literal or other expression). 2215The parameter is incremented by 1. 2216When used as a prefix operator, the result 2217is the incremented value of the parameter; when used as a postfix operator, the 2218result is the original value of the parameter. 2219.It -- 2220Similar to 2221.Ic ++ , 2222except the parameter is decremented by 1. 2223.It \&, 2224Separates two arithmetic expressions; the left-hand side is evaluated first, 2225then the right. 2226The result is the value of the expression on the right-hand side. 2227.It = 2228Assignment; the variable on the left is set to the value on the right. 2229.It Xo 2230.No *= /= += -= \*(Lt\*(Lt= 2231.No \*(Gt\*(Gt= &= ^= \*(Ba= 2232.Xc 2233Assignment operators. 2234.Sm off 2235.Ao Ar var Ac Xo 2236.Aq Ar op 2237.No = Aq Ar expr 2238.Xc 2239.Sm on 2240is the same as 2241.Sm off 2242.Ao Ar var Ac Xo 2243.No = Aq Ar var 2244.Aq Ar op 2245.Aq Ar expr , 2246.Xc 2247.Sm on 2248with any operator precedence in 2249.Aq Ar expr 2250preserved. 2251For example, 2252.Dq var1 *= 5 + 3 2253is the same as specifying 2254.Dq var1 = var1 * (5 + 3) . 2255.It \*(Ba\*(Ba 2256Logical OR; 2257the result is 1 if either argument is non-zero, 0 if not. 2258The right argument is evaluated only if the left argument is zero. 2259.It && 2260Logical AND; 2261the result is 1 if both arguments are non-zero, 0 if not. 2262The right argument is evaluated only if the left argument is non-zero. 2263.It \*(Ba 2264Arithmetic (bit-wise) OR. 2265.It ^ 2266Arithmetic (bit-wise) XOR 2267(exclusive-OR). 2268.It & 2269Arithmetic (bit-wise) AND. 2270.It == 2271Equal; the result is 1 if both arguments are equal, 0 if not. 2272.It != 2273Not equal; the result is 0 if both arguments are equal, 1 if not. 2274.It \*(Lt 2275Less than; the result is 1 if the left argument is less than the right, 0 if 2276not. 2277.It \*(Lt= \*(Gt= \*(Gt 2278Less than or equal, greater than or equal, greater than. 2279See 2280.Ic \*(Lt . 2281.It \*(Lt\*(Lt \*(Gt\*(Gt 2282Shift left (right); the result is the left argument with its bits shifted left 2283(right) by the amount given in the right argument. 2284.It + - * / 2285Addition, subtraction, multiplication, and division. 2286.It % 2287Remainder; the result is the remainder of the division of the left argument by 2288the right. 2289The sign of the result is unspecified if either argument is negative. 2290.It Xo 2291.Sm off 2292.Aq Ar arg1 ? 2293.Aq Ar arg2 : 2294.Aq Ar arg3 2295.Sm on 2296.Xc 2297If 2298.Aq Ar arg1 2299is non-zero, the result is 2300.Aq Ar arg2 ; 2301otherwise the result is 2302.Aq Ar arg3 . 2303.El 2304.Ss Co-processes 2305A co-process, which is a pipeline created with the 2306.Sq \*(Ba& 2307operator, is an asynchronous process that the shell can both write to (using 2308.Ic print -p ) 2309and read from (using 2310.Ic read -p ) . 2311The input and output of the co-process can also be manipulated using 2312.Ic \*(Gt&p 2313and 2314.Ic \*(Lt&p 2315redirections, respectively. 2316Once a co-process has been started, another can't 2317be started until the co-process exits, or until the co-process's input has been 2318redirected using an 2319.Ic exec Ar n Ns Ic \*(Gt&p 2320redirection. 2321If a co-process's input is redirected in this way, the next 2322co-process to be started will share the output with the first co-process, 2323unless the output of the initial co-process has been redirected using an 2324.Ic exec Ar n Ns Ic \*(Lt&p 2325redirection. 2326.Pp 2327Some notes concerning co-processes: 2328.Bl -bullet 2329.It 2330The only way to close the co-process's input (so the co-process reads an 2331end-of-file) is to redirect the input to a numbered file descriptor and then 2332close that file descriptor e.g.\& 2333.Ic exec 3\*(Gt&p; exec 3\*(Gt&- . 2334.It 2335In order for co-processes to share a common output, the shell must keep the 2336write portion of the output pipe open. 2337This means that end-of-file will not be 2338detected until all co-processes sharing the co-process's output have exited 2339(when they all exit, the shell closes its copy of the pipe). 2340This can be 2341avoided by redirecting the output to a numbered file descriptor (as this also 2342causes the shell to close its copy). 2343Note that this behaviour is slightly 2344different from the original Korn shell which closes its copy of the write 2345portion of the co-process output when the most recently started co-process 2346(instead of when all sharing co-processes) exits. 2347.It 2348.Ic print -p 2349will ignore 2350.Dv SIGPIPE 2351signals during writes if the signal is not being trapped or ignored; the same 2352is true if the co-process input has been duplicated to another file descriptor 2353and 2354.Ic print -u Ns Ar n 2355is used. 2356.El 2357.Ss Functions 2358Functions are defined using either Korn shell 2359.Ic function Ar function-name 2360syntax or the Bourne/POSIX shell 2361.Ar function-name Ns () 2362syntax (see below for the difference between the two forms). 2363Functions are like 2364.Li .-scripts 2365(i.e. scripts sourced using the 2366.Sq \&. 2367built-in) 2368in that they are executed in the current environment. 2369However, unlike 2370.Li .-scripts , 2371shell arguments (i.e. positional parameters $1, $2, etc.)\& 2372are never visible inside them. 2373When the shell is determining the location of a command, functions 2374are searched after special built-in commands, before regular and 2375non-regular built-ins, and before the 2376.Ev PATH 2377is searched. 2378.Pp 2379An existing function may be deleted using 2380.Ic unset Fl f Ar function-name . 2381A list of functions can be obtained using 2382.Ic typeset +f 2383and the function definitions can be listed using 2384.Ic typeset -f . 2385The 2386.Ic autoload 2387command (which is an alias for 2388.Ic typeset -fu ) 2389may be used to create undefined functions: when an undefined function is 2390executed, the shell searches the path specified in the 2391.Ev FPATH 2392parameter for a file with the same name as the function, which, if found, is 2393read and executed. 2394If after executing the file the named function is found to 2395be defined, the function is executed; otherwise, the normal command search is 2396continued (i.e. the shell searches the regular built-in command table and 2397.Ev PATH ) . 2398Note that if a command is not found using 2399.Ev PATH , 2400an attempt is made to autoload a function using 2401.Ev FPATH 2402(this is an undocumented feature of the original Korn shell). 2403.Pp 2404Functions can have two attributes, 2405.Dq trace 2406and 2407.Dq export , 2408which can be set with 2409.Ic typeset -ft 2410and 2411.Ic typeset -fx , 2412respectively. 2413When a traced function is executed, the shell's 2414.Ic xtrace 2415option is turned on for the function's duration; otherwise, the 2416.Ic xtrace 2417option is turned off. 2418The 2419.Dq export 2420attribute of functions is currently not used. 2421In the original Korn shell, 2422exported functions are visible to shell scripts that are executed. 2423.Pp 2424Since functions are executed in the current shell environment, parameter 2425assignments made inside functions are visible after the function completes. 2426If this is not the desired effect, the 2427.Ic typeset 2428command can be used inside a function to create a local parameter. 2429Note that special parameters (e.g.\& 2430.Ic \&$$ , $! ) 2431can't be scoped in this way. 2432.Pp 2433The exit status of a function is that of the last command executed in the 2434function. 2435A function can be made to finish immediately using the 2436.Ic return 2437command; this may also be used to explicitly specify the exit status. 2438.Pp 2439Functions defined with the 2440.Ic function 2441reserved word are treated differently in the following ways from functions 2442defined with the 2443.Ic () 2444notation: 2445.Bl -bullet 2446.It 2447The $0 parameter is set to the name of the function 2448(Bourne-style functions leave $0 untouched). 2449.It 2450Parameter assignments preceding function calls are not kept in the shell 2451environment (executing Bourne-style functions will keep assignments). 2452.It 2453.Ev OPTIND 2454is saved/reset and restored on entry and exit from the function so 2455.Ic getopts 2456can be used properly both inside and outside the function (Bourne-style 2457functions leave 2458.Ev OPTIND 2459untouched, so using 2460.Ic getopts 2461inside a function interferes with using 2462.Ic getopts 2463outside the function). 2464.El 2465.Pp 2466In the future, the following differences will also be added: 2467.Bl -bullet 2468.It 2469A separate trap/signal environment will be used during the execution of 2470functions. 2471This will mean that traps set inside a function will not affect the 2472shell's traps and signals that are not ignored in the shell (but may be 2473trapped) will have their default effect in a function. 2474.It 2475The EXIT trap, if set in a function, will be executed after the function 2476returns. 2477.El 2478.Ss POSIX mode 2479The shell is intended to be POSIX compliant; 2480however, in some cases, POSIX behaviour is contrary either to 2481the original Korn shell behaviour or to user convenience. 2482How the shell behaves in these cases is determined by the state of the 2483.Ic posix 2484option 2485.Pq Ic set -o posix . 2486If it is on, the POSIX behaviour is followed; otherwise, it is not. 2487The 2488.Ic posix 2489option is set automatically when the shell starts up if the environment 2490contains the 2491.Ev POSIXLY_CORRECT 2492parameter. 2493The shell can also be compiled so that it is in POSIX mode by default; 2494however, this is usually not desirable. 2495.Pp 2496The following is a list of things that are affected by the state of the 2497.Ic posix 2498option: 2499.Bl -bullet 2500.It 2501Occurrences of 2502.Ic \e\&" 2503inside double quoted 2504.Ic `..` 2505command substitutions. 2506In POSIX mode, the 2507.Ic \e\&" 2508is interpreted when the command is interpreted; 2509in non-POSIX mode, 2510the backslash is stripped before the command substitution is interpreted. 2511For example, 2512.Ic echo \&"`echo \e\&"hi\e\&"`\&" 2513produces 2514.Dq \&"hi\&" 2515in POSIX mode, 2516.Dq hi 2517in non-POSIX mode. 2518To avoid problems, use the 2519.Ic $(...)\& 2520form of command substitution. 2521.It 2522.Ic kill -l 2523output. 2524In POSIX mode, only signal names are listed (in a single line); 2525in non-POSIX mode, 2526signal numbers, names, and descriptions are printed (in columns). 2527In the future, a new option 2528.Pq Fl v No perhaps 2529will be added to distinguish the two behaviours. 2530.It 2531.Ic echo 2532options. 2533In POSIX mode, 2534.Fl e 2535and 2536.Fl E 2537are not treated as options, but printed like other arguments; 2538in non-POSIX mode, these options control the interpretation 2539of backslash sequences. 2540.It 2541.Ic fg 2542exit status. 2543In POSIX mode, the exit status is 0 if no errors occur; 2544in non-POSIX mode, the exit status is that of the last foregrounded job. 2545.It 2546.Ic eval 2547exit status. 2548If 2549.Ic eval 2550gets to see an empty command (i.e.\& 2551.Ic eval `false` ) , 2552its exit status in POSIX mode will be 0. 2553In non-POSIX mode, 2554it will be the exit status of the last command substitution that was 2555done in the processing of the arguments to 2556.Ic eval 2557(or 0 if there were no command substitutions). 2558.It 2559.Ic getopts . 2560In POSIX mode, options must start with a 2561.Ql - ; 2562in non-POSIX mode, options can start with either 2563.Ql - 2564or 2565.Ql + . 2566.It 2567Brace expansion (also known as alternation). 2568In POSIX mode, brace expansion is disabled; 2569in non-POSIX mode, brace expansion is enabled. 2570Note that 2571.Ic set -o posix 2572(or setting the 2573.Ev POSIXLY_CORRECT 2574parameter) automatically turns the 2575.Ic braceexpand 2576option off; however, it can be explicitly turned on later. 2577.It 2578.Ic set - . 2579In POSIX mode, this does not clear the 2580.Ic verbose 2581or 2582.Ic xtrace 2583options; in non-POSIX mode, it does. 2584.It 2585.Ic set 2586exit status. 2587In POSIX mode, the exit status of 2588.Ic set 2589is 0 if there are no errors; 2590in non-POSIX mode, the exit status is that of any 2591command substitutions performed in generating the 2592.Ic set 2593command. 2594For example, 2595.Ic set -- `false`; echo $?\& 2596prints 0 in POSIX mode, 1 in non-POSIX mode. 2597This construct is used in most shell scripts that use the old 2598.Xr getopt 1 2599command. 2600.It 2601Argument expansion of the 2602.Ic alias , 2603.Ic export , 2604.Ic readonly , 2605and 2606.Ic typeset 2607commands. 2608In POSIX mode, normal argument expansion is done; in non-POSIX mode, 2609field splitting, file globbing, brace expansion, and (normal) tilde expansion 2610are turned off, while assignment tilde expansion is turned on. 2611.It 2612Signal specification. 2613In POSIX mode, signals can be specified as digits, only 2614if signal numbers match POSIX values 2615(i.e. HUP=1, INT=2, QUIT=3, ABRT=6, KILL=9, ALRM=14, and TERM=15); 2616in non-POSIX mode, signals can always be digits. 2617.It 2618Alias expansion. 2619In POSIX mode, alias expansion is only carried out when reading command words; 2620in non-POSIX mode, alias expansion is carried out on any 2621word following an alias that ended in a space. 2622For example, the following 2623.Ic for 2624loop uses parameter 2625.Sq i 2626in POSIX mode and 2627.Sq j 2628in non-POSIX mode: 2629.Bd -literal -offset indent 2630alias a='for ' i='j' 2631a i in 1 2; do echo i=$i j=$j; done 2632.Ed 2633.It 2634.Ic test . 2635In POSIX mode, the expression 2636.Sq Fl t 2637(preceded by some number of 2638.Sq \&! 2639arguments) is always true as it is a non-zero length string; 2640in non-POSIX mode, it tests if file descriptor 1 is a 2641.Xr tty 4 2642(i.e. the 2643.Ar fd 2644argument to the 2645.Fl t 2646test may be left out and defaults to 1). 2647.El 2648.Ss Strict Bourne shell mode 2649When the 2650.Ic sh 2651option is enabled (see the 2652.Ic set 2653command), 2654.Nm 2655will behave like 2656.Xr sh 1 2657in the following ways: 2658.Bl -bullet 2659.It 2660The parameter 2661.Ic $_ 2662is not set to: 2663.Pp 2664.Bl -dash -compact 2665.It 2666the expanded alias' full program path after entering commands 2667that are tracked aliases 2668.It 2669the last argument on the command line after entering external 2670commands 2671.It 2672the file that changed when 2673.Ev MAILPATH 2674is set to monitor a mailbox 2675.El 2676.It 2677File descriptors are left untouched when executing 2678.Ic exec 2679with no arguments. 2680.It 2681Backslash-escaped special characters are not substituted in 2682.Ev PS1 . 2683.It 2684Sequences of 2685.Sq ((...)) 2686are not interpreted as arithmetic expressions. 2687.El 2688.Ss Command execution 2689After evaluation of command-line arguments, redirections, and parameter 2690assignments, the type of command is determined: a special built-in, a 2691function, a regular built-in, or the name of a file to execute found using the 2692.Ev PATH 2693parameter. 2694The checks are made in the above order. 2695Special built-in commands differ from other commands in that the 2696.Ev PATH 2697parameter is not used to find them, an error during their execution can 2698cause a non-interactive shell to exit, and parameter assignments that are 2699specified before the command are kept after the command completes. 2700Just to confuse things, if the 2701.Ic posix 2702option is turned off (see the 2703.Ic set 2704command below), some special commands are very special in that no field 2705splitting, file globbing, brace expansion, nor tilde expansion is performed 2706on arguments that look like assignments. 2707Regular built-in commands are different only in that the 2708.Ev PATH 2709parameter is not used to find them. 2710.Pp 2711The original 2712.Nm ksh 2713and POSIX differ somewhat in which commands are considered 2714special or regular: 2715.Pp 2716POSIX special commands 2717.Pp 2718.Ic \&. , \&: , break , continue , 2719.Ic eval , exec , exit , export , 2720.Ic readonly , return , set , shift , 2721.Ic times , trap , unset 2722.Pp 2723Additional 2724.Nm 2725special commands 2726.Pp 2727.Ic builtin , typeset 2728.Pp 2729Very special commands 2730.Pq when POSIX mode is off 2731.Pp 2732.Ic alias , readonly , set , typeset 2733.Pp 2734POSIX regular commands 2735.Pp 2736.Ic alias , bg , cd , command , 2737.Ic false , fc , fg , getopts , 2738.Ic jobs , kill , pwd , read , 2739.Ic true , umask , unalias , wait 2740.Pp 2741Additional 2742.Nm 2743regular commands 2744.Pp 2745.Ic \&[ , echo , let , mknod , 2746.Ic print , suspend , test , 2747.Ic ulimit , whence 2748.Pp 2749In the future, the additional 2750.Nm 2751special and regular commands may be treated 2752differently from the POSIX special and regular commands. 2753.Pp 2754Once the type of command has been determined, any command-line parameter 2755assignments are performed and exported for the duration of the command. 2756.Pp 2757The following describes the special and regular built-in commands: 2758.Pp 2759.Bl -tag -width Ds -compact 2760.It Ic \&. Ar file Op Ar arg ... 2761Execute the commands in 2762.Ar file 2763in the current environment. 2764The file is searched for in the directories of 2765.Ev PATH . 2766If arguments are given, the positional parameters may be used to access them 2767while 2768.Ar file 2769is being executed. 2770If no arguments are given, the positional parameters are 2771those of the environment the command is used in. 2772.Pp 2773.It Ic \&: Op Ar ... 2774The null command. 2775Exit status is set to zero. 2776.Pp 2777.It Xo Ic alias 2778.Oo Fl d \*(Ba t Oo Fl r Oc \*(Ba 2779.Cm +-x Oc 2780.Op Fl p 2781.Op Cm + 2782.Oo Ar name 2783.Op Ns = Ns Ar value 2784.Ar ... Oc 2785.Xc 2786Without arguments, 2787.Ic alias 2788lists all aliases. 2789For any name without a value, the existing alias is listed. 2790Any name with a value defines an alias (see 2791.Sx Aliases 2792above). 2793.Pp 2794When listing aliases, one of two formats is used. 2795Normally, aliases are listed as 2796.Ar name Ns = Ns Ar value , 2797where 2798.Ar value 2799is quoted. 2800If options were preceded with 2801.Ql + , 2802or a lone 2803.Ql + 2804is given on the command line, only 2805.Ar name 2806is printed. 2807.Pp 2808The 2809.Fl d 2810option causes directory aliases, which are used in tilde expansion, to be 2811listed or set (see 2812.Sx Tilde expansion 2813above). 2814.Pp 2815If the 2816.Fl p 2817option is used, each alias is prefixed with the string 2818.Dq alias\ \& . 2819.Pp 2820The 2821.Fl t 2822option indicates that tracked aliases are to be listed/set (values specified on 2823the command line are ignored for tracked aliases). 2824The 2825.Fl r 2826option indicates that all tracked aliases are to be reset. 2827.Pp 2828The 2829.Fl x 2830option sets 2831.Pq Ic +x No clears 2832the export attribute of an alias or, if no names are given, lists the aliases 2833with the export attribute (exporting an alias has no effect). 2834.Pp 2835.It Ic bg Op Ar job ... 2836Resume the specified stopped job(s) in the background. 2837If no jobs are specified, 2838.Ic %+ 2839is assumed. 2840See 2841.Sx Job control 2842below for more information. 2843.Pp 2844.It Ic bind Op Fl l 2845The current bindings are listed. 2846If the 2847.Fl l 2848flag is given, 2849.Ic bind 2850instead lists the names of the functions to which keys may be bound. 2851See 2852.Sx Emacs editing mode 2853for more information. 2854.Pp 2855.It Xo Ic bind Op Fl m 2856.Ar string Ns = Ns Op Ar substitute 2857.Ar ... 2858.Xc 2859.It Xo Ic bind 2860.Ar string Ns = Ns Op Ar editing-command 2861.Ar ... 2862.Xc 2863The specified editing command is bound to the given 2864.Ar string , 2865which should consist of a control character 2866optionally preceded by one of the two prefix characters. 2867Future input of the 2868.Ar string 2869will cause the editing command to be immediately invoked. 2870If the 2871.Fl m 2872flag is given, the specified input 2873.Ar string 2874will afterwards be immediately replaced by the given 2875.Ar substitute 2876string, which may contain editing commands. 2877.Pp 2878Control characters may be written using caret notation 2879i.e. ^X represents Control-X. 2880Multi-character sequences are supported. 2881.Pp 2882The following default bindings show how the arrow keys 2883on an ANSI terminal or xterm are bound 2884(of course some escape sequences won't work out quite this nicely): 2885.Bd -literal -offset indent 2886bind '^[[A'=up-history 2887bind '^[[B'=down-history 2888bind '^[[C'=forward-char 2889bind '^[[D'=backward-char 2890.Ed 2891.Pp 2892.It Ic break Op Ar level 2893Exit the 2894.Ar level Ns th 2895inner-most 2896.Ic for , 2897.Ic select , 2898.Ic until , 2899or 2900.Ic while 2901loop. 2902.Ar level 2903defaults to 1. 2904.Pp 2905.It Ic builtin Ar command Op Ar arg ... 2906Execute the built-in command 2907.Ar command . 2908.Pp 2909.It Xo 2910.Ic cd 2911.Op Fl LP 2912.Op Ar dir 2913.Xc 2914Set the working directory to 2915.Ar dir . 2916If the parameter 2917.Ev CDPATH 2918is set, it lists the search path for the directory containing 2919.Ar dir . 2920A 2921.Dv NULL 2922path means the current directory. 2923If 2924.Ar dir 2925is found in any component of the 2926.Ev CDPATH 2927search path other than the 2928.Dv NULL 2929path, the name of the new working directory will be written to standard output. 2930If 2931.Ar dir 2932is missing, the home directory 2933.Ev HOME 2934is used. 2935If 2936.Ar dir 2937is 2938.Ql - , 2939the previous working directory is used (see the 2940.Ev OLDPWD 2941parameter). 2942.Pp 2943If the 2944.Fl L 2945option (logical path) is used or if the 2946.Ic physical 2947option isn't set (see the 2948.Ic set 2949command below), references to 2950.Sq .. 2951in 2952.Ar dir 2953are relative to the path used to get to the directory. 2954If the 2955.Fl P 2956option (physical path) is used or if the 2957.Ic physical 2958option is set, 2959.Sq .. 2960is relative to the filesystem directory tree. 2961The 2962.Ev PWD 2963and 2964.Ev OLDPWD 2965parameters are updated to reflect the current and old working directory, 2966respectively. 2967.Pp 2968.It Xo 2969.Ic cd 2970.Op Fl LP 2971.Ar old new 2972.Xc 2973The string 2974.Ar new 2975is substituted for 2976.Ar old 2977in the current directory, and the shell attempts to change to the new 2978directory. 2979.Pp 2980.It Xo 2981.Ic command 2982.Op Fl pVv 2983.Ar cmd 2984.Op Ar arg ... 2985.Xc 2986If neither the 2987.Fl v 2988nor 2989.Fl V 2990option is given, 2991.Ar cmd 2992is executed exactly as if 2993.Ic command 2994had not been specified, with two exceptions: 2995firstly, 2996.Ar cmd 2997cannot be a shell function; 2998and secondly, special built-in commands lose their specialness 2999(i.e. redirection and utility errors do not cause the shell to 3000exit, and command assignments are not permanent). 3001.Pp 3002If the 3003.Fl p 3004option is given, a default search path is used instead of the current value of 3005.Ev PATH 3006(the actual value of the default path is system dependent: on 3007POSIX-ish systems, it is the value returned by 3008.Ic getconf CS_PATH ) . 3009.Pp 3010If the 3011.Fl v 3012option is given, instead of executing 3013.Ar cmd , 3014information about what would be executed is given (and the same is done for 3015.Ar arg ... ) . 3016For special and regular built-in commands and functions, their names are simply 3017printed; for aliases, a command that defines them is printed; and for commands 3018found by searching the 3019.Ev PATH 3020parameter, the full path of the command is printed. 3021If no command is found 3022(i.e. the path search fails), nothing is printed and 3023.Ic command 3024exits with a non-zero status. 3025The 3026.Fl V 3027option is like the 3028.Fl v 3029option, except it is more verbose. 3030.Pp 3031.It Ic continue Op Ar level 3032Jumps to the beginning of the 3033.Ar level Ns th 3034inner-most 3035.Ic for , 3036.Ic select , 3037.Ic until , 3038or 3039.Ic while 3040loop. 3041.Ar level 3042defaults to 1. 3043.Pp 3044.It Xo 3045.Ic echo 3046.Op Fl Een 3047.Op Ar arg ... 3048.Xc 3049Prints its arguments (separated by spaces) followed by a newline, to the 3050standard output. 3051The newline is suppressed if any of the arguments contain the 3052backslash sequence 3053.Ql \ec . 3054See the 3055.Ic print 3056command below for a list of other backslash sequences that are recognized. 3057.Pp 3058The options are provided for compatibility with 3059.Bx 3060shell scripts. 3061The 3062.Fl n 3063option suppresses the trailing newline, 3064.Fl e 3065enables backslash interpretation (a no-op, since this is normally done), and 3066.Fl E 3067suppresses backslash interpretation. 3068If the 3069.Ic posix 3070option is set, only the first argument is treated as an option, and only 3071if it is exactly 3072.Dq -n . 3073.Pp 3074.It Ic eval Ar command ... 3075The arguments are concatenated (with spaces between them) to form a single 3076string which the shell then parses and executes in the current environment. 3077.Pp 3078.It Xo 3079.Ic exec 3080.Op Ar command Op Ar arg ... 3081.Xc 3082The command is executed without forking, replacing the shell process. 3083.Pp 3084If no command is given except for I/O redirection, the I/O redirection is 3085permanent and the shell is 3086not replaced. 3087Any file descriptors greater than 2 which are opened or 3088.Xr dup 2 Ns 'd 3089in this way are not made available to other executed commands (i.e. commands 3090that are not built-in to the shell). 3091Note that the Bourne shell differs here; 3092it does pass these file descriptors on. 3093.Pp 3094.It Ic exit Op Ar status 3095The shell exits with the specified exit status. 3096If 3097.Ar status 3098is not specified, the exit status is the current value of the 3099.Ic $?\& 3100parameter. 3101.Pp 3102.It Xo 3103.Ic export 3104.Op Fl p 3105.Op Ar parameter Ns Op = Ns Ar value 3106.Xc 3107Sets the export attribute of the named parameters. 3108Exported parameters are passed in the environment to executed commands. 3109If values are specified, the named parameters are also assigned. 3110.Pp 3111If no parameters are specified, the names of all parameters with the export 3112attribute are printed one per line, unless the 3113.Fl p 3114option is used, in which case 3115.Ic export 3116commands defining all exported parameters, including their values, are printed. 3117.Pp 3118.It Ic false 3119A command that exits with a non-zero status. 3120.Pp 3121.It Xo 3122.Ic fc 3123.Oo 3124.Fl e Ar editor \*(Ba 3125.Fl l Op Fl n 3126.Oc 3127.Op Fl r 3128.Op Ar first Op Ar last 3129.Xc 3130.Ar first 3131and 3132.Ar last 3133select commands from the history. 3134Commands can be selected by history number 3135or a string specifying the most recent command starting with that string. 3136The 3137.Fl l 3138option lists the command on standard output, and 3139.Fl n 3140inhibits the default command numbers. 3141The 3142.Fl r 3143option reverses the order of the list. 3144Without 3145.Fl l , 3146the selected commands are edited by the editor specified with the 3147.Fl e 3148option, or if no 3149.Fl e 3150is specified, the editor specified by the 3151.Ev FCEDIT 3152parameter (if this parameter is not set, 3153.Pa /bin/ed 3154is used), and then executed by the shell. 3155.Pp 3156.It Xo 3157.Ic fc 3158.Cm -e - \*(Ba Fl s 3159.Op Fl g 3160.Op Ar old Ns = Ns Ar new 3161.Op Ar prefix 3162.Xc 3163Re-execute the selected command (the previous command by default) after 3164performing the optional substitution of 3165.Ar old 3166with 3167.Ar new . 3168If 3169.Fl g 3170is specified, all occurrences of 3171.Ar old 3172are replaced with 3173.Ar new . 3174The meaning of 3175.Cm -e - 3176and 3177.Fl s 3178is identical: re-execute the selected command without invoking an editor. 3179This command is usually accessed with the predefined 3180.Ic alias r='fc -e -' . 3181.Pp 3182.It Ic fg Op Ar job ... 3183Resume the specified job(s) in the foreground. 3184If no jobs are specified, 3185.Ic %+ 3186is assumed. 3187See 3188.Sx Job control 3189below for more information. 3190.Pp 3191.It Xo 3192.Ic getopts 3193.Ar optstring name 3194.Op Ar arg ... 3195.Xc 3196Used by shell procedures to parse the specified arguments (or positional 3197parameters, if no arguments are given) and to check for legal options. 3198.Ar optstring 3199contains the option letters that 3200.Ic getopts 3201is to recognize. 3202If a letter is followed by a colon, the option is expected to 3203have an argument. 3204Options that do not take arguments may be grouped in a single argument. 3205If an option takes an argument and the option character is not the 3206last character of the argument it is found in, the remainder of the argument is 3207taken to be the option's argument; otherwise, the next argument is the option's 3208argument. 3209.Pp 3210Each time 3211.Ic getopts 3212is invoked, it places the next option in the shell parameter 3213.Ar name 3214and the index of the argument to be processed by the next call to 3215.Ic getopts 3216in the shell parameter 3217.Ev OPTIND . 3218If the option was introduced with a 3219.Ql + , 3220the option placed in 3221.Ar name 3222is prefixed with a 3223.Ql + . 3224When an option requires an argument, 3225.Ic getopts 3226places it in the shell parameter 3227.Ev OPTARG . 3228.Pp 3229When an illegal option or a missing option argument is encountered, a question 3230mark or a colon is placed in 3231.Ar name 3232(indicating an illegal option or missing argument, respectively) and 3233.Ev OPTARG 3234is set to the option character that caused the problem. 3235Furthermore, if 3236.Ar optstring 3237does not begin with a colon, a question mark is placed in 3238.Ar name , 3239.Ev OPTARG 3240is unset, and an error message is printed to standard error. 3241.Pp 3242When the end of the options is encountered, 3243.Ic getopts 3244exits with a non-zero exit status. 3245Options end at the first (non-option 3246argument) argument that does not start with a 3247.Ql - , 3248or when a 3249.Ql -- 3250argument is encountered. 3251.Pp 3252Option parsing can be reset by setting 3253.Ev OPTIND 3254to 1 (this is done automatically whenever the shell or a shell procedure is 3255invoked). 3256.Pp 3257Warning: Changing the value of the shell parameter 3258.Ev OPTIND 3259to a value other than 1, or parsing different sets of arguments without 3260resetting 3261.Ev OPTIND , 3262may lead to unexpected results. 3263.Pp 3264.It Xo 3265.Ic hash 3266.Op Fl r 3267.Op Ar name ... 3268.Xc 3269Without arguments, any hashed executable command pathnames are listed. 3270The 3271.Fl r 3272option causes all hashed commands to be removed from the hash table. 3273Each 3274.Ar name 3275is searched as if it were a command name and added to the hash table if it is 3276an executable command. 3277.Pp 3278.It Xo 3279.Ic jobs 3280.Op Fl lnp 3281.Op Ar job ... 3282.Xc 3283Display information about the specified job(s); if no jobs are specified, all 3284jobs are displayed. 3285The 3286.Fl n 3287option causes information to be displayed only for jobs that have changed 3288state since the last notification. 3289If the 3290.Fl l 3291option is used, the process ID of each process in a job is also listed. 3292The 3293.Fl p 3294option causes only the process group of each job to be printed. 3295See 3296.Sx Job control 3297below for the format of 3298.Ar job 3299and the displayed job. 3300.Pp 3301.It Xo 3302.Ic kill 3303.Oo Fl s Ar signame \*(Ba 3304.No - Ns Ar signum \*(Ba 3305.No - Ns Ar signame Oc 3306.No { Ar job \*(Ba pid \*(Ba pgrp No } 3307.Ar ... 3308.Xc 3309Send the specified signal to the specified jobs, process IDs, or process 3310groups. 3311If no signal is specified, the 3312.Dv TERM 3313signal is sent. 3314If a job is specified, the signal is sent to the job's process group. 3315See 3316.Sx Job control 3317below for the format of 3318.Ar job . 3319.Pp 3320.It Xo 3321.Ic kill 3322.Fl l 3323.Op Ar exit-status ... 3324.Xc 3325Print the signal name corresponding to 3326.Ar exit-status . 3327If no arguments are specified, a list of all the signals, their numbers, and 3328a short description of them are printed. 3329.Pp 3330.It Ic let Op Ar expression ... 3331Each expression is evaluated (see 3332.Sx Arithmetic expressions 3333above). 3334If all expressions are successfully evaluated, the exit status is 0 (1) 3335if the last expression evaluated to non-zero (zero). 3336If an error occurs during 3337the parsing or evaluation of an expression, the exit status is greater than 1. 3338Since expressions may need to be quoted, 3339.No (( Ar expr No )) 3340is syntactic sugar for 3341.No let \&" Ns Ar expr Ns \&" . 3342.Pp 3343.It Xo 3344.Ic mknod 3345.Op Fl m Ar mode 3346.Ar name 3347.Cm b\*(Bac 3348.Ar major minor 3349.Xc 3350.It Xo 3351.Ic mknod 3352.Op Fl m Ar mode 3353.Ar name 3354.Cm p 3355.Xc 3356Create a device special file. 3357The file type may be 3358.Cm b 3359(block type device), 3360.Cm c 3361(character type device), 3362or 3363.Cm p 3364(named pipe). 3365The file created may be modified according to its 3366.Ar mode 3367(via the 3368.Fl m 3369option), 3370.Ar major 3371(major device number), 3372and 3373.Ar minor 3374(minor device number). 3375.Pp 3376See 3377.Xr mknod 8 3378for further information. 3379.Pp 3380.It Xo 3381.Ic print 3382.Oo 3383.Fl nprsu Ns Oo Ar n Oc \*(Ba 3384.Fl R Op Fl en 3385.Oc 3386.Op Ar argument ... 3387.Xc 3388.Ic print 3389prints its arguments on the standard output, separated by spaces and 3390terminated with a newline. 3391The 3392.Fl n 3393option suppresses the newline. 3394By default, certain C escapes are translated. 3395These include 3396.Ql \eb , 3397.Ql \ef , 3398.Ql \en , 3399.Ql \er , 3400.Ql \et , 3401.Ql \ev , 3402and 3403.Ql \e0### 3404.Po 3405.Ql # 3406is an octal digit, of which there may be 0 to 3 3407.Pc . 3408.Ql \ec 3409is equivalent to using the 3410.Fl n 3411option. 3412.Ql \e 3413expansion may be inhibited with the 3414.Fl r 3415option. 3416The 3417.Fl s 3418option prints to the history file instead of standard output; the 3419.Fl u 3420option prints to file descriptor 3421.Ar n 3422.Po 3423.Ar n 3424defaults to 1 if omitted 3425.Pc ; 3426and the 3427.Fl p 3428option prints to the co-process (see 3429.Sx Co-processes 3430above). 3431.Pp 3432The 3433.Fl R 3434option is used to emulate, to some degree, the 3435.Bx 3436.Xr echo 1 3437command, which does not process 3438.Ql \e 3439sequences unless the 3440.Fl e 3441option is given. 3442As above, the 3443.Fl n 3444option suppresses the trailing newline. 3445.Pp 3446.It Ic pwd Op Fl LP 3447Print the present working directory. 3448If the 3449.Fl L 3450option is used or if the 3451.Ic physical 3452option isn't set (see the 3453.Ic set 3454command below), the logical path is printed (i.e. the path used to 3455.Ic cd 3456to the current directory). 3457If the 3458.Fl P 3459option (physical path) is used or if the 3460.Ic physical 3461option is set, the path determined from the filesystem (by following 3462.Sq .. 3463directories to the root directory) is printed. 3464.Pp 3465.It Xo 3466.Ic read 3467.Op Fl prsu Ns Op Ar n 3468.Op Ar parameter ... 3469.Xc 3470Reads a line of input from the standard input, separates the line into fields 3471using the 3472.Ev IFS 3473parameter (see 3474.Sx Substitution 3475above), and assigns each field to the specified parameters. 3476If there are more parameters than fields, the extra parameters are set to 3477.Dv NULL , 3478or alternatively, if there are more fields than parameters, the last parameter 3479is assigned the remaining fields (inclusive of any separating spaces). 3480If no parameters are specified, the 3481.Ev REPLY 3482parameter is used. 3483If the input line ends in a backslash and the 3484.Fl r 3485option was not used, the backslash and the newline are stripped and more input 3486is read. 3487If no input is read, 3488.Ic read 3489exits with a non-zero status. 3490.Pp 3491The first parameter may have a question mark and a string appended to it, in 3492which case the string is used as a prompt (printed to standard error before 3493any input is read) if the input is a 3494.Xr tty 4 3495(e.g.\& 3496.Ic read nfoo?'number of foos: ' ) . 3497.Pp 3498The 3499.Fl u Ns Ar n 3500and 3501.Fl p 3502options cause input to be read from file descriptor 3503.Ar n 3504.Pf ( Ar n 3505defaults to 0 if omitted) 3506or the current co-process (see 3507.Sx Co-processes 3508above for comments on this), respectively. 3509If the 3510.Fl s 3511option is used, input is saved to the history file. 3512.Pp 3513.It Xo 3514.Ic readonly 3515.Op Fl p 3516.Oo Ar parameter 3517.Op Ns = Ns Ar value 3518.Ar ... Oc 3519.Xc 3520Sets the read-only attribute of the named parameters. 3521If values are given, 3522parameters are set to them before setting the attribute. 3523Once a parameter is 3524made read-only, it cannot be unset and its value cannot be changed. 3525.Pp 3526If no parameters are specified, the names of all parameters with the read-only 3527attribute are printed one per line, unless the 3528.Fl p 3529option is used, in which case 3530.Ic readonly 3531commands defining all read-only parameters, including their values, are 3532printed. 3533.Pp 3534.It Ic return Op Ar status 3535Returns from a function or 3536.Ic .\& 3537script, with exit status 3538.Ar status . 3539If no 3540.Ar status 3541is given, the exit status of the last executed command is used. 3542If used outside of a function or 3543.Ic .\& 3544script, it has the same effect as 3545.Ic exit . 3546Note that 3547.Nm pdksh 3548treats both profile and 3549.Ev ENV 3550files as 3551.Ic .\& 3552scripts, while the original Korn shell only treats profiles as 3553.Ic .\& 3554scripts. 3555.Pp 3556.It Xo 3557.Ic set Op Ic +-abCefhkmnpsuvXx 3558.Op Ic +-o Ar option 3559.Op Ic +-A Ar name 3560.Op Fl - 3561.Op Ar arg ... 3562.Xc 3563The 3564.Ic set 3565command can be used to set 3566.Pq Ic - 3567or clear 3568.Pq Ic + 3569shell options, set the positional parameters, or set an array parameter. 3570Options can be changed using the 3571.Cm +-o Ar option 3572syntax, where 3573.Ar option 3574is the long name of an option, or using the 3575.Cm +- Ns Ar letter 3576syntax, where 3577.Ar letter 3578is the option's single letter name (not all options have a single letter name). 3579The following table lists both option letters (if they exist) and long names 3580along with a description of what the option does: 3581.Bl -tag -width 15n 3582.It Fl A Ar name 3583Sets the elements of the array parameter 3584.Ar name 3585to 3586.Ar arg ... 3587If 3588.Fl A 3589is used, the array is reset (i.e. emptied) first; if 3590.Ic +A 3591is used, the first N elements are set (where N is the number of arguments); 3592the rest are left untouched. 3593.It Fl a \*(Ba Ic allexport 3594All new parameters are created with the export attribute. 3595.It Fl b \*(Ba Ic notify 3596Print job notification messages asynchronously, instead of just before the 3597prompt. 3598Only used if job control is enabled 3599.Pq Fl m . 3600.It Fl C \*(Ba Ic noclobber 3601Prevent \*(Gt redirection from overwriting existing files. 3602Instead, \*(Gt\*(Ba must be used to force an overwrite. 3603.It Fl e \*(Ba Ic errexit 3604Exit (after executing the 3605.Dv ERR 3606trap) as soon as an error occurs or a command fails (i.e. exits with a 3607non-zero status). 3608This does not apply to commands whose exit status is 3609explicitly tested by a shell construct such as 3610.Ic if , 3611.Ic until , 3612.Ic while , 3613or 3614.Ic !\& 3615statements. 3616For 3617.Ic && 3618or 3619.Ic || , 3620only the status of the last command is tested. 3621.It Fl f \*(Ba Ic noglob 3622Do not expand file name patterns. 3623.It Fl h \*(Ba Ic trackall 3624Create tracked aliases for all executed commands (see 3625.Sx Aliases 3626above). 3627Enabled by default for non-interactive shells. 3628.It Fl k \*(Ba Ic keyword 3629Parameter assignments are recognized anywhere in a command. 3630.It Fl m \*(Ba Ic monitor 3631Enable job control (default for interactive shells). 3632.It Fl n \*(Ba Ic noexec 3633Do not execute any commands. 3634Useful for checking the syntax of scripts 3635(ignored if interactive). 3636.It Fl p \*(Ba Ic privileged 3637The shell is a privileged shell. 3638It is set automatically if, when the shell starts, 3639the real UID or GID does not match 3640the effective UID (EUID) or GID (EGID), respectively. 3641See above for a description of what this means. 3642.It Fl s \*(Ba Ic stdin 3643If used when the shell is invoked, commands are read from standard input. 3644Set automatically if the shell is invoked with no arguments. 3645.Pp 3646When 3647.Fl s 3648is used with the 3649.Ic set 3650command it causes the specified arguments to be sorted before assigning them to 3651the positional parameters (or to array 3652.Ar name , 3653if 3654.Fl A 3655is used). 3656.It Fl u \*(Ba Ic nounset 3657Referencing of an unset parameter is treated as an error, unless one of the 3658.Ql - , 3659.Ql + , 3660or 3661.Ql = 3662modifiers is used. 3663.It Fl v \*(Ba Ic verbose 3664Write shell input to standard error as it is read. 3665.It Fl X \*(Ba Ic markdirs 3666Mark directories with a trailing 3667.Ql / 3668during file name generation. 3669.It Fl x \*(Ba Ic xtrace 3670Print commands and parameter assignments when they are executed, preceded by 3671the value of 3672.Ev PS4 . 3673.It Ic bgnice 3674Background jobs are run with lower priority. 3675.It Ic braceexpand 3676Enable brace expansion (a.k.a. alternation). 3677.It Ic csh-history 3678Enables a subset of 3679.Xr csh 1 Ns -style 3680history editing using the 3681.Ql !\& 3682character. 3683.It Ic emacs 3684Enable BRL emacs-like command-line editing (interactive shells only); see 3685.Sx Emacs editing mode . 3686.It Ic emacs-usemeta 3687In emacs command-line editing, use the 8th bit as meta (^[) prefix. 3688This is the default. 3689.It Ic gmacs 3690Enable gmacs-like command-line editing (interactive shells only). 3691Currently identical to emacs editing except that transpose (^T) acts slightly 3692differently. 3693.It Ic ignoreeof 3694The shell will not (easily) exit when end-of-file is read; 3695.Ic exit 3696must be used. 3697To avoid infinite loops, the shell will exit if 3698.Dv EOF 3699is read 13 times in a row. 3700.It Ic interactive 3701The shell is an interactive shell. 3702This option can only be used when the shell is invoked. 3703See above for a description of what this means. 3704.It Ic login 3705The shell is a login shell. 3706This option can only be used when the shell is invoked. 3707See above for a description of what this means. 3708.It Ic nohup 3709Do not kill running jobs with a 3710.Dv SIGHUP 3711signal when a login shell exits. 3712Currently set by default, but this will 3713change in the future to be compatible with the original Korn shell (which 3714doesn't have this option, but does send the 3715.Dv SIGHUP 3716signal). 3717.It Ic nolog 3718No effect. 3719In the original Korn shell, this prevents function definitions from 3720being stored in the history file. 3721.It Ic physical 3722Causes the 3723.Ic cd 3724and 3725.Ic pwd 3726commands to use 3727.Dq physical 3728(i.e. the filesystem's) 3729.Sq .. 3730directories instead of 3731.Dq logical 3732directories (i.e. the shell handles 3733.Sq .. , 3734which allows the user to be oblivious of symbolic links to directories). 3735Clear by default. 3736Note that setting this option does not affect the current value of the 3737.Ev PWD 3738parameter; only the 3739.Ic cd 3740command changes 3741.Ev PWD . 3742See the 3743.Ic cd 3744and 3745.Ic pwd 3746commands above for more details. 3747.It Ic posix 3748Enable POSIX mode. 3749See 3750.Sx POSIX mode 3751above. 3752.It Ic restricted 3753The shell is a restricted shell. 3754This option can only be used when the shell is invoked. 3755See above for a description of what this means. 3756.It Ic sh 3757Enable strict Bourne shell mode (see 3758.Sx Strict Bourne shell mode 3759above). 3760.It Ic vi 3761Enable 3762.Xr vi 1 Ns -like 3763command-line editing (interactive shells only). 3764.It Ic vi-esccomplete 3765In vi command-line editing, do command and file name completion when escape 3766(^[) is entered in command mode. 3767.It Ic vi-show8 3768Prefix characters with the eighth bit set with 3769.Sq M- . 3770If this option is not set, characters in the range 128\-160 are printed as is, 3771which may cause problems. 3772.It Ic vi-tabcomplete 3773In vi command-line editing, do command and file name completion when tab (^I) 3774is entered in insert mode. 3775This is the default. 3776.It Ic viraw 3777No effect. 3778In the original Korn shell, unless 3779.Ic viraw 3780was set, the vi command-line mode would let the 3781.Xr tty 4 3782driver do the work until ESC (^[) was entered. 3783.Nm pdksh 3784is always in viraw mode. 3785.El 3786.Pp 3787These options can also be used upon invocation of the shell. 3788The current set of 3789options (with single letter names) can be found in the parameter 3790.Sq $- . 3791.Ic set Fl o 3792with no option name will list all the options and whether each is on or off; 3793.Ic set +o 3794will print the long names of all options that are currently on. 3795.Pp 3796Remaining arguments, if any, are positional parameters and are assigned, in 3797order, to the positional parameters (i.e. $1, $2, etc.). 3798If options end with 3799.Ql -- 3800and there are no remaining arguments, all positional parameters are cleared. 3801If no options or arguments are given, the values of all names are printed. 3802For unknown historical reasons, a lone 3803.Ql - 3804option is treated specially \- it clears both the 3805.Fl x 3806and 3807.Fl v 3808options. 3809.Pp 3810.It Ic shift Op Ar number 3811The positional parameters 3812.Ar number Ns +1 , 3813.Ar number Ns +2 , 3814etc. are renamed to 3815.Sq 1 , 3816.Sq 2 , 3817etc. 3818.Ar number 3819defaults to 1. 3820.Pp 3821.It Ic suspend 3822Stops the shell as if it had received the suspend character from 3823the terminal. 3824It is not possible to suspend a login shell unless the parent process 3825is a member of the same terminal session but is a member of a different 3826process group. 3827As a general rule, if the shell was started by another shell or via 3828.Xr su 1 , 3829it can be suspended. 3830.Pp 3831.It Ic test Ar expression 3832.It Ic \&[ Ar expression Ic \&] 3833.Ic test 3834evaluates the 3835.Ar expression 3836and returns zero status if true, 1 if false, or greater than 1 if there 3837was an error. 3838It is normally used as the condition command of 3839.Ic if 3840and 3841.Ic while 3842statements. 3843Symbolic links are followed for all 3844.Ar file 3845expressions except 3846.Fl h 3847and 3848.Fl L . 3849.Pp 3850The following basic expressions are available: 3851.Bl -tag -width 17n 3852.It Fl a Ar file 3853.Ar file 3854exists. 3855.It Fl b Ar file 3856.Ar file 3857is a block special device. 3858.It Fl c Ar file 3859.Ar file 3860is a character special device. 3861.It Fl d Ar file 3862.Ar file 3863is a directory. 3864.It Fl e Ar file 3865.Ar file 3866exists. 3867.It Fl f Ar file 3868.Ar file 3869is a regular file. 3870.It Fl G Ar file 3871.Ar file Ns 's 3872group is the shell's effective group ID. 3873.It Fl g Ar file 3874.Ar file Ns 's 3875mode has the setgid bit set. 3876.It Fl h Ar file 3877.Ar file 3878is a symbolic link. 3879.It Fl k Ar file 3880.Ar file Ns 's 3881mode has the 3882.Xr sticky 8 3883bit set. 3884.It Fl L Ar file 3885.Ar file 3886is a symbolic link. 3887.It Fl O Ar file 3888.Ar file Ns 's 3889owner is the shell's effective user ID. 3890.It Fl o Ar option 3891Shell 3892.Ar option 3893is set (see the 3894.Ic set 3895command above for a list of options). 3896As a non-standard extension, if the option starts with a 3897.Ql \&! , 3898the test is negated; the test always fails if 3899.Ar option 3900doesn't exist (so [ -o foo -o -o !foo ] returns true if and only if option 3901.Ar foo 3902exists). 3903.It Fl p Ar file 3904.Ar file 3905is a named pipe. 3906.It Fl r Ar file 3907.Ar file 3908exists and is readable. 3909.It Fl S Ar file 3910.Ar file 3911is a 3912.Xr unix 4 Ns -domain 3913socket. 3914.It Fl s Ar file 3915.Ar file 3916is not empty. 3917.It Fl t Op Ar fd 3918File descriptor 3919.Ar fd 3920is a 3921.Xr tty 4 3922device. 3923If the 3924.Ic posix 3925option is not set, 3926.Ar fd 3927may be left out, in which case it is taken to be 1 (the behaviour differs due 3928to the special POSIX rules described above). 3929.It Fl u Ar file 3930.Ar file Ns 's 3931mode has the setuid bit set. 3932.It Fl w Ar file 3933.Ar file 3934exists and is writable. 3935.It Fl x Ar file 3936.Ar file 3937exists and is executable. 3938.It Ar file1 Fl nt Ar file2 3939.Ar file1 3940is newer than 3941.Ar file2 3942or 3943.Ar file1 3944exists and 3945.Ar file2 3946does not. 3947.It Ar file1 Fl ot Ar file2 3948.Ar file1 3949is older than 3950.Ar file2 3951or 3952.Ar file2 3953exists and 3954.Ar file1 3955does not. 3956.It Ar file1 Fl ef Ar file2 3957.Ar file1 3958is the same file as 3959.Ar file2 . 3960.It Ar string 3961.Ar string 3962has non-zero length. 3963.It Fl n Ar string 3964.Ar string 3965is not empty. 3966.It Fl z Ar string 3967.Ar string 3968is empty. 3969.It Ar string No = Ar string 3970Strings are equal. 3971.It Ar string No == Ar string 3972Strings are equal. 3973.It Ar string No != Ar string 3974Strings are not equal. 3975.It Ar number Fl eq Ar number 3976Numbers compare equal. 3977.It Ar number Fl ne Ar number 3978Numbers compare not equal. 3979.It Ar number Fl ge Ar number 3980Numbers compare greater than or equal. 3981.It Ar number Fl gt Ar number 3982Numbers compare greater than. 3983.It Ar number Fl le Ar number 3984Numbers compare less than or equal. 3985.It Ar number Fl \< Ar number 3986Numbers compare less than. 3987.El 3988.Pp 3989The above basic expressions, in which unary operators have precedence over 3990binary operators, may be combined with the following operators (listed in 3991increasing order of precedence): 3992.Bd -literal -offset indent 3993expr -o expr Logical OR. 3994expr -a expr Logical AND. 3995! expr Logical NOT. 3996( expr ) Grouping. 3997.Ed 3998.Pp 3999On operating systems not supporting 4000.Pa /dev/fd/ Ns Ar n 4001devices (where 4002.Ar n 4003is a file descriptor number), the 4004.Ic test 4005command will attempt to fake it for all tests that operate on files (except the 4006.Fl e 4007test). 4008For example, 4009[ -w /dev/fd/2 ] tests if file descriptor 2 is writable. 4010.Pp 4011Note that some special rules are applied (courtesy of POSIX) 4012if the number of 4013arguments to 4014.Ic test 4015or 4016.Ic \&[ ... \&] 4017is less than five: if leading 4018.Ql \&! 4019arguments can be stripped such that only one argument remains then a string 4020length test is performed (again, even if the argument is a unary operator); if 4021leading 4022.Ql \&! 4023arguments can be stripped such that three arguments remain and the second 4024argument is a binary operator, then the binary operation is performed (even 4025if the first argument is a unary operator, including an unstripped 4026.Ql \&! ) . 4027.Pp 4028.Sy Note : 4029A common mistake is to use 4030.Dq if \&[ $foo = bar \&] 4031which fails if parameter 4032.Dq foo 4033is 4034.Dv NULL 4035or unset, if it has embedded spaces (i.e.\& 4036.Ev IFS 4037characters), or if it is a unary operator like 4038.Sq \&! 4039or 4040.Sq Fl n . 4041Use tests like 4042.Dq if \&[ \&"X$foo\&" = Xbar \&] 4043instead. 4044.Pp 4045.It Xo 4046.Ic time 4047.Op Fl p 4048.Op Ar pipeline 4049.Xc 4050If a 4051.Ar pipeline 4052is given, the times used to execute the pipeline are reported. 4053If no pipeline 4054is given, then the user and system time used by the shell itself, and all the 4055commands it has run since it was started, are reported. 4056The times reported are the real time (elapsed time from start to finish), 4057the user CPU time (time spent running in user mode), and the system CPU time 4058(time spent running in kernel mode). 4059Times are reported to standard error; the format of the output is: 4060.Pp 4061.Dl "0m0.00s real 0m0.00s user 0m0.00s system" 4062.Pp 4063If the 4064.Fl p 4065option is given the output is slightly longer: 4066.Bd -literal -offset indent 4067real 0.00 4068user 0.00 4069sys 0.00 4070.Ed 4071.Pp 4072It is an error to specify the 4073.Fl p 4074option unless 4075.Ar pipeline 4076is a simple command. 4077.Pp 4078Simple redirections of standard error do not affect the output of the 4079.Ic time 4080command: 4081.Pp 4082.Dl $ time sleep 1 2\*(Gt afile 4083.Dl $ { time sleep 1; } 2\*(Gt afile 4084.Pp 4085Times for the first command do not go to 4086.Dq afile , 4087but those of the second command do. 4088.Pp 4089.It Ic times 4090Print the accumulated user and system times used both by the shell 4091and by processes that the shell started which have exited. 4092The format of the output is: 4093.Bd -literal -offset indent 40940m0.00s 0m0.00s 40950m0.00s 0m0.00s 4096.Ed 4097.Pp 4098.It Ic trap Op Ar handler signal ... 4099Sets a trap handler that is to be executed when any of the specified signals are 4100received. 4101.Ar handler 4102is either a 4103.Dv NULL 4104string, indicating the signals are to be ignored, a minus sign 4105.Pq Sq - , 4106indicating that the default action is to be taken for the signals (see 4107.Xr signal 3 ) , 4108or a string containing shell commands to be evaluated and executed at the first 4109opportunity (i.e. when the current command completes, or before printing the 4110next 4111.Ev PS1 4112prompt) after receipt of one of the signals. 4113.Ar signal 4114is the name of a signal (e.g.\& 4115.Dv PIPE 4116or 4117.Dv ALRM ) 4118or the number of the signal (see the 4119.Ic kill -l 4120command above). 4121.Pp 4122There are two special signals: 4123.Dv EXIT 4124(also known as 0), which is executed when the shell is about to exit, and 4125.Dv ERR , 4126which is executed after an error occurs (an error is something that would cause 4127the shell to exit if the 4128.Fl e 4129or 4130.Ic errexit 4131option were set \- see the 4132.Ic set 4133command above). 4134.Dv EXIT 4135handlers are executed in the environment of the last executed command. 4136Note 4137that for non-interactive shells, the trap handler cannot be changed for signals 4138that were ignored when the shell started. 4139.Pp 4140With no arguments, 4141.Ic trap 4142lists, as a series of 4143.Ic trap 4144commands, the current state of the traps that have been set since the shell 4145started. 4146Note that the output of 4147.Ic trap 4148cannot be usefully piped to another process (an artifact of the fact that 4149traps are cleared when subprocesses are created). 4150.Pp 4151The original Korn shell's 4152.Dv DEBUG 4153trap and the handling of 4154.Dv ERR 4155and 4156.Dv EXIT 4157traps in functions are not yet implemented. 4158.Pp 4159.It Ic true 4160A command that exits with a zero value. 4161.Pp 4162.It Xo 4163.Ic typeset 4164.Oo 4165.Op Ic +-lprtUux 4166.Op Fl L Ns Op Ar n 4167.Op Fl R Ns Op Ar n 4168.Op Fl Z Ns Op Ar n 4169.Op Fl i Ns Op Ar n 4170.No \&| Fl f Op Fl tux 4171.Oc 4172.Oo 4173.Ar name 4174.Op Ns = Ns Ar value 4175.Ar ... 4176.Oc 4177.Xc 4178Display or set parameter attributes. 4179With no 4180.Ar name 4181arguments, parameter attributes are displayed; if no options are used, the 4182current attributes of all parameters are printed as 4183.Ic typeset 4184commands; if an option is given (or 4185.Ql - 4186with no option letter), all parameters and their values with the specified 4187attributes are printed; if options are introduced with 4188.Ql + , 4189parameter values are not printed. 4190.Pp 4191If 4192.Ar name 4193arguments are given, the attributes of the named parameters are set 4194.Pq Ic - 4195or cleared 4196.Pq Ic + . 4197Values for parameters may optionally be specified. 4198If 4199.Ic typeset 4200is used inside a function, any newly created parameters are local to the 4201function. 4202.Pp 4203When 4204.Fl f 4205is used, 4206.Ic typeset 4207operates on the attributes of functions. 4208As with parameters, if no 4209.Ar name 4210arguments are given, 4211functions are listed with their values (i.e. definitions) unless 4212options are introduced with 4213.Ql + , 4214in which case only the function names are reported. 4215.Bl -tag -width Ds 4216.It Fl f 4217Function mode. 4218Display or set functions and their attributes, instead of parameters. 4219.It Fl i Ns Op Ar n 4220Integer attribute. 4221.Ar n 4222specifies the base to use when displaying the integer (if not specified, the 4223base given in the first assignment is used). 4224Parameters with this attribute may 4225be assigned values containing arithmetic expressions. 4226.It Fl L Ns Op Ar n 4227Left justify attribute. 4228.Ar n 4229specifies the field width. 4230If 4231.Ar n 4232is not specified, the current width of a parameter (or the width of its first 4233assigned value) is used. 4234Leading whitespace (and zeros, if used with the 4235.Fl Z 4236option) is stripped. 4237If necessary, values are either truncated or space padded 4238to fit the field width. 4239.It Fl l 4240Lower case attribute. 4241All upper case characters in values are converted to lower case. 4242(In the original Korn shell, this parameter meant 4243.Dq long integer 4244when used with the 4245.Fl i 4246option.) 4247.It Fl p 4248Print complete 4249.Ic typeset 4250commands that can be used to re-create the attributes (but not the values) of 4251parameters. 4252This is the default action (option exists for ksh93 compatibility). 4253.It Fl R Ns Op Ar n 4254Right justify attribute. 4255.Ar n 4256specifies the field width. 4257If 4258.Ar n 4259is not specified, the current width of a parameter (or the width of its first 4260assigned value) is used. 4261Trailing whitespace is stripped. 4262If necessary, values are either stripped of leading characters or space 4263padded to make them fit the field width. 4264.It Fl r 4265Read-only attribute. 4266Parameters with this attribute may not be assigned to or unset. 4267Once this attribute is set, it cannot be turned off. 4268.It Fl t 4269Tag attribute. 4270Has no meaning to the shell; provided for application use. 4271.Pp 4272For functions, 4273.Fl t 4274is the trace attribute. 4275When functions with the trace attribute are executed, the 4276.Ic xtrace 4277.Pq Fl x 4278shell option is temporarily turned on. 4279.It Fl U 4280Unsigned integer attribute. 4281Integers are printed as unsigned values (only 4282useful when combined with the 4283.Fl i 4284option). 4285This option is not in the original Korn shell. 4286.It Fl u 4287Upper case attribute. 4288All lower case characters in values are converted to upper case. 4289(In the original Korn shell, this parameter meant 4290.Dq unsigned integer 4291when used with the 4292.Fl i 4293option, which meant upper case letters would never be used for bases greater 4294than 10. 4295See the 4296.Fl U 4297option.) 4298.Pp 4299For functions, 4300.Fl u 4301is the undefined attribute. 4302See 4303.Sx Functions 4304above for the implications of this. 4305.It Fl x 4306Export attribute. 4307Parameters (or functions) are placed in the environment of 4308any executed commands. 4309Exported functions are not yet implemented. 4310.It Fl Z Ns Op Ar n 4311Zero fill attribute. 4312If not combined with 4313.Fl L , 4314this is the same as 4315.Fl R , 4316except zero padding is used instead of space padding. 4317.El 4318.Pp 4319.It Xo 4320.Ic ulimit 4321.Op Fl acdfHlmnpSst Op Ar value 4322.Ar ... 4323.Xc 4324Display or set process limits. 4325If no options are used, the file size limit 4326.Pq Fl f 4327is assumed. 4328.Ar value , 4329if specified, may be either an arithmetic expression starting with a 4330number or the word 4331.Dq unlimited . 4332The limits affect the shell and any processes created by the shell after a 4333limit is imposed; limits may not be increased once they are set. 4334.Bl -tag -width 5n 4335.It Fl a 4336Display all limits; unless 4337.Fl H 4338is used, soft limits are displayed. 4339.It Fl c Ar n 4340Impose a size limit of 4341.Ar n 4342blocks on the size of core dumps. 4343.It Fl d Ar n 4344Impose a size limit of 4345.Ar n 4346kilobytes on the size of the data area. 4347.It Fl f Ar n 4348Impose a size limit of 4349.Ar n 4350blocks on files written by the shell and its child processes (files of any 4351size may be read). 4352.It Fl H 4353Set the hard limit only (the default is to set both hard and soft limits). 4354.It Fl l Ar n 4355Impose a limit of 4356.Ar n 4357kilobytes on the amount of locked (wired) physical memory. 4358.It Fl m Ar n 4359Impose a limit of 4360.Ar n 4361kilobytes on the amount of physical memory used. 4362.It Fl n Ar n 4363Impose a limit of 4364.Ar n 4365file descriptors that can be open at once. 4366.It Fl p Ar n 4367Impose a limit of 4368.Ar n 4369processes that can be run by the user at any one time. 4370.It Fl S 4371Set the soft limit only (the default is to set both hard and soft limits). 4372.It Fl s Ar n 4373Impose a size limit of 4374.Ar n 4375kilobytes on the size of the stack area. 4376.It Fl t Ar n 4377Impose a time limit of 4378.Ar n 4379CPU seconds spent in user mode to be used by each process. 4380.\".It Fl v Ar n 4381.\"Impose a limit of 4382.\"Ar n 4383.\"kilobytes on the amount of virtual memory used. 4384.El 4385.Pp 4386As far as 4387.Ic ulimit 4388is concerned, a block is 512 bytes. 4389.Pp 4390.It Xo 4391.Ic umask 4392.Op Fl S 4393.Op Ar mask 4394.Xc 4395Display or set the file permission creation mask, or umask (see 4396.Xr umask 2 ) . 4397If the 4398.Fl S 4399option is used, the mask displayed or set is symbolic; otherwise, it is an 4400octal number. 4401.Pp 4402Symbolic masks are like those used by 4403.Xr chmod 1 . 4404When used, they describe what permissions may be made available (as opposed to 4405octal masks in which a set bit means the corresponding bit is to be cleared). 4406For example, 4407.Dq ug=rwx,o= 4408sets the mask so files will not be readable, writable, or executable by 4409.Dq others , 4410and is equivalent (on most systems) to the octal mask 4411.Dq 007 . 4412.Pp 4413.It Xo 4414.Ic unalias 4415.Op Fl adt 4416.Op Ar name ... 4417.Xc 4418The aliases for the given names are removed. 4419If the 4420.Fl a 4421option is used, all aliases are removed. 4422If the 4423.Fl t 4424or 4425.Fl d 4426options are used, the indicated operations are carried out on tracked or 4427directory aliases, respectively. 4428.Pp 4429.It Xo 4430.Ic unset 4431.Op Fl fv 4432.Ar parameter ... 4433.Xc 4434Unset the named parameters 4435.Po 4436.Fl v , 4437the default 4438.Pc 4439or functions 4440.Pq Fl f . 4441The exit status is non-zero if any of the parameters have the read-only 4442attribute set, zero otherwise. 4443.Pp 4444.It Ic wait Op Ar job ... 4445Wait for the specified job(s) to finish. 4446The exit status of 4447.Ic wait 4448is that of the last specified job; if the last job is killed by a signal, the 4449exit status is 128 + the number of the signal (see 4450.Ic kill -l Ar exit-status 4451above); if the last specified job can't be found (because it never existed, or 4452had already finished), the exit status of 4453.Ic wait 4454is 127. 4455See 4456.Sx Job control 4457below for the format of 4458.Ar job . 4459.Ic wait 4460will return if a signal for which a trap has been set is received, or if a 4461.Dv SIGHUP , 4462.Dv SIGINT , 4463or 4464.Dv SIGQUIT 4465signal is received. 4466.Pp 4467If no jobs are specified, 4468.Ic wait 4469waits for all currently running jobs (if any) to finish and exits with a zero 4470status. 4471If job monitoring is enabled, the completion status of jobs is printed 4472(this is not the case when jobs are explicitly specified). 4473.Pp 4474.It Xo 4475.Ic whence 4476.Op Fl pv 4477.Op Ar name ... 4478.Xc 4479For each 4480.Ar name , 4481the type of command is listed (reserved word, built-in, alias, 4482function, tracked alias, or executable). 4483If the 4484.Fl p 4485option is used, a path search is performed even if 4486.Ar name 4487is a reserved word, alias, etc. 4488Without the 4489.Fl v 4490option, 4491.Ic whence 4492is similar to 4493.Ic command Fl v 4494except that 4495.Ic whence 4496will find reserved words and won't print aliases as alias commands. 4497With the 4498.Fl v 4499option, 4500.Ic whence 4501is the same as 4502.Ic command Fl V . 4503Note that for 4504.Ic whence , 4505the 4506.Fl p 4507option does not affect the search path used, as it does for 4508.Ic command . 4509If the type of one or more of the names could not be determined, the exit 4510status is non-zero. 4511.El 4512.Ss Job control 4513Job control refers to the shell's ability to monitor and control jobs, which 4514are processes or groups of processes created for commands or pipelines. 4515At a minimum, the shell keeps track of the status of the background (i.e.\& 4516asynchronous) jobs that currently exist; this information can be displayed 4517using the 4518.Ic jobs 4519commands. 4520If job control is fully enabled (using 4521.Ic set -m 4522or 4523.Ic set -o monitor ) , 4524as it is for interactive shells, the processes of a job are placed in their 4525own process group. 4526Foreground jobs can be stopped by typing the suspend 4527character from the terminal (normally ^Z), jobs can be restarted in either the 4528foreground or background using the 4529.Ic fg 4530and 4531.Ic bg 4532commands, and the state of the terminal is saved or restored when a foreground 4533job is stopped or restarted, respectively. 4534.Pp 4535Note that only commands that create processes (e.g. asynchronous commands, 4536subshell commands, and non-built-in, non-function commands) can be stopped; 4537commands like 4538.Ic read 4539cannot be. 4540.Pp 4541When a job is created, it is assigned a job number. 4542For interactive shells, this number is printed inside 4543.Dq [..] , 4544followed by the process IDs of the processes in the job when an asynchronous 4545command is run. 4546A job may be referred to in the 4547.Ic bg , 4548.Ic fg , 4549.Ic jobs , 4550.Ic kill , 4551and 4552.Ic wait 4553commands either by the process ID of the last process in the command pipeline 4554(as stored in the 4555.Ic $!\& 4556parameter) or by prefixing the job number with a percent 4557sign 4558.Pq Sq % . 4559Other percent sequences can also be used to refer to jobs: 4560.Bl -tag -width "%+ | %% | %XX" 4561.It %+ \*(Ba %% \*(Ba % 4562The most recently stopped job or, if there are no stopped jobs, the oldest 4563running job. 4564.It %- 4565The job that would be the 4566.Ic %+ 4567job if the latter did not exist. 4568.It % Ns Ar n 4569The job with job number 4570.Ar n . 4571.It %? Ns Ar string 4572The job with its command containing the string 4573.Ar string 4574(an error occurs if multiple jobs are matched). 4575.It % Ns Ar string 4576The job with its command starting with the string 4577.Ar string 4578(an error occurs if multiple jobs are matched). 4579.El 4580.Pp 4581When a job changes state (e.g. a background job finishes or foreground job is 4582stopped), the shell prints the following status information: 4583.Pp 4584.D1 [ Ns Ar number ] Ar flag status command 4585.Pp 4586where... 4587.Bl -tag -width "command" 4588.It Ar number 4589is the job number of the job; 4590.It Ar flag 4591is the 4592.Ql + 4593or 4594.Ql - 4595character if the job is the 4596.Ic %+ 4597or 4598.Ic %- 4599job, respectively, or space if it is neither; 4600.It Ar status 4601indicates the current state of the job and can be: 4602.Bl -tag -width "RunningXX" 4603.It Done Op Ar number 4604The job exited. 4605.Ar number 4606is the exit status of the job, which is omitted if the status is zero. 4607.It Running 4608The job has neither stopped nor exited (note that running does not necessarily 4609mean consuming CPU time \- 4610the process could be blocked waiting for some event). 4611.It Stopped Op Ar signal 4612The job was stopped by the indicated 4613.Ar signal 4614(if no signal is given, the job was stopped by 4615.Dv SIGTSTP ) . 4616.It Ar signal-description Op Dq core dumped 4617The job was killed by a signal (e.g. memory fault, hangup); use 4618.Ic kill -l 4619for a list of signal descriptions. 4620The 4621.Dq core dumped 4622message indicates the process created a core file. 4623.El 4624.It Ar command 4625is the command that created the process. 4626If there are multiple processes in 4627the job, each process will have a line showing its 4628.Ar command 4629and possibly its 4630.Ar status , 4631if it is different from the status of the previous process. 4632.El 4633.Pp 4634When an attempt is made to exit the shell while there are jobs in the stopped 4635state, the shell warns the user that there are stopped jobs and does not exit. 4636If another attempt is immediately made to exit the shell, the stopped jobs are 4637sent a 4638.Dv SIGHUP 4639signal and the shell exits. 4640Similarly, if the 4641.Ic nohup 4642option is not set and there are running jobs when an attempt is made to exit 4643a login shell, the shell warns the user and does not exit. 4644If another attempt 4645is immediately made to exit the shell, the running jobs are sent a 4646.Dv SIGHUP 4647signal and the shell exits. 4648.Ss Interactive input line editing 4649The shell supports three modes of reading command lines from a 4650.Xr tty 4 4651in an interactive session, controlled by the 4652.Ic emacs , 4653.Ic gmacs , 4654and 4655.Ic vi 4656options (at most one of these can be set at once). 4657The default is 4658.Ic emacs . 4659Editing modes can be set explicitly using the 4660.Ic set 4661built-in, or implicitly via the 4662.Ev EDITOR 4663and 4664.Ev VISUAL 4665environment variables. 4666If none of these options are enabled, 4667the shell simply reads lines using the normal 4668.Xr tty 4 4669driver. 4670If the 4671.Ic emacs 4672or 4673.Ic gmacs 4674option is set, the shell allows emacs-like editing of the command; similarly, 4675if the 4676.Ic vi 4677option is set, the shell allows vi-like editing of the command. 4678These modes are described in detail in the following sections. 4679.Pp 4680In these editing modes, if a line is longer than the screen width (see the 4681.Ev COLUMNS 4682parameter), 4683a 4684.Ql \*(Gt , 4685.Ql + , 4686or 4687.Ql \*(Lt 4688character is displayed in the last column indicating that there are more 4689characters after, before and after, or before the current position, 4690respectively. 4691The line is scrolled horizontally as necessary. 4692.Ss Emacs editing mode 4693When the 4694.Ic emacs 4695option is set, interactive input line editing is enabled. 4696Warning: This mode is 4697slightly different from the emacs mode in the original Korn shell. 4698In this mode, various editing commands 4699(typically bound to one or more control characters) cause immediate actions 4700without waiting for a newline. 4701Several editing commands are bound to particular 4702control characters when the shell is invoked; these bindings can be changed 4703using the 4704.Ic bind 4705command. 4706.Pp 4707The following is a list of available editing commands. 4708Each description starts with the name of the command, 4709suffixed with a colon; 4710an 4711.Op Ar n 4712(if the command can be prefixed with a count); and any keys the command is 4713bound to by default, written using caret notation 4714e.g. the ASCII ESC character is written as ^[. 4715^[A-Z] sequences are not case sensitive. 4716A count prefix for a command is entered using the sequence 4717.Pf ^[ Ns Ar n , 4718where 4719.Ar n 4720is a sequence of 1 or more digits. 4721Unless otherwise specified, if a count is 4722omitted, it defaults to 1. 4723.Pp 4724Note that editing command names are used only with the 4725.Ic bind 4726command. 4727Furthermore, many editing commands are useful only on terminals with 4728a visible cursor. 4729The default bindings were chosen to resemble corresponding 4730Emacs key bindings. 4731The user's 4732.Xr tty 4 4733characters (e.g.\& 4734.Dv ERASE ) 4735are bound to 4736reasonable substitutes and override the default bindings. 4737.Bl -tag -width Ds 4738.It abort: ^C, ^G 4739Useful as a response to a request for a 4740.Ic search-history 4741pattern in order to abort the search. 4742.It auto-insert: Op Ar n 4743Simply causes the character to appear as literal input. 4744Most ordinary characters are bound to this. 4745.It Xo backward-char: 4746.Op Ar n 4747.No ^B , ^XD 4748.Xc 4749Moves the cursor backward 4750.Ar n 4751characters. 4752.It Xo backward-word: 4753.Op Ar n 4754.No ^[b 4755.Xc 4756Moves the cursor backward to the beginning of the word; words consist of 4757alphanumerics, underscore 4758.Pq Sq _ , 4759and dollar sign 4760.Pq Sq $ 4761characters. 4762.It beginning-of-history: ^[\*(Lt 4763Moves to the beginning of the history. 4764.It beginning-of-line: ^A 4765Moves the cursor to the beginning of the edited input line. 4766.It Xo capitalize-word: 4767.Op Ar n 4768.No ^[C , ^[c 4769.Xc 4770Uppercase the first character in the next 4771.Ar n 4772words, leaving the cursor past the end of the last word. 4773.It comment: ^[# 4774If the current line does not begin with a comment character, one is added at 4775the beginning of the line and the line is entered (as if return had been 4776pressed); otherwise, the existing comment characters are removed and the cursor 4777is placed at the beginning of the line. 4778.It complete: ^[^[ 4779Automatically completes as much as is unique of the command name or the file 4780name containing the cursor. 4781If the entire remaining command or file name is 4782unique, a space is printed after its completion, unless it is a directory name 4783in which case 4784.Ql / 4785is appended. 4786If there is no command or file name with the current partial word 4787as its prefix, a bell character is output (usually causing a beep to be 4788sounded). 4789.It complete-command: ^X^[ 4790Automatically completes as much as is unique of the command name having the 4791partial word up to the cursor as its prefix, as in the 4792.Ic complete 4793command above. 4794.It complete-file: ^[^X 4795Automatically completes as much as is unique of the file name having the 4796partial word up to the cursor as its prefix, as in the 4797.Ic complete 4798command described above. 4799.It complete-list: ^I, ^[= 4800Complete as much as is possible of the current word, 4801and list the possible completions for it. 4802If only one completion is possible, 4803match as in the 4804.Ic complete 4805command above. 4806.It Xo delete-char-backward: 4807.Op Ar n 4808.No ERASE , ^? , ^H 4809.Xc 4810Deletes 4811.Ar n 4812characters before the cursor. 4813.It Xo delete-char-forward: 4814.Op Ar n 4815.No Delete 4816.Xc 4817Deletes 4818.Ar n 4819characters after the cursor. 4820.It Xo delete-word-backward: 4821.Op Ar n 4822.No ERASE , ^[^? , ^[^H , ^[h 4823.Xc 4824Deletes 4825.Ar n 4826words before the cursor. 4827.It Xo delete-word-forward: 4828.Op Ar n 4829.No ^[d 4830.Xc 4831Deletes characters after the cursor up to the end of 4832.Ar n 4833words. 4834.It Xo down-history: 4835.Op Ar n 4836.No ^N , ^XB 4837.Xc 4838Scrolls the history buffer forward 4839.Ar n 4840lines (later). 4841Each input line originally starts just after the last entry 4842in the history buffer, so 4843.Ic down-history 4844is not useful until either 4845.Ic search-history 4846or 4847.Ic up-history 4848has been performed. 4849.It Xo downcase-word: 4850.Op Ar n 4851.No ^[L , ^[l 4852.Xc 4853Lowercases the next 4854.Ar n 4855words. 4856.It end-of-history: ^[\*(Gt 4857Moves to the end of the history. 4858.It end-of-line: ^E 4859Moves the cursor to the end of the input line. 4860.It eot: ^_ 4861Acts as an end-of-file; this is useful because edit-mode input disables 4862normal terminal input canonicalization. 4863.It Xo eot-or-delete: 4864.Op Ar n 4865.No ^D 4866.Xc 4867Acts as 4868.Ic eot 4869if alone on a line; otherwise acts as 4870.Ic delete-char-forward . 4871.It error: 4872Error (ring the bell). 4873.It exchange-point-and-mark: ^X^X 4874Places the cursor where the mark is and sets the mark to where the cursor was. 4875.It expand-file: ^[* 4876Appends a 4877.Ql * 4878to the current word and replaces the word with the result of performing file 4879globbing on the word. 4880If no files match the pattern, the bell is rung. 4881.It Xo forward-char: 4882.Op Ar n 4883.No ^F , ^XC 4884.Xc 4885Moves the cursor forward 4886.Ar n 4887characters. 4888.It Xo forward-word: 4889.Op Ar n 4890.No ^[f 4891.Xc 4892Moves the cursor forward to the end of the 4893.Ar n Ns th 4894word. 4895.It Xo goto-history: 4896.Op Ar n 4897.No ^[g 4898.Xc 4899Goes to history number 4900.Ar n . 4901.It kill-line: KILL 4902Deletes the entire input line. 4903.It kill-region: ^W 4904Deletes the input between the cursor and the mark. 4905.It Xo kill-to-eol: 4906.Op Ar n 4907.No ^K 4908.Xc 4909Deletes the input from the cursor to the end of the line if 4910.Ar n 4911is not specified; otherwise deletes characters between the cursor and column 4912.Ar n . 4913.It list: ^[? 4914Prints a sorted, columnated list of command names or file names (if any) that 4915can complete the partial word containing the cursor. 4916Directory names have 4917.Ql / 4918appended to them. 4919.It list-command: ^X? 4920Prints a sorted, columnated list of command names (if any) that can complete 4921the partial word containing the cursor. 4922.It list-file: ^X^Y 4923Prints a sorted, columnated list of file names (if any) that can complete the 4924partial word containing the cursor. 4925File type indicators are appended as described under 4926.Ic list 4927above. 4928.It newline: ^J , ^M 4929Causes the current input line to be processed by the shell. 4930The current cursor position may be anywhere on the line. 4931.It newline-and-next: ^O 4932Causes the current input line to be processed by the shell, and the next line 4933from history becomes the current line. 4934This is only useful after an 4935.Ic up-history 4936or 4937.Ic search-history . 4938.It no-op: QUIT 4939This does nothing. 4940.It Xo prev-hist-word: 4941.Op Ar n 4942.No ^[. , ^[_ 4943.Xc 4944The last 4945.Pq Ar n Ns th 4946word of the previous command is inserted at the cursor. 4947.It quote: ^^ 4948The following character is taken literally rather than as an editing command. 4949.It redraw: ^L 4950Reprints the prompt string and the current input line. 4951.It Xo search-character-backward: 4952.Op Ar n 4953.No ^[^] 4954.Xc 4955Search backward in the current line for the 4956.Ar n Ns th 4957occurrence of the next character typed. 4958.It Xo search-character-forward: 4959.Op Ar n 4960.No ^] 4961.Xc 4962Search forward in the current line for the 4963.Ar n Ns th 4964occurrence of the next character typed. 4965.It search-history: ^R 4966Enter incremental search mode. 4967The internal history list is searched 4968backwards for commands matching the input. 4969An initial 4970.Ql ^ 4971in the search string anchors the search. 4972The abort key will leave search mode. 4973Other commands will be executed after leaving search mode. 4974Successive 4975.Ic search-history 4976commands continue searching backward to the next previous occurrence of the 4977pattern. 4978The history buffer retains only a finite number of lines; the oldest 4979are discarded as necessary. 4980.It set-mark-command: ^[ Ns Aq space 4981Set the mark at the cursor position. 4982.It stuff: 4983On systems supporting it, pushes the bound character back onto the terminal 4984input where it may receive special processing by the terminal handler. 4985This is useful for the BRL ^T mini-systat feature, for example. 4986.It stuff-reset: 4987Acts like 4988.Ic stuff , 4989then aborts input the same as an interrupt. 4990.It transpose-chars: ^T 4991If at the end of line, or if the 4992.Ic gmacs 4993option is set, this exchanges the two previous characters; otherwise, it 4994exchanges the previous and current characters and moves the cursor one 4995character to the right. 4996.It Xo up-history: 4997.Op Ar n 4998.No ^P , ^XA 4999.Xc 5000Scrolls the history buffer backward 5001.Ar n 5002lines (earlier). 5003.It Xo upcase-word: 5004.Op Ar n 5005.No ^[U , ^[u 5006.Xc 5007Uppercase the next 5008.Ar n 5009words. 5010.It quote: ^V 5011Synonym for ^^. 5012.It yank: ^Y 5013Inserts the most recently killed text string at the current cursor position. 5014.It yank-pop: ^[y 5015Immediately after a 5016.Ic yank , 5017replaces the inserted text string with the next previously killed text string. 5018.El 5019.Ss Vi editing mode 5020The vi command-line editor in 5021.Nm 5022has basically the same commands as the 5023.Xr vi 1 5024editor with the following exceptions: 5025.Bl -bullet 5026.It 5027You start out in insert mode. 5028.It 5029There are file name and command completion commands: 5030=, \e, *, ^X, ^E, ^F, and, optionally, 5031.Aq tab 5032and 5033.Aq esc . 5034.It 5035The 5036.Ic _ 5037command is different (in 5038.Nm 5039it is the last argument command; in 5040.Xr vi 1 5041it goes to the start of the current line). 5042.It 5043The 5044.Ic / 5045and 5046.Ic G 5047commands move in the opposite direction to the 5048.Ic j 5049command. 5050.It 5051Commands which don't make sense in a single line editor are not available 5052(e.g. screen movement commands and 5053.Xr ex 1 Ns -style 5054colon 5055.Pq Ic \&: 5056commands). 5057.El 5058.Pp 5059Note that the ^X stands for control-X; also 5060.Aq esc , 5061.Aq space , 5062and 5063.Aq tab 5064are used for escape, space, and tab, respectively (no kidding). 5065.Pp 5066Like 5067.Xr vi 1 , 5068there are two modes: 5069.Dq insert 5070mode and 5071.Dq command 5072mode. 5073In insert mode, most characters are simply put in the buffer at the 5074current cursor position as they are typed; however, some characters are 5075treated specially. 5076In particular, the following characters are taken from current 5077.Xr tty 4 5078settings 5079(see 5080.Xr stty 1 ) 5081and have their usual meaning (normal values are in parentheses): kill (^U), 5082erase (^?), werase (^W), eof (^D), intr (^C), and quit (^\e). 5083In addition to 5084the above, the following characters are also treated specially in insert mode: 5085.Bl -tag -width 10n 5086.It ^E 5087Command and file name enumeration (see below). 5088.It ^F 5089Command and file name completion (see below). 5090If used twice in a row, the 5091list of possible completions is displayed; if used a third time, the completion 5092is undone. 5093.It ^H 5094Erases previous character. 5095.It ^J \*(Ba ^M 5096End of line. 5097The current line is read, parsed, and executed by the shell. 5098.It ^V 5099Literal next. 5100The next character typed is not treated specially (can be used 5101to insert the characters being described here). 5102.It ^X 5103Command and file name expansion (see below). 5104.It Aq esc 5105Puts the editor in command mode (see below). 5106.It Aq tab 5107Optional file name and command completion (see 5108.Ic ^F 5109above), enabled with 5110.Ic set -o vi-tabcomplete . 5111.El 5112.Pp 5113In command mode, each character is interpreted as a command. 5114Characters that 5115don't correspond to commands, are illegal combinations of commands, or are 5116commands that can't be carried out, all cause beeps. 5117In the following command descriptions, an 5118.Op Ar n 5119indicates the command may be prefixed by a number (e.g.\& 5120.Ic 10l 5121moves right 10 characters); if no number prefix is used, 5122.Ar n 5123is assumed to be 1 unless otherwise specified. 5124The term 5125.Dq current position 5126refers to the position between the cursor and the character preceding the 5127cursor. 5128A 5129.Dq word 5130is a sequence of letters, digits, and underscore characters or a sequence of 5131non-letter, non-digit, non-underscore, and non-whitespace characters (e.g.\& 5132.Dq ab2*&^ 5133contains two words) and a 5134.Dq big-word 5135is a sequence of non-whitespace characters. 5136.Pp 5137Special 5138.Nm 5139vi commands: 5140.Pp 5141The following commands are not in, or are different from, the normal vi file 5142editor: 5143.Bl -tag -width 10n 5144.It Xo 5145.Oo Ar n Oc Ns _ 5146.Xc 5147Insert a space followed by the 5148.Ar n Ns th 5149big-word from the last command in the history at the current position and enter 5150insert mode; if 5151.Ar n 5152is not specified, the last word is inserted. 5153.It # 5154Insert the comment character 5155.Pq Sq # 5156at the start of the current line and return the line to the shell (equivalent 5157to 5158.Ic I#^J ) . 5159.It Xo 5160.Oo Ar n Oc Ns g 5161.Xc 5162Like 5163.Ic G , 5164except if 5165.Ar n 5166is not specified, it goes to the most recent remembered line. 5167.It Xo 5168.Oo Ar n Oc Ns v 5169.Xc 5170Edit line 5171.Ar n 5172using the 5173.Xr vi 1 5174editor; if 5175.Ar n 5176is not specified, the current line is edited. 5177The actual command executed is 5178.Ic fc -e ${VISUAL:-${EDITOR:-vi}} Ar n . 5179.It * and ^X 5180Command or file name expansion is applied to the current big-word (with an 5181appended 5182.Ql * 5183if the word contains no file globbing characters) \- the big-word is replaced 5184with the resulting words. 5185If the current big-word is the first on the line 5186or follows one of the characters 5187.Ql \&; , 5188.Ql | , 5189.Ql & , 5190.Ql \&( , 5191or 5192.Ql \&) , 5193and does not contain a slash 5194.Pq Sq / , 5195then command expansion is done; otherwise file name expansion is done. 5196Command expansion will match the big-word against all aliases, functions, and 5197built-in commands as well as any executable files found by searching the 5198directories in the 5199.Ev PATH 5200parameter. 5201File name expansion matches the big-word against the files in the 5202current directory. 5203After expansion, the cursor is placed just past the last 5204word and the editor is in insert mode. 5205.It Xo 5206.Oo Ar n Oc Ns \e , 5207.Oo Ar n Oc Ns ^F , 5208.Oo Ar n Oc Ns Aq tab , 5209.No and 5210.Oo Ar n Oc Ns Aq esc 5211.Xc 5212Command/file name completion. 5213Replace the current big-word with the 5214longest unique match obtained after performing command and file name expansion. 5215.Aq tab 5216is only recognized if the 5217.Ic vi-tabcomplete 5218option is set, while 5219.Aq esc 5220is only recognized if the 5221.Ic vi-esccomplete 5222option is set (see 5223.Ic set -o ) . 5224If 5225.Ar n 5226is specified, the 5227.Ar n Ns th 5228possible completion is selected (as reported by the command/file name 5229enumeration command). 5230.It = and ^E 5231Command/file name enumeration. 5232List all the commands or files that match the current big-word. 5233.It @ Ns Ar c 5234Macro expansion. 5235Execute the commands found in the alias 5236.Ar c . 5237.El 5238.Pp 5239Intra-line movement commands: 5240.Bl -tag -width Ds 5241.It Xo 5242.Oo Ar n Oc Ns h and 5243.Oo Ar n Oc Ns ^H 5244.Xc 5245Move left 5246.Ar n 5247characters. 5248.It Xo 5249.Oo Ar n Oc Ns l and 5250.Oo Ar n Oc Ns Aq space 5251.Xc 5252Move right 5253.Ar n 5254characters. 5255.It 0 5256Move to column 0. 5257.It ^ 5258Move to the first non-whitespace character. 5259.It Xo 5260.Oo Ar n Oc Ns \*(Ba 5261.Xc 5262Move to column 5263.Ar n . 5264.It $ 5265Move to the last character. 5266.It Xo 5267.Oo Ar n Oc Ns b 5268.Xc 5269Move back 5270.Ar n 5271words. 5272.It Xo 5273.Oo Ar n Oc Ns B 5274.Xc 5275Move back 5276.Ar n 5277big-words. 5278.It Xo 5279.Oo Ar n Oc Ns e 5280.Xc 5281Move forward to the end of the word, 5282.Ar n 5283times. 5284.It Xo 5285.Oo Ar n Oc Ns E 5286.Xc 5287Move forward to the end of the big-word, 5288.Ar n 5289times. 5290.It Xo 5291.Oo Ar n Oc Ns w 5292.Xc 5293Move forward 5294.Ar n 5295words. 5296.It Xo 5297.Oo Ar n Oc Ns W 5298.Xc 5299Move forward 5300.Ar n 5301big-words. 5302.It % 5303Find match. 5304The editor looks forward for the nearest parenthesis, bracket, or 5305brace and then moves the cursor to the matching parenthesis, bracket, or brace. 5306.It Xo 5307.Oo Ar n Oc Ns f Ns Ar c 5308.Xc 5309Move forward to the 5310.Ar n Ns th 5311occurrence of the character 5312.Ar c . 5313.It Xo 5314.Oo Ar n Oc Ns F Ns Ar c 5315.Xc 5316Move backward to the 5317.Ar n Ns th 5318occurrence of the character 5319.Ar c . 5320.It Xo 5321.Oo Ar n Oc Ns t Ns Ar c 5322.Xc 5323Move forward to just before the 5324.Ar n Ns th 5325occurrence of the character 5326.Ar c . 5327.It Xo 5328.Oo Ar n Oc Ns T Ns Ar c 5329.Xc 5330Move backward to just before the 5331.Ar n Ns th 5332occurrence of the character 5333.Ar c . 5334.It Xo 5335.Oo Ar n Oc Ns \&; 5336.Xc 5337Repeats the last 5338.Ic f , F , t , 5339or 5340.Ic T 5341command. 5342.It Xo 5343.Oo Ar n Oc Ns \&, 5344.Xc 5345Repeats the last 5346.Ic f , F , t , 5347or 5348.Ic T 5349command, but moves in the opposite direction. 5350.El 5351.Pp 5352Inter-line movement commands: 5353.Bl -tag -width Ds 5354.It Xo 5355.Oo Ar n Oc Ns j , 5356.Oo Ar n Oc Ns + , 5357.No and 5358.Oo Ar n Oc Ns ^N 5359.Xc 5360Move to the 5361.Ar n Ns th 5362next line in the history. 5363.It Xo 5364.Oo Ar n Oc Ns k , 5365.Oo Ar n Oc Ns - , 5366.No and 5367.Oo Ar n Oc Ns ^P 5368.Xc 5369Move to the 5370.Ar n Ns th 5371previous line in the history. 5372.It Xo 5373.Oo Ar n Oc Ns G 5374.Xc 5375Move to line 5376.Ar n 5377in the history; if 5378.Ar n 5379is not specified, the number of the first remembered line is used. 5380.It Xo 5381.Oo Ar n Oc Ns g 5382.Xc 5383Like 5384.Ic G , 5385except if 5386.Ar n 5387is not specified, it goes to the most recent remembered line. 5388.It Xo 5389.Oo Ar n Oc Ns / Ns Ar string 5390.Xc 5391Search backward through the history for the 5392.Ar n Ns th 5393line containing 5394.Ar string ; 5395if 5396.Ar string 5397starts with 5398.Ql ^ , 5399the remainder of the string must appear at the start of the history line for 5400it to match. 5401.It Xo 5402.Oo Ar n Oc Ns \&? Ns Ar string 5403.Xc 5404Same as 5405.Ic / , 5406except it searches forward through the history. 5407.It Xo 5408.Oo Ar n Oc Ns n 5409.Xc 5410Search for the 5411.Ar n Ns th 5412occurrence of the last search string; 5413the direction of the search is the same as the last search. 5414.It Xo 5415.Oo Ar n Oc Ns N 5416.Xc 5417Search for the 5418.Ar n Ns th 5419occurrence of the last search string; 5420the direction of the search is the opposite of the last search. 5421.El 5422.Pp 5423Edit commands 5424.Bl -tag -width Ds 5425.It Xo 5426.Oo Ar n Oc Ns a 5427.Xc 5428Append text 5429.Ar n 5430times; goes into insert mode just after the current position. 5431The append is 5432only replicated if command mode is re-entered i.e.\& 5433.Aq esc 5434is used. 5435.It Xo 5436.Oo Ar n Oc Ns A 5437.Xc 5438Same as 5439.Ic a , 5440except it appends at the end of the line. 5441.It Xo 5442.Oo Ar n Oc Ns i 5443.Xc 5444Insert text 5445.Ar n 5446times; goes into insert mode at the current position. 5447The insertion is only 5448replicated if command mode is re-entered i.e.\& 5449.Aq esc 5450is used. 5451.It Xo 5452.Oo Ar n Oc Ns I 5453.Xc 5454Same as 5455.Ic i , 5456except the insertion is done just before the first non-blank character. 5457.It Xo 5458.Oo Ar n Oc Ns s 5459.Xc 5460Substitute the next 5461.Ar n 5462characters (i.e. delete the characters and go into insert mode). 5463.It S 5464Substitute whole line. 5465All characters from the first non-blank character to the 5466end of the line are deleted and insert mode is entered. 5467.It Xo 5468.Oo Ar n Oc Ns c Ns Ar move-cmd 5469.Xc 5470Change from the current position to the position resulting from 5471.Ar n move-cmd Ns s 5472(i.e. delete the indicated region and go into insert mode); if 5473.Ar move-cmd 5474is 5475.Ic c , 5476the line starting from the first non-blank character is changed. 5477.It C 5478Change from the current position to the end of the line (i.e. delete to the 5479end of the line and go into insert mode). 5480.It Xo 5481.Oo Ar n Oc Ns x 5482.Xc 5483Delete the next 5484.Ar n 5485characters. 5486.It Xo 5487.Oo Ar n Oc Ns X 5488.Xc 5489Delete the previous 5490.Ar n 5491characters. 5492.It D 5493Delete to the end of the line. 5494.It Xo 5495.Oo Ar n Oc Ns d Ns Ar move-cmd 5496.Xc 5497Delete from the current position to the position resulting from 5498.Ar n move-cmd Ns s ; 5499.Ar move-cmd 5500is a movement command (see above) or 5501.Ic d , 5502in which case the current line is deleted. 5503.It Xo 5504.Oo Ar n Oc Ns r Ns Ar c 5505.Xc 5506Replace the next 5507.Ar n 5508characters with the character 5509.Ar c . 5510.It Xo 5511.Oo Ar n Oc Ns R 5512.Xc 5513Replace. 5514Enter insert mode but overwrite existing characters instead of 5515inserting before existing characters. 5516The replacement is repeated 5517.Ar n 5518times. 5519.It Xo 5520.Oo Ar n Oc Ns ~ 5521.Xc 5522Change the case of the next 5523.Ar n 5524characters. 5525.It Xo 5526.Oo Ar n Oc Ns y Ns Ar move-cmd 5527.Xc 5528Yank from the current position to the position resulting from 5529.Ar n move-cmd Ns s 5530into the yank buffer; if 5531.Ar move-cmd 5532is 5533.Ic y , 5534the whole line is yanked. 5535.It Y 5536Yank from the current position to the end of the line. 5537.It Xo 5538.Oo Ar n Oc Ns p 5539.Xc 5540Paste the contents of the yank buffer just after the current position, 5541.Ar n 5542times. 5543.It Xo 5544.Oo Ar n Oc Ns P 5545.Xc 5546Same as 5547.Ic p , 5548except the buffer is pasted at the current position. 5549.El 5550.Pp 5551Miscellaneous vi commands 5552.Bl -tag -width Ds 5553.It ^J and ^M 5554The current line is read, parsed, and executed by the shell. 5555.It ^L and ^R 5556Redraw the current line. 5557.It Xo 5558.Oo Ar n Oc Ns \&. 5559.Xc 5560Redo the last edit command 5561.Ar n 5562times. 5563.It u 5564Undo the last edit command. 5565.It U 5566Undo all changes that have been made to the current line. 5567.It Ar intr No and Ar quit 5568The interrupt and quit terminal characters cause the current line to be 5569deleted and a new prompt to be printed. 5570.El 5571.Sh FILES 5572.Bl -tag -width "/etc/suid_profileXX" -compact 5573.It Pa ~/.profile 5574User's login profile. 5575.It Pa /etc/ksh.kshrc 5576Global configuration file. 5577Not sourced by default. 5578.It Pa /etc/profile 5579System login profile. 5580.It Pa /etc/shells 5581Shell database. 5582.It Pa /etc/suid_profile 5583Privileged shell profile. 5584.El 5585.Sh SEE ALSO 5586.Xr csh 1 , 5587.Xr ed 1 , 5588.Xr mg 1 , 5589.Xr sh 1 , 5590.Xr stty 1 , 5591.Xr vi 1 , 5592.Xr shells 5 , 5593.Xr environ 7 , 5594.Xr script 7 5595.Rs 5596.%A Morris Bolsky 5597.%A David Korn 5598.%B The KornShell Command and Programming Language, 2nd Edition 5599.%D 1995 5600.%I Prentice Hall 5601.%O ISBN 0131827006 5602.Re 5603.Rs 5604.%A Stephen G. Kochan 5605.%A Patrick H. Wood 5606.%B UNIX Shell Programming, 3rd Edition 5607.%D 2003 5608.%I Sams 5609.%O ISBN 0672324903 5610.Re 5611.Rs 5612.%A IEEE Inc. 5613.%D 1993 5614.%O ISBN 1-55937-266-9 5615.%T IEEE Standard for Information Technology \- Portable Operating \ 5616 System Interface (POSIX) \- Part 2: Shell and Utilities 5617.Re 5618.Sh VERSION 5619This page documents version @(#)PD KSH v5.2.14 99/07/13.2 of the public 5620domain Korn shell. 5621.Sh AUTHORS 5622.An -nosplit 5623This shell is based on the public domain 7th edition Bourne shell clone by 5624.An Charles Forsyth 5625and parts of the BRL shell by 5626.An Doug A. Gwyn , 5627.An Doug Kingston , 5628.An Ron Natalie , 5629.An Arnold Robbins , 5630.An Lou Salkind , 5631and others. 5632The first release of 5633.Nm pdksh 5634was created by 5635.An Eric Gisin , 5636and it was subsequently maintained by 5637.An John R. MacMillan Aq Mt change!john@sq.sq.com , 5638.An Simon J. Gerraty Aq Mt sjg@zen.void.oz.au , 5639and 5640.An Michael Rendell Aq Mt michael@cs.mun.ca . 5641The 5642.Pa CONTRIBUTORS 5643file in the source distribution contains a more complete list of people and 5644their part in the shell's development. 5645.\" .Sh BUGS 5646.\" Any bugs in 5647.\" .Nm pdksh 5648.\" should be reported to pdksh@cs.mun.ca. 5649.\" Please include the version of 5650.\" .Nm pdksh 5651.\" .Po 5652.\" .Ic echo $KSH_VERSION 5653.\" shows it 5654.\" .Pc , 5655.\" the machine, operating system, and compiler you are using and a description of 5656.\" how to repeat the bug (a small shell script that demonstrates the bug is best). 5657.\" The following, if relevant (if you are not sure, include them), can also be 5658.\" helpful: options you are using (both 5659.\" .Pa options.h 5660.\" and 5661.\" .Ic set Fl o Ic options ) 5662.\" and a copy of your 5663.\" .Pa config.h 5664.\" (the file generated by the 5665.\" .Pa configure 5666.\" script). 5667.\" New versions of 5668.\" .Nm pdksh 5669.\" can be obtained from ftp://ftp.cs.mun.ca/pub/pdksh. 5670.\" .Pp 5671.\" BTW, the most frequently reported bug is: 5672.\" .Bd -literal -offset indent 5673.\" $ echo hi | read a; echo $a # Does not print hi 5674.\" .Ed 5675.\" .Pp 5676.\" I'm aware of this and there is no need to report it. 5677