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