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.\" 35*d806a030SJilles Tjoelker.Dd May 9, 2010 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 60dfe302abSRuslan Ermilovshell clone like 61dfe302abSRuslan Ermilov.Nm pdksh . 6249e11e3aSSheldon HearnOnly features 63dfe302abSRuslan Ermilovdesignated by 64dfe302abSRuslan Ermilov.Tn POSIX , 65dfe302abSRuslan Ermilovplus a few Berkeley extensions, are being 66ab72124fSSteve Priceincorporated into this shell. 6749e11e3aSSheldon HearnThis man page is not intended to be a tutorial nor a complete 684b88c807SRodney W. Grimesspecification of the shell. 69ab72124fSSteve Price.Ss Overview 704b88c807SRodney W. GrimesThe shell is a command that reads lines from 714b88c807SRodney W. Grimeseither a file or the terminal, interprets them, and 72e6d3cf26SSheldon Hearngenerally executes other commands. 7349e11e3aSSheldon HearnIt is the program that is started when a user logs into the system, 7449e11e3aSSheldon Hearnalthough a user can select a different shell with the 75c644db6aSSheldon Hearn.Xr chsh 1 7649e11e3aSSheldon Hearncommand. 774b88c807SRodney W. GrimesThe shell 784b88c807SRodney W. Grimesimplements a language that has flow control constructs, 794b88c807SRodney W. Grimesa macro facility that provides a variety of features in 808eed22b1SJens Schweikhardtaddition to data storage, along with built-in history and line 81eccea571SRuslan Ermilovediting capabilities. 82eccea571SRuslan ErmilovIt incorporates many features to 834b88c807SRodney W. Grimesaid interactive use and has the advantage that the interpretative 844b88c807SRodney W. Grimeslanguage is common to both interactive and non-interactive 85eccea571SRuslan Ermilovuse (shell scripts). 86eccea571SRuslan ErmilovThat is, commands can be typed directly 8749e11e3aSSheldon Hearnto the running shell or can be put into a file, 8849e11e3aSSheldon Hearnwhich can be executed directly by the shell. 89ab72124fSSteve Price.Ss Invocation 9049e11e3aSSheldon Hearn.\" 9149e11e3aSSheldon Hearn.\" XXX This next sentence is incredibly confusing. 9249e11e3aSSheldon Hearn.\" 9349e11e3aSSheldon HearnIf no arguments are present and if the standard input of the shell 9449e11e3aSSheldon Hearnis connected to a terminal 9549e11e3aSSheldon Hearn(or if the 9649e11e3aSSheldon Hearn.Fl i 9749e11e3aSSheldon Hearnoption is set), 98eccea571SRuslan Ermilovthe shell is considered an interactive shell. 99eccea571SRuslan ErmilovAn interactive shell 1004b88c807SRodney W. Grimesgenerally prompts before each command and handles programming 1014b88c807SRodney W. Grimesand command errors differently (as described below). 1024b88c807SRodney W. GrimesWhen first starting, the shell inspects argument 0, and 10349e11e3aSSheldon Hearnif it begins with a dash 104a762afe5SGiorgos Keramidas.Pq Ql - , 10549e11e3aSSheldon Hearnthe shell is also considered a login shell. 10649e11e3aSSheldon HearnThis is normally done automatically by the system 107eccea571SRuslan Ermilovwhen the user first logs in. 108eccea571SRuslan ErmilovA login shell first reads commands 109ab72124fSSteve Pricefrom the files 110ab72124fSSteve Price.Pa /etc/profile 11149e11e3aSSheldon Hearnand then 112ab72124fSSteve Price.Pa .profile 113dfe302abSRuslan Ermilovin a user's home directory, 114eccea571SRuslan Ermilovif they exist. 115eccea571SRuslan ErmilovIf the environment variable 116ab72124fSSteve Price.Ev ENV 117ab72124fSSteve Priceis set on entry to a shell, or is set in the 118ab72124fSSteve Price.Pa .profile 11949e11e3aSSheldon Hearnof a login shell, the shell then reads commands from the file named in 120ab72124fSSteve Price.Ev ENV . 121ab72124fSSteve PriceTherefore, a user should place commands that are to be executed only 122ab72124fSSteve Priceat login time in the 123ab72124fSSteve Price.Pa .profile 124ab72124fSSteve Pricefile, and commands that are executed for every shell inside the 125ab72124fSSteve Price.Ev ENV 126e6d3cf26SSheldon Hearnfile. 12749e11e3aSSheldon HearnThe user can set the 128ab72124fSSteve Price.Ev ENV 12949e11e3aSSheldon Hearnvariable to some file by placing the following line in the file 130ab72124fSSteve Price.Pa .profile 13149e11e3aSSheldon Hearnin the home directory, 132ab72124fSSteve Pricesubstituting for 133ab72124fSSteve Price.Pa .shinit 13449e11e3aSSheldon Hearnthe filename desired: 13549e11e3aSSheldon Hearn.Pp 136dfe302abSRuslan Ermilov.Dl "ENV=$HOME/.shinit; export ENV" 13749e11e3aSSheldon Hearn.Pp 13849e11e3aSSheldon HearnThe first non-option argument specified on the command line 13949e11e3aSSheldon Hearnwill be treated as the 1404b88c807SRodney W. Grimesname of a file from which to read commands (a shell script), and 1414b88c807SRodney W. Grimesthe remaining arguments are set as the positional parameters 142dfe302abSRuslan Ermilovof the shell 143dfe302abSRuslan Ermilov.Li ( $1 , $2 , 144dfe302abSRuslan Ermilovetc.). 145eccea571SRuslan ErmilovOtherwise, the shell reads commands 1464b88c807SRodney W. Grimesfrom its standard input. 147ea76be72SSteve Price.Pp 148ea76be72SSteve PriceUnlike older versions of 149ea76be72SSteve Price.Nm 150ea76be72SSteve Pricethe 151ea76be72SSteve Price.Ev ENV 152eccea571SRuslan Ermilovscript is only sourced on invocation of interactive shells. 153eccea571SRuslan ErmilovThis 154ea76be72SSteve Pricecloses a well-known, and sometimes easily exploitable security 155ea76be72SSteve Pricehole related to poorly thought out 156ea76be72SSteve Price.Ev ENV 157ea76be72SSteve Pricescripts. 158ab72124fSSteve Price.Ss Argument List Processing 159ab72124fSSteve PriceAll of the single letter options to 160ab72124fSSteve Price.Nm 16149e11e3aSSheldon Hearnhave a corresponding long name, 16249e11e3aSSheldon Hearnwith the exception of 16349e11e3aSSheldon Hearn.Fl c 16449e11e3aSSheldon Hearnand 16549e11e3aSSheldon Hearn.Fl /+o . 16649e11e3aSSheldon HearnThese long names are provided next to the single letter options 16749e11e3aSSheldon Hearnin the descriptions below. 16849e11e3aSSheldon HearnThe long name for an option may be specified as an argument to the 16949e11e3aSSheldon Hearn.Fl /+o 17049e11e3aSSheldon Hearnoption of 171facc6767SRuslan Ermilov.Nm . 17249e11e3aSSheldon HearnOnce the shell is running, 17349e11e3aSSheldon Hearnthe long name for an option may be specified as an argument to the 17449e11e3aSSheldon Hearn.Fl /+o 17549e11e3aSSheldon Hearnoption of the 176c644db6aSSheldon Hearn.Ic set 1778eed22b1SJens Schweikhardtbuilt-in command 17849e11e3aSSheldon Hearn(described later in the section called 1798eed22b1SJens Schweikhardt.Sx Built-in Commands ) . 18049e11e3aSSheldon HearnIntroducing an option with a dash 181a762afe5SGiorgos Keramidas.Pq Ql - 18249e11e3aSSheldon Hearnenables the option, 18349e11e3aSSheldon Hearnwhile using a plus 184a762afe5SGiorgos Keramidas.Pq Ql + 18549e11e3aSSheldon Hearndisables the option. 18649e11e3aSSheldon HearnA 18749e11e3aSSheldon Hearn.Dq Li -- 188fab26805SJoseph Koshyor plain 189dfe302abSRuslan Ermilov.Ql - 190fab26805SJoseph Koshywill stop option processing and will force the remaining 191fab26805SJoseph Koshywords on the command line to be treated as arguments. 19249e11e3aSSheldon HearnThe 19349e11e3aSSheldon Hearn.Fl /+o 19449e11e3aSSheldon Hearnand 19549e11e3aSSheldon Hearn.Fl c 19649e11e3aSSheldon Hearnoptions do not have long names. 19749e11e3aSSheldon HearnThey take arguments and are described after the single letter options. 19881e9cda2SRuslan Ermilov.Bl -tag -width indent 199ab72124fSSteve Price.It Fl a Li allexport 20049e11e3aSSheldon HearnFlag variables for export when assignments are made to them. 201ab72124fSSteve Price.It Fl b Li notify 202ab72124fSSteve PriceEnable asynchronous notification of background job 203ab72124fSSteve Pricecompletion. 204c4d9468eSRuslan Ermilov(UNIMPLEMENTED) 205ab72124fSSteve Price.It Fl C Li noclobber 206c644db6aSSheldon HearnDo not overwrite existing files with 207dfe302abSRuslan Ermilov.Ql > . 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 213d5f6b530SJilles Tjoelkeroption if it has been set; 214d5f6b530SJilles Tjoelkerset automatically when interactive on terminals). 215ab72124fSSteve Price.It Fl e Li errexit 21649e11e3aSSheldon HearnExit immediately if any untested command fails in non-interactive mode. 2174b88c807SRodney W. GrimesThe exit status of a command is considered to be 21874053659SStefan Farfelederexplicitly tested if the command is part of the list used to control 2198af11131SRuslan Ermilovan 2208af11131SRuslan Ermilov.Ic if , elif , while , 2218af11131SRuslan Ermilovor 2228af11131SRuslan Ermilov.Ic until ; 2238af11131SRuslan Ermilovif the command is the left 224ab72124fSSteve Pricehand operand of an 22549e11e3aSSheldon Hearn.Dq Li && 226ab72124fSSteve Priceor 22749e11e3aSSheldon Hearn.Dq Li || 22874053659SStefan Farfelederoperator; or if the command is a pipeline preceded by the 22974053659SStefan Farfeleder.Ic !\& 230ab72124fSSteve Priceoperator. 23174053659SStefan FarfelederIf a shell function is executed and its exit status is explicitly 23274053659SStefan Farfeledertested, all commands of the function are considered to be tested as 23374053659SStefan Farfelederwell. 234ab72124fSSteve Price.It Fl f Li noglob 2354b88c807SRodney W. GrimesDisable pathname expansion. 236ab72124fSSteve Price.It Fl I Li ignoreeof 23749e11e3aSSheldon HearnIgnore 238dfe302abSRuslan Ermilov.Dv EOF Ap s 23949e11e3aSSheldon Hearnfrom input when in interactive mode. 240ab72124fSSteve Price.It Fl i Li interactive 241ab72124fSSteve PriceForce the shell to behave interactively. 242ab72124fSSteve Price.It Fl m Li monitor 243ab72124fSSteve PriceTurn on job control (set automatically when interactive). 244ab72124fSSteve Price.It Fl n Li noexec 2454b88c807SRodney W. GrimesIf not interactive, read commands but do not 246eccea571SRuslan Ermilovexecute them. 247eccea571SRuslan ErmilovThis is useful for checking the 2484b88c807SRodney W. Grimessyntax of shell scripts. 2497e1975c2STim J. Robbins.It Fl P Li physical 2507e1975c2STim J. RobbinsChange the default for the 2517e1975c2STim J. Robbins.Ic cd 2527e1975c2STim J. Robbinsand 2537e1975c2STim J. Robbins.Ic pwd 2547e1975c2STim J. Robbinscommands from 2557e1975c2STim J. Robbins.Fl L 2567e1975c2STim J. Robbins(logical directory layout) 2577e1975c2STim J. Robbinsto 2587e1975c2STim J. Robbins.Fl P 2597e1975c2STim J. Robbins(physical directory layout). 260ab72124fSSteve Price.It Fl p Li privileged 261eccea571SRuslan ErmilovTurn on privileged mode. 262eccea571SRuslan ErmilovThis mode is enabled on startup 263dfe302abSRuslan Ermilovif either the effective user or group ID is not equal to the 264dfe302abSRuslan Ermilovreal user or group ID. 265eccea571SRuslan ErmilovTurning this mode off sets the 266dfe302abSRuslan Ermiloveffective user and group IDs to the real user and group IDs. 26749e11e3aSSheldon HearnWhen this mode is enabled for interactive shells, the file 268ab72124fSSteve Price.Pa /etc/suid_profile 26949e11e3aSSheldon Hearnis sourced instead of 27049e11e3aSSheldon Hearn.Pa ~/.profile 271ab72124fSSteve Priceafter 272ab72124fSSteve Price.Pa /etc/profile 27349e11e3aSSheldon Hearnis sourced, and the contents of the 274ab72124fSSteve Price.Ev ENV 27549e11e3aSSheldon Hearnvariable are ignored. 276ab72124fSSteve Price.It Fl s Li stdin 2774b88c807SRodney W. GrimesRead commands from standard input (set automatically 278eccea571SRuslan Ermilovif no file arguments are present). 279eccea571SRuslan ErmilovThis option has 2804b88c807SRodney W. Grimesno effect when set after the shell has already started 281eccea571SRuslan Ermilovrunning (i.e., when set with the 282c644db6aSSheldon Hearn.Ic set 2836b15476eSSheldon Hearncommand). 284304199ceSTom Rhodes.It Fl T Li trapsasync 285e6d3cf26SSheldon HearnWhen waiting for a child, execute traps immediately. 286e6d3cf26SSheldon HearnIf this option is not set, 287e6d3cf26SSheldon Hearntraps are executed after the child exits, 288e6d3cf26SSheldon Hearnas specified in 289af5eb6fcSMaxim Konovalov.St -p1003.2 . 2906b15476eSSheldon HearnThis nonstandard option is useful for putting guarding shells around 291eccea571SRuslan Ermilovchildren that block signals. 292eccea571SRuslan ErmilovThe surrounding shell may kill the child 2936b15476eSSheldon Hearnor it may just return control to the tty and leave the child alone, 2946b15476eSSheldon Hearnlike this: 295c1c72a3cSMartin Cracauer.Bd -literal -offset indent 296c1c72a3cSMartin Cracauersh -T -c "trap 'exit 1' 2 ; some-blocking-program" 297c1c72a3cSMartin Cracauer.Ed 298ab72124fSSteve Price.It Fl u Li nounset 299ab72124fSSteve PriceWrite a message to standard error when attempting 30064254a66SJilles Tjoelkerto expand a variable, a positional parameter or 30164254a66SJilles Tjoelkerthe special parameter 30264254a66SJilles Tjoelker.Va \&! 30364254a66SJilles Tjoelkerthat is not set, and if the 304ab72124fSSteve Priceshell is not interactive, exit immediately. 305ab72124fSSteve Price.It Fl V Li vi 3068eed22b1SJens SchweikhardtEnable the built-in 307ab72124fSSteve Price.Xr vi 1 308ab72124fSSteve Pricecommand line editor (disables 309ab72124fSSteve Price.Fl E 310ab72124fSSteve Priceif it has been set). 311ab72124fSSteve Price.It Fl v Li verbose 312ab72124fSSteve PriceThe shell writes its input to standard error 313eccea571SRuslan Ermilovas it is read. 314eccea571SRuslan ErmilovUseful for debugging. 315ab72124fSSteve Price.It Fl x Li xtrace 31649e11e3aSSheldon HearnWrite each command 317120c8e6cSStefan Farfeleder(preceded by the value of the 318dfe302abSRuslan Ermilov.Va PS4 319120c8e6cSStefan Farfeledervariable) 32049e11e3aSSheldon Hearnto standard error before it is executed. 32149e11e3aSSheldon HearnUseful for debugging. 32249e11e3aSSheldon Hearn.El 32349e11e3aSSheldon Hearn.Pp 32449e11e3aSSheldon HearnThe 325fd50df30SRuslan Ermilov.Fl c 326fd50df30SRuslan Ermilovoption causes the commands to be read from the 327fd50df30SRuslan Ermilov.Ar string 328fd50df30SRuslan Ermilovoperand instead of from the standard input. 329fd50df30SRuslan ErmilovKeep in mind that this option only accepts a single string as its 330fd50df30SRuslan Ermilovargument, hence multi-word strings must be quoted. 331fd50df30SRuslan Ermilov.Pp 332fd50df30SRuslan ErmilovThe 33349e11e3aSSheldon Hearn.Fl /+o 33449e11e3aSSheldon Hearnoption takes as its only argument the long name of an option 33549e11e3aSSheldon Hearnto be enabled or disabled. 33649e11e3aSSheldon HearnFor example, the following two invocations of 33749e11e3aSSheldon Hearn.Nm 3388eed22b1SJens Schweikhardtboth enable the built-in 33949e11e3aSSheldon Hearn.Xr emacs 1 34049e11e3aSSheldon Hearncommand line editor: 34149e11e3aSSheldon Hearn.Bd -literal -offset indent 34249e11e3aSSheldon Hearnset -E 34349e11e3aSSheldon Hearnset -o emacs 34449e11e3aSSheldon Hearn.Ed 345d513af6aSTim J. Robbins.Pp 346d513af6aSTim J. RobbinsIf used without an argument, the 347d513af6aSTim J. Robbins.Fl o 348d513af6aSTim J. Robbinsoption displays the current option settings in a human-readable format. 349d513af6aSTim J. RobbinsIf 350d513af6aSTim J. Robbins.Cm +o 351d513af6aSTim J. Robbinsis used without an argument, the current option settings are output 352d513af6aSTim J. Robbinsin a format suitable for re-input into the shell. 353ab72124fSSteve Price.Ss Lexical Structure 3544b88c807SRodney W. GrimesThe shell reads input in terms of lines from a file and breaks 3554b88c807SRodney W. Grimesit up into words at whitespace (blanks and tabs), and at 3564b88c807SRodney W. Grimescertain sequences of 3576b15476eSSheldon Hearncharacters called 3586b15476eSSheldon Hearn.Dq operators , 3596b15476eSSheldon Hearnwhich are special to the shell. 3604b88c807SRodney W. GrimesThere are two types of operators: control operators and 3614b88c807SRodney W. Grimesredirection operators (their meaning is discussed later). 362ab72124fSSteve PriceThe following is a list of valid operators: 36381e9cda2SRuslan Ermilov.Bl -tag -width indent 36449e11e3aSSheldon Hearn.It Control operators: 36549e11e3aSSheldon Hearn.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 36681e9cda2SRuslan Ermilov.It Li & Ta Li && Ta Li ( Ta Li ) Ta Li \en 36781e9cda2SRuslan Ermilov.It Li ;; Ta Li ; Ta Li | Ta Li || 36849e11e3aSSheldon Hearn.El 36949e11e3aSSheldon Hearn.It Redirection operators: 3704682f420SBrian Somers.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 37181e9cda2SRuslan Ermilov.It Li < Ta Li > Ta Li << Ta Li >> Ta Li <> 37281e9cda2SRuslan Ermilov.It Li <& Ta Li >& Ta Li <<- Ta Li >| 37349e11e3aSSheldon Hearn.El 374ab72124fSSteve Price.El 3757d1a55fcSStefan Farfeleder.Pp 3767d1a55fcSStefan FarfelederThe character 3777d1a55fcSStefan Farfeleder.Ql # 3787d1a55fcSStefan Farfelederintroduces a comment if used at the beginning of a word. 3797d1a55fcSStefan FarfelederThe word starting with 3807d1a55fcSStefan Farfeleder.Ql # 3817d1a55fcSStefan Farfelederand the rest of the line are ignored. 3829764aa41SJilles Tjoelker.Pp 3839764aa41SJilles Tjoelker.Tn ASCII 3849764aa41SJilles Tjoelker.Dv NUL 3859764aa41SJilles Tjoelkercharacters (character code 0) are not allowed in shell input. 386ab72124fSSteve Price.Ss Quoting 3874b88c807SRodney W. GrimesQuoting is used to remove the special meaning of certain characters 388a886288eSJesus R. Camouor words to the shell, such as operators, whitespace, keywords, 389a886288eSJesus R. Camouor alias names. 390a886288eSJesus R. Camou.Pp 391eccea571SRuslan ErmilovThere are three types of quoting: matched single quotes, 3924b88c807SRodney W. Grimesmatched double quotes, and backslash. 39381e9cda2SRuslan Ermilov.Bl -tag -width indent 394ab72124fSSteve Price.It Single Quotes 3954b88c807SRodney W. GrimesEnclosing characters in single quotes preserves the literal 396ab0a2172SSteve Pricemeaning of all the characters (except single quotes, making 397ab0a2172SSteve Priceit impossible to put single-quotes in a single-quoted string). 398ab72124fSSteve Price.It Double Quotes 3994b88c807SRodney W. GrimesEnclosing characters within double quotes preserves the literal 40049e11e3aSSheldon Hearnmeaning of all characters except dollar sign 401a762afe5SGiorgos Keramidas.Pq Ql $ , 40249e11e3aSSheldon Hearnbackquote 403a762afe5SGiorgos Keramidas.Pq Ql ` , 40449e11e3aSSheldon Hearnand backslash 405a762afe5SGiorgos Keramidas.Pq Ql \e . 40649e11e3aSSheldon HearnThe backslash inside double quotes is historically weird. 40749e11e3aSSheldon HearnIt remains literal unless it precedes the following characters, 40849e11e3aSSheldon Hearnwhich it serves to quote: 40949e11e3aSSheldon Hearn.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 41081e9cda2SRuslan Ermilov.It Li $ Ta Li ` Ta Li \&" Ta Li \e\ Ta Li \en 41149e11e3aSSheldon Hearn.El 412ab72124fSSteve Price.It Backslash 413ab72124fSSteve PriceA backslash preserves the literal meaning of the following 41449e11e3aSSheldon Hearncharacter, with the exception of the newline character 415a762afe5SGiorgos Keramidas.Pq Ql \en . 41649e11e3aSSheldon HearnA backslash preceding a newline is treated as a line continuation. 417ab72124fSSteve Price.El 418*d806a030SJilles Tjoelker.Ss Keywords 419*d806a030SJilles TjoelkerKeywords or reserved words are words that have special meaning to the 4204b88c807SRodney W. Grimesshell and are recognized at the beginning of a line and 421eccea571SRuslan Ermilovafter a control operator. 422*d806a030SJilles TjoelkerThe following are keywords: 42349e11e3aSSheldon Hearn.Bl -column "doneXX" "elifXX" "elseXX" "untilXX" "whileX" -offset center 42481e9cda2SRuslan Ermilov.It Li \&! Ta { Ta } Ta Ic case Ta Ic do 42581e9cda2SRuslan Ermilov.It Ic done Ta Ic elif Ta Ic else Ta Ic esac Ta Ic fi 42681e9cda2SRuslan Ermilov.It Ic for Ta Ic if Ta Ic then Ta Ic until Ta Ic while 42749e11e3aSSheldon Hearn.El 428ab72124fSSteve Price.Ss Aliases 429ab72124fSSteve PriceAn alias is a name and corresponding value set using the 430c644db6aSSheldon Hearn.Ic alias 431eccea571SRuslan Ermilovbuilt-in command. 432*d806a030SJilles TjoelkerWhenever a keyword may occur (see above), 433*d806a030SJilles Tjoelkerand after checking for keywords, the shell 434e6d3cf26SSheldon Hearnchecks the word to see if it matches an alias. 435e6d3cf26SSheldon HearnIf it does, it replaces it in the input stream with its value. 436e6d3cf26SSheldon HearnFor example, if there is an alias called 43749e11e3aSSheldon Hearn.Dq Li lf 4386b15476eSSheldon Hearnwith the value 439dfe302abSRuslan Ermilov.Dq Li "ls -F" , 4404b88c807SRodney W. Grimesthen the input 441dfe302abSRuslan Ermilov.Pp 442dfe302abSRuslan Ermilov.Dl "lf foobar" 443ab72124fSSteve Price.Pp 4444b88c807SRodney W. Grimeswould become 445dfe302abSRuslan Ermilov.Pp 446dfe302abSRuslan Ermilov.Dl "ls -F foobar" 447ab72124fSSteve Price.Pp 4484b88c807SRodney W. GrimesAliases provide a convenient way for naive users to 4494b88c807SRodney W. Grimescreate shorthands for commands without having to learn how 450eccea571SRuslan Ermilovto create functions with arguments. 451eccea571SRuslan ErmilovThey can also be 452eccea571SRuslan Ermilovused to create lexically obscure code. 453eccea571SRuslan ErmilovThis use is discouraged. 454a886288eSJesus R. Camou.Pp 455a886288eSJesus R. CamouAn alias name may be escaped in a command line, so that it is not 456a886288eSJesus R. Camoureplaced by its alias value, by using quoting characters within or 45719162ab9SJesus R. Camouadjacent to the alias name. 45819162ab9SJesus R. CamouThis is most often done by prefixing 459a886288eSJesus R. Camouan alias name with a backslash to execute a function, built-in, or 460a886288eSJesus R. Camounormal program with the same name. 461a886288eSJesus R. CamouSee the 462a886288eSJesus R. Camou.Sx Quoting 463a886288eSJesus R. Camousubsection. 464ab72124fSSteve Price.Ss Commands 4654b88c807SRodney W. GrimesThe shell interprets the words it reads according to a 4664b88c807SRodney W. Grimeslanguage, the specification of which is outside the scope 467ab72124fSSteve Priceof this man page (refer to the BNF in the 468ab72124fSSteve Price.St -p1003.2 469eccea571SRuslan Ermilovdocument). 470eccea571SRuslan ErmilovEssentially though, a line is read and if 4714b88c807SRodney W. Grimesthe first word of the line (or after a control operator) 472*d806a030SJilles Tjoelkeris not a keyword, then the shell has recognized a 473eccea571SRuslan Ermilovsimple command. 474eccea571SRuslan ErmilovOtherwise, a complex command or some 4754b88c807SRodney W. Grimesother special construct may have been recognized. 476ab72124fSSteve Price.Ss Simple Commands 4774b88c807SRodney W. GrimesIf a simple command has been recognized, the shell performs 4784b88c807SRodney W. Grimesthe following actions: 479ab72124fSSteve Price.Bl -enum 480ab72124fSSteve Price.It 4816b15476eSSheldon HearnLeading words of the form 48249e11e3aSSheldon Hearn.Dq Li name=value 4836b15476eSSheldon Hearnare stripped off and assigned to the environment of 484eccea571SRuslan Ermilovthe simple command. 485eccea571SRuslan ErmilovRedirection operators and 4864b88c807SRodney W. Grimestheir arguments (as described below) are stripped 4874b88c807SRodney W. Grimesoff and saved for processing. 488ab72124fSSteve Price.It 489ab72124fSSteve PriceThe remaining words are expanded as described in 4906b15476eSSheldon Hearnthe section called 4916b15476eSSheldon Hearn.Sx Word Expansions , 4926b15476eSSheldon Hearnand the first remaining word is considered the command 493eccea571SRuslan Ermilovname and the command is located. 494eccea571SRuslan ErmilovThe remaining 4954b88c807SRodney W. Grimeswords are considered the arguments of the command. 4966b15476eSSheldon HearnIf no command name resulted, then the 49749e11e3aSSheldon Hearn.Dq Li name=value 4984b88c807SRodney W. Grimesvariable assignments recognized in 1) affect the 4994b88c807SRodney W. Grimescurrent shell. 500ab72124fSSteve Price.It 501ab72124fSSteve PriceRedirections are performed as described in 5024b88c807SRodney W. Grimesthe next section. 503ab72124fSSteve Price.El 504ab72124fSSteve Price.Ss Redirections 5054b88c807SRodney W. GrimesRedirections are used to change where a command reads its input 506eccea571SRuslan Ermilovor sends its output. 507eccea571SRuslan ErmilovIn general, redirections open, close, or 508eccea571SRuslan Ermilovduplicate an existing reference to a file. 509eccea571SRuslan ErmilovThe overall format 5104b88c807SRodney W. Grimesused for redirection is: 51149e11e3aSSheldon Hearn.Pp 512dfe302abSRuslan Ermilov.D1 Oo Ar n Oc Ar redir-op file 51349e11e3aSSheldon Hearn.Pp 51449e11e3aSSheldon HearnThe 515dfe302abSRuslan Ermilov.Ar redir-op 51649e11e3aSSheldon Hearnis one of the redirection operators mentioned 517eccea571SRuslan Ermilovpreviously. 518eccea571SRuslan ErmilovThe following gives some examples of how these 51949e11e3aSSheldon Hearnoperators can be used. 52049e11e3aSSheldon HearnNote that stdin and stdout are commonly used abbreviations 52149e11e3aSSheldon Hearnfor standard input and standard output respectively. 52249e11e3aSSheldon Hearn.Bl -tag -width "1234567890XX" -offset indent 523dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li > Ar file 524dfe302abSRuslan Ermilovredirect stdout (or file descriptor 525dfe302abSRuslan Ermilov.Ar n ) 526dfe302abSRuslan Ermilovto 527dfe302abSRuslan Ermilov.Ar file 528dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li >| Ar file 52949e11e3aSSheldon Hearnsame as above, but override the 53049e11e3aSSheldon Hearn.Fl C 53149e11e3aSSheldon Hearnoption 532dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li >> Ar file 533dfe302abSRuslan Ermilovappend stdout (or file descriptor 534dfe302abSRuslan Ermilov.Ar n ) 535dfe302abSRuslan Ermilovto 536dfe302abSRuslan Ermilov.Ar file 537dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li < Ar file 538dfe302abSRuslan Ermilovredirect stdin (or file descriptor 539dfe302abSRuslan Ermilov.Ar n ) 540dfe302abSRuslan Ermilovfrom 541dfe302abSRuslan Ermilov.Ar file 542dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li <> Ar file 543dfe302abSRuslan Ermilovredirect stdin (or file descriptor 544dfe302abSRuslan Ermilov.Ar n ) 545dfe302abSRuslan Ermilovto and from 546dfe302abSRuslan Ermilov.Ar file 547dfe302abSRuslan Ermilov.It Oo Ar n1 Oc Ns Li <& Ns Ar n2 548dfe302abSRuslan Ermilovduplicate stdin (or file descriptor 549dfe302abSRuslan Ermilov.Ar n1 ) 550dfe302abSRuslan Ermilovfrom file descriptor 551dfe302abSRuslan Ermilov.Ar n2 552dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li <&- 553dfe302abSRuslan Ermilovclose stdin (or file descriptor 554dfe302abSRuslan Ermilov.Ar n ) 555dfe302abSRuslan Ermilov.It Oo Ar n1 Oc Ns Li >& Ns Ar n2 556dfe302abSRuslan Ermilovduplicate stdout (or file descriptor 557dfe302abSRuslan Ermilov.Ar n1 ) 558dfe302abSRuslan Ermilovto file descriptor 559dfe302abSRuslan Ermilov.Ar n2 560dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li >&- 561dfe302abSRuslan Ermilovclose stdout (or file descriptor 562dfe302abSRuslan Ermilov.Ar n ) 563ab72124fSSteve Price.El 564ab72124fSSteve Price.Pp 5656b15476eSSheldon HearnThe following redirection is often called a 5666b15476eSSheldon Hearn.Dq here-document . 567dfe302abSRuslan Ermilov.Bd -unfilled -offset indent 568dfe302abSRuslan Ermilov.Oo Ar n Oc Ns Li << Ar delimiter 569dfe302abSRuslan Ermilov.D1 Ar here-doc-text 570dfe302abSRuslan Ermilov.D1 ... 571dfe302abSRuslan Ermilov.Ar delimiter 572ab72124fSSteve Price.Ed 573ab72124fSSteve Price.Pp 5744b88c807SRodney W. GrimesAll the text on successive lines up to the delimiter is 5754b88c807SRodney W. Grimessaved away and made available to the command on standard 576dfe302abSRuslan Ermilovinput, or file descriptor 577dfe302abSRuslan Ermilov.Ar n 578dfe302abSRuslan Ermilovif it is specified. 579dfe302abSRuslan ErmilovIf the 580dfe302abSRuslan Ermilov.Ar delimiter 581dfe302abSRuslan Ermilovas specified on the initial line is quoted, then the 582dfe302abSRuslan Ermilov.Ar here-doc-text 5834b88c807SRodney W. Grimesis treated literally, otherwise the text is subjected to 5844b88c807SRodney W. Grimesparameter expansion, command substitution, and arithmetic 5856b15476eSSheldon Hearnexpansion (as described in the section on 5866b15476eSSheldon Hearn.Sx Word Expansions ) . 5876b15476eSSheldon HearnIf the operator is 58849e11e3aSSheldon Hearn.Dq Li <<- 5896b15476eSSheldon Hearninstead of 59049e11e3aSSheldon Hearn.Dq Li << , 5916b15476eSSheldon Hearnthen leading tabs 592dfe302abSRuslan Ermilovin the 593dfe302abSRuslan Ermilov.Ar here-doc-text 594dfe302abSRuslan Ermilovare stripped. 595ab72124fSSteve Price.Ss Search and Execution 596ab0a2172SSteve PriceThere are three types of commands: shell functions, 5978eed22b1SJens Schweikhardtbuilt-in commands, and normal programs. 59849e11e3aSSheldon HearnThe command is searched for (by name) in that order. 59949e11e3aSSheldon HearnThe three types of commands are all executed in a different way. 600ab72124fSSteve Price.Pp 601ab0a2172SSteve PriceWhen a shell function is executed, all of the shell positional 602dfe302abSRuslan Ermilovparameters (except 603dfe302abSRuslan Ermilov.Li $0 , 604dfe302abSRuslan Ermilovwhich remains unchanged) are 6054b88c807SRodney W. Grimesset to the arguments of the shell function. 6064b88c807SRodney W. GrimesThe variables which are explicitly placed in the environment of 6074b88c807SRodney W. Grimesthe command (by placing assignments to them before the 6084b88c807SRodney W. Grimesfunction name) are made local to the function and are set 609e6d3cf26SSheldon Hearnto the values given. 610e6d3cf26SSheldon HearnThen the command given in the function definition is executed. 611e6d3cf26SSheldon HearnThe positional parameters are restored to their original values 612e6d3cf26SSheldon Hearnwhen the command completes. 613ab0a2172SSteve PriceThis all occurs within the current shell. 614ab72124fSSteve Price.Pp 6158eed22b1SJens SchweikhardtShell built-in commands are executed internally to the shell, without 616ab0a2172SSteve Pricespawning a new process. 61730268dfaSJilles TjoelkerThere are two kinds of built-in commands: regular and special. 61830268dfaSJilles TjoelkerAssignments before special builtins persist after they finish 61930268dfaSJilles Tjoelkerexecuting and assignment errors, redirection errors and certain 62030268dfaSJilles Tjoelkeroperand errors cause a script to be aborted. 62130268dfaSJilles TjoelkerBoth regular and special builtins can affect the shell in ways 62230268dfaSJilles Tjoelkernormal programs cannot. 623ab72124fSSteve Price.Pp 624c644db6aSSheldon HearnOtherwise, if the command name does not match a function 6258eed22b1SJens Schweikhardtor built-in command, the command is searched for as a normal 6264b88c807SRodney W. Grimesprogram in the file system (as described in the next section). 6274b88c807SRodney W. GrimesWhen a normal program is executed, the shell runs the program, 628e6d3cf26SSheldon Hearnpassing the arguments and the environment to the program. 629e6d3cf26SSheldon HearnIf the program is not a normal executable file 630eccea571SRuslan Ermilov(i.e., if it does not begin with the 631dfe302abSRuslan Ermilov.Dq "magic number" 6326b15476eSSheldon Hearnwhose 633ab72124fSSteve Price.Tn ASCII 6346b15476eSSheldon Hearnrepresentation is 635dfe302abSRuslan Ermilov.Dq Li #! , 63649e11e3aSSheldon Hearnresulting in an 637b4f0f4aaSRuslan Ermilov.Er ENOEXEC 63849e11e3aSSheldon Hearnreturn value from 63949e11e3aSSheldon Hearn.Xr execve 2 ) 640e6d3cf26SSheldon Hearnthe shell will interpret the program in a subshell. 641e6d3cf26SSheldon HearnThe child shell will reinitialize itself in this case, 642e6d3cf26SSheldon Hearnso that the effect will be 643e6d3cf26SSheldon Hearnas if a new shell had been invoked to handle the ad-hoc shell script, 644e6d3cf26SSheldon Hearnexcept that the location of hashed commands located in 645dfe302abSRuslan Ermilovthe parent shell will be remembered by the child 646dfe302abSRuslan Ermilov(see the description of the 647dfe302abSRuslan Ermilov.Ic hash 648dfe302abSRuslan Ermilovbuilt-in command below). 649ab72124fSSteve Price.Pp 650ab0a2172SSteve PriceNote that previous versions of this document 651ab0a2172SSteve Priceand the source code itself misleadingly and sporadically 652ab0a2172SSteve Pricerefer to a shell script without a magic number 6536b15476eSSheldon Hearnas a 654dfe302abSRuslan Ermilov.Dq "shell procedure" . 655ab72124fSSteve Price.Ss Path Search 6564b88c807SRodney W. GrimesWhen locating a command, the shell first looks to see if 657eccea571SRuslan Ermilovit has a shell function by that name. 658eccea571SRuslan ErmilovThen it looks for a 659eccea571SRuslan Ermilovbuilt-in command by that name. 660eccea571SRuslan ErmilovIf a built-in command is not found, 661ab0a2172SSteve Priceone of two things happen: 662ab72124fSSteve Price.Bl -enum 663ab72124fSSteve Price.It 664ab72124fSSteve PriceCommand names containing a slash are simply executed without 665ab0a2172SSteve Priceperforming any searches. 666ab72124fSSteve Price.It 667dfe302abSRuslan ErmilovThe shell searches each entry in the 668ab72124fSSteve Price.Ev PATH 669dfe302abSRuslan Ermilovenvironment variable 670eccea571SRuslan Ermilovin turn for the command. 671eccea571SRuslan ErmilovThe value of the 672ab72124fSSteve Price.Ev PATH 673ab72124fSSteve Pricevariable should be a series of 674eccea571SRuslan Ermiloventries separated by colons. 675eccea571SRuslan ErmilovEach entry consists of a 6764b88c807SRodney W. Grimesdirectory name. 6774b88c807SRodney W. GrimesThe current directory 678ab0a2172SSteve Pricemay be indicated implicitly by an empty directory name, 679ab0a2172SSteve Priceor explicitly by a single period. 680ab72124fSSteve Price.El 681ab72124fSSteve Price.Ss Command Exit Status 6824b88c807SRodney W. GrimesEach command has an exit status that can influence the behavior 683eccea571SRuslan Ermilovof other shell commands. 684eccea571SRuslan ErmilovThe paradigm is that a command exits 6854b88c807SRodney W. Grimeswith zero for normal or success, and non-zero for failure, 686eccea571SRuslan Ermiloverror, or a false indication. 687eccea571SRuslan ErmilovThe man page for each command 6884b88c807SRodney W. Grimesshould indicate the various exit codes and what they mean. 6898eed22b1SJens SchweikhardtAdditionally, the built-in commands return exit codes, as does 690ab0a2172SSteve Pricean executed shell function. 691c351e089SJohn Polstra.Pp 692c351e089SJohn PolstraIf a command is terminated by a signal, its exit status is 128 plus 693eccea571SRuslan Ermilovthe signal number. 694eccea571SRuslan ErmilovSignal numbers are defined in the header file 695fe08efe6SRuslan Ermilov.In sys/signal.h . 696ab72124fSSteve Price.Ss Complex Commands 6974b88c807SRodney W. GrimesComplex commands are combinations of simple commands 698*d806a030SJilles Tjoelkerwith control operators or keywords, together creating a larger complex 699eccea571SRuslan Ermilovcommand. 700eccea571SRuslan ErmilovMore generally, a command is one of the following: 701ab72124fSSteve Price.Bl -item -offset indent 702ab72124fSSteve Price.It 703ab72124fSSteve Pricesimple command 704ab72124fSSteve Price.It 705ab72124fSSteve Pricepipeline 706ab72124fSSteve Price.It 707ab72124fSSteve Pricelist or compound-list 708ab72124fSSteve Price.It 709ab72124fSSteve Pricecompound command 710ab72124fSSteve Price.It 711ab72124fSSteve Pricefunction definition 712ab72124fSSteve Price.El 713ab72124fSSteve Price.Pp 7144b88c807SRodney W. GrimesUnless otherwise stated, the exit status of a command is 7154b88c807SRodney W. Grimesthat of the last simple command executed by the command. 716ab72124fSSteve Price.Ss Pipelines 7174b88c807SRodney W. GrimesA pipeline is a sequence of one or more commands separated 718dfe302abSRuslan Ermilovby the control operator 719dfe302abSRuslan Ermilov.Ql \&| . 720eccea571SRuslan ErmilovThe standard output of all but 7214b88c807SRodney W. Grimesthe last command is connected to the standard input 722eccea571SRuslan Ermilovof the next command. 723eccea571SRuslan ErmilovThe standard output of the last 724ab0a2172SSteve Pricecommand is inherited from the shell, as usual. 725ab72124fSSteve Price.Pp 7264b88c807SRodney W. GrimesThe format for a pipeline is: 72749e11e3aSSheldon Hearn.Pp 728dfe302abSRuslan Ermilov.D1 Oo Li \&! Oc Ar command1 Op Li \&| Ar command2 ... 729ab72124fSSteve Price.Pp 730dfe302abSRuslan ErmilovThe standard output of 731dfe302abSRuslan Ermilov.Ar command1 732dfe302abSRuslan Ermilovis connected to the standard input of 733dfe302abSRuslan Ermilov.Ar command2 . 734eccea571SRuslan ErmilovThe standard input, standard output, or 7354b88c807SRodney W. Grimesboth of a command is considered to be assigned by the 7364b88c807SRodney W. Grimespipeline before any redirection specified by redirection 7374b88c807SRodney W. Grimesoperators that are part of the command. 738ab72124fSSteve Price.Pp 7394b88c807SRodney W. GrimesIf the pipeline is not in the background (discussed later), 7404b88c807SRodney W. Grimesthe shell waits for all commands to complete. 741ab72124fSSteve Price.Pp 742*d806a030SJilles TjoelkerIf the keyword 743eccea571SRuslan Ermilov.Ic !\& 744eccea571SRuslan Ermilovdoes not precede the pipeline, the 7454b88c807SRodney W. Grimesexit status is the exit status of the last command specified 746eccea571SRuslan Ermilovin the pipeline. 747eccea571SRuslan ErmilovOtherwise, the exit status is the logical 748eccea571SRuslan ErmilovNOT of the exit status of the last command. 749eccea571SRuslan ErmilovThat is, if 7504b88c807SRodney W. Grimesthe last command returns zero, the exit status is 1; if 7514b88c807SRodney W. Grimesthe last command returns greater than zero, the exit status 7524b88c807SRodney W. Grimesis zero. 753ab72124fSSteve Price.Pp 7544b88c807SRodney W. GrimesBecause pipeline assignment of standard input or standard 7554b88c807SRodney W. Grimesoutput or both takes place before redirection, it can be 756eccea571SRuslan Ermilovmodified by redirection. 757eccea571SRuslan ErmilovFor example: 758ab72124fSSteve Price.Pp 759dfe302abSRuslan Ermilov.Dl "command1 2>&1 | command2" 760ab72124fSSteve Price.Pp 76149e11e3aSSheldon Hearnsends both the standard output and standard error of 762dfe302abSRuslan Ermilov.Ar command1 76349e11e3aSSheldon Hearnto the standard input of 764dfe302abSRuslan Ermilov.Ar command2 . 76549e11e3aSSheldon Hearn.Pp 76649e11e3aSSheldon HearnA 767dfe302abSRuslan Ermilov.Ql \&; 76849e11e3aSSheldon Hearnor newline terminator causes the preceding 769e918fc8fSSheldon HearnAND-OR-list 770e918fc8fSSheldon Hearn(described below in the section called 771e918fc8fSSheldon Hearn.Sx Short-Circuit List Operators ) 772e918fc8fSSheldon Hearnto be executed sequentially; 773e918fc8fSSheldon Hearnan 774dfe302abSRuslan Ermilov.Ql & 775e918fc8fSSheldon Hearncauses asynchronous execution of the preceding AND-OR-list. 776ab72124fSSteve Price.Pp 77749e11e3aSSheldon HearnNote that unlike some other shells, 77849e11e3aSSheldon Hearn.Nm 77949e11e3aSSheldon Hearnexecutes each process in the pipeline as a child of the 78049e11e3aSSheldon Hearn.Nm 78149e11e3aSSheldon Hearnprocess. 7828eed22b1SJens SchweikhardtShell built-in commands are the exception to this rule. 78349e11e3aSSheldon HearnThey are executed in the current shell, although they do not affect its 78449e11e3aSSheldon Hearnenvironment when used in pipelines. 78549e11e3aSSheldon Hearn.Ss Background Commands (&) 7864b88c807SRodney W. GrimesIf a command is terminated by the control operator ampersand 787a762afe5SGiorgos Keramidas.Pq Ql & , 78849e11e3aSSheldon Hearnthe shell executes the command asynchronously; 78949e11e3aSSheldon Hearnthe shell does not wait for the command to finish 79049e11e3aSSheldon Hearnbefore executing the next command. 791ab72124fSSteve Price.Pp 7924b88c807SRodney W. GrimesThe format for running a command in background is: 793dfe302abSRuslan Ermilov.Pp 794dfe302abSRuslan Ermilov.D1 Ar command1 Li & Op Ar command2 Li & Ar ... 795ab72124fSSteve Price.Pp 7964b88c807SRodney W. GrimesIf the shell is not interactive, the standard input of an 797dfe302abSRuslan Ermilovasynchronous command is set to 798dfe302abSRuslan Ermilov.Pa /dev/null . 79949e11e3aSSheldon Hearn.Ss Lists (Generally Speaking) 8004b88c807SRodney W. GrimesA list is a sequence of zero or more commands separated by 8014b88c807SRodney W. Grimesnewlines, semicolons, or ampersands, 8024b88c807SRodney W. Grimesand optionally terminated by one of these three characters. 8034b88c807SRodney W. GrimesThe commands in a 8044b88c807SRodney W. Grimeslist are executed in the order they are written. 8054b88c807SRodney W. GrimesIf command is followed by an ampersand, the shell starts the 8068eed22b1SJens Schweikhardtcommand and immediately proceeds onto the next command; 8074b88c807SRodney W. Grimesotherwise it waits for the command to terminate before 8084b88c807SRodney W. Grimesproceeding to the next one. 809ab72124fSSteve Price.Ss Short-Circuit List Operators 81049e11e3aSSheldon Hearn.Dq Li && 8116b15476eSSheldon Hearnand 81249e11e3aSSheldon Hearn.Dq Li || 8136b15476eSSheldon Hearnare AND-OR list operators. 81449e11e3aSSheldon Hearn.Dq Li && 8156b15476eSSheldon Hearnexecutes the first command, and then executes the second command 8166b15476eSSheldon Hearnif the exit status of the first command is zero. 81749e11e3aSSheldon Hearn.Dq Li || 818120ac26dSMasafumi Max NAKANEis similar, but executes the second command if the exit 8196b15476eSSheldon Hearnstatus of the first command is nonzero. 82049e11e3aSSheldon Hearn.Dq Li && 8216b15476eSSheldon Hearnand 82249e11e3aSSheldon Hearn.Dq Li || 8234b88c807SRodney W. Grimesboth have the same priority. 82449e11e3aSSheldon Hearn.Ss Flow-Control Constructs (if, while, for, case) 82549e11e3aSSheldon HearnThe syntax of the 82649e11e3aSSheldon Hearn.Ic if 82749e11e3aSSheldon Hearncommand is: 828dfe302abSRuslan Ermilov.Bd -unfilled -offset indent -compact 829dfe302abSRuslan Ermilov.Ic if Ar list 830dfe302abSRuslan Ermilov.Ic then Ar list 831dfe302abSRuslan Ermilov.Oo Ic elif Ar list 832dfe302abSRuslan Ermilov.Ic then Ar list Oc Ar ... 833dfe302abSRuslan Ermilov.Op Ic else Ar list 834dfe302abSRuslan Ermilov.Ic fi 835dfe302abSRuslan Ermilov.Ed 836ab72124fSSteve Price.Pp 83749e11e3aSSheldon HearnThe syntax of the 83849e11e3aSSheldon Hearn.Ic while 83949e11e3aSSheldon Hearncommand is: 840dfe302abSRuslan Ermilov.Bd -unfilled -offset indent -compact 841dfe302abSRuslan Ermilov.Ic while Ar list 842dfe302abSRuslan Ermilov.Ic do Ar list 843dfe302abSRuslan Ermilov.Ic done 844dfe302abSRuslan Ermilov.Ed 845ab72124fSSteve Price.Pp 846ab0a2172SSteve PriceThe two lists are executed repeatedly while the exit status of the 84749e11e3aSSheldon Hearnfirst list is zero. 84849e11e3aSSheldon HearnThe 84949e11e3aSSheldon Hearn.Ic until 85049e11e3aSSheldon Hearncommand is similar, but has the word 85149e11e3aSSheldon Hearn.Ic until 85249e11e3aSSheldon Hearnin place of 85349e11e3aSSheldon Hearn.Ic while , 85449e11e3aSSheldon Hearnwhich causes it to 8554b88c807SRodney W. Grimesrepeat until the exit status of the first list is zero. 856ab72124fSSteve Price.Pp 85749e11e3aSSheldon HearnThe syntax of the 85849e11e3aSSheldon Hearn.Ic for 85949e11e3aSSheldon Hearncommand is: 860dfe302abSRuslan Ermilov.Bd -unfilled -offset indent -compact 861dfe302abSRuslan Ermilov.Ic for Ar variable Op Ic in Ar word ... 862dfe302abSRuslan Ermilov.Ic do Ar list 863dfe302abSRuslan Ermilov.Ic done 864dfe302abSRuslan Ermilov.Ed 865ab72124fSSteve Price.Pp 866a01459dfSStefan FarfelederIf 867a01459dfSStefan Farfeleder.Ic in 8687b14d37fSRalf S. Engelschalland the following words are omitted, 869776e6b33SJilles Tjoelker.Ic in Li \&"$@\&" 870a01459dfSStefan Farfelederis used instead. 8714b88c807SRodney W. GrimesThe words are expanded, and then the list is executed 87249e11e3aSSheldon Hearnrepeatedly with the variable set to each word in turn. 87349e11e3aSSheldon HearnThe 87449e11e3aSSheldon Hearn.Ic do 8756b15476eSSheldon Hearnand 87649e11e3aSSheldon Hearn.Ic done 87749e11e3aSSheldon Hearncommands may be replaced with 878dfe302abSRuslan Ermilov.Ql { 87949e11e3aSSheldon Hearnand 880dfe302abSRuslan Ermilov.Ql } . 881ab72124fSSteve Price.Pp 88249e11e3aSSheldon HearnThe syntax of the 88349e11e3aSSheldon Hearn.Ic break 88449e11e3aSSheldon Hearnand 88549e11e3aSSheldon Hearn.Ic continue 88649e11e3aSSheldon Hearncommands is: 887dfe302abSRuslan Ermilov.D1 Ic break Op Ar num 888dfe302abSRuslan Ermilov.D1 Ic continue Op Ar num 889ab72124fSSteve Price.Pp 89049e11e3aSSheldon HearnThe 89149e11e3aSSheldon Hearn.Ic break 89249e11e3aSSheldon Hearncommand terminates the 89349e11e3aSSheldon Hearn.Ar num 89449e11e3aSSheldon Hearninnermost 89549e11e3aSSheldon Hearn.Ic for 89649e11e3aSSheldon Hearnor 89749e11e3aSSheldon Hearn.Ic while 89849e11e3aSSheldon Hearnloops. 89949e11e3aSSheldon HearnThe 90049e11e3aSSheldon Hearn.Ic continue 90149e11e3aSSheldon Hearncommand continues with the next iteration of the innermost loop. 90230268dfaSJilles TjoelkerThese are implemented as special built-in commands. 903ab72124fSSteve Price.Pp 90449e11e3aSSheldon HearnThe syntax of the 90549e11e3aSSheldon Hearn.Ic case 906dfe302abSRuslan Ermilovcommand is: 907dfe302abSRuslan Ermilov.Bd -unfilled -offset indent -compact 908dfe302abSRuslan Ermilov.Ic case Ar word Ic in 909dfe302abSRuslan Ermilov.Ar pattern Ns Li ) Ar list Li ;; 910dfe302abSRuslan Ermilov.Ar ... 911dfe302abSRuslan Ermilov.Ic esac 912dfe302abSRuslan Ermilov.Ed 913ab72124fSSteve Price.Pp 91449e11e3aSSheldon HearnThe pattern can actually be one or more patterns 91549e11e3aSSheldon Hearn(see 91649e11e3aSSheldon Hearn.Sx Shell Patterns 91749e11e3aSSheldon Hearndescribed later), 91849e11e3aSSheldon Hearnseparated by 919dfe302abSRuslan Ermilov.Ql \&| 9206b15476eSSheldon Hearncharacters. 921aafd6a87SStefan FarfelederThe exit code of the 922aafd6a87SStefan Farfeleder.Ic case 923aafd6a87SStefan Farfeledercommand is the exit code of the last command executed in the list or 924aafd6a87SStefan Farfelederzero if no patterns were matched. 925ab72124fSSteve Price.Ss Grouping Commands Together 9264b88c807SRodney W. GrimesCommands may be grouped by writing either 927dfe302abSRuslan Ermilov.Pp 928dfe302abSRuslan Ermilov.D1 Li \&( Ns Ar list Ns Li \%) 929ab72124fSSteve Price.Pp 9304b88c807SRodney W. Grimesor 931dfe302abSRuslan Ermilov.Pp 932dfe302abSRuslan Ermilov.D1 Li { Ar list Ns Li \&; } 933ab72124fSSteve Price.Pp 93449e11e3aSSheldon HearnThe first form executes the commands in a subshell. 9358eed22b1SJens SchweikhardtNote that built-in commands thus executed do not affect the current shell. 93649e11e3aSSheldon HearnThe second form does not fork another shell, 93749e11e3aSSheldon Hearnso it is slightly more efficient. 93849e11e3aSSheldon HearnGrouping commands together this way allows the user to 939ab0a2172SSteve Priceredirect their output as though they were one program: 940ab72124fSSteve Price.Bd -literal -offset indent 941ee7dc416SSteve Price{ echo -n "hello"; echo " world"; } > greeting 942ab72124fSSteve Price.Ed 943ab72124fSSteve Price.Ss Functions 9444b88c807SRodney W. GrimesThe syntax of a function definition is 945dfe302abSRuslan Ermilov.Pp 946dfe302abSRuslan Ermilov.D1 Ar name Li \&( \&) Ar command 947ab72124fSSteve Price.Pp 9484b88c807SRodney W. GrimesA function definition is an executable statement; when 949dfe302abSRuslan Ermilovexecuted it installs a function named 950dfe302abSRuslan Ermilov.Ar name 951dfe302abSRuslan Ermilovand returns an 952eccea571SRuslan Ermilovexit status of zero. 953dfe302abSRuslan ErmilovThe 954dfe302abSRuslan Ermilov.Ar command 955dfe302abSRuslan Ermilovis normally a list 9566b15476eSSheldon Hearnenclosed between 957dfe302abSRuslan Ermilov.Ql { 9586b15476eSSheldon Hearnand 959dfe302abSRuslan Ermilov.Ql } . 960ab72124fSSteve Price.Pp 9614b88c807SRodney W. GrimesVariables may be declared to be local to a function by 96249e11e3aSSheldon Hearnusing the 96349e11e3aSSheldon Hearn.Ic local 96449e11e3aSSheldon Hearncommand. 96549e11e3aSSheldon HearnThis should appear as the first statement of a function, 96649e11e3aSSheldon Hearnand the syntax is: 967dfe302abSRuslan Ermilov.Pp 968dfe302abSRuslan Ermilov.D1 Ic local Oo Ar variable ... Oc Op Fl 969ab72124fSSteve Price.Pp 97049e11e3aSSheldon HearnThe 97149e11e3aSSheldon Hearn.Ic local 9728eed22b1SJens Schweikhardtcommand is implemented as a built-in command. 973ab72124fSSteve Price.Pp 9744b88c807SRodney W. GrimesWhen a variable is made local, it inherits the initial 9754b88c807SRodney W. Grimesvalue and exported and readonly flags from the variable 9764b88c807SRodney W. Grimeswith the same name in the surrounding scope, if there is 977eccea571SRuslan Ermilovone. 978eccea571SRuslan ErmilovOtherwise, the variable is initially unset. 979eccea571SRuslan ErmilovThe shell 980e918fc8fSSheldon Hearnuses dynamic scoping, so that if the variable 981dfe302abSRuslan Ermilov.Va x 982e918fc8fSSheldon Hearnis made local to function 983e918fc8fSSheldon Hearn.Em f , 984e918fc8fSSheldon Hearnwhich then calls function 985e918fc8fSSheldon Hearn.Em g , 986e918fc8fSSheldon Hearnreferences to the variable 987dfe302abSRuslan Ermilov.Va x 988e918fc8fSSheldon Hearnmade inside 989e918fc8fSSheldon Hearn.Em g 990e918fc8fSSheldon Hearnwill refer to the variable 991dfe302abSRuslan Ermilov.Va x 992e918fc8fSSheldon Hearndeclared inside 993e918fc8fSSheldon Hearn.Em f , 994e918fc8fSSheldon Hearnnot to the global variable named 995dfe302abSRuslan Ermilov.Va x . 996ab72124fSSteve Price.Pp 9976b4bbd8aSCeri DaviesThe only special parameter that can be made local is 998dfe302abSRuslan Ermilov.Ql - . 9996b15476eSSheldon HearnMaking 1000dfe302abSRuslan Ermilov.Ql - 10016b15476eSSheldon Hearnlocal causes any shell options that are 1002dfe302abSRuslan Ermilovchanged via the 1003dfe302abSRuslan Ermilov.Ic set 1004dfe302abSRuslan Ermilovcommand inside the function to be 10054b88c807SRodney W. Grimesrestored to their original values when the function 10064b88c807SRodney W. Grimesreturns. 1007ab72124fSSteve Price.Pp 100849e11e3aSSheldon HearnThe syntax of the 100949e11e3aSSheldon Hearn.Ic return 101049e11e3aSSheldon Hearncommand is 1011dfe302abSRuslan Ermilov.Pp 1012dfe302abSRuslan Ermilov.D1 Ic return Op Ar exitstatus 1013ab72124fSSteve Price.Pp 10144ad8968aSBrian FeldmanIt terminates the current executional scope, returning from the previous 10154ad8968aSBrian Feldmannested function, sourced script, or shell instance, in that order. 101649e11e3aSSheldon HearnThe 101749e11e3aSSheldon Hearn.Ic return 101830268dfaSJilles Tjoelkercommand is implemented as a special built-in command. 1019ab72124fSSteve Price.Ss Variables and Parameters 1020eccea571SRuslan ErmilovThe shell maintains a set of parameters. 1021eccea571SRuslan ErmilovA parameter 1022eccea571SRuslan Ermilovdenoted by a name is called a variable. 1023eccea571SRuslan ErmilovWhen starting up, 10244b88c807SRodney W. Grimesthe shell turns all the environment variables into shell 1025eccea571SRuslan Ermilovvariables. 1026eccea571SRuslan ErmilovNew variables can be set using the form 1027dfe302abSRuslan Ermilov.Pp 1028dfe302abSRuslan Ermilov.D1 Ar name Ns = Ns Ar value 1029ab72124fSSteve Price.Pp 10304b88c807SRodney W. GrimesVariables set by the user must have a name consisting solely 103149e11e3aSSheldon Hearnof alphabetics, numerics, and underscores. 103249e11e3aSSheldon HearnThe first letter of a variable name must not be numeric. 103349e11e3aSSheldon HearnA parameter can also be denoted by a number 10344b88c807SRodney W. Grimesor a special character as explained below. 1035ab72124fSSteve Price.Ss Positional Parameters 103649e11e3aSSheldon HearnA positional parameter is a parameter denoted by a number greater than zero. 1037ab72124fSSteve PriceThe shell sets these initially to the values of its command line 1038eccea571SRuslan Ermilovarguments that follow the name of the shell script. 1039eccea571SRuslan ErmilovThe 1040c644db6aSSheldon Hearn.Ic set 10418eed22b1SJens Schweikhardtbuilt-in command can also be used to set or reset them. 1042ab72124fSSteve Price.Ss Special Parameters 104343d6677bSAlfred PerlsteinA special parameter is a parameter denoted by a special one-character 104443d6677bSAlfred Perlsteinname. 104543d6677bSAlfred PerlsteinThe special parameters recognized by the 104643d6677bSAlfred Perlstein.Nm 104743d6677bSAlfred Perlsteinshell of 104843d6677bSAlfred Perlstein.Fx 104943d6677bSAlfred Perlsteinare shown in the following list, exactly as they would appear in input 105043d6677bSAlfred Perlsteintyped by the user or in the source of a shell script. 1051ab72124fSSteve Price.Bl -hang 105243d6677bSAlfred Perlstein.It Li $* 1053eccea571SRuslan ErmilovExpands to the positional parameters, starting from one. 1054eccea571SRuslan ErmilovWhen 10554b88c807SRodney W. Grimesthe expansion occurs within a double-quoted string 10564b88c807SRodney W. Grimesit expands to a single field with the value of each parameter 105749e11e3aSSheldon Hearnseparated by the first character of the 1058dfe302abSRuslan Ermilov.Va IFS 105949e11e3aSSheldon Hearnvariable, 1060dfe302abSRuslan Ermilovor by a space if 1061dfe302abSRuslan Ermilov.Va IFS 106249e11e3aSSheldon Hearnis unset. 106343d6677bSAlfred Perlstein.It Li $@ 1064eccea571SRuslan ErmilovExpands to the positional parameters, starting from one. 1065eccea571SRuslan ErmilovWhen 10664b88c807SRodney W. Grimesthe expansion occurs within double-quotes, each positional 10674b88c807SRodney W. Grimesparameter expands as a separate argument. 10684b88c807SRodney W. GrimesIf there are no positional parameters, the 1069e918fc8fSSheldon Hearnexpansion of 1070e918fc8fSSheldon Hearn.Li @ 1071e918fc8fSSheldon Hearngenerates zero arguments, even when 1072e918fc8fSSheldon Hearn.Li @ 1073eccea571SRuslan Ermilovis double-quoted. 1074eccea571SRuslan ErmilovWhat this basically means, for example, is 1075dfe302abSRuslan Ermilovif 1076dfe302abSRuslan Ermilov.Li $1 1077dfe302abSRuslan Ermilovis 1078dfe302abSRuslan Ermilov.Dq Li abc 1079dfe302abSRuslan Ermilovand 1080dfe302abSRuslan Ermilov.Li $2 1081dfe302abSRuslan Ermilovis 1082dfe302abSRuslan Ermilov.Dq Li "def ghi" , 10836b15476eSSheldon Hearnthen 1084776e6b33SJilles Tjoelker.Li \&"$@\&" 10856b15476eSSheldon Hearnexpands to 10864b88c807SRodney W. Grimesthe two arguments: 1087ab72124fSSteve Price.Bd -literal -offset indent 10884b88c807SRodney W. Grimes"abc" "def ghi" 1089ab72124fSSteve Price.Ed 109043d6677bSAlfred Perlstein.It Li $# 10914b88c807SRodney W. GrimesExpands to the number of positional parameters. 1092dfe302abSRuslan Ermilov.It Li $? 10934b88c807SRodney W. GrimesExpands to the exit status of the most recent pipeline. 109443d6677bSAlfred Perlstein.It Li $- 1095ab72124fSSteve Price(hyphen) Expands to the current option flags (the single-letter 10964b88c807SRodney W. Grimesoption names concatenated into a string) as specified on 1097dfe302abSRuslan Ermilovinvocation, by the 1098dfe302abSRuslan Ermilov.Ic set 1099dfe302abSRuslan Ermilovbuilt-in command, or implicitly 11004b88c807SRodney W. Grimesby the shell. 110143d6677bSAlfred Perlstein.It Li $$ 1102eccea571SRuslan ErmilovExpands to the process ID of the invoked shell. 1103eccea571SRuslan ErmilovA subshell 1104dfe302abSRuslan Ermilovretains the same value of 1105dfe302abSRuslan Ermilov.Va $ 1106dfe302abSRuslan Ermilovas its parent. 1107dfe302abSRuslan Ermilov.It Li $! 11084b88c807SRodney W. GrimesExpands to the process ID of the most recent background 1109eccea571SRuslan Ermilovcommand executed from the current shell. 1110eccea571SRuslan ErmilovFor a 11114b88c807SRodney W. Grimespipeline, the process ID is that of the last command in the 11124b88c807SRodney W. Grimespipeline. 111343d6677bSAlfred Perlstein.It Li $0 1114ab72124fSSteve Price(zero) Expands to the name of the shell or shell script. 1115ab72124fSSteve Price.El 1116ab72124fSSteve Price.Ss Word Expansions 11174b88c807SRodney W. GrimesThis clause describes the various expansions that are 1118eccea571SRuslan Ermilovperformed on words. 1119eccea571SRuslan ErmilovNot all expansions are performed on 11204b88c807SRodney W. Grimesevery word, as explained later. 1121ab72124fSSteve Price.Pp 11224b88c807SRodney W. GrimesTilde expansions, parameter expansions, command substitutions, 11234b88c807SRodney W. Grimesarithmetic expansions, and quote removals that occur within 1124eccea571SRuslan Ermilova single word expand to a single field. 1125eccea571SRuslan ErmilovIt is only field 11264b88c807SRodney W. Grimessplitting or pathname expansion that can create multiple 1127e6d3cf26SSheldon Hearnfields from a single word. 1128e6d3cf26SSheldon HearnThe single exception to this rule is 1129e918fc8fSSheldon Hearnthe expansion of the special parameter 1130dfe302abSRuslan Ermilov.Va @ 1131e918fc8fSSheldon Hearnwithin double-quotes, 1132e6d3cf26SSheldon Hearnas was described above. 1133ab72124fSSteve Price.Pp 11344b88c807SRodney W. GrimesThe order of word expansion is: 1135ab72124fSSteve Price.Bl -enum 1136ab72124fSSteve Price.It 1137ab72124fSSteve PriceTilde Expansion, Parameter Expansion, Command Substitution, 11384b88c807SRodney W. GrimesArithmetic Expansion (these all occur at the same time). 1139ab72124fSSteve Price.It 114049e11e3aSSheldon HearnField Splitting is performed on fields generated by step (1) 114149e11e3aSSheldon Hearnunless the 1142dfe302abSRuslan Ermilov.Va IFS 114349e11e3aSSheldon Hearnvariable is null. 1144ab72124fSSteve Price.It 114549e11e3aSSheldon HearnPathname Expansion (unless the 114649e11e3aSSheldon Hearn.Fl f 114749e11e3aSSheldon Hearnoption is in effect). 1148ab72124fSSteve Price.It 1149ab72124fSSteve PriceQuote Removal. 1150ab72124fSSteve Price.El 1151ab72124fSSteve Price.Pp 115249e11e3aSSheldon HearnThe 1153dfe302abSRuslan Ermilov.Ql $ 115449e11e3aSSheldon Hearncharacter is used to introduce parameter expansion, command 11554b88c807SRodney W. Grimessubstitution, or arithmetic evaluation. 1156ab72124fSSteve Price.Ss Tilde Expansion (substituting a user's home directory) 115749e11e3aSSheldon HearnA word beginning with an unquoted tilde character 1158a762afe5SGiorgos Keramidas.Pq Ql ~ 115949e11e3aSSheldon Hearnis 116049e11e3aSSheldon Hearnsubjected to tilde expansion. 116149e11e3aSSheldon HearnAll the characters up to a slash 1162a762afe5SGiorgos Keramidas.Pq Ql / 116349e11e3aSSheldon Hearnor the end of the word are treated as a username 1164eccea571SRuslan Ermilovand are replaced with the user's home directory. 1165eccea571SRuslan ErmilovIf the 1166dfe302abSRuslan Ermilovusername is missing (as in 1167dfe302abSRuslan Ermilov.Pa ~/foobar ) , 1168dfe302abSRuslan Ermilovthe tilde is replaced with the value of the 1169dfe302abSRuslan Ermilov.Ev HOME 1170dfe302abSRuslan Ermilovvariable (the current user's home directory). 1171ab72124fSSteve Price.Ss Parameter Expansion 11724b88c807SRodney W. GrimesThe format for parameter expansion is as follows: 1173ab72124fSSteve Price.Pp 1174dfe302abSRuslan Ermilov.D1 Li ${ Ns Ar expression Ns Li } 1175dfe302abSRuslan Ermilov.Pp 1176dfe302abSRuslan Ermilovwhere 1177dfe302abSRuslan Ermilov.Ar expression 1178dfe302abSRuslan Ermilovconsists of all characters until the matching 1179dfe302abSRuslan Ermilov.Ql } . 118049e11e3aSSheldon HearnAny 1181dfe302abSRuslan Ermilov.Ql } 1182227c8e2aSJilles Tjoelkerescaped by a backslash or within a single-quoted string, and characters in 11834b88c807SRodney W. Grimesembedded arithmetic expansions, command substitutions, and variable 118449e11e3aSSheldon Hearnexpansions, are not examined in determining the matching 1185dfe302abSRuslan Ermilov.Ql } . 1186227c8e2aSJilles TjoelkerExcept for the variants with 1187227c8e2aSJilles Tjoelker.Ql + , 1188227c8e2aSJilles Tjoelker.Ql - , 1189227c8e2aSJilles Tjoelker.Ql = 1190227c8e2aSJilles Tjoelkeror 1191227c8e2aSJilles Tjoelker.Ql ?\& , 1192227c8e2aSJilles Tjoelkerany 1193227c8e2aSJilles Tjoelker.Ql } 1194227c8e2aSJilles Tjoelkerwithin a double-quoted string is also not examined in determining the matching 1195227c8e2aSJilles Tjoelker.Ql } . 1196ab72124fSSteve Price.Pp 11974b88c807SRodney W. GrimesThe simplest form for parameter expansion is: 1198ab72124fSSteve Price.Pp 1199dfe302abSRuslan Ermilov.D1 Li ${ Ns Ar parameter Ns Li } 1200dfe302abSRuslan Ermilov.Pp 1201dfe302abSRuslan ErmilovThe value, if any, of 1202dfe302abSRuslan Ermilov.Ar parameter 1203dfe302abSRuslan Ermilovis substituted. 1204ab72124fSSteve Price.Pp 12054b88c807SRodney W. GrimesThe parameter name or symbol can be enclosed in braces, which are 12064b88c807SRodney W. Grimesoptional except for positional parameters with more than one digit or 12074b88c807SRodney W. Grimeswhen parameter is followed by a character that could be interpreted as 12084b88c807SRodney W. Grimespart of the name. 1209ab72124fSSteve PriceIf a parameter expansion occurs inside double-quotes: 1210ab72124fSSteve Price.Bl -enum 1211ab72124fSSteve Price.It 1212ab72124fSSteve PricePathname expansion is not performed on the results of the 12134b88c807SRodney W. Grimesexpansion. 1214ab72124fSSteve Price.It 1215ab72124fSSteve PriceField splitting is not performed on the results of the 1216e918fc8fSSheldon Hearnexpansion, with the exception of the special parameter 1217dfe302abSRuslan Ermilov.Va @ . 1218ab72124fSSteve Price.El 1219ab72124fSSteve Price.Pp 12204b88c807SRodney W. GrimesIn addition, a parameter expansion can be modified by using one of the 12214b88c807SRodney W. Grimesfollowing formats. 122281e9cda2SRuslan Ermilov.Bl -tag -width indent 1223dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li :- Ns Ar word Ns Li } 1224eccea571SRuslan ErmilovUse Default Values. 1225dfe302abSRuslan ErmilovIf 1226dfe302abSRuslan Ermilov.Ar parameter 1227dfe302abSRuslan Ermilovis unset or null, the expansion of 1228dfe302abSRuslan Ermilov.Ar word 1229dfe302abSRuslan Ermilovis substituted; otherwise, the value of 1230dfe302abSRuslan Ermilov.Ar parameter 1231dfe302abSRuslan Ermilovis substituted. 1232dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li := Ns Ar word Ns Li } 1233eccea571SRuslan ErmilovAssign Default Values. 1234dfe302abSRuslan ErmilovIf 1235dfe302abSRuslan Ermilov.Ar parameter 1236dfe302abSRuslan Ermilovis unset or null, the expansion of 1237dfe302abSRuslan Ermilov.Ar word 1238dfe302abSRuslan Ermilovis assigned to 1239dfe302abSRuslan Ermilov.Ar parameter . 1240eccea571SRuslan ErmilovIn all cases, the 1241dfe302abSRuslan Ermilovfinal value of 1242dfe302abSRuslan Ermilov.Ar parameter 1243dfe302abSRuslan Ermilovis substituted. 1244b139165cSJilles TjoelkerQuoting inside 1245b139165cSJilles Tjoelker.Ar word 1246b139165cSJilles Tjoelkerdoes not prevent field splitting or pathname expansion. 1247eccea571SRuslan ErmilovOnly variables, not positional 12484b88c807SRodney W. Grimesparameters or special parameters, can be 12494b88c807SRodney W. Grimesassigned in this way. 1250dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li :? Ns Oo Ar word Oc Ns Li } 1251eccea571SRuslan ErmilovIndicate Error if Null or Unset. 1252eccea571SRuslan ErmilovIf 1253dfe302abSRuslan Ermilov.Ar parameter 1254dfe302abSRuslan Ermilovis unset or null, the expansion of 1255dfe302abSRuslan Ermilov.Ar word 1256dfe302abSRuslan Ermilov(or a message indicating it is unset if 1257dfe302abSRuslan Ermilov.Ar word 1258dfe302abSRuslan Ermilovis omitted) is written to standard 12594b88c807SRodney W. Grimeserror and the shell exits with a nonzero 1260e6d3cf26SSheldon Hearnexit status. 1261e6d3cf26SSheldon HearnOtherwise, the value of 1262dfe302abSRuslan Ermilov.Ar parameter 1263dfe302abSRuslan Ermilovis substituted. 1264eccea571SRuslan ErmilovAn 12654b88c807SRodney W. Grimesinteractive shell need not exit. 1266dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li :+ Ns Ar word Ns Li } 1267eccea571SRuslan ErmilovUse Alternate Value. 1268dfe302abSRuslan ErmilovIf 1269dfe302abSRuslan Ermilov.Ar parameter 1270dfe302abSRuslan Ermilovis unset or null, null is substituted; 1271dfe302abSRuslan Ermilovotherwise, the expansion of 1272dfe302abSRuslan Ermilov.Ar word 1273dfe302abSRuslan Ermilovis substituted. 12741413f7deSTony Finch.El 1275ab72124fSSteve Price.Pp 12764b88c807SRodney W. GrimesIn the parameter expansions shown previously, use of the colon in the 12774b88c807SRodney W. Grimesformat results in a test for a parameter that is unset or null; omission 12784b88c807SRodney W. Grimesof the colon results in a test for a parameter that is only unset. 1279227c8e2aSJilles Tjoelker.Pp 1280227c8e2aSJilles TjoelkerThe 1281227c8e2aSJilles Tjoelker.Ar word 1282227c8e2aSJilles Tjoelkerinherits the type of quoting 1283227c8e2aSJilles Tjoelker(unquoted, double-quoted or here-document) 1284227c8e2aSJilles Tjoelkerfrom the surroundings, 1285227c8e2aSJilles Tjoelkerwith the exception that a backslash that quotes a closing brace is removed 1286227c8e2aSJilles Tjoelkerduring quote removal. 12871413f7deSTony Finch.Bl -tag -width indent 1288dfe302abSRuslan Ermilov.It Li ${# Ns Ar parameter Ns Li } 1289eccea571SRuslan ErmilovString Length. 1290eccea571SRuslan ErmilovThe length in characters of 1291dfe302abSRuslan Ermilovthe value of 1292dfe302abSRuslan Ermilov.Ar parameter . 129371337c33SSheldon Hearn.El 1294ab72124fSSteve Price.Pp 12954b88c807SRodney W. GrimesThe following four varieties of parameter expansion provide for substring 129649e11e3aSSheldon Hearnprocessing. 129749e11e3aSSheldon HearnIn each case, pattern matching notation 129849e11e3aSSheldon Hearn(see 129949e11e3aSSheldon Hearn.Sx Shell Patterns ) , 130049e11e3aSSheldon Hearnrather than regular expression notation, 130149e11e3aSSheldon Hearnis used to evaluate the patterns. 1302e918fc8fSSheldon HearnIf parameter is one of the special parameters 1303dfe302abSRuslan Ermilov.Va * 130449e11e3aSSheldon Hearnor 1305dfe302abSRuslan Ermilov.Va @ , 130649e11e3aSSheldon Hearnthe result of the expansion is unspecified. 13074b88c807SRodney W. GrimesEnclosing the full parameter expansion string in double-quotes does not 13084b88c807SRodney W. Grimescause the following four varieties of pattern characters to be quoted, 13094b88c807SRodney W. Grimeswhereas quoting characters within the braces has this effect. 131081e9cda2SRuslan Ermilov.Bl -tag -width indent 1311dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li % Ns Ar word Ns Li } 1312eccea571SRuslan ErmilovRemove Smallest Suffix Pattern. 1313dfe302abSRuslan ErmilovThe 1314dfe302abSRuslan Ermilov.Ar word 1315eccea571SRuslan Ermilovis expanded to produce a pattern. 1316eccea571SRuslan ErmilovThe 13174b88c807SRodney W. Grimesparameter expansion then results in 1318dfe302abSRuslan Ermilov.Ar parameter , 1319dfe302abSRuslan Ermilovwith the smallest portion of the 13204b88c807SRodney W. Grimessuffix matched by the pattern deleted. 1321dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li %% Ns Ar word Ns Li } 1322eccea571SRuslan ErmilovRemove Largest Suffix Pattern. 1323dfe302abSRuslan ErmilovThe 1324dfe302abSRuslan Ermilov.Ar word 1325eccea571SRuslan Ermilovis expanded to produce a pattern. 1326eccea571SRuslan ErmilovThe 13274b88c807SRodney W. Grimesparameter expansion then results in 1328dfe302abSRuslan Ermilov.Ar parameter , 1329dfe302abSRuslan Ermilovwith the largest portion of the 13304b88c807SRodney W. Grimessuffix matched by the pattern deleted. 1331dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li # Ns Ar word Ns Li } 1332eccea571SRuslan ErmilovRemove Smallest Prefix Pattern. 1333dfe302abSRuslan ErmilovThe 1334dfe302abSRuslan Ermilov.Ar word 1335eccea571SRuslan Ermilovis expanded to produce a pattern. 1336eccea571SRuslan ErmilovThe 13374b88c807SRodney W. Grimesparameter expansion then results in 1338dfe302abSRuslan Ermilov.Ar parameter , 1339dfe302abSRuslan Ermilovwith the smallest portion of the 13404b88c807SRodney W. Grimesprefix matched by the pattern deleted. 1341dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li ## Ns Ar word Ns Li } 1342eccea571SRuslan ErmilovRemove Largest Prefix Pattern. 1343dfe302abSRuslan ErmilovThe 1344dfe302abSRuslan Ermilov.Ar word 1345eccea571SRuslan Ermilovis expanded to produce a pattern. 1346eccea571SRuslan ErmilovThe 13474b88c807SRodney W. Grimesparameter expansion then results in 1348dfe302abSRuslan Ermilov.Ar parameter , 1349dfe302abSRuslan Ermilovwith the largest portion of the 13504b88c807SRodney W. Grimesprefix matched by the pattern deleted. 1351ab72124fSSteve Price.El 1352ab72124fSSteve Price.Ss Command Substitution 13534b88c807SRodney W. GrimesCommand substitution allows the output of a command to be substituted in 1354eccea571SRuslan Ermilovplace of the command name itself. 1355eccea571SRuslan ErmilovCommand substitution occurs when 13564b88c807SRodney W. Grimesthe command is enclosed as follows: 1357dfe302abSRuslan Ermilov.Pp 1358dfe302abSRuslan Ermilov.D1 Li $( Ns Ar command Ns Li )\& 1359ab72124fSSteve Price.Pp 136049e11e3aSSheldon Hearnor the backquoted version: 1361dfe302abSRuslan Ermilov.Pp 1362dfe302abSRuslan Ermilov.D1 Li ` Ns Ar command Ns Li ` 1363ab72124fSSteve Price.Pp 13644b88c807SRodney W. GrimesThe shell expands the command substitution by executing command in a 13654b88c807SRodney W. Grimessubshell environment and replacing the command substitution 136649e11e3aSSheldon Hearnwith the standard output of the command, 136749e11e3aSSheldon Hearnremoving sequences of one or more newlines at the end of the substitution. 136849e11e3aSSheldon HearnEmbedded newlines before the end of the output are not removed; 136949e11e3aSSheldon Hearnhowever, during field splitting, they may be translated into spaces 137049e11e3aSSheldon Hearndepending on the value of 1371dfe302abSRuslan Ermilov.Va IFS 137249e11e3aSSheldon Hearnand the quoting that is in effect. 1373ab72124fSSteve Price.Ss Arithmetic Expansion 13744b88c807SRodney W. GrimesArithmetic expansion provides a mechanism for evaluating an arithmetic 1375e6d3cf26SSheldon Hearnexpression and substituting its value. 1376e6d3cf26SSheldon HearnThe format for arithmetic expansion is as follows: 1377ab72124fSSteve Price.Pp 1378dfe302abSRuslan Ermilov.D1 Li $(( Ns Ar expression Ns Li )) 1379dfe302abSRuslan Ermilov.Pp 1380dfe302abSRuslan ErmilovThe 1381dfe302abSRuslan Ermilov.Ar expression 1382dfe302abSRuslan Ermilovis treated as if it were in double-quotes, except 1383eccea571SRuslan Ermilovthat a double-quote inside the expression is not treated specially. 1384eccea571SRuslan ErmilovThe 1385dfe302abSRuslan Ermilovshell expands all tokens in the 1386dfe302abSRuslan Ermilov.Ar expression 1387dfe302abSRuslan Ermilovfor parameter expansion, 13884b88c807SRodney W. Grimescommand substitution, and quote removal. 1389ab72124fSSteve Price.Pp 13904b88c807SRodney W. GrimesNext, the shell treats this as an arithmetic expression and 13914b88c807SRodney W. Grimessubstitutes the value of the expression. 1392ab72124fSSteve Price.Ss White Space Splitting (Field Splitting) 13934b88c807SRodney W. GrimesAfter parameter expansion, command substitution, and 13944b88c807SRodney W. Grimesarithmetic expansion the shell scans the results of 13954b88c807SRodney W. Grimesexpansions and substitutions that did not occur in double-quotes for 13964b88c807SRodney W. Grimesfield splitting and multiple fields can result. 1397ab72124fSSteve Price.Pp 139849e11e3aSSheldon HearnThe shell treats each character of the 1399dfe302abSRuslan Ermilov.Va IFS 1400dfe302abSRuslan Ermilovvariable as a delimiter and uses 14014b88c807SRodney W. Grimesthe delimiters to split the results of parameter expansion and command 14024b88c807SRodney W. Grimessubstitution into fields. 1403ab72124fSSteve Price.Ss Pathname Expansion (File Name Generation) 140449e11e3aSSheldon HearnUnless the 140549e11e3aSSheldon Hearn.Fl f 140649e11e3aSSheldon Hearnoption is set, 140749e11e3aSSheldon Hearnfile name generation is performed 1408eccea571SRuslan Ermilovafter word splitting is complete. 1409eccea571SRuslan ErmilovEach word is 1410eccea571SRuslan Ermilovviewed as a series of patterns, separated by slashes. 1411eccea571SRuslan ErmilovThe 14124b88c807SRodney W. Grimesprocess of expansion replaces the word with the names of 14134b88c807SRodney W. Grimesall existing files whose names can be formed by replacing 14144b88c807SRodney W. Grimeseach pattern with a string that matches the specified pattern. 1415ab0a2172SSteve PriceThere are two restrictions on this: first, a pattern cannot match 1416ab0a2172SSteve Pricea string containing a slash, and second, 14174b88c807SRodney W. Grimesa pattern cannot match a string starting with a period 14184b88c807SRodney W. Grimesunless the first character of the pattern is a period. 14194b88c807SRodney W. GrimesThe next section describes the patterns used for both 1420ab72124fSSteve PricePathname Expansion and the 1421c644db6aSSheldon Hearn.Ic case 1422ab72124fSSteve Pricecommand. 1423ab72124fSSteve Price.Ss Shell Patterns 1424f434d1dfSAdam DavidA pattern consists of normal characters, which match themselves, 142549e11e3aSSheldon Hearnand meta-characters. 142649e11e3aSSheldon HearnThe meta-characters are 1427dfe302abSRuslan Ermilov.Ql \&! , 1428dfe302abSRuslan Ermilov.Ql * , 1429dfe302abSRuslan Ermilov.Ql \&? , 14306b15476eSSheldon Hearnand 1431dfe302abSRuslan Ermilov.Ql \&[ . 14326b15476eSSheldon HearnThese characters lose their special meanings if they are quoted. 14336b15476eSSheldon HearnWhen command or variable substitution is performed and the dollar sign 14346b15476eSSheldon Hearnor back quotes are not double-quoted, the value of the 14354b88c807SRodney W. Grimesvariable or the output of the command is scanned for these 14364b88c807SRodney W. Grimescharacters and they are turned into meta-characters. 1437ab72124fSSteve Price.Pp 14386b15476eSSheldon HearnAn asterisk 1439a762afe5SGiorgos Keramidas.Pq Ql * 1440e918fc8fSSheldon Hearnmatches any string of characters. 1441e918fc8fSSheldon HearnA question mark 1442a762afe5SGiorgos Keramidas.Pq Ql \&? 1443e918fc8fSSheldon Hearnmatches any single character. 1444e6d3cf26SSheldon HearnA left bracket 1445dfe302abSRuslan Ermilov.Pq Ql \&[ 1446e6d3cf26SSheldon Hearnintroduces a character class. 1447e6d3cf26SSheldon HearnThe end of the character class is indicated by a 1448dfe302abSRuslan Ermilov.Ql \&] ; 14496b15476eSSheldon Hearnif the 1450dfe302abSRuslan Ermilov.Ql \&] 14516b15476eSSheldon Hearnis missing then the 1452dfe302abSRuslan Ermilov.Ql \&[ 14536b15476eSSheldon Hearnmatches a 1454dfe302abSRuslan Ermilov.Ql \&[ 1455e6d3cf26SSheldon Hearnrather than introducing a character class. 1456e6d3cf26SSheldon HearnA character class matches any of the characters between the square brackets. 1457e6d3cf26SSheldon HearnA range of characters may be specified using a minus sign. 1458e918fc8fSSheldon HearnThe character class may be complemented by making an exclamation point 1459a762afe5SGiorgos Keramidas.Pq Ql !\& 1460e918fc8fSSheldon Hearnthe first character of the character class. 1461ab72124fSSteve Price.Pp 14626b15476eSSheldon HearnTo include a 1463dfe302abSRuslan Ermilov.Ql \&] 1464e6d3cf26SSheldon Hearnin a character class, make it the first character listed 1465e6d3cf26SSheldon Hearn(after the 1466dfe302abSRuslan Ermilov.Ql \&! , 1467e6d3cf26SSheldon Hearnif any). 1468e918fc8fSSheldon HearnTo include a 1469dfe302abSRuslan Ermilov.Ql - , 1470e918fc8fSSheldon Hearnmake it the first or last character listed. 14718eed22b1SJens Schweikhardt.Ss Built-in Commands 1472c644db6aSSheldon HearnThis section lists the commands which 14738eed22b1SJens Schweikhardtare built-in because they need to perform some operation 1474eccea571SRuslan Ermilovthat cannot be performed by a separate process. 1475eccea571SRuslan ErmilovIn addition to 147610845922SYaroslav Tykhiythese, built-in versions of essential utilities 147710845922SYaroslav Tykhiyare provided for efficiency. 147881e9cda2SRuslan Ermilov.Bl -tag -width indent 1479d0353b83SRuslan Ermilov.It Ic \&: 1480aa9caaf6SPeter WemmA null command that returns a 0 (true) exit value. 1481d0353b83SRuslan Ermilov.It Ic \&. Ar file 1482aa9caaf6SPeter WemmThe commands in the specified file are read and executed by the shell. 14834ad8968aSBrian FeldmanThe 14844ad8968aSBrian Feldman.Ic return 14854ad8968aSBrian Feldmancommand may be used to return to the 14864ad8968aSBrian Feldman.Ic \&. 14874ad8968aSBrian Feldmancommand's caller. 14886466945aSJohn PolstraIf 14896466945aSJohn Polstra.Ar file 14906466945aSJohn Polstracontains any 1491dfe302abSRuslan Ermilov.Ql / 1492eccea571SRuslan Ermilovcharacters, it is used as is. 1493eccea571SRuslan ErmilovOtherwise, the shell searches the 14946466945aSJohn Polstra.Ev PATH 1495eccea571SRuslan Ermilovfor the file. 1496eccea571SRuslan ErmilovIf it is not found in the 14976466945aSJohn Polstra.Ev PATH , 14986466945aSJohn Polstrait is sought in the current working directory. 149910845922SYaroslav Tykhiy.It Ic \&[ 150010845922SYaroslav TykhiyA built-in equivalent of 150110845922SYaroslav Tykhiy.Xr test 1 . 1502a886288eSJesus R. Camou.It Ic alias Oo Ar name Ns Oo = Ns Ar string Oc ... Oc 150349e11e3aSSheldon HearnIf 1504d0353b83SRuslan Ermilov.Ar name Ns = Ns Ar string 150549e11e3aSSheldon Hearnis specified, the shell defines the alias 150649e11e3aSSheldon Hearn.Ar name 15076b15476eSSheldon Hearnwith value 150849e11e3aSSheldon Hearn.Ar string . 15096b15476eSSheldon HearnIf just 151049e11e3aSSheldon Hearn.Ar name 15116b15476eSSheldon Hearnis specified, the value of the alias 151249e11e3aSSheldon Hearn.Ar name 15136b15476eSSheldon Hearnis printed. 151449e11e3aSSheldon HearnWith no arguments, the 151549e11e3aSSheldon Hearn.Ic alias 15168eed22b1SJens Schweikhardtbuilt-in command prints the names and values of all defined aliases 151749e11e3aSSheldon Hearn(see 151849e11e3aSSheldon Hearn.Ic unalias ) . 1519e5341cbbSTim J. RobbinsAlias values are written with appropriate quoting so that they are 15209ba31ca0SRuslan Ermilovsuitable for re-input to the shell. 1521a886288eSJesus R. CamouAlso see the 1522a886288eSJesus R. Camou.Sx Aliases 1523a886288eSJesus R. Camousubsection. 152449e11e3aSSheldon Hearn.It Ic bg Op Ar job ... 152549e11e3aSSheldon HearnContinue the specified jobs 152649e11e3aSSheldon Hearn(or the current job if no jobs are given) 152749e11e3aSSheldon Hearnin the background. 1528df9e587bSTim J. Robbins.It Ic builtin Ar cmd Op Ar arg ... 15298eed22b1SJens SchweikhardtExecute the specified built-in command, 153049e11e3aSSheldon Hearn.Ar cmd . 153149e11e3aSSheldon HearnThis is useful when the user wishes to override a shell function 15328eed22b1SJens Schweikhardtwith the same name as a built-in command. 1533088acf90STim J. Robbins.It Ic bind Oo Fl aeklrsv Oc Oo Ar key Oo Ar command Oc Oc 1534088acf90STim J. RobbinsList or alter key bindings for the line editor. 1535088acf90STim J. RobbinsThis command is documented in 1536088acf90STim J. Robbins.Xr editrc 5 . 1537d74e011fSRuslan Ermilov.It Ic cd Oo Fl L | P Oc Op Ar directory 153849e11e3aSSheldon HearnSwitch to the specified 153949e11e3aSSheldon Hearn.Ar directory , 154049e11e3aSSheldon Hearnor to the directory specified in the 154149e11e3aSSheldon Hearn.Ev HOME 154249e11e3aSSheldon Hearnenvironment variable if no 154349e11e3aSSheldon Hearn.Ar directory 154449e11e3aSSheldon Hearnis specified. 154549e11e3aSSheldon HearnIf 154649e11e3aSSheldon Hearn.Ar directory 1547029c8ee4STim J. Robbinsdoes not begin with 15489ba31ca0SRuslan Ermilov.Pa / , \&. , 154949e11e3aSSheldon Hearnor 1550029c8ee4STim J. Robbins.Pa .. , 155149e11e3aSSheldon Hearnthen the directories listed in the 155249e11e3aSSheldon Hearn.Ev CDPATH 155349e11e3aSSheldon Hearnvariable will be 155449e11e3aSSheldon Hearnsearched for the specified 155549e11e3aSSheldon Hearn.Ar directory . 1556029c8ee4STim J. RobbinsIf 1557029c8ee4STim J. Robbins.Ev CDPATH 1558029c8ee4STim J. Robbinsis unset, the current directory is searched. 155949e11e3aSSheldon HearnThe format of 1560dfe302abSRuslan Ermilov.Ev CDPATH 156149e11e3aSSheldon Hearnis the same as that of 156249e11e3aSSheldon Hearn.Ev PATH . 1563e6d3cf26SSheldon HearnIn an interactive shell, 156449e11e3aSSheldon Hearnthe 156549e11e3aSSheldon Hearn.Ic cd 156649e11e3aSSheldon Hearncommand will print out the name of the directory 1567e6d3cf26SSheldon Hearnthat it actually switched to 1568e6d3cf26SSheldon Hearnif this is different from the name that the user gave. 156949e11e3aSSheldon HearnThese may be different either because the 157049e11e3aSSheldon Hearn.Ev CDPATH 157149e11e3aSSheldon Hearnmechanism was used or because a symbolic link was crossed. 1572178897f1STim J. Robbins.Pp 1573178897f1STim J. RobbinsIf the 1574178897f1STim J. Robbins.Fl P 1575178897f1STim J. Robbinsoption is specified, 157681e9cda2SRuslan Ermilov.Pa .. 1577178897f1STim J. Robbinsis handled physically and symbolic links are resolved before 157881e9cda2SRuslan Ermilov.Pa .. 1579178897f1STim J. Robbinscomponents are processed. 1580178897f1STim J. RobbinsIf the 1581178897f1STim J. Robbins.Fl L 1582178897f1STim J. Robbinsoption is specified, 158381e9cda2SRuslan Ermilov.Pa .. 1584178897f1STim J. Robbinsis handled logically. 1585178897f1STim J. RobbinsThis is the default. 15869434a1c7SDima Dorfman.It Ic chdir 15879434a1c7SDima DorfmanA synonym for the 15889434a1c7SDima Dorfman.Ic cd 15898eed22b1SJens Schweikhardtbuilt-in command. 15909ba31ca0SRuslan Ermilov.It Ic command Oo Fl p Oc Op Ar utility Op Ar argument ... 159133b222b9SStefan Farfeleder.It Ic command Oo Fl v | V Oc Op Ar utility 159233b222b9SStefan FarfelederThe first form of invocation executes the specified 1593c848bc18SJilles Tjoelker.Ar utility , 1594c848bc18SJilles Tjoelkerignoring shell functions in the search. 1595c848bc18SJilles TjoelkerIf 15962babaf74STim J. Robbins.Ar utility 1597c848bc18SJilles Tjoelkeris a special builtin, 1598c848bc18SJilles Tjoelkerit is executed as if it were a regular builtin. 15992babaf74STim J. Robbins.Pp 16002babaf74STim J. RobbinsIf the 16012babaf74STim J. Robbins.Fl p 16022babaf74STim J. Robbinsoption is specified, the command search is performed using a 16032babaf74STim J. Robbinsdefault value of 16042babaf74STim J. Robbins.Ev PATH 16052babaf74STim J. Robbinsthat is guaranteed to find all of the standard utilities. 160633b222b9SStefan Farfeleder.Pp 160733b222b9SStefan FarfelederIf the 160833b222b9SStefan Farfeleder.Fl v 160933b222b9SStefan Farfelederoption is specified, 161033b222b9SStefan Farfeleder.Ar utility 161133b222b9SStefan Farfelederis not executed but a description of its interpretation by the shell is 161233b222b9SStefan Farfelederprinted. 161333b222b9SStefan FarfelederFor ordinary commands the output is the path name; for shell built-in 161433b222b9SStefan Farfeledercommands, shell functions and keywords only the name is written. 161533b222b9SStefan FarfelederAliases are printed as 161633b222b9SStefan Farfeleder.Dq Ic alias Ar name Ns = Ns Ar value . 161733b222b9SStefan Farfeleder.Pp 161833b222b9SStefan FarfelederThe 161933b222b9SStefan Farfeleder.Fl V 162033b222b9SStefan Farfelederoption is identical to 162133b222b9SStefan Farfeleder.Fl v 162233b222b9SStefan Farfelederexcept for the output. 162333b222b9SStefan FarfelederIt prints 162433b222b9SStefan Farfeleder.Dq Ar utility Ic is Ar description 162533b222b9SStefan Farfelederwhere 162633b222b9SStefan Farfeleder.Ar description 162733b222b9SStefan Farfelederis either 162833b222b9SStefan Farfelederthe path name to 162933b222b9SStefan Farfeleder.Ar utility , 163030268dfaSJilles Tjoelkera special shell builtin, 16318af11131SRuslan Ermilova shell builtin, 16328af11131SRuslan Ermilova shell function, 16338af11131SRuslan Ermilova shell keyword 163433b222b9SStefan Farfelederor 16358af11131SRuslan Ermilovan alias for 16368af11131SRuslan Ermilov.Ar value . 163773313421SStefan Farfeleder.It Ic echo Oo Fl e | n Oc Op Ar string ... 163873313421SStefan FarfelederPrint a space-separated list of the arguments to the standard output 163973313421SStefan Farfelederand append a newline character. 164081e9cda2SRuslan Ermilov.Bl -tag -width indent 1641501e74b7SMark Ovens.It Fl n 1642501e74b7SMark OvensSuppress the output of the trailing newline. 1643501e74b7SMark Ovens.It Fl e 1644501e74b7SMark OvensProcess C-style backslash escape sequences. 1645dfe302abSRuslan ErmilovThe 1646501e74b7SMark Ovens.Ic echo 1647dfe302abSRuslan Ermilovcommand understands the following character escapes: 164881e9cda2SRuslan Ermilov.Bl -tag -width indent 1649501e74b7SMark Ovens.It \ea 1650501e74b7SMark OvensAlert (ring the terminal bell) 1651501e74b7SMark Ovens.It \eb 1652501e74b7SMark OvensBackspace 1653501e74b7SMark Ovens.It \ec 1654501e74b7SMark OvensSuppress the trailing newline (this has the side-effect of truncating the 1655501e74b7SMark Ovensline if it is not the last character) 1656501e74b7SMark Ovens.It \ee 1657dfe302abSRuslan ErmilovThe ESC character 1658dfe302abSRuslan Ermilov.Tn ( ASCII 1659dfe302abSRuslan Ermilov0x1b) 1660501e74b7SMark Ovens.It \ef 1661501e74b7SMark OvensFormfeed 1662501e74b7SMark Ovens.It \en 1663501e74b7SMark OvensNewline 1664501e74b7SMark Ovens.It \er 1665501e74b7SMark OvensCarriage return 1666501e74b7SMark Ovens.It \et 1667501e74b7SMark OvensHorizontal tab 1668501e74b7SMark Ovens.It \ev 1669501e74b7SMark OvensVertical tab 1670501e74b7SMark Ovens.It \e\e 1671501e74b7SMark OvensLiteral backslash 1672501e74b7SMark Ovens.It \e0nnn 1673dfe302abSRuslan Ermilov(Zero) The character whose octal value is 1674dfe302abSRuslan Ermilov.Ar nnn 1675501e74b7SMark Ovens.El 1676501e74b7SMark Ovens.Pp 1677501e74b7SMark OvensIf 1678501e74b7SMark Ovens.Ar string 1679501e74b7SMark Ovensis not enclosed in quotes then the backslash itself must be escaped 1680eccea571SRuslan Ermilovwith a backslash to protect it from the shell. 1681eccea571SRuslan ErmilovFor example 1682501e74b7SMark Ovens.Bd -literal -offset indent 1683501e74b7SMark Ovens$ echo -e "a\evb" 1684501e74b7SMark Ovensa 1685501e74b7SMark Ovens b 1686501e74b7SMark Ovens$ echo -e a\e\evb 1687501e74b7SMark Ovensa 1688501e74b7SMark Ovens b 1689501e74b7SMark Ovens$ echo -e "a\e\eb" 1690501e74b7SMark Ovensa\eb 1691501e74b7SMark Ovens$ echo -e a\e\e\e\eb 1692501e74b7SMark Ovensa\eb 1693501e74b7SMark Ovens.Ed 1694501e74b7SMark Ovens.El 1695558175caSTim J. Robbins.Pp 1696558175caSTim J. RobbinsOnly one of the 1697558175caSTim J. Robbins.Fl e 1698558175caSTim J. Robbinsand 1699558175caSTim J. Robbins.Fl n 1700558175caSTim J. Robbinsoptions may be specified. 170149e11e3aSSheldon Hearn.It Ic eval Ar string ... 1702e6d3cf26SSheldon HearnConcatenate all the arguments with spaces. 1703e6d3cf26SSheldon HearnThen re-parse and execute the command. 170449e11e3aSSheldon Hearn.It Ic exec Op Ar command Op arg ... 170549e11e3aSSheldon HearnUnless 170649e11e3aSSheldon Hearn.Ar command 170749e11e3aSSheldon Hearnis omitted, 170849e11e3aSSheldon Hearnthe shell process is replaced with the specified program 17098eed22b1SJens Schweikhardt(which must be a real program, not a shell built-in command or function). 171049e11e3aSSheldon HearnAny redirections on the 171149e11e3aSSheldon Hearn.Ic exec 171249e11e3aSSheldon Hearncommand are marked as permanent, 171349e11e3aSSheldon Hearnso that they are not undone when the 171449e11e3aSSheldon Hearn.Ic exec 171549e11e3aSSheldon Hearncommand finishes. 171649e11e3aSSheldon Hearn.It Ic exit Op Ar exitstatus 171749e11e3aSSheldon HearnTerminate the shell process. 171849e11e3aSSheldon HearnIf 171949e11e3aSSheldon Hearn.Ar exitstatus 172049e11e3aSSheldon Hearnis given 172149e11e3aSSheldon Hearnit is used as the exit status of the shell; 172249e11e3aSSheldon Hearnotherwise the exit status of the preceding command is used. 1723a68fbc44SJilles TjoelkerThe exit status should be an integer between 0 and 255. 1724ef9791a3SStefan Farfeleder.It Ic export Ar name ... 1725ef9791a3SStefan Farfeleder.It Ic export Op Fl p 17264b88c807SRodney W. GrimesThe specified names are exported so that they will 17274b88c807SRodney W. Grimesappear in the environment of subsequent commands. 172849e11e3aSSheldon HearnThe only way to un-export a variable is to 172949e11e3aSSheldon Hearn.Ic unset 173049e11e3aSSheldon Hearnit. 173149e11e3aSSheldon HearnThe shell allows the value of a variable to be set 173249e11e3aSSheldon Hearnat the same time as it is exported by writing 1733ab72124fSSteve Price.Pp 1734dfe302abSRuslan Ermilov.D1 Ic export Ar name Ns = Ns Ar value 1735dfe302abSRuslan Ermilov.Pp 1736dfe302abSRuslan ErmilovWith no arguments the 1737dfe302abSRuslan Ermilov.Ic export 1738dfe302abSRuslan Ermilovcommand lists the names 17394b88c807SRodney W. Grimesof all exported variables. 174045086f8cSTim J. RobbinsIf the 174145086f8cSTim J. Robbins.Fl p 174245086f8cSTim J. Robbinsoption is specified, the exported variables are printed as 174345086f8cSTim J. Robbins.Dq Ic export Ar name Ns = Ns Ar value 174445086f8cSTim J. Robbinslines, suitable for re-input to the shell. 1745a6557dcbSYaroslav Tykhiy.It Ic false 1746a6557dcbSYaroslav TykhiyA null command that returns a non-zero (false) exit value. 174781e9cda2SRuslan Ermilov.It Ic fc Oo Fl e Ar editor Oc Op Ar first Op Ar last 174881e9cda2SRuslan Ermilov.It Ic fc Fl l Oo Fl nr Oc Op Ar first Op Ar last 174981e9cda2SRuslan Ermilov.It Ic fc Fl s Oo Ar old Ns = Ns Ar new Oc Op Ar first 175049e11e3aSSheldon HearnThe 175149e11e3aSSheldon Hearn.Ic fc 17528eed22b1SJens Schweikhardtbuilt-in command lists, or edits and re-executes, 175349e11e3aSSheldon Hearncommands previously entered to an interactive shell. 175481e9cda2SRuslan Ermilov.Bl -tag -width indent 175549e11e3aSSheldon Hearn.It Fl e Ar editor 175649e11e3aSSheldon HearnUse the editor named by 175749e11e3aSSheldon Hearn.Ar editor 175849e11e3aSSheldon Hearnto edit the commands. 1759dfe302abSRuslan ErmilovThe 1760dfe302abSRuslan Ermilov.Ar editor 1761dfe302abSRuslan Ermilovstring is a command name, 176249e11e3aSSheldon Hearnsubject to search via the 176349e11e3aSSheldon Hearn.Ev PATH 176449e11e3aSSheldon Hearnvariable. 176549e11e3aSSheldon HearnThe value in the 176649e11e3aSSheldon Hearn.Ev FCEDIT 176749e11e3aSSheldon Hearnvariable is used as a default when 176849e11e3aSSheldon Hearn.Fl e 176949e11e3aSSheldon Hearnis not specified. 177049e11e3aSSheldon HearnIf 177149e11e3aSSheldon Hearn.Ev FCEDIT 177249e11e3aSSheldon Hearnis null or unset, the value of the 177349e11e3aSSheldon Hearn.Ev EDITOR 177449e11e3aSSheldon Hearnvariable is used. 177549e11e3aSSheldon HearnIf 177649e11e3aSSheldon Hearn.Ev EDITOR 177749e11e3aSSheldon Hearnis null or unset, 1778ab72124fSSteve Price.Xr ed 1 1779ab72124fSSteve Priceis used as the editor. 178049e11e3aSSheldon Hearn.It Fl l No (ell) 17814b88c807SRodney W. GrimesList the commands rather than invoking 1782eccea571SRuslan Ermilovan editor on them. 1783eccea571SRuslan ErmilovThe commands are written in the 1784dfe302abSRuslan Ermilovsequence indicated by the 1785dfe302abSRuslan Ermilov.Ar first 1786dfe302abSRuslan Ermilovand 1787dfe302abSRuslan Ermilov.Ar last 1788dfe302abSRuslan Ermilovoperands, as affected by 178949e11e3aSSheldon Hearn.Fl r , 179049e11e3aSSheldon Hearnwith each command preceded by the command number. 179149e11e3aSSheldon Hearn.It Fl n 179249e11e3aSSheldon HearnSuppress command numbers when listing with 179349e11e3aSSheldon Hearn.Fl l . 179449e11e3aSSheldon Hearn.It Fl r 179549e11e3aSSheldon HearnReverse the order of the commands listed 179649e11e3aSSheldon Hearn(with 179749e11e3aSSheldon Hearn.Fl l ) 179849e11e3aSSheldon Hearnor edited 179949e11e3aSSheldon Hearn(with neither 180049e11e3aSSheldon Hearn.Fl l 180149e11e3aSSheldon Hearnnor 180249e11e3aSSheldon Hearn.Fl s ) . 180349e11e3aSSheldon Hearn.It Fl s 18044b88c807SRodney W. GrimesRe-execute the command without invoking an editor. 180549e11e3aSSheldon Hearn.It Ar first 180649e11e3aSSheldon Hearn.It Ar last 180749e11e3aSSheldon HearnSelect the commands to list or edit. 180849e11e3aSSheldon HearnThe number of previous commands that can be accessed 180949e11e3aSSheldon Hearnare determined by the value of the 1810d0353b83SRuslan Ermilov.Ev HISTSIZE 1811d0353b83SRuslan Ermilovvariable. 181249e11e3aSSheldon HearnThe value of 181349e11e3aSSheldon Hearn.Ar first 181449e11e3aSSheldon Hearnor 181549e11e3aSSheldon Hearn.Ar last 181649e11e3aSSheldon Hearnor both are one of the following: 181781e9cda2SRuslan Ermilov.Bl -tag -width indent 1818dfe302abSRuslan Ermilov.It Oo Cm + Oc Ns Ar num 181949e11e3aSSheldon HearnA positive number representing a command number; 182049e11e3aSSheldon Hearncommand numbers can be displayed with the 182149e11e3aSSheldon Hearn.Fl l 182249e11e3aSSheldon Hearnoption. 1823dfe302abSRuslan Ermilov.It Fl Ar num 182449e11e3aSSheldon HearnA negative decimal number representing the 182549e11e3aSSheldon Hearncommand that was executed 182649e11e3aSSheldon Hearn.Ar num 182749e11e3aSSheldon Hearnof 182849e11e3aSSheldon Hearncommands previously. 1829dfe302abSRuslan ErmilovFor example, \-1 is the immediately previous command. 183049e11e3aSSheldon Hearn.It Ar string 183149e11e3aSSheldon HearnA string indicating the most recently entered command 183249e11e3aSSheldon Hearnthat begins with that string. 183349e11e3aSSheldon HearnIf the 1834dfe302abSRuslan Ermilov.Ar old Ns = Ns Ar new 183549e11e3aSSheldon Hearnoperand is not also specified with 183649e11e3aSSheldon Hearn.Fl s , 183749e11e3aSSheldon Hearnthe string form of the first operand cannot contain an embedded equal sign. 183849e11e3aSSheldon Hearn.El 183949e11e3aSSheldon Hearn.El 184049e11e3aSSheldon Hearn.Pp 184149e11e3aSSheldon HearnThe following environment variables affect the execution of 184249e11e3aSSheldon Hearn.Ic fc : 184338afdcbcSGiorgos Keramidas.Bl -tag -width ".Ev HISTSIZE" 184449e11e3aSSheldon Hearn.It Ev FCEDIT 184538afdcbcSGiorgos KeramidasName of the editor to use for history editing. 184649e11e3aSSheldon Hearn.It Ev HISTSIZE 18473d7b5b93SPhilippe CharnierThe number of previous commands that are accessible. 1848ab72124fSSteve Price.El 184949e11e3aSSheldon Hearn.It Ic fg Op Ar job 185049e11e3aSSheldon HearnMove the specified 185149e11e3aSSheldon Hearn.Ar job 185249e11e3aSSheldon Hearnor the current job to the foreground. 1853dfe302abSRuslan Ermilov.It Ic getopts Ar optstring var 1854dfe302abSRuslan ErmilovThe 1855dfe302abSRuslan Ermilov.Tn POSIX 185649e11e3aSSheldon Hearn.Ic getopts 185749e11e3aSSheldon Hearncommand. 185849e11e3aSSheldon HearnThe 185949e11e3aSSheldon Hearn.Ic getopts 186049e11e3aSSheldon Hearncommand deprecates the older 186149e11e3aSSheldon Hearn.Xr getopt 1 186249e11e3aSSheldon Hearncommand. 1863ab0a2172SSteve PriceThe first argument should be a series of letters, each possibly 1864ab0a2172SSteve Pricefollowed by a colon which indicates that the option takes an argument. 1865eccea571SRuslan ErmilovThe specified variable is set to the parsed option. 1866eccea571SRuslan ErmilovThe index of 186749e11e3aSSheldon Hearnthe next argument is placed into the shell variable 1868dfe302abSRuslan Ermilov.Va OPTIND . 1869ab0a2172SSteve PriceIf an option takes an argument, it is placed into the shell variable 1870dfe302abSRuslan Ermilov.Va OPTARG . 187149e11e3aSSheldon HearnIf an invalid option is encountered, 1872dfe302abSRuslan Ermilov.Ar var 187349e11e3aSSheldon Hearnis set to 1874dfe302abSRuslan Ermilov.Ql \&? . 1875ab0a2172SSteve PriceIt returns a false value (1) when it encounters the end of the options. 187681e9cda2SRuslan Ermilov.It Ic hash Oo Fl rv Oc Op Ar command ... 187749e11e3aSSheldon HearnThe shell maintains a hash table which remembers the locations of commands. 187849e11e3aSSheldon HearnWith no arguments whatsoever, the 187949e11e3aSSheldon Hearn.Ic hash 188049e11e3aSSheldon Hearncommand prints out the contents of this table. 188149e11e3aSSheldon HearnEntries which have not been looked at since the last 188249e11e3aSSheldon Hearn.Ic cd 188349e11e3aSSheldon Hearncommand are marked with an asterisk; 188449e11e3aSSheldon Hearnit is possible for these entries to be invalid. 1885ab72124fSSteve Price.Pp 188649e11e3aSSheldon HearnWith arguments, the 188749e11e3aSSheldon Hearn.Ic hash 188849e11e3aSSheldon Hearncommand removes each specified 188949e11e3aSSheldon Hearn.Ar command 189049e11e3aSSheldon Hearnfrom the hash table (unless they are functions) and then locates it. 189149e11e3aSSheldon HearnWith the 189249e11e3aSSheldon Hearn.Fl v 189349e11e3aSSheldon Hearnoption, 189449e11e3aSSheldon Hearn.Ic hash 189549e11e3aSSheldon Hearnprints the locations of the commands as it finds them. 189649e11e3aSSheldon HearnThe 189749e11e3aSSheldon Hearn.Fl r 189849e11e3aSSheldon Hearnoption causes the 189949e11e3aSSheldon Hearn.Ic hash 190049e11e3aSSheldon Hearncommand to delete all the entries in the hash table except for functions. 190149e11e3aSSheldon Hearn.It Ic jobid Op Ar job 1902dfe302abSRuslan ErmilovPrint the process IDs of the processes in the specified 190349e11e3aSSheldon Hearn.Ar job . 190449e11e3aSSheldon HearnIf the 190549e11e3aSSheldon Hearn.Ar job 190649e11e3aSSheldon Hearnargument is omitted, use the current job. 1907de37e41cSStefan Farfeleder.It Ic jobs Oo Fl lps Oc Op Ar job ... 1908ad8a0759STim J. RobbinsPrint information about the specified jobs, or all jobs if no 1909ad8a0759STim J. Robbins.Ar job 1910ad8a0759STim J. Robbinsargument is given. 1911ad8a0759STim J. RobbinsThe information printed includes job ID, status and command name. 1912ad8a0759STim J. Robbins.Pp 1913ad8a0759STim J. RobbinsIf the 1914ad8a0759STim J. Robbins.Fl l 1915ad8a0759STim J. Robbinsoption is specified, the PID of each job is also printed. 1916ad8a0759STim J. RobbinsIf the 1917de37e41cSStefan Farfeleder.Fl p 1918de37e41cSStefan Farfelederoption is specified, only the process IDs for the process group leaders 1919de37e41cSStefan Farfelederare printed, one per line. 1920de37e41cSStefan FarfelederIf the 1921ad8a0759STim J. Robbins.Fl s 1922de37e41cSStefan Farfelederoption is specified, only the PIDs of the job commands are printed, one per 1923de37e41cSStefan Farfelederline. 19248af11131SRuslan Ermilov.It Ic local Oo Ar variable ... Oc Op Fl 1925d2f90294SJesus R. CamouSee the 1926d2f90294SJesus R. Camou.Sx Functions 1927d2f90294SJesus R. Camousubsection. 1928d74e011fSRuslan Ermilov.It Ic pwd Op Fl L | P 1929eccea571SRuslan ErmilovPrint the path of the current directory. 1930eccea571SRuslan ErmilovThe built-in command may 19314b88c807SRodney W. Grimesdiffer from the program of the same name because the 19328eed22b1SJens Schweikhardtbuilt-in command remembers what the current directory 1933eccea571SRuslan Ermilovis rather than recomputing it each time. 1934eccea571SRuslan ErmilovThis makes 1935eccea571SRuslan Ermilovit faster. 1936eccea571SRuslan ErmilovHowever, if the current directory is 193749e11e3aSSheldon Hearnrenamed, 19388eed22b1SJens Schweikhardtthe built-in version of 193949e11e3aSSheldon Hearn.Xr pwd 1 194049e11e3aSSheldon Hearnwill continue to print the old name for the directory. 1941178897f1STim J. Robbins.Pp 1942178897f1STim J. RobbinsIf the 1943178897f1STim J. Robbins.Fl P 1944178897f1STim J. Robbinsoption is specified, symbolic links are resolved. 1945178897f1STim J. RobbinsIf the 1946178897f1STim J. Robbins.Fl L 1947178897f1STim J. Robbinsoption is specified, the shell's notion of the current directory 1948178897f1STim J. Robbinsis printed (symbolic links are not resolved). 1949178897f1STim J. RobbinsThis is the default. 1950dfe302abSRuslan Ermilov.It Ic read Oo Fl p Ar prompt Oc Oo 1951dfe302abSRuslan Ermilov.Fl t Ar timeout Oc Oo Fl er Oc Ar variable ... 195249e11e3aSSheldon HearnThe 195349e11e3aSSheldon Hearn.Ar prompt 195449e11e3aSSheldon Hearnis printed if the 195549e11e3aSSheldon Hearn.Fl p 195649e11e3aSSheldon Hearnoption is specified 1957eccea571SRuslan Ermilovand the standard input is a terminal. 1958eccea571SRuslan ErmilovThen a line is 1959eccea571SRuslan Ermilovread from the standard input. 1960eccea571SRuslan ErmilovThe trailing newline 19614b88c807SRodney W. Grimesis deleted from the line and the line is split as 196249e11e3aSSheldon Hearndescribed in the section on 196349e11e3aSSheldon Hearn.Sx White Space Splitting (Field Splitting) 196449e11e3aSSheldon Hearnabove, and 19654b88c807SRodney W. Grimesthe pieces are assigned to the variables in order. 1966f434d1dfSAdam DavidIf there are more pieces than variables, the remaining 196749e11e3aSSheldon Hearnpieces (along with the characters in 1968dfe302abSRuslan Ermilov.Va IFS 196949e11e3aSSheldon Hearnthat separated them) 197049e11e3aSSheldon Hearnare assigned to the last variable. 1971f434d1dfSAdam DavidIf there are more variables than pieces, the remaining 1972f434d1dfSAdam Davidvariables are assigned the null string. 1973ab72124fSSteve Price.Pp 197449e11e3aSSheldon HearnBackslashes are treated specially, unless the 197549e11e3aSSheldon Hearn.Fl r 197649e11e3aSSheldon Hearnoption is 1977eccea571SRuslan Ermilovspecified. 1978eccea571SRuslan ErmilovIf a backslash is followed by 19798f0561ccSThomas Gellekuma newline, the backslash and the newline will be 1980eccea571SRuslan Ermilovdeleted. 1981eccea571SRuslan ErmilovIf a backslash is followed by any other 19828f0561ccSThomas Gellekumcharacter, the backslash will be deleted and the following 198349e11e3aSSheldon Hearncharacter will be treated as though it were not in 1984dfe302abSRuslan Ermilov.Va IFS , 198549e11e3aSSheldon Hearneven if it is. 19868f0561ccSThomas Gellekum.Pp 198749e11e3aSSheldon HearnIf the 198849e11e3aSSheldon Hearn.Fl t 198949e11e3aSSheldon Hearnoption is specified and the 199049e11e3aSSheldon Hearn.Ar timeout 1991fe40d6d3SJilles Tjoelkerelapses before a complete line of input is supplied, 199249e11e3aSSheldon Hearnthe 199349e11e3aSSheldon Hearn.Ic read 19941b161559SStefan Farfeledercommand will return an exit status of 1 without assigning any values. 199549e11e3aSSheldon HearnThe 199649e11e3aSSheldon Hearn.Ar timeout 199749e11e3aSSheldon Hearnvalue may optionally be followed by one of 1998dfe302abSRuslan Ermilov.Ql s , 1999dfe302abSRuslan Ermilov.Ql m 200049e11e3aSSheldon Hearnor 2001dfe302abSRuslan Ermilov.Ql h 2002a910f192SDima Dorfmanto explicitly specify seconds, minutes or hours. 200349e11e3aSSheldon HearnIf none is supplied, 2004dfe302abSRuslan Ermilov.Ql s 200549e11e3aSSheldon Hearnis assumed. 2006afa53c8dSMike Smith.Pp 200749e11e3aSSheldon HearnThe 200849e11e3aSSheldon Hearn.Fl e 200949e11e3aSSheldon Hearnoption exists only for backward compatibility with older scripts. 20109ba31ca0SRuslan Ermilov.It Ic readonly Oo Fl p Oc Op Ar name ... 201149e11e3aSSheldon HearnEach specified 201249e11e3aSSheldon Hearn.Ar name 201349e11e3aSSheldon Hearnis marked as read only, 201449e11e3aSSheldon Hearnso that it cannot be subsequently modified or unset. 201549e11e3aSSheldon HearnThe shell allows the value of a variable to be set 201649e11e3aSSheldon Hearnat the same time as it is marked read only 201749e11e3aSSheldon Hearnby using the following form: 2018dfe302abSRuslan Ermilov.Pp 2019dfe302abSRuslan Ermilov.D1 Ic readonly Ar name Ns = Ns Ar value 2020ab72124fSSteve Price.Pp 202149e11e3aSSheldon HearnWith no arguments the 202249e11e3aSSheldon Hearn.Ic readonly 202349e11e3aSSheldon Hearncommand lists the names of all read only variables. 202445086f8cSTim J. RobbinsIf the 202545086f8cSTim J. Robbins.Fl p 202645086f8cSTim J. Robbinsoption is specified, the read-only variables are printed as 202745086f8cSTim J. Robbins.Dq Ic readonly Ar name Ns = Ns Ar value 202845086f8cSTim J. Robbinslines, suitable for re-input to the shell. 2029d2f90294SJesus R. Camou.It Ic return Op Ar exitstatus 2030d2f90294SJesus R. CamouSee the 2031d2f90294SJesus R. Camou.Sx Functions 2032d2f90294SJesus R. Camousubsection. 203381e9cda2SRuslan Ermilov.It Ic set Oo Fl /+abCEefIimnpTuVvx Oc Oo Fl /+o Ar longname Oc Oo 203481e9cda2SRuslan Ermilov.Fl c Ar string Oc Op Fl - Ar arg ... 2035e918fc8fSSheldon HearnThe 2036e918fc8fSSheldon Hearn.Ic set 2037e918fc8fSSheldon Hearncommand performs three different functions: 2038ab72124fSSteve Price.Bl -item 2039ab72124fSSteve Price.It 204049e11e3aSSheldon HearnWith no arguments, it lists the values of all shell variables. 2041ab72124fSSteve Price.It 204249e11e3aSSheldon HearnIf options are given, 204349e11e3aSSheldon Hearneither in short form or using the long 204449e11e3aSSheldon Hearn.Dq Fl /+o Ar longname 204549e11e3aSSheldon Hearnform, 204649e11e3aSSheldon Hearnit sets or clears the specified options as described in the section called 20476b15476eSSheldon Hearn.Sx Argument List Processing . 2048ab72124fSSteve Price.It 204949e11e3aSSheldon HearnIf the 205049e11e3aSSheldon Hearn.Dq Fl - 205149e11e3aSSheldon Hearnoption is specified, 205249e11e3aSSheldon Hearn.Ic set 205349e11e3aSSheldon Hearnwill replace the shell's positional parameters with the subsequent 205449e11e3aSSheldon Hearnarguments. 205549e11e3aSSheldon HearnIf no arguments follow the 205649e11e3aSSheldon Hearn.Dq Fl - 205749e11e3aSSheldon Hearnoption, 205849e11e3aSSheldon Hearnall the positional parameters will be cleared, 205949e11e3aSSheldon Hearnwhich is equivalent to executing the command 2060dfe302abSRuslan Ermilov.Dq Li "shift $#" . 206149e11e3aSSheldon HearnThe 206249e11e3aSSheldon Hearn.Dq Fl - 20638eed22b1SJens Schweikhardtflag may be omitted when specifying arguments to be used 206449e11e3aSSheldon Hearnas positional replacement parameters. 206549e11e3aSSheldon HearnThis is not recommended, 206649e11e3aSSheldon Hearnbecause the first argument may begin with a dash 2067a762afe5SGiorgos Keramidas.Pq Ql - 206849e11e3aSSheldon Hearnor a plus 2069a762afe5SGiorgos Keramidas.Pq Ql + , 207049e11e3aSSheldon Hearnwhich the 207149e11e3aSSheldon Hearn.Ic set 207249e11e3aSSheldon Hearncommand will interpret as a request to enable or disable options. 2073ab72124fSSteve Price.El 2074dfe302abSRuslan Ermilov.It Ic setvar Ar variable value 207549e11e3aSSheldon HearnAssigns the specified 207649e11e3aSSheldon Hearn.Ar value 207749e11e3aSSheldon Hearnto the specified 207849e11e3aSSheldon Hearn.Ar variable . 2079dfe302abSRuslan ErmilovThe 2080dfe302abSRuslan Ermilov.Ic setvar 2081dfe302abSRuslan Ermilovcommand is intended to be used in functions that 2082e6d3cf26SSheldon Hearnassign values to variables whose names are passed as parameters. 208349e11e3aSSheldon HearnIn general it is better to write 2084dfe302abSRuslan Ermilov.Dq Ar variable Ns = Ns Ar value 208549e11e3aSSheldon Hearnrather than using 208649e11e3aSSheldon Hearn.Ic setvar . 208749e11e3aSSheldon Hearn.It Ic shift Op Ar n 208849e11e3aSSheldon HearnShift the positional parameters 208949e11e3aSSheldon Hearn.Ar n 2090e918fc8fSSheldon Hearntimes, or once if 209149e11e3aSSheldon Hearn.Ar n 209249e11e3aSSheldon Hearnis not specified. 2093dfe302abSRuslan ErmilovA shift sets the value of 2094dfe302abSRuslan Ermilov.Li $1 2095dfe302abSRuslan Ermilovto the value of 2096dfe302abSRuslan Ermilov.Li $2 , 2097dfe302abSRuslan Ermilovthe value of 2098dfe302abSRuslan Ermilov.Li $2 2099dfe302abSRuslan Ermilovto the value of 2100dfe302abSRuslan Ermilov.Li $3 , 2101dfe302abSRuslan Ermilovand so on, 2102dfe302abSRuslan Ermilovdecreasing the value of 2103dfe302abSRuslan Ermilov.Li $# 2104dfe302abSRuslan Ermilovby one. 210549e11e3aSSheldon HearnIf there are zero positional parameters, shifting does not do anything. 210610845922SYaroslav Tykhiy.It Ic test 210710845922SYaroslav TykhiyA built-in equivalent of 210810845922SYaroslav Tykhiy.Xr test 1 . 21091974986aSStefan Farfeleder.It Ic times 21101974986aSStefan FarfelederPrint the amount of time spent executing the shell and its children. 21111974986aSStefan FarfelederThe first output line shows the user and system times for the shell 21121974986aSStefan Farfelederitself, the second one contains the user and system times for the 21131974986aSStefan Farfelederchildren. 211481e9cda2SRuslan Ermilov.It Ic trap Oo Ar action Oc Ar signal ... 21150673e800SStefan Farfeleder.It Ic trap Fl l 211649e11e3aSSheldon HearnCause the shell to parse and execute 211749e11e3aSSheldon Hearn.Ar action 211849e11e3aSSheldon Hearnwhen any specified 211949e11e3aSSheldon Hearn.Ar signal 212049e11e3aSSheldon Hearnis received. 2121162ae3aeSTony FinchThe signals are specified by name or number. 2122162ae3aeSTony FinchIn addition, the pseudo-signal 2123f5d1157fSRuslan Ermilov.Cm EXIT 2124dfe302abSRuslan Ermilovmay be used to specify an 2125dfe302abSRuslan Ermilov.Ar action 2126dfe302abSRuslan Ermilovthat is performed when the shell terminates. 212749e11e3aSSheldon HearnThe 212849e11e3aSSheldon Hearn.Ar action 21290673e800SStefan Farfeledermay be an empty string or a dash 21309badf57fSRuslan Ermilov.Pq Ql - ; 213149e11e3aSSheldon Hearnthe former causes the specified signal to be ignored 213249e11e3aSSheldon Hearnand the latter causes the default action to be taken. 21330673e800SStefan FarfelederOmitting the 21340673e800SStefan Farfeleder.Ar action 21350673e800SStefan Farfelederis another way to request the default action, for compatibility reasons this 21360673e800SStefan Farfelederusage is not recommended though. 213749e11e3aSSheldon HearnWhen the shell forks off a subshell, 213849e11e3aSSheldon Hearnit resets trapped (but not ignored) signals to the default action. 213949e11e3aSSheldon HearnThe 214049e11e3aSSheldon Hearn.Ic trap 214149e11e3aSSheldon Hearncommand has no effect on signals that were ignored on entry to the shell. 21420673e800SStefan Farfeleder.Pp 21430673e800SStefan FarfelederOption 21440673e800SStefan Farfeleder.Fl l 21450673e800SStefan Farfeledercauses the 21460673e800SStefan Farfeleder.Ic trap 21470673e800SStefan Farfeledercommand to display a list of valid signal names. 2148a6557dcbSYaroslav Tykhiy.It Ic true 2149a6557dcbSYaroslav TykhiyA null command that returns a 0 (true) exit value. 215049e11e3aSSheldon Hearn.It Ic type Op Ar name ... 215149e11e3aSSheldon HearnInterpret each 215249e11e3aSSheldon Hearn.Ar name 215349e11e3aSSheldon Hearnas a command and print the resolution of the command search. 2154e6d3cf26SSheldon HearnPossible resolutions are: 215530268dfaSJilles Tjoelkershell keyword, alias, special shell builtin, shell builtin, command, 215630268dfaSJilles Tjoelkertracked alias 215749e11e3aSSheldon Hearnand not found. 215849e11e3aSSheldon HearnFor aliases the alias expansion is printed; 215949e11e3aSSheldon Hearnfor commands and tracked aliases 216049e11e3aSSheldon Hearnthe complete pathname of the command is printed. 2161c8054a61SJilles Tjoelker.It Ic ulimit Oo Fl HSabcdflmnpstuvw Oc Op Ar limit 2162ab72124fSSteve PriceSet or display resource limits (see 2163ab72124fSSteve Price.Xr getrlimit 2 ) . 21646b15476eSSheldon HearnIf 216549e11e3aSSheldon Hearn.Ar limit 21666b15476eSSheldon Hearnis specified, the named resource will be set; 21677a2afe64SJoerg Wunschotherwise the current resource value will be displayed. 2168ab72124fSSteve Price.Pp 21696b15476eSSheldon HearnIf 217049e11e3aSSheldon Hearn.Fl H 217149e11e3aSSheldon Hearnis specified, the hard limits will be set or displayed. 217249e11e3aSSheldon HearnWhile everybody is allowed to reduce a hard limit, 217349e11e3aSSheldon Hearnonly the superuser can increase it. 217449e11e3aSSheldon HearnThe 217549e11e3aSSheldon Hearn.Fl S 217649e11e3aSSheldon Hearnoption 2177eccea571SRuslan Ermilovspecifies the soft limits instead. 2178eccea571SRuslan ErmilovWhen displaying limits, 21796b15476eSSheldon Hearnonly one of 218049e11e3aSSheldon Hearn.Fl S 21816b15476eSSheldon Hearnor 218249e11e3aSSheldon Hearn.Fl H 218349e11e3aSSheldon Hearncan be given. 218449e11e3aSSheldon HearnThe default is to display the soft limits, 218549e11e3aSSheldon Hearnand to set both the hard and the soft limits. 2186ab72124fSSteve Price.Pp 21876b15476eSSheldon HearnOption 218849e11e3aSSheldon Hearn.Fl a 218949e11e3aSSheldon Hearncauses the 219049e11e3aSSheldon Hearn.Ic ulimit 219149e11e3aSSheldon Hearncommand to display all resources. 219249e11e3aSSheldon HearnThe parameter 219349e11e3aSSheldon Hearn.Ar limit 21946b15476eSSheldon Hearnis not acceptable in this mode. 2195ab72124fSSteve Price.Pp 21967a2afe64SJoerg WunschThe remaining options specify which resource value is to be 219749e11e3aSSheldon Hearndisplayed or modified. 219849e11e3aSSheldon HearnThey are mutually exclusive. 219981e9cda2SRuslan Ermilov.Bl -tag -width indent 22003652a236SMartin Cracauer.It Fl b Ar sbsize 22013652a236SMartin CracauerThe maximum size of socket buffer usage, in bytes. 220249e11e3aSSheldon Hearn.It Fl c Ar coredumpsize 22037a2afe64SJoerg WunschThe maximal size of core dump files, in 512-byte blocks. 220449e11e3aSSheldon Hearn.It Fl d Ar datasize 22057a2afe64SJoerg WunschThe maximal size of the data segment of a process, in kilobytes. 220649e11e3aSSheldon Hearn.It Fl f Ar filesize 220749e11e3aSSheldon HearnThe maximal size of a file, in 512-byte blocks. 220849e11e3aSSheldon Hearn.It Fl l Ar lockedmem 22097a2afe64SJoerg WunschThe maximal size of memory that can be locked by a process, in 22107a2afe64SJoerg Wunschkilobytes. 221149e11e3aSSheldon Hearn.It Fl m Ar memoryuse 22127a2afe64SJoerg WunschThe maximal resident set size of a process, in kilobytes. 221349e11e3aSSheldon Hearn.It Fl n Ar nofiles 22147a2afe64SJoerg WunschThe maximal number of descriptors that could be opened by a process. 2215331773cdSEd Schouten.It Fl p Ar pseudoterminals 2216331773cdSEd SchoutenThe maximal number of pseudo-terminals for this user ID. 221749e11e3aSSheldon Hearn.It Fl s Ar stacksize 22187a2afe64SJoerg WunschThe maximal size of the stack segment, in kilobytes. 221949e11e3aSSheldon Hearn.It Fl t Ar time 22207a2afe64SJoerg WunschThe maximal amount of CPU time to be used by each process, in seconds. 222149e11e3aSSheldon Hearn.It Fl u Ar userproc 2222ab72124fSSteve PriceThe maximal number of simultaneous processes for this user ID. 222362df9b62SSheldon Hearn.It Fl v Ar virtualmem 22242d41ef4bSMatthew DillonThe maximal virtual size of a process, in kilobytes. 2225c8054a61SJilles Tjoelker.It Fl w Ar swapuse 2226c8054a61SJilles TjoelkerThe maximum amount of swap space reserved or used for this user ID, 2227c8054a61SJilles Tjoelkerin kilobytes. 2228ab72124fSSteve Price.El 2229faa1ed35SStefan Farfeleder.It Ic umask Oo Fl S Oc Op Ar mask 223049e11e3aSSheldon HearnSet the file creation mask (see 2231ab72124fSSteve Price.Xr umask 2 ) 2232faa1ed35SStefan Farfelederto the octal or symbolic (see 2233faa1ed35SStefan Farfeleder.Xr chmod 1 ) 2234faa1ed35SStefan Farfeledervalue specified by 22355d3b843bSSheldon Hearn.Ar mask . 223649e11e3aSSheldon HearnIf the argument is omitted, the current mask value is printed. 2237faa1ed35SStefan FarfelederIf the 2238faa1ed35SStefan Farfeleder.Fl S 2239faa1ed35SStefan Farfelederoption is specified, the output is symbolic, otherwise the output is octal. 2240de4ad382SStefan Farfeleder.It Ic unalias Oo Fl a Oc Op Ar name ... 2241de4ad382SStefan FarfelederThe specified alias names are removed. 22426b15476eSSheldon HearnIf 22431b9735e6SSheldon Hearn.Fl a 22446b15476eSSheldon Hearnis specified, all aliases are removed. 22459ba31ca0SRuslan Ermilov.It Ic unset Oo Fl fv Oc Ar name ... 22468b34ad92STim J. RobbinsThe specified variables or functions are unset and unexported. 22478b34ad92STim J. RobbinsIf the 22488b34ad92STim J. Robbins.Fl v 22498b34ad92STim J. Robbinsoption is specified or no options are given, the 225049e11e3aSSheldon Hearn.Ar name 22518b34ad92STim J. Robbinsarguments are treated as variable names. 22528b34ad92STim J. RobbinsIf the 22538b34ad92STim J. Robbins.Fl f 22548b34ad92STim J. Robbinsoption is specified, the 22558b34ad92STim J. Robbins.Ar name 22568b34ad92STim J. Robbinsarguments are treated as function names. 225749e11e3aSSheldon Hearn.It Ic wait Op Ar job 225849e11e3aSSheldon HearnWait for the specified 225949e11e3aSSheldon Hearn.Ar job 226049e11e3aSSheldon Hearnto complete and return the exit status of the last process in the 226149e11e3aSSheldon Hearn.Ar job . 2262e6d3cf26SSheldon HearnIf the argument is omitted, wait for all jobs to complete 2263e6d3cf26SSheldon Hearnand return an exit status of zero. 2264ab72124fSSteve Price.El 2265ab72124fSSteve Price.Ss Commandline Editing 2266ab72124fSSteve PriceWhen 2267ab72124fSSteve Price.Nm 2268ab72124fSSteve Priceis being used interactively from a terminal, the current command 226949e11e3aSSheldon Hearnand the command history 227049e11e3aSSheldon Hearn(see 227149e11e3aSSheldon Hearn.Ic fc 227249e11e3aSSheldon Hearnin 22738eed22b1SJens Schweikhardt.Sx Built-in Commands ) 2274dfe302abSRuslan Ermilovcan be edited using 2275dfe302abSRuslan Ermilov.Nm vi Ns -mode 2276dfe302abSRuslan Ermilovcommand line editing. 227749e11e3aSSheldon HearnThis mode uses commands similar 2278dfe302abSRuslan Ermilovto a subset of those described in the 2279dfe302abSRuslan Ermilov.Xr vi 1 2280dfe302abSRuslan Ermilovman page. 228149e11e3aSSheldon HearnThe command 2282dfe302abSRuslan Ermilov.Dq Li "set -o vi" 228349e11e3aSSheldon Hearn(or 2284dfe302abSRuslan Ermilov.Dq Li "set -V" ) 2285dfe302abSRuslan Ermilovenables 2286dfe302abSRuslan Ermilov.Nm vi Ns -mode 2287dfe302abSRuslan Ermilovediting and places 2288ab72124fSSteve Price.Nm 2289dfe302abSRuslan Ermilovinto 2290dfe302abSRuslan Ermilov.Nm vi 2291dfe302abSRuslan Ermilovinsert mode. 2292dfe302abSRuslan ErmilovWith 2293dfe302abSRuslan Ermilov.Nm vi Ns -mode 2294dfe302abSRuslan Ermilovenabled, 2295ab72124fSSteve Price.Nm 229649e11e3aSSheldon Hearncan be switched between insert mode and command mode by typing 229749e11e3aSSheldon Hearn.Aq ESC . 229849e11e3aSSheldon HearnHitting 229949e11e3aSSheldon Hearn.Aq return 230049e11e3aSSheldon Hearnwhile in command mode will pass the line to the shell. 2301ab72124fSSteve Price.Pp 230249e11e3aSSheldon HearnSimilarly, the 2303dfe302abSRuslan Ermilov.Dq Li "set -o emacs" 230449e11e3aSSheldon Hearn(or 2305dfe302abSRuslan Ermilov.Dq Li "set -E" ) 230649e11e3aSSheldon Hearncommand can be used to enable a subset of 2307dfe302abSRuslan Ermilov.Nm emacs Ns -style 2308dfe302abSRuslan Ermilovcommand line editing features. 230938afdcbcSGiorgos Keramidas.Sh ENVIRONMENT 231038afdcbcSGiorgos KeramidasThe following environment variables affect the execution of 231138afdcbcSGiorgos Keramidas.Nm : 231238afdcbcSGiorgos Keramidas.Bl -tag -width ".Ev HISTSIZE" 231338afdcbcSGiorgos Keramidas.It Ev CDPATH 231438afdcbcSGiorgos KeramidasThe search path used with the 231538afdcbcSGiorgos Keramidas.Ic cd 231638afdcbcSGiorgos Keramidasbuilt-in. 231738afdcbcSGiorgos Keramidas.It Ev EDITOR 231838afdcbcSGiorgos KeramidasThe fallback editor used with the 231938afdcbcSGiorgos Keramidas.Ic fc 232038afdcbcSGiorgos Keramidasbuilt-in. 232138afdcbcSGiorgos KeramidasIf not set, the default editor is 232238afdcbcSGiorgos Keramidas.Xr ed 1 . 232338afdcbcSGiorgos Keramidas.It Ev FCEDIT 232438afdcbcSGiorgos KeramidasThe default editor used with the 232538afdcbcSGiorgos Keramidas.Ic fc 232638afdcbcSGiorgos Keramidasbuilt-in. 232738afdcbcSGiorgos Keramidas.It Ev HISTSIZE 232838afdcbcSGiorgos KeramidasThe number of previous commands that are accessible. 232938afdcbcSGiorgos Keramidas.It Ev HOME 233038afdcbcSGiorgos KeramidasThe starting directory of 233138afdcbcSGiorgos Keramidas.Nm . 233238afdcbcSGiorgos Keramidas.It Ev IFS 233338afdcbcSGiorgos KeramidasInput Field Separators. 233438afdcbcSGiorgos KeramidasThis is normally set to 233538afdcbcSGiorgos Keramidas.Aq space , 233638afdcbcSGiorgos Keramidas.Aq tab , 233738afdcbcSGiorgos Keramidasand 233838afdcbcSGiorgos Keramidas.Aq newline . 233938afdcbcSGiorgos KeramidasSee the 234038afdcbcSGiorgos Keramidas.Sx White Space Splitting 234138afdcbcSGiorgos Keramidassection for more details. 234238afdcbcSGiorgos Keramidas.It Ev MAIL 234338afdcbcSGiorgos KeramidasThe name of a mail file, that will be checked for the arrival of new 234438afdcbcSGiorgos Keramidasmail. 234538afdcbcSGiorgos KeramidasOverridden by 234638afdcbcSGiorgos Keramidas.Ev MAILPATH . 234738afdcbcSGiorgos Keramidas.It Ev MAILPATH 234838afdcbcSGiorgos KeramidasA colon 234938afdcbcSGiorgos Keramidas.Pq Ql \&: 235038afdcbcSGiorgos Keramidasseparated list of file names, for the shell to check for incoming 235138afdcbcSGiorgos Keramidasmail. 235238afdcbcSGiorgos KeramidasThis environment setting overrides the 235338afdcbcSGiorgos Keramidas.Ev MAIL 235438afdcbcSGiorgos Keramidassetting. 235538afdcbcSGiorgos KeramidasThere is a maximum of 10 mailboxes that can be monitored at once. 235638afdcbcSGiorgos Keramidas.It Ev PATH 235738afdcbcSGiorgos KeramidasThe default search path for executables. 235838afdcbcSGiorgos KeramidasSee the 235938afdcbcSGiorgos Keramidas.Sx Path Search 236038afdcbcSGiorgos Keramidassection for details. 236138afdcbcSGiorgos Keramidas.It Ev PS1 236238afdcbcSGiorgos KeramidasThe primary prompt string, which defaults to 2363fb039b55SRuslan Ermilov.Dq Li "$ " , 236438afdcbcSGiorgos Keramidasunless you are the superuser, in which case it defaults to 2365fb039b55SRuslan Ermilov.Dq Li "# " . 236638afdcbcSGiorgos Keramidas.It Ev PS2 236738afdcbcSGiorgos KeramidasThe secondary prompt string, which defaults to 2368fb039b55SRuslan Ermilov.Dq Li "> " . 2369120c8e6cSStefan Farfeleder.It Ev PS4 2370120c8e6cSStefan FarfelederThe prefix for the trace output (if 2371120c8e6cSStefan Farfeleder.Fl x 2372120c8e6cSStefan Farfelederis active). 2373120c8e6cSStefan FarfelederThe default is 2374120c8e6cSStefan Farfeleder.Dq Li "+ " . 237538afdcbcSGiorgos Keramidas.It Ev TERM 237638afdcbcSGiorgos KeramidasThe default terminal setting for the shell. 237738afdcbcSGiorgos KeramidasThis is inherited by children of the shell, and is used in the history 237838afdcbcSGiorgos Keramidasediting modes. 237938afdcbcSGiorgos Keramidas.El 2380fb039b55SRuslan Ermilov.Sh EXIT STATUS 2381fb039b55SRuslan ErmilovErrors that are detected by the shell, such as a syntax error, will 2382fb039b55SRuslan Ermilovcause the shell to exit with a non-zero exit status. 2383fb039b55SRuslan ErmilovIf the shell is not an interactive shell, the execution of the shell 2384fb039b55SRuslan Ermilovfile will be aborted. 2385fb039b55SRuslan ErmilovOtherwise the shell will return the exit status of the last command 2386dfe302abSRuslan Ermilovexecuted, or if the 2387dfe302abSRuslan Ermilov.Ic exit 2388dfe302abSRuslan Ermilovbuiltin is used with a numeric argument, it 2389fb039b55SRuslan Ermilovwill return the argument. 2390c83e7c50SJoseph Koshy.Sh SEE ALSO 2391c644db6aSSheldon Hearn.Xr builtin 1 , 239238afdcbcSGiorgos Keramidas.Xr chsh 1 , 2393c644db6aSSheldon Hearn.Xr echo 1 , 239438afdcbcSGiorgos Keramidas.Xr ed 1 , 239538afdcbcSGiorgos Keramidas.Xr emacs 1 , 2396c83e7c50SJoseph Koshy.Xr expr 1 , 239738afdcbcSGiorgos Keramidas.Xr getopt 1 , 23985521ff5aSRuslan Ermilov.Xr pwd 1 , 239938afdcbcSGiorgos Keramidas.Xr test 1 , 240038afdcbcSGiorgos Keramidas.Xr vi 1 , 240138afdcbcSGiorgos Keramidas.Xr execve 2 , 240238afdcbcSGiorgos Keramidas.Xr getrlimit 2 , 2403fd50df30SRuslan Ermilov.Xr umask 2 , 240438afdcbcSGiorgos Keramidas.Xr editrc 5 2405ab72124fSSteve Price.Sh HISTORY 2406b8923d4cSWolfram SchneiderA 2407ab72124fSSteve Price.Nm 24089cdd1e3fSYaroslav Tykhiycommand, the Thompson shell, appeared in 2409fc482908STim J. Robbins.At v1 . 24109cdd1e3fSYaroslav TykhiyIt was superseded in 24119cdd1e3fSYaroslav Tykhiy.At v7 24129cdd1e3fSYaroslav Tykhiyby the Bourne shell, which inherited the name 24139cdd1e3fSYaroslav Tykhiy.Nm . 24149cdd1e3fSYaroslav Tykhiy.Pp 24159cdd1e3fSYaroslav TykhiyThis version of 24169cdd1e3fSYaroslav Tykhiy.Nm 24179cdd1e3fSYaroslav Tykhiywas rewritten in 1989 under the 24189cdd1e3fSYaroslav Tykhiy.Bx 24199cdd1e3fSYaroslav Tykhiylicense after the Bourne shell from 24209cdd1e3fSYaroslav Tykhiy.At V.4 . 24219cdd1e3fSYaroslav Tykhiy.Sh AUTHORS 24229cdd1e3fSYaroslav TykhiyThis version of 24239cdd1e3fSYaroslav Tykhiy.Nm 24249badf57fSRuslan Ermilovwas originally written by 24259badf57fSRuslan Ermilov.An Kenneth Almquist . 2426128dc4a2STim J. Robbins.Sh BUGS 2427128dc4a2STim J. RobbinsThe 2428128dc4a2STim J. Robbins.Nm 2429128dc4a2STim J. Robbinsutility does not recognize multibyte characters. 2430