Tue Mar 13 19:35:46 2018 UTC ()
.Bd expects the display type to come first, so move -compact to the end.


(uwe)
diff -r1.176 -r1.177 src/bin/sh/sh.1

cvs diff -r1.176 -r1.177 src/bin/sh/sh.1 (switch to unified diff)

--- src/bin/sh/sh.1 2018/03/13 19:18:53 1.176
+++ src/bin/sh/sh.1 2018/03/13 19:35:46 1.177
@@ -1,1444 +1,1444 @@ @@ -1,1444 +1,1444 @@
1.\" $NetBSD: sh.1,v 1.176 2018/03/13 19:18:53 uwe Exp $ 1.\" $NetBSD: sh.1,v 1.177 2018/03/13 19:35:46 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 -compact -literal 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.Dl hello() cat <<EOF 1413.Dl hello() cat <<EOF
1414.Dl Hello World! 1414.Dl Hello World!
1415.Dl EOF 1415.Dl EOF
1416To be correctly standards conforming this should be re-written as: 1416To be correctly standards conforming this should be re-written as:
1417.Dl hello() { cat; } <<EOF 1417.Dl hello() { cat; } <<EOF
1418.Dl Hello World! 1418.Dl Hello World!
1419.Dl EOF 1419.Dl EOF
1420Note the distinction between those forms, and 1420Note the distinction between those forms, and
1421.Dl hello() { cat <<EOF 1421.Dl hello() { cat <<EOF
1422.Dl Hello World! 1422.Dl Hello World!
1423.Dl EOF 1423.Dl EOF
1424.Dl \&} 1424.Dl \&}
1425which reads and processes the 1425which reads and processes the
1426.Ic here document 1426.Ic here document
1427each time the shell executes the function, and which applies 1427each time the shell executes the function, and which applies
1428that input only to the cat command, not to any other commands 1428that input only to the cat command, not to any other commands
1429that might appear in the function. 1429that might appear in the function.
1430.Pp 1430.Pp
1431Variables may be declared to be local to a function by using the 1431Variables may be declared to be local to a function by using the
1432.Ic local 1432.Ic local
1433command. 1433command.
1434This should usually appear as the first statement of a function, 1434This should usually appear as the first statement of a function,
1435though 1435though
1436.Ic local 1436.Ic local
1437is an executable command which can be used anywhere in a function. 1437is an executable command which can be used anywhere in a function.
1438See 1438See
1439.Sx Built-ins 1439.Sx Built-ins
1440below for its definition. 1440below for its definition.
1441.Pp 1441.Pp
1442The function completes after having executed 1442The function completes after having executed
1443.Ar command 1443.Ar command
1444with exit status set to the status returned by 1444with exit status set to the status returned by
@@ -2531,1501 +2531,1501 @@ With the @@ -2531,1501 +2531,1501 @@ With the
2531.Fl p 2531.Fl p
2532flag, the output contains only the process identifier of the lead 2532flag, the output contains only the process identifier of the lead
2533process. 2533process.
2534.Pp 2534.Pp
2535In an interactive shell, each job shown as completed in the output 2535In an interactive shell, each job shown as completed in the output
2536from the jobs command is implicitly waited for, and is removed from 2536from the jobs command is implicitly waited for, and is removed from
2537the jobs table, never to be seen again. 2537the jobs table, never to be seen again.
2538In an interactive shell, when a background job terminates, the 2538In an interactive shell, when a background job terminates, the
2539.Ic jobs 2539.Ic jobs
2540command (with that job as an argument) is implicitly run just 2540command (with that job as an argument) is implicitly run just
2541before outputting the next PS1 command prompt, after the job 2541before outputting the next PS1 command prompt, after the job
2542terminated. 2542terminated.
2543This indicates that the job finished, shows its status, 2543This indicates that the job finished, shows its status,
2544and cleans up the job table entry for that job. 2544and cleans up the job table entry for that job.
2545Non-interactive shells need to execute 2545Non-interactive shells need to execute
2546.Ic wait 2546.Ic wait
2547commands to clean up terminated background jobs. 2547commands to clean up terminated background jobs.
2548.It local Oo Fl INx Oc Oo Ar variable | \- Oc ... 2548.It local Oo Fl INx Oc Oo Ar variable | \- Oc ...
2549Define local variables for a function. 2549Define local variables for a function.
2550Local variables have their attributes, and values, 2550Local variables have their attributes, and values,
2551as they were before the 2551as they were before the
2552.Ic local 2552.Ic local
2553declaration, restored when the function terminates. 2553declaration, restored when the function terminates.
2554.Pp 2554.Pp
2555With the 2555With the
2556.Fl N 2556.Fl N
2557flag, variables made local, are unset initially inside 2557flag, variables made local, are unset initially inside
2558the function. 2558the function.
2559Unless the 2559Unless the
2560.Fl x 2560.Fl x
2561flag is also given, such variables are also unexported. 2561flag is also given, such variables are also unexported.
2562The 2562The
2563.Fl I 2563.Fl I
2564flag, which is the default in this shell, causes 2564flag, which is the default in this shell, causes
2565the initial value and exported attribute 2565the initial value and exported attribute
2566of local variables 2566of local variables
2567to be inherited from the variable 2567to be inherited from the variable
2568with the same name in the surrounding 2568with the same name in the surrounding
2569scope, if there is one. 2569scope, if there is one.
2570If there is not, the variable is initially unset, 2570If there is not, the variable is initially unset,
2571and not exported. 2571and not exported.
2572The 2572The
2573.Fl N 2573.Fl N
2574and 2574and
2575.Fl I 2575.Fl I
2576flags are mutually exclusive, if both are given, the last specified applies. 2576flags are mutually exclusive, if both are given, the last specified applies.
2577The read-only and unexportable attributes are always 2577The read-only and unexportable attributes are always
2578inherited, if a variable with the same name already exists. 2578inherited, if a variable with the same name already exists.
2579.Pp 2579.Pp
2580The 2580The
2581.Fl x 2581.Fl x
2582flag (lower case) causes the local variable to be exported, 2582flag (lower case) causes the local variable to be exported,
2583while the function runs, unless it has the unexportable attribute. 2583while the function runs, unless it has the unexportable attribute.
2584This can also be accomplished by using the 2584This can also be accomplished by using the
2585.Ic export 2585.Ic export
2586command, giving the same 2586command, giving the same
2587.Ar variable 2587.Ar variable
2588names, after the 2588names, after the
2589.Ic local 2589.Ic local
2590command. 2590command.
2591.Pp 2591.Pp
2592Making an existing read-only variable local is possible, 2592Making an existing read-only variable local is possible,
2593but pointless. 2593but pointless.
2594If an attempt is made to assign an initial value to such 2594If an attempt is made to assign an initial value to such
2595a variable, the 2595a variable, the
2596.Ic local 2596.Ic local
2597command fails, as does any later attempted assignment. 2597command fails, as does any later attempted assignment.
2598If the 2598If the
2599.Ic readonly 2599.Ic readonly
2600command is applied to a variable that has been declared local, 2600command is applied to a variable that has been declared local,
2601the variable cannot be (further) modified within the function, 2601the variable cannot be (further) modified within the function,
2602or any other functions it calls, however when the function returns, 2602or any other functions it calls, however when the function returns,
2603the previous status (and value) of the variable is returned. 2603the previous status (and value) of the variable is returned.
2604.Pp 2604.Pp
2605Values may be given to local variables on the 2605Values may be given to local variables on the
2606.Ic local 2606.Ic local
2607command line in a similar fashion as used for 2607command line in a similar fashion as used for
2608.Ic export 2608.Ic export
2609and 2609and
2610.Ic readonly . 2610.Ic readonly .
2611These values are assigned immediately after the initialization 2611These values are assigned immediately after the initialization
2612described above. 2612described above.
2613Note that any variable references on the command line will have 2613Note that any variable references on the command line will have
2614been expanded before 2614been expanded before
2615.Ic local 2615.Ic local
2616is executed, so expressions like 2616is executed, so expressions like
2617.Dl "local -N X=${X}" 2617.Dl "local -N X=${X}"
2618are well defined, first $X is expanded, and then the command run is 2618are well defined, first $X is expanded, and then the command run is
2619.Dl "local -N X=old-value-of-X" 2619.Dl "local -N X=old-value-of-X"
2620After arranging to preserve the old value and attributes, of X 2620After arranging to preserve the old value and attributes, of X
2621.Dq ( old-value-of X ) 2621.Dq ( old-value-of X )
2622.Ic local 2622.Ic local
2623unsets 2623unsets
2624.Ev X , 2624.Ev X ,
2625unexports it, and then assigns the 2625unexports it, and then assigns the
2626.Dq old-value-of-X 2626.Dq old-value-of-X
2627to 2627to
2628.Ev X . 2628.Ev X .
2629.Pp 2629.Pp
2630The shell uses dynamic scoping, so that if you make the variable x local to 2630The shell uses dynamic scoping, so that if you make the variable x local to
2631function f, which then calls function g, references to the variable x made 2631function f, which then calls function g, references to the variable x made
2632inside g will refer to the variable x declared inside f, not to the global 2632inside g will refer to the variable x declared inside f, not to the global
2633variable named x. 2633variable named x.
2634.Pp 2634.Pp
2635Another way to view this, is as if the shell just has one flat, global, 2635Another way to view this, is as if the shell just has one flat, global,
2636namespace, in which all variables exist. 2636namespace, in which all variables exist.
2637The 2637The
2638.Ic local 2638.Ic local
2639command conceptually copies the variable(s) named to unnamed temporary 2639command conceptually copies the variable(s) named to unnamed temporary
2640variables, and when the function ends, copies them back again. 2640variables, and when the function ends, copies them back again.
2641All references to the variables reference the same global variables, 2641All references to the variables reference the same global variables,
2642but while the function is active, after the 2642but while the function is active, after the
2643.Ic local 2643.Ic local
2644command has run, the values and attributes of the variables might 2644command has run, the values and attributes of the variables might
2645be altered, and later, when the function completes, be restored. 2645be altered, and later, when the function completes, be restored.
2646.Pp 2646.Pp
2647Note that the parameters $1, $2, ... (see 2647Note that the parameters $1, $2, ... (see
2648.Sx Positional Parameters ) , 2648.Sx Positional Parameters ) ,
2649and $#, $* and $@ (see 2649and $#, $* and $@ (see
2650.Sx Special Parameters ) , 2650.Sx Special Parameters ) ,
2651are always made local in all functions, and are reset inside the 2651are always made local in all functions, and are reset inside the
2652function to represent the options and arguments passed to the function. 2652function to represent the options and arguments passed to the function.
2653Note that $0 however retains the value it had outside the function, 2653Note that $0 however retains the value it had outside the function,
2654as do all the other special parameters. 2654as do all the other special parameters.
2655.Pp 2655.Pp
2656The only other special parameter that can be made local is 2656The only other special parameter that can be made local is
2657.Dq \- . 2657.Dq \- .
2658Making 2658Making
2659.Dq \- 2659.Dq \-
2660local causes any shell options that are changed via the set command inside the 2660local causes any shell options that are changed via the set command inside the
2661function to be restored to their original values when the function 2661function to be restored to their original values when the function
2662returns. 2662returns.
2663If 2663If
2664.Fl X 2664.Fl X
2665option is altered after 2665option is altered after
2666.Dq \- 2666.Dq \-
2667has been made local, then when the function returns, the previous 2667has been made local, then when the function returns, the previous
2668destination for 2668destination for
2669.Ic xtrace 2669.Ic xtrace
2670output (as of the time of the 2670output (as of the time of the
2671.Ic local 2671.Ic local
2672command) will also be restored. 2672command) will also be restored.
2673.Pp 2673.Pp
2674It is an error to use 2674It is an error to use
2675.Ic local 2675.Ic local
2676outside the scope of a function definition. 2676outside the scope of a function definition.
2677When used inside a function, it exits with status 0, 2677When used inside a function, it exits with status 0,
2678unless an undefined option is used, or an attempt is made to 2678unless an undefined option is used, or an attempt is made to
2679assign a value to a read-only variable. 2679assign a value to a read-only variable.
2680.Pp 2680.Pp
2681Note that either 2681Note that either
2682.Fl I 2682.Fl I
2683or 2683or
2684.Fl N 2684.Fl N
2685should always be used, or variables made local should always 2685should always be used, or variables made local should always
2686be given a value, or explicitly unset, as the default behavior 2686be given a value, or explicitly unset, as the default behavior
2687(inheriting the earlier value, or starting unset after 2687(inheriting the earlier value, or starting unset after
2688.Ic local ) 2688.Ic local )
2689differs amongst shell implementations. 2689differs amongst shell implementations.
2690Using 2690Using
2691.Dq local \&\- 2691.Dq local \&\-
2692is an extension not implemented by most shells. 2692is an extension not implemented by most shells.
2693.Pp 2693.Pp
2694See the section 2694See the section
2695.Sx LINENO 2695.Sx LINENO
2696below for details of the effects of making the variable 2696below for details of the effects of making the variable
2697.Ev LINENO 2697.Ev LINENO
2698local. 2698local.
2699.It pwd Op Fl \&LP 2699.It pwd Op Fl \&LP
2700Print the current directory. 2700Print the current directory.
2701If 2701If
2702.Fl L 2702.Fl L
2703is specified the cached value (initially set from 2703is specified the cached value (initially set from
2704.Ev PWD ) 2704.Ev PWD )
2705is checked to see if it refers to the current directory; if it does 2705is checked to see if it refers to the current directory; if it does
2706the value is printed. 2706the value is printed.
2707Otherwise the current directory name is found using 2707Otherwise the current directory name is found using
2708.Xr getcwd 3 . 2708.Xr getcwd 3 .
2709The environment variable 2709The environment variable
2710.Ev PWD 2710.Ev PWD
2711is set to the printed value. 2711is set to the printed value.
2712.Pp 2712.Pp
2713The default is 2713The default is
2714.Ic pwd 2714.Ic pwd
2715.Fl L , 2715.Fl L ,
2716but note that the built-in 2716but note that the built-in
2717.Ic cd 2717.Ic cd
2718command doesn't support the 2718command doesn't support the
2719.Fl L 2719.Fl L
2720option and will cache (almost) the absolute path. 2720option and will cache (almost) the absolute path.
2721If 2721If
2722.Ic cd 2722.Ic cd
2723is changed (as unlikely as that is), 2723is changed (as unlikely as that is),
2724.Ic pwd 2724.Ic pwd
2725may be changed to default to 2725may be changed to default to
2726.Ic pwd 2726.Ic pwd
2727.Fl P . 2727.Fl P .
2728.Pp 2728.Pp
2729If the current directory is renamed and replaced by a symlink to the 2729If the current directory is renamed and replaced by a symlink to the
2730same directory, or the initial 2730same directory, or the initial
2731.Ev PWD 2731.Ev PWD
2732value followed a symbolic link, then the cached value may not 2732value followed a symbolic link, then the cached value may not
2733be the absolute path. 2733be the absolute path.
2734.Pp 2734.Pp
2735The built-in command may differ from the program of the same name because 2735The built-in command may differ from the program of the same name because
2736the program will use 2736the program will use
2737.Ev PWD 2737.Ev PWD
2738and the built-in uses a separately cached value. 2738and the built-in uses a separately cached value.
2739.It read Oo Fl p Ar prompt Oc Oo Fl r Oc Ar variable Oo Ar ... Oc 2739.It read Oo Fl p Ar prompt Oc Oo Fl r Oc Ar variable Oo Ar ... Oc
2740The prompt is printed if the 2740The prompt is printed if the
2741.Fl p 2741.Fl p
2742option is specified and the standard input is a terminal. 2742option is specified and the standard input is a terminal.
2743Then a line is read from the standard input. 2743Then a line is read from the standard input.
2744The trailing newline is deleted from the 2744The trailing newline is deleted from the
2745line and the line is split as described in the field splitting section of the 2745line and the line is split as described in the field splitting section of the
2746.Sx Word Expansions 2746.Sx Word Expansions
2747section above, and the pieces are assigned to the variables in order. 2747section above, and the pieces are assigned to the variables in order.
2748If there are more pieces than variables, the remaining pieces 2748If there are more pieces than variables, the remaining pieces
2749(along with the characters in 2749(along with the characters in
2750.Ev IFS 2750.Ev IFS
2751that separated them) are assigned to the last variable. 2751that separated them) are assigned to the last variable.
2752If there are more variables than pieces, 2752If there are more variables than pieces,
2753the remaining variables are assigned the null string. 2753the remaining variables are assigned the null string.
2754The 2754The
2755.Ic read 2755.Ic read
2756built-in will indicate success unless EOF is encountered on input, in 2756built-in will indicate success unless EOF is encountered on input, in
2757which case failure is returned. 2757which case failure is returned.
2758.Pp 2758.Pp
2759By default, unless the 2759By default, unless the
2760.Fl r 2760.Fl r
2761option is specified, the backslash 2761option is specified, the backslash
2762.Dq \e 2762.Dq \e
2763acts as an escape character, causing the following character to be treated 2763acts as an escape character, causing the following character to be treated
2764literally. 2764literally.
2765If a backslash is followed by a newline, the backslash and the 2765If a backslash is followed by a newline, the backslash and the
2766newline will be deleted. 2766newline will be deleted.
2767.It readonly Ar name ... 2767.It readonly Ar name ...
2768.It readonly Oo Fl p Oc 2768.It readonly Oo Fl p Oc
2769The specified names are marked as read only, so that they cannot be 2769The specified names are marked as read only, so that they cannot be
2770subsequently modified or unset. 2770subsequently modified or unset.
2771The shell allows the value of a variable 2771The shell allows the value of a variable
2772to be set at the same time it is marked read only by writing 2772to be set at the same time it is marked read only by writing
2773.Pp 2773.Pp
2774.Dl readonly name=value 2774.Dl readonly name=value
2775.Pp 2775.Pp
2776With no arguments the readonly command lists the names of all read only 2776With no arguments the readonly command lists the names of all read only
2777variables. 2777variables.
2778With the 2778With the
2779.Fl p 2779.Fl p
2780option specified the output will be formatted suitably for non-interactive use. 2780option specified the output will be formatted suitably for non-interactive use.
2781.It return Op Ar n 2781.It return Op Ar n
2782Stop executing the current function or a dot command with return value of 2782Stop executing the current function or a dot command with return value of
2783.Ar n 2783.Ar n
2784or the value of the last executed command, if not specified. 2784or the value of the last executed command, if not specified.
2785For portability, 2785For portability,
2786.Ar n 2786.Ar n
2787should be in the range from 0 to 255. 2787should be in the range from 0 to 255.
2788.Pp 2788.Pp
2789The POSIX standard says that the results of 2789The POSIX standard says that the results of
2790.Sq return 2790.Sq return
2791outside a function or a dot command are unspecified. 2791outside a function or a dot command are unspecified.
2792This implementation treats such a return as a no-op with a return value of 0 2792This implementation treats such a return as a no-op with a return value of 0
2793(success, true). 2793(success, true).
2794Use the exit command instead, if you want to return from a script or exit 2794Use the exit command instead, if you want to return from a script or exit
2795your shell. 2795your shell.
2796.It set Oo { Fl options | Cm +options | Cm \-- } Oc Ar arg ... 2796.It set Oo { Fl options | Cm +options | Cm \-- } Oc Ar arg ...
2797The 2797The
2798.Ic set 2798.Ic set
2799command performs four different functions. 2799command performs four different functions.
2800.Pp 2800.Pp
2801With no arguments, it lists the values of all shell variables. 2801With no arguments, it lists the values of all shell variables.
2802.Pp 2802.Pp
2803With a single option of either 2803With a single option of either
2804.Sq Fl o 2804.Sq Fl o
2805or 2805or
2806.Sq Cm +o 2806.Sq Cm +o
2807.Ic set 2807.Ic set
2808outputs the current values of the options. 2808outputs the current values of the options.
2809In the 2809In the
2810.Fl o 2810.Fl o
2811form, all options are listed, with their current values. 2811form, all options are listed, with their current values.
2812In the 2812In the
2813.Cm +o 2813.Cm +o
2814form, the shell outputs a string that can later be used 2814form, the shell outputs a string that can later be used
2815as a command to reset all options to their current values. 2815as a command to reset all options to their current values.
2816.Pp 2816.Pp
2817If options are given, it sets the specified option 2817If options are given, it sets the specified option
2818flags, or clears them as described in the 2818flags, or clears them as described in the
2819.Sx Argument List Processing 2819.Sx Argument List Processing
2820section. 2820section.
2821In addition to the options listed there, 2821In addition to the options listed there,
2822when the 2822when the
2823.Dq "option name" 2823.Dq "option name"
2824given to 2824given to
2825.Ic set Fl o 2825.Ic set Fl o
2826is 2826is
2827.Cm default 2827.Cm default
2828all of the options are reset to the values they had immediately 2828all of the options are reset to the values they had immediately
2829after 2829after
2830.Nm 2830.Nm
2831initialization, before any startup scripts, or other input, had been processed. 2831initialization, before any startup scripts, or other input, had been processed.
2832While this may be of use to users or scripts, its primary purpose 2832While this may be of use to users or scripts, its primary purpose
2833is for use in the output of 2833is for use in the output of
2834.Dq Ic set Cm +o , 2834.Dq Ic set Cm +o ,
2835to avoid that command needing to list every available option. 2835to avoid that command needing to list every available option.
2836There is no 2836There is no
2837.Cm +o default . 2837.Cm +o default .
2838.Pp 2838.Pp
2839The fourth use of the set command is to set the values of the shell's 2839The fourth use of the set command is to set the values of the shell's
2840positional parameters to the specified arguments. 2840positional parameters to the specified arguments.
2841To change the positional 2841To change the positional
2842parameters without changing any options, use 2842parameters without changing any options, use
2843.Dq -\|- 2843.Dq -\|-
2844as the first argument to set. 2844as the first argument to set.
2845If no following arguments are present, the set command 2845If no following arguments are present, the set command
2846will clear all the positional parameters (equivalent to executing 2846will clear all the positional parameters (equivalent to executing
2847.Dq shift $# . ) 2847.Dq shift $# . )
2848Otherwise the following arguments become 2848Otherwise the following arguments become
2849.Dq \&$1 , 2849.Dq \&$1 ,
2850.Dq \&$2 , 2850.Dq \&$2 ,
2851\&..., 2851\&...,
2852and 2852and
2853.Dq \&$# 2853.Dq \&$#
2854is set to the number of arguments present. 2854is set to the number of arguments present.
2855.It setvar Ar variable Ar value 2855.It setvar Ar variable Ar value
2856Assigns value to variable. 2856Assigns value to variable.
2857(In general it is better to write 2857(In general it is better to write
2858variable=value rather than using 2858variable=value rather than using
2859.Ic setvar . 2859.Ic setvar .
2860.Ic setvar 2860.Ic setvar
2861is intended to be used in 2861is intended to be used in
2862functions that assign values to variables whose names are passed as 2862functions that assign values to variables whose names are passed as
2863parameters.) 2863parameters.)
2864.It shift Op Ar n 2864.It shift Op Ar n
2865Shift the positional parameters n times. 2865Shift the positional parameters n times.
2866If n is omitted, 1 is assumed. 2866If n is omitted, 1 is assumed.
2867Each 2867Each
2868.Ic shift 2868.Ic shift
2869sets the value of 2869sets the value of
2870.Va $1 2870.Va $1
2871to the previous value of 2871to the previous value of
2872.Va $2 , 2872.Va $2 ,
2873the value of 2873the value of
2874.Va $2 2874.Va $2
2875to the previous value of 2875to the previous value of
2876.Va $3 , 2876.Va $3 ,
2877and so on, decreasing 2877and so on, decreasing
2878the value of 2878the value of
2879.Va $# 2879.Va $#
2880by one. 2880by one.
2881The shift count must be less than or equal to the number of 2881The shift count must be less than or equal to the number of
2882positional parameters ( 2882positional parameters (
2883.Dq $# ) 2883.Dq $# )
2884before the shift. 2884before the shift.
2885.It times 2885.It times
2886Prints two lines to standard output. 2886Prints two lines to standard output.
2887Each line contains two accumulated time values, expressed 2887Each line contains two accumulated time values, expressed
2888in minutes and seconds (including fractions of a second.) 2888in minutes and seconds (including fractions of a second.)
2889The first value gives the user time consumed, the second the system time. 2889The first value gives the user time consumed, the second the system time.
2890.Pp 2890.Pp
2891The first output line gives the CPU and system times consumed by the 2891The first output line gives the CPU and system times consumed by the
2892shell itself. 2892shell itself.
2893The second line gives the accumulated times for children of this 2893The second line gives the accumulated times for children of this
2894shell (and their descendants) which have exited, and then been 2894shell (and their descendants) which have exited, and then been
2895successfully waited for by the relevant parent. 2895successfully waited for by the relevant parent.
2896See 2896See
2897.Xr times 3 2897.Xr times 3
2898for more information. 2898for more information.
2899.Pp 2899.Pp
2900.Ic times 2900.Ic times
2901has no parameters, and exits with an exit status of 0 unless 2901has no parameters, and exits with an exit status of 0 unless
2902an attempt is made to give it an option. 2902an attempt is made to give it an option.
2903.It trap Ar action signal ... 2903.It trap Ar action signal ...
2904.It trap \- 2904.It trap \-
2905.It trap Oo Fl l Oc 2905.It trap Oo Fl l Oc
2906.It trap Oo Fl p Oc signal ... 2906.It trap Oo Fl p Oc signal ...
2907.It trap Ar N signal ... 2907.It trap Ar N signal ...
2908.Pp 2908.Pp
2909Cause the shell to parse and execute action when any of the specified 2909Cause the shell to parse and execute action when any of the specified
2910signals are received. 2910signals are received.
2911The signals are specified by signal number or as the name of the signal. 2911The signals are specified by signal number or as the name of the signal.
2912If 2912If
2913.Ar signal 2913.Ar signal
2914is 2914is
2915.Li 0 2915.Li 0
2916or its equivalent, EXIT, 2916or its equivalent, EXIT,
2917the action is executed when the shell exits. 2917the action is executed when the shell exits.
2918The 2918The
2919.Ar action 2919.Ar action
2920may be a null (empty) string, 2920may be a null (empty) string,
2921which causes the specified signals to be ignored. 2921which causes the specified signals to be ignored.
2922With 2922With
2923.Ar action 2923.Ar action
2924set to 2924set to
2925.Sq - 2925.Sq -
2926the specified signals are set to their default actions. 2926the specified signals are set to their default actions.
2927If the first 2927If the first
2928.Ar signal 2928.Ar signal
2929is specified in its numeric form, then 2929is specified in its numeric form, then
2930.Ar action 2930.Ar action
2931can be omitted to achieve the same effect. 2931can be omitted to achieve the same effect.
2932This archaic, 2932This archaic,
2933but still standard, 2933but still standard,
2934form should not be relied upon, use the explicit 2934form should not be relied upon, use the explicit
2935.Sq - 2935.Sq -
2936action. 2936action.
2937If no signals are specified with an action of 2937If no signals are specified with an action of
2938.Sq - , 2938.Sq - ,
2939all signals are reset. 2939all signals are reset.
2940.Pp 2940.Pp
2941When the shell forks off a sub-shell, it resets trapped (but not ignored) 2941When the shell forks off a sub-shell, it resets trapped (but not ignored)
2942signals to the default action. 2942signals to the default action.
2943On non-interactive shells, the 2943On non-interactive shells, the
2944.Ic trap 2944.Ic trap
2945command has no effect on signals that were 2945command has no effect on signals that were
2946ignored on entry to the shell. 2946ignored on entry to the shell.
2947On interactive shells, the 2947On interactive shells, the
2948.Ic trap 2948.Ic trap
2949command will catch or reset signals ignored on entry. 2949command will catch or reset signals ignored on entry.
2950.Pp 2950.Pp
2951Issuing 2951Issuing
2952.Ic trap 2952.Ic trap
2953with option 2953with option
2954.Fl l 2954.Fl l
2955will print a list of valid signal names. 2955will print a list of valid signal names.
2956.Ic trap 2956.Ic trap
2957without any arguments causes it to write a list of signals and their 2957without any arguments causes it to write a list of signals and their
2958associated non-default actions to the standard output in a format 2958associated non-default actions to the standard output in a format
2959that is suitable as an input to the shell that achieves the same 2959that is suitable as an input to the shell that achieves the same
2960trapping results. 2960trapping results.
2961With the 2961With the
2962.Fl p 2962.Fl p
2963flag, trap prints the same information for the signals specified, 2963flag, trap prints the same information for the signals specified,
2964or if none are given, for all signals, including those where the 2964or if none are given, for all signals, including those where the
2965action is the default. 2965action is the default.
2966.Pp 2966.Pp
2967Examples: 2967Examples:
2968.Pp 2968.Pp
2969.Dl trap 2969.Dl trap
2970.Pp 2970.Pp
2971List trapped signals and their corresponding actions. 2971List trapped signals and their corresponding actions.
2972.Pp 2972.Pp
2973.Dl trap -l 2973.Dl trap -l
2974.Pp 2974.Pp
2975Print a list of valid signals. 2975Print a list of valid signals.
2976.Pp 2976.Pp
2977.Dl trap '' INT QUIT tstp 30 2977.Dl trap '' INT QUIT tstp 30
2978.Pp 2978.Pp
2979Ignore signals INT QUIT TSTP USR1. 2979Ignore signals INT QUIT TSTP USR1.
2980.Pp 2980.Pp
2981.Dl trap date INT 2981.Dl trap date INT
2982.Pp 2982.Pp
2983Run the 2983Run the
2984.Dq date 2984.Dq date
2985command (print the date) upon receiving signal INT. 2985command (print the date) upon receiving signal INT.
2986.Pp 2986.Pp
2987.Dl trap HUP INT 2987.Dl trap HUP INT
2988.Pp 2988.Pp
2989Run the 2989Run the
2990.Dq HUP 2990.Dq HUP
2991command, or function, upon receiving signal INT. 2991command, or function, upon receiving signal INT.
2992.Pp 2992.Pp
2993.Dl trap 1 2 2993.Dl trap 1 2
2994.Pp 2994.Pp
2995Reset the actions for signals 1 (HUP) and 2 (INT) to their defaults. 2995Reset the actions for signals 1 (HUP) and 2 (INT) to their defaults.
2996.Bd -literal -offset indent 2996.Bd -literal -offset indent
2997traps=$(trap -p) 2997traps=$(trap -p)
2998 # more commands ... 2998 # more commands ...
2999trap 'action' SIG 2999trap 'action' SIG
3000 # more commands ... 3000 # more commands ...
3001eval "$traps" 3001eval "$traps"
3002.Ed 3002.Ed
3003.Pp 3003.Pp
3004Save the trap status, execute commands, changing some traps, 3004Save the trap status, execute commands, changing some traps,
3005and then reset all traps to their values at the start of the sequence. 3005and then reset all traps to their values at the start of the sequence.
3006The 3006The
3007.Fl p 3007.Fl p
3008option is required in the first command here, 3008option is required in the first command here,
3009or any signals that were previously 3009or any signals that were previously
3010untrapped (in their default states) 3010untrapped (in their default states)
3011and which were altered during the intermediate code, 3011and which were altered during the intermediate code,
3012would not be reset by the final 3012would not be reset by the final
3013.Dq eval . 3013.Dq eval .
3014.It type Op Ar name ... 3014.It type Op Ar name ...
3015Interpret each name as a command and print the resolution of the command 3015Interpret each name as a command and print the resolution of the command
3016search. 3016search.
3017Possible resolutions are: 3017Possible resolutions are:
3018shell keyword, alias, shell built-in, 3018shell keyword, alias, shell built-in,
3019command, tracked alias and not found. 3019command, tracked alias and not found.
3020For aliases the alias expansion is 3020For aliases the alias expansion is
3021printed; for commands and tracked aliases the complete pathname of the 3021printed; for commands and tracked aliases the complete pathname of the
3022command is printed. 3022command is printed.
3023.It ulimit Oo Fl H \*(Ba Fl S Oc Oo Fl a \*(Ba Fl btfdscmlrpnv Oo Ar value Oc Oc 3023.It ulimit Oo Fl H \*(Ba Fl S Oc Oo Fl a \*(Ba Fl btfdscmlrpnv Oo Ar value Oc Oc
3024Inquire about or set the hard or soft limits on processes or set new 3024Inquire about or set the hard or soft limits on processes or set new
3025limits. 3025limits.
3026The choice between hard limit (which no process is allowed to 3026The choice between hard limit (which no process is allowed to
3027violate, and which may not be raised once it has been lowered) and soft 3027violate, and which may not be raised once it has been lowered) and soft
3028limit (which causes processes to be signaled but not necessarily killed, 3028limit (which causes processes to be signaled but not necessarily killed,
3029and which may be raised) is made with these flags: 3029and which may be raised) is made with these flags:
3030.Bl -tag -width Fl 3030.Bl -tag -width Fl
3031.It Fl H 3031.It Fl H
3032set or inquire about hard limits 3032set or inquire about hard limits
3033.It Fl S 3033.It Fl S
3034set or inquire about soft limits. 3034set or inquire about soft limits.
3035If neither 3035If neither
3036.Fl H 3036.Fl H
3037nor 3037nor
3038.Fl S 3038.Fl S
3039is specified, the soft limit is displayed or both limits are set. 3039is specified, the soft limit is displayed or both limits are set.
3040If both are specified, the last one wins. 3040If both are specified, the last one wins.
3041.El 3041.El
3042.Pp 3042.Pp
3043The limit to be interrogated or set, then, is chosen by specifying 3043The limit to be interrogated or set, then, is chosen by specifying
3044any one of these flags: 3044any one of these flags:
3045.Bl -tag -width Fl 3045.Bl -tag -width Fl
3046.It Fl a 3046.It Fl a
3047show all the current limits 3047show all the current limits
3048.It Fl b 3048.It Fl b
3049show or set the limit on the socket buffer size of a process (in bytes) 3049show or set the limit on the socket buffer size of a process (in bytes)
3050.It Fl c 3050.It Fl c
3051show or set the limit on the largest core dump size that can be produced 3051show or set the limit on the largest core dump size that can be produced
3052(in 512-byte blocks) 3052(in 512-byte blocks)
3053.It Fl d 3053.It Fl d
3054show or set the limit on the data segment size of a process (in kilobytes) 3054show or set the limit on the data segment size of a process (in kilobytes)
3055.It Fl f 3055.It Fl f
3056show or set the limit on the largest file that can be created 3056show or set the limit on the largest file that can be created
3057(in 512-byte blocks) 3057(in 512-byte blocks)
3058.It Fl l 3058.It Fl l
3059show or set the limit on how much memory a process can lock with 3059show or set the limit on how much memory a process can lock with
3060.Xr mlock 2 3060.Xr mlock 2
3061(in kilobytes) 3061(in kilobytes)
3062.It Fl m 3062.It Fl m
3063show or set the limit on the total physical memory that can be 3063show or set the limit on the total physical memory that can be
3064in use by a process (in kilobytes) 3064in use by a process (in kilobytes)
3065.It Fl n 3065.It Fl n
3066show or set the limit on the number of files a process can have open at once 3066show or set the limit on the number of files a process can have open at once
3067.It Fl p 3067.It Fl p
3068show or set the limit on the number of processes this user can 3068show or set the limit on the number of processes this user can
3069have at one time 3069have at one time
3070.It Fl r 3070.It Fl r
3071show or set the limit on the number of threads this user can 3071show or set the limit on the number of threads this user can
3072have at one time 3072have at one time
3073.It Fl s 3073.It Fl s
3074show or set the limit on the stack size of a process (in kilobytes) 3074show or set the limit on the stack size of a process (in kilobytes)
3075.It Fl t 3075.It Fl t
3076show or set the limit on CPU time (in seconds) 3076show or set the limit on CPU time (in seconds)
3077.It Fl v 3077.It Fl v
3078show or set the limit on how large a process address space can be 3078show or set the limit on how large a process address space can be
3079.El 3079.El
3080.Pp 3080.Pp
3081If none of these is specified, it is the limit on file size that is shown 3081If none of these is specified, it is the limit on file size that is shown
3082or set. 3082or set.
3083If value is specified, the limit is set to that number; otherwise 3083If value is specified, the limit is set to that number; otherwise
3084the current limit is displayed. 3084the current limit is displayed.
3085.Pp 3085.Pp
3086Limits of an arbitrary process can be displayed or set using the 3086Limits of an arbitrary process can be displayed or set using the
3087.Xr sysctl 8 3087.Xr sysctl 8
3088utility. 3088utility.
3089.It umask Oo Fl S Oc Op Ar mask 3089.It umask Oo Fl S Oc Op Ar mask
3090Set the value of umask (see 3090Set the value of umask (see
3091.Xr umask 2 ) 3091.Xr umask 2 )
3092to the specified octal value. 3092to the specified octal value.
3093If the argument is omitted, the umask value is printed. 3093If the argument is omitted, the umask value is printed.
3094With 3094With
3095.Fl S 3095.Fl S
3096a symbolic form is used instead of an octal number. 3096a symbolic form is used instead of an octal number.
3097.It unalias Oo Fl a Oc Oo Ar name Oc 3097.It unalias Oo Fl a Oc Oo Ar name Oc
3098If 3098If
3099.Ar name 3099.Ar name
3100is specified, the shell removes that alias. 3100is specified, the shell removes that alias.
3101If 3101If
3102.Fl a 3102.Fl a
3103is specified, all aliases are removed. 3103is specified, all aliases are removed.
3104.It unset Oo Fl efvx Oc Ar name ... 3104.It unset Oo Fl efvx Oc Ar name ...
3105If 3105If
3106.Fl v 3106.Fl v
3107is specified, the specified variables are unset and unexported. 3107is specified, the specified variables are unset and unexported.
3108Readonly variables cannot be unset. 3108Readonly variables cannot be unset.
3109If 3109If
3110.Fl f 3110.Fl f
3111is specified, the specified functions are undefined. 3111is specified, the specified functions are undefined.
3112If 3112If
3113.Fl e 3113.Fl e
3114is given, the specified variables are unexported, but otherwise unchanged, 3114is given, the specified variables are unexported, but otherwise unchanged,
3115alternatively, if 3115alternatively, if
3116.Fl x 3116.Fl x
3117is given, the exported status of the variable will be retained, 3117is given, the exported status of the variable will be retained,
3118even after it is unset. 3118even after it is unset.
3119.Pp 3119.Pp
3120If no flags are provided 3120If no flags are provided
3121.Fl v 3121.Fl v
3122is assumed. 3122is assumed.
3123If 3123If
3124.Fl f 3124.Fl f
3125is given with one of the other flags, 3125is given with one of the other flags,
3126then the named variables will be unset, or unexported, and functions 3126then the named variables will be unset, or unexported, and functions
3127of the same names will be undefined. 3127of the same names will be undefined.
3128The 3128The
3129.Fl e 3129.Fl e
3130and 3130and
3131.Fl x 3131.Fl x
3132flags both imply 3132flags both imply
3133.Fl v . 3133.Fl v .
3134If 3134If
3135.Fl e 3135.Fl e
3136is given, the 3136is given, the
3137.Fl x 3137.Fl x
3138flag is ignored. 3138flag is ignored.
3139.Pp 3139.Pp
3140The exit status is 0, unless an attempt was made to unset 3140The exit status is 0, unless an attempt was made to unset
3141a readonly variable, in which case the exit status is 1. 3141a readonly variable, in which case the exit status is 1.
3142It is not an error to unset (or undefine) a variable (or function) 3142It is not an error to unset (or undefine) a variable (or function)
3143that is not currently set (or defined.) 3143that is not currently set (or defined.)
3144.It wait Oo Fl n Oc Oo Fl p Ar var Oc Op Ar job ... 3144.It wait Oo Fl n Oc Oo Fl p Ar var Oc Op Ar job ...
3145Wait for the specified jobs to complete 3145Wait for the specified jobs to complete
3146and return the exit status of the last job in the parameter list, 3146and return the exit status of the last job in the parameter list,
3147or 127 if that job is not a current child of the shell. 3147or 127 if that job is not a current child of the shell.
3148.Pp 3148.Pp
3149If no 3149If no
3150.Ar job 3150.Ar job
3151arguments are given, wait for all jobs to 3151arguments are given, wait for all jobs to
3152complete and then return an exit status of zero 3152complete and then return an exit status of zero
3153(including when there were no jobs, and so nothing exited.) 3153(including when there were no jobs, and so nothing exited.)
3154.Pp 3154.Pp
3155With the 3155With the
3156.Fl n 3156.Fl n
3157option, wait instead for any one of the given 3157option, wait instead for any one of the given
3158.Ar job Ns s, 3158.Ar job Ns s,
3159or if none are given, any job, to complete, and 3159or if none are given, any job, to complete, and
3160return the exit status of that job. 3160return the exit status of that job.
3161If none of the given 3161If none of the given
3162.Ar job 3162.Ar job
3163arguments is a current child of the shell, 3163arguments is a current child of the shell,
3164or if no 3164or if no
3165.Ar job 3165.Ar job
3166arguments are given and the shell has no unwaited for children, 3166arguments are given and the shell has no unwaited for children,
3167then the exit status will be 127. 3167then the exit status will be 127.
3168.Pp 3168.Pp
3169The 3169The
3170.Fl p Ar var 3170.Fl p Ar var
3171option allows the process (or job) identifier of the 3171option allows the process (or job) identifier of the
3172job for which the exit status is returned to be obtained. 3172job for which the exit status is returned to be obtained.
3173The variable named (which must not be readonly) will be 3173The variable named (which must not be readonly) will be
3174unset initially, then if a job has exited and its status is 3174unset initially, then if a job has exited and its status is
3175being returned, set to the identifier from the 3175being returned, set to the identifier from the
3176arg list (if given) of that job, 3176arg list (if given) of that job,
3177or the lead process identifier of the job to exit when used with 3177or the lead process identifier of the job to exit when used with
3178.Fl n 3178.Fl n
3179and no job arguments. 3179and no job arguments.
3180Note that 3180Note that
3181.Fl p 3181.Fl p
3182with neither 3182with neither
3183.Fl n 3183.Fl n
3184nor 3184nor
3185.Ar job 3185.Ar job
3186arguments is useless, as in that case no job status is 3186arguments is useless, as in that case no job status is
3187returned, the variable named is simply unset. 3187returned, the variable named is simply unset.
3188.Pp 3188.Pp
3189If the wait is interrupted by a signal, 3189If the wait is interrupted by a signal,
3190its exit status will be greater than 128, 3190its exit status will be greater than 128,
3191and 3191and
3192.Ar var , 3192.Ar var ,
3193if given, will remain unset. 3193if given, will remain unset.
3194.Pp 3194.Pp
3195Once waited upon, by specific process number or job-id, 3195Once waited upon, by specific process number or job-id,
3196or by a 3196or by a
3197.Ic wait 3197.Ic wait
3198with no arguments, 3198with no arguments,
3199knowledge of the child is removed from the system, 3199knowledge of the child is removed from the system,
3200and it cannot be waited upon again. 3200and it cannot be waited upon again.
3201.Pp 3201.Pp
3202Note than when a list of jobs are given, more that 3202Note than when a list of jobs are given, more that
3203one argument might refer to the same job. 3203one argument might refer to the same job.
3204In that case, if the final argument represents a job 3204In that case, if the final argument represents a job
3205that is also given earlier in the list, it is not 3205that is also given earlier in the list, it is not
3206defined whether the status returned will be the 3206defined whether the status returned will be the
3207exit status of the job, or 127 indicating that 3207exit status of the job, or 127 indicating that
3208the child no longer existed when the wait command 3208the child no longer existed when the wait command
3209reached the later argument in the list. 3209reached the later argument in the list.
3210In this 3210In this
3211.Nm 3211.Nm
3212the exit status will be that from the job. 3212the exit status will be that from the job.
3213.Nm 3213.Nm
3214waits for each job exactly once, regardless of 3214waits for each job exactly once, regardless of
3215how many times (or how many different ways) it 3215how many times (or how many different ways) it
3216is listed in the arguments to 3216is listed in the arguments to
3217.Ic wait . 3217.Ic wait .
3218That is 3218That is
3219.Bd -literal -compact 3219.Bd -literal -compact
3220 wait 100 100 100 3220 wait 100 100 100
3221.Ed 3221.Ed
3222is identical to 3222is identical to
3223.Bd -literal -compact 3223.Bd -literal -compact
3224 wait 100 3224 wait 100
3225.Ed 3225.Ed
3226.El 3226.El
3227.Ss Job Control 3227.Ss Job Control
3228Each process (or set of processes) started by 3228Each process (or set of processes) started by
3229.Nm 3229.Nm
3230is created as a 3230is created as a
3231.Dq job 3231.Dq job
3232and added to the jobs table. 3232and added to the jobs table.
3233When enabled by the 3233When enabled by the
3234.Fl m 3234.Fl m
3235option 3235option
3236.Pq aka Fl o Ar monitor 3236.Pq aka Fl o Ar monitor
3237when the job is created, 3237when the job is created,
3238.Nm 3238.Nm
3239places each job (if run from the top level shell) 3239places each job (if run from the top level shell)
3240into a process group of its own, which allows control 3240into a process group of its own, which allows control
3241of the process(es), and its/their descendants, as a unit. 3241of the process(es), and its/their descendants, as a unit.
3242When the 3242When the
3243.Fl m 3243.Fl m
3244option is off, or when started from a sub-shell environment, 3244option is off, or when started from a sub-shell environment,
3245jobs share the same process group as the parent shell. 3245jobs share the same process group as the parent shell.
3246The 3246The
3247.Fl m 3247.Fl m
3248option is enabled by default in interactive shells with 3248option is enabled by default in interactive shells with
3249a terminal as standard input and standard error. 3249a terminal as standard input and standard error.
3250.Pp 3250.Pp
3251Jobs with separate process groups may be stopped, and then later 3251Jobs with separate process groups may be stopped, and then later
3252resumed in the foreground (with access to the terminal) 3252resumed in the foreground (with access to the terminal)
3253or in the background (where attempting to read from the 3253or in the background (where attempting to read from the
3254terminal will result in the job stopping.) 3254terminal will result in the job stopping.)
3255A list of current jobs can be obtained using the 3255A list of current jobs can be obtained using the
3256.Ic jobs 3256.Ic jobs
3257built-in command. 3257built-in command.
3258Jobs are identified using either the process identifier 3258Jobs are identified using either the process identifier
3259of the lead process of the job (the value available in 3259of the lead process of the job (the value available in
3260the special parameter 3260the special parameter
3261.Sq \&$! 3261.Sq \&$!
3262if the job is started in the background), or using percent 3262if the job is started in the background), or using percent
3263notation. 3263notation.
3264Each job is given a 3264Each job is given a
3265.Dq job number 3265.Dq job number
3266which is a small integer, starting from 1, and can be 3266which is a small integer, starting from 1, and can be
3267referenced as 3267referenced as
3268.Sq \&%n 3268.Sq \&%n
3269where n is that number. 3269where n is that number.
3270Note that this applies to jobs both with and without their own process groups. 3270Note that this applies to jobs both with and without their own process groups.
3271Job numbers are shown in the output from the 3271Job numbers are shown in the output from the
3272.Ic jobs 3272.Ic jobs
3273command enclosed in brackets 3273command enclosed in brackets
3274.Po 3274.Po
3275.Sq \&[ 3275.Sq \&[
3276and 3276and
3277.Sq \&] 3277.Sq \&]
3278.Pc . 3278.Pc .
3279Whenever the job table becomes empty, the numbers begin at one again. 3279Whenever the job table becomes empty, the numbers begin at one again.
3280In addition, there is the concept of a current, and a previous job, 3280In addition, there is the concept of a current, and a previous job,
3281identified by 3281identified by
3282.Sq \&%+ 3282.Sq \&%+
3283.Po 3283.Po
3284or 3284or
3285.Sq \&%% 3285.Sq \&%%
3286or even just 3286or even just
3287.Sq \&% 3287.Sq \&%
3288.Pc , 3288.Pc ,
3289and a previous job, identified by 3289and a previous job, identified by
3290.Sq \&%\- . 3290.Sq \&%\- .
3291Whenever a background job is started, 3291Whenever a background job is started,
3292or a job is resumed in the background, 3292or a job is resumed in the background,
3293it becomes the current job. 3293it becomes the current job.
3294The job that was the current job 3294The job that was the current job
3295(prepare for a big surprise here, drum roll..., wait for it...\&) 3295(prepare for a big surprise here, drum roll..., wait for it...\&)
3296becomes the previous job. 3296becomes the previous job.
3297When the current job terminates, the previous job is 3297When the current job terminates, the previous job is
3298promoted to be the current job. 3298promoted to be the current job.
3299In addition the form 3299In addition the form
3300.Dq %string 3300.Dq %string
3301finds the job for which the command starts with 3301finds the job for which the command starts with
3302.Dq string 3302.Dq string
3303and the form 3303and the form
3304.Dq %?string 3304.Dq %?string
3305finds the job which contains the 3305finds the job which contains the
3306.Dq string 3306.Dq string
3307in its command somewhere. 3307in its command somewhere.
3308Both forms require the result to be unambiguous. 3308Both forms require the result to be unambiguous.
3309For this purpose the 3309For this purpose the
3310.Dq command 3310.Dq command
3311is that shown in the output from the 3311is that shown in the output from the
3312.Ic jobs 3312.Ic jobs
3313command, not the original command line. 3313command, not the original command line.
3314.Pp 3314.Pp
3315The 3315The
3316.Ic bg , 3316.Ic bg ,
3317.Ic fg , 3317.Ic fg ,
3318.Ic jobid , 3318.Ic jobid ,
3319.Ic jobs , 3319.Ic jobs ,
3320.Ic kill , 3320.Ic kill ,
3321and 3321and
3322.Ic wait 3322.Ic wait
3323commands all accept job identifiers as arguments, in addition to 3323commands all accept job identifiers as arguments, in addition to
3324process identifiers (larger integers). 3324process identifiers (larger integers).
3325See the 3325See the
3326.Sx Built-ins 3326.Sx Built-ins
3327section above, and 3327section above, and
3328.Xr kill 1 , 3328.Xr kill 1 ,
3329for more details of those commands. 3329for more details of those commands.
3330In addition, a job identifier 3330In addition, a job identifier
3331.Pq using one of the Sq \&% forms 3331.Pq using one of the Sq \&% forms
3332issued as a command, without arguments, is interpreted as 3332issued as a command, without arguments, is interpreted as
3333if it had been given as the argument to the 3333if it had been given as the argument to the
3334.Ic fg 3334.Ic fg
3335command. 3335command.
3336.Pp 3336.Pp
3337To cause a foreground process to stop, enter the terminal's 3337To cause a foreground process to stop, enter the terminal's
3338.Ic stop 3338.Ic stop
3339character (usually control-Z). 3339character (usually control-Z).
3340To cause a background process to stop, send it a 3340To cause a background process to stop, send it a
3341.Dv STOP 3341.Dv STOP
3342signal, using the kill command. 3342signal, using the kill command.
3343A useful function to define is 3343A useful function to define is
3344.Bd -literal -compact 3344.Bd -literal -compact
3345 stop() { kill -s STOP "${@:-%%}"; } 3345 stop() { kill -s STOP "${@:-%%}"; }
3346.Ed 3346.Ed
3347.Pp 3347.Pp
3348The 3348The
3349.Ic fg 3349.Ic fg
3350command resumes a stopped job, placing it in the foreground, 3350command resumes a stopped job, placing it in the foreground,
3351and 3351and
3352.Ic bg 3352.Ic bg
3353resumes a stopped job in the background. 3353resumes a stopped job in the background.
3354The 3354The
3355.Ic jobid 3355.Ic jobid
3356command provides information about process identifiers, job identifiers, 3356command provides information about process identifiers, job identifiers,
3357and the process group identifier, for a job. 3357and the process group identifier, for a job.
3358.Pp 3358.Pp
3359Whenever a sub-shell is created, the jobs table becomes invalid 3359Whenever a sub-shell is created, the jobs table becomes invalid
3360(the sub-shell has no children.) 3360(the sub-shell has no children.)
3361However, to enable uses like 3361However, to enable uses like
3362.Bd -literal -compact 3362.Bd -literal -compact
3363 PID=$(jobid -p %1) 3363 PID=$(jobid -p %1)
3364.Ed 3364.Ed
3365the table is only actually cleared in a sub-shell when needed to 3365the table is only actually cleared in a sub-shell when needed to
3366create the first job there (built-in commands run in the foreground 3366create the first job there (built-in commands run in the foreground
3367do not create jobs.) 3367do not create jobs.)
3368Note that in this environment, there is no useful current job 3368Note that in this environment, there is no useful current job
3369(%% actually refers to the sub-shell itself, but is not accessible) 3369(%% actually refers to the sub-shell itself, but is not accessible)
3370but the job which is the current job in the parent can be accessed as %\-. 3370but the job which is the current job in the parent can be accessed as %\-.
3371.Ss Command Line Editing 3371.Ss Command Line Editing
3372When 3372When
3373.Nm 3373.Nm
3374is being used interactively from a terminal, the current command 3374is being used interactively from a terminal, the current command
3375and the command history (see 3375and the command history (see
3376.Ic fc 3376.Ic fc
3377in the 3377in the
3378.Sx Built-ins 3378.Sx Built-ins
3379section) 3379section)
3380can be edited using emacs-mode or vi-mode command-line editing. 3380can be edited using emacs-mode or vi-mode command-line editing.
3381The command 3381The command
3382.Ql set -o emacs 3382.Ql set -o emacs
3383enables emacs-mode editing. 3383enables emacs-mode editing.
3384The command 3384The command
3385.Ql set -o vi 3385.Ql set -o vi
3386enables vi-mode editing and places the current shell process into 3386enables vi-mode editing and places the current shell process into
3387.Ar vi 3387.Ar vi
3388insert mode. 3388insert mode.
3389(See the 3389(See the
3390.Sx Argument List Processing 3390.Sx Argument List Processing
3391section above.) 3391section above.)
3392.Pp 3392.Pp
3393The 3393The
3394.Ar vi 3394.Ar vi
3395mode uses commands similar to a subset of those described in the 3395mode uses commands similar to a subset of those described in the
3396.Xr vi 1 3396.Xr vi 1
3397man page. 3397man page.
3398With vi-mode 3398With vi-mode
3399enabled, 3399enabled,
3400.Nm sh 3400.Nm sh
3401can be switched between insert mode and command mode. 3401can be switched between insert mode and command mode.
3402It's similar to 3402It's similar to
3403.Xr vi 1 : 3403.Xr vi 1 :
3404pressing the 3404pressing the
3405.Aq ESC 3405.Aq ESC
3406key will throw you into command VI command mode. 3406key will throw you into command VI command mode.
3407Pressing the 3407Pressing the
3408.Aq return 3408.Aq return
3409key while in command mode will pass the line to the shell. 3409key while in command mode will pass the line to the shell.
3410.Pp 3410.Pp
3411The 3411The
3412.Ar emacs 3412.Ar emacs
3413mode uses commands similar to a subset available in the 3413mode uses commands similar to a subset available in the
3414.Ic emacs 3414.Ic emacs
3415editor. 3415editor.
3416With emacs-mode enabled, special keys can be used to modify the text 3416With emacs-mode enabled, special keys can be used to modify the text
3417in the buffer using the control key. 3417in the buffer using the control key.
3418.Pp 3418.Pp
3419.Nm 3419.Nm
3420uses the 3420uses the
3421.Xr editline 3 3421.Xr editline 3
3422library. 3422library.
3423See 3423See
3424.Xr editline 7 3424.Xr editline 7
3425for a list of the possible command bindings, 3425for a list of the possible command bindings,
3426and the default settings in 3426and the default settings in
3427.Ar emacs 3427.Ar emacs
3428and 3428and
3429.Ar vi 3429.Ar vi
3430modes. 3430modes.
3431Also see 3431Also see
3432.Xr editrc 5 3432.Xr editrc 5
3433for the commands that can be given to configure 3433for the commands that can be given to configure
3434.Xr editline 7 3434.Xr editline 7
3435in the file named by the 3435in the file named by the
3436.Ev EDITRC 3436.Ev EDITRC
3437parameter, 3437parameter,
3438or a file used with the 3438or a file used with the
3439.Ic inputrc 3439.Ic inputrc
3440built-in command, 3440built-in command,
3441or using 3441or using
3442.Xr editline 7 Ap s 3442.Xr editline 7 Ap s
3443configuration command line. 3443configuration command line.
3444.Pp 3444.Pp
3445When command line editing is enabled, the 3445When command line editing is enabled, the
3446.Xr editline 7 3446.Xr editline 7
3447functions control printing of the 3447functions control printing of the
3448.Ev PS1 3448.Ev PS1
3449and 3449and
3450.Ev PS2 3450.Ev PS2
3451prompts when required. 3451prompts when required.
3452As, in this mode, the command line editor needs to 3452As, in this mode, the command line editor needs to
3453keep track of what characters are in what position on 3453keep track of what characters are in what position on
3454the command line, care needs to be taken when setting 3454the command line, care needs to be taken when setting
3455the prompts. 3455the prompts.
3456Normal printing characters are handled automatically, 3456Normal printing characters are handled automatically,
3457however mode setting sequences, which do not actually display 3457however mode setting sequences, which do not actually display
3458on the terminal, need to be identified to 3458on the terminal, need to be identified to
3459.Xr editline 7 . 3459.Xr editline 7 .
3460This is done, when needed, by choosing a character that 3460This is done, when needed, by choosing a character that
3461is not needed anywhere in the prompt, including in the mode 3461is not needed anywhere in the prompt, including in the mode
3462setting sequences, any single character is acceptable, 3462setting sequences, any single character is acceptable,
3463and assigning it to the shell parameter 3463and assigning it to the shell parameter
3464.Ev PSlit . 3464.Ev PSlit .
3465Then that character should be used, in pairs, in the 3465Then that character should be used, in pairs, in the
3466prompt string. 3466prompt string.
3467Between each pair of 3467Between each pair of
3468.Ev PSlit 3468.Ev PSlit
3469characters are mode setting sequences, which affect the printing 3469characters are mode setting sequences, which affect the printing
3470attributes of the following (normal) characters of the prompt, 3470attributes of the following (normal) characters of the prompt,
3471but do not themselves appear visibly, nor change the terminal's 3471but do not themselves appear visibly, nor change the terminal's
3472cursor position. 3472cursor position.
3473.Pp 3473.Pp
3474Each such sequence, that is 3474Each such sequence, that is
3475.Ev PSlit 3475.Ev PSlit
3476character, mode setting character sequence, and another 3476character, mode setting character sequence, and another
3477.Ev PSlit 3477.Ev PSlit
3478character, must currently be followed by at least one following 3478character, must currently be followed by at least one following
3479normal prompt character, or it will be ignored. 3479normal prompt character, or it will be ignored.
3480That is, a 3480That is, a
3481.Ev PSlit 3481.Ev PSlit
3482character cannot be the final character of 3482character cannot be the final character of
3483.Ev PS1 3483.Ev PS1
3484or 3484or
3485.Ev PS2 , 3485.Ev PS2 ,
3486nor may two 3486nor may two
3487.Ev PSlit 3487.Ev PSlit
3488delimited sequences appear adjacent to each other. 3488delimited sequences appear adjacent to each other.
3489Each sequence can contain as many mode altering sequences as are 3489Each sequence can contain as many mode altering sequences as are
3490required however. 3490required however.
3491Only the first character from 3491Only the first character from
3492.Ev PSlit 3492.Ev PSlit
3493will be used. 3493will be used.
3494When set 3494When set
3495.Ev PSlit 3495.Ev PSlit
3496should usually be set to a string containing just one 3496should usually be set to a string containing just one
3497character, then it can simply be embedded in 3497character, then it can simply be embedded in
3498.Ev PS1 3498.Ev PS1
3499(or 3499(or
3500.Ev PS2 ) 3500.Ev PS2 )
3501as in 3501as in
3502.Dl PS1="${PSlit}mset${PSlit}XYZ${PSlit}mclr${PSlit}ABC" 3502.Dl PS1="${PSlit}mset${PSlit}XYZ${PSlit}mclr${PSlit}ABC"
3503The prompt visible will be 3503The prompt visible will be
3504.Dq XYZABC 3504.Dq XYZABC
3505with the 3505with the
3506.Dq XYZ 3506.Dq XYZ
3507part shown according as defined by the mode setting characters 3507part shown according as defined by the mode setting characters
3508.Dq mset , 3508.Dq mset ,
3509and then cleared again by 3509and then cleared again by
3510.Dq mclr . 3510.Dq mclr .
3511See 3511See
3512.Xr tput 1 3512.Xr tput 1
3513for one method to generate appropriate mode sequences. 3513for one method to generate appropriate mode sequences.
3514Note that both parts, XYZ and ABC, must each contain at least one 3514Note that both parts, XYZ and ABC, must each contain at least one
3515character. 3515character.
3516.Pp 3516.Pp
3517If 3517If
3518.Ev PSlit 3518.Ev PSlit
3519is unset, which is its initial state, or set to a null string, 3519is unset, which is its initial state, or set to a null string,
3520no literal character will be defined, 3520no literal character will be defined,
3521and all characters of the prompt strings will be assumed 3521and all characters of the prompt strings will be assumed
3522to be visible characters (which includes spaces etc.) 3522to be visible characters (which includes spaces etc.)
3523To allow smooth use of prompts, without needing redefinition, when 3523To allow smooth use of prompts, without needing redefinition, when
3524.Xr editline 7 3524.Xr editline 7
3525is disabled, the character chosen should be one which will be 3525is disabled, the character chosen should be one which will be
3526ignored by the terminal if received, as when 3526ignored by the terminal if received, as when
3527.Xr editline 7 3527.Xr editline 7
3528is not in use, the prompt strings are simply written to the terminal. 3528is not in use, the prompt strings are simply written to the terminal.
3529For example, setting: 3529For example, setting:
3530.Bd -compact -literal -offset left 3530.Bd -literal -offset left -compact
3531 PSlit="$(printf\ '\e1')" 3531 PSlit="$(printf\ '\e1')"
3532 PS1="${PSlit}$(tput\ bold\ blink)${PSlit}\e$${PSlit}$(tput\ sgr0)${PSlit}\ " 3532 PS1="${PSlit}$(tput\ bold\ blink)${PSlit}\e$${PSlit}$(tput\ sgr0)${PSlit}\ "
3533.Ed 3533.Ed
3534will arrange for the primary prompt to be a bold blinking dollar sign, 3534will arrange for the primary prompt to be a bold blinking dollar sign,
3535if supported by the current terminal, followed by an (ordinary) space, 3535if supported by the current terminal, followed by an (ordinary) space,
3536and, as the SOH (Control-A) character ('\e1') will not normally affect 3536and, as the SOH (Control-A) character ('\e1') will not normally affect
3537a terminal, this same prompt will usually work with 3537a terminal, this same prompt will usually work with
3538.Xr editline 7 3538.Xr editline 7
3539enabled or disabled. 3539enabled or disabled.
3540.Sh ENVIRONMENT 3540.Sh ENVIRONMENT
3541.Bl -tag -width MAILCHECK 3541.Bl -tag -width MAILCHECK
3542.It Ev CDPATH 3542.It Ev CDPATH
3543The search path used with the 3543The search path used with the
3544.Ic cd 3544.Ic cd
3545built-in. 3545built-in.
3546.It Ev EDITRC 3546.It Ev EDITRC
3547Gives the name of the file containing commands for 3547Gives the name of the file containing commands for
3548.Xr editline 7 . 3548.Xr editline 7 .
3549See 3549See
3550.Xr editrc 5 3550.Xr editrc 5
3551for possible content and format. 3551for possible content and format.
3552The file is processed, when in interactive mode with 3552The file is processed, when in interactive mode with
3553command line editing enabled, whenever 3553command line editing enabled, whenever
3554.Ev EDITRC 3554.Ev EDITRC
3555is set (even with no actual value change,) 3555is set (even with no actual value change,)
3556and if command line editing changes from disabled to enabled, 3556and if command line editing changes from disabled to enabled,
3557or the editor style used is changed. 3557or the editor style used is changed.
3558(See the 3558(See the
3559.Fl E 3559.Fl E
3560and 3560and
3561.Fl V 3561.Fl V
3562options of the 3562options of the
3563.Ic set 3563.Ic set
3564built-in command, described in 3564built-in command, described in
3565.Sx Built-ins 3565.Sx Built-ins
3566above, which are documented further above in 3566above, which are documented further above in
3567.Sx Argument List Processing . ) 3567.Sx Argument List Processing . )
3568If unset 3568If unset
3569.Dq $HOME/.editrc 3569.Dq $HOME/.editrc
3570is used. 3570is used.
3571.It Ev HISTSIZE 3571.It Ev HISTSIZE
3572The number of lines in the history buffer for the shell. 3572The number of lines in the history buffer for the shell.
3573.It Ev HOME 3573.It Ev HOME
3574Set automatically by 3574Set automatically by
3575.Xr login 1 3575.Xr login 1
3576from the user's login directory in the password file 3576from the user's login directory in the password file
3577.Pq Xr passwd 5 . 3577.Pq Xr passwd 5 .
3578This environment variable also functions as the default argument for the 3578This environment variable also functions as the default argument for the
3579.Ic cd 3579.Ic cd
3580built-in. 3580built-in.
3581.It Ev HOSTNAME 3581.It Ev HOSTNAME
3582Set to the current hostname of the system, as returned by 3582Set to the current hostname of the system, as returned by
3583.Xr gethostname 3 . 3583.Xr gethostname 3 .
3584This is obtained each time 3584This is obtained each time
3585.Ev HOSTNAME 3585.Ev HOSTNAME
3586is expanded, so changes to the system's name are reflected 3586is expanded, so changes to the system's name are reflected
3587without further action. 3587without further action.
3588If unset, it returns nothing. 3588If unset, it returns nothing.
3589Setting it does nothing except reverse the effect of an earlier 3589Setting it does nothing except reverse the effect of an earlier
3590.Ic unset . 3590.Ic unset .
3591.It Ev IFS 3591.It Ev IFS
3592Input Field Separators. 3592Input Field Separators.
3593This is normally set to 3593This is normally set to
3594.Aq space , 3594.Aq space ,
3595.Aq tab , 3595.Aq tab ,
3596and 3596and
3597.Aq newline . 3597.Aq newline .
3598See the 3598See the
3599.Sx White Space Splitting 3599.Sx White Space Splitting
3600section for more details. 3600section for more details.
3601.It Ev LANG 3601.It Ev LANG
3602The string used to specify localization information that allows users 3602The string used to specify localization information that allows users
3603to work with different culture-specific and language conventions. 3603to work with different culture-specific and language conventions.
3604See 3604See
3605.Xr nls 7 . 3605.Xr nls 7 .
3606.It Ev LINENO 3606.It Ev LINENO
3607The current line number in the script or function. 3607The current line number in the script or function.
3608See the section 3608See the section
3609.Sx LINENO 3609.Sx LINENO
3610below for more details. 3610below for more details.
3611.It Ev MAIL 3611.It Ev MAIL
3612The name of a mail file, that will be checked for the arrival of new mail. 3612The name of a mail file, that will be checked for the arrival of new mail.
3613Overridden by 3613Overridden by
3614.Ev MAILPATH . 3614.Ev MAILPATH .
3615The check occurs just before 3615The check occurs just before
3616.Ev PS1 3616.Ev PS1
3617is written, immediately after reporting jobs which have changed status, 3617is written, immediately after reporting jobs which have changed status,
3618in interactive shells only. 3618in interactive shells only.
3619New mail is considered to have arrived if the monitored file 3619New mail is considered to have arrived if the monitored file
3620has increased in size since the last check. 3620has increased in size since the last check.
3621.\" .It Ev MAILCHECK 3621.\" .It Ev MAILCHECK
3622.\" The frequency in seconds that the shell checks for the arrival of mail 3622.\" The frequency in seconds that the shell checks for the arrival of mail
3623.\" in the files specified by the 3623.\" in the files specified by the
3624.\" .Ev MAILPATH 3624.\" .Ev MAILPATH
3625.\" or the 3625.\" or the
3626.\" .Ev MAIL 3626.\" .Ev MAIL
3627.\" file. 3627.\" file.
3628.\" If set to 0, the check will occur at each prompt. 3628.\" If set to 0, the check will occur at each prompt.
3629.It Ev MAILPATH 3629.It Ev MAILPATH
3630A colon 3630A colon
3631.Dq \&: 3631.Dq \&:
3632separated list of file names, for the shell to check for incoming mail. 3632separated list of file names, for the shell to check for incoming mail.
3633This environment setting overrides the 3633This environment setting overrides the
3634.Ev MAIL 3634.Ev MAIL
3635setting. 3635setting.
3636There is a maximum of 10 mailboxes that can be monitored at once. 3636There is a maximum of 10 mailboxes that can be monitored at once.
3637.It Ev PATH 3637.It Ev PATH
3638The default search path for executables. 3638The default search path for executables.
3639See the 3639See the
3640.Sx Path Search 3640.Sx Path Search
3641section above. 3641section above.
3642.It Ev PPID 3642.It Ev PPID
3643The process identified of the parent process of the 3643The process identified of the parent process of the
3644current shell. 3644current shell.
3645This value is set at shell startup, ignoring 3645This value is set at shell startup, ignoring
3646any value in the environment, and then made readonly. 3646any value in the environment, and then made readonly.
3647.It Ev PS1 3647.It Ev PS1
3648The primary prompt string, which defaults to 3648The primary prompt string, which defaults to
3649.Dq $ \ , 3649.Dq $ \ ,
3650unless you are the superuser, in which case it defaults to 3650unless you are the superuser, in which case it defaults to
3651.Dq # \ . 3651.Dq # \ .
3652This string is subject to parameter, arithmetic, and if 3652This string is subject to parameter, arithmetic, and if
3653enabled by setting the 3653enabled by setting the
3654.Ic promptcmds 3654.Ic promptcmds
3655option, command substitution before being output. 3655option, command substitution before being output.
3656During execution of commands used by command substitution, 3656During execution of commands used by command substitution,
3657execution tracing, the 3657execution tracing, the
3658.Ic xtrace 3658.Ic xtrace
3659.Ic ( set Fl x ) 3659.Ic ( set Fl x )
3660option is temporarily disabled. 3660option is temporarily disabled.
3661If 3661If
3662.Ic promptcmds 3662.Ic promptcmds
3663is not set and the prompt string uses command substitution, 3663is not set and the prompt string uses command substitution,
3664the prompt used will be an appropriate error string. 3664the prompt used will be an appropriate error string.
3665For other expansion errors, a message will be output, 3665For other expansion errors, a message will be output,
3666and the unexpanded string will then be used as the prompt. 3666and the unexpanded string will then be used as the prompt.
3667.It Ev PS2 3667.It Ev PS2
3668The secondary prompt string, which defaults to 3668The secondary prompt string, which defaults to
3669.Dq > \ . 3669.Dq > \ .
3670After expansion (as for 3670After expansion (as for
3671.Ev PS1 ) 3671.Ev PS1 )
3672it is written whenever more input is required to complete the 3672it is written whenever more input is required to complete the
3673current command. 3673current command.
3674.It Ev PS4 3674.It Ev PS4
3675Output, after expansion like 3675Output, after expansion like
3676.Ev PS1 , 3676.Ev PS1 ,
3677before each line when execution trace 3677before each line when execution trace
3678.Ic ( set Fl x ) 3678.Ic ( set Fl x )
3679is enabled. 3679is enabled.
3680.Ev PS4 3680.Ev PS4
3681defaults to 3681defaults to
3682.Dq + \ . 3682.Dq + \ .
3683.It Ev PSc 3683.It Ev PSc
3684Initialized by the shell, ignoring any value from the environment, 3684Initialized by the shell, ignoring any value from the environment,
3685to a single character string, either 3685to a single character string, either
3686.Sq \&# 3686.Sq \&#
3687or 3687or
3688.Sq \&$ , 3688.Sq \&$ ,
3689depending upon whether the current user is the superuser or not. 3689depending upon whether the current user is the superuser or not.
3690This is intended for use when building a custom 3690This is intended for use when building a custom
3691.Ev PS1 . 3691.Ev PS1 .
3692.It Ev PSlit 3692.It Ev PSlit
3693Defines the character which may be embedded in pairs, in 3693Defines the character which may be embedded in pairs, in
3694.Ev PS1 3694.Ev PS1
3695or 3695or
3696.Ev PS2 3696.Ev PS2
3697to indicate to 3697to indicate to
3698.Xr editline 7 3698.Xr editline 7
3699that the characters between each pair of occurrences of the 3699that the characters between each pair of occurrences of the
3700.Ev PSlit 3700.Ev PSlit
3701character will not appear in the visible prompt, and will not 3701character will not appear in the visible prompt, and will not
3702cause the terminal's cursor to change position, but rather set terminal 3702cause the terminal's cursor to change position, but rather set terminal
3703attributes for the following prompt character(s) at least one of 3703attributes for the following prompt character(s) at least one of
3704which must be present. 3704which must be present.
3705See 3705See
3706.Sx Command Line Editing 3706.Sx Command Line Editing
3707above for more information. 3707above for more information.
3708.It Ev RANDOM 3708.It Ev RANDOM
3709Returns a different pseudo-random integer, 3709Returns a different pseudo-random integer,
3710in the range [0,32767] each time it is accessed. 3710in the range [0,32767] each time it is accessed.
3711.Ev RANDOM 3711.Ev RANDOM
3712can be assigned an integer value to seed the PRNG. 3712can be assigned an integer value to seed the PRNG.
3713If the value assigned is a constant, then the 3713If the value assigned is a constant, then the
3714sequence of values produces on subsequent references of 3714sequence of values produces on subsequent references of
3715.Ev RANDOM 3715.Ev RANDOM
3716will repeat after the next time the same constant is assigned. 3716will repeat after the next time the same constant is assigned.
3717Note, this is not guaranteed to remain constant from one version 3717Note, this is not guaranteed to remain constant from one version
3718of the shell to another \(en the PRNG algorithm, or seeding 3718of the shell to another \(en the PRNG algorithm, or seeding
3719method is subject to change. 3719method is subject to change.
3720If 3720If
3721.Ev RANDOM 3721.Ev RANDOM
3722is assigned an empty value (null string) then the next time 3722is assigned an empty value (null string) then the next time
3723.Ev RANDOM 3723.Ev RANDOM
3724is accessed, it will be seeded from a more genuinely random source. 3724is accessed, it will be seeded from a more genuinely random source.
3725The sequence of pseudo-random numbers generated will not be able to 3725The sequence of pseudo-random numbers generated will not be able to
3726be generated again (except by luck, whether good or bad, depends!) 3726be generated again (except by luck, whether good or bad, depends!)
3727This is also how the initial seed is generated, if none has been 3727This is also how the initial seed is generated, if none has been
3728assigned before 3728assigned before
3729.Ev RANDOM 3729.Ev RANDOM
3730is first accessed after shell initialization. 3730is first accessed after shell initialization.
3731.It Ev SECONDS 3731.It Ev SECONDS
3732Returns the number of seconds since the current shell was started. 3732Returns the number of seconds since the current shell was started.
3733Attempts to set this variable are ignored. 3733Attempts to set this variable are ignored.
3734If unset, it remains unset, and returns nothing, unless set again. 3734If unset, it remains unset, and returns nothing, unless set again.
3735.It Ev START_TIME 3735.It Ev START_TIME
3736Initialized by the shell to the number of seconds since the Epoch 3736Initialized by the shell to the number of seconds since the Epoch
3737(see 3737(see
3738.Xr localtime 3 ) 3738.Xr localtime 3 )
3739when the shell was started. 3739when the shell was started.
3740The value of 3740The value of
3741.Dl $(( Ns Ev START_TIME + Ev SECONDS Ns )) 3741.Dl $(( Ns Ev START_TIME + Ev SECONDS Ns ))
3742represents the current time, if 3742represents the current time, if
3743.Ev START_TIME 3743.Ev START_TIME
3744has not been modified, and 3744has not been modified, and
3745.Ev SECONDS 3745.Ev SECONDS
3746is not unset. 3746is not unset.
3747.It Ev TERM 3747.It Ev TERM
3748The default terminal setting for the shell. 3748The default terminal setting for the shell.
3749This is inherited by 3749This is inherited by
3750children of the shell, and is used in the history editing modes. 3750children of the shell, and is used in the history editing modes.
3751.\" This is explicitly last, not in sort order - please leave! 3751.\" This is explicitly last, not in sort order - please leave!
3752.It Ev ToD 3752.It Ev ToD
3753When referenced, uses the value of 3753When referenced, uses the value of
3754.Ev ToD_FORMAT 3754.Ev ToD_FORMAT
3755(or 3755(or
3756.Dq \&%T 3756.Dq \&%T
3757if 3757if
3758.Ev ToD_FORMAT 3758.Ev ToD_FORMAT
3759is unset) as the format argument to 3759is unset) as the format argument to
3760.Xr strftime 3 3760.Xr strftime 3
3761to encode the current time of day, in the time zone 3761to encode the current time of day, in the time zone
3762defined by 3762defined by
3763.Ev TZ 3763.Ev TZ
3764if set, or current local time if not, and returns the result. 3764if set, or current local time if not, and returns the result.
3765If unset 3765If unset
3766.Ev ToD 3766.Ev ToD
3767returns nothing. 3767returns nothing.
3768Setting it has no effect, other than to reverse the effect of an earlier 3768Setting it has no effect, other than to reverse the effect of an earlier
3769.Ic unset . 3769.Ic unset .
3770.It Ev ToD_FORMAT 3770.It Ev ToD_FORMAT
3771Can be set to the 3771Can be set to the
3772.Xr strftime 3 3772.Xr strftime 3
3773format string to be used when expanding 3773format string to be used when expanding
3774.Ev ToD . 3774.Ev ToD .
3775Initially unset. 3775Initially unset.
3776.It Ev TZ 3776.It Ev TZ
3777If set, gives the time zone 3777If set, gives the time zone
3778(see 3778(see
3779.Xr localtime 3 , 3779.Xr localtime 3 ,
3780.Xr environ 7 ) 3780.Xr environ 7 )
3781to use when formatting 3781to use when formatting
3782.Ev ToD 3782.Ev ToD
3783and if exported, other utilities that deal with times. 3783and if exported, other utilities that deal with times.
3784If unset, the system's local wall clock time zone is used. 3784If unset, the system's local wall clock time zone is used.
3785.It Ev NETBSD_SHELL 3785.It Ev NETBSD_SHELL
3786Unlike the variables previously mentioned, 3786Unlike the variables previously mentioned,
3787this variable is somewhat strange, 3787this variable is somewhat strange,
3788in that it cannot be set, 3788in that it cannot be set,
3789inherited from the environment, 3789inherited from the environment,
3790modified, or exported from the shell. 3790modified, or exported from the shell.
3791If set, by the shell, it indicates that the shell is the 3791If set, by the shell, it indicates that the shell is the
3792.Ic sh 3792.Ic sh
3793defined by this manual page, and gives its version information. 3793defined by this manual page, and gives its version information.
3794It can also give information in additional space separated words, 3794It can also give information in additional space separated words,
3795after the version string. 3795after the version string.
3796If the shell was built as part of a reproducible build, 3796If the shell was built as part of a reproducible build,
3797the relevant date that was used for that build will be included. 3797the relevant date that was used for that build will be included.
3798Finally, any non-standard compilation options, 3798Finally, any non-standard compilation options,
3799which may affect features available, 3799which may affect features available,
3800that were used when building the shell will be listed. 3800that were used when building the shell will be listed.
3801.Ev NETBSD_SHELL 3801.Ev NETBSD_SHELL
3802behaves like any other variable that has the read-only 3802behaves like any other variable that has the read-only
3803and un-exportable attributes set. 3803and un-exportable attributes set.
3804.El 3804.El
3805.Ss Ev LINENO 3805.Ss Ev LINENO
3806.Ev LINENO 3806.Ev LINENO
3807is in many respects a normal shell variable, containing an 3807is in many respects a normal shell variable, containing an
3808integer value. and can be expanded using any of the forms 3808integer value. and can be expanded using any of the forms
3809mentioned above which can be used for any other variable. 3809mentioned above which can be used for any other variable.
3810.Pp 3810.Pp
3811.Ev LINENO 3811.Ev LINENO
3812can be exported, made readonly, or unset, as with any other 3812can be exported, made readonly, or unset, as with any other
3813variable, with similar effects. 3813variable, with similar effects.
3814Note that while being readonly prevents later attempts to 3814Note that while being readonly prevents later attempts to
3815set, or unset, 3815set, or unset,
3816.Ev LINENO , 3816.Ev LINENO ,
3817it does not prevent its value changing. 3817it does not prevent its value changing.
3818References to 3818References to
3819.Ev LINENO 3819.Ev LINENO
3820.Pq "when not unset" 3820.Pq "when not unset"
3821always obtain the current line number. 3821always obtain the current line number.
3822However, 3822However,
3823.Ev LINENO 3823.Ev LINENO
3824should normally not ever be set or unset. 3824should normally not ever be set or unset.
3825In this shell setting 3825In this shell setting
3826.Ev LINENO 3826.Ev LINENO
3827reverses the effect of an earlier 3827reverses the effect of an earlier
3828.Ic unset , 3828.Ic unset ,
3829but does not otherwise affect the value obtained. 3829but does not otherwise affect the value obtained.
3830If unset, 3830If unset,
3831.Ev LINENO 3831.Ev LINENO
3832should not normally be set again, doing so is not portable. 3832should not normally be set again, doing so is not portable.
3833If 3833If
3834.Ev LINENO 3834.Ev LINENO
3835is set or unset, different shells act differently. 3835is set or unset, different shells act differently.
3836The value of 3836The value of
3837.Ev LINENO 3837.Ev LINENO
3838is never imported from the environment when the shell is 3838is never imported from the environment when the shell is
3839started, though if present there, as with any other variable, 3839started, though if present there, as with any other variable,
3840.Ev LINENO 3840.Ev LINENO
3841will be exported by this shell. 3841will be exported by this shell.
3842.Pp 3842.Pp
3843.Ev LINENO 3843.Ev LINENO
3844is set automatically by the shell to be the number of the source 3844is set automatically by the shell to be the number of the source
3845line on which it occurs. 3845line on which it occurs.
3846When exported, 3846When exported,
3847.Ev LINENO 3847.Ev LINENO
3848is exported with its value set to the line number it would have 3848is exported with its value set to the line number it would have
3849had had it been referenced on the command line of the command to 3849had had it been referenced on the command line of the command to
3850which it is exported. 3850which it is exported.
3851Line numbers are counted from 1, which is the first line the shell 3851Line numbers are counted from 1, which is the first line the shell
3852reads from any particular file. 3852reads from any particular file.
3853For this shell, standard input, including in an interactive shell, 3853For this shell, standard input, including in an interactive shell,
3854the user's terminal, is just another file and lines are counted 3854the user's terminal, is just another file and lines are counted
3855there as well. 3855there as well.
3856However note that not all shells count interactive 3856However note that not all shells count interactive
3857lines this way, it is not wise to rely upon 3857lines this way, it is not wise to rely upon
3858.Ev LINENO 3858.Ev LINENO
3859having a useful value, except in a script, or a function. 3859having a useful value, except in a script, or a function.
3860.Pp 3860.Pp
3861The role of 3861The role of
3862.Ev LINENO 3862.Ev LINENO
3863in functions is less clear. 3863in functions is less clear.
3864In some shells, 3864In some shells,
3865.Ev LINENO 3865.Ev LINENO
3866continues to refer to the line number in the script which defines 3866continues to refer to the line number in the script which defines
3867the function, 3867the function,
3868in others lines count from one within the function, always (and 3868in others lines count from one within the function, always (and
3869resume counting normally once the function definition is complete) 3869resume counting normally once the function definition is complete)
3870and others count in functions from one if the function is defined 3870and others count in functions from one if the function is defined
3871interactively, but otherwise just reference the line number in the 3871interactively, but otherwise just reference the line number in the
3872script in which the function is defined. 3872script in which the function is defined.
3873This shell gives the user the option to choose. 3873This shell gives the user the option to choose.
3874If the 3874If the
3875.Fl L 3875.Fl L
3876flag (the 3876flag (the
3877.Ic local_lineno 3877.Ic local_lineno
3878option, see 3878option, see
3879.Sx Argument List Processing ) 3879.Sx Argument List Processing )
3880is set, when the function is defined, then the function 3880is set, when the function is defined, then the function
3881defaults to counting lines with one being the first line of the 3881defaults to counting lines with one being the first line of the
3882function. 3882function.
3883When the 3883When the
3884.Fl L 3884.Fl L
3885flag is not set, the shell counts lines in a function definition 3885flag is not set, the shell counts lines in a function definition
3886in the same continuous sequence as the lines that surround the 3886in the same continuous sequence as the lines that surround the
3887function definition. 3887function definition.
3888Further, if 3888Further, if
3889.Ev LINENO 3889.Ev LINENO
3890is made local 3890is made local
3891(see 3891(see
3892.Sx Built-ins 3892.Sx Built-ins
3893above) 3893above)
3894inside the function, the function can decide which 3894inside the function, the function can decide which
3895behavior it prefers. 3895behavior it prefers.
3896If 3896If
3897.Ev LINENO 3897.Ev LINENO
3898is made local and inherited, and not given a value, as in 3898is made local and inherited, and not given a value, as in
3899.Dl local Fl I Ev LINENO 3899.Dl local Fl I Ev LINENO
3900then from that point in the function, 3900then from that point in the function,
3901.Ev LINENO 3901.Ev LINENO
3902will give the line number as if lines are counted in sequence 3902will give the line number as if lines are counted in sequence
3903with the lines that surround the function definition (and 3903with the lines that surround the function definition (and
3904any other function definitions in which this is nested.) 3904any other function definitions in which this is nested.)
3905If 3905If
3906.Ev LINENO 3906.Ev LINENO
3907is made local, and in that same command, given a value, as 3907is made local, and in that same command, given a value, as
3908.Dl local Oo Fl I Ns | Ns Fl N Oc Ev LINENO Ns = Ns Ar value 3908.Dl local Oo Fl I Ns | Ns Fl N Oc Ev LINENO Ns = Ns Ar value
3909then 3909then
3910.Ev LINENO 3910.Ev LINENO
3911will give the line number as if lines are counted from one 3911will give the line number as if lines are counted from one
3912from the beginning of the function. 3912from the beginning of the function.
3913The value nominally assigned in this case is irrelevant, and ignored. 3913The value nominally assigned in this case is irrelevant, and ignored.
3914For completeness, if lineno is made local and unset, as in 3914For completeness, if lineno is made local and unset, as in
3915.Dl local Fl N Ev LINENO 3915.Dl local Fl N Ev LINENO
3916then 3916then
3917.Ev LINENO 3917.Ev LINENO
3918is simply unset inside the function, and gives no value at all. 3918is simply unset inside the function, and gives no value at all.
3919.Pp 3919.Pp
3920Now for some technical details. 3920Now for some technical details.
3921The line on which 3921The line on which
3922.Ev LINENO 3922.Ev LINENO
3923occurs in a parameter expansion, is the line that contains the 3923occurs in a parameter expansion, is the line that contains the
3924.Sq \&$ 3924.Sq \&$
3925that begins the expansion of 3925that begins the expansion of
3926.Ev LINENO . 3926.Ev LINENO .
3927In the case of nested expansions, that 3927In the case of nested expansions, that
3928.Sq \&$ 3928.Sq \&$
3929is the one that actually has 3929is the one that actually has
3930.Ev LINENO 3930.Ev LINENO
3931as its parameter. 3931as its parameter.
3932In an arithmetic expansion, where no 3932In an arithmetic expansion, where no
3933.Sq \&$ 3933.Sq \&$
3934is used to evaluate 3934is used to evaluate
3935.Ev LINENO 3935.Ev LINENO
3936but 3936but
3937.Ev LINENO 3937.Ev LINENO
3938is simply referenced as a variable, then the value is the 3938is simply referenced as a variable, then the value is the
3939line number of the line that contains the 3939line number of the line that contains the
3940.Sq L 3940.Sq L
3941of 3941of
3942.Ev LINENO . 3942.Ev LINENO .
3943For functions line one of the function definition (when relevant) 3943For functions line one of the function definition (when relevant)
3944is the line that contains the first character of the 3944is the line that contains the first character of the
3945function name in the definition. 3945function name in the definition.
3946When exported, the line number of the command is the line number 3946When exported, the line number of the command is the line number
3947where the first character of the word which becomes the command name occurs. 3947where the first character of the word which becomes the command name occurs.
3948.Pp 3948.Pp
3949When the shell opens a new file, for any reason, 3949When the shell opens a new file, for any reason,
3950it counts lines from one in that file, 3950it counts lines from one in that file,
3951and then resumes its original counting once it resumes reading the 3951and then resumes its original counting once it resumes reading the
3952previous input stream. 3952previous input stream.
3953When handling a string passed to 3953When handling a string passed to
3954.Ic eval 3954.Ic eval
3955the line number starts at the line on which the string starts, 3955the line number starts at the line on which the string starts,
3956and then if the string contains internal newline characters, 3956and then if the string contains internal newline characters,
3957those characters increase the line number. 3957those characters increase the line number.
3958This means that references to 3958This means that references to
3959.Ev LINENO 3959.Ev LINENO
3960in such a case can produce values larger than would be 3960in such a case can produce values larger than would be
3961produced by a reference on the line after the 3961produced by a reference on the line after the
3962.Ic eval . 3962.Ic eval .
3963.Sh FILES 3963.Sh FILES
3964.Bl -item 3964.Bl -item
3965.It 3965.It
3966.Pa $HOME/.profile 3966.Pa $HOME/.profile
3967.It 3967.It
3968.Pa /etc/profile 3968.Pa /etc/profile
3969.El 3969.El
3970.Sh EXIT STATUS 3970.Sh EXIT STATUS
3971Errors that are detected by the shell, such as a syntax error, will cause the 3971Errors that are detected by the shell, such as a syntax error, will cause the
3972shell to exit with a non-zero exit status. 3972shell to exit with a non-zero exit status.
3973If the shell is not an 3973If the shell is not an
3974interactive shell, the execution of the shell file will be aborted. 3974interactive shell, the execution of the shell file will be aborted.
3975Otherwise 3975Otherwise
3976the shell will return the exit status of the last command executed, or 3976the shell will return the exit status of the last command executed, or
3977if the exit built-in is used with a numeric argument, it will return the 3977if the exit built-in is used with a numeric argument, it will return the
3978argument. 3978argument.
3979.Sh SEE ALSO 3979.Sh SEE ALSO
3980.Xr csh 1 , 3980.Xr csh 1 ,
3981.Xr echo 1 , 3981.Xr echo 1 ,
3982.Xr getopt 1 , 3982.Xr getopt 1 ,
3983.Xr ksh 1 , 3983.Xr ksh 1 ,
3984.Xr login 1 , 3984.Xr login 1 ,
3985.Xr printf 1 , 3985.Xr printf 1 ,
3986.Xr test 1 , 3986.Xr test 1 ,
3987.Xr editline 3 , 3987.Xr editline 3 ,
3988.Xr getopt 3 , 3988.Xr getopt 3 ,
3989.\" .Xr profile 4 , 3989.\" .Xr profile 4 ,
3990.Xr editrc 5 , 3990.Xr editrc 5 ,
3991.Xr passwd 5 , 3991.Xr passwd 5 ,
3992.Xr editline 7 , 3992.Xr editline 7 ,
3993.Xr environ 7 , 3993.Xr environ 7 ,
3994.Xr nls 7 , 3994.Xr nls 7 ,
3995.Xr sysctl 8 3995.Xr sysctl 8
3996.Sh HISTORY 3996.Sh HISTORY
3997A 3997A
3998.Nm 3998.Nm
3999command appeared in 3999command appeared in
4000.At v1 . 4000.At v1 .
4001It was replaced in 4001It was replaced in
4002.At v7 4002.At v7
4003with a version that introduced the basis of the current syntax. 4003with a version that introduced the basis of the current syntax.
4004That was, however, unmaintainable so we wrote this one. 4004That was, however, unmaintainable so we wrote this one.
4005.Sh BUGS 4005.Sh BUGS
4006Setuid shell scripts should be avoided at all costs, as they are a 4006Setuid shell scripts should be avoided at all costs, as they are a
4007significant security risk. 4007significant security risk.
4008.Pp 4008.Pp
4009The characters generated by filename completion should probably be quoted 4009The characters generated by filename completion should probably be quoted
4010to ensure that the filename is still valid after the input line has been 4010to ensure that the filename is still valid after the input line has been
4011processed. 4011processed.
4012.Pp 4012.Pp
4013The 4013The
4014.Ic trap 4014.Ic trap
4015command cannot usefully be used, yet, within a command substitution, 4015command cannot usefully be used, yet, within a command substitution,
4016to obtain the current trap values, 4016to obtain the current trap values,
4017as all command substitutions are currently executed within a 4017as all command substitutions are currently executed within a
4018sub-shell environment, 4018sub-shell environment,
4019and in sub-shells all non-ignored, non-default, traps are reset. 4019and in sub-shells all non-ignored, non-default, traps are reset.
4020As a workaround, it is possible to redirect output from 4020As a workaround, it is possible to redirect output from
4021.Dq trap 4021.Dq trap
4022or 4022or
4023.Dq trap -p 4023.Dq trap -p
4024to a file, and then read the file later using the 4024to a file, and then read the file later using the
4025.Dq \&. 4025.Dq \&.
4026command. 4026command.
4027.Pp 4027.Pp
4028Job control of compound statements (loops, etc) is a complete mess. 4028Job control of compound statements (loops, etc) is a complete mess.
4029.Pp 4029.Pp
4030Many, many, more. 4030Many, many, more.
4031(But less than there were...) 4031(But less than there were...)