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.\" 32*65f5dd42SBaptiste Daroussin.Dd November 20, 2024 33ab72124fSSteve Price.Dt SH 1 34caa2db3bSRuslan Ermilov.Os 35ab72124fSSteve Price.Sh NAME 36ab72124fSSteve Price.Nm sh 37ab72124fSSteve Price.Nd command interpreter (shell) 38ab72124fSSteve Price.Sh SYNOPSIS 39ab72124fSSteve Price.Nm 40*65f5dd42SBaptiste Daroussin.Op Fl /+abCEefhIilmnPpTuVvx 41ab72124fSSteve Price.Op Fl /+o Ar longname 4257a40f7dSJilles Tjoelker.Oo 4357a40f7dSJilles Tjoelker.Ar script 4457a40f7dSJilles Tjoelker.Op Ar arg ... 4557a40f7dSJilles Tjoelker.Oc 4657a40f7dSJilles Tjoelker.Nm 47*65f5dd42SBaptiste Daroussin.Op Fl /+abCEefhIilmnPpTuVvx 4857a40f7dSJilles Tjoelker.Op Fl /+o Ar longname 4957a40f7dSJilles Tjoelker.Fl c Ar string 5057a40f7dSJilles Tjoelker.Oo 5157a40f7dSJilles Tjoelker.Ar name 5257a40f7dSJilles Tjoelker.Op Ar arg ... 5357a40f7dSJilles Tjoelker.Oc 5457a40f7dSJilles Tjoelker.Nm 55*65f5dd42SBaptiste Daroussin.Op Fl /+abCEefhIilmnPpTuVvx 5657a40f7dSJilles Tjoelker.Op Fl /+o Ar longname 5757a40f7dSJilles Tjoelker.Fl s 5881e9cda2SRuslan Ermilov.Op Ar arg ... 59ab72124fSSteve Price.Sh DESCRIPTION 60e918fc8fSSheldon HearnThe 61e918fc8fSSheldon Hearn.Nm 62e918fc8fSSheldon Hearnutility is the standard command interpreter for the system. 63ab72124fSSteve PriceThe current version of 64ab72124fSSteve Price.Nm 653fdfd0a4SJilles Tjoelkeris close to the 663fdfd0a4SJilles Tjoelker.St -p1003.1 67eccea571SRuslan Ermilovspecification for the shell. 683fdfd0a4SJilles TjoelkerIt only supports features 6917e98da8SMateusz Piotrowskidesignated by POSIX, 703fdfd0a4SJilles Tjoelkerplus a few Berkeley extensions. 7149e11e3aSSheldon HearnThis man page is not intended to be a tutorial nor a complete 724b88c807SRodney W. Grimesspecification of the shell. 73ab72124fSSteve Price.Ss Overview 744b88c807SRodney W. GrimesThe shell is a command that reads lines from 754b88c807SRodney W. Grimeseither a file or the terminal, interprets them, and 76e6d3cf26SSheldon Hearngenerally executes other commands. 7749e11e3aSSheldon HearnIt is the program that is started when a user logs into the system, 7849e11e3aSSheldon Hearnalthough a user can select a different shell with the 79c644db6aSSheldon Hearn.Xr chsh 1 8049e11e3aSSheldon Hearncommand. 814b88c807SRodney W. GrimesThe shell 824b88c807SRodney W. Grimesimplements a language that has flow control constructs, 834b88c807SRodney W. Grimesa macro facility that provides a variety of features in 848eed22b1SJens Schweikhardtaddition to data storage, along with built-in history and line 85eccea571SRuslan Ermilovediting capabilities. 86eccea571SRuslan ErmilovIt incorporates many features to 874b88c807SRodney W. Grimesaid interactive use and has the advantage that the interpretative 884b88c807SRodney W. Grimeslanguage is common to both interactive and non-interactive 89eccea571SRuslan Ermilovuse (shell scripts). 90eccea571SRuslan ErmilovThat is, commands can be typed directly 9149e11e3aSSheldon Hearnto the running shell or can be put into a file, 9249e11e3aSSheldon Hearnwhich can be executed directly by the shell. 93ab72124fSSteve Price.Ss Invocation 9449e11e3aSSheldon Hearn.\" 9549e11e3aSSheldon Hearn.\" XXX This next sentence is incredibly confusing. 9649e11e3aSSheldon Hearn.\" 9749e11e3aSSheldon HearnIf no arguments are present and if the standard input of the shell 9849e11e3aSSheldon Hearnis connected to a terminal 9949e11e3aSSheldon Hearn(or if the 10049e11e3aSSheldon Hearn.Fl i 10149e11e3aSSheldon Hearnoption is set), 102eccea571SRuslan Ermilovthe shell is considered an interactive shell. 103eccea571SRuslan ErmilovAn interactive shell 1044b88c807SRodney W. Grimesgenerally prompts before each command and handles programming 1054b88c807SRodney W. Grimesand command errors differently (as described below). 1064b88c807SRodney W. GrimesWhen first starting, the shell inspects argument 0, and 10749e11e3aSSheldon Hearnif it begins with a dash 108a762afe5SGiorgos Keramidas.Pq Ql - , 10949e11e3aSSheldon Hearnthe shell is also considered a login shell. 11049e11e3aSSheldon HearnThis is normally done automatically by the system 111eccea571SRuslan Ermilovwhen the user first logs in. 112eccea571SRuslan ErmilovA login shell first reads commands 113ab72124fSSteve Pricefrom the files 114ab72124fSSteve Price.Pa /etc/profile 11549e11e3aSSheldon Hearnand then 116ab72124fSSteve Price.Pa .profile 117dfe302abSRuslan Ermilovin a user's home directory, 118eccea571SRuslan Ermilovif they exist. 119eccea571SRuslan ErmilovIf the environment variable 120ab72124fSSteve Price.Ev ENV 121ab72124fSSteve Priceis set on entry to a shell, or is set in the 122ab72124fSSteve Price.Pa .profile 1231a62d884SJilles Tjoelkerof a login shell, the shell then subjects its value to parameter expansion 1241a62d884SJilles Tjoelkerand arithmetic expansion and reads commands from the named file. 125ab72124fSSteve PriceTherefore, a user should place commands that are to be executed only 126ab72124fSSteve Priceat login time in the 127ab72124fSSteve Price.Pa .profile 128ab72124fSSteve Pricefile, and commands that are executed for every shell inside the 129ab72124fSSteve Price.Ev ENV 130e6d3cf26SSheldon Hearnfile. 13149e11e3aSSheldon HearnThe user can set the 132ab72124fSSteve Price.Ev ENV 13349e11e3aSSheldon Hearnvariable to some file by placing the following line in the file 134ab72124fSSteve Price.Pa .profile 13549e11e3aSSheldon Hearnin the home directory, 136ab72124fSSteve Pricesubstituting for 1375dd78c9fSJoel Dahl.Pa .shrc 13849e11e3aSSheldon Hearnthe filename desired: 13949e11e3aSSheldon Hearn.Pp 1405dd78c9fSJoel Dahl.Dl "ENV=$HOME/.shrc; export ENV" 14149e11e3aSSheldon Hearn.Pp 14249e11e3aSSheldon HearnThe first non-option argument specified on the command line 14349e11e3aSSheldon Hearnwill be treated as the 1444b88c807SRodney W. Grimesname of a file from which to read commands (a shell script), and 1454b88c807SRodney W. Grimesthe remaining arguments are set as the positional parameters 146dfe302abSRuslan Ermilovof the shell 147dfe302abSRuslan Ermilov.Li ( $1 , $2 , 148dfe302abSRuslan Ermilovetc.). 149eccea571SRuslan ErmilovOtherwise, the shell reads commands 1504b88c807SRodney W. Grimesfrom its standard input. 151ea76be72SSteve Price.Pp 152ea76be72SSteve PriceUnlike older versions of 153ea76be72SSteve Price.Nm 154ea76be72SSteve Pricethe 155ea76be72SSteve Price.Ev ENV 156eccea571SRuslan Ermilovscript is only sourced on invocation of interactive shells. 157eccea571SRuslan ErmilovThis 158ea76be72SSteve Pricecloses a well-known, and sometimes easily exploitable security 159ea76be72SSteve Pricehole related to poorly thought out 160ea76be72SSteve Price.Ev ENV 161ea76be72SSteve Pricescripts. 162ab72124fSSteve Price.Ss Argument List Processing 163ab72124fSSteve PriceAll of the single letter options to 164ab72124fSSteve Price.Nm 16549e11e3aSSheldon Hearnhave a corresponding long name, 16649e11e3aSSheldon Hearnwith the exception of 16749e11e3aSSheldon Hearn.Fl c 16849e11e3aSSheldon Hearnand 16949e11e3aSSheldon Hearn.Fl /+o . 17049e11e3aSSheldon HearnThese long names are provided next to the single letter options 17149e11e3aSSheldon Hearnin the descriptions below. 17249e11e3aSSheldon HearnThe long name for an option may be specified as an argument to the 17349e11e3aSSheldon Hearn.Fl /+o 17449e11e3aSSheldon Hearnoption of 175facc6767SRuslan Ermilov.Nm . 17649e11e3aSSheldon HearnOnce the shell is running, 17749e11e3aSSheldon Hearnthe long name for an option may be specified as an argument to the 17849e11e3aSSheldon Hearn.Fl /+o 17949e11e3aSSheldon Hearnoption of the 180c644db6aSSheldon Hearn.Ic set 1818eed22b1SJens Schweikhardtbuilt-in command 18249e11e3aSSheldon Hearn(described later in the section called 1838eed22b1SJens Schweikhardt.Sx Built-in Commands ) . 18449e11e3aSSheldon HearnIntroducing an option with a dash 185a762afe5SGiorgos Keramidas.Pq Ql - 18649e11e3aSSheldon Hearnenables the option, 18749e11e3aSSheldon Hearnwhile using a plus 188a762afe5SGiorgos Keramidas.Pq Ql + 18949e11e3aSSheldon Hearndisables the option. 19049e11e3aSSheldon HearnA 19149e11e3aSSheldon Hearn.Dq Li -- 192fab26805SJoseph Koshyor plain 193dfe302abSRuslan Ermilov.Ql - 194fab26805SJoseph Koshywill stop option processing and will force the remaining 195fab26805SJoseph Koshywords on the command line to be treated as arguments. 19649e11e3aSSheldon HearnThe 19749e11e3aSSheldon Hearn.Fl /+o 19849e11e3aSSheldon Hearnand 19949e11e3aSSheldon Hearn.Fl c 20049e11e3aSSheldon Hearnoptions do not have long names. 20149e11e3aSSheldon HearnThey take arguments and are described after the single letter options. 20281e9cda2SRuslan Ermilov.Bl -tag -width indent 203ab72124fSSteve Price.It Fl a Li allexport 20449e11e3aSSheldon HearnFlag variables for export when assignments are made to them. 205ab72124fSSteve Price.It Fl b Li notify 206ab72124fSSteve PriceEnable asynchronous notification of background job 207ab72124fSSteve Pricecompletion. 208c4d9468eSRuslan Ermilov(UNIMPLEMENTED) 209ab72124fSSteve Price.It Fl C Li noclobber 210c644db6aSSheldon HearnDo not overwrite existing files with 211dfe302abSRuslan Ermilov.Ql > . 212ab72124fSSteve Price.It Fl E Li emacs 2138eed22b1SJens SchweikhardtEnable the built-in 214825225e5SJens Schweikhardt.Xr emacs 1 Pq Pa ports/editors/emacs 21549e11e3aSSheldon Hearncommand line editor (disables the 216ab72124fSSteve Price.Fl V 217d5f6b530SJilles Tjoelkeroption if it has been set; 218d5f6b530SJilles Tjoelkerset automatically when interactive on terminals). 219ab72124fSSteve Price.It Fl e Li errexit 22049e11e3aSSheldon HearnExit immediately if any untested command fails in non-interactive mode. 2214b88c807SRodney W. GrimesThe exit status of a command is considered to be 22274053659SStefan Farfelederexplicitly tested if the command is part of the list used to control 2238af11131SRuslan Ermilovan 2248af11131SRuslan Ermilov.Ic if , elif , while , 2258af11131SRuslan Ermilovor 2268af11131SRuslan Ermilov.Ic until ; 2278af11131SRuslan Ermilovif the command is the left 228ab72124fSSteve Pricehand operand of an 22949e11e3aSSheldon Hearn.Dq Li && 230ab72124fSSteve Priceor 23149e11e3aSSheldon Hearn.Dq Li || 23274053659SStefan Farfelederoperator; or if the command is a pipeline preceded by the 23374053659SStefan Farfeleder.Ic !\& 234b14cfdf6SJilles Tjoelkerkeyword. 23574053659SStefan FarfelederIf a shell function is executed and its exit status is explicitly 23674053659SStefan Farfeledertested, all commands of the function are considered to be tested as 23774053659SStefan Farfelederwell. 238b14cfdf6SJilles Tjoelker.Pp 239b14cfdf6SJilles TjoelkerIt is recommended to check for failures explicitly 240b14cfdf6SJilles Tjoelkerinstead of relying on 241b14cfdf6SJilles Tjoelker.Fl e 242b14cfdf6SJilles Tjoelkerbecause it tends to behave in unexpected ways, 243b14cfdf6SJilles Tjoelkerparticularly in larger scripts. 244ab72124fSSteve Price.It Fl f Li noglob 2454b88c807SRodney W. GrimesDisable pathname expansion. 24654b16435SJilles Tjoelker.It Fl h Li trackall 24717e98da8SMateusz PiotrowskiA do-nothing option for POSIX compliance. 248ab72124fSSteve Price.It Fl I Li ignoreeof 24949e11e3aSSheldon HearnIgnore 250dfe302abSRuslan Ermilov.Dv EOF Ap s 25149e11e3aSSheldon Hearnfrom input when in interactive mode. 252ab72124fSSteve Price.It Fl i Li interactive 253ab72124fSSteve PriceForce the shell to behave interactively. 254*65f5dd42SBaptiste Daroussin.It Fl l 255*65f5dd42SBaptiste DaroussinForce the shell to act as if it has been invoked as a login shell. 256ab72124fSSteve Price.It Fl m Li monitor 257ab72124fSSteve PriceTurn on job control (set automatically when interactive). 258cd60e2c6SJilles TjoelkerA new process group is created for each pipeline (called a job). 259cd60e2c6SJilles TjoelkerIt is possible to suspend jobs or to have them run in the foreground or 260cd60e2c6SJilles Tjoelkerin the background. 261cd60e2c6SJilles TjoelkerIn a non-interactive shell, 262cd60e2c6SJilles Tjoelkerthis option can be set even if no terminal is available 263cd60e2c6SJilles Tjoelkerand is useful to place processes in separate process groups. 264ab72124fSSteve Price.It Fl n Li noexec 2654b88c807SRodney W. GrimesIf not interactive, read commands but do not 266eccea571SRuslan Ermilovexecute them. 267eccea571SRuslan ErmilovThis is useful for checking the 2684b88c807SRodney W. Grimessyntax of shell scripts. 2697e1975c2STim J. Robbins.It Fl P Li physical 2707e1975c2STim J. RobbinsChange the default for the 2717e1975c2STim J. Robbins.Ic cd 2727e1975c2STim J. Robbinsand 2737e1975c2STim J. Robbins.Ic pwd 2747e1975c2STim J. Robbinscommands from 2757e1975c2STim J. Robbins.Fl L 2767e1975c2STim J. Robbins(logical directory layout) 2777e1975c2STim J. Robbinsto 2787e1975c2STim J. Robbins.Fl P 2797e1975c2STim J. Robbins(physical directory layout). 280ab72124fSSteve Price.It Fl p Li privileged 281eccea571SRuslan ErmilovTurn on privileged mode. 282eccea571SRuslan ErmilovThis mode is enabled on startup 283dfe302abSRuslan Ermilovif either the effective user or group ID is not equal to the 284dfe302abSRuslan Ermilovreal user or group ID. 285eccea571SRuslan ErmilovTurning this mode off sets the 286dfe302abSRuslan Ermiloveffective user and group IDs to the real user and group IDs. 28749e11e3aSSheldon HearnWhen this mode is enabled for interactive shells, the file 288ab72124fSSteve Price.Pa /etc/suid_profile 28949e11e3aSSheldon Hearnis sourced instead of 29049e11e3aSSheldon Hearn.Pa ~/.profile 291ab72124fSSteve Priceafter 292ab72124fSSteve Price.Pa /etc/profile 29349e11e3aSSheldon Hearnis sourced, and the contents of the 294ab72124fSSteve Price.Ev ENV 29549e11e3aSSheldon Hearnvariable are ignored. 296ab72124fSSteve Price.It Fl s Li stdin 2974b88c807SRodney W. GrimesRead commands from standard input (set automatically 298eccea571SRuslan Ermilovif no file arguments are present). 299eccea571SRuslan ErmilovThis option has 3004b88c807SRodney W. Grimesno effect when set after the shell has already started 301eccea571SRuslan Ermilovrunning (i.e., when set with the 302c644db6aSSheldon Hearn.Ic set 3036b15476eSSheldon Hearncommand). 304304199ceSTom Rhodes.It Fl T Li trapsasync 305e6d3cf26SSheldon HearnWhen waiting for a child, execute traps immediately. 306e6d3cf26SSheldon HearnIf this option is not set, 307e6d3cf26SSheldon Hearntraps are executed after the child exits, 308e6d3cf26SSheldon Hearnas specified in 309af5eb6fcSMaxim Konovalov.St -p1003.2 . 3106b15476eSSheldon HearnThis nonstandard option is useful for putting guarding shells around 311eccea571SRuslan Ermilovchildren that block signals. 312eccea571SRuslan ErmilovThe surrounding shell may kill the child 3136b15476eSSheldon Hearnor it may just return control to the tty and leave the child alone, 3146b15476eSSheldon Hearnlike this: 315c1c72a3cSMartin Cracauer.Bd -literal -offset indent 316c1c72a3cSMartin Cracauersh -T -c "trap 'exit 1' 2 ; some-blocking-program" 317c1c72a3cSMartin Cracauer.Ed 318ab72124fSSteve Price.It Fl u Li nounset 319ab72124fSSteve PriceWrite a message to standard error when attempting 32064254a66SJilles Tjoelkerto expand a variable, a positional parameter or 32164254a66SJilles Tjoelkerthe special parameter 32264254a66SJilles Tjoelker.Va \&! 32364254a66SJilles Tjoelkerthat is not set, and if the 324ab72124fSSteve Priceshell is not interactive, exit immediately. 325ab72124fSSteve Price.It Fl V Li vi 3268eed22b1SJens SchweikhardtEnable the built-in 327ab72124fSSteve Price.Xr vi 1 328ab72124fSSteve Pricecommand line editor (disables 329ab72124fSSteve Price.Fl E 330ab72124fSSteve Priceif it has been set). 331ab72124fSSteve Price.It Fl v Li verbose 332ab72124fSSteve PriceThe shell writes its input to standard error 333eccea571SRuslan Ermilovas it is read. 334eccea571SRuslan ErmilovUseful for debugging. 335ab72124fSSteve Price.It Fl x Li xtrace 33649e11e3aSSheldon HearnWrite each command 337120c8e6cSStefan Farfeleder(preceded by the value of the 338dfe302abSRuslan Ermilov.Va PS4 339292e6676SJilles Tjoelkervariable subjected to parameter expansion and arithmetic expansion) 34049e11e3aSSheldon Hearnto standard error before it is executed. 34149e11e3aSSheldon HearnUseful for debugging. 3426986f58fSJilles Tjoelker.It Li nolog 34317e98da8SMateusz PiotrowskiAnother do-nothing option for POSIX compliance. 34462c37116SJilles TjoelkerIt only has a long name. 345484160a9SJilles Tjoelker.It Li pipefail 346484160a9SJilles TjoelkerChange the exit status of a pipeline to the last non-zero exit status of 347484160a9SJilles Tjoelkerany command in the pipeline, if any. 348484160a9SJilles TjoelkerSince an exit due to 349484160a9SJilles Tjoelker.Dv SIGPIPE 350484160a9SJilles Tjoelkercounts as a non-zero exit status, 351484160a9SJilles Tjoelkerthis option may cause non-zero exit status for successful pipelines 352484160a9SJilles Tjoelkerif a command such as 353484160a9SJilles Tjoelker.Xr head 1 354484160a9SJilles Tjoelkerin the pipeline terminates with status 0 without reading its 355484160a9SJilles Tjoelkerinput completely. 356484160a9SJilles TjoelkerThis option only has a long name. 357d2c23317SStephane Rochoy.It Li verify 358d2c23317SStephane RochoySet 359d2c23317SStephane Rochoy.Dv O_VERIFY 360b131efe3SGordon Berglingwhen sourcing files or loading profiles. 361825225e5SJens Schweikhardt.\" See also 362825225e5SJens Schweikhardt.\" .Xr mac_veriexec 4 . TODO Does not exist; write it. 36349e11e3aSSheldon Hearn.El 36449e11e3aSSheldon Hearn.Pp 36549e11e3aSSheldon HearnThe 366fd50df30SRuslan Ermilov.Fl c 367fd50df30SRuslan Ermilovoption causes the commands to be read from the 368fd50df30SRuslan Ermilov.Ar string 369fd50df30SRuslan Ermilovoperand instead of from the standard input. 370fd50df30SRuslan ErmilovKeep in mind that this option only accepts a single string as its 371fd50df30SRuslan Ermilovargument, hence multi-word strings must be quoted. 372fd50df30SRuslan Ermilov.Pp 373fd50df30SRuslan ErmilovThe 37449e11e3aSSheldon Hearn.Fl /+o 37549e11e3aSSheldon Hearnoption takes as its only argument the long name of an option 37649e11e3aSSheldon Hearnto be enabled or disabled. 37749e11e3aSSheldon HearnFor example, the following two invocations of 37849e11e3aSSheldon Hearn.Nm 3798eed22b1SJens Schweikhardtboth enable the built-in 380825225e5SJens Schweikhardt.Xr emacs 1 Pq Pa ports/editors/emacs 38149e11e3aSSheldon Hearncommand line editor: 38249e11e3aSSheldon Hearn.Bd -literal -offset indent 38349e11e3aSSheldon Hearnset -E 38449e11e3aSSheldon Hearnset -o emacs 38549e11e3aSSheldon Hearn.Ed 386d513af6aSTim J. Robbins.Pp 387d513af6aSTim J. RobbinsIf used without an argument, the 388d513af6aSTim J. Robbins.Fl o 389d513af6aSTim J. Robbinsoption displays the current option settings in a human-readable format. 390d513af6aSTim J. RobbinsIf 391d513af6aSTim J. Robbins.Cm +o 392d513af6aSTim J. Robbinsis used without an argument, the current option settings are output 393d513af6aSTim J. Robbinsin a format suitable for re-input into the shell. 394ab72124fSSteve Price.Ss Lexical Structure 3954b88c807SRodney W. GrimesThe shell reads input in terms of lines from a file and breaks 3964b88c807SRodney W. Grimesit up into words at whitespace (blanks and tabs), and at 3974b88c807SRodney W. Grimescertain sequences of 3986b15476eSSheldon Hearncharacters called 3996b15476eSSheldon Hearn.Dq operators , 4006b15476eSSheldon Hearnwhich are special to the shell. 4014b88c807SRodney W. GrimesThere are two types of operators: control operators and 4024b88c807SRodney W. Grimesredirection operators (their meaning is discussed later). 403ab72124fSSteve PriceThe following is a list of valid operators: 40481e9cda2SRuslan Ermilov.Bl -tag -width indent 40549e11e3aSSheldon Hearn.It Control operators: 40649e11e3aSSheldon Hearn.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 40735471bf8SJoel Dahl.It Li & Ta Li && Ta Li \&( Ta Li \&) Ta Li \en 40835471bf8SJoel Dahl.It Li ;; Ta Li ;& Ta Li \&; Ta Li \&| Ta Li || 40949e11e3aSSheldon Hearn.El 41049e11e3aSSheldon Hearn.It Redirection operators: 4114682f420SBrian Somers.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 41281e9cda2SRuslan Ermilov.It Li < Ta Li > Ta Li << Ta Li >> Ta Li <> 413748611c9SJoel Dahl.It Li <& Ta Li >& Ta Li <<- Ta Li >| Ta \& 41449e11e3aSSheldon Hearn.El 415ab72124fSSteve Price.El 4167d1a55fcSStefan Farfeleder.Pp 4177d1a55fcSStefan FarfelederThe character 4187d1a55fcSStefan Farfeleder.Ql # 4197d1a55fcSStefan Farfelederintroduces a comment if used at the beginning of a word. 4207d1a55fcSStefan FarfelederThe word starting with 4217d1a55fcSStefan Farfeleder.Ql # 4227d1a55fcSStefan Farfelederand the rest of the line are ignored. 4239764aa41SJilles Tjoelker.Pp 42417e98da8SMateusz PiotrowskiASCII 4259764aa41SJilles Tjoelker.Dv NUL 4269764aa41SJilles Tjoelkercharacters (character code 0) are not allowed in shell input. 427ab72124fSSteve Price.Ss Quoting 4284b88c807SRodney W. GrimesQuoting is used to remove the special meaning of certain characters 429a886288eSJesus R. Camouor words to the shell, such as operators, whitespace, keywords, 430a886288eSJesus R. Camouor alias names. 431a886288eSJesus R. Camou.Pp 432a62ab027SJilles TjoelkerThere are four types of quoting: matched single quotes, 433a62ab027SJilles Tjoelkerdollar-single quotes, 4344b88c807SRodney W. Grimesmatched double quotes, and backslash. 43581e9cda2SRuslan Ermilov.Bl -tag -width indent 436ab72124fSSteve Price.It Single Quotes 4374b88c807SRodney W. GrimesEnclosing characters in single quotes preserves the literal 438ab0a2172SSteve Pricemeaning of all the characters (except single quotes, making 439ab0a2172SSteve Priceit impossible to put single-quotes in a single-quoted string). 440a62ab027SJilles Tjoelker.It Dollar-Single Quotes 441a62ab027SJilles TjoelkerEnclosing characters between 442a62ab027SJilles Tjoelker.Li $' 443a62ab027SJilles Tjoelkerand 444a62ab027SJilles Tjoelker.Li ' 445a62ab027SJilles Tjoelkerpreserves the literal meaning of all characters 446a62ab027SJilles Tjoelkerexcept backslashes and single quotes. 447a62ab027SJilles TjoelkerA backslash introduces a C-style escape sequence: 448a62ab027SJilles Tjoelker.Bl -tag -width xUnnnnnnnn 449a62ab027SJilles Tjoelker.It \ea 450a62ab027SJilles TjoelkerAlert (ring the terminal bell) 451a62ab027SJilles Tjoelker.It \eb 452a62ab027SJilles TjoelkerBackspace 453a62ab027SJilles Tjoelker.It \ec Ns Ar c 454a62ab027SJilles TjoelkerThe control character denoted by 455a62ab027SJilles Tjoelker.Li ^ Ns Ar c 456a62ab027SJilles Tjoelkerin 457a62ab027SJilles Tjoelker.Xr stty 1 . 458a62ab027SJilles TjoelkerIf 459a62ab027SJilles Tjoelker.Ar c 460a62ab027SJilles Tjoelkeris a backslash, it must be doubled. 461a62ab027SJilles Tjoelker.It \ee 46217e98da8SMateusz PiotrowskiThe ESC character (ASCII 0x1b) 463a62ab027SJilles Tjoelker.It \ef 464a62ab027SJilles TjoelkerFormfeed 465a62ab027SJilles Tjoelker.It \en 466a62ab027SJilles TjoelkerNewline 467a62ab027SJilles Tjoelker.It \er 468a62ab027SJilles TjoelkerCarriage return 469a62ab027SJilles Tjoelker.It \et 470a62ab027SJilles TjoelkerHorizontal tab 471a62ab027SJilles Tjoelker.It \ev 472a62ab027SJilles TjoelkerVertical tab 473a62ab027SJilles Tjoelker.It \e\e 474a62ab027SJilles TjoelkerLiteral backslash 475a62ab027SJilles Tjoelker.It \e\&' 476a62ab027SJilles TjoelkerLiteral single-quote 477a62ab027SJilles Tjoelker.It \e\&" 478a62ab027SJilles TjoelkerLiteral double-quote 479a62ab027SJilles Tjoelker.It \e Ns Ar nnn 480a62ab027SJilles TjoelkerThe byte whose octal value is 481a62ab027SJilles Tjoelker.Ar nnn 482a62ab027SJilles Tjoelker(one to three digits) 483a62ab027SJilles Tjoelker.It \ex Ns Ar nn 484a62ab027SJilles TjoelkerThe byte whose hexadecimal value is 485a62ab027SJilles Tjoelker.Ar nn 486a62ab027SJilles Tjoelker(one or more digits only the last two of which are used) 487a62ab027SJilles Tjoelker.It \eu Ns Ar nnnn 488a62ab027SJilles TjoelkerThe Unicode code point 489a62ab027SJilles Tjoelker.Ar nnnn 490a62ab027SJilles Tjoelker(four hexadecimal digits) 491a62ab027SJilles Tjoelker.It \eU Ns Ar nnnnnnnn 492a62ab027SJilles TjoelkerThe Unicode code point 493a62ab027SJilles Tjoelker.Ar nnnnnnnn 494a62ab027SJilles Tjoelker(eight hexadecimal digits) 495a62ab027SJilles Tjoelker.El 496a62ab027SJilles Tjoelker.Pp 49707eb7033SJilles TjoelkerThe sequences for Unicode code points are currently only useful with 49807eb7033SJilles TjoelkerUTF-8 locales. 499a62ab027SJilles TjoelkerThey reject code point 0 and UTF-16 surrogates. 500a62ab027SJilles Tjoelker.Pp 501a62ab027SJilles TjoelkerIf an escape sequence would produce a byte with value 0, 502a62ab027SJilles Tjoelkerthat byte and the rest of the string until the matching single-quote 503a62ab027SJilles Tjoelkerare ignored. 504a62ab027SJilles Tjoelker.Pp 505a62ab027SJilles TjoelkerAny other string starting with a backslash is an error. 506ab72124fSSteve Price.It Double Quotes 5074b88c807SRodney W. GrimesEnclosing characters within double quotes preserves the literal 50849e11e3aSSheldon Hearnmeaning of all characters except dollar sign 509a762afe5SGiorgos Keramidas.Pq Ql $ , 51049e11e3aSSheldon Hearnbackquote 511a762afe5SGiorgos Keramidas.Pq Ql ` , 51249e11e3aSSheldon Hearnand backslash 513a762afe5SGiorgos Keramidas.Pq Ql \e . 51449e11e3aSSheldon HearnThe backslash inside double quotes is historically weird. 51549e11e3aSSheldon HearnIt remains literal unless it precedes the following characters, 51649e11e3aSSheldon Hearnwhich it serves to quote: 517afc5a69aSJoel Dahl.Pp 51849e11e3aSSheldon Hearn.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 519afc5a69aSJoel Dahl.It Li $ Ta Li ` Ta Li \&" Ta Li \e Ta Li \en 52049e11e3aSSheldon Hearn.El 521ab72124fSSteve Price.It Backslash 522ab72124fSSteve PriceA backslash preserves the literal meaning of the following 52349e11e3aSSheldon Hearncharacter, with the exception of the newline character 524a762afe5SGiorgos Keramidas.Pq Ql \en . 52549e11e3aSSheldon HearnA backslash preceding a newline is treated as a line continuation. 526ab72124fSSteve Price.El 527d806a030SJilles Tjoelker.Ss Keywords 528d806a030SJilles TjoelkerKeywords or reserved words are words that have special meaning to the 5294b88c807SRodney W. Grimesshell and are recognized at the beginning of a line and 530eccea571SRuslan Ermilovafter a control operator. 531d806a030SJilles TjoelkerThe following are keywords: 53249e11e3aSSheldon Hearn.Bl -column "doneXX" "elifXX" "elseXX" "untilXX" "whileX" -offset center 53381e9cda2SRuslan Ermilov.It Li \&! Ta { Ta } Ta Ic case Ta Ic do 53481e9cda2SRuslan Ermilov.It Ic done Ta Ic elif Ta Ic else Ta Ic esac Ta Ic fi 53581e9cda2SRuslan Ermilov.It Ic for Ta Ic if Ta Ic then Ta Ic until Ta Ic while 53649e11e3aSSheldon Hearn.El 537ab72124fSSteve Price.Ss Aliases 538ab72124fSSteve PriceAn alias is a name and corresponding value set using the 539c644db6aSSheldon Hearn.Ic alias 540eccea571SRuslan Ermilovbuilt-in command. 54105a447d0SJilles TjoelkerWherever the command word of a simple command may occur, 54205a447d0SJilles Tjoelkerand after checking for keywords if a keyword may occur, the shell 543e6d3cf26SSheldon Hearnchecks the word to see if it matches an alias. 544e6d3cf26SSheldon HearnIf it does, it replaces it in the input stream with its value. 545e6d3cf26SSheldon HearnFor example, if there is an alias called 54649e11e3aSSheldon Hearn.Dq Li lf 5476b15476eSSheldon Hearnwith the value 548dfe302abSRuslan Ermilov.Dq Li "ls -F" , 5494b88c807SRodney W. Grimesthen the input 550dfe302abSRuslan Ermilov.Pp 551dfe302abSRuslan Ermilov.Dl "lf foobar" 552ab72124fSSteve Price.Pp 5534b88c807SRodney W. Grimeswould become 554dfe302abSRuslan Ermilov.Pp 555dfe302abSRuslan Ermilov.Dl "ls -F foobar" 556ab72124fSSteve Price.Pp 55748f49aacSJilles TjoelkerAliases are also recognized after an alias 55848f49aacSJilles Tjoelkerwhose value ends with a space or tab. 55948f49aacSJilles TjoelkerFor example, if there is also an alias called 56048f49aacSJilles Tjoelker.Dq Li nohup 56148f49aacSJilles Tjoelkerwith the value 56248f49aacSJilles Tjoelker.Dq Li "nohup " , 56348f49aacSJilles Tjoelkerthen the input 56448f49aacSJilles Tjoelker.Pp 56548f49aacSJilles Tjoelker.Dl "nohup lf foobar" 56648f49aacSJilles Tjoelker.Pp 56748f49aacSJilles Tjoelkerwould become 56848f49aacSJilles Tjoelker.Pp 56948f49aacSJilles Tjoelker.Dl "nohup ls -F foobar" 57048f49aacSJilles Tjoelker.Pp 5714b88c807SRodney W. GrimesAliases provide a convenient way for naive users to 5724b88c807SRodney W. Grimescreate shorthands for commands without having to learn how 573eccea571SRuslan Ermilovto create functions with arguments. 57412dfb7a5SJilles TjoelkerUsing aliases in scripts is discouraged 57512dfb7a5SJilles Tjoelkerbecause the command that defines them must be executed 57612dfb7a5SJilles Tjoelkerbefore the code that uses them is parsed. 57712dfb7a5SJilles TjoelkerThis is fragile and not portable. 578a886288eSJesus R. Camou.Pp 579a886288eSJesus R. CamouAn alias name may be escaped in a command line, so that it is not 580a886288eSJesus R. Camoureplaced by its alias value, by using quoting characters within or 58119162ab9SJesus R. Camouadjacent to the alias name. 58219162ab9SJesus R. CamouThis is most often done by prefixing 583a886288eSJesus R. Camouan alias name with a backslash to execute a function, built-in, or 584a886288eSJesus R. Camounormal program with the same name. 585a886288eSJesus R. CamouSee the 586a886288eSJesus R. Camou.Sx Quoting 587a886288eSJesus R. Camousubsection. 588ab72124fSSteve Price.Ss Commands 5894b88c807SRodney W. GrimesThe shell interprets the words it reads according to a 5904b88c807SRodney W. Grimeslanguage, the specification of which is outside the scope 591ab72124fSSteve Priceof this man page (refer to the BNF in the 592ab72124fSSteve Price.St -p1003.2 593eccea571SRuslan Ermilovdocument). 594eccea571SRuslan ErmilovEssentially though, a line is read and if 5954b88c807SRodney W. Grimesthe first word of the line (or after a control operator) 596d806a030SJilles Tjoelkeris not a keyword, then the shell has recognized a 597eccea571SRuslan Ermilovsimple command. 598eccea571SRuslan ErmilovOtherwise, a complex command or some 5994b88c807SRodney W. Grimesother special construct may have been recognized. 600ab72124fSSteve Price.Ss Simple Commands 6014b88c807SRodney W. GrimesIf a simple command has been recognized, the shell performs 6024b88c807SRodney W. Grimesthe following actions: 603ab72124fSSteve Price.Bl -enum 604ab72124fSSteve Price.It 6056b15476eSSheldon HearnLeading words of the form 60649e11e3aSSheldon Hearn.Dq Li name=value 6076b15476eSSheldon Hearnare stripped off and assigned to the environment of 608000dda7bSJilles Tjoelkerthe simple command 609000dda7bSJilles Tjoelker(they do not affect expansions). 610eccea571SRuslan ErmilovRedirection operators and 6114b88c807SRodney W. Grimestheir arguments (as described below) are stripped 6124b88c807SRodney W. Grimesoff and saved for processing. 613ab72124fSSteve Price.It 614ab72124fSSteve PriceThe remaining words are expanded as described in 6156b15476eSSheldon Hearnthe section called 6166b15476eSSheldon Hearn.Sx Word Expansions , 6176b15476eSSheldon Hearnand the first remaining word is considered the command 618eccea571SRuslan Ermilovname and the command is located. 619eccea571SRuslan ErmilovThe remaining 6204b88c807SRodney W. Grimeswords are considered the arguments of the command. 6216b15476eSSheldon HearnIf no command name resulted, then the 62249e11e3aSSheldon Hearn.Dq Li name=value 6234b88c807SRodney W. Grimesvariable assignments recognized in 1) affect the 6244b88c807SRodney W. Grimescurrent shell. 625ab72124fSSteve Price.It 626ab72124fSSteve PriceRedirections are performed as described in 6274b88c807SRodney W. Grimesthe next section. 628ab72124fSSteve Price.El 629ab72124fSSteve Price.Ss Redirections 6304b88c807SRodney W. GrimesRedirections are used to change where a command reads its input 631eccea571SRuslan Ermilovor sends its output. 632eccea571SRuslan ErmilovIn general, redirections open, close, or 633eccea571SRuslan Ermilovduplicate an existing reference to a file. 634eccea571SRuslan ErmilovThe overall format 6354b88c807SRodney W. Grimesused for redirection is: 63649e11e3aSSheldon Hearn.Pp 637dfe302abSRuslan Ermilov.D1 Oo Ar n Oc Ar redir-op file 63849e11e3aSSheldon Hearn.Pp 63949e11e3aSSheldon HearnThe 640dfe302abSRuslan Ermilov.Ar redir-op 64149e11e3aSSheldon Hearnis one of the redirection operators mentioned 642eccea571SRuslan Ermilovpreviously. 643eccea571SRuslan ErmilovThe following gives some examples of how these 64449e11e3aSSheldon Hearnoperators can be used. 64549e11e3aSSheldon HearnNote that stdin and stdout are commonly used abbreviations 64649e11e3aSSheldon Hearnfor standard input and standard output respectively. 64749e11e3aSSheldon Hearn.Bl -tag -width "1234567890XX" -offset indent 648dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li > Ar file 649dfe302abSRuslan Ermilovredirect stdout (or file descriptor 650dfe302abSRuslan Ermilov.Ar n ) 651dfe302abSRuslan Ermilovto 652dfe302abSRuslan Ermilov.Ar file 653dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li >| Ar file 65449e11e3aSSheldon Hearnsame as above, but override the 65549e11e3aSSheldon Hearn.Fl C 65649e11e3aSSheldon Hearnoption 657dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li >> Ar file 658dfe302abSRuslan Ermilovappend stdout (or file descriptor 659dfe302abSRuslan Ermilov.Ar n ) 660dfe302abSRuslan Ermilovto 661dfe302abSRuslan Ermilov.Ar file 662dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li < Ar file 663dfe302abSRuslan Ermilovredirect stdin (or file descriptor 664dfe302abSRuslan Ermilov.Ar n ) 665dfe302abSRuslan Ermilovfrom 666dfe302abSRuslan Ermilov.Ar file 667dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li <> Ar file 668dfe302abSRuslan Ermilovredirect stdin (or file descriptor 669dfe302abSRuslan Ermilov.Ar n ) 670dfe302abSRuslan Ermilovto and from 671dfe302abSRuslan Ermilov.Ar file 672dfe302abSRuslan Ermilov.It Oo Ar n1 Oc Ns Li <& Ns Ar n2 673dfe302abSRuslan Ermilovduplicate stdin (or file descriptor 674dfe302abSRuslan Ermilov.Ar n1 ) 675dfe302abSRuslan Ermilovfrom file descriptor 676dfe302abSRuslan Ermilov.Ar n2 677dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li <&- 678dfe302abSRuslan Ermilovclose stdin (or file descriptor 679dfe302abSRuslan Ermilov.Ar n ) 680dfe302abSRuslan Ermilov.It Oo Ar n1 Oc Ns Li >& Ns Ar n2 681dfe302abSRuslan Ermilovduplicate stdout (or file descriptor 682dfe302abSRuslan Ermilov.Ar n1 ) 683dfe302abSRuslan Ermilovto file descriptor 684dfe302abSRuslan Ermilov.Ar n2 685dfe302abSRuslan Ermilov.It Oo Ar n Oc Ns Li >&- 686dfe302abSRuslan Ermilovclose stdout (or file descriptor 687dfe302abSRuslan Ermilov.Ar n ) 688ab72124fSSteve Price.El 689ab72124fSSteve Price.Pp 6906b15476eSSheldon HearnThe following redirection is often called a 6916b15476eSSheldon Hearn.Dq here-document . 692dfe302abSRuslan Ermilov.Bd -unfilled -offset indent 693dfe302abSRuslan Ermilov.Oo Ar n Oc Ns Li << Ar delimiter 694a2442c2fSJoel Dahl.Ar here-doc-text 695a2442c2fSJoel Dahl.Ar ... 696dfe302abSRuslan Ermilov.Ar delimiter 697ab72124fSSteve Price.Ed 698ab72124fSSteve Price.Pp 6994b88c807SRodney W. GrimesAll the text on successive lines up to the delimiter is 7004b88c807SRodney W. Grimessaved away and made available to the command on standard 701dfe302abSRuslan Ermilovinput, or file descriptor 702dfe302abSRuslan Ermilov.Ar n 703dfe302abSRuslan Ermilovif it is specified. 704dfe302abSRuslan ErmilovIf the 705dfe302abSRuslan Ermilov.Ar delimiter 706dfe302abSRuslan Ermilovas specified on the initial line is quoted, then the 707dfe302abSRuslan Ermilov.Ar here-doc-text 7084b88c807SRodney W. Grimesis treated literally, otherwise the text is subjected to 7094b88c807SRodney W. Grimesparameter expansion, command substitution, and arithmetic 7106b15476eSSheldon Hearnexpansion (as described in the section on 7116b15476eSSheldon Hearn.Sx Word Expansions ) . 7126b15476eSSheldon HearnIf the operator is 71349e11e3aSSheldon Hearn.Dq Li <<- 7146b15476eSSheldon Hearninstead of 71549e11e3aSSheldon Hearn.Dq Li << , 7166b15476eSSheldon Hearnthen leading tabs 717dfe302abSRuslan Ermilovin the 718dfe302abSRuslan Ermilov.Ar here-doc-text 719dfe302abSRuslan Ermilovare stripped. 720ab72124fSSteve Price.Ss Search and Execution 721ab0a2172SSteve PriceThere are three types of commands: shell functions, 7228eed22b1SJens Schweikhardtbuilt-in commands, and normal programs. 72349e11e3aSSheldon HearnThe command is searched for (by name) in that order. 72449e11e3aSSheldon HearnThe three types of commands are all executed in a different way. 725ab72124fSSteve Price.Pp 726ab0a2172SSteve PriceWhen a shell function is executed, all of the shell positional 727dfe302abSRuslan Ermilovparameters (except 728dfe302abSRuslan Ermilov.Li $0 , 729dfe302abSRuslan Ermilovwhich remains unchanged) are 7304b88c807SRodney W. Grimesset to the arguments of the shell function. 7314b88c807SRodney W. GrimesThe variables which are explicitly placed in the environment of 7324b88c807SRodney W. Grimesthe command (by placing assignments to them before the 7334b88c807SRodney W. Grimesfunction name) are made local to the function and are set 734e6d3cf26SSheldon Hearnto the values given. 735e6d3cf26SSheldon HearnThen the command given in the function definition is executed. 736e6d3cf26SSheldon HearnThe positional parameters are restored to their original values 737e6d3cf26SSheldon Hearnwhen the command completes. 738ab0a2172SSteve PriceThis all occurs within the current shell. 739ab72124fSSteve Price.Pp 7408eed22b1SJens SchweikhardtShell built-in commands are executed internally to the shell, without 741ab0a2172SSteve Pricespawning a new process. 74230268dfaSJilles TjoelkerThere are two kinds of built-in commands: regular and special. 74330268dfaSJilles TjoelkerAssignments before special builtins persist after they finish 74430268dfaSJilles Tjoelkerexecuting and assignment errors, redirection errors and certain 74530268dfaSJilles Tjoelkeroperand errors cause a script to be aborted. 7464b985a89SJilles TjoelkerSpecial builtins cannot be overridden with a function. 74730268dfaSJilles TjoelkerBoth regular and special builtins can affect the shell in ways 74830268dfaSJilles Tjoelkernormal programs cannot. 749ab72124fSSteve Price.Pp 750c644db6aSSheldon HearnOtherwise, if the command name does not match a function 7518eed22b1SJens Schweikhardtor built-in command, the command is searched for as a normal 7524b88c807SRodney W. Grimesprogram in the file system (as described in the next section). 7534b88c807SRodney W. GrimesWhen a normal program is executed, the shell runs the program, 754e6d3cf26SSheldon Hearnpassing the arguments and the environment to the program. 755e6d3cf26SSheldon HearnIf the program is not a normal executable file 756eccea571SRuslan Ermilov(i.e., if it does not begin with the 757dfe302abSRuslan Ermilov.Dq "magic number" 75817e98da8SMateusz Piotrowskiwhose ASCII representation is 759dfe302abSRuslan Ermilov.Dq Li #! , 76049e11e3aSSheldon Hearnresulting in an 761b4f0f4aaSRuslan Ermilov.Er ENOEXEC 76249e11e3aSSheldon Hearnreturn value from 76349e11e3aSSheldon Hearn.Xr execve 2 ) 764604e8224SJilles Tjoelkerbut appears to be a text file, 7653835f47cSJilles Tjoelkerthe shell will run a new instance of 7663835f47cSJilles Tjoelker.Nm 7673835f47cSJilles Tjoelkerto interpret it. 768ab72124fSSteve Price.Pp 769ab0a2172SSteve PriceNote that previous versions of this document 770ab0a2172SSteve Priceand the source code itself misleadingly and sporadically 771ab0a2172SSteve Pricerefer to a shell script without a magic number 7726b15476eSSheldon Hearnas a 773dfe302abSRuslan Ermilov.Dq "shell procedure" . 774ab72124fSSteve Price.Ss Path Search 7754b88c807SRodney W. GrimesWhen locating a command, the shell first looks to see if 776eccea571SRuslan Ermilovit has a shell function by that name. 777eccea571SRuslan ErmilovThen it looks for a 778eccea571SRuslan Ermilovbuilt-in command by that name. 779eccea571SRuslan ErmilovIf a built-in command is not found, 780ab0a2172SSteve Priceone of two things happen: 781ab72124fSSteve Price.Bl -enum 782ab72124fSSteve Price.It 783ab72124fSSteve PriceCommand names containing a slash are simply executed without 784ab0a2172SSteve Priceperforming any searches. 785ab72124fSSteve Price.It 786dfe302abSRuslan ErmilovThe shell searches each entry in the 7871788b7ffSJilles Tjoelker.Va PATH 7881788b7ffSJilles Tjoelkervariable 789eccea571SRuslan Ermilovin turn for the command. 790eccea571SRuslan ErmilovThe value of the 7911788b7ffSJilles Tjoelker.Va PATH 792ab72124fSSteve Pricevariable should be a series of 793eccea571SRuslan Ermiloventries separated by colons. 794eccea571SRuslan ErmilovEach entry consists of a 7954b88c807SRodney W. Grimesdirectory name. 7964b88c807SRodney W. GrimesThe current directory 797ab0a2172SSteve Pricemay be indicated implicitly by an empty directory name, 798ab0a2172SSteve Priceor explicitly by a single period. 799ab72124fSSteve Price.El 800ab72124fSSteve Price.Ss Command Exit Status 8014b88c807SRodney W. GrimesEach command has an exit status that can influence the behavior 802eccea571SRuslan Ermilovof other shell commands. 803eccea571SRuslan ErmilovThe paradigm is that a command exits 8044b88c807SRodney W. Grimeswith zero for normal or success, and non-zero for failure, 805eccea571SRuslan Ermiloverror, or a false indication. 806eccea571SRuslan ErmilovThe man page for each command 8074b88c807SRodney W. Grimesshould indicate the various exit codes and what they mean. 8088eed22b1SJens SchweikhardtAdditionally, the built-in commands return exit codes, as does 809ab0a2172SSteve Pricean executed shell function. 810c351e089SJohn Polstra.Pp 811b1f60592SJilles TjoelkerIf a command is terminated by a signal, its exit status is greater than 128. 812b1f60592SJilles TjoelkerThe signal name can be found by passing the exit status to 813b1f60592SJilles Tjoelker.Li kill -l . 814b1f60592SJilles Tjoelker.Pp 815b1f60592SJilles TjoelkerIf there is no command word, 816b1f60592SJilles Tjoelkerthe exit status is the exit status of the last command substitution executed, 817b1f60592SJilles Tjoelkeror zero if the command does not contain any command substitutions. 818ab72124fSSteve Price.Ss Complex Commands 8194b88c807SRodney W. GrimesComplex commands are combinations of simple commands 820d806a030SJilles Tjoelkerwith control operators or keywords, together creating a larger complex 821eccea571SRuslan Ermilovcommand. 822eccea571SRuslan ErmilovMore generally, a command is one of the following: 823ab72124fSSteve Price.Bl -item -offset indent 824ab72124fSSteve Price.It 825ab72124fSSteve Pricesimple command 826ab72124fSSteve Price.It 827ab72124fSSteve Pricepipeline 828ab72124fSSteve Price.It 829ab72124fSSteve Pricelist or compound-list 830ab72124fSSteve Price.It 831ab72124fSSteve Pricecompound command 832ab72124fSSteve Price.It 833ab72124fSSteve Pricefunction definition 834ab72124fSSteve Price.El 835ab72124fSSteve Price.Pp 8364b88c807SRodney W. GrimesUnless otherwise stated, the exit status of a command is 837b1f60592SJilles Tjoelkerthat of the last simple command executed by the command, 838b1f60592SJilles Tjoelkeror zero if no simple command was executed. 839ab72124fSSteve Price.Ss Pipelines 8404b88c807SRodney W. GrimesA pipeline is a sequence of one or more commands separated 841dfe302abSRuslan Ermilovby the control operator 842dfe302abSRuslan Ermilov.Ql \&| . 843eccea571SRuslan ErmilovThe standard output of all but 8444b88c807SRodney W. Grimesthe last command is connected to the standard input 845eccea571SRuslan Ermilovof the next command. 846eccea571SRuslan ErmilovThe standard output of the last 847ab0a2172SSteve Pricecommand is inherited from the shell, as usual. 848ab72124fSSteve Price.Pp 8494b88c807SRodney W. GrimesThe format for a pipeline is: 85049e11e3aSSheldon Hearn.Pp 851dfe302abSRuslan Ermilov.D1 Oo Li \&! Oc Ar command1 Op Li \&| Ar command2 ... 852ab72124fSSteve Price.Pp 853dfe302abSRuslan ErmilovThe standard output of 854dfe302abSRuslan Ermilov.Ar command1 855dfe302abSRuslan Ermilovis connected to the standard input of 856dfe302abSRuslan Ermilov.Ar command2 . 857eccea571SRuslan ErmilovThe standard input, standard output, or 8584b88c807SRodney W. Grimesboth of a command is considered to be assigned by the 8594b88c807SRodney W. Grimespipeline before any redirection specified by redirection 8604b88c807SRodney W. Grimesoperators that are part of the command. 861ab72124fSSteve Price.Pp 862f1ec0581SJilles TjoelkerNote that unlike some other shells, 863f1ec0581SJilles Tjoelker.Nm 864f1ec0581SJilles Tjoelkerexecutes each process in a pipeline with more than one command 865f1ec0581SJilles Tjoelkerin a subshell environment and as a child of the 866f1ec0581SJilles Tjoelker.Nm 867f1ec0581SJilles Tjoelkerprocess. 868f1ec0581SJilles Tjoelker.Pp 8694b88c807SRodney W. GrimesIf the pipeline is not in the background (discussed later), 8704b88c807SRodney W. Grimesthe shell waits for all commands to complete. 871ab72124fSSteve Price.Pp 872d806a030SJilles TjoelkerIf the keyword 873eccea571SRuslan Ermilov.Ic !\& 874eccea571SRuslan Ermilovdoes not precede the pipeline, the 8754b88c807SRodney W. Grimesexit status is the exit status of the last command specified 876484160a9SJilles Tjoelkerin the pipeline if the 877484160a9SJilles Tjoelker.Cm pipefail 878484160a9SJilles Tjoelkeroption is not set or all commands returned zero, 879484160a9SJilles Tjoelkeror the last non-zero exit status of any command in the pipeline otherwise. 880eccea571SRuslan ErmilovOtherwise, the exit status is the logical 881484160a9SJilles TjoelkerNOT of that exit status. 882eccea571SRuslan ErmilovThat is, if 883484160a9SJilles Tjoelkerthat status is zero, the exit status is 1; if 884484160a9SJilles Tjoelkerthat status is greater than zero, the exit status 8854b88c807SRodney W. Grimesis zero. 886ab72124fSSteve Price.Pp 8874b88c807SRodney W. GrimesBecause pipeline assignment of standard input or standard 8884b88c807SRodney W. Grimesoutput or both takes place before redirection, it can be 889eccea571SRuslan Ermilovmodified by redirection. 890eccea571SRuslan ErmilovFor example: 891ab72124fSSteve Price.Pp 892dfe302abSRuslan Ermilov.Dl "command1 2>&1 | command2" 893ab72124fSSteve Price.Pp 89449e11e3aSSheldon Hearnsends both the standard output and standard error of 895dfe302abSRuslan Ermilov.Ar command1 89649e11e3aSSheldon Hearnto the standard input of 897dfe302abSRuslan Ermilov.Ar command2 . 89849e11e3aSSheldon Hearn.Pp 89949e11e3aSSheldon HearnA 900dfe302abSRuslan Ermilov.Ql \&; 90149e11e3aSSheldon Hearnor newline terminator causes the preceding 902e918fc8fSSheldon HearnAND-OR-list 903e918fc8fSSheldon Hearn(described below in the section called 904e918fc8fSSheldon Hearn.Sx Short-Circuit List Operators ) 905e918fc8fSSheldon Hearnto be executed sequentially; 906e918fc8fSSheldon Hearnan 907dfe302abSRuslan Ermilov.Ql & 908e918fc8fSSheldon Hearncauses asynchronous execution of the preceding AND-OR-list. 90949e11e3aSSheldon Hearn.Ss Background Commands (&) 9104b88c807SRodney W. GrimesIf a command is terminated by the control operator ampersand 911a762afe5SGiorgos Keramidas.Pq Ql & , 91251a514adSJilles Tjoelkerthe shell executes the command in a subshell environment (see 91351a514adSJilles Tjoelker.Sx Grouping Commands Together 91451a514adSJilles Tjoelkerbelow) and asynchronously; 91549e11e3aSSheldon Hearnthe shell does not wait for the command to finish 91649e11e3aSSheldon Hearnbefore executing the next command. 917ab72124fSSteve Price.Pp 9184b88c807SRodney W. GrimesThe format for running a command in background is: 919dfe302abSRuslan Ermilov.Pp 920dfe302abSRuslan Ermilov.D1 Ar command1 Li & Op Ar command2 Li & Ar ... 921ab72124fSSteve Price.Pp 9224b88c807SRodney W. GrimesIf the shell is not interactive, the standard input of an 923dfe302abSRuslan Ermilovasynchronous command is set to 924dfe302abSRuslan Ermilov.Pa /dev/null . 925b1f60592SJilles Tjoelker.Pp 926b1f60592SJilles TjoelkerThe exit status is zero. 92749e11e3aSSheldon Hearn.Ss Lists (Generally Speaking) 9284b88c807SRodney W. GrimesA list is a sequence of zero or more commands separated by 9294b88c807SRodney W. Grimesnewlines, semicolons, or ampersands, 9304b88c807SRodney W. Grimesand optionally terminated by one of these three characters. 9314b88c807SRodney W. GrimesThe commands in a 9324b88c807SRodney W. Grimeslist are executed in the order they are written. 9334b88c807SRodney W. GrimesIf command is followed by an ampersand, the shell starts the 9348eed22b1SJens Schweikhardtcommand and immediately proceeds onto the next command; 9354b88c807SRodney W. Grimesotherwise it waits for the command to terminate before 9364b88c807SRodney W. Grimesproceeding to the next one. 937ab72124fSSteve Price.Ss Short-Circuit List Operators 93849e11e3aSSheldon Hearn.Dq Li && 9396b15476eSSheldon Hearnand 94049e11e3aSSheldon Hearn.Dq Li || 9416b15476eSSheldon Hearnare AND-OR list operators. 94249e11e3aSSheldon Hearn.Dq Li && 9436b15476eSSheldon Hearnexecutes the first command, and then executes the second command 9446b15476eSSheldon Hearnif the exit status of the first command is zero. 94549e11e3aSSheldon Hearn.Dq Li || 946120ac26dSMasafumi Max NAKANEis similar, but executes the second command if the exit 9476b15476eSSheldon Hearnstatus of the first command is nonzero. 94849e11e3aSSheldon Hearn.Dq Li && 9496b15476eSSheldon Hearnand 95049e11e3aSSheldon Hearn.Dq Li || 9514b88c807SRodney W. Grimesboth have the same priority. 95249e11e3aSSheldon Hearn.Ss Flow-Control Constructs (if, while, for, case) 95349e11e3aSSheldon HearnThe syntax of the 95449e11e3aSSheldon Hearn.Ic if 95549e11e3aSSheldon Hearncommand is: 956dfe302abSRuslan Ermilov.Bd -unfilled -offset indent -compact 957dfe302abSRuslan Ermilov.Ic if Ar list 958dfe302abSRuslan Ermilov.Ic then Ar list 959dfe302abSRuslan Ermilov.Oo Ic elif Ar list 960dfe302abSRuslan Ermilov.Ic then Ar list Oc Ar ... 961dfe302abSRuslan Ermilov.Op Ic else Ar list 962dfe302abSRuslan Ermilov.Ic fi 963dfe302abSRuslan Ermilov.Ed 964ab72124fSSteve Price.Pp 965b1f60592SJilles TjoelkerThe exit status is that of selected 966b1f60592SJilles Tjoelker.Ic then 967b1f60592SJilles Tjoelkeror 968b1f60592SJilles Tjoelker.Ic else 969b1f60592SJilles Tjoelkerlist, 970b1f60592SJilles Tjoelkeror zero if no list was selected. 971b1f60592SJilles Tjoelker.Pp 97249e11e3aSSheldon HearnThe syntax of the 97349e11e3aSSheldon Hearn.Ic while 97449e11e3aSSheldon Hearncommand is: 975dfe302abSRuslan Ermilov.Bd -unfilled -offset indent -compact 976dfe302abSRuslan Ermilov.Ic while Ar list 977dfe302abSRuslan Ermilov.Ic do Ar list 978dfe302abSRuslan Ermilov.Ic done 979dfe302abSRuslan Ermilov.Ed 980ab72124fSSteve Price.Pp 981ab0a2172SSteve PriceThe two lists are executed repeatedly while the exit status of the 98249e11e3aSSheldon Hearnfirst list is zero. 98349e11e3aSSheldon HearnThe 98449e11e3aSSheldon Hearn.Ic until 98549e11e3aSSheldon Hearncommand is similar, but has the word 98649e11e3aSSheldon Hearn.Ic until 98749e11e3aSSheldon Hearnin place of 98849e11e3aSSheldon Hearn.Ic while , 98949e11e3aSSheldon Hearnwhich causes it to 9904b88c807SRodney W. Grimesrepeat until the exit status of the first list is zero. 991ab72124fSSteve Price.Pp 992b1f60592SJilles TjoelkerThe exit status is that of the last execution of the second list, 993b1f60592SJilles Tjoelkeror zero if it was never executed. 994b1f60592SJilles Tjoelker.Pp 99549e11e3aSSheldon HearnThe syntax of the 99649e11e3aSSheldon Hearn.Ic for 99749e11e3aSSheldon Hearncommand is: 998dfe302abSRuslan Ermilov.Bd -unfilled -offset indent -compact 999dfe302abSRuslan Ermilov.Ic for Ar variable Op Ic in Ar word ... 1000dfe302abSRuslan Ermilov.Ic do Ar list 1001dfe302abSRuslan Ermilov.Ic done 1002dfe302abSRuslan Ermilov.Ed 1003ab72124fSSteve Price.Pp 1004a01459dfSStefan FarfelederIf 1005a01459dfSStefan Farfeleder.Ic in 10067b14d37fSRalf S. Engelschalland the following words are omitted, 1007776e6b33SJilles Tjoelker.Ic in Li \&"$@\&" 1008a01459dfSStefan Farfelederis used instead. 10094b88c807SRodney W. GrimesThe words are expanded, and then the list is executed 101049e11e3aSSheldon Hearnrepeatedly with the variable set to each word in turn. 101149e11e3aSSheldon HearnThe 101249e11e3aSSheldon Hearn.Ic do 10136b15476eSSheldon Hearnand 101449e11e3aSSheldon Hearn.Ic done 101549e11e3aSSheldon Hearncommands may be replaced with 1016dfe302abSRuslan Ermilov.Ql { 101749e11e3aSSheldon Hearnand 1018dfe302abSRuslan Ermilov.Ql } . 1019ab72124fSSteve Price.Pp 102049e11e3aSSheldon HearnThe syntax of the 102149e11e3aSSheldon Hearn.Ic break 102249e11e3aSSheldon Hearnand 102349e11e3aSSheldon Hearn.Ic continue 102449e11e3aSSheldon Hearncommands is: 1025dfe302abSRuslan Ermilov.D1 Ic break Op Ar num 1026dfe302abSRuslan Ermilov.D1 Ic continue Op Ar num 1027ab72124fSSteve Price.Pp 102849e11e3aSSheldon HearnThe 102949e11e3aSSheldon Hearn.Ic break 103049e11e3aSSheldon Hearncommand terminates the 103149e11e3aSSheldon Hearn.Ar num 103249e11e3aSSheldon Hearninnermost 103349e11e3aSSheldon Hearn.Ic for 103449e11e3aSSheldon Hearnor 103549e11e3aSSheldon Hearn.Ic while 103649e11e3aSSheldon Hearnloops. 103749e11e3aSSheldon HearnThe 103849e11e3aSSheldon Hearn.Ic continue 103949e11e3aSSheldon Hearncommand continues with the next iteration of the innermost loop. 104030268dfaSJilles TjoelkerThese are implemented as special built-in commands. 1041ab72124fSSteve Price.Pp 104249e11e3aSSheldon HearnThe syntax of the 104349e11e3aSSheldon Hearn.Ic case 1044dfe302abSRuslan Ermilovcommand is: 1045dfe302abSRuslan Ermilov.Bd -unfilled -offset indent -compact 1046dfe302abSRuslan Ermilov.Ic case Ar word Ic in 1047f3aff7c9SBenjamin Kaduk.Ar pattern ) Ar list Li ;; 1048dfe302abSRuslan Ermilov.Ar ... 1049dfe302abSRuslan Ermilov.Ic esac 1050dfe302abSRuslan Ermilov.Ed 1051ab72124fSSteve Price.Pp 105249e11e3aSSheldon HearnThe pattern can actually be one or more patterns 105349e11e3aSSheldon Hearn(see 105449e11e3aSSheldon Hearn.Sx Shell Patterns 105549e11e3aSSheldon Hearndescribed later), 105649e11e3aSSheldon Hearnseparated by 1057dfe302abSRuslan Ermilov.Ql \&| 10586b15476eSSheldon Hearncharacters. 1059b97989d6SJilles TjoelkerTilde expansion, parameter expansion, command substitution, 1060b97989d6SJilles Tjoelkerarithmetic expansion and quote removal are applied to the word. 1061b97989d6SJilles TjoelkerThen, each pattern is expanded in turn using tilde expansion, 1062b97989d6SJilles Tjoelkerparameter expansion, command substitution and arithmetic expansion and 1063b97989d6SJilles Tjoelkerthe expanded form of the word is checked against it. 1064b97989d6SJilles TjoelkerIf a match is found, the corresponding list is executed. 1065c9afaa63SJilles TjoelkerIf the selected list is terminated by the control operator 1066c9afaa63SJilles Tjoelker.Ql ;& 1067c9afaa63SJilles Tjoelkerinstead of 1068c9afaa63SJilles Tjoelker.Ql ;; , 1069b97989d6SJilles Tjoelkerexecution continues with the next list, 1070b97989d6SJilles Tjoelkercontinuing until a list terminated with 1071b97989d6SJilles Tjoelker.Ql ;; 1072b97989d6SJilles Tjoelkeror the end of the 1073b97989d6SJilles Tjoelker.Ic case 1074b97989d6SJilles Tjoelkercommand. 1075ab72124fSSteve Price.Ss Grouping Commands Together 10764b88c807SRodney W. GrimesCommands may be grouped by writing either 1077dfe302abSRuslan Ermilov.Pp 107817e98da8SMateusz Piotrowski.Sm off 1079c013ca2cSGraham Percival.Bd -literal -offset indent 108017e98da8SMateusz Piotrowski.Po Ar list Pc 108117e98da8SMateusz Piotrowski.Ed 108217e98da8SMateusz Piotrowski.Sm on 1083ab72124fSSteve Price.Pp 10844b88c807SRodney W. Grimesor 1085c013ca2cSGraham Percival.Bd -literal -offset indent 108617e98da8SMateusz Piotrowski.No { Ar list ; } 108717e98da8SMateusz Piotrowski.Ed 1088ab72124fSSteve Price.Pp 1089ef89d04fSJilles TjoelkerThe first form executes the commands in a subshell environment. 109051a514adSJilles TjoelkerA subshell environment has its own copy of: 109151a514adSJilles Tjoelker.Bl -enum 109251a514adSJilles Tjoelker.It 109351a514adSJilles TjoelkerThe current working directory as set by 109451a514adSJilles Tjoelker.Ic cd . 109551a514adSJilles Tjoelker.It 109651a514adSJilles TjoelkerThe file creation mask as set by 109751a514adSJilles Tjoelker.Ic umask . 109851a514adSJilles Tjoelker.It 10990c35cec6SJilles TjoelkerResource limits as set by 11000c35cec6SJilles Tjoelker.Ic ulimit . 11010c35cec6SJilles Tjoelker.It 110251a514adSJilles TjoelkerReferences to open files. 110351a514adSJilles Tjoelker.It 110451a514adSJilles TjoelkerTraps as set by 110551a514adSJilles Tjoelker.Ic trap . 110651a514adSJilles Tjoelker.It 110751a514adSJilles TjoelkerKnown jobs. 110851a514adSJilles Tjoelker.It 110951a514adSJilles TjoelkerPositional parameters and variables. 111051a514adSJilles Tjoelker.It 111151a514adSJilles TjoelkerShell options. 111251a514adSJilles Tjoelker.It 111351a514adSJilles TjoelkerShell functions. 111451a514adSJilles Tjoelker.It 111551a514adSJilles TjoelkerShell aliases. 111651a514adSJilles Tjoelker.El 111751a514adSJilles Tjoelker.Pp 111851a514adSJilles TjoelkerThese are copied from the parent shell environment, 111951a514adSJilles Tjoelkerexcept that trapped (but not ignored) signals are reset to the default action 112051a514adSJilles Tjoelkerand known jobs are cleared. 112151a514adSJilles TjoelkerAny changes do not affect the parent shell environment. 112251a514adSJilles Tjoelker.Pp 112351a514adSJilles TjoelkerA subshell environment may be implemented as a child process or differently. 112451a514adSJilles TjoelkerIf job control is enabled in an interactive shell, 112551a514adSJilles Tjoelkercommands grouped in parentheses can be suspended and continued as a unit. 112651a514adSJilles Tjoelker.Pp 112754ccc8b5SJilles TjoelkerFor compatibility with other shells, 112854ccc8b5SJilles Tjoelkertwo open parentheses in sequence should be separated by whitespace. 112954ccc8b5SJilles Tjoelker.Pp 1130ef89d04fSJilles TjoelkerThe second form never forks another shell, 113149e11e3aSSheldon Hearnso it is slightly more efficient. 113249e11e3aSSheldon HearnGrouping commands together this way allows the user to 1133ab0a2172SSteve Priceredirect their output as though they were one program: 1134ab72124fSSteve Price.Bd -literal -offset indent 1135ee7dc416SSteve Price{ echo -n "hello"; echo " world"; } > greeting 1136ab72124fSSteve Price.Ed 1137ab72124fSSteve Price.Ss Functions 11384b88c807SRodney W. GrimesThe syntax of a function definition is 1139dfe302abSRuslan Ermilov.Pp 1140dfe302abSRuslan Ermilov.D1 Ar name Li \&( \&) Ar command 1141ab72124fSSteve Price.Pp 11424b88c807SRodney W. GrimesA function definition is an executable statement; when 1143dfe302abSRuslan Ermilovexecuted it installs a function named 1144dfe302abSRuslan Ermilov.Ar name 1145dfe302abSRuslan Ermilovand returns an 1146eccea571SRuslan Ermilovexit status of zero. 1147dfe302abSRuslan ErmilovThe 1148dfe302abSRuslan Ermilov.Ar command 1149dfe302abSRuslan Ermilovis normally a list 11506b15476eSSheldon Hearnenclosed between 1151dfe302abSRuslan Ermilov.Ql { 11526b15476eSSheldon Hearnand 1153dfe302abSRuslan Ermilov.Ql } . 1154ab72124fSSteve Price.Pp 11554b88c807SRodney W. GrimesVariables may be declared to be local to a function by 115649e11e3aSSheldon Hearnusing the 115749e11e3aSSheldon Hearn.Ic local 115849e11e3aSSheldon Hearncommand. 115949e11e3aSSheldon HearnThis should appear as the first statement of a function, 116049e11e3aSSheldon Hearnand the syntax is: 1161dfe302abSRuslan Ermilov.Pp 1162dfe302abSRuslan Ermilov.D1 Ic local Oo Ar variable ... Oc Op Fl 1163ab72124fSSteve Price.Pp 116449e11e3aSSheldon HearnThe 116549e11e3aSSheldon Hearn.Ic local 11668eed22b1SJens Schweikhardtcommand is implemented as a built-in command. 1167b1f60592SJilles TjoelkerThe exit status is zero 1168b1f60592SJilles Tjoelkerunless the command is not in a function or a variable name is invalid. 1169ab72124fSSteve Price.Pp 11704b88c807SRodney W. GrimesWhen a variable is made local, it inherits the initial 11714b88c807SRodney W. Grimesvalue and exported and readonly flags from the variable 11724b88c807SRodney W. Grimeswith the same name in the surrounding scope, if there is 1173eccea571SRuslan Ermilovone. 1174eccea571SRuslan ErmilovOtherwise, the variable is initially unset. 1175eccea571SRuslan ErmilovThe shell 1176e918fc8fSSheldon Hearnuses dynamic scoping, so that if the variable 1177dfe302abSRuslan Ermilov.Va x 1178e918fc8fSSheldon Hearnis made local to function 1179e918fc8fSSheldon Hearn.Em f , 1180e918fc8fSSheldon Hearnwhich then calls function 1181e918fc8fSSheldon Hearn.Em g , 1182e918fc8fSSheldon Hearnreferences to the variable 1183dfe302abSRuslan Ermilov.Va x 1184e918fc8fSSheldon Hearnmade inside 1185e918fc8fSSheldon Hearn.Em g 1186e918fc8fSSheldon Hearnwill refer to the variable 1187dfe302abSRuslan Ermilov.Va x 1188e918fc8fSSheldon Hearndeclared inside 1189e918fc8fSSheldon Hearn.Em f , 1190e918fc8fSSheldon Hearnnot to the global variable named 1191dfe302abSRuslan Ermilov.Va x . 1192ab72124fSSteve Price.Pp 11936b4bbd8aSCeri DaviesThe only special parameter that can be made local is 1194dfe302abSRuslan Ermilov.Ql - . 11956b15476eSSheldon HearnMaking 1196dfe302abSRuslan Ermilov.Ql - 119762c37116SJilles Tjoelkerlocal causes any shell options 119862c37116SJilles Tjoelker(including those that only have long names) 119962c37116SJilles Tjoelkerthat are 1200dfe302abSRuslan Ermilovchanged via the 1201dfe302abSRuslan Ermilov.Ic set 1202dfe302abSRuslan Ermilovcommand inside the function to be 12034b88c807SRodney W. Grimesrestored to their original values when the function 12044b88c807SRodney W. Grimesreturns. 1205ab72124fSSteve Price.Pp 120649e11e3aSSheldon HearnThe syntax of the 120749e11e3aSSheldon Hearn.Ic return 120849e11e3aSSheldon Hearncommand is 1209dfe302abSRuslan Ermilov.Pp 1210dfe302abSRuslan Ermilov.D1 Ic return Op Ar exitstatus 1211ab72124fSSteve Price.Pp 12122935c4ccSJilles TjoelkerIt terminates the current executional scope, returning from the closest 12132935c4ccSJilles Tjoelkernested function or sourced script; 12142935c4ccSJilles Tjoelkerif no function or sourced script is being executed, 12152935c4ccSJilles Tjoelkerit exits the shell instance. 121649e11e3aSSheldon HearnThe 121749e11e3aSSheldon Hearn.Ic return 121830268dfaSJilles Tjoelkercommand is implemented as a special built-in command. 1219ab72124fSSteve Price.Ss Variables and Parameters 1220eccea571SRuslan ErmilovThe shell maintains a set of parameters. 1221eccea571SRuslan ErmilovA parameter 12224445af21SJilles Tjoelkerdenoted by a name 12234445af21SJilles Tjoelker(consisting solely 12244445af21SJilles Tjoelkerof alphabetics, numerics, and underscores, 12254445af21SJilles Tjoelkerand starting with an alphabetic or an underscore) 12264445af21SJilles Tjoelkeris called a variable. 1227eccea571SRuslan ErmilovWhen starting up, 12284445af21SJilles Tjoelkerthe shell turns all environment variables with valid names into shell 1229eccea571SRuslan Ermilovvariables. 1230eccea571SRuslan ErmilovNew variables can be set using the form 1231dfe302abSRuslan Ermilov.Pp 1232dfe302abSRuslan Ermilov.D1 Ar name Ns = Ns Ar value 1233ab72124fSSteve Price.Pp 123449e11e3aSSheldon HearnA parameter can also be denoted by a number 12354b88c807SRodney W. Grimesor a special character as explained below. 1236ad56ebdcSJilles Tjoelker.Pp 1237ad56ebdcSJilles TjoelkerAssignments are expanded differently from other words: 1238ad56ebdcSJilles Tjoelkertilde expansion is also performed after the equals sign and after any colon 1239ad56ebdcSJilles Tjoelkerand usernames are also terminated by colons, 1240ad56ebdcSJilles Tjoelkerand field splitting and pathname expansion are not performed. 124184fbdd8cSJilles Tjoelker.Pp 124284fbdd8cSJilles TjoelkerThis special expansion applies not only to assignments that form a simple 124384fbdd8cSJilles Tjoelkercommand by themselves or precede a command word, 124484fbdd8cSJilles Tjoelkerbut also to words passed to the 124584fbdd8cSJilles Tjoelker.Ic export , 124684fbdd8cSJilles Tjoelker.Ic local 124784fbdd8cSJilles Tjoelkeror 124884fbdd8cSJilles Tjoelker.Ic readonly 124984fbdd8cSJilles Tjoelkerbuilt-in commands that have this form. 125084fbdd8cSJilles TjoelkerFor this, the builtin's name must be literal 125184fbdd8cSJilles Tjoelker(not the result of an expansion) 125284fbdd8cSJilles Tjoelkerand may optionally be preceded by one or more literal instances of 125384fbdd8cSJilles Tjoelker.Ic command 125484fbdd8cSJilles Tjoelkerwithout options. 1255ab72124fSSteve Price.Ss Positional Parameters 125649e11e3aSSheldon HearnA positional parameter is a parameter denoted by a number greater than zero. 1257ab72124fSSteve PriceThe shell sets these initially to the values of its command line 1258eccea571SRuslan Ermilovarguments that follow the name of the shell script. 1259eccea571SRuslan ErmilovThe 1260c644db6aSSheldon Hearn.Ic set 12618eed22b1SJens Schweikhardtbuilt-in command can also be used to set or reset them. 1262ab72124fSSteve Price.Ss Special Parameters 1263626a7b1dSJilles TjoelkerSpecial parameters are parameters denoted by a single special character 1264626a7b1dSJilles Tjoelkeror the digit zero. 1265626a7b1dSJilles TjoelkerThey are shown in the following list, exactly as they would appear in input 126643d6677bSAlfred Perlsteintyped by the user or in the source of a shell script. 1267ab72124fSSteve Price.Bl -hang 126843d6677bSAlfred Perlstein.It Li $* 1269eccea571SRuslan ErmilovExpands to the positional parameters, starting from one. 1270eccea571SRuslan ErmilovWhen 12714b88c807SRodney W. Grimesthe expansion occurs within a double-quoted string 12724b88c807SRodney W. Grimesit expands to a single field with the value of each parameter 127349e11e3aSSheldon Hearnseparated by the first character of the 1274dfe302abSRuslan Ermilov.Va IFS 127549e11e3aSSheldon Hearnvariable, 1276dfe302abSRuslan Ermilovor by a space if 1277dfe302abSRuslan Ermilov.Va IFS 127849e11e3aSSheldon Hearnis unset. 127943d6677bSAlfred Perlstein.It Li $@ 1280eccea571SRuslan ErmilovExpands to the positional parameters, starting from one. 1281eccea571SRuslan ErmilovWhen 12824b88c807SRodney W. Grimesthe expansion occurs within double-quotes, each positional 12834b88c807SRodney W. Grimesparameter expands as a separate argument. 12844b88c807SRodney W. GrimesIf there are no positional parameters, the 1285e918fc8fSSheldon Hearnexpansion of 1286e918fc8fSSheldon Hearn.Li @ 1287e918fc8fSSheldon Hearngenerates zero arguments, even when 1288e918fc8fSSheldon Hearn.Li @ 1289eccea571SRuslan Ermilovis double-quoted. 1290eccea571SRuslan ErmilovWhat this basically means, for example, is 1291dfe302abSRuslan Ermilovif 1292dfe302abSRuslan Ermilov.Li $1 1293dfe302abSRuslan Ermilovis 1294dfe302abSRuslan Ermilov.Dq Li abc 1295dfe302abSRuslan Ermilovand 1296dfe302abSRuslan Ermilov.Li $2 1297dfe302abSRuslan Ermilovis 1298dfe302abSRuslan Ermilov.Dq Li "def ghi" , 12996b15476eSSheldon Hearnthen 1300776e6b33SJilles Tjoelker.Li \&"$@\&" 13016b15476eSSheldon Hearnexpands to 13024b88c807SRodney W. Grimesthe two arguments: 1303ab72124fSSteve Price.Bd -literal -offset indent 13044b88c807SRodney W. Grimes"abc" "def ghi" 1305ab72124fSSteve Price.Ed 130643d6677bSAlfred Perlstein.It Li $# 13074b88c807SRodney W. GrimesExpands to the number of positional parameters. 1308dfe302abSRuslan Ermilov.It Li $? 13094b88c807SRodney W. GrimesExpands to the exit status of the most recent pipeline. 131043d6677bSAlfred Perlstein.It Li $- 1311ab72124fSSteve Price(hyphen) Expands to the current option flags (the single-letter 13124b88c807SRodney W. Grimesoption names concatenated into a string) as specified on 1313dfe302abSRuslan Ermilovinvocation, by the 1314dfe302abSRuslan Ermilov.Ic set 1315dfe302abSRuslan Ermilovbuilt-in command, or implicitly 13164b88c807SRodney W. Grimesby the shell. 131743d6677bSAlfred Perlstein.It Li $$ 1318eccea571SRuslan ErmilovExpands to the process ID of the invoked shell. 1319eccea571SRuslan ErmilovA subshell 1320dfe302abSRuslan Ermilovretains the same value of 1321dfe302abSRuslan Ermilov.Va $ 1322dfe302abSRuslan Ermilovas its parent. 1323dfe302abSRuslan Ermilov.It Li $! 13244b88c807SRodney W. GrimesExpands to the process ID of the most recent background 1325eccea571SRuslan Ermilovcommand executed from the current shell. 1326eccea571SRuslan ErmilovFor a 13274b88c807SRodney W. Grimespipeline, the process ID is that of the last command in the 13284b88c807SRodney W. Grimespipeline. 1329ed4c3b5fSJilles TjoelkerIf this parameter is referenced, the shell will remember 1330ed4c3b5fSJilles Tjoelkerthe process ID and its exit status until the 1331ed4c3b5fSJilles Tjoelker.Ic wait 1332ed4c3b5fSJilles Tjoelkerbuilt-in command reports completion of the process. 133343d6677bSAlfred Perlstein.It Li $0 133457a40f7dSJilles Tjoelker(zero) Expands to the name of the shell script if passed on the command line, 133557a40f7dSJilles Tjoelkerthe 133657a40f7dSJilles Tjoelker.Ar name 133757a40f7dSJilles Tjoelkeroperand if given (with 133857a40f7dSJilles Tjoelker.Fl c ) 133957a40f7dSJilles Tjoelkeror otherwise argument 0 passed to the shell. 1340ab72124fSSteve Price.El 13411788b7ffSJilles Tjoelker.Ss Special Variables 13421788b7ffSJilles TjoelkerThe following variables are set by the shell or 13431788b7ffSJilles Tjoelkerhave special meaning to it: 13441788b7ffSJilles Tjoelker.Bl -tag -width ".Va HISTSIZE" 13451788b7ffSJilles Tjoelker.It Va CDPATH 13461788b7ffSJilles TjoelkerThe search path used with the 13471788b7ffSJilles Tjoelker.Ic cd 13481788b7ffSJilles Tjoelkerbuilt-in. 13491788b7ffSJilles Tjoelker.It Va EDITOR 13501788b7ffSJilles TjoelkerThe fallback editor used with the 13511788b7ffSJilles Tjoelker.Ic fc 13521788b7ffSJilles Tjoelkerbuilt-in. 13531788b7ffSJilles TjoelkerIf not set, the default editor is 13541788b7ffSJilles Tjoelker.Xr ed 1 . 13551788b7ffSJilles Tjoelker.It Va FCEDIT 13561788b7ffSJilles TjoelkerThe default editor used with the 13571788b7ffSJilles Tjoelker.Ic fc 13581788b7ffSJilles Tjoelkerbuilt-in. 1359988b1bb0SBaptiste Daroussin.It Va HISTFILE 1360988b1bb0SBaptiste DaroussinFile used for persistent history storage. 1361988b1bb0SBaptiste DaroussinIf unset 1362988b1bb0SBaptiste Daroussin.Pa ~/.sh_history 1363988b1bb0SBaptiste Daroussinwill be used. 1364988b1bb0SBaptiste DaroussinIf set but empty or 1365988b1bb0SBaptiste Daroussin.Va HISTSIZE 1366988b1bb0SBaptiste Daroussinis set to 0 1367988b1bb0SBaptiste Daroussinthe shell will not load and save the history. 13681788b7ffSJilles Tjoelker.It Va HISTSIZE 13691788b7ffSJilles TjoelkerThe number of previous commands that are accessible. 13701788b7ffSJilles Tjoelker.It Va HOME 13711788b7ffSJilles TjoelkerThe user's home directory, 13721788b7ffSJilles Tjoelkerused in tilde expansion and as a default directory for the 13731788b7ffSJilles Tjoelker.Ic cd 13741788b7ffSJilles Tjoelkerbuilt-in. 13751788b7ffSJilles Tjoelker.It Va IFS 13761788b7ffSJilles TjoelkerInput Field Separators. 13777cca93e6SJilles TjoelkerThis is initialized at startup to 13781788b7ffSJilles Tjoelker.Aq space , 13791788b7ffSJilles Tjoelker.Aq tab , 13801788b7ffSJilles Tjoelkerand 1381ad56ebdcSJilles Tjoelker.Aq newline 1382ad56ebdcSJilles Tjoelkerin that order. 13837cca93e6SJilles TjoelkerThis value also applies if 1384ad56ebdcSJilles Tjoelker.Va IFS 1385ad56ebdcSJilles Tjoelkeris unset, but not if it is set to the empty string. 13861788b7ffSJilles TjoelkerSee the 13871788b7ffSJilles Tjoelker.Sx White Space Splitting 13881788b7ffSJilles Tjoelkersection for more details. 13891788b7ffSJilles Tjoelker.It Va LINENO 13901788b7ffSJilles TjoelkerThe current line number in the script or function. 13911788b7ffSJilles Tjoelker.It Va MAIL 13921788b7ffSJilles TjoelkerThe name of a mail file, that will be checked for the arrival of new 13931788b7ffSJilles Tjoelkermail. 13941788b7ffSJilles TjoelkerOverridden by 13951788b7ffSJilles Tjoelker.Va MAILPATH . 13961788b7ffSJilles Tjoelker.It Va MAILPATH 13971788b7ffSJilles TjoelkerA colon 13981788b7ffSJilles Tjoelker.Pq Ql \&: 13991788b7ffSJilles Tjoelkerseparated list of file names, for the shell to check for incoming 14001788b7ffSJilles Tjoelkermail. 14011788b7ffSJilles TjoelkerThis variable overrides the 14021788b7ffSJilles Tjoelker.Va MAIL 14031788b7ffSJilles Tjoelkersetting. 14041788b7ffSJilles TjoelkerThere is a maximum of 10 mailboxes that can be monitored at once. 14054445af21SJilles Tjoelker.It Va OPTIND 14064445af21SJilles TjoelkerThe index of the next argument to be processed by 14074445af21SJilles Tjoelker.Ic getopts . 14084445af21SJilles TjoelkerThis is initialized to 1 at startup. 14091788b7ffSJilles Tjoelker.It Va PATH 14101788b7ffSJilles TjoelkerThe default search path for executables. 14111788b7ffSJilles TjoelkerSee the 14121788b7ffSJilles Tjoelker.Sx Path Search 14131788b7ffSJilles Tjoelkersection for details. 14141788b7ffSJilles Tjoelker.It Va PPID 14151788b7ffSJilles TjoelkerThe parent process ID of the invoked shell. 14161788b7ffSJilles TjoelkerThis is set at startup 14171788b7ffSJilles Tjoelkerunless this variable is in the environment. 14181788b7ffSJilles TjoelkerA later change of parent process ID is not reflected. 14191788b7ffSJilles TjoelkerA subshell retains the same value of 14201788b7ffSJilles Tjoelker.Va PPID . 14211788b7ffSJilles Tjoelker.It Va PS1 14221788b7ffSJilles TjoelkerThe primary prompt string, which defaults to 14231788b7ffSJilles Tjoelker.Dq Li "$ " , 14241788b7ffSJilles Tjoelkerunless you are the superuser, in which case it defaults to 14251788b7ffSJilles Tjoelker.Dq Li "# " . 14261ca3beb9SJoel Dahl.Va PS1 14271ca3beb9SJoel Dahlmay include any of the following formatting sequences, 14281ca3beb9SJoel Dahlwhich are replaced by the given information: 14291ca3beb9SJoel Dahl.Bl -tag -width indent 1430a675eaecSPiotr Pawel Stefaniak.It Li \eD{format} 1431a675eaecSPiotr Pawel StefaniakThe current time in 1432a675eaecSPiotr Pawel Stefaniak.Xr strftime 3 1433a675eaecSPiotr Pawel Stefaniak.Ar format . 1434a675eaecSPiotr Pawel StefaniakThe braces are required. 1435a675eaecSPiotr Pawel StefaniakEmpty 1436a675eaecSPiotr Pawel Stefaniak.Ar format 1437a675eaecSPiotr Pawel Stefaniakis equivalent to 1438a675eaecSPiotr Pawel Stefaniak\&%X, 1439a675eaecSPiotr Pawel Stefaniaknational representation of the time. 14401ca3beb9SJoel Dahl.It Li \eH 14412770ce60SWarren BlockThis system's fully-qualified hostname (FQDN). 1442ae100660SDon Lewis.It Li \eh 14432770ce60SWarren BlockThis system's hostname. 1444d81ca439SEdward Tomasz Napierala.It Li \eu 1445d81ca439SEdward Tomasz NapieralaUser name. 14461ca3beb9SJoel Dahl.It Li \eW 14471ca3beb9SJoel DahlThe final component of the current working directory. 14481ca3beb9SJoel Dahl.It Li \ew 14491ca3beb9SJoel DahlThe entire path of the current working directory. 14501ca3beb9SJoel Dahl.It Li \e$ 14511ca3beb9SJoel DahlSuperuser status. 14521ca3beb9SJoel Dahl.Dq Li "$" 14531ca3beb9SJoel Dahlfor normal users and 14541ca3beb9SJoel Dahl.Dq Li "#" 14551ca3beb9SJoel Dahlfor superusers. 14561ca3beb9SJoel Dahl.It Li \e\e 14571ca3beb9SJoel DahlA literal backslash. 14583cf65f8aSJuraj Lutter.It Li \e[ 14593cf65f8aSJuraj LutterStart of a sequence of non-printing characters (used, for example, 14603cf65f8aSJuraj Lutterto embed ANSI CSI sequences into the prompt). 14613cf65f8aSJuraj Lutter.It Li \e] 14623cf65f8aSJuraj LutterEnd of a sequence of non-printing characters. 14633cf65f8aSJuraj Lutter.El 14643cf65f8aSJuraj Lutter.Pp 14653cf65f8aSJuraj LutterThe following special and non-printing characters are supported 14663cf65f8aSJuraj Lutterwithin the sequence of non-printing characters: 14673cf65f8aSJuraj Lutter.Bl -tag -width indent 14683cf65f8aSJuraj Lutter.It Li \ea 14693cf65f8aSJuraj LutterEmits ASCII BEL (0x07, 007) character. 14703cf65f8aSJuraj Lutter.It Li \ee 14713cf65f8aSJuraj LutterEmits ASCII ESC (0x1b, 033) character. 14723cf65f8aSJuraj Lutter.It Li \er 14733cf65f8aSJuraj LutterEmits ASCII CR (0x0d, 015) character. 14743cf65f8aSJuraj Lutter.It Li \en 14753cf65f8aSJuraj LutterEmits CRLF sequence. 14761ca3beb9SJoel Dahl.El 14771788b7ffSJilles Tjoelker.It Va PS2 14781788b7ffSJilles TjoelkerThe secondary prompt string, which defaults to 14791788b7ffSJilles Tjoelker.Dq Li "> " . 14801ca3beb9SJoel Dahl.Va PS2 14811ca3beb9SJoel Dahlmay include any of the formatting sequences from 14821ca3beb9SJoel Dahl.Va PS1 . 14831788b7ffSJilles Tjoelker.It Va PS4 14841788b7ffSJilles TjoelkerThe prefix for the trace output (if 14851788b7ffSJilles Tjoelker.Fl x 14861788b7ffSJilles Tjoelkeris active). 14871788b7ffSJilles TjoelkerThe default is 14881788b7ffSJilles Tjoelker.Dq Li "+ " . 14891788b7ffSJilles Tjoelker.El 1490ab72124fSSteve Price.Ss Word Expansions 14914b88c807SRodney W. GrimesThis clause describes the various expansions that are 1492eccea571SRuslan Ermilovperformed on words. 1493eccea571SRuslan ErmilovNot all expansions are performed on 14944b88c807SRodney W. Grimesevery word, as explained later. 1495ab72124fSSteve Price.Pp 14964b88c807SRodney W. GrimesTilde expansions, parameter expansions, command substitutions, 14974b88c807SRodney W. Grimesarithmetic expansions, and quote removals that occur within 1498eccea571SRuslan Ermilova single word expand to a single field. 1499eccea571SRuslan ErmilovIt is only field 15004b88c807SRodney W. Grimessplitting or pathname expansion that can create multiple 1501e6d3cf26SSheldon Hearnfields from a single word. 1502e6d3cf26SSheldon HearnThe single exception to this rule is 1503e918fc8fSSheldon Hearnthe expansion of the special parameter 1504dfe302abSRuslan Ermilov.Va @ 1505e918fc8fSSheldon Hearnwithin double-quotes, 1506e6d3cf26SSheldon Hearnas was described above. 1507ab72124fSSteve Price.Pp 15084b88c807SRodney W. GrimesThe order of word expansion is: 1509ab72124fSSteve Price.Bl -enum 1510ab72124fSSteve Price.It 1511ab72124fSSteve PriceTilde Expansion, Parameter Expansion, Command Substitution, 15124b88c807SRodney W. GrimesArithmetic Expansion (these all occur at the same time). 1513ab72124fSSteve Price.It 151449e11e3aSSheldon HearnField Splitting is performed on fields generated by step (1) 151549e11e3aSSheldon Hearnunless the 1516dfe302abSRuslan Ermilov.Va IFS 151749e11e3aSSheldon Hearnvariable is null. 1518ab72124fSSteve Price.It 151949e11e3aSSheldon HearnPathname Expansion (unless the 152049e11e3aSSheldon Hearn.Fl f 152149e11e3aSSheldon Hearnoption is in effect). 1522ab72124fSSteve Price.It 1523ab72124fSSteve PriceQuote Removal. 1524ab72124fSSteve Price.El 1525ab72124fSSteve Price.Pp 152649e11e3aSSheldon HearnThe 1527dfe302abSRuslan Ermilov.Ql $ 152849e11e3aSSheldon Hearncharacter is used to introduce parameter expansion, command 152936cf3efeSJilles Tjoelkersubstitution, or arithmetic expansion. 1530ab72124fSSteve Price.Ss Tilde Expansion (substituting a user's home directory) 153149e11e3aSSheldon HearnA word beginning with an unquoted tilde character 1532a762afe5SGiorgos Keramidas.Pq Ql ~ 153349e11e3aSSheldon Hearnis 153449e11e3aSSheldon Hearnsubjected to tilde expansion. 153549e11e3aSSheldon HearnAll the characters up to a slash 1536a762afe5SGiorgos Keramidas.Pq Ql / 153749e11e3aSSheldon Hearnor the end of the word are treated as a username 1538eccea571SRuslan Ermilovand are replaced with the user's home directory. 1539eccea571SRuslan ErmilovIf the 1540dfe302abSRuslan Ermilovusername is missing (as in 1541dfe302abSRuslan Ermilov.Pa ~/foobar ) , 1542dfe302abSRuslan Ermilovthe tilde is replaced with the value of the 15431788b7ffSJilles Tjoelker.Va HOME 1544dfe302abSRuslan Ermilovvariable (the current user's home directory). 1545ab72124fSSteve Price.Ss Parameter Expansion 15464b88c807SRodney W. GrimesThe format for parameter expansion is as follows: 1547ab72124fSSteve Price.Pp 1548dfe302abSRuslan Ermilov.D1 Li ${ Ns Ar expression Ns Li } 1549dfe302abSRuslan Ermilov.Pp 1550dfe302abSRuslan Ermilovwhere 1551dfe302abSRuslan Ermilov.Ar expression 1552dfe302abSRuslan Ermilovconsists of all characters until the matching 1553dfe302abSRuslan Ermilov.Ql } . 155449e11e3aSSheldon HearnAny 1555dfe302abSRuslan Ermilov.Ql } 1556f35d74beSJilles Tjoelkerescaped by a backslash or within a single-quoted or double-quoted 1557f35d74beSJilles Tjoelkerstring, and characters in 15584b88c807SRodney W. Grimesembedded arithmetic expansions, command substitutions, and variable 155949e11e3aSSheldon Hearnexpansions, are not examined in determining the matching 1560dfe302abSRuslan Ermilov.Ql } . 1561f35d74beSJilles TjoelkerIf the variants with 1562227c8e2aSJilles Tjoelker.Ql + , 1563227c8e2aSJilles Tjoelker.Ql - , 1564227c8e2aSJilles Tjoelker.Ql = 1565227c8e2aSJilles Tjoelkeror 1566f35d74beSJilles Tjoelker.Ql ?\& 1567f35d74beSJilles Tjoelkeroccur within a double-quoted string, 1568f35d74beSJilles Tjoelkeras an extension there may be unquoted parts 1569f35d74beSJilles Tjoelker(via double-quotes inside the expansion); 1570227c8e2aSJilles Tjoelker.Ql } 1571f35d74beSJilles Tjoelkerwithin such parts are also not examined in determining the matching 1572227c8e2aSJilles Tjoelker.Ql } . 1573ab72124fSSteve Price.Pp 15744b88c807SRodney W. GrimesThe simplest form for parameter expansion is: 1575ab72124fSSteve Price.Pp 1576dfe302abSRuslan Ermilov.D1 Li ${ Ns Ar parameter Ns Li } 1577dfe302abSRuslan Ermilov.Pp 1578dfe302abSRuslan ErmilovThe value, if any, of 1579dfe302abSRuslan Ermilov.Ar parameter 1580dfe302abSRuslan Ermilovis substituted. 1581ab72124fSSteve Price.Pp 15824b88c807SRodney W. GrimesThe parameter name or symbol can be enclosed in braces, which are 15834b88c807SRodney W. Grimesoptional except for positional parameters with more than one digit or 15844b88c807SRodney W. Grimeswhen parameter is followed by a character that could be interpreted as 15854b88c807SRodney W. Grimespart of the name. 1586ab72124fSSteve PriceIf a parameter expansion occurs inside double-quotes: 1587ab72124fSSteve Price.Bl -enum 1588ab72124fSSteve Price.It 1589ab72124fSSteve PriceField splitting is not performed on the results of the 1590e918fc8fSSheldon Hearnexpansion, with the exception of the special parameter 1591dfe302abSRuslan Ermilov.Va @ . 1592ad56ebdcSJilles Tjoelker.It 1593ad56ebdcSJilles TjoelkerPathname expansion is not performed on the results of the 1594ad56ebdcSJilles Tjoelkerexpansion. 1595ab72124fSSteve Price.El 1596ab72124fSSteve Price.Pp 15974b88c807SRodney W. GrimesIn addition, a parameter expansion can be modified by using one of the 15984b88c807SRodney W. Grimesfollowing formats. 159981e9cda2SRuslan Ermilov.Bl -tag -width indent 1600dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li :- Ns Ar word Ns Li } 1601eccea571SRuslan ErmilovUse Default Values. 1602dfe302abSRuslan ErmilovIf 1603dfe302abSRuslan Ermilov.Ar parameter 1604dfe302abSRuslan Ermilovis unset or null, the expansion of 1605dfe302abSRuslan Ermilov.Ar word 1606dfe302abSRuslan Ermilovis substituted; otherwise, the value of 1607dfe302abSRuslan Ermilov.Ar parameter 1608dfe302abSRuslan Ermilovis substituted. 1609dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li := Ns Ar word Ns Li } 1610eccea571SRuslan ErmilovAssign Default Values. 1611dfe302abSRuslan ErmilovIf 1612dfe302abSRuslan Ermilov.Ar parameter 1613dfe302abSRuslan Ermilovis unset or null, the expansion of 1614dfe302abSRuslan Ermilov.Ar word 1615dfe302abSRuslan Ermilovis assigned to 1616dfe302abSRuslan Ermilov.Ar parameter . 1617eccea571SRuslan ErmilovIn all cases, the 1618dfe302abSRuslan Ermilovfinal value of 1619dfe302abSRuslan Ermilov.Ar parameter 1620dfe302abSRuslan Ermilovis substituted. 1621b139165cSJilles TjoelkerQuoting inside 1622b139165cSJilles Tjoelker.Ar word 1623b139165cSJilles Tjoelkerdoes not prevent field splitting or pathname expansion. 1624eccea571SRuslan ErmilovOnly variables, not positional 16254b88c807SRodney W. Grimesparameters or special parameters, can be 16264b88c807SRodney W. Grimesassigned in this way. 1627dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li :? Ns Oo Ar word Oc Ns Li } 1628eccea571SRuslan ErmilovIndicate Error if Null or Unset. 1629eccea571SRuslan ErmilovIf 1630dfe302abSRuslan Ermilov.Ar parameter 1631dfe302abSRuslan Ermilovis unset or null, the expansion of 1632dfe302abSRuslan Ermilov.Ar word 1633dfe302abSRuslan Ermilov(or a message indicating it is unset if 1634dfe302abSRuslan Ermilov.Ar word 1635dfe302abSRuslan Ermilovis omitted) is written to standard 16364b88c807SRodney W. Grimeserror and the shell exits with a nonzero 1637e6d3cf26SSheldon Hearnexit status. 1638e6d3cf26SSheldon HearnOtherwise, the value of 1639dfe302abSRuslan Ermilov.Ar parameter 1640dfe302abSRuslan Ermilovis substituted. 1641eccea571SRuslan ErmilovAn 16424b88c807SRodney W. Grimesinteractive shell need not exit. 1643dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li :+ Ns Ar word Ns Li } 1644eccea571SRuslan ErmilovUse Alternate Value. 1645dfe302abSRuslan ErmilovIf 1646dfe302abSRuslan Ermilov.Ar parameter 1647dfe302abSRuslan Ermilovis unset or null, null is substituted; 1648dfe302abSRuslan Ermilovotherwise, the expansion of 1649dfe302abSRuslan Ermilov.Ar word 1650dfe302abSRuslan Ermilovis substituted. 16511413f7deSTony Finch.El 1652ab72124fSSteve Price.Pp 16534b88c807SRodney W. GrimesIn the parameter expansions shown previously, use of the colon in the 16544b88c807SRodney W. Grimesformat results in a test for a parameter that is unset or null; omission 16554b88c807SRodney W. Grimesof the colon results in a test for a parameter that is only unset. 1656227c8e2aSJilles Tjoelker.Pp 1657227c8e2aSJilles TjoelkerThe 1658227c8e2aSJilles Tjoelker.Ar word 1659227c8e2aSJilles Tjoelkerinherits the type of quoting 1660227c8e2aSJilles Tjoelker(unquoted, double-quoted or here-document) 1661227c8e2aSJilles Tjoelkerfrom the surroundings, 1662227c8e2aSJilles Tjoelkerwith the exception that a backslash that quotes a closing brace is removed 1663227c8e2aSJilles Tjoelkerduring quote removal. 16641413f7deSTony Finch.Bl -tag -width indent 1665dfe302abSRuslan Ermilov.It Li ${# Ns Ar parameter Ns Li } 1666eccea571SRuslan ErmilovString Length. 1667eccea571SRuslan ErmilovThe length in characters of 1668dfe302abSRuslan Ermilovthe value of 1669dfe302abSRuslan Ermilov.Ar parameter . 167071337c33SSheldon Hearn.El 1671ab72124fSSteve Price.Pp 16724b88c807SRodney W. GrimesThe following four varieties of parameter expansion provide for substring 167349e11e3aSSheldon Hearnprocessing. 167449e11e3aSSheldon HearnIn each case, pattern matching notation 167549e11e3aSSheldon Hearn(see 167649e11e3aSSheldon Hearn.Sx Shell Patterns ) , 167749e11e3aSSheldon Hearnrather than regular expression notation, 167849e11e3aSSheldon Hearnis used to evaluate the patterns. 1679e918fc8fSSheldon HearnIf parameter is one of the special parameters 1680dfe302abSRuslan Ermilov.Va * 168149e11e3aSSheldon Hearnor 1682dfe302abSRuslan Ermilov.Va @ , 168349e11e3aSSheldon Hearnthe result of the expansion is unspecified. 16844b88c807SRodney W. GrimesEnclosing the full parameter expansion string in double-quotes does not 16854b88c807SRodney W. Grimescause the following four varieties of pattern characters to be quoted, 16864b88c807SRodney W. Grimeswhereas quoting characters within the braces has this effect. 168781e9cda2SRuslan Ermilov.Bl -tag -width indent 1688dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li % Ns Ar word Ns Li } 1689eccea571SRuslan ErmilovRemove Smallest Suffix Pattern. 1690dfe302abSRuslan ErmilovThe 1691dfe302abSRuslan Ermilov.Ar word 1692eccea571SRuslan Ermilovis expanded to produce a pattern. 1693eccea571SRuslan ErmilovThe 16944b88c807SRodney W. Grimesparameter expansion then results in 1695dfe302abSRuslan Ermilov.Ar parameter , 1696dfe302abSRuslan Ermilovwith the smallest portion of the 16974b88c807SRodney W. Grimessuffix matched by the pattern deleted. 1698dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li %% Ns Ar word Ns Li } 1699eccea571SRuslan ErmilovRemove Largest Suffix Pattern. 1700dfe302abSRuslan ErmilovThe 1701dfe302abSRuslan Ermilov.Ar word 1702eccea571SRuslan Ermilovis expanded to produce a pattern. 1703eccea571SRuslan ErmilovThe 17044b88c807SRodney W. Grimesparameter expansion then results in 1705dfe302abSRuslan Ermilov.Ar parameter , 1706dfe302abSRuslan Ermilovwith the largest portion of the 17074b88c807SRodney W. Grimessuffix matched by the pattern deleted. 1708dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li # Ns Ar word Ns Li } 1709eccea571SRuslan ErmilovRemove Smallest Prefix Pattern. 1710dfe302abSRuslan ErmilovThe 1711dfe302abSRuslan Ermilov.Ar word 1712eccea571SRuslan Ermilovis expanded to produce a pattern. 1713eccea571SRuslan ErmilovThe 17144b88c807SRodney W. Grimesparameter expansion then results in 1715dfe302abSRuslan Ermilov.Ar parameter , 1716dfe302abSRuslan Ermilovwith the smallest portion of the 17174b88c807SRodney W. Grimesprefix matched by the pattern deleted. 1718dfe302abSRuslan Ermilov.It Li ${ Ns Ar parameter Ns Li ## Ns Ar word Ns Li } 1719eccea571SRuslan ErmilovRemove Largest Prefix Pattern. 1720dfe302abSRuslan ErmilovThe 1721dfe302abSRuslan Ermilov.Ar word 1722eccea571SRuslan Ermilovis expanded to produce a pattern. 1723eccea571SRuslan ErmilovThe 17244b88c807SRodney W. Grimesparameter expansion then results in 1725dfe302abSRuslan Ermilov.Ar parameter , 1726dfe302abSRuslan Ermilovwith the largest portion of the 17274b88c807SRodney W. Grimesprefix matched by the pattern deleted. 1728ab72124fSSteve Price.El 1729ab72124fSSteve Price.Ss Command Substitution 17304b88c807SRodney W. GrimesCommand substitution allows the output of a command to be substituted in 1731eccea571SRuslan Ermilovplace of the command name itself. 1732eccea571SRuslan ErmilovCommand substitution occurs when 17334b88c807SRodney W. Grimesthe command is enclosed as follows: 1734dfe302abSRuslan Ermilov.Pp 1735dfe302abSRuslan Ermilov.D1 Li $( Ns Ar command Ns Li )\& 1736ab72124fSSteve Price.Pp 173749e11e3aSSheldon Hearnor the backquoted version: 1738dfe302abSRuslan Ermilov.Pp 1739dfe302abSRuslan Ermilov.D1 Li ` Ns Ar command Ns Li ` 1740ab72124fSSteve Price.Pp 1741ef89d04fSJilles TjoelkerThe shell expands the command substitution by executing command 1742ef89d04fSJilles Tjoelkerand replacing the command substitution 174349e11e3aSSheldon Hearnwith the standard output of the command, 174449e11e3aSSheldon Hearnremoving sequences of one or more newlines at the end of the substitution. 174549e11e3aSSheldon HearnEmbedded newlines before the end of the output are not removed; 174649e11e3aSSheldon Hearnhowever, during field splitting, they may be translated into spaces 174749e11e3aSSheldon Hearndepending on the value of 1748dfe302abSRuslan Ermilov.Va IFS 174949e11e3aSSheldon Hearnand the quoting that is in effect. 1750ef89d04fSJilles TjoelkerThe command is executed in a subshell environment, 1751ef89d04fSJilles Tjoelkerexcept that the built-in commands 1752ef89d04fSJilles Tjoelker.Ic jobid , 1753ef89d04fSJilles Tjoelker.Ic jobs , 1754ef89d04fSJilles Tjoelkerand 1755ef89d04fSJilles Tjoelker.Ic trap 175651a514adSJilles Tjoelkerreturn information about the parent shell environment 175751a514adSJilles Tjoelkerand 175851a514adSJilles Tjoelker.Ic times 175951a514adSJilles Tjoelkerreturns information about the same process 1760c543e1aeSJilles Tjoelkerif they are the only command in a command substitution. 176154ccc8b5SJilles Tjoelker.Pp 176254ccc8b5SJilles TjoelkerIf a command substitution of the 176354ccc8b5SJilles Tjoelker.Li $( 176454ccc8b5SJilles Tjoelkerform begins with a subshell, 176554ccc8b5SJilles Tjoelkerthe 176654ccc8b5SJilles Tjoelker.Li $( 176754ccc8b5SJilles Tjoelkerand 17685127efa3SJoel Dahl.Li (\& 176954ccc8b5SJilles Tjoelkermust be separated by whitespace 177054ccc8b5SJilles Tjoelkerto avoid ambiguity with arithmetic expansion. 1771ab72124fSSteve Price.Ss Arithmetic Expansion 17724b88c807SRodney W. GrimesArithmetic expansion provides a mechanism for evaluating an arithmetic 1773e6d3cf26SSheldon Hearnexpression and substituting its value. 1774e6d3cf26SSheldon HearnThe format for arithmetic expansion is as follows: 1775ab72124fSSteve Price.Pp 1776dfe302abSRuslan Ermilov.D1 Li $(( Ns Ar expression Ns Li )) 1777dfe302abSRuslan Ermilov.Pp 1778dfe302abSRuslan ErmilovThe 1779dfe302abSRuslan Ermilov.Ar expression 1780dfe302abSRuslan Ermilovis treated as if it were in double-quotes, except 1781eccea571SRuslan Ermilovthat a double-quote inside the expression is not treated specially. 1782eccea571SRuslan ErmilovThe 1783dfe302abSRuslan Ermilovshell expands all tokens in the 1784dfe302abSRuslan Ermilov.Ar expression 1785dfe302abSRuslan Ermilovfor parameter expansion, 178636cf3efeSJilles Tjoelkercommand substitution, 178736cf3efeSJilles Tjoelkerarithmetic expansion 178836cf3efeSJilles Tjoelkerand quote removal. 1789ab72124fSSteve Price.Pp 179036cf3efeSJilles TjoelkerThe allowed expressions are a subset of C expressions, 179136cf3efeSJilles Tjoelkersummarized below. 179236cf3efeSJilles Tjoelker.Bl -tag -width "Variables" -offset indent 179336cf3efeSJilles Tjoelker.It Values 179436cf3efeSJilles TjoelkerAll values are of type 179536cf3efeSJilles Tjoelker.Ft intmax_t . 179636cf3efeSJilles Tjoelker.It Constants 179736cf3efeSJilles TjoelkerDecimal, octal (starting with 179836cf3efeSJilles Tjoelker.Li 0 ) 179936cf3efeSJilles Tjoelkerand hexadecimal (starting with 180036cf3efeSJilles Tjoelker.Li 0x ) 180136cf3efeSJilles Tjoelkerinteger constants. 180236cf3efeSJilles Tjoelker.It Variables 180336cf3efeSJilles TjoelkerShell variables can be read and written 180436cf3efeSJilles Tjoelkerand contain integer constants. 180536cf3efeSJilles Tjoelker.It Unary operators 180636cf3efeSJilles Tjoelker.Li "! ~ + -" 180736cf3efeSJilles Tjoelker.It Binary operators 180817e98da8SMateusz Piotrowski.Li "* / % + - << >> < <= > >= == != & ^ | && ||"\& 180936cf3efeSJilles Tjoelker.It Assignment operators 181036cf3efeSJilles Tjoelker.Li "= += -= *= /= %= <<= >>= &= ^= |=" 1811075b72efSJilles Tjoelker.It Conditional operator 181217e98da8SMateusz Piotrowski.Li "? :"\& 181336cf3efeSJilles Tjoelker.El 181436cf3efeSJilles Tjoelker.Pp 181536cf3efeSJilles TjoelkerThe result of the expression is substituted in decimal. 1816ab72124fSSteve Price.Ss White Space Splitting (Field Splitting) 1817ad56ebdcSJilles TjoelkerIn certain contexts, 1818ad56ebdcSJilles Tjoelkerafter parameter expansion, command substitution, and 18194b88c807SRodney W. Grimesarithmetic expansion the shell scans the results of 18204b88c807SRodney W. Grimesexpansions and substitutions that did not occur in double-quotes for 18214b88c807SRodney W. Grimesfield splitting and multiple fields can result. 1822ab72124fSSteve Price.Pp 1823ad56ebdcSJilles TjoelkerCharacters in 1824dfe302abSRuslan Ermilov.Va IFS 1825ad56ebdcSJilles Tjoelkerthat are whitespace 1826ad56ebdcSJilles Tjoelker.Po 1827ad56ebdcSJilles Tjoelker.Aq space , 1828ad56ebdcSJilles Tjoelker.Aq tab , 1829ad56ebdcSJilles Tjoelkerand 1830ad56ebdcSJilles Tjoelker.Aq newline 1831ad56ebdcSJilles Tjoelker.Pc 1832ad56ebdcSJilles Tjoelkerare treated differently from other characters in 1833ad56ebdcSJilles Tjoelker.Va IFS . 1834ad56ebdcSJilles Tjoelker.Pp 1835ad56ebdcSJilles TjoelkerWhitespace in 1836ad56ebdcSJilles Tjoelker.Va IFS 1837ad56ebdcSJilles Tjoelkerat the beginning or end of a word is discarded. 1838ad56ebdcSJilles Tjoelker.Pp 1839ad56ebdcSJilles TjoelkerSubsequently, a field is delimited by either 1840ad56ebdcSJilles Tjoelker.Bl -enum 1841ad56ebdcSJilles Tjoelker.It 1842ad56ebdcSJilles Tjoelkera non-whitespace character in 1843ad56ebdcSJilles Tjoelker.Va IFS 1844ad56ebdcSJilles Tjoelkerwith any whitespace in 1845ad56ebdcSJilles Tjoelker.Va IFS 1846ad56ebdcSJilles Tjoelkersurrounding it, or 1847ad56ebdcSJilles Tjoelker.It 1848ad56ebdcSJilles Tjoelkerone or more whitespace characters in 1849ad56ebdcSJilles Tjoelker.Va IFS . 1850ad56ebdcSJilles Tjoelker.El 1851ad56ebdcSJilles Tjoelker.Pp 1852ad56ebdcSJilles TjoelkerIf a word ends with a non-whitespace character in 1853ad56ebdcSJilles Tjoelker.Va IFS , 1854ad56ebdcSJilles Tjoelkerthere is no empty field after this character. 1855ad56ebdcSJilles Tjoelker.Pp 1856ad56ebdcSJilles TjoelkerIf no field is delimited, the word is discarded. 1857ad56ebdcSJilles TjoelkerIn particular, if a word consists solely of an unquoted substitution 1858ad56ebdcSJilles Tjoelkerand the result of the substitution is null, 1859ad56ebdcSJilles Tjoelkerit is removed by field splitting even if 1860ad56ebdcSJilles Tjoelker.Va IFS 1861ad56ebdcSJilles Tjoelkeris null. 1862ab72124fSSteve Price.Ss Pathname Expansion (File Name Generation) 186349e11e3aSSheldon HearnUnless the 186449e11e3aSSheldon Hearn.Fl f 186549e11e3aSSheldon Hearnoption is set, 186649e11e3aSSheldon Hearnfile name generation is performed 1867eccea571SRuslan Ermilovafter word splitting is complete. 1868eccea571SRuslan ErmilovEach word is 1869eccea571SRuslan Ermilovviewed as a series of patterns, separated by slashes. 1870eccea571SRuslan ErmilovThe 18714b88c807SRodney W. Grimesprocess of expansion replaces the word with the names of 18724b88c807SRodney W. Grimesall existing files whose names can be formed by replacing 18734b88c807SRodney W. Grimeseach pattern with a string that matches the specified pattern. 1874ab0a2172SSteve PriceThere are two restrictions on this: first, a pattern cannot match 1875ab0a2172SSteve Pricea string containing a slash, and second, 18764b88c807SRodney W. Grimesa pattern cannot match a string starting with a period 18774b88c807SRodney W. Grimesunless the first character of the pattern is a period. 1878519c4ef3SJilles TjoelkerThe next section describes the patterns used for 1879519c4ef3SJilles TjoelkerPathname Expansion, 1880519c4ef3SJilles Tjoelkerthe four varieties of parameter expansion for substring processing and the 1881c644db6aSSheldon Hearn.Ic case 1882ab72124fSSteve Pricecommand. 1883ab72124fSSteve Price.Ss Shell Patterns 1884f434d1dfSAdam DavidA pattern consists of normal characters, which match themselves, 188549e11e3aSSheldon Hearnand meta-characters. 188649e11e3aSSheldon HearnThe meta-characters are 1887dfe302abSRuslan Ermilov.Ql * , 1888dfe302abSRuslan Ermilov.Ql \&? , 18896b15476eSSheldon Hearnand 1890dfe302abSRuslan Ermilov.Ql \&[ . 18916b15476eSSheldon HearnThese characters lose their special meanings if they are quoted. 18926b15476eSSheldon HearnWhen command or variable substitution is performed and the dollar sign 18936b15476eSSheldon Hearnor back quotes are not double-quoted, the value of the 18944b88c807SRodney W. Grimesvariable or the output of the command is scanned for these 18954b88c807SRodney W. Grimescharacters and they are turned into meta-characters. 1896ab72124fSSteve Price.Pp 18976b15476eSSheldon HearnAn asterisk 1898a762afe5SGiorgos Keramidas.Pq Ql * 1899e918fc8fSSheldon Hearnmatches any string of characters. 1900e918fc8fSSheldon HearnA question mark 1901a762afe5SGiorgos Keramidas.Pq Ql \&? 1902e918fc8fSSheldon Hearnmatches any single character. 1903e6d3cf26SSheldon HearnA left bracket 1904dfe302abSRuslan Ermilov.Pq Ql \&[ 1905e6d3cf26SSheldon Hearnintroduces a character class. 1906e6d3cf26SSheldon HearnThe end of the character class is indicated by a 1907dfe302abSRuslan Ermilov.Ql \&] ; 19086b15476eSSheldon Hearnif the 1909dfe302abSRuslan Ermilov.Ql \&] 19106b15476eSSheldon Hearnis missing then the 1911dfe302abSRuslan Ermilov.Ql \&[ 19126b15476eSSheldon Hearnmatches a 1913dfe302abSRuslan Ermilov.Ql \&[ 1914e6d3cf26SSheldon Hearnrather than introducing a character class. 1915e6d3cf26SSheldon HearnA character class matches any of the characters between the square brackets. 1916519c4ef3SJilles TjoelkerA locale-dependent range of characters may be specified using a minus sign. 1917ff4dc672SJilles TjoelkerA named class of characters (see 1918ff4dc672SJilles Tjoelker.Xr wctype 3 ) 1919ff4dc672SJilles Tjoelkermay be specified by surrounding the name with 192017e98da8SMateusz Piotrowski.Ql \&[:\& 1921ff4dc672SJilles Tjoelkerand 1922ff4dc672SJilles Tjoelker.Ql :\&] . 1923ff4dc672SJilles TjoelkerFor example, 1924ff4dc672SJilles Tjoelker.Ql \&[\&[:alpha:\&]\&] 1925ff4dc672SJilles Tjoelkeris a shell pattern that matches a single letter. 1926e918fc8fSSheldon HearnThe character class may be complemented by making an exclamation point 1927a762afe5SGiorgos Keramidas.Pq Ql !\& 1928e918fc8fSSheldon Hearnthe first character of the character class. 1929519c4ef3SJilles TjoelkerA caret 1930519c4ef3SJilles Tjoelker.Pq Ql ^ 1931519c4ef3SJilles Tjoelkerhas the same effect but is non-standard. 1932ab72124fSSteve Price.Pp 19336b15476eSSheldon HearnTo include a 1934dfe302abSRuslan Ermilov.Ql \&] 1935e6d3cf26SSheldon Hearnin a character class, make it the first character listed 1936e6d3cf26SSheldon Hearn(after the 1937519c4ef3SJilles Tjoelker.Ql \&! 1938519c4ef3SJilles Tjoelkeror 1939519c4ef3SJilles Tjoelker.Ql ^ , 1940e6d3cf26SSheldon Hearnif any). 1941e918fc8fSSheldon HearnTo include a 1942dfe302abSRuslan Ermilov.Ql - , 1943e918fc8fSSheldon Hearnmake it the first or last character listed. 19448eed22b1SJens Schweikhardt.Ss Built-in Commands 194525f6b31fSJilles TjoelkerThis section lists the built-in commands. 194681e9cda2SRuslan Ermilov.Bl -tag -width indent 1947d0353b83SRuslan Ermilov.It Ic \&: 1948aa9caaf6SPeter WemmA null command that returns a 0 (true) exit value. 1949d0353b83SRuslan Ermilov.It Ic \&. Ar file 1950aa9caaf6SPeter WemmThe commands in the specified file are read and executed by the shell. 19514ad8968aSBrian FeldmanThe 19524ad8968aSBrian Feldman.Ic return 19534ad8968aSBrian Feldmancommand may be used to return to the 19544ad8968aSBrian Feldman.Ic \&. 19554ad8968aSBrian Feldmancommand's caller. 19566466945aSJohn PolstraIf 19576466945aSJohn Polstra.Ar file 19586466945aSJohn Polstracontains any 1959dfe302abSRuslan Ermilov.Ql / 1960eccea571SRuslan Ermilovcharacters, it is used as is. 1961eccea571SRuslan ErmilovOtherwise, the shell searches the 19621788b7ffSJilles Tjoelker.Va PATH 1963eccea571SRuslan Ermilovfor the file. 1964eccea571SRuslan ErmilovIf it is not found in the 19651788b7ffSJilles Tjoelker.Va PATH , 19666466945aSJohn Polstrait is sought in the current working directory. 196710845922SYaroslav Tykhiy.It Ic \&[ 196810845922SYaroslav TykhiyA built-in equivalent of 196910845922SYaroslav Tykhiy.Xr test 1 . 1970a886288eSJesus R. Camou.It Ic alias Oo Ar name Ns Oo = Ns Ar string Oc ... Oc 197149e11e3aSSheldon HearnIf 1972d0353b83SRuslan Ermilov.Ar name Ns = Ns Ar string 197349e11e3aSSheldon Hearnis specified, the shell defines the alias 197449e11e3aSSheldon Hearn.Ar name 19756b15476eSSheldon Hearnwith value 197649e11e3aSSheldon Hearn.Ar string . 19776b15476eSSheldon HearnIf just 197849e11e3aSSheldon Hearn.Ar name 19796b15476eSSheldon Hearnis specified, the value of the alias 198049e11e3aSSheldon Hearn.Ar name 19816b15476eSSheldon Hearnis printed. 198249e11e3aSSheldon HearnWith no arguments, the 198349e11e3aSSheldon Hearn.Ic alias 19848eed22b1SJens Schweikhardtbuilt-in command prints the names and values of all defined aliases 198549e11e3aSSheldon Hearn(see 198649e11e3aSSheldon Hearn.Ic unalias ) . 1987e5341cbbSTim J. RobbinsAlias values are written with appropriate quoting so that they are 19889ba31ca0SRuslan Ermilovsuitable for re-input to the shell. 1989a886288eSJesus R. CamouAlso see the 1990a886288eSJesus R. Camou.Sx Aliases 1991a886288eSJesus R. Camousubsection. 199249e11e3aSSheldon Hearn.It Ic bg Op Ar job ... 199349e11e3aSSheldon HearnContinue the specified jobs 199449e11e3aSSheldon Hearn(or the current job if no jobs are given) 199549e11e3aSSheldon Hearnin the background. 199625f6b31fSJilles Tjoelker.It Ic bind Oo Fl aeklrsv Oc Oo Ar key Oo Ar command Oc Oc 199725f6b31fSJilles TjoelkerList or alter key bindings for the line editor. 199825f6b31fSJilles TjoelkerThis command is documented in 199925f6b31fSJilles Tjoelker.Xr editrc 5 . 200025f6b31fSJilles Tjoelker.It Ic break Op Ar num 200125f6b31fSJilles TjoelkerSee the 200225f6b31fSJilles Tjoelker.Sx Flow-Control Constructs 200325f6b31fSJilles Tjoelkersubsection. 2004df9e587bSTim J. Robbins.It Ic builtin Ar cmd Op Ar arg ... 20058eed22b1SJens SchweikhardtExecute the specified built-in command, 200649e11e3aSSheldon Hearn.Ar cmd . 200749e11e3aSSheldon HearnThis is useful when the user wishes to override a shell function 20088eed22b1SJens Schweikhardtwith the same name as a built-in command. 2009d6ee26adSJilles Tjoelker.It Ic cd Oo Fl L | P Oc Oo Fl e Oc Op Ar directory 20107b6779b6SJilles Tjoelker.It Ic cd Fl 201149e11e3aSSheldon HearnSwitch to the specified 201249e11e3aSSheldon Hearn.Ar directory , 20137b6779b6SJilles Tjoelkerto the directory specified in the 20141788b7ffSJilles Tjoelker.Va HOME 201549e11e3aSSheldon Hearnenvironment variable if no 201649e11e3aSSheldon Hearn.Ar directory 20177b6779b6SJilles Tjoelkeris specified or 20187b6779b6SJilles Tjoelkerto the directory specified in the 20197b6779b6SJilles Tjoelker.Va OLDPWD 20207b6779b6SJilles Tjoelkerenvironment variable if 20217b6779b6SJilles Tjoelker.Ar directory 20227b6779b6SJilles Tjoelkeris 20237b6779b6SJilles Tjoelker.Fl . 202449e11e3aSSheldon HearnIf 202549e11e3aSSheldon Hearn.Ar directory 2026029c8ee4STim J. Robbinsdoes not begin with 20279ba31ca0SRuslan Ermilov.Pa / , \&. , 202849e11e3aSSheldon Hearnor 2029029c8ee4STim J. Robbins.Pa .. , 203049e11e3aSSheldon Hearnthen the directories listed in the 20311788b7ffSJilles Tjoelker.Va CDPATH 203249e11e3aSSheldon Hearnvariable will be 203349e11e3aSSheldon Hearnsearched for the specified 203449e11e3aSSheldon Hearn.Ar directory . 2035029c8ee4STim J. RobbinsIf 20361788b7ffSJilles Tjoelker.Va CDPATH 2037029c8ee4STim J. Robbinsis unset, the current directory is searched. 203849e11e3aSSheldon HearnThe format of 20391788b7ffSJilles Tjoelker.Va CDPATH 204049e11e3aSSheldon Hearnis the same as that of 20411788b7ffSJilles Tjoelker.Va PATH . 2042e6d3cf26SSheldon HearnIn an interactive shell, 204349e11e3aSSheldon Hearnthe 204449e11e3aSSheldon Hearn.Ic cd 204549e11e3aSSheldon Hearncommand will print out the name of the directory 2046e6d3cf26SSheldon Hearnthat it actually switched to 20477b6779b6SJilles Tjoelkerif the 20481788b7ffSJilles Tjoelker.Va CDPATH 20497b6779b6SJilles Tjoelkermechanism was used or if 20507b6779b6SJilles Tjoelker.Ar directory 20517b6779b6SJilles Tjoelkerwas 20527b6779b6SJilles Tjoelker.Fl . 2053178897f1STim J. Robbins.Pp 2054178897f1STim J. RobbinsIf the 2055178897f1STim J. Robbins.Fl P 2056178897f1STim J. Robbinsoption is specified, 205781e9cda2SRuslan Ermilov.Pa .. 2058178897f1STim J. Robbinsis handled physically and symbolic links are resolved before 205981e9cda2SRuslan Ermilov.Pa .. 2060178897f1STim J. Robbinscomponents are processed. 2061178897f1STim J. RobbinsIf the 2062178897f1STim J. Robbins.Fl L 2063178897f1STim J. Robbinsoption is specified, 206481e9cda2SRuslan Ermilov.Pa .. 2065178897f1STim J. Robbinsis handled logically. 2066178897f1STim J. RobbinsThis is the default. 2067d6ee26adSJilles Tjoelker.Pp 2068d6ee26adSJilles TjoelkerThe 2069d6ee26adSJilles Tjoelker.Fl e 2070d6ee26adSJilles Tjoelkeroption causes 2071d6ee26adSJilles Tjoelker.Ic cd 2072d6ee26adSJilles Tjoelkerto return exit status 1 if the full pathname of the new directory 2073d6ee26adSJilles Tjoelkercannot be determined reliably or at all. 2074d6ee26adSJilles TjoelkerNormally this is not considered an error, 2075d6ee26adSJilles Tjoelkeralthough a warning is printed. 20766f49cd26SJilles Tjoelker.Pp 20776f49cd26SJilles TjoelkerIf changing the directory fails, the exit status is greater than 1. 20786f49cd26SJilles TjoelkerIf the directory is changed, the exit status is 0, or also 1 if 20796f49cd26SJilles Tjoelker.Fl e 20806f49cd26SJilles Tjoelkerwas given. 20819434a1c7SDima Dorfman.It Ic chdir 20829434a1c7SDima DorfmanA synonym for the 20839434a1c7SDima Dorfman.Ic cd 20848eed22b1SJens Schweikhardtbuilt-in command. 20859ba31ca0SRuslan Ermilov.It Ic command Oo Fl p Oc Op Ar utility Op Ar argument ... 2086b97d13b3SJilles Tjoelker.It Ic command Oo Fl p Oc Fl v Ar utility 2087b97d13b3SJilles Tjoelker.It Ic command Oo Fl p Oc Fl V Ar utility 208833b222b9SStefan FarfelederThe first form of invocation executes the specified 2089c848bc18SJilles Tjoelker.Ar utility , 2090c848bc18SJilles Tjoelkerignoring shell functions in the search. 2091c848bc18SJilles TjoelkerIf 20922babaf74STim J. Robbins.Ar utility 2093c848bc18SJilles Tjoelkeris a special builtin, 2094c848bc18SJilles Tjoelkerit is executed as if it were a regular builtin. 20952babaf74STim J. Robbins.Pp 20962babaf74STim J. RobbinsIf the 20972babaf74STim J. Robbins.Fl p 20982babaf74STim J. Robbinsoption is specified, the command search is performed using a 20992babaf74STim J. Robbinsdefault value of 21001788b7ffSJilles Tjoelker.Va PATH 21012babaf74STim J. Robbinsthat is guaranteed to find all of the standard utilities. 210233b222b9SStefan Farfeleder.Pp 210333b222b9SStefan FarfelederIf the 210433b222b9SStefan Farfeleder.Fl v 210533b222b9SStefan Farfelederoption is specified, 210633b222b9SStefan Farfeleder.Ar utility 210733b222b9SStefan Farfelederis not executed but a description of its interpretation by the shell is 210833b222b9SStefan Farfelederprinted. 210933b222b9SStefan FarfelederFor ordinary commands the output is the path name; for shell built-in 211033b222b9SStefan Farfeledercommands, shell functions and keywords only the name is written. 211133b222b9SStefan FarfelederAliases are printed as 211233b222b9SStefan Farfeleder.Dq Ic alias Ar name Ns = Ns Ar value . 211333b222b9SStefan Farfeleder.Pp 211433b222b9SStefan FarfelederThe 211533b222b9SStefan Farfeleder.Fl V 211633b222b9SStefan Farfelederoption is identical to 211733b222b9SStefan Farfeleder.Fl v 211833b222b9SStefan Farfelederexcept for the output. 211933b222b9SStefan FarfelederIt prints 212033b222b9SStefan Farfeleder.Dq Ar utility Ic is Ar description 212133b222b9SStefan Farfelederwhere 212233b222b9SStefan Farfeleder.Ar description 212333b222b9SStefan Farfelederis either 212433b222b9SStefan Farfelederthe path name to 212533b222b9SStefan Farfeleder.Ar utility , 212630268dfaSJilles Tjoelkera special shell builtin, 21278af11131SRuslan Ermilova shell builtin, 21288af11131SRuslan Ermilova shell function, 21298af11131SRuslan Ermilova shell keyword 213033b222b9SStefan Farfelederor 21318af11131SRuslan Ermilovan alias for 21328af11131SRuslan Ermilov.Ar value . 213325f6b31fSJilles Tjoelker.It Ic continue Op Ar num 213425f6b31fSJilles TjoelkerSee the 213525f6b31fSJilles Tjoelker.Sx Flow-Control Constructs 213625f6b31fSJilles Tjoelkersubsection. 213773313421SStefan Farfeleder.It Ic echo Oo Fl e | n Oc Op Ar string ... 213873313421SStefan FarfelederPrint a space-separated list of the arguments to the standard output 213973313421SStefan Farfelederand append a newline character. 214081e9cda2SRuslan Ermilov.Bl -tag -width indent 2141501e74b7SMark Ovens.It Fl n 2142501e74b7SMark OvensSuppress the output of the trailing newline. 2143501e74b7SMark Ovens.It Fl e 2144501e74b7SMark OvensProcess C-style backslash escape sequences. 2145dfe302abSRuslan ErmilovThe 2146501e74b7SMark Ovens.Ic echo 2147dfe302abSRuslan Ermilovcommand understands the following character escapes: 214881e9cda2SRuslan Ermilov.Bl -tag -width indent 2149501e74b7SMark Ovens.It \ea 2150501e74b7SMark OvensAlert (ring the terminal bell) 2151501e74b7SMark Ovens.It \eb 2152501e74b7SMark OvensBackspace 2153501e74b7SMark Ovens.It \ec 2154501e74b7SMark OvensSuppress the trailing newline (this has the side-effect of truncating the 2155501e74b7SMark Ovensline if it is not the last character) 2156501e74b7SMark Ovens.It \ee 215717e98da8SMateusz PiotrowskiThe ESC character (ASCII 0x1b) 2158501e74b7SMark Ovens.It \ef 2159501e74b7SMark OvensFormfeed 2160501e74b7SMark Ovens.It \en 2161501e74b7SMark OvensNewline 2162501e74b7SMark Ovens.It \er 2163501e74b7SMark OvensCarriage return 2164501e74b7SMark Ovens.It \et 2165501e74b7SMark OvensHorizontal tab 2166501e74b7SMark Ovens.It \ev 2167501e74b7SMark OvensVertical tab 2168501e74b7SMark Ovens.It \e\e 2169501e74b7SMark OvensLiteral backslash 2170501e74b7SMark Ovens.It \e0nnn 2171dfe302abSRuslan Ermilov(Zero) The character whose octal value is 2172dfe302abSRuslan Ermilov.Ar nnn 2173501e74b7SMark Ovens.El 2174501e74b7SMark Ovens.Pp 2175501e74b7SMark OvensIf 2176501e74b7SMark Ovens.Ar string 2177501e74b7SMark Ovensis not enclosed in quotes then the backslash itself must be escaped 2178eccea571SRuslan Ermilovwith a backslash to protect it from the shell. 2179eccea571SRuslan ErmilovFor example 2180501e74b7SMark Ovens.Bd -literal -offset indent 2181501e74b7SMark Ovens$ echo -e "a\evb" 2182501e74b7SMark Ovensa 2183501e74b7SMark Ovens b 2184501e74b7SMark Ovens$ echo -e a\e\evb 2185501e74b7SMark Ovensa 2186501e74b7SMark Ovens b 2187501e74b7SMark Ovens$ echo -e "a\e\eb" 2188501e74b7SMark Ovensa\eb 2189501e74b7SMark Ovens$ echo -e a\e\e\e\eb 2190501e74b7SMark Ovensa\eb 2191501e74b7SMark Ovens.Ed 2192501e74b7SMark Ovens.El 2193558175caSTim J. Robbins.Pp 2194558175caSTim J. RobbinsOnly one of the 2195558175caSTim J. Robbins.Fl e 2196558175caSTim J. Robbinsand 2197558175caSTim J. Robbins.Fl n 2198558175caSTim J. Robbinsoptions may be specified. 219949e11e3aSSheldon Hearn.It Ic eval Ar string ... 2200e6d3cf26SSheldon HearnConcatenate all the arguments with spaces. 2201e6d3cf26SSheldon HearnThen re-parse and execute the command. 220249e11e3aSSheldon Hearn.It Ic exec Op Ar command Op arg ... 220349e11e3aSSheldon HearnUnless 220449e11e3aSSheldon Hearn.Ar command 220549e11e3aSSheldon Hearnis omitted, 220649e11e3aSSheldon Hearnthe shell process is replaced with the specified program 22078eed22b1SJens Schweikhardt(which must be a real program, not a shell built-in command or function). 220849e11e3aSSheldon HearnAny redirections on the 220949e11e3aSSheldon Hearn.Ic exec 221049e11e3aSSheldon Hearncommand are marked as permanent, 221149e11e3aSSheldon Hearnso that they are not undone when the 221249e11e3aSSheldon Hearn.Ic exec 221349e11e3aSSheldon Hearncommand finishes. 221449e11e3aSSheldon Hearn.It Ic exit Op Ar exitstatus 221549e11e3aSSheldon HearnTerminate the shell process. 221649e11e3aSSheldon HearnIf 221749e11e3aSSheldon Hearn.Ar exitstatus 221849e11e3aSSheldon Hearnis given 2219ea381e69SJilles Tjoelkerit is used as the exit status of the shell. 2220ea381e69SJilles TjoelkerOtherwise, if the shell is executing an 2221421fb021SJilles Tjoelker.Cm EXIT 2222421fb021SJilles Tjoelkertrap, the exit status of the last command before the trap is used; 2223421fb021SJilles Tjoelkerif the shell is executing a trap for a signal, 2224ea381e69SJilles Tjoelkerthe shell exits by resending the signal to itself. 2225ea381e69SJilles TjoelkerOtherwise, the exit status of the preceding command is used. 2226a68fbc44SJilles TjoelkerThe exit status should be an integer between 0 and 255. 2227ef9791a3SStefan Farfeleder.It Ic export Ar name ... 2228ef9791a3SStefan Farfeleder.It Ic export Op Fl p 22294b88c807SRodney W. GrimesThe specified names are exported so that they will 22304b88c807SRodney W. Grimesappear in the environment of subsequent commands. 223149e11e3aSSheldon HearnThe only way to un-export a variable is to 223249e11e3aSSheldon Hearn.Ic unset 223349e11e3aSSheldon Hearnit. 223449e11e3aSSheldon HearnThe shell allows the value of a variable to be set 223549e11e3aSSheldon Hearnat the same time as it is exported by writing 2236ab72124fSSteve Price.Pp 2237dfe302abSRuslan Ermilov.D1 Ic export Ar name Ns = Ns Ar value 2238dfe302abSRuslan Ermilov.Pp 2239dfe302abSRuslan ErmilovWith no arguments the 2240dfe302abSRuslan Ermilov.Ic export 2241dfe302abSRuslan Ermilovcommand lists the names 22424b88c807SRodney W. Grimesof all exported variables. 224345086f8cSTim J. RobbinsIf the 224445086f8cSTim J. Robbins.Fl p 224545086f8cSTim J. Robbinsoption is specified, the exported variables are printed as 224645086f8cSTim J. Robbins.Dq Ic export Ar name Ns = Ns Ar value 224745086f8cSTim J. Robbinslines, suitable for re-input to the shell. 2248a6557dcbSYaroslav Tykhiy.It Ic false 2249a6557dcbSYaroslav TykhiyA null command that returns a non-zero (false) exit value. 225081e9cda2SRuslan Ermilov.It Ic fc Oo Fl e Ar editor Oc Op Ar first Op Ar last 225181e9cda2SRuslan Ermilov.It Ic fc Fl l Oo Fl nr Oc Op Ar first Op Ar last 225281e9cda2SRuslan Ermilov.It Ic fc Fl s Oo Ar old Ns = Ns Ar new Oc Op Ar first 225349e11e3aSSheldon HearnThe 225449e11e3aSSheldon Hearn.Ic fc 22558eed22b1SJens Schweikhardtbuilt-in command lists, or edits and re-executes, 225649e11e3aSSheldon Hearncommands previously entered to an interactive shell. 225781e9cda2SRuslan Ermilov.Bl -tag -width indent 225849e11e3aSSheldon Hearn.It Fl e Ar editor 225949e11e3aSSheldon HearnUse the editor named by 226049e11e3aSSheldon Hearn.Ar editor 226149e11e3aSSheldon Hearnto edit the commands. 2262dfe302abSRuslan ErmilovThe 2263dfe302abSRuslan Ermilov.Ar editor 2264dfe302abSRuslan Ermilovstring is a command name, 226549e11e3aSSheldon Hearnsubject to search via the 22661788b7ffSJilles Tjoelker.Va PATH 226749e11e3aSSheldon Hearnvariable. 226849e11e3aSSheldon HearnThe value in the 22691788b7ffSJilles Tjoelker.Va FCEDIT 227049e11e3aSSheldon Hearnvariable is used as a default when 227149e11e3aSSheldon Hearn.Fl e 227249e11e3aSSheldon Hearnis not specified. 227349e11e3aSSheldon HearnIf 22741788b7ffSJilles Tjoelker.Va FCEDIT 227549e11e3aSSheldon Hearnis null or unset, the value of the 22761788b7ffSJilles Tjoelker.Va EDITOR 227749e11e3aSSheldon Hearnvariable is used. 227849e11e3aSSheldon HearnIf 22791788b7ffSJilles Tjoelker.Va EDITOR 228049e11e3aSSheldon Hearnis null or unset, 2281ab72124fSSteve Price.Xr ed 1 2282ab72124fSSteve Priceis used as the editor. 228349e11e3aSSheldon Hearn.It Fl l No (ell) 22844b88c807SRodney W. GrimesList the commands rather than invoking 2285eccea571SRuslan Ermilovan editor on them. 2286eccea571SRuslan ErmilovThe commands are written in the 2287dfe302abSRuslan Ermilovsequence indicated by the 2288dfe302abSRuslan Ermilov.Ar first 2289dfe302abSRuslan Ermilovand 2290dfe302abSRuslan Ermilov.Ar last 2291dfe302abSRuslan Ermilovoperands, as affected by 229249e11e3aSSheldon Hearn.Fl r , 229349e11e3aSSheldon Hearnwith each command preceded by the command number. 229449e11e3aSSheldon Hearn.It Fl n 229549e11e3aSSheldon HearnSuppress command numbers when listing with 229649e11e3aSSheldon Hearn.Fl l . 229749e11e3aSSheldon Hearn.It Fl r 229849e11e3aSSheldon HearnReverse the order of the commands listed 229949e11e3aSSheldon Hearn(with 230049e11e3aSSheldon Hearn.Fl l ) 230149e11e3aSSheldon Hearnor edited 230249e11e3aSSheldon Hearn(with neither 230349e11e3aSSheldon Hearn.Fl l 230449e11e3aSSheldon Hearnnor 230549e11e3aSSheldon Hearn.Fl s ) . 230649e11e3aSSheldon Hearn.It Fl s 23074b88c807SRodney W. GrimesRe-execute the command without invoking an editor. 230849e11e3aSSheldon Hearn.It Ar first 230949e11e3aSSheldon Hearn.It Ar last 231049e11e3aSSheldon HearnSelect the commands to list or edit. 231149e11e3aSSheldon HearnThe number of previous commands that can be accessed 231249e11e3aSSheldon Hearnare determined by the value of the 23131788b7ffSJilles Tjoelker.Va HISTSIZE 2314d0353b83SRuslan Ermilovvariable. 231549e11e3aSSheldon HearnThe value of 231649e11e3aSSheldon Hearn.Ar first 231749e11e3aSSheldon Hearnor 231849e11e3aSSheldon Hearn.Ar last 231949e11e3aSSheldon Hearnor both are one of the following: 232081e9cda2SRuslan Ermilov.Bl -tag -width indent 2321dfe302abSRuslan Ermilov.It Oo Cm + Oc Ns Ar num 232249e11e3aSSheldon HearnA positive number representing a command number; 232349e11e3aSSheldon Hearncommand numbers can be displayed with the 232449e11e3aSSheldon Hearn.Fl l 232549e11e3aSSheldon Hearnoption. 2326dfe302abSRuslan Ermilov.It Fl Ar num 232749e11e3aSSheldon HearnA negative decimal number representing the 232849e11e3aSSheldon Hearncommand that was executed 232949e11e3aSSheldon Hearn.Ar num 233049e11e3aSSheldon Hearnof 233149e11e3aSSheldon Hearncommands previously. 2332dfe302abSRuslan ErmilovFor example, \-1 is the immediately previous command. 233349e11e3aSSheldon Hearn.It Ar string 233449e11e3aSSheldon HearnA string indicating the most recently entered command 233549e11e3aSSheldon Hearnthat begins with that string. 233649e11e3aSSheldon HearnIf the 2337dfe302abSRuslan Ermilov.Ar old Ns = Ns Ar new 233849e11e3aSSheldon Hearnoperand is not also specified with 233949e11e3aSSheldon Hearn.Fl s , 234049e11e3aSSheldon Hearnthe string form of the first operand cannot contain an embedded equal sign. 234149e11e3aSSheldon Hearn.El 234249e11e3aSSheldon Hearn.El 234349e11e3aSSheldon Hearn.Pp 23441788b7ffSJilles TjoelkerThe following variables affect the execution of 234549e11e3aSSheldon Hearn.Ic fc : 23461788b7ffSJilles Tjoelker.Bl -tag -width ".Va HISTSIZE" 23471788b7ffSJilles Tjoelker.It Va FCEDIT 234838afdcbcSGiorgos KeramidasName of the editor to use for history editing. 23491788b7ffSJilles Tjoelker.It Va HISTSIZE 23503d7b5b93SPhilippe CharnierThe number of previous commands that are accessible. 2351ab72124fSSteve Price.El 235249e11e3aSSheldon Hearn.It Ic fg Op Ar job 235349e11e3aSSheldon HearnMove the specified 235449e11e3aSSheldon Hearn.Ar job 235549e11e3aSSheldon Hearnor the current job to the foreground. 2356dfe302abSRuslan Ermilov.It Ic getopts Ar optstring var 235717e98da8SMateusz PiotrowskiThe POSIX 235849e11e3aSSheldon Hearn.Ic getopts 235949e11e3aSSheldon Hearncommand. 236049e11e3aSSheldon HearnThe 236149e11e3aSSheldon Hearn.Ic getopts 236249e11e3aSSheldon Hearncommand deprecates the older 236349e11e3aSSheldon Hearn.Xr getopt 1 236449e11e3aSSheldon Hearncommand. 2365ab0a2172SSteve PriceThe first argument should be a series of letters, each possibly 2366ab0a2172SSteve Pricefollowed by a colon which indicates that the option takes an argument. 2367eccea571SRuslan ErmilovThe specified variable is set to the parsed option. 2368eccea571SRuslan ErmilovThe index of 236949e11e3aSSheldon Hearnthe next argument is placed into the shell variable 2370dfe302abSRuslan Ermilov.Va OPTIND . 2371ab0a2172SSteve PriceIf an option takes an argument, it is placed into the shell variable 2372dfe302abSRuslan Ermilov.Va OPTARG . 237349e11e3aSSheldon HearnIf an invalid option is encountered, 2374dfe302abSRuslan Ermilov.Ar var 237549e11e3aSSheldon Hearnis set to 2376dfe302abSRuslan Ermilov.Ql \&? . 2377ab0a2172SSteve PriceIt returns a false value (1) when it encounters the end of the options. 23784445af21SJilles TjoelkerA new set of arguments may be parsed by assigning 23794445af21SJilles Tjoelker.Li OPTIND=1 . 238081e9cda2SRuslan Ermilov.It Ic hash Oo Fl rv Oc Op Ar command ... 238149e11e3aSSheldon HearnThe shell maintains a hash table which remembers the locations of commands. 238249e11e3aSSheldon HearnWith no arguments whatsoever, the 238349e11e3aSSheldon Hearn.Ic hash 238449e11e3aSSheldon Hearncommand prints out the contents of this table. 2385ab72124fSSteve Price.Pp 238649e11e3aSSheldon HearnWith arguments, the 238749e11e3aSSheldon Hearn.Ic hash 238849e11e3aSSheldon Hearncommand removes each specified 238949e11e3aSSheldon Hearn.Ar command 239049e11e3aSSheldon Hearnfrom the hash table (unless they are functions) and then locates it. 239149e11e3aSSheldon HearnWith the 239249e11e3aSSheldon Hearn.Fl v 239349e11e3aSSheldon Hearnoption, 239449e11e3aSSheldon Hearn.Ic hash 239549e11e3aSSheldon Hearnprints the locations of the commands as it finds them. 239649e11e3aSSheldon HearnThe 239749e11e3aSSheldon Hearn.Fl r 239849e11e3aSSheldon Hearnoption causes the 239949e11e3aSSheldon Hearn.Ic hash 240049e11e3aSSheldon Hearncommand to delete all the entries in the hash table except for functions. 240149e11e3aSSheldon Hearn.It Ic jobid Op Ar job 2402dfe302abSRuslan ErmilovPrint the process IDs of the processes in the specified 240349e11e3aSSheldon Hearn.Ar job . 240449e11e3aSSheldon HearnIf the 240549e11e3aSSheldon Hearn.Ar job 240649e11e3aSSheldon Hearnargument is omitted, use the current job. 2407de37e41cSStefan Farfeleder.It Ic jobs Oo Fl lps Oc Op Ar job ... 2408ad8a0759STim J. RobbinsPrint information about the specified jobs, or all jobs if no 2409ad8a0759STim J. Robbins.Ar job 2410ad8a0759STim J. Robbinsargument is given. 2411ad8a0759STim J. RobbinsThe information printed includes job ID, status and command name. 2412ad8a0759STim J. Robbins.Pp 2413ad8a0759STim J. RobbinsIf the 2414ad8a0759STim J. Robbins.Fl l 2415ad8a0759STim J. Robbinsoption is specified, the PID of each job is also printed. 2416ad8a0759STim J. RobbinsIf the 2417de37e41cSStefan Farfeleder.Fl p 2418de37e41cSStefan Farfelederoption is specified, only the process IDs for the process group leaders 2419de37e41cSStefan Farfelederare printed, one per line. 2420de37e41cSStefan FarfelederIf the 2421ad8a0759STim J. Robbins.Fl s 2422de37e41cSStefan Farfelederoption is specified, only the PIDs of the job commands are printed, one per 2423de37e41cSStefan Farfelederline. 24240a62a9caSJilles Tjoelker.It Ic kill 24250a62a9caSJilles TjoelkerA built-in equivalent of 24260a62a9caSJilles Tjoelker.Xr kill 1 24270a62a9caSJilles Tjoelkerthat additionally supports sending signals to jobs. 24288af11131SRuslan Ermilov.It Ic local Oo Ar variable ... Oc Op Fl 2429d2f90294SJesus R. CamouSee the 2430d2f90294SJesus R. Camou.Sx Functions 2431d2f90294SJesus R. Camousubsection. 24329897c45fSJilles Tjoelker.It Ic printf 24339897c45fSJilles TjoelkerA built-in equivalent of 24349897c45fSJilles Tjoelker.Xr printf 1 . 2435d74e011fSRuslan Ermilov.It Ic pwd Op Fl L | P 2436eccea571SRuslan ErmilovPrint the path of the current directory. 2437eccea571SRuslan ErmilovThe built-in command may 24384b88c807SRodney W. Grimesdiffer from the program of the same name because the 24398eed22b1SJens Schweikhardtbuilt-in command remembers what the current directory 2440eccea571SRuslan Ermilovis rather than recomputing it each time. 2441eccea571SRuslan ErmilovThis makes 2442eccea571SRuslan Ermilovit faster. 2443eccea571SRuslan ErmilovHowever, if the current directory is 244449e11e3aSSheldon Hearnrenamed, 24458eed22b1SJens Schweikhardtthe built-in version of 244649e11e3aSSheldon Hearn.Xr pwd 1 244749e11e3aSSheldon Hearnwill continue to print the old name for the directory. 2448178897f1STim J. Robbins.Pp 2449178897f1STim J. RobbinsIf the 2450178897f1STim J. Robbins.Fl P 2451178897f1STim J. Robbinsoption is specified, symbolic links are resolved. 2452178897f1STim J. RobbinsIf the 2453178897f1STim J. Robbins.Fl L 2454178897f1STim J. Robbinsoption is specified, the shell's notion of the current directory 2455178897f1STim J. Robbinsis printed (symbolic links are not resolved). 2456178897f1STim J. RobbinsThis is the default. 2457dfe302abSRuslan Ermilov.It Ic read Oo Fl p Ar prompt Oc Oo 2458dfe302abSRuslan Ermilov.Fl t Ar timeout Oc Oo Fl er Oc Ar variable ... 245949e11e3aSSheldon HearnThe 246049e11e3aSSheldon Hearn.Ar prompt 246149e11e3aSSheldon Hearnis printed if the 246249e11e3aSSheldon Hearn.Fl p 246349e11e3aSSheldon Hearnoption is specified 2464eccea571SRuslan Ermilovand the standard input is a terminal. 2465eccea571SRuslan ErmilovThen a line is 2466eccea571SRuslan Ermilovread from the standard input. 2467eccea571SRuslan ErmilovThe trailing newline 24684b88c807SRodney W. Grimesis deleted from the line and the line is split as 246949e11e3aSSheldon Hearndescribed in the section on 247017e98da8SMateusz Piotrowski.Sx White Space Splitting (Field Splitting)\& 247149e11e3aSSheldon Hearnabove, and 24724b88c807SRodney W. Grimesthe pieces are assigned to the variables in order. 2473f434d1dfSAdam DavidIf there are more pieces than variables, the remaining 247449e11e3aSSheldon Hearnpieces (along with the characters in 2475dfe302abSRuslan Ermilov.Va IFS 247649e11e3aSSheldon Hearnthat separated them) 247749e11e3aSSheldon Hearnare assigned to the last variable. 2478f434d1dfSAdam DavidIf there are more variables than pieces, the remaining 2479f434d1dfSAdam Davidvariables are assigned the null string. 2480ab72124fSSteve Price.Pp 248149e11e3aSSheldon HearnBackslashes are treated specially, unless the 248249e11e3aSSheldon Hearn.Fl r 248349e11e3aSSheldon Hearnoption is 2484eccea571SRuslan Ermilovspecified. 2485eccea571SRuslan ErmilovIf a backslash is followed by 24868f0561ccSThomas Gellekuma newline, the backslash and the newline will be 2487eccea571SRuslan Ermilovdeleted. 2488eccea571SRuslan ErmilovIf a backslash is followed by any other 24898f0561ccSThomas Gellekumcharacter, the backslash will be deleted and the following 249049e11e3aSSheldon Hearncharacter will be treated as though it were not in 2491dfe302abSRuslan Ermilov.Va IFS , 249249e11e3aSSheldon Hearneven if it is. 24938f0561ccSThomas Gellekum.Pp 249449e11e3aSSheldon HearnIf the 249549e11e3aSSheldon Hearn.Fl t 249649e11e3aSSheldon Hearnoption is specified and the 249749e11e3aSSheldon Hearn.Ar timeout 2498fe40d6d3SJilles Tjoelkerelapses before a complete line of input is supplied, 249949e11e3aSSheldon Hearnthe 250049e11e3aSSheldon Hearn.Ic read 2501c4539460SJilles Tjoelkercommand will return an exit status as if terminated by 2502c4539460SJilles Tjoelker.Dv SIGALRM 2503c4539460SJilles Tjoelkerwithout assigning any values. 250449e11e3aSSheldon HearnThe 250549e11e3aSSheldon Hearn.Ar timeout 250649e11e3aSSheldon Hearnvalue may optionally be followed by one of 2507dfe302abSRuslan Ermilov.Ql s , 2508dfe302abSRuslan Ermilov.Ql m 250949e11e3aSSheldon Hearnor 2510dfe302abSRuslan Ermilov.Ql h 2511a910f192SDima Dorfmanto explicitly specify seconds, minutes or hours. 251249e11e3aSSheldon HearnIf none is supplied, 2513dfe302abSRuslan Ermilov.Ql s 251449e11e3aSSheldon Hearnis assumed. 2515afa53c8dSMike Smith.Pp 251649e11e3aSSheldon HearnThe 251749e11e3aSSheldon Hearn.Fl e 251849e11e3aSSheldon Hearnoption exists only for backward compatibility with older scripts. 2519c4539460SJilles Tjoelker.Pp 2520c4539460SJilles TjoelkerThe exit status is 0 on success, 1 on end of file, 2521c4539460SJilles Tjoelkerbetween 2 and 128 if an error occurs 2522c4539460SJilles Tjoelkerand greater than 128 if a trapped signal interrupts 2523c4539460SJilles Tjoelker.Ic read . 25249ba31ca0SRuslan Ermilov.It Ic readonly Oo Fl p Oc Op Ar name ... 252549e11e3aSSheldon HearnEach specified 252649e11e3aSSheldon Hearn.Ar name 252749e11e3aSSheldon Hearnis marked as read only, 252849e11e3aSSheldon Hearnso that it cannot be subsequently modified or unset. 252949e11e3aSSheldon HearnThe shell allows the value of a variable to be set 253049e11e3aSSheldon Hearnat the same time as it is marked read only 253149e11e3aSSheldon Hearnby using the following form: 2532dfe302abSRuslan Ermilov.Pp 2533dfe302abSRuslan Ermilov.D1 Ic readonly Ar name Ns = Ns Ar value 2534ab72124fSSteve Price.Pp 253549e11e3aSSheldon HearnWith no arguments the 253649e11e3aSSheldon Hearn.Ic readonly 253749e11e3aSSheldon Hearncommand lists the names of all read only variables. 253845086f8cSTim J. RobbinsIf the 253945086f8cSTim J. Robbins.Fl p 254045086f8cSTim J. Robbinsoption is specified, the read-only variables are printed as 254145086f8cSTim J. Robbins.Dq Ic readonly Ar name Ns = Ns Ar value 254245086f8cSTim J. Robbinslines, suitable for re-input to the shell. 2543d2f90294SJesus R. Camou.It Ic return Op Ar exitstatus 2544d2f90294SJesus R. CamouSee the 2545d2f90294SJesus R. Camou.Sx Functions 2546d2f90294SJesus R. Camousubsection. 25471becbc64SJilles Tjoelker.It Ic set Oo Fl /+abCEefIimnpTuVvx Oc Oo Fl /+o Ar longname 25481becbc64SJilles Tjoelker.Oc Op Fl - Ar arg ... 2549e918fc8fSSheldon HearnThe 2550e918fc8fSSheldon Hearn.Ic set 2551e918fc8fSSheldon Hearncommand performs three different functions: 2552ab72124fSSteve Price.Bl -item 2553ab72124fSSteve Price.It 255449e11e3aSSheldon HearnWith no arguments, it lists the values of all shell variables. 2555ab72124fSSteve Price.It 255649e11e3aSSheldon HearnIf options are given, 255749e11e3aSSheldon Hearneither in short form or using the long 255849e11e3aSSheldon Hearn.Dq Fl /+o Ar longname 255949e11e3aSSheldon Hearnform, 256049e11e3aSSheldon Hearnit sets or clears the specified options as described in the section called 25616b15476eSSheldon Hearn.Sx Argument List Processing . 2562ab72124fSSteve Price.It 256349e11e3aSSheldon HearnIf the 256449e11e3aSSheldon Hearn.Dq Fl - 256549e11e3aSSheldon Hearnoption is specified, 256649e11e3aSSheldon Hearn.Ic set 256749e11e3aSSheldon Hearnwill replace the shell's positional parameters with the subsequent 256849e11e3aSSheldon Hearnarguments. 256949e11e3aSSheldon HearnIf no arguments follow the 257049e11e3aSSheldon Hearn.Dq Fl - 257149e11e3aSSheldon Hearnoption, 257249e11e3aSSheldon Hearnall the positional parameters will be cleared, 257349e11e3aSSheldon Hearnwhich is equivalent to executing the command 2574dfe302abSRuslan Ermilov.Dq Li "shift $#" . 257549e11e3aSSheldon HearnThe 257649e11e3aSSheldon Hearn.Dq Fl - 25778eed22b1SJens Schweikhardtflag may be omitted when specifying arguments to be used 257849e11e3aSSheldon Hearnas positional replacement parameters. 257949e11e3aSSheldon HearnThis is not recommended, 258049e11e3aSSheldon Hearnbecause the first argument may begin with a dash 2581a762afe5SGiorgos Keramidas.Pq Ql - 258249e11e3aSSheldon Hearnor a plus 2583a762afe5SGiorgos Keramidas.Pq Ql + , 258449e11e3aSSheldon Hearnwhich the 258549e11e3aSSheldon Hearn.Ic set 258649e11e3aSSheldon Hearncommand will interpret as a request to enable or disable options. 2587ab72124fSSteve Price.El 2588dfe302abSRuslan Ermilov.It Ic setvar Ar variable value 258949e11e3aSSheldon HearnAssigns the specified 259049e11e3aSSheldon Hearn.Ar value 259149e11e3aSSheldon Hearnto the specified 259249e11e3aSSheldon Hearn.Ar variable . 2593dfe302abSRuslan ErmilovThe 2594dfe302abSRuslan Ermilov.Ic setvar 2595dfe302abSRuslan Ermilovcommand is intended to be used in functions that 2596e6d3cf26SSheldon Hearnassign values to variables whose names are passed as parameters. 259749e11e3aSSheldon HearnIn general it is better to write 2598dfe302abSRuslan Ermilov.Dq Ar variable Ns = Ns Ar value 259949e11e3aSSheldon Hearnrather than using 260049e11e3aSSheldon Hearn.Ic setvar . 260149e11e3aSSheldon Hearn.It Ic shift Op Ar n 260249e11e3aSSheldon HearnShift the positional parameters 260349e11e3aSSheldon Hearn.Ar n 2604e918fc8fSSheldon Hearntimes, or once if 260549e11e3aSSheldon Hearn.Ar n 260649e11e3aSSheldon Hearnis not specified. 2607dfe302abSRuslan ErmilovA shift sets the value of 2608dfe302abSRuslan Ermilov.Li $1 2609dfe302abSRuslan Ermilovto the value of 2610dfe302abSRuslan Ermilov.Li $2 , 2611dfe302abSRuslan Ermilovthe value of 2612dfe302abSRuslan Ermilov.Li $2 2613dfe302abSRuslan Ermilovto the value of 2614dfe302abSRuslan Ermilov.Li $3 , 2615dfe302abSRuslan Ermilovand so on, 2616dfe302abSRuslan Ermilovdecreasing the value of 2617dfe302abSRuslan Ermilov.Li $# 2618dfe302abSRuslan Ermilovby one. 2619945e1562SJilles TjoelkerFor portability, shifting if there are zero positional parameters 2620945e1562SJilles Tjoelkershould be avoided, since the shell may abort. 262110845922SYaroslav Tykhiy.It Ic test 262210845922SYaroslav TykhiyA built-in equivalent of 262310845922SYaroslav Tykhiy.Xr test 1 . 26241974986aSStefan Farfeleder.It Ic times 262551a514adSJilles TjoelkerPrint the amount of time spent executing the shell process and its children. 262651a514adSJilles TjoelkerThe first output line shows the user and system times for the shell process 26271974986aSStefan Farfelederitself, the second one contains the user and system times for the 26281974986aSStefan Farfelederchildren. 262981e9cda2SRuslan Ermilov.It Ic trap Oo Ar action Oc Ar signal ... 26300673e800SStefan Farfeleder.It Ic trap Fl l 263149e11e3aSSheldon HearnCause the shell to parse and execute 263249e11e3aSSheldon Hearn.Ar action 263349e11e3aSSheldon Hearnwhen any specified 263449e11e3aSSheldon Hearn.Ar signal 263549e11e3aSSheldon Hearnis received. 2636162ae3aeSTony FinchThe signals are specified by name or number. 2637162ae3aeSTony FinchIn addition, the pseudo-signal 2638f5d1157fSRuslan Ermilov.Cm EXIT 2639dfe302abSRuslan Ermilovmay be used to specify an 2640dfe302abSRuslan Ermilov.Ar action 2641dfe302abSRuslan Ermilovthat is performed when the shell terminates. 264249e11e3aSSheldon HearnThe 264349e11e3aSSheldon Hearn.Ar action 26440673e800SStefan Farfeledermay be an empty string or a dash 26459badf57fSRuslan Ermilov.Pq Ql - ; 264649e11e3aSSheldon Hearnthe former causes the specified signal to be ignored 264749e11e3aSSheldon Hearnand the latter causes the default action to be taken. 26480673e800SStefan FarfelederOmitting the 26490673e800SStefan Farfeleder.Ar action 2650a59f8174SBryan Dreweryand using only signal numbers is another way to request the default action. 265151a514adSJilles TjoelkerIn a subshell or utility environment, 2652ef89d04fSJilles Tjoelkerthe shell resets trapped (but not ignored) signals to the default action. 265349e11e3aSSheldon HearnThe 265449e11e3aSSheldon Hearn.Ic trap 265549e11e3aSSheldon Hearncommand has no effect on signals that were ignored on entry to the shell. 26560673e800SStefan Farfeleder.Pp 26570673e800SStefan FarfelederOption 26580673e800SStefan Farfeleder.Fl l 26590673e800SStefan Farfeledercauses the 26600673e800SStefan Farfeleder.Ic trap 26610673e800SStefan Farfeledercommand to display a list of valid signal names. 2662a6557dcbSYaroslav Tykhiy.It Ic true 2663a6557dcbSYaroslav TykhiyA null command that returns a 0 (true) exit value. 266449e11e3aSSheldon Hearn.It Ic type Op Ar name ... 266549e11e3aSSheldon HearnInterpret each 266649e11e3aSSheldon Hearn.Ar name 266749e11e3aSSheldon Hearnas a command and print the resolution of the command search. 2668e6d3cf26SSheldon HearnPossible resolutions are: 266930268dfaSJilles Tjoelkershell keyword, alias, special shell builtin, shell builtin, command, 267030268dfaSJilles Tjoelkertracked alias 267149e11e3aSSheldon Hearnand not found. 267249e11e3aSSheldon HearnFor aliases the alias expansion is printed; 267349e11e3aSSheldon Hearnfor commands and tracked aliases 267449e11e3aSSheldon Hearnthe complete pathname of the command is printed. 2675250d9fd8SKonstantin Belousov.It Ic ulimit Oo Fl HSabcdfklmnopstuvw Oc Op Ar limit 2676ab72124fSSteve PriceSet or display resource limits (see 2677ab72124fSSteve Price.Xr getrlimit 2 ) . 26786b15476eSSheldon HearnIf 267949e11e3aSSheldon Hearn.Ar limit 26806b15476eSSheldon Hearnis specified, the named resource will be set; 26817a2afe64SJoerg Wunschotherwise the current resource value will be displayed. 2682ab72124fSSteve Price.Pp 26836b15476eSSheldon HearnIf 268449e11e3aSSheldon Hearn.Fl H 268549e11e3aSSheldon Hearnis specified, the hard limits will be set or displayed. 268649e11e3aSSheldon HearnWhile everybody is allowed to reduce a hard limit, 268749e11e3aSSheldon Hearnonly the superuser can increase it. 268849e11e3aSSheldon HearnThe 268949e11e3aSSheldon Hearn.Fl S 269049e11e3aSSheldon Hearnoption 2691eccea571SRuslan Ermilovspecifies the soft limits instead. 2692eccea571SRuslan ErmilovWhen displaying limits, 26936b15476eSSheldon Hearnonly one of 269449e11e3aSSheldon Hearn.Fl S 26956b15476eSSheldon Hearnor 269649e11e3aSSheldon Hearn.Fl H 269749e11e3aSSheldon Hearncan be given. 269849e11e3aSSheldon HearnThe default is to display the soft limits, 269949e11e3aSSheldon Hearnand to set both the hard and the soft limits. 2700ab72124fSSteve Price.Pp 27016b15476eSSheldon HearnOption 270249e11e3aSSheldon Hearn.Fl a 270349e11e3aSSheldon Hearncauses the 270449e11e3aSSheldon Hearn.Ic ulimit 270549e11e3aSSheldon Hearncommand to display all resources. 270649e11e3aSSheldon HearnThe parameter 270749e11e3aSSheldon Hearn.Ar limit 27086b15476eSSheldon Hearnis not acceptable in this mode. 2709ab72124fSSteve Price.Pp 27107a2afe64SJoerg WunschThe remaining options specify which resource value is to be 271149e11e3aSSheldon Hearndisplayed or modified. 271249e11e3aSSheldon HearnThey are mutually exclusive. 271381e9cda2SRuslan Ermilov.Bl -tag -width indent 27143652a236SMartin Cracauer.It Fl b Ar sbsize 27153652a236SMartin CracauerThe maximum size of socket buffer usage, in bytes. 271649e11e3aSSheldon Hearn.It Fl c Ar coredumpsize 27177a2afe64SJoerg WunschThe maximal size of core dump files, in 512-byte blocks. 271817e98da8SMateusz PiotrowskiSetting 271917e98da8SMateusz Piotrowski.Ar coredumpsize 272017e98da8SMateusz Piotrowskito 0 prevents core dump files from being created. 272149e11e3aSSheldon Hearn.It Fl d Ar datasize 27227a2afe64SJoerg WunschThe maximal size of the data segment of a process, in kilobytes. 272349e11e3aSSheldon Hearn.It Fl f Ar filesize 272449e11e3aSSheldon HearnThe maximal size of a file, in 512-byte blocks. 2725d2c068eaSJilles Tjoelker.It Fl k Ar kqueues 2726d2c068eaSJilles TjoelkerThe maximal number of kqueues 2727d2c068eaSJilles Tjoelker(see 2728d2c068eaSJilles Tjoelker.Xr kqueue 2 ) 2729d2c068eaSJilles Tjoelkerfor this user ID. 273049e11e3aSSheldon Hearn.It Fl l Ar lockedmem 27317a2afe64SJoerg WunschThe maximal size of memory that can be locked by a process, in 27327a2afe64SJoerg Wunschkilobytes. 273349e11e3aSSheldon Hearn.It Fl m Ar memoryuse 27347a2afe64SJoerg WunschThe maximal resident set size of a process, in kilobytes. 273549e11e3aSSheldon Hearn.It Fl n Ar nofiles 27367a2afe64SJoerg WunschThe maximal number of descriptors that could be opened by a process. 2737250d9fd8SKonstantin Belousov.It Fl o Ar umtxp 2738250d9fd8SKonstantin BelousovThe maximal number of process-shared locks 2739250d9fd8SKonstantin Belousov(see 2740250d9fd8SKonstantin Belousov.Xr pthread 3 ) 2741250d9fd8SKonstantin Belousovfor this user ID. 2742331773cdSEd Schouten.It Fl p Ar pseudoterminals 2743331773cdSEd SchoutenThe maximal number of pseudo-terminals for this user ID. 274449e11e3aSSheldon Hearn.It Fl s Ar stacksize 27457a2afe64SJoerg WunschThe maximal size of the stack segment, in kilobytes. 274649e11e3aSSheldon Hearn.It Fl t Ar time 27477a2afe64SJoerg WunschThe maximal amount of CPU time to be used by each process, in seconds. 274849e11e3aSSheldon Hearn.It Fl u Ar userproc 2749ab72124fSSteve PriceThe maximal number of simultaneous processes for this user ID. 275062df9b62SSheldon Hearn.It Fl v Ar virtualmem 27512d41ef4bSMatthew DillonThe maximal virtual size of a process, in kilobytes. 2752c8054a61SJilles Tjoelker.It Fl w Ar swapuse 2753c8054a61SJilles TjoelkerThe maximum amount of swap space reserved or used for this user ID, 2754c8054a61SJilles Tjoelkerin kilobytes. 2755ab72124fSSteve Price.El 2756faa1ed35SStefan Farfeleder.It Ic umask Oo Fl S Oc Op Ar mask 275749e11e3aSSheldon HearnSet the file creation mask (see 2758ab72124fSSteve Price.Xr umask 2 ) 2759faa1ed35SStefan Farfelederto the octal or symbolic (see 2760faa1ed35SStefan Farfeleder.Xr chmod 1 ) 2761faa1ed35SStefan Farfeledervalue specified by 27625d3b843bSSheldon Hearn.Ar mask . 276349e11e3aSSheldon HearnIf the argument is omitted, the current mask value is printed. 2764faa1ed35SStefan FarfelederIf the 2765faa1ed35SStefan Farfeleder.Fl S 2766faa1ed35SStefan Farfelederoption is specified, the output is symbolic, otherwise the output is octal. 2767de4ad382SStefan Farfeleder.It Ic unalias Oo Fl a Oc Op Ar name ... 2768de4ad382SStefan FarfelederThe specified alias names are removed. 27696b15476eSSheldon HearnIf 27701b9735e6SSheldon Hearn.Fl a 27716b15476eSSheldon Hearnis specified, all aliases are removed. 27729ba31ca0SRuslan Ermilov.It Ic unset Oo Fl fv Oc Ar name ... 27738b34ad92STim J. RobbinsThe specified variables or functions are unset and unexported. 27748b34ad92STim J. RobbinsIf the 27758b34ad92STim J. Robbins.Fl v 27768b34ad92STim J. Robbinsoption is specified or no options are given, the 277749e11e3aSSheldon Hearn.Ar name 27788b34ad92STim J. Robbinsarguments are treated as variable names. 27798b34ad92STim J. RobbinsIf the 27808b34ad92STim J. Robbins.Fl f 27818b34ad92STim J. Robbinsoption is specified, the 27828b34ad92STim J. Robbins.Ar name 27838b34ad92STim J. Robbinsarguments are treated as function names. 2784bd76c6b8SJilles Tjoelker.It Ic wait Op Ar job ... 2785bd76c6b8SJilles TjoelkerWait for each specified 278649e11e3aSSheldon Hearn.Ar job 278749e11e3aSSheldon Hearnto complete and return the exit status of the last process in the 2788bd76c6b8SJilles Tjoelkerlast specified 278949e11e3aSSheldon Hearn.Ar job . 2790bd76c6b8SJilles TjoelkerIf any 2791bd76c6b8SJilles Tjoelker.Ar job 2792bd76c6b8SJilles Tjoelkerspecified is unknown to the shell, it is treated as if it 2793bd76c6b8SJilles Tjoelkerwere a known job that exited with exit status 127. 2794bd76c6b8SJilles TjoelkerIf no operands are given, wait for all jobs to complete 2795e6d3cf26SSheldon Hearnand return an exit status of zero. 2796ab72124fSSteve Price.El 27976986f58fSJilles Tjoelker.Ss Command Line Editing 2798ab72124fSSteve PriceWhen 2799ab72124fSSteve Price.Nm 2800ab72124fSSteve Priceis being used interactively from a terminal, the current command 280149e11e3aSSheldon Hearnand the command history 280249e11e3aSSheldon Hearn(see 280349e11e3aSSheldon Hearn.Ic fc 280449e11e3aSSheldon Hearnin 28058eed22b1SJens Schweikhardt.Sx Built-in Commands ) 2806dfe302abSRuslan Ermilovcan be edited using 2807dfe302abSRuslan Ermilov.Nm vi Ns -mode 2808dfe302abSRuslan Ermilovcommand line editing. 280949e11e3aSSheldon HearnThis mode uses commands similar 2810dfe302abSRuslan Ermilovto a subset of those described in the 2811dfe302abSRuslan Ermilov.Xr vi 1 2812dfe302abSRuslan Ermilovman page. 281349e11e3aSSheldon HearnThe command 2814dfe302abSRuslan Ermilov.Dq Li "set -o vi" 281549e11e3aSSheldon Hearn(or 2816dfe302abSRuslan Ermilov.Dq Li "set -V" ) 2817dfe302abSRuslan Ermilovenables 2818dfe302abSRuslan Ermilov.Nm vi Ns -mode 2819dfe302abSRuslan Ermilovediting and places 2820ab72124fSSteve Price.Nm 2821dfe302abSRuslan Ermilovinto 2822dfe302abSRuslan Ermilov.Nm vi 2823dfe302abSRuslan Ermilovinsert mode. 2824dfe302abSRuslan ErmilovWith 2825dfe302abSRuslan Ermilov.Nm vi Ns -mode 2826dfe302abSRuslan Ermilovenabled, 2827ab72124fSSteve Price.Nm 282849e11e3aSSheldon Hearncan be switched between insert mode and command mode by typing 282949e11e3aSSheldon Hearn.Aq ESC . 283049e11e3aSSheldon HearnHitting 283149e11e3aSSheldon Hearn.Aq return 283249e11e3aSSheldon Hearnwhile in command mode will pass the line to the shell. 2833ab72124fSSteve Price.Pp 283449e11e3aSSheldon HearnSimilarly, the 2835dfe302abSRuslan Ermilov.Dq Li "set -o emacs" 283649e11e3aSSheldon Hearn(or 2837dfe302abSRuslan Ermilov.Dq Li "set -E" ) 283849e11e3aSSheldon Hearncommand can be used to enable a subset of 2839dfe302abSRuslan Ermilov.Nm emacs Ns -style 2840dfe302abSRuslan Ermilovcommand line editing features. 284138afdcbcSGiorgos Keramidas.Sh ENVIRONMENT 284238afdcbcSGiorgos KeramidasThe following environment variables affect the execution of 284338afdcbcSGiorgos Keramidas.Nm : 28441788b7ffSJilles Tjoelker.Bl -tag -width ".Ev LANGXXXXXX" 28451788b7ffSJilles Tjoelker.It Ev ENV 28461788b7ffSJilles TjoelkerInitialization file for interactive shells. 28471788b7ffSJilles Tjoelker.It Ev LANG , Ev LC_* 28481788b7ffSJilles TjoelkerLocale settings. 28491788b7ffSJilles TjoelkerThese are inherited by children of the shell, 28501788b7ffSJilles Tjoelkerand is used in a limited manner by the shell itself. 28517b6779b6SJilles Tjoelker.It Ev OLDPWD 28527b6779b6SJilles TjoelkerThe previous current directory. 28537b6779b6SJilles TjoelkerThis is used and updated by 28547b6779b6SJilles Tjoelker.Ic cd . 28551788b7ffSJilles Tjoelker.It Ev PWD 28561788b7ffSJilles TjoelkerAn absolute pathname for the current directory, 28571788b7ffSJilles Tjoelkerpossibly containing symbolic links. 28581788b7ffSJilles TjoelkerThis is used and updated by the shell. 285938afdcbcSGiorgos Keramidas.It Ev TERM 286038afdcbcSGiorgos KeramidasThe default terminal setting for the shell. 286138afdcbcSGiorgos KeramidasThis is inherited by children of the shell, and is used in the history 286238afdcbcSGiorgos Keramidasediting modes. 286338afdcbcSGiorgos Keramidas.El 28641788b7ffSJilles Tjoelker.Pp 28654445af21SJilles TjoelkerAdditionally, environment variables are turned into shell variables 28661788b7ffSJilles Tjoelkerat startup, 28671788b7ffSJilles Tjoelkerwhich may affect the shell as described under 28681788b7ffSJilles Tjoelker.Sx Special Variables . 2869cb5a6a58SJoel Dahl.Sh FILES 2870cb5a6a58SJoel Dahl.Bl -tag -width "/etc/suid_profileXX" -compact 2871cb5a6a58SJoel Dahl.It Pa ~/.profile 2872cb5a6a58SJoel DahlUser's login profile. 2873cb5a6a58SJoel Dahl.It Pa /etc/profile 2874cb5a6a58SJoel DahlSystem login profile. 2875cb5a6a58SJoel Dahl.It Pa /etc/shells 2876cb5a6a58SJoel DahlShell database. 2877cb5a6a58SJoel Dahl.It Pa /etc/suid_profile 2878cb5a6a58SJoel DahlPrivileged shell profile. 2879cb5a6a58SJoel Dahl.El 2880fb039b55SRuslan Ermilov.Sh EXIT STATUS 288177da4a95SJilles TjoelkerIf the 288277da4a95SJilles Tjoelker.Ar script 288377da4a95SJilles Tjoelkercannot be found, the exit status will be 127; 288477da4a95SJilles Tjoelkerif it cannot be opened for another reason, the exit status will be 126. 288577da4a95SJilles TjoelkerOther errors that are detected by the shell, such as a syntax error, will 2886fb039b55SRuslan Ermilovcause the shell to exit with a non-zero exit status. 2887fb039b55SRuslan ErmilovIf the shell is not an interactive shell, the execution of the shell 2888fb039b55SRuslan Ermilovfile will be aborted. 2889fb039b55SRuslan ErmilovOtherwise the shell will return the exit status of the last command 2890dfe302abSRuslan Ermilovexecuted, or if the 2891dfe302abSRuslan Ermilov.Ic exit 2892dfe302abSRuslan Ermilovbuiltin is used with a numeric argument, it 2893fb039b55SRuslan Ermilovwill return the argument. 2894c83e7c50SJoseph Koshy.Sh SEE ALSO 2895c644db6aSSheldon Hearn.Xr builtin 1 , 289638afdcbcSGiorgos Keramidas.Xr chsh 1 , 2897c644db6aSSheldon Hearn.Xr echo 1 , 289838afdcbcSGiorgos Keramidas.Xr ed 1 , 2899825225e5SJens Schweikhardt.Xr emacs 1 Pq Pa ports/editors/emacs , 29000a62a9caSJilles Tjoelker.Xr kill 1 , 29019897c45fSJilles Tjoelker.Xr printf 1 , 29025521ff5aSRuslan Ermilov.Xr pwd 1 , 290338afdcbcSGiorgos Keramidas.Xr test 1 , 290438afdcbcSGiorgos Keramidas.Xr vi 1 , 290538afdcbcSGiorgos Keramidas.Xr execve 2 , 290638afdcbcSGiorgos Keramidas.Xr getrlimit 2 , 2907fd50df30SRuslan Ermilov.Xr umask 2 , 2908ff4dc672SJilles Tjoelker.Xr wctype 3 , 2909cb5a6a58SJoel Dahl.Xr editrc 5 , 2910cb5a6a58SJoel Dahl.Xr shells 5 2911ab72124fSSteve Price.Sh HISTORY 2912b8923d4cSWolfram SchneiderA 2913ab72124fSSteve Price.Nm 29149cdd1e3fSYaroslav Tykhiycommand, the Thompson shell, appeared in 2915fc482908STim J. Robbins.At v1 . 29169cdd1e3fSYaroslav TykhiyIt was superseded in 29179cdd1e3fSYaroslav Tykhiy.At v7 29189cdd1e3fSYaroslav Tykhiyby the Bourne shell, which inherited the name 29199cdd1e3fSYaroslav Tykhiy.Nm . 29209cdd1e3fSYaroslav Tykhiy.Pp 29219cdd1e3fSYaroslav TykhiyThis version of 29229cdd1e3fSYaroslav Tykhiy.Nm 29239cdd1e3fSYaroslav Tykhiywas rewritten in 1989 under the 29249cdd1e3fSYaroslav Tykhiy.Bx 29259cdd1e3fSYaroslav Tykhiylicense after the Bourne shell from 29269cdd1e3fSYaroslav Tykhiy.At V.4 . 29279cdd1e3fSYaroslav Tykhiy.Sh AUTHORS 29289cdd1e3fSYaroslav TykhiyThis version of 29299cdd1e3fSYaroslav Tykhiy.Nm 29309badf57fSRuslan Ermilovwas originally written by 29319badf57fSRuslan Ermilov.An Kenneth Almquist . 2932128dc4a2STim J. Robbins.Sh BUGS 2933128dc4a2STim J. RobbinsThe 2934128dc4a2STim J. Robbins.Nm 293550df3424SJilles Tjoelkerutility does not recognize multibyte characters other than UTF-8. 293650df3424SJilles TjoelkerSplitting using 293750df3424SJilles Tjoelker.Va IFS 29388956c4ecSJilles Tjoelkerdoes not recognize multibyte characters. 2939