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. 16fbbd9655SWarner Losh.\" 3. Neither the name of the University nor the names of its contributors 174b88c807SRodney W. Grimes.\" may be used to endorse or promote products derived from this software 184b88c807SRodney W. Grimes.\" without specific prior written permission. 194b88c807SRodney W. Grimes.\" 204b88c807SRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 214b88c807SRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 224b88c807SRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 234b88c807SRodney W. Grimes.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 244b88c807SRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 254b88c807SRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 264b88c807SRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 274b88c807SRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 284b88c807SRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 294b88c807SRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 304b88c807SRodney W. Grimes.\" SUCH DAMAGE. 314b88c807SRodney W. Grimes.\" 32ab72124fSSteve Price.\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95 332a456239SPeter Wemm.\" $FreeBSD$ 344b88c807SRodney W. Grimes.\" 35*77da4a95SJilles Tjoelker.Dd November 27, 2018 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 7217e98da8SMateusz Piotrowskidesignated by POSIX, 733fdfd0a4SJilles Tjoelkerplus a few Berkeley extensions. 7449e11e3aSSheldon HearnThis man page is not intended to be a tutorial nor a complete 754b88c807SRodney W. Grimesspecification of the shell. 76ab72124fSSteve Price.Ss Overview 774b88c807SRodney W. GrimesThe shell is a command that reads lines from 784b88c807SRodney W. Grimeseither a file or the terminal, interprets them, and 79e6d3cf26SSheldon Hearngenerally executes other commands. 8049e11e3aSSheldon HearnIt is the program that is started when a user logs into the system, 8149e11e3aSSheldon Hearnalthough a user can select a different shell with the 82c644db6aSSheldon Hearn.Xr chsh 1 8349e11e3aSSheldon Hearncommand. 844b88c807SRodney W. GrimesThe shell 854b88c807SRodney W. Grimesimplements a language that has flow control constructs, 864b88c807SRodney W. Grimesa macro facility that provides a variety of features in 878eed22b1SJens Schweikhardtaddition to data storage, along with built-in history and line 88eccea571SRuslan Ermilovediting capabilities. 89eccea571SRuslan ErmilovIt incorporates many features to 904b88c807SRodney W. Grimesaid interactive use and has the advantage that the interpretative 914b88c807SRodney W. Grimeslanguage is common to both interactive and non-interactive 92eccea571SRuslan Ermilovuse (shell scripts). 93eccea571SRuslan ErmilovThat is, commands can be typed directly 9449e11e3aSSheldon Hearnto the running shell or can be put into a file, 9549e11e3aSSheldon Hearnwhich can be executed directly by the shell. 96ab72124fSSteve Price.Ss Invocation 9749e11e3aSSheldon Hearn.\" 9849e11e3aSSheldon Hearn.\" XXX This next sentence is incredibly confusing. 9949e11e3aSSheldon Hearn.\" 10049e11e3aSSheldon HearnIf no arguments are present and if the standard input of the shell 10149e11e3aSSheldon Hearnis connected to a terminal 10249e11e3aSSheldon Hearn(or if the 10349e11e3aSSheldon Hearn.Fl i 10449e11e3aSSheldon Hearnoption is set), 105eccea571SRuslan Ermilovthe shell is considered an interactive shell. 106eccea571SRuslan ErmilovAn interactive shell 1074b88c807SRodney W. Grimesgenerally prompts before each command and handles programming 1084b88c807SRodney W. Grimesand command errors differently (as described below). 1094b88c807SRodney W. GrimesWhen first starting, the shell inspects argument 0, and 11049e11e3aSSheldon Hearnif it begins with a dash 111a762afe5SGiorgos Keramidas.Pq Ql - , 11249e11e3aSSheldon Hearnthe shell is also considered a login shell. 11349e11e3aSSheldon HearnThis is normally done automatically by the system 114eccea571SRuslan Ermilovwhen the user first logs in. 115eccea571SRuslan ErmilovA login shell first reads commands 116ab72124fSSteve Pricefrom the files 117ab72124fSSteve Price.Pa /etc/profile 11849e11e3aSSheldon Hearnand then 119ab72124fSSteve Price.Pa .profile 120dfe302abSRuslan Ermilovin a user's home directory, 121eccea571SRuslan Ermilovif they exist. 122eccea571SRuslan ErmilovIf the environment variable 123ab72124fSSteve Price.Ev ENV 124ab72124fSSteve Priceis set on entry to a shell, or is set in the 125ab72124fSSteve Price.Pa .profile 1261a62d884SJilles Tjoelkerof a login shell, the shell then subjects its value to parameter expansion 1271a62d884SJilles Tjoelkerand arithmetic expansion and reads commands from the named file. 128ab72124fSSteve PriceTherefore, a user should place commands that are to be executed only 129ab72124fSSteve Priceat login time in the 130ab72124fSSteve Price.Pa .profile 131ab72124fSSteve Pricefile, and commands that are executed for every shell inside the 132ab72124fSSteve Price.Ev ENV 133e6d3cf26SSheldon Hearnfile. 13449e11e3aSSheldon HearnThe user can set the 135ab72124fSSteve Price.Ev ENV 13649e11e3aSSheldon Hearnvariable to some file by placing the following line in the file 137ab72124fSSteve Price.Pa .profile 13849e11e3aSSheldon Hearnin the home directory, 139ab72124fSSteve Pricesubstituting for 1405dd78c9fSJoel Dahl.Pa .shrc 14149e11e3aSSheldon Hearnthe filename desired: 14249e11e3aSSheldon Hearn.Pp 1435dd78c9fSJoel Dahl.Dl "ENV=$HOME/.shrc; export ENV" 14449e11e3aSSheldon Hearn.Pp 14549e11e3aSSheldon HearnThe first non-option argument specified on the command line 14649e11e3aSSheldon Hearnwill be treated as the 1474b88c807SRodney W. Grimesname of a file from which to read commands (a shell script), and 1484b88c807SRodney W. Grimesthe remaining arguments are set as the positional parameters 149dfe302abSRuslan Ermilovof the shell 150dfe302abSRuslan Ermilov.Li ( $1 , $2 , 151dfe302abSRuslan Ermilovetc.). 152eccea571SRuslan ErmilovOtherwise, the shell reads commands 1534b88c807SRodney W. Grimesfrom its standard input. 154ea76be72SSteve Price.Pp 155ea76be72SSteve PriceUnlike older versions of 156ea76be72SSteve Price.Nm 157ea76be72SSteve Pricethe 158ea76be72SSteve Price.Ev ENV 159eccea571SRuslan Ermilovscript is only sourced on invocation of interactive shells. 160eccea571SRuslan ErmilovThis 161ea76be72SSteve Pricecloses a well-known, and sometimes easily exploitable security 162ea76be72SSteve Pricehole related to poorly thought out 163ea76be72SSteve Price.Ev ENV 164ea76be72SSteve Pricescripts. 165ab72124fSSteve Price.Ss Argument List Processing 166ab72124fSSteve PriceAll of the single letter options to 167ab72124fSSteve Price.Nm 16849e11e3aSSheldon Hearnhave a corresponding long name, 16949e11e3aSSheldon Hearnwith the exception of 17049e11e3aSSheldon Hearn.Fl c 17149e11e3aSSheldon Hearnand 17249e11e3aSSheldon Hearn.Fl /+o . 17349e11e3aSSheldon HearnThese long names are provided next to the single letter options 17449e11e3aSSheldon Hearnin the descriptions below. 17549e11e3aSSheldon HearnThe long name for an option may be specified as an argument to the 17649e11e3aSSheldon Hearn.Fl /+o 17749e11e3aSSheldon Hearnoption of 178facc6767SRuslan Ermilov.Nm . 17949e11e3aSSheldon HearnOnce the shell is running, 18049e11e3aSSheldon Hearnthe long name for an option may be specified as an argument to the 18149e11e3aSSheldon Hearn.Fl /+o 18249e11e3aSSheldon Hearnoption of the 183c644db6aSSheldon Hearn.Ic set 1848eed22b1SJens Schweikhardtbuilt-in command 18549e11e3aSSheldon Hearn(described later in the section called 1868eed22b1SJens Schweikhardt.Sx Built-in Commands ) . 18749e11e3aSSheldon HearnIntroducing an option with a dash 188a762afe5SGiorgos Keramidas.Pq Ql - 18949e11e3aSSheldon Hearnenables the option, 19049e11e3aSSheldon Hearnwhile using a plus 191a762afe5SGiorgos Keramidas.Pq Ql + 19249e11e3aSSheldon Hearndisables the option. 19349e11e3aSSheldon HearnA 19449e11e3aSSheldon Hearn.Dq Li -- 195fab26805SJoseph Koshyor plain 196dfe302abSRuslan Ermilov.Ql - 197fab26805SJoseph Koshywill stop option processing and will force the remaining 198fab26805SJoseph Koshywords on the command line to be treated as arguments. 19949e11e3aSSheldon HearnThe 20049e11e3aSSheldon Hearn.Fl /+o 20149e11e3aSSheldon Hearnand 20249e11e3aSSheldon Hearn.Fl c 20349e11e3aSSheldon Hearnoptions do not have long names. 20449e11e3aSSheldon HearnThey take arguments and are described after the single letter options. 20581e9cda2SRuslan Ermilov.Bl -tag -width indent 206ab72124fSSteve Price.It Fl a Li allexport 20749e11e3aSSheldon HearnFlag variables for export when assignments are made to them. 208ab72124fSSteve Price.It Fl b Li notify 209ab72124fSSteve PriceEnable asynchronous notification of background job 210ab72124fSSteve Pricecompletion. 211c4d9468eSRuslan Ermilov(UNIMPLEMENTED) 212ab72124fSSteve Price.It Fl C Li noclobber 213c644db6aSSheldon HearnDo not overwrite existing files with 214dfe302abSRuslan Ermilov.Ql > . 215ab72124fSSteve Price.It Fl E Li emacs 2168eed22b1SJens SchweikhardtEnable the built-in 217ab72124fSSteve Price.Xr emacs 1 21849e11e3aSSheldon Hearncommand line editor (disables the 219ab72124fSSteve Price.Fl V 220d5f6b530SJilles Tjoelkeroption if it has been set; 221d5f6b530SJilles Tjoelkerset automatically when interactive on terminals). 222ab72124fSSteve Price.It Fl e Li errexit 22349e11e3aSSheldon HearnExit immediately if any untested command fails in non-interactive mode. 2244b88c807SRodney W. GrimesThe exit status of a command is considered to be 22574053659SStefan Farfelederexplicitly tested if the command is part of the list used to control 2268af11131SRuslan Ermilovan 2278af11131SRuslan Ermilov.Ic if , elif , while , 2288af11131SRuslan Ermilovor 2298af11131SRuslan Ermilov.Ic until ; 2308af11131SRuslan Ermilovif the command is the left 231ab72124fSSteve Pricehand operand of an 23249e11e3aSSheldon Hearn.Dq Li && 233ab72124fSSteve Priceor 23449e11e3aSSheldon Hearn.Dq Li || 23574053659SStefan Farfelederoperator; or if the command is a pipeline preceded by the 23674053659SStefan Farfeleder.Ic !\& 237b14cfdf6SJilles Tjoelkerkeyword. 23874053659SStefan FarfelederIf a shell function is executed and its exit status is explicitly 23974053659SStefan Farfeledertested, all commands of the function are considered to be tested as 24074053659SStefan Farfelederwell. 241b14cfdf6SJilles Tjoelker.Pp 242b14cfdf6SJilles TjoelkerIt is recommended to check for failures explicitly 243b14cfdf6SJilles Tjoelkerinstead of relying on 244b14cfdf6SJilles Tjoelker.Fl e 245b14cfdf6SJilles Tjoelkerbecause it tends to behave in unexpected ways, 246b14cfdf6SJilles Tjoelkerparticularly in larger scripts. 247ab72124fSSteve Price.It Fl f Li noglob 2484b88c807SRodney W. GrimesDisable pathname expansion. 24954b16435SJilles Tjoelker.It Fl h Li trackall 25017e98da8SMateusz PiotrowskiA do-nothing option for POSIX compliance. 251ab72124fSSteve Price.It Fl I Li ignoreeof 25249e11e3aSSheldon HearnIgnore 253dfe302abSRuslan Ermilov.Dv EOF Ap s 25449e11e3aSSheldon Hearnfrom input when in interactive mode. 255ab72124fSSteve Price.It Fl i Li interactive 256ab72124fSSteve PriceForce the shell to behave interactively. 257ab72124fSSteve Price.It Fl m Li monitor 258ab72124fSSteve PriceTurn on job control (set automatically when interactive). 259cd60e2c6SJilles TjoelkerA new process group is created for each pipeline (called a job). 260cd60e2c6SJilles TjoelkerIt is possible to suspend jobs or to have them run in the foreground or 261cd60e2c6SJilles Tjoelkerin the background. 262cd60e2c6SJilles TjoelkerIn a non-interactive shell, 263cd60e2c6SJilles Tjoelkerthis option can be set even if no terminal is available 264cd60e2c6SJilles Tjoelkerand is useful to place processes in separate process groups. 265ab72124fSSteve Price.It Fl n Li noexec 2664b88c807SRodney W. GrimesIf not interactive, read commands but do not 267eccea571SRuslan Ermilovexecute them. 268eccea571SRuslan ErmilovThis is useful for checking the 2694b88c807SRodney W. Grimessyntax of shell scripts. 2707e1975c2STim J. Robbins.It Fl P Li physical 2717e1975c2STim J. RobbinsChange the default for the 2727e1975c2STim J. Robbins.Ic cd 2737e1975c2STim J. Robbinsand 2747e1975c2STim J. Robbins.Ic pwd 2757e1975c2STim J. Robbinscommands from 2767e1975c2STim J. Robbins.Fl L 2777e1975c2STim J. Robbins(logical directory layout) 2787e1975c2STim J. Robbinsto 2797e1975c2STim J. Robbins.Fl P 2807e1975c2STim J. Robbins(physical directory layout). 281ab72124fSSteve Price.It Fl p Li privileged 282eccea571SRuslan ErmilovTurn on privileged mode. 283eccea571SRuslan ErmilovThis mode is enabled on startup 284dfe302abSRuslan Ermilovif either the effective user or group ID is not equal to the 285dfe302abSRuslan Ermilovreal user or group ID. 286eccea571SRuslan ErmilovTurning this mode off sets the 287dfe302abSRuslan Ermiloveffective user and group IDs to the real user and group IDs. 28849e11e3aSSheldon HearnWhen this mode is enabled for interactive shells, the file 289ab72124fSSteve Price.Pa /etc/suid_profile 29049e11e3aSSheldon Hearnis sourced instead of 29149e11e3aSSheldon Hearn.Pa ~/.profile 292ab72124fSSteve Priceafter 293ab72124fSSteve Price.Pa /etc/profile 29449e11e3aSSheldon Hearnis sourced, and the contents of the 295ab72124fSSteve Price.Ev ENV 29649e11e3aSSheldon Hearnvariable are ignored. 297ab72124fSSteve Price.It Fl s Li stdin 2984b88c807SRodney W. GrimesRead commands from standard input (set automatically 299eccea571SRuslan Ermilovif no file arguments are present). 300eccea571SRuslan ErmilovThis option has 3014b88c807SRodney W. Grimesno effect when set after the shell has already started 302eccea571SRuslan Ermilovrunning (i.e., when set with the 303c644db6aSSheldon Hearn.Ic set 3046b15476eSSheldon Hearncommand). 305304199ceSTom Rhodes.It Fl T Li trapsasync 306e6d3cf26SSheldon HearnWhen waiting for a child, execute traps immediately. 307e6d3cf26SSheldon HearnIf this option is not set, 308e6d3cf26SSheldon Hearntraps are executed after the child exits, 309e6d3cf26SSheldon Hearnas specified in 310af5eb6fcSMaxim Konovalov.St -p1003.2 . 3116b15476eSSheldon HearnThis nonstandard option is useful for putting guarding shells around 312eccea571SRuslan Ermilovchildren that block signals. 313eccea571SRuslan ErmilovThe surrounding shell may kill the child 3146b15476eSSheldon Hearnor it may just return control to the tty and leave the child alone, 3156b15476eSSheldon Hearnlike this: 316c1c72a3cSMartin Cracauer.Bd -literal -offset indent 317c1c72a3cSMartin Cracauersh -T -c "trap 'exit 1' 2 ; some-blocking-program" 318c1c72a3cSMartin Cracauer.Ed 319ab72124fSSteve Price.It Fl u Li nounset 320ab72124fSSteve PriceWrite a message to standard error when attempting 32164254a66SJilles Tjoelkerto expand a variable, a positional parameter or 32264254a66SJilles Tjoelkerthe special parameter 32364254a66SJilles Tjoelker.Va \&! 32464254a66SJilles Tjoelkerthat is not set, and if the 325ab72124fSSteve Priceshell is not interactive, exit immediately. 326ab72124fSSteve Price.It Fl V Li vi 3278eed22b1SJens SchweikhardtEnable the built-in 328ab72124fSSteve Price.Xr vi 1 329ab72124fSSteve Pricecommand line editor (disables 330ab72124fSSteve Price.Fl E 331ab72124fSSteve Priceif it has been set). 332ab72124fSSteve Price.It Fl v Li verbose 333ab72124fSSteve PriceThe shell writes its input to standard error 334eccea571SRuslan Ermilovas it is read. 335eccea571SRuslan ErmilovUseful for debugging. 336ab72124fSSteve Price.It Fl x Li xtrace 33749e11e3aSSheldon HearnWrite each command 338120c8e6cSStefan Farfeleder(preceded by the value of the 339dfe302abSRuslan Ermilov.Va PS4 340292e6676SJilles Tjoelkervariable subjected to parameter expansion and arithmetic expansion) 34149e11e3aSSheldon Hearnto standard error before it is executed. 34249e11e3aSSheldon HearnUseful for debugging. 3436986f58fSJilles Tjoelker.It Li nolog 34417e98da8SMateusz PiotrowskiAnother do-nothing option for POSIX compliance. 34562c37116SJilles TjoelkerIt only has a long name. 34649e11e3aSSheldon Hearn.El 34749e11e3aSSheldon Hearn.Pp 34849e11e3aSSheldon HearnThe 349fd50df30SRuslan Ermilov.Fl c 350fd50df30SRuslan Ermilovoption causes the commands to be read from the 351fd50df30SRuslan Ermilov.Ar string 352fd50df30SRuslan Ermilovoperand instead of from the standard input. 353fd50df30SRuslan ErmilovKeep in mind that this option only accepts a single string as its 354fd50df30SRuslan Ermilovargument, hence multi-word strings must be quoted. 355fd50df30SRuslan Ermilov.Pp 356fd50df30SRuslan ErmilovThe 35749e11e3aSSheldon Hearn.Fl /+o 35849e11e3aSSheldon Hearnoption takes as its only argument the long name of an option 35949e11e3aSSheldon Hearnto be enabled or disabled. 36049e11e3aSSheldon HearnFor example, the following two invocations of 36149e11e3aSSheldon Hearn.Nm 3628eed22b1SJens Schweikhardtboth enable the built-in 36349e11e3aSSheldon Hearn.Xr emacs 1 36449e11e3aSSheldon Hearncommand line editor: 36549e11e3aSSheldon Hearn.Bd -literal -offset indent 36649e11e3aSSheldon Hearnset -E 36749e11e3aSSheldon Hearnset -o emacs 36849e11e3aSSheldon Hearn.Ed 369d513af6aSTim J. Robbins.Pp 370d513af6aSTim J. RobbinsIf used without an argument, the 371d513af6aSTim J. Robbins.Fl o 372d513af6aSTim J. Robbinsoption displays the current option settings in a human-readable format. 373d513af6aSTim J. RobbinsIf 374d513af6aSTim J. Robbins.Cm +o 375d513af6aSTim J. Robbinsis used without an argument, the current option settings are output 376d513af6aSTim J. Robbinsin a format suitable for re-input into the shell. 377ab72124fSSteve Price.Ss Lexical Structure 3784b88c807SRodney W. GrimesThe shell reads input in terms of lines from a file and breaks 3794b88c807SRodney W. Grimesit up into words at whitespace (blanks and tabs), and at 3804b88c807SRodney W. Grimescertain sequences of 3816b15476eSSheldon Hearncharacters called 3826b15476eSSheldon Hearn.Dq operators , 3836b15476eSSheldon Hearnwhich are special to the shell. 3844b88c807SRodney W. GrimesThere are two types of operators: control operators and 3854b88c807SRodney W. Grimesredirection operators (their meaning is discussed later). 386ab72124fSSteve PriceThe following is a list of valid operators: 38781e9cda2SRuslan Ermilov.Bl -tag -width indent 38849e11e3aSSheldon Hearn.It Control operators: 38949e11e3aSSheldon Hearn.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 39035471bf8SJoel Dahl.It Li & Ta Li && Ta Li \&( Ta Li \&) Ta Li \en 39135471bf8SJoel Dahl.It Li ;; Ta Li ;& Ta Li \&; Ta Li \&| Ta Li || 39249e11e3aSSheldon Hearn.El 39349e11e3aSSheldon Hearn.It Redirection operators: 3944682f420SBrian Somers.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 39581e9cda2SRuslan Ermilov.It Li < Ta Li > Ta Li << Ta Li >> Ta Li <> 396748611c9SJoel Dahl.It Li <& Ta Li >& Ta Li <<- Ta Li >| Ta \& 39749e11e3aSSheldon Hearn.El 398ab72124fSSteve Price.El 3997d1a55fcSStefan Farfeleder.Pp 4007d1a55fcSStefan FarfelederThe character 4017d1a55fcSStefan Farfeleder.Ql # 4027d1a55fcSStefan Farfelederintroduces a comment if used at the beginning of a word. 4037d1a55fcSStefan FarfelederThe word starting with 4047d1a55fcSStefan Farfeleder.Ql # 4057d1a55fcSStefan Farfelederand the rest of the line are ignored. 4069764aa41SJilles Tjoelker.Pp 40717e98da8SMateusz PiotrowskiASCII 4089764aa41SJilles Tjoelker.Dv NUL 4099764aa41SJilles Tjoelkercharacters (character code 0) are not allowed in shell input. 410ab72124fSSteve Price.Ss Quoting 4114b88c807SRodney W. GrimesQuoting is used to remove the special meaning of certain characters 412a886288eSJesus R. Camouor words to the shell, such as operators, whitespace, keywords, 413a886288eSJesus R. Camouor alias names. 414a886288eSJesus R. Camou.Pp 415a62ab027SJilles TjoelkerThere are four types of quoting: matched single quotes, 416a62ab027SJilles Tjoelkerdollar-single quotes, 4174b88c807SRodney W. Grimesmatched double quotes, and backslash. 41881e9cda2SRuslan Ermilov.Bl -tag -width indent 419ab72124fSSteve Price.It Single Quotes 4204b88c807SRodney W. GrimesEnclosing characters in single quotes preserves the literal 421ab0a2172SSteve Pricemeaning of all the characters (except single quotes, making 422ab0a2172SSteve Priceit impossible to put single-quotes in a single-quoted string). 423a62ab027SJilles Tjoelker.It Dollar-Single Quotes 424a62ab027SJilles TjoelkerEnclosing characters between 425a62ab027SJilles Tjoelker.Li $' 426a62ab027SJilles Tjoelkerand 427a62ab027SJilles Tjoelker.Li ' 428a62ab027SJilles Tjoelkerpreserves the literal meaning of all characters 429a62ab027SJilles Tjoelkerexcept backslashes and single quotes. 430a62ab027SJilles TjoelkerA backslash introduces a C-style escape sequence: 431a62ab027SJilles Tjoelker.Bl -tag -width xUnnnnnnnn 432a62ab027SJilles Tjoelker.It \ea 433a62ab027SJilles TjoelkerAlert (ring the terminal bell) 434a62ab027SJilles Tjoelker.It \eb 435a62ab027SJilles TjoelkerBackspace 436a62ab027SJilles Tjoelker.It \ec Ns Ar c 437a62ab027SJilles TjoelkerThe control character denoted by 438a62ab027SJilles Tjoelker.Li ^ Ns Ar c 439a62ab027SJilles Tjoelkerin 440a62ab027SJilles Tjoelker.Xr stty 1 . 441a62ab027SJilles TjoelkerIf 442a62ab027SJilles Tjoelker.Ar c 443a62ab027SJilles Tjoelkeris a backslash, it must be doubled. 444a62ab027SJilles Tjoelker.It \ee 44517e98da8SMateusz PiotrowskiThe ESC character (ASCII 0x1b) 446a62ab027SJilles Tjoelker.It \ef 447a62ab027SJilles TjoelkerFormfeed 448a62ab027SJilles Tjoelker.It \en 449a62ab027SJilles TjoelkerNewline 450a62ab027SJilles Tjoelker.It \er 451a62ab027SJilles TjoelkerCarriage return 452a62ab027SJilles Tjoelker.It \et 453a62ab027SJilles TjoelkerHorizontal tab 454a62ab027SJilles Tjoelker.It \ev 455a62ab027SJilles TjoelkerVertical tab 456a62ab027SJilles Tjoelker.It \e\e 457a62ab027SJilles TjoelkerLiteral backslash 458a62ab027SJilles Tjoelker.It \e\&' 459a62ab027SJilles TjoelkerLiteral single-quote 460a62ab027SJilles Tjoelker.It \e\&" 461a62ab027SJilles TjoelkerLiteral double-quote 462a62ab027SJilles Tjoelker.It \e Ns Ar nnn 463a62ab027SJilles TjoelkerThe byte whose octal value is 464a62ab027SJilles Tjoelker.Ar nnn 465a62ab027SJilles Tjoelker(one to three digits) 466a62ab027SJilles Tjoelker.It \ex Ns Ar nn 467a62ab027SJilles TjoelkerThe byte whose hexadecimal value is 468a62ab027SJilles Tjoelker.Ar nn 469a62ab027SJilles Tjoelker(one or more digits only the last two of which are used) 470a62ab027SJilles Tjoelker.It \eu Ns Ar nnnn 471a62ab027SJilles TjoelkerThe Unicode code point 472a62ab027SJilles Tjoelker.Ar nnnn 473a62ab027SJilles Tjoelker(four hexadecimal digits) 474a62ab027SJilles Tjoelker.It \eU Ns Ar nnnnnnnn 475a62ab027SJilles TjoelkerThe Unicode code point 476a62ab027SJilles Tjoelker.Ar nnnnnnnn 477a62ab027SJilles Tjoelker(eight hexadecimal digits) 478a62ab027SJilles Tjoelker.El 479a62ab027SJilles Tjoelker.Pp 48007eb7033SJilles TjoelkerThe sequences for Unicode code points are currently only useful with 48107eb7033SJilles TjoelkerUTF-8 locales. 482a62ab027SJilles TjoelkerThey reject code point 0 and UTF-16 surrogates. 483a62ab027SJilles Tjoelker.Pp 484a62ab027SJilles TjoelkerIf an escape sequence would produce a byte with value 0, 485a62ab027SJilles Tjoelkerthat byte and the rest of the string until the matching single-quote 486a62ab027SJilles Tjoelkerare ignored. 487a62ab027SJilles Tjoelker.Pp 488a62ab027SJilles TjoelkerAny other string starting with a backslash is an error. 489ab72124fSSteve Price.It Double Quotes 4904b88c807SRodney W. GrimesEnclosing characters within double quotes preserves the literal 49149e11e3aSSheldon Hearnmeaning of all characters except dollar sign 492a762afe5SGiorgos Keramidas.Pq Ql $ , 49349e11e3aSSheldon Hearnbackquote 494a762afe5SGiorgos Keramidas.Pq Ql ` , 49549e11e3aSSheldon Hearnand backslash 496a762afe5SGiorgos Keramidas.Pq Ql \e . 49749e11e3aSSheldon HearnThe backslash inside double quotes is historically weird. 49849e11e3aSSheldon HearnIt remains literal unless it precedes the following characters, 49949e11e3aSSheldon Hearnwhich it serves to quote: 500afc5a69aSJoel Dahl.Pp 50149e11e3aSSheldon Hearn.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 502afc5a69aSJoel Dahl.It Li $ Ta Li ` Ta Li \&" Ta Li \e Ta Li \en 50349e11e3aSSheldon Hearn.El 504ab72124fSSteve Price.It Backslash 505ab72124fSSteve PriceA backslash preserves the literal meaning of the following 50649e11e3aSSheldon Hearncharacter, with the exception of the newline character 507a762afe5SGiorgos Keramidas.Pq Ql \en . 50849e11e3aSSheldon HearnA backslash preceding a newline is treated as a line continuation. 509ab72124fSSteve Price.El 510d806a030SJilles Tjoelker.Ss Keywords 511d806a030SJilles TjoelkerKeywords or reserved words are words that have special meaning to the 5124b88c807SRodney W. Grimesshell and are recognized at the beginning of a line and 513eccea571SRuslan Ermilovafter a control operator. 514d806a030SJilles TjoelkerThe following are keywords: 51549e11e3aSSheldon Hearn.Bl -column "doneXX" "elifXX" "elseXX" "untilXX" "whileX" -offset center 51681e9cda2SRuslan Ermilov.It Li \&! Ta { Ta } Ta Ic case Ta Ic do 51781e9cda2SRuslan Ermilov.It Ic done Ta Ic elif Ta Ic else Ta Ic esac Ta Ic fi 51881e9cda2SRuslan Ermilov.It Ic for Ta Ic if Ta Ic then Ta Ic until Ta Ic while 51949e11e3aSSheldon Hearn.El 520ab72124fSSteve Price.Ss Aliases 521ab72124fSSteve PriceAn alias is a name and corresponding value set using the 522c644db6aSSheldon Hearn.Ic alias 523eccea571SRuslan Ermilovbuilt-in command. 52405a447d0SJilles TjoelkerWherever the command word of a simple command may occur, 52505a447d0SJilles Tjoelkerand after checking for keywords if a keyword may occur, the shell 526e6d3cf26SSheldon Hearnchecks the word to see if it matches an alias. 527e6d3cf26SSheldon HearnIf it does, it replaces it in the input stream with its value. 528e6d3cf26SSheldon HearnFor example, if there is an alias called 52949e11e3aSSheldon Hearn.Dq Li lf 5306b15476eSSheldon Hearnwith the value 531dfe302abSRuslan Ermilov.Dq Li "ls -F" , 5324b88c807SRodney W. Grimesthen the input 533dfe302abSRuslan Ermilov.Pp 534dfe302abSRuslan Ermilov.Dl "lf foobar" 535ab72124fSSteve Price.Pp 5364b88c807SRodney W. Grimeswould become 537dfe302abSRuslan Ermilov.Pp 538dfe302abSRuslan Ermilov.Dl "ls -F foobar" 539ab72124fSSteve Price.Pp 54048f49aacSJilles TjoelkerAliases are also recognized after an alias 54148f49aacSJilles Tjoelkerwhose value ends with a space or tab. 54248f49aacSJilles TjoelkerFor example, if there is also an alias called 54348f49aacSJilles Tjoelker.Dq Li nohup 54448f49aacSJilles Tjoelkerwith the value 54548f49aacSJilles Tjoelker.Dq Li "nohup " , 54648f49aacSJilles Tjoelkerthen the input 54748f49aacSJilles Tjoelker.Pp 54848f49aacSJilles Tjoelker.Dl "nohup lf foobar" 54948f49aacSJilles Tjoelker.Pp 55048f49aacSJilles Tjoelkerwould become 55148f49aacSJilles Tjoelker.Pp 55248f49aacSJilles Tjoelker.Dl "nohup ls -F foobar" 55348f49aacSJilles Tjoelker.Pp 5544b88c807SRodney W. GrimesAliases provide a convenient way for naive users to 5554b88c807SRodney W. Grimescreate shorthands for commands without having to learn how 556eccea571SRuslan Ermilovto create functions with arguments. 55712dfb7a5SJilles TjoelkerUsing aliases in scripts is discouraged 55812dfb7a5SJilles Tjoelkerbecause the command that defines them must be executed 55912dfb7a5SJilles Tjoelkerbefore the code that uses them is parsed. 56012dfb7a5SJilles TjoelkerThis is fragile and not portable. 561a886288eSJesus R. Camou.Pp 562a886288eSJesus R. CamouAn alias name may be escaped in a command line, so that it is not 563a886288eSJesus R. Camoureplaced by its alias value, by using quoting characters within or 56419162ab9SJesus R. Camouadjacent to the alias name. 56519162ab9SJesus R. CamouThis is most often done by prefixing 566a886288eSJesus R. Camouan alias name with a backslash to execute a function, built-in, or 567a886288eSJesus R. Camounormal program with the same name. 568a886288eSJesus R. CamouSee the 569a886288eSJesus R. Camou.Sx Quoting 570a886288eSJesus R. Camousubsection. 571ab72124fSSteve Price.Ss Commands 5724b88c807SRodney W. GrimesThe shell interprets the words it reads according to a 5734b88c807SRodney W. Grimeslanguage, the specification of which is outside the scope 574ab72124fSSteve Priceof this man page (refer to the BNF in the 575ab72124fSSteve Price.St -p1003.2 576eccea571SRuslan Ermilovdocument). 577eccea571SRuslan ErmilovEssentially though, a line is read and if 5784b88c807SRodney W. Grimesthe first word of the line (or after a control operator) 579d806a030SJilles Tjoelkeris not a keyword, then the shell has recognized a 580eccea571SRuslan Ermilovsimple command. 581eccea571SRuslan ErmilovOtherwise, a complex command or some 5824b88c807SRodney W. Grimesother special construct may have been recognized. 583ab72124fSSteve Price.Ss Simple Commands 5844b88c807SRodney W. GrimesIf a simple command has been recognized, the shell performs 5854b88c807SRodney W. Grimesthe following actions: 586ab72124fSSteve Price.Bl -enum 587ab72124fSSteve Price.It 5886b15476eSSheldon HearnLeading words of the form 58949e11e3aSSheldon Hearn.Dq Li name=value 5906b15476eSSheldon Hearnare stripped off and assigned to the environment of 591000dda7bSJilles Tjoelkerthe simple command 592000dda7bSJilles Tjoelker(they do not affect expansions). 593eccea571SRuslan ErmilovRedirection operators and 5944b88c807SRodney W. Grimestheir arguments (as described below) are stripped 5954b88c807SRodney W. Grimesoff and saved for processing. 596ab72124fSSteve Price.It 597ab72124fSSteve PriceThe remaining words are expanded as described in 5986b15476eSSheldon Hearnthe section called 5996b15476eSSheldon Hearn.Sx Word Expansions , 6006b15476eSSheldon Hearnand the first remaining word is considered the command 601eccea571SRuslan Ermilovname and the command is located. 602eccea571SRuslan ErmilovThe remaining 6034b88c807SRodney W. Grimeswords are considered the arguments of the command. 6046b15476eSSheldon HearnIf no command name resulted, then the 60549e11e3aSSheldon Hearn.Dq Li name=value 6064b88c807SRodney W. Grimesvariable assignments recognized in 1) affect the 6074b88c807SRodney W. Grimescurrent shell. 608ab72124fSSteve Price.It 609ab72124fSSteve PriceRedirections are performed as described in 6104b88c807SRodney W. Grimesthe next section. 611ab72124fSSteve Price.El 612ab72124fSSteve Price.Ss Redirections 6134b88c807SRodney W. GrimesRedirections are used to change where a command reads its input 614eccea571SRuslan Ermilovor sends its output. 615eccea571SRuslan ErmilovIn general, redirections open, close, or 616eccea571SRuslan Ermilovduplicate an existing reference to a file. 617eccea571SRuslan ErmilovThe overall format 6184b88c807SRodney W. Grimesused for redirection is: 61949e11e3aSSheldon Hearn.Pp 620dfe302abSRuslan Ermilov.D1 Oo Ar n Oc Ar redir-op file 62149e11e3aSSheldon Hearn.Pp 62249e11e3aSSheldon HearnThe 623dfe302abSRuslan Ermilov.Ar redir-op 62449e11e3aSSheldon Hearnis one of the redirection operators mentioned 625eccea571SRuslan Ermilovpreviously. 626eccea571SRuslan ErmilovThe following gives some examples of how these 62749e11e3aSSheldon Hearnoperators can be used. 62849e11e3aSSheldon HearnNote that stdin and stdout are commonly used abbreviations 62949e11e3aSSheldon Hearnfor standard input and standard output respectively. 63049e11e3aSSheldon Hearn.Bl -tag -width "1234567890XX" -offset indent 631dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li > Ar file 632dfe302abSRuslan Ermilovredirect stdout (or file descriptor 633dfe302abSRuslan Ermilov.Ar n ) 634dfe302abSRuslan Ermilovto 635dfe302abSRuslan Ermilov.Ar file 636dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li >| Ar file 63749e11e3aSSheldon Hearnsame as above, but override the 63849e11e3aSSheldon Hearn.Fl C 63949e11e3aSSheldon Hearnoption 640dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li >> Ar file 641dfe302abSRuslan Ermilovappend stdout (or file descriptor 642dfe302abSRuslan Ermilov.Ar n ) 643dfe302abSRuslan Ermilovto 644dfe302abSRuslan Ermilov.Ar file 645dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li < Ar file 646dfe302abSRuslan Ermilovredirect stdin (or file descriptor 647dfe302abSRuslan Ermilov.Ar n ) 648dfe302abSRuslan Ermilovfrom 649dfe302abSRuslan Ermilov.Ar file 650dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li <> Ar file 651dfe302abSRuslan Ermilovredirect stdin (or file descriptor 652dfe302abSRuslan Ermilov.Ar n ) 653dfe302abSRuslan Ermilovto and from 654dfe302abSRuslan Ermilov.Ar file 655dfe302abSRuslan Ermilov.It Oo Ar n1 Oc Ns Li <& Ns Ar n2 656dfe302abSRuslan Ermilovduplicate stdin (or file descriptor 657dfe302abSRuslan Ermilov.Ar n1 ) 658dfe302abSRuslan Ermilovfrom file descriptor 659dfe302abSRuslan Ermilov.Ar n2 660dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li <&- 661dfe302abSRuslan Ermilovclose stdin (or file descriptor 662dfe302abSRuslan Ermilov.Ar n ) 663dfe302abSRuslan Ermilov.It Oo Ar n1 Oc Ns Li >& Ns Ar n2 664dfe302abSRuslan Ermilovduplicate stdout (or file descriptor 665dfe302abSRuslan Ermilov.Ar n1 ) 666dfe302abSRuslan Ermilovto file descriptor 667dfe302abSRuslan Ermilov.Ar n2 668dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li >&- 669dfe302abSRuslan Ermilovclose stdout (or file descriptor 670dfe302abSRuslan Ermilov.Ar n ) 671ab72124fSSteve Price.El 672ab72124fSSteve Price.Pp 6736b15476eSSheldon HearnThe following redirection is often called a 6746b15476eSSheldon Hearn.Dq here-document . 675dfe302abSRuslan Ermilov.Bd -unfilled -offset indent 676dfe302abSRuslan Ermilov.Oo Ar n Oc Ns Li << Ar delimiter 677a2442c2fSJoel Dahl.Ar here-doc-text 678a2442c2fSJoel Dahl.Ar ... 679dfe302abSRuslan Ermilov.Ar delimiter 680ab72124fSSteve Price.Ed 681ab72124fSSteve Price.Pp 6824b88c807SRodney W. GrimesAll the text on successive lines up to the delimiter is 6834b88c807SRodney W. Grimessaved away and made available to the command on standard 684dfe302abSRuslan Ermilovinput, or file descriptor 685dfe302abSRuslan Ermilov.Ar n 686dfe302abSRuslan Ermilovif it is specified. 687dfe302abSRuslan ErmilovIf the 688dfe302abSRuslan Ermilov.Ar delimiter 689dfe302abSRuslan Ermilovas specified on the initial line is quoted, then the 690dfe302abSRuslan Ermilov.Ar here-doc-text 6914b88c807SRodney W. Grimesis treated literally, otherwise the text is subjected to 6924b88c807SRodney W. Grimesparameter expansion, command substitution, and arithmetic 6936b15476eSSheldon Hearnexpansion (as described in the section on 6946b15476eSSheldon Hearn.Sx Word Expansions ) . 6956b15476eSSheldon HearnIf the operator is 69649e11e3aSSheldon Hearn.Dq Li <<- 6976b15476eSSheldon Hearninstead of 69849e11e3aSSheldon Hearn.Dq Li << , 6996b15476eSSheldon Hearnthen leading tabs 700dfe302abSRuslan Ermilovin the 701dfe302abSRuslan Ermilov.Ar here-doc-text 702dfe302abSRuslan Ermilovare stripped. 703ab72124fSSteve Price.Ss Search and Execution 704ab0a2172SSteve PriceThere are three types of commands: shell functions, 7058eed22b1SJens Schweikhardtbuilt-in commands, and normal programs. 70649e11e3aSSheldon HearnThe command is searched for (by name) in that order. 70749e11e3aSSheldon HearnThe three types of commands are all executed in a different way. 708ab72124fSSteve Price.Pp 709ab0a2172SSteve PriceWhen a shell function is executed, all of the shell positional 710dfe302abSRuslan Ermilovparameters (except 711dfe302abSRuslan Ermilov.Li $0 , 712dfe302abSRuslan Ermilovwhich remains unchanged) are 7134b88c807SRodney W. Grimesset to the arguments of the shell function. 7144b88c807SRodney W. GrimesThe variables which are explicitly placed in the environment of 7154b88c807SRodney W. Grimesthe command (by placing assignments to them before the 7164b88c807SRodney W. Grimesfunction name) are made local to the function and are set 717e6d3cf26SSheldon Hearnto the values given. 718e6d3cf26SSheldon HearnThen the command given in the function definition is executed. 719e6d3cf26SSheldon HearnThe positional parameters are restored to their original values 720e6d3cf26SSheldon Hearnwhen the command completes. 721ab0a2172SSteve PriceThis all occurs within the current shell. 722ab72124fSSteve Price.Pp 7238eed22b1SJens SchweikhardtShell built-in commands are executed internally to the shell, without 724ab0a2172SSteve Pricespawning a new process. 72530268dfaSJilles TjoelkerThere are two kinds of built-in commands: regular and special. 72630268dfaSJilles TjoelkerAssignments before special builtins persist after they finish 72730268dfaSJilles Tjoelkerexecuting and assignment errors, redirection errors and certain 72830268dfaSJilles Tjoelkeroperand errors cause a script to be aborted. 7294b985a89SJilles TjoelkerSpecial builtins cannot be overridden with a function. 73030268dfaSJilles TjoelkerBoth regular and special builtins can affect the shell in ways 73130268dfaSJilles Tjoelkernormal programs cannot. 732ab72124fSSteve Price.Pp 733c644db6aSSheldon HearnOtherwise, if the command name does not match a function 7348eed22b1SJens Schweikhardtor built-in command, the command is searched for as a normal 7354b88c807SRodney W. Grimesprogram in the file system (as described in the next section). 7364b88c807SRodney W. GrimesWhen a normal program is executed, the shell runs the program, 737e6d3cf26SSheldon Hearnpassing the arguments and the environment to the program. 738e6d3cf26SSheldon HearnIf the program is not a normal executable file 739eccea571SRuslan Ermilov(i.e., if it does not begin with the 740dfe302abSRuslan Ermilov.Dq "magic number" 74117e98da8SMateusz Piotrowskiwhose ASCII representation is 742dfe302abSRuslan Ermilov.Dq Li #! , 74349e11e3aSSheldon Hearnresulting in an 744b4f0f4aaSRuslan Ermilov.Er ENOEXEC 74549e11e3aSSheldon Hearnreturn value from 74649e11e3aSSheldon Hearn.Xr execve 2 ) 747604e8224SJilles Tjoelkerbut appears to be a text file, 7483835f47cSJilles Tjoelkerthe shell will run a new instance of 7493835f47cSJilles Tjoelker.Nm 7503835f47cSJilles Tjoelkerto interpret it. 751ab72124fSSteve Price.Pp 752ab0a2172SSteve PriceNote that previous versions of this document 753ab0a2172SSteve Priceand the source code itself misleadingly and sporadically 754ab0a2172SSteve Pricerefer to a shell script without a magic number 7556b15476eSSheldon Hearnas a 756dfe302abSRuslan Ermilov.Dq "shell procedure" . 757ab72124fSSteve Price.Ss Path Search 7584b88c807SRodney W. GrimesWhen locating a command, the shell first looks to see if 759eccea571SRuslan Ermilovit has a shell function by that name. 760eccea571SRuslan ErmilovThen it looks for a 761eccea571SRuslan Ermilovbuilt-in command by that name. 762eccea571SRuslan ErmilovIf a built-in command is not found, 763ab0a2172SSteve Priceone of two things happen: 764ab72124fSSteve Price.Bl -enum 765ab72124fSSteve Price.It 766ab72124fSSteve PriceCommand names containing a slash are simply executed without 767ab0a2172SSteve Priceperforming any searches. 768ab72124fSSteve Price.It 769dfe302abSRuslan ErmilovThe shell searches each entry in the 7701788b7ffSJilles Tjoelker.Va PATH 7711788b7ffSJilles Tjoelkervariable 772eccea571SRuslan Ermilovin turn for the command. 773eccea571SRuslan ErmilovThe value of the 7741788b7ffSJilles Tjoelker.Va PATH 775ab72124fSSteve Pricevariable should be a series of 776eccea571SRuslan Ermiloventries separated by colons. 777eccea571SRuslan ErmilovEach entry consists of a 7784b88c807SRodney W. Grimesdirectory name. 7794b88c807SRodney W. GrimesThe current directory 780ab0a2172SSteve Pricemay be indicated implicitly by an empty directory name, 781ab0a2172SSteve Priceor explicitly by a single period. 782ab72124fSSteve Price.El 783ab72124fSSteve Price.Ss Command Exit Status 7844b88c807SRodney W. GrimesEach command has an exit status that can influence the behavior 785eccea571SRuslan Ermilovof other shell commands. 786eccea571SRuslan ErmilovThe paradigm is that a command exits 7874b88c807SRodney W. Grimeswith zero for normal or success, and non-zero for failure, 788eccea571SRuslan Ermiloverror, or a false indication. 789eccea571SRuslan ErmilovThe man page for each command 7904b88c807SRodney W. Grimesshould indicate the various exit codes and what they mean. 7918eed22b1SJens SchweikhardtAdditionally, the built-in commands return exit codes, as does 792ab0a2172SSteve Pricean executed shell function. 793c351e089SJohn Polstra.Pp 794b1f60592SJilles TjoelkerIf a command is terminated by a signal, its exit status is greater than 128. 795b1f60592SJilles TjoelkerThe signal name can be found by passing the exit status to 796b1f60592SJilles Tjoelker.Li kill -l . 797b1f60592SJilles Tjoelker.Pp 798b1f60592SJilles TjoelkerIf there is no command word, 799b1f60592SJilles Tjoelkerthe exit status is the exit status of the last command substitution executed, 800b1f60592SJilles Tjoelkeror zero if the command does not contain any command substitutions. 801ab72124fSSteve Price.Ss Complex Commands 8024b88c807SRodney W. GrimesComplex commands are combinations of simple commands 803d806a030SJilles Tjoelkerwith control operators or keywords, together creating a larger complex 804eccea571SRuslan Ermilovcommand. 805eccea571SRuslan ErmilovMore generally, a command is one of the following: 806ab72124fSSteve Price.Bl -item -offset indent 807ab72124fSSteve Price.It 808ab72124fSSteve Pricesimple command 809ab72124fSSteve Price.It 810ab72124fSSteve Pricepipeline 811ab72124fSSteve Price.It 812ab72124fSSteve Pricelist or compound-list 813ab72124fSSteve Price.It 814ab72124fSSteve Pricecompound command 815ab72124fSSteve Price.It 816ab72124fSSteve Pricefunction definition 817ab72124fSSteve Price.El 818ab72124fSSteve Price.Pp 8194b88c807SRodney W. GrimesUnless otherwise stated, the exit status of a command is 820b1f60592SJilles Tjoelkerthat of the last simple command executed by the command, 821b1f60592SJilles Tjoelkeror zero if no simple command was executed. 822ab72124fSSteve Price.Ss Pipelines 8234b88c807SRodney W. GrimesA pipeline is a sequence of one or more commands separated 824dfe302abSRuslan Ermilovby the control operator 825dfe302abSRuslan Ermilov.Ql \&| . 826eccea571SRuslan ErmilovThe standard output of all but 8274b88c807SRodney W. Grimesthe last command is connected to the standard input 828eccea571SRuslan Ermilovof the next command. 829eccea571SRuslan ErmilovThe standard output of the last 830ab0a2172SSteve Pricecommand is inherited from the shell, as usual. 831ab72124fSSteve Price.Pp 8324b88c807SRodney W. GrimesThe format for a pipeline is: 83349e11e3aSSheldon Hearn.Pp 834dfe302abSRuslan Ermilov.D1 Oo Li \&! Oc Ar command1 Op Li \&| Ar command2 ... 835ab72124fSSteve Price.Pp 836dfe302abSRuslan ErmilovThe standard output of 837dfe302abSRuslan Ermilov.Ar command1 838dfe302abSRuslan Ermilovis connected to the standard input of 839dfe302abSRuslan Ermilov.Ar command2 . 840eccea571SRuslan ErmilovThe standard input, standard output, or 8414b88c807SRodney W. Grimesboth of a command is considered to be assigned by the 8424b88c807SRodney W. Grimespipeline before any redirection specified by redirection 8434b88c807SRodney W. Grimesoperators that are part of the command. 844ab72124fSSteve Price.Pp 845f1ec0581SJilles TjoelkerNote that unlike some other shells, 846f1ec0581SJilles Tjoelker.Nm 847f1ec0581SJilles Tjoelkerexecutes each process in a pipeline with more than one command 848f1ec0581SJilles Tjoelkerin a subshell environment and as a child of the 849f1ec0581SJilles Tjoelker.Nm 850f1ec0581SJilles Tjoelkerprocess. 851f1ec0581SJilles Tjoelker.Pp 8524b88c807SRodney W. GrimesIf the pipeline is not in the background (discussed later), 8534b88c807SRodney W. Grimesthe shell waits for all commands to complete. 854ab72124fSSteve Price.Pp 855d806a030SJilles TjoelkerIf the keyword 856eccea571SRuslan Ermilov.Ic !\& 857eccea571SRuslan Ermilovdoes not precede the pipeline, the 8584b88c807SRodney W. Grimesexit status is the exit status of the last command specified 859eccea571SRuslan Ermilovin the pipeline. 860eccea571SRuslan ErmilovOtherwise, the exit status is the logical 861eccea571SRuslan ErmilovNOT of the exit status of the last command. 862eccea571SRuslan ErmilovThat is, if 8634b88c807SRodney W. Grimesthe last command returns zero, the exit status is 1; if 8644b88c807SRodney W. Grimesthe last command returns greater than zero, the exit status 8654b88c807SRodney W. Grimesis zero. 866ab72124fSSteve Price.Pp 8674b88c807SRodney W. GrimesBecause pipeline assignment of standard input or standard 8684b88c807SRodney W. Grimesoutput or both takes place before redirection, it can be 869eccea571SRuslan Ermilovmodified by redirection. 870eccea571SRuslan ErmilovFor example: 871ab72124fSSteve Price.Pp 872dfe302abSRuslan Ermilov.Dl "command1 2>&1 | command2" 873ab72124fSSteve Price.Pp 87449e11e3aSSheldon Hearnsends both the standard output and standard error of 875dfe302abSRuslan Ermilov.Ar command1 87649e11e3aSSheldon Hearnto the standard input of 877dfe302abSRuslan Ermilov.Ar command2 . 87849e11e3aSSheldon Hearn.Pp 87949e11e3aSSheldon HearnA 880dfe302abSRuslan Ermilov.Ql \&; 88149e11e3aSSheldon Hearnor newline terminator causes the preceding 882e918fc8fSSheldon HearnAND-OR-list 883e918fc8fSSheldon Hearn(described below in the section called 884e918fc8fSSheldon Hearn.Sx Short-Circuit List Operators ) 885e918fc8fSSheldon Hearnto be executed sequentially; 886e918fc8fSSheldon Hearnan 887dfe302abSRuslan Ermilov.Ql & 888e918fc8fSSheldon Hearncauses asynchronous execution of the preceding AND-OR-list. 88949e11e3aSSheldon Hearn.Ss Background Commands (&) 8904b88c807SRodney W. GrimesIf a command is terminated by the control operator ampersand 891a762afe5SGiorgos Keramidas.Pq Ql & , 89251a514adSJilles Tjoelkerthe shell executes the command in a subshell environment (see 89351a514adSJilles Tjoelker.Sx Grouping Commands Together 89451a514adSJilles Tjoelkerbelow) and asynchronously; 89549e11e3aSSheldon Hearnthe shell does not wait for the command to finish 89649e11e3aSSheldon Hearnbefore executing the next command. 897ab72124fSSteve Price.Pp 8984b88c807SRodney W. GrimesThe format for running a command in background is: 899dfe302abSRuslan Ermilov.Pp 900dfe302abSRuslan Ermilov.D1 Ar command1 Li & Op Ar command2 Li & Ar ... 901ab72124fSSteve Price.Pp 9024b88c807SRodney W. GrimesIf the shell is not interactive, the standard input of an 903dfe302abSRuslan Ermilovasynchronous command is set to 904dfe302abSRuslan Ermilov.Pa /dev/null . 905b1f60592SJilles Tjoelker.Pp 906b1f60592SJilles TjoelkerThe exit status is zero. 90749e11e3aSSheldon Hearn.Ss Lists (Generally Speaking) 9084b88c807SRodney W. GrimesA list is a sequence of zero or more commands separated by 9094b88c807SRodney W. Grimesnewlines, semicolons, or ampersands, 9104b88c807SRodney W. Grimesand optionally terminated by one of these three characters. 9114b88c807SRodney W. GrimesThe commands in a 9124b88c807SRodney W. Grimeslist are executed in the order they are written. 9134b88c807SRodney W. GrimesIf command is followed by an ampersand, the shell starts the 9148eed22b1SJens Schweikhardtcommand and immediately proceeds onto the next command; 9154b88c807SRodney W. Grimesotherwise it waits for the command to terminate before 9164b88c807SRodney W. Grimesproceeding to the next one. 917ab72124fSSteve Price.Ss Short-Circuit List Operators 91849e11e3aSSheldon Hearn.Dq Li && 9196b15476eSSheldon Hearnand 92049e11e3aSSheldon Hearn.Dq Li || 9216b15476eSSheldon Hearnare AND-OR list operators. 92249e11e3aSSheldon Hearn.Dq Li && 9236b15476eSSheldon Hearnexecutes the first command, and then executes the second command 9246b15476eSSheldon Hearnif the exit status of the first command is zero. 92549e11e3aSSheldon Hearn.Dq Li || 926120ac26dSMasafumi Max NAKANEis similar, but executes the second command if the exit 9276b15476eSSheldon Hearnstatus of the first command is nonzero. 92849e11e3aSSheldon Hearn.Dq Li && 9296b15476eSSheldon Hearnand 93049e11e3aSSheldon Hearn.Dq Li || 9314b88c807SRodney W. Grimesboth have the same priority. 93249e11e3aSSheldon Hearn.Ss Flow-Control Constructs (if, while, for, case) 93349e11e3aSSheldon HearnThe syntax of the 93449e11e3aSSheldon Hearn.Ic if 93549e11e3aSSheldon Hearncommand is: 936dfe302abSRuslan Ermilov.Bd -unfilled -offset indent -compact 937dfe302abSRuslan Ermilov.Ic if Ar list 938dfe302abSRuslan Ermilov.Ic then Ar list 939dfe302abSRuslan Ermilov.Oo Ic elif Ar list 940dfe302abSRuslan Ermilov.Ic then Ar list Oc Ar ... 941dfe302abSRuslan Ermilov.Op Ic else Ar list 942dfe302abSRuslan Ermilov.Ic fi 943dfe302abSRuslan Ermilov.Ed 944ab72124fSSteve Price.Pp 945b1f60592SJilles TjoelkerThe exit status is that of selected 946b1f60592SJilles Tjoelker.Ic then 947b1f60592SJilles Tjoelkeror 948b1f60592SJilles Tjoelker.Ic else 949b1f60592SJilles Tjoelkerlist, 950b1f60592SJilles Tjoelkeror zero if no list was selected. 951b1f60592SJilles Tjoelker.Pp 95249e11e3aSSheldon HearnThe syntax of the 95349e11e3aSSheldon Hearn.Ic while 95449e11e3aSSheldon Hearncommand is: 955dfe302abSRuslan Ermilov.Bd -unfilled -offset indent -compact 956dfe302abSRuslan Ermilov.Ic while Ar list 957dfe302abSRuslan Ermilov.Ic do Ar list 958dfe302abSRuslan Ermilov.Ic done 959dfe302abSRuslan Ermilov.Ed 960ab72124fSSteve Price.Pp 961ab0a2172SSteve PriceThe two lists are executed repeatedly while the exit status of the 96249e11e3aSSheldon Hearnfirst list is zero. 96349e11e3aSSheldon HearnThe 96449e11e3aSSheldon Hearn.Ic until 96549e11e3aSSheldon Hearncommand is similar, but has the word 96649e11e3aSSheldon Hearn.Ic until 96749e11e3aSSheldon Hearnin place of 96849e11e3aSSheldon Hearn.Ic while , 96949e11e3aSSheldon Hearnwhich causes it to 9704b88c807SRodney W. Grimesrepeat until the exit status of the first list is zero. 971ab72124fSSteve Price.Pp 972b1f60592SJilles TjoelkerThe exit status is that of the last execution of the second list, 973b1f60592SJilles Tjoelkeror zero if it was never executed. 974b1f60592SJilles Tjoelker.Pp 97549e11e3aSSheldon HearnThe syntax of the 97649e11e3aSSheldon Hearn.Ic for 97749e11e3aSSheldon Hearncommand is: 978dfe302abSRuslan Ermilov.Bd -unfilled -offset indent -compact 979dfe302abSRuslan Ermilov.Ic for Ar variable Op Ic in Ar word ... 980dfe302abSRuslan Ermilov.Ic do Ar list 981dfe302abSRuslan Ermilov.Ic done 982dfe302abSRuslan Ermilov.Ed 983ab72124fSSteve Price.Pp 984a01459dfSStefan FarfelederIf 985a01459dfSStefan Farfeleder.Ic in 9867b14d37fSRalf S. Engelschalland the following words are omitted, 987776e6b33SJilles Tjoelker.Ic in Li \&"$@\&" 988a01459dfSStefan Farfelederis used instead. 9894b88c807SRodney W. GrimesThe words are expanded, and then the list is executed 99049e11e3aSSheldon Hearnrepeatedly with the variable set to each word in turn. 99149e11e3aSSheldon HearnThe 99249e11e3aSSheldon Hearn.Ic do 9936b15476eSSheldon Hearnand 99449e11e3aSSheldon Hearn.Ic done 99549e11e3aSSheldon Hearncommands may be replaced with 996dfe302abSRuslan Ermilov.Ql { 99749e11e3aSSheldon Hearnand 998dfe302abSRuslan Ermilov.Ql } . 999ab72124fSSteve Price.Pp 100049e11e3aSSheldon HearnThe syntax of the 100149e11e3aSSheldon Hearn.Ic break 100249e11e3aSSheldon Hearnand 100349e11e3aSSheldon Hearn.Ic continue 100449e11e3aSSheldon Hearncommands is: 1005dfe302abSRuslan Ermilov.D1 Ic break Op Ar num 1006dfe302abSRuslan Ermilov.D1 Ic continue Op Ar num 1007ab72124fSSteve Price.Pp 100849e11e3aSSheldon HearnThe 100949e11e3aSSheldon Hearn.Ic break 101049e11e3aSSheldon Hearncommand terminates the 101149e11e3aSSheldon Hearn.Ar num 101249e11e3aSSheldon Hearninnermost 101349e11e3aSSheldon Hearn.Ic for 101449e11e3aSSheldon Hearnor 101549e11e3aSSheldon Hearn.Ic while 101649e11e3aSSheldon Hearnloops. 101749e11e3aSSheldon HearnThe 101849e11e3aSSheldon Hearn.Ic continue 101949e11e3aSSheldon Hearncommand continues with the next iteration of the innermost loop. 102030268dfaSJilles TjoelkerThese are implemented as special built-in commands. 1021ab72124fSSteve Price.Pp 102249e11e3aSSheldon HearnThe syntax of the 102349e11e3aSSheldon Hearn.Ic case 1024dfe302abSRuslan Ermilovcommand is: 1025dfe302abSRuslan Ermilov.Bd -unfilled -offset indent -compact 1026dfe302abSRuslan Ermilov.Ic case Ar word Ic in 1027f3aff7c9SBenjamin Kaduk.Ar pattern ) Ar list Li ;; 1028dfe302abSRuslan Ermilov.Ar ... 1029dfe302abSRuslan Ermilov.Ic esac 1030dfe302abSRuslan Ermilov.Ed 1031ab72124fSSteve Price.Pp 103249e11e3aSSheldon HearnThe pattern can actually be one or more patterns 103349e11e3aSSheldon Hearn(see 103449e11e3aSSheldon Hearn.Sx Shell Patterns 103549e11e3aSSheldon Hearndescribed later), 103649e11e3aSSheldon Hearnseparated by 1037dfe302abSRuslan Ermilov.Ql \&| 10386b15476eSSheldon Hearncharacters. 1039b97989d6SJilles TjoelkerTilde expansion, parameter expansion, command substitution, 1040b97989d6SJilles Tjoelkerarithmetic expansion and quote removal are applied to the word. 1041b97989d6SJilles TjoelkerThen, each pattern is expanded in turn using tilde expansion, 1042b97989d6SJilles Tjoelkerparameter expansion, command substitution and arithmetic expansion and 1043b97989d6SJilles Tjoelkerthe expanded form of the word is checked against it. 1044b97989d6SJilles TjoelkerIf a match is found, the corresponding list is executed. 1045c9afaa63SJilles TjoelkerIf the selected list is terminated by the control operator 1046c9afaa63SJilles Tjoelker.Ql ;& 1047c9afaa63SJilles Tjoelkerinstead of 1048c9afaa63SJilles Tjoelker.Ql ;; , 1049b97989d6SJilles Tjoelkerexecution continues with the next list, 1050b97989d6SJilles Tjoelkercontinuing until a list terminated with 1051b97989d6SJilles Tjoelker.Ql ;; 1052b97989d6SJilles Tjoelkeror the end of the 1053b97989d6SJilles Tjoelker.Ic case 1054b97989d6SJilles Tjoelkercommand. 1055ab72124fSSteve Price.Ss Grouping Commands Together 10564b88c807SRodney W. GrimesCommands may be grouped by writing either 1057dfe302abSRuslan Ermilov.Pp 105817e98da8SMateusz Piotrowski.Sm off 105917e98da8SMateusz Piotrowski.Bd -literal -offset -ident 106017e98da8SMateusz Piotrowski.Po Ar list Pc 106117e98da8SMateusz Piotrowski.Ed 106217e98da8SMateusz Piotrowski.Sm on 1063ab72124fSSteve Price.Pp 10644b88c807SRodney W. Grimesor 106517e98da8SMateusz Piotrowski.Bd -literal -offset -ident 106617e98da8SMateusz Piotrowski.No { Ar list ; } 106717e98da8SMateusz Piotrowski.Ed 1068ab72124fSSteve Price.Pp 1069ef89d04fSJilles TjoelkerThe first form executes the commands in a subshell environment. 107051a514adSJilles TjoelkerA subshell environment has its own copy of: 107151a514adSJilles Tjoelker.Bl -enum 107251a514adSJilles Tjoelker.It 107351a514adSJilles TjoelkerThe current working directory as set by 107451a514adSJilles Tjoelker.Ic cd . 107551a514adSJilles Tjoelker.It 107651a514adSJilles TjoelkerThe file creation mask as set by 107751a514adSJilles Tjoelker.Ic umask . 107851a514adSJilles Tjoelker.It 10790c35cec6SJilles TjoelkerResource limits as set by 10800c35cec6SJilles Tjoelker.Ic ulimit . 10810c35cec6SJilles Tjoelker.It 108251a514adSJilles TjoelkerReferences to open files. 108351a514adSJilles Tjoelker.It 108451a514adSJilles TjoelkerTraps as set by 108551a514adSJilles Tjoelker.Ic trap . 108651a514adSJilles Tjoelker.It 108751a514adSJilles TjoelkerKnown jobs. 108851a514adSJilles Tjoelker.It 108951a514adSJilles TjoelkerPositional parameters and variables. 109051a514adSJilles Tjoelker.It 109151a514adSJilles TjoelkerShell options. 109251a514adSJilles Tjoelker.It 109351a514adSJilles TjoelkerShell functions. 109451a514adSJilles Tjoelker.It 109551a514adSJilles TjoelkerShell aliases. 109651a514adSJilles Tjoelker.El 109751a514adSJilles Tjoelker.Pp 109851a514adSJilles TjoelkerThese are copied from the parent shell environment, 109951a514adSJilles Tjoelkerexcept that trapped (but not ignored) signals are reset to the default action 110051a514adSJilles Tjoelkerand known jobs are cleared. 110151a514adSJilles TjoelkerAny changes do not affect the parent shell environment. 110251a514adSJilles Tjoelker.Pp 110351a514adSJilles TjoelkerA subshell environment may be implemented as a child process or differently. 110451a514adSJilles TjoelkerIf job control is enabled in an interactive shell, 110551a514adSJilles Tjoelkercommands grouped in parentheses can be suspended and continued as a unit. 110651a514adSJilles Tjoelker.Pp 110754ccc8b5SJilles TjoelkerFor compatibility with other shells, 110854ccc8b5SJilles Tjoelkertwo open parentheses in sequence should be separated by whitespace. 110954ccc8b5SJilles Tjoelker.Pp 1110ef89d04fSJilles TjoelkerThe second form never forks another shell, 111149e11e3aSSheldon Hearnso it is slightly more efficient. 111249e11e3aSSheldon HearnGrouping commands together this way allows the user to 1113ab0a2172SSteve Priceredirect their output as though they were one program: 1114ab72124fSSteve Price.Bd -literal -offset indent 1115ee7dc416SSteve Price{ echo -n "hello"; echo " world"; } > greeting 1116ab72124fSSteve Price.Ed 1117ab72124fSSteve Price.Ss Functions 11184b88c807SRodney W. GrimesThe syntax of a function definition is 1119dfe302abSRuslan Ermilov.Pp 1120dfe302abSRuslan Ermilov.D1 Ar name Li \&( \&) Ar command 1121ab72124fSSteve Price.Pp 11224b88c807SRodney W. GrimesA function definition is an executable statement; when 1123dfe302abSRuslan Ermilovexecuted it installs a function named 1124dfe302abSRuslan Ermilov.Ar name 1125dfe302abSRuslan Ermilovand returns an 1126eccea571SRuslan Ermilovexit status of zero. 1127dfe302abSRuslan ErmilovThe 1128dfe302abSRuslan Ermilov.Ar command 1129dfe302abSRuslan Ermilovis normally a list 11306b15476eSSheldon Hearnenclosed between 1131dfe302abSRuslan Ermilov.Ql { 11326b15476eSSheldon Hearnand 1133dfe302abSRuslan Ermilov.Ql } . 1134ab72124fSSteve Price.Pp 11354b88c807SRodney W. GrimesVariables may be declared to be local to a function by 113649e11e3aSSheldon Hearnusing the 113749e11e3aSSheldon Hearn.Ic local 113849e11e3aSSheldon Hearncommand. 113949e11e3aSSheldon HearnThis should appear as the first statement of a function, 114049e11e3aSSheldon Hearnand the syntax is: 1141dfe302abSRuslan Ermilov.Pp 1142dfe302abSRuslan Ermilov.D1 Ic local Oo Ar variable ... Oc Op Fl 1143ab72124fSSteve Price.Pp 114449e11e3aSSheldon HearnThe 114549e11e3aSSheldon Hearn.Ic local 11468eed22b1SJens Schweikhardtcommand is implemented as a built-in command. 1147b1f60592SJilles TjoelkerThe exit status is zero 1148b1f60592SJilles Tjoelkerunless the command is not in a function or a variable name is invalid. 1149ab72124fSSteve Price.Pp 11504b88c807SRodney W. GrimesWhen a variable is made local, it inherits the initial 11514b88c807SRodney W. Grimesvalue and exported and readonly flags from the variable 11524b88c807SRodney W. Grimeswith the same name in the surrounding scope, if there is 1153eccea571SRuslan Ermilovone. 1154eccea571SRuslan ErmilovOtherwise, the variable is initially unset. 1155eccea571SRuslan ErmilovThe shell 1156e918fc8fSSheldon Hearnuses dynamic scoping, so that if the variable 1157dfe302abSRuslan Ermilov.Va x 1158e918fc8fSSheldon Hearnis made local to function 1159e918fc8fSSheldon Hearn.Em f , 1160e918fc8fSSheldon Hearnwhich then calls function 1161e918fc8fSSheldon Hearn.Em g , 1162e918fc8fSSheldon Hearnreferences to the variable 1163dfe302abSRuslan Ermilov.Va x 1164e918fc8fSSheldon Hearnmade inside 1165e918fc8fSSheldon Hearn.Em g 1166e918fc8fSSheldon Hearnwill refer to the variable 1167dfe302abSRuslan Ermilov.Va x 1168e918fc8fSSheldon Hearndeclared inside 1169e918fc8fSSheldon Hearn.Em f , 1170e918fc8fSSheldon Hearnnot to the global variable named 1171dfe302abSRuslan Ermilov.Va x . 1172ab72124fSSteve Price.Pp 11736b4bbd8aSCeri DaviesThe only special parameter that can be made local is 1174dfe302abSRuslan Ermilov.Ql - . 11756b15476eSSheldon HearnMaking 1176dfe302abSRuslan Ermilov.Ql - 117762c37116SJilles Tjoelkerlocal causes any shell options 117862c37116SJilles Tjoelker(including those that only have long names) 117962c37116SJilles Tjoelkerthat are 1180dfe302abSRuslan Ermilovchanged via the 1181dfe302abSRuslan Ermilov.Ic set 1182dfe302abSRuslan Ermilovcommand inside the function to be 11834b88c807SRodney W. Grimesrestored to their original values when the function 11844b88c807SRodney W. Grimesreturns. 1185ab72124fSSteve Price.Pp 118649e11e3aSSheldon HearnThe syntax of the 118749e11e3aSSheldon Hearn.Ic return 118849e11e3aSSheldon Hearncommand is 1189dfe302abSRuslan Ermilov.Pp 1190dfe302abSRuslan Ermilov.D1 Ic return Op Ar exitstatus 1191ab72124fSSteve Price.Pp 11922935c4ccSJilles TjoelkerIt terminates the current executional scope, returning from the closest 11932935c4ccSJilles Tjoelkernested function or sourced script; 11942935c4ccSJilles Tjoelkerif no function or sourced script is being executed, 11952935c4ccSJilles Tjoelkerit exits the shell instance. 119649e11e3aSSheldon HearnThe 119749e11e3aSSheldon Hearn.Ic return 119830268dfaSJilles Tjoelkercommand is implemented as a special built-in command. 1199ab72124fSSteve Price.Ss Variables and Parameters 1200eccea571SRuslan ErmilovThe shell maintains a set of parameters. 1201eccea571SRuslan ErmilovA parameter 12024445af21SJilles Tjoelkerdenoted by a name 12034445af21SJilles Tjoelker(consisting solely 12044445af21SJilles Tjoelkerof alphabetics, numerics, and underscores, 12054445af21SJilles Tjoelkerand starting with an alphabetic or an underscore) 12064445af21SJilles Tjoelkeris called a variable. 1207eccea571SRuslan ErmilovWhen starting up, 12084445af21SJilles Tjoelkerthe shell turns all environment variables with valid names into shell 1209eccea571SRuslan Ermilovvariables. 1210eccea571SRuslan ErmilovNew variables can be set using the form 1211dfe302abSRuslan Ermilov.Pp 1212dfe302abSRuslan Ermilov.D1 Ar name Ns = Ns Ar value 1213ab72124fSSteve Price.Pp 121449e11e3aSSheldon HearnA parameter can also be denoted by a number 12154b88c807SRodney W. Grimesor a special character as explained below. 1216ad56ebdcSJilles Tjoelker.Pp 1217ad56ebdcSJilles TjoelkerAssignments are expanded differently from other words: 1218ad56ebdcSJilles Tjoelkertilde expansion is also performed after the equals sign and after any colon 1219ad56ebdcSJilles Tjoelkerand usernames are also terminated by colons, 1220ad56ebdcSJilles Tjoelkerand field splitting and pathname expansion are not performed. 122184fbdd8cSJilles Tjoelker.Pp 122284fbdd8cSJilles TjoelkerThis special expansion applies not only to assignments that form a simple 122384fbdd8cSJilles Tjoelkercommand by themselves or precede a command word, 122484fbdd8cSJilles Tjoelkerbut also to words passed to the 122584fbdd8cSJilles Tjoelker.Ic export , 122684fbdd8cSJilles Tjoelker.Ic local 122784fbdd8cSJilles Tjoelkeror 122884fbdd8cSJilles Tjoelker.Ic readonly 122984fbdd8cSJilles Tjoelkerbuilt-in commands that have this form. 123084fbdd8cSJilles TjoelkerFor this, the builtin's name must be literal 123184fbdd8cSJilles Tjoelker(not the result of an expansion) 123284fbdd8cSJilles Tjoelkerand may optionally be preceded by one or more literal instances of 123384fbdd8cSJilles Tjoelker.Ic command 123484fbdd8cSJilles Tjoelkerwithout options. 1235ab72124fSSteve Price.Ss Positional Parameters 123649e11e3aSSheldon HearnA positional parameter is a parameter denoted by a number greater than zero. 1237ab72124fSSteve PriceThe shell sets these initially to the values of its command line 1238eccea571SRuslan Ermilovarguments that follow the name of the shell script. 1239eccea571SRuslan ErmilovThe 1240c644db6aSSheldon Hearn.Ic set 12418eed22b1SJens Schweikhardtbuilt-in command can also be used to set or reset them. 1242ab72124fSSteve Price.Ss Special Parameters 1243626a7b1dSJilles TjoelkerSpecial parameters are parameters denoted by a single special character 1244626a7b1dSJilles Tjoelkeror the digit zero. 1245626a7b1dSJilles TjoelkerThey are shown in the following list, exactly as they would appear in input 124643d6677bSAlfred Perlsteintyped by the user or in the source of a shell script. 1247ab72124fSSteve Price.Bl -hang 124843d6677bSAlfred Perlstein.It Li $* 1249eccea571SRuslan ErmilovExpands to the positional parameters, starting from one. 1250eccea571SRuslan ErmilovWhen 12514b88c807SRodney W. Grimesthe expansion occurs within a double-quoted string 12524b88c807SRodney W. Grimesit expands to a single field with the value of each parameter 125349e11e3aSSheldon Hearnseparated by the first character of the 1254dfe302abSRuslan Ermilov.Va IFS 125549e11e3aSSheldon Hearnvariable, 1256dfe302abSRuslan Ermilovor by a space if 1257dfe302abSRuslan Ermilov.Va IFS 125849e11e3aSSheldon Hearnis unset. 125943d6677bSAlfred Perlstein.It Li $@ 1260eccea571SRuslan ErmilovExpands to the positional parameters, starting from one. 1261eccea571SRuslan ErmilovWhen 12624b88c807SRodney W. Grimesthe expansion occurs within double-quotes, each positional 12634b88c807SRodney W. Grimesparameter expands as a separate argument. 12644b88c807SRodney W. GrimesIf there are no positional parameters, the 1265e918fc8fSSheldon Hearnexpansion of 1266e918fc8fSSheldon Hearn.Li @ 1267e918fc8fSSheldon Hearngenerates zero arguments, even when 1268e918fc8fSSheldon Hearn.Li @ 1269eccea571SRuslan Ermilovis double-quoted. 1270eccea571SRuslan ErmilovWhat this basically means, for example, is 1271dfe302abSRuslan Ermilovif 1272dfe302abSRuslan Ermilov.Li $1 1273dfe302abSRuslan Ermilovis 1274dfe302abSRuslan Ermilov.Dq Li abc 1275dfe302abSRuslan Ermilovand 1276dfe302abSRuslan Ermilov.Li $2 1277dfe302abSRuslan Ermilovis 1278dfe302abSRuslan Ermilov.Dq Li "def ghi" , 12796b15476eSSheldon Hearnthen 1280776e6b33SJilles Tjoelker.Li \&"$@\&" 12816b15476eSSheldon Hearnexpands to 12824b88c807SRodney W. Grimesthe two arguments: 1283ab72124fSSteve Price.Bd -literal -offset indent 12844b88c807SRodney W. Grimes"abc" "def ghi" 1285ab72124fSSteve Price.Ed 128643d6677bSAlfred Perlstein.It Li $# 12874b88c807SRodney W. GrimesExpands to the number of positional parameters. 1288dfe302abSRuslan Ermilov.It Li $? 12894b88c807SRodney W. GrimesExpands to the exit status of the most recent pipeline. 129043d6677bSAlfred Perlstein.It Li $- 1291ab72124fSSteve Price(hyphen) Expands to the current option flags (the single-letter 12924b88c807SRodney W. Grimesoption names concatenated into a string) as specified on 1293dfe302abSRuslan Ermilovinvocation, by the 1294dfe302abSRuslan Ermilov.Ic set 1295dfe302abSRuslan Ermilovbuilt-in command, or implicitly 12964b88c807SRodney W. Grimesby the shell. 129743d6677bSAlfred Perlstein.It Li $$ 1298eccea571SRuslan ErmilovExpands to the process ID of the invoked shell. 1299eccea571SRuslan ErmilovA subshell 1300dfe302abSRuslan Ermilovretains the same value of 1301dfe302abSRuslan Ermilov.Va $ 1302dfe302abSRuslan Ermilovas its parent. 1303dfe302abSRuslan Ermilov.It Li $! 13044b88c807SRodney W. GrimesExpands to the process ID of the most recent background 1305eccea571SRuslan Ermilovcommand executed from the current shell. 1306eccea571SRuslan ErmilovFor a 13074b88c807SRodney W. Grimespipeline, the process ID is that of the last command in the 13084b88c807SRodney W. Grimespipeline. 1309ed4c3b5fSJilles TjoelkerIf this parameter is referenced, the shell will remember 1310ed4c3b5fSJilles Tjoelkerthe process ID and its exit status until the 1311ed4c3b5fSJilles Tjoelker.Ic wait 1312ed4c3b5fSJilles Tjoelkerbuilt-in command reports completion of the process. 131343d6677bSAlfred Perlstein.It Li $0 131457a40f7dSJilles Tjoelker(zero) Expands to the name of the shell script if passed on the command line, 131557a40f7dSJilles Tjoelkerthe 131657a40f7dSJilles Tjoelker.Ar name 131757a40f7dSJilles Tjoelkeroperand if given (with 131857a40f7dSJilles Tjoelker.Fl c ) 131957a40f7dSJilles Tjoelkeror otherwise argument 0 passed to the shell. 1320ab72124fSSteve Price.El 13211788b7ffSJilles Tjoelker.Ss Special Variables 13221788b7ffSJilles TjoelkerThe following variables are set by the shell or 13231788b7ffSJilles Tjoelkerhave special meaning to it: 13241788b7ffSJilles Tjoelker.Bl -tag -width ".Va HISTSIZE" 13251788b7ffSJilles Tjoelker.It Va CDPATH 13261788b7ffSJilles TjoelkerThe search path used with the 13271788b7ffSJilles Tjoelker.Ic cd 13281788b7ffSJilles Tjoelkerbuilt-in. 13291788b7ffSJilles Tjoelker.It Va EDITOR 13301788b7ffSJilles TjoelkerThe fallback editor used with the 13311788b7ffSJilles Tjoelker.Ic fc 13321788b7ffSJilles Tjoelkerbuilt-in. 13331788b7ffSJilles TjoelkerIf not set, the default editor is 13341788b7ffSJilles Tjoelker.Xr ed 1 . 13351788b7ffSJilles Tjoelker.It Va FCEDIT 13361788b7ffSJilles TjoelkerThe default editor used with the 13371788b7ffSJilles Tjoelker.Ic fc 13381788b7ffSJilles Tjoelkerbuilt-in. 13391788b7ffSJilles Tjoelker.It Va HISTSIZE 13401788b7ffSJilles TjoelkerThe number of previous commands that are accessible. 13411788b7ffSJilles Tjoelker.It Va HOME 13421788b7ffSJilles TjoelkerThe user's home directory, 13431788b7ffSJilles Tjoelkerused in tilde expansion and as a default directory for the 13441788b7ffSJilles Tjoelker.Ic cd 13451788b7ffSJilles Tjoelkerbuilt-in. 13461788b7ffSJilles Tjoelker.It Va IFS 13471788b7ffSJilles TjoelkerInput Field Separators. 13487cca93e6SJilles TjoelkerThis is initialized at startup to 13491788b7ffSJilles Tjoelker.Aq space , 13501788b7ffSJilles Tjoelker.Aq tab , 13511788b7ffSJilles Tjoelkerand 1352ad56ebdcSJilles Tjoelker.Aq newline 1353ad56ebdcSJilles Tjoelkerin that order. 13547cca93e6SJilles TjoelkerThis value also applies if 1355ad56ebdcSJilles Tjoelker.Va IFS 1356ad56ebdcSJilles Tjoelkeris unset, but not if it is set to the empty string. 13571788b7ffSJilles TjoelkerSee the 13581788b7ffSJilles Tjoelker.Sx White Space Splitting 13591788b7ffSJilles Tjoelkersection for more details. 13601788b7ffSJilles Tjoelker.It Va LINENO 13611788b7ffSJilles TjoelkerThe current line number in the script or function. 13621788b7ffSJilles Tjoelker.It Va MAIL 13631788b7ffSJilles TjoelkerThe name of a mail file, that will be checked for the arrival of new 13641788b7ffSJilles Tjoelkermail. 13651788b7ffSJilles TjoelkerOverridden by 13661788b7ffSJilles Tjoelker.Va MAILPATH . 13671788b7ffSJilles Tjoelker.It Va MAILPATH 13681788b7ffSJilles TjoelkerA colon 13691788b7ffSJilles Tjoelker.Pq Ql \&: 13701788b7ffSJilles Tjoelkerseparated list of file names, for the shell to check for incoming 13711788b7ffSJilles Tjoelkermail. 13721788b7ffSJilles TjoelkerThis variable overrides the 13731788b7ffSJilles Tjoelker.Va MAIL 13741788b7ffSJilles Tjoelkersetting. 13751788b7ffSJilles TjoelkerThere is a maximum of 10 mailboxes that can be monitored at once. 13764445af21SJilles Tjoelker.It Va OPTIND 13774445af21SJilles TjoelkerThe index of the next argument to be processed by 13784445af21SJilles Tjoelker.Ic getopts . 13794445af21SJilles TjoelkerThis is initialized to 1 at startup. 13801788b7ffSJilles Tjoelker.It Va PATH 13811788b7ffSJilles TjoelkerThe default search path for executables. 13821788b7ffSJilles TjoelkerSee the 13831788b7ffSJilles Tjoelker.Sx Path Search 13841788b7ffSJilles Tjoelkersection for details. 13851788b7ffSJilles Tjoelker.It Va PPID 13861788b7ffSJilles TjoelkerThe parent process ID of the invoked shell. 13871788b7ffSJilles TjoelkerThis is set at startup 13881788b7ffSJilles Tjoelkerunless this variable is in the environment. 13891788b7ffSJilles TjoelkerA later change of parent process ID is not reflected. 13901788b7ffSJilles TjoelkerA subshell retains the same value of 13911788b7ffSJilles Tjoelker.Va PPID . 13921788b7ffSJilles Tjoelker.It Va PS1 13931788b7ffSJilles TjoelkerThe primary prompt string, which defaults to 13941788b7ffSJilles Tjoelker.Dq Li "$ " , 13951788b7ffSJilles Tjoelkerunless you are the superuser, in which case it defaults to 13961788b7ffSJilles Tjoelker.Dq Li "# " . 13971ca3beb9SJoel Dahl.Va PS1 13981ca3beb9SJoel Dahlmay include any of the following formatting sequences, 13991ca3beb9SJoel Dahlwhich are replaced by the given information: 14001ca3beb9SJoel Dahl.Bl -tag -width indent 14011ca3beb9SJoel Dahl.It Li \eH 14022770ce60SWarren BlockThis system's fully-qualified hostname (FQDN). 1403ae100660SDon Lewis.It Li \eh 14042770ce60SWarren BlockThis system's hostname. 14051ca3beb9SJoel Dahl.It Li \eW 14061ca3beb9SJoel DahlThe final component of the current working directory. 14071ca3beb9SJoel Dahl.It Li \ew 14081ca3beb9SJoel DahlThe entire path of the current working directory. 14091ca3beb9SJoel Dahl.It Li \e$ 14101ca3beb9SJoel DahlSuperuser status. 14111ca3beb9SJoel Dahl.Dq Li "$ " 14121ca3beb9SJoel Dahlfor normal users and 14131ca3beb9SJoel Dahl.Dq Li "# " 14141ca3beb9SJoel Dahlfor superusers. 14151ca3beb9SJoel Dahl.It Li \e\e 14161ca3beb9SJoel DahlA literal backslash. 14171ca3beb9SJoel Dahl.El 14181788b7ffSJilles Tjoelker.It Va PS2 14191788b7ffSJilles TjoelkerThe secondary prompt string, which defaults to 14201788b7ffSJilles Tjoelker.Dq Li "> " . 14211ca3beb9SJoel Dahl.Va PS2 14221ca3beb9SJoel Dahlmay include any of the formatting sequences from 14231ca3beb9SJoel Dahl.Va PS1 . 14241788b7ffSJilles Tjoelker.It Va PS4 14251788b7ffSJilles TjoelkerThe prefix for the trace output (if 14261788b7ffSJilles Tjoelker.Fl x 14271788b7ffSJilles Tjoelkeris active). 14281788b7ffSJilles TjoelkerThe default is 14291788b7ffSJilles Tjoelker.Dq Li "+ " . 14301788b7ffSJilles Tjoelker.El 1431ab72124fSSteve Price.Ss Word Expansions 14324b88c807SRodney W. GrimesThis clause describes the various expansions that are 1433eccea571SRuslan Ermilovperformed on words. 1434eccea571SRuslan ErmilovNot all expansions are performed on 14354b88c807SRodney W. Grimesevery word, as explained later. 1436ab72124fSSteve Price.Pp 14374b88c807SRodney W. GrimesTilde expansions, parameter expansions, command substitutions, 14384b88c807SRodney W. Grimesarithmetic expansions, and quote removals that occur within 1439eccea571SRuslan Ermilova single word expand to a single field. 1440eccea571SRuslan ErmilovIt is only field 14414b88c807SRodney W. Grimessplitting or pathname expansion that can create multiple 1442e6d3cf26SSheldon Hearnfields from a single word. 1443e6d3cf26SSheldon HearnThe single exception to this rule is 1444e918fc8fSSheldon Hearnthe expansion of the special parameter 1445dfe302abSRuslan Ermilov.Va @ 1446e918fc8fSSheldon Hearnwithin double-quotes, 1447e6d3cf26SSheldon Hearnas was described above. 1448ab72124fSSteve Price.Pp 14494b88c807SRodney W. GrimesThe order of word expansion is: 1450ab72124fSSteve Price.Bl -enum 1451ab72124fSSteve Price.It 1452ab72124fSSteve PriceTilde Expansion, Parameter Expansion, Command Substitution, 14534b88c807SRodney W. GrimesArithmetic Expansion (these all occur at the same time). 1454ab72124fSSteve Price.It 145549e11e3aSSheldon HearnField Splitting is performed on fields generated by step (1) 145649e11e3aSSheldon Hearnunless the 1457dfe302abSRuslan Ermilov.Va IFS 145849e11e3aSSheldon Hearnvariable is null. 1459ab72124fSSteve Price.It 146049e11e3aSSheldon HearnPathname Expansion (unless the 146149e11e3aSSheldon Hearn.Fl f 146249e11e3aSSheldon Hearnoption is in effect). 1463ab72124fSSteve Price.It 1464ab72124fSSteve PriceQuote Removal. 1465ab72124fSSteve Price.El 1466ab72124fSSteve Price.Pp 146749e11e3aSSheldon HearnThe 1468dfe302abSRuslan Ermilov.Ql $ 146949e11e3aSSheldon Hearncharacter is used to introduce parameter expansion, command 147036cf3efeSJilles Tjoelkersubstitution, or arithmetic expansion. 1471ab72124fSSteve Price.Ss Tilde Expansion (substituting a user's home directory) 147249e11e3aSSheldon HearnA word beginning with an unquoted tilde character 1473a762afe5SGiorgos Keramidas.Pq Ql ~ 147449e11e3aSSheldon Hearnis 147549e11e3aSSheldon Hearnsubjected to tilde expansion. 147649e11e3aSSheldon HearnAll the characters up to a slash 1477a762afe5SGiorgos Keramidas.Pq Ql / 147849e11e3aSSheldon Hearnor the end of the word are treated as a username 1479eccea571SRuslan Ermilovand are replaced with the user's home directory. 1480eccea571SRuslan ErmilovIf the 1481dfe302abSRuslan Ermilovusername is missing (as in 1482dfe302abSRuslan Ermilov.Pa ~/foobar ) , 1483dfe302abSRuslan Ermilovthe tilde is replaced with the value of the 14841788b7ffSJilles Tjoelker.Va HOME 1485dfe302abSRuslan Ermilovvariable (the current user's home directory). 1486ab72124fSSteve Price.Ss Parameter Expansion 14874b88c807SRodney W. GrimesThe format for parameter expansion is as follows: 1488ab72124fSSteve Price.Pp 1489dfe302abSRuslan Ermilov.D1 Li ${ Ns Ar expression Ns Li } 1490dfe302abSRuslan Ermilov.Pp 1491dfe302abSRuslan Ermilovwhere 1492dfe302abSRuslan Ermilov.Ar expression 1493dfe302abSRuslan Ermilovconsists of all characters until the matching 1494dfe302abSRuslan Ermilov.Ql } . 149549e11e3aSSheldon HearnAny 1496dfe302abSRuslan Ermilov.Ql } 1497f35d74beSJilles Tjoelkerescaped by a backslash or within a single-quoted or double-quoted 1498f35d74beSJilles Tjoelkerstring, and characters in 14994b88c807SRodney W. Grimesembedded arithmetic expansions, command substitutions, and variable 150049e11e3aSSheldon Hearnexpansions, are not examined in determining the matching 1501dfe302abSRuslan Ermilov.Ql } . 1502f35d74beSJilles TjoelkerIf the variants with 1503227c8e2aSJilles Tjoelker.Ql + , 1504227c8e2aSJilles Tjoelker.Ql - , 1505227c8e2aSJilles Tjoelker.Ql = 1506227c8e2aSJilles Tjoelkeror 1507f35d74beSJilles Tjoelker.Ql ?\& 1508f35d74beSJilles Tjoelkeroccur within a double-quoted string, 1509f35d74beSJilles Tjoelkeras an extension there may be unquoted parts 1510f35d74beSJilles Tjoelker(via double-quotes inside the expansion); 1511227c8e2aSJilles Tjoelker.Ql } 1512f35d74beSJilles Tjoelkerwithin such parts are also not examined in determining the matching 1513227c8e2aSJilles Tjoelker.Ql } . 1514ab72124fSSteve Price.Pp 15154b88c807SRodney W. GrimesThe simplest form for parameter expansion is: 1516ab72124fSSteve Price.Pp 1517dfe302abSRuslan Ermilov.D1 Li ${ Ns Ar parameter Ns Li } 1518dfe302abSRuslan Ermilov.Pp 1519dfe302abSRuslan ErmilovThe value, if any, of 1520dfe302abSRuslan Ermilov.Ar parameter 1521dfe302abSRuslan Ermilovis substituted. 1522ab72124fSSteve Price.Pp 15234b88c807SRodney W. GrimesThe parameter name or symbol can be enclosed in braces, which are 15244b88c807SRodney W. Grimesoptional except for positional parameters with more than one digit or 15254b88c807SRodney W. Grimeswhen parameter is followed by a character that could be interpreted as 15264b88c807SRodney W. Grimespart of the name. 1527ab72124fSSteve PriceIf a parameter expansion occurs inside double-quotes: 1528ab72124fSSteve Price.Bl -enum 1529ab72124fSSteve Price.It 1530ab72124fSSteve PriceField splitting is not performed on the results of the 1531e918fc8fSSheldon Hearnexpansion, with the exception of the special parameter 1532dfe302abSRuslan Ermilov.Va @ . 1533ad56ebdcSJilles Tjoelker.It 1534ad56ebdcSJilles TjoelkerPathname expansion is not performed on the results of the 1535ad56ebdcSJilles Tjoelkerexpansion. 1536ab72124fSSteve Price.El 1537ab72124fSSteve Price.Pp 15384b88c807SRodney W. GrimesIn addition, a parameter expansion can be modified by using one of the 15394b88c807SRodney W. Grimesfollowing formats. 154081e9cda2SRuslan Ermilov.Bl -tag -width indent 1541dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li :- Ns Ar word Ns Li } 1542eccea571SRuslan ErmilovUse Default Values. 1543dfe302abSRuslan ErmilovIf 1544dfe302abSRuslan Ermilov.Ar parameter 1545dfe302abSRuslan Ermilovis unset or null, the expansion of 1546dfe302abSRuslan Ermilov.Ar word 1547dfe302abSRuslan Ermilovis substituted; otherwise, the value of 1548dfe302abSRuslan Ermilov.Ar parameter 1549dfe302abSRuslan Ermilovis substituted. 1550dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li := Ns Ar word Ns Li } 1551eccea571SRuslan ErmilovAssign Default Values. 1552dfe302abSRuslan ErmilovIf 1553dfe302abSRuslan Ermilov.Ar parameter 1554dfe302abSRuslan Ermilovis unset or null, the expansion of 1555dfe302abSRuslan Ermilov.Ar word 1556dfe302abSRuslan Ermilovis assigned to 1557dfe302abSRuslan Ermilov.Ar parameter . 1558eccea571SRuslan ErmilovIn all cases, the 1559dfe302abSRuslan Ermilovfinal value of 1560dfe302abSRuslan Ermilov.Ar parameter 1561dfe302abSRuslan Ermilovis substituted. 1562b139165cSJilles TjoelkerQuoting inside 1563b139165cSJilles Tjoelker.Ar word 1564b139165cSJilles Tjoelkerdoes not prevent field splitting or pathname expansion. 1565eccea571SRuslan ErmilovOnly variables, not positional 15664b88c807SRodney W. Grimesparameters or special parameters, can be 15674b88c807SRodney W. Grimesassigned in this way. 1568dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li :? Ns Oo Ar word Oc Ns Li } 1569eccea571SRuslan ErmilovIndicate Error if Null or Unset. 1570eccea571SRuslan ErmilovIf 1571dfe302abSRuslan Ermilov.Ar parameter 1572dfe302abSRuslan Ermilovis unset or null, the expansion of 1573dfe302abSRuslan Ermilov.Ar word 1574dfe302abSRuslan Ermilov(or a message indicating it is unset if 1575dfe302abSRuslan Ermilov.Ar word 1576dfe302abSRuslan Ermilovis omitted) is written to standard 15774b88c807SRodney W. Grimeserror and the shell exits with a nonzero 1578e6d3cf26SSheldon Hearnexit status. 1579e6d3cf26SSheldon HearnOtherwise, the value of 1580dfe302abSRuslan Ermilov.Ar parameter 1581dfe302abSRuslan Ermilovis substituted. 1582eccea571SRuslan ErmilovAn 15834b88c807SRodney W. Grimesinteractive shell need not exit. 1584dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li :+ Ns Ar word Ns Li } 1585eccea571SRuslan ErmilovUse Alternate Value. 1586dfe302abSRuslan ErmilovIf 1587dfe302abSRuslan Ermilov.Ar parameter 1588dfe302abSRuslan Ermilovis unset or null, null is substituted; 1589dfe302abSRuslan Ermilovotherwise, the expansion of 1590dfe302abSRuslan Ermilov.Ar word 1591dfe302abSRuslan Ermilovis substituted. 15921413f7deSTony Finch.El 1593ab72124fSSteve Price.Pp 15944b88c807SRodney W. GrimesIn the parameter expansions shown previously, use of the colon in the 15954b88c807SRodney W. Grimesformat results in a test for a parameter that is unset or null; omission 15964b88c807SRodney W. Grimesof the colon results in a test for a parameter that is only unset. 1597227c8e2aSJilles Tjoelker.Pp 1598227c8e2aSJilles TjoelkerThe 1599227c8e2aSJilles Tjoelker.Ar word 1600227c8e2aSJilles Tjoelkerinherits the type of quoting 1601227c8e2aSJilles Tjoelker(unquoted, double-quoted or here-document) 1602227c8e2aSJilles Tjoelkerfrom the surroundings, 1603227c8e2aSJilles Tjoelkerwith the exception that a backslash that quotes a closing brace is removed 1604227c8e2aSJilles Tjoelkerduring quote removal. 16051413f7deSTony Finch.Bl -tag -width indent 1606dfe302abSRuslan Ermilov.It Li ${# Ns Ar parameter Ns Li } 1607eccea571SRuslan ErmilovString Length. 1608eccea571SRuslan ErmilovThe length in characters of 1609dfe302abSRuslan Ermilovthe value of 1610dfe302abSRuslan Ermilov.Ar parameter . 161171337c33SSheldon Hearn.El 1612ab72124fSSteve Price.Pp 16134b88c807SRodney W. GrimesThe following four varieties of parameter expansion provide for substring 161449e11e3aSSheldon Hearnprocessing. 161549e11e3aSSheldon HearnIn each case, pattern matching notation 161649e11e3aSSheldon Hearn(see 161749e11e3aSSheldon Hearn.Sx Shell Patterns ) , 161849e11e3aSSheldon Hearnrather than regular expression notation, 161949e11e3aSSheldon Hearnis used to evaluate the patterns. 1620e918fc8fSSheldon HearnIf parameter is one of the special parameters 1621dfe302abSRuslan Ermilov.Va * 162249e11e3aSSheldon Hearnor 1623dfe302abSRuslan Ermilov.Va @ , 162449e11e3aSSheldon Hearnthe result of the expansion is unspecified. 16254b88c807SRodney W. GrimesEnclosing the full parameter expansion string in double-quotes does not 16264b88c807SRodney W. Grimescause the following four varieties of pattern characters to be quoted, 16274b88c807SRodney W. Grimeswhereas quoting characters within the braces has this effect. 162881e9cda2SRuslan Ermilov.Bl -tag -width indent 1629dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li % Ns Ar word Ns Li } 1630eccea571SRuslan ErmilovRemove Smallest Suffix Pattern. 1631dfe302abSRuslan ErmilovThe 1632dfe302abSRuslan Ermilov.Ar word 1633eccea571SRuslan Ermilovis expanded to produce a pattern. 1634eccea571SRuslan ErmilovThe 16354b88c807SRodney W. Grimesparameter expansion then results in 1636dfe302abSRuslan Ermilov.Ar parameter , 1637dfe302abSRuslan Ermilovwith the smallest portion of the 16384b88c807SRodney W. Grimessuffix matched by the pattern deleted. 1639dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li %% Ns Ar word Ns Li } 1640eccea571SRuslan ErmilovRemove Largest Suffix Pattern. 1641dfe302abSRuslan ErmilovThe 1642dfe302abSRuslan Ermilov.Ar word 1643eccea571SRuslan Ermilovis expanded to produce a pattern. 1644eccea571SRuslan ErmilovThe 16454b88c807SRodney W. Grimesparameter expansion then results in 1646dfe302abSRuslan Ermilov.Ar parameter , 1647dfe302abSRuslan Ermilovwith the largest portion of the 16484b88c807SRodney W. Grimessuffix matched by the pattern deleted. 1649dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li # Ns Ar word Ns Li } 1650eccea571SRuslan ErmilovRemove Smallest Prefix Pattern. 1651dfe302abSRuslan ErmilovThe 1652dfe302abSRuslan Ermilov.Ar word 1653eccea571SRuslan Ermilovis expanded to produce a pattern. 1654eccea571SRuslan ErmilovThe 16554b88c807SRodney W. Grimesparameter expansion then results in 1656dfe302abSRuslan Ermilov.Ar parameter , 1657dfe302abSRuslan Ermilovwith the smallest portion of the 16584b88c807SRodney W. Grimesprefix matched by the pattern deleted. 1659dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li ## Ns Ar word Ns Li } 1660eccea571SRuslan ErmilovRemove Largest Prefix Pattern. 1661dfe302abSRuslan ErmilovThe 1662dfe302abSRuslan Ermilov.Ar word 1663eccea571SRuslan Ermilovis expanded to produce a pattern. 1664eccea571SRuslan ErmilovThe 16654b88c807SRodney W. Grimesparameter expansion then results in 1666dfe302abSRuslan Ermilov.Ar parameter , 1667dfe302abSRuslan Ermilovwith the largest portion of the 16684b88c807SRodney W. Grimesprefix matched by the pattern deleted. 1669ab72124fSSteve Price.El 1670ab72124fSSteve Price.Ss Command Substitution 16714b88c807SRodney W. GrimesCommand substitution allows the output of a command to be substituted in 1672eccea571SRuslan Ermilovplace of the command name itself. 1673eccea571SRuslan ErmilovCommand substitution occurs when 16744b88c807SRodney W. Grimesthe command is enclosed as follows: 1675dfe302abSRuslan Ermilov.Pp 1676dfe302abSRuslan Ermilov.D1 Li $( Ns Ar command Ns Li )\& 1677ab72124fSSteve Price.Pp 167849e11e3aSSheldon Hearnor the backquoted version: 1679dfe302abSRuslan Ermilov.Pp 1680dfe302abSRuslan Ermilov.D1 Li ` Ns Ar command Ns Li ` 1681ab72124fSSteve Price.Pp 1682ef89d04fSJilles TjoelkerThe shell expands the command substitution by executing command 1683ef89d04fSJilles Tjoelkerand replacing the command substitution 168449e11e3aSSheldon Hearnwith the standard output of the command, 168549e11e3aSSheldon Hearnremoving sequences of one or more newlines at the end of the substitution. 168649e11e3aSSheldon HearnEmbedded newlines before the end of the output are not removed; 168749e11e3aSSheldon Hearnhowever, during field splitting, they may be translated into spaces 168849e11e3aSSheldon Hearndepending on the value of 1689dfe302abSRuslan Ermilov.Va IFS 169049e11e3aSSheldon Hearnand the quoting that is in effect. 1691ef89d04fSJilles TjoelkerThe command is executed in a subshell environment, 1692ef89d04fSJilles Tjoelkerexcept that the built-in commands 1693ef89d04fSJilles Tjoelker.Ic jobid , 1694ef89d04fSJilles Tjoelker.Ic jobs , 1695ef89d04fSJilles Tjoelkerand 1696ef89d04fSJilles Tjoelker.Ic trap 169751a514adSJilles Tjoelkerreturn information about the parent shell environment 169851a514adSJilles Tjoelkerand 169951a514adSJilles Tjoelker.Ic times 170051a514adSJilles Tjoelkerreturns information about the same process 1701c543e1aeSJilles Tjoelkerif they are the only command in a command substitution. 170254ccc8b5SJilles Tjoelker.Pp 170354ccc8b5SJilles TjoelkerIf a command substitution of the 170454ccc8b5SJilles Tjoelker.Li $( 170554ccc8b5SJilles Tjoelkerform begins with a subshell, 170654ccc8b5SJilles Tjoelkerthe 170754ccc8b5SJilles Tjoelker.Li $( 170854ccc8b5SJilles Tjoelkerand 17095127efa3SJoel Dahl.Li (\& 171054ccc8b5SJilles Tjoelkermust be separated by whitespace 171154ccc8b5SJilles Tjoelkerto avoid ambiguity with arithmetic expansion. 1712ab72124fSSteve Price.Ss Arithmetic Expansion 17134b88c807SRodney W. GrimesArithmetic expansion provides a mechanism for evaluating an arithmetic 1714e6d3cf26SSheldon Hearnexpression and substituting its value. 1715e6d3cf26SSheldon HearnThe format for arithmetic expansion is as follows: 1716ab72124fSSteve Price.Pp 1717dfe302abSRuslan Ermilov.D1 Li $(( Ns Ar expression Ns Li )) 1718dfe302abSRuslan Ermilov.Pp 1719dfe302abSRuslan ErmilovThe 1720dfe302abSRuslan Ermilov.Ar expression 1721dfe302abSRuslan Ermilovis treated as if it were in double-quotes, except 1722eccea571SRuslan Ermilovthat a double-quote inside the expression is not treated specially. 1723eccea571SRuslan ErmilovThe 1724dfe302abSRuslan Ermilovshell expands all tokens in the 1725dfe302abSRuslan Ermilov.Ar expression 1726dfe302abSRuslan Ermilovfor parameter expansion, 172736cf3efeSJilles Tjoelkercommand substitution, 172836cf3efeSJilles Tjoelkerarithmetic expansion 172936cf3efeSJilles Tjoelkerand quote removal. 1730ab72124fSSteve Price.Pp 173136cf3efeSJilles TjoelkerThe allowed expressions are a subset of C expressions, 173236cf3efeSJilles Tjoelkersummarized below. 173336cf3efeSJilles Tjoelker.Bl -tag -width "Variables" -offset indent 173436cf3efeSJilles Tjoelker.It Values 173536cf3efeSJilles TjoelkerAll values are of type 173636cf3efeSJilles Tjoelker.Ft intmax_t . 173736cf3efeSJilles Tjoelker.It Constants 173836cf3efeSJilles TjoelkerDecimal, octal (starting with 173936cf3efeSJilles Tjoelker.Li 0 ) 174036cf3efeSJilles Tjoelkerand hexadecimal (starting with 174136cf3efeSJilles Tjoelker.Li 0x ) 174236cf3efeSJilles Tjoelkerinteger constants. 174336cf3efeSJilles Tjoelker.It Variables 174436cf3efeSJilles TjoelkerShell variables can be read and written 174536cf3efeSJilles Tjoelkerand contain integer constants. 174636cf3efeSJilles Tjoelker.It Unary operators 174736cf3efeSJilles Tjoelker.Li "! ~ + -" 174836cf3efeSJilles Tjoelker.It Binary operators 174917e98da8SMateusz Piotrowski.Li "* / % + - << >> < <= > >= == != & ^ | && ||"\& 175036cf3efeSJilles Tjoelker.It Assignment operators 175136cf3efeSJilles Tjoelker.Li "= += -= *= /= %= <<= >>= &= ^= |=" 1752075b72efSJilles Tjoelker.It Conditional operator 175317e98da8SMateusz Piotrowski.Li "? :"\& 175436cf3efeSJilles Tjoelker.El 175536cf3efeSJilles Tjoelker.Pp 175636cf3efeSJilles TjoelkerThe result of the expression is substituted in decimal. 1757ab72124fSSteve Price.Ss White Space Splitting (Field Splitting) 1758ad56ebdcSJilles TjoelkerIn certain contexts, 1759ad56ebdcSJilles Tjoelkerafter parameter expansion, command substitution, and 17604b88c807SRodney W. Grimesarithmetic expansion the shell scans the results of 17614b88c807SRodney W. Grimesexpansions and substitutions that did not occur in double-quotes for 17624b88c807SRodney W. Grimesfield splitting and multiple fields can result. 1763ab72124fSSteve Price.Pp 1764ad56ebdcSJilles TjoelkerCharacters in 1765dfe302abSRuslan Ermilov.Va IFS 1766ad56ebdcSJilles Tjoelkerthat are whitespace 1767ad56ebdcSJilles Tjoelker.Po 1768ad56ebdcSJilles Tjoelker.Aq space , 1769ad56ebdcSJilles Tjoelker.Aq tab , 1770ad56ebdcSJilles Tjoelkerand 1771ad56ebdcSJilles Tjoelker.Aq newline 1772ad56ebdcSJilles Tjoelker.Pc 1773ad56ebdcSJilles Tjoelkerare treated differently from other characters in 1774ad56ebdcSJilles Tjoelker.Va IFS . 1775ad56ebdcSJilles Tjoelker.Pp 1776ad56ebdcSJilles TjoelkerWhitespace in 1777ad56ebdcSJilles Tjoelker.Va IFS 1778ad56ebdcSJilles Tjoelkerat the beginning or end of a word is discarded. 1779ad56ebdcSJilles Tjoelker.Pp 1780ad56ebdcSJilles TjoelkerSubsequently, a field is delimited by either 1781ad56ebdcSJilles Tjoelker.Bl -enum 1782ad56ebdcSJilles Tjoelker.It 1783ad56ebdcSJilles Tjoelkera non-whitespace character in 1784ad56ebdcSJilles Tjoelker.Va IFS 1785ad56ebdcSJilles Tjoelkerwith any whitespace in 1786ad56ebdcSJilles Tjoelker.Va IFS 1787ad56ebdcSJilles Tjoelkersurrounding it, or 1788ad56ebdcSJilles Tjoelker.It 1789ad56ebdcSJilles Tjoelkerone or more whitespace characters in 1790ad56ebdcSJilles Tjoelker.Va IFS . 1791ad56ebdcSJilles Tjoelker.El 1792ad56ebdcSJilles Tjoelker.Pp 1793ad56ebdcSJilles TjoelkerIf a word ends with a non-whitespace character in 1794ad56ebdcSJilles Tjoelker.Va IFS , 1795ad56ebdcSJilles Tjoelkerthere is no empty field after this character. 1796ad56ebdcSJilles Tjoelker.Pp 1797ad56ebdcSJilles TjoelkerIf no field is delimited, the word is discarded. 1798ad56ebdcSJilles TjoelkerIn particular, if a word consists solely of an unquoted substitution 1799ad56ebdcSJilles Tjoelkerand the result of the substitution is null, 1800ad56ebdcSJilles Tjoelkerit is removed by field splitting even if 1801ad56ebdcSJilles Tjoelker.Va IFS 1802ad56ebdcSJilles Tjoelkeris null. 1803ab72124fSSteve Price.Ss Pathname Expansion (File Name Generation) 180449e11e3aSSheldon HearnUnless the 180549e11e3aSSheldon Hearn.Fl f 180649e11e3aSSheldon Hearnoption is set, 180749e11e3aSSheldon Hearnfile name generation is performed 1808eccea571SRuslan Ermilovafter word splitting is complete. 1809eccea571SRuslan ErmilovEach word is 1810eccea571SRuslan Ermilovviewed as a series of patterns, separated by slashes. 1811eccea571SRuslan ErmilovThe 18124b88c807SRodney W. Grimesprocess of expansion replaces the word with the names of 18134b88c807SRodney W. Grimesall existing files whose names can be formed by replacing 18144b88c807SRodney W. Grimeseach pattern with a string that matches the specified pattern. 1815ab0a2172SSteve PriceThere are two restrictions on this: first, a pattern cannot match 1816ab0a2172SSteve Pricea string containing a slash, and second, 18174b88c807SRodney W. Grimesa pattern cannot match a string starting with a period 18184b88c807SRodney W. Grimesunless the first character of the pattern is a period. 1819519c4ef3SJilles TjoelkerThe next section describes the patterns used for 1820519c4ef3SJilles TjoelkerPathname Expansion, 1821519c4ef3SJilles Tjoelkerthe four varieties of parameter expansion for substring processing and the 1822c644db6aSSheldon Hearn.Ic case 1823ab72124fSSteve Pricecommand. 1824ab72124fSSteve Price.Ss Shell Patterns 1825f434d1dfSAdam DavidA pattern consists of normal characters, which match themselves, 182649e11e3aSSheldon Hearnand meta-characters. 182749e11e3aSSheldon HearnThe meta-characters are 1828dfe302abSRuslan Ermilov.Ql * , 1829dfe302abSRuslan Ermilov.Ql \&? , 18306b15476eSSheldon Hearnand 1831dfe302abSRuslan Ermilov.Ql \&[ . 18326b15476eSSheldon HearnThese characters lose their special meanings if they are quoted. 18336b15476eSSheldon HearnWhen command or variable substitution is performed and the dollar sign 18346b15476eSSheldon Hearnor back quotes are not double-quoted, the value of the 18354b88c807SRodney W. Grimesvariable or the output of the command is scanned for these 18364b88c807SRodney W. Grimescharacters and they are turned into meta-characters. 1837ab72124fSSteve Price.Pp 18386b15476eSSheldon HearnAn asterisk 1839a762afe5SGiorgos Keramidas.Pq Ql * 1840e918fc8fSSheldon Hearnmatches any string of characters. 1841e918fc8fSSheldon HearnA question mark 1842a762afe5SGiorgos Keramidas.Pq Ql \&? 1843e918fc8fSSheldon Hearnmatches any single character. 1844e6d3cf26SSheldon HearnA left bracket 1845dfe302abSRuslan Ermilov.Pq Ql \&[ 1846e6d3cf26SSheldon Hearnintroduces a character class. 1847e6d3cf26SSheldon HearnThe end of the character class is indicated by a 1848dfe302abSRuslan Ermilov.Ql \&] ; 18496b15476eSSheldon Hearnif the 1850dfe302abSRuslan Ermilov.Ql \&] 18516b15476eSSheldon Hearnis missing then the 1852dfe302abSRuslan Ermilov.Ql \&[ 18536b15476eSSheldon Hearnmatches a 1854dfe302abSRuslan Ermilov.Ql \&[ 1855e6d3cf26SSheldon Hearnrather than introducing a character class. 1856e6d3cf26SSheldon HearnA character class matches any of the characters between the square brackets. 1857519c4ef3SJilles TjoelkerA locale-dependent range of characters may be specified using a minus sign. 1858ff4dc672SJilles TjoelkerA named class of characters (see 1859ff4dc672SJilles Tjoelker.Xr wctype 3 ) 1860ff4dc672SJilles Tjoelkermay be specified by surrounding the name with 186117e98da8SMateusz Piotrowski.Ql \&[:\& 1862ff4dc672SJilles Tjoelkerand 1863ff4dc672SJilles Tjoelker.Ql :\&] . 1864ff4dc672SJilles TjoelkerFor example, 1865ff4dc672SJilles Tjoelker.Ql \&[\&[:alpha:\&]\&] 1866ff4dc672SJilles Tjoelkeris a shell pattern that matches a single letter. 1867e918fc8fSSheldon HearnThe character class may be complemented by making an exclamation point 1868a762afe5SGiorgos Keramidas.Pq Ql !\& 1869e918fc8fSSheldon Hearnthe first character of the character class. 1870519c4ef3SJilles TjoelkerA caret 1871519c4ef3SJilles Tjoelker.Pq Ql ^ 1872519c4ef3SJilles Tjoelkerhas the same effect but is non-standard. 1873ab72124fSSteve Price.Pp 18746b15476eSSheldon HearnTo include a 1875dfe302abSRuslan Ermilov.Ql \&] 1876e6d3cf26SSheldon Hearnin a character class, make it the first character listed 1877e6d3cf26SSheldon Hearn(after the 1878519c4ef3SJilles Tjoelker.Ql \&! 1879519c4ef3SJilles Tjoelkeror 1880519c4ef3SJilles Tjoelker.Ql ^ , 1881e6d3cf26SSheldon Hearnif any). 1882e918fc8fSSheldon HearnTo include a 1883dfe302abSRuslan Ermilov.Ql - , 1884e918fc8fSSheldon Hearnmake it the first or last character listed. 18858eed22b1SJens Schweikhardt.Ss Built-in Commands 188625f6b31fSJilles TjoelkerThis section lists the built-in commands. 188781e9cda2SRuslan Ermilov.Bl -tag -width indent 1888d0353b83SRuslan Ermilov.It Ic \&: 1889aa9caaf6SPeter WemmA null command that returns a 0 (true) exit value. 1890d0353b83SRuslan Ermilov.It Ic \&. Ar file 1891aa9caaf6SPeter WemmThe commands in the specified file are read and executed by the shell. 18924ad8968aSBrian FeldmanThe 18934ad8968aSBrian Feldman.Ic return 18944ad8968aSBrian Feldmancommand may be used to return to the 18954ad8968aSBrian Feldman.Ic \&. 18964ad8968aSBrian Feldmancommand's caller. 18976466945aSJohn PolstraIf 18986466945aSJohn Polstra.Ar file 18996466945aSJohn Polstracontains any 1900dfe302abSRuslan Ermilov.Ql / 1901eccea571SRuslan Ermilovcharacters, it is used as is. 1902eccea571SRuslan ErmilovOtherwise, the shell searches the 19031788b7ffSJilles Tjoelker.Va PATH 1904eccea571SRuslan Ermilovfor the file. 1905eccea571SRuslan ErmilovIf it is not found in the 19061788b7ffSJilles Tjoelker.Va PATH , 19076466945aSJohn Polstrait is sought in the current working directory. 190810845922SYaroslav Tykhiy.It Ic \&[ 190910845922SYaroslav TykhiyA built-in equivalent of 191010845922SYaroslav Tykhiy.Xr test 1 . 1911a886288eSJesus R. Camou.It Ic alias Oo Ar name Ns Oo = Ns Ar string Oc ... Oc 191249e11e3aSSheldon HearnIf 1913d0353b83SRuslan Ermilov.Ar name Ns = Ns Ar string 191449e11e3aSSheldon Hearnis specified, the shell defines the alias 191549e11e3aSSheldon Hearn.Ar name 19166b15476eSSheldon Hearnwith value 191749e11e3aSSheldon Hearn.Ar string . 19186b15476eSSheldon HearnIf just 191949e11e3aSSheldon Hearn.Ar name 19206b15476eSSheldon Hearnis specified, the value of the alias 192149e11e3aSSheldon Hearn.Ar name 19226b15476eSSheldon Hearnis printed. 192349e11e3aSSheldon HearnWith no arguments, the 192449e11e3aSSheldon Hearn.Ic alias 19258eed22b1SJens Schweikhardtbuilt-in command prints the names and values of all defined aliases 192649e11e3aSSheldon Hearn(see 192749e11e3aSSheldon Hearn.Ic unalias ) . 1928e5341cbbSTim J. RobbinsAlias values are written with appropriate quoting so that they are 19299ba31ca0SRuslan Ermilovsuitable for re-input to the shell. 1930a886288eSJesus R. CamouAlso see the 1931a886288eSJesus R. Camou.Sx Aliases 1932a886288eSJesus R. Camousubsection. 193349e11e3aSSheldon Hearn.It Ic bg Op Ar job ... 193449e11e3aSSheldon HearnContinue the specified jobs 193549e11e3aSSheldon Hearn(or the current job if no jobs are given) 193649e11e3aSSheldon Hearnin the background. 193725f6b31fSJilles Tjoelker.It Ic bind Oo Fl aeklrsv Oc Oo Ar key Oo Ar command Oc Oc 193825f6b31fSJilles TjoelkerList or alter key bindings for the line editor. 193925f6b31fSJilles TjoelkerThis command is documented in 194025f6b31fSJilles Tjoelker.Xr editrc 5 . 194125f6b31fSJilles Tjoelker.It Ic break Op Ar num 194225f6b31fSJilles TjoelkerSee the 194325f6b31fSJilles Tjoelker.Sx Flow-Control Constructs 194425f6b31fSJilles Tjoelkersubsection. 1945df9e587bSTim J. Robbins.It Ic builtin Ar cmd Op Ar arg ... 19468eed22b1SJens SchweikhardtExecute the specified built-in command, 194749e11e3aSSheldon Hearn.Ar cmd . 194849e11e3aSSheldon HearnThis is useful when the user wishes to override a shell function 19498eed22b1SJens Schweikhardtwith the same name as a built-in command. 1950d6ee26adSJilles Tjoelker.It Ic cd Oo Fl L | P Oc Oo Fl e Oc Op Ar directory 19517b6779b6SJilles Tjoelker.It Ic cd Fl 195249e11e3aSSheldon HearnSwitch to the specified 195349e11e3aSSheldon Hearn.Ar directory , 19547b6779b6SJilles Tjoelkerto the directory specified in the 19551788b7ffSJilles Tjoelker.Va HOME 195649e11e3aSSheldon Hearnenvironment variable if no 195749e11e3aSSheldon Hearn.Ar directory 19587b6779b6SJilles Tjoelkeris specified or 19597b6779b6SJilles Tjoelkerto the directory specified in the 19607b6779b6SJilles Tjoelker.Va OLDPWD 19617b6779b6SJilles Tjoelkerenvironment variable if 19627b6779b6SJilles Tjoelker.Ar directory 19637b6779b6SJilles Tjoelkeris 19647b6779b6SJilles Tjoelker.Fl . 196549e11e3aSSheldon HearnIf 196649e11e3aSSheldon Hearn.Ar directory 1967029c8ee4STim J. Robbinsdoes not begin with 19689ba31ca0SRuslan Ermilov.Pa / , \&. , 196949e11e3aSSheldon Hearnor 1970029c8ee4STim J. Robbins.Pa .. , 197149e11e3aSSheldon Hearnthen the directories listed in the 19721788b7ffSJilles Tjoelker.Va CDPATH 197349e11e3aSSheldon Hearnvariable will be 197449e11e3aSSheldon Hearnsearched for the specified 197549e11e3aSSheldon Hearn.Ar directory . 1976029c8ee4STim J. RobbinsIf 19771788b7ffSJilles Tjoelker.Va CDPATH 1978029c8ee4STim J. Robbinsis unset, the current directory is searched. 197949e11e3aSSheldon HearnThe format of 19801788b7ffSJilles Tjoelker.Va CDPATH 198149e11e3aSSheldon Hearnis the same as that of 19821788b7ffSJilles Tjoelker.Va PATH . 1983e6d3cf26SSheldon HearnIn an interactive shell, 198449e11e3aSSheldon Hearnthe 198549e11e3aSSheldon Hearn.Ic cd 198649e11e3aSSheldon Hearncommand will print out the name of the directory 1987e6d3cf26SSheldon Hearnthat it actually switched to 19887b6779b6SJilles Tjoelkerif the 19891788b7ffSJilles Tjoelker.Va CDPATH 19907b6779b6SJilles Tjoelkermechanism was used or if 19917b6779b6SJilles Tjoelker.Ar directory 19927b6779b6SJilles Tjoelkerwas 19937b6779b6SJilles Tjoelker.Fl . 1994178897f1STim J. Robbins.Pp 1995178897f1STim J. RobbinsIf the 1996178897f1STim J. Robbins.Fl P 1997178897f1STim J. Robbinsoption is specified, 199881e9cda2SRuslan Ermilov.Pa .. 1999178897f1STim J. Robbinsis handled physically and symbolic links are resolved before 200081e9cda2SRuslan Ermilov.Pa .. 2001178897f1STim J. Robbinscomponents are processed. 2002178897f1STim J. RobbinsIf the 2003178897f1STim J. Robbins.Fl L 2004178897f1STim J. Robbinsoption is specified, 200581e9cda2SRuslan Ermilov.Pa .. 2006178897f1STim J. Robbinsis handled logically. 2007178897f1STim J. RobbinsThis is the default. 2008d6ee26adSJilles Tjoelker.Pp 2009d6ee26adSJilles TjoelkerThe 2010d6ee26adSJilles Tjoelker.Fl e 2011d6ee26adSJilles Tjoelkeroption causes 2012d6ee26adSJilles Tjoelker.Ic cd 2013d6ee26adSJilles Tjoelkerto return exit status 1 if the full pathname of the new directory 2014d6ee26adSJilles Tjoelkercannot be determined reliably or at all. 2015d6ee26adSJilles TjoelkerNormally this is not considered an error, 2016d6ee26adSJilles Tjoelkeralthough a warning is printed. 20176f49cd26SJilles Tjoelker.Pp 20186f49cd26SJilles TjoelkerIf changing the directory fails, the exit status is greater than 1. 20196f49cd26SJilles TjoelkerIf the directory is changed, the exit status is 0, or also 1 if 20206f49cd26SJilles Tjoelker.Fl e 20216f49cd26SJilles Tjoelkerwas given. 20229434a1c7SDima Dorfman.It Ic chdir 20239434a1c7SDima DorfmanA synonym for the 20249434a1c7SDima Dorfman.Ic cd 20258eed22b1SJens Schweikhardtbuilt-in command. 20269ba31ca0SRuslan Ermilov.It Ic command Oo Fl p Oc Op Ar utility Op Ar argument ... 2027b97d13b3SJilles Tjoelker.It Ic command Oo Fl p Oc Fl v Ar utility 2028b97d13b3SJilles Tjoelker.It Ic command Oo Fl p Oc Fl V Ar utility 202933b222b9SStefan FarfelederThe first form of invocation executes the specified 2030c848bc18SJilles Tjoelker.Ar utility , 2031c848bc18SJilles Tjoelkerignoring shell functions in the search. 2032c848bc18SJilles TjoelkerIf 20332babaf74STim J. Robbins.Ar utility 2034c848bc18SJilles Tjoelkeris a special builtin, 2035c848bc18SJilles Tjoelkerit is executed as if it were a regular builtin. 20362babaf74STim J. Robbins.Pp 20372babaf74STim J. RobbinsIf the 20382babaf74STim J. Robbins.Fl p 20392babaf74STim J. Robbinsoption is specified, the command search is performed using a 20402babaf74STim J. Robbinsdefault value of 20411788b7ffSJilles Tjoelker.Va PATH 20422babaf74STim J. Robbinsthat is guaranteed to find all of the standard utilities. 204333b222b9SStefan Farfeleder.Pp 204433b222b9SStefan FarfelederIf the 204533b222b9SStefan Farfeleder.Fl v 204633b222b9SStefan Farfelederoption is specified, 204733b222b9SStefan Farfeleder.Ar utility 204833b222b9SStefan Farfelederis not executed but a description of its interpretation by the shell is 204933b222b9SStefan Farfelederprinted. 205033b222b9SStefan FarfelederFor ordinary commands the output is the path name; for shell built-in 205133b222b9SStefan Farfeledercommands, shell functions and keywords only the name is written. 205233b222b9SStefan FarfelederAliases are printed as 205333b222b9SStefan Farfeleder.Dq Ic alias Ar name Ns = Ns Ar value . 205433b222b9SStefan Farfeleder.Pp 205533b222b9SStefan FarfelederThe 205633b222b9SStefan Farfeleder.Fl V 205733b222b9SStefan Farfelederoption is identical to 205833b222b9SStefan Farfeleder.Fl v 205933b222b9SStefan Farfelederexcept for the output. 206033b222b9SStefan FarfelederIt prints 206133b222b9SStefan Farfeleder.Dq Ar utility Ic is Ar description 206233b222b9SStefan Farfelederwhere 206333b222b9SStefan Farfeleder.Ar description 206433b222b9SStefan Farfelederis either 206533b222b9SStefan Farfelederthe path name to 206633b222b9SStefan Farfeleder.Ar utility , 206730268dfaSJilles Tjoelkera special shell builtin, 20688af11131SRuslan Ermilova shell builtin, 20698af11131SRuslan Ermilova shell function, 20708af11131SRuslan Ermilova shell keyword 207133b222b9SStefan Farfelederor 20728af11131SRuslan Ermilovan alias for 20738af11131SRuslan Ermilov.Ar value . 207425f6b31fSJilles Tjoelker.It Ic continue Op Ar num 207525f6b31fSJilles TjoelkerSee the 207625f6b31fSJilles Tjoelker.Sx Flow-Control Constructs 207725f6b31fSJilles Tjoelkersubsection. 207873313421SStefan Farfeleder.It Ic echo Oo Fl e | n Oc Op Ar string ... 207973313421SStefan FarfelederPrint a space-separated list of the arguments to the standard output 208073313421SStefan Farfelederand append a newline character. 208181e9cda2SRuslan Ermilov.Bl -tag -width indent 2082501e74b7SMark Ovens.It Fl n 2083501e74b7SMark OvensSuppress the output of the trailing newline. 2084501e74b7SMark Ovens.It Fl e 2085501e74b7SMark OvensProcess C-style backslash escape sequences. 2086dfe302abSRuslan ErmilovThe 2087501e74b7SMark Ovens.Ic echo 2088dfe302abSRuslan Ermilovcommand understands the following character escapes: 208981e9cda2SRuslan Ermilov.Bl -tag -width indent 2090501e74b7SMark Ovens.It \ea 2091501e74b7SMark OvensAlert (ring the terminal bell) 2092501e74b7SMark Ovens.It \eb 2093501e74b7SMark OvensBackspace 2094501e74b7SMark Ovens.It \ec 2095501e74b7SMark OvensSuppress the trailing newline (this has the side-effect of truncating the 2096501e74b7SMark Ovensline if it is not the last character) 2097501e74b7SMark Ovens.It \ee 209817e98da8SMateusz PiotrowskiThe ESC character (ASCII 0x1b) 2099501e74b7SMark Ovens.It \ef 2100501e74b7SMark OvensFormfeed 2101501e74b7SMark Ovens.It \en 2102501e74b7SMark OvensNewline 2103501e74b7SMark Ovens.It \er 2104501e74b7SMark OvensCarriage return 2105501e74b7SMark Ovens.It \et 2106501e74b7SMark OvensHorizontal tab 2107501e74b7SMark Ovens.It \ev 2108501e74b7SMark OvensVertical tab 2109501e74b7SMark Ovens.It \e\e 2110501e74b7SMark OvensLiteral backslash 2111501e74b7SMark Ovens.It \e0nnn 2112dfe302abSRuslan Ermilov(Zero) The character whose octal value is 2113dfe302abSRuslan Ermilov.Ar nnn 2114501e74b7SMark Ovens.El 2115501e74b7SMark Ovens.Pp 2116501e74b7SMark OvensIf 2117501e74b7SMark Ovens.Ar string 2118501e74b7SMark Ovensis not enclosed in quotes then the backslash itself must be escaped 2119eccea571SRuslan Ermilovwith a backslash to protect it from the shell. 2120eccea571SRuslan ErmilovFor example 2121501e74b7SMark Ovens.Bd -literal -offset indent 2122501e74b7SMark Ovens$ echo -e "a\evb" 2123501e74b7SMark Ovensa 2124501e74b7SMark Ovens b 2125501e74b7SMark Ovens$ echo -e a\e\evb 2126501e74b7SMark Ovensa 2127501e74b7SMark Ovens b 2128501e74b7SMark Ovens$ echo -e "a\e\eb" 2129501e74b7SMark Ovensa\eb 2130501e74b7SMark Ovens$ echo -e a\e\e\e\eb 2131501e74b7SMark Ovensa\eb 2132501e74b7SMark Ovens.Ed 2133501e74b7SMark Ovens.El 2134558175caSTim J. Robbins.Pp 2135558175caSTim J. RobbinsOnly one of the 2136558175caSTim J. Robbins.Fl e 2137558175caSTim J. Robbinsand 2138558175caSTim J. Robbins.Fl n 2139558175caSTim J. Robbinsoptions may be specified. 214049e11e3aSSheldon Hearn.It Ic eval Ar string ... 2141e6d3cf26SSheldon HearnConcatenate all the arguments with spaces. 2142e6d3cf26SSheldon HearnThen re-parse and execute the command. 214349e11e3aSSheldon Hearn.It Ic exec Op Ar command Op arg ... 214449e11e3aSSheldon HearnUnless 214549e11e3aSSheldon Hearn.Ar command 214649e11e3aSSheldon Hearnis omitted, 214749e11e3aSSheldon Hearnthe shell process is replaced with the specified program 21488eed22b1SJens Schweikhardt(which must be a real program, not a shell built-in command or function). 214949e11e3aSSheldon HearnAny redirections on the 215049e11e3aSSheldon Hearn.Ic exec 215149e11e3aSSheldon Hearncommand are marked as permanent, 215249e11e3aSSheldon Hearnso that they are not undone when the 215349e11e3aSSheldon Hearn.Ic exec 215449e11e3aSSheldon Hearncommand finishes. 215549e11e3aSSheldon Hearn.It Ic exit Op Ar exitstatus 215649e11e3aSSheldon HearnTerminate the shell process. 215749e11e3aSSheldon HearnIf 215849e11e3aSSheldon Hearn.Ar exitstatus 215949e11e3aSSheldon Hearnis given 2160ea381e69SJilles Tjoelkerit is used as the exit status of the shell. 2161ea381e69SJilles TjoelkerOtherwise, if the shell is executing an 2162421fb021SJilles Tjoelker.Cm EXIT 2163421fb021SJilles Tjoelkertrap, the exit status of the last command before the trap is used; 2164421fb021SJilles Tjoelkerif the shell is executing a trap for a signal, 2165ea381e69SJilles Tjoelkerthe shell exits by resending the signal to itself. 2166ea381e69SJilles TjoelkerOtherwise, the exit status of the preceding command is used. 2167a68fbc44SJilles TjoelkerThe exit status should be an integer between 0 and 255. 2168ef9791a3SStefan Farfeleder.It Ic export Ar name ... 2169ef9791a3SStefan Farfeleder.It Ic export Op Fl p 21704b88c807SRodney W. GrimesThe specified names are exported so that they will 21714b88c807SRodney W. Grimesappear in the environment of subsequent commands. 217249e11e3aSSheldon HearnThe only way to un-export a variable is to 217349e11e3aSSheldon Hearn.Ic unset 217449e11e3aSSheldon Hearnit. 217549e11e3aSSheldon HearnThe shell allows the value of a variable to be set 217649e11e3aSSheldon Hearnat the same time as it is exported by writing 2177ab72124fSSteve Price.Pp 2178dfe302abSRuslan Ermilov.D1 Ic export Ar name Ns = Ns Ar value 2179dfe302abSRuslan Ermilov.Pp 2180dfe302abSRuslan ErmilovWith no arguments the 2181dfe302abSRuslan Ermilov.Ic export 2182dfe302abSRuslan Ermilovcommand lists the names 21834b88c807SRodney W. Grimesof all exported variables. 218445086f8cSTim J. RobbinsIf the 218545086f8cSTim J. Robbins.Fl p 218645086f8cSTim J. Robbinsoption is specified, the exported variables are printed as 218745086f8cSTim J. Robbins.Dq Ic export Ar name Ns = Ns Ar value 218845086f8cSTim J. Robbinslines, suitable for re-input to the shell. 2189a6557dcbSYaroslav Tykhiy.It Ic false 2190a6557dcbSYaroslav TykhiyA null command that returns a non-zero (false) exit value. 219181e9cda2SRuslan Ermilov.It Ic fc Oo Fl e Ar editor Oc Op Ar first Op Ar last 219281e9cda2SRuslan Ermilov.It Ic fc Fl l Oo Fl nr Oc Op Ar first Op Ar last 219381e9cda2SRuslan Ermilov.It Ic fc Fl s Oo Ar old Ns = Ns Ar new Oc Op Ar first 219449e11e3aSSheldon HearnThe 219549e11e3aSSheldon Hearn.Ic fc 21968eed22b1SJens Schweikhardtbuilt-in command lists, or edits and re-executes, 219749e11e3aSSheldon Hearncommands previously entered to an interactive shell. 219881e9cda2SRuslan Ermilov.Bl -tag -width indent 219949e11e3aSSheldon Hearn.It Fl e Ar editor 220049e11e3aSSheldon HearnUse the editor named by 220149e11e3aSSheldon Hearn.Ar editor 220249e11e3aSSheldon Hearnto edit the commands. 2203dfe302abSRuslan ErmilovThe 2204dfe302abSRuslan Ermilov.Ar editor 2205dfe302abSRuslan Ermilovstring is a command name, 220649e11e3aSSheldon Hearnsubject to search via the 22071788b7ffSJilles Tjoelker.Va PATH 220849e11e3aSSheldon Hearnvariable. 220949e11e3aSSheldon HearnThe value in the 22101788b7ffSJilles Tjoelker.Va FCEDIT 221149e11e3aSSheldon Hearnvariable is used as a default when 221249e11e3aSSheldon Hearn.Fl e 221349e11e3aSSheldon Hearnis not specified. 221449e11e3aSSheldon HearnIf 22151788b7ffSJilles Tjoelker.Va FCEDIT 221649e11e3aSSheldon Hearnis null or unset, the value of the 22171788b7ffSJilles Tjoelker.Va EDITOR 221849e11e3aSSheldon Hearnvariable is used. 221949e11e3aSSheldon HearnIf 22201788b7ffSJilles Tjoelker.Va EDITOR 222149e11e3aSSheldon Hearnis null or unset, 2222ab72124fSSteve Price.Xr ed 1 2223ab72124fSSteve Priceis used as the editor. 222449e11e3aSSheldon Hearn.It Fl l No (ell) 22254b88c807SRodney W. GrimesList the commands rather than invoking 2226eccea571SRuslan Ermilovan editor on them. 2227eccea571SRuslan ErmilovThe commands are written in the 2228dfe302abSRuslan Ermilovsequence indicated by the 2229dfe302abSRuslan Ermilov.Ar first 2230dfe302abSRuslan Ermilovand 2231dfe302abSRuslan Ermilov.Ar last 2232dfe302abSRuslan Ermilovoperands, as affected by 223349e11e3aSSheldon Hearn.Fl r , 223449e11e3aSSheldon Hearnwith each command preceded by the command number. 223549e11e3aSSheldon Hearn.It Fl n 223649e11e3aSSheldon HearnSuppress command numbers when listing with 223749e11e3aSSheldon Hearn.Fl l . 223849e11e3aSSheldon Hearn.It Fl r 223949e11e3aSSheldon HearnReverse the order of the commands listed 224049e11e3aSSheldon Hearn(with 224149e11e3aSSheldon Hearn.Fl l ) 224249e11e3aSSheldon Hearnor edited 224349e11e3aSSheldon Hearn(with neither 224449e11e3aSSheldon Hearn.Fl l 224549e11e3aSSheldon Hearnnor 224649e11e3aSSheldon Hearn.Fl s ) . 224749e11e3aSSheldon Hearn.It Fl s 22484b88c807SRodney W. GrimesRe-execute the command without invoking an editor. 224949e11e3aSSheldon Hearn.It Ar first 225049e11e3aSSheldon Hearn.It Ar last 225149e11e3aSSheldon HearnSelect the commands to list or edit. 225249e11e3aSSheldon HearnThe number of previous commands that can be accessed 225349e11e3aSSheldon Hearnare determined by the value of the 22541788b7ffSJilles Tjoelker.Va HISTSIZE 2255d0353b83SRuslan Ermilovvariable. 225649e11e3aSSheldon HearnThe value of 225749e11e3aSSheldon Hearn.Ar first 225849e11e3aSSheldon Hearnor 225949e11e3aSSheldon Hearn.Ar last 226049e11e3aSSheldon Hearnor both are one of the following: 226181e9cda2SRuslan Ermilov.Bl -tag -width indent 2262dfe302abSRuslan Ermilov.It Oo Cm + Oc Ns Ar num 226349e11e3aSSheldon HearnA positive number representing a command number; 226449e11e3aSSheldon Hearncommand numbers can be displayed with the 226549e11e3aSSheldon Hearn.Fl l 226649e11e3aSSheldon Hearnoption. 2267dfe302abSRuslan Ermilov.It Fl Ar num 226849e11e3aSSheldon HearnA negative decimal number representing the 226949e11e3aSSheldon Hearncommand that was executed 227049e11e3aSSheldon Hearn.Ar num 227149e11e3aSSheldon Hearnof 227249e11e3aSSheldon Hearncommands previously. 2273dfe302abSRuslan ErmilovFor example, \-1 is the immediately previous command. 227449e11e3aSSheldon Hearn.It Ar string 227549e11e3aSSheldon HearnA string indicating the most recently entered command 227649e11e3aSSheldon Hearnthat begins with that string. 227749e11e3aSSheldon HearnIf the 2278dfe302abSRuslan Ermilov.Ar old Ns = Ns Ar new 227949e11e3aSSheldon Hearnoperand is not also specified with 228049e11e3aSSheldon Hearn.Fl s , 228149e11e3aSSheldon Hearnthe string form of the first operand cannot contain an embedded equal sign. 228249e11e3aSSheldon Hearn.El 228349e11e3aSSheldon Hearn.El 228449e11e3aSSheldon Hearn.Pp 22851788b7ffSJilles TjoelkerThe following variables affect the execution of 228649e11e3aSSheldon Hearn.Ic fc : 22871788b7ffSJilles Tjoelker.Bl -tag -width ".Va HISTSIZE" 22881788b7ffSJilles Tjoelker.It Va FCEDIT 228938afdcbcSGiorgos KeramidasName of the editor to use for history editing. 22901788b7ffSJilles Tjoelker.It Va HISTSIZE 22913d7b5b93SPhilippe CharnierThe number of previous commands that are accessible. 2292ab72124fSSteve Price.El 229349e11e3aSSheldon Hearn.It Ic fg Op Ar job 229449e11e3aSSheldon HearnMove the specified 229549e11e3aSSheldon Hearn.Ar job 229649e11e3aSSheldon Hearnor the current job to the foreground. 2297dfe302abSRuslan Ermilov.It Ic getopts Ar optstring var 229817e98da8SMateusz PiotrowskiThe POSIX 229949e11e3aSSheldon Hearn.Ic getopts 230049e11e3aSSheldon Hearncommand. 230149e11e3aSSheldon HearnThe 230249e11e3aSSheldon Hearn.Ic getopts 230349e11e3aSSheldon Hearncommand deprecates the older 230449e11e3aSSheldon Hearn.Xr getopt 1 230549e11e3aSSheldon Hearncommand. 2306ab0a2172SSteve PriceThe first argument should be a series of letters, each possibly 2307ab0a2172SSteve Pricefollowed by a colon which indicates that the option takes an argument. 2308eccea571SRuslan ErmilovThe specified variable is set to the parsed option. 2309eccea571SRuslan ErmilovThe index of 231049e11e3aSSheldon Hearnthe next argument is placed into the shell variable 2311dfe302abSRuslan Ermilov.Va OPTIND . 2312ab0a2172SSteve PriceIf an option takes an argument, it is placed into the shell variable 2313dfe302abSRuslan Ermilov.Va OPTARG . 231449e11e3aSSheldon HearnIf an invalid option is encountered, 2315dfe302abSRuslan Ermilov.Ar var 231649e11e3aSSheldon Hearnis set to 2317dfe302abSRuslan Ermilov.Ql \&? . 2318ab0a2172SSteve PriceIt returns a false value (1) when it encounters the end of the options. 23194445af21SJilles TjoelkerA new set of arguments may be parsed by assigning 23204445af21SJilles Tjoelker.Li OPTIND=1 . 232181e9cda2SRuslan Ermilov.It Ic hash Oo Fl rv Oc Op Ar command ... 232249e11e3aSSheldon HearnThe shell maintains a hash table which remembers the locations of commands. 232349e11e3aSSheldon HearnWith no arguments whatsoever, the 232449e11e3aSSheldon Hearn.Ic hash 232549e11e3aSSheldon Hearncommand prints out the contents of this table. 2326ab72124fSSteve Price.Pp 232749e11e3aSSheldon HearnWith arguments, the 232849e11e3aSSheldon Hearn.Ic hash 232949e11e3aSSheldon Hearncommand removes each specified 233049e11e3aSSheldon Hearn.Ar command 233149e11e3aSSheldon Hearnfrom the hash table (unless they are functions) and then locates it. 233249e11e3aSSheldon HearnWith the 233349e11e3aSSheldon Hearn.Fl v 233449e11e3aSSheldon Hearnoption, 233549e11e3aSSheldon Hearn.Ic hash 233649e11e3aSSheldon Hearnprints the locations of the commands as it finds them. 233749e11e3aSSheldon HearnThe 233849e11e3aSSheldon Hearn.Fl r 233949e11e3aSSheldon Hearnoption causes the 234049e11e3aSSheldon Hearn.Ic hash 234149e11e3aSSheldon Hearncommand to delete all the entries in the hash table except for functions. 234249e11e3aSSheldon Hearn.It Ic jobid Op Ar job 2343dfe302abSRuslan ErmilovPrint the process IDs of the processes in the specified 234449e11e3aSSheldon Hearn.Ar job . 234549e11e3aSSheldon HearnIf the 234649e11e3aSSheldon Hearn.Ar job 234749e11e3aSSheldon Hearnargument is omitted, use the current job. 2348de37e41cSStefan Farfeleder.It Ic jobs Oo Fl lps Oc Op Ar job ... 2349ad8a0759STim J. RobbinsPrint information about the specified jobs, or all jobs if no 2350ad8a0759STim J. Robbins.Ar job 2351ad8a0759STim J. Robbinsargument is given. 2352ad8a0759STim J. RobbinsThe information printed includes job ID, status and command name. 2353ad8a0759STim J. Robbins.Pp 2354ad8a0759STim J. RobbinsIf the 2355ad8a0759STim J. Robbins.Fl l 2356ad8a0759STim J. Robbinsoption is specified, the PID of each job is also printed. 2357ad8a0759STim J. RobbinsIf the 2358de37e41cSStefan Farfeleder.Fl p 2359de37e41cSStefan Farfelederoption is specified, only the process IDs for the process group leaders 2360de37e41cSStefan Farfelederare printed, one per line. 2361de37e41cSStefan FarfelederIf the 2362ad8a0759STim J. Robbins.Fl s 2363de37e41cSStefan Farfelederoption is specified, only the PIDs of the job commands are printed, one per 2364de37e41cSStefan Farfelederline. 23650a62a9caSJilles Tjoelker.It Ic kill 23660a62a9caSJilles TjoelkerA built-in equivalent of 23670a62a9caSJilles Tjoelker.Xr kill 1 23680a62a9caSJilles Tjoelkerthat additionally supports sending signals to jobs. 23698af11131SRuslan Ermilov.It Ic local Oo Ar variable ... Oc Op Fl 2370d2f90294SJesus R. CamouSee the 2371d2f90294SJesus R. Camou.Sx Functions 2372d2f90294SJesus R. Camousubsection. 23739897c45fSJilles Tjoelker.It Ic printf 23749897c45fSJilles TjoelkerA built-in equivalent of 23759897c45fSJilles Tjoelker.Xr printf 1 . 2376d74e011fSRuslan Ermilov.It Ic pwd Op Fl L | P 2377eccea571SRuslan ErmilovPrint the path of the current directory. 2378eccea571SRuslan ErmilovThe built-in command may 23794b88c807SRodney W. Grimesdiffer from the program of the same name because the 23808eed22b1SJens Schweikhardtbuilt-in command remembers what the current directory 2381eccea571SRuslan Ermilovis rather than recomputing it each time. 2382eccea571SRuslan ErmilovThis makes 2383eccea571SRuslan Ermilovit faster. 2384eccea571SRuslan ErmilovHowever, if the current directory is 238549e11e3aSSheldon Hearnrenamed, 23868eed22b1SJens Schweikhardtthe built-in version of 238749e11e3aSSheldon Hearn.Xr pwd 1 238849e11e3aSSheldon Hearnwill continue to print the old name for the directory. 2389178897f1STim J. Robbins.Pp 2390178897f1STim J. RobbinsIf the 2391178897f1STim J. Robbins.Fl P 2392178897f1STim J. Robbinsoption is specified, symbolic links are resolved. 2393178897f1STim J. RobbinsIf the 2394178897f1STim J. Robbins.Fl L 2395178897f1STim J. Robbinsoption is specified, the shell's notion of the current directory 2396178897f1STim J. Robbinsis printed (symbolic links are not resolved). 2397178897f1STim J. RobbinsThis is the default. 2398dfe302abSRuslan Ermilov.It Ic read Oo Fl p Ar prompt Oc Oo 2399dfe302abSRuslan Ermilov.Fl t Ar timeout Oc Oo Fl er Oc Ar variable ... 240049e11e3aSSheldon HearnThe 240149e11e3aSSheldon Hearn.Ar prompt 240249e11e3aSSheldon Hearnis printed if the 240349e11e3aSSheldon Hearn.Fl p 240449e11e3aSSheldon Hearnoption is specified 2405eccea571SRuslan Ermilovand the standard input is a terminal. 2406eccea571SRuslan ErmilovThen a line is 2407eccea571SRuslan Ermilovread from the standard input. 2408eccea571SRuslan ErmilovThe trailing newline 24094b88c807SRodney W. Grimesis deleted from the line and the line is split as 241049e11e3aSSheldon Hearndescribed in the section on 241117e98da8SMateusz Piotrowski.Sx White Space Splitting (Field Splitting)\& 241249e11e3aSSheldon Hearnabove, and 24134b88c807SRodney W. Grimesthe pieces are assigned to the variables in order. 2414f434d1dfSAdam DavidIf there are more pieces than variables, the remaining 241549e11e3aSSheldon Hearnpieces (along with the characters in 2416dfe302abSRuslan Ermilov.Va IFS 241749e11e3aSSheldon Hearnthat separated them) 241849e11e3aSSheldon Hearnare assigned to the last variable. 2419f434d1dfSAdam DavidIf there are more variables than pieces, the remaining 2420f434d1dfSAdam Davidvariables are assigned the null string. 2421ab72124fSSteve Price.Pp 242249e11e3aSSheldon HearnBackslashes are treated specially, unless the 242349e11e3aSSheldon Hearn.Fl r 242449e11e3aSSheldon Hearnoption is 2425eccea571SRuslan Ermilovspecified. 2426eccea571SRuslan ErmilovIf a backslash is followed by 24278f0561ccSThomas Gellekuma newline, the backslash and the newline will be 2428eccea571SRuslan Ermilovdeleted. 2429eccea571SRuslan ErmilovIf a backslash is followed by any other 24308f0561ccSThomas Gellekumcharacter, the backslash will be deleted and the following 243149e11e3aSSheldon Hearncharacter will be treated as though it were not in 2432dfe302abSRuslan Ermilov.Va IFS , 243349e11e3aSSheldon Hearneven if it is. 24348f0561ccSThomas Gellekum.Pp 243549e11e3aSSheldon HearnIf the 243649e11e3aSSheldon Hearn.Fl t 243749e11e3aSSheldon Hearnoption is specified and the 243849e11e3aSSheldon Hearn.Ar timeout 2439fe40d6d3SJilles Tjoelkerelapses before a complete line of input is supplied, 244049e11e3aSSheldon Hearnthe 244149e11e3aSSheldon Hearn.Ic read 2442c4539460SJilles Tjoelkercommand will return an exit status as if terminated by 2443c4539460SJilles Tjoelker.Dv SIGALRM 2444c4539460SJilles Tjoelkerwithout assigning any values. 244549e11e3aSSheldon HearnThe 244649e11e3aSSheldon Hearn.Ar timeout 244749e11e3aSSheldon Hearnvalue may optionally be followed by one of 2448dfe302abSRuslan Ermilov.Ql s , 2449dfe302abSRuslan Ermilov.Ql m 245049e11e3aSSheldon Hearnor 2451dfe302abSRuslan Ermilov.Ql h 2452a910f192SDima Dorfmanto explicitly specify seconds, minutes or hours. 245349e11e3aSSheldon HearnIf none is supplied, 2454dfe302abSRuslan Ermilov.Ql s 245549e11e3aSSheldon Hearnis assumed. 2456afa53c8dSMike Smith.Pp 245749e11e3aSSheldon HearnThe 245849e11e3aSSheldon Hearn.Fl e 245949e11e3aSSheldon Hearnoption exists only for backward compatibility with older scripts. 2460c4539460SJilles Tjoelker.Pp 2461c4539460SJilles TjoelkerThe exit status is 0 on success, 1 on end of file, 2462c4539460SJilles Tjoelkerbetween 2 and 128 if an error occurs 2463c4539460SJilles Tjoelkerand greater than 128 if a trapped signal interrupts 2464c4539460SJilles Tjoelker.Ic read . 24659ba31ca0SRuslan Ermilov.It Ic readonly Oo Fl p Oc Op Ar name ... 246649e11e3aSSheldon HearnEach specified 246749e11e3aSSheldon Hearn.Ar name 246849e11e3aSSheldon Hearnis marked as read only, 246949e11e3aSSheldon Hearnso that it cannot be subsequently modified or unset. 247049e11e3aSSheldon HearnThe shell allows the value of a variable to be set 247149e11e3aSSheldon Hearnat the same time as it is marked read only 247249e11e3aSSheldon Hearnby using the following form: 2473dfe302abSRuslan Ermilov.Pp 2474dfe302abSRuslan Ermilov.D1 Ic readonly Ar name Ns = Ns Ar value 2475ab72124fSSteve Price.Pp 247649e11e3aSSheldon HearnWith no arguments the 247749e11e3aSSheldon Hearn.Ic readonly 247849e11e3aSSheldon Hearncommand lists the names of all read only variables. 247945086f8cSTim J. RobbinsIf the 248045086f8cSTim J. Robbins.Fl p 248145086f8cSTim J. Robbinsoption is specified, the read-only variables are printed as 248245086f8cSTim J. Robbins.Dq Ic readonly Ar name Ns = Ns Ar value 248345086f8cSTim J. Robbinslines, suitable for re-input to the shell. 2484d2f90294SJesus R. Camou.It Ic return Op Ar exitstatus 2485d2f90294SJesus R. CamouSee the 2486d2f90294SJesus R. Camou.Sx Functions 2487d2f90294SJesus R. Camousubsection. 248881e9cda2SRuslan Ermilov.It Ic set Oo Fl /+abCEefIimnpTuVvx Oc Oo Fl /+o Ar longname Oc Oo 248981e9cda2SRuslan Ermilov.Fl c Ar string Oc Op Fl - Ar arg ... 2490e918fc8fSSheldon HearnThe 2491e918fc8fSSheldon Hearn.Ic set 2492e918fc8fSSheldon Hearncommand performs three different functions: 2493ab72124fSSteve Price.Bl -item 2494ab72124fSSteve Price.It 249549e11e3aSSheldon HearnWith no arguments, it lists the values of all shell variables. 2496ab72124fSSteve Price.It 249749e11e3aSSheldon HearnIf options are given, 249849e11e3aSSheldon Hearneither in short form or using the long 249949e11e3aSSheldon Hearn.Dq Fl /+o Ar longname 250049e11e3aSSheldon Hearnform, 250149e11e3aSSheldon Hearnit sets or clears the specified options as described in the section called 25026b15476eSSheldon Hearn.Sx Argument List Processing . 2503ab72124fSSteve Price.It 250449e11e3aSSheldon HearnIf the 250549e11e3aSSheldon Hearn.Dq Fl - 250649e11e3aSSheldon Hearnoption is specified, 250749e11e3aSSheldon Hearn.Ic set 250849e11e3aSSheldon Hearnwill replace the shell's positional parameters with the subsequent 250949e11e3aSSheldon Hearnarguments. 251049e11e3aSSheldon HearnIf no arguments follow the 251149e11e3aSSheldon Hearn.Dq Fl - 251249e11e3aSSheldon Hearnoption, 251349e11e3aSSheldon Hearnall the positional parameters will be cleared, 251449e11e3aSSheldon Hearnwhich is equivalent to executing the command 2515dfe302abSRuslan Ermilov.Dq Li "shift $#" . 251649e11e3aSSheldon HearnThe 251749e11e3aSSheldon Hearn.Dq Fl - 25188eed22b1SJens Schweikhardtflag may be omitted when specifying arguments to be used 251949e11e3aSSheldon Hearnas positional replacement parameters. 252049e11e3aSSheldon HearnThis is not recommended, 252149e11e3aSSheldon Hearnbecause the first argument may begin with a dash 2522a762afe5SGiorgos Keramidas.Pq Ql - 252349e11e3aSSheldon Hearnor a plus 2524a762afe5SGiorgos Keramidas.Pq Ql + , 252549e11e3aSSheldon Hearnwhich the 252649e11e3aSSheldon Hearn.Ic set 252749e11e3aSSheldon Hearncommand will interpret as a request to enable or disable options. 2528ab72124fSSteve Price.El 2529dfe302abSRuslan Ermilov.It Ic setvar Ar variable value 253049e11e3aSSheldon HearnAssigns the specified 253149e11e3aSSheldon Hearn.Ar value 253249e11e3aSSheldon Hearnto the specified 253349e11e3aSSheldon Hearn.Ar variable . 2534dfe302abSRuslan ErmilovThe 2535dfe302abSRuslan Ermilov.Ic setvar 2536dfe302abSRuslan Ermilovcommand is intended to be used in functions that 2537e6d3cf26SSheldon Hearnassign values to variables whose names are passed as parameters. 253849e11e3aSSheldon HearnIn general it is better to write 2539dfe302abSRuslan Ermilov.Dq Ar variable Ns = Ns Ar value 254049e11e3aSSheldon Hearnrather than using 254149e11e3aSSheldon Hearn.Ic setvar . 254249e11e3aSSheldon Hearn.It Ic shift Op Ar n 254349e11e3aSSheldon HearnShift the positional parameters 254449e11e3aSSheldon Hearn.Ar n 2545e918fc8fSSheldon Hearntimes, or once if 254649e11e3aSSheldon Hearn.Ar n 254749e11e3aSSheldon Hearnis not specified. 2548dfe302abSRuslan ErmilovA shift sets the value of 2549dfe302abSRuslan Ermilov.Li $1 2550dfe302abSRuslan Ermilovto the value of 2551dfe302abSRuslan Ermilov.Li $2 , 2552dfe302abSRuslan Ermilovthe value of 2553dfe302abSRuslan Ermilov.Li $2 2554dfe302abSRuslan Ermilovto the value of 2555dfe302abSRuslan Ermilov.Li $3 , 2556dfe302abSRuslan Ermilovand so on, 2557dfe302abSRuslan Ermilovdecreasing the value of 2558dfe302abSRuslan Ermilov.Li $# 2559dfe302abSRuslan Ermilovby one. 2560945e1562SJilles TjoelkerFor portability, shifting if there are zero positional parameters 2561945e1562SJilles Tjoelkershould be avoided, since the shell may abort. 256210845922SYaroslav Tykhiy.It Ic test 256310845922SYaroslav TykhiyA built-in equivalent of 256410845922SYaroslav Tykhiy.Xr test 1 . 25651974986aSStefan Farfeleder.It Ic times 256651a514adSJilles TjoelkerPrint the amount of time spent executing the shell process and its children. 256751a514adSJilles TjoelkerThe first output line shows the user and system times for the shell process 25681974986aSStefan Farfelederitself, the second one contains the user and system times for the 25691974986aSStefan Farfelederchildren. 257081e9cda2SRuslan Ermilov.It Ic trap Oo Ar action Oc Ar signal ... 25710673e800SStefan Farfeleder.It Ic trap Fl l 257249e11e3aSSheldon HearnCause the shell to parse and execute 257349e11e3aSSheldon Hearn.Ar action 257449e11e3aSSheldon Hearnwhen any specified 257549e11e3aSSheldon Hearn.Ar signal 257649e11e3aSSheldon Hearnis received. 2577162ae3aeSTony FinchThe signals are specified by name or number. 2578162ae3aeSTony FinchIn addition, the pseudo-signal 2579f5d1157fSRuslan Ermilov.Cm EXIT 2580dfe302abSRuslan Ermilovmay be used to specify an 2581dfe302abSRuslan Ermilov.Ar action 2582dfe302abSRuslan Ermilovthat is performed when the shell terminates. 258349e11e3aSSheldon HearnThe 258449e11e3aSSheldon Hearn.Ar action 25850673e800SStefan Farfeledermay be an empty string or a dash 25869badf57fSRuslan Ermilov.Pq Ql - ; 258749e11e3aSSheldon Hearnthe former causes the specified signal to be ignored 258849e11e3aSSheldon Hearnand the latter causes the default action to be taken. 25890673e800SStefan FarfelederOmitting the 25900673e800SStefan Farfeleder.Ar action 2591a59f8174SBryan Dreweryand using only signal numbers is another way to request the default action. 259251a514adSJilles TjoelkerIn a subshell or utility environment, 2593ef89d04fSJilles Tjoelkerthe shell resets trapped (but not ignored) signals to the default action. 259449e11e3aSSheldon HearnThe 259549e11e3aSSheldon Hearn.Ic trap 259649e11e3aSSheldon Hearncommand has no effect on signals that were ignored on entry to the shell. 25970673e800SStefan Farfeleder.Pp 25980673e800SStefan FarfelederOption 25990673e800SStefan Farfeleder.Fl l 26000673e800SStefan Farfeledercauses the 26010673e800SStefan Farfeleder.Ic trap 26020673e800SStefan Farfeledercommand to display a list of valid signal names. 2603a6557dcbSYaroslav Tykhiy.It Ic true 2604a6557dcbSYaroslav TykhiyA null command that returns a 0 (true) exit value. 260549e11e3aSSheldon Hearn.It Ic type Op Ar name ... 260649e11e3aSSheldon HearnInterpret each 260749e11e3aSSheldon Hearn.Ar name 260849e11e3aSSheldon Hearnas a command and print the resolution of the command search. 2609e6d3cf26SSheldon HearnPossible resolutions are: 261030268dfaSJilles Tjoelkershell keyword, alias, special shell builtin, shell builtin, command, 261130268dfaSJilles Tjoelkertracked alias 261249e11e3aSSheldon Hearnand not found. 261349e11e3aSSheldon HearnFor aliases the alias expansion is printed; 261449e11e3aSSheldon Hearnfor commands and tracked aliases 261549e11e3aSSheldon Hearnthe complete pathname of the command is printed. 2616250d9fd8SKonstantin Belousov.It Ic ulimit Oo Fl HSabcdfklmnopstuvw Oc Op Ar limit 2617ab72124fSSteve PriceSet or display resource limits (see 2618ab72124fSSteve Price.Xr getrlimit 2 ) . 26196b15476eSSheldon HearnIf 262049e11e3aSSheldon Hearn.Ar limit 26216b15476eSSheldon Hearnis specified, the named resource will be set; 26227a2afe64SJoerg Wunschotherwise the current resource value will be displayed. 2623ab72124fSSteve Price.Pp 26246b15476eSSheldon HearnIf 262549e11e3aSSheldon Hearn.Fl H 262649e11e3aSSheldon Hearnis specified, the hard limits will be set or displayed. 262749e11e3aSSheldon HearnWhile everybody is allowed to reduce a hard limit, 262849e11e3aSSheldon Hearnonly the superuser can increase it. 262949e11e3aSSheldon HearnThe 263049e11e3aSSheldon Hearn.Fl S 263149e11e3aSSheldon Hearnoption 2632eccea571SRuslan Ermilovspecifies the soft limits instead. 2633eccea571SRuslan ErmilovWhen displaying limits, 26346b15476eSSheldon Hearnonly one of 263549e11e3aSSheldon Hearn.Fl S 26366b15476eSSheldon Hearnor 263749e11e3aSSheldon Hearn.Fl H 263849e11e3aSSheldon Hearncan be given. 263949e11e3aSSheldon HearnThe default is to display the soft limits, 264049e11e3aSSheldon Hearnand to set both the hard and the soft limits. 2641ab72124fSSteve Price.Pp 26426b15476eSSheldon HearnOption 264349e11e3aSSheldon Hearn.Fl a 264449e11e3aSSheldon Hearncauses the 264549e11e3aSSheldon Hearn.Ic ulimit 264649e11e3aSSheldon Hearncommand to display all resources. 264749e11e3aSSheldon HearnThe parameter 264849e11e3aSSheldon Hearn.Ar limit 26496b15476eSSheldon Hearnis not acceptable in this mode. 2650ab72124fSSteve Price.Pp 26517a2afe64SJoerg WunschThe remaining options specify which resource value is to be 265249e11e3aSSheldon Hearndisplayed or modified. 265349e11e3aSSheldon HearnThey are mutually exclusive. 265481e9cda2SRuslan Ermilov.Bl -tag -width indent 26553652a236SMartin Cracauer.It Fl b Ar sbsize 26563652a236SMartin CracauerThe maximum size of socket buffer usage, in bytes. 265749e11e3aSSheldon Hearn.It Fl c Ar coredumpsize 26587a2afe64SJoerg WunschThe maximal size of core dump files, in 512-byte blocks. 265917e98da8SMateusz PiotrowskiSetting 266017e98da8SMateusz Piotrowski.Ar coredumpsize 266117e98da8SMateusz Piotrowskito 0 prevents core dump files from being created. 266249e11e3aSSheldon Hearn.It Fl d Ar datasize 26637a2afe64SJoerg WunschThe maximal size of the data segment of a process, in kilobytes. 266449e11e3aSSheldon Hearn.It Fl f Ar filesize 266549e11e3aSSheldon HearnThe maximal size of a file, in 512-byte blocks. 2666d2c068eaSJilles Tjoelker.It Fl k Ar kqueues 2667d2c068eaSJilles TjoelkerThe maximal number of kqueues 2668d2c068eaSJilles Tjoelker(see 2669d2c068eaSJilles Tjoelker.Xr kqueue 2 ) 2670d2c068eaSJilles Tjoelkerfor this user ID. 267149e11e3aSSheldon Hearn.It Fl l Ar lockedmem 26727a2afe64SJoerg WunschThe maximal size of memory that can be locked by a process, in 26737a2afe64SJoerg Wunschkilobytes. 267449e11e3aSSheldon Hearn.It Fl m Ar memoryuse 26757a2afe64SJoerg WunschThe maximal resident set size of a process, in kilobytes. 267649e11e3aSSheldon Hearn.It Fl n Ar nofiles 26777a2afe64SJoerg WunschThe maximal number of descriptors that could be opened by a process. 2678250d9fd8SKonstantin Belousov.It Fl o Ar umtxp 2679250d9fd8SKonstantin BelousovThe maximal number of process-shared locks 2680250d9fd8SKonstantin Belousov(see 2681250d9fd8SKonstantin Belousov.Xr pthread 3 ) 2682250d9fd8SKonstantin Belousovfor this user ID. 2683331773cdSEd Schouten.It Fl p Ar pseudoterminals 2684331773cdSEd SchoutenThe maximal number of pseudo-terminals for this user ID. 268549e11e3aSSheldon Hearn.It Fl s Ar stacksize 26867a2afe64SJoerg WunschThe maximal size of the stack segment, in kilobytes. 268749e11e3aSSheldon Hearn.It Fl t Ar time 26887a2afe64SJoerg WunschThe maximal amount of CPU time to be used by each process, in seconds. 268949e11e3aSSheldon Hearn.It Fl u Ar userproc 2690ab72124fSSteve PriceThe maximal number of simultaneous processes for this user ID. 269162df9b62SSheldon Hearn.It Fl v Ar virtualmem 26922d41ef4bSMatthew DillonThe maximal virtual size of a process, in kilobytes. 2693c8054a61SJilles Tjoelker.It Fl w Ar swapuse 2694c8054a61SJilles TjoelkerThe maximum amount of swap space reserved or used for this user ID, 2695c8054a61SJilles Tjoelkerin kilobytes. 2696ab72124fSSteve Price.El 2697faa1ed35SStefan Farfeleder.It Ic umask Oo Fl S Oc Op Ar mask 269849e11e3aSSheldon HearnSet the file creation mask (see 2699ab72124fSSteve Price.Xr umask 2 ) 2700faa1ed35SStefan Farfelederto the octal or symbolic (see 2701faa1ed35SStefan Farfeleder.Xr chmod 1 ) 2702faa1ed35SStefan Farfeledervalue specified by 27035d3b843bSSheldon Hearn.Ar mask . 270449e11e3aSSheldon HearnIf the argument is omitted, the current mask value is printed. 2705faa1ed35SStefan FarfelederIf the 2706faa1ed35SStefan Farfeleder.Fl S 2707faa1ed35SStefan Farfelederoption is specified, the output is symbolic, otherwise the output is octal. 2708de4ad382SStefan Farfeleder.It Ic unalias Oo Fl a Oc Op Ar name ... 2709de4ad382SStefan FarfelederThe specified alias names are removed. 27106b15476eSSheldon HearnIf 27111b9735e6SSheldon Hearn.Fl a 27126b15476eSSheldon Hearnis specified, all aliases are removed. 27139ba31ca0SRuslan Ermilov.It Ic unset Oo Fl fv Oc Ar name ... 27148b34ad92STim J. RobbinsThe specified variables or functions are unset and unexported. 27158b34ad92STim J. RobbinsIf the 27168b34ad92STim J. Robbins.Fl v 27178b34ad92STim J. Robbinsoption is specified or no options are given, the 271849e11e3aSSheldon Hearn.Ar name 27198b34ad92STim J. Robbinsarguments are treated as variable names. 27208b34ad92STim J. RobbinsIf the 27218b34ad92STim J. Robbins.Fl f 27228b34ad92STim J. Robbinsoption is specified, the 27238b34ad92STim J. Robbins.Ar name 27248b34ad92STim J. Robbinsarguments are treated as function names. 2725bd76c6b8SJilles Tjoelker.It Ic wait Op Ar job ... 2726bd76c6b8SJilles TjoelkerWait for each specified 272749e11e3aSSheldon Hearn.Ar job 272849e11e3aSSheldon Hearnto complete and return the exit status of the last process in the 2729bd76c6b8SJilles Tjoelkerlast specified 273049e11e3aSSheldon Hearn.Ar job . 2731bd76c6b8SJilles TjoelkerIf any 2732bd76c6b8SJilles Tjoelker.Ar job 2733bd76c6b8SJilles Tjoelkerspecified is unknown to the shell, it is treated as if it 2734bd76c6b8SJilles Tjoelkerwere a known job that exited with exit status 127. 2735bd76c6b8SJilles TjoelkerIf no operands are given, wait for all jobs to complete 2736e6d3cf26SSheldon Hearnand return an exit status of zero. 2737ab72124fSSteve Price.El 27386986f58fSJilles Tjoelker.Ss Command Line Editing 2739ab72124fSSteve PriceWhen 2740ab72124fSSteve Price.Nm 2741ab72124fSSteve Priceis being used interactively from a terminal, the current command 274249e11e3aSSheldon Hearnand the command history 274349e11e3aSSheldon Hearn(see 274449e11e3aSSheldon Hearn.Ic fc 274549e11e3aSSheldon Hearnin 27468eed22b1SJens Schweikhardt.Sx Built-in Commands ) 2747dfe302abSRuslan Ermilovcan be edited using 2748dfe302abSRuslan Ermilov.Nm vi Ns -mode 2749dfe302abSRuslan Ermilovcommand line editing. 275049e11e3aSSheldon HearnThis mode uses commands similar 2751dfe302abSRuslan Ermilovto a subset of those described in the 2752dfe302abSRuslan Ermilov.Xr vi 1 2753dfe302abSRuslan Ermilovman page. 275449e11e3aSSheldon HearnThe command 2755dfe302abSRuslan Ermilov.Dq Li "set -o vi" 275649e11e3aSSheldon Hearn(or 2757dfe302abSRuslan Ermilov.Dq Li "set -V" ) 2758dfe302abSRuslan Ermilovenables 2759dfe302abSRuslan Ermilov.Nm vi Ns -mode 2760dfe302abSRuslan Ermilovediting and places 2761ab72124fSSteve Price.Nm 2762dfe302abSRuslan Ermilovinto 2763dfe302abSRuslan Ermilov.Nm vi 2764dfe302abSRuslan Ermilovinsert mode. 2765dfe302abSRuslan ErmilovWith 2766dfe302abSRuslan Ermilov.Nm vi Ns -mode 2767dfe302abSRuslan Ermilovenabled, 2768ab72124fSSteve Price.Nm 276949e11e3aSSheldon Hearncan be switched between insert mode and command mode by typing 277049e11e3aSSheldon Hearn.Aq ESC . 277149e11e3aSSheldon HearnHitting 277249e11e3aSSheldon Hearn.Aq return 277349e11e3aSSheldon Hearnwhile in command mode will pass the line to the shell. 2774ab72124fSSteve Price.Pp 277549e11e3aSSheldon HearnSimilarly, the 2776dfe302abSRuslan Ermilov.Dq Li "set -o emacs" 277749e11e3aSSheldon Hearn(or 2778dfe302abSRuslan Ermilov.Dq Li "set -E" ) 277949e11e3aSSheldon Hearncommand can be used to enable a subset of 2780dfe302abSRuslan Ermilov.Nm emacs Ns -style 2781dfe302abSRuslan Ermilovcommand line editing features. 278238afdcbcSGiorgos Keramidas.Sh ENVIRONMENT 278338afdcbcSGiorgos KeramidasThe following environment variables affect the execution of 278438afdcbcSGiorgos Keramidas.Nm : 27851788b7ffSJilles Tjoelker.Bl -tag -width ".Ev LANGXXXXXX" 27861788b7ffSJilles Tjoelker.It Ev ENV 27871788b7ffSJilles TjoelkerInitialization file for interactive shells. 27881788b7ffSJilles Tjoelker.It Ev LANG , Ev LC_* 27891788b7ffSJilles TjoelkerLocale settings. 27901788b7ffSJilles TjoelkerThese are inherited by children of the shell, 27911788b7ffSJilles Tjoelkerand is used in a limited manner by the shell itself. 27927b6779b6SJilles Tjoelker.It Ev OLDPWD 27937b6779b6SJilles TjoelkerThe previous current directory. 27947b6779b6SJilles TjoelkerThis is used and updated by 27957b6779b6SJilles Tjoelker.Ic cd . 27961788b7ffSJilles Tjoelker.It Ev PWD 27971788b7ffSJilles TjoelkerAn absolute pathname for the current directory, 27981788b7ffSJilles Tjoelkerpossibly containing symbolic links. 27991788b7ffSJilles TjoelkerThis is used and updated by the shell. 280038afdcbcSGiorgos Keramidas.It Ev TERM 280138afdcbcSGiorgos KeramidasThe default terminal setting for the shell. 280238afdcbcSGiorgos KeramidasThis is inherited by children of the shell, and is used in the history 280338afdcbcSGiorgos Keramidasediting modes. 280438afdcbcSGiorgos Keramidas.El 28051788b7ffSJilles Tjoelker.Pp 28064445af21SJilles TjoelkerAdditionally, environment variables are turned into shell variables 28071788b7ffSJilles Tjoelkerat startup, 28081788b7ffSJilles Tjoelkerwhich may affect the shell as described under 28091788b7ffSJilles Tjoelker.Sx Special Variables . 2810cb5a6a58SJoel Dahl.Sh FILES 2811cb5a6a58SJoel Dahl.Bl -tag -width "/etc/suid_profileXX" -compact 2812cb5a6a58SJoel Dahl.It Pa ~/.profile 2813cb5a6a58SJoel DahlUser's login profile. 2814cb5a6a58SJoel Dahl.It Pa /etc/profile 2815cb5a6a58SJoel DahlSystem login profile. 2816cb5a6a58SJoel Dahl.It Pa /etc/shells 2817cb5a6a58SJoel DahlShell database. 2818cb5a6a58SJoel Dahl.It Pa /etc/suid_profile 2819cb5a6a58SJoel DahlPrivileged shell profile. 2820cb5a6a58SJoel Dahl.El 2821fb039b55SRuslan Ermilov.Sh EXIT STATUS 2822*77da4a95SJilles TjoelkerIf the 2823*77da4a95SJilles Tjoelker.Ar script 2824*77da4a95SJilles Tjoelkercannot be found, the exit status will be 127; 2825*77da4a95SJilles Tjoelkerif it cannot be opened for another reason, the exit status will be 126. 2826*77da4a95SJilles TjoelkerOther errors that are detected by the shell, such as a syntax error, will 2827fb039b55SRuslan Ermilovcause the shell to exit with a non-zero exit status. 2828fb039b55SRuslan ErmilovIf the shell is not an interactive shell, the execution of the shell 2829fb039b55SRuslan Ermilovfile will be aborted. 2830fb039b55SRuslan ErmilovOtherwise the shell will return the exit status of the last command 2831dfe302abSRuslan Ermilovexecuted, or if the 2832dfe302abSRuslan Ermilov.Ic exit 2833dfe302abSRuslan Ermilovbuiltin is used with a numeric argument, it 2834fb039b55SRuslan Ermilovwill return the argument. 2835c83e7c50SJoseph Koshy.Sh SEE ALSO 2836c644db6aSSheldon Hearn.Xr builtin 1 , 283738afdcbcSGiorgos Keramidas.Xr chsh 1 , 2838c644db6aSSheldon Hearn.Xr echo 1 , 283938afdcbcSGiorgos Keramidas.Xr ed 1 , 284038afdcbcSGiorgos Keramidas.Xr emacs 1 , 28410a62a9caSJilles Tjoelker.Xr kill 1 , 28429897c45fSJilles Tjoelker.Xr printf 1 , 28435521ff5aSRuslan Ermilov.Xr pwd 1 , 284438afdcbcSGiorgos Keramidas.Xr test 1 , 284538afdcbcSGiorgos Keramidas.Xr vi 1 , 284638afdcbcSGiorgos Keramidas.Xr execve 2 , 284738afdcbcSGiorgos Keramidas.Xr getrlimit 2 , 2848fd50df30SRuslan Ermilov.Xr umask 2 , 2849ff4dc672SJilles Tjoelker.Xr wctype 3 , 2850cb5a6a58SJoel Dahl.Xr editrc 5 , 2851cb5a6a58SJoel Dahl.Xr shells 5 2852ab72124fSSteve Price.Sh HISTORY 2853b8923d4cSWolfram SchneiderA 2854ab72124fSSteve Price.Nm 28559cdd1e3fSYaroslav Tykhiycommand, the Thompson shell, appeared in 2856fc482908STim J. Robbins.At v1 . 28579cdd1e3fSYaroslav TykhiyIt was superseded in 28589cdd1e3fSYaroslav Tykhiy.At v7 28599cdd1e3fSYaroslav Tykhiyby the Bourne shell, which inherited the name 28609cdd1e3fSYaroslav Tykhiy.Nm . 28619cdd1e3fSYaroslav Tykhiy.Pp 28629cdd1e3fSYaroslav TykhiyThis version of 28639cdd1e3fSYaroslav Tykhiy.Nm 28649cdd1e3fSYaroslav Tykhiywas rewritten in 1989 under the 28659cdd1e3fSYaroslav Tykhiy.Bx 28669cdd1e3fSYaroslav Tykhiylicense after the Bourne shell from 28679cdd1e3fSYaroslav Tykhiy.At V.4 . 28689cdd1e3fSYaroslav Tykhiy.Sh AUTHORS 28699cdd1e3fSYaroslav TykhiyThis version of 28709cdd1e3fSYaroslav Tykhiy.Nm 28719badf57fSRuslan Ermilovwas originally written by 28729badf57fSRuslan Ermilov.An Kenneth Almquist . 2873128dc4a2STim J. Robbins.Sh BUGS 2874128dc4a2STim J. RobbinsThe 2875128dc4a2STim J. Robbins.Nm 287650df3424SJilles Tjoelkerutility does not recognize multibyte characters other than UTF-8. 287750df3424SJilles TjoelkerSplitting using 287850df3424SJilles Tjoelker.Va IFS 28798956c4ecSJilles Tjoelkerdoes not recognize multibyte characters. 2880