19ddb49cbSWarner Losh.\"- 24b88c807SRodney W. Grimes.\" Copyright (c) 1991, 1993 34b88c807SRodney W. Grimes.\" The Regents of the University of California. All rights reserved. 44b88c807SRodney W. Grimes.\" 54b88c807SRodney W. Grimes.\" This code is derived from software contributed to Berkeley by 64b88c807SRodney W. Grimes.\" Kenneth Almquist. 74b88c807SRodney W. Grimes.\" 84b88c807SRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without 94b88c807SRodney W. Grimes.\" modification, are permitted provided that the following conditions 104b88c807SRodney W. Grimes.\" are met: 114b88c807SRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright 124b88c807SRodney W. Grimes.\" notice, this list of conditions and the following disclaimer. 134b88c807SRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright 144b88c807SRodney W. Grimes.\" notice, this list of conditions and the following disclaimer in the 154b88c807SRodney W. Grimes.\" documentation and/or other materials provided with the distribution. 164b88c807SRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors 174b88c807SRodney W. Grimes.\" may be used to endorse or promote products derived from this software 184b88c807SRodney W. Grimes.\" without specific prior written permission. 194b88c807SRodney W. Grimes.\" 204b88c807SRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 214b88c807SRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 224b88c807SRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 234b88c807SRodney W. Grimes.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 244b88c807SRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 254b88c807SRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 264b88c807SRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 274b88c807SRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 284b88c807SRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 294b88c807SRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 304b88c807SRodney W. Grimes.\" SUCH DAMAGE. 314b88c807SRodney W. Grimes.\" 32ab72124fSSteve Price.\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95 332a456239SPeter Wemm.\" $FreeBSD$ 344b88c807SRodney W. Grimes.\" 35128dc4a2STim J. Robbins.Dd July 3, 2004 36ab72124fSSteve Price.Dt SH 1 37caa2db3bSRuslan Ermilov.Os 38ab72124fSSteve Price.Sh NAME 39ab72124fSSteve Price.Nm sh 40ab72124fSSteve Price.Nd command interpreter (shell) 41ab72124fSSteve Price.Sh SYNOPSIS 42ab72124fSSteve Price.Nm 437e1975c2STim J. Robbins.Op Fl /+abCEefIimnPpsTuVvx 44ab72124fSSteve Price.Op Fl /+o Ar longname 45c7a197e1SWolfram Schneider.Op Fl c Ar string 4681e9cda2SRuslan Ermilov.Op Ar arg ... 47ab72124fSSteve Price.Sh DESCRIPTION 48e918fc8fSSheldon HearnThe 49e918fc8fSSheldon Hearn.Nm 50e918fc8fSSheldon Hearnutility is the standard command interpreter for the system. 51ab72124fSSteve PriceThe current version of 52ab72124fSSteve Price.Nm 53ab72124fSSteve Priceis in the process of being changed to 54ab72124fSSteve Priceconform with the 55ab72124fSSteve Price.St -p1003.2 56eccea571SRuslan Ermilovspecification for the shell. 57eccea571SRuslan ErmilovThis version has many features which make 58ab72124fSSteve Priceit appear 594b88c807SRodney W. Grimessimilar in some respects to the Korn shell, but it is not a Korn 60fbc8f8a2SJens Schweikhardtshell clone like pdksh. 6149e11e3aSSheldon HearnOnly features 624b88c807SRodney W. Grimesdesignated by POSIX, plus a few Berkeley extensions, are being 63ab72124fSSteve Priceincorporated into this shell. 6449e11e3aSSheldon HearnThis man page is not intended to be a tutorial nor a complete 654b88c807SRodney W. Grimesspecification of the shell. 66ab72124fSSteve Price.Ss Overview 674b88c807SRodney W. GrimesThe shell is a command that reads lines from 684b88c807SRodney W. Grimeseither a file or the terminal, interprets them, and 69e6d3cf26SSheldon Hearngenerally executes other commands. 7049e11e3aSSheldon HearnIt is the program that is started when a user logs into the system, 7149e11e3aSSheldon Hearnalthough a user can select a different shell with the 72c644db6aSSheldon Hearn.Xr chsh 1 7349e11e3aSSheldon Hearncommand. 744b88c807SRodney W. GrimesThe shell 754b88c807SRodney W. Grimesimplements a language that has flow control constructs, 764b88c807SRodney W. Grimesa macro facility that provides a variety of features in 778eed22b1SJens Schweikhardtaddition to data storage, along with built-in history and line 78eccea571SRuslan Ermilovediting capabilities. 79eccea571SRuslan ErmilovIt incorporates many features to 804b88c807SRodney W. Grimesaid interactive use and has the advantage that the interpretative 814b88c807SRodney W. Grimeslanguage is common to both interactive and non-interactive 82eccea571SRuslan Ermilovuse (shell scripts). 83eccea571SRuslan ErmilovThat is, commands can be typed directly 8449e11e3aSSheldon Hearnto the running shell or can be put into a file, 8549e11e3aSSheldon Hearnwhich can be executed directly by the shell. 86ab72124fSSteve Price.Ss Invocation 8749e11e3aSSheldon Hearn.\" 8849e11e3aSSheldon Hearn.\" XXX This next sentence is incredibly confusing. 8949e11e3aSSheldon Hearn.\" 9049e11e3aSSheldon HearnIf no arguments are present and if the standard input of the shell 9149e11e3aSSheldon Hearnis connected to a terminal 9249e11e3aSSheldon Hearn(or if the 9349e11e3aSSheldon Hearn.Fl i 9449e11e3aSSheldon Hearnoption is set), 95eccea571SRuslan Ermilovthe shell is considered an interactive shell. 96eccea571SRuslan ErmilovAn interactive shell 974b88c807SRodney W. Grimesgenerally prompts before each command and handles programming 984b88c807SRodney W. Grimesand command errors differently (as described below). 994b88c807SRodney W. GrimesWhen first starting, the shell inspects argument 0, and 10049e11e3aSSheldon Hearnif it begins with a dash 101a762afe5SGiorgos Keramidas.Pq Ql - , 10249e11e3aSSheldon Hearnthe shell is also considered a login shell. 10349e11e3aSSheldon HearnThis is normally done automatically by the system 104eccea571SRuslan Ermilovwhen the user first logs in. 105eccea571SRuslan ErmilovA login shell first reads commands 106ab72124fSSteve Pricefrom the files 107ab72124fSSteve Price.Pa /etc/profile 10849e11e3aSSheldon Hearnand then 109ab72124fSSteve Price.Pa .profile 110eccea571SRuslan Ermilovif they exist. 111eccea571SRuslan ErmilovIf the environment variable 112ab72124fSSteve Price.Ev ENV 113ab72124fSSteve Priceis set on entry to a shell, or is set in the 114ab72124fSSteve Price.Pa .profile 11549e11e3aSSheldon Hearnof a login shell, the shell then reads commands from the file named in 116ab72124fSSteve Price.Ev ENV . 117ab72124fSSteve PriceTherefore, a user should place commands that are to be executed only 118ab72124fSSteve Priceat login time in the 119ab72124fSSteve Price.Pa .profile 120ab72124fSSteve Pricefile, and commands that are executed for every shell inside the 121ab72124fSSteve Price.Ev ENV 122e6d3cf26SSheldon Hearnfile. 12349e11e3aSSheldon HearnThe user can set the 124ab72124fSSteve Price.Ev ENV 12549e11e3aSSheldon Hearnvariable to some file by placing the following line in the file 126ab72124fSSteve Price.Pa .profile 12749e11e3aSSheldon Hearnin the home directory, 128ab72124fSSteve Pricesubstituting for 129ab72124fSSteve Price.Pa .shinit 13049e11e3aSSheldon Hearnthe filename desired: 13149e11e3aSSheldon Hearn.Pp 13249e11e3aSSheldon Hearn.Dl ENV=$HOME/.shinit; export ENV 13349e11e3aSSheldon Hearn.Pp 13449e11e3aSSheldon HearnThe first non-option argument specified on the command line 13549e11e3aSSheldon Hearnwill be treated as the 1364b88c807SRodney W. Grimesname of a file from which to read commands (a shell script), and 1374b88c807SRodney W. Grimesthe remaining arguments are set as the positional parameters 138eccea571SRuslan Ermilovof the shell ($1, $2, etc). 139eccea571SRuslan ErmilovOtherwise, the shell reads commands 1404b88c807SRodney W. Grimesfrom its standard input. 141ea76be72SSteve Price.Pp 142ea76be72SSteve PriceUnlike older versions of 143ea76be72SSteve Price.Nm 144ea76be72SSteve Pricethe 145ea76be72SSteve Price.Ev ENV 146eccea571SRuslan Ermilovscript is only sourced on invocation of interactive shells. 147eccea571SRuslan ErmilovThis 148ea76be72SSteve Pricecloses a well-known, and sometimes easily exploitable security 149ea76be72SSteve Pricehole related to poorly thought out 150ea76be72SSteve Price.Ev ENV 151ea76be72SSteve Pricescripts. 152ab72124fSSteve Price.Ss Argument List Processing 153ab72124fSSteve PriceAll of the single letter options to 154ab72124fSSteve Price.Nm 15549e11e3aSSheldon Hearnhave a corresponding long name, 15649e11e3aSSheldon Hearnwith the exception of 15749e11e3aSSheldon Hearn.Fl c 15849e11e3aSSheldon Hearnand 15949e11e3aSSheldon Hearn.Fl /+o . 16049e11e3aSSheldon HearnThese long names are provided next to the single letter options 16149e11e3aSSheldon Hearnin the descriptions below. 16249e11e3aSSheldon HearnThe long name for an option may be specified as an argument to the 16349e11e3aSSheldon Hearn.Fl /+o 16449e11e3aSSheldon Hearnoption of 165facc6767SRuslan Ermilov.Nm . 16649e11e3aSSheldon HearnOnce the shell is running, 16749e11e3aSSheldon Hearnthe long name for an option may be specified as an argument to the 16849e11e3aSSheldon Hearn.Fl /+o 16949e11e3aSSheldon Hearnoption of the 170c644db6aSSheldon Hearn.Ic set 1718eed22b1SJens Schweikhardtbuilt-in command 17249e11e3aSSheldon Hearn(described later in the section called 1738eed22b1SJens Schweikhardt.Sx Built-in Commands ) . 17449e11e3aSSheldon HearnIntroducing an option with a dash 175a762afe5SGiorgos Keramidas.Pq Ql - 17649e11e3aSSheldon Hearnenables the option, 17749e11e3aSSheldon Hearnwhile using a plus 178a762afe5SGiorgos Keramidas.Pq Ql + 17949e11e3aSSheldon Hearndisables the option. 18049e11e3aSSheldon HearnA 18149e11e3aSSheldon Hearn.Dq Li -- 182fab26805SJoseph Koshyor plain 183a762afe5SGiorgos Keramidas.Dq Ql - 184fab26805SJoseph Koshywill stop option processing and will force the remaining 185fab26805SJoseph Koshywords on the command line to be treated as arguments. 18649e11e3aSSheldon HearnThe 18749e11e3aSSheldon Hearn.Fl /+o 18849e11e3aSSheldon Hearnand 18949e11e3aSSheldon Hearn.Fl c 19049e11e3aSSheldon Hearnoptions do not have long names. 19149e11e3aSSheldon HearnThey take arguments and are described after the single letter options. 19281e9cda2SRuslan Ermilov.Bl -tag -width indent 193ab72124fSSteve Price.It Fl a Li allexport 19449e11e3aSSheldon HearnFlag variables for export when assignments are made to them. 195ab72124fSSteve Price.It Fl b Li notify 196ab72124fSSteve PriceEnable asynchronous notification of background job 197ab72124fSSteve Pricecompletion. 198c4d9468eSRuslan Ermilov(UNIMPLEMENTED) 19938afdcbcSGiorgos Keramidas.It Fl c Li string 20038afdcbcSGiorgos KeramidasRead commands from the 20138afdcbcSGiorgos Keramidas.Ar string 20238afdcbcSGiorgos Keramidasoperand instead of from the standard input. 20338afdcbcSGiorgos KeramidasKeep in mind that this option only accepts a single string as its 20438afdcbcSGiorgos Keramidasargument, hence multi-word strings must be quoted. 205ab72124fSSteve Price.It Fl C Li noclobber 206c644db6aSSheldon HearnDo not overwrite existing files with 20749e11e3aSSheldon Hearn.Dq Li > . 208ab72124fSSteve Price.It Fl E Li emacs 2098eed22b1SJens SchweikhardtEnable the built-in 210ab72124fSSteve Price.Xr emacs 1 21149e11e3aSSheldon Hearncommand line editor (disables the 212ab72124fSSteve Price.Fl V 21349e11e3aSSheldon Hearnoption if it has been set). 214ab72124fSSteve Price.It Fl e Li errexit 21549e11e3aSSheldon HearnExit immediately if any untested command fails in non-interactive mode. 2164b88c807SRodney W. GrimesThe exit status of a command is considered to be 2174b88c807SRodney W. Grimesexplicitly tested if the command is used to control 2184b88c807SRodney W. Grimesan if, elif, while, or until; or if the command is the left 219ab72124fSSteve Pricehand operand of an 22049e11e3aSSheldon Hearn.Dq Li && 221ab72124fSSteve Priceor 22249e11e3aSSheldon Hearn.Dq Li || 223ab72124fSSteve Priceoperator. 224ab72124fSSteve Price.It Fl f Li noglob 2254b88c807SRodney W. GrimesDisable pathname expansion. 226ab72124fSSteve Price.It Fl I Li ignoreeof 22749e11e3aSSheldon HearnIgnore 22849e11e3aSSheldon Hearn.Dv EOF Ns ' Ns s 22949e11e3aSSheldon Hearnfrom input when in interactive mode. 230ab72124fSSteve Price.It Fl i Li interactive 231ab72124fSSteve PriceForce the shell to behave interactively. 232ab72124fSSteve Price.It Fl m Li monitor 233ab72124fSSteve PriceTurn on job control (set automatically when interactive). 234ab72124fSSteve Price.It Fl n Li noexec 2354b88c807SRodney W. GrimesIf not interactive, read commands but do not 236eccea571SRuslan Ermilovexecute them. 237eccea571SRuslan ErmilovThis is useful for checking the 2384b88c807SRodney W. Grimessyntax of shell scripts. 2397e1975c2STim J. Robbins.It Fl P Li physical 2407e1975c2STim J. RobbinsChange the default for the 2417e1975c2STim J. Robbins.Ic cd 2427e1975c2STim J. Robbinsand 2437e1975c2STim J. Robbins.Ic pwd 2447e1975c2STim J. Robbinscommands from 2457e1975c2STim J. Robbins.Fl L 2467e1975c2STim J. Robbins(logical directory layout) 2477e1975c2STim J. Robbinsto 2487e1975c2STim J. Robbins.Fl P 2497e1975c2STim J. Robbins(physical directory layout). 250ab72124fSSteve Price.It Fl p Li privileged 251eccea571SRuslan ErmilovTurn on privileged mode. 252eccea571SRuslan ErmilovThis mode is enabled on startup 253621a31c6SSteve Priceif either the effective user or group id is not equal to the 254eccea571SRuslan Ermilovreal user or group id. 255eccea571SRuslan ErmilovTurning this mode off sets the 256621a31c6SSteve Priceeffective user and group ids to the real user and group ids. 25749e11e3aSSheldon HearnWhen this mode is enabled for interactive shells, the file 258ab72124fSSteve Price.Pa /etc/suid_profile 25949e11e3aSSheldon Hearnis sourced instead of 26049e11e3aSSheldon Hearn.Pa ~/.profile 261ab72124fSSteve Priceafter 262ab72124fSSteve Price.Pa /etc/profile 26349e11e3aSSheldon Hearnis sourced, and the contents of the 264ab72124fSSteve Price.Ev ENV 26549e11e3aSSheldon Hearnvariable are ignored. 266ab72124fSSteve Price.It Fl s Li stdin 2674b88c807SRodney W. GrimesRead commands from standard input (set automatically 268eccea571SRuslan Ermilovif no file arguments are present). 269eccea571SRuslan ErmilovThis option has 2704b88c807SRodney W. Grimesno effect when set after the shell has already started 271eccea571SRuslan Ermilovrunning (i.e., when set with the 272c644db6aSSheldon Hearn.Ic set 2736b15476eSSheldon Hearncommand). 274304199ceSTom Rhodes.It Fl T Li trapsasync 275e6d3cf26SSheldon HearnWhen waiting for a child, execute traps immediately. 276e6d3cf26SSheldon HearnIf this option is not set, 277e6d3cf26SSheldon Hearntraps are executed after the child exits, 278e6d3cf26SSheldon Hearnas specified in 279af5eb6fcSMaxim Konovalov.St -p1003.2 . 2806b15476eSSheldon HearnThis nonstandard option is useful for putting guarding shells around 281eccea571SRuslan Ermilovchildren that block signals. 282eccea571SRuslan ErmilovThe surrounding shell may kill the child 2836b15476eSSheldon Hearnor it may just return control to the tty and leave the child alone, 2846b15476eSSheldon Hearnlike this: 285c1c72a3cSMartin Cracauer.Bd -literal -offset indent 286c1c72a3cSMartin Cracauersh -T -c "trap 'exit 1' 2 ; some-blocking-program" 287c1c72a3cSMartin Cracauer.Ed 288c1c72a3cSMartin Cracauer.Pp 289ab72124fSSteve Price.It Fl u Li nounset 290ab72124fSSteve PriceWrite a message to standard error when attempting 291ab72124fSSteve Priceto expand a variable that is not set, and if the 292ab72124fSSteve Priceshell is not interactive, exit immediately. 293ab72124fSSteve Price.It Fl V Li vi 2948eed22b1SJens SchweikhardtEnable the built-in 295ab72124fSSteve Price.Xr vi 1 296ab72124fSSteve Pricecommand line editor (disables 297ab72124fSSteve Price.Fl E 298ab72124fSSteve Priceif it has been set). 299ab72124fSSteve Price.It Fl v Li verbose 300ab72124fSSteve PriceThe shell writes its input to standard error 301eccea571SRuslan Ermilovas it is read. 302eccea571SRuslan ErmilovUseful for debugging. 303ab72124fSSteve Price.It Fl x Li xtrace 30449e11e3aSSheldon HearnWrite each command 30549e11e3aSSheldon Hearn(preceded by 3066fa13ec0SRuslan Ermilov.Dq Li "+ " ) 30749e11e3aSSheldon Hearnto standard error before it is executed. 30849e11e3aSSheldon HearnUseful for debugging. 30949e11e3aSSheldon Hearn.El 31049e11e3aSSheldon Hearn.Pp 31149e11e3aSSheldon HearnThe 31249e11e3aSSheldon Hearn.Fl /+o 31349e11e3aSSheldon Hearnoption takes as its only argument the long name of an option 31449e11e3aSSheldon Hearnto be enabled or disabled. 31549e11e3aSSheldon HearnFor example, the following two invocations of 31649e11e3aSSheldon Hearn.Nm 3178eed22b1SJens Schweikhardtboth enable the built-in 31849e11e3aSSheldon Hearn.Xr emacs 1 31949e11e3aSSheldon Hearncommand line editor: 32049e11e3aSSheldon Hearn.Bd -literal -offset indent 32149e11e3aSSheldon Hearnset -E 32249e11e3aSSheldon Hearnset -o emacs 32349e11e3aSSheldon Hearn.Ed 324d513af6aSTim J. Robbins.Pp 325d513af6aSTim J. RobbinsIf used without an argument, the 326d513af6aSTim J. Robbins.Fl o 327d513af6aSTim J. Robbinsoption displays the current option settings in a human-readable format. 328d513af6aSTim J. RobbinsIf 329d513af6aSTim J. Robbins.Cm +o 330d513af6aSTim J. Robbinsis used without an argument, the current option settings are output 331d513af6aSTim J. Robbinsin a format suitable for re-input into the shell. 332ab72124fSSteve Price.Ss Lexical Structure 3334b88c807SRodney W. GrimesThe shell reads input in terms of lines from a file and breaks 3344b88c807SRodney W. Grimesit up into words at whitespace (blanks and tabs), and at 3354b88c807SRodney W. Grimescertain sequences of 3366b15476eSSheldon Hearncharacters called 3376b15476eSSheldon Hearn.Dq operators , 3386b15476eSSheldon Hearnwhich are special to the shell. 3394b88c807SRodney W. GrimesThere are two types of operators: control operators and 3404b88c807SRodney W. Grimesredirection operators (their meaning is discussed later). 341ab72124fSSteve PriceThe following is a list of valid operators: 34281e9cda2SRuslan Ermilov.Bl -tag -width indent 34349e11e3aSSheldon Hearn.It Control operators: 34449e11e3aSSheldon Hearn.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 34581e9cda2SRuslan Ermilov.It Li & Ta Li && Ta Li ( Ta Li ) Ta Li \en 34681e9cda2SRuslan Ermilov.It Li ;; Ta Li ; Ta Li | Ta Li || 34749e11e3aSSheldon Hearn.El 34849e11e3aSSheldon Hearn.It Redirection operators: 3494682f420SBrian Somers.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 35081e9cda2SRuslan Ermilov.It Li < Ta Li > Ta Li << Ta Li >> Ta Li <> 35181e9cda2SRuslan Ermilov.It Li <& Ta Li >& Ta Li <<- Ta Li >| 35249e11e3aSSheldon Hearn.El 353ab72124fSSteve Price.El 354ab72124fSSteve Price.Ss Quoting 3554b88c807SRodney W. GrimesQuoting is used to remove the special meaning of certain characters 3564b88c807SRodney W. Grimesor words to the shell, such as operators, whitespace, or 357eccea571SRuslan Ermilovkeywords. 358eccea571SRuslan ErmilovThere are three types of quoting: matched single quotes, 3594b88c807SRodney W. Grimesmatched double quotes, and backslash. 36081e9cda2SRuslan Ermilov.Bl -tag -width indent 361ab72124fSSteve Price.It Single Quotes 3624b88c807SRodney W. GrimesEnclosing characters in single quotes preserves the literal 363ab0a2172SSteve Pricemeaning of all the characters (except single quotes, making 364ab0a2172SSteve Priceit impossible to put single-quotes in a single-quoted string). 365ab72124fSSteve Price.It Double Quotes 3664b88c807SRodney W. GrimesEnclosing characters within double quotes preserves the literal 36749e11e3aSSheldon Hearnmeaning of all characters except dollarsign 368a762afe5SGiorgos Keramidas.Pq Ql $ , 36949e11e3aSSheldon Hearnbackquote 370a762afe5SGiorgos Keramidas.Pq Ql ` , 37149e11e3aSSheldon Hearnand backslash 372a762afe5SGiorgos Keramidas.Pq Ql \e . 37349e11e3aSSheldon HearnThe backslash inside double quotes is historically weird. 37449e11e3aSSheldon HearnIt remains literal unless it precedes the following characters, 37549e11e3aSSheldon Hearnwhich it serves to quote: 37649e11e3aSSheldon Hearn.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 37781e9cda2SRuslan Ermilov.It Li $ Ta Li ` Ta Li \&" Ta Li \e\ Ta Li \en 37849e11e3aSSheldon Hearn.El 379ab72124fSSteve Price.It Backslash 380ab72124fSSteve PriceA backslash preserves the literal meaning of the following 38149e11e3aSSheldon Hearncharacter, with the exception of the newline character 382a762afe5SGiorgos Keramidas.Pq Ql \en . 38349e11e3aSSheldon HearnA backslash preceding a newline is treated as a line continuation. 384ab72124fSSteve Price.El 385ab72124fSSteve Price.Ss Reserved Words 3864b88c807SRodney W. GrimesReserved words are words that have special meaning to the 3874b88c807SRodney W. Grimesshell and are recognized at the beginning of a line and 388eccea571SRuslan Ermilovafter a control operator. 389eccea571SRuslan ErmilovThe following are reserved words: 39049e11e3aSSheldon Hearn.Bl -column "doneXX" "elifXX" "elseXX" "untilXX" "whileX" -offset center 39181e9cda2SRuslan Ermilov.It Li \&! Ta { Ta } Ta Ic case Ta Ic do 39281e9cda2SRuslan Ermilov.It Ic done Ta Ic elif Ta Ic else Ta Ic esac Ta Ic fi 39381e9cda2SRuslan Ermilov.It Ic for Ta Ic if Ta Ic then Ta Ic until Ta Ic while 39449e11e3aSSheldon Hearn.El 395ab72124fSSteve Price.Ss Aliases 396ab72124fSSteve PriceAn alias is a name and corresponding value set using the 397c644db6aSSheldon Hearn.Ic alias 398eccea571SRuslan Ermilovbuilt-in command. 399eccea571SRuslan ErmilovWhenever a reserved word may occur (see above), 4004b88c807SRodney W. Grimesand after checking for reserved words, the shell 401e6d3cf26SSheldon Hearnchecks the word to see if it matches an alias. 402e6d3cf26SSheldon HearnIf it does, it replaces it in the input stream with its value. 403e6d3cf26SSheldon HearnFor example, if there is an alias called 40449e11e3aSSheldon Hearn.Dq Li lf 4056b15476eSSheldon Hearnwith the value 40649e11e3aSSheldon Hearn.Dq Li ls -F , 4074b88c807SRodney W. Grimesthen the input 408ab72124fSSteve Price.Bd -literal -offset indent 40949e11e3aSSheldon Hearnlf foobar 410ab72124fSSteve Price.Ed 411ab72124fSSteve Price.Pp 4124b88c807SRodney W. Grimeswould become 413ab72124fSSteve Price.Bd -literal -offset indent 41449e11e3aSSheldon Hearnls -F foobar 415ab72124fSSteve Price.Ed 416ab72124fSSteve Price.Pp 4174b88c807SRodney W. GrimesAliases provide a convenient way for naive users to 4184b88c807SRodney W. Grimescreate shorthands for commands without having to learn how 419eccea571SRuslan Ermilovto create functions with arguments. 420eccea571SRuslan ErmilovThey can also be 421eccea571SRuslan Ermilovused to create lexically obscure code. 422eccea571SRuslan ErmilovThis use is discouraged. 423ab72124fSSteve Price.Ss Commands 4244b88c807SRodney W. GrimesThe shell interprets the words it reads according to a 4254b88c807SRodney W. Grimeslanguage, the specification of which is outside the scope 426ab72124fSSteve Priceof this man page (refer to the BNF in the 427ab72124fSSteve Price.St -p1003.2 428eccea571SRuslan Ermilovdocument). 429eccea571SRuslan ErmilovEssentially though, a line is read and if 4304b88c807SRodney W. Grimesthe first word of the line (or after a control operator) 4314b88c807SRodney W. Grimesis not a reserved word, then the shell has recognized a 432eccea571SRuslan Ermilovsimple command. 433eccea571SRuslan ErmilovOtherwise, a complex command or some 4344b88c807SRodney W. Grimesother special construct may have been recognized. 435ab72124fSSteve Price.Ss Simple Commands 4364b88c807SRodney W. GrimesIf a simple command has been recognized, the shell performs 4374b88c807SRodney W. Grimesthe following actions: 438ab72124fSSteve Price.Bl -enum 439ab72124fSSteve Price.It 4406b15476eSSheldon HearnLeading words of the form 44149e11e3aSSheldon Hearn.Dq Li name=value 4426b15476eSSheldon Hearnare stripped off and assigned to the environment of 443eccea571SRuslan Ermilovthe simple command. 444eccea571SRuslan ErmilovRedirection operators and 4454b88c807SRodney W. Grimestheir arguments (as described below) are stripped 4464b88c807SRodney W. Grimesoff and saved for processing. 447ab72124fSSteve Price.It 448ab72124fSSteve PriceThe remaining words are expanded as described in 4496b15476eSSheldon Hearnthe section called 4506b15476eSSheldon Hearn.Sx Word Expansions , 4516b15476eSSheldon Hearnand the first remaining word is considered the command 452eccea571SRuslan Ermilovname and the command is located. 453eccea571SRuslan ErmilovThe remaining 4544b88c807SRodney W. Grimeswords are considered the arguments of the command. 4556b15476eSSheldon HearnIf no command name resulted, then the 45649e11e3aSSheldon Hearn.Dq Li name=value 4574b88c807SRodney W. Grimesvariable assignments recognized in 1) affect the 4584b88c807SRodney W. Grimescurrent shell. 459ab72124fSSteve Price.It 460ab72124fSSteve PriceRedirections are performed as described in 4614b88c807SRodney W. Grimesthe next section. 462ab72124fSSteve Price.El 463ab72124fSSteve Price.Ss Redirections 4644b88c807SRodney W. GrimesRedirections are used to change where a command reads its input 465eccea571SRuslan Ermilovor sends its output. 466eccea571SRuslan ErmilovIn general, redirections open, close, or 467eccea571SRuslan Ermilovduplicate an existing reference to a file. 468eccea571SRuslan ErmilovThe overall format 4694b88c807SRodney W. Grimesused for redirection is: 47049e11e3aSSheldon Hearn.Pp 471ab72124fSSteve Price.Dl [n] redir-op file 47249e11e3aSSheldon Hearn.Pp 47349e11e3aSSheldon HearnThe 47449e11e3aSSheldon Hearn.Ql redir-op 47549e11e3aSSheldon Hearnis one of the redirection operators mentioned 476eccea571SRuslan Ermilovpreviously. 477eccea571SRuslan ErmilovThe following gives some examples of how these 47849e11e3aSSheldon Hearnoperators can be used. 47949e11e3aSSheldon HearnNote that stdin and stdout are commonly used abbreviations 48049e11e3aSSheldon Hearnfor standard input and standard output respectively. 48149e11e3aSSheldon Hearn.Bl -tag -width "1234567890XX" -offset indent 48249e11e3aSSheldon Hearn.It Li [n]> file 48349e11e3aSSheldon Hearnredirect stdout (or file descriptor n) to file 48449e11e3aSSheldon Hearn.It Li [n]>| file 48549e11e3aSSheldon Hearnsame as above, but override the 48649e11e3aSSheldon Hearn.Fl C 48749e11e3aSSheldon Hearnoption 48849e11e3aSSheldon Hearn.It Li [n]>> file 48949e11e3aSSheldon Hearnappend stdout (or file descriptor n) to file 49049e11e3aSSheldon Hearn.It Li [n]< file 49149e11e3aSSheldon Hearnredirect stdin (or file descriptor n) from file 4924682f420SBrian Somers.It Li [n]<> file 4934682f420SBrian Somersredirect stdin (or file descriptor n) to and from file 49449e11e3aSSheldon Hearn.It Li [n1]<&n2 49549e11e3aSSheldon Hearnduplicate stdin (or file descriptor n1) from file descriptor n2 49649e11e3aSSheldon Hearn.It Li [n]<&- 49749e11e3aSSheldon Hearnclose stdin (or file descriptor n) 49849e11e3aSSheldon Hearn.It Li [n1]>&n2 49949e11e3aSSheldon Hearnduplicate stdout (or file descriptor n1) to file descriptor n2 50049e11e3aSSheldon Hearn.It Li [n]>&- 50149e11e3aSSheldon Hearnclose stdout (or file descriptor n) 502ab72124fSSteve Price.El 503ab72124fSSteve Price.Pp 5046b15476eSSheldon HearnThe following redirection is often called a 5056b15476eSSheldon Hearn.Dq here-document . 506ab72124fSSteve Price.Bd -literal -offset indent 5074b88c807SRodney W. Grimes[n]<< delimiter 50849e11e3aSSheldon Hearn here-doc-text 50949e11e3aSSheldon Hearn ... 5104b88c807SRodney W. Grimesdelimiter 511ab72124fSSteve Price.Ed 512ab72124fSSteve Price.Pp 5134b88c807SRodney W. GrimesAll the text on successive lines up to the delimiter is 5144b88c807SRodney W. Grimessaved away and made available to the command on standard 515eccea571SRuslan Ermilovinput, or file descriptor n if it is specified. 516eccea571SRuslan ErmilovIf the delimiter 5174b88c807SRodney W. Grimesas specified on the initial line is quoted, then the here-doc-text 5184b88c807SRodney W. Grimesis treated literally, otherwise the text is subjected to 5194b88c807SRodney W. Grimesparameter expansion, command substitution, and arithmetic 5206b15476eSSheldon Hearnexpansion (as described in the section on 5216b15476eSSheldon Hearn.Sx Word Expansions ) . 5226b15476eSSheldon HearnIf the operator is 52349e11e3aSSheldon Hearn.Dq Li <<- 5246b15476eSSheldon Hearninstead of 52549e11e3aSSheldon Hearn.Dq Li << , 5266b15476eSSheldon Hearnthen leading tabs 5274b88c807SRodney W. Grimesin the here-doc-text are stripped. 528ab72124fSSteve Price.Ss Search and Execution 529ab0a2172SSteve PriceThere are three types of commands: shell functions, 5308eed22b1SJens Schweikhardtbuilt-in commands, and normal programs. 53149e11e3aSSheldon HearnThe command is searched for (by name) in that order. 53249e11e3aSSheldon HearnThe three types of commands are all executed in a different way. 533ab72124fSSteve Price.Pp 534ab0a2172SSteve PriceWhen a shell function is executed, all of the shell positional 535ab0a2172SSteve Priceparameters (except $0, which remains unchanged) are 5364b88c807SRodney W. Grimesset to the arguments of the shell function. 5374b88c807SRodney W. GrimesThe variables which are explicitly placed in the environment of 5384b88c807SRodney W. Grimesthe command (by placing assignments to them before the 5394b88c807SRodney W. Grimesfunction name) are made local to the function and are set 540e6d3cf26SSheldon Hearnto the values given. 541e6d3cf26SSheldon HearnThen the command given in the function definition is executed. 542e6d3cf26SSheldon HearnThe positional parameters are restored to their original values 543e6d3cf26SSheldon Hearnwhen the command completes. 544ab0a2172SSteve PriceThis all occurs within the current shell. 545ab72124fSSteve Price.Pp 5468eed22b1SJens SchweikhardtShell built-in commands are executed internally to the shell, without 547ab0a2172SSteve Pricespawning a new process. 548ab72124fSSteve Price.Pp 549c644db6aSSheldon HearnOtherwise, if the command name does not match a function 5508eed22b1SJens Schweikhardtor built-in command, the command is searched for as a normal 5514b88c807SRodney W. Grimesprogram in the file system (as described in the next section). 5524b88c807SRodney W. GrimesWhen a normal program is executed, the shell runs the program, 553e6d3cf26SSheldon Hearnpassing the arguments and the environment to the program. 554e6d3cf26SSheldon HearnIf the program is not a normal executable file 555eccea571SRuslan Ermilov(i.e., if it does not begin with the 5566b15476eSSheldon Hearn.Qq magic number 5576b15476eSSheldon Hearnwhose 558ab72124fSSteve Price.Tn ASCII 5596b15476eSSheldon Hearnrepresentation is 5606b15476eSSheldon Hearn.Qq #! , 56149e11e3aSSheldon Hearnresulting in an 562b4f0f4aaSRuslan Ermilov.Er ENOEXEC 56349e11e3aSSheldon Hearnreturn value from 56449e11e3aSSheldon Hearn.Xr execve 2 ) 565e6d3cf26SSheldon Hearnthe shell will interpret the program in a subshell. 566e6d3cf26SSheldon HearnThe child shell will reinitialize itself in this case, 567e6d3cf26SSheldon Hearnso that the effect will be 568e6d3cf26SSheldon Hearnas if a new shell had been invoked to handle the ad-hoc shell script, 569e6d3cf26SSheldon Hearnexcept that the location of hashed commands located in 5704b88c807SRodney W. Grimesthe parent shell will be remembered by the child. 571ab72124fSSteve Price.Pp 572ab0a2172SSteve PriceNote that previous versions of this document 573ab0a2172SSteve Priceand the source code itself misleadingly and sporadically 574ab0a2172SSteve Pricerefer to a shell script without a magic number 5756b15476eSSheldon Hearnas a 5766b15476eSSheldon Hearn.Qq shell procedure . 577ab72124fSSteve Price.Ss Path Search 5784b88c807SRodney W. GrimesWhen locating a command, the shell first looks to see if 579eccea571SRuslan Ermilovit has a shell function by that name. 580eccea571SRuslan ErmilovThen it looks for a 581eccea571SRuslan Ermilovbuilt-in command by that name. 582eccea571SRuslan ErmilovIf a built-in command is not found, 583ab0a2172SSteve Priceone of two things happen: 584ab72124fSSteve Price.Bl -enum 585ab72124fSSteve Price.It 586ab72124fSSteve PriceCommand names containing a slash are simply executed without 587ab0a2172SSteve Priceperforming any searches. 588ab72124fSSteve Price.It 589ab72124fSSteve PriceThe shell searches each entry in 590ab72124fSSteve Price.Ev PATH 591eccea571SRuslan Ermilovin turn for the command. 592eccea571SRuslan ErmilovThe value of the 593ab72124fSSteve Price.Ev PATH 594ab72124fSSteve Pricevariable should be a series of 595eccea571SRuslan Ermiloventries separated by colons. 596eccea571SRuslan ErmilovEach entry consists of a 5974b88c807SRodney W. Grimesdirectory name. 5984b88c807SRodney W. GrimesThe current directory 599ab0a2172SSteve Pricemay be indicated implicitly by an empty directory name, 600ab0a2172SSteve Priceor explicitly by a single period. 601ab72124fSSteve Price.El 602ab72124fSSteve Price.Ss Command Exit Status 6034b88c807SRodney W. GrimesEach command has an exit status that can influence the behavior 604eccea571SRuslan Ermilovof other shell commands. 605eccea571SRuslan ErmilovThe paradigm is that a command exits 6064b88c807SRodney W. Grimeswith zero for normal or success, and non-zero for failure, 607eccea571SRuslan Ermiloverror, or a false indication. 608eccea571SRuslan ErmilovThe man page for each command 6094b88c807SRodney W. Grimesshould indicate the various exit codes and what they mean. 6108eed22b1SJens SchweikhardtAdditionally, the built-in commands return exit codes, as does 611ab0a2172SSteve Pricean executed shell function. 612c351e089SJohn Polstra.Pp 613c351e089SJohn PolstraIf a command is terminated by a signal, its exit status is 128 plus 614eccea571SRuslan Ermilovthe signal number. 615eccea571SRuslan ErmilovSignal numbers are defined in the header file 616fe08efe6SRuslan Ermilov.In sys/signal.h . 617ab72124fSSteve Price.Ss Complex Commands 6184b88c807SRodney W. GrimesComplex commands are combinations of simple commands 6194b88c807SRodney W. Grimeswith control operators or reserved words, together creating a larger complex 620eccea571SRuslan Ermilovcommand. 621eccea571SRuslan ErmilovMore generally, a command is one of the following: 622ab72124fSSteve Price.Bl -item -offset indent 623ab72124fSSteve Price.It 624ab72124fSSteve Pricesimple command 625ab72124fSSteve Price.It 626ab72124fSSteve Pricepipeline 627ab72124fSSteve Price.It 628ab72124fSSteve Pricelist or compound-list 629ab72124fSSteve Price.It 630ab72124fSSteve Pricecompound command 631ab72124fSSteve Price.It 632ab72124fSSteve Pricefunction definition 633ab72124fSSteve Price.El 634ab72124fSSteve Price.Pp 6354b88c807SRodney W. GrimesUnless otherwise stated, the exit status of a command is 6364b88c807SRodney W. Grimesthat of the last simple command executed by the command. 637ab72124fSSteve Price.Ss Pipelines 6384b88c807SRodney W. GrimesA pipeline is a sequence of one or more commands separated 639eccea571SRuslan Ermilovby the control operator |. 640eccea571SRuslan ErmilovThe standard output of all but 6414b88c807SRodney W. Grimesthe last command is connected to the standard input 642eccea571SRuslan Ermilovof the next command. 643eccea571SRuslan ErmilovThe standard output of the last 644ab0a2172SSteve Pricecommand is inherited from the shell, as usual. 645ab72124fSSteve Price.Pp 6464b88c807SRodney W. GrimesThe format for a pipeline is: 64749e11e3aSSheldon Hearn.Pp 64849e11e3aSSheldon Hearn.Dl [!] command1 [ | command2 ...] 649ab72124fSSteve Price.Pp 6504b88c807SRodney W. GrimesThe standard output of command1 is connected to the standard 651eccea571SRuslan Ermilovinput of command2. 652eccea571SRuslan ErmilovThe standard input, standard output, or 6534b88c807SRodney W. Grimesboth of a command is considered to be assigned by the 6544b88c807SRodney W. Grimespipeline before any redirection specified by redirection 6554b88c807SRodney W. Grimesoperators that are part of the command. 656ab72124fSSteve Price.Pp 6574b88c807SRodney W. GrimesIf the pipeline is not in the background (discussed later), 6584b88c807SRodney W. Grimesthe shell waits for all commands to complete. 659ab72124fSSteve Price.Pp 660eccea571SRuslan ErmilovIf the reserved word 661eccea571SRuslan Ermilov.Ic !\& 662eccea571SRuslan Ermilovdoes not precede the pipeline, the 6634b88c807SRodney W. Grimesexit status is the exit status of the last command specified 664eccea571SRuslan Ermilovin the pipeline. 665eccea571SRuslan ErmilovOtherwise, the exit status is the logical 666eccea571SRuslan ErmilovNOT of the exit status of the last command. 667eccea571SRuslan ErmilovThat is, if 6684b88c807SRodney W. Grimesthe last command returns zero, the exit status is 1; if 6694b88c807SRodney W. Grimesthe last command returns greater than zero, the exit status 6704b88c807SRodney W. Grimesis zero. 671ab72124fSSteve Price.Pp 6724b88c807SRodney W. GrimesBecause pipeline assignment of standard input or standard 6734b88c807SRodney W. Grimesoutput or both takes place before redirection, it can be 674eccea571SRuslan Ermilovmodified by redirection. 675eccea571SRuslan ErmilovFor example: 676ab72124fSSteve Price.Pp 67749e11e3aSSheldon Hearn.Dl $ command1 2>&1 | command2 678ab72124fSSteve Price.Pp 67949e11e3aSSheldon Hearnsends both the standard output and standard error of 68049e11e3aSSheldon Hearn.Ql command1 68149e11e3aSSheldon Hearnto the standard input of 68249e11e3aSSheldon Hearn.Ql command2 . 68349e11e3aSSheldon Hearn.Pp 68449e11e3aSSheldon HearnA 68512e720d7SRuslan Ermilov.Dq Li \&; 68649e11e3aSSheldon Hearnor newline terminator causes the preceding 687e918fc8fSSheldon HearnAND-OR-list 688e918fc8fSSheldon Hearn(described below in the section called 689e918fc8fSSheldon Hearn.Sx Short-Circuit List Operators ) 690e918fc8fSSheldon Hearnto be executed sequentially; 691e918fc8fSSheldon Hearnan 692e918fc8fSSheldon Hearn.Dq Li & 693e918fc8fSSheldon Hearncauses asynchronous execution of the preceding AND-OR-list. 694ab72124fSSteve Price.Pp 69549e11e3aSSheldon HearnNote that unlike some other shells, 69649e11e3aSSheldon Hearn.Nm 69749e11e3aSSheldon Hearnexecutes each process in the pipeline as a child of the 69849e11e3aSSheldon Hearn.Nm 69949e11e3aSSheldon Hearnprocess. 7008eed22b1SJens SchweikhardtShell built-in commands are the exception to this rule. 70149e11e3aSSheldon HearnThey are executed in the current shell, although they do not affect its 70249e11e3aSSheldon Hearnenvironment when used in pipelines. 70349e11e3aSSheldon Hearn.Ss Background Commands (&) 7044b88c807SRodney W. GrimesIf a command is terminated by the control operator ampersand 705a762afe5SGiorgos Keramidas.Pq Ql & , 70649e11e3aSSheldon Hearnthe shell executes the command asynchronously; 70749e11e3aSSheldon Hearnthe shell does not wait for the command to finish 70849e11e3aSSheldon Hearnbefore executing the next command. 709ab72124fSSteve Price.Pp 7104b88c807SRodney W. GrimesThe format for running a command in background is: 711ab72124fSSteve Price.Bd -literal -offset indent 7124b88c807SRodney W. Grimescommand1 & [command2 & ...] 713ab72124fSSteve Price.Ed 714ab72124fSSteve Price.Pp 7154b88c807SRodney W. GrimesIf the shell is not interactive, the standard input of an 7164b88c807SRodney W. Grimesasynchronous command is set to /dev/null. 71749e11e3aSSheldon Hearn.Ss Lists (Generally Speaking) 7184b88c807SRodney W. GrimesA list is a sequence of zero or more commands separated by 7194b88c807SRodney W. Grimesnewlines, semicolons, or ampersands, 7204b88c807SRodney W. Grimesand optionally terminated by one of these three characters. 7214b88c807SRodney W. GrimesThe commands in a 7224b88c807SRodney W. Grimeslist are executed in the order they are written. 7234b88c807SRodney W. GrimesIf command is followed by an ampersand, the shell starts the 7248eed22b1SJens Schweikhardtcommand and immediately proceeds onto the next command; 7254b88c807SRodney W. Grimesotherwise it waits for the command to terminate before 7264b88c807SRodney W. Grimesproceeding to the next one. 727ab72124fSSteve Price.Ss Short-Circuit List Operators 72849e11e3aSSheldon Hearn.Dq Li && 7296b15476eSSheldon Hearnand 73049e11e3aSSheldon Hearn.Dq Li || 7316b15476eSSheldon Hearnare AND-OR list operators. 73249e11e3aSSheldon Hearn.Dq Li && 7336b15476eSSheldon Hearnexecutes the first command, and then executes the second command 7346b15476eSSheldon Hearnif the exit status of the first command is zero. 73549e11e3aSSheldon Hearn.Dq Li || 736120ac26dSMasafumi Max NAKANEis similar, but executes the second command if the exit 7376b15476eSSheldon Hearnstatus of the first command is nonzero. 73849e11e3aSSheldon Hearn.Dq Li && 7396b15476eSSheldon Hearnand 74049e11e3aSSheldon Hearn.Dq Li || 7414b88c807SRodney W. Grimesboth have the same priority. 74249e11e3aSSheldon Hearn.Ss Flow-Control Constructs (if, while, for, case) 74349e11e3aSSheldon HearnThe syntax of the 74449e11e3aSSheldon Hearn.Ic if 74549e11e3aSSheldon Hearncommand is: 74649e11e3aSSheldon Hearn.\" 74749e11e3aSSheldon Hearn.\" XXX Use .Dl to work around broken handling of .Ic inside .Bd and .Ed . 74849e11e3aSSheldon Hearn.\" 74949e11e3aSSheldon Hearn.Dl Ic if Ar list 75049e11e3aSSheldon Hearn.Dl Ic then Ar list 75149e11e3aSSheldon Hearn.Dl [ Ic elif Ar list 75249e11e3aSSheldon Hearn.Dl Ic then Ar list ] ... 75349e11e3aSSheldon Hearn.Dl [ Ic else Ar list ] 75449e11e3aSSheldon Hearn.Dl Ic fi 755ab72124fSSteve Price.Pp 75649e11e3aSSheldon HearnThe syntax of the 75749e11e3aSSheldon Hearn.Ic while 75849e11e3aSSheldon Hearncommand is: 75949e11e3aSSheldon Hearn.Dl Ic while Ar list 76049e11e3aSSheldon Hearn.Dl Ic do Ar list 76149e11e3aSSheldon Hearn.Dl Ic done 762ab72124fSSteve Price.Pp 763ab0a2172SSteve PriceThe two lists are executed repeatedly while the exit status of the 76449e11e3aSSheldon Hearnfirst list is zero. 76549e11e3aSSheldon HearnThe 76649e11e3aSSheldon Hearn.Ic until 76749e11e3aSSheldon Hearncommand is similar, but has the word 76849e11e3aSSheldon Hearn.Ic until 76949e11e3aSSheldon Hearnin place of 77049e11e3aSSheldon Hearn.Ic while , 77149e11e3aSSheldon Hearnwhich causes it to 7724b88c807SRodney W. Grimesrepeat until the exit status of the first list is zero. 773ab72124fSSteve Price.Pp 77449e11e3aSSheldon HearnThe syntax of the 77549e11e3aSSheldon Hearn.Ic for 77649e11e3aSSheldon Hearncommand is: 77749e11e3aSSheldon Hearn.Dl Ic for Ar variable Ic in Ar word ... 77849e11e3aSSheldon Hearn.Dl Ic do Ar list 77949e11e3aSSheldon Hearn.Dl Ic done 780ab72124fSSteve Price.Pp 7814b88c807SRodney W. GrimesThe words are expanded, and then the list is executed 78249e11e3aSSheldon Hearnrepeatedly with the variable set to each word in turn. 78349e11e3aSSheldon HearnThe 78449e11e3aSSheldon Hearn.Ic do 7856b15476eSSheldon Hearnand 78649e11e3aSSheldon Hearn.Ic done 78749e11e3aSSheldon Hearncommands may be replaced with 78849e11e3aSSheldon Hearn.Dq Li { 78949e11e3aSSheldon Hearnand 79049e11e3aSSheldon Hearn.Dq Li } . 791ab72124fSSteve Price.Pp 79249e11e3aSSheldon HearnThe syntax of the 79349e11e3aSSheldon Hearn.Ic break 79449e11e3aSSheldon Hearnand 79549e11e3aSSheldon Hearn.Ic continue 79649e11e3aSSheldon Hearncommands is: 79749e11e3aSSheldon Hearn.Dl Ic break Op Ar num 79849e11e3aSSheldon Hearn.Dl Ic continue Op Ar num 799ab72124fSSteve Price.Pp 80049e11e3aSSheldon HearnThe 80149e11e3aSSheldon Hearn.Ic break 80249e11e3aSSheldon Hearncommand terminates the 80349e11e3aSSheldon Hearn.Ar num 80449e11e3aSSheldon Hearninnermost 80549e11e3aSSheldon Hearn.Ic for 80649e11e3aSSheldon Hearnor 80749e11e3aSSheldon Hearn.Ic while 80849e11e3aSSheldon Hearnloops. 80949e11e3aSSheldon HearnThe 81049e11e3aSSheldon Hearn.Ic continue 81149e11e3aSSheldon Hearncommand continues with the next iteration of the innermost loop. 8128eed22b1SJens SchweikhardtThese are implemented as built-in commands. 813ab72124fSSteve Price.Pp 81449e11e3aSSheldon HearnThe syntax of the 81549e11e3aSSheldon Hearn.Ic case 81649e11e3aSSheldon Hearncommand is 81749e11e3aSSheldon Hearn.Dl Ic case Ar word Ic in 81849e11e3aSSheldon Hearn.Dl pattern) list ;; 81949e11e3aSSheldon Hearn.Dl ... 82049e11e3aSSheldon Hearn.Dl Ic esac 821ab72124fSSteve Price.Pp 82249e11e3aSSheldon HearnThe pattern can actually be one or more patterns 82349e11e3aSSheldon Hearn(see 82449e11e3aSSheldon Hearn.Sx Shell Patterns 82549e11e3aSSheldon Hearndescribed later), 82649e11e3aSSheldon Hearnseparated by 82767135607SMartin Cracauer.Dq Li \&| 8286b15476eSSheldon Hearncharacters. 829ab72124fSSteve Price.Ss Grouping Commands Together 8304b88c807SRodney W. GrimesCommands may be grouped by writing either 831ab72124fSSteve Price.Bd -literal -offset indent 8324b88c807SRodney W. Grimes(list) 833ab72124fSSteve Price.Ed 834ab72124fSSteve Price.Pp 8354b88c807SRodney W. Grimesor 836ab72124fSSteve Price.Bd -literal -offset indent 8374b88c807SRodney W. Grimes{ list; } 838ab72124fSSteve Price.Ed 839ab72124fSSteve Price.Pp 84049e11e3aSSheldon HearnThe first form executes the commands in a subshell. 8418eed22b1SJens SchweikhardtNote that built-in commands thus executed do not affect the current shell. 84249e11e3aSSheldon HearnThe second form does not fork another shell, 84349e11e3aSSheldon Hearnso it is slightly more efficient. 84449e11e3aSSheldon HearnGrouping commands together this way allows the user to 845ab0a2172SSteve Priceredirect their output as though they were one program: 846ab72124fSSteve Price.Bd -literal -offset indent 847ee7dc416SSteve Price{ echo -n "hello"; echo " world"; } > greeting 848ab72124fSSteve Price.Ed 849ab72124fSSteve Price.Ss Functions 8504b88c807SRodney W. GrimesThe syntax of a function definition is 851ab72124fSSteve Price.Bd -literal -offset indent 8524b88c807SRodney W. Grimesname ( ) command 853ab72124fSSteve Price.Ed 854ab72124fSSteve Price.Pp 8554b88c807SRodney W. GrimesA function definition is an executable statement; when 8564b88c807SRodney W. Grimesexecuted it installs a function named name and returns an 857eccea571SRuslan Ermilovexit status of zero. 858eccea571SRuslan ErmilovThe command is normally a list 8596b15476eSSheldon Hearnenclosed between 86049e11e3aSSheldon Hearn.Dq Li { 8616b15476eSSheldon Hearnand 86249e11e3aSSheldon Hearn.Dq Li } . 863ab72124fSSteve Price.Pp 8644b88c807SRodney W. GrimesVariables may be declared to be local to a function by 86549e11e3aSSheldon Hearnusing the 86649e11e3aSSheldon Hearn.Ic local 86749e11e3aSSheldon Hearncommand. 86849e11e3aSSheldon HearnThis should appear as the first statement of a function, 86949e11e3aSSheldon Hearnand the syntax is: 87049e11e3aSSheldon Hearn.Bd -ragged -offset indent 87149e11e3aSSheldon Hearn.Ic local 87281e9cda2SRuslan Ermilov.Op Ar variable ... 87349e11e3aSSheldon Hearn.Op Ar - 874ab72124fSSteve Price.Ed 875ab72124fSSteve Price.Pp 87649e11e3aSSheldon HearnThe 87749e11e3aSSheldon Hearn.Ic local 8788eed22b1SJens Schweikhardtcommand is implemented as a built-in command. 879ab72124fSSteve Price.Pp 8804b88c807SRodney W. GrimesWhen a variable is made local, it inherits the initial 8814b88c807SRodney W. Grimesvalue and exported and readonly flags from the variable 8824b88c807SRodney W. Grimeswith the same name in the surrounding scope, if there is 883eccea571SRuslan Ermilovone. 884eccea571SRuslan ErmilovOtherwise, the variable is initially unset. 885eccea571SRuslan ErmilovThe shell 886e918fc8fSSheldon Hearnuses dynamic scoping, so that if the variable 887e918fc8fSSheldon Hearn.Em x 888e918fc8fSSheldon Hearnis made local to function 889e918fc8fSSheldon Hearn.Em f , 890e918fc8fSSheldon Hearnwhich then calls function 891e918fc8fSSheldon Hearn.Em g , 892e918fc8fSSheldon Hearnreferences to the variable 893e918fc8fSSheldon Hearn.Em x 894e918fc8fSSheldon Hearnmade inside 895e918fc8fSSheldon Hearn.Em g 896e918fc8fSSheldon Hearnwill refer to the variable 897e918fc8fSSheldon Hearn.Em x 898e918fc8fSSheldon Hearndeclared inside 899e918fc8fSSheldon Hearn.Em f , 900e918fc8fSSheldon Hearnnot to the global variable named 901e918fc8fSSheldon Hearn.Em x . 902ab72124fSSteve Price.Pp 9036b4bbd8aSCeri DaviesThe only special parameter that can be made local is 90449e11e3aSSheldon Hearn.Dq Li - . 9056b15476eSSheldon HearnMaking 90649e11e3aSSheldon Hearn.Dq Li - 9076b15476eSSheldon Hearnlocal causes any shell options that are 9084b88c807SRodney W. Grimeschanged via the set command inside the function to be 9094b88c807SRodney W. Grimesrestored to their original values when the function 9104b88c807SRodney W. Grimesreturns. 911ab72124fSSteve Price.Pp 91249e11e3aSSheldon HearnThe syntax of the 91349e11e3aSSheldon Hearn.Ic return 91449e11e3aSSheldon Hearncommand is 91549e11e3aSSheldon Hearn.Bd -ragged -offset indent 91649e11e3aSSheldon Hearn.Ic return 91749e11e3aSSheldon Hearn.Op Ar exitstatus 918ab72124fSSteve Price.Ed 919ab72124fSSteve Price.Pp 9204ad8968aSBrian FeldmanIt terminates the current executional scope, returning from the previous 9214ad8968aSBrian Feldmannested function, sourced script, or shell instance, in that order. 92249e11e3aSSheldon HearnThe 92349e11e3aSSheldon Hearn.Ic return 9248eed22b1SJens Schweikhardtcommand is implemented as a built-in command. 925ab72124fSSteve Price.Ss Variables and Parameters 926eccea571SRuslan ErmilovThe shell maintains a set of parameters. 927eccea571SRuslan ErmilovA parameter 928eccea571SRuslan Ermilovdenoted by a name is called a variable. 929eccea571SRuslan ErmilovWhen starting up, 9304b88c807SRodney W. Grimesthe shell turns all the environment variables into shell 931eccea571SRuslan Ermilovvariables. 932eccea571SRuslan ErmilovNew variables can be set using the form 933ab72124fSSteve Price.Bd -literal -offset indent 9344b88c807SRodney W. Grimesname=value 935ab72124fSSteve Price.Ed 936ab72124fSSteve Price.Pp 9374b88c807SRodney W. GrimesVariables set by the user must have a name consisting solely 93849e11e3aSSheldon Hearnof alphabetics, numerics, and underscores. 93949e11e3aSSheldon HearnThe first letter of a variable name must not be numeric. 94049e11e3aSSheldon HearnA parameter can also be denoted by a number 9414b88c807SRodney W. Grimesor a special character as explained below. 942ab72124fSSteve Price.Ss Positional Parameters 94349e11e3aSSheldon HearnA positional parameter is a parameter denoted by a number greater than zero. 944ab72124fSSteve PriceThe shell sets these initially to the values of its command line 945eccea571SRuslan Ermilovarguments that follow the name of the shell script. 946eccea571SRuslan ErmilovThe 947c644db6aSSheldon Hearn.Ic set 9488eed22b1SJens Schweikhardtbuilt-in command can also be used to set or reset them. 949ab72124fSSteve Price.Ss Special Parameters 95043d6677bSAlfred PerlsteinA special parameter is a parameter denoted by a special one-character 95143d6677bSAlfred Perlsteinname. 95243d6677bSAlfred PerlsteinThe special parameters recognized by the 95343d6677bSAlfred Perlstein.Nm 95443d6677bSAlfred Perlsteinshell of 95543d6677bSAlfred Perlstein.Fx 95643d6677bSAlfred Perlsteinare shown in the following list, exactly as they would appear in input 95743d6677bSAlfred Perlsteintyped by the user or in the source of a shell script. 958ab72124fSSteve Price.Bl -hang 95943d6677bSAlfred Perlstein.It Li $* 960eccea571SRuslan ErmilovExpands to the positional parameters, starting from one. 961eccea571SRuslan ErmilovWhen 9624b88c807SRodney W. Grimesthe expansion occurs within a double-quoted string 9634b88c807SRodney W. Grimesit expands to a single field with the value of each parameter 96449e11e3aSSheldon Hearnseparated by the first character of the 96549e11e3aSSheldon Hearn.Ev IFS 96649e11e3aSSheldon Hearnvariable, 96749e11e3aSSheldon Hearnor by a 96849e11e3aSSheldon Hearn.Aq space 96949e11e3aSSheldon Hearnif 97049e11e3aSSheldon Hearn.Ev IFS 97149e11e3aSSheldon Hearnis unset. 97243d6677bSAlfred Perlstein.It Li $@ 973eccea571SRuslan ErmilovExpands to the positional parameters, starting from one. 974eccea571SRuslan ErmilovWhen 9754b88c807SRodney W. Grimesthe expansion occurs within double-quotes, each positional 9764b88c807SRodney W. Grimesparameter expands as a separate argument. 9774b88c807SRodney W. GrimesIf there are no positional parameters, the 978e918fc8fSSheldon Hearnexpansion of 979e918fc8fSSheldon Hearn.Li @ 980e918fc8fSSheldon Hearngenerates zero arguments, even when 981e918fc8fSSheldon Hearn.Li @ 982eccea571SRuslan Ermilovis double-quoted. 983eccea571SRuslan ErmilovWhat this basically means, for example, is 9846b15476eSSheldon Hearnif $1 is 9856b15476eSSheldon Hearn.Dq abc 9866b15476eSSheldon Hearnand $2 is 9876b15476eSSheldon Hearn.Dq def ghi , 9886b15476eSSheldon Hearnthen 989e918fc8fSSheldon Hearn.Qq Li $@ 9906b15476eSSheldon Hearnexpands to 9914b88c807SRodney W. Grimesthe two arguments: 992ab72124fSSteve Price.Bd -literal -offset indent 9934b88c807SRodney W. Grimes"abc" "def ghi" 994ab72124fSSteve Price.Ed 99543d6677bSAlfred Perlstein.It Li $# 9964b88c807SRodney W. GrimesExpands to the number of positional parameters. 99743d6677bSAlfred Perlstein.It Li $\&? 9984b88c807SRodney W. GrimesExpands to the exit status of the most recent pipeline. 99943d6677bSAlfred Perlstein.It Li $- 1000ab72124fSSteve Price(hyphen) Expands to the current option flags (the single-letter 10014b88c807SRodney W. Grimesoption names concatenated into a string) as specified on 10028eed22b1SJens Schweikhardtinvocation, by the set built-in command, or implicitly 10034b88c807SRodney W. Grimesby the shell. 100443d6677bSAlfred Perlstein.It Li $$ 1005eccea571SRuslan ErmilovExpands to the process ID of the invoked shell. 1006eccea571SRuslan ErmilovA subshell 10074b88c807SRodney W. Grimesretains the same value of $ as its parent. 100843d6677bSAlfred Perlstein.It Li $\&! 10094b88c807SRodney W. GrimesExpands to the process ID of the most recent background 1010eccea571SRuslan Ermilovcommand executed from the current shell. 1011eccea571SRuslan ErmilovFor a 10124b88c807SRodney W. Grimespipeline, the process ID is that of the last command in the 10134b88c807SRodney W. Grimespipeline. 101443d6677bSAlfred Perlstein.It Li $0 1015ab72124fSSteve Price(zero) Expands to the name of the shell or shell script. 1016ab72124fSSteve Price.El 1017ab72124fSSteve Price.Ss Word Expansions 10184b88c807SRodney W. GrimesThis clause describes the various expansions that are 1019eccea571SRuslan Ermilovperformed on words. 1020eccea571SRuslan ErmilovNot all expansions are performed on 10214b88c807SRodney W. Grimesevery word, as explained later. 1022ab72124fSSteve Price.Pp 10234b88c807SRodney W. GrimesTilde expansions, parameter expansions, command substitutions, 10244b88c807SRodney W. Grimesarithmetic expansions, and quote removals that occur within 1025eccea571SRuslan Ermilova single word expand to a single field. 1026eccea571SRuslan ErmilovIt is only field 10274b88c807SRodney W. Grimessplitting or pathname expansion that can create multiple 1028e6d3cf26SSheldon Hearnfields from a single word. 1029e6d3cf26SSheldon HearnThe single exception to this rule is 1030e918fc8fSSheldon Hearnthe expansion of the special parameter 1031e918fc8fSSheldon Hearn.Li @ 1032e918fc8fSSheldon Hearnwithin double-quotes, 1033e6d3cf26SSheldon Hearnas was described above. 1034ab72124fSSteve Price.Pp 10354b88c807SRodney W. GrimesThe order of word expansion is: 1036ab72124fSSteve Price.Bl -enum 1037ab72124fSSteve Price.It 1038ab72124fSSteve PriceTilde Expansion, Parameter Expansion, Command Substitution, 10394b88c807SRodney W. GrimesArithmetic Expansion (these all occur at the same time). 1040ab72124fSSteve Price.It 104149e11e3aSSheldon HearnField Splitting is performed on fields generated by step (1) 104249e11e3aSSheldon Hearnunless the 104349e11e3aSSheldon Hearn.Ev IFS 104449e11e3aSSheldon Hearnvariable is null. 1045ab72124fSSteve Price.It 104649e11e3aSSheldon HearnPathname Expansion (unless the 104749e11e3aSSheldon Hearn.Fl f 104849e11e3aSSheldon Hearnoption is in effect). 1049ab72124fSSteve Price.It 1050ab72124fSSteve PriceQuote Removal. 1051ab72124fSSteve Price.El 1052ab72124fSSteve Price.Pp 105349e11e3aSSheldon HearnThe 105449e11e3aSSheldon Hearn.Dq Li $ 105549e11e3aSSheldon Hearncharacter is used to introduce parameter expansion, command 10564b88c807SRodney W. Grimessubstitution, or arithmetic evaluation. 1057ab72124fSSteve Price.Ss Tilde Expansion (substituting a user's home directory) 105849e11e3aSSheldon HearnA word beginning with an unquoted tilde character 1059a762afe5SGiorgos Keramidas.Pq Ql ~ 106049e11e3aSSheldon Hearnis 106149e11e3aSSheldon Hearnsubjected to tilde expansion. 106249e11e3aSSheldon HearnAll the characters up to a slash 1063a762afe5SGiorgos Keramidas.Pq Ql / 106449e11e3aSSheldon Hearnor the end of the word are treated as a username 1065eccea571SRuslan Ermilovand are replaced with the user's home directory. 1066eccea571SRuslan ErmilovIf the 10674b88c807SRodney W. Grimesusername is missing (as in ~/foobar), the tilde is replaced 10684b88c807SRodney W. Grimeswith the value of the HOME variable (the current user's 10694b88c807SRodney W. Grimeshome directory). 1070ab72124fSSteve Price.Ss Parameter Expansion 10714b88c807SRodney W. GrimesThe format for parameter expansion is as follows: 1072ab72124fSSteve Price.Bd -literal -offset indent 10734b88c807SRodney W. Grimes${expression} 1074ab72124fSSteve Price.Ed 1075ab72124fSSteve Price.Pp 107649e11e3aSSheldon Hearnwhere expression consists of all characters until the matching 107749e11e3aSSheldon Hearn.Dq Li } . 107849e11e3aSSheldon HearnAny 107949e11e3aSSheldon Hearn.Dq Li } 10804b88c807SRodney W. Grimesescaped by a backslash or within a quoted string, and characters in 10814b88c807SRodney W. Grimesembedded arithmetic expansions, command substitutions, and variable 108249e11e3aSSheldon Hearnexpansions, are not examined in determining the matching 108349e11e3aSSheldon Hearn.Dq Li } . 1084ab72124fSSteve Price.Pp 10854b88c807SRodney W. GrimesThe simplest form for parameter expansion is: 1086ab72124fSSteve Price.Bd -literal -offset indent 10874b88c807SRodney W. Grimes${parameter} 1088ab72124fSSteve Price.Ed 1089ab72124fSSteve Price.Pp 10904b88c807SRodney W. GrimesThe value, if any, of parameter is substituted. 1091ab72124fSSteve Price.Pp 10924b88c807SRodney W. GrimesThe parameter name or symbol can be enclosed in braces, which are 10934b88c807SRodney W. Grimesoptional except for positional parameters with more than one digit or 10944b88c807SRodney W. Grimeswhen parameter is followed by a character that could be interpreted as 10954b88c807SRodney W. Grimespart of the name. 1096ab72124fSSteve PriceIf a parameter expansion occurs inside double-quotes: 1097ab72124fSSteve Price.Bl -enum 1098ab72124fSSteve Price.It 1099ab72124fSSteve PricePathname expansion is not performed on the results of the 11004b88c807SRodney W. Grimesexpansion. 1101ab72124fSSteve Price.It 1102ab72124fSSteve PriceField splitting is not performed on the results of the 1103e918fc8fSSheldon Hearnexpansion, with the exception of the special parameter 1104e918fc8fSSheldon Hearn.Li @ . 1105ab72124fSSteve Price.El 1106ab72124fSSteve Price.Pp 11074b88c807SRodney W. GrimesIn addition, a parameter expansion can be modified by using one of the 11084b88c807SRodney W. Grimesfollowing formats. 110981e9cda2SRuslan Ermilov.Bl -tag -width indent 1110ab72124fSSteve Price.It Li ${parameter:-word} 1111eccea571SRuslan ErmilovUse Default Values. 1112eccea571SRuslan ErmilovIf parameter is unset or 11134b88c807SRodney W. Grimesnull, the expansion of word is 11144b88c807SRodney W. Grimessubstituted; otherwise, the value of 11154b88c807SRodney W. Grimesparameter is substituted. 1116ab72124fSSteve Price.It Li ${parameter:=word} 1117eccea571SRuslan ErmilovAssign Default Values. 1118eccea571SRuslan ErmilovIf parameter is unset 11194b88c807SRodney W. Grimesor null, the expansion of word is 1120eccea571SRuslan Ermilovassigned to parameter. 1121eccea571SRuslan ErmilovIn all cases, the 11224b88c807SRodney W. Grimesfinal value of parameter is 1123eccea571SRuslan Ermilovsubstituted. 1124eccea571SRuslan ErmilovOnly variables, not positional 11254b88c807SRodney W. Grimesparameters or special parameters, can be 11264b88c807SRodney W. Grimesassigned in this way. 1127ab72124fSSteve Price.It Li ${parameter:?[word]} 1128eccea571SRuslan ErmilovIndicate Error if Null or Unset. 1129eccea571SRuslan ErmilovIf 11304b88c807SRodney W. Grimesparameter is unset or null, the expansion of 11314b88c807SRodney W. Grimesword (or a message indicating it is unset if 11324b88c807SRodney W. Grimesword is omitted) is written to standard 11334b88c807SRodney W. Grimeserror and the shell exits with a nonzero 1134e6d3cf26SSheldon Hearnexit status. 1135e6d3cf26SSheldon HearnOtherwise, the value of 1136eccea571SRuslan Ermilovparameter is substituted. 1137eccea571SRuslan ErmilovAn 11384b88c807SRodney W. Grimesinteractive shell need not exit. 1139ab72124fSSteve Price.It Li ${parameter:+word} 1140eccea571SRuslan ErmilovUse Alternate Value. 1141eccea571SRuslan ErmilovIf parameter is unset 11424b88c807SRodney W. Grimesor null, null is substituted; 11434b88c807SRodney W. Grimesotherwise, the expansion of word is 11444b88c807SRodney W. Grimessubstituted. 11451413f7deSTony Finch.El 1146ab72124fSSteve Price.Pp 11474b88c807SRodney W. GrimesIn the parameter expansions shown previously, use of the colon in the 11484b88c807SRodney W. Grimesformat results in a test for a parameter that is unset or null; omission 11494b88c807SRodney W. Grimesof the colon results in a test for a parameter that is only unset. 11501413f7deSTony Finch.Bl -tag -width indent 1151ab72124fSSteve Price.It Li ${#parameter} 1152eccea571SRuslan ErmilovString Length. 1153eccea571SRuslan ErmilovThe length in characters of 11544b88c807SRodney W. Grimesthe value of parameter. 115571337c33SSheldon Hearn.El 1156ab72124fSSteve Price.Pp 11574b88c807SRodney W. GrimesThe following four varieties of parameter expansion provide for substring 115849e11e3aSSheldon Hearnprocessing. 115949e11e3aSSheldon HearnIn each case, pattern matching notation 116049e11e3aSSheldon Hearn(see 116149e11e3aSSheldon Hearn.Sx Shell Patterns ) , 116249e11e3aSSheldon Hearnrather than regular expression notation, 116349e11e3aSSheldon Hearnis used to evaluate the patterns. 1164e918fc8fSSheldon HearnIf parameter is one of the special parameters 1165e918fc8fSSheldon Hearn.Li * 116649e11e3aSSheldon Hearnor 1167e918fc8fSSheldon Hearn.Li @ , 116849e11e3aSSheldon Hearnthe result of the expansion is unspecified. 11694b88c807SRodney W. GrimesEnclosing the full parameter expansion string in double-quotes does not 11704b88c807SRodney W. Grimescause the following four varieties of pattern characters to be quoted, 11714b88c807SRodney W. Grimeswhereas quoting characters within the braces has this effect. 117281e9cda2SRuslan Ermilov.Bl -tag -width indent 1173ab72124fSSteve Price.It Li ${parameter%word} 1174eccea571SRuslan ErmilovRemove Smallest Suffix Pattern. 1175eccea571SRuslan ErmilovThe word 1176eccea571SRuslan Ermilovis expanded to produce a pattern. 1177eccea571SRuslan ErmilovThe 11784b88c807SRodney W. Grimesparameter expansion then results in 11794b88c807SRodney W. Grimesparameter, with the smallest portion of the 11804b88c807SRodney W. Grimessuffix matched by the pattern deleted. 1181ab72124fSSteve Price.It Li ${parameter%%word} 1182eccea571SRuslan ErmilovRemove Largest Suffix Pattern. 1183eccea571SRuslan ErmilovThe word 1184eccea571SRuslan Ermilovis expanded to produce a pattern. 1185eccea571SRuslan ErmilovThe 11864b88c807SRodney W. Grimesparameter expansion then results in 11874b88c807SRodney W. Grimesparameter, with the largest portion of the 11884b88c807SRodney W. Grimessuffix matched by the pattern deleted. 1189ab72124fSSteve Price.It Li ${parameter#word} 1190eccea571SRuslan ErmilovRemove Smallest Prefix Pattern. 1191eccea571SRuslan ErmilovThe word 1192eccea571SRuslan Ermilovis expanded to produce a pattern. 1193eccea571SRuslan ErmilovThe 11944b88c807SRodney W. Grimesparameter expansion then results in 11954b88c807SRodney W. Grimesparameter, with the smallest portion of the 11964b88c807SRodney W. Grimesprefix matched by the pattern deleted. 1197ab72124fSSteve Price.It Li ${parameter##word} 1198eccea571SRuslan ErmilovRemove Largest Prefix Pattern. 1199eccea571SRuslan ErmilovThe word 1200eccea571SRuslan Ermilovis expanded to produce a pattern. 1201eccea571SRuslan ErmilovThe 12024b88c807SRodney W. Grimesparameter expansion then results in 12034b88c807SRodney W. Grimesparameter, with the largest portion of the 12044b88c807SRodney W. Grimesprefix matched by the pattern deleted. 1205ab72124fSSteve Price.El 1206ab72124fSSteve Price.Ss Command Substitution 12074b88c807SRodney W. GrimesCommand substitution allows the output of a command to be substituted in 1208eccea571SRuslan Ermilovplace of the command name itself. 1209eccea571SRuslan ErmilovCommand substitution occurs when 12104b88c807SRodney W. Grimesthe command is enclosed as follows: 1211ab72124fSSteve Price.Bd -literal -offset indent 12124b88c807SRodney W. Grimes$(command) 1213ab72124fSSteve Price.Ed 1214ab72124fSSteve Price.Pp 121549e11e3aSSheldon Hearnor the backquoted version: 1216ab72124fSSteve Price.Bd -literal -offset indent 12174b88c807SRodney W. Grimes`command` 1218ab72124fSSteve Price.Ed 1219ab72124fSSteve Price.Pp 12204b88c807SRodney W. GrimesThe shell expands the command substitution by executing command in a 12214b88c807SRodney W. Grimessubshell environment and replacing the command substitution 122249e11e3aSSheldon Hearnwith the standard output of the command, 122349e11e3aSSheldon Hearnremoving sequences of one or more newlines at the end of the substitution. 122449e11e3aSSheldon HearnEmbedded newlines before the end of the output are not removed; 122549e11e3aSSheldon Hearnhowever, during field splitting, they may be translated into spaces 122649e11e3aSSheldon Hearndepending on the value of 122749e11e3aSSheldon Hearn.Ev IFS 122849e11e3aSSheldon Hearnand the quoting that is in effect. 1229ab72124fSSteve Price.Ss Arithmetic Expansion 12304b88c807SRodney W. GrimesArithmetic expansion provides a mechanism for evaluating an arithmetic 1231e6d3cf26SSheldon Hearnexpression and substituting its value. 1232e6d3cf26SSheldon HearnThe format for arithmetic expansion is as follows: 1233ab72124fSSteve Price.Bd -literal -offset indent 12344b88c807SRodney W. Grimes$((expression)) 1235ab72124fSSteve Price.Ed 1236ab72124fSSteve Price.Pp 12374b88c807SRodney W. GrimesThe expression is treated as if it were in double-quotes, except 1238eccea571SRuslan Ermilovthat a double-quote inside the expression is not treated specially. 1239eccea571SRuslan ErmilovThe 12404b88c807SRodney W. Grimesshell expands all tokens in the expression for parameter expansion, 12414b88c807SRodney W. Grimescommand substitution, and quote removal. 1242ab72124fSSteve Price.Pp 12434b88c807SRodney W. GrimesNext, the shell treats this as an arithmetic expression and 12444b88c807SRodney W. Grimessubstitutes the value of the expression. 1245ab72124fSSteve Price.Ss White Space Splitting (Field Splitting) 12464b88c807SRodney W. GrimesAfter parameter expansion, command substitution, and 12474b88c807SRodney W. Grimesarithmetic expansion the shell scans the results of 12484b88c807SRodney W. Grimesexpansions and substitutions that did not occur in double-quotes for 12494b88c807SRodney W. Grimesfield splitting and multiple fields can result. 1250ab72124fSSteve Price.Pp 125149e11e3aSSheldon HearnThe shell treats each character of the 125249e11e3aSSheldon Hearn.Ev IFS 125349e11e3aSSheldon Hearnas a delimiter and uses 12544b88c807SRodney W. Grimesthe delimiters to split the results of parameter expansion and command 12554b88c807SRodney W. Grimessubstitution into fields. 1256ab72124fSSteve Price.Ss Pathname Expansion (File Name Generation) 125749e11e3aSSheldon HearnUnless the 125849e11e3aSSheldon Hearn.Fl f 125949e11e3aSSheldon Hearnoption is set, 126049e11e3aSSheldon Hearnfile name generation is performed 1261eccea571SRuslan Ermilovafter word splitting is complete. 1262eccea571SRuslan ErmilovEach word is 1263eccea571SRuslan Ermilovviewed as a series of patterns, separated by slashes. 1264eccea571SRuslan ErmilovThe 12654b88c807SRodney W. Grimesprocess of expansion replaces the word with the names of 12664b88c807SRodney W. Grimesall existing files whose names can be formed by replacing 12674b88c807SRodney W. Grimeseach pattern with a string that matches the specified pattern. 1268ab0a2172SSteve PriceThere are two restrictions on this: first, a pattern cannot match 1269ab0a2172SSteve Pricea string containing a slash, and second, 12704b88c807SRodney W. Grimesa pattern cannot match a string starting with a period 12714b88c807SRodney W. Grimesunless the first character of the pattern is a period. 12724b88c807SRodney W. GrimesThe next section describes the patterns used for both 1273ab72124fSSteve PricePathname Expansion and the 1274c644db6aSSheldon Hearn.Ic case 1275ab72124fSSteve Pricecommand. 1276ab72124fSSteve Price.Ss Shell Patterns 1277f434d1dfSAdam DavidA pattern consists of normal characters, which match themselves, 127849e11e3aSSheldon Hearnand meta-characters. 127949e11e3aSSheldon HearnThe meta-characters are 12801586940eSRuslan Ermilov.Dq Li \&! , 128149e11e3aSSheldon Hearn.Dq Li * , 12821586940eSRuslan Ermilov.Dq Li \&? , 12836b15476eSSheldon Hearnand 128449e11e3aSSheldon Hearn.Dq Li [ . 12856b15476eSSheldon HearnThese characters lose their special meanings if they are quoted. 12866b15476eSSheldon HearnWhen command or variable substitution is performed and the dollar sign 12876b15476eSSheldon Hearnor back quotes are not double-quoted, the value of the 12884b88c807SRodney W. Grimesvariable or the output of the command is scanned for these 12894b88c807SRodney W. Grimescharacters and they are turned into meta-characters. 1290ab72124fSSteve Price.Pp 12916b15476eSSheldon HearnAn asterisk 1292a762afe5SGiorgos Keramidas.Pq Ql * 1293e918fc8fSSheldon Hearnmatches any string of characters. 1294e918fc8fSSheldon HearnA question mark 1295a762afe5SGiorgos Keramidas.Pq Ql \&? 1296e918fc8fSSheldon Hearnmatches any single character. 1297e6d3cf26SSheldon HearnA left bracket 1298a762afe5SGiorgos Keramidas.Pq Ql [ 1299e6d3cf26SSheldon Hearnintroduces a character class. 1300e6d3cf26SSheldon HearnThe end of the character class is indicated by a 130149e11e3aSSheldon Hearn.Dq Li \&] ; 13026b15476eSSheldon Hearnif the 130349e11e3aSSheldon Hearn.Dq Li \&] 13046b15476eSSheldon Hearnis missing then the 130549e11e3aSSheldon Hearn.Dq Li [ 13066b15476eSSheldon Hearnmatches a 130749e11e3aSSheldon Hearn.Dq Li [ 1308e6d3cf26SSheldon Hearnrather than introducing a character class. 1309e6d3cf26SSheldon HearnA character class matches any of the characters between the square brackets. 1310e6d3cf26SSheldon HearnA range of characters may be specified using a minus sign. 1311e918fc8fSSheldon HearnThe character class may be complemented by making an exclamation point 1312a762afe5SGiorgos Keramidas.Pq Ql !\& 1313e918fc8fSSheldon Hearnthe first character of the character class. 1314ab72124fSSteve Price.Pp 13156b15476eSSheldon HearnTo include a 131612e720d7SRuslan Ermilov.Dq Li \&] 1317e6d3cf26SSheldon Hearnin a character class, make it the first character listed 1318e6d3cf26SSheldon Hearn(after the 13191586940eSRuslan Ermilov.Dq Li \&! , 1320e6d3cf26SSheldon Hearnif any). 1321e918fc8fSSheldon HearnTo include a 1322e918fc8fSSheldon Hearn.Dq Li - , 1323e918fc8fSSheldon Hearnmake it the first or last character listed. 13248eed22b1SJens Schweikhardt.Ss Built-in Commands 1325c644db6aSSheldon HearnThis section lists the commands which 13268eed22b1SJens Schweikhardtare built-in because they need to perform some operation 1327eccea571SRuslan Ermilovthat cannot be performed by a separate process. 1328eccea571SRuslan ErmilovIn addition to 13298eed22b1SJens Schweikhardtthese, a built-in version of the 1330d90c5c4aSAkinori MUSHA.Xr test 1 1331018d9f62SAkinori MUSHAcommand is provided for efficiency. 133281e9cda2SRuslan Ermilov.Bl -tag -width indent 1333d0353b83SRuslan Ermilov.It Ic \&: 1334aa9caaf6SPeter WemmA null command that returns a 0 (true) exit value. 1335d0353b83SRuslan Ermilov.It Ic \&. Ar file 1336aa9caaf6SPeter WemmThe commands in the specified file are read and executed by the shell. 13374ad8968aSBrian FeldmanThe 13384ad8968aSBrian Feldman.Ic return 13394ad8968aSBrian Feldmancommand may be used to return to the 13404ad8968aSBrian Feldman.Ic \&. 13414ad8968aSBrian Feldmancommand's caller. 13426466945aSJohn PolstraIf 13436466945aSJohn Polstra.Ar file 13446466945aSJohn Polstracontains any 134549e11e3aSSheldon Hearn.Dq / 1346eccea571SRuslan Ermilovcharacters, it is used as is. 1347eccea571SRuslan ErmilovOtherwise, the shell searches the 13486466945aSJohn Polstra.Ev PATH 1349eccea571SRuslan Ermilovfor the file. 1350eccea571SRuslan ErmilovIf it is not found in the 13516466945aSJohn Polstra.Ev PATH , 13526466945aSJohn Polstrait is sought in the current working directory. 135349e11e3aSSheldon Hearn.It Ic alias Op Ar name ... 135481e9cda2SRuslan Ermilov.It Ic alias Op Ar name Ns = Ns Ar string ... 135549e11e3aSSheldon HearnIf 1356d0353b83SRuslan Ermilov.Ar name Ns = Ns Ar string 135749e11e3aSSheldon Hearnis specified, the shell defines the alias 135849e11e3aSSheldon Hearn.Ar name 13596b15476eSSheldon Hearnwith value 136049e11e3aSSheldon Hearn.Ar string . 13616b15476eSSheldon HearnIf just 136249e11e3aSSheldon Hearn.Ar name 13636b15476eSSheldon Hearnis specified, the value of the alias 136449e11e3aSSheldon Hearn.Ar name 13656b15476eSSheldon Hearnis printed. 136649e11e3aSSheldon HearnWith no arguments, the 136749e11e3aSSheldon Hearn.Ic alias 13688eed22b1SJens Schweikhardtbuilt-in command prints the names and values of all defined aliases 136949e11e3aSSheldon Hearn(see 137049e11e3aSSheldon Hearn.Ic unalias ) . 1371e5341cbbSTim J. RobbinsAlias values are written with appropriate quoting so that they are 13729ba31ca0SRuslan Ermilovsuitable for re-input to the shell. 137349e11e3aSSheldon Hearn.It Ic bg Op Ar job ... 137449e11e3aSSheldon HearnContinue the specified jobs 137549e11e3aSSheldon Hearn(or the current job if no jobs are given) 137649e11e3aSSheldon Hearnin the background. 1377df9e587bSTim J. Robbins.It Ic builtin Ar cmd Op Ar arg ... 13788eed22b1SJens SchweikhardtExecute the specified built-in command, 137949e11e3aSSheldon Hearn.Ar cmd . 138049e11e3aSSheldon HearnThis is useful when the user wishes to override a shell function 13818eed22b1SJens Schweikhardtwith the same name as a built-in command. 1382088acf90STim J. Robbins.It Ic bind Oo Fl aeklrsv Oc Oo Ar key Oo Ar command Oc Oc 1383088acf90STim J. RobbinsList or alter key bindings for the line editor. 1384088acf90STim J. RobbinsThis command is documented in 1385088acf90STim J. Robbins.Xr editrc 5 . 1386d74e011fSRuslan Ermilov.It Ic cd Oo Fl L | P Oc Op Ar directory 138749e11e3aSSheldon HearnSwitch to the specified 138849e11e3aSSheldon Hearn.Ar directory , 138949e11e3aSSheldon Hearnor to the directory specified in the 139049e11e3aSSheldon Hearn.Ev HOME 139149e11e3aSSheldon Hearnenvironment variable if no 139249e11e3aSSheldon Hearn.Ar directory 139349e11e3aSSheldon Hearnis specified. 139449e11e3aSSheldon HearnIf 139549e11e3aSSheldon Hearn.Ar directory 1396029c8ee4STim J. Robbinsdoes not begin with 13979ba31ca0SRuslan Ermilov.Pa / , \&. , 139849e11e3aSSheldon Hearnor 1399029c8ee4STim J. Robbins.Pa .. , 140049e11e3aSSheldon Hearnthen the directories listed in the 140149e11e3aSSheldon Hearn.Ev CDPATH 140249e11e3aSSheldon Hearnvariable will be 140349e11e3aSSheldon Hearnsearched for the specified 140449e11e3aSSheldon Hearn.Ar directory . 1405029c8ee4STim J. RobbinsIf 1406029c8ee4STim J. Robbins.Ev CDPATH 1407029c8ee4STim J. Robbinsis unset, the current directory is searched. 140849e11e3aSSheldon HearnThe format of 140949e11e3aSSheldon Hearn.Ar CDPATH 141049e11e3aSSheldon Hearnis the same as that of 141149e11e3aSSheldon Hearn.Ev PATH . 1412e6d3cf26SSheldon HearnIn an interactive shell, 141349e11e3aSSheldon Hearnthe 141449e11e3aSSheldon Hearn.Ic cd 141549e11e3aSSheldon Hearncommand will print out the name of the directory 1416e6d3cf26SSheldon Hearnthat it actually switched to 1417e6d3cf26SSheldon Hearnif this is different from the name that the user gave. 141849e11e3aSSheldon HearnThese may be different either because the 141949e11e3aSSheldon Hearn.Ev CDPATH 142049e11e3aSSheldon Hearnmechanism was used or because a symbolic link was crossed. 1421178897f1STim J. Robbins.Pp 1422178897f1STim J. RobbinsIf the 1423178897f1STim J. Robbins.Fl P 1424178897f1STim J. Robbinsoption is specified, 142581e9cda2SRuslan Ermilov.Pa .. 1426178897f1STim J. Robbinsis handled physically and symbolic links are resolved before 142781e9cda2SRuslan Ermilov.Pa .. 1428178897f1STim J. Robbinscomponents are processed. 1429178897f1STim J. RobbinsIf the 1430178897f1STim J. Robbins.Fl L 1431178897f1STim J. Robbinsoption is specified, 143281e9cda2SRuslan Ermilov.Pa .. 1433178897f1STim J. Robbinsis handled logically. 1434178897f1STim J. RobbinsThis is the default. 14359434a1c7SDima Dorfman.It Ic chdir 14369434a1c7SDima DorfmanA synonym for the 14379434a1c7SDima Dorfman.Ic cd 14388eed22b1SJens Schweikhardtbuilt-in command. 14399ba31ca0SRuslan Ermilov.It Ic command Oo Fl p Oc Op Ar utility Op Ar argument ... 14402babaf74STim J. RobbinsExecute the specified 14412babaf74STim J. Robbins.Ar utility 14422babaf74STim J. Robbinsas a simple command (see the 14432babaf74STim J. Robbins.Sx Simple Commands 14442babaf74STim J. Robbinssection). 14452babaf74STim J. Robbins.Pp 14462babaf74STim J. RobbinsIf the 14472babaf74STim J. Robbins.Fl p 14482babaf74STim J. Robbinsoption is specified, the command search is performed using a 14492babaf74STim J. Robbinsdefault value of 14502babaf74STim J. Robbins.Ev PATH 14512babaf74STim J. Robbinsthat is guaranteed to find all of the standard utilities. 14529ba31ca0SRuslan Ermilov.It Ic echo Oo Fl e | n Oc Op Ar string 1453501e74b7SMark OvensPrint 1454501e74b7SMark Ovens.Ar string 1455501e74b7SMark Ovensto the standard output with a newline appended. 145681e9cda2SRuslan Ermilov.Bl -tag -width indent 1457501e74b7SMark Ovens.It Fl n 1458501e74b7SMark OvensSuppress the output of the trailing newline. 1459501e74b7SMark Ovens.It Fl e 1460501e74b7SMark OvensProcess C-style backslash escape sequences. 1461501e74b7SMark Ovens.Ic echo 1462501e74b7SMark Ovensunderstands the following character escapes: 146381e9cda2SRuslan Ermilov.Bl -tag -width indent 1464501e74b7SMark Ovens.It \ea 1465501e74b7SMark OvensAlert (ring the terminal bell) 1466501e74b7SMark Ovens.It \eb 1467501e74b7SMark OvensBackspace 1468501e74b7SMark Ovens.It \ec 1469501e74b7SMark OvensSuppress the trailing newline (this has the side-effect of truncating the 1470501e74b7SMark Ovensline if it is not the last character) 1471501e74b7SMark Ovens.It \ee 1472501e74b7SMark OvensThe ESC character (ASCII 0x1b) 1473501e74b7SMark Ovens.It \ef 1474501e74b7SMark OvensFormfeed 1475501e74b7SMark Ovens.It \en 1476501e74b7SMark OvensNewline 1477501e74b7SMark Ovens.It \er 1478501e74b7SMark OvensCarriage return 1479501e74b7SMark Ovens.It \et 1480501e74b7SMark OvensHorizontal tab 1481501e74b7SMark Ovens.It \ev 1482501e74b7SMark OvensVertical tab 1483501e74b7SMark Ovens.It \e\e 1484501e74b7SMark OvensLiteral backslash 1485501e74b7SMark Ovens.It \e0nnn 1486501e74b7SMark Ovens(Zero) The character whose octal value is nnn 1487501e74b7SMark Ovens.El 1488501e74b7SMark Ovens.Pp 1489501e74b7SMark OvensIf 1490501e74b7SMark Ovens.Ar string 1491501e74b7SMark Ovensis not enclosed in quotes then the backslash itself must be escaped 1492eccea571SRuslan Ermilovwith a backslash to protect it from the shell. 1493eccea571SRuslan ErmilovFor example 1494501e74b7SMark Ovens.Bd -literal -offset indent 1495501e74b7SMark Ovens$ echo -e "a\evb" 1496501e74b7SMark Ovensa 1497501e74b7SMark Ovens b 1498501e74b7SMark Ovens$ echo -e a\e\evb 1499501e74b7SMark Ovensa 1500501e74b7SMark Ovens b 1501501e74b7SMark Ovens$ echo -e "a\e\eb" 1502501e74b7SMark Ovensa\eb 1503501e74b7SMark Ovens$ echo -e a\e\e\e\eb 1504501e74b7SMark Ovensa\eb 1505501e74b7SMark Ovens.Ed 1506501e74b7SMark Ovens.El 1507558175caSTim J. Robbins.Pp 1508558175caSTim J. RobbinsOnly one of the 1509558175caSTim J. Robbins.Fl e 1510558175caSTim J. Robbinsand 1511558175caSTim J. Robbins.Fl n 1512558175caSTim J. Robbinsoptions may be specified. 151349e11e3aSSheldon Hearn.It Ic eval Ar string ... 1514e6d3cf26SSheldon HearnConcatenate all the arguments with spaces. 1515e6d3cf26SSheldon HearnThen re-parse and execute the command. 151649e11e3aSSheldon Hearn.It Ic exec Op Ar command Op arg ... 151749e11e3aSSheldon HearnUnless 151849e11e3aSSheldon Hearn.Ar command 151949e11e3aSSheldon Hearnis omitted, 152049e11e3aSSheldon Hearnthe shell process is replaced with the specified program 15218eed22b1SJens Schweikhardt(which must be a real program, not a shell built-in command or function). 152249e11e3aSSheldon HearnAny redirections on the 152349e11e3aSSheldon Hearn.Ic exec 152449e11e3aSSheldon Hearncommand are marked as permanent, 152549e11e3aSSheldon Hearnso that they are not undone when the 152649e11e3aSSheldon Hearn.Ic exec 152749e11e3aSSheldon Hearncommand finishes. 152849e11e3aSSheldon Hearn.It Ic exit Op Ar exitstatus 152949e11e3aSSheldon HearnTerminate the shell process. 153049e11e3aSSheldon HearnIf 153149e11e3aSSheldon Hearn.Ar exitstatus 153249e11e3aSSheldon Hearnis given 153349e11e3aSSheldon Hearnit is used as the exit status of the shell; 153449e11e3aSSheldon Hearnotherwise the exit status of the preceding command is used. 15359ba31ca0SRuslan Ermilov.It Ic export Oo Fl p Oc Op Ar name ... 15364b88c807SRodney W. GrimesThe specified names are exported so that they will 15374b88c807SRodney W. Grimesappear in the environment of subsequent commands. 153849e11e3aSSheldon HearnThe only way to un-export a variable is to 153949e11e3aSSheldon Hearn.Ic unset 154049e11e3aSSheldon Hearnit. 154149e11e3aSSheldon HearnThe shell allows the value of a variable to be set 154249e11e3aSSheldon Hearnat the same time as it is exported by writing 1543ab72124fSSteve Price.Bd -literal -offset indent 15444b88c807SRodney W. Grimesexport name=value 1545ab72124fSSteve Price.Ed 1546ab72124fSSteve Price.Pp 15474b88c807SRodney W. GrimesWith no arguments the export command lists the names 15484b88c807SRodney W. Grimesof all exported variables. 154945086f8cSTim J. RobbinsIf the 155045086f8cSTim J. Robbins.Fl p 155145086f8cSTim J. Robbinsoption is specified, the exported variables are printed as 155245086f8cSTim J. Robbins.Dq Ic export Ar name Ns = Ns Ar value 155345086f8cSTim J. Robbinslines, suitable for re-input to the shell. 155481e9cda2SRuslan Ermilov.It Ic fc Oo Fl e Ar editor Oc Op Ar first Op Ar last 155581e9cda2SRuslan Ermilov.It Ic fc Fl l Oo Fl nr Oc Op Ar first Op Ar last 155681e9cda2SRuslan Ermilov.It Ic fc Fl s Oo Ar old Ns = Ns Ar new Oc Op Ar first 155749e11e3aSSheldon HearnThe 155849e11e3aSSheldon Hearn.Ic fc 15598eed22b1SJens Schweikhardtbuilt-in command lists, or edits and re-executes, 156049e11e3aSSheldon Hearncommands previously entered to an interactive shell. 156181e9cda2SRuslan Ermilov.Bl -tag -width indent 156249e11e3aSSheldon Hearn.It Fl e Ar editor 156349e11e3aSSheldon HearnUse the editor named by 156449e11e3aSSheldon Hearn.Ar editor 156549e11e3aSSheldon Hearnto edit the commands. 156649e11e3aSSheldon HearnThe editor string is a command name, 156749e11e3aSSheldon Hearnsubject to search via the 156849e11e3aSSheldon Hearn.Ev PATH 156949e11e3aSSheldon Hearnvariable. 157049e11e3aSSheldon HearnThe value in the 157149e11e3aSSheldon Hearn.Ev FCEDIT 157249e11e3aSSheldon Hearnvariable is used as a default when 157349e11e3aSSheldon Hearn.Fl e 157449e11e3aSSheldon Hearnis not specified. 157549e11e3aSSheldon HearnIf 157649e11e3aSSheldon Hearn.Ev FCEDIT 157749e11e3aSSheldon Hearnis null or unset, the value of the 157849e11e3aSSheldon Hearn.Ev EDITOR 157949e11e3aSSheldon Hearnvariable is used. 158049e11e3aSSheldon HearnIf 158149e11e3aSSheldon Hearn.Ev EDITOR 158249e11e3aSSheldon Hearnis null or unset, 1583ab72124fSSteve Price.Xr ed 1 1584ab72124fSSteve Priceis used as the editor. 158549e11e3aSSheldon Hearn.It Fl l No (ell) 15864b88c807SRodney W. GrimesList the commands rather than invoking 1587eccea571SRuslan Ermilovan editor on them. 1588eccea571SRuslan ErmilovThe commands are written in the 15894b88c807SRodney W. Grimessequence indicated by the first and last operands, as 159049e11e3aSSheldon Hearnaffected by 159149e11e3aSSheldon Hearn.Fl r , 159249e11e3aSSheldon Hearnwith each command preceded by the command number. 159349e11e3aSSheldon Hearn.It Fl n 159449e11e3aSSheldon HearnSuppress command numbers when listing with 159549e11e3aSSheldon Hearn.Fl l . 159649e11e3aSSheldon Hearn.It Fl r 159749e11e3aSSheldon HearnReverse the order of the commands listed 159849e11e3aSSheldon Hearn(with 159949e11e3aSSheldon Hearn.Fl l ) 160049e11e3aSSheldon Hearnor edited 160149e11e3aSSheldon Hearn(with neither 160249e11e3aSSheldon Hearn.Fl l 160349e11e3aSSheldon Hearnnor 160449e11e3aSSheldon Hearn.Fl s ) . 160549e11e3aSSheldon Hearn.It Fl s 16064b88c807SRodney W. GrimesRe-execute the command without invoking an editor. 160749e11e3aSSheldon Hearn.It Ar first 160849e11e3aSSheldon Hearn.It Ar last 160949e11e3aSSheldon HearnSelect the commands to list or edit. 161049e11e3aSSheldon HearnThe number of previous commands that can be accessed 161149e11e3aSSheldon Hearnare determined by the value of the 1612d0353b83SRuslan Ermilov.Ev HISTSIZE 1613d0353b83SRuslan Ermilovvariable. 161449e11e3aSSheldon HearnThe value of 161549e11e3aSSheldon Hearn.Ar first 161649e11e3aSSheldon Hearnor 161749e11e3aSSheldon Hearn.Ar last 161849e11e3aSSheldon Hearnor both are one of the following: 161981e9cda2SRuslan Ermilov.Bl -tag -width indent 162049e11e3aSSheldon Hearn.It Ar [+]num 162149e11e3aSSheldon HearnA positive number representing a command number; 162249e11e3aSSheldon Hearncommand numbers can be displayed with the 162349e11e3aSSheldon Hearn.Fl l 162449e11e3aSSheldon Hearnoption. 162549e11e3aSSheldon Hearn.It Ar -num 162649e11e3aSSheldon HearnA negative decimal number representing the 162749e11e3aSSheldon Hearncommand that was executed 162849e11e3aSSheldon Hearn.Ar num 162949e11e3aSSheldon Hearnof 163049e11e3aSSheldon Hearncommands previously. 163149e11e3aSSheldon HearnFor example, -1 is the immediately previous command. 163249e11e3aSSheldon Hearn.It Ar string 163349e11e3aSSheldon HearnA string indicating the most recently entered command 163449e11e3aSSheldon Hearnthat begins with that string. 163549e11e3aSSheldon HearnIf the 163649e11e3aSSheldon Hearn.Ar old=new 163749e11e3aSSheldon Hearnoperand is not also specified with 163849e11e3aSSheldon Hearn.Fl s , 163949e11e3aSSheldon Hearnthe string form of the first operand cannot contain an embedded equal sign. 164049e11e3aSSheldon Hearn.El 164149e11e3aSSheldon Hearn.El 164249e11e3aSSheldon Hearn.Pp 164349e11e3aSSheldon HearnThe following environment variables affect the execution of 164449e11e3aSSheldon Hearn.Ic fc : 164538afdcbcSGiorgos Keramidas.Bl -tag -width ".Ev HISTSIZE" 164649e11e3aSSheldon Hearn.It Ev FCEDIT 164738afdcbcSGiorgos KeramidasName of the editor to use for history editing. 164849e11e3aSSheldon Hearn.It Ev HISTSIZE 16493d7b5b93SPhilippe CharnierThe number of previous commands that are accessible. 1650ab72124fSSteve Price.El 165149e11e3aSSheldon Hearn.It Ic fg Op Ar job 165249e11e3aSSheldon HearnMove the specified 165349e11e3aSSheldon Hearn.Ar job 165449e11e3aSSheldon Hearnor the current job to the foreground. 165549e11e3aSSheldon Hearn.It Ic getopts Ar optstring Ar var 165649e11e3aSSheldon HearnThe POSIX 165749e11e3aSSheldon Hearn.Ic getopts 165849e11e3aSSheldon Hearncommand. 165949e11e3aSSheldon HearnThe 166049e11e3aSSheldon Hearn.Ic getopts 166149e11e3aSSheldon Hearncommand deprecates the older 166249e11e3aSSheldon Hearn.Xr getopt 1 166349e11e3aSSheldon Hearncommand. 1664ab0a2172SSteve PriceThe first argument should be a series of letters, each possibly 1665ab0a2172SSteve Pricefollowed by a colon which indicates that the option takes an argument. 1666eccea571SRuslan ErmilovThe specified variable is set to the parsed option. 1667eccea571SRuslan ErmilovThe index of 166849e11e3aSSheldon Hearnthe next argument is placed into the shell variable 166949e11e3aSSheldon Hearn.Ev OPTIND . 1670ab0a2172SSteve PriceIf an option takes an argument, it is placed into the shell variable 167149e11e3aSSheldon Hearn.Ev OPTARG . 167249e11e3aSSheldon HearnIf an invalid option is encountered, 167349e11e3aSSheldon Hearn.Ev var 167449e11e3aSSheldon Hearnis set to 16751586940eSRuslan Ermilov.Dq Li \&? . 1676ab0a2172SSteve PriceIt returns a false value (1) when it encounters the end of the options. 167781e9cda2SRuslan Ermilov.It Ic hash Oo Fl rv Oc Op Ar command ... 167849e11e3aSSheldon HearnThe shell maintains a hash table which remembers the locations of commands. 167949e11e3aSSheldon HearnWith no arguments whatsoever, the 168049e11e3aSSheldon Hearn.Ic hash 168149e11e3aSSheldon Hearncommand prints out the contents of this table. 168249e11e3aSSheldon HearnEntries which have not been looked at since the last 168349e11e3aSSheldon Hearn.Ic cd 168449e11e3aSSheldon Hearncommand are marked with an asterisk; 168549e11e3aSSheldon Hearnit is possible for these entries to be invalid. 1686ab72124fSSteve Price.Pp 168749e11e3aSSheldon HearnWith arguments, the 168849e11e3aSSheldon Hearn.Ic hash 168949e11e3aSSheldon Hearncommand removes each specified 169049e11e3aSSheldon Hearn.Ar command 169149e11e3aSSheldon Hearnfrom the hash table (unless they are functions) and then locates it. 169249e11e3aSSheldon HearnWith the 169349e11e3aSSheldon Hearn.Fl v 169449e11e3aSSheldon Hearnoption, 169549e11e3aSSheldon Hearn.Ic hash 169649e11e3aSSheldon Hearnprints the locations of the commands as it finds them. 169749e11e3aSSheldon HearnThe 169849e11e3aSSheldon Hearn.Fl r 169949e11e3aSSheldon Hearnoption causes the 170049e11e3aSSheldon Hearn.Ic hash 170149e11e3aSSheldon Hearncommand to delete all the entries in the hash table except for functions. 170249e11e3aSSheldon Hearn.It Ic jobid Op Ar job 170349e11e3aSSheldon HearnPrint the process id's of the processes in the specified 170449e11e3aSSheldon Hearn.Ar job . 170549e11e3aSSheldon HearnIf the 170649e11e3aSSheldon Hearn.Ar job 170749e11e3aSSheldon Hearnargument is omitted, use the current job. 17089ba31ca0SRuslan Ermilov.It Ic jobs Oo Fl ls Oc Op Ar job ... 1709ad8a0759STim J. RobbinsPrint information about the specified jobs, or all jobs if no 1710ad8a0759STim J. Robbins.Ar job 1711ad8a0759STim J. Robbinsargument is given. 1712ad8a0759STim J. RobbinsThe information printed includes job ID, status and command name. 1713ad8a0759STim J. Robbins.Pp 1714ad8a0759STim J. RobbinsIf the 1715ad8a0759STim J. Robbins.Fl l 1716ad8a0759STim J. Robbinsoption is specified, the PID of each job is also printed. 1717ad8a0759STim J. RobbinsIf the 1718ad8a0759STim J. Robbins.Fl s 17199ba31ca0SRuslan Ermilovoption is specified, only the PIDs of the jobs are printed, one per line. 1720d74e011fSRuslan Ermilov.It Ic pwd Op Fl L | P 1721eccea571SRuslan ErmilovPrint the path of the current directory. 1722eccea571SRuslan ErmilovThe built-in command may 17234b88c807SRodney W. Grimesdiffer from the program of the same name because the 17248eed22b1SJens Schweikhardtbuilt-in command remembers what the current directory 1725eccea571SRuslan Ermilovis rather than recomputing it each time. 1726eccea571SRuslan ErmilovThis makes 1727eccea571SRuslan Ermilovit faster. 1728eccea571SRuslan ErmilovHowever, if the current directory is 172949e11e3aSSheldon Hearnrenamed, 17308eed22b1SJens Schweikhardtthe built-in version of 173149e11e3aSSheldon Hearn.Xr pwd 1 173249e11e3aSSheldon Hearnwill continue to print the old name for the directory. 1733178897f1STim J. Robbins.Pp 1734178897f1STim J. RobbinsIf the 1735178897f1STim J. Robbins.Fl P 1736178897f1STim J. Robbinsoption is specified, symbolic links are resolved. 1737178897f1STim J. RobbinsIf the 1738178897f1STim J. Robbins.Fl L 1739178897f1STim J. Robbinsoption is specified, the shell's notion of the current directory 1740178897f1STim J. Robbinsis printed (symbolic links are not resolved). 1741178897f1STim J. RobbinsThis is the default. 174281e9cda2SRuslan Ermilov.It Ic read Oo Fl p Ar prompt Oc Oo Fl t Ar timeout Oc Oo Fl er Oc Ar variable ... 174349e11e3aSSheldon HearnThe 174449e11e3aSSheldon Hearn.Ar prompt 174549e11e3aSSheldon Hearnis printed if the 174649e11e3aSSheldon Hearn.Fl p 174749e11e3aSSheldon Hearnoption is specified 1748eccea571SRuslan Ermilovand the standard input is a terminal. 1749eccea571SRuslan ErmilovThen a line is 1750eccea571SRuslan Ermilovread from the standard input. 1751eccea571SRuslan ErmilovThe trailing newline 17524b88c807SRodney W. Grimesis deleted from the line and the line is split as 175349e11e3aSSheldon Hearndescribed in the section on 175449e11e3aSSheldon Hearn.Sx White Space Splitting (Field Splitting) 175549e11e3aSSheldon Hearnabove, and 17564b88c807SRodney W. Grimesthe pieces are assigned to the variables in order. 1757f434d1dfSAdam DavidIf there are more pieces than variables, the remaining 175849e11e3aSSheldon Hearnpieces (along with the characters in 175949e11e3aSSheldon Hearn.Ev IFS 176049e11e3aSSheldon Hearnthat separated them) 176149e11e3aSSheldon Hearnare assigned to the last variable. 1762f434d1dfSAdam DavidIf there are more variables than pieces, the remaining 1763f434d1dfSAdam Davidvariables are assigned the null string. 1764ab72124fSSteve Price.Pp 176549e11e3aSSheldon HearnBackslashes are treated specially, unless the 176649e11e3aSSheldon Hearn.Fl r 176749e11e3aSSheldon Hearnoption is 1768eccea571SRuslan Ermilovspecified. 1769eccea571SRuslan ErmilovIf a backslash is followed by 17708f0561ccSThomas Gellekuma newline, the backslash and the newline will be 1771eccea571SRuslan Ermilovdeleted. 1772eccea571SRuslan ErmilovIf a backslash is followed by any other 17738f0561ccSThomas Gellekumcharacter, the backslash will be deleted and the following 177449e11e3aSSheldon Hearncharacter will be treated as though it were not in 177549e11e3aSSheldon Hearn.Ev IFS , 177649e11e3aSSheldon Hearneven if it is. 17778f0561ccSThomas Gellekum.Pp 177849e11e3aSSheldon HearnIf the 177949e11e3aSSheldon Hearn.Fl t 178049e11e3aSSheldon Hearnoption is specified and the 178149e11e3aSSheldon Hearn.Ar timeout 178249e11e3aSSheldon Hearnelapses before any input is supplied, 178349e11e3aSSheldon Hearnthe 178449e11e3aSSheldon Hearn.Ic read 178549e11e3aSSheldon Hearncommand will return without assigning any values. 178649e11e3aSSheldon HearnThe 178749e11e3aSSheldon Hearn.Ar timeout 178849e11e3aSSheldon Hearnvalue may optionally be followed by one of 178949e11e3aSSheldon Hearn.Dq s , 179049e11e3aSSheldon Hearn.Dq m 179149e11e3aSSheldon Hearnor 179249e11e3aSSheldon Hearn.Dq h 1793a910f192SDima Dorfmanto explicitly specify seconds, minutes or hours. 179449e11e3aSSheldon HearnIf none is supplied, 179549e11e3aSSheldon Hearn.Dq s 179649e11e3aSSheldon Hearnis assumed. 1797afa53c8dSMike Smith.Pp 179849e11e3aSSheldon HearnThe 179949e11e3aSSheldon Hearn.Fl e 180049e11e3aSSheldon Hearnoption exists only for backward compatibility with older scripts. 18019ba31ca0SRuslan Ermilov.It Ic readonly Oo Fl p Oc Op Ar name ... 180249e11e3aSSheldon HearnEach specified 180349e11e3aSSheldon Hearn.Ar name 180449e11e3aSSheldon Hearnis marked as read only, 180549e11e3aSSheldon Hearnso that it cannot be subsequently modified or unset. 180649e11e3aSSheldon HearnThe shell allows the value of a variable to be set 180749e11e3aSSheldon Hearnat the same time as it is marked read only 180849e11e3aSSheldon Hearnby using the following form: 1809ab72124fSSteve Price.Bd -literal -offset indent 18104b88c807SRodney W. Grimesreadonly name=value 1811ab72124fSSteve Price.Ed 1812ab72124fSSteve Price.Pp 181349e11e3aSSheldon HearnWith no arguments the 181449e11e3aSSheldon Hearn.Ic readonly 181549e11e3aSSheldon Hearncommand lists the names of all read only variables. 181645086f8cSTim J. RobbinsIf the 181745086f8cSTim J. Robbins.Fl p 181845086f8cSTim J. Robbinsoption is specified, the read-only variables are printed as 181945086f8cSTim J. Robbins.Dq Ic readonly Ar name Ns = Ns Ar value 182045086f8cSTim J. Robbinslines, suitable for re-input to the shell. 182181e9cda2SRuslan Ermilov.It Ic set Oo Fl /+abCEefIimnpTuVvx Oc Oo Fl /+o Ar longname Oc Oo 182281e9cda2SRuslan Ermilov.Fl c Ar string Oc Op Fl - Ar arg ... 1823e918fc8fSSheldon HearnThe 1824e918fc8fSSheldon Hearn.Ic set 1825e918fc8fSSheldon Hearncommand performs three different functions: 1826ab72124fSSteve Price.Bl -item 1827ab72124fSSteve Price.It 182849e11e3aSSheldon HearnWith no arguments, it lists the values of all shell variables. 1829ab72124fSSteve Price.It 183049e11e3aSSheldon HearnIf options are given, 183149e11e3aSSheldon Hearneither in short form or using the long 183249e11e3aSSheldon Hearn.Dq Fl /+o Ar longname 183349e11e3aSSheldon Hearnform, 183449e11e3aSSheldon Hearnit sets or clears the specified options as described in the section called 18356b15476eSSheldon Hearn.Sx Argument List Processing . 1836ab72124fSSteve Price.It 183749e11e3aSSheldon HearnIf the 183849e11e3aSSheldon Hearn.Dq Fl - 183949e11e3aSSheldon Hearnoption is specified, 184049e11e3aSSheldon Hearn.Ic set 184149e11e3aSSheldon Hearnwill replace the shell's positional parameters with the subsequent 184249e11e3aSSheldon Hearnarguments. 184349e11e3aSSheldon HearnIf no arguments follow the 184449e11e3aSSheldon Hearn.Dq Fl - 184549e11e3aSSheldon Hearnoption, 184649e11e3aSSheldon Hearnall the positional parameters will be cleared, 184749e11e3aSSheldon Hearnwhich is equivalent to executing the command 184849e11e3aSSheldon Hearn.Dq Li shift $# . 184949e11e3aSSheldon HearnThe 185049e11e3aSSheldon Hearn.Dq Fl - 18518eed22b1SJens Schweikhardtflag may be omitted when specifying arguments to be used 185249e11e3aSSheldon Hearnas positional replacement parameters. 185349e11e3aSSheldon HearnThis is not recommended, 185449e11e3aSSheldon Hearnbecause the first argument may begin with a dash 1855a762afe5SGiorgos Keramidas.Pq Ql - 185649e11e3aSSheldon Hearnor a plus 1857a762afe5SGiorgos Keramidas.Pq Ql + , 185849e11e3aSSheldon Hearnwhich the 185949e11e3aSSheldon Hearn.Ic set 186049e11e3aSSheldon Hearncommand will interpret as a request to enable or disable options. 1861ab72124fSSteve Price.El 186249e11e3aSSheldon Hearn.It Ic setvar Ar variable Ar value 186349e11e3aSSheldon HearnAssigns the specified 186449e11e3aSSheldon Hearn.Ar value 186549e11e3aSSheldon Hearnto the specified 186649e11e3aSSheldon Hearn.Ar variable . 186749e11e3aSSheldon Hearn.Ic Setvar 186849e11e3aSSheldon Hearnis intended to be used in functions that 1869e6d3cf26SSheldon Hearnassign values to variables whose names are passed as parameters. 187049e11e3aSSheldon HearnIn general it is better to write 187149e11e3aSSheldon Hearn.Bd -literal -offset indent 187249e11e3aSSheldon Hearnvariable=value 187349e11e3aSSheldon Hearn.Ed 187449e11e3aSSheldon Hearnrather than using 187549e11e3aSSheldon Hearn.Ic setvar . 187649e11e3aSSheldon Hearn.It Ic shift Op Ar n 187749e11e3aSSheldon HearnShift the positional parameters 187849e11e3aSSheldon Hearn.Ar n 1879e918fc8fSSheldon Hearntimes, or once if 188049e11e3aSSheldon Hearn.Ar n 188149e11e3aSSheldon Hearnis not specified. 188249e11e3aSSheldon HearnA shift sets the value of $1 to the value of $2, 188349e11e3aSSheldon Hearnthe value of $2 to the value of $3, and so on, 188449e11e3aSSheldon Hearndecreasing the value of $# by one. 188549e11e3aSSheldon HearnIf there are zero positional parameters, shifting does not do anything. 188681e9cda2SRuslan Ermilov.It Ic trap Oo Ar action Oc Ar signal ... 188749e11e3aSSheldon HearnCause the shell to parse and execute 188849e11e3aSSheldon Hearn.Ar action 188949e11e3aSSheldon Hearnwhen any specified 189049e11e3aSSheldon Hearn.Ar signal 189149e11e3aSSheldon Hearnis received. 1892162ae3aeSTony FinchThe signals are specified by name or number. 1893162ae3aeSTony FinchIn addition, the pseudo-signal 1894f5d1157fSRuslan Ermilov.Cm EXIT 1895162ae3aeSTony Finchmay be used to specify an action that is performed when the shell terminates. 189649e11e3aSSheldon HearnThe 189749e11e3aSSheldon Hearn.Ar action 189849e11e3aSSheldon Hearnmay be null or omitted; 189949e11e3aSSheldon Hearnthe former causes the specified signal to be ignored 190049e11e3aSSheldon Hearnand the latter causes the default action to be taken. 190149e11e3aSSheldon HearnWhen the shell forks off a subshell, 190249e11e3aSSheldon Hearnit resets trapped (but not ignored) signals to the default action. 190349e11e3aSSheldon HearnThe 190449e11e3aSSheldon Hearn.Ic trap 190549e11e3aSSheldon Hearncommand has no effect on signals that were ignored on entry to the shell. 190649e11e3aSSheldon Hearn.It Ic type Op Ar name ... 190749e11e3aSSheldon HearnInterpret each 190849e11e3aSSheldon Hearn.Ar name 190949e11e3aSSheldon Hearnas a command and print the resolution of the command search. 1910e6d3cf26SSheldon HearnPossible resolutions are: 19118eed22b1SJens Schweikhardtshell keyword, alias, shell built-in command, command, tracked alias 191249e11e3aSSheldon Hearnand not found. 191349e11e3aSSheldon HearnFor aliases the alias expansion is printed; 191449e11e3aSSheldon Hearnfor commands and tracked aliases 191549e11e3aSSheldon Hearnthe complete pathname of the command is printed. 191662df9b62SSheldon Hearn.It Ic ulimit Oo Fl HSabcdflmnstuv Oc Op Ar limit 1917ab72124fSSteve PriceSet or display resource limits (see 1918ab72124fSSteve Price.Xr getrlimit 2 ) . 19196b15476eSSheldon HearnIf 192049e11e3aSSheldon Hearn.Ar limit 19216b15476eSSheldon Hearnis specified, the named resource will be set; 19227a2afe64SJoerg Wunschotherwise the current resource value will be displayed. 1923ab72124fSSteve Price.Pp 19246b15476eSSheldon HearnIf 192549e11e3aSSheldon Hearn.Fl H 192649e11e3aSSheldon Hearnis specified, the hard limits will be set or displayed. 192749e11e3aSSheldon HearnWhile everybody is allowed to reduce a hard limit, 192849e11e3aSSheldon Hearnonly the superuser can increase it. 192949e11e3aSSheldon HearnThe 193049e11e3aSSheldon Hearn.Fl S 193149e11e3aSSheldon Hearnoption 1932eccea571SRuslan Ermilovspecifies the soft limits instead. 1933eccea571SRuslan ErmilovWhen displaying limits, 19346b15476eSSheldon Hearnonly one of 193549e11e3aSSheldon Hearn.Fl S 19366b15476eSSheldon Hearnor 193749e11e3aSSheldon Hearn.Fl H 193849e11e3aSSheldon Hearncan be given. 193949e11e3aSSheldon HearnThe default is to display the soft limits, 194049e11e3aSSheldon Hearnand to set both the hard and the soft limits. 1941ab72124fSSteve Price.Pp 19426b15476eSSheldon HearnOption 194349e11e3aSSheldon Hearn.Fl a 194449e11e3aSSheldon Hearncauses the 194549e11e3aSSheldon Hearn.Ic ulimit 194649e11e3aSSheldon Hearncommand to display all resources. 194749e11e3aSSheldon HearnThe parameter 194849e11e3aSSheldon Hearn.Ar limit 19496b15476eSSheldon Hearnis not acceptable in this mode. 1950ab72124fSSteve Price.Pp 19517a2afe64SJoerg WunschThe remaining options specify which resource value is to be 195249e11e3aSSheldon Hearndisplayed or modified. 195349e11e3aSSheldon HearnThey are mutually exclusive. 195481e9cda2SRuslan Ermilov.Bl -tag -width indent 19553652a236SMartin Cracauer.It Fl b Ar sbsize 19563652a236SMartin CracauerThe maximum size of socket buffer usage, in bytes. 195749e11e3aSSheldon Hearn.It Fl c Ar coredumpsize 19587a2afe64SJoerg WunschThe maximal size of core dump files, in 512-byte blocks. 195949e11e3aSSheldon Hearn.It Fl d Ar datasize 19607a2afe64SJoerg WunschThe maximal size of the data segment of a process, in kilobytes. 196149e11e3aSSheldon Hearn.It Fl f Ar filesize 196249e11e3aSSheldon HearnThe maximal size of a file, in 512-byte blocks. 196349e11e3aSSheldon Hearn.It Fl l Ar lockedmem 19647a2afe64SJoerg WunschThe maximal size of memory that can be locked by a process, in 19657a2afe64SJoerg Wunschkilobytes. 196649e11e3aSSheldon Hearn.It Fl m Ar memoryuse 19677a2afe64SJoerg WunschThe maximal resident set size of a process, in kilobytes. 196849e11e3aSSheldon Hearn.It Fl n Ar nofiles 19697a2afe64SJoerg WunschThe maximal number of descriptors that could be opened by a process. 197049e11e3aSSheldon Hearn.It Fl s Ar stacksize 19717a2afe64SJoerg WunschThe maximal size of the stack segment, in kilobytes. 197249e11e3aSSheldon Hearn.It Fl t Ar time 19737a2afe64SJoerg WunschThe maximal amount of CPU time to be used by each process, in seconds. 197449e11e3aSSheldon Hearn.It Fl u Ar userproc 1975ab72124fSSteve PriceThe maximal number of simultaneous processes for this user ID. 197662df9b62SSheldon Hearn.It Fl v Ar virtualmem 19772d41ef4bSMatthew DillonThe maximal virtual size of a process, in kilobytes. 1978ab72124fSSteve Price.El 197949e11e3aSSheldon Hearn.It Ic umask Op Ar mask 198049e11e3aSSheldon HearnSet the file creation mask (see 1981ab72124fSSteve Price.Xr umask 2 ) 198249e11e3aSSheldon Hearnto the octal value specified by 19835d3b843bSSheldon Hearn.Ar mask . 198449e11e3aSSheldon HearnIf the argument is omitted, the current mask value is printed. 198581e9cda2SRuslan Ermilov.It Ic unalias Oo Fl a Oc Op Ar name 19866b15476eSSheldon HearnIf 198749e11e3aSSheldon Hearn.Ar name 19886b15476eSSheldon Hearnis specified, the shell removes that alias. 19896b15476eSSheldon HearnIf 19901b9735e6SSheldon Hearn.Fl a 19916b15476eSSheldon Hearnis specified, all aliases are removed. 19929ba31ca0SRuslan Ermilov.It Ic unset Oo Fl fv Oc Ar name ... 19938b34ad92STim J. RobbinsThe specified variables or functions are unset and unexported. 19948b34ad92STim J. RobbinsIf the 19958b34ad92STim J. Robbins.Fl v 19968b34ad92STim J. Robbinsoption is specified or no options are given, the 199749e11e3aSSheldon Hearn.Ar name 19988b34ad92STim J. Robbinsarguments are treated as variable names. 19998b34ad92STim J. RobbinsIf the 20008b34ad92STim J. Robbins.Fl f 20018b34ad92STim J. Robbinsoption is specified, the 20028b34ad92STim J. Robbins.Ar name 20038b34ad92STim J. Robbinsarguments are treated as function names. 200449e11e3aSSheldon Hearn.It Ic wait Op Ar job 200549e11e3aSSheldon HearnWait for the specified 200649e11e3aSSheldon Hearn.Ar job 200749e11e3aSSheldon Hearnto complete and return the exit status of the last process in the 200849e11e3aSSheldon Hearn.Ar job . 2009e6d3cf26SSheldon HearnIf the argument is omitted, wait for all jobs to complete 2010e6d3cf26SSheldon Hearnand return an exit status of zero. 2011ab72124fSSteve Price.El 2012ab72124fSSteve Price.Ss Commandline Editing 2013ab72124fSSteve PriceWhen 2014ab72124fSSteve Price.Nm 2015ab72124fSSteve Priceis being used interactively from a terminal, the current command 201649e11e3aSSheldon Hearnand the command history 201749e11e3aSSheldon Hearn(see 201849e11e3aSSheldon Hearn.Ic fc 201949e11e3aSSheldon Hearnin 20208eed22b1SJens Schweikhardt.Sx Built-in Commands ) 202149e11e3aSSheldon Hearncan be edited using vi-mode command line editing. 202249e11e3aSSheldon HearnThis mode uses commands similar 20234b88c807SRodney W. Grimesto a subset of those described in the vi man page. 202449e11e3aSSheldon HearnThe command 202549e11e3aSSheldon Hearn.Dq Li set -o vi 202649e11e3aSSheldon Hearn(or 2027e918fc8fSSheldon Hearn.Dq Li set -V ) 202849e11e3aSSheldon Hearnenables vi-mode editing and places 2029ab72124fSSteve Price.Nm 2030eccea571SRuslan Ermilovinto vi insert mode. 2031eccea571SRuslan ErmilovWith vi-mode enabled, 2032ab72124fSSteve Price.Nm 203349e11e3aSSheldon Hearncan be switched between insert mode and command mode by typing 203449e11e3aSSheldon Hearn.Aq ESC . 203549e11e3aSSheldon HearnHitting 203649e11e3aSSheldon Hearn.Aq return 203749e11e3aSSheldon Hearnwhile in command mode will pass the line to the shell. 2038ab72124fSSteve Price.Pp 203949e11e3aSSheldon HearnSimilarly, the 204049e11e3aSSheldon Hearn.Dq Li set -o emacs 204149e11e3aSSheldon Hearn(or 2042e918fc8fSSheldon Hearn.Dq Li set -E ) 204349e11e3aSSheldon Hearncommand can be used to enable a subset of 2044ab72124fSSteve Priceemacs-style command line editing features. 204591ee1c5dSGiorgos Keramidas.Sh EXIT STATUS 204691ee1c5dSGiorgos KeramidasErrors that are detected by the shell, such as a syntax error, will 204791ee1c5dSGiorgos Keramidascause the shell to exit with a non-zero exit status. 204891ee1c5dSGiorgos KeramidasIf the shell is not an interactive shell, the execution of the shell 204991ee1c5dSGiorgos Keramidasfile will be aborted. 205091ee1c5dSGiorgos KeramidasOtherwise the shell will return the exit status of the last command 205191ee1c5dSGiorgos Keramidasexecuted, or if the exit builtin is used with a numeric argument, it 205291ee1c5dSGiorgos Keramidaswill return the argument. 205338afdcbcSGiorgos Keramidas.Sh ENVIRONMENT 205438afdcbcSGiorgos KeramidasThe following environment variables affect the execution of 205538afdcbcSGiorgos Keramidas.Nm : 205638afdcbcSGiorgos Keramidas.Bl -tag -width ".Ev HISTSIZE" 205738afdcbcSGiorgos Keramidas.It Ev CDPATH 205838afdcbcSGiorgos KeramidasThe search path used with the 205938afdcbcSGiorgos Keramidas.Ic cd 206038afdcbcSGiorgos Keramidasbuilt-in. 206138afdcbcSGiorgos Keramidas.It Ev EDITOR 206238afdcbcSGiorgos KeramidasThe fallback editor used with the 206338afdcbcSGiorgos Keramidas.Ic fc 206438afdcbcSGiorgos Keramidasbuilt-in. 206538afdcbcSGiorgos KeramidasIf not set, the default editor is 206638afdcbcSGiorgos Keramidas.Xr ed 1 . 206738afdcbcSGiorgos Keramidas.It Ev FCEDIT 206838afdcbcSGiorgos KeramidasThe default editor used with the 206938afdcbcSGiorgos Keramidas.Ic fc 207038afdcbcSGiorgos Keramidasbuilt-in. 207138afdcbcSGiorgos Keramidas.It Ev HISTSIZE 207238afdcbcSGiorgos KeramidasThe number of previous commands that are accessible. 207338afdcbcSGiorgos Keramidas.It Ev HOME 207438afdcbcSGiorgos KeramidasThe starting directory of 207538afdcbcSGiorgos Keramidas.Nm . 207638afdcbcSGiorgos Keramidas.It Ev IFS 207738afdcbcSGiorgos KeramidasInput Field Separators. 207838afdcbcSGiorgos KeramidasThis is normally set to 207938afdcbcSGiorgos Keramidas.Aq space , 208038afdcbcSGiorgos Keramidas.Aq tab , 208138afdcbcSGiorgos Keramidasand 208238afdcbcSGiorgos Keramidas.Aq newline . 208338afdcbcSGiorgos KeramidasSee the 208438afdcbcSGiorgos Keramidas.Sx White Space Splitting 208538afdcbcSGiorgos Keramidassection for more details. 208638afdcbcSGiorgos Keramidas.It Ev MAIL 208738afdcbcSGiorgos KeramidasThe name of a mail file, that will be checked for the arrival of new 208838afdcbcSGiorgos Keramidasmail. 208938afdcbcSGiorgos KeramidasOverridden by 209038afdcbcSGiorgos Keramidas.Ev MAILPATH . 209138afdcbcSGiorgos Keramidas.It Ev MAILPATH 209238afdcbcSGiorgos KeramidasA colon 209338afdcbcSGiorgos Keramidas.Pq Ql \&: 209438afdcbcSGiorgos Keramidasseparated list of file names, for the shell to check for incoming 209538afdcbcSGiorgos Keramidasmail. 209638afdcbcSGiorgos KeramidasThis environment setting overrides the 209738afdcbcSGiorgos Keramidas.Ev MAIL 209838afdcbcSGiorgos Keramidassetting. 209938afdcbcSGiorgos KeramidasThere is a maximum of 10 mailboxes that can be monitored at once. 210038afdcbcSGiorgos Keramidas.It Ev PATH 210138afdcbcSGiorgos KeramidasThe default search path for executables. 210238afdcbcSGiorgos KeramidasSee the 210338afdcbcSGiorgos Keramidas.Sx Path Search 210438afdcbcSGiorgos Keramidassection for details. 210538afdcbcSGiorgos Keramidas.It Ev PS1 210638afdcbcSGiorgos KeramidasThe primary prompt string, which defaults to 210738afdcbcSGiorgos Keramidas.Dq $ \ , 210838afdcbcSGiorgos Keramidasunless you are the superuser, in which case it defaults to 210938afdcbcSGiorgos Keramidas.Dq # \ . 211038afdcbcSGiorgos Keramidas.It Ev PS2 211138afdcbcSGiorgos KeramidasThe secondary prompt string, which defaults to 211238afdcbcSGiorgos Keramidas.Dq \*[Gt] \ . 211338afdcbcSGiorgos Keramidas.It Ev TERM 211438afdcbcSGiorgos KeramidasThe default terminal setting for the shell. 211538afdcbcSGiorgos KeramidasThis is inherited by children of the shell, and is used in the history 211638afdcbcSGiorgos Keramidasediting modes. 211738afdcbcSGiorgos Keramidas.El 2118c83e7c50SJoseph Koshy.Sh SEE ALSO 2119c644db6aSSheldon Hearn.Xr builtin 1 , 212038afdcbcSGiorgos Keramidas.Xr chsh 1 , 2121c644db6aSSheldon Hearn.Xr echo 1 , 212238afdcbcSGiorgos Keramidas.Xr ed 1 , 212338afdcbcSGiorgos Keramidas.Xr emacs 1 , 2124c83e7c50SJoseph Koshy.Xr expr 1 , 212538afdcbcSGiorgos Keramidas.Xr getopt 1 , 21265521ff5aSRuslan Ermilov.Xr pwd 1 , 212738afdcbcSGiorgos Keramidas.Xr test 1 , 212838afdcbcSGiorgos Keramidas.Xr umask 2 , 212938afdcbcSGiorgos Keramidas.Xr vi 1 , 213038afdcbcSGiorgos Keramidas.Xr execve 2 , 213138afdcbcSGiorgos Keramidas.Xr getrlimit 2 , 213238afdcbcSGiorgos Keramidas.Xr editrc 5 2133ab72124fSSteve Price.Sh HISTORY 2134b8923d4cSWolfram SchneiderA 2135ab72124fSSteve Price.Nm 2136b8923d4cSWolfram Schneidercommand appeared in 2137fc482908STim J. Robbins.At v1 . 2138128dc4a2STim J. Robbins.Sh BUGS 2139128dc4a2STim J. RobbinsThe 2140128dc4a2STim J. Robbins.Nm 2141128dc4a2STim J. Robbinsutility does not recognize multibyte characters. 2142