~ubuntu-branches/ubuntu/trusty/bash/trusty-security

« back to all changes in this revision

Viewing changes to .pc/man-bashrc.diff/doc/bash.1

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-03-03 22:52:05 UTC
  • mfrom: (1.3.5) (2.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20140303225205-87ltrt5kspeq0g1b
Tags: 4.3-1ubuntu1
* Merge with Debian; remaining changes:
  - skel.bashrc:
    - Run lesspipe.
    - Enable ls aliases.
    - Set options in ll alias to -alF.
    - Define an alert alias.
    - Enabled colored grep aliases.
  - etc.bash.bashrc:
    - Add sudo hint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
.\"
 
2
.\" MAN PAGE COMMENTS to
 
3
.\"
 
4
.\"     Chet Ramey
 
5
.\"     Case Western Reserve University
 
6
.\"     chet.ramey@case.edu
 
7
.\"
 
8
.\"     Last Change: Sun Feb  2 16:21:40 EST 2014
 
9
.\"
 
10
.\" bash_builtins, strip all but Built-Ins section
 
11
.if \n(zZ=1 .ig zZ
 
12
.if \n(zY=1 .ig zY
 
13
.TH BASH 1 "2014 February 2" "GNU Bash 4.3"
 
14
.\"
 
15
.\" There's some problem with having a `@'
 
16
.\" in a tagged paragraph with the BSD man macros.
 
17
.\" It has to do with `@' appearing in the }1 macro.
 
18
.\" This is a problem on 4.3 BSD and Ultrix, but Sun
 
19
.\" appears to have fixed it.
 
20
.\" If you're seeing the characters
 
21
.\" `@u-3p' appearing before the lines reading
 
22
.\" `possible-hostname-completions
 
23
.\" and `complete-hostname' down in READLINE,
 
24
.\" then uncomment this redefinition.
 
25
.\"
 
26
.de }1
 
27
.ds ]X \&\\*(]B\\
 
28
.nr )E 0
 
29
.if !"\\$1"" .nr )I \\$1n
 
30
.}f
 
31
.ll \\n(LLu
 
32
.in \\n()Ru+\\n(INu+\\n()Iu
 
33
.ti \\n(INu
 
34
.ie !\\n()Iu+\\n()Ru-\w\\*(]Xu-3p \{\\*(]X
 
35
.br\}
 
36
.el \\*(]X\h|\\n()Iu+\\n()Ru\c
 
37
.}f
 
38
..
 
39
.\"
 
40
.\" File Name macro.  This used to be `.PN', for Path Name,
 
41
.\" but Sun doesn't seem to like that very much.
 
42
.\"
 
43
.de FN
 
44
\fI\|\\$1\|\fP
 
45
..
 
46
.SH NAME
 
47
bash \- GNU Bourne-Again SHell
 
48
.SH SYNOPSIS
 
49
.B bash
 
50
[options]
 
51
[command_string | file]
 
52
.SH COPYRIGHT
 
53
.if n Bash is Copyright (C) 1989-2013 by the Free Software Foundation, Inc.
 
54
.if t Bash is Copyright \(co 1989-2013 by the Free Software Foundation, Inc.
 
55
.SH DESCRIPTION
 
56
.B Bash
 
57
is an \fBsh\fR-compatible command language interpreter that
 
58
executes commands read from the standard input or from a file.
 
59
.B Bash
 
60
also incorporates useful features from the \fIKorn\fP and \fIC\fP
 
61
shells (\fBksh\fP and \fBcsh\fP).
 
62
.PP
 
63
.B Bash
 
64
is intended to be a conformant implementation of the
 
65
Shell and Utilities portion of the IEEE POSIX specification
 
66
(IEEE Standard 1003.1).
 
67
.B Bash
 
68
can be configured to be POSIX-conformant by default.
 
69
.SH OPTIONS
 
70
All of the  single-character shell options documented in the
 
71
description of the \fBset\fR builtin command can be used as options
 
72
when the shell is invoked.
 
73
In addition, \fBbash\fR
 
74
interprets the following options when it is invoked:
 
75
.PP
 
76
.PD 0
 
77
.TP 10
 
78
.B \-c
 
79
If the
 
80
.B \-c
 
81
option is present, then commands are read from the first non-option argument
 
82
.IR command_string .
 
83
If there are arguments after the
 
84
.IR command_string ,
 
85
they are assigned to the positional parameters, starting with
 
86
.BR $0 .
 
87
.TP
 
88
.B \-i
 
89
If the
 
90
.B \-i
 
91
option is present, the shell is
 
92
.IR interactive .
 
93
.TP
 
94
.B \-l
 
95
Make
 
96
.B bash
 
97
act as if it had been invoked as a login shell (see
 
98
.SM
 
99
.B INVOCATION
 
100
below).
 
101
.TP
 
102
.B \-r
 
103
If the
 
104
.B \-r
 
105
option is present, the shell becomes
 
106
.I restricted
 
107
(see
 
108
.SM
 
109
.B "RESTRICTED SHELL"
 
110
below).
 
111
.TP
 
112
.B \-s
 
113
If the
 
114
.B \-s
 
115
option is present, or if no arguments remain after option
 
116
processing, then commands are read from the standard input.
 
117
This option allows the positional parameters to be set
 
118
when invoking an interactive shell.
 
119
.TP
 
120
.B \-D
 
121
A list of all double-quoted strings preceded by \fB$\fP
 
122
is printed on the standard output.
 
123
These are the strings that
 
124
are subject to language translation when the current locale
 
125
is not \fBC\fP or \fBPOSIX\fP.
 
126
This implies the \fB\-n\fP option; no commands will be executed.
 
127
.TP
 
128
.B [\-+]O [\fIshopt_option\fP]
 
129
\fIshopt_option\fP is one of the shell options accepted by the
 
130
\fBshopt\fP builtin (see
 
131
.SM
 
132
.B SHELL BUILTIN COMMANDS
 
133
below).
 
134
If \fIshopt_option\fP is present, \fB\-O\fP sets the value of that option;
 
135
\fB+O\fP unsets it.
 
136
If \fIshopt_option\fP is not supplied, the names and values of the shell
 
137
options accepted by \fBshopt\fP are printed on the standard output.
 
138
If the invocation option is \fB+O\fP, the output is displayed in a format
 
139
that may be reused as input.
 
140
.TP
 
141
.B \-\-
 
142
A
 
143
.B \-\-
 
144
signals the end of options and disables further option processing.
 
145
Any arguments after the
 
146
.B \-\-
 
147
are treated as filenames and arguments.  An argument of
 
148
.B \-
 
149
is equivalent to \fB\-\-\fP.
 
150
.PD
 
151
.PP
 
152
.B Bash
 
153
also interprets a number of multi-character options.
 
154
These options must appear on the command line before the
 
155
single-character options to be recognized.
 
156
.PP
 
157
.PD 0
 
158
.TP
 
159
.B \-\-debugger
 
160
Arrange for the debugger profile to be executed before the shell
 
161
starts.
 
162
Turns on extended debugging mode (see the description of the
 
163
.B extdebug
 
164
option to the
 
165
.B shopt
 
166
builtin below).
 
167
.TP
 
168
.B \-\-dump\-po\-strings
 
169
Equivalent to \fB\-D\fP, but the output is in the GNU \fIgettext\fP
 
170
\fBpo\fP (portable object) file format.
 
171
.TP
 
172
.B \-\-dump\-strings
 
173
Equivalent to \fB\-D\fP.
 
174
.TP
 
175
.B \-\-help
 
176
Display a usage message on standard output and exit successfully.
 
177
.TP
 
178
\fB\-\-init\-file\fP \fIfile\fP
 
179
.PD 0
 
180
.TP
 
181
\fB\-\-rcfile\fP \fIfile\fP
 
182
.PD
 
183
Execute commands from
 
184
.I file
 
185
instead of the standard personal initialization file
 
186
.I ~/.bashrc
 
187
if the shell is interactive (see
 
188
.SM
 
189
.B INVOCATION
 
190
below).
 
191
.TP
 
192
.B \-\-login
 
193
Equivalent to \fB\-l\fP.
 
194
.TP
 
195
.B \-\-noediting
 
196
Do not use the GNU
 
197
.B readline
 
198
library to read command lines when the shell is interactive.
 
199
.TP
 
200
.B \-\-noprofile
 
201
Do not read either the system-wide startup file
 
202
.FN /etc/profile
 
203
or any of the personal initialization files
 
204
.IR ~/.bash_profile ,
 
205
.IR ~/.bash_login ,
 
206
or
 
207
.IR ~/.profile .
 
208
By default,
 
209
.B bash
 
210
reads these files when it is invoked as a login shell (see
 
211
.SM
 
212
.B INVOCATION
 
213
below).
 
214
.TP
 
215
.B \-\-norc
 
216
Do not read and execute the personal initialization file
 
217
.I ~/.bashrc
 
218
if the shell is interactive.
 
219
This option is on by default if the shell is invoked as
 
220
.BR sh .
 
221
.TP
 
222
.B \-\-posix
 
223
Change the behavior of \fBbash\fP where the default operation differs
 
224
from the POSIX standard to match the standard (\fIposix mode\fP).
 
225
See
 
226
.SM
 
227
.B "SEE ALSO"
 
228
below for a reference to a document that details how posix mode affects
 
229
bash's behavior.
 
230
.TP
 
231
.B \-\-restricted
 
232
The shell becomes restricted (see
 
233
.SM
 
234
.B "RESTRICTED SHELL"
 
235
below).
 
236
.TP
 
237
.B \-\-verbose
 
238
Equivalent to  \fB\-v\fP.
 
239
.TP
 
240
.B \-\-version
 
241
Show version information for this instance of
 
242
.B bash
 
243
on the standard output and exit successfully.
 
244
.PD
 
245
.SH ARGUMENTS
 
246
If arguments remain after option processing, and neither the
 
247
.B \-c
 
248
nor the
 
249
.B \-s
 
250
option has been supplied, the first argument is assumed to
 
251
be the name of a file containing shell commands.
 
252
If
 
253
.B bash
 
254
is invoked in this fashion, 
 
255
.B $0
 
256
is set to the name of the file, and the positional parameters
 
257
are set to the remaining arguments.
 
258
.B Bash
 
259
reads and executes commands from this file, then exits.
 
260
\fBBash\fP's exit status is the exit status of the last command
 
261
executed in the script.
 
262
If no commands are executed, the exit status is 0.
 
263
An attempt is first made to open the file in the current directory, and,
 
264
if no file is found, then the shell searches the directories in
 
265
.SM
 
266
.B PATH
 
267
for the script.
 
268
.SH INVOCATION
 
269
A \fIlogin shell\fP is one whose first character of argument zero is a
 
270
.BR \- ,
 
271
or one started with the 
 
272
.B \-\-login
 
273
option.
 
274
.PP
 
275
An \fIinteractive\fP shell is one started without non-option arguments
 
276
and without the
 
277
.B \-c
 
278
option
 
279
whose standard input and error are
 
280
both connected to terminals (as determined by
 
281
.IR isatty (3)),
 
282
or one started with the
 
283
.B \-i
 
284
option.
 
285
.SM
 
286
.B PS1
 
287
is set and
 
288
.B $\-
 
289
includes
 
290
.B i
 
291
if
 
292
.B bash
 
293
is interactive,
 
294
allowing a shell script or a startup file to test this state.
 
295
.PP
 
296
The following paragraphs describe how
 
297
.B bash
 
298
executes its startup files.
 
299
If any of the files exist but cannot be read,
 
300
.B bash
 
301
reports an error.
 
302
Tildes are expanded in filenames as described below under
 
303
.B "Tilde Expansion"
 
304
in the
 
305
.SM
 
306
.B EXPANSION
 
307
section.
 
308
.PP
 
309
When
 
310
.B bash
 
311
is invoked as an interactive login shell, or as a non-interactive shell
 
312
with the \fB\-\-login\fP option, it first reads and
 
313
executes commands from the file \fI/etc/profile\fP, if that
 
314
file exists.
 
315
After reading that file, it looks for \fI~/.bash_profile\fP,
 
316
\fI~/.bash_login\fP, and \fI~/.profile\fP, in that order, and reads
 
317
and executes commands from the first one that exists and is readable.
 
318
The
 
319
.B \-\-noprofile
 
320
option may be used when the shell is started to inhibit this behavior.
 
321
.PP
 
322
When a login shell exits,
 
323
.B bash
 
324
reads and executes commands from the file \fI~/.bash_logout\fP, if it
 
325
exists.
 
326
.PP
 
327
When an interactive shell that is not a login shell is started,
 
328
.B bash
 
329
reads and executes commands from \fI~/.bashrc\fP, if that file exists.
 
330
This may be inhibited by using the
 
331
.B \-\-norc
 
332
option.
 
333
The \fB\-\-rcfile\fP \fIfile\fP option will force
 
334
.B bash
 
335
to read and execute commands from \fIfile\fP instead of \fI~/.bashrc\fP.
 
336
.PP
 
337
When
 
338
.B bash
 
339
is started non-interactively, to run a shell script, for example, it
 
340
looks for the variable
 
341
.SM
 
342
.B BASH_ENV
 
343
in the environment, expands its value if it appears there, and uses the
 
344
expanded value as the name of a file to read and execute.
 
345
.B Bash
 
346
behaves as if the following command were executed:
 
347
.sp .5
 
348
.RS
 
349
.if t \f(CWif [ \-n "$BASH_ENV" ]; then . "$BASH_ENV"; fi\fP
 
350
.if n if [ \-n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
 
351
.RE
 
352
.sp .5
 
353
but the value of the
 
354
.SM
 
355
.B PATH
 
356
variable is not used to search for the filename.
 
357
.PP
 
358
If
 
359
.B bash
 
360
is invoked with the name
 
361
.BR sh ,
 
362
it tries to mimic the startup behavior of historical versions of
 
363
.B sh
 
364
as closely as possible,
 
365
while conforming to the POSIX standard as well.
 
366
When invoked as an interactive login shell, or a non-interactive
 
367
shell with the \fB\-\-login\fP option, it first attempts to
 
368
read and execute commands from
 
369
.I /etc/profile
 
370
and
 
371
.IR ~/.profile ,
 
372
in that order.
 
373
The
 
374
.B \-\-noprofile
 
375
option may be used to inhibit this behavior.
 
376
When invoked as an interactive shell with the name
 
377
.BR sh ,
 
378
.B bash
 
379
looks for the variable
 
380
.SM
 
381
.BR ENV ,
 
382
expands its value if it is defined, and uses the
 
383
expanded value as the name of a file to read and execute.
 
384
Since a shell invoked as
 
385
.B sh
 
386
does not attempt to read and execute commands from any other startup
 
387
files, the
 
388
.B \-\-rcfile
 
389
option has no effect.
 
390
A non-interactive shell invoked with the name
 
391
.B sh
 
392
does not attempt to read any other startup files. 
 
393
When invoked as
 
394
.BR sh ,
 
395
.B bash
 
396
enters
 
397
.I posix
 
398
mode after the startup files are read.
 
399
.PP
 
400
When
 
401
.B bash
 
402
is started in
 
403
.I posix
 
404
mode, as with the
 
405
.B \-\-posix
 
406
command line option, it follows the POSIX standard for startup files.
 
407
In this mode, interactive shells expand the
 
408
.SM
 
409
.B ENV
 
410
variable and commands are read and executed from the file
 
411
whose name is the expanded value.
 
412
No other startup files are read.
 
413
.PP
 
414
.B Bash
 
415
attempts to determine when it is being run with its standard input
 
416
connected to a network connection, as when executed by the remote shell
 
417
daemon, usually \fIrshd\fP, or the secure shell daemon \fIsshd\fP.
 
418
If
 
419
.B bash
 
420
determines it is being run in this fashion, it reads and executes
 
421
commands from \fI~/.bashrc\fP, if that file exists and is readable.
 
422
It will not do this if invoked as \fBsh\fP.
 
423
The
 
424
.B \-\-norc
 
425
option may be used to inhibit this behavior, and the
 
426
.B \-\-rcfile
 
427
option may be used to force another file to be read, but neither
 
428
\fIrshd\fP nor \fIsshd\fP generally invoke the shell with those options
 
429
or allow them to be specified.
 
430
.PP
 
431
If the shell is started with the effective user (group) id not equal to the
 
432
real user (group) id, and the \fB\-p\fP option is not supplied, no startup
 
433
files are read, shell functions are not inherited from the environment, the
 
434
.SM
 
435
.BR SHELLOPTS ,
 
436
.SM
 
437
.BR BASHOPTS ,
 
438
.SM
 
439
.BR CDPATH ,
 
440
and
 
441
.SM
 
442
.B GLOBIGNORE
 
443
variables, if they appear in the environment, are ignored,
 
444
and the effective user id is set to the real user id.
 
445
If the \fB\-p\fP option is supplied at invocation, the startup behavior is
 
446
the same, but the effective user id is not reset.
 
447
.SH DEFINITIONS
 
448
.PP
 
449
The following definitions are used throughout the rest of this
 
450
document.
 
451
.PD 0
 
452
.TP
 
453
.B blank 
 
454
A space or tab.
 
455
.TP
 
456
.B word
 
457
A sequence of characters considered as a single unit by the shell.
 
458
Also known as a
 
459
.BR token .
 
460
.TP
 
461
.B name
 
462
 
463
.I word
 
464
consisting only of alphanumeric characters and underscores, and
 
465
beginning with an alphabetic character or an underscore.  Also
 
466
referred to as an
 
467
.BR identifier .
 
468
.TP
 
469
.B metacharacter
 
470
A character that, when unquoted, separates words.  One of the following:
 
471
.br
 
472
.RS
 
473
.PP
 
474
.if t \fB|  &  ;  (  )  <  >  space  tab\fP
 
475
.if n \fB|  & ; ( ) < > space tab\fP
 
476
.RE
 
477
.PP
 
478
.TP
 
479
.B control operator
 
480
A \fItoken\fP that performs a control function.  It is one of the following
 
481
symbols:
 
482
.RS
 
483
.PP
 
484
.if t \fB||  &  &&  ;  ;;  (  )  |  |&    <newline>\fP
 
485
.if n \fB|| & && ; ;; ( ) | |& <newline>\fP
 
486
.RE
 
487
.PD
 
488
.SH "RESERVED WORDS"
 
489
\fIReserved words\fP are words that have a special meaning to the shell.
 
490
The following words are recognized as reserved when unquoted and either
 
491
the first word of a simple command (see
 
492
.SM
 
493
.B SHELL GRAMMAR
 
494
below) or the third word of a 
 
495
.B case 
 
496
or
 
497
.B for
 
498
command:
 
499
.if t .RS
 
500
.PP
 
501
.B
 
502
.if n ! case  coproc  do done elif else esac fi for function if in select then until while { } time [[ ]]
 
503
.if t !    case    coproc    do    done    elif    else    esac    fi    for    function    if    in    select    then    until    while    {    }    time    [[    ]]
 
504
.if t .RE
 
505
.SH "SHELL GRAMMAR"
 
506
.SS Simple Commands
 
507
.PP
 
508
A \fIsimple command\fP is a sequence of optional variable assignments
 
509
followed by \fBblank\fP-separated words and redirections, and
 
510
terminated by a \fIcontrol operator\fP.  The first word
 
511
specifies the command to be executed, and is passed as argument zero.
 
512
The remaining words are passed as arguments to the invoked command.
 
513
.PP
 
514
The return value of a \fIsimple command\fP is its exit status, or
 
515
128+\fIn\^\fP if the command is terminated by signal
 
516
.IR n .
 
517
.SS Pipelines
 
518
.PP
 
519
A \fIpipeline\fP is a sequence of one or more commands separated by
 
520
one of the control operators
 
521
.B |
 
522
or \fB|&\fP.
 
523
The format for a pipeline is:
 
524
.RS
 
525
.PP
 
526
[\fBtime\fP [\fB\-p\fP]] [ ! ] \fIcommand\fP [ [\fB|\fP\(bv\fB|&\fP] \fIcommand2\fP ... ]
 
527
.RE
 
528
.PP
 
529
The standard output of
 
530
.I command
 
531
is connected via a pipe to the standard input of
 
532
.IR command2 .
 
533
This connection is performed before any redirections specified by the
 
534
command (see
 
535
.SM
 
536
.B REDIRECTION
 
537
below).
 
538
If \fB|&\fP is used, \fIcommand\fP's standard error, in addition to its
 
539
standard output, is connected to
 
540
\fIcommand2\fP's standard input through the pipe;
 
541
it is shorthand for \fB2>&1 |\fP.
 
542
This implicit redirection of the standard error to the standard output is
 
543
performed after any redirections specified by the command.
 
544
.PP
 
545
The return status of a pipeline is the exit status of the last
 
546
command, unless the \fBpipefail\fP option is enabled.
 
547
If \fBpipefail\fP is enabled, the pipeline's return status is the
 
548
value of the last (rightmost) command to exit with a non-zero status,
 
549
or zero if all commands exit successfully.
 
550
If the reserved word
 
551
.B !
 
552
precedes a pipeline, the exit status of that pipeline is the logical
 
553
negation of the exit status as described above.
 
554
The shell waits for all commands in the pipeline to
 
555
terminate before returning a value.
 
556
.PP
 
557
If the
 
558
.B time
 
559
reserved word precedes a pipeline, the elapsed as well as user and
 
560
system time consumed by its execution are reported when the pipeline
 
561
terminates.
 
562
The \fB\-p\fP option changes the output format to that specified by POSIX.
 
563
When the shell is in \fIposix mode\fP, it does not recognize
 
564
\fBtime\fP as a reserved word if the next token begins with a `-'.
 
565
The
 
566
.SM
 
567
.B TIMEFORMAT
 
568
variable may be set to a format string that specifies how the timing
 
569
information should be displayed; see the description of
 
570
.SM
 
571
.B TIMEFORMAT
 
572
under
 
573
.B "Shell Variables"
 
574
below.
 
575
.PP
 
576
When the shell is in \fIposix mode\fP, \fBtime\fP
 
577
may be followed by a newline.  In this case, the shell displays the
 
578
total user and system time consumed by the shell and its children.
 
579
The
 
580
.SM
 
581
.B TIMEFORMAT
 
582
variable may be used to specify the format of
 
583
the time information.
 
584
.PP
 
585
Each command in a pipeline is executed as a separate process (i.e., in a
 
586
subshell).
 
587
.SS Lists
 
588
.PP
 
589
A \fIlist\fP is a sequence of one or more pipelines separated by one
 
590
of the operators
 
591
.BR ; ,
 
592
.BR & ,
 
593
.BR && ,
 
594
or
 
595
.BR || ,
 
596
and optionally terminated by one of
 
597
.BR ; ,
 
598
.BR & ,
 
599
or
 
600
.BR <newline> .
 
601
.PP
 
602
Of these list operators,
 
603
.B &&
 
604
and
 
605
.B ||
 
606
have equal precedence, followed by
 
607
.B ;
 
608
and
 
609
.BR & ,
 
610
which have equal precedence.
 
611
.PP
 
612
A sequence of one or more newlines may appear in a \fIlist\fP instead
 
613
of a semicolon to delimit commands.
 
614
.PP
 
615
If a command is terminated by the control operator
 
616
.BR & ,
 
617
the shell executes the command in the \fIbackground\fP
 
618
in a subshell.  The shell does not wait for the command to
 
619
finish, and the return status is 0.  Commands separated by a
 
620
.B ;
 
621
are executed sequentially; the shell waits for each
 
622
command to terminate in turn.  The return status is the
 
623
exit status of the last command executed.
 
624
.PP
 
625
AND and OR lists are sequences of one of more pipelines separated by the
 
626
\fB&&\fP and \fB||\fP control operators, respectively.
 
627
AND and OR lists are executed with left associativity.
 
628
An AND list has the form
 
629
.RS
 
630
.PP
 
631
\fIcommand1\fP \fB&&\fP \fIcommand2\fP
 
632
.RE
 
633
.PP
 
634
.I command2
 
635
is executed if, and only if,
 
636
.I command1
 
637
returns an exit status of zero.
 
638
.PP
 
639
An OR list has the form
 
640
.RS
 
641
.PP
 
642
\fIcommand1\fP \fB||\fP \fIcommand2\fP
 
643
.PP
 
644
.RE
 
645
.PP
 
646
.I command2
 
647
is executed if and only if
 
648
.I command1
 
649
returns a non-zero exit status.
 
650
The return status of
 
651
AND and OR lists is the exit status of the last command
 
652
executed in the list.
 
653
.SS Compound Commands
 
654
.PP
 
655
A \fIcompound command\fP is one of the following.
 
656
In most cases a \fIlist\fP in a command's description may be separated from
 
657
the rest of the command by one or more newlines, and may be followed by a
 
658
newline in place of a semicolon.
 
659
.TP
 
660
(\fIlist\fP)
 
661
\fIlist\fP is executed in a subshell environment (see
 
662
.SM
 
663
\fBCOMMAND EXECUTION ENVIRONMENT\fP
 
664
below).
 
665
Variable assignments and builtin
 
666
commands that affect the shell's environment do not remain in effect
 
667
after the command completes.  The return status is the exit status of
 
668
\fIlist\fP.
 
669
.TP
 
670
{ \fIlist\fP; }
 
671
\fIlist\fP is simply executed in the current shell environment.
 
672
\fIlist\fP must be terminated with a newline or semicolon.
 
673
This is known as a \fIgroup command\fP.
 
674
The return status is the exit status of
 
675
\fIlist\fP.
 
676
Note that unlike the metacharacters \fB(\fP and \fB)\fP, \fB{\fP and
 
677
\fB}\fP are \fIreserved words\fP and must occur where a reserved
 
678
word is permitted to be recognized.  Since they do not cause a word
 
679
break, they must be separated from \fIlist\fP by whitespace or another
 
680
shell metacharacter.
 
681
.TP
 
682
((\fIexpression\fP))
 
683
The \fIexpression\fP is evaluated according to the rules described
 
684
below under
 
685
.SM
 
686
.BR "ARITHMETIC EVALUATION" .
 
687
If the value of the expression is non-zero, the return status is 0;
 
688
otherwise the return status is 1.  This is exactly equivalent to
 
689
\fBlet "\fIexpression\fP"\fR.
 
690
.TP
 
691
\fB[[\fP \fIexpression\fP \fB]]\fP
 
692
Return a status of 0 or 1 depending on the evaluation of
 
693
the conditional expression \fIexpression\fP.
 
694
Expressions are composed of the primaries described below under
 
695
.SM
 
696
.BR "CONDITIONAL EXPRESSIONS" .
 
697
Word splitting and pathname expansion are not performed on the words
 
698
between the \fB[[\fP and \fB]]\fP; tilde expansion,
 
699
parameter and variable expansion,
 
700
arithmetic expansion, command substitution, process
 
701
substitution, and quote removal are performed.
 
702
Conditional operators such as \fB\-f\fP must be unquoted to be recognized
 
703
as primaries.
 
704
.if t .sp 0.5
 
705
.if n .sp 1
 
706
When used with \fB[[\fP, the \fB<\fP and \fB>\fP operators sort
 
707
lexicographically using the current locale.
 
708
.if t .sp 0.5
 
709
.if n .sp 1
 
710
When the \fB==\fP and \fB!=\fP operators are used, the string to the
 
711
right of the operator is considered a pattern and matched according
 
712
to the rules described below under \fBPattern Matching\fP,
 
713
as if the \fBextglob\fP shell option were enabled.
 
714
The \fB=\fP operator is equivalent to \fB==\fP.
 
715
If the shell option
 
716
.B nocasematch
 
717
is enabled, the match is performed without regard to the case
 
718
of alphabetic characters.
 
719
The return value is 0 if the string matches (\fB==\fP) or does not match
 
720
(\fB!=\fP) the pattern, and 1 otherwise.
 
721
Any part of the pattern may be quoted to force the quoted portion
 
722
to be matched as a string.
 
723
.if t .sp 0.5
 
724
.if n .sp 1
 
725
An additional binary operator, \fB=~\fP, is available, with the same
 
726
precedence as \fB==\fP and \fB!=\fP.
 
727
When it is used, the string to the right of the operator is considered
 
728
an extended regular expression and matched accordingly (as in \fIregex\fP(3)).  
 
729
The return value is 0 if the string matches
 
730
the pattern, and 1 otherwise.
 
731
If the regular expression is syntactically incorrect, the conditional
 
732
expression's return value is 2.
 
733
If the shell option
 
734
.B nocasematch
 
735
is enabled, the match is performed without regard to the case
 
736
of alphabetic characters.
 
737
Any part of the pattern may be quoted to force the quoted portion
 
738
to be matched as a string.
 
739
Bracket expressions in regular expressions must be treated carefully,
 
740
since normal quoting characters lose their meanings between brackets.
 
741
If the pattern is stored in a shell variable, quoting the variable
 
742
expansion forces the entire pattern to be matched as a string.
 
743
Substrings matched by parenthesized subexpressions within the regular
 
744
expression are saved in the array variable
 
745
.SM
 
746
.BR BASH_REMATCH .
 
747
The element of
 
748
.SM
 
749
.B BASH_REMATCH
 
750
with index 0 is the portion of the string
 
751
matching the entire regular expression.
 
752
The element of
 
753
.SM
 
754
.B BASH_REMATCH
 
755
with index \fIn\fP is the portion of the
 
756
string matching the \fIn\fPth parenthesized subexpression.
 
757
.if t .sp 0.5
 
758
.if n .sp 1
 
759
Expressions may be combined using the following operators, listed
 
760
in decreasing order of precedence:
 
761
.if t .sp 0.5
 
762
.if n .sp 1
 
763
.RS
 
764
.PD 0
 
765
.TP
 
766
.B ( \fIexpression\fP )
 
767
Returns the value of \fIexpression\fP.
 
768
This may be used to override the normal precedence of operators.
 
769
.TP
 
770
.B ! \fIexpression\fP
 
771
True if
 
772
.I expression
 
773
is false.
 
774
.TP
 
775
\fIexpression1\fP \fB&&\fP \fIexpression2\fP
 
776
True if both
 
777
.I expression1
 
778
and
 
779
.I expression2
 
780
are true.
 
781
.TP
 
782
\fIexpression1\fP \fB||\fP \fIexpression2\fP
 
783
True if either
 
784
.I expression1
 
785
or
 
786
.I expression2
 
787
is true.
 
788
.PD
 
789
.LP
 
790
The \fB&&\fP and \fB||\fP
 
791
operators do not evaluate \fIexpression2\fP if the value of
 
792
\fIexpression1\fP is sufficient to determine the return value of
 
793
the entire conditional expression.
 
794
.RE
 
795
.TP
 
796
\fBfor\fP \fIname\fP [ [ \fBin\fP [ \fIword ...\fP ] ] ; ] \fBdo\fP \fIlist\fP ; \fBdone\fP
 
797
The list of words following \fBin\fP is expanded, generating a list
 
798
of items.
 
799
The variable \fIname\fP is set to each element of this list
 
800
in turn, and \fIlist\fP is executed each time.
 
801
If the \fBin\fP \fIword\fP is omitted, the \fBfor\fP command executes
 
802
\fIlist\fP once for each positional parameter that is set (see
 
803
.SM
 
804
.B PARAMETERS
 
805
below).
 
806
The return status is the exit status of the last command that executes.
 
807
If the expansion of the items following \fBin\fP results in an empty
 
808
list, no commands are executed, and the return status is 0.
 
809
.TP
 
810
\fBfor\fP (( \fIexpr1\fP ; \fIexpr2\fP ; \fIexpr3\fP )) ; \fBdo\fP \fIlist\fP ; \fBdone\fP
 
811
First, the arithmetic expression \fIexpr1\fP is evaluated according
 
812
to the rules described below under
 
813
.SM
 
814
.BR "ARITHMETIC EVALUATION" .
 
815
The arithmetic expression \fIexpr2\fP is then evaluated repeatedly
 
816
until it evaluates to zero.
 
817
Each time \fIexpr2\fP evaluates to a non-zero value, \fIlist\fP is
 
818
executed and the arithmetic expression \fIexpr3\fP is evaluated.
 
819
If any expression is omitted, it behaves as if it evaluates to 1.
 
820
The return value is the exit status of the last command in \fIlist\fP
 
821
that is executed, or false if any of the expressions is invalid.
 
822
.TP
 
823
\fBselect\fP \fIname\fP [ \fBin\fP \fIword\fP ] ; \fBdo\fP \fIlist\fP ; \fBdone\fP
 
824
The list of words following \fBin\fP is expanded, generating a list
 
825
of items.  The set of expanded words is printed on the standard
 
826
error, each preceded by a number.  If the \fBin\fP
 
827
\fIword\fP is omitted, the positional parameters are printed (see
 
828
.SM
 
829
.B PARAMETERS
 
830
below).  The
 
831
.SM
 
832
.B PS3
 
833
prompt is then displayed and a line read from the standard input.
 
834
If the line consists of a number corresponding to one of
 
835
the displayed words, then the value of
 
836
.I name
 
837
is set to that word.  If the line is empty, the words and prompt
 
838
are displayed again.  If EOF is read, the command completes.  Any
 
839
other value read causes
 
840
.I name
 
841
to be set to null.  The line read is saved in the variable
 
842
.SM
 
843
.BR REPLY .
 
844
The
 
845
.I list
 
846
is executed after each selection until a
 
847
.B break
 
848
command is executed.
 
849
The exit status of
 
850
.B select
 
851
is the exit status of the last command executed in
 
852
.IR list ,
 
853
or zero if no commands were executed.
 
854
.TP
 
855
\fBcase\fP \fIword\fP \fBin\fP [ [(] \fIpattern\fP [ \fB|\fP \fIpattern\fP ] \
 
856
... ) \fIlist\fP ;; ] ... \fBesac\fP
 
857
A \fBcase\fP command first expands \fIword\fP, and tries to match
 
858
it against each \fIpattern\fP in turn, using the same matching rules
 
859
as for pathname expansion (see
 
860
.B Pathname Expansion
 
861
below).
 
862
The \fIword\fP is expanded using tilde
 
863
expansion, parameter and variable expansion, arithmetic substitution,
 
864
command substitution, process substitution and quote removal.
 
865
Each \fIpattern\fP examined is expanded using tilde
 
866
expansion, parameter and variable expansion, arithmetic substitution,
 
867
command substitution, and process substitution.
 
868
If the shell option
 
869
.B nocasematch
 
870
is enabled, the match is performed without regard to the case
 
871
of alphabetic characters.
 
872
When a match is found, the corresponding \fIlist\fP is executed.
 
873
If the \fB;;\fP operator is used, no subsequent matches are attempted after
 
874
the first pattern match.
 
875
Using \fB;&\fP in place of \fB;;\fP causes execution to continue with
 
876
the \fIlist\fP associated with the next set of patterns.
 
877
Using \fB;;&\fP in place of \fB;;\fP causes the shell to test the next
 
878
pattern list in the statement, if any, and execute any associated \fIlist\fP
 
879
on a successful match.
 
880
The exit status is zero if no
 
881
pattern matches.  Otherwise, it is the exit status of the
 
882
last command executed in \fIlist\fP.
 
883
.TP
 
884
\fBif\fP \fIlist\fP; \fBthen\fP \fIlist\fP; \
 
885
[ \fBelif\fP \fIlist\fP; \fBthen\fP \fIlist\fP; ] ... \
 
886
[ \fBelse\fP \fIlist\fP; ] \fBfi\fP
 
887
The
 
888
.B if 
 
889
.I list
 
890
is executed.  If its exit status is zero, the
 
891
\fBthen\fP \fIlist\fP is executed.  Otherwise, each \fBelif\fP
 
892
\fIlist\fP is executed in turn, and if its exit status is zero,
 
893
the corresponding \fBthen\fP \fIlist\fP is executed and the
 
894
command completes.  Otherwise, the \fBelse\fP \fIlist\fP is
 
895
executed, if present.  The exit status is the exit status of the
 
896
last command executed, or zero if no condition tested true.
 
897
.TP
 
898
\fBwhile\fP \fIlist-1\fP; \fBdo\fP \fIlist-2\fP; \fBdone\fP
 
899
.PD 0
 
900
.TP
 
901
\fBuntil\fP \fIlist-1\fP; \fBdo\fP \fIlist-2\fP; \fBdone\fP
 
902
.PD
 
903
The \fBwhile\fP command continuously executes the list
 
904
\fIlist-2\fP as long as the last command in the list \fIlist-1\fP returns
 
905
an exit status of zero.  The \fBuntil\fP command is identical
 
906
to the \fBwhile\fP command, except that the test is negated;
 
907
.I list-2
 
908
is executed as long as the last command in
 
909
.I list-1
 
910
returns a non-zero exit status.
 
911
The exit status of the \fBwhile\fP and \fBuntil\fP commands
 
912
is the exit status
 
913
of the last command executed in \fIlist-2\fP, or zero if
 
914
none was executed.
 
915
.SS Coprocesses
 
916
.PP
 
917
A \fIcoprocess\fP is a shell command preceded by the \fBcoproc\fP reserved
 
918
word.
 
919
A coprocess is executed asynchronously in a subshell, as if the command
 
920
had been terminated with the \fB&\fP control operator, with a two-way pipe
 
921
established between the executing shell and the coprocess.
 
922
.PP
 
923
The format for a coprocess is:
 
924
.RS
 
925
.PP
 
926
\fBcoproc\fP [\fINAME\fP] \fIcommand\fP [\fIredirections\fP]
 
927
.RE
 
928
.PP
 
929
This creates a coprocess named \fINAME\fP.
 
930
If \fINAME\fP is not supplied, the default name is \fBCOPROC\fP.
 
931
\fINAME\fP must not be supplied if \fIcommand\fP is a \fIsimple
 
932
command\fP (see above); otherwise, it is interpreted as the first word
 
933
of the simple command.
 
934
When the coprocess is executed, the shell creates an array variable (see
 
935
.B Arrays
 
936
below) named \fINAME\fP in the context of the executing shell.
 
937
The standard output of
 
938
.I command
 
939
is connected via a pipe to a file descriptor in the executing shell,
 
940
and that file descriptor is assigned to \fINAME\fP[0].
 
941
The standard input of
 
942
.I command
 
943
is connected via a pipe to a file descriptor in the executing shell,
 
944
and that file descriptor is assigned to \fINAME\fP[1].
 
945
This pipe is established before any redirections specified by the
 
946
command (see
 
947
.SM
 
948
.B REDIRECTION
 
949
below).
 
950
The file descriptors can be utilized as arguments to shell commands
 
951
and redirections using standard word expansions.
 
952
The file descriptors are not available in subshells.
 
953
The process ID of the shell spawned to execute the coprocess is
 
954
available as the value of the variable \fINAME\fP_PID.
 
955
The \fBwait\fP
 
956
builtin command may be used to wait for the coprocess to terminate.
 
957
.PP
 
958
Since the coprocess is created as an asynchronous command,
 
959
the \fBcoproc\fP command always returns success.
 
960
The return status of a coprocess is the exit status of \fIcommand\fP.
 
961
.SS Shell Function Definitions
 
962
.PP
 
963
A shell function is an object that is called like a simple command and
 
964
executes a compound command with a new set of positional parameters.
 
965
Shell functions are declared as follows:
 
966
.TP
 
967
\fIname\fP () \fIcompound\-command\fP [\fIredirection\fP]
 
968
.PD 0
 
969
.TP
 
970
\fBfunction\fP \fIname\fP [()] \fIcompound\-command\fP [\fIredirection\fP]
 
971
.PD
 
972
This defines a function named \fIname\fP.
 
973
The reserved word \fBfunction\fP is optional.
 
974
If the \fBfunction\fP reserved word is supplied, the parentheses are optional.
 
975
The \fIbody\fP of the function is the compound command
 
976
.I compound\-command 
 
977
(see \fBCompound Commands\fP above).
 
978
That command is usually a \fIlist\fP of commands between { and }, but
 
979
may be any command listed under \fBCompound Commands\fP above.
 
980
\fIcompound\-command\fP is executed whenever \fIname\fP is specified as the
 
981
name of a simple command.
 
982
When in \fIposix mode\fP, \fIname\fP may not be the name of one of the
 
983
POSIX \fIspecial builtins\fP.
 
984
Any redirections (see
 
985
.SM
 
986
.B REDIRECTION
 
987
below) specified when a function is defined are performed
 
988
when the function is executed.
 
989
The exit status of a function definition is zero unless a syntax error
 
990
occurs or a readonly function with the same name already exists.
 
991
When executed, the exit status of a function is the exit status of the
 
992
last command executed in the body.  (See
 
993
.SM
 
994
.B FUNCTIONS
 
995
below.)
 
996
.SH COMMENTS
 
997
In a non-interactive shell, or an interactive shell in which the
 
998
.B interactive_comments
 
999
option to the
 
1000
.B shopt
 
1001
builtin is enabled (see
 
1002
.SM
 
1003
.B "SHELL BUILTIN COMMANDS"
 
1004
below), a word beginning with
 
1005
.B #
 
1006
causes that word and all remaining characters on that line to
 
1007
be ignored.  An interactive shell without the
 
1008
.B interactive_comments
 
1009
option enabled does not allow comments.  The
 
1010
.B interactive_comments
 
1011
option is on by default in interactive shells.
 
1012
.SH QUOTING
 
1013
\fIQuoting\fP is used to remove the special meaning of certain
 
1014
characters or words to the shell.  Quoting can be used to 
 
1015
disable special treatment for special characters, to prevent
 
1016
reserved words from being recognized as such, and to prevent
 
1017
parameter expansion.
 
1018
.PP
 
1019
Each of the \fImetacharacters\fP listed above under
 
1020
.SM
 
1021
.B DEFINITIONS
 
1022
has special meaning to the shell and must be quoted if it is to
 
1023
represent itself.
 
1024
.PP
 
1025
When the command history expansion facilities are being used
 
1026
(see
 
1027
.SM
 
1028
.B HISTORY EXPANSION
 
1029
below), the
 
1030
\fIhistory expansion\fP character, usually \fB!\fP, must be quoted
 
1031
to prevent history expansion.
 
1032
.PP
 
1033
There are three quoting mechanisms: the
 
1034
.IR "escape character" ,
 
1035
single quotes, and double quotes.
 
1036
.PP
 
1037
A non-quoted backslash (\fB\e\fP) is the
 
1038
.IR "escape character" .
 
1039
It preserves the literal value of the next character that follows,
 
1040
with the exception of <newline>.  If a \fB\e\fP<newline> pair
 
1041
appears, and the backslash is not itself quoted, the \fB\e\fP<newline>
 
1042
is treated as a line continuation (that is, it is removed from the
 
1043
input stream and effectively ignored).
 
1044
.PP
 
1045
Enclosing characters in single quotes preserves the literal value
 
1046
of each character within the quotes.  A single quote may not occur
 
1047
between single quotes, even when preceded by a backslash.
 
1048
.PP
 
1049
Enclosing characters in double quotes preserves the literal value
 
1050
of all characters within the quotes, with the exception of
 
1051
.BR $ ,
 
1052
.BR \` ,
 
1053
.BR \e ,
 
1054
and, when history expansion is enabled,
 
1055
.BR ! .
 
1056
The characters
 
1057
.B $
 
1058
and
 
1059
.B \`
 
1060
retain their special meaning within double quotes.  The backslash
 
1061
retains its special meaning only when followed by one of the following
 
1062
characters:
 
1063
.BR $ ,
 
1064
.BR \` ,
 
1065
\^\fB"\fP\^,
 
1066
.BR \e ,
 
1067
or
 
1068
.BR <newline> .
 
1069
A double quote may be quoted within double quotes by preceding it with
 
1070
a backslash.
 
1071
If enabled, history expansion will be performed unless an
 
1072
.B !
 
1073
appearing in double quotes is escaped using a backslash.
 
1074
The backslash preceding the
 
1075
.B !
 
1076
is not removed.
 
1077
.PP
 
1078
The special parameters
 
1079
.B *
 
1080
and
 
1081
.B @
 
1082
have special meaning when in double
 
1083
quotes (see
 
1084
.SM
 
1085
.B PARAMETERS
 
1086
below).
 
1087
.PP
 
1088
Words of the form \fB$\fP\(aq\fIstring\fP\(aq are treated specially.  The
 
1089
word expands to \fIstring\fP, with backslash-escaped characters replaced
 
1090
as specified by the ANSI C standard.  Backslash escape sequences, if
 
1091
present, are decoded as follows:
 
1092
.RS
 
1093
.PD 0
 
1094
.TP
 
1095
.B \ea
 
1096
alert (bell)
 
1097
.TP
 
1098
.B \eb
 
1099
backspace
 
1100
.TP
 
1101
.B \ee
 
1102
.TP
 
1103
.B \eE
 
1104
an escape character
 
1105
.TP   
 
1106
.B \ef
 
1107
form feed
 
1108
.TP  
 
1109
.B \en
 
1110
new line
 
1111
.TP     
 
1112
.B \er
 
1113
carriage return
 
1114
.TP
 
1115
.B \et
 
1116
horizontal tab
 
1117
.TP   
 
1118
.B \ev
 
1119
vertical tab
 
1120
.TP
 
1121
.B \e\e
 
1122
backslash
 
1123
.TP
 
1124
.B \e\(aq
 
1125
single quote
 
1126
.TP
 
1127
.B \e\(dq
 
1128
double quote
 
1129
.TP   
 
1130
.B \e\fInnn\fP
 
1131
the eight-bit character whose value is the octal value \fInnn\fP
 
1132
(one to three digits)
 
1133
.TP
 
1134
.B \ex\fIHH\fP
 
1135
the eight-bit character whose value is the hexadecimal value \fIHH\fP
 
1136
(one or two hex digits)
 
1137
.TP
 
1138
.B \eu\fIHHHH\fP
 
1139
the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
 
1140
\fIHHHH\fP (one to four hex digits)
 
1141
.TP
 
1142
.B \eU\fIHHHHHHHH\fP
 
1143
the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
 
1144
\fIHHHHHHHH\fP (one to eight hex digits)
 
1145
.TP
 
1146
.B \ec\fIx\fP
 
1147
a control-\fIx\fP character
 
1148
.PD
 
1149
.RE
 
1150
.LP
 
1151
The expanded result is single-quoted, as if the dollar sign had
 
1152
not been present.
 
1153
.PP
 
1154
A double-quoted string preceded by a dollar sign (\fB$\fP\(dq\fIstring\fP\(dq)
 
1155
will cause the string to be translated according to the current locale.
 
1156
If the current locale is \fBC\fP or \fBPOSIX\fP, the dollar sign
 
1157
is ignored.
 
1158
If the string is translated and replaced, the replacement is
 
1159
double-quoted.
 
1160
.SH PARAMETERS
 
1161
A
 
1162
.I parameter
 
1163
is an entity that stores values.
 
1164
It can be a
 
1165
.IR name ,
 
1166
a number, or one of the special characters listed below under
 
1167
.BR "Special Parameters" .
 
1168
A
 
1169
.I variable
 
1170
is a parameter denoted by a
 
1171
.IR name .
 
1172
A variable has a \fIvalue\fP and zero or more \fIattributes\fP.
 
1173
Attributes are assigned using the
 
1174
.B declare
 
1175
builtin command (see
 
1176
.B declare
 
1177
below in
 
1178
.SM
 
1179
.BR "SHELL BUILTIN COMMANDS" ).
 
1180
.PP
 
1181
A parameter is set if it has been assigned a value.  The null string is
 
1182
a valid value.  Once a variable is set, it may be unset only by using
 
1183
the
 
1184
.B unset
 
1185
builtin command (see
 
1186
.SM
 
1187
.B SHELL BUILTIN COMMANDS
 
1188
below).
 
1189
.PP
 
1190
A
 
1191
.I variable
 
1192
may be assigned to by a statement of the form
 
1193
.RS
 
1194
.PP
 
1195
\fIname\fP=[\fIvalue\fP]
 
1196
.RE
 
1197
.PP
 
1198
If
 
1199
.I value
 
1200
is not given, the variable is assigned the null string.  All
 
1201
.I values
 
1202
undergo tilde expansion, parameter and variable expansion,
 
1203
command substitution, arithmetic expansion, and quote
 
1204
removal (see
 
1205
.SM
 
1206
.B EXPANSION
 
1207
below).  If the variable has its
 
1208
.B integer
 
1209
attribute set, then
 
1210
.I value
 
1211
is evaluated as an arithmetic expression even if the $((...)) expansion is
 
1212
not used (see
 
1213
.B "Arithmetic Expansion"
 
1214
below).
 
1215
Word splitting is not performed, with the exception
 
1216
of \fB"$@"\fP as explained below under
 
1217
.BR "Special Parameters" .
 
1218
Pathname expansion is not performed.
 
1219
Assignment statements may also appear as arguments to the
 
1220
.BR alias ,
 
1221
.BR declare ,
 
1222
.BR typeset ,
 
1223
.BR export ,
 
1224
.BR readonly ,
 
1225
and
 
1226
.B local
 
1227
builtin commands.
 
1228
When in \fIposix mode\fP, these builtins may appear in a command after
 
1229
one or more instances of the \fBcommand\fP builtin and retain these
 
1230
assignment statement properties.
 
1231
.PP
 
1232
In the context where an assignment statement is assigning a value
 
1233
to a shell variable or array index, the += operator can be used to
 
1234
append to or add to the variable's previous value.
 
1235
When += is applied to a variable for which the \fIinteger\fP attribute has been
 
1236
set, \fIvalue\fP is evaluated as an arithmetic expression and added to the
 
1237
variable's current value, which is also evaluated.
 
1238
When += is applied to an array variable using compound assignment (see
 
1239
.B Arrays
 
1240
below), the
 
1241
variable's value is not unset (as it is when using =), and new values are
 
1242
appended to the array beginning at one greater than the array's maximum index
 
1243
(for indexed arrays) or added as additional key\-value pairs in an
 
1244
associative array.
 
1245
When applied to a string-valued variable, \fIvalue\fP is expanded and
 
1246
appended to the variable's value.
 
1247
.PP
 
1248
A variable can be assigned the \fInameref\fP attribute using the
 
1249
\fB\-n\fP option to the \fBdeclare\fP or \fBlocal\fP builtin commands
 
1250
(see the descriptions of \fBdeclare\fP and \fBlocal\fP below)
 
1251
to create a \fInameref\fP, or a reference to another variable.
 
1252
This allows variables to be manipulated indirectly.
 
1253
Whenever the nameref variable is referenced or assigned to, the operation
 
1254
is actually performed on the variable specified by the nameref variable's
 
1255
value.
 
1256
A nameref is commonly used within shell functions to refer to a variable
 
1257
whose name is passed as an argument to the function.
 
1258
For instance, if a variable name is passed to a shell function as its first
 
1259
argument, running
 
1260
.sp .5
 
1261
.RS
 
1262
.if t \f(CWdeclare -n ref=$1\fP
 
1263
.if n declare -n ref=$1
 
1264
.RE
 
1265
.sp .5
 
1266
inside the function creates a nameref variable \fBref\fP whose value is
 
1267
the variable name passed as the first argument.
 
1268
References and assignments to \fBref\fP are treated as references and
 
1269
assignments to the variable whose name was passed as \fB$1\fP.
 
1270
If the control variable in a \fBfor\fP loop has the nameref attribute,
 
1271
the list of words can be a list of shell variables, and a name reference
 
1272
will be established for each word in the list, in turn, when the loop is
 
1273
executed.
 
1274
Array variables cannot be given the \fB\-n\fP attribute.
 
1275
However, nameref variables can reference array variables and subscripted
 
1276
array variables.
 
1277
Namerefs can be unset using the \fB\-n\fP option to the \fBunset\fP builtin.
 
1278
Otherwise, if \fBunset\fP is executed with the name of a nameref variable
 
1279
as an argument, the variable referenced by the nameref variable will be unset.
 
1280
.SS Positional Parameters
 
1281
.PP
 
1282
A
 
1283
.I positional parameter
 
1284
is a parameter denoted by one or more
 
1285
digits, other than the single digit 0.  Positional parameters are
 
1286
assigned from the shell's arguments when it is invoked,
 
1287
and may be reassigned using the
 
1288
.B set
 
1289
builtin command.  Positional parameters may not be assigned to
 
1290
with assignment statements.  The positional parameters are
 
1291
temporarily replaced when a shell function is executed (see
 
1292
.SM
 
1293
.B FUNCTIONS
 
1294
below).
 
1295
.PP
 
1296
When a positional parameter consisting of more than a single
 
1297
digit is expanded, it must be enclosed in braces (see
 
1298
.SM
 
1299
.B EXPANSION
 
1300
below).
 
1301
.SS Special Parameters
 
1302
.PP
 
1303
The shell treats several parameters specially.  These parameters may
 
1304
only be referenced; assignment to them is not allowed.
 
1305
.PD 0
 
1306
.TP
 
1307
.B *
 
1308
Expands to the positional parameters, starting from one.
 
1309
When the expansion is not within double quotes, each positional parameter
 
1310
expands to a separate word.
 
1311
In contexts where it is performed, those words
 
1312
are subject to further word splitting and pathname expansion.
 
1313
When the expansion occurs within double quotes, it expands to a single word
 
1314
with the value of each parameter separated by the first character
 
1315
of the 
 
1316
.SM
 
1317
.B IFS
 
1318
special variable.  That is, "\fB$*\fP" is equivalent
 
1319
to "\fB$1\fP\fIc\fP\fB$2\fP\fIc\fP\fB...\fP", where
 
1320
.I c
 
1321
is the first character of the value of the
 
1322
.SM
 
1323
.B IFS
 
1324
variable.  If
 
1325
.SM
 
1326
.B IFS
 
1327
is unset, the parameters are separated by spaces.
 
1328
If
 
1329
.SM
 
1330
.B IFS
 
1331
is null, the parameters are joined without intervening separators.
 
1332
.TP
 
1333
.B @
 
1334
Expands to the positional parameters, starting from one.  When the
 
1335
expansion occurs within double quotes, each parameter expands to a
 
1336
separate word.  That is, "\fB$@\fP" is equivalent to
 
1337
"\fB$1\fP" "\fB$2\fP" ...
 
1338
If the double-quoted expansion occurs within a word, the expansion of
 
1339
the first parameter is joined with the beginning part of the original
 
1340
word, and the expansion of the last parameter is joined with the last
 
1341
part of the original word.
 
1342
When there are no positional parameters, "\fB$@\fP" and 
 
1343
.B $@
 
1344
expand to nothing (i.e., they are removed).
 
1345
.TP
 
1346
.B #
 
1347
Expands to the number of positional parameters in decimal.
 
1348
.TP
 
1349
.B ?
 
1350
Expands to the exit status of the most recently executed foreground
 
1351
pipeline.
 
1352
.TP
 
1353
.B \-
 
1354
Expands to the current option flags as specified upon invocation, 
 
1355
by the
 
1356
.B set
 
1357
builtin command, or those set by the shell itself
 
1358
(such as the
 
1359
.B \-i
 
1360
option).
 
1361
.TP
 
1362
.B $
 
1363
Expands to the process ID of the shell.  In a () subshell, it
 
1364
expands to the process ID of the current shell, not the
 
1365
subshell.
 
1366
.TP
 
1367
.B !
 
1368
Expands to the process ID of the job most recently placed into the
 
1369
background, whether executed as an asynchronous command or using
 
1370
the \fBbg\fP builtin (see
 
1371
.SM
 
1372
.B "JOB CONTROL"
 
1373
below).
 
1374
.TP
 
1375
.B 0
 
1376
Expands to the name of the shell or shell script.  This is set at
 
1377
shell initialization.  If
 
1378
.B bash
 
1379
is invoked with a file of commands,
 
1380
.B $0
 
1381
is set to the name of that file.  If
 
1382
.B bash
 
1383
is started with the
 
1384
.B \-c
 
1385
option, then
 
1386
.B $0
 
1387
is set to the first argument after the string to be
 
1388
executed, if one is present.  Otherwise, it is set
 
1389
to the filename used to invoke
 
1390
.BR bash ,
 
1391
as given by argument zero.
 
1392
.TP
 
1393
.B _
 
1394
At shell startup, set to the absolute pathname used to invoke the
 
1395
shell or shell script being executed as passed in the environment
 
1396
or argument list.
 
1397
Subsequently, expands to the last argument to the previous command,
 
1398
after expansion.
 
1399
Also set to the full pathname used to invoke each command executed
 
1400
and placed in the environment exported to that command.
 
1401
When checking mail, this parameter holds the name of the mail file
 
1402
currently being checked.
 
1403
.PD
 
1404
.SS Shell Variables
 
1405
.PP
 
1406
The following variables are set by the shell:
 
1407
.PP
 
1408
.PD 0
 
1409
.TP
 
1410
.B BASH
 
1411
Expands to the full filename used to invoke this instance of
 
1412
.BR bash .
 
1413
.TP
 
1414
.B BASHOPTS
 
1415
A colon-separated list of enabled shell options.  Each word in
 
1416
the list is a valid argument for the
 
1417
.B \-s
 
1418
option to the
 
1419
.B shopt
 
1420
builtin command (see
 
1421
.SM
 
1422
.B "SHELL BUILTIN COMMANDS"
 
1423
below).  The options appearing in
 
1424
.SM
 
1425
.B BASHOPTS
 
1426
are those reported as
 
1427
.I on
 
1428
by \fBshopt\fP.
 
1429
If this variable is in the environment when
 
1430
.B bash
 
1431
starts up, each shell option in the list will be enabled before
 
1432
reading any startup files.
 
1433
This variable is read-only.
 
1434
.TP
 
1435
.B BASHPID
 
1436
Expands to the process ID of the current \fBbash\fP process.
 
1437
This differs from \fB$$\fP under certain circumstances, such as subshells
 
1438
that do not require \fBbash\fP to be re-initialized.
 
1439
.TP
 
1440
.B BASH_ALIASES
 
1441
An associative array variable whose members correspond to the internal
 
1442
list of aliases as maintained by the \fBalias\fP builtin.
 
1443
Elements added to this array appear in the alias list; unsetting array
 
1444
elements cause aliases to be removed from the alias list.
 
1445
.TP
 
1446
.B BASH_ARGC
 
1447
An array variable whose values are the number of parameters in each
 
1448
frame of the current \fBbash\fP execution call stack.
 
1449
The number of
 
1450
parameters to the current subroutine (shell function or script executed
 
1451
with \fB.\fP or \fBsource\fP) is at the top of the stack.
 
1452
When a subroutine is executed, the number of parameters passed is pushed onto
 
1453
.SM
 
1454
.BR BASH_ARGC .
 
1455
The shell sets
 
1456
.SM
 
1457
.B BASH_ARGC
 
1458
only when in extended debugging mode (see the description of the
 
1459
.B extdebug
 
1460
option to the
 
1461
.B shopt
 
1462
builtin below)
 
1463
.TP
 
1464
.B BASH_ARGV
 
1465
An array variable containing all of the parameters in the current \fBbash\fP
 
1466
execution call stack.  The final parameter of the last subroutine call
 
1467
is at the top of the stack; the first parameter of the initial call is
 
1468
at the bottom.  When a subroutine is executed, the parameters supplied
 
1469
are pushed onto
 
1470
.SM
 
1471
.BR BASH_ARGV .
 
1472
The shell sets
 
1473
.SM
 
1474
.B BASH_ARGV
 
1475
only when in extended debugging mode
 
1476
(see the description of the
 
1477
.B extdebug
 
1478
option to the
 
1479
.B shopt
 
1480
builtin below)
 
1481
.TP
 
1482
.B BASH_CMDS
 
1483
An associative array variable whose members correspond to the internal
 
1484
hash table of commands as maintained by the \fBhash\fP builtin.
 
1485
Elements added to this array appear in the hash table; unsetting array
 
1486
elements cause commands to be removed from the hash table.
 
1487
.TP
 
1488
.B BASH_COMMAND
 
1489
The command currently being executed or about to be executed, unless the
 
1490
shell is executing a command as the result of a trap,
 
1491
in which case it is the command executing at the time of the trap.
 
1492
.TP
 
1493
.B BASH_EXECUTION_STRING
 
1494
The command argument to the \fB\-c\fP invocation option.
 
1495
.TP
 
1496
.B BASH_LINENO
 
1497
An array variable whose members are the line numbers in source files
 
1498
where each corresponding member of
 
1499
.SM
 
1500
.B FUNCNAME
 
1501
was invoked.
 
1502
\fB${BASH_LINENO[\fP\fI$i\fP\fB]}\fP is the line number in the source
 
1503
file (\fB${BASH_SOURCE[\fP\fI$i+1\fP\fB]}\fP) where
 
1504
\fB${FUNCNAME[\fP\fI$i\fP\fB]}\fP was called
 
1505
(or \fB${BASH_LINENO[\fP\fI$i-1\fP\fB]}\fP if referenced within another
 
1506
shell function).
 
1507
Use
 
1508
.SM
 
1509
.B LINENO
 
1510
to obtain the current line number.
 
1511
.TP
 
1512
.B BASH_REMATCH
 
1513
An array variable whose members are assigned by the \fB=~\fP binary
 
1514
operator to the \fB[[\fP conditional command.
 
1515
The element with index 0 is the portion of the string
 
1516
matching the entire regular expression.
 
1517
The element with index \fIn\fP is the portion of the
 
1518
string matching the \fIn\fPth parenthesized subexpression.
 
1519
This variable is read-only.
 
1520
.TP
 
1521
.B BASH_SOURCE
 
1522
An array variable whose members are the source filenames
 
1523
where the corresponding shell function names in the
 
1524
.SM
 
1525
.B FUNCNAME
 
1526
array variable are defined.
 
1527
The shell function
 
1528
\fB${FUNCNAME[\fP\fI$i\fP\fB]}\fP is defined in the file
 
1529
\fB${BASH_SOURCE[\fP\fI$i\fP\fB]}\fP and called from
 
1530
\fB${BASH_SOURCE[\fP\fI$i+1\fP\fB]}\fP.
 
1531
.TP
 
1532
.B BASH_SUBSHELL
 
1533
Incremented by one within each subshell or subshell environment when
 
1534
the shell begins executing in that environment.
 
1535
The initial value is 0.
 
1536
.TP
 
1537
.B BASH_VERSINFO
 
1538
A readonly array variable whose members hold version information for
 
1539
this instance of
 
1540
.BR bash .
 
1541
The values assigned to the array members are as follows:
 
1542
.sp .5
 
1543
.RS
 
1544
.TP 24
 
1545
.B BASH_VERSINFO[\fR0\fP]
 
1546
The major version number (the \fIrelease\fP).
 
1547
.TP
 
1548
.B BASH_VERSINFO[\fR1\fP]
 
1549
The minor version number (the \fIversion\fP).
 
1550
.TP
 
1551
.B BASH_VERSINFO[\fR2\fP]
 
1552
The patch level.
 
1553
.TP
 
1554
.B BASH_VERSINFO[\fR3\fP]
 
1555
The build version.
 
1556
.TP
 
1557
.B BASH_VERSINFO[\fR4\fP]
 
1558
The release status (e.g., \fIbeta1\fP).
 
1559
.TP
 
1560
.B BASH_VERSINFO[\fR5\fP]
 
1561
The value of
 
1562
.SM
 
1563
.BR MACHTYPE .
 
1564
.RE
 
1565
.TP
 
1566
.B BASH_VERSION
 
1567
Expands to a string describing the version of this instance of
 
1568
.BR bash .
 
1569
.TP
 
1570
.B COMP_CWORD
 
1571
An index into \fB${COMP_WORDS}\fP of the word containing the current
 
1572
cursor position.
 
1573
This variable is available only in shell functions invoked by the
 
1574
programmable completion facilities (see \fBProgrammable Completion\fP
 
1575
below).
 
1576
.TP
 
1577
.B COMP_KEY
 
1578
The key (or final key of a key sequence) used to invoke the current
 
1579
completion function.
 
1580
.TP
 
1581
.B COMP_LINE
 
1582
The current command line.
 
1583
This variable is available only in shell functions and external
 
1584
commands invoked by the
 
1585
programmable completion facilities (see \fBProgrammable Completion\fP
 
1586
below).
 
1587
.TP
 
1588
.B COMP_POINT
 
1589
The index of the current cursor position relative to the beginning of
 
1590
the current command.
 
1591
If the current cursor position is at the end of the current command,
 
1592
the value of this variable is equal to \fB${#COMP_LINE}\fP.
 
1593
This variable is available only in shell functions and external
 
1594
commands invoked by the
 
1595
programmable completion facilities (see \fBProgrammable Completion\fP
 
1596
below).
 
1597
.TP
 
1598
.B COMP_TYPE
 
1599
Set to an integer value corresponding to the type of completion attempted
 
1600
that caused a completion function to be called:
 
1601
\fITAB\fP, for normal completion,
 
1602
\fI?\fP, for listing completions after successive tabs,
 
1603
\fI!\fP, for listing alternatives on partial word completion,
 
1604
\fI@\fP, to list completions if the word is not unmodified,
 
1605
or
 
1606
\fI%\fP, for menu completion.
 
1607
This variable is available only in shell functions and external
 
1608
commands invoked by the
 
1609
programmable completion facilities (see \fBProgrammable Completion\fP
 
1610
below).
 
1611
.TP
 
1612
.B COMP_WORDBREAKS
 
1613
The set of characters that the \fBreadline\fP library treats as word
 
1614
separators when performing word completion.
 
1615
If
 
1616
.SM
 
1617
.B COMP_WORDBREAKS
 
1618
is unset, it loses its special properties, even if it is
 
1619
subsequently reset.
 
1620
.TP
 
1621
.B COMP_WORDS
 
1622
An array variable (see \fBArrays\fP below) consisting of the individual
 
1623
words in the current command line.
 
1624
The line is split into words as \fBreadline\fP would split it, using
 
1625
.SM
 
1626
.B COMP_WORDBREAKS
 
1627
as described above.
 
1628
This variable is available only in shell functions invoked by the
 
1629
programmable completion facilities (see \fBProgrammable Completion\fP
 
1630
below).
 
1631
.TP
 
1632
.B COPROC
 
1633
An array variable (see \fBArrays\fP below) created to hold the file descriptors
 
1634
for output from and input to an unnamed coprocess (see \fBCoprocesses\fP
 
1635
above).
 
1636
.TP
 
1637
.B DIRSTACK
 
1638
An array variable (see
 
1639
.B Arrays
 
1640
below) containing the current contents of the directory stack.
 
1641
Directories appear in the stack in the order they are displayed by the
 
1642
.B dirs
 
1643
builtin.
 
1644
Assigning to members of this array variable may be used to modify
 
1645
directories already in the stack, but the
 
1646
.B pushd
 
1647
and
 
1648
.B popd
 
1649
builtins must be used to add and remove directories.
 
1650
Assignment to this variable will not change the current directory.
 
1651
If
 
1652
.SM
 
1653
.B DIRSTACK
 
1654
is unset, it loses its special properties, even if it is
 
1655
subsequently reset.
 
1656
.TP
 
1657
.B EUID
 
1658
Expands to the effective user ID of the current user, initialized at
 
1659
shell startup.  This variable is readonly.
 
1660
.TP
 
1661
.B FUNCNAME
 
1662
An array variable containing the names of all shell functions
 
1663
currently in the execution call stack.
 
1664
The element with index 0 is the name of any currently-executing
 
1665
shell function.
 
1666
The bottom-most element (the one with the highest index) is
 
1667
.if t \f(CW"main"\fP.
 
1668
.if n "main".
 
1669
This variable exists only when a shell function is executing.
 
1670
Assignments to
 
1671
.SM
 
1672
.B FUNCNAME
 
1673
have no effect and return an error status.
 
1674
If
 
1675
.SM
 
1676
.B FUNCNAME
 
1677
is unset, it loses its special properties, even if it is
 
1678
subsequently reset.
 
1679
.if t .sp 0.5
 
1680
.if n .sp 1
 
1681
This variable can be used with \fBBASH_LINENO\fP and \fBBASH_SOURCE\fP.
 
1682
Each element of \fBFUNCNAME\fP has corresponding elements in
 
1683
\fBBASH_LINENO\fP and \fBBASH_SOURCE\fP to describe the call stack.
 
1684
For instance, \fB${FUNCNAME[\fP\fI$i\fP\fB]}\fP was called from the file
 
1685
\fB${BASH_SOURCE[\fP\fI$i+1\fP\fB]}\fP at line number
 
1686
\fB${BASH_LINENO[\fP\fI$i\fP\fB]}\fP.
 
1687
The \fBcaller\fP builtin displays the current call stack using this
 
1688
information.
 
1689
.TP
 
1690
.B GROUPS
 
1691
An array variable containing the list of groups of which the current
 
1692
user is a member.
 
1693
Assignments to    
 
1694
.SM
 
1695
.B GROUPS
 
1696
have no effect and return an error status.
 
1697
If
 
1698
.SM
 
1699
.B GROUPS
 
1700
is unset, it loses its special properties, even if it is
 
1701
subsequently reset.
 
1702
.TP
 
1703
.B HISTCMD
 
1704
The history number, or index in the history list, of the current
 
1705
command.
 
1706
If
 
1707
.SM
 
1708
.B HISTCMD
 
1709
is unset, it loses its special properties, even if it is
 
1710
subsequently reset.
 
1711
.TP
 
1712
.B HOSTNAME
 
1713
Automatically set to the name of the current host.
 
1714
.TP
 
1715
.B HOSTTYPE
 
1716
Automatically set to a string that uniquely
 
1717
describes the type of machine on which
 
1718
.B bash
 
1719
is executing.
 
1720
The default is system-dependent.
 
1721
.TP
 
1722
.B LINENO
 
1723
Each time this parameter is referenced, the shell substitutes
 
1724
a decimal number representing the current sequential line number
 
1725
(starting with 1) within a script or function.  When not in a
 
1726
script or function, the value substituted is not guaranteed to
 
1727
be meaningful.
 
1728
If
 
1729
.SM
 
1730
.B LINENO
 
1731
is unset, it loses its special properties, even if it is
 
1732
subsequently reset.
 
1733
.TP
 
1734
.B MACHTYPE
 
1735
Automatically set to a string that fully describes the system
 
1736
type on which
 
1737
.B bash
 
1738
is executing, in the standard GNU \fIcpu-company-system\fP format.
 
1739
The default is system-dependent.
 
1740
.TP
 
1741
.B MAPFILE
 
1742
An array variable (see \fBArrays\fP below) created to hold the text
 
1743
read by the \fBmapfile\fP builtin when no variable name is supplied.
 
1744
.TP
 
1745
.B OLDPWD
 
1746
The previous working directory as set by the
 
1747
.B cd
 
1748
command.
 
1749
.TP
 
1750
.B OPTARG
 
1751
The value of the last option argument processed by the
 
1752
.B getopts
 
1753
builtin command (see
 
1754
.SM
 
1755
.B SHELL BUILTIN COMMANDS
 
1756
below).
 
1757
.TP
 
1758
.B OPTIND
 
1759
The index of the next argument to be processed by the
 
1760
.B getopts
 
1761
builtin command (see
 
1762
.SM
 
1763
.B SHELL BUILTIN COMMANDS
 
1764
below).
 
1765
.TP
 
1766
.B OSTYPE
 
1767
Automatically set to a string that
 
1768
describes the operating system on which
 
1769
.B bash
 
1770
is executing.
 
1771
The default is system-dependent.
 
1772
.TP
 
1773
.B PIPESTATUS
 
1774
An array variable (see
 
1775
.B Arrays
 
1776
below) containing a list of exit status values from the processes
 
1777
in the most-recently-executed foreground pipeline (which may
 
1778
contain only a single command).
 
1779
.TP
 
1780
.B PPID
 
1781
The process ID of the shell's parent.  This variable is readonly.
 
1782
.TP
 
1783
.B PWD
 
1784
The current working directory as set by the
 
1785
.B cd
 
1786
command.
 
1787
.TP
 
1788
.B RANDOM
 
1789
Each time this parameter is referenced, a random integer between
 
1790
0 and 32767 is
 
1791
generated.  The sequence of random numbers may be initialized by assigning
 
1792
a value to
 
1793
.SM
 
1794
.BR RANDOM .
 
1795
If
 
1796
.SM
 
1797
.B RANDOM
 
1798
is unset, it loses its special properties, even if it is
 
1799
subsequently reset.
 
1800
.TP
 
1801
.B READLINE_LINE
 
1802
The contents of the
 
1803
.B readline
 
1804
line buffer, for use with
 
1805
.if t \f(CWbind -x\fP
 
1806
.if n "bind -x"
 
1807
(see
 
1808
.SM
 
1809
.B "SHELL BUILTIN COMMANDS"
 
1810
below).
 
1811
.TP
 
1812
.B READLINE_POINT
 
1813
The position of the insertion point in the
 
1814
.B readline
 
1815
line buffer, for use with
 
1816
.if t \f(CWbind -x\fP
 
1817
.if n "bind -x"
 
1818
(see
 
1819
.SM
 
1820
.B "SHELL BUILTIN COMMANDS"
 
1821
below).
 
1822
.TP
 
1823
.B REPLY
 
1824
Set to the line of input read by the
 
1825
.B read
 
1826
builtin command when no arguments are supplied.
 
1827
.TP
 
1828
.B SECONDS
 
1829
Each time this parameter is
 
1830
referenced, the number of seconds since shell invocation is returned.  If a
 
1831
value is assigned to 
 
1832
.SM
 
1833
.BR SECONDS ,
 
1834
the value returned upon subsequent
 
1835
references is
 
1836
the number of seconds since the assignment plus the value assigned.
 
1837
If
 
1838
.SM
 
1839
.B SECONDS
 
1840
is unset, it loses its special properties, even if it is
 
1841
subsequently reset.
 
1842
.TP
 
1843
.B SHELLOPTS
 
1844
A colon-separated list of enabled shell options.  Each word in
 
1845
the list is a valid argument for the
 
1846
.B \-o
 
1847
option to the
 
1848
.B set
 
1849
builtin command (see
 
1850
.SM
 
1851
.B "SHELL BUILTIN COMMANDS"
 
1852
below).  The options appearing in
 
1853
.SM
 
1854
.B SHELLOPTS
 
1855
are those reported as
 
1856
.I on
 
1857
by \fBset \-o\fP.
 
1858
If this variable is in the environment when
 
1859
.B bash
 
1860
starts up, each shell option in the list will be enabled before
 
1861
reading any startup files.
 
1862
This variable is read-only.
 
1863
.TP
 
1864
.B SHLVL
 
1865
Incremented by one each time an instance of
 
1866
.B bash
 
1867
is started.
 
1868
.TP
 
1869
.B UID
 
1870
Expands to the user ID of the current user, initialized at shell startup.
 
1871
This variable is readonly.
 
1872
.PD
 
1873
.PP
 
1874
The following variables are used by the shell.  In some cases,
 
1875
.B bash
 
1876
assigns a default value to a variable; these cases are noted
 
1877
below.
 
1878
.PP
 
1879
.PD 0
 
1880
.TP
 
1881
.B BASH_COMPAT
 
1882
The value is used to set the shell's compatibility level.
 
1883
See the description of the \fBshopt\fP builtin below under
 
1884
\fBSHELL BUILTIN COMMANDS\fP
 
1885
for a description of the various compatibility
 
1886
levels and their effects.
 
1887
The value may be a decimal number (e.g., 4.2) or an integer (e.g., 42)
 
1888
corresponding to the desired compatibility level.
 
1889
If \fBBASH_COMPAT\fP is unset or set to the empty string, the compatibility
 
1890
level is set to the default for the current version.
 
1891
If \fBBASH_COMPAT\fP is set to a value that is not one of the valid
 
1892
compatibility levels, the shell prints an error message and sets the
 
1893
compatibility level to the default for the current version.
 
1894
The valid compatibility levels correspond to the compatibility options
 
1895
accepted by the \fBshopt\fP builtin described below (for example,
 
1896
\fBcompat42\fP means that 4.2 and 42 are valid values).
 
1897
The current version is also a valid value.
 
1898
.TP
 
1899
.B BASH_ENV
 
1900
If this parameter is set when \fBbash\fP is executing a shell script,
 
1901
its value is interpreted as a filename containing commands to
 
1902
initialize the shell, as in
 
1903
.IR ~/.bashrc .
 
1904
The value of
 
1905
.SM
 
1906
.B BASH_ENV
 
1907
is subjected to parameter expansion, command substitution, and arithmetic
 
1908
expansion before being interpreted as a filename.
 
1909
.SM
 
1910
.B PATH
 
1911
is not used to search for the resultant filename.
 
1912
.TP
 
1913
.B BASH_XTRACEFD
 
1914
If set to an integer corresponding to a valid file descriptor, \fBbash\fP
 
1915
will write the trace output generated when
 
1916
.if t \f(CWset -x\fP
 
1917
.if n \fIset -x\fP
 
1918
is enabled to that file descriptor.
 
1919
The file descriptor is closed when
 
1920
.SM
 
1921
.B BASH_XTRACEFD
 
1922
is unset or assigned a new value.
 
1923
Unsetting
 
1924
.SM
 
1925
.B BASH_XTRACEFD
 
1926
or assigning it the empty string causes the
 
1927
trace output to be sent to the standard error.
 
1928
Note that setting
 
1929
.SM
 
1930
.B BASH_XTRACEFD
 
1931
to 2 (the standard error file
 
1932
descriptor) and then unsetting it will result in the standard error
 
1933
being closed.
 
1934
.TP
 
1935
.B CDPATH
 
1936
The search path for the
 
1937
.B cd
 
1938
command.
 
1939
This is a colon-separated list of directories in which the shell looks
 
1940
for destination directories specified by the
 
1941
.B cd
 
1942
command.
 
1943
A sample value is
 
1944
.if t \f(CW".:~:/usr"\fP.
 
1945
.if n ".:~:/usr".
 
1946
.TP
 
1947
.B CHILD_MAX
 
1948
Set the number of exited child status values for the shell to remember.
 
1949
Bash will not allow this value to be decreased below a POSIX-mandated
 
1950
minimum, and there is a maximum value (currently 8192) that this may
 
1951
not exceed.
 
1952
The minimum value is system-dependent.
 
1953
.TP
 
1954
.B COLUMNS
 
1955
Used by the \fBselect\fP compound command to determine the terminal width
 
1956
when printing selection lists.
 
1957
Automatically set if the
 
1958
.B checkwinsize
 
1959
option is enabled or in an interactive shell upon receipt of a
 
1960
.SM
 
1961
.BR SIGWINCH .
 
1962
.TP
 
1963
.B COMPREPLY
 
1964
An array variable from which \fBbash\fP reads the possible completions
 
1965
generated by a shell function invoked by the programmable completion
 
1966
facility (see \fBProgrammable Completion\fP below).
 
1967
Each array element contains one possible completion.
 
1968
.TP
 
1969
.B EMACS
 
1970
If \fBbash\fP finds this variable in the environment when the shell starts
 
1971
with value
 
1972
.if t \f(CWt\fP,
 
1973
.if n "t",
 
1974
it assumes that the shell is running in an Emacs shell buffer and disables
 
1975
line editing.
 
1976
.TP
 
1977
.B ENV
 
1978
Similar to
 
1979
.SM
 
1980
.BR BASH_ENV ;
 
1981
used when the shell is invoked in POSIX mode.
 
1982
.TP
 
1983
.B FCEDIT
 
1984
The default editor for the
 
1985
.B fc
 
1986
builtin command.
 
1987
.TP
 
1988
.B FIGNORE
 
1989
A colon-separated list of suffixes to ignore when performing
 
1990
filename completion (see
 
1991
.SM
 
1992
.B READLINE
 
1993
below).
 
1994
A filename whose suffix matches one of the entries in 
 
1995
.SM
 
1996
.B FIGNORE
 
1997
is excluded from the list of matched filenames.
 
1998
A sample value is
 
1999
.if t \f(CW".o:~"\fP.
 
2000
.if n ".o:~"
 
2001
(Quoting is needed when assigning a value to this variable,
 
2002
which contains tildes).
 
2003
.TP
 
2004
.B FUNCNEST
 
2005
If set to a numeric value greater than 0, defines a maximum function
 
2006
nesting level.  Function invocations that exceed this nesting level
 
2007
will cause the current command to abort.
 
2008
.TP
 
2009
.B GLOBIGNORE
 
2010
A colon-separated list of patterns defining the set of filenames to
 
2011
be ignored by pathname expansion.
 
2012
If a filename matched by a pathname expansion pattern also matches one
 
2013
of the patterns in
 
2014
.SM
 
2015
.BR GLOBIGNORE ,
 
2016
it is removed from the list of matches.
 
2017
.TP
 
2018
.B HISTCONTROL
 
2019
A colon-separated list of values controlling how commands are saved on
 
2020
the history list.
 
2021
If the list of values includes
 
2022
.IR ignorespace ,
 
2023
lines which begin with a
 
2024
.B space
 
2025
character are not saved in the history list.
 
2026
A value of 
 
2027
.I ignoredups
 
2028
causes lines matching the previous history entry to not be saved.
 
2029
A value of
 
2030
.I ignoreboth
 
2031
is shorthand for \fIignorespace\fP and \fIignoredups\fP.
 
2032
A value of
 
2033
.IR erasedups
 
2034
causes all previous lines matching the current line to be removed from
 
2035
the history list before that line is saved.
 
2036
Any value not in the above list is ignored.
 
2037
If
 
2038
.SM
 
2039
.B HISTCONTROL
 
2040
is unset, or does not include a valid value,
 
2041
all lines read by the shell parser are saved on the history list,
 
2042
subject to the value of
 
2043
.SM
 
2044
.BR HISTIGNORE .
 
2045
The second and subsequent lines of a multi-line compound command are
 
2046
not tested, and are added to the history regardless of the value of
 
2047
.SM
 
2048
.BR HISTCONTROL .
 
2049
.TP
 
2050
.B HISTFILE
 
2051
The name of the file in which command history is saved (see
 
2052
.SM
 
2053
.B HISTORY
 
2054
below).  The default value is \fI~/.bash_history\fP.  If unset, the
 
2055
command history is not saved when a shell exits.
 
2056
.TP
 
2057
.B HISTFILESIZE
 
2058
The maximum number of lines contained in the history file.  When this
 
2059
variable is assigned a value, the history file is truncated, if
 
2060
necessary,
 
2061
to contain no more than that number of lines by removing the oldest entries.
 
2062
The history file is also truncated to this size after
 
2063
writing it when a shell exits.
 
2064
If the value is 0, the history file is truncated to zero size.
 
2065
Non-numeric values and numeric values less than zero inhibit truncation.
 
2066
The shell sets the default value to the value of \fBHISTSIZE\fP
 
2067
after reading any startup files.
 
2068
.TP
 
2069
.B HISTIGNORE
 
2070
A colon-separated list of patterns used to decide which command lines
 
2071
should be saved on the history list.  Each pattern is anchored at the
 
2072
beginning of the line and must match the complete line (no implicit
 
2073
`\fB*\fP' is appended).  Each pattern is tested against the line
 
2074
after the checks specified by
 
2075
.SM
 
2076
.B HISTCONTROL
 
2077
are applied.
 
2078
In addition to the normal shell pattern matching characters, `\fB&\fP'
 
2079
matches the previous history line.  `\fB&\fP' may be escaped using a
 
2080
backslash; the backslash is removed before attempting a match.
 
2081
The second and subsequent lines of a multi-line compound command are
 
2082
not tested, and are added to the history regardless of the value of
 
2083
.SM
 
2084
.BR HISTIGNORE .
 
2085
.TP
 
2086
.B HISTSIZE
 
2087
The number of commands to remember in the command history (see
 
2088
.SM
 
2089
.B HISTORY
 
2090
below).
 
2091
If the value is 0, commands are not saved in the history list.
 
2092
Numeric values less than zero result in every command being saved
 
2093
on the history list (there is no limit).
 
2094
The shell sets the default value to 500 after reading any startup files.
 
2095
.TP
 
2096
.B HISTTIMEFORMAT
 
2097
If this variable is set and not null, its value is used as a format string
 
2098
for \fIstrftime\fP(3) to print the time stamp associated with each history
 
2099
entry displayed by the \fBhistory\fP builtin.
 
2100
If this variable is set, time stamps are written to the history file so
 
2101
they may be preserved across shell sessions.
 
2102
This uses the history comment character to distinguish timestamps from
 
2103
other history lines.
 
2104
.TP
 
2105
.B HOME
 
2106
The home directory of the current user; the default argument for the
 
2107
\fBcd\fP builtin command.
 
2108
The value of this variable is also used when performing tilde expansion.
 
2109
.TP
 
2110
.B HOSTFILE
 
2111
Contains the name of a file in the same format as
 
2112
.FN /etc/hosts
 
2113
that should be read when the shell needs to complete a
 
2114
hostname.
 
2115
The list of possible hostname completions may be changed while the
 
2116
shell is running;
 
2117
the next time hostname completion is attempted after the
 
2118
value is changed,
 
2119
.B bash
 
2120
adds the contents of the new file to the existing list.
 
2121
If
 
2122
.SM
 
2123
.B HOSTFILE
 
2124
is set, but has no value, or does not name a readable file,
 
2125
\fBbash\fP attempts to read
 
2126
.FN /etc/hosts
 
2127
to obtain the list of possible hostname completions.
 
2128
When
 
2129
.SM
 
2130
.B HOSTFILE
 
2131
is unset, the hostname list is cleared.
 
2132
.TP
 
2133
.B IFS
 
2134
The
 
2135
.I Internal Field Separator
 
2136
that is used
 
2137
for word splitting after expansion and to
 
2138
split lines into words with the
 
2139
.B read
 
2140
builtin command.  The default value is
 
2141
``<space><tab><newline>''.
 
2142
.TP
 
2143
.B IGNOREEOF
 
2144
Controls the
 
2145
action of an interactive shell on receipt of an
 
2146
.SM
 
2147
.B EOF
 
2148
character as the sole input.  If set, the value is the number of
 
2149
consecutive
 
2150
.SM
 
2151
.B EOF
 
2152
characters which must be
 
2153
typed as the first characters on an input line before
 
2154
.B bash
 
2155
exits.  If the variable exists but does not have a numeric value, or
 
2156
has no value, the default value is 10.  If it does not exist,
 
2157
.SM
 
2158
.B EOF
 
2159
signifies the end of input to the shell.
 
2160
.TP
 
2161
.B INPUTRC
 
2162
The filename for the
 
2163
.B readline
 
2164
startup file, overriding the default of
 
2165
.FN ~/.inputrc
 
2166
(see
 
2167
.SM
 
2168
.B READLINE
 
2169
below).
 
2170
.TP
 
2171
.B LANG
 
2172
Used to determine the locale category for any category not specifically
 
2173
selected with a variable starting with \fBLC_\fP.
 
2174
.TP
 
2175
.B LC_ALL
 
2176
This variable overrides the value of
 
2177
.SM
 
2178
.B LANG
 
2179
and any other
 
2180
\fBLC_\fP variable specifying a locale category.
 
2181
.TP
 
2182
.B LC_COLLATE
 
2183
This variable determines the collation order used when sorting the
 
2184
results of pathname expansion, and determines the behavior of range
 
2185
expressions, equivalence classes, and collating sequences within
 
2186
pathname expansion and pattern matching.
 
2187
.TP
 
2188
.B LC_CTYPE
 
2189
This variable determines the interpretation of characters and the
 
2190
behavior of character classes within pathname expansion and pattern
 
2191
matching.
 
2192
.TP
 
2193
.B LC_MESSAGES
 
2194
This variable determines the locale used to translate double-quoted
 
2195
strings preceded by a \fB$\fP.
 
2196
.TP
 
2197
.B LC_NUMERIC
 
2198
This variable determines the locale category used for number formatting.
 
2199
.TP
 
2200
.B LINES
 
2201
Used by the \fBselect\fP compound command to determine the column length
 
2202
for printing selection lists.
 
2203
Automatically set if the
 
2204
.B checkwinsize
 
2205
option is enabled or in an interactive shell upon receipt of a
 
2206
.SM
 
2207
.BR SIGWINCH .
 
2208
.TP
 
2209
.B MAIL
 
2210
If this parameter is set to a file or directory name and the
 
2211
.SM
 
2212
.B MAILPATH
 
2213
variable is not set,
 
2214
.B bash
 
2215
informs the user of the arrival of mail in the specified file or
 
2216
Maildir-format directory.
 
2217
.TP
 
2218
.B MAILCHECK
 
2219
Specifies how
 
2220
often (in seconds)
 
2221
.B bash
 
2222
checks for mail.  The default is 60 seconds.  When it is time to check
 
2223
for mail, the shell does so before displaying the primary prompt.
 
2224
If this variable is unset, or set to a value that is not a number
 
2225
greater than or equal to zero, the shell disables mail checking.
 
2226
.TP
 
2227
.B MAILPATH
 
2228
A colon-separated list of filenames to be checked for mail. 
 
2229
The message to be printed when mail arrives in a particular file
 
2230
may be specified by separating the filename from the message with a `?'.
 
2231
When used in the text of the message, \fB$_\fP expands to the name of
 
2232
the current mailfile. 
 
2233
Example:
 
2234
.RS
 
2235
.PP
 
2236
\fBMAILPATH\fP=\(aq/var/mail/bfox?"You have mail":~/shell\-mail?"$_ has mail!"\(aq
 
2237
.PP
 
2238
.B Bash
 
2239
supplies a default value for this variable, but the location of the user
 
2240
mail files that it uses is system dependent (e.g., /var/mail/\fB$USER\fP).
 
2241
.RE
 
2242
.TP
 
2243
.B OPTERR
 
2244
If set to the value 1,
 
2245
.B bash
 
2246
displays error messages generated by the
 
2247
.B getopts
 
2248
builtin command (see
 
2249
.SM
 
2250
.B SHELL BUILTIN COMMANDS
 
2251
below).
 
2252
.SM
 
2253
.B OPTERR
 
2254
is initialized to 1 each time the shell is invoked or a shell
 
2255
script is executed.
 
2256
.TP
 
2257
.B PATH
 
2258
The search path for commands.  It
 
2259
is a colon-separated list of directories in which
 
2260
the shell looks for commands (see
 
2261
.SM
 
2262
.B COMMAND EXECUTION
 
2263
below).
 
2264
A zero-length (null) directory name in the value of
 
2265
.SM
 
2266
.B PATH
 
2267
indicates the current directory.
 
2268
A null directory name may appear as two adjacent colons, or as an initial
 
2269
or trailing colon.
 
2270
The default path is system-dependent,
 
2271
and is set by the administrator who installs
 
2272
.BR bash .
 
2273
A common value is
 
2274
.if t \f(CW/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin\fP.
 
2275
.if n ``/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin''.
 
2276
.TP
 
2277
.B POSIXLY_CORRECT
 
2278
If this variable is in the environment when \fBbash\fP starts, the shell
 
2279
enters \fIposix mode\fP before reading the startup files, as if the
 
2280
.B \-\-posix
 
2281
invocation option had been supplied.  If it is set while the shell is
 
2282
running, \fBbash\fP enables \fIposix mode\fP, as if the command
 
2283
.if t \f(CWset -o posix\fP
 
2284
.if n \fIset -o posix\fP
 
2285
had been executed.
 
2286
.TP
 
2287
.B PROMPT_COMMAND
 
2288
If set, the value is executed as a command prior to issuing each primary
 
2289
prompt.
 
2290
.TP
 
2291
.B PROMPT_DIRTRIM
 
2292
If set to a number greater than zero, the value is used as the number of
 
2293
trailing directory components to retain when expanding the \fB\ew\fP and
 
2294
\fB\eW\fP prompt string escapes (see
 
2295
.SM
 
2296
.B PROMPTING
 
2297
below).  Characters removed are replaced with an ellipsis.
 
2298
.TP
 
2299
.B PS1
 
2300
The value of this parameter is expanded (see
 
2301
.SM
 
2302
.B PROMPTING
 
2303
below) and used as the primary prompt string.  The default value is
 
2304
``\fB\es\-\ev\e$ \fP''.
 
2305
.TP
 
2306
.B PS2
 
2307
The value of this parameter is expanded as with
 
2308
.SM
 
2309
.B PS1
 
2310
and used as the secondary prompt string.  The default is
 
2311
``\fB> \fP''.
 
2312
.TP
 
2313
.B PS3
 
2314
The value of this parameter is used as the prompt for the
 
2315
.B select
 
2316
command (see
 
2317
.SM
 
2318
.B SHELL GRAMMAR
 
2319
above).
 
2320
.TP
 
2321
.B PS4
 
2322
The value of this parameter is expanded as with
 
2323
.SM
 
2324
.B PS1
 
2325
and the value is printed before each command
 
2326
.B bash
 
2327
displays during an execution trace.  The first character of
 
2328
.SM
 
2329
.B PS4
 
2330
is replicated multiple times, as necessary, to indicate multiple
 
2331
levels of indirection.  The default is ``\fB+ \fP''.
 
2332
.TP
 
2333
.B SHELL
 
2334
The full pathname to the shell is kept in this environment variable.
 
2335
If it is not set when the shell starts,
 
2336
.B bash
 
2337
assigns to it the full pathname of the current user's login shell.
 
2338
.TP
 
2339
.B TIMEFORMAT
 
2340
The value of this parameter is used as a format string specifying
 
2341
how the timing information for pipelines prefixed with the
 
2342
.B time
 
2343
reserved word should be displayed.
 
2344
The \fB%\fP character introduces an escape sequence that is
 
2345
expanded to a time value or other information.
 
2346
The escape sequences and their meanings are as follows; the
 
2347
braces denote optional portions.
 
2348
.sp .5
 
2349
.RS
 
2350
.PD 0
 
2351
.TP 10
 
2352
.B %%
 
2353
A literal \fB%\fP.
 
2354
.TP
 
2355
.B %[\fIp\fP][l]R
 
2356
The elapsed time in seconds.
 
2357
.TP
 
2358
.B %[\fIp\fP][l]U
 
2359
The number of CPU seconds spent in user mode.
 
2360
.TP
 
2361
.B %[\fIp\fP][l]S
 
2362
The number of CPU seconds spent in system mode.
 
2363
.TP
 
2364
.B %P
 
2365
The CPU percentage, computed as (%U + %S) / %R.
 
2366
.PD
 
2367
.RE
 
2368
.IP
 
2369
The optional \fIp\fP is a digit specifying the \fIprecision\fP,
 
2370
the number of fractional digits after a decimal point.
 
2371
A value of 0 causes no decimal point or fraction to be output.
 
2372
At most three places after the decimal point may be specified;
 
2373
values of \fIp\fP greater than 3 are changed to 3.
 
2374
If \fIp\fP is not specified, the value 3 is used.
 
2375
.IP
 
2376
The optional \fBl\fP specifies a longer format, including
 
2377
minutes, of the form \fIMM\fPm\fISS\fP.\fIFF\fPs.
 
2378
The value of \fIp\fP determines whether or not the fraction is
 
2379
included.
 
2380
.IP
 
2381
If this variable is not set, \fBbash\fP acts as if it had the
 
2382
value \fB$\(aq\enreal\et%3lR\enuser\et%3lU\ensys\et%3lS\(aq\fP.
 
2383
If the value is null, no timing information is displayed.
 
2384
A trailing newline is added when the format string is displayed.
 
2385
.PD 0
 
2386
.TP
 
2387
.B TMOUT
 
2388
If set to a value greater than zero,
 
2389
.SM
 
2390
.B TMOUT
 
2391
is treated as the
 
2392
default timeout for the \fBread\fP builtin.
 
2393
The \fBselect\fP command terminates if input does not arrive
 
2394
after
 
2395
.SM
 
2396
.B TMOUT
 
2397
seconds when input is coming from a terminal.
 
2398
In an interactive shell, the value is interpreted as the
 
2399
number of seconds to wait for a line of input after issuing the
 
2400
primary prompt.
 
2401
.B Bash
 
2402
terminates after waiting for that number of seconds if a complete
 
2403
line of input does not arrive.
 
2404
.TP
 
2405
.B TMPDIR
 
2406
If set, \fBbash\fP uses its value as the name of a directory in which
 
2407
\fBbash\fP creates temporary files for the shell's use.
 
2408
.TP
 
2409
.B auto_resume
 
2410
This variable controls how the shell interacts with the user and
 
2411
job control.  If this variable is set, single word simple
 
2412
commands without redirections are treated as candidates for resumption
 
2413
of an existing stopped job.  There is no ambiguity allowed; if there is
 
2414
more than one job beginning with the string typed, the job most recently
 
2415
accessed is selected.  The
 
2416
.I name
 
2417
of a stopped job, in this context, is the command line used to
 
2418
start it.
 
2419
If set to the value
 
2420
.IR exact ,
 
2421
the string supplied must match the name of a stopped job exactly;
 
2422
if set to
 
2423
.IR substring ,
 
2424
the string supplied needs to match a substring of the name of a
 
2425
stopped job.  The
 
2426
.I substring
 
2427
value provides functionality analogous to the
 
2428
.B %?
 
2429
job identifier (see
 
2430
.SM
 
2431
.B JOB CONTROL
 
2432
below).  If set to any other value, the supplied string must
 
2433
be a prefix of a stopped job's name; this provides functionality
 
2434
analogous to the \fB%\fP\fIstring\fP job identifier.
 
2435
.TP
 
2436
.B histchars
 
2437
The two or three characters which control history expansion
 
2438
and tokenization (see
 
2439
.SM
 
2440
.B HISTORY EXPANSION
 
2441
below).  The first character is the \fIhistory expansion\fP character,
 
2442
the character which signals the start of a history
 
2443
expansion, normally `\fB!\fP'.
 
2444
The second character is the \fIquick substitution\fP
 
2445
character, which is used as shorthand for re-running the previous
 
2446
command entered, substituting one string for another in the command.
 
2447
The default is `\fB^\fP'.
 
2448
The optional third character is the character
 
2449
which indicates that the remainder of the line is a comment when found
 
2450
as the first character of a word, normally `\fB#\fP'.  The history
 
2451
comment character causes history substitution to be skipped for the
 
2452
remaining words on the line.  It does not necessarily cause the shell
 
2453
parser to treat the rest of the line as a comment.
 
2454
.PD
 
2455
.SS Arrays
 
2456
.B Bash
 
2457
provides one-dimensional indexed and associative array variables.
 
2458
Any variable may be used as an indexed array; the
 
2459
.B declare
 
2460
builtin will explicitly declare an array.
 
2461
There is no maximum
 
2462
limit on the size of an array, nor any requirement that members
 
2463
be indexed or assigned contiguously.
 
2464
Indexed arrays are referenced using integers (including arithmetic
 
2465
expressions)  and are zero-based; associative arrays are referenced
 
2466
using arbitrary strings.
 
2467
Unless otherwise noted, indexed array indices must be non-negative integers.
 
2468
.PP
 
2469
An indexed array is created automatically if any variable is assigned to
 
2470
using the syntax \fIname\fP[\fIsubscript\fP]=\fIvalue\fP.  The
 
2471
.I subscript
 
2472
is treated as an arithmetic expression that must evaluate to a number.
 
2473
To explicitly declare an indexed array, use
 
2474
.B declare \-a \fIname\fP
 
2475
(see
 
2476
.SM
 
2477
.B SHELL BUILTIN COMMANDS
 
2478
below).
 
2479
.B declare \-a \fIname\fP[\fIsubscript\fP]
 
2480
is also accepted; the \fIsubscript\fP is ignored.
 
2481
.PP
 
2482
Associative arrays are created using
 
2483
.BR "declare \-A \fIname\fP" .
 
2484
.PP
 
2485
Attributes may be
 
2486
specified for an array variable using the
 
2487
.B declare
 
2488
and
 
2489
.B readonly
 
2490
builtins.  Each attribute applies to all members of an array.
 
2491
.PP
 
2492
Arrays are assigned to using compound assignments of the form
 
2493
\fIname\fP=\fB(\fPvalue\fI1\fP ... value\fIn\fP\fB)\fP, where each
 
2494
\fIvalue\fP is of the form [\fIsubscript\fP]=\fIstring\fP.
 
2495
Indexed array assignments do not require anything but \fIstring\fP.
 
2496
When assigning to indexed arrays, if the optional brackets and subscript
 
2497
are supplied, that index is assigned to;
 
2498
otherwise the index of the element assigned is the last index assigned
 
2499
to by the statement plus one.  Indexing starts at zero.
 
2500
.PP
 
2501
When assigning to an associative array, the subscript is required.
 
2502
.PP
 
2503
This syntax is also accepted by the
 
2504
.B declare
 
2505
builtin.  Individual array elements may be assigned to using the
 
2506
\fIname\fP[\fIsubscript\fP]=\fIvalue\fP syntax introduced above.
 
2507
When assigning to an indexed array, if
 
2508
.I name
 
2509
is subscripted by a negative number, that number is
 
2510
interpreted as relative to one greater than the maximum index of
 
2511
\fIname\fP, so negative indices count back from the end of the
 
2512
array, and an index of \-1 references the last element.
 
2513
.PP
 
2514
Any element of an array may be referenced using
 
2515
${\fIname\fP[\fIsubscript\fP]}.  The braces are required to avoid
 
2516
conflicts with pathname expansion.  If
 
2517
\fIsubscript\fP is \fB@\fP or \fB*\fP, the word expands to
 
2518
all members of \fIname\fP.  These subscripts differ only when the
 
2519
word appears within double quotes.  If the word is double-quoted,
 
2520
${\fIname\fP[*]} expands to a single
 
2521
word with the value of each array member separated by the first
 
2522
character of the
 
2523
.SM
 
2524
.B IFS
 
2525
special variable, and ${\fIname\fP[@]} expands each element of
 
2526
\fIname\fP to a separate word.  When there are no array members,
 
2527
${\fIname\fP[@]} expands to nothing.
 
2528
If the double-quoted expansion occurs within a word, the expansion of
 
2529
the first parameter is joined with the beginning part of the original
 
2530
word, and the expansion of the last parameter is joined with the last
 
2531
part of the original word.
 
2532
This is analogous to the expansion
 
2533
of the special parameters \fB*\fP and \fB@\fP (see
 
2534
.B Special Parameters
 
2535
above).  ${#\fIname\fP[\fIsubscript\fP]} expands to the length of
 
2536
${\fIname\fP[\fIsubscript\fP]}.  If \fIsubscript\fP is \fB*\fP or
 
2537
\fB@\fP, the expansion is the number of elements in the array.
 
2538
Referencing an array variable without a subscript is equivalent to
 
2539
referencing the array with a subscript of 0.
 
2540
If the
 
2541
.I subscript
 
2542
used to reference an element of an indexed array
 
2543
evaluates to a number less than zero, it is 
 
2544
interpreted as relative to one greater than the maximum index of the array,
 
2545
so negative indices count back from the end of the
 
2546
array, and an index of \-1 references the last element.
 
2547
.PP
 
2548
An array variable is considered set if a subscript has been assigned a
 
2549
value.  The null string is a valid value.
 
2550
.PP
 
2551
It is possible to obtain the keys (indices) of an array as well as the values.
 
2552
${\fB!\fP\fIname\fP[\fI@\fP]} and ${\fB!\fP\fIname\fP[\fI*\fP]}
 
2553
expand to the indices assigned in array variable \fIname\fP.
 
2554
The treatment when in double quotes is similar to the expansion of the
 
2555
special parameters \fI@\fP and \fI*\fP within double quotes.
 
2556
.PP
 
2557
The
 
2558
.B unset
 
2559
builtin is used to destroy arrays.  \fBunset\fP \fIname\fP[\fIsubscript\fP]
 
2560
destroys the array element at index \fIsubscript\fP.
 
2561
Negative subscripts to indexed arrays are interpreted as described above.
 
2562
Care must be taken to avoid unwanted side effects caused by pathname
 
2563
expansion.
 
2564
\fBunset\fP \fIname\fP, where \fIname\fP is an array, or
 
2565
\fBunset\fP \fIname\fP[\fIsubscript\fP], where
 
2566
\fIsubscript\fP is \fB*\fP or \fB@\fP, removes the entire array.
 
2567
.PP
 
2568
The
 
2569
.BR declare ,
 
2570
.BR local ,
 
2571
and
 
2572
.B readonly
 
2573
builtins each accept a
 
2574
.B \-a
 
2575
option to specify an indexed array and a
 
2576
.B \-A
 
2577
option to specify an associative array.
 
2578
If both options are supplied, 
 
2579
.B \-A
 
2580
takes precedence.
 
2581
The
 
2582
.B read
 
2583
builtin accepts a
 
2584
.B \-a
 
2585
option to assign a list of words read from the standard input
 
2586
to an array.  The
 
2587
.B set
 
2588
and
 
2589
.B declare
 
2590
builtins display array values in a way that allows them to be
 
2591
reused as assignments.
 
2592
.SH EXPANSION
 
2593
Expansion is performed on the command line after it has been split into
 
2594
words.  There are seven kinds of expansion performed:
 
2595
.IR "brace expansion" ,
 
2596
.IR "tilde expansion" ,
 
2597
.IR "parameter and variable expansion" ,
 
2598
.IR "command substitution" ,
 
2599
.IR "arithmetic expansion" ,
 
2600
.IR "word splitting" ,
 
2601
and
 
2602
.IR "pathname expansion" .
 
2603
.PP
 
2604
The order of expansions is:
 
2605
brace expansion;
 
2606
tilde expansion, parameter and variable expansion, arithmetic expansion,
 
2607
and command substitution (done in a left-to-right fashion);
 
2608
word splitting;
 
2609
and pathname expansion.
 
2610
.PP
 
2611
On systems that can support it, there is an additional expansion
 
2612
available: \fIprocess substitution\fP.
 
2613
This is performed at the
 
2614
same time as tilde, parameter, variable, and arithmetic expansion and
 
2615
command substitution.
 
2616
.PP
 
2617
Only brace expansion, word splitting, and pathname expansion
 
2618
can change the number of words of the expansion; other expansions
 
2619
expand a single word to a single word.
 
2620
The only exceptions to this are the expansions of
 
2621
"\fB$@\fP" and "\fB${\fP\fIname\fP\fB[@]}\fP"
 
2622
as explained above (see
 
2623
.SM
 
2624
.BR PARAMETERS ).
 
2625
.SS Brace Expansion
 
2626
.PP
 
2627
.I "Brace expansion"
 
2628
is a mechanism by which arbitrary strings
 
2629
may be generated.  This mechanism is similar to
 
2630
\fIpathname expansion\fP, but the filenames generated
 
2631
need not exist.  Patterns to be brace expanded take
 
2632
the form of an optional
 
2633
.IR preamble ,
 
2634
followed by either a series of comma-separated strings or
 
2635
a sequence expression between a pair of braces, followed by
 
2636
an optional
 
2637
.IR postscript .
 
2638
The preamble is prefixed to each string contained
 
2639
within the braces, and the postscript is then appended
 
2640
to each resulting string, expanding left to right.
 
2641
.PP
 
2642
Brace expansions may be nested.  The results of each expanded
 
2643
string are not sorted; left to right order is preserved.
 
2644
For example, a\fB{\fPd,c,b\fB}\fPe expands into `ade ace abe'.
 
2645
.PP
 
2646
A sequence expression takes the form
 
2647
\fB{\fP\fIx\fP\fB..\fP\fIy\fP\fB[..\fP\fIincr\fP\fB]}\fP,
 
2648
where \fIx\fP and \fIy\fP are either integers or single characters,
 
2649
and \fIincr\fP, an optional increment, is an integer.
 
2650
When integers are supplied, the expression expands to each number between
 
2651
\fIx\fP and \fIy\fP, inclusive.
 
2652
Supplied integers may be prefixed with \fI0\fP to force each term to have the
 
2653
same width.
 
2654
When either \fIx\fP or \fPy\fP begins with a zero, the shell
 
2655
attempts to force all generated terms to contain the same number of digits,
 
2656
zero-padding where necessary.
 
2657
When characters are supplied, the expression expands to each character
 
2658
lexicographically between \fIx\fP and \fIy\fP, inclusive,
 
2659
using the default C locale.
 
2660
Note that both \fIx\fP and \fIy\fP must be of the same type.
 
2661
When the increment is supplied, it is used as the difference between
 
2662
each term.  The default increment is 1 or -1 as appropriate.
 
2663
.PP
 
2664
Brace expansion is performed before any other expansions,
 
2665
and any characters special to other expansions are preserved
 
2666
in the result.  It is strictly textual.
 
2667
.B Bash
 
2668
does not apply any syntactic interpretation to the context of the
 
2669
expansion or the text between the braces.
 
2670
.PP
 
2671
A correctly-formed brace expansion must contain unquoted opening
 
2672
and closing braces, and at least one unquoted comma or a valid
 
2673
sequence expression.
 
2674
Any incorrectly formed brace expansion is left unchanged.
 
2675
A \fB{\fP or \fB,\fP may be quoted with a backslash to prevent its
 
2676
being considered part of a brace expression.
 
2677
To avoid conflicts with parameter expansion, the string \fB${\fP
 
2678
is not considered eligible for brace expansion.
 
2679
.PP
 
2680
This construct is typically used as shorthand when the common
 
2681
prefix of the strings to be generated is longer than in the
 
2682
above example:
 
2683
.RS
 
2684
.PP
 
2685
mkdir /usr/local/src/bash/{old,new,dist,bugs}
 
2686
.RE
 
2687
or
 
2688
.RS
 
2689
chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
 
2690
.RE
 
2691
.PP
 
2692
Brace expansion introduces a slight incompatibility with
 
2693
historical versions of
 
2694
.BR sh .
 
2695
.B sh
 
2696
does not treat opening or closing braces specially when they
 
2697
appear as part of a word, and preserves them in the output.
 
2698
.B Bash
 
2699
removes braces from words as a consequence of brace
 
2700
expansion.  For example, a word entered to
 
2701
.B sh
 
2702
as \fIfile{1,2}\fP
 
2703
appears identically in the output.  The same word is
 
2704
output as
 
2705
.I file1 file2
 
2706
after expansion by
 
2707
.BR bash .
 
2708
If strict compatibility with
 
2709
.B sh
 
2710
is desired, start
 
2711
.B bash
 
2712
with the
 
2713
.B +B 
 
2714
option or disable brace expansion with the
 
2715
.B +B
 
2716
option to the
 
2717
.B set
 
2718
command (see
 
2719
.SM
 
2720
.B SHELL BUILTIN COMMANDS
 
2721
below).
 
2722
.SS Tilde Expansion
 
2723
.PP
 
2724
If a word begins with an unquoted tilde character (`\fB~\fP'), all of
 
2725
the characters preceding the first unquoted slash (or all characters,
 
2726
if there is no unquoted slash) are considered a \fItilde-prefix\fP.
 
2727
If none of the characters in the tilde-prefix are quoted, the
 
2728
characters in the tilde-prefix following the tilde are treated as a
 
2729
possible \fIlogin name\fP.
 
2730
If this login name is the null string, the tilde is replaced with the
 
2731
value of the shell parameter
 
2732
.SM
 
2733
.BR HOME .
 
2734
If
 
2735
.SM
 
2736
.B HOME
 
2737
is unset, the home directory of the user executing the shell is
 
2738
substituted instead.
 
2739
Otherwise, the tilde-prefix is replaced with the home directory
 
2740
associated with the specified login name.
 
2741
.PP
 
2742
If the tilde-prefix is a `~+', the value of the shell variable
 
2743
.SM
 
2744
.B PWD
 
2745
replaces the tilde-prefix.
 
2746
If the tilde-prefix is a `~\-', the value of the shell variable
 
2747
.SM
 
2748
.BR OLDPWD ,
 
2749
if it is set, is substituted.
 
2750
If the characters following the tilde in the tilde-prefix consist
 
2751
of a number \fIN\fP, optionally prefixed
 
2752
by a `+' or a `\-', the tilde-prefix is replaced with the corresponding
 
2753
element from the directory stack, as it would be displayed by the
 
2754
.B dirs
 
2755
builtin invoked with the tilde-prefix as an argument.
 
2756
If the characters following the tilde in the tilde-prefix consist of a
 
2757
number without a leading `+' or `\-', `+' is assumed.
 
2758
.PP
 
2759
If the login name is invalid, or the tilde expansion fails, the word
 
2760
is unchanged.
 
2761
.PP
 
2762
Each variable assignment is checked for unquoted tilde-prefixes immediately
 
2763
following a
 
2764
.B :
 
2765
or the first
 
2766
.BR = .
 
2767
In these cases, tilde expansion is also performed.
 
2768
Consequently, one may use filenames with tildes in assignments to
 
2769
.SM
 
2770
.BR PATH ,
 
2771
.SM
 
2772
.BR MAILPATH ,
 
2773
and
 
2774
.SM
 
2775
.BR CDPATH ,
 
2776
and the shell assigns the expanded value.
 
2777
.SS Parameter Expansion
 
2778
.PP
 
2779
The `\fB$\fP' character introduces parameter expansion,
 
2780
command substitution, or arithmetic expansion.  The parameter name
 
2781
or symbol to be expanded may be enclosed in braces, which
 
2782
are optional but serve to protect the variable to be expanded from
 
2783
characters immediately following it which could be
 
2784
interpreted as part of the name.
 
2785
.PP
 
2786
When braces are used, the matching ending brace is the first `\fB}\fP'
 
2787
not escaped by a backslash or within a quoted string, and not within an
 
2788
embedded arithmetic expansion, command substitution, or parameter
 
2789
expansion.
 
2790
.PP
 
2791
.PD 0
 
2792
.TP
 
2793
${\fIparameter\fP}
 
2794
The value of \fIparameter\fP is substituted.  The braces are required
 
2795
when
 
2796
.I parameter
 
2797
is a positional parameter with more than one digit,
 
2798
or when
 
2799
.I parameter
 
2800
is followed by a character which is not to be
 
2801
interpreted as part of its name.
 
2802
The \fIparameter\fP is a shell parameter as described above
 
2803
\fBPARAMETERS\fP) or an array reference (\fBArrays\fP).
 
2804
.PD
 
2805
.PP
 
2806
If the first character of \fIparameter\fP is an exclamation point (\fB!\fP),
 
2807
it introduces a level of variable indirection.
 
2808
\fBBash\fP uses the value of the variable formed from the rest of
 
2809
\fIparameter\fP as the name of the variable; this variable is then
 
2810
expanded and that value is used in the rest of the substitution, rather
 
2811
than the value of \fIparameter\fP itself.
 
2812
This is known as \fIindirect expansion\fP.
 
2813
The exceptions to this are the expansions of ${\fB!\fP\fIprefix\fP\fB*\fP} and
 
2814
${\fB!\fP\fIname\fP[\fI@\fP]} described below.
 
2815
The exclamation point must immediately follow the left brace in order to
 
2816
introduce indirection.
 
2817
.PP
 
2818
In each of the cases below, \fIword\fP is subject to tilde expansion,
 
2819
parameter expansion, command substitution, and arithmetic expansion.
 
2820
.PP
 
2821
When not performing substring expansion, using the forms documented below
 
2822
(e.g., \fB:-\fP),
 
2823
\fBbash\fP tests for a parameter that is unset or null.  Omitting the colon
 
2824
results in a test only for a parameter that is unset.
 
2825
.PP
 
2826
.PD 0
 
2827
.TP
 
2828
${\fIparameter\fP\fB:\-\fP\fIword\fP}
 
2829
\fBUse Default Values\fP.  If
 
2830
.I parameter
 
2831
is unset or null, the expansion of
 
2832
.I word
 
2833
is substituted.  Otherwise, the value of
 
2834
.I parameter
 
2835
is substituted.
 
2836
.TP
 
2837
${\fIparameter\fP\fB:=\fP\fIword\fP}
 
2838
\fBAssign Default Values\fP.
 
2839
If
 
2840
.I parameter
 
2841
is unset or null, the expansion of
 
2842
.I word
 
2843
is assigned to
 
2844
.IR parameter .
 
2845
The value of
 
2846
.I parameter
 
2847
is then substituted.  Positional parameters and special parameters may
 
2848
not be assigned to in this way.
 
2849
.TP
 
2850
${\fIparameter\fP\fB:?\fP\fIword\fP}
 
2851
\fBDisplay Error if Null or Unset\fP.
 
2852
If
 
2853
.I parameter
 
2854
is null or unset, the expansion of \fIword\fP (or a message to that effect
 
2855
if
 
2856
.I word
 
2857
is not present) is written to the standard error and the shell, if it
 
2858
is not interactive, exits.  Otherwise, the value of \fIparameter\fP is
 
2859
substituted.
 
2860
.TP
 
2861
${\fIparameter\fP\fB:+\fP\fIword\fP}
 
2862
\fBUse Alternate Value\fP.
 
2863
If
 
2864
.I parameter
 
2865
is null or unset, nothing is substituted, otherwise the expansion of
 
2866
.I word
 
2867
is substituted.
 
2868
.TP
 
2869
${\fIparameter\fP\fB:\fP\fIoffset\fP}
 
2870
.PD 0
 
2871
.TP
 
2872
${\fIparameter\fP\fB:\fP\fIoffset\fP\fB:\fP\fIlength\fP}
 
2873
.PD
 
2874
\fBSubstring Expansion\fP.
 
2875
Expands to up to \fIlength\fP characters of the value of \fIparameter\fP
 
2876
starting at the character specified by \fIoffset\fP.
 
2877
If \fIparameter\fP is \fB@\fP, an indexed array subscripted by
 
2878
\fB@\fP or \fB*\fP, or an associative array name, the results differ as
 
2879
described below.
 
2880
If \fIlength\fP is omitted, expands to the substring of the value of
 
2881
\fIparameter\fP starting at the character specified by \fIoffset\fP
 
2882
and extending to the end of the value.
 
2883
\fIlength\fP and \fIoffset\fP are arithmetic expressions (see
 
2884
.SM
 
2885
.B
 
2886
ARITHMETIC EVALUATION
 
2887
below).
 
2888
.sp 1
 
2889
If \fIoffset\fP evaluates to a number less than zero, the value
 
2890
is used as an offset in characters
 
2891
from the end of the value of \fIparameter\fP.
 
2892
If \fIlength\fP evaluates to a number less than zero,
 
2893
it is interpreted as an offset in characters
 
2894
from the end of the value of \fIparameter\fP rather than
 
2895
a number of characters, and the expansion is the characters between
 
2896
\fIoffset\fP and that result.
 
2897
Note that a negative offset must be separated from the colon by at least
 
2898
one space to avoid being confused with the \fB:-\fP expansion.
 
2899
.sp 1
 
2900
If \fIparameter\fP is \fB@\fP, the result is \fIlength\fP positional
 
2901
parameters beginning at \fIoffset\fP.
 
2902
A negative \fIoffset\fP is taken relative to one greater than the greatest
 
2903
positional parameter, so an offset of -1 evaluates to the last positional
 
2904
parameter.
 
2905
It is an expansion error if \fIlength\fP evaluates to a number less than
 
2906
zero.
 
2907
.sp 1
 
2908
If \fIparameter\fP is an indexed array name subscripted by @ or *,
 
2909
the result is the \fIlength\fP
 
2910
members of the array beginning with ${\fIparameter\fP[\fIoffset\fP]}.
 
2911
A negative \fIoffset\fP is taken relative to one greater than the maximum
 
2912
index of the specified array.
 
2913
It is an expansion error if \fIlength\fP evaluates to a number less than
 
2914
zero.
 
2915
.sp 1
 
2916
Substring expansion applied to an associative array produces undefined
 
2917
results.
 
2918
.sp 1
 
2919
Substring indexing is zero-based unless the positional parameters 
 
2920
are used, in which case the indexing starts at 1 by default.
 
2921
If \fIoffset\fP is 0, and the positional parameters are used, \fB$0\fP is
 
2922
prefixed to the list.
 
2923
.TP
 
2924
${\fB!\fP\fIprefix\fP\fB*\fP}
 
2925
.PD 0
 
2926
.TP
 
2927
${\fB!\fP\fIprefix\fP\fB@\fP}
 
2928
.PD
 
2929
\fBNames matching prefix\fP.
 
2930
Expands to the names of variables whose names begin with \fIprefix\fP,
 
2931
separated by the first character of the
 
2932
.SM
 
2933
.B IFS
 
2934
special variable.
 
2935
When \fI@\fP is used and the expansion appears within double quotes, each
 
2936
variable name expands to a separate word.
 
2937
.TP
 
2938
${\fB!\fP\fIname\fP[\fI@\fP]}
 
2939
.PD 0
 
2940
.TP
 
2941
${\fB!\fP\fIname\fP[\fI*\fP]}
 
2942
.PD
 
2943
\fBList of array keys\fP.
 
2944
If \fIname\fP is an array variable, expands to the list of array indices
 
2945
(keys) assigned in \fIname\fP.
 
2946
If \fIname\fP is not an array, expands to 0 if \fIname\fP is set and null
 
2947
otherwise.
 
2948
When \fI@\fP is used and the expansion appears within double quotes, each
 
2949
key expands to a separate word.
 
2950
.TP
 
2951
${\fB#\fP\fIparameter\fP}
 
2952
\fBParameter length\fP.
 
2953
The length in characters of the value of \fIparameter\fP is substituted.
 
2954
If
 
2955
.I parameter
 
2956
is
 
2957
.B *
 
2958
or 
 
2959
.BR @ ,
 
2960
the value substituted is the number of positional parameters.
 
2961
If
 
2962
.I parameter
 
2963
is an array name subscripted by
 
2964
.B *
 
2965
or
 
2966
.BR @ ,
 
2967
the value substituted is the number of elements in the array.
 
2968
If
 
2969
.I parameter
 
2970
is an indexed array name subscripted by a negative number, that number is
 
2971
interpreted as relative to one greater than the maximum index of
 
2972
\fIparameter\fP, so negative indices count back from the end of the
 
2973
array, and an index of \-1 references the last element.
 
2974
.TP
 
2975
${\fIparameter\fP\fB#\fP\fIword\fP}
 
2976
.PD 0
 
2977
.TP
 
2978
${\fIparameter\fP\fB##\fP\fIword\fP}
 
2979
.PD
 
2980
\fBRemove matching prefix pattern\fP.
 
2981
The 
 
2982
.I word
 
2983
is expanded to produce a pattern just as in pathname
 
2984
expansion.  If the pattern matches the beginning of
 
2985
the value of
 
2986
.IR parameter ,
 
2987
then the result of the expansion is the expanded value of
 
2988
.I parameter
 
2989
with the shortest matching pattern (the ``\fB#\fP'' case) or the
 
2990
longest matching pattern (the ``\fB##\fP'' case) deleted.
 
2991
If
 
2992
.I parameter
 
2993
is
 
2994
.B @
 
2995
or
 
2996
.BR * ,
 
2997
the pattern removal operation is applied to each positional
 
2998
parameter in turn, and the expansion is the resultant list.
 
2999
If
 
3000
.I parameter
 
3001
is an array variable subscripted with
 
3002
.B @
 
3003
or
 
3004
.BR * ,
 
3005
the pattern removal operation is applied to each member of the
 
3006
array in turn, and the expansion is the resultant list.
 
3007
.TP
 
3008
${\fIparameter\fP\fB%\fP\fIword\fP}
 
3009
.PD 0
 
3010
.TP
 
3011
${\fIparameter\fP\fB%%\fP\fIword\fP}
 
3012
.PD
 
3013
\fBRemove matching suffix pattern\fP.
 
3014
The \fIword\fP is expanded to produce a pattern just as in
 
3015
pathname expansion.
 
3016
If the pattern matches a trailing portion of the expanded value of
 
3017
.IR parameter ,
 
3018
then the result of the expansion is the expanded value of
 
3019
.I parameter
 
3020
with the shortest matching pattern (the ``\fB%\fP'' case) or the
 
3021
longest matching pattern (the ``\fB%%\fP'' case) deleted.
 
3022
If
 
3023
.I parameter
 
3024
is
 
3025
.B @
 
3026
or
 
3027
.BR * ,
 
3028
the pattern removal operation is applied to each positional
 
3029
parameter in turn, and the expansion is the resultant list.
 
3030
If
 
3031
.I parameter
 
3032
is an array variable subscripted with
 
3033
.B @
 
3034
or
 
3035
.BR * ,
 
3036
the pattern removal operation is applied to each member of the
 
3037
array in turn, and the expansion is the resultant list.
 
3038
.TP
 
3039
${\fIparameter\fP\fB/\fP\fIpattern\fP\fB/\fP\fIstring\fP}
 
3040
\fBPattern substitution\fP.
 
3041
The \fIpattern\fP is expanded to produce a pattern just as in
 
3042
pathname expansion.
 
3043
\fIParameter\fP is expanded and the longest match of \fIpattern\fP
 
3044
against its value is replaced with \fIstring\fP.
 
3045
If \fIpattern\fP begins with \fB/\fP, all matches of \fIpattern\fP are
 
3046
replaced with \fIstring\fP.  Normally only the first match is replaced.
 
3047
If \fIpattern\fP begins with \fB#\fP, it must match at the beginning
 
3048
of the expanded value of \fIparameter\fP.
 
3049
If \fIpattern\fP begins with \fB%\fP, it must match at the end
 
3050
of the expanded value of \fIparameter\fP.
 
3051
If \fIstring\fP is null, matches of \fIpattern\fP are deleted
 
3052
and the \fB/\fP following \fIpattern\fP may be omitted.
 
3053
If
 
3054
.I parameter
 
3055
is
 
3056
.B @
 
3057
or
 
3058
.BR * ,
 
3059
the substitution operation is applied to each positional
 
3060
parameter in turn, and the expansion is the resultant list.
 
3061
If
 
3062
.I parameter
 
3063
is an array variable subscripted with
 
3064
.B @
 
3065
or
 
3066
.BR * ,
 
3067
the substitution operation is applied to each member of the
 
3068
array in turn, and the expansion is the resultant list.
 
3069
.TP
 
3070
${\fIparameter\fP\fB^\fP\fIpattern\fP}
 
3071
.PD 0
 
3072
.TP
 
3073
${\fIparameter\fP\fB^^\fP\fIpattern\fP}
 
3074
.TP
 
3075
${\fIparameter\fP\fB,\fP\fIpattern\fP}
 
3076
.TP
 
3077
${\fIparameter\fP\fB,,\fP\fIpattern\fP}
 
3078
.PD
 
3079
\fBCase modification\fP.
 
3080
This expansion modifies the case of alphabetic characters in \fIparameter\fP.
 
3081
The \fIpattern\fP is expanded to produce a pattern just as in
 
3082
pathname expansion.
 
3083
Each character in the expanded value of \fIparameter\fP is tested against
 
3084
\fIpattern\fP, and, if it matches the pattern, its case is converted.
 
3085
The pattern should not attempt to match more than one character.
 
3086
The \fB^\fP operator converts lowercase letters matching \fIpattern\fP
 
3087
to uppercase; the \fB,\fP operator converts matching uppercase letters
 
3088
to lowercase.
 
3089
The \fB^^\fP and \fB,,\fP expansions convert each matched character in the
 
3090
expanded value; the \fB^\fP and \fB,\fP expansions match and convert only
 
3091
the first character in the expanded value.
 
3092
If \fIpattern\fP is omitted, it is treated like a \fB?\fP, which matches
 
3093
every character.
 
3094
If
 
3095
.I parameter
 
3096
is
 
3097
.B @
 
3098
or
 
3099
.BR * ,
 
3100
the case modification operation is applied to each positional
 
3101
parameter in turn, and the expansion is the resultant list.
 
3102
If
 
3103
.I parameter
 
3104
is an array variable subscripted with
 
3105
.B @
 
3106
or
 
3107
.BR * ,
 
3108
the case modification operation is applied to each member of the
 
3109
array in turn, and the expansion is the resultant list.
 
3110
.SS Command Substitution
 
3111
.PP
 
3112
\fICommand substitution\fP allows the output of a command to replace
 
3113
the command name.  There are two forms:
 
3114
.RS
 
3115
.PP
 
3116
\fB$(\fP\fIcommand\fP\|\fB)\fP
 
3117
.RE
 
3118
or
 
3119
.RS
 
3120
\fB\`\fP\fIcommand\fP\fB\`\fP
 
3121
.RE
 
3122
.PP
 
3123
.B Bash
 
3124
performs the expansion by executing \fIcommand\fP and
 
3125
replacing the command substitution with the standard output of the
 
3126
command, with any trailing newlines deleted.
 
3127
Embedded newlines are not deleted, but they may be removed during
 
3128
word splitting.
 
3129
The command substitution \fB$(cat \fIfile\fP)\fR can be replaced by
 
3130
the equivalent but faster \fB$(< \fIfile\fP)\fR.
 
3131
.PP
 
3132
When the old-style backquote form of substitution is used,
 
3133
backslash retains its literal meaning except when followed by
 
3134
.BR $ ,
 
3135
.BR \` ,
 
3136
or
 
3137
.BR \e .
 
3138
The first backquote not preceded by a backslash terminates the
 
3139
command substitution.
 
3140
When using the $(\^\fIcommand\fP\|) form, all characters between the
 
3141
parentheses make up the command; none are treated specially.
 
3142
.PP
 
3143
Command substitutions may be nested.  To nest when using the backquoted form,
 
3144
escape the inner backquotes with backslashes.
 
3145
.PP
 
3146
If the substitution appears within double quotes, word splitting and
 
3147
pathname expansion are not performed on the results.
 
3148
.SS Arithmetic Expansion
 
3149
.PP
 
3150
Arithmetic expansion allows the evaluation of an arithmetic expression
 
3151
and the substitution of the result.  The format for arithmetic expansion is:
 
3152
.RS
 
3153
.PP
 
3154
\fB$((\fP\fIexpression\fP\fB))\fP
 
3155
.RE
 
3156
.PP
 
3157
The old format \fB$[\fP\fIexpression\fP\fB]\fP is deprecated and will
 
3158
be removed in upcoming versions of bash.
 
3159
.PP
 
3160
The
 
3161
.I expression
 
3162
is treated as if it were within double quotes, but a double quote
 
3163
inside the parentheses is not treated specially.
 
3164
All tokens in the expression undergo parameter and variable expansion,
 
3165
command substitution, and quote removal.
 
3166
The result is treated as the arithmetic expression to be evaluated.
 
3167
Arithmetic expansions may be nested.
 
3168
.PP
 
3169
The evaluation is performed according to the rules listed below under
 
3170
.SM
 
3171
.BR "ARITHMETIC EVALUATION" .
 
3172
If
 
3173
.I expression
 
3174
is invalid,
 
3175
.B bash
 
3176
prints a message indicating failure and no substitution occurs.
 
3177
.SS Process Substitution
 
3178
.PP
 
3179
\fIProcess substitution\fP is supported on systems that support named
 
3180
pipes (\fIFIFOs\fP) or the \fB/dev/fd\fP method of naming open files.
 
3181
It takes the form of
 
3182
\fB<(\fP\fIlist\^\fP\fB)\fP
 
3183
or
 
3184
\fB>(\fP\fIlist\^\fP\fB)\fP.
 
3185
The process \fIlist\fP is run with its input or output connected to a
 
3186
\fIFIFO\fP or some file in \fB/dev/fd\fP.  The name of this file is
 
3187
passed as an argument to the current command as the result of the
 
3188
expansion.  If the \fB>(\fP\fIlist\^\fP\fB)\fP form is used, writing to
 
3189
the file will provide input for \fIlist\fP.  If the
 
3190
\fB<(\fP\fIlist\^\fP\fB)\fP form is used, the file passed as an
 
3191
argument should be read to obtain the output of \fIlist\fP.
 
3192
.PP
 
3193
When available, process substitution is performed
 
3194
simultaneously with parameter and variable expansion, 
 
3195
command substitution,
 
3196
and arithmetic expansion.
 
3197
.SS Word Splitting
 
3198
.PP
 
3199
The shell scans the results of
 
3200
parameter expansion,
 
3201
command substitution,
 
3202
and
 
3203
arithmetic expansion
 
3204
that did not occur within double quotes for
 
3205
.IR "word splitting" .
 
3206
.PP
 
3207
The shell treats each character of
 
3208
.SM
 
3209
.B IFS
 
3210
as a delimiter, and splits the results of the other
 
3211
expansions into words using these characters as field terminators.
 
3212
If
 
3213
.SM
 
3214
.B IFS
 
3215
is unset, or its
 
3216
value is exactly
 
3217
.BR <space><tab><newline> ,
 
3218
the default, then
 
3219
sequences of
 
3220
.BR <space> ,
 
3221
.BR <tab> ,
 
3222
and
 
3223
.B <newline>
 
3224
at the beginning and end of the results of the previous
 
3225
expansions are ignored, and
 
3226
any sequence of
 
3227
.SM
 
3228
.B IFS
 
3229
characters not at the beginning or end serves to delimit words.
 
3230
If
 
3231
.SM
 
3232
.B IFS
 
3233
has a value other than the default, then sequences of
 
3234
the whitespace characters
 
3235
.B space
 
3236
and
 
3237
.B tab
 
3238
are ignored at the beginning and end of the
 
3239
word, as long as the whitespace character is in the
 
3240
value of
 
3241
.SM
 
3242
.BR IFS
 
3243
(an
 
3244
.SM
 
3245
.B IFS
 
3246
whitespace character).
 
3247
Any character in
 
3248
.SM
 
3249
.B IFS
 
3250
that is not
 
3251
.SM
 
3252
.B IFS
 
3253
whitespace, along with any adjacent
 
3254
.SM
 
3255
.B IFS
 
3256
whitespace characters, delimits a field.
 
3257
A sequence of
 
3258
.SM
 
3259
.B IFS
 
3260
whitespace characters is also treated as a delimiter.
 
3261
If the value of
 
3262
.SM
 
3263
.B IFS
 
3264
is null, no word splitting occurs.
 
3265
.PP
 
3266
Explicit null arguments (\^\f3"\^"\fP or \^\f3\(aq\^\(aq\fP\^) are retained.
 
3267
Unquoted implicit null arguments, resulting from the expansion of
 
3268
parameters that have no values, are removed.
 
3269
If a parameter with no value is expanded within double quotes, a
 
3270
null argument results and is retained.
 
3271
.PP
 
3272
Note that if no expansion occurs, no splitting
 
3273
is performed.
 
3274
.SS Pathname Expansion
 
3275
.PP
 
3276
After word splitting,
 
3277
unless the
 
3278
.B \-f
 
3279
option has been set,
 
3280
.B bash
 
3281
scans each word for the characters
 
3282
.BR * ,
 
3283
.BR ? ,
 
3284
and
 
3285
.BR [ .
 
3286
If one of these characters appears, then the word is
 
3287
regarded as a
 
3288
.IR pattern ,
 
3289
and replaced with an alphabetically sorted list of
 
3290
filenames matching the pattern
 
3291
(see
 
3292
.SM
 
3293
.B "Pattern Matching"
 
3294
below).
 
3295
If no matching filenames are found,
 
3296
and the shell option
 
3297
.B nullglob
 
3298
is not enabled, the word is left unchanged.
 
3299
If the 
 
3300
.B nullglob
 
3301
option is set, and no matches are found,
 
3302
the word is removed.
 
3303
If the
 
3304
.B failglob
 
3305
shell option is set, and no matches are found, an error message
 
3306
is printed and the command is not executed.
 
3307
If the shell option
 
3308
.B nocaseglob
 
3309
is enabled, the match is performed without regard to the case
 
3310
of alphabetic characters.
 
3311
When a pattern is used for pathname expansion,
 
3312
the character
 
3313
.B ``.''
 
3314
at the start of a name or immediately following a slash
 
3315
must be matched explicitly, unless the shell option
 
3316
.B dotglob
 
3317
is set.
 
3318
When matching a pathname, the slash character must always be
 
3319
matched explicitly.
 
3320
In other cases, the
 
3321
.B ``.''
 
3322
character is not treated specially.
 
3323
See the description of
 
3324
.B shopt
 
3325
below under
 
3326
.SM
 
3327
.B SHELL BUILTIN COMMANDS
 
3328
for a description of the
 
3329
.BR nocaseglob ,
 
3330
.BR nullglob ,
 
3331
.BR failglob ,
 
3332
and
 
3333
.B dotglob
 
3334
shell options.
 
3335
.PP
 
3336
The
 
3337
.SM
 
3338
.B GLOBIGNORE
 
3339
shell variable may be used to restrict the set of filenames matching a
 
3340
.IR pattern .
 
3341
If
 
3342
.SM
 
3343
.B GLOBIGNORE
 
3344
is set, each matching filename that also matches one of the patterns in
 
3345
.SM
 
3346
.B GLOBIGNORE
 
3347
is removed from the list of matches.
 
3348
The filenames
 
3349
.B ``.''
 
3350
and
 
3351
.B ``..''
 
3352
are always ignored when
 
3353
.SM
 
3354
.B GLOBIGNORE
 
3355
is set and not null.  However, setting
 
3356
.SM
 
3357
.B GLOBIGNORE
 
3358
to a non-null value has the effect of enabling the
 
3359
.B dotglob
 
3360
shell option, so all other filenames beginning with a
 
3361
.B ``.''
 
3362
will match.
 
3363
To get the old behavior of ignoring filenames beginning with a
 
3364
.BR ``.'' ,
 
3365
make
 
3366
.B ``.*''
 
3367
one of the patterns in
 
3368
.SM
 
3369
.BR GLOBIGNORE .
 
3370
The
 
3371
.B dotglob
 
3372
option is disabled when
 
3373
.SM
 
3374
.B GLOBIGNORE
 
3375
is unset.
 
3376
.PP
 
3377
\fBPattern Matching\fP
 
3378
.PP
 
3379
Any character that appears in a pattern, other than the special pattern
 
3380
characters described below, matches itself.  The NUL character may not
 
3381
occur in a pattern.  A backslash escapes the following character; the
 
3382
escaping backslash is discarded when matching.
 
3383
The special pattern characters must be quoted if
 
3384
they are to be matched literally.
 
3385
.PP
 
3386
The special pattern characters have the following meanings:
 
3387
.PP
 
3388
.PD 0
 
3389
.RS
 
3390
.TP
 
3391
.B *
 
3392
Matches any string, including the null string.
 
3393
When the \fBglobstar\fP shell option is enabled, and \fB*\fP is used in
 
3394
a pathname expansion context, two adjacent \fB*\fPs used as a single
 
3395
pattern will match all files and zero or more directories and
 
3396
subdirectories.
 
3397
If followed by a \fB/\fP, two adjacent \fB*\fPs will match only directories
 
3398
and subdirectories.
 
3399
.TP
 
3400
.B ?
 
3401
Matches any single character.
 
3402
.TP
 
3403
.B [...]
 
3404
Matches any one of the enclosed characters.  A pair of characters
 
3405
separated by a hyphen denotes a
 
3406
\fIrange expression\fP;
 
3407
any character that falls between those two characters, inclusive,
 
3408
using the current locale's collating sequence and character set,
 
3409
is matched.  If the first character following the
 
3410
.B [
 
3411
is a
 
3412
.B !
 
3413
or a
 
3414
.B ^
 
3415
then any character not enclosed is matched.
 
3416
The sorting order of characters in range expressions is determined by
 
3417
the current locale and the values of the
 
3418
.SM
 
3419
.B LC_COLLATE
 
3420
or
 
3421
.SM
 
3422
.B LC_ALL
 
3423
shell variables, if set.
 
3424
To obtain the traditional interpretation of range expressions, where
 
3425
.B [a\-d]
 
3426
is equivalent to
 
3427
.BR [abcd] ,
 
3428
set value of the
 
3429
.B LC_ALL
 
3430
shell variable to
 
3431
.BR C ,
 
3432
or enable the
 
3433
.B globasciiranges
 
3434
shell option.
 
3435
 
3436
.B \-
 
3437
may be matched by including it as the first or last character
 
3438
in the set.
 
3439
A
 
3440
.B ]
 
3441
may be matched by including it as the first character
 
3442
in the set.
 
3443
.br
 
3444
.if t .sp 0.5
 
3445
.if n .sp 1
 
3446
Within
 
3447
.B [
 
3448
and
 
3449
.BR ] ,
 
3450
\fIcharacter classes\fP can be specified using the syntax
 
3451
\fB[:\fP\fIclass\fP\fB:]\fP, where \fIclass\fP is one of the
 
3452
following classes defined in the POSIX standard:
 
3453
.PP
 
3454
.RS
 
3455
.B
 
3456
.if n alnum alpha ascii blank cntrl digit graph lower print punct space upper word xdigit
 
3457
.if t alnum   alpha   ascii   blank   cntrl   digit   graph   lower   print   punct   space   upper   word   xdigit
 
3458
.br
 
3459
A character class matches any character belonging to that class.
 
3460
The \fBword\fP character class matches letters, digits, and the character _.
 
3461
.br
 
3462
.if t .sp 0.5
 
3463
.if n .sp 1
 
3464
Within
 
3465
.B [
 
3466
and 
 
3467
.BR ] ,
 
3468
an \fIequivalence class\fP can be specified using the syntax
 
3469
\fB[=\fP\fIc\fP\fB=]\fP, which matches all characters with the
 
3470
same collation weight (as defined by the current locale) as
 
3471
the character \fIc\fP.
 
3472
.br
 
3473
.if t .sp 0.5
 
3474
.if n .sp 1
 
3475
Within
 
3476
.B [
 
3477
and 
 
3478
.BR ] ,
 
3479
the syntax \fB[.\fP\fIsymbol\fP\fB.]\fP matches the collating symbol
 
3480
\fIsymbol\fP.
 
3481
.RE
 
3482
.RE
 
3483
.PD
 
3484
.PP
 
3485
If the \fBextglob\fP shell option is enabled using the \fBshopt\fP
 
3486
builtin, several extended pattern matching operators are recognized.
 
3487
In the following description, a \fIpattern-list\fP is a list of one
 
3488
or more patterns separated by a \fB|\fP.
 
3489
Composite patterns may be formed using one or more of the following
 
3490
sub-patterns:
 
3491
.sp 1
 
3492
.PD 0
 
3493
.RS
 
3494
.TP
 
3495
\fB?(\fP\^\fIpattern-list\^\fP\fB)\fP
 
3496
Matches zero or one occurrence of the given patterns
 
3497
.TP
 
3498
\fB*(\fP\^\fIpattern-list\^\fP\fB)\fP
 
3499
Matches zero or more occurrences of the given patterns
 
3500
.TP
 
3501
\fB+(\fP\^\fIpattern-list\^\fP\fB)\fP
 
3502
Matches one or more occurrences of the given patterns
 
3503
.TP
 
3504
\fB@(\fP\^\fIpattern-list\^\fP\fB)\fP
 
3505
Matches one of the given patterns
 
3506
.TP
 
3507
\fB!(\fP\^\fIpattern-list\^\fP\fB)\fP
 
3508
Matches anything except one of the given patterns
 
3509
.RE
 
3510
.PD
 
3511
.SS Quote Removal
 
3512
.PP
 
3513
After the preceding expansions, all unquoted occurrences of the
 
3514
characters
 
3515
.BR \e ,
 
3516
.BR \(aq ,
 
3517
and \^\f3"\fP\^ that did not result from one of the above
 
3518
expansions are removed.
 
3519
.SH REDIRECTION
 
3520
Before a command is executed, its input and output
 
3521
may be
 
3522
.I redirected
 
3523
using a special notation interpreted by the shell.
 
3524
Redirection allows commands' file handles to be
 
3525
duplicated, opened, closed,
 
3526
made to refer to different files,
 
3527
and can change the files the command reads from and writes to.
 
3528
Redirection may also be used to modify file handles in the
 
3529
current shell execution environment.
 
3530
The following redirection
 
3531
operators may precede or appear anywhere within a
 
3532
.I simple command
 
3533
or may follow a
 
3534
.IR command .
 
3535
Redirections are processed in the order they appear, from
 
3536
left to right.
 
3537
.PP
 
3538
Each redirection that may be preceded by a file descriptor number
 
3539
may instead be preceded by a word of the form {\fIvarname\fP}.
 
3540
In this case, for each redirection operator except
 
3541
>&- and <&-, the shell will allocate a file descriptor greater
 
3542
than or equal to 10 and assign it to \fIvarname\fP.
 
3543
If >&- or <&- is preceded
 
3544
by {\fIvarname\fP}, the value of \fIvarname\fP defines the file
 
3545
descriptor to close.
 
3546
.PP
 
3547
In the following descriptions, if the file descriptor number is
 
3548
omitted, and the first character of the redirection operator is
 
3549
.BR < ,
 
3550
the redirection refers to the standard input (file descriptor
 
3551
0).  If the first character of the redirection operator is
 
3552
.BR > ,
 
3553
the redirection refers to the standard output (file descriptor
 
3554
1).
 
3555
.PP
 
3556
The word following the redirection operator in the following
 
3557
descriptions, unless otherwise noted, is subjected to
 
3558
brace expansion, tilde expansion, parameter and variable expansion,
 
3559
command substitution, arithmetic expansion, quote removal,
 
3560
pathname expansion, and word splitting.
 
3561
If it expands to more than one word,
 
3562
.B bash
 
3563
reports an error.
 
3564
.PP
 
3565
Note that the order of redirections is significant.  For example, 
 
3566
the command
 
3567
.RS
 
3568
.PP
 
3569
ls \fB>\fP dirlist 2\fB>&\fP1
 
3570
.RE
 
3571
.PP
 
3572
directs both standard output and standard error to the file 
 
3573
.IR dirlist ,
 
3574
while the command
 
3575
.RS
 
3576
.PP
 
3577
ls 2\fB>&\fP1 \fB>\fP dirlist
 
3578
.RE
 
3579
.PP
 
3580
directs only the standard output to file
 
3581
.IR dirlist ,
 
3582
because the standard error was duplicated from the standard output
 
3583
before the standard output was redirected to
 
3584
.IR dirlist .
 
3585
.PP
 
3586
\fBBash\fP handles several filenames specially when they are used in
 
3587
redirections, as described in the following table:
 
3588
.RS
 
3589
.PP
 
3590
.PD 0
 
3591
.TP
 
3592
.B /dev/fd/\fIfd\fP
 
3593
If \fIfd\fP is a valid integer, file descriptor \fIfd\fP is duplicated.
 
3594
.TP
 
3595
.B /dev/stdin
 
3596
File descriptor 0 is duplicated.
 
3597
.TP
 
3598
.B /dev/stdout
 
3599
File descriptor 1 is duplicated.
 
3600
.TP
 
3601
.B /dev/stderr
 
3602
File descriptor 2 is duplicated.
 
3603
.TP
 
3604
.B /dev/tcp/\fIhost\fP/\fIport\fP
 
3605
If \fIhost\fP is a valid hostname or Internet address, and \fIport\fP
 
3606
is an integer port number or service name, \fBbash\fP attempts to open
 
3607
the corresponding TCP socket.
 
3608
.TP
 
3609
.B /dev/udp/\fIhost\fP/\fIport\fP
 
3610
If \fIhost\fP is a valid hostname or Internet address, and \fIport\fP
 
3611
is an integer port number or service name, \fBbash\fP attempts to open
 
3612
the corresponding UDP socket.
 
3613
.PD
 
3614
.RE
 
3615
.PP
 
3616
A failure to open or create a file causes the redirection to fail.
 
3617
.PP
 
3618
Redirections using file descriptors greater than 9 should be used with
 
3619
care, as they may conflict with file descriptors the shell uses
 
3620
internally.
 
3621
.SS Redirecting Input
 
3622
.PP
 
3623
Redirection of input causes the file whose name results from
 
3624
the expansion of
 
3625
.I word
 
3626
to be opened for reading on file descriptor
 
3627
.IR n ,
 
3628
or the standard input (file descriptor 0) if
 
3629
.I n
 
3630
is not specified.
 
3631
.PP
 
3632
The general format for redirecting input is:
 
3633
.RS
 
3634
.PP
 
3635
[\fIn\fP]\fB<\fP\fIword\fP
 
3636
.RE
 
3637
.SS Redirecting Output
 
3638
.PP
 
3639
Redirection of output causes the file whose name results from
 
3640
the expansion of
 
3641
.I word
 
3642
to be opened for writing on file descriptor
 
3643
.IR n ,
 
3644
or the standard output (file descriptor 1) if
 
3645
.I n
 
3646
is not specified.  If the file does not exist it is created;
 
3647
if it does exist it is truncated to zero size.
 
3648
.PP
 
3649
The general format for redirecting output is:
 
3650
.RS
 
3651
.PP
 
3652
[\fIn\fP]\fB>\fP\fIword\fP
 
3653
.RE
 
3654
.PP
 
3655
If the redirection operator is
 
3656
.BR > ,
 
3657
and the
 
3658
.B noclobber
 
3659
option to the
 
3660
.B set
 
3661
builtin has been enabled, the redirection will fail if the file
 
3662
whose name results from the expansion of \fIword\fP exists and is
 
3663
a regular file.
 
3664
If the redirection operator is
 
3665
.BR >| ,
 
3666
or the redirection operator is
 
3667
.B >
 
3668
and the
 
3669
.B noclobber
 
3670
option to the
 
3671
.B set
 
3672
builtin command is not enabled, the redirection is attempted even
 
3673
if the file named by \fIword\fP exists.
 
3674
.SS Appending Redirected Output
 
3675
.PP
 
3676
Redirection of output in this fashion
 
3677
causes the file whose name results from
 
3678
the expansion of
 
3679
.I word
 
3680
to be opened for appending on file descriptor
 
3681
.IR n ,
 
3682
or the standard output (file descriptor 1) if
 
3683
.I n
 
3684
is not specified.  If the file does not exist it is created.
 
3685
.PP
 
3686
The general format for appending output is:
 
3687
.RS
 
3688
.PP
 
3689
[\fIn\fP]\fB>>\fP\fIword\fP
 
3690
.RE
 
3691
.PP
 
3692
.SS Redirecting Standard Output and Standard Error
 
3693
.PP
 
3694
This construct allows both the
 
3695
standard output (file descriptor 1) and
 
3696
the standard error output (file descriptor 2)
 
3697
to be redirected to the file whose name is the
 
3698
expansion of
 
3699
.IR word .
 
3700
.PP
 
3701
There are two formats for redirecting standard output and
 
3702
standard error:
 
3703
.RS
 
3704
.PP
 
3705
\fB&>\fP\fIword\fP
 
3706
.RE
 
3707
and
 
3708
.RS
 
3709
\fB>&\fP\fIword\fP
 
3710
.RE
 
3711
.PP
 
3712
Of the two forms, the first is preferred.
 
3713
This is semantically equivalent to
 
3714
.RS
 
3715
.PP
 
3716
\fB>\fP\fIword\fP 2\fB>&\fP1
 
3717
.RE
 
3718
.PP
 
3719
When using the second form, \fIword\fP may not expand to a number or
 
3720
\fB\-\fP.  If it does, other redirection operators apply
 
3721
(see \fBDuplicating File Descriptors\fP below) for compatibility
 
3722
reasons.
 
3723
.SS Appending Standard Output and Standard Error
 
3724
.PP
 
3725
This construct allows both the
 
3726
standard output (file descriptor 1) and
 
3727
the standard error output (file descriptor 2)
 
3728
to be appended to the file whose name is the
 
3729
expansion of
 
3730
.IR word .
 
3731
.PP
 
3732
The format for appending standard output and standard error is:
 
3733
.RS
 
3734
.PP
 
3735
\fB&>>\fP\fIword\fP
 
3736
.RE
 
3737
.PP
 
3738
This is semantically equivalent to
 
3739
.RS
 
3740
.PP
 
3741
\fB>>\fP\fIword\fP 2\fB>&\fP1
 
3742
.RE
 
3743
.PP
 
3744
(see \fBDuplicating File Descriptors\fP below).
 
3745
.SS Here Documents
 
3746
.PP
 
3747
This type of redirection instructs the shell to read input from the
 
3748
current source until a line containing only
 
3749
.I delimiter
 
3750
(with no trailing blanks)
 
3751
is seen.  All of
 
3752
the lines read up to that point are then used as the standard
 
3753
input for a command.
 
3754
.PP
 
3755
The format of here-documents is:
 
3756
.RS
 
3757
.PP
 
3758
.nf
 
3759
\fB<<\fP[\fB\-\fP]\fIword\fP
 
3760
        \fIhere-document\fP
 
3761
\fIdelimiter\fP
 
3762
.fi
 
3763
.RE
 
3764
.PP
 
3765
No parameter and variable expansion, command substitution,
 
3766
arithmetic expansion, or pathname expansion is performed on
 
3767
.IR word .
 
3768
If any characters in
 
3769
.I word
 
3770
are quoted, the
 
3771
.I delimiter
 
3772
is the result of quote removal on
 
3773
.IR word ,
 
3774
and the lines in the here-document are not expanded.
 
3775
If \fIword\fP is unquoted,
 
3776
all lines of the here-document are subjected to
 
3777
parameter expansion, command substitution, and arithmetic expansion,
 
3778
the character sequence
 
3779
.B \e<newline>
 
3780
is ignored, and
 
3781
.B \e
 
3782
must be used to quote the characters
 
3783
.BR \e ,
 
3784
.BR $ ,
 
3785
and
 
3786
.BR \` .
 
3787
.PP
 
3788
If the redirection operator is
 
3789
.BR <<\- ,
 
3790
then all leading tab characters are stripped from input lines and the
 
3791
line containing
 
3792
.IR delimiter .
 
3793
This allows
 
3794
here-documents within shell scripts to be indented in a
 
3795
natural fashion.
 
3796
.SS "Here Strings"
 
3797
A variant of here documents, the format is:
 
3798
.RS
 
3799
.PP
 
3800
.nf
 
3801
\fB<<<\fP\fIword\fP
 
3802
.fi
 
3803
.RE
 
3804
.PP
 
3805
The \fIword\fP undergoes
 
3806
brace expansion, tilde expansion, parameter and variable expansion,
 
3807
command substitution, arithmetic expansion, and quote removal.
 
3808
Pathname expansion and word splitting are not performed.
 
3809
The result is supplied as a single string to the command on its
 
3810
standard input.
 
3811
.SS "Duplicating File Descriptors"
 
3812
.PP
 
3813
The redirection operator
 
3814
.RS
 
3815
.PP
 
3816
[\fIn\fP]\fB<&\fP\fIword\fP
 
3817
.RE
 
3818
.PP
 
3819
is used to duplicate input file descriptors.
 
3820
If
 
3821
.I word
 
3822
expands to one or more digits, the file descriptor denoted by
 
3823
.I n
 
3824
is made to be a copy of that file descriptor.
 
3825
If the digits in
 
3826
.I word
 
3827
do not specify a file descriptor open for input, a redirection error occurs.
 
3828
If
 
3829
.I word
 
3830
evaluates to
 
3831
.BR \- ,
 
3832
file descriptor
 
3833
.I n
 
3834
is closed.  If
 
3835
.I n
 
3836
is not specified, the standard input (file descriptor 0) is used.
 
3837
.PP
 
3838
The operator
 
3839
.RS
 
3840
.PP
 
3841
[\fIn\fP]\fB>&\fP\fIword\fP
 
3842
.RE
 
3843
.PP
 
3844
is used similarly to duplicate output file descriptors.  If
 
3845
.I n
 
3846
is not specified, the standard output (file descriptor 1) is used.
 
3847
If the digits in
 
3848
.I word
 
3849
do not specify a file descriptor open for output, a redirection error occurs.
 
3850
If
 
3851
.I word
 
3852
evaluates to
 
3853
.BR \- ,
 
3854
file descriptor
 
3855
.I n
 
3856
is closed.
 
3857
As a special case, if \fIn\fP is omitted, and \fIword\fP does not
 
3858
expand to one or more digits or \fB\-\fP, the standard output and standard
 
3859
error are redirected as described previously.
 
3860
.SS "Moving File Descriptors"
 
3861
.PP
 
3862
The redirection operator
 
3863
.RS
 
3864
.PP
 
3865
[\fIn\fP]\fB<&\fP\fIdigit\fP\fB\-\fP
 
3866
.RE
 
3867
.PP
 
3868
moves the file descriptor \fIdigit\fP to file descriptor
 
3869
.IR n ,
 
3870
or the standard input (file descriptor 0) if \fIn\fP is not specified.
 
3871
\fIdigit\fP is closed after being duplicated to \fIn\fP.
 
3872
.PP
 
3873
Similarly, the redirection operator
 
3874
.RS
 
3875
.PP
 
3876
[\fIn\fP]\fB>&\fP\fIdigit\fP\fB\-\fP
 
3877
.RE
 
3878
.PP
 
3879
moves the file descriptor \fIdigit\fP to file descriptor
 
3880
.IR n ,
 
3881
or the standard output (file descriptor 1) if \fIn\fP is not specified.
 
3882
.SS "Opening File Descriptors for Reading and Writing"
 
3883
.PP
 
3884
The redirection operator
 
3885
.RS
 
3886
.PP
 
3887
[\fIn\fP]\fB<>\fP\fIword\fP
 
3888
.RE
 
3889
.PP
 
3890
causes the file whose name is the expansion of
 
3891
.I word
 
3892
to be opened for both reading and writing on file descriptor
 
3893
.IR n ,
 
3894
or on file descriptor 0 if
 
3895
.I n
 
3896
is not specified.  If the file does not exist, it is created.
 
3897
.SH ALIASES
 
3898
\fIAliases\fP allow a string to be substituted for a word when it is used
 
3899
as the first word of a simple command.
 
3900
The shell maintains a list of aliases that may be set and unset with the
 
3901
.B alias
 
3902
and
 
3903
.B unalias
 
3904
builtin commands (see
 
3905
.SM
 
3906
.B SHELL BUILTIN COMMANDS
 
3907
below).
 
3908
The first word of each simple command, if unquoted,
 
3909
is checked to see if it has an
 
3910
alias.  If so, that word is replaced by the text of the alias.
 
3911
The characters \fB/\fP, \fB$\fP, \fB\`\fP, and \fB=\fP and
 
3912
any of the shell \fImetacharacters\fP or quoting characters
 
3913
listed above may not appear in an alias name.
 
3914
The replacement text may contain any valid shell input,
 
3915
including shell metacharacters.
 
3916
The first word of the replacement text is tested
 
3917
for aliases, but a word that is identical to an alias being expanded
 
3918
is not expanded a second time.
 
3919
This means that one may alias
 
3920
.B ls
 
3921
to
 
3922
.BR "ls \-F" ,
 
3923
for instance, and
 
3924
.B bash
 
3925
does not try to recursively expand the replacement text.
 
3926
If the last character of the alias value is a
 
3927
.IR blank ,
 
3928
then the next command
 
3929
word following the alias is also checked for alias expansion.
 
3930
.PP
 
3931
Aliases are created and listed with the
 
3932
.B alias
 
3933
command, and removed with the
 
3934
.B unalias
 
3935
command.
 
3936
.PP
 
3937
There is no mechanism for using arguments in the replacement text.
 
3938
If arguments are needed, a shell function should be used (see
 
3939
.SM
 
3940
.B FUNCTIONS
 
3941
below).
 
3942
.PP
 
3943
Aliases are not expanded when the shell is not interactive, unless
 
3944
the
 
3945
.B expand_aliases
 
3946
shell option is set using
 
3947
.B shopt
 
3948
(see the description of
 
3949
.B shopt
 
3950
under
 
3951
.SM
 
3952
\fBSHELL BUILTIN COMMANDS\fP
 
3953
below).
 
3954
.PP
 
3955
The rules concerning the definition and use of aliases are
 
3956
somewhat confusing.
 
3957
.B Bash
 
3958
always reads at least one complete line
 
3959
of input before executing any
 
3960
of the commands on that line.  Aliases are expanded when a
 
3961
command is read, not when it is executed.  Therefore, an
 
3962
alias definition appearing on the same line as another
 
3963
command does not take effect until the next line of input is read.
 
3964
The commands following the alias definition
 
3965
on that line are not affected by the new alias.
 
3966
This behavior is also an issue when functions are executed.
 
3967
Aliases are expanded when a function definition is read,
 
3968
not when the function is executed, because a function definition
 
3969
is itself a compound command.  As a consequence, aliases
 
3970
defined in a function are not available until after that
 
3971
function is executed.  To be safe, always put
 
3972
alias definitions on a separate line, and do not use
 
3973
.B alias
 
3974
in compound commands.
 
3975
.PP
 
3976
For almost every purpose, aliases are superseded by
 
3977
shell functions.
 
3978
.SH FUNCTIONS
 
3979
A shell function, defined as described above under
 
3980
.SM
 
3981
.BR "SHELL GRAMMAR" ,
 
3982
stores a series of commands for later execution.
 
3983
When the name of a shell function is used as a simple command name,
 
3984
the list of commands associated with that function name is executed.
 
3985
Functions are executed in the context of the
 
3986
current shell; no new process is created to interpret
 
3987
them (contrast this with the execution of a shell script).
 
3988
When a function is executed, the arguments to the
 
3989
function become the positional parameters
 
3990
during its execution.
 
3991
The special parameter
 
3992
.B #
 
3993
is updated to reflect the change.  Special parameter \fB0\fP
 
3994
is unchanged.
 
3995
The first element of the
 
3996
.SM
 
3997
.B FUNCNAME
 
3998
variable is set to the name of the function while the function
 
3999
is executing.
 
4000
.PP
 
4001
All other aspects of the shell execution
 
4002
environment are identical between a function and its caller
 
4003
with these exceptions:  the
 
4004
.SM
 
4005
.B DEBUG
 
4006
and
 
4007
.B RETURN
 
4008
traps (see the description of the
 
4009
.B trap
 
4010
builtin under
 
4011
.SM
 
4012
.B SHELL BUILTIN COMMANDS
 
4013
below) are not inherited unless the function has been given the
 
4014
\fBtrace\fP attribute (see the description of the
 
4015
.SM
 
4016
.B declare
 
4017
builtin below) or the
 
4018
\fB\-o functrace\fP shell option has been enabled with
 
4019
the \fBset\fP builtin
 
4020
(in which case all functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps),
 
4021
and the
 
4022
.SM
 
4023
.B ERR
 
4024
trap is not inherited unless the \fB\-o errtrace\fP shell option has
 
4025
been enabled.
 
4026
.PP
 
4027
Variables local to the function may be declared with the
 
4028
.B local
 
4029
builtin command.  Ordinarily, variables and their values
 
4030
are shared between the function and its caller.
 
4031
.PP
 
4032
The \fBFUNCNEST\fP variable, if set to a numeric value greater
 
4033
than 0, defines a maximum function nesting level.  Function
 
4034
invocations that exceed the limit cause the entire command to
 
4035
abort.
 
4036
.PP
 
4037
If the builtin command
 
4038
.B return
 
4039
is executed in a function, the function completes and
 
4040
execution resumes with the next command after the function
 
4041
call.
 
4042
Any command associated with the \fBRETURN\fP trap is executed
 
4043
before execution resumes.
 
4044
When a function completes, the values of the
 
4045
positional parameters and the special parameter
 
4046
.B #
 
4047
are restored to the values they had prior to the function's
 
4048
execution.
 
4049
.PP
 
4050
Function names and definitions may be listed with the
 
4051
.B \-f
 
4052
option to the
 
4053
.B declare
 
4054
or
 
4055
.B typeset
 
4056
builtin commands.  The
 
4057
.B \-F
 
4058
option to
 
4059
.B declare
 
4060
or
 
4061
.B typeset
 
4062
will list the function names only
 
4063
(and optionally the source file and line number, if the \fBextdebug\fP
 
4064
shell option is enabled).
 
4065
Functions may be exported so that subshells
 
4066
automatically have them defined with the
 
4067
.B \-f
 
4068
option to the 
 
4069
.B export
 
4070
builtin.
 
4071
A function definition may be deleted using the \fB\-f\fP option to
 
4072
the
 
4073
.B unset
 
4074
builtin.
 
4075
Note that shell functions and variables with the same name may result
 
4076
in multiple identically-named entries in the environment passed to the
 
4077
shell's children.
 
4078
Care should be taken in cases where this may cause a problem.
 
4079
.PP
 
4080
Functions may be recursive.
 
4081
The \fBFUNCNEST\fP variable may be used to limit the depth of the
 
4082
function call stack and restrict the number of function invocations.
 
4083
By default, no limit is imposed on the number of recursive calls.
 
4084
.SH "ARITHMETIC EVALUATION"
 
4085
The shell allows arithmetic expressions to be evaluated, under
 
4086
certain circumstances (see the \fBlet\fP and \fBdeclare\fP builtin
 
4087
commands and \fBArithmetic Expansion\fP).
 
4088
Evaluation is done in fixed-width integers with no check for overflow,
 
4089
though division by 0 is trapped and flagged as an error.
 
4090
The operators and their precedence, associativity, and values
 
4091
are the same as in the C language.
 
4092
The following list of operators is grouped into levels of
 
4093
equal-precedence operators.
 
4094
The levels are listed in order of decreasing precedence.
 
4095
.PP
 
4096
.PD 0
 
4097
.TP
 
4098
.B \fIid\fP++ \fIid\fP\-\-
 
4099
variable post-increment and post-decrement
 
4100
.TP
 
4101
.B ++\fIid\fP \-\-\fIid\fP
 
4102
variable pre-increment and pre-decrement
 
4103
.TP
 
4104
.B \- +
 
4105
unary minus and plus
 
4106
.TP
 
4107
.B ! ~
 
4108
logical and bitwise negation
 
4109
.TP
 
4110
.B **
 
4111
exponentiation
 
4112
.TP
 
4113
.B * / %
 
4114
multiplication, division, remainder
 
4115
.TP
 
4116
.B + \-
 
4117
addition, subtraction
 
4118
.TP
 
4119
.B << >>
 
4120
left and right bitwise shifts
 
4121
.TP
 
4122
.B <= >= < >
 
4123
comparison
 
4124
.TP
 
4125
.B == !=
 
4126
equality and inequality
 
4127
.TP
 
4128
.B &
 
4129
bitwise AND
 
4130
.TP
 
4131
.B ^
 
4132
bitwise exclusive OR
 
4133
.TP
 
4134
.B |
 
4135
bitwise OR
 
4136
.TP
 
4137
.B &&
 
4138
logical AND
 
4139
.TP
 
4140
.B ||
 
4141
logical OR
 
4142
.TP
 
4143
.B \fIexpr\fP?\fIexpr\fP:\fIexpr\fP
 
4144
conditional operator
 
4145
.TP
 
4146
.B = *= /= %= += \-= <<= >>= &= ^= |=
 
4147
assignment
 
4148
.TP
 
4149
.B \fIexpr1\fP , \fIexpr2\fP
 
4150
comma
 
4151
.PD
 
4152
.PP
 
4153
Shell variables are allowed as operands; parameter expansion is
 
4154
performed before the expression is evaluated.
 
4155
Within an expression, shell variables may also be referenced by name
 
4156
without using the parameter expansion syntax.
 
4157
A shell variable that is null or unset evaluates to 0 when referenced
 
4158
by name without using the parameter expansion syntax.
 
4159
The value of a variable is evaluated as an arithmetic expression
 
4160
when it is referenced, or when a variable which has been given the
 
4161
\fIinteger\fP attribute using \fBdeclare -i\fP is assigned a value.
 
4162
A null value evaluates to 0.
 
4163
A shell variable need not have its \fIinteger\fP attribute
 
4164
turned on to be used in an expression.
 
4165
.PP
 
4166
Constants with a leading 0 are interpreted as octal numbers.
 
4167
A leading 0x or 0X denotes hexadecimal.
 
4168
Otherwise, numbers take the form [\fIbase#\fP]n, where the optional \fIbase\fP
 
4169
is a decimal number between 2 and 64 representing the arithmetic
 
4170
base, and \fIn\fP is a number in that base.
 
4171
If \fIbase#\fP is omitted, then base 10 is used.
 
4172
When specifying \fIn\fP,
 
4173
the digits greater< than 9 are represented by the lowercase letters,
 
4174
the uppercase letters, @, and _, in that order.
 
4175
If \fIbase\fP is less than or equal to 36, lowercase and uppercase
 
4176
letters may be used interchangeably to represent numbers between 10
 
4177
and 35.
 
4178
.PP
 
4179
Operators are evaluated in order of precedence.  Sub-expressions in
 
4180
parentheses are evaluated first and may override the precedence
 
4181
rules above.
 
4182
.SH "CONDITIONAL EXPRESSIONS"
 
4183
Conditional expressions are used by the \fB[[\fP compound command and
 
4184
the \fBtest\fP and \fB[\fP builtin commands to test file attributes
 
4185
and perform string and arithmetic comparisons.
 
4186
Expressions are formed from the following unary or binary primaries.
 
4187
If any \fIfile\fP argument to one of the primaries is of the form
 
4188
\fI/dev/fd/n\fP, then file descriptor \fIn\fP is checked.
 
4189
If the \fIfile\fP argument to one of the primaries is one of
 
4190
\fI/dev/stdin\fP, \fI/dev/stdout\fP, or \fI/dev/stderr\fP, file
 
4191
descriptor 0, 1, or 2, respectively, is checked.
 
4192
.PP
 
4193
Unless otherwise specified, primaries that operate on files follow symbolic
 
4194
links and operate on the target of the link, rather than the link itself.
 
4195
.if t .sp 0.5
 
4196
.if n .sp 1
 
4197
When used with \fB[[\fP, the \fB<\fP and \fB>\fP operators sort
 
4198
lexicographically using the current locale.
 
4199
The \fBtest\fP command sorts using ASCII ordering.
 
4200
.sp 1
 
4201
.PD 0
 
4202
.TP
 
4203
.B \-a \fIfile\fP
 
4204
True if \fIfile\fP exists.
 
4205
.TP
 
4206
.B \-b \fIfile\fP
 
4207
True if \fIfile\fP exists and is a block special file.
 
4208
.TP
 
4209
.B \-c \fIfile\fP
 
4210
True if \fIfile\fP exists and is a character special file.
 
4211
.TP
 
4212
.B \-d \fIfile\fP
 
4213
True if \fIfile\fP exists and is a directory.
 
4214
.TP
 
4215
.B \-e \fIfile\fP
 
4216
True if \fIfile\fP exists.
 
4217
.TP
 
4218
.B \-f \fIfile\fP
 
4219
True if \fIfile\fP exists and is a regular file.
 
4220
.TP
 
4221
.B \-g \fIfile\fP
 
4222
True if \fIfile\fP exists and is set-group-id.
 
4223
.TP
 
4224
.B \-h \fIfile\fP
 
4225
True if \fIfile\fP exists and is a symbolic link.
 
4226
.TP
 
4227
.B \-k \fIfile\fP
 
4228
True if \fIfile\fP exists and its ``sticky'' bit is set.
 
4229
.TP
 
4230
.B \-p \fIfile\fP
 
4231
True if \fIfile\fP exists and is a named pipe (FIFO).
 
4232
.TP
 
4233
.B \-r \fIfile\fP
 
4234
True if \fIfile\fP exists and is readable.
 
4235
.TP
 
4236
.B \-s \fIfile\fP
 
4237
True if \fIfile\fP exists and has a size greater than zero.
 
4238
.TP
 
4239
.B \-t \fIfd\fP
 
4240
True if file descriptor
 
4241
.I fd
 
4242
is open and refers to a terminal.
 
4243
.TP
 
4244
.B \-u \fIfile\fP
 
4245
True if \fIfile\fP exists and its set-user-id bit is set.
 
4246
.TP
 
4247
.B \-w \fIfile\fP
 
4248
True if \fIfile\fP exists and is writable.
 
4249
.TP
 
4250
.B \-x \fIfile\fP
 
4251
True if \fIfile\fP exists and is executable.
 
4252
.TP
 
4253
.B \-G \fIfile\fP
 
4254
True if \fIfile\fP exists and is owned by the effective group id.
 
4255
.TP
 
4256
.B \-L \fIfile\fP
 
4257
True if \fIfile\fP exists and is a symbolic link.
 
4258
.TP
 
4259
.B \-N \fIfile\fP
 
4260
True if \fIfile\fP exists and has been modified since it was last read.
 
4261
.TP
 
4262
.B \-O \fIfile\fP
 
4263
True if \fIfile\fP exists and is owned by the effective user id.
 
4264
.TP
 
4265
.B \-S \fIfile\fP
 
4266
True if \fIfile\fP exists and is a socket.
 
4267
.TP
 
4268
\fIfile1\fP \fB\-ef\fP \fIfile2\fP
 
4269
True if \fIfile1\fP and \fIfile2\fP refer to the same device and
 
4270
inode numbers.
 
4271
.TP
 
4272
\fIfile1\fP \-\fBnt\fP \fIfile2\fP
 
4273
True if \fIfile1\fP is newer (according to modification date) than \fIfile2\fP,
 
4274
or if \fIfile1\fP exists and \fPfile2\fP does not.
 
4275
.TP
 
4276
\fIfile1\fP \-\fBot\fP \fIfile2\fP
 
4277
True if \fIfile1\fP is older than \fIfile2\fP, or if \fIfile2\fP exists
 
4278
and \fIfile1\fP does not.
 
4279
.TP
 
4280
.B \-o \fIoptname\fP
 
4281
True if the shell option
 
4282
.I optname
 
4283
is enabled.
 
4284
See the list of options under the description of the
 
4285
.B \-o
 
4286
option to the
 
4287
.B set
 
4288
builtin below.
 
4289
.TP
 
4290
.B \-v \fIvarname\fP
 
4291
True if the shell variable
 
4292
.I varname
 
4293
is set (has been assigned a value).
 
4294
.TP
 
4295
.B \-R \fIvarname\fP
 
4296
True if the shell variable
 
4297
.I varname
 
4298
is set and is a name reference.
 
4299
.TP
 
4300
.B \-z \fIstring\fP
 
4301
True if the length of \fIstring\fP is zero.
 
4302
.TP
 
4303
\fIstring\fP
 
4304
.PD 0
 
4305
.TP
 
4306
.B \-n \fIstring\fP
 
4307
.PD
 
4308
True if the length of
 
4309
.I string
 
4310
is non-zero.
 
4311
.TP
 
4312
\fIstring1\fP \fB==\fP \fIstring2\fP
 
4313
.PD 0
 
4314
.TP
 
4315
\fIstring1\fP \fB=\fP \fIstring2\fP
 
4316
.PD
 
4317
True if the strings are equal.  \fB=\fP should be used
 
4318
with the \fBtest\fP command for POSIX conformance.
 
4319
When used with the \fB[[\fP command, this performs pattern matching as
 
4320
described above (\fBCompound Commands\fP).
 
4321
.TP
 
4322
\fIstring1\fP \fB!=\fP \fIstring2\fP
 
4323
True if the strings are not equal.
 
4324
.TP
 
4325
\fIstring1\fP \fB<\fP \fIstring2\fP
 
4326
True if \fIstring1\fP sorts before \fIstring2\fP lexicographically.
 
4327
.TP
 
4328
\fIstring1\fP \fB>\fP \fIstring2\fP
 
4329
True if \fIstring1\fP sorts after \fIstring2\fP lexicographically.
 
4330
.TP
 
4331
.I \fIarg1\fP \fBOP\fP \fIarg2\fP
 
4332
.SM
 
4333
.B OP
 
4334
is one of
 
4335
.BR \-eq ,
 
4336
.BR \-ne ,
 
4337
.BR \-lt ,
 
4338
.BR \-le ,
 
4339
.BR \-gt ,
 
4340
or
 
4341
.BR \-ge .
 
4342
These arithmetic binary operators return true if \fIarg1\fP
 
4343
is equal to, not equal to, less than, less than or equal to,
 
4344
greater than, or greater than or equal to \fIarg2\fP, respectively.
 
4345
.I Arg1
 
4346
and
 
4347
.I arg2
 
4348
may be positive or negative integers.
 
4349
.PD
 
4350
.SH "SIMPLE COMMAND EXPANSION"
 
4351
When a simple command is executed, the shell performs the following
 
4352
expansions, assignments, and redirections, from left to right.
 
4353
.IP 1.
 
4354
The words that the parser has marked as variable assignments (those
 
4355
preceding the command name) and redirections are saved for later
 
4356
processing.
 
4357
.IP 2.
 
4358
The words that are not variable assignments or redirections are
 
4359
expanded.  If any words remain after expansion, the first word
 
4360
is taken to be the name of the command and the remaining words are
 
4361
the arguments.
 
4362
.IP 3.
 
4363
Redirections are performed as described above under
 
4364
.SM
 
4365
.BR REDIRECTION .
 
4366
.IP 4.
 
4367
The text after the \fB=\fP in each variable assignment undergoes tilde
 
4368
expansion, parameter expansion, command substitution, arithmetic expansion,
 
4369
and quote removal before being assigned to the variable.
 
4370
.PP
 
4371
If no command name results, the variable assignments affect the current
 
4372
shell environment.  Otherwise, the variables are added to the environment
 
4373
of the executed command and do not affect the current shell environment.
 
4374
If any of the assignments attempts to assign a value to a readonly variable,
 
4375
an error occurs, and the command exits with a non-zero status.
 
4376
.PP
 
4377
If no command name results, redirections are performed, but do not
 
4378
affect the current shell environment.  A redirection error causes the
 
4379
command to exit with a non-zero status.
 
4380
.PP
 
4381
If there is a command name left after expansion, execution proceeds as
 
4382
described below.  Otherwise, the command exits.  If one of the expansions
 
4383
contained a command substitution, the exit status of the command is
 
4384
the exit status of the last command substitution performed.  If there
 
4385
were no command substitutions, the command exits with a status of zero.
 
4386
.SH "COMMAND EXECUTION"
 
4387
After a command has been split into words, if it results in a
 
4388
simple command and an optional list of arguments, the following
 
4389
actions are taken.
 
4390
.PP
 
4391
If the command name contains no slashes, the shell attempts to
 
4392
locate it.  If there exists a shell function by that name, that
 
4393
function is invoked as described above in
 
4394
.SM
 
4395
.BR FUNCTIONS .
 
4396
If the name does not match a function, the shell searches for
 
4397
it in the list of shell builtins.  If a match is found, that
 
4398
builtin is invoked.
 
4399
.PP
 
4400
If the name is neither a shell function nor a builtin,
 
4401
and contains no slashes,
 
4402
.B bash
 
4403
searches each element of the
 
4404
.SM
 
4405
.B PATH
 
4406
for a directory containing an executable file by that name.
 
4407
.B Bash
 
4408
uses a hash table to remember the full pathnames of executable
 
4409
files (see
 
4410
.B hash
 
4411
under
 
4412
.SM
 
4413
.B "SHELL BUILTIN COMMANDS"
 
4414
below).
 
4415
A full search of the directories in
 
4416
.SM
 
4417
.B PATH
 
4418
is performed only if the command is not found in the hash table.
 
4419
If the search is unsuccessful, the shell searches for a defined shell
 
4420
function named \fBcommand_not_found_handle\fP.
 
4421
If that function exists, it is invoked with the original command and
 
4422
the original command's arguments as its arguments, and the function's
 
4423
exit status becomes the exit status of the shell.
 
4424
If that function is not defined, the shell prints an error
 
4425
message and returns an exit status of 127.
 
4426
.PP
 
4427
If the search is successful, or if the command name contains
 
4428
one or more slashes, the shell executes the named program in a
 
4429
separate execution environment.
 
4430
Argument 0 is set to the name given, and the remaining arguments
 
4431
to the command are set to the arguments given, if any.
 
4432
.PP
 
4433
If this execution fails because the file is not in executable
 
4434
format, and the file is not a directory, it is assumed to be
 
4435
a \fIshell script\fP, a file
 
4436
containing shell commands.  A subshell is spawned to execute
 
4437
it.  This subshell reinitializes itself, so
 
4438
that the effect is as if a new shell had been invoked
 
4439
to handle the script, with the exception that the locations of
 
4440
commands remembered by the parent (see
 
4441
.B hash
 
4442
below under
 
4443
.SM
 
4444
\fBSHELL BUILTIN COMMANDS\fP)
 
4445
are retained by the child.
 
4446
.PP
 
4447
If the program is a file beginning with
 
4448
.BR #! ,
 
4449
the remainder of the first line specifies an interpreter
 
4450
for the program.  The shell executes the
 
4451
specified interpreter on operating systems that do not
 
4452
handle this executable format themselves.  The arguments to the 
 
4453
interpreter consist of a single optional argument following the
 
4454
interpreter name on the first line of the program, followed
 
4455
by the name of the program, followed by the command
 
4456
arguments, if any.
 
4457
.SH COMMAND EXECUTION ENVIRONMENT
 
4458
The shell has an \fIexecution environment\fP, which consists of the
 
4459
following:
 
4460
.IP \(bu
 
4461
open files inherited by the shell at invocation, as modified by
 
4462
redirections supplied to the \fBexec\fP builtin
 
4463
.IP \(bu
 
4464
the current working directory as set by \fBcd\fP, \fBpushd\fP, or
 
4465
\fBpopd\fP, or inherited by the shell at invocation
 
4466
.IP \(bu
 
4467
the file creation mode mask as set by \fBumask\fP or inherited from
 
4468
the shell's parent
 
4469
.IP \(bu
 
4470
current traps set by \fBtrap\fP
 
4471
.IP \(bu
 
4472
shell parameters that are set by variable assignment or with \fBset\fP
 
4473
or inherited from the shell's parent in the environment
 
4474
.IP \(bu
 
4475
shell functions defined during execution or inherited from the shell's
 
4476
parent in the environment
 
4477
.IP \(bu
 
4478
options enabled at invocation (either by default or with command-line
 
4479
arguments) or by \fBset\fP
 
4480
.IP \(bu
 
4481
options enabled by \fBshopt\fP
 
4482
.IP \(bu
 
4483
shell aliases defined with \fBalias\fP
 
4484
.IP \(bu
 
4485
various process IDs, including those of background jobs, the value
 
4486
of \fB$$\fP, and the value of
 
4487
.SM
 
4488
.B PPID
 
4489
.PP
 
4490
When a simple command other than a builtin or shell function
 
4491
is to be executed, it
 
4492
is invoked in a separate execution environment that consists of
 
4493
the following.  Unless otherwise noted, the values are inherited
 
4494
from the shell.
 
4495
.if n .sp 1
 
4496
.IP \(bu
 
4497
the shell's open files, plus any modifications and additions specified
 
4498
by redirections to the command
 
4499
.IP \(bu
 
4500
the current working directory
 
4501
.IP \(bu
 
4502
the file creation mode mask
 
4503
.IP \(bu
 
4504
shell variables and functions marked for export, along with variables
 
4505
exported for the command, passed in the environment
 
4506
.IP \(bu
 
4507
traps caught by the shell are reset to the values inherited from the
 
4508
shell's parent, and traps ignored by the shell are ignored
 
4509
.PP
 
4510
A command invoked in this separate environment cannot affect the
 
4511
shell's execution environment. 
 
4512
.PP
 
4513
Command substitution, commands grouped with parentheses,
 
4514
and asynchronous commands are invoked in a
 
4515
subshell environment that is a duplicate of the shell environment,
 
4516
except that traps caught by the shell are reset to the values
 
4517
that the shell inherited from its parent at invocation.  Builtin
 
4518
commands that are invoked as part of a pipeline are also executed in a
 
4519
subshell environment.  Changes made to the subshell environment
 
4520
cannot affect the shell's execution environment.
 
4521
.PP
 
4522
Subshells spawned to execute command substitutions inherit the value of
 
4523
the \fB\-e\fP option from the parent shell.  When not in \fIposix\fP mode,
 
4524
\fBbash\fP clears the \fB\-e\fP option in such subshells.
 
4525
.PP
 
4526
If a command is followed by a \fB&\fP and job control is not active, the
 
4527
default standard input for the command is the empty file \fI/dev/null\fP.
 
4528
Otherwise, the invoked command inherits the file descriptors of the calling
 
4529
shell as modified by redirections.
 
4530
.SH ENVIRONMENT
 
4531
When a program is invoked it is given an array of strings
 
4532
called the
 
4533
.IR environment .
 
4534
This is a list of 
 
4535
\fIname\fP\-\fIvalue\fP pairs, of the form
 
4536
.IR "name\fR=\fPvalue" .
 
4537
.PP
 
4538
The shell provides several ways to manipulate the environment.
 
4539
On invocation, the shell scans its own environment and
 
4540
creates a parameter for each name found, automatically marking
 
4541
it for
 
4542
.I export
 
4543
to child processes.  Executed commands inherit the environment.
 
4544
The
 
4545
.B export
 
4546
and
 
4547
.B declare \-x
 
4548
commands allow parameters and functions to be added to and
 
4549
deleted from the environment.  If the value of a parameter
 
4550
in the environment is modified, the new value becomes part
 
4551
of the environment, replacing the old.  The environment
 
4552
inherited by any executed command consists of the shell's
 
4553
initial environment, whose values may be modified in the shell,
 
4554
less any pairs removed by the
 
4555
.B unset
 
4556
command, plus any additions via the
 
4557
.B export
 
4558
and
 
4559
.B declare \-x
 
4560
commands.
 
4561
.PP
 
4562
The environment for any
 
4563
.I simple command
 
4564
or function may be augmented temporarily by prefixing it with
 
4565
parameter assignments, as described above in
 
4566
.SM
 
4567
.BR PARAMETERS .
 
4568
These assignment statements affect only the environment seen
 
4569
by that command.
 
4570
.PP
 
4571
If the 
 
4572
.B \-k
 
4573
option is set (see the
 
4574
.B set
 
4575
builtin command below), then
 
4576
.I all
 
4577
parameter assignments are placed in the environment for a command,
 
4578
not just those that precede the command name.
 
4579
.PP
 
4580
When
 
4581
.B bash
 
4582
invokes an external command, the variable
 
4583
.B _
 
4584
is set to the full filename of the command and passed to that
 
4585
command in its environment.
 
4586
.SH "EXIT STATUS"
 
4587
.PP
 
4588
The exit status of an executed command is the value returned by the
 
4589
\fIwaitpid\fP system call or equivalent function.  Exit statuses
 
4590
fall between 0 and 255, though, as explained below, the shell may
 
4591
use values above 125 specially.  Exit statuses from shell builtins and
 
4592
compound commands are also limited to this range. Under certain
 
4593
circumstances, the shell will use special values to indicate specific
 
4594
failure modes.
 
4595
.PP
 
4596
For the shell's purposes, a command which exits with a 
 
4597
zero exit status has succeeded.  An exit status of zero
 
4598
indicates success.  A non-zero exit status indicates failure.
 
4599
When a command terminates on a fatal signal \fIN\fP, \fBbash\fP uses
 
4600
the value of 128+\fIN\fP as the exit status.
 
4601
.PP
 
4602
If a command is not found, the child process created to
 
4603
execute it returns a status of 127.  If a command is found
 
4604
but is not executable, the return status is 126.
 
4605
.PP
 
4606
If a command fails because of an error during expansion or redirection,
 
4607
the exit status is greater than zero.
 
4608
.PP
 
4609
Shell builtin commands return a status of 0 (\fItrue\fP) if
 
4610
successful, and non-zero (\fIfalse\fP) if an error occurs
 
4611
while they execute. 
 
4612
All builtins return an exit status of 2 to indicate incorrect usage.
 
4613
.PP
 
4614
\fBBash\fP itself returns the exit status of the last command
 
4615
executed, unless a syntax error occurs, in which case it exits
 
4616
with a non-zero value.  See also the \fBexit\fP builtin
 
4617
command below.
 
4618
.SH SIGNALS
 
4619
When \fBbash\fP is interactive, in the absence of any traps, it ignores
 
4620
.SM
 
4621
.B SIGTERM
 
4622
(so that \fBkill 0\fP does not kill an interactive shell),
 
4623
and
 
4624
.SM
 
4625
.B SIGINT
 
4626
is caught and handled (so that the \fBwait\fP builtin is interruptible).
 
4627
In all cases, \fBbash\fP ignores
 
4628
.SM
 
4629
.BR SIGQUIT .
 
4630
If job control is in effect,
 
4631
.B bash
 
4632
ignores
 
4633
.SM
 
4634
.BR SIGTTIN ,
 
4635
.SM
 
4636
.BR SIGTTOU ,
 
4637
and
 
4638
.SM
 
4639
.BR SIGTSTP .
 
4640
.PP
 
4641
Non-builtin commands run by \fBbash\fP have signal handlers
 
4642
set to the values inherited by the shell from its parent.
 
4643
When job control is not in effect, asynchronous commands
 
4644
ignore
 
4645
.SM
 
4646
.B SIGINT
 
4647
and
 
4648
.SM
 
4649
.B SIGQUIT
 
4650
in addition to these inherited handlers.
 
4651
Commands run as a result of command substitution ignore the
 
4652
keyboard-generated job control signals
 
4653
.SM
 
4654
.BR SIGTTIN ,
 
4655
.SM
 
4656
.BR SIGTTOU ,
 
4657
and
 
4658
.SM
 
4659
.BR SIGTSTP .
 
4660
.PP
 
4661
The shell exits by default upon receipt of a
 
4662
.SM
 
4663
.BR SIGHUP .
 
4664
Before exiting, an interactive shell resends the
 
4665
.SM
 
4666
.B SIGHUP
 
4667
to all jobs, running or stopped.
 
4668
Stopped jobs are sent
 
4669
.SM
 
4670
.B SIGCONT
 
4671
to ensure that they receive the
 
4672
.SM
 
4673
.BR SIGHUP .
 
4674
To prevent the shell from
 
4675
sending the signal to a particular job, it should be removed from the
 
4676
jobs table with the 
 
4677
.B disown
 
4678
builtin (see
 
4679
.SM
 
4680
.B "SHELL BUILTIN COMMANDS"
 
4681
below) or marked 
 
4682
to not receive
 
4683
.SM
 
4684
.B SIGHUP
 
4685
using
 
4686
.BR "disown \-h" .
 
4687
.PP
 
4688
If the
 
4689
.B huponexit
 
4690
shell option has been set with
 
4691
.BR shopt ,
 
4692
.B bash
 
4693
sends a 
 
4694
.SM
 
4695
.B SIGHUP
 
4696
to all jobs when an interactive login shell exits.
 
4697
.PP
 
4698
If \fBbash\fP is waiting for a command to complete and receives a signal
 
4699
for which a trap has been set, the trap will not be executed until
 
4700
the command completes. 
 
4701
When \fBbash\fP is waiting for an asynchronous command via the \fBwait\fP
 
4702
builtin, the reception of a signal for which a trap has been set will
 
4703
cause the \fBwait\fP builtin to return immediately with an exit status
 
4704
greater than 128, immediately after which the trap is executed.
 
4705
.SH "JOB CONTROL"
 
4706
.I Job control
 
4707
refers to the ability to selectively stop (\fIsuspend\fP)
 
4708
the execution of processes and continue (\fIresume\fP)
 
4709
their execution at a later point.  A user typically employs
 
4710
this facility via an interactive interface supplied jointly
 
4711
by the operating system kernel's terminal driver and
 
4712
.BR bash .
 
4713
.PP
 
4714
The shell associates a
 
4715
.I job
 
4716
with each pipeline.  It keeps a table of currently executing
 
4717
jobs, which may be listed with the
 
4718
.B jobs
 
4719
command.  When
 
4720
.B bash
 
4721
starts a job asynchronously (in the
 
4722
.IR background ),
 
4723
it prints a line that looks like:
 
4724
.RS
 
4725
.PP
 
4726
[1] 25647
 
4727
.RE
 
4728
.PP
 
4729
indicating that this job is job number 1 and that the process ID
 
4730
of the last process in the pipeline associated with this job is 25647.
 
4731
All of the processes in a single pipeline are members of the same job.
 
4732
.B Bash
 
4733
uses the
 
4734
.I job
 
4735
abstraction as the basis for job control.
 
4736
.PP
 
4737
To facilitate the implementation of the user interface to job
 
4738
control, the operating system maintains the notion of a \fIcurrent terminal
 
4739
process group ID\fP.  Members of this process group (processes whose
 
4740
process group ID is equal to the current terminal process group ID)
 
4741
receive keyboard-generated signals such as
 
4742
.SM
 
4743
.BR SIGINT .
 
4744
These processes are said to be in the
 
4745
.IR foreground .
 
4746
.I Background
 
4747
processes are those whose process group ID differs from the terminal's;
 
4748
such processes are immune to keyboard-generated signals.
 
4749
Only foreground processes are allowed to read from or, if the
 
4750
user so specifies with \f(CWstty tostop\fP, write to the
 
4751
terminal.
 
4752
Background processes which attempt to read from (write to when
 
4753
\f(CWstty tostop\fP is in effect) the
 
4754
terminal are sent a 
 
4755
.SM
 
4756
.B SIGTTIN (SIGTTOU)
 
4757
signal by the kernel's terminal driver, 
 
4758
which, unless caught, suspends the process.
 
4759
.PP
 
4760
If the operating system on which
 
4761
.B bash
 
4762
is running supports
 
4763
job control,
 
4764
.B bash
 
4765
contains facilities to use it.
 
4766
Typing the
 
4767
.I suspend
 
4768
character (typically
 
4769
.BR ^Z ,
 
4770
Control-Z) while a process is running
 
4771
causes that process to be stopped and returns control to 
 
4772
.BR bash .
 
4773
Typing the
 
4774
.I "delayed suspend"
 
4775
character (typically
 
4776
.BR ^Y ,
 
4777
Control-Y) causes the process to be stopped when it
 
4778
attempts to read input from the terminal, and control to
 
4779
be returned to
 
4780
.BR bash .
 
4781
The user may then manipulate the state of this job, using the
 
4782
.B bg
 
4783
command to continue it in the background, the
 
4784
.B fg
 
4785
command to continue it in the foreground, or
 
4786
the
 
4787
.B kill
 
4788
command to kill it.  A \fB^Z\fP takes effect immediately,
 
4789
and has the additional side effect of causing pending output
 
4790
and typeahead to be discarded.
 
4791
.PP
 
4792
There are a number of ways to refer to a job in the shell.
 
4793
The character
 
4794
.B %
 
4795
introduces a job specification (\fIjobspec\fP).  Job number
 
4796
.I n
 
4797
may be referred to as
 
4798
.BR %n .
 
4799
A job may also be referred to using a prefix of the name used to
 
4800
start it, or using a substring that appears in its command line.
 
4801
For example,
 
4802
.B %ce
 
4803
refers to a stopped
 
4804
.B ce
 
4805
job.  If a prefix matches more than one job,
 
4806
.B bash
 
4807
reports an error.  Using
 
4808
.BR %?ce ,
 
4809
on the other hand, refers to any job containing the string
 
4810
.B ce
 
4811
in its command line.  If the substring matches more than one job,
 
4812
.B bash
 
4813
reports an error.  The symbols
 
4814
.B %%
 
4815
and
 
4816
.B %+
 
4817
refer to the shell's notion of the
 
4818
.IR "current job" ,
 
4819
which is the last job stopped while it was in
 
4820
the foreground or started in the background.
 
4821
The 
 
4822
.I "previous job"
 
4823
may be referenced using
 
4824
.BR %\- .
 
4825
If there is only a single job, \fB%+\fP and \fB%\-\fP can both be used
 
4826
to refer to that job.
 
4827
In output pertaining to jobs (e.g., the output of the
 
4828
.B jobs
 
4829
command), the current job is always flagged with a
 
4830
.BR + ,
 
4831
and the previous job with a
 
4832
.BR \- .
 
4833
A single % (with no accompanying job specification) also refers to the
 
4834
current job.
 
4835
.PP
 
4836
Simply naming a job can be used to bring it into the
 
4837
foreground:
 
4838
.B %1
 
4839
is a synonym for
 
4840
\fB``fg %1''\fP,
 
4841
bringing job 1 from the background into the foreground.
 
4842
Similarly,
 
4843
.B ``%1 &''
 
4844
resumes job 1 in the background, equivalent to
 
4845
\fB``bg %1''\fP.
 
4846
.PP
 
4847
The shell learns immediately whenever a job changes state.
 
4848
Normally,
 
4849
.B bash
 
4850
waits until it is about to print a prompt before reporting
 
4851
changes in a job's status so as to not interrupt
 
4852
any other output.  If the 
 
4853
.B \-b
 
4854
option to the
 
4855
.B set
 
4856
builtin command
 
4857
is enabled,
 
4858
.B bash
 
4859
reports such changes immediately.
 
4860
Any trap on
 
4861
.SM
 
4862
.B SIGCHLD
 
4863
is executed for each child that exits.
 
4864
.PP
 
4865
If an attempt to exit
 
4866
.B bash
 
4867
is made while jobs are stopped (or, if the \fBcheckjobs\fP shell option has
 
4868
been enabled using the \fBshopt\fP builtin, running), the shell prints a
 
4869
warning message, and, if the \fBcheckjobs\fP option is enabled, lists the
 
4870
jobs and their statuses.
 
4871
The
 
4872
.B jobs
 
4873
command may then be used to inspect their status. 
 
4874
If a second attempt to exit is made without an intervening command,
 
4875
the shell does not print another warning, and any stopped
 
4876
jobs are terminated.
 
4877
.SH PROMPTING
 
4878
When executing interactively, 
 
4879
.B bash
 
4880
displays the primary prompt
 
4881
.SM
 
4882
.B PS1
 
4883
when it is ready to read a command, and the secondary prompt
 
4884
.SM
 
4885
.B PS2
 
4886
when it needs more input to complete a command.
 
4887
.B Bash
 
4888
allows these prompt strings to be customized by inserting a number of
 
4889
backslash-escaped special characters that are decoded as follows:
 
4890
.RS
 
4891
.PD 0
 
4892
.TP
 
4893
.B \ea
 
4894
an ASCII bell character (07)
 
4895
.TP
 
4896
.B \ed
 
4897
the date in "Weekday Month Date" format (e.g., "Tue May 26")
 
4898
.TP
 
4899
.B \eD{\fIformat\fP}
 
4900
the \fIformat\fP is passed to \fIstrftime\fP(3) and the result is inserted
 
4901
into the prompt string; an empty \fIformat\fP results in a locale-specific
 
4902
time representation.  The braces are required
 
4903
.TP
 
4904
.B \ee
 
4905
an ASCII escape character (033)
 
4906
.TP
 
4907
.B \eh
 
4908
the hostname up to the first `.'
 
4909
.TP
 
4910
.B \eH
 
4911
the hostname
 
4912
.TP
 
4913
.B \ej
 
4914
the number of jobs currently managed by the shell
 
4915
.TP
 
4916
.B \el
 
4917
the basename of the shell's terminal device name
 
4918
.TP
 
4919
.B \en
 
4920
newline
 
4921
.TP
 
4922
.B \er
 
4923
carriage return
 
4924
.TP
 
4925
.B \es
 
4926
the name of the shell, the basename of
 
4927
.B $0
 
4928
(the portion following the final slash)
 
4929
.TP
 
4930
.B \et
 
4931
the current time in 24-hour HH:MM:SS format
 
4932
.TP
 
4933
.B \eT
 
4934
the current time in 12-hour HH:MM:SS format
 
4935
.TP
 
4936
.B \e@
 
4937
the current time in 12-hour am/pm format
 
4938
.TP
 
4939
.B \eA
 
4940
the current time in 24-hour HH:MM format
 
4941
.TP
 
4942
.B \eu
 
4943
the username of the current user
 
4944
.TP
 
4945
.B \ev
 
4946
the version of \fBbash\fP (e.g., 2.00)
 
4947
.TP
 
4948
.B \eV
 
4949
the release of \fBbash\fP, version + patch level (e.g., 2.00.0)
 
4950
.TP
 
4951
.B \ew
 
4952
the current working directory, with
 
4953
.SM
 
4954
.B $HOME
 
4955
abbreviated with a tilde
 
4956
(uses the value of the
 
4957
.SM
 
4958
.B PROMPT_DIRTRIM
 
4959
variable)
 
4960
.TP
 
4961
.B \eW
 
4962
the basename of the current working directory, with
 
4963
.SM
 
4964
.B $HOME
 
4965
abbreviated with a tilde
 
4966
.TP
 
4967
.B \e!
 
4968
the history number of this command
 
4969
.TP
 
4970
.B \e#
 
4971
the command number of this command
 
4972
.TP
 
4973
.B \e$
 
4974
if the effective UID is 0, a
 
4975
.BR # ,
 
4976
otherwise a
 
4977
.B $
 
4978
.TP
 
4979
.B \e\fInnn\fP
 
4980
the character corresponding to the octal number \fInnn\fP
 
4981
.TP
 
4982
.B \e\e
 
4983
a backslash
 
4984
.TP
 
4985
.B \e[
 
4986
begin a sequence of non-printing characters, which could be used to
 
4987
embed a terminal control sequence into the prompt
 
4988
.TP
 
4989
.B \e]
 
4990
end a sequence of non-printing characters
 
4991
.PD
 
4992
.RE
 
4993
.PP
 
4994
The command number and the history number are usually different:
 
4995
the history number of a command is its position in the history
 
4996
list, which may include commands restored from the history file
 
4997
(see
 
4998
.SM
 
4999
.B HISTORY
 
5000
below), while the command number is the position in the sequence
 
5001
of commands executed during the current shell session.
 
5002
After the string is decoded, it is expanded via
 
5003
parameter expansion, command substitution, arithmetic
 
5004
expansion, and quote removal, subject to the value of the
 
5005
.B promptvars
 
5006
shell option (see the description of the
 
5007
.B shopt
 
5008
command under
 
5009
.SM
 
5010
.B "SHELL BUILTIN COMMANDS"
 
5011
below).
 
5012
.SH READLINE
 
5013
This is the library that handles reading input when using an interactive
 
5014
shell, unless the
 
5015
.B \-\-noediting
 
5016
option is given at shell invocation.
 
5017
Line editing is also used when using the \fB\-e\fP option to the
 
5018
\fBread\fP builtin.
 
5019
By default, the line editing commands are similar to those of Emacs.
 
5020
A vi-style line editing interface is also available.
 
5021
Line editing can be enabled at any time using the
 
5022
.B \-o emacs
 
5023
or
 
5024
.B \-o vi
 
5025
options to the
 
5026
.B set
 
5027
builtin (see
 
5028
.SM
 
5029
.B SHELL BUILTIN COMMANDS
 
5030
below).
 
5031
To turn off line editing after the shell is running, use the
 
5032
.B +o emacs
 
5033
or
 
5034
.B +o vi
 
5035
options to the
 
5036
.B set
 
5037
builtin.
 
5038
.SS "Readline Notation"
 
5039
.PP
 
5040
In this section, the Emacs-style notation is used to denote
 
5041
keystrokes.  Control keys are denoted by C\-\fIkey\fR, e.g., C\-n
 
5042
means Control\-N.  Similarly, 
 
5043
.I meta
 
5044
keys are denoted by M\-\fIkey\fR, so M\-x means Meta\-X.  (On keyboards
 
5045
without a 
 
5046
.I meta
 
5047
key, M\-\fIx\fP means ESC \fIx\fP, i.e., press the Escape key
 
5048
then the
 
5049
.I x
 
5050
key.  This makes ESC the \fImeta prefix\fP.
 
5051
The combination M\-C\-\fIx\fP means ESC\-Control\-\fIx\fP,
 
5052
or press the Escape key
 
5053
then hold the Control key while pressing the
 
5054
.I x
 
5055
key.)
 
5056
.PP
 
5057
Readline commands may be given numeric
 
5058
.IR arguments ,
 
5059
which normally act as a repeat count.
 
5060
Sometimes, however, it is the sign of the argument that is significant.
 
5061
Passing a negative argument to a command that acts in the forward
 
5062
direction (e.g., \fBkill\-line\fP) causes that command to act in a
 
5063
backward direction. 
 
5064
Commands whose behavior with arguments deviates from this are noted
 
5065
below.
 
5066
.PP
 
5067
When a command is described as \fIkilling\fP text, the text
 
5068
deleted is saved for possible future retrieval
 
5069
(\fIyanking\fP).  The killed text is saved in a
 
5070
\fIkill ring\fP.  Consecutive kills cause the text to be
 
5071
accumulated into one unit, which can be yanked all at once. 
 
5072
Commands which do not kill text separate the chunks of text
 
5073
on the kill ring.
 
5074
.SS "Readline Initialization"
 
5075
.PP
 
5076
Readline is customized by putting commands in an initialization
 
5077
file (the \fIinputrc\fP file).
 
5078
The name of this file is taken from the value of the
 
5079
.SM
 
5080
.B INPUTRC
 
5081
variable.  If that variable is unset, the default is
 
5082
.IR ~/.inputrc .
 
5083
When a program which uses the readline library starts up, the
 
5084
initialization file is read, and the key bindings and variables
 
5085
are set.
 
5086
There are only a few basic constructs allowed in the
 
5087
readline initialization file.
 
5088
Blank lines are ignored.
 
5089
Lines beginning with a \fB#\fP are comments.
 
5090
Lines beginning with a \fB$\fP indicate conditional constructs.
 
5091
Other lines denote key bindings and variable settings.
 
5092
.PP
 
5093
The default key-bindings may be changed with an
 
5094
.I inputrc 
 
5095
file.
 
5096
Other programs that use this library may add their own commands
 
5097
and bindings.
 
5098
.PP
 
5099
For example, placing
 
5100
.RS
 
5101
.PP
 
5102
M\-Control\-u: universal\-argument
 
5103
.RE
 
5104
or
 
5105
.RS
 
5106
C\-Meta\-u: universal\-argument
 
5107
.RE
 
5108
into the 
 
5109
.I inputrc
 
5110
would make M\-C\-u execute the readline command
 
5111
.IR universal\-argument .
 
5112
.PP
 
5113
The following symbolic character names are recognized:
 
5114
.IR RUBOUT ,
 
5115
.IR DEL ,
 
5116
.IR ESC ,
 
5117
.IR LFD ,
 
5118
.IR NEWLINE ,
 
5119
.IR RET ,
 
5120
.IR RETURN ,
 
5121
.IR SPC ,
 
5122
.IR SPACE ,
 
5123
and
 
5124
.IR TAB .
 
5125
.PP
 
5126
In addition to command names, readline allows keys to be bound
 
5127
to a string that is inserted when the key is pressed (a \fImacro\fP).
 
5128
.SS "Readline Key Bindings"
 
5129
.PP
 
5130
The syntax for controlling key bindings in the
 
5131
.I inputrc
 
5132
file is simple.  All that is required is the name of the
 
5133
command or the text of a macro and a key sequence to which
 
5134
it should be bound. The name may be specified in one of two ways:
 
5135
as a symbolic key name, possibly with \fIMeta\-\fP or \fIControl\-\fP
 
5136
prefixes, or as a key sequence.
 
5137
.PP
 
5138
When using the form \fBkeyname\fP:\^\fIfunction\-name\fP or \fImacro\fP,
 
5139
.I keyname
 
5140
is the name of a key spelled out in English.  For example:
 
5141
.sp
 
5142
.RS
 
5143
Control-u: universal\-argument
 
5144
.br
 
5145
Meta-Rubout: backward-kill-word
 
5146
.br
 
5147
Control-o: "> output"
 
5148
.RE
 
5149
.LP
 
5150
In the above example,
 
5151
.I C\-u
 
5152
is bound to the function
 
5153
.BR universal\-argument ,
 
5154
.I M\-DEL
 
5155
is bound to the function
 
5156
.BR backward\-kill\-word ,
 
5157
and
 
5158
.I C\-o
 
5159
is bound to run the macro
 
5160
expressed on the right hand side (that is, to insert the text
 
5161
.if t \f(CW> output\fP
 
5162
.if n ``> output''
 
5163
into the line).
 
5164
.PP
 
5165
In the second form, \fB"keyseq"\fP:\^\fIfunction\-name\fP or \fImacro\fP,
 
5166
.B keyseq
 
5167
differs from
 
5168
.B keyname
 
5169
above in that strings denoting
 
5170
an entire key sequence may be specified by placing the sequence
 
5171
within double quotes.  Some GNU Emacs style key escapes can be
 
5172
used, as in the following example, but the symbolic character names
 
5173
are not recognized.
 
5174
.sp
 
5175
.RS
 
5176
"\eC\-u": universal\-argument
 
5177
.br
 
5178
"\eC\-x\eC\-r": re\-read\-init\-file
 
5179
.br
 
5180
"\ee[11~": "Function Key 1"
 
5181
.RE
 
5182
.PP
 
5183
In this example,
 
5184
.I C\-u
 
5185
is again bound to the function
 
5186
.BR universal\-argument .
 
5187
.I "C\-x C\-r"
 
5188
is bound to the function
 
5189
.BR re\-read\-init\-file ,
 
5190
and 
 
5191
.I "ESC [ 1 1 ~"
 
5192
is bound to insert the text
 
5193
.if t \f(CWFunction Key 1\fP.
 
5194
.if n ``Function Key 1''.
 
5195
.PP
 
5196
The full set of GNU Emacs style escape sequences is
 
5197
.RS
 
5198
.PD 0
 
5199
.TP
 
5200
.B \eC\-
 
5201
control prefix
 
5202
.TP
 
5203
.B \eM\-
 
5204
meta prefix
 
5205
.TP
 
5206
.B \ee
 
5207
an escape character
 
5208
.TP
 
5209
.B \e\e
 
5210
backslash
 
5211
.TP
 
5212
.B \e"
 
5213
literal "
 
5214
.TP
 
5215
.B \e\(aq
 
5216
literal \(aq
 
5217
.RE
 
5218
.PD
 
5219
.PP
 
5220
In addition to the GNU Emacs style escape sequences, a second
 
5221
set of backslash escapes is available:
 
5222
.RS
 
5223
.PD 0
 
5224
.TP
 
5225
.B \ea
 
5226
alert (bell)
 
5227
.TP
 
5228
.B \eb
 
5229
backspace
 
5230
.TP
 
5231
.B \ed
 
5232
delete
 
5233
.TP
 
5234
.B \ef
 
5235
form feed
 
5236
.TP
 
5237
.B \en
 
5238
newline
 
5239
.TP
 
5240
.B \er
 
5241
carriage return
 
5242
.TP
 
5243
.B \et
 
5244
horizontal tab
 
5245
.TP
 
5246
.B \ev
 
5247
vertical tab
 
5248
.TP
 
5249
.B \e\fInnn\fP
 
5250
the eight-bit character whose value is the octal value \fInnn\fP
 
5251
(one to three digits)
 
5252
.TP
 
5253
.B \ex\fIHH\fP
 
5254
the eight-bit character whose value is the hexadecimal value \fIHH\fP
 
5255
(one or two hex digits)
 
5256
.RE
 
5257
.PD
 
5258
.PP
 
5259
When entering the text of a macro, single or double quotes must
 
5260
be used to indicate a macro definition.
 
5261
Unquoted text is assumed to be a function name.
 
5262
In the macro body, the backslash escapes described above are expanded.
 
5263
Backslash will quote any other character in the macro text,
 
5264
including " and \(aq.
 
5265
.PP
 
5266
.B Bash
 
5267
allows the current readline key bindings to be displayed or modified
 
5268
with the
 
5269
.B bind
 
5270
builtin command.  The editing mode may be switched during interactive
 
5271
use by using the
 
5272
.B \-o
 
5273
option to the
 
5274
.B set
 
5275
builtin command (see
 
5276
.SM
 
5277
.B SHELL BUILTIN COMMANDS
 
5278
below).
 
5279
.SS "Readline Variables"
 
5280
.PP
 
5281
Readline has variables that can be used to further customize its
 
5282
behavior.  A variable may be set in the
 
5283
.I inputrc
 
5284
file with a statement of the form
 
5285
.RS
 
5286
.PP
 
5287
\fBset\fP \fIvariable\-name\fP \fIvalue\fP
 
5288
.RE
 
5289
.PP
 
5290
Except where noted, readline variables can take the values
 
5291
.B On
 
5292
or
 
5293
.B Off
 
5294
(without regard to case).
 
5295
Unrecognized variable names are ignored.
 
5296
When a variable value is read, empty or null values, "on" (case-insensitive),
 
5297
and "1" are equivalent to \fBOn\fP.  All other values are equivalent to
 
5298
\fBOff\fP.
 
5299
The variables and their default values are:
 
5300
.PP
 
5301
.PD 0
 
5302
.TP
 
5303
.B bell\-style (audible)
 
5304
Controls what happens when readline wants to ring the terminal bell.
 
5305
If set to \fBnone\fP, readline never rings the bell.  If set to
 
5306
\fBvisible\fP, readline uses a visible bell if one is available.
 
5307
If set to \fBaudible\fP, readline attempts to ring the terminal's bell.
 
5308
.TP
 
5309
.B bind\-tty\-special\-chars (On)
 
5310
If set to \fBOn\fP, readline attempts to bind the control characters
 
5311
treated specially by the kernel's terminal driver to their readline
 
5312
equivalents.
 
5313
.TP
 
5314
.B colored\-stats (Off)
 
5315
If set to \fBOn\fP, readline displays possible completions using different
 
5316
colors to indicate their file type.     
 
5317
The color definitions are taken from the value of the \fBLS_COLORS\fP
 
5318
environment variable.
 
5319
.TP
 
5320
.B comment\-begin (``#'')
 
5321
The string that is inserted when the readline
 
5322
.B insert\-comment
 
5323
command is executed.
 
5324
This command is bound to
 
5325
.B M\-#
 
5326
in emacs mode and to
 
5327
.B #
 
5328
in vi command mode.
 
5329
.TP
 
5330
.B completion\-ignore\-case (Off)
 
5331
If set to \fBOn\fP, readline performs filename matching and completion
 
5332
in a case\-insensitive fashion.
 
5333
.TP
 
5334
.B completion\-prefix\-display\-length (0)
 
5335
The length in characters of the common prefix of a list of possible
 
5336
completions that is displayed without modification.  When set to a
 
5337
value greater than zero, common prefixes longer than this value are
 
5338
replaced with an ellipsis when displaying possible completions.
 
5339
.TP
 
5340
.B completion\-query\-items (100)
 
5341
This determines when the user is queried about viewing
 
5342
the number of possible completions
 
5343
generated by the \fBpossible\-completions\fP command.
 
5344
It may be set to any integer value greater than or equal to
 
5345
zero.  If the number of possible completions is greater than
 
5346
or equal to the value of this variable, the user is asked whether
 
5347
or not he wishes to view them; otherwise they are simply listed
 
5348
on the terminal.
 
5349
.TP
 
5350
.B convert\-meta (On)
 
5351
If set to \fBOn\fP, readline will convert characters with the
 
5352
eighth bit set to an ASCII key sequence
 
5353
by stripping the eighth bit and prefixing an
 
5354
escape character (in effect, using escape as the \fImeta prefix\fP).
 
5355
.TP
 
5356
.B disable\-completion (Off)
 
5357
If set to \fBOn\fP, readline will inhibit word completion.  Completion
 
5358
characters will be inserted into the line as if they had been
 
5359
mapped to \fBself-insert\fP.
 
5360
.TP
 
5361
.B editing\-mode (emacs)
 
5362
Controls whether readline begins with a set of key bindings similar
 
5363
to \fIEmacs\fP or \fIvi\fP.
 
5364
.B editing\-mode
 
5365
can be set to either
 
5366
.B emacs
 
5367
or
 
5368
.BR vi .
 
5369
.TP
 
5370
.B echo\-control\-characters (On)
 
5371
When set to \fBOn\fP, on operating systems that indicate they support it,
 
5372
readline echoes a character corresponding to a signal generated from the
 
5373
keyboard.
 
5374
.TP
 
5375
.B enable\-keypad (Off)
 
5376
When set to \fBOn\fP, readline will try to enable the application
 
5377
keypad when it is called.  Some systems need this to enable the
 
5378
arrow keys.
 
5379
.TP
 
5380
.B enable\-meta\-key (On)
 
5381
When set to \fBOn\fP, readline will try to enable any meta modifier
 
5382
key the terminal claims to support when it is called.  On many terminals,
 
5383
the meta key is used to send eight-bit characters.
 
5384
.TP
 
5385
.B expand\-tilde (Off)
 
5386
If set to \fBOn\fP, tilde expansion is performed when readline
 
5387
attempts word completion.
 
5388
.TP
 
5389
.B history\-preserve\-point (Off)
 
5390
If set to \fBOn\fP, the history code attempts to place point at the
 
5391
same location on each history line retrieved with \fBprevious-history\fP
 
5392
or \fBnext-history\fP.
 
5393
.TP
 
5394
.B history\-size (0)
 
5395
Set the maximum number of history entries saved in the history list.
 
5396
If set to zero, any existing history entries are deleted and no new entries
 
5397
are saved.
 
5398
If set to a value less than zero, the number of history entries is not
 
5399
limited.
 
5400
By default, the number of history entries is not limited.
 
5401
.TP
 
5402
.B horizontal\-scroll\-mode (Off)
 
5403
When set to \fBOn\fP, makes readline use a single line for display,
 
5404
scrolling the input horizontally on a single screen line when it
 
5405
becomes longer than the screen width rather than wrapping to a new line.
 
5406
.TP
 
5407
.B input\-meta (Off)
 
5408
If set to \fBOn\fP, readline will enable eight-bit input (that is,
 
5409
it will not strip the high bit from the characters it reads),
 
5410
regardless of what the terminal claims it can support.  The name
 
5411
.B meta\-flag
 
5412
is a synonym for this variable.
 
5413
.TP
 
5414
.B isearch\-terminators (``C\-[C\-J'')
 
5415
The string of characters that should terminate an incremental
 
5416
search without subsequently executing the character as a command.
 
5417
If this variable has not been given a value, the characters
 
5418
\fIESC\fP and \fIC\-J\fP will terminate an incremental search.
 
5419
.TP
 
5420
.B keymap (emacs)
 
5421
Set the current readline keymap.  The set of valid keymap names is
 
5422
\fIemacs, emacs\-standard, emacs\-meta, emacs\-ctlx, vi,
 
5423
vi\-command\fP, and
 
5424
.IR vi\-insert .
 
5425
\fIvi\fP is equivalent to \fIvi\-command\fP; \fIemacs\fP is
 
5426
equivalent to \fIemacs\-standard\fP.  The default value is
 
5427
.IR emacs ;
 
5428
the value of
 
5429
.B editing\-mode
 
5430
also affects the default keymap.
 
5431
.TP
 
5432
.B keyseq\-timeout (500)
 
5433
Specifies the duration \fIreadline\fP will wait for a character when reading an
 
5434
ambiguous key sequence (one that can form a complete key sequence using
 
5435
the input read so far, or can take additional input to complete a longer
 
5436
key sequence).
 
5437
If no input is received within the timeout, \fIreadline\fP will use the shorter
 
5438
but complete key sequence.
 
5439
The value is specified in milliseconds, so a value of 1000 means that
 
5440
\fIreadline\fP will wait one second for additional input.
 
5441
If this variable is set to a value less than or equal to zero, or to a
 
5442
non-numeric value, \fIreadline\fP will wait until another key is pressed to
 
5443
decide which key sequence to complete.
 
5444
.TP
 
5445
.B mark\-directories (On)
 
5446
If set to \fBOn\fP, completed directory names have a slash
 
5447
appended.
 
5448
.TP
 
5449
.B mark\-modified\-lines (Off)
 
5450
If set to \fBOn\fP, history lines that have been modified are displayed
 
5451
with a preceding asterisk (\fB*\fP).
 
5452
.TP
 
5453
.B mark\-symlinked\-directories (Off)
 
5454
If set to \fBOn\fP, completed names which are symbolic links to directories
 
5455
have a slash appended (subject to the value of
 
5456
\fBmark\-directories\fP).
 
5457
.TP
 
5458
.B match\-hidden\-files (On)
 
5459
This variable, when set to \fBOn\fP, causes readline to match files whose
 
5460
names begin with a `.' (hidden files) when performing filename 
 
5461
completion.
 
5462
If set to \fBOff\fP, the leading `.' must be
 
5463
supplied by the user in the filename to be completed.
 
5464
.TP
 
5465
.B menu\-complete\-display\-prefix (Off)
 
5466
If set to \fBOn\fP, menu completion displays the common prefix of the
 
5467
list of possible completions (which may be empty) before cycling through
 
5468
the list.
 
5469
.TP
 
5470
.B output\-meta (Off)
 
5471
If set to \fBOn\fP, readline will display characters with the
 
5472
eighth bit set directly rather than as a meta-prefixed escape
 
5473
sequence.
 
5474
.TP
 
5475
.B page\-completions (On)
 
5476
If set to \fBOn\fP, readline uses an internal \fImore\fP-like pager
 
5477
to display a screenful of possible completions at a time.
 
5478
.TP
 
5479
.B print\-completions\-horizontally (Off)
 
5480
If set to \fBOn\fP, readline will display completions with matches
 
5481
sorted horizontally in alphabetical order, rather than down the screen.
 
5482
.TP 
 
5483
.B revert\-all\-at\-newline (Off)
 
5484
If set to \fBOn\fP, readline will undo all changes to history lines 
 
5485
before returning when \fBaccept\-line\fP is executed.  By default,
 
5486
history lines may be modified and retain individual undo lists across
 
5487
calls to \fBreadline\fP.
 
5488
.TP
 
5489
.B show\-all\-if\-ambiguous (Off)
 
5490
This alters the default behavior of the completion functions.  If
 
5491
set to
 
5492
.BR On ,
 
5493
words which have more than one possible completion cause the
 
5494
matches to be listed immediately instead of ringing the bell.
 
5495
.TP
 
5496
.B show\-all\-if\-unmodified (Off)
 
5497
This alters the default behavior of the completion functions in
 
5498
a fashion similar to \fBshow\-all\-if\-ambiguous\fP.
 
5499
If set to
 
5500
.BR On ,
 
5501
words which have more than one possible completion without any
 
5502
possible partial completion (the possible completions don't share
 
5503
a common prefix) cause the matches to be listed immediately instead
 
5504
of ringing the bell.
 
5505
.TP
 
5506
.B show\-mode\-in\-prompt (Off)
 
5507
If set to \fBOn\fP, add a character to the beginning of the prompt
 
5508
indicating the editing mode: emacs (@), vi command (:) or vi
 
5509
insertion (+).
 
5510
.TP
 
5511
.B skip\-completed\-text (Off)
 
5512
If set to \fBOn\fP, this alters the default completion behavior when
 
5513
inserting a single match into the line.  It's only active when
 
5514
performing completion in the middle of a word.  If enabled, readline
 
5515
does not insert characters from the completion that match characters
 
5516
after point in the word being completed, so portions of the word
 
5517
following the cursor are not duplicated.
 
5518
.TP
 
5519
.B visible\-stats (Off)
 
5520
If set to \fBOn\fP, a character denoting a file's type as reported
 
5521
by \fIstat\fP(2) is appended to the filename when listing possible
 
5522
completions.
 
5523
.PD
 
5524
.SS "Readline Conditional Constructs"
 
5525
.PP
 
5526
Readline implements a facility similar in spirit to the conditional
 
5527
compilation features of the C preprocessor which allows key
 
5528
bindings and variable settings to be performed as the result
 
5529
of tests.  There are four parser directives used.
 
5530
.IP \fB$if\fP
 
5531
The 
 
5532
.B $if
 
5533
construct allows bindings to be made based on the
 
5534
editing mode, the terminal being used, or the application using
 
5535
readline.  The text of the test extends to the end of the line;
 
5536
no characters are required to isolate it.
 
5537
.RS
 
5538
.IP \fBmode\fP
 
5539
The \fBmode=\fP form of the \fB$if\fP directive is used to test
 
5540
whether readline is in emacs or vi mode.
 
5541
This may be used in conjunction
 
5542
with the \fBset keymap\fP command, for instance, to set bindings in
 
5543
the \fIemacs\-standard\fP and \fIemacs\-ctlx\fP keymaps only if
 
5544
readline is starting out in emacs mode.
 
5545
.IP \fBterm\fP
 
5546
The \fBterm=\fP form may be used to include terminal-specific
 
5547
key bindings, perhaps to bind the key sequences output by the
 
5548
terminal's function keys.  The word on the right side of the
 
5549
.B =
 
5550
is tested against the both full name of the terminal and the portion
 
5551
of the terminal name before the first \fB\-\fP.  This allows
 
5552
.I sun
 
5553
to match both
 
5554
.I sun
 
5555
and
 
5556
.IR sun\-cmd ,
 
5557
for instance.
 
5558
.IP \fBapplication\fP
 
5559
The \fBapplication\fP construct is used to include
 
5560
application-specific settings.  Each program using the readline
 
5561
library sets the \fIapplication name\fP, and an initialization
 
5562
file can test for a particular value.
 
5563
This could be used to bind key sequences to functions useful for
 
5564
a specific program.  For instance, the following command adds a
 
5565
key sequence that quotes the current or previous word in \fBbash\fP:
 
5566
.sp 1
 
5567
.RS
 
5568
.nf
 
5569
\fB$if\fP Bash
 
5570
# Quote the current or previous word
 
5571
"\eC\-xq": "\eeb\e"\eef\e""
 
5572
\fB$endif\fP
 
5573
.fi
 
5574
.RE
 
5575
.RE
 
5576
.IP \fB$endif\fP
 
5577
This command, as seen in the previous example, terminates an
 
5578
\fB$if\fP command.
 
5579
.IP \fB$else\fP
 
5580
Commands in this branch of the \fB$if\fP directive are executed if
 
5581
the test fails.
 
5582
.IP \fB$include\fP
 
5583
This directive takes a single filename as an argument and reads commands
 
5584
and bindings from that file.  For example, the following directive
 
5585
would read \fI/etc/inputrc\fP:
 
5586
.sp 1
 
5587
.RS
 
5588
.nf
 
5589
\fB$include\fP \^ \fI/etc/inputrc\fP
 
5590
.fi
 
5591
.RE
 
5592
.SS Searching
 
5593
.PP
 
5594
Readline provides commands for searching through the command history
 
5595
(see
 
5596
.SM
 
5597
.B HISTORY
 
5598
below) for lines containing a specified string.
 
5599
There are two search modes:
 
5600
.I incremental
 
5601
and
 
5602
.IR non-incremental .
 
5603
.PP
 
5604
Incremental searches begin before the user has finished typing the
 
5605
search string.
 
5606
As each character of the search string is typed, readline displays
 
5607
the next entry from the history matching the string typed so far.
 
5608
An incremental search requires only as many characters as needed to
 
5609
find the desired history entry.
 
5610
The characters present in the value of the \fBisearch-terminators\fP
 
5611
variable are used to terminate an incremental search.
 
5612
If that variable has not been assigned a value the Escape and
 
5613
Control-J characters will terminate an incremental search.
 
5614
Control-G will abort an incremental search and restore the original
 
5615
line.
 
5616
When the search is terminated, the history entry containing the
 
5617
search string becomes the current line.
 
5618
.PP
 
5619
To find other matching entries in the history list, type Control-S or
 
5620
Control-R as appropriate.
 
5621
This will search backward or forward in the history for the next
 
5622
entry matching the search string typed so far.
 
5623
Any other key sequence bound to a readline command will terminate
 
5624
the search and execute that command.
 
5625
For instance, a \fInewline\fP will terminate the search and accept
 
5626
the line, thereby executing the command from the history list.
 
5627
.PP
 
5628
Readline remembers the last incremental search string.  If two
 
5629
Control-Rs are typed without any intervening characters defining a
 
5630
new search string, any remembered search string is used.
 
5631
.PP
 
5632
Non-incremental searches read the entire search string before starting
 
5633
to search for matching history lines.  The search string may be
 
5634
typed by the user or be part of the contents of the current line.
 
5635
.SS "Readline Command Names"
 
5636
.PP
 
5637
The following is a list of the names of the commands and the default
 
5638
key sequences to which they are bound.
 
5639
Command names without an accompanying key sequence are unbound by default.
 
5640
In the following descriptions, \fIpoint\fP refers to the current cursor
 
5641
position, and \fImark\fP refers to a cursor position saved by the
 
5642
\fBset\-mark\fP command.
 
5643
The text between the point and mark is referred to as the \fIregion\fP.
 
5644
.SS Commands for Moving
 
5645
.PP
 
5646
.PD 0
 
5647
.TP
 
5648
.B beginning\-of\-line (C\-a)
 
5649
Move to the start of the current line.
 
5650
.TP
 
5651
.B end\-of\-line (C\-e)
 
5652
Move to the end of the line.
 
5653
.TP
 
5654
.B forward\-char (C\-f)
 
5655
Move forward a character.
 
5656
.TP
 
5657
.B backward\-char (C\-b)
 
5658
Move back a character.
 
5659
.TP
 
5660
.B forward\-word (M\-f)
 
5661
Move forward to the end of the next word.  Words are composed of
 
5662
alphanumeric characters (letters and digits).
 
5663
.TP
 
5664
.B backward\-word (M\-b)
 
5665
Move back to the start of the current or previous word.
 
5666
Words are composed of alphanumeric characters (letters and digits).
 
5667
.TP
 
5668
.B shell\-forward\-word
 
5669
Move forward to the end of the next word.
 
5670
Words are delimited by non-quoted shell metacharacters.
 
5671
.TP
 
5672
.B shell\-backward\-word
 
5673
Move back to the start of the current or previous word.
 
5674
Words are delimited by non-quoted shell metacharacters.
 
5675
.TP
 
5676
.B clear\-screen (C\-l)
 
5677
Clear the screen leaving the current line at the top of the screen.
 
5678
With an argument, refresh the current line without clearing the
 
5679
screen.
 
5680
.TP
 
5681
.B redraw\-current\-line
 
5682
Refresh the current line.
 
5683
.PD
 
5684
.SS Commands for Manipulating the History
 
5685
.PP
 
5686
.PD 0
 
5687
.TP
 
5688
.B accept\-line (Newline, Return)
 
5689
Accept the line regardless of where the cursor is.  If this line is
 
5690
non-empty, add it to the history list according to the state of the
 
5691
.SM
 
5692
.B HISTCONTROL
 
5693
variable.  If the line is a modified history
 
5694
line, then restore the history line to its original state.
 
5695
.TP
 
5696
.B previous\-history (C\-p)
 
5697
Fetch the previous command from the history list, moving back in
 
5698
the list.
 
5699
.TP
 
5700
.B next\-history (C\-n)
 
5701
Fetch the next command from the history list, moving forward in the
 
5702
list.
 
5703
.TP
 
5704
.B beginning\-of\-history (M\-<)
 
5705
Move to the first line in the history.
 
5706
.TP
 
5707
.B end\-of\-history (M\->)
 
5708
Move to the end of the input history, i.e., the line currently being
 
5709
entered.
 
5710
.TP
 
5711
.B reverse\-search\-history (C\-r)
 
5712
Search backward starting at the current line and moving `up' through
 
5713
the history as necessary.  This is an incremental search.
 
5714
.TP
 
5715
.B forward\-search\-history (C\-s)
 
5716
Search forward starting at the current line and moving `down' through
 
5717
the history as necessary.  This is an incremental search.
 
5718
.TP
 
5719
.B non\-incremental\-reverse\-search\-history (M\-p)
 
5720
Search backward through the history starting at the current line
 
5721
using a non-incremental search for a string supplied by the user.
 
5722
.TP
 
5723
.B non\-incremental\-forward\-search\-history (M\-n)
 
5724
Search forward through the history using a non-incremental search for
 
5725
a string supplied by the user.
 
5726
.TP
 
5727
.B history\-search\-forward
 
5728
Search forward through the history for the string of characters
 
5729
between the start of the current line and the point.
 
5730
This is a non-incremental search.
 
5731
.TP
 
5732
.B history\-search\-backward
 
5733
Search backward through the history for the string of characters
 
5734
between the start of the current line and the point.
 
5735
This is a non-incremental search.
 
5736
.TP
 
5737
.B yank\-nth\-arg (M\-C\-y)
 
5738
Insert the first argument to the previous command (usually
 
5739
the second word on the previous line) at point.
 
5740
With an argument
 
5741
.IR n ,
 
5742
insert the \fIn\fPth word from the previous command (the words
 
5743
in the previous command begin with word 0).  A negative argument
 
5744
inserts the \fIn\fPth word from the end of the previous command.
 
5745
Once the argument \fIn\fP is computed, the argument is extracted
 
5746
as if the "!\fIn\fP" history expansion had been specified.
 
5747
.TP
 
5748
.B
 
5749
yank\-last\-arg (M\-.\^, M\-_\^)
 
5750
Insert the last argument to the previous command (the last word of
 
5751
the previous history entry).
 
5752
With a numeric argument, behave exactly like \fByank\-nth\-arg\fP.
 
5753
Successive calls to \fByank\-last\-arg\fP move back through the history
 
5754
list, inserting the last word (or the word specified by the argument to
 
5755
the first call) of each line in turn.
 
5756
Any numeric argument supplied to these successive calls determines
 
5757
the direction to move through the history.  A negative argument switches
 
5758
the direction through the history (back or forward).
 
5759
The history expansion facilities are used to extract the last word,
 
5760
as if the "!$" history expansion had been specified.
 
5761
.TP
 
5762
.B shell\-expand\-line (M\-C\-e)
 
5763
Expand the line as the shell does.  This
 
5764
performs alias and history expansion as well as all of the shell
 
5765
word expansions.  See
 
5766
.SM
 
5767
.B HISTORY EXPANSION
 
5768
below for a description of history expansion.
 
5769
.TP
 
5770
.B history\-expand\-line (M\-^)
 
5771
Perform history expansion on the current line.
 
5772
See
 
5773
.SM
 
5774
.B HISTORY EXPANSION
 
5775
below for a description of history expansion.
 
5776
.TP
 
5777
.B magic\-space
 
5778
Perform history expansion on the current line and insert a space.
 
5779
See
 
5780
.SM
 
5781
.B HISTORY EXPANSION
 
5782
below for a description of history expansion.
 
5783
.TP
 
5784
.B alias\-expand\-line
 
5785
Perform alias expansion on the current line.
 
5786
See
 
5787
.SM
 
5788
.B ALIASES
 
5789
above for a description of alias expansion.
 
5790
.TP
 
5791
.B history\-and\-alias\-expand\-line
 
5792
Perform history and alias expansion on the current line.
 
5793
.TP
 
5794
.B insert\-last\-argument (M\-.\^, M\-_\^)
 
5795
A synonym for \fByank\-last\-arg\fP.
 
5796
.TP
 
5797
.B operate\-and\-get\-next (C\-o)
 
5798
Accept the current line for execution and fetch the next line
 
5799
relative to the current line from the history for editing.  Any
 
5800
argument is ignored.
 
5801
.TP
 
5802
.B edit\-and\-execute\-command (C\-xC\-e)
 
5803
Invoke an editor on the current command line, and execute the result as shell
 
5804
commands.
 
5805
\fBBash\fP attempts to invoke
 
5806
.SM
 
5807
.BR $VISUAL ,
 
5808
.SM
 
5809
.BR $EDITOR ,
 
5810
and \fIemacs\fP as the editor, in that order.
 
5811
.PD
 
5812
.SS Commands for Changing Text
 
5813
.PP
 
5814
.PD 0
 
5815
.TP
 
5816
.B \fIend\-of\-file\fP (usually C\-d)
 
5817
The character indicating end-of-file as set, for example, by
 
5818
.if t \f(CWstty\fP.
 
5819
.if n ``stty''.
 
5820
If this character is read when there are no characters
 
5821
on the line, and point is at the beginning of the line, Readline
 
5822
interprets it as the end of input and returns
 
5823
.SM
 
5824
.BR EOF .
 
5825
.TP
 
5826
.B delete\-char (C\-d)
 
5827
Delete the character at point.
 
5828
If this function is bound to the
 
5829
same character as the tty \fBEOF\fP character, as \fBC\-d\fP
 
5830
commonly is, see above for the effects.
 
5831
.TP
 
5832
.B backward\-delete\-char (Rubout)
 
5833
Delete the character behind the cursor.  When given a numeric argument,
 
5834
save the deleted text on the kill ring.
 
5835
.TP
 
5836
.B forward\-backward\-delete\-char
 
5837
Delete the character under the cursor, unless the cursor is at the
 
5838
end of the line, in which case the character behind the cursor is
 
5839
deleted.
 
5840
.TP
 
5841
.B quoted\-insert (C\-q, C\-v)
 
5842
Add the next character typed to the line verbatim.  This is
 
5843
how to insert characters like \fBC\-q\fP, for example.
 
5844
.TP
 
5845
.B tab\-insert (C\-v TAB)
 
5846
Insert a tab character.
 
5847
.TP
 
5848
.B self\-insert (a,\ b,\ A,\ 1,\ !,\ ...)
 
5849
Insert the character typed.
 
5850
.TP
 
5851
.B transpose\-chars (C\-t)
 
5852
Drag the character before point forward over the character at point,
 
5853
moving point forward as well.
 
5854
If point is at the end of the line, then this transposes
 
5855
the two characters before point.
 
5856
Negative arguments have no effect.
 
5857
.TP
 
5858
.B transpose\-words (M\-t)
 
5859
Drag the word before point past the word after point,
 
5860
moving point over that word as well.
 
5861
If point is at the end of the line, this transposes
 
5862
the last two words on the line.   
 
5863
.TP
 
5864
.B upcase\-word (M\-u)
 
5865
Uppercase the current (or following) word.  With a negative argument,
 
5866
uppercase the previous word, but do not move point.
 
5867
.TP
 
5868
.B downcase\-word (M\-l)
 
5869
Lowercase the current (or following) word.  With a negative argument,
 
5870
lowercase the previous word, but do not move point.
 
5871
.TP
 
5872
.B capitalize\-word (M\-c)
 
5873
Capitalize the current (or following) word.  With a negative argument,
 
5874
capitalize the previous word, but do not move point.
 
5875
.TP
 
5876
.B overwrite\-mode
 
5877
Toggle overwrite mode.  With an explicit positive numeric argument,
 
5878
switches to overwrite mode.  With an explicit non-positive numeric
 
5879
argument, switches to insert mode.  This command affects only
 
5880
\fBemacs\fP mode; \fBvi\fP mode does overwrite differently.
 
5881
Each call to \fIreadline()\fP starts in insert mode.
 
5882
In overwrite mode, characters bound to \fBself\-insert\fP replace   
 
5883
the text at point rather than pushing the text to the right.
 
5884
Characters bound to \fBbackward\-delete\-char\fP replace the character
 
5885
before point with a space.  By default, this command is unbound.
 
5886
.PD
 
5887
.SS Killing and Yanking
 
5888
.PP
 
5889
.PD 0
 
5890
.TP
 
5891
.B kill\-line (C\-k)
 
5892
Kill the text from point to the end of the line.
 
5893
.TP
 
5894
.B backward\-kill\-line (C\-x Rubout)
 
5895
Kill backward to the beginning of the line.
 
5896
.TP
 
5897
.B unix\-line\-discard (C\-u)
 
5898
Kill backward from point to the beginning of the line.
 
5899
The killed text is saved on the kill-ring.
 
5900
.\" There is no real difference between this and backward-kill-line
 
5901
.TP
 
5902
.B kill\-whole\-line
 
5903
Kill all characters on the current line, no matter where point is.
 
5904
.TP
 
5905
.B kill\-word  (M\-d)
 
5906
Kill from point to the end of the current word, or if between
 
5907
words, to the end of the next word.
 
5908
Word boundaries are the same as those used by \fBforward\-word\fP.
 
5909
.TP
 
5910
.B backward\-kill\-word (M\-Rubout)
 
5911
Kill the word behind point.
 
5912
Word boundaries are the same as those used by \fBbackward\-word\fP.
 
5913
.TP
 
5914
.B shell\-kill\-word  (M\-d)
 
5915
Kill from point to the end of the current word, or if between
 
5916
words, to the end of the next word.
 
5917
Word boundaries are the same as those used by \fBshell\-forward\-word\fP.
 
5918
.TP
 
5919
.B shell\-backward\-kill\-word (M\-Rubout)
 
5920
Kill the word behind point.
 
5921
Word boundaries are the same as those used by \fBshell\-backward\-word\fP.
 
5922
.TP
 
5923
.B unix\-word\-rubout (C\-w)
 
5924
Kill the word behind point, using white space as a word boundary.
 
5925
The killed text is saved on the kill-ring.
 
5926
.TP
 
5927
.B unix\-filename\-rubout
 
5928
Kill the word behind point, using white space and the slash character
 
5929
as the word boundaries.
 
5930
The killed text is saved on the kill-ring.
 
5931
.TP
 
5932
.B delete\-horizontal\-space (M\-\e)
 
5933
Delete all spaces and tabs around point.
 
5934
.TP
 
5935
.B kill\-region
 
5936
Kill the text in the current region.
 
5937
.TP
 
5938
.B copy\-region\-as\-kill
 
5939
Copy the text in the region to the kill buffer.
 
5940
.TP
 
5941
.B copy\-backward\-word
 
5942
Copy the word before point to the kill buffer.
 
5943
The word boundaries are the same as \fBbackward\-word\fP.
 
5944
.TP
 
5945
.B copy\-forward\-word
 
5946
Copy the word following point to the kill buffer.
 
5947
The word boundaries are the same as \fBforward\-word\fP.
 
5948
.TP
 
5949
.B yank (C\-y)
 
5950
Yank the top of the kill ring into the buffer at point.
 
5951
.TP
 
5952
.B yank\-pop (M\-y)
 
5953
Rotate the kill ring, and yank the new top.  Only works following
 
5954
.B yank
 
5955
or
 
5956
.BR yank\-pop .
 
5957
.PD
 
5958
.SS Numeric Arguments
 
5959
.PP
 
5960
.PD 0
 
5961
.TP
 
5962
.B digit\-argument (M\-0, M\-1, ..., M\-\-)
 
5963
Add this digit to the argument already accumulating, or start a new
 
5964
argument.  M\-\- starts a negative argument.
 
5965
.TP
 
5966
.B universal\-argument
 
5967
This is another way to specify an argument.
 
5968
If this command is followed by one or more digits, optionally with a
 
5969
leading minus sign, those digits define the argument.
 
5970
If the command is followed by digits, executing
 
5971
.B universal\-argument
 
5972
again ends the numeric argument, but is otherwise ignored.
 
5973
As a special case, if this command is immediately followed by a
 
5974
character that is neither a digit or minus sign, the argument count
 
5975
for the next command is multiplied by four.
 
5976
The argument count is initially one, so executing this function the
 
5977
first time makes the argument count four, a second time makes the
 
5978
argument count sixteen, and so on.
 
5979
.PD
 
5980
.SS Completing
 
5981
.PP
 
5982
.PD 0
 
5983
.TP
 
5984
.B complete (TAB)
 
5985
Attempt to perform completion on the text before point.
 
5986
.B Bash
 
5987
attempts completion treating the text as a variable (if the
 
5988
text begins with \fB$\fP), username (if the text begins with
 
5989
\fB~\fP), hostname (if the text begins with \fB@\fP), or
 
5990
command (including aliases and functions) in turn.  If none
 
5991
of these produces a match, filename completion is attempted.
 
5992
.TP
 
5993
.B possible\-completions (M\-?)
 
5994
List the possible completions of the text before point.
 
5995
.TP
 
5996
.B insert\-completions (M\-*)
 
5997
Insert all completions of the text before point
 
5998
that would have been generated by
 
5999
\fBpossible\-completions\fP.
 
6000
.TP
 
6001
.B menu\-complete
 
6002
Similar to \fBcomplete\fP, but replaces the word to be completed
 
6003
with a single match from the list of possible completions.
 
6004
Repeated execution of \fBmenu\-complete\fP steps through the list
 
6005
of possible completions, inserting each match in turn.
 
6006
At the end of the list of completions, the bell is rung
 
6007
(subject to the setting of \fBbell\-style\fP)
 
6008
and the original text is restored.
 
6009
An argument of \fIn\fP moves \fIn\fP positions forward in the list
 
6010
of matches; a negative argument may be used to move backward
 
6011
through the list.
 
6012
This command is intended to be bound to \fBTAB\fP, but is unbound
 
6013
by default.
 
6014
.TP
 
6015
.B menu\-complete\-backward
 
6016
Identical to \fBmenu\-complete\fP, but moves backward through the list
 
6017
of possible completions, as if \fBmenu\-complete\fP had been given a
 
6018
negative argument.  This command is unbound by default.
 
6019
.TP
 
6020
.B delete\-char\-or\-list
 
6021
Deletes the character under the cursor if not at the beginning or
 
6022
end of the line (like \fBdelete\-char\fP).
 
6023
If at the end of the line, behaves identically to
 
6024
\fBpossible\-completions\fP.
 
6025
This command is unbound by default.
 
6026
.TP
 
6027
.B complete\-filename (M\-/)
 
6028
Attempt filename completion on the text before point.
 
6029
.TP
 
6030
.B possible\-filename\-completions (C\-x /)
 
6031
List the possible completions of the text before point,
 
6032
treating it as a filename.
 
6033
.TP
 
6034
.B complete\-username (M\-~)
 
6035
Attempt completion on the text before point, treating
 
6036
it as a username.
 
6037
.TP
 
6038
.B possible\-username\-completions (C\-x ~)
 
6039
List the possible completions of the text before point,
 
6040
treating it as a username.
 
6041
.TP
 
6042
.B complete\-variable (M\-$)
 
6043
Attempt completion on the text before point, treating
 
6044
it as a shell variable.
 
6045
.TP
 
6046
.B possible\-variable\-completions (C\-x $)
 
6047
List the possible completions of the text before point,
 
6048
treating it as a shell variable.
 
6049
.TP
 
6050
.B complete\-hostname (M\-@)
 
6051
Attempt completion on the text before point, treating
 
6052
it as a hostname.
 
6053
.TP
 
6054
.B possible\-hostname\-completions (C\-x @)
 
6055
List the possible completions of the text before point,
 
6056
treating it as a hostname.
 
6057
.TP
 
6058
.B complete\-command (M\-!)
 
6059
Attempt completion on the text before point, treating
 
6060
it as a command name.  Command completion attempts to
 
6061
match the text against aliases, reserved words, shell
 
6062
functions, shell builtins, and finally executable filenames,
 
6063
in that order.
 
6064
.TP
 
6065
.B possible\-command\-completions (C\-x !)
 
6066
List the possible completions of the text before point,
 
6067
treating it as a command name.
 
6068
.TP
 
6069
.B dynamic\-complete\-history (M\-TAB)
 
6070
Attempt completion on the text before point, comparing
 
6071
the text against lines from the history list for possible
 
6072
completion matches.
 
6073
.TP
 
6074
.B dabbrev\-expand
 
6075
Attempt menu completion on the text before point, comparing
 
6076
the text against lines from the history list for possible
 
6077
completion matches.
 
6078
.TP
 
6079
.B complete\-into\-braces (M\-{)
 
6080
Perform filename completion and insert the list of possible completions
 
6081
enclosed within braces so the list is available to the shell (see
 
6082
.B Brace Expansion
 
6083
above).
 
6084
.PD
 
6085
.SS Keyboard Macros
 
6086
.PP
 
6087
.PD 0
 
6088
.TP
 
6089
.B start\-kbd\-macro (C\-x (\^)
 
6090
Begin saving the characters typed into the current keyboard macro.
 
6091
.TP
 
6092
.B end\-kbd\-macro (C\-x )\^)
 
6093
Stop saving the characters typed into the current keyboard macro
 
6094
and store the definition.
 
6095
.TP
 
6096
.B call\-last\-kbd\-macro (C\-x e)
 
6097
Re-execute the last keyboard macro defined, by making the characters
 
6098
in the macro appear as if typed at the keyboard.
 
6099
.TP
 
6100
.B print\-last\-kbd\-macro ()
 
6101
Print the last keyboard macro defined in a format suitable for the
 
6102
\fIinputrc\fP file.
 
6103
.PD
 
6104
.SS Miscellaneous
 
6105
.PP
 
6106
.PD 0
 
6107
.TP
 
6108
.B re\-read\-init\-file (C\-x C\-r)
 
6109
Read in the contents of the \fIinputrc\fP file, and incorporate
 
6110
any bindings or variable assignments found there.
 
6111
.TP
 
6112
.B abort (C\-g)
 
6113
Abort the current editing command and
 
6114
ring the terminal's bell (subject to the setting of
 
6115
.BR bell\-style ).
 
6116
.TP
 
6117
.B do\-uppercase\-version (M\-a, M\-b, M\-\fIx\fP, ...)
 
6118
If the metafied character \fIx\fP is lowercase, run the command
 
6119
that is bound to the corresponding uppercase character.
 
6120
.TP
 
6121
.B prefix\-meta (ESC)
 
6122
Metafy the next character typed.
 
6123
.SM
 
6124
.B ESC
 
6125
.B f
 
6126
is equivalent to
 
6127
.BR Meta\-f .
 
6128
.TP
 
6129
.B undo (C\-_, C\-x C\-u)
 
6130
Incremental undo, separately remembered for each line.
 
6131
.TP
 
6132
.B revert\-line (M\-r)
 
6133
Undo all changes made to this line.  This is like executing the
 
6134
.B undo
 
6135
command enough times to return the line to its initial state.
 
6136
.TP
 
6137
.B tilde\-expand (M\-&)
 
6138
Perform tilde expansion on the current word.
 
6139
.TP
 
6140
.B set\-mark (C\-@, M\-<space>)
 
6141
Set the mark to the point.  If a
 
6142
numeric argument is supplied, the mark is set to that position.
 
6143
.TP
 
6144
.B exchange\-point\-and\-mark (C\-x C\-x)
 
6145
Swap the point with the mark.  The current cursor position is set to
 
6146
the saved position, and the old cursor position is saved as the mark.
 
6147
.TP
 
6148
.B character\-search (C\-])
 
6149
A character is read and point is moved to the next occurrence of that
 
6150
character.  A negative count searches for previous occurrences.
 
6151
.TP
 
6152
.B character\-search\-backward (M\-C\-])
 
6153
A character is read and point is moved to the previous occurrence of that
 
6154
character.  A negative count searches for subsequent occurrences.
 
6155
.TP
 
6156
.B skip\-csi\-sequence
 
6157
Read enough characters to consume a multi-key sequence such as those
 
6158
defined for keys like Home and End.  Such sequences begin with a
 
6159
Control Sequence Indicator (CSI), usually ESC\-[.  If this sequence is
 
6160
bound to "\e[", keys producing such sequences will have no effect
 
6161
unless explicitly bound to a readline command, instead of inserting
 
6162
stray characters into the editing buffer.  This is unbound by default,
 
6163
but usually bound to ESC\-[.
 
6164
.TP
 
6165
.B insert\-comment (M\-#)
 
6166
Without a numeric argument, the value of the readline
 
6167
.B comment\-begin
 
6168
variable is inserted at the beginning of the current line.
 
6169
If a numeric argument is supplied, this command acts as a toggle:  if
 
6170
the characters at the beginning of the line do not match the value
 
6171
of \fBcomment\-begin\fP, the value is inserted, otherwise
 
6172
the characters in \fBcomment\-begin\fP are deleted from the beginning of 
 
6173
the line.
 
6174
In either case, the line is accepted as if a newline had been typed.
 
6175
The default value of
 
6176
\fBcomment\-begin\fP causes this command to make the current line
 
6177
a shell comment.
 
6178
If a numeric argument causes the comment character to be removed, the line
 
6179
will be executed by the shell.
 
6180
.TP
 
6181
.B glob\-complete\-word (M\-g)
 
6182
The word before point is treated as a pattern for pathname expansion,
 
6183
with an asterisk implicitly appended.  This pattern is used to
 
6184
generate a list of matching filenames for possible completions.
 
6185
.TP
 
6186
.B glob\-expand\-word (C\-x *)
 
6187
The word before point is treated as a pattern for pathname expansion,
 
6188
and the list of matching filenames is inserted, replacing the word.
 
6189
If a numeric argument is supplied, an asterisk is appended before
 
6190
pathname expansion.
 
6191
.TP
 
6192
.B glob\-list\-expansions (C\-x g)
 
6193
The list of expansions that would have been generated by
 
6194
.B glob\-expand\-word
 
6195
is displayed, and the line is redrawn.
 
6196
If a numeric argument is supplied, an asterisk is appended before
 
6197
pathname expansion.
 
6198
.TP
 
6199
.B dump\-functions
 
6200
Print all of the functions and their key bindings to the
 
6201
readline output stream.  If a numeric argument is supplied,
 
6202
the output is formatted in such a way that it can be made part
 
6203
of an \fIinputrc\fP file.
 
6204
.TP
 
6205
.B dump\-variables
 
6206
Print all of the settable readline variables and their values to the
 
6207
readline output stream.  If a numeric argument is supplied,
 
6208
the output is formatted in such a way that it can be made part
 
6209
of an \fIinputrc\fP file.
 
6210
.TP
 
6211
.B dump\-macros
 
6212
Print all of the readline key sequences bound to macros and the
 
6213
strings they output.  If a numeric argument is supplied,
 
6214
the output is formatted in such a way that it can be made part
 
6215
of an \fIinputrc\fP file.
 
6216
.TP
 
6217
.B display\-shell\-version (C\-x C\-v)
 
6218
Display version information about the current instance of
 
6219
.BR bash .
 
6220
.PD
 
6221
.SS Programmable Completion
 
6222
.PP
 
6223
When word completion is attempted for an argument to a command for
 
6224
which a completion specification (a \fIcompspec\fP) has been defined
 
6225
using the \fBcomplete\fP builtin (see
 
6226
.SM
 
6227
.B "SHELL BUILTIN COMMANDS"
 
6228
below), the programmable completion facilities are invoked.
 
6229
.PP
 
6230
First, the command name is identified.
 
6231
If the command word is the empty string (completion attempted at the
 
6232
beginning of an empty line), any compspec defined with
 
6233
the \fB\-E\fP option to \fBcomplete\fP is used.
 
6234
If a compspec has been defined for that command, the
 
6235
compspec is used to generate the list of possible completions for the word.
 
6236
If the command word is a full pathname, a compspec for the full
 
6237
pathname is searched for first.
 
6238
If no compspec is found for the full pathname, an attempt is made to
 
6239
find a compspec for the portion following the final slash.
 
6240
If those searches do not result in a compspec, any compspec defined with
 
6241
the \fB\-D\fP option to \fBcomplete\fP is used as the default.
 
6242
.PP
 
6243
Once a compspec has been found, it is used to generate the list of
 
6244
matching words.
 
6245
If a compspec is not found, the default \fBbash\fP completion as
 
6246
described above under \fBCompleting\fP is performed.
 
6247
.PP
 
6248
First, the actions specified by the compspec are used.
 
6249
Only matches which are prefixed by the word being completed are
 
6250
returned.
 
6251
When the
 
6252
.B \-f
 
6253
or
 
6254
.B \-d
 
6255
option is used for filename or directory name completion, the shell
 
6256
variable
 
6257
.SM
 
6258
.B FIGNORE
 
6259
is used to filter the matches.
 
6260
.PP
 
6261
Any completions specified by a pathname expansion pattern to the
 
6262
\fB\-G\fP option are generated next.
 
6263
The words generated by the pattern need not match the word
 
6264
being completed.
 
6265
The
 
6266
.SM
 
6267
.B GLOBIGNORE
 
6268
shell variable is not used to filter the matches, but the
 
6269
.SM
 
6270
.B FIGNORE
 
6271
variable is used.
 
6272
.PP
 
6273
Next, the string specified as the argument to the \fB\-W\fP option
 
6274
is considered.
 
6275
The string is first split using the characters in the
 
6276
.SM
 
6277
.B IFS
 
6278
special variable as delimiters.
 
6279
Shell quoting is honored.
 
6280
Each word is then expanded using
 
6281
brace expansion, tilde expansion, parameter and variable expansion,
 
6282
command substitution, and arithmetic expansion,
 
6283
as described above under 
 
6284
.SM
 
6285
.BR EXPANSION .
 
6286
The results are split using the rules described above under
 
6287
\fBWord Splitting\fP.
 
6288
The results of the expansion are prefix-matched against the word being
 
6289
completed, and the matching words become the possible completions.
 
6290
.PP
 
6291
After these matches have been generated, any shell function or command
 
6292
specified with the \fB\-F\fP and \fB\-C\fP options is invoked.
 
6293
When the command or function is invoked, the
 
6294
.SM
 
6295
.BR COMP_LINE ,
 
6296
.SM
 
6297
.BR COMP_POINT ,
 
6298
.SM
 
6299
.BR COMP_KEY ,
 
6300
and
 
6301
.SM
 
6302
.B COMP_TYPE
 
6303
variables are assigned values as described above under
 
6304
\fBShell Variables\fP.
 
6305
If a shell function is being invoked, the 
 
6306
.SM
 
6307
.B COMP_WORDS
 
6308
and
 
6309
.SM
 
6310
.B COMP_CWORD
 
6311
variables are also set.
 
6312
When the function or command is invoked,
 
6313
the first argument (\fB$1\fP) is the name of the command whose arguments are
 
6314
being completed,
 
6315
the second argument (\fB$2\fP) is the word being completed,
 
6316
and the third argument (\fB$3\fP) is the word preceding the word being
 
6317
completed on the current command line.
 
6318
No filtering of the generated completions against the word being completed
 
6319
is performed; the function or command has complete freedom in generating
 
6320
the matches.
 
6321
.PP
 
6322
Any function specified with \fB\-F\fP is invoked first.
 
6323
The function may use any of the shell facilities, including the
 
6324
\fBcompgen\fP builtin described below, to generate the matches.
 
6325
It must put the possible completions in the
 
6326
.SM
 
6327
.B COMPREPLY
 
6328
array variable, one per array element.
 
6329
.PP
 
6330
Next, any command specified with the \fB\-C\fP option is invoked
 
6331
in an environment equivalent to command substitution.
 
6332
It should print a list of completions, one per line, to the
 
6333
standard output.
 
6334
Backslash may be used to escape a newline, if necessary.
 
6335
.PP
 
6336
After all of the possible completions are generated, any filter
 
6337
specified with the \fB\-X\fP option is applied to the list.
 
6338
The filter is a pattern as used for pathname expansion; a \fB&\fP
 
6339
in the pattern is replaced with the text of the word being completed.
 
6340
A literal \fB&\fP may be escaped with a backslash; the backslash
 
6341
is removed before attempting a match.
 
6342
Any completion that matches the pattern will be removed from the list.
 
6343
A leading \fB!\fP negates the pattern; in this case any completion
 
6344
not matching the pattern will be removed.
 
6345
.PP
 
6346
Finally, any prefix and suffix specified with the \fB\-P\fP and \fB\-S\fP
 
6347
options are added to each member of the completion list, and the result is
 
6348
returned to the readline completion code as the list of possible
 
6349
completions.
 
6350
.PP
 
6351
If the previously-applied actions do not generate any matches, and the
 
6352
\fB\-o dirnames\fP option was supplied to \fBcomplete\fP when the
 
6353
compspec was defined, directory name completion is attempted.
 
6354
.PP
 
6355
If the \fB\-o plusdirs\fP option was supplied to \fBcomplete\fP when the
 
6356
compspec was defined, directory name completion is attempted and any
 
6357
matches are added to the results of the other actions.
 
6358
.PP
 
6359
By default, if a compspec is found, whatever it generates is returned
 
6360
to the completion code as the full set of possible completions.
 
6361
The default \fBbash\fP completions are not attempted, and the readline
 
6362
default of filename completion is disabled.
 
6363
If the \fB\-o bashdefault\fP option was supplied to \fBcomplete\fP when
 
6364
the compspec was defined, the \fBbash\fP default completions are attempted
 
6365
if the compspec generates no matches.
 
6366
If the \fB\-o default\fP option was supplied to \fBcomplete\fP when the
 
6367
compspec was defined, readline's default completion will be performed
 
6368
if the compspec (and, if attempted, the default \fBbash\fP completions)
 
6369
generate no matches.
 
6370
.PP
 
6371
When a compspec indicates that directory name completion is desired,
 
6372
the programmable completion functions force readline to append a slash
 
6373
to completed names which are symbolic links to directories, subject to  
 
6374
the value of the \fBmark\-directories\fP readline variable, regardless
 
6375
of the setting of the \fBmark-symlinked\-directories\fP readline variable.
 
6376
.PP
 
6377
There is some support for dynamically modifying completions.  This is
 
6378
most useful when used in combination with a default completion specified
 
6379
with \fBcomplete -D\fP.
 
6380
It's possible for shell functions executed as completion
 
6381
handlers to indicate that completion should be retried by returning an
 
6382
exit status of 124.  If a shell function returns 124, and changes
 
6383
the compspec associated with the command on which completion is being
 
6384
attempted (supplied as the first argument when the function is executed),
 
6385
programmable completion restarts from the beginning, with an
 
6386
attempt to find a new compspec for that command.  This allows a set of
 
6387
completions to be built dynamically as completion is attempted, rather than
 
6388
being loaded all at once.
 
6389
.PP
 
6390
For instance, assuming that there is a library of compspecs, each kept in a
 
6391
file corresponding to the name of the command, the following default
 
6392
completion function would load completions dynamically:
 
6393
.PP
 
6394
\f(CW_completion_loader()
 
6395
.br
 
6396
{
 
6397
.br
 
6398
        . "/etc/bash_completion.d/$1.sh" >/dev/null 2>&1 && return 124
 
6399
.br
 
6400
}
 
6401
.br
 
6402
complete -D -F _completion_loader -o bashdefault -o default
 
6403
.br
 
6404
\fP
 
6405
.SH HISTORY
 
6406
When the
 
6407
.B \-o history
 
6408
option to the
 
6409
.B set
 
6410
builtin is enabled, the shell provides access to the
 
6411
\fIcommand history\fP,
 
6412
the list of commands previously typed.
 
6413
The value of the
 
6414
.SM
 
6415
.B HISTSIZE
 
6416
variable is used as the
 
6417
number of commands to save in a history list.
 
6418
The text of the last
 
6419
.SM
 
6420
.B HISTSIZE
 
6421
commands (default 500) is saved.  The shell
 
6422
stores each command in the history list prior to parameter and
 
6423
variable expansion (see
 
6424
.SM
 
6425
.B EXPANSION
 
6426
above) but after history expansion is performed, subject to the
 
6427
values of the shell variables
 
6428
.SM
 
6429
.B HISTIGNORE
 
6430
and
 
6431
.SM
 
6432
.BR HISTCONTROL .
 
6433
.PP
 
6434
On startup, the history is initialized from the file named by
 
6435
the variable
 
6436
.SM
 
6437
.B HISTFILE
 
6438
(default \fI~/.bash_history\fP).
 
6439
The file named by the value of
 
6440
.SM
 
6441
.B HISTFILE
 
6442
is truncated, if necessary, to contain no more than
 
6443
the number of lines specified by the value of
 
6444
.SM
 
6445
.BR HISTFILESIZE .
 
6446
If \fBHISTFILESIZE\fP is unset, or set to null, a non-numeric value,
 
6447
or a numeric value less than zero, the history file is not truncated.
 
6448
When the history file is read,
 
6449
lines beginning with the history comment character followed immediately
 
6450
by a digit are interpreted as timestamps for the preceding history line.
 
6451
These timestamps are optionally displayed depending on the value of the
 
6452
.SM
 
6453
.B HISTTIMEFORMAT
 
6454
variable.
 
6455
When a shell with history enabled exits, the last
 
6456
.SM
 
6457
.B $HISTSIZE
 
6458
lines are copied from the history list to
 
6459
.SM
 
6460
.BR $HISTFILE .
 
6461
If the
 
6462
.B histappend
 
6463
shell option is enabled
 
6464
(see the description of
 
6465
.B shopt
 
6466
under
 
6467
.SM
 
6468
.B "SHELL BUILTIN COMMANDS"
 
6469
below), the lines are appended to the history file,
 
6470
otherwise the history file is overwritten.
 
6471
If
 
6472
.SM
 
6473
.B HISTFILE
 
6474
is unset, or if the history file is unwritable, the history is
 
6475
not saved.
 
6476
If the
 
6477
.SM
 
6478
.B HISTTIMEFORMAT
 
6479
variable is set, time stamps are written to the history file, marked
 
6480
with the history comment character, so
 
6481
they may be preserved across shell sessions.
 
6482
This uses the history comment character to distinguish timestamps from
 
6483
other history lines.
 
6484
After saving the history, the history file is truncated
 
6485
to contain no more than
 
6486
.SM
 
6487
.B HISTFILESIZE
 
6488
lines.  If
 
6489
.SM
 
6490
.B HISTFILESIZE
 
6491
is unset, or set to null, a non-numeric value,
 
6492
or a numeric value less than zero, the history file is not truncated.
 
6493
.PP
 
6494
The builtin command
 
6495
.B fc
 
6496
(see
 
6497
.SM
 
6498
.B SHELL BUILTIN COMMANDS
 
6499
below) may be used to list or edit and re-execute a portion of
 
6500
the history list.
 
6501
The
 
6502
.B history
 
6503
builtin may be used to display or modify the history list and
 
6504
manipulate the history file.
 
6505
When using command-line editing, search commands
 
6506
are available in each editing mode that provide access to the
 
6507
history list.
 
6508
.PP
 
6509
The shell allows control over which commands are saved on the history
 
6510
list.  The
 
6511
.SM
 
6512
.B HISTCONTROL
 
6513
and
 
6514
.SM
 
6515
.B HISTIGNORE
 
6516
variables may be set to cause the shell to save only a subset of the
 
6517
commands entered.
 
6518
The
 
6519
.B cmdhist
 
6520
shell option, if enabled, causes the shell to attempt to save each
 
6521
line of a multi-line command in the same history entry, adding
 
6522
semicolons where necessary to preserve syntactic correctness.
 
6523
The
 
6524
.B lithist
 
6525
shell option causes the shell to save the command with embedded newlines
 
6526
instead of semicolons.  See the description of the
 
6527
.B shopt
 
6528
builtin below under
 
6529
.SM
 
6530
.B "SHELL BUILTIN COMMANDS"
 
6531
for information on setting and unsetting shell options.
 
6532
.SH "HISTORY EXPANSION"
 
6533
.PP
 
6534
The shell supports a history expansion feature that
 
6535
is similar to the history expansion in
 
6536
.BR csh.
 
6537
This section describes what syntax features are available.  This
 
6538
feature is enabled by default for interactive shells, and can be
 
6539
disabled using the
 
6540
.B +H
 
6541
option to the
 
6542
.B set
 
6543
builtin command (see
 
6544
.SM
 
6545
.B SHELL BUILTIN COMMANDS
 
6546
below).  Non-interactive shells do not perform history expansion
 
6547
by default.
 
6548
.PP
 
6549
History expansions introduce words from the history list into
 
6550
the input stream, making it easy to repeat commands, insert the
 
6551
arguments to a previous command into the current input line, or
 
6552
fix errors in previous commands quickly.
 
6553
.PP
 
6554
History expansion is performed immediately after a complete line
 
6555
is read, before the shell breaks it into words.
 
6556
It takes place in two parts.
 
6557
The first is to determine which line from the history list
 
6558
to use during substitution.
 
6559
The second is to select portions of that line for inclusion into
 
6560
the current one.
 
6561
The line selected from the history is the \fIevent\fP,
 
6562
and the portions of that line that are acted upon are \fIwords\fP.
 
6563
Various \fImodifiers\fP are available to manipulate the selected words.
 
6564
The line is broken into words in the same fashion as when reading input,
 
6565
so that several \fImetacharacter\fP-separated words surrounded by
 
6566
quotes are considered one word.
 
6567
History expansions are introduced by the appearance of the
 
6568
history expansion character, which is \^\fB!\fP\^ by default.
 
6569
Only backslash (\^\fB\e\fP\^) and single quotes can quote
 
6570
the history expansion character.
 
6571
.PP
 
6572
Several characters inhibit history expansion if found immediately
 
6573
following the history expansion character, even if it is unquoted:
 
6574
space, tab, newline, carriage return, and \fB=\fP.
 
6575
If the \fBextglob\fP shell option is enabled, \fB(\fP will also
 
6576
inhibit expansion.
 
6577
.PP
 
6578
Several shell options settable with the
 
6579
.B shopt
 
6580
builtin may be used to tailor the behavior of history expansion.
 
6581
If the
 
6582
.B histverify
 
6583
shell option is enabled (see the description of the
 
6584
.B shopt
 
6585
builtin below), and
 
6586
.B readline
 
6587
is being used, history substitutions are not immediately passed to
 
6588
the shell parser.
 
6589
Instead, the expanded line is reloaded into the
 
6590
.B readline
 
6591
editing buffer for further modification.
 
6592
If
 
6593
.B readline
 
6594
is being used, and the
 
6595
.B histreedit
 
6596
shell option is enabled, a failed history substitution will be reloaded
 
6597
into the
 
6598
.B readline
 
6599
editing buffer for correction.
 
6600
The
 
6601
.B \-p
 
6602
option to the
 
6603
.B history
 
6604
builtin command may be used to see what a history expansion will
 
6605
do before using it.
 
6606
The
 
6607
.B \-s
 
6608
option to the
 
6609
.B history
 
6610
builtin may be used to add commands to the end of the history list
 
6611
without actually executing them, so that they are available for
 
6612
subsequent recall.
 
6613
.PP
 
6614
The shell allows control of the various characters used by the
 
6615
history expansion mechanism (see the description of
 
6616
.B histchars
 
6617
above under
 
6618
.BR "Shell Variables" ).
 
6619
The shell uses
 
6620
the history comment character to mark history timestamps when
 
6621
writing the history file.
 
6622
.SS Event Designators
 
6623
.PP
 
6624
An event designator is a reference to a command line entry in the
 
6625
history list.
 
6626
Unless the reference is absolute, events are relative to the current
 
6627
position in the history list.
 
6628
.PP
 
6629
.PD 0
 
6630
.TP
 
6631
.B !
 
6632
Start a history substitution, except when followed by a
 
6633
.BR blank ,
 
6634
newline, carriage return, =
 
6635
or ( (when the \fBextglob\fP shell option is enabled using
 
6636
the \fBshopt\fP builtin).
 
6637
.TP
 
6638
.B !\fIn\fR
 
6639
Refer to command line
 
6640
.IR n .
 
6641
.TP
 
6642
.B !\-\fIn\fR
 
6643
Refer to the current command minus
 
6644
.IR n .
 
6645
.TP
 
6646
.B !!
 
6647
Refer to the previous command.  This is a synonym for `!\-1'.
 
6648
.TP
 
6649
.B !\fIstring\fR
 
6650
Refer to the most recent command preceding the current position in the
 
6651
history list starting with
 
6652
.IR string .
 
6653
.TP
 
6654
.B !?\fIstring\fR\fB[?]\fR
 
6655
Refer to the most recent command preceding the current position in the
 
6656
history list containing
 
6657
.IR string .
 
6658
The trailing \fB?\fP may be omitted if
 
6659
.I string
 
6660
is followed immediately by a newline.
 
6661
.TP
 
6662
.B \d\s+2^\s-2\u\fIstring1\fP\d\s+2^\s-2\u\fIstring2\fP\d\s+2^\s-2\u
 
6663
Quick substitution.  Repeat the previous command, replacing
 
6664
.I string1
 
6665
with
 
6666
.IR string2 .
 
6667
Equivalent to
 
6668
``!!:s/\fIstring1\fP/\fIstring2\fP/''
 
6669
(see \fBModifiers\fP below).
 
6670
.TP
 
6671
.B !#
 
6672
The entire command line typed so far.
 
6673
.PD
 
6674
.SS Word Designators
 
6675
.PP
 
6676
Word designators are used to select desired words from the event.
 
6677
 
6678
.B :
 
6679
separates the event specification from the word designator.
 
6680
It may be omitted if the word designator begins with a
 
6681
.BR ^ ,
 
6682
.BR $ ,
 
6683
.BR * ,
 
6684
.BR \- ,
 
6685
or
 
6686
.BR % .
 
6687
Words are numbered from the beginning of the line,
 
6688
with the first word being denoted by 0 (zero).
 
6689
Words are inserted into the current line separated by single spaces.
 
6690
.PP
 
6691
.PD 0
 
6692
.TP
 
6693
.B 0 (zero)
 
6694
The zeroth word.  For the shell, this is the command
 
6695
word.
 
6696
.TP
 
6697
.I n
 
6698
The \fIn\fRth word.
 
6699
.TP
 
6700
.B ^
 
6701
The first argument.  That is, word 1.
 
6702
.TP
 
6703
.B $
 
6704
The last word.  This is usually the last argument, but will expand to the
 
6705
zeroth word if there is only one word in the line.
 
6706
.TP
 
6707
.B %
 
6708
The word matched by the most recent `?\fIstring\fR?' search.
 
6709
.TP
 
6710
.I x\fB\-\fPy
 
6711
A range of words; `\-\fIy\fR' abbreviates `0\-\fIy\fR'.
 
6712
.TP
 
6713
.B *
 
6714
All of the words but the zeroth.  This is a synonym
 
6715
for `\fI1\-$\fP'.  It is not an error to use
 
6716
.B *
 
6717
if there is just one
 
6718
word in the event; the empty string is returned in that case.
 
6719
.TP
 
6720
.B x*
 
6721
Abbreviates \fIx\-$\fP.
 
6722
.TP
 
6723
.B x\-
 
6724
Abbreviates \fIx\-$\fP like \fBx*\fP, but omits the last word.
 
6725
.PD
 
6726
.PP
 
6727
If a word designator is supplied without an event specification, the
 
6728
previous command is used as the event.
 
6729
.SS Modifiers
 
6730
.PP
 
6731
After the optional word designator, there may appear a sequence of
 
6732
one or more of the following modifiers, each preceded by a `:'.
 
6733
.PP
 
6734
.PD 0
 
6735
.PP
 
6736
.TP
 
6737
.B h
 
6738
Remove a trailing filename component, leaving only the head.
 
6739
.TP
 
6740
.B t
 
6741
Remove all leading filename components, leaving the tail.
 
6742
.TP
 
6743
.B r
 
6744
Remove a trailing suffix of the form \fI.xxx\fP, leaving the
 
6745
basename.
 
6746
.TP
 
6747
.B e
 
6748
Remove all but the trailing suffix.
 
6749
.TP
 
6750
.B p
 
6751
Print the new command but do not execute it.
 
6752
.TP
 
6753
.B q
 
6754
Quote the substituted words, escaping further substitutions.
 
6755
.TP
 
6756
.B x
 
6757
Quote the substituted words as with
 
6758
.BR q ,
 
6759
but break into words at
 
6760
.B blanks
 
6761
and newlines.
 
6762
.TP
 
6763
.B s/\fIold\fP/\fInew\fP/
 
6764
Substitute
 
6765
.I new
 
6766
for the first occurrence of
 
6767
.I old
 
6768
in the event line.  Any delimiter can be used in place of /.  The
 
6769
final delimiter is optional if it is the last character of the
 
6770
event line.  The delimiter may be quoted in
 
6771
.I old
 
6772
and
 
6773
.I new
 
6774
with a single backslash.  If & appears in
 
6775
.IR new ,
 
6776
it is replaced by
 
6777
.IR old .
 
6778
A single backslash will quote the &.  If
 
6779
.I old
 
6780
is null, it is set to the last
 
6781
.I old
 
6782
substituted, or, if no previous history substitutions took place,
 
6783
the last
 
6784
.I string
 
6785
in a
 
6786
.B !?\fIstring\fR\fB[?]\fR
 
6787
search.
 
6788
.TP
 
6789
.B &
 
6790
Repeat the previous substitution.
 
6791
.TP
 
6792
.B g
 
6793
Cause changes to be applied over the entire event line.  This is
 
6794
used in conjunction with `\fB:s\fP' (e.g., `\fB:gs/\fIold\fP/\fInew\fP/\fR')
 
6795
or `\fB:&\fP'.  If used with
 
6796
`\fB:s\fP', any delimiter can be used
 
6797
in place of /, and the final delimiter is optional
 
6798
if it is the last character of the event line.
 
6799
An \fBa\fP may be used as a synonym for \fBg\fP.
 
6800
.TP
 
6801
.B G
 
6802
Apply the following `\fBs\fP' modifier once to each word in the event line.
 
6803
.PD
 
6804
.SH "SHELL BUILTIN COMMANDS"
 
6805
.\" start of bash_builtins
 
6806
.zZ
 
6807
.PP
 
6808
Unless otherwise noted, each builtin command documented in this
 
6809
section as accepting options preceded by
 
6810
.B \-
 
6811
accepts
 
6812
.B \-\-
 
6813
to signify the end of the options.
 
6814
The \fB:\fP, \fBtrue\fP, \fBfalse\fP, and \fBtest\fP builtins
 
6815
do not accept options and do not treat \fB\-\-\fP specially.
 
6816
The \fBexit\fP, \fBlogout\fP, \fBbreak\fP, \fBcontinue\fP, \fBlet\fP,
 
6817
and \fBshift\fP builtins accept and process arguments beginning with
 
6818
\fB\-\fP without requiring \fB\-\-\fP.
 
6819
Other builtins that accept arguments but are not specified as accepting
 
6820
options interpret arguments beginning with \fB\-\fP as invalid options and
 
6821
require \fB\-\-\fP to prevent this interpretation.
 
6822
.sp .5
 
6823
.PD 0
 
6824
.TP
 
6825
\fB:\fP [\fIarguments\fP]
 
6826
.PD
 
6827
No effect; the command does nothing beyond expanding
 
6828
.I arguments
 
6829
and performing any specified
 
6830
redirections.  A zero exit code is returned.
 
6831
.TP
 
6832
\fB .\| \fP \fIfilename\fP [\fIarguments\fP]
 
6833
.PD 0
 
6834
.TP
 
6835
\fBsource\fP \fIfilename\fP [\fIarguments\fP]
 
6836
.PD
 
6837
Read and execute commands from
 
6838
.I filename
 
6839
in the current
 
6840
shell environment and return the exit status of the last command
 
6841
executed from
 
6842
.IR filename .
 
6843
If
 
6844
.I filename
 
6845
does not contain a slash, filenames in
 
6846
.SM
 
6847
.B PATH
 
6848
are used to find the directory containing
 
6849
.IR filename .
 
6850
The file searched for in
 
6851
.SM
 
6852
.B PATH
 
6853
need not be executable.
 
6854
When \fBbash\fP is not in \fIposix mode\fP, the current directory is
 
6855
searched if no file is found in
 
6856
.SM
 
6857
.BR PATH .
 
6858
If the
 
6859
.B sourcepath
 
6860
option to the
 
6861
.B shopt
 
6862
builtin command is turned off, the
 
6863
.SM
 
6864
.B PATH
 
6865
is not searched.
 
6866
If any \fIarguments\fP are supplied, they become the positional
 
6867
parameters when \fIfilename\fP is executed.  Otherwise the positional
 
6868
parameters are unchanged.
 
6869
The return status is the status of the last command exited within
 
6870
the script (0 if no commands are executed), and false if
 
6871
.I filename
 
6872
is not found or cannot be read.
 
6873
.TP
 
6874
\fBalias\fP [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...]
 
6875
\fBAlias\fP with no arguments or with the
 
6876
.B \-p
 
6877
option prints the list of aliases in the form
 
6878
\fBalias\fP \fIname\fP=\fIvalue\fP on standard output.
 
6879
When arguments are supplied, an alias is defined for
 
6880
each \fIname\fP whose \fIvalue\fP is given.
 
6881
A trailing space in  \fIvalue\fP causes the next word to be
 
6882
checked for alias substitution when the alias is expanded.
 
6883
For each \fIname\fP in the argument list for which no \fIvalue\fP
 
6884
is supplied, the name and value of the alias is printed.
 
6885
\fBAlias\fP returns true unless a \fIname\fP is given for which
 
6886
no alias has been defined.
 
6887
.TP
 
6888
\fBbg\fP [\fIjobspec\fP ...]
 
6889
Resume each suspended job \fIjobspec\fP in the background, as if it
 
6890
had been started with
 
6891
.BR & .
 
6892
If
 
6893
.I jobspec
 
6894
is not present, the shell's notion of the \fIcurrent job\fP is used.
 
6895
.B bg
 
6896
.I jobspec
 
6897
returns 0 unless run when job control is disabled or, when run with
 
6898
job control enabled, any specified \fIjobspec\fP was not found
 
6899
or was started without job control.
 
6900
.TP
 
6901
\fBbind\fP [\fB\-m\fP \fIkeymap\fP] [\fB\-lpsvPSVX\fP]
 
6902
.PD 0
 
6903
.TP
 
6904
\fBbind\fP [\fB\-m\fP \fIkeymap\fP] [\fB\-q\fP \fIfunction\fP] [\fB\-u\fP \fIfunction\fP] [\fB\-r\fP \fIkeyseq\fP]
 
6905
.TP
 
6906
\fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-f\fP \fIfilename\fP
 
6907
.TP
 
6908
\fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-x\fP \fIkeyseq\fP:\fIshell\-command\fP
 
6909
.TP
 
6910
\fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fIkeyseq\fP:\fIfunction\-name\fP
 
6911
.TP
 
6912
\fBbind\fP \fIreadline\-command\fP
 
6913
.PD
 
6914
Display current
 
6915
.B readline
 
6916
key and function bindings, bind a key sequence to a
 
6917
.B readline
 
6918
function or macro, or set a
 
6919
.B readline
 
6920
variable.
 
6921
Each non-option argument is a command as it would appear in
 
6922
.IR .inputrc ,
 
6923
but each binding or command must be passed as a separate argument;
 
6924
e.g., '"\eC\-x\eC\-r": re\-read\-init\-file'.
 
6925
Options, if supplied, have the following meanings:
 
6926
.RS
 
6927
.PD 0
 
6928
.TP
 
6929
.B \-m \fIkeymap\fP
 
6930
Use
 
6931
.I keymap
 
6932
as the keymap to be affected by the subsequent bindings.
 
6933
Acceptable
 
6934
.I keymap
 
6935
names are
 
6936
\fIemacs, emacs\-standard, emacs\-meta, emacs\-ctlx, vi,
 
6937
vi\-move, vi\-command\fP, and
 
6938
.IR vi\-insert .
 
6939
\fIvi\fP is equivalent to \fIvi\-command\fP; \fIemacs\fP is
 
6940
equivalent to \fIemacs\-standard\fP.
 
6941
.TP
 
6942
.B \-l
 
6943
List the names of all \fBreadline\fP functions.
 
6944
.TP
 
6945
.B \-p
 
6946
Display \fBreadline\fP function names and bindings in such a way
 
6947
that they can be re-read.
 
6948
.TP
 
6949
.B \-P
 
6950
List current \fBreadline\fP function names and bindings.
 
6951
.TP
 
6952
.B \-s
 
6953
Display \fBreadline\fP key sequences bound to macros and the strings
 
6954
they output in such a way that they can be re-read.
 
6955
.TP
 
6956
.B \-S
 
6957
Display \fBreadline\fP key sequences bound to macros and the strings
 
6958
they output.
 
6959
.TP
 
6960
.B \-v
 
6961
Display \fBreadline\fP variable names and values in such a way that they
 
6962
can be re-read.
 
6963
.TP
 
6964
.B \-V
 
6965
List current \fBreadline\fP variable names and values.
 
6966
.TP
 
6967
.B \-f \fIfilename\fP
 
6968
Read key bindings from \fIfilename\fP.
 
6969
.TP
 
6970
.B \-q \fIfunction\fP
 
6971
Query about which keys invoke the named \fIfunction\fP.
 
6972
.TP
 
6973
.B \-u \fIfunction\fP
 
6974
Unbind all keys bound to the named \fIfunction\fP.
 
6975
.TP
 
6976
.B \-r \fIkeyseq\fP
 
6977
Remove any current binding for \fIkeyseq\fP.
 
6978
.TP
 
6979
.B \-x \fIkeyseq\fP:\fIshell\-command\fP
 
6980
Cause \fIshell\-command\fP to be executed whenever \fIkeyseq\fP is
 
6981
entered.
 
6982
When \fIshell\-command\fP is executed, the shell sets the
 
6983
.SM
 
6984
.B READLINE_LINE
 
6985
variable to the contents of the \fBreadline\fP line buffer and the
 
6986
.SM
 
6987
.B READLINE_POINT
 
6988
variable to the current location of the insertion point.
 
6989
If the executed command changes the value of
 
6990
.SM
 
6991
.B READLINE_LINE
 
6992
or
 
6993
.SM
 
6994
.BR READLINE_POINT ,
 
6995
those new values will be reflected in the editing state.
 
6996
.TP
 
6997
.B \-X
 
6998
List all key sequences bound to shell commands and the associated commands
 
6999
in a format that can be reused as input.
 
7000
.PD
 
7001
.PP
 
7002
The return value is 0 unless an unrecognized option is given or an
 
7003
error occurred.
 
7004
.RE
 
7005
.TP
 
7006
\fBbreak\fP [\fIn\fP]
 
7007
Exit from within a
 
7008
.BR for ,
 
7009
.BR while ,
 
7010
.BR until ,
 
7011
or
 
7012
.B select
 
7013
loop.  If \fIn\fP is specified, break \fIn\fP levels.
 
7014
.I n
 
7015
must be \(>= 1.  If
 
7016
.I n
 
7017
is greater than the number of enclosing loops, all enclosing loops
 
7018
are exited.
 
7019
The return value is 0 unless \fIn\fP is not greater than or equal to 1.
 
7020
.TP
 
7021
\fBbuiltin\fP \fIshell\-builtin\fP [\fIarguments\fP]
 
7022
Execute the specified shell builtin, passing it
 
7023
.IR arguments ,
 
7024
and return its exit status.
 
7025
This is useful when defining a
 
7026
function whose name is the same as a shell builtin,
 
7027
retaining the functionality of the builtin within the function.
 
7028
The \fBcd\fP builtin is commonly redefined this way.
 
7029
The return status is false if
 
7030
.I shell\-builtin
 
7031
is not a shell builtin command.
 
7032
.TP
 
7033
\fBcaller\fP [\fIexpr\fP]
 
7034
Returns the context of any active subroutine call (a shell function or
 
7035
a script executed with the \fB.\fP or \fBsource\fP builtins).
 
7036
Without \fIexpr\fP, \fBcaller\fP displays the line number and source
 
7037
filename of the current subroutine call.
 
7038
If a non-negative integer is supplied as \fIexpr\fP, \fBcaller\fP 
 
7039
displays the line number, subroutine name, and source file corresponding
 
7040
to that position in the current execution call stack.  This extra
 
7041
information may be used, for example, to print a stack trace.  The
 
7042
current frame is frame 0.
 
7043
The return value is 0 unless the shell is not executing a subroutine
 
7044
call or \fIexpr\fP does not correspond to a valid position in the
 
7045
call stack.
 
7046
.TP
 
7047
\fBcd\fP [\fB\-L\fP|[\fB\-P\fP [\fB\-e\fP]] [\-@]] [\fIdir\fP]
 
7048
Change the current directory to \fIdir\fP.
 
7049
if \fIdir\fP is not supplied, the value of the
 
7050
.SM
 
7051
.B HOME
 
7052
shell variable is the default.
 
7053
Any additional arguments following \fIdir\fP are ignored.
 
7054
The variable
 
7055
.SM
 
7056
.B CDPATH
 
7057
defines the search path for the directory containing
 
7058
.IR dir :
 
7059
each directory name in
 
7060
.SM
 
7061
.B CDPATH
 
7062
is searched for \fIdir\fP.
 
7063
Alternative directory names in
 
7064
.SM
 
7065
.B CDPATH
 
7066
are separated by a colon (:).  A null directory name in
 
7067
.SM
 
7068
.B CDPATH
 
7069
is the same as the current directory, i.e., ``\fB.\fP''.  If
 
7070
.I dir
 
7071
begins with a slash (/),
 
7072
then
 
7073
.SM
 
7074
.B CDPATH
 
7075
is not used. The
 
7076
.B \-P
 
7077
option causes \fBcd\fP to use the physical directory structure
 
7078
by resolving symbolic links while traversing \fIdir\fP and
 
7079
before processing instances of \fI..\fP in \fIdir\fP (see also the
 
7080
.B \-P
 
7081
option to the
 
7082
.B set
 
7083
builtin command); the
 
7084
.B \-L
 
7085
option forces symbolic links to be followed by resolving the link
 
7086
after processing instances of \fI..\fP in \fIdir\fP.
 
7087
If \fI..\fP appears in \fIdir\fP, it is processed by removing the
 
7088
immediately previous pathname component from \fIdir\fP, back to a slash
 
7089
or the beginning of \fIdir\fP.
 
7090
If the
 
7091
.B \-e
 
7092
option is supplied with
 
7093
.BR \-P ,
 
7094
and the current working directory cannot be successfully determined
 
7095
after a successful directory change, \fBcd\fP will return an unsuccessful
 
7096
status.
 
7097
On systems that support it, the \fB\-@\fP option presents the extended
 
7098
attributes associated with a file as a directory.
 
7099
An argument of
 
7100
.B \-
 
7101
is converted to
 
7102
.SM
 
7103
.B $OLDPWD
 
7104
before the directory change is attempted.
 
7105
If a non-empty directory name from
 
7106
.SM
 
7107
.B CDPATH
 
7108
is used, or if
 
7109
\fB\-\fP is the first argument, and the directory change is
 
7110
successful, the absolute pathname of the new working directory is
 
7111
written to the standard output.
 
7112
The return value is true if the directory was successfully changed;
 
7113
false otherwise.
 
7114
.TP
 
7115
\fBcommand\fP [\fB\-pVv\fP] \fIcommand\fP [\fIarg\fP ...]
 
7116
Run
 
7117
.I command
 
7118
with
 
7119
.I args
 
7120
suppressing the normal shell function lookup. Only builtin
 
7121
commands or commands found in the
 
7122
.SM
 
7123
.B PATH
 
7124
are executed.  If the
 
7125
.B \-p
 
7126
option is given, the search for
 
7127
.I command
 
7128
is performed using a default value for
 
7129
.SM
 
7130
.B PATH
 
7131
that is guaranteed to find all of the standard utilities.
 
7132
If either the
 
7133
.B \-V
 
7134
or
 
7135
.B \-v
 
7136
option is supplied, a description of
 
7137
.I command
 
7138
is printed.  The
 
7139
.B \-v
 
7140
option causes a single word indicating the command or filename
 
7141
used to invoke
 
7142
.I command
 
7143
to be displayed; the
 
7144
.B \-V
 
7145
option produces a more verbose description.
 
7146
If the
 
7147
.B \-V
 
7148
or
 
7149
.B \-v
 
7150
option is supplied, the exit status is 0 if
 
7151
.I command
 
7152
was found, and 1 if not.  If neither option is supplied and
 
7153
an error occurred or
 
7154
.I command
 
7155
cannot be found, the exit status is 127.  Otherwise, the exit status of the
 
7156
.B command
 
7157
builtin is the exit status of
 
7158
.IR command .
 
7159
.TP
 
7160
\fBcompgen\fP [\fIoption\fP] [\fIword\fP]
 
7161
Generate possible completion matches for \fIword\fP according to
 
7162
the \fIoption\fPs, which may be any option accepted by the
 
7163
.B complete
 
7164
builtin with the exception of \fB\-p\fP and \fB\-r\fP, and write
 
7165
the matches to the standard output.
 
7166
When using the \fB\-F\fP or \fB\-C\fP options, the various shell variables
 
7167
set by the programmable completion facilities, while available, will not
 
7168
have useful values.
 
7169
.sp 1
 
7170
The matches will be generated in the same way as if the programmable
 
7171
completion code had generated them directly from a completion specification
 
7172
with the same flags.
 
7173
If \fIword\fP is specified, only those completions matching \fIword\fP
 
7174
will be displayed.
 
7175
.sp 1
 
7176
The return value is true unless an invalid option is supplied, or no
 
7177
matches were generated.
 
7178
.TP
 
7179
\fBcomplete\fP [\fB\-abcdefgjksuv\fP] [\fB\-o\fP \fIcomp-option\fP] [\fB\-DE\fP] [\fB\-A\fP \fIaction\fP] [\fB\-G\fP \fIglobpat\fP] [\fB\-W\fP \fIwordlist\fP] [\fB\-F\fP \fIfunction\fP] [\fB\-C\fP \fIcommand\fP]
 
7180
.br
 
7181
[\fB\-X\fP \fIfilterpat\fP] [\fB\-P\fP \fIprefix\fP] [\fB\-S\fP \fIsuffix\fP] \fIname\fP [\fIname ...\fP]
 
7182
.PD 0
 
7183
.TP
 
7184
\fBcomplete\fP \fB\-pr\fP [\fB\-DE\fP] [\fIname\fP ...]
 
7185
.PD
 
7186
Specify how arguments to each \fIname\fP should be completed.
 
7187
If the \fB\-p\fP option is supplied, or if no options are supplied,
 
7188
existing completion specifications are printed in a way that allows
 
7189
them to be reused as input.
 
7190
The \fB\-r\fP option removes a completion specification for
 
7191
each \fIname\fP, or, if no \fIname\fPs are supplied, all
 
7192
completion specifications.
 
7193
The \fB\-D\fP option indicates that the remaining options and actions should
 
7194
apply to the ``default'' command completion; that is, completion attempted
 
7195
on a command for which no completion has previously been defined.
 
7196
The \fB\-E\fP option indicates that the remaining options and actions should
 
7197
apply to ``empty'' command completion; that is, completion attempted on a
 
7198
blank line.
 
7199
.sp 1
 
7200
The process of applying these completion specifications when word completion
 
7201
is attempted is described above under \fBProgrammable Completion\fP.
 
7202
.sp 1
 
7203
Other options, if specified, have the following meanings.
 
7204
The arguments to the \fB\-G\fP, \fB\-W\fP, and \fB\-X\fP options
 
7205
(and, if necessary, the \fB\-P\fP and \fB\-S\fP options)
 
7206
should be quoted to protect them from expansion before the
 
7207
.B complete
 
7208
builtin is invoked.
 
7209
.RS
 
7210
.PD 0
 
7211
.TP 8
 
7212
\fB\-o\fP \fIcomp-option\fP
 
7213
The \fIcomp-option\fP controls several aspects of the compspec's behavior
 
7214
beyond the simple generation of completions.
 
7215
\fIcomp-option\fP may be one of:
 
7216
.RS
 
7217
.TP 8
 
7218
.B bashdefault
 
7219
Perform the rest of the default \fBbash\fP completions if the compspec
 
7220
generates no matches.
 
7221
.TP 8
 
7222
.B default
 
7223
Use readline's default filename completion if the compspec generates
 
7224
no matches.
 
7225
.TP 8
 
7226
.B dirnames
 
7227
Perform directory name completion if the compspec generates no matches.
 
7228
.TP 8
 
7229
.B filenames
 
7230
Tell readline that the compspec generates filenames, so it can perform any
 
7231
filename\-specific processing (like adding a slash to directory names,
 
7232
quoting special characters, or suppressing trailing spaces).
 
7233
Intended to be used with shell functions.
 
7234
.TP 8
 
7235
.B noquote
 
7236
Tell readline not to quote the completed words if they are filenames
 
7237
(quoting filenames is the default).
 
7238
.TP 8
 
7239
.B nospace
 
7240
Tell readline not to append a space (the default) to words completed at
 
7241
the end of the line.
 
7242
.TP 8
 
7243
.B plusdirs
 
7244
After any matches defined by the compspec are generated, 
 
7245
directory name completion is attempted and any
 
7246
matches are added to the results of the other actions.
 
7247
.RE
 
7248
.TP 8
 
7249
\fB\-A\fP \fIaction\fP
 
7250
The \fIaction\fP may be one of the following to generate a list of possible
 
7251
completions:
 
7252
.RS
 
7253
.TP 8
 
7254
.B alias
 
7255
Alias names.  May also be specified as \fB\-a\fP.
 
7256
.TP 8
 
7257
.B arrayvar
 
7258
Array variable names.
 
7259
.TP 8
 
7260
.B binding
 
7261
\fBReadline\fP key binding names.
 
7262
.TP 8
 
7263
.B builtin
 
7264
Names of shell builtin commands.  May also be specified as \fB\-b\fP.
 
7265
.TP 8
 
7266
.B command
 
7267
Command names.  May also be specified as \fB\-c\fP.
 
7268
.TP 8
 
7269
.B directory
 
7270
Directory names.  May also be specified as \fB\-d\fP.
 
7271
.TP 8
 
7272
.B disabled
 
7273
Names of disabled shell builtins.
 
7274
.TP 8
 
7275
.B enabled
 
7276
Names of enabled shell builtins.
 
7277
.TP 8
 
7278
.B export
 
7279
Names of exported shell variables.  May also be specified as \fB\-e\fP.
 
7280
.TP 8
 
7281
.B file
 
7282
File names.  May also be specified as \fB\-f\fP.
 
7283
.TP 8
 
7284
.B function
 
7285
Names of shell functions.
 
7286
.TP 8
 
7287
.B group
 
7288
Group names.  May also be specified as \fB\-g\fP.
 
7289
.TP 8
 
7290
.B helptopic
 
7291
Help topics as accepted by the \fBhelp\fP builtin.
 
7292
.TP 8
 
7293
.B hostname
 
7294
Hostnames, as taken from the file specified by the
 
7295
.SM
 
7296
.B HOSTFILE
 
7297
shell variable.
 
7298
.TP 8
 
7299
.B job
 
7300
Job names, if job control is active.  May also be specified as \fB\-j\fP.
 
7301
.TP 8
 
7302
.B keyword
 
7303
Shell reserved words.  May also be specified as \fB\-k\fP.
 
7304
.TP 8
 
7305
.B running
 
7306
Names of running jobs, if job control is active.
 
7307
.TP 8
 
7308
.B service
 
7309
Service names.  May also be specified as \fB\-s\fP.
 
7310
.TP 8
 
7311
.B setopt
 
7312
Valid arguments for the \fB\-o\fP option to the \fBset\fP builtin.
 
7313
.TP 8
 
7314
.B shopt
 
7315
Shell option names as accepted by the \fBshopt\fP builtin.
 
7316
.TP 8
 
7317
.B signal
 
7318
Signal names.
 
7319
.TP 8
 
7320
.B stopped
 
7321
Names of stopped jobs, if job control is active.
 
7322
.TP 8
 
7323
.B user
 
7324
User names.  May also be specified as \fB\-u\fP.
 
7325
.TP 8
 
7326
.B variable
 
7327
Names of all shell variables.  May also be specified as \fB\-v\fP.
 
7328
.RE
 
7329
.TP 8
 
7330
\fB\-C\fP \fIcommand\fP
 
7331
\fIcommand\fP is executed in a subshell environment, and its output is
 
7332
used as the possible completions.
 
7333
.TP 8
 
7334
\fB\-F\fP \fIfunction\fP
 
7335
The shell function \fIfunction\fP is executed in the current shell
 
7336
environment.
 
7337
When the function is executed,
 
7338
the first argument (\fB$1\fP) is the name of the command whose arguments are
 
7339
being completed,
 
7340
the second argument (\fB$2\fP) is the word being completed,
 
7341
and the third argument (\fB$3\fP) is the word preceding the word being
 
7342
completed on the current command line.
 
7343
When it finishes, the possible completions are retrieved from the value
 
7344
of the
 
7345
.SM
 
7346
.B COMPREPLY
 
7347
array variable.
 
7348
.TP 8
 
7349
\fB\-G\fP \fIglobpat\fP
 
7350
The pathname expansion pattern \fIglobpat\fP is expanded to generate
 
7351
the possible completions.
 
7352
.TP 8
 
7353
\fB\-P\fP \fIprefix\fP
 
7354
\fIprefix\fP is added at the beginning of each possible completion
 
7355
after all other options have been applied.
 
7356
.TP 8
 
7357
\fB\-S\fP \fIsuffix\fP
 
7358
\fIsuffix\fP is appended to each possible completion
 
7359
after all other options have been applied.
 
7360
.TP 8
 
7361
\fB\-W\fP \fIwordlist\fP
 
7362
The \fIwordlist\fP is split using the characters in the
 
7363
.SM
 
7364
.B IFS
 
7365
special variable as delimiters, and each resultant word is expanded.
 
7366
The possible completions are the members of the resultant list which
 
7367
match the word being completed.
 
7368
.TP 8
 
7369
\fB\-X\fP \fIfilterpat\fP
 
7370
\fIfilterpat\fP is a pattern as used for pathname expansion.
 
7371
It is applied to the list of possible completions generated by the
 
7372
preceding options and arguments, and each completion matching
 
7373
\fIfilterpat\fP is removed from the list.
 
7374
A leading \fB!\fP in \fIfilterpat\fP negates the pattern; in this
 
7375
case, any completion not matching \fIfilterpat\fP is removed.
 
7376
.PD
 
7377
.PP
 
7378
The return value is true unless an invalid option is supplied, an option
 
7379
other than \fB\-p\fP or \fB\-r\fP is supplied without a \fIname\fP
 
7380
argument, an attempt is made to remove a completion specification for
 
7381
a \fIname\fP for which no specification exists, or
 
7382
an error occurs adding a completion specification.
 
7383
.RE
 
7384
.TP
 
7385
\fBcompopt\fP [\fB\-o\fP \fIoption\fP] [\fB\-DE\fP] [\fB+o\fP \fIoption\fP] [\fIname\fP]
 
7386
Modify completion options for each \fIname\fP according to the
 
7387
\fIoption\fPs, or for the
 
7388
currently-executing completion if no \fIname\fPs are supplied.
 
7389
If no \fIoption\fPs are given, display the completion options for each
 
7390
\fIname\fP or the current completion.
 
7391
The possible values of \fIoption\fP are those valid for the \fBcomplete\fP
 
7392
builtin described above.
 
7393
The \fB\-D\fP option indicates that the remaining options should
 
7394
apply to the ``default'' command completion; that is, completion attempted
 
7395
on a command for which no completion has previously been defined.
 
7396
The \fB\-E\fP option indicates that the remaining options should
 
7397
apply to ``empty'' command completion; that is, completion attempted on a
 
7398
blank line.
 
7399
.sp 1
 
7400
The return value is true unless an invalid option is supplied, an attempt
 
7401
is made to modify the options for a \fIname\fP for which no completion
 
7402
specification exists, or an output error occurs.
 
7403
.TP
 
7404
\fBcontinue\fP [\fIn\fP]
 
7405
Resume the next iteration of the enclosing
 
7406
.BR for ,
 
7407
.BR while ,
 
7408
.BR until ,
 
7409
or
 
7410
.B select
 
7411
loop.
 
7412
If
 
7413
.I n
 
7414
is specified, resume at the \fIn\fPth enclosing loop.
 
7415
.I n
 
7416
must be \(>= 1.  If
 
7417
.I n
 
7418
is greater than the number of enclosing loops, the last enclosing loop
 
7419
(the ``top-level'' loop) is resumed.
 
7420
The return value is 0 unless \fIn\fP is not greater than or equal to 1.
 
7421
.TP
 
7422
\fBdeclare\fP [\fB\-aAfFgilnrtux\fP] [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...]
 
7423
.PD 0
 
7424
.TP
 
7425
\fBtypeset\fP [\fB\-aAfFgilnrtux\fP] [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...]
 
7426
.PD
 
7427
Declare variables and/or give them attributes.
 
7428
If no \fIname\fPs are given then display the values of variables.
 
7429
The
 
7430
.B \-p
 
7431
option will display the attributes and values of each
 
7432
.IR name .
 
7433
When
 
7434
.B \-p
 
7435
is used with \fIname\fP arguments, additional options,
 
7436
other than \fB\-f\fP and \fB\-F\fP, are ignored.
 
7437
When
 
7438
.B \-p
 
7439
is supplied without \fIname\fP arguments, it will display the attributes
 
7440
and values of all variables having the attributes specified by the
 
7441
additional options.
 
7442
If no other options are supplied with \fB\-p\fP, \fBdeclare\fP will display
 
7443
the attributes and values of all shell variables.  The \fB\-f\fP option
 
7444
will restrict the display to shell functions.
 
7445
The
 
7446
.B \-F
 
7447
option inhibits the display of function definitions; only the
 
7448
function name and attributes are printed.
 
7449
If the \fBextdebug\fP shell option is enabled using \fBshopt\fP,
 
7450
the source file name and line number where the function is defined
 
7451
are displayed as well.  The
 
7452
.B \-F
 
7453
option implies
 
7454
.BR \-f .
 
7455
The
 
7456
.B \-g
 
7457
option forces variables to be created or modified at the global scope,
 
7458
even when \fBdeclare\fP is executed in a shell function.
 
7459
It is ignored in all other cases.
 
7460
The following options can
 
7461
be used to restrict output to variables with the specified attribute or
 
7462
to give variables attributes:
 
7463
.RS
 
7464
.PD 0
 
7465
.TP
 
7466
.B \-a
 
7467
Each \fIname\fP is an indexed array variable (see
 
7468
.B Arrays
 
7469
above).
 
7470
.TP
 
7471
.B \-A
 
7472
Each \fIname\fP is an associative array variable (see
 
7473
.B Arrays
 
7474
above).
 
7475
.TP
 
7476
.B \-f
 
7477
Use function names only.
 
7478
.TP
 
7479
.B \-i
 
7480
The variable is treated as an integer; arithmetic evaluation (see
 
7481
.SM
 
7482
.B "ARITHMETIC EVALUATION"
 
7483
above) is performed when the variable is assigned a value.
 
7484
.TP
 
7485
.B \-l
 
7486
When the variable is assigned a value, all upper-case characters are
 
7487
converted to lower-case.
 
7488
The upper-case attribute is disabled.
 
7489
.TP
 
7490
.B \-n
 
7491
Give each \fIname\fP the \fInameref\fP attribute, making
 
7492
it a name reference to another variable.
 
7493
That other variable is defined by the value of \fIname\fP.
 
7494
All references and assignments to \fIname\fP, except for changing the
 
7495
\fB\-n\fP attribute itself, are performed on the variable referenced by
 
7496
\fIname\fP's value.
 
7497
The \fB\-n\fP attribute cannot be applied to array variables.
 
7498
.TP
 
7499
.B \-r
 
7500
Make \fIname\fPs readonly.  These names cannot then be assigned values
 
7501
by subsequent assignment statements or unset.
 
7502
.TP
 
7503
.B \-t
 
7504
Give each \fIname\fP the \fItrace\fP attribute.
 
7505
Traced functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps from
 
7506
the calling shell.
 
7507
The trace attribute has no special meaning for variables.
 
7508
.TP
 
7509
.B \-u
 
7510
When the variable is assigned a value, all lower-case characters are
 
7511
converted to upper-case.
 
7512
The lower-case attribute is disabled.
 
7513
.TP
 
7514
.B \-x
 
7515
Mark \fIname\fPs for export to subsequent commands via the environment.
 
7516
.PD
 
7517
.PP
 
7518
Using `+' instead of `\-'
 
7519
turns off the attribute instead,
 
7520
with the exceptions that \fB+a\fP
 
7521
may not be used to destroy an array variable and \fB+r\fP will not
 
7522
remove the readonly attribute.
 
7523
When used in a function,
 
7524
.B declare
 
7525
and
 
7526
.B typeset
 
7527
make each
 
7528
\fIname\fP local, as with the
 
7529
.B local
 
7530
command,
 
7531
unless the \fB\-g\fP option is supplied.
 
7532
If a variable name is followed by =\fIvalue\fP, the value of
 
7533
the variable is set to \fIvalue\fP.
 
7534
When using \fB\-a\fP or \fB\-A\fP and the compound assignment syntax to
 
7535
create array variables, additional attributes do not take effect until
 
7536
subsequent assignments.
 
7537
The return value is 0 unless an invalid option is encountered,
 
7538
an attempt is made to define a function using
 
7539
.if n ``\-f foo=bar'',
 
7540
.if t \f(CW\-f foo=bar\fP,
 
7541
an attempt is made to assign a value to a readonly variable,
 
7542
an attempt is made to assign a value to an array variable without
 
7543
using the compound assignment syntax (see
 
7544
.B Arrays
 
7545
above), one of the \fInames\fP is not a valid shell variable name,
 
7546
an attempt is made to turn off readonly status for a readonly variable,
 
7547
an attempt is made to turn off array status for an array variable,
 
7548
or an attempt is made to display a non-existent function with \fB\-f\fP.
 
7549
.RE
 
7550
.TP
 
7551
.B dirs [\fB\-clpv\fP] [+\fIn\fP] [\-\fIn\fP]
 
7552
Without options, displays the list of currently remembered directories.
 
7553
The default display is on a single line with directory names separated
 
7554
by spaces.
 
7555
Directories are added to the list with the 
 
7556
.B pushd
 
7557
command; the
 
7558
.B popd
 
7559
command removes entries from the list.
 
7560
.RS
 
7561
.PD 0
 
7562
.TP
 
7563
.B \-c
 
7564
Clears the directory stack by deleting all of the entries.
 
7565
.TP
 
7566
.B \-l
 
7567
Produces a listing using full pathnames;
 
7568
the default listing format uses a tilde to denote the home directory.
 
7569
.TP
 
7570
.B \-p
 
7571
Print the directory stack with one entry per line.
 
7572
.TP
 
7573
.B \-v
 
7574
Print the directory stack with one entry per line,
 
7575
prefixing each entry with its index in the stack.
 
7576
.TP
 
7577
\fB+\fP\fIn\fP
 
7578
Displays the \fIn\fPth entry counting from the left of the list
 
7579
shown by
 
7580
.B dirs
 
7581
when invoked without options, starting with zero.
 
7582
.TP
 
7583
\fB\-\fP\fIn\fP
 
7584
Displays the \fIn\fPth entry counting from the right of the list
 
7585
shown by
 
7586
.B dirs
 
7587
when invoked without options, starting with zero.
 
7588
.PD
 
7589
.PP
 
7590
The return value is 0 unless an
 
7591
invalid option is supplied or \fIn\fP indexes beyond the end
 
7592
of the directory stack.
 
7593
.RE
 
7594
.TP
 
7595
\fBdisown\fP [\fB\-ar\fP] [\fB\-h\fP] [\fIjobspec\fP ...]
 
7596
Without options, remove each
 
7597
.I jobspec
 
7598
from the table of active jobs.
 
7599
If
 
7600
.I jobspec
 
7601
is not present, and neither the \fB\-a\fP nor the \fB\-r\fP option
 
7602
is supplied, the \fIcurrent job\fP is used.
 
7603
If the \fB\-h\fP option is given, each
 
7604
.I jobspec
 
7605
is not removed from the table, but is marked so that
 
7606
.SM
 
7607
.B SIGHUP
 
7608
is not sent to the job if the shell receives a
 
7609
.SM
 
7610
.BR SIGHUP .
 
7611
If no
 
7612
.I jobspec
 
7613
is supplied, the
 
7614
.B \-a
 
7615
option means to remove or mark all jobs; the
 
7616
.B \-r
 
7617
option without a
 
7618
.I jobspec
 
7619
argument restricts operation to running jobs.
 
7620
The return value is 0 unless a
 
7621
.I jobspec
 
7622
does not specify a valid job.
 
7623
.TP
 
7624
\fBecho\fP [\fB\-neE\fP] [\fIarg\fP ...]
 
7625
Output the \fIarg\fPs, separated by spaces, followed by a newline.
 
7626
The return status is 0 unless a write error occurs.
 
7627
If \fB\-n\fP is specified, the trailing newline is
 
7628
suppressed.  If the \fB\-e\fP option is given, interpretation of
 
7629
the following backslash-escaped characters is enabled.  The
 
7630
.B \-E
 
7631
option disables the interpretation of these escape characters,
 
7632
even on systems where they are interpreted by default.
 
7633
The \fBxpg_echo\fP shell option may be used to
 
7634
dynamically determine whether or not \fBecho\fP expands these
 
7635
escape characters by default.
 
7636
.B echo
 
7637
does not interpret \fB\-\-\fP to mean the end of options.
 
7638
.B echo
 
7639
interprets the following escape sequences:
 
7640
.RS
 
7641
.PD 0
 
7642
.TP
 
7643
.B \ea
 
7644
alert (bell)
 
7645
.TP
 
7646
.B \eb
 
7647
backspace
 
7648
.TP
 
7649
.B \ec
 
7650
suppress further output
 
7651
.TP
 
7652
.B \ee
 
7653
.TP
 
7654
.B \eE
 
7655
an escape character
 
7656
.TP
 
7657
.B \ef
 
7658
form feed
 
7659
.TP
 
7660
.B \en
 
7661
new line
 
7662
.TP
 
7663
.B \er
 
7664
carriage return
 
7665
.TP
 
7666
.B \et
 
7667
horizontal tab
 
7668
.TP
 
7669
.B \ev
 
7670
vertical tab
 
7671
.TP
 
7672
.B \e\e
 
7673
backslash
 
7674
.TP
 
7675
.B \e0\fInnn\fP
 
7676
the eight-bit character whose value is the octal value \fInnn\fP
 
7677
(zero to three octal digits)
 
7678
.TP
 
7679
.B \ex\fIHH\fP
 
7680
the eight-bit character whose value is the hexadecimal value \fIHH\fP
 
7681
(one or two hex digits)
 
7682
.TP
 
7683
.B \eu\fIHHHH\fP
 
7684
the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
 
7685
\fIHHHH\fP (one to four hex digits)
 
7686
.TP
 
7687
.B \eU\fIHHHHHHHH\fP
 
7688
the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
 
7689
\fIHHHHHHHH\fP (one to eight hex digits)
 
7690
.PD
 
7691
.RE
 
7692
.TP
 
7693
\fBenable\fP [\fB\-a\fP] [\fB\-dnps\fP] [\fB\-f\fP \fIfilename\fP] [\fIname\fP ...]
 
7694
Enable and disable builtin shell commands.
 
7695
Disabling a builtin allows a disk command which has the same name
 
7696
as a shell builtin to be executed without specifying a full pathname,
 
7697
even though the shell normally searches for builtins before disk commands.
 
7698
If \fB\-n\fP is used, each \fIname\fP
 
7699
is disabled; otherwise,
 
7700
\fInames\fP are enabled.  For example, to use the
 
7701
.B test
 
7702
binary found via the
 
7703
.SM
 
7704
.B PATH
 
7705
instead of the shell builtin version, run
 
7706
.if t \f(CWenable -n test\fP.
 
7707
.if n ``enable -n test''.
 
7708
The
 
7709
.B \-f
 
7710
option means to load the new builtin command
 
7711
.I name
 
7712
from shared object
 
7713
.IR filename ,
 
7714
on systems that support dynamic loading.  The
 
7715
.B \-d
 
7716
option will delete a builtin previously loaded with
 
7717
.BR \-f .
 
7718
If no \fIname\fP arguments are given, or if the
 
7719
.B \-p
 
7720
option is supplied, a list of shell builtins is printed.
 
7721
With no other option arguments, the list consists of all enabled
 
7722
shell builtins.
 
7723
If \fB\-n\fP is supplied, only disabled builtins are printed.
 
7724
If \fB\-a\fP is supplied, the list printed includes all builtins, with an
 
7725
indication of whether or not each is enabled.
 
7726
If \fB\-s\fP is supplied, the output is restricted to the POSIX
 
7727
\fIspecial\fP builtins.
 
7728
The return value is 0 unless a
 
7729
.I name
 
7730
is not a shell builtin or there is an error loading a new builtin
 
7731
from a shared object.
 
7732
.TP
 
7733
\fBeval\fP [\fIarg\fP ...]
 
7734
The \fIarg\fPs are read and concatenated together into a single
 
7735
command.  This command is then read and executed by the shell, and
 
7736
its exit status is returned as the value of
 
7737
.BR eval .
 
7738
If there are no
 
7739
.IR args ,
 
7740
or only null arguments,
 
7741
.B eval
 
7742
returns 0.
 
7743
.TP
 
7744
\fBexec\fP [\fB\-cl\fP] [\fB\-a\fP \fIname\fP] [\fIcommand\fP [\fIarguments\fP]]
 
7745
If
 
7746
.I command
 
7747
is specified, it replaces the shell.
 
7748
No new process is created.  The
 
7749
.I arguments
 
7750
become the arguments to \fIcommand\fP.
 
7751
If the
 
7752
.B \-l
 
7753
option is supplied,
 
7754
the shell places a dash at the beginning of the zeroth argument passed to 
 
7755
.IR command .
 
7756
This is what
 
7757
.IR login (1)
 
7758
does.  The
 
7759
.B \-c
 
7760
option causes
 
7761
.I command
 
7762
to be executed with an empty environment.  If
 
7763
.B \-a
 
7764
is supplied, the shell passes
 
7765
.I name
 
7766
as the zeroth argument to the executed command.
 
7767
If
 
7768
.I command
 
7769
cannot be executed for some reason, a non-interactive shell exits,
 
7770
unless the
 
7771
.B execfail
 
7772
shell option
 
7773
is enabled.  In that case, it returns failure.
 
7774
An interactive shell returns failure if the file cannot be executed.
 
7775
If
 
7776
.I command
 
7777
is not specified, any redirections take effect in the current shell,
 
7778
and the return status is 0.  If there is a redirection error, the
 
7779
return status is 1.
 
7780
.TP
 
7781
\fBexit\fP [\fIn\fP]
 
7782
Cause the shell to exit
 
7783
with a status of \fIn\fP.  If
 
7784
.I n
 
7785
is omitted, the exit status
 
7786
is that of the last command executed.
 
7787
A trap on
 
7788
.SM
 
7789
.B EXIT
 
7790
is executed before the shell terminates.
 
7791
.TP
 
7792
\fBexport\fP [\fB\-fn\fP\^] [\fIname\fP[=\fIword\fP]] ...
 
7793
.PD 0
 
7794
.TP
 
7795
.B export \-p
 
7796
.PD
 
7797
The supplied
 
7798
.I names
 
7799
are marked for automatic export to the environment of
 
7800
subsequently executed commands.  If the 
 
7801
.B \-f
 
7802
option is given,
 
7803
the 
 
7804
.I names
 
7805
refer to functions.
 
7806
If no
 
7807
.I names
 
7808
are given, or if the
 
7809
.B \-p
 
7810
option is supplied, a list
 
7811
of names of all exported variables is printed.
 
7812
The
 
7813
.B \-n
 
7814
option causes the export property to be removed from each
 
7815
\fIname\fP.
 
7816
If a variable name is followed by =\fIword\fP, the value of
 
7817
the variable is set to \fIword\fP.
 
7818
.B export
 
7819
returns an exit status of 0 unless an invalid option is
 
7820
encountered,
 
7821
one of the \fInames\fP is not a valid shell variable name, or
 
7822
.B \-f
 
7823
is supplied with a
 
7824
.I name
 
7825
that is not a function.
 
7826
.TP
 
7827
\fBfc\fP [\fB\-e\fP \fIename\fP] [\fB\-lnr\fP] [\fIfirst\fP] [\fIlast\fP]
 
7828
.PD 0
 
7829
.TP
 
7830
\fBfc\fP \fB\-s\fP [\fIpat\fP=\fIrep\fP] [\fIcmd\fP]
 
7831
.PD
 
7832
The first form selects a range of commands from
 
7833
.I first
 
7834
to
 
7835
.I last
 
7836
from the history list and displays or edits and re-executes them.
 
7837
.I First
 
7838
and
 
7839
.I last
 
7840
may be specified as a string (to locate the last command beginning
 
7841
with that string) or as a number (an index into the history list,
 
7842
where a negative number is used as an offset from the current
 
7843
command number).  If 
 
7844
.I last
 
7845
is not specified it is set to
 
7846
the current command for listing (so that
 
7847
.if n ``fc \-l \-10''
 
7848
.if t \f(CWfc \-l \-10\fP
 
7849
prints the last 10 commands) and to
 
7850
.I first
 
7851
otherwise.
 
7852
If
 
7853
.I first
 
7854
is not specified it is set to the previous
 
7855
command for editing and \-16 for listing.
 
7856
.sp 1
 
7857
The
 
7858
.B \-n
 
7859
option suppresses
 
7860
the command numbers when listing.  The
 
7861
.B \-r
 
7862
option reverses the order of
 
7863
the commands.  If the
 
7864
.B \-l
 
7865
option is given,
 
7866
the commands are listed on
 
7867
standard output.  Otherwise, the editor given by
 
7868
.I ename
 
7869
is invoked
 
7870
on a file containing those commands.  If
 
7871
.I ename
 
7872
is not given, the
 
7873
value of the
 
7874
.SM
 
7875
.B FCEDIT
 
7876
variable is used, and
 
7877
the value of
 
7878
.SM
 
7879
.B EDITOR
 
7880
if
 
7881
.SM
 
7882
.B FCEDIT
 
7883
is not set.  If neither variable is set,
 
7884
.FN vi
 
7885
is used.  When editing is complete, the edited commands are
 
7886
echoed and executed.
 
7887
.sp 1
 
7888
In the second form, \fIcommand\fP is re-executed after each instance
 
7889
of \fIpat\fP is replaced by \fIrep\fP.
 
7890
\fICommand\fP is intepreted the same as \fIfirst\fP above.
 
7891
A useful alias to use with this is
 
7892
.if n ``r="fc -s"'',
 
7893
.if t \f(CWr='fc \-s'\fP,
 
7894
so that typing
 
7895
.if n ``r cc''
 
7896
.if t \f(CWr cc\fP
 
7897
runs the last command beginning with
 
7898
.if n ``cc''
 
7899
.if t \f(CWcc\fP
 
7900
and typing
 
7901
.if n ``r''
 
7902
.if t \f(CWr\fP
 
7903
re-executes the last command.
 
7904
.sp 1
 
7905
If the first form is used, the return value is 0 unless an invalid
 
7906
option is encountered or
 
7907
.I first
 
7908
or
 
7909
.I last
 
7910
specify history lines out of range.
 
7911
If the
 
7912
.B \-e
 
7913
option is supplied, the return value is the value of the last
 
7914
command executed or failure if an error occurs with the temporary
 
7915
file of commands.  If the second form is used, the return status
 
7916
is that of the command re-executed, unless
 
7917
.I cmd
 
7918
does not specify a valid history line, in which case
 
7919
.B fc
 
7920
returns failure.
 
7921
.TP
 
7922
\fBfg\fP [\fIjobspec\fP]
 
7923
Resume
 
7924
.I jobspec
 
7925
in the foreground, and make it the current job.
 
7926
If
 
7927
.I jobspec
 
7928
is not present, the shell's notion of the \fIcurrent job\fP is used.
 
7929
The return value is that of the command placed into the foreground,
 
7930
or failure if run when job control is disabled or, when run with
 
7931
job control enabled, if
 
7932
.I jobspec
 
7933
does not specify a valid job or
 
7934
.I jobspec
 
7935
specifies a job that was started without job control.
 
7936
.TP
 
7937
\fBgetopts\fP \fIoptstring\fP \fIname\fP [\fIargs\fP]
 
7938
.B getopts
 
7939
is used by shell procedures to parse positional parameters.
 
7940
.I optstring
 
7941
contains the option characters to be recognized; if a character
 
7942
is followed by a colon, the option is expected to have an
 
7943
argument, which should be separated from it by white space.
 
7944
The colon and question mark characters may not be used as
 
7945
option characters.
 
7946
Each time it is invoked,
 
7947
.B getopts
 
7948
places the next option in the shell variable
 
7949
.IR name ,
 
7950
initializing
 
7951
.I name
 
7952
if it does not exist,
 
7953
and the index of the next argument to be processed into the
 
7954
variable
 
7955
.SM
 
7956
.BR OPTIND .
 
7957
.SM
 
7958
.B OPTIND
 
7959
is initialized to 1 each time the shell or a shell script
 
7960
is invoked.  When an option requires an argument,
 
7961
.B getopts
 
7962
places that argument into the variable
 
7963
.SM
 
7964
.BR OPTARG .
 
7965
The shell does not reset
 
7966
.SM
 
7967
.B OPTIND
 
7968
automatically; it must be manually reset between multiple
 
7969
calls to
 
7970
.B getopts
 
7971
within the same shell invocation if a new set of parameters
 
7972
is to be used.
 
7973
.sp 1
 
7974
When the end of options is encountered, \fBgetopts\fP exits with a
 
7975
return value greater than zero.
 
7976
.SM
 
7977
.B OPTIND
 
7978
is set to the index of the first non-option argument,
 
7979
and \fIname\fP is set to ?.
 
7980
.sp 1
 
7981
.B getopts
 
7982
normally parses the positional parameters, but if more arguments are
 
7983
given in
 
7984
.IR args ,
 
7985
.B getopts
 
7986
parses those instead.
 
7987
.sp 1
 
7988
.B getopts
 
7989
can report errors in two ways.  If the first character of
 
7990
.I optstring
 
7991
is a colon,
 
7992
.I silent
 
7993
error reporting is used.  In normal operation, diagnostic messages
 
7994
are printed when invalid options or missing option arguments are
 
7995
encountered.
 
7996
If the variable
 
7997
.SM
 
7998
.B OPTERR
 
7999
is set to 0, no error messages will be displayed, even if the first
 
8000
character of 
 
8001
.I optstring
 
8002
is not a colon.
 
8003
.sp 1
 
8004
If an invalid option is seen,
 
8005
.B getopts
 
8006
places ? into
 
8007
.I name
 
8008
and, if not silent,
 
8009
prints an error message and unsets
 
8010
.SM
 
8011
.BR OPTARG .
 
8012
If
 
8013
.B getopts
 
8014
is silent,
 
8015
the option character found is placed in
 
8016
.SM
 
8017
.B OPTARG
 
8018
and no diagnostic message is printed.
 
8019
.sp 1
 
8020
If a required argument is not found, and
 
8021
.B getopts
 
8022
is not silent,
 
8023
a question mark (\^\fB?\fP\^) is placed in
 
8024
.IR name ,
 
8025
.SM
 
8026
.B OPTARG
 
8027
is unset, and a diagnostic message is printed.
 
8028
If
 
8029
.B getopts
 
8030
is silent, then a colon (\^\fB:\fP\^) is placed in
 
8031
.I name
 
8032
and
 
8033
.SM
 
8034
.B OPTARG
 
8035
is set to the option character found.
 
8036
.sp 1
 
8037
.B getopts
 
8038
returns true if an option, specified or unspecified, is found.
 
8039
It returns false if the end of options is encountered or an
 
8040
error occurs.
 
8041
.TP
 
8042
\fBhash\fP [\fB\-lr\fP] [\fB\-p\fP \fIfilename\fP] [\fB\-dt\fP] [\fIname\fP]
 
8043
Each time \fBhash\fP is invoked,
 
8044
the full pathname of the command 
 
8045
.I name
 
8046
is determined by searching
 
8047
the directories in
 
8048
.B $PATH
 
8049
and remembered.  Any previously-remembered pathname is discarded.
 
8050
If the
 
8051
.B \-p
 
8052
option is supplied, no path search is performed, and
 
8053
.I filename
 
8054
is used as the full filename of the command.
 
8055
The
 
8056
.B \-r
 
8057
option causes the shell to forget all
 
8058
remembered locations.
 
8059
The
 
8060
.B \-d
 
8061
option causes the shell to forget the remembered location of each \fIname\fP.
 
8062
If the
 
8063
.B \-t
 
8064
option is supplied, the full pathname to which each \fIname\fP corresponds
 
8065
is printed.  If multiple \fIname\fP arguments are supplied with \fB\-t\fP,
 
8066
the \fIname\fP is printed before the hashed full pathname.
 
8067
The
 
8068
.B \-l
 
8069
option causes output to be displayed in a format that may be reused as input.
 
8070
If no arguments are given, or if only \fB\-l\fP is supplied,
 
8071
information about remembered commands is printed.
 
8072
The return status is true unless a
 
8073
.I name
 
8074
is not found or an invalid option is supplied.
 
8075
.TP
 
8076
\fBhelp\fP [\fB\-dms\fP] [\fIpattern\fP]
 
8077
Display helpful information about builtin commands.  If
 
8078
.I pattern
 
8079
is specified,
 
8080
.B help
 
8081
gives detailed help on all commands matching
 
8082
.IR pattern ;
 
8083
otherwise help for all the builtins and shell control structures
 
8084
is printed.
 
8085
.RS
 
8086
.PD 0
 
8087
.TP
 
8088
.B \-d
 
8089
Display a short description of each \fIpattern\fP
 
8090
.TP
 
8091
.B \-m
 
8092
Display the description of each \fIpattern\fP in a manpage-like format
 
8093
.TP
 
8094
.B \-s
 
8095
Display only a short usage synopsis for each \fIpattern\fP
 
8096
.PD
 
8097
.PP
 
8098
The return status is 0 unless no command matches
 
8099
.IR pattern .
 
8100
.RE
 
8101
.TP
 
8102
\fBhistory [\fIn\fP]
 
8103
.PD 0
 
8104
.TP
 
8105
\fBhistory\fP \fB\-c\fP
 
8106
.TP
 
8107
\fBhistory \-d\fP \fIoffset\fP
 
8108
.TP
 
8109
\fBhistory\fP \fB\-anrw\fP [\fIfilename\fP]
 
8110
.TP
 
8111
\fBhistory\fP \fB\-p\fP \fIarg\fP [\fIarg ...\fP]
 
8112
.TP
 
8113
\fBhistory\fP \fB\-s\fP \fIarg\fP [\fIarg ...\fP]
 
8114
.PD
 
8115
With no options, display the command
 
8116
history list with line numbers.  Lines listed
 
8117
with a 
 
8118
.B *
 
8119
have been modified.  An argument of
 
8120
.I n
 
8121
lists only the last
 
8122
.I n
 
8123
lines.
 
8124
If the shell variable
 
8125
.SM
 
8126
.B HISTTIMEFORMAT
 
8127
is set and not null,
 
8128
it is used as a format string for \fIstrftime\fP(3) to display
 
8129
the time stamp associated with each displayed history entry.
 
8130
No intervening blank is printed between the formatted time stamp
 
8131
and the history line.
 
8132
If \fIfilename\fP is supplied, it is used as the
 
8133
name of the history file; if not, the value of
 
8134
.SM
 
8135
.B HISTFILE
 
8136
is used.  Options, if supplied, have the following meanings:
 
8137
.RS
 
8138
.PD 0
 
8139
.TP
 
8140
.B \-c
 
8141
Clear the history list by deleting all the entries.
 
8142
.TP
 
8143
\fB\-d\fP \fIoffset\fP
 
8144
Delete the history entry at position \fIoffset\fP.
 
8145
.TP
 
8146
.B \-a
 
8147
Append the ``new'' history lines (history lines entered since the
 
8148
beginning of the current \fBbash\fP session) to the history file.
 
8149
.TP
 
8150
.B \-n
 
8151
Read the history lines not already read from the history
 
8152
file into the current history list.  These are lines
 
8153
appended to the history file since the beginning of the
 
8154
current \fBbash\fP session.
 
8155
.TP
 
8156
.B \-r
 
8157
Read the contents of the history file
 
8158
and append them to the current history list.
 
8159
.TP
 
8160
.B \-w
 
8161
Write the current history list to the history file, overwriting the
 
8162
history file's contents.
 
8163
.TP
 
8164
.B \-p
 
8165
Perform history substitution on the following \fIargs\fP and display
 
8166
the result on the standard output.
 
8167
Does not store the results in the history list.
 
8168
Each \fIarg\fP must be quoted to disable normal history expansion.
 
8169
.TP
 
8170
.B \-s
 
8171
Store the
 
8172
.I args
 
8173
in the history list as a single entry.  The last command in the
 
8174
history list is removed before the
 
8175
.I args
 
8176
are added.
 
8177
.PD
 
8178
.PP
 
8179
If the
 
8180
.SM
 
8181
.B HISTTIMEFORMAT
 
8182
variable is set, the time stamp information
 
8183
associated with each history entry is written to the history file,
 
8184
marked with the history comment character.
 
8185
When the history file is read, lines beginning with the history
 
8186
comment character followed immediately by a digit are interpreted
 
8187
as timestamps for the previous history line.
 
8188
The return value is 0 unless an invalid option is encountered, an
 
8189
error occurs while reading or writing the history file, an invalid
 
8190
\fIoffset\fP is supplied as an argument to \fB\-d\fP, or the
 
8191
history expansion supplied as an argument to \fB\-p\fP fails.
 
8192
.RE
 
8193
.TP
 
8194
\fBjobs\fP [\fB\-lnprs\fP] [ \fIjobspec\fP ... ]
 
8195
.PD 0
 
8196
.TP
 
8197
\fBjobs\fP \fB\-x\fP \fIcommand\fP [ \fIargs\fP ... ]
 
8198
.PD
 
8199
The first form lists the active jobs.  The options have the following
 
8200
meanings:
 
8201
.RS
 
8202
.PD 0
 
8203
.TP
 
8204
.B \-l
 
8205
List process IDs
 
8206
in addition to the normal information.
 
8207
.TP
 
8208
.B \-n
 
8209
Display information only about jobs that have changed status since
 
8210
the user was last notified of their status.
 
8211
.TP
 
8212
.B \-p
 
8213
List only the process ID of the job's process group
 
8214
leader.
 
8215
.TP
 
8216
.B \-r
 
8217
Display only running jobs.
 
8218
.TP
 
8219
.B \-s
 
8220
Display only stopped jobs.
 
8221
.PD
 
8222
.PP
 
8223
If
 
8224
.I jobspec
 
8225
is given, output is restricted to information about that job.
 
8226
The return status is 0 unless an invalid option is encountered
 
8227
or an invalid
 
8228
.I jobspec
 
8229
is supplied.
 
8230
.PP
 
8231
If the
 
8232
.B \-x
 
8233
option is supplied,
 
8234
.B jobs
 
8235
replaces any
 
8236
.I jobspec
 
8237
found in
 
8238
.I command
 
8239
or
 
8240
.I args
 
8241
with the corresponding process group ID, and executes
 
8242
.I command
 
8243
passing it
 
8244
.IR args ,
 
8245
returning its exit status.
 
8246
.RE
 
8247
.TP
 
8248
\fBkill\fP [\fB\-s\fP \fIsigspec\fP | \fB\-n\fP \fIsignum\fP | \fB\-\fP\fIsigspec\fP] [\fIpid\fP | \fIjobspec\fP] ...
 
8249
.PD 0
 
8250
.TP
 
8251
\fBkill\fP \fB\-l\fP [\fIsigspec\fP | \fIexit_status\fP]
 
8252
.PD
 
8253
Send the signal named by
 
8254
.I sigspec
 
8255
or
 
8256
.I signum
 
8257
to the processes named by
 
8258
.I pid
 
8259
or
 
8260
.IR jobspec .
 
8261
.I sigspec
 
8262
is either a case-insensitive signal name such as
 
8263
.SM
 
8264
.B SIGKILL
 
8265
(with or without the
 
8266
.SM
 
8267
.B SIG
 
8268
prefix) or a signal number;
 
8269
.I signum
 
8270
is a signal number.
 
8271
If
 
8272
.I sigspec
 
8273
is not present, then
 
8274
.SM
 
8275
.B SIGTERM
 
8276
is assumed.
 
8277
An argument of
 
8278
.B \-l
 
8279
lists the signal names.
 
8280
If any arguments are supplied when
 
8281
.B \-l
 
8282
is given, the names of the signals corresponding to the arguments are
 
8283
listed, and the return status is 0.
 
8284
The \fIexit_status\fP argument to
 
8285
.B \-l
 
8286
is a number specifying either a signal number or the exit status of
 
8287
a process terminated by a signal.
 
8288
.B kill
 
8289
returns true if at least one signal was successfully sent, or false
 
8290
if an error occurs or an invalid option is encountered.
 
8291
.TP
 
8292
\fBlet\fP \fIarg\fP [\fIarg\fP ...]
 
8293
Each
 
8294
.I arg
 
8295
is an arithmetic expression to be evaluated (see
 
8296
.SM
 
8297
.B "ARITHMETIC EVALUATION"
 
8298
above).
 
8299
If the last
 
8300
.I arg
 
8301
evaluates to 0,
 
8302
.B let
 
8303
returns 1; 0 is returned otherwise.
 
8304
.TP
 
8305
\fBlocal\fP [\fIoption\fP] [\fIname\fP[=\fIvalue\fP] ...]
 
8306
For each argument, a local variable named
 
8307
.I name 
 
8308
is created, and assigned
 
8309
.IR value .
 
8310
The \fIoption\fP can be any of the options accepted by \fBdeclare\fP.
 
8311
When
 
8312
.B local
 
8313
is used within a function, it causes the variable
 
8314
.I name
 
8315
to have a visible scope restricted to that function and its children.
 
8316
With no operands,
 
8317
.B local
 
8318
writes a list of local variables to the standard output.  It is
 
8319
an error to use
 
8320
.B local
 
8321
when not within a function.  The return status is 0 unless
 
8322
.B local
 
8323
is used outside a function, an invalid
 
8324
.I name
 
8325
is supplied, or
 
8326
\fIname\fP is a readonly variable.
 
8327
.TP
 
8328
.B logout
 
8329
Exit a login shell.
 
8330
.TP
 
8331
\fBmapfile\fP [\fB\-n\fP \fIcount\fP] [\fB\-O\fP \fIorigin\fP] [\fB\-s\fP \fIcount\fP] [\fB\-t\fP] [\fB\-u\fP \fIfd\fP] [\fB\-C\fP \fIcallback\fP] [\fB\-c\fP \fIquantum\fP] [\fIarray\fP]
 
8332
.PD 0
 
8333
.TP
 
8334
\fBreadarray\fP [\fB\-n\fP \fIcount\fP] [\fB\-O\fP \fIorigin\fP] [\fB\-s\fP \fIcount\fP] [\fB\-t\fP] [\fB\-u\fP \fIfd\fP] [\fB\-C\fP \fIcallback\fP] [\fB\-c\fP \fIquantum\fP] [\fIarray\fP]
 
8335
.PD
 
8336
Read lines from the standard input into the indexed array variable
 
8337
.IR array ,
 
8338
or from file descriptor 
 
8339
.IR fd
 
8340
if the 
 
8341
.B \-u
 
8342
option is supplied.
 
8343
The variable
 
8344
.SM
 
8345
.B MAPFILE
 
8346
is the default \fIarray\fP.
 
8347
Options, if supplied, have the following meanings:
 
8348
.RS
 
8349
.PD 0
 
8350
.TP
 
8351
.B \-n
 
8352
Copy at most
 
8353
.I count
 
8354
lines.  If \fIcount\fP is 0, all lines are copied.
 
8355
.TP
 
8356
.B \-O
 
8357
Begin assigning to
 
8358
.I array
 
8359
at index
 
8360
.IR origin .
 
8361
The default index is 0.
 
8362
.TP
 
8363
.B \-s
 
8364
Discard the first \fIcount\fP lines read.
 
8365
.TP
 
8366
.B \-t
 
8367
Remove a trailing newline from each line read.
 
8368
.TP
 
8369
.B \-u
 
8370
Read lines from file descriptor \fIfd\fP instead of the standard input.
 
8371
.TP
 
8372
.B \-C
 
8373
Evaluate
 
8374
.I callback
 
8375
each time \fIquantum\fP lines are read.  The \fB\-c\fP option specifies
 
8376
.IR quantum .
 
8377
.TP
 
8378
.B \-c
 
8379
Specify the number of lines read between each call to
 
8380
.IR callback .
 
8381
.PD
 
8382
.PP
 
8383
If
 
8384
.B \-C
 
8385
is specified without 
 
8386
.BR \-c ,
 
8387
the default quantum is 5000.
 
8388
When \fIcallback\fP is evaluated, it is supplied the index of the next
 
8389
array element to be assigned and the line to be assigned to that element
 
8390
as additional arguments.
 
8391
\fIcallback\fP is evaluated after the line is read but before the 
 
8392
array element is assigned.
 
8393
.PP
 
8394
If not supplied with an explicit origin, \fBmapfile\fP will clear \fIarray\fP
 
8395
before assigning to it.
 
8396
.PP
 
8397
\fBmapfile\fP returns successfully unless an invalid option or option
 
8398
argument is supplied, \fIarray\fP is invalid or unassignable, or if
 
8399
\fIarray\fP is not an indexed array.
 
8400
.RE
 
8401
.TP
 
8402
\fBpopd\fP [\-\fBn\fP] [+\fIn\fP] [\-\fIn\fP]
 
8403
Removes entries from the directory stack.  With no arguments,
 
8404
removes the top directory from the stack, and performs a
 
8405
.B cd
 
8406
to the new top directory.
 
8407
Arguments, if supplied, have the following meanings:
 
8408
.RS
 
8409
.PD 0
 
8410
.TP
 
8411
.B \-n
 
8412
Suppresses the normal change of directory when removing directories
 
8413
from the stack, so that only the stack is manipulated.
 
8414
.TP
 
8415
\fB+\fP\fIn\fP
 
8416
Removes the \fIn\fPth entry counting from the left of the list
 
8417
shown by
 
8418
.BR dirs ,
 
8419
starting with zero.  For example:
 
8420
.if n ``popd +0''
 
8421
.if t \f(CWpopd +0\fP
 
8422
removes the first directory,
 
8423
.if n ``popd +1''
 
8424
.if t \f(CWpopd +1\fP
 
8425
the second.
 
8426
.TP
 
8427
\fB\-\fP\fIn\fP
 
8428
Removes the \fIn\fPth entry counting from the right of the list
 
8429
shown by
 
8430
.BR dirs ,
 
8431
starting with zero.  For example:
 
8432
.if n ``popd -0''
 
8433
.if t \f(CWpopd -0\fP
 
8434
removes the last directory,
 
8435
.if n ``popd -1''
 
8436
.if t \f(CWpopd -1\fP
 
8437
the next to last.
 
8438
.PD
 
8439
.PP
 
8440
If the
 
8441
.B popd
 
8442
command is successful, a 
 
8443
.B dirs
 
8444
is performed as well, and the return status is 0.
 
8445
.B popd
 
8446
returns false if an invalid option is encountered, the directory stack
 
8447
is empty, a non-existent directory stack entry is specified, or the
 
8448
directory change fails.
 
8449
.RE
 
8450
.TP
 
8451
\fBprintf\fP [\fB\-v\fP \fIvar\fP] \fIformat\fP [\fIarguments\fP]
 
8452
Write the formatted \fIarguments\fP to the standard output under the
 
8453
control of the \fIformat\fP.
 
8454
The \fB\-v\fP option causes the output to be assigned to the variable
 
8455
\fIvar\fP rather than being printed to the standard output.
 
8456
.sp 1
 
8457
The \fIformat\fP is a character string which contains three types of objects:
 
8458
plain characters, which are simply copied to standard output, character
 
8459
escape sequences, which are converted and copied to the standard output, and
 
8460
format specifications, each of which causes printing of the next successive
 
8461
\fIargument\fP.
 
8462
In addition to the standard \fIprintf\fP(1) format specifications,
 
8463
\fBprintf\fP interprets the following extensions:
 
8464
.RS
 
8465
.PD 0
 
8466
.TP
 
8467
.B %b
 
8468
causes
 
8469
\fBprintf\fP to expand backslash escape sequences in the corresponding
 
8470
\fIargument\fP (except that \fB\ec\fP terminates output, backslashes in
 
8471
\fB\e\(aq\fP, \fB\e"\fP, and \fB\e?\fP are not removed, and octal escapes
 
8472
beginning with \fB\e0\fP may contain up to four digits).
 
8473
.TP
 
8474
.B %q
 
8475
causes \fBprintf\fP to output the corresponding
 
8476
\fIargument\fP in a format that can be reused as shell input.
 
8477
.TP
 
8478
.B %(\fIdatefmt\fP)T
 
8479
causes \fBprintf\fP to output the date-time string resulting from using
 
8480
\fIdatefmt\fP as a format string for \fIstrftime\fP(3).
 
8481
The corresponding \fIargument\fP is an integer representing the number of
 
8482
seconds since the epoch.
 
8483
Two special argument values may be used: -1 represents the current
 
8484
time, and -2 represents the time the shell was invoked.
 
8485
If no argument is specified, conversion behaves as if -1 had been given.
 
8486
This is an exception to the usual \fBprintf\fP behavior.
 
8487
.PD
 
8488
.PP
 
8489
Arguments to non-string format specifiers are treated as C constants,
 
8490
except that a leading plus or minus sign is allowed, and if the leading
 
8491
character is a single or double quote, the value is the ASCII value of
 
8492
the following character.
 
8493
.PP
 
8494
The \fIformat\fP is reused as necessary to consume all of the \fIarguments\fP.
 
8495
If the \fIformat\fP requires more \fIarguments\fP than are supplied, the
 
8496
extra format specifications behave as if a zero value or null string, as
 
8497
appropriate, had been supplied.
 
8498
The return value is zero on success, non-zero on failure.
 
8499
.RE
 
8500
.TP
 
8501
\fBpushd\fP [\fB\-n\fP] [+\fIn\fP] [\-\fIn\fP]
 
8502
.PD 0
 
8503
.TP
 
8504
\fBpushd\fP [\fB\-n\fP] [\fIdir\fP]
 
8505
.PD
 
8506
Adds a directory to the top of the directory stack, or rotates
 
8507
the stack, making the new top of the stack the current working
 
8508
directory.  With no arguments, exchanges the top two directories
 
8509
and returns 0, unless the directory stack is empty.
 
8510
Arguments, if supplied, have the following meanings:
 
8511
.RS
 
8512
.PD 0
 
8513
.TP
 
8514
.B \-n
 
8515
Suppresses the normal change of directory when adding directories
 
8516
to the stack, so that only the stack is manipulated.
 
8517
.TP
 
8518
\fB+\fP\fIn\fP
 
8519
Rotates the stack so that the \fIn\fPth directory
 
8520
(counting from the left of the list shown by
 
8521
.BR dirs ,
 
8522
starting with zero)
 
8523
is at the top.
 
8524
.TP
 
8525
\fB\-\fP\fIn\fP
 
8526
Rotates the stack so that the \fIn\fPth directory
 
8527
(counting from the right of the list shown by
 
8528
.BR dirs ,
 
8529
starting with zero) is at the top.
 
8530
.TP
 
8531
.I dir
 
8532
Adds
 
8533
.I dir
 
8534
to the directory stack at the top, making it the
 
8535
new current working directory as if it had been supplied as the argument
 
8536
to the \fBcd\fP builtin.
 
8537
.PD
 
8538
.PP
 
8539
If the
 
8540
.B pushd
 
8541
command is successful, a 
 
8542
.B dirs
 
8543
is performed as well.
 
8544
If the first form is used,
 
8545
.B pushd
 
8546
returns 0 unless the cd to
 
8547
.I dir
 
8548
fails.  With the second form,
 
8549
.B pushd
 
8550
returns 0 unless the directory stack is empty,
 
8551
a non-existent directory stack element is specified,
 
8552
or the directory change to the specified new current directory
 
8553
fails.
 
8554
.RE
 
8555
.TP
 
8556
\fBpwd\fP [\fB\-LP\fP]
 
8557
Print the absolute pathname of the current working directory.
 
8558
The pathname printed contains no symbolic links if the
 
8559
.B \-P
 
8560
option is supplied or the 
 
8561
.B \-o physical
 
8562
option to the
 
8563
.B set
 
8564
builtin command is enabled.
 
8565
If the
 
8566
.B \-L
 
8567
option is used, the pathname printed may contain symbolic links.
 
8568
The return status is 0 unless an error occurs while
 
8569
reading the name of the current directory or an
 
8570
invalid option is supplied.
 
8571
.TP
 
8572
\fBread\fP [\fB\-ers\fP] [\fB\-a\fP \fIaname\fP] [\fB\-d\fP \fIdelim\fP] [\fB\-i\fP \fItext\fP] [\fB\-n\fP \fInchars\fP] [\fB\-N\fP \fInchars\fP] [\fB\-p\fP \fIprompt\fP] [\fB\-t\fP \fItimeout\fP] [\fB\-u\fP \fIfd\fP] [\fIname\fP ...]
 
8573
One line is read from the standard input, or from the file descriptor
 
8574
\fIfd\fP supplied as an argument to the \fB\-u\fP option, and the first word
 
8575
is assigned to the first
 
8576
.IR name ,
 
8577
the second word to the second
 
8578
.IR name ,
 
8579
and so on, with leftover words and their intervening separators assigned
 
8580
to the last
 
8581
.IR name .
 
8582
If there are fewer words read from the input stream than names,
 
8583
the remaining names are assigned empty values.
 
8584
The characters in 
 
8585
.SM
 
8586
.B IFS
 
8587
are used to split the line into words using the same rules the shell
 
8588
uses for expansion (described above under \fBWord Splitting\fP).
 
8589
The backslash character (\fB\e\fP) may be used to remove any special
 
8590
meaning for the next character read and for line continuation.
 
8591
Options, if supplied, have the following meanings:
 
8592
.RS
 
8593
.PD 0
 
8594
.TP
 
8595
.B \-a \fIaname\fP
 
8596
The words are assigned to sequential indices
 
8597
of the array variable
 
8598
.IR aname ,
 
8599
starting at 0.
 
8600
.I aname
 
8601
is unset before any new values are assigned.
 
8602
Other \fIname\fP arguments are ignored.
 
8603
.TP
 
8604
.B \-d \fIdelim\fP
 
8605
The first character of \fIdelim\fP is used to terminate the input line,
 
8606
rather than newline.
 
8607
.TP
 
8608
.B \-e
 
8609
If the standard input
 
8610
is coming from a terminal,
 
8611
.B readline
 
8612
(see
 
8613
.SM
 
8614
.B READLINE
 
8615
above) is used to obtain the line.
 
8616
Readline uses the current (or default, if line editing was not previously
 
8617
active) editing settings.
 
8618
.TP
 
8619
.B \-i \fItext\fP
 
8620
If
 
8621
.B readline
 
8622
is being used to read the line, \fItext\fP is placed into the editing
 
8623
buffer before editing begins.
 
8624
.TP
 
8625
.B \-n \fInchars\fP
 
8626
\fBread\fP returns after reading \fInchars\fP characters rather than
 
8627
waiting for a complete line of input, but honor a delimiter if fewer
 
8628
than \fInchars\fP characters are read before the delimiter.
 
8629
.TP
 
8630
.B \-N \fInchars\fP
 
8631
\fBread\fP returns after reading exactly \fInchars\fP characters rather
 
8632
than waiting for a complete line of input, unless EOF is encountered or
 
8633
\fBread\fP times out.
 
8634
Delimiter characters encountered in the input are
 
8635
not treated specially and do not cause \fBread\fP to return until
 
8636
\fInchars\fP characters are read.
 
8637
.TP
 
8638
.B \-p \fIprompt\fP
 
8639
Display \fIprompt\fP on standard error, without a
 
8640
trailing newline, before attempting to read any input.  The prompt
 
8641
is displayed only if input is coming from a terminal.
 
8642
.TP
 
8643
.B \-r
 
8644
Backslash does not act as an escape character.
 
8645
The backslash is considered to be part of the line.
 
8646
In particular, a backslash-newline pair may not be used as a line
 
8647
continuation.
 
8648
.TP
 
8649
.B \-s
 
8650
Silent mode.  If input is coming from a terminal, characters are
 
8651
not echoed.
 
8652
.TP
 
8653
.B \-t \fItimeout\fP
 
8654
Cause \fBread\fP to time out and return failure if a complete line of
 
8655
input (or a specified number of characters)
 
8656
is not read within \fItimeout\fP seconds.
 
8657
\fItimeout\fP may be a decimal number with a fractional portion following
 
8658
the decimal point.
 
8659
This option is only effective if \fBread\fP is reading input from a
 
8660
terminal, pipe, or other special file; it has no effect when reading
 
8661
from regular files.
 
8662
If \fBread\fP times out, \fBread\fP saves any partial input read into
 
8663
the specified variable \fIname\fP.
 
8664
If \fItimeout\fP is 0, \fBread\fP returns immediately, without trying to
 
8665
read any data.  The exit status is 0 if input is available on
 
8666
the specified file descriptor, non-zero otherwise.
 
8667
The exit status is greater than 128 if the timeout is exceeded.
 
8668
.TP
 
8669
.B \-u \fIfd\fP
 
8670
Read input from file descriptor \fIfd\fP.
 
8671
.PD
 
8672
.PP
 
8673
If no
 
8674
.I names
 
8675
are supplied, the line read is assigned to the variable
 
8676
.SM
 
8677
.BR REPLY .
 
8678
The return code is zero, unless end-of-file is encountered, \fBread\fP
 
8679
times out (in which case the return code is greater than 128),
 
8680
a variable assignment error (such as assigning to a readonly variable) occurs,
 
8681
or an invalid file descriptor is supplied as the argument to \fB\-u\fP.
 
8682
.RE
 
8683
.TP
 
8684
\fBreadonly\fP [\fB\-aAf\fP] [\fB\-p\fP] [\fIname\fP[=\fIword\fP] ...]
 
8685
.PD
 
8686
The given
 
8687
\fInames\fP are marked readonly; the values of these
 
8688
.I names
 
8689
may not be changed by subsequent assignment.
 
8690
If the
 
8691
.B \-f
 
8692
option is supplied, the functions corresponding to the
 
8693
\fInames\fP are so
 
8694
marked.
 
8695
The
 
8696
.B \-a
 
8697
option restricts the variables to indexed arrays; the
 
8698
.B \-A
 
8699
option restricts the variables to associative arrays.
 
8700
If both options are supplied,
 
8701
.B \-A
 
8702
takes precedence.
 
8703
If no
 
8704
.I name
 
8705
arguments are given, or if the
 
8706
.B \-p
 
8707
option is supplied, a list of all readonly names is printed.
 
8708
The other options may be used to restrict the output to a subset of
 
8709
the set of readonly names.
 
8710
The
 
8711
.B \-p
 
8712
option causes output to be displayed in a format that
 
8713
may be reused as input.
 
8714
If a variable name is followed by =\fIword\fP, the value of
 
8715
the variable is set to \fIword\fP.
 
8716
The return status is 0 unless an invalid option is encountered,
 
8717
one of the
 
8718
.I names
 
8719
is not a valid shell variable name, or
 
8720
.B \-f
 
8721
is supplied with a
 
8722
.I name
 
8723
that is not a function.
 
8724
.TP
 
8725
\fBreturn\fP [\fIn\fP]
 
8726
Causes a function to stop executing and return the value specified by
 
8727
.I n
 
8728
to its caller.
 
8729
If 
 
8730
.I n
 
8731
is omitted, the return status is that of the last command
 
8732
executed in the function body.  If
 
8733
.B return
 
8734
is used outside a function,
 
8735
but during execution of a script by the 
 
8736
.B .
 
8737
(\fBsource\fP) command, it causes the shell to stop executing
 
8738
that script and return either
 
8739
.I n
 
8740
or the exit status of the last command executed within the
 
8741
script as the exit status of the script.
 
8742
If \fIn\fP is supplied, the return value is its least significant
 
8743
8 bits.
 
8744
The return status is non-zero if
 
8745
.B return
 
8746
is supplied a non-numeric argument, or
 
8747
is used outside a
 
8748
function and not during execution of a script by \fB.\fP\^ or \fBsource\fP.
 
8749
Any command associated with the \fBRETURN\fP trap is executed
 
8750
before execution resumes after the function or script.
 
8751
.TP
 
8752
\fBset\fP [\fB\-\-abefhkmnptuvxBCEHPT\fP] [\fB\-o\fP \fIoption\-name\fP] [\fIarg\fP ...]
 
8753
.PD 0
 
8754
.TP
 
8755
\fBset\fP [\fB+abefhkmnptuvxBCEHPT\fP] [\fB+o\fP \fIoption\-name\fP] [\fIarg\fP ...]
 
8756
.PD
 
8757
Without options, the name and value of each shell variable are displayed
 
8758
in a format that can be reused as input
 
8759
for setting or resetting the currently-set variables.
 
8760
Read-only variables cannot be reset.
 
8761
In \fIposix\fP mode, only shell variables are listed.
 
8762
The output is sorted according to the current locale.
 
8763
When options are specified, they set or unset shell attributes.
 
8764
Any arguments remaining after option processing are treated
 
8765
as values for the positional parameters and are assigned, in order, to 
 
8766
.BR $1 ,
 
8767
.BR $2 ,
 
8768
.B ...
 
8769
.BR $\fIn\fP .
 
8770
Options, if specified, have the following meanings:
 
8771
.RS
 
8772
.PD 0
 
8773
.TP 8
 
8774
.B \-a
 
8775
Automatically mark variables and functions which are modified or
 
8776
created for export to the environment of subsequent commands.
 
8777
.TP 8
 
8778
.B \-b
 
8779
Report the status of terminated background jobs
 
8780
immediately, rather than before the next primary prompt.  This is
 
8781
effective only when job control is enabled.
 
8782
.TP 8
 
8783
.B \-e
 
8784
Exit immediately if a
 
8785
\fIpipeline\fP (which may consist of a single \fIsimple command\fP),
 
8786
a \fIlist\fP,
 
8787
or a \fIcompound command\fP
 
8788
(see
 
8789
.SM
 
8790
.B SHELL GRAMMAR
 
8791
above),  exits with a non-zero status.
 
8792
The shell does not exit if the
 
8793
command that fails is part of the command list immediately following a
 
8794
.B while
 
8795
or
 
8796
.B until
 
8797
keyword, 
 
8798
part of the test following the
 
8799
.B if
 
8800
or
 
8801
.B elif
 
8802
reserved words, part of any command executed in a
 
8803
.B &&
 
8804
or
 
8805
.B ||
 
8806
list except the command following the final \fB&&\fP or \fB||\fP,
 
8807
any command in a pipeline but the last,
 
8808
or if the command's return value is
 
8809
being inverted with
 
8810
.BR ! .
 
8811
If a compound command other than a subshell
 
8812
returns a non-zero status because a command failed
 
8813
while \fB\-e\fP was being ignored, the shell does not exit.
 
8814
A trap on \fBERR\fP, if set, is executed before the shell exits.
 
8815
This option applies to the shell environment and each subshell environment
 
8816
separately (see
 
8817
.SM
 
8818
.B "COMMAND EXECUTION ENVIRONMENT"
 
8819
above), and may cause
 
8820
subshells to exit before executing all the commands in the subshell.
 
8821
.if t .sp 0.5
 
8822
.if n .sp 1
 
8823
If a compound command or shell function executes in a context
 
8824
where \fB\-e\fP is being ignored,
 
8825
none of the commands executed within the compound command or function body
 
8826
will be affected by the \fB\-e\fP setting, even if \fB\-e\fP is set
 
8827
and a command returns a failure status.
 
8828
If a compound command or shell function sets \fB\-e\fP while executing in
 
8829
a context where \fB\-e\fP is ignored, that setting will not have any
 
8830
effect until the compound command or the command containing the function
 
8831
call completes.
 
8832
.TP 8
 
8833
.B \-f
 
8834
Disable pathname expansion.
 
8835
.TP 8 
 
8836
.B \-h
 
8837
Remember the location of commands as they are looked up for execution.
 
8838
This is enabled by default.
 
8839
.TP 8
 
8840
.B \-k
 
8841
All arguments in the form of assignment statements
 
8842
are placed in the environment for a command, not just
 
8843
those that precede the command name.
 
8844
.TP 8
 
8845
.B \-m
 
8846
Monitor mode.  Job control is enabled.  This option is on
 
8847
by default for interactive shells on systems that support
 
8848
it (see
 
8849
.SM
 
8850
.B JOB CONTROL
 
8851
above).
 
8852
All processes run in a separate process group.
 
8853
When a background job completes, the shell prints a line
 
8854
containing its exit status.
 
8855
.TP 8
 
8856
.B \-n
 
8857
Read commands but do not execute them.  This may be used to 
 
8858
check a shell script for syntax errors.  This is ignored by
 
8859
interactive shells.
 
8860
.TP 8
 
8861
.B \-o \fIoption\-name\fP
 
8862
The \fIoption\-name\fP can be one of the following:
 
8863
.RS
 
8864
.TP 8
 
8865
.B allexport
 
8866
Same as
 
8867
.BR \-a .
 
8868
.TP 8
 
8869
.B braceexpand
 
8870
Same as
 
8871
.BR \-B .
 
8872
.TP 8
 
8873
.B emacs
 
8874
Use an emacs-style command line editing interface.  This is enabled
 
8875
by default when the shell is interactive, unless the shell is started
 
8876
with the
 
8877
.B \-\-noediting
 
8878
option.
 
8879
This also affects the editing interface used for \fBread \-e\fP.
 
8880
.TP 8
 
8881
.B errexit
 
8882
Same as
 
8883
.BR \-e .
 
8884
.TP 8
 
8885
.B errtrace
 
8886
Same as
 
8887
.BR \-E .
 
8888
.TP 8
 
8889
.B functrace
 
8890
Same as
 
8891
.BR \-T .
 
8892
.TP 8
 
8893
.B hashall
 
8894
Same as
 
8895
.BR \-h .
 
8896
.TP 8
 
8897
.B histexpand
 
8898
Same as
 
8899
.BR \-H .
 
8900
.TP 8
 
8901
.B history
 
8902
Enable command history, as described above under
 
8903
.SM
 
8904
.BR HISTORY .
 
8905
This option is on by default in interactive shells.
 
8906
.TP 8
 
8907
.B ignoreeof
 
8908
The effect is as if the shell command
 
8909
.if t \f(CWIGNOREEOF=10\fP
 
8910
.if n ``IGNOREEOF=10''
 
8911
had been executed
 
8912
(see
 
8913
.B Shell Variables
 
8914
above).
 
8915
.TP 8
 
8916
.B keyword
 
8917
Same as
 
8918
.BR \-k .
 
8919
.TP 8
 
8920
.B monitor
 
8921
Same as
 
8922
.BR \-m .
 
8923
.TP 8
 
8924
.B noclobber
 
8925
Same as
 
8926
.BR \-C .
 
8927
.TP 8
 
8928
.B noexec
 
8929
Same as
 
8930
.BR \-n .
 
8931
.TP 8
 
8932
.B noglob
 
8933
Same as
 
8934
.BR \-f .
 
8935
.TP 8
 
8936
.B nolog
 
8937
Currently ignored.
 
8938
.TP 8
 
8939
.B notify
 
8940
Same as
 
8941
.BR \-b .
 
8942
.TP 8
 
8943
.B nounset
 
8944
Same as
 
8945
.BR \-u .
 
8946
.TP 8
 
8947
.B onecmd
 
8948
Same as
 
8949
.BR \-t .
 
8950
.TP 8
 
8951
.B physical
 
8952
Same as
 
8953
.BR \-P .
 
8954
.TP 8
 
8955
.B pipefail
 
8956
If set, the return value of a pipeline is the value of the last
 
8957
(rightmost) command to exit with a non-zero status, or zero if all
 
8958
commands in the pipeline exit successfully.
 
8959
This option is disabled by default.
 
8960
.TP 8
 
8961
.B posix
 
8962
Change the behavior of
 
8963
.B bash
 
8964
where the default operation differs
 
8965
from the POSIX standard to match the standard (\fIposix mode\fP).
 
8966
See
 
8967
.SM
 
8968
.B "SEE ALSO"
 
8969
below for a reference to a document that details how posix mode affects
 
8970
bash's behavior.
 
8971
.TP 8
 
8972
.B privileged
 
8973
Same as
 
8974
.BR \-p .
 
8975
.TP 8
 
8976
.B verbose
 
8977
Same as
 
8978
.BR \-v .
 
8979
.TP 8
 
8980
.B vi
 
8981
Use a vi-style command line editing interface.
 
8982
This also affects the editing interface used for \fBread \-e\fP.
 
8983
.TP 8
 
8984
.B xtrace
 
8985
Same as
 
8986
.BR \-x .
 
8987
.sp .5
 
8988
.PP
 
8989
If
 
8990
.B \-o
 
8991
is supplied with no \fIoption\-name\fP, the values of the current options are
 
8992
printed.
 
8993
If
 
8994
.B +o
 
8995
is supplied with no \fIoption\-name\fP, a series of
 
8996
.B set
 
8997
commands to recreate the current option settings is displayed on
 
8998
the standard output.
 
8999
.RE
 
9000
.TP 8
 
9001
.B \-p
 
9002
Turn on
 
9003
.I privileged
 
9004
mode.  In this mode, the
 
9005
.SM
 
9006
.B $ENV
 
9007
and
 
9008
.SM
 
9009
.B $BASH_ENV
 
9010
files are not processed, shell functions are not inherited from the
 
9011
environment, and the
 
9012
.SM
 
9013
.BR SHELLOPTS ,
 
9014
.SM
 
9015
.BR BASHOPTS ,
 
9016
.SM
 
9017
.BR CDPATH ,
 
9018
and
 
9019
.SM
 
9020
.B GLOBIGNORE
 
9021
variables, if they appear in the environment, are ignored.
 
9022
If the shell is started with the effective user (group) id not equal to the
 
9023
real user (group) id, and the \fB\-p\fP option is not supplied, these actions
 
9024
are taken and the effective user id is set to the real user id.
 
9025
If the \fB\-p\fP option is supplied at startup, the effective user id is
 
9026
not reset.
 
9027
Turning this option off causes the effective user
 
9028
and group ids to be set to the real user and group ids.
 
9029
.TP 8
 
9030
.B \-t
 
9031
Exit after reading and executing one command.
 
9032
.TP 8
 
9033
.B \-u
 
9034
Treat unset variables and parameters other than the special
 
9035
parameters "@" and "*" as an error when performing
 
9036
parameter expansion.  If expansion is attempted on an
 
9037
unset variable or parameter, the shell prints an error message, and,
 
9038
if not interactive, exits with a non-zero status.
 
9039
.TP 8
 
9040
.B \-v
 
9041
Print shell input lines as they are read.
 
9042
.TP 8
 
9043
.B \-x
 
9044
After expanding each \fIsimple command\fP,
 
9045
\fBfor\fP command, \fBcase\fP command, \fBselect\fP command, or
 
9046
arithmetic \fBfor\fP command, display the expanded value of
 
9047
.SM
 
9048
.BR PS4 ,
 
9049
followed by the command and its expanded arguments
 
9050
or associated word list.
 
9051
.TP 8
 
9052
.B \-B
 
9053
The shell performs brace expansion (see
 
9054
.B Brace Expansion
 
9055
above).  This is on by default.
 
9056
.TP 8
 
9057
.B \-C
 
9058
If set,
 
9059
.B bash
 
9060
does not overwrite an existing file with the
 
9061
.BR > ,
 
9062
.BR >& ,
 
9063
and
 
9064
.B <>
 
9065
redirection operators.  This may be overridden when 
 
9066
creating output files by using the redirection operator
 
9067
.B >|
 
9068
instead of
 
9069
.BR > .
 
9070
.TP 8
 
9071
.B \-E
 
9072
If set, any trap on \fBERR\fP is inherited by shell functions, command
 
9073
substitutions, and commands executed in a subshell environment.
 
9074
The \fBERR\fP trap is normally not inherited in such cases.
 
9075
.TP 8
 
9076
.B \-H
 
9077
Enable
 
9078
.B !
 
9079
style history substitution.  This option is on by
 
9080
default when the shell is interactive.
 
9081
.TP 8
 
9082
.B \-P
 
9083
If set, the shell does not resolve symbolic links when executing
 
9084
commands such as
 
9085
.B cd
 
9086
that change the current working directory.  It uses the
 
9087
physical directory structure instead.  By default,
 
9088
.B bash
 
9089
follows the logical chain of directories when performing commands
 
9090
which change the current directory.
 
9091
.TP 8
 
9092
.B \-T
 
9093
If set, any traps on \fBDEBUG\fP and \fBRETURN\fP are inherited by shell
 
9094
functions, command substitutions, and commands executed in a
 
9095
subshell environment.
 
9096
The \fBDEBUG\fP and \fBRETURN\fP traps are normally not inherited
 
9097
in such cases.
 
9098
.TP 8
 
9099
.B \-\-
 
9100
If no arguments follow this option, then the positional parameters are
 
9101
unset.  Otherwise, the positional parameters are set to the
 
9102
\fIarg\fPs, even if some of them begin with a
 
9103
.BR \- .
 
9104
.TP 8
 
9105
.B \-
 
9106
Signal the end of options, cause all remaining \fIarg\fPs to be
 
9107
assigned to the positional parameters.  The
 
9108
.B \-x
 
9109
and
 
9110
.B \-v
 
9111
options are turned off.
 
9112
If there are no \fIarg\fPs,
 
9113
the positional parameters remain unchanged.
 
9114
.PD
 
9115
.PP
 
9116
The options are off by default unless otherwise noted.
 
9117
Using + rather than \- causes these options to be turned off.
 
9118
The options can also be specified as arguments to an invocation of
 
9119
the shell.
 
9120
The current set of options may be found in
 
9121
.BR $\- .
 
9122
The return status is always true unless an invalid option is encountered.
 
9123
.RE
 
9124
.TP
 
9125
\fBshift\fP [\fIn\fP]
 
9126
The positional parameters from \fIn\fP+1 ... are renamed to
 
9127
.B $1
 
9128
.B ....
 
9129
Parameters represented by the numbers \fB$#\fP
 
9130
down to \fB$#\fP\-\fIn\fP+1 are unset.
 
9131
.I n
 
9132
must be a non-negative number less than or equal to \fB$#\fP.
 
9133
If
 
9134
.I n
 
9135
is 0, no parameters are changed.
 
9136
If
 
9137
.I n 
 
9138
is not given, it is assumed to be 1.
 
9139
If
 
9140
.I n
 
9141
is greater than \fB$#\fP, the positional parameters are not changed.
 
9142
The return status is greater than zero if
 
9143
.I n
 
9144
is greater than
 
9145
.B $#
 
9146
or less than zero; otherwise 0.
 
9147
.TP
 
9148
\fBshopt\fP [\fB\-pqsu\fP] [\fB\-o\fP] [\fIoptname\fP ...]
 
9149
Toggle the values of settings controlling optional shell behavior.
 
9150
The settings can be either those listed below, or, if the
 
9151
.B \-o
 
9152
option is used, those available with the
 
9153
.B \-o
 
9154
option to the \fBset\fP builtin command.
 
9155
With no options, or with the
 
9156
.B \-p
 
9157
option, a list of all settable options is displayed, with
 
9158
an indication of whether or not each is set.
 
9159
The \fB\-p\fP option causes output to be displayed in a form that
 
9160
may be reused as input.
 
9161
Other options have the following meanings:
 
9162
.RS
 
9163
.PD 0
 
9164
.TP
 
9165
.B \-s
 
9166
Enable (set) each \fIoptname\fP.
 
9167
.TP
 
9168
.B \-u
 
9169
Disable (unset) each \fIoptname\fP.
 
9170
.TP
 
9171
.B \-q
 
9172
Suppresses normal output (quiet mode); the return status indicates
 
9173
whether the \fIoptname\fP is set or unset.
 
9174
If multiple \fIoptname\fP arguments are given with
 
9175
.BR \-q ,
 
9176
the return status is zero if all \fIoptnames\fP are enabled; non-zero
 
9177
otherwise.
 
9178
.TP
 
9179
.B \-o
 
9180
Restricts the values of \fIoptname\fP to be those defined for the
 
9181
.B \-o
 
9182
option to the
 
9183
.B set
 
9184
builtin.
 
9185
.PD
 
9186
.PP
 
9187
If either
 
9188
.B \-s
 
9189
or
 
9190
.B \-u
 
9191
is used with no \fIoptname\fP arguments,
 
9192
.B shopt
 
9193
shows only those options which are set or unset, respectively.
 
9194
Unless otherwise noted, the \fBshopt\fP options are disabled (unset)
 
9195
by default.
 
9196
.PP
 
9197
The return status when listing options is zero if all \fIoptnames\fP
 
9198
are enabled, non-zero otherwise.  When setting or unsetting options,
 
9199
the return status is zero unless an \fIoptname\fP is not a valid shell
 
9200
option.
 
9201
.PP
 
9202
The list of \fBshopt\fP options is:
 
9203
.if t .sp .5v
 
9204
.if n .sp 1v
 
9205
.PD 0
 
9206
.TP 8
 
9207
.B autocd
 
9208
If set, a command name that is the name of a directory is executed as if
 
9209
it were the argument to the \fBcd\fP command.
 
9210
This option is only used by interactive shells.
 
9211
.TP 8
 
9212
.B cdable_vars
 
9213
If set, an argument to the
 
9214
.B cd
 
9215
builtin command that
 
9216
is not a directory is assumed to be the name of a variable whose
 
9217
value is the directory to change to.
 
9218
.TP 8
 
9219
.B cdspell
 
9220
If set, minor errors in the spelling of a directory component in a
 
9221
.B cd
 
9222
command will be corrected.
 
9223
The errors checked for are transposed characters,
 
9224
a missing character, and one character too many.
 
9225
If a correction is found, the corrected filename is printed,
 
9226
and the command proceeds.
 
9227
This option is only used by interactive shells.
 
9228
.TP 8
 
9229
.B checkhash
 
9230
If set, \fBbash\fP checks that a command found in the hash
 
9231
table exists before trying to execute it.  If a hashed command no
 
9232
longer exists, a normal path search is performed.
 
9233
.TP 8
 
9234
.B checkjobs
 
9235
If set, \fBbash\fP lists the status of any stopped and running jobs before
 
9236
exiting an interactive shell.  If any jobs are running, this causes
 
9237
the exit to be deferred until a second exit is attempted without an
 
9238
intervening command (see
 
9239
.SM
 
9240
.B "JOB CONTROL"
 
9241
above).  The shell always
 
9242
postpones exiting if any jobs are stopped.
 
9243
.TP 8
 
9244
.B checkwinsize
 
9245
If set, \fBbash\fP checks the window size after each command
 
9246
and, if necessary, updates the values of
 
9247
.SM
 
9248
.B LINES
 
9249
and
 
9250
.SM
 
9251
.BR COLUMNS .
 
9252
.TP 8
 
9253
.B cmdhist
 
9254
If set,
 
9255
.B bash
 
9256
attempts to save all lines of a multiple-line
 
9257
command in the same history entry.  This allows
 
9258
easy re-editing of multi-line commands.
 
9259
.TP 8
 
9260
.B compat31
 
9261
If set,
 
9262
.B bash
 
9263
changes its behavior to that of version 3.1 with respect to quoted
 
9264
arguments to the \fB[[\fP conditional command's \fB=~\fP operator
 
9265
and locale-specific string comparison when using the \fB[[\fP
 
9266
conditional command's \fB<\fP and \fB>\fP operators.
 
9267
Bash versions prior to bash-4.1 use ASCII collation and
 
9268
.IR strcmp (3);
 
9269
bash-4.1 and later use the current locale's collation sequence and
 
9270
.IR strcoll (3).
 
9271
.TP 8
 
9272
.B compat32
 
9273
If set,
 
9274
.B bash
 
9275
changes its behavior to that of version 3.2 with respect to
 
9276
locale-specific string comparison when using the \fB[[\fP
 
9277
conditional command's \fB<\fP and \fB>\fP operators (see previous item).
 
9278
.TP 8
 
9279
.B compat40
 
9280
If set,
 
9281
.B bash
 
9282
changes its behavior to that of version 4.0 with respect to locale-specific
 
9283
string comparison when using the \fB[[\fP
 
9284
conditional command's \fB<\fP and \fB>\fP operators (see description of
 
9285
\fBcompat31\fP)
 
9286
and the effect of interrupting a command list.
 
9287
Bash versions 4.0 and later interrupt the list as if the shell received the
 
9288
interrupt; previous versions continue with the next command in the list.
 
9289
.TP 8
 
9290
.B compat41
 
9291
If set,
 
9292
.BR bash ,
 
9293
when in \fIposix\fP mode, treats a single quote in a double-quoted
 
9294
parameter expansion as a special character.  The single quotes must match
 
9295
(an even number) and the characters between the single quotes are considered
 
9296
quoted.  This is the behavior of posix mode through version 4.1.
 
9297
The default bash behavior remains as in previous versions.
 
9298
.TP 8
 
9299
.B compat42
 
9300
If set,
 
9301
.B bash
 
9302
does not process the replacement string in the pattern substitution word
 
9303
expansion using quote removal.
 
9304
.TP 8
 
9305
.B complete_fullquote
 
9306
If set,
 
9307
.B bash
 
9308
quotes all shell metacharacters in filenames and directory names when
 
9309
performing completion.
 
9310
If not set,
 
9311
.B bash
 
9312
removes metacharacters such as the dollar sign from the set of
 
9313
characters that will be quoted in completed filenames
 
9314
when these metacharacters appear in shell variable references in words to be
 
9315
completed.
 
9316
This means that dollar signs in variable names that expand to directories
 
9317
will not be quoted;
 
9318
however, any dollar signs appearing in filenames will not be quoted, either.
 
9319
This is active only when bash is using backslashes to quote completed
 
9320
filenames.
 
9321
This variable is set by default, which is the default bash behavior in
 
9322
versions through 4.2.
 
9323
.TP 8
 
9324
.B direxpand
 
9325
If set,
 
9326
.B bash
 
9327
replaces directory names with the results of word expansion when performing
 
9328
filename completion.  This changes the contents of the readline editing
 
9329
buffer.
 
9330
If not set,
 
9331
.B bash
 
9332
attempts to preserve what the user typed.
 
9333
.TP 8
 
9334
.B dirspell
 
9335
If set,
 
9336
.B bash
 
9337
attempts spelling correction on directory names during word completion
 
9338
if the directory name initially supplied does not exist.
 
9339
.TP 8
 
9340
.B dotglob
 
9341
If set, 
 
9342
.B bash
 
9343
includes filenames beginning with a `.' in the results of pathname
 
9344
expansion.
 
9345
.TP 8
 
9346
.B execfail
 
9347
If set, a non-interactive shell will not exit if
 
9348
it cannot execute the file specified as an argument to the
 
9349
.B exec
 
9350
builtin command.  An interactive shell does not exit if
 
9351
.B exec
 
9352
fails.
 
9353
.TP 8
 
9354
.B expand_aliases
 
9355
If set, aliases are expanded as described above under
 
9356
.SM
 
9357
.BR ALIASES .
 
9358
This option is enabled by default for interactive shells.
 
9359
.TP 8
 
9360
.B extdebug
 
9361
If set, behavior intended for use by debuggers is enabled:
 
9362
.RS
 
9363
.TP
 
9364
.B 1.
 
9365
The \fB\-F\fP option to the \fBdeclare\fP builtin displays the source
 
9366
file name and line number corresponding to each function name supplied
 
9367
as an argument.
 
9368
.TP
 
9369
.B 2.
 
9370
If the command run by the \fBDEBUG\fP trap returns a non-zero value, the
 
9371
next command is skipped and not executed.
 
9372
.TP
 
9373
.B 3.
 
9374
If the command run by the \fBDEBUG\fP trap returns a value of 2, and the
 
9375
shell is executing in a subroutine (a shell function or a shell script
 
9376
executed by the \fB.\fP or \fBsource\fP builtins), a call to
 
9377
\fBreturn\fP is simulated.
 
9378
.TP
 
9379
.B 4.
 
9380
.SM
 
9381
.B BASH_ARGC
 
9382
and
 
9383
.SM
 
9384
.B BASH_ARGV
 
9385
are updated as described in their descriptions above.
 
9386
.TP
 
9387
.B 5.
 
9388
Function tracing is enabled:  command substitution, shell functions, and
 
9389
subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the
 
9390
\fBDEBUG\fP and \fBRETURN\fP traps.
 
9391
.TP
 
9392
.B 6.
 
9393
Error tracing is enabled:  command substitution, shell functions, and
 
9394
subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the
 
9395
\fBERR\fP trap.
 
9396
.RE
 
9397
.TP 8
 
9398
.B extglob
 
9399
If set, the extended pattern matching features described above under
 
9400
\fBPathname Expansion\fP are enabled.
 
9401
.TP 8
 
9402
.B extquote
 
9403
If set, \fB$\fP\(aq\fIstring\fP\(aq and \fB$\fP"\fIstring\fP" quoting is
 
9404
performed within \fB${\fP\fIparameter\fP\fB}\fP expansions
 
9405
enclosed in double quotes.  This option is enabled by default.
 
9406
.TP 8
 
9407
.B failglob
 
9408
If set, patterns which fail to match filenames during pathname expansion
 
9409
result in an expansion error.
 
9410
.TP 8
 
9411
.B force_fignore
 
9412
If set, the suffixes specified by the
 
9413
.SM
 
9414
.B FIGNORE
 
9415
shell variable
 
9416
cause words to be ignored when performing word completion even if
 
9417
the ignored words are the only possible completions.
 
9418
See
 
9419
.SM
 
9420
\fBSHELL VARIABLES\fP
 
9421
above for a description of
 
9422
.SM
 
9423
.BR FIGNORE .
 
9424
This option is enabled by default.
 
9425
.TP 8
 
9426
.B globasciiranges
 
9427
If set, range expressions used in pattern matching bracket expressions (see
 
9428
.SM
 
9429
.B Pattern Matching
 
9430
above) behave as if in the traditional C locale when performing
 
9431
comparisons.  That is, the current locale's collating sequence
 
9432
is not taken into account, so
 
9433
.B b
 
9434
will not collate between
 
9435
.B A
 
9436
and
 
9437
.BR B ,
 
9438
and upper-case and lower-case ASCII characters will collate together.
 
9439
.TP 8
 
9440
.B globstar
 
9441
If set, the pattern \fB**\fP used in a pathname expansion context will
 
9442
match all files and zero or more directories and subdirectories.
 
9443
If the pattern is followed by a \fB/\fP, only directories and
 
9444
subdirectories match.
 
9445
.TP 8
 
9446
.B gnu_errfmt
 
9447
If set, shell error messages are written in the standard GNU error
 
9448
message format.
 
9449
.TP 8
 
9450
.B histappend
 
9451
If set, the history list is appended to the file named by the value
 
9452
of the
 
9453
.SM
 
9454
.B HISTFILE
 
9455
variable when the shell exits, rather than overwriting the file.
 
9456
.TP 8
 
9457
.B histreedit
 
9458
If set, and
 
9459
.B readline
 
9460
is being used, a user is given the opportunity to re-edit a
 
9461
failed history substitution.
 
9462
.TP 8
 
9463
.B histverify
 
9464
If set, and 
 
9465
.B readline
 
9466
is being used, the results of history substitution are not immediately
 
9467
passed to the shell parser.  Instead, the resulting line is loaded into
 
9468
the \fBreadline\fP editing buffer, allowing further modification.
 
9469
.TP 8
 
9470
.B hostcomplete
 
9471
If set, and
 
9472
.B readline
 
9473
is being used, \fBbash\fP will attempt to perform hostname completion when a
 
9474
word containing a \fB@\fP is being completed (see
 
9475
.B Completing
 
9476
under
 
9477
.SM
 
9478
.B READLINE
 
9479
above).
 
9480
This is enabled by default.
 
9481
.TP 8
 
9482
.B huponexit
 
9483
If set, \fBbash\fP will send
 
9484
.SM
 
9485
.B SIGHUP
 
9486
to all jobs when an interactive login shell exits.
 
9487
.TP 8
 
9488
.B interactive_comments
 
9489
If set, allow a word beginning with
 
9490
.B #
 
9491
to cause that word and all remaining characters on that
 
9492
line to be ignored in an interactive shell (see
 
9493
.SM
 
9494
.B COMMENTS
 
9495
above).  This option is enabled by default.
 
9496
.TP 8
 
9497
.B lastpipe
 
9498
If set, and job control is not active, the shell runs the last command of
 
9499
a pipeline not executed in the background in the current shell environment.
 
9500
.TP 8
 
9501
.B lithist
 
9502
If set, and the
 
9503
.B cmdhist
 
9504
option is enabled, multi-line commands are saved to the history with
 
9505
embedded newlines rather than using semicolon separators where possible.
 
9506
.TP 8
 
9507
.B login_shell
 
9508
The shell sets this option if it is started as a login shell (see
 
9509
.SM
 
9510
.B "INVOCATION"
 
9511
above).
 
9512
The value may not be changed.
 
9513
.TP 8
 
9514
.B mailwarn
 
9515
If set, and a file that \fBbash\fP is checking for mail has been  
 
9516
accessed since the last time it was checked, the message ``The mail in
 
9517
\fImailfile\fP has been read'' is displayed.
 
9518
.TP 8
 
9519
.B no_empty_cmd_completion
 
9520
If set, and
 
9521
.B readline
 
9522
is being used,
 
9523
.B bash
 
9524
will not attempt to search the
 
9525
.SM
 
9526
.B PATH
 
9527
for possible completions when
 
9528
completion is attempted on an empty line.
 
9529
.TP 8
 
9530
.B nocaseglob
 
9531
If set,
 
9532
.B bash
 
9533
matches filenames in a case\-insensitive fashion when performing pathname
 
9534
expansion (see
 
9535
.B Pathname Expansion
 
9536
above).
 
9537
.TP 8
 
9538
.B nocasematch
 
9539
If set,
 
9540
.B bash
 
9541
matches patterns in a case\-insensitive fashion when performing matching
 
9542
while executing \fBcase\fP or \fB[[\fP conditional commands.
 
9543
.TP 8
 
9544
.B nullglob
 
9545
If set,
 
9546
.B bash
 
9547
allows patterns which match no
 
9548
files (see
 
9549
.B Pathname Expansion
 
9550
above)
 
9551
to expand to a null string, rather than themselves.
 
9552
.TP 8
 
9553
.B progcomp
 
9554
If set, the programmable completion facilities (see
 
9555
\fBProgrammable Completion\fP above) are enabled.
 
9556
This option is enabled by default.
 
9557
.TP 8
 
9558
.B promptvars
 
9559
If set, prompt strings undergo
 
9560
parameter expansion, command substitution, arithmetic
 
9561
expansion, and quote removal after being expanded as described in
 
9562
.SM
 
9563
.B PROMPTING
 
9564
above.  This option is enabled by default.
 
9565
.TP 8
 
9566
.B restricted_shell
 
9567
The shell sets this option if it is started in restricted mode (see
 
9568
.SM
 
9569
.B "RESTRICTED SHELL"
 
9570
below).
 
9571
The value may not be changed.
 
9572
This is not reset when the startup files are executed, allowing
 
9573
the startup files to discover whether or not a shell is restricted.
 
9574
.TP 8
 
9575
.B shift_verbose
 
9576
If set, the
 
9577
.B shift
 
9578
builtin prints an error message when the shift count exceeds the
 
9579
number of positional parameters.
 
9580
.TP 8
 
9581
.B sourcepath
 
9582
If set, the
 
9583
\fBsource\fP (\fB.\fP) builtin uses the value of
 
9584
.SM
 
9585
.B PATH
 
9586
to find the directory containing the file supplied as an argument.
 
9587
This option is enabled by default.
 
9588
.TP 8
 
9589
.B xpg_echo
 
9590
If set, the \fBecho\fP builtin expands backslash-escape sequences
 
9591
by default.
 
9592
.RE
 
9593
.PD
 
9594
.TP
 
9595
\fBsuspend\fP [\fB\-f\fP]
 
9596
Suspend the execution of this shell until it receives a
 
9597
.SM
 
9598
.B SIGCONT
 
9599
signal.  A login shell cannot be suspended; the
 
9600
.B \-f
 
9601
option can be used to override this and force the suspension.
 
9602
The return status is 0 unless the shell is a login shell and
 
9603
.B \-f
 
9604
is not supplied, or if job control is not enabled.
 
9605
.TP
 
9606
\fBtest\fP \fIexpr\fP
 
9607
.PD 0
 
9608
.TP
 
9609
\fB[\fP \fIexpr\fP \fB]\fP
 
9610
Return a status of 0 (true) or 1 (false) depending on
 
9611
the evaluation of the conditional expression
 
9612
.IR expr .
 
9613
Each operator and operand must be a separate argument.
 
9614
Expressions are composed of the primaries described above under
 
9615
.SM
 
9616
.BR "CONDITIONAL EXPRESSIONS" .
 
9617
\fBtest\fP does not accept any options, nor does it accept and ignore
 
9618
an argument of \fB\-\-\fP as signifying the end of options.
 
9619
.if t .sp 0.5
 
9620
.if n .sp 1
 
9621
Expressions may be combined using the following operators, listed
 
9622
in decreasing order of precedence.
 
9623
The evaluation depends on the number of arguments; see below.
 
9624
Operator precedence is used when there are five or more arguments.
 
9625
.RS
 
9626
.PD 0
 
9627
.TP
 
9628
.B ! \fIexpr\fP
 
9629
True if
 
9630
.I expr
 
9631
is false.
 
9632
.TP
 
9633
.B ( \fIexpr\fP )
 
9634
Returns the value of \fIexpr\fP.
 
9635
This may be used to override the normal precedence of operators.
 
9636
.TP
 
9637
\fIexpr1\fP \-\fBa\fP \fIexpr2\fP
 
9638
True if both
 
9639
.I expr1
 
9640
and
 
9641
.I expr2
 
9642
are true.
 
9643
.TP
 
9644
\fIexpr1\fP \-\fBo\fP \fIexpr2\fP
 
9645
True if either
 
9646
.I expr1
 
9647
or
 
9648
.I expr2
 
9649
is true.
 
9650
.PD
 
9651
.PP
 
9652
\fBtest\fP and \fB[\fP evaluate conditional
 
9653
expressions using a set of rules based on the number of arguments.
 
9654
.if t .sp 0.5
 
9655
.if n .sp 1
 
9656
.PD 0
 
9657
.TP
 
9658
0 arguments
 
9659
The expression is false.
 
9660
.TP
 
9661
1 argument
 
9662
The expression is true if and only if the argument is not null.
 
9663
.TP
 
9664
2 arguments
 
9665
If the first argument is \fB!\fP, the expression is true if and
 
9666
only if the second argument is null.
 
9667
If the first argument is one of the unary conditional operators listed above
 
9668
under
 
9669
.SM
 
9670
.BR "CONDITIONAL EXPRESSIONS" ,
 
9671
the expression is true if the unary test is true.
 
9672
If the first argument is not a valid unary conditional operator, the expression
 
9673
is false.
 
9674
.TP
 
9675
3 arguments
 
9676
The following conditions are applied in the order listed.
 
9677
If the second argument is one of the binary conditional operators listed above
 
9678
under
 
9679
.SM
 
9680
.BR "CONDITIONAL EXPRESSIONS" ,
 
9681
the result of the expression is the result of the binary test using
 
9682
the first and third arguments as operands.
 
9683
The \fB\-a\fP and \fB\-o\fP operators are considered binary operators
 
9684
when there are three arguments.  
 
9685
If the first argument is \fB!\fP, the value is the negation of
 
9686
the two-argument test using the second and third arguments.
 
9687
If the first argument is exactly \fB(\fP and the third argument is
 
9688
exactly \fB)\fP, the result is the one-argument test of the second
 
9689
argument.
 
9690
Otherwise, the expression is false.
 
9691
.TP
 
9692
4 arguments
 
9693
If the first argument is \fB!\fP, the result is the negation of
 
9694
the three-argument expression composed of the remaining arguments.
 
9695
Otherwise, the expression is parsed and evaluated according to 
 
9696
precedence using the rules listed above.
 
9697
.TP
 
9698
5 or more arguments
 
9699
The expression is parsed and evaluated according to precedence
 
9700
using the rules listed above.
 
9701
.if t .sp 0.5
 
9702
.if n .sp 1
 
9703
.LP
 
9704
When used with \fBtest\fP or \fB[\fP, the \fB<\fP and \fB>\fP operators
 
9705
sort lexicographically using ASCII ordering.
 
9706
.RE
 
9707
.PD
 
9708
.TP
 
9709
.B times
 
9710
Print the accumulated user and system times for the shell and
 
9711
for processes run from the shell.  The return status is 0.
 
9712
.TP
 
9713
\fBtrap\fP [\fB\-lp\fP] [[\fIarg\fP] \fIsigspec\fP ...]
 
9714
The command
 
9715
.I arg
 
9716
is to be read and executed when the shell receives
 
9717
signal(s)
 
9718
.IR sigspec .
 
9719
If
 
9720
.I arg
 
9721
is absent (and there is a single \fIsigspec\fP) or
 
9722
.BR \- ,
 
9723
each specified signal is
 
9724
reset to its original disposition (the value it had
 
9725
upon entrance to the shell).
 
9726
If 
 
9727
.I arg
 
9728
is the null string the signal specified by each
 
9729
.I sigspec
 
9730
is ignored by the shell and by the commands it invokes.
 
9731
If
 
9732
.I arg
 
9733
is not present and
 
9734
.B \-p
 
9735
has been supplied, then the trap commands associated with each
 
9736
.I sigspec
 
9737
are displayed.
 
9738
If no arguments are supplied or if only
 
9739
.B \-p
 
9740
is given,
 
9741
.B trap
 
9742
prints the list of commands associated with each signal.
 
9743
The
 
9744
.B \-l
 
9745
option causes the shell to print a list of signal names and
 
9746
their corresponding numbers.
 
9747
Each
 
9748
.I sigspec
 
9749
is either
 
9750
a signal name defined in <\fIsignal.h\fP>, or a signal number.
 
9751
Signal names are case insensitive and the
 
9752
.SM
 
9753
.B SIG
 
9754
prefix is optional.
 
9755
.if t .sp 0.5
 
9756
.if n .sp 1
 
9757
If a
 
9758
.I sigspec
 
9759
is
 
9760
.SM
 
9761
.B EXIT
 
9762
(0) the command
 
9763
.I arg
 
9764
is executed on exit from the shell.
 
9765
If a
 
9766
.I sigspec
 
9767
is
 
9768
.SM
 
9769
.BR DEBUG ,
 
9770
the command
 
9771
.I arg
 
9772
is executed before every \fIsimple command\fP, \fIfor\fP command,
 
9773
\fIcase\fP command, \fIselect\fP command, every arithmetic \fIfor\fP
 
9774
command, and before the first command executes in a shell function (see
 
9775
.SM
 
9776
.B SHELL GRAMMAR
 
9777
above).
 
9778
Refer to the description of the \fBextdebug\fP option to the
 
9779
\fBshopt\fP builtin for details of its effect on the \fBDEBUG\fP trap.
 
9780
If a
 
9781
.I sigspec
 
9782
is
 
9783
.SM
 
9784
.BR RETURN ,
 
9785
the command
 
9786
.I arg
 
9787
is executed each time a shell function or a script executed with
 
9788
the \fB.\fP or \fBsource\fP builtins finishes executing.
 
9789
.if t .sp 0.5
 
9790
.if n .sp 1
 
9791
If a
 
9792
.I sigspec
 
9793
is
 
9794
.SM
 
9795
.BR ERR ,
 
9796
the command
 
9797
.I arg
 
9798
is executed whenever a 
 
9799
a pipeline (which may consist of a single simple
 
9800
command), a list, or a compound command returns a 
 
9801
non\-zero exit status,
 
9802
subject to the following conditions.
 
9803
The
 
9804
.SM
 
9805
.B ERR
 
9806
trap is not executed if the failed
 
9807
command is part of the command list immediately following a
 
9808
.B while
 
9809
or
 
9810
.B until
 
9811
keyword, 
 
9812
part of the test in an
 
9813
.I if
 
9814
statement, part of a command executed in a
 
9815
.B &&
 
9816
or
 
9817
.B ||
 
9818
list except the command following the final \fB&&\fP or \fB||\fP,
 
9819
any command in a pipeline but the last,
 
9820
or if the command's return value is
 
9821
being inverted using
 
9822
.BR ! .
 
9823
These are the same conditions obeyed by the \fBerrexit\fP (\fB\-e\fP) option.
 
9824
.if t .sp 0.5
 
9825
.if n .sp 1
 
9826
Signals ignored upon entry to the shell cannot be trapped or reset.
 
9827
Trapped signals that are not being ignored are reset to their original
 
9828
values in a subshell or subshell environment when one is created.
 
9829
The return status is false if any
 
9830
.I sigspec
 
9831
is invalid; otherwise
 
9832
.B trap
 
9833
returns true.
 
9834
.TP
 
9835
\fBtype\fP [\fB\-aftpP\fP] \fIname\fP [\fIname\fP ...]
 
9836
With no options, 
 
9837
indicate how each
 
9838
.I name
 
9839
would be interpreted if used as a command name.
 
9840
If the
 
9841
.B \-t
 
9842
option is used,
 
9843
.B type
 
9844
prints a string which is one of
 
9845
.IR alias ,
 
9846
.IR keyword ,
 
9847
.IR function ,
 
9848
.IR builtin ,
 
9849
or
 
9850
.I file 
 
9851
if
 
9852
.I name
 
9853
is an alias, shell reserved word, function, builtin, or disk file,
 
9854
respectively.
 
9855
If the
 
9856
.I name
 
9857
is not found, then nothing is printed, and an exit status of false
 
9858
is returned.
 
9859
If the
 
9860
.B \-p
 
9861
option is used,
 
9862
.B type
 
9863
either returns the name of the disk file
 
9864
that would be executed if
 
9865
.I name
 
9866
were specified as a command name,
 
9867
or nothing if
 
9868
.if t \f(CWtype -t name\fP
 
9869
.if n ``type -t name''
 
9870
would not return
 
9871
.IR file .
 
9872
The
 
9873
.B \-P
 
9874
option forces a
 
9875
.SM
 
9876
.B PATH
 
9877
search for each \fIname\fP, even if
 
9878
.if t \f(CWtype -t name\fP
 
9879
.if n ``type -t name''
 
9880
would not return
 
9881
.IR file .
 
9882
If a command is hashed,
 
9883
.B \-p
 
9884
and
 
9885
.B \-P
 
9886
print the hashed value, which is not necessarily the file that appears
 
9887
first in 
 
9888
.SM
 
9889
.BR PATH .
 
9890
If the
 
9891
.B \-a
 
9892
option is used, 
 
9893
.B type
 
9894
prints all of the places that contain
 
9895
an executable named 
 
9896
.IR name .
 
9897
This includes aliases and functions,
 
9898
if and only if the 
 
9899
.B \-p
 
9900
option is not also used.
 
9901
The table of hashed commands is not consulted
 
9902
when using
 
9903
.BR \-a .
 
9904
The
 
9905
.B \-f
 
9906
option suppresses shell function lookup, as with the \fBcommand\fP builtin.
 
9907
.B type
 
9908
returns true if all of the arguments are found, false if
 
9909
any are not found.
 
9910
.TP
 
9911
\fBulimit\fP [\fB\-HSTabcdefilmnpqrstuvx\fP [\fIlimit\fP]]
 
9912
Provides control over the resources available to the shell and to
 
9913
processes started by it, on systems that allow such control.
 
9914
The \fB\-H\fP and \fB\-S\fP options specify that the hard or soft limit is
 
9915
set for the given resource.
 
9916
A hard limit cannot be increased by a non-root user once it is set;
 
9917
a soft limit may be increased up to the value of the hard limit.
 
9918
If neither \fB\-H\fP nor \fB\-S\fP is specified, both the soft and hard
 
9919
limits are set.
 
9920
The value of
 
9921
.I limit
 
9922
can be a number in the unit specified for the resource
 
9923
or one of the special values
 
9924
.BR hard ,
 
9925
.BR soft ,
 
9926
or
 
9927
.BR unlimited ,
 
9928
which stand for the current hard limit, the current soft limit, and
 
9929
no limit, respectively.
 
9930
If
 
9931
.I limit
 
9932
is omitted, the current value of the soft limit of the resource is
 
9933
printed, unless the \fB\-H\fP option is given.  When more than one
 
9934
resource is specified, the limit name and unit are printed before the value.
 
9935
Other options are interpreted as follows:
 
9936
.RS
 
9937
.PD 0
 
9938
.TP
 
9939
.B \-a
 
9940
All current limits are reported
 
9941
.TP
 
9942
.B \-b
 
9943
The maximum socket buffer size
 
9944
.TP
 
9945
.B \-c
 
9946
The maximum size of core files created
 
9947
.TP
 
9948
.B \-d
 
9949
The maximum size of a process's data segment
 
9950
.TP
 
9951
.B \-e
 
9952
The maximum scheduling priority ("nice")
 
9953
.TP
 
9954
.B \-f
 
9955
The maximum size of files written by the shell and its children
 
9956
.TP
 
9957
.B \-i
 
9958
The maximum number of pending signals
 
9959
.TP
 
9960
.B \-l
 
9961
The maximum size that may be locked into memory
 
9962
.TP
 
9963
.B \-m
 
9964
The maximum resident set size (many systems do not honor this limit)
 
9965
.TP
 
9966
.B \-n
 
9967
The maximum number of open file descriptors (most systems do not
 
9968
allow this value to be set)
 
9969
.TP
 
9970
.B \-p
 
9971
The pipe size in 512-byte blocks (this may not be set)
 
9972
.TP
 
9973
.B \-q
 
9974
The maximum number of bytes in POSIX message queues
 
9975
.TP
 
9976
.B \-r
 
9977
The maximum real-time scheduling priority
 
9978
.TP
 
9979
.B \-s
 
9980
The maximum stack size
 
9981
.TP
 
9982
.B \-t
 
9983
The maximum amount of cpu time in seconds
 
9984
.TP
 
9985
.B \-u
 
9986
The maximum number of processes available to a single user
 
9987
.TP
 
9988
.B \-v
 
9989
The maximum amount of virtual memory available to the shell and, on
 
9990
some systems, to its children
 
9991
.TP
 
9992
.B \-x
 
9993
The maximum number of file locks
 
9994
.TP
 
9995
.B \-T
 
9996
The maximum number of threads
 
9997
.PD
 
9998
.PP
 
9999
If
 
10000
.I limit
 
10001
is given, and the
 
10002
.B \-a
 
10003
option is not used,
 
10004
\fIlimit\fP is the new value of the specified resource.
 
10005
If no option is given, then
 
10006
.B \-f
 
10007
is assumed.  Values are in 1024-byte increments, except for
 
10008
.BR \-t ,
 
10009
which is in seconds;
 
10010
.BR \-p ,
 
10011
which is in units of 512-byte blocks;
 
10012
and
 
10013
.BR \-T ,
 
10014
.BR \-b ,
 
10015
.BR \-n ,
 
10016
and
 
10017
.BR \-u ,
 
10018
which are unscaled values.
 
10019
The return status is 0 unless an invalid option or argument is supplied,
 
10020
or an error occurs while setting a new limit.
 
10021
.RE
 
10022
.TP
 
10023
\fBumask\fP [\fB\-p\fP] [\fB\-S\fP] [\fImode\fP]
 
10024
The user file-creation mask is set to 
 
10025
.IR mode .
 
10026
If
 
10027
.I mode
 
10028
begins with a digit, it
 
10029
is interpreted as an octal number; otherwise
 
10030
it is interpreted as a symbolic mode mask similar
 
10031
to that accepted by
 
10032
.IR chmod (1).
 
10033
If
 
10034
.I mode
 
10035
is omitted, the current value of the mask is printed.
 
10036
The
 
10037
.B \-S
 
10038
option causes the mask to be printed in symbolic form; the
 
10039
default output is an octal number.
 
10040
If the
 
10041
.B \-p
 
10042
option is supplied, and
 
10043
.I mode
 
10044
is omitted, the output is in a form that may be reused as input.
 
10045
The return status is 0 if the mode was successfully changed or if
 
10046
no \fImode\fP argument was supplied, and false otherwise.
 
10047
.TP
 
10048
\fBunalias\fP [\-\fBa\fP] [\fIname\fP ...]
 
10049
Remove each \fIname\fP from the list of defined aliases.  If
 
10050
.B \-a
 
10051
is supplied, all alias definitions are removed.  The return
 
10052
value is true unless a supplied
 
10053
.I name
 
10054
is not a defined alias.
 
10055
.TP
 
10056
\fBunset\fP [\-\fBfv\fP] [\-\fBn\fP] [\fIname\fP ...]
 
10057
For each
 
10058
.IR name ,
 
10059
remove the corresponding variable or function.
 
10060
If the
 
10061
.B \-v
 
10062
option is given, each
 
10063
.I name
 
10064
refers to a shell variable, and that variable is removed.
 
10065
Read-only variables may not be unset.
 
10066
If
 
10067
.B \-f
 
10068
is specified, each
 
10069
.I name
 
10070
refers to a shell function, and the function definition
 
10071
is removed.
 
10072
If the
 
10073
.B \-n
 
10074
option is supplied, and \fIname\fP is a variable with the \fInameref\fP
 
10075
attribute, \fIname\fP will be unset rather than the variable it
 
10076
references.
 
10077
\fB\-n\fP has no effect if the \fB\-f\fP option is supplied.
 
10078
If no options are supplied, each \fIname\fP refers to a variable; if
 
10079
there is no variable by that name, any function with that name is
 
10080
unset.
 
10081
Each unset variable or function is removed from the environment
 
10082
passed to subsequent commands.
 
10083
If any of
 
10084
.SM
 
10085
.BR COMP_WORDBREAKS ,
 
10086
.SM
 
10087
.BR RANDOM ,
 
10088
.SM
 
10089
.BR SECONDS ,
 
10090
.SM
 
10091
.BR LINENO ,
 
10092
.SM
 
10093
.BR HISTCMD ,
 
10094
.SM
 
10095
.BR FUNCNAME ,
 
10096
.SM
 
10097
.BR GROUPS ,
 
10098
or
 
10099
.SM
 
10100
.B DIRSTACK
 
10101
are unset, they lose their special properties, even if they are
 
10102
subsequently reset.  The exit status is true unless a
 
10103
.I name
 
10104
is readonly.
 
10105
.TP
 
10106
\fBwait\fP [\fB\-n\fP] [\fIn ...\fP]
 
10107
Wait for each specified child process and return its termination status.
 
10108
Each
 
10109
.I n
 
10110
may be a process
 
10111
ID or a job specification; if a job spec is given, all processes
 
10112
in that job's pipeline are waited for.  If
 
10113
.I n
 
10114
is not given, all currently active child processes
 
10115
are waited for, and the return status is zero.
 
10116
If the \fB\-n\fP option is supplied, \fBwait\fP waits for any job to
 
10117
terminate and returns its exit status.
 
10118
If
 
10119
.I n
 
10120
specifies a non-existent process or job, the return status is
 
10121
127.  Otherwise, the return status is the exit status of the last
 
10122
process or job waited for.
 
10123
.\" bash_builtins
 
10124
.if \n(zZ=1 .ig zZ
 
10125
.SH "RESTRICTED SHELL"
 
10126
.\" rbash.1
 
10127
.zY
 
10128
.PP
 
10129
If
 
10130
.B bash
 
10131
is started with the name
 
10132
.BR rbash ,
 
10133
or the
 
10134
.B \-r
 
10135
option is supplied at invocation,
 
10136
the shell becomes restricted.
 
10137
A restricted shell is used to
 
10138
set up an environment more controlled than the standard shell.
 
10139
It behaves identically to
 
10140
.B bash
 
10141
with the exception that the following are disallowed or not performed:
 
10142
.IP \(bu
 
10143
changing directories with \fBcd\fP
 
10144
.IP \(bu
 
10145
setting or unsetting the values of
 
10146
.SM
 
10147
.BR SHELL ,
 
10148
.SM
 
10149
.BR PATH ,
 
10150
.SM
 
10151
.BR ENV ,
 
10152
or
 
10153
.SM
 
10154
.B BASH_ENV
 
10155
.IP \(bu
 
10156
specifying command names containing
 
10157
.B /
 
10158
.IP \(bu
 
10159
specifying a filename containing a
 
10160
.B /
 
10161
as an argument to the
 
10162
.B .
 
10163
builtin command
 
10164
.IP \(bu
 
10165
specifying a filename containing a slash as an argument to the
 
10166
.B \-p
 
10167
option to the
 
10168
.B hash
 
10169
builtin command
 
10170
.IP \(bu
 
10171
importing function definitions from the shell environment at startup
 
10172
.IP \(bu
 
10173
parsing the value of
 
10174
.SM
 
10175
.B SHELLOPTS
 
10176
from the shell environment at startup
 
10177
.IP \(bu
 
10178
redirecting output using the >, >|, <>, >&, &>, and >> redirection operators
 
10179
.IP \(bu
 
10180
using the
 
10181
.B exec
 
10182
builtin command to replace the shell with another command
 
10183
.IP \(bu
 
10184
adding or deleting builtin commands with the
 
10185
.B \-f
 
10186
and
 
10187
.B \-d
 
10188
options to the
 
10189
.B enable
 
10190
builtin command
 
10191
.IP \(bu
 
10192
using the \fBenable\fP builtin command to enable disabled shell builtins
 
10193
.IP \(bu
 
10194
specifying the
 
10195
.B \-p
 
10196
option to the
 
10197
.B command
 
10198
builtin command
 
10199
.IP \(bu
 
10200
turning off restricted mode with
 
10201
\fBset +r\fP or \fBset +o restricted\fP.
 
10202
.PP
 
10203
These restrictions are enforced after any startup files are read.
 
10204
.PP
 
10205
.ie \n(zY=1 When a command that is found to be a shell script is executed,
 
10206
.el \{ When a command that is found to be a shell script is executed
 
10207
(see
 
10208
.SM
 
10209
.B "COMMAND EXECUTION"
 
10210
above),
 
10211
\}
 
10212
.B rbash
 
10213
turns off any restrictions in the shell spawned to execute the
 
10214
script.
 
10215
.\" end of rbash.1
 
10216
.if \n(zY=1 .ig zY
 
10217
.SH "SEE ALSO"
 
10218
.PD 0
 
10219
.TP
 
10220
\fIBash Reference Manual\fP, Brian Fox and Chet Ramey
 
10221
.TP
 
10222
\fIThe Gnu Readline Library\fP, Brian Fox and Chet Ramey
 
10223
.TP
 
10224
\fIThe Gnu History Library\fP, Brian Fox and Chet Ramey
 
10225
.TP
 
10226
\fIPortable Operating System Interface (POSIX) Part 2: Shell and Utilities\fP, IEEE --
 
10227
http://pubs.opengroup.org/onlinepubs/9699919799/
 
10228
.TP
 
10229
http://tiswww.case.edu/~chet/bash/POSIX -- a description of posix mode
 
10230
.TP
 
10231
\fIsh\fP(1), \fIksh\fP(1), \fIcsh\fP(1)
 
10232
.TP
 
10233
\fIemacs\fP(1), \fIvi\fP(1)
 
10234
.TP
 
10235
\fIreadline\fP(3)
 
10236
.PD
 
10237
.SH FILES
 
10238
.PD 0
 
10239
.TP
 
10240
.FN /bin/bash
 
10241
The \fBbash\fP executable
 
10242
.TP
 
10243
.FN /etc/profile
 
10244
The systemwide initialization file, executed for login shells
 
10245
.TP
 
10246
.FN ~/.bash_profile
 
10247
The personal initialization file, executed for login shells
 
10248
.TP
 
10249
.FN ~/.bashrc
 
10250
The individual per-interactive-shell startup file
 
10251
.TP
 
10252
.FN ~/.bash_logout
 
10253
The individual login shell cleanup file, executed when a login shell exits
 
10254
.TP
 
10255
.FN ~/.inputrc
 
10256
Individual \fIreadline\fP initialization file
 
10257
.PD
 
10258
.SH AUTHORS
 
10259
Brian Fox, Free Software Foundation
 
10260
.br
 
10261
bfox@gnu.org
 
10262
.PP
 
10263
Chet Ramey, Case Western Reserve University
 
10264
.br
 
10265
chet.ramey@case.edu
 
10266
.SH BUG REPORTS
 
10267
If you find a bug in
 
10268
.B bash,
 
10269
you should report it.  But first, you should
 
10270
make sure that it really is a bug, and that it appears in the latest
 
10271
version of
 
10272
.BR bash .
 
10273
The latest version is always available from
 
10274
\fIftp://ftp.gnu.org/pub/gnu/bash/\fP.
 
10275
.PP
 
10276
Once you have determined that a bug actually exists, use the
 
10277
.I bashbug
 
10278
command to submit a bug report.
 
10279
If you have a fix, you are encouraged to mail that as well!
 
10280
Suggestions and `philosophical' bug reports may be mailed
 
10281
to \fIbug-bash@gnu.org\fP or posted to the Usenet
 
10282
newsgroup
 
10283
.BR gnu.bash.bug .
 
10284
.PP
 
10285
ALL bug reports should include:
 
10286
.PP
 
10287
.PD 0
 
10288
.TP 20
 
10289
The version number of \fBbash\fR
 
10290
.TP
 
10291
The hardware and operating system
 
10292
.TP
 
10293
The compiler used to compile
 
10294
.TP
 
10295
A description of the bug behaviour
 
10296
.TP
 
10297
A short script or `recipe' which exercises the bug
 
10298
.PD
 
10299
.PP
 
10300
.I bashbug
 
10301
inserts the first three items automatically into the template
 
10302
it provides for filing a bug report.
 
10303
.PP
 
10304
Comments and bug reports concerning
 
10305
this manual page should be directed to
 
10306
.IR chet.ramey@case.edu .
 
10307
.SH BUGS
 
10308
.PP
 
10309
It's too big and too slow.
 
10310
.PP
 
10311
There are some subtle differences between 
 
10312
.B bash
 
10313
and traditional versions of
 
10314
.BR sh ,
 
10315
mostly because of the
 
10316
.SM
 
10317
.B POSIX
 
10318
specification.
 
10319
.PP
 
10320
Aliases are confusing in some uses.
 
10321
.PP
 
10322
Shell builtin commands and functions are not stoppable/restartable.
 
10323
.PP
 
10324
Compound commands and command sequences of the form `a ; b ; c'
 
10325
are not handled gracefully when process suspension is attempted.
 
10326
When a process is stopped, the shell immediately executes the next
 
10327
command in the sequence.
 
10328
It suffices to place the sequence of commands between
 
10329
parentheses to force it into a subshell, which may be stopped as
 
10330
a unit.
 
10331
.PP
 
10332
Array variables may not (yet) be exported.
 
10333
.PP
 
10334
There may be only one active coprocess at a time.
 
10335
.zZ
 
10336
.zY