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.\" 357b6779b6SJilles Tjoelker.Dd January 30, 2016 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 43455b6546SDaichi GOTO.Op Fl /+abCEefhIimnPpTuVvx 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 50455b6546SDaichi GOTO.Op Fl /+abCEefhIimnPpTuVvx 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 58455b6546SDaichi GOTO.Op Fl /+abCEefhIimnPpTuVvx 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 1271a62d884SJilles Tjoelkerof a login shell, the shell then subjects its value to parameter expansion 1281a62d884SJilles Tjoelkerand arithmetic expansion and reads commands from the named file. 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 1415dd78c9fSJoel Dahl.Pa .shrc 14249e11e3aSSheldon Hearnthe filename desired: 14349e11e3aSSheldon Hearn.Pp 1445dd78c9fSJoel Dahl.Dl "ENV=$HOME/.shrc; 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 !\& 238b14cfdf6SJilles Tjoelkerkeyword. 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. 242b14cfdf6SJilles Tjoelker.Pp 243b14cfdf6SJilles TjoelkerIt is recommended to check for failures explicitly 244b14cfdf6SJilles Tjoelkerinstead of relying on 245b14cfdf6SJilles Tjoelker.Fl e 246b14cfdf6SJilles Tjoelkerbecause it tends to behave in unexpected ways, 247b14cfdf6SJilles Tjoelkerparticularly in larger scripts. 248ab72124fSSteve Price.It Fl f Li noglob 2494b88c807SRodney W. GrimesDisable pathname expansion. 25054b16435SJilles Tjoelker.It Fl h Li trackall 25154b16435SJilles TjoelkerA do-nothing option for 25254b16435SJilles Tjoelker.Tn POSIX 25354b16435SJilles Tjoelkercompliance. 254ab72124fSSteve Price.It Fl I Li ignoreeof 25549e11e3aSSheldon HearnIgnore 256dfe302abSRuslan Ermilov.Dv EOF Ap s 25749e11e3aSSheldon Hearnfrom input when in interactive mode. 258ab72124fSSteve Price.It Fl i Li interactive 259ab72124fSSteve PriceForce the shell to behave interactively. 260ab72124fSSteve Price.It Fl m Li monitor 261ab72124fSSteve PriceTurn on job control (set automatically when interactive). 262cd60e2c6SJilles TjoelkerA new process group is created for each pipeline (called a job). 263cd60e2c6SJilles TjoelkerIt is possible to suspend jobs or to have them run in the foreground or 264cd60e2c6SJilles Tjoelkerin the background. 265cd60e2c6SJilles TjoelkerIn a non-interactive shell, 266cd60e2c6SJilles Tjoelkerthis option can be set even if no terminal is available 267cd60e2c6SJilles Tjoelkerand is useful to place processes in separate process groups. 268ab72124fSSteve Price.It Fl n Li noexec 2694b88c807SRodney W. GrimesIf not interactive, read commands but do not 270eccea571SRuslan Ermilovexecute them. 271eccea571SRuslan ErmilovThis is useful for checking the 2724b88c807SRodney W. Grimessyntax of shell scripts. 2737e1975c2STim J. Robbins.It Fl P Li physical 2747e1975c2STim J. RobbinsChange the default for the 2757e1975c2STim J. Robbins.Ic cd 2767e1975c2STim J. Robbinsand 2777e1975c2STim J. Robbins.Ic pwd 2787e1975c2STim J. Robbinscommands from 2797e1975c2STim J. Robbins.Fl L 2807e1975c2STim J. Robbins(logical directory layout) 2817e1975c2STim J. Robbinsto 2827e1975c2STim J. Robbins.Fl P 2837e1975c2STim J. Robbins(physical directory layout). 284ab72124fSSteve Price.It Fl p Li privileged 285eccea571SRuslan ErmilovTurn on privileged mode. 286eccea571SRuslan ErmilovThis mode is enabled on startup 287dfe302abSRuslan Ermilovif either the effective user or group ID is not equal to the 288dfe302abSRuslan Ermilovreal user or group ID. 289eccea571SRuslan ErmilovTurning this mode off sets the 290dfe302abSRuslan Ermiloveffective user and group IDs to the real user and group IDs. 29149e11e3aSSheldon HearnWhen this mode is enabled for interactive shells, the file 292ab72124fSSteve Price.Pa /etc/suid_profile 29349e11e3aSSheldon Hearnis sourced instead of 29449e11e3aSSheldon Hearn.Pa ~/.profile 295ab72124fSSteve Priceafter 296ab72124fSSteve Price.Pa /etc/profile 29749e11e3aSSheldon Hearnis sourced, and the contents of the 298ab72124fSSteve Price.Ev ENV 29949e11e3aSSheldon Hearnvariable are ignored. 300ab72124fSSteve Price.It Fl s Li stdin 3014b88c807SRodney W. GrimesRead commands from standard input (set automatically 302eccea571SRuslan Ermilovif no file arguments are present). 303eccea571SRuslan ErmilovThis option has 3044b88c807SRodney W. Grimesno effect when set after the shell has already started 305eccea571SRuslan Ermilovrunning (i.e., when set with the 306c644db6aSSheldon Hearn.Ic set 3076b15476eSSheldon Hearncommand). 308304199ceSTom Rhodes.It Fl T Li trapsasync 309e6d3cf26SSheldon HearnWhen waiting for a child, execute traps immediately. 310e6d3cf26SSheldon HearnIf this option is not set, 311e6d3cf26SSheldon Hearntraps are executed after the child exits, 312e6d3cf26SSheldon Hearnas specified in 313af5eb6fcSMaxim Konovalov.St -p1003.2 . 3146b15476eSSheldon HearnThis nonstandard option is useful for putting guarding shells around 315eccea571SRuslan Ermilovchildren that block signals. 316eccea571SRuslan ErmilovThe surrounding shell may kill the child 3176b15476eSSheldon Hearnor it may just return control to the tty and leave the child alone, 3186b15476eSSheldon Hearnlike this: 319c1c72a3cSMartin Cracauer.Bd -literal -offset indent 320c1c72a3cSMartin Cracauersh -T -c "trap 'exit 1' 2 ; some-blocking-program" 321c1c72a3cSMartin Cracauer.Ed 322ab72124fSSteve Price.It Fl u Li nounset 323ab72124fSSteve PriceWrite a message to standard error when attempting 32464254a66SJilles Tjoelkerto expand a variable, a positional parameter or 32564254a66SJilles Tjoelkerthe special parameter 32664254a66SJilles Tjoelker.Va \&! 32764254a66SJilles Tjoelkerthat is not set, and if the 328ab72124fSSteve Priceshell is not interactive, exit immediately. 329ab72124fSSteve Price.It Fl V Li vi 3308eed22b1SJens SchweikhardtEnable the built-in 331ab72124fSSteve Price.Xr vi 1 332ab72124fSSteve Pricecommand line editor (disables 333ab72124fSSteve Price.Fl E 334ab72124fSSteve Priceif it has been set). 335ab72124fSSteve Price.It Fl v Li verbose 336ab72124fSSteve PriceThe shell writes its input to standard error 337eccea571SRuslan Ermilovas it is read. 338eccea571SRuslan ErmilovUseful for debugging. 339ab72124fSSteve Price.It Fl x Li xtrace 34049e11e3aSSheldon HearnWrite each command 341120c8e6cSStefan Farfeleder(preceded by the value of the 342dfe302abSRuslan Ermilov.Va PS4 343292e6676SJilles Tjoelkervariable subjected to parameter expansion and arithmetic expansion) 34449e11e3aSSheldon Hearnto standard error before it is executed. 34549e11e3aSSheldon HearnUseful for debugging. 34662c37116SJilles Tjoelker.It nolog 34762c37116SJilles TjoelkerAnother do-nothing option for 34862c37116SJilles Tjoelker.Tn POSIX 34962c37116SJilles Tjoelkercompliance. 35062c37116SJilles TjoelkerIt only has a long name. 35149e11e3aSSheldon Hearn.El 35249e11e3aSSheldon Hearn.Pp 35349e11e3aSSheldon HearnThe 354fd50df30SRuslan Ermilov.Fl c 355fd50df30SRuslan Ermilovoption causes the commands to be read from the 356fd50df30SRuslan Ermilov.Ar string 357fd50df30SRuslan Ermilovoperand instead of from the standard input. 358fd50df30SRuslan ErmilovKeep in mind that this option only accepts a single string as its 359fd50df30SRuslan Ermilovargument, hence multi-word strings must be quoted. 360fd50df30SRuslan Ermilov.Pp 361fd50df30SRuslan ErmilovThe 36249e11e3aSSheldon Hearn.Fl /+o 36349e11e3aSSheldon Hearnoption takes as its only argument the long name of an option 36449e11e3aSSheldon Hearnto be enabled or disabled. 36549e11e3aSSheldon HearnFor example, the following two invocations of 36649e11e3aSSheldon Hearn.Nm 3678eed22b1SJens Schweikhardtboth enable the built-in 36849e11e3aSSheldon Hearn.Xr emacs 1 36949e11e3aSSheldon Hearncommand line editor: 37049e11e3aSSheldon Hearn.Bd -literal -offset indent 37149e11e3aSSheldon Hearnset -E 37249e11e3aSSheldon Hearnset -o emacs 37349e11e3aSSheldon Hearn.Ed 374d513af6aSTim J. Robbins.Pp 375d513af6aSTim J. RobbinsIf used without an argument, the 376d513af6aSTim J. Robbins.Fl o 377d513af6aSTim J. Robbinsoption displays the current option settings in a human-readable format. 378d513af6aSTim J. RobbinsIf 379d513af6aSTim J. Robbins.Cm +o 380d513af6aSTim J. Robbinsis used without an argument, the current option settings are output 381d513af6aSTim J. Robbinsin a format suitable for re-input into the shell. 382ab72124fSSteve Price.Ss Lexical Structure 3834b88c807SRodney W. GrimesThe shell reads input in terms of lines from a file and breaks 3844b88c807SRodney W. Grimesit up into words at whitespace (blanks and tabs), and at 3854b88c807SRodney W. Grimescertain sequences of 3866b15476eSSheldon Hearncharacters called 3876b15476eSSheldon Hearn.Dq operators , 3886b15476eSSheldon Hearnwhich are special to the shell. 3894b88c807SRodney W. GrimesThere are two types of operators: control operators and 3904b88c807SRodney W. Grimesredirection operators (their meaning is discussed later). 391ab72124fSSteve PriceThe following is a list of valid operators: 39281e9cda2SRuslan Ermilov.Bl -tag -width indent 39349e11e3aSSheldon Hearn.It Control operators: 39449e11e3aSSheldon Hearn.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 39535471bf8SJoel Dahl.It Li & Ta Li && Ta Li \&( Ta Li \&) Ta Li \en 39635471bf8SJoel Dahl.It Li ;; Ta Li ;& Ta Li \&; Ta Li \&| Ta Li || 39749e11e3aSSheldon Hearn.El 39849e11e3aSSheldon Hearn.It Redirection operators: 3994682f420SBrian Somers.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 40081e9cda2SRuslan Ermilov.It Li < Ta Li > Ta Li << Ta Li >> Ta Li <> 401748611c9SJoel Dahl.It Li <& Ta Li >& Ta Li <<- Ta Li >| Ta \& 40249e11e3aSSheldon Hearn.El 403ab72124fSSteve Price.El 4047d1a55fcSStefan Farfeleder.Pp 4057d1a55fcSStefan FarfelederThe character 4067d1a55fcSStefan Farfeleder.Ql # 4077d1a55fcSStefan Farfelederintroduces a comment if used at the beginning of a word. 4087d1a55fcSStefan FarfelederThe word starting with 4097d1a55fcSStefan Farfeleder.Ql # 4107d1a55fcSStefan Farfelederand the rest of the line are ignored. 4119764aa41SJilles Tjoelker.Pp 4129764aa41SJilles Tjoelker.Tn ASCII 4139764aa41SJilles Tjoelker.Dv NUL 4149764aa41SJilles Tjoelkercharacters (character code 0) are not allowed in shell input. 415ab72124fSSteve Price.Ss Quoting 4164b88c807SRodney W. GrimesQuoting is used to remove the special meaning of certain characters 417a886288eSJesus R. Camouor words to the shell, such as operators, whitespace, keywords, 418a886288eSJesus R. Camouor alias names. 419a886288eSJesus R. Camou.Pp 420a62ab027SJilles TjoelkerThere are four types of quoting: matched single quotes, 421a62ab027SJilles Tjoelkerdollar-single quotes, 4224b88c807SRodney W. Grimesmatched double quotes, and backslash. 42381e9cda2SRuslan Ermilov.Bl -tag -width indent 424ab72124fSSteve Price.It Single Quotes 4254b88c807SRodney W. GrimesEnclosing characters in single quotes preserves the literal 426ab0a2172SSteve Pricemeaning of all the characters (except single quotes, making 427ab0a2172SSteve Priceit impossible to put single-quotes in a single-quoted string). 428a62ab027SJilles Tjoelker.It Dollar-Single Quotes 429a62ab027SJilles TjoelkerEnclosing characters between 430a62ab027SJilles Tjoelker.Li $' 431a62ab027SJilles Tjoelkerand 432a62ab027SJilles Tjoelker.Li ' 433a62ab027SJilles Tjoelkerpreserves the literal meaning of all characters 434a62ab027SJilles Tjoelkerexcept backslashes and single quotes. 435a62ab027SJilles TjoelkerA backslash introduces a C-style escape sequence: 436a62ab027SJilles Tjoelker.Bl -tag -width xUnnnnnnnn 437a62ab027SJilles Tjoelker.It \ea 438a62ab027SJilles TjoelkerAlert (ring the terminal bell) 439a62ab027SJilles Tjoelker.It \eb 440a62ab027SJilles TjoelkerBackspace 441a62ab027SJilles Tjoelker.It \ec Ns Ar c 442a62ab027SJilles TjoelkerThe control character denoted by 443a62ab027SJilles Tjoelker.Li ^ Ns Ar c 444a62ab027SJilles Tjoelkerin 445a62ab027SJilles Tjoelker.Xr stty 1 . 446a62ab027SJilles TjoelkerIf 447a62ab027SJilles Tjoelker.Ar c 448a62ab027SJilles Tjoelkeris a backslash, it must be doubled. 449a62ab027SJilles Tjoelker.It \ee 450a62ab027SJilles TjoelkerThe ESC character 451a62ab027SJilles Tjoelker.Tn ( ASCII 452a62ab027SJilles Tjoelker0x1b) 453a62ab027SJilles Tjoelker.It \ef 454a62ab027SJilles TjoelkerFormfeed 455a62ab027SJilles Tjoelker.It \en 456a62ab027SJilles TjoelkerNewline 457a62ab027SJilles Tjoelker.It \er 458a62ab027SJilles TjoelkerCarriage return 459a62ab027SJilles Tjoelker.It \et 460a62ab027SJilles TjoelkerHorizontal tab 461a62ab027SJilles Tjoelker.It \ev 462a62ab027SJilles TjoelkerVertical tab 463a62ab027SJilles Tjoelker.It \e\e 464a62ab027SJilles TjoelkerLiteral backslash 465a62ab027SJilles Tjoelker.It \e\&' 466a62ab027SJilles TjoelkerLiteral single-quote 467a62ab027SJilles Tjoelker.It \e\&" 468a62ab027SJilles TjoelkerLiteral double-quote 469a62ab027SJilles Tjoelker.It \e Ns Ar nnn 470a62ab027SJilles TjoelkerThe byte whose octal value is 471a62ab027SJilles Tjoelker.Ar nnn 472a62ab027SJilles Tjoelker(one to three digits) 473a62ab027SJilles Tjoelker.It \ex Ns Ar nn 474a62ab027SJilles TjoelkerThe byte whose hexadecimal value is 475a62ab027SJilles Tjoelker.Ar nn 476a62ab027SJilles Tjoelker(one or more digits only the last two of which are used) 477a62ab027SJilles Tjoelker.It \eu Ns Ar nnnn 478a62ab027SJilles TjoelkerThe Unicode code point 479a62ab027SJilles Tjoelker.Ar nnnn 480a62ab027SJilles Tjoelker(four hexadecimal digits) 481a62ab027SJilles Tjoelker.It \eU Ns Ar nnnnnnnn 482a62ab027SJilles TjoelkerThe Unicode code point 483a62ab027SJilles Tjoelker.Ar nnnnnnnn 484a62ab027SJilles Tjoelker(eight hexadecimal digits) 485a62ab027SJilles Tjoelker.El 486a62ab027SJilles Tjoelker.Pp 48707eb7033SJilles TjoelkerThe sequences for Unicode code points are currently only useful with 48807eb7033SJilles TjoelkerUTF-8 locales. 489a62ab027SJilles TjoelkerThey reject code point 0 and UTF-16 surrogates. 490a62ab027SJilles Tjoelker.Pp 491a62ab027SJilles TjoelkerIf an escape sequence would produce a byte with value 0, 492a62ab027SJilles Tjoelkerthat byte and the rest of the string until the matching single-quote 493a62ab027SJilles Tjoelkerare ignored. 494a62ab027SJilles Tjoelker.Pp 495a62ab027SJilles TjoelkerAny other string starting with a backslash is an error. 496ab72124fSSteve Price.It Double Quotes 4974b88c807SRodney W. GrimesEnclosing characters within double quotes preserves the literal 49849e11e3aSSheldon Hearnmeaning of all characters except dollar sign 499a762afe5SGiorgos Keramidas.Pq Ql $ , 50049e11e3aSSheldon Hearnbackquote 501a762afe5SGiorgos Keramidas.Pq Ql ` , 50249e11e3aSSheldon Hearnand backslash 503a762afe5SGiorgos Keramidas.Pq Ql \e . 50449e11e3aSSheldon HearnThe backslash inside double quotes is historically weird. 50549e11e3aSSheldon HearnIt remains literal unless it precedes the following characters, 50649e11e3aSSheldon Hearnwhich it serves to quote: 507afc5a69aSJoel Dahl.Pp 50849e11e3aSSheldon Hearn.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 509afc5a69aSJoel Dahl.It Li $ Ta Li ` Ta Li \&" Ta Li \e Ta Li \en 51049e11e3aSSheldon Hearn.El 511ab72124fSSteve Price.It Backslash 512ab72124fSSteve PriceA backslash preserves the literal meaning of the following 51349e11e3aSSheldon Hearncharacter, with the exception of the newline character 514a762afe5SGiorgos Keramidas.Pq Ql \en . 51549e11e3aSSheldon HearnA backslash preceding a newline is treated as a line continuation. 516ab72124fSSteve Price.El 517d806a030SJilles Tjoelker.Ss Keywords 518d806a030SJilles TjoelkerKeywords or reserved words are words that have special meaning to the 5194b88c807SRodney W. Grimesshell and are recognized at the beginning of a line and 520eccea571SRuslan Ermilovafter a control operator. 521d806a030SJilles TjoelkerThe following are keywords: 52249e11e3aSSheldon Hearn.Bl -column "doneXX" "elifXX" "elseXX" "untilXX" "whileX" -offset center 52381e9cda2SRuslan Ermilov.It Li \&! Ta { Ta } Ta Ic case Ta Ic do 52481e9cda2SRuslan Ermilov.It Ic done Ta Ic elif Ta Ic else Ta Ic esac Ta Ic fi 52581e9cda2SRuslan Ermilov.It Ic for Ta Ic if Ta Ic then Ta Ic until Ta Ic while 52649e11e3aSSheldon Hearn.El 527ab72124fSSteve Price.Ss Aliases 528ab72124fSSteve PriceAn alias is a name and corresponding value set using the 529c644db6aSSheldon Hearn.Ic alias 530eccea571SRuslan Ermilovbuilt-in command. 53105a447d0SJilles TjoelkerWherever the command word of a simple command may occur, 53205a447d0SJilles Tjoelkerand after checking for keywords if a keyword may occur, the shell 533e6d3cf26SSheldon Hearnchecks the word to see if it matches an alias. 534e6d3cf26SSheldon HearnIf it does, it replaces it in the input stream with its value. 535e6d3cf26SSheldon HearnFor example, if there is an alias called 53649e11e3aSSheldon Hearn.Dq Li lf 5376b15476eSSheldon Hearnwith the value 538dfe302abSRuslan Ermilov.Dq Li "ls -F" , 5394b88c807SRodney W. Grimesthen the input 540dfe302abSRuslan Ermilov.Pp 541dfe302abSRuslan Ermilov.Dl "lf foobar" 542ab72124fSSteve Price.Pp 5434b88c807SRodney W. Grimeswould become 544dfe302abSRuslan Ermilov.Pp 545dfe302abSRuslan Ermilov.Dl "ls -F foobar" 546ab72124fSSteve Price.Pp 54748f49aacSJilles TjoelkerAliases are also recognized after an alias 54848f49aacSJilles Tjoelkerwhose value ends with a space or tab. 54948f49aacSJilles TjoelkerFor example, if there is also an alias called 55048f49aacSJilles Tjoelker.Dq Li nohup 55148f49aacSJilles Tjoelkerwith the value 55248f49aacSJilles Tjoelker.Dq Li "nohup " , 55348f49aacSJilles Tjoelkerthen the input 55448f49aacSJilles Tjoelker.Pp 55548f49aacSJilles Tjoelker.Dl "nohup lf foobar" 55648f49aacSJilles Tjoelker.Pp 55748f49aacSJilles Tjoelkerwould become 55848f49aacSJilles Tjoelker.Pp 55948f49aacSJilles Tjoelker.Dl "nohup ls -F foobar" 56048f49aacSJilles Tjoelker.Pp 5614b88c807SRodney W. GrimesAliases provide a convenient way for naive users to 5624b88c807SRodney W. Grimescreate shorthands for commands without having to learn how 563eccea571SRuslan Ermilovto create functions with arguments. 56412dfb7a5SJilles TjoelkerUsing aliases in scripts is discouraged 56512dfb7a5SJilles Tjoelkerbecause the command that defines them must be executed 56612dfb7a5SJilles Tjoelkerbefore the code that uses them is parsed. 56712dfb7a5SJilles TjoelkerThis is fragile and not portable. 568a886288eSJesus R. Camou.Pp 569a886288eSJesus R. CamouAn alias name may be escaped in a command line, so that it is not 570a886288eSJesus R. Camoureplaced by its alias value, by using quoting characters within or 57119162ab9SJesus R. Camouadjacent to the alias name. 57219162ab9SJesus R. CamouThis is most often done by prefixing 573a886288eSJesus R. Camouan alias name with a backslash to execute a function, built-in, or 574a886288eSJesus R. Camounormal program with the same name. 575a886288eSJesus R. CamouSee the 576a886288eSJesus R. Camou.Sx Quoting 577a886288eSJesus R. Camousubsection. 578ab72124fSSteve Price.Ss Commands 5794b88c807SRodney W. GrimesThe shell interprets the words it reads according to a 5804b88c807SRodney W. Grimeslanguage, the specification of which is outside the scope 581ab72124fSSteve Priceof this man page (refer to the BNF in the 582ab72124fSSteve Price.St -p1003.2 583eccea571SRuslan Ermilovdocument). 584eccea571SRuslan ErmilovEssentially though, a line is read and if 5854b88c807SRodney W. Grimesthe first word of the line (or after a control operator) 586d806a030SJilles Tjoelkeris not a keyword, then the shell has recognized a 587eccea571SRuslan Ermilovsimple command. 588eccea571SRuslan ErmilovOtherwise, a complex command or some 5894b88c807SRodney W. Grimesother special construct may have been recognized. 590ab72124fSSteve Price.Ss Simple Commands 5914b88c807SRodney W. GrimesIf a simple command has been recognized, the shell performs 5924b88c807SRodney W. Grimesthe following actions: 593ab72124fSSteve Price.Bl -enum 594ab72124fSSteve Price.It 5956b15476eSSheldon HearnLeading words of the form 59649e11e3aSSheldon Hearn.Dq Li name=value 5976b15476eSSheldon Hearnare stripped off and assigned to the environment of 598000dda7bSJilles Tjoelkerthe simple command 599000dda7bSJilles Tjoelker(they do not affect expansions). 600eccea571SRuslan ErmilovRedirection operators and 6014b88c807SRodney W. Grimestheir arguments (as described below) are stripped 6024b88c807SRodney W. Grimesoff and saved for processing. 603ab72124fSSteve Price.It 604ab72124fSSteve PriceThe remaining words are expanded as described in 6056b15476eSSheldon Hearnthe section called 6066b15476eSSheldon Hearn.Sx Word Expansions , 6076b15476eSSheldon Hearnand the first remaining word is considered the command 608eccea571SRuslan Ermilovname and the command is located. 609eccea571SRuslan ErmilovThe remaining 6104b88c807SRodney W. Grimeswords are considered the arguments of the command. 6116b15476eSSheldon HearnIf no command name resulted, then the 61249e11e3aSSheldon Hearn.Dq Li name=value 6134b88c807SRodney W. Grimesvariable assignments recognized in 1) affect the 6144b88c807SRodney W. Grimescurrent shell. 615ab72124fSSteve Price.It 616ab72124fSSteve PriceRedirections are performed as described in 6174b88c807SRodney W. Grimesthe next section. 618ab72124fSSteve Price.El 619ab72124fSSteve Price.Ss Redirections 6204b88c807SRodney W. GrimesRedirections are used to change where a command reads its input 621eccea571SRuslan Ermilovor sends its output. 622eccea571SRuslan ErmilovIn general, redirections open, close, or 623eccea571SRuslan Ermilovduplicate an existing reference to a file. 624eccea571SRuslan ErmilovThe overall format 6254b88c807SRodney W. Grimesused for redirection is: 62649e11e3aSSheldon Hearn.Pp 627dfe302abSRuslan Ermilov.D1 Oo Ar n Oc Ar redir-op file 62849e11e3aSSheldon Hearn.Pp 62949e11e3aSSheldon HearnThe 630dfe302abSRuslan Ermilov.Ar redir-op 63149e11e3aSSheldon Hearnis one of the redirection operators mentioned 632eccea571SRuslan Ermilovpreviously. 633eccea571SRuslan ErmilovThe following gives some examples of how these 63449e11e3aSSheldon Hearnoperators can be used. 63549e11e3aSSheldon HearnNote that stdin and stdout are commonly used abbreviations 63649e11e3aSSheldon Hearnfor standard input and standard output respectively. 63749e11e3aSSheldon Hearn.Bl -tag -width "1234567890XX" -offset indent 638dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li > Ar file 639dfe302abSRuslan Ermilovredirect stdout (or file descriptor 640dfe302abSRuslan Ermilov.Ar n ) 641dfe302abSRuslan Ermilovto 642dfe302abSRuslan Ermilov.Ar file 643dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li >| Ar file 64449e11e3aSSheldon Hearnsame as above, but override the 64549e11e3aSSheldon Hearn.Fl C 64649e11e3aSSheldon Hearnoption 647dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li >> Ar file 648dfe302abSRuslan Ermilovappend stdout (or file descriptor 649dfe302abSRuslan Ermilov.Ar n ) 650dfe302abSRuslan Ermilovto 651dfe302abSRuslan Ermilov.Ar file 652dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li < Ar file 653dfe302abSRuslan Ermilovredirect stdin (or file descriptor 654dfe302abSRuslan Ermilov.Ar n ) 655dfe302abSRuslan Ermilovfrom 656dfe302abSRuslan Ermilov.Ar file 657dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li <> Ar file 658dfe302abSRuslan Ermilovredirect stdin (or file descriptor 659dfe302abSRuslan Ermilov.Ar n ) 660dfe302abSRuslan Ermilovto and from 661dfe302abSRuslan Ermilov.Ar file 662dfe302abSRuslan Ermilov.It Oo Ar n1 Oc Ns Li <& Ns Ar n2 663dfe302abSRuslan Ermilovduplicate stdin (or file descriptor 664dfe302abSRuslan Ermilov.Ar n1 ) 665dfe302abSRuslan Ermilovfrom file descriptor 666dfe302abSRuslan Ermilov.Ar n2 667dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li <&- 668dfe302abSRuslan Ermilovclose stdin (or file descriptor 669dfe302abSRuslan Ermilov.Ar n ) 670dfe302abSRuslan Ermilov.It Oo Ar n1 Oc Ns Li >& Ns Ar n2 671dfe302abSRuslan Ermilovduplicate stdout (or file descriptor 672dfe302abSRuslan Ermilov.Ar n1 ) 673dfe302abSRuslan Ermilovto file descriptor 674dfe302abSRuslan Ermilov.Ar n2 675dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li >&- 676dfe302abSRuslan Ermilovclose stdout (or file descriptor 677dfe302abSRuslan Ermilov.Ar n ) 678ab72124fSSteve Price.El 679ab72124fSSteve Price.Pp 6806b15476eSSheldon HearnThe following redirection is often called a 6816b15476eSSheldon Hearn.Dq here-document . 682dfe302abSRuslan Ermilov.Bd -unfilled -offset indent 683dfe302abSRuslan Ermilov.Oo Ar n Oc Ns Li << Ar delimiter 684a2442c2fSJoel Dahl.Ar here-doc-text 685a2442c2fSJoel Dahl.Ar ... 686dfe302abSRuslan Ermilov.Ar delimiter 687ab72124fSSteve Price.Ed 688ab72124fSSteve Price.Pp 6894b88c807SRodney W. GrimesAll the text on successive lines up to the delimiter is 6904b88c807SRodney W. Grimessaved away and made available to the command on standard 691dfe302abSRuslan Ermilovinput, or file descriptor 692dfe302abSRuslan Ermilov.Ar n 693dfe302abSRuslan Ermilovif it is specified. 694dfe302abSRuslan ErmilovIf the 695dfe302abSRuslan Ermilov.Ar delimiter 696dfe302abSRuslan Ermilovas specified on the initial line is quoted, then the 697dfe302abSRuslan Ermilov.Ar here-doc-text 6984b88c807SRodney W. Grimesis treated literally, otherwise the text is subjected to 6994b88c807SRodney W. Grimesparameter expansion, command substitution, and arithmetic 7006b15476eSSheldon Hearnexpansion (as described in the section on 7016b15476eSSheldon Hearn.Sx Word Expansions ) . 7026b15476eSSheldon HearnIf the operator is 70349e11e3aSSheldon Hearn.Dq Li <<- 7046b15476eSSheldon Hearninstead of 70549e11e3aSSheldon Hearn.Dq Li << , 7066b15476eSSheldon Hearnthen leading tabs 707dfe302abSRuslan Ermilovin the 708dfe302abSRuslan Ermilov.Ar here-doc-text 709dfe302abSRuslan Ermilovare stripped. 710ab72124fSSteve Price.Ss Search and Execution 711ab0a2172SSteve PriceThere are three types of commands: shell functions, 7128eed22b1SJens Schweikhardtbuilt-in commands, and normal programs. 71349e11e3aSSheldon HearnThe command is searched for (by name) in that order. 71449e11e3aSSheldon HearnThe three types of commands are all executed in a different way. 715ab72124fSSteve Price.Pp 716ab0a2172SSteve PriceWhen a shell function is executed, all of the shell positional 717dfe302abSRuslan Ermilovparameters (except 718dfe302abSRuslan Ermilov.Li $0 , 719dfe302abSRuslan Ermilovwhich remains unchanged) are 7204b88c807SRodney W. Grimesset to the arguments of the shell function. 7214b88c807SRodney W. GrimesThe variables which are explicitly placed in the environment of 7224b88c807SRodney W. Grimesthe command (by placing assignments to them before the 7234b88c807SRodney W. Grimesfunction name) are made local to the function and are set 724e6d3cf26SSheldon Hearnto the values given. 725e6d3cf26SSheldon HearnThen the command given in the function definition is executed. 726e6d3cf26SSheldon HearnThe positional parameters are restored to their original values 727e6d3cf26SSheldon Hearnwhen the command completes. 728ab0a2172SSteve PriceThis all occurs within the current shell. 729ab72124fSSteve Price.Pp 7308eed22b1SJens SchweikhardtShell built-in commands are executed internally to the shell, without 731ab0a2172SSteve Pricespawning a new process. 73230268dfaSJilles TjoelkerThere are two kinds of built-in commands: regular and special. 73330268dfaSJilles TjoelkerAssignments before special builtins persist after they finish 73430268dfaSJilles Tjoelkerexecuting and assignment errors, redirection errors and certain 73530268dfaSJilles Tjoelkeroperand errors cause a script to be aborted. 7364b985a89SJilles TjoelkerSpecial builtins cannot be overridden with a function. 73730268dfaSJilles TjoelkerBoth regular and special builtins can affect the shell in ways 73830268dfaSJilles Tjoelkernormal programs cannot. 739ab72124fSSteve Price.Pp 740c644db6aSSheldon HearnOtherwise, if the command name does not match a function 7418eed22b1SJens Schweikhardtor built-in command, the command is searched for as a normal 7424b88c807SRodney W. Grimesprogram in the file system (as described in the next section). 7434b88c807SRodney W. GrimesWhen a normal program is executed, the shell runs the program, 744e6d3cf26SSheldon Hearnpassing the arguments and the environment to the program. 745e6d3cf26SSheldon HearnIf the program is not a normal executable file 746eccea571SRuslan Ermilov(i.e., if it does not begin with the 747dfe302abSRuslan Ermilov.Dq "magic number" 7486b15476eSSheldon Hearnwhose 749ab72124fSSteve Price.Tn ASCII 7506b15476eSSheldon Hearnrepresentation is 751dfe302abSRuslan Ermilov.Dq Li #! , 75249e11e3aSSheldon Hearnresulting in an 753b4f0f4aaSRuslan Ermilov.Er ENOEXEC 75449e11e3aSSheldon Hearnreturn value from 75549e11e3aSSheldon Hearn.Xr execve 2 ) 756604e8224SJilles Tjoelkerbut appears to be a text file, 7573835f47cSJilles Tjoelkerthe shell will run a new instance of 7583835f47cSJilles Tjoelker.Nm 7593835f47cSJilles Tjoelkerto interpret it. 760ab72124fSSteve Price.Pp 761ab0a2172SSteve PriceNote that previous versions of this document 762ab0a2172SSteve Priceand the source code itself misleadingly and sporadically 763ab0a2172SSteve Pricerefer to a shell script without a magic number 7646b15476eSSheldon Hearnas a 765dfe302abSRuslan Ermilov.Dq "shell procedure" . 766ab72124fSSteve Price.Ss Path Search 7674b88c807SRodney W. GrimesWhen locating a command, the shell first looks to see if 768eccea571SRuslan Ermilovit has a shell function by that name. 769eccea571SRuslan ErmilovThen it looks for a 770eccea571SRuslan Ermilovbuilt-in command by that name. 771eccea571SRuslan ErmilovIf a built-in command is not found, 772ab0a2172SSteve Priceone of two things happen: 773ab72124fSSteve Price.Bl -enum 774ab72124fSSteve Price.It 775ab72124fSSteve PriceCommand names containing a slash are simply executed without 776ab0a2172SSteve Priceperforming any searches. 777ab72124fSSteve Price.It 778dfe302abSRuslan ErmilovThe shell searches each entry in the 7791788b7ffSJilles Tjoelker.Va PATH 7801788b7ffSJilles Tjoelkervariable 781eccea571SRuslan Ermilovin turn for the command. 782eccea571SRuslan ErmilovThe value of the 7831788b7ffSJilles Tjoelker.Va PATH 784ab72124fSSteve Pricevariable should be a series of 785eccea571SRuslan Ermiloventries separated by colons. 786eccea571SRuslan ErmilovEach entry consists of a 7874b88c807SRodney W. Grimesdirectory name. 7884b88c807SRodney W. GrimesThe current directory 789ab0a2172SSteve Pricemay be indicated implicitly by an empty directory name, 790ab0a2172SSteve Priceor explicitly by a single period. 791ab72124fSSteve Price.El 792ab72124fSSteve Price.Ss Command Exit Status 7934b88c807SRodney W. GrimesEach command has an exit status that can influence the behavior 794eccea571SRuslan Ermilovof other shell commands. 795eccea571SRuslan ErmilovThe paradigm is that a command exits 7964b88c807SRodney W. Grimeswith zero for normal or success, and non-zero for failure, 797eccea571SRuslan Ermiloverror, or a false indication. 798eccea571SRuslan ErmilovThe man page for each command 7994b88c807SRodney W. Grimesshould indicate the various exit codes and what they mean. 8008eed22b1SJens SchweikhardtAdditionally, the built-in commands return exit codes, as does 801ab0a2172SSteve Pricean executed shell function. 802c351e089SJohn Polstra.Pp 803b1f60592SJilles TjoelkerIf a command is terminated by a signal, its exit status is greater than 128. 804b1f60592SJilles TjoelkerThe signal name can be found by passing the exit status to 805b1f60592SJilles Tjoelker.Li kill -l . 806b1f60592SJilles Tjoelker.Pp 807b1f60592SJilles TjoelkerIf there is no command word, 808b1f60592SJilles Tjoelkerthe exit status is the exit status of the last command substitution executed, 809b1f60592SJilles Tjoelkeror zero if the command does not contain any command substitutions. 810ab72124fSSteve Price.Ss Complex Commands 8114b88c807SRodney W. GrimesComplex commands are combinations of simple commands 812d806a030SJilles Tjoelkerwith control operators or keywords, together creating a larger complex 813eccea571SRuslan Ermilovcommand. 814eccea571SRuslan ErmilovMore generally, a command is one of the following: 815ab72124fSSteve Price.Bl -item -offset indent 816ab72124fSSteve Price.It 817ab72124fSSteve Pricesimple command 818ab72124fSSteve Price.It 819ab72124fSSteve Pricepipeline 820ab72124fSSteve Price.It 821ab72124fSSteve Pricelist or compound-list 822ab72124fSSteve Price.It 823ab72124fSSteve Pricecompound command 824ab72124fSSteve Price.It 825ab72124fSSteve Pricefunction definition 826ab72124fSSteve Price.El 827ab72124fSSteve Price.Pp 8284b88c807SRodney W. GrimesUnless otherwise stated, the exit status of a command is 829b1f60592SJilles Tjoelkerthat of the last simple command executed by the command, 830b1f60592SJilles Tjoelkeror zero if no simple command was executed. 831ab72124fSSteve Price.Ss Pipelines 8324b88c807SRodney W. GrimesA pipeline is a sequence of one or more commands separated 833dfe302abSRuslan Ermilovby the control operator 834dfe302abSRuslan Ermilov.Ql \&| . 835eccea571SRuslan ErmilovThe standard output of all but 8364b88c807SRodney W. Grimesthe last command is connected to the standard input 837eccea571SRuslan Ermilovof the next command. 838eccea571SRuslan ErmilovThe standard output of the last 839ab0a2172SSteve Pricecommand is inherited from the shell, as usual. 840ab72124fSSteve Price.Pp 8414b88c807SRodney W. GrimesThe format for a pipeline is: 84249e11e3aSSheldon Hearn.Pp 843dfe302abSRuslan Ermilov.D1 Oo Li \&! Oc Ar command1 Op Li \&| Ar command2 ... 844ab72124fSSteve Price.Pp 845dfe302abSRuslan ErmilovThe standard output of 846dfe302abSRuslan Ermilov.Ar command1 847dfe302abSRuslan Ermilovis connected to the standard input of 848dfe302abSRuslan Ermilov.Ar command2 . 849eccea571SRuslan ErmilovThe standard input, standard output, or 8504b88c807SRodney W. Grimesboth of a command is considered to be assigned by the 8514b88c807SRodney W. Grimespipeline before any redirection specified by redirection 8524b88c807SRodney W. Grimesoperators that are part of the command. 853ab72124fSSteve Price.Pp 854f1ec0581SJilles TjoelkerNote that unlike some other shells, 855f1ec0581SJilles Tjoelker.Nm 856f1ec0581SJilles Tjoelkerexecutes each process in a pipeline with more than one command 857f1ec0581SJilles Tjoelkerin a subshell environment and as a child of the 858f1ec0581SJilles Tjoelker.Nm 859f1ec0581SJilles Tjoelkerprocess. 860f1ec0581SJilles Tjoelker.Pp 8614b88c807SRodney W. GrimesIf the pipeline is not in the background (discussed later), 8624b88c807SRodney W. Grimesthe shell waits for all commands to complete. 863ab72124fSSteve Price.Pp 864d806a030SJilles TjoelkerIf the keyword 865eccea571SRuslan Ermilov.Ic !\& 866eccea571SRuslan Ermilovdoes not precede the pipeline, the 8674b88c807SRodney W. Grimesexit status is the exit status of the last command specified 868eccea571SRuslan Ermilovin the pipeline. 869eccea571SRuslan ErmilovOtherwise, the exit status is the logical 870eccea571SRuslan ErmilovNOT of the exit status of the last command. 871eccea571SRuslan ErmilovThat is, if 8724b88c807SRodney W. Grimesthe last command returns zero, the exit status is 1; if 8734b88c807SRodney W. Grimesthe last command returns greater than zero, the exit status 8744b88c807SRodney W. Grimesis zero. 875ab72124fSSteve Price.Pp 8764b88c807SRodney W. GrimesBecause pipeline assignment of standard input or standard 8774b88c807SRodney W. Grimesoutput or both takes place before redirection, it can be 878eccea571SRuslan Ermilovmodified by redirection. 879eccea571SRuslan ErmilovFor example: 880ab72124fSSteve Price.Pp 881dfe302abSRuslan Ermilov.Dl "command1 2>&1 | command2" 882ab72124fSSteve Price.Pp 88349e11e3aSSheldon Hearnsends both the standard output and standard error of 884dfe302abSRuslan Ermilov.Ar command1 88549e11e3aSSheldon Hearnto the standard input of 886dfe302abSRuslan Ermilov.Ar command2 . 88749e11e3aSSheldon Hearn.Pp 88849e11e3aSSheldon HearnA 889dfe302abSRuslan Ermilov.Ql \&; 89049e11e3aSSheldon Hearnor newline terminator causes the preceding 891e918fc8fSSheldon HearnAND-OR-list 892e918fc8fSSheldon Hearn(described below in the section called 893e918fc8fSSheldon Hearn.Sx Short-Circuit List Operators ) 894e918fc8fSSheldon Hearnto be executed sequentially; 895e918fc8fSSheldon Hearnan 896dfe302abSRuslan Ermilov.Ql & 897e918fc8fSSheldon Hearncauses asynchronous execution of the preceding AND-OR-list. 89849e11e3aSSheldon Hearn.Ss Background Commands (&) 8994b88c807SRodney W. GrimesIf a command is terminated by the control operator ampersand 900a762afe5SGiorgos Keramidas.Pq Ql & , 90151a514adSJilles Tjoelkerthe shell executes the command in a subshell environment (see 90251a514adSJilles Tjoelker.Sx Grouping Commands Together 90351a514adSJilles Tjoelkerbelow) and asynchronously; 90449e11e3aSSheldon Hearnthe shell does not wait for the command to finish 90549e11e3aSSheldon Hearnbefore executing the next command. 906ab72124fSSteve Price.Pp 9074b88c807SRodney W. GrimesThe format for running a command in background is: 908dfe302abSRuslan Ermilov.Pp 909dfe302abSRuslan Ermilov.D1 Ar command1 Li & Op Ar command2 Li & Ar ... 910ab72124fSSteve Price.Pp 9114b88c807SRodney W. GrimesIf the shell is not interactive, the standard input of an 912dfe302abSRuslan Ermilovasynchronous command is set to 913dfe302abSRuslan Ermilov.Pa /dev/null . 914b1f60592SJilles Tjoelker.Pp 915b1f60592SJilles TjoelkerThe exit status is zero. 91649e11e3aSSheldon Hearn.Ss Lists (Generally Speaking) 9174b88c807SRodney W. GrimesA list is a sequence of zero or more commands separated by 9184b88c807SRodney W. Grimesnewlines, semicolons, or ampersands, 9194b88c807SRodney W. Grimesand optionally terminated by one of these three characters. 9204b88c807SRodney W. GrimesThe commands in a 9214b88c807SRodney W. Grimeslist are executed in the order they are written. 9224b88c807SRodney W. GrimesIf command is followed by an ampersand, the shell starts the 9238eed22b1SJens Schweikhardtcommand and immediately proceeds onto the next command; 9244b88c807SRodney W. Grimesotherwise it waits for the command to terminate before 9254b88c807SRodney W. Grimesproceeding to the next one. 926ab72124fSSteve Price.Ss Short-Circuit List Operators 92749e11e3aSSheldon Hearn.Dq Li && 9286b15476eSSheldon Hearnand 92949e11e3aSSheldon Hearn.Dq Li || 9306b15476eSSheldon Hearnare AND-OR list operators. 93149e11e3aSSheldon Hearn.Dq Li && 9326b15476eSSheldon Hearnexecutes the first command, and then executes the second command 9336b15476eSSheldon Hearnif the exit status of the first command is zero. 93449e11e3aSSheldon Hearn.Dq Li || 935120ac26dSMasafumi Max NAKANEis similar, but executes the second command if the exit 9366b15476eSSheldon Hearnstatus of the first command is nonzero. 93749e11e3aSSheldon Hearn.Dq Li && 9386b15476eSSheldon Hearnand 93949e11e3aSSheldon Hearn.Dq Li || 9404b88c807SRodney W. Grimesboth have the same priority. 94149e11e3aSSheldon Hearn.Ss Flow-Control Constructs (if, while, for, case) 94249e11e3aSSheldon HearnThe syntax of the 94349e11e3aSSheldon Hearn.Ic if 94449e11e3aSSheldon Hearncommand is: 945dfe302abSRuslan Ermilov.Bd -unfilled -offset indent -compact 946dfe302abSRuslan Ermilov.Ic if Ar list 947dfe302abSRuslan Ermilov.Ic then Ar list 948dfe302abSRuslan Ermilov.Oo Ic elif Ar list 949dfe302abSRuslan Ermilov.Ic then Ar list Oc Ar ... 950dfe302abSRuslan Ermilov.Op Ic else Ar list 951dfe302abSRuslan Ermilov.Ic fi 952dfe302abSRuslan Ermilov.Ed 953ab72124fSSteve Price.Pp 954b1f60592SJilles TjoelkerThe exit status is that of selected 955b1f60592SJilles Tjoelker.Ic then 956b1f60592SJilles Tjoelkeror 957b1f60592SJilles Tjoelker.Ic else 958b1f60592SJilles Tjoelkerlist, 959b1f60592SJilles Tjoelkeror zero if no list was selected. 960b1f60592SJilles Tjoelker.Pp 96149e11e3aSSheldon HearnThe syntax of the 96249e11e3aSSheldon Hearn.Ic while 96349e11e3aSSheldon Hearncommand is: 964dfe302abSRuslan Ermilov.Bd -unfilled -offset indent -compact 965dfe302abSRuslan Ermilov.Ic while Ar list 966dfe302abSRuslan Ermilov.Ic do Ar list 967dfe302abSRuslan Ermilov.Ic done 968dfe302abSRuslan Ermilov.Ed 969ab72124fSSteve Price.Pp 970ab0a2172SSteve PriceThe two lists are executed repeatedly while the exit status of the 97149e11e3aSSheldon Hearnfirst list is zero. 97249e11e3aSSheldon HearnThe 97349e11e3aSSheldon Hearn.Ic until 97449e11e3aSSheldon Hearncommand is similar, but has the word 97549e11e3aSSheldon Hearn.Ic until 97649e11e3aSSheldon Hearnin place of 97749e11e3aSSheldon Hearn.Ic while , 97849e11e3aSSheldon Hearnwhich causes it to 9794b88c807SRodney W. Grimesrepeat until the exit status of the first list is zero. 980ab72124fSSteve Price.Pp 981b1f60592SJilles TjoelkerThe exit status is that of the last execution of the second list, 982b1f60592SJilles Tjoelkeror zero if it was never executed. 983b1f60592SJilles Tjoelker.Pp 98449e11e3aSSheldon HearnThe syntax of the 98549e11e3aSSheldon Hearn.Ic for 98649e11e3aSSheldon Hearncommand is: 987dfe302abSRuslan Ermilov.Bd -unfilled -offset indent -compact 988dfe302abSRuslan Ermilov.Ic for Ar variable Op Ic in Ar word ... 989dfe302abSRuslan Ermilov.Ic do Ar list 990dfe302abSRuslan Ermilov.Ic done 991dfe302abSRuslan Ermilov.Ed 992ab72124fSSteve Price.Pp 993a01459dfSStefan FarfelederIf 994a01459dfSStefan Farfeleder.Ic in 9957b14d37fSRalf S. Engelschalland the following words are omitted, 996776e6b33SJilles Tjoelker.Ic in Li \&"$@\&" 997a01459dfSStefan Farfelederis used instead. 9984b88c807SRodney W. GrimesThe words are expanded, and then the list is executed 99949e11e3aSSheldon Hearnrepeatedly with the variable set to each word in turn. 100049e11e3aSSheldon HearnThe 100149e11e3aSSheldon Hearn.Ic do 10026b15476eSSheldon Hearnand 100349e11e3aSSheldon Hearn.Ic done 100449e11e3aSSheldon Hearncommands may be replaced with 1005dfe302abSRuslan Ermilov.Ql { 100649e11e3aSSheldon Hearnand 1007dfe302abSRuslan Ermilov.Ql } . 1008ab72124fSSteve Price.Pp 100949e11e3aSSheldon HearnThe syntax of the 101049e11e3aSSheldon Hearn.Ic break 101149e11e3aSSheldon Hearnand 101249e11e3aSSheldon Hearn.Ic continue 101349e11e3aSSheldon Hearncommands is: 1014dfe302abSRuslan Ermilov.D1 Ic break Op Ar num 1015dfe302abSRuslan Ermilov.D1 Ic continue Op Ar num 1016ab72124fSSteve Price.Pp 101749e11e3aSSheldon HearnThe 101849e11e3aSSheldon Hearn.Ic break 101949e11e3aSSheldon Hearncommand terminates the 102049e11e3aSSheldon Hearn.Ar num 102149e11e3aSSheldon Hearninnermost 102249e11e3aSSheldon Hearn.Ic for 102349e11e3aSSheldon Hearnor 102449e11e3aSSheldon Hearn.Ic while 102549e11e3aSSheldon Hearnloops. 102649e11e3aSSheldon HearnThe 102749e11e3aSSheldon Hearn.Ic continue 102849e11e3aSSheldon Hearncommand continues with the next iteration of the innermost loop. 102930268dfaSJilles TjoelkerThese are implemented as special built-in commands. 1030ab72124fSSteve Price.Pp 103149e11e3aSSheldon HearnThe syntax of the 103249e11e3aSSheldon Hearn.Ic case 1033dfe302abSRuslan Ermilovcommand is: 1034dfe302abSRuslan Ermilov.Bd -unfilled -offset indent -compact 1035dfe302abSRuslan Ermilov.Ic case Ar word Ic in 1036dfe302abSRuslan Ermilov.Ar pattern Ns Li ) Ar list Li ;; 1037dfe302abSRuslan Ermilov.Ar ... 1038dfe302abSRuslan Ermilov.Ic esac 1039dfe302abSRuslan Ermilov.Ed 1040ab72124fSSteve Price.Pp 104149e11e3aSSheldon HearnThe pattern can actually be one or more patterns 104249e11e3aSSheldon Hearn(see 104349e11e3aSSheldon Hearn.Sx Shell Patterns 104449e11e3aSSheldon Hearndescribed later), 104549e11e3aSSheldon Hearnseparated by 1046dfe302abSRuslan Ermilov.Ql \&| 10476b15476eSSheldon Hearncharacters. 1048b97989d6SJilles TjoelkerTilde expansion, parameter expansion, command substitution, 1049b97989d6SJilles Tjoelkerarithmetic expansion and quote removal are applied to the word. 1050b97989d6SJilles TjoelkerThen, each pattern is expanded in turn using tilde expansion, 1051b97989d6SJilles Tjoelkerparameter expansion, command substitution and arithmetic expansion and 1052b97989d6SJilles Tjoelkerthe expanded form of the word is checked against it. 1053b97989d6SJilles TjoelkerIf a match is found, the corresponding list is executed. 1054c9afaa63SJilles TjoelkerIf the selected list is terminated by the control operator 1055c9afaa63SJilles Tjoelker.Ql ;& 1056c9afaa63SJilles Tjoelkerinstead of 1057c9afaa63SJilles Tjoelker.Ql ;; , 1058b97989d6SJilles Tjoelkerexecution continues with the next list, 1059b97989d6SJilles Tjoelkercontinuing until a list terminated with 1060b97989d6SJilles Tjoelker.Ql ;; 1061b97989d6SJilles Tjoelkeror the end of the 1062b97989d6SJilles Tjoelker.Ic case 1063b97989d6SJilles Tjoelkercommand. 1064ab72124fSSteve Price.Ss Grouping Commands Together 10654b88c807SRodney W. GrimesCommands may be grouped by writing either 1066dfe302abSRuslan Ermilov.Pp 1067dfe302abSRuslan Ermilov.D1 Li \&( Ns Ar list Ns Li \%) 1068ab72124fSSteve Price.Pp 10694b88c807SRodney W. Grimesor 1070dfe302abSRuslan Ermilov.Pp 1071dfe302abSRuslan Ermilov.D1 Li { Ar list Ns Li \&; } 1072ab72124fSSteve Price.Pp 1073ef89d04fSJilles TjoelkerThe first form executes the commands in a subshell environment. 107451a514adSJilles TjoelkerA subshell environment has its own copy of: 107551a514adSJilles Tjoelker.Bl -enum 107651a514adSJilles Tjoelker.It 107751a514adSJilles TjoelkerThe current working directory as set by 107851a514adSJilles Tjoelker.Ic cd . 107951a514adSJilles Tjoelker.It 108051a514adSJilles TjoelkerThe file creation mask as set by 108151a514adSJilles Tjoelker.Ic umask . 108251a514adSJilles Tjoelker.It 10830c35cec6SJilles TjoelkerResource limits as set by 10840c35cec6SJilles Tjoelker.Ic ulimit . 10850c35cec6SJilles Tjoelker.It 108651a514adSJilles TjoelkerReferences to open files. 108751a514adSJilles Tjoelker.It 108851a514adSJilles TjoelkerTraps as set by 108951a514adSJilles Tjoelker.Ic trap . 109051a514adSJilles Tjoelker.It 109151a514adSJilles TjoelkerKnown jobs. 109251a514adSJilles Tjoelker.It 109351a514adSJilles TjoelkerPositional parameters and variables. 109451a514adSJilles Tjoelker.It 109551a514adSJilles TjoelkerShell options. 109651a514adSJilles Tjoelker.It 109751a514adSJilles TjoelkerShell functions. 109851a514adSJilles Tjoelker.It 109951a514adSJilles TjoelkerShell aliases. 110051a514adSJilles Tjoelker.El 110151a514adSJilles Tjoelker.Pp 110251a514adSJilles TjoelkerThese are copied from the parent shell environment, 110351a514adSJilles Tjoelkerexcept that trapped (but not ignored) signals are reset to the default action 110451a514adSJilles Tjoelkerand known jobs are cleared. 110551a514adSJilles TjoelkerAny changes do not affect the parent shell environment. 110651a514adSJilles Tjoelker.Pp 110751a514adSJilles TjoelkerA subshell environment may be implemented as a child process or differently. 110851a514adSJilles TjoelkerIf job control is enabled in an interactive shell, 110951a514adSJilles Tjoelkercommands grouped in parentheses can be suspended and continued as a unit. 111051a514adSJilles Tjoelker.Pp 111154ccc8b5SJilles TjoelkerFor compatibility with other shells, 111254ccc8b5SJilles Tjoelkertwo open parentheses in sequence should be separated by whitespace. 111354ccc8b5SJilles Tjoelker.Pp 1114ef89d04fSJilles TjoelkerThe second form never forks another shell, 111549e11e3aSSheldon Hearnso it is slightly more efficient. 111649e11e3aSSheldon HearnGrouping commands together this way allows the user to 1117ab0a2172SSteve Priceredirect their output as though they were one program: 1118ab72124fSSteve Price.Bd -literal -offset indent 1119ee7dc416SSteve Price{ echo -n "hello"; echo " world"; } > greeting 1120ab72124fSSteve Price.Ed 1121ab72124fSSteve Price.Ss Functions 11224b88c807SRodney W. GrimesThe syntax of a function definition is 1123dfe302abSRuslan Ermilov.Pp 1124dfe302abSRuslan Ermilov.D1 Ar name Li \&( \&) Ar command 1125ab72124fSSteve Price.Pp 11264b88c807SRodney W. GrimesA function definition is an executable statement; when 1127dfe302abSRuslan Ermilovexecuted it installs a function named 1128dfe302abSRuslan Ermilov.Ar name 1129dfe302abSRuslan Ermilovand returns an 1130eccea571SRuslan Ermilovexit status of zero. 1131dfe302abSRuslan ErmilovThe 1132dfe302abSRuslan Ermilov.Ar command 1133dfe302abSRuslan Ermilovis normally a list 11346b15476eSSheldon Hearnenclosed between 1135dfe302abSRuslan Ermilov.Ql { 11366b15476eSSheldon Hearnand 1137dfe302abSRuslan Ermilov.Ql } . 1138ab72124fSSteve Price.Pp 11394b88c807SRodney W. GrimesVariables may be declared to be local to a function by 114049e11e3aSSheldon Hearnusing the 114149e11e3aSSheldon Hearn.Ic local 114249e11e3aSSheldon Hearncommand. 114349e11e3aSSheldon HearnThis should appear as the first statement of a function, 114449e11e3aSSheldon Hearnand the syntax is: 1145dfe302abSRuslan Ermilov.Pp 1146dfe302abSRuslan Ermilov.D1 Ic local Oo Ar variable ... Oc Op Fl 1147ab72124fSSteve Price.Pp 114849e11e3aSSheldon HearnThe 114949e11e3aSSheldon Hearn.Ic local 11508eed22b1SJens Schweikhardtcommand is implemented as a built-in command. 1151b1f60592SJilles TjoelkerThe exit status is zero 1152b1f60592SJilles Tjoelkerunless the command is not in a function or a variable name is invalid. 1153ab72124fSSteve Price.Pp 11544b88c807SRodney W. GrimesWhen a variable is made local, it inherits the initial 11554b88c807SRodney W. Grimesvalue and exported and readonly flags from the variable 11564b88c807SRodney W. Grimeswith the same name in the surrounding scope, if there is 1157eccea571SRuslan Ermilovone. 1158eccea571SRuslan ErmilovOtherwise, the variable is initially unset. 1159eccea571SRuslan ErmilovThe shell 1160e918fc8fSSheldon Hearnuses dynamic scoping, so that if the variable 1161dfe302abSRuslan Ermilov.Va x 1162e918fc8fSSheldon Hearnis made local to function 1163e918fc8fSSheldon Hearn.Em f , 1164e918fc8fSSheldon Hearnwhich then calls function 1165e918fc8fSSheldon Hearn.Em g , 1166e918fc8fSSheldon Hearnreferences to the variable 1167dfe302abSRuslan Ermilov.Va x 1168e918fc8fSSheldon Hearnmade inside 1169e918fc8fSSheldon Hearn.Em g 1170e918fc8fSSheldon Hearnwill refer to the variable 1171dfe302abSRuslan Ermilov.Va x 1172e918fc8fSSheldon Hearndeclared inside 1173e918fc8fSSheldon Hearn.Em f , 1174e918fc8fSSheldon Hearnnot to the global variable named 1175dfe302abSRuslan Ermilov.Va x . 1176ab72124fSSteve Price.Pp 11776b4bbd8aSCeri DaviesThe only special parameter that can be made local is 1178dfe302abSRuslan Ermilov.Ql - . 11796b15476eSSheldon HearnMaking 1180dfe302abSRuslan Ermilov.Ql - 118162c37116SJilles Tjoelkerlocal causes any shell options 118262c37116SJilles Tjoelker(including those that only have long names) 118362c37116SJilles Tjoelkerthat are 1184dfe302abSRuslan Ermilovchanged via the 1185dfe302abSRuslan Ermilov.Ic set 1186dfe302abSRuslan Ermilovcommand inside the function to be 11874b88c807SRodney W. Grimesrestored to their original values when the function 11884b88c807SRodney W. Grimesreturns. 1189ab72124fSSteve Price.Pp 119049e11e3aSSheldon HearnThe syntax of the 119149e11e3aSSheldon Hearn.Ic return 119249e11e3aSSheldon Hearncommand is 1193dfe302abSRuslan Ermilov.Pp 1194dfe302abSRuslan Ermilov.D1 Ic return Op Ar exitstatus 1195ab72124fSSteve Price.Pp 11962935c4ccSJilles TjoelkerIt terminates the current executional scope, returning from the closest 11972935c4ccSJilles Tjoelkernested function or sourced script; 11982935c4ccSJilles Tjoelkerif no function or sourced script is being executed, 11992935c4ccSJilles Tjoelkerit exits the shell instance. 120049e11e3aSSheldon HearnThe 120149e11e3aSSheldon Hearn.Ic return 120230268dfaSJilles Tjoelkercommand is implemented as a special built-in command. 1203ab72124fSSteve Price.Ss Variables and Parameters 1204eccea571SRuslan ErmilovThe shell maintains a set of parameters. 1205eccea571SRuslan ErmilovA parameter 12064445af21SJilles Tjoelkerdenoted by a name 12074445af21SJilles Tjoelker(consisting solely 12084445af21SJilles Tjoelkerof alphabetics, numerics, and underscores, 12094445af21SJilles Tjoelkerand starting with an alphabetic or an underscore) 12104445af21SJilles Tjoelkeris called a variable. 1211eccea571SRuslan ErmilovWhen starting up, 12124445af21SJilles Tjoelkerthe shell turns all environment variables with valid names into shell 1213eccea571SRuslan Ermilovvariables. 1214eccea571SRuslan ErmilovNew variables can be set using the form 1215dfe302abSRuslan Ermilov.Pp 1216dfe302abSRuslan Ermilov.D1 Ar name Ns = Ns Ar value 1217ab72124fSSteve Price.Pp 121849e11e3aSSheldon HearnA parameter can also be denoted by a number 12194b88c807SRodney W. Grimesor a special character as explained below. 1220ad56ebdcSJilles Tjoelker.Pp 1221ad56ebdcSJilles TjoelkerAssignments are expanded differently from other words: 1222ad56ebdcSJilles Tjoelkertilde expansion is also performed after the equals sign and after any colon 1223ad56ebdcSJilles Tjoelkerand usernames are also terminated by colons, 1224ad56ebdcSJilles Tjoelkerand field splitting and pathname expansion are not performed. 122584fbdd8cSJilles Tjoelker.Pp 122684fbdd8cSJilles TjoelkerThis special expansion applies not only to assignments that form a simple 122784fbdd8cSJilles Tjoelkercommand by themselves or precede a command word, 122884fbdd8cSJilles Tjoelkerbut also to words passed to the 122984fbdd8cSJilles Tjoelker.Ic export , 123084fbdd8cSJilles Tjoelker.Ic local 123184fbdd8cSJilles Tjoelkeror 123284fbdd8cSJilles Tjoelker.Ic readonly 123384fbdd8cSJilles Tjoelkerbuilt-in commands that have this form. 123484fbdd8cSJilles TjoelkerFor this, the builtin's name must be literal 123584fbdd8cSJilles Tjoelker(not the result of an expansion) 123684fbdd8cSJilles Tjoelkerand may optionally be preceded by one or more literal instances of 123784fbdd8cSJilles Tjoelker.Ic command 123884fbdd8cSJilles Tjoelkerwithout options. 1239ab72124fSSteve Price.Ss Positional Parameters 124049e11e3aSSheldon HearnA positional parameter is a parameter denoted by a number greater than zero. 1241ab72124fSSteve PriceThe shell sets these initially to the values of its command line 1242eccea571SRuslan Ermilovarguments that follow the name of the shell script. 1243eccea571SRuslan ErmilovThe 1244c644db6aSSheldon Hearn.Ic set 12458eed22b1SJens Schweikhardtbuilt-in command can also be used to set or reset them. 1246ab72124fSSteve Price.Ss Special Parameters 1247626a7b1dSJilles TjoelkerSpecial parameters are parameters denoted by a single special character 1248626a7b1dSJilles Tjoelkeror the digit zero. 1249626a7b1dSJilles TjoelkerThey are shown in the following list, exactly as they would appear in input 125043d6677bSAlfred Perlsteintyped by the user or in the source of a shell script. 1251ab72124fSSteve Price.Bl -hang 125243d6677bSAlfred Perlstein.It Li $* 1253eccea571SRuslan ErmilovExpands to the positional parameters, starting from one. 1254eccea571SRuslan ErmilovWhen 12554b88c807SRodney W. Grimesthe expansion occurs within a double-quoted string 12564b88c807SRodney W. Grimesit expands to a single field with the value of each parameter 125749e11e3aSSheldon Hearnseparated by the first character of the 1258dfe302abSRuslan Ermilov.Va IFS 125949e11e3aSSheldon Hearnvariable, 1260dfe302abSRuslan Ermilovor by a space if 1261dfe302abSRuslan Ermilov.Va IFS 126249e11e3aSSheldon Hearnis unset. 126343d6677bSAlfred Perlstein.It Li $@ 1264eccea571SRuslan ErmilovExpands to the positional parameters, starting from one. 1265eccea571SRuslan ErmilovWhen 12664b88c807SRodney W. Grimesthe expansion occurs within double-quotes, each positional 12674b88c807SRodney W. Grimesparameter expands as a separate argument. 12684b88c807SRodney W. GrimesIf there are no positional parameters, the 1269e918fc8fSSheldon Hearnexpansion of 1270e918fc8fSSheldon Hearn.Li @ 1271e918fc8fSSheldon Hearngenerates zero arguments, even when 1272e918fc8fSSheldon Hearn.Li @ 1273eccea571SRuslan Ermilovis double-quoted. 1274eccea571SRuslan ErmilovWhat this basically means, for example, is 1275dfe302abSRuslan Ermilovif 1276dfe302abSRuslan Ermilov.Li $1 1277dfe302abSRuslan Ermilovis 1278dfe302abSRuslan Ermilov.Dq Li abc 1279dfe302abSRuslan Ermilovand 1280dfe302abSRuslan Ermilov.Li $2 1281dfe302abSRuslan Ermilovis 1282dfe302abSRuslan Ermilov.Dq Li "def ghi" , 12836b15476eSSheldon Hearnthen 1284776e6b33SJilles Tjoelker.Li \&"$@\&" 12856b15476eSSheldon Hearnexpands to 12864b88c807SRodney W. Grimesthe two arguments: 1287ab72124fSSteve Price.Bd -literal -offset indent 12884b88c807SRodney W. Grimes"abc" "def ghi" 1289ab72124fSSteve Price.Ed 129043d6677bSAlfred Perlstein.It Li $# 12914b88c807SRodney W. GrimesExpands to the number of positional parameters. 1292dfe302abSRuslan Ermilov.It Li $? 12934b88c807SRodney W. GrimesExpands to the exit status of the most recent pipeline. 129443d6677bSAlfred Perlstein.It Li $- 1295ab72124fSSteve Price(hyphen) Expands to the current option flags (the single-letter 12964b88c807SRodney W. Grimesoption names concatenated into a string) as specified on 1297dfe302abSRuslan Ermilovinvocation, by the 1298dfe302abSRuslan Ermilov.Ic set 1299dfe302abSRuslan Ermilovbuilt-in command, or implicitly 13004b88c807SRodney W. Grimesby the shell. 130143d6677bSAlfred Perlstein.It Li $$ 1302eccea571SRuslan ErmilovExpands to the process ID of the invoked shell. 1303eccea571SRuslan ErmilovA subshell 1304dfe302abSRuslan Ermilovretains the same value of 1305dfe302abSRuslan Ermilov.Va $ 1306dfe302abSRuslan Ermilovas its parent. 1307dfe302abSRuslan Ermilov.It Li $! 13084b88c807SRodney W. GrimesExpands to the process ID of the most recent background 1309eccea571SRuslan Ermilovcommand executed from the current shell. 1310eccea571SRuslan ErmilovFor a 13114b88c807SRodney W. Grimespipeline, the process ID is that of the last command in the 13124b88c807SRodney W. Grimespipeline. 1313ed4c3b5fSJilles TjoelkerIf this parameter is referenced, the shell will remember 1314ed4c3b5fSJilles Tjoelkerthe process ID and its exit status until the 1315ed4c3b5fSJilles Tjoelker.Ic wait 1316ed4c3b5fSJilles Tjoelkerbuilt-in command reports completion of the process. 131743d6677bSAlfred Perlstein.It Li $0 131857a40f7dSJilles Tjoelker(zero) Expands to the name of the shell script if passed on the command line, 131957a40f7dSJilles Tjoelkerthe 132057a40f7dSJilles Tjoelker.Ar name 132157a40f7dSJilles Tjoelkeroperand if given (with 132257a40f7dSJilles Tjoelker.Fl c ) 132357a40f7dSJilles Tjoelkeror otherwise argument 0 passed to the shell. 1324ab72124fSSteve Price.El 13251788b7ffSJilles Tjoelker.Ss Special Variables 13261788b7ffSJilles TjoelkerThe following variables are set by the shell or 13271788b7ffSJilles Tjoelkerhave special meaning to it: 13281788b7ffSJilles Tjoelker.Bl -tag -width ".Va HISTSIZE" 13291788b7ffSJilles Tjoelker.It Va CDPATH 13301788b7ffSJilles TjoelkerThe search path used with the 13311788b7ffSJilles Tjoelker.Ic cd 13321788b7ffSJilles Tjoelkerbuilt-in. 13331788b7ffSJilles Tjoelker.It Va EDITOR 13341788b7ffSJilles TjoelkerThe fallback editor used with the 13351788b7ffSJilles Tjoelker.Ic fc 13361788b7ffSJilles Tjoelkerbuilt-in. 13371788b7ffSJilles TjoelkerIf not set, the default editor is 13381788b7ffSJilles Tjoelker.Xr ed 1 . 13391788b7ffSJilles Tjoelker.It Va FCEDIT 13401788b7ffSJilles TjoelkerThe default editor used with the 13411788b7ffSJilles Tjoelker.Ic fc 13421788b7ffSJilles Tjoelkerbuilt-in. 13431788b7ffSJilles Tjoelker.It Va HISTSIZE 13441788b7ffSJilles TjoelkerThe number of previous commands that are accessible. 13451788b7ffSJilles Tjoelker.It Va HOME 13461788b7ffSJilles TjoelkerThe user's home directory, 13471788b7ffSJilles Tjoelkerused in tilde expansion and as a default directory for the 13481788b7ffSJilles Tjoelker.Ic cd 13491788b7ffSJilles Tjoelkerbuilt-in. 13501788b7ffSJilles Tjoelker.It Va IFS 13511788b7ffSJilles TjoelkerInput Field Separators. 1352ad56ebdcSJilles TjoelkerThe default value is 13531788b7ffSJilles Tjoelker.Aq space , 13541788b7ffSJilles Tjoelker.Aq tab , 13551788b7ffSJilles Tjoelkerand 1356ad56ebdcSJilles Tjoelker.Aq newline 1357ad56ebdcSJilles Tjoelkerin that order. 1358ad56ebdcSJilles TjoelkerThis default also applies if 1359ad56ebdcSJilles Tjoelker.Va IFS 1360ad56ebdcSJilles Tjoelkeris unset, but not if it is set to the empty string. 13611788b7ffSJilles TjoelkerSee the 13621788b7ffSJilles Tjoelker.Sx White Space Splitting 13631788b7ffSJilles Tjoelkersection for more details. 13641788b7ffSJilles Tjoelker.It Va LINENO 13651788b7ffSJilles TjoelkerThe current line number in the script or function. 13661788b7ffSJilles Tjoelker.It Va MAIL 13671788b7ffSJilles TjoelkerThe name of a mail file, that will be checked for the arrival of new 13681788b7ffSJilles Tjoelkermail. 13691788b7ffSJilles TjoelkerOverridden by 13701788b7ffSJilles Tjoelker.Va MAILPATH . 13711788b7ffSJilles Tjoelker.It Va MAILPATH 13721788b7ffSJilles TjoelkerA colon 13731788b7ffSJilles Tjoelker.Pq Ql \&: 13741788b7ffSJilles Tjoelkerseparated list of file names, for the shell to check for incoming 13751788b7ffSJilles Tjoelkermail. 13761788b7ffSJilles TjoelkerThis variable overrides the 13771788b7ffSJilles Tjoelker.Va MAIL 13781788b7ffSJilles Tjoelkersetting. 13791788b7ffSJilles TjoelkerThere is a maximum of 10 mailboxes that can be monitored at once. 13804445af21SJilles Tjoelker.It Va OPTIND 13814445af21SJilles TjoelkerThe index of the next argument to be processed by 13824445af21SJilles Tjoelker.Ic getopts . 13834445af21SJilles TjoelkerThis is initialized to 1 at startup. 13841788b7ffSJilles Tjoelker.It Va PATH 13851788b7ffSJilles TjoelkerThe default search path for executables. 13861788b7ffSJilles TjoelkerSee the 13871788b7ffSJilles Tjoelker.Sx Path Search 13881788b7ffSJilles Tjoelkersection for details. 13891788b7ffSJilles Tjoelker.It Va PPID 13901788b7ffSJilles TjoelkerThe parent process ID of the invoked shell. 13911788b7ffSJilles TjoelkerThis is set at startup 13921788b7ffSJilles Tjoelkerunless this variable is in the environment. 13931788b7ffSJilles TjoelkerA later change of parent process ID is not reflected. 13941788b7ffSJilles TjoelkerA subshell retains the same value of 13951788b7ffSJilles Tjoelker.Va PPID . 13961788b7ffSJilles Tjoelker.It Va PS1 13971788b7ffSJilles TjoelkerThe primary prompt string, which defaults to 13981788b7ffSJilles Tjoelker.Dq Li "$ " , 13991788b7ffSJilles Tjoelkerunless you are the superuser, in which case it defaults to 14001788b7ffSJilles Tjoelker.Dq Li "# " . 14011ca3beb9SJoel Dahl.Va PS1 14021ca3beb9SJoel Dahlmay include any of the following formatting sequences, 14031ca3beb9SJoel Dahlwhich are replaced by the given information: 14041ca3beb9SJoel Dahl.Bl -tag -width indent 14051ca3beb9SJoel Dahl.It Li \eH 14061ca3beb9SJoel DahlThe local hostname. 14071ca3beb9SJoel Dahl.It Li \eh 14081ca3beb9SJoel DahlThe fully-qualified hostname. 14091ca3beb9SJoel Dahl.It Li \eW 14101ca3beb9SJoel DahlThe final component of the current working directory. 14111ca3beb9SJoel Dahl.It Li \ew 14121ca3beb9SJoel DahlThe entire path of the current working directory. 14131ca3beb9SJoel Dahl.It Li \e$ 14141ca3beb9SJoel DahlSuperuser status. 14151ca3beb9SJoel Dahl.Dq Li "$ " 14161ca3beb9SJoel Dahlfor normal users and 14171ca3beb9SJoel Dahl.Dq Li "# " 14181ca3beb9SJoel Dahlfor superusers. 14191ca3beb9SJoel Dahl.It Li \e\e 14201ca3beb9SJoel DahlA literal backslash. 14211ca3beb9SJoel Dahl.El 14221788b7ffSJilles Tjoelker.It Va PS2 14231788b7ffSJilles TjoelkerThe secondary prompt string, which defaults to 14241788b7ffSJilles Tjoelker.Dq Li "> " . 14251ca3beb9SJoel Dahl.Va PS2 14261ca3beb9SJoel Dahlmay include any of the formatting sequences from 14271ca3beb9SJoel Dahl.Va PS1 . 14281788b7ffSJilles Tjoelker.It Va PS4 14291788b7ffSJilles TjoelkerThe prefix for the trace output (if 14301788b7ffSJilles Tjoelker.Fl x 14311788b7ffSJilles Tjoelkeris active). 14321788b7ffSJilles TjoelkerThe default is 14331788b7ffSJilles Tjoelker.Dq Li "+ " . 14341788b7ffSJilles Tjoelker.El 1435ab72124fSSteve Price.Ss Word Expansions 14364b88c807SRodney W. GrimesThis clause describes the various expansions that are 1437eccea571SRuslan Ermilovperformed on words. 1438eccea571SRuslan ErmilovNot all expansions are performed on 14394b88c807SRodney W. Grimesevery word, as explained later. 1440ab72124fSSteve Price.Pp 14414b88c807SRodney W. GrimesTilde expansions, parameter expansions, command substitutions, 14424b88c807SRodney W. Grimesarithmetic expansions, and quote removals that occur within 1443eccea571SRuslan Ermilova single word expand to a single field. 1444eccea571SRuslan ErmilovIt is only field 14454b88c807SRodney W. Grimessplitting or pathname expansion that can create multiple 1446e6d3cf26SSheldon Hearnfields from a single word. 1447e6d3cf26SSheldon HearnThe single exception to this rule is 1448e918fc8fSSheldon Hearnthe expansion of the special parameter 1449dfe302abSRuslan Ermilov.Va @ 1450e918fc8fSSheldon Hearnwithin double-quotes, 1451e6d3cf26SSheldon Hearnas was described above. 1452ab72124fSSteve Price.Pp 14534b88c807SRodney W. GrimesThe order of word expansion is: 1454ab72124fSSteve Price.Bl -enum 1455ab72124fSSteve Price.It 1456ab72124fSSteve PriceTilde Expansion, Parameter Expansion, Command Substitution, 14574b88c807SRodney W. GrimesArithmetic Expansion (these all occur at the same time). 1458ab72124fSSteve Price.It 145949e11e3aSSheldon HearnField Splitting is performed on fields generated by step (1) 146049e11e3aSSheldon Hearnunless the 1461dfe302abSRuslan Ermilov.Va IFS 146249e11e3aSSheldon Hearnvariable is null. 1463ab72124fSSteve Price.It 146449e11e3aSSheldon HearnPathname Expansion (unless the 146549e11e3aSSheldon Hearn.Fl f 146649e11e3aSSheldon Hearnoption is in effect). 1467ab72124fSSteve Price.It 1468ab72124fSSteve PriceQuote Removal. 1469ab72124fSSteve Price.El 1470ab72124fSSteve Price.Pp 147149e11e3aSSheldon HearnThe 1472dfe302abSRuslan Ermilov.Ql $ 147349e11e3aSSheldon Hearncharacter is used to introduce parameter expansion, command 147436cf3efeSJilles Tjoelkersubstitution, or arithmetic expansion. 1475ab72124fSSteve Price.Ss Tilde Expansion (substituting a user's home directory) 147649e11e3aSSheldon HearnA word beginning with an unquoted tilde character 1477a762afe5SGiorgos Keramidas.Pq Ql ~ 147849e11e3aSSheldon Hearnis 147949e11e3aSSheldon Hearnsubjected to tilde expansion. 148049e11e3aSSheldon HearnAll the characters up to a slash 1481a762afe5SGiorgos Keramidas.Pq Ql / 148249e11e3aSSheldon Hearnor the end of the word are treated as a username 1483eccea571SRuslan Ermilovand are replaced with the user's home directory. 1484eccea571SRuslan ErmilovIf the 1485dfe302abSRuslan Ermilovusername is missing (as in 1486dfe302abSRuslan Ermilov.Pa ~/foobar ) , 1487dfe302abSRuslan Ermilovthe tilde is replaced with the value of the 14881788b7ffSJilles Tjoelker.Va HOME 1489dfe302abSRuslan Ermilovvariable (the current user's home directory). 1490ab72124fSSteve Price.Ss Parameter Expansion 14914b88c807SRodney W. GrimesThe format for parameter expansion is as follows: 1492ab72124fSSteve Price.Pp 1493dfe302abSRuslan Ermilov.D1 Li ${ Ns Ar expression Ns Li } 1494dfe302abSRuslan Ermilov.Pp 1495dfe302abSRuslan Ermilovwhere 1496dfe302abSRuslan Ermilov.Ar expression 1497dfe302abSRuslan Ermilovconsists of all characters until the matching 1498dfe302abSRuslan Ermilov.Ql } . 149949e11e3aSSheldon HearnAny 1500dfe302abSRuslan Ermilov.Ql } 1501f35d74beSJilles Tjoelkerescaped by a backslash or within a single-quoted or double-quoted 1502f35d74beSJilles Tjoelkerstring, and characters in 15034b88c807SRodney W. Grimesembedded arithmetic expansions, command substitutions, and variable 150449e11e3aSSheldon Hearnexpansions, are not examined in determining the matching 1505dfe302abSRuslan Ermilov.Ql } . 1506f35d74beSJilles TjoelkerIf the variants with 1507227c8e2aSJilles Tjoelker.Ql + , 1508227c8e2aSJilles Tjoelker.Ql - , 1509227c8e2aSJilles Tjoelker.Ql = 1510227c8e2aSJilles Tjoelkeror 1511f35d74beSJilles Tjoelker.Ql ?\& 1512f35d74beSJilles Tjoelkeroccur within a double-quoted string, 1513f35d74beSJilles Tjoelkeras an extension there may be unquoted parts 1514f35d74beSJilles Tjoelker(via double-quotes inside the expansion); 1515227c8e2aSJilles Tjoelker.Ql } 1516f35d74beSJilles Tjoelkerwithin such parts are also not examined in determining the matching 1517227c8e2aSJilles Tjoelker.Ql } . 1518ab72124fSSteve Price.Pp 15194b88c807SRodney W. GrimesThe simplest form for parameter expansion is: 1520ab72124fSSteve Price.Pp 1521dfe302abSRuslan Ermilov.D1 Li ${ Ns Ar parameter Ns Li } 1522dfe302abSRuslan Ermilov.Pp 1523dfe302abSRuslan ErmilovThe value, if any, of 1524dfe302abSRuslan Ermilov.Ar parameter 1525dfe302abSRuslan Ermilovis substituted. 1526ab72124fSSteve Price.Pp 15274b88c807SRodney W. GrimesThe parameter name or symbol can be enclosed in braces, which are 15284b88c807SRodney W. Grimesoptional except for positional parameters with more than one digit or 15294b88c807SRodney W. Grimeswhen parameter is followed by a character that could be interpreted as 15304b88c807SRodney W. Grimespart of the name. 1531ab72124fSSteve PriceIf a parameter expansion occurs inside double-quotes: 1532ab72124fSSteve Price.Bl -enum 1533ab72124fSSteve Price.It 1534ab72124fSSteve PriceField splitting is not performed on the results of the 1535e918fc8fSSheldon Hearnexpansion, with the exception of the special parameter 1536dfe302abSRuslan Ermilov.Va @ . 1537ad56ebdcSJilles Tjoelker.It 1538ad56ebdcSJilles TjoelkerPathname expansion is not performed on the results of the 1539ad56ebdcSJilles Tjoelkerexpansion. 1540ab72124fSSteve Price.El 1541ab72124fSSteve Price.Pp 15424b88c807SRodney W. GrimesIn addition, a parameter expansion can be modified by using one of the 15434b88c807SRodney W. Grimesfollowing formats. 154481e9cda2SRuslan Ermilov.Bl -tag -width indent 1545dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li :- Ns Ar word Ns Li } 1546eccea571SRuslan ErmilovUse Default Values. 1547dfe302abSRuslan ErmilovIf 1548dfe302abSRuslan Ermilov.Ar parameter 1549dfe302abSRuslan Ermilovis unset or null, the expansion of 1550dfe302abSRuslan Ermilov.Ar word 1551dfe302abSRuslan Ermilovis substituted; otherwise, the value of 1552dfe302abSRuslan Ermilov.Ar parameter 1553dfe302abSRuslan Ermilovis substituted. 1554dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li := Ns Ar word Ns Li } 1555eccea571SRuslan ErmilovAssign Default Values. 1556dfe302abSRuslan ErmilovIf 1557dfe302abSRuslan Ermilov.Ar parameter 1558dfe302abSRuslan Ermilovis unset or null, the expansion of 1559dfe302abSRuslan Ermilov.Ar word 1560dfe302abSRuslan Ermilovis assigned to 1561dfe302abSRuslan Ermilov.Ar parameter . 1562eccea571SRuslan ErmilovIn all cases, the 1563dfe302abSRuslan Ermilovfinal value of 1564dfe302abSRuslan Ermilov.Ar parameter 1565dfe302abSRuslan Ermilovis substituted. 1566b139165cSJilles TjoelkerQuoting inside 1567b139165cSJilles Tjoelker.Ar word 1568b139165cSJilles Tjoelkerdoes not prevent field splitting or pathname expansion. 1569eccea571SRuslan ErmilovOnly variables, not positional 15704b88c807SRodney W. Grimesparameters or special parameters, can be 15714b88c807SRodney W. Grimesassigned in this way. 1572dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li :? Ns Oo Ar word Oc Ns Li } 1573eccea571SRuslan ErmilovIndicate Error if Null or Unset. 1574eccea571SRuslan ErmilovIf 1575dfe302abSRuslan Ermilov.Ar parameter 1576dfe302abSRuslan Ermilovis unset or null, the expansion of 1577dfe302abSRuslan Ermilov.Ar word 1578dfe302abSRuslan Ermilov(or a message indicating it is unset if 1579dfe302abSRuslan Ermilov.Ar word 1580dfe302abSRuslan Ermilovis omitted) is written to standard 15814b88c807SRodney W. Grimeserror and the shell exits with a nonzero 1582e6d3cf26SSheldon Hearnexit status. 1583e6d3cf26SSheldon HearnOtherwise, the value of 1584dfe302abSRuslan Ermilov.Ar parameter 1585dfe302abSRuslan Ermilovis substituted. 1586eccea571SRuslan ErmilovAn 15874b88c807SRodney W. Grimesinteractive shell need not exit. 1588dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li :+ Ns Ar word Ns Li } 1589eccea571SRuslan ErmilovUse Alternate Value. 1590dfe302abSRuslan ErmilovIf 1591dfe302abSRuslan Ermilov.Ar parameter 1592dfe302abSRuslan Ermilovis unset or null, null is substituted; 1593dfe302abSRuslan Ermilovotherwise, the expansion of 1594dfe302abSRuslan Ermilov.Ar word 1595dfe302abSRuslan Ermilovis substituted. 15961413f7deSTony Finch.El 1597ab72124fSSteve Price.Pp 15984b88c807SRodney W. GrimesIn the parameter expansions shown previously, use of the colon in the 15994b88c807SRodney W. Grimesformat results in a test for a parameter that is unset or null; omission 16004b88c807SRodney W. Grimesof the colon results in a test for a parameter that is only unset. 1601227c8e2aSJilles Tjoelker.Pp 1602227c8e2aSJilles TjoelkerThe 1603227c8e2aSJilles Tjoelker.Ar word 1604227c8e2aSJilles Tjoelkerinherits the type of quoting 1605227c8e2aSJilles Tjoelker(unquoted, double-quoted or here-document) 1606227c8e2aSJilles Tjoelkerfrom the surroundings, 1607227c8e2aSJilles Tjoelkerwith the exception that a backslash that quotes a closing brace is removed 1608227c8e2aSJilles Tjoelkerduring quote removal. 16091413f7deSTony Finch.Bl -tag -width indent 1610dfe302abSRuslan Ermilov.It Li ${# Ns Ar parameter Ns Li } 1611eccea571SRuslan ErmilovString Length. 1612eccea571SRuslan ErmilovThe length in characters of 1613dfe302abSRuslan Ermilovthe value of 1614dfe302abSRuslan Ermilov.Ar parameter . 161571337c33SSheldon Hearn.El 1616ab72124fSSteve Price.Pp 16174b88c807SRodney W. GrimesThe following four varieties of parameter expansion provide for substring 161849e11e3aSSheldon Hearnprocessing. 161949e11e3aSSheldon HearnIn each case, pattern matching notation 162049e11e3aSSheldon Hearn(see 162149e11e3aSSheldon Hearn.Sx Shell Patterns ) , 162249e11e3aSSheldon Hearnrather than regular expression notation, 162349e11e3aSSheldon Hearnis used to evaluate the patterns. 1624e918fc8fSSheldon HearnIf parameter is one of the special parameters 1625dfe302abSRuslan Ermilov.Va * 162649e11e3aSSheldon Hearnor 1627dfe302abSRuslan Ermilov.Va @ , 162849e11e3aSSheldon Hearnthe result of the expansion is unspecified. 16294b88c807SRodney W. GrimesEnclosing the full parameter expansion string in double-quotes does not 16304b88c807SRodney W. Grimescause the following four varieties of pattern characters to be quoted, 16314b88c807SRodney W. Grimeswhereas quoting characters within the braces has this effect. 163281e9cda2SRuslan Ermilov.Bl -tag -width indent 1633dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li % Ns Ar word Ns Li } 1634eccea571SRuslan ErmilovRemove Smallest Suffix Pattern. 1635dfe302abSRuslan ErmilovThe 1636dfe302abSRuslan Ermilov.Ar word 1637eccea571SRuslan Ermilovis expanded to produce a pattern. 1638eccea571SRuslan ErmilovThe 16394b88c807SRodney W. Grimesparameter expansion then results in 1640dfe302abSRuslan Ermilov.Ar parameter , 1641dfe302abSRuslan Ermilovwith the smallest portion of the 16424b88c807SRodney W. Grimessuffix matched by the pattern deleted. 1643dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li %% Ns Ar word Ns Li } 1644eccea571SRuslan ErmilovRemove Largest Suffix Pattern. 1645dfe302abSRuslan ErmilovThe 1646dfe302abSRuslan Ermilov.Ar word 1647eccea571SRuslan Ermilovis expanded to produce a pattern. 1648eccea571SRuslan ErmilovThe 16494b88c807SRodney W. Grimesparameter expansion then results in 1650dfe302abSRuslan Ermilov.Ar parameter , 1651dfe302abSRuslan Ermilovwith the largest portion of the 16524b88c807SRodney W. Grimessuffix matched by the pattern deleted. 1653dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li # Ns Ar word Ns Li } 1654eccea571SRuslan ErmilovRemove Smallest Prefix Pattern. 1655dfe302abSRuslan ErmilovThe 1656dfe302abSRuslan Ermilov.Ar word 1657eccea571SRuslan Ermilovis expanded to produce a pattern. 1658eccea571SRuslan ErmilovThe 16594b88c807SRodney W. Grimesparameter expansion then results in 1660dfe302abSRuslan Ermilov.Ar parameter , 1661dfe302abSRuslan Ermilovwith the smallest portion of the 16624b88c807SRodney W. Grimesprefix matched by the pattern deleted. 1663dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li ## Ns Ar word Ns Li } 1664eccea571SRuslan ErmilovRemove Largest Prefix Pattern. 1665dfe302abSRuslan ErmilovThe 1666dfe302abSRuslan Ermilov.Ar word 1667eccea571SRuslan Ermilovis expanded to produce a pattern. 1668eccea571SRuslan ErmilovThe 16694b88c807SRodney W. Grimesparameter expansion then results in 1670dfe302abSRuslan Ermilov.Ar parameter , 1671dfe302abSRuslan Ermilovwith the largest portion of the 16724b88c807SRodney W. Grimesprefix matched by the pattern deleted. 1673ab72124fSSteve Price.El 1674ab72124fSSteve Price.Ss Command Substitution 16754b88c807SRodney W. GrimesCommand substitution allows the output of a command to be substituted in 1676eccea571SRuslan Ermilovplace of the command name itself. 1677eccea571SRuslan ErmilovCommand substitution occurs when 16784b88c807SRodney W. Grimesthe command is enclosed as follows: 1679dfe302abSRuslan Ermilov.Pp 1680dfe302abSRuslan Ermilov.D1 Li $( Ns Ar command Ns Li )\& 1681ab72124fSSteve Price.Pp 168249e11e3aSSheldon Hearnor the backquoted version: 1683dfe302abSRuslan Ermilov.Pp 1684dfe302abSRuslan Ermilov.D1 Li ` Ns Ar command Ns Li ` 1685ab72124fSSteve Price.Pp 1686ef89d04fSJilles TjoelkerThe shell expands the command substitution by executing command 1687ef89d04fSJilles Tjoelkerand replacing the command substitution 168849e11e3aSSheldon Hearnwith the standard output of the command, 168949e11e3aSSheldon Hearnremoving sequences of one or more newlines at the end of the substitution. 169049e11e3aSSheldon HearnEmbedded newlines before the end of the output are not removed; 169149e11e3aSSheldon Hearnhowever, during field splitting, they may be translated into spaces 169249e11e3aSSheldon Hearndepending on the value of 1693dfe302abSRuslan Ermilov.Va IFS 169449e11e3aSSheldon Hearnand the quoting that is in effect. 1695ef89d04fSJilles TjoelkerThe command is executed in a subshell environment, 1696ef89d04fSJilles Tjoelkerexcept that the built-in commands 1697ef89d04fSJilles Tjoelker.Ic jobid , 1698ef89d04fSJilles Tjoelker.Ic jobs , 1699ef89d04fSJilles Tjoelkerand 1700ef89d04fSJilles Tjoelker.Ic trap 170151a514adSJilles Tjoelkerreturn information about the parent shell environment 170251a514adSJilles Tjoelkerand 170351a514adSJilles Tjoelker.Ic times 170451a514adSJilles Tjoelkerreturns information about the same process 1705c543e1aeSJilles Tjoelkerif they are the only command in a command substitution. 170654ccc8b5SJilles Tjoelker.Pp 170754ccc8b5SJilles TjoelkerIf a command substitution of the 170854ccc8b5SJilles Tjoelker.Li $( 170954ccc8b5SJilles Tjoelkerform begins with a subshell, 171054ccc8b5SJilles Tjoelkerthe 171154ccc8b5SJilles Tjoelker.Li $( 171254ccc8b5SJilles Tjoelkerand 17135127efa3SJoel Dahl.Li (\& 171454ccc8b5SJilles Tjoelkermust be separated by whitespace 171554ccc8b5SJilles Tjoelkerto avoid ambiguity with arithmetic expansion. 1716ab72124fSSteve Price.Ss Arithmetic Expansion 17174b88c807SRodney W. GrimesArithmetic expansion provides a mechanism for evaluating an arithmetic 1718e6d3cf26SSheldon Hearnexpression and substituting its value. 1719e6d3cf26SSheldon HearnThe format for arithmetic expansion is as follows: 1720ab72124fSSteve Price.Pp 1721dfe302abSRuslan Ermilov.D1 Li $(( Ns Ar expression Ns Li )) 1722dfe302abSRuslan Ermilov.Pp 1723dfe302abSRuslan ErmilovThe 1724dfe302abSRuslan Ermilov.Ar expression 1725dfe302abSRuslan Ermilovis treated as if it were in double-quotes, except 1726eccea571SRuslan Ermilovthat a double-quote inside the expression is not treated specially. 1727eccea571SRuslan ErmilovThe 1728dfe302abSRuslan Ermilovshell expands all tokens in the 1729dfe302abSRuslan Ermilov.Ar expression 1730dfe302abSRuslan Ermilovfor parameter expansion, 173136cf3efeSJilles Tjoelkercommand substitution, 173236cf3efeSJilles Tjoelkerarithmetic expansion 173336cf3efeSJilles Tjoelkerand quote removal. 1734ab72124fSSteve Price.Pp 173536cf3efeSJilles TjoelkerThe allowed expressions are a subset of C expressions, 173636cf3efeSJilles Tjoelkersummarized below. 173736cf3efeSJilles Tjoelker.Bl -tag -width "Variables" -offset indent 173836cf3efeSJilles Tjoelker.It Values 173936cf3efeSJilles TjoelkerAll values are of type 174036cf3efeSJilles Tjoelker.Ft intmax_t . 174136cf3efeSJilles Tjoelker.It Constants 174236cf3efeSJilles TjoelkerDecimal, octal (starting with 174336cf3efeSJilles Tjoelker.Li 0 ) 174436cf3efeSJilles Tjoelkerand hexadecimal (starting with 174536cf3efeSJilles Tjoelker.Li 0x ) 174636cf3efeSJilles Tjoelkerinteger constants. 174736cf3efeSJilles Tjoelker.It Variables 174836cf3efeSJilles TjoelkerShell variables can be read and written 174936cf3efeSJilles Tjoelkerand contain integer constants. 175036cf3efeSJilles Tjoelker.It Unary operators 175136cf3efeSJilles Tjoelker.Li "! ~ + -" 175236cf3efeSJilles Tjoelker.It Binary operators 175336cf3efeSJilles Tjoelker.Li "* / % + - << >> < <= > >= == != & ^ | && ||" 175436cf3efeSJilles Tjoelker.It Assignment operators 175536cf3efeSJilles Tjoelker.Li "= += -= *= /= %= <<= >>= &= ^= |=" 1756075b72efSJilles Tjoelker.It Conditional operator 1757075b72efSJilles Tjoelker.Li "? :" 175836cf3efeSJilles Tjoelker.El 175936cf3efeSJilles Tjoelker.Pp 176036cf3efeSJilles TjoelkerThe result of the expression is substituted in decimal. 1761ab72124fSSteve Price.Ss White Space Splitting (Field Splitting) 1762ad56ebdcSJilles TjoelkerIn certain contexts, 1763ad56ebdcSJilles Tjoelkerafter parameter expansion, command substitution, and 17644b88c807SRodney W. Grimesarithmetic expansion the shell scans the results of 17654b88c807SRodney W. Grimesexpansions and substitutions that did not occur in double-quotes for 17664b88c807SRodney W. Grimesfield splitting and multiple fields can result. 1767ab72124fSSteve Price.Pp 1768ad56ebdcSJilles TjoelkerCharacters in 1769dfe302abSRuslan Ermilov.Va IFS 1770ad56ebdcSJilles Tjoelkerthat are whitespace 1771ad56ebdcSJilles Tjoelker.Po 1772ad56ebdcSJilles Tjoelker.Aq space , 1773ad56ebdcSJilles Tjoelker.Aq tab , 1774ad56ebdcSJilles Tjoelkerand 1775ad56ebdcSJilles Tjoelker.Aq newline 1776ad56ebdcSJilles Tjoelker.Pc 1777ad56ebdcSJilles Tjoelkerare treated differently from other characters in 1778ad56ebdcSJilles Tjoelker.Va IFS . 1779ad56ebdcSJilles Tjoelker.Pp 1780ad56ebdcSJilles TjoelkerWhitespace in 1781ad56ebdcSJilles Tjoelker.Va IFS 1782ad56ebdcSJilles Tjoelkerat the beginning or end of a word is discarded. 1783ad56ebdcSJilles Tjoelker.Pp 1784ad56ebdcSJilles TjoelkerSubsequently, a field is delimited by either 1785ad56ebdcSJilles Tjoelker.Bl -enum 1786ad56ebdcSJilles Tjoelker.It 1787ad56ebdcSJilles Tjoelkera non-whitespace character in 1788ad56ebdcSJilles Tjoelker.Va IFS 1789ad56ebdcSJilles Tjoelkerwith any whitespace in 1790ad56ebdcSJilles Tjoelker.Va IFS 1791ad56ebdcSJilles Tjoelkersurrounding it, or 1792ad56ebdcSJilles Tjoelker.It 1793ad56ebdcSJilles Tjoelkerone or more whitespace characters in 1794ad56ebdcSJilles Tjoelker.Va IFS . 1795ad56ebdcSJilles Tjoelker.El 1796ad56ebdcSJilles Tjoelker.Pp 1797ad56ebdcSJilles TjoelkerIf a word ends with a non-whitespace character in 1798ad56ebdcSJilles Tjoelker.Va IFS , 1799ad56ebdcSJilles Tjoelkerthere is no empty field after this character. 1800ad56ebdcSJilles Tjoelker.Pp 1801ad56ebdcSJilles TjoelkerIf no field is delimited, the word is discarded. 1802ad56ebdcSJilles TjoelkerIn particular, if a word consists solely of an unquoted substitution 1803ad56ebdcSJilles Tjoelkerand the result of the substitution is null, 1804ad56ebdcSJilles Tjoelkerit is removed by field splitting even if 1805ad56ebdcSJilles Tjoelker.Va IFS 1806ad56ebdcSJilles Tjoelkeris null. 1807ab72124fSSteve Price.Ss Pathname Expansion (File Name Generation) 180849e11e3aSSheldon HearnUnless the 180949e11e3aSSheldon Hearn.Fl f 181049e11e3aSSheldon Hearnoption is set, 181149e11e3aSSheldon Hearnfile name generation is performed 1812eccea571SRuslan Ermilovafter word splitting is complete. 1813eccea571SRuslan ErmilovEach word is 1814eccea571SRuslan Ermilovviewed as a series of patterns, separated by slashes. 1815eccea571SRuslan ErmilovThe 18164b88c807SRodney W. Grimesprocess of expansion replaces the word with the names of 18174b88c807SRodney W. Grimesall existing files whose names can be formed by replacing 18184b88c807SRodney W. Grimeseach pattern with a string that matches the specified pattern. 1819ab0a2172SSteve PriceThere are two restrictions on this: first, a pattern cannot match 1820ab0a2172SSteve Pricea string containing a slash, and second, 18214b88c807SRodney W. Grimesa pattern cannot match a string starting with a period 18224b88c807SRodney W. Grimesunless the first character of the pattern is a period. 1823519c4ef3SJilles TjoelkerThe next section describes the patterns used for 1824519c4ef3SJilles TjoelkerPathname Expansion, 1825519c4ef3SJilles Tjoelkerthe four varieties of parameter expansion for substring processing and the 1826c644db6aSSheldon Hearn.Ic case 1827ab72124fSSteve Pricecommand. 1828ab72124fSSteve Price.Ss Shell Patterns 1829f434d1dfSAdam DavidA pattern consists of normal characters, which match themselves, 183049e11e3aSSheldon Hearnand meta-characters. 183149e11e3aSSheldon HearnThe meta-characters are 1832dfe302abSRuslan Ermilov.Ql * , 1833dfe302abSRuslan Ermilov.Ql \&? , 18346b15476eSSheldon Hearnand 1835dfe302abSRuslan Ermilov.Ql \&[ . 18366b15476eSSheldon HearnThese characters lose their special meanings if they are quoted. 18376b15476eSSheldon HearnWhen command or variable substitution is performed and the dollar sign 18386b15476eSSheldon Hearnor back quotes are not double-quoted, the value of the 18394b88c807SRodney W. Grimesvariable or the output of the command is scanned for these 18404b88c807SRodney W. Grimescharacters and they are turned into meta-characters. 1841ab72124fSSteve Price.Pp 18426b15476eSSheldon HearnAn asterisk 1843a762afe5SGiorgos Keramidas.Pq Ql * 1844e918fc8fSSheldon Hearnmatches any string of characters. 1845e918fc8fSSheldon HearnA question mark 1846a762afe5SGiorgos Keramidas.Pq Ql \&? 1847e918fc8fSSheldon Hearnmatches any single character. 1848e6d3cf26SSheldon HearnA left bracket 1849dfe302abSRuslan Ermilov.Pq Ql \&[ 1850e6d3cf26SSheldon Hearnintroduces a character class. 1851e6d3cf26SSheldon HearnThe end of the character class is indicated by a 1852dfe302abSRuslan Ermilov.Ql \&] ; 18536b15476eSSheldon Hearnif the 1854dfe302abSRuslan Ermilov.Ql \&] 18556b15476eSSheldon Hearnis missing then the 1856dfe302abSRuslan Ermilov.Ql \&[ 18576b15476eSSheldon Hearnmatches a 1858dfe302abSRuslan Ermilov.Ql \&[ 1859e6d3cf26SSheldon Hearnrather than introducing a character class. 1860e6d3cf26SSheldon HearnA character class matches any of the characters between the square brackets. 1861519c4ef3SJilles TjoelkerA locale-dependent range of characters may be specified using a minus sign. 1862ff4dc672SJilles TjoelkerA named class of characters (see 1863ff4dc672SJilles Tjoelker.Xr wctype 3 ) 1864ff4dc672SJilles Tjoelkermay be specified by surrounding the name with 1865ff4dc672SJilles Tjoelker.Ql \&[: 1866ff4dc672SJilles Tjoelkerand 1867ff4dc672SJilles Tjoelker.Ql :\&] . 1868ff4dc672SJilles TjoelkerFor example, 1869ff4dc672SJilles Tjoelker.Ql \&[\&[:alpha:\&]\&] 1870ff4dc672SJilles Tjoelkeris a shell pattern that matches a single letter. 1871e918fc8fSSheldon HearnThe character class may be complemented by making an exclamation point 1872a762afe5SGiorgos Keramidas.Pq Ql !\& 1873e918fc8fSSheldon Hearnthe first character of the character class. 1874519c4ef3SJilles TjoelkerA caret 1875519c4ef3SJilles Tjoelker.Pq Ql ^ 1876519c4ef3SJilles Tjoelkerhas the same effect but is non-standard. 1877ab72124fSSteve Price.Pp 18786b15476eSSheldon HearnTo include a 1879dfe302abSRuslan Ermilov.Ql \&] 1880e6d3cf26SSheldon Hearnin a character class, make it the first character listed 1881e6d3cf26SSheldon Hearn(after the 1882519c4ef3SJilles Tjoelker.Ql \&! 1883519c4ef3SJilles Tjoelkeror 1884519c4ef3SJilles Tjoelker.Ql ^ , 1885e6d3cf26SSheldon Hearnif any). 1886e918fc8fSSheldon HearnTo include a 1887dfe302abSRuslan Ermilov.Ql - , 1888e918fc8fSSheldon Hearnmake it the first or last character listed. 18898eed22b1SJens Schweikhardt.Ss Built-in Commands 189025f6b31fSJilles TjoelkerThis section lists the built-in commands. 189181e9cda2SRuslan Ermilov.Bl -tag -width indent 1892d0353b83SRuslan Ermilov.It Ic \&: 1893aa9caaf6SPeter WemmA null command that returns a 0 (true) exit value. 1894d0353b83SRuslan Ermilov.It Ic \&. Ar file 1895aa9caaf6SPeter WemmThe commands in the specified file are read and executed by the shell. 18964ad8968aSBrian FeldmanThe 18974ad8968aSBrian Feldman.Ic return 18984ad8968aSBrian Feldmancommand may be used to return to the 18994ad8968aSBrian Feldman.Ic \&. 19004ad8968aSBrian Feldmancommand's caller. 19016466945aSJohn PolstraIf 19026466945aSJohn Polstra.Ar file 19036466945aSJohn Polstracontains any 1904dfe302abSRuslan Ermilov.Ql / 1905eccea571SRuslan Ermilovcharacters, it is used as is. 1906eccea571SRuslan ErmilovOtherwise, the shell searches the 19071788b7ffSJilles Tjoelker.Va PATH 1908eccea571SRuslan Ermilovfor the file. 1909eccea571SRuslan ErmilovIf it is not found in the 19101788b7ffSJilles Tjoelker.Va PATH , 19116466945aSJohn Polstrait is sought in the current working directory. 191210845922SYaroslav Tykhiy.It Ic \&[ 191310845922SYaroslav TykhiyA built-in equivalent of 191410845922SYaroslav Tykhiy.Xr test 1 . 1915a886288eSJesus R. Camou.It Ic alias Oo Ar name Ns Oo = Ns Ar string Oc ... Oc 191649e11e3aSSheldon HearnIf 1917d0353b83SRuslan Ermilov.Ar name Ns = Ns Ar string 191849e11e3aSSheldon Hearnis specified, the shell defines the alias 191949e11e3aSSheldon Hearn.Ar name 19206b15476eSSheldon Hearnwith value 192149e11e3aSSheldon Hearn.Ar string . 19226b15476eSSheldon HearnIf just 192349e11e3aSSheldon Hearn.Ar name 19246b15476eSSheldon Hearnis specified, the value of the alias 192549e11e3aSSheldon Hearn.Ar name 19266b15476eSSheldon Hearnis printed. 192749e11e3aSSheldon HearnWith no arguments, the 192849e11e3aSSheldon Hearn.Ic alias 19298eed22b1SJens Schweikhardtbuilt-in command prints the names and values of all defined aliases 193049e11e3aSSheldon Hearn(see 193149e11e3aSSheldon Hearn.Ic unalias ) . 1932e5341cbbSTim J. RobbinsAlias values are written with appropriate quoting so that they are 19339ba31ca0SRuslan Ermilovsuitable for re-input to the shell. 1934a886288eSJesus R. CamouAlso see the 1935a886288eSJesus R. Camou.Sx Aliases 1936a886288eSJesus R. Camousubsection. 193749e11e3aSSheldon Hearn.It Ic bg Op Ar job ... 193849e11e3aSSheldon HearnContinue the specified jobs 193949e11e3aSSheldon Hearn(or the current job if no jobs are given) 194049e11e3aSSheldon Hearnin the background. 194125f6b31fSJilles Tjoelker.It Ic bind Oo Fl aeklrsv Oc Oo Ar key Oo Ar command Oc Oc 194225f6b31fSJilles TjoelkerList or alter key bindings for the line editor. 194325f6b31fSJilles TjoelkerThis command is documented in 194425f6b31fSJilles Tjoelker.Xr editrc 5 . 194525f6b31fSJilles Tjoelker.It Ic break Op Ar num 194625f6b31fSJilles TjoelkerSee the 194725f6b31fSJilles Tjoelker.Sx Flow-Control Constructs 194825f6b31fSJilles Tjoelkersubsection. 1949df9e587bSTim J. Robbins.It Ic builtin Ar cmd Op Ar arg ... 19508eed22b1SJens SchweikhardtExecute the specified built-in command, 195149e11e3aSSheldon Hearn.Ar cmd . 195249e11e3aSSheldon HearnThis is useful when the user wishes to override a shell function 19538eed22b1SJens Schweikhardtwith the same name as a built-in command. 1954d6ee26adSJilles Tjoelker.It Ic cd Oo Fl L | P Oc Oo Fl e Oc Op Ar directory 19557b6779b6SJilles Tjoelker.It Ic cd Fl 195649e11e3aSSheldon HearnSwitch to the specified 195749e11e3aSSheldon Hearn.Ar directory , 19587b6779b6SJilles Tjoelkerto the directory specified in the 19591788b7ffSJilles Tjoelker.Va HOME 196049e11e3aSSheldon Hearnenvironment variable if no 196149e11e3aSSheldon Hearn.Ar directory 19627b6779b6SJilles Tjoelkeris specified or 19637b6779b6SJilles Tjoelkerto the directory specified in the 19647b6779b6SJilles Tjoelker.Va OLDPWD 19657b6779b6SJilles Tjoelkerenvironment variable if 19667b6779b6SJilles Tjoelker.Ar directory 19677b6779b6SJilles Tjoelkeris 19687b6779b6SJilles Tjoelker.Fl . 196949e11e3aSSheldon HearnIf 197049e11e3aSSheldon Hearn.Ar directory 1971029c8ee4STim J. Robbinsdoes not begin with 19729ba31ca0SRuslan Ermilov.Pa / , \&. , 197349e11e3aSSheldon Hearnor 1974029c8ee4STim J. Robbins.Pa .. , 197549e11e3aSSheldon Hearnthen the directories listed in the 19761788b7ffSJilles Tjoelker.Va CDPATH 197749e11e3aSSheldon Hearnvariable will be 197849e11e3aSSheldon Hearnsearched for the specified 197949e11e3aSSheldon Hearn.Ar directory . 1980029c8ee4STim J. RobbinsIf 19811788b7ffSJilles Tjoelker.Va CDPATH 1982029c8ee4STim J. Robbinsis unset, the current directory is searched. 198349e11e3aSSheldon HearnThe format of 19841788b7ffSJilles Tjoelker.Va CDPATH 198549e11e3aSSheldon Hearnis the same as that of 19861788b7ffSJilles Tjoelker.Va PATH . 1987e6d3cf26SSheldon HearnIn an interactive shell, 198849e11e3aSSheldon Hearnthe 198949e11e3aSSheldon Hearn.Ic cd 199049e11e3aSSheldon Hearncommand will print out the name of the directory 1991e6d3cf26SSheldon Hearnthat it actually switched to 19927b6779b6SJilles Tjoelkerif the 19931788b7ffSJilles Tjoelker.Va CDPATH 19947b6779b6SJilles Tjoelkermechanism was used or if 19957b6779b6SJilles Tjoelker.Ar directory 19967b6779b6SJilles Tjoelkerwas 19977b6779b6SJilles Tjoelker.Fl . 1998178897f1STim J. Robbins.Pp 1999178897f1STim J. RobbinsIf the 2000178897f1STim J. Robbins.Fl P 2001178897f1STim J. Robbinsoption is specified, 200281e9cda2SRuslan Ermilov.Pa .. 2003178897f1STim J. Robbinsis handled physically and symbolic links are resolved before 200481e9cda2SRuslan Ermilov.Pa .. 2005178897f1STim J. Robbinscomponents are processed. 2006178897f1STim J. RobbinsIf the 2007178897f1STim J. Robbins.Fl L 2008178897f1STim J. Robbinsoption is specified, 200981e9cda2SRuslan Ermilov.Pa .. 2010178897f1STim J. Robbinsis handled logically. 2011178897f1STim J. RobbinsThis is the default. 2012d6ee26adSJilles Tjoelker.Pp 2013d6ee26adSJilles TjoelkerThe 2014d6ee26adSJilles Tjoelker.Fl e 2015d6ee26adSJilles Tjoelkeroption causes 2016d6ee26adSJilles Tjoelker.Ic cd 2017d6ee26adSJilles Tjoelkerto return exit status 1 if the full pathname of the new directory 2018d6ee26adSJilles Tjoelkercannot be determined reliably or at all. 2019d6ee26adSJilles TjoelkerNormally this is not considered an error, 2020d6ee26adSJilles Tjoelkeralthough a warning is printed. 20219434a1c7SDima Dorfman.It Ic chdir 20229434a1c7SDima DorfmanA synonym for the 20239434a1c7SDima Dorfman.Ic cd 20248eed22b1SJens Schweikhardtbuilt-in command. 20259ba31ca0SRuslan Ermilov.It Ic command Oo Fl p Oc Op Ar utility Op Ar argument ... 2026b97d13b3SJilles Tjoelker.It Ic command Oo Fl p Oc Fl v Ar utility 2027b97d13b3SJilles Tjoelker.It Ic command Oo Fl p Oc Fl V Ar utility 202833b222b9SStefan FarfelederThe first form of invocation executes the specified 2029c848bc18SJilles Tjoelker.Ar utility , 2030c848bc18SJilles Tjoelkerignoring shell functions in the search. 2031c848bc18SJilles TjoelkerIf 20322babaf74STim J. Robbins.Ar utility 2033c848bc18SJilles Tjoelkeris a special builtin, 2034c848bc18SJilles Tjoelkerit is executed as if it were a regular builtin. 20352babaf74STim J. Robbins.Pp 20362babaf74STim J. RobbinsIf the 20372babaf74STim J. Robbins.Fl p 20382babaf74STim J. Robbinsoption is specified, the command search is performed using a 20392babaf74STim J. Robbinsdefault value of 20401788b7ffSJilles Tjoelker.Va PATH 20412babaf74STim J. Robbinsthat is guaranteed to find all of the standard utilities. 204233b222b9SStefan Farfeleder.Pp 204333b222b9SStefan FarfelederIf the 204433b222b9SStefan Farfeleder.Fl v 204533b222b9SStefan Farfelederoption is specified, 204633b222b9SStefan Farfeleder.Ar utility 204733b222b9SStefan Farfelederis not executed but a description of its interpretation by the shell is 204833b222b9SStefan Farfelederprinted. 204933b222b9SStefan FarfelederFor ordinary commands the output is the path name; for shell built-in 205033b222b9SStefan Farfeledercommands, shell functions and keywords only the name is written. 205133b222b9SStefan FarfelederAliases are printed as 205233b222b9SStefan Farfeleder.Dq Ic alias Ar name Ns = Ns Ar value . 205333b222b9SStefan Farfeleder.Pp 205433b222b9SStefan FarfelederThe 205533b222b9SStefan Farfeleder.Fl V 205633b222b9SStefan Farfelederoption is identical to 205733b222b9SStefan Farfeleder.Fl v 205833b222b9SStefan Farfelederexcept for the output. 205933b222b9SStefan FarfelederIt prints 206033b222b9SStefan Farfeleder.Dq Ar utility Ic is Ar description 206133b222b9SStefan Farfelederwhere 206233b222b9SStefan Farfeleder.Ar description 206333b222b9SStefan Farfelederis either 206433b222b9SStefan Farfelederthe path name to 206533b222b9SStefan Farfeleder.Ar utility , 206630268dfaSJilles Tjoelkera special shell builtin, 20678af11131SRuslan Ermilova shell builtin, 20688af11131SRuslan Ermilova shell function, 20698af11131SRuslan Ermilova shell keyword 207033b222b9SStefan Farfelederor 20718af11131SRuslan Ermilovan alias for 20728af11131SRuslan Ermilov.Ar value . 207325f6b31fSJilles Tjoelker.It Ic continue Op Ar num 207425f6b31fSJilles TjoelkerSee the 207525f6b31fSJilles Tjoelker.Sx Flow-Control Constructs 207625f6b31fSJilles Tjoelkersubsection. 207773313421SStefan Farfeleder.It Ic echo Oo Fl e | n Oc Op Ar string ... 207873313421SStefan FarfelederPrint a space-separated list of the arguments to the standard output 207973313421SStefan Farfelederand append a newline character. 208081e9cda2SRuslan Ermilov.Bl -tag -width indent 2081501e74b7SMark Ovens.It Fl n 2082501e74b7SMark OvensSuppress the output of the trailing newline. 2083501e74b7SMark Ovens.It Fl e 2084501e74b7SMark OvensProcess C-style backslash escape sequences. 2085dfe302abSRuslan ErmilovThe 2086501e74b7SMark Ovens.Ic echo 2087dfe302abSRuslan Ermilovcommand understands the following character escapes: 208881e9cda2SRuslan Ermilov.Bl -tag -width indent 2089501e74b7SMark Ovens.It \ea 2090501e74b7SMark OvensAlert (ring the terminal bell) 2091501e74b7SMark Ovens.It \eb 2092501e74b7SMark OvensBackspace 2093501e74b7SMark Ovens.It \ec 2094501e74b7SMark OvensSuppress the trailing newline (this has the side-effect of truncating the 2095501e74b7SMark Ovensline if it is not the last character) 2096501e74b7SMark Ovens.It \ee 2097dfe302abSRuslan ErmilovThe ESC character 2098dfe302abSRuslan Ermilov.Tn ( ASCII 2099dfe302abSRuslan Ermilov0x1b) 2100501e74b7SMark Ovens.It \ef 2101501e74b7SMark OvensFormfeed 2102501e74b7SMark Ovens.It \en 2103501e74b7SMark OvensNewline 2104501e74b7SMark Ovens.It \er 2105501e74b7SMark OvensCarriage return 2106501e74b7SMark Ovens.It \et 2107501e74b7SMark OvensHorizontal tab 2108501e74b7SMark Ovens.It \ev 2109501e74b7SMark OvensVertical tab 2110501e74b7SMark Ovens.It \e\e 2111501e74b7SMark OvensLiteral backslash 2112501e74b7SMark Ovens.It \e0nnn 2113dfe302abSRuslan Ermilov(Zero) The character whose octal value is 2114dfe302abSRuslan Ermilov.Ar nnn 2115501e74b7SMark Ovens.El 2116501e74b7SMark Ovens.Pp 2117501e74b7SMark OvensIf 2118501e74b7SMark Ovens.Ar string 2119501e74b7SMark Ovensis not enclosed in quotes then the backslash itself must be escaped 2120eccea571SRuslan Ermilovwith a backslash to protect it from the shell. 2121eccea571SRuslan ErmilovFor example 2122501e74b7SMark Ovens.Bd -literal -offset indent 2123501e74b7SMark Ovens$ echo -e "a\evb" 2124501e74b7SMark Ovensa 2125501e74b7SMark Ovens b 2126501e74b7SMark Ovens$ echo -e a\e\evb 2127501e74b7SMark Ovensa 2128501e74b7SMark Ovens b 2129501e74b7SMark Ovens$ echo -e "a\e\eb" 2130501e74b7SMark Ovensa\eb 2131501e74b7SMark Ovens$ echo -e a\e\e\e\eb 2132501e74b7SMark Ovensa\eb 2133501e74b7SMark Ovens.Ed 2134501e74b7SMark Ovens.El 2135558175caSTim J. Robbins.Pp 2136558175caSTim J. RobbinsOnly one of the 2137558175caSTim J. Robbins.Fl e 2138558175caSTim J. Robbinsand 2139558175caSTim J. Robbins.Fl n 2140558175caSTim J. Robbinsoptions may be specified. 214149e11e3aSSheldon Hearn.It Ic eval Ar string ... 2142e6d3cf26SSheldon HearnConcatenate all the arguments with spaces. 2143e6d3cf26SSheldon HearnThen re-parse and execute the command. 214449e11e3aSSheldon Hearn.It Ic exec Op Ar command Op arg ... 214549e11e3aSSheldon HearnUnless 214649e11e3aSSheldon Hearn.Ar command 214749e11e3aSSheldon Hearnis omitted, 214849e11e3aSSheldon Hearnthe shell process is replaced with the specified program 21498eed22b1SJens Schweikhardt(which must be a real program, not a shell built-in command or function). 215049e11e3aSSheldon HearnAny redirections on the 215149e11e3aSSheldon Hearn.Ic exec 215249e11e3aSSheldon Hearncommand are marked as permanent, 215349e11e3aSSheldon Hearnso that they are not undone when the 215449e11e3aSSheldon Hearn.Ic exec 215549e11e3aSSheldon Hearncommand finishes. 215649e11e3aSSheldon Hearn.It Ic exit Op Ar exitstatus 215749e11e3aSSheldon HearnTerminate the shell process. 215849e11e3aSSheldon HearnIf 215949e11e3aSSheldon Hearn.Ar exitstatus 216049e11e3aSSheldon Hearnis given 2161ea381e69SJilles Tjoelkerit is used as the exit status of the shell. 2162ea381e69SJilles TjoelkerOtherwise, if the shell is executing an 2163421fb021SJilles Tjoelker.Cm EXIT 2164421fb021SJilles Tjoelkertrap, the exit status of the last command before the trap is used; 2165421fb021SJilles Tjoelkerif the shell is executing a trap for a signal, 2166ea381e69SJilles Tjoelkerthe shell exits by resending the signal to itself. 2167ea381e69SJilles TjoelkerOtherwise, the exit status of the preceding command is used. 2168a68fbc44SJilles TjoelkerThe exit status should be an integer between 0 and 255. 2169ef9791a3SStefan Farfeleder.It Ic export Ar name ... 2170ef9791a3SStefan Farfeleder.It Ic export Op Fl p 21714b88c807SRodney W. GrimesThe specified names are exported so that they will 21724b88c807SRodney W. Grimesappear in the environment of subsequent commands. 217349e11e3aSSheldon HearnThe only way to un-export a variable is to 217449e11e3aSSheldon Hearn.Ic unset 217549e11e3aSSheldon Hearnit. 217649e11e3aSSheldon HearnThe shell allows the value of a variable to be set 217749e11e3aSSheldon Hearnat the same time as it is exported by writing 2178ab72124fSSteve Price.Pp 2179dfe302abSRuslan Ermilov.D1 Ic export Ar name Ns = Ns Ar value 2180dfe302abSRuslan Ermilov.Pp 2181dfe302abSRuslan ErmilovWith no arguments the 2182dfe302abSRuslan Ermilov.Ic export 2183dfe302abSRuslan Ermilovcommand lists the names 21844b88c807SRodney W. Grimesof all exported variables. 218545086f8cSTim J. RobbinsIf the 218645086f8cSTim J. Robbins.Fl p 218745086f8cSTim J. Robbinsoption is specified, the exported variables are printed as 218845086f8cSTim J. Robbins.Dq Ic export Ar name Ns = Ns Ar value 218945086f8cSTim J. Robbinslines, suitable for re-input to the shell. 2190a6557dcbSYaroslav Tykhiy.It Ic false 2191a6557dcbSYaroslav TykhiyA null command that returns a non-zero (false) exit value. 219281e9cda2SRuslan Ermilov.It Ic fc Oo Fl e Ar editor Oc Op Ar first Op Ar last 219381e9cda2SRuslan Ermilov.It Ic fc Fl l Oo Fl nr Oc Op Ar first Op Ar last 219481e9cda2SRuslan Ermilov.It Ic fc Fl s Oo Ar old Ns = Ns Ar new Oc Op Ar first 219549e11e3aSSheldon HearnThe 219649e11e3aSSheldon Hearn.Ic fc 21978eed22b1SJens Schweikhardtbuilt-in command lists, or edits and re-executes, 219849e11e3aSSheldon Hearncommands previously entered to an interactive shell. 219981e9cda2SRuslan Ermilov.Bl -tag -width indent 220049e11e3aSSheldon Hearn.It Fl e Ar editor 220149e11e3aSSheldon HearnUse the editor named by 220249e11e3aSSheldon Hearn.Ar editor 220349e11e3aSSheldon Hearnto edit the commands. 2204dfe302abSRuslan ErmilovThe 2205dfe302abSRuslan Ermilov.Ar editor 2206dfe302abSRuslan Ermilovstring is a command name, 220749e11e3aSSheldon Hearnsubject to search via the 22081788b7ffSJilles Tjoelker.Va PATH 220949e11e3aSSheldon Hearnvariable. 221049e11e3aSSheldon HearnThe value in the 22111788b7ffSJilles Tjoelker.Va FCEDIT 221249e11e3aSSheldon Hearnvariable is used as a default when 221349e11e3aSSheldon Hearn.Fl e 221449e11e3aSSheldon Hearnis not specified. 221549e11e3aSSheldon HearnIf 22161788b7ffSJilles Tjoelker.Va FCEDIT 221749e11e3aSSheldon Hearnis null or unset, the value of the 22181788b7ffSJilles Tjoelker.Va EDITOR 221949e11e3aSSheldon Hearnvariable is used. 222049e11e3aSSheldon HearnIf 22211788b7ffSJilles Tjoelker.Va EDITOR 222249e11e3aSSheldon Hearnis null or unset, 2223ab72124fSSteve Price.Xr ed 1 2224ab72124fSSteve Priceis used as the editor. 222549e11e3aSSheldon Hearn.It Fl l No (ell) 22264b88c807SRodney W. GrimesList the commands rather than invoking 2227eccea571SRuslan Ermilovan editor on them. 2228eccea571SRuslan ErmilovThe commands are written in the 2229dfe302abSRuslan Ermilovsequence indicated by the 2230dfe302abSRuslan Ermilov.Ar first 2231dfe302abSRuslan Ermilovand 2232dfe302abSRuslan Ermilov.Ar last 2233dfe302abSRuslan Ermilovoperands, as affected by 223449e11e3aSSheldon Hearn.Fl r , 223549e11e3aSSheldon Hearnwith each command preceded by the command number. 223649e11e3aSSheldon Hearn.It Fl n 223749e11e3aSSheldon HearnSuppress command numbers when listing with 223849e11e3aSSheldon Hearn.Fl l . 223949e11e3aSSheldon Hearn.It Fl r 224049e11e3aSSheldon HearnReverse the order of the commands listed 224149e11e3aSSheldon Hearn(with 224249e11e3aSSheldon Hearn.Fl l ) 224349e11e3aSSheldon Hearnor edited 224449e11e3aSSheldon Hearn(with neither 224549e11e3aSSheldon Hearn.Fl l 224649e11e3aSSheldon Hearnnor 224749e11e3aSSheldon Hearn.Fl s ) . 224849e11e3aSSheldon Hearn.It Fl s 22494b88c807SRodney W. GrimesRe-execute the command without invoking an editor. 225049e11e3aSSheldon Hearn.It Ar first 225149e11e3aSSheldon Hearn.It Ar last 225249e11e3aSSheldon HearnSelect the commands to list or edit. 225349e11e3aSSheldon HearnThe number of previous commands that can be accessed 225449e11e3aSSheldon Hearnare determined by the value of the 22551788b7ffSJilles Tjoelker.Va HISTSIZE 2256d0353b83SRuslan Ermilovvariable. 225749e11e3aSSheldon HearnThe value of 225849e11e3aSSheldon Hearn.Ar first 225949e11e3aSSheldon Hearnor 226049e11e3aSSheldon Hearn.Ar last 226149e11e3aSSheldon Hearnor both are one of the following: 226281e9cda2SRuslan Ermilov.Bl -tag -width indent 2263dfe302abSRuslan Ermilov.It Oo Cm + Oc Ns Ar num 226449e11e3aSSheldon HearnA positive number representing a command number; 226549e11e3aSSheldon Hearncommand numbers can be displayed with the 226649e11e3aSSheldon Hearn.Fl l 226749e11e3aSSheldon Hearnoption. 2268dfe302abSRuslan Ermilov.It Fl Ar num 226949e11e3aSSheldon HearnA negative decimal number representing the 227049e11e3aSSheldon Hearncommand that was executed 227149e11e3aSSheldon Hearn.Ar num 227249e11e3aSSheldon Hearnof 227349e11e3aSSheldon Hearncommands previously. 2274dfe302abSRuslan ErmilovFor example, \-1 is the immediately previous command. 227549e11e3aSSheldon Hearn.It Ar string 227649e11e3aSSheldon HearnA string indicating the most recently entered command 227749e11e3aSSheldon Hearnthat begins with that string. 227849e11e3aSSheldon HearnIf the 2279dfe302abSRuslan Ermilov.Ar old Ns = Ns Ar new 228049e11e3aSSheldon Hearnoperand is not also specified with 228149e11e3aSSheldon Hearn.Fl s , 228249e11e3aSSheldon Hearnthe string form of the first operand cannot contain an embedded equal sign. 228349e11e3aSSheldon Hearn.El 228449e11e3aSSheldon Hearn.El 228549e11e3aSSheldon Hearn.Pp 22861788b7ffSJilles TjoelkerThe following variables affect the execution of 228749e11e3aSSheldon Hearn.Ic fc : 22881788b7ffSJilles Tjoelker.Bl -tag -width ".Va HISTSIZE" 22891788b7ffSJilles Tjoelker.It Va FCEDIT 229038afdcbcSGiorgos KeramidasName of the editor to use for history editing. 22911788b7ffSJilles Tjoelker.It Va HISTSIZE 22923d7b5b93SPhilippe CharnierThe number of previous commands that are accessible. 2293ab72124fSSteve Price.El 229449e11e3aSSheldon Hearn.It Ic fg Op Ar job 229549e11e3aSSheldon HearnMove the specified 229649e11e3aSSheldon Hearn.Ar job 229749e11e3aSSheldon Hearnor the current job to the foreground. 2298dfe302abSRuslan Ermilov.It Ic getopts Ar optstring var 2299dfe302abSRuslan ErmilovThe 2300dfe302abSRuslan Ermilov.Tn POSIX 230149e11e3aSSheldon Hearn.Ic getopts 230249e11e3aSSheldon Hearncommand. 230349e11e3aSSheldon HearnThe 230449e11e3aSSheldon Hearn.Ic getopts 230549e11e3aSSheldon Hearncommand deprecates the older 230649e11e3aSSheldon Hearn.Xr getopt 1 230749e11e3aSSheldon Hearncommand. 2308ab0a2172SSteve PriceThe first argument should be a series of letters, each possibly 2309ab0a2172SSteve Pricefollowed by a colon which indicates that the option takes an argument. 2310eccea571SRuslan ErmilovThe specified variable is set to the parsed option. 2311eccea571SRuslan ErmilovThe index of 231249e11e3aSSheldon Hearnthe next argument is placed into the shell variable 2313dfe302abSRuslan Ermilov.Va OPTIND . 2314ab0a2172SSteve PriceIf an option takes an argument, it is placed into the shell variable 2315dfe302abSRuslan Ermilov.Va OPTARG . 231649e11e3aSSheldon HearnIf an invalid option is encountered, 2317dfe302abSRuslan Ermilov.Ar var 231849e11e3aSSheldon Hearnis set to 2319dfe302abSRuslan Ermilov.Ql \&? . 2320ab0a2172SSteve PriceIt returns a false value (1) when it encounters the end of the options. 23214445af21SJilles TjoelkerA new set of arguments may be parsed by assigning 23224445af21SJilles Tjoelker.Li OPTIND=1 . 232381e9cda2SRuslan Ermilov.It Ic hash Oo Fl rv Oc Op Ar command ... 232449e11e3aSSheldon HearnThe shell maintains a hash table which remembers the locations of commands. 232549e11e3aSSheldon HearnWith no arguments whatsoever, the 232649e11e3aSSheldon Hearn.Ic hash 232749e11e3aSSheldon Hearncommand prints out the contents of this table. 2328ab72124fSSteve Price.Pp 232949e11e3aSSheldon HearnWith arguments, the 233049e11e3aSSheldon Hearn.Ic hash 233149e11e3aSSheldon Hearncommand removes each specified 233249e11e3aSSheldon Hearn.Ar command 233349e11e3aSSheldon Hearnfrom the hash table (unless they are functions) and then locates it. 233449e11e3aSSheldon HearnWith the 233549e11e3aSSheldon Hearn.Fl v 233649e11e3aSSheldon Hearnoption, 233749e11e3aSSheldon Hearn.Ic hash 233849e11e3aSSheldon Hearnprints the locations of the commands as it finds them. 233949e11e3aSSheldon HearnThe 234049e11e3aSSheldon Hearn.Fl r 234149e11e3aSSheldon Hearnoption causes the 234249e11e3aSSheldon Hearn.Ic hash 234349e11e3aSSheldon Hearncommand to delete all the entries in the hash table except for functions. 234449e11e3aSSheldon Hearn.It Ic jobid Op Ar job 2345dfe302abSRuslan ErmilovPrint the process IDs of the processes in the specified 234649e11e3aSSheldon Hearn.Ar job . 234749e11e3aSSheldon HearnIf the 234849e11e3aSSheldon Hearn.Ar job 234949e11e3aSSheldon Hearnargument is omitted, use the current job. 2350de37e41cSStefan Farfeleder.It Ic jobs Oo Fl lps Oc Op Ar job ... 2351ad8a0759STim J. RobbinsPrint information about the specified jobs, or all jobs if no 2352ad8a0759STim J. Robbins.Ar job 2353ad8a0759STim J. Robbinsargument is given. 2354ad8a0759STim J. RobbinsThe information printed includes job ID, status and command name. 2355ad8a0759STim J. Robbins.Pp 2356ad8a0759STim J. RobbinsIf the 2357ad8a0759STim J. Robbins.Fl l 2358ad8a0759STim J. Robbinsoption is specified, the PID of each job is also printed. 2359ad8a0759STim J. RobbinsIf the 2360de37e41cSStefan Farfeleder.Fl p 2361de37e41cSStefan Farfelederoption is specified, only the process IDs for the process group leaders 2362de37e41cSStefan Farfelederare printed, one per line. 2363de37e41cSStefan FarfelederIf the 2364ad8a0759STim J. Robbins.Fl s 2365de37e41cSStefan Farfelederoption is specified, only the PIDs of the job commands are printed, one per 2366de37e41cSStefan Farfelederline. 23670a62a9caSJilles Tjoelker.It Ic kill 23680a62a9caSJilles TjoelkerA built-in equivalent of 23690a62a9caSJilles Tjoelker.Xr kill 1 23700a62a9caSJilles Tjoelkerthat additionally supports sending signals to jobs. 23718af11131SRuslan Ermilov.It Ic local Oo Ar variable ... Oc Op Fl 2372d2f90294SJesus R. CamouSee the 2373d2f90294SJesus R. Camou.Sx Functions 2374d2f90294SJesus R. Camousubsection. 23759897c45fSJilles Tjoelker.It Ic printf 23769897c45fSJilles TjoelkerA built-in equivalent of 23779897c45fSJilles Tjoelker.Xr printf 1 . 2378d74e011fSRuslan Ermilov.It Ic pwd Op Fl L | P 2379eccea571SRuslan ErmilovPrint the path of the current directory. 2380eccea571SRuslan ErmilovThe built-in command may 23814b88c807SRodney W. Grimesdiffer from the program of the same name because the 23828eed22b1SJens Schweikhardtbuilt-in command remembers what the current directory 2383eccea571SRuslan Ermilovis rather than recomputing it each time. 2384eccea571SRuslan ErmilovThis makes 2385eccea571SRuslan Ermilovit faster. 2386eccea571SRuslan ErmilovHowever, if the current directory is 238749e11e3aSSheldon Hearnrenamed, 23888eed22b1SJens Schweikhardtthe built-in version of 238949e11e3aSSheldon Hearn.Xr pwd 1 239049e11e3aSSheldon Hearnwill continue to print the old name for the directory. 2391178897f1STim J. Robbins.Pp 2392178897f1STim J. RobbinsIf the 2393178897f1STim J. Robbins.Fl P 2394178897f1STim J. Robbinsoption is specified, symbolic links are resolved. 2395178897f1STim J. RobbinsIf the 2396178897f1STim J. Robbins.Fl L 2397178897f1STim J. Robbinsoption is specified, the shell's notion of the current directory 2398178897f1STim J. Robbinsis printed (symbolic links are not resolved). 2399178897f1STim J. RobbinsThis is the default. 2400dfe302abSRuslan Ermilov.It Ic read Oo Fl p Ar prompt Oc Oo 2401dfe302abSRuslan Ermilov.Fl t Ar timeout Oc Oo Fl er Oc Ar variable ... 240249e11e3aSSheldon HearnThe 240349e11e3aSSheldon Hearn.Ar prompt 240449e11e3aSSheldon Hearnis printed if the 240549e11e3aSSheldon Hearn.Fl p 240649e11e3aSSheldon Hearnoption is specified 2407eccea571SRuslan Ermilovand the standard input is a terminal. 2408eccea571SRuslan ErmilovThen a line is 2409eccea571SRuslan Ermilovread from the standard input. 2410eccea571SRuslan ErmilovThe trailing newline 24114b88c807SRodney W. Grimesis deleted from the line and the line is split as 241249e11e3aSSheldon Hearndescribed in the section on 241349e11e3aSSheldon Hearn.Sx White Space Splitting (Field Splitting) 241449e11e3aSSheldon Hearnabove, and 24154b88c807SRodney W. Grimesthe pieces are assigned to the variables in order. 2416f434d1dfSAdam DavidIf there are more pieces than variables, the remaining 241749e11e3aSSheldon Hearnpieces (along with the characters in 2418dfe302abSRuslan Ermilov.Va IFS 241949e11e3aSSheldon Hearnthat separated them) 242049e11e3aSSheldon Hearnare assigned to the last variable. 2421f434d1dfSAdam DavidIf there are more variables than pieces, the remaining 2422f434d1dfSAdam Davidvariables are assigned the null string. 2423ab72124fSSteve Price.Pp 242449e11e3aSSheldon HearnBackslashes are treated specially, unless the 242549e11e3aSSheldon Hearn.Fl r 242649e11e3aSSheldon Hearnoption is 2427eccea571SRuslan Ermilovspecified. 2428eccea571SRuslan ErmilovIf a backslash is followed by 24298f0561ccSThomas Gellekuma newline, the backslash and the newline will be 2430eccea571SRuslan Ermilovdeleted. 2431eccea571SRuslan ErmilovIf a backslash is followed by any other 24328f0561ccSThomas Gellekumcharacter, the backslash will be deleted and the following 243349e11e3aSSheldon Hearncharacter will be treated as though it were not in 2434dfe302abSRuslan Ermilov.Va IFS , 243549e11e3aSSheldon Hearneven if it is. 24368f0561ccSThomas Gellekum.Pp 243749e11e3aSSheldon HearnIf the 243849e11e3aSSheldon Hearn.Fl t 243949e11e3aSSheldon Hearnoption is specified and the 244049e11e3aSSheldon Hearn.Ar timeout 2441fe40d6d3SJilles Tjoelkerelapses before a complete line of input is supplied, 244249e11e3aSSheldon Hearnthe 244349e11e3aSSheldon Hearn.Ic read 2444c4539460SJilles Tjoelkercommand will return an exit status as if terminated by 2445c4539460SJilles Tjoelker.Dv SIGALRM 2446c4539460SJilles Tjoelkerwithout assigning any values. 244749e11e3aSSheldon HearnThe 244849e11e3aSSheldon Hearn.Ar timeout 244949e11e3aSSheldon Hearnvalue may optionally be followed by one of 2450dfe302abSRuslan Ermilov.Ql s , 2451dfe302abSRuslan Ermilov.Ql m 245249e11e3aSSheldon Hearnor 2453dfe302abSRuslan Ermilov.Ql h 2454a910f192SDima Dorfmanto explicitly specify seconds, minutes or hours. 245549e11e3aSSheldon HearnIf none is supplied, 2456dfe302abSRuslan Ermilov.Ql s 245749e11e3aSSheldon Hearnis assumed. 2458afa53c8dSMike Smith.Pp 245949e11e3aSSheldon HearnThe 246049e11e3aSSheldon Hearn.Fl e 246149e11e3aSSheldon Hearnoption exists only for backward compatibility with older scripts. 2462c4539460SJilles Tjoelker.Pp 2463c4539460SJilles TjoelkerThe exit status is 0 on success, 1 on end of file, 2464c4539460SJilles Tjoelkerbetween 2 and 128 if an error occurs 2465c4539460SJilles Tjoelkerand greater than 128 if a trapped signal interrupts 2466c4539460SJilles Tjoelker.Ic read . 24679ba31ca0SRuslan Ermilov.It Ic readonly Oo Fl p Oc Op Ar name ... 246849e11e3aSSheldon HearnEach specified 246949e11e3aSSheldon Hearn.Ar name 247049e11e3aSSheldon Hearnis marked as read only, 247149e11e3aSSheldon Hearnso that it cannot be subsequently modified or unset. 247249e11e3aSSheldon HearnThe shell allows the value of a variable to be set 247349e11e3aSSheldon Hearnat the same time as it is marked read only 247449e11e3aSSheldon Hearnby using the following form: 2475dfe302abSRuslan Ermilov.Pp 2476dfe302abSRuslan Ermilov.D1 Ic readonly Ar name Ns = Ns Ar value 2477ab72124fSSteve Price.Pp 247849e11e3aSSheldon HearnWith no arguments the 247949e11e3aSSheldon Hearn.Ic readonly 248049e11e3aSSheldon Hearncommand lists the names of all read only variables. 248145086f8cSTim J. RobbinsIf the 248245086f8cSTim J. Robbins.Fl p 248345086f8cSTim J. Robbinsoption is specified, the read-only variables are printed as 248445086f8cSTim J. Robbins.Dq Ic readonly Ar name Ns = Ns Ar value 248545086f8cSTim J. Robbinslines, suitable for re-input to the shell. 2486d2f90294SJesus R. Camou.It Ic return Op Ar exitstatus 2487d2f90294SJesus R. CamouSee the 2488d2f90294SJesus R. Camou.Sx Functions 2489d2f90294SJesus R. Camousubsection. 249081e9cda2SRuslan Ermilov.It Ic set Oo Fl /+abCEefIimnpTuVvx Oc Oo Fl /+o Ar longname Oc Oo 249181e9cda2SRuslan Ermilov.Fl c Ar string Oc Op Fl - Ar arg ... 2492e918fc8fSSheldon HearnThe 2493e918fc8fSSheldon Hearn.Ic set 2494e918fc8fSSheldon Hearncommand performs three different functions: 2495ab72124fSSteve Price.Bl -item 2496ab72124fSSteve Price.It 249749e11e3aSSheldon HearnWith no arguments, it lists the values of all shell variables. 2498ab72124fSSteve Price.It 249949e11e3aSSheldon HearnIf options are given, 250049e11e3aSSheldon Hearneither in short form or using the long 250149e11e3aSSheldon Hearn.Dq Fl /+o Ar longname 250249e11e3aSSheldon Hearnform, 250349e11e3aSSheldon Hearnit sets or clears the specified options as described in the section called 25046b15476eSSheldon Hearn.Sx Argument List Processing . 2505ab72124fSSteve Price.It 250649e11e3aSSheldon HearnIf the 250749e11e3aSSheldon Hearn.Dq Fl - 250849e11e3aSSheldon Hearnoption is specified, 250949e11e3aSSheldon Hearn.Ic set 251049e11e3aSSheldon Hearnwill replace the shell's positional parameters with the subsequent 251149e11e3aSSheldon Hearnarguments. 251249e11e3aSSheldon HearnIf no arguments follow the 251349e11e3aSSheldon Hearn.Dq Fl - 251449e11e3aSSheldon Hearnoption, 251549e11e3aSSheldon Hearnall the positional parameters will be cleared, 251649e11e3aSSheldon Hearnwhich is equivalent to executing the command 2517dfe302abSRuslan Ermilov.Dq Li "shift $#" . 251849e11e3aSSheldon HearnThe 251949e11e3aSSheldon Hearn.Dq Fl - 25208eed22b1SJens Schweikhardtflag may be omitted when specifying arguments to be used 252149e11e3aSSheldon Hearnas positional replacement parameters. 252249e11e3aSSheldon HearnThis is not recommended, 252349e11e3aSSheldon Hearnbecause the first argument may begin with a dash 2524a762afe5SGiorgos Keramidas.Pq Ql - 252549e11e3aSSheldon Hearnor a plus 2526a762afe5SGiorgos Keramidas.Pq Ql + , 252749e11e3aSSheldon Hearnwhich the 252849e11e3aSSheldon Hearn.Ic set 252949e11e3aSSheldon Hearncommand will interpret as a request to enable or disable options. 2530ab72124fSSteve Price.El 2531dfe302abSRuslan Ermilov.It Ic setvar Ar variable value 253249e11e3aSSheldon HearnAssigns the specified 253349e11e3aSSheldon Hearn.Ar value 253449e11e3aSSheldon Hearnto the specified 253549e11e3aSSheldon Hearn.Ar variable . 2536dfe302abSRuslan ErmilovThe 2537dfe302abSRuslan Ermilov.Ic setvar 2538dfe302abSRuslan Ermilovcommand is intended to be used in functions that 2539e6d3cf26SSheldon Hearnassign values to variables whose names are passed as parameters. 254049e11e3aSSheldon HearnIn general it is better to write 2541dfe302abSRuslan Ermilov.Dq Ar variable Ns = Ns Ar value 254249e11e3aSSheldon Hearnrather than using 254349e11e3aSSheldon Hearn.Ic setvar . 254449e11e3aSSheldon Hearn.It Ic shift Op Ar n 254549e11e3aSSheldon HearnShift the positional parameters 254649e11e3aSSheldon Hearn.Ar n 2547e918fc8fSSheldon Hearntimes, or once if 254849e11e3aSSheldon Hearn.Ar n 254949e11e3aSSheldon Hearnis not specified. 2550dfe302abSRuslan ErmilovA shift sets the value of 2551dfe302abSRuslan Ermilov.Li $1 2552dfe302abSRuslan Ermilovto the value of 2553dfe302abSRuslan Ermilov.Li $2 , 2554dfe302abSRuslan Ermilovthe value of 2555dfe302abSRuslan Ermilov.Li $2 2556dfe302abSRuslan Ermilovto the value of 2557dfe302abSRuslan Ermilov.Li $3 , 2558dfe302abSRuslan Ermilovand so on, 2559dfe302abSRuslan Ermilovdecreasing the value of 2560dfe302abSRuslan Ermilov.Li $# 2561dfe302abSRuslan Ermilovby one. 2562945e1562SJilles TjoelkerFor portability, shifting if there are zero positional parameters 2563945e1562SJilles Tjoelkershould be avoided, since the shell may abort. 256410845922SYaroslav Tykhiy.It Ic test 256510845922SYaroslav TykhiyA built-in equivalent of 256610845922SYaroslav Tykhiy.Xr test 1 . 25671974986aSStefan Farfeleder.It Ic times 256851a514adSJilles TjoelkerPrint the amount of time spent executing the shell process and its children. 256951a514adSJilles TjoelkerThe first output line shows the user and system times for the shell process 25701974986aSStefan Farfelederitself, the second one contains the user and system times for the 25711974986aSStefan Farfelederchildren. 257281e9cda2SRuslan Ermilov.It Ic trap Oo Ar action Oc Ar signal ... 25730673e800SStefan Farfeleder.It Ic trap Fl l 257449e11e3aSSheldon HearnCause the shell to parse and execute 257549e11e3aSSheldon Hearn.Ar action 257649e11e3aSSheldon Hearnwhen any specified 257749e11e3aSSheldon Hearn.Ar signal 257849e11e3aSSheldon Hearnis received. 2579162ae3aeSTony FinchThe signals are specified by name or number. 2580162ae3aeSTony FinchIn addition, the pseudo-signal 2581f5d1157fSRuslan Ermilov.Cm EXIT 2582dfe302abSRuslan Ermilovmay be used to specify an 2583dfe302abSRuslan Ermilov.Ar action 2584dfe302abSRuslan Ermilovthat is performed when the shell terminates. 258549e11e3aSSheldon HearnThe 258649e11e3aSSheldon Hearn.Ar action 25870673e800SStefan Farfeledermay be an empty string or a dash 25889badf57fSRuslan Ermilov.Pq Ql - ; 258949e11e3aSSheldon Hearnthe former causes the specified signal to be ignored 259049e11e3aSSheldon Hearnand the latter causes the default action to be taken. 25910673e800SStefan FarfelederOmitting the 25920673e800SStefan Farfeleder.Ar action 2593a59f8174SBryan Dreweryand using only signal numbers is another way to request the default action. 259451a514adSJilles TjoelkerIn a subshell or utility environment, 2595ef89d04fSJilles Tjoelkerthe shell resets trapped (but not ignored) signals to the default action. 259649e11e3aSSheldon HearnThe 259749e11e3aSSheldon Hearn.Ic trap 259849e11e3aSSheldon Hearncommand has no effect on signals that were ignored on entry to the shell. 25990673e800SStefan Farfeleder.Pp 26000673e800SStefan FarfelederOption 26010673e800SStefan Farfeleder.Fl l 26020673e800SStefan Farfeledercauses the 26030673e800SStefan Farfeleder.Ic trap 26040673e800SStefan Farfeledercommand to display a list of valid signal names. 2605a6557dcbSYaroslav Tykhiy.It Ic true 2606a6557dcbSYaroslav TykhiyA null command that returns a 0 (true) exit value. 260749e11e3aSSheldon Hearn.It Ic type Op Ar name ... 260849e11e3aSSheldon HearnInterpret each 260949e11e3aSSheldon Hearn.Ar name 261049e11e3aSSheldon Hearnas a command and print the resolution of the command search. 2611e6d3cf26SSheldon HearnPossible resolutions are: 261230268dfaSJilles Tjoelkershell keyword, alias, special shell builtin, shell builtin, command, 261330268dfaSJilles Tjoelkertracked alias 261449e11e3aSSheldon Hearnand not found. 261549e11e3aSSheldon HearnFor aliases the alias expansion is printed; 261649e11e3aSSheldon Hearnfor commands and tracked aliases 261749e11e3aSSheldon Hearnthe complete pathname of the command is printed. 2618*250d9fd8SKonstantin Belousov.It Ic ulimit Oo Fl HSabcdfklmnopstuvw Oc Op Ar limit 2619ab72124fSSteve PriceSet or display resource limits (see 2620ab72124fSSteve Price.Xr getrlimit 2 ) . 26216b15476eSSheldon HearnIf 262249e11e3aSSheldon Hearn.Ar limit 26236b15476eSSheldon Hearnis specified, the named resource will be set; 26247a2afe64SJoerg Wunschotherwise the current resource value will be displayed. 2625ab72124fSSteve Price.Pp 26266b15476eSSheldon HearnIf 262749e11e3aSSheldon Hearn.Fl H 262849e11e3aSSheldon Hearnis specified, the hard limits will be set or displayed. 262949e11e3aSSheldon HearnWhile everybody is allowed to reduce a hard limit, 263049e11e3aSSheldon Hearnonly the superuser can increase it. 263149e11e3aSSheldon HearnThe 263249e11e3aSSheldon Hearn.Fl S 263349e11e3aSSheldon Hearnoption 2634eccea571SRuslan Ermilovspecifies the soft limits instead. 2635eccea571SRuslan ErmilovWhen displaying limits, 26366b15476eSSheldon Hearnonly one of 263749e11e3aSSheldon Hearn.Fl S 26386b15476eSSheldon Hearnor 263949e11e3aSSheldon Hearn.Fl H 264049e11e3aSSheldon Hearncan be given. 264149e11e3aSSheldon HearnThe default is to display the soft limits, 264249e11e3aSSheldon Hearnand to set both the hard and the soft limits. 2643ab72124fSSteve Price.Pp 26446b15476eSSheldon HearnOption 264549e11e3aSSheldon Hearn.Fl a 264649e11e3aSSheldon Hearncauses the 264749e11e3aSSheldon Hearn.Ic ulimit 264849e11e3aSSheldon Hearncommand to display all resources. 264949e11e3aSSheldon HearnThe parameter 265049e11e3aSSheldon Hearn.Ar limit 26516b15476eSSheldon Hearnis not acceptable in this mode. 2652ab72124fSSteve Price.Pp 26537a2afe64SJoerg WunschThe remaining options specify which resource value is to be 265449e11e3aSSheldon Hearndisplayed or modified. 265549e11e3aSSheldon HearnThey are mutually exclusive. 265681e9cda2SRuslan Ermilov.Bl -tag -width indent 26573652a236SMartin Cracauer.It Fl b Ar sbsize 26583652a236SMartin CracauerThe maximum size of socket buffer usage, in bytes. 265949e11e3aSSheldon Hearn.It Fl c Ar coredumpsize 26607a2afe64SJoerg WunschThe maximal size of core dump files, in 512-byte blocks. 266149e11e3aSSheldon Hearn.It Fl d Ar datasize 26627a2afe64SJoerg WunschThe maximal size of the data segment of a process, in kilobytes. 266349e11e3aSSheldon Hearn.It Fl f Ar filesize 266449e11e3aSSheldon HearnThe maximal size of a file, in 512-byte blocks. 2665d2c068eaSJilles Tjoelker.It Fl k Ar kqueues 2666d2c068eaSJilles TjoelkerThe maximal number of kqueues 2667d2c068eaSJilles Tjoelker(see 2668d2c068eaSJilles Tjoelker.Xr kqueue 2 ) 2669d2c068eaSJilles Tjoelkerfor this user ID. 267049e11e3aSSheldon Hearn.It Fl l Ar lockedmem 26717a2afe64SJoerg WunschThe maximal size of memory that can be locked by a process, in 26727a2afe64SJoerg Wunschkilobytes. 267349e11e3aSSheldon Hearn.It Fl m Ar memoryuse 26747a2afe64SJoerg WunschThe maximal resident set size of a process, in kilobytes. 267549e11e3aSSheldon Hearn.It Fl n Ar nofiles 26767a2afe64SJoerg WunschThe maximal number of descriptors that could be opened by a process. 2677*250d9fd8SKonstantin Belousov.It Fl o Ar umtxp 2678*250d9fd8SKonstantin BelousovThe maximal number of process-shared locks 2679*250d9fd8SKonstantin Belousov(see 2680*250d9fd8SKonstantin Belousov.Xr pthread 3 ) 2681*250d9fd8SKonstantin Belousovfor this user ID. 2682331773cdSEd Schouten.It Fl p Ar pseudoterminals 2683331773cdSEd SchoutenThe maximal number of pseudo-terminals for this user ID. 268449e11e3aSSheldon Hearn.It Fl s Ar stacksize 26857a2afe64SJoerg WunschThe maximal size of the stack segment, in kilobytes. 268649e11e3aSSheldon Hearn.It Fl t Ar time 26877a2afe64SJoerg WunschThe maximal amount of CPU time to be used by each process, in seconds. 268849e11e3aSSheldon Hearn.It Fl u Ar userproc 2689ab72124fSSteve PriceThe maximal number of simultaneous processes for this user ID. 269062df9b62SSheldon Hearn.It Fl v Ar virtualmem 26912d41ef4bSMatthew DillonThe maximal virtual size of a process, in kilobytes. 2692c8054a61SJilles Tjoelker.It Fl w Ar swapuse 2693c8054a61SJilles TjoelkerThe maximum amount of swap space reserved or used for this user ID, 2694c8054a61SJilles Tjoelkerin kilobytes. 2695ab72124fSSteve Price.El 2696faa1ed35SStefan Farfeleder.It Ic umask Oo Fl S Oc Op Ar mask 269749e11e3aSSheldon HearnSet the file creation mask (see 2698ab72124fSSteve Price.Xr umask 2 ) 2699faa1ed35SStefan Farfelederto the octal or symbolic (see 2700faa1ed35SStefan Farfeleder.Xr chmod 1 ) 2701faa1ed35SStefan Farfeledervalue specified by 27025d3b843bSSheldon Hearn.Ar mask . 270349e11e3aSSheldon HearnIf the argument is omitted, the current mask value is printed. 2704faa1ed35SStefan FarfelederIf the 2705faa1ed35SStefan Farfeleder.Fl S 2706faa1ed35SStefan Farfelederoption is specified, the output is symbolic, otherwise the output is octal. 2707de4ad382SStefan Farfeleder.It Ic unalias Oo Fl a Oc Op Ar name ... 2708de4ad382SStefan FarfelederThe specified alias names are removed. 27096b15476eSSheldon HearnIf 27101b9735e6SSheldon Hearn.Fl a 27116b15476eSSheldon Hearnis specified, all aliases are removed. 27129ba31ca0SRuslan Ermilov.It Ic unset Oo Fl fv Oc Ar name ... 27138b34ad92STim J. RobbinsThe specified variables or functions are unset and unexported. 27148b34ad92STim J. RobbinsIf the 27158b34ad92STim J. Robbins.Fl v 27168b34ad92STim J. Robbinsoption is specified or no options are given, the 271749e11e3aSSheldon Hearn.Ar name 27188b34ad92STim J. Robbinsarguments are treated as variable names. 27198b34ad92STim J. RobbinsIf the 27208b34ad92STim J. Robbins.Fl f 27218b34ad92STim J. Robbinsoption is specified, the 27228b34ad92STim J. Robbins.Ar name 27238b34ad92STim J. Robbinsarguments are treated as function names. 2724bd76c6b8SJilles Tjoelker.It Ic wait Op Ar job ... 2725bd76c6b8SJilles TjoelkerWait for each specified 272649e11e3aSSheldon Hearn.Ar job 272749e11e3aSSheldon Hearnto complete and return the exit status of the last process in the 2728bd76c6b8SJilles Tjoelkerlast specified 272949e11e3aSSheldon Hearn.Ar job . 2730bd76c6b8SJilles TjoelkerIf any 2731bd76c6b8SJilles Tjoelker.Ar job 2732bd76c6b8SJilles Tjoelkerspecified is unknown to the shell, it is treated as if it 2733bd76c6b8SJilles Tjoelkerwere a known job that exited with exit status 127. 2734bd76c6b8SJilles TjoelkerIf no operands are given, wait for all jobs to complete 2735e6d3cf26SSheldon Hearnand return an exit status of zero. 2736ab72124fSSteve Price.El 2737ab72124fSSteve Price.Ss Commandline Editing 2738ab72124fSSteve PriceWhen 2739ab72124fSSteve Price.Nm 2740ab72124fSSteve Priceis being used interactively from a terminal, the current command 274149e11e3aSSheldon Hearnand the command history 274249e11e3aSSheldon Hearn(see 274349e11e3aSSheldon Hearn.Ic fc 274449e11e3aSSheldon Hearnin 27458eed22b1SJens Schweikhardt.Sx Built-in Commands ) 2746dfe302abSRuslan Ermilovcan be edited using 2747dfe302abSRuslan Ermilov.Nm vi Ns -mode 2748dfe302abSRuslan Ermilovcommand line editing. 274949e11e3aSSheldon HearnThis mode uses commands similar 2750dfe302abSRuslan Ermilovto a subset of those described in the 2751dfe302abSRuslan Ermilov.Xr vi 1 2752dfe302abSRuslan Ermilovman page. 275349e11e3aSSheldon HearnThe command 2754dfe302abSRuslan Ermilov.Dq Li "set -o vi" 275549e11e3aSSheldon Hearn(or 2756dfe302abSRuslan Ermilov.Dq Li "set -V" ) 2757dfe302abSRuslan Ermilovenables 2758dfe302abSRuslan Ermilov.Nm vi Ns -mode 2759dfe302abSRuslan Ermilovediting and places 2760ab72124fSSteve Price.Nm 2761dfe302abSRuslan Ermilovinto 2762dfe302abSRuslan Ermilov.Nm vi 2763dfe302abSRuslan Ermilovinsert mode. 2764dfe302abSRuslan ErmilovWith 2765dfe302abSRuslan Ermilov.Nm vi Ns -mode 2766dfe302abSRuslan Ermilovenabled, 2767ab72124fSSteve Price.Nm 276849e11e3aSSheldon Hearncan be switched between insert mode and command mode by typing 276949e11e3aSSheldon Hearn.Aq ESC . 277049e11e3aSSheldon HearnHitting 277149e11e3aSSheldon Hearn.Aq return 277249e11e3aSSheldon Hearnwhile in command mode will pass the line to the shell. 2773ab72124fSSteve Price.Pp 277449e11e3aSSheldon HearnSimilarly, the 2775dfe302abSRuslan Ermilov.Dq Li "set -o emacs" 277649e11e3aSSheldon Hearn(or 2777dfe302abSRuslan Ermilov.Dq Li "set -E" ) 277849e11e3aSSheldon Hearncommand can be used to enable a subset of 2779dfe302abSRuslan Ermilov.Nm emacs Ns -style 2780dfe302abSRuslan Ermilovcommand line editing features. 278138afdcbcSGiorgos Keramidas.Sh ENVIRONMENT 278238afdcbcSGiorgos KeramidasThe following environment variables affect the execution of 278338afdcbcSGiorgos Keramidas.Nm : 27841788b7ffSJilles Tjoelker.Bl -tag -width ".Ev LANGXXXXXX" 27851788b7ffSJilles Tjoelker.It Ev ENV 27861788b7ffSJilles TjoelkerInitialization file for interactive shells. 27871788b7ffSJilles Tjoelker.It Ev LANG , Ev LC_* 27881788b7ffSJilles TjoelkerLocale settings. 27891788b7ffSJilles TjoelkerThese are inherited by children of the shell, 27901788b7ffSJilles Tjoelkerand is used in a limited manner by the shell itself. 27917b6779b6SJilles Tjoelker.It Ev OLDPWD 27927b6779b6SJilles TjoelkerThe previous current directory. 27937b6779b6SJilles TjoelkerThis is used and updated by 27947b6779b6SJilles Tjoelker.Ic cd . 27951788b7ffSJilles Tjoelker.It Ev PWD 27961788b7ffSJilles TjoelkerAn absolute pathname for the current directory, 27971788b7ffSJilles Tjoelkerpossibly containing symbolic links. 27981788b7ffSJilles TjoelkerThis is used and updated by the shell. 279938afdcbcSGiorgos Keramidas.It Ev TERM 280038afdcbcSGiorgos KeramidasThe default terminal setting for the shell. 280138afdcbcSGiorgos KeramidasThis is inherited by children of the shell, and is used in the history 280238afdcbcSGiorgos Keramidasediting modes. 280338afdcbcSGiorgos Keramidas.El 28041788b7ffSJilles Tjoelker.Pp 28054445af21SJilles TjoelkerAdditionally, environment variables are turned into shell variables 28061788b7ffSJilles Tjoelkerat startup, 28071788b7ffSJilles Tjoelkerwhich may affect the shell as described under 28081788b7ffSJilles Tjoelker.Sx Special Variables . 2809cb5a6a58SJoel Dahl.Sh FILES 2810cb5a6a58SJoel Dahl.Bl -tag -width "/etc/suid_profileXX" -compact 2811cb5a6a58SJoel Dahl.It Pa ~/.profile 2812cb5a6a58SJoel DahlUser's login profile. 2813cb5a6a58SJoel Dahl.It Pa /etc/profile 2814cb5a6a58SJoel DahlSystem login profile. 2815cb5a6a58SJoel Dahl.It Pa /etc/shells 2816cb5a6a58SJoel DahlShell database. 2817cb5a6a58SJoel Dahl.It Pa /etc/suid_profile 2818cb5a6a58SJoel DahlPrivileged shell profile. 2819cb5a6a58SJoel Dahl.El 2820fb039b55SRuslan Ermilov.Sh EXIT STATUS 2821fb039b55SRuslan ErmilovErrors that are detected by the shell, such as a syntax error, will 2822fb039b55SRuslan Ermilovcause the shell to exit with a non-zero exit status. 2823fb039b55SRuslan ErmilovIf the shell is not an interactive shell, the execution of the shell 2824fb039b55SRuslan Ermilovfile will be aborted. 2825fb039b55SRuslan ErmilovOtherwise the shell will return the exit status of the last command 2826dfe302abSRuslan Ermilovexecuted, or if the 2827dfe302abSRuslan Ermilov.Ic exit 2828dfe302abSRuslan Ermilovbuiltin is used with a numeric argument, it 2829fb039b55SRuslan Ermilovwill return the argument. 2830c83e7c50SJoseph Koshy.Sh SEE ALSO 2831c644db6aSSheldon Hearn.Xr builtin 1 , 283238afdcbcSGiorgos Keramidas.Xr chsh 1 , 2833c644db6aSSheldon Hearn.Xr echo 1 , 283438afdcbcSGiorgos Keramidas.Xr ed 1 , 283538afdcbcSGiorgos Keramidas.Xr emacs 1 , 28360a62a9caSJilles Tjoelker.Xr kill 1 , 28379897c45fSJilles Tjoelker.Xr printf 1 , 28385521ff5aSRuslan Ermilov.Xr pwd 1 , 283938afdcbcSGiorgos Keramidas.Xr test 1 , 284038afdcbcSGiorgos Keramidas.Xr vi 1 , 284138afdcbcSGiorgos Keramidas.Xr execve 2 , 284238afdcbcSGiorgos Keramidas.Xr getrlimit 2 , 2843fd50df30SRuslan Ermilov.Xr umask 2 , 2844ff4dc672SJilles Tjoelker.Xr wctype 3 , 2845cb5a6a58SJoel Dahl.Xr editrc 5 , 2846cb5a6a58SJoel Dahl.Xr shells 5 2847ab72124fSSteve Price.Sh HISTORY 2848b8923d4cSWolfram SchneiderA 2849ab72124fSSteve Price.Nm 28509cdd1e3fSYaroslav Tykhiycommand, the Thompson shell, appeared in 2851fc482908STim J. Robbins.At v1 . 28529cdd1e3fSYaroslav TykhiyIt was superseded in 28539cdd1e3fSYaroslav Tykhiy.At v7 28549cdd1e3fSYaroslav Tykhiyby the Bourne shell, which inherited the name 28559cdd1e3fSYaroslav Tykhiy.Nm . 28569cdd1e3fSYaroslav Tykhiy.Pp 28579cdd1e3fSYaroslav TykhiyThis version of 28589cdd1e3fSYaroslav Tykhiy.Nm 28599cdd1e3fSYaroslav Tykhiywas rewritten in 1989 under the 28609cdd1e3fSYaroslav Tykhiy.Bx 28619cdd1e3fSYaroslav Tykhiylicense after the Bourne shell from 28629cdd1e3fSYaroslav Tykhiy.At V.4 . 28639cdd1e3fSYaroslav Tykhiy.Sh AUTHORS 28649cdd1e3fSYaroslav TykhiyThis version of 28659cdd1e3fSYaroslav Tykhiy.Nm 28669badf57fSRuslan Ermilovwas originally written by 28679badf57fSRuslan Ermilov.An Kenneth Almquist . 2868128dc4a2STim J. Robbins.Sh BUGS 2869128dc4a2STim J. RobbinsThe 2870128dc4a2STim J. Robbins.Nm 287150df3424SJilles Tjoelkerutility does not recognize multibyte characters other than UTF-8. 287250df3424SJilles TjoelkerSplitting using 287350df3424SJilles Tjoelker.Va IFS 28748956c4ecSJilles Tjoelkerdoes not recognize multibyte characters. 2875