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*9897c45fSJilles Tjoelker.Dd November 19, 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 4357a40f7dSJilles Tjoelker.Op Fl /+abCEefIimnPpTuVvx 44ab72124fSSteve Price.Op Fl /+o Ar longname 4557a40f7dSJilles Tjoelker.Oo 4657a40f7dSJilles Tjoelker.Ar script 4757a40f7dSJilles Tjoelker.Op Ar arg ... 4857a40f7dSJilles Tjoelker.Oc 4957a40f7dSJilles Tjoelker.Nm 5057a40f7dSJilles Tjoelker.Op Fl /+abCEefIimnPpTuVvx 5157a40f7dSJilles Tjoelker.Op Fl /+o Ar longname 5257a40f7dSJilles Tjoelker.Fl c Ar string 5357a40f7dSJilles Tjoelker.Oo 5457a40f7dSJilles Tjoelker.Ar name 5557a40f7dSJilles Tjoelker.Op Ar arg ... 5657a40f7dSJilles Tjoelker.Oc 5757a40f7dSJilles Tjoelker.Nm 5857a40f7dSJilles Tjoelker.Op Fl /+abCEefIimnPpTuVvx 5957a40f7dSJilles Tjoelker.Op Fl /+o Ar longname 6057a40f7dSJilles Tjoelker.Fl s 6181e9cda2SRuslan Ermilov.Op Ar arg ... 62ab72124fSSteve Price.Sh DESCRIPTION 63e918fc8fSSheldon HearnThe 64e918fc8fSSheldon Hearn.Nm 65e918fc8fSSheldon Hearnutility is the standard command interpreter for the system. 66ab72124fSSteve PriceThe current version of 67ab72124fSSteve Price.Nm 683fdfd0a4SJilles Tjoelkeris close to the 693fdfd0a4SJilles Tjoelker.St -p1003.1 70eccea571SRuslan Ermilovspecification for the shell. 713fdfd0a4SJilles TjoelkerIt only supports features 72dfe302abSRuslan Ermilovdesignated by 73dfe302abSRuslan Ermilov.Tn POSIX , 743fdfd0a4SJilles Tjoelkerplus a few Berkeley extensions. 7549e11e3aSSheldon HearnThis man page is not intended to be a tutorial nor a complete 764b88c807SRodney W. Grimesspecification of the shell. 77ab72124fSSteve Price.Ss Overview 784b88c807SRodney W. GrimesThe shell is a command that reads lines from 794b88c807SRodney W. Grimeseither a file or the terminal, interprets them, and 80e6d3cf26SSheldon Hearngenerally executes other commands. 8149e11e3aSSheldon HearnIt is the program that is started when a user logs into the system, 8249e11e3aSSheldon Hearnalthough a user can select a different shell with the 83c644db6aSSheldon Hearn.Xr chsh 1 8449e11e3aSSheldon Hearncommand. 854b88c807SRodney W. GrimesThe shell 864b88c807SRodney W. Grimesimplements a language that has flow control constructs, 874b88c807SRodney W. Grimesa macro facility that provides a variety of features in 888eed22b1SJens Schweikhardtaddition to data storage, along with built-in history and line 89eccea571SRuslan Ermilovediting capabilities. 90eccea571SRuslan ErmilovIt incorporates many features to 914b88c807SRodney W. Grimesaid interactive use and has the advantage that the interpretative 924b88c807SRodney W. Grimeslanguage is common to both interactive and non-interactive 93eccea571SRuslan Ermilovuse (shell scripts). 94eccea571SRuslan ErmilovThat is, commands can be typed directly 9549e11e3aSSheldon Hearnto the running shell or can be put into a file, 9649e11e3aSSheldon Hearnwhich can be executed directly by the shell. 97ab72124fSSteve Price.Ss Invocation 9849e11e3aSSheldon Hearn.\" 9949e11e3aSSheldon Hearn.\" XXX This next sentence is incredibly confusing. 10049e11e3aSSheldon Hearn.\" 10149e11e3aSSheldon HearnIf no arguments are present and if the standard input of the shell 10249e11e3aSSheldon Hearnis connected to a terminal 10349e11e3aSSheldon Hearn(or if the 10449e11e3aSSheldon Hearn.Fl i 10549e11e3aSSheldon Hearnoption is set), 106eccea571SRuslan Ermilovthe shell is considered an interactive shell. 107eccea571SRuslan ErmilovAn interactive shell 1084b88c807SRodney W. Grimesgenerally prompts before each command and handles programming 1094b88c807SRodney W. Grimesand command errors differently (as described below). 1104b88c807SRodney W. GrimesWhen first starting, the shell inspects argument 0, and 11149e11e3aSSheldon Hearnif it begins with a dash 112a762afe5SGiorgos Keramidas.Pq Ql - , 11349e11e3aSSheldon Hearnthe shell is also considered a login shell. 11449e11e3aSSheldon HearnThis is normally done automatically by the system 115eccea571SRuslan Ermilovwhen the user first logs in. 116eccea571SRuslan ErmilovA login shell first reads commands 117ab72124fSSteve Pricefrom the files 118ab72124fSSteve Price.Pa /etc/profile 11949e11e3aSSheldon Hearnand then 120ab72124fSSteve Price.Pa .profile 121dfe302abSRuslan Ermilovin a user's home directory, 122eccea571SRuslan Ermilovif they exist. 123eccea571SRuslan ErmilovIf the environment variable 124ab72124fSSteve Price.Ev ENV 125ab72124fSSteve Priceis set on entry to a shell, or is set in the 126ab72124fSSteve Price.Pa .profile 12749e11e3aSSheldon Hearnof a login shell, the shell then reads commands from the file named in 128ab72124fSSteve Price.Ev ENV . 129ab72124fSSteve PriceTherefore, a user should place commands that are to be executed only 130ab72124fSSteve Priceat login time in the 131ab72124fSSteve Price.Pa .profile 132ab72124fSSteve Pricefile, and commands that are executed for every shell inside the 133ab72124fSSteve Price.Ev ENV 134e6d3cf26SSheldon Hearnfile. 13549e11e3aSSheldon HearnThe user can set the 136ab72124fSSteve Price.Ev ENV 13749e11e3aSSheldon Hearnvariable to some file by placing the following line in the file 138ab72124fSSteve Price.Pa .profile 13949e11e3aSSheldon Hearnin the home directory, 140ab72124fSSteve Pricesubstituting for 141ab72124fSSteve Price.Pa .shinit 14249e11e3aSSheldon Hearnthe filename desired: 14349e11e3aSSheldon Hearn.Pp 144dfe302abSRuslan Ermilov.Dl "ENV=$HOME/.shinit; export ENV" 14549e11e3aSSheldon Hearn.Pp 14649e11e3aSSheldon HearnThe first non-option argument specified on the command line 14749e11e3aSSheldon Hearnwill be treated as the 1484b88c807SRodney W. Grimesname of a file from which to read commands (a shell script), and 1494b88c807SRodney W. Grimesthe remaining arguments are set as the positional parameters 150dfe302abSRuslan Ermilovof the shell 151dfe302abSRuslan Ermilov.Li ( $1 , $2 , 152dfe302abSRuslan Ermilovetc.). 153eccea571SRuslan ErmilovOtherwise, the shell reads commands 1544b88c807SRodney W. Grimesfrom its standard input. 155ea76be72SSteve Price.Pp 156ea76be72SSteve PriceUnlike older versions of 157ea76be72SSteve Price.Nm 158ea76be72SSteve Pricethe 159ea76be72SSteve Price.Ev ENV 160eccea571SRuslan Ermilovscript is only sourced on invocation of interactive shells. 161eccea571SRuslan ErmilovThis 162ea76be72SSteve Pricecloses a well-known, and sometimes easily exploitable security 163ea76be72SSteve Pricehole related to poorly thought out 164ea76be72SSteve Price.Ev ENV 165ea76be72SSteve Pricescripts. 166ab72124fSSteve Price.Ss Argument List Processing 167ab72124fSSteve PriceAll of the single letter options to 168ab72124fSSteve Price.Nm 16949e11e3aSSheldon Hearnhave a corresponding long name, 17049e11e3aSSheldon Hearnwith the exception of 17149e11e3aSSheldon Hearn.Fl c 17249e11e3aSSheldon Hearnand 17349e11e3aSSheldon Hearn.Fl /+o . 17449e11e3aSSheldon HearnThese long names are provided next to the single letter options 17549e11e3aSSheldon Hearnin the descriptions below. 17649e11e3aSSheldon HearnThe long name for an option may be specified as an argument to the 17749e11e3aSSheldon Hearn.Fl /+o 17849e11e3aSSheldon Hearnoption of 179facc6767SRuslan Ermilov.Nm . 18049e11e3aSSheldon HearnOnce the shell is running, 18149e11e3aSSheldon Hearnthe long name for an option may be specified as an argument to the 18249e11e3aSSheldon Hearn.Fl /+o 18349e11e3aSSheldon Hearnoption of the 184c644db6aSSheldon Hearn.Ic set 1858eed22b1SJens Schweikhardtbuilt-in command 18649e11e3aSSheldon Hearn(described later in the section called 1878eed22b1SJens Schweikhardt.Sx Built-in Commands ) . 18849e11e3aSSheldon HearnIntroducing an option with a dash 189a762afe5SGiorgos Keramidas.Pq Ql - 19049e11e3aSSheldon Hearnenables the option, 19149e11e3aSSheldon Hearnwhile using a plus 192a762afe5SGiorgos Keramidas.Pq Ql + 19349e11e3aSSheldon Hearndisables the option. 19449e11e3aSSheldon HearnA 19549e11e3aSSheldon Hearn.Dq Li -- 196fab26805SJoseph Koshyor plain 197dfe302abSRuslan Ermilov.Ql - 198fab26805SJoseph Koshywill stop option processing and will force the remaining 199fab26805SJoseph Koshywords on the command line to be treated as arguments. 20049e11e3aSSheldon HearnThe 20149e11e3aSSheldon Hearn.Fl /+o 20249e11e3aSSheldon Hearnand 20349e11e3aSSheldon Hearn.Fl c 20449e11e3aSSheldon Hearnoptions do not have long names. 20549e11e3aSSheldon HearnThey take arguments and are described after the single letter options. 20681e9cda2SRuslan Ermilov.Bl -tag -width indent 207ab72124fSSteve Price.It Fl a Li allexport 20849e11e3aSSheldon HearnFlag variables for export when assignments are made to them. 209ab72124fSSteve Price.It Fl b Li notify 210ab72124fSSteve PriceEnable asynchronous notification of background job 211ab72124fSSteve Pricecompletion. 212c4d9468eSRuslan Ermilov(UNIMPLEMENTED) 213ab72124fSSteve Price.It Fl C Li noclobber 214c644db6aSSheldon HearnDo not overwrite existing files with 215dfe302abSRuslan Ermilov.Ql > . 216ab72124fSSteve Price.It Fl E Li emacs 2178eed22b1SJens SchweikhardtEnable the built-in 218ab72124fSSteve Price.Xr emacs 1 21949e11e3aSSheldon Hearncommand line editor (disables the 220ab72124fSSteve Price.Fl V 221d5f6b530SJilles Tjoelkeroption if it has been set; 222d5f6b530SJilles Tjoelkerset automatically when interactive on terminals). 223ab72124fSSteve Price.It Fl e Li errexit 22449e11e3aSSheldon HearnExit immediately if any untested command fails in non-interactive mode. 2254b88c807SRodney W. GrimesThe exit status of a command is considered to be 22674053659SStefan Farfelederexplicitly tested if the command is part of the list used to control 2278af11131SRuslan Ermilovan 2288af11131SRuslan Ermilov.Ic if , elif , while , 2298af11131SRuslan Ermilovor 2308af11131SRuslan Ermilov.Ic until ; 2318af11131SRuslan Ermilovif the command is the left 232ab72124fSSteve Pricehand operand of an 23349e11e3aSSheldon Hearn.Dq Li && 234ab72124fSSteve Priceor 23549e11e3aSSheldon Hearn.Dq Li || 23674053659SStefan Farfelederoperator; or if the command is a pipeline preceded by the 23774053659SStefan Farfeleder.Ic !\& 238ab72124fSSteve Priceoperator. 23974053659SStefan FarfelederIf a shell function is executed and its exit status is explicitly 24074053659SStefan Farfeledertested, all commands of the function are considered to be tested as 24174053659SStefan Farfelederwell. 242ab72124fSSteve Price.It Fl f Li noglob 2434b88c807SRodney W. GrimesDisable pathname expansion. 244ab72124fSSteve Price.It Fl I Li ignoreeof 24549e11e3aSSheldon HearnIgnore 246dfe302abSRuslan Ermilov.Dv EOF Ap s 24749e11e3aSSheldon Hearnfrom input when in interactive mode. 248ab72124fSSteve Price.It Fl i Li interactive 249ab72124fSSteve PriceForce the shell to behave interactively. 250ab72124fSSteve Price.It Fl m Li monitor 251ab72124fSSteve PriceTurn on job control (set automatically when interactive). 252ab72124fSSteve Price.It Fl n Li noexec 2534b88c807SRodney W. GrimesIf not interactive, read commands but do not 254eccea571SRuslan Ermilovexecute them. 255eccea571SRuslan ErmilovThis is useful for checking the 2564b88c807SRodney W. Grimessyntax of shell scripts. 2577e1975c2STim J. Robbins.It Fl P Li physical 2587e1975c2STim J. RobbinsChange the default for the 2597e1975c2STim J. Robbins.Ic cd 2607e1975c2STim J. Robbinsand 2617e1975c2STim J. Robbins.Ic pwd 2627e1975c2STim J. Robbinscommands from 2637e1975c2STim J. Robbins.Fl L 2647e1975c2STim J. Robbins(logical directory layout) 2657e1975c2STim J. Robbinsto 2667e1975c2STim J. Robbins.Fl P 2677e1975c2STim J. Robbins(physical directory layout). 268ab72124fSSteve Price.It Fl p Li privileged 269eccea571SRuslan ErmilovTurn on privileged mode. 270eccea571SRuslan ErmilovThis mode is enabled on startup 271dfe302abSRuslan Ermilovif either the effective user or group ID is not equal to the 272dfe302abSRuslan Ermilovreal user or group ID. 273eccea571SRuslan ErmilovTurning this mode off sets the 274dfe302abSRuslan Ermiloveffective user and group IDs to the real user and group IDs. 27549e11e3aSSheldon HearnWhen this mode is enabled for interactive shells, the file 276ab72124fSSteve Price.Pa /etc/suid_profile 27749e11e3aSSheldon Hearnis sourced instead of 27849e11e3aSSheldon Hearn.Pa ~/.profile 279ab72124fSSteve Priceafter 280ab72124fSSteve Price.Pa /etc/profile 28149e11e3aSSheldon Hearnis sourced, and the contents of the 282ab72124fSSteve Price.Ev ENV 28349e11e3aSSheldon Hearnvariable are ignored. 284ab72124fSSteve Price.It Fl s Li stdin 2854b88c807SRodney W. GrimesRead commands from standard input (set automatically 286eccea571SRuslan Ermilovif no file arguments are present). 287eccea571SRuslan ErmilovThis option has 2884b88c807SRodney W. Grimesno effect when set after the shell has already started 289eccea571SRuslan Ermilovrunning (i.e., when set with the 290c644db6aSSheldon Hearn.Ic set 2916b15476eSSheldon Hearncommand). 292304199ceSTom Rhodes.It Fl T Li trapsasync 293e6d3cf26SSheldon HearnWhen waiting for a child, execute traps immediately. 294e6d3cf26SSheldon HearnIf this option is not set, 295e6d3cf26SSheldon Hearntraps are executed after the child exits, 296e6d3cf26SSheldon Hearnas specified in 297af5eb6fcSMaxim Konovalov.St -p1003.2 . 2986b15476eSSheldon HearnThis nonstandard option is useful for putting guarding shells around 299eccea571SRuslan Ermilovchildren that block signals. 300eccea571SRuslan ErmilovThe surrounding shell may kill the child 3016b15476eSSheldon Hearnor it may just return control to the tty and leave the child alone, 3026b15476eSSheldon Hearnlike this: 303c1c72a3cSMartin Cracauer.Bd -literal -offset indent 304c1c72a3cSMartin Cracauersh -T -c "trap 'exit 1' 2 ; some-blocking-program" 305c1c72a3cSMartin Cracauer.Ed 306ab72124fSSteve Price.It Fl u Li nounset 307ab72124fSSteve PriceWrite a message to standard error when attempting 30864254a66SJilles Tjoelkerto expand a variable, a positional parameter or 30964254a66SJilles Tjoelkerthe special parameter 31064254a66SJilles Tjoelker.Va \&! 31164254a66SJilles Tjoelkerthat is not set, and if the 312ab72124fSSteve Priceshell is not interactive, exit immediately. 313ab72124fSSteve Price.It Fl V Li vi 3148eed22b1SJens SchweikhardtEnable the built-in 315ab72124fSSteve Price.Xr vi 1 316ab72124fSSteve Pricecommand line editor (disables 317ab72124fSSteve Price.Fl E 318ab72124fSSteve Priceif it has been set). 319ab72124fSSteve Price.It Fl v Li verbose 320ab72124fSSteve PriceThe shell writes its input to standard error 321eccea571SRuslan Ermilovas it is read. 322eccea571SRuslan ErmilovUseful for debugging. 323ab72124fSSteve Price.It Fl x Li xtrace 32449e11e3aSSheldon HearnWrite each command 325120c8e6cSStefan Farfeleder(preceded by the value of the 326dfe302abSRuslan Ermilov.Va PS4 327120c8e6cSStefan Farfeledervariable) 32849e11e3aSSheldon Hearnto standard error before it is executed. 32949e11e3aSSheldon HearnUseful for debugging. 33049e11e3aSSheldon Hearn.El 33149e11e3aSSheldon Hearn.Pp 33249e11e3aSSheldon HearnThe 333fd50df30SRuslan Ermilov.Fl c 334fd50df30SRuslan Ermilovoption causes the commands to be read from the 335fd50df30SRuslan Ermilov.Ar string 336fd50df30SRuslan Ermilovoperand instead of from the standard input. 337fd50df30SRuslan ErmilovKeep in mind that this option only accepts a single string as its 338fd50df30SRuslan Ermilovargument, hence multi-word strings must be quoted. 339fd50df30SRuslan Ermilov.Pp 340fd50df30SRuslan ErmilovThe 34149e11e3aSSheldon Hearn.Fl /+o 34249e11e3aSSheldon Hearnoption takes as its only argument the long name of an option 34349e11e3aSSheldon Hearnto be enabled or disabled. 34449e11e3aSSheldon HearnFor example, the following two invocations of 34549e11e3aSSheldon Hearn.Nm 3468eed22b1SJens Schweikhardtboth enable the built-in 34749e11e3aSSheldon Hearn.Xr emacs 1 34849e11e3aSSheldon Hearncommand line editor: 34949e11e3aSSheldon Hearn.Bd -literal -offset indent 35049e11e3aSSheldon Hearnset -E 35149e11e3aSSheldon Hearnset -o emacs 35249e11e3aSSheldon Hearn.Ed 353d513af6aSTim J. Robbins.Pp 354d513af6aSTim J. RobbinsIf used without an argument, the 355d513af6aSTim J. Robbins.Fl o 356d513af6aSTim J. Robbinsoption displays the current option settings in a human-readable format. 357d513af6aSTim J. RobbinsIf 358d513af6aSTim J. Robbins.Cm +o 359d513af6aSTim J. Robbinsis used without an argument, the current option settings are output 360d513af6aSTim J. Robbinsin a format suitable for re-input into the shell. 361ab72124fSSteve Price.Ss Lexical Structure 3624b88c807SRodney W. GrimesThe shell reads input in terms of lines from a file and breaks 3634b88c807SRodney W. Grimesit up into words at whitespace (blanks and tabs), and at 3644b88c807SRodney W. Grimescertain sequences of 3656b15476eSSheldon Hearncharacters called 3666b15476eSSheldon Hearn.Dq operators , 3676b15476eSSheldon Hearnwhich are special to the shell. 3684b88c807SRodney W. GrimesThere are two types of operators: control operators and 3694b88c807SRodney W. Grimesredirection operators (their meaning is discussed later). 370ab72124fSSteve PriceThe following is a list of valid operators: 37181e9cda2SRuslan Ermilov.Bl -tag -width indent 37249e11e3aSSheldon Hearn.It Control operators: 37349e11e3aSSheldon Hearn.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 37481e9cda2SRuslan Ermilov.It Li & Ta Li && Ta Li ( Ta Li ) Ta Li \en 37581e9cda2SRuslan Ermilov.It Li ;; Ta Li ; Ta Li | Ta Li || 37649e11e3aSSheldon Hearn.El 37749e11e3aSSheldon Hearn.It Redirection operators: 3784682f420SBrian Somers.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 37981e9cda2SRuslan Ermilov.It Li < Ta Li > Ta Li << Ta Li >> Ta Li <> 38081e9cda2SRuslan Ermilov.It Li <& Ta Li >& Ta Li <<- Ta Li >| 38149e11e3aSSheldon Hearn.El 382ab72124fSSteve Price.El 3837d1a55fcSStefan Farfeleder.Pp 3847d1a55fcSStefan FarfelederThe character 3857d1a55fcSStefan Farfeleder.Ql # 3867d1a55fcSStefan Farfelederintroduces a comment if used at the beginning of a word. 3877d1a55fcSStefan FarfelederThe word starting with 3887d1a55fcSStefan Farfeleder.Ql # 3897d1a55fcSStefan Farfelederand the rest of the line are ignored. 3909764aa41SJilles Tjoelker.Pp 3919764aa41SJilles Tjoelker.Tn ASCII 3929764aa41SJilles Tjoelker.Dv NUL 3939764aa41SJilles Tjoelkercharacters (character code 0) are not allowed in shell input. 394ab72124fSSteve Price.Ss Quoting 3954b88c807SRodney W. GrimesQuoting is used to remove the special meaning of certain characters 396a886288eSJesus R. Camouor words to the shell, such as operators, whitespace, keywords, 397a886288eSJesus R. Camouor alias names. 398a886288eSJesus R. Camou.Pp 399eccea571SRuslan ErmilovThere are three types of quoting: matched single quotes, 4004b88c807SRodney W. Grimesmatched double quotes, and backslash. 40181e9cda2SRuslan Ermilov.Bl -tag -width indent 402ab72124fSSteve Price.It Single Quotes 4034b88c807SRodney W. GrimesEnclosing characters in single quotes preserves the literal 404ab0a2172SSteve Pricemeaning of all the characters (except single quotes, making 405ab0a2172SSteve Priceit impossible to put single-quotes in a single-quoted string). 406ab72124fSSteve Price.It Double Quotes 4074b88c807SRodney W. GrimesEnclosing characters within double quotes preserves the literal 40849e11e3aSSheldon Hearnmeaning of all characters except dollar sign 409a762afe5SGiorgos Keramidas.Pq Ql $ , 41049e11e3aSSheldon Hearnbackquote 411a762afe5SGiorgos Keramidas.Pq Ql ` , 41249e11e3aSSheldon Hearnand backslash 413a762afe5SGiorgos Keramidas.Pq Ql \e . 41449e11e3aSSheldon HearnThe backslash inside double quotes is historically weird. 41549e11e3aSSheldon HearnIt remains literal unless it precedes the following characters, 41649e11e3aSSheldon Hearnwhich it serves to quote: 41749e11e3aSSheldon Hearn.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 41881e9cda2SRuslan Ermilov.It Li $ Ta Li ` Ta Li \&" Ta Li \e\ Ta Li \en 41949e11e3aSSheldon Hearn.El 420ab72124fSSteve Price.It Backslash 421ab72124fSSteve PriceA backslash preserves the literal meaning of the following 42249e11e3aSSheldon Hearncharacter, with the exception of the newline character 423a762afe5SGiorgos Keramidas.Pq Ql \en . 42449e11e3aSSheldon HearnA backslash preceding a newline is treated as a line continuation. 425ab72124fSSteve Price.El 426d806a030SJilles Tjoelker.Ss Keywords 427d806a030SJilles TjoelkerKeywords or reserved words are words that have special meaning to the 4284b88c807SRodney W. Grimesshell and are recognized at the beginning of a line and 429eccea571SRuslan Ermilovafter a control operator. 430d806a030SJilles TjoelkerThe following are keywords: 43149e11e3aSSheldon Hearn.Bl -column "doneXX" "elifXX" "elseXX" "untilXX" "whileX" -offset center 43281e9cda2SRuslan Ermilov.It Li \&! Ta { Ta } Ta Ic case Ta Ic do 43381e9cda2SRuslan Ermilov.It Ic done Ta Ic elif Ta Ic else Ta Ic esac Ta Ic fi 43481e9cda2SRuslan Ermilov.It Ic for Ta Ic if Ta Ic then Ta Ic until Ta Ic while 43549e11e3aSSheldon Hearn.El 436ab72124fSSteve Price.Ss Aliases 437ab72124fSSteve PriceAn alias is a name and corresponding value set using the 438c644db6aSSheldon Hearn.Ic alias 439eccea571SRuslan Ermilovbuilt-in command. 440d806a030SJilles TjoelkerWhenever a keyword may occur (see above), 441d806a030SJilles Tjoelkerand after checking for keywords, the shell 442e6d3cf26SSheldon Hearnchecks the word to see if it matches an alias. 443e6d3cf26SSheldon HearnIf it does, it replaces it in the input stream with its value. 444e6d3cf26SSheldon HearnFor example, if there is an alias called 44549e11e3aSSheldon Hearn.Dq Li lf 4466b15476eSSheldon Hearnwith the value 447dfe302abSRuslan Ermilov.Dq Li "ls -F" , 4484b88c807SRodney W. Grimesthen the input 449dfe302abSRuslan Ermilov.Pp 450dfe302abSRuslan Ermilov.Dl "lf foobar" 451ab72124fSSteve Price.Pp 4524b88c807SRodney W. Grimeswould become 453dfe302abSRuslan Ermilov.Pp 454dfe302abSRuslan Ermilov.Dl "ls -F foobar" 455ab72124fSSteve Price.Pp 4564b88c807SRodney W. GrimesAliases provide a convenient way for naive users to 4574b88c807SRodney W. Grimescreate shorthands for commands without having to learn how 458eccea571SRuslan Ermilovto create functions with arguments. 459eccea571SRuslan ErmilovThey can also be 460eccea571SRuslan Ermilovused to create lexically obscure code. 461eccea571SRuslan ErmilovThis use is discouraged. 462a886288eSJesus R. Camou.Pp 463a886288eSJesus R. CamouAn alias name may be escaped in a command line, so that it is not 464a886288eSJesus R. Camoureplaced by its alias value, by using quoting characters within or 46519162ab9SJesus R. Camouadjacent to the alias name. 46619162ab9SJesus R. CamouThis is most often done by prefixing 467a886288eSJesus R. Camouan alias name with a backslash to execute a function, built-in, or 468a886288eSJesus R. Camounormal program with the same name. 469a886288eSJesus R. CamouSee the 470a886288eSJesus R. Camou.Sx Quoting 471a886288eSJesus R. Camousubsection. 472ab72124fSSteve Price.Ss Commands 4734b88c807SRodney W. GrimesThe shell interprets the words it reads according to a 4744b88c807SRodney W. Grimeslanguage, the specification of which is outside the scope 475ab72124fSSteve Priceof this man page (refer to the BNF in the 476ab72124fSSteve Price.St -p1003.2 477eccea571SRuslan Ermilovdocument). 478eccea571SRuslan ErmilovEssentially though, a line is read and if 4794b88c807SRodney W. Grimesthe first word of the line (or after a control operator) 480d806a030SJilles Tjoelkeris not a keyword, then the shell has recognized a 481eccea571SRuslan Ermilovsimple command. 482eccea571SRuslan ErmilovOtherwise, a complex command or some 4834b88c807SRodney W. Grimesother special construct may have been recognized. 484ab72124fSSteve Price.Ss Simple Commands 4854b88c807SRodney W. GrimesIf a simple command has been recognized, the shell performs 4864b88c807SRodney W. Grimesthe following actions: 487ab72124fSSteve Price.Bl -enum 488ab72124fSSteve Price.It 4896b15476eSSheldon HearnLeading words of the form 49049e11e3aSSheldon Hearn.Dq Li name=value 4916b15476eSSheldon Hearnare stripped off and assigned to the environment of 492eccea571SRuslan Ermilovthe simple command. 493eccea571SRuslan ErmilovRedirection operators and 4944b88c807SRodney W. Grimestheir arguments (as described below) are stripped 4954b88c807SRodney W. Grimesoff and saved for processing. 496ab72124fSSteve Price.It 497ab72124fSSteve PriceThe remaining words are expanded as described in 4986b15476eSSheldon Hearnthe section called 4996b15476eSSheldon Hearn.Sx Word Expansions , 5006b15476eSSheldon Hearnand the first remaining word is considered the command 501eccea571SRuslan Ermilovname and the command is located. 502eccea571SRuslan ErmilovThe remaining 5034b88c807SRodney W. Grimeswords are considered the arguments of the command. 5046b15476eSSheldon HearnIf no command name resulted, then the 50549e11e3aSSheldon Hearn.Dq Li name=value 5064b88c807SRodney W. Grimesvariable assignments recognized in 1) affect the 5074b88c807SRodney W. Grimescurrent shell. 508ab72124fSSteve Price.It 509ab72124fSSteve PriceRedirections are performed as described in 5104b88c807SRodney W. Grimesthe next section. 511ab72124fSSteve Price.El 512ab72124fSSteve Price.Ss Redirections 5134b88c807SRodney W. GrimesRedirections are used to change where a command reads its input 514eccea571SRuslan Ermilovor sends its output. 515eccea571SRuslan ErmilovIn general, redirections open, close, or 516eccea571SRuslan Ermilovduplicate an existing reference to a file. 517eccea571SRuslan ErmilovThe overall format 5184b88c807SRodney W. Grimesused for redirection is: 51949e11e3aSSheldon Hearn.Pp 520dfe302abSRuslan Ermilov.D1 Oo Ar n Oc Ar redir-op file 52149e11e3aSSheldon Hearn.Pp 52249e11e3aSSheldon HearnThe 523dfe302abSRuslan Ermilov.Ar redir-op 52449e11e3aSSheldon Hearnis one of the redirection operators mentioned 525eccea571SRuslan Ermilovpreviously. 526eccea571SRuslan ErmilovThe following gives some examples of how these 52749e11e3aSSheldon Hearnoperators can be used. 52849e11e3aSSheldon HearnNote that stdin and stdout are commonly used abbreviations 52949e11e3aSSheldon Hearnfor standard input and standard output respectively. 53049e11e3aSSheldon Hearn.Bl -tag -width "1234567890XX" -offset indent 531dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li > Ar file 532dfe302abSRuslan Ermilovredirect stdout (or file descriptor 533dfe302abSRuslan Ermilov.Ar n ) 534dfe302abSRuslan Ermilovto 535dfe302abSRuslan Ermilov.Ar file 536dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li >| Ar file 53749e11e3aSSheldon Hearnsame as above, but override the 53849e11e3aSSheldon Hearn.Fl C 53949e11e3aSSheldon Hearnoption 540dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li >> Ar file 541dfe302abSRuslan Ermilovappend stdout (or file descriptor 542dfe302abSRuslan Ermilov.Ar n ) 543dfe302abSRuslan Ermilovto 544dfe302abSRuslan Ermilov.Ar file 545dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li < Ar file 546dfe302abSRuslan Ermilovredirect stdin (or file descriptor 547dfe302abSRuslan Ermilov.Ar n ) 548dfe302abSRuslan Ermilovfrom 549dfe302abSRuslan Ermilov.Ar file 550dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li <> Ar file 551dfe302abSRuslan Ermilovredirect stdin (or file descriptor 552dfe302abSRuslan Ermilov.Ar n ) 553dfe302abSRuslan Ermilovto and from 554dfe302abSRuslan Ermilov.Ar file 555dfe302abSRuslan Ermilov.It Oo Ar n1 Oc Ns Li <& Ns Ar n2 556dfe302abSRuslan Ermilovduplicate stdin (or file descriptor 557dfe302abSRuslan Ermilov.Ar n1 ) 558dfe302abSRuslan Ermilovfrom file descriptor 559dfe302abSRuslan Ermilov.Ar n2 560dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li <&- 561dfe302abSRuslan Ermilovclose stdin (or file descriptor 562dfe302abSRuslan Ermilov.Ar n ) 563dfe302abSRuslan Ermilov.It Oo Ar n1 Oc Ns Li >& Ns Ar n2 564dfe302abSRuslan Ermilovduplicate stdout (or file descriptor 565dfe302abSRuslan Ermilov.Ar n1 ) 566dfe302abSRuslan Ermilovto file descriptor 567dfe302abSRuslan Ermilov.Ar n2 568dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li >&- 569dfe302abSRuslan Ermilovclose stdout (or file descriptor 570dfe302abSRuslan Ermilov.Ar n ) 571ab72124fSSteve Price.El 572ab72124fSSteve Price.Pp 5736b15476eSSheldon HearnThe following redirection is often called a 5746b15476eSSheldon Hearn.Dq here-document . 575dfe302abSRuslan Ermilov.Bd -unfilled -offset indent 576dfe302abSRuslan Ermilov.Oo Ar n Oc Ns Li << Ar delimiter 577dfe302abSRuslan Ermilov.D1 Ar here-doc-text 578dfe302abSRuslan Ermilov.D1 ... 579dfe302abSRuslan Ermilov.Ar delimiter 580ab72124fSSteve Price.Ed 581ab72124fSSteve Price.Pp 5824b88c807SRodney W. GrimesAll the text on successive lines up to the delimiter is 5834b88c807SRodney W. Grimessaved away and made available to the command on standard 584dfe302abSRuslan Ermilovinput, or file descriptor 585dfe302abSRuslan Ermilov.Ar n 586dfe302abSRuslan Ermilovif it is specified. 587dfe302abSRuslan ErmilovIf the 588dfe302abSRuslan Ermilov.Ar delimiter 589dfe302abSRuslan Ermilovas specified on the initial line is quoted, then the 590dfe302abSRuslan Ermilov.Ar here-doc-text 5914b88c807SRodney W. Grimesis treated literally, otherwise the text is subjected to 5924b88c807SRodney W. Grimesparameter expansion, command substitution, and arithmetic 5936b15476eSSheldon Hearnexpansion (as described in the section on 5946b15476eSSheldon Hearn.Sx Word Expansions ) . 5956b15476eSSheldon HearnIf the operator is 59649e11e3aSSheldon Hearn.Dq Li <<- 5976b15476eSSheldon Hearninstead of 59849e11e3aSSheldon Hearn.Dq Li << , 5996b15476eSSheldon Hearnthen leading tabs 600dfe302abSRuslan Ermilovin the 601dfe302abSRuslan Ermilov.Ar here-doc-text 602dfe302abSRuslan Ermilovare stripped. 603ab72124fSSteve Price.Ss Search and Execution 604ab0a2172SSteve PriceThere are three types of commands: shell functions, 6058eed22b1SJens Schweikhardtbuilt-in commands, and normal programs. 60649e11e3aSSheldon HearnThe command is searched for (by name) in that order. 60749e11e3aSSheldon HearnThe three types of commands are all executed in a different way. 608ab72124fSSteve Price.Pp 609ab0a2172SSteve PriceWhen a shell function is executed, all of the shell positional 610dfe302abSRuslan Ermilovparameters (except 611dfe302abSRuslan Ermilov.Li $0 , 612dfe302abSRuslan Ermilovwhich remains unchanged) are 6134b88c807SRodney W. Grimesset to the arguments of the shell function. 6144b88c807SRodney W. GrimesThe variables which are explicitly placed in the environment of 6154b88c807SRodney W. Grimesthe command (by placing assignments to them before the 6164b88c807SRodney W. Grimesfunction name) are made local to the function and are set 617e6d3cf26SSheldon Hearnto the values given. 618e6d3cf26SSheldon HearnThen the command given in the function definition is executed. 619e6d3cf26SSheldon HearnThe positional parameters are restored to their original values 620e6d3cf26SSheldon Hearnwhen the command completes. 621ab0a2172SSteve PriceThis all occurs within the current shell. 622ab72124fSSteve Price.Pp 6238eed22b1SJens SchweikhardtShell built-in commands are executed internally to the shell, without 624ab0a2172SSteve Pricespawning a new process. 62530268dfaSJilles TjoelkerThere are two kinds of built-in commands: regular and special. 62630268dfaSJilles TjoelkerAssignments before special builtins persist after they finish 62730268dfaSJilles Tjoelkerexecuting and assignment errors, redirection errors and certain 62830268dfaSJilles Tjoelkeroperand errors cause a script to be aborted. 6294b985a89SJilles TjoelkerSpecial builtins cannot be overridden with a function. 63030268dfaSJilles TjoelkerBoth regular and special builtins can affect the shell in ways 63130268dfaSJilles Tjoelkernormal programs cannot. 632ab72124fSSteve Price.Pp 633c644db6aSSheldon HearnOtherwise, if the command name does not match a function 6348eed22b1SJens Schweikhardtor built-in command, the command is searched for as a normal 6354b88c807SRodney W. Grimesprogram in the file system (as described in the next section). 6364b88c807SRodney W. GrimesWhen a normal program is executed, the shell runs the program, 637e6d3cf26SSheldon Hearnpassing the arguments and the environment to the program. 638e6d3cf26SSheldon HearnIf the program is not a normal executable file 639eccea571SRuslan Ermilov(i.e., if it does not begin with the 640dfe302abSRuslan Ermilov.Dq "magic number" 6416b15476eSSheldon Hearnwhose 642ab72124fSSteve Price.Tn ASCII 6436b15476eSSheldon Hearnrepresentation is 644dfe302abSRuslan Ermilov.Dq Li #! , 64549e11e3aSSheldon Hearnresulting in an 646b4f0f4aaSRuslan Ermilov.Er ENOEXEC 64749e11e3aSSheldon Hearnreturn value from 64849e11e3aSSheldon Hearn.Xr execve 2 ) 649e6d3cf26SSheldon Hearnthe shell will interpret the program in a subshell. 650e6d3cf26SSheldon HearnThe child shell will reinitialize itself in this case, 651e6d3cf26SSheldon Hearnso that the effect will be 652e6d3cf26SSheldon Hearnas if a new shell had been invoked to handle the ad-hoc shell script, 653e6d3cf26SSheldon Hearnexcept that the location of hashed commands located in 654dfe302abSRuslan Ermilovthe parent shell will be remembered by the child 655dfe302abSRuslan Ermilov(see the description of the 656dfe302abSRuslan Ermilov.Ic hash 657dfe302abSRuslan Ermilovbuilt-in command below). 658ab72124fSSteve Price.Pp 659ab0a2172SSteve PriceNote that previous versions of this document 660ab0a2172SSteve Priceand the source code itself misleadingly and sporadically 661ab0a2172SSteve Pricerefer to a shell script without a magic number 6626b15476eSSheldon Hearnas a 663dfe302abSRuslan Ermilov.Dq "shell procedure" . 664ab72124fSSteve Price.Ss Path Search 6654b88c807SRodney W. GrimesWhen locating a command, the shell first looks to see if 666eccea571SRuslan Ermilovit has a shell function by that name. 667eccea571SRuslan ErmilovThen it looks for a 668eccea571SRuslan Ermilovbuilt-in command by that name. 669eccea571SRuslan ErmilovIf a built-in command is not found, 670ab0a2172SSteve Priceone of two things happen: 671ab72124fSSteve Price.Bl -enum 672ab72124fSSteve Price.It 673ab72124fSSteve PriceCommand names containing a slash are simply executed without 674ab0a2172SSteve Priceperforming any searches. 675ab72124fSSteve Price.It 676dfe302abSRuslan ErmilovThe shell searches each entry in the 6771788b7ffSJilles Tjoelker.Va PATH 6781788b7ffSJilles Tjoelkervariable 679eccea571SRuslan Ermilovin turn for the command. 680eccea571SRuslan ErmilovThe value of the 6811788b7ffSJilles Tjoelker.Va PATH 682ab72124fSSteve Pricevariable should be a series of 683eccea571SRuslan Ermiloventries separated by colons. 684eccea571SRuslan ErmilovEach entry consists of a 6854b88c807SRodney W. Grimesdirectory name. 6864b88c807SRodney W. GrimesThe current directory 687ab0a2172SSteve Pricemay be indicated implicitly by an empty directory name, 688ab0a2172SSteve Priceor explicitly by a single period. 689ab72124fSSteve Price.El 690ab72124fSSteve Price.Ss Command Exit Status 6914b88c807SRodney W. GrimesEach command has an exit status that can influence the behavior 692eccea571SRuslan Ermilovof other shell commands. 693eccea571SRuslan ErmilovThe paradigm is that a command exits 6944b88c807SRodney W. Grimeswith zero for normal or success, and non-zero for failure, 695eccea571SRuslan Ermiloverror, or a false indication. 696eccea571SRuslan ErmilovThe man page for each command 6974b88c807SRodney W. Grimesshould indicate the various exit codes and what they mean. 6988eed22b1SJens SchweikhardtAdditionally, the built-in commands return exit codes, as does 699ab0a2172SSteve Pricean executed shell function. 700c351e089SJohn Polstra.Pp 701c351e089SJohn PolstraIf a command is terminated by a signal, its exit status is 128 plus 702eccea571SRuslan Ermilovthe signal number. 703eccea571SRuslan ErmilovSignal numbers are defined in the header file 704fe08efe6SRuslan Ermilov.In sys/signal.h . 705ab72124fSSteve Price.Ss Complex Commands 7064b88c807SRodney W. GrimesComplex commands are combinations of simple commands 707d806a030SJilles Tjoelkerwith control operators or keywords, together creating a larger complex 708eccea571SRuslan Ermilovcommand. 709eccea571SRuslan ErmilovMore generally, a command is one of the following: 710ab72124fSSteve Price.Bl -item -offset indent 711ab72124fSSteve Price.It 712ab72124fSSteve Pricesimple command 713ab72124fSSteve Price.It 714ab72124fSSteve Pricepipeline 715ab72124fSSteve Price.It 716ab72124fSSteve Pricelist or compound-list 717ab72124fSSteve Price.It 718ab72124fSSteve Pricecompound command 719ab72124fSSteve Price.It 720ab72124fSSteve Pricefunction definition 721ab72124fSSteve Price.El 722ab72124fSSteve Price.Pp 7234b88c807SRodney W. GrimesUnless otherwise stated, the exit status of a command is 7244b88c807SRodney W. Grimesthat of the last simple command executed by the command. 725ab72124fSSteve Price.Ss Pipelines 7264b88c807SRodney W. GrimesA pipeline is a sequence of one or more commands separated 727dfe302abSRuslan Ermilovby the control operator 728dfe302abSRuslan Ermilov.Ql \&| . 729eccea571SRuslan ErmilovThe standard output of all but 7304b88c807SRodney W. Grimesthe last command is connected to the standard input 731eccea571SRuslan Ermilovof the next command. 732eccea571SRuslan ErmilovThe standard output of the last 733ab0a2172SSteve Pricecommand is inherited from the shell, as usual. 734ab72124fSSteve Price.Pp 7354b88c807SRodney W. GrimesThe format for a pipeline is: 73649e11e3aSSheldon Hearn.Pp 737dfe302abSRuslan Ermilov.D1 Oo Li \&! Oc Ar command1 Op Li \&| Ar command2 ... 738ab72124fSSteve Price.Pp 739dfe302abSRuslan ErmilovThe standard output of 740dfe302abSRuslan Ermilov.Ar command1 741dfe302abSRuslan Ermilovis connected to the standard input of 742dfe302abSRuslan Ermilov.Ar command2 . 743eccea571SRuslan ErmilovThe standard input, standard output, or 7444b88c807SRodney W. Grimesboth of a command is considered to be assigned by the 7454b88c807SRodney W. Grimespipeline before any redirection specified by redirection 7464b88c807SRodney W. Grimesoperators that are part of the command. 747ab72124fSSteve Price.Pp 748f1ec0581SJilles TjoelkerNote that unlike some other shells, 749f1ec0581SJilles Tjoelker.Nm 750f1ec0581SJilles Tjoelkerexecutes each process in a pipeline with more than one command 751f1ec0581SJilles Tjoelkerin a subshell environment and as a child of the 752f1ec0581SJilles Tjoelker.Nm 753f1ec0581SJilles Tjoelkerprocess. 754f1ec0581SJilles Tjoelker.Pp 7554b88c807SRodney W. GrimesIf the pipeline is not in the background (discussed later), 7564b88c807SRodney W. Grimesthe shell waits for all commands to complete. 757ab72124fSSteve Price.Pp 758d806a030SJilles TjoelkerIf the keyword 759eccea571SRuslan Ermilov.Ic !\& 760eccea571SRuslan Ermilovdoes not precede the pipeline, the 7614b88c807SRodney W. Grimesexit status is the exit status of the last command specified 762eccea571SRuslan Ermilovin the pipeline. 763eccea571SRuslan ErmilovOtherwise, the exit status is the logical 764eccea571SRuslan ErmilovNOT of the exit status of the last command. 765eccea571SRuslan ErmilovThat is, if 7664b88c807SRodney W. Grimesthe last command returns zero, the exit status is 1; if 7674b88c807SRodney W. Grimesthe last command returns greater than zero, the exit status 7684b88c807SRodney W. Grimesis zero. 769ab72124fSSteve Price.Pp 7704b88c807SRodney W. GrimesBecause pipeline assignment of standard input or standard 7714b88c807SRodney W. Grimesoutput or both takes place before redirection, it can be 772eccea571SRuslan Ermilovmodified by redirection. 773eccea571SRuslan ErmilovFor example: 774ab72124fSSteve Price.Pp 775dfe302abSRuslan Ermilov.Dl "command1 2>&1 | command2" 776ab72124fSSteve Price.Pp 77749e11e3aSSheldon Hearnsends both the standard output and standard error of 778dfe302abSRuslan Ermilov.Ar command1 77949e11e3aSSheldon Hearnto the standard input of 780dfe302abSRuslan Ermilov.Ar command2 . 78149e11e3aSSheldon Hearn.Pp 78249e11e3aSSheldon HearnA 783dfe302abSRuslan Ermilov.Ql \&; 78449e11e3aSSheldon Hearnor newline terminator causes the preceding 785e918fc8fSSheldon HearnAND-OR-list 786e918fc8fSSheldon Hearn(described below in the section called 787e918fc8fSSheldon Hearn.Sx Short-Circuit List Operators ) 788e918fc8fSSheldon Hearnto be executed sequentially; 789e918fc8fSSheldon Hearnan 790dfe302abSRuslan Ermilov.Ql & 791e918fc8fSSheldon Hearncauses asynchronous execution of the preceding AND-OR-list. 79249e11e3aSSheldon Hearn.Ss Background Commands (&) 7934b88c807SRodney W. GrimesIf a command is terminated by the control operator ampersand 794a762afe5SGiorgos Keramidas.Pq Ql & , 79549e11e3aSSheldon Hearnthe shell executes the command asynchronously; 79649e11e3aSSheldon Hearnthe shell does not wait for the command to finish 79749e11e3aSSheldon Hearnbefore executing the next command. 798ab72124fSSteve Price.Pp 7994b88c807SRodney W. GrimesThe format for running a command in background is: 800dfe302abSRuslan Ermilov.Pp 801dfe302abSRuslan Ermilov.D1 Ar command1 Li & Op Ar command2 Li & Ar ... 802ab72124fSSteve Price.Pp 8034b88c807SRodney W. GrimesIf the shell is not interactive, the standard input of an 804dfe302abSRuslan Ermilovasynchronous command is set to 805dfe302abSRuslan Ermilov.Pa /dev/null . 80649e11e3aSSheldon Hearn.Ss Lists (Generally Speaking) 8074b88c807SRodney W. GrimesA list is a sequence of zero or more commands separated by 8084b88c807SRodney W. Grimesnewlines, semicolons, or ampersands, 8094b88c807SRodney W. Grimesand optionally terminated by one of these three characters. 8104b88c807SRodney W. GrimesThe commands in a 8114b88c807SRodney W. Grimeslist are executed in the order they are written. 8124b88c807SRodney W. GrimesIf command is followed by an ampersand, the shell starts the 8138eed22b1SJens Schweikhardtcommand and immediately proceeds onto the next command; 8144b88c807SRodney W. Grimesotherwise it waits for the command to terminate before 8154b88c807SRodney W. Grimesproceeding to the next one. 816ab72124fSSteve Price.Ss Short-Circuit List Operators 81749e11e3aSSheldon Hearn.Dq Li && 8186b15476eSSheldon Hearnand 81949e11e3aSSheldon Hearn.Dq Li || 8206b15476eSSheldon Hearnare AND-OR list operators. 82149e11e3aSSheldon Hearn.Dq Li && 8226b15476eSSheldon Hearnexecutes the first command, and then executes the second command 8236b15476eSSheldon Hearnif the exit status of the first command is zero. 82449e11e3aSSheldon Hearn.Dq Li || 825120ac26dSMasafumi Max NAKANEis similar, but executes the second command if the exit 8266b15476eSSheldon Hearnstatus of the first command is nonzero. 82749e11e3aSSheldon Hearn.Dq Li && 8286b15476eSSheldon Hearnand 82949e11e3aSSheldon Hearn.Dq Li || 8304b88c807SRodney W. Grimesboth have the same priority. 83149e11e3aSSheldon Hearn.Ss Flow-Control Constructs (if, while, for, case) 83249e11e3aSSheldon HearnThe syntax of the 83349e11e3aSSheldon Hearn.Ic if 83449e11e3aSSheldon Hearncommand is: 835dfe302abSRuslan Ermilov.Bd -unfilled -offset indent -compact 836dfe302abSRuslan Ermilov.Ic if Ar list 837dfe302abSRuslan Ermilov.Ic then Ar list 838dfe302abSRuslan Ermilov.Oo Ic elif Ar list 839dfe302abSRuslan Ermilov.Ic then Ar list Oc Ar ... 840dfe302abSRuslan Ermilov.Op Ic else Ar list 841dfe302abSRuslan Ermilov.Ic fi 842dfe302abSRuslan Ermilov.Ed 843ab72124fSSteve Price.Pp 84449e11e3aSSheldon HearnThe syntax of the 84549e11e3aSSheldon Hearn.Ic while 84649e11e3aSSheldon Hearncommand is: 847dfe302abSRuslan Ermilov.Bd -unfilled -offset indent -compact 848dfe302abSRuslan Ermilov.Ic while Ar list 849dfe302abSRuslan Ermilov.Ic do Ar list 850dfe302abSRuslan Ermilov.Ic done 851dfe302abSRuslan Ermilov.Ed 852ab72124fSSteve Price.Pp 853ab0a2172SSteve PriceThe two lists are executed repeatedly while the exit status of the 85449e11e3aSSheldon Hearnfirst list is zero. 85549e11e3aSSheldon HearnThe 85649e11e3aSSheldon Hearn.Ic until 85749e11e3aSSheldon Hearncommand is similar, but has the word 85849e11e3aSSheldon Hearn.Ic until 85949e11e3aSSheldon Hearnin place of 86049e11e3aSSheldon Hearn.Ic while , 86149e11e3aSSheldon Hearnwhich causes it to 8624b88c807SRodney W. Grimesrepeat until the exit status of the first list is zero. 863ab72124fSSteve Price.Pp 86449e11e3aSSheldon HearnThe syntax of the 86549e11e3aSSheldon Hearn.Ic for 86649e11e3aSSheldon Hearncommand is: 867dfe302abSRuslan Ermilov.Bd -unfilled -offset indent -compact 868dfe302abSRuslan Ermilov.Ic for Ar variable Op Ic in Ar word ... 869dfe302abSRuslan Ermilov.Ic do Ar list 870dfe302abSRuslan Ermilov.Ic done 871dfe302abSRuslan Ermilov.Ed 872ab72124fSSteve Price.Pp 873a01459dfSStefan FarfelederIf 874a01459dfSStefan Farfeleder.Ic in 8757b14d37fSRalf S. Engelschalland the following words are omitted, 876776e6b33SJilles Tjoelker.Ic in Li \&"$@\&" 877a01459dfSStefan Farfelederis used instead. 8784b88c807SRodney W. GrimesThe words are expanded, and then the list is executed 87949e11e3aSSheldon Hearnrepeatedly with the variable set to each word in turn. 88049e11e3aSSheldon HearnThe 88149e11e3aSSheldon Hearn.Ic do 8826b15476eSSheldon Hearnand 88349e11e3aSSheldon Hearn.Ic done 88449e11e3aSSheldon Hearncommands may be replaced with 885dfe302abSRuslan Ermilov.Ql { 88649e11e3aSSheldon Hearnand 887dfe302abSRuslan Ermilov.Ql } . 888ab72124fSSteve Price.Pp 88949e11e3aSSheldon HearnThe syntax of the 89049e11e3aSSheldon Hearn.Ic break 89149e11e3aSSheldon Hearnand 89249e11e3aSSheldon Hearn.Ic continue 89349e11e3aSSheldon Hearncommands is: 894dfe302abSRuslan Ermilov.D1 Ic break Op Ar num 895dfe302abSRuslan Ermilov.D1 Ic continue Op Ar num 896ab72124fSSteve Price.Pp 89749e11e3aSSheldon HearnThe 89849e11e3aSSheldon Hearn.Ic break 89949e11e3aSSheldon Hearncommand terminates the 90049e11e3aSSheldon Hearn.Ar num 90149e11e3aSSheldon Hearninnermost 90249e11e3aSSheldon Hearn.Ic for 90349e11e3aSSheldon Hearnor 90449e11e3aSSheldon Hearn.Ic while 90549e11e3aSSheldon Hearnloops. 90649e11e3aSSheldon HearnThe 90749e11e3aSSheldon Hearn.Ic continue 90849e11e3aSSheldon Hearncommand continues with the next iteration of the innermost loop. 90930268dfaSJilles TjoelkerThese are implemented as special built-in commands. 910ab72124fSSteve Price.Pp 91149e11e3aSSheldon HearnThe syntax of the 91249e11e3aSSheldon Hearn.Ic case 913dfe302abSRuslan Ermilovcommand is: 914dfe302abSRuslan Ermilov.Bd -unfilled -offset indent -compact 915dfe302abSRuslan Ermilov.Ic case Ar word Ic in 916dfe302abSRuslan Ermilov.Ar pattern Ns Li ) Ar list Li ;; 917dfe302abSRuslan Ermilov.Ar ... 918dfe302abSRuslan Ermilov.Ic esac 919dfe302abSRuslan Ermilov.Ed 920ab72124fSSteve Price.Pp 92149e11e3aSSheldon HearnThe pattern can actually be one or more patterns 92249e11e3aSSheldon Hearn(see 92349e11e3aSSheldon Hearn.Sx Shell Patterns 92449e11e3aSSheldon Hearndescribed later), 92549e11e3aSSheldon Hearnseparated by 926dfe302abSRuslan Ermilov.Ql \&| 9276b15476eSSheldon Hearncharacters. 928aafd6a87SStefan FarfelederThe exit code of the 929aafd6a87SStefan Farfeleder.Ic case 930aafd6a87SStefan Farfeledercommand is the exit code of the last command executed in the list or 931aafd6a87SStefan Farfelederzero if no patterns were matched. 932ab72124fSSteve Price.Ss Grouping Commands Together 9334b88c807SRodney W. GrimesCommands may be grouped by writing either 934dfe302abSRuslan Ermilov.Pp 935dfe302abSRuslan Ermilov.D1 Li \&( Ns Ar list Ns Li \%) 936ab72124fSSteve Price.Pp 9374b88c807SRodney W. Grimesor 938dfe302abSRuslan Ermilov.Pp 939dfe302abSRuslan Ermilov.D1 Li { Ar list Ns Li \&; } 940ab72124fSSteve Price.Pp 94149e11e3aSSheldon HearnThe first form executes the commands in a subshell. 9428eed22b1SJens SchweikhardtNote that built-in commands thus executed do not affect the current shell. 94349e11e3aSSheldon HearnThe second form does not fork another shell, 94449e11e3aSSheldon Hearnso it is slightly more efficient. 94549e11e3aSSheldon HearnGrouping commands together this way allows the user to 946ab0a2172SSteve Priceredirect their output as though they were one program: 947ab72124fSSteve Price.Bd -literal -offset indent 948ee7dc416SSteve Price{ echo -n "hello"; echo " world"; } > greeting 949ab72124fSSteve Price.Ed 950ab72124fSSteve Price.Ss Functions 9514b88c807SRodney W. GrimesThe syntax of a function definition is 952dfe302abSRuslan Ermilov.Pp 953dfe302abSRuslan Ermilov.D1 Ar name Li \&( \&) Ar command 954ab72124fSSteve Price.Pp 9554b88c807SRodney W. GrimesA function definition is an executable statement; when 956dfe302abSRuslan Ermilovexecuted it installs a function named 957dfe302abSRuslan Ermilov.Ar name 958dfe302abSRuslan Ermilovand returns an 959eccea571SRuslan Ermilovexit status of zero. 960dfe302abSRuslan ErmilovThe 961dfe302abSRuslan Ermilov.Ar command 962dfe302abSRuslan Ermilovis normally a list 9636b15476eSSheldon Hearnenclosed between 964dfe302abSRuslan Ermilov.Ql { 9656b15476eSSheldon Hearnand 966dfe302abSRuslan Ermilov.Ql } . 967ab72124fSSteve Price.Pp 9684b88c807SRodney W. GrimesVariables may be declared to be local to a function by 96949e11e3aSSheldon Hearnusing the 97049e11e3aSSheldon Hearn.Ic local 97149e11e3aSSheldon Hearncommand. 97249e11e3aSSheldon HearnThis should appear as the first statement of a function, 97349e11e3aSSheldon Hearnand the syntax is: 974dfe302abSRuslan Ermilov.Pp 975dfe302abSRuslan Ermilov.D1 Ic local Oo Ar variable ... Oc Op Fl 976ab72124fSSteve Price.Pp 97749e11e3aSSheldon HearnThe 97849e11e3aSSheldon Hearn.Ic local 9798eed22b1SJens Schweikhardtcommand is implemented as a built-in command. 980ab72124fSSteve Price.Pp 9814b88c807SRodney W. GrimesWhen a variable is made local, it inherits the initial 9824b88c807SRodney W. Grimesvalue and exported and readonly flags from the variable 9834b88c807SRodney W. Grimeswith the same name in the surrounding scope, if there is 984eccea571SRuslan Ermilovone. 985eccea571SRuslan ErmilovOtherwise, the variable is initially unset. 986eccea571SRuslan ErmilovThe shell 987e918fc8fSSheldon Hearnuses dynamic scoping, so that if the variable 988dfe302abSRuslan Ermilov.Va x 989e918fc8fSSheldon Hearnis made local to function 990e918fc8fSSheldon Hearn.Em f , 991e918fc8fSSheldon Hearnwhich then calls function 992e918fc8fSSheldon Hearn.Em g , 993e918fc8fSSheldon Hearnreferences to the variable 994dfe302abSRuslan Ermilov.Va x 995e918fc8fSSheldon Hearnmade inside 996e918fc8fSSheldon Hearn.Em g 997e918fc8fSSheldon Hearnwill refer to the variable 998dfe302abSRuslan Ermilov.Va x 999e918fc8fSSheldon Hearndeclared inside 1000e918fc8fSSheldon Hearn.Em f , 1001e918fc8fSSheldon Hearnnot to the global variable named 1002dfe302abSRuslan Ermilov.Va x . 1003ab72124fSSteve Price.Pp 10046b4bbd8aSCeri DaviesThe only special parameter that can be made local is 1005dfe302abSRuslan Ermilov.Ql - . 10066b15476eSSheldon HearnMaking 1007dfe302abSRuslan Ermilov.Ql - 10086b15476eSSheldon Hearnlocal causes any shell options that are 1009dfe302abSRuslan Ermilovchanged via the 1010dfe302abSRuslan Ermilov.Ic set 1011dfe302abSRuslan Ermilovcommand inside the function to be 10124b88c807SRodney W. Grimesrestored to their original values when the function 10134b88c807SRodney W. Grimesreturns. 1014ab72124fSSteve Price.Pp 101549e11e3aSSheldon HearnThe syntax of the 101649e11e3aSSheldon Hearn.Ic return 101749e11e3aSSheldon Hearncommand is 1018dfe302abSRuslan Ermilov.Pp 1019dfe302abSRuslan Ermilov.D1 Ic return Op Ar exitstatus 1020ab72124fSSteve Price.Pp 10214ad8968aSBrian FeldmanIt terminates the current executional scope, returning from the previous 10224ad8968aSBrian Feldmannested function, sourced script, or shell instance, in that order. 102349e11e3aSSheldon HearnThe 102449e11e3aSSheldon Hearn.Ic return 102530268dfaSJilles Tjoelkercommand is implemented as a special built-in command. 1026ab72124fSSteve Price.Ss Variables and Parameters 1027eccea571SRuslan ErmilovThe shell maintains a set of parameters. 1028eccea571SRuslan ErmilovA parameter 1029eccea571SRuslan Ermilovdenoted by a name is called a variable. 1030eccea571SRuslan ErmilovWhen starting up, 10314b88c807SRodney W. Grimesthe shell turns all the environment variables into shell 1032eccea571SRuslan Ermilovvariables. 1033eccea571SRuslan ErmilovNew variables can be set using the form 1034dfe302abSRuslan Ermilov.Pp 1035dfe302abSRuslan Ermilov.D1 Ar name Ns = Ns Ar value 1036ab72124fSSteve Price.Pp 10374b88c807SRodney W. GrimesVariables set by the user must have a name consisting solely 103849e11e3aSSheldon Hearnof alphabetics, numerics, and underscores. 103949e11e3aSSheldon HearnThe first letter of a variable name must not be numeric. 104049e11e3aSSheldon HearnA parameter can also be denoted by a number 10414b88c807SRodney W. Grimesor a special character as explained below. 1042ab72124fSSteve Price.Ss Positional Parameters 104349e11e3aSSheldon HearnA positional parameter is a parameter denoted by a number greater than zero. 1044ab72124fSSteve PriceThe shell sets these initially to the values of its command line 1045eccea571SRuslan Ermilovarguments that follow the name of the shell script. 1046eccea571SRuslan ErmilovThe 1047c644db6aSSheldon Hearn.Ic set 10488eed22b1SJens Schweikhardtbuilt-in command can also be used to set or reset them. 1049ab72124fSSteve Price.Ss Special Parameters 1050626a7b1dSJilles TjoelkerSpecial parameters are parameters denoted by a single special character 1051626a7b1dSJilles Tjoelkeror the digit zero. 1052626a7b1dSJilles TjoelkerThey are shown in the following list, exactly as they would appear in input 105343d6677bSAlfred Perlsteintyped by the user or in the source of a shell script. 1054ab72124fSSteve Price.Bl -hang 105543d6677bSAlfred Perlstein.It Li $* 1056eccea571SRuslan ErmilovExpands to the positional parameters, starting from one. 1057eccea571SRuslan ErmilovWhen 10584b88c807SRodney W. Grimesthe expansion occurs within a double-quoted string 10594b88c807SRodney W. Grimesit expands to a single field with the value of each parameter 106049e11e3aSSheldon Hearnseparated by the first character of the 1061dfe302abSRuslan Ermilov.Va IFS 106249e11e3aSSheldon Hearnvariable, 1063dfe302abSRuslan Ermilovor by a space if 1064dfe302abSRuslan Ermilov.Va IFS 106549e11e3aSSheldon Hearnis unset. 106643d6677bSAlfred Perlstein.It Li $@ 1067eccea571SRuslan ErmilovExpands to the positional parameters, starting from one. 1068eccea571SRuslan ErmilovWhen 10694b88c807SRodney W. Grimesthe expansion occurs within double-quotes, each positional 10704b88c807SRodney W. Grimesparameter expands as a separate argument. 10714b88c807SRodney W. GrimesIf there are no positional parameters, the 1072e918fc8fSSheldon Hearnexpansion of 1073e918fc8fSSheldon Hearn.Li @ 1074e918fc8fSSheldon Hearngenerates zero arguments, even when 1075e918fc8fSSheldon Hearn.Li @ 1076eccea571SRuslan Ermilovis double-quoted. 1077eccea571SRuslan ErmilovWhat this basically means, for example, is 1078dfe302abSRuslan Ermilovif 1079dfe302abSRuslan Ermilov.Li $1 1080dfe302abSRuslan Ermilovis 1081dfe302abSRuslan Ermilov.Dq Li abc 1082dfe302abSRuslan Ermilovand 1083dfe302abSRuslan Ermilov.Li $2 1084dfe302abSRuslan Ermilovis 1085dfe302abSRuslan Ermilov.Dq Li "def ghi" , 10866b15476eSSheldon Hearnthen 1087776e6b33SJilles Tjoelker.Li \&"$@\&" 10886b15476eSSheldon Hearnexpands to 10894b88c807SRodney W. Grimesthe two arguments: 1090ab72124fSSteve Price.Bd -literal -offset indent 10914b88c807SRodney W. Grimes"abc" "def ghi" 1092ab72124fSSteve Price.Ed 109343d6677bSAlfred Perlstein.It Li $# 10944b88c807SRodney W. GrimesExpands to the number of positional parameters. 1095dfe302abSRuslan Ermilov.It Li $? 10964b88c807SRodney W. GrimesExpands to the exit status of the most recent pipeline. 109743d6677bSAlfred Perlstein.It Li $- 1098ab72124fSSteve Price(hyphen) Expands to the current option flags (the single-letter 10994b88c807SRodney W. Grimesoption names concatenated into a string) as specified on 1100dfe302abSRuslan Ermilovinvocation, by the 1101dfe302abSRuslan Ermilov.Ic set 1102dfe302abSRuslan Ermilovbuilt-in command, or implicitly 11034b88c807SRodney W. Grimesby the shell. 110443d6677bSAlfred Perlstein.It Li $$ 1105eccea571SRuslan ErmilovExpands to the process ID of the invoked shell. 1106eccea571SRuslan ErmilovA subshell 1107dfe302abSRuslan Ermilovretains the same value of 1108dfe302abSRuslan Ermilov.Va $ 1109dfe302abSRuslan Ermilovas its parent. 1110dfe302abSRuslan Ermilov.It Li $! 11114b88c807SRodney W. GrimesExpands to the process ID of the most recent background 1112eccea571SRuslan Ermilovcommand executed from the current shell. 1113eccea571SRuslan ErmilovFor a 11144b88c807SRodney W. Grimespipeline, the process ID is that of the last command in the 11154b88c807SRodney W. Grimespipeline. 1116ed4c3b5fSJilles TjoelkerIf this parameter is referenced, the shell will remember 1117ed4c3b5fSJilles Tjoelkerthe process ID and its exit status until the 1118ed4c3b5fSJilles Tjoelker.Ic wait 1119ed4c3b5fSJilles Tjoelkerbuilt-in command reports completion of the process. 112043d6677bSAlfred Perlstein.It Li $0 112157a40f7dSJilles Tjoelker(zero) Expands to the name of the shell script if passed on the command line, 112257a40f7dSJilles Tjoelkerthe 112357a40f7dSJilles Tjoelker.Ar name 112457a40f7dSJilles Tjoelkeroperand if given (with 112557a40f7dSJilles Tjoelker.Fl c ) 112657a40f7dSJilles Tjoelkeror otherwise argument 0 passed to the shell. 1127ab72124fSSteve Price.El 11281788b7ffSJilles Tjoelker.Ss Special Variables 11291788b7ffSJilles TjoelkerThe following variables are set by the shell or 11301788b7ffSJilles Tjoelkerhave special meaning to it: 11311788b7ffSJilles Tjoelker.Bl -tag -width ".Va HISTSIZE" 11321788b7ffSJilles Tjoelker.It Va CDPATH 11331788b7ffSJilles TjoelkerThe search path used with the 11341788b7ffSJilles Tjoelker.Ic cd 11351788b7ffSJilles Tjoelkerbuilt-in. 11361788b7ffSJilles Tjoelker.It Va EDITOR 11371788b7ffSJilles TjoelkerThe fallback editor used with the 11381788b7ffSJilles Tjoelker.Ic fc 11391788b7ffSJilles Tjoelkerbuilt-in. 11401788b7ffSJilles TjoelkerIf not set, the default editor is 11411788b7ffSJilles Tjoelker.Xr ed 1 . 11421788b7ffSJilles Tjoelker.It Va FCEDIT 11431788b7ffSJilles TjoelkerThe default editor used with the 11441788b7ffSJilles Tjoelker.Ic fc 11451788b7ffSJilles Tjoelkerbuilt-in. 11461788b7ffSJilles Tjoelker.It Va HISTSIZE 11471788b7ffSJilles TjoelkerThe number of previous commands that are accessible. 11481788b7ffSJilles Tjoelker.It Va HOME 11491788b7ffSJilles TjoelkerThe user's home directory, 11501788b7ffSJilles Tjoelkerused in tilde expansion and as a default directory for the 11511788b7ffSJilles Tjoelker.Ic cd 11521788b7ffSJilles Tjoelkerbuilt-in. 11531788b7ffSJilles Tjoelker.It Va IFS 11541788b7ffSJilles TjoelkerInput Field Separators. 11551788b7ffSJilles TjoelkerThis is normally set to 11561788b7ffSJilles Tjoelker.Aq space , 11571788b7ffSJilles Tjoelker.Aq tab , 11581788b7ffSJilles Tjoelkerand 11591788b7ffSJilles Tjoelker.Aq newline . 11601788b7ffSJilles TjoelkerSee the 11611788b7ffSJilles Tjoelker.Sx White Space Splitting 11621788b7ffSJilles Tjoelkersection for more details. 11631788b7ffSJilles Tjoelker.It Va LINENO 11641788b7ffSJilles TjoelkerThe current line number in the script or function. 11651788b7ffSJilles Tjoelker.It Va MAIL 11661788b7ffSJilles TjoelkerThe name of a mail file, that will be checked for the arrival of new 11671788b7ffSJilles Tjoelkermail. 11681788b7ffSJilles TjoelkerOverridden by 11691788b7ffSJilles Tjoelker.Va MAILPATH . 11701788b7ffSJilles Tjoelker.It Va MAILPATH 11711788b7ffSJilles TjoelkerA colon 11721788b7ffSJilles Tjoelker.Pq Ql \&: 11731788b7ffSJilles Tjoelkerseparated list of file names, for the shell to check for incoming 11741788b7ffSJilles Tjoelkermail. 11751788b7ffSJilles TjoelkerThis variable overrides the 11761788b7ffSJilles Tjoelker.Va MAIL 11771788b7ffSJilles Tjoelkersetting. 11781788b7ffSJilles TjoelkerThere is a maximum of 10 mailboxes that can be monitored at once. 11791788b7ffSJilles Tjoelker.It Va PATH 11801788b7ffSJilles TjoelkerThe default search path for executables. 11811788b7ffSJilles TjoelkerSee the 11821788b7ffSJilles Tjoelker.Sx Path Search 11831788b7ffSJilles Tjoelkersection for details. 11841788b7ffSJilles Tjoelker.It Va PPID 11851788b7ffSJilles TjoelkerThe parent process ID of the invoked shell. 11861788b7ffSJilles TjoelkerThis is set at startup 11871788b7ffSJilles Tjoelkerunless this variable is in the environment. 11881788b7ffSJilles TjoelkerA later change of parent process ID is not reflected. 11891788b7ffSJilles TjoelkerA subshell retains the same value of 11901788b7ffSJilles Tjoelker.Va PPID . 11911788b7ffSJilles Tjoelker.It Va PS1 11921788b7ffSJilles TjoelkerThe primary prompt string, which defaults to 11931788b7ffSJilles Tjoelker.Dq Li "$ " , 11941788b7ffSJilles Tjoelkerunless you are the superuser, in which case it defaults to 11951788b7ffSJilles Tjoelker.Dq Li "# " . 11961788b7ffSJilles Tjoelker.It Va PS2 11971788b7ffSJilles TjoelkerThe secondary prompt string, which defaults to 11981788b7ffSJilles Tjoelker.Dq Li "> " . 11991788b7ffSJilles Tjoelker.It Va PS4 12001788b7ffSJilles TjoelkerThe prefix for the trace output (if 12011788b7ffSJilles Tjoelker.Fl x 12021788b7ffSJilles Tjoelkeris active). 12031788b7ffSJilles TjoelkerThe default is 12041788b7ffSJilles Tjoelker.Dq Li "+ " . 12051788b7ffSJilles Tjoelker.El 1206ab72124fSSteve Price.Ss Word Expansions 12074b88c807SRodney W. GrimesThis clause describes the various expansions that are 1208eccea571SRuslan Ermilovperformed on words. 1209eccea571SRuslan ErmilovNot all expansions are performed on 12104b88c807SRodney W. Grimesevery word, as explained later. 1211ab72124fSSteve Price.Pp 12124b88c807SRodney W. GrimesTilde expansions, parameter expansions, command substitutions, 12134b88c807SRodney W. Grimesarithmetic expansions, and quote removals that occur within 1214eccea571SRuslan Ermilova single word expand to a single field. 1215eccea571SRuslan ErmilovIt is only field 12164b88c807SRodney W. Grimessplitting or pathname expansion that can create multiple 1217e6d3cf26SSheldon Hearnfields from a single word. 1218e6d3cf26SSheldon HearnThe single exception to this rule is 1219e918fc8fSSheldon Hearnthe expansion of the special parameter 1220dfe302abSRuslan Ermilov.Va @ 1221e918fc8fSSheldon Hearnwithin double-quotes, 1222e6d3cf26SSheldon Hearnas was described above. 1223ab72124fSSteve Price.Pp 12244b88c807SRodney W. GrimesThe order of word expansion is: 1225ab72124fSSteve Price.Bl -enum 1226ab72124fSSteve Price.It 1227ab72124fSSteve PriceTilde Expansion, Parameter Expansion, Command Substitution, 12284b88c807SRodney W. GrimesArithmetic Expansion (these all occur at the same time). 1229ab72124fSSteve Price.It 123049e11e3aSSheldon HearnField Splitting is performed on fields generated by step (1) 123149e11e3aSSheldon Hearnunless the 1232dfe302abSRuslan Ermilov.Va IFS 123349e11e3aSSheldon Hearnvariable is null. 1234ab72124fSSteve Price.It 123549e11e3aSSheldon HearnPathname Expansion (unless the 123649e11e3aSSheldon Hearn.Fl f 123749e11e3aSSheldon Hearnoption is in effect). 1238ab72124fSSteve Price.It 1239ab72124fSSteve PriceQuote Removal. 1240ab72124fSSteve Price.El 1241ab72124fSSteve Price.Pp 124249e11e3aSSheldon HearnThe 1243dfe302abSRuslan Ermilov.Ql $ 124449e11e3aSSheldon Hearncharacter is used to introduce parameter expansion, command 124536cf3efeSJilles Tjoelkersubstitution, or arithmetic expansion. 1246ab72124fSSteve Price.Ss Tilde Expansion (substituting a user's home directory) 124749e11e3aSSheldon HearnA word beginning with an unquoted tilde character 1248a762afe5SGiorgos Keramidas.Pq Ql ~ 124949e11e3aSSheldon Hearnis 125049e11e3aSSheldon Hearnsubjected to tilde expansion. 125149e11e3aSSheldon HearnAll the characters up to a slash 1252a762afe5SGiorgos Keramidas.Pq Ql / 125349e11e3aSSheldon Hearnor the end of the word are treated as a username 1254eccea571SRuslan Ermilovand are replaced with the user's home directory. 1255eccea571SRuslan ErmilovIf the 1256dfe302abSRuslan Ermilovusername is missing (as in 1257dfe302abSRuslan Ermilov.Pa ~/foobar ) , 1258dfe302abSRuslan Ermilovthe tilde is replaced with the value of the 12591788b7ffSJilles Tjoelker.Va HOME 1260dfe302abSRuslan Ermilovvariable (the current user's home directory). 1261ab72124fSSteve Price.Ss Parameter Expansion 12624b88c807SRodney W. GrimesThe format for parameter expansion is as follows: 1263ab72124fSSteve Price.Pp 1264dfe302abSRuslan Ermilov.D1 Li ${ Ns Ar expression Ns Li } 1265dfe302abSRuslan Ermilov.Pp 1266dfe302abSRuslan Ermilovwhere 1267dfe302abSRuslan Ermilov.Ar expression 1268dfe302abSRuslan Ermilovconsists of all characters until the matching 1269dfe302abSRuslan Ermilov.Ql } . 127049e11e3aSSheldon HearnAny 1271dfe302abSRuslan Ermilov.Ql } 1272f35d74beSJilles Tjoelkerescaped by a backslash or within a single-quoted or double-quoted 1273f35d74beSJilles Tjoelkerstring, and characters in 12744b88c807SRodney W. Grimesembedded arithmetic expansions, command substitutions, and variable 127549e11e3aSSheldon Hearnexpansions, are not examined in determining the matching 1276dfe302abSRuslan Ermilov.Ql } . 1277f35d74beSJilles TjoelkerIf the variants with 1278227c8e2aSJilles Tjoelker.Ql + , 1279227c8e2aSJilles Tjoelker.Ql - , 1280227c8e2aSJilles Tjoelker.Ql = 1281227c8e2aSJilles Tjoelkeror 1282f35d74beSJilles Tjoelker.Ql ?\& 1283f35d74beSJilles Tjoelkeroccur within a double-quoted string, 1284f35d74beSJilles Tjoelkeras an extension there may be unquoted parts 1285f35d74beSJilles Tjoelker(via double-quotes inside the expansion); 1286227c8e2aSJilles Tjoelker.Ql } 1287f35d74beSJilles Tjoelkerwithin such parts are also not examined in determining the matching 1288227c8e2aSJilles Tjoelker.Ql } . 1289ab72124fSSteve Price.Pp 12904b88c807SRodney W. GrimesThe simplest form for parameter expansion is: 1291ab72124fSSteve Price.Pp 1292dfe302abSRuslan Ermilov.D1 Li ${ Ns Ar parameter Ns Li } 1293dfe302abSRuslan Ermilov.Pp 1294dfe302abSRuslan ErmilovThe value, if any, of 1295dfe302abSRuslan Ermilov.Ar parameter 1296dfe302abSRuslan Ermilovis substituted. 1297ab72124fSSteve Price.Pp 12984b88c807SRodney W. GrimesThe parameter name or symbol can be enclosed in braces, which are 12994b88c807SRodney W. Grimesoptional except for positional parameters with more than one digit or 13004b88c807SRodney W. Grimeswhen parameter is followed by a character that could be interpreted as 13014b88c807SRodney W. Grimespart of the name. 1302ab72124fSSteve PriceIf a parameter expansion occurs inside double-quotes: 1303ab72124fSSteve Price.Bl -enum 1304ab72124fSSteve Price.It 1305ab72124fSSteve PricePathname expansion is not performed on the results of the 13064b88c807SRodney W. Grimesexpansion. 1307ab72124fSSteve Price.It 1308ab72124fSSteve PriceField splitting is not performed on the results of the 1309e918fc8fSSheldon Hearnexpansion, with the exception of the special parameter 1310dfe302abSRuslan Ermilov.Va @ . 1311ab72124fSSteve Price.El 1312ab72124fSSteve Price.Pp 13134b88c807SRodney W. GrimesIn addition, a parameter expansion can be modified by using one of the 13144b88c807SRodney W. Grimesfollowing formats. 131581e9cda2SRuslan Ermilov.Bl -tag -width indent 1316dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li :- Ns Ar word Ns Li } 1317eccea571SRuslan ErmilovUse Default Values. 1318dfe302abSRuslan ErmilovIf 1319dfe302abSRuslan Ermilov.Ar parameter 1320dfe302abSRuslan Ermilovis unset or null, the expansion of 1321dfe302abSRuslan Ermilov.Ar word 1322dfe302abSRuslan Ermilovis substituted; otherwise, the value of 1323dfe302abSRuslan Ermilov.Ar parameter 1324dfe302abSRuslan Ermilovis substituted. 1325dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li := Ns Ar word Ns Li } 1326eccea571SRuslan ErmilovAssign Default Values. 1327dfe302abSRuslan ErmilovIf 1328dfe302abSRuslan Ermilov.Ar parameter 1329dfe302abSRuslan Ermilovis unset or null, the expansion of 1330dfe302abSRuslan Ermilov.Ar word 1331dfe302abSRuslan Ermilovis assigned to 1332dfe302abSRuslan Ermilov.Ar parameter . 1333eccea571SRuslan ErmilovIn all cases, the 1334dfe302abSRuslan Ermilovfinal value of 1335dfe302abSRuslan Ermilov.Ar parameter 1336dfe302abSRuslan Ermilovis substituted. 1337b139165cSJilles TjoelkerQuoting inside 1338b139165cSJilles Tjoelker.Ar word 1339b139165cSJilles Tjoelkerdoes not prevent field splitting or pathname expansion. 1340eccea571SRuslan ErmilovOnly variables, not positional 13414b88c807SRodney W. Grimesparameters or special parameters, can be 13424b88c807SRodney W. Grimesassigned in this way. 1343dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li :? Ns Oo Ar word Oc Ns Li } 1344eccea571SRuslan ErmilovIndicate Error if Null or Unset. 1345eccea571SRuslan ErmilovIf 1346dfe302abSRuslan Ermilov.Ar parameter 1347dfe302abSRuslan Ermilovis unset or null, the expansion of 1348dfe302abSRuslan Ermilov.Ar word 1349dfe302abSRuslan Ermilov(or a message indicating it is unset if 1350dfe302abSRuslan Ermilov.Ar word 1351dfe302abSRuslan Ermilovis omitted) is written to standard 13524b88c807SRodney W. Grimeserror and the shell exits with a nonzero 1353e6d3cf26SSheldon Hearnexit status. 1354e6d3cf26SSheldon HearnOtherwise, the value of 1355dfe302abSRuslan Ermilov.Ar parameter 1356dfe302abSRuslan Ermilovis substituted. 1357eccea571SRuslan ErmilovAn 13584b88c807SRodney W. Grimesinteractive shell need not exit. 1359dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li :+ Ns Ar word Ns Li } 1360eccea571SRuslan ErmilovUse Alternate Value. 1361dfe302abSRuslan ErmilovIf 1362dfe302abSRuslan Ermilov.Ar parameter 1363dfe302abSRuslan Ermilovis unset or null, null is substituted; 1364dfe302abSRuslan Ermilovotherwise, the expansion of 1365dfe302abSRuslan Ermilov.Ar word 1366dfe302abSRuslan Ermilovis substituted. 13671413f7deSTony Finch.El 1368ab72124fSSteve Price.Pp 13694b88c807SRodney W. GrimesIn the parameter expansions shown previously, use of the colon in the 13704b88c807SRodney W. Grimesformat results in a test for a parameter that is unset or null; omission 13714b88c807SRodney W. Grimesof the colon results in a test for a parameter that is only unset. 1372227c8e2aSJilles Tjoelker.Pp 1373227c8e2aSJilles TjoelkerThe 1374227c8e2aSJilles Tjoelker.Ar word 1375227c8e2aSJilles Tjoelkerinherits the type of quoting 1376227c8e2aSJilles Tjoelker(unquoted, double-quoted or here-document) 1377227c8e2aSJilles Tjoelkerfrom the surroundings, 1378227c8e2aSJilles Tjoelkerwith the exception that a backslash that quotes a closing brace is removed 1379227c8e2aSJilles Tjoelkerduring quote removal. 13801413f7deSTony Finch.Bl -tag -width indent 1381dfe302abSRuslan Ermilov.It Li ${# Ns Ar parameter Ns Li } 1382eccea571SRuslan ErmilovString Length. 1383eccea571SRuslan ErmilovThe length in characters of 1384dfe302abSRuslan Ermilovthe value of 1385dfe302abSRuslan Ermilov.Ar parameter . 138671337c33SSheldon Hearn.El 1387ab72124fSSteve Price.Pp 13884b88c807SRodney W. GrimesThe following four varieties of parameter expansion provide for substring 138949e11e3aSSheldon Hearnprocessing. 139049e11e3aSSheldon HearnIn each case, pattern matching notation 139149e11e3aSSheldon Hearn(see 139249e11e3aSSheldon Hearn.Sx Shell Patterns ) , 139349e11e3aSSheldon Hearnrather than regular expression notation, 139449e11e3aSSheldon Hearnis used to evaluate the patterns. 1395e918fc8fSSheldon HearnIf parameter is one of the special parameters 1396dfe302abSRuslan Ermilov.Va * 139749e11e3aSSheldon Hearnor 1398dfe302abSRuslan Ermilov.Va @ , 139949e11e3aSSheldon Hearnthe result of the expansion is unspecified. 14004b88c807SRodney W. GrimesEnclosing the full parameter expansion string in double-quotes does not 14014b88c807SRodney W. Grimescause the following four varieties of pattern characters to be quoted, 14024b88c807SRodney W. Grimeswhereas quoting characters within the braces has this effect. 140381e9cda2SRuslan Ermilov.Bl -tag -width indent 1404dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li % Ns Ar word Ns Li } 1405eccea571SRuslan ErmilovRemove Smallest Suffix Pattern. 1406dfe302abSRuslan ErmilovThe 1407dfe302abSRuslan Ermilov.Ar word 1408eccea571SRuslan Ermilovis expanded to produce a pattern. 1409eccea571SRuslan ErmilovThe 14104b88c807SRodney W. Grimesparameter expansion then results in 1411dfe302abSRuslan Ermilov.Ar parameter , 1412dfe302abSRuslan Ermilovwith the smallest portion of the 14134b88c807SRodney W. Grimessuffix matched by the pattern deleted. 1414dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li %% Ns Ar word Ns Li } 1415eccea571SRuslan ErmilovRemove Largest Suffix Pattern. 1416dfe302abSRuslan ErmilovThe 1417dfe302abSRuslan Ermilov.Ar word 1418eccea571SRuslan Ermilovis expanded to produce a pattern. 1419eccea571SRuslan ErmilovThe 14204b88c807SRodney W. Grimesparameter expansion then results in 1421dfe302abSRuslan Ermilov.Ar parameter , 1422dfe302abSRuslan Ermilovwith the largest portion of the 14234b88c807SRodney W. Grimessuffix matched by the pattern deleted. 1424dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li # Ns Ar word Ns Li } 1425eccea571SRuslan ErmilovRemove Smallest Prefix Pattern. 1426dfe302abSRuslan ErmilovThe 1427dfe302abSRuslan Ermilov.Ar word 1428eccea571SRuslan Ermilovis expanded to produce a pattern. 1429eccea571SRuslan ErmilovThe 14304b88c807SRodney W. Grimesparameter expansion then results in 1431dfe302abSRuslan Ermilov.Ar parameter , 1432dfe302abSRuslan Ermilovwith the smallest portion of the 14334b88c807SRodney W. Grimesprefix matched by the pattern deleted. 1434dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li ## Ns Ar word Ns Li } 1435eccea571SRuslan ErmilovRemove Largest Prefix Pattern. 1436dfe302abSRuslan ErmilovThe 1437dfe302abSRuslan Ermilov.Ar word 1438eccea571SRuslan Ermilovis expanded to produce a pattern. 1439eccea571SRuslan ErmilovThe 14404b88c807SRodney W. Grimesparameter expansion then results in 1441dfe302abSRuslan Ermilov.Ar parameter , 1442dfe302abSRuslan Ermilovwith the largest portion of the 14434b88c807SRodney W. Grimesprefix matched by the pattern deleted. 1444ab72124fSSteve Price.El 1445ab72124fSSteve Price.Ss Command Substitution 14464b88c807SRodney W. GrimesCommand substitution allows the output of a command to be substituted in 1447eccea571SRuslan Ermilovplace of the command name itself. 1448eccea571SRuslan ErmilovCommand substitution occurs when 14494b88c807SRodney W. Grimesthe command is enclosed as follows: 1450dfe302abSRuslan Ermilov.Pp 1451dfe302abSRuslan Ermilov.D1 Li $( Ns Ar command Ns Li )\& 1452ab72124fSSteve Price.Pp 145349e11e3aSSheldon Hearnor the backquoted version: 1454dfe302abSRuslan Ermilov.Pp 1455dfe302abSRuslan Ermilov.D1 Li ` Ns Ar command Ns Li ` 1456ab72124fSSteve Price.Pp 14574b88c807SRodney W. GrimesThe shell expands the command substitution by executing command in a 14584b88c807SRodney W. Grimessubshell environment and replacing the command substitution 145949e11e3aSSheldon Hearnwith the standard output of the command, 146049e11e3aSSheldon Hearnremoving sequences of one or more newlines at the end of the substitution. 146149e11e3aSSheldon HearnEmbedded newlines before the end of the output are not removed; 146249e11e3aSSheldon Hearnhowever, during field splitting, they may be translated into spaces 146349e11e3aSSheldon Hearndepending on the value of 1464dfe302abSRuslan Ermilov.Va IFS 146549e11e3aSSheldon Hearnand the quoting that is in effect. 1466ab72124fSSteve Price.Ss Arithmetic Expansion 14674b88c807SRodney W. GrimesArithmetic expansion provides a mechanism for evaluating an arithmetic 1468e6d3cf26SSheldon Hearnexpression and substituting its value. 1469e6d3cf26SSheldon HearnThe format for arithmetic expansion is as follows: 1470ab72124fSSteve Price.Pp 1471dfe302abSRuslan Ermilov.D1 Li $(( Ns Ar expression Ns Li )) 1472dfe302abSRuslan Ermilov.Pp 1473dfe302abSRuslan ErmilovThe 1474dfe302abSRuslan Ermilov.Ar expression 1475dfe302abSRuslan Ermilovis treated as if it were in double-quotes, except 1476eccea571SRuslan Ermilovthat a double-quote inside the expression is not treated specially. 1477eccea571SRuslan ErmilovThe 1478dfe302abSRuslan Ermilovshell expands all tokens in the 1479dfe302abSRuslan Ermilov.Ar expression 1480dfe302abSRuslan Ermilovfor parameter expansion, 148136cf3efeSJilles Tjoelkercommand substitution, 148236cf3efeSJilles Tjoelkerarithmetic expansion 148336cf3efeSJilles Tjoelkerand quote removal. 1484ab72124fSSteve Price.Pp 148536cf3efeSJilles TjoelkerThe allowed expressions are a subset of C expressions, 148636cf3efeSJilles Tjoelkersummarized below. 148736cf3efeSJilles Tjoelker.Bl -tag -width "Variables" -offset indent 148836cf3efeSJilles Tjoelker.It Values 148936cf3efeSJilles TjoelkerAll values are of type 149036cf3efeSJilles Tjoelker.Ft intmax_t . 149136cf3efeSJilles Tjoelker.It Constants 149236cf3efeSJilles TjoelkerDecimal, octal (starting with 149336cf3efeSJilles Tjoelker.Li 0 ) 149436cf3efeSJilles Tjoelkerand hexadecimal (starting with 149536cf3efeSJilles Tjoelker.Li 0x ) 149636cf3efeSJilles Tjoelkerinteger constants. 149736cf3efeSJilles Tjoelker.It Variables 149836cf3efeSJilles TjoelkerShell variables can be read and written 149936cf3efeSJilles Tjoelkerand contain integer constants. 150036cf3efeSJilles Tjoelker.It Unary operators 150136cf3efeSJilles Tjoelker.Li "! ~ + -" 150236cf3efeSJilles Tjoelker.It Binary operators 150336cf3efeSJilles Tjoelker.Li "* / % + - << >> < <= > >= == != & ^ | && ||" 150436cf3efeSJilles Tjoelker.It Assignment operators 150536cf3efeSJilles Tjoelker.Li "= += -= *= /= %= <<= >>= &= ^= |=" 150636cf3efeSJilles Tjoelker.It Short-circuit evaluation 150736cf3efeSJilles TjoelkerThe 150836cf3efeSJilles Tjoelker.Li && 150936cf3efeSJilles Tjoelkerand 151036cf3efeSJilles Tjoelker.Li || 151136cf3efeSJilles Tjoelkeroperators always evaluate both sides. 151236cf3efeSJilles TjoelkerThis is a bug. 151336cf3efeSJilles Tjoelker.El 151436cf3efeSJilles Tjoelker.Pp 151536cf3efeSJilles TjoelkerThe result of the expression is substituted in decimal. 1516ab72124fSSteve Price.Ss White Space Splitting (Field Splitting) 15174b88c807SRodney W. GrimesAfter parameter expansion, command substitution, and 15184b88c807SRodney W. Grimesarithmetic expansion the shell scans the results of 15194b88c807SRodney W. Grimesexpansions and substitutions that did not occur in double-quotes for 15204b88c807SRodney W. Grimesfield splitting and multiple fields can result. 1521ab72124fSSteve Price.Pp 152249e11e3aSSheldon HearnThe shell treats each character of the 1523dfe302abSRuslan Ermilov.Va IFS 1524dfe302abSRuslan Ermilovvariable as a delimiter and uses 15254b88c807SRodney W. Grimesthe delimiters to split the results of parameter expansion and command 15264b88c807SRodney W. Grimessubstitution into fields. 1527ab72124fSSteve Price.Ss Pathname Expansion (File Name Generation) 152849e11e3aSSheldon HearnUnless the 152949e11e3aSSheldon Hearn.Fl f 153049e11e3aSSheldon Hearnoption is set, 153149e11e3aSSheldon Hearnfile name generation is performed 1532eccea571SRuslan Ermilovafter word splitting is complete. 1533eccea571SRuslan ErmilovEach word is 1534eccea571SRuslan Ermilovviewed as a series of patterns, separated by slashes. 1535eccea571SRuslan ErmilovThe 15364b88c807SRodney W. Grimesprocess of expansion replaces the word with the names of 15374b88c807SRodney W. Grimesall existing files whose names can be formed by replacing 15384b88c807SRodney W. Grimeseach pattern with a string that matches the specified pattern. 1539ab0a2172SSteve PriceThere are two restrictions on this: first, a pattern cannot match 1540ab0a2172SSteve Pricea string containing a slash, and second, 15414b88c807SRodney W. Grimesa pattern cannot match a string starting with a period 15424b88c807SRodney W. Grimesunless the first character of the pattern is a period. 15434b88c807SRodney W. GrimesThe next section describes the patterns used for both 1544ab72124fSSteve PricePathname Expansion and the 1545c644db6aSSheldon Hearn.Ic case 1546ab72124fSSteve Pricecommand. 1547ab72124fSSteve Price.Ss Shell Patterns 1548f434d1dfSAdam DavidA pattern consists of normal characters, which match themselves, 154949e11e3aSSheldon Hearnand meta-characters. 155049e11e3aSSheldon HearnThe meta-characters are 1551dfe302abSRuslan Ermilov.Ql \&! , 1552dfe302abSRuslan Ermilov.Ql * , 1553dfe302abSRuslan Ermilov.Ql \&? , 15546b15476eSSheldon Hearnand 1555dfe302abSRuslan Ermilov.Ql \&[ . 15566b15476eSSheldon HearnThese characters lose their special meanings if they are quoted. 15576b15476eSSheldon HearnWhen command or variable substitution is performed and the dollar sign 15586b15476eSSheldon Hearnor back quotes are not double-quoted, the value of the 15594b88c807SRodney W. Grimesvariable or the output of the command is scanned for these 15604b88c807SRodney W. Grimescharacters and they are turned into meta-characters. 1561ab72124fSSteve Price.Pp 15626b15476eSSheldon HearnAn asterisk 1563a762afe5SGiorgos Keramidas.Pq Ql * 1564e918fc8fSSheldon Hearnmatches any string of characters. 1565e918fc8fSSheldon HearnA question mark 1566a762afe5SGiorgos Keramidas.Pq Ql \&? 1567e918fc8fSSheldon Hearnmatches any single character. 1568e6d3cf26SSheldon HearnA left bracket 1569dfe302abSRuslan Ermilov.Pq Ql \&[ 1570e6d3cf26SSheldon Hearnintroduces a character class. 1571e6d3cf26SSheldon HearnThe end of the character class is indicated by a 1572dfe302abSRuslan Ermilov.Ql \&] ; 15736b15476eSSheldon Hearnif the 1574dfe302abSRuslan Ermilov.Ql \&] 15756b15476eSSheldon Hearnis missing then the 1576dfe302abSRuslan Ermilov.Ql \&[ 15776b15476eSSheldon Hearnmatches a 1578dfe302abSRuslan Ermilov.Ql \&[ 1579e6d3cf26SSheldon Hearnrather than introducing a character class. 1580e6d3cf26SSheldon HearnA character class matches any of the characters between the square brackets. 1581e6d3cf26SSheldon HearnA range of characters may be specified using a minus sign. 1582e918fc8fSSheldon HearnThe character class may be complemented by making an exclamation point 1583a762afe5SGiorgos Keramidas.Pq Ql !\& 1584e918fc8fSSheldon Hearnthe first character of the character class. 1585ab72124fSSteve Price.Pp 15866b15476eSSheldon HearnTo include a 1587dfe302abSRuslan Ermilov.Ql \&] 1588e6d3cf26SSheldon Hearnin a character class, make it the first character listed 1589e6d3cf26SSheldon Hearn(after the 1590dfe302abSRuslan Ermilov.Ql \&! , 1591e6d3cf26SSheldon Hearnif any). 1592e918fc8fSSheldon HearnTo include a 1593dfe302abSRuslan Ermilov.Ql - , 1594e918fc8fSSheldon Hearnmake it the first or last character listed. 15958eed22b1SJens Schweikhardt.Ss Built-in Commands 1596c644db6aSSheldon HearnThis section lists the commands which 15978eed22b1SJens Schweikhardtare built-in because they need to perform some operation 1598eccea571SRuslan Ermilovthat cannot be performed by a separate process. 1599eccea571SRuslan ErmilovIn addition to 160010845922SYaroslav Tykhiythese, built-in versions of essential utilities 160110845922SYaroslav Tykhiyare provided for efficiency. 160281e9cda2SRuslan Ermilov.Bl -tag -width indent 1603d0353b83SRuslan Ermilov.It Ic \&: 1604aa9caaf6SPeter WemmA null command that returns a 0 (true) exit value. 1605d0353b83SRuslan Ermilov.It Ic \&. Ar file 1606aa9caaf6SPeter WemmThe commands in the specified file are read and executed by the shell. 16074ad8968aSBrian FeldmanThe 16084ad8968aSBrian Feldman.Ic return 16094ad8968aSBrian Feldmancommand may be used to return to the 16104ad8968aSBrian Feldman.Ic \&. 16114ad8968aSBrian Feldmancommand's caller. 16126466945aSJohn PolstraIf 16136466945aSJohn Polstra.Ar file 16146466945aSJohn Polstracontains any 1615dfe302abSRuslan Ermilov.Ql / 1616eccea571SRuslan Ermilovcharacters, it is used as is. 1617eccea571SRuslan ErmilovOtherwise, the shell searches the 16181788b7ffSJilles Tjoelker.Va PATH 1619eccea571SRuslan Ermilovfor the file. 1620eccea571SRuslan ErmilovIf it is not found in the 16211788b7ffSJilles Tjoelker.Va PATH , 16226466945aSJohn Polstrait is sought in the current working directory. 162310845922SYaroslav Tykhiy.It Ic \&[ 162410845922SYaroslav TykhiyA built-in equivalent of 162510845922SYaroslav Tykhiy.Xr test 1 . 1626a886288eSJesus R. Camou.It Ic alias Oo Ar name Ns Oo = Ns Ar string Oc ... Oc 162749e11e3aSSheldon HearnIf 1628d0353b83SRuslan Ermilov.Ar name Ns = Ns Ar string 162949e11e3aSSheldon Hearnis specified, the shell defines the alias 163049e11e3aSSheldon Hearn.Ar name 16316b15476eSSheldon Hearnwith value 163249e11e3aSSheldon Hearn.Ar string . 16336b15476eSSheldon HearnIf just 163449e11e3aSSheldon Hearn.Ar name 16356b15476eSSheldon Hearnis specified, the value of the alias 163649e11e3aSSheldon Hearn.Ar name 16376b15476eSSheldon Hearnis printed. 163849e11e3aSSheldon HearnWith no arguments, the 163949e11e3aSSheldon Hearn.Ic alias 16408eed22b1SJens Schweikhardtbuilt-in command prints the names and values of all defined aliases 164149e11e3aSSheldon Hearn(see 164249e11e3aSSheldon Hearn.Ic unalias ) . 1643e5341cbbSTim J. RobbinsAlias values are written with appropriate quoting so that they are 16449ba31ca0SRuslan Ermilovsuitable for re-input to the shell. 1645a886288eSJesus R. CamouAlso see the 1646a886288eSJesus R. Camou.Sx Aliases 1647a886288eSJesus R. Camousubsection. 164849e11e3aSSheldon Hearn.It Ic bg Op Ar job ... 164949e11e3aSSheldon HearnContinue the specified jobs 165049e11e3aSSheldon Hearn(or the current job if no jobs are given) 165149e11e3aSSheldon Hearnin the background. 1652df9e587bSTim J. Robbins.It Ic builtin Ar cmd Op Ar arg ... 16538eed22b1SJens SchweikhardtExecute the specified built-in command, 165449e11e3aSSheldon Hearn.Ar cmd . 165549e11e3aSSheldon HearnThis is useful when the user wishes to override a shell function 16568eed22b1SJens Schweikhardtwith the same name as a built-in command. 1657088acf90STim J. Robbins.It Ic bind Oo Fl aeklrsv Oc Oo Ar key Oo Ar command Oc Oc 1658088acf90STim J. RobbinsList or alter key bindings for the line editor. 1659088acf90STim J. RobbinsThis command is documented in 1660088acf90STim J. Robbins.Xr editrc 5 . 1661d74e011fSRuslan Ermilov.It Ic cd Oo Fl L | P Oc Op Ar directory 166249e11e3aSSheldon HearnSwitch to the specified 166349e11e3aSSheldon Hearn.Ar directory , 166449e11e3aSSheldon Hearnor to the directory specified in the 16651788b7ffSJilles Tjoelker.Va HOME 166649e11e3aSSheldon Hearnenvironment variable if no 166749e11e3aSSheldon Hearn.Ar directory 166849e11e3aSSheldon Hearnis specified. 166949e11e3aSSheldon HearnIf 167049e11e3aSSheldon Hearn.Ar directory 1671029c8ee4STim J. Robbinsdoes not begin with 16729ba31ca0SRuslan Ermilov.Pa / , \&. , 167349e11e3aSSheldon Hearnor 1674029c8ee4STim J. Robbins.Pa .. , 167549e11e3aSSheldon Hearnthen the directories listed in the 16761788b7ffSJilles Tjoelker.Va CDPATH 167749e11e3aSSheldon Hearnvariable will be 167849e11e3aSSheldon Hearnsearched for the specified 167949e11e3aSSheldon Hearn.Ar directory . 1680029c8ee4STim J. RobbinsIf 16811788b7ffSJilles Tjoelker.Va CDPATH 1682029c8ee4STim J. Robbinsis unset, the current directory is searched. 168349e11e3aSSheldon HearnThe format of 16841788b7ffSJilles Tjoelker.Va CDPATH 168549e11e3aSSheldon Hearnis the same as that of 16861788b7ffSJilles Tjoelker.Va PATH . 1687e6d3cf26SSheldon HearnIn an interactive shell, 168849e11e3aSSheldon Hearnthe 168949e11e3aSSheldon Hearn.Ic cd 169049e11e3aSSheldon Hearncommand will print out the name of the directory 1691e6d3cf26SSheldon Hearnthat it actually switched to 1692e6d3cf26SSheldon Hearnif this is different from the name that the user gave. 169349e11e3aSSheldon HearnThese may be different either because the 16941788b7ffSJilles Tjoelker.Va CDPATH 169549e11e3aSSheldon Hearnmechanism was used or because a symbolic link was crossed. 1696178897f1STim J. Robbins.Pp 1697178897f1STim J. RobbinsIf the 1698178897f1STim J. Robbins.Fl P 1699178897f1STim J. Robbinsoption is specified, 170081e9cda2SRuslan Ermilov.Pa .. 1701178897f1STim J. Robbinsis handled physically and symbolic links are resolved before 170281e9cda2SRuslan Ermilov.Pa .. 1703178897f1STim J. Robbinscomponents are processed. 1704178897f1STim J. RobbinsIf the 1705178897f1STim J. Robbins.Fl L 1706178897f1STim J. Robbinsoption is specified, 170781e9cda2SRuslan Ermilov.Pa .. 1708178897f1STim J. Robbinsis handled logically. 1709178897f1STim J. RobbinsThis is the default. 17109434a1c7SDima Dorfman.It Ic chdir 17119434a1c7SDima DorfmanA synonym for the 17129434a1c7SDima Dorfman.Ic cd 17138eed22b1SJens Schweikhardtbuilt-in command. 17149ba31ca0SRuslan Ermilov.It Ic command Oo Fl p Oc Op Ar utility Op Ar argument ... 171533b222b9SStefan Farfeleder.It Ic command Oo Fl v | V Oc Op Ar utility 171633b222b9SStefan FarfelederThe first form of invocation executes the specified 1717c848bc18SJilles Tjoelker.Ar utility , 1718c848bc18SJilles Tjoelkerignoring shell functions in the search. 1719c848bc18SJilles TjoelkerIf 17202babaf74STim J. Robbins.Ar utility 1721c848bc18SJilles Tjoelkeris a special builtin, 1722c848bc18SJilles Tjoelkerit is executed as if it were a regular builtin. 17232babaf74STim J. Robbins.Pp 17242babaf74STim J. RobbinsIf the 17252babaf74STim J. Robbins.Fl p 17262babaf74STim J. Robbinsoption is specified, the command search is performed using a 17272babaf74STim J. Robbinsdefault value of 17281788b7ffSJilles Tjoelker.Va PATH 17292babaf74STim J. Robbinsthat is guaranteed to find all of the standard utilities. 173033b222b9SStefan Farfeleder.Pp 173133b222b9SStefan FarfelederIf the 173233b222b9SStefan Farfeleder.Fl v 173333b222b9SStefan Farfelederoption is specified, 173433b222b9SStefan Farfeleder.Ar utility 173533b222b9SStefan Farfelederis not executed but a description of its interpretation by the shell is 173633b222b9SStefan Farfelederprinted. 173733b222b9SStefan FarfelederFor ordinary commands the output is the path name; for shell built-in 173833b222b9SStefan Farfeledercommands, shell functions and keywords only the name is written. 173933b222b9SStefan FarfelederAliases are printed as 174033b222b9SStefan Farfeleder.Dq Ic alias Ar name Ns = Ns Ar value . 174133b222b9SStefan Farfeleder.Pp 174233b222b9SStefan FarfelederThe 174333b222b9SStefan Farfeleder.Fl V 174433b222b9SStefan Farfelederoption is identical to 174533b222b9SStefan Farfeleder.Fl v 174633b222b9SStefan Farfelederexcept for the output. 174733b222b9SStefan FarfelederIt prints 174833b222b9SStefan Farfeleder.Dq Ar utility Ic is Ar description 174933b222b9SStefan Farfelederwhere 175033b222b9SStefan Farfeleder.Ar description 175133b222b9SStefan Farfelederis either 175233b222b9SStefan Farfelederthe path name to 175333b222b9SStefan Farfeleder.Ar utility , 175430268dfaSJilles Tjoelkera special shell builtin, 17558af11131SRuslan Ermilova shell builtin, 17568af11131SRuslan Ermilova shell function, 17578af11131SRuslan Ermilova shell keyword 175833b222b9SStefan Farfelederor 17598af11131SRuslan Ermilovan alias for 17608af11131SRuslan Ermilov.Ar value . 176173313421SStefan Farfeleder.It Ic echo Oo Fl e | n Oc Op Ar string ... 176273313421SStefan FarfelederPrint a space-separated list of the arguments to the standard output 176373313421SStefan Farfelederand append a newline character. 176481e9cda2SRuslan Ermilov.Bl -tag -width indent 1765501e74b7SMark Ovens.It Fl n 1766501e74b7SMark OvensSuppress the output of the trailing newline. 1767501e74b7SMark Ovens.It Fl e 1768501e74b7SMark OvensProcess C-style backslash escape sequences. 1769dfe302abSRuslan ErmilovThe 1770501e74b7SMark Ovens.Ic echo 1771dfe302abSRuslan Ermilovcommand understands the following character escapes: 177281e9cda2SRuslan Ermilov.Bl -tag -width indent 1773501e74b7SMark Ovens.It \ea 1774501e74b7SMark OvensAlert (ring the terminal bell) 1775501e74b7SMark Ovens.It \eb 1776501e74b7SMark OvensBackspace 1777501e74b7SMark Ovens.It \ec 1778501e74b7SMark OvensSuppress the trailing newline (this has the side-effect of truncating the 1779501e74b7SMark Ovensline if it is not the last character) 1780501e74b7SMark Ovens.It \ee 1781dfe302abSRuslan ErmilovThe ESC character 1782dfe302abSRuslan Ermilov.Tn ( ASCII 1783dfe302abSRuslan Ermilov0x1b) 1784501e74b7SMark Ovens.It \ef 1785501e74b7SMark OvensFormfeed 1786501e74b7SMark Ovens.It \en 1787501e74b7SMark OvensNewline 1788501e74b7SMark Ovens.It \er 1789501e74b7SMark OvensCarriage return 1790501e74b7SMark Ovens.It \et 1791501e74b7SMark OvensHorizontal tab 1792501e74b7SMark Ovens.It \ev 1793501e74b7SMark OvensVertical tab 1794501e74b7SMark Ovens.It \e\e 1795501e74b7SMark OvensLiteral backslash 1796501e74b7SMark Ovens.It \e0nnn 1797dfe302abSRuslan Ermilov(Zero) The character whose octal value is 1798dfe302abSRuslan Ermilov.Ar nnn 1799501e74b7SMark Ovens.El 1800501e74b7SMark Ovens.Pp 1801501e74b7SMark OvensIf 1802501e74b7SMark Ovens.Ar string 1803501e74b7SMark Ovensis not enclosed in quotes then the backslash itself must be escaped 1804eccea571SRuslan Ermilovwith a backslash to protect it from the shell. 1805eccea571SRuslan ErmilovFor example 1806501e74b7SMark Ovens.Bd -literal -offset indent 1807501e74b7SMark Ovens$ echo -e "a\evb" 1808501e74b7SMark Ovensa 1809501e74b7SMark Ovens b 1810501e74b7SMark Ovens$ echo -e a\e\evb 1811501e74b7SMark Ovensa 1812501e74b7SMark Ovens b 1813501e74b7SMark Ovens$ echo -e "a\e\eb" 1814501e74b7SMark Ovensa\eb 1815501e74b7SMark Ovens$ echo -e a\e\e\e\eb 1816501e74b7SMark Ovensa\eb 1817501e74b7SMark Ovens.Ed 1818501e74b7SMark Ovens.El 1819558175caSTim J. Robbins.Pp 1820558175caSTim J. RobbinsOnly one of the 1821558175caSTim J. Robbins.Fl e 1822558175caSTim J. Robbinsand 1823558175caSTim J. Robbins.Fl n 1824558175caSTim J. Robbinsoptions may be specified. 182549e11e3aSSheldon Hearn.It Ic eval Ar string ... 1826e6d3cf26SSheldon HearnConcatenate all the arguments with spaces. 1827e6d3cf26SSheldon HearnThen re-parse and execute the command. 182849e11e3aSSheldon Hearn.It Ic exec Op Ar command Op arg ... 182949e11e3aSSheldon HearnUnless 183049e11e3aSSheldon Hearn.Ar command 183149e11e3aSSheldon Hearnis omitted, 183249e11e3aSSheldon Hearnthe shell process is replaced with the specified program 18338eed22b1SJens Schweikhardt(which must be a real program, not a shell built-in command or function). 183449e11e3aSSheldon HearnAny redirections on the 183549e11e3aSSheldon Hearn.Ic exec 183649e11e3aSSheldon Hearncommand are marked as permanent, 183749e11e3aSSheldon Hearnso that they are not undone when the 183849e11e3aSSheldon Hearn.Ic exec 183949e11e3aSSheldon Hearncommand finishes. 184049e11e3aSSheldon Hearn.It Ic exit Op Ar exitstatus 184149e11e3aSSheldon HearnTerminate the shell process. 184249e11e3aSSheldon HearnIf 184349e11e3aSSheldon Hearn.Ar exitstatus 184449e11e3aSSheldon Hearnis given 184549e11e3aSSheldon Hearnit is used as the exit status of the shell; 184649e11e3aSSheldon Hearnotherwise the exit status of the preceding command is used. 1847a68fbc44SJilles TjoelkerThe exit status should be an integer between 0 and 255. 1848ef9791a3SStefan Farfeleder.It Ic export Ar name ... 1849ef9791a3SStefan Farfeleder.It Ic export Op Fl p 18504b88c807SRodney W. GrimesThe specified names are exported so that they will 18514b88c807SRodney W. Grimesappear in the environment of subsequent commands. 185249e11e3aSSheldon HearnThe only way to un-export a variable is to 185349e11e3aSSheldon Hearn.Ic unset 185449e11e3aSSheldon Hearnit. 185549e11e3aSSheldon HearnThe shell allows the value of a variable to be set 185649e11e3aSSheldon Hearnat the same time as it is exported by writing 1857ab72124fSSteve Price.Pp 1858dfe302abSRuslan Ermilov.D1 Ic export Ar name Ns = Ns Ar value 1859dfe302abSRuslan Ermilov.Pp 1860dfe302abSRuslan ErmilovWith no arguments the 1861dfe302abSRuslan Ermilov.Ic export 1862dfe302abSRuslan Ermilovcommand lists the names 18634b88c807SRodney W. Grimesof all exported variables. 186445086f8cSTim J. RobbinsIf the 186545086f8cSTim J. Robbins.Fl p 186645086f8cSTim J. Robbinsoption is specified, the exported variables are printed as 186745086f8cSTim J. Robbins.Dq Ic export Ar name Ns = Ns Ar value 186845086f8cSTim J. Robbinslines, suitable for re-input to the shell. 1869a6557dcbSYaroslav Tykhiy.It Ic false 1870a6557dcbSYaroslav TykhiyA null command that returns a non-zero (false) exit value. 187181e9cda2SRuslan Ermilov.It Ic fc Oo Fl e Ar editor Oc Op Ar first Op Ar last 187281e9cda2SRuslan Ermilov.It Ic fc Fl l Oo Fl nr Oc Op Ar first Op Ar last 187381e9cda2SRuslan Ermilov.It Ic fc Fl s Oo Ar old Ns = Ns Ar new Oc Op Ar first 187449e11e3aSSheldon HearnThe 187549e11e3aSSheldon Hearn.Ic fc 18768eed22b1SJens Schweikhardtbuilt-in command lists, or edits and re-executes, 187749e11e3aSSheldon Hearncommands previously entered to an interactive shell. 187881e9cda2SRuslan Ermilov.Bl -tag -width indent 187949e11e3aSSheldon Hearn.It Fl e Ar editor 188049e11e3aSSheldon HearnUse the editor named by 188149e11e3aSSheldon Hearn.Ar editor 188249e11e3aSSheldon Hearnto edit the commands. 1883dfe302abSRuslan ErmilovThe 1884dfe302abSRuslan Ermilov.Ar editor 1885dfe302abSRuslan Ermilovstring is a command name, 188649e11e3aSSheldon Hearnsubject to search via the 18871788b7ffSJilles Tjoelker.Va PATH 188849e11e3aSSheldon Hearnvariable. 188949e11e3aSSheldon HearnThe value in the 18901788b7ffSJilles Tjoelker.Va FCEDIT 189149e11e3aSSheldon Hearnvariable is used as a default when 189249e11e3aSSheldon Hearn.Fl e 189349e11e3aSSheldon Hearnis not specified. 189449e11e3aSSheldon HearnIf 18951788b7ffSJilles Tjoelker.Va FCEDIT 189649e11e3aSSheldon Hearnis null or unset, the value of the 18971788b7ffSJilles Tjoelker.Va EDITOR 189849e11e3aSSheldon Hearnvariable is used. 189949e11e3aSSheldon HearnIf 19001788b7ffSJilles Tjoelker.Va EDITOR 190149e11e3aSSheldon Hearnis null or unset, 1902ab72124fSSteve Price.Xr ed 1 1903ab72124fSSteve Priceis used as the editor. 190449e11e3aSSheldon Hearn.It Fl l No (ell) 19054b88c807SRodney W. GrimesList the commands rather than invoking 1906eccea571SRuslan Ermilovan editor on them. 1907eccea571SRuslan ErmilovThe commands are written in the 1908dfe302abSRuslan Ermilovsequence indicated by the 1909dfe302abSRuslan Ermilov.Ar first 1910dfe302abSRuslan Ermilovand 1911dfe302abSRuslan Ermilov.Ar last 1912dfe302abSRuslan Ermilovoperands, as affected by 191349e11e3aSSheldon Hearn.Fl r , 191449e11e3aSSheldon Hearnwith each command preceded by the command number. 191549e11e3aSSheldon Hearn.It Fl n 191649e11e3aSSheldon HearnSuppress command numbers when listing with 191749e11e3aSSheldon Hearn.Fl l . 191849e11e3aSSheldon Hearn.It Fl r 191949e11e3aSSheldon HearnReverse the order of the commands listed 192049e11e3aSSheldon Hearn(with 192149e11e3aSSheldon Hearn.Fl l ) 192249e11e3aSSheldon Hearnor edited 192349e11e3aSSheldon Hearn(with neither 192449e11e3aSSheldon Hearn.Fl l 192549e11e3aSSheldon Hearnnor 192649e11e3aSSheldon Hearn.Fl s ) . 192749e11e3aSSheldon Hearn.It Fl s 19284b88c807SRodney W. GrimesRe-execute the command without invoking an editor. 192949e11e3aSSheldon Hearn.It Ar first 193049e11e3aSSheldon Hearn.It Ar last 193149e11e3aSSheldon HearnSelect the commands to list or edit. 193249e11e3aSSheldon HearnThe number of previous commands that can be accessed 193349e11e3aSSheldon Hearnare determined by the value of the 19341788b7ffSJilles Tjoelker.Va HISTSIZE 1935d0353b83SRuslan Ermilovvariable. 193649e11e3aSSheldon HearnThe value of 193749e11e3aSSheldon Hearn.Ar first 193849e11e3aSSheldon Hearnor 193949e11e3aSSheldon Hearn.Ar last 194049e11e3aSSheldon Hearnor both are one of the following: 194181e9cda2SRuslan Ermilov.Bl -tag -width indent 1942dfe302abSRuslan Ermilov.It Oo Cm + Oc Ns Ar num 194349e11e3aSSheldon HearnA positive number representing a command number; 194449e11e3aSSheldon Hearncommand numbers can be displayed with the 194549e11e3aSSheldon Hearn.Fl l 194649e11e3aSSheldon Hearnoption. 1947dfe302abSRuslan Ermilov.It Fl Ar num 194849e11e3aSSheldon HearnA negative decimal number representing the 194949e11e3aSSheldon Hearncommand that was executed 195049e11e3aSSheldon Hearn.Ar num 195149e11e3aSSheldon Hearnof 195249e11e3aSSheldon Hearncommands previously. 1953dfe302abSRuslan ErmilovFor example, \-1 is the immediately previous command. 195449e11e3aSSheldon Hearn.It Ar string 195549e11e3aSSheldon HearnA string indicating the most recently entered command 195649e11e3aSSheldon Hearnthat begins with that string. 195749e11e3aSSheldon HearnIf the 1958dfe302abSRuslan Ermilov.Ar old Ns = Ns Ar new 195949e11e3aSSheldon Hearnoperand is not also specified with 196049e11e3aSSheldon Hearn.Fl s , 196149e11e3aSSheldon Hearnthe string form of the first operand cannot contain an embedded equal sign. 196249e11e3aSSheldon Hearn.El 196349e11e3aSSheldon Hearn.El 196449e11e3aSSheldon Hearn.Pp 19651788b7ffSJilles TjoelkerThe following variables affect the execution of 196649e11e3aSSheldon Hearn.Ic fc : 19671788b7ffSJilles Tjoelker.Bl -tag -width ".Va HISTSIZE" 19681788b7ffSJilles Tjoelker.It Va FCEDIT 196938afdcbcSGiorgos KeramidasName of the editor to use for history editing. 19701788b7ffSJilles Tjoelker.It Va HISTSIZE 19713d7b5b93SPhilippe CharnierThe number of previous commands that are accessible. 1972ab72124fSSteve Price.El 197349e11e3aSSheldon Hearn.It Ic fg Op Ar job 197449e11e3aSSheldon HearnMove the specified 197549e11e3aSSheldon Hearn.Ar job 197649e11e3aSSheldon Hearnor the current job to the foreground. 1977dfe302abSRuslan Ermilov.It Ic getopts Ar optstring var 1978dfe302abSRuslan ErmilovThe 1979dfe302abSRuslan Ermilov.Tn POSIX 198049e11e3aSSheldon Hearn.Ic getopts 198149e11e3aSSheldon Hearncommand. 198249e11e3aSSheldon HearnThe 198349e11e3aSSheldon Hearn.Ic getopts 198449e11e3aSSheldon Hearncommand deprecates the older 198549e11e3aSSheldon Hearn.Xr getopt 1 198649e11e3aSSheldon Hearncommand. 1987ab0a2172SSteve PriceThe first argument should be a series of letters, each possibly 1988ab0a2172SSteve Pricefollowed by a colon which indicates that the option takes an argument. 1989eccea571SRuslan ErmilovThe specified variable is set to the parsed option. 1990eccea571SRuslan ErmilovThe index of 199149e11e3aSSheldon Hearnthe next argument is placed into the shell variable 1992dfe302abSRuslan Ermilov.Va OPTIND . 1993ab0a2172SSteve PriceIf an option takes an argument, it is placed into the shell variable 1994dfe302abSRuslan Ermilov.Va OPTARG . 199549e11e3aSSheldon HearnIf an invalid option is encountered, 1996dfe302abSRuslan Ermilov.Ar var 199749e11e3aSSheldon Hearnis set to 1998dfe302abSRuslan Ermilov.Ql \&? . 1999ab0a2172SSteve PriceIt returns a false value (1) when it encounters the end of the options. 200081e9cda2SRuslan Ermilov.It Ic hash Oo Fl rv Oc Op Ar command ... 200149e11e3aSSheldon HearnThe shell maintains a hash table which remembers the locations of commands. 200249e11e3aSSheldon HearnWith no arguments whatsoever, the 200349e11e3aSSheldon Hearn.Ic hash 200449e11e3aSSheldon Hearncommand prints out the contents of this table. 200549e11e3aSSheldon HearnEntries which have not been looked at since the last 200649e11e3aSSheldon Hearn.Ic cd 200749e11e3aSSheldon Hearncommand are marked with an asterisk; 200849e11e3aSSheldon Hearnit is possible for these entries to be invalid. 2009ab72124fSSteve Price.Pp 201049e11e3aSSheldon HearnWith arguments, the 201149e11e3aSSheldon Hearn.Ic hash 201249e11e3aSSheldon Hearncommand removes each specified 201349e11e3aSSheldon Hearn.Ar command 201449e11e3aSSheldon Hearnfrom the hash table (unless they are functions) and then locates it. 201549e11e3aSSheldon HearnWith the 201649e11e3aSSheldon Hearn.Fl v 201749e11e3aSSheldon Hearnoption, 201849e11e3aSSheldon Hearn.Ic hash 201949e11e3aSSheldon Hearnprints the locations of the commands as it finds them. 202049e11e3aSSheldon HearnThe 202149e11e3aSSheldon Hearn.Fl r 202249e11e3aSSheldon Hearnoption causes the 202349e11e3aSSheldon Hearn.Ic hash 202449e11e3aSSheldon Hearncommand to delete all the entries in the hash table except for functions. 202549e11e3aSSheldon Hearn.It Ic jobid Op Ar job 2026dfe302abSRuslan ErmilovPrint the process IDs of the processes in the specified 202749e11e3aSSheldon Hearn.Ar job . 202849e11e3aSSheldon HearnIf the 202949e11e3aSSheldon Hearn.Ar job 203049e11e3aSSheldon Hearnargument is omitted, use the current job. 2031de37e41cSStefan Farfeleder.It Ic jobs Oo Fl lps Oc Op Ar job ... 2032ad8a0759STim J. RobbinsPrint information about the specified jobs, or all jobs if no 2033ad8a0759STim J. Robbins.Ar job 2034ad8a0759STim J. Robbinsargument is given. 2035ad8a0759STim J. RobbinsThe information printed includes job ID, status and command name. 2036ad8a0759STim J. Robbins.Pp 2037ad8a0759STim J. RobbinsIf the 2038ad8a0759STim J. Robbins.Fl l 2039ad8a0759STim J. Robbinsoption is specified, the PID of each job is also printed. 2040ad8a0759STim J. RobbinsIf the 2041de37e41cSStefan Farfeleder.Fl p 2042de37e41cSStefan Farfelederoption is specified, only the process IDs for the process group leaders 2043de37e41cSStefan Farfelederare printed, one per line. 2044de37e41cSStefan FarfelederIf the 2045ad8a0759STim J. Robbins.Fl s 2046de37e41cSStefan Farfelederoption is specified, only the PIDs of the job commands are printed, one per 2047de37e41cSStefan Farfelederline. 20488af11131SRuslan Ermilov.It Ic local Oo Ar variable ... Oc Op Fl 2049d2f90294SJesus R. CamouSee the 2050d2f90294SJesus R. Camou.Sx Functions 2051d2f90294SJesus R. Camousubsection. 2052*9897c45fSJilles Tjoelker.It Ic printf 2053*9897c45fSJilles TjoelkerA built-in equivalent of 2054*9897c45fSJilles Tjoelker.Xr printf 1 . 2055d74e011fSRuslan Ermilov.It Ic pwd Op Fl L | P 2056eccea571SRuslan ErmilovPrint the path of the current directory. 2057eccea571SRuslan ErmilovThe built-in command may 20584b88c807SRodney W. Grimesdiffer from the program of the same name because the 20598eed22b1SJens Schweikhardtbuilt-in command remembers what the current directory 2060eccea571SRuslan Ermilovis rather than recomputing it each time. 2061eccea571SRuslan ErmilovThis makes 2062eccea571SRuslan Ermilovit faster. 2063eccea571SRuslan ErmilovHowever, if the current directory is 206449e11e3aSSheldon Hearnrenamed, 20658eed22b1SJens Schweikhardtthe built-in version of 206649e11e3aSSheldon Hearn.Xr pwd 1 206749e11e3aSSheldon Hearnwill continue to print the old name for the directory. 2068178897f1STim J. Robbins.Pp 2069178897f1STim J. RobbinsIf the 2070178897f1STim J. Robbins.Fl P 2071178897f1STim J. Robbinsoption is specified, symbolic links are resolved. 2072178897f1STim J. RobbinsIf the 2073178897f1STim J. Robbins.Fl L 2074178897f1STim J. Robbinsoption is specified, the shell's notion of the current directory 2075178897f1STim J. Robbinsis printed (symbolic links are not resolved). 2076178897f1STim J. RobbinsThis is the default. 2077dfe302abSRuslan Ermilov.It Ic read Oo Fl p Ar prompt Oc Oo 2078dfe302abSRuslan Ermilov.Fl t Ar timeout Oc Oo Fl er Oc Ar variable ... 207949e11e3aSSheldon HearnThe 208049e11e3aSSheldon Hearn.Ar prompt 208149e11e3aSSheldon Hearnis printed if the 208249e11e3aSSheldon Hearn.Fl p 208349e11e3aSSheldon Hearnoption is specified 2084eccea571SRuslan Ermilovand the standard input is a terminal. 2085eccea571SRuslan ErmilovThen a line is 2086eccea571SRuslan Ermilovread from the standard input. 2087eccea571SRuslan ErmilovThe trailing newline 20884b88c807SRodney W. Grimesis deleted from the line and the line is split as 208949e11e3aSSheldon Hearndescribed in the section on 209049e11e3aSSheldon Hearn.Sx White Space Splitting (Field Splitting) 209149e11e3aSSheldon Hearnabove, and 20924b88c807SRodney W. Grimesthe pieces are assigned to the variables in order. 2093f434d1dfSAdam DavidIf there are more pieces than variables, the remaining 209449e11e3aSSheldon Hearnpieces (along with the characters in 2095dfe302abSRuslan Ermilov.Va IFS 209649e11e3aSSheldon Hearnthat separated them) 209749e11e3aSSheldon Hearnare assigned to the last variable. 2098f434d1dfSAdam DavidIf there are more variables than pieces, the remaining 2099f434d1dfSAdam Davidvariables are assigned the null string. 2100ab72124fSSteve Price.Pp 210149e11e3aSSheldon HearnBackslashes are treated specially, unless the 210249e11e3aSSheldon Hearn.Fl r 210349e11e3aSSheldon Hearnoption is 2104eccea571SRuslan Ermilovspecified. 2105eccea571SRuslan ErmilovIf a backslash is followed by 21068f0561ccSThomas Gellekuma newline, the backslash and the newline will be 2107eccea571SRuslan Ermilovdeleted. 2108eccea571SRuslan ErmilovIf a backslash is followed by any other 21098f0561ccSThomas Gellekumcharacter, the backslash will be deleted and the following 211049e11e3aSSheldon Hearncharacter will be treated as though it were not in 2111dfe302abSRuslan Ermilov.Va IFS , 211249e11e3aSSheldon Hearneven if it is. 21138f0561ccSThomas Gellekum.Pp 211449e11e3aSSheldon HearnIf the 211549e11e3aSSheldon Hearn.Fl t 211649e11e3aSSheldon Hearnoption is specified and the 211749e11e3aSSheldon Hearn.Ar timeout 2118fe40d6d3SJilles Tjoelkerelapses before a complete line of input is supplied, 211949e11e3aSSheldon Hearnthe 212049e11e3aSSheldon Hearn.Ic read 21211b161559SStefan Farfeledercommand will return an exit status of 1 without assigning any values. 212249e11e3aSSheldon HearnThe 212349e11e3aSSheldon Hearn.Ar timeout 212449e11e3aSSheldon Hearnvalue may optionally be followed by one of 2125dfe302abSRuslan Ermilov.Ql s , 2126dfe302abSRuslan Ermilov.Ql m 212749e11e3aSSheldon Hearnor 2128dfe302abSRuslan Ermilov.Ql h 2129a910f192SDima Dorfmanto explicitly specify seconds, minutes or hours. 213049e11e3aSSheldon HearnIf none is supplied, 2131dfe302abSRuslan Ermilov.Ql s 213249e11e3aSSheldon Hearnis assumed. 2133afa53c8dSMike Smith.Pp 213449e11e3aSSheldon HearnThe 213549e11e3aSSheldon Hearn.Fl e 213649e11e3aSSheldon Hearnoption exists only for backward compatibility with older scripts. 21379ba31ca0SRuslan Ermilov.It Ic readonly Oo Fl p Oc Op Ar name ... 213849e11e3aSSheldon HearnEach specified 213949e11e3aSSheldon Hearn.Ar name 214049e11e3aSSheldon Hearnis marked as read only, 214149e11e3aSSheldon Hearnso that it cannot be subsequently modified or unset. 214249e11e3aSSheldon HearnThe shell allows the value of a variable to be set 214349e11e3aSSheldon Hearnat the same time as it is marked read only 214449e11e3aSSheldon Hearnby using the following form: 2145dfe302abSRuslan Ermilov.Pp 2146dfe302abSRuslan Ermilov.D1 Ic readonly Ar name Ns = Ns Ar value 2147ab72124fSSteve Price.Pp 214849e11e3aSSheldon HearnWith no arguments the 214949e11e3aSSheldon Hearn.Ic readonly 215049e11e3aSSheldon Hearncommand lists the names of all read only variables. 215145086f8cSTim J. RobbinsIf the 215245086f8cSTim J. Robbins.Fl p 215345086f8cSTim J. Robbinsoption is specified, the read-only variables are printed as 215445086f8cSTim J. Robbins.Dq Ic readonly Ar name Ns = Ns Ar value 215545086f8cSTim J. Robbinslines, suitable for re-input to the shell. 2156d2f90294SJesus R. Camou.It Ic return Op Ar exitstatus 2157d2f90294SJesus R. CamouSee the 2158d2f90294SJesus R. Camou.Sx Functions 2159d2f90294SJesus R. Camousubsection. 216081e9cda2SRuslan Ermilov.It Ic set Oo Fl /+abCEefIimnpTuVvx Oc Oo Fl /+o Ar longname Oc Oo 216181e9cda2SRuslan Ermilov.Fl c Ar string Oc Op Fl - Ar arg ... 2162e918fc8fSSheldon HearnThe 2163e918fc8fSSheldon Hearn.Ic set 2164e918fc8fSSheldon Hearncommand performs three different functions: 2165ab72124fSSteve Price.Bl -item 2166ab72124fSSteve Price.It 216749e11e3aSSheldon HearnWith no arguments, it lists the values of all shell variables. 2168ab72124fSSteve Price.It 216949e11e3aSSheldon HearnIf options are given, 217049e11e3aSSheldon Hearneither in short form or using the long 217149e11e3aSSheldon Hearn.Dq Fl /+o Ar longname 217249e11e3aSSheldon Hearnform, 217349e11e3aSSheldon Hearnit sets or clears the specified options as described in the section called 21746b15476eSSheldon Hearn.Sx Argument List Processing . 2175ab72124fSSteve Price.It 217649e11e3aSSheldon HearnIf the 217749e11e3aSSheldon Hearn.Dq Fl - 217849e11e3aSSheldon Hearnoption is specified, 217949e11e3aSSheldon Hearn.Ic set 218049e11e3aSSheldon Hearnwill replace the shell's positional parameters with the subsequent 218149e11e3aSSheldon Hearnarguments. 218249e11e3aSSheldon HearnIf no arguments follow the 218349e11e3aSSheldon Hearn.Dq Fl - 218449e11e3aSSheldon Hearnoption, 218549e11e3aSSheldon Hearnall the positional parameters will be cleared, 218649e11e3aSSheldon Hearnwhich is equivalent to executing the command 2187dfe302abSRuslan Ermilov.Dq Li "shift $#" . 218849e11e3aSSheldon HearnThe 218949e11e3aSSheldon Hearn.Dq Fl - 21908eed22b1SJens Schweikhardtflag may be omitted when specifying arguments to be used 219149e11e3aSSheldon Hearnas positional replacement parameters. 219249e11e3aSSheldon HearnThis is not recommended, 219349e11e3aSSheldon Hearnbecause the first argument may begin with a dash 2194a762afe5SGiorgos Keramidas.Pq Ql - 219549e11e3aSSheldon Hearnor a plus 2196a762afe5SGiorgos Keramidas.Pq Ql + , 219749e11e3aSSheldon Hearnwhich the 219849e11e3aSSheldon Hearn.Ic set 219949e11e3aSSheldon Hearncommand will interpret as a request to enable or disable options. 2200ab72124fSSteve Price.El 2201dfe302abSRuslan Ermilov.It Ic setvar Ar variable value 220249e11e3aSSheldon HearnAssigns the specified 220349e11e3aSSheldon Hearn.Ar value 220449e11e3aSSheldon Hearnto the specified 220549e11e3aSSheldon Hearn.Ar variable . 2206dfe302abSRuslan ErmilovThe 2207dfe302abSRuslan Ermilov.Ic setvar 2208dfe302abSRuslan Ermilovcommand is intended to be used in functions that 2209e6d3cf26SSheldon Hearnassign values to variables whose names are passed as parameters. 221049e11e3aSSheldon HearnIn general it is better to write 2211dfe302abSRuslan Ermilov.Dq Ar variable Ns = Ns Ar value 221249e11e3aSSheldon Hearnrather than using 221349e11e3aSSheldon Hearn.Ic setvar . 221449e11e3aSSheldon Hearn.It Ic shift Op Ar n 221549e11e3aSSheldon HearnShift the positional parameters 221649e11e3aSSheldon Hearn.Ar n 2217e918fc8fSSheldon Hearntimes, or once if 221849e11e3aSSheldon Hearn.Ar n 221949e11e3aSSheldon Hearnis not specified. 2220dfe302abSRuslan ErmilovA shift sets the value of 2221dfe302abSRuslan Ermilov.Li $1 2222dfe302abSRuslan Ermilovto the value of 2223dfe302abSRuslan Ermilov.Li $2 , 2224dfe302abSRuslan Ermilovthe value of 2225dfe302abSRuslan Ermilov.Li $2 2226dfe302abSRuslan Ermilovto the value of 2227dfe302abSRuslan Ermilov.Li $3 , 2228dfe302abSRuslan Ermilovand so on, 2229dfe302abSRuslan Ermilovdecreasing the value of 2230dfe302abSRuslan Ermilov.Li $# 2231dfe302abSRuslan Ermilovby one. 223249e11e3aSSheldon HearnIf there are zero positional parameters, shifting does not do anything. 223310845922SYaroslav Tykhiy.It Ic test 223410845922SYaroslav TykhiyA built-in equivalent of 223510845922SYaroslav Tykhiy.Xr test 1 . 22361974986aSStefan Farfeleder.It Ic times 22371974986aSStefan FarfelederPrint the amount of time spent executing the shell and its children. 22381974986aSStefan FarfelederThe first output line shows the user and system times for the shell 22391974986aSStefan Farfelederitself, the second one contains the user and system times for the 22401974986aSStefan Farfelederchildren. 224181e9cda2SRuslan Ermilov.It Ic trap Oo Ar action Oc Ar signal ... 22420673e800SStefan Farfeleder.It Ic trap Fl l 224349e11e3aSSheldon HearnCause the shell to parse and execute 224449e11e3aSSheldon Hearn.Ar action 224549e11e3aSSheldon Hearnwhen any specified 224649e11e3aSSheldon Hearn.Ar signal 224749e11e3aSSheldon Hearnis received. 2248162ae3aeSTony FinchThe signals are specified by name or number. 2249162ae3aeSTony FinchIn addition, the pseudo-signal 2250f5d1157fSRuslan Ermilov.Cm EXIT 2251dfe302abSRuslan Ermilovmay be used to specify an 2252dfe302abSRuslan Ermilov.Ar action 2253dfe302abSRuslan Ermilovthat is performed when the shell terminates. 225449e11e3aSSheldon HearnThe 225549e11e3aSSheldon Hearn.Ar action 22560673e800SStefan Farfeledermay be an empty string or a dash 22579badf57fSRuslan Ermilov.Pq Ql - ; 225849e11e3aSSheldon Hearnthe former causes the specified signal to be ignored 225949e11e3aSSheldon Hearnand the latter causes the default action to be taken. 22600673e800SStefan FarfelederOmitting the 22610673e800SStefan Farfeleder.Ar action 22620673e800SStefan Farfelederis another way to request the default action, for compatibility reasons this 22630673e800SStefan Farfelederusage is not recommended though. 226449e11e3aSSheldon HearnWhen the shell forks off a subshell, 226549e11e3aSSheldon Hearnit resets trapped (but not ignored) signals to the default action. 226649e11e3aSSheldon HearnThe 226749e11e3aSSheldon Hearn.Ic trap 226849e11e3aSSheldon Hearncommand has no effect on signals that were ignored on entry to the shell. 22690673e800SStefan Farfeleder.Pp 22700673e800SStefan FarfelederOption 22710673e800SStefan Farfeleder.Fl l 22720673e800SStefan Farfeledercauses the 22730673e800SStefan Farfeleder.Ic trap 22740673e800SStefan Farfeledercommand to display a list of valid signal names. 2275a6557dcbSYaroslav Tykhiy.It Ic true 2276a6557dcbSYaroslav TykhiyA null command that returns a 0 (true) exit value. 227749e11e3aSSheldon Hearn.It Ic type Op Ar name ... 227849e11e3aSSheldon HearnInterpret each 227949e11e3aSSheldon Hearn.Ar name 228049e11e3aSSheldon Hearnas a command and print the resolution of the command search. 2281e6d3cf26SSheldon HearnPossible resolutions are: 228230268dfaSJilles Tjoelkershell keyword, alias, special shell builtin, shell builtin, command, 228330268dfaSJilles Tjoelkertracked alias 228449e11e3aSSheldon Hearnand not found. 228549e11e3aSSheldon HearnFor aliases the alias expansion is printed; 228649e11e3aSSheldon Hearnfor commands and tracked aliases 228749e11e3aSSheldon Hearnthe complete pathname of the command is printed. 2288c8054a61SJilles Tjoelker.It Ic ulimit Oo Fl HSabcdflmnpstuvw Oc Op Ar limit 2289ab72124fSSteve PriceSet or display resource limits (see 2290ab72124fSSteve Price.Xr getrlimit 2 ) . 22916b15476eSSheldon HearnIf 229249e11e3aSSheldon Hearn.Ar limit 22936b15476eSSheldon Hearnis specified, the named resource will be set; 22947a2afe64SJoerg Wunschotherwise the current resource value will be displayed. 2295ab72124fSSteve Price.Pp 22966b15476eSSheldon HearnIf 229749e11e3aSSheldon Hearn.Fl H 229849e11e3aSSheldon Hearnis specified, the hard limits will be set or displayed. 229949e11e3aSSheldon HearnWhile everybody is allowed to reduce a hard limit, 230049e11e3aSSheldon Hearnonly the superuser can increase it. 230149e11e3aSSheldon HearnThe 230249e11e3aSSheldon Hearn.Fl S 230349e11e3aSSheldon Hearnoption 2304eccea571SRuslan Ermilovspecifies the soft limits instead. 2305eccea571SRuslan ErmilovWhen displaying limits, 23066b15476eSSheldon Hearnonly one of 230749e11e3aSSheldon Hearn.Fl S 23086b15476eSSheldon Hearnor 230949e11e3aSSheldon Hearn.Fl H 231049e11e3aSSheldon Hearncan be given. 231149e11e3aSSheldon HearnThe default is to display the soft limits, 231249e11e3aSSheldon Hearnand to set both the hard and the soft limits. 2313ab72124fSSteve Price.Pp 23146b15476eSSheldon HearnOption 231549e11e3aSSheldon Hearn.Fl a 231649e11e3aSSheldon Hearncauses the 231749e11e3aSSheldon Hearn.Ic ulimit 231849e11e3aSSheldon Hearncommand to display all resources. 231949e11e3aSSheldon HearnThe parameter 232049e11e3aSSheldon Hearn.Ar limit 23216b15476eSSheldon Hearnis not acceptable in this mode. 2322ab72124fSSteve Price.Pp 23237a2afe64SJoerg WunschThe remaining options specify which resource value is to be 232449e11e3aSSheldon Hearndisplayed or modified. 232549e11e3aSSheldon HearnThey are mutually exclusive. 232681e9cda2SRuslan Ermilov.Bl -tag -width indent 23273652a236SMartin Cracauer.It Fl b Ar sbsize 23283652a236SMartin CracauerThe maximum size of socket buffer usage, in bytes. 232949e11e3aSSheldon Hearn.It Fl c Ar coredumpsize 23307a2afe64SJoerg WunschThe maximal size of core dump files, in 512-byte blocks. 233149e11e3aSSheldon Hearn.It Fl d Ar datasize 23327a2afe64SJoerg WunschThe maximal size of the data segment of a process, in kilobytes. 233349e11e3aSSheldon Hearn.It Fl f Ar filesize 233449e11e3aSSheldon HearnThe maximal size of a file, in 512-byte blocks. 233549e11e3aSSheldon Hearn.It Fl l Ar lockedmem 23367a2afe64SJoerg WunschThe maximal size of memory that can be locked by a process, in 23377a2afe64SJoerg Wunschkilobytes. 233849e11e3aSSheldon Hearn.It Fl m Ar memoryuse 23397a2afe64SJoerg WunschThe maximal resident set size of a process, in kilobytes. 234049e11e3aSSheldon Hearn.It Fl n Ar nofiles 23417a2afe64SJoerg WunschThe maximal number of descriptors that could be opened by a process. 2342331773cdSEd Schouten.It Fl p Ar pseudoterminals 2343331773cdSEd SchoutenThe maximal number of pseudo-terminals for this user ID. 234449e11e3aSSheldon Hearn.It Fl s Ar stacksize 23457a2afe64SJoerg WunschThe maximal size of the stack segment, in kilobytes. 234649e11e3aSSheldon Hearn.It Fl t Ar time 23477a2afe64SJoerg WunschThe maximal amount of CPU time to be used by each process, in seconds. 234849e11e3aSSheldon Hearn.It Fl u Ar userproc 2349ab72124fSSteve PriceThe maximal number of simultaneous processes for this user ID. 235062df9b62SSheldon Hearn.It Fl v Ar virtualmem 23512d41ef4bSMatthew DillonThe maximal virtual size of a process, in kilobytes. 2352c8054a61SJilles Tjoelker.It Fl w Ar swapuse 2353c8054a61SJilles TjoelkerThe maximum amount of swap space reserved or used for this user ID, 2354c8054a61SJilles Tjoelkerin kilobytes. 2355ab72124fSSteve Price.El 2356faa1ed35SStefan Farfeleder.It Ic umask Oo Fl S Oc Op Ar mask 235749e11e3aSSheldon HearnSet the file creation mask (see 2358ab72124fSSteve Price.Xr umask 2 ) 2359faa1ed35SStefan Farfelederto the octal or symbolic (see 2360faa1ed35SStefan Farfeleder.Xr chmod 1 ) 2361faa1ed35SStefan Farfeledervalue specified by 23625d3b843bSSheldon Hearn.Ar mask . 236349e11e3aSSheldon HearnIf the argument is omitted, the current mask value is printed. 2364faa1ed35SStefan FarfelederIf the 2365faa1ed35SStefan Farfeleder.Fl S 2366faa1ed35SStefan Farfelederoption is specified, the output is symbolic, otherwise the output is octal. 2367de4ad382SStefan Farfeleder.It Ic unalias Oo Fl a Oc Op Ar name ... 2368de4ad382SStefan FarfelederThe specified alias names are removed. 23696b15476eSSheldon HearnIf 23701b9735e6SSheldon Hearn.Fl a 23716b15476eSSheldon Hearnis specified, all aliases are removed. 23729ba31ca0SRuslan Ermilov.It Ic unset Oo Fl fv Oc Ar name ... 23738b34ad92STim J. RobbinsThe specified variables or functions are unset and unexported. 23748b34ad92STim J. RobbinsIf the 23758b34ad92STim J. Robbins.Fl v 23768b34ad92STim J. Robbinsoption is specified or no options are given, the 237749e11e3aSSheldon Hearn.Ar name 23788b34ad92STim J. Robbinsarguments are treated as variable names. 23798b34ad92STim J. RobbinsIf the 23808b34ad92STim J. Robbins.Fl f 23818b34ad92STim J. Robbinsoption is specified, the 23828b34ad92STim J. Robbins.Ar name 23838b34ad92STim J. Robbinsarguments are treated as function names. 238449e11e3aSSheldon Hearn.It Ic wait Op Ar job 238549e11e3aSSheldon HearnWait for the specified 238649e11e3aSSheldon Hearn.Ar job 238749e11e3aSSheldon Hearnto complete and return the exit status of the last process in the 238849e11e3aSSheldon Hearn.Ar job . 2389e6d3cf26SSheldon HearnIf the argument is omitted, wait for all jobs to complete 2390e6d3cf26SSheldon Hearnand return an exit status of zero. 2391ab72124fSSteve Price.El 2392ab72124fSSteve Price.Ss Commandline Editing 2393ab72124fSSteve PriceWhen 2394ab72124fSSteve Price.Nm 2395ab72124fSSteve Priceis being used interactively from a terminal, the current command 239649e11e3aSSheldon Hearnand the command history 239749e11e3aSSheldon Hearn(see 239849e11e3aSSheldon Hearn.Ic fc 239949e11e3aSSheldon Hearnin 24008eed22b1SJens Schweikhardt.Sx Built-in Commands ) 2401dfe302abSRuslan Ermilovcan be edited using 2402dfe302abSRuslan Ermilov.Nm vi Ns -mode 2403dfe302abSRuslan Ermilovcommand line editing. 240449e11e3aSSheldon HearnThis mode uses commands similar 2405dfe302abSRuslan Ermilovto a subset of those described in the 2406dfe302abSRuslan Ermilov.Xr vi 1 2407dfe302abSRuslan Ermilovman page. 240849e11e3aSSheldon HearnThe command 2409dfe302abSRuslan Ermilov.Dq Li "set -o vi" 241049e11e3aSSheldon Hearn(or 2411dfe302abSRuslan Ermilov.Dq Li "set -V" ) 2412dfe302abSRuslan Ermilovenables 2413dfe302abSRuslan Ermilov.Nm vi Ns -mode 2414dfe302abSRuslan Ermilovediting and places 2415ab72124fSSteve Price.Nm 2416dfe302abSRuslan Ermilovinto 2417dfe302abSRuslan Ermilov.Nm vi 2418dfe302abSRuslan Ermilovinsert mode. 2419dfe302abSRuslan ErmilovWith 2420dfe302abSRuslan Ermilov.Nm vi Ns -mode 2421dfe302abSRuslan Ermilovenabled, 2422ab72124fSSteve Price.Nm 242349e11e3aSSheldon Hearncan be switched between insert mode and command mode by typing 242449e11e3aSSheldon Hearn.Aq ESC . 242549e11e3aSSheldon HearnHitting 242649e11e3aSSheldon Hearn.Aq return 242749e11e3aSSheldon Hearnwhile in command mode will pass the line to the shell. 2428ab72124fSSteve Price.Pp 242949e11e3aSSheldon HearnSimilarly, the 2430dfe302abSRuslan Ermilov.Dq Li "set -o emacs" 243149e11e3aSSheldon Hearn(or 2432dfe302abSRuslan Ermilov.Dq Li "set -E" ) 243349e11e3aSSheldon Hearncommand can be used to enable a subset of 2434dfe302abSRuslan Ermilov.Nm emacs Ns -style 2435dfe302abSRuslan Ermilovcommand line editing features. 243638afdcbcSGiorgos Keramidas.Sh ENVIRONMENT 243738afdcbcSGiorgos KeramidasThe following environment variables affect the execution of 243838afdcbcSGiorgos Keramidas.Nm : 24391788b7ffSJilles Tjoelker.Bl -tag -width ".Ev LANGXXXXXX" 24401788b7ffSJilles Tjoelker.It Ev ENV 24411788b7ffSJilles TjoelkerInitialization file for interactive shells. 24421788b7ffSJilles Tjoelker.It Ev LANG , Ev LC_* 24431788b7ffSJilles TjoelkerLocale settings. 24441788b7ffSJilles TjoelkerThese are inherited by children of the shell, 24451788b7ffSJilles Tjoelkerand is used in a limited manner by the shell itself. 24461788b7ffSJilles Tjoelker.It Ev PWD 24471788b7ffSJilles TjoelkerAn absolute pathname for the current directory, 24481788b7ffSJilles Tjoelkerpossibly containing symbolic links. 24491788b7ffSJilles TjoelkerThis is used and updated by the shell. 245038afdcbcSGiorgos Keramidas.It Ev TERM 245138afdcbcSGiorgos KeramidasThe default terminal setting for the shell. 245238afdcbcSGiorgos KeramidasThis is inherited by children of the shell, and is used in the history 245338afdcbcSGiorgos Keramidasediting modes. 245438afdcbcSGiorgos Keramidas.El 24551788b7ffSJilles Tjoelker.Pp 24561788b7ffSJilles TjoelkerAdditionally, all environment variables are turned into shell variables 24571788b7ffSJilles Tjoelkerat startup, 24581788b7ffSJilles Tjoelkerwhich may affect the shell as described under 24591788b7ffSJilles Tjoelker.Sx Special Variables . 2460fb039b55SRuslan Ermilov.Sh EXIT STATUS 2461fb039b55SRuslan ErmilovErrors that are detected by the shell, such as a syntax error, will 2462fb039b55SRuslan Ermilovcause the shell to exit with a non-zero exit status. 2463fb039b55SRuslan ErmilovIf the shell is not an interactive shell, the execution of the shell 2464fb039b55SRuslan Ermilovfile will be aborted. 2465fb039b55SRuslan ErmilovOtherwise the shell will return the exit status of the last command 2466dfe302abSRuslan Ermilovexecuted, or if the 2467dfe302abSRuslan Ermilov.Ic exit 2468dfe302abSRuslan Ermilovbuiltin is used with a numeric argument, it 2469fb039b55SRuslan Ermilovwill return the argument. 2470c83e7c50SJoseph Koshy.Sh SEE ALSO 2471c644db6aSSheldon Hearn.Xr builtin 1 , 247238afdcbcSGiorgos Keramidas.Xr chsh 1 , 2473c644db6aSSheldon Hearn.Xr echo 1 , 247438afdcbcSGiorgos Keramidas.Xr ed 1 , 247538afdcbcSGiorgos Keramidas.Xr emacs 1 , 2476*9897c45fSJilles Tjoelker.Xr printf 1 , 24775521ff5aSRuslan Ermilov.Xr pwd 1 , 247838afdcbcSGiorgos Keramidas.Xr test 1 , 247938afdcbcSGiorgos Keramidas.Xr vi 1 , 248038afdcbcSGiorgos Keramidas.Xr execve 2 , 248138afdcbcSGiorgos Keramidas.Xr getrlimit 2 , 2482fd50df30SRuslan Ermilov.Xr umask 2 , 248338afdcbcSGiorgos Keramidas.Xr editrc 5 2484ab72124fSSteve Price.Sh HISTORY 2485b8923d4cSWolfram SchneiderA 2486ab72124fSSteve Price.Nm 24879cdd1e3fSYaroslav Tykhiycommand, the Thompson shell, appeared in 2488fc482908STim J. Robbins.At v1 . 24899cdd1e3fSYaroslav TykhiyIt was superseded in 24909cdd1e3fSYaroslav Tykhiy.At v7 24919cdd1e3fSYaroslav Tykhiyby the Bourne shell, which inherited the name 24929cdd1e3fSYaroslav Tykhiy.Nm . 24939cdd1e3fSYaroslav Tykhiy.Pp 24949cdd1e3fSYaroslav TykhiyThis version of 24959cdd1e3fSYaroslav Tykhiy.Nm 24969cdd1e3fSYaroslav Tykhiywas rewritten in 1989 under the 24979cdd1e3fSYaroslav Tykhiy.Bx 24989cdd1e3fSYaroslav Tykhiylicense after the Bourne shell from 24999cdd1e3fSYaroslav Tykhiy.At V.4 . 25009cdd1e3fSYaroslav Tykhiy.Sh AUTHORS 25019cdd1e3fSYaroslav TykhiyThis version of 25029cdd1e3fSYaroslav Tykhiy.Nm 25039badf57fSRuslan Ermilovwas originally written by 25049badf57fSRuslan Ermilov.An Kenneth Almquist . 2505128dc4a2STim J. Robbins.Sh BUGS 2506128dc4a2STim J. RobbinsThe 2507128dc4a2STim J. Robbins.Nm 2508128dc4a2STim J. Robbinsutility does not recognize multibyte characters. 2509