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.\" 35de4ad382SStefan Farfeleder.Dd September 2, 2005 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 2114b88c807SRodney W. Grimesexplicitly tested if the command is used to control 2124b88c807SRodney W. Grimesan if, elif, while, or until; or if the command is the left 213ab72124fSSteve Pricehand operand of an 21449e11e3aSSheldon Hearn.Dq Li && 215ab72124fSSteve Priceor 21649e11e3aSSheldon Hearn.Dq Li || 217ab72124fSSteve Priceoperator. 218ab72124fSSteve Price.It Fl f Li noglob 2194b88c807SRodney W. GrimesDisable pathname expansion. 220ab72124fSSteve Price.It Fl I Li ignoreeof 22149e11e3aSSheldon HearnIgnore 22249e11e3aSSheldon Hearn.Dv EOF Ns ' Ns s 22349e11e3aSSheldon Hearnfrom input when in interactive mode. 224ab72124fSSteve Price.It Fl i Li interactive 225ab72124fSSteve PriceForce the shell to behave interactively. 226ab72124fSSteve Price.It Fl m Li monitor 227ab72124fSSteve PriceTurn on job control (set automatically when interactive). 228ab72124fSSteve Price.It Fl n Li noexec 2294b88c807SRodney W. GrimesIf not interactive, read commands but do not 230eccea571SRuslan Ermilovexecute them. 231eccea571SRuslan ErmilovThis is useful for checking the 2324b88c807SRodney W. Grimessyntax of shell scripts. 2337e1975c2STim J. Robbins.It Fl P Li physical 2347e1975c2STim J. RobbinsChange the default for the 2357e1975c2STim J. Robbins.Ic cd 2367e1975c2STim J. Robbinsand 2377e1975c2STim J. Robbins.Ic pwd 2387e1975c2STim J. Robbinscommands from 2397e1975c2STim J. Robbins.Fl L 2407e1975c2STim J. Robbins(logical directory layout) 2417e1975c2STim J. Robbinsto 2427e1975c2STim J. Robbins.Fl P 2437e1975c2STim J. Robbins(physical directory layout). 244ab72124fSSteve Price.It Fl p Li privileged 245eccea571SRuslan ErmilovTurn on privileged mode. 246eccea571SRuslan ErmilovThis mode is enabled on startup 247621a31c6SSteve Priceif either the effective user or group id is not equal to the 248eccea571SRuslan Ermilovreal user or group id. 249eccea571SRuslan ErmilovTurning this mode off sets the 250621a31c6SSteve Priceeffective user and group ids to the real user and group ids. 25149e11e3aSSheldon HearnWhen this mode is enabled for interactive shells, the file 252ab72124fSSteve Price.Pa /etc/suid_profile 25349e11e3aSSheldon Hearnis sourced instead of 25449e11e3aSSheldon Hearn.Pa ~/.profile 255ab72124fSSteve Priceafter 256ab72124fSSteve Price.Pa /etc/profile 25749e11e3aSSheldon Hearnis sourced, and the contents of the 258ab72124fSSteve Price.Ev ENV 25949e11e3aSSheldon Hearnvariable are ignored. 260ab72124fSSteve Price.It Fl s Li stdin 2614b88c807SRodney W. GrimesRead commands from standard input (set automatically 262eccea571SRuslan Ermilovif no file arguments are present). 263eccea571SRuslan ErmilovThis option has 2644b88c807SRodney W. Grimesno effect when set after the shell has already started 265eccea571SRuslan Ermilovrunning (i.e., when set with the 266c644db6aSSheldon Hearn.Ic set 2676b15476eSSheldon Hearncommand). 268304199ceSTom Rhodes.It Fl T Li trapsasync 269e6d3cf26SSheldon HearnWhen waiting for a child, execute traps immediately. 270e6d3cf26SSheldon HearnIf this option is not set, 271e6d3cf26SSheldon Hearntraps are executed after the child exits, 272e6d3cf26SSheldon Hearnas specified in 273af5eb6fcSMaxim Konovalov.St -p1003.2 . 2746b15476eSSheldon HearnThis nonstandard option is useful for putting guarding shells around 275eccea571SRuslan Ermilovchildren that block signals. 276eccea571SRuslan ErmilovThe surrounding shell may kill the child 2776b15476eSSheldon Hearnor it may just return control to the tty and leave the child alone, 2786b15476eSSheldon Hearnlike this: 279c1c72a3cSMartin Cracauer.Bd -literal -offset indent 280c1c72a3cSMartin Cracauersh -T -c "trap 'exit 1' 2 ; some-blocking-program" 281c1c72a3cSMartin Cracauer.Ed 282c1c72a3cSMartin Cracauer.Pp 283ab72124fSSteve Price.It Fl u Li nounset 284ab72124fSSteve PriceWrite a message to standard error when attempting 285ab72124fSSteve Priceto expand a variable that is not set, and if the 286ab72124fSSteve Priceshell is not interactive, exit immediately. 287ab72124fSSteve Price.It Fl V Li vi 2888eed22b1SJens SchweikhardtEnable the built-in 289ab72124fSSteve Price.Xr vi 1 290ab72124fSSteve Pricecommand line editor (disables 291ab72124fSSteve Price.Fl E 292ab72124fSSteve Priceif it has been set). 293ab72124fSSteve Price.It Fl v Li verbose 294ab72124fSSteve PriceThe shell writes its input to standard error 295eccea571SRuslan Ermilovas it is read. 296eccea571SRuslan ErmilovUseful for debugging. 297ab72124fSSteve Price.It Fl x Li xtrace 29849e11e3aSSheldon HearnWrite each command 29949e11e3aSSheldon Hearn(preceded by 3006fa13ec0SRuslan Ermilov.Dq Li "+ " ) 30149e11e3aSSheldon Hearnto standard error before it is executed. 30249e11e3aSSheldon HearnUseful for debugging. 30349e11e3aSSheldon Hearn.El 30449e11e3aSSheldon Hearn.Pp 30549e11e3aSSheldon HearnThe 306fd50df30SRuslan Ermilov.Fl c 307fd50df30SRuslan Ermilovoption causes the commands to be read from the 308fd50df30SRuslan Ermilov.Ar string 309fd50df30SRuslan Ermilovoperand instead of from the standard input. 310fd50df30SRuslan ErmilovKeep in mind that this option only accepts a single string as its 311fd50df30SRuslan Ermilovargument, hence multi-word strings must be quoted. 312fd50df30SRuslan Ermilov.Pp 313fd50df30SRuslan ErmilovThe 31449e11e3aSSheldon Hearn.Fl /+o 31549e11e3aSSheldon Hearnoption takes as its only argument the long name of an option 31649e11e3aSSheldon Hearnto be enabled or disabled. 31749e11e3aSSheldon HearnFor example, the following two invocations of 31849e11e3aSSheldon Hearn.Nm 3198eed22b1SJens Schweikhardtboth enable the built-in 32049e11e3aSSheldon Hearn.Xr emacs 1 32149e11e3aSSheldon Hearncommand line editor: 32249e11e3aSSheldon Hearn.Bd -literal -offset indent 32349e11e3aSSheldon Hearnset -E 32449e11e3aSSheldon Hearnset -o emacs 32549e11e3aSSheldon Hearn.Ed 326d513af6aSTim J. Robbins.Pp 327d513af6aSTim J. RobbinsIf used without an argument, the 328d513af6aSTim J. Robbins.Fl o 329d513af6aSTim J. Robbinsoption displays the current option settings in a human-readable format. 330d513af6aSTim J. RobbinsIf 331d513af6aSTim J. Robbins.Cm +o 332d513af6aSTim J. Robbinsis used without an argument, the current option settings are output 333d513af6aSTim J. Robbinsin a format suitable for re-input into the shell. 334ab72124fSSteve Price.Ss Lexical Structure 3354b88c807SRodney W. GrimesThe shell reads input in terms of lines from a file and breaks 3364b88c807SRodney W. Grimesit up into words at whitespace (blanks and tabs), and at 3374b88c807SRodney W. Grimescertain sequences of 3386b15476eSSheldon Hearncharacters called 3396b15476eSSheldon Hearn.Dq operators , 3406b15476eSSheldon Hearnwhich are special to the shell. 3414b88c807SRodney W. GrimesThere are two types of operators: control operators and 3424b88c807SRodney W. Grimesredirection operators (their meaning is discussed later). 343ab72124fSSteve PriceThe following is a list of valid operators: 34481e9cda2SRuslan Ermilov.Bl -tag -width indent 34549e11e3aSSheldon Hearn.It Control operators: 34649e11e3aSSheldon Hearn.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 34781e9cda2SRuslan Ermilov.It Li & Ta Li && Ta Li ( Ta Li ) Ta Li \en 34881e9cda2SRuslan Ermilov.It Li ;; Ta Li ; Ta Li | Ta Li || 34949e11e3aSSheldon Hearn.El 35049e11e3aSSheldon Hearn.It Redirection operators: 3514682f420SBrian Somers.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 35281e9cda2SRuslan Ermilov.It Li < Ta Li > Ta Li << Ta Li >> Ta Li <> 35381e9cda2SRuslan Ermilov.It Li <& Ta Li >& Ta Li <<- Ta Li >| 35449e11e3aSSheldon Hearn.El 355ab72124fSSteve Price.El 356ab72124fSSteve Price.Ss Quoting 3574b88c807SRodney W. GrimesQuoting is used to remove the special meaning of certain characters 358a886288eSJesus R. Camouor words to the shell, such as operators, whitespace, keywords, 359a886288eSJesus R. Camouor alias names. 360a886288eSJesus R. Camou.Pp 361eccea571SRuslan ErmilovThere are three types of quoting: matched single quotes, 3624b88c807SRodney W. Grimesmatched double quotes, and backslash. 36381e9cda2SRuslan Ermilov.Bl -tag -width indent 364ab72124fSSteve Price.It Single Quotes 3654b88c807SRodney W. GrimesEnclosing characters in single quotes preserves the literal 366ab0a2172SSteve Pricemeaning of all the characters (except single quotes, making 367ab0a2172SSteve Priceit impossible to put single-quotes in a single-quoted string). 368ab72124fSSteve Price.It Double Quotes 3694b88c807SRodney W. GrimesEnclosing characters within double quotes preserves the literal 37049e11e3aSSheldon Hearnmeaning of all characters except dollarsign 371a762afe5SGiorgos Keramidas.Pq Ql $ , 37249e11e3aSSheldon Hearnbackquote 373a762afe5SGiorgos Keramidas.Pq Ql ` , 37449e11e3aSSheldon Hearnand backslash 375a762afe5SGiorgos Keramidas.Pq Ql \e . 37649e11e3aSSheldon HearnThe backslash inside double quotes is historically weird. 37749e11e3aSSheldon HearnIt remains literal unless it precedes the following characters, 37849e11e3aSSheldon Hearnwhich it serves to quote: 37949e11e3aSSheldon Hearn.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact 38081e9cda2SRuslan Ermilov.It Li $ Ta Li ` Ta Li \&" Ta Li \e\ Ta Li \en 38149e11e3aSSheldon Hearn.El 382ab72124fSSteve Price.It Backslash 383ab72124fSSteve PriceA backslash preserves the literal meaning of the following 38449e11e3aSSheldon Hearncharacter, with the exception of the newline character 385a762afe5SGiorgos Keramidas.Pq Ql \en . 38649e11e3aSSheldon HearnA backslash preceding a newline is treated as a line continuation. 387ab72124fSSteve Price.El 388ab72124fSSteve Price.Ss Reserved Words 3894b88c807SRodney W. GrimesReserved words are words that have special meaning to the 3904b88c807SRodney W. Grimesshell and are recognized at the beginning of a line and 391eccea571SRuslan Ermilovafter a control operator. 392eccea571SRuslan ErmilovThe following are reserved words: 39349e11e3aSSheldon Hearn.Bl -column "doneXX" "elifXX" "elseXX" "untilXX" "whileX" -offset center 39481e9cda2SRuslan Ermilov.It Li \&! Ta { Ta } Ta Ic case Ta Ic do 39581e9cda2SRuslan Ermilov.It Ic done Ta Ic elif Ta Ic else Ta Ic esac Ta Ic fi 39681e9cda2SRuslan Ermilov.It Ic for Ta Ic if Ta Ic then Ta Ic until Ta Ic while 39749e11e3aSSheldon Hearn.El 398ab72124fSSteve Price.Ss Aliases 399ab72124fSSteve PriceAn alias is a name and corresponding value set using the 400c644db6aSSheldon Hearn.Ic alias 401eccea571SRuslan Ermilovbuilt-in command. 402eccea571SRuslan ErmilovWhenever a reserved word may occur (see above), 4034b88c807SRodney W. Grimesand after checking for reserved words, the shell 404e6d3cf26SSheldon Hearnchecks the word to see if it matches an alias. 405e6d3cf26SSheldon HearnIf it does, it replaces it in the input stream with its value. 406e6d3cf26SSheldon HearnFor example, if there is an alias called 40749e11e3aSSheldon Hearn.Dq Li lf 4086b15476eSSheldon Hearnwith the value 40949e11e3aSSheldon Hearn.Dq Li ls -F , 4104b88c807SRodney W. Grimesthen the input 411ab72124fSSteve Price.Bd -literal -offset indent 41249e11e3aSSheldon Hearnlf foobar 413ab72124fSSteve Price.Ed 414ab72124fSSteve Price.Pp 4154b88c807SRodney W. Grimeswould become 416ab72124fSSteve Price.Bd -literal -offset indent 41749e11e3aSSheldon Hearnls -F foobar 418ab72124fSSteve Price.Ed 419ab72124fSSteve Price.Pp 4204b88c807SRodney W. GrimesAliases provide a convenient way for naive users to 4214b88c807SRodney W. Grimescreate shorthands for commands without having to learn how 422eccea571SRuslan Ermilovto create functions with arguments. 423eccea571SRuslan ErmilovThey can also be 424eccea571SRuslan Ermilovused to create lexically obscure code. 425eccea571SRuslan ErmilovThis use is discouraged. 426a886288eSJesus R. Camou.Pp 427a886288eSJesus R. CamouAn alias name may be escaped in a command line, so that it is not 428a886288eSJesus R. Camoureplaced by its alias value, by using quoting characters within or 42919162ab9SJesus R. Camouadjacent to the alias name. 43019162ab9SJesus R. CamouThis is most often done by prefixing 431a886288eSJesus R. Camouan alias name with a backslash to execute a function, built-in, or 432a886288eSJesus R. Camounormal program with the same name. 433a886288eSJesus R. CamouSee the 434a886288eSJesus R. Camou.Sx Quoting 435a886288eSJesus R. Camousubsection. 436ab72124fSSteve Price.Ss Commands 4374b88c807SRodney W. GrimesThe shell interprets the words it reads according to a 4384b88c807SRodney W. Grimeslanguage, the specification of which is outside the scope 439ab72124fSSteve Priceof this man page (refer to the BNF in the 440ab72124fSSteve Price.St -p1003.2 441eccea571SRuslan Ermilovdocument). 442eccea571SRuslan ErmilovEssentially though, a line is read and if 4434b88c807SRodney W. Grimesthe first word of the line (or after a control operator) 4444b88c807SRodney W. Grimesis not a reserved word, then the shell has recognized a 445eccea571SRuslan Ermilovsimple command. 446eccea571SRuslan ErmilovOtherwise, a complex command or some 4474b88c807SRodney W. Grimesother special construct may have been recognized. 448ab72124fSSteve Price.Ss Simple Commands 4494b88c807SRodney W. GrimesIf a simple command has been recognized, the shell performs 4504b88c807SRodney W. Grimesthe following actions: 451ab72124fSSteve Price.Bl -enum 452ab72124fSSteve Price.It 4536b15476eSSheldon HearnLeading words of the form 45449e11e3aSSheldon Hearn.Dq Li name=value 4556b15476eSSheldon Hearnare stripped off and assigned to the environment of 456eccea571SRuslan Ermilovthe simple command. 457eccea571SRuslan ErmilovRedirection operators and 4584b88c807SRodney W. Grimestheir arguments (as described below) are stripped 4594b88c807SRodney W. Grimesoff and saved for processing. 460ab72124fSSteve Price.It 461ab72124fSSteve PriceThe remaining words are expanded as described in 4626b15476eSSheldon Hearnthe section called 4636b15476eSSheldon Hearn.Sx Word Expansions , 4646b15476eSSheldon Hearnand the first remaining word is considered the command 465eccea571SRuslan Ermilovname and the command is located. 466eccea571SRuslan ErmilovThe remaining 4674b88c807SRodney W. Grimeswords are considered the arguments of the command. 4686b15476eSSheldon HearnIf no command name resulted, then the 46949e11e3aSSheldon Hearn.Dq Li name=value 4704b88c807SRodney W. Grimesvariable assignments recognized in 1) affect the 4714b88c807SRodney W. Grimescurrent shell. 472ab72124fSSteve Price.It 473ab72124fSSteve PriceRedirections are performed as described in 4744b88c807SRodney W. Grimesthe next section. 475ab72124fSSteve Price.El 476ab72124fSSteve Price.Ss Redirections 4774b88c807SRodney W. GrimesRedirections are used to change where a command reads its input 478eccea571SRuslan Ermilovor sends its output. 479eccea571SRuslan ErmilovIn general, redirections open, close, or 480eccea571SRuslan Ermilovduplicate an existing reference to a file. 481eccea571SRuslan ErmilovThe overall format 4824b88c807SRodney W. Grimesused for redirection is: 48349e11e3aSSheldon Hearn.Pp 484ab72124fSSteve Price.Dl [n] redir-op file 48549e11e3aSSheldon Hearn.Pp 48649e11e3aSSheldon HearnThe 48749e11e3aSSheldon Hearn.Ql redir-op 48849e11e3aSSheldon Hearnis one of the redirection operators mentioned 489eccea571SRuslan Ermilovpreviously. 490eccea571SRuslan ErmilovThe following gives some examples of how these 49149e11e3aSSheldon Hearnoperators can be used. 49249e11e3aSSheldon HearnNote that stdin and stdout are commonly used abbreviations 49349e11e3aSSheldon Hearnfor standard input and standard output respectively. 49449e11e3aSSheldon Hearn.Bl -tag -width "1234567890XX" -offset indent 49549e11e3aSSheldon Hearn.It Li [n]> file 49649e11e3aSSheldon Hearnredirect stdout (or file descriptor n) to file 49749e11e3aSSheldon Hearn.It Li [n]>| file 49849e11e3aSSheldon Hearnsame as above, but override the 49949e11e3aSSheldon Hearn.Fl C 50049e11e3aSSheldon Hearnoption 50149e11e3aSSheldon Hearn.It Li [n]>> file 50249e11e3aSSheldon Hearnappend stdout (or file descriptor n) to file 50349e11e3aSSheldon Hearn.It Li [n]< file 50449e11e3aSSheldon Hearnredirect stdin (or file descriptor n) from file 5054682f420SBrian Somers.It Li [n]<> file 5064682f420SBrian Somersredirect stdin (or file descriptor n) to and from file 50749e11e3aSSheldon Hearn.It Li [n1]<&n2 50849e11e3aSSheldon Hearnduplicate stdin (or file descriptor n1) from file descriptor n2 50949e11e3aSSheldon Hearn.It Li [n]<&- 51049e11e3aSSheldon Hearnclose stdin (or file descriptor n) 51149e11e3aSSheldon Hearn.It Li [n1]>&n2 51249e11e3aSSheldon Hearnduplicate stdout (or file descriptor n1) to file descriptor n2 51349e11e3aSSheldon Hearn.It Li [n]>&- 51449e11e3aSSheldon Hearnclose stdout (or file descriptor n) 515ab72124fSSteve Price.El 516ab72124fSSteve Price.Pp 5176b15476eSSheldon HearnThe following redirection is often called a 5186b15476eSSheldon Hearn.Dq here-document . 519ab72124fSSteve Price.Bd -literal -offset indent 5204b88c807SRodney W. Grimes[n]<< delimiter 52149e11e3aSSheldon Hearn here-doc-text 52249e11e3aSSheldon Hearn ... 5234b88c807SRodney W. Grimesdelimiter 524ab72124fSSteve Price.Ed 525ab72124fSSteve Price.Pp 5264b88c807SRodney W. GrimesAll the text on successive lines up to the delimiter is 5274b88c807SRodney W. Grimessaved away and made available to the command on standard 528eccea571SRuslan Ermilovinput, or file descriptor n if it is specified. 529eccea571SRuslan ErmilovIf the delimiter 5304b88c807SRodney W. Grimesas specified on the initial line is quoted, then the here-doc-text 5314b88c807SRodney W. Grimesis treated literally, otherwise the text is subjected to 5324b88c807SRodney W. Grimesparameter expansion, command substitution, and arithmetic 5336b15476eSSheldon Hearnexpansion (as described in the section on 5346b15476eSSheldon Hearn.Sx Word Expansions ) . 5356b15476eSSheldon HearnIf the operator is 53649e11e3aSSheldon Hearn.Dq Li <<- 5376b15476eSSheldon Hearninstead of 53849e11e3aSSheldon Hearn.Dq Li << , 5396b15476eSSheldon Hearnthen leading tabs 5404b88c807SRodney W. Grimesin the here-doc-text are stripped. 541ab72124fSSteve Price.Ss Search and Execution 542ab0a2172SSteve PriceThere are three types of commands: shell functions, 5438eed22b1SJens Schweikhardtbuilt-in commands, and normal programs. 54449e11e3aSSheldon HearnThe command is searched for (by name) in that order. 54549e11e3aSSheldon HearnThe three types of commands are all executed in a different way. 546ab72124fSSteve Price.Pp 547ab0a2172SSteve PriceWhen a shell function is executed, all of the shell positional 548ab0a2172SSteve Priceparameters (except $0, which remains unchanged) are 5494b88c807SRodney W. Grimesset to the arguments of the shell function. 5504b88c807SRodney W. GrimesThe variables which are explicitly placed in the environment of 5514b88c807SRodney W. Grimesthe command (by placing assignments to them before the 5524b88c807SRodney W. Grimesfunction name) are made local to the function and are set 553e6d3cf26SSheldon Hearnto the values given. 554e6d3cf26SSheldon HearnThen the command given in the function definition is executed. 555e6d3cf26SSheldon HearnThe positional parameters are restored to their original values 556e6d3cf26SSheldon Hearnwhen the command completes. 557ab0a2172SSteve PriceThis all occurs within the current shell. 558ab72124fSSteve Price.Pp 5598eed22b1SJens SchweikhardtShell built-in commands are executed internally to the shell, without 560ab0a2172SSteve Pricespawning a new process. 561ab72124fSSteve Price.Pp 562c644db6aSSheldon HearnOtherwise, if the command name does not match a function 5638eed22b1SJens Schweikhardtor built-in command, the command is searched for as a normal 5644b88c807SRodney W. Grimesprogram in the file system (as described in the next section). 5654b88c807SRodney W. GrimesWhen a normal program is executed, the shell runs the program, 566e6d3cf26SSheldon Hearnpassing the arguments and the environment to the program. 567e6d3cf26SSheldon HearnIf the program is not a normal executable file 568eccea571SRuslan Ermilov(i.e., if it does not begin with the 5696b15476eSSheldon Hearn.Qq magic number 5706b15476eSSheldon Hearnwhose 571ab72124fSSteve Price.Tn ASCII 5726b15476eSSheldon Hearnrepresentation is 5736b15476eSSheldon Hearn.Qq #! , 57449e11e3aSSheldon Hearnresulting in an 575b4f0f4aaSRuslan Ermilov.Er ENOEXEC 57649e11e3aSSheldon Hearnreturn value from 57749e11e3aSSheldon Hearn.Xr execve 2 ) 578e6d3cf26SSheldon Hearnthe shell will interpret the program in a subshell. 579e6d3cf26SSheldon HearnThe child shell will reinitialize itself in this case, 580e6d3cf26SSheldon Hearnso that the effect will be 581e6d3cf26SSheldon Hearnas if a new shell had been invoked to handle the ad-hoc shell script, 582e6d3cf26SSheldon Hearnexcept that the location of hashed commands located in 5834b88c807SRodney W. Grimesthe parent shell will be remembered by the child. 584ab72124fSSteve Price.Pp 585ab0a2172SSteve PriceNote that previous versions of this document 586ab0a2172SSteve Priceand the source code itself misleadingly and sporadically 587ab0a2172SSteve Pricerefer to a shell script without a magic number 5886b15476eSSheldon Hearnas a 5896b15476eSSheldon Hearn.Qq shell procedure . 590ab72124fSSteve Price.Ss Path Search 5914b88c807SRodney W. GrimesWhen locating a command, the shell first looks to see if 592eccea571SRuslan Ermilovit has a shell function by that name. 593eccea571SRuslan ErmilovThen it looks for a 594eccea571SRuslan Ermilovbuilt-in command by that name. 595eccea571SRuslan ErmilovIf a built-in command is not found, 596ab0a2172SSteve Priceone of two things happen: 597ab72124fSSteve Price.Bl -enum 598ab72124fSSteve Price.It 599ab72124fSSteve PriceCommand names containing a slash are simply executed without 600ab0a2172SSteve Priceperforming any searches. 601ab72124fSSteve Price.It 602ab72124fSSteve PriceThe shell searches each entry in 603ab72124fSSteve Price.Ev PATH 604eccea571SRuslan Ermilovin turn for the command. 605eccea571SRuslan ErmilovThe value of the 606ab72124fSSteve Price.Ev PATH 607ab72124fSSteve Pricevariable should be a series of 608eccea571SRuslan Ermiloventries separated by colons. 609eccea571SRuslan ErmilovEach entry consists of a 6104b88c807SRodney W. Grimesdirectory name. 6114b88c807SRodney W. GrimesThe current directory 612ab0a2172SSteve Pricemay be indicated implicitly by an empty directory name, 613ab0a2172SSteve Priceor explicitly by a single period. 614ab72124fSSteve Price.El 615ab72124fSSteve Price.Ss Command Exit Status 6164b88c807SRodney W. GrimesEach command has an exit status that can influence the behavior 617eccea571SRuslan Ermilovof other shell commands. 618eccea571SRuslan ErmilovThe paradigm is that a command exits 6194b88c807SRodney W. Grimeswith zero for normal or success, and non-zero for failure, 620eccea571SRuslan Ermiloverror, or a false indication. 621eccea571SRuslan ErmilovThe man page for each command 6224b88c807SRodney W. Grimesshould indicate the various exit codes and what they mean. 6238eed22b1SJens SchweikhardtAdditionally, the built-in commands return exit codes, as does 624ab0a2172SSteve Pricean executed shell function. 625c351e089SJohn Polstra.Pp 626c351e089SJohn PolstraIf a command is terminated by a signal, its exit status is 128 plus 627eccea571SRuslan Ermilovthe signal number. 628eccea571SRuslan ErmilovSignal numbers are defined in the header file 629fe08efe6SRuslan Ermilov.In sys/signal.h . 630ab72124fSSteve Price.Ss Complex Commands 6314b88c807SRodney W. GrimesComplex commands are combinations of simple commands 6324b88c807SRodney W. Grimeswith control operators or reserved words, together creating a larger complex 633eccea571SRuslan Ermilovcommand. 634eccea571SRuslan ErmilovMore generally, a command is one of the following: 635ab72124fSSteve Price.Bl -item -offset indent 636ab72124fSSteve Price.It 637ab72124fSSteve Pricesimple command 638ab72124fSSteve Price.It 639ab72124fSSteve Pricepipeline 640ab72124fSSteve Price.It 641ab72124fSSteve Pricelist or compound-list 642ab72124fSSteve Price.It 643ab72124fSSteve Pricecompound command 644ab72124fSSteve Price.It 645ab72124fSSteve Pricefunction definition 646ab72124fSSteve Price.El 647ab72124fSSteve Price.Pp 6484b88c807SRodney W. GrimesUnless otherwise stated, the exit status of a command is 6494b88c807SRodney W. Grimesthat of the last simple command executed by the command. 650ab72124fSSteve Price.Ss Pipelines 6514b88c807SRodney W. GrimesA pipeline is a sequence of one or more commands separated 652eccea571SRuslan Ermilovby the control operator |. 653eccea571SRuslan ErmilovThe standard output of all but 6544b88c807SRodney W. Grimesthe last command is connected to the standard input 655eccea571SRuslan Ermilovof the next command. 656eccea571SRuslan ErmilovThe standard output of the last 657ab0a2172SSteve Pricecommand is inherited from the shell, as usual. 658ab72124fSSteve Price.Pp 6594b88c807SRodney W. GrimesThe format for a pipeline is: 66049e11e3aSSheldon Hearn.Pp 66149e11e3aSSheldon Hearn.Dl [!] command1 [ | command2 ...] 662ab72124fSSteve Price.Pp 6634b88c807SRodney W. GrimesThe standard output of command1 is connected to the standard 664eccea571SRuslan Ermilovinput of command2. 665eccea571SRuslan ErmilovThe standard input, standard output, or 6664b88c807SRodney W. Grimesboth of a command is considered to be assigned by the 6674b88c807SRodney W. Grimespipeline before any redirection specified by redirection 6684b88c807SRodney W. Grimesoperators that are part of the command. 669ab72124fSSteve Price.Pp 6704b88c807SRodney W. GrimesIf the pipeline is not in the background (discussed later), 6714b88c807SRodney W. Grimesthe shell waits for all commands to complete. 672ab72124fSSteve Price.Pp 673eccea571SRuslan ErmilovIf the reserved word 674eccea571SRuslan Ermilov.Ic !\& 675eccea571SRuslan Ermilovdoes not precede the pipeline, the 6764b88c807SRodney W. Grimesexit status is the exit status of the last command specified 677eccea571SRuslan Ermilovin the pipeline. 678eccea571SRuslan ErmilovOtherwise, the exit status is the logical 679eccea571SRuslan ErmilovNOT of the exit status of the last command. 680eccea571SRuslan ErmilovThat is, if 6814b88c807SRodney W. Grimesthe last command returns zero, the exit status is 1; if 6824b88c807SRodney W. Grimesthe last command returns greater than zero, the exit status 6834b88c807SRodney W. Grimesis zero. 684ab72124fSSteve Price.Pp 6854b88c807SRodney W. GrimesBecause pipeline assignment of standard input or standard 6864b88c807SRodney W. Grimesoutput or both takes place before redirection, it can be 687eccea571SRuslan Ermilovmodified by redirection. 688eccea571SRuslan ErmilovFor example: 689ab72124fSSteve Price.Pp 69049e11e3aSSheldon Hearn.Dl $ command1 2>&1 | command2 691ab72124fSSteve Price.Pp 69249e11e3aSSheldon Hearnsends both the standard output and standard error of 69349e11e3aSSheldon Hearn.Ql command1 69449e11e3aSSheldon Hearnto the standard input of 69549e11e3aSSheldon Hearn.Ql command2 . 69649e11e3aSSheldon Hearn.Pp 69749e11e3aSSheldon HearnA 69812e720d7SRuslan Ermilov.Dq Li \&; 69949e11e3aSSheldon Hearnor newline terminator causes the preceding 700e918fc8fSSheldon HearnAND-OR-list 701e918fc8fSSheldon Hearn(described below in the section called 702e918fc8fSSheldon Hearn.Sx Short-Circuit List Operators ) 703e918fc8fSSheldon Hearnto be executed sequentially; 704e918fc8fSSheldon Hearnan 705e918fc8fSSheldon Hearn.Dq Li & 706e918fc8fSSheldon Hearncauses asynchronous execution of the preceding AND-OR-list. 707ab72124fSSteve Price.Pp 70849e11e3aSSheldon HearnNote that unlike some other shells, 70949e11e3aSSheldon Hearn.Nm 71049e11e3aSSheldon Hearnexecutes each process in the pipeline as a child of the 71149e11e3aSSheldon Hearn.Nm 71249e11e3aSSheldon Hearnprocess. 7138eed22b1SJens SchweikhardtShell built-in commands are the exception to this rule. 71449e11e3aSSheldon HearnThey are executed in the current shell, although they do not affect its 71549e11e3aSSheldon Hearnenvironment when used in pipelines. 71649e11e3aSSheldon Hearn.Ss Background Commands (&) 7174b88c807SRodney W. GrimesIf a command is terminated by the control operator ampersand 718a762afe5SGiorgos Keramidas.Pq Ql & , 71949e11e3aSSheldon Hearnthe shell executes the command asynchronously; 72049e11e3aSSheldon Hearnthe shell does not wait for the command to finish 72149e11e3aSSheldon Hearnbefore executing the next command. 722ab72124fSSteve Price.Pp 7234b88c807SRodney W. GrimesThe format for running a command in background is: 724ab72124fSSteve Price.Bd -literal -offset indent 7254b88c807SRodney W. Grimescommand1 & [command2 & ...] 726ab72124fSSteve Price.Ed 727ab72124fSSteve Price.Pp 7284b88c807SRodney W. GrimesIf the shell is not interactive, the standard input of an 7294b88c807SRodney W. Grimesasynchronous command is set to /dev/null. 73049e11e3aSSheldon Hearn.Ss Lists (Generally Speaking) 7314b88c807SRodney W. GrimesA list is a sequence of zero or more commands separated by 7324b88c807SRodney W. Grimesnewlines, semicolons, or ampersands, 7334b88c807SRodney W. Grimesand optionally terminated by one of these three characters. 7344b88c807SRodney W. GrimesThe commands in a 7354b88c807SRodney W. Grimeslist are executed in the order they are written. 7364b88c807SRodney W. GrimesIf command is followed by an ampersand, the shell starts the 7378eed22b1SJens Schweikhardtcommand and immediately proceeds onto the next command; 7384b88c807SRodney W. Grimesotherwise it waits for the command to terminate before 7394b88c807SRodney W. Grimesproceeding to the next one. 740ab72124fSSteve Price.Ss Short-Circuit List Operators 74149e11e3aSSheldon Hearn.Dq Li && 7426b15476eSSheldon Hearnand 74349e11e3aSSheldon Hearn.Dq Li || 7446b15476eSSheldon Hearnare AND-OR list operators. 74549e11e3aSSheldon Hearn.Dq Li && 7466b15476eSSheldon Hearnexecutes the first command, and then executes the second command 7476b15476eSSheldon Hearnif the exit status of the first command is zero. 74849e11e3aSSheldon Hearn.Dq Li || 749120ac26dSMasafumi Max NAKANEis similar, but executes the second command if the exit 7506b15476eSSheldon Hearnstatus of the first command is nonzero. 75149e11e3aSSheldon Hearn.Dq Li && 7526b15476eSSheldon Hearnand 75349e11e3aSSheldon Hearn.Dq Li || 7544b88c807SRodney W. Grimesboth have the same priority. 75549e11e3aSSheldon Hearn.Ss Flow-Control Constructs (if, while, for, case) 75649e11e3aSSheldon HearnThe syntax of the 75749e11e3aSSheldon Hearn.Ic if 75849e11e3aSSheldon Hearncommand is: 75949e11e3aSSheldon Hearn.\" 76049e11e3aSSheldon Hearn.\" XXX Use .Dl to work around broken handling of .Ic inside .Bd and .Ed . 76149e11e3aSSheldon Hearn.\" 76249e11e3aSSheldon Hearn.Dl Ic if Ar list 76349e11e3aSSheldon Hearn.Dl Ic then Ar list 76449e11e3aSSheldon Hearn.Dl [ Ic elif Ar list 76549e11e3aSSheldon Hearn.Dl Ic then Ar list ] ... 76649e11e3aSSheldon Hearn.Dl [ Ic else Ar list ] 76749e11e3aSSheldon Hearn.Dl Ic fi 768ab72124fSSteve Price.Pp 76949e11e3aSSheldon HearnThe syntax of the 77049e11e3aSSheldon Hearn.Ic while 77149e11e3aSSheldon Hearncommand is: 77249e11e3aSSheldon Hearn.Dl Ic while Ar list 77349e11e3aSSheldon Hearn.Dl Ic do Ar list 77449e11e3aSSheldon Hearn.Dl Ic done 775ab72124fSSteve Price.Pp 776ab0a2172SSteve PriceThe two lists are executed repeatedly while the exit status of the 77749e11e3aSSheldon Hearnfirst list is zero. 77849e11e3aSSheldon HearnThe 77949e11e3aSSheldon Hearn.Ic until 78049e11e3aSSheldon Hearncommand is similar, but has the word 78149e11e3aSSheldon Hearn.Ic until 78249e11e3aSSheldon Hearnin place of 78349e11e3aSSheldon Hearn.Ic while , 78449e11e3aSSheldon Hearnwhich causes it to 7854b88c807SRodney W. Grimesrepeat until the exit status of the first list is zero. 786ab72124fSSteve Price.Pp 78749e11e3aSSheldon HearnThe syntax of the 78849e11e3aSSheldon Hearn.Ic for 78949e11e3aSSheldon Hearncommand is: 79049e11e3aSSheldon Hearn.Dl Ic for Ar variable Ic in Ar word ... 79149e11e3aSSheldon Hearn.Dl Ic do Ar list 79249e11e3aSSheldon Hearn.Dl Ic done 793ab72124fSSteve Price.Pp 7944b88c807SRodney W. GrimesThe words are expanded, and then the list is executed 79549e11e3aSSheldon Hearnrepeatedly with the variable set to each word in turn. 79649e11e3aSSheldon HearnThe 79749e11e3aSSheldon Hearn.Ic do 7986b15476eSSheldon Hearnand 79949e11e3aSSheldon Hearn.Ic done 80049e11e3aSSheldon Hearncommands may be replaced with 80149e11e3aSSheldon Hearn.Dq Li { 80249e11e3aSSheldon Hearnand 80349e11e3aSSheldon Hearn.Dq Li } . 804ab72124fSSteve Price.Pp 80549e11e3aSSheldon HearnThe syntax of the 80649e11e3aSSheldon Hearn.Ic break 80749e11e3aSSheldon Hearnand 80849e11e3aSSheldon Hearn.Ic continue 80949e11e3aSSheldon Hearncommands is: 81049e11e3aSSheldon Hearn.Dl Ic break Op Ar num 81149e11e3aSSheldon Hearn.Dl Ic continue Op Ar num 812ab72124fSSteve Price.Pp 81349e11e3aSSheldon HearnThe 81449e11e3aSSheldon Hearn.Ic break 81549e11e3aSSheldon Hearncommand terminates the 81649e11e3aSSheldon Hearn.Ar num 81749e11e3aSSheldon Hearninnermost 81849e11e3aSSheldon Hearn.Ic for 81949e11e3aSSheldon Hearnor 82049e11e3aSSheldon Hearn.Ic while 82149e11e3aSSheldon Hearnloops. 82249e11e3aSSheldon HearnThe 82349e11e3aSSheldon Hearn.Ic continue 82449e11e3aSSheldon Hearncommand continues with the next iteration of the innermost loop. 8258eed22b1SJens SchweikhardtThese are implemented as built-in commands. 826ab72124fSSteve Price.Pp 82749e11e3aSSheldon HearnThe syntax of the 82849e11e3aSSheldon Hearn.Ic case 82949e11e3aSSheldon Hearncommand is 83049e11e3aSSheldon Hearn.Dl Ic case Ar word Ic in 83149e11e3aSSheldon Hearn.Dl pattern) list ;; 83249e11e3aSSheldon Hearn.Dl ... 83349e11e3aSSheldon Hearn.Dl Ic esac 834ab72124fSSteve Price.Pp 83549e11e3aSSheldon HearnThe pattern can actually be one or more patterns 83649e11e3aSSheldon Hearn(see 83749e11e3aSSheldon Hearn.Sx Shell Patterns 83849e11e3aSSheldon Hearndescribed later), 83949e11e3aSSheldon Hearnseparated by 84067135607SMartin Cracauer.Dq Li \&| 8416b15476eSSheldon Hearncharacters. 842ab72124fSSteve Price.Ss Grouping Commands Together 8434b88c807SRodney W. GrimesCommands may be grouped by writing either 844ab72124fSSteve Price.Bd -literal -offset indent 8454b88c807SRodney W. Grimes(list) 846ab72124fSSteve Price.Ed 847ab72124fSSteve Price.Pp 8484b88c807SRodney W. Grimesor 849ab72124fSSteve Price.Bd -literal -offset indent 8504b88c807SRodney W. Grimes{ list; } 851ab72124fSSteve Price.Ed 852ab72124fSSteve Price.Pp 85349e11e3aSSheldon HearnThe first form executes the commands in a subshell. 8548eed22b1SJens SchweikhardtNote that built-in commands thus executed do not affect the current shell. 85549e11e3aSSheldon HearnThe second form does not fork another shell, 85649e11e3aSSheldon Hearnso it is slightly more efficient. 85749e11e3aSSheldon HearnGrouping commands together this way allows the user to 858ab0a2172SSteve Priceredirect their output as though they were one program: 859ab72124fSSteve Price.Bd -literal -offset indent 860ee7dc416SSteve Price{ echo -n "hello"; echo " world"; } > greeting 861ab72124fSSteve Price.Ed 862ab72124fSSteve Price.Ss Functions 8634b88c807SRodney W. GrimesThe syntax of a function definition is 864ab72124fSSteve Price.Bd -literal -offset indent 8654b88c807SRodney W. Grimesname ( ) command 866ab72124fSSteve Price.Ed 867ab72124fSSteve Price.Pp 8684b88c807SRodney W. GrimesA function definition is an executable statement; when 8694b88c807SRodney W. Grimesexecuted it installs a function named name and returns an 870eccea571SRuslan Ermilovexit status of zero. 871eccea571SRuslan ErmilovThe command is normally a list 8726b15476eSSheldon Hearnenclosed between 87349e11e3aSSheldon Hearn.Dq Li { 8746b15476eSSheldon Hearnand 87549e11e3aSSheldon Hearn.Dq Li } . 876ab72124fSSteve Price.Pp 8774b88c807SRodney W. GrimesVariables may be declared to be local to a function by 87849e11e3aSSheldon Hearnusing the 87949e11e3aSSheldon Hearn.Ic local 88049e11e3aSSheldon Hearncommand. 88149e11e3aSSheldon HearnThis should appear as the first statement of a function, 88249e11e3aSSheldon Hearnand the syntax is: 88349e11e3aSSheldon Hearn.Bd -ragged -offset indent 88449e11e3aSSheldon Hearn.Ic local 88581e9cda2SRuslan Ermilov.Op Ar variable ... 88649e11e3aSSheldon Hearn.Op Ar - 887ab72124fSSteve Price.Ed 888ab72124fSSteve Price.Pp 88949e11e3aSSheldon HearnThe 89049e11e3aSSheldon Hearn.Ic local 8918eed22b1SJens Schweikhardtcommand is implemented as a built-in command. 892ab72124fSSteve Price.Pp 8934b88c807SRodney W. GrimesWhen a variable is made local, it inherits the initial 8944b88c807SRodney W. Grimesvalue and exported and readonly flags from the variable 8954b88c807SRodney W. Grimeswith the same name in the surrounding scope, if there is 896eccea571SRuslan Ermilovone. 897eccea571SRuslan ErmilovOtherwise, the variable is initially unset. 898eccea571SRuslan ErmilovThe shell 899e918fc8fSSheldon Hearnuses dynamic scoping, so that if the variable 900e918fc8fSSheldon Hearn.Em x 901e918fc8fSSheldon Hearnis made local to function 902e918fc8fSSheldon Hearn.Em f , 903e918fc8fSSheldon Hearnwhich then calls function 904e918fc8fSSheldon Hearn.Em g , 905e918fc8fSSheldon Hearnreferences to the variable 906e918fc8fSSheldon Hearn.Em x 907e918fc8fSSheldon Hearnmade inside 908e918fc8fSSheldon Hearn.Em g 909e918fc8fSSheldon Hearnwill refer to the variable 910e918fc8fSSheldon Hearn.Em x 911e918fc8fSSheldon Hearndeclared inside 912e918fc8fSSheldon Hearn.Em f , 913e918fc8fSSheldon Hearnnot to the global variable named 914e918fc8fSSheldon Hearn.Em x . 915ab72124fSSteve Price.Pp 9166b4bbd8aSCeri DaviesThe only special parameter that can be made local is 91749e11e3aSSheldon Hearn.Dq Li - . 9186b15476eSSheldon HearnMaking 91949e11e3aSSheldon Hearn.Dq Li - 9206b15476eSSheldon Hearnlocal causes any shell options that are 9214b88c807SRodney W. Grimeschanged via the set command inside the function to be 9224b88c807SRodney W. Grimesrestored to their original values when the function 9234b88c807SRodney W. Grimesreturns. 924ab72124fSSteve Price.Pp 92549e11e3aSSheldon HearnThe syntax of the 92649e11e3aSSheldon Hearn.Ic return 92749e11e3aSSheldon Hearncommand is 92849e11e3aSSheldon Hearn.Bd -ragged -offset indent 92949e11e3aSSheldon Hearn.Ic return 93049e11e3aSSheldon Hearn.Op Ar exitstatus 931ab72124fSSteve Price.Ed 932ab72124fSSteve Price.Pp 9334ad8968aSBrian FeldmanIt terminates the current executional scope, returning from the previous 9344ad8968aSBrian Feldmannested function, sourced script, or shell instance, in that order. 93549e11e3aSSheldon HearnThe 93649e11e3aSSheldon Hearn.Ic return 9378eed22b1SJens Schweikhardtcommand is implemented as a built-in command. 938ab72124fSSteve Price.Ss Variables and Parameters 939eccea571SRuslan ErmilovThe shell maintains a set of parameters. 940eccea571SRuslan ErmilovA parameter 941eccea571SRuslan Ermilovdenoted by a name is called a variable. 942eccea571SRuslan ErmilovWhen starting up, 9434b88c807SRodney W. Grimesthe shell turns all the environment variables into shell 944eccea571SRuslan Ermilovvariables. 945eccea571SRuslan ErmilovNew variables can be set using the form 946ab72124fSSteve Price.Bd -literal -offset indent 9474b88c807SRodney W. Grimesname=value 948ab72124fSSteve Price.Ed 949ab72124fSSteve Price.Pp 9504b88c807SRodney W. GrimesVariables set by the user must have a name consisting solely 95149e11e3aSSheldon Hearnof alphabetics, numerics, and underscores. 95249e11e3aSSheldon HearnThe first letter of a variable name must not be numeric. 95349e11e3aSSheldon HearnA parameter can also be denoted by a number 9544b88c807SRodney W. Grimesor a special character as explained below. 955ab72124fSSteve Price.Ss Positional Parameters 95649e11e3aSSheldon HearnA positional parameter is a parameter denoted by a number greater than zero. 957ab72124fSSteve PriceThe shell sets these initially to the values of its command line 958eccea571SRuslan Ermilovarguments that follow the name of the shell script. 959eccea571SRuslan ErmilovThe 960c644db6aSSheldon Hearn.Ic set 9618eed22b1SJens Schweikhardtbuilt-in command can also be used to set or reset them. 962ab72124fSSteve Price.Ss Special Parameters 96343d6677bSAlfred PerlsteinA special parameter is a parameter denoted by a special one-character 96443d6677bSAlfred Perlsteinname. 96543d6677bSAlfred PerlsteinThe special parameters recognized by the 96643d6677bSAlfred Perlstein.Nm 96743d6677bSAlfred Perlsteinshell of 96843d6677bSAlfred Perlstein.Fx 96943d6677bSAlfred Perlsteinare shown in the following list, exactly as they would appear in input 97043d6677bSAlfred Perlsteintyped by the user or in the source of a shell script. 971ab72124fSSteve Price.Bl -hang 97243d6677bSAlfred Perlstein.It Li $* 973eccea571SRuslan ErmilovExpands to the positional parameters, starting from one. 974eccea571SRuslan ErmilovWhen 9754b88c807SRodney W. Grimesthe expansion occurs within a double-quoted string 9764b88c807SRodney W. Grimesit expands to a single field with the value of each parameter 97749e11e3aSSheldon Hearnseparated by the first character of the 97849e11e3aSSheldon Hearn.Ev IFS 97949e11e3aSSheldon Hearnvariable, 98049e11e3aSSheldon Hearnor by a 98149e11e3aSSheldon Hearn.Aq space 98249e11e3aSSheldon Hearnif 98349e11e3aSSheldon Hearn.Ev IFS 98449e11e3aSSheldon Hearnis unset. 98543d6677bSAlfred Perlstein.It Li $@ 986eccea571SRuslan ErmilovExpands to the positional parameters, starting from one. 987eccea571SRuslan ErmilovWhen 9884b88c807SRodney W. Grimesthe expansion occurs within double-quotes, each positional 9894b88c807SRodney W. Grimesparameter expands as a separate argument. 9904b88c807SRodney W. GrimesIf there are no positional parameters, the 991e918fc8fSSheldon Hearnexpansion of 992e918fc8fSSheldon Hearn.Li @ 993e918fc8fSSheldon Hearngenerates zero arguments, even when 994e918fc8fSSheldon Hearn.Li @ 995eccea571SRuslan Ermilovis double-quoted. 996eccea571SRuslan ErmilovWhat this basically means, for example, is 9976b15476eSSheldon Hearnif $1 is 9986b15476eSSheldon Hearn.Dq abc 9996b15476eSSheldon Hearnand $2 is 10006b15476eSSheldon Hearn.Dq def ghi , 10016b15476eSSheldon Hearnthen 1002e918fc8fSSheldon Hearn.Qq Li $@ 10036b15476eSSheldon Hearnexpands to 10044b88c807SRodney W. Grimesthe two arguments: 1005ab72124fSSteve Price.Bd -literal -offset indent 10064b88c807SRodney W. Grimes"abc" "def ghi" 1007ab72124fSSteve Price.Ed 100843d6677bSAlfred Perlstein.It Li $# 10094b88c807SRodney W. GrimesExpands to the number of positional parameters. 101043d6677bSAlfred Perlstein.It Li $\&? 10114b88c807SRodney W. GrimesExpands to the exit status of the most recent pipeline. 101243d6677bSAlfred Perlstein.It Li $- 1013ab72124fSSteve Price(hyphen) Expands to the current option flags (the single-letter 10144b88c807SRodney W. Grimesoption names concatenated into a string) as specified on 10158eed22b1SJens Schweikhardtinvocation, by the set built-in command, or implicitly 10164b88c807SRodney W. Grimesby the shell. 101743d6677bSAlfred Perlstein.It Li $$ 1018eccea571SRuslan ErmilovExpands to the process ID of the invoked shell. 1019eccea571SRuslan ErmilovA subshell 10204b88c807SRodney W. Grimesretains the same value of $ as its parent. 102143d6677bSAlfred Perlstein.It Li $\&! 10224b88c807SRodney W. GrimesExpands to the process ID of the most recent background 1023eccea571SRuslan Ermilovcommand executed from the current shell. 1024eccea571SRuslan ErmilovFor a 10254b88c807SRodney W. Grimespipeline, the process ID is that of the last command in the 10264b88c807SRodney W. Grimespipeline. 102743d6677bSAlfred Perlstein.It Li $0 1028ab72124fSSteve Price(zero) Expands to the name of the shell or shell script. 1029ab72124fSSteve Price.El 1030ab72124fSSteve Price.Ss Word Expansions 10314b88c807SRodney W. GrimesThis clause describes the various expansions that are 1032eccea571SRuslan Ermilovperformed on words. 1033eccea571SRuslan ErmilovNot all expansions are performed on 10344b88c807SRodney W. Grimesevery word, as explained later. 1035ab72124fSSteve Price.Pp 10364b88c807SRodney W. GrimesTilde expansions, parameter expansions, command substitutions, 10374b88c807SRodney W. Grimesarithmetic expansions, and quote removals that occur within 1038eccea571SRuslan Ermilova single word expand to a single field. 1039eccea571SRuslan ErmilovIt is only field 10404b88c807SRodney W. Grimessplitting or pathname expansion that can create multiple 1041e6d3cf26SSheldon Hearnfields from a single word. 1042e6d3cf26SSheldon HearnThe single exception to this rule is 1043e918fc8fSSheldon Hearnthe expansion of the special parameter 1044e918fc8fSSheldon Hearn.Li @ 1045e918fc8fSSheldon Hearnwithin double-quotes, 1046e6d3cf26SSheldon Hearnas was described above. 1047ab72124fSSteve Price.Pp 10484b88c807SRodney W. GrimesThe order of word expansion is: 1049ab72124fSSteve Price.Bl -enum 1050ab72124fSSteve Price.It 1051ab72124fSSteve PriceTilde Expansion, Parameter Expansion, Command Substitution, 10524b88c807SRodney W. GrimesArithmetic Expansion (these all occur at the same time). 1053ab72124fSSteve Price.It 105449e11e3aSSheldon HearnField Splitting is performed on fields generated by step (1) 105549e11e3aSSheldon Hearnunless the 105649e11e3aSSheldon Hearn.Ev IFS 105749e11e3aSSheldon Hearnvariable is null. 1058ab72124fSSteve Price.It 105949e11e3aSSheldon HearnPathname Expansion (unless the 106049e11e3aSSheldon Hearn.Fl f 106149e11e3aSSheldon Hearnoption is in effect). 1062ab72124fSSteve Price.It 1063ab72124fSSteve PriceQuote Removal. 1064ab72124fSSteve Price.El 1065ab72124fSSteve Price.Pp 106649e11e3aSSheldon HearnThe 106749e11e3aSSheldon Hearn.Dq Li $ 106849e11e3aSSheldon Hearncharacter is used to introduce parameter expansion, command 10694b88c807SRodney W. Grimessubstitution, or arithmetic evaluation. 1070ab72124fSSteve Price.Ss Tilde Expansion (substituting a user's home directory) 107149e11e3aSSheldon HearnA word beginning with an unquoted tilde character 1072a762afe5SGiorgos Keramidas.Pq Ql ~ 107349e11e3aSSheldon Hearnis 107449e11e3aSSheldon Hearnsubjected to tilde expansion. 107549e11e3aSSheldon HearnAll the characters up to a slash 1076a762afe5SGiorgos Keramidas.Pq Ql / 107749e11e3aSSheldon Hearnor the end of the word are treated as a username 1078eccea571SRuslan Ermilovand are replaced with the user's home directory. 1079eccea571SRuslan ErmilovIf the 10804b88c807SRodney W. Grimesusername is missing (as in ~/foobar), the tilde is replaced 10814b88c807SRodney W. Grimeswith the value of the HOME variable (the current user's 10824b88c807SRodney W. Grimeshome directory). 1083ab72124fSSteve Price.Ss Parameter Expansion 10844b88c807SRodney W. GrimesThe format for parameter expansion is as follows: 1085ab72124fSSteve Price.Bd -literal -offset indent 10864b88c807SRodney W. Grimes${expression} 1087ab72124fSSteve Price.Ed 1088ab72124fSSteve Price.Pp 108949e11e3aSSheldon Hearnwhere expression consists of all characters until the matching 109049e11e3aSSheldon Hearn.Dq Li } . 109149e11e3aSSheldon HearnAny 109249e11e3aSSheldon Hearn.Dq Li } 10934b88c807SRodney W. Grimesescaped by a backslash or within a quoted string, and characters in 10944b88c807SRodney W. Grimesembedded arithmetic expansions, command substitutions, and variable 109549e11e3aSSheldon Hearnexpansions, are not examined in determining the matching 109649e11e3aSSheldon Hearn.Dq Li } . 1097ab72124fSSteve Price.Pp 10984b88c807SRodney W. GrimesThe simplest form for parameter expansion is: 1099ab72124fSSteve Price.Bd -literal -offset indent 11004b88c807SRodney W. Grimes${parameter} 1101ab72124fSSteve Price.Ed 1102ab72124fSSteve Price.Pp 11034b88c807SRodney W. GrimesThe value, if any, of parameter is substituted. 1104ab72124fSSteve Price.Pp 11054b88c807SRodney W. GrimesThe parameter name or symbol can be enclosed in braces, which are 11064b88c807SRodney W. Grimesoptional except for positional parameters with more than one digit or 11074b88c807SRodney W. Grimeswhen parameter is followed by a character that could be interpreted as 11084b88c807SRodney W. Grimespart of the name. 1109ab72124fSSteve PriceIf a parameter expansion occurs inside double-quotes: 1110ab72124fSSteve Price.Bl -enum 1111ab72124fSSteve Price.It 1112ab72124fSSteve PricePathname expansion is not performed on the results of the 11134b88c807SRodney W. Grimesexpansion. 1114ab72124fSSteve Price.It 1115ab72124fSSteve PriceField splitting is not performed on the results of the 1116e918fc8fSSheldon Hearnexpansion, with the exception of the special parameter 1117e918fc8fSSheldon Hearn.Li @ . 1118ab72124fSSteve Price.El 1119ab72124fSSteve Price.Pp 11204b88c807SRodney W. GrimesIn addition, a parameter expansion can be modified by using one of the 11214b88c807SRodney W. Grimesfollowing formats. 112281e9cda2SRuslan Ermilov.Bl -tag -width indent 1123ab72124fSSteve Price.It Li ${parameter:-word} 1124eccea571SRuslan ErmilovUse Default Values. 1125eccea571SRuslan ErmilovIf parameter is unset or 11264b88c807SRodney W. Grimesnull, the expansion of word is 11274b88c807SRodney W. Grimessubstituted; otherwise, the value of 11284b88c807SRodney W. Grimesparameter is substituted. 1129ab72124fSSteve Price.It Li ${parameter:=word} 1130eccea571SRuslan ErmilovAssign Default Values. 1131eccea571SRuslan ErmilovIf parameter is unset 11324b88c807SRodney W. Grimesor null, the expansion of word is 1133eccea571SRuslan Ermilovassigned to parameter. 1134eccea571SRuslan ErmilovIn all cases, the 11354b88c807SRodney W. Grimesfinal value of parameter is 1136eccea571SRuslan Ermilovsubstituted. 1137eccea571SRuslan ErmilovOnly variables, not positional 11384b88c807SRodney W. Grimesparameters or special parameters, can be 11394b88c807SRodney W. Grimesassigned in this way. 1140ab72124fSSteve Price.It Li ${parameter:?[word]} 1141eccea571SRuslan ErmilovIndicate Error if Null or Unset. 1142eccea571SRuslan ErmilovIf 11434b88c807SRodney W. Grimesparameter is unset or null, the expansion of 11444b88c807SRodney W. Grimesword (or a message indicating it is unset if 11454b88c807SRodney W. Grimesword is omitted) is written to standard 11464b88c807SRodney W. Grimeserror and the shell exits with a nonzero 1147e6d3cf26SSheldon Hearnexit status. 1148e6d3cf26SSheldon HearnOtherwise, the value of 1149eccea571SRuslan Ermilovparameter is substituted. 1150eccea571SRuslan ErmilovAn 11514b88c807SRodney W. Grimesinteractive shell need not exit. 1152ab72124fSSteve Price.It Li ${parameter:+word} 1153eccea571SRuslan ErmilovUse Alternate Value. 1154eccea571SRuslan ErmilovIf parameter is unset 11554b88c807SRodney W. Grimesor null, null is substituted; 11564b88c807SRodney W. Grimesotherwise, the expansion of word is 11574b88c807SRodney W. Grimessubstituted. 11581413f7deSTony Finch.El 1159ab72124fSSteve Price.Pp 11604b88c807SRodney W. GrimesIn the parameter expansions shown previously, use of the colon in the 11614b88c807SRodney W. Grimesformat results in a test for a parameter that is unset or null; omission 11624b88c807SRodney W. Grimesof the colon results in a test for a parameter that is only unset. 11631413f7deSTony Finch.Bl -tag -width indent 1164ab72124fSSteve Price.It Li ${#parameter} 1165eccea571SRuslan ErmilovString Length. 1166eccea571SRuslan ErmilovThe length in characters of 11674b88c807SRodney W. Grimesthe value of parameter. 116871337c33SSheldon Hearn.El 1169ab72124fSSteve Price.Pp 11704b88c807SRodney W. GrimesThe following four varieties of parameter expansion provide for substring 117149e11e3aSSheldon Hearnprocessing. 117249e11e3aSSheldon HearnIn each case, pattern matching notation 117349e11e3aSSheldon Hearn(see 117449e11e3aSSheldon Hearn.Sx Shell Patterns ) , 117549e11e3aSSheldon Hearnrather than regular expression notation, 117649e11e3aSSheldon Hearnis used to evaluate the patterns. 1177e918fc8fSSheldon HearnIf parameter is one of the special parameters 1178e918fc8fSSheldon Hearn.Li * 117949e11e3aSSheldon Hearnor 1180e918fc8fSSheldon Hearn.Li @ , 118149e11e3aSSheldon Hearnthe result of the expansion is unspecified. 11824b88c807SRodney W. GrimesEnclosing the full parameter expansion string in double-quotes does not 11834b88c807SRodney W. Grimescause the following four varieties of pattern characters to be quoted, 11844b88c807SRodney W. Grimeswhereas quoting characters within the braces has this effect. 118581e9cda2SRuslan Ermilov.Bl -tag -width indent 1186ab72124fSSteve Price.It Li ${parameter%word} 1187eccea571SRuslan ErmilovRemove Smallest Suffix Pattern. 1188eccea571SRuslan ErmilovThe word 1189eccea571SRuslan Ermilovis expanded to produce a pattern. 1190eccea571SRuslan ErmilovThe 11914b88c807SRodney W. Grimesparameter expansion then results in 11924b88c807SRodney W. Grimesparameter, with the smallest portion of the 11934b88c807SRodney W. Grimessuffix matched by the pattern deleted. 1194ab72124fSSteve Price.It Li ${parameter%%word} 1195eccea571SRuslan ErmilovRemove Largest Suffix Pattern. 1196eccea571SRuslan ErmilovThe word 1197eccea571SRuslan Ermilovis expanded to produce a pattern. 1198eccea571SRuslan ErmilovThe 11994b88c807SRodney W. Grimesparameter expansion then results in 12004b88c807SRodney W. Grimesparameter, with the largest portion of the 12014b88c807SRodney W. Grimessuffix matched by the pattern deleted. 1202ab72124fSSteve Price.It Li ${parameter#word} 1203eccea571SRuslan ErmilovRemove Smallest Prefix Pattern. 1204eccea571SRuslan ErmilovThe word 1205eccea571SRuslan Ermilovis expanded to produce a pattern. 1206eccea571SRuslan ErmilovThe 12074b88c807SRodney W. Grimesparameter expansion then results in 12084b88c807SRodney W. Grimesparameter, with the smallest portion of the 12094b88c807SRodney W. Grimesprefix matched by the pattern deleted. 1210ab72124fSSteve Price.It Li ${parameter##word} 1211eccea571SRuslan ErmilovRemove Largest Prefix Pattern. 1212eccea571SRuslan ErmilovThe word 1213eccea571SRuslan Ermilovis expanded to produce a pattern. 1214eccea571SRuslan ErmilovThe 12154b88c807SRodney W. Grimesparameter expansion then results in 12164b88c807SRodney W. Grimesparameter, with the largest portion of the 12174b88c807SRodney W. Grimesprefix matched by the pattern deleted. 1218ab72124fSSteve Price.El 1219ab72124fSSteve Price.Ss Command Substitution 12204b88c807SRodney W. GrimesCommand substitution allows the output of a command to be substituted in 1221eccea571SRuslan Ermilovplace of the command name itself. 1222eccea571SRuslan ErmilovCommand substitution occurs when 12234b88c807SRodney W. Grimesthe command is enclosed as follows: 1224ab72124fSSteve Price.Bd -literal -offset indent 12254b88c807SRodney W. Grimes$(command) 1226ab72124fSSteve Price.Ed 1227ab72124fSSteve Price.Pp 122849e11e3aSSheldon Hearnor the backquoted version: 1229ab72124fSSteve Price.Bd -literal -offset indent 12304b88c807SRodney W. Grimes`command` 1231ab72124fSSteve Price.Ed 1232ab72124fSSteve Price.Pp 12334b88c807SRodney W. GrimesThe shell expands the command substitution by executing command in a 12344b88c807SRodney W. Grimessubshell environment and replacing the command substitution 123549e11e3aSSheldon Hearnwith the standard output of the command, 123649e11e3aSSheldon Hearnremoving sequences of one or more newlines at the end of the substitution. 123749e11e3aSSheldon HearnEmbedded newlines before the end of the output are not removed; 123849e11e3aSSheldon Hearnhowever, during field splitting, they may be translated into spaces 123949e11e3aSSheldon Hearndepending on the value of 124049e11e3aSSheldon Hearn.Ev IFS 124149e11e3aSSheldon Hearnand the quoting that is in effect. 1242ab72124fSSteve Price.Ss Arithmetic Expansion 12434b88c807SRodney W. GrimesArithmetic expansion provides a mechanism for evaluating an arithmetic 1244e6d3cf26SSheldon Hearnexpression and substituting its value. 1245e6d3cf26SSheldon HearnThe format for arithmetic expansion is as follows: 1246ab72124fSSteve Price.Bd -literal -offset indent 12474b88c807SRodney W. Grimes$((expression)) 1248ab72124fSSteve Price.Ed 1249ab72124fSSteve Price.Pp 12504b88c807SRodney W. GrimesThe expression is treated as if it were in double-quotes, except 1251eccea571SRuslan Ermilovthat a double-quote inside the expression is not treated specially. 1252eccea571SRuslan ErmilovThe 12534b88c807SRodney W. Grimesshell expands all tokens in the expression for parameter expansion, 12544b88c807SRodney W. Grimescommand substitution, and quote removal. 1255ab72124fSSteve Price.Pp 12564b88c807SRodney W. GrimesNext, the shell treats this as an arithmetic expression and 12574b88c807SRodney W. Grimessubstitutes the value of the expression. 1258ab72124fSSteve Price.Ss White Space Splitting (Field Splitting) 12594b88c807SRodney W. GrimesAfter parameter expansion, command substitution, and 12604b88c807SRodney W. Grimesarithmetic expansion the shell scans the results of 12614b88c807SRodney W. Grimesexpansions and substitutions that did not occur in double-quotes for 12624b88c807SRodney W. Grimesfield splitting and multiple fields can result. 1263ab72124fSSteve Price.Pp 126449e11e3aSSheldon HearnThe shell treats each character of the 126549e11e3aSSheldon Hearn.Ev IFS 126649e11e3aSSheldon Hearnas a delimiter and uses 12674b88c807SRodney W. Grimesthe delimiters to split the results of parameter expansion and command 12684b88c807SRodney W. Grimessubstitution into fields. 1269ab72124fSSteve Price.Ss Pathname Expansion (File Name Generation) 127049e11e3aSSheldon HearnUnless the 127149e11e3aSSheldon Hearn.Fl f 127249e11e3aSSheldon Hearnoption is set, 127349e11e3aSSheldon Hearnfile name generation is performed 1274eccea571SRuslan Ermilovafter word splitting is complete. 1275eccea571SRuslan ErmilovEach word is 1276eccea571SRuslan Ermilovviewed as a series of patterns, separated by slashes. 1277eccea571SRuslan ErmilovThe 12784b88c807SRodney W. Grimesprocess of expansion replaces the word with the names of 12794b88c807SRodney W. Grimesall existing files whose names can be formed by replacing 12804b88c807SRodney W. Grimeseach pattern with a string that matches the specified pattern. 1281ab0a2172SSteve PriceThere are two restrictions on this: first, a pattern cannot match 1282ab0a2172SSteve Pricea string containing a slash, and second, 12834b88c807SRodney W. Grimesa pattern cannot match a string starting with a period 12844b88c807SRodney W. Grimesunless the first character of the pattern is a period. 12854b88c807SRodney W. GrimesThe next section describes the patterns used for both 1286ab72124fSSteve PricePathname Expansion and the 1287c644db6aSSheldon Hearn.Ic case 1288ab72124fSSteve Pricecommand. 1289ab72124fSSteve Price.Ss Shell Patterns 1290f434d1dfSAdam DavidA pattern consists of normal characters, which match themselves, 129149e11e3aSSheldon Hearnand meta-characters. 129249e11e3aSSheldon HearnThe meta-characters are 12931586940eSRuslan Ermilov.Dq Li \&! , 129449e11e3aSSheldon Hearn.Dq Li * , 12951586940eSRuslan Ermilov.Dq Li \&? , 12966b15476eSSheldon Hearnand 129749e11e3aSSheldon Hearn.Dq Li [ . 12986b15476eSSheldon HearnThese characters lose their special meanings if they are quoted. 12996b15476eSSheldon HearnWhen command or variable substitution is performed and the dollar sign 13006b15476eSSheldon Hearnor back quotes are not double-quoted, the value of the 13014b88c807SRodney W. Grimesvariable or the output of the command is scanned for these 13024b88c807SRodney W. Grimescharacters and they are turned into meta-characters. 1303ab72124fSSteve Price.Pp 13046b15476eSSheldon HearnAn asterisk 1305a762afe5SGiorgos Keramidas.Pq Ql * 1306e918fc8fSSheldon Hearnmatches any string of characters. 1307e918fc8fSSheldon HearnA question mark 1308a762afe5SGiorgos Keramidas.Pq Ql \&? 1309e918fc8fSSheldon Hearnmatches any single character. 1310e6d3cf26SSheldon HearnA left bracket 1311a762afe5SGiorgos Keramidas.Pq Ql [ 1312e6d3cf26SSheldon Hearnintroduces a character class. 1313e6d3cf26SSheldon HearnThe end of the character class is indicated by a 131449e11e3aSSheldon Hearn.Dq Li \&] ; 13156b15476eSSheldon Hearnif the 131649e11e3aSSheldon Hearn.Dq Li \&] 13176b15476eSSheldon Hearnis missing then the 131849e11e3aSSheldon Hearn.Dq Li [ 13196b15476eSSheldon Hearnmatches a 132049e11e3aSSheldon Hearn.Dq Li [ 1321e6d3cf26SSheldon Hearnrather than introducing a character class. 1322e6d3cf26SSheldon HearnA character class matches any of the characters between the square brackets. 1323e6d3cf26SSheldon HearnA range of characters may be specified using a minus sign. 1324e918fc8fSSheldon HearnThe character class may be complemented by making an exclamation point 1325a762afe5SGiorgos Keramidas.Pq Ql !\& 1326e918fc8fSSheldon Hearnthe first character of the character class. 1327ab72124fSSteve Price.Pp 13286b15476eSSheldon HearnTo include a 132912e720d7SRuslan Ermilov.Dq Li \&] 1330e6d3cf26SSheldon Hearnin a character class, make it the first character listed 1331e6d3cf26SSheldon Hearn(after the 13321586940eSRuslan Ermilov.Dq Li \&! , 1333e6d3cf26SSheldon Hearnif any). 1334e918fc8fSSheldon HearnTo include a 1335e918fc8fSSheldon Hearn.Dq Li - , 1336e918fc8fSSheldon Hearnmake it the first or last character listed. 13378eed22b1SJens Schweikhardt.Ss Built-in Commands 1338c644db6aSSheldon HearnThis section lists the commands which 13398eed22b1SJens Schweikhardtare built-in because they need to perform some operation 1340eccea571SRuslan Ermilovthat cannot be performed by a separate process. 1341eccea571SRuslan ErmilovIn addition to 13428eed22b1SJens Schweikhardtthese, a built-in version of the 1343d90c5c4aSAkinori MUSHA.Xr test 1 1344018d9f62SAkinori MUSHAcommand is provided for efficiency. 134581e9cda2SRuslan Ermilov.Bl -tag -width indent 1346d0353b83SRuslan Ermilov.It Ic \&: 1347aa9caaf6SPeter WemmA null command that returns a 0 (true) exit value. 1348d0353b83SRuslan Ermilov.It Ic \&. Ar file 1349aa9caaf6SPeter WemmThe commands in the specified file are read and executed by the shell. 13504ad8968aSBrian FeldmanThe 13514ad8968aSBrian Feldman.Ic return 13524ad8968aSBrian Feldmancommand may be used to return to the 13534ad8968aSBrian Feldman.Ic \&. 13544ad8968aSBrian Feldmancommand's caller. 13556466945aSJohn PolstraIf 13566466945aSJohn Polstra.Ar file 13576466945aSJohn Polstracontains any 135849e11e3aSSheldon Hearn.Dq / 1359eccea571SRuslan Ermilovcharacters, it is used as is. 1360eccea571SRuslan ErmilovOtherwise, the shell searches the 13616466945aSJohn Polstra.Ev PATH 1362eccea571SRuslan Ermilovfor the file. 1363eccea571SRuslan ErmilovIf it is not found in the 13646466945aSJohn Polstra.Ev PATH , 13656466945aSJohn Polstrait is sought in the current working directory. 1366a886288eSJesus R. Camou.It Ic alias Oo Ar name Ns Oo = Ns Ar string Oc ... Oc 136749e11e3aSSheldon HearnIf 1368d0353b83SRuslan Ermilov.Ar name Ns = Ns Ar string 136949e11e3aSSheldon Hearnis specified, the shell defines the alias 137049e11e3aSSheldon Hearn.Ar name 13716b15476eSSheldon Hearnwith value 137249e11e3aSSheldon Hearn.Ar string . 13736b15476eSSheldon HearnIf just 137449e11e3aSSheldon Hearn.Ar name 13756b15476eSSheldon Hearnis specified, the value of the alias 137649e11e3aSSheldon Hearn.Ar name 13776b15476eSSheldon Hearnis printed. 137849e11e3aSSheldon HearnWith no arguments, the 137949e11e3aSSheldon Hearn.Ic alias 13808eed22b1SJens Schweikhardtbuilt-in command prints the names and values of all defined aliases 138149e11e3aSSheldon Hearn(see 138249e11e3aSSheldon Hearn.Ic unalias ) . 1383e5341cbbSTim J. RobbinsAlias values are written with appropriate quoting so that they are 13849ba31ca0SRuslan Ermilovsuitable for re-input to the shell. 1385a886288eSJesus R. CamouAlso see the 1386a886288eSJesus R. Camou.Sx Aliases 1387a886288eSJesus R. Camousubsection. 138849e11e3aSSheldon Hearn.It Ic bg Op Ar job ... 138949e11e3aSSheldon HearnContinue the specified jobs 139049e11e3aSSheldon Hearn(or the current job if no jobs are given) 139149e11e3aSSheldon Hearnin the background. 1392df9e587bSTim J. Robbins.It Ic builtin Ar cmd Op Ar arg ... 13938eed22b1SJens SchweikhardtExecute the specified built-in command, 139449e11e3aSSheldon Hearn.Ar cmd . 139549e11e3aSSheldon HearnThis is useful when the user wishes to override a shell function 13968eed22b1SJens Schweikhardtwith the same name as a built-in command. 1397088acf90STim J. Robbins.It Ic bind Oo Fl aeklrsv Oc Oo Ar key Oo Ar command Oc Oc 1398088acf90STim J. RobbinsList or alter key bindings for the line editor. 1399088acf90STim J. RobbinsThis command is documented in 1400088acf90STim J. Robbins.Xr editrc 5 . 1401d74e011fSRuslan Ermilov.It Ic cd Oo Fl L | P Oc Op Ar directory 140249e11e3aSSheldon HearnSwitch to the specified 140349e11e3aSSheldon Hearn.Ar directory , 140449e11e3aSSheldon Hearnor to the directory specified in the 140549e11e3aSSheldon Hearn.Ev HOME 140649e11e3aSSheldon Hearnenvironment variable if no 140749e11e3aSSheldon Hearn.Ar directory 140849e11e3aSSheldon Hearnis specified. 140949e11e3aSSheldon HearnIf 141049e11e3aSSheldon Hearn.Ar directory 1411029c8ee4STim J. Robbinsdoes not begin with 14129ba31ca0SRuslan Ermilov.Pa / , \&. , 141349e11e3aSSheldon Hearnor 1414029c8ee4STim J. Robbins.Pa .. , 141549e11e3aSSheldon Hearnthen the directories listed in the 141649e11e3aSSheldon Hearn.Ev CDPATH 141749e11e3aSSheldon Hearnvariable will be 141849e11e3aSSheldon Hearnsearched for the specified 141949e11e3aSSheldon Hearn.Ar directory . 1420029c8ee4STim J. RobbinsIf 1421029c8ee4STim J. Robbins.Ev CDPATH 1422029c8ee4STim J. Robbinsis unset, the current directory is searched. 142349e11e3aSSheldon HearnThe format of 142449e11e3aSSheldon Hearn.Ar CDPATH 142549e11e3aSSheldon Hearnis the same as that of 142649e11e3aSSheldon Hearn.Ev PATH . 1427e6d3cf26SSheldon HearnIn an interactive shell, 142849e11e3aSSheldon Hearnthe 142949e11e3aSSheldon Hearn.Ic cd 143049e11e3aSSheldon Hearncommand will print out the name of the directory 1431e6d3cf26SSheldon Hearnthat it actually switched to 1432e6d3cf26SSheldon Hearnif this is different from the name that the user gave. 143349e11e3aSSheldon HearnThese may be different either because the 143449e11e3aSSheldon Hearn.Ev CDPATH 143549e11e3aSSheldon Hearnmechanism was used or because a symbolic link was crossed. 1436178897f1STim J. Robbins.Pp 1437178897f1STim J. RobbinsIf the 1438178897f1STim J. Robbins.Fl P 1439178897f1STim J. Robbinsoption is specified, 144081e9cda2SRuslan Ermilov.Pa .. 1441178897f1STim J. Robbinsis handled physically and symbolic links are resolved before 144281e9cda2SRuslan Ermilov.Pa .. 1443178897f1STim J. Robbinscomponents are processed. 1444178897f1STim J. RobbinsIf the 1445178897f1STim J. Robbins.Fl L 1446178897f1STim J. Robbinsoption is specified, 144781e9cda2SRuslan Ermilov.Pa .. 1448178897f1STim J. Robbinsis handled logically. 1449178897f1STim J. RobbinsThis is the default. 14509434a1c7SDima Dorfman.It Ic chdir 14519434a1c7SDima DorfmanA synonym for the 14529434a1c7SDima Dorfman.Ic cd 14538eed22b1SJens Schweikhardtbuilt-in command. 14549ba31ca0SRuslan Ermilov.It Ic command Oo Fl p Oc Op Ar utility Op Ar argument ... 14552babaf74STim J. RobbinsExecute the specified 14562babaf74STim J. Robbins.Ar utility 14572babaf74STim J. Robbinsas a simple command (see the 14582babaf74STim J. Robbins.Sx Simple Commands 14592babaf74STim J. Robbinssection). 14602babaf74STim J. Robbins.Pp 14612babaf74STim J. RobbinsIf the 14622babaf74STim J. Robbins.Fl p 14632babaf74STim J. Robbinsoption is specified, the command search is performed using a 14642babaf74STim J. Robbinsdefault value of 14652babaf74STim J. Robbins.Ev PATH 14662babaf74STim J. Robbinsthat is guaranteed to find all of the standard utilities. 14679ba31ca0SRuslan Ermilov.It Ic echo Oo Fl e | n Oc Op Ar string 1468501e74b7SMark OvensPrint 1469501e74b7SMark Ovens.Ar string 1470501e74b7SMark Ovensto the standard output with a newline appended. 147181e9cda2SRuslan Ermilov.Bl -tag -width indent 1472501e74b7SMark Ovens.It Fl n 1473501e74b7SMark OvensSuppress the output of the trailing newline. 1474501e74b7SMark Ovens.It Fl e 1475501e74b7SMark OvensProcess C-style backslash escape sequences. 1476501e74b7SMark Ovens.Ic echo 1477501e74b7SMark Ovensunderstands the following character escapes: 147881e9cda2SRuslan Ermilov.Bl -tag -width indent 1479501e74b7SMark Ovens.It \ea 1480501e74b7SMark OvensAlert (ring the terminal bell) 1481501e74b7SMark Ovens.It \eb 1482501e74b7SMark OvensBackspace 1483501e74b7SMark Ovens.It \ec 1484501e74b7SMark OvensSuppress the trailing newline (this has the side-effect of truncating the 1485501e74b7SMark Ovensline if it is not the last character) 1486501e74b7SMark Ovens.It \ee 1487501e74b7SMark OvensThe ESC character (ASCII 0x1b) 1488501e74b7SMark Ovens.It \ef 1489501e74b7SMark OvensFormfeed 1490501e74b7SMark Ovens.It \en 1491501e74b7SMark OvensNewline 1492501e74b7SMark Ovens.It \er 1493501e74b7SMark OvensCarriage return 1494501e74b7SMark Ovens.It \et 1495501e74b7SMark OvensHorizontal tab 1496501e74b7SMark Ovens.It \ev 1497501e74b7SMark OvensVertical tab 1498501e74b7SMark Ovens.It \e\e 1499501e74b7SMark OvensLiteral backslash 1500501e74b7SMark Ovens.It \e0nnn 1501501e74b7SMark Ovens(Zero) The character whose octal value is nnn 1502501e74b7SMark Ovens.El 1503501e74b7SMark Ovens.Pp 1504501e74b7SMark OvensIf 1505501e74b7SMark Ovens.Ar string 1506501e74b7SMark Ovensis not enclosed in quotes then the backslash itself must be escaped 1507eccea571SRuslan Ermilovwith a backslash to protect it from the shell. 1508eccea571SRuslan ErmilovFor example 1509501e74b7SMark Ovens.Bd -literal -offset indent 1510501e74b7SMark Ovens$ echo -e "a\evb" 1511501e74b7SMark Ovensa 1512501e74b7SMark Ovens b 1513501e74b7SMark Ovens$ echo -e a\e\evb 1514501e74b7SMark Ovensa 1515501e74b7SMark Ovens b 1516501e74b7SMark Ovens$ echo -e "a\e\eb" 1517501e74b7SMark Ovensa\eb 1518501e74b7SMark Ovens$ echo -e a\e\e\e\eb 1519501e74b7SMark Ovensa\eb 1520501e74b7SMark Ovens.Ed 1521501e74b7SMark Ovens.El 1522558175caSTim J. Robbins.Pp 1523558175caSTim J. RobbinsOnly one of the 1524558175caSTim J. Robbins.Fl e 1525558175caSTim J. Robbinsand 1526558175caSTim J. Robbins.Fl n 1527558175caSTim J. Robbinsoptions may be specified. 152849e11e3aSSheldon Hearn.It Ic eval Ar string ... 1529e6d3cf26SSheldon HearnConcatenate all the arguments with spaces. 1530e6d3cf26SSheldon HearnThen re-parse and execute the command. 153149e11e3aSSheldon Hearn.It Ic exec Op Ar command Op arg ... 153249e11e3aSSheldon HearnUnless 153349e11e3aSSheldon Hearn.Ar command 153449e11e3aSSheldon Hearnis omitted, 153549e11e3aSSheldon Hearnthe shell process is replaced with the specified program 15368eed22b1SJens Schweikhardt(which must be a real program, not a shell built-in command or function). 153749e11e3aSSheldon HearnAny redirections on the 153849e11e3aSSheldon Hearn.Ic exec 153949e11e3aSSheldon Hearncommand are marked as permanent, 154049e11e3aSSheldon Hearnso that they are not undone when the 154149e11e3aSSheldon Hearn.Ic exec 154249e11e3aSSheldon Hearncommand finishes. 154349e11e3aSSheldon Hearn.It Ic exit Op Ar exitstatus 154449e11e3aSSheldon HearnTerminate the shell process. 154549e11e3aSSheldon HearnIf 154649e11e3aSSheldon Hearn.Ar exitstatus 154749e11e3aSSheldon Hearnis given 154849e11e3aSSheldon Hearnit is used as the exit status of the shell; 154949e11e3aSSheldon Hearnotherwise the exit status of the preceding command is used. 15509ba31ca0SRuslan Ermilov.It Ic export Oo Fl p Oc Op Ar name ... 15514b88c807SRodney W. GrimesThe specified names are exported so that they will 15524b88c807SRodney W. Grimesappear in the environment of subsequent commands. 155349e11e3aSSheldon HearnThe only way to un-export a variable is to 155449e11e3aSSheldon Hearn.Ic unset 155549e11e3aSSheldon Hearnit. 155649e11e3aSSheldon HearnThe shell allows the value of a variable to be set 155749e11e3aSSheldon Hearnat the same time as it is exported by writing 1558ab72124fSSteve Price.Bd -literal -offset indent 15594b88c807SRodney W. Grimesexport name=value 1560ab72124fSSteve Price.Ed 1561ab72124fSSteve Price.Pp 15624b88c807SRodney W. GrimesWith no arguments the export command lists the names 15634b88c807SRodney W. Grimesof all exported variables. 156445086f8cSTim J. RobbinsIf the 156545086f8cSTim J. Robbins.Fl p 156645086f8cSTim J. Robbinsoption is specified, the exported variables are printed as 156745086f8cSTim J. Robbins.Dq Ic export Ar name Ns = Ns Ar value 156845086f8cSTim J. Robbinslines, suitable for re-input to the shell. 156981e9cda2SRuslan Ermilov.It Ic fc Oo Fl e Ar editor Oc Op Ar first Op Ar last 157081e9cda2SRuslan Ermilov.It Ic fc Fl l Oo Fl nr Oc Op Ar first Op Ar last 157181e9cda2SRuslan Ermilov.It Ic fc Fl s Oo Ar old Ns = Ns Ar new Oc Op Ar first 157249e11e3aSSheldon HearnThe 157349e11e3aSSheldon Hearn.Ic fc 15748eed22b1SJens Schweikhardtbuilt-in command lists, or edits and re-executes, 157549e11e3aSSheldon Hearncommands previously entered to an interactive shell. 157681e9cda2SRuslan Ermilov.Bl -tag -width indent 157749e11e3aSSheldon Hearn.It Fl e Ar editor 157849e11e3aSSheldon HearnUse the editor named by 157949e11e3aSSheldon Hearn.Ar editor 158049e11e3aSSheldon Hearnto edit the commands. 158149e11e3aSSheldon HearnThe editor string is a command name, 158249e11e3aSSheldon Hearnsubject to search via the 158349e11e3aSSheldon Hearn.Ev PATH 158449e11e3aSSheldon Hearnvariable. 158549e11e3aSSheldon HearnThe value in the 158649e11e3aSSheldon Hearn.Ev FCEDIT 158749e11e3aSSheldon Hearnvariable is used as a default when 158849e11e3aSSheldon Hearn.Fl e 158949e11e3aSSheldon Hearnis not specified. 159049e11e3aSSheldon HearnIf 159149e11e3aSSheldon Hearn.Ev FCEDIT 159249e11e3aSSheldon Hearnis null or unset, the value of the 159349e11e3aSSheldon Hearn.Ev EDITOR 159449e11e3aSSheldon Hearnvariable is used. 159549e11e3aSSheldon HearnIf 159649e11e3aSSheldon Hearn.Ev EDITOR 159749e11e3aSSheldon Hearnis null or unset, 1598ab72124fSSteve Price.Xr ed 1 1599ab72124fSSteve Priceis used as the editor. 160049e11e3aSSheldon Hearn.It Fl l No (ell) 16014b88c807SRodney W. GrimesList the commands rather than invoking 1602eccea571SRuslan Ermilovan editor on them. 1603eccea571SRuslan ErmilovThe commands are written in the 16044b88c807SRodney W. Grimessequence indicated by the first and last operands, as 160549e11e3aSSheldon Hearnaffected by 160649e11e3aSSheldon Hearn.Fl r , 160749e11e3aSSheldon Hearnwith each command preceded by the command number. 160849e11e3aSSheldon Hearn.It Fl n 160949e11e3aSSheldon HearnSuppress command numbers when listing with 161049e11e3aSSheldon Hearn.Fl l . 161149e11e3aSSheldon Hearn.It Fl r 161249e11e3aSSheldon HearnReverse the order of the commands listed 161349e11e3aSSheldon Hearn(with 161449e11e3aSSheldon Hearn.Fl l ) 161549e11e3aSSheldon Hearnor edited 161649e11e3aSSheldon Hearn(with neither 161749e11e3aSSheldon Hearn.Fl l 161849e11e3aSSheldon Hearnnor 161949e11e3aSSheldon Hearn.Fl s ) . 162049e11e3aSSheldon Hearn.It Fl s 16214b88c807SRodney W. GrimesRe-execute the command without invoking an editor. 162249e11e3aSSheldon Hearn.It Ar first 162349e11e3aSSheldon Hearn.It Ar last 162449e11e3aSSheldon HearnSelect the commands to list or edit. 162549e11e3aSSheldon HearnThe number of previous commands that can be accessed 162649e11e3aSSheldon Hearnare determined by the value of the 1627d0353b83SRuslan Ermilov.Ev HISTSIZE 1628d0353b83SRuslan Ermilovvariable. 162949e11e3aSSheldon HearnThe value of 163049e11e3aSSheldon Hearn.Ar first 163149e11e3aSSheldon Hearnor 163249e11e3aSSheldon Hearn.Ar last 163349e11e3aSSheldon Hearnor both are one of the following: 163481e9cda2SRuslan Ermilov.Bl -tag -width indent 163549e11e3aSSheldon Hearn.It Ar [+]num 163649e11e3aSSheldon HearnA positive number representing a command number; 163749e11e3aSSheldon Hearncommand numbers can be displayed with the 163849e11e3aSSheldon Hearn.Fl l 163949e11e3aSSheldon Hearnoption. 164049e11e3aSSheldon Hearn.It Ar -num 164149e11e3aSSheldon HearnA negative decimal number representing the 164249e11e3aSSheldon Hearncommand that was executed 164349e11e3aSSheldon Hearn.Ar num 164449e11e3aSSheldon Hearnof 164549e11e3aSSheldon Hearncommands previously. 164649e11e3aSSheldon HearnFor example, -1 is the immediately previous command. 164749e11e3aSSheldon Hearn.It Ar string 164849e11e3aSSheldon HearnA string indicating the most recently entered command 164949e11e3aSSheldon Hearnthat begins with that string. 165049e11e3aSSheldon HearnIf the 165149e11e3aSSheldon Hearn.Ar old=new 165249e11e3aSSheldon Hearnoperand is not also specified with 165349e11e3aSSheldon Hearn.Fl s , 165449e11e3aSSheldon Hearnthe string form of the first operand cannot contain an embedded equal sign. 165549e11e3aSSheldon Hearn.El 165649e11e3aSSheldon Hearn.El 165749e11e3aSSheldon Hearn.Pp 165849e11e3aSSheldon HearnThe following environment variables affect the execution of 165949e11e3aSSheldon Hearn.Ic fc : 166038afdcbcSGiorgos Keramidas.Bl -tag -width ".Ev HISTSIZE" 166149e11e3aSSheldon Hearn.It Ev FCEDIT 166238afdcbcSGiorgos KeramidasName of the editor to use for history editing. 166349e11e3aSSheldon Hearn.It Ev HISTSIZE 16643d7b5b93SPhilippe CharnierThe number of previous commands that are accessible. 1665ab72124fSSteve Price.El 166649e11e3aSSheldon Hearn.It Ic fg Op Ar job 166749e11e3aSSheldon HearnMove the specified 166849e11e3aSSheldon Hearn.Ar job 166949e11e3aSSheldon Hearnor the current job to the foreground. 167049e11e3aSSheldon Hearn.It Ic getopts Ar optstring Ar var 167149e11e3aSSheldon HearnThe POSIX 167249e11e3aSSheldon Hearn.Ic getopts 167349e11e3aSSheldon Hearncommand. 167449e11e3aSSheldon HearnThe 167549e11e3aSSheldon Hearn.Ic getopts 167649e11e3aSSheldon Hearncommand deprecates the older 167749e11e3aSSheldon Hearn.Xr getopt 1 167849e11e3aSSheldon Hearncommand. 1679ab0a2172SSteve PriceThe first argument should be a series of letters, each possibly 1680ab0a2172SSteve Pricefollowed by a colon which indicates that the option takes an argument. 1681eccea571SRuslan ErmilovThe specified variable is set to the parsed option. 1682eccea571SRuslan ErmilovThe index of 168349e11e3aSSheldon Hearnthe next argument is placed into the shell variable 168449e11e3aSSheldon Hearn.Ev OPTIND . 1685ab0a2172SSteve PriceIf an option takes an argument, it is placed into the shell variable 168649e11e3aSSheldon Hearn.Ev OPTARG . 168749e11e3aSSheldon HearnIf an invalid option is encountered, 168849e11e3aSSheldon Hearn.Ev var 168949e11e3aSSheldon Hearnis set to 16901586940eSRuslan Ermilov.Dq Li \&? . 1691ab0a2172SSteve PriceIt returns a false value (1) when it encounters the end of the options. 169281e9cda2SRuslan Ermilov.It Ic hash Oo Fl rv Oc Op Ar command ... 169349e11e3aSSheldon HearnThe shell maintains a hash table which remembers the locations of commands. 169449e11e3aSSheldon HearnWith no arguments whatsoever, the 169549e11e3aSSheldon Hearn.Ic hash 169649e11e3aSSheldon Hearncommand prints out the contents of this table. 169749e11e3aSSheldon HearnEntries which have not been looked at since the last 169849e11e3aSSheldon Hearn.Ic cd 169949e11e3aSSheldon Hearncommand are marked with an asterisk; 170049e11e3aSSheldon Hearnit is possible for these entries to be invalid. 1701ab72124fSSteve Price.Pp 170249e11e3aSSheldon HearnWith arguments, the 170349e11e3aSSheldon Hearn.Ic hash 170449e11e3aSSheldon Hearncommand removes each specified 170549e11e3aSSheldon Hearn.Ar command 170649e11e3aSSheldon Hearnfrom the hash table (unless they are functions) and then locates it. 170749e11e3aSSheldon HearnWith the 170849e11e3aSSheldon Hearn.Fl v 170949e11e3aSSheldon Hearnoption, 171049e11e3aSSheldon Hearn.Ic hash 171149e11e3aSSheldon Hearnprints the locations of the commands as it finds them. 171249e11e3aSSheldon HearnThe 171349e11e3aSSheldon Hearn.Fl r 171449e11e3aSSheldon Hearnoption causes the 171549e11e3aSSheldon Hearn.Ic hash 171649e11e3aSSheldon Hearncommand to delete all the entries in the hash table except for functions. 171749e11e3aSSheldon Hearn.It Ic jobid Op Ar job 171849e11e3aSSheldon HearnPrint the process id's of the processes in the specified 171949e11e3aSSheldon Hearn.Ar job . 172049e11e3aSSheldon HearnIf the 172149e11e3aSSheldon Hearn.Ar job 172249e11e3aSSheldon Hearnargument is omitted, use the current job. 17239ba31ca0SRuslan Ermilov.It Ic jobs Oo Fl ls Oc Op Ar job ... 1724ad8a0759STim J. RobbinsPrint information about the specified jobs, or all jobs if no 1725ad8a0759STim J. Robbins.Ar job 1726ad8a0759STim J. Robbinsargument is given. 1727ad8a0759STim J. RobbinsThe information printed includes job ID, status and command name. 1728ad8a0759STim J. Robbins.Pp 1729ad8a0759STim J. RobbinsIf the 1730ad8a0759STim J. Robbins.Fl l 1731ad8a0759STim J. Robbinsoption is specified, the PID of each job is also printed. 1732ad8a0759STim J. RobbinsIf the 1733ad8a0759STim J. Robbins.Fl s 17349ba31ca0SRuslan Ermilovoption is specified, only the PIDs of the jobs are printed, one per line. 1735d74e011fSRuslan Ermilov.It Ic pwd Op Fl L | P 1736eccea571SRuslan ErmilovPrint the path of the current directory. 1737eccea571SRuslan ErmilovThe built-in command may 17384b88c807SRodney W. Grimesdiffer from the program of the same name because the 17398eed22b1SJens Schweikhardtbuilt-in command remembers what the current directory 1740eccea571SRuslan Ermilovis rather than recomputing it each time. 1741eccea571SRuslan ErmilovThis makes 1742eccea571SRuslan Ermilovit faster. 1743eccea571SRuslan ErmilovHowever, if the current directory is 174449e11e3aSSheldon Hearnrenamed, 17458eed22b1SJens Schweikhardtthe built-in version of 174649e11e3aSSheldon Hearn.Xr pwd 1 174749e11e3aSSheldon Hearnwill continue to print the old name for the directory. 1748178897f1STim J. Robbins.Pp 1749178897f1STim J. RobbinsIf the 1750178897f1STim J. Robbins.Fl P 1751178897f1STim J. Robbinsoption is specified, symbolic links are resolved. 1752178897f1STim J. RobbinsIf the 1753178897f1STim J. Robbins.Fl L 1754178897f1STim J. Robbinsoption is specified, the shell's notion of the current directory 1755178897f1STim J. Robbinsis printed (symbolic links are not resolved). 1756178897f1STim J. RobbinsThis is the default. 175781e9cda2SRuslan Ermilov.It Ic read Oo Fl p Ar prompt Oc Oo Fl t Ar timeout Oc Oo Fl er Oc Ar variable ... 175849e11e3aSSheldon HearnThe 175949e11e3aSSheldon Hearn.Ar prompt 176049e11e3aSSheldon Hearnis printed if the 176149e11e3aSSheldon Hearn.Fl p 176249e11e3aSSheldon Hearnoption is specified 1763eccea571SRuslan Ermilovand the standard input is a terminal. 1764eccea571SRuslan ErmilovThen a line is 1765eccea571SRuslan Ermilovread from the standard input. 1766eccea571SRuslan ErmilovThe trailing newline 17674b88c807SRodney W. Grimesis deleted from the line and the line is split as 176849e11e3aSSheldon Hearndescribed in the section on 176949e11e3aSSheldon Hearn.Sx White Space Splitting (Field Splitting) 177049e11e3aSSheldon Hearnabove, and 17714b88c807SRodney W. Grimesthe pieces are assigned to the variables in order. 1772f434d1dfSAdam DavidIf there are more pieces than variables, the remaining 177349e11e3aSSheldon Hearnpieces (along with the characters in 177449e11e3aSSheldon Hearn.Ev IFS 177549e11e3aSSheldon Hearnthat separated them) 177649e11e3aSSheldon Hearnare assigned to the last variable. 1777f434d1dfSAdam DavidIf there are more variables than pieces, the remaining 1778f434d1dfSAdam Davidvariables are assigned the null string. 1779ab72124fSSteve Price.Pp 178049e11e3aSSheldon HearnBackslashes are treated specially, unless the 178149e11e3aSSheldon Hearn.Fl r 178249e11e3aSSheldon Hearnoption is 1783eccea571SRuslan Ermilovspecified. 1784eccea571SRuslan ErmilovIf a backslash is followed by 17858f0561ccSThomas Gellekuma newline, the backslash and the newline will be 1786eccea571SRuslan Ermilovdeleted. 1787eccea571SRuslan ErmilovIf a backslash is followed by any other 17888f0561ccSThomas Gellekumcharacter, the backslash will be deleted and the following 178949e11e3aSSheldon Hearncharacter will be treated as though it were not in 179049e11e3aSSheldon Hearn.Ev IFS , 179149e11e3aSSheldon Hearneven if it is. 17928f0561ccSThomas Gellekum.Pp 179349e11e3aSSheldon HearnIf the 179449e11e3aSSheldon Hearn.Fl t 179549e11e3aSSheldon Hearnoption is specified and the 179649e11e3aSSheldon Hearn.Ar timeout 179749e11e3aSSheldon Hearnelapses before any input is supplied, 179849e11e3aSSheldon Hearnthe 179949e11e3aSSheldon Hearn.Ic read 180049e11e3aSSheldon Hearncommand will return without assigning any values. 180149e11e3aSSheldon HearnThe 180249e11e3aSSheldon Hearn.Ar timeout 180349e11e3aSSheldon Hearnvalue may optionally be followed by one of 180449e11e3aSSheldon Hearn.Dq s , 180549e11e3aSSheldon Hearn.Dq m 180649e11e3aSSheldon Hearnor 180749e11e3aSSheldon Hearn.Dq h 1808a910f192SDima Dorfmanto explicitly specify seconds, minutes or hours. 180949e11e3aSSheldon HearnIf none is supplied, 181049e11e3aSSheldon Hearn.Dq s 181149e11e3aSSheldon Hearnis assumed. 1812afa53c8dSMike Smith.Pp 181349e11e3aSSheldon HearnThe 181449e11e3aSSheldon Hearn.Fl e 181549e11e3aSSheldon Hearnoption exists only for backward compatibility with older scripts. 18169ba31ca0SRuslan Ermilov.It Ic readonly Oo Fl p Oc Op Ar name ... 181749e11e3aSSheldon HearnEach specified 181849e11e3aSSheldon Hearn.Ar name 181949e11e3aSSheldon Hearnis marked as read only, 182049e11e3aSSheldon Hearnso that it cannot be subsequently modified or unset. 182149e11e3aSSheldon HearnThe shell allows the value of a variable to be set 182249e11e3aSSheldon Hearnat the same time as it is marked read only 182349e11e3aSSheldon Hearnby using the following form: 1824ab72124fSSteve Price.Bd -literal -offset indent 18254b88c807SRodney W. Grimesreadonly name=value 1826ab72124fSSteve Price.Ed 1827ab72124fSSteve Price.Pp 182849e11e3aSSheldon HearnWith no arguments the 182949e11e3aSSheldon Hearn.Ic readonly 183049e11e3aSSheldon Hearncommand lists the names of all read only variables. 183145086f8cSTim J. RobbinsIf the 183245086f8cSTim J. Robbins.Fl p 183345086f8cSTim J. Robbinsoption is specified, the read-only variables are printed as 183445086f8cSTim J. Robbins.Dq Ic readonly Ar name Ns = Ns Ar value 183545086f8cSTim J. Robbinslines, suitable for re-input to the shell. 183681e9cda2SRuslan Ermilov.It Ic set Oo Fl /+abCEefIimnpTuVvx Oc Oo Fl /+o Ar longname Oc Oo 183781e9cda2SRuslan Ermilov.Fl c Ar string Oc Op Fl - Ar arg ... 1838e918fc8fSSheldon HearnThe 1839e918fc8fSSheldon Hearn.Ic set 1840e918fc8fSSheldon Hearncommand performs three different functions: 1841ab72124fSSteve Price.Bl -item 1842ab72124fSSteve Price.It 184349e11e3aSSheldon HearnWith no arguments, it lists the values of all shell variables. 1844ab72124fSSteve Price.It 184549e11e3aSSheldon HearnIf options are given, 184649e11e3aSSheldon Hearneither in short form or using the long 184749e11e3aSSheldon Hearn.Dq Fl /+o Ar longname 184849e11e3aSSheldon Hearnform, 184949e11e3aSSheldon Hearnit sets or clears the specified options as described in the section called 18506b15476eSSheldon Hearn.Sx Argument List Processing . 1851ab72124fSSteve Price.It 185249e11e3aSSheldon HearnIf the 185349e11e3aSSheldon Hearn.Dq Fl - 185449e11e3aSSheldon Hearnoption is specified, 185549e11e3aSSheldon Hearn.Ic set 185649e11e3aSSheldon Hearnwill replace the shell's positional parameters with the subsequent 185749e11e3aSSheldon Hearnarguments. 185849e11e3aSSheldon HearnIf no arguments follow the 185949e11e3aSSheldon Hearn.Dq Fl - 186049e11e3aSSheldon Hearnoption, 186149e11e3aSSheldon Hearnall the positional parameters will be cleared, 186249e11e3aSSheldon Hearnwhich is equivalent to executing the command 186349e11e3aSSheldon Hearn.Dq Li shift $# . 186449e11e3aSSheldon HearnThe 186549e11e3aSSheldon Hearn.Dq Fl - 18668eed22b1SJens Schweikhardtflag may be omitted when specifying arguments to be used 186749e11e3aSSheldon Hearnas positional replacement parameters. 186849e11e3aSSheldon HearnThis is not recommended, 186949e11e3aSSheldon Hearnbecause the first argument may begin with a dash 1870a762afe5SGiorgos Keramidas.Pq Ql - 187149e11e3aSSheldon Hearnor a plus 1872a762afe5SGiorgos Keramidas.Pq Ql + , 187349e11e3aSSheldon Hearnwhich the 187449e11e3aSSheldon Hearn.Ic set 187549e11e3aSSheldon Hearncommand will interpret as a request to enable or disable options. 1876ab72124fSSteve Price.El 187749e11e3aSSheldon Hearn.It Ic setvar Ar variable Ar value 187849e11e3aSSheldon HearnAssigns the specified 187949e11e3aSSheldon Hearn.Ar value 188049e11e3aSSheldon Hearnto the specified 188149e11e3aSSheldon Hearn.Ar variable . 188249e11e3aSSheldon Hearn.Ic Setvar 188349e11e3aSSheldon Hearnis intended to be used in functions that 1884e6d3cf26SSheldon Hearnassign values to variables whose names are passed as parameters. 188549e11e3aSSheldon HearnIn general it is better to write 188649e11e3aSSheldon Hearn.Bd -literal -offset indent 188749e11e3aSSheldon Hearnvariable=value 188849e11e3aSSheldon Hearn.Ed 188949e11e3aSSheldon Hearnrather than using 189049e11e3aSSheldon Hearn.Ic setvar . 189149e11e3aSSheldon Hearn.It Ic shift Op Ar n 189249e11e3aSSheldon HearnShift the positional parameters 189349e11e3aSSheldon Hearn.Ar n 1894e918fc8fSSheldon Hearntimes, or once if 189549e11e3aSSheldon Hearn.Ar n 189649e11e3aSSheldon Hearnis not specified. 189749e11e3aSSheldon HearnA shift sets the value of $1 to the value of $2, 189849e11e3aSSheldon Hearnthe value of $2 to the value of $3, and so on, 189949e11e3aSSheldon Hearndecreasing the value of $# by one. 190049e11e3aSSheldon HearnIf there are zero positional parameters, shifting does not do anything. 190181e9cda2SRuslan Ermilov.It Ic trap Oo Ar action Oc Ar signal ... 190249e11e3aSSheldon HearnCause the shell to parse and execute 190349e11e3aSSheldon Hearn.Ar action 190449e11e3aSSheldon Hearnwhen any specified 190549e11e3aSSheldon Hearn.Ar signal 190649e11e3aSSheldon Hearnis received. 1907162ae3aeSTony FinchThe signals are specified by name or number. 1908162ae3aeSTony FinchIn addition, the pseudo-signal 1909f5d1157fSRuslan Ermilov.Cm EXIT 1910162ae3aeSTony Finchmay be used to specify an action that is performed when the shell terminates. 191149e11e3aSSheldon HearnThe 191249e11e3aSSheldon Hearn.Ar action 191349e11e3aSSheldon Hearnmay be null or omitted; 191449e11e3aSSheldon Hearnthe former causes the specified signal to be ignored 191549e11e3aSSheldon Hearnand the latter causes the default action to be taken. 191649e11e3aSSheldon HearnWhen the shell forks off a subshell, 191749e11e3aSSheldon Hearnit resets trapped (but not ignored) signals to the default action. 191849e11e3aSSheldon HearnThe 191949e11e3aSSheldon Hearn.Ic trap 192049e11e3aSSheldon Hearncommand has no effect on signals that were ignored on entry to the shell. 192149e11e3aSSheldon Hearn.It Ic type Op Ar name ... 192249e11e3aSSheldon HearnInterpret each 192349e11e3aSSheldon Hearn.Ar name 192449e11e3aSSheldon Hearnas a command and print the resolution of the command search. 1925e6d3cf26SSheldon HearnPossible resolutions are: 19268eed22b1SJens Schweikhardtshell keyword, alias, shell built-in command, command, tracked alias 192749e11e3aSSheldon Hearnand not found. 192849e11e3aSSheldon HearnFor aliases the alias expansion is printed; 192949e11e3aSSheldon Hearnfor commands and tracked aliases 193049e11e3aSSheldon Hearnthe complete pathname of the command is printed. 193162df9b62SSheldon Hearn.It Ic ulimit Oo Fl HSabcdflmnstuv Oc Op Ar limit 1932ab72124fSSteve PriceSet or display resource limits (see 1933ab72124fSSteve Price.Xr getrlimit 2 ) . 19346b15476eSSheldon HearnIf 193549e11e3aSSheldon Hearn.Ar limit 19366b15476eSSheldon Hearnis specified, the named resource will be set; 19377a2afe64SJoerg Wunschotherwise the current resource value will be displayed. 1938ab72124fSSteve Price.Pp 19396b15476eSSheldon HearnIf 194049e11e3aSSheldon Hearn.Fl H 194149e11e3aSSheldon Hearnis specified, the hard limits will be set or displayed. 194249e11e3aSSheldon HearnWhile everybody is allowed to reduce a hard limit, 194349e11e3aSSheldon Hearnonly the superuser can increase it. 194449e11e3aSSheldon HearnThe 194549e11e3aSSheldon Hearn.Fl S 194649e11e3aSSheldon Hearnoption 1947eccea571SRuslan Ermilovspecifies the soft limits instead. 1948eccea571SRuslan ErmilovWhen displaying limits, 19496b15476eSSheldon Hearnonly one of 195049e11e3aSSheldon Hearn.Fl S 19516b15476eSSheldon Hearnor 195249e11e3aSSheldon Hearn.Fl H 195349e11e3aSSheldon Hearncan be given. 195449e11e3aSSheldon HearnThe default is to display the soft limits, 195549e11e3aSSheldon Hearnand to set both the hard and the soft limits. 1956ab72124fSSteve Price.Pp 19576b15476eSSheldon HearnOption 195849e11e3aSSheldon Hearn.Fl a 195949e11e3aSSheldon Hearncauses the 196049e11e3aSSheldon Hearn.Ic ulimit 196149e11e3aSSheldon Hearncommand to display all resources. 196249e11e3aSSheldon HearnThe parameter 196349e11e3aSSheldon Hearn.Ar limit 19646b15476eSSheldon Hearnis not acceptable in this mode. 1965ab72124fSSteve Price.Pp 19667a2afe64SJoerg WunschThe remaining options specify which resource value is to be 196749e11e3aSSheldon Hearndisplayed or modified. 196849e11e3aSSheldon HearnThey are mutually exclusive. 196981e9cda2SRuslan Ermilov.Bl -tag -width indent 19703652a236SMartin Cracauer.It Fl b Ar sbsize 19713652a236SMartin CracauerThe maximum size of socket buffer usage, in bytes. 197249e11e3aSSheldon Hearn.It Fl c Ar coredumpsize 19737a2afe64SJoerg WunschThe maximal size of core dump files, in 512-byte blocks. 197449e11e3aSSheldon Hearn.It Fl d Ar datasize 19757a2afe64SJoerg WunschThe maximal size of the data segment of a process, in kilobytes. 197649e11e3aSSheldon Hearn.It Fl f Ar filesize 197749e11e3aSSheldon HearnThe maximal size of a file, in 512-byte blocks. 197849e11e3aSSheldon Hearn.It Fl l Ar lockedmem 19797a2afe64SJoerg WunschThe maximal size of memory that can be locked by a process, in 19807a2afe64SJoerg Wunschkilobytes. 198149e11e3aSSheldon Hearn.It Fl m Ar memoryuse 19827a2afe64SJoerg WunschThe maximal resident set size of a process, in kilobytes. 198349e11e3aSSheldon Hearn.It Fl n Ar nofiles 19847a2afe64SJoerg WunschThe maximal number of descriptors that could be opened by a process. 198549e11e3aSSheldon Hearn.It Fl s Ar stacksize 19867a2afe64SJoerg WunschThe maximal size of the stack segment, in kilobytes. 198749e11e3aSSheldon Hearn.It Fl t Ar time 19887a2afe64SJoerg WunschThe maximal amount of CPU time to be used by each process, in seconds. 198949e11e3aSSheldon Hearn.It Fl u Ar userproc 1990ab72124fSSteve PriceThe maximal number of simultaneous processes for this user ID. 199162df9b62SSheldon Hearn.It Fl v Ar virtualmem 19922d41ef4bSMatthew DillonThe maximal virtual size of a process, in kilobytes. 1993ab72124fSSteve Price.El 1994faa1ed35SStefan Farfeleder.It Ic umask Oo Fl S Oc Op Ar mask 199549e11e3aSSheldon HearnSet the file creation mask (see 1996ab72124fSSteve Price.Xr umask 2 ) 1997faa1ed35SStefan Farfelederto the octal or symbolic (see 1998faa1ed35SStefan Farfeleder.Xr chmod 1 ) 1999faa1ed35SStefan Farfeledervalue specified by 20005d3b843bSSheldon Hearn.Ar mask . 200149e11e3aSSheldon HearnIf the argument is omitted, the current mask value is printed. 2002faa1ed35SStefan FarfelederIf the 2003faa1ed35SStefan Farfeleder.Fl S 2004faa1ed35SStefan Farfelederoption is specified, the output is symbolic, otherwise the output is octal. 2005de4ad382SStefan Farfeleder.It Ic unalias Oo Fl a Oc Op Ar name ... 2006de4ad382SStefan FarfelederThe specified alias names are removed. 20076b15476eSSheldon HearnIf 20081b9735e6SSheldon Hearn.Fl a 20096b15476eSSheldon Hearnis specified, all aliases are removed. 20109ba31ca0SRuslan Ermilov.It Ic unset Oo Fl fv Oc Ar name ... 20118b34ad92STim J. RobbinsThe specified variables or functions are unset and unexported. 20128b34ad92STim J. RobbinsIf the 20138b34ad92STim J. Robbins.Fl v 20148b34ad92STim J. Robbinsoption is specified or no options are given, the 201549e11e3aSSheldon Hearn.Ar name 20168b34ad92STim J. Robbinsarguments are treated as variable names. 20178b34ad92STim J. RobbinsIf the 20188b34ad92STim J. Robbins.Fl f 20198b34ad92STim J. Robbinsoption is specified, the 20208b34ad92STim J. Robbins.Ar name 20218b34ad92STim J. Robbinsarguments are treated as function names. 202249e11e3aSSheldon Hearn.It Ic wait Op Ar job 202349e11e3aSSheldon HearnWait for the specified 202449e11e3aSSheldon Hearn.Ar job 202549e11e3aSSheldon Hearnto complete and return the exit status of the last process in the 202649e11e3aSSheldon Hearn.Ar job . 2027e6d3cf26SSheldon HearnIf the argument is omitted, wait for all jobs to complete 2028e6d3cf26SSheldon Hearnand return an exit status of zero. 2029ab72124fSSteve Price.El 2030ab72124fSSteve Price.Ss Commandline Editing 2031ab72124fSSteve PriceWhen 2032ab72124fSSteve Price.Nm 2033ab72124fSSteve Priceis being used interactively from a terminal, the current command 203449e11e3aSSheldon Hearnand the command history 203549e11e3aSSheldon Hearn(see 203649e11e3aSSheldon Hearn.Ic fc 203749e11e3aSSheldon Hearnin 20388eed22b1SJens Schweikhardt.Sx Built-in Commands ) 203949e11e3aSSheldon Hearncan be edited using vi-mode command line editing. 204049e11e3aSSheldon HearnThis mode uses commands similar 20414b88c807SRodney W. Grimesto a subset of those described in the vi man page. 204249e11e3aSSheldon HearnThe command 204349e11e3aSSheldon Hearn.Dq Li set -o vi 204449e11e3aSSheldon Hearn(or 2045e918fc8fSSheldon Hearn.Dq Li set -V ) 204649e11e3aSSheldon Hearnenables vi-mode editing and places 2047ab72124fSSteve Price.Nm 2048eccea571SRuslan Ermilovinto vi insert mode. 2049eccea571SRuslan ErmilovWith vi-mode enabled, 2050ab72124fSSteve Price.Nm 205149e11e3aSSheldon Hearncan be switched between insert mode and command mode by typing 205249e11e3aSSheldon Hearn.Aq ESC . 205349e11e3aSSheldon HearnHitting 205449e11e3aSSheldon Hearn.Aq return 205549e11e3aSSheldon Hearnwhile in command mode will pass the line to the shell. 2056ab72124fSSteve Price.Pp 205749e11e3aSSheldon HearnSimilarly, the 205849e11e3aSSheldon Hearn.Dq Li set -o emacs 205949e11e3aSSheldon Hearn(or 2060e918fc8fSSheldon Hearn.Dq Li set -E ) 206149e11e3aSSheldon Hearncommand can be used to enable a subset of 2062ab72124fSSteve Priceemacs-style command line editing features. 206338afdcbcSGiorgos Keramidas.Sh ENVIRONMENT 206438afdcbcSGiorgos KeramidasThe following environment variables affect the execution of 206538afdcbcSGiorgos Keramidas.Nm : 206638afdcbcSGiorgos Keramidas.Bl -tag -width ".Ev HISTSIZE" 206738afdcbcSGiorgos Keramidas.It Ev CDPATH 206838afdcbcSGiorgos KeramidasThe search path used with the 206938afdcbcSGiorgos Keramidas.Ic cd 207038afdcbcSGiorgos Keramidasbuilt-in. 207138afdcbcSGiorgos Keramidas.It Ev EDITOR 207238afdcbcSGiorgos KeramidasThe fallback editor used with the 207338afdcbcSGiorgos Keramidas.Ic fc 207438afdcbcSGiorgos Keramidasbuilt-in. 207538afdcbcSGiorgos KeramidasIf not set, the default editor is 207638afdcbcSGiorgos Keramidas.Xr ed 1 . 207738afdcbcSGiorgos Keramidas.It Ev FCEDIT 207838afdcbcSGiorgos KeramidasThe default editor used with the 207938afdcbcSGiorgos Keramidas.Ic fc 208038afdcbcSGiorgos Keramidasbuilt-in. 208138afdcbcSGiorgos Keramidas.It Ev HISTSIZE 208238afdcbcSGiorgos KeramidasThe number of previous commands that are accessible. 208338afdcbcSGiorgos Keramidas.It Ev HOME 208438afdcbcSGiorgos KeramidasThe starting directory of 208538afdcbcSGiorgos Keramidas.Nm . 208638afdcbcSGiorgos Keramidas.It Ev IFS 208738afdcbcSGiorgos KeramidasInput Field Separators. 208838afdcbcSGiorgos KeramidasThis is normally set to 208938afdcbcSGiorgos Keramidas.Aq space , 209038afdcbcSGiorgos Keramidas.Aq tab , 209138afdcbcSGiorgos Keramidasand 209238afdcbcSGiorgos Keramidas.Aq newline . 209338afdcbcSGiorgos KeramidasSee the 209438afdcbcSGiorgos Keramidas.Sx White Space Splitting 209538afdcbcSGiorgos Keramidassection for more details. 209638afdcbcSGiorgos Keramidas.It Ev MAIL 209738afdcbcSGiorgos KeramidasThe name of a mail file, that will be checked for the arrival of new 209838afdcbcSGiorgos Keramidasmail. 209938afdcbcSGiorgos KeramidasOverridden by 210038afdcbcSGiorgos Keramidas.Ev MAILPATH . 210138afdcbcSGiorgos Keramidas.It Ev MAILPATH 210238afdcbcSGiorgos KeramidasA colon 210338afdcbcSGiorgos Keramidas.Pq Ql \&: 210438afdcbcSGiorgos Keramidasseparated list of file names, for the shell to check for incoming 210538afdcbcSGiorgos Keramidasmail. 210638afdcbcSGiorgos KeramidasThis environment setting overrides the 210738afdcbcSGiorgos Keramidas.Ev MAIL 210838afdcbcSGiorgos Keramidassetting. 210938afdcbcSGiorgos KeramidasThere is a maximum of 10 mailboxes that can be monitored at once. 211038afdcbcSGiorgos Keramidas.It Ev PATH 211138afdcbcSGiorgos KeramidasThe default search path for executables. 211238afdcbcSGiorgos KeramidasSee the 211338afdcbcSGiorgos Keramidas.Sx Path Search 211438afdcbcSGiorgos Keramidassection for details. 211538afdcbcSGiorgos Keramidas.It Ev PS1 211638afdcbcSGiorgos KeramidasThe primary prompt string, which defaults to 2117fb039b55SRuslan Ermilov.Dq Li "$ " , 211838afdcbcSGiorgos Keramidasunless you are the superuser, in which case it defaults to 2119fb039b55SRuslan Ermilov.Dq Li "# " . 212038afdcbcSGiorgos Keramidas.It Ev PS2 212138afdcbcSGiorgos KeramidasThe secondary prompt string, which defaults to 2122fb039b55SRuslan Ermilov.Dq Li "> " . 212338afdcbcSGiorgos Keramidas.It Ev TERM 212438afdcbcSGiorgos KeramidasThe default terminal setting for the shell. 212538afdcbcSGiorgos KeramidasThis is inherited by children of the shell, and is used in the history 212638afdcbcSGiorgos Keramidasediting modes. 212738afdcbcSGiorgos Keramidas.El 2128fb039b55SRuslan Ermilov.Sh EXIT STATUS 2129fb039b55SRuslan ErmilovErrors that are detected by the shell, such as a syntax error, will 2130fb039b55SRuslan Ermilovcause the shell to exit with a non-zero exit status. 2131fb039b55SRuslan ErmilovIf the shell is not an interactive shell, the execution of the shell 2132fb039b55SRuslan Ermilovfile will be aborted. 2133fb039b55SRuslan ErmilovOtherwise the shell will return the exit status of the last command 2134fb039b55SRuslan Ermilovexecuted, or if the exit builtin is used with a numeric argument, it 2135fb039b55SRuslan Ermilovwill return the argument. 2136c83e7c50SJoseph Koshy.Sh SEE ALSO 2137c644db6aSSheldon Hearn.Xr builtin 1 , 213838afdcbcSGiorgos Keramidas.Xr chsh 1 , 2139c644db6aSSheldon Hearn.Xr echo 1 , 214038afdcbcSGiorgos Keramidas.Xr ed 1 , 214138afdcbcSGiorgos Keramidas.Xr emacs 1 , 2142c83e7c50SJoseph Koshy.Xr expr 1 , 214338afdcbcSGiorgos Keramidas.Xr getopt 1 , 21445521ff5aSRuslan Ermilov.Xr pwd 1 , 214538afdcbcSGiorgos Keramidas.Xr test 1 , 214638afdcbcSGiorgos Keramidas.Xr vi 1 , 214738afdcbcSGiorgos Keramidas.Xr execve 2 , 214838afdcbcSGiorgos Keramidas.Xr getrlimit 2 , 2149fd50df30SRuslan Ermilov.Xr umask 2 , 215038afdcbcSGiorgos Keramidas.Xr editrc 5 2151ab72124fSSteve Price.Sh HISTORY 2152b8923d4cSWolfram SchneiderA 2153ab72124fSSteve Price.Nm 2154b8923d4cSWolfram Schneidercommand appeared in 2155fc482908STim J. Robbins.At v1 . 2156128dc4a2STim J. Robbins.Sh BUGS 2157128dc4a2STim J. RobbinsThe 2158128dc4a2STim J. Robbins.Nm 2159128dc4a2STim J. Robbinsutility does not recognize multibyte characters. 2160