Tue Mar 13 20:08:11 2018 UTC ()
Standalone | means \[ba] while we want \[or] so add \& protection to
the few places where it was missing.


(uwe)
diff -r1.178 -r1.179 src/bin/sh/sh.1

cvs diff -r1.178 -r1.179 src/bin/sh/sh.1 (switch to unified diff)

--- src/bin/sh/sh.1 2018/03/13 19:43:52 1.178
+++ src/bin/sh/sh.1 2018/03/13 20:08:11 1.179
@@ -1,2122 +1,2122 @@ @@ -1,2122 +1,2122 @@
1.\" $NetBSD: sh.1,v 1.178 2018/03/13 19:43:52 uwe Exp $ 1.\" $NetBSD: sh.1,v 1.179 2018/03/13 20:08:11 uwe Exp $
2.\" Copyright (c) 1991, 1993 2.\" Copyright (c) 1991, 1993
3.\" The Regents of the University of California. All rights reserved. 3.\" The Regents of the University of California. All rights reserved.
4.\" 4.\"
5.\" This code is derived from software contributed to Berkeley by 5.\" This code is derived from software contributed to Berkeley by
6.\" Kenneth Almquist. 6.\" Kenneth Almquist.
7.\" 7.\"
8.\" Redistribution and use in source and binary forms, with or without 8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions 9.\" modification, are permitted provided that the following conditions
10.\" are met: 10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright 11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer. 12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the 14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution. 15.\" documentation and/or other materials provided with the distribution.
16.\" 3. Neither the name of the University nor the names of its contributors 16.\" 3. Neither the name of the University nor the names of its contributors
17.\" may be used to endorse or promote products derived from this software 17.\" may be used to endorse or promote products derived from this software
18.\" without specific prior written permission. 18.\" without specific prior written permission.
19.\" 19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE. 30.\" SUCH DAMAGE.
31.\" 31.\"
32.\" @(#)sh.1 8.6 (Berkeley) 5/4/95 32.\" @(#)sh.1 8.6 (Berkeley) 5/4/95
33.\" 33.\"
34.Dd October 24, 2017 34.Dd October 24, 2017
35.Dt SH 1 35.Dt SH 1
36.\" everything except c o and s (keep them ordered) 36.\" everything except c o and s (keep them ordered)
37.ds flags abCEeFfhIiLmnpquVvXx 37.ds flags abCEeFfhIiLmnpquVvXx
38.Os 38.Os
39.Sh NAME 39.Sh NAME
40.Nm sh 40.Nm sh
41.Nd command interpreter (shell) 41.Nd command interpreter (shell)
42.Sh SYNOPSIS 42.Sh SYNOPSIS
43.Nm 43.Nm
44.Bk -words 44.Bk -words
45.Op Fl \*[flags] 45.Op Fl \*[flags]
46.Op Cm +\*[flags] 46.Op Cm +\*[flags]
47.Ek 47.Ek
48.Bk -words 48.Bk -words
49.Op Fl o Ar option_name 49.Op Fl o Ar option_name
50.Op Cm +o Ar option_name 50.Op Cm +o Ar option_name
51.Ek 51.Ek
52.Bk -words 52.Bk -words
53.Op Ar command_file Oo Ar argument ... Oc 53.Op Ar command_file Oo Ar argument ... Oc
54.Ek 54.Ek
55.Nm 55.Nm
56.Fl c 56.Fl c
57.Bk -words 57.Bk -words
58.Op Fl s 58.Op Fl s
59.Op Fl \*[flags] 59.Op Fl \*[flags]
60.Op Cm +\*[flags] 60.Op Cm +\*[flags]
61.Ek 61.Ek
62.Bk -words 62.Bk -words
63.Op Fl o Ar option_name 63.Op Fl o Ar option_name
64.Op Cm +o Ar option_name 64.Op Cm +o Ar option_name
65.Ek 65.Ek
66.Bk -words 66.Bk -words
67.Ar command_string 67.Ar command_string
68.Op Ar command_name Oo Ar argument ... Oc 68.Op Ar command_name Oo Ar argument ... Oc
69.Ek 69.Ek
70.Nm 70.Nm
71.Fl s 71.Fl s
72.Bk -words 72.Bk -words
73.Op Fl \*[flags] 73.Op Fl \*[flags]
74.Op Cm +\*[flags] 74.Op Cm +\*[flags]
75.Ek 75.Ek
76.Bk -words 76.Bk -words
77.Op Fl o Ar option_name 77.Op Fl o Ar option_name
78.Op Cm +o Ar option_name 78.Op Cm +o Ar option_name
79.Ek 79.Ek
80.Bk -words 80.Bk -words
81.Op Ar argument ... 81.Op Ar argument ...
82.Ek 82.Ek
83.Sh DESCRIPTION 83.Sh DESCRIPTION
84.Nm 84.Nm
85is the standard command interpreter for the system. 85is the standard command interpreter for the system.
86The current version of 86The current version of
87.Nm 87.Nm
88is in the process of being changed to conform more closely to the 88is in the process of being changed to conform more closely to the
89POSIX 1003.2 and 1003.2a specifications for the shell. 89POSIX 1003.2 and 1003.2a specifications for the shell.
90This version has many 90This version has many
91features which make it appear similar in some respects to the Korn shell, 91features which make it appear similar in some respects to the Korn shell,
92but it is not a Korn shell clone (see 92but it is not a Korn shell clone (see
93.Xr ksh 1 ) . 93.Xr ksh 1 ) .
94This man page is not intended 94This man page is not intended
95to be a tutorial or a complete specification of the shell. 95to be a tutorial or a complete specification of the shell.
96.Ss Overview 96.Ss Overview
97The shell is a command that reads lines from either a file or the 97The shell is a command that reads lines from either a file or the
98terminal, interprets them, and generally executes other commands. 98terminal, interprets them, and generally executes other commands.
99A shell is the program that is running when a user logs into the system. 99A shell is the program that is running when a user logs into the system.
100(Users can select which shell is executed for them at login with the 100(Users can select which shell is executed for them at login with the
101.Xr chsh 1 101.Xr chsh 1
102command). 102command).
103The shell implements a language that has flow control 103The shell implements a language that has flow control
104constructs, a macro facility that provides a variety of features in 104constructs, a macro facility that provides a variety of features in
105addition to data storage, along with built in history and line editing 105addition to data storage, along with built in history and line editing
106capabilities. 106capabilities.
107It incorporates many features to aid interactive use and 107It incorporates many features to aid interactive use and
108has the advantage that the interpretative language is common to both 108has the advantage that the interpretative language is common to both
109interactive and non-interactive use (shell scripts). 109interactive and non-interactive use (shell scripts).
110That is, commands 110That is, commands
111can be typed directly to the running shell or can be put into a file and 111can be typed directly to the running shell or can be put into a file and
112the file can be executed directly by the shell. 112the file can be executed directly by the shell.
113.Ss Invocation 113.Ss Invocation
114If no arguments are present and if the standard input, 114If no arguments are present and if the standard input,
115and standard error output, of the shell 115and standard error output, of the shell
116are connected to a terminal (or terminals, or if the 116are connected to a terminal (or terminals, or if the
117.Fl i 117.Fl i
118flag is set), 118flag is set),
119and the 119and the
120.Fl c 120.Fl c
121option is not present, the shell is considered an interactive shell. 121option is not present, the shell is considered an interactive shell.
122An interactive shell generally prompts before each command and handles 122An interactive shell generally prompts before each command and handles
123programming and command errors differently (as described below). 123programming and command errors differently (as described below).
124When first starting, 124When first starting,
125the shell inspects argument 0, and if it begins with a dash 125the shell inspects argument 0, and if it begins with a dash
126.Sq - , 126.Sq - ,
127the shell is also considered 127the shell is also considered
128a login shell. 128a login shell.
129This is normally done automatically by the system 129This is normally done automatically by the system
130when the user first logs in. 130when the user first logs in.
131A login shell first reads commands 131A login shell first reads commands
132from the files 132from the files
133.Pa /etc/profile 133.Pa /etc/profile
134and 134and
135.Pa .profile 135.Pa .profile
136if they exist. 136if they exist.
137If the environment variable 137If the environment variable
138.Ev ENV 138.Ev ENV
139is set on entry to a shell, 139is set on entry to a shell,
140or is set in the 140or is set in the
141.Pa .profile 141.Pa .profile
142of a login shell, 142of a login shell,
143and either the shell is interactive, or the 143and either the shell is interactive, or the
144.Cm posix 144.Cm posix
145option is not set, 145option is not set,
146the shell next reads 146the shell next reads
147commands from the file named in 147commands from the file named in
148.Ev ENV . 148.Ev ENV .
149Therefore, a user should place commands that are to be executed only at 149Therefore, a user should place commands that are to be executed only at
150login time in the 150login time in the
151.Pa .profile 151.Pa .profile
152file, and commands that are executed for every shell inside the 152file, and commands that are executed for every shell inside the
153.Ev ENV 153.Ev ENV
154file. 154file.
155To set the 155To set the
156.Ev ENV 156.Ev ENV
157variable to some file, place the following line in your 157variable to some file, place the following line in your
158.Pa .profile 158.Pa .profile
159of your home directory 159of your home directory
160.Pp 160.Pp
161.Dl ENV=$HOME/.shinit; export ENV 161.Dl ENV=$HOME/.shinit; export ENV
162.Pp 162.Pp
163substituting for 163substituting for
164.Dq .shinit 164.Dq .shinit
165any filename you wish. 165any filename you wish.
166Since the 166Since the
167.Ev ENV 167.Ev ENV
168file can be read for every invocation of the shell, including shell scripts 168file can be read for every invocation of the shell, including shell scripts
169and non-interactive shells, the following paradigm is useful for 169and non-interactive shells, the following paradigm is useful for
170restricting commands in the 170restricting commands in the
171.Ev ENV 171.Ev ENV
172file to interactive invocations. 172file to interactive invocations.
173Place commands within the 173Place commands within the
174.Dq Ic case 174.Dq Ic case
175and 175and
176.Dq Ic esac 176.Dq Ic esac
177below (these commands are described later): 177below (these commands are described later):
178.Pp 178.Pp
179.Bl -item -compact -offset indent 179.Bl -item -compact -offset indent
180.It 180.It
181.Li case $- in *i*) 181.Li case $- in *i*)
182.Bl -item -compact -offset indent 182.Bl -item -compact -offset indent
183.It 183.It
184.Li # commands for interactive use only 184.Li # commands for interactive use only
185.It 185.It
186.Li ... 186.Li ...
187.El 187.El
188.It 188.It
189.Li esac 189.Li esac
190.El 190.El
191.Pp 191.Pp
192If command line arguments besides the options have been specified, and 192If command line arguments besides the options have been specified, and
193neither 193neither
194.Fl c 194.Fl c
195nor 195nor
196.Fl s 196.Fl s
197was given, then the shell treats the first argument 197was given, then the shell treats the first argument
198as the name of a file from which to read commands (a shell script). 198as the name of a file from which to read commands (a shell script).
199This also becomes $0 and the remaining arguments are set as the 199This also becomes $0 and the remaining arguments are set as the
200positional parameters of the shell ($1, $2, etc). 200positional parameters of the shell ($1, $2, etc).
201Otherwise, if 201Otherwise, if
202.Fl c 202.Fl c
203was given, then the first argument, which must exist, 203was given, then the first argument, which must exist,
204is taken to be a string of 204is taken to be a string of
205.Nm 205.Nm
206commands to execute. 206commands to execute.
207Then if any additional arguments follow the command string, 207Then if any additional arguments follow the command string,
208those arguments become $0, $1, ... 208those arguments become $0, $1, ...
209Otherwise, if additional arguments were given 209Otherwise, if additional arguments were given
210(which implies that 210(which implies that
211.Fl s 211.Fl s
212was set) 212was set)
213those arguments become $1, $2, ... 213those arguments become $1, $2, ...
214If $0 has not been set by the preceding processing, it 214If $0 has not been set by the preceding processing, it
215will be set to argv[0] as passed to the shell, which will 215will be set to argv[0] as passed to the shell, which will
216usually be the name of the shell itself. 216usually be the name of the shell itself.
217If 217If
218.Fl s 218.Fl s
219was given, or if neither 219was given, or if neither
220.Fl c 220.Fl c
221nor any additional (non-option) arguments were present, 221nor any additional (non-option) arguments were present,
222the shell reads commands from its standard input. 222the shell reads commands from its standard input.
223.Ss Argument List Processing 223.Ss Argument List Processing
224Currently, all of the single letter options that can meaningfully 224Currently, all of the single letter options that can meaningfully
225be set using the 225be set using the
226.Ic set 226.Ic set
227built-in, have a corresponding name 227built-in, have a corresponding name
228that can be used as an argument to the 228that can be used as an argument to the
229.Fl o 229.Fl o
230option. 230option.
231The set 231The set
232.Fl o 232.Fl o
233name is provided next to the single letter option in 233name is provided next to the single letter option in
234the description below. 234the description below.
235Some options have only a long name, they are described after 235Some options have only a long name, they are described after
236the flag options, they are used with 236the flag options, they are used with
237.Fl o 237.Fl o
238or 238or
239.Cm +o 239.Cm +o
240only, either on the command line, or with the 240only, either on the command line, or with the
241.Ic set 241.Ic set
242built-in command. 242built-in command.
243Other options described are for the command line only. 243Other options described are for the command line only.
244Specifying a dash 244Specifying a dash
245.Dq - 245.Dq -
246turns the option on, while using a plus 246turns the option on, while using a plus
247.Dq + 247.Dq +
248disables the option. 248disables the option.
249The following options can be set from the command line and, 249The following options can be set from the command line and,
250unless otherwise stated, with the 250unless otherwise stated, with the
251.Ic set 251.Ic set
252built-in (described later). 252built-in (described later).
253.\" 253.\"
254.\" strlen("quietprofile") == strlen("local_lineno"): pick the latter 254.\" strlen("quietprofile") == strlen("local_lineno"): pick the latter
255.\" to give the indent as the _ in local_lineno, and the fi ligature in 255.\" to give the indent as the _ in local_lineno, and the fi ligature in
256.\" quietprofile combine to make "local_lineno' slightly wider when printed 256.\" quietprofile combine to make "local_lineno' slightly wider when printed
257.\" (in italics) in a variable width font. Probably should test the actual 257.\" (in italics) in a variable width font. Probably should test the actual
258.\" widths and use the wider, but I am not sure if mandoc is up to that... 258.\" widths and use the wider, but I am not sure if mandoc is up to that...
259.\" (and I don't know how to get at the font that will be used easily anyway!) 259.\" (and I don't know how to get at the font that will be used easily anyway!)
260.\" The X's just provide a little extra space. 260.\" The X's just provide a little extra space.
261.Bl -tag -width \-WXXlocal_linenoXX -offset indent 261.Bl -tag -width \-WXXlocal_linenoXX -offset indent
262.\" 262.\"
263.It Fl a Em allexport 263.It Fl a Em allexport
264Automatically export any variable to which a value is assigned 264Automatically export any variable to which a value is assigned
265while this flag is set. 265while this flag is set.
266.It Fl b Em notify 266.It Fl b Em notify
267Enable asynchronous notification of background job completion. 267Enable asynchronous notification of background job completion.
268(Not implemented.) 268(Not implemented.)
269.It Fl C Em noclobber 269.It Fl C Em noclobber
270Don't overwrite existing files with 270Don't overwrite existing files with
271.Dq > . 271.Dq > .
272.It Fl c 272.It Fl c
273Read commands from the 273Read commands from the
274.Ar command_string 274.Ar command_string
275operand instead of, or in addition to, from the standard input. 275operand instead of, or in addition to, from the standard input.
276Special parameter 0 will be set from the 276Special parameter 0 will be set from the
277.Ar command_name 277.Ar command_name
278operand if given, and the positional parameters ($1, $2, etc.) 278operand if given, and the positional parameters ($1, $2, etc.)
279set from the remaining argument operands, if any. 279set from the remaining argument operands, if any.
280.Fl c 280.Fl c
281is only available at invocation, it cannot be 281is only available at invocation, it cannot be
282.Ic set , 282.Ic set ,
283and there is no form using 283and there is no form using
284.Dq \&+ . 284.Dq \&+ .
285.It Fl E Em emacs 285.It Fl E Em emacs
286Enable the built-in emacs style 286Enable the built-in emacs style
287command line editor (disables 287command line editor (disables
288.Fl V 288.Fl V
289if it has been set). 289if it has been set).
290(See the 290(See the
291.Sx Command Line Editing 291.Sx Command Line Editing
292section below.) 292section below.)
293.It Fl e Em errexit 293.It Fl e Em errexit
294If not interactive, exit immediately if any untested command fails. 294If not interactive, exit immediately if any untested command fails.
295If interactive, and an untested command fails, 295If interactive, and an untested command fails,
296cease all processing of the current command and return to 296cease all processing of the current command and return to
297prompt for a new command. 297prompt for a new command.
298The exit status of a command is considered to be 298The exit status of a command is considered to be
299explicitly tested if the command is used to control an 299explicitly tested if the command is used to control an
300.Ic if , 300.Ic if ,
301.Ic elif , 301.Ic elif ,
302.Ic while , 302.Ic while ,
303or 303or
304.Ic until , 304.Ic until ,
305or if the command is the left hand operand of an 305or if the command is the left hand operand of an
306.Dq && 306.Dq &&
307or 307or
308.Dq || 308.Dq ||
309operator, 309operator,
310or if it is a pipeline (or simple command) preceded by the 310or if it is a pipeline (or simple command) preceded by the
311.Dq \&! 311.Dq \&!
312operator. 312operator.
313With pipelines, only the status of the entire pipeline 313With pipelines, only the status of the entire pipeline
314(indicated by the last command it contains) 314(indicated by the last command it contains)
315is tested when 315is tested when
316.Fl e 316.Fl e
317is set to determine if the shell should exit. 317is set to determine if the shell should exit.
318.It Fl F Em fork 318.It Fl F Em fork
319Cause the shell to always use 319Cause the shell to always use
320.Xr fork 2 320.Xr fork 2
321instead of attempting 321instead of attempting
322.Xr vfork 2 322.Xr vfork 2
323when it needs to create a new process. 323when it needs to create a new process.
324This should normally have no visible effect, 324This should normally have no visible effect,
325but can slow execution. 325but can slow execution.
326The 326The
327.Nm 327.Nm
328can be compiled to always use 328can be compiled to always use
329.Xr fork 2 329.Xr fork 2
330in which case altering the 330in which case altering the
331.Fl F 331.Fl F
332flag has no effect. 332flag has no effect.
333.It Fl f Em noglob 333.It Fl f Em noglob
334Disable pathname expansion. 334Disable pathname expansion.
335.It Fl h Em trackall 335.It Fl h Em trackall
336Functions defined while this option is set will have paths bound to 336Functions defined while this option is set will have paths bound to
337commands to be executed by the function at the time of the definition. 337commands to be executed by the function at the time of the definition.
338When off when a function is defined, 338When off when a function is defined,
339the file system is searched for commands each time the function is invoked. 339the file system is searched for commands each time the function is invoked.
340(Not implemented.) 340(Not implemented.)
341.It Fl I Em ignoreeof 341.It Fl I Em ignoreeof
342Ignore EOFs from input when interactive. 342Ignore EOFs from input when interactive.
343(After a large number of consecutive EOFs the shell will exit anyway.) 343(After a large number of consecutive EOFs the shell will exit anyway.)
344.It Fl i Em interactive 344.It Fl i Em interactive
345Force the shell to behave interactively. 345Force the shell to behave interactively.
346.It Fl L Em local_lineno 346.It Fl L Em local_lineno
347When set, before a function is defined, 347When set, before a function is defined,
348causes the variable 348causes the variable
349.Ev LINENO 349.Ev LINENO
350when used within the function, 350when used within the function,
351to refer to the line number defined such that 351to refer to the line number defined such that
352first line of the function is line 1. 352first line of the function is line 1.
353When reset, 353When reset,
354.Ev LINENO 354.Ev LINENO
355in a function refers to the line number within the file 355in a function refers to the line number within the file
356within which the definition of the function occurs. 356within which the definition of the function occurs.
357This option defaults to 357This option defaults to
358.Dq on 358.Dq on
359in this shell. 359in this shell.
360For more details see the section 360For more details see the section
361.Sx LINENO 361.Sx LINENO
362below. 362below.
363.It Fl m Em monitor 363.It Fl m Em monitor
364Turn on job control (set automatically when interactive). 364Turn on job control (set automatically when interactive).
365.It Fl n Em noexec 365.It Fl n Em noexec
366Read and parse commands, but do not execute them. 366Read and parse commands, but do not execute them.
367This is useful for checking the syntax of shell scripts. 367This is useful for checking the syntax of shell scripts.
368If 368If
369.Fl n 369.Fl n
370becomes set in an interactive shell, it will automatically be 370becomes set in an interactive shell, it will automatically be
371cleared just before the next time the command line prompt 371cleared just before the next time the command line prompt
372.Pq Ev PS1 372.Pq Ev PS1
373is written. 373is written.
374.It Fl p Em nopriv 374.It Fl p Em nopriv
375Do not attempt to reset effective UID if it does not match UID. 375Do not attempt to reset effective UID if it does not match UID.
376This is not set by default to help avoid incorrect usage by setuid 376This is not set by default to help avoid incorrect usage by setuid
377root programs via 377root programs via
378.Xr system 3 378.Xr system 3
379or 379or
380.Xr popen 3 . 380.Xr popen 3 .
381.It Fl q Em quietprofile 381.It Fl q Em quietprofile
382If the 382If the
383.Fl v 383.Fl v
384or 384or
385.Fl x 385.Fl x
386options have been set, do not apply them when reading 386options have been set, do not apply them when reading
387initialization files, these being 387initialization files, these being
388.Pa /etc/profile , 388.Pa /etc/profile ,
389.Pa .profile , 389.Pa .profile ,
390and the file specified by the 390and the file specified by the
391.Ev ENV 391.Ev ENV
392environment variable. 392environment variable.
393.It Fl s Em stdin 393.It Fl s Em stdin
394Read commands from standard input (set automatically if 394Read commands from standard input (set automatically if
395neither 395neither
396.Fl c 396.Fl c
397nor file arguments are present). 397nor file arguments are present).
398If after processing a command_string with the 398If after processing a command_string with the
399.Fl c 399.Fl c
400option, the shell has not exited, and the 400option, the shell has not exited, and the
401.Fl s 401.Fl s
402option is set, it will continue reading more commands from standard input. 402option is set, it will continue reading more commands from standard input.
403This option has no effect when set or reset after the shell has 403This option has no effect when set or reset after the shell has
404already started reading from the command_file, or from standard input. 404already started reading from the command_file, or from standard input.
405Note that the 405Note that the
406.Fl s 406.Fl s
407flag being set does not cause the shell to be interactive. 407flag being set does not cause the shell to be interactive.
408.It Fl u Em nounset 408.It Fl u Em nounset
409Write a message to standard error when attempting to obtain a 409Write a message to standard error when attempting to obtain a
410value from a variable that is not set, 410value from a variable that is not set,
411and if the shell is not interactive, exit immediately. 411and if the shell is not interactive, exit immediately.
412For interactive shells, instead return immediately to the command prompt 412For interactive shells, instead return immediately to the command prompt
413and read the next command. 413and read the next command.
414Note that expansions (described later, see 414Note that expansions (described later, see
415.Sx Word Expansions 415.Sx Word Expansions
416below) using the 416below) using the
417.Sq \&+ , 417.Sq \&+ ,
418.Sq \&\- , 418.Sq \&\- ,
419.Sq \&= , 419.Sq \&= ,
420or 420or
421.Sq \&? 421.Sq \&?
422operators test if the variable is set, before attempting to 422operators test if the variable is set, before attempting to
423obtain its value, and hence are unaffected by 423obtain its value, and hence are unaffected by
424.Fl u . 424.Fl u .
425.It Fl V Em vi 425.It Fl V Em vi
426Enable the built-in 426Enable the built-in
427.Xr vi 1 427.Xr vi 1
428command line editor (disables 428command line editor (disables
429.Fl E 429.Fl E
430if it has been set). 430if it has been set).
431(See the 431(See the
432.Sx Command Line Editing 432.Sx Command Line Editing
433section below.) 433section below.)
434.It Fl v Em verbose 434.It Fl v Em verbose
435The shell writes its input to standard error as it is read. 435The shell writes its input to standard error as it is read.
436Useful for debugging. 436Useful for debugging.
437.It Fl X Em Xtrace 437.It Fl X Em Xtrace
438Cause output from the 438Cause output from the
439.Ic xtrace 439.Ic xtrace
440.Pq Fl x 440.Pq Fl x
441option to be sent to standard error as it exists when the 441option to be sent to standard error as it exists when the
442.Fl X 442.Fl X
443option is enabled (regardless of its previous state.) 443option is enabled (regardless of its previous state.)
444For example: 444For example:
445.Bd -literal -compact 445.Bd -literal -compact
446 set -X 2>/tmp/trace-file 446 set -X 2>/tmp/trace-file
447.Ed 447.Ed
448will arrange for tracing output to be sent to the file named, 448will arrange for tracing output to be sent to the file named,
449instead of wherever it was previously being sent, 449instead of wherever it was previously being sent,
450until the X option is set again, or cleared. 450until the X option is set again, or cleared.
451.Pp 451.Pp
452Each change (set or clear) to 452Each change (set or clear) to
453.Fl X 453.Fl X
454is also performed upon 454is also performed upon
455.Fl x , 455.Fl x ,
456but not the converse. 456but not the converse.
457.It Fl x Em xtrace 457.It Fl x Em xtrace
458Write each command to standard error (preceded by the expanded value of 458Write each command to standard error (preceded by the expanded value of
459.Dq $PS4 ) 459.Dq $PS4 )
460before it is executed. 460before it is executed.
461Unless 461Unless
462.Fl X 462.Fl X
463is set, 463is set,
464.Dq "standard error" 464.Dq "standard error"
465means that which existed immediately before any redirections to 465means that which existed immediately before any redirections to
466be applied to the command are performed. 466be applied to the command are performed.
467Useful for debugging. 467Useful for debugging.
468.It "\ \ " Em cdprint 468.It "\ \ " Em cdprint
469Make an interactive shell always print the new directory name when 469Make an interactive shell always print the new directory name when
470changed by the 470changed by the
471.Ic cd 471.Ic cd
472command. 472command.
473In a non-interactive shell this option has no effect. 473In a non-interactive shell this option has no effect.
474.It "\ \ " Em nolog 474.It "\ \ " Em nolog
475Prevent the entry of function definitions into the command history (see 475Prevent the entry of function definitions into the command history (see
476.Ic fc 476.Ic fc
477in the 477in the
478.Sx Built-ins 478.Sx Built-ins
479section.) 479section.)
480(Not implemented.) 480(Not implemented.)
481.It "\ \ " Em pipefail 481.It "\ \ " Em pipefail
482If set, the way the exit status of a pipeline is determined 482If set, the way the exit status of a pipeline is determined
483is altered. 483is altered.
484See 484See
485.Sx Pipelines 485.Sx Pipelines
486below for the details. 486below for the details.
487.It "\ \ " Em posix 487.It "\ \ " Em posix
488Enables closer adherence to the POSIX shell standard. 488Enables closer adherence to the POSIX shell standard.
489This option will default set at shell startup if the 489This option will default set at shell startup if the
490environment variable 490environment variable
491.Ev POSIXLY_CORRECT 491.Ev POSIXLY_CORRECT
492is present. 492is present.
493That can be overridden (set or reset) by the 493That can be overridden (set or reset) by the
494.Fl o 494.Fl o
495option on the command line. 495option on the command line.
496Currently this option controls whether (!posix) or not (posix) 496Currently this option controls whether (!posix) or not (posix)
497the file given by the 497the file given by the
498.Ev ENV 498.Ev ENV
499variable is read at startup by a non-interactive shell. 499variable is read at startup by a non-interactive shell.
500It also controls whether file descriptors greater than 2 500It also controls whether file descriptors greater than 2
501opened using the 501opened using the
502.Ic exec 502.Ic exec
503built-in command are passed on to utilities executed 503built-in command are passed on to utilities executed
504.Dq ( yes 504.Dq ( yes
505in posix mode), 505in posix mode),
506whether a colon (:) terminates the user name in tilde (~) expansions 506whether a colon (:) terminates the user name in tilde (~) expansions
507other than in assignment statements 507other than in assignment statements
508.Dq ( no 508.Dq ( no
509in posix mode), 509in posix mode),
510and whether the shell treats 510and whether the shell treats
511an empty brace-list compound statement as a syntax error 511an empty brace-list compound statement as a syntax error
512(expected by POSIX) or permits it. 512(expected by POSIX) or permits it.
513Such statements 513Such statements
514.Dq "{ }" 514.Dq "{ }"
515can be useful when defining dummy functions. 515can be useful when defining dummy functions.
516Lastly, in posix mode, only one 516Lastly, in posix mode, only one
517.Dq \&! 517.Dq \&!
518is permitted before a pipeline. 518is permitted before a pipeline.
519.It "\ \ " Em promptcmds 519.It "\ \ " Em promptcmds
520Allows command substitutions (as well as parameter 520Allows command substitutions (as well as parameter
521and arithmetic expansions, which are always performed) 521and arithmetic expansions, which are always performed)
522upon the prompt strings 522upon the prompt strings
523.Ev PS1 , 523.Ev PS1 ,
524.Ev PS2 , 524.Ev PS2 ,
525and 525and
526.Ev PS4 526.Ev PS4
527each time, before they are output. 527each time, before they are output.
528This option should not be set until after the prompts 528This option should not be set until after the prompts
529have been set (or verified) to avoid accidentally importing 529have been set (or verified) to avoid accidentally importing
530unwanted command substitutions from the environment. 530unwanted command substitutions from the environment.
531.It "\ \ " Em tabcomplete 531.It "\ \ " Em tabcomplete
532Enables filename completion in the command line editor. 532Enables filename completion in the command line editor.
533Typing a tab character will extend the current input word to match a 533Typing a tab character will extend the current input word to match a
534filename. 534filename.
535If more than one filename matches it is only extended to be the common prefix. 535If more than one filename matches it is only extended to be the common prefix.
536Typing a second tab character will list all the matching names. 536Typing a second tab character will list all the matching names.
537One of the editing modes, either 537One of the editing modes, either
538.Fl E 538.Fl E
539or 539or
540.Fl V , 540.Fl V ,
541must be enabled for this to work. 541must be enabled for this to work.
542.El 542.El
543.Ss Lexical Structure 543.Ss Lexical Structure
544The shell reads input in terms of lines from a file and breaks it up into 544The shell reads input in terms of lines from a file and breaks it up into
545words at whitespace (blanks and tabs), and at certain sequences of 545words at whitespace (blanks and tabs), and at certain sequences of
546characters that are special to the shell called 546characters that are special to the shell called
547.Dq operators . 547.Dq operators .
548There are two types of operators: control operators and redirection 548There are two types of operators: control operators and redirection
549operators (their meaning is discussed later). 549operators (their meaning is discussed later).
550The following is a list of operators: 550The following is a list of operators:
551.Bl -ohang -offset indent 551.Bl -ohang -offset indent
552.It "Control operators:" 552.It "Control operators:"
553.Dl & && \&( \&) \&; ;; ;& | || <newline> 553.Dl & && \&( \&) \&; ;; ;& \&| || <newline>
554.It "Redirection operators:" 554.It "Redirection operators:"
555.Dl < > >| << >> <& >& <<- <> 555.Dl < > >| << >> <& >& <<- <>
556.El 556.El
557.Ss Quoting 557.Ss Quoting
558Quoting is used to remove the special meaning of certain characters or 558Quoting is used to remove the special meaning of certain characters or
559words to the shell, such as operators, whitespace, or keywords. 559words to the shell, such as operators, whitespace, or keywords.
560There are four types of quoting: 560There are four types of quoting:
561matched single quotes, 561matched single quotes,
562matched double quotes, 562matched double quotes,
563backslash, 563backslash,
564and 564and
565dollar preceding matched single quotes (enhanced C style strings.) 565dollar preceding matched single quotes (enhanced C style strings.)
566.Ss Backslash 566.Ss Backslash
567An unquoted backslash preserves the literal meaning of the following 567An unquoted backslash preserves the literal meaning of the following
568character, with the exception of 568character, with the exception of
569.Aq newline . 569.Aq newline .
570An unquoted backslash preceding a 570An unquoted backslash preceding a
571.Aq newline 571.Aq newline
572is treated as a line continuation, the two characters are simply removed. 572is treated as a line continuation, the two characters are simply removed.
573.Ss Single Quotes 573.Ss Single Quotes
574Enclosing characters in single quotes preserves the literal meaning of all 574Enclosing characters in single quotes preserves the literal meaning of all
575the characters (except single quotes, making it impossible to put 575the characters (except single quotes, making it impossible to put
576single quotes in a single-quoted string). 576single quotes in a single-quoted string).
577.Ss Double Quotes 577.Ss Double Quotes
578Enclosing characters within double quotes preserves the literal 578Enclosing characters within double quotes preserves the literal
579meaning of all characters except dollar sign 579meaning of all characters except dollar sign
580.Pq $ , 580.Pq $ ,
581backquote 581backquote
582.Pq ` , 582.Pq ` ,
583and backslash 583and backslash
584.Pq \e . 584.Pq \e .
585The backslash inside double quotes is historically weird, and serves to 585The backslash inside double quotes is historically weird, and serves to
586quote only the following characters (and these not in all contexts): 586quote only the following characters (and these not in all contexts):
587.Dl $ ` \*q \e <newline> , 587.Dl $ ` \*q \e <newline> ,
588where a backslash newline is a line continuation as above. 588where a backslash newline is a line continuation as above.
589Otherwise it remains literal. 589Otherwise it remains literal.
590.Ss Dollar Single Quotes (\&$'...') 590.Ss Dollar Single Quotes (\&$'...')
591.Bd -filled -offset indent 591.Bd -filled -offset indent
592.Bf Em 592.Bf Em
593Note: this form of quoting is still somewhat experimental, 593Note: this form of quoting is still somewhat experimental,
594and yet to be included in the POSIX standard. 594and yet to be included in the POSIX standard.
595This implementation is based upon the current proposals for 595This implementation is based upon the current proposals for
596standardization, and is subject to change should the eventual 596standardization, and is subject to change should the eventual
597adopted text differ. 597adopted text differ.
598.Ef 598.Ef
599.Ed 599.Ed
600.Pp 600.Pp
601Enclosing characters in a matched pair of single quotes, with the 601Enclosing characters in a matched pair of single quotes, with the
602first immediately preceded by an unquoted dollar sign 602first immediately preceded by an unquoted dollar sign
603.Pq \&$ 603.Pq \&$
604provides a quoting mechanism similar to single quotes, except 604provides a quoting mechanism similar to single quotes, except
605that within the sequence of characters, any backslash 605that within the sequence of characters, any backslash
606.Pq \e , 606.Pq \e ,
607is an escape character, which causes the following character to 607is an escape character, which causes the following character to
608be treated specially. 608be treated specially.
609Only a subset of the characters that can occur in the string 609Only a subset of the characters that can occur in the string
610are defined after a backslash, others are reserved for future 610are defined after a backslash, others are reserved for future
611definition, and currently generate a syntax error if used. 611definition, and currently generate a syntax error if used.
612The escape sequences are modeled after the similar sequences 612The escape sequences are modeled after the similar sequences
613in strings in the C programming language, with some extensions. 613in strings in the C programming language, with some extensions.
614.Pp 614.Pp
615The following characters are treated literally when following 615The following characters are treated literally when following
616the escape character (backslash): 616the escape character (backslash):
617.Dl \e \&' \&" 617.Dl \e \&' \&"
618The sequence 618The sequence
619.Dq \e\e 619.Dq \e\e
620allows the escape character (backslash) to appear in the string literally. 620allows the escape character (backslash) to appear in the string literally.
621.Dq \e' 621.Dq \e'
622allows a single quote character into the string, such an 622allows a single quote character into the string, such an
623escaped single quote does not terminate the quoted string. 623escaped single quote does not terminate the quoted string.
624.Dq \e" 624.Dq \e"
625is for compatibility with C strings, the double quote has 625is for compatibility with C strings, the double quote has
626no special meaning in a shell C-style string, 626no special meaning in a shell C-style string,
627and does not need to be escaped, but may be. 627and does not need to be escaped, but may be.
628.Pp 628.Pp
629A newline following the escape character is treated as a line continuation, 629A newline following the escape character is treated as a line continuation,
630like the same sequence in a double quoted string, 630like the same sequence in a double quoted string,
631or when not quoted \(en 631or when not quoted \(en
632the two characters, escape and newline, are removed from the input string. 632the two characters, escape and newline, are removed from the input string.
633.Pp 633.Pp
634The following characters, when escaped, are converted in a 634The following characters, when escaped, are converted in a
635manner similar to the way they would be in a string in the C language: 635manner similar to the way they would be in a string in the C language:
636.Dl a b e f n r t v 636.Dl a b e f n r t v
637An escaped 637An escaped
638.Sq a 638.Sq a
639generates an alert (or 639generates an alert (or
640.Sq BEL ) 640.Sq BEL )
641character, that is, control-G, or 0x07. 641character, that is, control-G, or 0x07.
642In a similar way, 642In a similar way,
643.Sq b 643.Sq b
644is backspace (0x08), 644is backspace (0x08),
645.Sq e 645.Sq e
646(an extension to C) is escape (0x1B), 646(an extension to C) is escape (0x1B),
647.Sq f 647.Sq f
648is form feed (0x0C), 648is form feed (0x0C),
649.Sq n 649.Sq n
650is newline (or line feed, 0x0A), 650is newline (or line feed, 0x0A),
651.Sq r 651.Sq r
652is return (0x0D), 652is return (0x0D),
653.Sq t 653.Sq t
654is horizontal tab (0x09), 654is horizontal tab (0x09),
655and 655and
656.Sq v 656.Sq v
657is vertical tab (0x13). 657is vertical tab (0x13).
658.Pp 658.Pp
659In addition to those there are 5 forms that need additional 659In addition to those there are 5 forms that need additional
660data, which is obtained from the subsequent characters. 660data, which is obtained from the subsequent characters.
661An escape 661An escape
662.Pq \e 662.Pq \e
663followed by one, two or three, octal digits 663followed by one, two or three, octal digits
664.Po So 0 Sc Ns \&.. Ns So 7 Sc Ns Pc 664.Po So 0 Sc Ns \&.. Ns So 7 Sc Ns Pc
665is processed to form an 8 bit character value. 665is processed to form an 8 bit character value.
666If only one or two digits are present, the following 666If only one or two digits are present, the following
667character must be something other than an octal digit. 667character must be something other than an octal digit.
668It is safest to always use all 3 digits, with leading 668It is safest to always use all 3 digits, with leading
669zeros if needed. 669zeros if needed.
670If all three digits are present, the first must be one of 670If all three digits are present, the first must be one of
671.So 0 Sc Ns \&.. Ns So 3 Sc . 671.So 0 Sc Ns \&.. Ns So 3 Sc .
672.Pp 672.Pp
673An escape followed by 673An escape followed by
674.Sq x 674.Sq x
675(lower case only) can be followed by one or two 675(lower case only) can be followed by one or two
676hexadecimal digits 676hexadecimal digits
677.Po So 0 Sc Ns \&.. Ns So 9 Sc , So A Sc Ns \&.. Ns So F Sc , or So a Sc Ns \&.. Ns So f Sc . Pc 677.Po So 0 Sc Ns \&.. Ns So 9 Sc , So A Sc Ns \&.. Ns So F Sc , or So a Sc Ns \&.. Ns So f Sc . Pc
678As with octal, if only one hex digit is present, the following 678As with octal, if only one hex digit is present, the following
679character must be something other than a hex digit, 679character must be something other than a hex digit,
680so always giving 2 hex digits is best. 680so always giving 2 hex digits is best.
681However, unlike octal, it is unspecified in the standard 681However, unlike octal, it is unspecified in the standard
682how many hex digits can be consumed. 682how many hex digits can be consumed.
683This 683This
684.Nm 684.Nm
685takes at most two, but other shells will continue consuming 685takes at most two, but other shells will continue consuming
686characters as long as they remain valid hex digits. 686characters as long as they remain valid hex digits.
687Consequently, users should ensure that the character 687Consequently, users should ensure that the character
688following the hex escape sequence is something other than 688following the hex escape sequence is something other than
689a hex digit. 689a hex digit.
690One way to achieve this is to end the $'...' string immediately 690One way to achieve this is to end the $'...' string immediately
691after the final hex digit, and then, immediately start 691after the final hex digit, and then, immediately start
692another, so 692another, so
693.Dl \&$'\ex33'$'4...' 693.Dl \&$'\ex33'$'4...'
694always gives the character with value 0x33 694always gives the character with value 0x33
695.Pq Sq 3 , 695.Pq Sq 3 ,
696followed by the character 696followed by the character
697.Sq 4 , 697.Sq 4 ,
698whereas 698whereas
699.Dl \&$'\ex334' 699.Dl \&$'\ex334'
700in some other shells would be the hex value 0x334 (10, or more, bits). 700in some other shells would be the hex value 0x334 (10, or more, bits).
701.Pp 701.Pp
702There are two escape sequences beginning with 702There are two escape sequences beginning with
703.Sq \eu 703.Sq \eu
704or 704or
705.Sq \eU . 705.Sq \eU .
706The former is followed by from 1 to 4 hex digits, the latter by 706The former is followed by from 1 to 4 hex digits, the latter by
707from 1 to 8 hex digits. 707from 1 to 8 hex digits.
708Leading zeros can be used to pad the sequences to the maximum 708Leading zeros can be used to pad the sequences to the maximum
709permitted length, to avoid any possible ambiguity problem with 709permitted length, to avoid any possible ambiguity problem with
710the following character, and because there are some shells that 710the following character, and because there are some shells that
711insist on exactly 4 (or 8) hex digits. 711insist on exactly 4 (or 8) hex digits.
712These sequences are evaluated to form the value of a Unicode code 712These sequences are evaluated to form the value of a Unicode code
713point, which is then encoded into UTF-8 form, and entered into the 713point, which is then encoded into UTF-8 form, and entered into the
714string. 714string.
715(The code point should be converted to the appropriate 715(The code point should be converted to the appropriate
716code point value for the corresponding character in the character 716code point value for the corresponding character in the character
717set given by the current locale, or perhaps the locale in use 717set given by the current locale, or perhaps the locale in use
718when the shell was started, but is not... currently.) 718when the shell was started, but is not... currently.)
719Not all values that are possible to write are valid, values that 719Not all values that are possible to write are valid, values that
720specify (known) invalid Unicode code points will be rejected, or 720specify (known) invalid Unicode code points will be rejected, or
721simply produce 721simply produce
722.Sq \&? . 722.Sq \&? .
723.Pp 723.Pp
724Lastly, as another addition to what is available in C, the escape 724Lastly, as another addition to what is available in C, the escape
725character (backslash), followed by 725character (backslash), followed by
726.Sq c 726.Sq c
727(lower case only) followed by one additional character, which must 727(lower case only) followed by one additional character, which must
728be an alphabetic character (a letter), or one of the following: 728be an alphabetic character (a letter), or one of the following:
729.Dl \&@ \&[ \&\e \&] \&^ \&_ \&? 729.Dl \&@ \&[ \&\e \&] \&^ \&_ \&?
730Other than 730Other than
731.Sq \ec? 731.Sq \ec?
732the value obtained is the least significant 5 bits of the 732the value obtained is the least significant 5 bits of the
733ASCII value of the character following the 733ASCII value of the character following the
734.Sq \ec 734.Sq \ec
735escape sequence. 735escape sequence.
736That is what is commonly known as the 736That is what is commonly known as the
737.Dq control 737.Dq control
738character obtained from the given character. 738character obtained from the given character.
739The escape sequence 739The escape sequence
740.Sq \ec? 740.Sq \ec?
741yields the ASCII DEL character (0x7F). 741yields the ASCII DEL character (0x7F).
742Note that to obtain the ASCII FS character (0x1C) this way, 742Note that to obtain the ASCII FS character (0x1C) this way,
743.Pq "that is control-\e" 743.Pq "that is control-\e"
744the trailing 744the trailing
745.Sq \e 745.Sq \e
746must be escaped itself, and so for this one case, the full 746must be escaped itself, and so for this one case, the full
747escape sequence is 747escape sequence is
748.Dq \ec\e\e . 748.Dq \ec\e\e .
749The sequence 749The sequence
750.Dq \ec\eX 750.Dq \ec\eX
751where 751where
752.Sq X 752.Sq X
753is some character other than 753is some character other than
754.Sq \e 754.Sq \e
755is reserved for future use, its meaning is unspecified. 755is reserved for future use, its meaning is unspecified.
756In this 756In this
757.Nm 757.Nm
758an error is generated. 758an error is generated.
759.Pp 759.Pp
760If any of the preceding escape sequences generate the value 760If any of the preceding escape sequences generate the value
761.Sq \e0 761.Sq \e0
762(a NUL character) that character, and all that follow in the 762(a NUL character) that character, and all that follow in the
763same $'...' string, are omitted from the resulting word. 763same $'...' string, are omitted from the resulting word.
764.Pp 764.Pp
765After the $'...' string has had any included escape sequences 765After the $'...' string has had any included escape sequences
766converted, it is treated as if it had been a single quoted string. 766converted, it is treated as if it had been a single quoted string.
767.Ss Reserved Words 767.Ss Reserved Words
768Reserved words are words that have special meaning to the 768Reserved words are words that have special meaning to the
769shell and are recognized at the beginning of a line and 769shell and are recognized at the beginning of a line and
770after a control operator. 770after a control operator.
771The following are reserved words: 771The following are reserved words:
772.Bl -column while while while while -offset indent 772.Bl -column while while while while -offset indent
773.It Ic \&! Ta Ic \&{ Ta Ic \&} Ta Ic case 773.It Ic \&! Ta Ic \&{ Ta Ic \&} Ta Ic case
774.It Ic do Ta Ic done Ta Ic elif Ta Ic else 774.It Ic do Ta Ic done Ta Ic elif Ta Ic else
775.It Ic esac Ta Ic fi Ta Ic for Ta Ic if 775.It Ic esac Ta Ic fi Ta Ic for Ta Ic if
776.It Ic in Ta Ic then Ta Ic until Ta Ic while 776.It Ic in Ta Ic then Ta Ic until Ta Ic while
777.El 777.El
778.Pp 778.Pp
779Their meanings are discussed later. 779Their meanings are discussed later.
780.Ss Aliases 780.Ss Aliases
781An alias is a name and corresponding value set using the 781An alias is a name and corresponding value set using the
782.Ic alias 782.Ic alias
783built-in command. 783built-in command.
784Whenever a reserved word (see above) may occur, 784Whenever a reserved word (see above) may occur,
785and after checking for reserved words, the shell 785and after checking for reserved words, the shell
786checks the word to see if it matches an alias. 786checks the word to see if it matches an alias.
787If it does, it replaces it in the input stream with its value. 787If it does, it replaces it in the input stream with its value.
788For example, if there is an alias called 788For example, if there is an alias called
789.Dq lf 789.Dq lf
790with the value 790with the value
791.Dq "ls -F" , 791.Dq "ls -F" ,
792then the input: 792then the input:
793.Pp 793.Pp
794.Dl lf foobar Aq return 794.Dl lf foobar Aq return
795.Pp 795.Pp
796would become 796would become
797.Pp 797.Pp
798.Dl ls -F foobar Aq return 798.Dl ls -F foobar Aq return
799.Pp 799.Pp
800Aliases provide a convenient way for naive users to create shorthands for 800Aliases provide a convenient way for naive users to create shorthands for
801commands without having to learn how to create functions with arguments. 801commands without having to learn how to create functions with arguments.
802They can also be used to create lexically obscure code. 802They can also be used to create lexically obscure code.
803This use is strongly discouraged. 803This use is strongly discouraged.
804.Ss Commands 804.Ss Commands
805The shell interprets the words it reads according to a language, the 805The shell interprets the words it reads according to a language, the
806specification of which is outside the scope of this man page (refer to the 806specification of which is outside the scope of this man page (refer to the
807BNF in the POSIX 1003.2 document). 807BNF in the POSIX 1003.2 document).
808Essentially though, a line is read and if the first 808Essentially though, a line is read and if the first
809word of the line (or after a control operator) is not a reserved word, 809word of the line (or after a control operator) is not a reserved word,
810then the shell has recognized a simple command. 810then the shell has recognized a simple command.
811Otherwise, a complex 811Otherwise, a complex
812command or some other special construct may have been recognized. 812command or some other special construct may have been recognized.
813.Ss Simple Commands 813.Ss Simple Commands
814If a simple command has been recognized, the shell performs 814If a simple command has been recognized, the shell performs
815the following actions: 815the following actions:
816.Bl -enum -offset indent 816.Bl -enum -offset indent
817.It 817.It
818Leading words of the form 818Leading words of the form
819.Dq name=value 819.Dq name=value
820are stripped off, the value is expanded, as described below, 820are stripped off, the value is expanded, as described below,
821and the results are assigned to the environment of the simple command. 821and the results are assigned to the environment of the simple command.
822Redirection operators and their arguments (as described below) are 822Redirection operators and their arguments (as described below) are
823stripped off and saved for processing in step 3 below. 823stripped off and saved for processing in step 3 below.
824.It 824.It
825The remaining words are expanded as described in the 825The remaining words are expanded as described in the
826.Sx Word Expansions 826.Sx Word Expansions
827section below. 827section below.
828The first remaining word is considered the command name and the 828The first remaining word is considered the command name and the
829command is located. 829command is located.
830Any remaining words are considered the arguments of the command. 830Any remaining words are considered the arguments of the command.
831If no command name resulted, then the 831If no command name resulted, then the
832.Dq name=value 832.Dq name=value
833variable assignments recognized in item 1 affect the current shell. 833variable assignments recognized in item 1 affect the current shell.
834.It 834.It
835Redirections are performed, from first to last, in the order given, 835Redirections are performed, from first to last, in the order given,
836as described in the next section. 836as described in the next section.
837.El 837.El
838.Ss Redirections 838.Ss Redirections
839Redirections are used to change where a command reads its input or sends 839Redirections are used to change where a command reads its input or sends
840its output. 840its output.
841In general, redirections open, close, or duplicate an 841In general, redirections open, close, or duplicate an
842existing reference to a file. 842existing reference to a file.
843The overall format used for redirection is: 843The overall format used for redirection is:
844.Pp 844.Pp
845.Dl [n] Ns Va redir-op Ar file 845.Dl [n] Ns Va redir-op Ar file
846.Pp 846.Pp
847where 847where
848.Va redir-op 848.Va redir-op
849is one of the redirection operators mentioned previously. 849is one of the redirection operators mentioned previously.
850The following is a list of the possible redirections. 850The following is a list of the possible redirections.
851The 851The
852.Bq n 852.Bq n
853is an optional number, as in 853is an optional number, as in
854.Sq 3 854.Sq 3
855(not 855(not
856.Sq Bq 3 ) , 856.Sq Bq 3 ) ,
857that refers to a file descriptor. 857that refers to a file descriptor.
858If present it must occur immediately before the redirection 858If present it must occur immediately before the redirection
859operator, with no intervening white space, and becomes a 859operator, with no intervening white space, and becomes a
860part of that operator. 860part of that operator.
861.Bl -tag -width aaabsfiles -offset indent 861.Bl -tag -width aaabsfiles -offset indent
862.It Oo Ar n Oc Ns > Ar file 862.It Oo Ar n Oc Ns > Ar file
863Redirect standard output (or n) to 863Redirect standard output (or n) to
864.Ar file . 864.Ar file .
865.It Oo Ar n Oc Ns >| file 865.It Oo Ar n Oc Ns >| file
866The same, but override the 866The same, but override the
867.Fl C 867.Fl C
868option. 868option.
869.It Oo Ar n Oc Ns >> Ar file 869.It Oo Ar n Oc Ns >> Ar file
870Append standard output (or n) to 870Append standard output (or n) to
871.Ar file . 871.Ar file .
872.It Oo Ar n Oc Ns < Ar file 872.It Oo Ar n Oc Ns < Ar file
873Redirect standard input (or 873Redirect standard input (or
874.Ar n ) 874.Ar n )
875from 875from
876.Ar file . 876.Ar file .
877.It Oo Ar n1 Oc Ns <& Ns Ar n2 877.It Oo Ar n1 Oc Ns <& Ns Ar n2
878Duplicate standard input (or 878Duplicate standard input (or
879.Ar n1 ) 879.Ar n1 )
880from file descriptor 880from file descriptor
881.Ar n2 . 881.Ar n2 .
882.Ar n2 882.Ar n2
883is expanded if not a digit string, the result must be a number. 883is expanded if not a digit string, the result must be a number.
884.It Oo Ar n Oc Ns <&- 884.It Oo Ar n Oc Ns <&-
885Close standard input (or 885Close standard input (or
886.Ar n ) . 886.Ar n ) .
887.It Oo Ar n1 Oc Ns >& Ns Ar n2 887.It Oo Ar n1 Oc Ns >& Ns Ar n2
888Duplicate standard output (or 888Duplicate standard output (or
889.Ar n1 ) 889.Ar n1 )
890to 890to
891.Ar n2 . 891.Ar n2 .
892.It Oo Ar n Oc Ns >&- 892.It Oo Ar n Oc Ns >&-
893Close standard output (or n). 893Close standard output (or n).
894.It Oo Ar n Oc Ns <> Ar file 894.It Oo Ar n Oc Ns <> Ar file
895Open 895Open
896.Ar file 896.Ar file
897for reading and writing on standard input (or 897for reading and writing on standard input (or
898.Ar n ) . 898.Ar n ) .
899.El 899.El
900.Pp 900.Pp
901The following redirection is often called a 901The following redirection is often called a
902.Dq here-document . 902.Dq here-document .
903.Bl -item -offset indent 903.Bl -item -offset indent
904.It 904.It
905.Li [n]<< delimiter 905.Li [n]<< delimiter
906.Dl here-doc-text ... 906.Dl here-doc-text ...
907.Li delimiter 907.Li delimiter
908.El 908.El
909.Pp 909.Pp
910The 910The
911.Dq here-doc-text 911.Dq here-doc-text
912starts immediately after the next unquoted newline character following 912starts immediately after the next unquoted newline character following
913the here-doc redirection operator. 913the here-doc redirection operator.
914If there is more than one here-document redirection on the same 914If there is more than one here-document redirection on the same
915line, then the text for the first (from left to right) is read 915line, then the text for the first (from left to right) is read
916first, and subsequent here-doc-text for later here-doc redirections 916first, and subsequent here-doc-text for later here-doc redirections
917follows immediately after, until all such redirections have been 917follows immediately after, until all such redirections have been
918processed. 918processed.
919.Pp 919.Pp
920All the text on successive lines up to the delimiter, 920All the text on successive lines up to the delimiter,
921which must appear on a line by itself, with nothing other 921which must appear on a line by itself, with nothing other
922than an immediately following newline, is 922than an immediately following newline, is
923saved away and made available to the command on standard input, or file 923saved away and made available to the command on standard input, or file
924descriptor n if it is specified. 924descriptor n if it is specified.
925If the delimiter as specified on the initial line is 925If the delimiter as specified on the initial line is
926quoted, then the here-doc-text is treated literally; otherwise, the text is 926quoted, then the here-doc-text is treated literally; otherwise, the text is
927treated much like a double quoted string, except that 927treated much like a double quoted string, except that
928.Sq \&" 928.Sq \&"
929characters have no special meaning, and are not escaped by 929characters have no special meaning, and are not escaped by
930.Sq \&\e , 930.Sq \&\e ,
931and is subjected to parameter expansion, command substitution, and arithmetic 931and is subjected to parameter expansion, command substitution, and arithmetic
932expansion as described in the 932expansion as described in the
933.Sx Word Expansions 933.Sx Word Expansions
934section below. 934section below.
935If the operator is 935If the operator is
936.Dq <<\(mi 936.Dq <<\(mi
937instead of 937instead of
938.Dq << , 938.Dq << ,
939then leading tabs in all lines in the here-doc-text, including before the 939then leading tabs in all lines in the here-doc-text, including before the
940end delimiter, are stripped. 940end delimiter, are stripped.
941If the delimiter is not quoted, lines in here-doc-text that end with 941If the delimiter is not quoted, lines in here-doc-text that end with
942an unquoted \e are joined to the following line, the \e and following 942an unquoted \e are joined to the following line, the \e and following
943newline are simply removed while reading the here-doc, which thus guarantees 943newline are simply removed while reading the here-doc, which thus guarantees
944that neither of those lines can be the end delimiter. 944that neither of those lines can be the end delimiter.
945.Pp 945.Pp
946It is a syntax error for the end of the input file (or string) to be 946It is a syntax error for the end of the input file (or string) to be
947reached before the delimiter is encountered. 947reached before the delimiter is encountered.
948.Ss Search and Execution 948.Ss Search and Execution
949There are three types of commands: shell functions, built-in commands, and 949There are three types of commands: shell functions, built-in commands, and
950normal programs -- and the command is searched for (by name) in that order. 950normal programs -- and the command is searched for (by name) in that order.
951A command that contains a slash 951A command that contains a slash
952.Sq \&/ 952.Sq \&/
953in its name is always a normal program. 953in its name is always a normal program.
954They each are executed in a different way. 954They each are executed in a different way.
955.Pp 955.Pp
956When a shell function is executed, all of the shell positional parameters 956When a shell function is executed, all of the shell positional parameters
957(except $0, which remains unchanged) are set to the arguments of the shell 957(except $0, which remains unchanged) are set to the arguments of the shell
958function. 958function.
959The variables which are explicitly placed in the environment of 959The variables which are explicitly placed in the environment of
960the command (by placing assignments to them before the function name) are 960the command (by placing assignments to them before the function name) are
961made local to the function and are set to the values given, 961made local to the function and are set to the values given,
962and exported for the benefit of programs executed with the function. 962and exported for the benefit of programs executed with the function.
963Then the command given in the function definition is executed. 963Then the command given in the function definition is executed.
964The positional parameters, and local variables, are restored to 964The positional parameters, and local variables, are restored to
965their original values when the command completes. 965their original values when the command completes.
966This all occurs within the current shell, and the function 966This all occurs within the current shell, and the function
967can alter variables, or other settings, of the shell. 967can alter variables, or other settings, of the shell.
968.Pp 968.Pp
969Shell built-ins are executed internally to the shell, without spawning a 969Shell built-ins are executed internally to the shell, without spawning a
970new process. 970new process.
971.Pp 971.Pp
972Otherwise, if the command name doesn't match a function or built-in, the 972Otherwise, if the command name doesn't match a function or built-in, the
973command is searched for as a normal program in the file system (as 973command is searched for as a normal program in the file system (as
974described in the next section). 974described in the next section).
975When a normal program is executed, the shell runs the program, 975When a normal program is executed, the shell runs the program,
976passing the arguments and the environment to the program. 976passing the arguments and the environment to the program.
977If the program is not a normal executable file, and if it does 977If the program is not a normal executable file, and if it does
978not begin with the "magic number" whose ASCII representation is "#!", so 978not begin with the "magic number" whose ASCII representation is "#!", so
979.Xr execve 2 979.Xr execve 2
980returns 980returns
981.Er ENOEXEC 981.Er ENOEXEC
982then) the shell will interpret the program in a sub-shell. 982then) the shell will interpret the program in a sub-shell.
983The child shell will reinitialize itself in this case, 983The child shell will reinitialize itself in this case,
984so that the effect will be as if a 984so that the effect will be as if a
985new shell had been invoked to handle the ad-hoc shell script, except that 985new shell had been invoked to handle the ad-hoc shell script, except that
986the location of hashed commands located in the parent shell will be 986the location of hashed commands located in the parent shell will be
987remembered by the child. 987remembered by the child.
988.Pp 988.Pp
989Note that previous versions of this document and the source code itself 989Note that previous versions of this document and the source code itself
990misleadingly and sporadically refer to a shell script without a magic 990misleadingly and sporadically refer to a shell script without a magic
991number as a "shell procedure". 991number as a "shell procedure".
992.Ss Path Search 992.Ss Path Search
993When locating a command, the shell first looks to see if it has a shell 993When locating a command, the shell first looks to see if it has a shell
994function by that name. 994function by that name.
995Then it looks for a built-in command by that name. 995Then it looks for a built-in command by that name.
996If a built-in command is not found, one of two things happen: 996If a built-in command is not found, one of two things happen:
997.Bl -enum 997.Bl -enum
998.It 998.It
999Command names containing a slash are simply executed without performing 999Command names containing a slash are simply executed without performing
1000any searches. 1000any searches.
1001.It 1001.It
1002Otherwise, the shell searches each entry in 1002Otherwise, the shell searches each entry in
1003.Ev PATH 1003.Ev PATH
1004in turn for the command. 1004in turn for the command.
1005The value of the 1005The value of the
1006.Ev PATH 1006.Ev PATH
1007variable should be a series of entries separated by colons. 1007variable should be a series of entries separated by colons.
1008Each entry consists of a directory name. 1008Each entry consists of a directory name.
1009The current directory may be indicated 1009The current directory may be indicated
1010implicitly by an empty directory name, or explicitly by a single period. 1010implicitly by an empty directory name, or explicitly by a single period.
1011If a directory searched contains an executable file with the same 1011If a directory searched contains an executable file with the same
1012name as the command given, 1012name as the command given,
1013the search terminates, and that program is executed. 1013the search terminates, and that program is executed.
1014.El 1014.El
1015.Ss Command Exit Status 1015.Ss Command Exit Status
1016Each command has an exit status that can influence the behavior 1016Each command has an exit status that can influence the behavior
1017of other shell commands. 1017of other shell commands.
1018The paradigm is that a command exits 1018The paradigm is that a command exits
1019with zero in normal cases, or to indicate success, 1019with zero in normal cases, or to indicate success,
1020and non-zero for failure, 1020and non-zero for failure,
1021error, or a false indication. 1021error, or a false indication.
1022The man page for each command 1022The man page for each command
1023should indicate the various exit codes and what they mean. 1023should indicate the various exit codes and what they mean.
1024Additionally, the built-in commands return exit codes, as does 1024Additionally, the built-in commands return exit codes, as does
1025an executed shell function. 1025an executed shell function.
1026.Pp 1026.Pp
1027If a command consists entirely of variable assignments then the 1027If a command consists entirely of variable assignments then the
1028exit status of the command is that of the last command substitution 1028exit status of the command is that of the last command substitution
1029if any, otherwise 0. 1029if any, otherwise 0.
1030.Pp 1030.Pp
1031If redirections are present, and any fail to be correctly performed, 1031If redirections are present, and any fail to be correctly performed,
1032any command present is not executed, and an exit status of 2 1032any command present is not executed, and an exit status of 2
1033is returned. 1033is returned.
1034.Ss Complex Commands 1034.Ss Complex Commands
1035Complex commands are combinations of simple commands with control 1035Complex commands are combinations of simple commands with control
1036operators or reserved words, together creating a larger complex command. 1036operators or reserved words, together creating a larger complex command.
1037Overall, a shell program is a: 1037Overall, a shell program is a:
1038.Bl -tag -width XpipelineX 1038.Bl -tag -width XpipelineX
1039.It list 1039.It list
1040Which is a sequence of one or more AND-OR lists. 1040Which is a sequence of one or more AND-OR lists.
1041.It "AND-OR list" 1041.It "AND-OR list"
1042is a sequence of one or more pipelines. 1042is a sequence of one or more pipelines.
1043.It pipeline 1043.It pipeline
1044is a sequence of one or more commands. 1044is a sequence of one or more commands.
1045.It command 1045.It command
1046is one of a simple command, a compound command, or a function definition. 1046is one of a simple command, a compound command, or a function definition.
1047.It "simple command" 1047.It "simple command"
1048has been explained above, and is the basic building block. 1048has been explained above, and is the basic building block.
1049.It "compound command" 1049.It "compound command"
1050provides mechanisms to group lists to achieve different effects. 1050provides mechanisms to group lists to achieve different effects.
1051.It "function definition" 1051.It "function definition"
1052allows new simple commands to be created as groupings of existing commands. 1052allows new simple commands to be created as groupings of existing commands.
1053.El 1053.El
1054.Pp 1054.Pp
1055Unless otherwise stated, the exit status of a list 1055Unless otherwise stated, the exit status of a list
1056is that of the last simple command executed by the list. 1056is that of the last simple command executed by the list.
1057.Ss Pipelines 1057.Ss Pipelines
1058A pipeline is a sequence of one or more commands separated 1058A pipeline is a sequence of one or more commands separated
1059by the control operator 1059by the control operator
1060.Sq \&| , 1060.Sq \&| ,
1061and optionally preceded by the 1061and optionally preceded by the
1062.Dq \&! 1062.Dq \&!
1063reserved word. 1063reserved word.
1064Note that 1064Note that
1065.Sq \&| 1065.Sq \&|
1066is an operator, and so is recognized anywhere it appears unquoted, 1066is an operator, and so is recognized anywhere it appears unquoted,
1067it does not require surrounding white space or other syntax elements. 1067it does not require surrounding white space or other syntax elements.
1068On the other hand 1068On the other hand
1069.Dq \&! 1069.Dq \&!
1070being a reserved word, must be separated from adjacent words by 1070being a reserved word, must be separated from adjacent words by
1071white space (or other operators, perhaps redirects) and is only 1071white space (or other operators, perhaps redirects) and is only
1072recognized as the reserved word when it appears in a command word 1072recognized as the reserved word when it appears in a command word
1073position (such as at the beginning of a pipeline.) 1073position (such as at the beginning of a pipeline.)
1074.Pp 1074.Pp
1075The standard output of all but 1075The standard output of all but
1076the last command in the sequence is connected to the standard input 1076the last command in the sequence is connected to the standard input
1077of the next command. 1077of the next command.
1078The standard output of the last 1078The standard output of the last
1079command is inherited from the shell, as usual, 1079command is inherited from the shell, as usual,
1080as is the standard input of the first command. 1080as is the standard input of the first command.
1081.Pp 1081.Pp
1082The format for a pipeline is: 1082The format for a pipeline is:
1083.Pp 1083.Pp
1084.Dl [!] command1 [ | command2 ...] 1084.Dl [!] command1 [ \&| command2 ...]
1085.Pp 1085.Pp
1086The standard output of command1 is connected to the standard input of 1086The standard output of command1 is connected to the standard input of
1087command2. 1087command2.
1088The standard input, standard output, or both of each command is 1088The standard input, standard output, or both of each command is
1089considered to be assigned by the pipeline before any redirection specified 1089considered to be assigned by the pipeline before any redirection specified
1090by redirection operators that are part of the command are performed. 1090by redirection operators that are part of the command are performed.
1091.Pp 1091.Pp
1092If the pipeline is not in the background (discussed later), the shell 1092If the pipeline is not in the background (discussed later), the shell
1093waits for all commands to complete. 1093waits for all commands to complete.
1094.Pp 1094.Pp
1095The commands in a pipeline can either be simple commands, 1095The commands in a pipeline can either be simple commands,
1096or one of the compound commands described below. 1096or one of the compound commands described below.
1097The simplest case of a pipeline is a single simple command. 1097The simplest case of a pipeline is a single simple command.
1098.Pp 1098.Pp
1099If the 1099If the
1100.Ic pipefail 1100.Ic pipefail
1101option is set when the pipeline completes and its status is 1101option is set when the pipeline completes and its status is
1102collected, the pipeline status is the status of 1102collected, the pipeline status is the status of
1103the last (rightmost) command in the pipeline to exit with non-zero exit 1103the last (rightmost) command in the pipeline to exit with non-zero exit
1104status, or zero, if, and only if, all commands in the pipeline 1104status, or zero, if, and only if, all commands in the pipeline
1105exited with a status of zero. 1105exited with a status of zero.
1106If the 1106If the
1107.Ic pipefail 1107.Ic pipefail
1108option is not set, which is the default state, 1108option is not set, which is the default state,
1109the pipeline status is the exit 1109the pipeline status is the exit
1110status of the last command in the pipeline, 1110status of the last command in the pipeline,
1111and the exit status of any other commands in the pipeline is ignored. 1111and the exit status of any other commands in the pipeline is ignored.
1112.Pp 1112.Pp
1113If the reserved word ! precedes the pipeline, the exit status 1113If the reserved word ! precedes the pipeline, the exit status
1114becomes the logical NOT of the pipeline status as determined above. 1114becomes the logical NOT of the pipeline status as determined above.
1115That is, if the pipeline status is zero, the exit status is 1; 1115That is, if the pipeline status is zero, the exit status is 1;
1116if the pipeline status is other than zero, the exit status is zero. 1116if the pipeline status is other than zero, the exit status is zero.
1117If there is no ! reserved word, the pipeline status becomes the exit status. 1117If there is no ! reserved word, the pipeline status becomes the exit status.
1118.Pp 1118.Pp
1119Because pipeline assignment of standard input or standard output or both 1119Because pipeline assignment of standard input or standard output or both
1120takes place before redirection, it can be modified by redirection. 1120takes place before redirection, it can be modified by redirection.
1121For example: 1121For example:
1122.Pp 1122.Pp
1123.Dl $ command1 2>&1 | command2 1123.Dl $ command1 2>&1 \&| command2
1124.Pp 1124.Pp
1125sends both the standard output and standard error of command1 1125sends both the standard output and standard error of command1
1126to the standard input of command2. 1126to the standard input of command2.
1127.Pp 1127.Pp
1128Note that unlike some other shells, each process in the pipeline is a 1128Note that unlike some other shells, each process in the pipeline is a
1129child of the invoking shell (unless it is a shell built-in, in which case 1129child of the invoking shell (unless it is a shell built-in, in which case
1130it executes in the current shell -- but any effect it has on the 1130it executes in the current shell -- but any effect it has on the
1131environment is wiped). 1131environment is wiped).
1132.Pp 1132.Pp
1133A pipeline is a simple case of an AND-OR-list (described below.) 1133A pipeline is a simple case of an AND-OR-list (described below.)
1134A ; or 1134A ; or
1135.Aq newline 1135.Aq newline
1136terminator causes the preceding pipeline, or more generally, 1136terminator causes the preceding pipeline, or more generally,
1137the preceding AND-OR-list to be executed sequentially; 1137the preceding AND-OR-list to be executed sequentially;
1138that is, the shell executes the commands, and waits for them 1138that is, the shell executes the commands, and waits for them
1139to finish before proceeding to following commands. 1139to finish before proceeding to following commands.
1140An & terminator causes asynchronous (background) execution 1140An & terminator causes asynchronous (background) execution
1141of the preceding AND-OR-list (see the next paragraph below). 1141of the preceding AND-OR-list (see the next paragraph below).
1142The exit status of an asynchronous AND-OR-list is zero. 1142The exit status of an asynchronous AND-OR-list is zero.
1143The actual status of the commands, 1143The actual status of the commands,
1144after they have completed, 1144after they have completed,
1145can be obtained using the 1145can be obtained using the
1146.Ic wait 1146.Ic wait
1147built-in command described later. 1147built-in command described later.
1148.Ss Background Commands -- & 1148.Ss Background Commands -- &
1149If a command, pipeline, or AND-OR-list 1149If a command, pipeline, or AND-OR-list
1150is terminated by the control operator ampersand (&), the 1150is terminated by the control operator ampersand (&), the
1151shell executes the command asynchronously -- that is, the shell does not 1151shell executes the command asynchronously -- that is, the shell does not
1152wait for the command to finish before executing the next command. 1152wait for the command to finish before executing the next command.
1153.Pp 1153.Pp
1154The format for running a command in background is: 1154The format for running a command in background is:
1155.Pp 1155.Pp
1156.Dl command1 & [command2 & ...] 1156.Dl command1 & [command2 & ...]
1157.Pp 1157.Pp
1158If the shell is not interactive, the standard input of an asynchronous 1158If the shell is not interactive, the standard input of an asynchronous
1159command is set to 1159command is set to
1160.Pa /dev/null . 1160.Pa /dev/null .
1161The process identifier of the most recent command started in the 1161The process identifier of the most recent command started in the
1162background can be obtained from the value of the special parameter 1162background can be obtained from the value of the special parameter
1163.Dq \&! 1163.Dq \&!
1164(see 1164(see
1165.Sx Special Parameters ) 1165.Sx Special Parameters )
1166provided it is accessed before the next asynchronous command is started. 1166provided it is accessed before the next asynchronous command is started.
1167.Ss Lists -- Generally Speaking 1167.Ss Lists -- Generally Speaking
1168A list is a sequence of one or more commands separated by newlines, 1168A list is a sequence of one or more commands separated by newlines,
1169semicolons, or ampersands, and optionally terminated by one of these three 1169semicolons, or ampersands, and optionally terminated by one of these three
1170characters. 1170characters.
1171A shell program, which includes the commands given to an 1171A shell program, which includes the commands given to an
1172interactive shell, is a list. 1172interactive shell, is a list.
1173Each command in such a list is executed when it is fully parsed. 1173Each command in such a list is executed when it is fully parsed.
1174Another use of a list is as a complete-command, 1174Another use of a list is as a complete-command,
1175which is parsed in its entirety, and then later the commands in 1175which is parsed in its entirety, and then later the commands in
1176the list are executed only if there were no parsing errors. 1176the list are executed only if there were no parsing errors.
1177.Pp 1177.Pp
1178The commands in a list are executed in the order they are written. 1178The commands in a list are executed in the order they are written.
1179If command is followed by an ampersand, the shell starts the 1179If command is followed by an ampersand, the shell starts the
1180command and immediately proceeds to the next command; otherwise it waits 1180command and immediately proceeds to the next command; otherwise it waits
1181for the command to terminate before proceeding to the next one. 1181for the command to terminate before proceeding to the next one.
1182A newline is equivalent to a 1182A newline is equivalent to a
1183.Sq \&; 1183.Sq \&;
1184when no other operator is present, and the command being input 1184when no other operator is present, and the command being input
1185could syntactically correctly be terminated at the point where 1185could syntactically correctly be terminated at the point where
1186the newline is encountered, otherwise it is just whitespace. 1186the newline is encountered, otherwise it is just whitespace.
1187.Ss AND-OR Lists (Short-Circuit List Operators) 1187.Ss AND-OR Lists (Short-Circuit List Operators)
1188.Dq && 1188.Dq &&
1189and 1189and
1190.Dq || 1190.Dq ||
1191are AND-OR list operators. 1191are AND-OR list operators.
1192After executing the commands that precede the 1192After executing the commands that precede the
1193.Dq && 1193.Dq &&
1194the subsequent command is executed 1194the subsequent command is executed
1195if and only if the exit status of the preceding command(s) is zero. 1195if and only if the exit status of the preceding command(s) is zero.
1196.Dq || 1196.Dq ||
1197is similar, but executes the subsequent command if and only if the exit status 1197is similar, but executes the subsequent command if and only if the exit status
1198of the preceding command is nonzero. 1198of the preceding command is nonzero.
1199If a command is not executed, the exit status remains unchanged 1199If a command is not executed, the exit status remains unchanged
1200and the following AND-OR list operator (if any) uses that status. 1200and the following AND-OR list operator (if any) uses that status.
1201.Dq && 1201.Dq &&
1202and 1202and
1203.Dq || 1203.Dq ||
1204both have the same priority. 1204both have the same priority.
1205Note that these operators are left-associative, so 1205Note that these operators are left-associative, so
1206.Dl true || echo bar && echo baz 1206.Dl true || echo bar && echo baz
1207writes 1207writes
1208.Dq baz 1208.Dq baz
1209and nothing else. 1209and nothing else.
1210This is not the way it works in C. 1210This is not the way it works in C.
1211.Ss Flow-Control Constructs -- if, while, until, for, case 1211.Ss Flow-Control Constructs -- if, while, until, for, case
1212These commands are instances of compound commands. 1212These commands are instances of compound commands.
1213The syntax of the 1213The syntax of the
1214.Ic if 1214.Ic if
1215command is 1215command is
1216.Bd -literal -offset indent 1216.Bd -literal -offset indent
1217if list 1217if list
1218then list 1218then list
1219[ elif list 1219[ elif list
1220then list ] ... 1220then list ] ...
1221[ else list ] 1221[ else list ]
1222fi 1222fi
1223.Ed 1223.Ed
1224The first list is executed, and if the exit status of that list is zero, 1224The first list is executed, and if the exit status of that list is zero,
1225the list following the 1225the list following the
1226.Ic then 1226.Ic then
1227is executed. 1227is executed.
1228Otherwise the list after an 1228Otherwise the list after an
1229.Ic elif 1229.Ic elif
1230(if any) is executed and the process repeats. 1230(if any) is executed and the process repeats.
1231When no more 1231When no more
1232.Ic elif 1232.Ic elif
1233reserved words, and accompanying lists, appear, 1233reserved words, and accompanying lists, appear,
1234the list after the 1234the list after the
1235.Ic else 1235.Ic else
1236reserved word, if any, is executed. 1236reserved word, if any, is executed.
1237.Pp 1237.Pp
1238The syntax of the 1238The syntax of the
1239.Ic while 1239.Ic while
1240command is 1240command is
1241.Bd -literal -offset indent 1241.Bd -literal -offset indent
1242while list 1242while list
1243do list 1243do list
1244done 1244done
1245.Ed 1245.Ed
1246.Pp 1246.Pp
1247The two lists are executed repeatedly while the exit status of the 1247The two lists are executed repeatedly while the exit status of the
1248first list is zero. 1248first list is zero.
1249The 1249The
1250.Ic until 1250.Ic until
1251command is similar, but has the word 1251command is similar, but has the word
1252.Ic until 1252.Ic until
1253in place of 1253in place of
1254.Ic while , 1254.Ic while ,
1255which causes it to repeat until the exit status of the first list is zero. 1255which causes it to repeat until the exit status of the first list is zero.
1256.Pp 1256.Pp
1257The syntax of the 1257The syntax of the
1258.Ic for 1258.Ic for
1259command is 1259command is
1260.Bd -literal -offset indent 1260.Bd -literal -offset indent
1261for variable [ in word ... ] 1261for variable [ in word ... ]
1262do list 1262do list
1263done 1263done
1264.Ed 1264.Ed
1265.Pp 1265.Pp
1266The words are expanded, or "$@" if 1266The words are expanded, or "$@" if
1267.Dq in 1267.Dq in
1268(and the following words) is not present, 1268(and the following words) is not present,
1269and then the list is executed repeatedly with the 1269and then the list is executed repeatedly with the
1270variable set to each word in turn. 1270variable set to each word in turn.
1271If 1271If
1272.Dq in 1272.Dq in
1273appears after the variable, but no words are 1273appears after the variable, but no words are
1274present, the list is not executed, and the exit status is zero. 1274present, the list is not executed, and the exit status is zero.
1275.Ic do 1275.Ic do
1276and 1276and
1277.Ic done 1277.Ic done
1278may be replaced with 1278may be replaced with
1279.Sq Ic \&{ 1279.Sq Ic \&{
1280and 1280and
1281.Sq Ic \&} , 1281.Sq Ic \&} ,
1282but doing so is non-standard and not recommended. 1282but doing so is non-standard and not recommended.
1283.Pp 1283.Pp
1284The syntax of the 1284The syntax of the
1285.Ic break 1285.Ic break
1286and 1286and
1287.Ic continue 1287.Ic continue
1288commands is 1288commands is
1289.Bd -literal -offset indent 1289.Bd -literal -offset indent
1290break [ num ] 1290break [ num ]
1291continue [ num ] 1291continue [ num ]
1292.Ed 1292.Ed
1293.Pp 1293.Pp
1294.Ic break 1294.Ic break
1295terminates the 1295terminates the
1296.Ar num 1296.Ar num
1297innermost 1297innermost
1298.Ic for , while , 1298.Ic for , while ,
1299or 1299or
1300.Ic until 1300.Ic until
1301loops. 1301loops.
1302.Ic continue 1302.Ic continue
1303breaks execution of the 1303breaks execution of the
1304.Ar num\-1 1304.Ar num\-1
1305innermost 1305innermost
1306.Ic for , while , 1306.Ic for , while ,
1307or 1307or
1308.Ic until 1308.Ic until
1309loops, and then continues with the next iteration of the enclosing loop. 1309loops, and then continues with the next iteration of the enclosing loop.
1310These are implemented as special built-in commands. 1310These are implemented as special built-in commands.
1311The parameter 1311The parameter
1312.Ar num , 1312.Ar num ,
1313if given, must be an unsigned positive integer (greater than zero). 1313if given, must be an unsigned positive integer (greater than zero).
1314If not given, 1 is used. 1314If not given, 1 is used.
1315.Pp 1315.Pp
1316The syntax of the 1316The syntax of the
1317.Ic case 1317.Ic case
1318command is 1318command is
1319.Bd -literal -offset indent 1319.Bd -literal -offset indent
1320case word in 1320case word in
1321[(] pattern ) [ list ] ;& 1321[(] pattern ) [ list ] ;&
1322[(] pattern ) [ list ] ;; 1322[(] pattern ) [ list ] ;;
1323\&... 1323\&...
1324esac 1324esac
1325.Ed 1325.Ed
1326.Pp 1326.Pp
1327The pattern can actually be one or more patterns (see 1327The pattern can actually be one or more patterns (see
1328.Sx Shell Patterns 1328.Sx Shell Patterns
1329described later), separated by 1329described later), separated by
1330.Dq \*(Ba 1330.Dq \*(Ba
1331characters. 1331characters.
1332.Pp 1332.Pp
1333Word is expanded and matched against each pattern in turn, 1333Word is expanded and matched against each pattern in turn,
1334from first to last, 1334from first to last,
1335with each pattern being expanded just before the match is attempted. 1335with each pattern being expanded just before the match is attempted.
1336When a match is found, pattern comparisons cease, and the associated 1336When a match is found, pattern comparisons cease, and the associated
1337.Dq list , 1337.Dq list ,
1338if given, 1338if given,
1339is evaluated. 1339is evaluated.
1340If the list is terminated with 1340If the list is terminated with
1341.Dq \&;& 1341.Dq \&;&
1342execution then falls through to the following list, if any, 1342execution then falls through to the following list, if any,
1343without evaluating its pattern, or attempting a match. 1343without evaluating its pattern, or attempting a match.
1344When a list terminated with 1344When a list terminated with
1345.Dq \&;; 1345.Dq \&;;
1346has been executed, or when 1346has been executed, or when
1347.Ic esac 1347.Ic esac
1348is reached, execution of the 1348is reached, execution of the
1349.Ic case 1349.Ic case
1350statement is complete. 1350statement is complete.
1351The exit status is that of the last command executed 1351The exit status is that of the last command executed
1352from the last list evaluated, if any, or zero otherwise. 1352from the last list evaluated, if any, or zero otherwise.
1353.Ss Grouping Commands Together 1353.Ss Grouping Commands Together
1354Commands may be grouped by writing either 1354Commands may be grouped by writing either
1355.Dl (list) 1355.Dl (list)
1356or 1356or
1357.Dl { list; } 1357.Dl { list; }
1358These also form compound commands. 1358These also form compound commands.
1359.Pp 1359.Pp
1360Note that while parentheses are operators, and do not require 1360Note that while parentheses are operators, and do not require
1361any extra syntax, braces are reserved words, so the opening brace 1361any extra syntax, braces are reserved words, so the opening brace
1362must be followed by white space (or some other operator), and the 1362must be followed by white space (or some other operator), and the
1363closing brace must occur in a position where a new command word might 1363closing brace must occur in a position where a new command word might
1364otherwise appear. 1364otherwise appear.
1365.Pp 1365.Pp
1366The first of these executes the commands in a sub-shell. 1366The first of these executes the commands in a sub-shell.
1367Built-in commands grouped into a (list) will not affect the current shell. 1367Built-in commands grouped into a (list) will not affect the current shell.
1368The second form does not fork another shell so is slightly more efficient, 1368The second form does not fork another shell so is slightly more efficient,
1369and allows for commands which do affect the current shell. 1369and allows for commands which do affect the current shell.
1370Grouping commands together this way allows you to redirect 1370Grouping commands together this way allows you to redirect
1371their output as though they were one program: 1371their output as though they were one program:
1372.Bd -literal -offset indent 1372.Bd -literal -offset indent
1373{ echo -n \*qhello \*q ; echo \*qworld\*q ; } > greeting 1373{ echo -n \*qhello \*q ; echo \*qworld\*q ; } > greeting
1374.Ed 1374.Ed
1375.Pp 1375.Pp
1376Note that 1376Note that
1377.Dq } 1377.Dq }
1378must follow a control operator (here, 1378must follow a control operator (here,
1379.Dq \&; ) 1379.Dq \&; )
1380so that it is recognized as a reserved word and not as another command argument. 1380so that it is recognized as a reserved word and not as another command argument.
1381.Ss Functions 1381.Ss Functions
1382The syntax of a function definition is 1382The syntax of a function definition is
1383.Pp 1383.Pp
1384.Dl name ( ) command [ redirect... ] 1384.Dl name ( ) command [ redirect... ]
1385.Pp 1385.Pp
1386A function definition is an executable statement; when executed it 1386A function definition is an executable statement; when executed it
1387installs a function named name and returns an exit status of zero. 1387installs a function named name and returns an exit status of zero.
1388The command is normally a list enclosed between 1388The command is normally a list enclosed between
1389.Dq { 1389.Dq {
1390and 1390and
1391.Dq } . 1391.Dq } .
1392The standard syntax also allows the command to be any of the other 1392The standard syntax also allows the command to be any of the other
1393compound commands, including a sub-shell, all of which are supported. 1393compound commands, including a sub-shell, all of which are supported.
1394As an extension, this shell also allows a simple command 1394As an extension, this shell also allows a simple command
1395(or even another function definition) to be 1395(or even another function definition) to be
1396used, though users should be aware this is non-standard syntax. 1396used, though users should be aware this is non-standard syntax.
1397This means that 1397This means that
1398.Dl l() ls "$@" 1398.Dl l() ls "$@"
1399works to make 1399works to make
1400.Dq l 1400.Dq l
1401an alternative name for the 1401an alternative name for the
1402.Ic ls 1402.Ic ls
1403command. 1403command.
1404.Pp 1404.Pp
1405If the optional redirect, (see 1405If the optional redirect, (see
1406.Sx Redirections ) , 1406.Sx Redirections ) ,
1407which may be of any of the normal forms, 1407which may be of any of the normal forms,
1408is given, it is applied each time the 1408is given, it is applied each time the
1409function is called. 1409function is called.
1410This means that a simple 1410This means that a simple
1411.Dq Hello World 1411.Dq Hello World
1412function might be written (in the extended syntax) as: 1412function might be written (in the extended syntax) as:
1413.Bd -literal -offset indent 1413.Bd -literal -offset indent
1414hello() cat <<EOF 1414hello() cat <<EOF
1415Hello World! 1415Hello World!
1416EOF 1416EOF
1417.Ed 1417.Ed
1418.Pp 1418.Pp
1419To be correctly standards conforming this should be re-written as: 1419To be correctly standards conforming this should be re-written as:
1420.Bd -literal -offset indent 1420.Bd -literal -offset indent
1421hello() { cat; } <<EOF 1421hello() { cat; } <<EOF
1422Hello World! 1422Hello World!
1423EOF 1423EOF
1424.Ed 1424.Ed
1425.Pp 1425.Pp
1426Note the distinction between those forms, and 1426Note the distinction between those forms, and
1427.Bd -literal -offset indent 1427.Bd -literal -offset indent
1428hello() { cat <<EOF 1428hello() { cat <<EOF
1429Hello World! 1429Hello World!
1430EOF 1430EOF
1431\&} 1431\&}
1432.Ed 1432.Ed
1433.Pp 1433.Pp
1434which reads and processes the 1434which reads and processes the
1435.Ic here document 1435.Ic here document
1436each time the shell executes the function, and which applies 1436each time the shell executes the function, and which applies
1437that input only to the cat command, not to any other commands 1437that input only to the cat command, not to any other commands
1438that might appear in the function. 1438that might appear in the function.
1439.Pp 1439.Pp
1440Variables may be declared to be local to a function by using the 1440Variables may be declared to be local to a function by using the
1441.Ic local 1441.Ic local
1442command. 1442command.
1443This should usually appear as the first statement of a function, 1443This should usually appear as the first statement of a function,
1444though 1444though
1445.Ic local 1445.Ic local
1446is an executable command which can be used anywhere in a function. 1446is an executable command which can be used anywhere in a function.
1447See 1447See
1448.Sx Built-ins 1448.Sx Built-ins
1449below for its definition. 1449below for its definition.
1450.Pp 1450.Pp
1451The function completes after having executed 1451The function completes after having executed
1452.Ar command 1452.Ar command
1453with exit status set to the status returned by 1453with exit status set to the status returned by
1454.Ar command . 1454.Ar command .
1455If 1455If
1456.Ar command 1456.Ar command
1457is a compound-command 1457is a compound-command
1458it can use the 1458it can use the
1459.Ic return 1459.Ic return
1460command (see 1460command (see
1461.Sx Built-ins 1461.Sx Built-ins
1462below) 1462below)
1463to finish before completing all of 1463to finish before completing all of
1464.Ar command . 1464.Ar command .
1465.Ss Variables and Parameters 1465.Ss Variables and Parameters
1466The shell maintains a set of parameters. 1466The shell maintains a set of parameters.
1467A parameter denoted by a name is called a variable. 1467A parameter denoted by a name is called a variable.
1468When starting up, the shell turns all the environment 1468When starting up, the shell turns all the environment
1469variables into shell variables, and exports them. 1469variables into shell variables, and exports them.
1470New variables can be set using the form 1470New variables can be set using the form
1471.Pp 1471.Pp
1472.Dl name=value 1472.Dl name=value
1473.Pp 1473.Pp
1474Variables set by the user must have a name consisting solely of 1474Variables set by the user must have a name consisting solely of
1475alphabetics, numerics, and underscores - the first of which must not be 1475alphabetics, numerics, and underscores - the first of which must not be
1476numeric. 1476numeric.
1477A parameter can also be denoted by a number or a special 1477A parameter can also be denoted by a number or a special
1478character as explained below. 1478character as explained below.
1479.Ss Positional Parameters 1479.Ss Positional Parameters
1480A positional parameter is a parameter denoted by a number (n > 0). 1480A positional parameter is a parameter denoted by a number (n > 0).
1481The shell sets these initially to the values of its command line arguments 1481The shell sets these initially to the values of its command line arguments
1482that follow the name of the shell script. 1482that follow the name of the shell script.
1483The 1483The
1484.Ic set 1484.Ic set
1485built-in can also be used to set or reset them, and 1485built-in can also be used to set or reset them, and
1486.Ic shift 1486.Ic shift
1487can be used to manipulate the list. 1487can be used to manipulate the list.
1488.Pp 1488.Pp
1489To refer to the 10th (and later) positional parameters, 1489To refer to the 10th (and later) positional parameters,
1490the form ${n} must be used. 1490the form ${n} must be used.
1491Without the braces, a digit following 1491Without the braces, a digit following
1492.Dq $ 1492.Dq $
1493can only refer to one of the first 9 positional parameters, 1493can only refer to one of the first 9 positional parameters,
1494or the special parameter 1494or the special parameter
1495.Dq 0 . 1495.Dq 0 .
1496The word 1496The word
1497.Dq $10 1497.Dq $10
1498is treated identically to 1498is treated identically to
1499.Dq ${1}0 . 1499.Dq ${1}0 .
1500.Ss Special Parameters 1500.Ss Special Parameters
1501A special parameter is a parameter denoted by one of the following special 1501A special parameter is a parameter denoted by one of the following special
1502characters. 1502characters.
1503The value of the parameter is listed next to its character. 1503The value of the parameter is listed next to its character.
1504.Bl -tag -width thinhyphena 1504.Bl -tag -width thinhyphena
1505.It * 1505.It *
1506Expands to the positional parameters, starting from one. 1506Expands to the positional parameters, starting from one.
1507When the 1507When the
1508expansion occurs within a double-quoted string it expands to a single 1508expansion occurs within a double-quoted string it expands to a single
1509field with the value of each parameter separated by the first character of 1509field with the value of each parameter separated by the first character of
1510the 1510the
1511.Ev IFS 1511.Ev IFS
1512variable, or by a 1512variable, or by a
1513.Aq space 1513.Aq space
1514if 1514if
1515.Ev IFS 1515.Ev IFS
1516is unset. 1516is unset.
1517.It @ 1517.It @
1518Expands to the positional parameters, starting from one. 1518Expands to the positional parameters, starting from one.
1519When the expansion occurs within double quotes, each positional 1519When the expansion occurs within double quotes, each positional
1520parameter expands as a separate argument. 1520parameter expands as a separate argument.
1521If there are no positional parameters, the 1521If there are no positional parameters, the
1522expansion of @ generates zero arguments, even when @ is 1522expansion of @ generates zero arguments, even when @ is
1523double-quoted. 1523double-quoted.
1524What this basically means, for example, is 1524What this basically means, for example, is
1525if $1 is 1525if $1 is
1526.Dq abc 1526.Dq abc
1527and $2 is 1527and $2 is
1528.Dq def ghi , 1528.Dq def ghi ,
1529then 1529then
1530.Qq $@ 1530.Qq $@
1531expands to 1531expands to
1532the two arguments: 1532the two arguments:
1533.Pp 1533.Pp
1534.Sm off 1534.Sm off
1535.Dl \*q abc \*q \ \*q def\ ghi \*q 1535.Dl \*q abc \*q \ \*q def\ ghi \*q
1536.Sm on 1536.Sm on
1537.It # 1537.It #
1538Expands to the number of positional parameters. 1538Expands to the number of positional parameters.
1539.It \&? 1539.It \&?
1540Expands to the exit status of the most recent pipeline. 1540Expands to the exit status of the most recent pipeline.
1541.It \- (Hyphen, or minus.) 1541.It \- (Hyphen, or minus.)
1542Expands to the current option flags (the single-letter 1542Expands to the current option flags (the single-letter
1543option names concatenated into a string) as specified on 1543option names concatenated into a string) as specified on
1544invocation, by the set built-in command, or implicitly 1544invocation, by the set built-in command, or implicitly
1545by the shell. 1545by the shell.
1546.It $ 1546.It $
1547Expands to the process ID of the invoked shell. 1547Expands to the process ID of the invoked shell.
1548A sub-shell retains the same value of $ as its parent. 1548A sub-shell retains the same value of $ as its parent.
1549.It \&! 1549.It \&!
1550Expands to the process ID of the most recent background 1550Expands to the process ID of the most recent background
1551command executed from the current shell. 1551command executed from the current shell.
1552For a pipeline, the process ID is that of the last command in the pipeline. 1552For a pipeline, the process ID is that of the last command in the pipeline.
1553If no background commands have yet been started by the shell, then 1553If no background commands have yet been started by the shell, then
1554.Dq \&! 1554.Dq \&!
1555will be unset. 1555will be unset.
1556Once set, the value of 1556Once set, the value of
1557.Dq \&! 1557.Dq \&!
1558will be retained until another background command is started. 1558will be retained until another background command is started.
1559.It 0 (Zero.) 1559.It 0 (Zero.)
1560Expands to the name of the shell or shell script. 1560Expands to the name of the shell or shell script.
1561.El 1561.El
1562.Ss Word Expansions 1562.Ss Word Expansions
1563This section describes the various expansions that are performed on words. 1563This section describes the various expansions that are performed on words.
1564Not all expansions are performed on every word, as explained later. 1564Not all expansions are performed on every word, as explained later.
1565.Pp 1565.Pp
1566Tilde expansions, parameter expansions, command substitutions, arithmetic 1566Tilde expansions, parameter expansions, command substitutions, arithmetic
1567expansions, and quote removals that occur within a single word expand to a 1567expansions, and quote removals that occur within a single word expand to a
1568single field. 1568single field.
1569It is only field splitting or pathname expansion that can 1569It is only field splitting or pathname expansion that can
1570create multiple fields from a single word. 1570create multiple fields from a single word.
1571The single exception to this 1571The single exception to this
1572rule is the expansion of the special parameter @ within double quotes, as 1572rule is the expansion of the special parameter @ within double quotes, as
1573was described above. 1573was described above.
1574.Pp 1574.Pp
1575The order of word expansion is: 1575The order of word expansion is:
1576.Bl -enum 1576.Bl -enum
1577.It 1577.It
1578Tilde Expansion, Parameter Expansion, Command Substitution, 1578Tilde Expansion, Parameter Expansion, Command Substitution,
1579Arithmetic Expansion (these all occur at the same time). 1579Arithmetic Expansion (these all occur at the same time).
1580.It 1580.It
1581Field Splitting is performed on fields 1581Field Splitting is performed on fields
1582generated by step (1) unless the 1582generated by step (1) unless the
1583.Ev IFS 1583.Ev IFS
1584variable is null. 1584variable is null.
1585.It 1585.It
1586Pathname Expansion (unless set 1586Pathname Expansion (unless set
1587.Fl f 1587.Fl f
1588is in effect). 1588is in effect).
1589.It 1589.It
1590Quote Removal. 1590Quote Removal.
1591.El 1591.El
1592.Pp 1592.Pp
1593The $ character is used to introduce parameter expansion, command 1593The $ character is used to introduce parameter expansion, command
1594substitution, or arithmetic evaluation. 1594substitution, or arithmetic evaluation.
1595.Ss Tilde Expansion (substituting a user's home directory) 1595.Ss Tilde Expansion (substituting a user's home directory)
1596A word beginning with an unquoted tilde character (~) is 1596A word beginning with an unquoted tilde character (~) is
1597subjected to tilde expansion. 1597subjected to tilde expansion.
1598Provided all of the subsequent characters in the word are unquoted 1598Provided all of the subsequent characters in the word are unquoted
1599up to an unquoted slash (/) 1599up to an unquoted slash (/)
1600or when in an assignment or not in posix mode, an unquoted colon (:), 1600or when in an assignment or not in posix mode, an unquoted colon (:),
1601or if neither of those appear, the end of the word, 1601or if neither of those appear, the end of the word,
1602they are treated as a user name 1602they are treated as a user name
1603and are replaced with the pathname of the named user's home directory. 1603and are replaced with the pathname of the named user's home directory.
1604If the user name is missing (as in 1604If the user name is missing (as in
1605.Pa ~/foobar ) , 1605.Pa ~/foobar ) ,
1606the tilde is replaced with the value of the 1606the tilde is replaced with the value of the
1607.Va HOME 1607.Va HOME
1608variable (the current user's home directory). 1608variable (the current user's home directory).
1609.Pp 1609.Pp
1610In variable assignments, 1610In variable assignments,
1611an unquoted tilde immediately after the assignment operator (=), and 1611an unquoted tilde immediately after the assignment operator (=), and
1612each unquoted tilde immediately after an unquoted colon in the value 1612each unquoted tilde immediately after an unquoted colon in the value
1613to be assigned is also subject to tilde expansion as just stated. 1613to be assigned is also subject to tilde expansion as just stated.
1614.Ss Parameter Expansion 1614.Ss Parameter Expansion
1615The format for parameter expansion is as follows: 1615The format for parameter expansion is as follows:
1616.Pp 1616.Pp
1617.Dl ${expression} 1617.Dl ${expression}
1618.Pp 1618.Pp
1619where expression consists of all characters until the matching 1619where expression consists of all characters until the matching
1620.Dq } . 1620.Dq } .
1621Any 1621Any
1622.Dq } 1622.Dq }
1623escaped by a backslash or within a quoted string, and characters in 1623escaped by a backslash or within a quoted string, and characters in
1624embedded arithmetic expansions, command substitutions, and variable 1624embedded arithmetic expansions, command substitutions, and variable
1625expansions, are not examined in determining the matching 1625expansions, are not examined in determining the matching
1626.Dq } . 1626.Dq } .
1627.Pp 1627.Pp
1628The simplest form for parameter expansion is: 1628The simplest form for parameter expansion is:
1629.Pp 1629.Pp
1630.Dl ${parameter} 1630.Dl ${parameter}
1631.Pp 1631.Pp
1632The value, if any, of parameter is substituted. 1632The value, if any, of parameter is substituted.
1633.Pp 1633.Pp
1634The parameter name or symbol can be enclosed in braces, 1634The parameter name or symbol can be enclosed in braces,
1635which are optional in this simple case, 1635which are optional in this simple case,
1636except for positional parameters with more than one digit or 1636except for positional parameters with more than one digit or
1637when parameter is followed by a character that could be interpreted as 1637when parameter is followed by a character that could be interpreted as
1638part of the name. 1638part of the name.
1639If a parameter expansion occurs inside double quotes: 1639If a parameter expansion occurs inside double quotes:
1640.Bl -enum 1640.Bl -enum
1641.It 1641.It
1642Pathname expansion is not performed on the results of the expansion. 1642Pathname expansion is not performed on the results of the expansion.
1643.It 1643.It
1644Field splitting is not performed on the results of the 1644Field splitting is not performed on the results of the
1645expansion, with the exception of the special rules for @. 1645expansion, with the exception of the special rules for @.
1646.El 1646.El
1647.Pp 1647.Pp
1648In addition, a parameter expansion where braces are used, 1648In addition, a parameter expansion where braces are used,
1649can be modified by using one of the following formats. 1649can be modified by using one of the following formats.
1650If the 1650If the
1651.Dq Dv \&: 1651.Dq Dv \&:
1652is omitted in the following modifiers, then the test in the expansion 1652is omitted in the following modifiers, then the test in the expansion
1653applies only to unset parameters, not null ones. 1653applies only to unset parameters, not null ones.
1654.Bl -tag -width aaparameterwordaaaaa 1654.Bl -tag -width aaparameterwordaaaaa
1655.It ${parameter:\(miword} 1655.It ${parameter:\(miword}
1656Use Default Values. 1656Use Default Values.
1657If parameter is unset or null, the expansion of word 1657If parameter is unset or null, the expansion of word
1658is substituted; otherwise, the value of parameter is substituted. 1658is substituted; otherwise, the value of parameter is substituted.
1659.It ${parameter:=word} 1659.It ${parameter:=word}
1660Assign Default Values. 1660Assign Default Values.
1661If parameter is unset or null, the expansion of 1661If parameter is unset or null, the expansion of
1662word is assigned to parameter. 1662word is assigned to parameter.
1663In all cases, the final value of parameter is substituted. 1663In all cases, the final value of parameter is substituted.
1664Only variables, not positional parameters or special 1664Only variables, not positional parameters or special
1665parameters, can be assigned in this way. 1665parameters, can be assigned in this way.
1666.It ${parameter:?[word]} 1666.It ${parameter:?[word]}
1667Indicate Error if Null or Unset. 1667Indicate Error if Null or Unset.
1668If parameter is unset or null, the 1668If parameter is unset or null, the
1669expansion of word (or a message indicating it is unset if word is omitted) 1669expansion of word (or a message indicating it is unset if word is omitted)
1670is written to standard error and a non-interactive shell exits with 1670is written to standard error and a non-interactive shell exits with
1671a nonzero exit status. 1671a nonzero exit status.
1672An interactive shell will not exit, but any associated command(s) will 1672An interactive shell will not exit, but any associated command(s) will
1673not be executed. 1673not be executed.
1674If the parameter is set, its value is substituted. 1674If the parameter is set, its value is substituted.
1675.It ${parameter:+word} 1675.It ${parameter:+word}
1676Use Alternative Value. 1676Use Alternative Value.
1677If parameter is unset or null, null is 1677If parameter is unset or null, null is
1678substituted; otherwise, the expansion of word is substituted. 1678substituted; otherwise, the expansion of word is substituted.
1679The value of parameter is not used in this expansion. 1679The value of parameter is not used in this expansion.
1680.It ${#parameter} 1680.It ${#parameter}
1681String Length. 1681String Length.
1682The length in characters of the value of parameter. 1682The length in characters of the value of parameter.
1683.El 1683.El
1684.Pp 1684.Pp
1685The following four varieties of parameter expansion provide for substring 1685The following four varieties of parameter expansion provide for substring
1686processing. 1686processing.
1687In each case, pattern matching notation (see 1687In each case, pattern matching notation (see
1688.Sx Shell Patterns ) , 1688.Sx Shell Patterns ) ,
1689rather than regular expression notation, is used to evaluate the patterns. 1689rather than regular expression notation, is used to evaluate the patterns.
1690If parameter is * or @, the result of the expansion is unspecified. 1690If parameter is * or @, the result of the expansion is unspecified.
1691Enclosing the full parameter expansion string in double quotes does not 1691Enclosing the full parameter expansion string in double quotes does not
1692cause the following four varieties of pattern characters to be quoted, 1692cause the following four varieties of pattern characters to be quoted,
1693whereas quoting characters within the braces has this effect. 1693whereas quoting characters within the braces has this effect.
1694.Bl -tag -width aaparameterwordaaaaa 1694.Bl -tag -width aaparameterwordaaaaa
1695.It ${parameter%word} 1695.It ${parameter%word}
1696Remove Smallest Suffix Pattern. 1696Remove Smallest Suffix Pattern.
1697The word is expanded to produce a pattern. 1697The word is expanded to produce a pattern.
1698The parameter expansion then results in parameter, with the 1698The parameter expansion then results in parameter, with the
1699smallest portion of the suffix matched by the pattern deleted. 1699smallest portion of the suffix matched by the pattern deleted.
1700If the word is to start with a 1700If the word is to start with a
1701.Sq \&% 1701.Sq \&%
1702character, it must be quoted. 1702character, it must be quoted.
1703.It ${parameter%%word} 1703.It ${parameter%%word}
1704Remove Largest Suffix Pattern. 1704Remove Largest Suffix Pattern.
1705The word is expanded to produce a pattern. 1705The word is expanded to produce a pattern.
1706The parameter expansion then results in parameter, with the largest 1706The parameter expansion then results in parameter, with the largest
1707portion of the suffix matched by the pattern deleted. 1707portion of the suffix matched by the pattern deleted.
1708The 1708The
1709.Dq %% 1709.Dq %%
1710pattern operator only produces different results from the 1710pattern operator only produces different results from the
1711.Dq \&% 1711.Dq \&%
1712operator when the pattern contains at least one unquoted 1712operator when the pattern contains at least one unquoted
1713.Sq \&* . 1713.Sq \&* .
1714.It ${parameter#word} 1714.It ${parameter#word}
1715Remove Smallest Prefix Pattern. 1715Remove Smallest Prefix Pattern.
1716The word is expanded to produce a pattern. 1716The word is expanded to produce a pattern.
1717The parameter expansion then results in parameter, with the 1717The parameter expansion then results in parameter, with the
1718smallest portion of the prefix matched by the pattern deleted. 1718smallest portion of the prefix matched by the pattern deleted.
1719If the word is to start with a 1719If the word is to start with a
1720.Sq \&# 1720.Sq \&#
1721character, it must be quoted. 1721character, it must be quoted.
1722.It ${parameter##word} 1722.It ${parameter##word}
1723Remove Largest Prefix Pattern. 1723Remove Largest Prefix Pattern.
1724The word is expanded to produce a pattern. 1724The word is expanded to produce a pattern.
1725The parameter expansion then results in parameter, with the largest 1725The parameter expansion then results in parameter, with the largest
1726portion of the prefix matched by the pattern deleted. 1726portion of the prefix matched by the pattern deleted.
1727This has the same relationship with the 1727This has the same relationship with the
1728.Sq \&# 1728.Sq \&#
1729pattern operator as 1729pattern operator as
1730.Dq %% 1730.Dq %%
1731has with 1731has with
1732.Dq \&% . 1732.Dq \&% .
1733.El 1733.El
1734.Ss Command Substitution 1734.Ss Command Substitution
1735Command substitution allows the output of a command to be substituted in 1735Command substitution allows the output of a command to be substituted in
1736place of the command (and surrounding syntax). 1736place of the command (and surrounding syntax).
1737Command substitution occurs when the command is enclosed as follows: 1737Command substitution occurs when the command is enclosed as follows:
1738.Pp 1738.Pp
1739.Dl $(command) 1739.Dl $(command)
1740.Pp 1740.Pp
1741or 1741or
1742.Po 1742.Po
1743.Dq backquoted 1743.Dq backquoted
1744version 1744version
1745.Pc : 1745.Pc :
1746.Pp 1746.Pp
1747.Dl `command` 1747.Dl `command`
1748.Pp 1748.Pp
1749The shell expands the command substitution by executing command in a 1749The shell expands the command substitution by executing command in a
1750sub-shell environment and replacing the command substitution with the 1750sub-shell environment and replacing the command substitution with the
1751standard output of the command, removing sequences of one or more 1751standard output of the command, removing sequences of one or more
1752.Ao newline Ac Ns s 1752.Ao newline Ac Ns s
1753at the end of the substitution. 1753at the end of the substitution.
1754(Embedded 1754(Embedded
1755.Ao newline Ac Ns s 1755.Ao newline Ac Ns s
1756before 1756before
1757the end of the output are not removed; however, during field splitting, 1757the end of the output are not removed; however, during field splitting,
1758they may be translated into 1758they may be translated into
1759.Ao space Ac Ns s , 1759.Ao space Ac Ns s ,
1760depending on the value of 1760depending on the value of
1761.Ev IFS 1761.Ev IFS
1762and any quoting that is in effect.) 1762and any quoting that is in effect.)
1763.Ss Arithmetic Expansion 1763.Ss Arithmetic Expansion
1764Arithmetic expansion provides a mechanism for evaluating an arithmetic 1764Arithmetic expansion provides a mechanism for evaluating an arithmetic
1765expression and substituting its value. 1765expression and substituting its value.
1766The format for arithmetic expansion is as follows: 1766The format for arithmetic expansion is as follows:
1767.Pp 1767.Pp
1768.Dl $((expression)) 1768.Dl $((expression))
1769.Pp 1769.Pp
1770The expression in an arithmetic expansion is treated as if it were in 1770The expression in an arithmetic expansion is treated as if it were in
1771double quotes, except that a double quote character inside the expression 1771double quotes, except that a double quote character inside the expression
1772is just a normal character (it quotes nothing.) 1772is just a normal character (it quotes nothing.)
1773The shell expands all tokens in the expression for parameter expansion, 1773The shell expands all tokens in the expression for parameter expansion,
1774command substitution, and quote removal (the only quoting character is 1774command substitution, and quote removal (the only quoting character is
1775the backslash 1775the backslash
1776.Sq \&\e , 1776.Sq \&\e ,
1777and only when followed by another 1777and only when followed by another
1778.Sq \&\e , 1778.Sq \&\e ,
1779a dollar sign 1779a dollar sign
1780.Sq \&$ , 1780.Sq \&$ ,
1781a backquote 1781a backquote
1782.Sq \&` 1782.Sq \&`
1783or a newline.) 1783or a newline.)
1784.Pp 1784.Pp
1785Next, the shell evaluates the expanded result as an arithmetic expression 1785Next, the shell evaluates the expanded result as an arithmetic expression
1786and substitutes the calculated value of that expression. 1786and substitutes the calculated value of that expression.
1787.Pp 1787.Pp
1788Arithmetic expressions use a syntax similar to that 1788Arithmetic expressions use a syntax similar to that
1789of the C language, and are evaluated using the 1789of the C language, and are evaluated using the
1790.Ql intmax_t 1790.Ql intmax_t
1791data type (this is an extension to POSIX, which requires only 1791data type (this is an extension to POSIX, which requires only
1792.Ql long 1792.Ql long
1793arithmetic.) 1793arithmetic.)
1794Shell variables may be referenced by name inside an arithmetic 1794Shell variables may be referenced by name inside an arithmetic
1795expression, without needing a 1795expression, without needing a
1796.Dq \&$ 1796.Dq \&$
1797sign. 1797sign.
1798Variables that are not set, or which have an empty (null string) value, 1798Variables that are not set, or which have an empty (null string) value,
1799used this way evaluate as zero (that is, 1799used this way evaluate as zero (that is,
1800.Dq x 1800.Dq x
1801in arithmetic, as an R-Value, is evaluated as 1801in arithmetic, as an R-Value, is evaluated as
1802.Dq ${x:-0} ) 1802.Dq ${x:-0} )
1803unless the 1803unless the
1804.Nm 1804.Nm
1805.Fl u 1805.Fl u
1806flag is set, in which case a reference to an unset variable is an error. 1806flag is set, in which case a reference to an unset variable is an error.
1807Note that unset variables used in the ${var} form expand to a null 1807Note that unset variables used in the ${var} form expand to a null
1808string, which might result in syntax errors. 1808string, which might result in syntax errors.
1809Referencing the value of a variable which is not numeric is an error. 1809Referencing the value of a variable which is not numeric is an error.
1810.Pp 1810.Pp
1811All of the C expression operators applicable to integers are supported, 1811All of the C expression operators applicable to integers are supported,
1812and operate as they would in a C expression. 1812and operate as they would in a C expression.
1813Use white space, or parentheses, to disambiguate confusing syntax, 1813Use white space, or parentheses, to disambiguate confusing syntax,
1814otherwise, as in C, the longest sequence of consecutive characters 1814otherwise, as in C, the longest sequence of consecutive characters
1815which make a valid token (operator, variable name, or number) is taken 1815which make a valid token (operator, variable name, or number) is taken
1816to be that token, even if the token designated cannot be used 1816to be that token, even if the token designated cannot be used
1817and a different interpretation could produce a successful parse. 1817and a different interpretation could produce a successful parse.
1818This means, as an example, that 1818This means, as an example, that
1819.Dq a+++++b 1819.Dq a+++++b
1820is parsed as the gibberish sequence 1820is parsed as the gibberish sequence
1821.Dq "a ++ ++ + b" , 1821.Dq "a ++ ++ + b" ,
1822rather than as the valid alternative 1822rather than as the valid alternative
1823.Dq "a ++ + ++ b" . 1823.Dq "a ++ + ++ b" .
1824Similarly, separate the 1824Similarly, separate the
1825.Sq \&, 1825.Sq \&,
1826operator from numbers with white space to avoid the possibility 1826operator from numbers with white space to avoid the possibility
1827of confusion with the decimal indicator in some locales (though 1827of confusion with the decimal indicator in some locales (though
1828fractional, or floating-point, numbers are not supported in this 1828fractional, or floating-point, numbers are not supported in this
1829implementation.) 1829implementation.)
1830.Pp 1830.Pp
1831It should not be necessary to state that the C operators which 1831It should not be necessary to state that the C operators which
1832operate on, or produce, pointer types, are not supported. 1832operate on, or produce, pointer types, are not supported.
1833Those include unary 1833Those include unary
1834.Dq \&* 1834.Dq \&*
1835and 1835and
1836.Dq \&& 1836.Dq \&&
1837and the struct and array referencing binary operators: 1837and the struct and array referencing binary operators:
1838.Dq \&. , 1838.Dq \&. ,
1839.Dq \&-> 1839.Dq \&->
1840and 1840and
1841.Dq \&[ . 1841.Dq \&[ .
1842.Ss White Space Splitting (Field Splitting) 1842.Ss White Space Splitting (Field Splitting)
1843After parameter expansion, command substitution, and 1843After parameter expansion, command substitution, and
1844arithmetic expansion the shell scans the results of 1844arithmetic expansion the shell scans the results of
1845expansions and substitutions that did not occur in double quotes, 1845expansions and substitutions that did not occur in double quotes,
1846and 1846and
1847.Dq $@ 1847.Dq $@
1848even if it did, 1848even if it did,
1849for field splitting and multiple fields can result. 1849for field splitting and multiple fields can result.
1850.Pp 1850.Pp
1851The shell treats each character of the 1851The shell treats each character of the
1852.Ev IFS 1852.Ev IFS
1853as a delimiter and uses the delimiters to split the results of parameter 1853as a delimiter and uses the delimiters to split the results of parameter
1854expansion and command substitution into fields. 1854expansion and command substitution into fields.
1855.Pp 1855.Pp
1856Non-whitespace characters in 1856Non-whitespace characters in
1857.Ev IFS 1857.Ev IFS
1858are treated strictly as parameter separators. 1858are treated strictly as parameter separators.
1859So adjacent non-whitespace 1859So adjacent non-whitespace
1860.Ev IFS 1860.Ev IFS
1861characters will produce empty parameters. 1861characters will produce empty parameters.
1862On the other hand, any sequence of whitespace 1862On the other hand, any sequence of whitespace
1863characters that occur in 1863characters that occur in
1864.Ev IFS 1864.Ev IFS
1865(known as 1865(known as
1866.Ev IFS 1866.Ev IFS
1867whitespace) 1867whitespace)
1868can occur, leading and trailing 1868can occur, leading and trailing
1869.Ev IFS 1869.Ev IFS
1870whitespace, and any 1870whitespace, and any
1871.Ev IFS 1871.Ev IFS
1872whitespace surrounding a non whitespace 1872whitespace surrounding a non whitespace
1873.Ev IFS 1873.Ev IFS
1874delimiter, is removed. 1874delimiter, is removed.
1875Any sequence of 1875Any sequence of
1876.Ev IFS 1876.Ev IFS
1877whitespace characters without a non-whitespace 1877whitespace characters without a non-whitespace
1878.Ev IFS 1878.Ev IFS
1879delimiter acts as a single field separator. 1879delimiter acts as a single field separator.
1880.Pp 1880.Pp
1881If 1881If
1882.Ev IFS 1882.Ev IFS
1883is unset it is assumed to contain space, tab, and newline, 1883is unset it is assumed to contain space, tab, and newline,
1884all of which are 1884all of which are
1885.Ev IFS 1885.Ev IFS
1886whitespace characters. 1886whitespace characters.
1887If 1887If
1888.Ev IFS 1888.Ev IFS
1889is set to a null string, there are no delimiters, 1889is set to a null string, there are no delimiters,
1890and no field splitting occurs. 1890and no field splitting occurs.
1891.Ss Pathname Expansion (File Name Generation) 1891.Ss Pathname Expansion (File Name Generation)
1892Unless the 1892Unless the
1893.Fl f 1893.Fl f
1894flag is set, file name generation is performed after word splitting is 1894flag is set, file name generation is performed after word splitting is
1895complete. 1895complete.
1896Each word is viewed as a series of patterns, separated by slashes. 1896Each word is viewed as a series of patterns, separated by slashes.
1897The process of expansion replaces the word with the names of all 1897The process of expansion replaces the word with the names of all
1898existing files whose names can be formed by replacing each pattern with a 1898existing files whose names can be formed by replacing each pattern with a
1899string that matches the specified pattern. 1899string that matches the specified pattern.
1900There are two restrictions on 1900There are two restrictions on
1901this: first, a pattern cannot match a string containing a slash, and 1901this: first, a pattern cannot match a string containing a slash, and
1902second, a pattern cannot match a string starting with a period unless the 1902second, a pattern cannot match a string starting with a period unless the
1903first character of the pattern is a period. 1903first character of the pattern is a period.
1904The next section describes the 1904The next section describes the
1905patterns used for both Pathname Expansion and the 1905patterns used for both Pathname Expansion and the
1906.Ic case 1906.Ic case
1907command. 1907command.
1908.Ss Shell Patterns 1908.Ss Shell Patterns
1909A pattern consists of normal characters, which match themselves, 1909A pattern consists of normal characters, which match themselves,
1910and meta-characters. 1910and meta-characters.
1911The meta-characters are 1911The meta-characters are
1912.Dq \&! , 1912.Dq \&! ,
1913.Dq * , 1913.Dq * ,
1914.Dq \&? , 1914.Dq \&? ,
1915and 1915and
1916.Dq \&[ . 1916.Dq \&[ .
1917These characters lose their special meanings if they are quoted. 1917These characters lose their special meanings if they are quoted.
1918When command or variable substitution is performed 1918When command or variable substitution is performed
1919and the dollar sign or backquotes are not double-quoted, 1919and the dollar sign or backquotes are not double-quoted,
1920the value of the variable or the output of 1920the value of the variable or the output of
1921the command is scanned for these characters and they are turned into 1921the command is scanned for these characters and they are turned into
1922meta-characters. 1922meta-characters.
1923.Pp 1923.Pp
1924An asterisk 1924An asterisk
1925.Pq Dq * 1925.Pq Dq *
1926matches any string of characters. 1926matches any string of characters.
1927A question mark 1927A question mark
1928.Pq Dq \&? 1928.Pq Dq \&?
1929matches any single character. 1929matches any single character.
1930A left bracket 1930A left bracket
1931.Pq Dq \&[ 1931.Pq Dq \&[
1932introduces a character class. 1932introduces a character class.
1933The end of the character class is indicated by a right bracket 1933The end of the character class is indicated by a right bracket
1934.Pq Dq \&] ; 1934.Pq Dq \&] ;
1935if this 1935if this
1936.Dq \&] 1936.Dq \&]
1937is missing then the 1937is missing then the
1938.Dq \&[ 1938.Dq \&[
1939matches a 1939matches a
1940.Dq \&[ 1940.Dq \&[
1941rather than introducing a character class. 1941rather than introducing a character class.
1942A character class matches any of the characters between the square brackets. 1942A character class matches any of the characters between the square brackets.
1943A named class of characters (see 1943A named class of characters (see
1944.Xr wctype 3 ) 1944.Xr wctype 3 )
1945may be specified by surrounding the name with 1945may be specified by surrounding the name with
1946.Pq Dq [: 1946.Pq Dq [:
1947and 1947and
1948.Pq Dq :] . 1948.Pq Dq :] .
1949For example, 1949For example,
1950.Pq Dq [[:alpha:]] 1950.Pq Dq [[:alpha:]]
1951is a shell pattern that matches a single letter. 1951is a shell pattern that matches a single letter.
1952A range of characters may be specified using a minus sign 1952A range of characters may be specified using a minus sign
1953.Pq Dq \(mi . 1953.Pq Dq \(mi .
1954The character class may be complemented 1954The character class may be complemented
1955by making an exclamation mark 1955by making an exclamation mark
1956.Pq Dq \&! 1956.Pq Dq \&!
1957the first character of the character class. 1957the first character of the character class.
1958.Pp 1958.Pp
1959To include a 1959To include a
1960.Dq \&] 1960.Dq \&]
1961in a character class, make it the first character listed (after the 1961in a character class, make it the first character listed (after the
1962.Dq \&! , 1962.Dq \&! ,
1963if any). 1963if any).
1964To include a 1964To include a
1965.Dq \(mi , 1965.Dq \(mi ,
1966make it the first (after !) or last character listed. 1966make it the first (after !) or last character listed.
1967If both 1967If both
1968.Dq \&] 1968.Dq \&]
1969and 1969and
1970.Dq \(mi 1970.Dq \(mi
1971are to be included, the 1971are to be included, the
1972.Dq \&] 1972.Dq \&]
1973must be first (after !) 1973must be first (after !)
1974and the 1974and the
1975.Dq \(mi 1975.Dq \(mi
1976last, in the character class. 1976last, in the character class.
1977.Ss Built-ins 1977.Ss Built-ins
1978This section lists the built-in commands which are built-in because they 1978This section lists the built-in commands which are built-in because they
1979need to perform some operation that can't be performed by a separate 1979need to perform some operation that can't be performed by a separate
1980process. 1980process.
1981Or just because they traditionally are. 1981Or just because they traditionally are.
1982In addition to these, there are several other commands that may 1982In addition to these, there are several other commands that may
1983be built in for efficiency (e.g. 1983be built in for efficiency (e.g.
1984.Xr printf 1 , 1984.Xr printf 1 ,
1985.Xr echo 1 , 1985.Xr echo 1 ,
1986.Xr test 1 , 1986.Xr test 1 ,
1987etc). 1987etc).
1988.Bl -tag -width 5n 1988.Bl -tag -width 5n
1989.It : [ Ar arg ... ] 1989.It : [ Ar arg ... ]
1990A null command that returns a 0 (true) exit value. 1990A null command that returns a 0 (true) exit value.
1991Any arguments or redirects are evaluated, then ignored. 1991Any arguments or redirects are evaluated, then ignored.
1992.It \&. file 1992.It \&. file
1993The dot command reads and executes the commands from the specified 1993The dot command reads and executes the commands from the specified
1994.Ar file 1994.Ar file
1995in the current shell environment. 1995in the current shell environment.
1996The file does not need to be executable and is looked up from the directories 1996The file does not need to be executable and is looked up from the directories
1997listed in the 1997listed in the
1998.Ev PATH 1998.Ev PATH
1999variable if its name does not contain a directory separator 1999variable if its name does not contain a directory separator
2000.Pq Sq / . 2000.Pq Sq / .
2001The return command 2001The return command
2002(see 2002(see
2003.Sx Built-ins 2003.Sx Built-ins
2004below) 2004below)
2005can be used for a premature return from the sourced file. 2005can be used for a premature return from the sourced file.
2006.Pp 2006.Pp
2007The POSIX standard has been unclear on how loop control keywords (break 2007The POSIX standard has been unclear on how loop control keywords (break
2008and continue) behave across a dot command boundary. 2008and continue) behave across a dot command boundary.
2009This implementation allows them to control loops surrounding the dot command, 2009This implementation allows them to control loops surrounding the dot command,
2010but obviously such behavior should not be relied on. 2010but obviously such behavior should not be relied on.
2011It is now permitted by the standard, but not required. 2011It is now permitted by the standard, but not required.
2012.It alias Op Ar name Ns Op Ar "=string ..." 2012.It alias Op Ar name Ns Op Ar "=string ..."
2013If 2013If
2014.Ar name=string 2014.Ar name=string
2015is specified, the shell defines the alias 2015is specified, the shell defines the alias
2016.Ar name 2016.Ar name
2017with value 2017with value
2018.Ar string . 2018.Ar string .
2019If just 2019If just
2020.Ar name 2020.Ar name
2021is specified, the value of the alias 2021is specified, the value of the alias
2022.Ar name 2022.Ar name
2023is printed. 2023is printed.
2024With no arguments, the 2024With no arguments, the
2025.Ic alias 2025.Ic alias
2026built-in prints the 2026built-in prints the
2027names and values of all defined aliases (see 2027names and values of all defined aliases (see
2028.Ic unalias ) . 2028.Ic unalias ) .
2029.It bg [ Ar job ] ... 2029.It bg [ Ar job ] ...
2030Continue the specified jobs (or the current job if no 2030Continue the specified jobs (or the current job if no
2031jobs are given) in the background. 2031jobs are given) in the background.
2032.It command Oo Fl p Oc Oo Fl v Oc Oo Fl V Oc Ar command Oo Ar arg ... Oc 2032.It command Oo Fl p Oc Oo Fl v Oc Oo Fl V Oc Ar command Oo Ar arg ... Oc
2033Execute the specified command but ignore shell functions when searching 2033Execute the specified command but ignore shell functions when searching
2034for it. 2034for it.
2035(This is useful when you 2035(This is useful when you
2036have a shell function with the same name as a command.) 2036have a shell function with the same name as a command.)
2037.Bl -tag -width 5n 2037.Bl -tag -width 5n
2038.It Fl p 2038.It Fl p
2039search for command using a 2039search for command using a
2040.Ev PATH 2040.Ev PATH
2041that guarantees to find all the standard utilities. 2041that guarantees to find all the standard utilities.
2042.It Fl V 2042.It Fl V
2043Do not execute the command but 2043Do not execute the command but
2044search for the command and print the resolution of the 2044search for the command and print the resolution of the
2045command search. 2045command search.
2046This is the same as the 2046This is the same as the
2047.Ic type 2047.Ic type
2048built-in. 2048built-in.
2049.It Fl v 2049.It Fl v
2050Do not execute the command but 2050Do not execute the command but
2051search for the command and print the absolute pathname 2051search for the command and print the absolute pathname
2052of utilities, the name for built-ins or the expansion of aliases. 2052of utilities, the name for built-ins or the expansion of aliases.
2053.El 2053.El
2054.It cd Oo Fl P Oc Op Ar directory Op Ar replace 2054.It cd Oo Fl P Oc Op Ar directory Op Ar replace
2055Switch to the specified directory (default 2055Switch to the specified directory (default
2056.Ev $HOME ) . 2056.Ev $HOME ) .
2057If 2057If
2058.Ar replace 2058.Ar replace
2059is specified, then the new directory name is generated by replacing 2059is specified, then the new directory name is generated by replacing
2060the first occurrence of the string 2060the first occurrence of the string
2061.Ar directory 2061.Ar directory
2062in the current directory name with 2062in the current directory name with
2063.Ar replace . 2063.Ar replace .
2064Otherwise if 2064Otherwise if
2065.Ar directory 2065.Ar directory
2066is 2066is
2067.Sq - , 2067.Sq - ,
2068then the current working directory is changed to the previous current 2068then the current working directory is changed to the previous current
2069working directory as set in 2069working directory as set in
2070.Ev OLDPWD . 2070.Ev OLDPWD .
2071Otherwise if an entry for 2071Otherwise if an entry for
2072.Ev CDPATH 2072.Ev CDPATH
2073appears in the environment of the 2073appears in the environment of the
2074.Ic cd 2074.Ic cd
2075command or the shell variable 2075command or the shell variable
2076.Ev CDPATH 2076.Ev CDPATH
2077is set and the directory name does not begin with a slash, 2077is set and the directory name does not begin with a slash,
2078and its first (or only) component isn't dot or dot dot, 2078and its first (or only) component isn't dot or dot dot,
2079then the directories listed in 2079then the directories listed in
2080.Ev CDPATH 2080.Ev CDPATH
2081will be searched for the specified directory. 2081will be searched for the specified directory.
2082The format of 2082The format of
2083.Ev CDPATH 2083.Ev CDPATH
2084is the same as that of 2084is the same as that of
2085.Ev PATH . 2085.Ev PATH .
2086.Pp 2086.Pp
2087The 2087The
2088.Fl P 2088.Fl P
2089option instructs the shell to update 2089option instructs the shell to update
2090.Ev PWD 2090.Ev PWD
2091with the specified physical directory path and change to that directory. 2091with the specified physical directory path and change to that directory.
2092This is the default. 2092This is the default.
2093.Pp 2093.Pp
2094When the directory changes, the variable 2094When the directory changes, the variable
2095.Ev OLDPWD 2095.Ev OLDPWD
2096is set to the working directory before the change. 2096is set to the working directory before the change.
2097.Pp 2097.Pp
2098Some shells also support a 2098Some shells also support a
2099.Fl L 2099.Fl L
2100option, which instructs the shell to update 2100option, which instructs the shell to update
2101.Ev PWD 2101.Ev PWD
2102with the logical path and to change the current directory 2102with the logical path and to change the current directory
2103accordingly. 2103accordingly.
2104This is not supported. 2104This is not supported.
2105.Pp 2105.Pp
2106In an interactive shell, the 2106In an interactive shell, the
2107.Ic cd 2107.Ic cd
2108command will print out the name of the 2108command will print out the name of the
2109directory that it actually switched to if this is different from the name 2109directory that it actually switched to if this is different from the name
2110that the user gave, 2110that the user gave,
2111or always if the 2111or always if the
2112.Ic cdprint 2112.Ic cdprint
2113option is set. 2113option is set.
2114The destination may be different either because the 2114The destination may be different either because the
2115.Ev CDPATH 2115.Ev CDPATH
2116mechanism was used 2116mechanism was used
2117.\" or because a symbolic link was crossed. 2117.\" or because a symbolic link was crossed.
2118or if the 2118or if the
2119.Ar replace 2119.Ar replace
2120argument was used. 2120argument was used.
2121.It eval Ar string ... 2121.It eval Ar string ...
2122Concatenate all the arguments with spaces. 2122Concatenate all the arguments with spaces.