19ddb49cbSWarner Losh.\"- 24b88c807SRodney W. Grimes.\" Copyright (c) 1991, 1993 34b88c807SRodney W. Grimes.\" The Regents of the University of California. All rights reserved. 44b88c807SRodney W. Grimes.\" 54b88c807SRodney W. Grimes.\" This code is derived from software contributed to Berkeley by 64b88c807SRodney W. Grimes.\" Kenneth Almquist. 74b88c807SRodney W. Grimes.\" 84b88c807SRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without 94b88c807SRodney W. Grimes.\" modification, are permitted provided that the following conditions 104b88c807SRodney W. Grimes.\" are met: 114b88c807SRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright 124b88c807SRodney W. Grimes.\" notice, this list of conditions and the following disclaimer. 134b88c807SRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright 144b88c807SRodney W. Grimes.\" notice, this list of conditions and the following disclaimer in the 154b88c807SRodney W. Grimes.\" documentation and/or other materials provided with the distribution. 164b88c807SRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors 174b88c807SRodney W. Grimes.\" may be used to endorse or promote products derived from this software 184b88c807SRodney W. Grimes.\" without specific prior written permission. 194b88c807SRodney W. Grimes.\" 204b88c807SRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 214b88c807SRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 224b88c807SRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 234b88c807SRodney W. Grimes.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 244b88c807SRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 254b88c807SRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 264b88c807SRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 274b88c807SRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 284b88c807SRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 294b88c807SRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 304b88c807SRodney W. Grimes.\" SUCH DAMAGE. 314b88c807SRodney W. Grimes.\" 32ab72124fSSteve Price.\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95 332a456239SPeter Wemm.\" $FreeBSD$ 344b88c807SRodney W. Grimes.\" 359cdd1e3fSYaroslav Tykhiy.Dd July 29, 2006 36ab72124fSSteve Price.Dt SH 1 37caa2db3bSRuslan Ermilov.Os 38ab72124fSSteve Price.Sh NAME 39ab72124fSSteve Price.Nm sh 40ab72124fSSteve Price.Nd command interpreter (shell) 41ab72124fSSteve Price.Sh SYNOPSIS 42ab72124fSSteve Price.Nm 437e1975c2STim J. Robbins.Op Fl /+abCEefIimnPpsTuVvx 44ab72124fSSteve Price.Op Fl /+o Ar longname 45c7a197e1SWolfram Schneider.Op Fl c Ar string 4681e9cda2SRuslan Ermilov.Op Ar arg ... 47ab72124fSSteve Price.Sh DESCRIPTION 48e918fc8fSSheldon HearnThe 49e918fc8fSSheldon Hearn.Nm 50e918fc8fSSheldon Hearnutility is the standard command interpreter for the system. 51ab72124fSSteve PriceThe current version of 52ab72124fSSteve Price.Nm 53ab72124fSSteve Priceis in the process of being changed to 54ab72124fSSteve Priceconform with the 55ab72124fSSteve Price.St -p1003.2 56eccea571SRuslan Ermilovspecification for the shell. 57eccea571SRuslan ErmilovThis version has many features which make 58ab72124fSSteve Priceit appear 594b88c807SRodney W. Grimessimilar in some respects to the Korn shell, but it is not a Korn 60fbc8f8a2SJens Schweikhardtshell clone like pdksh. 6149e11e3aSSheldon HearnOnly features 624b88c807SRodney W. Grimesdesignated by POSIX, plus a few Berkeley extensions, are being 63ab72124fSSteve Priceincorporated into this shell. 6449e11e3aSSheldon HearnThis man page is not intended to be a tutorial nor a complete 654b88c807SRodney W. Grimesspecification of the shell. 66ab72124fSSteve Price.Ss Overview 674b88c807SRodney W. GrimesThe shell is a command that reads lines from 684b88c807SRodney W. Grimeseither a file or the terminal, interprets them, and 69e6d3cf26SSheldon Hearngenerally executes other commands. 7049e11e3aSSheldon HearnIt is the program that is started when a user logs into the system, 7149e11e3aSSheldon Hearnalthough a user can select a different shell with the 72c644db6aSSheldon Hearn.Xr chsh 1 7349e11e3aSSheldon Hearncommand. 744b88c807SRodney W. GrimesThe shell 754b88c807SRodney W. Grimesimplements a language that has flow control constructs, 764b88c807SRodney W. Grimesa macro facility that provides a variety of features in 778eed22b1SJens Schweikhardtaddition to data storage, along with built-in history and line 78eccea571SRuslan Ermilovediting capabilities. 79eccea571SRuslan ErmilovIt incorporates many features to 804b88c807SRodney W. Grimesaid interactive use and has the advantage that the interpretative 814b88c807SRodney W. Grimeslanguage is common to both interactive and non-interactive 82eccea571SRuslan Ermilovuse (shell scripts). 83eccea571SRuslan ErmilovThat is, commands can be typed directly 8449e11e3aSSheldon Hearnto the running shell or can be put into a file, 8549e11e3aSSheldon Hearnwhich can be executed directly by the shell. 86ab72124fSSteve Price.Ss Invocation 8749e11e3aSSheldon Hearn.\" 8849e11e3aSSheldon Hearn.\" XXX This next sentence is incredibly confusing. 8949e11e3aSSheldon Hearn.\" 9049e11e3aSSheldon HearnIf no arguments are present and if the standard input of the shell 9149e11e3aSSheldon Hearnis connected to a terminal 9249e11e3aSSheldon Hearn(or if the 9349e11e3aSSheldon Hearn.Fl i 9449e11e3aSSheldon Hearnoption is set), 95eccea571SRuslan Ermilovthe shell is considered an interactive shell. 96eccea571SRuslan ErmilovAn interactive shell 974b88c807SRodney W. Grimesgenerally prompts before each command and handles programming 984b88c807SRodney W. Grimesand command errors differently (as described below). 994b88c807SRodney W. GrimesWhen first starting, the shell inspects argument 0, and 10049e11e3aSSheldon Hearnif it begins with a dash 101a762afe5SGiorgos Keramidas.Pq Ql - , 10249e11e3aSSheldon Hearnthe shell is also considered a login shell. 10349e11e3aSSheldon HearnThis is normally done automatically by the system 104eccea571SRuslan Ermilovwhen the user first logs in. 105eccea571SRuslan ErmilovA login shell first reads commands 106ab72124fSSteve Pricefrom the files 107ab72124fSSteve Price.Pa /etc/profile 10849e11e3aSSheldon Hearnand then 109ab72124fSSteve Price.Pa .profile 110eccea571SRuslan Ermilovif they exist. 111eccea571SRuslan ErmilovIf the environment variable 112ab72124fSSteve Price.Ev ENV 113ab72124fSSteve Priceis set on entry to a shell, or is set in the 114ab72124fSSteve Price.Pa .profile 11549e11e3aSSheldon Hearnof a login shell, the shell then reads commands from the file named in 116ab72124fSSteve Price.Ev ENV . 117ab72124fSSteve PriceTherefore, a user should place commands that are to be executed only 118ab72124fSSteve Priceat login time in the 119ab72124fSSteve Price.Pa .profile 120ab72124fSSteve Pricefile, and commands that are executed for every shell inside the 121ab72124fSSteve Price.Ev ENV 122e6d3cf26SSheldon Hearnfile. 12349e11e3aSSheldon HearnThe user can set the 124ab72124fSSteve Price.Ev ENV 12549e11e3aSSheldon Hearnvariable to some file by placing the following line in the file 126ab72124fSSteve Price.Pa .profile 12749e11e3aSSheldon Hearnin the home directory, 128ab72124fSSteve Pricesubstituting for 129ab72124fSSteve Price.Pa .shinit 13049e11e3aSSheldon Hearnthe filename desired: 13149e11e3aSSheldon Hearn.Pp 13249e11e3aSSheldon Hearn.Dl ENV=$HOME/.shinit; export ENV 13349e11e3aSSheldon Hearn.Pp 13449e11e3aSSheldon HearnThe first non-option argument specified on the command line 13549e11e3aSSheldon Hearnwill be treated as the 1364b88c807SRodney W. Grimesname of a file from which to read commands (a shell script), and 1374b88c807SRodney W. Grimesthe remaining arguments are set as the positional parameters 138eccea571SRuslan Ermilovof the shell ($1, $2, etc). 139eccea571SRuslan ErmilovOtherwise, the shell reads commands 1404b88c807SRodney W. Grimesfrom its standard input. 141ea76be72SSteve Price.Pp 142ea76be72SSteve PriceUnlike older versions of 143ea76be72SSteve Price.Nm 144ea76be72SSteve Pricethe 145ea76be72SSteve Price.Ev ENV 146eccea571SRuslan Ermilovscript is only sourced on invocation of interactive shells. 147eccea571SRuslan ErmilovThis 148ea76be72SSteve Pricecloses a well-known, and sometimes easily exploitable security 149ea76be72SSteve Pricehole related to poorly thought out 150ea76be72SSteve Price.Ev ENV 151ea76be72SSteve Pricescripts. 152ab72124fSSteve Price.Ss Argument List Processing 153ab72124fSSteve PriceAll of the single letter options to 154ab72124fSSteve Price.Nm 15549e11e3aSSheldon Hearnhave a corresponding long name, 15649e11e3aSSheldon Hearnwith the exception of 15749e11e3aSSheldon Hearn.Fl c 15849e11e3aSSheldon Hearnand 15949e11e3aSSheldon Hearn.Fl /+o . 16049e11e3aSSheldon HearnThese long names are provided next to the single letter options 16149e11e3aSSheldon Hearnin the descriptions below. 16249e11e3aSSheldon HearnThe long name for an option may be specified as an argument to the 16349e11e3aSSheldon Hearn.Fl /+o 16449e11e3aSSheldon Hearnoption of 165facc6767SRuslan Ermilov.Nm . 16649e11e3aSSheldon HearnOnce the shell is running, 16749e11e3aSSheldon Hearnthe long name for an option may be specified as an argument to the 16849e11e3aSSheldon Hearn.Fl /+o 16949e11e3aSSheldon Hearnoption of the 170c644db6aSSheldon Hearn.Ic set 1718eed22b1SJens Schweikhardtbuilt-in command 17249e11e3aSSheldon Hearn(described later in the section called 1738eed22b1SJens Schweikhardt.Sx Built-in Commands ) . 17449e11e3aSSheldon HearnIntroducing an option with a dash 175a762afe5SGiorgos Keramidas.Pq Ql - 17649e11e3aSSheldon Hearnenables the option, 17749e11e3aSSheldon Hearnwhile using a plus 178a762afe5SGiorgos Keramidas.Pq Ql + 17949e11e3aSSheldon Hearndisables the option. 18049e11e3aSSheldon HearnA 18149e11e3aSSheldon Hearn.Dq Li -- 182fab26805SJoseph Koshyor plain 183a762afe5SGiorgos Keramidas.Dq Ql - 184fab26805SJoseph Koshywill stop option processing and will force the remaining 185fab26805SJoseph Koshywords on the command line to be treated as arguments. 18649e11e3aSSheldon HearnThe 18749e11e3aSSheldon Hearn.Fl /+o 18849e11e3aSSheldon Hearnand 18949e11e3aSSheldon Hearn.Fl c 19049e11e3aSSheldon Hearnoptions do not have long names. 19149e11e3aSSheldon HearnThey take arguments and are described after the single letter options. 19281e9cda2SRuslan Ermilov.Bl -tag -width indent 193ab72124fSSteve Price.It Fl a Li allexport 19449e11e3aSSheldon HearnFlag variables for export when assignments are made to them. 195ab72124fSSteve Price.It Fl b Li notify 196ab72124fSSteve PriceEnable asynchronous notification of background job 197ab72124fSSteve Pricecompletion. 198c4d9468eSRuslan Ermilov(UNIMPLEMENTED) 199ab72124fSSteve Price.It Fl C Li noclobber 200c644db6aSSheldon HearnDo not overwrite existing files with 20149e11e3aSSheldon Hearn.Dq Li > . 202ab72124fSSteve Price.It Fl E Li emacs 2038eed22b1SJens SchweikhardtEnable the built-in 204ab72124fSSteve Price.Xr emacs 1 20549e11e3aSSheldon Hearncommand line editor (disables the 206ab72124fSSteve Price.Fl V 20749e11e3aSSheldon Hearnoption if it has been set). 208ab72124fSSteve Price.It Fl e Li errexit 20949e11e3aSSheldon HearnExit immediately if any untested command fails in non-interactive mode. 2104b88c807SRodney W. GrimesThe exit status of a command is considered to be 21174053659SStefan Farfelederexplicitly tested if the command is part of the list used to control 2128af11131SRuslan Ermilovan 2138af11131SRuslan Ermilov.Ic if , elif , while , 2148af11131SRuslan Ermilovor 2158af11131SRuslan Ermilov.Ic until ; 2168af11131SRuslan Ermilovif the command is the left 217ab72124fSSteve Pricehand operand of an 21849e11e3aSSheldon Hearn.Dq Li && 219ab72124fSSteve Priceor 22049e11e3aSSheldon Hearn.Dq Li || 22174053659SStefan Farfelederoperator; or if the command is a pipeline preceded by the 22274053659SStefan Farfeleder.Ic !\& 223ab72124fSSteve Priceoperator. 22474053659SStefan FarfelederIf a shell function is executed and its exit status is explicitly 22574053659SStefan Farfeledertested, all commands of the function are considered to be tested as 22674053659SStefan Farfelederwell. 227ab72124fSSteve Price.It Fl f Li noglob 2284b88c807SRodney W. GrimesDisable pathname expansion. 229ab72124fSSteve Price.It Fl I Li ignoreeof 23049e11e3aSSheldon HearnIgnore 23149e11e3aSSheldon Hearn.Dv EOF Ns ' Ns s 23249e11e3aSSheldon Hearnfrom input when in interactive mode. 233ab72124fSSteve Price.It Fl i Li interactive 234ab72124fSSteve PriceForce the shell to behave interactively. 235ab72124fSSteve Price.It Fl m Li monitor 236ab72124fSSteve PriceTurn on job control (set automatically when interactive). 237ab72124fSSteve Price.It Fl n Li noexec 2384b88c807SRodney W. GrimesIf not interactive, read commands but do not 239eccea571SRuslan Ermilovexecute them. 240eccea571SRuslan ErmilovThis is useful for checking the 2414b88c807SRodney W. Grimessyntax of shell scripts. 2427e1975c2STim J. Robbins.It Fl P Li physical 2437e1975c2STim J. RobbinsChange the default for the 2447e1975c2STim J. Robbins.Ic cd 2457e1975c2STim J. Robbinsand 2467e1975c2STim J. Robbins.Ic pwd 2477e1975c2STim J. Robbinscommands from 2487e1975c2STim J. Robbins.Fl L 2497e1975c2STim J. Robbins(logical directory layout) 2507e1975c2STim J. Robbinsto 2517e1975c2STim J. Robbins.Fl P 2527e1975c2STim J. Robbins(physical directory layout). 253ab72124fSSteve Price.It Fl p Li privileged 254eccea571SRuslan ErmilovTurn on privileged mode. 255eccea571SRuslan ErmilovThis mode is enabled on startup 256621a31c6SSteve Priceif either the effective user or group id is not equal to the 257eccea571SRuslan Ermilovreal user or group id. 258eccea571SRuslan ErmilovTurning this mode off sets the 259621a31c6SSteve Priceeffective user and group ids to the real user and group ids. 26049e11e3aSSheldon HearnWhen this mode is enabled for interactive shells, the file 261ab72124fSSteve Price.Pa /etc/suid_profile 26249e11e3aSSheldon Hearnis sourced instead of 26349e11e3aSSheldon Hearn.Pa ~/.profile 264ab72124fSSteve Priceafter 265ab72124fSSteve Price.Pa /etc/profile 26649e11e3aSSheldon Hearnis sourced, and the contents of the 267ab72124fSSteve Price.Ev ENV 26849e11e3aSSheldon Hearnvariable are ignored. 269ab72124fSSteve Price.It Fl s Li stdin 2704b88c807SRodney W. GrimesRead commands from standard input (set automatically 271eccea571SRuslan Ermilovif no file arguments are present). 272eccea571SRuslan ErmilovThis option has 2734b88c807SRodney W. Grimesno effect when set after the shell has already started 274eccea571SRuslan Ermilovrunning (i.e., when set with the 275c644db6aSSheldon Hearn.Ic set 2766b15476eSSheldon Hearncommand). 277304199ceSTom Rhodes.It Fl T Li trapsasync 278e6d3cf26SSheldon HearnWhen waiting for a child, execute traps immediately. 279e6d3cf26SSheldon HearnIf this option is not set, 280e6d3cf26SSheldon Hearntraps are executed after the child exits, 281e6d3cf26SSheldon Hearnas specified in 282af5eb6fcSMaxim Konovalov.St -p1003.2 . 2836b15476eSSheldon HearnThis nonstandard option is useful for putting guarding shells around 284eccea571SRuslan Ermilovchildren that block signals. 285eccea571SRuslan ErmilovThe surrounding shell may kill the child 2866b15476eSSheldon Hearnor it may just return control to the tty and leave the child alone, 2876b15476eSSheldon Hearnlike this: 288c1c72a3cSMartin Cracauer.Bd -literal -offset indent 289c1c72a3cSMartin Cracauersh -T -c "trap 'exit 1' 2 ; some-blocking-program" 290c1c72a3cSMartin Cracauer.Ed 291c1c72a3cSMartin Cracauer.Pp 292ab72124fSSteve Price.It Fl u Li nounset 293ab72124fSSteve PriceWrite a message to standard error when attempting 294ab72124fSSteve Priceto expand a variable that is not set, and if the 295ab72124fSSteve Priceshell is not interactive, exit immediately. 296ab72124fSSteve Price.It Fl V Li vi 2978eed22b1SJens SchweikhardtEnable the built-in 298ab72124fSSteve Price.Xr vi 1 299ab72124fSSteve Pricecommand line editor (disables 300ab72124fSSteve Price.Fl E 301ab72124fSSteve Priceif it has been set). 302ab72124fSSteve Price.It Fl v Li verbose 303ab72124fSSteve PriceThe shell writes its input to standard error 304eccea571SRuslan Ermilovas it is read. 305eccea571SRuslan ErmilovUseful for debugging. 306ab72124fSSteve Price.It Fl x Li xtrace 30749e11e3aSSheldon HearnWrite each command 308120c8e6cSStefan Farfeleder(preceded by the value of the 309120c8e6cSStefan Farfeleder.Ev PS4 310120c8e6cSStefan Farfeledervariable) 31149e11e3aSSheldon Hearnto standard error before it is executed. 31249e11e3aSSheldon HearnUseful for debugging. 31349e11e3aSSheldon Hearn.El 31449e11e3aSSheldon Hearn.Pp 31549e11e3aSSheldon HearnThe 316fd50df30SRuslan Ermilov.Fl c 317fd50df30SRuslan Ermilovoption causes the commands to be read from the 318fd50df30SRuslan Ermilov.Ar string 319fd50df30SRuslan Ermilovoperand instead of from the standard input. 320fd50df30SRuslan ErmilovKeep in mind that this option only accepts a single string as its 321fd50df30SRuslan Ermilovargument, hence multi-word strings must be quoted. 322fd50df30SRuslan Ermilov.Pp 323fd50df30SRuslan ErmilovThe 32449e11e3aSSheldon Hearn.Fl /+o 32549e11e3aSSheldon Hearnoption takes as its only argument the long name of an option 32649e11e3aSSheldon Hearnto be enabled or disabled. 32749e11e3aSSheldon HearnFor example, the following two invocations of 32849e11e3aSSheldon Hearn.Nm 3298eed22b1SJens Schweikhardtboth enable the built-in 33049e11e3aSSheldon Hearn.Xr emacs 1 33149e11e3aSSheldon Hearncommand line editor: 33249e11e3aSSheldon Hearn.Bd -literal -offset indent 33349e11e3aSSheldon Hearnset -E 33449e11e3aSSheldon Hearnset -o emacs 33549e11e3aSSheldon Hearn.Ed 336d513af6aSTim J. Robbins.Pp 337d513af6aSTim J. RobbinsIf used without an argument, the 338d513af6aSTim J. Robbins.Fl o 339d513af6aSTim J. Robbinsoption displays the current option settings in a human-readable format. 340d513af6aSTim J. RobbinsIf 341d513af6aSTim J. Robbins.Cm +o 342d513af6aSTim J. Robbinsis used without an argument, the current option settings are output 343d513af6aSTim J. Robbinsin a format suitable for re-input into the shell. 344ab72124fSSteve Price.Ss Lexical Structure 3454b88c807SRodney W. GrimesThe shell reads input in terms of lines from a file and breaks 3464b88c807SRodney W. Grimesit up into words at whitespace (blanks and tabs), and at 3474b88c807SRodney W. Grimescertain sequences of 3486b15476eSSheldon Hearncharacters called 3496b15476eSSheldon Hearn.Dq operators , 3506b15476eSSheldon Hearnwhich are special to the shell. 3514b88c807SRodney W. GrimesThere are two types of operators: control operators and 3524b88c807SRodney W. Grimesredirection operators (their meaning is discussed later). 353ab72124fSSteve PriceThe following is a list of valid operators: 35481e9cda2SRuslan Ermilov.Bl -tag -width indent 35549e11e3aSSheldon Hearn.It Control operators: 35649e11e3aSSheldon Hearn.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 35781e9cda2SRuslan Ermilov.It Li & Ta Li && Ta Li ( Ta Li ) Ta Li \en 35881e9cda2SRuslan Ermilov.It Li ;; Ta Li ; Ta Li | Ta Li || 35949e11e3aSSheldon Hearn.El 36049e11e3aSSheldon Hearn.It Redirection operators: 3614682f420SBrian Somers.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 36281e9cda2SRuslan Ermilov.It Li < Ta Li > Ta Li << Ta Li >> Ta Li <> 36381e9cda2SRuslan Ermilov.It Li <& Ta Li >& Ta Li <<- Ta Li >| 36449e11e3aSSheldon Hearn.El 365ab72124fSSteve Price.El 3667d1a55fcSStefan Farfeleder.Pp 3677d1a55fcSStefan FarfelederThe character 3687d1a55fcSStefan Farfeleder.Ql # 3697d1a55fcSStefan Farfelederintroduces a comment if used at the beginning of a word. 3707d1a55fcSStefan FarfelederThe word starting with 3717d1a55fcSStefan Farfeleder.Ql # 3727d1a55fcSStefan Farfelederand the rest of the line are ignored. 373ab72124fSSteve Price.Ss Quoting 3744b88c807SRodney W. GrimesQuoting is used to remove the special meaning of certain characters 375a886288eSJesus R. Camouor words to the shell, such as operators, whitespace, keywords, 376a886288eSJesus R. Camouor alias names. 377a886288eSJesus R. Camou.Pp 378eccea571SRuslan ErmilovThere are three types of quoting: matched single quotes, 3794b88c807SRodney W. Grimesmatched double quotes, and backslash. 38081e9cda2SRuslan Ermilov.Bl -tag -width indent 381ab72124fSSteve Price.It Single Quotes 3824b88c807SRodney W. GrimesEnclosing characters in single quotes preserves the literal 383ab0a2172SSteve Pricemeaning of all the characters (except single quotes, making 384ab0a2172SSteve Priceit impossible to put single-quotes in a single-quoted string). 385ab72124fSSteve Price.It Double Quotes 3864b88c807SRodney W. GrimesEnclosing characters within double quotes preserves the literal 38749e11e3aSSheldon Hearnmeaning of all characters except dollarsign 388a762afe5SGiorgos Keramidas.Pq Ql $ , 38949e11e3aSSheldon Hearnbackquote 390a762afe5SGiorgos Keramidas.Pq Ql ` , 39149e11e3aSSheldon Hearnand backslash 392a762afe5SGiorgos Keramidas.Pq Ql \e . 39349e11e3aSSheldon HearnThe backslash inside double quotes is historically weird. 39449e11e3aSSheldon HearnIt remains literal unless it precedes the following characters, 39549e11e3aSSheldon Hearnwhich it serves to quote: 39649e11e3aSSheldon Hearn.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 39781e9cda2SRuslan Ermilov.It Li $ Ta Li ` Ta Li \&" Ta Li \e\ Ta Li \en 39849e11e3aSSheldon Hearn.El 399ab72124fSSteve Price.It Backslash 400ab72124fSSteve PriceA backslash preserves the literal meaning of the following 40149e11e3aSSheldon Hearncharacter, with the exception of the newline character 402a762afe5SGiorgos Keramidas.Pq Ql \en . 40349e11e3aSSheldon HearnA backslash preceding a newline is treated as a line continuation. 404ab72124fSSteve Price.El 405ab72124fSSteve Price.Ss Reserved Words 4064b88c807SRodney W. GrimesReserved words are words that have special meaning to the 4074b88c807SRodney W. Grimesshell and are recognized at the beginning of a line and 408eccea571SRuslan Ermilovafter a control operator. 409eccea571SRuslan ErmilovThe following are reserved words: 41049e11e3aSSheldon Hearn.Bl -column "doneXX" "elifXX" "elseXX" "untilXX" "whileX" -offset center 41181e9cda2SRuslan Ermilov.It Li \&! Ta { Ta } Ta Ic case Ta Ic do 41281e9cda2SRuslan Ermilov.It Ic done Ta Ic elif Ta Ic else Ta Ic esac Ta Ic fi 41381e9cda2SRuslan Ermilov.It Ic for Ta Ic if Ta Ic then Ta Ic until Ta Ic while 41449e11e3aSSheldon Hearn.El 415ab72124fSSteve Price.Ss Aliases 416ab72124fSSteve PriceAn alias is a name and corresponding value set using the 417c644db6aSSheldon Hearn.Ic alias 418eccea571SRuslan Ermilovbuilt-in command. 419eccea571SRuslan ErmilovWhenever a reserved word may occur (see above), 4204b88c807SRodney W. Grimesand after checking for reserved words, the shell 421e6d3cf26SSheldon Hearnchecks the word to see if it matches an alias. 422e6d3cf26SSheldon HearnIf it does, it replaces it in the input stream with its value. 423e6d3cf26SSheldon HearnFor example, if there is an alias called 42449e11e3aSSheldon Hearn.Dq Li lf 4256b15476eSSheldon Hearnwith the value 42649e11e3aSSheldon Hearn.Dq Li ls -F , 4274b88c807SRodney W. Grimesthen the input 428ab72124fSSteve Price.Bd -literal -offset indent 42949e11e3aSSheldon Hearnlf foobar 430ab72124fSSteve Price.Ed 431ab72124fSSteve Price.Pp 4324b88c807SRodney W. Grimeswould become 433ab72124fSSteve Price.Bd -literal -offset indent 43449e11e3aSSheldon Hearnls -F foobar 435ab72124fSSteve Price.Ed 436ab72124fSSteve Price.Pp 4374b88c807SRodney W. GrimesAliases provide a convenient way for naive users to 4384b88c807SRodney W. Grimescreate shorthands for commands without having to learn how 439eccea571SRuslan Ermilovto create functions with arguments. 440eccea571SRuslan ErmilovThey can also be 441eccea571SRuslan Ermilovused to create lexically obscure code. 442eccea571SRuslan ErmilovThis use is discouraged. 443a886288eSJesus R. Camou.Pp 444a886288eSJesus R. CamouAn alias name may be escaped in a command line, so that it is not 445a886288eSJesus R. Camoureplaced by its alias value, by using quoting characters within or 44619162ab9SJesus R. Camouadjacent to the alias name. 44719162ab9SJesus R. CamouThis is most often done by prefixing 448a886288eSJesus R. Camouan alias name with a backslash to execute a function, built-in, or 449a886288eSJesus R. Camounormal program with the same name. 450a886288eSJesus R. CamouSee the 451a886288eSJesus R. Camou.Sx Quoting 452a886288eSJesus R. Camousubsection. 453ab72124fSSteve Price.Ss Commands 4544b88c807SRodney W. GrimesThe shell interprets the words it reads according to a 4554b88c807SRodney W. Grimeslanguage, the specification of which is outside the scope 456ab72124fSSteve Priceof this man page (refer to the BNF in the 457ab72124fSSteve Price.St -p1003.2 458eccea571SRuslan Ermilovdocument). 459eccea571SRuslan ErmilovEssentially though, a line is read and if 4604b88c807SRodney W. Grimesthe first word of the line (or after a control operator) 4614b88c807SRodney W. Grimesis not a reserved word, then the shell has recognized a 462eccea571SRuslan Ermilovsimple command. 463eccea571SRuslan ErmilovOtherwise, a complex command or some 4644b88c807SRodney W. Grimesother special construct may have been recognized. 465ab72124fSSteve Price.Ss Simple Commands 4664b88c807SRodney W. GrimesIf a simple command has been recognized, the shell performs 4674b88c807SRodney W. Grimesthe following actions: 468ab72124fSSteve Price.Bl -enum 469ab72124fSSteve Price.It 4706b15476eSSheldon HearnLeading words of the form 47149e11e3aSSheldon Hearn.Dq Li name=value 4726b15476eSSheldon Hearnare stripped off and assigned to the environment of 473eccea571SRuslan Ermilovthe simple command. 474eccea571SRuslan ErmilovRedirection operators and 4754b88c807SRodney W. Grimestheir arguments (as described below) are stripped 4764b88c807SRodney W. Grimesoff and saved for processing. 477ab72124fSSteve Price.It 478ab72124fSSteve PriceThe remaining words are expanded as described in 4796b15476eSSheldon Hearnthe section called 4806b15476eSSheldon Hearn.Sx Word Expansions , 4816b15476eSSheldon Hearnand the first remaining word is considered the command 482eccea571SRuslan Ermilovname and the command is located. 483eccea571SRuslan ErmilovThe remaining 4844b88c807SRodney W. Grimeswords are considered the arguments of the command. 4856b15476eSSheldon HearnIf no command name resulted, then the 48649e11e3aSSheldon Hearn.Dq Li name=value 4874b88c807SRodney W. Grimesvariable assignments recognized in 1) affect the 4884b88c807SRodney W. Grimescurrent shell. 489ab72124fSSteve Price.It 490ab72124fSSteve PriceRedirections are performed as described in 4914b88c807SRodney W. Grimesthe next section. 492ab72124fSSteve Price.El 493ab72124fSSteve Price.Ss Redirections 4944b88c807SRodney W. GrimesRedirections are used to change where a command reads its input 495eccea571SRuslan Ermilovor sends its output. 496eccea571SRuslan ErmilovIn general, redirections open, close, or 497eccea571SRuslan Ermilovduplicate an existing reference to a file. 498eccea571SRuslan ErmilovThe overall format 4994b88c807SRodney W. Grimesused for redirection is: 50049e11e3aSSheldon Hearn.Pp 501ab72124fSSteve Price.Dl [n] redir-op file 50249e11e3aSSheldon Hearn.Pp 50349e11e3aSSheldon HearnThe 50449e11e3aSSheldon Hearn.Ql redir-op 50549e11e3aSSheldon Hearnis one of the redirection operators mentioned 506eccea571SRuslan Ermilovpreviously. 507eccea571SRuslan ErmilovThe following gives some examples of how these 50849e11e3aSSheldon Hearnoperators can be used. 50949e11e3aSSheldon HearnNote that stdin and stdout are commonly used abbreviations 51049e11e3aSSheldon Hearnfor standard input and standard output respectively. 51149e11e3aSSheldon Hearn.Bl -tag -width "1234567890XX" -offset indent 51249e11e3aSSheldon Hearn.It Li [n]> file 51349e11e3aSSheldon Hearnredirect stdout (or file descriptor n) to file 51449e11e3aSSheldon Hearn.It Li [n]>| file 51549e11e3aSSheldon Hearnsame as above, but override the 51649e11e3aSSheldon Hearn.Fl C 51749e11e3aSSheldon Hearnoption 51849e11e3aSSheldon Hearn.It Li [n]>> file 51949e11e3aSSheldon Hearnappend stdout (or file descriptor n) to file 52049e11e3aSSheldon Hearn.It Li [n]< file 52149e11e3aSSheldon Hearnredirect stdin (or file descriptor n) from file 5224682f420SBrian Somers.It Li [n]<> file 5234682f420SBrian Somersredirect stdin (or file descriptor n) to and from file 52449e11e3aSSheldon Hearn.It Li [n1]<&n2 52549e11e3aSSheldon Hearnduplicate stdin (or file descriptor n1) from file descriptor n2 52649e11e3aSSheldon Hearn.It Li [n]<&- 52749e11e3aSSheldon Hearnclose stdin (or file descriptor n) 52849e11e3aSSheldon Hearn.It Li [n1]>&n2 52949e11e3aSSheldon Hearnduplicate stdout (or file descriptor n1) to file descriptor n2 53049e11e3aSSheldon Hearn.It Li [n]>&- 53149e11e3aSSheldon Hearnclose stdout (or file descriptor n) 532ab72124fSSteve Price.El 533ab72124fSSteve Price.Pp 5346b15476eSSheldon HearnThe following redirection is often called a 5356b15476eSSheldon Hearn.Dq here-document . 536ab72124fSSteve Price.Bd -literal -offset indent 5374b88c807SRodney W. Grimes[n]<< delimiter 53849e11e3aSSheldon Hearn here-doc-text 53949e11e3aSSheldon Hearn ... 5404b88c807SRodney W. Grimesdelimiter 541ab72124fSSteve Price.Ed 542ab72124fSSteve Price.Pp 5434b88c807SRodney W. GrimesAll the text on successive lines up to the delimiter is 5444b88c807SRodney W. Grimessaved away and made available to the command on standard 545eccea571SRuslan Ermilovinput, or file descriptor n if it is specified. 546eccea571SRuslan ErmilovIf the delimiter 5474b88c807SRodney W. Grimesas specified on the initial line is quoted, then the here-doc-text 5484b88c807SRodney W. Grimesis treated literally, otherwise the text is subjected to 5494b88c807SRodney W. Grimesparameter expansion, command substitution, and arithmetic 5506b15476eSSheldon Hearnexpansion (as described in the section on 5516b15476eSSheldon Hearn.Sx Word Expansions ) . 5526b15476eSSheldon HearnIf the operator is 55349e11e3aSSheldon Hearn.Dq Li <<- 5546b15476eSSheldon Hearninstead of 55549e11e3aSSheldon Hearn.Dq Li << , 5566b15476eSSheldon Hearnthen leading tabs 5574b88c807SRodney W. Grimesin the here-doc-text are stripped. 558ab72124fSSteve Price.Ss Search and Execution 559ab0a2172SSteve PriceThere are three types of commands: shell functions, 5608eed22b1SJens Schweikhardtbuilt-in commands, and normal programs. 56149e11e3aSSheldon HearnThe command is searched for (by name) in that order. 56249e11e3aSSheldon HearnThe three types of commands are all executed in a different way. 563ab72124fSSteve Price.Pp 564ab0a2172SSteve PriceWhen a shell function is executed, all of the shell positional 565ab0a2172SSteve Priceparameters (except $0, which remains unchanged) are 5664b88c807SRodney W. Grimesset to the arguments of the shell function. 5674b88c807SRodney W. GrimesThe variables which are explicitly placed in the environment of 5684b88c807SRodney W. Grimesthe command (by placing assignments to them before the 5694b88c807SRodney W. Grimesfunction name) are made local to the function and are set 570e6d3cf26SSheldon Hearnto the values given. 571e6d3cf26SSheldon HearnThen the command given in the function definition is executed. 572e6d3cf26SSheldon HearnThe positional parameters are restored to their original values 573e6d3cf26SSheldon Hearnwhen the command completes. 574ab0a2172SSteve PriceThis all occurs within the current shell. 575ab72124fSSteve Price.Pp 5768eed22b1SJens SchweikhardtShell built-in commands are executed internally to the shell, without 577ab0a2172SSteve Pricespawning a new process. 578ab72124fSSteve Price.Pp 579c644db6aSSheldon HearnOtherwise, if the command name does not match a function 5808eed22b1SJens Schweikhardtor built-in command, the command is searched for as a normal 5814b88c807SRodney W. Grimesprogram in the file system (as described in the next section). 5824b88c807SRodney W. GrimesWhen a normal program is executed, the shell runs the program, 583e6d3cf26SSheldon Hearnpassing the arguments and the environment to the program. 584e6d3cf26SSheldon HearnIf the program is not a normal executable file 585eccea571SRuslan Ermilov(i.e., if it does not begin with the 5866b15476eSSheldon Hearn.Qq magic number 5876b15476eSSheldon Hearnwhose 588ab72124fSSteve Price.Tn ASCII 5896b15476eSSheldon Hearnrepresentation is 5906b15476eSSheldon Hearn.Qq #! , 59149e11e3aSSheldon Hearnresulting in an 592b4f0f4aaSRuslan Ermilov.Er ENOEXEC 59349e11e3aSSheldon Hearnreturn value from 59449e11e3aSSheldon Hearn.Xr execve 2 ) 595e6d3cf26SSheldon Hearnthe shell will interpret the program in a subshell. 596e6d3cf26SSheldon HearnThe child shell will reinitialize itself in this case, 597e6d3cf26SSheldon Hearnso that the effect will be 598e6d3cf26SSheldon Hearnas if a new shell had been invoked to handle the ad-hoc shell script, 599e6d3cf26SSheldon Hearnexcept that the location of hashed commands located in 6004b88c807SRodney W. Grimesthe parent shell will be remembered by the child. 601ab72124fSSteve Price.Pp 602ab0a2172SSteve PriceNote that previous versions of this document 603ab0a2172SSteve Priceand the source code itself misleadingly and sporadically 604ab0a2172SSteve Pricerefer to a shell script without a magic number 6056b15476eSSheldon Hearnas a 6066b15476eSSheldon Hearn.Qq shell procedure . 607ab72124fSSteve Price.Ss Path Search 6084b88c807SRodney W. GrimesWhen locating a command, the shell first looks to see if 609eccea571SRuslan Ermilovit has a shell function by that name. 610eccea571SRuslan ErmilovThen it looks for a 611eccea571SRuslan Ermilovbuilt-in command by that name. 612eccea571SRuslan ErmilovIf a built-in command is not found, 613ab0a2172SSteve Priceone of two things happen: 614ab72124fSSteve Price.Bl -enum 615ab72124fSSteve Price.It 616ab72124fSSteve PriceCommand names containing a slash are simply executed without 617ab0a2172SSteve Priceperforming any searches. 618ab72124fSSteve Price.It 619ab72124fSSteve PriceThe shell searches each entry in 620ab72124fSSteve Price.Ev PATH 621eccea571SRuslan Ermilovin turn for the command. 622eccea571SRuslan ErmilovThe value of the 623ab72124fSSteve Price.Ev PATH 624ab72124fSSteve Pricevariable should be a series of 625eccea571SRuslan Ermiloventries separated by colons. 626eccea571SRuslan ErmilovEach entry consists of a 6274b88c807SRodney W. Grimesdirectory name. 6284b88c807SRodney W. GrimesThe current directory 629ab0a2172SSteve Pricemay be indicated implicitly by an empty directory name, 630ab0a2172SSteve Priceor explicitly by a single period. 631ab72124fSSteve Price.El 632ab72124fSSteve Price.Ss Command Exit Status 6334b88c807SRodney W. GrimesEach command has an exit status that can influence the behavior 634eccea571SRuslan Ermilovof other shell commands. 635eccea571SRuslan ErmilovThe paradigm is that a command exits 6364b88c807SRodney W. Grimeswith zero for normal or success, and non-zero for failure, 637eccea571SRuslan Ermiloverror, or a false indication. 638eccea571SRuslan ErmilovThe man page for each command 6394b88c807SRodney W. Grimesshould indicate the various exit codes and what they mean. 6408eed22b1SJens SchweikhardtAdditionally, the built-in commands return exit codes, as does 641ab0a2172SSteve Pricean executed shell function. 642c351e089SJohn Polstra.Pp 643c351e089SJohn PolstraIf a command is terminated by a signal, its exit status is 128 plus 644eccea571SRuslan Ermilovthe signal number. 645eccea571SRuslan ErmilovSignal numbers are defined in the header file 646fe08efe6SRuslan Ermilov.In sys/signal.h . 647ab72124fSSteve Price.Ss Complex Commands 6484b88c807SRodney W. GrimesComplex commands are combinations of simple commands 6494b88c807SRodney W. Grimeswith control operators or reserved words, together creating a larger complex 650eccea571SRuslan Ermilovcommand. 651eccea571SRuslan ErmilovMore generally, a command is one of the following: 652ab72124fSSteve Price.Bl -item -offset indent 653ab72124fSSteve Price.It 654ab72124fSSteve Pricesimple command 655ab72124fSSteve Price.It 656ab72124fSSteve Pricepipeline 657ab72124fSSteve Price.It 658ab72124fSSteve Pricelist or compound-list 659ab72124fSSteve Price.It 660ab72124fSSteve Pricecompound command 661ab72124fSSteve Price.It 662ab72124fSSteve Pricefunction definition 663ab72124fSSteve Price.El 664ab72124fSSteve Price.Pp 6654b88c807SRodney W. GrimesUnless otherwise stated, the exit status of a command is 6664b88c807SRodney W. Grimesthat of the last simple command executed by the command. 667ab72124fSSteve Price.Ss Pipelines 6684b88c807SRodney W. GrimesA pipeline is a sequence of one or more commands separated 669eccea571SRuslan Ermilovby the control operator |. 670eccea571SRuslan ErmilovThe standard output of all but 6714b88c807SRodney W. Grimesthe last command is connected to the standard input 672eccea571SRuslan Ermilovof the next command. 673eccea571SRuslan ErmilovThe standard output of the last 674ab0a2172SSteve Pricecommand is inherited from the shell, as usual. 675ab72124fSSteve Price.Pp 6764b88c807SRodney W. GrimesThe format for a pipeline is: 67749e11e3aSSheldon Hearn.Pp 67849e11e3aSSheldon Hearn.Dl [!] command1 [ | command2 ...] 679ab72124fSSteve Price.Pp 6804b88c807SRodney W. GrimesThe standard output of command1 is connected to the standard 681eccea571SRuslan Ermilovinput of command2. 682eccea571SRuslan ErmilovThe standard input, standard output, or 6834b88c807SRodney W. Grimesboth of a command is considered to be assigned by the 6844b88c807SRodney W. Grimespipeline before any redirection specified by redirection 6854b88c807SRodney W. Grimesoperators that are part of the command. 686ab72124fSSteve Price.Pp 6874b88c807SRodney W. GrimesIf the pipeline is not in the background (discussed later), 6884b88c807SRodney W. Grimesthe shell waits for all commands to complete. 689ab72124fSSteve Price.Pp 690eccea571SRuslan ErmilovIf the reserved word 691eccea571SRuslan Ermilov.Ic !\& 692eccea571SRuslan Ermilovdoes not precede the pipeline, the 6934b88c807SRodney W. Grimesexit status is the exit status of the last command specified 694eccea571SRuslan Ermilovin the pipeline. 695eccea571SRuslan ErmilovOtherwise, the exit status is the logical 696eccea571SRuslan ErmilovNOT of the exit status of the last command. 697eccea571SRuslan ErmilovThat is, if 6984b88c807SRodney W. Grimesthe last command returns zero, the exit status is 1; if 6994b88c807SRodney W. Grimesthe last command returns greater than zero, the exit status 7004b88c807SRodney W. Grimesis zero. 701ab72124fSSteve Price.Pp 7024b88c807SRodney W. GrimesBecause pipeline assignment of standard input or standard 7034b88c807SRodney W. Grimesoutput or both takes place before redirection, it can be 704eccea571SRuslan Ermilovmodified by redirection. 705eccea571SRuslan ErmilovFor example: 706ab72124fSSteve Price.Pp 70749e11e3aSSheldon Hearn.Dl $ command1 2>&1 | command2 708ab72124fSSteve Price.Pp 70949e11e3aSSheldon Hearnsends both the standard output and standard error of 71049e11e3aSSheldon Hearn.Ql command1 71149e11e3aSSheldon Hearnto the standard input of 71249e11e3aSSheldon Hearn.Ql command2 . 71349e11e3aSSheldon Hearn.Pp 71449e11e3aSSheldon HearnA 71512e720d7SRuslan Ermilov.Dq Li \&; 71649e11e3aSSheldon Hearnor newline terminator causes the preceding 717e918fc8fSSheldon HearnAND-OR-list 718e918fc8fSSheldon Hearn(described below in the section called 719e918fc8fSSheldon Hearn.Sx Short-Circuit List Operators ) 720e918fc8fSSheldon Hearnto be executed sequentially; 721e918fc8fSSheldon Hearnan 722e918fc8fSSheldon Hearn.Dq Li & 723e918fc8fSSheldon Hearncauses asynchronous execution of the preceding AND-OR-list. 724ab72124fSSteve Price.Pp 72549e11e3aSSheldon HearnNote that unlike some other shells, 72649e11e3aSSheldon Hearn.Nm 72749e11e3aSSheldon Hearnexecutes each process in the pipeline as a child of the 72849e11e3aSSheldon Hearn.Nm 72949e11e3aSSheldon Hearnprocess. 7308eed22b1SJens SchweikhardtShell built-in commands are the exception to this rule. 73149e11e3aSSheldon HearnThey are executed in the current shell, although they do not affect its 73249e11e3aSSheldon Hearnenvironment when used in pipelines. 73349e11e3aSSheldon Hearn.Ss Background Commands (&) 7344b88c807SRodney W. GrimesIf a command is terminated by the control operator ampersand 735a762afe5SGiorgos Keramidas.Pq Ql & , 73649e11e3aSSheldon Hearnthe shell executes the command asynchronously; 73749e11e3aSSheldon Hearnthe shell does not wait for the command to finish 73849e11e3aSSheldon Hearnbefore executing the next command. 739ab72124fSSteve Price.Pp 7404b88c807SRodney W. GrimesThe format for running a command in background is: 741ab72124fSSteve Price.Bd -literal -offset indent 7424b88c807SRodney W. Grimescommand1 & [command2 & ...] 743ab72124fSSteve Price.Ed 744ab72124fSSteve Price.Pp 7454b88c807SRodney W. GrimesIf the shell is not interactive, the standard input of an 7464b88c807SRodney W. Grimesasynchronous command is set to /dev/null. 74749e11e3aSSheldon Hearn.Ss Lists (Generally Speaking) 7484b88c807SRodney W. GrimesA list is a sequence of zero or more commands separated by 7494b88c807SRodney W. Grimesnewlines, semicolons, or ampersands, 7504b88c807SRodney W. Grimesand optionally terminated by one of these three characters. 7514b88c807SRodney W. GrimesThe commands in a 7524b88c807SRodney W. Grimeslist are executed in the order they are written. 7534b88c807SRodney W. GrimesIf command is followed by an ampersand, the shell starts the 7548eed22b1SJens Schweikhardtcommand and immediately proceeds onto the next command; 7554b88c807SRodney W. Grimesotherwise it waits for the command to terminate before 7564b88c807SRodney W. Grimesproceeding to the next one. 757ab72124fSSteve Price.Ss Short-Circuit List Operators 75849e11e3aSSheldon Hearn.Dq Li && 7596b15476eSSheldon Hearnand 76049e11e3aSSheldon Hearn.Dq Li || 7616b15476eSSheldon Hearnare AND-OR list operators. 76249e11e3aSSheldon Hearn.Dq Li && 7636b15476eSSheldon Hearnexecutes the first command, and then executes the second command 7646b15476eSSheldon Hearnif the exit status of the first command is zero. 76549e11e3aSSheldon Hearn.Dq Li || 766120ac26dSMasafumi Max NAKANEis similar, but executes the second command if the exit 7676b15476eSSheldon Hearnstatus of the first command is nonzero. 76849e11e3aSSheldon Hearn.Dq Li && 7696b15476eSSheldon Hearnand 77049e11e3aSSheldon Hearn.Dq Li || 7714b88c807SRodney W. Grimesboth have the same priority. 77249e11e3aSSheldon Hearn.Ss Flow-Control Constructs (if, while, for, case) 77349e11e3aSSheldon HearnThe syntax of the 77449e11e3aSSheldon Hearn.Ic if 77549e11e3aSSheldon Hearncommand is: 77649e11e3aSSheldon Hearn.\" 77749e11e3aSSheldon Hearn.\" XXX Use .Dl to work around broken handling of .Ic inside .Bd and .Ed . 77849e11e3aSSheldon Hearn.\" 77949e11e3aSSheldon Hearn.Dl Ic if Ar list 78049e11e3aSSheldon Hearn.Dl Ic then Ar list 78149e11e3aSSheldon Hearn.Dl [ Ic elif Ar list 78249e11e3aSSheldon Hearn.Dl Ic then Ar list ] ... 78349e11e3aSSheldon Hearn.Dl [ Ic else Ar list ] 78449e11e3aSSheldon Hearn.Dl Ic fi 785ab72124fSSteve Price.Pp 78649e11e3aSSheldon HearnThe syntax of the 78749e11e3aSSheldon Hearn.Ic while 78849e11e3aSSheldon Hearncommand is: 78949e11e3aSSheldon Hearn.Dl Ic while Ar list 79049e11e3aSSheldon Hearn.Dl Ic do Ar list 79149e11e3aSSheldon Hearn.Dl Ic done 792ab72124fSSteve Price.Pp 793ab0a2172SSteve PriceThe two lists are executed repeatedly while the exit status of the 79449e11e3aSSheldon Hearnfirst list is zero. 79549e11e3aSSheldon HearnThe 79649e11e3aSSheldon Hearn.Ic until 79749e11e3aSSheldon Hearncommand is similar, but has the word 79849e11e3aSSheldon Hearn.Ic until 79949e11e3aSSheldon Hearnin place of 80049e11e3aSSheldon Hearn.Ic while , 80149e11e3aSSheldon Hearnwhich causes it to 8024b88c807SRodney W. Grimesrepeat until the exit status of the first list is zero. 803ab72124fSSteve Price.Pp 80449e11e3aSSheldon HearnThe syntax of the 80549e11e3aSSheldon Hearn.Ic for 80649e11e3aSSheldon Hearncommand is: 807a01459dfSStefan Farfeleder.Dl Ic for Ar variable Op Ic in Ar word ... 80849e11e3aSSheldon Hearn.Dl Ic do Ar list 80949e11e3aSSheldon Hearn.Dl Ic done 810ab72124fSSteve Price.Pp 811a01459dfSStefan FarfelederIf 812a01459dfSStefan Farfeleder.Ic in 8137b14d37fSRalf S. Engelschalland the following words are omitted, 814a01459dfSStefan Farfeleder.Ic in Li $@ 815a01459dfSStefan Farfelederis used instead. 8164b88c807SRodney W. GrimesThe words are expanded, and then the list is executed 81749e11e3aSSheldon Hearnrepeatedly with the variable set to each word in turn. 81849e11e3aSSheldon HearnThe 81949e11e3aSSheldon Hearn.Ic do 8206b15476eSSheldon Hearnand 82149e11e3aSSheldon Hearn.Ic done 82249e11e3aSSheldon Hearncommands may be replaced with 82349e11e3aSSheldon Hearn.Dq Li { 82449e11e3aSSheldon Hearnand 82549e11e3aSSheldon Hearn.Dq Li } . 826ab72124fSSteve Price.Pp 82749e11e3aSSheldon HearnThe syntax of the 82849e11e3aSSheldon Hearn.Ic break 82949e11e3aSSheldon Hearnand 83049e11e3aSSheldon Hearn.Ic continue 83149e11e3aSSheldon Hearncommands is: 83249e11e3aSSheldon Hearn.Dl Ic break Op Ar num 83349e11e3aSSheldon Hearn.Dl Ic continue Op Ar num 834ab72124fSSteve Price.Pp 83549e11e3aSSheldon HearnThe 83649e11e3aSSheldon Hearn.Ic break 83749e11e3aSSheldon Hearncommand terminates the 83849e11e3aSSheldon Hearn.Ar num 83949e11e3aSSheldon Hearninnermost 84049e11e3aSSheldon Hearn.Ic for 84149e11e3aSSheldon Hearnor 84249e11e3aSSheldon Hearn.Ic while 84349e11e3aSSheldon Hearnloops. 84449e11e3aSSheldon HearnThe 84549e11e3aSSheldon Hearn.Ic continue 84649e11e3aSSheldon Hearncommand continues with the next iteration of the innermost loop. 8478eed22b1SJens SchweikhardtThese are implemented as built-in commands. 848ab72124fSSteve Price.Pp 84949e11e3aSSheldon HearnThe syntax of the 85049e11e3aSSheldon Hearn.Ic case 85149e11e3aSSheldon Hearncommand is 85249e11e3aSSheldon Hearn.Dl Ic case Ar word Ic in 85349e11e3aSSheldon Hearn.Dl pattern) list ;; 85449e11e3aSSheldon Hearn.Dl ... 85549e11e3aSSheldon Hearn.Dl Ic esac 856ab72124fSSteve Price.Pp 85749e11e3aSSheldon HearnThe pattern can actually be one or more patterns 85849e11e3aSSheldon Hearn(see 85949e11e3aSSheldon Hearn.Sx Shell Patterns 86049e11e3aSSheldon Hearndescribed later), 86149e11e3aSSheldon Hearnseparated by 86267135607SMartin Cracauer.Dq Li \&| 8636b15476eSSheldon Hearncharacters. 864ab72124fSSteve Price.Ss Grouping Commands Together 8654b88c807SRodney W. GrimesCommands may be grouped by writing either 866ab72124fSSteve Price.Bd -literal -offset indent 8674b88c807SRodney W. Grimes(list) 868ab72124fSSteve Price.Ed 869ab72124fSSteve Price.Pp 8704b88c807SRodney W. Grimesor 871ab72124fSSteve Price.Bd -literal -offset indent 8724b88c807SRodney W. Grimes{ list; } 873ab72124fSSteve Price.Ed 874ab72124fSSteve Price.Pp 87549e11e3aSSheldon HearnThe first form executes the commands in a subshell. 8768eed22b1SJens SchweikhardtNote that built-in commands thus executed do not affect the current shell. 87749e11e3aSSheldon HearnThe second form does not fork another shell, 87849e11e3aSSheldon Hearnso it is slightly more efficient. 87949e11e3aSSheldon HearnGrouping commands together this way allows the user to 880ab0a2172SSteve Priceredirect their output as though they were one program: 881ab72124fSSteve Price.Bd -literal -offset indent 882ee7dc416SSteve Price{ echo -n "hello"; echo " world"; } > greeting 883ab72124fSSteve Price.Ed 884ab72124fSSteve Price.Ss Functions 8854b88c807SRodney W. GrimesThe syntax of a function definition is 886ab72124fSSteve Price.Bd -literal -offset indent 8874b88c807SRodney W. Grimesname ( ) command 888ab72124fSSteve Price.Ed 889ab72124fSSteve Price.Pp 8904b88c807SRodney W. GrimesA function definition is an executable statement; when 8914b88c807SRodney W. Grimesexecuted it installs a function named name and returns an 892eccea571SRuslan Ermilovexit status of zero. 893eccea571SRuslan ErmilovThe command is normally a list 8946b15476eSSheldon Hearnenclosed between 89549e11e3aSSheldon Hearn.Dq Li { 8966b15476eSSheldon Hearnand 89749e11e3aSSheldon Hearn.Dq Li } . 898ab72124fSSteve Price.Pp 8994b88c807SRodney W. GrimesVariables may be declared to be local to a function by 90049e11e3aSSheldon Hearnusing the 90149e11e3aSSheldon Hearn.Ic local 90249e11e3aSSheldon Hearncommand. 90349e11e3aSSheldon HearnThis should appear as the first statement of a function, 90449e11e3aSSheldon Hearnand the syntax is: 90549e11e3aSSheldon Hearn.Bd -ragged -offset indent 90649e11e3aSSheldon Hearn.Ic local 90781e9cda2SRuslan Ermilov.Op Ar variable ... 9088af11131SRuslan Ermilov.Op Fl 909ab72124fSSteve Price.Ed 910ab72124fSSteve Price.Pp 91149e11e3aSSheldon HearnThe 91249e11e3aSSheldon Hearn.Ic local 9138eed22b1SJens Schweikhardtcommand is implemented as a built-in command. 914ab72124fSSteve Price.Pp 9154b88c807SRodney W. GrimesWhen a variable is made local, it inherits the initial 9164b88c807SRodney W. Grimesvalue and exported and readonly flags from the variable 9174b88c807SRodney W. Grimeswith the same name in the surrounding scope, if there is 918eccea571SRuslan Ermilovone. 919eccea571SRuslan ErmilovOtherwise, the variable is initially unset. 920eccea571SRuslan ErmilovThe shell 921e918fc8fSSheldon Hearnuses dynamic scoping, so that if the variable 922e918fc8fSSheldon Hearn.Em x 923e918fc8fSSheldon Hearnis made local to function 924e918fc8fSSheldon Hearn.Em f , 925e918fc8fSSheldon Hearnwhich then calls function 926e918fc8fSSheldon Hearn.Em g , 927e918fc8fSSheldon Hearnreferences to the variable 928e918fc8fSSheldon Hearn.Em x 929e918fc8fSSheldon Hearnmade inside 930e918fc8fSSheldon Hearn.Em g 931e918fc8fSSheldon Hearnwill refer to the variable 932e918fc8fSSheldon Hearn.Em x 933e918fc8fSSheldon Hearndeclared inside 934e918fc8fSSheldon Hearn.Em f , 935e918fc8fSSheldon Hearnnot to the global variable named 936e918fc8fSSheldon Hearn.Em x . 937ab72124fSSteve Price.Pp 9386b4bbd8aSCeri DaviesThe only special parameter that can be made local is 93949e11e3aSSheldon Hearn.Dq Li - . 9406b15476eSSheldon HearnMaking 94149e11e3aSSheldon Hearn.Dq Li - 9426b15476eSSheldon Hearnlocal causes any shell options that are 9434b88c807SRodney W. Grimeschanged via the set command inside the function to be 9444b88c807SRodney W. Grimesrestored to their original values when the function 9454b88c807SRodney W. Grimesreturns. 946ab72124fSSteve Price.Pp 94749e11e3aSSheldon HearnThe syntax of the 94849e11e3aSSheldon Hearn.Ic return 94949e11e3aSSheldon Hearncommand is 95049e11e3aSSheldon Hearn.Bd -ragged -offset indent 95149e11e3aSSheldon Hearn.Ic return 95249e11e3aSSheldon Hearn.Op Ar exitstatus 953ab72124fSSteve Price.Ed 954ab72124fSSteve Price.Pp 9554ad8968aSBrian FeldmanIt terminates the current executional scope, returning from the previous 9564ad8968aSBrian Feldmannested function, sourced script, or shell instance, in that order. 95749e11e3aSSheldon HearnThe 95849e11e3aSSheldon Hearn.Ic return 9598eed22b1SJens Schweikhardtcommand is implemented as a built-in command. 960ab72124fSSteve Price.Ss Variables and Parameters 961eccea571SRuslan ErmilovThe shell maintains a set of parameters. 962eccea571SRuslan ErmilovA parameter 963eccea571SRuslan Ermilovdenoted by a name is called a variable. 964eccea571SRuslan ErmilovWhen starting up, 9654b88c807SRodney W. Grimesthe shell turns all the environment variables into shell 966eccea571SRuslan Ermilovvariables. 967eccea571SRuslan ErmilovNew variables can be set using the form 968ab72124fSSteve Price.Bd -literal -offset indent 9694b88c807SRodney W. Grimesname=value 970ab72124fSSteve Price.Ed 971ab72124fSSteve Price.Pp 9724b88c807SRodney W. GrimesVariables set by the user must have a name consisting solely 97349e11e3aSSheldon Hearnof alphabetics, numerics, and underscores. 97449e11e3aSSheldon HearnThe first letter of a variable name must not be numeric. 97549e11e3aSSheldon HearnA parameter can also be denoted by a number 9764b88c807SRodney W. Grimesor a special character as explained below. 977ab72124fSSteve Price.Ss Positional Parameters 97849e11e3aSSheldon HearnA positional parameter is a parameter denoted by a number greater than zero. 979ab72124fSSteve PriceThe shell sets these initially to the values of its command line 980eccea571SRuslan Ermilovarguments that follow the name of the shell script. 981eccea571SRuslan ErmilovThe 982c644db6aSSheldon Hearn.Ic set 9838eed22b1SJens Schweikhardtbuilt-in command can also be used to set or reset them. 984ab72124fSSteve Price.Ss Special Parameters 98543d6677bSAlfred PerlsteinA special parameter is a parameter denoted by a special one-character 98643d6677bSAlfred Perlsteinname. 98743d6677bSAlfred PerlsteinThe special parameters recognized by the 98843d6677bSAlfred Perlstein.Nm 98943d6677bSAlfred Perlsteinshell of 99043d6677bSAlfred Perlstein.Fx 99143d6677bSAlfred Perlsteinare shown in the following list, exactly as they would appear in input 99243d6677bSAlfred Perlsteintyped by the user or in the source of a shell script. 993ab72124fSSteve Price.Bl -hang 99443d6677bSAlfred Perlstein.It Li $* 995eccea571SRuslan ErmilovExpands to the positional parameters, starting from one. 996eccea571SRuslan ErmilovWhen 9974b88c807SRodney W. Grimesthe expansion occurs within a double-quoted string 9984b88c807SRodney W. Grimesit expands to a single field with the value of each parameter 99949e11e3aSSheldon Hearnseparated by the first character of the 100049e11e3aSSheldon Hearn.Ev IFS 100149e11e3aSSheldon Hearnvariable, 100249e11e3aSSheldon Hearnor by a 100349e11e3aSSheldon Hearn.Aq space 100449e11e3aSSheldon Hearnif 100549e11e3aSSheldon Hearn.Ev IFS 100649e11e3aSSheldon Hearnis unset. 100743d6677bSAlfred Perlstein.It Li $@ 1008eccea571SRuslan ErmilovExpands to the positional parameters, starting from one. 1009eccea571SRuslan ErmilovWhen 10104b88c807SRodney W. Grimesthe expansion occurs within double-quotes, each positional 10114b88c807SRodney W. Grimesparameter expands as a separate argument. 10124b88c807SRodney W. GrimesIf there are no positional parameters, the 1013e918fc8fSSheldon Hearnexpansion of 1014e918fc8fSSheldon Hearn.Li @ 1015e918fc8fSSheldon Hearngenerates zero arguments, even when 1016e918fc8fSSheldon Hearn.Li @ 1017eccea571SRuslan Ermilovis double-quoted. 1018eccea571SRuslan ErmilovWhat this basically means, for example, is 10196b15476eSSheldon Hearnif $1 is 10206b15476eSSheldon Hearn.Dq abc 10216b15476eSSheldon Hearnand $2 is 10226b15476eSSheldon Hearn.Dq def ghi , 10236b15476eSSheldon Hearnthen 1024e918fc8fSSheldon Hearn.Qq Li $@ 10256b15476eSSheldon Hearnexpands to 10264b88c807SRodney W. Grimesthe two arguments: 1027ab72124fSSteve Price.Bd -literal -offset indent 10284b88c807SRodney W. Grimes"abc" "def ghi" 1029ab72124fSSteve Price.Ed 103043d6677bSAlfred Perlstein.It Li $# 10314b88c807SRodney W. GrimesExpands to the number of positional parameters. 103243d6677bSAlfred Perlstein.It Li $\&? 10334b88c807SRodney W. GrimesExpands to the exit status of the most recent pipeline. 103443d6677bSAlfred Perlstein.It Li $- 1035ab72124fSSteve Price(hyphen) Expands to the current option flags (the single-letter 10364b88c807SRodney W. Grimesoption names concatenated into a string) as specified on 10378eed22b1SJens Schweikhardtinvocation, by the set built-in command, or implicitly 10384b88c807SRodney W. Grimesby the shell. 103943d6677bSAlfred Perlstein.It Li $$ 1040eccea571SRuslan ErmilovExpands to the process ID of the invoked shell. 1041eccea571SRuslan ErmilovA subshell 10424b88c807SRodney W. Grimesretains the same value of $ as its parent. 104343d6677bSAlfred Perlstein.It Li $\&! 10444b88c807SRodney W. GrimesExpands to the process ID of the most recent background 1045eccea571SRuslan Ermilovcommand executed from the current shell. 1046eccea571SRuslan ErmilovFor a 10474b88c807SRodney W. Grimespipeline, the process ID is that of the last command in the 10484b88c807SRodney W. Grimespipeline. 104943d6677bSAlfred Perlstein.It Li $0 1050ab72124fSSteve Price(zero) Expands to the name of the shell or shell script. 1051ab72124fSSteve Price.El 1052ab72124fSSteve Price.Ss Word Expansions 10534b88c807SRodney W. GrimesThis clause describes the various expansions that are 1054eccea571SRuslan Ermilovperformed on words. 1055eccea571SRuslan ErmilovNot all expansions are performed on 10564b88c807SRodney W. Grimesevery word, as explained later. 1057ab72124fSSteve Price.Pp 10584b88c807SRodney W. GrimesTilde expansions, parameter expansions, command substitutions, 10594b88c807SRodney W. Grimesarithmetic expansions, and quote removals that occur within 1060eccea571SRuslan Ermilova single word expand to a single field. 1061eccea571SRuslan ErmilovIt is only field 10624b88c807SRodney W. Grimessplitting or pathname expansion that can create multiple 1063e6d3cf26SSheldon Hearnfields from a single word. 1064e6d3cf26SSheldon HearnThe single exception to this rule is 1065e918fc8fSSheldon Hearnthe expansion of the special parameter 1066e918fc8fSSheldon Hearn.Li @ 1067e918fc8fSSheldon Hearnwithin double-quotes, 1068e6d3cf26SSheldon Hearnas was described above. 1069ab72124fSSteve Price.Pp 10704b88c807SRodney W. GrimesThe order of word expansion is: 1071ab72124fSSteve Price.Bl -enum 1072ab72124fSSteve Price.It 1073ab72124fSSteve PriceTilde Expansion, Parameter Expansion, Command Substitution, 10744b88c807SRodney W. GrimesArithmetic Expansion (these all occur at the same time). 1075ab72124fSSteve Price.It 107649e11e3aSSheldon HearnField Splitting is performed on fields generated by step (1) 107749e11e3aSSheldon Hearnunless the 107849e11e3aSSheldon Hearn.Ev IFS 107949e11e3aSSheldon Hearnvariable is null. 1080ab72124fSSteve Price.It 108149e11e3aSSheldon HearnPathname Expansion (unless the 108249e11e3aSSheldon Hearn.Fl f 108349e11e3aSSheldon Hearnoption is in effect). 1084ab72124fSSteve Price.It 1085ab72124fSSteve PriceQuote Removal. 1086ab72124fSSteve Price.El 1087ab72124fSSteve Price.Pp 108849e11e3aSSheldon HearnThe 108949e11e3aSSheldon Hearn.Dq Li $ 109049e11e3aSSheldon Hearncharacter is used to introduce parameter expansion, command 10914b88c807SRodney W. Grimessubstitution, or arithmetic evaluation. 1092ab72124fSSteve Price.Ss Tilde Expansion (substituting a user's home directory) 109349e11e3aSSheldon HearnA word beginning with an unquoted tilde character 1094a762afe5SGiorgos Keramidas.Pq Ql ~ 109549e11e3aSSheldon Hearnis 109649e11e3aSSheldon Hearnsubjected to tilde expansion. 109749e11e3aSSheldon HearnAll the characters up to a slash 1098a762afe5SGiorgos Keramidas.Pq Ql / 109949e11e3aSSheldon Hearnor the end of the word are treated as a username 1100eccea571SRuslan Ermilovand are replaced with the user's home directory. 1101eccea571SRuslan ErmilovIf the 11024b88c807SRodney W. Grimesusername is missing (as in ~/foobar), the tilde is replaced 11034b88c807SRodney W. Grimeswith the value of the HOME variable (the current user's 11044b88c807SRodney W. Grimeshome directory). 1105ab72124fSSteve Price.Ss Parameter Expansion 11064b88c807SRodney W. GrimesThe format for parameter expansion is as follows: 1107ab72124fSSteve Price.Bd -literal -offset indent 11084b88c807SRodney W. Grimes${expression} 1109ab72124fSSteve Price.Ed 1110ab72124fSSteve Price.Pp 111149e11e3aSSheldon Hearnwhere expression consists of all characters until the matching 111249e11e3aSSheldon Hearn.Dq Li } . 111349e11e3aSSheldon HearnAny 111449e11e3aSSheldon Hearn.Dq Li } 11154b88c807SRodney W. Grimesescaped by a backslash or within a quoted string, and characters in 11164b88c807SRodney W. Grimesembedded arithmetic expansions, command substitutions, and variable 111749e11e3aSSheldon Hearnexpansions, are not examined in determining the matching 111849e11e3aSSheldon Hearn.Dq Li } . 1119ab72124fSSteve Price.Pp 11204b88c807SRodney W. GrimesThe simplest form for parameter expansion is: 1121ab72124fSSteve Price.Bd -literal -offset indent 11224b88c807SRodney W. Grimes${parameter} 1123ab72124fSSteve Price.Ed 1124ab72124fSSteve Price.Pp 11254b88c807SRodney W. GrimesThe value, if any, of parameter is substituted. 1126ab72124fSSteve Price.Pp 11274b88c807SRodney W. GrimesThe parameter name or symbol can be enclosed in braces, which are 11284b88c807SRodney W. Grimesoptional except for positional parameters with more than one digit or 11294b88c807SRodney W. Grimeswhen parameter is followed by a character that could be interpreted as 11304b88c807SRodney W. Grimespart of the name. 1131ab72124fSSteve PriceIf a parameter expansion occurs inside double-quotes: 1132ab72124fSSteve Price.Bl -enum 1133ab72124fSSteve Price.It 1134ab72124fSSteve PricePathname expansion is not performed on the results of the 11354b88c807SRodney W. Grimesexpansion. 1136ab72124fSSteve Price.It 1137ab72124fSSteve PriceField splitting is not performed on the results of the 1138e918fc8fSSheldon Hearnexpansion, with the exception of the special parameter 1139e918fc8fSSheldon Hearn.Li @ . 1140ab72124fSSteve Price.El 1141ab72124fSSteve Price.Pp 11424b88c807SRodney W. GrimesIn addition, a parameter expansion can be modified by using one of the 11434b88c807SRodney W. Grimesfollowing formats. 114481e9cda2SRuslan Ermilov.Bl -tag -width indent 1145ab72124fSSteve Price.It Li ${parameter:-word} 1146eccea571SRuslan ErmilovUse Default Values. 1147eccea571SRuslan ErmilovIf parameter is unset or 11484b88c807SRodney W. Grimesnull, the expansion of word is 11494b88c807SRodney W. Grimessubstituted; otherwise, the value of 11504b88c807SRodney W. Grimesparameter is substituted. 1151ab72124fSSteve Price.It Li ${parameter:=word} 1152eccea571SRuslan ErmilovAssign Default Values. 1153eccea571SRuslan ErmilovIf parameter is unset 11544b88c807SRodney W. Grimesor null, the expansion of word is 1155eccea571SRuslan Ermilovassigned to parameter. 1156eccea571SRuslan ErmilovIn all cases, the 11574b88c807SRodney W. Grimesfinal value of parameter is 1158eccea571SRuslan Ermilovsubstituted. 1159eccea571SRuslan ErmilovOnly variables, not positional 11604b88c807SRodney W. Grimesparameters or special parameters, can be 11614b88c807SRodney W. Grimesassigned in this way. 1162ab72124fSSteve Price.It Li ${parameter:?[word]} 1163eccea571SRuslan ErmilovIndicate Error if Null or Unset. 1164eccea571SRuslan ErmilovIf 11654b88c807SRodney W. Grimesparameter is unset or null, the expansion of 11664b88c807SRodney W. Grimesword (or a message indicating it is unset if 11674b88c807SRodney W. Grimesword is omitted) is written to standard 11684b88c807SRodney W. Grimeserror and the shell exits with a nonzero 1169e6d3cf26SSheldon Hearnexit status. 1170e6d3cf26SSheldon HearnOtherwise, the value of 1171eccea571SRuslan Ermilovparameter is substituted. 1172eccea571SRuslan ErmilovAn 11734b88c807SRodney W. Grimesinteractive shell need not exit. 1174ab72124fSSteve Price.It Li ${parameter:+word} 1175eccea571SRuslan ErmilovUse Alternate Value. 1176eccea571SRuslan ErmilovIf parameter is unset 11774b88c807SRodney W. Grimesor null, null is substituted; 11784b88c807SRodney W. Grimesotherwise, the expansion of word is 11794b88c807SRodney W. Grimessubstituted. 11801413f7deSTony Finch.El 1181ab72124fSSteve Price.Pp 11824b88c807SRodney W. GrimesIn the parameter expansions shown previously, use of the colon in the 11834b88c807SRodney W. Grimesformat results in a test for a parameter that is unset or null; omission 11844b88c807SRodney W. Grimesof the colon results in a test for a parameter that is only unset. 11851413f7deSTony Finch.Bl -tag -width indent 1186ab72124fSSteve Price.It Li ${#parameter} 1187eccea571SRuslan ErmilovString Length. 1188eccea571SRuslan ErmilovThe length in characters of 11894b88c807SRodney W. Grimesthe value of parameter. 119071337c33SSheldon Hearn.El 1191ab72124fSSteve Price.Pp 11924b88c807SRodney W. GrimesThe following four varieties of parameter expansion provide for substring 119349e11e3aSSheldon Hearnprocessing. 119449e11e3aSSheldon HearnIn each case, pattern matching notation 119549e11e3aSSheldon Hearn(see 119649e11e3aSSheldon Hearn.Sx Shell Patterns ) , 119749e11e3aSSheldon Hearnrather than regular expression notation, 119849e11e3aSSheldon Hearnis used to evaluate the patterns. 1199e918fc8fSSheldon HearnIf parameter is one of the special parameters 1200e918fc8fSSheldon Hearn.Li * 120149e11e3aSSheldon Hearnor 1202e918fc8fSSheldon Hearn.Li @ , 120349e11e3aSSheldon Hearnthe result of the expansion is unspecified. 12044b88c807SRodney W. GrimesEnclosing the full parameter expansion string in double-quotes does not 12054b88c807SRodney W. Grimescause the following four varieties of pattern characters to be quoted, 12064b88c807SRodney W. Grimeswhereas quoting characters within the braces has this effect. 120781e9cda2SRuslan Ermilov.Bl -tag -width indent 1208ab72124fSSteve Price.It Li ${parameter%word} 1209eccea571SRuslan ErmilovRemove Smallest Suffix Pattern. 1210eccea571SRuslan ErmilovThe word 1211eccea571SRuslan Ermilovis expanded to produce a pattern. 1212eccea571SRuslan ErmilovThe 12134b88c807SRodney W. Grimesparameter expansion then results in 12144b88c807SRodney W. Grimesparameter, with the smallest portion of the 12154b88c807SRodney W. Grimessuffix matched by the pattern deleted. 1216ab72124fSSteve Price.It Li ${parameter%%word} 1217eccea571SRuslan ErmilovRemove Largest Suffix Pattern. 1218eccea571SRuslan ErmilovThe word 1219eccea571SRuslan Ermilovis expanded to produce a pattern. 1220eccea571SRuslan ErmilovThe 12214b88c807SRodney W. Grimesparameter expansion then results in 12224b88c807SRodney W. Grimesparameter, with the largest portion of the 12234b88c807SRodney W. Grimessuffix matched by the pattern deleted. 1224ab72124fSSteve Price.It Li ${parameter#word} 1225eccea571SRuslan ErmilovRemove Smallest Prefix Pattern. 1226eccea571SRuslan ErmilovThe word 1227eccea571SRuslan Ermilovis expanded to produce a pattern. 1228eccea571SRuslan ErmilovThe 12294b88c807SRodney W. Grimesparameter expansion then results in 12304b88c807SRodney W. Grimesparameter, with the smallest portion of the 12314b88c807SRodney W. Grimesprefix matched by the pattern deleted. 1232ab72124fSSteve Price.It Li ${parameter##word} 1233eccea571SRuslan ErmilovRemove Largest Prefix Pattern. 1234eccea571SRuslan ErmilovThe word 1235eccea571SRuslan Ermilovis expanded to produce a pattern. 1236eccea571SRuslan ErmilovThe 12374b88c807SRodney W. Grimesparameter expansion then results in 12384b88c807SRodney W. Grimesparameter, with the largest portion of the 12394b88c807SRodney W. Grimesprefix matched by the pattern deleted. 1240ab72124fSSteve Price.El 1241ab72124fSSteve Price.Ss Command Substitution 12424b88c807SRodney W. GrimesCommand substitution allows the output of a command to be substituted in 1243eccea571SRuslan Ermilovplace of the command name itself. 1244eccea571SRuslan ErmilovCommand substitution occurs when 12454b88c807SRodney W. Grimesthe command is enclosed as follows: 1246ab72124fSSteve Price.Bd -literal -offset indent 12474b88c807SRodney W. Grimes$(command) 1248ab72124fSSteve Price.Ed 1249ab72124fSSteve Price.Pp 125049e11e3aSSheldon Hearnor the backquoted version: 1251ab72124fSSteve Price.Bd -literal -offset indent 12524b88c807SRodney W. Grimes`command` 1253ab72124fSSteve Price.Ed 1254ab72124fSSteve Price.Pp 12554b88c807SRodney W. GrimesThe shell expands the command substitution by executing command in a 12564b88c807SRodney W. Grimessubshell environment and replacing the command substitution 125749e11e3aSSheldon Hearnwith the standard output of the command, 125849e11e3aSSheldon Hearnremoving sequences of one or more newlines at the end of the substitution. 125949e11e3aSSheldon HearnEmbedded newlines before the end of the output are not removed; 126049e11e3aSSheldon Hearnhowever, during field splitting, they may be translated into spaces 126149e11e3aSSheldon Hearndepending on the value of 126249e11e3aSSheldon Hearn.Ev IFS 126349e11e3aSSheldon Hearnand the quoting that is in effect. 1264ab72124fSSteve Price.Ss Arithmetic Expansion 12654b88c807SRodney W. GrimesArithmetic expansion provides a mechanism for evaluating an arithmetic 1266e6d3cf26SSheldon Hearnexpression and substituting its value. 1267e6d3cf26SSheldon HearnThe format for arithmetic expansion is as follows: 1268ab72124fSSteve Price.Bd -literal -offset indent 12694b88c807SRodney W. Grimes$((expression)) 1270ab72124fSSteve Price.Ed 1271ab72124fSSteve Price.Pp 12724b88c807SRodney W. GrimesThe expression is treated as if it were in double-quotes, except 1273eccea571SRuslan Ermilovthat a double-quote inside the expression is not treated specially. 1274eccea571SRuslan ErmilovThe 12754b88c807SRodney W. Grimesshell expands all tokens in the expression for parameter expansion, 12764b88c807SRodney W. Grimescommand substitution, and quote removal. 1277ab72124fSSteve Price.Pp 12784b88c807SRodney W. GrimesNext, the shell treats this as an arithmetic expression and 12794b88c807SRodney W. Grimessubstitutes the value of the expression. 1280ab72124fSSteve Price.Ss White Space Splitting (Field Splitting) 12814b88c807SRodney W. GrimesAfter parameter expansion, command substitution, and 12824b88c807SRodney W. Grimesarithmetic expansion the shell scans the results of 12834b88c807SRodney W. Grimesexpansions and substitutions that did not occur in double-quotes for 12844b88c807SRodney W. Grimesfield splitting and multiple fields can result. 1285ab72124fSSteve Price.Pp 128649e11e3aSSheldon HearnThe shell treats each character of the 128749e11e3aSSheldon Hearn.Ev IFS 128849e11e3aSSheldon Hearnas a delimiter and uses 12894b88c807SRodney W. Grimesthe delimiters to split the results of parameter expansion and command 12904b88c807SRodney W. Grimessubstitution into fields. 1291ab72124fSSteve Price.Ss Pathname Expansion (File Name Generation) 129249e11e3aSSheldon HearnUnless the 129349e11e3aSSheldon Hearn.Fl f 129449e11e3aSSheldon Hearnoption is set, 129549e11e3aSSheldon Hearnfile name generation is performed 1296eccea571SRuslan Ermilovafter word splitting is complete. 1297eccea571SRuslan ErmilovEach word is 1298eccea571SRuslan Ermilovviewed as a series of patterns, separated by slashes. 1299eccea571SRuslan ErmilovThe 13004b88c807SRodney W. Grimesprocess of expansion replaces the word with the names of 13014b88c807SRodney W. Grimesall existing files whose names can be formed by replacing 13024b88c807SRodney W. Grimeseach pattern with a string that matches the specified pattern. 1303ab0a2172SSteve PriceThere are two restrictions on this: first, a pattern cannot match 1304ab0a2172SSteve Pricea string containing a slash, and second, 13054b88c807SRodney W. Grimesa pattern cannot match a string starting with a period 13064b88c807SRodney W. Grimesunless the first character of the pattern is a period. 13074b88c807SRodney W. GrimesThe next section describes the patterns used for both 1308ab72124fSSteve PricePathname Expansion and the 1309c644db6aSSheldon Hearn.Ic case 1310ab72124fSSteve Pricecommand. 1311ab72124fSSteve Price.Ss Shell Patterns 1312f434d1dfSAdam DavidA pattern consists of normal characters, which match themselves, 131349e11e3aSSheldon Hearnand meta-characters. 131449e11e3aSSheldon HearnThe meta-characters are 13151586940eSRuslan Ermilov.Dq Li \&! , 131649e11e3aSSheldon Hearn.Dq Li * , 13171586940eSRuslan Ermilov.Dq Li \&? , 13186b15476eSSheldon Hearnand 131949e11e3aSSheldon Hearn.Dq Li [ . 13206b15476eSSheldon HearnThese characters lose their special meanings if they are quoted. 13216b15476eSSheldon HearnWhen command or variable substitution is performed and the dollar sign 13226b15476eSSheldon Hearnor back quotes are not double-quoted, the value of the 13234b88c807SRodney W. Grimesvariable or the output of the command is scanned for these 13244b88c807SRodney W. Grimescharacters and they are turned into meta-characters. 1325ab72124fSSteve Price.Pp 13266b15476eSSheldon HearnAn asterisk 1327a762afe5SGiorgos Keramidas.Pq Ql * 1328e918fc8fSSheldon Hearnmatches any string of characters. 1329e918fc8fSSheldon HearnA question mark 1330a762afe5SGiorgos Keramidas.Pq Ql \&? 1331e918fc8fSSheldon Hearnmatches any single character. 1332e6d3cf26SSheldon HearnA left bracket 1333a762afe5SGiorgos Keramidas.Pq Ql [ 1334e6d3cf26SSheldon Hearnintroduces a character class. 1335e6d3cf26SSheldon HearnThe end of the character class is indicated by a 133649e11e3aSSheldon Hearn.Dq Li \&] ; 13376b15476eSSheldon Hearnif the 133849e11e3aSSheldon Hearn.Dq Li \&] 13396b15476eSSheldon Hearnis missing then the 134049e11e3aSSheldon Hearn.Dq Li [ 13416b15476eSSheldon Hearnmatches a 134249e11e3aSSheldon Hearn.Dq Li [ 1343e6d3cf26SSheldon Hearnrather than introducing a character class. 1344e6d3cf26SSheldon HearnA character class matches any of the characters between the square brackets. 1345e6d3cf26SSheldon HearnA range of characters may be specified using a minus sign. 1346e918fc8fSSheldon HearnThe character class may be complemented by making an exclamation point 1347a762afe5SGiorgos Keramidas.Pq Ql !\& 1348e918fc8fSSheldon Hearnthe first character of the character class. 1349ab72124fSSteve Price.Pp 13506b15476eSSheldon HearnTo include a 135112e720d7SRuslan Ermilov.Dq Li \&] 1352e6d3cf26SSheldon Hearnin a character class, make it the first character listed 1353e6d3cf26SSheldon Hearn(after the 13541586940eSRuslan Ermilov.Dq Li \&! , 1355e6d3cf26SSheldon Hearnif any). 1356e918fc8fSSheldon HearnTo include a 1357e918fc8fSSheldon Hearn.Dq Li - , 1358e918fc8fSSheldon Hearnmake it the first or last character listed. 13598eed22b1SJens Schweikhardt.Ss Built-in Commands 1360c644db6aSSheldon HearnThis section lists the commands which 13618eed22b1SJens Schweikhardtare built-in because they need to perform some operation 1362eccea571SRuslan Ermilovthat cannot be performed by a separate process. 1363eccea571SRuslan ErmilovIn addition to 136410845922SYaroslav Tykhiythese, built-in versions of essential utilities 136510845922SYaroslav Tykhiyare provided for efficiency. 136681e9cda2SRuslan Ermilov.Bl -tag -width indent 1367d0353b83SRuslan Ermilov.It Ic \&: 1368aa9caaf6SPeter WemmA null command that returns a 0 (true) exit value. 1369d0353b83SRuslan Ermilov.It Ic \&. Ar file 1370aa9caaf6SPeter WemmThe commands in the specified file are read and executed by the shell. 13714ad8968aSBrian FeldmanThe 13724ad8968aSBrian Feldman.Ic return 13734ad8968aSBrian Feldmancommand may be used to return to the 13744ad8968aSBrian Feldman.Ic \&. 13754ad8968aSBrian Feldmancommand's caller. 13766466945aSJohn PolstraIf 13776466945aSJohn Polstra.Ar file 13786466945aSJohn Polstracontains any 137949e11e3aSSheldon Hearn.Dq / 1380eccea571SRuslan Ermilovcharacters, it is used as is. 1381eccea571SRuslan ErmilovOtherwise, the shell searches the 13826466945aSJohn Polstra.Ev PATH 1383eccea571SRuslan Ermilovfor the file. 1384eccea571SRuslan ErmilovIf it is not found in the 13856466945aSJohn Polstra.Ev PATH , 13866466945aSJohn Polstrait is sought in the current working directory. 138710845922SYaroslav Tykhiy.It Ic \&[ 138810845922SYaroslav TykhiyA built-in equivalent of 138910845922SYaroslav Tykhiy.Xr test 1 . 1390a886288eSJesus R. Camou.It Ic alias Oo Ar name Ns Oo = Ns Ar string Oc ... Oc 139149e11e3aSSheldon HearnIf 1392d0353b83SRuslan Ermilov.Ar name Ns = Ns Ar string 139349e11e3aSSheldon Hearnis specified, the shell defines the alias 139449e11e3aSSheldon Hearn.Ar name 13956b15476eSSheldon Hearnwith value 139649e11e3aSSheldon Hearn.Ar string . 13976b15476eSSheldon HearnIf just 139849e11e3aSSheldon Hearn.Ar name 13996b15476eSSheldon Hearnis specified, the value of the alias 140049e11e3aSSheldon Hearn.Ar name 14016b15476eSSheldon Hearnis printed. 140249e11e3aSSheldon HearnWith no arguments, the 140349e11e3aSSheldon Hearn.Ic alias 14048eed22b1SJens Schweikhardtbuilt-in command prints the names and values of all defined aliases 140549e11e3aSSheldon Hearn(see 140649e11e3aSSheldon Hearn.Ic unalias ) . 1407e5341cbbSTim J. RobbinsAlias values are written with appropriate quoting so that they are 14089ba31ca0SRuslan Ermilovsuitable for re-input to the shell. 1409a886288eSJesus R. CamouAlso see the 1410a886288eSJesus R. Camou.Sx Aliases 1411a886288eSJesus R. Camousubsection. 141249e11e3aSSheldon Hearn.It Ic bg Op Ar job ... 141349e11e3aSSheldon HearnContinue the specified jobs 141449e11e3aSSheldon Hearn(or the current job if no jobs are given) 141549e11e3aSSheldon Hearnin the background. 1416df9e587bSTim J. Robbins.It Ic builtin Ar cmd Op Ar arg ... 14178eed22b1SJens SchweikhardtExecute the specified built-in command, 141849e11e3aSSheldon Hearn.Ar cmd . 141949e11e3aSSheldon HearnThis is useful when the user wishes to override a shell function 14208eed22b1SJens Schweikhardtwith the same name as a built-in command. 1421088acf90STim J. Robbins.It Ic bind Oo Fl aeklrsv Oc Oo Ar key Oo Ar command Oc Oc 1422088acf90STim J. RobbinsList or alter key bindings for the line editor. 1423088acf90STim J. RobbinsThis command is documented in 1424088acf90STim J. Robbins.Xr editrc 5 . 1425d74e011fSRuslan Ermilov.It Ic cd Oo Fl L | P Oc Op Ar directory 142649e11e3aSSheldon HearnSwitch to the specified 142749e11e3aSSheldon Hearn.Ar directory , 142849e11e3aSSheldon Hearnor to the directory specified in the 142949e11e3aSSheldon Hearn.Ev HOME 143049e11e3aSSheldon Hearnenvironment variable if no 143149e11e3aSSheldon Hearn.Ar directory 143249e11e3aSSheldon Hearnis specified. 143349e11e3aSSheldon HearnIf 143449e11e3aSSheldon Hearn.Ar directory 1435029c8ee4STim J. Robbinsdoes not begin with 14369ba31ca0SRuslan Ermilov.Pa / , \&. , 143749e11e3aSSheldon Hearnor 1438029c8ee4STim J. Robbins.Pa .. , 143949e11e3aSSheldon Hearnthen the directories listed in the 144049e11e3aSSheldon Hearn.Ev CDPATH 144149e11e3aSSheldon Hearnvariable will be 144249e11e3aSSheldon Hearnsearched for the specified 144349e11e3aSSheldon Hearn.Ar directory . 1444029c8ee4STim J. RobbinsIf 1445029c8ee4STim J. Robbins.Ev CDPATH 1446029c8ee4STim J. Robbinsis unset, the current directory is searched. 144749e11e3aSSheldon HearnThe format of 144849e11e3aSSheldon Hearn.Ar CDPATH 144949e11e3aSSheldon Hearnis the same as that of 145049e11e3aSSheldon Hearn.Ev PATH . 1451e6d3cf26SSheldon HearnIn an interactive shell, 145249e11e3aSSheldon Hearnthe 145349e11e3aSSheldon Hearn.Ic cd 145449e11e3aSSheldon Hearncommand will print out the name of the directory 1455e6d3cf26SSheldon Hearnthat it actually switched to 1456e6d3cf26SSheldon Hearnif this is different from the name that the user gave. 145749e11e3aSSheldon HearnThese may be different either because the 145849e11e3aSSheldon Hearn.Ev CDPATH 145949e11e3aSSheldon Hearnmechanism was used or because a symbolic link was crossed. 1460178897f1STim J. Robbins.Pp 1461178897f1STim J. RobbinsIf the 1462178897f1STim J. Robbins.Fl P 1463178897f1STim J. Robbinsoption is specified, 146481e9cda2SRuslan Ermilov.Pa .. 1465178897f1STim J. Robbinsis handled physically and symbolic links are resolved before 146681e9cda2SRuslan Ermilov.Pa .. 1467178897f1STim J. Robbinscomponents are processed. 1468178897f1STim J. RobbinsIf the 1469178897f1STim J. Robbins.Fl L 1470178897f1STim J. Robbinsoption is specified, 147181e9cda2SRuslan Ermilov.Pa .. 1472178897f1STim J. Robbinsis handled logically. 1473178897f1STim J. RobbinsThis is the default. 14749434a1c7SDima Dorfman.It Ic chdir 14759434a1c7SDima DorfmanA synonym for the 14769434a1c7SDima Dorfman.Ic cd 14778eed22b1SJens Schweikhardtbuilt-in command. 14789ba31ca0SRuslan Ermilov.It Ic command Oo Fl p Oc Op Ar utility Op Ar argument ... 147933b222b9SStefan Farfeleder.It Ic command Oo Fl v | V Oc Op Ar utility 148033b222b9SStefan FarfelederThe first form of invocation executes the specified 14812babaf74STim J. Robbins.Ar utility 14822babaf74STim J. Robbinsas a simple command (see the 14832babaf74STim J. Robbins.Sx Simple Commands 14842babaf74STim J. Robbinssection). 14852babaf74STim J. Robbins.Pp 14862babaf74STim J. RobbinsIf the 14872babaf74STim J. Robbins.Fl p 14882babaf74STim J. Robbinsoption is specified, the command search is performed using a 14892babaf74STim J. Robbinsdefault value of 14902babaf74STim J. Robbins.Ev PATH 14912babaf74STim J. Robbinsthat is guaranteed to find all of the standard utilities. 149233b222b9SStefan Farfeleder.Pp 149333b222b9SStefan FarfelederIf the 149433b222b9SStefan Farfeleder.Fl v 149533b222b9SStefan Farfelederoption is specified, 149633b222b9SStefan Farfeleder.Ar utility 149733b222b9SStefan Farfelederis not executed but a description of its interpretation by the shell is 149833b222b9SStefan Farfelederprinted. 149933b222b9SStefan FarfelederFor ordinary commands the output is the path name; for shell built-in 150033b222b9SStefan Farfeledercommands, shell functions and keywords only the name is written. 150133b222b9SStefan FarfelederAliases are printed as 150233b222b9SStefan Farfeleder.Dq Ic alias Ar name Ns = Ns Ar value . 150333b222b9SStefan Farfeleder.Pp 150433b222b9SStefan FarfelederThe 150533b222b9SStefan Farfeleder.Fl V 150633b222b9SStefan Farfelederoption is identical to 150733b222b9SStefan Farfeleder.Fl v 150833b222b9SStefan Farfelederexcept for the output. 150933b222b9SStefan FarfelederIt prints 151033b222b9SStefan Farfeleder.Dq Ar utility Ic is Ar description 151133b222b9SStefan Farfelederwhere 151233b222b9SStefan Farfeleder.Ar description 151333b222b9SStefan Farfelederis either 151433b222b9SStefan Farfelederthe path name to 151533b222b9SStefan Farfeleder.Ar utility , 15168af11131SRuslan Ermilova shell builtin, 15178af11131SRuslan Ermilova shell function, 15188af11131SRuslan Ermilova shell keyword 151933b222b9SStefan Farfelederor 15208af11131SRuslan Ermilovan alias for 15218af11131SRuslan Ermilov. Ar value . 152273313421SStefan Farfeleder.It Ic echo Oo Fl e | n Oc Op Ar string ... 152373313421SStefan FarfelederPrint a space-separated list of the arguments to the standard output 152473313421SStefan Farfelederand append a newline character. 152581e9cda2SRuslan Ermilov.Bl -tag -width indent 1526501e74b7SMark Ovens.It Fl n 1527501e74b7SMark OvensSuppress the output of the trailing newline. 1528501e74b7SMark Ovens.It Fl e 1529501e74b7SMark OvensProcess C-style backslash escape sequences. 1530501e74b7SMark Ovens.Ic echo 1531501e74b7SMark Ovensunderstands the following character escapes: 153281e9cda2SRuslan Ermilov.Bl -tag -width indent 1533501e74b7SMark Ovens.It \ea 1534501e74b7SMark OvensAlert (ring the terminal bell) 1535501e74b7SMark Ovens.It \eb 1536501e74b7SMark OvensBackspace 1537501e74b7SMark Ovens.It \ec 1538501e74b7SMark OvensSuppress the trailing newline (this has the side-effect of truncating the 1539501e74b7SMark Ovensline if it is not the last character) 1540501e74b7SMark Ovens.It \ee 1541501e74b7SMark OvensThe ESC character (ASCII 0x1b) 1542501e74b7SMark Ovens.It \ef 1543501e74b7SMark OvensFormfeed 1544501e74b7SMark Ovens.It \en 1545501e74b7SMark OvensNewline 1546501e74b7SMark Ovens.It \er 1547501e74b7SMark OvensCarriage return 1548501e74b7SMark Ovens.It \et 1549501e74b7SMark OvensHorizontal tab 1550501e74b7SMark Ovens.It \ev 1551501e74b7SMark OvensVertical tab 1552501e74b7SMark Ovens.It \e\e 1553501e74b7SMark OvensLiteral backslash 1554501e74b7SMark Ovens.It \e0nnn 1555501e74b7SMark Ovens(Zero) The character whose octal value is nnn 1556501e74b7SMark Ovens.El 1557501e74b7SMark Ovens.Pp 1558501e74b7SMark OvensIf 1559501e74b7SMark Ovens.Ar string 1560501e74b7SMark Ovensis not enclosed in quotes then the backslash itself must be escaped 1561eccea571SRuslan Ermilovwith a backslash to protect it from the shell. 1562eccea571SRuslan ErmilovFor example 1563501e74b7SMark Ovens.Bd -literal -offset indent 1564501e74b7SMark Ovens$ echo -e "a\evb" 1565501e74b7SMark Ovensa 1566501e74b7SMark Ovens b 1567501e74b7SMark Ovens$ echo -e a\e\evb 1568501e74b7SMark Ovensa 1569501e74b7SMark Ovens b 1570501e74b7SMark Ovens$ echo -e "a\e\eb" 1571501e74b7SMark Ovensa\eb 1572501e74b7SMark Ovens$ echo -e a\e\e\e\eb 1573501e74b7SMark Ovensa\eb 1574501e74b7SMark Ovens.Ed 1575501e74b7SMark Ovens.El 1576558175caSTim J. Robbins.Pp 1577558175caSTim J. RobbinsOnly one of the 1578558175caSTim J. Robbins.Fl e 1579558175caSTim J. Robbinsand 1580558175caSTim J. Robbins.Fl n 1581558175caSTim J. Robbinsoptions may be specified. 158249e11e3aSSheldon Hearn.It Ic eval Ar string ... 1583e6d3cf26SSheldon HearnConcatenate all the arguments with spaces. 1584e6d3cf26SSheldon HearnThen re-parse and execute the command. 158549e11e3aSSheldon Hearn.It Ic exec Op Ar command Op arg ... 158649e11e3aSSheldon HearnUnless 158749e11e3aSSheldon Hearn.Ar command 158849e11e3aSSheldon Hearnis omitted, 158949e11e3aSSheldon Hearnthe shell process is replaced with the specified program 15908eed22b1SJens Schweikhardt(which must be a real program, not a shell built-in command or function). 159149e11e3aSSheldon HearnAny redirections on the 159249e11e3aSSheldon Hearn.Ic exec 159349e11e3aSSheldon Hearncommand are marked as permanent, 159449e11e3aSSheldon Hearnso that they are not undone when the 159549e11e3aSSheldon Hearn.Ic exec 159649e11e3aSSheldon Hearncommand finishes. 159749e11e3aSSheldon Hearn.It Ic exit Op Ar exitstatus 159849e11e3aSSheldon HearnTerminate the shell process. 159949e11e3aSSheldon HearnIf 160049e11e3aSSheldon Hearn.Ar exitstatus 160149e11e3aSSheldon Hearnis given 160249e11e3aSSheldon Hearnit is used as the exit status of the shell; 160349e11e3aSSheldon Hearnotherwise the exit status of the preceding command is used. 1604ef9791a3SStefan Farfeleder.It Ic export Ar name ... 1605ef9791a3SStefan Farfeleder.It Ic export Op Fl p 16064b88c807SRodney W. GrimesThe specified names are exported so that they will 16074b88c807SRodney W. Grimesappear in the environment of subsequent commands. 160849e11e3aSSheldon HearnThe only way to un-export a variable is to 160949e11e3aSSheldon Hearn.Ic unset 161049e11e3aSSheldon Hearnit. 161149e11e3aSSheldon HearnThe shell allows the value of a variable to be set 161249e11e3aSSheldon Hearnat the same time as it is exported by writing 1613ab72124fSSteve Price.Bd -literal -offset indent 16144b88c807SRodney W. Grimesexport name=value 1615ab72124fSSteve Price.Ed 1616ab72124fSSteve Price.Pp 16174b88c807SRodney W. GrimesWith no arguments the export command lists the names 16184b88c807SRodney W. Grimesof all exported variables. 161945086f8cSTim J. RobbinsIf the 162045086f8cSTim J. Robbins.Fl p 162145086f8cSTim J. Robbinsoption is specified, the exported variables are printed as 162245086f8cSTim J. Robbins.Dq Ic export Ar name Ns = Ns Ar value 162345086f8cSTim J. Robbinslines, suitable for re-input to the shell. 1624a6557dcbSYaroslav Tykhiy.It Ic false 1625a6557dcbSYaroslav TykhiyA null command that returns a non-zero (false) exit value. 162681e9cda2SRuslan Ermilov.It Ic fc Oo Fl e Ar editor Oc Op Ar first Op Ar last 162781e9cda2SRuslan Ermilov.It Ic fc Fl l Oo Fl nr Oc Op Ar first Op Ar last 162881e9cda2SRuslan Ermilov.It Ic fc Fl s Oo Ar old Ns = Ns Ar new Oc Op Ar first 162949e11e3aSSheldon HearnThe 163049e11e3aSSheldon Hearn.Ic fc 16318eed22b1SJens Schweikhardtbuilt-in command lists, or edits and re-executes, 163249e11e3aSSheldon Hearncommands previously entered to an interactive shell. 163381e9cda2SRuslan Ermilov.Bl -tag -width indent 163449e11e3aSSheldon Hearn.It Fl e Ar editor 163549e11e3aSSheldon HearnUse the editor named by 163649e11e3aSSheldon Hearn.Ar editor 163749e11e3aSSheldon Hearnto edit the commands. 163849e11e3aSSheldon HearnThe editor string is a command name, 163949e11e3aSSheldon Hearnsubject to search via the 164049e11e3aSSheldon Hearn.Ev PATH 164149e11e3aSSheldon Hearnvariable. 164249e11e3aSSheldon HearnThe value in the 164349e11e3aSSheldon Hearn.Ev FCEDIT 164449e11e3aSSheldon Hearnvariable is used as a default when 164549e11e3aSSheldon Hearn.Fl e 164649e11e3aSSheldon Hearnis not specified. 164749e11e3aSSheldon HearnIf 164849e11e3aSSheldon Hearn.Ev FCEDIT 164949e11e3aSSheldon Hearnis null or unset, the value of the 165049e11e3aSSheldon Hearn.Ev EDITOR 165149e11e3aSSheldon Hearnvariable is used. 165249e11e3aSSheldon HearnIf 165349e11e3aSSheldon Hearn.Ev EDITOR 165449e11e3aSSheldon Hearnis null or unset, 1655ab72124fSSteve Price.Xr ed 1 1656ab72124fSSteve Priceis used as the editor. 165749e11e3aSSheldon Hearn.It Fl l No (ell) 16584b88c807SRodney W. GrimesList the commands rather than invoking 1659eccea571SRuslan Ermilovan editor on them. 1660eccea571SRuslan ErmilovThe commands are written in the 16614b88c807SRodney W. Grimessequence indicated by the first and last operands, as 166249e11e3aSSheldon Hearnaffected by 166349e11e3aSSheldon Hearn.Fl r , 166449e11e3aSSheldon Hearnwith each command preceded by the command number. 166549e11e3aSSheldon Hearn.It Fl n 166649e11e3aSSheldon HearnSuppress command numbers when listing with 166749e11e3aSSheldon Hearn.Fl l . 166849e11e3aSSheldon Hearn.It Fl r 166949e11e3aSSheldon HearnReverse the order of the commands listed 167049e11e3aSSheldon Hearn(with 167149e11e3aSSheldon Hearn.Fl l ) 167249e11e3aSSheldon Hearnor edited 167349e11e3aSSheldon Hearn(with neither 167449e11e3aSSheldon Hearn.Fl l 167549e11e3aSSheldon Hearnnor 167649e11e3aSSheldon Hearn.Fl s ) . 167749e11e3aSSheldon Hearn.It Fl s 16784b88c807SRodney W. GrimesRe-execute the command without invoking an editor. 167949e11e3aSSheldon Hearn.It Ar first 168049e11e3aSSheldon Hearn.It Ar last 168149e11e3aSSheldon HearnSelect the commands to list or edit. 168249e11e3aSSheldon HearnThe number of previous commands that can be accessed 168349e11e3aSSheldon Hearnare determined by the value of the 1684d0353b83SRuslan Ermilov.Ev HISTSIZE 1685d0353b83SRuslan Ermilovvariable. 168649e11e3aSSheldon HearnThe value of 168749e11e3aSSheldon Hearn.Ar first 168849e11e3aSSheldon Hearnor 168949e11e3aSSheldon Hearn.Ar last 169049e11e3aSSheldon Hearnor both are one of the following: 169181e9cda2SRuslan Ermilov.Bl -tag -width indent 169249e11e3aSSheldon Hearn.It Ar [+]num 169349e11e3aSSheldon HearnA positive number representing a command number; 169449e11e3aSSheldon Hearncommand numbers can be displayed with the 169549e11e3aSSheldon Hearn.Fl l 169649e11e3aSSheldon Hearnoption. 169749e11e3aSSheldon Hearn.It Ar -num 169849e11e3aSSheldon HearnA negative decimal number representing the 169949e11e3aSSheldon Hearncommand that was executed 170049e11e3aSSheldon Hearn.Ar num 170149e11e3aSSheldon Hearnof 170249e11e3aSSheldon Hearncommands previously. 170349e11e3aSSheldon HearnFor example, -1 is the immediately previous command. 170449e11e3aSSheldon Hearn.It Ar string 170549e11e3aSSheldon HearnA string indicating the most recently entered command 170649e11e3aSSheldon Hearnthat begins with that string. 170749e11e3aSSheldon HearnIf the 170849e11e3aSSheldon Hearn.Ar old=new 170949e11e3aSSheldon Hearnoperand is not also specified with 171049e11e3aSSheldon Hearn.Fl s , 171149e11e3aSSheldon Hearnthe string form of the first operand cannot contain an embedded equal sign. 171249e11e3aSSheldon Hearn.El 171349e11e3aSSheldon Hearn.El 171449e11e3aSSheldon Hearn.Pp 171549e11e3aSSheldon HearnThe following environment variables affect the execution of 171649e11e3aSSheldon Hearn.Ic fc : 171738afdcbcSGiorgos Keramidas.Bl -tag -width ".Ev HISTSIZE" 171849e11e3aSSheldon Hearn.It Ev FCEDIT 171938afdcbcSGiorgos KeramidasName of the editor to use for history editing. 172049e11e3aSSheldon Hearn.It Ev HISTSIZE 17213d7b5b93SPhilippe CharnierThe number of previous commands that are accessible. 1722ab72124fSSteve Price.El 172349e11e3aSSheldon Hearn.It Ic fg Op Ar job 172449e11e3aSSheldon HearnMove the specified 172549e11e3aSSheldon Hearn.Ar job 172649e11e3aSSheldon Hearnor the current job to the foreground. 172749e11e3aSSheldon Hearn.It Ic getopts Ar optstring Ar var 172849e11e3aSSheldon HearnThe POSIX 172949e11e3aSSheldon Hearn.Ic getopts 173049e11e3aSSheldon Hearncommand. 173149e11e3aSSheldon HearnThe 173249e11e3aSSheldon Hearn.Ic getopts 173349e11e3aSSheldon Hearncommand deprecates the older 173449e11e3aSSheldon Hearn.Xr getopt 1 173549e11e3aSSheldon Hearncommand. 1736ab0a2172SSteve PriceThe first argument should be a series of letters, each possibly 1737ab0a2172SSteve Pricefollowed by a colon which indicates that the option takes an argument. 1738eccea571SRuslan ErmilovThe specified variable is set to the parsed option. 1739eccea571SRuslan ErmilovThe index of 174049e11e3aSSheldon Hearnthe next argument is placed into the shell variable 174149e11e3aSSheldon Hearn.Ev OPTIND . 1742ab0a2172SSteve PriceIf an option takes an argument, it is placed into the shell variable 174349e11e3aSSheldon Hearn.Ev OPTARG . 174449e11e3aSSheldon HearnIf an invalid option is encountered, 174549e11e3aSSheldon Hearn.Ev var 174649e11e3aSSheldon Hearnis set to 17471586940eSRuslan Ermilov.Dq Li \&? . 1748ab0a2172SSteve PriceIt returns a false value (1) when it encounters the end of the options. 174981e9cda2SRuslan Ermilov.It Ic hash Oo Fl rv Oc Op Ar command ... 175049e11e3aSSheldon HearnThe shell maintains a hash table which remembers the locations of commands. 175149e11e3aSSheldon HearnWith no arguments whatsoever, the 175249e11e3aSSheldon Hearn.Ic hash 175349e11e3aSSheldon Hearncommand prints out the contents of this table. 175449e11e3aSSheldon HearnEntries which have not been looked at since the last 175549e11e3aSSheldon Hearn.Ic cd 175649e11e3aSSheldon Hearncommand are marked with an asterisk; 175749e11e3aSSheldon Hearnit is possible for these entries to be invalid. 1758ab72124fSSteve Price.Pp 175949e11e3aSSheldon HearnWith arguments, the 176049e11e3aSSheldon Hearn.Ic hash 176149e11e3aSSheldon Hearncommand removes each specified 176249e11e3aSSheldon Hearn.Ar command 176349e11e3aSSheldon Hearnfrom the hash table (unless they are functions) and then locates it. 176449e11e3aSSheldon HearnWith the 176549e11e3aSSheldon Hearn.Fl v 176649e11e3aSSheldon Hearnoption, 176749e11e3aSSheldon Hearn.Ic hash 176849e11e3aSSheldon Hearnprints the locations of the commands as it finds them. 176949e11e3aSSheldon HearnThe 177049e11e3aSSheldon Hearn.Fl r 177149e11e3aSSheldon Hearnoption causes the 177249e11e3aSSheldon Hearn.Ic hash 177349e11e3aSSheldon Hearncommand to delete all the entries in the hash table except for functions. 177449e11e3aSSheldon Hearn.It Ic jobid Op Ar job 177549e11e3aSSheldon HearnPrint the process id's of the processes in the specified 177649e11e3aSSheldon Hearn.Ar job . 177749e11e3aSSheldon HearnIf the 177849e11e3aSSheldon Hearn.Ar job 177949e11e3aSSheldon Hearnargument is omitted, use the current job. 17809ba31ca0SRuslan Ermilov.It Ic jobs Oo Fl ls Oc Op Ar job ... 1781ad8a0759STim J. RobbinsPrint information about the specified jobs, or all jobs if no 1782ad8a0759STim J. Robbins.Ar job 1783ad8a0759STim J. Robbinsargument is given. 1784ad8a0759STim J. RobbinsThe information printed includes job ID, status and command name. 1785ad8a0759STim J. Robbins.Pp 1786ad8a0759STim J. RobbinsIf the 1787ad8a0759STim J. Robbins.Fl l 1788ad8a0759STim J. Robbinsoption is specified, the PID of each job is also printed. 1789ad8a0759STim J. RobbinsIf the 1790ad8a0759STim J. Robbins.Fl s 17919ba31ca0SRuslan Ermilovoption is specified, only the PIDs of the jobs are printed, one per line. 17928af11131SRuslan Ermilov.It Ic local Oo Ar variable ... Oc Op Fl 1793d2f90294SJesus R. CamouSee the 1794d2f90294SJesus R. Camou.Sx Functions 1795d2f90294SJesus R. Camousubsection. 1796d74e011fSRuslan Ermilov.It Ic pwd Op Fl L | P 1797eccea571SRuslan ErmilovPrint the path of the current directory. 1798eccea571SRuslan ErmilovThe built-in command may 17994b88c807SRodney W. Grimesdiffer from the program of the same name because the 18008eed22b1SJens Schweikhardtbuilt-in command remembers what the current directory 1801eccea571SRuslan Ermilovis rather than recomputing it each time. 1802eccea571SRuslan ErmilovThis makes 1803eccea571SRuslan Ermilovit faster. 1804eccea571SRuslan ErmilovHowever, if the current directory is 180549e11e3aSSheldon Hearnrenamed, 18068eed22b1SJens Schweikhardtthe built-in version of 180749e11e3aSSheldon Hearn.Xr pwd 1 180849e11e3aSSheldon Hearnwill continue to print the old name for the directory. 1809178897f1STim J. Robbins.Pp 1810178897f1STim J. RobbinsIf the 1811178897f1STim J. Robbins.Fl P 1812178897f1STim J. Robbinsoption is specified, symbolic links are resolved. 1813178897f1STim J. RobbinsIf the 1814178897f1STim J. Robbins.Fl L 1815178897f1STim J. Robbinsoption is specified, the shell's notion of the current directory 1816178897f1STim J. Robbinsis printed (symbolic links are not resolved). 1817178897f1STim J. RobbinsThis is the default. 181881e9cda2SRuslan Ermilov.It Ic read Oo Fl p Ar prompt Oc Oo Fl t Ar timeout Oc Oo Fl er Oc Ar variable ... 181949e11e3aSSheldon HearnThe 182049e11e3aSSheldon Hearn.Ar prompt 182149e11e3aSSheldon Hearnis printed if the 182249e11e3aSSheldon Hearn.Fl p 182349e11e3aSSheldon Hearnoption is specified 1824eccea571SRuslan Ermilovand the standard input is a terminal. 1825eccea571SRuslan ErmilovThen a line is 1826eccea571SRuslan Ermilovread from the standard input. 1827eccea571SRuslan ErmilovThe trailing newline 18284b88c807SRodney W. Grimesis deleted from the line and the line is split as 182949e11e3aSSheldon Hearndescribed in the section on 183049e11e3aSSheldon Hearn.Sx White Space Splitting (Field Splitting) 183149e11e3aSSheldon Hearnabove, and 18324b88c807SRodney W. Grimesthe pieces are assigned to the variables in order. 1833f434d1dfSAdam DavidIf there are more pieces than variables, the remaining 183449e11e3aSSheldon Hearnpieces (along with the characters in 183549e11e3aSSheldon Hearn.Ev IFS 183649e11e3aSSheldon Hearnthat separated them) 183749e11e3aSSheldon Hearnare assigned to the last variable. 1838f434d1dfSAdam DavidIf there are more variables than pieces, the remaining 1839f434d1dfSAdam Davidvariables are assigned the null string. 1840ab72124fSSteve Price.Pp 184149e11e3aSSheldon HearnBackslashes are treated specially, unless the 184249e11e3aSSheldon Hearn.Fl r 184349e11e3aSSheldon Hearnoption is 1844eccea571SRuslan Ermilovspecified. 1845eccea571SRuslan ErmilovIf a backslash is followed by 18468f0561ccSThomas Gellekuma newline, the backslash and the newline will be 1847eccea571SRuslan Ermilovdeleted. 1848eccea571SRuslan ErmilovIf a backslash is followed by any other 18498f0561ccSThomas Gellekumcharacter, the backslash will be deleted and the following 185049e11e3aSSheldon Hearncharacter will be treated as though it were not in 185149e11e3aSSheldon Hearn.Ev IFS , 185249e11e3aSSheldon Hearneven if it is. 18538f0561ccSThomas Gellekum.Pp 185449e11e3aSSheldon HearnIf the 185549e11e3aSSheldon Hearn.Fl t 185649e11e3aSSheldon Hearnoption is specified and the 185749e11e3aSSheldon Hearn.Ar timeout 185849e11e3aSSheldon Hearnelapses before any input is supplied, 185949e11e3aSSheldon Hearnthe 186049e11e3aSSheldon Hearn.Ic read 18611b161559SStefan Farfeledercommand will return an exit status of 1 without assigning any values. 186249e11e3aSSheldon HearnThe 186349e11e3aSSheldon Hearn.Ar timeout 186449e11e3aSSheldon Hearnvalue may optionally be followed by one of 186549e11e3aSSheldon Hearn.Dq s , 186649e11e3aSSheldon Hearn.Dq m 186749e11e3aSSheldon Hearnor 186849e11e3aSSheldon Hearn.Dq h 1869a910f192SDima Dorfmanto explicitly specify seconds, minutes or hours. 187049e11e3aSSheldon HearnIf none is supplied, 187149e11e3aSSheldon Hearn.Dq s 187249e11e3aSSheldon Hearnis assumed. 1873afa53c8dSMike Smith.Pp 187449e11e3aSSheldon HearnThe 187549e11e3aSSheldon Hearn.Fl e 187649e11e3aSSheldon Hearnoption exists only for backward compatibility with older scripts. 18779ba31ca0SRuslan Ermilov.It Ic readonly Oo Fl p Oc Op Ar name ... 187849e11e3aSSheldon HearnEach specified 187949e11e3aSSheldon Hearn.Ar name 188049e11e3aSSheldon Hearnis marked as read only, 188149e11e3aSSheldon Hearnso that it cannot be subsequently modified or unset. 188249e11e3aSSheldon HearnThe shell allows the value of a variable to be set 188349e11e3aSSheldon Hearnat the same time as it is marked read only 188449e11e3aSSheldon Hearnby using the following form: 1885ab72124fSSteve Price.Bd -literal -offset indent 18864b88c807SRodney W. Grimesreadonly name=value 1887ab72124fSSteve Price.Ed 1888ab72124fSSteve Price.Pp 188949e11e3aSSheldon HearnWith no arguments the 189049e11e3aSSheldon Hearn.Ic readonly 189149e11e3aSSheldon Hearncommand lists the names of all read only variables. 189245086f8cSTim J. RobbinsIf the 189345086f8cSTim J. Robbins.Fl p 189445086f8cSTim J. Robbinsoption is specified, the read-only variables are printed as 189545086f8cSTim J. Robbins.Dq Ic readonly Ar name Ns = Ns Ar value 189645086f8cSTim J. Robbinslines, suitable for re-input to the shell. 1897d2f90294SJesus R. Camou.It Ic return Op Ar exitstatus 1898d2f90294SJesus R. CamouSee the 1899d2f90294SJesus R. Camou.Sx Functions 1900d2f90294SJesus R. Camousubsection. 190181e9cda2SRuslan Ermilov.It Ic set Oo Fl /+abCEefIimnpTuVvx Oc Oo Fl /+o Ar longname Oc Oo 190281e9cda2SRuslan Ermilov.Fl c Ar string Oc Op Fl - Ar arg ... 1903e918fc8fSSheldon HearnThe 1904e918fc8fSSheldon Hearn.Ic set 1905e918fc8fSSheldon Hearncommand performs three different functions: 1906ab72124fSSteve Price.Bl -item 1907ab72124fSSteve Price.It 190849e11e3aSSheldon HearnWith no arguments, it lists the values of all shell variables. 1909ab72124fSSteve Price.It 191049e11e3aSSheldon HearnIf options are given, 191149e11e3aSSheldon Hearneither in short form or using the long 191249e11e3aSSheldon Hearn.Dq Fl /+o Ar longname 191349e11e3aSSheldon Hearnform, 191449e11e3aSSheldon Hearnit sets or clears the specified options as described in the section called 19156b15476eSSheldon Hearn.Sx Argument List Processing . 1916ab72124fSSteve Price.It 191749e11e3aSSheldon HearnIf the 191849e11e3aSSheldon Hearn.Dq Fl - 191949e11e3aSSheldon Hearnoption is specified, 192049e11e3aSSheldon Hearn.Ic set 192149e11e3aSSheldon Hearnwill replace the shell's positional parameters with the subsequent 192249e11e3aSSheldon Hearnarguments. 192349e11e3aSSheldon HearnIf no arguments follow the 192449e11e3aSSheldon Hearn.Dq Fl - 192549e11e3aSSheldon Hearnoption, 192649e11e3aSSheldon Hearnall the positional parameters will be cleared, 192749e11e3aSSheldon Hearnwhich is equivalent to executing the command 192849e11e3aSSheldon Hearn.Dq Li shift $# . 192949e11e3aSSheldon HearnThe 193049e11e3aSSheldon Hearn.Dq Fl - 19318eed22b1SJens Schweikhardtflag may be omitted when specifying arguments to be used 193249e11e3aSSheldon Hearnas positional replacement parameters. 193349e11e3aSSheldon HearnThis is not recommended, 193449e11e3aSSheldon Hearnbecause the first argument may begin with a dash 1935a762afe5SGiorgos Keramidas.Pq Ql - 193649e11e3aSSheldon Hearnor a plus 1937a762afe5SGiorgos Keramidas.Pq Ql + , 193849e11e3aSSheldon Hearnwhich the 193949e11e3aSSheldon Hearn.Ic set 194049e11e3aSSheldon Hearncommand will interpret as a request to enable or disable options. 1941ab72124fSSteve Price.El 194249e11e3aSSheldon Hearn.It Ic setvar Ar variable Ar value 194349e11e3aSSheldon HearnAssigns the specified 194449e11e3aSSheldon Hearn.Ar value 194549e11e3aSSheldon Hearnto the specified 194649e11e3aSSheldon Hearn.Ar variable . 194749e11e3aSSheldon Hearn.Ic Setvar 194849e11e3aSSheldon Hearnis intended to be used in functions that 1949e6d3cf26SSheldon Hearnassign values to variables whose names are passed as parameters. 195049e11e3aSSheldon HearnIn general it is better to write 195149e11e3aSSheldon Hearn.Bd -literal -offset indent 195249e11e3aSSheldon Hearnvariable=value 195349e11e3aSSheldon Hearn.Ed 195449e11e3aSSheldon Hearnrather than using 195549e11e3aSSheldon Hearn.Ic setvar . 195649e11e3aSSheldon Hearn.It Ic shift Op Ar n 195749e11e3aSSheldon HearnShift the positional parameters 195849e11e3aSSheldon Hearn.Ar n 1959e918fc8fSSheldon Hearntimes, or once if 196049e11e3aSSheldon Hearn.Ar n 196149e11e3aSSheldon Hearnis not specified. 196249e11e3aSSheldon HearnA shift sets the value of $1 to the value of $2, 196349e11e3aSSheldon Hearnthe value of $2 to the value of $3, and so on, 196449e11e3aSSheldon Hearndecreasing the value of $# by one. 196549e11e3aSSheldon HearnIf there are zero positional parameters, shifting does not do anything. 196610845922SYaroslav Tykhiy.It Ic test 196710845922SYaroslav TykhiyA built-in equivalent of 196810845922SYaroslav Tykhiy.Xr test 1 . 19691974986aSStefan Farfeleder.It Ic times 19701974986aSStefan FarfelederPrint the amount of time spent executing the shell and its children. 19711974986aSStefan FarfelederThe first output line shows the user and system times for the shell 19721974986aSStefan Farfelederitself, the second one contains the user and system times for the 19731974986aSStefan Farfelederchildren. 197481e9cda2SRuslan Ermilov.It Ic trap Oo Ar action Oc Ar signal ... 19750673e800SStefan Farfeleder.It Ic trap Fl l 197649e11e3aSSheldon HearnCause the shell to parse and execute 197749e11e3aSSheldon Hearn.Ar action 197849e11e3aSSheldon Hearnwhen any specified 197949e11e3aSSheldon Hearn.Ar signal 198049e11e3aSSheldon Hearnis received. 1981162ae3aeSTony FinchThe signals are specified by name or number. 1982162ae3aeSTony FinchIn addition, the pseudo-signal 1983f5d1157fSRuslan Ermilov.Cm EXIT 1984162ae3aeSTony Finchmay be used to specify an action that is performed when the shell terminates. 198549e11e3aSSheldon HearnThe 198649e11e3aSSheldon Hearn.Ar action 19870673e800SStefan Farfeledermay be an empty string or a dash 19889badf57fSRuslan Ermilov.Pq Ql - ; 198949e11e3aSSheldon Hearnthe former causes the specified signal to be ignored 199049e11e3aSSheldon Hearnand the latter causes the default action to be taken. 19910673e800SStefan FarfelederOmitting the 19920673e800SStefan Farfeleder.Ar action 19930673e800SStefan Farfelederis another way to request the default action, for compatibility reasons this 19940673e800SStefan Farfelederusage is not recommended though. 199549e11e3aSSheldon HearnWhen the shell forks off a subshell, 199649e11e3aSSheldon Hearnit resets trapped (but not ignored) signals to the default action. 199749e11e3aSSheldon HearnThe 199849e11e3aSSheldon Hearn.Ic trap 199949e11e3aSSheldon Hearncommand has no effect on signals that were ignored on entry to the shell. 20000673e800SStefan Farfeleder.Pp 20010673e800SStefan FarfelederOption 20020673e800SStefan Farfeleder.Fl l 20030673e800SStefan Farfeledercauses the 20040673e800SStefan Farfeleder.Ic trap 20050673e800SStefan Farfeledercommand to display a list of valid signal names. 2006a6557dcbSYaroslav Tykhiy.It Ic true 2007a6557dcbSYaroslav TykhiyA null command that returns a 0 (true) exit value. 200849e11e3aSSheldon Hearn.It Ic type Op Ar name ... 200949e11e3aSSheldon HearnInterpret each 201049e11e3aSSheldon Hearn.Ar name 201149e11e3aSSheldon Hearnas a command and print the resolution of the command search. 2012e6d3cf26SSheldon HearnPossible resolutions are: 20138eed22b1SJens Schweikhardtshell keyword, alias, shell built-in command, command, tracked alias 201449e11e3aSSheldon Hearnand not found. 201549e11e3aSSheldon HearnFor aliases the alias expansion is printed; 201649e11e3aSSheldon Hearnfor commands and tracked aliases 201749e11e3aSSheldon Hearnthe complete pathname of the command is printed. 201862df9b62SSheldon Hearn.It Ic ulimit Oo Fl HSabcdflmnstuv Oc Op Ar limit 2019ab72124fSSteve PriceSet or display resource limits (see 2020ab72124fSSteve Price.Xr getrlimit 2 ) . 20216b15476eSSheldon HearnIf 202249e11e3aSSheldon Hearn.Ar limit 20236b15476eSSheldon Hearnis specified, the named resource will be set; 20247a2afe64SJoerg Wunschotherwise the current resource value will be displayed. 2025ab72124fSSteve Price.Pp 20266b15476eSSheldon HearnIf 202749e11e3aSSheldon Hearn.Fl H 202849e11e3aSSheldon Hearnis specified, the hard limits will be set or displayed. 202949e11e3aSSheldon HearnWhile everybody is allowed to reduce a hard limit, 203049e11e3aSSheldon Hearnonly the superuser can increase it. 203149e11e3aSSheldon HearnThe 203249e11e3aSSheldon Hearn.Fl S 203349e11e3aSSheldon Hearnoption 2034eccea571SRuslan Ermilovspecifies the soft limits instead. 2035eccea571SRuslan ErmilovWhen displaying limits, 20366b15476eSSheldon Hearnonly one of 203749e11e3aSSheldon Hearn.Fl S 20386b15476eSSheldon Hearnor 203949e11e3aSSheldon Hearn.Fl H 204049e11e3aSSheldon Hearncan be given. 204149e11e3aSSheldon HearnThe default is to display the soft limits, 204249e11e3aSSheldon Hearnand to set both the hard and the soft limits. 2043ab72124fSSteve Price.Pp 20446b15476eSSheldon HearnOption 204549e11e3aSSheldon Hearn.Fl a 204649e11e3aSSheldon Hearncauses the 204749e11e3aSSheldon Hearn.Ic ulimit 204849e11e3aSSheldon Hearncommand to display all resources. 204949e11e3aSSheldon HearnThe parameter 205049e11e3aSSheldon Hearn.Ar limit 20516b15476eSSheldon Hearnis not acceptable in this mode. 2052ab72124fSSteve Price.Pp 20537a2afe64SJoerg WunschThe remaining options specify which resource value is to be 205449e11e3aSSheldon Hearndisplayed or modified. 205549e11e3aSSheldon HearnThey are mutually exclusive. 205681e9cda2SRuslan Ermilov.Bl -tag -width indent 20573652a236SMartin Cracauer.It Fl b Ar sbsize 20583652a236SMartin CracauerThe maximum size of socket buffer usage, in bytes. 205949e11e3aSSheldon Hearn.It Fl c Ar coredumpsize 20607a2afe64SJoerg WunschThe maximal size of core dump files, in 512-byte blocks. 206149e11e3aSSheldon Hearn.It Fl d Ar datasize 20627a2afe64SJoerg WunschThe maximal size of the data segment of a process, in kilobytes. 206349e11e3aSSheldon Hearn.It Fl f Ar filesize 206449e11e3aSSheldon HearnThe maximal size of a file, in 512-byte blocks. 206549e11e3aSSheldon Hearn.It Fl l Ar lockedmem 20667a2afe64SJoerg WunschThe maximal size of memory that can be locked by a process, in 20677a2afe64SJoerg Wunschkilobytes. 206849e11e3aSSheldon Hearn.It Fl m Ar memoryuse 20697a2afe64SJoerg WunschThe maximal resident set size of a process, in kilobytes. 207049e11e3aSSheldon Hearn.It Fl n Ar nofiles 20717a2afe64SJoerg WunschThe maximal number of descriptors that could be opened by a process. 207249e11e3aSSheldon Hearn.It Fl s Ar stacksize 20737a2afe64SJoerg WunschThe maximal size of the stack segment, in kilobytes. 207449e11e3aSSheldon Hearn.It Fl t Ar time 20757a2afe64SJoerg WunschThe maximal amount of CPU time to be used by each process, in seconds. 207649e11e3aSSheldon Hearn.It Fl u Ar userproc 2077ab72124fSSteve PriceThe maximal number of simultaneous processes for this user ID. 207862df9b62SSheldon Hearn.It Fl v Ar virtualmem 20792d41ef4bSMatthew DillonThe maximal virtual size of a process, in kilobytes. 2080ab72124fSSteve Price.El 2081faa1ed35SStefan Farfeleder.It Ic umask Oo Fl S Oc Op Ar mask 208249e11e3aSSheldon HearnSet the file creation mask (see 2083ab72124fSSteve Price.Xr umask 2 ) 2084faa1ed35SStefan Farfelederto the octal or symbolic (see 2085faa1ed35SStefan Farfeleder.Xr chmod 1 ) 2086faa1ed35SStefan Farfeledervalue specified by 20875d3b843bSSheldon Hearn.Ar mask . 208849e11e3aSSheldon HearnIf the argument is omitted, the current mask value is printed. 2089faa1ed35SStefan FarfelederIf the 2090faa1ed35SStefan Farfeleder.Fl S 2091faa1ed35SStefan Farfelederoption is specified, the output is symbolic, otherwise the output is octal. 2092de4ad382SStefan Farfeleder.It Ic unalias Oo Fl a Oc Op Ar name ... 2093de4ad382SStefan FarfelederThe specified alias names are removed. 20946b15476eSSheldon HearnIf 20951b9735e6SSheldon Hearn.Fl a 20966b15476eSSheldon Hearnis specified, all aliases are removed. 20979ba31ca0SRuslan Ermilov.It Ic unset Oo Fl fv Oc Ar name ... 20988b34ad92STim J. RobbinsThe specified variables or functions are unset and unexported. 20998b34ad92STim J. RobbinsIf the 21008b34ad92STim J. Robbins.Fl v 21018b34ad92STim J. Robbinsoption is specified or no options are given, the 210249e11e3aSSheldon Hearn.Ar name 21038b34ad92STim J. Robbinsarguments are treated as variable names. 21048b34ad92STim J. RobbinsIf the 21058b34ad92STim J. Robbins.Fl f 21068b34ad92STim J. Robbinsoption is specified, the 21078b34ad92STim J. Robbins.Ar name 21088b34ad92STim J. Robbinsarguments are treated as function names. 210949e11e3aSSheldon Hearn.It Ic wait Op Ar job 211049e11e3aSSheldon HearnWait for the specified 211149e11e3aSSheldon Hearn.Ar job 211249e11e3aSSheldon Hearnto complete and return the exit status of the last process in the 211349e11e3aSSheldon Hearn.Ar job . 2114e6d3cf26SSheldon HearnIf the argument is omitted, wait for all jobs to complete 2115e6d3cf26SSheldon Hearnand return an exit status of zero. 2116ab72124fSSteve Price.El 2117ab72124fSSteve Price.Ss Commandline Editing 2118ab72124fSSteve PriceWhen 2119ab72124fSSteve Price.Nm 2120ab72124fSSteve Priceis being used interactively from a terminal, the current command 212149e11e3aSSheldon Hearnand the command history 212249e11e3aSSheldon Hearn(see 212349e11e3aSSheldon Hearn.Ic fc 212449e11e3aSSheldon Hearnin 21258eed22b1SJens Schweikhardt.Sx Built-in Commands ) 212649e11e3aSSheldon Hearncan be edited using vi-mode command line editing. 212749e11e3aSSheldon HearnThis mode uses commands similar 21284b88c807SRodney W. Grimesto a subset of those described in the vi man page. 212949e11e3aSSheldon HearnThe command 213049e11e3aSSheldon Hearn.Dq Li set -o vi 213149e11e3aSSheldon Hearn(or 2132e918fc8fSSheldon Hearn.Dq Li set -V ) 213349e11e3aSSheldon Hearnenables vi-mode editing and places 2134ab72124fSSteve Price.Nm 2135eccea571SRuslan Ermilovinto vi insert mode. 2136eccea571SRuslan ErmilovWith vi-mode enabled, 2137ab72124fSSteve Price.Nm 213849e11e3aSSheldon Hearncan be switched between insert mode and command mode by typing 213949e11e3aSSheldon Hearn.Aq ESC . 214049e11e3aSSheldon HearnHitting 214149e11e3aSSheldon Hearn.Aq return 214249e11e3aSSheldon Hearnwhile in command mode will pass the line to the shell. 2143ab72124fSSteve Price.Pp 214449e11e3aSSheldon HearnSimilarly, the 214549e11e3aSSheldon Hearn.Dq Li set -o emacs 214649e11e3aSSheldon Hearn(or 2147e918fc8fSSheldon Hearn.Dq Li set -E ) 214849e11e3aSSheldon Hearncommand can be used to enable a subset of 2149ab72124fSSteve Priceemacs-style command line editing features. 215038afdcbcSGiorgos Keramidas.Sh ENVIRONMENT 215138afdcbcSGiorgos KeramidasThe following environment variables affect the execution of 215238afdcbcSGiorgos Keramidas.Nm : 215338afdcbcSGiorgos Keramidas.Bl -tag -width ".Ev HISTSIZE" 215438afdcbcSGiorgos Keramidas.It Ev CDPATH 215538afdcbcSGiorgos KeramidasThe search path used with the 215638afdcbcSGiorgos Keramidas.Ic cd 215738afdcbcSGiorgos Keramidasbuilt-in. 215838afdcbcSGiorgos Keramidas.It Ev EDITOR 215938afdcbcSGiorgos KeramidasThe fallback editor used with the 216038afdcbcSGiorgos Keramidas.Ic fc 216138afdcbcSGiorgos Keramidasbuilt-in. 216238afdcbcSGiorgos KeramidasIf not set, the default editor is 216338afdcbcSGiorgos Keramidas.Xr ed 1 . 216438afdcbcSGiorgos Keramidas.It Ev FCEDIT 216538afdcbcSGiorgos KeramidasThe default editor used with the 216638afdcbcSGiorgos Keramidas.Ic fc 216738afdcbcSGiorgos Keramidasbuilt-in. 216838afdcbcSGiorgos Keramidas.It Ev HISTSIZE 216938afdcbcSGiorgos KeramidasThe number of previous commands that are accessible. 217038afdcbcSGiorgos Keramidas.It Ev HOME 217138afdcbcSGiorgos KeramidasThe starting directory of 217238afdcbcSGiorgos Keramidas.Nm . 217338afdcbcSGiorgos Keramidas.It Ev IFS 217438afdcbcSGiorgos KeramidasInput Field Separators. 217538afdcbcSGiorgos KeramidasThis is normally set to 217638afdcbcSGiorgos Keramidas.Aq space , 217738afdcbcSGiorgos Keramidas.Aq tab , 217838afdcbcSGiorgos Keramidasand 217938afdcbcSGiorgos Keramidas.Aq newline . 218038afdcbcSGiorgos KeramidasSee the 218138afdcbcSGiorgos Keramidas.Sx White Space Splitting 218238afdcbcSGiorgos Keramidassection for more details. 218338afdcbcSGiorgos Keramidas.It Ev MAIL 218438afdcbcSGiorgos KeramidasThe name of a mail file, that will be checked for the arrival of new 218538afdcbcSGiorgos Keramidasmail. 218638afdcbcSGiorgos KeramidasOverridden by 218738afdcbcSGiorgos Keramidas.Ev MAILPATH . 218838afdcbcSGiorgos Keramidas.It Ev MAILPATH 218938afdcbcSGiorgos KeramidasA colon 219038afdcbcSGiorgos Keramidas.Pq Ql \&: 219138afdcbcSGiorgos Keramidasseparated list of file names, for the shell to check for incoming 219238afdcbcSGiorgos Keramidasmail. 219338afdcbcSGiorgos KeramidasThis environment setting overrides the 219438afdcbcSGiorgos Keramidas.Ev MAIL 219538afdcbcSGiorgos Keramidassetting. 219638afdcbcSGiorgos KeramidasThere is a maximum of 10 mailboxes that can be monitored at once. 219738afdcbcSGiorgos Keramidas.It Ev PATH 219838afdcbcSGiorgos KeramidasThe default search path for executables. 219938afdcbcSGiorgos KeramidasSee the 220038afdcbcSGiorgos Keramidas.Sx Path Search 220138afdcbcSGiorgos Keramidassection for details. 220238afdcbcSGiorgos Keramidas.It Ev PS1 220338afdcbcSGiorgos KeramidasThe primary prompt string, which defaults to 2204fb039b55SRuslan Ermilov.Dq Li "$ " , 220538afdcbcSGiorgos Keramidasunless you are the superuser, in which case it defaults to 2206fb039b55SRuslan Ermilov.Dq Li "# " . 220738afdcbcSGiorgos Keramidas.It Ev PS2 220838afdcbcSGiorgos KeramidasThe secondary prompt string, which defaults to 2209fb039b55SRuslan Ermilov.Dq Li "> " . 2210120c8e6cSStefan Farfeleder.It Ev PS4 2211120c8e6cSStefan FarfelederThe prefix for the trace output (if 2212120c8e6cSStefan Farfeleder.Fl x 2213120c8e6cSStefan Farfelederis active). 2214120c8e6cSStefan FarfelederThe default is 2215120c8e6cSStefan Farfeleder.Dq Li "+ " . 221638afdcbcSGiorgos Keramidas.It Ev TERM 221738afdcbcSGiorgos KeramidasThe default terminal setting for the shell. 221838afdcbcSGiorgos KeramidasThis is inherited by children of the shell, and is used in the history 221938afdcbcSGiorgos Keramidasediting modes. 222038afdcbcSGiorgos Keramidas.El 2221fb039b55SRuslan Ermilov.Sh EXIT STATUS 2222fb039b55SRuslan ErmilovErrors that are detected by the shell, such as a syntax error, will 2223fb039b55SRuslan Ermilovcause the shell to exit with a non-zero exit status. 2224fb039b55SRuslan ErmilovIf the shell is not an interactive shell, the execution of the shell 2225fb039b55SRuslan Ermilovfile will be aborted. 2226fb039b55SRuslan ErmilovOtherwise the shell will return the exit status of the last command 2227fb039b55SRuslan Ermilovexecuted, or if the exit builtin is used with a numeric argument, it 2228fb039b55SRuslan Ermilovwill return the argument. 2229c83e7c50SJoseph Koshy.Sh SEE ALSO 2230c644db6aSSheldon Hearn.Xr builtin 1 , 223138afdcbcSGiorgos Keramidas.Xr chsh 1 , 2232c644db6aSSheldon Hearn.Xr echo 1 , 223338afdcbcSGiorgos Keramidas.Xr ed 1 , 223438afdcbcSGiorgos Keramidas.Xr emacs 1 , 2235c83e7c50SJoseph Koshy.Xr expr 1 , 223638afdcbcSGiorgos Keramidas.Xr getopt 1 , 22375521ff5aSRuslan Ermilov.Xr pwd 1 , 223838afdcbcSGiorgos Keramidas.Xr test 1 , 223938afdcbcSGiorgos Keramidas.Xr vi 1 , 224038afdcbcSGiorgos Keramidas.Xr execve 2 , 224138afdcbcSGiorgos Keramidas.Xr getrlimit 2 , 2242fd50df30SRuslan Ermilov.Xr umask 2 , 224338afdcbcSGiorgos Keramidas.Xr editrc 5 2244ab72124fSSteve Price.Sh HISTORY 2245b8923d4cSWolfram SchneiderA 2246ab72124fSSteve Price.Nm 22479cdd1e3fSYaroslav Tykhiycommand, the Thompson shell, appeared in 2248fc482908STim J. Robbins.At v1 . 22499cdd1e3fSYaroslav TykhiyIt was superseded in 22509cdd1e3fSYaroslav Tykhiy.At v7 22519cdd1e3fSYaroslav Tykhiyby the Bourne shell, which inherited the name 22529cdd1e3fSYaroslav Tykhiy.Nm . 22539cdd1e3fSYaroslav Tykhiy.Pp 22549cdd1e3fSYaroslav TykhiyThis version of 22559cdd1e3fSYaroslav Tykhiy.Nm 22569cdd1e3fSYaroslav Tykhiywas rewritten in 1989 under the 22579cdd1e3fSYaroslav Tykhiy.Bx 22589cdd1e3fSYaroslav Tykhiylicense after the Bourne shell from 22599cdd1e3fSYaroslav Tykhiy.At V.4 . 22609cdd1e3fSYaroslav Tykhiy.Sh AUTHORS 22619cdd1e3fSYaroslav TykhiyThis version of 22629cdd1e3fSYaroslav Tykhiy.Nm 22639badf57fSRuslan Ermilovwas originally written by 22649badf57fSRuslan Ermilov.An Kenneth Almquist . 2265128dc4a2STim J. Robbins.Sh BUGS 2266128dc4a2STim J. RobbinsThe 2267128dc4a2STim J. Robbins.Nm 2268128dc4a2STim J. Robbinsutility does not recognize multibyte characters. 2269