1.\" $MirOS: src/bin/mksh/mksh.1,v 1.494 2020/10/01 22:39:57 tg Exp $ 2.\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $ 3.\"- 4.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 5.\" 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 6.\" 2018, 2019, 2020 7.\" mirabilos <m@mirbsd.org> 8.\" 9.\" Provided that these terms and disclaimer and all copyright notices 10.\" are retained or reproduced in an accompanying document, permission 11.\" is granted to deal in this work without restriction, including un‐ 12.\" limited rights to use, publicly perform, distribute, sell, modify, 13.\" merge, give away, or sublicence. 14.\" 15.\" This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to 16.\" the utmost extent permitted by applicable law, neither express nor 17.\" implied; without malicious intent or gross negligence. In no event 18.\" may a licensor, author or contributor be held liable for indirect, 19.\" direct, other damage, loss, or other issues arising in any way out 20.\" of dealing in the work, even if advised of the possibility of such 21.\" damage or existence of a defect, except proven that it results out 22.\" of said person’s immediate fault when using the work as intended. 23.\"- 24.\" Try to make GNU groff and AT&T nroff more compatible 25.\" * ` generates ‘ in gnroff, so use \` 26.\" * ' generates ’ in gnroff, \' generates ´, so use \*(aq 27.\" * - generates ‐ in gnroff, \- generates −, so .tr it to - 28.\" thus use - for hyphens and \- for minus signs and option dashes 29.\" * ~ is size-reduced and placed atop in groff, so use \*(TI 30.\" * ^ is size-reduced and placed atop in groff, so use \*(ha 31.\" * \(en does not work in nroff, so use \*(en for a solo en dash 32.\" * and \*(EM for a correctly spaced em dash 33.\" * <>| are problematic, so redefine and use \*(Lt\*(Gt\*(Ba 34.\" Also make sure to use \& *before* a punctuation char that is to not 35.\" be interpreted as punctuation, and especially with two-letter words 36.\" but also (after) a period that does not end a sentence (“e.g.\&”). 37.\" The section after the "doc" macropackage has been loaded contains 38.\" additional code to convene between the UCB mdoc macropackage (and 39.\" its variant as BSD mdoc in groff) and the GNU mdoc macropackage. 40.\" 41.ie \n(.g \{\ 42. if \*[.T]ascii .tr \-\N'45' 43. if \*[.T]latin1 .tr \-\N'45' 44. if \*[.T]utf8 .tr \-\N'45' 45. ds <= \[<=] 46. ds >= \[>=] 47. ds Rq \[rq] 48. ds Lq \[lq] 49. ds sL \(aq 50. ds sR \(aq 51. if \*[.T]utf8 .ds sL ` 52. if \*[.T]ps .ds sL ` 53. if \*[.T]utf8 .ds sR ' 54. if \*[.T]ps .ds sR ' 55. ds aq \(aq 56. ds TI \(ti 57. ds ha \(ha 58. ds en \(en 59.\} 60.el \{\ 61. ds aq ' 62. ds TI ~ 63. ds ha ^ 64. ds en \(em 65.\} 66.ie n \{\ 67. ds EM \ \*(en\ \& 68.\} 69.el \{\ 70. ds EM \f(TR\^\(em\^\fP 71.\} 72.\" 73.\" Implement .Dd with the Mdocdate RCS keyword 74.\" 75.rn Dd xD 76.de Dd 77.ie \\$1$Mdocdate: \{\ 78. xD \\$2 \\$3, \\$4 79.\} 80.el .xD \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 81.. 82.\" 83.\" .Dd must come before definition of .Mx, because when called 84.\" with -mandoc, it might implement .Mx itself, but we want to 85.\" use our own definition. And .Dd must come *first*, always. 86.\" 87.Dd $Mdocdate: October 1 2020 $ 88.\" 89.\" Check which macro package we use, and do other -mdoc setup. 90.\" 91.ie \n(.g \{\ 92. if \*[.T]utf8 .tr \[la]\*(Lt 93. if \*[.T]utf8 .tr \[ra]\*(Gt 94. ie d volume-ds-1 .ds tT gnu 95. el .ie d doc-volume-ds-1 .ds tT gnp 96. el .ds tT bsd 97.\} 98.el .ds tT ucb 99.\" 100.\" Implement .Mx (MirBSD) 101.\" 102.ie "\*(tT"gnu" \{\ 103. eo 104. de Mx 105. nr curr-font \n[.f] 106. nr curr-size \n[.ps] 107. ds str-Mx \f[\n[curr-font]]\s[\n[curr-size]u] 108. ds str-Mx1 \*[Tn-font-size]\%MirBSD\*[str-Mx] 109. if !\n[arg-limit] \ 110. if \n[.$] \{\ 111. ds macro-name Mx 112. parse-args \$@ 113. \} 114. if (\n[arg-limit] > \n[arg-ptr]) \{\ 115. nr arg-ptr +1 116. ie (\n[type\n[arg-ptr]] == 2) \ 117. as str-Mx1 \~\*[arg\n[arg-ptr]] 118. el \ 119. nr arg-ptr -1 120. \} 121. ds arg\n[arg-ptr] "\*[str-Mx1] 122. nr type\n[arg-ptr] 2 123. ds space\n[arg-ptr] "\*[space] 124. nr num-args (\n[arg-limit] - \n[arg-ptr]) 125. nr arg-limit \n[arg-ptr] 126. if \n[num-args] \ 127. parse-space-vector 128. print-recursive 129.. 130. ec 131. ds sP \s0 132. ds tN \*[Tn-font-size] 133.\} 134.el .ie "\*(tT"gnp" \{\ 135. eo 136. de Mx 137. nr doc-curr-font \n[.f] 138. nr doc-curr-size \n[.ps] 139. ds doc-str-Mx \f[\n[doc-curr-font]]\s[\n[doc-curr-size]u] 140. ds doc-str-Mx1 \*[doc-Tn-font-size]\%MirBSD\*[doc-str-Mx] 141. if !\n[doc-arg-limit] \ 142. if \n[.$] \{\ 143. ds doc-macro-name Mx 144. doc-parse-args \$@ 145. \} 146. if (\n[doc-arg-limit] > \n[doc-arg-ptr]) \{\ 147. nr doc-arg-ptr +1 148. ie (\n[doc-type\n[doc-arg-ptr]] == 2) \ 149. as doc-str-Mx1 \~\*[doc-arg\n[doc-arg-ptr]] 150. el \ 151. nr doc-arg-ptr -1 152. \} 153. ds doc-arg\n[doc-arg-ptr] "\*[doc-str-Mx1] 154. nr doc-type\n[doc-arg-ptr] 2 155. ds doc-space\n[doc-arg-ptr] "\*[doc-space] 156. nr doc-num-args (\n[doc-arg-limit] - \n[doc-arg-ptr]) 157. nr doc-arg-limit \n[doc-arg-ptr] 158. if \n[doc-num-args] \ 159. doc-parse-space-vector 160. doc-print-recursive 161.. 162. ec 163. ds sP \s0 164. ds tN \*[doc-Tn-font-size] 165.\} 166.el \{\ 167. de Mx 168. nr cF \\n(.f 169. nr cZ \\n(.s 170. ds aa \&\f\\n(cF\s\\n(cZ 171. if \\n(aC==0 \{\ 172. ie \\n(.$==0 \&MirBSD\\*(aa 173. el .aV \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9 174. \} 175. if \\n(aC>\\n(aP \{\ 176. nr aP \\n(aP+1 177. ie \\n(C\\n(aP==2 \{\ 178. as b1 \&MirBSD\ #\&\\*(A\\n(aP\\*(aa 179. ie \\n(aC>\\n(aP \{\ 180. nr aP \\n(aP+1 181. nR 182. \} 183. el .aZ 184. \} 185. el \{\ 186. as b1 \&MirBSD\\*(aa 187. nR 188. \} 189. \} 190.. 191.\} 192.\"- 193.Dt MKSH 1 194.Os MirBSD 195.Sh NAME 196.Nm mksh , 197.Nm sh 198.Nd MirBSD Korn shell 199.Sh SYNOPSIS 200.Nm 201.Bk -words 202.Op Fl +abCefhiklmnprUuvXx 203.Oo 204.Fl T Oo Ar \&! Oc Ns Ar tty 205\*(Ba 206.Ar \&\- 207.Oc 208.Op Fl +o Ar option 209.Oo 210.Fl c Ar string \*(Ba 211.Fl s \*(Ba 212.Ar file 213.Op Ar argument ... 214.Oc 215.Ek 216.Nm builtin-name 217.Op Ar argument ... 218.Sh DESCRIPTION 219.Nm 220is a command interpreter intended for both interactive and shell 221script use. 222Its command language is a superset of the 223.Xr sh C 224shell language and largely compatible to the original Korn shell. 225At times, this manual page may give scripting advice; while it 226sometimes does take portable shell scripting or various standards 227into account all information is first and foremost presented with 228.Nm 229in mind and should be taken as such. 230.Ss I use Android, OS/2, etc. so what...? 231Please refer to: 232.Pa http://www.mirbsd.org/mksh\-faq.htm#sowhatismksh 233.Ss Invocation 234Most builtins can be called directly, for example if a link points from its 235name to the shell; not all make sense, have been tested or work at all though. 236.Pp 237The options are as follows: 238.Bl -tag -width XcXstring 239.It Fl c Ar string 240.Nm 241will execute the command(s) contained in 242.Ar string . 243.It Fl i 244Interactive shell. 245A shell that reads commands from standard input is 246.Dq interactive 247if this 248option is used or if both standard input and standard error are attached 249to a 250.Xr tty 4 . 251An interactive shell has job control enabled, ignores the 252.Dv SIGINT , 253.Dv SIGQUIT 254and 255.Dv SIGTERM 256signals, and prints prompts before reading input (see the 257.Ev PS1 258and 259.Ev PS2 260parameters). 261It also processes the 262.Ev ENV 263parameter or the 264.Pa mkshrc 265file (see below). 266For non-interactive shells, the 267.Ic trackall 268option is on by default (see the 269.Ic set 270command below). 271.It Fl l 272Login shell. 273If the name or basename the shell is called with (i.e. argv[0]) 274starts with 275.Ql \- 276or if this option is used, 277the shell is assumed to be a login shell; see 278.Sx Startup files 279below. 280.It Fl p 281Privileged shell. 282A shell is 283.Dq privileged 284if the real user ID or group ID does not match the 285effective user ID or group ID (see 286.Xr getuid 2 287and 288.Xr getgid 2 ) . 289Clearing the privileged option causes the shell to set 290its effective user ID (group ID) to its initial real user ID (group ID). 291For further implications, see 292.Sx Startup files . 293If the shell is privileged and this flag is not explicitly set, the 294.Dq privileged 295option is cleared automatically after processing the startup files. 296.It Fl r 297Restricted shell. 298A shell is 299.Dq restricted 300if the basename the shell is called with, after 301.Ql \- 302processing, starts with 303.Ql r 304or if this option is used. 305The following restrictions come into effect after the shell processes any 306profile and 307.Ev ENV 308files: 309.Pp 310.Bl -bullet -compact 311.It 312The 313.Ic cd 314.Po and Ic chdir Pc 315command is disabled. 316.It 317The 318.Ev SHELL , 319.Ev ENV 320and 321.Ev PATH 322parameters cannot be changed. 323.It 324Command names can't be specified with absolute or relative paths. 325.It 326The 327.Fl p 328option of the built-in command 329.Ic command 330can't be used. 331.It 332Redirections that create files can't be used (i.e.\& 333.Dq Li \*(Gt , 334.Dq Li \*(Gt\*(Ba , 335.Dq Li \*(Gt\*(Gt , 336.Dq Li \*(Lt\*(Gt ) . 337.El 338.It Fl s 339The shell reads commands from standard input; all non-option arguments 340are positional parameters. 341.It Fl T Ar name 342Spawn 343.Nm 344on the 345.Xr tty 4 346device given. 347The paths 348.Ar name , 349.Pa /dev/ttyC Ns Ar name 350and 351.Pa /dev/tty Ns Ar name 352are attempted in order. 353Unless 354.Ar name 355begins with an exclamation mark 356.Pq Ql \&! , 357this is done in a subshell and returns immediately. 358If 359.Ar name 360is a dash 361.Pq Ql \&\- , 362detach from controlling terminal (daemonise) instead. 363.El 364.Pp 365In addition to the above, the options described in the 366.Ic set 367built-in command can also be used on the command line: 368both 369.Op Fl +abCefhkmnuvXx 370and 371.Op Fl +o Ar option 372can be used for single letter or long options, respectively. 373.Pp 374If neither the 375.Fl c 376nor the 377.Fl s 378option is specified, the first non-option argument specifies the name 379of a file the shell reads commands from. 380If there are no non-option 381arguments, the shell reads commands from the standard input. 382The name of the shell (i.e. the contents of $0) 383is determined as follows: if the 384.Fl c 385option is used and there is a non-option argument, it is used as the name; 386if commands are being read from a file, the file is used as the name; 387otherwise, the name the shell was called with (i.e. argv[0]) is used. 388.Pp 389The exit status of the shell is 127 if the command file specified on the 390command line could not be opened, or non-zero if a fatal syntax error 391occurred during the execution of a script. 392In the absence of fatal errors, 393the exit status is that of the last command executed, or zero if no 394command is executed. 395.Ss Startup files 396For the actual location of these files, see 397.Sx FILES . 398A login shell processes the system profile first. 399A privileged shell then processes the suid profile. 400A non-privileged login shell processes the user profile next. 401A non-privileged interactive shell checks the value of the 402.Ev ENV 403parameter after subjecting it to parameter, command, arithmetic and tilde 404.Pq Ql \*(TI 405substitution; if unset or empty, the user mkshrc profile is processed; 406otherwise, if a file whose name is the substitution result exists, 407it is processed; non-existence is silently ignored. 408A privileged shell then drops privileges if neither was the 409.Fl p 410option given on the command line nor set during execution of the startup files. 411.Ss Command syntax 412The shell begins parsing its input by removing any backslash-newline 413combinations, then breaking it into 414.Em words . 415Words (which are sequences of characters) are delimited by unquoted whitespace 416characters (space, tab and newline) or meta-characters 417.Po 418.Ql \*(Lt , 419.Ql \*(Gt , 420.Ql \*(Ba , 421.Ql \&; , 422.Ql \&( , 423.Ql \&) 424and 425.Ql & 426.Pc . 427Aside from delimiting words, spaces and tabs are ignored, while newlines 428usually delimit commands. 429The meta-characters are used in building the following 430.Em tokens : 431.Dq Li \*(Lt , 432.Dq Li \*(Lt& , 433.Dq Li \*(Lt\*(Lt , 434.Dq Li \*(Lt\*(Lt\*(Lt , 435.Dq Li \*(Gt , 436.Dq Li \*(Gt& , 437.Dq Li \*(Gt\*(Gt , 438.Dq Li &\*(Gt , 439etc. are used to specify redirections (see 440.Sx Input/output redirection 441below); 442.Dq Li \*(Ba 443is used to create pipelines; 444.Dq Li \*(Ba& 445is used to create co-processes (see 446.Sx Co-processes 447below); 448.Dq Li \&; 449is used to separate commands; 450.Dq Li & 451is used to create asynchronous pipelines; 452.Dq Li && 453and 454.Dq Li \*(Ba\*(Ba 455are used to specify conditional execution; 456.Dq Li \&;; , 457.Dq Li \&;& 458and 459.Dq Li \&;\*(Ba 460are used in 461.Ic case 462statements; 463.Dq Li \&(( ... \&)) 464is used in arithmetic expressions; 465and lastly, 466.Dq Li \&( ... \&) 467is used to create subshells. 468.Pp 469Whitespace and meta-characters can be quoted individually using a backslash 470.Pq Ql \e , 471or in groups using double 472.Pq Ql \&" 473or single 474.Pq Dq Li \*(aq 475quotes. 476Note that the following characters are also treated specially by the 477shell and must be quoted if they are to represent themselves: 478.Ql \e , 479.Ql \&" , 480.Dq Li \*(aq , 481.Ql # , 482.Ql $ , 483.Ql \` , 484.Ql \*(TI , 485.Ql { , 486.Ql } , 487.Ql * , 488.Ql \&? 489and 490.Ql \&[ . 491The first three of these are the above mentioned quoting characters (see 492.Sx Quoting 493below); 494.Ql # , 495if used at the beginning of a word, 496introduces a comment\*(EMeverything after the 497.Ql # 498up to the nearest newline is ignored; 499.Ql $ 500is used to introduce parameter, command and arithmetic substitutions (see 501.Sx Substitution 502below); 503.Ql \` 504introduces an old-style command substitution (see 505.Sx Substitution 506below); 507.Ql \*(TI 508begins a directory expansion (see 509.Sx Tilde expansion 510below); 511.Ql { 512and 513.Ql } 514delimit 515.Xr csh 1 Ns -style 516alternations (see 517.Sx Brace expansion 518below); 519and finally, 520.Ql * , 521.Ql \&? 522and 523.Ql \&[ 524are used in file name generation (see 525.Sx File name patterns 526below). 527.Pp 528As words and tokens are parsed, the shell builds commands, of which there 529are two basic types: 530.Em simple-commands , 531typically programmes that are executed, and 532.Em compound-commands , 533such as 534.Ic for 535and 536.Ic if 537statements, grouping constructs and function definitions. 538.Pp 539A simple-command consists of some combination of parameter assignments 540(see 541.Sx Parameters 542below), 543input/output redirections (see 544.Sx Input/output redirections 545below) 546and command words; the only restriction is that parameter assignments come 547before any command words. 548The command words, if any, define the command 549that is to be executed and its arguments. 550The command may be a shell built-in command, a function 551or an external command 552(i.e. a separate executable file that is located using the 553.Ev PATH 554parameter; see 555.Sx Command execution 556below). 557Note that all command constructs have an exit status: for external commands, 558this is related to the status returned by 559.Xr wait 2 560(if the command could not be found, the exit status is 127; if it could not 561be executed, the exit status is 126); the exit status of other command 562constructs (built-in commands, functions, compound-commands, pipelines, lists, 563etc.) are all well-defined and are described where the construct is 564described. 565The exit status of a command consisting only of parameter 566assignments is that of the last command substitution performed during the 567parameter assignment or 0 if there were no command substitutions. 568.Pp 569Commands can be chained together using the 570.Dq Li \*(Ba 571token to form pipelines, in which the standard output of each command but the 572last is piped (see 573.Xr pipe 2 ) 574to the standard input of the following command. 575The exit status of a pipeline is that of its last command, unless the 576.Ic pipefail 577option is set (see there). 578All commands of a pipeline are executed in separate subshells; 579this is allowed by POSIX but differs from both variants of 580.At 581.Nm ksh , 582where all but the last command were executed in subshells; see the 583.Ic read 584builtin's description for implications and workarounds. 585A pipeline may be prefixed by the 586.Dq Li \&! 587reserved word which causes the exit status of the pipeline to be logically 588complemented: if the original status was 0, the complemented status will be 1; 589if the original status was not 0, the complemented status will be 0. 590.Pp 591.Em Lists 592of commands can be created by separating pipelines by any of the following 593tokens: 594.Dq Li && , 595.Dq Li \*(Ba\*(Ba , 596.Dq Li & , 597.Dq Li \*(Ba& 598and 599.Dq Li \&; . 600The first two are for conditional execution: 601.Dq Ar cmd1 No && Ar cmd2 602executes 603.Ar cmd2 604only if the exit status of 605.Ar cmd1 606is zero; 607.Dq Li \*(Ba\*(Ba 608.No is the opposite\*(EM Ns Ar cmd2 609is executed only if the exit status of 610.Ar cmd1 611is non-zero. 612.Dq Li && 613and 614.Dq Li \*(Ba\*(Ba 615have equal precedence which is higher than that of 616.Dq Li & , 617.Dq Li \*(Ba& 618and 619.Dq Li \&; , 620which also have equal precedence. 621Note that the 622.Dq Li && 623and 624.Dq Li \*(Ba\*(Ba 625operators are 626.Qq left-associative . 627For example, both of these commands will print only 628.Qq bar : 629.Bd -literal -offset indent 630$ false && echo foo \*(Ba\*(Ba echo bar 631$ true \*(Ba\*(Ba echo foo && echo bar 632.Ed 633.Pp 634The 635.Dq Li & 636token causes the preceding command to be executed asynchronously; that is, 637the shell starts the command but does not wait for it to complete (the shell 638does keep track of the status of asynchronous commands; see 639.Sx Job control 640below). 641When an asynchronous command is started when job control is disabled 642(i.e. in most scripts), the command is started with signals 643.Dv SIGINT 644and 645.Dv SIGQUIT 646ignored and with input redirected from 647.Pa /dev/null 648(however, redirections specified in the asynchronous command have precedence). 649The 650.Dq Li \*(Ba& 651operator starts a co-process which is a special kind of asynchronous process 652(see 653.Sx Co-processes 654below). 655Note that a command must follow the 656.Dq Li && 657and 658.Dq Li \*(Ba\*(Ba 659operators, while it need not follow 660.Dq Li & , 661.Dq Li \*(Ba& 662or 663.Dq Li \&; . 664The exit status of a list is that of the last command executed, with the 665exception of asynchronous lists, for which the exit status is 0. 666.Pp 667Compound commands are created using the following reserved words. 668These words 669are only recognised if they are unquoted and if they are used as the first 670word of a command (i.e. they can't be preceded by parameter assignments or 671redirections): 672.Bd -literal -offset indent 673case else function then ! ( 674do esac if time [[ (( 675done fi in until { 676elif for select while } 677.Ed 678.Pp 679In the following compound command descriptions, command lists (denoted as 680.Em list ) 681that are followed by reserved words must end with a semicolon, a newline or 682a (syntactically correct) reserved word. 683For example, the following are all valid: 684.Bd -literal -offset indent 685$ { echo foo; echo bar; } 686$ { echo foo; echo bar\*(Ltnewline\*(Gt} 687$ { { echo foo; echo bar; } } 688.Ed 689.Pp 690This is not valid: 691.Pp 692.Dl $ { echo foo; echo bar } 693.Bl -tag -width 4n 694.It Xo Ic case Ar word Ic in 695.Oo Op \&( 696.Ar pattern 697.Op \*(Ba Ar pattern 698.No ... Ns ) 699.Ar list 700.Aq terminator 701.Oc No ... Ic esac 702.Xc 703The 704.Ic case 705statement attempts to match 706.Ar word 707against a specified 708.Ar pattern ; 709the 710.Ar list 711associated with the first successfully matched pattern is executed. 712Patterns used in 713.Ic case 714statements are the same as those used for file name patterns except that the 715restrictions regarding 716.Ql \&. 717and 718.Ql / 719are dropped. 720Note that any unquoted space before and after a pattern is 721stripped; any space within a pattern must be quoted. 722Both the word and the 723patterns are subject to parameter, command and arithmetic substitution, as 724well as tilde substitution. 725.Pp 726For historical reasons, open and close braces may be used instead of 727.Ic in 728and 729.Ic esac , 730for example: 731.Dq Li case $foo { (ba[rz]\*(Bablah) date ;; } 732.Pp 733The list 734.Ao terminator Ac Ns s 735are: 736.Bl -tag -width 4n 737.It Dq Li ;; 738Terminate after the list. 739.It Dq Li \&;& 740Fall through into the next list. 741.It Dq Li \&;\*(Ba 742Evaluate the remaining pattern-list tuples. 743.El 744.Pp 745The exit status of a 746.Ic case 747statement is that of the executed 748.Ar list ; 749if no 750.Ar list 751is executed, the exit status is zero. 752.It Xo Ic for Ar name 753.Oo Ic in Ar word ... Oc Ic ; 754.Ic do Ar list ; Ic done 755.Xc 756For each 757.Ar word 758in the specified word list, the parameter 759.Ar name 760is set to the word and 761.Ar list 762is executed. 763The exit status of a 764.Ic for 765statement is the last exit status of 766.Ar list ; 767if 768.Ar list 769is never executed, the exit status is zero. 770If 771.Ic in 772is not used to specify a word list, the positional parameters ($1, $2, 773etc.) are used instead; in this case, use a newline instead of the semicolon 774.Pq Sq Ic ;\& 775for portability. 776For historical reasons, open and close braces may be used instead of 777.Ic do 778and 779.Ic done , 780as in 781.Dq Li for i; { echo $i; } 782.Pq not portable . 783.It Xo Ic function Ar name 784.No { Ar list ; No } 785.Xc 786Defines the function 787.Ar name 788(see 789.Sx Functions 790below). 791All redirections specified after a function definition are performed whenever 792the function is executed, not when the function definition is executed. 793.It Ar name Ns \&() Ar command 794Mostly the same as 795.Ic function 796(see above and 797.Sx Functions 798below). 799Most amounts of space and tab after 800.Ar name 801will be ignored. 802.It Xo Ic function Ar name Ns \&() 803.No { Ar list ; No } 804.Xc 805.Nm bash Ns ism for 806.Ar name Ns Li ()\ { 807.Ar list Ns Li ;\ } 808.Pq the Ic function No keyword is ignored . 809.It Xo Ic if Ar list ; 810.Ic then Ar list ; 811.Oo Ic elif Ar list ; 812.Ic then Ar list ; Oc 813.No ... 814.Oo Ic else Ar list ; Oc 815.Ic fi 816.Xc 817If the exit status of the first 818.Ar list 819is zero, the second 820.Ar list 821is executed; otherwise, the 822.Ar list 823following the 824.Ic elif , 825if any, is executed with similar consequences. 826If all the lists following the 827.Ic if 828and 829.Ic elif Ns s 830fail (i.e. exit with non-zero status), the 831.Ar list 832following the 833.Ic else 834is executed. 835The exit status of an 836.Ic if 837statement is that of whatever non-conditional 838.Pq not the first 839.Ar list 840that is executed; if no non-conditional 841.Ar list 842is executed, the exit status is zero. 843.It Xo Ic select Ar name 844.Oo Ic in Ar word No ... Oc ; 845.Ic do Ar list ; Ic done 846.Xc 847The 848.Ic select 849statement provides an automatic method of presenting the user with a menu and 850selecting from it. 851An enumerated list of the specified 852.Ar word Ns s 853is printed on standard error, followed by a prompt 854.Po 855.Ev PS3 : 856normally 857.Dq Li #?\ \& 858.Pc . 859A number corresponding to one of the enumerated words is then read from 860standard input, 861.Ar name 862is set to the selected word (or unset if the selection is not valid), 863.Ev REPLY 864is set to what was read (leading and trailing space is stripped), and 865.Ar list 866is executed. 867If a blank line (i.e. zero or more 868.Ev IFS 869octets) is entered, the menu is reprinted without executing 870.Ar list . 871.Pp 872When 873.Ar list 874completes, the enumerated list is printed if 875.Ev REPLY 876is empty, the prompt is printed, and so on. 877This process continues until an end-of-file 878is read, an interrupt is received, or a 879.Ic break 880statement is executed inside the loop. 881The exit status of a 882.Ic select 883statement is zero if a 884.Ic break 885statement is used to exit the loop, non-zero otherwise. 886If 887.Dq Ic in Ar word ... 888is omitted, the positional parameters are used. 889For historical reasons, open and close braces may be used instead of 890.Ic do 891and 892.Ic done , 893as in: 894.Dq Li select i; { echo $i; } 895.It Xo Ic time Op Fl p 896.Op Ar pipeline 897.Xc 898The 899.Sx Command execution 900section describes the 901.Ic time 902reserved word. 903.It Xo Ic until Ar list ; 904.Ic do Ar list ; Ic done 905.Xc 906This works like 907.Ic while Pq see below , 908except that the body 909.Ar list 910is executed only while the exit status of the first 911.Ar list 912is non-zero. 913.It Xo Ic while Ar list ; 914.Ic do Ar list ; Ic done 915.Xc 916A 917.Ic while 918is a pre-checked loop. 919Its body 920.Ar list 921is executed as often as the exit status of the first 922.Ar list 923is zero. 924The exit status of a 925.Ic while 926statement is the last exit status of the 927.Ar list 928in the body of the loop; if the body is not executed, the exit status is zero. 929.It Bq Bq Ar \ \&expression\ \& 930Similar to the 931.Ic test 932and 933.Ic \&[ ... \&] 934commands (described later), with the following exceptions: 935.Bl -bullet 936.It 937Field splitting and globbing are not performed on arguments. 938.It 939The 940.Fl a 941.Pq AND 942and 943.Fl o 944.Pq OR 945operators are replaced, respectively, with 946.Dq Ic && 947and 948.Dq Ic \*(Ba\*(Ba . 949.It 950Operators (e.g.\& 951.Dq Ic \-f , 952.Dq Ic = , 953.Dq Ic \&! ) 954must be unquoted. 955.It 956Parameter, command and arithmetic substitutions are performed as expressions 957are evaluated and lazy expression evaluation is used for the 958.Dq Ic && 959and 960.Dq Ic \*(Ba\*(Ba 961operators. 962This means that in the following statement, 963.Ic $(\*(Ltfoo) 964is evaluated if and only if the file 965.Pa foo 966exists and is readable: 967.Bd -literal -offset indent 968$ [[ \-r foo && $(\*(Ltfoo) = b*r ]] 969.Ed 970.It 971The second operand of the 972.Dq Ic = 973and 974.Dq Ic != 975expressions is a pattern (e.g. the comparison 976.Ic \&[[ foobar = f*r ]] 977succeeds). 978This even works indirectly, while quoting forces literal interpretation: 979.Bd -literal -offset indent 980$ bar=foobar; baz=\*(aqf*r\*(aq # or: baz=\*(aqf+(o)b?r\*(aq 981$ [[ $bar = $baz ]]; echo $? # 0 982$ [[ $bar = \&"$baz" ]]; echo $? # 1 983.Ed 984.El 985.It { Ar list ; No } 986Compound construct; 987.Ar list 988is executed, but not in a subshell. 989.br 990Note that 991.Dq Li { 992and 993.Dq Li } 994are reserved words, not meta-characters. 995.It Pq Ar list 996Execute 997.Ar list 998in a subshell, forking. 999There is no implicit way to pass environment changes from a 1000subshell back to its parent. 1001.It \&(( Ar expression No )) 1002The arithmetic expression 1003.Ar expression 1004is evaluated; equivalent to 1005.Sq Li let \&" Ns Ar expression Ns \&" 1006in a compound construct. 1007.br 1008See the 1009.Ic let 1010command and 1011.Sx Arithmetic expressions 1012below. 1013.El 1014.Ss Quoting 1015Quoting is used to prevent the shell from treating characters or words 1016specially. 1017There are three methods of quoting. 1018First, 1019.Ql \e 1020quotes the following character, unless it is at the end of a line, in which 1021case both the 1022.Ql \e 1023and the newline are stripped. 1024Second, a single quote 1025.Pq Dq Li \*(aq 1026quotes everything up to the next single quote (this may span lines). 1027Third, a double quote 1028.Pq Ql \&" 1029quotes all characters, except 1030.Ql $ , 1031.Ql \e 1032and 1033.Ql \` , 1034up to the next unescaped double quote. 1035.Ql $ 1036and 1037.Ql \` 1038inside double quotes have their usual meaning (i.e. parameter, arithmetic 1039or command substitution) except no field splitting is carried out on the 1040results of double-quoted substitutions, and the old-style form of command 1041substitution has backslash-quoting for double quotes enabled. 1042If a 1043.Ql \e 1044inside a double-quoted string is followed by 1045.Ql \&" , 1046.Ql $ , 1047.Ql \e 1048or 1049.Ql \` , 1050only the 1051.Ql \e 1052is removed, i.e. the combination is replaced by the second character; 1053if it is followed by a newline, both the 1054.Ql \e 1055and the newline are stripped; otherwise, both the 1056.Ql \e 1057and the character following are unchanged. 1058.Pp 1059If a single-quoted string is preceded by an unquoted 1060.Ql $ , 1061C style backslash expansion (see below) is applied (even single quote 1062characters inside can be escaped and do not terminate the string then); 1063the expanded result is treated as any other single-quoted string. 1064If a double-quoted string is preceded by an unquoted 1065.Ql $ , 1066the 1067.Ql $ 1068is simply ignored. 1069.Ss Backslash expansion 1070In places where backslashes are expanded, certain C and 1071.At 1072.Nm ksh 1073or GNU 1074.Nm bash 1075style escapes are translated. 1076These include 1077.Dq Li \ea , 1078.Dq Li \eb , 1079.Dq Li \ef , 1080.Dq Li \en , 1081.Dq Li \er , 1082.Dq Li \et , 1083.Dq Li \eU######## , 1084.Dq Li \eu#### 1085and 1086.Dq Li \ev . 1087For 1088.Dq Li \eU######## 1089and 1090.Dq Li \eu#### , 1091.Sq Li # 1092means a hexadecimal digit (up to 4 or 8); these translate a 1093Universal Coded Character Set codepoint to UTF-8 (see 1094.Sx CAVEATS 1095on UCS limitations). 1096Furthermore, 1097.Dq Li \eE 1098and 1099.Dq Li \ee 1100expand to the escape character. 1101.Pp 1102In the 1103.Ic print 1104builtin mode, 1105octal sequences must have the optional up to three octal digits 1106.Sq Li # 1107prefixed with the digit zero 1108.Pq Dq Li \e0### ; 1109hexadecimal sequences 1110.Dq Li \ex## 1111are limited to up to two hexadecimal digits 1112.Sq Li # ; 1113both octal and hexadecimal sequences convert to raw octets; 1114.Dq Li \e% , 1115where 1116.Sq Li % 1117is none of the above, translates to 1118.Li \e% 1119.Pq backslashes are retained . 1120.Pp 1121In C style mode, raw octet-yielding octal sequences 1122.Dq Li \e### 1123must not have the one up to three octal digits prefixed with the 1124digit zero; hexadecimal sequences 1125.Dq Li \ex## 1126greedily eat up as many hexadecimal digits 1127.Sq Li # 1128as they can and terminate with the first non-xdigit; below 1129.Li \ex100 1130these produce raw octets; above, they are equivalent to 1131.Dq Li \eU# . 1132The sequence 1133.Dq Li \ec% , 1134where 1135.Sq Li % 1136is any octet, translates to 1137.Ic Ctrl- Ns Li % , 1138that is, 1139.Dq Li \ec? 1140becomes DEL, everything else is bitwise ANDed with 0x9F. 1141.Dq Li \e% , 1142where 1143.Sq Li % 1144is none of the above, translates to 1145.Li % : 1146backslashes are trimmed even before newlines. 1147.Ss Aliases 1148There are two types of aliases: normal command aliases and tracked aliases. 1149Command aliases are normally used as a short hand for a long or often used 1150command. 1151The shell expands command aliases (i.e. substitutes the alias name 1152for its value) when it reads the first word of a command. 1153An expanded alias is re-processed to check for more aliases. 1154If a command alias ends in a 1155space or tab, the following word is also checked for alias expansion. 1156The alias expansion process stops when a word that is not an alias is found, 1157when a quoted word is found, or when an alias word that is currently being 1158expanded is found. 1159Aliases are specifically an interactive feature: while they do happen 1160to work in scripts and on the command line in some cases, aliases are 1161expanded during lexing, so their use must be in a separate command tree 1162from their definition; otherwise, the alias will not be found. 1163Noticeably, command lists (separated by semicolon, in command substitutions 1164also by newline) may be one same parse tree. 1165.Pp 1166The following command aliases are defined automatically by the shell: 1167.Bd -literal -offset indent 1168autoload=\*(aq\e\ebuiltin typeset \-fu\*(aq 1169functions=\*(aq\e\ebuiltin typeset \-f\*(aq 1170hash=\*(aq\e\ebuiltin alias \-t\*(aq 1171history=\*(aq\e\ebuiltin fc \-l\*(aq 1172integer=\*(aq\e\ebuiltin typeset \-i\*(aq 1173local=\*(aq\e\ebuiltin typeset\*(aq 1174login=\*(aq\e\ebuiltin exec login\*(aq 1175nameref=\*(aq\e\ebuiltin typeset \-n\*(aq 1176nohup=\*(aqnohup \*(aq 1177r=\*(aq\e\ebuiltin fc \-e \-\*(aq 1178type=\*(aq\e\ebuiltin whence \-v\*(aq 1179.Ed 1180.Pp 1181Tracked aliases allow the shell to remember where it found a particular 1182command. 1183The first time the shell does a path search for a command that is 1184marked as a tracked alias, it saves the full path of the command. 1185The next 1186time the command is executed, the shell checks the saved path to see that it 1187is still valid, and if so, avoids repeating the path search. 1188Tracked aliases can be listed and created using 1189.Ic alias Fl t . 1190Note that changing the 1191.Ev PATH 1192parameter clears the saved paths for all tracked aliases. 1193If the 1194.Ic trackall 1195option is set (i.e.\& 1196.Ic set Fl o Ic trackall 1197or 1198.Ic set Fl h ) , 1199the shell tracks all commands. 1200This option is set automatically for non-interactive shells. 1201For interactive shells, only the following commands are 1202automatically tracked: 1203.Xr cat 1 , 1204.Xr cc 1 , 1205.Xr chmod 1 , 1206.Xr cp 1 , 1207.Xr date 1 , 1208.Xr ed 1 , 1209.Xr emacs 1 , 1210.Xr grep 1 , 1211.Xr ls 1 , 1212.Xr make 1 , 1213.Xr mv 1 , 1214.Xr pr 1 , 1215.Xr rm 1 , 1216.Xr sed 1 , 1217.Xr sh 1 , 1218.Xr vi 1 1219and 1220.Xr who 1 . 1221.Ss Substitution 1222The first step the shell takes in executing a simple-command is to perform 1223substitutions on the words of the command. 1224There are three kinds of 1225substitution: parameter, command and arithmetic. 1226Parameter substitutions, 1227which are described in detail in the next section, take the form 1228.Pf $ Ns Ar name 1229or 1230.Pf ${ Ns Ar ... Ns } ; 1231command substitutions take the form 1232.Pf $( Ns Ar command Ns \&) 1233or (deprecated) 1234.Pf \` Ns Ar command Ns \` 1235or (executed in the current environment) 1236.Pf ${\ \& Ar command Ns \&;} 1237and strip trailing newlines; 1238and arithmetic substitutions take the form 1239.Pf $(( Ns Ar expression Ns )) . 1240Parsing the current-environment command substitution requires a space, 1241tab or newline after the opening brace and that the closing brace be 1242recognised as a keyword (i.e. is preceded by a newline or semicolon). 1243They are also called funsubs (function substitutions) and behave like 1244functions in that 1245.Ic local 1246and 1247.Ic return 1248work, and in that 1249.Ic exit 1250terminates the parent shell; shell options are shared. 1251.Pp 1252Another variant of substitution are the valsubs (value substitutions) 1253.Pf ${\*(Ba\& Ns Ar command Ns \&;} 1254which are also executed in the current environment, like funsubs, but 1255share their I/O with the parent; instead, they evaluate to whatever 1256the, initially empty, expression-local variable 1257.Ev REPLY 1258is set to within the 1259.Ar command Ns s . 1260.Pp 1261If a substitution appears outside of double quotes, the results of the 1262substitution are generally subject to word or field splitting according to 1263the current value of the 1264.Ev IFS 1265parameter. 1266The 1267.Ev IFS 1268parameter specifies a list of octets which are used to break a string up 1269into several words; any octets from the set space, tab and newline that 1270appear in the 1271.Ev IFS 1272octets are called 1273.Dq IFS whitespace . 1274Sequences of one or more 1275.Ev IFS 1276whitespace octets, in combination with zero or one 1277.Pf non- Ev IFS 1278whitespace octets, delimit a field. 1279As a special case, leading and trailing 1280.Ev IFS 1281whitespace is stripped (i.e. no leading or trailing empty field 1282is created by it); leading or trailing 1283.Pf non- Ev IFS 1284whitespace does create an empty field. 1285.Pp 1286Example: If 1287.Ev IFS 1288is set to 1289.Dq Li \*(Ltspace\*(Gt: 1290and VAR is set to 1291.Dq Li \*(Ltspace\*(GtA\*(Ltspace\*(Gt:\*(Ltspace\*(Gt\*(Ltspace\*(GtB::D , 1292the substitution for $VAR results in four fields: 1293.Dq Li A , 1294.Dq Li B , 1295.Dq 1296(an empty field) and 1297.Dq Li D . 1298Note that if the 1299.Ev IFS 1300parameter is set to the empty string, no field splitting is done; 1301if it is unset, the default value of space, tab and newline is used. 1302.Pp 1303Also, note that the field splitting applies only to the immediate result of 1304the substitution. 1305Using the previous example, the substitution for $VAR:E 1306results in the fields: 1307.Dq Li A , 1308.Dq Li B , 1309.Dq 1310and 1311.Dq Li D:E , 1312not 1313.Dq Li A , 1314.Dq Li B , 1315.Dq , 1316.Dq Li D 1317and 1318.Dq Li E . 1319This behavior is POSIX compliant, but incompatible with some other shell 1320implementations which do field splitting on the word which contained the 1321substitution or use 1322.Dv IFS 1323as a general whitespace delimiter. 1324.Pp 1325The results of substitution are, unless otherwise specified, also subject to 1326brace expansion and file name expansion (see the relevant sections below). 1327.Pp 1328A command substitution is replaced by the output generated by the specified 1329command which is run in a subshell. 1330For 1331.Pf $( Ns Ar command Ns \&) 1332and 1333.Pf ${\*(Ba\& Ns Ar command Ns \&;} 1334and 1335.Pf ${\ \& Ar command Ns \&;} 1336substitutions, normal quoting rules are used when 1337.Ar command 1338is parsed; however, for the deprecated 1339.Pf \` Ns Ar command Ns \` 1340form, a 1341.Ql \e 1342followed by any of 1343.Ql $ , 1344.Ql \` 1345or 1346.Ql \e 1347is stripped (as is 1348.Ql \&" 1349when the substitution is part of a double-quoted string); a backslash 1350.Ql \e 1351followed by any other character is unchanged. 1352As a special case in command substitutions, a command of the form 1353.Pf \*(Lt Ar file 1354is interpreted to mean substitute the contents of 1355.Ar file . 1356Note that 1357.Ic $(\*(Ltfoo) 1358has the same effect as 1359.Ic $(cat foo) . 1360.Pp 1361Note that some shells do not use a recursive parser for command substitutions, 1362leading to failure for certain constructs; to be portable, use as workaround 1363.Dq Li x=$(cat) \*(Lt\*(Lt\eEOF 1364(or the newline-keeping 1365.Dq Li x=\*(Lt\*(Lt\eEOF 1366extension) instead to merely slurp the string. 1367.St -p1003.1 1368recommends using case statements of the form 1369.Li "x=$(case $foo in (bar) echo $bar ;; (*) echo $baz ;; esac)" 1370instead, which would work but not serve as example for this portability issue. 1371.Bd -literal -offset indent 1372x=$(case $foo in bar) echo $bar ;; *) echo $baz ;; esac) 1373# above fails to parse on old shells; below is the workaround 1374x=$(eval $(cat)) \*(Lt\*(Lt\eEOF 1375case $foo in bar) echo $bar ;; *) echo $baz ;; esac 1376EOF 1377.Ed 1378.Pp 1379Arithmetic substitutions are replaced by the value of the specified expression. 1380For example, the command 1381.Ic print $((2+3*4)) 1382displays 14. 1383See 1384.Sx Arithmetic expressions 1385for a description of an expression. 1386.Ss Parameters 1387Parameters are shell variables; they can be assigned values and their values 1388can be accessed using a parameter substitution. 1389A parameter name is either one 1390of the special single punctuation or digit character parameters described 1391below, or a letter followed by zero or more letters or digits 1392.Po 1393.Ql _ 1394counts as a letter 1395.Pc . 1396The latter form can be treated as arrays by appending an array index of the 1397form 1398.Op Ar expr 1399where 1400.Ar expr 1401is an arithmetic expression. 1402Array indices in 1403.Nm 1404are limited to the range 0 through 4294967295, inclusive. 1405That is, they are a 32-bit unsigned integer. 1406.Pp 1407Parameter substitutions take the form 1408.Pf $ Ns Ar name , 1409.Pf ${ Ns Ar name Ns } 1410or 1411.Sm off 1412.Pf ${ Ar name Oo Ar expr Oc } 1413.Sm on 1414where 1415.Ar name 1416is a parameter name. 1417Substitutions of an array in scalar context, i.e. without an 1418.Ar expr 1419in the latter form mentioned above, expand the element with the key 1420.Dq 0 . 1421Substitution of all array elements with 1422.Pf ${ Ns Ar name Ns \&[*]} 1423and 1424.Pf ${ Ns Ar name Ns \&[@]} 1425works equivalent to $* and $@ for positional parameters. 1426If substitution is performed on a parameter 1427(or an array parameter element) 1428that is not set, an empty string is substituted unless the 1429.Ic nounset 1430option 1431.Pq Ic set Fl u 1432is set, in which case an error occurs. 1433.Pp 1434Parameters can be assigned values in a number of ways. 1435First, the shell implicitly sets some parameters like 1436.Dq Li # , 1437.Dq Li PWD 1438and 1439.Dq Li $ ; 1440this is the only way the special single character parameters are set. 1441Second, parameters are imported from the shell's environment at startup. 1442Third, parameters can be assigned values on the command line: for example, 1443.Ic FOO=bar 1444sets the parameter 1445.Dq Li FOO 1446to 1447.Dq Li bar ; 1448multiple parameter assignments can be given on a single command line and they 1449can be followed by a simple-command, in which case the assignments are in 1450effect only for the duration of the command (such assignments are also 1451exported; see below for the implications of this). 1452Note that both the parameter name and the 1453.Ql = 1454must be unquoted for the shell to recognise a parameter assignment. 1455The construct 1456.Ic FOO+=baz 1457is also recognised; 1458the old and new values are string-concatenated with no separator. 1459The fourth way of setting a parameter is with the 1460.Ic export , 1461.Ic readonly 1462and 1463.Ic typeset 1464commands; see their descriptions in the 1465.Sx Command execution 1466section. 1467Fifth, 1468.Ic for 1469and 1470.Ic select 1471loops set parameters as well as the 1472.Ic getopts , 1473.Ic read 1474and 1475.Ic set Fl A 1476commands. 1477Lastly, parameters can be assigned values using assignment operators 1478inside arithmetic expressions (see 1479.Sx Arithmetic expressions 1480below) or using the 1481.Sm off 1482.Pf ${ Ar name No = Ar value No } 1483.Sm on 1484form of the parameter substitution (see below). 1485.Pp 1486Parameters with the export attribute (set using the 1487.Ic export 1488or 1489.Ic typeset Fl x 1490commands, or by parameter assignments followed by simple commands) are put in 1491the environment (see 1492.Xr environ 7 ) 1493of commands run by the shell as 1494.Ar name Ns = Ns Ar value 1495pairs. 1496The order in which parameters appear in the environment of a command is 1497unspecified. 1498When the shell starts up, it extracts parameters and their values 1499from its environment and automatically sets the export attribute for those 1500parameters. 1501.Pp 1502Modifiers can be applied to the 1503.Pf ${ Ns Ar name Ns } 1504form of parameter substitution: 1505.Bl -tag -width Ds 1506.Sm off 1507.It ${ Ar name No :\- Ar word No } 1508.Sm on 1509If 1510.Ar name 1511is set and not empty, 1512it is substituted; otherwise, 1513.Ar word 1514is substituted. 1515.Sm off 1516.It ${ Ar name No :+ Ar word No } 1517.Sm on 1518If 1519.Ar name 1520is set and not empty, 1521.Ar word 1522is substituted; otherwise, nothing is substituted. 1523.Sm off 1524.It ${ Ar name No := Ar word No } 1525.Sm on 1526If 1527.Ar name 1528is set and not empty, 1529it is substituted; otherwise, it is assigned 1530.Ar word 1531and the resulting value of 1532.Ar name 1533is substituted. 1534.Sm off 1535.It ${ Ar name No :? Ar word No } 1536.Sm on 1537If 1538.Ar name 1539is set and not empty, 1540it is substituted; otherwise, 1541.Ar word 1542is printed on standard error (preceded by 1543.Ar name : ) 1544and an error occurs (normally causing termination of a shell script, function, 1545or a script sourced using the 1546.Dq Li \&. 1547built-in). 1548If 1549.Ar word 1550is omitted, the string 1551.Dq Li parameter null or not set 1552is used instead. 1553.El 1554.Pp 1555Note that, for all of the above, 1556.Ar word 1557is actually considered quoted, and special parsing rules apply. 1558The parsing rules also differ on whether the expression is double-quoted: 1559.Ar word 1560then uses double-quoting rules, except for the double quote itself 1561.Pq Ql \&" 1562and the closing brace, which, if backslash escaped, gets quote removal applied. 1563.Pp 1564In the above modifiers, the 1565.Ql \&: 1566can be omitted, in which case the conditions only depend on 1567.Ar name 1568being set (as opposed to set and not empty). 1569If 1570.Ar word 1571is needed, parameter, command, arithmetic and tilde substitution are performed 1572on it; if 1573.Ar word 1574is not needed, it is not evaluated. 1575.Pp 1576The following forms of parameter substitution can also be used: 1577.Pp 1578.Bl -tag -width Ds -compact 1579.It Pf ${# Ns Ar name Ns \&} 1580The number of positional parameters if 1581.Ar name 1582is 1583.Dq Li * , 1584.Dq Li @ 1585or not specified; otherwise the length 1586.Pq in characters 1587of the string value of parameter 1588.Ar name . 1589.Pp 1590.It Pf ${# Ns Ar name Ns \&[*]} 1591.It Pf ${# Ns Ar name Ns \&[@]} 1592The number of elements in the array 1593.Ar name . 1594.Pp 1595.It Pf ${% Ns Ar name Ns \&} 1596The width 1597.Pq in screen columns 1598of the string value of parameter 1599.Ar name , 1600or \-1 if 1601.Pf ${ Ns Ar name Ns } 1602contains a control character. 1603.Pp 1604.It Pf ${! Ns Ar name Ns } 1605The name of the variable referred to by 1606.Ar name . 1607This will be 1608.Ar name 1609except when 1610.Ar name 1611is a name reference (bound variable), created by the 1612.Ic nameref 1613command (which is an alias for 1614.Ic typeset Fl n ) . 1615.Ar name 1616cannot be one of most special parameters (see below). 1617.Pp 1618.It Pf ${! Ns Ar name Ns \&[*]} 1619.It Pf ${! Ns Ar name Ns \&[@]} 1620The names of indices (keys) in the array 1621.Ar name . 1622.Pp 1623.Sm off 1624.It Xo 1625.Pf ${ Ar name 1626.Pf # Ar pattern No } 1627.Xc 1628.It Xo 1629.Pf ${ Ar name 1630.Pf ## Ar pattern No } 1631.Xc 1632.Sm on 1633If 1634.Ar pattern 1635matches the beginning of the value of parameter 1636.Ar name , 1637the matched text is deleted from the result of substitution. 1638A single 1639.Ql # 1640results in the shortest match, and two 1641of them result in the longest match. 1642.Pp 1643.Sm off 1644.It Xo 1645.Pf ${ Ar name 1646.Pf % Ar pattern No } 1647.Xc 1648.It Xo 1649.Pf ${ Ar name 1650.Pf %% Ar pattern No } 1651.Xc 1652.Sm on 1653Like ${...#...} but deletes from the end of the value. 1654.Pp 1655.Sm off 1656.It Xo 1657.Pf ${ Ar name 1658.Pf / Ar pattern / Ar string No } 1659.Xc 1660.It Xo 1661.Pf ${ Ar name 1662.Pf /# Ar pattern / Ar string No } 1663.Xc 1664.It Xo 1665.Pf ${ Ar name 1666.Pf /% Ar pattern / Ar string No } 1667.Xc 1668.It Xo 1669.Pf ${ Ar name 1670.Pf // Ar pattern / Ar string No } 1671.Xc 1672.Sm on 1673The longest match of 1674.Ar pattern 1675in the value of parameter 1676.Ar name 1677is replaced with 1678.Ar string 1679(deleted if 1680.Ar string 1681is empty; the trailing slash 1682.Pq Ql / 1683may be omitted in that case). 1684A leading slash followed by 1685.Ql # 1686or 1687.Ql % 1688causes the pattern to be anchored at the beginning or end of 1689the value, respectively; empty unanchored 1690.Ar pattern Ns s 1691cause no replacement; a single leading slash or use of a 1692.Ar pattern 1693that matches the empty string causes the replacement to 1694happen only once; two leading slashes cause all occurrences 1695of matches in the value to be replaced. 1696May be slow on long strings. 1697.Pp 1698.Sm off 1699.It Xo 1700.Pf ${ Ar name 1701.Pf @/ Ar pattern / Ar string No } 1702.Xc 1703.Sm on 1704The same as 1705.Sm off 1706.Xo 1707.Pf ${ Ar name 1708.Pf // Ar pattern / Ar string No } , 1709.Xc 1710.Sm on 1711except that both 1712.Ar pattern 1713and 1714.Ar string 1715are expanded anew for each iteration. 1716Use with 1717.Ev KSH_MATCH . 1718.Pp 1719.Sm off 1720.It Xo 1721.Pf ${ Ar name : Ns Ar pos 1722.Pf : Ns Ar len Ns } 1723.Xc 1724.Sm on 1725The first 1726.Ar len 1727characters of 1728.Ar name , 1729starting at position 1730.Ar pos , 1731are substituted. 1732Both 1733.Ar pos 1734and 1735.Pf : Ns Ar len 1736are optional. 1737If 1738.Ar pos 1739is negative, counting starts at the end of the string; if it 1740is omitted, it defaults to 0. 1741If 1742.Ar len 1743is omitted or greater than the length of the remaining string, 1744all of it is substituted. 1745Both 1746.Ar pos 1747and 1748.Ar len 1749are evaluated as arithmetic expressions. 1750.Pp 1751.It Pf ${ Ns Ar name Ns @#} 1752The hash (using the BAFH algorithm) of the expansion of 1753.Ar name . 1754This is also used internally for the shell's hashtables. 1755.Pp 1756.It Pf ${ Ns Ar name Ns @Q} 1757A quoted expression safe for re-entry, whose value is the value of the 1758.Ar name 1759parameter, is substituted. 1760.El 1761.Pp 1762Note that 1763.Ar pattern 1764may need extended globbing pattern 1765.Pq @(...) , 1766single 1767.Pq \&\*(aq...\&\*(aq 1768or double 1769.Pq \&"...\&" 1770quote escaping unless 1771.Fl o Ic sh 1772is set. 1773.Pp 1774The following special parameters are implicitly set by the shell and cannot be 1775set directly using assignments: 1776.Bl -tag -width "1 .. 9" 1777.It Ev \&! 1778Process ID of the last background process started. 1779If no background processes have been started, the parameter is not set. 1780.It Ev \&# 1781The number of positional parameters ($1, $2, etc.). 1782.It Ev \&$ 1783The PID of the shell or, if it is a subshell, the PID of the original shell. 1784Do 1785.Em NOT 1786use this mechanism for generating temporary file names; see 1787.Xr mktemp 1 1788instead. 1789.It Ev \- 1790The concatenation of the current single letter options (see the 1791.Ic set 1792command below for a list of options). 1793.It Ev \&? 1794The exit status of the last non-asynchronous command executed. 1795If the last command was killed by a signal, 1796.Ic \&$? 1797is set to 128 plus the signal number, but at most 255. 1798.It Ev 0 1799The name of the shell, determined as follows: 1800the first argument to 1801.Nm 1802if it was invoked with the 1803.Fl c 1804option and arguments were given; otherwise the 1805.Ar file 1806argument, if it was supplied; or else the name the shell was invoked with 1807.Pq i.e.\& Li argv[0] . 1808.Ev $0 1809is also set to the name of the current script, 1810or to the name of the current function if it was defined with the 1811.Ic function 1812keyword (i.e. a Korn shell style function). 1813.It Ev 1 No .. Ev 9 1814The first nine positional parameters that were supplied to the shell, function, 1815or script sourced using the 1816.Dq Li \&. 1817built-in. 1818Further positional parameters may be accessed using 1819.Pf ${ Ar number Ns } . 1820.It Ev * 1821All positional parameters (except 0), i.e. $1, $2, $3, ... 1822.br 1823If used 1824outside of double quotes, parameters are separate words (which are subjected 1825to word splitting); if used within double quotes, parameters are separated 1826by the first character of the 1827.Ev IFS 1828parameter (or the empty string if 1829.Ev IFS 1830is unset. 1831.It Ev @ 1832Same as 1833.Ic $* , 1834unless it is used inside double quotes, in which case a separate word is 1835generated for each positional parameter. 1836If there are no positional parameters, no word is generated. 1837.Ic \&"$@" 1838can be used to access arguments, verbatim, without losing 1839empty arguments or splitting arguments with spaces (IFS, actually). 1840.El 1841.Pp 1842The following parameters are set and/or used by the shell: 1843.Bl -tag -width "KSH_VERSION" 1844.It Ev _ 1845.Pq underscore 1846When an external command is executed by the shell, this parameter is set in the 1847environment of the new process to the path of the executed command. 1848In interactive use, this parameter is also set in the parent shell to the last 1849word of the previous command. 1850.It Ev BASHPID 1851The PID of the shell or subshell. 1852.It Ev CDPATH 1853Like 1854.Ev PATH , 1855but used to resolve the argument to the 1856.Ic cd 1857built-in command. 1858Note that if 1859.Ev CDPATH 1860is set and does not contain 1861.Dq Li \&. 1862or an empty string element, the current directory is not searched. 1863Also, the 1864.Ic cd 1865built-in command will display the resulting directory when a match is found 1866in any search path other than the empty path. 1867.It Ev COLUMNS 1868Set to the number of columns on the terminal or window. 1869If never unset and not imported, always set dynamically; 1870unless the value as reported by 1871.Xr stty 1 1872is non-zero and sane enough (minimum is 12x3), defaults to 80; similar for 1873.Ev LINES . 1874This parameter is used by the interactive line editing modes and by the 1875.Ic select , 1876.Ic set Fl o 1877and 1878.Ic kill Fl l 1879commands to format information columns. 1880Importing from the environment or unsetting this parameter removes the 1881binding to the actual terminal size in favour of the provided value. 1882.It Ev ENV 1883If this parameter is found to be set after any profile files are executed, the 1884expanded value is used as a shell startup file. 1885It typically contains function and alias definitions. 1886.It Ev EPOCHREALTIME 1887Time since the epoch, as returned by 1888.Xr gettimeofday 2 , 1889formatted as decimal 1890.Va tv_sec 1891followed by a dot 1892.Pq Ql \&. 1893and 1894.Va tv_usec 1895padded to exactly six decimal digits. 1896.It Ev EXECSHELL 1897If set, this parameter is assumed to contain the shell that is to be used to 1898execute commands that 1899.Xr execve 2 1900fails to execute and which do not start with a 1901.Dq Li #! Ns Ar shell 1902sequence. 1903.It Ev FCEDIT 1904The editor used by the 1905.Ic fc 1906command (see below). 1907.It Ev FPATH 1908Like 1909.Ev PATH , 1910but used when an undefined function is executed to locate the file defining the 1911function. 1912It is also searched when a command can't be found using 1913.Ev PATH . 1914See 1915.Sx Functions 1916below for more information. 1917.It Ev HISTFILE 1918The name of the file used to store command history. 1919When assigned to or unset, the file is opened, history is truncated 1920then loaded from the file; subsequent new commands (possibly consisting 1921of several lines) are appended once they successfully compiled. 1922Also, several invocations of the shell will share history if their 1923.Ev HISTFILE 1924parameters all point to the same file. 1925.Pp 1926.Sy Note : 1927If 1928.Ev HISTFILE 1929is unset or empty, no history file is used. 1930This is different from 1931.At 1932.Nm ksh . 1933.It Ev HISTSIZE 1934The number of commands normally stored for history. 1935The default is 2047. 1936The maximum is 65535. 1937.It Ev HOME 1938The default directory for the 1939.Ic cd 1940command and the value substituted for an unqualified 1941.Ic \*(TI 1942(see 1943.Sx Tilde expansion 1944below). 1945.It Ev IFS 1946Internal field separator, used during substitution and by the 1947.Ic read 1948command, to split values into distinct arguments; normally set to space, tab 1949and newline. 1950See 1951.Sx Substitution 1952above for details. 1953.Pp 1954.Sy Note : 1955This parameter is not imported from the environment when the shell is 1956started. 1957.It Ev KSHEGID 1958The effective group id of the shell at startup. 1959.It Ev KSHGID 1960The real group id of the shell at startup. 1961.It Ev KSHUID 1962The real user id of the shell at startup. 1963.It Ev KSH_MATCH 1964The last matched string. 1965In a future version, this will be an indexed array, 1966with indexes 1 and up capturing matching groups. 1967Set by string comparisons (= and !=) in double-bracket test 1968expressions when a match is found (when != returns false), by 1969.Ic case 1970when a match is encountered, and by the substitution operations 1971.Sm off 1972.Xo 1973.Pf ${ Ar x 1974.Pf # Ar pat No } , 1975.Sm on 1976.Xc 1977.Sm off 1978.Xo 1979.Pf ${ Ar x 1980.Pf ## Ar pat No } , 1981.Sm on 1982.Xc 1983.Sm off 1984.Xo 1985.Pf ${ Ar x 1986.Pf % Ar pat No } , 1987.Sm on 1988.Xc 1989.Sm off 1990.Xo 1991.Pf ${ Ar x 1992.Pf %% Ar pat No } , 1993.Sm on 1994.Xc 1995.Sm off 1996.Xo 1997.Pf ${ Ar x 1998.Pf / Ar pat / Ar rpl No } , 1999.Sm on 2000.Xc 2001.Sm off 2002.Xo 2003.Pf ${ Ar x 2004.Pf /# Ar pat / Ar rpl No } , 2005.Sm on 2006.Xc 2007.Sm off 2008.Xo 2009.Pf ${ Ar x 2010.Pf /% Ar pat / Ar rpl No } , 2011.Sm on 2012.Xc 2013.Sm off 2014.Xo 2015.Pf ${ Ar x 2016.Pf // Ar pat / Ar rpl No } , 2017.Sm on 2018.Xc 2019and 2020.Sm off 2021.Xo 2022.Pf ${ Ar x 2023.Pf @/ Ar pat / Ar rpl No } . 2024.Sm on 2025.Xc 2026See the end of the Emacs editing mode documentation for an example. 2027.It Ev KSH_VERSION 2028The name (self-identification) and version of the shell (read-only). 2029See also the version commands in 2030.Sx Emacs editing mode 2031and 2032.Sx Vi editing mode 2033sections, below. 2034.It Ev LINENO 2035The line number of the function or shell script that is currently being 2036executed. 2037.It Ev LINES 2038Set to the number of lines on the terminal or window. 2039Defaults to 24; always set, unless imported or unset. 2040See 2041.Ev COLUMNS . 2042.It Ev OLDPWD 2043The previous working directory. 2044Unset if 2045.Ic cd 2046has not successfully changed directories since the shell started or if the 2047shell doesn't know where it is. 2048.It Ev OPTARG 2049When using 2050.Ic getopts , 2051it contains the argument for a parsed option, if it requires one. 2052.It Ev OPTIND 2053The index of the next argument to be processed when using 2054.Ic getopts . 2055Assigning 1 to this parameter causes 2056.Ic getopts 2057to process arguments from the beginning the next time it is invoked. 2058.It Ev PATH 2059A colon (semicolon on OS/2) separated list of directories that are 2060searched when looking for commands and files sourced using the 2061.Dq Li \&. 2062command (see below). 2063An empty string resulting from a leading or trailing 2064(semi)colon, or two adjacent ones, is treated as a 2065.Dq Li \&. 2066(the current directory). 2067.It Ev PATHSEP 2068A colon (semicolon on OS/2), for the user's convenience. 2069.It Ev PGRP 2070The process ID of the shell's process group leader. 2071.It Ev PIPESTATUS 2072An array containing the errorlevel (exit status) codes, 2073one by one, of the last pipeline run in the foreground. 2074.It Ev PPID 2075The process ID of the shell's parent. 2076.It Ev PS1 2077The primary prompt for interactive shells. 2078Parameter, command and arithmetic 2079substitutions are performed, and 2080.Ql \&! 2081is replaced with the current command number (see the 2082.Ic fc 2083command below). 2084A literal 2085.Ql \&! 2086can be put in the prompt by placing 2087.Dq Li !! 2088in 2089.Ev PS1 . 2090.Pp 2091The default prompt is 2092.Dq Li $\ \& 2093for non-root users, 2094.Dq Li #\ \& 2095for root. 2096If 2097.Nm 2098is invoked by root and 2099.Ev PS1 2100does not contain a 2101.Ql # 2102character, the default value will be used even if 2103.Ev PS1 2104already exists in the environment. 2105.Pp 2106The 2107.Nm 2108distribution comes with a sample 2109.Pa dot.mkshrc 2110containing a sophisticated example, but you might like the following one 2111(note that ${HOSTNAME:=$(hostname)} and the 2112root-vs-user distinguishing clause are (in this example) executed at 2113.Ev PS1 2114assignment time, while the $USER and $PWD are escaped 2115and thus will be evaluated each time a prompt is displayed): 2116.Bd -literal 2117PS1=\*(aq${USER:=$(id \-un)}\*(aq"@${HOSTNAME:=$(hostname)}:\e$PWD $( 2118 if (( USER_ID )); then print \e$; else print \e#; fi) " 2119.Ed 2120.Pp 2121Note that since the command-line editors try to figure out how long the prompt 2122is (so they know how far it is to the edge of the screen), escape codes in 2123the prompt tend to mess things up. 2124You can tell the shell not to count certain 2125sequences (such as escape codes) by prefixing your prompt with a 2126character (such as Ctrl-A) followed by a carriage return and then delimiting 2127the escape codes with this character. 2128Any occurrences of that character in the prompt are not printed. 2129By the way, don't blame me for 2130this hack; it's derived from the original 2131.Xr ksh88 1 , 2132which did print the delimiter character so you were out of luck 2133if you did not have any non-printing characters. 2134.Pp 2135Since backslashes and other special characters may be 2136interpreted by the shell, to set 2137.Ev PS1 2138either escape the backslash itself 2139or use double quotes. 2140The latter is more practical. 2141This is a more complex example, 2142avoiding to directly enter special characters (for example with 2143.Ic \*(haV 2144in the emacs editing mode), 2145which embeds the current working directory, 2146in reverse video 2147.Pq colour would work, too , 2148in the prompt string: 2149.Bd -literal -offset indent 2150x=$(print \e\e001) # otherwise unused char 2151PS1="$x$(print \e\er)$x$(tput so)$x\e$PWD$x$(tput se)$x\*(Gt " 2152.Ed 2153.Pp 2154Due to a strong suggestion from David G. Korn, 2155.Nm 2156now also supports the following form: 2157.Bd -literal -offset indent 2158PS1=$\*(aq\e1\er\e1\ee[7m\e1$PWD\e1\ee[0m\e1\*(Gt \*(aq 2159.Ed 2160.It Ev PS2 2161Secondary prompt string, by default 2162.Dq Li \*(Gt\ \& , 2163used when more input is needed to complete a command. 2164.It Ev PS3 2165Prompt used by the 2166.Ic select 2167statement when reading a menu selection. 2168The default is 2169.Dq Li #?\ \& . 2170.It Ev PS4 2171Used to prefix commands that are printed during execution tracing (see the 2172.Ic set Fl x 2173command below). 2174Parameter, command and arithmetic substitutions are performed 2175before it is printed. 2176The default is 2177.Dq Li +\ \& . 2178You may want to set it to 2179.Dq Li \&[$EPOCHREALTIME]\ \& 2180instead, to include timestamps. 2181.It Ev PWD 2182The current working directory. 2183May be unset or empty if the shell doesn't know where it is. 2184.It Ev RANDOM 2185Each time 2186.Ev RANDOM 2187is referenced, it is assigned a number between 0 and 32767 from 2188a Linear Congruential PRNG first. 2189.It Ev REPLY 2190Default parameter for the 2191.Ic read 2192command if no names are given. 2193Also used in 2194.Ic select 2195loops to store the value that is read from standard input. 2196.It Ev SECONDS 2197The number of seconds since the shell started or, if the parameter has been 2198assigned an integer value, the number of seconds since the assignment plus the 2199value that was assigned. 2200.It Ev TMOUT 2201If set to a positive integer in an interactive shell, it specifies the maximum 2202number of seconds the shell will wait for input after printing the primary 2203prompt 2204.Pq Ev PS1 . 2205If the time is exceeded, the shell exits. 2206.It Ev TMPDIR 2207The directory temporary shell files are created in. 2208If this parameter is not 2209set or does not contain the absolute path of a writable directory, temporary 2210files are created in 2211.Pa /tmp . 2212.It Ev USER_ID 2213The effective user id of the shell at startup. 2214.El 2215.Ss Tilde expansion 2216Tilde expansion, which is done in parallel with parameter substitution, 2217is applied to words starting with an unquoted 2218.Ql \*(TI . 2219In parameter assignments (such as those preceding a simple-command or those 2220occurring in the arguments of a declaration utility), tilde expansion is done 2221after any assignment (i.e. after the equals sign) or after an unquoted colon 2222.Pq Ql \&: ; 2223login names are also delimited by colons. 2224The Korn shell, except in POSIX mode, always expands tildes after unquoted 2225equals signs, not just in assignment context (see below), and enables tab 2226completion for tildes after all unquoted colons during command line editing. 2227.Pp 2228The characters following the tilde, up to the first 2229.Ql / , 2230if any, are assumed to be a login name. 2231If the login name is empty, 2232.Ql + 2233or 2234.Ql \- , 2235the simplified value of the 2236.Ev HOME , 2237.Ev PWD 2238or 2239.Ev OLDPWD 2240parameter is substituted, respectively. 2241Otherwise, the password file is 2242searched for the login name, and the tilde expression is substituted with the 2243user's home directory. 2244If the login name is not found in the password file or 2245if any quoting or parameter substitution occurs in the login name, no 2246substitution is performed. 2247.Pp 2248The home directory of previously expanded login names are cached and re-used. 2249The 2250.Ic alias Fl d 2251command may be used to list, change and add to this cache (e.g.\& 2252.Ic alias \-d fac=/usr/local/facilities; cd \*(TIfac/bin ) . 2253.Ss Brace expansion (alternation) 2254Brace expressions take the following form: 2255.Bd -unfilled -offset indent 2256.Sm off 2257.Xo 2258.Ar prefix No { Ar str1 No ,..., 2259.Ar strN No } Ar suffix 2260.Xc 2261.Sm on 2262.Ed 2263.Pp 2264The expressions are expanded to 2265.Ar N 2266words, each of which is the concatenation of 2267.Ar prefix , 2268.Ar str Ns i 2269and 2270.Ar suffix 2271(e.g.\& 2272.Dq Li a{c,b{X,Y},d}e 2273expands to four words: 2274.Dq Li ace , 2275.Dq Li abXe , 2276.Dq Li abYe 2277and 2278.Dq Li ade ) . 2279As noted in the example, brace expressions can be nested and the resulting 2280words are not sorted. 2281Brace expressions must contain an unquoted comma 2282.Pq Ql \&, 2283for expansion to occur (e.g.\& 2284.Ic {} 2285and 2286.Ic {foo} 2287are not expanded). 2288Brace expansion is carried out after parameter substitution 2289and before file name generation. 2290.Ss File name patterns 2291A file name pattern is a word containing one or more unquoted 2292.Ql \&? , 2293.Ql * , 2294.Ql + , 2295.Ql @ 2296or 2297.Ql \&! 2298characters or 2299.Dq Li \&[...] 2300sequences. 2301Once brace expansion has been performed, the shell replaces file 2302name patterns with the sorted names of all the files that match the pattern 2303(if no files match, the word is left unchanged). 2304The pattern elements have the following meaning: 2305.Bl -tag -width Ds 2306.It \&? 2307Matches any single character. 2308.It \&* 2309Matches any sequence of octets. 2310.It \&[...] 2311Matches any of the octets inside the brackets. 2312Ranges of octets can be specified by separating two octets by a 2313.Ql \- 2314(e.g.\& 2315.Dq Li \&[a0\-9] 2316matches the letter 2317.Ql a 2318or any digit). 2319In order to represent itself, a 2320.Ql \- 2321must either be quoted or the first or last octet in the octet list. 2322Similarly, a 2323.Ql \&] 2324must be quoted or the first octet in the list if it is to represent itself 2325instead of the end of the list. 2326Also, a 2327.Ql \&! 2328appearing at the start of the list has special meaning (see below), so to 2329represent itself it must be quoted or appear later in the list. 2330.It \&[!...] 2331Like [...], 2332except it matches any octet not inside the brackets. 2333.Sm off 2334.It *( Ar pattern\*(Ba No ...\*(Ba Ar pattern ) 2335.Sm on 2336Matches any string of octets that matches zero or more occurrences of the 2337specified patterns. 2338Example: The pattern 2339.Ic *(foo\*(Babar) 2340matches the strings 2341.Dq , 2342.Dq Li foo , 2343.Dq Li bar , 2344.Dq Li foobarfoo , 2345etc. 2346.Sm off 2347.It +( Ar pattern\*(Ba No ...\*(Ba Ar pattern ) 2348.Sm on 2349Matches any string of octets that matches one or more occurrences of the 2350specified patterns. 2351Example: The pattern 2352.Ic +(foo\*(Babar) 2353matches the strings 2354.Dq Li foo , 2355.Dq Li bar , 2356.Dq Li foobar , 2357etc. 2358.Sm off 2359.It ?( Ar pattern\*(Ba No ...\*(Ba Ar pattern ) 2360.Sm on 2361Matches the empty string or a string that matches one of the specified 2362patterns. 2363Example: The pattern 2364.Ic ?(foo\*(Babar) 2365only matches the strings 2366.Dq , 2367.Dq Li foo 2368and 2369.Dq Li bar . 2370.Sm off 2371.It @( Ar pattern\*(Ba No ...\*(Ba Ar pattern ) 2372.Sm on 2373Matches a string that matches one of the specified patterns. 2374Example: The pattern 2375.Ic @(foo\*(Babar) 2376only matches the strings 2377.Dq Li foo 2378and 2379.Dq Li bar . 2380.Sm off 2381.It !( Ar pattern\*(Ba No ...\*(Ba Ar pattern ) 2382.Sm on 2383Matches any string that does not match one of the specified patterns. 2384Examples: The pattern 2385.Ic !(foo\*(Babar) 2386matches all strings except 2387.Dq Li foo 2388and 2389.Dq Li bar ; 2390the pattern 2391.Ic \&!(*) 2392matches no strings; the pattern 2393.Ic \&!(?)* 2394matches all strings (think about it). 2395.El 2396.Pp 2397Note that complicated globbing, especially with alternatives, 2398is slow; using separate comparisons may (or may not) be faster. 2399.Pp 2400Note that 2401.Nm mksh 2402.Po and Nm pdksh Pc 2403never matches 2404.Dq Li \&. 2405and 2406.Dq Li .. , 2407but 2408.At 2409.Nm ksh , 2410Bourne 2411.Nm sh 2412and GNU 2413.Nm bash 2414do. 2415.Pp 2416Note that none of the above pattern elements match either a period 2417.Pq Ql \&. 2418at the start of a file name or a slash 2419.Pq Ql / , 2420even if they are explicitly used in a [...] sequence; also, the names 2421.Dq Li \&. 2422and 2423.Dq Li .. 2424are never matched, even by the pattern 2425.Dq Li .* . 2426.Pp 2427If the 2428.Ic markdirs 2429option is set, any directories that result from file name generation are marked 2430with a trailing 2431.Ql / . 2432.Ss Input/output redirection 2433When a command is executed, its standard input, standard output and standard 2434error (file descriptors 0, 1 and 2, respectively) are normally inherited from 2435the shell. 2436Three exceptions to this are commands in pipelines, for which 2437standard input and/or standard output are those set up by the pipeline, 2438asynchronous commands created when job control is disabled, for which standard 2439input is initially set to 2440.Pa /dev/null , 2441and commands for which any of the following redirections have been specified: 2442.Bl -tag -width XXxxmarker 2443.It \*(Gt Ns Ar file 2444Standard output is redirected to 2445.Ar file . 2446If 2447.Ar file 2448does not exist, it is created; if it does exist, is a regular file, and the 2449.Ic noclobber 2450option is set, an error occurs; otherwise, the file is truncated. 2451Note that this means the command 2452.Ic cmd \*(Ltfoo \*(Gtfoo 2453will open 2454.Ar foo 2455for reading and then truncate it when it opens it for writing, before 2456.Ar cmd 2457gets a chance to actually read 2458.Ar foo . 2459.It \*(Gt\*(Ba Ns Ar file 2460Same as 2461.Ic \*(Gt , 2462except the file is truncated, even if the 2463.Ic noclobber 2464option is set. 2465.It \*(Gt\*(Gt Ns Ar file 2466Same as 2467.Ic \*(Gt , 2468except if 2469.Ar file 2470exists it is appended to instead of being truncated. 2471Also, the file is opened 2472in append mode, so writes always go to the end of the file (see 2473.Xr open 2 ) . 2474.It \*(Lt Ns Ar file 2475Standard input is redirected from 2476.Ar file , 2477which is opened for reading. 2478.It \*(Lt\*(Gt Ns Ar file 2479Same as 2480.Ic \*(Lt , 2481except the file is opened for reading and writing. 2482.It \*(Lt\*(Lt Ns Ar marker 2483After reading the command line containing this kind of redirection (called a 2484.Dq here document ) , 2485the shell copies lines from the command source into a temporary file until a 2486line matching 2487.Ar marker 2488is read. 2489When the command is executed, standard input is redirected from the 2490temporary file. 2491If 2492.Ar marker 2493contains no quoted characters, the contents of the temporary file are processed 2494as if enclosed in double quotes each time the command is executed, so 2495parameter, command and arithmetic substitutions are performed, along with 2496backslash 2497.Pq Ql \e 2498escapes for 2499.Ql $ , 2500.Ql \` , 2501.Ql \e 2502and 2503.Dq Li \enewline , 2504but not for 2505.Ql \&" . 2506If multiple here documents are used on the same command line, they are saved in 2507order. 2508.Pp 2509If no 2510.Ar marker 2511is given, the here document ends at the next 2512.Ic \*(Lt\*(Lt 2513and substitution will be performed. 2514If 2515.Ar marker 2516is only a set of either single 2517.Dq Li \*(aq\*(aq 2518or double 2519.Ql \&"" 2520quotes with nothing in between, the here document ends at the next empty line 2521and substitution will not be performed. 2522.It \*(Lt\*(Lt\- Ns Ar marker 2523Same as 2524.Ic \*(Lt\*(Lt , 2525except leading tabs are stripped from lines in the here document. 2526.It \*(Lt\*(Lt\*(Lt Ns Ar word 2527Same as 2528.Ic \*(Lt\*(Lt , 2529except that 2530.Ar word 2531.Em is 2532the here document. 2533This is called a here string. 2534.It \*(Lt& Ns Ar fd 2535Standard input is duplicated from file descriptor 2536.Ar fd . 2537.Ar fd 2538can be a single digit, indicating the number of an existing file descriptor; 2539the letter 2540.Ql p , 2541indicating the file descriptor associated with the output of the current 2542co-process; or the character 2543.Ql \- , 2544indicating standard input is to be closed. 2545.It \*(Gt& Ns Ar fd 2546Same as 2547.Ic \*(Lt& , 2548except the operation is done on standard output. 2549.It &\*(Gt Ns Ar file 2550Same as 2551.Ic \*(Gt Ns Ar file 2\*(Gt&1 . 2552This is a deprecated (legacy) GNU 2553.Nm bash 2554extension supported by 2555.Nm 2556which also supports the preceding explicit fd digit, for example, 2557.Ic 3&\*(Gt Ns Ar file 2558is the same as 2559.Ic 3\*(Gt Ns Ar file 2\*(Gt&3 2560in 2561.Nm 2562but a syntax error in GNU 2563.Nm bash . 2564.It Xo 2565.No &\*(Gt\*(Ba Ns Ar file , 2566.No &\*(Gt\*(Gt Ns Ar file , 2567.No &\*(Gt& Ns Ar fd 2568.Xc 2569Same as 2570.Ic \*(Gt\*(Ba Ns Ar file , 2571.Ic \*(Gt\*(Gt Ns Ar file 2572or 2573.Ic \*(Gt& Ns Ar fd , 2574followed by 2575.Ic 2\*(Gt&1 , 2576as above. 2577These are 2578.Nm 2579extensions. 2580.El 2581.Pp 2582In any of the above redirections, the file descriptor that is redirected 2583(i.e. standard input or standard output) 2584can be explicitly given by preceding the 2585redirection with a single digit. 2586Parameter, command and arithmetic 2587substitutions, tilde substitutions, and, if the shell is interactive, 2588file name generation are all performed on the 2589.Ar file , 2590.Ar marker 2591and 2592.Ar fd 2593arguments of redirections. 2594Note, however, that the results of any file name 2595generation are only used if a single file is matched; if multiple files match, 2596the word with the expanded file name generation characters is used. 2597Note 2598that in restricted shells, redirections which can create files cannot be used. 2599.Pp 2600For simple-commands, redirections may appear anywhere in the command; for 2601compound-commands 2602.Po 2603.Ic if 2604statements, etc. 2605.Pc , 2606any redirections must appear at the end. 2607Redirections are processed after 2608pipelines are created and in the order they are given, so the following 2609will print an error with a line number prepended to it: 2610.Pp 2611.Dl $ cat /foo/bar 2\*(Gt&1 \*(Gt/dev/null \*(Ba pr \-n \-t 2612.Pp 2613File descriptors created by I/O redirections are private to the shell. 2614.Ss Arithmetic expressions 2615Integer arithmetic expressions can be used with the 2616.Ic let 2617command, inside $((...)) expressions, inside array references (e.g.\& 2618.Ar name Ns Bq Ar expr ) , 2619as numeric arguments to the 2620.Ic test 2621command, and as the value of an assignment to an integer parameter. 2622.Em Warning : 2623This also affects implicit conversion to integer, for example as done by the 2624.Ic let 2625command. 2626.Em Never 2627use unchecked user input, e.g. from the environment, in an arithmetic context! 2628.Pp 2629Expressions are calculated using signed arithmetic and the 2630.Vt mksh_ari_t 2631type (a 32-bit signed integer), unless they begin with a sole 2632.Ql # 2633character, in which case they use 2634.Vt mksh_uari_t 2635.Po a 32-bit unsigned integer Pc . 2636.Pp 2637Expressions may contain alpha-numeric parameter identifiers, array references 2638and integer constants and may be combined with the following C operators 2639(listed and grouped in increasing order of precedence): 2640.Pp 2641Unary operators: 2642.Bd -literal -offset indent 2643+ \- ! \*(TI ++ \-\- 2644.Ed 2645.Pp 2646Binary operators: 2647.Bd -literal -offset indent 2648, 2649= += \-= *= /= %= \*(Lt\*(Lt= \*(Gt\*(Gt= \*(ha\*(Lt= \*(ha\*(Gt= &= \*(ha= \*(Ba= 2650\*(Ba\*(Ba 2651&& 2652\*(Ba 2653\*(ha 2654& 2655== != 2656\*(Lt \*(Lt= \*(Gt \*(Gt= 2657\*(Lt\*(Lt \*(Gt\*(Gt \*(ha\*(Lt \*(ha\*(Gt 2658+ \- 2659* / % 2660.Ed 2661.Pp 2662Ternary operators: 2663.Bd -literal -offset indent 2664?: (precedence is immediately higher than assignment) 2665.Ed 2666.Pp 2667Grouping operators: 2668.Bd -literal -offset indent 2669( ) 2670.Ed 2671.Pp 2672Integer constants and expressions are calculated using an exactly 32-bit 2673wide, signed or unsigned, type with silent wraparound on integer overflow. 2674Integer constants may be specified with arbitrary bases using the notation 2675.Ar base Ns # Ns Ar number , 2676where 2677.Ar base 2678is a decimal integer specifying the base (up to 36), and 2679.Ar number 2680is a number in the specified base. 2681Additionally, base-16 integers may be specified by prefixing them with 2682.Dq Li 0x 2683.Pq case-insensitive 2684in all forms of arithmetic expressions, except as numeric arguments to the 2685.Ic test 2686built-in utility. 2687Prefixing numbers with a sole digit zero 2688.Pq Dq Li 0 2689does not cause interpretation as octal (except in POSIX mode, 2690as required by the standard), as that's unsafe to do. 2691.Pp 2692As a special 2693.Nm mksh 2694extension, numbers to the base of one are treated as either (8-bit 2695transparent) ASCII or Universal Coded Character Set codepoints, 2696depending on the shell's 2697.Ic utf8\-mode 2698flag (current setting). 2699The 2700.At 2701.Nm ksh93 2702syntax of 2703.Dq Li \*(aqx\*(aq 2704instead of 2705.Dq Li 1#x 2706is also supported. 2707Note that NUL bytes (integral value of zero) cannot be used. 2708An unset or empty parameter evaluates to 0 in integer context. 2709If 2710.Sq Li x 2711isn't comprised of exactly one valid character, the behaviour is undefined 2712(usually, the shell aborts with a parse error, but rarely, it succeeds, 2713e.g. on the sequence C2 20); users of this feature (as opposed to 2714.Ic read Fl a ) 2715must validate the input first. 2716See 2717.Sx CAVEATS 2718for UTF-8 mode handling. 2719.Pp 2720The operators are evaluated as follows: 2721.Bl -tag -width Ds -offset indent 2722.It unary + 2723Result is the argument (included for completeness). 2724.It unary \- 2725Negation. 2726.It \&! 2727Logical NOT; 2728the result is 1 if argument is zero, 0 if not. 2729.It \*(TI 2730Arithmetic (bit-wise) NOT. 2731.It ++ 2732Increment; must be applied to a parameter (not a literal or other expression). 2733The parameter is incremented by 1. 2734When used as a prefix operator, the result 2735is the incremented value of the parameter; when used as a postfix operator, the 2736result is the original value of the parameter. 2737.It \-\- 2738Similar to 2739.Ic ++ , 2740except the parameter is decremented by 1. 2741.It \&, 2742Separates two arithmetic expressions; the left-hand side is evaluated first, 2743then the right. 2744The result is the value of the expression on the right-hand side. 2745.It = 2746Assignment; the variable on the left is set to the value on the right. 2747.It Xo 2748.No += \-= *= /= %= \*(Lt\*(Lt= \*(Gt\*(Gt= 2749.No \*(ha\*(Lt= \*(ha\*(Gt= &= \*(ha= \*(Ba= 2750.Xc 2751Assignment operators. 2752.Sm off 2753.Ao Ar var Ac Xo 2754.Aq Ar op 2755.No = Aq Ar expr 2756.Xc 2757.Sm on 2758is the same as 2759.Sm off 2760.Ao Ar var Ac Xo 2761.No = Aq Ar var 2762.Aq Ar op 2763.Aq Ar expr , 2764.Xc 2765.Sm on 2766with any operator precedence in 2767.Aq Ar expr 2768preserved. 2769For example, 2770.Dq Li var1 *= 5 + 3 2771is the same as specifying 2772.Dq Li var1 = var1 * (5 + 3) . 2773.It \*(Ba\*(Ba 2774Logical OR; 2775the result is 1 if either argument is non-zero, 0 if not. 2776The right argument is evaluated only if the left argument is zero. 2777.It && 2778Logical AND; 2779the result is 1 if both arguments are non-zero, 0 if not. 2780The right argument is evaluated only if the left argument is non-zero. 2781.It \*(Ba 2782Arithmetic (bit-wise) OR. 2783.It \*(ha 2784Arithmetic (bit-wise) XOR 2785(exclusive-OR). 2786.It & 2787Arithmetic (bit-wise) AND. 2788.It == 2789Equal; the result is 1 if both arguments are equal, 0 if not. 2790.It != 2791Not equal; the result is 0 if both arguments are equal, 1 if not. 2792.It \*(Lt 2793Less than; the result is 1 if the left argument is less than the right, 0 if 2794not. 2795.It \*(Lt= \*(Gt \*(Gt= 2796Less than or equal, greater than, greater than or equal. 2797See 2798.Ic \*(Lt . 2799.It \*(Lt\*(Lt \*(Gt\*(Gt 2800Shift left (right); the result is the left argument with its bits 2801arithmetically (signed operation) or logically (unsigned expression) 2802shifted left (right) by the amount given in the right argument. 2803.It \*(ha\*(Lt \*(ha\*(Gt 2804Rotate left (right); the result is similar to shift, 2805except that the bits shifted out at one end are shifted in 2806at the other end, instead of zero or sign bits. 2807.It + \- * / 2808Addition, subtraction, multiplication and division. 2809.It % 2810Remainder; the result is the symmetric remainder of the division of the left 2811argument by the right. 2812To get the mathematical modulus of 2813.Dq a Ic mod No b , 2814use the formula 2815.Do 2816.Pq a % b + b 2817.No % b 2818.Dc . 2819.It Xo 2820.Sm off 2821.Aq Ar arg1 ? 2822.Aq Ar arg2 : 2823.Aq Ar arg3 2824.Sm on 2825.Xc 2826If 2827.Aq Ar arg1 2828is non-zero, the result is 2829.Aq Ar arg2 ; 2830otherwise the result is 2831.Aq Ar arg3 . 2832The non-result argument is not evaluated. 2833.El 2834.Ss Co-processes 2835A co-process (which is a pipeline created with the 2836.Dq Li \*(Ba& 2837operator) is an asynchronous process that the shell can both write to (using 2838.Ic print Fl p ) 2839and read from (using 2840.Ic read Fl p ) . 2841The input and output of the co-process can also be manipulated using 2842.Ic \*(Gt&p 2843and 2844.Ic \*(Lt&p 2845redirections, respectively. 2846Once a co-process has been started, another can't 2847be started until the co-process exits, or until the co-process's input has been 2848redirected using an 2849.Ic exec Ar n Ns Ic \*(Gt&p 2850redirection. 2851If a co-process's input is redirected in this way, the next 2852co-process to be started will share the output with the first co-process, 2853unless the output of the initial co-process has been redirected using an 2854.Ic exec Ar n Ns Ic \*(Lt&p 2855redirection. 2856.Pp 2857Some notes concerning co-processes: 2858.Bl -bullet 2859.It 2860The only way to close the co-process's input (so the co-process reads an 2861end-of-file) is to redirect the input to a numbered file descriptor and then 2862close that file descriptor: 2863.Ic exec 3\*(Gt&p; exec 3\*(Gt&\- 2864.It 2865In order for co-processes to share a common output, the shell must keep the 2866write portion of the output pipe open. 2867This means that end-of-file will not be 2868detected until all co-processes sharing the co-process's output have exited 2869(when they all exit, the shell closes its copy of the pipe). 2870This can be 2871avoided by redirecting the output to a numbered file descriptor (as this also 2872causes the shell to close its copy). 2873Note that this behaviour is slightly 2874different from the original Korn shell which closes its copy of the write 2875portion of the co-process output when the most recently started co-process 2876(instead of when all sharing co-processes) exits. 2877.It 2878.Ic print Fl p 2879will ignore 2880.Dv SIGPIPE 2881signals during writes if the signal is not being trapped or ignored; the same 2882is true if the co-process input has been duplicated to another file descriptor 2883and 2884.Ic print Fl u Ns Ar n 2885is used. 2886.El 2887.Ss Functions 2888Functions are defined using either Korn shell 2889.Ic function Ar function-name 2890syntax or the Bourne/POSIX shell 2891.Ar function-name Ns \&() 2892syntax (see below for the difference between the two forms). 2893Functions are like 2894.Li .\(hyscripts 2895(i.e. scripts sourced using the 2896.Dq Li \&. 2897built-in) 2898in that they are executed in the current environment. 2899However, unlike 2900.Li .\(hyscripts , 2901shell arguments (i.e. positional parameters $1, $2, etc.)\& 2902are never visible inside them. 2903When the shell is determining the location of a command, functions 2904are searched after special built-in commands, before builtins and the 2905.Ev PATH 2906is searched. 2907.Pp 2908An existing function may be deleted using 2909.Ic unset Fl f Ar function-name . 2910A list of functions can be obtained using 2911.Ic typeset +f 2912and the function definitions can be listed using 2913.Ic typeset Fl f . 2914The 2915.Ic autoload 2916command (which is an alias for 2917.Ic typeset Fl fu ) 2918may be used to create undefined functions: when an undefined function is 2919executed, the shell searches the path specified in the 2920.Ev FPATH 2921parameter for a file with the same name as the function which, if found, is 2922read and executed. 2923If after executing the file the named function is found to 2924be defined, the function is executed; otherwise, the normal command search is 2925continued (i.e. the shell searches the regular built-in command table and 2926.Ev PATH ) . 2927Note that if a command is not found using 2928.Ev PATH , 2929an attempt is made to autoload a function using 2930.Ev FPATH 2931(this is an undocumented feature of the original Korn shell). 2932.Pp 2933Functions can have two attributes, 2934.Dq trace 2935and 2936.Dq export , 2937which can be set with 2938.Ic typeset Fl ft 2939and 2940.Ic typeset Fl fx , 2941respectively. 2942When a traced function is executed, the shell's 2943.Ic xtrace 2944option is turned on for the function's duration. 2945The 2946.Dq export 2947attribute of functions is currently not used. 2948.Pp 2949Since functions are executed in the current shell environment, parameter 2950assignments made inside functions are visible after the function completes. 2951If this is not the desired effect, the 2952.Ic typeset 2953command can be used inside a function to create a local parameter. 2954Note that 2955.At 2956.Nm ksh93 2957uses static scoping (one global scope, one local scope per function) 2958and allows local variables only on Korn style functions, whereas 2959.Nm mksh 2960uses dynamic scoping (nested scopes of varying locality). 2961Note that special parameters (e.g.\& 2962.Ic \&$$ , $! ) 2963can't be scoped in this way. 2964.Pp 2965The exit status of a function is that of the last command executed in the 2966function. 2967A function can be made to finish immediately using the 2968.Ic return 2969command; this may also be used to explicitly specify the exit status. 2970Note that when called in a subshell, 2971.Ic return 2972will only exit that subshell and will not cause the original shell to exit 2973a running function (see the 2974.Ic while Ns Li \&... Ns Ic read 2975loop FAQ). 2976.Pp 2977Functions defined with the 2978.Ic function 2979reserved word are treated differently in the following ways from functions 2980defined with the 2981.Ic \&() 2982notation: 2983.Bl -bullet 2984.It 2985The $0 parameter is set to the name of the function 2986(Bourne-style functions leave $0 untouched). 2987.It 2988.Ev OPTIND 2989is saved/reset and restored on entry and exit from the function so 2990.Ic getopts 2991can be used properly both inside and outside the function (Bourne-style 2992functions leave 2993.Ev OPTIND 2994untouched, so using 2995.Ic getopts 2996inside a function interferes with using 2997.Ic getopts 2998outside the function). 2999.It 3000Shell options 3001.Pq Ic set Fl o 3002have local scope, i.e. changes inside a function are reset upon its exit. 3003.El 3004.Pp 3005In the future, the following differences may also be added: 3006.Bl -bullet 3007.It 3008A separate trap/signal environment will be used during the execution of 3009functions. 3010This will mean that traps set inside a function will not affect the 3011shell's traps and signals that are not ignored in the shell (but may be 3012trapped) will have their default effect in a function. 3013.It 3014The EXIT trap, if set in a function, will be executed after the function 3015returns. 3016.El 3017.Ss Command execution 3018After evaluation of command-line arguments, redirections and parameter 3019assignments, the type of command is determined: a special built-in command, 3020a function, a normal builtin or the name of a file to execute found using the 3021.Ev PATH 3022parameter. 3023The checks are made in the above order. 3024Special built-in commands differ from other commands in that the 3025.Ev PATH 3026parameter is not used to find them, an error during their execution can 3027cause a non-interactive shell to exit, and parameter assignments that are 3028specified before the command are kept after the command completes. 3029Regular built-in commands are different only in that the 3030.Ev PATH 3031parameter is not used to find them. 3032.Pp 3033POSIX special built-in utilities: 3034.Pp 3035.Ic \&. , \&: , break , continue , 3036.Ic eval , exec , exit , export , 3037.Ic readonly , return , set , shift , 3038.Ic times , trap , unset 3039.Pp 3040Additional 3041.Nm 3042commands keeping assignments: 3043.Pp 3044.Ic source , typeset 3045.Pp 3046All other builtins are not special; these are at least: 3047.Pp 3048.Ic [\& , alias , bg , bind , 3049.Ic builtin , cat , cd , command , 3050.Ic echo , false , fc , fg , 3051.Ic getopts , jobs , kill , let , 3052.Ic print , pwd , read , realpath , 3053.Ic rename , sleep , suspend , test , 3054.Ic true , ulimit , umask , unalias , 3055.Ic wait , whence 3056.Pp 3057Once the type of command has been determined, any command-line parameter 3058assignments are performed and exported for the duration of the command. 3059.Pp 3060The following describes the special and regular built-in commands and 3061builtin-like reserved words, as well as some optional utilities: 3062.Pp 3063.Bl -tag -width false -compact 3064.It Ic \&. Ar file Op Ar arg ... 3065.Pq keeps assignments , special 3066This is called the 3067.Dq dot 3068command. 3069Execute the commands in 3070.Ar file 3071in the current environment. 3072The file is searched for in the directories of 3073.Ev PATH . 3074If arguments are given, the positional parameters may be used to access them 3075while 3076.Ar file 3077is being executed. 3078If no arguments are given, the positional parameters are 3079those of the environment the command is used in. 3080.Pp 3081.It Ic \&: Op Ar ... 3082.Pq keeps assignments , special 3083The null command. 3084.br 3085Exit status is set to zero. 3086.Pp 3087.It Ic Lb64decode Op Ar string 3088.Pq Li dot.mkshrc No function 3089Decode 3090.Ar string 3091or standard input to binary. 3092.Pp 3093.It Ic Lb64encode Op Ar string 3094.Pq Li dot.mkshrc No function 3095Encode 3096.Ar string 3097or standard input as base64. 3098.Pp 3099.It Ic Lbafh_init 3100.It Ic Lbafh_add Op Ar string 3101.It Ic Lbafh_finish 3102.Pq Li dot.mkshrc No functions 3103Implement the Better Avalance for the Jenkins Hash. 3104This is the same hash 3105.Nm 3106currently uses internally. 3107.No "After calling" Ic Lbafh_init , No call Ic Lbafh_add 3108multiple times until all input is read, then call 3109.Ic Lbafh_finish , 3110which writes the result to the unsigned integer 3111.Va Lbafh_v 3112variable for your consumption. 3113.Pp 3114.It Ic Lstripcom Op Ar 3115.Pq Li dot.mkshrc No function 3116Same as 3117.Ic cat 3118but strips any empty lines and comments (from any 3119.Sq # 3120character onwards, no escapes) 3121and reduces any amount of whitespace to one space character. 3122.Pp 3123.It Ic \&[ Ar expression Ic \&] 3124.Pq regular 3125See 3126.Ic test . 3127.Pp 3128.It Xo Ic alias 3129.Oo Fl d \*(Ba t Oo Fl r Oc \*(Ba 3130.Fl +x Oc 3131.Op Fl p 3132.Op Cm + 3133.Oo Ar name 3134.Op Ns = Ns Ar value 3135.Ar ... Oc 3136.Xc 3137.Pq regular 3138Without arguments, 3139.Ic alias 3140lists all aliases. 3141For any name without a value, the existing alias is listed. 3142Any name with a value defines an alias; see 3143.Sx Aliases 3144above. 3145.Li \&[][A\-Za\-z0\-9_!%+,.@:\-] 3146are valid in names, except they may not begin with a plus or hyphen-minus, and 3147.Ic \&[[ 3148is not a valid alias name. 3149.Pp 3150When listing aliases, one of two formats is used. 3151Normally, aliases are listed as 3152.Ar name Ns = Ns Ar value , 3153where 3154.Ar value 3155is quoted as necessary. 3156If options were preceded with 3157.Ql + , 3158or a lone 3159.Ql + 3160is given on the command line, only 3161.Ar name 3162is printed. 3163.Pp 3164The 3165.Fl d 3166option causes directory aliases which are used in tilde expansion to be 3167listed or set (see 3168.Sx Tilde expansion 3169above). 3170.Pp 3171With 3172.Fl p , 3173each alias is listed with the string 3174.Dq Li alias\ \& 3175prefixed. 3176.Pp 3177The 3178.Fl t 3179option indicates that tracked aliases are to be listed/set (values given 3180with the command are ignored for tracked aliases). 3181.Pp 3182The 3183.Fl r 3184option indicates that all tracked aliases are to be reset. 3185.Pp 3186The 3187.Fl x 3188option sets 3189.Pq Ic +x No clears 3190the export attribute of an alias, or, if no names are given, lists the aliases 3191with the export attribute (exporting an alias has no effect). 3192.Pp 3193.It Ic autoload 3194.Pq built-in alias 3195See 3196.Sx Functions 3197above. 3198.Pp 3199.It Ic bg Op Ar job ... 3200.Pq regular , needs job control 3201Resume the specified stopped job(s) in the background. 3202If no jobs are specified, 3203.Ic %+ 3204is assumed. 3205See 3206.Sx Job control 3207below for more information. 3208.Pp 3209.It Ic bind Fl l 3210.Pq regular 3211The names of editing commands strings can be bound to are listed. 3212See 3213.Sx Emacs editing mode 3214for more information. 3215.Pp 3216.It Ic bind Op Ar string ... 3217The current bindings, for 3218.Ar string , 3219if given, else all, are listed. 3220.Em Note: 3221Default prefix bindings 3222.Pq 1=Esc , 2=\*(haX , 3=NUL 3223assumed. 3224.Pp 3225.It Xo Ic bind 3226.Ar string Ns = Ns Op Ar editing-command 3227.Op Ar ... 3228.Xc 3229.It Xo Ic bind Fl m 3230.Ar string Ns = Ns Ar substitute 3231.Op Ar ... 3232.Xc 3233To 3234.Ar string , 3235which should consist of a control character 3236optionally preceded by one of the three prefix characters 3237and optionally succeeded by a tilde character, the 3238.Ar editing-command 3239is bound so that future input of the 3240.Ar string 3241will immediately invoke that editing command. 3242If a tilde postfix is given, a tilde trailing the control character is ignored. 3243If 3244.Fl m 3245.Pq macro 3246is given, future input of the 3247.Ar string 3248will be replaced by the given NUL-terminated 3249.Ar substitute 3250string, wherein prefix/control/tilde characters mapped to editing commands 3251.Pq but not those mapped to other macros 3252will be processed. 3253.Pp 3254Prefix and control characters may be written using caret notation, i.e.\& 3255.No \*(ha Ns Li Z 3256represents 3257.No Ctrl- Ns Li Z . 3258Use a backslash to escape the caret, an equals sign or another backslash. 3259Note that, although only three prefix characters 3260.Pq usually Esc, \*(haX and NUL 3261are supported, some multi-character sequences can be supported. 3262.Pp 3263.It Ic break Op Ar level 3264.Pq keeps assignments , special 3265Exit the 3266.Ar level Ns th 3267inner-most 3268.Ic for , 3269.Ic select , 3270.Ic until 3271or 3272.Ic while 3273loop. 3274.Ar level 3275defaults to 1. 3276.Pp 3277.It Xo 3278.Ic builtin 3279.Op Fl \- 3280.Ar command Op Ar arg ... 3281.Xc 3282.Pq regular 3283Execute the built-in command 3284.Ar command . 3285.Pp 3286.It Xo 3287.Ic \ebuiltin 3288.Ar command Op Ar arg ... 3289.Xc 3290.Pq regular , decl-forwarder 3291Same as 3292.Ic builtin . 3293Additionally acts as declaration utility forwarder, i.e. this is a 3294declaration utility (see 3295.Sx Tilde expansion ) 3296.No iff Ar command 3297is a declaration utility. 3298.Pp 3299.It Xo 3300.Ic cat 3301.Op Fl u 3302.Op Ar 3303.Xc 3304.Pq defer with flags 3305Copy files in command line order to standard output. 3306If a 3307.Ar file 3308is a single dash 3309.Pq Dq Li \- 3310or absent, read from standard input. 3311For direct builtin calls, the 3312.Tn POSIX 3313.Fl u 3314option is supported as a no-op. 3315For calls from shell, if any options are given, an external 3316.Xr cat 1 3317utility is preferred over the builtin. 3318.Pp 3319.It Xo 3320.Ic cd 3321.Op Fl L 3322.Op Ar dir 3323.Xc 3324.It Xo 3325.Ic cd 3326.Fl P Op Fl e 3327.Op Ar dir 3328.Xc 3329.It Xo 3330.Ic chdir 3331.Op Fl eLP 3332.Op Ar dir 3333.Xc 3334.Pq regular 3335Set the working directory to 3336.Ar dir . 3337If the parameter 3338.Ev CDPATH 3339is set, it lists the search path for the directory containing 3340.Ar dir . 3341An unset or empty path means the current directory. 3342If 3343.Ar dir 3344is found in any component of the 3345.Ev CDPATH 3346search path other than an unset or empty path, 3347the name of the new working directory will be written to standard output. 3348If 3349.Ar dir 3350is missing, the home directory 3351.Ev HOME 3352is used. 3353If 3354.Ar dir 3355is 3356.Dq Li \- , 3357the previous working directory is used (see the 3358.Ev OLDPWD 3359parameter). 3360.Pp 3361If the 3362.Fl L 3363option (logical path) is used or if the 3364.Ic physical 3365option isn't set (see the 3366.Ic set 3367command below), references to 3368.Dq Li .. 3369in 3370.Ar dir 3371are relative to the path used to get to the directory. 3372If the 3373.Fl P 3374option (physical path) is used or if the 3375.Ic physical 3376option is set, 3377.Dq Li .. 3378is relative to the filesystem directory tree. 3379The 3380.Ev PWD 3381and 3382.Ev OLDPWD 3383parameters are updated to reflect the current and old working directory, 3384respectively. 3385If the 3386.Fl e 3387option is set for physical filesystem traversal and 3388.Ev PWD 3389could not be set, the exit code is 1; greater than 1 if an 3390error occurred, 0 otherwise. 3391.Pp 3392.It Xo 3393.Ic cd 3394.Op Fl eLP 3395.Ar old new 3396.Xc 3397.It Xo 3398.Ic chdir 3399.Op Fl eLP 3400.Ar old new 3401.Xc 3402.Pq regular 3403The string 3404.Ar new 3405is substituted for 3406.Ar old 3407in the current directory, and the shell attempts to change to the new 3408directory. 3409.Pp 3410.It Ic cls 3411.Pq Li dot.mkshrc No alias 3412Reinitialise the display (hard reset). 3413.Pp 3414.It Xo 3415.Ic command 3416.Op Fl pVv 3417.Ar cmd 3418.Op Ar arg ... 3419.Xc 3420.Pq regular , decl-forwarder 3421If neither the 3422.Fl v 3423nor 3424.Fl V 3425option is given, 3426.Ar cmd 3427is executed exactly as if 3428.Ic command 3429had not been specified, with two exceptions: 3430firstly, 3431.Ar cmd 3432cannot be a shell function; 3433and secondly, special built-in commands lose their specialness 3434(i.e. redirection and utility errors do not cause the shell to 3435exit, and command assignments are not permanent). 3436.Pp 3437If the 3438.Fl p 3439option is given, a default search path, whose actual value is 3440system-dependent, is used instead of the current 3441.Ev PATH . 3442.Pp 3443If the 3444.Fl v 3445option is given, instead of executing 3446.Ar cmd , 3447information about what would be executed is given for each argument. 3448For builtins, functions and keywords, their names are simply printed; 3449for aliases, a command that defines them is printed; 3450for utilities found by searching the 3451.Ev PATH 3452parameter, the full path of the command is printed. 3453If no command is found 3454(i.e. the path search fails), nothing is printed and 3455.Ic command 3456exits with a non-zero status. 3457The 3458.Fl V 3459option is like the 3460.Fl v 3461option, but more verbose. 3462.Pp 3463.It Ic continue Op Ar level 3464.Pq keeps assignments , special 3465Jumps to the beginning of the 3466.Ar level Ns th 3467inner-most 3468.Ic for , 3469.Ic select , 3470.Ic until 3471or 3472.Ic while 3473loop. 3474.Ar level 3475defaults to 1. 3476.Pp 3477.It Ic dirs Op Fl lnv 3478.Pq Li dot.mkshrc No function 3479Print the directory stack. 3480.Fl l 3481causes tilde expansion to occur in the output. 3482.Fl n 3483causes line wrapping before 80 columns, whereas 3484.Fl v 3485causes numbered vertical output. 3486.Pp 3487.It Ic doch 3488.Pq Li dot.mkshrc No alias 3489Execute the last command with 3490.Xr sudo 8 . 3491.Pp 3492.It Xo 3493.Ic echo 3494.Op Fl Een 3495.Op Ar arg ... 3496.Xc 3497.Pq regular 3498.Em Warning: 3499this utility is not portable; use the standard Korn shell built-in utility 3500.Ic print 3501in new code instead. 3502.Pp 3503Print arguments, separated by spaces, followed by a newline, to 3504standard output. 3505The newline is suppressed if any of the arguments contain the 3506backslash sequence 3507.Dq Li \ec . 3508See the 3509.Ic print 3510command below for a list of other backslash sequences that are recognised. 3511.Pp 3512The options are provided for compatibility with 3513.Bx 3514shell scripts. 3515The 3516.Fl E 3517option suppresses backslash interpretation, 3518.Fl e 3519enables it (normally default), 3520.Fl n 3521suppresses the trailing newline, 3522and anything else causes the word to be printed as argument instead. 3523.Pp 3524If the 3525.Ic posix 3526or 3527.Ic sh 3528option is set or this is a direct builtin call or 3529.Ic print 3530.Fl R , 3531only the first argument is treated as an option, and only if it is exactly 3532.Dq Li \-n . 3533Backslash interpretation is disabled. 3534.Pp 3535.It Xo 3536.Ic enable 3537.Op Fl anps 3538.Op Ar name ... 3539.Xc 3540.Pq Li dot.mkshrc No function 3541Hide and unhide built-in utilities, aliases and functions and those defined in 3542.Li dot.mkshrc . 3543.Pp 3544If no 3545.Ar name 3546is given or the 3547.Fl p 3548option is used, builtins are printed (behind the string 3549.Dq Li enable\ \& , 3550followed by 3551.Dq Li \-n\ \& 3552if the builtin is currently disabled), otherwise, they are disabled (if 3553.Fl n 3554is given) or re-enabled. 3555.Pp 3556When printing, only enabled builtins are printed by default; the 3557.Fl a 3558options prints all builtins, while 3559.Fl n 3560prints only disabled builtins instead; 3561.Fl s 3562limits the list to POSIX special builtins. 3563.Pp 3564.It Ic eval Ar command ... 3565.Pq keeps assignments , special 3566The arguments are concatenated, with a space between each, 3567to form a single string which the shell then parses 3568and executes in the current execution environment. 3569.Pp 3570.It Xo 3571.Ic exec 3572.Op Fl a Ar argv0 3573.Op Fl c 3574.Op Ar command Op Ar arg ... 3575.Xc 3576.Pq keeps assignments , special 3577The command (with arguments) is executed without forking, 3578fully replacing the shell process; this is absolute, i.e.\& 3579.Ic exec 3580never returns, even if the 3581.Ar command 3582is not found. 3583The 3584.Fl a 3585option permits setting a different 3586.Li argv[0] 3587value, and 3588.Fl c 3589clears the environment before executing the child process, except for the 3590.Ev _ 3591parameter and direct assignments. 3592.Pp 3593If no command is given except for I/O redirection, the I/O redirection is 3594permanent and the shell is 3595not replaced. 3596Any file descriptors greater than 2 which are opened or 3597.Xr dup 2 Ns 'd 3598in this way are not made available to other executed commands (i.e. commands 3599that are not built-in to the shell). 3600Note that the Bourne shell differs here; 3601it does pass these file descriptors on. 3602.Pp 3603.It Ic exit Op Ar status 3604.Pq keeps assignments , special 3605The shell or subshell exits with the specified errorlevel 3606(or the current value of the 3607.Va $?\& 3608parameter). 3609.Pp 3610.It Xo 3611.Ic export 3612.Op Fl p 3613.Op Ar parameter Ns Op = Ns Ar value 3614.Xc 3615.Pq keeps assignments , special, decl-util 3616Sets the export attribute of the named parameters. 3617Exported parameters are passed in the environment to executed commands. 3618If values are specified, the named parameters are also assigned. 3619This is a declaration utility. 3620.Pp 3621If no parameters are specified, all parameters with the export attribute 3622set are printed one per line: either their names, or, if a 3623.Dq Li \- 3624with no option letter is specified, name=value pairs, or, with the 3625.Fl p 3626option, 3627.Ic export 3628commands suitable for re-entry. 3629.Pp 3630.It Ic extproc 3631.Pq OS/2 3632Null command required for shebang-like functionality. 3633.Pp 3634.It Ic false 3635.Pq regular 3636A command that exits with a non-zero status. 3637.Pp 3638.It Xo 3639.Ic fc 3640.Oo Fl e Ar editor \*(Ba 3641.Fl l Op Fl n Oc 3642.Op Fl r 3643.Op Ar first Op Ar last 3644.Xc 3645.Pq regular 3646.Ar first 3647and 3648.Ar last 3649select commands from the history. 3650Commands can be selected by history number 3651(negative numbers go backwards from the current, most recent, line) 3652or a string specifying the most recent command starting with that string. 3653The 3654.Fl l 3655option lists the command on standard output, and 3656.Fl n 3657inhibits the default command numbers. 3658The 3659.Fl r 3660option reverses the order of the list. 3661Without 3662.Fl l , 3663the selected commands are edited by the editor specified with the 3664.Fl e 3665option or, if no 3666.Fl e 3667is specified, the editor specified by the 3668.Ev FCEDIT 3669parameter (if this parameter is not set, 3670.Pa /bin/ed 3671is used), and the result is executed by the shell. 3672.Pp 3673.It Xo 3674.Ic fc 3675.Cm \-e \- \*(Ba Fl s 3676.Op Fl g 3677.Op Ar old Ns = Ns Ar new 3678.Op Ar prefix 3679.Xc 3680.Pq regular 3681Re-execute the selected command (the previous command by default) after 3682performing the optional substitution of 3683.Ar old 3684with 3685.Ar new . 3686If 3687.Fl g 3688is specified, all occurrences of 3689.Ar old 3690are replaced with 3691.Ar new . 3692The meaning of 3693.Cm \-e \- 3694and 3695.Fl s 3696is identical: re-execute the selected command without invoking an editor. 3697This command is usually accessed with the predefined: 3698.Ic alias r=\*(aqfc \-e \-\*(aq 3699.Pp 3700.It Ic fg Op Ar job ... 3701.Pq regular , needs job control 3702Resume the specified job(s) in the foreground. 3703If no jobs are specified, 3704.Ic %+ 3705is assumed. 3706.br 3707See 3708.Sx Job control 3709below for more information. 3710.Pp 3711.It Ic functions Op Ar name ... 3712.Pq built-in alias 3713Display the function definition commands corresponding to the listed, 3714or all defined, functions. 3715.Pp 3716.It Xo 3717.Ic getopts 3718.Ar optstring name 3719.Op Ar arg ... 3720.Xc 3721.Pq regular 3722Used by shell procedures to parse the specified arguments (or positional 3723parameters, if no arguments are given) and to check for legal options. 3724Options that do not take arguments may be grouped in a single argument. 3725If an option takes an argument and the option character is not the last 3726character of the word it is found in, the remainder of the word is taken to 3727be the option's argument; otherwise, the next word is the option's argument. 3728.Pp 3729.Ar optstring 3730contains the option letters to be recognised. 3731If a letter is followed by a colon, the option takes an argument. 3732.Pp 3733Each time 3734.Ic getopts 3735is invoked, it places the next option in the shell parameter 3736.Ar name . 3737If the option was introduced with a 3738.Ql + , 3739the character placed in 3740.Ar name 3741is prefixed with a 3742.Ql + . 3743If the option takes an argument, it is placed in the shell parameter 3744.Ev OPTARG. 3745.Pp 3746When an illegal option or a missing option argument is encountered, a question 3747mark or a colon is placed in 3748.Ar name 3749(indicating an illegal option or missing argument, respectively) and 3750.Ev OPTARG 3751is set to the option letter that caused the problem. 3752Furthermore, unless 3753.Ar optstring 3754begins with a colon, a question mark is placed in 3755.Ar name , 3756.Ev OPTARG 3757is unset and a diagnostic is shown on standard error. 3758.Pp 3759.Ic getopts 3760records the index of the argument to be processed by the next call in 3761.Ev OPTIND . 3762When the end of the options is encountered, 3763.Ic getopts 3764returns a non-zero exit status. 3765Options end at the first argument that does not start with a 3766.Ql \- 3767.Pq non-option argument 3768or when a 3769.Dq Li \-\- 3770argument is encountered. 3771.Pp 3772Option parsing can be reset by setting 3773.Ev OPTIND 3774to 1 (this is done automatically whenever the shell or a shell procedure is 3775invoked). 3776.Pp 3777.Em Warning: 3778Changing the value of the shell parameter 3779.Ev OPTIND 3780to a value other than 1 or parsing different sets of arguments without 3781resetting 3782.Ev OPTIND 3783may lead to unexpected results. 3784.Pp 3785.It Xo 3786.Ic hash 3787.Op Fl r 3788.Op Ar name ... 3789.Xc 3790.Pq built-in alias 3791Without arguments, any hashed executable command paths are listed. 3792The 3793.Fl r 3794option causes all hashed commands to be removed from the cache. 3795Each 3796.Ar name 3797is searched as if it were a command name 3798and added to the cache if it is an executable command. 3799.Pp 3800.It Ic hd Op Ar 3801.Pq Li dot.mkshrc No alias or function 3802Hexdump stdin or arguments legibly. 3803.Pp 3804.It Xo 3805.Ic history 3806.Op Fl nr 3807.Op Ar first Op Ar last 3808.Xc 3809.Pq built-in alias 3810Same as 3811.Ic fc Fl l Pq see above . 3812.Pp 3813.It Xo 3814.Ic integer 3815.Op flags 3816.Oo Ar name 3817.Op Ns = Ns Ar value 3818.Ar ... Oc 3819.Xc 3820.Pq built-in alias 3821Same as 3822.Ic typeset Fl i Pq see below . 3823.Pp 3824.It Xo 3825.Ic jobs 3826.Op Fl lnp 3827.Op Ar job ... 3828.Xc 3829.Pq regular 3830Display information about the specified job(s); if no jobs are specified, all 3831jobs are displayed. 3832The 3833.Fl n 3834option causes information to be displayed only for jobs that have changed 3835state since the last notification. 3836If the 3837.Fl l 3838option is used, the process ID of each process in a job is also listed. 3839The 3840.Fl p 3841option causes only the process group of each job to be printed. 3842See 3843.Sx Job control 3844below for the format of 3845.Ar job 3846and the displayed job. 3847.Pp 3848.It Xo 3849.Ic kill 3850.Oo Fl s Ar signame \*(Ba 3851.No \- Ns Ar signum \*(Ba 3852.No \- Ns Ar signame Oc 3853.No { Ar job \*(Ba pid \*(Ba pgrp No } 3854.Ar ... 3855.Xc 3856.Pq regular 3857Send the specified signal to the specified jobs, process IDs or process 3858groups. 3859If no signal is specified, the 3860.Dv TERM 3861signal is sent. 3862If a job is specified, the signal is sent to the job's process group. 3863See 3864.Sx Job control 3865below for the format of 3866.Ar job . 3867.Pp 3868.It Xo 3869.Ic kill 3870.Fl l 3871.Op Ar exit-status ... 3872.Xc 3873.Pq regular 3874Print the signal name corresponding to 3875.Ar exit-status . 3876If no arguments are specified, a list of all the signals with their numbers 3877and a short description of each are printed. 3878.Pp 3879.It Ic let Op Ar expression ... 3880.Pq regular 3881Each expression is evaluated (see 3882.Sx Arithmetic expressions 3883above). 3884If all expressions evaluate successfully, the exit status is 38850 (1) if the last expression evaluated to non-zero (zero). 3886If an error occurs during 3887the parsing or evaluation of an expression, the exit status is greater than 1. 3888Since expressions may need to be quoted, 3889.Li \&(( Ar expr Li )) 3890is syntactic sugar for: 3891.Dl "{ \e\ebuiltin let \*(aq" Ns Ar expr Ns Li "\*(aq; }" 3892.Pp 3893.It Xo 3894.Ic local 3895.Op flags 3896.Oo Ar name 3897.Op Ns = Ns Ar value 3898.Ar ... Oc 3899.Xc 3900.Pq built-in alias 3901Same as 3902.Ic typeset Pq see below . 3903.Pp 3904.It Xo 3905.Ic mknod 3906.Op Fl m Ar mode 3907.Ar name 3908.Cm b\*(Bac 3909.Ar major minor 3910.Xc 3911.It Xo 3912.Ic mknod 3913.Op Fl m Ar mode 3914.Ar name 3915.Cm p 3916.Xc 3917.Pq optional 3918Create a device special file. 3919The file type may be one of 3920.Cm b 3921(block type device), 3922.Cm c 3923(character type device) 3924or 3925.Cm p 3926.Pq named pipe , Tn FIFO . 3927The file created may be modified according to its 3928.Ar mode 3929(via the 3930.Fl m 3931option), 3932.Ar major 3933(major device number), 3934and 3935.Ar minor 3936(minor device number). 3937This is not normally part of 3938.Nm mksh ; 3939however, distributors may have added this as builtin as a speed hack. 3940.Pp 3941.It Xo 3942.Ic nameref 3943.Op flags 3944.Oo Ar name 3945.Op Ns = Ns Ar value 3946.Ar ... Oc 3947.Xc 3948.Pq built-in alias 3949Same as 3950.Ic typeset Fl n Pq see below . 3951.Pp 3952.It Xo 3953.Ic popd 3954.Op Fl lnv 3955.Op Ic + Ns Ar n 3956.Xc 3957.Pq Li dot.mkshrc No function 3958Pops the directory stack and returns to the new top directory. 3959The flags are as in 3960.Ic dirs Pq see above . 3961A numeric argument 3962.Ic + Ns Ar n 3963selects the entry in the stack to discard. 3964.Pp 3965.It Xo 3966.Ic print 3967.Oo Fl AcelNnprsu Ns Oo Ar n Oc \*(Ba 3968.Fl R Op Fl n Oc 3969.Op Ar argument ... 3970.Xc 3971.Pq regular 3972Print the specified argument(s) on the standard output, 3973separated by spaces, terminated with a newline. 3974The escapes mentioned in 3975.Sx Backslash expansion 3976above, as well as 3977.Dq Li \ec , 3978which is equivalent to using the 3979.Fl n 3980option, are interpreted. 3981.Pp 3982The options are as follows: 3983.Bl -tag -width XuXnX 3984.It Fl A 3985Each 3986.Ar argument 3987is arithmetically evaluated; the character corresponding to the 3988resulting value is printed. 3989Empty 3990.Ar argument Ns s 3991separate input words. 3992.It Fl c 3993The output is printed columnised, line by line, similar to how the 3994.Xr rs 1 3995utility, tab completion, the 3996.Ic kill Fl l 3997built-in utility and the 3998.Ic select 3999statement do. 4000.It Fl e 4001Restore backslash expansion after a previous 4002.Fl r . 4003.It Fl l 4004Change the output word separator to newline. 4005.It Fl N 4006Change the output word and line separator to ASCII NUL. 4007.It Fl n 4008Do not print the trailing line separator. 4009.It Fl p 4010Print to the co-process (see 4011.Sx Co-processes 4012above). 4013.It Fl r 4014Inhibit backslash expansion. 4015.It Fl s 4016Print to the history file instead of standard output. 4017.It Fl u Ns Op Ar n 4018Print to the file descriptor 4019.Ar n Pq defaults to 1 if omitted 4020instead of standard output. 4021.El 4022.Pp 4023The 4024.Fl R 4025option mostly emulates the 4026.Bx 4027.Xr echo 1 4028command which does not expand backslashes and interprets 4029its first argument as option only if it is exactly 4030.Dq Li \-n 4031.Pq to suppress the trailing newline . 4032.Pp 4033.It Ic printf Ar format Op Ar arguments ... 4034.Pq optional , defer always 4035If compiled in, format and print the arguments, supporting the bare 4036.Tn POSIX Ns -mandated 4037minimum. 4038If an external utility of the same name is found, it is deferred to, 4039unless run as direct builtin call or from the 4040.Ic builtin 4041utility. 4042.Pp 4043.It Ic pushd Op Fl lnv 4044.Pq Li dot.mkshrc No function 4045Rotate the top two elements of the directory stack. 4046The options are the same as for 4047.Ic dirs Pq see above , 4048and 4049.Ic pushd 4050changes to the topmost directory stack entry after acting. 4051.Pp 4052.It Xo 4053.Ic pushd 4054.Op Fl lnv 4055.Ic + Ns Ar n 4056.Xc 4057.Pq Li dot.mkshrc No function 4058Rotate the element number 4059.Ar n 4060to the top. 4061.Pp 4062.It Xo 4063.Ic pushd 4064.Op Fl lnv 4065.Ar name 4066.Xc 4067.Pq Li dot.mkshrc No function 4068Push 4069.Ar name 4070on top of the stack. 4071.Pp 4072.It Ic pwd Op Fl LP 4073.Pq regular 4074Print the present working directory. 4075If no options are given, 4076.Ic pwd 4077behaves as if the 4078.Fl P 4079option (print physical path) was used if the 4080.Ic physical 4081shell option is set, the 4082.Fl L 4083option (print logical path) otherwise. 4084The logical path is the path used to 4085.Ic cd 4086to the current directory; 4087the physical path is determined from the filesystem (by following 4088.Dq Li ..\& 4089directories to the root directory). 4090.Pp 4091.It Xo 4092.Ic r 4093.Op Fl g 4094.Op Ar old Ns = Ns Ar new 4095.Op Ar prefix 4096.Xc 4097.Pq built-in alias 4098Same as 4099.Ic fc Fl e \& Pq see above . 4100.Pp 4101.It Xo 4102.Ic read 4103.Op Fl A \*(Ba Fl a 4104.Op Fl d Ar x 4105.Oo Fl N Ar z \*(Ba 4106.Fl n Ar z Oc 4107.Oo Fl p \*(Ba 4108.Fl u Ns Op Ar n 4109.Oc Op Fl t Ar n 4110.Op Fl rs 4111.Op Ar p ... 4112.Xc 4113.Pq regular 4114Reads a line of input, separates the input into fields using the 4115.Ev IFS 4116parameter (see 4117.Sx Substitution 4118above) or other specified means, 4119and assigns each field to the specified parameters 4120.Ar p . 4121If no parameters are specified, the 4122.Ev REPLY 4123parameter is used to store the result. 4124If there are more parameters than fields, the extra parameters are set to 4125the empty string or 0; if there are more fields than parameters, the last 4126parameter is assigned the remaining fields (including the word separators). 4127.Pp 4128The options are as follows: 4129.Bl -tag -width XuXnX 4130.It Fl A 4131Store the result into the parameter 4132.Ar p 4133(or 4134.Ev REPLY ) 4135as array of words. 4136Only no or one parameter is accepted. 4137.It Fl a 4138Store the result, without applying IFS word splitting, into the parameter 4139.Ar p 4140(or 4141.Ev REPLY ) 4142as array of characters (wide characters if the 4143.Ic utf8\-mode 4144option is enacted, octets otherwise); the codepoints are 4145encoded as decimal numbers by default. 4146Only no or one parameter is accepted. 4147.It Fl d Ar x 4148Use the first byte of 4149.Ar x , 4150.Dv NUL 4151if empty, instead of the ASCII newline character to delimit input lines. 4152.It Fl N Ar z 4153Instead of reading till end-of-line, read exactly 4154.Ar z 4155bytes. 4156Upon EOF, a partial read is returned with exit status 1. 4157After timeout, a partial read is returned with an exit status as if 4158.Dv SIGALRM 4159were caught. 4160.It Fl n Ar z 4161Instead of reading till end-of-line, read up to 4162.Ar z 4163bytes but return as soon as any bytes are read, e.g.\& from a 4164slow terminal device, or if EOF or a timeout occurs. 4165.It Fl p 4166Read from the currently active co-process (see 4167.Sx Co-processes 4168above for details) instead of from a file descriptor. 4169.It Fl u Ns Op Ar n 4170Read from the file descriptor number 4171.Ar n 4172(defaults to 0, i.e.\& standard input). 4173.br 4174The argument must immediately follow the option character. 4175.It Fl t Ar n 4176Interrupt reading after 4177.Ar n 4178seconds (specified as positive decimal value with an optional fractional part). 4179The exit status of 4180.Nm read 4181is the same as if 4182.Dv SIGALRM 4183were caught if the timeout occurred, but partial reads may still be returned. 4184.It Fl r 4185Normally, 4186.Ic read 4187strips backslash-newline sequences and any remaining backslashes from input. 4188This option enables raw mode, in which backslashes are retained and ignored. 4189.It Fl s 4190The input line is saved to the history. 4191.El 4192.Pp 4193If the input is a terminal, both the 4194.Fl N 4195and 4196.Fl n 4197options set it into raw mode; 4198they read an entire file if \-1 is passed as 4199.Ar z 4200argument. 4201.Pp 4202The first parameter may have a question mark and a string appended to it, in 4203which case the string is used as a prompt (printed to standard error before 4204any input is read) if the input is a 4205.Xr tty 4 4206(e.g.\& 4207.Ic read nfoo?\*(aqnumber of foos: \*(aq ) . 4208.Pp 4209If no input is read or a timeout occurred, 4210.Ic read 4211exits with a non-zero status. 4212.Pp 4213.It Xo 4214.Ic readonly 4215.Op Fl p 4216.Oo Ar parameter 4217.Op Ns = Ns Ar value 4218.Ar ... Oc 4219.Xc 4220.Pq keeps assignments , special, decl-util 4221Sets the read-only attribute of the named parameters. 4222If values are given, 4223parameters are assigned these before disallowing writes. 4224Once a parameter is made read-only, 4225it cannot be unset and its value cannot be changed. 4226.Pp 4227If no parameters are specified, the names of all parameters with the read-only 4228attribute are printed one per line, unless the 4229.Fl p 4230option is used, in which case 4231.Ic readonly 4232commands defining all read-only parameters, including their values, are 4233printed. 4234.Pp 4235.It Xo 4236.Ic realpath 4237.Op Fl \- 4238.Ar name 4239.Xc 4240.Pq defer with flags 4241Resolves an absolute pathname corresponding to 4242.Ar name . 4243If the resolved pathname either exists or can be created immediately, 4244.Ic realpath 4245returns 0 and prints the resolved pathname, 4246otherwise or if an error occurs, it issues a diagnostic and returns nonzero. 4247If 4248.Ar name 4249ends with a slash 4250.Pq Ql / , 4251resolving to an extant non-directory is also treated as error. 4252.Pp 4253.It Xo 4254.Ic rename 4255.Op Fl \- 4256.Ar from to 4257.Xc 4258.Pq defer always 4259Renames the file 4260.Ar from 4261to 4262.Ar to . 4263Both must be complete pathnames and on the same device. 4264Intended for emergency situations 4265.Pq where Pa /bin/mv No becomes unusable ; 4266directly calls 4267.Xr rename 2 . 4268.Pp 4269.It Ic return Op Ar status 4270.Pq keeps assignments , special 4271Returns from a function or 4272.Ic \&. 4273script with errorlevel 4274.Ar status . 4275If no 4276.Ar status 4277is given, the exit status of the last executed command is used. 4278If used outside of a function or 4279.Ic \&. 4280script, it has the same effect as 4281.Ic exit . 4282Note that 4283.Nm 4284treats both profile and 4285.Ev ENV 4286files as 4287.Ic \&. 4288scripts, while the original Korn shell only treated profiles as 4289.Ic \&. 4290scripts. 4291.Pp 4292.It Ic rot13 4293.Pq Li dot.mkshrc No alias 4294ROT13-encrypts/-decrypts stdin to stdout. 4295.Pp 4296.It Xo 4297.Ic set Op Fl +abCefhiklmnprsUuvXx 4298.Op Fl +o Ar option 4299.Op Fl +A Ar name 4300.Op Fl \- 4301.Op Ar arg ... 4302.Xc 4303.Pq keeps assignments , special 4304The 4305.Ic set 4306command can be used to show all shell parameters 4307.Pq like Ic typeset \- , 4308set 4309.Pq Ic \- 4310or clear 4311.Pq Ic + 4312shell options, set an array parameter or the positional parameters. 4313.Pp 4314Options can be changed using the 4315.Fl +o Ar option 4316syntax, where 4317.Ar option 4318is the long name of an option, or using the 4319.Fl + Ns Ar letter 4320syntax, where 4321.Ar letter 4322is the option's single letter name (not all options have a single letter name). 4323The following table lists short (if extant) and long names 4324along with a description of what each option does: 4325.Bl -tag -width 3n 4326.It Fl A Ar name 4327Sets the elements of the array parameter 4328.Ar name 4329to 4330.Ar arg ... 4331.Pp 4332If 4333.Fl A 4334is used, the array is reset (i.e. emptied) first; if 4335.Ic +A 4336is used, the first N elements are set (where N is the number of arguments); 4337the rest are left untouched. 4338If 4339.Ar name 4340ends with a 4341.Sq + , 4342the array is appended to instead. 4343.Pp 4344An alternative syntax for the command 4345.Ic set \-A foo \-\- a b c; 4346.Ic set \-A foo+ \-\- d e 4347which is compatible to 4348.Tn GNU 4349.Nm bash 4350and also supported by 4351.At 4352.Nm ksh93 4353is: 4354.Ic foo=(a b c); foo+=(d e) 4355.It Fl a \*(Ba Fl o Ic allexport 4356All new parameters are created with the export attribute. 4357.It Fl b \*(Ba Fl o Ic notify 4358Print job notification messages asynchronously instead of just before the 4359prompt. 4360Only used with job control 4361.Pq Fl m . 4362.It Fl C \*(Ba Fl o Ic noclobber 4363Prevent \*(Gt redirection from overwriting existing files. 4364Instead, \*(Gt\*(Ba must be used to force an overwrite. 4365.Em Note: 4366This is not safe to use for creation of temporary files or 4367lockfiles due to a TOCTOU in a check allowing one to redirect output to 4368.Pa /dev/null 4369or other device files even in 4370.Ic noclobber 4371mode. 4372.It Fl e \*(Ba Fl o Ic errexit 4373Exit (after executing the 4374.Dv ERR 4375trap) as soon as an error occurs or a command fails (i.e. exits with a 4376non-zero status). 4377This does not apply to commands whose exit status is 4378explicitly tested by a shell construct such as 4379.Ic !\& , 4380.Ic if , 4381.Ic until 4382or 4383.Ic while 4384statements. 4385For 4386.Ic && , 4387.Ic \*(Ba\*(Ba 4388and pipelines (but mind 4389.Fl o Ic pipefail ) , 4390only the status of the last command is tested. 4391.It Fl f \*(Ba Fl o Ic noglob 4392Do not expand file name patterns. 4393.It Fl h \*(Ba Fl o Ic trackall 4394Create tracked aliases for all executed commands (see 4395.Sx Aliases 4396above). 4397Enabled by default for non-interactive shells. 4398.It Fl i \*(Ba Fl o Ic interactive 4399The shell is an interactive shell. 4400This option can only be used when the shell is invoked. 4401See above for details. 4402.It Fl k \*(Ba Fl o Ic keyword 4403Parameter assignments are recognised anywhere in a command. 4404.It Fl l \*(Ba Fl o Ic login 4405The shell is a login shell. 4406This option can only be used when the shell is invoked. 4407See above for what this means. 4408.It Fl m \*(Ba Fl o Ic monitor 4409Enable job control (default for interactive shells). 4410.It Fl n \*(Ba Fl o Ic noexec 4411Do not execute any commands. 4412Useful for checking the syntax of scripts. 4413Ignored if reading commands from a tty. 4414.It Fl p \*(Ba Fl o Ic privileged 4415The shell is a privileged shell. 4416It is set automatically if, when the shell starts, 4417the real UID or GID does not match 4418the effective UID (EUID) or GID (EGID), respectively. 4419See above for a description of what this means. 4420.Pp 4421If the shell is privileged, setting this flag after startup files 4422have been processed let it go full setuid and/or setgid. 4423Clearing this flag makes the shell drop privileges. 4424Changing this flag resets the groups vector. 4425.It Fl r \*(Ba Fl o Ic restricted 4426The shell is a restricted shell. 4427This option can only be used when the shell is invoked. 4428See above for what this means. 4429.It Fl s \*(Ba Fl o Ic stdin 4430If used when the shell is invoked, commands are read from standard input. 4431Set automatically if the shell is invoked with no arguments. 4432.Pp 4433When 4434.Fl s 4435is used with the 4436.Ic set 4437command it causes the specified arguments to be sorted ASCIIbetically 4438before assigning them to the positional parameters (or to array 4439.Ar name , 4440with 4441.Fl A ) . 4442.It Fl U \*(Ba Fl o Ic utf8\-mode 4443Enable UTF-8 support in the 4444.Sx Emacs editing mode 4445and internal string handling functions. 4446This flag is disabled by default, but can be enabled by setting it on the 4447shell command line; is enabled automatically for interactive shells if 4448requested at compile time, your system supports 4449.Fn setlocale LC_CTYPE \&"" 4450and optionally 4451.Fn nl_langinfo CODESET , 4452or the 4453.Ev LC_ALL , 4454.Ev LC_CTYPE 4455or 4456.Ev LANG 4457environment variables, 4458and at least one of these returns something that matches 4459.Dq UTF\-8 4460or 4461.Dq utf8 4462case-insensitively; for direct builtin calls depending on the 4463aforementioned environment variables; or for stdin or scripts, 4464if the input begins with a UTF-8 Byte Order Mark. 4465.Pp 4466In near future, locale tracking will be implemented, which means that 4467.Ic set Fl +U 4468is changed whenever one of the 4469.Tn POSIX 4470locale-related environment variables changes. 4471.It Fl u \*(Ba Fl o Ic nounset 4472Referencing of an unset parameter, other than 4473.Dq Li $@ 4474or 4475.Dq Li $* , 4476is treated as an error, unless one of the 4477.Ql \- , 4478.Ql + 4479or 4480.Ql = 4481modifiers is used. 4482.It Fl v \*(Ba Fl o Ic verbose 4483Write shell input to standard error as it is read. 4484.It Fl X \*(Ba Fl o Ic markdirs 4485Mark directories with a trailing 4486.Ql / 4487during globbing. 4488.It Fl x \*(Ba Fl o Ic xtrace 4489Print commands when they are executed, preceded by 4490.Ev PS4 . 4491.It Fl o Ic bgnice 4492Background jobs are run with lower priority. 4493.It Fl o Ic braceexpand 4494Enable brace expansion. 4495This is enabled by default. 4496.It Fl o Ic emacs 4497Enable BRL emacs-like command-line editing (interactive shells only); see 4498.Sx Emacs editing mode . 4499Enabled by default. 4500.It Fl o Ic gmacs 4501Enable gmacs-like command-line editing (interactive shells only). 4502Currently identical to emacs editing except that 4503.Li transpose\-chars Pq \*(haT 4504acts slightly differently. 4505.It Fl o Ic ignoreeof 4506The shell will not (easily) exit when end-of-file is read; 4507.Ic exit 4508must be used. 4509To avoid infinite loops, the shell will exit if 4510.Dv EOF 4511is read 13 times in a row. 4512.It Fl o Ic inherit\-xtrace 4513Do not reset 4514.Fl o Ic xtrace 4515upon entering functions (default). 4516.It Fl o Ic nohup 4517Do not kill running jobs with a 4518.Dv SIGHUP 4519signal when a login shell exits. 4520Currently set by default, but this may 4521change in the future to be compatible with 4522.At 4523.Nm ksh , 4524which 4525doesn't have this option, but does send the 4526.Dv SIGHUP 4527signal. 4528.It Fl o Ic nolog 4529No effect. 4530In the original Korn shell, this prevented function definitions from 4531being stored in the history file. 4532.It Fl o Ic physical 4533Causes the 4534.Ic cd 4535and 4536.Ic pwd 4537commands to use 4538.Dq physical 4539(i.e. the filesystem's) 4540.Dq Li .. 4541directories instead of 4542.Dq logical 4543directories (i.e. the shell handles 4544.Dq Li .. , 4545which allows the user to be oblivious of symbolic links to directories). 4546Clear by default. 4547Note that setting this option does not affect the current value of the 4548.Ev PWD 4549parameter; only the 4550.Ic cd 4551command changes 4552.Ev PWD . 4553See 4554.Ic cd 4555and 4556.Ic pwd 4557above for more details. 4558.It Fl o Ic pipefail 4559Make the exit status of a pipeline the rightmost non-zero errorlevel, 4560or zero if all commands exited with zero. 4561.It Fl o Ic posix 4562Behave closer to the standards 4563(see 4564.Sx POSIX mode 4565for details). 4566Automatically enabled if the shell invocation basename, after 4567.Sq \- 4568and 4569.Sq r 4570processing, begins with 4571.Dq sh 4572and 4573.Pq often used for the Nm lksh No binary 4574this autodetection feature is compiled in. 4575As a side effect, setting this flag turns off the 4576.Ic braceexpand 4577and 4578.Ic utf8\-mode 4579flags, which can be turned back on manually, and 4580.Pq unless both are set in the same command 4581.Ic sh 4582mode. 4583.It Fl o Ic sh 4584Enable kludge 4585.Pa /bin/sh 4586compatibility mode (see 4587.Sx SH mode 4588below for details). 4589Automatically enabled if the basename of the shell invocation, after 4590.Sq \- 4591and 4592.Sq r 4593processing, begins with 4594.Dq sh 4595and this autodetection feature is compiled in 4596.Pq rather uncommon . 4597As a side effect, setting this flag turns off the 4598.Ic braceexpand 4599flag, which can be turned back on manually, and 4600.Ic posix 4601mode (unless both are set in the same command). 4602.It Fl o Ic vi 4603Enable 4604.Xr vi 1 Ns -like 4605command-line editing (interactive shells only). 4606See 4607.Sx Vi editing mode 4608for documentation and limitations. 4609.It Fl o Ic vi\-esccomplete 4610In vi command-line editing, do command and file name completion when Esc 4611.Pq \*(ha[ 4612is entered in command mode. 4613.It Fl o Ic vi\-tabcomplete 4614In vi command-line editing, do command and file name completion when Tab 4615.Pq \*(haI 4616is entered in insert mode (default). 4617.It Fl o Ic viraw 4618No effect. 4619In the original Korn shell, unless 4620.Ic viraw 4621was set, the vi command-line mode would let the 4622.Xr tty 4 4623driver do the work until Esc was entered. 4624.Nm 4625is always in viraw mode. 4626.El 4627.Pp 4628These options can also be used upon invocation of the shell. 4629The current set of 4630options (with single letter names) can be found in the parameter 4631.Dq Li $\- . 4632.Ic set Fl o 4633with no option name will list all the options and whether each is on or off; 4634.Ic set +o 4635prints a command to restore the current option set, using the internal 4636.Ic set Fl o Ic .reset 4637construct, which is an implementation detail; these commands are transient 4638.Pq only valid within the current shell session . 4639.Pp 4640Remaining arguments, if any, are positional parameters and are assigned, in 4641order, to the positional parameters (i.e. $1, $2, etc.). 4642If options end with 4643.Dq Li \-\- 4644and there are no remaining arguments, all positional parameters are cleared. 4645For unknown historical reasons, a lone 4646.Dq Li \- 4647option is treated specially\*(EMit clears both the 4648.Fl v 4649and 4650.Fl x 4651options. 4652If no options or arguments are given, the values of all parameters are printed 4653.Pq suitably quoted . 4654.Pp 4655.It Xo 4656.Ic setenv 4657.Op Ar name Op Ar value 4658.Xc 4659.Pq Li dot.mkshrc No function 4660Without arguments, display the names and values of all exported parameters. 4661Otherwise, set 4662.Ar name Ns 's 4663export attribute, and its value to 4664.Ar value Pq empty string if none given . 4665.Pp 4666.It Ic shift Op Ar number 4667.Pq keeps assignments , special 4668The positional parameters 4669.Ar number Ns +1 , 4670.Ar number Ns +2 , 4671etc. 4672.Pq Ar number No defaults to 1 4673are renamed to 1, 2, etc. 4674.Pp 4675.It Ic sleep Ar seconds 4676.Pq regular , needs Xr select 2 4677Suspends execution for a minimum of the 4678.Ar seconds 4679(specified as positive decimal value with an optional fractional part). 4680Signal delivery may continue execution earlier. 4681.Pp 4682.It Ic smores Op Ar 4683.Pq Li dot.mkshrc No function 4684Simple pager: 4685.Aq Enter 4686next; 4687.So q Sc Ns + Ns Aq Enter 4688quit 4689.Pp 4690.It Ic source Ar file Op Ar arg ... 4691.Pq keeps assignments 4692Like 4693.Ic \&. 4694.Pq Dq dot , 4695except that the current working directory is appended to the 4696search path. 4697.Pq GNU Nm bash No extension 4698.Pp 4699.It Ic suspend 4700.Pq needs job control and Xr getsid 2 4701Stops the shell as if it had received the suspend character from 4702the terminal. 4703.Pp 4704It is not possible to suspend a login shell unless the parent process 4705is a member of the same terminal session but is a member of a different 4706process group. 4707As a general rule, if the shell was started by another shell or via 4708.Xr su 1 , 4709it can be suspended. 4710.Pp 4711.It Ic test Ar expression 4712.It Ic \&[ Ar expression Ic \&] 4713.Pq regular 4714.Ic test 4715evaluates the 4716.Ar expression 4717and exits with status code 0 if true, 1 if false, 4718or greater than 1 if there was an error. 4719It is often used as the condition command of 4720.Ic if 4721and 4722.Ic while 4723statements. 4724All 4725.Ar file 4726expressions, except 4727.Fl h 4728and 4729.Fl L , 4730follow symbolic links. 4731.Pp 4732The following basic expressions are available: 4733.Bl -tag -width 17n 4734.It Fl a Ar file 4735.Ar file 4736exists. 4737.It Fl b Ar file 4738.Ar file 4739is a block special device. 4740.It Fl c Ar file 4741.Ar file 4742is a character special device. 4743.It Fl d Ar file 4744.Ar file 4745is a directory. 4746.It Fl e Ar file 4747.Ar file 4748exists. 4749.It Fl f Ar file 4750.Ar file 4751is a regular file. 4752.It Fl G Ar file 4753.Ar file Ns 's 4754group is the shell's effective group ID. 4755.It Fl g Ar file 4756.Ar file Ns 's 4757mode has the setgid bit set. 4758.It Fl H Ar file 4759.Ar file 4760is a context dependent directory (only useful on HP-UX). 4761.It Fl h Ar file 4762.Ar file 4763is a symbolic link. 4764.It Fl k Ar file 4765.Ar file Ns 's 4766mode has the 4767.Xr sticky 7 4768bit set. 4769.It Fl L Ar file 4770.Ar file 4771is a symbolic link. 4772.It Fl O Ar file 4773.Ar file Ns 's 4774owner is the shell's effective user ID. 4775.It Fl p Ar file 4776.Ar file 4777is a named pipe 4778.Pq Tn FIFO . 4779.It Fl r Ar file 4780.Ar file 4781exists and is readable. 4782.It Fl S Ar file 4783.Ar file 4784is a 4785.Xr unix 4 Ns -domain 4786socket. 4787.It Fl s Ar file 4788.Ar file 4789is not empty. 4790.It Fl t Ar fd 4791File descriptor 4792.Ar fd 4793is a 4794.Xr tty 4 4795device. 4796.It Fl u Ar file 4797.Ar file Ns 's 4798mode has the setuid bit set. 4799.It Fl w Ar file 4800.Ar file 4801exists and is writable. 4802.It Fl x Ar file 4803.Ar file 4804exists and is executable. 4805.It Ar file1 Fl nt Ar file2 4806.Ar file1 4807is newer than 4808.Ar file2 4809or 4810.Ar file1 4811exists and 4812.Ar file2 4813does not. 4814.It Ar file1 Fl ot Ar file2 4815.Ar file1 4816is older than 4817.Ar file2 4818or 4819.Ar file2 4820exists and 4821.Ar file1 4822does not. 4823.It Ar file1 Fl ef Ar file2 4824.Ar file1 4825is the same file as 4826.Ar file2 . 4827.It Ar string 4828.Ar string 4829has non-zero length. 4830.It Fl n Ar string 4831.Ar string 4832is not empty. 4833.It Fl z Ar string 4834.Ar string 4835is empty. 4836.It Fl v Ar name 4837The shell parameter 4838.Ar name 4839is set. 4840.It Fl o Ar option 4841Shell 4842.Ar option 4843is set (see the 4844.Ic set 4845command above for a list of options). 4846As a non-standard extension, if the option starts with a 4847.Ql \&! , 4848the test is negated; the test always fails if 4849.Ar option 4850doesn't exist (so [ \-o foo \-o \-o !foo ] returns true if and only if option 4851.Ar foo 4852exists). 4853The same can be achieved with [ \-o ?foo ] like in 4854.At 4855.Nm ksh93 . 4856.Ar option 4857can also be the short flag prefixed with either 4858.Ql \- 4859or 4860.Ql + 4861.Pq no logical negation , 4862for example 4863.Dq Li \-x 4864or 4865.Dq Li +x 4866instead of 4867.Dq Li xtrace . 4868.It Ar string No = Ar string 4869Strings are equal. 4870In double brackets, pattern matching 4871.Pq R59+ using extglobs 4872occurs if the right-hand string isn't quoted. 4873.It Ar string No == Ar string 4874Same as 4875.Sq = 4876.Pq deprecated . 4877.It Ar string No != Ar string 4878Strings are not equal. 4879See 4880.Sq = 4881regarding pattern matching. 4882.It Ar string No \*(Gt Ar string 4883First string operand is greater than second string operand. 4884.It Ar string No \*(Lt Ar string 4885First string operand is less than second string operand. 4886.It Ar number Fl eq Ar number 4887Numbers compare equal. 4888.It Ar number Fl ne Ar number 4889Numbers compare not equal. 4890.It Ar number Fl ge Ar number 4891Numbers compare greater than or equal. 4892.It Ar number Fl gt Ar number 4893Numbers compare greater than. 4894.It Ar number Fl le Ar number 4895Numbers compare less than or equal. 4896.It Ar number Fl \< Ar number 4897Numbers compare less than. 4898.El 4899.Pp 4900The above basic expressions, in which unary operators have precedence over 4901binary operators, may be combined with the following operators (listed in 4902increasing order of precedence): 4903.Bd -literal -offset indent 4904expr \-o expr Logical OR. 4905expr \-a expr Logical AND. 4906! expr Logical NOT. 4907( expr ) Grouping. 4908.Ed 4909.Pp 4910Note that a number actually may be an arithmetic expression, such as 4911a mathematical term or the name of an integer variable: 4912.Bd -literal -offset indent 4913x=1; [ "x" \-eq 1 ] evaluates to true 4914.Ed 4915.Pp 4916Note that some special rules are applied (courtesy of 4917.Px 4918) if the number of arguments to 4919.Ic test 4920or inside the brackets 4921.Ic \&[ ... \&] 4922is less than five: if leading 4923.Dq Li \&! 4924arguments can be stripped such that only one to three arguments remain, 4925then the lowered comparison is executed; (thanks to XSI) parentheses 4926.Ic \e( ... \e) 4927lower four- and three-argument forms to two- and one-argument forms, 4928respectively; three-argument forms ultimately prefer binary operations, 4929followed by negation and parenthesis lowering; two- and four-argument forms 4930prefer negation followed by parenthesis; the one-argument form always implies 4931.Fl n . 4932To assume this is not necessarily portable. 4933.Pp 4934.Sy Note : 4935A common mistake is to use 4936.Dq Li if \&[ $foo = bar \&] 4937which fails if parameter 4938.Dq foo 4939is empty or unset, if it has embedded spaces (i.e.\& 4940.Ev IFS 4941octets) or if it is a unary operator like 4942.Dq Li \&! 4943or 4944.Dq Li \-n . 4945Use tests like 4946.Dq Li if \&[ x\&"$foo\&" = x"bar" \&] 4947instead, or the double-bracket operator (see 4948.Ic \&[[ 4949above): 4950.Dq Li if \&[[ $foo = bar \&]] 4951or, to avoid pattern matching, 4952.Dq Li if \&[[ $foo = \&"$bar" \&]] ; 4953the 4954.Ic \&[[ ... \&]] 4955construct is not only more secure to use but also often faster. 4956.Pp 4957.It Xo 4958.Ic time 4959.Op Fl p 4960.Op Ar pipeline 4961.Xc 4962.Pq reserved word 4963If a 4964.Ar pipeline 4965is given, the times used to execute the pipeline are reported. 4966If no pipeline 4967is given, then the user and system time used by the shell itself, and all the 4968commands it has run since it was started, are reported. 4969.Pp 4970The times reported are the real time (elapsed time from start to finish), 4971the user CPU time (time spent running in user mode), and the system CPU time 4972(time spent running in kernel mode). 4973.Pp 4974Times are reported to standard error; the format of the output is: 4975.Pp 4976.Dl "0m0.03s real 0m0.02s user 0m0.01s system" 4977.Pp 4978If the 4979.Fl p 4980option is given (which is only permitted if 4981.Ar pipeline 4982is a simple command), the output is slightly longer: 4983.Bd -literal -offset indent 4984real 0.03 4985user 0.02 4986sys 0.01 4987.Ed 4988.Pp 4989Simple redirections of standard error do not affect 4990.Ic time Ns 's output : 4991.Pp 4992.Dl $ time sleep 1 2\*(Gtafile 4993.Dl $ { time sleep 1; } 2\*(Gtafile 4994.Pp 4995Times for the first command do not go to 4996.Dq afile , 4997but those of the second command do. 4998.Pp 4999.It Ic times 5000.Pq keeps assignments , special 5001Print the accumulated user and system times (see above) used both 5002by the shell and by processes that the shell started which have exited. 5003The format of the output is: 5004.Bd -literal -offset indent 50050m0.01s 0m0.00s 50060m0.04s 0m0.02s 5007.Ed 5008.Pp 5009.It Ic trap Ar n Op Ar signal ... 5010.Pq keeps assignments , special 5011If the first operand is a decimal unsigned integer, this resets all 5012specified signals to the default action, i.e. is the same as calling 5013.Ic trap 5014with a dash 5015.Pq Dq Li \- 5016as 5017.Ar handler , 5018followed by the arguments (interpreted as signals). 5019.Pp 5020.It Ic trap Op Ar handler signal ... 5021.Pq keeps assignments , special 5022Sets a trap handler that is to be executed when any of the specified 5023.Ar signal Ns s 5024are received. 5025.Ar handler 5026is either an empty string, indicating the signals are to be ignored, a dash 5027.Pq Dq Li \- , 5028indicating that the default action is to be taken for the signals 5029.Pq see Xr signal 3 , 5030or a string comprised of shell commands to be executed at the first opportunity 5031(i.e. when the current command completes or before printing the next 5032.Ev PS1 5033prompt) after receipt of one of the signals. 5034.Ar signal 5035is the name, possibly prefixed with 5036.Dq Li SIG , 5037of a signal 5038.Po 5039e.g.\& 5040.Dv PIPE , 5041.Dv ALRM 5042or 5043.Dv SIGINT 5044.Pc 5045or the number of the signal (see the 5046.Ic kill Fl l 5047command above). 5048.Pp 5049There are two special signals: 5050.Dv EXIT 5051.Pq also known as 0 , 5052which is executed when the shell is about to exit, and 5053.Dv ERR , 5054which is executed after an error occurs; an error is something 5055that would cause the shell to exit if the 5056.Ic set Fl e 5057or 5058.Ic set Fl o Ic errexit 5059option were set. 5060.Dv EXIT 5061handlers are executed in the environment of the last executed command. 5062The original Korn shell's 5063.Dv DEBUG 5064trap and handling of 5065.Dv ERR 5066and 5067.Dv EXIT 5068in functions are not yet implemented. 5069.Pp 5070Note that, for non-interactive shells, the trap handler cannot be changed 5071for signals that were ignored when the shell started. 5072.Pp 5073With no arguments, the current state of the traps that have been set since 5074the shell started is shown as a series of 5075.Ic trap 5076commands. 5077Note that the output of 5078.Ic trap 5079cannot be usefully captured or piped to another process (an artifact 5080of the fact that traps are cleared when subprocesses are created). 5081.Pp 5082.It Ic true 5083.Pq regular 5084A command that exits with a zero status. 5085.Pp 5086.It Ic type Ar name ... 5087.Pq built-in alias 5088Reveal how 5089.Ar name 5090would be interpreted as command. 5091.Pp 5092.It Xo 5093.Ic typeset 5094.Op Fl +aglpnrtUux 5095.Oo Fl L Ns Op Ar n 5096.No \*(Ba Fl R Ns Op Ar n 5097.No \*(Ba Fl Z Ns Op Ar n Oc 5098.Op Fl i Ns Op Ar n 5099.Oo Ar name 5100.Op Ns = Ns Ar value 5101.Ar ... Oc 5102.Xc 5103.It Xo 5104.Ic typeset 5105.Fl f Op Fl tux 5106.Op Ar name ... 5107.Xc 5108.Pq keeps assignments , decl-util 5109Display or set attributes of shell parameters or functions. 5110With no 5111.Ar name 5112arguments, parameter attributes are shown; 5113if no options are used, the current attributes of all parameters are printed as 5114.Ic typeset 5115commands; if an option is given (or 5116.Dq Li \- 5117with no option letter), all parameters and their values with the specified 5118attributes are printed; if options are introduced with 5119.Ql + 5120.Po 5121or 5122.Dq Li + 5123alone 5124.Pc , 5125only names are printed. 5126.Pp 5127If any 5128.Ar name 5129arguments are given, the attributes of the so named parameters are set 5130.Pq Ic \&\- 5131or cleared 5132.Pq Ic \&+ ; 5133inside a function, this will cause the parameters to be created (and set to 5134.Dq 5135if no value is given) in the local scope 5136.Pq except if Fl g No is used . 5137Values for parameters may optionally be specified. 5138For 5139.Ar name Ns \&[*] , 5140the change affects all elements of the array, and no value may be specified. 5141.Pp 5142When 5143.Fl f 5144is used, 5145.Ic typeset 5146operates on the attributes of functions. 5147As with parameters, if no 5148.Ar name 5149arguments are given, 5150functions are listed with their values (i.e. definitions) unless 5151options are introduced with 5152.Ql + , 5153in which case only the names are displayed. 5154.Bl -tag -width Ds 5155.It Fl a 5156Indexed array attribute. 5157.It Fl f 5158Function mode. 5159Display or set shell functions and their attributes, 5160instead of shell parameters. 5161.It Fl g 5162.Dq global 5163mode. 5164Do not cause named parameters to be created in 5165the local scope when called inside a function. 5166.It Fl i Ns Op Ar n 5167Integer attribute. 5168.Ar n 5169specifies the base to use when stringifying the integer 5170(if not specified, the base given in the first assignment is used). 5171Parameters with this attribute 5172may be assigned arithmetic expressions for values. 5173.It Fl L Ns Op Ar n 5174Left justify attribute. 5175.Ar n 5176specifies the field width. 5177If 5178.Ar n 5179is not specified, the current width of the parameter 5180(or the width of its first assigned value) is used. 5181Leading whitespace (and digit zeros, if used with the 5182.Fl Z 5183option) is stripped. 5184If necessary, values are either truncated 5185or padded with space to fit the field width. 5186.It Fl l 5187Lower case attribute. 5188All upper case ASCII characters in values are converted to lower case. 5189(In the original Korn shell, this parameter meant 5190.Dq long integer 5191when used with the 5192.Fl i 5193option.) 5194.It Fl n 5195Create a bound variable (name reference): any access to the variable 5196.Ar name 5197will access the variable 5198.Ar value 5199in the current scope (this is different from 5200.At 5201.Nm ksh93 ! ) 5202instead. 5203Also different from 5204.At 5205.Nm ksh93 5206is that 5207.Ar value 5208is lazily evaluated at the time 5209.Ar name 5210is accessed. 5211This can be used by functions to access variables whose names are 5212passed as parameters, instead of resorting to 5213.Ic eval . 5214.It Fl p 5215Print complete 5216.Ic typeset 5217commands that can be used to re-create the attributes and values of 5218parameters. 5219.It Fl R Ns Op Ar n 5220Right justify attribute. 5221.Ar n 5222specifies the field width. 5223If 5224.Ar n 5225is not specified, the current width of the parameter 5226(or the width of its first assigned value) is used. 5227Trailing whitespace is stripped. 5228If necessary, values are either stripped of leading characters 5229or padded with space to fit the field width. 5230.It Fl r 5231Read-only attribute. 5232Parameters with this attribute may not be assigned to or unset. 5233Once this attribute is set, it cannot be turned off. 5234.It Fl t 5235Tag attribute. 5236This attribute has no meaning to the shell for parameters 5237and is provided for application use. 5238.Pp 5239For functions, 5240.Fl t 5241is the trace attribute. 5242When functions with the trace attribute are executed, the 5243.Fl o Ic xtrace 5244.Pq Fl x 5245shell option is temporarily turned on. 5246.It Fl U 5247Unsigned integer attribute. 5248Integers are printed as unsigned values (combined with the 5249.Fl i 5250option). 5251.It Fl u 5252Upper case attribute. 5253All lower case ASCII characters in values are converted to upper case. 5254(In the original Korn shell, this parameter meant 5255.Dq unsigned integer 5256when used with the 5257.Fl i 5258option which meant upper case letters would never be used for bases greater 5259than 10. 5260See 5261.Fl U 5262above.) 5263.Pp 5264For functions, 5265.Fl u 5266is the undefined attribute, used with 5267.Ev FPATH . 5268See 5269.Sx Functions 5270above for the implications of this. 5271.It Fl x 5272Export attribute. 5273Parameters are placed in the environment of any executed commands. 5274Functions cannot be exported for security reasons 5275.Pq Dq shellshock . 5276.It Fl Z Ns Op Ar n 5277Zero fill attribute. 5278If not combined with 5279.Fl L , 5280this is the same as 5281.Fl R , 5282except zero padding is used instead of space padding. 5283For integers, the number is padded, not the base. 5284.El 5285.Pp 5286If any of the 5287.\" long integer , 5288.Fl i , 5289.Fl L , 5290.Fl l , 5291.Fl R , 5292.Fl U , 5293.Fl u 5294or 5295.Fl Z 5296options are changed, all others from this set are cleared, 5297unless they are also given on the same command line. 5298.Pp 5299.It Xo 5300.Ic ulimit 5301.Op Fl aBCcdefHilMmnOPpqrSsTtVvwx 5302.Op Ar value 5303.Xc 5304.Pq regular 5305Display or set process limits. 5306If no options are used, the file size limit 5307.Pq Fl f 5308is assumed. 5309.Ar value , 5310if specified, may be either an arithmetic expression or the word 5311.Dq Li unlimited . 5312The limits affect the shell and any processes created by the shell after a 5313limit is imposed. 5314Note that systems may not allow some limits to be increased 5315once they are set. 5316Also note that the types of limits available are system 5317dependent\*(EMsome systems have only the 5318.Fl f 5319limit, or not even that, or can set only the soft limits, etc. 5320.Bl -tag -width 5n 5321.It Fl a 5322Display all limits (soft limits unless 5323.Fl H 5324is used). 5325.It Fl B Ar n 5326Set the socket buffer size to 5327.Ar n 5328kibibytes. 5329.It Fl C Ar n 5330Set the number of cached threads to 5331.Ar n . 5332.It Fl c Ar n 5333Impose a size limit of 5334.Ar n 5335blocks on the size of core dumps. 5336Silently ignored if the system does not support this limit. 5337.It Fl d Ar n 5338Limit the size of the data area to 5339.Ar n 5340kibibytes. 5341.br 5342On some systems, read-only maximum 5343.Xr brk 2 5344size minus 5345.Li etext . 5346.It Fl e Ar n 5347Set the maximum niceness to 5348.Ar n . 5349.It Fl f Ar n 5350Impose a size limit of 5351.Ar n 5352blocks on files written by the shell and its child processes 5353.Pq any size may be read . 5354.It Fl H 5355Set the hard limit only (the default is to set both hard and soft limits). 5356With 5357.Fl a , 5358display all hard limits. 5359.It Fl i Ar n 5360Set the number of pending signals to 5361.Ar n . 5362.It Fl l Ar n 5363Impose a limit of 5364.Ar n 5365kibibytes on the amount of locked (wired) physical memory. 5366.It Fl M Ar n 5367Set the AIO locked memory to 5368.Ar n 5369kibibytes. 5370.It Fl m Ar n 5371Impose a limit of 5372.Ar n 5373kibibytes on the amount of physical memory used. 5374.It Fl n Ar n 5375Impose a limit of 5376.Ar n 5377file descriptors that can be open at once. 5378On some systems attempts to set are silently ignored. 5379.It Fl O Ar n 5380Set the number of AIO operations to 5381.Ar n . 5382.It Fl P Ar n 5383Limit the number of threads per process to 5384.Ar n . 5385.Pp 5386This option mostly matches 5387.At 5388.Nm ksh93 Ns 's 5389.Fl T ; 5390.br 5391on 5392.Tn AIX , 5393see 5394.Fl r 5395as used by its 5396.Nm ksh 5397though. 5398.It Fl p Ar n 5399Impose a limit of 5400.Ar n 5401processes that can be run by the user (uid) at any one time. 5402.It Fl q Ar n 5403Limit the size of 5404.Tn POSIX 5405message queues to 5406.Ar n 5407bytes. 5408.It Fl r Ar n 5409.Pq Cm AIX 5410Limit the number of threads per process to 5411.Ar n . 5412.br 5413.Pq Cm Linux 5414Set the maximum real-time priority to 5415.Ar n . 5416.It Fl S 5417Set the soft limit only (the default is to set both hard and soft limits). 5418With 5419.Fl a , 5420display soft limits (default). 5421.It Fl s Ar n 5422Limit the size of the stack area to 5423.Ar n 5424kibibytes. 5425.It Fl T Ar n 5426Impose a time limit of 5427.Ar n 5428real seconds 5429.Pq Dq humantime 5430to be used by each process. 5431.It Fl t Ar n 5432Impose a time limit of 5433.Ar n 5434CPU seconds spent in user mode to be used by each process. 5435.It Fl V Ar n 5436Set the number of vnode monitors on Haiku to 5437.Ar n . 5438.It Fl v Ar n 5439Impose a limit of 5440.Ar n 5441kibibytes on the amount of virtual memory (address space) used. 5442.It Fl w Ar n 5443Limit the amount of swap space used to at most 5444.Ar n 5445kibibytes. 5446.It Fl x Ar n 5447Set the maximum number of file locks to 5448.Ar n . 5449.El 5450.Pp 5451As far as 5452.Ic ulimit 5453is concerned, a block is 512 bytes. 5454.Pp 5455.It Xo 5456.Ic umask 5457.Op Fl S 5458.Op Ar mask 5459.Xc 5460.Pq regular 5461Display or set the file permission creation mask or umask (see 5462.Xr umask 2 ) . 5463If the 5464.Fl S 5465option is used, the mask displayed or set is symbolic; otherwise, it is an 5466octal number. 5467.Pp 5468Symbolic masks are like those used by 5469.Xr chmod 1 . 5470When used, they describe what permissions may be made available (as opposed to 5471octal masks in which a set bit means the corresponding bit is to be cleared). 5472For example, 5473.Dq Li ug=rwx,o= 5474sets the mask so files will not be readable, writable or executable by 5475.Dq others , 5476and is equivalent (on most systems) to the octal mask 5477.Dq Li 007 . 5478.Pp 5479.It Xo 5480.Ic unalias 5481.Op Fl adt 5482.Op Ar name ... 5483.Xc 5484.Pq regular 5485The aliases for the given names are removed. 5486If the 5487.Fl a 5488option is used, all aliases are removed. 5489If the 5490.Fl t 5491or 5492.Fl d 5493options are used, the indicated operations are carried out on tracked or 5494directory aliases, respectively. 5495.Pp 5496.It Xo 5497.Ic unset 5498.Op Fl fv 5499.Ar parameter ... 5500.Xc 5501.Pq keeps assignments , special 5502Unset the named parameters 5503.Pq Fl v , No the default 5504or functions 5505.Pq Fl f . 5506With 5507.Ar parameter Ns \&[*] , 5508attributes are retained, only values are unset. 5509The exit status is non-zero if any of the parameters are read-only, 5510zero otherwise (not portable). 5511.Pp 5512.It Ic wait Op Ar job ... 5513.Pq regular 5514Wait for the specified job(s) to finish. 5515The exit status of 5516.Ic wait 5517is that of the last specified job; if the last job is killed by a signal, the 5518exit status is 128 + the signal number (see 5519.Ic kill Fl l Ar exit-status 5520above); if the last specified job cannot be found (because it never existed 5521or had already finished), the exit status is 127. 5522See 5523.Sx Job control 5524below for the format of 5525.Ar job . 5526.Ic wait 5527will return if a signal for which a trap has been set is received or if a 5528.Dv SIGHUP , 5529.Dv SIGINT 5530or 5531.Dv SIGQUIT 5532signal is received. 5533.Pp 5534If no jobs are specified, 5535.Ic wait 5536waits for all currently running jobs (if any) to finish and exits with a zero 5537status. 5538If job monitoring is enabled, the completion status of jobs is printed 5539(this is not the case when jobs are explicitly specified). 5540.Pp 5541.It Xo 5542.Ic whence 5543.Op Fl pv 5544.Op Ar name ... 5545.Xc 5546.Pq regular 5547Without the 5548.Fl v 5549option, it is the same as 5550.Ic command Fl v , 5551except aliases are printed as their definition only. 5552With the 5553.Fl v 5554option, it is exactly identical to 5555.Ic command Fl V . 5556In either case, with the 5557.Fl p 5558option the search is restricted to the (current) 5559.Ev PATH . 5560.Pp 5561.It Xo Ic which 5562.Op Fl a 5563.Op Ar name ... 5564.Xc 5565.Pq Li dot.mkshrc No function 5566Without 5567.Fl a , 5568behaves like 5569.Ic whence Fl p 5570(does a 5571.Ev PATH 5572search for each 5573.Ar name 5574printing the resulting pathname if found); with 5575.Fl a , 5576matches in all 5577.Ev PATH 5578components are printed, i.e. the search is not stopped after a match. 5579If no 5580.Ar name 5581was matched, the exit status is 2; if every name was matched, it is zero, 5582otherwise it is 1. 5583No diagnostics are produced on failure to match. 5584.El 5585.Ss Job control 5586Job control refers to the shell's ability to monitor and control jobs which 5587are processes or groups of processes created for commands or pipelines. 5588At a minimum, the shell keeps track of the status of the background (i.e.\& 5589asynchronous) jobs that currently exist; this information can be displayed 5590using the 5591.Ic jobs 5592commands. 5593If job control is fully enabled (using 5594.Ic set Fl m 5595or 5596.Ic set Fl o Ic monitor ) , 5597as it is for interactive shells, the processes of a job are placed in their 5598own process group. 5599Foreground jobs can be stopped by typing the suspend character from 5600the terminal (normally \*(haZ); jobs can be restarted in either the 5601foreground or background using the commands 5602.Ic fg 5603and 5604.Ic bg . 5605.Pp 5606Note that only commands that create processes (e.g. asynchronous commands, 5607subshell commands and non-built-in, non-function commands) can be stopped; 5608commands like 5609.Ic read 5610cannot be. 5611.Pp 5612When a job is created, it is assigned a job number. 5613For interactive shells, this number is printed inside 5614.Dq Li \&[...] , 5615followed by the process IDs of the processes in the job when an asynchronous 5616command is run. 5617A job may be referred to in the 5618.Ic bg , 5619.Ic fg , 5620.Ic jobs , 5621.Ic kill 5622and 5623.Ic wait 5624commands either by the process ID of the last process in the command pipeline 5625(as stored in the 5626.Ic \&$! 5627parameter) or by prefixing the job number with a percent sign 5628.Pq Ql % . 5629Other percent sequences can also be used to refer to jobs: 5630.Bl -tag -width "%+ x %% x %XX" 5631.It %+ \*(Ba %% \*(Ba % 5632The most recently stopped job or, if there are no stopped jobs, the oldest 5633running job. 5634.It %\- 5635The job that would be the 5636.Ic %+ 5637job if the latter did not exist. 5638.It % Ns Ar n 5639The job with job number 5640.Ar n . 5641.It %? Ns Ar string 5642The job with its command containing the string 5643.Ar string 5644(an error occurs if multiple jobs are matched). 5645.It % Ns Ar string 5646The job with its command starting with the string 5647.Ar string 5648(an error occurs if multiple jobs are matched). 5649.El 5650.Pp 5651When a job changes state (e.g. a background job finishes or foreground job is 5652stopped), the shell prints the following status information: 5653.Pp 5654.D1 [ Ns Ar number ] Ar flag status command 5655.Pp 5656where... 5657.Bl -tag -width "command" 5658.It Ar number 5659is the job number of the job; 5660.It Ar flag 5661is the 5662.Ql + 5663or 5664.Ql \- 5665character if the job is the 5666.Ic %+ 5667or 5668.Ic %\- 5669job, respectively, or space if it is neither; 5670.It Ar status 5671indicates the current state of the job and can be: 5672.Bl -tag -width "RunningXX" 5673.It Done Op Ar number 5674The job exited. 5675.Ar number 5676is the exit status of the job which is omitted if the status is zero. 5677.It Running 5678The job has neither stopped nor exited (note that running does not 5679necessarily mean consuming CPU time\*(EMthe process could be blocked 5680waiting for some event). 5681.It Stopped Op Ar signal 5682The job was stopped by the indicated 5683.Ar signal 5684(if no signal is given, the job was stopped by 5685.Dv SIGTSTP ) . 5686.It Ar signal-description Op Dq core dumped 5687The job was killed by a signal (e.g. memory fault, hangup); use 5688.Ic kill Fl l 5689for a list of signal descriptions. 5690The 5691.Dq Li core dumped 5692message indicates the process created a core file. 5693.El 5694.It Ar command 5695is the command that created the process. 5696If there are multiple processes in 5697the job, each process will have a line showing its 5698.Ar command 5699and possibly its 5700.Ar status , 5701if it is different from the status of the previous process. 5702.El 5703.Pp 5704When an attempt is made to exit the shell while there are jobs in the stopped 5705state, the shell warns the user that there are stopped jobs and does not exit. 5706If another attempt is immediately made to exit the shell, the stopped jobs are 5707sent a 5708.Dv SIGHUP 5709signal and the shell exits. 5710Similarly, if the 5711.Ic nohup 5712option is not set and there are running jobs when an attempt is made to exit 5713a login shell, the shell warns the user and does not exit. 5714If another attempt 5715is immediately made to exit the shell, the running jobs are sent a 5716.Dv SIGHUP 5717signal and the shell exits. 5718.Ss Terminal state 5719The state of the controlling terminal can be modified by a command 5720executed in the foreground, whether or not job control is enabled, but 5721the modified terminal state is only kept past the job's lifetime and used 5722for later command invocations if the command exits successfully (i.e.\& 5723with an exit status of 0). 5724When such a job is momentarily stopped or restarted, the terminal state 5725is saved and restored, respectively, but it will not be kept afterwards. 5726In interactive mode, when line editing is enabled, the terminal state is 5727saved before being reconfigured by the shell for the line editor, then 5728restored before running a command. 5729.Ss POSIX mode 5730Entering 5731.Ic set Fl o Ic posix 5732mode will cause 5733.Nm 5734to behave even more 5735.Tn POSIX 5736compliant in places where the defaults or opinions differ. 5737Note that 5738.Nm mksh 5739will still operate with unsigned 32-bit arithmetic; use 5740.Nm lksh 5741if arithmetic on the host 5742.Vt long 5743data type, complete with ISO C Undefined Behaviour, is required; 5744refer to the 5745.Xr lksh 1 5746manual page for details. 5747Most other historic, 5748.At 5749.Nm ksh Ns -compatible 5750or opinionated differences can be disabled by using this mode; these are: 5751.Bl -bullet 5752.It 5753The incompatible GNU 5754.Nm bash 5755I/O redirection 5756.Ic &\*(Gt Ns Ar file 5757is not supported. 5758.It 5759File descriptors created by I/O redirections are inherited by 5760child processes. 5761.It 5762Numbers with a leading digit zero are interpreted as octal. 5763.It 5764The 5765.Nm echo 5766builtin does not interpret backslashes and only supports the exact option 5767.Fl n . 5768.It 5769Alias expansion with a trailing space only reruns on command words. 5770.It 5771Tilde expansion follows POSIX instead of Korn shell rules. 5772.It 5773The exit status of 5774.Ic fg 5775is always 0. 5776.It 5777.Ic kill 5778.Fl l 5779only lists signal names, all in one line. 5780.It 5781.Ic getopts 5782does not accept options with a leading 5783.Ql + . 5784.It 5785.Ic exec 5786skips builtins, functions and other commands and uses a 5787.Ev PATH 5788search to determine the utility to execute. 5789.El 5790.Ss SH mode 5791Compatibility mode; intended for use with legacy scripts that 5792cannot easily be fixed; the changes are as follows: 5793.Bl -bullet 5794.It 5795The incompatible GNU 5796.Nm bash 5797I/O redirection 5798.Ic &\*(Gt Ns Ar file 5799is not supported. 5800.It 5801File descriptors created by I/O redirections are inherited by 5802child processes. 5803.It 5804The 5805.Nm echo 5806builtin does not interpret backslashes and only supports the exact option 5807.Fl n , 5808unless built with 5809.Ev \-DMKSH_MIDNIGHTBSD01ASH_COMPAT . 5810.It 5811The substitution operations 5812.Sm off 5813.Xo 5814.Pf ${ Ar x 5815.Pf # Ar pat No } , 5816.Sm on 5817.Xc 5818.Sm off 5819.Xo 5820.Pf ${ Ar x 5821.Pf ## Ar pat No } , 5822.Sm on 5823.Xc 5824.Sm off 5825.Xo 5826.Pf ${ Ar x 5827.Pf % Ar pat No } , 5828.Sm on 5829.Xc 5830and 5831.Sm off 5832.Xo 5833.Pf ${ Ar x 5834.Pf %% Ar pat No } 5835.Sm on 5836.Xc 5837wrongly do not require a parenthesis to be escaped and do not parse extglobs. 5838.It 5839The getopt construct from 5840.Xr lksh 1 5841passes through the errorlevel. 5842.It 5843.Nm sh 5844.Fl c 5845eats a leading 5846.Fl \- 5847if built with 5848.Ev \-DMKSH_MIDNIGHTBSD01ASH_COMPAT . 5849.El 5850.Ss Interactive input line editing 5851The shell supports three modes of reading command lines from a 5852.Xr tty 4 5853in an interactive session, controlled by the 5854.Ic emacs , 5855.Ic gmacs 5856and 5857.Ic vi 5858options (at most one of these can be set at once). 5859The default is 5860.Ic emacs . 5861Editing modes can be set explicitly using the 5862.Ic set 5863built-in. 5864If none of these options are enabled, 5865the shell simply reads lines using the normal 5866.Xr tty 4 5867driver. 5868If the 5869.Ic emacs 5870or 5871.Ic gmacs 5872option is set, the shell allows emacs-like editing of the command; similarly, 5873if the 5874.Ic vi 5875option is set, the shell allows vi-like editing of the command. 5876These modes are described in detail in the following sections. 5877.Pp 5878In these editing modes, if a line is longer than the screen width (see the 5879.Ev COLUMNS 5880parameter), 5881a 5882.Ql \*(Gt , 5883.Ql + 5884or 5885.Ql \*(Lt 5886character is displayed in the last column indicating that there are more 5887characters after, before and after, or before the current position, 5888respectively. 5889The line is scrolled horizontally as necessary. 5890.Pp 5891Completed lines are pushed into the history, unless they begin with an 5892IFS octet or IFS white space or are the same as the previous line. 5893.Ss Emacs editing mode 5894When the 5895.Ic emacs 5896option is set, interactive input line editing is enabled. 5897Warning: This mode is 5898slightly different from the emacs mode in the original Korn shell. 5899In this mode, various editing commands 5900(typically bound to one or more control characters) cause immediate actions 5901without waiting for a newline. 5902Several editing commands are bound to particular 5903control characters when the shell is invoked; these bindings can be changed 5904using the 5905.Ic bind 5906command. 5907.Pp 5908The following is a list of available editing commands. 5909Each description starts with the name of the command, 5910suffixed with a colon; 5911an 5912.Op Ar n 5913(if the command can be prefixed with a count); and any keys the command is 5914bound to by default, written using caret notation 5915e.g. the ASCII Esc character is written as \*(ha[. 5916These control sequences are not case sensitive. 5917A count prefix for a command is entered using the sequence 5918.Pf \*(ha[ Ns Ar n , 5919where 5920.Ar n 5921is a sequence of 1 or more digits. 5922Unless otherwise specified, if a count is 5923omitted, it defaults to 1. 5924.Pp 5925Note that editing command names are used only with the 5926.Ic bind 5927command. 5928Furthermore, many editing commands are useful only on terminals with 5929a visible cursor. 5930The user's 5931.Xr tty 4 5932characters (e.g.\& 5933.Dv ERASE ) 5934are bound to 5935reasonable substitutes and override the default bindings; 5936their customary values are shown in parentheses below. 5937The default bindings were chosen to resemble corresponding 5938Emacs key bindings: 5939.Bl -tag -width Ds 5940.It Xo abort: 5941.No INTR Pq \*(haC , 5942.No \*(haG 5943.Xc 5944Abort the current command, save it to the history, empty the line buffer and 5945set the exit state to interrupted. 5946.It auto\-insert: Op Ar n 5947Simply causes the character to appear as literal input. 5948Most ordinary characters are bound to this. 5949.It Xo backward\-char: 5950.Op Ar n 5951.No \*(haB , \*(haXD , ANSI-CurLeft , PC-CurLeft 5952.Xc 5953Moves the cursor backward 5954.Ar n 5955characters. 5956.It Xo backward\-word: 5957.Op Ar n 5958.No \*(ha[b , ANSI-Ctrl-CurLeft , ANSI-Alt-CurLeft 5959.Xc 5960Moves the cursor backward to the beginning of the word; words consist of 5961alphanumerics, underscore 5962.Pq Ql _ 5963and dollar sign 5964.Pq Ql $ 5965characters. 5966.It beginning\-of\-history: \*(ha[\*(Lt 5967Moves to the beginning of the history. 5968.It beginning\-of\-line: \*(haA, ANSI-Home, PC-Home 5969Moves the cursor to the beginning of the edited input line. 5970.It Xo capitalise\-word: 5971.Op Ar n 5972.No \*(ha[C , \*(ha[c 5973.Xc 5974Uppercase the first ASCII character in the next 5975.Ar n 5976words, leaving the cursor past the end of the last word. 5977.It clear\-screen: \*(ha[\*(haL 5978Prints a compile-time configurable sequence to clear the screen and home 5979the cursor, redraws the last line of the prompt string and the currently 5980edited input line. 5981The default sequence works for almost all standard terminals. 5982.It comment: \*(ha[# 5983If the current line does not begin with a comment character, one is added at 5984the beginning of the line and the line is entered (as if return had been 5985pressed); otherwise, the existing comment characters are removed and the cursor 5986is placed at the beginning of the line. 5987.It complete: \*(ha[\*(ha[ 5988Automatically completes as much as is unique of the command name or the file 5989name containing the cursor. 5990If the entire remaining command or file name is 5991unique, a space is printed after its completion, unless it is a directory name 5992in which case 5993.Ql / 5994is appended. 5995If there is no command or file name with the current partial word 5996as its prefix, a bell character is output (usually causing a beep to be 5997sounded). 5998.It complete\-command: \*(haX\*(ha[ 5999Automatically completes as much as is unique of the command name having the 6000partial word up to the cursor as its prefix, as in the 6001.Ic complete 6002command above. 6003.It complete\-file: \*(ha[\*(haX 6004Automatically completes as much as is unique of the file name having the 6005partial word up to the cursor as its prefix, as in the 6006.Ic complete 6007command described above. 6008.It complete\-list: \*(haI, \*(ha[= 6009Complete as much as is possible of the current word 6010and list the possible completions for it. 6011If only one completion is possible, 6012match as in the 6013.Ic complete 6014command above. 6015Note that \*(haI is usually generated by the Tab (tabulator) key. 6016.It Xo delete\-char\-backward: 6017.Op Ar n 6018.No ERASE Pq \*(haH , 6019.No \*(ha? , \*(haH 6020.Xc 6021Deletes 6022.Ar n 6023characters before the cursor. 6024.It Xo delete\-char\-forward: 6025.Op Ar n 6026.No ANSI-Del , PC-Del 6027.Xc 6028Deletes 6029.Ar n 6030characters after the cursor. 6031.It Xo delete\-word\-backward: 6032.Op Ar n 6033.No Pfx1+ERASE Pq \*(ha[\*(haH , 6034.No WERASE Pq \*(haW , 6035.No \*(ha[\*(ha? , \*(ha[\*(haH , \*(ha[h 6036.Xc 6037Deletes 6038.Ar n 6039words before the cursor. 6040.It Xo delete\-word\-forward: 6041.Op Ar n 6042.No \*(ha[d 6043.Xc 6044Deletes characters after the cursor up to the end of 6045.Ar n 6046words. 6047.It Xo down\-history: 6048.Op Ar n 6049.No \*(haN , \*(haXB , ANSI-CurDown , PC-CurDown 6050.Xc 6051Scrolls the history buffer forward 6052.Ar n 6053lines (later). 6054Each input line originally starts just after the last entry 6055in the history buffer, so 6056.Ic down\-history 6057is not useful until either 6058.Ic search\-history , 6059.Ic search\-history\-up 6060or 6061.Ic up\-history 6062has been performed. 6063.It Xo downcase\-word: 6064.Op Ar n 6065.No \*(ha[L , \*(ha[l 6066.Xc 6067Lowercases the next 6068.Ar n 6069words. 6070.It Xo edit\-line: 6071.Op Ar n 6072.No \*(haXe 6073.Xc 6074Internally run the command 6075.Ic fc \-e \&"${VISUAL:\-${EDITOR:\-vi}}" Fl \- Ar n 6076.br 6077on a temporary script file to interactively edit line 6078.Ar n 6079(if 6080.Ar n 6081is not specified, the current line); then, unless the editor invoked 6082exits nonzero but even if the script was not changed, execute the 6083resulting script as if typed on the command line; both the edited 6084.Pq resulting 6085and original lines are added onto history. 6086.It end\-of\-history: \*(ha[\*(Gt 6087Moves to the end of the history. 6088.It end\-of\-line: \*(haE, ANSI-End, PC-End 6089Moves the cursor to the end of the input line. 6090.It eot: \*(ha_ 6091Acts as an end-of-file; this is useful because edit-mode input disables 6092normal terminal input canonicalisation. 6093.It Xo eot\-or\-delete: 6094.Op Ar n 6095.No EOF Pq \*(haD 6096.Xc 6097If alone on a line, same as 6098.Ic eot , 6099otherwise, 6100.Ic delete\-char\-forward . 6101.It error: (not bound) 6102Error (ring the bell). 6103.It evaluate\-region: \*(ha[\*(haE 6104Evaluates the text between the mark and the cursor position 6105.Pq the entire line if no mark is set 6106as function substitution (if it cannot be parsed, the editing state is 6107unchanged and the bell is rung to signal an error); $? is updated accordingly. 6108.It exchange\-point\-and\-mark: \*(haX\*(haX 6109Places the cursor where the mark is and sets the mark to where the cursor was. 6110.It expand\-file: \*(ha[* 6111Appends a 6112.Ql * 6113to the current word and replaces the word with the result of performing file 6114globbing on the word. 6115If no files match the pattern, the bell is rung. 6116.It Xo forward\-char: 6117.Op Ar n 6118.No \*(haF , \*(haXC , ANSI-CurRight , PC-CurRight 6119.Xc 6120Moves the cursor forward 6121.Ar n 6122characters. 6123.It Xo forward\-word: 6124.Op Ar n 6125.No \*(ha[f , ANSI-Ctrl-CurRight , ANSI-Alt-CurRight 6126.Xc 6127Moves the cursor forward to the end of the 6128.Ar n Ns th 6129word. 6130.It Xo goto\-history: 6131.Op Ar n 6132.No \*(ha[g 6133.Xc 6134Goes to history number 6135.Ar n . 6136.It Xo kill\-line: 6137.No KILL Pq \*(haU 6138.Xc 6139Deletes the entire input line. 6140.It kill\-region: \*(haW 6141Deletes the input between the cursor and the mark. 6142.It Xo kill\-to\-eol: 6143.Op Ar n 6144.No \*(haK 6145.Xc 6146Deletes the input from the cursor to the end of the line if 6147.Ar n 6148is not specified; otherwise deletes characters between the cursor and column 6149.Ar n . 6150.It list: \*(ha[? 6151Prints a sorted, columnated list of command names or file names (if any) that 6152can complete the partial word containing the cursor. 6153Directory names have 6154.Ql / 6155appended to them. 6156.It list\-command: \*(haX? 6157Prints a sorted, columnated list of command names (if any) that can complete 6158the partial word containing the cursor. 6159.It list\-file: \*(haX\*(haY 6160Prints a sorted, columnated list of file names (if any) that can complete the 6161partial word containing the cursor. 6162File type indicators are appended as described under 6163.Ic list 6164above. 6165.It newline: \*(haJ , \*(haM 6166Causes the current input line to be processed by the shell. 6167The current cursor position may be anywhere on the line. 6168.It newline\-and\-next: \*(haO 6169Causes the current input line to be processed by the shell, and the next line 6170from history becomes the current line. 6171This is only useful after an 6172.Ic up\-history , 6173.Ic search\-history 6174or 6175.Ic search\-history\-up . 6176.It Xo no\-op: 6177.No QUIT Pq \*(ha\e 6178.Xc 6179This does nothing. 6180.It prefix\-1: \*(ha[ 6181Introduces a 2-character command sequence. 6182.It prefix\-2: \*(haX , \*(ha[[ , \*(ha[O 6183Introduces a multi-character command sequence. 6184.It Xo prev\-hist\-word: 6185.Op Ar n 6186.No \*(ha[. , \*(ha[_ 6187.Xc 6188The last word or, if given, the 6189.Ar n Ns th 6190word (zero-based) of the previous (on repeated execution, second-last, 6191third-last, etc.) command is inserted at the cursor. 6192Use of this editing command trashes the mark. 6193.It quote: \*(ha\*(ha , \*(haV 6194The following character is taken literally rather than as an editing command. 6195.It quote\-region: \*(ha[Q 6196Escapes the text between the mark and the cursor position 6197.Pq the entire line if no mark is set 6198into a shell command argument. 6199.It redraw: \*(haL 6200Reprints the last line of the prompt string and the current input line 6201on a new line. 6202.It Xo search\-character\-backward: 6203.Op Ar n 6204.No \*(ha[\*(ha] 6205.Xc 6206Search backward in the current line for the 6207.Ar n Ns th 6208occurrence of the next character typed. 6209.It Xo search\-character\-forward: 6210.Op Ar n 6211.No \*(ha] 6212.Xc 6213Search forward in the current line for the 6214.Ar n Ns th 6215occurrence of the next character typed. 6216.It search\-history: \*(haR 6217Enter incremental search mode. 6218The internal history list is searched 6219backwards for commands matching the input. 6220An initial 6221.Ql \*(ha 6222in the search string anchors the search. 6223The escape key will leave search mode. 6224Other commands, including sequences of escape as 6225.Ic prefix\-1 6226followed by a 6227.Ic prefix\-1 6228or 6229.Ic prefix\-2 6230key will be executed after leaving search mode. 6231The 6232.Ic abort Pq \*(haG 6233command will restore the input line before search started. 6234Successive 6235.Ic search\-history 6236commands continue searching backward to the next previous occurrence of the 6237pattern. 6238The history buffer retains only a finite number of lines; the oldest 6239are discarded as necessary. 6240.It search\-history\-up: ANSI-PgUp, PC-PgUp 6241Search backwards through the history buffer for commands whose beginning match 6242the portion of the input line before the cursor. 6243When used on an empty line, this has the same effect as 6244.Ic up\-history . 6245.It search\-history\-down: ANSI-PgDn, PC-PgDn 6246Search forwards through the history buffer for commands whose beginning match 6247the portion of the input line before the cursor. 6248When used on an empty line, this has the same effect as 6249.Ic down\-history . 6250This is only useful after an 6251.Ic up\-history , 6252.Ic search\-history 6253or 6254.Ic search\-history\-up . 6255.It set\-mark\-command: \*(ha[ Ns Aq space 6256Set the mark at the cursor position. 6257.It transpose\-chars: \*(haT 6258If at the end of line or, if the 6259.Ic gmacs 6260option is set, this exchanges the two previous characters; otherwise, it 6261exchanges the previous and current characters and moves the cursor one 6262character to the right. 6263.It Xo up\-history: 6264.Op Ar n 6265.No \*(haP , \*(haXA , ANSI-CurUp , PC-CurUp 6266.Xc 6267Scrolls the history buffer backward 6268.Ar n 6269lines (earlier). 6270.It Xo upcase\-word: 6271.Op Ar n 6272.No \*(ha[U , \*(ha[u 6273.Xc 6274Uppercase the next 6275.Ar n 6276words. 6277.It version: \*(ha[\*(haV 6278Display the version of 6279.Nm mksh . 6280The current edit buffer is restored as soon as a key is pressed. 6281The restoring keypress is processed, unless it is a space. 6282.It yank: \*(haY 6283Inserts the most recently killed text string at the current cursor position. 6284.It yank\-pop: \*(ha[y 6285Immediately after a 6286.Ic yank , 6287replaces the inserted text string with the next previously killed text string. 6288.El 6289.Pp 6290The tab completion escapes characters the same way as the following code: 6291.Bd -literal 6292print \-nr \-\- "${x@/[\e"\-\e$\e&\-*:\-?[\e\e\e`\e{\-\e}${IFS\-$\*(aq \et\en\*(aq}]/\e\e$KSH_MATCH}" 6293.Ed 6294.Ss Vi editing mode 6295.Em Note: 6296The vi command-line editing mode has not yet been brought up to the 6297same quality and feature set as the emacs mode. 6298It is 8-bit clean but specifically does not support UTF-8 or MBCS. 6299.Pp 6300The vi command-line editor in 6301.Nm 6302has basically the same commands as the 6303.Xr vi 1 6304editor with the following exceptions: 6305.Bl -bullet 6306.It 6307You start out in insert mode. 6308.It 6309There are file name and command completion commands: 6310=, \e, *, \*(haX, \*(haE, \*(haF and, optionally, 6311.Aq Tab 6312and 6313.Aq Esc . 6314.It 6315The 6316.Ic _ 6317command is different (in 6318.Nm mksh , 6319it is the last argument command; in 6320.Xr vi 1 6321it goes to the start of the current line). 6322.It 6323The 6324.Ic / 6325and 6326.Ic G 6327commands move in the opposite direction to the 6328.Ic j 6329command. 6330.It 6331Commands which don't make sense in a single line editor are not available 6332(e.g. screen movement commands and 6333.Xr ex 1 Ns -style 6334colon 6335.Pq Ic \&: 6336commands). 6337.El 6338.Pp 6339Like 6340.Xr vi 1 , 6341there are two modes: 6342.Dq insert 6343mode and 6344.Dq command 6345mode. 6346In insert mode, most characters are simply put in the buffer at the 6347current cursor position as they are typed; however, some characters are 6348treated specially. 6349In particular, the following characters are taken from current 6350.Xr tty 4 6351settings 6352(see 6353.Xr stty 1 ) 6354and have their usual meaning (normal values are in parentheses): kill (\*(haU), 6355erase (\*(ha?), werase (\*(haW), eof (\*(haD), intr (\*(haC) and quit (\*(ha\e). 6356In addition to 6357the above, the following characters are also treated specially in insert mode: 6358.Bl -tag -width XJXXXXM 6359.It \*(haE 6360Command and file name enumeration (see below). 6361.It \*(haF 6362Command and file name completion (see below). 6363If used twice in a row, the 6364list of possible completions is displayed; if used a third time, the completion 6365is undone. 6366.It \*(haH 6367Erases previous character. 6368.It \*(haJ \*(Ba \*(haM 6369End of line. 6370The current line is read, parsed and executed by the shell. 6371.It \*(haV 6372Literal next. 6373The next character typed is not treated specially (can be used 6374to insert the characters being described here). 6375.It \*(haX 6376Command and file name expansion (see below). 6377.It Aq Esc 6378Puts the editor in command mode (see below). 6379.It Aq Tab 6380Optional file name and command completion (see 6381.Ic \*(haF 6382above), enabled with 6383.Ic set Fl o Ic vi\-tabcomplete . 6384.El 6385.Pp 6386In command mode, each character is interpreted as a command. 6387Characters that 6388don't correspond to commands, are illegal combinations of commands, or are 6389commands that can't be carried out, all cause beeps. 6390In the following command descriptions, an 6391.Op Ar n 6392indicates the command may be prefixed by a number (e.g.\& 6393.Ic 10l 6394moves right 10 characters); if no number prefix is used, 6395.Ar n 6396is assumed to be 1 unless otherwise specified. 6397The term 6398.Dq current position 6399refers to the position between the cursor and the character preceding the 6400cursor. 6401A 6402.Dq word 6403is a sequence of letters, digits and underscore characters or a sequence of 6404non-letter, non-digit, non-underscore and non-whitespace characters (e.g.\& 6405.Dq Li ab2*&\*(ha 6406contains two words) and a 6407.Dq big-word 6408is a sequence of non-whitespace characters. 6409.Pp 6410Special 6411.Nm 6412vi commands: 6413.Pp 6414The following commands are not in, or are different from, the normal vi file 6415editor: 6416.Bl -tag -width 10n 6417.It Xo 6418.Oo Ar n Oc Ns _ 6419.Xc 6420Insert a space followed by the 6421.Ar n Ns th 6422big-word from the last command in the history at the current position and enter 6423insert mode; if 6424.Ar n 6425is not specified, the last word is inserted. 6426.It # 6427Insert the comment character 6428.Pq Ql # 6429at the start of the current line and return the line to the shell (equivalent 6430to 6431.Ic I#\*(haJ ) . 6432.It Xo 6433.Oo Ar n Oc Ns g 6434.Xc 6435Like 6436.Ic G , 6437except if 6438.Ar n 6439is not specified, it goes to the most recent remembered line. 6440.It Xo 6441.Oo Ar n Oc Ns v 6442.Xc 6443Internally run the command 6444.Ic fc \-e \&"${VISUAL:\-${EDITOR:\-vi}}" Fl \- Ar n 6445.br 6446on a temporary script file to interactively edit line 6447.Ar n 6448(if 6449.Ar n 6450is not specified, the current line); then, unless the editor invoked 6451exits nonzero but even if the script was not changed, execute the 6452resulting script as if typed on the command line; both the edited 6453.Pq resulting 6454and original lines are added onto history. 6455.It * and \*(haX 6456Command or file name expansion is applied to the current big-word (with an 6457appended 6458.Ql * 6459if the word contains no file globbing characters)\*(EMthe big-word is replaced 6460with the resulting words. 6461If the current big-word is the first on the line 6462or follows one of the characters 6463.Ql \&; , 6464.Ql \*(Ba , 6465.Ql & , 6466.Ql \&( 6467or 6468.Ql \&) 6469and does not contain a slash 6470.Pq Ql / , 6471then command expansion is done; otherwise file name expansion is done. 6472Command expansion will match the big-word against all aliases, functions and 6473built-in commands as well as any executable files found by searching the 6474directories in the 6475.Ev PATH 6476parameter. 6477File name expansion matches the big-word against the files in the 6478current directory. 6479After expansion, the cursor is placed just past the last 6480word and the editor is in insert mode. 6481.It Xo 6482.Oo Ar n Oc Ns \e , 6483.Oo Ar n Oc Ns \*(haF , 6484.Oo Ar n Oc Ns Aq Tab , 6485.No and 6486.Oo Ar n Oc Ns Aq Esc 6487.Xc 6488Command/file name completion. 6489Replace the current big-word with the 6490longest unique match obtained after performing command and file name expansion. 6491.Aq Tab 6492is only recognised if the 6493.Ic vi\-tabcomplete 6494option is set, while 6495.Aq Esc 6496is only recognised if the 6497.Ic vi\-esccomplete 6498option is set (see 6499.Ic set Fl o ) . 6500If 6501.Ar n 6502is specified, the 6503.Ar n Ns th 6504possible completion is selected (as reported by the command/file name 6505enumeration command). 6506.It = and \*(haE 6507Command/file name enumeration. 6508List all the commands or files that match the current big-word. 6509.It \*(haV 6510Display the version of 6511.Nm mksh . 6512The current edit buffer is restored as soon as a key is pressed. 6513The restoring keypress is ignored. 6514.It @ Ns Ar c 6515Macro expansion. 6516Execute the commands found in the alias 6517.Li _ Ns Ar c . 6518.El 6519.Pp 6520Intra-line movement commands: 6521.Bl -tag -width Ds 6522.It Xo 6523.Oo Ar n Oc Ns h and 6524.Oo Ar n Oc Ns \*(haH 6525.Xc 6526Move left 6527.Ar n 6528characters. 6529.It Xo 6530.Oo Ar n Oc Ns l and 6531.Oo Ar n Oc Ns Aq space 6532.Xc 6533Move right 6534.Ar n 6535characters. 6536.It 0 6537Move to column 0. 6538.It \*(ha 6539Move to the first non-whitespace character. 6540.It Xo 6541.Oo Ar n Oc Ns \*(Ba 6542.Xc 6543Move to column 6544.Ar n . 6545.It $ 6546Move to the last character. 6547.It Xo 6548.Oo Ar n Oc Ns b 6549.Xc 6550Move back 6551.Ar n 6552words. 6553.It Xo 6554.Oo Ar n Oc Ns B 6555.Xc 6556Move back 6557.Ar n 6558big-words. 6559.It Xo 6560.Oo Ar n Oc Ns e 6561.Xc 6562Move forward to the end of the word, 6563.Ar n 6564times. 6565.It Xo 6566.Oo Ar n Oc Ns E 6567.Xc 6568Move forward to the end of the big-word, 6569.Ar n 6570times. 6571.It Xo 6572.Oo Ar n Oc Ns w 6573.Xc 6574Move forward 6575.Ar n 6576words. 6577.It Xo 6578.Oo Ar n Oc Ns W 6579.Xc 6580Move forward 6581.Ar n 6582big-words. 6583.It % 6584Find match. 6585The editor looks forward for the nearest parenthesis, bracket or 6586brace and then moves the cursor to the matching parenthesis, bracket or brace. 6587.It Xo 6588.Oo Ar n Oc Ns f Ns Ar c 6589.Xc 6590Move forward to the 6591.Ar n Ns th 6592occurrence of the character 6593.Ar c . 6594.It Xo 6595.Oo Ar n Oc Ns F Ns Ar c 6596.Xc 6597Move backward to the 6598.Ar n Ns th 6599occurrence of the character 6600.Ar c . 6601.It Xo 6602.Oo Ar n Oc Ns t Ns Ar c 6603.Xc 6604Move forward to just before the 6605.Ar n Ns th 6606occurrence of the character 6607.Ar c . 6608.It Xo 6609.Oo Ar n Oc Ns T Ns Ar c 6610.Xc 6611Move backward to just before the 6612.Ar n Ns th 6613occurrence of the character 6614.Ar c . 6615.It Xo 6616.Oo Ar n Oc Ns \&; 6617.Xc 6618Repeats the last 6619.Ic f , F , t 6620or 6621.Ic T 6622command. 6623.It Xo 6624.Oo Ar n Oc Ns \&, 6625.Xc 6626Repeats the last 6627.Ic f , F , t 6628or 6629.Ic T 6630command, but moves in the opposite direction. 6631.El 6632.Pp 6633Inter-line movement commands: 6634.Bl -tag -width Ds 6635.It Xo 6636.Oo Ar n Oc Ns j , 6637.Oo Ar n Oc Ns + , 6638.No and 6639.Oo Ar n Oc Ns \*(haN 6640.Xc 6641Move to the 6642.Ar n Ns th 6643next line in the history. 6644.It Xo 6645.Oo Ar n Oc Ns k , 6646.Oo Ar n Oc Ns \- , 6647.No and 6648.Oo Ar n Oc Ns \*(haP 6649.Xc 6650Move to the 6651.Ar n Ns th 6652previous line in the history. 6653.It Xo 6654.Oo Ar n Oc Ns G 6655.Xc 6656Move to line 6657.Ar n 6658in the history; if 6659.Ar n 6660is not specified, the number of the first remembered line is used. 6661.It Xo 6662.Oo Ar n Oc Ns g 6663.Xc 6664Like 6665.Ic G , 6666except if 6667.Ar n 6668is not specified, it goes to the most recent remembered line. 6669.It Xo 6670.Oo Ar n Oc Ns / Ns Ar string 6671.Xc 6672Search backward through the history for the 6673.Ar n Ns th 6674line containing 6675.Ar string ; 6676if 6677.Ar string 6678starts with 6679.Ql \*(ha , 6680the remainder of the string must appear at the start of the history line for 6681it to match. 6682.It Xo 6683.Oo Ar n Oc Ns \&? Ns Ar string 6684.Xc 6685Same as 6686.Ic / , 6687except it searches forward through the history. 6688.It Xo 6689.Oo Ar n Oc Ns n 6690.Xc 6691Search for the 6692.Ar n Ns th 6693occurrence of the last search string; 6694the direction of the search is the same as the last search. 6695.It Xo 6696.Oo Ar n Oc Ns N 6697.Xc 6698Search for the 6699.Ar n Ns th 6700occurrence of the last search string; 6701the direction of the search is the opposite of the last search. 6702.It Ar ANSI-CurUp , PC-PgUp 6703Take the characters from the beginning of the line to the current 6704cursor position as search string and do a history search, backwards, 6705for lines beginning with this string; keep the cursor position. 6706This works only in insert mode and keeps it enabled. 6707.It Ar ANSI-CurDown , PC-PgDn 6708Take the characters from the beginning of the line to the current 6709cursor position as search string and do a history search, forwards, 6710for lines beginning with this string; keep the cursor position. 6711This works only in insert mode and keeps it enabled. 6712.El 6713.Pp 6714Edit commands 6715.Bl -tag -width Ds 6716.It Xo 6717.Oo Ar n Oc Ns a 6718.Xc 6719Append text 6720.Ar n 6721times; goes into insert mode just after the current position. 6722The append is 6723only replicated if command mode is re-entered i.e.\& 6724.Aq Esc 6725is used. 6726.It Xo 6727.Oo Ar n Oc Ns A 6728.Xc 6729Same as 6730.Ic a , 6731except it appends at the end of the line. 6732.It Xo 6733.Oo Ar n Oc Ns i 6734.Xc 6735Insert text 6736.Ar n 6737times; goes into insert mode at the current position. 6738The insertion is only 6739replicated if command mode is re-entered i.e.\& 6740.Aq Esc 6741is used. 6742.It Xo 6743.Oo Ar n Oc Ns I 6744.Xc 6745Same as 6746.Ic i , 6747except the insertion is done just before the first non-blank character. 6748.It Xo 6749.Oo Ar n Oc Ns s 6750.Xc 6751Substitute the next 6752.Ar n 6753characters (i.e. delete the characters and go into insert mode). 6754.It S 6755Substitute whole line. 6756All characters from the first non-blank character to the 6757end of the line are deleted and insert mode is entered. 6758.It Xo 6759.Oo Ar n Oc Ns c Ns Ar move-cmd 6760.Xc 6761Change from the current position to the position resulting from 6762.Ar n move-cmd Ns s 6763(i.e. delete the indicated region and go into insert mode); if 6764.Ar move-cmd 6765is 6766.Ic c , 6767the line starting from the first non-blank character is changed. 6768.It C 6769Change from the current position to the end of the line (i.e. delete to the 6770end of the line and go into insert mode). 6771.It Xo 6772.Oo Ar n Oc Ns x 6773.Xc 6774Delete the next 6775.Ar n 6776characters. 6777.It Xo 6778.Oo Ar n Oc Ns X 6779.Xc 6780Delete the previous 6781.Ar n 6782characters. 6783.It D 6784Delete to the end of the line. 6785.It Xo 6786.Oo Ar n Oc Ns d Ns Ar move-cmd 6787.Xc 6788Delete from the current position to the position resulting from 6789.Ar n move-cmd Ns s ; 6790.Ar move-cmd 6791is a movement command (see above) or 6792.Ic d , 6793in which case the current line is deleted. 6794.It Xo 6795.Oo Ar n Oc Ns r Ns Ar c 6796.Xc 6797Replace the next 6798.Ar n 6799characters with the character 6800.Ar c . 6801.It Xo 6802.Oo Ar n Oc Ns R 6803.Xc 6804Replace. 6805Enter insert mode but overwrite existing characters instead of 6806inserting before existing characters. 6807The replacement is repeated 6808.Ar n 6809times. 6810.It Xo 6811.Oo Ar n Oc Ns \*(TI 6812.Xc 6813Change the case of the next 6814.Ar n 6815characters. 6816.It Xo 6817.Oo Ar n Oc Ns y Ns Ar move-cmd 6818.Xc 6819Yank from the current position to the position resulting from 6820.Ar n move-cmd Ns s 6821into the yank buffer; if 6822.Ar move-cmd 6823is 6824.Ic y , 6825the whole line is yanked. 6826.It Y 6827Yank from the current position to the end of the line. 6828.It Xo 6829.Oo Ar n Oc Ns p 6830.Xc 6831Paste the contents of the yank buffer just after the current position, 6832.Ar n 6833times. 6834.It Xo 6835.Oo Ar n Oc Ns P 6836.Xc 6837Same as 6838.Ic p , 6839except the buffer is pasted at the current position. 6840.El 6841.Pp 6842Miscellaneous vi commands 6843.Bl -tag -width Ds 6844.It \*(haJ and \*(haM 6845The current line is read, parsed and executed by the shell. 6846.It \*(haL and \*(haR 6847Redraw the current line. 6848.It Xo 6849.Oo Ar n Oc Ns \&. 6850.Xc 6851Redo the last edit command 6852.Ar n 6853times. 6854.It u 6855Undo the last edit command. 6856.It U 6857Undo all changes that have been made to the current line. 6858.It PC Home, End, Del and cursor keys 6859They move as expected, both in insert and command mode. 6860.It Ar intr No and Ar quit 6861The interrupt and quit terminal characters cause the current line to be 6862removed to the history and a new prompt to be printed. 6863.El 6864.Sh FILES 6865.Bl -tag -width XetcXsuid_profile -compact 6866.It Pa \*(TI/.mkshrc 6867User mkshrc profile (non-privileged interactive shells); see 6868.Sx Startup files. 6869The location can be changed at compile time (e.g. for embedded systems); 6870AOSP Android builds use 6871.Pa /system/etc/mkshrc . 6872.It Pa \*(TI/.profile 6873User profile (non-privileged login shells); see 6874.Sx Startup files 6875near the top of this manual. 6876.It Pa /etc/profile 6877System profile (login shells); see 6878.Sx Startup files. 6879.It Pa /etc/shells 6880Shell database. 6881.It Pa /etc/suid_profile 6882Privileged shells' profile (sugid); see 6883.Sx Startup files. 6884.El 6885.Pp 6886Note: On Android, 6887.Pa /system/etc/ 6888contains the system and suid profile. 6889.Sh SEE ALSO 6890.Xr awk 1 , 6891.Xr cat 1 , 6892.Xr ed 1 , 6893.Xr getopt 1 , 6894.Xr lksh 1 , 6895.Xr sed 1 , 6896.Xr sh 1 , 6897.Xr stty 1 , 6898.Xr dup 2 , 6899.Xr execve 2 , 6900.Xr getgid 2 , 6901.Xr getuid 2 , 6902.Xr mknod 2 , 6903.Xr mkfifo 2 , 6904.Xr open 2 , 6905.Xr pipe 2 , 6906.Xr rename 2 , 6907.Xr wait 2 , 6908.Xr getopt 3 , 6909.Xr nl_langinfo 3 , 6910.Xr setlocale 3 , 6911.Xr signal 3 , 6912.Xr system 3 , 6913.Xr tty 4 , 6914.Xr shells 5 , 6915.Xr environ 7 , 6916.Xr script 7 , 6917.Xr utf\-8 7 , 6918.Xr mknod 8 6919.Pp 6920The FAQ at 6921.Pa http://www.mirbsd.org/mksh\-faq.htm 6922or in the 6923.Pa mksh.faq 6924file. 6925.Pp 6926.Pa http://www.mirbsd.org/ksh\-chan.htm 6927.Rs 6928.%A Morris Bolsky 6929.%B "The KornShell Command and Programming Language" 6930.%D 1989 6931.%I "Prentice Hall PTR" 6932.%P "xvi\ +\ 356 pages" 6933.%O "ISBN 978\-0\-13\-516972\-8 (0\-13\-516972\-0)" 6934.Re 6935.Rs 6936.%A Morris I. Bolsky 6937.%A David G. Korn 6938.%B "The New KornShell Command and Programming Language (2nd Edition)" 6939.%D 1995 6940.%I "Prentice Hall PTR" 6941.%P "xvi\ +\ 400 pages" 6942.%O "ISBN 978\-0\-13\-182700\-4 (0\-13\-182700\-6)" 6943.Re 6944.Rs 6945.%A Stephen G. Kochan 6946.%A Patrick H. Wood 6947.%B "\\*(tNUNIX\\*(sP Shell Programming" 6948.%V "3rd Edition" 6949.%D 2003 6950.%I "Sams" 6951.%P "xiii\ +\ 437 pages" 6952.%O "ISBN 978\-0\-672\-32490\-1 (0\-672\-32490\-3)" 6953.Re 6954.Rs 6955.%A "IEEE Inc." 6956.%T "\\*(tNIEEE\\*(sP Standard for Information Technology\*(EMPortable Operating System Interface (POSIX)" 6957.%V "Part 2: Shell and Utilities" 6958.%D 1993 6959.%I "IEEE Press" 6960.%P "xvii\ +\ 1195 pages" 6961.%O "ISBN 978\-1\-55937\-255\-8 (1\-55937\-255\-9)" 6962.Re 6963.Rs 6964.%A Bill Rosenblatt 6965.%B "Learning the Korn Shell" 6966.%D 1993 6967.%I "O'Reilly" 6968.%P "360 pages" 6969.%O "ISBN 978\-1\-56592\-054\-5 (1\-56592\-054\-6)" 6970.Re 6971.Rs 6972.%A Bill Rosenblatt 6973.%A Arnold Robbins 6974.%B "Learning the Korn Shell, Second Edition" 6975.%D 2002 6976.%I "O'Reilly" 6977.%P "432 pages" 6978.%O "ISBN 978\-0\-596\-00195\-7 (0\-596\-00195\-9)" 6979.Re 6980.Rs 6981.%A Barry Rosenberg 6982.%B "KornShell Programming Tutorial" 6983.%D 1991 6984.%I "Addison-Wesley Professional" 6985.%P "xxi\ +\ 324 pages" 6986.%O "ISBN 978\-0\-201\-56324\-5 (0\-201\-56324\-X)" 6987.Re 6988.Sh AUTHORS 6989.An -nosplit 6990.Nm "The MirBSD Korn Shell" 6991is developed by 6992.An mirabilos Aq Mt m@mirbsd.org 6993as part of The MirOS Project. 6994This shell is based on the public domain 7th edition Bourne shell clone by 6995.An Charles Forsyth , 6996who kindly agreed to, in countries where the Public Domain status of the work 6997may not be valid, grant a copyright licence to the general public to deal in 6998the work without restriction and permission to sublicence derivatives under 6999the terms of any (OSI approved) Open Source licence, 7000and parts of the BRL shell by 7001.An Doug A. Gwyn , 7002.An Doug Kingston , 7003.An Ron Natalie , 7004.An Arnold Robbins , 7005.An Lou Salkind 7006and others. 7007The first release of 7008.Nm pdksh 7009was created by 7010.An Eric Gisin , 7011and it was subsequently maintained by 7012.An John R. MacMillan , 7013.An Simon J. Gerraty 7014and 7015.An Michael Rendell . 7016The effort of several projects, such as Debian and OpenBSD, and other 7017contributors including our users, to improve the shell is appreciated. 7018See the documentation, website and source code (CVS) for details. 7019.Pp 7020.Nm mksh\-os2 7021is developed by 7022.An KO Myung-Hun Aq Mt komh@chollian.net . 7023.Pp 7024.Nm mksh\-w32 7025is developed by 7026.An Michael Langguth Aq Mt lan@scalaris.com . 7027.Pp 7028.Nm mksh Ns / Ns Tn z/OS 7029is contributed by 7030.An Daniel Richard G. Aq Mt skunk@iSKUNK.ORG . 7031.Pp 7032The BSD daemon is Copyright \(co Marshall Kirk McKusick. 7033The complete legalese is at: 7034.Pa http://www.mirbsd.org/TaC\-mksh.txt 7035.\" 7036.\" This boils down to: feel free to use mksh.ico as application icon 7037.\" or shortcut for mksh or mksh/Win32 or OS/2; distro patches are ok 7038.\" (but we request they amend $KSH_VERSION when modifying mksh). 7039.\" Authors are Marshall Kirk McKusick (UCB), Rick Collette (ekkoBSD), 7040.\" mirabilos, Benny Siegert (MirBSD), Michael Langguth (mksh/Win32), 7041.\" KO Myung-Hun (mksh for OS/2). 7042.\" 7043.\" As far as MirBSD is concerned, the files themselves are free 7044.\" to modification and distribution under BSD/MirOS Licence, the 7045.\" restriction on use stems only from trademark law's requirement 7046.\" to protect it or lose it, which McKusick almost did. 7047.\" 7048.Sh CAVEATS 7049.Nm mksh 7050provides a consistent, clear interface normally. 7051This may deviate from POSIX in historic or opinionated places. 7052.Ic set Fl o Ic posix 7053(see 7054.Sx POSIX mode 7055for details) 7056will make the shell more conformant, but mind the FAQ (see 7057.Sx SEE ALSO ) , 7058especially regarding locales. 7059.Nm mksh 7060.Pq but not Nm lksh 7061provides a consistent 32-bit integer arithmetic implementation, both 7062signed and unsigned, with sign of the result of a remainder operation 7063and wraparound defined, even (defying POSIX) on 36-bit and 64-bit systems. 7064.Pp 7065.Nm mksh 7066currently uses OPTU-16 internally, which is the same as UTF-8 and CESU-8 7067with 0000..FFFD being valid codepoints; raw octets are mapped into the 7068PUA range EF80..EFFF, which is assigned by CSUR for this purpose. 7069.Sh BUGS 7070Suspending (using \*(haZ) pipelines like the one below will only suspend 7071the currently running part of the pipeline; in this example, 7072.Dq Li fubar 7073is immediately printed on suspension (but not later after an 7074.Ic fg ) . 7075.Bd -literal -offset indent 7076$ /bin/sleep 666 && echo fubar 7077.Ed 7078.Pp 7079The truncation process involved when changing 7080.Ev HISTFILE 7081does not free old history entries (leaks memory) and leaks 7082old entries into the new history if their line numbers are 7083not overwritten by same-number entries from the persistent 7084history file; truncating the on-disc file to 7085.Ev HISTSIZE 7086lines has always been broken and prone to history file corruption 7087when multiple shells are accessing the file; the rollover process 7088for the in-memory portion of the history is slow, should use 7089.Xr memmove 3 . 7090.Pp 7091This document attempts to describe 7092.Nm mksh\ R59c 7093and up, 7094.\" with vendor patches from insert-your-name-here, 7095compiled without any options impacting functionality, such as 7096.Dv MKSH_SMALL , 7097when not called as 7098.Pa /bin/sh 7099which, on some systems only, enables 7100.Ic set Fl o Ic posix 7101or 7102.Ic set Fl o Ic sh 7103automatically (whose behaviour differs across targets), 7104for an operating environment supporting all of its advanced needs. 7105.Pp 7106Please report bugs in 7107.Nm 7108to the public development mailing list at 7109.Aq Mt miros\-mksh@mirbsd.org 7110(please note the EU-DSGVO/GDPR notice on 7111.Pa http://www.mirbsd.org/rss.htm#lists 7112and in the SMTP banner!) or in the 7113.Li \&#\&!/bin/mksh 7114.Pq or Li \&#ksh 7115IRC channel at 7116.Pa irc.freenode.net 7117.Pq Port 6697 SSL, 6667 unencrypted , 7118or at: 7119.Pa https://launchpad.net/mksh 7120