1.\"- 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.\" 4. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95 33.\" $FreeBSD$ 34.\" 35.Dd January 3, 2014 36.Dt SH 1 37.Os 38.Sh NAME 39.Nm sh 40.Nd command interpreter (shell) 41.Sh SYNOPSIS 42.Nm 43.Op Fl /+abCEefIimnPpTuVvx 44.Op Fl /+o Ar longname 45.Oo 46.Ar script 47.Op Ar arg ... 48.Oc 49.Nm 50.Op Fl /+abCEefIimnPpTuVvx 51.Op Fl /+o Ar longname 52.Fl c Ar string 53.Oo 54.Ar name 55.Op Ar arg ... 56.Oc 57.Nm 58.Op Fl /+abCEefIimnPpTuVvx 59.Op Fl /+o Ar longname 60.Fl s 61.Op Ar arg ... 62.Sh DESCRIPTION 63The 64.Nm 65utility is the standard command interpreter for the system. 66The current version of 67.Nm 68is close to the 69.St -p1003.1 70specification for the shell. 71It only supports features 72designated by 73.Tn POSIX , 74plus a few Berkeley extensions. 75This man page is not intended to be a tutorial nor a complete 76specification of the shell. 77.Ss Overview 78The shell is a command that reads lines from 79either a file or the terminal, interprets them, and 80generally executes other commands. 81It is the program that is started when a user logs into the system, 82although a user can select a different shell with the 83.Xr chsh 1 84command. 85The shell 86implements a language that has flow control constructs, 87a macro facility that provides a variety of features in 88addition to data storage, along with built-in history and line 89editing capabilities. 90It incorporates many features to 91aid interactive use and has the advantage that the interpretative 92language is common to both interactive and non-interactive 93use (shell scripts). 94That is, commands can be typed directly 95to the running shell or can be put into a file, 96which can be executed directly by the shell. 97.Ss Invocation 98.\" 99.\" XXX This next sentence is incredibly confusing. 100.\" 101If no arguments are present and if the standard input of the shell 102is connected to a terminal 103(or if the 104.Fl i 105option is set), 106the shell is considered an interactive shell. 107An interactive shell 108generally prompts before each command and handles programming 109and command errors differently (as described below). 110When first starting, the shell inspects argument 0, and 111if it begins with a dash 112.Pq Ql - , 113the shell is also considered a login shell. 114This is normally done automatically by the system 115when the user first logs in. 116A login shell first reads commands 117from the files 118.Pa /etc/profile 119and then 120.Pa .profile 121in a user's home directory, 122if they exist. 123If the environment variable 124.Ev ENV 125is set on entry to a shell, or is set in the 126.Pa .profile 127of a login shell, the shell then subjects its value to parameter expansion 128and arithmetic expansion and reads commands from the named file. 129Therefore, a user should place commands that are to be executed only 130at login time in the 131.Pa .profile 132file, and commands that are executed for every shell inside the 133.Ev ENV 134file. 135The user can set the 136.Ev ENV 137variable to some file by placing the following line in the file 138.Pa .profile 139in the home directory, 140substituting for 141.Pa .shrc 142the filename desired: 143.Pp 144.Dl "ENV=$HOME/.shrc; export ENV" 145.Pp 146The first non-option argument specified on the command line 147will be treated as the 148name of a file from which to read commands (a shell script), and 149the remaining arguments are set as the positional parameters 150of the shell 151.Li ( $1 , $2 , 152etc.). 153Otherwise, the shell reads commands 154from its standard input. 155.Pp 156Unlike older versions of 157.Nm 158the 159.Ev ENV 160script is only sourced on invocation of interactive shells. 161This 162closes a well-known, and sometimes easily exploitable security 163hole related to poorly thought out 164.Ev ENV 165scripts. 166.Ss Argument List Processing 167All of the single letter options to 168.Nm 169have a corresponding long name, 170with the exception of 171.Fl c 172and 173.Fl /+o . 174These long names are provided next to the single letter options 175in the descriptions below. 176The long name for an option may be specified as an argument to the 177.Fl /+o 178option of 179.Nm . 180Once the shell is running, 181the long name for an option may be specified as an argument to the 182.Fl /+o 183option of the 184.Ic set 185built-in command 186(described later in the section called 187.Sx Built-in Commands ) . 188Introducing an option with a dash 189.Pq Ql - 190enables the option, 191while using a plus 192.Pq Ql + 193disables the option. 194A 195.Dq Li -- 196or plain 197.Ql - 198will stop option processing and will force the remaining 199words on the command line to be treated as arguments. 200The 201.Fl /+o 202and 203.Fl c 204options do not have long names. 205They take arguments and are described after the single letter options. 206.Bl -tag -width indent 207.It Fl a Li allexport 208Flag variables for export when assignments are made to them. 209.It Fl b Li notify 210Enable asynchronous notification of background job 211completion. 212(UNIMPLEMENTED) 213.It Fl C Li noclobber 214Do not overwrite existing files with 215.Ql > . 216.It Fl E Li emacs 217Enable the built-in 218.Xr emacs 1 219command line editor (disables the 220.Fl V 221option if it has been set; 222set automatically when interactive on terminals). 223.It Fl e Li errexit 224Exit immediately if any untested command fails in non-interactive mode. 225The exit status of a command is considered to be 226explicitly tested if the command is part of the list used to control 227an 228.Ic if , elif , while , 229or 230.Ic until ; 231if the command is the left 232hand operand of an 233.Dq Li && 234or 235.Dq Li || 236operator; or if the command is a pipeline preceded by the 237.Ic !\& 238keyword. 239If a shell function is executed and its exit status is explicitly 240tested, all commands of the function are considered to be tested as 241well. 242.Pp 243It is recommended to check for failures explicitly 244instead of relying on 245.Fl e 246because it tends to behave in unexpected ways, 247particularly in larger scripts. 248.It Fl f Li noglob 249Disable pathname expansion. 250.It Fl h Li trackall 251A do-nothing option for 252.Tn POSIX 253compliance. 254.It Fl I Li ignoreeof 255Ignore 256.Dv EOF Ap s 257from input when in interactive mode. 258.It Fl i Li interactive 259Force the shell to behave interactively. 260.It Fl m Li monitor 261Turn on job control (set automatically when interactive). 262.It Fl n Li noexec 263If not interactive, read commands but do not 264execute them. 265This is useful for checking the 266syntax of shell scripts. 267.It Fl P Li physical 268Change the default for the 269.Ic cd 270and 271.Ic pwd 272commands from 273.Fl L 274(logical directory layout) 275to 276.Fl P 277(physical directory layout). 278.It Fl p Li privileged 279Turn on privileged mode. 280This mode is enabled on startup 281if either the effective user or group ID is not equal to the 282real user or group ID. 283Turning this mode off sets the 284effective user and group IDs to the real user and group IDs. 285When this mode is enabled for interactive shells, the file 286.Pa /etc/suid_profile 287is sourced instead of 288.Pa ~/.profile 289after 290.Pa /etc/profile 291is sourced, and the contents of the 292.Ev ENV 293variable are ignored. 294.It Fl s Li stdin 295Read commands from standard input (set automatically 296if no file arguments are present). 297This option has 298no effect when set after the shell has already started 299running (i.e., when set with the 300.Ic set 301command). 302.It Fl T Li trapsasync 303When waiting for a child, execute traps immediately. 304If this option is not set, 305traps are executed after the child exits, 306as specified in 307.St -p1003.2 . 308This nonstandard option is useful for putting guarding shells around 309children that block signals. 310The surrounding shell may kill the child 311or it may just return control to the tty and leave the child alone, 312like this: 313.Bd -literal -offset indent 314sh -T -c "trap 'exit 1' 2 ; some-blocking-program" 315.Ed 316.It Fl u Li nounset 317Write a message to standard error when attempting 318to expand a variable, a positional parameter or 319the special parameter 320.Va \&! 321that is not set, and if the 322shell is not interactive, exit immediately. 323.It Fl V Li vi 324Enable the built-in 325.Xr vi 1 326command line editor (disables 327.Fl E 328if it has been set). 329.It Fl v Li verbose 330The shell writes its input to standard error 331as it is read. 332Useful for debugging. 333.It Fl x Li xtrace 334Write each command 335(preceded by the value of the 336.Va PS4 337variable subjected to parameter expansion and arithmetic expansion) 338to standard error before it is executed. 339Useful for debugging. 340.El 341.Pp 342The 343.Fl c 344option causes the commands to be read from the 345.Ar string 346operand instead of from the standard input. 347Keep in mind that this option only accepts a single string as its 348argument, hence multi-word strings must be quoted. 349.Pp 350The 351.Fl /+o 352option takes as its only argument the long name of an option 353to be enabled or disabled. 354For example, the following two invocations of 355.Nm 356both enable the built-in 357.Xr emacs 1 358command line editor: 359.Bd -literal -offset indent 360set -E 361set -o emacs 362.Ed 363.Pp 364If used without an argument, the 365.Fl o 366option displays the current option settings in a human-readable format. 367If 368.Cm +o 369is used without an argument, the current option settings are output 370in a format suitable for re-input into the shell. 371.Ss Lexical Structure 372The shell reads input in terms of lines from a file and breaks 373it up into words at whitespace (blanks and tabs), and at 374certain sequences of 375characters called 376.Dq operators , 377which are special to the shell. 378There are two types of operators: control operators and 379redirection operators (their meaning is discussed later). 380The following is a list of valid operators: 381.Bl -tag -width indent 382.It Control operators: 383.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 384.It Li & Ta Li && Ta Li \&( Ta Li \&) Ta Li \en 385.It Li ;; Ta Li ;& Ta Li \&; Ta Li \&| Ta Li || 386.El 387.It Redirection operators: 388.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 389.It Li < Ta Li > Ta Li << Ta Li >> Ta Li <> 390.It Li <& Ta Li >& Ta Li <<- Ta Li >| Ta \& 391.El 392.El 393.Pp 394The character 395.Ql # 396introduces a comment if used at the beginning of a word. 397The word starting with 398.Ql # 399and the rest of the line are ignored. 400.Pp 401.Tn ASCII 402.Dv NUL 403characters (character code 0) are not allowed in shell input. 404.Ss Quoting 405Quoting is used to remove the special meaning of certain characters 406or words to the shell, such as operators, whitespace, keywords, 407or alias names. 408.Pp 409There are four types of quoting: matched single quotes, 410dollar-single quotes, 411matched double quotes, and backslash. 412.Bl -tag -width indent 413.It Single Quotes 414Enclosing characters in single quotes preserves the literal 415meaning of all the characters (except single quotes, making 416it impossible to put single-quotes in a single-quoted string). 417.It Dollar-Single Quotes 418Enclosing characters between 419.Li $' 420and 421.Li ' 422preserves the literal meaning of all characters 423except backslashes and single quotes. 424A backslash introduces a C-style escape sequence: 425.Bl -tag -width xUnnnnnnnn 426.It \ea 427Alert (ring the terminal bell) 428.It \eb 429Backspace 430.It \ec Ns Ar c 431The control character denoted by 432.Li ^ Ns Ar c 433in 434.Xr stty 1 . 435If 436.Ar c 437is a backslash, it must be doubled. 438.It \ee 439The ESC character 440.Tn ( ASCII 4410x1b) 442.It \ef 443Formfeed 444.It \en 445Newline 446.It \er 447Carriage return 448.It \et 449Horizontal tab 450.It \ev 451Vertical tab 452.It \e\e 453Literal backslash 454.It \e\&' 455Literal single-quote 456.It \e\&" 457Literal double-quote 458.It \e Ns Ar nnn 459The byte whose octal value is 460.Ar nnn 461(one to three digits) 462.It \ex Ns Ar nn 463The byte whose hexadecimal value is 464.Ar nn 465(one or more digits only the last two of which are used) 466.It \eu Ns Ar nnnn 467The Unicode code point 468.Ar nnnn 469(four hexadecimal digits) 470.It \eU Ns Ar nnnnnnnn 471The Unicode code point 472.Ar nnnnnnnn 473(eight hexadecimal digits) 474.El 475.Pp 476The sequences for Unicode code points are currently only useful with 477UTF-8 locales. 478They reject code point 0 and UTF-16 surrogates. 479.Pp 480If an escape sequence would produce a byte with value 0, 481that byte and the rest of the string until the matching single-quote 482are ignored. 483.Pp 484Any other string starting with a backslash is an error. 485.It Double Quotes 486Enclosing characters within double quotes preserves the literal 487meaning of all characters except dollar sign 488.Pq Ql $ , 489backquote 490.Pq Ql ` , 491and backslash 492.Pq Ql \e . 493The backslash inside double quotes is historically weird. 494It remains literal unless it precedes the following characters, 495which it serves to quote: 496.Pp 497.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 498.It Li $ Ta Li ` Ta Li \&" Ta Li \e Ta Li \en 499.El 500.It Backslash 501A backslash preserves the literal meaning of the following 502character, with the exception of the newline character 503.Pq Ql \en . 504A backslash preceding a newline is treated as a line continuation. 505.El 506.Ss Keywords 507Keywords or reserved words are words that have special meaning to the 508shell and are recognized at the beginning of a line and 509after a control operator. 510The following are keywords: 511.Bl -column "doneXX" "elifXX" "elseXX" "untilXX" "whileX" -offset center 512.It Li \&! Ta { Ta } Ta Ic case Ta Ic do 513.It Ic done Ta Ic elif Ta Ic else Ta Ic esac Ta Ic fi 514.It Ic for Ta Ic if Ta Ic then Ta Ic until Ta Ic while 515.El 516.Ss Aliases 517An alias is a name and corresponding value set using the 518.Ic alias 519built-in command. 520Wherever the command word of a simple command may occur, 521and after checking for keywords if a keyword may occur, the shell 522checks the word to see if it matches an alias. 523If it does, it replaces it in the input stream with its value. 524For example, if there is an alias called 525.Dq Li lf 526with the value 527.Dq Li "ls -F" , 528then the input 529.Pp 530.Dl "lf foobar" 531.Pp 532would become 533.Pp 534.Dl "ls -F foobar" 535.Pp 536Aliases provide a convenient way for naive users to 537create shorthands for commands without having to learn how 538to create functions with arguments. 539Using aliases in scripts is discouraged 540because the command that defines them must be executed 541before the code that uses them is parsed. 542This is fragile and not portable. 543.Pp 544An alias name may be escaped in a command line, so that it is not 545replaced by its alias value, by using quoting characters within or 546adjacent to the alias name. 547This is most often done by prefixing 548an alias name with a backslash to execute a function, built-in, or 549normal program with the same name. 550See the 551.Sx Quoting 552subsection. 553.Ss Commands 554The shell interprets the words it reads according to a 555language, the specification of which is outside the scope 556of this man page (refer to the BNF in the 557.St -p1003.2 558document). 559Essentially though, a line is read and if 560the first word of the line (or after a control operator) 561is not a keyword, then the shell has recognized a 562simple command. 563Otherwise, a complex command or some 564other special construct may have been recognized. 565.Ss Simple Commands 566If a simple command has been recognized, the shell performs 567the following actions: 568.Bl -enum 569.It 570Leading words of the form 571.Dq Li name=value 572are stripped off and assigned to the environment of 573the simple command. 574Redirection operators and 575their arguments (as described below) are stripped 576off and saved for processing. 577.It 578The remaining words are expanded as described in 579the section called 580.Sx Word Expansions , 581and the first remaining word is considered the command 582name and the command is located. 583The remaining 584words are considered the arguments of the command. 585If no command name resulted, then the 586.Dq Li name=value 587variable assignments recognized in 1) affect the 588current shell. 589.It 590Redirections are performed as described in 591the next section. 592.El 593.Ss Redirections 594Redirections are used to change where a command reads its input 595or sends its output. 596In general, redirections open, close, or 597duplicate an existing reference to a file. 598The overall format 599used for redirection is: 600.Pp 601.D1 Oo Ar n Oc Ar redir-op file 602.Pp 603The 604.Ar redir-op 605is one of the redirection operators mentioned 606previously. 607The following gives some examples of how these 608operators can be used. 609Note that stdin and stdout are commonly used abbreviations 610for standard input and standard output respectively. 611.Bl -tag -width "1234567890XX" -offset indent 612.It Oo Ar n Oc Ns Li > Ar file 613redirect stdout (or file descriptor 614.Ar n ) 615to 616.Ar file 617.It Oo Ar n Oc Ns Li >| Ar file 618same as above, but override the 619.Fl C 620option 621.It Oo Ar n Oc Ns Li >> Ar file 622append stdout (or file descriptor 623.Ar n ) 624to 625.Ar file 626.It Oo Ar n Oc Ns Li < Ar file 627redirect stdin (or file descriptor 628.Ar n ) 629from 630.Ar file 631.It Oo Ar n Oc Ns Li <> Ar file 632redirect stdin (or file descriptor 633.Ar n ) 634to and from 635.Ar file 636.It Oo Ar n1 Oc Ns Li <& Ns Ar n2 637duplicate stdin (or file descriptor 638.Ar n1 ) 639from file descriptor 640.Ar n2 641.It Oo Ar n Oc Ns Li <&- 642close stdin (or file descriptor 643.Ar n ) 644.It Oo Ar n1 Oc Ns Li >& Ns Ar n2 645duplicate stdout (or file descriptor 646.Ar n1 ) 647to file descriptor 648.Ar n2 649.It Oo Ar n Oc Ns Li >&- 650close stdout (or file descriptor 651.Ar n ) 652.El 653.Pp 654The following redirection is often called a 655.Dq here-document . 656.Bd -unfilled -offset indent 657.Oo Ar n Oc Ns Li << Ar delimiter 658.Ar here-doc-text 659.Ar ... 660.Ar delimiter 661.Ed 662.Pp 663All the text on successive lines up to the delimiter is 664saved away and made available to the command on standard 665input, or file descriptor 666.Ar n 667if it is specified. 668If the 669.Ar delimiter 670as specified on the initial line is quoted, then the 671.Ar here-doc-text 672is treated literally, otherwise the text is subjected to 673parameter expansion, command substitution, and arithmetic 674expansion (as described in the section on 675.Sx Word Expansions ) . 676If the operator is 677.Dq Li <<- 678instead of 679.Dq Li << , 680then leading tabs 681in the 682.Ar here-doc-text 683are stripped. 684.Ss Search and Execution 685There are three types of commands: shell functions, 686built-in commands, and normal programs. 687The command is searched for (by name) in that order. 688The three types of commands are all executed in a different way. 689.Pp 690When a shell function is executed, all of the shell positional 691parameters (except 692.Li $0 , 693which remains unchanged) are 694set to the arguments of the shell function. 695The variables which are explicitly placed in the environment of 696the command (by placing assignments to them before the 697function name) are made local to the function and are set 698to the values given. 699Then the command given in the function definition is executed. 700The positional parameters are restored to their original values 701when the command completes. 702This all occurs within the current shell. 703.Pp 704Shell built-in commands are executed internally to the shell, without 705spawning a new process. 706There are two kinds of built-in commands: regular and special. 707Assignments before special builtins persist after they finish 708executing and assignment errors, redirection errors and certain 709operand errors cause a script to be aborted. 710Special builtins cannot be overridden with a function. 711Both regular and special builtins can affect the shell in ways 712normal programs cannot. 713.Pp 714Otherwise, if the command name does not match a function 715or built-in command, the command is searched for as a normal 716program in the file system (as described in the next section). 717When a normal program is executed, the shell runs the program, 718passing the arguments and the environment to the program. 719If the program is not a normal executable file 720(i.e., if it does not begin with the 721.Dq "magic number" 722whose 723.Tn ASCII 724representation is 725.Dq Li #! , 726resulting in an 727.Er ENOEXEC 728return value from 729.Xr execve 2 ) 730but appears to be a text file, 731the shell will run a new instance of 732.Nm 733to interpret it. 734.Pp 735Note that previous versions of this document 736and the source code itself misleadingly and sporadically 737refer to a shell script without a magic number 738as a 739.Dq "shell procedure" . 740.Ss Path Search 741When locating a command, the shell first looks to see if 742it has a shell function by that name. 743Then it looks for a 744built-in command by that name. 745If a built-in command is not found, 746one of two things happen: 747.Bl -enum 748.It 749Command names containing a slash are simply executed without 750performing any searches. 751.It 752The shell searches each entry in the 753.Va PATH 754variable 755in turn for the command. 756The value of the 757.Va PATH 758variable should be a series of 759entries separated by colons. 760Each entry consists of a 761directory name. 762The current directory 763may be indicated implicitly by an empty directory name, 764or explicitly by a single period. 765.El 766.Ss Command Exit Status 767Each command has an exit status that can influence the behavior 768of other shell commands. 769The paradigm is that a command exits 770with zero for normal or success, and non-zero for failure, 771error, or a false indication. 772The man page for each command 773should indicate the various exit codes and what they mean. 774Additionally, the built-in commands return exit codes, as does 775an executed shell function. 776.Pp 777If a command is terminated by a signal, its exit status is 128 plus 778the signal number. 779Signal numbers are defined in the header file 780.In sys/signal.h . 781.Ss Complex Commands 782Complex commands are combinations of simple commands 783with control operators or keywords, together creating a larger complex 784command. 785More generally, a command is one of the following: 786.Bl -item -offset indent 787.It 788simple command 789.It 790pipeline 791.It 792list or compound-list 793.It 794compound command 795.It 796function definition 797.El 798.Pp 799Unless otherwise stated, the exit status of a command is 800that of the last simple command executed by the command. 801.Ss Pipelines 802A pipeline is a sequence of one or more commands separated 803by the control operator 804.Ql \&| . 805The standard output of all but 806the last command is connected to the standard input 807of the next command. 808The standard output of the last 809command is inherited from the shell, as usual. 810.Pp 811The format for a pipeline is: 812.Pp 813.D1 Oo Li \&! Oc Ar command1 Op Li \&| Ar command2 ... 814.Pp 815The standard output of 816.Ar command1 817is connected to the standard input of 818.Ar command2 . 819The standard input, standard output, or 820both of a command is considered to be assigned by the 821pipeline before any redirection specified by redirection 822operators that are part of the command. 823.Pp 824Note that unlike some other shells, 825.Nm 826executes each process in a pipeline with more than one command 827in a subshell environment and as a child of the 828.Nm 829process. 830.Pp 831If the pipeline is not in the background (discussed later), 832the shell waits for all commands to complete. 833.Pp 834If the keyword 835.Ic !\& 836does not precede the pipeline, the 837exit status is the exit status of the last command specified 838in the pipeline. 839Otherwise, the exit status is the logical 840NOT of the exit status of the last command. 841That is, if 842the last command returns zero, the exit status is 1; if 843the last command returns greater than zero, the exit status 844is zero. 845.Pp 846Because pipeline assignment of standard input or standard 847output or both takes place before redirection, it can be 848modified by redirection. 849For example: 850.Pp 851.Dl "command1 2>&1 | command2" 852.Pp 853sends both the standard output and standard error of 854.Ar command1 855to the standard input of 856.Ar command2 . 857.Pp 858A 859.Ql \&; 860or newline terminator causes the preceding 861AND-OR-list 862(described below in the section called 863.Sx Short-Circuit List Operators ) 864to be executed sequentially; 865an 866.Ql & 867causes asynchronous execution of the preceding AND-OR-list. 868.Ss Background Commands (&) 869If a command is terminated by the control operator ampersand 870.Pq Ql & , 871the shell executes the command in a subshell environment (see 872.Sx Grouping Commands Together 873below) and asynchronously; 874the shell does not wait for the command to finish 875before executing the next command. 876.Pp 877The format for running a command in background is: 878.Pp 879.D1 Ar command1 Li & Op Ar command2 Li & Ar ... 880.Pp 881If the shell is not interactive, the standard input of an 882asynchronous command is set to 883.Pa /dev/null . 884.Ss Lists (Generally Speaking) 885A list is a sequence of zero or more commands separated by 886newlines, semicolons, or ampersands, 887and optionally terminated by one of these three characters. 888The commands in a 889list are executed in the order they are written. 890If command is followed by an ampersand, the shell starts the 891command and immediately proceeds onto the next command; 892otherwise it waits for the command to terminate before 893proceeding to the next one. 894.Ss Short-Circuit List Operators 895.Dq Li && 896and 897.Dq Li || 898are AND-OR list operators. 899.Dq Li && 900executes the first command, and then executes the second command 901if the exit status of the first command is zero. 902.Dq Li || 903is similar, but executes the second command if the exit 904status of the first command is nonzero. 905.Dq Li && 906and 907.Dq Li || 908both have the same priority. 909.Ss Flow-Control Constructs (if, while, for, case) 910The syntax of the 911.Ic if 912command is: 913.Bd -unfilled -offset indent -compact 914.Ic if Ar list 915.Ic then Ar list 916.Oo Ic elif Ar list 917.Ic then Ar list Oc Ar ... 918.Op Ic else Ar list 919.Ic fi 920.Ed 921.Pp 922The syntax of the 923.Ic while 924command is: 925.Bd -unfilled -offset indent -compact 926.Ic while Ar list 927.Ic do Ar list 928.Ic done 929.Ed 930.Pp 931The two lists are executed repeatedly while the exit status of the 932first list is zero. 933The 934.Ic until 935command is similar, but has the word 936.Ic until 937in place of 938.Ic while , 939which causes it to 940repeat until the exit status of the first list is zero. 941.Pp 942The syntax of the 943.Ic for 944command is: 945.Bd -unfilled -offset indent -compact 946.Ic for Ar variable Op Ic in Ar word ... 947.Ic do Ar list 948.Ic done 949.Ed 950.Pp 951If 952.Ic in 953and the following words are omitted, 954.Ic in Li \&"$@\&" 955is used instead. 956The words are expanded, and then the list is executed 957repeatedly with the variable set to each word in turn. 958The 959.Ic do 960and 961.Ic done 962commands may be replaced with 963.Ql { 964and 965.Ql } . 966.Pp 967The syntax of the 968.Ic break 969and 970.Ic continue 971commands is: 972.D1 Ic break Op Ar num 973.D1 Ic continue Op Ar num 974.Pp 975The 976.Ic break 977command terminates the 978.Ar num 979innermost 980.Ic for 981or 982.Ic while 983loops. 984The 985.Ic continue 986command continues with the next iteration of the innermost loop. 987These are implemented as special built-in commands. 988.Pp 989The syntax of the 990.Ic case 991command is: 992.Bd -unfilled -offset indent -compact 993.Ic case Ar word Ic in 994.Ar pattern Ns Li ) Ar list Li ;; 995.Ar ... 996.Ic esac 997.Ed 998.Pp 999The pattern can actually be one or more patterns 1000(see 1001.Sx Shell Patterns 1002described later), 1003separated by 1004.Ql \&| 1005characters. 1006Tilde expansion, parameter expansion, command substitution, 1007arithmetic expansion and quote removal are applied to the word. 1008Then, each pattern is expanded in turn using tilde expansion, 1009parameter expansion, command substitution and arithmetic expansion and 1010the expanded form of the word is checked against it. 1011If a match is found, the corresponding list is executed. 1012If the selected list is terminated by the control operator 1013.Ql ;& 1014instead of 1015.Ql ;; , 1016execution continues with the next list, 1017continuing until a list terminated with 1018.Ql ;; 1019or the end of the 1020.Ic case 1021command. 1022The exit code of the 1023.Ic case 1024command is the exit code of the last command executed in the list or 1025zero if no patterns were matched. 1026.Ss Grouping Commands Together 1027Commands may be grouped by writing either 1028.Pp 1029.D1 Li \&( Ns Ar list Ns Li \%) 1030.Pp 1031or 1032.Pp 1033.D1 Li { Ar list Ns Li \&; } 1034.Pp 1035The first form executes the commands in a subshell environment. 1036A subshell environment has its own copy of: 1037.Bl -enum 1038.It 1039The current working directory as set by 1040.Ic cd . 1041.It 1042The file creation mask as set by 1043.Ic umask . 1044.It 1045Resource limits as set by 1046.Ic ulimit . 1047.It 1048References to open files. 1049.It 1050Traps as set by 1051.Ic trap . 1052.It 1053Known jobs. 1054.It 1055Positional parameters and variables. 1056.It 1057Shell options. 1058.It 1059Shell functions. 1060.It 1061Shell aliases. 1062.El 1063.Pp 1064These are copied from the parent shell environment, 1065except that trapped (but not ignored) signals are reset to the default action 1066and known jobs are cleared. 1067Any changes do not affect the parent shell environment. 1068.Pp 1069A subshell environment may be implemented as a child process or differently. 1070If job control is enabled in an interactive shell, 1071commands grouped in parentheses can be suspended and continued as a unit. 1072.Pp 1073For compatibility with other shells, 1074two open parentheses in sequence should be separated by whitespace. 1075.Pp 1076The second form never forks another shell, 1077so it is slightly more efficient. 1078Grouping commands together this way allows the user to 1079redirect their output as though they were one program: 1080.Bd -literal -offset indent 1081{ echo -n "hello"; echo " world"; } > greeting 1082.Ed 1083.Ss Functions 1084The syntax of a function definition is 1085.Pp 1086.D1 Ar name Li \&( \&) Ar command 1087.Pp 1088A function definition is an executable statement; when 1089executed it installs a function named 1090.Ar name 1091and returns an 1092exit status of zero. 1093The 1094.Ar command 1095is normally a list 1096enclosed between 1097.Ql { 1098and 1099.Ql } . 1100.Pp 1101Variables may be declared to be local to a function by 1102using the 1103.Ic local 1104command. 1105This should appear as the first statement of a function, 1106and the syntax is: 1107.Pp 1108.D1 Ic local Oo Ar variable ... Oc Op Fl 1109.Pp 1110The 1111.Ic local 1112command is implemented as a built-in command. 1113.Pp 1114When a variable is made local, it inherits the initial 1115value and exported and readonly flags from the variable 1116with the same name in the surrounding scope, if there is 1117one. 1118Otherwise, the variable is initially unset. 1119The shell 1120uses dynamic scoping, so that if the variable 1121.Va x 1122is made local to function 1123.Em f , 1124which then calls function 1125.Em g , 1126references to the variable 1127.Va x 1128made inside 1129.Em g 1130will refer to the variable 1131.Va x 1132declared inside 1133.Em f , 1134not to the global variable named 1135.Va x . 1136.Pp 1137The only special parameter that can be made local is 1138.Ql - . 1139Making 1140.Ql - 1141local causes any shell options that are 1142changed via the 1143.Ic set 1144command inside the function to be 1145restored to their original values when the function 1146returns. 1147.Pp 1148The syntax of the 1149.Ic return 1150command is 1151.Pp 1152.D1 Ic return Op Ar exitstatus 1153.Pp 1154It terminates the current executional scope, returning from the closest 1155nested function or sourced script; 1156if no function or sourced script is being executed, 1157it exits the shell instance. 1158The 1159.Ic return 1160command is implemented as a special built-in command. 1161.Ss Variables and Parameters 1162The shell maintains a set of parameters. 1163A parameter 1164denoted by a name is called a variable. 1165When starting up, 1166the shell turns all the environment variables into shell 1167variables. 1168New variables can be set using the form 1169.Pp 1170.D1 Ar name Ns = Ns Ar value 1171.Pp 1172Variables set by the user must have a name consisting solely 1173of alphabetics, numerics, and underscores. 1174The first letter of a variable name must not be numeric. 1175A parameter can also be denoted by a number 1176or a special character as explained below. 1177.Pp 1178Assignments are expanded differently from other words: 1179tilde expansion is also performed after the equals sign and after any colon 1180and usernames are also terminated by colons, 1181and field splitting and pathname expansion are not performed. 1182.Pp 1183This special expansion applies not only to assignments that form a simple 1184command by themselves or precede a command word, 1185but also to words passed to the 1186.Ic export , 1187.Ic local 1188or 1189.Ic readonly 1190built-in commands that have this form. 1191For this, the builtin's name must be literal 1192(not the result of an expansion) 1193and may optionally be preceded by one or more literal instances of 1194.Ic command 1195without options. 1196.Ss Positional Parameters 1197A positional parameter is a parameter denoted by a number greater than zero. 1198The shell sets these initially to the values of its command line 1199arguments that follow the name of the shell script. 1200The 1201.Ic set 1202built-in command can also be used to set or reset them. 1203.Ss Special Parameters 1204Special parameters are parameters denoted by a single special character 1205or the digit zero. 1206They are shown in the following list, exactly as they would appear in input 1207typed by the user or in the source of a shell script. 1208.Bl -hang 1209.It Li $* 1210Expands to the positional parameters, starting from one. 1211When 1212the expansion occurs within a double-quoted string 1213it expands to a single field with the value of each parameter 1214separated by the first character of the 1215.Va IFS 1216variable, 1217or by a space if 1218.Va IFS 1219is unset. 1220.It Li $@ 1221Expands to the positional parameters, starting from one. 1222When 1223the expansion occurs within double-quotes, each positional 1224parameter expands as a separate argument. 1225If there are no positional parameters, the 1226expansion of 1227.Li @ 1228generates zero arguments, even when 1229.Li @ 1230is double-quoted. 1231What this basically means, for example, is 1232if 1233.Li $1 1234is 1235.Dq Li abc 1236and 1237.Li $2 1238is 1239.Dq Li "def ghi" , 1240then 1241.Li \&"$@\&" 1242expands to 1243the two arguments: 1244.Bd -literal -offset indent 1245"abc" "def ghi" 1246.Ed 1247.It Li $# 1248Expands to the number of positional parameters. 1249.It Li $? 1250Expands to the exit status of the most recent pipeline. 1251.It Li $- 1252(hyphen) Expands to the current option flags (the single-letter 1253option names concatenated into a string) as specified on 1254invocation, by the 1255.Ic set 1256built-in command, or implicitly 1257by the shell. 1258.It Li $$ 1259Expands to the process ID of the invoked shell. 1260A subshell 1261retains the same value of 1262.Va $ 1263as its parent. 1264.It Li $! 1265Expands to the process ID of the most recent background 1266command executed from the current shell. 1267For a 1268pipeline, the process ID is that of the last command in the 1269pipeline. 1270If this parameter is referenced, the shell will remember 1271the process ID and its exit status until the 1272.Ic wait 1273built-in command reports completion of the process. 1274.It Li $0 1275(zero) Expands to the name of the shell script if passed on the command line, 1276the 1277.Ar name 1278operand if given (with 1279.Fl c ) 1280or otherwise argument 0 passed to the shell. 1281.El 1282.Ss Special Variables 1283The following variables are set by the shell or 1284have special meaning to it: 1285.Bl -tag -width ".Va HISTSIZE" 1286.It Va CDPATH 1287The search path used with the 1288.Ic cd 1289built-in. 1290.It Va EDITOR 1291The fallback editor used with the 1292.Ic fc 1293built-in. 1294If not set, the default editor is 1295.Xr ed 1 . 1296.It Va FCEDIT 1297The default editor used with the 1298.Ic fc 1299built-in. 1300.It Va HISTSIZE 1301The number of previous commands that are accessible. 1302.It Va HOME 1303The user's home directory, 1304used in tilde expansion and as a default directory for the 1305.Ic cd 1306built-in. 1307.It Va IFS 1308Input Field Separators. 1309The default value is 1310.Aq space , 1311.Aq tab , 1312and 1313.Aq newline 1314in that order. 1315This default also applies if 1316.Va IFS 1317is unset, but not if it is set to the empty string. 1318See the 1319.Sx White Space Splitting 1320section for more details. 1321.It Va LINENO 1322The current line number in the script or function. 1323.It Va MAIL 1324The name of a mail file, that will be checked for the arrival of new 1325mail. 1326Overridden by 1327.Va MAILPATH . 1328.It Va MAILPATH 1329A colon 1330.Pq Ql \&: 1331separated list of file names, for the shell to check for incoming 1332mail. 1333This variable overrides the 1334.Va MAIL 1335setting. 1336There is a maximum of 10 mailboxes that can be monitored at once. 1337.It Va PATH 1338The default search path for executables. 1339See the 1340.Sx Path Search 1341section for details. 1342.It Va PPID 1343The parent process ID of the invoked shell. 1344This is set at startup 1345unless this variable is in the environment. 1346A later change of parent process ID is not reflected. 1347A subshell retains the same value of 1348.Va PPID . 1349.It Va PS1 1350The primary prompt string, which defaults to 1351.Dq Li "$ " , 1352unless you are the superuser, in which case it defaults to 1353.Dq Li "# " . 1354.Va PS1 1355may include any of the following formatting sequences, 1356which are replaced by the given information: 1357.Bl -tag -width indent 1358.It Li \eH 1359The local hostname. 1360.It Li \eh 1361The fully-qualified hostname. 1362.It Li \eW 1363The final component of the current working directory. 1364.It Li \ew 1365The entire path of the current working directory. 1366.It Li \e$ 1367Superuser status. 1368.Dq Li "$ " 1369for normal users and 1370.Dq Li "# " 1371for superusers. 1372.It Li \e\e 1373A literal backslash. 1374.El 1375.It Va PS2 1376The secondary prompt string, which defaults to 1377.Dq Li "> " . 1378.Va PS2 1379may include any of the formatting sequences from 1380.Va PS1 . 1381.It Va PS4 1382The prefix for the trace output (if 1383.Fl x 1384is active). 1385The default is 1386.Dq Li "+ " . 1387.El 1388.Ss Word Expansions 1389This clause describes the various expansions that are 1390performed on words. 1391Not all expansions are performed on 1392every word, as explained later. 1393.Pp 1394Tilde expansions, parameter expansions, command substitutions, 1395arithmetic expansions, and quote removals that occur within 1396a single word expand to a single field. 1397It is only field 1398splitting or pathname expansion that can create multiple 1399fields from a single word. 1400The single exception to this rule is 1401the expansion of the special parameter 1402.Va @ 1403within double-quotes, 1404as was described above. 1405.Pp 1406The order of word expansion is: 1407.Bl -enum 1408.It 1409Tilde Expansion, Parameter Expansion, Command Substitution, 1410Arithmetic Expansion (these all occur at the same time). 1411.It 1412Field Splitting is performed on fields generated by step (1) 1413unless the 1414.Va IFS 1415variable is null. 1416.It 1417Pathname Expansion (unless the 1418.Fl f 1419option is in effect). 1420.It 1421Quote Removal. 1422.El 1423.Pp 1424The 1425.Ql $ 1426character is used to introduce parameter expansion, command 1427substitution, or arithmetic expansion. 1428.Ss Tilde Expansion (substituting a user's home directory) 1429A word beginning with an unquoted tilde character 1430.Pq Ql ~ 1431is 1432subjected to tilde expansion. 1433All the characters up to a slash 1434.Pq Ql / 1435or the end of the word are treated as a username 1436and are replaced with the user's home directory. 1437If the 1438username is missing (as in 1439.Pa ~/foobar ) , 1440the tilde is replaced with the value of the 1441.Va HOME 1442variable (the current user's home directory). 1443.Ss Parameter Expansion 1444The format for parameter expansion is as follows: 1445.Pp 1446.D1 Li ${ Ns Ar expression Ns Li } 1447.Pp 1448where 1449.Ar expression 1450consists of all characters until the matching 1451.Ql } . 1452Any 1453.Ql } 1454escaped by a backslash or within a single-quoted or double-quoted 1455string, and characters in 1456embedded arithmetic expansions, command substitutions, and variable 1457expansions, are not examined in determining the matching 1458.Ql } . 1459If the variants with 1460.Ql + , 1461.Ql - , 1462.Ql = 1463or 1464.Ql ?\& 1465occur within a double-quoted string, 1466as an extension there may be unquoted parts 1467(via double-quotes inside the expansion); 1468.Ql } 1469within such parts are also not examined in determining the matching 1470.Ql } . 1471.Pp 1472The simplest form for parameter expansion is: 1473.Pp 1474.D1 Li ${ Ns Ar parameter Ns Li } 1475.Pp 1476The value, if any, of 1477.Ar parameter 1478is substituted. 1479.Pp 1480The parameter name or symbol can be enclosed in braces, which are 1481optional except for positional parameters with more than one digit or 1482when parameter is followed by a character that could be interpreted as 1483part of the name. 1484If a parameter expansion occurs inside double-quotes: 1485.Bl -enum 1486.It 1487Field splitting is not performed on the results of the 1488expansion, with the exception of the special parameter 1489.Va @ . 1490.It 1491Pathname expansion is not performed on the results of the 1492expansion. 1493.El 1494.Pp 1495In addition, a parameter expansion can be modified by using one of the 1496following formats. 1497.Bl -tag -width indent 1498.It Li ${ Ns Ar parameter Ns Li :- Ns Ar word Ns Li } 1499Use Default Values. 1500If 1501.Ar parameter 1502is unset or null, the expansion of 1503.Ar word 1504is substituted; otherwise, the value of 1505.Ar parameter 1506is substituted. 1507.It Li ${ Ns Ar parameter Ns Li := Ns Ar word Ns Li } 1508Assign Default Values. 1509If 1510.Ar parameter 1511is unset or null, the expansion of 1512.Ar word 1513is assigned to 1514.Ar parameter . 1515In all cases, the 1516final value of 1517.Ar parameter 1518is substituted. 1519Quoting inside 1520.Ar word 1521does not prevent field splitting or pathname expansion. 1522Only variables, not positional 1523parameters or special parameters, can be 1524assigned in this way. 1525.It Li ${ Ns Ar parameter Ns Li :? Ns Oo Ar word Oc Ns Li } 1526Indicate Error if Null or Unset. 1527If 1528.Ar parameter 1529is unset or null, the expansion of 1530.Ar word 1531(or a message indicating it is unset if 1532.Ar word 1533is omitted) is written to standard 1534error and the shell exits with a nonzero 1535exit status. 1536Otherwise, the value of 1537.Ar parameter 1538is substituted. 1539An 1540interactive shell need not exit. 1541.It Li ${ Ns Ar parameter Ns Li :+ Ns Ar word Ns Li } 1542Use Alternate Value. 1543If 1544.Ar parameter 1545is unset or null, null is substituted; 1546otherwise, the expansion of 1547.Ar word 1548is substituted. 1549.El 1550.Pp 1551In the parameter expansions shown previously, use of the colon in the 1552format results in a test for a parameter that is unset or null; omission 1553of the colon results in a test for a parameter that is only unset. 1554.Pp 1555The 1556.Ar word 1557inherits the type of quoting 1558(unquoted, double-quoted or here-document) 1559from the surroundings, 1560with the exception that a backslash that quotes a closing brace is removed 1561during quote removal. 1562.Bl -tag -width indent 1563.It Li ${# Ns Ar parameter Ns Li } 1564String Length. 1565The length in characters of 1566the value of 1567.Ar parameter . 1568.El 1569.Pp 1570The following four varieties of parameter expansion provide for substring 1571processing. 1572In each case, pattern matching notation 1573(see 1574.Sx Shell Patterns ) , 1575rather than regular expression notation, 1576is used to evaluate the patterns. 1577If parameter is one of the special parameters 1578.Va * 1579or 1580.Va @ , 1581the result of the expansion is unspecified. 1582Enclosing the full parameter expansion string in double-quotes does not 1583cause the following four varieties of pattern characters to be quoted, 1584whereas quoting characters within the braces has this effect. 1585.Bl -tag -width indent 1586.It Li ${ Ns Ar parameter Ns Li % Ns Ar word Ns Li } 1587Remove Smallest Suffix Pattern. 1588The 1589.Ar word 1590is expanded to produce a pattern. 1591The 1592parameter expansion then results in 1593.Ar parameter , 1594with the smallest portion of the 1595suffix matched by the pattern deleted. 1596.It Li ${ Ns Ar parameter Ns Li %% Ns Ar word Ns Li } 1597Remove Largest Suffix Pattern. 1598The 1599.Ar word 1600is expanded to produce a pattern. 1601The 1602parameter expansion then results in 1603.Ar parameter , 1604with the largest portion of the 1605suffix matched by the pattern deleted. 1606.It Li ${ Ns Ar parameter Ns Li # Ns Ar word Ns Li } 1607Remove Smallest Prefix Pattern. 1608The 1609.Ar word 1610is expanded to produce a pattern. 1611The 1612parameter expansion then results in 1613.Ar parameter , 1614with the smallest portion of the 1615prefix matched by the pattern deleted. 1616.It Li ${ Ns Ar parameter Ns Li ## Ns Ar word Ns Li } 1617Remove Largest Prefix Pattern. 1618The 1619.Ar word 1620is expanded to produce a pattern. 1621The 1622parameter expansion then results in 1623.Ar parameter , 1624with the largest portion of the 1625prefix matched by the pattern deleted. 1626.El 1627.Ss Command Substitution 1628Command substitution allows the output of a command to be substituted in 1629place of the command name itself. 1630Command substitution occurs when 1631the command is enclosed as follows: 1632.Pp 1633.D1 Li $( Ns Ar command Ns Li )\& 1634.Pp 1635or the backquoted version: 1636.Pp 1637.D1 Li ` Ns Ar command Ns Li ` 1638.Pp 1639The shell expands the command substitution by executing command 1640and replacing the command substitution 1641with the standard output of the command, 1642removing sequences of one or more newlines at the end of the substitution. 1643Embedded newlines before the end of the output are not removed; 1644however, during field splitting, they may be translated into spaces 1645depending on the value of 1646.Va IFS 1647and the quoting that is in effect. 1648The command is executed in a subshell environment, 1649except that the built-in commands 1650.Ic jobid , 1651.Ic jobs , 1652and 1653.Ic trap 1654return information about the parent shell environment 1655and 1656.Ic times 1657returns information about the same process 1658if they are the only command in a command substitution. 1659.Pp 1660If a command substitution of the 1661.Li $( 1662form begins with a subshell, 1663the 1664.Li $( 1665and 1666.Li (\& 1667must be separated by whitespace 1668to avoid ambiguity with arithmetic expansion. 1669.Ss Arithmetic Expansion 1670Arithmetic expansion provides a mechanism for evaluating an arithmetic 1671expression and substituting its value. 1672The format for arithmetic expansion is as follows: 1673.Pp 1674.D1 Li $(( Ns Ar expression Ns Li )) 1675.Pp 1676The 1677.Ar expression 1678is treated as if it were in double-quotes, except 1679that a double-quote inside the expression is not treated specially. 1680The 1681shell expands all tokens in the 1682.Ar expression 1683for parameter expansion, 1684command substitution, 1685arithmetic expansion 1686and quote removal. 1687.Pp 1688The allowed expressions are a subset of C expressions, 1689summarized below. 1690.Bl -tag -width "Variables" -offset indent 1691.It Values 1692All values are of type 1693.Ft intmax_t . 1694.It Constants 1695Decimal, octal (starting with 1696.Li 0 ) 1697and hexadecimal (starting with 1698.Li 0x ) 1699integer constants. 1700.It Variables 1701Shell variables can be read and written 1702and contain integer constants. 1703.It Unary operators 1704.Li "! ~ + -" 1705.It Binary operators 1706.Li "* / % + - << >> < <= > >= == != & ^ | && ||" 1707.It Assignment operators 1708.Li "= += -= *= /= %= <<= >>= &= ^= |=" 1709.It Conditional operator 1710.Li "? :" 1711.El 1712.Pp 1713The result of the expression is substituted in decimal. 1714.Ss White Space Splitting (Field Splitting) 1715In certain contexts, 1716after parameter expansion, command substitution, and 1717arithmetic expansion the shell scans the results of 1718expansions and substitutions that did not occur in double-quotes for 1719field splitting and multiple fields can result. 1720.Pp 1721Characters in 1722.Va IFS 1723that are whitespace 1724.Po 1725.Aq space , 1726.Aq tab , 1727and 1728.Aq newline 1729.Pc 1730are treated differently from other characters in 1731.Va IFS . 1732.Pp 1733Whitespace in 1734.Va IFS 1735at the beginning or end of a word is discarded. 1736.Pp 1737Subsequently, a field is delimited by either 1738.Bl -enum 1739.It 1740a non-whitespace character in 1741.Va IFS 1742with any whitespace in 1743.Va IFS 1744surrounding it, or 1745.It 1746one or more whitespace characters in 1747.Va IFS . 1748.El 1749.Pp 1750If a word ends with a non-whitespace character in 1751.Va IFS , 1752there is no empty field after this character. 1753.Pp 1754If no field is delimited, the word is discarded. 1755In particular, if a word consists solely of an unquoted substitution 1756and the result of the substitution is null, 1757it is removed by field splitting even if 1758.Va IFS 1759is null. 1760.Ss Pathname Expansion (File Name Generation) 1761Unless the 1762.Fl f 1763option is set, 1764file name generation is performed 1765after word splitting is complete. 1766Each word is 1767viewed as a series of patterns, separated by slashes. 1768The 1769process of expansion replaces the word with the names of 1770all existing files whose names can be formed by replacing 1771each pattern with a string that matches the specified pattern. 1772There are two restrictions on this: first, a pattern cannot match 1773a string containing a slash, and second, 1774a pattern cannot match a string starting with a period 1775unless the first character of the pattern is a period. 1776The next section describes the patterns used for 1777Pathname Expansion, 1778the four varieties of parameter expansion for substring processing and the 1779.Ic case 1780command. 1781.Ss Shell Patterns 1782A pattern consists of normal characters, which match themselves, 1783and meta-characters. 1784The meta-characters are 1785.Ql * , 1786.Ql \&? , 1787and 1788.Ql \&[ . 1789These characters lose their special meanings if they are quoted. 1790When command or variable substitution is performed and the dollar sign 1791or back quotes are not double-quoted, the value of the 1792variable or the output of the command is scanned for these 1793characters and they are turned into meta-characters. 1794.Pp 1795An asterisk 1796.Pq Ql * 1797matches any string of characters. 1798A question mark 1799.Pq Ql \&? 1800matches any single character. 1801A left bracket 1802.Pq Ql \&[ 1803introduces a character class. 1804The end of the character class is indicated by a 1805.Ql \&] ; 1806if the 1807.Ql \&] 1808is missing then the 1809.Ql \&[ 1810matches a 1811.Ql \&[ 1812rather than introducing a character class. 1813A character class matches any of the characters between the square brackets. 1814A locale-dependent range of characters may be specified using a minus sign. 1815A named class of characters (see 1816.Xr wctype 3 ) 1817may be specified by surrounding the name with 1818.Ql \&[: 1819and 1820.Ql :\&] . 1821For example, 1822.Ql \&[\&[:alpha:\&]\&] 1823is a shell pattern that matches a single letter. 1824The character class may be complemented by making an exclamation point 1825.Pq Ql !\& 1826the first character of the character class. 1827A caret 1828.Pq Ql ^ 1829has the same effect but is non-standard. 1830.Pp 1831To include a 1832.Ql \&] 1833in a character class, make it the first character listed 1834(after the 1835.Ql \&! 1836or 1837.Ql ^ , 1838if any). 1839To include a 1840.Ql - , 1841make it the first or last character listed. 1842.Ss Built-in Commands 1843This section lists the built-in commands. 1844.Bl -tag -width indent 1845.It Ic \&: 1846A null command that returns a 0 (true) exit value. 1847.It Ic \&. Ar file 1848The commands in the specified file are read and executed by the shell. 1849The 1850.Ic return 1851command may be used to return to the 1852.Ic \&. 1853command's caller. 1854If 1855.Ar file 1856contains any 1857.Ql / 1858characters, it is used as is. 1859Otherwise, the shell searches the 1860.Va PATH 1861for the file. 1862If it is not found in the 1863.Va PATH , 1864it is sought in the current working directory. 1865.It Ic \&[ 1866A built-in equivalent of 1867.Xr test 1 . 1868.It Ic alias Oo Ar name Ns Oo = Ns Ar string Oc ... Oc 1869If 1870.Ar name Ns = Ns Ar string 1871is specified, the shell defines the alias 1872.Ar name 1873with value 1874.Ar string . 1875If just 1876.Ar name 1877is specified, the value of the alias 1878.Ar name 1879is printed. 1880With no arguments, the 1881.Ic alias 1882built-in command prints the names and values of all defined aliases 1883(see 1884.Ic unalias ) . 1885Alias values are written with appropriate quoting so that they are 1886suitable for re-input to the shell. 1887Also see the 1888.Sx Aliases 1889subsection. 1890.It Ic bg Op Ar job ... 1891Continue the specified jobs 1892(or the current job if no jobs are given) 1893in the background. 1894.It Ic bind Oo Fl aeklrsv Oc Oo Ar key Oo Ar command Oc Oc 1895List or alter key bindings for the line editor. 1896This command is documented in 1897.Xr editrc 5 . 1898.It Ic break Op Ar num 1899See the 1900.Sx Flow-Control Constructs 1901subsection. 1902.It Ic builtin Ar cmd Op Ar arg ... 1903Execute the specified built-in command, 1904.Ar cmd . 1905This is useful when the user wishes to override a shell function 1906with the same name as a built-in command. 1907.It Ic cd Oo Fl L | P Oc Oo Fl e Oc Op Ar directory 1908Switch to the specified 1909.Ar directory , 1910or to the directory specified in the 1911.Va HOME 1912environment variable if no 1913.Ar directory 1914is specified. 1915If 1916.Ar directory 1917does not begin with 1918.Pa / , \&. , 1919or 1920.Pa .. , 1921then the directories listed in the 1922.Va CDPATH 1923variable will be 1924searched for the specified 1925.Ar directory . 1926If 1927.Va CDPATH 1928is unset, the current directory is searched. 1929The format of 1930.Va CDPATH 1931is the same as that of 1932.Va PATH . 1933In an interactive shell, 1934the 1935.Ic cd 1936command will print out the name of the directory 1937that it actually switched to 1938if this is different from the name that the user gave. 1939These may be different either because the 1940.Va CDPATH 1941mechanism was used or because a symbolic link was crossed. 1942.Pp 1943If the 1944.Fl P 1945option is specified, 1946.Pa .. 1947is handled physically and symbolic links are resolved before 1948.Pa .. 1949components are processed. 1950If the 1951.Fl L 1952option is specified, 1953.Pa .. 1954is handled logically. 1955This is the default. 1956.Pp 1957The 1958.Fl e 1959option causes 1960.Ic cd 1961to return exit status 1 if the full pathname of the new directory 1962cannot be determined reliably or at all. 1963Normally this is not considered an error, 1964although a warning is printed. 1965.It Ic chdir 1966A synonym for the 1967.Ic cd 1968built-in command. 1969.It Ic command Oo Fl p Oc Op Ar utility Op Ar argument ... 1970.It Ic command Oo Fl p Oc Fl v Ar utility 1971.It Ic command Oo Fl p Oc Fl V Ar utility 1972The first form of invocation executes the specified 1973.Ar utility , 1974ignoring shell functions in the search. 1975If 1976.Ar utility 1977is a special builtin, 1978it is executed as if it were a regular builtin. 1979.Pp 1980If the 1981.Fl p 1982option is specified, the command search is performed using a 1983default value of 1984.Va PATH 1985that is guaranteed to find all of the standard utilities. 1986.Pp 1987If the 1988.Fl v 1989option is specified, 1990.Ar utility 1991is not executed but a description of its interpretation by the shell is 1992printed. 1993For ordinary commands the output is the path name; for shell built-in 1994commands, shell functions and keywords only the name is written. 1995Aliases are printed as 1996.Dq Ic alias Ar name Ns = Ns Ar value . 1997.Pp 1998The 1999.Fl V 2000option is identical to 2001.Fl v 2002except for the output. 2003It prints 2004.Dq Ar utility Ic is Ar description 2005where 2006.Ar description 2007is either 2008the path name to 2009.Ar utility , 2010a special shell builtin, 2011a shell builtin, 2012a shell function, 2013a shell keyword 2014or 2015an alias for 2016.Ar value . 2017.It Ic continue Op Ar num 2018See the 2019.Sx Flow-Control Constructs 2020subsection. 2021.It Ic echo Oo Fl e | n Oc Op Ar string ... 2022Print a space-separated list of the arguments to the standard output 2023and append a newline character. 2024.Bl -tag -width indent 2025.It Fl n 2026Suppress the output of the trailing newline. 2027.It Fl e 2028Process C-style backslash escape sequences. 2029The 2030.Ic echo 2031command understands the following character escapes: 2032.Bl -tag -width indent 2033.It \ea 2034Alert (ring the terminal bell) 2035.It \eb 2036Backspace 2037.It \ec 2038Suppress the trailing newline (this has the side-effect of truncating the 2039line if it is not the last character) 2040.It \ee 2041The ESC character 2042.Tn ( ASCII 20430x1b) 2044.It \ef 2045Formfeed 2046.It \en 2047Newline 2048.It \er 2049Carriage return 2050.It \et 2051Horizontal tab 2052.It \ev 2053Vertical tab 2054.It \e\e 2055Literal backslash 2056.It \e0nnn 2057(Zero) The character whose octal value is 2058.Ar nnn 2059.El 2060.Pp 2061If 2062.Ar string 2063is not enclosed in quotes then the backslash itself must be escaped 2064with a backslash to protect it from the shell. 2065For example 2066.Bd -literal -offset indent 2067$ echo -e "a\evb" 2068a 2069 b 2070$ echo -e a\e\evb 2071a 2072 b 2073$ echo -e "a\e\eb" 2074a\eb 2075$ echo -e a\e\e\e\eb 2076a\eb 2077.Ed 2078.El 2079.Pp 2080Only one of the 2081.Fl e 2082and 2083.Fl n 2084options may be specified. 2085.It Ic eval Ar string ... 2086Concatenate all the arguments with spaces. 2087Then re-parse and execute the command. 2088.It Ic exec Op Ar command Op arg ... 2089Unless 2090.Ar command 2091is omitted, 2092the shell process is replaced with the specified program 2093(which must be a real program, not a shell built-in command or function). 2094Any redirections on the 2095.Ic exec 2096command are marked as permanent, 2097so that they are not undone when the 2098.Ic exec 2099command finishes. 2100.It Ic exit Op Ar exitstatus 2101Terminate the shell process. 2102If 2103.Ar exitstatus 2104is given 2105it is used as the exit status of the shell. 2106Otherwise, if the shell is executing an 2107.Cm EXIT 2108trap, the exit status of the last command before the trap is used; 2109if the shell is executing a trap for a signal, 2110the shell exits by resending the signal to itself. 2111Otherwise, the exit status of the preceding command is used. 2112The exit status should be an integer between 0 and 255. 2113.It Ic export Ar name ... 2114.It Ic export Op Fl p 2115The specified names are exported so that they will 2116appear in the environment of subsequent commands. 2117The only way to un-export a variable is to 2118.Ic unset 2119it. 2120The shell allows the value of a variable to be set 2121at the same time as it is exported by writing 2122.Pp 2123.D1 Ic export Ar name Ns = Ns Ar value 2124.Pp 2125With no arguments the 2126.Ic export 2127command lists the names 2128of all exported variables. 2129If the 2130.Fl p 2131option is specified, the exported variables are printed as 2132.Dq Ic export Ar name Ns = Ns Ar value 2133lines, suitable for re-input to the shell. 2134.It Ic false 2135A null command that returns a non-zero (false) exit value. 2136.It Ic fc Oo Fl e Ar editor Oc Op Ar first Op Ar last 2137.It Ic fc Fl l Oo Fl nr Oc Op Ar first Op Ar last 2138.It Ic fc Fl s Oo Ar old Ns = Ns Ar new Oc Op Ar first 2139The 2140.Ic fc 2141built-in command lists, or edits and re-executes, 2142commands previously entered to an interactive shell. 2143.Bl -tag -width indent 2144.It Fl e Ar editor 2145Use the editor named by 2146.Ar editor 2147to edit the commands. 2148The 2149.Ar editor 2150string is a command name, 2151subject to search via the 2152.Va PATH 2153variable. 2154The value in the 2155.Va FCEDIT 2156variable is used as a default when 2157.Fl e 2158is not specified. 2159If 2160.Va FCEDIT 2161is null or unset, the value of the 2162.Va EDITOR 2163variable is used. 2164If 2165.Va EDITOR 2166is null or unset, 2167.Xr ed 1 2168is used as the editor. 2169.It Fl l No (ell) 2170List the commands rather than invoking 2171an editor on them. 2172The commands are written in the 2173sequence indicated by the 2174.Ar first 2175and 2176.Ar last 2177operands, as affected by 2178.Fl r , 2179with each command preceded by the command number. 2180.It Fl n 2181Suppress command numbers when listing with 2182.Fl l . 2183.It Fl r 2184Reverse the order of the commands listed 2185(with 2186.Fl l ) 2187or edited 2188(with neither 2189.Fl l 2190nor 2191.Fl s ) . 2192.It Fl s 2193Re-execute the command without invoking an editor. 2194.It Ar first 2195.It Ar last 2196Select the commands to list or edit. 2197The number of previous commands that can be accessed 2198are determined by the value of the 2199.Va HISTSIZE 2200variable. 2201The value of 2202.Ar first 2203or 2204.Ar last 2205or both are one of the following: 2206.Bl -tag -width indent 2207.It Oo Cm + Oc Ns Ar num 2208A positive number representing a command number; 2209command numbers can be displayed with the 2210.Fl l 2211option. 2212.It Fl Ar num 2213A negative decimal number representing the 2214command that was executed 2215.Ar num 2216of 2217commands previously. 2218For example, \-1 is the immediately previous command. 2219.It Ar string 2220A string indicating the most recently entered command 2221that begins with that string. 2222If the 2223.Ar old Ns = Ns Ar new 2224operand is not also specified with 2225.Fl s , 2226the string form of the first operand cannot contain an embedded equal sign. 2227.El 2228.El 2229.Pp 2230The following variables affect the execution of 2231.Ic fc : 2232.Bl -tag -width ".Va HISTSIZE" 2233.It Va FCEDIT 2234Name of the editor to use for history editing. 2235.It Va HISTSIZE 2236The number of previous commands that are accessible. 2237.El 2238.It Ic fg Op Ar job 2239Move the specified 2240.Ar job 2241or the current job to the foreground. 2242.It Ic getopts Ar optstring var 2243The 2244.Tn POSIX 2245.Ic getopts 2246command. 2247The 2248.Ic getopts 2249command deprecates the older 2250.Xr getopt 1 2251command. 2252The first argument should be a series of letters, each possibly 2253followed by a colon which indicates that the option takes an argument. 2254The specified variable is set to the parsed option. 2255The index of 2256the next argument is placed into the shell variable 2257.Va OPTIND . 2258If an option takes an argument, it is placed into the shell variable 2259.Va OPTARG . 2260If an invalid option is encountered, 2261.Ar var 2262is set to 2263.Ql \&? . 2264It returns a false value (1) when it encounters the end of the options. 2265.It Ic hash Oo Fl rv Oc Op Ar command ... 2266The shell maintains a hash table which remembers the locations of commands. 2267With no arguments whatsoever, the 2268.Ic hash 2269command prints out the contents of this table. 2270.Pp 2271With arguments, the 2272.Ic hash 2273command removes each specified 2274.Ar command 2275from the hash table (unless they are functions) and then locates it. 2276With the 2277.Fl v 2278option, 2279.Ic hash 2280prints the locations of the commands as it finds them. 2281The 2282.Fl r 2283option causes the 2284.Ic hash 2285command to delete all the entries in the hash table except for functions. 2286.It Ic jobid Op Ar job 2287Print the process IDs of the processes in the specified 2288.Ar job . 2289If the 2290.Ar job 2291argument is omitted, use the current job. 2292.It Ic jobs Oo Fl lps Oc Op Ar job ... 2293Print information about the specified jobs, or all jobs if no 2294.Ar job 2295argument is given. 2296The information printed includes job ID, status and command name. 2297.Pp 2298If the 2299.Fl l 2300option is specified, the PID of each job is also printed. 2301If the 2302.Fl p 2303option is specified, only the process IDs for the process group leaders 2304are printed, one per line. 2305If the 2306.Fl s 2307option is specified, only the PIDs of the job commands are printed, one per 2308line. 2309.It Ic kill 2310A built-in equivalent of 2311.Xr kill 1 2312that additionally supports sending signals to jobs. 2313.It Ic local Oo Ar variable ... Oc Op Fl 2314See the 2315.Sx Functions 2316subsection. 2317.It Ic printf 2318A built-in equivalent of 2319.Xr printf 1 . 2320.It Ic pwd Op Fl L | P 2321Print the path of the current directory. 2322The built-in command may 2323differ from the program of the same name because the 2324built-in command remembers what the current directory 2325is rather than recomputing it each time. 2326This makes 2327it faster. 2328However, if the current directory is 2329renamed, 2330the built-in version of 2331.Xr pwd 1 2332will continue to print the old name for the directory. 2333.Pp 2334If the 2335.Fl P 2336option is specified, symbolic links are resolved. 2337If the 2338.Fl L 2339option is specified, the shell's notion of the current directory 2340is printed (symbolic links are not resolved). 2341This is the default. 2342.It Ic read Oo Fl p Ar prompt Oc Oo 2343.Fl t Ar timeout Oc Oo Fl er Oc Ar variable ... 2344The 2345.Ar prompt 2346is printed if the 2347.Fl p 2348option is specified 2349and the standard input is a terminal. 2350Then a line is 2351read from the standard input. 2352The trailing newline 2353is deleted from the line and the line is split as 2354described in the section on 2355.Sx White Space Splitting (Field Splitting) 2356above, and 2357the pieces are assigned to the variables in order. 2358If there are more pieces than variables, the remaining 2359pieces (along with the characters in 2360.Va IFS 2361that separated them) 2362are assigned to the last variable. 2363If there are more variables than pieces, the remaining 2364variables are assigned the null string. 2365.Pp 2366Backslashes are treated specially, unless the 2367.Fl r 2368option is 2369specified. 2370If a backslash is followed by 2371a newline, the backslash and the newline will be 2372deleted. 2373If a backslash is followed by any other 2374character, the backslash will be deleted and the following 2375character will be treated as though it were not in 2376.Va IFS , 2377even if it is. 2378.Pp 2379If the 2380.Fl t 2381option is specified and the 2382.Ar timeout 2383elapses before a complete line of input is supplied, 2384the 2385.Ic read 2386command will return an exit status as if terminated by 2387.Dv SIGALRM 2388without assigning any values. 2389The 2390.Ar timeout 2391value may optionally be followed by one of 2392.Ql s , 2393.Ql m 2394or 2395.Ql h 2396to explicitly specify seconds, minutes or hours. 2397If none is supplied, 2398.Ql s 2399is assumed. 2400.Pp 2401The 2402.Fl e 2403option exists only for backward compatibility with older scripts. 2404.Pp 2405The exit status is 0 on success, 1 on end of file, 2406between 2 and 128 if an error occurs 2407and greater than 128 if a trapped signal interrupts 2408.Ic read . 2409.It Ic readonly Oo Fl p Oc Op Ar name ... 2410Each specified 2411.Ar name 2412is marked as read only, 2413so that it cannot be subsequently modified or unset. 2414The shell allows the value of a variable to be set 2415at the same time as it is marked read only 2416by using the following form: 2417.Pp 2418.D1 Ic readonly Ar name Ns = Ns Ar value 2419.Pp 2420With no arguments the 2421.Ic readonly 2422command lists the names of all read only variables. 2423If the 2424.Fl p 2425option is specified, the read-only variables are printed as 2426.Dq Ic readonly Ar name Ns = Ns Ar value 2427lines, suitable for re-input to the shell. 2428.It Ic return Op Ar exitstatus 2429See the 2430.Sx Functions 2431subsection. 2432.It Ic set Oo Fl /+abCEefIimnpTuVvx Oc Oo Fl /+o Ar longname Oc Oo 2433.Fl c Ar string Oc Op Fl - Ar arg ... 2434The 2435.Ic set 2436command performs three different functions: 2437.Bl -item 2438.It 2439With no arguments, it lists the values of all shell variables. 2440.It 2441If options are given, 2442either in short form or using the long 2443.Dq Fl /+o Ar longname 2444form, 2445it sets or clears the specified options as described in the section called 2446.Sx Argument List Processing . 2447.It 2448If the 2449.Dq Fl - 2450option is specified, 2451.Ic set 2452will replace the shell's positional parameters with the subsequent 2453arguments. 2454If no arguments follow the 2455.Dq Fl - 2456option, 2457all the positional parameters will be cleared, 2458which is equivalent to executing the command 2459.Dq Li "shift $#" . 2460The 2461.Dq Fl - 2462flag may be omitted when specifying arguments to be used 2463as positional replacement parameters. 2464This is not recommended, 2465because the first argument may begin with a dash 2466.Pq Ql - 2467or a plus 2468.Pq Ql + , 2469which the 2470.Ic set 2471command will interpret as a request to enable or disable options. 2472.El 2473.It Ic setvar Ar variable value 2474Assigns the specified 2475.Ar value 2476to the specified 2477.Ar variable . 2478The 2479.Ic setvar 2480command is intended to be used in functions that 2481assign values to variables whose names are passed as parameters. 2482In general it is better to write 2483.Dq Ar variable Ns = Ns Ar value 2484rather than using 2485.Ic setvar . 2486.It Ic shift Op Ar n 2487Shift the positional parameters 2488.Ar n 2489times, or once if 2490.Ar n 2491is not specified. 2492A shift sets the value of 2493.Li $1 2494to the value of 2495.Li $2 , 2496the value of 2497.Li $2 2498to the value of 2499.Li $3 , 2500and so on, 2501decreasing the value of 2502.Li $# 2503by one. 2504If there are zero positional parameters, shifting does not do anything. 2505.It Ic test 2506A built-in equivalent of 2507.Xr test 1 . 2508.It Ic times 2509Print the amount of time spent executing the shell process and its children. 2510The first output line shows the user and system times for the shell process 2511itself, the second one contains the user and system times for the 2512children. 2513.It Ic trap Oo Ar action Oc Ar signal ... 2514.It Ic trap Fl l 2515Cause the shell to parse and execute 2516.Ar action 2517when any specified 2518.Ar signal 2519is received. 2520The signals are specified by name or number. 2521In addition, the pseudo-signal 2522.Cm EXIT 2523may be used to specify an 2524.Ar action 2525that is performed when the shell terminates. 2526The 2527.Ar action 2528may be an empty string or a dash 2529.Pq Ql - ; 2530the former causes the specified signal to be ignored 2531and the latter causes the default action to be taken. 2532Omitting the 2533.Ar action 2534is another way to request the default action, for compatibility reasons this 2535usage is not recommended though. 2536In a subshell or utility environment, 2537the shell resets trapped (but not ignored) signals to the default action. 2538The 2539.Ic trap 2540command has no effect on signals that were ignored on entry to the shell. 2541.Pp 2542Option 2543.Fl l 2544causes the 2545.Ic trap 2546command to display a list of valid signal names. 2547.It Ic true 2548A null command that returns a 0 (true) exit value. 2549.It Ic type Op Ar name ... 2550Interpret each 2551.Ar name 2552as a command and print the resolution of the command search. 2553Possible resolutions are: 2554shell keyword, alias, special shell builtin, shell builtin, command, 2555tracked alias 2556and not found. 2557For aliases the alias expansion is printed; 2558for commands and tracked aliases 2559the complete pathname of the command is printed. 2560.It Ic ulimit Oo Fl HSabcdfklmnpstuvw Oc Op Ar limit 2561Set or display resource limits (see 2562.Xr getrlimit 2 ) . 2563If 2564.Ar limit 2565is specified, the named resource will be set; 2566otherwise the current resource value will be displayed. 2567.Pp 2568If 2569.Fl H 2570is specified, the hard limits will be set or displayed. 2571While everybody is allowed to reduce a hard limit, 2572only the superuser can increase it. 2573The 2574.Fl S 2575option 2576specifies the soft limits instead. 2577When displaying limits, 2578only one of 2579.Fl S 2580or 2581.Fl H 2582can be given. 2583The default is to display the soft limits, 2584and to set both the hard and the soft limits. 2585.Pp 2586Option 2587.Fl a 2588causes the 2589.Ic ulimit 2590command to display all resources. 2591The parameter 2592.Ar limit 2593is not acceptable in this mode. 2594.Pp 2595The remaining options specify which resource value is to be 2596displayed or modified. 2597They are mutually exclusive. 2598.Bl -tag -width indent 2599.It Fl b Ar sbsize 2600The maximum size of socket buffer usage, in bytes. 2601.It Fl c Ar coredumpsize 2602The maximal size of core dump files, in 512-byte blocks. 2603.It Fl d Ar datasize 2604The maximal size of the data segment of a process, in kilobytes. 2605.It Fl f Ar filesize 2606The maximal size of a file, in 512-byte blocks. 2607.It Fl k Ar kqueues 2608The maximal number of kqueues 2609(see 2610.Xr kqueue 2 ) 2611for this user ID. 2612.It Fl l Ar lockedmem 2613The maximal size of memory that can be locked by a process, in 2614kilobytes. 2615.It Fl m Ar memoryuse 2616The maximal resident set size of a process, in kilobytes. 2617.It Fl n Ar nofiles 2618The maximal number of descriptors that could be opened by a process. 2619.It Fl p Ar pseudoterminals 2620The maximal number of pseudo-terminals for this user ID. 2621.It Fl s Ar stacksize 2622The maximal size of the stack segment, in kilobytes. 2623.It Fl t Ar time 2624The maximal amount of CPU time to be used by each process, in seconds. 2625.It Fl u Ar userproc 2626The maximal number of simultaneous processes for this user ID. 2627.It Fl v Ar virtualmem 2628The maximal virtual size of a process, in kilobytes. 2629.It Fl w Ar swapuse 2630The maximum amount of swap space reserved or used for this user ID, 2631in kilobytes. 2632.El 2633.It Ic umask Oo Fl S Oc Op Ar mask 2634Set the file creation mask (see 2635.Xr umask 2 ) 2636to the octal or symbolic (see 2637.Xr chmod 1 ) 2638value specified by 2639.Ar mask . 2640If the argument is omitted, the current mask value is printed. 2641If the 2642.Fl S 2643option is specified, the output is symbolic, otherwise the output is octal. 2644.It Ic unalias Oo Fl a Oc Op Ar name ... 2645The specified alias names are removed. 2646If 2647.Fl a 2648is specified, all aliases are removed. 2649.It Ic unset Oo Fl fv Oc Ar name ... 2650The specified variables or functions are unset and unexported. 2651If the 2652.Fl v 2653option is specified or no options are given, the 2654.Ar name 2655arguments are treated as variable names. 2656If the 2657.Fl f 2658option is specified, the 2659.Ar name 2660arguments are treated as function names. 2661.It Ic wait Op Ar job ... 2662Wait for each specified 2663.Ar job 2664to complete and return the exit status of the last process in the 2665last specified 2666.Ar job . 2667If any 2668.Ar job 2669specified is unknown to the shell, it is treated as if it 2670were a known job that exited with exit status 127. 2671If no operands are given, wait for all jobs to complete 2672and return an exit status of zero. 2673.El 2674.Ss Commandline Editing 2675When 2676.Nm 2677is being used interactively from a terminal, the current command 2678and the command history 2679(see 2680.Ic fc 2681in 2682.Sx Built-in Commands ) 2683can be edited using 2684.Nm vi Ns -mode 2685command line editing. 2686This mode uses commands similar 2687to a subset of those described in the 2688.Xr vi 1 2689man page. 2690The command 2691.Dq Li "set -o vi" 2692(or 2693.Dq Li "set -V" ) 2694enables 2695.Nm vi Ns -mode 2696editing and places 2697.Nm 2698into 2699.Nm vi 2700insert mode. 2701With 2702.Nm vi Ns -mode 2703enabled, 2704.Nm 2705can be switched between insert mode and command mode by typing 2706.Aq ESC . 2707Hitting 2708.Aq return 2709while in command mode will pass the line to the shell. 2710.Pp 2711Similarly, the 2712.Dq Li "set -o emacs" 2713(or 2714.Dq Li "set -E" ) 2715command can be used to enable a subset of 2716.Nm emacs Ns -style 2717command line editing features. 2718.Sh ENVIRONMENT 2719The following environment variables affect the execution of 2720.Nm : 2721.Bl -tag -width ".Ev LANGXXXXXX" 2722.It Ev ENV 2723Initialization file for interactive shells. 2724.It Ev LANG , Ev LC_* 2725Locale settings. 2726These are inherited by children of the shell, 2727and is used in a limited manner by the shell itself. 2728.It Ev PWD 2729An absolute pathname for the current directory, 2730possibly containing symbolic links. 2731This is used and updated by the shell. 2732.It Ev TERM 2733The default terminal setting for the shell. 2734This is inherited by children of the shell, and is used in the history 2735editing modes. 2736.El 2737.Pp 2738Additionally, all environment variables are turned into shell variables 2739at startup, 2740which may affect the shell as described under 2741.Sx Special Variables . 2742.Sh FILES 2743.Bl -tag -width "/etc/suid_profileXX" -compact 2744.It Pa ~/.profile 2745User's login profile. 2746.It Pa /etc/profile 2747System login profile. 2748.It Pa /etc/shells 2749Shell database. 2750.It Pa /etc/suid_profile 2751Privileged shell profile. 2752.El 2753.Sh EXIT STATUS 2754Errors that are detected by the shell, such as a syntax error, will 2755cause the shell to exit with a non-zero exit status. 2756If the shell is not an interactive shell, the execution of the shell 2757file will be aborted. 2758Otherwise the shell will return the exit status of the last command 2759executed, or if the 2760.Ic exit 2761builtin is used with a numeric argument, it 2762will return the argument. 2763.Sh SEE ALSO 2764.Xr builtin 1 , 2765.Xr chsh 1 , 2766.Xr echo 1 , 2767.Xr ed 1 , 2768.Xr emacs 1 , 2769.Xr kill 1 , 2770.Xr printf 1 , 2771.Xr pwd 1 , 2772.Xr test 1 , 2773.Xr vi 1 , 2774.Xr execve 2 , 2775.Xr getrlimit 2 , 2776.Xr umask 2 , 2777.Xr wctype 3 , 2778.Xr editrc 5 , 2779.Xr shells 5 2780.Sh HISTORY 2781A 2782.Nm 2783command, the Thompson shell, appeared in 2784.At v1 . 2785It was superseded in 2786.At v7 2787by the Bourne shell, which inherited the name 2788.Nm . 2789.Pp 2790This version of 2791.Nm 2792was rewritten in 1989 under the 2793.Bx 2794license after the Bourne shell from 2795.At V.4 . 2796.Sh AUTHORS 2797This version of 2798.Nm 2799was originally written by 2800.An Kenneth Almquist . 2801.Sh BUGS 2802The 2803.Nm 2804utility does not recognize multibyte characters other than UTF-8. 2805Splitting using 2806.Va IFS 2807and the line editing library 2808.Xr editline 3 2809do not recognize multibyte characters. 2810