1.\" $NetBSD: sh.1,v 1.52 2002/10/02 10:01:46 wiz Exp $ 2.\" Copyright (c) 1991, 1993 3.\" The Regents of the University of California. All rights reserved. 4.\" 5.\" This code is derived from software contributed to Berkeley by 6.\" Kenneth Almquist. 7.\" 8.\" Redistribution and use in source and binary forms, with or without 9.\" modification, are permitted provided that the following conditions 10.\" are met: 11.\" 1. Redistributions of source code must retain the above copyright 12.\" notice, this list of conditions and the following disclaimer. 13.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" notice, this list of conditions and the following disclaimer in the 15.\" documentation and/or other materials provided with the distribution. 16.\" 3. All advertising materials mentioning features or use of this software 17.\" must display the following acknowledgement: 18.\" This product includes software developed by the University of 19.\" California, Berkeley and its contributors. 20.\" 4. Neither the name of the University nor the names of its contributors 21.\" may be used to endorse or promote products derived from this software 22.\" without specific prior written permission. 23.\" 24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34.\" SUCH DAMAGE. 35.\" 36.\" @(#)sh.1 8.6 (Berkeley) 5/4/95 37.\" 38.Dd February 25, 2002 39.Os 40.Dt SH 1 41.Sh NAME 42.Nm sh 43.Nd command interpreter (shell) 44.Sh SYNOPSIS 45.Nm 46.Op Fl /+aCefnuvxIimqsVEbc 47.Op Fl o Ar longname 48.Bk -words 49.Op Ar target ... 50.Ek 51.Sh DESCRIPTION 52.Nm 53is the standard command interpreter for the system. 54The current version of 55.Nm 56is in the process of being changed to conform with the 57.Tn POSIX 581003.2 and 1003.2a specifications for the shell. 59This version has many 60features which make it appear similar in some respects to the Korn shell, 61but it is not a Korn shell clone (see 62.Xr ksh 1 ) . 63Only features designated by 64.Tn POSIX , 65plus a few Berkeley extensions, are being incorporated into this shell. 66We expect 67.Tn POSIX 68conformance by the time 4.4 BSD is released. 69This man page is not intended 70to be a tutorial or a complete specification of the shell. 71.Ss Overview 72The shell is a command that reads lines from either a file or the 73terminal, interprets them, and generally executes other commands. 74It is the program that is running when a user logs into the system 75(although a user can select a different shell with the 76.Xr chsh 1 77command). 78The shell implements a language that has flow control 79constructs, a macro facility that provides a variety of features in 80addition to data storage, along with built in history and line editing 81capabilities. 82It incorporates many features to aid interactive use and 83has the advantage that the interpretative language is common to both 84interactive and non-interactive use (shell scripts). 85That is, commands 86can be typed directly to the running shell or can be put into a file and 87the file can be executed directly by the shell. 88.Ss Invocation 89If no args are present and if the standard input of the shell 90is connected to a terminal (or if the 91.Fl i 92flag is set), 93and the 94.Fl c 95option is not present, the shell is considered an interactive shell. 96An interactive shell generally prompts before each command and handles 97programming and command errors differently (as described below). 98When first starting, 99the shell inspects argument 0, and if it begins with a dash 100.Sq - , 101the shell is also considered 102a login shell. 103This is normally done automatically by the system 104when the user first logs in. 105A login shell first reads commands 106from the files 107.Pa /etc/profile 108and 109.Pa .profile 110if they exist. 111If the environment variable 112.Ev ENV 113is set on entry to a shell, or is set in the 114.Pa .profile 115of a login shell, the shell next reads 116commands from the file named in 117.Ev ENV . 118Therefore, a user should place commands that are to be executed only at 119login time in the 120.Pa .profile 121file, and commands that are executed for every shell inside the 122.Ev ENV 123file. 124To set the 125.Ev ENV 126variable to some file, place the following line in your 127.Pa .profile 128of your home directory 129.Pp 130.Dl ENV=$HOME/.shinit; export ENV 131.Pp 132substituting for 133.Dq .shinit 134any filename you wish. 135Since the 136.Ev ENV 137file is read for every invocation of the shell, including shell scripts 138and non-interactive shells, the following paradigm is useful for 139restricting commands in the 140.Ev ENV 141file to interactive invocations. 142Place commands within the 143.Dq case 144and 145.Dq esac 146below (these commands are described later): 147.Pp 148.Bl -item -compact -offset indent 149.It 150.Li case $- in *i*) 151.Bl -item -compact -offset indent 152.It 153.Li # commands for interactive use only 154.It 155.Li ... 156.El 157.It 158.Li esac 159.El 160.Pp 161If command line arguments besides the options have been specified, then 162the shell treats the first argument as the name of a file from which to 163read commands (a shell script), and the remaining arguments are set as the 164positional parameters of the shell ($1, $2, etc). 165Otherwise, the shell 166reads commands from its standard input. 167.Ss Argument List Processing 168All of the single letter options have a corresponding name that can be 169used as an argument to the 170.Fl o 171option. 172The set 173.Fl o 174name is provided next to the single letter option in 175the description below. 176Specifying a dash 177.Dq - 178turns the option on, while using a plus 179.Dq + 180disables the option. 181The following options can be set from the command line or 182with the 183.Ic set 184builtin (described later). 185.Bl -tag -width aaaallexportfoo -offset indent 186.It Fl a Em allexport 187Export all variables assigned to. 188.It Fl c 189Read commands from the command line. 190No commands will be read from the standard input. 191.It Fl C Em noclobber 192Don't overwrite existing files with 193.Dq \*[Gt] . 194.It Fl e Em errexit 195If not interactive, exit immediately if any untested command fails. 196The exit status of a command is considered to be 197explicitly tested if the command is used to control an 198.Ic if , 199.Ic elif , 200.Ic while , 201or 202.Ic until ; 203or if the command is the left hand operand of an 204.Dq \*[Am]\*[Am] 205or 206.Dq || 207operator. 208.It Fl f Em noglob 209Disable pathname expansion. 210.It Fl n Em noexec 211If not interactive, read commands but do not execute them. 212This is useful for checking the syntax of shell scripts. 213.It Fl u Em nounset 214Write a message to standard error when attempting to expand a variable 215that is not set, and if the shell is not interactive, exit immediately. 216.It Fl v Em verbose 217The shell writes its input to standard error as it is read. 218Useful for debugging. 219.It Fl x Em xtrace 220Write each command to standard error (preceded by a 221.Sq +\ ) 222before it is executed. 223Useful for debugging. 224.It Fl q Em quietprofile 225If the 226.Fl v 227or 228.Fl x 229options have been set, do not apply them when reading 230initialization files, these being 231.Pa /etc/profile , 232.Pa .profile , 233and the file specified by the 234.Ev ENV 235environment variable. 236.It Fl I Em ignoreeof 237Ignore EOF's from input when interactive. 238.It Fl i Em interactive 239Force the shell to behave interactively. 240.It Fl m Em monitor 241Turn on job control (set automatically when interactive). 242.It Fl s Em stdin 243Read commands from standard input (set automatically if no file arguments 244are present). 245This option has no effect when set after the shell has 246already started running (i.e. with 247.Ic set ) . 248.It Fl V Em vi 249Enable the built-in 250.Xr vi 1 251command line editor (disables 252.Fl E 253if it has been set). 254.It Fl E Em emacs 255Enable the built-in 256.Xr emacs 1 257command line editor (disables 258.Fl V 259if it has been set). 260.It Fl b Em notify 261Enable asynchronous notification of background job completion. 262(UNIMPLEMENTED for 4.4alpha) 263.El 264.Ss Lexical Structure 265The shell reads input in terms of lines from a file and breaks it up into 266words at whitespace (blanks and tabs), and at certain sequences of 267characters that are special to the shell called 268.Dq operators . 269There are two types of operators: control operators and redirection 270operators (their meaning is discussed later). 271Following is a list of operators: 272.Bl -ohang -offset indent 273.It "Control operators:" 274.Dl \*[Am] \*[Am]\*[Am] \&( \&) \&; ;; | || \*[Lt]newline\*[Gt] 275.It "Redirection operators:" 276.Dl \*[Lt] \*[Gt] \*[Gt]| \*[Lt]\*[Lt] \*[Gt]\*[Gt] \*[Lt]\*[Am] \*[Gt]\*[Am] \*[Lt]\*[Lt]- \*[Lt]\*[Gt] 277.El 278.Ss Quoting 279Quoting is used to remove the special meaning of certain characters or 280words to the shell, such as operators, whitespace, or keywords. 281There are three types of quoting: matched single quotes, 282matched double quotes, and backslash. 283.Ss Backslash 284A backslash preserves the literal meaning of the following 285character, with the exception of 286.Aq newline . 287A backslash preceding a 288.Aq newline 289is treated as a line continuation. 290.Ss Single Quotes 291Enclosing characters in single quotes preserves the literal meaning of all 292the characters (except single quotes, making it impossible to put 293single-quotes in a single-quoted string). 294.Ss Double Quotes 295Enclosing characters within double quotes preserves the literal 296meaning of all characters except dollarsign 297.Pq $ , 298backquote 299.Pq ` , 300and backslash 301.Pq \e . 302The backslash inside double quotes is historically weird, and serves to 303quote only the following characters: 304.Dl $ ` \*q \e \*[Lt]newline\*[Gt] . 305Otherwise it remains literal. 306.Ss Reserved Words 307Reserved words are words that have special meaning to the 308shell and are recognized at the beginning of a line and 309after a control operator. 310The following are reserved words: 311.Bl -column while while while while while -offset indent 312.It ! Ta elif Ta fi Ta while Ta case 313.It else Ta for Ta then Ta { Ta } 314.It do Ta done Ta until Ta if Ta esac 315.El 316.Pp 317Their meaning is discussed later. 318.Ss Aliases 319An alias is a name and corresponding value set using the 320.Xr alias 1 321builtin command. 322Whenever a reserved word may occur (see above), 323and after checking for reserved words, the shell 324checks the word to see if it matches an alias. 325If it does, it replaces it in the input stream with its value. 326For example, if there is an alias called 327.Dq lf 328with the value 329.Dq "ls -F" , 330then the input: 331.Pp 332.Dl lf foobar Aq return 333.Pp 334would become 335.Pp 336.Dl ls -F foobar Aq return 337.Pp 338Aliases provide a convenient way for naive users to create shorthands for 339commands without having to learn how to create functions with arguments. 340They can also be used to create lexically obscure code. 341This use is discouraged. 342.Ss Commands 343The shell interprets the words it reads according to a language, the 344specification of which is outside the scope of this man page (refer to the 345BNF in the 346.Tn POSIX 3471003.2 document). 348Essentially though, a line is read and if the first 349word of the line (or after a control operator) is not a reserved word, 350then the shell has recognized a simple command. 351Otherwise, a complex 352command or some other special construct may have been recognized. 353.Ss Simple Commands 354If a simple command has been recognized, the shell performs 355the following actions: 356.Bl -enum -offset indent 357.It 358Leading words of the form 359.Dq name=value 360are stripped off and assigned to the environment of the simple command. 361Redirection operators and their arguments (as described below) are 362stripped off and saved for processing. 363.It 364The remaining words are expanded as described in 365the section called 366.Dq Expansions , 367and the first remaining word is considered the command name and the 368command is located. 369The remaining words are considered the arguments of the command. 370If no command name resulted, then the 371.Dq name=value 372variable assignments recognized in item 1 affect the current shell. 373.It 374Redirections are performed as described in the next section. 375.El 376.Ss Redirections 377Redirections are used to change where a command reads its input or sends 378its output. 379In general, redirections open, close, or duplicate an 380existing reference to a file. 381The overall format used for redirection is: 382.Pp 383.Dl [n] Va redir-op Ar file 384.Pp 385where 386.Va redir-op 387is one of the redirection operators mentioned previously. 388Following is a list of the possible redirections. 389The 390.Bq n 391is an optional number, as in 392.Sq 3 393(not 394.Sq Bq 3 , 395that refers to a file descriptor. 396.Bl -tag -width aaabsfiles -offset indent 397.It [n] Ns \*[Gt] file 398Redirect standard output (or n) to file. 399.It [n] Ns \*[Gt]| file 400Same, but override the 401.Fl C 402option. 403.It [n] Ns \*[Gt]\*[Gt] file 404Append standard output (or n) to file. 405.It [n] Ns \*[Lt] file 406Redirect standard input (or n) from file. 407.It [n1] Ns \*[Lt]\*[Am] Ns n2 408Duplicate standard input (or n1) from file descriptor n2. 409.It [n] Ns \*[Lt]\*[Am]- 410Close standard input (or n). 411.It [n1] Ns \*[Gt]\*[Am] Ns n2 412Duplicate standard output (or n1) from n2. 413.It [n] Ns \*[Gt]\*[Am]- 414Close standard output (or n). 415.It [n] Ns \*[Lt]\*[Gt] file 416Open file for reading and writing on standard input (or n). 417.El 418.Pp 419The following redirection is often called a 420.Dq here-document . 421.Bl -item -offset indent 422.It 423.Li [n]\*[Lt]\*[Lt] delimiter 424.Dl here-doc-text ... 425.Li delimiter 426.El 427.Pp 428All the text on successive lines up to the delimiter is saved away and 429made available to the command on standard input, or file descriptor n if 430it is specified. 431If the delimiter as specified on the initial line is 432quoted, then the here-doc-text is treated literally, otherwise the text is 433subjected to parameter expansion, command substitution, and arithmetic 434expansion (as described in the section on 435.Dq Expansions ) . 436If the operator is 437.Dq \*[Lt]\*[Lt]- 438instead of 439.Dq \*[Lt]\*[Lt] , 440then leading tabs in the here-doc-text are stripped. 441.Ss Search and Execution 442There are three types of commands: shell functions, builtin commands, and 443normal programs -- and the command is searched for (by name) in that order. 444They each are executed in a different way. 445.Pp 446When a shell function is executed, all of the shell positional parameters 447(except $0, which remains unchanged) are set to the arguments of the shell 448function. 449The variables which are explicitly placed in the environment of 450the command (by placing assignments to them before the function name) are 451made local to the function and are set to the values given. 452Then the command given in the function definition is executed. 453The positional parameters are restored to their original values 454when the command completes. 455This all occurs within the current shell. 456.Pp 457Shell builtins are executed internally to the shell, without spawning a 458new process. 459.Pp 460Otherwise, if the command name doesn't match a function or builtin, the 461command is searched for as a normal program in the file system (as 462described in the next section). 463When a normal program is executed, the shell runs the program, 464passing the arguments and the environment to the program. 465If the program is not a normal executable file (i.e., if it does 466not begin with the "magic number" whose 467.Tn ASCII 468representation is "#!", so 469.Xr execve 2 470returns 471.Er ENOEXEC 472then) the shell will interpret the program in a subshell. 473The child shell will reinitialize itself in this case, 474so that the effect will be as if a 475new shell had been invoked to handle the ad-hoc shell script, except that 476the location of hashed commands located in the parent shell will be 477remembered by the child. 478.Pp 479Note that previous versions of this document and the source code itself 480misleadingly and sporadically refer to a shell script without a magic 481number as a "shell procedure". 482.Ss Path Search 483When locating a command, the shell first looks to see if it has a shell 484function by that name. 485Then it looks for a builtin command by that name. 486If a builtin command is not found, one of two things happen: 487.Bl -enum 488.It 489Command names containing a slash are simply executed without performing 490any searches. 491.It 492The shell searches each entry in 493.Ev PATH 494in turn for the command. 495The value of the 496.Ev PATH 497variable should be a series of entries separated by colons. 498Each entry consists of a directory name. 499The current directory may be indicated 500implicitly by an empty directory name, or explicitly by a single period. 501.El 502.Ss Command Exit Status 503Each command has an exit status that can influence the behavior 504of other shell commands. 505The paradigm is that a command exits 506with zero for normal or success, and non-zero for failure, 507error, or a false indication. 508The man page for each command 509should indicate the various exit codes and what they mean. 510Additionally, the builtin commands return exit codes, as does 511an executed shell function. 512.Ss Complex Commands 513Complex commands are combinations of simple commands with control 514operators or reserved words, together creating a larger complex command. 515More generally, a command is one of the following: 516.Bl -bullet 517.It 518simple command 519.It 520pipeline 521.It 522list or compound-list 523.It 524compound command 525.It 526function definition 527.El 528.Pp 529Unless otherwise stated, the exit status of a command is that of the last 530simple command executed by the command. 531.Ss Pipelines 532A pipeline is a sequence of one or more commands separated 533by the control operator |. 534The standard output of all but 535the last command is connected to the standard input 536of the next command. 537The standard output of the last 538command is inherited from the shell, as usual. 539.Pp 540The format for a pipeline is: 541.Pp 542.Dl [!] command1 [ | command2 ...] 543.Pp 544The standard output of command1 is connected to the standard input of 545command2. 546The standard input, standard output, or both of a command is 547considered to be assigned by the pipeline before any redirection specified 548by redirection operators that are part of the command. 549.Pp 550If the pipeline is not in the background (discussed later), the shell 551waits for all commands to complete. 552.Pp 553If the reserved word ! does not precede the pipeline, the exit status is 554the exit status of the last command specified in the pipeline. 555Otherwise, the exit status is the logical NOT of the exit status of the 556last command. 557That is, if the last command returns zero, the exit status 558is 1; if the last command returns greater than zero, the exit status is 559zero. 560.Pp 561Because pipeline assignment of standard input or standard output or both 562takes place before redirection, it can be modified by redirection. 563For example: 564.Pp 565.Dl $ command1 2\*[Gt]\*[Am]1 | command2 566.Pp 567sends both the standard output and standard error of command1 568to the standard input of command2. 569.Pp 570A ; or 571.Aq newline 572terminator causes the preceding AND-OR-list (described 573next) to be executed sequentially; a \*[Am] causes asynchronous execution of 574the preceding AND-OR-list. 575.Pp 576Note that unlike some other shells, each process in the pipeline is a 577child of the invoking shell (unless it is a shell builtin, in which case 578it executes in the current shell -- but any effect it has on the 579environment is wiped). 580.Ss Background Commands -- \*[Am] 581If a command is terminated by the control operator ampersand (\*[Am]), the 582shell executes the command asynchronously -- that is, the shell does not 583wait for the command to finish before executing the next command. 584.Pp 585The format for running a command in background is: 586.Pp 587.Dl command1 \*[Am] [command2 \*[Am] ...] 588.Pp 589If the shell is not interactive, the standard input of an asynchronous 590command is set to 591.Pa /dev/null . 592.Ss Lists -- Generally Speaking 593A list is a sequence of zero or more commands separated by newlines, 594semicolons, or ampersands, and optionally terminated by one of these three 595characters. 596The commands in a list are executed in the order they are written. 597If command is followed by an ampersand, the shell starts the 598command and immediately proceed onto the next command; otherwise it waits 599for the command to terminate before proceeding to the next one. 600.Ss Short-Circuit List Operators 601.Dq \*[Am]\*[Am] 602and 603.Dq || 604are AND-OR list operators. 605.Dq \*[Am]\*[Am] 606executes the first command, and then executes the second command iff the 607exit status of the first command is zero. 608.Dq || 609is similar, but executes the second command iff the exit status of the first 610command is nonzero. 611.Dq \*[Am]\*[Am] 612and 613.Dq || 614both have the same priority. 615.Ss Flow-Control Constructs -- if, while, for, case 616The syntax of the if command is 617.Bd -literal -offset indent 618if list 619then list 620[ elif list 621then list ] ... 622[ else list ] 623fi 624.Ed 625.Pp 626The syntax of the while command is 627.Bd -literal -offset indent 628while list 629do list 630done 631.Ed 632.Pp 633The two lists are executed repeatedly while the exit status of the 634first list is zero. 635The until command is similar, but has the word 636until in place of while, which causes it to 637repeat until the exit status of the first list is zero. 638.Pp 639The syntax of the for command is 640.Bd -literal -offset indent 641for variable in word ... 642do list 643done 644.Ed 645.Pp 646The words are expanded, and then the list is executed repeatedly with the 647variable set to each word in turn. 648do and done may be replaced with 649.Dq { 650and 651.Dq } . 652.Pp 653The syntax of the break and continue command is 654.Bd -literal -offset indent 655break [ num ] 656continue [ num ] 657.Ed 658.Pp 659Break terminates the num innermost for or while loops. 660Continue continues with the next iteration of the innermost loop. 661These are implemented as builtin commands. 662.Pp 663The syntax of the case command is 664.Bd -literal -offset indent 665case word in 666pattern) list ;; 667\&... 668esac 669.Ed 670.Pp 671The pattern can actually be one or more patterns (see 672.Sx Shell Patterns 673described later), separated by 674.Dq \*(Ba 675characters. 676.Ss Grouping Commands Together 677Commands may be grouped by writing either 678.Pp 679.Dl (list) 680.Pp 681or 682.Pp 683.Dl { list; } 684.Pp 685The first of these executes the commands in a subshell. 686Builtin commands grouped into a (list) will not affect the current shell. 687The second form does not fork another shell so is slightly more efficient. 688Grouping commands together this way allows you to redirect 689their output as though they were one program: 690.Pp 691.Bd -literal -offset indent 692{ echo -n \*q hello \*q ; echo \*q world" ; } \*[Gt] greeting 693.Ed 694.Pp 695Note that 696.Dq } 697must follow a control operator (here, 698.Dq \&; ) 699so that it is recognized as a reserved word and not as another command argument. 700.Ss Functions 701The syntax of a function definition is 702.Pp 703.Dl name ( ) command 704.Pp 705A function definition is an executable statement; when executed it 706installs a function named name and returns an exit status of zero. 707The command is normally a list enclosed between 708.Dq { 709and 710.Dq } . 711.Pp 712Variables may be declared to be local to a function by using a local 713command. 714This should appear as the first statement of a function, and the syntax is 715.Pp 716.Dl local [ variable | - ] ... 717.Pp 718Local is implemented as a builtin command. 719.Pp 720When a variable is made local, it inherits the initial value and exported 721and readonly flags from the variable with the same name in the surrounding 722scope, if there is one. 723Otherwise, the variable is initially unset. 724The shell uses dynamic scoping, so that if you make the variable x local to 725function f, which then calls function g, references to the variable x made 726inside g will refer to the variable x declared inside f, not to the global 727variable named x. 728.Pp 729The only special parameter than can be made local is 730.Dq - . 731Making 732.Dq - 733local any shell options that are changed via the set command inside the 734function to be restored to their original values when the function 735returns. 736.Pp 737The syntax of the return command is 738.Pp 739.Dl return [ exitstatus ] 740.Pp 741It terminates the currently executing function. 742Return is implemented as a builtin command. 743.Ss Variables and Parameters 744The shell maintains a set of parameters. 745A parameter denoted by a name is called a variable. 746When starting up, the shell turns all the environment 747variables into shell variables. 748New variables can be set using the form 749.Pp 750.Dl name=value 751.Pp 752Variables set by the user must have a name consisting solely of 753alphabetics, numerics, and underscores - the first of which must not be 754numeric. 755A parameter can also be denoted by a number or a special 756character as explained below. 757.Ss Positional Parameters 758A positional parameter is a parameter denoted by a number (n \*[Gt] 0). 759The shell sets these initially to the values of its command line arguments 760that follow the name of the shell script. 761The 762.Ic set 763builtin can also be used to set or reset them. 764.Ss Special Parameters 765A special parameter is a parameter denoted by one of the following special 766characters. 767The value of the parameter is listed next to its character. 768.Bl -tag -width thinhyphena 769.It * 770Expands to the positional parameters, starting from one. 771When the 772expansion occurs within a double-quoted string it expands to a single 773field with the value of each parameter separated by the first character of 774the 775.Ev IFS 776variable, or by a 777.Aq space 778if 779.Ev IFS 780is unset. 781.It @ 782Expands to the positional parameters, starting from one. 783When the expansion occurs within double-quotes, each positional 784parameter expands as a separate argument. 785If there are no positional parameters, the 786expansion of @ generates zero arguments, even when @ is 787double-quoted. 788What this basically means, for example, is 789if $1 is 790.Dq abc 791and $2 is 792.Dq def ghi , 793then 794.Qq $@ 795expands to 796the two arguments: 797.Pp 798.Sm off 799.Dl \*q abc \*q \ \*q def\ ghi \*q 800.Sm on 801.It # 802Expands to the number of positional parameters. 803.It ? 804Expands to the exit status of the most recent pipeline. 805.It - (Hyphen.) 806Expands to the current option flags (the single-letter 807option names concatenated into a string) as specified on 808invocation, by the set builtin command, or implicitly 809by the shell. 810.It $ 811Expands to the process ID of the invoked shell. 812A subshell retains the same value of $ as its parent. 813.It ! 814Expands to the process ID of the most recent background 815command executed from the current shell. 816For a pipeline, the process ID is that of the last command in the pipeline. 817.It 0 (Zero.) 818Expands to the name of the shell or shell script. 819.El 820.Ss Word Expansions 821This clause describes the various expansions that are performed on words. 822Not all expansions are performed on every word, as explained later. 823.Pp 824Tilde expansions, parameter expansions, command substitutions, arithmetic 825expansions, and quote removals that occur within a single word expand to a 826single field. 827It is only field splitting or pathname expansion that can 828create multiple fields from a single word. 829The single exception to this 830rule is the expansion of the special parameter @ within double-quotes, as 831was described above. 832.Pp 833The order of word expansion is: 834.Bl -enum 835.It 836Tilde Expansion, Parameter Expansion, Command Substitution, 837Arithmetic Expansion (these all occur at the same time). 838.It 839Field Splitting is performed on fields 840generated by step (1) unless the 841.Ev IFS 842variable is null. 843.It 844Pathname Expansion (unless set 845.Fl f 846is in effect). 847.It 848Quote Removal. 849.El 850.Pp 851The $ character is used to introduce parameter expansion, command 852substitution, or arithmetic evaluation. 853.Ss Tilde Expansion (substituting a user's home directory) 854A word beginning with an unquoted tilde character (~) is 855subjected to tilde expansion. 856All the characters up to 857a slash (/) or the end of the word are treated as a username 858and are replaced with the user's home directory. 859If the username is missing (as in 860.Pa ~/foobar ) , 861the tilde is replaced with the value of the 862.Va HOME 863variable (the current user's home directory). 864.Ss Parameter Expansion 865The format for parameter expansion is as follows: 866.Pp 867.Dl ${expression} 868.Pp 869where expression consists of all characters until the matching 870.Dq } . 871Any 872.Dq } 873escaped by a backslash or within a quoted string, and characters in 874embedded arithmetic expansions, command substitutions, and variable 875expansions, are not examined in determining the matching 876.Dq } . 877.Pp 878The simplest form for parameter expansion is: 879.Pp 880.Dl ${parameter} 881.Pp 882The value, if any, of parameter is substituted. 883.Pp 884The parameter name or symbol can be enclosed in braces, which are 885optional except for positional parameters with more than one digit or 886when parameter is followed by a character that could be interpreted as 887part of the name. 888If a parameter expansion occurs inside double-quotes: 889.Bl -enum 890.It 891Pathname expansion is not performed on the results of the expansion. 892.It 893Field splitting is not performed on the results of the 894expansion, with the exception of @. 895.El 896.Pp 897In addition, a parameter expansion can be modified by using one of the 898following formats. 899.Bl -tag -width aaparameterwordaaaaa 900.It ${parameter:-word} 901Use Default Values. 902If parameter is unset or null, the expansion of word 903is substituted; otherwise, the value of parameter is substituted. 904.It ${parameter:=word} 905Assign Default Values. 906If parameter is unset or null, the expansion of 907word is assigned to parameter. 908In all cases, the final value of parameter is substituted. 909Only variables, not positional parameters or special 910parameters, can be assigned in this way. 911.It ${parameter:?[word]} 912Indicate Error if Null or Unset. 913If parameter is unset or null, the 914expansion of word (or a message indicating it is unset if word is omitted) 915is written to standard error and the shell exits with a nonzero exit status. 916Otherwise, the value of parameter is substituted. 917An interactive shell need not exit. 918.It ${parameter:+word} 919Use Alternative Value. 920If parameter is unset or null, null is 921substituted; otherwise, the expansion of word is substituted. 922.El 923.Pp 924In the parameter expansions shown previously, use of the colon in the 925format results in a test for a parameter that is unset or null; omission 926of the colon results in a test for a parameter that is only unset. 927.Bl -tag -width aaparameterwordaaaaa 928.It ${#parameter} 929String Length. 930The length in characters of the value of parameter. 931.El 932.Pp 933The following four varieties of parameter expansion provide for substring 934processing. 935In each case, pattern matching notation (see 936.Sx Shell Patterns ) , 937rather than regular expression notation, is used to evaluate the patterns. 938If parameter is * or @, the result of the expansion is unspecified. 939Enclosing the full parameter expansion string in double-quotes does not 940cause the following four varieties of pattern characters to be quoted, 941whereas quoting characters within the braces has this effect. 942.Bl -tag -width aaparameterwordaaaaa 943.It ${parameter%word} 944Remove Smallest Suffix Pattern. 945The word is expanded to produce a pattern. 946The parameter expansion then results in parameter, with the 947smallest portion of the suffix matched by the pattern deleted. 948.It ${parameter%%word} 949Remove Largest Suffix Pattern. 950The word is expanded to produce a pattern. 951The parameter expansion then results in parameter, with the largest 952portion of the suffix matched by the pattern deleted. 953.It ${parameter#word} 954Remove Smallest Prefix Pattern. 955The word is expanded to produce a pattern. 956The parameter expansion then results in parameter, with the 957smallest portion of the prefix matched by the pattern deleted. 958.It ${parameter##word} 959Remove Largest Prefix Pattern. 960The word is expanded to produce a pattern. 961The parameter expansion then results in parameter, with the largest 962portion of the prefix matched by the pattern deleted. 963.El 964.Ss Command Substitution 965Command substitution allows the output of a command to be substituted in 966place of the command name itself. 967Command substitution occurs when the command is enclosed as follows: 968.Pp 969.Dl $(command) 970.Pp 971or 972.Po 973.Dq backquoted 974version 975.Pc : 976.Pp 977.Dl `command` 978.Pp 979The shell expands the command substitution by executing command in a 980subshell environment and replacing the command substitution with the 981standard output of the command, removing sequences of one or more 982.Ao newline Ac Ns s 983at the end of the substitution. 984(Embedded 985.Ao newline Ac Ns s 986before 987the end of the output are not removed; however, during field splitting, 988they may be translated into 989.Ao space Ac Ns s , 990depending on the value of 991.Ev IFS 992and quoting that is in effect.) 993.Ss Arithmetic Expansion 994Arithmetic expansion provides a mechanism for evaluating an arithmetic 995expression and substituting its value. 996The format for arithmetic expansion is as follows: 997.Pp 998.Dl $((expression)) 999.Pp 1000The expression is treated as if it were in double-quotes, except 1001that a double-quote inside the expression is not treated specially. 1002The shell expands all tokens in the expression for parameter expansion, 1003command substitution, and quote removal. 1004.Pp 1005Next, the shell treats this as an arithmetic expression and 1006substitutes the value of the expression. 1007.Ss White Space Splitting (Field Splitting) 1008After parameter expansion, command substitution, and 1009arithmetic expansion the shell scans the results of 1010expansions and substitutions that did not occur in double-quotes for 1011field splitting and multiple fields can result. 1012.Pp 1013The shell treats each character of the 1014.Ev IFS 1015as a delimiter and use the delimiters to split the results of parameter 1016expansion and command substitution into fields. 1017.Ss Pathname Expansion (File Name Generation) 1018Unless the 1019.Fl f 1020flag is set, file name generation is performed after word splitting is 1021complete. 1022Each word is viewed as a series of patterns, separated by slashes. 1023The process of expansion replaces the word with the names of all 1024existing files whose names can be formed by replacing each pattern with a 1025string that matches the specified pattern. 1026There are two restrictions on 1027this: first, a pattern cannot match a string containing a slash, and 1028second, a pattern cannot match a string starting with a period unless the 1029first character of the pattern is a period. 1030The next section describes the 1031patterns used for both Pathname Expansion and the 1032.Ic case 1033command. 1034.Ss Shell Patterns 1035A pattern consists of normal characters, which match themselves, 1036and meta-characters. 1037The meta-characters are 1038.Dq ! , 1039.Dq * , 1040.Dq ? , 1041and 1042.Dq [ . 1043These characters lose their special meanings if they are quoted. 1044When command or variable substitution is performed 1045and the dollar sign or back quotes are not double quoted, 1046the value of the variable or the output of 1047the command is scanned for these characters and they are turned into 1048meta-characters. 1049.Pp 1050An asterisk 1051.Pq Dq * 1052matches any string of characters. 1053A question mark matches any single character. 1054A left bracket 1055.Pq Dq \&[ 1056introduces a character class. 1057The end of the character class is indicated by a 1058.Pq Dq \&] ; 1059if the 1060.Dq \&] 1061is missing then the 1062.Dq \&[ 1063matches a 1064.Dq \&[ 1065rather than introducing a character class. 1066A character class matches any of the characters between the square brackets. 1067A range of characters may be specified using a minus sign. 1068The character class may be complemented 1069by making an exclamation point the first character of the character class. 1070.Pp 1071To include a 1072.Dq \&] 1073in a character class, make it the first character listed (after the 1074.Dq \&! , 1075if any). 1076To include a minus sign, make it the first or last character listed. 1077.Ss Builtins 1078This section lists the builtin commands which are builtin because they 1079need to perform some operation that can't be performed by a separate 1080process. 1081In addition to these, there are several other commands that may 1082be builtin for efficiency (e.g. 1083.Xr printf 1 , 1084.Xr echo 1 , 1085.Xr test 1 , 1086etc). 1087.Bl -tag -width 5n 1088.It : 1089A null command that returns a 0 (true) exit value. 1090.It \&. file 1091The commands in the specified file are read and executed by the shell. 1092.It alias Op Ar name Ns Op Ar "=string ..." 1093If 1094.Ar name=string 1095is specified, the shell defines the alias 1096.Ar name 1097with value 1098.Ar string . 1099If just 1100.Ar name 1101is specified, the value of the alias 1102.Ar name 1103is printed. 1104With no arguments, the 1105.Ic alias 1106builtin prints the 1107names and values of all defined aliases (see 1108.Ic unalias ) . 1109.It bg [ Ar job ] ... 1110Continue the specified jobs (or the current job if no 1111jobs are given) in the background. 1112.It command Ar command Ar arg ... 1113Execute the specified builtin command. 1114(This is useful when you 1115have a shell function with the same name as a builtin command.) 1116.It cd Op Ar directory 1117Switch to the specified directory (default 1118.Ev $HOME ) . 1119If an entry for 1120.Ev CDPATH 1121appears in the environment of the 1122.Ic cd 1123command or the shell variable 1124.Ev CDPATH 1125is set and the directory name does not begin with a slash, then the 1126directories listed in 1127.Ev CDPATH 1128will be searched for the specified directory. 1129The format of 1130.Ev CDPATH 1131is the same as that of 1132.Ev PATH . 1133In an interactive shell, the 1134.Ic cd 1135command will print out the name of the 1136directory that it actually switched to if this is different from the name 1137that the user gave. 1138These may be different either because the 1139.Ev CDPATH 1140mechanism was used or because a symbolic link was crossed. 1141.It eval Ar string ... 1142Concatenate all the arguments with spaces. 1143Then re-parse and execute the command. 1144.It exec Op Ar command arg ... 1145Unless command is omitted, the shell process is replaced with the 1146specified program (which must be a real program, not a shell builtin or 1147function). 1148Any redirections on the 1149.Ic exec 1150command are marked as permanent, so that they are not undone when the 1151.Ic exec 1152command finishes. 1153.It exit Op Ar exitstatus 1154Terminate the shell process. 1155If 1156.Ar exitstatus 1157is given it is used as the exit status of the shell; otherwise the 1158exit status of the preceding command is used. 1159.It export Ar name ... 1160.It export Fl p 1161The specified names are exported so that they will appear in the 1162environment of subsequent commands. 1163The only way to un-export a variable is to unset it. 1164The shell allows the value of a variable to be set at the 1165same time it is exported by writing 1166.Pp 1167.Dl export name=value 1168.Pp 1169With no arguments the export command lists the names of all exported variables. 1170With the 1171.Fl p 1172option specified the output will be formatted suitably for non-interactive use. 1173.It Xo fc Op Fl e Ar editor 1174.Op Ar first Op Ar last 1175.Xc 1176.It Xo fc Fl l 1177.Op Fl nr 1178.Op Ar first Op Ar last 1179.Xc 1180.It Xo fc Fl s Op Ar old=new 1181.Op Ar first 1182.Xc 1183The 1184.Ic fc 1185builtin lists, or edits and re-executes, commands previously entered 1186to an interactive shell. 1187.Bl -tag -width 5n 1188.It Fl e No editor 1189Use the editor named by editor to edit the commands. 1190The editor string is a command name, subject to search via the 1191.Ev PATH 1192variable. 1193The value in the 1194.Ev FCEDIT 1195variable is used as a default when 1196.Fl e 1197is not specified. 1198If 1199.Ev FCEDIT 1200is null or unset, the value of the 1201.Ev EDITOR 1202variable is used. 1203If 1204.Ev EDITOR 1205is null or unset, 1206.Xr ed 1 1207is used as the editor. 1208.It Fl l No (ell) 1209List the commands rather than invoking an editor on them. 1210The commands are written in the sequence indicated by 1211the first and last operands, as affected by 1212.Fl r , 1213with each command preceded by the command number. 1214.It Fl n 1215Suppress command numbers when listing with -l. 1216.It Fl r 1217Reverse the order of the commands listed (with 1218.Fl l ) 1219or edited (with neither 1220.Fl l 1221nor 1222.Fl s ) . 1223.It Fl s 1224Re-execute the command without invoking an editor. 1225.It first 1226.It last 1227Select the commands to list or edit. 1228The number of previous commands that 1229can be accessed are determined by the value of the 1230.Ev HISTSIZE 1231variable. 1232The value of first or last or both are one of the following: 1233.Bl -tag -width 5n 1234.It [+]number 1235A positive number representing a command number; command numbers can be 1236displayed with the 1237.Fl l 1238option. 1239.It Fl number 1240A negative decimal number representing the command that was executed 1241number of commands previously. 1242For example, \-1 is the immediately previous command. 1243.El 1244.It string 1245A string indicating the most recently entered command that begins with 1246that string. 1247If the old=new operand is not also specified with 1248.Fl s , 1249the string form of the first operand cannot contain an embedded equal sign. 1250.El 1251.Pp 1252The following environment variables affect the execution of fc: 1253.Bl -tag -width HISTSIZE 1254.It Ev FCEDIT 1255Name of the editor to use. 1256.It Ev HISTSIZE 1257The number of previous commands that are accessible. 1258.El 1259.It fg Op Ar job 1260Move the specified job or the current job to the foreground. 1261.It getopts Ar optstring var 1262The 1263.Tn POSIX 1264.Ic getopts 1265command, not to be confused with the 1266.Em Bell Labs 1267-derived 1268.Xr getopt 1 . 1269.Pp 1270The first argument should be a series of letters, each of which may be 1271optionally followed by a colon to indicate that the option requires an 1272argument. 1273The variable specified is set to the parsed option. 1274.Pp 1275The 1276.Ic getopts 1277command deprecates the older 1278.Xr getopt 1 1279utility due to its handling of arguments containing whitespace. 1280.Pp 1281The 1282.Ic getopts 1283builtin may be used to obtain options and their arguments 1284from a list of parameters. 1285When invoked, 1286.Ic getopts 1287places the value of the next option from the option string in the list in 1288the shell variable specified by 1289.Va var 1290and it's index in the shell variable 1291.Ev OPTIND . 1292When the shell is invoked, 1293.Ev OPTIND 1294is initialized to 1. 1295For each option that requires an argument, the 1296.Ic getopts 1297builtin will place it in the shell variable 1298.Ev OPTARG . 1299If an option is not allowed for in the 1300.Va optstring , 1301then 1302.Ev OPTARG 1303will be unset. 1304.Pp 1305.Va optstring 1306is a string of recognized option letters (see 1307.Xr getopt 3 ) . 1308If a letter is followed by a colon, the option is expected to have an 1309argument which may or may not be separated from it by white space. 1310If an option character is not found where expected, 1311.Ic getopts 1312will set the variable 1313.Va var 1314to a 1315.Dq ? ; 1316.Ic getopts 1317will then unset 1318.Ev OPTARG 1319and write output to standard error. 1320By specifying a colon as the first character of 1321.Va optstring 1322all errors will be ignored. 1323.Pp 1324A nonzero value is returned when the last option is reached. 1325If there are no remaining arguments, 1326.Ic getopts 1327will set 1328.Va var 1329to the special option, 1330.Dq -- , 1331otherwise, it will set 1332.Va var 1333to 1334.Dq ? . 1335.Pp 1336The following code fragment shows how one might process the arguments 1337for a command that can take the options 1338.Op a 1339and 1340.Op b , 1341and the option 1342.Op c , 1343which requires an argument. 1344.Pp 1345.Bd -literal -offset indent 1346while getopts abc: f 1347do 1348 case $f in 1349 a | b) flag=$f;; 1350 c) carg=$OPTARG;; 1351 \\?) echo $USAGE; exit 1;; 1352 esac 1353done 1354shift `expr $OPTIND - 1` 1355.Ed 1356.Pp 1357This code will accept any of the following as equivalent: 1358.Pp 1359.Bd -literal -offset indent 1360cmd \-acarg file file 1361cmd \-a \-c arg file file 1362cmd \-carg -a file file 1363cmd \-a \-carg \-\- file file 1364.Ed 1365.It hash Fl rv Ar command ... 1366The shell maintains a hash table which remembers the 1367locations of commands. 1368With no arguments whatsoever, 1369the 1370.Ic hash 1371command prints out the contents of this table. 1372Entries which have not been looked at since the last 1373.Ic cd 1374command are marked with an asterisk; it is possible for these entries 1375to be invalid. 1376.Pp 1377With arguments, the 1378.Ic hash 1379command removes the specified commands from the hash table (unless 1380they are functions) and then locates them. 1381With the 1382.Fl v 1383option, hash prints the locations of the commands as it finds them. 1384The 1385.Fl r 1386option causes the hash command to delete all the entries in the hash table 1387except for functions. 1388.It jobid Op Ar job 1389Print the process id's of the processes in the job. 1390If the 1391.Ar job 1392argument is omitted, the current job is used. 1393.It jobs 1394This command lists out all the background processes 1395which are children of the current shell process. 1396.It pwd 1397Print the current directory. 1398The builtin command may differ from the program of the same name because the 1399builtin command remembers what the current directory 1400is rather than recomputing it each time. 1401This makes it faster. 1402However, if the current directory is renamed, the builtin version of 1403.Ic pwd 1404will continue to print the old name for the directory. 1405.It Xo read Op Fl p Ar prompt 1406.Op Fl r 1407.Ar variable 1408.Op Ar ... 1409.Xc 1410The prompt is printed if the 1411.Fl p 1412option is specified and the standard input is a terminal. 1413Then a line is read from the standard input. 1414The trailing newline is deleted from the 1415line and the line is split as described in the section on word splitting 1416above, and the pieces are assigned to the variables in order. 1417If there are more pieces than variables, the remaining pieces 1418(along with the characters in 1419.Ev IFS 1420that separated them) are assigned to the last variable. 1421If there are more variables than pieces, 1422the remaining variables are assigned the null string. 1423The 1424.Ic read 1425builtin will indicate success unless EOF is encountered on input, in 1426which case failure is returned. 1427.Pp 1428By default, unless the 1429.Fl r 1430option is specified, the backslash 1431.Dq \e 1432acts as an escape character, causing the following character to be treated 1433literally. 1434If a backslash is followed by a newline, the backslash and the 1435newline will be deleted. 1436.It readonly Ar name ... 1437.It readonly Fl p 1438The specified names are marked as read only, so that they cannot be 1439subsequently modified or unset. 1440The shell allows the value of a variable 1441to be set at the same time it is marked read only by writing 1442.Pp 1443.Dl readonly name=value 1444.Pp 1445With no arguments the readonly command lists the names of all read only 1446variables. 1447With the 1448.Fl p 1449option specified the output will be formatted suitably for non-interactive use. 1450.Pp 1451.It Xo set 1452.Oo { 1453.Fl options | Cm +options | Cm -- } 1454.Oc Ar arg ... 1455.Xc 1456The 1457.Ic set 1458command performs three different functions. 1459.Pp 1460With no arguments, it lists the values of all shell variables. 1461.Pp 1462If options are given, it sets the specified option 1463flags, or clears them as described in the section called 1464.Sx Argument List Processing . 1465.Pp 1466The third use of the set command is to set the values of the shell's 1467positional parameters to the specified args. 1468To change the positional 1469parameters without changing any options, use 1470.Dq -- 1471as the first argument to set. 1472If no args are present, the set command 1473will clear all the positional parameters (equivalent to executing 1474.Dq shift $# . ) 1475.It setvar Ar variable Ar value 1476Assigns value to variable. 1477(In general it is better to write 1478variable=value rather than using 1479.Ic setvar . 1480.Ic setvar 1481is intended to be used in 1482functions that assign values to variables whose names are passed as 1483parameters.) 1484.It shift Op Ar n 1485Shift the positional parameters n times. 1486A 1487.Ic shift 1488sets the value of 1489.Va $1 1490to the value of 1491.Va $2 , 1492the value of 1493.Va $2 1494to the value of 1495.Va $3 , 1496and so on, decreasing 1497the value of 1498.Va $# 1499by one. 1500If there are zero positional parameters, 1501.Ic shift 1502does nothing. 1503.It Xo trap 1504.Op Fl l 1505.Xc 1506.It Xo trap 1507.Op Ar action 1508.Ar signal ... 1509.Xc 1510Cause the shell to parse and execute action when any of the specified 1511signals are received. 1512The signals are specified by signal number or as the name of the signal. 1513If 1514.Ar signal 1515is 1516.Li 0 , 1517the action is executed when the shell exits. 1518.Ar action 1519may be null, which cause the specified signals to be ignored. 1520With 1521.Ar action 1522omitted or set to `-' the specified signals are set to their default action. 1523When the shell forks off a subshell, it resets trapped (but not ignored) 1524signals to the default action. 1525The 1526.Ic trap 1527command has no effect on signals that were 1528ignored on entry to the shell. 1529Issuing 1530.Ic trap 1531with option 1532.Ar -l 1533will print a list of valid signal names. 1534.Ic trap 1535without any arguments cause it to write a list of signals and their 1536associated action to the standard output in a format that is suitable 1537as an input to the shell that achieves the same trapping results. 1538.Pp 1539Examples: 1540.Pp 1541.Dl trap 1542.Pp 1543List trapped signals and their corresponding action 1544.Pp 1545.Dl trap -l 1546.Pp 1547Print a list of valid signals 1548.Pp 1549.Dl trap '' SIGINT QUIT tstp 30 1550.Pp 1551Ignore signals INT QUIT TSTP USR1 1552.Pp 1553.Dl trap date INT 1554.Pp 1555Print date upon receiving signal INT 1556.It type Op Ar name ... 1557Interpret each name as a command and print the resolution of the command 1558search. 1559Possible resolutions are: 1560shell keyword, alias, shell builtin, 1561command, tracked alias and not found. 1562For aliases the alias expansion is 1563printed; for commands and tracked aliases the complete pathname of the 1564command is printed. 1565.It ulimit Xo 1566.Op Fl H \*(Ba Fl S 1567.Op Fl a \*(Ba Fl tfdscmlpn Op Ar value 1568.Xc 1569Inquire about or set the hard or soft limits on processes or set new 1570limits. 1571The choice between hard limit (which no process is allowed to 1572violate, and which may not be raised once it has been lowered) and soft 1573limit (which causes processes to be signaled but not necessarily killed, 1574and which may be raised) is made with these flags: 1575.Bl -tag -width Fl 1576.It Fl H 1577set or inquire about hard limits 1578.It Fl S 1579set or inquire about soft limits. 1580If neither 1581.Fl H 1582nor 1583.Fl S 1584is specified, the soft limit is displayed or both limits are set. 1585If both are specified, the last one wins. 1586.El 1587.Pp 1588.Bl -tag -width Fl 1589The limit to be interrogated or set, then, is chosen by specifying 1590any one of these flags: 1591.It Fl a 1592show all the current limits 1593.It Fl t 1594show or set the limit on CPU time (in seconds) 1595.It Fl f 1596show or set the limit on the largest file that can be created 1597(in 512-byte blocks) 1598.It Fl d 1599show or set the limit on the data segment size of a process (in kilobytes) 1600.It Fl s 1601show or set the limit on the stack size of a process (in kilobytes) 1602.It Fl c 1603show or set the limit on the largest core dump size that can be produced 1604(in 512-byte blocks) 1605.It Fl m 1606show or set the limit on the total physical memory that can be 1607in use by a process (in kilobytes) 1608.It Fl l 1609show or set the limit on how much memory a process can lock with 1610.Xr mlock 2 1611(in kilobytes) 1612.It Fl p 1613show or set the limit on the number of processes this user can 1614have at one time 1615.It Fl n 1616show or set the limit on the number files a process can have open at once 1617.El 1618.Pp 1619If none of these is specified, it is the limit on file size that is shown 1620or set. 1621If value is specified, the limit is set to that number; otherwise 1622the current limit is displayed. 1623.Pp 1624Limits of an arbitrary process can be displayed or set using the 1625.Xr sysctl 8 1626utility. 1627.Pp 1628.It umask Op Ar mask 1629Set the value of umask (see 1630.Xr umask 2 ) 1631to the specified octal value. 1632If the argument is omitted, the umask value is printed. 1633.It unalias Xo 1634.Op Fl a 1635.Op Ar name 1636.Xc 1637If 1638.Ar name 1639is specified, the shell removes that alias. 1640If 1641.Fl a 1642is specified, all aliases are removed. 1643.It unset Ar name ... 1644The specified variables and functions are unset and unexported. 1645If a given name corresponds to both a variable and a function, both 1646the variable and the function are unset. 1647.It wait Op Ar job 1648Wait for the specified job to complete and return the exit status of the 1649last process in the job. 1650If the argument is omitted, wait for all jobs to 1651complete and the return an exit status of zero. 1652.El 1653.Ss Command Line Editing 1654When 1655.Nm 1656is being used interactively from a terminal, the current command 1657and the command history (see 1658.Ic fc 1659in 1660.Sx Builtins ) 1661can be edited using vi-mode command-line editing. 1662This mode uses commands, described below, 1663similar to a subset of those described in the vi man page. 1664The command 1665.Ql set -o vi 1666enables vi-mode editing and place sh into vi insert mode. 1667With vi-mode 1668enabled, sh can be switched between insert mode and command mode. 1669The editor is not described in full here, but will be in a later document. 1670It's similar to vi: typing 1671.Aq ESC 1672will throw you into command VI command mode. 1673Hitting 1674.Aq return 1675while in command mode will pass the line to the shell. 1676.Sh EXIT STATUS 1677Errors that are detected by the shell, such as a syntax error, will cause the 1678shell to exit with a non-zero exit status. 1679If the shell is not an 1680interactive shell, the execution of the shell file will be aborted. 1681Otherwise 1682the shell will return the exit status of the last command executed, or 1683if the exit builtin is used with a numeric argument, it will return the 1684argument. 1685.Sh ENVIRONMENT 1686.Bl -tag -width MAILCHECK 1687.It Ev HOME 1688Set automatically by 1689.Xr login 1 1690from the user's login directory in the password file 1691.Pq Xr passwd 4 . 1692This environment variable also functions as the default argument for the 1693cd builtin. 1694.It Ev PATH 1695The default search path for executables. 1696See the above section 1697.Sx Path Search . 1698.It Ev CDPATH 1699The search path used with the cd builtin. 1700.It Ev MAIL 1701The name of a mail file, that will be checked for the arrival of new mail. 1702Overridden by 1703.Ev MAILPATH . 1704.It Ev MAILCHECK 1705The frequency in seconds that the shell checks for the arrival of mail 1706in the files specified by the 1707.Ev MAILPATH 1708or the 1709.Ev MAIL 1710file. 1711If set to 0, the check will occur at each prompt. 1712.It Ev MAILPATH 1713A colon 1714.Dq \&: 1715separated list of file names, for the shell to check for incoming mail. 1716This environment setting overrides the 1717.Ev MAIL 1718setting. 1719There is a maximum of 10 mailboxes that can be monitored at once. 1720.It Ev PS1 1721The primary prompt string, which defaults to 1722.Dq $ \ , 1723unless you are the superuser, in which case it defaults to 1724.Dq # \ . 1725.It Ev PS2 1726The secondary prompt string, which defaults to 1727.Dq \*[Gt] \ . 1728.It Ev IFS 1729Input Field Separators. 1730This is normally set to 1731.Aq space , 1732.Aq tab , 1733and 1734.Aq newline . 1735See the 1736.Sx White Space Splitting 1737section for more details. 1738.It Ev TERM 1739The default terminal setting for the shell. 1740This is inherited by 1741children of the shell, and is used in the history editing modes. 1742.It Ev HISTSIZE 1743The number of lines in the history buffer for the shell. 1744.El 1745.Sh FILES 1746.Bl -item -width HOMEprofilexxxx 1747.It 1748.Pa $HOME/.profile 1749.It 1750.Pa /etc/profile 1751.El 1752.Sh SEE ALSO 1753.Xr csh 1 , 1754.Xr getopt 1 , 1755.Xr ksh 1 , 1756.Xr login 1 , 1757.Xr test 1 , 1758.Xr getopt 3 , 1759.Xr passwd 5 , 1760.\" .Xr profile 4 , 1761.Xr environ 7 , 1762.Xr sysctl 8 1763.Sh HISTORY 1764A 1765.Nm 1766command appeared in 1767.At v1 . 1768It was, however, unmaintainable so we wrote this one. 1769.Sh BUGS 1770Setuid shell scripts should be avoided at all costs, as they are a 1771significant security risk. 1772