]> git.ipfire.org Git - thirdparty/bash.git/blame - doc/bash.1
updated translations; remove unneeded files
[thirdparty/bash.git] / doc / bash.1
CommitLineData
0628567a 1.\"
726f6388
JA
2.\" MAN PAGE COMMENTS to
3.\"
4.\" Chet Ramey
726f6388 5.\" Case Western Reserve University
ac50fbac 6.\" chet.ramey@case.edu
726f6388 7.\"
74091dd4 8.\" Last Change: Mon Sep 19 11:13:21 EDT 2022
726f6388
JA
9.\"
10.\" bash_builtins, strip all but Built-Ins section
11.if \n(zZ=1 .ig zZ
bb70624e 12.if \n(zY=1 .ig zY
74091dd4 13.TH BASH 1 "2022 September 19" "GNU Bash 5.2"
726f6388
JA
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.\"
d233b485
CR
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\a\\*(]X\au-3p \{\\*(]X
35.\" .br\}
36.\" .el \\*(]X\h\a|\\n()Iu+\\n()Ru\a\c
37.\" .}f
38.\" ..
726f6388
JA
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
ccc6cda3 47bash \- GNU Bourne-Again SHell
726f6388
JA
48.SH SYNOPSIS
49.B bash
50[options]
ac50fbac 51[command_string | file]
726f6388 52.SH COPYRIGHT
74091dd4
CR
53.if n Bash is Copyright (C) 1989-2022 by the Free Software Foundation, Inc.
54.if t Bash is Copyright \(co 1989-2022 by the Free Software Foundation, Inc.
726f6388
JA
55.SH DESCRIPTION
56.B Bash
ccc6cda3 57is an \fBsh\fR-compatible command language interpreter that
726f6388
JA
58executes commands read from the standard input or from a file.
59.B Bash
60also incorporates useful features from the \fIKorn\fP and \fIC\fP
61shells (\fBksh\fP and \fBcsh\fP).
62.PP
63.B Bash
0628567a
JA
64is intended to be a conformant implementation of the
65Shell and Utilities portion of the IEEE POSIX specification
66(IEEE Standard 1003.1).
95732b49
JA
67.B Bash
68can be configured to be POSIX-conformant by default.
726f6388 69.SH OPTIONS
a0c0a00f 70All of the single-character shell options documented in the
d233b485
CR
71description of the \fBset\fR builtin command, including \fB\-o\fP,
72can be used as options when the shell is invoked.
495aee44 73In addition, \fBbash\fR
cce855bc 74interprets the following options when it is invoked:
726f6388
JA
75.PP
76.PD 0
77.TP 10
ac50fbac 78.B \-c
ccc6cda3 79If the
726f6388 80.B \-c
ac50fbac
CR
81option is present, then commands are read from the first non-option argument
82.IR command_string .
726f6388 83If there are arguments after the
ac50fbac 84.IR command_string ,
a0c0a00f
CR
85the first argument is assigned to
86.B $0
87and any remaining arguments are assigned to the positional parameters.
88The assignment to
89.B $0
90sets the name of the shell, which is used in warning and error messages.
726f6388 91.TP
7117c2d2
JA
92.B \-i
93If the
94.B \-i
95option is present, the shell is
96.IR interactive .
97.TP
98.B \-l
99Make
100.B bash
101act as if it had been invoked as a login shell (see
102.SM
103.B INVOCATION
104below).
105.TP
ccc6cda3
JA
106.B \-r
107If the
108.B \-r
cce855bc 109option is present, the shell becomes
ccc6cda3
JA
110.I restricted
111(see
112.SM
113.B "RESTRICTED SHELL"
114below).
115.TP
726f6388
JA
116.B \-s
117If the
118.B \-s
cce855bc 119option is present, or if no arguments remain after option
726f6388
JA
120processing, then commands are read from the standard input.
121This option allows the positional parameters to be set
d233b485
CR
122when invoking an interactive shell or when reading input
123through a pipe.
726f6388 124.TP
ccc6cda3
JA
125.B \-D
126A list of all double-quoted strings preceded by \fB$\fP
95732b49 127is printed on the standard output.
ccc6cda3
JA
128These are the strings that
129are subject to language translation when the current locale
28ef6c31 130is not \fBC\fP or \fBPOSIX\fP.
ccc6cda3
JA
131This implies the \fB\-n\fP option; no commands will be executed.
132.TP
f73dda09
JA
133.B [\-+]O [\fIshopt_option\fP]
134\fIshopt_option\fP is one of the shell options accepted by the
135\fBshopt\fP builtin (see
136.SM
137.B SHELL BUILTIN COMMANDS
138below).
139If \fIshopt_option\fP is present, \fB\-O\fP sets the value of that option;
140\fB+O\fP unsets it.
141If \fIshopt_option\fP is not supplied, the names and values of the shell
142options accepted by \fBshopt\fP are printed on the standard output.
143If the invocation option is \fB+O\fP, the output is displayed in a format
144that may be reused as input.
145.TP
ccc6cda3
JA
146.B \-\-
147A
148.B \-\-
726f6388
JA
149signals the end of options and disables further option processing.
150Any arguments after the
726f6388 151.B \-\-
ccc6cda3
JA
152are treated as filenames and arguments. An argument of
153.B \-
154is equivalent to \fB\-\-\fP.
726f6388
JA
155.PD
156.PP
157.B Bash
ccc6cda3
JA
158also interprets a number of multi-character options.
159These options must appear on the command line before the
7117c2d2 160single-character options to be recognized.
726f6388
JA
161.PP
162.PD 0
726f6388 163.TP
b80f6443
JA
164.B \-\-debugger
165Arrange for the debugger profile to be executed before the shell
95732b49
JA
166starts.
167Turns on extended debugging mode (see the description of the
b80f6443
JA
168.B extdebug
169option to the
170.B shopt
b80f6443
JA
171builtin below).
172.TP
cce855bc
JA
173.B \-\-dump\-po\-strings
174Equivalent to \fB\-D\fP, but the output is in the GNU \fIgettext\fP
175\fBpo\fP (portable object) file format.
176.TP
ccc6cda3
JA
177.B \-\-dump\-strings
178Equivalent to \fB\-D\fP.
179.TP
180.B \-\-help
181Display a usage message on standard output and exit successfully.
182.TP
28ef6c31 183\fB\-\-init\-file\fP \fIfile\fP
7117c2d2 184.PD 0
28ef6c31
JA
185.TP
186\fB\-\-rcfile\fP \fIfile\fP
187.PD
188Execute commands from
189.I file
190instead of the standard personal initialization file
191.I ~/.bashrc
192if the shell is interactive (see
193.SM
194.B INVOCATION
195below).
196.TP
ccc6cda3 197.B \-\-login
7117c2d2 198Equivalent to \fB\-l\fP.
ccc6cda3
JA
199.TP
200.B \-\-noediting
201Do not use the GNU
202.B readline
bb70624e 203library to read command lines when the shell is interactive.
ccc6cda3
JA
204.TP
205.B \-\-noprofile
206Do not read either the system-wide startup file
726f6388
JA
207.FN /etc/profile
208or any of the personal initialization files
209.IR ~/.bash_profile ,
210.IR ~/.bash_login ,
211or
212.IR ~/.profile .
213By default,
214.B bash
ccc6cda3 215reads these files when it is invoked as a login shell (see
726f6388
JA
216.SM
217.B INVOCATION
218below).
219.TP
ccc6cda3
JA
220.B \-\-norc
221Do not read and execute the personal initialization file
222.I ~/.bashrc
223if the shell is interactive.
224This option is on by default if the shell is invoked as
225.BR sh .
226.TP
227.B \-\-posix
228Change the behavior of \fBbash\fP where the default operation differs
0628567a 229from the POSIX standard to match the standard (\fIposix mode\fP).
ac50fbac
CR
230See
231.SM
232.B "SEE ALSO"
233below for a reference to a document that details how posix mode affects
234bash's behavior.
726f6388 235.TP
ccc6cda3
JA
236.B \-\-restricted
237The shell becomes restricted (see
238.SM
239.B "RESTRICTED SHELL"
726f6388
JA
240below).
241.TP
ccc6cda3 242.B \-\-verbose
a0c0a00f 243Equivalent to \fB\-v\fP.
726f6388 244.TP
ccc6cda3
JA
245.B \-\-version
246Show version information for this instance of
247.B bash
248on the standard output and exit successfully.
726f6388
JA
249.PD
250.SH ARGUMENTS
251If arguments remain after option processing, and neither the
252.B \-c
253nor the
254.B \-s
255option has been supplied, the first argument is assumed to
ccc6cda3
JA
256be the name of a file containing shell commands.
257If
726f6388 258.B bash
a0c0a00f 259is invoked in this fashion,
726f6388
JA
260.B $0
261is set to the name of the file, and the positional parameters
262are set to the remaining arguments.
263.B Bash
264reads and executes commands from this file, then exits.
ccc6cda3
JA
265\fBBash\fP's exit status is the exit status of the last command
266executed in the script.
267If no commands are executed, the exit status is 0.
f73dda09
JA
268An attempt is first made to open the file in the current directory, and,
269if no file is found, then the shell searches the directories in
270.SM
271.B PATH
272for the script.
ccc6cda3
JA
273.SH INVOCATION
274A \fIlogin shell\fP is one whose first character of argument zero is a
275.BR \- ,
a0c0a00f 276or one started with the
ccc6cda3
JA
277.B \-\-login
278option.
279.PP
bb70624e 280An \fIinteractive\fP shell is one started without non-option arguments
a0c0a00f 281(unless \fB\-s\fP is specified)
bb70624e
JA
282and without the
283.B \-c
74091dd4 284option,
b80f6443 285whose standard input and error are
ccc6cda3
JA
286both connected to terminals (as determined by
287.IR isatty (3)),
288or one started with the
289.B \-i
290option.
291.SM
292.B PS1
293is set and
294.B $\-
295includes
296.B i
297if
298.B bash
299is interactive,
300allowing a shell script or a startup file to test this state.
301.PP
302The following paragraphs describe how
303.B bash
304executes its startup files.
305If any of the files exist but cannot be read,
306.B bash
307reports an error.
ac50fbac 308Tildes are expanded in filenames as described below under
ccc6cda3
JA
309.B "Tilde Expansion"
310in the
311.SM
312.B EXPANSION
313section.
314.PP
315When
316.B bash
b72432fd
JA
317is invoked as an interactive login shell, or as a non-interactive shell
318with the \fB\-\-login\fP option, it first reads and
d166f048
JA
319executes commands from the file \fI/etc/profile\fP, if that
320file exists.
ccc6cda3
JA
321After reading that file, it looks for \fI~/.bash_profile\fP,
322\fI~/.bash_login\fP, and \fI~/.profile\fP, in that order, and reads
323and executes commands from the first one that exists and is readable.
324The
325.B \-\-noprofile
326option may be used when the shell is started to inhibit this behavior.
327.PP
a0c0a00f
CR
328When an interactive login shell exits,
329or a non-interactive login shell executes the \fBexit\fP builtin command,
ccc6cda3
JA
330.B bash
331reads and executes commands from the file \fI~/.bash_logout\fP, if it
332exists.
333.PP
334When an interactive shell that is not a login shell is started,
335.B bash
336reads and executes commands from \fI~/.bashrc\fP, if that file exists.
337This may be inhibited by using the
338.B \-\-norc
339option.
340The \fB\-\-rcfile\fP \fIfile\fP option will force
341.B bash
342to read and execute commands from \fIfile\fP instead of \fI~/.bashrc\fP.
343.PP
344When
345.B bash
346is started non-interactively, to run a shell script, for example, it
347looks for the variable
348.SM
349.B BASH_ENV
350in the environment, expands its value if it appears there, and uses the
351expanded value as the name of a file to read and execute.
352.B Bash
353behaves as if the following command were executed:
354.sp .5
355.RS
28ef6c31
JA
356.if t \f(CWif [ \-n "$BASH_ENV" ]; then . "$BASH_ENV"; fi\fP
357.if n if [ \-n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
ccc6cda3
JA
358.RE
359.sp .5
360but the value of the
361.SM
362.B PATH
ac50fbac 363variable is not used to search for the filename.
ccc6cda3
JA
364.PP
365If
366.B bash
367is invoked with the name
368.BR sh ,
369it tries to mimic the startup behavior of historical versions of
370.B sh
371as closely as possible,
372while conforming to the POSIX standard as well.
b72432fd
JA
373When invoked as an interactive login shell, or a non-interactive
374shell with the \fB\-\-login\fP option, it first attempts to
cce855bc 375read and execute commands from
ccc6cda3
JA
376.I /etc/profile
377and
378.IR ~/.profile ,
379in that order.
380The
381.B \-\-noprofile
382option may be used to inhibit this behavior.
383When invoked as an interactive shell with the name
384.BR sh ,
385.B bash
386looks for the variable
387.SM
388.BR ENV ,
389expands its value if it is defined, and uses the
390expanded value as the name of a file to read and execute.
391Since a shell invoked as
392.B sh
393does not attempt to read and execute commands from any other startup
394files, the
395.B \-\-rcfile
396option has no effect.
397A non-interactive shell invoked with the name
398.B sh
8868edaf 399does not attempt to read any other startup files.
ccc6cda3
JA
400When invoked as
401.BR sh ,
402.B bash
403enters
404.I posix
405mode after the startup files are read.
406.PP
407When
408.B bash
409is started in
410.I posix
411mode, as with the
412.B \-\-posix
413command line option, it follows the POSIX standard for startup files.
cce855bc 414In this mode, interactive shells expand the
ccc6cda3
JA
415.SM
416.B ENV
cce855bc 417variable and commands are read and executed from the file
ccc6cda3
JA
418whose name is the expanded value.
419No other startup files are read.
ccc6cda3
JA
420.PP
421.B Bash
3185942a 422attempts to determine when it is being run with its standard input
74091dd4
CR
423connected to a network connection, as when executed by
424the historical remote shell daemon, usually \fIrshd\fP,
425or the secure shell daemon \fIsshd\fP.
ccc6cda3
JA
426If
427.B bash
74091dd4
CR
428determines it is being run non-interactively in this fashion,
429it reads and executes commands from \fI~/.bashrc\fP,
430if that file exists and is readable.
ccc6cda3
JA
431It will not do this if invoked as \fBsh\fP.
432The
433.B \-\-norc
434option may be used to inhibit this behavior, and the
435.B \-\-rcfile
ac50fbac
CR
436option may be used to force another file to be read, but neither
437\fIrshd\fP nor \fIsshd\fP generally invoke the shell with those options
ccc6cda3 438or allow them to be specified.
b72432fd
JA
439.PP
440If the shell is started with the effective user (group) id not equal to the
441real user (group) id, and the \fB\-p\fP option is not supplied, no startup
f73dda09
JA
442files are read, shell functions are not inherited from the environment, the
443.SM
0001803f
CR
444.BR SHELLOPTS ,
445.SM
446.BR BASHOPTS ,
447.SM
448.BR CDPATH ,
449and
450.SM
451.B GLOBIGNORE
452variables, if they appear in the environment, are ignored,
b72432fd
JA
453and the effective user id is set to the real user id.
454If the \fB\-p\fP option is supplied at invocation, the startup behavior is
455the same, but the effective user id is not reset.
726f6388 456.SH DEFINITIONS
ccc6cda3
JA
457The following definitions are used throughout the rest of this
458document.
726f6388
JA
459.PD 0
460.TP
a0c0a00f 461.B blank
726f6388
JA
462A space or tab.
463.TP
464.B word
465A sequence of characters considered as a single unit by the shell.
466Also known as a
467.BR token .
468.TP
469.B name
a0c0a00f 470A
726f6388
JA
471.I word
472consisting only of alphanumeric characters and underscores, and
473beginning with an alphabetic character or an underscore. Also
474referred to as an
475.BR identifier .
476.TP
477.B metacharacter
478A character that, when unquoted, separates words. One of the following:
479.br
480.RS
481.PP
a0c0a00f
CR
482.if t \fB| & ; ( ) < > space tab newline\fP
483.if n \fB| & ; ( ) < > space tab newline\fP
726f6388 484.RE
726f6388
JA
485.TP
486.B control operator
487A \fItoken\fP that performs a control function. It is one of the following
488symbols:
489.RS
490.PP
a0c0a00f
CR
491.if t \fB|| & && ; ;; ;& ;;& ( ) | |& <newline>\fP
492.if n \fB|| & && ; ;; ;& ;;& ( ) | |& <newline>\fP
726f6388
JA
493.RE
494.PD
495.SH "RESERVED WORDS"
496\fIReserved words\fP are words that have a special meaning to the shell.
497The following words are recognized as reserved when unquoted and either
8868edaf 498the first word of a command (see
726f6388
JA
499.SM
500.B SHELL GRAMMAR
8868edaf 501below), the third word of a
a0c0a00f 502.B case
726f6388 503or
8868edaf
CR
504.B select
505command
506(only \fBin\fP is valid), or the third word of a
726f6388 507.B for
8868edaf 508command (only \fBin\fP and \fBdo\fP are valid):
726f6388
JA
509.if t .RS
510.PP
511.B
ac50fbac
CR
512.if n ! case coproc do done elif else esac fi for function if in select then until while { } time [[ ]]
513.if t ! case coproc do done elif else esac fi for function if in select then until while { } time [[ ]]
726f6388 514.if t .RE
726f6388 515.SH "SHELL GRAMMAR"
74091dd4 516This section describes the syntax of the various forms of shell commands.
726f6388 517.SS Simple Commands
726f6388 518A \fIsimple command\fP is a sequence of optional variable assignments
ccc6cda3 519followed by \fBblank\fP-separated words and redirections, and
726f6388 520terminated by a \fIcontrol operator\fP. The first word
f73dda09
JA
521specifies the command to be executed, and is passed as argument zero.
522The remaining words are passed as arguments to the invoked command.
726f6388
JA
523.PP
524The return value of a \fIsimple command\fP is its exit status, or
525128+\fIn\^\fP if the command is terminated by signal
526.IR n .
527.SS Pipelines
726f6388 528A \fIpipeline\fP is a sequence of one or more commands separated by
3185942a
JA
529one of the control operators
530.B |
531or \fB|&\fP.
726f6388
JA
532The format for a pipeline is:
533.RS
534.PP
74091dd4 535[\fBtime\fP [\fB\-p\fP]] [ ! ] \fIcommand1\fP [ [\fB|\fP\(bv\fB|&\fP] \fIcommand2\fP ... ]
726f6388
JA
536.RE
537.PP
538The standard output of
74091dd4 539.I command1
f73dda09 540is connected via a pipe to the standard input of
726f6388
JA
541.IR command2 .
542This connection is performed before any redirections specified by the
74091dd4 543.IR command1 (see
726f6388
JA
544.SM
545.B REDIRECTION
546below).
74091dd4 547If \fB|&\fP is used, \fIcommand1\fP's standard error, in addition to its
ac50fbac
CR
548standard output, is connected to
549\fIcommand2\fP's standard input through the pipe;
550it is shorthand for \fB2>&1 |\fP.
551This implicit redirection of the standard error to the standard output is
74091dd4 552performed after any redirections specified by \fIcommand1\fP.
726f6388 553.PP
b80f6443
JA
554The return status of a pipeline is the exit status of the last
555command, unless the \fBpipefail\fP option is enabled.
556If \fBpipefail\fP is enabled, the pipeline's return status is the
557value of the last (rightmost) command to exit with a non-zero status,
558or zero if all commands exit successfully.
726f6388
JA
559If the reserved word
560.B !
b80f6443
JA
561precedes a pipeline, the exit status of that pipeline is the logical
562negation of the exit status as described above.
ccc6cda3 563The shell waits for all commands in the pipeline to
726f6388
JA
564terminate before returning a value.
565.PP
ccc6cda3
JA
566If the
567.B time
568reserved word precedes a pipeline, the elapsed as well as user and
569system time consumed by its execution are reported when the pipeline
570terminates.
571The \fB\-p\fP option changes the output format to that specified by POSIX.
495aee44
CR
572When the shell is in \fIposix mode\fP, it does not recognize
573\fBtime\fP as a reserved word if the next token begins with a `-'.
ccc6cda3
JA
574The
575.SM
576.B TIMEFORMAT
577variable may be set to a format string that specifies how the timing
578information should be displayed; see the description of
579.SM
580.B TIMEFORMAT
581under
582.B "Shell Variables"
583below.
584.PP
495aee44
CR
585When the shell is in \fIposix mode\fP, \fBtime\fP
586may be followed by a newline. In this case, the shell displays the
587total user and system time consumed by the shell and its children.
588The
589.SM
590.B TIMEFORMAT
591variable may be used to specify the format of
592the time information.
593.PP
74091dd4
CR
594Each command in a multi-command pipeline,
595where pipes are created,
596is executed in a \fIsubshell\fP, which is a
597separate process.
d233b485
CR
598See
599.SM
600\fBCOMMAND EXECUTION ENVIRONMENT\fP
74091dd4 601for a description of subshells and a subshell environment.
d233b485
CR
602If the \fBlastpipe\fP option is enabled using the \fBshopt\fP builtin
603(see the description of \fBshopt\fP below),
74091dd4
CR
604the last element of a pipeline may be run by the shell process
605when job control is not active.
726f6388 606.SS Lists
726f6388
JA
607A \fIlist\fP is a sequence of one or more pipelines separated by one
608of the operators
609.BR ; ,
610.BR & ,
611.BR && ,
612or
495aee44 613.BR || ,
ccc6cda3 614and optionally terminated by one of
726f6388
JA
615.BR ; ,
616.BR & ,
617or
618.BR <newline> .
619.PP
620Of these list operators,
621.B &&
622and
495aee44 623.B ||
726f6388
JA
624have equal precedence, followed by
625.B ;
626and
3185942a 627.BR & ,
726f6388
JA
628which have equal precedence.
629.PP
7117c2d2
JA
630A sequence of one or more newlines may appear in a \fIlist\fP instead
631of a semicolon to delimit commands.
632.PP
726f6388
JA
633If a command is terminated by the control operator
634.BR & ,
635the shell executes the command in the \fIbackground\fP
d233b485
CR
636in a subshell.
637The shell does not wait for the command to
638finish, and the return status is 0.
639These are referred to as \fIasynchronous\fP commands.
640Commands separated by a
726f6388
JA
641.B ;
642are executed sequentially; the shell waits for each
643command to terminate in turn. The return status is the
644exit status of the last command executed.
645.PP
a0c0a00f 646AND and OR lists are sequences of one or more pipelines separated by the
495aee44 647\fB&&\fP and \fB||\fP control operators, respectively.
3185942a 648AND and OR lists are executed with left associativity.
726f6388
JA
649An AND list has the form
650.RS
651.PP
bb70624e 652\fIcommand1\fP \fB&&\fP \fIcommand2\fP
726f6388
JA
653.RE
654.PP
655.I command2
656is executed if, and only if,
bb70624e 657.I command1
d233b485 658returns an exit status of zero (success).
726f6388
JA
659.PP
660An OR list has the form
661.RS
662.PP
495aee44 663\fIcommand1\fP \fB||\fP \fIcommand2\fP
726f6388
JA
664.RE
665.PP
666.I command2
d233b485 667is executed if, and only if,
bb70624e 668.I command1
3185942a
JA
669returns a non-zero exit status.
670The return status of
726f6388
JA
671AND and OR lists is the exit status of the last command
672executed in the list.
673.SS Compound Commands
ac50fbac
CR
674A \fIcompound command\fP is one of the following.
675In most cases a \fIlist\fP in a command's description may be separated from
676the rest of the command by one or more newlines, and may be followed by a
677newline in place of a semicolon.
726f6388
JA
678.TP
679(\fIlist\fP)
74091dd4 680\fIlist\fP is executed in a subshell (see
b80f6443
JA
681.SM
682\fBCOMMAND EXECUTION ENVIRONMENT\fP
74091dd4 683below for a description of a subshell environment).
b80f6443 684Variable assignments and builtin
726f6388
JA
685commands that affect the shell's environment do not remain in effect
686after the command completes. The return status is the exit status of
687\fIlist\fP.
688.TP
689{ \fIlist\fP; }
ccc6cda3
JA
690\fIlist\fP is simply executed in the current shell environment.
691\fIlist\fP must be terminated with a newline or semicolon.
692This is known as a \fIgroup command\fP.
693The return status is the exit status of
726f6388 694\fIlist\fP.
b80f6443 695Note that unlike the metacharacters \fB(\fP and \fB)\fP, \fB{\fP and
f73dda09
JA
696\fB}\fP are \fIreserved words\fP and must occur where a reserved
697word is permitted to be recognized. Since they do not cause a word
3185942a
JA
698break, they must be separated from \fIlist\fP by whitespace or another
699shell metacharacter.
726f6388 700.TP
ccc6cda3
JA
701((\fIexpression\fP))
702The \fIexpression\fP is evaluated according to the rules described
703below under
704.SM
705.BR "ARITHMETIC EVALUATION" .
706If the value of the expression is non-zero, the return status is 0;
74091dd4
CR
707otherwise the return status is 1.
708The \fIexpression\fP
709undergoes the same expansions
710as if it were within double quotes,
711but double quote characters in \fIexpression\fP are not treated specially
712and are removed.
ccc6cda3 713.TP
cce855bc
JA
714\fB[[\fP \fIexpression\fP \fB]]\fP
715Return a status of 0 or 1 depending on the evaluation of
716the conditional expression \fIexpression\fP.
717Expressions are composed of the primaries described below under
718.SM
719.BR "CONDITIONAL EXPRESSIONS" .
74091dd4
CR
720The words between the \fB[[\fP and \fB]]\fP do not undergo word splitting
721and pathname expansion.
722The shell performs tilde expansion, parameter and
723variable expansion, arithmetic expansion, command substitution, process
724substitution, and quote removal on those words
725(the expansions that would occur if the words were enclosed in double quotes).
b80f6443
JA
726Conditional operators such as \fB\-f\fP must be unquoted to be recognized
727as primaries.
cce855bc
JA
728.if t .sp 0.5
729.if n .sp 1
495aee44 730When used with \fB[[\fP, the \fB<\fP and \fB>\fP operators sort
0001803f
CR
731lexicographically using the current locale.
732.if t .sp 0.5
733.if n .sp 1
cce855bc
JA
734When the \fB==\fP and \fB!=\fP operators are used, the string to the
735right of the operator is considered a pattern and matched according
ac50fbac
CR
736to the rules described below under \fBPattern Matching\fP,
737as if the \fBextglob\fP shell option were enabled.
738The \fB=\fP operator is equivalent to \fB==\fP.
a0c0a00f 739If the
95732b49 740.B nocasematch
a0c0a00f 741shell option is enabled, the match is performed without regard to the case
95732b49 742of alphabetic characters.
0628567a
JA
743The return value is 0 if the string matches (\fB==\fP) or does not match
744(\fB!=\fP) the pattern, and 1 otherwise.
ac50fbac
CR
745Any part of the pattern may be quoted to force the quoted portion
746to be matched as a string.
cce855bc
JA
747.if t .sp 0.5
748.if n .sp 1
b80f6443
JA
749An additional binary operator, \fB=~\fP, is available, with the same
750precedence as \fB==\fP and \fB!=\fP.
751When it is used, the string to the right of the operator is considered
8868edaf
CR
752a POSIX extended regular expression and matched accordingly
753(using the POSIX \fIregcomp\fP and \fIregexec\fP interfaces
754usually described in \fIregex\fP(3)).
b80f6443
JA
755The return value is 0 if the string matches
756the pattern, and 1 otherwise.
757If the regular expression is syntactically incorrect, the conditional
758expression's return value is 2.
a0c0a00f 759If the
95732b49 760.B nocasematch
a0c0a00f 761shell option is enabled, the match is performed without regard to the case
b80f6443 762of alphabetic characters.
74091dd4
CR
763If any part of the pattern is quoted, the quoted portion is matched literally.
764This means every character in the quoted portion matches itself,
765instead of having any special pattern matching meaning.
ac50fbac 766If the pattern is stored in a shell variable, quoting the variable
74091dd4
CR
767expansion forces the entire pattern to be matched literally.
768Treat bracket expressions in regular expressions carefully,
769since normal quoting and pattern characters lose their meanings
770between brackets.
8868edaf
CR
771.if t .sp 0.5
772.if n .sp 1
773The pattern will match if it matches any part of the string.
774Anchor the pattern using the \fB^\fP and \fB$\fP regular expression
775operators to force it to match the entire string.
776The array variable
0001803f 777.SM
8868edaf
CR
778.B BASH_REMATCH
779records which parts of the string matched the pattern.
0001803f
CR
780The element of
781.SM
782.B BASH_REMATCH
8868edaf
CR
783with index 0 contains the portion of
784the string matching the entire regular expression.
785Substrings matched by parenthesized subexpressions within the regular
786expression are saved in the remaining
787.SM
788.B BASH_REMATCH
789indices. The element of
0001803f
CR
790.SM
791.B BASH_REMATCH
792with index \fIn\fP is the portion of the
b80f6443 793string matching the \fIn\fPth parenthesized subexpression.
74091dd4
CR
794Bash sets
795.SM
796.B BASH_REMATCH
797in the global scope; declaring it as a local variable will lead to
798unexpected results.
b80f6443
JA
799.if t .sp 0.5
800.if n .sp 1
cce855bc
JA
801Expressions may be combined using the following operators, listed
802in decreasing order of precedence:
803.if t .sp 0.5
804.if n .sp 1
805.RS
806.PD 0
807.TP
808.B ( \fIexpression\fP )
809Returns the value of \fIexpression\fP.
810This may be used to override the normal precedence of operators.
811.TP
812.B ! \fIexpression\fP
813True if
814.I expression
815is false.
816.TP
817\fIexpression1\fP \fB&&\fP \fIexpression2\fP
818True if both
819.I expression1
820and
821.I expression2
822are true.
823.TP
495aee44 824\fIexpression1\fP \fB||\fP \fIexpression2\fP
cce855bc
JA
825True if either
826.I expression1
827or
828.I expression2
829is true.
830.PD
cce855bc 831.LP
495aee44 832The \fB&&\fP and \fB||\fP
7117c2d2 833operators do not evaluate \fIexpression2\fP if the value of
cce855bc
JA
834\fIexpression1\fP is sufficient to determine the return value of
835the entire conditional expression.
f73dda09 836.RE
cce855bc 837.TP
0001803f 838\fBfor\fP \fIname\fP [ [ \fBin\fP [ \fIword ...\fP ] ] ; ] \fBdo\fP \fIlist\fP ; \fBdone\fP
726f6388 839The list of words following \fBin\fP is expanded, generating a list
bb70624e
JA
840of items.
841The variable \fIname\fP is set to each element of this list
842in turn, and \fIlist\fP is executed each time.
843If the \fBin\fP \fIword\fP is omitted, the \fBfor\fP command executes
844\fIlist\fP once for each positional parameter that is set (see
726f6388
JA
845.SM
846.B PARAMETERS
847below).
cce855bc
JA
848The return status is the exit status of the last command that executes.
849If the expansion of the items following \fBin\fP results in an empty
850list, no commands are executed, and the return status is 0.
726f6388 851.TP
bb70624e
JA
852\fBfor\fP (( \fIexpr1\fP ; \fIexpr2\fP ; \fIexpr3\fP )) ; \fBdo\fP \fIlist\fP ; \fBdone\fP
853First, the arithmetic expression \fIexpr1\fP is evaluated according
854to the rules described below under
855.SM
856.BR "ARITHMETIC EVALUATION" .
857The arithmetic expression \fIexpr2\fP is then evaluated repeatedly
858until it evaluates to zero.
859Each time \fIexpr2\fP evaluates to a non-zero value, \fIlist\fP is
860executed and the arithmetic expression \fIexpr3\fP is evaluated.
861If any expression is omitted, it behaves as if it evaluates to 1.
862The return value is the exit status of the last command in \fIlist\fP
863that is executed, or false if any of the expressions is invalid.
864.TP
b72432fd 865\fBselect\fP \fIname\fP [ \fBin\fP \fIword\fP ] ; \fBdo\fP \fIlist\fP ; \fBdone\fP
726f6388 866The list of words following \fBin\fP is expanded, generating a list
74091dd4 867of items, and the set of expanded words is printed on the standard
726f6388
JA
868error, each preceded by a number. If the \fBin\fP
869\fIword\fP is omitted, the positional parameters are printed (see
870.SM
871.B PARAMETERS
74091dd4
CR
872below).
873.B select
874then displays the
0001803f 875.SM
726f6388 876.B PS3
74091dd4 877prompt and reads a line from the standard input.
ccc6cda3 878If the line consists of a number corresponding to one of
726f6388
JA
879the displayed words, then the value of
880.I name
74091dd4
CR
881is set to that word.
882If the line is empty, the words and prompt are displayed again.
883If EOF is read, the \fBselect\fP command completes and returns 1.
884Any other value read causes
726f6388
JA
885.I name
886to be set to null. The line read is saved in the variable
0001803f 887.SM
726f6388
JA
888.BR REPLY .
889The
890.I list
891is executed after each selection until a
892.B break
726f6388
JA
893command is executed.
894The exit status of
895.B select
896is the exit status of the last command executed in
897.IR list ,
898or zero if no commands were executed.
899.TP
bb70624e 900\fBcase\fP \fIword\fP \fBin\fP [ [(] \fIpattern\fP [ \fB|\fP \fIpattern\fP ] \
726f6388
JA
901... ) \fIlist\fP ;; ] ... \fBesac\fP
902A \fBcase\fP command first expands \fIword\fP, and tries to match
d233b485
CR
903it against each \fIpattern\fP in turn, using the matching rules
904described under
905.B Pattern Matching
906below.
0628567a 907The \fIword\fP is expanded using tilde
a0c0a00f 908expansion, parameter and variable expansion, arithmetic expansion,
0628567a
JA
909command substitution, process substitution and quote removal.
910Each \fIpattern\fP examined is expanded using tilde
a0c0a00f 911expansion, parameter and variable expansion, arithmetic expansion,
74091dd4 912command substitution, process substitution, and quote removal.
a0c0a00f 913If the
95732b49 914.B nocasematch
a0c0a00f 915shell option is enabled, the match is performed without regard to the case
95732b49 916of alphabetic characters.
3185942a
JA
917When a match is found, the corresponding \fIlist\fP is executed.
918If the \fB;;\fP operator is used, no subsequent matches are attempted after
919the first pattern match.
920Using \fB;&\fP in place of \fB;;\fP causes execution to continue with
921the \fIlist\fP associated with the next set of patterns.
922Using \fB;;&\fP in place of \fB;;\fP causes the shell to test the next
923pattern list in the statement, if any, and execute any associated \fIlist\fP
8868edaf
CR
924on a successful match,
925continuing the case statement execution as if the pattern list had not matched.
3185942a 926The exit status is zero if no
ccc6cda3 927pattern matches. Otherwise, it is the exit status of the
726f6388
JA
928last command executed in \fIlist\fP.
929.TP
ac50fbac 930\fBif\fP \fIlist\fP; \fBthen\fP \fIlist\fP; \
ccc6cda3
JA
931[ \fBelif\fP \fIlist\fP; \fBthen\fP \fIlist\fP; ] ... \
932[ \fBelse\fP \fIlist\fP; ] \fBfi\fP
726f6388 933The
a0c0a00f 934.B if
726f6388
JA
935.I list
936is executed. If its exit status is zero, the
937\fBthen\fP \fIlist\fP is executed. Otherwise, each \fBelif\fP
938\fIlist\fP is executed in turn, and if its exit status is zero,
939the corresponding \fBthen\fP \fIlist\fP is executed and the
940command completes. Otherwise, the \fBelse\fP \fIlist\fP is
941executed, if present. The exit status is the exit status of the
942last command executed, or zero if no condition tested true.
943.TP
495aee44 944\fBwhile\fP \fIlist-1\fP; \fBdo\fP \fIlist-2\fP; \fBdone\fP
7117c2d2 945.PD 0
726f6388 946.TP
495aee44 947\fBuntil\fP \fIlist-1\fP; \fBdo\fP \fIlist-2\fP; \fBdone\fP
726f6388 948.PD
495aee44
CR
949The \fBwhile\fP command continuously executes the list
950\fIlist-2\fP as long as the last command in the list \fIlist-1\fP returns
726f6388 951an exit status of zero. The \fBuntil\fP command is identical
a0c0a00f 952to the \fBwhile\fP command, except that the test is negated:
495aee44 953.I list-2
726f6388 954is executed as long as the last command in
495aee44 955.I list-1
ccc6cda3 956returns a non-zero exit status.
726f6388
JA
957The exit status of the \fBwhile\fP and \fBuntil\fP commands
958is the exit status
495aee44 959of the last command executed in \fIlist-2\fP, or zero if
726f6388 960none was executed.
3185942a 961.SS Coprocesses
3185942a
JA
962A \fIcoprocess\fP is a shell command preceded by the \fBcoproc\fP reserved
963word.
964A coprocess is executed asynchronously in a subshell, as if the command
965had been terminated with the \fB&\fP control operator, with a two-way pipe
966established between the executing shell and the coprocess.
967.PP
74091dd4 968The syntax for a coprocess is:
3185942a
JA
969.RS
970.PP
971\fBcoproc\fP [\fINAME\fP] \fIcommand\fP [\fIredirections\fP]
972.RE
973.PP
974This creates a coprocess named \fINAME\fP.
74091dd4
CR
975\fIcommand\fP may be either a simple command or a compound
976command (see above).
977\fINAME\fP is a shell variable name.
ac50fbac 978If \fINAME\fP is not supplied, the default name is \fBCOPROC\fP.
74091dd4
CR
979.PP
980The recommended form to use for a coprocess is
981.RS
982.PP
983\fBcoproc\fP \fINAME\fP { \fIcommand\fP [\fIredirections\fP]; }
984.RE
985.PP
986This form is recommended because simple commands result in the coprocess
987always being named \fBCOPROC\fP, and it is simpler to use and more complete
988than the other compound commands.
989.PP
990If \fIcommand\fP is a compound command, \fINAME\fP is optional. The
991word following \fBcoproc\fP determines whether that word is interpreted
992as a variable name: it is interpreted as \fINAME\fP if it is not a
993reserved word that introduces a compound command.
994If \fIcommand\fP is a simple command, \fINAME\fP is not allowed; this
995is to avoid confusion between \fINAME\fP and the first word of the simple
996command.
997.PP
ac50fbac 998When the coprocess is executed, the shell creates an array variable (see
3185942a
JA
999.B Arrays
1000below) named \fINAME\fP in the context of the executing shell.
1001The standard output of
1002.I command
1003is connected via a pipe to a file descriptor in the executing shell,
1004and that file descriptor is assigned to \fINAME\fP[0].
1005The standard input of
1006.I command
1007is connected via a pipe to a file descriptor in the executing shell,
1008and that file descriptor is assigned to \fINAME\fP[1].
1009This pipe is established before any redirections specified by the
1010command (see
1011.SM
1012.B REDIRECTION
1013below).
1014The file descriptors can be utilized as arguments to shell commands
1015and redirections using standard word expansions.
d233b485
CR
1016Other than those created to execute command and process substitutions,
1017the file descriptors are not available in subshells.
74091dd4 1018.PP
495aee44 1019The process ID of the shell spawned to execute the coprocess is
3185942a
JA
1020available as the value of the variable \fINAME\fP_PID.
1021The \fBwait\fP
1022builtin command may be used to wait for the coprocess to terminate.
1023.PP
ac50fbac
CR
1024Since the coprocess is created as an asynchronous command,
1025the \fBcoproc\fP command always returns success.
3185942a 1026The return status of a coprocess is the exit status of \fIcommand\fP.
b80f6443 1027.SS Shell Function Definitions
b80f6443
JA
1028A shell function is an object that is called like a simple command and
1029executes a compound command with a new set of positional parameters.
1030Shell functions are declared as follows:
1031.TP
8868edaf 1032\fIfname\fP () \fIcompound\-command\fP [\fIredirection\fP]
495aee44
CR
1033.PD 0
1034.TP
8868edaf 1035\fBfunction\fP \fIfname\fP [()] \fIcompound\-command\fP [\fIredirection\fP]
495aee44 1036.PD
8868edaf 1037This defines a function named \fIfname\fP.
b80f6443
JA
1038The reserved word \fBfunction\fP is optional.
1039If the \fBfunction\fP reserved word is supplied, the parentheses are optional.
1040The \fIbody\fP of the function is the compound command
a0c0a00f 1041.I compound\-command
b80f6443
JA
1042(see \fBCompound Commands\fP above).
1043That command is usually a \fIlist\fP of commands between { and }, but
74091dd4
CR
1044may be any command listed under \fBCompound Commands\fP above.
1045If the \fBfunction\fP reserved word is used, but the
1046parentheses are not supplied, the braces are recommended.
8868edaf 1047\fIcompound\-command\fP is executed whenever \fIfname\fP is specified as the
b80f6443 1048name of a simple command.
8868edaf
CR
1049When in \fIposix mode\fP, \fIfname\fP must be a valid shell \fIname\fP
1050and may not be the name of one of the
ac50fbac 1051POSIX \fIspecial builtins\fP.
8868edaf
CR
1052In default mode, a function name can be any unquoted shell word that does
1053not contain \fB$\fP.
b80f6443
JA
1054Any redirections (see
1055.SM
1056.B REDIRECTION
1057below) specified when a function is defined are performed
1058when the function is executed.
1059The exit status of a function definition is zero unless a syntax error
1060occurs or a readonly function with the same name already exists.
1061When executed, the exit status of a function is the exit status of the
1062last command executed in the body. (See
726f6388
JA
1063.SM
1064.B FUNCTIONS
1065below.)
1066.SH COMMENTS
ccc6cda3
JA
1067In a non-interactive shell, or an interactive shell in which the
1068.B interactive_comments
1069option to the
1070.B shopt
1071builtin is enabled (see
1072.SM
1073.B "SHELL BUILTIN COMMANDS"
1074below), a word beginning with
726f6388
JA
1075.B #
1076causes that word and all remaining characters on that line to
1077be ignored. An interactive shell without the
ccc6cda3 1078.B interactive_comments
ccc6cda3
JA
1079option enabled does not allow comments. The
1080.B interactive_comments
1081option is on by default in interactive shells.
726f6388
JA
1082.SH QUOTING
1083\fIQuoting\fP is used to remove the special meaning of certain
a0c0a00f 1084characters or words to the shell. Quoting can be used to
726f6388
JA
1085disable special treatment for special characters, to prevent
1086reserved words from being recognized as such, and to prevent
1087parameter expansion.
1088.PP
1089Each of the \fImetacharacters\fP listed above under
1090.SM
1091.B DEFINITIONS
bb70624e
JA
1092has special meaning to the shell and must be quoted if it is to
1093represent itself.
1094.PP
95732b49
JA
1095When the command history expansion facilities are being used
1096(see
1097.SM
1098.B HISTORY EXPANSION
1099below), the
bb70624e
JA
1100\fIhistory expansion\fP character, usually \fB!\fP, must be quoted
1101to prevent history expansion.
1102.PP
1103There are three quoting mechanisms: the
726f6388
JA
1104.IR "escape character" ,
1105single quotes, and double quotes.
1106.PP
1107A non-quoted backslash (\fB\e\fP) is the
1108.IR "escape character" .
1109It preserves the literal value of the next character that follows,
1110with the exception of <newline>. If a \fB\e\fP<newline> pair
cce855bc
JA
1111appears, and the backslash is not itself quoted, the \fB\e\fP<newline>
1112is treated as a line continuation (that is, it is removed from the
1113input stream and effectively ignored).
726f6388
JA
1114.PP
1115Enclosing characters in single quotes preserves the literal value
1116of each character within the quotes. A single quote may not occur
1117between single quotes, even when preceded by a backslash.
1118.PP
1119Enclosing characters in double quotes preserves the literal value
1120of all characters within the quotes, with the exception of
1121.BR $ ,
3185942a 1122.BR \` ,
95732b49
JA
1123.BR \e ,
1124and, when history expansion is enabled,
1125.BR ! .
a0c0a00f
CR
1126When the shell is in \fIposix mode\fP, the \fB!\fP has no special meaning
1127within double quotes, even when history expansion is enabled.
726f6388
JA
1128The characters
1129.B $
1130and
3185942a 1131.B \`
726f6388
JA
1132retain their special meaning within double quotes. The backslash
1133retains its special meaning only when followed by one of the following
1134characters:
1135.BR $ ,
3185942a 1136.BR \` ,
726f6388
JA
1137\^\fB"\fP\^,
1138.BR \e ,
1139or
1140.BR <newline> .
1141A double quote may be quoted within double quotes by preceding it with
1142a backslash.
95732b49
JA
1143If enabled, history expansion will be performed unless an
1144.B !
1145appearing in double quotes is escaped using a backslash.
1146The backslash preceding the
1147.B !
1148is not removed.
726f6388
JA
1149.PP
1150The special parameters
1151.B *
1152and
1153.B @
1154have special meaning when in double
1155quotes (see
1156.SM
1157.B PARAMETERS
1158below).
ccc6cda3 1159.PP
74091dd4
CR
1160Character sequences of the form \fB$\fP\(aq\fIstring\fP\(aq are treated
1161as a special variant of single quotes.
1162The sequence expands to \fIstring\fP, with backslash-escaped characters
1163in \fIstring\fP replaced as specified by the ANSI C standard.
1164Backslash escape sequences, if present, are decoded as follows:
ccc6cda3
JA
1165.RS
1166.PD 0
1167.TP
1168.B \ea
1169alert (bell)
1170.TP
1171.B \eb
1172backspace
1173.TP
1174.B \ee
0001803f
CR
1175.TP
1176.B \eE
ccc6cda3 1177an escape character
a0c0a00f 1178.TP
ccc6cda3
JA
1179.B \ef
1180form feed
a0c0a00f 1181.TP
ccc6cda3
JA
1182.B \en
1183new line
a0c0a00f 1184.TP
ccc6cda3
JA
1185.B \er
1186carriage return
1187.TP
1188.B \et
1189horizontal tab
a0c0a00f 1190.TP
ccc6cda3
JA
1191.B \ev
1192vertical tab
1193.TP
1194.B \e\e
1195backslash
bb70624e 1196.TP
0628567a 1197.B \e\(aq
bb70624e 1198single quote
0001803f
CR
1199.TP
1200.B \e\(dq
1201double quote
a0c0a00f
CR
1202.TP
1203.B \e?
1204question mark
1205.TP
ccc6cda3 1206.B \e\fInnn\fP
f73dda09 1207the eight-bit character whose value is the octal value \fInnn\fP
d233b485 1208(one to three octal digits)
cce855bc 1209.TP
f73dda09
JA
1210.B \ex\fIHH\fP
1211the eight-bit character whose value is the hexadecimal value \fIHH\fP
1212(one or two hex digits)
7117c2d2 1213.TP
495aee44
CR
1214.B \eu\fIHHHH\fP
1215the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
1216\fIHHHH\fP (one to four hex digits)
1217.TP
1218.B \eU\fIHHHHHHHH\fP
1219the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
1220\fIHHHHHHHH\fP (one to eight hex digits)
1221.TP
7117c2d2
JA
1222.B \ec\fIx\fP
1223a control-\fIx\fP character
ccc6cda3
JA
1224.PD
1225.RE
1226.LP
bb70624e 1227The expanded result is single-quoted, as if the dollar sign had
ccc6cda3
JA
1228not been present.
1229.PP
0001803f
CR
1230A double-quoted string preceded by a dollar sign (\fB$\fP\(dq\fIstring\fP\(dq)
1231will cause the string to be translated according to the current locale.
74091dd4
CR
1232The \fIgettext\fP infrastructure performs the lookup and
1233translation, using the \fBLC_MESSAGES\fP, \fBTEXTDOMAINDIR\fP,
1234and \fBTEXTDOMAIN\fP shell variables.
8868edaf 1235If the current locale is \fBC\fP or \fBPOSIX\fP,
74091dd4
CR
1236if there are no translations available,
1237or if the string is not translated,
8868edaf 1238the dollar sign is ignored.
74091dd4
CR
1239This is a form of double quoting, so the string remains double-quoted
1240by default, whether or not it is translated and replaced.
1241If the \fBnoexpand_translation\fP option is enabled
1242using the \fBshopt\fP builtin,
1243translated strings are single-quoted instead of double-quoted.
1244See the description of
1245.B shopt
1246below under
1247.SM
1248.BR SHELL BUILTIN COMMANDS .
726f6388
JA
1249.SH PARAMETERS
1250A
1251.I parameter
ccc6cda3
JA
1252is an entity that stores values.
1253It can be a
726f6388
JA
1254.IR name ,
1255a number, or one of the special characters listed below under
1256.BR "Special Parameters" .
b80f6443 1257A
726f6388
JA
1258.I variable
1259is a parameter denoted by a
1260.IR name .
f73dda09
JA
1261A variable has a \fIvalue\fP and zero or more \fIattributes\fP.
1262Attributes are assigned using the
1263.B declare
1264builtin command (see
1265.B declare
1266below in
1267.SM
1268.BR "SHELL BUILTIN COMMANDS" ).
726f6388
JA
1269.PP
1270A parameter is set if it has been assigned a value. The null string is
1271a valid value. Once a variable is set, it may be unset only by using
1272the
1273.B unset
1274builtin command (see
1275.SM
1276.B SHELL BUILTIN COMMANDS
1277below).
1278.PP
1279A
1280.I variable
1281may be assigned to by a statement of the form
1282.RS
1283.PP
1284\fIname\fP=[\fIvalue\fP]
1285.RE
1286.PP
1287If
1288.I value
1289is not given, the variable is assigned the null string. All
1290.I values
bb70624e
JA
1291undergo tilde expansion, parameter and variable expansion,
1292command substitution, arithmetic expansion, and quote
ccc6cda3
JA
1293removal (see
1294.SM
1295.B EXPANSION
1296below). If the variable has its
cce855bc 1297.B integer
f73dda09 1298attribute set, then
726f6388 1299.I value
b80f6443 1300is evaluated as an arithmetic expression even if the $((...)) expansion is
cce855bc 1301not used (see
ccc6cda3
JA
1302.B "Arithmetic Expansion"
1303below).
74091dd4 1304Word splitting and pathname expansion are not performed.
f73dda09 1305Assignment statements may also appear as arguments to the
b80f6443 1306.BR alias ,
f73dda09
JA
1307.BR declare ,
1308.BR typeset ,
1309.BR export ,
1310.BR readonly ,
1311and
1312.B local
a0c0a00f 1313builtin commands (\fIdeclaration\fP commands).
ac50fbac
CR
1314When in \fIposix mode\fP, these builtins may appear in a command after
1315one or more instances of the \fBcommand\fP builtin and retain these
1316assignment statement properties.
95732b49
JA
1317.PP
1318In the context where an assignment statement is assigning a value
1319to a shell variable or array index, the += operator can be used to
1320append to or add to the variable's previous value.
a0c0a00f
CR
1321This includes arguments to builtin commands such as \fBdeclare\fP that
1322accept assignment statements (\fIdeclaration\fP commands).
74091dd4 1323When += is applied to a variable for which the \fBinteger\fP attribute has been
95732b49
JA
1324set, \fIvalue\fP is evaluated as an arithmetic expression and added to the
1325variable's current value, which is also evaluated.
1326When += is applied to an array variable using compound assignment (see
1327.B Arrays
1328below), the
1329variable's value is not unset (as it is when using =), and new values are
3185942a
JA
1330appended to the array beginning at one greater than the array's maximum index
1331(for indexed arrays) or added as additional key\-value pairs in an
1332associative array.
95732b49
JA
1333When applied to a string-valued variable, \fIvalue\fP is expanded and
1334appended to the variable's value.
ac50fbac
CR
1335.PP
1336A variable can be assigned the \fInameref\fP attribute using the
1337\fB\-n\fP option to the \fBdeclare\fP or \fBlocal\fP builtin commands
1338(see the descriptions of \fBdeclare\fP and \fBlocal\fP below)
1339to create a \fInameref\fP, or a reference to another variable.
1340This allows variables to be manipulated indirectly.
a0c0a00f
CR
1341Whenever the nameref variable is referenced, assigned to, unset, or has
1342its attributes modified (other than using or changing the \fInameref\fP
1343attribute itself), the
1344operation is actually performed on the variable specified by the nameref
1345variable's value.
ac50fbac
CR
1346A nameref is commonly used within shell functions to refer to a variable
1347whose name is passed as an argument to the function.
1348For instance, if a variable name is passed to a shell function as its first
1349argument, running
1350.sp .5
1351.RS
1352.if t \f(CWdeclare -n ref=$1\fP
1353.if n declare -n ref=$1
1354.RE
1355.sp .5
1356inside the function creates a nameref variable \fBref\fP whose value is
1357the variable name passed as the first argument.
a0c0a00f
CR
1358References and assignments to \fBref\fP, and changes to its attributes,
1359are treated as references, assignments, and attribute modifications
1360to the variable whose name was passed as \fB$1\fP.
ac50fbac
CR
1361If the control variable in a \fBfor\fP loop has the nameref attribute,
1362the list of words can be a list of shell variables, and a name reference
1363will be established for each word in the list, in turn, when the loop is
1364executed.
a0c0a00f 1365Array variables cannot be given the \fBnameref\fP attribute.
ac50fbac
CR
1366However, nameref variables can reference array variables and subscripted
1367array variables.
1368Namerefs can be unset using the \fB\-n\fP option to the \fBunset\fP builtin.
1369Otherwise, if \fBunset\fP is executed with the name of a nameref variable
1370as an argument, the variable referenced by the nameref variable will be unset.
726f6388 1371.SS Positional Parameters
726f6388
JA
1372A
1373.I positional parameter
1374is a parameter denoted by one or more
1375digits, other than the single digit 0. Positional parameters are
1376assigned from the shell's arguments when it is invoked,
1377and may be reassigned using the
1378.B set
1379builtin command. Positional parameters may not be assigned to
1380with assignment statements. The positional parameters are
1381temporarily replaced when a shell function is executed (see
1382.SM
1383.B FUNCTIONS
1384below).
1385.PP
1386When a positional parameter consisting of more than a single
1387digit is expanded, it must be enclosed in braces (see
1388.SM
1389.B EXPANSION
1390below).
1391.SS Special Parameters
726f6388
JA
1392The shell treats several parameters specially. These parameters may
1393only be referenced; assignment to them is not allowed.
1394.PD 0
1395.TP
1396.B *
ac50fbac
CR
1397Expands to the positional parameters, starting from one.
1398When the expansion is not within double quotes, each positional parameter
1399expands to a separate word.
1400In contexts where it is performed, those words
1401are subject to further word splitting and pathname expansion.
1402When the expansion occurs within double quotes, it expands to a single word
a0c0a00f 1403with the value of each parameter separated by the first character of the
726f6388
JA
1404.SM
1405.B IFS
cce855bc
JA
1406special variable. That is, "\fB$*\fP" is equivalent
1407to "\fB$1\fP\fIc\fP\fB$2\fP\fIc\fP\fB...\fP", where
726f6388
JA
1408.I c
1409is the first character of the value of the
1410.SM
1411.B IFS
1412variable. If
1413.SM
1414.B IFS
d166f048
JA
1415is unset, the parameters are separated by spaces.
1416If
1417.SM
1418.B IFS
1419is null, the parameters are joined without intervening separators.
726f6388
JA
1420.TP
1421.B @
d233b485
CR
1422Expands to the positional parameters, starting from one.
1423In contexts where word splitting is performed, this expands each
1424positional parameter to a separate word; if not within double
1425quotes, these words are subject to word splitting.
1426In contexts where word splitting is not performed,
1427this expands to a single word
1428with each positional parameter separated by a space.
1429When the
cce855bc
JA
1430expansion occurs within double quotes, each parameter expands to a
1431separate word. That is, "\fB$@\fP" is equivalent to
1432"\fB$1\fP" "\fB$2\fP" ...
95732b49
JA
1433If the double-quoted expansion occurs within a word, the expansion of
1434the first parameter is joined with the beginning part of the original
1435word, and the expansion of the last parameter is joined with the last
1436part of the original word.
a0c0a00f 1437When there are no positional parameters, "\fB$@\fP" and
726f6388
JA
1438.B $@
1439expand to nothing (i.e., they are removed).
1440.TP
1441.B #
1442Expands to the number of positional parameters in decimal.
1443.TP
1444.B ?
3185942a 1445Expands to the exit status of the most recently executed foreground
726f6388
JA
1446pipeline.
1447.TP
1448.B \-
8868edaf 1449Expands to the current option flags as specified upon invocation,
726f6388
JA
1450by the
1451.B set
1452builtin command, or those set by the shell itself
1453(such as the
1454.B \-i
cce855bc 1455option).
726f6388
JA
1456.TP
1457.B $
74091dd4 1458Expands to the process ID of the shell. In a subshell, it
726f6388
JA
1459expands to the process ID of the current shell, not the
1460subshell.
1461.TP
1462.B !
ac50fbac
CR
1463Expands to the process ID of the job most recently placed into the
1464background, whether executed as an asynchronous command or using
1465the \fBbg\fP builtin (see
1466.SM
1467.B "JOB CONTROL"
1468below).
726f6388
JA
1469.TP
1470.B 0
1471Expands to the name of the shell or shell script. This is set at
1472shell initialization. If
1473.B bash
1474is invoked with a file of commands,
1475.B $0
1476is set to the name of that file. If
1477.B bash
1478is started with the
1479.B \-c
1480option, then
1481.B $0
1482is set to the first argument after the string to be
1483executed, if one is present. Otherwise, it is set
ac50fbac 1484to the filename used to invoke
726f6388
JA
1485.BR bash ,
1486as given by argument zero.
8868edaf
CR
1487.PD
1488.SS Shell Variables
1489The following variables are set by the shell:
1490.PP
1491.PD 0
726f6388
JA
1492.TP
1493.B _
8868edaf 1494At shell startup, set to the pathname used to invoke the
95732b49
JA
1495shell or shell script being executed as passed in the environment
1496or argument list.
d233b485
CR
1497Subsequently, expands to the last argument to the previous simple
1498command executed in the foreground, after expansion.
95732b49
JA
1499Also set to the full pathname used to invoke each command executed
1500and placed in the environment exported to that command.
ccc6cda3
JA
1501When checking mail, this parameter holds the name of the mail file
1502currently being checked.
726f6388 1503.TP
726f6388 1504.B BASH
ac50fbac 1505Expands to the full filename used to invoke this instance of
726f6388
JA
1506.BR bash .
1507.TP
0001803f
CR
1508.B BASHOPTS
1509A colon-separated list of enabled shell options. Each word in
1510the list is a valid argument for the
1511.B \-s
1512option to the
1513.B shopt
1514builtin command (see
1515.SM
1516.B "SHELL BUILTIN COMMANDS"
1517below). The options appearing in
1518.SM
1519.B BASHOPTS
1520are those reported as
1521.I on
1522by \fBshopt\fP.
1523If this variable is in the environment when
1524.B bash
1525starts up, each shell option in the list will be enabled before
1526reading any startup files.
1527This variable is read-only.
1528.TP
3185942a 1529.B BASHPID
495aee44 1530Expands to the process ID of the current \fBbash\fP process.
3185942a
JA
1531This differs from \fB$$\fP under certain circumstances, such as subshells
1532that do not require \fBbash\fP to be re-initialized.
d233b485
CR
1533Assignments to
1534.SM
1535.B BASHPID
1536have no effect.
1537If
1538.B BASHPID
1539is unset, it loses its special properties, even if it is
1540subsequently reset.
3185942a
JA
1541.TP
1542.B BASH_ALIASES
1543An associative array variable whose members correspond to the internal
495aee44 1544list of aliases as maintained by the \fBalias\fP builtin.
a0c0a00f
CR
1545Elements added to this array appear in the alias list; however,
1546unsetting array elements currently does not cause aliases to be removed
1547from the alias list.
1548If
1549.B BASH_ALIASES
1550is unset, it loses its special properties, even if it is
1551subsequently reset.
3185942a 1552.TP
b80f6443
JA
1553.B BASH_ARGC
1554An array variable whose values are the number of parameters in each
3185942a 1555frame of the current \fBbash\fP execution call stack.
95732b49 1556The number of
b80f6443 1557parameters to the current subroutine (shell function or script executed
95732b49
JA
1558with \fB.\fP or \fBsource\fP) is at the top of the stack.
1559When a subroutine is executed, the number of parameters passed is pushed onto
0001803f
CR
1560.SM
1561.BR BASH_ARGC .
1562The shell sets
1563.SM
1564.B BASH_ARGC
1565only when in extended debugging mode (see the description of the
95732b49
JA
1566.B extdebug
1567option to the
1568.B shopt
d233b485
CR
1569builtin below).
1570Setting \fBextdebug\fP after the shell has started to execute a script,
1571or referencing this variable when \fBextdebug\fP is not set,
1572may result in inconsistent values.
b80f6443
JA
1573.TP
1574.B BASH_ARGV
3185942a 1575An array variable containing all of the parameters in the current \fBbash\fP
b80f6443
JA
1576execution call stack. The final parameter of the last subroutine call
1577is at the top of the stack; the first parameter of the initial call is
1578at the bottom. When a subroutine is executed, the parameters supplied
0001803f
CR
1579are pushed onto
1580.SM
1581.BR BASH_ARGV .
1582The shell sets
1583.SM
1584.B BASH_ARGV
1585only when in extended debugging mode
95732b49
JA
1586(see the description of the
1587.B extdebug
1588option to the
1589.B shopt
d233b485
CR
1590builtin below).
1591Setting \fBextdebug\fP after the shell has started to execute a script,
1592or referencing this variable when \fBextdebug\fP is not set,
1593may result in inconsistent values.
1594.TP
1595.B BASH_ARGV0
1596When referenced, this variable expands to the name of the shell or shell
1597script (identical to
1598.BR $0 ;
1599see the description of special parameter 0 above).
1600Assignment to
1601.B BASH_ARGV0
1602causes the value assigned to also be assigned to \fB$0\fP.
1603If
1604.B BASH_ARGV0
1605is unset, it loses its special properties, even if it is
1606subsequently reset.
b80f6443 1607.TP
3185942a
JA
1608.B BASH_CMDS
1609An associative array variable whose members correspond to the internal
1610hash table of commands as maintained by the \fBhash\fP builtin.
a0c0a00f
CR
1611Elements added to this array appear in the hash table; however,
1612unsetting array elements currently does not cause command names to be removed
1613from the hash table.
1614If
1615.B BASH_CMDS
1616is unset, it loses its special properties, even if it is
1617subsequently reset.
3185942a 1618.TP
b80f6443
JA
1619.B BASH_COMMAND
1620The command currently being executed or about to be executed, unless the
1621shell is executing a command as the result of a trap,
1622in which case it is the command executing at the time of the trap.
8868edaf
CR
1623If
1624.B BASH_COMMAND
1625is unset, it loses its special properties, even if it is
1626subsequently reset.
b80f6443
JA
1627.TP
1628.B BASH_EXECUTION_STRING
1629The command argument to the \fB\-c\fP invocation option.
1630.TP
1631.B BASH_LINENO
1632An array variable whose members are the line numbers in source files
495aee44 1633where each corresponding member of
0001803f 1634.SM
495aee44
CR
1635.B FUNCNAME
1636was invoked.
b80f6443 1637\fB${BASH_LINENO[\fP\fI$i\fP\fB]}\fP is the line number in the source
495aee44
CR
1638file (\fB${BASH_SOURCE[\fP\fI$i+1\fP\fB]}\fP) where
1639\fB${FUNCNAME[\fP\fI$i\fP\fB]}\fP was called
3185942a
JA
1640(or \fB${BASH_LINENO[\fP\fI$i-1\fP\fB]}\fP if referenced within another
1641shell function).
0001803f
CR
1642Use
1643.SM
1644.B LINENO
1645to obtain the current line number.
b80f6443 1646.TP
a0c0a00f
CR
1647.B BASH_LOADABLES_PATH
1648A colon-separated list of directories in which the shell looks for
1649dynamically loadable builtins specified by the
1650.B enable
1651command.
1652.TP
b80f6443
JA
1653.B BASH_REMATCH
1654An array variable whose members are assigned by the \fB=~\fP binary
1655operator to the \fB[[\fP conditional command.
1656The element with index 0 is the portion of the string
1657matching the entire regular expression.
1658The element with index \fIn\fP is the portion of the
1659string matching the \fIn\fPth parenthesized subexpression.
b80f6443
JA
1660.TP
1661.B BASH_SOURCE
495aee44
CR
1662An array variable whose members are the source filenames
1663where the corresponding shell function names in the
0001803f
CR
1664.SM
1665.B FUNCNAME
495aee44
CR
1666array variable are defined.
1667The shell function
1668\fB${FUNCNAME[\fP\fI$i\fP\fB]}\fP is defined in the file
1669\fB${BASH_SOURCE[\fP\fI$i\fP\fB]}\fP and called from
1670\fB${BASH_SOURCE[\fP\fI$i+1\fP\fB]}\fP.
b80f6443
JA
1671.TP
1672.B BASH_SUBSHELL
ac50fbac
CR
1673Incremented by one within each subshell or subshell environment when
1674the shell begins executing in that environment.
b80f6443 1675The initial value is 0.
8868edaf
CR
1676If
1677.B BASH_SUBSHELL
1678is unset, it loses its special properties, even if it is
1679subsequently reset.
b80f6443 1680.TP
ccc6cda3 1681.B BASH_VERSINFO
cce855bc
JA
1682A readonly array variable whose members hold version information for
1683this instance of
ccc6cda3
JA
1684.BR bash .
1685The values assigned to the array members are as follows:
1686.sp .5
1687.RS
ccc6cda3
JA
1688.TP 24
1689.B BASH_VERSINFO[\fR0\fP]
1690The major version number (the \fIrelease\fP).
1691.TP
1692.B BASH_VERSINFO[\fR1\fP]
1693The minor version number (the \fIversion\fP).
1694.TP
1695.B BASH_VERSINFO[\fR2\fP]
1696The patch level.
1697.TP
1698.B BASH_VERSINFO[\fR3\fP]
1699The build version.
1700.TP
1701.B BASH_VERSINFO[\fR4\fP]
1702The release status (e.g., \fIbeta1\fP).
1703.TP
1704.B BASH_VERSINFO[\fR5\fP]
0001803f
CR
1705The value of
1706.SM
1707.BR MACHTYPE .
ccc6cda3
JA
1708.RE
1709.TP
f73dda09
JA
1710.B BASH_VERSION
1711Expands to a string describing the version of this instance of
1712.BR bash .
726f6388 1713.TP
f73dda09
JA
1714.B COMP_CWORD
1715An index into \fB${COMP_WORDS}\fP of the word containing the current
1716cursor position.
1717This variable is available only in shell functions invoked by the
1718programmable completion facilities (see \fBProgrammable Completion\fP
1719below).
1720.TP
3185942a
JA
1721.B COMP_KEY
1722The key (or final key of a key sequence) used to invoke the current
1723completion function.
1724.TP
f73dda09
JA
1725.B COMP_LINE
1726The current command line.
1727This variable is available only in shell functions and external
1728commands invoked by the
1729programmable completion facilities (see \fBProgrammable Completion\fP
1730below).
1731.TP
1732.B COMP_POINT
1733The index of the current cursor position relative to the beginning of
1734the current command.
1735If the current cursor position is at the end of the current command,
1736the value of this variable is equal to \fB${#COMP_LINE}\fP.
1737This variable is available only in shell functions and external
1738commands invoked by the
1739programmable completion facilities (see \fBProgrammable Completion\fP
1740below).
1741.TP
3185942a
JA
1742.B COMP_TYPE
1743Set to an integer value corresponding to the type of completion attempted
1744that caused a completion function to be called:
1745\fITAB\fP, for normal completion,
1746\fI?\fP, for listing completions after successive tabs,
1747\fI!\fP, for listing alternatives on partial word completion,
1748\fI@\fP, to list completions if the word is not unmodified,
1749or
1750\fI%\fP, for menu completion.
1751This variable is available only in shell functions and external
1752commands invoked by the
1753programmable completion facilities (see \fBProgrammable Completion\fP
1754below).
1755.TP
b80f6443 1756.B COMP_WORDBREAKS
17345e5a 1757The set of characters that the \fBreadline\fP library treats as word
b80f6443
JA
1758separators when performing word completion.
1759If
1760.SM
1761.B COMP_WORDBREAKS
1762is unset, it loses its special properties, even if it is
1763subsequently reset.
1764.TP
f73dda09
JA
1765.B COMP_WORDS
1766An array variable (see \fBArrays\fP below) consisting of the individual
1767words in the current command line.
17345e5a 1768The line is split into words as \fBreadline\fP would split it, using
0001803f
CR
1769.SM
1770.B COMP_WORDBREAKS
1771as described above.
f73dda09
JA
1772This variable is available only in shell functions invoked by the
1773programmable completion facilities (see \fBProgrammable Completion\fP
1774below).
1775.TP
495aee44
CR
1776.B COPROC
1777An array variable (see \fBArrays\fP below) created to hold the file descriptors
1778for output from and input to an unnamed coprocess (see \fBCoprocesses\fP
1779above).
1780.TP
f73dda09
JA
1781.B DIRSTACK
1782An array variable (see
1783.B Arrays
1784below) containing the current contents of the directory stack.
1785Directories appear in the stack in the order they are displayed by the
1786.B dirs
1787builtin.
1788Assigning to members of this array variable may be used to modify
1789directories already in the stack, but the
1790.B pushd
1791and
1792.B popd
1793builtins must be used to add and remove directories.
1794Assignment to this variable will not change the current directory.
726f6388
JA
1795If
1796.SM
f73dda09 1797.B DIRSTACK
726f6388
JA
1798is unset, it loses its special properties, even if it is
1799subsequently reset.
1800.TP
d233b485
CR
1801.B EPOCHREALTIME
1802Each time this parameter is referenced, it expands to the number of seconds
1803since the Unix Epoch (see \fItime\fP\fR(3)\fP) as a floating point value
1804with micro-second granularity.
1805Assignments to
1806.SM
1807.B EPOCHREALTIME
1808are ignored.
1809If
1810.SM
1811.B EPOCHREALTIME
1812is unset, it loses its special properties, even if it is
1813subsequently reset.
1814.TP
1815.B EPOCHSECONDS
1816Each time this parameter is referenced, it expands to the number of seconds
1817since the Unix Epoch (see \fItime\fP\fR(3)\fP).
1818Assignments to
1819.SM
1820.B EPOCHSECONDS
1821are ignored.
1822If
1823.SM
1824.B EPOCHSECONDS
1825is unset, it loses its special properties, even if it is
1826subsequently reset.
1827.TP
f73dda09
JA
1828.B EUID
1829Expands to the effective user ID of the current user, initialized at
1830shell startup. This variable is readonly.
1831.TP
1832.B FUNCNAME
b80f6443
JA
1833An array variable containing the names of all shell functions
1834currently in the execution call stack.
1835The element with index 0 is the name of any currently-executing
1836shell function.
495aee44 1837The bottom-most element (the one with the highest index) is
3185942a
JA
1838.if t \f(CW"main"\fP.
1839.if n "main".
f73dda09
JA
1840This variable exists only when a shell function is executing.
1841Assignments to
726f6388 1842.SM
f73dda09 1843.B FUNCNAME
a0c0a00f 1844have no effect.
726f6388
JA
1845If
1846.SM
f73dda09 1847.B FUNCNAME
726f6388
JA
1848is unset, it loses its special properties, even if it is
1849subsequently reset.
495aee44
CR
1850.if t .sp 0.5
1851.if n .sp 1
1852This variable can be used with \fBBASH_LINENO\fP and \fBBASH_SOURCE\fP.
1853Each element of \fBFUNCNAME\fP has corresponding elements in
1854\fBBASH_LINENO\fP and \fBBASH_SOURCE\fP to describe the call stack.
1855For instance, \fB${FUNCNAME[\fP\fI$i\fP\fB]}\fP was called from the file
1856\fB${BASH_SOURCE[\fP\fI$i+1\fP\fB]}\fP at line number
1857\fB${BASH_LINENO[\fP\fI$i\fP\fB]}\fP.
1858The \fBcaller\fP builtin displays the current call stack using this
1859information.
726f6388 1860.TP
f73dda09
JA
1861.B GROUPS
1862An array variable containing the list of groups of which the current
1863user is a member.
a0c0a00f 1864Assignments to
f73dda09
JA
1865.SM
1866.B GROUPS
a0c0a00f 1867have no effect.
726f6388
JA
1868If
1869.SM
f73dda09 1870.B GROUPS
726f6388
JA
1871is unset, it loses its special properties, even if it is
1872subsequently reset.
1873.TP
1874.B HISTCMD
1875The history number, or index in the history list, of the current
ccc6cda3 1876command.
8868edaf
CR
1877Assignments to
1878.SM
1879.B HISTCMD
1880are ignored.
ccc6cda3 1881If
726f6388
JA
1882.SM
1883.B HISTCMD
1884is unset, it loses its special properties, even if it is
1885subsequently reset.
1886.TP
f73dda09
JA
1887.B HOSTNAME
1888Automatically set to the name of the current host.
bb70624e 1889.TP
f73dda09
JA
1890.B HOSTTYPE
1891Automatically set to a string that uniquely
1892describes the type of machine on which
1893.B bash
1894is executing.
1895The default is system-dependent.
1896.TP
1897.B LINENO
1898Each time this parameter is referenced, the shell substitutes
1899a decimal number representing the current sequential line number
1900(starting with 1) within a script or function. When not in a
1901script or function, the value substituted is not guaranteed to
1902be meaningful.
ccc6cda3
JA
1903If
1904.SM
f73dda09 1905.B LINENO
ccc6cda3
JA
1906is unset, it loses its special properties, even if it is
1907subsequently reset.
1908.TP
f73dda09
JA
1909.B MACHTYPE
1910Automatically set to a string that fully describes the system
1911type on which
1912.B bash
1913is executing, in the standard GNU \fIcpu-company-system\fP format.
1914The default is system-dependent.
1915.TP
495aee44
CR
1916.B MAPFILE
1917An array variable (see \fBArrays\fP below) created to hold the text
1918read by the \fBmapfile\fP builtin when no variable name is supplied.
1919.TP
f73dda09
JA
1920.B OLDPWD
1921The previous working directory as set by the
1922.B cd
1923command.
ccc6cda3 1924.TP
726f6388
JA
1925.B OPTARG
1926The value of the last option argument processed by the
1927.B getopts
1928builtin command (see
1929.SM
1930.B SHELL BUILTIN COMMANDS
1931below).
1932.TP
1933.B OPTIND
1934The index of the next argument to be processed by the
1935.B getopts
1936builtin command (see
1937.SM
1938.B SHELL BUILTIN COMMANDS
1939below).
1940.TP
726f6388
JA
1941.B OSTYPE
1942Automatically set to a string that
1943describes the operating system on which
1944.B bash
ccc6cda3
JA
1945is executing.
1946The default is system-dependent.
1947.TP
f73dda09
JA
1948.B PIPESTATUS
1949An array variable (see
1950.B Arrays
1951below) containing a list of exit status values from the processes
1952in the most-recently-executed foreground pipeline (which may
1953contain only a single command).
ccc6cda3 1954.TP
f73dda09
JA
1955.B PPID
1956The process ID of the shell's parent. This variable is readonly.
1957.TP
1958.B PWD
1959The current working directory as set by the
1960.B cd
1961command.
1962.TP
1963.B RANDOM
8868edaf
CR
1964Each time this parameter is referenced, it expands to a random integer
1965between 0 and 32767.
1966Assigning
f73dda09
JA
1967a value to
1968.SM
8868edaf
CR
1969.BR RANDOM
1970initializes (seeds) the sequence of random numbers.
f73dda09
JA
1971If
1972.SM
1973.B RANDOM
1974is unset, it loses its special properties, even if it is
1975subsequently reset.
1976.TP
74091dd4
CR
1977.B READLINE_ARGUMENT
1978Any numeric argument given to a readline command that was defined using
1979.if t \f(CWbind -x\fP
1980.if n "bind -x"
1981(see
1982.SM
1983.B "SHELL BUILTIN COMMANDS"
1984below)
1985when it was invoked.
1986.TP
495aee44
CR
1987.B READLINE_LINE
1988The contents of the
1989.B readline
1990line buffer, for use with
1991.if t \f(CWbind -x\fP
1992.if n "bind -x"
1993(see
1994.SM
1995.B "SHELL BUILTIN COMMANDS"
1996below).
1997.TP
8868edaf
CR
1998.B READLINE_MARK
1999The position of the mark (saved insertion point) in the
2000.B readline
2001line buffer, for use with
2002.if t \f(CWbind -x\fP
2003.if n "bind -x"
2004(see
2005.SM
2006.B "SHELL BUILTIN COMMANDS"
2007below).
2008The characters between the insertion point and the mark are often
2009called the \fIregion\fP.
2010.TP
495aee44
CR
2011.B READLINE_POINT
2012The position of the insertion point in the
2013.B readline
2014line buffer, for use with
2015.if t \f(CWbind -x\fP
2016.if n "bind -x"
2017(see
2018.SM
2019.B "SHELL BUILTIN COMMANDS"
2020below).
2021.TP
f73dda09
JA
2022.B REPLY
2023Set to the line of input read by the
2024.B read
2025builtin command when no arguments are supplied.
2026.TP
2027.B SECONDS
2028Each time this parameter is
74091dd4
CR
2029referenced, it expands to the number of seconds since shell invocation.
2030If a value is assigned to
f73dda09
JA
2031.SM
2032.BR SECONDS ,
2033the value returned upon subsequent
2034references is
2035the number of seconds since the assignment plus the value assigned.
74091dd4 2036The number of seconds at shell invocation and the current time are always
8868edaf 2037determined by querying the system clock.
f73dda09
JA
2038If
2039.SM
2040.B SECONDS
2041is unset, it loses its special properties, even if it is
2042subsequently reset.
2043.TP
2044.B SHELLOPTS
2045A colon-separated list of enabled shell options. Each word in
2046the list is a valid argument for the
2047.B \-o
2048option to the
2049.B set
2050builtin command (see
2051.SM
2052.B "SHELL BUILTIN COMMANDS"
2053below). The options appearing in
ccc6cda3
JA
2054.SM
2055.B SHELLOPTS
2056are those reported as
2057.I on
2058by \fBset \-o\fP.
2059If this variable is in the environment when
2060.B bash
2061starts up, each shell option in the list will be enabled before
2062reading any startup files.
2063This variable is read-only.
bb70624e 2064.TP
f73dda09
JA
2065.B SHLVL
2066Incremented by one each time an instance of
2067.B bash
2068is started.
bb70624e 2069.TP
8868edaf
CR
2070.B SRANDOM
2071This variable expands to a 32-bit pseudo-random number each time it is
2072referenced. The random number generator is not linear on systems that
2073support \f(CW/dev/urandom\fP or \fIarc4random\fP, so each returned number
2074has no relationship to the numbers preceding it.
2075The random number generator cannot be seeded, so assignments to this
2076variable have no effect.
2077If
2078.SM
2079.B SRANDOM
2080is unset, it loses its special properties,
2081even if it is subsequently reset.
2082.TP
f73dda09
JA
2083.B UID
2084Expands to the user ID of the current user, initialized at shell startup.
2085This variable is readonly.
726f6388
JA
2086.PD
2087.PP
2088The following variables are used by the shell. In some cases,
2089.B bash
2090assigns a default value to a variable; these cases are noted
2091below.
2092.PP
2093.PD 0
2094.TP
ac50fbac
CR
2095.B BASH_COMPAT
2096The value is used to set the shell's compatibility level.
8868edaf
CR
2097See
2098.SM
74091dd4 2099.B "SHELL COMPATIBILITY MODE"
8868edaf 2100below for a description of the various compatibility
ac50fbac
CR
2101levels and their effects.
2102The value may be a decimal number (e.g., 4.2) or an integer (e.g., 42)
2103corresponding to the desired compatibility level.
2104If \fBBASH_COMPAT\fP is unset or set to the empty string, the compatibility
2105level is set to the default for the current version.
2106If \fBBASH_COMPAT\fP is set to a value that is not one of the valid
2107compatibility levels, the shell prints an error message and sets the
2108compatibility level to the default for the current version.
8868edaf
CR
2109The valid values correspond to the compatibility levels
2110described below under
2111.SM
74091dd4 2112.BR "SHELL COMPATIBILITY MODE" .
8868edaf
CR
2113For example, 4.2 and 42 are valid values that correspond
2114to the \fBcompat42\fP \fBshopt\fP option
2115and set the compatibility level to 42.
ac50fbac
CR
2116The current version is also a valid value.
2117.TP
d166f048 2118.B BASH_ENV
726f6388
JA
2119If this parameter is set when \fBbash\fP is executing a shell script,
2120its value is interpreted as a filename containing commands to
2121initialize the shell, as in
cce855bc 2122.IR ~/.bashrc .
726f6388
JA
2123The value of
2124.SM
d166f048 2125.B BASH_ENV
726f6388 2126is subjected to parameter expansion, command substitution, and arithmetic
ac50fbac 2127expansion before being interpreted as a filename.
726f6388
JA
2128.SM
2129.B PATH
ac50fbac 2130is not used to search for the resultant filename.
726f6388 2131.TP
0001803f
CR
2132.B BASH_XTRACEFD
2133If set to an integer corresponding to a valid file descriptor, \fBbash\fP
2134will write the trace output generated when
2135.if t \f(CWset -x\fP
2136.if n \fIset -x\fP
2137is enabled to that file descriptor.
2138The file descriptor is closed when
2139.SM
2140.B BASH_XTRACEFD
2141is unset or assigned a new value.
2142Unsetting
2143.SM
2144.B BASH_XTRACEFD
2145or assigning it the empty string causes the
2146trace output to be sent to the standard error.
2147Note that setting
2148.SM
2149.B BASH_XTRACEFD
2150to 2 (the standard error file
2151descriptor) and then unsetting it will result in the standard error
2152being closed.
2153.TP
495aee44
CR
2154.B CDPATH
2155The search path for the
2156.B cd
2157command.
2158This is a colon-separated list of directories in which the shell looks
2159for destination directories specified by the
2160.B cd
2161command.
2162A sample value is
2163.if t \f(CW".:~:/usr"\fP.
2164.if n ".:~:/usr".
2165.TP
ac50fbac
CR
2166.B CHILD_MAX
2167Set the number of exited child status values for the shell to remember.
2168Bash will not allow this value to be decreased below a POSIX-mandated
2169minimum, and there is a maximum value (currently 8192) that this may
2170not exceed.
2171The minimum value is system-dependent.
2172.TP
f73dda09 2173.B COLUMNS
495aee44 2174Used by the \fBselect\fP compound command to determine the terminal width
ac50fbac
CR
2175when printing selection lists.
2176Automatically set if the
2177.B checkwinsize
2178option is enabled or in an interactive shell upon receipt of a
495aee44
CR
2179.SM
2180.BR SIGWINCH .
726f6388 2181.TP
f73dda09
JA
2182.B COMPREPLY
2183An array variable from which \fBbash\fP reads the possible completions
2184generated by a shell function invoked by the programmable completion
2185facility (see \fBProgrammable Completion\fP below).
ac50fbac 2186Each array element contains one possible completion.
726f6388 2187.TP
b80f6443
JA
2188.B EMACS
2189If \fBbash\fP finds this variable in the environment when the shell starts
2190with value
2191.if t \f(CWt\fP,
2192.if n "t",
495aee44 2193it assumes that the shell is running in an Emacs shell buffer and disables
b80f6443
JA
2194line editing.
2195.TP
495aee44 2196.B ENV
8868edaf 2197Expanded and executed similarly to
495aee44 2198.SM
8868edaf
CR
2199.B BASH_ENV
2200(see \fBINVOCATION\fP above)
2201when an interactive shell is invoked in \fIposix mode\fP.
495aee44 2202.TP
a0c0a00f
CR
2203.B EXECIGNORE
2204A colon-separated list of shell patterns (see \fBPattern Matching\fP)
2205defining the list of filenames to be ignored by command search using
2206\fBPATH\fP.
2207Files whose full pathnames match one of these patterns are not considered
2208executable files for the purposes of completion and command execution
2209via \fBPATH\fP lookup.
2210This does not affect the behavior of the \fB[\fP, \fBtest\fP, and \fB[[\fP
2211commands.
2212Full pathnames in the command hash table are not subject to \fBEXECIGNORE\fP.
2213Use this variable to ignore shared library files that have the executable
2214bit set, but are not executable files.
2215The pattern matching honors the setting of the \fBextglob\fP shell
2216option.
2217.TP
f73dda09
JA
2218.B FCEDIT
2219The default editor for the
2220.B fc
2221builtin command.
726f6388 2222.TP
f73dda09
JA
2223.B FIGNORE
2224A colon-separated list of suffixes to ignore when performing
2225filename completion (see
726f6388 2226.SM
f73dda09
JA
2227.B READLINE
2228below).
8868edaf 2229A filename whose suffix matches one of the entries in
726f6388 2230.SM
f73dda09
JA
2231.B FIGNORE
2232is excluded from the list of matched filenames.
7117c2d2
JA
2233A sample value is
2234.if t \f(CW".o:~"\fP.
2235.if n ".o:~".
ccc6cda3 2236.TP
495aee44
CR
2237.B FUNCNEST
2238If set to a numeric value greater than 0, defines a maximum function
2239nesting level. Function invocations that exceed this nesting level
2240will cause the current command to abort.
2241.TP
f73dda09 2242.B GLOBIGNORE
d233b485 2243A colon-separated list of patterns defining the set of file names to
f73dda09 2244be ignored by pathname expansion.
d233b485 2245If a file name matched by a pathname expansion pattern also matches one
f73dda09 2246of the patterns in
726f6388 2247.SM
f73dda09
JA
2248.BR GLOBIGNORE ,
2249it is removed from the list of matches.
2250.TP
2251.B HISTCONTROL
b80f6443
JA
2252A colon-separated list of values controlling how commands are saved on
2253the history list.
2254If the list of values includes
f73dda09
JA
2255.IR ignorespace ,
2256lines which begin with a
2257.B space
b80f6443 2258character are not saved in the history list.
a0c0a00f 2259A value of
b80f6443
JA
2260.I ignoredups
2261causes lines matching the previous history entry to not be saved.
f73dda09
JA
2262A value of
2263.I ignoreboth
b80f6443
JA
2264is shorthand for \fIignorespace\fP and \fIignoredups\fP.
2265A value of
d233b485 2266.I erasedups
b80f6443
JA
2267causes all previous lines matching the current line to be removed from
2268the history list before that line is saved.
2269Any value not in the above list is ignored.
0001803f
CR
2270If
2271.SM
2272.B HISTCONTROL
2273is unset, or does not include a valid value,
b80f6443
JA
2274all lines read by the shell parser are saved on the history list,
2275subject to the value of
0001803f 2276.SM
f73dda09
JA
2277.BR HISTIGNORE .
2278The second and subsequent lines of a multi-line compound command are
2279not tested, and are added to the history regardless of the value of
0001803f 2280.SM
f73dda09 2281.BR HISTCONTROL .
726f6388
JA
2282.TP
2283.B HISTFILE
ccc6cda3 2284The name of the file in which command history is saved (see
726f6388
JA
2285.SM
2286.B HISTORY
ccc6cda3 2287below). The default value is \fI~/.bash_history\fP. If unset, the
ac50fbac 2288command history is not saved when a shell exits.
726f6388
JA
2289.TP
2290.B HISTFILESIZE
2291The maximum number of lines contained in the history file. When this
2292variable is assigned a value, the history file is truncated, if
ac50fbac
CR
2293necessary,
2294to contain no more than that number of lines by removing the oldest entries.
2295The history file is also truncated to this size after
2296writing it when a shell exits.
2297If the value is 0, the history file is truncated to zero size.
2298Non-numeric values and numeric values less than zero inhibit truncation.
2299The shell sets the default value to the value of \fBHISTSIZE\fP
2300after reading any startup files.
726f6388 2301.TP
f73dda09
JA
2302.B HISTIGNORE
2303A colon-separated list of patterns used to decide which command lines
2304should be saved on the history list. Each pattern is anchored at the
2305beginning of the line and must match the complete line (no implicit
2306`\fB*\fP' is appended). Each pattern is tested against the line
2307after the checks specified by
0001803f 2308.SM
f73dda09
JA
2309.B HISTCONTROL
2310are applied.
2311In addition to the normal shell pattern matching characters, `\fB&\fP'
2312matches the previous history line. `\fB&\fP' may be escaped using a
2313backslash; the backslash is removed before attempting a match.
2314The second and subsequent lines of a multi-line compound command are
2315not tested, and are added to the history regardless of the value of
0001803f 2316.SM
f73dda09 2317.BR HISTIGNORE .
a0c0a00f
CR
2318The pattern matching honors the setting of the \fBextglob\fP shell
2319option.
f73dda09
JA
2320.TP
2321.B HISTSIZE
2322The number of commands to remember in the command history (see
2323.SM
2324.B HISTORY
ac50fbac
CR
2325below).
2326If the value is 0, commands are not saved in the history list.
2327Numeric values less than zero result in every command being saved
2328on the history list (there is no limit).
2329The shell sets the default value to 500 after reading any startup files.
f73dda09 2330.TP
b80f6443
JA
2331.B HISTTIMEFORMAT
2332If this variable is set and not null, its value is used as a format string
2333for \fIstrftime\fP(3) to print the time stamp associated with each history
2334entry displayed by the \fBhistory\fP builtin.
2335If this variable is set, time stamps are written to the history file so
2336they may be preserved across shell sessions.
3185942a
JA
2337This uses the history comment character to distinguish timestamps from
2338other history lines.
b80f6443 2339.TP
f73dda09
JA
2340.B HOME
2341The home directory of the current user; the default argument for the
2342\fBcd\fP builtin command.
2343The value of this variable is also used when performing tilde expansion.
2344.TP
2345.B HOSTFILE
2346Contains the name of a file in the same format as
2347.FN /etc/hosts
2348that should be read when the shell needs to complete a
2349hostname.
2350The list of possible hostname completions may be changed while the
2351shell is running;
2352the next time hostname completion is attempted after the
2353value is changed,
726f6388 2354.B bash
f73dda09
JA
2355adds the contents of the new file to the existing list.
2356If
726f6388 2357.SM
f73dda09 2358.B HOSTFILE
0001803f
CR
2359is set, but has no value, or does not name a readable file,
2360\fBbash\fP attempts to read
f73dda09
JA
2361.FN /etc/hosts
2362to obtain the list of possible hostname completions.
2363When
726f6388 2364.SM
f73dda09
JA
2365.B HOSTFILE
2366is unset, the hostname list is cleared.
2367.TP
2368.B IFS
2369The
2370.I Internal Field Separator
2371that is used
2372for word splitting after expansion and to
2373split lines into words with the
2374.B read
2375builtin command. The default value is
2376``<space><tab><newline>''.
2377.TP
2378.B IGNOREEOF
2379Controls the
2380action of an interactive shell on receipt of an
2381.SM
2382.B EOF
2383character as the sole input. If set, the value is the number of
2384consecutive
2385.SM
2386.B EOF
2387characters which must be
2388typed as the first characters on an input line before
2389.B bash
2390exits. If the variable exists but does not have a numeric value, or
2391has no value, the default value is 10. If it does not exist,
2392.SM
2393.B EOF
2394signifies the end of input to the shell.
2395.TP
2396.B INPUTRC
2397The filename for the
2398.B readline
2399startup file, overriding the default of
2400.FN ~/.inputrc
2401(see
2402.SM
2403.B READLINE
2404below).
726f6388 2405.TP
d233b485
CR
2406.B INSIDE_EMACS
2407If this variable appears in the environment when the shell starts,
2408\fBbash\fP assumes that it is running inside an Emacs shell buffer
2409and may disable line editing, depending on the value of \fBTERM\fP.
2410.TP
ccc6cda3
JA
2411.B LANG
2412Used to determine the locale category for any category not specifically
2413selected with a variable starting with \fBLC_\fP.
2414.TP
2415.B LC_ALL
0001803f
CR
2416This variable overrides the value of
2417.SM
2418.B LANG
2419and any other
ccc6cda3
JA
2420\fBLC_\fP variable specifying a locale category.
2421.TP
2422.B LC_COLLATE
2423This variable determines the collation order used when sorting the
cce855bc
JA
2424results of pathname expansion, and determines the behavior of range
2425expressions, equivalence classes, and collating sequences within
2426pathname expansion and pattern matching.
2427.TP
2428.B LC_CTYPE
2429This variable determines the interpretation of characters and the
2430behavior of character classes within pathname expansion and pattern
2431matching.
ccc6cda3
JA
2432.TP
2433.B LC_MESSAGES
2434This variable determines the locale used to translate double-quoted
2435strings preceded by a \fB$\fP.
2436.TP
bb70624e
JA
2437.B LC_NUMERIC
2438This variable determines the locale category used for number formatting.
2439.TP
a0c0a00f
CR
2440.B LC_TIME
2441This variable determines the locale category used for data and time
2442formatting.
2443.TP
28ef6c31 2444.B LINES
495aee44 2445Used by the \fBselect\fP compound command to determine the column length
ac50fbac
CR
2446for printing selection lists.
2447Automatically set if the
2448.B checkwinsize
2449option is enabled or in an interactive shell upon receipt of a
0001803f
CR
2450.SM
2451.BR SIGWINCH .
28ef6c31 2452.TP
f73dda09 2453.B MAIL
495aee44 2454If this parameter is set to a file or directory name and the
726f6388 2455.SM
f73dda09
JA
2456.B MAILPATH
2457variable is not set,
726f6388 2458.B bash
495aee44
CR
2459informs the user of the arrival of mail in the specified file or
2460Maildir-format directory.
726f6388 2461.TP
f73dda09
JA
2462.B MAILCHECK
2463Specifies how
2464often (in seconds)
2465.B bash
2466checks for mail. The default is 60 seconds. When it is time to check
2467for mail, the shell does so before displaying the primary prompt.
2468If this variable is unset, or set to a value that is not a number
2469greater than or equal to zero, the shell disables mail checking.
726f6388 2470.TP
f73dda09 2471.B MAILPATH
a0c0a00f 2472A colon-separated list of filenames to be checked for mail.
f73dda09 2473The message to be printed when mail arrives in a particular file
ac50fbac 2474may be specified by separating the filename from the message with a `?'.
f73dda09 2475When used in the text of the message, \fB$_\fP expands to the name of
a0c0a00f 2476the current mailfile.
f73dda09
JA
2477Example:
2478.RS
2479.PP
0628567a 2480\fBMAILPATH\fP=\(aq/var/mail/bfox?"You have mail":~/shell\-mail?"$_ has mail!"\(aq
f73dda09
JA
2481.PP
2482.B Bash
a0c0a00f
CR
2483can be configured to supply
2484a default value for this variable (there is no value by default),
2485but the location of the user
f73dda09
JA
2486mail files that it uses is system dependent (e.g., /var/mail/\fB$USER\fP).
2487.RE
726f6388 2488.TP
f73dda09
JA
2489.B OPTERR
2490If set to the value 1,
2491.B bash
2492displays error messages generated by the
2493.B getopts
2494builtin command (see
726f6388 2495.SM
f73dda09 2496.B SHELL BUILTIN COMMANDS
ccc6cda3 2497below).
726f6388 2498.SM
f73dda09
JA
2499.B OPTERR
2500is initialized to 1 each time the shell is invoked or a shell
2501script is executed.
ccc6cda3 2502.TP
f73dda09
JA
2503.B PATH
2504The search path for commands. It
2505is a colon-separated list of directories in which
2506the shell looks for commands (see
ccc6cda3 2507.SM
f73dda09 2508.B COMMAND EXECUTION
b80f6443 2509below).
0001803f
CR
2510A zero-length (null) directory name in the value of
2511.SM
2512.B PATH
2513indicates the current directory.
b80f6443
JA
2514A null directory name may appear as two adjacent colons, or as an initial
2515or trailing colon.
2516The default path is system-dependent,
f73dda09
JA
2517and is set by the administrator who installs
2518.BR bash .
2519A common value is
a0c0a00f 2520.na
ac50fbac
CR
2521.if t \f(CW/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin\fP.
2522.if n ``/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin''.
a0c0a00f 2523.ad
726f6388 2524.TP
f73dda09
JA
2525.B POSIXLY_CORRECT
2526If this variable is in the environment when \fBbash\fP starts, the shell
2527enters \fIposix mode\fP before reading the startup files, as if the
2528.B \-\-posix
2529invocation option had been supplied. If it is set while the shell is
2530running, \fBbash\fP enables \fIposix mode\fP, as if the command
2531.if t \f(CWset -o posix\fP
2532.if n \fIset -o posix\fP
2533had been executed.
d233b485
CR
2534When the shell enters \fIposix mode\fP, it sets this variable if it was
2535not already set.
726f6388 2536.TP
f73dda09 2537.B PROMPT_COMMAND
8868edaf
CR
2538If this variable is set, and is an array,
2539the value of each set element is executed as a command
2540prior to issuing each primary prompt.
2541If this is set but not an array variable,
2542its value is used as a command to execute instead.
ccc6cda3 2543.TP
3185942a
JA
2544.B PROMPT_DIRTRIM
2545If set to a number greater than zero, the value is used as the number of
0001803f 2546trailing directory components to retain when expanding the \fB\ew\fP and
3185942a
JA
2547\fB\eW\fP prompt string escapes (see
2548.SM
2549.B PROMPTING
2550below). Characters removed are replaced with an ellipsis.
2551.TP
a0c0a00f
CR
2552.B PS0
2553The value of this parameter is expanded (see
2554.SM
2555.B PROMPTING
2556below) and displayed by interactive shells after reading a command
2557and before the command is executed.
2558.TP
f73dda09
JA
2559.B PS1
2560The value of this parameter is expanded (see
2561.SM
2562.B PROMPTING
2563below) and used as the primary prompt string. The default value is
2564``\fB\es\-\ev\e$ \fP''.
726f6388 2565.TP
f73dda09
JA
2566.B PS2
2567The value of this parameter is expanded as with
0001803f 2568.SM
f73dda09
JA
2569.B PS1
2570and used as the secondary prompt string. The default is
2571``\fB> \fP''.
2572.TP
2573.B PS3
2574The value of this parameter is used as the prompt for the
2575.B select
2576command (see
726f6388 2577.SM
f73dda09
JA
2578.B SHELL GRAMMAR
2579above).
726f6388 2580.TP
f73dda09
JA
2581.B PS4
2582The value of this parameter is expanded as with
0001803f 2583.SM
f73dda09
JA
2584.B PS1
2585and the value is printed before each command
726f6388 2586.B bash
f73dda09 2587displays during an execution trace. The first character of
d233b485 2588the expanded value of
bb70624e 2589.SM
f73dda09
JA
2590.B PS4
2591is replicated multiple times, as necessary, to indicate multiple
2592levels of indirection. The default is ``\fB+ \fP''.
2593.TP
b80f6443 2594.B SHELL
8868edaf 2595This variable expands to the full pathname to the shell.
b80f6443
JA
2596If it is not set when the shell starts,
2597.B bash
2598assigns to it the full pathname of the current user's login shell.
2599.TP
f73dda09
JA
2600.B TIMEFORMAT
2601The value of this parameter is used as a format string specifying
2602how the timing information for pipelines prefixed with the
2603.B time
2604reserved word should be displayed.
2605The \fB%\fP character introduces an escape sequence that is
2606expanded to a time value or other information.
2607The escape sequences and their meanings are as follows; the
2608braces denote optional portions.
2609.sp .5
2610.RS
2611.PD 0
2612.TP 10
2613.B %%
2614A literal \fB%\fP.
2615.TP
2616.B %[\fIp\fP][l]R
2617The elapsed time in seconds.
2618.TP
2619.B %[\fIp\fP][l]U
2620The number of CPU seconds spent in user mode.
2621.TP
2622.B %[\fIp\fP][l]S
2623The number of CPU seconds spent in system mode.
2624.TP
2625.B %P
2626The CPU percentage, computed as (%U + %S) / %R.
2627.PD
2628.RE
2629.IP
2630The optional \fIp\fP is a digit specifying the \fIprecision\fP,
2631the number of fractional digits after a decimal point.
2632A value of 0 causes no decimal point or fraction to be output.
2633At most three places after the decimal point may be specified;
2634values of \fIp\fP greater than 3 are changed to 3.
2635If \fIp\fP is not specified, the value 3 is used.
2636.IP
2637The optional \fBl\fP specifies a longer format, including
2638minutes, of the form \fIMM\fPm\fISS\fP.\fIFF\fPs.
2639The value of \fIp\fP determines whether or not the fraction is
2640included.
2641.IP
2642If this variable is not set, \fBbash\fP acts as if it had the
ac50fbac 2643value \fB$\(aq\enreal\et%3lR\enuser\et%3lU\ensys\et%3lS\(aq\fP.
f73dda09
JA
2644If the value is null, no timing information is displayed.
2645A trailing newline is added when the format string is displayed.
495aee44 2646.PD 0
f73dda09
JA
2647.TP
2648.B TMOUT
0001803f
CR
2649If set to a value greater than zero,
2650.SM
2651.B TMOUT
2652is treated as the
7117c2d2
JA
2653default timeout for the \fBread\fP builtin.
2654The \fBselect\fP command terminates if input does not arrive
0001803f
CR
2655after
2656.SM
2657.B TMOUT
2658seconds when input is coming from a terminal.
7117c2d2 2659In an interactive shell, the value is interpreted as the
ac50fbac
CR
2660number of seconds to wait for a line of input after issuing the
2661primary prompt.
f73dda09 2662.B Bash
ac50fbac
CR
2663terminates after waiting for that number of seconds if a complete
2664line of input does not arrive.
726f6388 2665.TP
95732b49 2666.B TMPDIR
495aee44
CR
2667If set, \fBbash\fP uses its value as the name of a directory in which
2668\fBbash\fP creates temporary files for the shell's use.
95732b49 2669.TP
726f6388
JA
2670.B auto_resume
2671This variable controls how the shell interacts with the user and
2672job control. If this variable is set, single word simple
2673commands without redirections are treated as candidates for resumption
2674of an existing stopped job. There is no ambiguity allowed; if there is
2675more than one job beginning with the string typed, the job most recently
2676accessed is selected. The
2677.I name
2678of a stopped job, in this context, is the command line used to
2679start it.
2680If set to the value
2681.IR exact ,
2682the string supplied must match the name of a stopped job exactly;
2683if set to
2684.IR substring ,
2685the string supplied needs to match a substring of the name of a
2686stopped job. The
2687.I substring
2688value provides functionality analogous to the
2689.B %?
ccc6cda3 2690job identifier (see
726f6388
JA
2691.SM
2692.B JOB CONTROL
2693below). If set to any other value, the supplied string must
2694be a prefix of a stopped job's name; this provides functionality
95732b49 2695analogous to the \fB%\fP\fIstring\fP job identifier.
bb70624e 2696.TP
f73dda09
JA
2697.B histchars
2698The two or three characters which control history expansion
2699and tokenization (see
2700.SM
2701.B HISTORY EXPANSION
2702below). The first character is the \fIhistory expansion\fP character,
2703the character which signals the start of a history
2704expansion, normally `\fB!\fP'.
2705The second character is the \fIquick substitution\fP
2706character, which is used as shorthand for re-running the previous
2707command entered, substituting one string for another in the command.
2708The default is `\fB^\fP'.
2709The optional third character is the character
2710which indicates that the remainder of the line is a comment when found
2711as the first character of a word, normally `\fB#\fP'. The history
2712comment character causes history substitution to be skipped for the
2713remaining words on the line. It does not necessarily cause the shell
2714parser to treat the rest of the line as a comment.
726f6388 2715.PD
ccc6cda3
JA
2716.SS Arrays
2717.B Bash
3185942a
JA
2718provides one-dimensional indexed and associative array variables.
2719Any variable may be used as an indexed array; the
ccc6cda3 2720.B declare
3185942a
JA
2721builtin will explicitly declare an array.
2722There is no maximum
ccc6cda3 2723limit on the size of an array, nor any requirement that members
3185942a
JA
2724be indexed or assigned contiguously.
2725Indexed arrays are referenced using integers (including arithmetic
a0c0a00f 2726expressions) and are zero-based; associative arrays are referenced
3185942a 2727using arbitrary strings.
ac50fbac 2728Unless otherwise noted, indexed array indices must be non-negative integers.
ccc6cda3 2729.PP
3185942a
JA
2730An indexed array is created automatically if any variable is assigned to
2731using the syntax \fIname\fP[\fIsubscript\fP]=\fIvalue\fP. The
ccc6cda3 2732.I subscript
495aee44 2733is treated as an arithmetic expression that must evaluate to a number.
495aee44 2734To explicitly declare an indexed array, use
ccc6cda3
JA
2735.B declare \-a \fIname\fP
2736(see
2737.SM
2738.B SHELL BUILTIN COMMANDS
2739below).
2740.B declare \-a \fIname\fP[\fIsubscript\fP]
3185942a
JA
2741is also accepted; the \fIsubscript\fP is ignored.
2742.PP
2743Associative arrays are created using
2744.BR "declare \-A \fIname\fP" .
2745.PP
2746Attributes may be
ccc6cda3
JA
2747specified for an array variable using the
2748.B declare
2749and
2750.B readonly
2751builtins. Each attribute applies to all members of an array.
2752.PP
2753Arrays are assigned to using compound assignments of the form
2754\fIname\fP=\fB(\fPvalue\fI1\fP ... value\fIn\fP\fB)\fP, where each
8868edaf 2755\fIvalue\fP may be of the form [\fIsubscript\fP]=\fIstring\fP.
ac50fbac 2756Indexed array assignments do not require anything but \fIstring\fP.
8868edaf
CR
2757Each \fIvalue\fP in the list is expanded using all the shell expansions
2758described below under
2759.SM
2760.BR EXPANSION .
3185942a
JA
2761When assigning to indexed arrays, if the optional brackets and subscript
2762are supplied, that index is assigned to;
ccc6cda3
JA
2763otherwise the index of the element assigned is the last index assigned
2764to by the statement plus one. Indexing starts at zero.
3185942a 2765.PP
8868edaf
CR
2766When assigning to an associative array, the words in a compound assignment
2767may be either assignment statements, for which the subscript is required,
2768or a list of words that is interpreted as a sequence of alternating keys
2769and values:
2770\fIname\fP=\fB( \fP\fIkey1 value1 key2 value2\fP ...\fB)\fP.
2771These are treated identically to
2772\fIname\fP=\fB(\fP [\fIkey1\fP]=\fIvalue1\fP [\fIkey2\fP]=\fIvalue2\fP ...\fB)\fP.
2773The first word in the list determines how the remaining words
2774are interpreted; all assignments in a list must be of the same type.
2775When using key/value pairs, the keys may not be missing or empty;
2776a final missing value is treated like the empty string.
3185942a 2777.PP
ccc6cda3
JA
2778This syntax is also accepted by the
2779.B declare
2780builtin. Individual array elements may be assigned to using the
2781\fIname\fP[\fIsubscript\fP]=\fIvalue\fP syntax introduced above.
ac50fbac
CR
2782When assigning to an indexed array, if
2783.I name
2784is subscripted by a negative number, that number is
2785interpreted as relative to one greater than the maximum index of
2786\fIname\fP, so negative indices count back from the end of the
2787array, and an index of \-1 references the last element.
ccc6cda3 2788.PP
74091dd4
CR
2789The += operator will append to an array variable when assigning
2790using the compound assignment syntax; see
2791.SM
2792.B PARAMETERS
2793above.
2794.PP
ccc6cda3
JA
2795Any element of an array may be referenced using
2796${\fIname\fP[\fIsubscript\fP]}. The braces are required to avoid
2797conflicts with pathname expansion. If
2798\fIsubscript\fP is \fB@\fP or \fB*\fP, the word expands to
2799all members of \fIname\fP. These subscripts differ only when the
2800word appears within double quotes. If the word is double-quoted,
2801${\fIname\fP[*]} expands to a single
2802word with the value of each array member separated by the first
2803character of the
2804.SM
2805.B IFS
2806special variable, and ${\fIname\fP[@]} expands each element of
2807\fIname\fP to a separate word. When there are no array members,
95732b49
JA
2808${\fIname\fP[@]} expands to nothing.
2809If the double-quoted expansion occurs within a word, the expansion of
2810the first parameter is joined with the beginning part of the original
2811word, and the expansion of the last parameter is joined with the last
2812part of the original word.
2813This is analogous to the expansion
ccc6cda3
JA
2814of the special parameters \fB*\fP and \fB@\fP (see
2815.B Special Parameters
2816above). ${#\fIname\fP[\fIsubscript\fP]} expands to the length of
2817${\fIname\fP[\fIsubscript\fP]}. If \fIsubscript\fP is \fB*\fP or
2818\fB@\fP, the expansion is the number of elements in the array.
ac50fbac
CR
2819If the
2820.I subscript
2821used to reference an element of an indexed array
a0c0a00f 2822evaluates to a number less than zero, it is
ac50fbac
CR
2823interpreted as relative to one greater than the maximum index of the array,
2824so negative indices count back from the end of the
2825array, and an index of \-1 references the last element.
ccc6cda3 2826.PP
a0c0a00f
CR
2827Referencing an array variable without a subscript is equivalent to
2828referencing the array with a subscript of 0.
2829Any reference to a variable using a valid subscript is legal, and
2830.B bash
2831will create an array if necessary.
2832.PP
0001803f
CR
2833An array variable is considered set if a subscript has been assigned a
2834value. The null string is a valid value.
2835.PP
ac50fbac
CR
2836It is possible to obtain the keys (indices) of an array as well as the values.
2837${\fB!\fP\fIname\fP[\fI@\fP]} and ${\fB!\fP\fIname\fP[\fI*\fP]}
2838expand to the indices assigned in array variable \fIname\fP.
2839The treatment when in double quotes is similar to the expansion of the
2840special parameters \fI@\fP and \fI*\fP within double quotes.
2841.PP
ccc6cda3
JA
2842The
2843.B unset
bb70624e 2844builtin is used to destroy arrays. \fBunset\fP \fIname\fP[\fIsubscript\fP]
d233b485
CR
2845destroys the array element at index \fIsubscript\fP,
2846for both indexed and associative arrays.
ac50fbac 2847Negative subscripts to indexed arrays are interpreted as described above.
d233b485 2848Unsetting the last element of an array variable does not unset the variable.
74091dd4
CR
2849\fBunset\fP \fIname\fP, where \fIname\fP is an array,
2850removes the entire array.
ccc6cda3 2851\fBunset\fP \fIname\fP[\fIsubscript\fP], where
74091dd4
CR
2852\fIsubscript\fP is \fB*\fP or \fB@\fP, behaves differently depending on
2853whether \fIname\fP is an indexed or associative array.
2854If \fIname\fP is an associative array, this unsets the element with
2855subscript \fB*\fP or \fB@\fP.
2856If \fIname\fP is an indexed array, unset removes all of the elements but
2857does not remove the array itself.
ccc6cda3 2858.PP
d233b485
CR
2859When using a variable name with a subscript as an argument to a command,
2860such as with \fBunset\fP, without using the word expansion syntax
2861described above, the argument is subject to pathname expansion.
2862If pathname expansion is not desired, the argument should be quoted.
2863.PP
ccc6cda3
JA
2864The
2865.BR declare ,
2866.BR local ,
2867and
2868.B readonly
2869builtins each accept a
2870.B \-a
3185942a
JA
2871option to specify an indexed array and a
2872.B \-A
2873option to specify an associative array.
a0c0a00f 2874If both options are supplied,
495aee44
CR
2875.B \-A
2876takes precedence.
3185942a 2877The
ccc6cda3
JA
2878.B read
2879builtin accepts a
2880.B \-a
2881option to assign a list of words read from the standard input
2882to an array. The
2883.B set
2884and
2885.B declare
2886builtins display array values in a way that allows them to be
2887reused as assignments.
726f6388
JA
2888.SH EXPANSION
2889Expansion is performed on the command line after it has been split into
2890words. There are seven kinds of expansion performed:
2891.IR "brace expansion" ,
2892.IR "tilde expansion" ,
2893.IR "parameter and variable expansion" ,
2894.IR "command substitution" ,
2895.IR "arithmetic expansion" ,
2896.IR "word splitting" ,
2897and
2898.IR "pathname expansion" .
2899.PP
ac50fbac
CR
2900The order of expansions is:
2901brace expansion;
2902tilde expansion, parameter and variable expansion, arithmetic expansion,
2903and command substitution (done in a left-to-right fashion);
2904word splitting;
2905and pathname expansion.
726f6388
JA
2906.PP
2907On systems that can support it, there is an additional expansion
2908available: \fIprocess substitution\fP.
ac50fbac
CR
2909This is performed at the
2910same time as tilde, parameter, variable, and arithmetic expansion and
2911command substitution.
726f6388 2912.PP
a0c0a00f
CR
2913After these expansions are performed, quote characters present in the
2914original word are removed unless they have been quoted themselves
2915(\fIquote removal\fP).
2916.PP
726f6388 2917Only brace expansion, word splitting, and pathname expansion
d233b485 2918can increase the number of words of the expansion; other expansions
726f6388 2919expand a single word to a single word.
ccc6cda3 2920The only exceptions to this are the expansions of
d233b485
CR
2921"\fB$@\fP" and "\fB${\fP\fIname\fP\fB[@]}\fP",
2922and, in most cases, \fB$*\fP and \fB${\fP\fIname\fP\fB[*]}\fP
ccc6cda3 2923as explained above (see
726f6388
JA
2924.SM
2925.BR PARAMETERS ).
2926.SS Brace Expansion
726f6388
JA
2927.I "Brace expansion"
2928is a mechanism by which arbitrary strings
2929may be generated. This mechanism is similar to
2930\fIpathname expansion\fP, but the filenames generated
2931need not exist. Patterns to be brace expanded take
2932the form of an optional
2933.IR preamble ,
b80f6443
JA
2934followed by either a series of comma-separated strings or
2935a sequence expression between a pair of braces, followed by
2936an optional
cce855bc 2937.IR postscript .
ccc6cda3 2938The preamble is prefixed to each string contained
cce855bc 2939within the braces, and the postscript is then appended
726f6388
JA
2940to each resulting string, expanding left to right.
2941.PP
2942Brace expansions may be nested. The results of each expanded
2943string are not sorted; left to right order is preserved.
2944For example, a\fB{\fPd,c,b\fB}\fPe expands into `ade ace abe'.
2945.PP
3185942a
JA
2946A sequence expression takes the form
2947\fB{\fP\fIx\fP\fB..\fP\fIy\fP\fB[..\fP\fIincr\fP\fB]}\fP,
74091dd4 2948where \fIx\fP and \fIy\fP are either integers or single letters,
3185942a 2949and \fIincr\fP, an optional increment, is an integer.
b80f6443
JA
2950When integers are supplied, the expression expands to each number between
2951\fIx\fP and \fIy\fP, inclusive.
3185942a 2952Supplied integers may be prefixed with \fI0\fP to force each term to have the
ac50fbac
CR
2953same width.
2954When either \fIx\fP or \fPy\fP begins with a zero, the shell
3185942a
JA
2955attempts to force all generated terms to contain the same number of digits,
2956zero-padding where necessary.
74091dd4 2957When letters are supplied, the expression expands to each character
ac50fbac
CR
2958lexicographically between \fIx\fP and \fIy\fP, inclusive,
2959using the default C locale.
74091dd4
CR
2960Note that both \fIx\fP and \fIy\fP must be of the same type
2961(integer or letter).
3185942a 2962When the increment is supplied, it is used as the difference between
d233b485 2963each term. The default increment is 1 or \-1 as appropriate.
b80f6443 2964.PP
726f6388
JA
2965Brace expansion is performed before any other expansions,
2966and any characters special to other expansions are preserved
2967in the result. It is strictly textual.
2968.B Bash
2969does not apply any syntactic interpretation to the context of the
2970expansion or the text between the braces.
2971.PP
2972A correctly-formed brace expansion must contain unquoted opening
b80f6443
JA
2973and closing braces, and at least one unquoted comma or a valid
2974sequence expression.
726f6388 2975Any incorrectly formed brace expansion is left unchanged.
ccc6cda3
JA
2976A \fB{\fP or \fB,\fP may be quoted with a backslash to prevent its
2977being considered part of a brace expression.
bb70624e 2978To avoid conflicts with parameter expansion, the string \fB${\fP
d233b485
CR
2979is not considered eligible for brace expansion, and inhibits brace
2980expansion until the closing \fB}\fP.
726f6388
JA
2981.PP
2982This construct is typically used as shorthand when the common
2983prefix of the strings to be generated is longer than in the
2984above example:
2985.RS
2986.PP
2987mkdir /usr/local/src/bash/{old,new,dist,bugs}
2988.RE
2989or
2990.RS
2991chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
2992.RE
2993.PP
2994Brace expansion introduces a slight incompatibility with
ccc6cda3
JA
2995historical versions of
2996.BR sh .
726f6388
JA
2997.B sh
2998does not treat opening or closing braces specially when they
2999appear as part of a word, and preserves them in the output.
3000.B Bash
3001removes braces from words as a consequence of brace
3002expansion. For example, a word entered to
3003.B sh
3004as \fIfile{1,2}\fP
3005appears identically in the output. The same word is
3006output as
3007.I file1 file2
3008after expansion by
3009.BR bash .
3010If strict compatibility with
3011.B sh
3012is desired, start
3013.B bash
3014with the
a0c0a00f 3015.B +B
ccc6cda3
JA
3016option or disable brace expansion with the
3017.B +B
726f6388
JA
3018option to the
3019.B set
3020command (see
3021.SM
3022.B SHELL BUILTIN COMMANDS
3023below).
3024.SS Tilde Expansion
cce855bc
JA
3025If a word begins with an unquoted tilde character (`\fB~\fP'), all of
3026the characters preceding the first unquoted slash (or all characters,
3027if there is no unquoted slash) are considered a \fItilde-prefix\fP.
3028If none of the characters in the tilde-prefix are quoted, the
3029characters in the tilde-prefix following the tilde are treated as a
3030possible \fIlogin name\fP.
3031If this login name is the null string, the tilde is replaced with the
3032value of the shell parameter
726f6388
JA
3033.SM
3034.BR HOME .
3035If
3036.SM
3037.B HOME
cce855bc
JA
3038is unset, the home directory of the user executing the shell is
3039substituted instead.
3040Otherwise, the tilde-prefix is replaced with the home directory
3041associated with the specified login name.
726f6388 3042.PP
cce855bc 3043If the tilde-prefix is a `~+', the value of the shell variable
726f6388
JA
3044.SM
3045.B PWD
cce855bc
JA
3046replaces the tilde-prefix.
3047If the tilde-prefix is a `~\-', the value of the shell variable
3048.SM
3049.BR OLDPWD ,
3050if it is set, is substituted.
3051If the characters following the tilde in the tilde-prefix consist
3052of a number \fIN\fP, optionally prefixed
3053by a `+' or a `\-', the tilde-prefix is replaced with the corresponding
3054element from the directory stack, as it would be displayed by the
3055.B dirs
3056builtin invoked with the tilde-prefix as an argument.
3057If the characters following the tilde in the tilde-prefix consist of a
3058number without a leading `+' or `\-', `+' is assumed.
3059.PP
3060If the login name is invalid, or the tilde expansion fails, the word
3061is unchanged.
726f6388 3062.PP
cce855bc
JA
3063Each variable assignment is checked for unquoted tilde-prefixes immediately
3064following a
726f6388 3065.B :
95732b49 3066or the first
726f6388 3067.BR = .
cce855bc 3068In these cases, tilde expansion is also performed.
ac50fbac 3069Consequently, one may use filenames with tildes in assignments to
726f6388
JA
3070.SM
3071.BR PATH ,
3072.SM
3073.BR MAILPATH ,
3074and
3075.SM
3076.BR CDPATH ,
3077and the shell assigns the expanded value.
d233b485
CR
3078.PP
3079Bash also performs tilde expansion on words satisfying the conditions of
3080variable assignments (as described above under
3081.SM
3082.BR PARAMETERS )
3083when they appear as arguments to simple commands.
3084Bash does not do this, except for the \fIdeclaration\fP commands listed
3085above, when in \fIposix mode\fP.
726f6388 3086.SS Parameter Expansion
726f6388
JA
3087The `\fB$\fP' character introduces parameter expansion,
3088command substitution, or arithmetic expansion. The parameter name
3089or symbol to be expanded may be enclosed in braces, which
3090are optional but serve to protect the variable to be expanded from
3091characters immediately following it which could be
3092interpreted as part of the name.
3093.PP
cce855bc
JA
3094When braces are used, the matching ending brace is the first `\fB}\fP'
3095not escaped by a backslash or within a quoted string, and not within an
95732b49 3096embedded arithmetic expansion, command substitution, or parameter
cce855bc
JA
3097expansion.
3098.PP
726f6388
JA
3099.PD 0
3100.TP
3101${\fIparameter\fP}
3102The value of \fIparameter\fP is substituted. The braces are required
3103when
3104.I parameter
3105is a positional parameter with more than one digit,
3106or when
3107.I parameter
3108is followed by a character which is not to be
3109interpreted as part of its name.
ac50fbac
CR
3110The \fIparameter\fP is a shell parameter as described above
3111\fBPARAMETERS\fP) or an array reference (\fBArrays\fP).
726f6388
JA
3112.PD
3113.PP
0001803f 3114If the first character of \fIparameter\fP is an exclamation point (\fB!\fP),
a0c0a00f 3115and \fIparameter\fP is not a \fInameref\fP,
d233b485
CR
3116it introduces a level of indirection.
3117\fBBash\fP uses the value formed by expanding the rest of
3118\fIparameter\fP as the new \fIparameter\fP; this is then
3119expanded and that value is used in the rest of the expansion, rather
3120than the expansion of the original \fIparameter\fP.
ccc6cda3 3121This is known as \fIindirect expansion\fP.
d233b485
CR
3122The value is subject to tilde expansion,
3123parameter expansion, command substitution, and arithmetic expansion.
a0c0a00f 3124If \fIparameter\fP is a nameref, this expands to the name of the
d233b485 3125parameter referenced by \fIparameter\fP instead of performing the
a0c0a00f 3126complete indirect expansion.
495aee44 3127The exceptions to this are the expansions of ${\fB!\fP\fIprefix\fP\fB*\fP} and
b80f6443
JA
3128${\fB!\fP\fIname\fP[\fI@\fP]} described below.
3129The exclamation point must immediately follow the left brace in order to
3130introduce indirection.
ccc6cda3 3131.PP
726f6388
JA
3132In each of the cases below, \fIword\fP is subject to tilde expansion,
3133parameter expansion, command substitution, and arithmetic expansion.
17345e5a 3134.PP
ac50fbac
CR
3135When not performing substring expansion, using the forms documented below
3136(e.g., \fB:-\fP),
17345e5a
JA
3137\fBbash\fP tests for a parameter that is unset or null. Omitting the colon
3138results in a test only for a parameter that is unset.
726f6388
JA
3139.PP
3140.PD 0
3141.TP
3142${\fIparameter\fP\fB:\-\fP\fIword\fP}
3143\fBUse Default Values\fP. If
3144.I parameter
3145is unset or null, the expansion of
3146.I word
3147is substituted. Otherwise, the value of
3148.I parameter
3149is substituted.
3150.TP
3151${\fIparameter\fP\fB:=\fP\fIword\fP}
3152\fBAssign Default Values\fP.
3153If
3154.I parameter
3155is unset or null, the expansion of
3156.I word
3157is assigned to
3158.IR parameter .
3159The value of
3160.I parameter
3161is then substituted. Positional parameters and special parameters may
3162not be assigned to in this way.
3163.TP
3164${\fIparameter\fP\fB:?\fP\fIword\fP}
3165\fBDisplay Error if Null or Unset\fP.
3166If
3167.I parameter
3168is null or unset, the expansion of \fIword\fP (or a message to that effect
3169if
3170.I word
3171is not present) is written to the standard error and the shell, if it
3172is not interactive, exits. Otherwise, the value of \fIparameter\fP is
3173substituted.
3174.TP
3175${\fIparameter\fP\fB:+\fP\fIword\fP}
3176\fBUse Alternate Value\fP.
3177If
3178.I parameter
3179is null or unset, nothing is substituted, otherwise the expansion of
3180.I word
3181is substituted.
3182.TP
ccc6cda3 3183${\fIparameter\fP\fB:\fP\fIoffset\fP}
7117c2d2 3184.PD 0
ccc6cda3
JA
3185.TP
3186${\fIparameter\fP\fB:\fP\fIoffset\fP\fB:\fP\fIlength\fP}
3187.PD
495aee44 3188\fBSubstring Expansion\fP.
ac50fbac 3189Expands to up to \fIlength\fP characters of the value of \fIparameter\fP
bb70624e 3190starting at the character specified by \fIoffset\fP.
74091dd4 3191If \fIparameter\fP is \fB@\fP or \fB*\fP, an indexed array subscripted by
ac50fbac
CR
3192\fB@\fP or \fB*\fP, or an associative array name, the results differ as
3193described below.
3194If \fIlength\fP is omitted, expands to the substring of the value of
3195\fIparameter\fP starting at the character specified by \fIoffset\fP
3196and extending to the end of the value.
ccc6cda3
JA
3197\fIlength\fP and \fIoffset\fP are arithmetic expressions (see
3198.SM
3199.B
3200ARITHMETIC EVALUATION
3201below).
ac50fbac 3202.sp 1
ccc6cda3 3203If \fIoffset\fP evaluates to a number less than zero, the value
ac50fbac
CR
3204is used as an offset in characters
3205from the end of the value of \fIparameter\fP.
3206If \fIlength\fP evaluates to a number less than zero,
3207it is interpreted as an offset in characters
3208from the end of the value of \fIparameter\fP rather than
3209a number of characters, and the expansion is the characters between
3210\fIoffset\fP and that result.
3211Note that a negative offset must be separated from the colon by at least
3212one space to avoid being confused with the \fB:-\fP expansion.
3213.sp 1
74091dd4
CR
3214If \fIparameter\fP is \fB@\fP or \fB*\fP, the result is \fIlength\fP
3215positional parameters beginning at \fIoffset\fP.
ac50fbac 3216A negative \fIoffset\fP is taken relative to one greater than the greatest
d233b485 3217positional parameter, so an offset of \-1 evaluates to the last positional
ac50fbac
CR
3218parameter.
3219It is an expansion error if \fIlength\fP evaluates to a number less than
3220zero.
3221.sp 1
3185942a 3222If \fIparameter\fP is an indexed array name subscripted by @ or *,
ccc6cda3
JA
3223the result is the \fIlength\fP
3224members of the array beginning with ${\fIparameter\fP[\fIoffset\fP]}.
95732b49
JA
3225A negative \fIoffset\fP is taken relative to one greater than the maximum
3226index of the specified array.
ac50fbac
CR
3227It is an expansion error if \fIlength\fP evaluates to a number less than
3228zero.
3229.sp 1
3185942a
JA
3230Substring expansion applied to an associative array produces undefined
3231results.
ac50fbac 3232.sp 1
a0c0a00f 3233Substring indexing is zero-based unless the positional parameters
3185942a
JA
3234are used, in which case the indexing starts at 1 by default.
3235If \fIoffset\fP is 0, and the positional parameters are used, \fB$0\fP is
3236prefixed to the list.
ccc6cda3 3237.TP
bb70624e 3238${\fB!\fP\fIprefix\fP\fB*\fP}
b80f6443
JA
3239.PD 0
3240.TP
3241${\fB!\fP\fIprefix\fP\fB@\fP}
3242.PD
495aee44 3243\fBNames matching prefix\fP.
bb70624e
JA
3244Expands to the names of variables whose names begin with \fIprefix\fP,
3245separated by the first character of the
3246.SM
3247.B IFS
3248special variable.
3185942a
JA
3249When \fI@\fP is used and the expansion appears within double quotes, each
3250variable name expands to a separate word.
bb70624e 3251.TP
b80f6443
JA
3252${\fB!\fP\fIname\fP[\fI@\fP]}
3253.PD 0
3254.TP
3255${\fB!\fP\fIname\fP[\fI*\fP]}
3256.PD
495aee44 3257\fBList of array keys\fP.
b80f6443
JA
3258If \fIname\fP is an array variable, expands to the list of array indices
3259(keys) assigned in \fIname\fP.
3260If \fIname\fP is not an array, expands to 0 if \fIname\fP is set and null
3261otherwise.
3262When \fI@\fP is used and the expansion appears within double quotes, each
3263key expands to a separate word.
3264.TP
726f6388 3265${\fB#\fP\fIparameter\fP}
495aee44 3266\fBParameter length\fP.
726f6388 3267The length in characters of the value of \fIparameter\fP is substituted.
ccc6cda3
JA
3268If
3269.I parameter
3270is
726f6388 3271.B *
a0c0a00f 3272or
726f6388 3273.BR @ ,
cce855bc 3274the value substituted is the number of positional parameters.
ccc6cda3
JA
3275If
3276.I parameter
3277is an array name subscripted by
726f6388 3278.B *
ccc6cda3
JA
3279or
3280.BR @ ,
cce855bc 3281the value substituted is the number of elements in the array.
ac50fbac
CR
3282If
3283.I parameter
3284is an indexed array name subscripted by a negative number, that number is
3285interpreted as relative to one greater than the maximum index of
3286\fIparameter\fP, so negative indices count back from the end of the
3287array, and an index of \-1 references the last element.
726f6388 3288.TP
726f6388 3289${\fIparameter\fP\fB#\fP\fIword\fP}
7117c2d2 3290.PD 0
726f6388
JA
3291.TP
3292${\fIparameter\fP\fB##\fP\fIword\fP}
3293.PD
495aee44 3294\fBRemove matching prefix pattern\fP.
a0c0a00f 3295The
726f6388
JA
3296.I word
3297is expanded to produce a pattern just as in pathname
d233b485
CR
3298expansion, and matched against the expanded value of
3299.I parameter
3300using the rules described under
3301.B Pattern Matching
3302below.
3303If the pattern matches the beginning of
726f6388
JA
3304the value of
3305.IR parameter ,
cce855bc 3306then the result of the expansion is the expanded value of
726f6388 3307.I parameter
ccc6cda3
JA
3308with the shortest matching pattern (the ``\fB#\fP'' case) or the
3309longest matching pattern (the ``\fB##\fP'' case) deleted.
3310If
3311.I parameter
3312is
3313.B @
3314or
3315.BR * ,
3316the pattern removal operation is applied to each positional
3317parameter in turn, and the expansion is the resultant list.
3318If
3319.I parameter
3320is an array variable subscripted with
3321.B @
3322or
3323.BR * ,
3324the pattern removal operation is applied to each member of the
3325array in turn, and the expansion is the resultant list.
726f6388 3326.TP
726f6388 3327${\fIparameter\fP\fB%\fP\fIword\fP}
7117c2d2 3328.PD 0
726f6388
JA
3329.TP
3330${\fIparameter\fP\fB%%\fP\fIword\fP}
3331.PD
495aee44 3332\fBRemove matching suffix pattern\fP.
726f6388 3333The \fIword\fP is expanded to produce a pattern just as in
d233b485
CR
3334pathname expansion, and matched against the expanded value of
3335.I parameter
3336using the rules described under
3337.B Pattern Matching
3338below.
cce855bc 3339If the pattern matches a trailing portion of the expanded value of
726f6388 3340.IR parameter ,
cce855bc 3341then the result of the expansion is the expanded value of
726f6388 3342.I parameter
ccc6cda3
JA
3343with the shortest matching pattern (the ``\fB%\fP'' case) or the
3344longest matching pattern (the ``\fB%%\fP'' case) deleted.
3345If
3346.I parameter
3347is
3348.B @
3349or
3350.BR * ,
3351the pattern removal operation is applied to each positional
3352parameter in turn, and the expansion is the resultant list.
3353If
3354.I parameter
3355is an array variable subscripted with
3356.B @
3357or
3358.BR * ,
3359the pattern removal operation is applied to each member of the
3360array in turn, and the expansion is the resultant list.
3361.TP
ccc6cda3 3362${\fIparameter\fP\fB/\fP\fIpattern\fP\fB/\fP\fIstring\fP}
74091dd4
CR
3363.PD 0
3364.TP
3365${\fIparameter\fP\fB//\fP\fIpattern\fP\fB/\fP\fIstring\fP}
3366.TP
3367${\fIparameter\fP\fB/#\fP\fIpattern\fP\fB/\fP\fIstring\fP}
3368.TP
3369${\fIparameter\fP\fB/%\fP\fIpattern\fP\fB/\fP\fIstring\fP}
3370.PD
495aee44 3371\fBPattern substitution\fP.
ccc6cda3 3372The \fIpattern\fP is expanded to produce a pattern just as in
74091dd4 3373pathname expansion.
ccc6cda3
JA
3374\fIParameter\fP is expanded and the longest match of \fIpattern\fP
3375against its value is replaced with \fIstring\fP.
74091dd4
CR
3376\fIstring\fP undergoes tilde expansion, parameter and variable expansion,
3377arithmetic expansion, command and process substitution, and quote removal.
d233b485
CR
3378The match is performed using the rules described under
3379.B Pattern Matching
3380below.
74091dd4
CR
3381In the first form above, only the first match is replaced.
3382If there are two slashes separating \fIparameter\fP and \fIpattern\fP
3383(the second form above), all matches of \fIpattern\fP are
3384replaced with \fIstring\fP.
3385If \fIpattern\fP is preceded by \fB#\fP (the third form above),
3386it must match at the beginning of the expanded value of \fIparameter\fP.
3387If \fIpattern\fP is preceded by \fB%\fP (the fourth form above),
3388it must match at the end of the expanded value of \fIparameter\fP.
3389If the expansion of \fIstring\fP is null,
3390matches of \fIpattern\fP are deleted.
3391If \fIstring\fP is null,
3392matches of \fIpattern\fP are deleted
ccc6cda3 3393and the \fB/\fP following \fIpattern\fP may be omitted.
74091dd4
CR
3394.sp 1
3395If the \fBpatsub_replacement\fP shell option is enabled using \fBshopt\fP,
3396any unquoted instances of \fB&\fP in \fIstring\fP are replaced with the
3397matching portion of \fIpattern\fP.
3398.sp 1
3399Quoting any part of \fIstring\fP inhibits replacement in the
3400expansion of the quoted portion, including replacement strings stored
3401in shell variables.
3402Backslash will escape \fB&\fP in \fIstring\fP; the backslash is removed
3403in order to permit a literal \fB&\fP in the replacement string.
3404Backslash can also be used to escape a backslash; \fB\e\e\fP results in
3405a literal backslash in the replacement.
3406Users should take care if \fIstring\fP is double-quoted to avoid
3407unwanted interactions between the backslash and double-quoting, since
3408backslash has special meaning within double quotes.
3409Pattern substitution performs the check for unquoted \fB&\fP after
3410expanding \fIstring\fP;
3411shell programmers should quote any occurrences of \fB&\fP
3412they want to be taken literally in the replacement
3413and ensure any instances of \fB&\fP they want to be replaced are unquoted.
3414.sp 1
a0c0a00f
CR
3415If the
3416.B nocasematch
3417shell option is enabled, the match is performed without regard to the case
3418of alphabetic characters.
ccc6cda3
JA
3419If
3420.I parameter
3421is
3422.B @
3423or
3424.BR * ,
3425the substitution operation is applied to each positional
3426parameter in turn, and the expansion is the resultant list.
3427If
3428.I parameter
3429is an array variable subscripted with
3430.B @
3431or
3432.BR * ,
3433the substitution operation is applied to each member of the
3434array in turn, and the expansion is the resultant list.
3185942a
JA
3435.TP
3436${\fIparameter\fP\fB^\fP\fIpattern\fP}
3437.PD 0
3438.TP
3439${\fIparameter\fP\fB^^\fP\fIpattern\fP}
3440.TP
3441${\fIparameter\fP\fB,\fP\fIpattern\fP}
3442.TP
3443${\fIparameter\fP\fB,,\fP\fIpattern\fP}
3444.PD
495aee44 3445\fBCase modification\fP.
3185942a
JA
3446This expansion modifies the case of alphabetic characters in \fIparameter\fP.
3447The \fIpattern\fP is expanded to produce a pattern just as in
3448pathname expansion.
ac50fbac
CR
3449Each character in the expanded value of \fIparameter\fP is tested against
3450\fIpattern\fP, and, if it matches the pattern, its case is converted.
3451The pattern should not attempt to match more than one character.
3185942a
JA
3452The \fB^\fP operator converts lowercase letters matching \fIpattern\fP
3453to uppercase; the \fB,\fP operator converts matching uppercase letters
3454to lowercase.
3455The \fB^^\fP and \fB,,\fP expansions convert each matched character in the
3456expanded value; the \fB^\fP and \fB,\fP expansions match and convert only
495aee44 3457the first character in the expanded value.
3185942a
JA
3458If \fIpattern\fP is omitted, it is treated like a \fB?\fP, which matches
3459every character.
3460If
3461.I parameter
3462is
3463.B @
3464or
3465.BR * ,
3466the case modification operation is applied to each positional
3467parameter in turn, and the expansion is the resultant list.
3468If
3469.I parameter
3470is an array variable subscripted with
3471.B @
3472or
3473.BR * ,
3474the case modification operation is applied to each member of the
3475array in turn, and the expansion is the resultant list.
a0c0a00f
CR
3476.TP
3477${\fIparameter\fP\fB@\fP\fIoperator\fP}
3478\fBParameter transformation\fP.
3479The expansion is either a transformation of the value of \fIparameter\fP
3480or information about \fIparameter\fP itself, depending on the value of
3481\fIoperator\fP. Each \fIoperator\fP is a single letter:
3482.sp 1
3483.RS
3484.PD 0
3485.TP
8868edaf
CR
3486.B U
3487The expansion is a string that is the value of \fIparameter\fP with lowercase
3488alphabetic characters converted to uppercase.
3489.TP
3490.B u
3491The expansion is a string that is the value of \fIparameter\fP with the first
3492character converted to uppercase, if it is alphabetic.
3493.TP
3494.B L
3495The expansion is a string that is the value of \fIparameter\fP with uppercase
3496alphabetic characters converted to lowercase.
3497.TP
a0c0a00f
CR
3498.B Q
3499The expansion is a string that is the value of \fIparameter\fP quoted in a
3500format that can be reused as input.
3501.TP
3502.B E
3503The expansion is a string that is the value of \fIparameter\fP with backslash
74091dd4 3504escape sequences expanded as with the \fB$\(aq...\(aq\fP quoting mechanism.
a0c0a00f
CR
3505.TP
3506.B P
3507The expansion is a string that is the result of expanding the value of
3508\fIparameter\fP as if it were a prompt string (see \fBPROMPTING\fP below).
3509.TP
3510.B A
3511The expansion is a string in the form of
3512an assignment statement or \fBdeclare\fP command that, if
3513evaluated, will recreate \fIparameter\fP with its attributes and value.
3514.TP
8868edaf
CR
3515.B K
3516Produces a possibly-quoted version of the value of \fIparameter\fP,
3517except that it prints the values of
3518indexed and associative arrays as a sequence of quoted key-value pairs
3519(see \fBArrays\fP above).
3520.TP
a0c0a00f
CR
3521.B a
3522The expansion is a string consisting of flag values representing
3523\fIparameter\fP's attributes.
74091dd4
CR
3524.TP
3525.B k
3526Like the K transformation, but expands the keys and values of
3527indexed and associative arrays to separate words after word splitting.
a0c0a00f
CR
3528.PD
3529.PP
3530If
3531.I parameter
3532is
3533.B @
3534or
3535.BR * ,
3536the operation is applied to each positional
3537parameter in turn, and the expansion is the resultant list.
3538If
3539.I parameter
3540is an array variable subscripted with
3541.B @
3542or
3543.BR * ,
d233b485 3544the operation is applied to each member of the
a0c0a00f
CR
3545array in turn, and the expansion is the resultant list.
3546.sp 1
3547The result of the expansion is subject to word splitting and pathname
3548expansion as described below.
3549.RE
726f6388 3550.SS Command Substitution
cce855bc 3551\fICommand substitution\fP allows the output of a command to replace
726f6388 3552the command name. There are two forms:
726f6388
JA
3553.RS
3554.PP
3555\fB$(\fP\fIcommand\fP\|\fB)\fP
3556.RE
3557or
3558.RS
3185942a 3559\fB\`\fP\fIcommand\fP\fB\`\fP
726f6388
JA
3560.RE
3561.PP
ccc6cda3 3562.B Bash
a0c0a00f
CR
3563performs the expansion by executing \fIcommand\fP in a subshell environment
3564and replacing the command substitution with the standard output of the
726f6388 3565command, with any trailing newlines deleted.
cce855bc
JA
3566Embedded newlines are not deleted, but they may be removed during
3567word splitting.
3568The command substitution \fB$(cat \fIfile\fP)\fR can be replaced by
3569the equivalent but faster \fB$(< \fIfile\fP)\fR.
726f6388 3570.PP
ccc6cda3 3571When the old-style backquote form of substitution is used,
726f6388
JA
3572backslash retains its literal meaning except when followed by
3573.BR $ ,
3185942a 3574.BR \` ,
726f6388
JA
3575or
3576.BR \e .
cce855bc
JA
3577The first backquote not preceded by a backslash terminates the
3578command substitution.
726f6388
JA
3579When using the $(\^\fIcommand\fP\|) form, all characters between the
3580parentheses make up the command; none are treated specially.
3581.PP
cce855bc 3582Command substitutions may be nested. To nest when using the backquoted form,
726f6388
JA
3583escape the inner backquotes with backslashes.
3584.PP
3585If the substitution appears within double quotes, word splitting and
3586pathname expansion are not performed on the results.
3587.SS Arithmetic Expansion
726f6388 3588Arithmetic expansion allows the evaluation of an arithmetic expression
ccc6cda3 3589and the substitution of the result. The format for arithmetic expansion is:
726f6388
JA
3590.RS
3591.PP
726f6388
JA
3592\fB$((\fP\fIexpression\fP\fB))\fP
3593.RE
3594.PP
3595The
3596.I expression
74091dd4
CR
3597undergoes the same expansions
3598as if it were within double quotes,
3599but double quote characters in \fIexpression\fP are not treated specially
3600and are removed.
ac50fbac
CR
3601All tokens in the expression undergo parameter and variable expansion,
3602command substitution, and quote removal.
3603The result is treated as the arithmetic expression to be evaluated.
b80f6443 3604Arithmetic expansions may be nested.
726f6388
JA
3605.PP
3606The evaluation is performed according to the rules listed below under
3607.SM
3608.BR "ARITHMETIC EVALUATION" .
3609If
3610.I expression
3611is invalid,
3612.B bash
3613prints a message indicating failure and no substitution occurs.
3614.SS Process Substitution
a0c0a00f
CR
3615\fIProcess substitution\fP allows a process's input or output to be
3616referred to using a filename.
726f6388
JA
3617It takes the form of
3618\fB<(\fP\fIlist\^\fP\fB)\fP
3619or
3620\fB>(\fP\fIlist\^\fP\fB)\fP.
a0c0a00f
CR
3621The process \fIlist\fP is run asynchronously, and its input or output
3622appears as a filename.
3623This filename is
726f6388 3624passed as an argument to the current command as the result of the
a0c0a00f
CR
3625expansion.
3626If the \fB>(\fP\fIlist\^\fP\fB)\fP form is used, writing to
726f6388
JA
3627the file will provide input for \fIlist\fP. If the
3628\fB<(\fP\fIlist\^\fP\fB)\fP form is used, the file passed as an
3629argument should be read to obtain the output of \fIlist\fP.
a0c0a00f
CR
3630Process substitution is supported on systems that support named
3631pipes (\fIFIFOs\fP) or the \fB/dev/fd\fP method of naming open files.
726f6388 3632.PP
bb70624e 3633When available, process substitution is performed
a0c0a00f 3634simultaneously with parameter and variable expansion,
ccc6cda3
JA
3635command substitution,
3636and arithmetic expansion.
726f6388 3637.SS Word Splitting
726f6388
JA
3638The shell scans the results of
3639parameter expansion,
3640command substitution,
3641and
3642arithmetic expansion
3643that did not occur within double quotes for
3644.IR "word splitting" .
3645.PP
3646The shell treats each character of
3647.SM
3648.B IFS
3649as a delimiter, and splits the results of the other
ac50fbac
CR
3650expansions into words using these characters as field terminators.
3651If
726f6388
JA
3652.SM
3653.B IFS
ccc6cda3
JA
3654is unset, or its
3655value is exactly
726f6388
JA
3656.BR <space><tab><newline> ,
3657the default, then
3185942a
JA
3658sequences of
3659.BR <space> ,
3660.BR <tab> ,
3661and
3662.B <newline>
3663at the beginning and end of the results of the previous
3664expansions are ignored, and
726f6388
JA
3665any sequence of
3666.SM
3667.B IFS
3185942a
JA
3668characters not at the beginning or end serves to delimit words.
3669If
726f6388
JA
3670.SM
3671.B IFS
3672has a value other than the default, then sequences of
3673the whitespace characters
a0c0a00f
CR
3674.BR space ,
3675.BR tab ,
726f6388 3676and
a0c0a00f 3677.B newline
726f6388
JA
3678are ignored at the beginning and end of the
3679word, as long as the whitespace character is in the
3680value of
3681.SM
d233b485 3682.B IFS
726f6388
JA
3683(an
3684.SM
3685.B IFS
3686whitespace character).
3687Any character in
3688.SM
3689.B IFS
3690that is not
3691.SM
3692.B IFS
3693whitespace, along with any adjacent
3694.SM
3695.B IFS
3696whitespace characters, delimits a field.
3697A sequence of
3698.SM
3699.B IFS
3700whitespace characters is also treated as a delimiter.
3701If the value of
3702.SM
3703.B IFS
3704is null, no word splitting occurs.
726f6388 3705.PP
a0c0a00f
CR
3706Explicit null arguments (\^\f3"\^"\fP or \^\f3\(aq\^\(aq\fP\^) are retained
3707and passed to commands as empty strings.
ccc6cda3 3708Unquoted implicit null arguments, resulting from the expansion of
bb70624e 3709parameters that have no values, are removed.
ccc6cda3 3710If a parameter with no value is expanded within double quotes, a
a0c0a00f
CR
3711null argument results and is retained
3712and passed to a command as an empty string.
3713When a quoted null argument appears as part of a word whose expansion is
3714non-null, the null argument is removed.
3715That is, the word
3716\f(CW\-d\(aq\^\(aq\fP becomes \f(CW\-d\fP after word splitting and
3717null argument removal.
726f6388
JA
3718.PP
3719Note that if no expansion occurs, no splitting
3720is performed.
3721.SS Pathname Expansion
726f6388
JA
3722After word splitting,
3723unless the
3724.B \-f
3725option has been set,
3726.B bash
ccc6cda3 3727scans each word for the characters
726f6388
JA
3728.BR * ,
3729.BR ? ,
3730and
3731.BR [ .
8868edaf 3732If one of these characters appears, and is not quoted, then the word is
726f6388
JA
3733regarded as a
3734.IR pattern ,
3735and replaced with an alphabetically sorted list of
ac50fbac
CR
3736filenames matching the pattern
3737(see
3738.SM
3739.B "Pattern Matching"
3740below).
3741If no matching filenames are found,
ccc6cda3
JA
3742and the shell option
3743.B nullglob
3185942a 3744is not enabled, the word is left unchanged.
a0c0a00f 3745If the
cce855bc
JA
3746.B nullglob
3747option is set, and no matches are found,
726f6388 3748the word is removed.
b80f6443
JA
3749If the
3750.B failglob
3751shell option is set, and no matches are found, an error message
3752is printed and the command is not executed.
cce855bc
JA
3753If the shell option
3754.B nocaseglob
3755is enabled, the match is performed without regard to the case
3756of alphabetic characters.
ccc6cda3 3757When a pattern is used for pathname expansion,
726f6388
JA
3758the character
3759.B ``.''
3760at the start of a name or immediately following a slash
ccc6cda3
JA
3761must be matched explicitly, unless the shell option
3762.B dotglob
3763is set.
74091dd4 3764In order to match the filenames
d233b485
CR
3765.B ``.''
3766and
74091dd4
CR
3767.BR ``..'' ,
3768the pattern must begin with ``.'' (for example, ``.?''),
3769even if
d233b485
CR
3770.B dotglob
3771is set.
74091dd4
CR
3772If the
3773.B globskipdots
3774shell option is enabled, the filenames
3775.B ``.''
3776and
3777.BR ``..''
3778are never matched, even if the pattern begins with a
3779.BR ``.'' .
3780When not matching pathnames, the
726f6388
JA
3781.B ``.''
3782character is not treated specially.
d233b485
CR
3783When matching a pathname, the slash character must always be
3784matched explicitly by a slash in the pattern, but in other matching
3785contexts it can be matched by a special pattern character as described
3786below under
3787.SM
3788.BR "Pattern Matching" .
ccc6cda3
JA
3789See the description of
3790.B shopt
3791below under
3792.SM
3793.B SHELL BUILTIN COMMANDS
3794for a description of the
cce855bc
JA
3795.BR nocaseglob ,
3796.BR nullglob ,
74091dd4 3797.BR globskipdots ,
b80f6443 3798.BR failglob ,
ccc6cda3
JA
3799and
3800.B dotglob
3801shell options.
3802.PP
3803The
3804.SM
3805.B GLOBIGNORE
d233b485 3806shell variable may be used to restrict the set of file names matching a
ccc6cda3
JA
3807.IR pattern .
3808If
3809.SM
3810.B GLOBIGNORE
d233b485 3811is set, each matching file name that also matches one of the patterns in
ccc6cda3
JA
3812.SM
3813.B GLOBIGNORE
3814is removed from the list of matches.
a0c0a00f
CR
3815If the \fBnocaseglob\fP option is set, the matching against the patterns in
3816.SM
3817.B GLOBIGNORE
3818is performed without regard to case.
ac50fbac 3819The filenames
ccc6cda3
JA
3820.B ``.''
3821and
3822.B ``..''
b80f6443 3823are always ignored when
ccc6cda3
JA
3824.SM
3825.B GLOBIGNORE
b80f6443 3826is set and not null. However, setting
ccc6cda3
JA
3827.SM
3828.B GLOBIGNORE
b80f6443 3829to a non-null value has the effect of enabling the
ccc6cda3 3830.B dotglob
ac50fbac 3831shell option, so all other filenames beginning with a
ccc6cda3
JA
3832.B ``.''
3833will match.
ac50fbac 3834To get the old behavior of ignoring filenames beginning with a
ccc6cda3
JA
3835.BR ``.'' ,
3836make
3837.B ``.*''
3838one of the patterns in
3839.SM
3840.BR GLOBIGNORE .
3841The
3842.B dotglob
3843option is disabled when
3844.SM
3845.B GLOBIGNORE
3846is unset.
a0c0a00f
CR
3847The pattern matching honors the setting of the \fBextglob\fP shell
3848option.
726f6388 3849.PP
cce855bc
JA
3850\fBPattern Matching\fP
3851.PP
3852Any character that appears in a pattern, other than the special pattern
3853characters described below, matches itself. The NUL character may not
b80f6443
JA
3854occur in a pattern. A backslash escapes the following character; the
3855escaping backslash is discarded when matching.
3856The special pattern characters must be quoted if
cce855bc
JA
3857they are to be matched literally.
3858.PP
726f6388
JA
3859The special pattern characters have the following meanings:
3860.PP
3861.PD 0
495aee44 3862.RS
726f6388
JA
3863.TP
3864.B *
3865Matches any string, including the null string.
3185942a 3866When the \fBglobstar\fP shell option is enabled, and \fB*\fP is used in
0001803f 3867a pathname expansion context, two adjacent \fB*\fPs used as a single
3185942a
JA
3868pattern will match all files and zero or more directories and
3869subdirectories.
3870If followed by a \fB/\fP, two adjacent \fB*\fPs will match only directories
3871and subdirectories.
726f6388
JA
3872.TP
3873.B ?
3874Matches any single character.
3875.TP
3876.B [...]
3877Matches any one of the enclosed characters. A pair of characters
28ef6c31
JA
3878separated by a hyphen denotes a
3879\fIrange expression\fP;
ac50fbac 3880any character that falls between those two characters, inclusive,
28ef6c31 3881using the current locale's collating sequence and character set,
726f6388
JA
3882is matched. If the first character following the
3883.B [
3884is a
3885.B !
3886or a
3887.B ^
ccc6cda3 3888then any character not enclosed is matched.
74091dd4
CR
3889The sorting order of characters in range expressions,
3890and the characters included in the range,
3891are determined by
ac50fbac 3892the current locale and the values of the
0001803f
CR
3893.SM
3894.B LC_COLLATE
ac50fbac
CR
3895or
3896.SM
3897.B LC_ALL
3898shell variables, if set.
3899To obtain the traditional interpretation of range expressions, where
3900.B [a\-d]
3901is equivalent to
3902.BR [abcd] ,
3903set value of the
3904.B LC_ALL
3905shell variable to
3906.BR C ,
3907or enable the
3908.B globasciiranges
3909shell option.
a0c0a00f 3910A
726f6388 3911.B \-
726f6388
JA
3912may be matched by including it as the first or last character
3913in the set.
ccc6cda3
JA
3914A
3915.B ]
3916may be matched by including it as the first character
3917in the set.
cce855bc
JA
3918.br
3919.if t .sp 0.5
3920.if n .sp 1
3921Within
3922.B [
3923and
3924.BR ] ,
3925\fIcharacter classes\fP can be specified using the syntax
3926\fB[:\fP\fIclass\fP\fB:]\fP, where \fIclass\fP is one of the
0628567a 3927following classes defined in the POSIX standard:
cce855bc
JA
3928.PP
3929.RS
3930.B
7117c2d2
JA
3931.if n alnum alpha ascii blank cntrl digit graph lower print punct space upper word xdigit
3932.if t alnum alpha ascii blank cntrl digit graph lower print punct space upper word xdigit
cce855bc
JA
3933.br
3934A character class matches any character belonging to that class.
7117c2d2 3935The \fBword\fP character class matches letters, digits, and the character _.
cce855bc
JA
3936.br
3937.if t .sp 0.5
3938.if n .sp 1
3939Within
3940.B [
a0c0a00f 3941and
cce855bc
JA
3942.BR ] ,
3943an \fIequivalence class\fP can be specified using the syntax
3944\fB[=\fP\fIc\fP\fB=]\fP, which matches all characters with the
3945same collation weight (as defined by the current locale) as
3946the character \fIc\fP.
3947.br
3948.if t .sp 0.5
3949.if n .sp 1
3950Within
3951.B [
a0c0a00f 3952and
cce855bc
JA
3953.BR ] ,
3954the syntax \fB[.\fP\fIsymbol\fP\fB.]\fP matches the collating symbol
3955\fIsymbol\fP.
3956.RE
495aee44 3957.RE
cce855bc
JA
3958.PD
3959.PP
3960If the \fBextglob\fP shell option is enabled using the \fBshopt\fP
74091dd4 3961builtin, the shell recognizes several extended pattern matching operators.
bb70624e 3962In the following description, a \fIpattern-list\fP is a list of one
cce855bc
JA
3963or more patterns separated by a \fB|\fP.
3964Composite patterns may be formed using one or more of the following
3965sub-patterns:
3966.sp 1
3967.PD 0
3968.RS
3969.TP
3970\fB?(\fP\^\fIpattern-list\^\fP\fB)\fP
3971Matches zero or one occurrence of the given patterns
3972.TP
3973\fB*(\fP\^\fIpattern-list\^\fP\fB)\fP
3974Matches zero or more occurrences of the given patterns
3975.TP
3976\fB+(\fP\^\fIpattern-list\^\fP\fB)\fP
3977Matches one or more occurrences of the given patterns
3978.TP
3979\fB@(\fP\^\fIpattern-list\^\fP\fB)\fP
95732b49 3980Matches one of the given patterns
cce855bc
JA
3981.TP
3982\fB!(\fP\^\fIpattern-list\^\fP\fB)\fP
3983Matches anything except one of the given patterns
3984.RE
726f6388 3985.PD
d233b485 3986.PP
74091dd4
CR
3987The\fBextglob\fP option changes the behavior of the parser, since the
3988parentheses are normally treated as operators with syntactic meaning.
3989To ensure that extended matching patterns are parsed correctly, make sure
3990that \fBextglob\fP is enabled before parsing constructs containing the
3991patterns, including shell functions and command substitutions.
3992.PP
3993When matching filenames, the \fBdotglob\fP shell option determines
3994the set of filenames that are tested:
3995when \fBdotglob\fP is enabled, the set of filenames includes all files
3996beginning with ``.'', but ``.'' and ``..'' must be matched by a
3997pattern or sub-pattern that begins with a dot;
3998when it is disabled, the set does not
3999include any filenames beginning with ``.'' unless the pattern
4000or sub-pattern begins with a ``.''.
4001As above, ``.'' only has a special meaning when matching filenames.
4002.PP
d233b485
CR
4003Complicated extended pattern matching against long strings is slow,
4004especially when the patterns contain alternations and the strings
4005contain multiple matches.
4006Using separate matches against shorter strings, or using arrays of
4007strings instead of a single long string, may be faster.
726f6388 4008.SS Quote Removal
726f6388
JA
4009After the preceding expansions, all unquoted occurrences of the
4010characters
4011.BR \e ,
0628567a 4012.BR \(aq ,
ccc6cda3
JA
4013and \^\f3"\fP\^ that did not result from one of the above
4014expansions are removed.
726f6388
JA
4015.SH REDIRECTION
4016Before a command is executed, its input and output
4017may be
4018.I redirected
4019using a special notation interpreted by the shell.
74091dd4 4020\fIRedirection\fP allows commands' file handles to be
ac50fbac
CR
4021duplicated, opened, closed,
4022made to refer to different files,
4023and can change the files the command reads from and writes to.
4024Redirection may also be used to modify file handles in the
4025current shell execution environment.
4026The following redirection
726f6388
JA
4027operators may precede or appear anywhere within a
4028.I simple command
4029or may follow a
4030.IR command .
4031Redirections are processed in the order they appear, from
4032left to right.
4033.PP
0001803f
CR
4034Each redirection that may be preceded by a file descriptor number
4035may instead be preceded by a word of the form {\fIvarname\fP}.
4036In this case, for each redirection operator except
4037>&- and <&-, the shell will allocate a file descriptor greater
ac50fbac
CR
4038than or equal to 10 and assign it to \fIvarname\fP.
4039If >&- or <&- is preceded
0001803f
CR
4040by {\fIvarname\fP}, the value of \fIvarname\fP defines the file
4041descriptor to close.
d233b485
CR
4042If {\fIvarname\fP} is supplied, the redirection persists beyond
4043the scope of the command, allowing the shell programmer to manage
74091dd4
CR
4044the file descriptor's lifetime manually.
4045The \fBvarredir_close\fP shell option manages this behavior.
0001803f 4046.PP
726f6388
JA
4047In the following descriptions, if the file descriptor number is
4048omitted, and the first character of the redirection operator is
4049.BR < ,
4050the redirection refers to the standard input (file descriptor
40510). If the first character of the redirection operator is
4052.BR > ,
4053the redirection refers to the standard output (file descriptor
40541).
4055.PP
cce855bc 4056The word following the redirection operator in the following
ac50fbac
CR
4057descriptions, unless otherwise noted, is subjected to
4058brace expansion, tilde expansion, parameter and variable expansion,
4059command substitution, arithmetic expansion, quote removal,
4060pathname expansion, and word splitting.
cce855bc 4061If it expands to more than one word,
726f6388
JA
4062.B bash
4063reports an error.
4064.PP
a0c0a00f 4065Note that the order of redirections is significant. For example,
726f6388
JA
4066the command
4067.RS
4068.PP
4069ls \fB>\fP dirlist 2\fB>&\fP1
4070.RE
4071.PP
a0c0a00f 4072directs both standard output and standard error to the file
726f6388
JA
4073.IR dirlist ,
4074while the command
4075.RS
4076.PP
4077ls 2\fB>&\fP1 \fB>\fP dirlist
4078.RE
4079.PP
4080directs only the standard output to file
4081.IR dirlist ,
17345e5a 4082because the standard error was duplicated from the standard output
726f6388
JA
4083before the standard output was redirected to
4084.IR dirlist .
cce855bc 4085.PP
bb70624e 4086\fBBash\fP handles several filenames specially when they are used in
a0c0a00f
CR
4087redirections, as described in the following table.
4088If the operating system on which \fBbash\fP is running provides these
4089special files, bash will use them; otherwise it will emulate them
4090internally with the behavior described below.
bb70624e
JA
4091.RS
4092.PP
4093.PD 0
4094.TP
4095.B /dev/fd/\fIfd\fP
4096If \fIfd\fP is a valid integer, file descriptor \fIfd\fP is duplicated.
4097.TP
4098.B /dev/stdin
4099File descriptor 0 is duplicated.
4100.TP
4101.B /dev/stdout
4102File descriptor 1 is duplicated.
4103.TP
4104.B /dev/stderr
4105File descriptor 2 is duplicated.
4106.TP
4107.B /dev/tcp/\fIhost\fP/\fIport\fP
4108If \fIhost\fP is a valid hostname or Internet address, and \fIport\fP
f73dda09 4109is an integer port number or service name, \fBbash\fP attempts to open
ac50fbac 4110the corresponding TCP socket.
bb70624e
JA
4111.TP
4112.B /dev/udp/\fIhost\fP/\fIport\fP
4113If \fIhost\fP is a valid hostname or Internet address, and \fIport\fP
f73dda09 4114is an integer port number or service name, \fBbash\fP attempts to open
ac50fbac 4115the corresponding UDP socket.
bb70624e
JA
4116.PD
4117.RE
4118.PP
cce855bc 4119A failure to open or create a file causes the redirection to fail.
95732b49
JA
4120.PP
4121Redirections using file descriptors greater than 9 should be used with
4122care, as they may conflict with file descriptors the shell uses
4123internally.
726f6388 4124.SS Redirecting Input
726f6388
JA
4125Redirection of input causes the file whose name results from
4126the expansion of
4127.I word
4128to be opened for reading on file descriptor
4129.IR n ,
4130or the standard input (file descriptor 0) if
4131.I n
4132is not specified.
4133.PP
4134The general format for redirecting input is:
4135.RS
4136.PP
4137[\fIn\fP]\fB<\fP\fIword\fP
4138.RE
4139.SS Redirecting Output
726f6388
JA
4140Redirection of output causes the file whose name results from
4141the expansion of
4142.I word
4143to be opened for writing on file descriptor
4144.IR n ,
4145or the standard output (file descriptor 1) if
4146.I n
4147is not specified. If the file does not exist it is created;
4148if it does exist it is truncated to zero size.
4149.PP
4150The general format for redirecting output is:
4151.RS
4152.PP
4153[\fIn\fP]\fB>\fP\fIword\fP
4154.RE
4155.PP
4156If the redirection operator is
ccc6cda3
JA
4157.BR > ,
4158and the
cce855bc 4159.B noclobber
ccc6cda3
JA
4160option to the
4161.B set
bb70624e 4162builtin has been enabled, the redirection will fail if the file
cce855bc
JA
4163whose name results from the expansion of \fIword\fP exists and is
4164a regular file.
ccc6cda3 4165If the redirection operator is
726f6388 4166.BR >| ,
cce855bc
JA
4167or the redirection operator is
4168.B >
4169and the
4170.B noclobber
726f6388
JA
4171option to the
4172.B set
cce855bc 4173builtin command is not enabled, the redirection is attempted even
ccc6cda3 4174if the file named by \fIword\fP exists.
726f6388 4175.SS Appending Redirected Output
726f6388
JA
4176Redirection of output in this fashion
4177causes the file whose name results from
4178the expansion of
4179.I word
4180to be opened for appending on file descriptor
4181.IR n ,
4182or the standard output (file descriptor 1) if
4183.I n
4184is not specified. If the file does not exist it is created.
4185.PP
4186The general format for appending output is:
4187.RS
4188.PP
4189[\fIn\fP]\fB>>\fP\fIword\fP
4190.RE
726f6388 4191.SS Redirecting Standard Output and Standard Error
3185942a 4192This construct allows both the
726f6388
JA
4193standard output (file descriptor 1) and
4194the standard error output (file descriptor 2)
4195to be redirected to the file whose name is the
4196expansion of
3185942a 4197.IR word .
726f6388
JA
4198.PP
4199There are two formats for redirecting standard output and
4200standard error:
4201.RS
4202.PP
4203\fB&>\fP\fIword\fP
4204.RE
4205and
4206.RS
4207\fB>&\fP\fIword\fP
4208.RE
4209.PP
4210Of the two forms, the first is preferred.
4211This is semantically equivalent to
4212.RS
4213.PP
4214\fB>\fP\fIword\fP 2\fB>&\fP1
4215.RE
3185942a 4216.PP
ac50fbac
CR
4217When using the second form, \fIword\fP may not expand to a number or
4218\fB\-\fP. If it does, other redirection operators apply
4219(see \fBDuplicating File Descriptors\fP below) for compatibility
4220reasons.
3185942a 4221.SS Appending Standard Output and Standard Error
3185942a
JA
4222This construct allows both the
4223standard output (file descriptor 1) and
4224the standard error output (file descriptor 2)
4225to be appended to the file whose name is the
4226expansion of
4227.IR word .
4228.PP
4229The format for appending standard output and standard error is:
4230.RS
4231.PP
4232\fB&>>\fP\fIword\fP
4233.RE
4234.PP
4235This is semantically equivalent to
4236.RS
4237.PP
4238\fB>>\fP\fIword\fP 2\fB>&\fP1
4239.RE
ac50fbac
CR
4240.PP
4241(see \fBDuplicating File Descriptors\fP below).
726f6388 4242.SS Here Documents
726f6388
JA
4243This type of redirection instructs the shell to read input from the
4244current source until a line containing only
3185942a 4245.I delimiter
726f6388
JA
4246(with no trailing blanks)
4247is seen. All of
4248the lines read up to that point are then used as the standard
a0c0a00f 4249input (or file descriptor \fIn\fP if \fIn\fP is specified) for a command.
726f6388 4250.PP
7117c2d2 4251The format of here-documents is:
726f6388
JA
4252.RS
4253.PP
4254.nf
a0c0a00f 4255[\fIn\fP]\fB<<\fP[\fB\-\fP]\fIword\fP
f73dda09 4256 \fIhere-document\fP
726f6388
JA
4257\fIdelimiter\fP
4258.fi
4259.RE
4260.PP
ac50fbac
CR
4261No parameter and variable expansion, command substitution,
4262arithmetic expansion, or pathname expansion is performed on
726f6388 4263.IR word .
a0c0a00f 4264If any part of
726f6388 4265.I word
a0c0a00f 4266is quoted, the
726f6388
JA
4267.I delimiter
4268is the result of quote removal on
4269.IR word ,
cce855bc
JA
4270and the lines in the here-document are not expanded.
4271If \fIword\fP is unquoted,
ac50fbac
CR
4272all lines of the here-document are subjected to
4273parameter expansion, command substitution, and arithmetic expansion,
4274the character sequence
726f6388
JA
4275.B \e<newline>
4276is ignored, and
4277.B \e
4278must be used to quote the characters
4279.BR \e ,
4280.BR $ ,
4281and
3185942a 4282.BR \` .
726f6388
JA
4283.PP
4284If the redirection operator is
4285.BR <<\- ,
4286then all leading tab characters are stripped from input lines and the
4287line containing
4288.IR delimiter .
4289This allows
4290here-documents within shell scripts to be indented in a
4291natural fashion.
7117c2d2
JA
4292.SS "Here Strings"
4293A variant of here documents, the format is:
4294.RS
4295.PP
4296.nf
a0c0a00f 4297[\fIn\fP]\fB<<<\fP\fIword\fP
7117c2d2
JA
4298.fi
4299.RE
4300.PP
ac50fbac 4301The \fIword\fP undergoes
d233b485 4302tilde expansion, parameter and variable expansion,
ac50fbac
CR
4303command substitution, arithmetic expansion, and quote removal.
4304Pathname expansion and word splitting are not performed.
a0c0a00f
CR
4305The result is supplied as a single string, with a newline appended,
4306to the command on its
4307standard input (or file descriptor \fIn\fP if \fIn\fP is specified).
726f6388 4308.SS "Duplicating File Descriptors"
726f6388
JA
4309The redirection operator
4310.RS
4311.PP
4312[\fIn\fP]\fB<&\fP\fIword\fP
4313.RE
4314.PP
4315is used to duplicate input file descriptors.
4316If
4317.I word
4318expands to one or more digits, the file descriptor denoted by
4319.I n
cce855bc
JA
4320is made to be a copy of that file descriptor.
4321If the digits in
4322.I word
4323do not specify a file descriptor open for input, a redirection error occurs.
4324If
726f6388
JA
4325.I word
4326evaluates to
4327.BR \- ,
4328file descriptor
4329.I n
4330is closed. If
4331.I n
4332is not specified, the standard input (file descriptor 0) is used.
4333.PP
4334The operator
4335.RS
4336.PP
4337[\fIn\fP]\fB>&\fP\fIword\fP
4338.RE
4339.PP
4340is used similarly to duplicate output file descriptors. If
4341.I n
4342is not specified, the standard output (file descriptor 1) is used.
cce855bc
JA
4343If the digits in
4344.I word
4345do not specify a file descriptor open for output, a redirection error occurs.
ac50fbac
CR
4346If
4347.I word
4348evaluates to
4349.BR \- ,
4350file descriptor
4351.I n
4352is closed.
726f6388 4353As a special case, if \fIn\fP is omitted, and \fIword\fP does not
ac50fbac 4354expand to one or more digits or \fB\-\fP, the standard output and standard
726f6388 4355error are redirected as described previously.
7117c2d2 4356.SS "Moving File Descriptors"
7117c2d2
JA
4357The redirection operator
4358.RS
4359.PP
4360[\fIn\fP]\fB<&\fP\fIdigit\fP\fB\-\fP
4361.RE
4362.PP
4363moves the file descriptor \fIdigit\fP to file descriptor
4364.IR n ,
4365or the standard input (file descriptor 0) if \fIn\fP is not specified.
4366\fIdigit\fP is closed after being duplicated to \fIn\fP.
4367.PP
4368Similarly, the redirection operator
4369.RS
4370.PP
4371[\fIn\fP]\fB>&\fP\fIdigit\fP\fB\-\fP
4372.RE
4373.PP
4374moves the file descriptor \fIdigit\fP to file descriptor
4375.IR n ,
4376or the standard output (file descriptor 1) if \fIn\fP is not specified.
726f6388 4377.SS "Opening File Descriptors for Reading and Writing"
726f6388
JA
4378The redirection operator
4379.RS
4380.PP
4381[\fIn\fP]\fB<>\fP\fIword\fP
4382.RE
4383.PP
4384causes the file whose name is the expansion of
4385.I word
4386to be opened for both reading and writing on file descriptor
4387.IR n ,
ccc6cda3 4388or on file descriptor 0 if
726f6388
JA
4389.I n
4390is not specified. If the file does not exist, it is created.
726f6388 4391.SH ALIASES
bb70624e 4392\fIAliases\fP allow a string to be substituted for a word when it is used
cce855bc 4393as the first word of a simple command.
bb70624e 4394The shell maintains a list of aliases that may be set and unset with the
726f6388
JA
4395.B alias
4396and
4397.B unalias
4398builtin commands (see
4399.SM
4400.B SHELL BUILTIN COMMANDS
4401below).
b80f6443 4402The first word of each simple command, if unquoted,
726f6388
JA
4403is checked to see if it has an
4404alias. If so, that word is replaced by the text of the alias.
3185942a 4405The characters \fB/\fP, \fB$\fP, \fB\`\fP, and \fB=\fP and
b80f6443
JA
4406any of the shell \fImetacharacters\fP or quoting characters
4407listed above may not appear in an alias name.
4408The replacement text may contain any valid shell input,
4409including shell metacharacters.
4410The first word of the replacement text is tested
726f6388 4411for aliases, but a word that is identical to an alias being expanded
b80f6443
JA
4412is not expanded a second time.
4413This means that one may alias
726f6388
JA
4414.B ls
4415to
4416.BR "ls \-F" ,
4417for instance, and
4418.B bash
4419does not try to recursively expand the replacement text.
4420If the last character of the alias value is a
4421.IR blank ,
4422then the next command
4423word following the alias is also checked for alias expansion.
4424.PP
4425Aliases are created and listed with the
4426.B alias
4427command, and removed with the
4428.B unalias
4429command.
4430.PP
ccc6cda3 4431There is no mechanism for using arguments in the replacement text.
74091dd4 4432If arguments are needed, use a shell function (see
bb70624e
JA
4433.SM
4434.B FUNCTIONS
4435below).
726f6388 4436.PP
ccc6cda3
JA
4437Aliases are not expanded when the shell is not interactive, unless
4438the
4439.B expand_aliases
4440shell option is set using
4441.B shopt
4442(see the description of
4443.B shopt
4444under
4445.SM
4446\fBSHELL BUILTIN COMMANDS\fP
4447below).
726f6388
JA
4448.PP
4449The rules concerning the definition and use of aliases are
4450somewhat confusing.
4451.B Bash
d233b485
CR
4452always reads at least one complete line of input,
4453and all lines that make up a compound command,
4454before executing any of the commands on that line or the compound command.
4455Aliases are expanded when a
726f6388
JA
4456command is read, not when it is executed. Therefore, an
4457alias definition appearing on the same line as another
4458command does not take effect until the next line of input is read.
ccc6cda3 4459The commands following the alias definition
726f6388
JA
4460on that line are not affected by the new alias.
4461This behavior is also an issue when functions are executed.
cce855bc 4462Aliases are expanded when a function definition is read,
726f6388 4463not when the function is executed, because a function definition
a0c0a00f 4464is itself a command. As a consequence, aliases
726f6388
JA
4465defined in a function are not available until after that
4466function is executed. To be safe, always put
4467alias definitions on a separate line, and do not use
4468.B alias
4469in compound commands.
4470.PP
cce855bc 4471For almost every purpose, aliases are superseded by
726f6388 4472shell functions.
ccc6cda3
JA
4473.SH FUNCTIONS
4474A shell function, defined as described above under
4475.SM
4476.BR "SHELL GRAMMAR" ,
4477stores a series of commands for later execution.
bb70624e
JA
4478When the name of a shell function is used as a simple command name,
4479the list of commands associated with that function name is executed.
ccc6cda3
JA
4480Functions are executed in the context of the
4481current shell; no new process is created to interpret
4482them (contrast this with the execution of a shell script).
4483When a function is executed, the arguments to the
4484function become the positional parameters
bb70624e
JA
4485during its execution.
4486The special parameter
ccc6cda3 4487.B #
495aee44 4488is updated to reflect the change. Special parameter \fB0\fP
bb70624e 4489is unchanged.
b80f6443 4490The first element of the
bb70624e
JA
4491.SM
4492.B FUNCNAME
4493variable is set to the name of the function while the function
4494is executing.
0001803f 4495.PP
bb70624e 4496All other aspects of the shell execution
ccc6cda3 4497environment are identical between a function and its caller
a0c0a00f 4498with these exceptions: the
ccc6cda3
JA
4499.SM
4500.B DEBUG
95732b49
JA
4501and
4502.B RETURN
4503traps (see the description of the
ccc6cda3
JA
4504.B trap
4505builtin under
4506.SM
4507.B SHELL BUILTIN COMMANDS
95732b49 4508below) are not inherited unless the function has been given the
7117c2d2
JA
4509\fBtrace\fP attribute (see the description of the
4510.SM
4511.B declare
b80f6443
JA
4512builtin below) or the
4513\fB\-o functrace\fP shell option has been enabled with
4514the \fBset\fP builtin
0001803f
CR
4515(in which case all functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps),
4516and the
4517.SM
4518.B ERR
4519trap is not inherited unless the \fB\-o errtrace\fP shell option has
4520been enabled.
726f6388 4521.PP
ccc6cda3
JA
4522Variables local to the function may be declared with the
4523.B local
74091dd4
CR
4524builtin command (\fIlocal variables\fP).
4525Ordinarily, variables and their values
ccc6cda3 4526are shared between the function and its caller.
d233b485
CR
4527If a variable is declared \fBlocal\fP, the variable's visible scope
4528is restricted to that function and its children (including the functions
4529it calls).
74091dd4
CR
4530.PP
4531In the following description, the \fIcurrent scope\fP is a currently-
4532executing function.
4533Previous scopes consist of that function's caller and so on,
4534back to the "global" scope, where the shell is not executing
4535any shell function.
4536Consequently, a local variable at the current scope is a variable
4537declared using the \fBlocal\fP or \fBdeclare\fP builtins in the
4538function that is currently executing.
4539.PP
d233b485
CR
4540Local variables "shadow" variables with the same name declared at
4541previous scopes.
4542For instance, a local variable declared in a function
4543hides a global variable of the same name: references and assignments
4544refer to the local variable, leaving the global variable unmodified.
4545When the function returns, the global variable is once again visible.
4546.PP
4547The shell uses \fIdynamic scoping\fP to control a variable's visibility
4548within functions.
4549With dynamic scoping, visible variables and their values
4550are a result of the sequence of function calls that caused execution
4551to reach the current function.
4552The value of a variable that a function sees depends
4553on its value within its caller, if any, whether that caller is
4554the "global" scope or another shell function.
4555This is also the value that a local variable
4556declaration "shadows", and the value that is restored when the function
4557returns.
4558.PP
4559For example, if a variable \fIvar\fP is declared as local in function
4560\fIfunc1\fP, and \fIfunc1\fP calls another function \fIfunc2\fP,
4561references to \fIvar\fP made from within \fIfunc2\fP will resolve to the
4562local variable \fIvar\fP from \fIfunc1\fP, shadowing any global variable
4563named \fIvar\fP.
4564.PP
4565The \fBunset\fP builtin also acts using the same dynamic scope: if a
4566variable is local to the current scope, \fBunset\fP will unset it;
4567otherwise the unset will refer to the variable found in any calling scope
4568as described above.
4569If a variable at the current local scope is unset, it will remain so
74091dd4 4570(appearing as unset)
d233b485
CR
4571until it is reset in that scope or until the function returns.
4572Once the function returns, any instance of the variable at a previous
4573scope will become visible.
4574If the unset acts on a variable at a previous scope, any instance of a
74091dd4
CR
4575variable with that name that had been shadowed will become visible
4576(see below how the \fBlocalvar_unset\fP shell option changes this behavior).
726f6388 4577.PP
495aee44
CR
4578The \fBFUNCNEST\fP variable, if set to a numeric value greater
4579than 0, defines a maximum function nesting level. Function
4580invocations that exceed the limit cause the entire command to
4581abort.
4582.PP
ccc6cda3
JA
4583If the builtin command
4584.B return
4585is executed in a function, the function completes and
4586execution resumes with the next command after the function
b80f6443
JA
4587call.
4588Any command associated with the \fBRETURN\fP trap is executed
4589before execution resumes.
4590When a function completes, the values of the
ccc6cda3
JA
4591positional parameters and the special parameter
4592.B #
cce855bc 4593are restored to the values they had prior to the function's
ccc6cda3 4594execution.
726f6388 4595.PP
ccc6cda3
JA
4596Function names and definitions may be listed with the
4597.B \-f
726f6388 4598option to the
ccc6cda3
JA
4599.B declare
4600or
4601.B typeset
4602builtin commands. The
4603.B \-F
4604option to
4605.B declare
4606or
4607.B typeset
b80f6443
JA
4608will list the function names only
4609(and optionally the source file and line number, if the \fBextdebug\fP
4610shell option is enabled).
74091dd4
CR
4611Functions may be exported so that child shell processes
4612(those created when executing a separate shell invocation)
ccc6cda3
JA
4613automatically have them defined with the
4614.B \-f
8868edaf 4615option to the
ccc6cda3
JA
4616.B export
4617builtin.
0628567a
JA
4618A function definition may be deleted using the \fB\-f\fP option to
4619the
4620.B unset
4621builtin.
726f6388 4622.PP
495aee44
CR
4623Functions may be recursive.
4624The \fBFUNCNEST\fP variable may be used to limit the depth of the
4625function call stack and restrict the number of function invocations.
4626By default, no limit is imposed on the number of recursive calls.
cce855bc
JA
4627.SH "ARITHMETIC EVALUATION"
4628The shell allows arithmetic expressions to be evaluated, under
b80f6443 4629certain circumstances (see the \fBlet\fP and \fBdeclare\fP builtin
a0c0a00f 4630commands, the \fB((\fP compound command, and \fBArithmetic Expansion\fP).
7117c2d2 4631Evaluation is done in fixed-width integers with no check for overflow,
cce855bc 4632though division by 0 is trapped and flagged as an error.
b80f6443
JA
4633The operators and their precedence, associativity, and values
4634are the same as in the C language.
cce855bc
JA
4635The following list of operators is grouped into levels of
4636equal-precedence operators.
4637The levels are listed in order of decreasing precedence.
726f6388 4638.PP
cce855bc
JA
4639.PD 0
4640.TP
bb70624e
JA
4641.B \fIid\fP++ \fIid\fP\-\-
4642variable post-increment and post-decrement
4643.TP
cce855bc
JA
4644.B \- +
4645unary minus and plus
4646.TP
d233b485
CR
4647.B ++\fIid\fP \-\-\fIid\fP
4648variable pre-increment and pre-decrement
4649.TP
cce855bc
JA
4650.B ! ~
4651logical and bitwise negation
4652.TP
4653.B **
4654exponentiation
4655.TP
4656.B * / %
4657multiplication, division, remainder
4658.TP
4659.B + \-
4660addition, subtraction
4661.TP
4662.B << >>
4663left and right bitwise shifts
4664.TP
4665.B <= >= < >
4666comparison
4667.TP
4668.B == !=
4669equality and inequality
4670.TP
4671.B &
4672bitwise AND
4673.TP
4674.B ^
4675bitwise exclusive OR
4676.TP
4677.B |
4678bitwise OR
4679.TP
4680.B &&
4681logical AND
4682.TP
4683.B ||
4684logical OR
4685.TP
4686.B \fIexpr\fP?\fIexpr\fP:\fIexpr\fP
b80f6443 4687conditional operator
cce855bc
JA
4688.TP
4689.B = *= /= %= += \-= <<= >>= &= ^= |=
4690assignment
bb70624e
JA
4691.TP
4692.B \fIexpr1\fP , \fIexpr2\fP
4693comma
cce855bc 4694.PD
ccc6cda3 4695.PP
cce855bc 4696Shell variables are allowed as operands; parameter expansion is
bb70624e
JA
4697performed before the expression is evaluated.
4698Within an expression, shell variables may also be referenced by name
4699without using the parameter expansion syntax.
b80f6443
JA
4700A shell variable that is null or unset evaluates to 0 when referenced
4701by name without using the parameter expansion syntax.
bb70624e 4702The value of a variable is evaluated as an arithmetic expression
b80f6443 4703when it is referenced, or when a variable which has been given the
d233b485 4704\fIinteger\fP attribute using \fBdeclare \-i\fP is assigned a value.
b80f6443 4705A null value evaluates to 0.
495aee44 4706A shell variable need not have its \fIinteger\fP attribute
cce855bc 4707turned on to be used in an expression.
ccc6cda3 4708.PP
8868edaf
CR
4709Integer constants follow the C language definition, without suffixes or
4710character constants.
cce855bc
JA
4711Constants with a leading 0 are interpreted as octal numbers.
4712A leading 0x or 0X denotes hexadecimal.
495aee44 4713Otherwise, numbers take the form [\fIbase#\fP]n, where the optional \fIbase\fP
cce855bc
JA
4714is a decimal number between 2 and 64 representing the arithmetic
4715base, and \fIn\fP is a number in that base.
bb70624e 4716If \fIbase#\fP is omitted, then base 10 is used.
ac50fbac 4717When specifying \fIn\fP,
8868edaf 4718if a non-digit is required,
a0c0a00f 4719the digits greater than 9 are represented by the lowercase letters,
f73dda09 4720the uppercase letters, @, and _, in that order.
cce855bc 4721If \fIbase\fP is less than or equal to 36, lowercase and uppercase
95732b49 4722letters may be used interchangeably to represent numbers between 10
cce855bc 4723and 35.
ccc6cda3 4724.PP
cce855bc
JA
4725Operators are evaluated in order of precedence. Sub-expressions in
4726parentheses are evaluated first and may override the precedence
4727rules above.
4728.SH "CONDITIONAL EXPRESSIONS"
4729Conditional expressions are used by the \fB[[\fP compound command and
4730the \fBtest\fP and \fB[\fP builtin commands to test file attributes
4731and perform string and arithmetic comparisons.
8868edaf 4732The \fBtest\fP and \fB[\fP commands determine their behavior based on
d233b485
CR
4733the number of arguments; see the descriptions of those commands for any
4734other command-specific actions.
4735.PP
cce855bc 4736Expressions are formed from the following unary or binary primaries.
a0c0a00f
CR
4737\fBBash\fP handles several filenames specially when they are used in
4738expressions.
4739If the operating system on which \fBbash\fP is running provides these
4740special files, bash will use them; otherwise it will emulate them
4741internally with this behavior:
cce855bc 4742If any \fIfile\fP argument to one of the primaries is of the form
bb70624e
JA
4743\fI/dev/fd/n\fP, then file descriptor \fIn\fP is checked.
4744If the \fIfile\fP argument to one of the primaries is one of
4745\fI/dev/stdin\fP, \fI/dev/stdout\fP, or \fI/dev/stderr\fP, file
4746descriptor 0, 1, or 2, respectively, is checked.
95732b49
JA
4747.PP
4748Unless otherwise specified, primaries that operate on files follow symbolic
4749links and operate on the target of the link, rather than the link itself.
0001803f
CR
4750.if t .sp 0.5
4751.if n .sp 1
495aee44 4752When used with \fB[[\fP, the \fB<\fP and \fB>\fP operators sort
0001803f 4753lexicographically using the current locale.
495aee44 4754The \fBtest\fP command sorts using ASCII ordering.
cce855bc
JA
4755.sp 1
4756.PD 0
4757.TP
4758.B \-a \fIfile\fP
4759True if \fIfile\fP exists.
4760.TP
4761.B \-b \fIfile\fP
4762True if \fIfile\fP exists and is a block special file.
4763.TP
4764.B \-c \fIfile\fP
4765True if \fIfile\fP exists and is a character special file.
4766.TP
4767.B \-d \fIfile\fP
4768True if \fIfile\fP exists and is a directory.
4769.TP
4770.B \-e \fIfile\fP
4771True if \fIfile\fP exists.
4772.TP
4773.B \-f \fIfile\fP
4774True if \fIfile\fP exists and is a regular file.
4775.TP
4776.B \-g \fIfile\fP
4777True if \fIfile\fP exists and is set-group-id.
4778.TP
b72432fd
JA
4779.B \-h \fIfile\fP
4780True if \fIfile\fP exists and is a symbolic link.
4781.TP
cce855bc
JA
4782.B \-k \fIfile\fP
4783True if \fIfile\fP exists and its ``sticky'' bit is set.
4784.TP
4785.B \-p \fIfile\fP
4786True if \fIfile\fP exists and is a named pipe (FIFO).
4787.TP
4788.B \-r \fIfile\fP
4789True if \fIfile\fP exists and is readable.
4790.TP
4791.B \-s \fIfile\fP
4792True if \fIfile\fP exists and has a size greater than zero.
4793.TP
4794.B \-t \fIfd\fP
4795True if file descriptor
4796.I fd
4797is open and refers to a terminal.
4798.TP
4799.B \-u \fIfile\fP
4800True if \fIfile\fP exists and its set-user-id bit is set.
4801.TP
4802.B \-w \fIfile\fP
4803True if \fIfile\fP exists and is writable.
4804.TP
4805.B \-x \fIfile\fP
4806True if \fIfile\fP exists and is executable.
4807.TP
cce855bc
JA
4808.B \-G \fIfile\fP
4809True if \fIfile\fP exists and is owned by the effective group id.
4810.TP
4811.B \-L \fIfile\fP
4812True if \fIfile\fP exists and is a symbolic link.
4813.TP
495aee44
CR
4814.B \-N \fIfile\fP
4815True if \fIfile\fP exists and has been modified since it was last read.
4816.TP
4817.B \-O \fIfile\fP
4818True if \fIfile\fP exists and is owned by the effective user id.
4819.TP
cce855bc
JA
4820.B \-S \fIfile\fP
4821True if \fIfile\fP exists and is a socket.
4822.TP
495aee44
CR
4823\fIfile1\fP \fB\-ef\fP \fIfile2\fP
4824True if \fIfile1\fP and \fIfile2\fP refer to the same device and
4825inode numbers.
cce855bc
JA
4826.TP
4827\fIfile1\fP \-\fBnt\fP \fIfile2\fP
7117c2d2
JA
4828True if \fIfile1\fP is newer (according to modification date) than \fIfile2\fP,
4829or if \fIfile1\fP exists and \fPfile2\fP does not.
cce855bc
JA
4830.TP
4831\fIfile1\fP \-\fBot\fP \fIfile2\fP
7117c2d2
JA
4832True if \fIfile1\fP is older than \fIfile2\fP, or if \fIfile2\fP exists
4833and \fIfile1\fP does not.
cce855bc 4834.TP
cce855bc 4835.B \-o \fIoptname\fP
495aee44 4836True if the shell option
cce855bc
JA
4837.I optname
4838is enabled.
4839See the list of options under the description of the
4840.B \-o
4841option to the
4842.B set
4843builtin below.
4844.TP
495aee44
CR
4845.B \-v \fIvarname\fP
4846True if the shell variable
4847.I varname
4848is set (has been assigned a value).
4849.TP
ac50fbac
CR
4850.B \-R \fIvarname\fP
4851True if the shell variable
4852.I varname
4853is set and is a name reference.
4854.TP
cce855bc
JA
4855.B \-z \fIstring\fP
4856True if the length of \fIstring\fP is zero.
4857.TP
cce855bc 4858\fIstring\fP
b80f6443
JA
4859.PD 0
4860.TP
4861.B \-n \fIstring\fP
4862.PD
cce855bc
JA
4863True if the length of
4864.I string
4865is non-zero.
4866.TP
4867\fIstring1\fP \fB==\fP \fIstring2\fP
0001803f
CR
4868.PD 0
4869.TP
4870\fIstring1\fP \fB=\fP \fIstring2\fP
4871.PD
4872True if the strings are equal. \fB=\fP should be used
4873with the \fBtest\fP command for POSIX conformance.
ac50fbac
CR
4874When used with the \fB[[\fP command, this performs pattern matching as
4875described above (\fBCompound Commands\fP).
cce855bc
JA
4876.TP
4877\fIstring1\fP \fB!=\fP \fIstring2\fP
4878True if the strings are not equal.
4879.TP
4880\fIstring1\fP \fB<\fP \fIstring2\fP
0001803f 4881True if \fIstring1\fP sorts before \fIstring2\fP lexicographically.
cce855bc
JA
4882.TP
4883\fIstring1\fP \fB>\fP \fIstring2\fP
0001803f 4884True if \fIstring1\fP sorts after \fIstring2\fP lexicographically.
cce855bc
JA
4885.TP
4886.I \fIarg1\fP \fBOP\fP \fIarg2\fP
4887.SM
4888.B OP
4889is one of
4890.BR \-eq ,
4891.BR \-ne ,
4892.BR \-lt ,
4893.BR \-le ,
4894.BR \-gt ,
4895or
4896.BR \-ge .
4897These arithmetic binary operators return true if \fIarg1\fP
4898is equal to, not equal to, less than, less than or equal to,
4899greater than, or greater than or equal to \fIarg2\fP, respectively.
4900.I Arg1
4901and
4902.I arg2
4903may be positive or negative integers.
d233b485
CR
4904When used with the \fB[[\fP command,
4905.I Arg1
4906and
4907.I Arg2
8868edaf 4908are evaluated as arithmetic expressions (see
d233b485
CR
4909.SM
4910.B "ARITHMETIC EVALUATION"
4911above).
cce855bc
JA
4912.PD
4913.SH "SIMPLE COMMAND EXPANSION"
4914When a simple command is executed, the shell performs the following
8868edaf
CR
4915expansions, assignments, and redirections, from left to right, in
4916the following order.
cce855bc
JA
4917.IP 1.
4918The words that the parser has marked as variable assignments (those
4919preceding the command name) and redirections are saved for later
4920processing.
4921.IP 2.
4922The words that are not variable assignments or redirections are
4923expanded. If any words remain after expansion, the first word
4924is taken to be the name of the command and the remaining words are
4925the arguments.
4926.IP 3.
4927Redirections are performed as described above under
4928.SM
4929.BR REDIRECTION .
4930.IP 4.
4931The text after the \fB=\fP in each variable assignment undergoes tilde
4932expansion, parameter expansion, command substitution, arithmetic expansion,
4933and quote removal before being assigned to the variable.
4934.PP
4935If no command name results, the variable assignments affect the current
74091dd4
CR
4936shell environment.
4937In the case of such a command (one that consists only of assignment
4938statements and redirections), assignment statements are performed before
4939redirections.
4940Otherwise, the variables are added to the environment
cce855bc
JA
4941of the executed command and do not affect the current shell environment.
4942If any of the assignments attempts to assign a value to a readonly variable,
4943an error occurs, and the command exits with a non-zero status.
4944.PP
4945If no command name results, redirections are performed, but do not
4946affect the current shell environment. A redirection error causes the
4947command to exit with a non-zero status.
4948.PP
4949If there is a command name left after expansion, execution proceeds as
4950described below. Otherwise, the command exits. If one of the expansions
4951contained a command substitution, the exit status of the command is
4952the exit status of the last command substitution performed. If there
4953were no command substitutions, the command exits with a status of zero.
4954.SH "COMMAND EXECUTION"
4955After a command has been split into words, if it results in a
4956simple command and an optional list of arguments, the following
4957actions are taken.
4958.PP
4959If the command name contains no slashes, the shell attempts to
4960locate it. If there exists a shell function by that name, that
4961function is invoked as described above in
4962.SM
4963.BR FUNCTIONS .
4964If the name does not match a function, the shell searches for
4965it in the list of shell builtins. If a match is found, that
4966builtin is invoked.
4967.PP
4968If the name is neither a shell function nor a builtin,
4969and contains no slashes,
4970.B bash
4971searches each element of the
4972.SM
4973.B PATH
4974for a directory containing an executable file by that name.
4975.B Bash
bb70624e 4976uses a hash table to remember the full pathnames of executable
cce855bc
JA
4977files (see
4978.B hash
4979under
4980.SM
4981.B "SHELL BUILTIN COMMANDS"
4982below).
4983A full search of the directories in
4984.SM
4985.B PATH
4986is performed only if the command is not found in the hash table.
3185942a
JA
4987If the search is unsuccessful, the shell searches for a defined shell
4988function named \fBcommand_not_found_handle\fP.
d233b485
CR
4989If that function exists, it is invoked in a separate execution environment
4990with the original command and
3185942a 4991the original command's arguments as its arguments, and the function's
d233b485 4992exit status becomes the exit status of that subshell.
3185942a 4993If that function is not defined, the shell prints an error
cce855bc
JA
4994message and returns an exit status of 127.
4995.PP
4996If the search is successful, or if the command name contains
4997one or more slashes, the shell executes the named program in a
4998separate execution environment.
4999Argument 0 is set to the name given, and the remaining arguments
5000to the command are set to the arguments given, if any.
5001.PP
5002If this execution fails because the file is not in executable
5003format, and the file is not a directory, it is assumed to be
5004a \fIshell script\fP, a file
74091dd4
CR
5005containing shell commands, and the shell creates a
5006new instance of itself
5007to execute it.
5008This subshell reinitializes itself, so
cce855bc
JA
5009that the effect is as if a new shell had been invoked
5010to handle the script, with the exception that the locations of
5011commands remembered by the parent (see
5012.B hash
5013below under
5014.SM
5015\fBSHELL BUILTIN COMMANDS\fP)
5016are retained by the child.
5017.PP
5018If the program is a file beginning with
5019.BR #! ,
5020the remainder of the first line specifies an interpreter
5021for the program. The shell executes the
5022specified interpreter on operating systems that do not
a0c0a00f 5023handle this executable format themselves. The arguments to the
cce855bc
JA
5024interpreter consist of a single optional argument following the
5025interpreter name on the first line of the program, followed
5026by the name of the program, followed by the command
5027arguments, if any.
5028.SH COMMAND EXECUTION ENVIRONMENT
5029The shell has an \fIexecution environment\fP, which consists of the
5030following:
cce855bc
JA
5031.IP \(bu
5032open files inherited by the shell at invocation, as modified by
5033redirections supplied to the \fBexec\fP builtin
5034.IP \(bu
5035the current working directory as set by \fBcd\fP, \fBpushd\fP, or
5036\fBpopd\fP, or inherited by the shell at invocation
5037.IP \(bu
5038the file creation mode mask as set by \fBumask\fP or inherited from
5039the shell's parent
5040.IP \(bu
5041current traps set by \fBtrap\fP
5042.IP \(bu
5043shell parameters that are set by variable assignment or with \fBset\fP
5044or inherited from the shell's parent in the environment
5045.IP \(bu
5046shell functions defined during execution or inherited from the shell's
5047parent in the environment
5048.IP \(bu
5049options enabled at invocation (either by default or with command-line
5050arguments) or by \fBset\fP
5051.IP \(bu
5052options enabled by \fBshopt\fP
5053.IP \(bu
5054shell aliases defined with \fBalias\fP
5055.IP \(bu
5056various process IDs, including those of background jobs, the value
0001803f
CR
5057of \fB$$\fP, and the value of
5058.SM
5059.B PPID
cce855bc
JA
5060.PP
5061When a simple command other than a builtin or shell function
5062is to be executed, it
5063is invoked in a separate execution environment that consists of
74091dd4
CR
5064the following.
5065Unless otherwise noted, the values are inherited from the shell.
0001803f 5066.if n .sp 1
cce855bc
JA
5067.IP \(bu
5068the shell's open files, plus any modifications and additions specified
5069by redirections to the command
5070.IP \(bu
5071the current working directory
5072.IP \(bu
5073the file creation mode mask
5074.IP \(bu
b80f6443
JA
5075shell variables and functions marked for export, along with variables
5076exported for the command, passed in the environment
cce855bc 5077.IP \(bu
b80f6443
JA
5078traps caught by the shell are reset to the values inherited from the
5079shell's parent, and traps ignored by the shell are ignored
cce855bc
JA
5080.PP
5081A command invoked in this separate environment cannot affect the
a0c0a00f 5082shell's execution environment.
cce855bc 5083.PP
74091dd4
CR
5084A \fIsubshell\fP is a copy of the shell process.
5085.PP
b80f6443
JA
5086Command substitution, commands grouped with parentheses,
5087and asynchronous commands are invoked in a
cce855bc
JA
5088subshell environment that is a duplicate of the shell environment,
5089except that traps caught by the shell are reset to the values
5090that the shell inherited from its parent at invocation. Builtin
5091commands that are invoked as part of a pipeline are also executed in a
5092subshell environment. Changes made to the subshell environment
5093cannot affect the shell's execution environment.
f73dda09 5094.PP
3185942a 5095Subshells spawned to execute command substitutions inherit the value of
d233b485 5096the \fB\-e\fP option from the parent shell. When not in \fIposix mode\fP,
495aee44 5097\fBbash\fP clears the \fB\-e\fP option in such subshells.
3185942a 5098.PP
f73dda09
JA
5099If a command is followed by a \fB&\fP and job control is not active, the
5100default standard input for the command is the empty file \fI/dev/null\fP.
5101Otherwise, the invoked command inherits the file descriptors of the calling
5102shell as modified by redirections.
cce855bc
JA
5103.SH ENVIRONMENT
5104When a program is invoked it is given an array of strings
5105called the
5106.IR environment .
a0c0a00f 5107This is a list of
cce855bc
JA
5108\fIname\fP\-\fIvalue\fP pairs, of the form
5109.IR "name\fR=\fPvalue" .
5110.PP
bb70624e
JA
5111The shell provides several ways to manipulate the environment.
5112On invocation, the shell scans its own environment and
cce855bc
JA
5113creates a parameter for each name found, automatically marking
5114it for
5115.I export
5116to child processes. Executed commands inherit the environment.
5117The
5118.B export
5119and
5120.B declare \-x
5121commands allow parameters and functions to be added to and
5122deleted from the environment. If the value of a parameter
5123in the environment is modified, the new value becomes part
5124of the environment, replacing the old. The environment
5125inherited by any executed command consists of the shell's
5126initial environment, whose values may be modified in the shell,
5127less any pairs removed by the
5128.B unset
5129command, plus any additions via the
5130.B export
5131and
5132.B declare \-x
5133commands.
5134.PP
5135The environment for any
5136.I simple command
5137or function may be augmented temporarily by prefixing it with
5138parameter assignments, as described above in
5139.SM
5140.BR PARAMETERS .
5141These assignment statements affect only the environment seen
5142by that command.
5143.PP
a0c0a00f 5144If the
cce855bc
JA
5145.B \-k
5146option is set (see the
5147.B set
5148builtin command below), then
5149.I all
5150parameter assignments are placed in the environment for a command,
5151not just those that precede the command name.
5152.PP
5153When
5154.B bash
5155invokes an external command, the variable
5156.B _
ac50fbac 5157is set to the full filename of the command and passed to that
ccc6cda3
JA
5158command in its environment.
5159.SH "EXIT STATUS"
3185942a
JA
5160The exit status of an executed command is the value returned by the
5161\fIwaitpid\fP system call or equivalent function. Exit statuses
5162fall between 0 and 255, though, as explained below, the shell may
5163use values above 125 specially. Exit statuses from shell builtins and
a0c0a00f 5164compound commands are also limited to this range. Under certain
3185942a
JA
5165circumstances, the shell will use special values to indicate specific
5166failure modes.
5167.PP
a0c0a00f 5168For the shell's purposes, a command which exits with a
ccc6cda3
JA
5169zero exit status has succeeded. An exit status of zero
5170indicates success. A non-zero exit status indicates failure.
bb70624e
JA
5171When a command terminates on a fatal signal \fIN\fP, \fBbash\fP uses
5172the value of 128+\fIN\fP as the exit status.
ccc6cda3
JA
5173.PP
5174If a command is not found, the child process created to
5175execute it returns a status of 127. If a command is found
5176but is not executable, the return status is 126.
5177.PP
cce855bc
JA
5178If a command fails because of an error during expansion or redirection,
5179the exit status is greater than zero.
5180.PP
ccc6cda3
JA
5181Shell builtin commands return a status of 0 (\fItrue\fP) if
5182successful, and non-zero (\fIfalse\fP) if an error occurs
a0c0a00f
CR
5183while they execute.
5184All builtins return an exit status of 2 to indicate incorrect usage,
5185generally invalid options or missing arguments.
ccc6cda3 5186.PP
74091dd4
CR
5187The exit status of the last command is available in the special
5188parameter $?.
5189.PP
ccc6cda3
JA
5190\fBBash\fP itself returns the exit status of the last command
5191executed, unless a syntax error occurs, in which case it exits
5192with a non-zero value. See also the \fBexit\fP builtin
5193command below.
5194.SH SIGNALS
cce855bc 5195When \fBbash\fP is interactive, in the absence of any traps, it ignores
ccc6cda3
JA
5196.SM
5197.B SIGTERM
5198(so that \fBkill 0\fP does not kill an interactive shell),
5199and
5200.SM
5201.B SIGINT
5202is caught and handled (so that the \fBwait\fP builtin is interruptible).
5203In all cases, \fBbash\fP ignores
5204.SM
5205.BR SIGQUIT .
5206If job control is in effect,
5207.B bash
5208ignores
5209.SM
5210.BR SIGTTIN ,
5211.SM
5212.BR SIGTTOU ,
5213and
5214.SM
5215.BR SIGTSTP .
5216.PP
b80f6443 5217Non-builtin commands run by \fBbash\fP have signal handlers
cce855bc
JA
5218set to the values inherited by the shell from its parent.
5219When job control is not in effect, asynchronous commands
ccc6cda3
JA
5220ignore
5221.SM
5222.B SIGINT
5223and
5224.SM
cce855bc 5225.B SIGQUIT
b80f6443 5226in addition to these inherited handlers.
ccc6cda3
JA
5227Commands run as a result of command substitution ignore the
5228keyboard-generated job control signals
5229.SM
5230.BR SIGTTIN ,
5231.SM
5232.BR SIGTTOU ,
5233and
5234.SM
5235.BR SIGTSTP .
5236.PP
5237The shell exits by default upon receipt of a
5238.SM
5239.BR SIGHUP .
f73dda09 5240Before exiting, an interactive shell resends the
ccc6cda3
JA
5241.SM
5242.B SIGHUP
cce855bc
JA
5243to all jobs, running or stopped.
5244Stopped jobs are sent
5245.SM
5246.B SIGCONT
5247to ensure that they receive the
5248.SM
5249.BR SIGHUP .
5250To prevent the shell from
5251sending the signal to a particular job, it should be removed from the
a0c0a00f 5252jobs table with the
ccc6cda3
JA
5253.B disown
5254builtin (see
5255.SM
5256.B "SHELL BUILTIN COMMANDS"
a0c0a00f 5257below) or marked
cce855bc 5258to not receive
ccc6cda3 5259.SM
cce855bc
JA
5260.B SIGHUP
5261using
5262.BR "disown \-h" .
5263.PP
5264If the
5265.B huponexit
5266shell option has been set with
5267.BR shopt ,
5268.B bash
a0c0a00f 5269sends a
cce855bc
JA
5270.SM
5271.B SIGHUP
5272to all jobs when an interactive login shell exits.
5273.PP
95732b49 5274If \fBbash\fP is waiting for a command to complete and receives a signal
b80f6443 5275for which a trap has been set, the trap will not be executed until
a0c0a00f 5276the command completes.
cce855bc
JA
5277When \fBbash\fP is waiting for an asynchronous command via the \fBwait\fP
5278builtin, the reception of a signal for which a trap has been set will
5279cause the \fBwait\fP builtin to return immediately with an exit status
5280greater than 128, immediately after which the trap is executed.
74091dd4
CR
5281.PP
5282When job control is not enabled, and \fBbash\fP is waiting for a foreground
5283command to complete, the shell receives keyboard-generated signals
5284such as
5285.SM
5286.B SIGINT
5287(usually generated by \fB^C\fP) that users commonly intend to send
5288to that command.
5289This happens because the shell and the command are in the
5290same process group as the terminal, and \fB^C\fP sends
5291.SM
5292.B SIGINT
5293to all processes in that process group.
5294.PP
5295When \fBbash\fP is running without job control enabled and receives
5296.SM
5297.B SIGINT
5298while waiting for a foreground command, it waits until that foreground
5299command terminates and then decides what to do about the
5300.SM
5301.BR SIGINT :
5302.IP 1.
5303If the command terminates due to the
5304.SM
5305.BR SIGINT ,
5306\fBbash\fP concludes
5307that the user meant to end the entire script, and acts on the
5308.SM
5309.B SIGINT
5310(e.g., by running a
5311.SM
5312.B SIGINT
5313trap or exiting itself);
5314.IP 2.
5315If the command does not terminate due to
5316.SM
5317.BR SIGINT ,
5318the program handled the
5319.SM
5320.B SIGINT
5321itself and did not treat it as a fatal signal.
5322In that case, \fBbash\fP does not treat
5323.SM
5324.B SIGINT
5325as a fatal signal, either, instead assuming that the
5326.SM
5327.B SIGINT
5328was used as part of the program's normal operation
5329(e.g., emacs uses it to abort editing
5330commands) or deliberately discarded.
5331However, \fBbash\fP will run any
5332trap set on
5333.SM
5334.BR SIGINT ,
5335as it does with any other trapped signal it
5336receives while it is waiting for the foreground command to
5337complete, for compatibility.
ccc6cda3
JA
5338.SH "JOB CONTROL"
5339.I Job control
5340refers to the ability to selectively stop (\fIsuspend\fP)
5341the execution of processes and continue (\fIresume\fP)
5342their execution at a later point. A user typically employs
5343this facility via an interactive interface supplied jointly
0001803f 5344by the operating system kernel's terminal driver and
ccc6cda3
JA
5345.BR bash .
5346.PP
5347The shell associates a
5348.I job
5349with each pipeline. It keeps a table of currently executing
5350jobs, which may be listed with the
5351.B jobs
5352command. When
5353.B bash
5354starts a job asynchronously (in the
5355.IR background ),
5356it prints a line that looks like:
5357.RS
5358.PP
5359[1] 25647
5360.RE
5361.PP
5362indicating that this job is job number 1 and that the process ID
5363of the last process in the pipeline associated with this job is 25647.
5364All of the processes in a single pipeline are members of the same job.
5365.B Bash
5366uses the
5367.I job
5368abstraction as the basis for job control.
5369.PP
5370To facilitate the implementation of the user interface to job
bb70624e 5371control, the operating system maintains the notion of a \fIcurrent terminal
ccc6cda3
JA
5372process group ID\fP. Members of this process group (processes whose
5373process group ID is equal to the current terminal process group ID)
5374receive keyboard-generated signals such as
5375.SM
5376.BR SIGINT .
5377These processes are said to be in the
5378.IR foreground .
5379.I Background
5380processes are those whose process group ID differs from the terminal's;
5381such processes are immune to keyboard-generated signals.
0001803f
CR
5382Only foreground processes are allowed to read from or, if the
5383user so specifies with \f(CWstty tostop\fP, write to the
5384terminal.
5385Background processes which attempt to read from (write to when
5386\f(CWstty tostop\fP is in effect) the
a0c0a00f 5387terminal are sent a
ccc6cda3
JA
5388.SM
5389.B SIGTTIN (SIGTTOU)
8868edaf 5390signal by the kernel's terminal driver,
ccc6cda3
JA
5391which, unless caught, suspends the process.
5392.PP
5393If the operating system on which
5394.B bash
5395is running supports
5396job control,
5397.B bash
bb70624e 5398contains facilities to use it.
ccc6cda3
JA
5399Typing the
5400.I suspend
5401character (typically
5402.BR ^Z ,
5403Control-Z) while a process is running
a0c0a00f 5404causes that process to be stopped and returns control to
ccc6cda3
JA
5405.BR bash .
5406Typing the
5407.I "delayed suspend"
5408character (typically
5409.BR ^Y ,
5410Control-Y) causes the process to be stopped when it
5411attempts to read input from the terminal, and control to
5412be returned to
5413.BR bash .
cce855bc 5414The user may then manipulate the state of this job, using the
ccc6cda3
JA
5415.B bg
5416command to continue it in the background, the
5417.B fg
5418command to continue it in the foreground, or
5419the
5420.B kill
5421command to kill it. A \fB^Z\fP takes effect immediately,
5422and has the additional side effect of causing pending output
5423and typeahead to be discarded.
5424.PP
5425There are a number of ways to refer to a job in the shell.
5426The character
5427.B %
3185942a 5428introduces a job specification (\fIjobspec\fP). Job number
ccc6cda3
JA
5429.I n
5430may be referred to as
5431.BR %n .
5432A job may also be referred to using a prefix of the name used to
5433start it, or using a substring that appears in its command line.
5434For example,
5435.B %ce
5436refers to a stopped
8868edaf
CR
5437job whose command name begins with
5438.BR ce .
5439If a prefix matches more than one job,
ccc6cda3
JA
5440.B bash
5441reports an error. Using
5442.BR %?ce ,
5443on the other hand, refers to any job containing the string
5444.B ce
5445in its command line. If the substring matches more than one job,
5446.B bash
5447reports an error. The symbols
5448.B %%
5449and
5450.B %+
5451refer to the shell's notion of the
5452.IR "current job" ,
5453which is the last job stopped while it was in
cce855bc 5454the foreground or started in the background.
a0c0a00f 5455The
ccc6cda3
JA
5456.I "previous job"
5457may be referenced using
5458.BR %\- .
3185942a
JA
5459If there is only a single job, \fB%+\fP and \fB%\-\fP can both be used
5460to refer to that job.
ccc6cda3
JA
5461In output pertaining to jobs (e.g., the output of the
5462.B jobs
5463command), the current job is always flagged with a
5464.BR + ,
5465and the previous job with a
5466.BR \- .
95732b49
JA
5467A single % (with no accompanying job specification) also refers to the
5468current job.
726f6388 5469.PP
ccc6cda3
JA
5470Simply naming a job can be used to bring it into the
5471foreground:
5472.B %1
5473is a synonym for
5474\fB``fg %1''\fP,
5475bringing job 1 from the background into the foreground.
5476Similarly,
5477.B ``%1 &''
5478resumes job 1 in the background, equivalent to
5479\fB``bg %1''\fP.
726f6388 5480.PP
ccc6cda3
JA
5481The shell learns immediately whenever a job changes state.
5482Normally,
5483.B bash
5484waits until it is about to print a prompt before reporting
5485changes in a job's status so as to not interrupt
a0c0a00f 5486any other output. If the
ccc6cda3
JA
5487.B \-b
5488option to the
726f6388 5489.B set
ccc6cda3 5490builtin command
cce855bc 5491is enabled,
726f6388 5492.B bash
ccc6cda3 5493reports such changes immediately.
f73dda09
JA
5494Any trap on
5495.SM
5496.B SIGCHLD
5497is executed for each child that exits.
726f6388 5498.PP
ccc6cda3
JA
5499If an attempt to exit
5500.B bash
3185942a
JA
5501is made while jobs are stopped (or, if the \fBcheckjobs\fP shell option has
5502been enabled using the \fBshopt\fP builtin, running), the shell prints a
5503warning message, and, if the \fBcheckjobs\fP option is enabled, lists the
5504jobs and their statuses.
5505The
ccc6cda3 5506.B jobs
a0c0a00f 5507command may then be used to inspect their status.
ccc6cda3 5508If a second attempt to exit is made without an intervening command,
3185942a 5509the shell does not print another warning, and any stopped
ccc6cda3 5510jobs are terminated.
d233b485
CR
5511.PP
5512When the shell is waiting for a job or process using the \fBwait\fP
5513builtin, and job control is enabled, \fBwait\fP will return when the
8868edaf 5514job changes state. The \fB\-f\fP option causes \fBwait\fP to wait
d233b485 5515until the job or process terminates before returning.
726f6388 5516.SH PROMPTING
a0c0a00f 5517When executing interactively,
726f6388
JA
5518.B bash
5519displays the primary prompt
5520.SM
5521.B PS1
5522when it is ready to read a command, and the secondary prompt
5523.SM
5524.B PS2
5525when it needs more input to complete a command.
5526.B Bash
a0c0a00f 5527displays
d233b485 5528.SM
a0c0a00f
CR
5529.B PS0
5530after it reads a command but before executing it.
5531.B Bash
d233b485
CR
5532displays
5533.SM
5534.B PS4
5535as described above
5536before tracing each command when the \fB\-x\fP option is enabled.
5537.B Bash
726f6388
JA
5538allows these prompt strings to be customized by inserting a number of
5539backslash-escaped special characters that are decoded as follows:
5540.RS
5541.PD 0
5542.TP
ccc6cda3
JA
5543.B \ea
5544an ASCII bell character (07)
726f6388
JA
5545.TP
5546.B \ed
5547the date in "Weekday Month Date" format (e.g., "Tue May 26")
5548.TP
7117c2d2
JA
5549.B \eD{\fIformat\fP}
5550the \fIformat\fP is passed to \fIstrftime\fP(3) and the result is inserted
5551into the prompt string; an empty \fIformat\fP results in a locale-specific
5552time representation. The braces are required
5553.TP
ccc6cda3
JA
5554.B \ee
5555an ASCII escape character (033)
5556.TP
5557.B \eh
5558the hostname up to the first `.'
5559.TP
5560.B \eH
5561the hostname
5562.TP
bb70624e
JA
5563.B \ej
5564the number of jobs currently managed by the shell
5565.TP
5566.B \el
5567the basename of the shell's terminal device name
5568.TP
726f6388
JA
5569.B \en
5570newline
5571.TP
cce855bc
JA
5572.B \er
5573carriage return
5574.TP
726f6388
JA
5575.B \es
5576the name of the shell, the basename of
5577.B $0
5578(the portion following the final slash)
5579.TP
ccc6cda3
JA
5580.B \et
5581the current time in 24-hour HH:MM:SS format
726f6388 5582.TP
ccc6cda3
JA
5583.B \eT
5584the current time in 12-hour HH:MM:SS format
5585.TP
5586.B \e@
5587the current time in 12-hour am/pm format
726f6388 5588.TP
f73dda09
JA
5589.B \eA
5590the current time in 24-hour HH:MM format
5591.TP
726f6388
JA
5592.B \eu
5593the username of the current user
5594.TP
ccc6cda3
JA
5595.B \ev
5596the version of \fBbash\fP (e.g., 2.00)
726f6388 5597.TP
ccc6cda3 5598.B \eV
b80f6443 5599the release of \fBbash\fP, version + patch level (e.g., 2.00.0)
ccc6cda3
JA
5600.TP
5601.B \ew
74091dd4
CR
5602the value of the \fBPWD\fP shell variable (\fB$PWD\fP),
5603with
0001803f
CR
5604.SM
5605.B $HOME
5606abbreviated with a tilde
5607(uses the value of the
5608.SM
5609.B PROMPT_DIRTRIM
5610variable)
ccc6cda3
JA
5611.TP
5612.B \eW
74091dd4
CR
5613the basename of \fB$PWD\fP,
5614with
0001803f
CR
5615.SM
5616.B $HOME
b80f6443 5617abbreviated with a tilde
726f6388
JA
5618.TP
5619.B \e!
5620the history number of this command
5621.TP
ccc6cda3
JA
5622.B \e#
5623the command number of this command
5624.TP
726f6388
JA
5625.B \e$
5626if the effective UID is 0, a
5627.BR # ,
5628otherwise a
5629.B $
5630.TP
ccc6cda3
JA
5631.B \e\fInnn\fP
5632the character corresponding to the octal number \fInnn\fP
726f6388
JA
5633.TP
5634.B \e\e
5635a backslash
5636.TP
5637.B \e[
5638begin a sequence of non-printing characters, which could be used to
5639embed a terminal control sequence into the prompt
5640.TP
5641.B \e]
5642end a sequence of non-printing characters
5643.PD
5644.RE
5645.PP
5646The command number and the history number are usually different:
5647the history number of a command is its position in the history
5648list, which may include commands restored from the history file
5649(see
5650.SM
5651.B HISTORY
5652below), while the command number is the position in the sequence
5653of commands executed during the current shell session.
5654After the string is decoded, it is expanded via
bb70624e
JA
5655parameter expansion, command substitution, arithmetic
5656expansion, and quote removal, subject to the value of the
ccc6cda3
JA
5657.B promptvars
5658shell option (see the description of the
5659.B shopt
5660command under
5661.SM
5662.B "SHELL BUILTIN COMMANDS"
5663below).
8868edaf
CR
5664This can have unwanted side effects if escaped portions of the string
5665appear within command substitution or contain characters special to
5666word expansion.
726f6388
JA
5667.SH READLINE
5668This is the library that handles reading input when using an interactive
5669shell, unless the
d166f048 5670.B \-\-noediting
ccc6cda3 5671option is given at shell invocation.
3185942a
JA
5672Line editing is also used when using the \fB\-e\fP option to the
5673\fBread\fP builtin.
495aee44 5674By default, the line editing commands are similar to those of Emacs.
726f6388 5675A vi-style line editing interface is also available.
3185942a
JA
5676Line editing can be enabled at any time using the
5677.B \-o emacs
ccc6cda3 5678or
3185942a 5679.B \-o vi
ccc6cda3
JA
5680options to the
5681.B set
5682builtin (see
5683.SM
5684.B SHELL BUILTIN COMMANDS
5685below).
3185942a
JA
5686To turn off line editing after the shell is running, use the
5687.B +o emacs
5688or
5689.B +o vi
5690options to the
5691.B set
5692builtin.
ccc6cda3 5693.SS "Readline Notation"
495aee44 5694In this section, the Emacs-style notation is used to denote
726f6388 5695keystrokes. Control keys are denoted by C\-\fIkey\fR, e.g., C\-n
a0c0a00f 5696means Control\-N. Similarly,
726f6388
JA
5697.I meta
5698keys are denoted by M\-\fIkey\fR, so M\-x means Meta\-X. (On keyboards
a0c0a00f 5699without a
726f6388
JA
5700.I meta
5701key, M\-\fIx\fP means ESC \fIx\fP, i.e., press the Escape key
5702then the
5703.I x
5704key. This makes ESC the \fImeta prefix\fP.
5705The combination M\-C\-\fIx\fP means ESC\-Control\-\fIx\fP,
5706or press the Escape key
5707then hold the Control key while pressing the
5708.I x
5709key.)
5710.PP
ccc6cda3
JA
5711Readline commands may be given numeric
5712.IR arguments ,
5713which normally act as a repeat count.
5714Sometimes, however, it is the sign of the argument that is significant.
5715Passing a negative argument to a command that acts in the forward
5716direction (e.g., \fBkill\-line\fP) causes that command to act in a
a0c0a00f 5717backward direction.
ccc6cda3
JA
5718Commands whose behavior with arguments deviates from this are noted
5719below.
5720.PP
5721When a command is described as \fIkilling\fP text, the text
5722deleted is saved for possible future retrieval
5723(\fIyanking\fP). The killed text is saved in a
5724\fIkill ring\fP. Consecutive kills cause the text to be
a0c0a00f 5725accumulated into one unit, which can be yanked all at once.
ccc6cda3
JA
5726Commands which do not kill text separate the chunks of text
5727on the kill ring.
5728.SS "Readline Initialization"
ccc6cda3
JA
5729Readline is customized by putting commands in an initialization
5730file (the \fIinputrc\fP file).
5731The name of this file is taken from the value of the
726f6388 5732.SM
ccc6cda3
JA
5733.B INPUTRC
5734variable. If that variable is unset, the default is
726f6388 5735.IR ~/.inputrc .
8868edaf
CR
5736If that file does not exist or cannot be read, the ultimate default is
5737.IR /etc/inputrc .
ccc6cda3
JA
5738When a program which uses the readline library starts up, the
5739initialization file is read, and the key bindings and variables
5740are set.
5741There are only a few basic constructs allowed in the
5742readline initialization file.
5743Blank lines are ignored.
5744Lines beginning with a \fB#\fP are comments.
5745Lines beginning with a \fB$\fP indicate conditional constructs.
5746Other lines denote key bindings and variable settings.
5747.PP
5748The default key-bindings may be changed with an
a0c0a00f 5749.I inputrc
ccc6cda3 5750file.
726f6388
JA
5751Other programs that use this library may add their own commands
5752and bindings.
5753.PP
5754For example, placing
5755.RS
5756.PP
5757M\-Control\-u: universal\-argument
5758.RE
5759or
5760.RS
5761C\-Meta\-u: universal\-argument
5762.RE
a0c0a00f 5763into the
ccc6cda3 5764.I inputrc
726f6388
JA
5765would make M\-C\-u execute the readline command
5766.IR universal\-argument .
5767.PP
5768The following symbolic character names are recognized:
5769.IR RUBOUT ,
5770.IR DEL ,
5771.IR ESC ,
5772.IR LFD ,
5773.IR NEWLINE ,
5774.IR RET ,
5775.IR RETURN ,
5776.IR SPC ,
5777.IR SPACE ,
5778and
5779.IR TAB .
bb70624e 5780.PP
726f6388
JA
5781In addition to command names, readline allows keys to be bound
5782to a string that is inserted when the key is pressed (a \fImacro\fP).
ccc6cda3 5783.SS "Readline Key Bindings"
726f6388 5784The syntax for controlling key bindings in the
cce855bc 5785.I inputrc
726f6388
JA
5786file is simple. All that is required is the name of the
5787command or the text of a macro and a key sequence to which
a0c0a00f 5788it should be bound. The name may be specified in one of two ways:
ccc6cda3 5789as a symbolic key name, possibly with \fIMeta\-\fP or \fIControl\-\fP
726f6388 5790prefixes, or as a key sequence.
28ef6c31 5791.PP
cce855bc 5792When using the form \fBkeyname\fP:\^\fIfunction\-name\fP or \fImacro\fP,
726f6388
JA
5793.I keyname
5794is the name of a key spelled out in English. For example:
5795.sp
5796.RS
5797Control-u: universal\-argument
5798.br
5799Meta-Rubout: backward-kill-word
5800.br
ccc6cda3 5801Control-o: "> output"
726f6388
JA
5802.RE
5803.LP
5804In the above example,
ccc6cda3 5805.I C\-u
726f6388
JA
5806is bound to the function
5807.BR universal\-argument ,
ccc6cda3 5808.I M\-DEL
726f6388
JA
5809is bound to the function
5810.BR backward\-kill\-word ,
5811and
ccc6cda3 5812.I C\-o
726f6388
JA
5813is bound to run the macro
5814expressed on the right hand side (that is, to insert the text
28ef6c31
JA
5815.if t \f(CW> output\fP
5816.if n ``> output''
726f6388
JA
5817into the line).
5818.PP
cce855bc 5819In the second form, \fB"keyseq"\fP:\^\fIfunction\-name\fP or \fImacro\fP,
726f6388
JA
5820.B keyseq
5821differs from
5822.B keyname
5823above in that strings denoting
5824an entire key sequence may be specified by placing the sequence
5825within double quotes. Some GNU Emacs style key escapes can be
28ef6c31
JA
5826used, as in the following example, but the symbolic character names
5827are not recognized.
726f6388
JA
5828.sp
5829.RS
ccc6cda3 5830"\eC\-u": universal\-argument
726f6388 5831.br
ccc6cda3 5832"\eC\-x\eC\-r": re\-read\-init\-file
726f6388
JA
5833.br
5834"\ee[11~": "Function Key 1"
5835.RE
5836.PP
5837In this example,
ccc6cda3 5838.I C\-u
726f6388
JA
5839is again bound to the function
5840.BR universal\-argument .
ccc6cda3 5841.I "C\-x C\-r"
726f6388
JA
5842is bound to the function
5843.BR re\-read\-init\-file ,
a0c0a00f 5844and
726f6388
JA
5845.I "ESC [ 1 1 ~"
5846is bound to insert the text
28ef6c31
JA
5847.if t \f(CWFunction Key 1\fP.
5848.if n ``Function Key 1''.
5849.PP
cce855bc 5850The full set of GNU Emacs style escape sequences is
726f6388 5851.RS
cce855bc 5852.PD 0
726f6388
JA
5853.TP
5854.B \eC\-
5855control prefix
5856.TP
ccc6cda3 5857.B \eM\-
726f6388
JA
5858meta prefix
5859.TP
5860.B \ee
5861an escape character
5862.TP
5863.B \e\e
5864backslash
5865.TP
5866.B \e"
5867literal "
5868.TP
0628567a
JA
5869.B \e\(aq
5870literal \(aq
726f6388 5871.RE
cce855bc
JA
5872.PD
5873.PP
5874In addition to the GNU Emacs style escape sequences, a second
5875set of backslash escapes is available:
5876.RS
5877.PD 0
5878.TP
5879.B \ea
5880alert (bell)
5881.TP
5882.B \eb
5883backspace
5884.TP
5885.B \ed
5886delete
5887.TP
5888.B \ef
5889form feed
5890.TP
5891.B \en
5892newline
5893.TP
5894.B \er
5895carriage return
5896.TP
5897.B \et
5898horizontal tab
5899.TP
5900.B \ev
5901vertical tab
5902.TP
5903.B \e\fInnn\fP
f73dda09 5904the eight-bit character whose value is the octal value \fInnn\fP
cce855bc
JA
5905(one to three digits)
5906.TP
f73dda09
JA
5907.B \ex\fIHH\fP
5908the eight-bit character whose value is the hexadecimal value \fIHH\fP
5909(one or two hex digits)
cce855bc
JA
5910.RE
5911.PD
726f6388 5912.PP
cce855bc
JA
5913When entering the text of a macro, single or double quotes must
5914be used to indicate a macro definition.
5915Unquoted text is assumed to be a function name.
5916In the macro body, the backslash escapes described above are expanded.
5917Backslash will quote any other character in the macro text,
0628567a 5918including " and \(aq.
726f6388
JA
5919.PP
5920.B Bash
5921allows the current readline key bindings to be displayed or modified
5922with the
5923.B bind
5924builtin command. The editing mode may be switched during interactive
5925use by using the
5926.B \-o
5927option to the
5928.B set
5929builtin command (see
5930.SM
5931.B SHELL BUILTIN COMMANDS
5932below).
ccc6cda3 5933.SS "Readline Variables"
726f6388
JA
5934Readline has variables that can be used to further customize its
5935behavior. A variable may be set in the
5936.I inputrc
5937file with a statement of the form
5938.RS
5939.PP
5940\fBset\fP \fIvariable\-name\fP \fIvalue\fP
5941.RE
8868edaf
CR
5942or using the \fBbind\fP builtin command (see
5943.SM
5944.B SHELL BUILTIN COMMANDS
5945below).
726f6388
JA
5946.PP
5947Except where noted, readline variables can take the values
5948.B On
5949or
95732b49
JA
5950.B Off
5951(without regard to case).
5952Unrecognized variable names are ignored.
5953When a variable value is read, empty or null values, "on" (case-insensitive),
5954and "1" are equivalent to \fBOn\fP. All other values are equivalent to
5955\fBOff\fP.
726f6388
JA
5956The variables and their default values are:
5957.PP
5958.PD 0
5959.TP
74091dd4
CR
5960.B active\-region\-start\-color
5961A string variable that controls the text color and background when displaying
5962the text in the active region (see the description of
5963\fBenable\-active\-region\fP below).
5964This string must not take up any physical character positions on the display,
5965so it should consist only of terminal escape sequences.
5966It is output to the terminal before displaying the text in the active region.
5967This variable is reset to the default value whenever the terminal type changes.
5968The default value is the string that puts the terminal in standout mode,
5969as obtained from the terminal's terminfo description.
5970A sample value might be \f(CW"\ee[01;33m"\fP.
5971.TP
5972.B active\-region\-end\-color
5973A string variable that "undoes" the effects of \fBactive\-region\-start\-color\fP
5974and restores "normal" terminal display appearance after displaying text
5975in the active region.
5976This string must not take up any physical character positions on the display,
5977so it should consist only of terminal escape sequences.
5978It is output to the terminal after displaying the text in the active region.
5979This variable is reset to the default value whenever the terminal type changes.
5980The default value is the string that restores the terminal from standout mode,
5981as obtained from the terminal's terminfo description.
5982A sample value might be \f(CW"\ee[0m"\fP.
5983.TP
726f6388
JA
5984.B bell\-style (audible)
5985Controls what happens when readline wants to ring the terminal bell.
5986If set to \fBnone\fP, readline never rings the bell. If set to
5987\fBvisible\fP, readline uses a visible bell if one is available.
5988If set to \fBaudible\fP, readline attempts to ring the terminal's bell.
5989.TP
95732b49
JA
5990.B bind\-tty\-special\-chars (On)
5991If set to \fBOn\fP, readline attempts to bind the control characters
5992treated specially by the kernel's terminal driver to their readline
5993equivalents.
5994.TP
a0c0a00f
CR
5995.B blink\-matching\-paren (Off)
5996If set to \fBOn\fP, readline attempts to briefly move the cursor to an
5997opening parenthesis when a closing parenthesis is inserted.
5998.TP
5999.B colored\-completion\-prefix (Off)
6000If set to \fBOn\fP, when listing completions, readline displays the
6001common prefix of the set of possible completions using a different color.
6002The color definitions are taken from the value of the \fBLS_COLORS\fP
6003environment variable.
74091dd4
CR
6004If there is a color definition in \fB$LS_COLORS\fP for the custom suffix
6005"readline-colored-completion-prefix", readline uses this color for
6006the common prefix instead of its default.
a0c0a00f 6007.TP
ac50fbac
CR
6008.B colored\-stats (Off)
6009If set to \fBOn\fP, readline displays possible completions using different
a0c0a00f 6010colors to indicate their file type.
ac50fbac
CR
6011The color definitions are taken from the value of the \fBLS_COLORS\fP
6012environment variable.
6013.TP
726f6388 6014.B comment\-begin (``#'')
bb70624e 6015The string that is inserted when the readline
ccc6cda3 6016.B insert\-comment
726f6388 6017command is executed.
ccc6cda3
JA
6018This command is bound to
6019.B M\-#
6020in emacs mode and to
6021.B #
6022in vi command mode.
726f6388 6023.TP
d233b485 6024.B completion\-display\-width (\-1)
a0c0a00f
CR
6025The number of screen columns used to display possible matches
6026when performing completion.
6027The value is ignored if it is less than 0 or greater than the terminal
6028screen width.
6029A value of 0 will cause matches to be displayed one per line.
d233b485 6030The default value is \-1.
a0c0a00f 6031.TP
cce855bc
JA
6032.B completion\-ignore\-case (Off)
6033If set to \fBOn\fP, readline performs filename matching and completion
6034in a case\-insensitive fashion.
6035.TP
a0c0a00f
CR
6036.B completion\-map\-case (Off)
6037If set to \fBOn\fP, and \fBcompletion\-ignore\-case\fP is enabled, readline
6038treats hyphens (\fI\-\fP) and underscores (\fI_\fP) as equivalent when
6039performing case\-insensitive filename matching and completion.
6040.TP
3185942a
JA
6041.B completion\-prefix\-display\-length (0)
6042The length in characters of the common prefix of a list of possible
6043completions that is displayed without modification. When set to a
6044value greater than zero, common prefixes longer than this value are
6045replaced with an ellipsis when displaying possible completions.
6046.TP
726f6388
JA
6047.B completion\-query\-items (100)
6048This determines when the user is queried about viewing
6049the number of possible completions
6050generated by the \fBpossible\-completions\fP command.
8868edaf
CR
6051It may be set to any integer value greater than or equal to zero.
6052If the number of possible completions is greater than
6053or equal to the value of this variable,
6054readline will ask whether or not the user wishes to view them;
6055otherwise they are simply listed on the terminal.
74091dd4
CR
6056A zero value means readline should never ask; negative values are
6057treated as zero.
726f6388 6058.TP
ccc6cda3
JA
6059.B convert\-meta (On)
6060If set to \fBOn\fP, readline will convert characters with the
6061eighth bit set to an ASCII key sequence
bb70624e 6062by stripping the eighth bit and prefixing an
ccc6cda3 6063escape character (in effect, using escape as the \fImeta prefix\fP).
a0c0a00f
CR
6064The default is \fIOn\fP, but readline will set it to \fIOff\fP if the
6065locale contains eight-bit characters.
74091dd4
CR
6066This variable is dependent on the \fBLC_CTYPE\fP locale category, and
6067may change if the locale is changed.
ccc6cda3
JA
6068.TP
6069.B disable\-completion (Off)
6070If set to \fBOn\fP, readline will inhibit word completion. Completion
6071characters will be inserted into the line as if they had been
6072mapped to \fBself-insert\fP.
6073.TP
a0c0a00f
CR
6074.B echo\-control\-characters (On)
6075When set to \fBOn\fP, on operating systems that indicate they support it,
6076readline echoes a character corresponding to a signal generated from the
6077keyboard.
6078.TP
ccc6cda3
JA
6079.B editing\-mode (emacs)
6080Controls whether readline begins with a set of key bindings similar
495aee44 6081to \fIEmacs\fP or \fIvi\fP.
ccc6cda3
JA
6082.B editing\-mode
6083can be set to either
6084.B emacs
6085or
6086.BR vi .
6087.TP
d233b485
CR
6088.B emacs\-mode\-string (@)
6089If the \fIshow\-mode\-in\-prompt\fP variable is enabled,
6090this string is displayed immediately before the last line of the primary
6091prompt when emacs editing mode is active. The value is expanded like a
6092key binding, so the standard set of meta- and control prefixes and
6093backslash escape sequences is available.
6094Use the \e1 and \e2 escapes to begin and end sequences of
6095non-printing characters, which can be used to embed a terminal control
6096sequence into the mode string.
6097.TP
74091dd4
CR
6098.B enable\-active\-region (On)
6099The \fIpoint\fP is the current cursor position, and \fImark\fP refers
6100to a saved cursor position.
6101The text between the point and mark is referred to as the \fIregion\fP.
6102When this variable is set to \fIOn\fP, readline allows certain commands
6103to designate the region as \fIactive\fP.
6104When the region is active, readline highlights the text in the region using
6105the value of the \fBactive\-region\-start\-color\fP, which defaults to the
6106string that enables
6107the terminal's standout mode.
6108The active region shows the text inserted by bracketed-paste and any
6109matching text found by incremental and non-incremental history searches.
6110.TP
8868edaf 6111.B enable\-bracketed\-paste (On)
74091dd4
CR
6112When set to \fBOn\fP, readline configures the terminal to insert each
6113paste into the editing buffer as a single string of characters, instead
6114of treating each character as if it had been read from the keyboard.
6115This prevents readline from executing any editing commands bound to key
6116sequences appearing in the pasted text.
0001803f 6117.TP
ccc6cda3
JA
6118.B enable\-keypad (Off)
6119When set to \fBOn\fP, readline will try to enable the application
6120keypad when it is called. Some systems need this to enable the
6121arrow keys.
6122.TP
0001803f
CR
6123.B enable\-meta\-key (On)
6124When set to \fBOn\fP, readline will try to enable any meta modifier
6125key the terminal claims to support when it is called. On many terminals,
6126the meta key is used to send eight-bit characters.
6127.TP
ccc6cda3 6128.B expand\-tilde (Off)
495aee44 6129If set to \fBOn\fP, tilde expansion is performed when readline
ccc6cda3
JA
6130attempts word completion.
6131.TP
95732b49 6132.B history\-preserve\-point (Off)
495aee44 6133If set to \fBOn\fP, the history code attempts to place point at the
95732b49 6134same location on each history line retrieved with \fBprevious-history\fP
f73dda09
JA
6135or \fBnext-history\fP.
6136.TP
a0c0a00f 6137.B history\-size (unset)
ac50fbac
CR
6138Set the maximum number of history entries saved in the history list.
6139If set to zero, any existing history entries are deleted and no new entries
6140are saved.
6141If set to a value less than zero, the number of history entries is not
6142limited.
a0c0a00f
CR
6143By default, the number of history entries is set to the value of the
6144\fBHISTSIZE\fP shell variable.
6145If an attempt is made to set \fIhistory\-size\fP to a non-numeric value,
6146the maximum number of history entries will be set to 500.
3185942a 6147.TP
ccc6cda3
JA
6148.B horizontal\-scroll\-mode (Off)
6149When set to \fBOn\fP, makes readline use a single line for display,
6150scrolling the input horizontally on a single screen line when it
6151becomes longer than the screen width rather than wrapping to a new line.
8868edaf 6152This setting is automatically enabled for terminals of height 1.
ccc6cda3
JA
6153.TP
6154.B input\-meta (Off)
6155If set to \fBOn\fP, readline will enable eight-bit input (that is,
a0c0a00f 6156it will not strip the eighth bit from the characters it reads),
ccc6cda3
JA
6157regardless of what the terminal claims it can support. The name
6158.B meta\-flag
6159is a synonym for this variable.
a0c0a00f
CR
6160The default is \fIOff\fP, but readline will set it to \fIOn\fP if the
6161locale contains eight-bit characters.
74091dd4
CR
6162This variable is dependent on the \fBLC_CTYPE\fP locale category, and
6163may change if the locale is changed.
ccc6cda3 6164.TP
b72432fd
JA
6165.B isearch\-terminators (``C\-[C\-J'')
6166The string of characters that should terminate an incremental
6167search without subsequently executing the character as a command.
6168If this variable has not been given a value, the characters
6169\fIESC\fP and \fIC\-J\fP will terminate an incremental search.
6170.TP
726f6388 6171.B keymap (emacs)
cce855bc 6172Set the current readline keymap. The set of valid keymap names is
ccc6cda3
JA
6173\fIemacs, emacs\-standard, emacs\-meta, emacs\-ctlx, vi,
6174vi\-command\fP, and
6175.IR vi\-insert .
6176\fIvi\fP is equivalent to \fIvi\-command\fP; \fIemacs\fP is
6177equivalent to \fIemacs\-standard\fP. The default value is
726f6388
JA
6178.IR emacs ;
6179the value of
6180.B editing\-mode
6181also affects the default keymap.
6182.TP
ac50fbac
CR
6183.B keyseq\-timeout (500)
6184Specifies the duration \fIreadline\fP will wait for a character when reading an
6185ambiguous key sequence (one that can form a complete key sequence using
6186the input read so far, or can take additional input to complete a longer
6187key sequence).
6188If no input is received within the timeout, \fIreadline\fP will use the shorter
6189but complete key sequence.
6190The value is specified in milliseconds, so a value of 1000 means that
6191\fIreadline\fP will wait one second for additional input.
6192If this variable is set to a value less than or equal to zero, or to a
6193non-numeric value, \fIreadline\fP will wait until another key is pressed to
6194decide which key sequence to complete.
6195.TP
ccc6cda3
JA
6196.B mark\-directories (On)
6197If set to \fBOn\fP, completed directory names have a slash
6198appended.
6199.TP
6200.B mark\-modified\-lines (Off)
6201If set to \fBOn\fP, history lines that have been modified are displayed
6202with a preceding asterisk (\fB*\fP).
6203.TP
7117c2d2
JA
6204.B mark\-symlinked\-directories (Off)
6205If set to \fBOn\fP, completed names which are symbolic links to directories
6206have a slash appended (subject to the value of
6207\fBmark\-directories\fP).
6208.TP
f73dda09
JA
6209.B match\-hidden\-files (On)
6210This variable, when set to \fBOn\fP, causes readline to match files whose
a0c0a00f 6211names begin with a `.' (hidden files) when performing filename
495aee44
CR
6212completion.
6213If set to \fBOff\fP, the leading `.' must be
f73dda09
JA
6214supplied by the user in the filename to be completed.
6215.TP
495aee44
CR
6216.B menu\-complete\-display\-prefix (Off)
6217If set to \fBOn\fP, menu completion displays the common prefix of the
6218list of possible completions (which may be empty) before cycling through
6219the list.
6220.TP
ccc6cda3
JA
6221.B output\-meta (Off)
6222If set to \fBOn\fP, readline will display characters with the
6223eighth bit set directly rather than as a meta-prefixed escape
6224sequence.
a0c0a00f
CR
6225The default is \fIOff\fP, but readline will set it to \fIOn\fP if the
6226locale contains eight-bit characters.
74091dd4
CR
6227This variable is dependent on the \fBLC_CTYPE\fP locale category, and
6228may change if the locale is changed.
ccc6cda3 6229.TP
7117c2d2
JA
6230.B page\-completions (On)
6231If set to \fBOn\fP, readline uses an internal \fImore\fP-like pager
6232to display a screenful of possible completions at a time.
6233.TP
cce855bc
JA
6234.B print\-completions\-horizontally (Off)
6235If set to \fBOn\fP, readline will display completions with matches
6236sorted horizontally in alphabetical order, rather than down the screen.
a0c0a00f 6237.TP
3185942a 6238.B revert\-all\-at\-newline (Off)
a0c0a00f 6239If set to \fBOn\fP, readline will undo all changes to history lines
3185942a
JA
6240before returning when \fBaccept\-line\fP is executed. By default,
6241history lines may be modified and retain individual undo lists across
6242calls to \fBreadline\fP.
cce855bc 6243.TP
726f6388
JA
6244.B show\-all\-if\-ambiguous (Off)
6245This alters the default behavior of the completion functions. If
6246set to
495aee44 6247.BR On ,
726f6388
JA
6248words which have more than one possible completion cause the
6249matches to be listed immediately instead of ringing the bell.
6250.TP
b80f6443
JA
6251.B show\-all\-if\-unmodified (Off)
6252This alters the default behavior of the completion functions in
6253a fashion similar to \fBshow\-all\-if\-ambiguous\fP.
6254If set to
495aee44 6255.BR On ,
b80f6443
JA
6256words which have more than one possible completion without any
6257possible partial completion (the possible completions don't share
6258a common prefix) cause the matches to be listed immediately instead
6259of ringing the bell.
6260.TP
ac50fbac 6261.B show\-mode\-in\-prompt (Off)
d233b485
CR
6262If set to \fBOn\fP, add a string to the beginning of the prompt
6263indicating the editing mode: emacs, vi command, or vi insertion.
6264The mode strings are user-settable (e.g., \fIemacs\-mode\-string\fP).
ac50fbac 6265.TP
0001803f
CR
6266.B skip\-completed\-text (Off)
6267If set to \fBOn\fP, this alters the default completion behavior when
6268inserting a single match into the line. It's only active when
6269performing completion in the middle of a word. If enabled, readline
6270does not insert characters from the completion that match characters
6271after point in the word being completed, so portions of the word
6272following the cursor are not duplicated.
6273.TP
a0c0a00f 6274.B vi\-cmd\-mode\-string ((cmd))
d233b485
CR
6275If the \fIshow\-mode\-in\-prompt\fP variable is enabled,
6276this string is displayed immediately before the last line of the primary
a0c0a00f
CR
6277prompt when vi editing mode is active and in command mode.
6278The value is expanded like a
6279key binding, so the standard set of meta- and control prefixes and
6280backslash escape sequences is available.
6281Use the \e1 and \e2 escapes to begin and end sequences of
6282non-printing characters, which can be used to embed a terminal control
6283sequence into the mode string.
6284.TP
6285.B vi\-ins\-mode\-string ((ins))
d233b485
CR
6286If the \fIshow\-mode\-in\-prompt\fP variable is enabled,
6287this string is displayed immediately before the last line of the primary
a0c0a00f
CR
6288prompt when vi editing mode is active and in insertion mode.
6289The value is expanded like a
6290key binding, so the standard set of meta- and control prefixes and
6291backslash escape sequences is available.
6292Use the \e1 and \e2 escapes to begin and end sequences of
6293non-printing characters, which can be used to embed a terminal control
6294sequence into the mode string.
6295.TP
ccc6cda3
JA
6296.B visible\-stats (Off)
6297If set to \fBOn\fP, a character denoting a file's type as reported
6298by \fIstat\fP(2) is appended to the filename when listing possible
6299completions.
726f6388 6300.PD
ccc6cda3 6301.SS "Readline Conditional Constructs"
726f6388
JA
6302Readline implements a facility similar in spirit to the conditional
6303compilation features of the C preprocessor which allows key
6304bindings and variable settings to be performed as the result
cce855bc 6305of tests. There are four parser directives used.
726f6388 6306.IP \fB$if\fP
a0c0a00f 6307The
726f6388
JA
6308.B $if
6309construct allows bindings to be made based on the
6310editing mode, the terminal being used, or the application using
d233b485
CR
6311readline. The text of the test, after any comparison operator,
6312 extends to the end of the line;
6313unless otherwise noted, no characters are required to isolate it.
726f6388
JA
6314.RS
6315.IP \fBmode\fP
6316The \fBmode=\fP form of the \fB$if\fP directive is used to test
6317whether readline is in emacs or vi mode.
6318This may be used in conjunction
6319with the \fBset keymap\fP command, for instance, to set bindings in
ccc6cda3 6320the \fIemacs\-standard\fP and \fIemacs\-ctlx\fP keymaps only if
726f6388
JA
6321readline is starting out in emacs mode.
6322.IP \fBterm\fP
6323The \fBterm=\fP form may be used to include terminal-specific
6324key bindings, perhaps to bind the key sequences output by the
6325terminal's function keys. The word on the right side of the
6326.B =
a0c0a00f 6327is tested against both the full name of the terminal and the portion
726f6388
JA
6328of the terminal name before the first \fB\-\fP. This allows
6329.I sun
6330to match both
6331.I sun
6332and
6333.IR sun\-cmd ,
6334for instance.
d233b485
CR
6335.IP \fBversion\fP
6336The \fBversion\fP test may be used to perform comparisons against
6337specific readline versions.
6338The \fBversion\fP expands to the current readline version.
6339The set of comparison operators includes
6340.BR = ,
6341(and
6342.BR == ),
6343.BR != ,
6344.BR <= ,
6345.BR >= ,
6346.BR < ,
6347and
6348.BR > .
6349The version number supplied on the right side of the operator consists
6350of a major version number, an optional decimal point, and an optional
6351minor version (e.g., \fB7.1\fP). If the minor version is omitted, it
6352is assumed to be \fB0\fP.
8868edaf 6353The operator may be separated from the string \fBversion\fP
d233b485 6354and from the version number argument by whitespace.
726f6388
JA
6355.IP \fBapplication\fP
6356The \fBapplication\fP construct is used to include
ccc6cda3 6357application-specific settings. Each program using the readline
726f6388
JA
6358library sets the \fIapplication name\fP, and an initialization
6359file can test for a particular value.
6360This could be used to bind key sequences to functions useful for
6361a specific program. For instance, the following command adds a
495aee44 6362key sequence that quotes the current or previous word in \fBbash\fP:
cce855bc 6363.sp 1
726f6388
JA
6364.RS
6365.nf
6366\fB$if\fP Bash
6367# Quote the current or previous word
ccc6cda3 6368"\eC\-xq": "\eeb\e"\eef\e""
726f6388
JA
6369\fB$endif\fP
6370.fi
6371.RE
d233b485
CR
6372.IP \fIvariable\fP
6373The \fIvariable\fP construct provides simple equality tests for readline
6374variables and values.
6375The permitted comparison operators are \fI=\fP, \fI==\fP, and \fI!=\fP.
6376The variable name must be separated from the comparison operator by
6377whitespace; the operator may be separated from the value on the right hand
6378side by whitespace.
6379Both string and boolean variables may be tested. Boolean variables must be
6380tested against the values \fIon\fP and \fIoff\fP.
726f6388
JA
6381.RE
6382.IP \fB$endif\fP
cce855bc 6383This command, as seen in the previous example, terminates an
726f6388
JA
6384\fB$if\fP command.
6385.IP \fB$else\fP
6386Commands in this branch of the \fB$if\fP directive are executed if
6387the test fails.
cce855bc
JA
6388.IP \fB$include\fP
6389This directive takes a single filename as an argument and reads commands
6390and bindings from that file. For example, the following directive
6391would read \fI/etc/inputrc\fP:
6392.sp 1
6393.RS
6394.nf
6395\fB$include\fP \^ \fI/etc/inputrc\fP
6396.fi
6397.RE
ccc6cda3 6398.SS Searching
ccc6cda3
JA
6399Readline provides commands for searching through the command history
6400(see
6401.SM
6402.B HISTORY
6403below) for lines containing a specified string.
6404There are two search modes:
6405.I incremental
6406and
6407.IR non-incremental .
6408.PP
6409Incremental searches begin before the user has finished typing the
6410search string.
6411As each character of the search string is typed, readline displays
6412the next entry from the history matching the string typed so far.
6413An incremental search requires only as many characters as needed to
6414find the desired history entry.
bb70624e 6415The characters present in the value of the \fBisearch-terminators\fP
b72432fd
JA
6416variable are used to terminate an incremental search.
6417If that variable has not been assigned a value the Escape and
6418Control-J characters will terminate an incremental search.
ccc6cda3
JA
6419Control-G will abort an incremental search and restore the original
6420line.
6421When the search is terminated, the history entry containing the
6422search string becomes the current line.
bb70624e 6423.PP
ccc6cda3
JA
6424To find other matching entries in the history list, type Control-S or
6425Control-R as appropriate.
6426This will search backward or forward in the history for the next
6427entry matching the search string typed so far.
6428Any other key sequence bound to a readline command will terminate
6429the search and execute that command.
6430For instance, a \fInewline\fP will terminate the search and accept
6431the line, thereby executing the command from the history list.
6432.PP
f73dda09
JA
6433Readline remembers the last incremental search string. If two
6434Control-Rs are typed without any intervening characters defining a
6435new search string, any remembered search string is used.
6436.PP
ccc6cda3
JA
6437Non-incremental searches read the entire search string before starting
6438to search for matching history lines. The search string may be
cce855bc 6439typed by the user or be part of the contents of the current line.
ccc6cda3 6440.SS "Readline Command Names"
726f6388
JA
6441The following is a list of the names of the commands and the default
6442key sequences to which they are bound.
ccc6cda3 6443Command names without an accompanying key sequence are unbound by default.
bb70624e
JA
6444In the following descriptions, \fIpoint\fP refers to the current cursor
6445position, and \fImark\fP refers to a cursor position saved by the
6446\fBset\-mark\fP command.
6447The text between the point and mark is referred to as the \fIregion\fP.
726f6388 6448.SS Commands for Moving
726f6388
JA
6449.PD 0
6450.TP
6451.B beginning\-of\-line (C\-a)
6452Move to the start of the current line.
6453.TP
6454.B end\-of\-line (C\-e)
6455Move to the end of the line.
6456.TP
6457.B forward\-char (C\-f)
6458Move forward a character.
6459.TP
6460.B backward\-char (C\-b)
6461Move back a character.
6462.TP
6463.B forward\-word (M\-f)
6464Move forward to the end of the next word. Words are composed of
6465alphanumeric characters (letters and digits).
6466.TP
6467.B backward\-word (M\-b)
3185942a
JA
6468Move back to the start of the current or previous word.
6469Words are composed of alphanumeric characters (letters and digits).
6470.TP
6471.B shell\-forward\-word
6472Move forward to the end of the next word.
6473Words are delimited by non-quoted shell metacharacters.
6474.TP
6475.B shell\-backward\-word
6476Move back to the start of the current or previous word.
6477Words are delimited by non-quoted shell metacharacters.
726f6388 6478.TP
d233b485
CR
6479.B previous\-screen\-line
6480Attempt to move point to the same physical screen column on the previous
6481physical screen line. This will not have the desired effect if the current
74091dd4 6482readline line does not take up more than one physical line or if point is not
d233b485
CR
6483greater than the length of the prompt plus the screen width.
6484.TP
6485.B next\-screen\-line
6486Attempt to move point to the same physical screen column on the next
6487physical screen line. This will not have the desired effect if the current
74091dd4
CR
6488readline line does not take up more than one physical line or if the length
6489of the current readline line is not greater than the length of the prompt
d233b485
CR
6490plus the screen width.
6491.TP
8868edaf
CR
6492.B clear\-display (M\-C\-l)
6493Clear the screen and, if possible, the terminal's scrollback buffer,
6494then redraw the current line,
6495leaving the current line at the top of the screen.
6496.TP
726f6388 6497.B clear\-screen (C\-l)
8868edaf
CR
6498Clear the screen,
6499then redraw the current line,
6500leaving the current line at the top of the screen.
726f6388
JA
6501With an argument, refresh the current line without clearing the
6502screen.
6503.TP
6504.B redraw\-current\-line
ccc6cda3 6505Refresh the current line.
726f6388
JA
6506.PD
6507.SS Commands for Manipulating the History
726f6388
JA
6508.PD 0
6509.TP
6510.B accept\-line (Newline, Return)
6511Accept the line regardless of where the cursor is. If this line is
ccc6cda3 6512non-empty, add it to the history list according to the state of the
726f6388
JA
6513.SM
6514.B HISTCONTROL
6515variable. If the line is a modified history
6516line, then restore the history line to its original state.
6517.TP
6518.B previous\-history (C\-p)
6519Fetch the previous command from the history list, moving back in
6520the list.
6521.TP
6522.B next\-history (C\-n)
6523Fetch the next command from the history list, moving forward in the
6524list.
6525.TP
6526.B beginning\-of\-history (M\-<)
6527Move to the first line in the history.
6528.TP
6529.B end\-of\-history (M\->)
6530Move to the end of the input history, i.e., the line currently being
6531entered.
6532.TP
74091dd4
CR
6533.B operate\-and\-get\-next (C\-o)
6534Accept the current line for execution and fetch the next line
6535relative to the current line from the history for editing.
6536A numeric argument, if supplied, specifies the history entry to use instead
6537of the current line.
6538.TP
6539.B
6540fetch\-history
6541With a numeric argument, fetch that entry from the history list
6542and make it the current line.
6543Without an argument, move back to the first entry in the history list.
6544.TP
726f6388
JA
6545.B reverse\-search\-history (C\-r)
6546Search backward starting at the current line and moving `up' through
6547the history as necessary. This is an incremental search.
6548.TP
6549.B forward\-search\-history (C\-s)
6550Search forward starting at the current line and moving `down' through
6551the history as necessary. This is an incremental search.
6552.TP
6553.B non\-incremental\-reverse\-search\-history (M\-p)
6554Search backward through the history starting at the current line
ccc6cda3 6555using a non-incremental search for a string supplied by the user.
726f6388
JA
6556.TP
6557.B non\-incremental\-forward\-search\-history (M\-n)
ccc6cda3 6558Search forward through the history using a non-incremental search for
726f6388
JA
6559a string supplied by the user.
6560.TP
6561.B history\-search\-forward
6562Search forward through the history for the string of characters
bb70624e 6563between the start of the current line and the point.
ccc6cda3 6564This is a non-incremental search.
726f6388
JA
6565.TP
6566.B history\-search\-backward
6567Search backward through the history for the string of characters
ccc6cda3
JA
6568between the start of the current line and the point.
6569This is a non-incremental search.
726f6388 6570.TP
d233b485 6571.B history\-substring\-search\-backward
8868edaf 6572Search backward through the history for the string of characters
d233b485
CR
6573between the start of the current line and the current cursor
6574position (the \fIpoint\fP).
6575The search string may match anywhere in a history line.
6576This is a non-incremental search.
6577.TP
6578.B history\-substring\-search\-forward
6579Search forward through the history for the string of characters
6580between the start of the current line and the point.
6581The search string may match anywhere in a history line.
6582This is a non-incremental search.
6583.TP
726f6388
JA
6584.B yank\-nth\-arg (M\-C\-y)
6585Insert the first argument to the previous command (usually
28ef6c31
JA
6586the second word on the previous line) at point.
6587With an argument
726f6388
JA
6588.IR n ,
6589insert the \fIn\fPth word from the previous command (the words
6590in the previous command begin with word 0). A negative argument
6591inserts the \fIn\fPth word from the end of the previous command.
95732b49
JA
6592Once the argument \fIn\fP is computed, the argument is extracted
6593as if the "!\fIn\fP" history expansion had been specified.
726f6388
JA
6594.TP
6595.B
6596yank\-last\-arg (M\-.\^, M\-_\^)
ccc6cda3 6597Insert the last argument to the previous command (the last word of
495aee44
CR
6598the previous history entry).
6599With a numeric argument, behave exactly like \fByank\-nth\-arg\fP.
cce855bc 6600Successive calls to \fByank\-last\-arg\fP move back through the history
495aee44
CR
6601list, inserting the last word (or the word specified by the argument to
6602the first call) of each line in turn.
6603Any numeric argument supplied to these successive calls determines
6604the direction to move through the history. A negative argument switches
6605the direction through the history (back or forward).
ac50fbac 6606The history expansion facilities are used to extract the last word,
95732b49 6607as if the "!$" history expansion had been specified.
726f6388
JA
6608.TP
6609.B shell\-expand\-line (M\-C\-e)
cce855bc 6610Expand the line as the shell does. This
726f6388
JA
6611performs alias and history expansion as well as all of the shell
6612word expansions. See
6613.SM
6614.B HISTORY EXPANSION
6615below for a description of history expansion.
6616.TP
6617.B history\-expand\-line (M\-^)
d166f048
JA
6618Perform history expansion on the current line.
6619See
726f6388
JA
6620.SM
6621.B HISTORY EXPANSION
6622below for a description of history expansion.
6623.TP
cce855bc
JA
6624.B magic\-space
6625Perform history expansion on the current line and insert a space.
6626See
6627.SM
6628.B HISTORY EXPANSION
6629below for a description of history expansion.
6630.TP
d166f048
JA
6631.B alias\-expand\-line
6632Perform alias expansion on the current line.
6633See
6634.SM
6635.B ALIASES
6636above for a description of alias expansion.
6637.TP
6638.B history\-and\-alias\-expand\-line
6639Perform history and alias expansion on the current line.
6640.TP
726f6388
JA
6641.B insert\-last\-argument (M\-.\^, M\-_\^)
6642A synonym for \fByank\-last\-arg\fP.
6643.TP
d233b485 6644.B edit\-and\-execute\-command (C\-x C\-e)
7117c2d2
JA
6645Invoke an editor on the current command line, and execute the result as shell
6646commands.
6647\fBBash\fP attempts to invoke
6648.SM
3185942a 6649.BR $VISUAL ,
7117c2d2
JA
6650.SM
6651.BR $EDITOR ,
6652and \fIemacs\fP as the editor, in that order.
726f6388
JA
6653.PD
6654.SS Commands for Changing Text
726f6388
JA
6655.PD 0
6656.TP
ac50fbac
CR
6657.B \fIend\-of\-file\fP (usually C\-d)
6658The character indicating end-of-file as set, for example, by
6659.if t \f(CWstty\fP.
6660.if n ``stty''.
6661If this character is read when there are no characters
74091dd4 6662on the line, and point is at the beginning of the line, readline
ac50fbac 6663interprets it as the end of input and returns
726f6388
JA
6664.SM
6665.BR EOF .
6666.TP
ac50fbac
CR
6667.B delete\-char (C\-d)
6668Delete the character at point.
6669If this function is bound to the
6670same character as the tty \fBEOF\fP character, as \fBC\-d\fP
6671commonly is, see above for the effects.
6672.TP
726f6388
JA
6673.B backward\-delete\-char (Rubout)
6674Delete the character behind the cursor. When given a numeric argument,
ccc6cda3 6675save the deleted text on the kill ring.
726f6388 6676.TP
b72432fd
JA
6677.B forward\-backward\-delete\-char
6678Delete the character under the cursor, unless the cursor is at the
6679end of the line, in which case the character behind the cursor is
f73dda09 6680deleted.
b72432fd 6681.TP
726f6388 6682.B quoted\-insert (C\-q, C\-v)
cce855bc 6683Add the next character typed to the line verbatim. This is
726f6388
JA
6684how to insert characters like \fBC\-q\fP, for example.
6685.TP
ccc6cda3 6686.B tab\-insert (C\-v TAB)
726f6388
JA
6687Insert a tab character.
6688.TP
6689.B self\-insert (a,\ b,\ A,\ 1,\ !,\ ...)
6690Insert the character typed.
6691.TP
6692.B transpose\-chars (C\-t)
28ef6c31
JA
6693Drag the character before point forward over the character at point,
6694moving point forward as well.
6695If point is at the end of the line, then this transposes
6696the two characters before point.
bb70624e 6697Negative arguments have no effect.
726f6388
JA
6698.TP
6699.B transpose\-words (M\-t)
bb70624e 6700Drag the word before point past the word after point,
28ef6c31 6701moving point over that word as well.
f73dda09 6702If point is at the end of the line, this transposes
a0c0a00f 6703the last two words on the line.
726f6388
JA
6704.TP
6705.B upcase\-word (M\-u)
6706Uppercase the current (or following) word. With a negative argument,
cce855bc 6707uppercase the previous word, but do not move point.
726f6388
JA
6708.TP
6709.B downcase\-word (M\-l)
6710Lowercase the current (or following) word. With a negative argument,
cce855bc 6711lowercase the previous word, but do not move point.
726f6388
JA
6712.TP
6713.B capitalize\-word (M\-c)
6714Capitalize the current (or following) word. With a negative argument,
cce855bc 6715capitalize the previous word, but do not move point.
7117c2d2
JA
6716.TP
6717.B overwrite\-mode
6718Toggle overwrite mode. With an explicit positive numeric argument,
6719switches to overwrite mode. With an explicit non-positive numeric
6720argument, switches to insert mode. This command affects only
6721\fBemacs\fP mode; \fBvi\fP mode does overwrite differently.
6722Each call to \fIreadline()\fP starts in insert mode.
a0c0a00f 6723In overwrite mode, characters bound to \fBself\-insert\fP replace
7117c2d2
JA
6724the text at point rather than pushing the text to the right.
6725Characters bound to \fBbackward\-delete\-char\fP replace the character
6726before point with a space. By default, this command is unbound.
726f6388
JA
6727.PD
6728.SS Killing and Yanking
726f6388
JA
6729.PD 0
6730.TP
6731.B kill\-line (C\-k)
bb70624e 6732Kill the text from point to the end of the line.
726f6388 6733.TP
ccc6cda3 6734.B backward\-kill\-line (C\-x Rubout)
726f6388
JA
6735Kill backward to the beginning of the line.
6736.TP
6737.B unix\-line\-discard (C\-u)
6738Kill backward from point to the beginning of the line.
cce855bc 6739The killed text is saved on the kill-ring.
bb70624e 6740.\" There is no real difference between this and backward-kill-line
726f6388
JA
6741.TP
6742.B kill\-whole\-line
bb70624e 6743Kill all characters on the current line, no matter where point is.
726f6388 6744.TP
a0c0a00f 6745.B kill\-word (M\-d)
bb70624e
JA
6746Kill from point to the end of the current word, or if between
6747words, to the end of the next word.
6748Word boundaries are the same as those used by \fBforward\-word\fP.
726f6388
JA
6749.TP
6750.B backward\-kill\-word (M\-Rubout)
bb70624e
JA
6751Kill the word behind point.
6752Word boundaries are the same as those used by \fBbackward\-word\fP.
726f6388 6753.TP
a0c0a00f 6754.B shell\-kill\-word
3185942a
JA
6755Kill from point to the end of the current word, or if between
6756words, to the end of the next word.
6757Word boundaries are the same as those used by \fBshell\-forward\-word\fP.
6758.TP
a0c0a00f 6759.B shell\-backward\-kill\-word
3185942a
JA
6760Kill the word behind point.
6761Word boundaries are the same as those used by \fBshell\-backward\-word\fP.
6762.TP
726f6388 6763.B unix\-word\-rubout (C\-w)
bb70624e 6764Kill the word behind point, using white space as a word boundary.
bb70624e 6765The killed text is saved on the kill-ring.
ccc6cda3 6766.TP
b80f6443
JA
6767.B unix\-filename\-rubout
6768Kill the word behind point, using white space and the slash character
6769as the word boundaries.
6770The killed text is saved on the kill-ring.
6771.TP
ccc6cda3
JA
6772.B delete\-horizontal\-space (M\-\e)
6773Delete all spaces and tabs around point.
6774.TP
6775.B kill\-region
bb70624e 6776Kill the text in the current region.
ccc6cda3
JA
6777.TP
6778.B copy\-region\-as\-kill
6779Copy the text in the region to the kill buffer.
726f6388 6780.TP
ccc6cda3
JA
6781.B copy\-backward\-word
6782Copy the word before point to the kill buffer.
cce855bc 6783The word boundaries are the same as \fBbackward\-word\fP.
ccc6cda3
JA
6784.TP
6785.B copy\-forward\-word
6786Copy the word following point to the kill buffer.
cce855bc 6787The word boundaries are the same as \fBforward\-word\fP.
726f6388
JA
6788.TP
6789.B yank (C\-y)
28ef6c31 6790Yank the top of the kill ring into the buffer at point.
726f6388
JA
6791.TP
6792.B yank\-pop (M\-y)
ccc6cda3 6793Rotate the kill ring, and yank the new top. Only works following
726f6388
JA
6794.B yank
6795or
6796.BR yank\-pop .
6797.PD
6798.SS Numeric Arguments
726f6388
JA
6799.PD 0
6800.TP
6801.B digit\-argument (M\-0, M\-1, ..., M\-\-)
6802Add this digit to the argument already accumulating, or start a new
6803argument. M\-\- starts a negative argument.
6804.TP
6805.B universal\-argument
d166f048
JA
6806This is another way to specify an argument.
6807If this command is followed by one or more digits, optionally with a
6808leading minus sign, those digits define the argument.
6809If the command is followed by digits, executing
6810.B universal\-argument
6811again ends the numeric argument, but is otherwise ignored.
6812As a special case, if this command is immediately followed by a
a0c0a00f 6813character that is neither a digit nor minus sign, the argument count
d166f048 6814for the next command is multiplied by four.
726f6388 6815The argument count is initially one, so executing this function the
d166f048
JA
6816first time makes the argument count four, a second time makes the
6817argument count sixteen, and so on.
726f6388
JA
6818.PD
6819.SS Completing
726f6388
JA
6820.PD 0
6821.TP
6822.B complete (TAB)
6823Attempt to perform completion on the text before point.
6824.B Bash
6825attempts completion treating the text as a variable (if the
6826text begins with \fB$\fP), username (if the text begins with
6827\fB~\fP), hostname (if the text begins with \fB@\fP), or
6828command (including aliases and functions) in turn. If none
6829of these produces a match, filename completion is attempted.
6830.TP
ccc6cda3 6831.B possible\-completions (M\-?)
726f6388
JA
6832List the possible completions of the text before point.
6833.TP
ccc6cda3 6834.B insert\-completions (M\-*)
726f6388
JA
6835Insert all completions of the text before point
6836that would have been generated by
ccc6cda3 6837\fBpossible\-completions\fP.
726f6388 6838.TP
cce855bc
JA
6839.B menu\-complete
6840Similar to \fBcomplete\fP, but replaces the word to be completed
6841with a single match from the list of possible completions.
6842Repeated execution of \fBmenu\-complete\fP steps through the list
6843of possible completions, inserting each match in turn.
28ef6c31 6844At the end of the list of completions, the bell is rung
f73dda09 6845(subject to the setting of \fBbell\-style\fP)
28ef6c31 6846and the original text is restored.
cce855bc
JA
6847An argument of \fIn\fP moves \fIn\fP positions forward in the list
6848of matches; a negative argument may be used to move backward
6849through the list.
6850This command is intended to be bound to \fBTAB\fP, but is unbound
6851by default.
6852.TP
495aee44 6853.B menu\-complete\-backward
0001803f
CR
6854Identical to \fBmenu\-complete\fP, but moves backward through the list
6855of possible completions, as if \fBmenu\-complete\fP had been given a
6856negative argument. This command is unbound by default.
6857.TP
b72432fd
JA
6858.B delete\-char\-or\-list
6859Deletes the character under the cursor if not at the beginning or
bb70624e 6860end of the line (like \fBdelete\-char\fP).
b72432fd 6861If at the end of the line, behaves identically to
bb70624e 6862\fBpossible\-completions\fP.
b72432fd
JA
6863This command is unbound by default.
6864.TP
726f6388
JA
6865.B complete\-filename (M\-/)
6866Attempt filename completion on the text before point.
6867.TP
6868.B possible\-filename\-completions (C\-x /)
6869List the possible completions of the text before point,
6870treating it as a filename.
6871.TP
6872.B complete\-username (M\-~)
6873Attempt completion on the text before point, treating
6874it as a username.
6875.TP
6876.B possible\-username\-completions (C\-x ~)
6877List the possible completions of the text before point,
6878treating it as a username.
6879.TP
6880.B complete\-variable (M\-$)
6881Attempt completion on the text before point, treating
6882it as a shell variable.
6883.TP
6884.B possible\-variable\-completions (C\-x $)
6885List the possible completions of the text before point,
6886treating it as a shell variable.
6887.TP
6888.B complete\-hostname (M\-@)
6889Attempt completion on the text before point, treating
6890it as a hostname.
6891.TP
6892.B possible\-hostname\-completions (C\-x @)
6893List the possible completions of the text before point,
6894treating it as a hostname.
6895.TP
6896.B complete\-command (M\-!)
6897Attempt completion on the text before point, treating
6898it as a command name. Command completion attempts to
6899match the text against aliases, reserved words, shell
cce855bc 6900functions, shell builtins, and finally executable filenames,
726f6388
JA
6901in that order.
6902.TP
6903.B possible\-command\-completions (C\-x !)
6904List the possible completions of the text before point,
6905treating it as a command name.
6906.TP
ccc6cda3 6907.B dynamic\-complete\-history (M\-TAB)
726f6388
JA
6908Attempt completion on the text before point, comparing
6909the text against lines from the history list for possible
6910completion matches.
6911.TP
3185942a
JA
6912.B dabbrev\-expand
6913Attempt menu completion on the text before point, comparing
6914the text against lines from the history list for possible
6915completion matches.
6916.TP
726f6388 6917.B complete\-into\-braces (M\-{)
bb70624e 6918Perform filename completion and insert the list of possible completions
726f6388
JA
6919enclosed within braces so the list is available to the shell (see
6920.B Brace Expansion
6921above).
6922.PD
6923.SS Keyboard Macros
726f6388
JA
6924.PD 0
6925.TP
ccc6cda3 6926.B start\-kbd\-macro (C\-x (\^)
726f6388
JA
6927Begin saving the characters typed into the current keyboard macro.
6928.TP
ccc6cda3 6929.B end\-kbd\-macro (C\-x )\^)
726f6388 6930Stop saving the characters typed into the current keyboard macro
ccc6cda3 6931and store the definition.
726f6388 6932.TP
ccc6cda3 6933.B call\-last\-kbd\-macro (C\-x e)
726f6388
JA
6934Re-execute the last keyboard macro defined, by making the characters
6935in the macro appear as if typed at the keyboard.
ac50fbac
CR
6936.TP
6937.B print\-last\-kbd\-macro ()
6938Print the last keyboard macro defined in a format suitable for the
6939\fIinputrc\fP file.
726f6388
JA
6940.PD
6941.SS Miscellaneous
726f6388
JA
6942.PD 0
6943.TP
6944.B re\-read\-init\-file (C\-x C\-r)
ccc6cda3 6945Read in the contents of the \fIinputrc\fP file, and incorporate
726f6388
JA
6946any bindings or variable assignments found there.
6947.TP
6948.B abort (C\-g)
6949Abort the current editing command and
6950ring the terminal's bell (subject to the setting of
6951.BR bell\-style ).
6952.TP
d233b485
CR
6953.B do\-lowercase\-version (M\-A, M\-B, M\-\fIx\fP, ...)
6954If the metafied character \fIx\fP is uppercase, run the command
8868edaf
CR
6955that is bound to the corresponding metafied lowercase character.
6956The behavior is undefined if \fIx\fP is already lowercase.
726f6388
JA
6957.TP
6958.B prefix\-meta (ESC)
6959Metafy the next character typed.
6960.SM
6961.B ESC
6962.B f
6963is equivalent to
6964.BR Meta\-f .
6965.TP
6966.B undo (C\-_, C\-x C\-u)
6967Incremental undo, separately remembered for each line.
6968.TP
6969.B revert\-line (M\-r)
cce855bc 6970Undo all changes made to this line. This is like executing the
726f6388
JA
6971.B undo
6972command enough times to return the line to its initial state.
6973.TP
b72432fd 6974.B tilde\-expand (M\-&)
726f6388
JA
6975Perform tilde expansion on the current word.
6976.TP
ccc6cda3 6977.B set\-mark (C\-@, M\-<space>)
28ef6c31 6978Set the mark to the point. If a
ccc6cda3
JA
6979numeric argument is supplied, the mark is set to that position.
6980.TP
6981.B exchange\-point\-and\-mark (C\-x C\-x)
6982Swap the point with the mark. The current cursor position is set to
6983the saved position, and the old cursor position is saved as the mark.
6984.TP
6985.B character\-search (C\-])
6986A character is read and point is moved to the next occurrence of that
74091dd4 6987character. A negative argument searches for previous occurrences.
ccc6cda3
JA
6988.TP
6989.B character\-search\-backward (M\-C\-])
6990A character is read and point is moved to the previous occurrence of that
74091dd4 6991character. A negative argument searches for subsequent occurrences.
ccc6cda3 6992.TP
495aee44 6993.B skip\-csi\-sequence
0001803f
CR
6994Read enough characters to consume a multi-key sequence such as those
6995defined for keys like Home and End. Such sequences begin with a
6996Control Sequence Indicator (CSI), usually ESC\-[. If this sequence is
6997bound to "\e[", keys producing such sequences will have no effect
6998unless explicitly bound to a readline command, instead of inserting
6999stray characters into the editing buffer. This is unbound by default,
7000but usually bound to ESC\-[.
7001.TP
ccc6cda3 7002.B insert\-comment (M\-#)
7117c2d2 7003Without a numeric argument, the value of the readline
ccc6cda3 7004.B comment\-begin
7117c2d2 7005variable is inserted at the beginning of the current line.
a0c0a00f 7006If a numeric argument is supplied, this command acts as a toggle: if
7117c2d2
JA
7007the characters at the beginning of the line do not match the value
7008of \fBcomment\-begin\fP, the value is inserted, otherwise
a0c0a00f 7009the characters in \fBcomment\-begin\fP are deleted from the beginning of
7117c2d2
JA
7010the line.
7011In either case, the line is accepted as if a newline had been typed.
7012The default value of
bb70624e 7013\fBcomment\-begin\fP causes this command to make the current line
ccc6cda3 7014a shell comment.
7117c2d2
JA
7015If a numeric argument causes the comment character to be removed, the line
7016will be executed by the shell.
7017.TP
74091dd4
CR
7018.B spell\-correct\-word (C\-x s)
7019Perform spelling correction on the current word, treating it as a directory
7020or filename, in the same way as the \fBcdspell\fP shell option.
7021Word boundaries are the same as those used by \fBshell\-forward\-word\fP.
7022.TP
7117c2d2
JA
7023.B glob\-complete\-word (M\-g)
7024The word before point is treated as a pattern for pathname expansion,
7025with an asterisk implicitly appended. This pattern is used to
ac50fbac 7026generate a list of matching filenames for possible completions.
ccc6cda3
JA
7027.TP
7028.B glob\-expand\-word (C\-x *)
7029The word before point is treated as a pattern for pathname expansion,
ac50fbac 7030and the list of matching filenames is inserted, replacing the word.
7117c2d2
JA
7031If a numeric argument is supplied, an asterisk is appended before
7032pathname expansion.
ccc6cda3
JA
7033.TP
7034.B glob\-list\-expansions (C\-x g)
7035The list of expansions that would have been generated by
7036.B glob\-expand\-word
7037is displayed, and the line is redrawn.
7117c2d2
JA
7038If a numeric argument is supplied, an asterisk is appended before
7039pathname expansion.
ccc6cda3 7040.TP
726f6388
JA
7041.B dump\-functions
7042Print all of the functions and their key bindings to the
7043readline output stream. If a numeric argument is supplied,
7044the output is formatted in such a way that it can be made part
7045of an \fIinputrc\fP file.
7046.TP
ccc6cda3
JA
7047.B dump\-variables
7048Print all of the settable readline variables and their values to the
7049readline output stream. If a numeric argument is supplied,
7050the output is formatted in such a way that it can be made part
7051of an \fIinputrc\fP file.
7052.TP
7053.B dump\-macros
7054Print all of the readline key sequences bound to macros and the
95732b49 7055strings they output. If a numeric argument is supplied,
ccc6cda3
JA
7056the output is formatted in such a way that it can be made part
7057of an \fIinputrc\fP file.
7058.TP
726f6388
JA
7059.B display\-shell\-version (C\-x C\-v)
7060Display version information about the current instance of
7061.BR bash .
7062.PD
bb70624e 7063.SS Programmable Completion
bb70624e
JA
7064When word completion is attempted for an argument to a command for
7065which a completion specification (a \fIcompspec\fP) has been defined
7066using the \fBcomplete\fP builtin (see
7067.SM
7068.B "SHELL BUILTIN COMMANDS"
7069below), the programmable completion facilities are invoked.
7070.PP
7071First, the command name is identified.
0001803f
CR
7072If the command word is the empty string (completion attempted at the
7073beginning of an empty line), any compspec defined with
7074the \fB\-E\fP option to \fBcomplete\fP is used.
bb70624e
JA
7075If a compspec has been defined for that command, the
7076compspec is used to generate the list of possible completions for the word.
7077If the command word is a full pathname, a compspec for the full
7078pathname is searched for first.
7079If no compspec is found for the full pathname, an attempt is made to
7080find a compspec for the portion following the final slash.
495aee44 7081If those searches do not result in a compspec, any compspec defined with
0001803f 7082the \fB\-D\fP option to \fBcomplete\fP is used as the default.
d233b485
CR
7083If there is no default compspec, \fBbash\fP attempts alias expansion
7084on the command word as a final resort, and attempts to find a compspec
7085for the command word from any successful expansion.
bb70624e
JA
7086.PP
7087Once a compspec has been found, it is used to generate the list of
7088matching words.
7089If a compspec is not found, the default \fBbash\fP completion as
7090described above under \fBCompleting\fP is performed.
7091.PP
7092First, the actions specified by the compspec are used.
7093Only matches which are prefixed by the word being completed are
7094returned.
7095When the
7096.B \-f
7097or
7098.B \-d
7099option is used for filename or directory name completion, the shell
7100variable
7101.SM
7102.B FIGNORE
7103is used to filter the matches.
7104.PP
0001803f 7105Any completions specified by a pathname expansion pattern to the
bb70624e
JA
7106\fB\-G\fP option are generated next.
7107The words generated by the pattern need not match the word
7108being completed.
7109The
7110.SM
7111.B GLOBIGNORE
7112shell variable is not used to filter the matches, but the
7113.SM
7114.B FIGNORE
7115variable is used.
7116.PP
7117Next, the string specified as the argument to the \fB\-W\fP option
7118is considered.
7119The string is first split using the characters in the
7120.SM
7121.B IFS
7122special variable as delimiters.
7123Shell quoting is honored.
7124Each word is then expanded using
7125brace expansion, tilde expansion, parameter and variable expansion,
95732b49 7126command substitution, and arithmetic expansion,
a0c0a00f 7127as described above under
bb70624e
JA
7128.SM
7129.BR EXPANSION .
7130The results are split using the rules described above under
7131\fBWord Splitting\fP.
7132The results of the expansion are prefix-matched against the word being
7133completed, and the matching words become the possible completions.
7134.PP
7135After these matches have been generated, any shell function or command
7136specified with the \fB\-F\fP and \fB\-C\fP options is invoked.
7137When the command or function is invoked, the
7138.SM
3185942a
JA
7139.BR COMP_LINE ,
7140.SM
7141.BR COMP_POINT ,
7142.SM
7143.BR COMP_KEY ,
bb70624e
JA
7144and
7145.SM
3185942a 7146.B COMP_TYPE
bb70624e
JA
7147variables are assigned values as described above under
7148\fBShell Variables\fP.
a0c0a00f 7149If a shell function is being invoked, the
bb70624e
JA
7150.SM
7151.B COMP_WORDS
7152and
7153.SM
7154.B COMP_CWORD
7155variables are also set.
ac50fbac
CR
7156When the function or command is invoked,
7157the first argument (\fB$1\fP) is the name of the command whose arguments are
7158being completed,
7159the second argument (\fB$2\fP) is the word being completed,
7160and the third argument (\fB$3\fP) is the word preceding the word being
7161completed on the current command line.
bb70624e
JA
7162No filtering of the generated completions against the word being completed
7163is performed; the function or command has complete freedom in generating
7164the matches.
7165.PP
7166Any function specified with \fB\-F\fP is invoked first.
7167The function may use any of the shell facilities, including the
7168\fBcompgen\fP builtin described below, to generate the matches.
7169It must put the possible completions in the
7170.SM
7171.B COMPREPLY
ac50fbac 7172array variable, one per array element.
bb70624e
JA
7173.PP
7174Next, any command specified with the \fB\-C\fP option is invoked
7175in an environment equivalent to command substitution.
7176It should print a list of completions, one per line, to the
7177standard output.
7178Backslash may be used to escape a newline, if necessary.
7179.PP
7180After all of the possible completions are generated, any filter
7181specified with the \fB\-X\fP option is applied to the list.
7182The filter is a pattern as used for pathname expansion; a \fB&\fP
7183in the pattern is replaced with the text of the word being completed.
7184A literal \fB&\fP may be escaped with a backslash; the backslash
7185is removed before attempting a match.
7186Any completion that matches the pattern will be removed from the list.
7187A leading \fB!\fP negates the pattern; in this case any completion
7188not matching the pattern will be removed.
a0c0a00f
CR
7189If the
7190.B nocasematch
7191shell option is enabled, the match is performed without regard to the case
7192of alphabetic characters.
bb70624e
JA
7193.PP
7194Finally, any prefix and suffix specified with the \fB\-P\fP and \fB\-S\fP
7195options are added to each member of the completion list, and the result is
7196returned to the readline completion code as the list of possible
7197completions.
7198.PP
28ef6c31
JA
7199If the previously-applied actions do not generate any matches, and the
7200\fB\-o dirnames\fP option was supplied to \fBcomplete\fP when the
7201compspec was defined, directory name completion is attempted.
7202.PP
b80f6443
JA
7203If the \fB\-o plusdirs\fP option was supplied to \fBcomplete\fP when the
7204compspec was defined, directory name completion is attempted and any
7205matches are added to the results of the other actions.
7206.PP
28ef6c31
JA
7207By default, if a compspec is found, whatever it generates is returned
7208to the completion code as the full set of possible completions.
bb70624e
JA
7209The default \fBbash\fP completions are not attempted, and the readline
7210default of filename completion is disabled.
b80f6443
JA
7211If the \fB\-o bashdefault\fP option was supplied to \fBcomplete\fP when
7212the compspec was defined, the \fBbash\fP default completions are attempted
28ef6c31 7213if the compspec generates no matches.
b80f6443
JA
7214If the \fB\-o default\fP option was supplied to \fBcomplete\fP when the
7215compspec was defined, readline's default completion will be performed
7216if the compspec (and, if attempted, the default \fBbash\fP completions)
7217generate no matches.
7117c2d2
JA
7218.PP
7219When a compspec indicates that directory name completion is desired,
7220the programmable completion functions force readline to append a slash
a0c0a00f 7221to completed names which are symbolic links to directories, subject to
7117c2d2
JA
7222the value of the \fBmark\-directories\fP readline variable, regardless
7223of the setting of the \fBmark-symlinked\-directories\fP readline variable.
0001803f
CR
7224.PP
7225There is some support for dynamically modifying completions. This is
7226most useful when used in combination with a default completion specified
d233b485 7227with \fBcomplete \-D\fP.
0001803f
CR
7228It's possible for shell functions executed as completion
7229handlers to indicate that completion should be retried by returning an
7230exit status of 124. If a shell function returns 124, and changes
7231the compspec associated with the command on which completion is being
7232attempted (supplied as the first argument when the function is executed),
7233programmable completion restarts from the beginning, with an
495aee44 7234attempt to find a new compspec for that command. This allows a set of
0001803f
CR
7235completions to be built dynamically as completion is attempted, rather than
7236being loaded all at once.
7237.PP
7238For instance, assuming that there is a library of compspecs, each kept in a
7239file corresponding to the name of the command, the following default
7240completion function would load completions dynamically:
7241.PP
7242\f(CW_completion_loader()
7243.br
7244{
7245.br
7246 . "/etc/bash_completion.d/$1.sh" >/dev/null 2>&1 && return 124
7247.br
7248}
7249.br
ac50fbac 7250complete -D -F _completion_loader -o bashdefault -o default
0001803f
CR
7251.br
7252\fP
726f6388 7253.SH HISTORY
ccc6cda3 7254When the
d166f048 7255.B \-o history
ccc6cda3
JA
7256option to the
7257.B set
7258builtin is enabled, the shell provides access to the
7259\fIcommand history\fP,
bb70624e 7260the list of commands previously typed.
0001803f
CR
7261The value of the
7262.SM
7263.B HISTSIZE
7264variable is used as the
bb70624e
JA
7265number of commands to save in a history list.
7266The text of the last
726f6388
JA
7267.SM
7268.B HISTSIZE
bb70624e 7269commands (default 500) is saved. The shell
726f6388
JA
7270stores each command in the history list prior to parameter and
7271variable expansion (see
7272.SM
7273.B EXPANSION
7274above) but after history expansion is performed, subject to the
7275values of the shell variables
ccc6cda3
JA
7276.SM
7277.B HISTIGNORE
726f6388
JA
7278and
7279.SM
7280.BR HISTCONTROL .
bb70624e 7281.PP
726f6388
JA
7282On startup, the history is initialized from the file named by
7283the variable
7284.SM
7285.B HISTFILE
7286(default \fI~/.bash_history\fP).
bb70624e 7287The file named by the value of
726f6388
JA
7288.SM
7289.B HISTFILE
7290is truncated, if necessary, to contain no more than
bb70624e 7291the number of lines specified by the value of
726f6388 7292.SM
bb70624e 7293.BR HISTFILESIZE .
ac50fbac
CR
7294If \fBHISTFILESIZE\fP is unset, or set to null, a non-numeric value,
7295or a numeric value less than zero, the history file is not truncated.
3185942a
JA
7296When the history file is read,
7297lines beginning with the history comment character followed immediately
d233b485 7298by a digit are interpreted as timestamps for the following history line.
3185942a
JA
7299These timestamps are optionally displayed depending on the value of the
7300.SM
7301.B HISTTIMEFORMAT
7302variable.
ac50fbac 7303When a shell with history enabled exits, the last
ccc6cda3 7304.SM
bb70624e 7305.B $HISTSIZE
ccc6cda3
JA
7306lines are copied from the history list to
7307.SM
bb70624e 7308.BR $HISTFILE .
ccc6cda3
JA
7309If the
7310.B histappend
7311shell option is enabled
7312(see the description of
7313.B shopt
7314under
7315.SM
7316.B "SHELL BUILTIN COMMANDS"
7317below), the lines are appended to the history file,
7318otherwise the history file is overwritten.
7319If
7320.SM
7321.B HISTFILE
7322is unset, or if the history file is unwritable, the history is
3185942a
JA
7323not saved.
7324If the
7325.SM
0001803f 7326.B HISTTIMEFORMAT
3185942a
JA
7327variable is set, time stamps are written to the history file, marked
7328with the history comment character, so
7329they may be preserved across shell sessions.
7330This uses the history comment character to distinguish timestamps from
7331other history lines.
7332After saving the history, the history file is truncated
ccc6cda3
JA
7333to contain no more than
7334.SM
7335.B HISTFILESIZE
7336lines. If
7337.SM
7338.B HISTFILESIZE
ac50fbac
CR
7339is unset, or set to null, a non-numeric value,
7340or a numeric value less than zero, the history file is not truncated.
ccc6cda3 7341.PP
726f6388
JA
7342The builtin command
7343.B fc
7344(see
7345.SM
7346.B SHELL BUILTIN COMMANDS
7347below) may be used to list or edit and re-execute a portion of
7348the history list.
7349The
7350.B history
bb70624e 7351builtin may be used to display or modify the history list and
ccc6cda3 7352manipulate the history file.
bb70624e 7353When using command-line editing, search commands
726f6388 7354are available in each editing mode that provide access to the
ccc6cda3
JA
7355history list.
7356.PP
7357The shell allows control over which commands are saved on the history
7358list. The
726f6388 7359.SM
ccc6cda3
JA
7360.B HISTCONTROL
7361and
726f6388 7362.SM
ccc6cda3
JA
7363.B HISTIGNORE
7364variables may be set to cause the shell to save only a subset of the
7365commands entered.
7366The
7367.B cmdhist
7368shell option, if enabled, causes the shell to attempt to save each
7369line of a multi-line command in the same history entry, adding
7370semicolons where necessary to preserve syntactic correctness.
7371The
7372.B lithist
7373shell option causes the shell to save the command with embedded newlines
7374instead of semicolons. See the description of the
7375.B shopt
7376builtin below under
7377.SM
7378.B "SHELL BUILTIN COMMANDS"
7379for information on setting and unsetting shell options.
726f6388 7380.SH "HISTORY EXPANSION"
726f6388
JA
7381The shell supports a history expansion feature that
7382is similar to the history expansion in
d233b485 7383.BR csh .
726f6388
JA
7384This section describes what syntax features are available. This
7385feature is enabled by default for interactive shells, and can be
7386disabled using the
ac50fbac 7387.B +H
726f6388
JA
7388option to the
7389.B set
7390builtin command (see
7391.SM
7392.B SHELL BUILTIN COMMANDS
ccc6cda3
JA
7393below). Non-interactive shells do not perform history expansion
7394by default.
7395.PP
7396History expansions introduce words from the history list into
7397the input stream, making it easy to repeat commands, insert the
7398arguments to a previous command into the current input line, or
7399fix errors in previous commands quickly.
726f6388
JA
7400.PP
7401History expansion is performed immediately after a complete line
d233b485
CR
7402is read, before the shell breaks it into words, and is performed
7403on each line individually without taking quoting on previous lines into
7404account.
ccc6cda3 7405It takes place in two parts.
cce855bc 7406The first is to determine which line from the history list
ccc6cda3
JA
7407to use during substitution.
7408The second is to select portions of that line for inclusion into
7409the current one.
cce855bc 7410The line selected from the history is the \fIevent\fP,
ccc6cda3
JA
7411and the portions of that line that are acted upon are \fIwords\fP.
7412Various \fImodifiers\fP are available to manipulate the selected words.
7413The line is broken into words in the same fashion as when reading input,
7414so that several \fImetacharacter\fP-separated words surrounded by
cce855bc 7415quotes are considered one word.
ccc6cda3
JA
7416History expansions are introduced by the appearance of the
7417history expansion character, which is \^\fB!\fP\^ by default.
7418Only backslash (\^\fB\e\fP\^) and single quotes can quote
a0c0a00f
CR
7419the history expansion character, but the history expansion character is
7420also treated as quoted if it immediately precedes the closing double quote
7421in a double-quoted string.
ccc6cda3 7422.PP
b80f6443
JA
7423Several characters inhibit history expansion if found immediately
7424following the history expansion character, even if it is unquoted:
7425space, tab, newline, carriage return, and \fB=\fP.
7426If the \fBextglob\fP shell option is enabled, \fB(\fP will also
7427inhibit expansion.
7428.PP
ccc6cda3
JA
7429Several shell options settable with the
7430.B shopt
7431builtin may be used to tailor the behavior of history expansion.
7432If the
7433.B histverify
7434shell option is enabled (see the description of the
7435.B shopt
0001803f 7436builtin below), and
ccc6cda3
JA
7437.B readline
7438is being used, history substitutions are not immediately passed to
7439the shell parser.
7440Instead, the expanded line is reloaded into the
7441.B readline
7442editing buffer for further modification.
7443If
7444.B readline
7445is being used, and the
7446.B histreedit
7447shell option is enabled, a failed history substitution will be reloaded
7448into the
7449.B readline
7450editing buffer for correction.
7451The
7452.B \-p
7453option to the
7454.B history
7455builtin command may be used to see what a history expansion will
7456do before using it.
7457The
7458.B \-s
7459option to the
7460.B history
7461builtin may be used to add commands to the end of the history list
7462without actually executing them, so that they are available for
7463subsequent recall.
726f6388
JA
7464.PP
7465The shell allows control of the various characters used by the
7466history expansion mechanism (see the description of
7467.B histchars
7468above under
7469.BR "Shell Variables" ).
3185942a
JA
7470The shell uses
7471the history comment character to mark history timestamps when
7472writing the history file.
726f6388 7473.SS Event Designators
726f6388
JA
7474An event designator is a reference to a command line entry in the
7475history list.
495aee44
CR
7476Unless the reference is absolute, events are relative to the current
7477position in the history list.
726f6388
JA
7478.PP
7479.PD 0
7480.TP
7481.B !
7482Start a history substitution, except when followed by a
7483.BR blank ,
b80f6443
JA
7484newline, carriage return, =
7485or ( (when the \fBextglob\fP shell option is enabled using
7486the \fBshopt\fP builtin).
726f6388 7487.TP
726f6388
JA
7488.B !\fIn\fR
7489Refer to command line
7490.IR n .
7491.TP
7492.B !\-\fIn\fR
495aee44 7493Refer to the current command minus
726f6388
JA
7494.IR n .
7495.TP
ccc6cda3
JA
7496.B !!
7497Refer to the previous command. This is a synonym for `!\-1'.
7498.TP
726f6388 7499.B !\fIstring\fR
495aee44
CR
7500Refer to the most recent command preceding the current position in the
7501history list starting with
726f6388
JA
7502.IR string .
7503.TP
7504.B !?\fIstring\fR\fB[?]\fR
ac50fbac 7505Refer to the most recent command preceding the current position in the
495aee44 7506history list containing
726f6388 7507.IR string .
ccc6cda3
JA
7508The trailing \fB?\fP may be omitted if
7509.I string
7510is followed immediately by a newline.
8868edaf
CR
7511If \fIstring\fP is missing, the string from the most recent search is used;
7512it is an error if there is no previous search string.
726f6388
JA
7513.TP
7514.B \d\s+2^\s-2\u\fIstring1\fP\d\s+2^\s-2\u\fIstring2\fP\d\s+2^\s-2\u
495aee44 7515Quick substitution. Repeat the previous command, replacing
726f6388
JA
7516.I string1
7517with
7518.IR string2 .
7519Equivalent to
8868edaf 7520``!!:s\d\s+2^\s-2\u\fIstring1\fP\d\s+2^\s-2\u\fIstring2\fP\d\s+2^\s-2\u''
726f6388
JA
7521(see \fBModifiers\fP below).
7522.TP
7523.B !#
7524The entire command line typed so far.
7525.PD
7526.SS Word Designators
ccc6cda3 7527Word designators are used to select desired words from the event.
a0c0a00f 7528A
726f6388 7529.B :
ccc6cda3 7530separates the event specification from the word designator.
cce855bc 7531It may be omitted if the word designator begins with a
726f6388
JA
7532.BR ^ ,
7533.BR $ ,
7534.BR * ,
ccc6cda3 7535.BR \- ,
726f6388
JA
7536or
7537.BR % .
7538Words are numbered from the beginning of the line,
ccc6cda3
JA
7539with the first word being denoted by 0 (zero).
7540Words are inserted into the current line separated by single spaces.
726f6388
JA
7541.PP
7542.PD 0
7543.TP
7544.B 0 (zero)
7545The zeroth word. For the shell, this is the command
7546word.
7547.TP
7548.I n
7549The \fIn\fRth word.
7550.TP
7551.B ^
7552The first argument. That is, word 1.
7553.TP
7554.B $
ac50fbac
CR
7555The last word. This is usually the last argument, but will expand to the
7556zeroth word if there is only one word in the line.
726f6388
JA
7557.TP
7558.B %
8868edaf
CR
7559The first word matched by the most recent `?\fIstring\fR?' search,
7560if the search string begins with a character that is part of a word.
726f6388
JA
7561.TP
7562.I x\fB\-\fPy
7563A range of words; `\-\fIy\fR' abbreviates `0\-\fIy\fR'.
7564.TP
7565.B *
7566All of the words but the zeroth. This is a synonym
7567for `\fI1\-$\fP'. It is not an error to use
7568.B *
7569if there is just one
7570word in the event; the empty string is returned in that case.
7571.TP
7572.B x*
7573Abbreviates \fIx\-$\fP.
7574.TP
7575.B x\-
7576Abbreviates \fIx\-$\fP like \fBx*\fP, but omits the last word.
8868edaf 7577If \fBx\fP is missing, it defaults to 0.
726f6388 7578.PD
ccc6cda3
JA
7579.PP
7580If a word designator is supplied without an event specification, the
7581previous command is used as the event.
726f6388 7582.SS Modifiers
ccc6cda3
JA
7583After the optional word designator, there may appear a sequence of
7584one or more of the following modifiers, each preceded by a `:'.
8868edaf 7585These modify, or edit, the word or words selected from the history event.
726f6388
JA
7586.PP
7587.PD 0
726f6388
JA
7588.TP
7589.B h
ac50fbac 7590Remove a trailing filename component, leaving only the head.
ccc6cda3
JA
7591.TP
7592.B t
ac50fbac 7593Remove all leading filename components, leaving the tail.
726f6388
JA
7594.TP
7595.B r
7596Remove a trailing suffix of the form \fI.xxx\fP, leaving the
7597basename.
7598.TP
7599.B e
7600Remove all but the trailing suffix.
7601.TP
726f6388
JA
7602.B p
7603Print the new command but do not execute it.
7604.TP
7605.B q
7606Quote the substituted words, escaping further substitutions.
7607.TP
cce855bc
JA
7608.B x
7609Quote the substituted words as with
7610.BR q ,
7611but break into words at
7612.B blanks
7613and newlines.
8868edaf
CR
7614The \fBq\fP and \fBx\fP modifiers are mutually exclusive; the last one
7615supplied is used.
726f6388 7616.TP
cce855bc
JA
7617.B s/\fIold\fP/\fInew\fP/
7618Substitute
7619.I new
7620for the first occurrence of
7621.I old
8868edaf
CR
7622in the event line.
7623Any character may be used as the delimiter in place of /.
7624The final delimiter is optional if it is the last character of the
7625event line.
7626The delimiter may be quoted in
cce855bc
JA
7627.I old
7628and
7629.I new
7630with a single backslash. If & appears in
7631.IR new ,
7632it is replaced by
7633.IR old .
8868edaf
CR
7634A single backslash will quote the &.
7635If
cce855bc
JA
7636.I old
7637is null, it is set to the last
7638.I old
7639substituted, or, if no previous history substitutions took place,
7640the last
7641.I string
7642in a
7643.B !?\fIstring\fR\fB[?]\fR
7644search.
8868edaf
CR
7645If
7646.I new
7647is null, each matching
7648.I old
7649is deleted.
ccc6cda3 7650.TP
cce855bc
JA
7651.B &
7652Repeat the previous substitution.
7653.TP
7654.B g
7655Cause changes to be applied over the entire event line. This is
7656used in conjunction with `\fB:s\fP' (e.g., `\fB:gs/\fIold\fP/\fInew\fP/\fR')
7657or `\fB:&\fP'. If used with
7658`\fB:s\fP', any delimiter can be used
7659in place of /, and the final delimiter is optional
7660if it is the last character of the event line.
b80f6443
JA
7661An \fBa\fP may be used as a synonym for \fBg\fP.
7662.TP
7663.B G
8868edaf
CR
7664Apply the following `\fBs\fP' or `\fB&\fP' modifier once to each word
7665in the event line.
726f6388 7666.PD
726f6388
JA
7667.SH "SHELL BUILTIN COMMANDS"
7668.\" start of bash_builtins
7669.zZ
ccc6cda3
JA
7670.PP
7671Unless otherwise noted, each builtin command documented in this
7672section as accepting options preceded by
7673.B \-
7674accepts
7675.B \-\-
7676to signify the end of the options.
d233b485 7677The \fB:\fP, \fBtrue\fP, \fBfalse\fP, and \fBtest\fP/\fB[\fP builtins
0001803f 7678do not accept options and do not treat \fB\-\-\fP specially.
a0c0a00f
CR
7679The \fBexit\fP, \fBlogout\fP, \fBreturn\fP,
7680\fBbreak\fP, \fBcontinue\fP, \fBlet\fP,
0001803f
CR
7681and \fBshift\fP builtins accept and process arguments beginning with
7682\fB\-\fP without requiring \fB\-\-\fP.
7683Other builtins that accept arguments but are not specified as accepting
7684options interpret arguments beginning with \fB\-\fP as invalid options and
7685require \fB\-\-\fP to prevent this interpretation.
ccc6cda3 7686.sp .5
726f6388
JA
7687.PD 0
7688.TP
7689\fB:\fP [\fIarguments\fP]
7690.PD
7691No effect; the command does nothing beyond expanding
7692.I arguments
7693and performing any specified
a0c0a00f
CR
7694redirections.
7695The return status is zero.
726f6388 7696.TP
726f6388 7697\fB .\| \fP \fIfilename\fP [\fIarguments\fP]
7117c2d2 7698.PD 0
726f6388
JA
7699.TP
7700\fBsource\fP \fIfilename\fP [\fIarguments\fP]
7701.PD
7702Read and execute commands from
7703.I filename
7704in the current
7705shell environment and return the exit status of the last command
7706executed from
7707.IR filename .
7708If
7709.I filename
ac50fbac 7710does not contain a slash, filenames in
726f6388
JA
7711.SM
7712.B PATH
7713are used to find the directory containing
74091dd4
CR
7714.IR filename ,
7715but \fIfilename\fP does not need to be executable.
726f6388
JA
7716The file searched for in
7717.SM
7718.B PATH
28ef6c31 7719need not be executable.
74091dd4
CR
7720When \fBbash\fP is not in \fIposix mode\fP, it searches
7721the current directory if no file is found in
726f6388
JA
7722.SM
7723.BR PATH .
ccc6cda3
JA
7724If the
7725.B sourcepath
7726option to the
7727.B shopt
7728builtin command is turned off, the
7729.SM
7730.B PATH
7731is not searched.
726f6388 7732If any \fIarguments\fP are supplied, they become the positional
ccc6cda3 7733parameters when \fIfilename\fP is executed. Otherwise the positional
726f6388 7734parameters are unchanged.
74091dd4 7735If the \fB\-T\fP option is enabled, \fB.\fP inherits any trap on
a0c0a00f 7736\fBDEBUG\fP; if it is not, any \fBDEBUG\fP trap string is saved and
74091dd4 7737restored around the call to \fB.\fP, and \fB.\fP unsets the
a0c0a00f
CR
7738\fBDEBUG\fP trap while it executes.
7739If \fB\-T\fP is not set, and the sourced file changes
74091dd4 7740the \fBDEBUG\fP trap, the new value is retained when \fB.\fP completes.
726f6388
JA
7741The return status is the status of the last command exited within
7742the script (0 if no commands are executed), and false if
7743.I filename
cce855bc 7744is not found or cannot be read.
726f6388 7745.TP
ccc6cda3
JA
7746\fBalias\fP [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...]
7747\fBAlias\fP with no arguments or with the
7748.B \-p
7749option prints the list of aliases in the form
7750\fBalias\fP \fIname\fP=\fIvalue\fP on standard output.
7751When arguments are supplied, an alias is defined for
7752each \fIname\fP whose \fIvalue\fP is given.
a0c0a00f 7753A trailing space in \fIvalue\fP causes the next word to be
ccc6cda3
JA
7754checked for alias substitution when the alias is expanded.
7755For each \fIname\fP in the argument list for which no \fIvalue\fP
7756is supplied, the name and value of the alias is printed.
7757\fBAlias\fP returns true unless a \fIname\fP is given for which
7758no alias has been defined.
726f6388 7759.TP
95732b49
JA
7760\fBbg\fP [\fIjobspec\fP ...]
7761Resume each suspended job \fIjobspec\fP in the background, as if it
cce855bc 7762had been started with
726f6388 7763.BR & .
3185942a
JA
7764If
7765.I jobspec
7766is not present, the shell's notion of the \fIcurrent job\fP is used.
726f6388
JA
7767.B bg
7768.I jobspec
7769returns 0 unless run when job control is disabled or, when run with
95732b49
JA
7770job control enabled, any specified \fIjobspec\fP was not found
7771or was started without job control.
726f6388 7772.TP
ac50fbac 7773\fBbind\fP [\fB\-m\fP \fIkeymap\fP] [\fB\-lpsvPSVX\fP]
7117c2d2 7774.PD 0
cce855bc
JA
7775.TP
7776\fBbind\fP [\fB\-m\fP \fIkeymap\fP] [\fB\-q\fP \fIfunction\fP] [\fB\-u\fP \fIfunction\fP] [\fB\-r\fP \fIkeyseq\fP]
726f6388 7777.TP
ccc6cda3 7778\fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-f\fP \fIfilename\fP
726f6388 7779.TP
bb70624e
JA
7780\fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-x\fP \fIkeyseq\fP:\fIshell\-command\fP
7781.TP
ccc6cda3 7782\fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fIkeyseq\fP:\fIfunction\-name\fP
7117c2d2 7783.TP
a0c0a00f 7784\fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fIkeyseq\fP:\fIreadline\-command\fP
74091dd4
CR
7785.TP
7786\fBbind\fP \fIreadline-command-line\fP
726f6388
JA
7787.PD
7788Display current
7789.B readline
7117c2d2 7790key and function bindings, bind a key sequence to a
726f6388 7791.B readline
7117c2d2
JA
7792function or macro, or set a
7793.B readline
7794variable.
74091dd4
CR
7795Each non-option argument is a command as it would appear in a
7796.B readline
7797initialization file such as
726f6388 7798.IR .inputrc ,
7117c2d2
JA
7799but each binding or command must be passed as a separate argument;
7800e.g., '"\eC\-x\eC\-r": re\-read\-init\-file'.
7801Options, if supplied, have the following meanings:
726f6388
JA
7802.RS
7803.PD 0
7804.TP
7805.B \-m \fIkeymap\fP
7806Use
7807.I keymap
7808as the keymap to be affected by the subsequent bindings.
7809Acceptable
7810.I keymap
7811names are
ccc6cda3 7812\fIemacs, emacs\-standard, emacs\-meta, emacs\-ctlx, vi,
28ef6c31 7813vi\-move, vi\-command\fP, and
ccc6cda3 7814.IR vi\-insert .
a0c0a00f
CR
7815\fIvi\fP is equivalent to \fIvi\-command\fP (\fIvi\-move\fP is also
7816a synonym); \fIemacs\fP is
ccc6cda3 7817equivalent to \fIemacs\-standard\fP.
726f6388
JA
7818.TP
7819.B \-l
ccc6cda3
JA
7820List the names of all \fBreadline\fP functions.
7821.TP
7822.B \-p
7823Display \fBreadline\fP function names and bindings in such a way
7824that they can be re-read.
7825.TP
7826.B \-P
7827List current \fBreadline\fP function names and bindings.
726f6388 7828.TP
ccc6cda3
JA
7829.B \-s
7830Display \fBreadline\fP key sequences bound to macros and the strings
7831they output in such a way that they can be re-read.
7832.TP
7833.B \-S
7834Display \fBreadline\fP key sequences bound to macros and the strings
7835they output.
726f6388 7836.TP
3185942a
JA
7837.B \-v
7838Display \fBreadline\fP variable names and values in such a way that they
7839can be re-read.
7840.TP
7841.B \-V
7842List current \fBreadline\fP variable names and values.
7843.TP
726f6388 7844.B \-f \fIfilename\fP
ccc6cda3 7845Read key bindings from \fIfilename\fP.
726f6388
JA
7846.TP
7847.B \-q \fIfunction\fP
ccc6cda3
JA
7848Query about which keys invoke the named \fIfunction\fP.
7849.TP
cce855bc
JA
7850.B \-u \fIfunction\fP
7851Unbind all keys bound to the named \fIfunction\fP.
7852.TP
ccc6cda3
JA
7853.B \-r \fIkeyseq\fP
7854Remove any current binding for \fIkeyseq\fP.
bb70624e
JA
7855.TP
7856.B \-x \fIkeyseq\fP:\fIshell\-command\fP
7857Cause \fIshell\-command\fP to be executed whenever \fIkeyseq\fP is
7858entered.
3185942a 7859When \fIshell\-command\fP is executed, the shell sets the
0001803f 7860.SM
3185942a
JA
7861.B READLINE_LINE
7862variable to the contents of the \fBreadline\fP line buffer and the
0001803f 7863.SM
3185942a 7864.B READLINE_POINT
8868edaf 7865and
0001803f 7866.SM
8868edaf
CR
7867.B READLINE_MARK
7868variables to the current location of the insertion point and the saved
7869insertion point (the mark), respectively.
74091dd4
CR
7870The shell assigns any numeric argument the user supplied to the
7871.SM
7872.B READLINE_ARGUMENT
7873variable.
7874If there was no argument, that variable is not set.
8868edaf
CR
7875If the executed command changes the value of any of
7876.SM
7877.BR READLINE_LINE ,
0001803f 7878.SM
3185942a 7879.BR READLINE_POINT ,
8868edaf
CR
7880or
7881.SM
7882.BR READLINE_MARK ,
3185942a 7883those new values will be reflected in the editing state.
ac50fbac
CR
7884.TP
7885.B \-X
7886List all key sequences bound to shell commands and the associated commands
7887in a format that can be reused as input.
726f6388
JA
7888.PD
7889.PP
7890The return value is 0 unless an unrecognized option is given or an
7891error occurred.
7892.RE
7893.TP
7894\fBbreak\fP [\fIn\fP]
7895Exit from within a
7896.BR for ,
7897.BR while ,
ccc6cda3 7898.BR until ,
726f6388 7899or
ccc6cda3 7900.B select
726f6388
JA
7901loop. If \fIn\fP is specified, break \fIn\fP levels.
7902.I n
7903must be \(>= 1. If
7904.I n
7905is greater than the number of enclosing loops, all enclosing loops
3185942a
JA
7906are exited.
7907The return value is 0 unless \fIn\fP is not greater than or equal to 1.
726f6388
JA
7908.TP
7909\fBbuiltin\fP \fIshell\-builtin\fP [\fIarguments\fP]
7910Execute the specified shell builtin, passing it
7911.IR arguments ,
7912and return its exit status.
cce855bc 7913This is useful when defining a
726f6388 7914function whose name is the same as a shell builtin,
cce855bc
JA
7915retaining the functionality of the builtin within the function.
7916The \fBcd\fP builtin is commonly redefined this way.
7917The return status is false if
726f6388
JA
7918.I shell\-builtin
7919is not a shell builtin command.
7920.TP
3185942a
JA
7921\fBcaller\fP [\fIexpr\fP]
7922Returns the context of any active subroutine call (a shell function or
495aee44 7923a script executed with the \fB.\fP or \fBsource\fP builtins).
3185942a
JA
7924Without \fIexpr\fP, \fBcaller\fP displays the line number and source
7925filename of the current subroutine call.
a0c0a00f 7926If a non-negative integer is supplied as \fIexpr\fP, \fBcaller\fP
3185942a
JA
7927displays the line number, subroutine name, and source file corresponding
7928to that position in the current execution call stack. This extra
7929information may be used, for example, to print a stack trace. The
7930current frame is frame 0.
7931The return value is 0 unless the shell is not executing a subroutine
7932call or \fIexpr\fP does not correspond to a valid position in the
7933call stack.
7934.TP
ac50fbac
CR
7935\fBcd\fP [\fB\-L\fP|[\fB\-P\fP [\fB\-e\fP]] [\-@]] [\fIdir\fP]
7936Change the current directory to \fIdir\fP.
7937if \fIdir\fP is not supplied, the value of the
726f6388
JA
7938.SM
7939.B HOME
ac50fbac 7940shell variable is the default.
726f6388
JA
7941The variable
7942.SM
7943.B CDPATH
ccc6cda3 7944defines the search path for the directory containing
ac50fbac
CR
7945.IR dir :
7946each directory name in
7947.SM
7948.B CDPATH
7949is searched for \fIdir\fP.
ccc6cda3
JA
7950Alternative directory names in
7951.SM
7952.B CDPATH
7953are separated by a colon (:). A null directory name in
726f6388
JA
7954.SM
7955.B CDPATH
ccc6cda3 7956is the same as the current directory, i.e., ``\fB.\fP''. If
726f6388
JA
7957.I dir
7958begins with a slash (/),
7959then
7960.SM
7961.B CDPATH
a0c0a00f 7962is not used. The
ccc6cda3 7963.B \-P
ac50fbac
CR
7964option causes \fBcd\fP to use the physical directory structure
7965by resolving symbolic links while traversing \fIdir\fP and
7966before processing instances of \fI..\fP in \fIdir\fP (see also the
ccc6cda3
JA
7967.B \-P
7968option to the
7969.B set
7970builtin command); the
7971.B \-L
ac50fbac
CR
7972option forces symbolic links to be followed by resolving the link
7973after processing instances of \fI..\fP in \fIdir\fP.
7974If \fI..\fP appears in \fIdir\fP, it is processed by removing the
7975immediately previous pathname component from \fIdir\fP, back to a slash
7976or the beginning of \fIdir\fP.
495aee44
CR
7977If the
7978.B \-e
7979option is supplied with
7980.BR \-P ,
7981and the current working directory cannot be successfully determined
7982after a successful directory change, \fBcd\fP will return an unsuccessful
7983status.
ac50fbac
CR
7984On systems that support it, the \fB\-@\fP option presents the extended
7985attributes associated with a file as a directory.
495aee44 7986An argument of
726f6388 7987.B \-
ac50fbac 7988is converted to
726f6388 7989.SM
ac50fbac
CR
7990.B $OLDPWD
7991before the directory change is attempted.
0001803f
CR
7992If a non-empty directory name from
7993.SM
7994.B CDPATH
7995is used, or if
b80f6443
JA
7996\fB\-\fP is the first argument, and the directory change is
7997successful, the absolute pathname of the new working directory is
7998written to the standard output.
74091dd4
CR
7999If the directory change is successful, \fBcd\fP sets the value of the
8000\fBPWD\fP environment variable to the new directory name, and sets the
8001\fBOLDPWD\fP environment variable to the value of the current working
8002directory before the change.
726f6388
JA
8003The return value is true if the directory was successfully changed;
8004false otherwise.
8005.TP
ccc6cda3 8006\fBcommand\fP [\fB\-pVv\fP] \fIcommand\fP [\fIarg\fP ...]
726f6388
JA
8007Run
8008.I command
8009with
8010.I args
a0c0a00f
CR
8011suppressing the normal shell function lookup.
8012Only builtin commands or commands found in the
726f6388
JA
8013.SM
8014.B PATH
8015are executed. If the
8016.B \-p
8017option is given, the search for
8018.I command
8019is performed using a default value for
0001803f 8020.SM
726f6388
JA
8021.B PATH
8022that is guaranteed to find all of the standard utilities.
8023If either the
8024.B \-V
8025or
8026.B \-v
8027option is supplied, a description of
8028.I command
8029is printed. The
8030.B \-v
ac50fbac 8031option causes a single word indicating the command or filename
726f6388
JA
8032used to invoke
8033.I command
cce855bc 8034to be displayed; the
726f6388
JA
8035.B \-V
8036option produces a more verbose description.
726f6388
JA
8037If the
8038.B \-V
8039or
8040.B \-v
8041option is supplied, the exit status is 0 if
8042.I command
8043was found, and 1 if not. If neither option is supplied and
8044an error occurred or
8045.I command
8046cannot be found, the exit status is 127. Otherwise, the exit status of the
8047.B command
8048builtin is the exit status of
8049.IR command .
8050.TP
bb70624e
JA
8051\fBcompgen\fP [\fIoption\fP] [\fIword\fP]
8052Generate possible completion matches for \fIword\fP according to
8053the \fIoption\fPs, which may be any option accepted by the
8054.B complete
8055builtin with the exception of \fB\-p\fP and \fB\-r\fP, and write
8056the matches to the standard output.
8057When using the \fB\-F\fP or \fB\-C\fP options, the various shell variables
8058set by the programmable completion facilities, while available, will not
8059have useful values.
8060.sp 1
8061The matches will be generated in the same way as if the programmable
8062completion code had generated them directly from a completion specification
8063with the same flags.
8064If \fIword\fP is specified, only those completions matching \fIword\fP
8065will be displayed.
8066.sp 1
8067The return value is true unless an invalid option is supplied, or no
8068matches were generated.
8069.TP
8868edaf 8070\fBcomplete\fP [\fB\-abcdefgjksuv\fP] [\fB\-o\fP \fIcomp-option\fP] [\fB\-DEI\fP] [\fB\-A\fP \fIaction\fP] [\fB\-G\fP \fIglobpat\fP] [\fB\-W\fP \fIwordlist\fP]
bb70624e 8071.br
8868edaf 8072[\fB\-F\fP \fIfunction\fP] [\fB\-C\fP \fIcommand\fP] [\fB\-X\fP \fIfilterpat\fP] [\fB\-P\fP \fIprefix\fP] [\fB\-S\fP \fIsuffix\fP] \fIname\fP [\fIname ...\fP]
7117c2d2 8073.PD 0
bb70624e 8074.TP
d233b485 8075\fBcomplete\fP \fB\-pr\fP [\fB\-DEI\fP] [\fIname\fP ...]
bb70624e
JA
8076.PD
8077Specify how arguments to each \fIname\fP should be completed.
8078If the \fB\-p\fP option is supplied, or if no options are supplied,
8079existing completion specifications are printed in a way that allows
8080them to be reused as input.
8081The \fB\-r\fP option removes a completion specification for
8082each \fIname\fP, or, if no \fIname\fPs are supplied, all
8083completion specifications.
d233b485 8084The \fB\-D\fP option indicates that other supplied options and actions should
0001803f
CR
8085apply to the ``default'' command completion; that is, completion attempted
8086on a command for which no completion has previously been defined.
d233b485 8087The \fB\-E\fP option indicates that other supplied options and actions should
3185942a
JA
8088apply to ``empty'' command completion; that is, completion attempted on a
8089blank line.
d233b485 8090The \fB\-I\fP option indicates that other supplied options and actions should
8868edaf 8091apply to completion on the initial non-assignment word on the line, or after
d233b485
CR
8092a command delimiter such as \fB;\fP or \fB|\fP, which is usually command
8093name completion.
8094If multiple options are supplied, the \fB\-D\fP option takes precedence
8095over \fB\-E\fP, and both take precedence over \fB\-I\fP.
8096If any of \fB\-D\fP, \fB\-E\fP, or \fB\-I\fP are supplied, any other
8097\fIname\fP arguments are ignored; these completions only apply to the case
8098specified by the option.
bb70624e
JA
8099.sp 1
8100The process of applying these completion specifications when word completion
74091dd4
CR
8101is attempted is described
8102.ie \n(zZ=1 in \fIbash(1)\fP.
8103.el above under \fBProgrammable Completion\fP.
bb70624e
JA
8104.sp 1
8105Other options, if specified, have the following meanings.
8106The arguments to the \fB\-G\fP, \fB\-W\fP, and \fB\-X\fP options
8107(and, if necessary, the \fB\-P\fP and \fB\-S\fP options)
8108should be quoted to protect them from expansion before the
8109.B complete
8110builtin is invoked.
8111.RS
8112.PD 0
8113.TP 8
28ef6c31
JA
8114\fB\-o\fP \fIcomp-option\fP
8115The \fIcomp-option\fP controls several aspects of the compspec's behavior
8116beyond the simple generation of completions.
8117\fIcomp-option\fP may be one of:
8118.RS
8119.TP 8
b80f6443
JA
8120.B bashdefault
8121Perform the rest of the default \fBbash\fP completions if the compspec
8122generates no matches.
8123.TP 8
28ef6c31 8124.B default
7117c2d2
JA
8125Use readline's default filename completion if the compspec generates
8126no matches.
28ef6c31
JA
8127.TP 8
8128.B dirnames
8129Perform directory name completion if the compspec generates no matches.
8130.TP 8
8131.B filenames
8132Tell readline that the compspec generates filenames, so it can perform any
3185942a
JA
8133filename\-specific processing (like adding a slash to directory names,
8134quoting special characters, or suppressing trailing spaces).
8135Intended to be used with shell functions.
7117c2d2 8136.TP 8
ac50fbac
CR
8137.B noquote
8138Tell readline not to quote the completed words if they are filenames
8139(quoting filenames is the default).
8140.TP 8
a0c0a00f
CR
8141.B nosort
8142Tell readline not to sort the list of possible completions alphabetically.
8143.TP 8
7117c2d2
JA
8144.B nospace
8145Tell readline not to append a space (the default) to words completed at
8146the end of the line.
95732b49
JA
8147.TP 8
8148.B plusdirs
a0c0a00f 8149After any matches defined by the compspec are generated,
95732b49
JA
8150directory name completion is attempted and any
8151matches are added to the results of the other actions.
28ef6c31
JA
8152.RE
8153.TP 8
bb70624e
JA
8154\fB\-A\fP \fIaction\fP
8155The \fIaction\fP may be one of the following to generate a list of possible
8156completions:
8157.RS
8158.TP 8
8159.B alias
8160Alias names. May also be specified as \fB\-a\fP.
8161.TP 8
8162.B arrayvar
8163Array variable names.
8164.TP 8
8165.B binding
8166\fBReadline\fP key binding names.
8167.TP 8
8168.B builtin
8169Names of shell builtin commands. May also be specified as \fB\-b\fP.
8170.TP 8
8171.B command
8172Command names. May also be specified as \fB\-c\fP.
8173.TP 8
8174.B directory
8175Directory names. May also be specified as \fB\-d\fP.
8176.TP 8
8177.B disabled
8178Names of disabled shell builtins.
8179.TP 8
8180.B enabled
8181Names of enabled shell builtins.
8182.TP 8
8183.B export
8184Names of exported shell variables. May also be specified as \fB\-e\fP.
8185.TP 8
8186.B file
8187File names. May also be specified as \fB\-f\fP.
8188.TP 8
8189.B function
8190Names of shell functions.
8191.TP 8
f73dda09
JA
8192.B group
8193Group names. May also be specified as \fB\-g\fP.
8194.TP 8
bb70624e
JA
8195.B helptopic
8196Help topics as accepted by the \fBhelp\fP builtin.
8197.TP 8
8198.B hostname
8199Hostnames, as taken from the file specified by the
8200.SM
8201.B HOSTFILE
8202shell variable.
8203.TP 8
8204.B job
8205Job names, if job control is active. May also be specified as \fB\-j\fP.
8206.TP 8
8207.B keyword
8208Shell reserved words. May also be specified as \fB\-k\fP.
8209.TP 8
8210.B running
8211Names of running jobs, if job control is active.
8212.TP 8
7117c2d2
JA
8213.B service
8214Service names. May also be specified as \fB\-s\fP.
8215.TP 8
bb70624e
JA
8216.B setopt
8217Valid arguments for the \fB\-o\fP option to the \fBset\fP builtin.
8218.TP 8
8219.B shopt
8220Shell option names as accepted by the \fBshopt\fP builtin.
8221.TP 8
8222.B signal
8223Signal names.
8224.TP 8
8225.B stopped
8226Names of stopped jobs, if job control is active.
8227.TP 8
8228.B user
8229User names. May also be specified as \fB\-u\fP.
8230.TP 8
8231.B variable
8232Names of all shell variables. May also be specified as \fB\-v\fP.
8233.RE
8234.TP 8
bb70624e
JA
8235\fB\-C\fP \fIcommand\fP
8236\fIcommand\fP is executed in a subshell environment, and its output is
8237used as the possible completions.
74091dd4 8238Arguments are passed as with the \fB\-F\fP option.
bb70624e
JA
8239.TP 8
8240\fB\-F\fP \fIfunction\fP
8241The shell function \fIfunction\fP is executed in the current shell
8242environment.
ac50fbac
CR
8243When the function is executed,
8244the first argument (\fB$1\fP) is the name of the command whose arguments are
8245being completed,
8246the second argument (\fB$2\fP) is the word being completed,
8247and the third argument (\fB$3\fP) is the word preceding the word being
8248completed on the current command line.
bb70624e
JA
8249When it finishes, the possible completions are retrieved from the value
8250of the
8251.SM
8252.B COMPREPLY
8253array variable.
8254.TP 8
495aee44
CR
8255\fB\-G\fP \fIglobpat\fP
8256The pathname expansion pattern \fIglobpat\fP is expanded to generate
8257the possible completions.
bb70624e
JA
8258.TP 8
8259\fB\-P\fP \fIprefix\fP
8260\fIprefix\fP is added at the beginning of each possible completion
8261after all other options have been applied.
8262.TP 8
8263\fB\-S\fP \fIsuffix\fP
8264\fIsuffix\fP is appended to each possible completion
8265after all other options have been applied.
495aee44
CR
8266.TP 8
8267\fB\-W\fP \fIwordlist\fP
8268The \fIwordlist\fP is split using the characters in the
8269.SM
8270.B IFS
8271special variable as delimiters, and each resultant word is expanded.
d233b485
CR
8272Shell quoting is honored within \fIwordlist\fP,
8273in order to provide a
8274mechanism for the words to contain shell metacharacters or characters
8275in the value of
8276.SM
8277.BR IFS .
495aee44
CR
8278The possible completions are the members of the resultant list which
8279match the word being completed.
8280.TP 8
8281\fB\-X\fP \fIfilterpat\fP
8282\fIfilterpat\fP is a pattern as used for pathname expansion.
8283It is applied to the list of possible completions generated by the
8284preceding options and arguments, and each completion matching
8285\fIfilterpat\fP is removed from the list.
8286A leading \fB!\fP in \fIfilterpat\fP negates the pattern; in this
8287case, any completion not matching \fIfilterpat\fP is removed.
bb70624e
JA
8288.PD
8289.PP
8290The return value is true unless an invalid option is supplied, an option
8291other than \fB\-p\fP or \fB\-r\fP is supplied without a \fIname\fP
8292argument, an attempt is made to remove a completion specification for
8293a \fIname\fP for which no specification exists, or
8294an error occurs adding a completion specification.
8295.RE
8296.TP
d233b485 8297\fBcompopt\fP [\fB\-o\fP \fIoption\fP] [\fB\-DEI\fP] [\fB+o\fP \fIoption\fP] [\fIname\fP]
3185942a
JA
8298Modify completion options for each \fIname\fP according to the
8299\fIoption\fPs, or for the
495aee44 8300currently-executing completion if no \fIname\fPs are supplied.
3185942a
JA
8301If no \fIoption\fPs are given, display the completion options for each
8302\fIname\fP or the current completion.
8303The possible values of \fIoption\fP are those valid for the \fBcomplete\fP
8304builtin described above.
d233b485 8305The \fB\-D\fP option indicates that other supplied options should
0001803f
CR
8306apply to the ``default'' command completion; that is, completion attempted
8307on a command for which no completion has previously been defined.
d233b485 8308The \fB\-E\fP option indicates that other supplied options should
0001803f
CR
8309apply to ``empty'' command completion; that is, completion attempted on a
8310blank line.
d233b485 8311The \fB\-I\fP option indicates that other supplied options should
8868edaf 8312apply to completion on the initial non-assignment word on the line,
d233b485
CR
8313or after a command delimiter such as \fB;\fP or \fB|\fP, which is usually
8314command name completion.
495aee44 8315.sp 1
3185942a
JA
8316The return value is true unless an invalid option is supplied, an attempt
8317is made to modify the options for a \fIname\fP for which no completion
8318specification exists, or an output error occurs.
8319.TP
726f6388
JA
8320\fBcontinue\fP [\fIn\fP]
8321Resume the next iteration of the enclosing
8322.BR for ,
8323.BR while ,
ccc6cda3 8324.BR until ,
726f6388 8325or
ccc6cda3 8326.B select
726f6388
JA
8327loop.
8328If
8329.I n
8330is specified, resume at the \fIn\fPth enclosing loop.
8331.I n
8332must be \(>= 1. If
8333.I n
8334is greater than the number of enclosing loops, the last enclosing loop
3185942a
JA
8335(the ``top-level'' loop) is resumed.
8336The return value is 0 unless \fIn\fP is not greater than or equal to 1.
726f6388 8337.TP
8868edaf 8338\fBdeclare\fP [\fB\-aAfFgiIlnrtux\fP] [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...]
726f6388 8339.PD 0
726f6388 8340.TP
8868edaf 8341\fBtypeset\fP [\fB\-aAfFgiIlnrtux\fP] [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...]
726f6388 8342.PD
ccc6cda3
JA
8343Declare variables and/or give them attributes.
8344If no \fIname\fPs are given then display the values of variables.
8345The
8346.B \-p
8347option will display the attributes and values of each
8348.IR name .
8349When
8350.B \-p
ac50fbac
CR
8351is used with \fIname\fP arguments, additional options,
8352other than \fB\-f\fP and \fB\-F\fP, are ignored.
3185942a
JA
8353When
8354.B \-p
8355is supplied without \fIname\fP arguments, it will display the attributes
8356and values of all variables having the attributes specified by the
8357additional options.
8358If no other options are supplied with \fB\-p\fP, \fBdeclare\fP will display
8359the attributes and values of all shell variables. The \fB\-f\fP option
8360will restrict the display to shell functions.
ccc6cda3
JA
8361The
8362.B \-F
8363option inhibits the display of function definitions; only the
8364function name and attributes are printed.
b80f6443 8365If the \fBextdebug\fP shell option is enabled using \fBshopt\fP,
a0c0a00f
CR
8366the source file name and line number where each \fIname\fP
8367is defined are displayed as well. The
ccc6cda3
JA
8368.B \-F
8369option implies
8370.BR \-f .
495aee44
CR
8371The
8372.B \-g
8373option forces variables to be created or modified at the global scope,
8374even when \fBdeclare\fP is executed in a shell function.
8375It is ignored in all other cases.
8868edaf
CR
8376The
8377.B \-I
8378option causes local variables to inherit the attributes
8379(except the \fInameref\fP attribute)
8380and value of any existing variable with the same
8381\fIname\fP at a surrounding scope.
8382If there is no existing variable, the local variable is initially unset.
ccc6cda3
JA
8383The following options can
8384be used to restrict output to variables with the specified attribute or
8385to give variables attributes:
726f6388
JA
8386.RS
8387.PD 0
8388.TP
ccc6cda3 8389.B \-a
3185942a
JA
8390Each \fIname\fP is an indexed array variable (see
8391.B Arrays
74091dd4
CR
8392.ie \n(zZ=1 in \fIbash(1)\fP).
8393.el above).
3185942a
JA
8394.TP
8395.B \-A
8396Each \fIname\fP is an associative array variable (see
ccc6cda3 8397.B Arrays
74091dd4
CR
8398.ie \n(zZ=1 in \fIbash(1)\fP).
8399.el above).
ccc6cda3 8400.TP
726f6388 8401.B \-f
ccc6cda3
JA
8402Use function names only.
8403.TP
8404.B \-i
8405The variable is treated as an integer; arithmetic evaluation (see
8406.SM
0001803f 8407.B "ARITHMETIC EVALUATION"
74091dd4
CR
8408.ie \n(zZ=1 in \fIbash(1)\fP)
8409.el above)
8410is performed when the variable is assigned a value.
726f6388 8411.TP
3185942a
JA
8412.B \-l
8413When the variable is assigned a value, all upper-case characters are
8414converted to lower-case.
8415The upper-case attribute is disabled.
8416.TP
ac50fbac
CR
8417.B \-n
8418Give each \fIname\fP the \fInameref\fP attribute, making
8419it a name reference to another variable.
8420That other variable is defined by the value of \fIname\fP.
a0c0a00f
CR
8421All references, assignments, and attribute modifications
8422to \fIname\fP, except those using or changing the
ac50fbac
CR
8423\fB\-n\fP attribute itself, are performed on the variable referenced by
8424\fIname\fP's value.
a0c0a00f 8425The nameref attribute cannot be applied to array variables.
ac50fbac 8426.TP
726f6388
JA
8427.B \-r
8428Make \fIname\fPs readonly. These names cannot then be assigned values
cce855bc 8429by subsequent assignment statements or unset.
726f6388 8430.TP
7117c2d2
JA
8431.B \-t
8432Give each \fIname\fP the \fItrace\fP attribute.
95732b49
JA
8433Traced functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps from
8434the calling shell.
7117c2d2
JA
8435The trace attribute has no special meaning for variables.
8436.TP
3185942a
JA
8437.B \-u
8438When the variable is assigned a value, all lower-case characters are
8439converted to upper-case.
8440The lower-case attribute is disabled.
8441.TP
726f6388
JA
8442.B \-x
8443Mark \fIname\fPs for export to subsequent commands via the environment.
726f6388
JA
8444.PD
8445.PP
8446Using `+' instead of `\-'
3185942a 8447turns off the attribute instead,
d233b485
CR
8448with the exceptions that \fB+a\fP and \fB+A\fP
8449may not be used to destroy array variables and \fB+r\fP will not
3185942a 8450remove the readonly attribute.
ac50fbac
CR
8451When used in a function,
8452.B declare
8453and
8454.B typeset
8455make each
495aee44 8456\fIname\fP local, as with the
726f6388 8457.B local
495aee44 8458command,
ac50fbac 8459unless the \fB\-g\fP option is supplied.
b80f6443
JA
8460If a variable name is followed by =\fIvalue\fP, the value of
8461the variable is set to \fIvalue\fP.
ac50fbac
CR
8462When using \fB\-a\fP or \fB\-A\fP and the compound assignment syntax to
8463create array variables, additional attributes do not take effect until
8464subsequent assignments.
b80f6443 8465The return value is 0 unless an invalid option is encountered,
bb70624e
JA
8466an attempt is made to define a function using
8467.if n ``\-f foo=bar'',
8468.if t \f(CW\-f foo=bar\fP,
ccc6cda3
JA
8469an attempt is made to assign a value to a readonly variable,
8470an attempt is made to assign a value to an array variable without
8471using the compound assignment syntax (see
8472.B Arrays
74091dd4
CR
8473.ie \n(zZ=1 in \fIbash(1)\fP),
8474.el above),
8475one of the \fInames\fP is not a valid shell variable name,
726f6388 8476an attempt is made to turn off readonly status for a readonly variable,
ccc6cda3 8477an attempt is made to turn off array status for an array variable,
bb70624e 8478or an attempt is made to display a non-existent function with \fB\-f\fP.
726f6388
JA
8479.RE
8480.TP
ac50fbac 8481.B dirs [\fB\-clpv\fP] [+\fIn\fP] [\-\fIn\fP]
ccc6cda3
JA
8482Without options, displays the list of currently remembered directories.
8483The default display is on a single line with directory names separated
8484by spaces.
a0c0a00f 8485Directories are added to the list with the
726f6388
JA
8486.B pushd
8487command; the
8488.B popd
ccc6cda3 8489command removes entries from the list.
a0c0a00f 8490The current directory is always the first directory in the stack.
726f6388
JA
8491.RS
8492.PD 0
8493.TP
ccc6cda3
JA
8494.B \-c
8495Clears the directory stack by deleting all of the entries.
8496.TP
726f6388 8497.B \-l
ac50fbac
CR
8498Produces a listing using full pathnames;
8499the default listing format uses a tilde to denote the home directory.
ccc6cda3
JA
8500.TP
8501.B \-p
8502Print the directory stack with one entry per line.
8503.TP
8504.B \-v
8505Print the directory stack with one entry per line,
8506prefixing each entry with its index in the stack.
ac50fbac
CR
8507.TP
8508\fB+\fP\fIn\fP
8509Displays the \fIn\fPth entry counting from the left of the list
8510shown by
8511.B dirs
8512when invoked without options, starting with zero.
8513.TP
8514\fB\-\fP\fIn\fP
8515Displays the \fIn\fPth entry counting from the right of the list
8516shown by
8517.B dirs
8518when invoked without options, starting with zero.
726f6388
JA
8519.PD
8520.PP
8521The return value is 0 unless an
cce855bc 8522invalid option is supplied or \fIn\fP indexes beyond the end
726f6388
JA
8523of the directory stack.
8524.RE
8525.TP
a0c0a00f 8526\fBdisown\fP [\fB\-ar\fP] [\fB\-h\fP] [\fIjobspec\fP ... | \fIpid\fP ... ]
ac50fbac 8527Without options, remove each
ccc6cda3 8528.I jobspec
ac50fbac 8529from the table of active jobs.
3185942a
JA
8530If
8531.I jobspec
ac50fbac
CR
8532is not present, and neither the \fB\-a\fP nor the \fB\-r\fP option
8533is supplied, the \fIcurrent job\fP is used.
cce855bc
JA
8534If the \fB\-h\fP option is given, each
8535.I jobspec
8536is not removed from the table, but is marked so that
ccc6cda3
JA
8537.SM
8538.B SIGHUP
8539is not sent to the job if the shell receives a
8540.SM
8541.BR SIGHUP .
8542If no
8543.I jobspec
cce855bc
JA
8544is supplied, the
8545.B \-a
8546option means to remove or mark all jobs; the
8547.B \-r
8548option without a
8549.I jobspec
8550argument restricts operation to running jobs.
8551The return value is 0 unless a
ccc6cda3
JA
8552.I jobspec
8553does not specify a valid job.
8554.TP
726f6388 8555\fBecho\fP [\fB\-neE\fP] [\fIarg\fP ...]
ccc6cda3 8556Output the \fIarg\fPs, separated by spaces, followed by a newline.
ac50fbac 8557The return status is 0 unless a write error occurs.
ccc6cda3 8558If \fB\-n\fP is specified, the trailing newline is
726f6388
JA
8559suppressed. If the \fB\-e\fP option is given, interpretation of
8560the following backslash-escaped characters is enabled. The
8561.B \-E
8562option disables the interpretation of these escape characters,
8563even on systems where they are interpreted by default.
28ef6c31 8564The \fBxpg_echo\fP shell option may be used to
bb70624e
JA
8565dynamically determine whether or not \fBecho\fP expands these
8566escape characters by default.
ccc6cda3 8567.B echo
95732b49 8568does not interpret \fB\-\-\fP to mean the end of options.
ccc6cda3
JA
8569.B echo
8570interprets the following escape sequences:
726f6388
JA
8571.RS
8572.PD 0
8573.TP
8574.B \ea
8575alert (bell)
8576.TP
8577.B \eb
8578backspace
8579.TP
8580.B \ec
3185942a 8581suppress further output
726f6388 8582.TP
ccc6cda3 8583.B \ee
495aee44
CR
8584.TP
8585.B \eE
ccc6cda3
JA
8586an escape character
8587.TP
726f6388
JA
8588.B \ef
8589form feed
8590.TP
8591.B \en
8592new line
8593.TP
8594.B \er
8595carriage return
8596.TP
8597.B \et
8598horizontal tab
8599.TP
8600.B \ev
8601vertical tab
8602.TP
8603.B \e\e
8604backslash
8605.TP
7117c2d2
JA
8606.B \e0\fInnn\fP
8607the eight-bit character whose value is the octal value \fInnn\fP
8608(zero to three octal digits)
8609.TP
f73dda09
JA
8610.B \ex\fIHH\fP
8611the eight-bit character whose value is the hexadecimal value \fIHH\fP
8612(one or two hex digits)
495aee44
CR
8613.TP
8614.B \eu\fIHHHH\fP
8615the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
8616\fIHHHH\fP (one to four hex digits)
8617.TP
8618.B \eU\fIHHHHHHHH\fP
8619the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
8620\fIHHHHHHHH\fP (one to eight hex digits)
726f6388
JA
8621.PD
8622.RE
8623.TP
3185942a 8624\fBenable\fP [\fB\-a\fP] [\fB\-dnps\fP] [\fB\-f\fP \fIfilename\fP] [\fIname\fP ...]
cce855bc
JA
8625Enable and disable builtin shell commands.
8626Disabling a builtin allows a disk command which has the same name
bb70624e 8627as a shell builtin to be executed without specifying a full pathname,
cce855bc 8628even though the shell normally searches for builtins before disk commands.
726f6388
JA
8629If \fB\-n\fP is used, each \fIname\fP
8630is disabled; otherwise,
8631\fInames\fP are enabled. For example, to use the
8632.B test
8633binary found via the
8634.SM
8635.B PATH
ccc6cda3 8636instead of the shell builtin version, run
28ef6c31
JA
8637.if t \f(CWenable -n test\fP.
8638.if n ``enable -n test''.
ccc6cda3
JA
8639The
8640.B \-f
8641option means to load the new builtin command
8642.I name
8643from shared object
8644.IR filename ,
74091dd4
CR
8645on systems that support dynamic loading.
8646Bash will use the value of the \fBBASH_LOADABLES_PATH\fP variable as a
8647colon-separated list of directories in which to search for \fIfilename\fP.
8648The default is system-dependent.
8649The
ccc6cda3
JA
8650.B \-d
8651option will delete a builtin previously loaded with
8652.BR \-f .
8653If no \fIname\fP arguments are given, or if the
8654.B \-p
8655option is supplied, a list of shell builtins is printed.
8656With no other option arguments, the list consists of all enabled
8657shell builtins.
8658If \fB\-n\fP is supplied, only disabled builtins are printed.
8659If \fB\-a\fP is supplied, the list printed includes all builtins, with an
726f6388 8660indication of whether or not each is enabled.
ccc6cda3
JA
8661If \fB\-s\fP is supplied, the output is restricted to the POSIX
8662\fIspecial\fP builtins.
74091dd4
CR
8663If no options are supplied and a \fIname\fP is not a shell builtin,
8664\fBenable\fP will attempt to load \fIname\fP from a shared object named
8665\fIname\fP, as if the command were
8666.if t \f(CWenable \-f\fP \fIname name\fP .
8667.if n ``enable -f \fIname name\fP .
726f6388
JA
8668The return value is 0 unless a
8669.I name
bb70624e 8670is not a shell builtin or there is an error loading a new builtin
ccc6cda3 8671from a shared object.
726f6388
JA
8672.TP
8673\fBeval\fP [\fIarg\fP ...]
8674The \fIarg\fPs are read and concatenated together into a single
8675command. This command is then read and executed by the shell, and
ccc6cda3
JA
8676its exit status is returned as the value of
8677.BR eval .
8678If there are no
726f6388
JA
8679.IR args ,
8680or only null arguments,
8681.B eval
ccc6cda3 8682returns 0.
726f6388 8683.TP
cce855bc 8684\fBexec\fP [\fB\-cl\fP] [\fB\-a\fP \fIname\fP] [\fIcommand\fP [\fIarguments\fP]]
726f6388
JA
8685If
8686.I command
8687is specified, it replaces the shell.
8688No new process is created. The
8689.I arguments
8690become the arguments to \fIcommand\fP.
ccc6cda3
JA
8691If the
8692.B \-l
8693option is supplied,
a0c0a00f 8694the shell places a dash at the beginning of the zeroth argument passed to
726f6388 8695.IR command .
ccc6cda3
JA
8696This is what
8697.IR login (1)
8698does. The
8699.B \-c
8700option causes
8701.I command
8702to be executed with an empty environment. If
8703.B \-a
8704is supplied, the shell passes
8705.I name
ac50fbac
CR
8706as the zeroth argument to the executed command.
8707If
ccc6cda3 8708.I command
726f6388 8709cannot be executed for some reason, a non-interactive shell exits,
ac50fbac 8710unless the
ccc6cda3 8711.B execfail
ac50fbac
CR
8712shell option
8713is enabled. In that case, it returns failure.
ccc6cda3 8714An interactive shell returns failure if the file cannot be executed.
d233b485 8715A subshell exits unconditionally if \fBexec\fP fails.
726f6388
JA
8716If
8717.I command
8718is not specified, any redirections take effect in the current shell,
cce855bc
JA
8719and the return status is 0. If there is a redirection error, the
8720return status is 1.
726f6388
JA
8721.TP
8722\fBexit\fP [\fIn\fP]
8723Cause the shell to exit
8724with a status of \fIn\fP. If
8725.I n
8726is omitted, the exit status
8727is that of the last command executed.
8728A trap on
8729.SM
8730.B EXIT
8731is executed before the shell terminates.
8732.TP
ccc6cda3 8733\fBexport\fP [\fB\-fn\fP\^] [\fIname\fP[=\fIword\fP]] ...
7117c2d2 8734.PD 0
726f6388
JA
8735.TP
8736.B export \-p
8737.PD
8738The supplied
8739.I names
8740are marked for automatic export to the environment of
a0c0a00f 8741subsequently executed commands. If the
726f6388 8742.B \-f
a0c0a00f 8743option is given, the
726f6388
JA
8744.I names
8745refer to functions.
8746If no
8747.I names
8748are given, or if the
8749.B \-p
8750option is supplied, a list
ac50fbac 8751of names of all exported variables is printed.
726f6388
JA
8752The
8753.B \-n
b80f6443
JA
8754option causes the export property to be removed from each
8755\fIname\fP.
8756If a variable name is followed by =\fIword\fP, the value of
8757the variable is set to \fIword\fP.
726f6388 8758.B export
cce855bc 8759returns an exit status of 0 unless an invalid option is
726f6388 8760encountered,
cce855bc 8761one of the \fInames\fP is not a valid shell variable name, or
726f6388
JA
8762.B \-f
8763is supplied with a
8764.I name
8765that is not a function.
8766.TP
3185942a 8767\fBfc\fP [\fB\-e\fP \fIename\fP] [\fB\-lnr\fP] [\fIfirst\fP] [\fIlast\fP]
7117c2d2 8768.PD 0
726f6388
JA
8769.TP
8770\fBfc\fP \fB\-s\fP [\fIpat\fP=\fIrep\fP] [\fIcmd\fP]
8771.PD
ac50fbac 8772The first form selects a range of commands from
726f6388
JA
8773.I first
8774to
8775.I last
ac50fbac 8776from the history list and displays or edits and re-executes them.
726f6388
JA
8777.I First
8778and
8779.I last
8780may be specified as a string (to locate the last command beginning
8781with that string) or as a number (an index into the history list,
8782where a negative number is used as an offset from the current
8868edaf
CR
8783command number).
8784When listing, a \fIfirst\fP or \fIlast\fP of
87850 is equivalent to \-1 and \-0 is equivalent to the current
8786command (usually the \fBfc\fP command); otherwise 0 is equivalent to \-1
8787and \-0 is invalid.
8788If
726f6388 8789.I last
d233b485 8790is not specified, it is set to
726f6388 8791the current command for listing (so that
bb70624e
JA
8792.if n ``fc \-l \-10''
8793.if t \f(CWfc \-l \-10\fP
726f6388
JA
8794prints the last 10 commands) and to
8795.I first
8796otherwise.
8797If
8798.I first
d233b485 8799is not specified, it is set to the previous
726f6388
JA
8800command for editing and \-16 for listing.
8801.sp 1
8802The
8803.B \-n
cce855bc 8804option suppresses
726f6388
JA
8805the command numbers when listing. The
8806.B \-r
cce855bc 8807option reverses the order of
726f6388
JA
8808the commands. If the
8809.B \-l
cce855bc 8810option is given,
726f6388
JA
8811the commands are listed on
8812standard output. Otherwise, the editor given by
8813.I ename
8814is invoked
8815on a file containing those commands. If
8816.I ename
8817is not given, the
8818value of the
8819.SM
8820.B FCEDIT
8821variable is used, and
8822the value of
8823.SM
8824.B EDITOR
8825if
8826.SM
8827.B FCEDIT
8828is not set. If neither variable is set,
8829.FN vi
8830is used. When editing is complete, the edited commands are
8831echoed and executed.
8832.sp 1
8833In the second form, \fIcommand\fP is re-executed after each instance
8834of \fIpat\fP is replaced by \fIrep\fP.
d233b485 8835\fICommand\fP is interpreted the same as \fIfirst\fP above.
ccc6cda3 8836A useful alias to use with this is
b80f6443 8837.if n ``r="fc -s"'',
ccc6cda3
JA
8838.if t \f(CWr='fc \-s'\fP,
8839so that typing
8840.if n ``r cc''
8841.if t \f(CWr cc\fP
8842runs the last command beginning with
8843.if n ``cc''
8844.if t \f(CWcc\fP
8845and typing
8846.if n ``r''
8847.if t \f(CWr\fP
726f6388
JA
8848re-executes the last command.
8849.sp 1
cce855bc 8850If the first form is used, the return value is 0 unless an invalid
726f6388
JA
8851option is encountered or
8852.I first
8853or
8854.I last
8855specify history lines out of range.
8856If the
8857.B \-e
8858option is supplied, the return value is the value of the last
8859command executed or failure if an error occurs with the temporary
8860file of commands. If the second form is used, the return status
8861is that of the command re-executed, unless
8862.I cmd
8863does not specify a valid history line, in which case
8864.B fc
8865returns failure.
8866.TP
8867\fBfg\fP [\fIjobspec\fP]
cce855bc 8868Resume
726f6388 8869.I jobspec
cce855bc
JA
8870in the foreground, and make it the current job.
8871If
726f6388
JA
8872.I jobspec
8873is not present, the shell's notion of the \fIcurrent job\fP is used.
8874The return value is that of the command placed into the foreground,
8875or failure if run when job control is disabled or, when run with
8876job control enabled, if
8877.I jobspec
8878does not specify a valid job or
8879.I jobspec
8880specifies a job that was started without job control.
8881.TP
8868edaf 8882\fBgetopts\fP \fIoptstring\fP \fIname\fP [\fIarg ...\fP]
726f6388
JA
8883.B getopts
8884is used by shell procedures to parse positional parameters.
8885.I optstring
bb70624e 8886contains the option characters to be recognized; if a character
726f6388
JA
8887is followed by a colon, the option is expected to have an
8888argument, which should be separated from it by white space.
bb70624e
JA
8889The colon and question mark characters may not be used as
8890option characters.
726f6388
JA
8891Each time it is invoked,
8892.B getopts
8893places the next option in the shell variable
8894.IR name ,
8895initializing
8896.I name
8897if it does not exist,
8898and the index of the next argument to be processed into the
8899variable
8900.SM
8901.BR OPTIND .
8902.SM
8903.B OPTIND
8904is initialized to 1 each time the shell or a shell script
8905is invoked. When an option requires an argument,
8906.B getopts
8907places that argument into the variable
8908.SM
8909.BR OPTARG .
8910The shell does not reset
8911.SM
8912.B OPTIND
8913automatically; it must be manually reset between multiple
8914calls to
8915.B getopts
8916within the same shell invocation if a new set of parameters
8917is to be used.
8918.sp 1
cce855bc
JA
8919When the end of options is encountered, \fBgetopts\fP exits with a
8920return value greater than zero.
0001803f
CR
8921.SM
8922.B OPTIND
8923is set to the index of the first non-option argument,
495aee44 8924and \fIname\fP is set to ?.
cce855bc
JA
8925.sp 1
8926.B getopts
8927normally parses the positional parameters, but if more arguments are
8868edaf
CR
8928supplied as
8929.I arg
8930values,
cce855bc
JA
8931.B getopts
8932parses those instead.
8933.sp 1
726f6388
JA
8934.B getopts
8935can report errors in two ways. If the first character of
8936.I optstring
8937is a colon,
8938.I silent
ac50fbac 8939error reporting is used. In normal operation, diagnostic messages
cce855bc 8940are printed when invalid options or missing option arguments are
726f6388
JA
8941encountered.
8942If the variable
8943.SM
8944.B OPTERR
cce855bc 8945is set to 0, no error messages will be displayed, even if the first
a0c0a00f 8946character of
726f6388
JA
8947.I optstring
8948is not a colon.
8949.sp 1
cce855bc 8950If an invalid option is seen,
726f6388
JA
8951.B getopts
8952places ? into
8953.I name
8954and, if not silent,
8955prints an error message and unsets
8956.SM
8957.BR OPTARG .
8958If
8959.B getopts
8960is silent,
8961the option character found is placed in
8962.SM
8963.B OPTARG
8964and no diagnostic message is printed.
8965.sp 1
8966If a required argument is not found, and
8967.B getopts
8968is not silent,
8969a question mark (\^\fB?\fP\^) is placed in
8970.IR name ,
f73dda09 8971.SM
726f6388
JA
8972.B OPTARG
8973is unset, and a diagnostic message is printed.
8974If
8975.B getopts
8976is silent, then a colon (\^\fB:\fP\^) is placed in
8977.I name
8978and
8979.SM
8980.B OPTARG
8981is set to the option character found.
8982.sp 1
8983.B getopts
726f6388
JA
8984returns true if an option, specified or unspecified, is found.
8985It returns false if the end of options is encountered or an
8986error occurs.
8987.TP
7117c2d2 8988\fBhash\fP [\fB\-lr\fP] [\fB\-p\fP \fIfilename\fP] [\fB\-dt\fP] [\fIname\fP]
495aee44 8989Each time \fBhash\fP is invoked,
a0c0a00f 8990the full pathname of the command
495aee44
CR
8991.I name
8992is determined by searching
ccc6cda3
JA
8993the directories in
8994.B $PATH
495aee44 8995and remembered. Any previously-remembered pathname is discarded.
ccc6cda3
JA
8996If the
8997.B \-p
8998option is supplied, no path search is performed, and
8999.I filename
ac50fbac 9000is used as the full filename of the command.
ccc6cda3 9001The
726f6388
JA
9002.B \-r
9003option causes the shell to forget all
f73dda09 9004remembered locations.
7117c2d2
JA
9005The
9006.B \-d
9007option causes the shell to forget the remembered location of each \fIname\fP.
f73dda09
JA
9008If the
9009.B \-t
9010option is supplied, the full pathname to which each \fIname\fP corresponds
9011is printed. If multiple \fIname\fP arguments are supplied with \fB\-t\fP,
9012the \fIname\fP is printed before the hashed full pathname.
7117c2d2
JA
9013The
9014.B \-l
9015option causes output to be displayed in a format that may be reused as input.
9016If no arguments are given, or if only \fB\-l\fP is supplied,
9017information about remembered commands is printed.
ccc6cda3 9018The return status is true unless a
726f6388 9019.I name
cce855bc 9020is not found or an invalid option is supplied.
726f6388 9021.TP
3185942a 9022\fBhelp\fP [\fB\-dms\fP] [\fIpattern\fP]
726f6388
JA
9023Display helpful information about builtin commands. If
9024.I pattern
9025is specified,
9026.B help
9027gives detailed help on all commands matching
9028.IR pattern ;
ccc6cda3 9029otherwise help for all the builtins and shell control structures
bb70624e 9030is printed.
3185942a
JA
9031.RS
9032.PD 0
9033.TP
9034.B \-d
9035Display a short description of each \fIpattern\fP
9036.TP
0001803f 9037.B \-m
3185942a
JA
9038Display the description of each \fIpattern\fP in a manpage-like format
9039.TP
9040.B \-s
9041Display only a short usage synopsis for each \fIpattern\fP
9042.PD
495aee44 9043.PP
bb70624e 9044The return status is 0 unless no command matches
726f6388 9045.IR pattern .
495aee44 9046.RE
726f6388 9047.TP
bb70624e 9048\fBhistory [\fIn\fP]
7117c2d2 9049.PD 0
bb70624e
JA
9050.TP
9051\fBhistory\fP \fB\-c\fP
9052.TP
9053\fBhistory \-d\fP \fIoffset\fP
ccc6cda3 9054.TP
d233b485
CR
9055\fBhistory \-d\fP \fIstart\fP\-\fIend\fP
9056.TP
ccc6cda3 9057\fBhistory\fP \fB\-anrw\fP [\fIfilename\fP]
726f6388 9058.TP
ccc6cda3
JA
9059\fBhistory\fP \fB\-p\fP \fIarg\fP [\fIarg ...\fP]
9060.TP
9061\fBhistory\fP \fB\-s\fP \fIarg\fP [\fIarg ...\fP]
726f6388
JA
9062.PD
9063With no options, display the command
9064history list with line numbers. Lines listed
a0c0a00f 9065with a
726f6388
JA
9066.B *
9067have been modified. An argument of
9068.I n
9069lists only the last
9070.I n
b80f6443 9071lines.
0001803f
CR
9072If the shell variable
9073.SM
9074.B HISTTIMEFORMAT
9075is set and not null,
b80f6443
JA
9076it is used as a format string for \fIstrftime\fP(3) to display
9077the time stamp associated with each displayed history entry.
9078No intervening blank is printed between the formatted time stamp
9079and the history line.
9080If \fIfilename\fP is supplied, it is used as the
726f6388
JA
9081name of the history file; if not, the value of
9082.SM
9083.B HISTFILE
9084is used. Options, if supplied, have the following meanings:
9085.RS
9086.PD 0
9087.TP
bb70624e
JA
9088.B \-c
9089Clear the history list by deleting all the entries.
9090.TP
9091\fB\-d\fP \fIoffset\fP
9092Delete the history entry at position \fIoffset\fP.
d233b485
CR
9093If \fIoffset\fP is negative, it is interpreted as relative to one greater
9094than the last history position, so negative indices count back from the
9095end of the history, and an index of \-1 refers to the current
9096\fBhistory -d\fP command.
9097.TP
9098\fB\-d\fP \fIstart\fP\-\fIend\fP
74091dd4
CR
9099Delete the range of history entries between positions \fIstart\fP and
9100\fIend\fP, inclusive.
9101Positive and negative values for \fIstart\fP and \fIend\fP
d233b485 9102are interpreted as described above.
bb70624e 9103.TP
726f6388 9104.B \-a
a0c0a00f
CR
9105Append the ``new'' history lines to the history file.
9106These are history lines entered since the beginning of the current
9107\fBbash\fP session, but not already appended to the history file.
726f6388
JA
9108.TP
9109.B \-n
9110Read the history lines not already read from the history
9111file into the current history list. These are lines
9112appended to the history file since the beginning of the
9113current \fBbash\fP session.
9114.TP
9115.B \-r
9116Read the contents of the history file
ac50fbac 9117and append them to the current history list.
726f6388
JA
9118.TP
9119.B \-w
ac50fbac 9120Write the current history list to the history file, overwriting the
726f6388 9121history file's contents.
ccc6cda3 9122.TP
ccc6cda3
JA
9123.B \-p
9124Perform history substitution on the following \fIargs\fP and display
9125the result on the standard output.
9126Does not store the results in the history list.
9127Each \fIarg\fP must be quoted to disable normal history expansion.
9128.TP
9129.B \-s
9130Store the
9131.I args
9132in the history list as a single entry. The last command in the
9133history list is removed before the
9134.I args
9135are added.
726f6388
JA
9136.PD
9137.PP
0001803f
CR
9138If the
9139.SM
9140.B HISTTIMEFORMAT
9141variable is set, the time stamp information
3185942a
JA
9142associated with each history entry is written to the history file,
9143marked with the history comment character.
9144When the history file is read, lines beginning with the history
9145comment character followed immediately by a digit are interpreted
a0c0a00f 9146as timestamps for the following history entry.
bb70624e
JA
9147The return value is 0 unless an invalid option is encountered, an
9148error occurs while reading or writing the history file, an invalid
74091dd4 9149\fIoffset\fP or range is supplied as an argument to \fB\-d\fP, or the
bb70624e 9150history expansion supplied as an argument to \fB\-p\fP fails.
726f6388
JA
9151.RE
9152.TP
ccc6cda3 9153\fBjobs\fP [\fB\-lnprs\fP] [ \fIjobspec\fP ... ]
7117c2d2 9154.PD 0
726f6388
JA
9155.TP
9156\fBjobs\fP \fB\-x\fP \fIcommand\fP [ \fIargs\fP ... ]
9157.PD
ccc6cda3
JA
9158The first form lists the active jobs. The options have the following
9159meanings:
9160.RS
9161.PD 0
9162.TP
726f6388 9163.B \-l
ccc6cda3
JA
9164List process IDs
9165in addition to the normal information.
9166.TP
726f6388 9167.B \-n
ccc6cda3
JA
9168Display information only about jobs that have changed status since
9169the user was last notified of their status.
9170.TP
495aee44
CR
9171.B \-p
9172List only the process ID of the job's process group
9173leader.
9174.TP
ccc6cda3 9175.B \-r
ac50fbac 9176Display only running jobs.
ccc6cda3
JA
9177.TP
9178.B \-s
ac50fbac 9179Display only stopped jobs.
ccc6cda3
JA
9180.PD
9181.PP
9182If
726f6388
JA
9183.I jobspec
9184is given, output is restricted to information about that job.
cce855bc
JA
9185The return status is 0 unless an invalid option is encountered
9186or an invalid
726f6388
JA
9187.I jobspec
9188is supplied.
ccc6cda3 9189.PP
726f6388
JA
9190If the
9191.B \-x
9192option is supplied,
9193.B jobs
9194replaces any
9195.I jobspec
9196found in
9197.I command
9198or
9199.I args
9200with the corresponding process group ID, and executes
9201.I command
9202passing it
9203.IR args ,
9204returning its exit status.
ccc6cda3 9205.RE
726f6388 9206.TP
ccc6cda3 9207\fBkill\fP [\fB\-s\fP \fIsigspec\fP | \fB\-n\fP \fIsignum\fP | \fB\-\fP\fIsigspec\fP] [\fIpid\fP | \fIjobspec\fP] ...
7117c2d2 9208.PD 0
726f6388 9209.TP
a0c0a00f 9210\fBkill\fP \fB\-l\fP|\fB\-L\fP [\fIsigspec\fP | \fIexit_status\fP]
726f6388
JA
9211.PD
9212Send the signal named by
9213.I sigspec
ccc6cda3
JA
9214or
9215.I signum
726f6388
JA
9216to the processes named by
9217.I pid
9218or
9219.IR jobspec .
9220.I sigspec
b80f6443 9221is either a case-insensitive signal name such as
726f6388
JA
9222.SM
9223.B SIGKILL
b80f6443 9224(with or without the
726f6388
JA
9225.SM
9226.B SIG
b80f6443
JA
9227prefix) or a signal number;
9228.I signum
9229is a signal number.
726f6388
JA
9230If
9231.I sigspec
9232is not present, then
9233.SM
9234.B SIGTERM
cce855bc
JA
9235is assumed.
9236An argument of
726f6388 9237.B \-l
cce855bc
JA
9238lists the signal names.
9239If any arguments are supplied when
726f6388 9240.B \-l
cce855bc
JA
9241is given, the names of the signals corresponding to the arguments are
9242listed, and the return status is 0.
9243The \fIexit_status\fP argument to
ccc6cda3 9244.B \-l
cce855bc
JA
9245is a number specifying either a signal number or the exit status of
9246a process terminated by a signal.
a0c0a00f
CR
9247The
9248.B \-L
9249option is equivalent to \fB\-l\fP.
726f6388
JA
9250.B kill
9251returns true if at least one signal was successfully sent, or false
cce855bc 9252if an error occurs or an invalid option is encountered.
726f6388
JA
9253.TP
9254\fBlet\fP \fIarg\fP [\fIarg\fP ...]
9255Each
9256.I arg
9257is an arithmetic expression to be evaluated (see
9258.SM
0001803f 9259.B "ARITHMETIC EVALUATION"
74091dd4
CR
9260.ie \n(zZ=1 in \fIbash(1)\fP).
9261.el above).
726f6388
JA
9262If the last
9263.I arg
9264evaluates to 0,
9265.B let
9266returns 1; 0 is returned otherwise.
9267.TP
a0c0a00f 9268\fBlocal\fP [\fIoption\fP] [\fIname\fP[=\fIvalue\fP] ... | \- ]
cce855bc 9269For each argument, a local variable named
a0c0a00f 9270.I name
cce855bc 9271is created, and assigned
726f6388 9272.IR value .
bb70624e 9273The \fIoption\fP can be any of the options accepted by \fBdeclare\fP.
726f6388
JA
9274When
9275.B local
9276is used within a function, it causes the variable
9277.I name
9278to have a visible scope restricted to that function and its children.
a0c0a00f
CR
9279If \fIname\fP is \-, the set of shell options is made local to the function
9280in which \fBlocal\fP is invoked: shell options changed using the
9281\fBset\fP builtin inside the function are restored to their original values
9282when the function returns.
8868edaf
CR
9283The restore is effected as if a series of \fBset\fP commands were executed
9284to restore the values that were in place before the function.
726f6388
JA
9285With no operands,
9286.B local
9287writes a list of local variables to the standard output. It is
9288an error to use
9289.B local
9290when not within a function. The return status is 0 unless
9291.B local
bb70624e 9292is used outside a function, an invalid
726f6388 9293.I name
bb70624e
JA
9294is supplied, or
9295\fIname\fP is a readonly variable.
726f6388
JA
9296.TP
9297.B logout
9298Exit a login shell.
9299.TP
a0c0a00f 9300\fBmapfile\fP [\fB\-d\fP \fIdelim\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]
17345e5a
JA
9301.PD 0
9302.TP
a0c0a00f 9303\fBreadarray\fP [\fB\-d\fP \fIdelim\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]
17345e5a 9304.PD
0001803f 9305Read lines from the standard input into the indexed array variable
3185942a 9306.IR array ,
a0c0a00f 9307or from file descriptor
d233b485 9308.I fd
a0c0a00f 9309if the
3185942a
JA
9310.B \-u
9311option is supplied.
0001803f
CR
9312The variable
9313.SM
9314.B MAPFILE
9315is the default \fIarray\fP.
3185942a
JA
9316Options, if supplied, have the following meanings:
9317.RS
9318.PD 0
9319.TP
a0c0a00f
CR
9320.B \-d
9321The first character of \fIdelim\fP is used to terminate each input line,
9322rather than newline.
d233b485
CR
9323If \fIdelim\fP is the empty string, \fBmapfile\fP will terminate a line
9324when it reads a NUL character.
a0c0a00f 9325.TP
3185942a
JA
9326.B \-n
9327Copy at most
9328.I count
9329lines. If \fIcount\fP is 0, all lines are copied.
9330.TP
9331.B \-O
9332Begin assigning to
9333.I array
9334at index
9335.IR origin .
9336The default index is 0.
9337.TP
9338.B \-s
9339Discard the first \fIcount\fP lines read.
9340.TP
9341.B \-t
a0c0a00f 9342Remove a trailing \fIdelim\fP (default newline) from each line read.
3185942a
JA
9343.TP
9344.B \-u
9345Read lines from file descriptor \fIfd\fP instead of the standard input.
9346.TP
9347.B \-C
9348Evaluate
9349.I callback
9350each time \fIquantum\fP lines are read. The \fB\-c\fP option specifies
9351.IR quantum .
9352.TP
9353.B \-c
9354Specify the number of lines read between each call to
9355.IR callback .
9356.PD
9357.PP
9358If
9359.B \-C
a0c0a00f 9360is specified without
3185942a
JA
9361.BR \-c ,
9362the default quantum is 5000.
17345e5a 9363When \fIcallback\fP is evaluated, it is supplied the index of the next
495aee44
CR
9364array element to be assigned and the line to be assigned to that element
9365as additional arguments.
a0c0a00f 9366\fIcallback\fP is evaluated after the line is read but before the
17345e5a 9367array element is assigned.
3185942a
JA
9368.PP
9369If not supplied with an explicit origin, \fBmapfile\fP will clear \fIarray\fP
9370before assigning to it.
9371.PP
9372\fBmapfile\fP returns successfully unless an invalid option or option
0001803f
CR
9373argument is supplied, \fIarray\fP is invalid or unassignable, or if
9374\fIarray\fP is not an indexed array.
3185942a
JA
9375.RE
9376.TP
ccc6cda3 9377\fBpopd\fP [\-\fBn\fP] [+\fIn\fP] [\-\fIn\fP]
74091dd4
CR
9378Removes entries from the directory stack.
9379The elements are numbered from 0 starting at the first directory
9380listed by \fBdirs\fP.
9381With no arguments, \fBpopd\fP
9382removes the top directory from the stack, and
9383changes to the new top directory.
ccc6cda3 9384Arguments, if supplied, have the following meanings:
726f6388
JA
9385.RS
9386.PD 0
9387.TP
3185942a
JA
9388.B \-n
9389Suppresses the normal change of directory when removing directories
9390from the stack, so that only the stack is manipulated.
9391.TP
ccc6cda3
JA
9392\fB+\fP\fIn\fP
9393Removes the \fIn\fPth entry counting from the left of the list
726f6388
JA
9394shown by
9395.BR dirs ,
74091dd4
CR
9396starting with zero, from the stack.
9397For example:
bb70624e
JA
9398.if n ``popd +0''
9399.if t \f(CWpopd +0\fP
9400removes the first directory,
9401.if n ``popd +1''
9402.if t \f(CWpopd +1\fP
9403the second.
726f6388 9404.TP
ccc6cda3
JA
9405\fB\-\fP\fIn\fP
9406Removes the \fIn\fPth entry counting from the right of the list
726f6388
JA
9407shown by
9408.BR dirs ,
bb70624e
JA
9409starting with zero. For example:
9410.if n ``popd -0''
9411.if t \f(CWpopd -0\fP
9412removes the last directory,
9413.if n ``popd -1''
9414.if t \f(CWpopd -1\fP
9415the next to last.
726f6388
JA
9416.PD
9417.PP
74091dd4
CR
9418If the top element of the directory stack is modified, and
9419the \fI-n\fP option was not supplied, \fBpopd\fP uses the \fBcd\fP
9420builtin to change to the directory at the top of the stack.
9421If the \fBcd\fP fails, \fBpopd\fP returns a non-zero value.
9422.PP
9423Otherwise,
9424.B popd
9425returns false if an invalid option is encountered, the directory stack
9426is empty, or a non-existent directory stack entry is specified.
9427.PP
726f6388
JA
9428If the
9429.B popd
74091dd4
CR
9430command is successful,
9431bash runs
726f6388 9432.B dirs
74091dd4
CR
9433to show the final contents of the directory stack,
9434and the return status is 0.
726f6388
JA
9435.RE
9436.TP
95732b49 9437\fBprintf\fP [\fB\-v\fP \fIvar\fP] \fIformat\fP [\fIarguments\fP]
cce855bc
JA
9438Write the formatted \fIarguments\fP to the standard output under the
9439control of the \fIformat\fP.
495aee44
CR
9440The \fB\-v\fP option causes the output to be assigned to the variable
9441\fIvar\fP rather than being printed to the standard output.
9442.sp 1
cce855bc
JA
9443The \fIformat\fP is a character string which contains three types of objects:
9444plain characters, which are simply copied to standard output, character
9445escape sequences, which are converted and copied to the standard output, and
9446format specifications, each of which causes printing of the next successive
9447\fIargument\fP.
495aee44
CR
9448In addition to the standard \fIprintf\fP(1) format specifications,
9449\fBprintf\fP interprets the following extensions:
9450.RS
9451.PD 0
9452.TP
9453.B %b
9454causes
cce855bc 9455\fBprintf\fP to expand backslash escape sequences in the corresponding
a0c0a00f
CR
9456\fIargument\fP
9457in the same way as \fBecho \-e\fP.
495aee44
CR
9458.TP
9459.B %q
9460causes \fBprintf\fP to output the corresponding
cce855bc 9461\fIargument\fP in a format that can be reused as shell input.
495aee44 9462.TP
74091dd4
CR
9463.B %Q
9464like \fB%q\fP, but applies any supplied precision to the \fIargument\fP
9465before quoting it.
9466.TP
495aee44
CR
9467.B %(\fIdatefmt\fP)T
9468causes \fBprintf\fP to output the date-time string resulting from using
ac50fbac
CR
9469\fIdatefmt\fP as a format string for \fIstrftime\fP(3).
9470The corresponding \fIargument\fP is an integer representing the number of
9471seconds since the epoch.
d233b485
CR
9472Two special argument values may be used: \-1 represents the current
9473time, and \-2 represents the time the shell was invoked.
9474If no argument is specified, conversion behaves as if \-1 had been given.
ac50fbac 9475This is an exception to the usual \fBprintf\fP behavior.
495aee44
CR
9476.PD
9477.PP
8868edaf
CR
9478The %b, %q, and %T directives all use the field width and precision
9479arguments from the format specification and write that many bytes from
9480(or use that wide a field for) the expanded argument, which usually
9481contains more characters than the original.
9482.PP
495aee44
CR
9483Arguments to non-string format specifiers are treated as C constants,
9484except that a leading plus or minus sign is allowed, and if the leading
9485character is a single or double quote, the value is the ASCII value of
9486the following character.
9487.PP
cce855bc
JA
9488The \fIformat\fP is reused as necessary to consume all of the \fIarguments\fP.
9489If the \fIformat\fP requires more \fIarguments\fP than are supplied, the
9490extra format specifications behave as if a zero value or null string, as
495aee44
CR
9491appropriate, had been supplied.
9492The return value is zero on success, non-zero on failure.
9493.RE
cce855bc 9494.TP
3185942a 9495\fBpushd\fP [\fB\-n\fP] [+\fIn\fP] [\-\fIn\fP]
7117c2d2 9496.PD 0
726f6388 9497.TP
3185942a 9498\fBpushd\fP [\fB\-n\fP] [\fIdir\fP]
726f6388
JA
9499.PD
9500Adds a directory to the top of the directory stack, or rotates
9501the stack, making the new top of the stack the current working
74091dd4
CR
9502directory.
9503With no arguments, \fBpushd\fP exchanges the top two elements of
9504the directory stack.
ccc6cda3 9505Arguments, if supplied, have the following meanings:
726f6388
JA
9506.RS
9507.PD 0
9508.TP
3185942a 9509.B \-n
a0c0a00f
CR
9510Suppresses the normal change of directory when rotating or
9511adding directories to the stack, so that only the stack is manipulated.
3185942a 9512.TP
ccc6cda3 9513\fB+\fP\fIn\fP
726f6388
JA
9514Rotates the stack so that the \fIn\fPth directory
9515(counting from the left of the list shown by
d166f048
JA
9516.BR dirs ,
9517starting with zero)
726f6388
JA
9518is at the top.
9519.TP
ccc6cda3 9520\fB\-\fP\fIn\fP
726f6388 9521Rotates the stack so that the \fIn\fPth directory
d166f048
JA
9522(counting from the right of the list shown by
9523.BR dirs ,
9524starting with zero) is at the top.
726f6388 9525.TP
bb70624e 9526.I dir
ccc6cda3 9527Adds
726f6388 9528.I dir
74091dd4 9529to the directory stack at the top
726f6388
JA
9530.PD
9531.PP
74091dd4
CR
9532After the stack has been modified, if the \fB\-n\fP option was not
9533supplied, \fBpushd\fP uses the \fBcd\fP builtin to change to the
9534directory at the top of the stack.
9535If the \fBcd\fP fails, \fBpushd\fP returns a non-zero value.
9536.PP
9537Otherwise, if no arguments are supplied,
726f6388 9538.B pushd
74091dd4
CR
9539returns 0 unless the directory stack is empty.
9540When rotating the directory stack,
726f6388 9541.B pushd
74091dd4
CR
9542returns 0 unless the directory stack is empty or
9543a non-existent directory stack element is specified.
9544.PP
9545If the
726f6388 9546.B pushd
74091dd4
CR
9547command is successful,
9548bash runs
9549.B dirs
9550to show the final contents of the directory stack.
726f6388
JA
9551.RE
9552.TP
ccc6cda3 9553\fBpwd\fP [\fB\-LP\fP]
bb70624e
JA
9554Print the absolute pathname of the current working directory.
9555The pathname printed contains no symbolic links if the
726f6388 9556.B \-P
a0c0a00f 9557option is supplied or the
ccc6cda3 9558.B \-o physical
726f6388
JA
9559option to the
9560.B set
ccc6cda3
JA
9561builtin command is enabled.
9562If the
9563.B \-L
bb70624e 9564option is used, the pathname printed may contain symbolic links.
ccc6cda3 9565The return status is 0 unless an error occurs while
cce855bc
JA
9566reading the name of the current directory or an
9567invalid option is supplied.
726f6388 9568.TP
0001803f 9569\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 ...]
7117c2d2 9570One line is read from the standard input, or from the file descriptor
a0c0a00f 9571\fIfd\fP supplied as an argument to the \fB\-u\fP option,
74091dd4
CR
9572split into words as described
9573.ie \n(zZ=1 in \fIbash(1)\fP
9574.el above
9575under \fBWord Splitting\fP,
a0c0a00f 9576and the first word
726f6388
JA
9577is assigned to the first
9578.IR name ,
9579the second word to the second
9580.IR name ,
a0c0a00f
CR
9581and so on.
9582If there are more words than names, the remaining words and their
9583intervening delimiters are assigned to the last
726f6388 9584.IR name .
7117c2d2 9585If there are fewer words read from the input stream than names,
cce855bc 9586the remaining names are assigned empty values.
a0c0a00f 9587The characters in
726f6388
JA
9588.SM
9589.B IFS
ac50fbac 9590are used to split the line into words using the same rules the shell
74091dd4
CR
9591uses for expansion (described
9592.ie \n(zZ=1 in \fIbash(1)\fP
9593.el above
9594under \fBWord Splitting\fP).
b72432fd
JA
9595The backslash character (\fB\e\fP) may be used to remove any special
9596meaning for the next character read and for line continuation.
cce855bc 9597Options, if supplied, have the following meanings:
ccc6cda3
JA
9598.RS
9599.PD 0
9600.TP
bb70624e 9601.B \-a \fIaname\fP
ccc6cda3
JA
9602The words are assigned to sequential indices
9603of the array variable
9604.IR aname ,
9605starting at 0.
9606.I aname
9607is unset before any new values are assigned.
cce855bc 9608Other \fIname\fP arguments are ignored.
ccc6cda3 9609.TP
bb70624e
JA
9610.B \-d \fIdelim\fP
9611The first character of \fIdelim\fP is used to terminate the input line,
9612rather than newline.
d233b485
CR
9613If \fIdelim\fP is the empty string, \fBread\fP will terminate a line
9614when it reads a NUL character.
bb70624e 9615.TP
ccc6cda3
JA
9616.B \-e
9617If the standard input
9618is coming from a terminal,
9619.B readline
9620(see
9621.SM
9622.B READLINE
74091dd4
CR
9623.ie \n(zZ=1 in \fIbash(1)\fP)
9624.el above)
9625is used to obtain the line.
3185942a 9626Readline uses the current (or default, if line editing was not previously
74091dd4 9627active) editing settings, but uses readline's default filename completion.
3185942a
JA
9628.TP
9629.B \-i \fItext\fP
9630If
9631.B readline
9632is being used to read the line, \fItext\fP is placed into the editing
9633buffer before editing begins.
bb70624e
JA
9634.TP
9635.B \-n \fInchars\fP
9636\fBread\fP returns after reading \fInchars\fP characters rather than
a0c0a00f 9637waiting for a complete line of input, but honors a delimiter if fewer
0001803f
CR
9638than \fInchars\fP characters are read before the delimiter.
9639.TP
9640.B \-N \fInchars\fP
9641\fBread\fP returns after reading exactly \fInchars\fP characters rather
9642than waiting for a complete line of input, unless EOF is encountered or
9643\fBread\fP times out.
9644Delimiter characters encountered in the input are
9645not treated specially and do not cause \fBread\fP to return until
9646\fInchars\fP characters are read.
a0c0a00f
CR
9647The result is not split on the characters in \fBIFS\fP; the intent is
9648that the variable is assigned exactly the characters read
9649(with the exception of backslash; see the \fB\-r\fP option below).
bb70624e
JA
9650.TP
9651.B \-p \fIprompt\fP
f73dda09 9652Display \fIprompt\fP on standard error, without a
bb70624e
JA
9653trailing newline, before attempting to read any input. The prompt
9654is displayed only if input is coming from a terminal.
9655.TP
9656.B \-r
9657Backslash does not act as an escape character.
9658The backslash is considered to be part of the line.
d233b485 9659In particular, a backslash-newline pair may not then be used as a line
bb70624e
JA
9660continuation.
9661.TP
9662.B \-s
9663Silent mode. If input is coming from a terminal, characters are
9664not echoed.
9665.TP
9666.B \-t \fItimeout\fP
9667Cause \fBread\fP to time out and return failure if a complete line of
ac50fbac
CR
9668input (or a specified number of characters)
9669is not read within \fItimeout\fP seconds.
3185942a
JA
9670\fItimeout\fP may be a decimal number with a fractional portion following
9671the decimal point.
9672This option is only effective if \fBread\fP is reading input from a
9673terminal, pipe, or other special file; it has no effect when reading
9674from regular files.
ac50fbac
CR
9675If \fBread\fP times out, \fBread\fP saves any partial input read into
9676the specified variable \fIname\fP.
9677If \fItimeout\fP is 0, \fBread\fP returns immediately, without trying to
74091dd4
CR
9678read any data.
9679The exit status is 0 if input is available on the specified file descriptor,
9680or the read will return EOF,
9681non-zero otherwise.
3185942a 9682The exit status is greater than 128 if the timeout is exceeded.
7117c2d2 9683.TP
95732b49 9684.B \-u \fIfd\fP
7117c2d2 9685Read input from file descriptor \fIfd\fP.
ccc6cda3
JA
9686.PD
9687.PP
9688If no
726f6388 9689.I names
8868edaf
CR
9690are supplied, the line read,
9691without the ending delimiter but otherwise unmodified,
9692is assigned to the variable
726f6388
JA
9693.SM
9694.BR REPLY .
a0c0a00f
CR
9695The exit status is zero, unless end-of-file is encountered, \fBread\fP
9696times out (in which case the status is greater than 128),
ac50fbac
CR
9697a variable assignment error (such as assigning to a readonly variable) occurs,
9698or an invalid file descriptor is supplied as the argument to \fB\-u\fP.
ccc6cda3 9699.RE
726f6388 9700.TP
495aee44 9701\fBreadonly\fP [\fB\-aAf\fP] [\fB\-p\fP] [\fIname\fP[=\fIword\fP] ...]
726f6388
JA
9702.PD
9703The given
ccc6cda3
JA
9704\fInames\fP are marked readonly; the values of these
9705.I names
726f6388
JA
9706may not be changed by subsequent assignment.
9707If the
9708.B \-f
9709option is supplied, the functions corresponding to the
9710\fInames\fP are so
ccc6cda3
JA
9711marked.
9712The
9713.B \-a
3185942a
JA
9714option restricts the variables to indexed arrays; the
9715.B \-A
9716option restricts the variables to associative arrays.
495aee44
CR
9717If both options are supplied,
9718.B \-A
9719takes precedence.
ccc6cda3
JA
9720If no
9721.I name
9722arguments are given, or if the
726f6388 9723.B \-p
ccc6cda3 9724option is supplied, a list of all readonly names is printed.
495aee44
CR
9725The other options may be used to restrict the output to a subset of
9726the set of readonly names.
cce855bc
JA
9727The
9728.B \-p
bb70624e
JA
9729option causes output to be displayed in a format that
9730may be reused as input.
b80f6443
JA
9731If a variable name is followed by =\fIword\fP, the value of
9732the variable is set to \fIword\fP.
cce855bc 9733The return status is 0 unless an invalid option is encountered,
ccc6cda3
JA
9734one of the
9735.I names
cce855bc 9736is not a valid shell variable name, or
726f6388
JA
9737.B \-f
9738is supplied with a
9739.I name
9740that is not a function.
9741.TP
9742\fBreturn\fP [\fIn\fP]
ac50fbac
CR
9743Causes a function to stop executing and return the value specified by
9744.I n
9745to its caller.
a0c0a00f 9746If
726f6388
JA
9747.I n
9748is omitted, the return status is that of the last command
a0c0a00f
CR
9749executed in the function body.
9750If \fBreturn\fP is executed by a trap handler, the last command used to
9751determine the status is the last command executed before the trap handler.
d233b485 9752If \fBreturn\fP is executed during a \fBDEBUG\fP trap, the last command
a0c0a00f
CR
9753used to determine the status is the last command executed by the trap
9754handler before \fBreturn\fP was invoked.
9755If
ac50fbac
CR
9756.B return
9757is used outside a function,
a0c0a00f 9758but during execution of a script by the
726f6388
JA
9759.B .
9760(\fBsource\fP) command, it causes the shell to stop executing
9761that script and return either
9762.I n
9763or the exit status of the last command executed within the
ac50fbac
CR
9764script as the exit status of the script.
9765If \fIn\fP is supplied, the return value is its least significant
97668 bits.
9767The return status is non-zero if
9768.B return
9769is supplied a non-numeric argument, or
9770is used outside a
9771function and not during execution of a script by \fB.\fP\^ or \fBsource\fP.
b80f6443
JA
9772Any command associated with the \fBRETURN\fP trap is executed
9773before execution resumes after the function or script.
726f6388 9774.TP
74091dd4 9775\fBset\fP [\fB\-abefhkmnptuvxBCEHPT\fP] [\fB\-o\fP \fIoption\-name\fP] [\fB\-\-\fP] [\fB\-\fP] [\fIarg\fP ...]
3185942a
JA
9776.PD 0
9777.TP
74091dd4 9778\fBset\fP [\fB+abefhkmnptuvxBCEHPT\fP] [\fB+o\fP \fIoption\-name\fP] [\fB\-\-\fP] [\fB\-\fP] [\fIarg\fP ...]
3185942a 9779.PD
74091dd4 9780Without options, display the name and value of each shell variable
95732b49
JA
9781in a format that can be reused as input
9782for setting or resetting the currently-set variables.
9783Read-only variables cannot be reset.
d233b485 9784In \fIposix mode\fP, only shell variables are listed.
cce855bc 9785The output is sorted according to the current locale.
ccc6cda3 9786When options are specified, they set or unset shell attributes.
3185942a 9787Any arguments remaining after option processing are treated
a0c0a00f 9788as values for the positional parameters and are assigned, in order, to
ccc6cda3
JA
9789.BR $1 ,
9790.BR $2 ,
9791.B ...
9792.BR $\fIn\fP .
9793Options, if specified, have the following meanings:
726f6388
JA
9794.RS
9795.PD 0
9796.TP 8
9797.B \-a
a0c0a00f
CR
9798Each variable or function that is created or modified is given the
9799export attribute and marked for export to the environment of
9800subsequent commands.
726f6388
JA
9801.TP 8
9802.B \-b
ccc6cda3
JA
9803Report the status of terminated background jobs
9804immediately, rather than before the next primary prompt. This is
9805effective only when job control is enabled.
726f6388
JA
9806.TP 8
9807.B \-e
ac50fbac
CR
9808Exit immediately if a
9809\fIpipeline\fP (which may consist of a single \fIsimple command\fP),
9810a \fIlist\fP,
9811or a \fIcompound command\fP
9812(see
726f6388
JA
9813.SM
9814.B SHELL GRAMMAR
74091dd4
CR
9815.ie \n(zZ=1 in \fIbash(1)\fP),
9816.el above),
9817exits with a non-zero status.
b80f6443
JA
9818The shell does not exit if the
9819command that fails is part of the command list immediately following a
9820.B while
726f6388 9821or
b80f6443 9822.B until
a0c0a00f 9823keyword,
17345e5a 9824part of the test following the
3185942a 9825.B if
17345e5a
JA
9826or
9827.B elif
9828reserved words, part of any command executed in a
726f6388
JA
9829.B &&
9830or
495aee44
CR
9831.B ||
9832list except the command following the final \fB&&\fP or \fB||\fP,
3185942a
JA
9833any command in a pipeline but the last,
9834or if the command's return value is
17345e5a 9835being inverted with
726f6388 9836.BR ! .
ac50fbac
CR
9837If a compound command other than a subshell
9838returns a non-zero status because a command failed
9839while \fB\-e\fP was being ignored, the shell does not exit.
f73dda09 9840A trap on \fBERR\fP, if set, is executed before the shell exits.
17345e5a
JA
9841This option applies to the shell environment and each subshell environment
9842separately (see
0001803f 9843.SM
17345e5a 9844.B "COMMAND EXECUTION ENVIRONMENT"
74091dd4
CR
9845.ie \n(zZ=1 in \fIbash(1)\fP),
9846.el above),
9847and may cause
17345e5a 9848subshells to exit before executing all the commands in the subshell.
ac50fbac
CR
9849.if t .sp 0.5
9850.if n .sp 1
9851If a compound command or shell function executes in a context
9852where \fB\-e\fP is being ignored,
9853none of the commands executed within the compound command or function body
9854will be affected by the \fB\-e\fP setting, even if \fB\-e\fP is set
9855and a command returns a failure status.
9856If a compound command or shell function sets \fB\-e\fP while executing in
9857a context where \fB\-e\fP is ignored, that setting will not have any
9858effect until the compound command or the command containing the function
9859call completes.
726f6388
JA
9860.TP 8
9861.B \-f
9862Disable pathname expansion.
a0c0a00f 9863.TP 8
726f6388 9864.B \-h
ccc6cda3 9865Remember the location of commands as they are looked up for execution.
cce855bc 9866This is enabled by default.
726f6388
JA
9867.TP 8
9868.B \-k
ccc6cda3
JA
9869All arguments in the form of assignment statements
9870are placed in the environment for a command, not just
9871those that precede the command name.
726f6388
JA
9872.TP 8
9873.B \-m
cce855bc 9874Monitor mode. Job control is enabled. This option is on
726f6388
JA
9875by default for interactive shells on systems that support
9876it (see
9877.SM
9878.B JOB CONTROL
74091dd4
CR
9879.ie \n(zZ=1 in \fIbash(1)\fP).
9880.el above).
ac50fbac
CR
9881All processes run in a separate process group.
9882When a background job completes, the shell prints a line
9883containing its exit status.
726f6388
JA
9884.TP 8
9885.B \-n
a0c0a00f
CR
9886Read commands but do not execute them.
9887This may be used to check a shell script for syntax errors.
9888This is ignored by interactive shells.
726f6388 9889.TP 8
ccc6cda3
JA
9890.B \-o \fIoption\-name\fP
9891The \fIoption\-name\fP can be one of the following:
726f6388
JA
9892.RS
9893.TP 8
9894.B allexport
9895Same as
9896.BR \-a .
9897.TP 8
9898.B braceexpand
ccc6cda3
JA
9899Same as
9900.BR \-B .
726f6388
JA
9901.TP 8
9902.B emacs
9903Use an emacs-style command line editing interface. This is enabled
9904by default when the shell is interactive, unless the shell is started
9905with the
ccc6cda3 9906.B \-\-noediting
726f6388 9907option.
3185942a 9908This also affects the editing interface used for \fBread \-e\fP.
726f6388 9909.TP 8
0001803f
CR
9910.B errexit
9911Same as
9912.BR \-e .
9913.TP 8
b80f6443
JA
9914.B errtrace
9915Same as
9916.BR \-E .
9917.TP 8
9918.B functrace
9919Same as
9920.BR \-T .
9921.TP 8
ccc6cda3
JA
9922.B hashall
9923Same as
9924.BR \-h .
9925.TP 8
726f6388
JA
9926.B histexpand
9927Same as
9928.BR \-H .
9929.TP 8
ccc6cda3 9930.B history
74091dd4
CR
9931Enable command history, as described
9932.ie \n(zZ=1 in \fIbash(1)\fP
9933.el above
9934under
ccc6cda3
JA
9935.SM
9936.BR HISTORY .
9937This option is on by default in interactive shells.
9938.TP 8
726f6388 9939.B ignoreeof
28ef6c31
JA
9940The effect is as if the shell command
9941.if t \f(CWIGNOREEOF=10\fP
9942.if n ``IGNOREEOF=10''
9943had been executed
726f6388
JA
9944(see
9945.B Shell Variables
74091dd4
CR
9946.ie \n(zZ=1 in \fIbash(1)\fP).
9947.el above).
726f6388 9948.TP 8
ccc6cda3
JA
9949.B keyword
9950Same as
9951.BR \-k .
726f6388
JA
9952.TP 8
9953.B monitor
9954Same as
9955.BR \-m .
9956.TP 8
9957.B noclobber
9958Same as
9959.BR \-C .
9960.TP 8
9961.B noexec
9962Same as
9963.BR \-n .
9964.TP 8
9965.B noglob
9966Same as
9967.BR \-f .
3185942a 9968.TP 8
f73dda09
JA
9969.B nolog
9970Currently ignored.
726f6388 9971.TP 8
726f6388
JA
9972.B notify
9973Same as
9974.BR \-b .
9975.TP 8
9976.B nounset
9977Same as
9978.BR \-u .
9979.TP 8
ccc6cda3
JA
9980.B onecmd
9981Same as
9982.BR \-t .
9983.TP 8
726f6388
JA
9984.B physical
9985Same as
9986.BR \-P .
9987.TP 8
b80f6443
JA
9988.B pipefail
9989If set, the return value of a pipeline is the value of the last
9990(rightmost) command to exit with a non-zero status, or zero if all
9991commands in the pipeline exit successfully.
9992This option is disabled by default.
9993.TP 8
726f6388 9994.B posix
ccc6cda3
JA
9995Change the behavior of
9996.B bash
9997where the default operation differs
0628567a 9998from the POSIX standard to match the standard (\fIposix mode\fP).
ac50fbac
CR
9999See
10000.SM
10001.B "SEE ALSO"
74091dd4
CR
10002.ie \n(zZ=1 in \fIbash(1)\fP
10003.el below
10004for a reference to a document that details how posix mode affects
ac50fbac 10005bash's behavior.
726f6388
JA
10006.TP 8
10007.B privileged
10008Same as
10009.BR \-p .
10010.TP 8
10011.B verbose
10012Same as
10013.BR \-v .
10014.TP 8
10015.B vi
10016Use a vi-style command line editing interface.
3185942a 10017This also affects the editing interface used for \fBread \-e\fP.
726f6388
JA
10018.TP 8
10019.B xtrace
10020Same as
10021.BR \-x .
ccc6cda3 10022.sp .5
726f6388 10023.PP
ccc6cda3
JA
10024If
10025.B \-o
10026is supplied with no \fIoption\-name\fP, the values of the current options are
726f6388 10027printed.
ccc6cda3
JA
10028If
10029.B +o
10030is supplied with no \fIoption\-name\fP, a series of
10031.B set
10032commands to recreate the current option settings is displayed on
10033the standard output.
726f6388
JA
10034.RE
10035.TP 8
10036.B \-p
10037Turn on
10038.I privileged
10039mode. In this mode, the
bb70624e 10040.SM
726f6388 10041.B $ENV
b72432fd 10042and
bb70624e 10043.SM
b72432fd
JA
10044.B $BASH_ENV
10045files are not processed, shell functions are not inherited from the
bb70624e
JA
10046environment, and the
10047.SM
3185942a 10048.BR SHELLOPTS ,
0001803f
CR
10049.SM
10050.BR BASHOPTS ,
10051.SM
3185942a
JA
10052.BR CDPATH ,
10053and
0001803f 10054.SM
3185942a
JA
10055.B GLOBIGNORE
10056variables, if they appear in the environment, are ignored.
b72432fd
JA
10057If the shell is started with the effective user (group) id not equal to the
10058real user (group) id, and the \fB\-p\fP option is not supplied, these actions
10059are taken and the effective user id is set to the real user id.
10060If the \fB\-p\fP option is supplied at startup, the effective user id is
10061not reset.
cce855bc 10062Turning this option off causes the effective user
726f6388
JA
10063and group ids to be set to the real user and group ids.
10064.TP 8
74091dd4
CR
10065.B \-r
10066Enable restricted shell mode.
10067This option cannot be unset once it has been set.
10068.TP 8
726f6388
JA
10069.B \-t
10070Exit after reading and executing one command.
10071.TP 8
10072.B \-u
89a92869 10073Treat unset variables and parameters other than the special
74091dd4
CR
10074parameters "@" and "*",
10075or array variables subscripted with "@" or "*",
10076as an error when performing
726f6388 10077parameter expansion. If expansion is attempted on an
89a92869 10078unset variable or parameter, the shell prints an error message, and,
ccc6cda3 10079if not interactive, exits with a non-zero status.
726f6388
JA
10080.TP 8
10081.B \-v
10082Print shell input lines as they are read.
10083.TP 8
10084.B \-x
ccc6cda3 10085After expanding each \fIsimple command\fP,
b80f6443
JA
10086\fBfor\fP command, \fBcase\fP command, \fBselect\fP command, or
10087arithmetic \fBfor\fP command, display the expanded value of
726f6388
JA
10088.SM
10089.BR PS4 ,
b80f6443
JA
10090followed by the command and its expanded arguments
10091or associated word list.
726f6388 10092.TP 8
ccc6cda3
JA
10093.B \-B
10094The shell performs brace expansion (see
10095.B Brace Expansion
74091dd4
CR
10096.ie \n(zZ=1 in \fIbash(1)\fP).
10097.el above).
10098This is on by default.
726f6388
JA
10099.TP 8
10100.B \-C
ccc6cda3
JA
10101If set,
10102.B bash
10103does not overwrite an existing file with the
10104.BR > ,
10105.BR >& ,
10106and
10107.B <>
a0c0a00f 10108redirection operators. This may be overridden when
ccc6cda3
JA
10109creating output files by using the redirection operator
10110.B >|
10111instead of
10112.BR > .
726f6388 10113.TP 8
b80f6443
JA
10114.B \-E
10115If set, any trap on \fBERR\fP is inherited by shell functions, command
10116substitutions, and commands executed in a subshell environment.
10117The \fBERR\fP trap is normally not inherited in such cases.
10118.TP 8
726f6388
JA
10119.B \-H
10120Enable
10121.B !
cce855bc 10122style history substitution. This option is on by
726f6388
JA
10123default when the shell is interactive.
10124.TP 8
10125.B \-P
ac50fbac 10126If set, the shell does not resolve symbolic links when executing
ccc6cda3 10127commands such as
726f6388 10128.B cd
ccc6cda3
JA
10129that change the current working directory. It uses the
10130physical directory structure instead. By default,
10131.B bash
10132follows the logical chain of directories when performing commands
10133which change the current directory.
726f6388 10134.TP 8
b80f6443 10135.B \-T
95732b49
JA
10136If set, any traps on \fBDEBUG\fP and \fBRETURN\fP are inherited by shell
10137functions, command substitutions, and commands executed in a
10138subshell environment.
10139The \fBDEBUG\fP and \fBRETURN\fP traps are normally not inherited
10140in such cases.
b80f6443 10141.TP 8
726f6388 10142.B \-\-
cce855bc 10143If no arguments follow this option, then the positional parameters are
726f6388
JA
10144unset. Otherwise, the positional parameters are set to the
10145\fIarg\fPs, even if some of them begin with a
10146.BR \- .
10147.TP 8
10148.B \-
10149Signal the end of options, cause all remaining \fIarg\fPs to be
10150assigned to the positional parameters. The
10151.B \-x
10152and
10153.B \-v
10154options are turned off.
10155If there are no \fIarg\fPs,
10156the positional parameters remain unchanged.
10157.PD
10158.PP
cce855bc
JA
10159The options are off by default unless otherwise noted.
10160Using + rather than \- causes these options to be turned off.
10161The options can also be specified as arguments to an invocation of
10162the shell.
10163The current set of options may be found in
726f6388 10164.BR $\- .
cce855bc 10165The return status is always true unless an invalid option is encountered.
726f6388
JA
10166.RE
10167.TP
10168\fBshift\fP [\fIn\fP]
10169The positional parameters from \fIn\fP+1 ... are renamed to
10170.B $1
10171.B ....
10172Parameters represented by the numbers \fB$#\fP
10173down to \fB$#\fP\-\fIn\fP+1 are unset.
ccc6cda3
JA
10174.I n
10175must be a non-negative number less than or equal to \fB$#\fP.
726f6388
JA
10176If
10177.I n
10178is 0, no parameters are changed.
10179If
a0c0a00f 10180.I n
726f6388 10181is not given, it is assumed to be 1.
726f6388
JA
10182If
10183.I n
10184is greater than \fB$#\fP, the positional parameters are not changed.
ccc6cda3 10185The return status is greater than zero if
726f6388
JA
10186.I n
10187is greater than
10188.B $#
ccc6cda3
JA
10189or less than zero; otherwise 0.
10190.TP
10191\fBshopt\fP [\fB\-pqsu\fP] [\fB\-o\fP] [\fIoptname\fP ...]
ac50fbac
CR
10192Toggle the values of settings controlling optional shell behavior.
10193The settings can be either those listed below, or, if the
10194.B \-o
10195option is used, those available with the
10196.B \-o
10197option to the \fBset\fP builtin command.
ccc6cda3
JA
10198With no options, or with the
10199.B \-p
10200option, a list of all settable options is displayed, with
d233b485
CR
10201an indication of whether or not each is set;
10202if \fIoptnames\fP are supplied, the output is restricted to those options.
cce855bc
JA
10203The \fB\-p\fP option causes output to be displayed in a form that
10204may be reused as input.
10205Other options have the following meanings:
ccc6cda3
JA
10206.RS
10207.PD 0
10208.TP
10209.B \-s
10210Enable (set) each \fIoptname\fP.
10211.TP
10212.B \-u
10213Disable (unset) each \fIoptname\fP.
10214.TP
10215.B \-q
10216Suppresses normal output (quiet mode); the return status indicates
10217whether the \fIoptname\fP is set or unset.
10218If multiple \fIoptname\fP arguments are given with
10219.BR \-q ,
10220the return status is zero if all \fIoptnames\fP are enabled; non-zero
10221otherwise.
10222.TP
10223.B \-o
10224Restricts the values of \fIoptname\fP to be those defined for the
10225.B \-o
10226option to the
10227.B set
10228builtin.
10229.PD
10230.PP
10231If either
10232.B \-s
10233or
10234.B \-u
ac50fbac
CR
10235is used with no \fIoptname\fP arguments,
10236.B shopt
10237shows only those options which are set or unset, respectively.
ccc6cda3
JA
10238Unless otherwise noted, the \fBshopt\fP options are disabled (unset)
10239by default.
10240.PP
10241The return status when listing options is zero if all \fIoptnames\fP
10242are enabled, non-zero otherwise. When setting or unsetting options,
cce855bc 10243the return status is zero unless an \fIoptname\fP is not a valid shell
ccc6cda3
JA
10244option.
10245.PP
10246The list of \fBshopt\fP options is:
10247.if t .sp .5v
10248.if n .sp 1v
10249.PD 0
10250.TP 8
d233b485
CR
10251.B assoc_expand_once
10252If set, the shell suppresses multiple evaluation of associative array
10253subscripts during arithmetic expression evaluation, while executing
10254builtins that can perform variable assignments,
10255and while executing builtins that perform array dereferencing.
10256.TP 8
3185942a
JA
10257.B autocd
10258If set, a command name that is the name of a directory is executed as if
10259it were the argument to the \fBcd\fP command.
10260This option is only used by interactive shells.
10261.TP 8
ccc6cda3
JA
10262.B cdable_vars
10263If set, an argument to the
10264.B cd
10265builtin command that
10266is not a directory is assumed to be the name of a variable whose
10267value is the directory to change to.
10268.TP 8
10269.B cdspell
10270If set, minor errors in the spelling of a directory component in a
10271.B cd
10272command will be corrected.
10273The errors checked for are transposed characters,
10274a missing character, and one character too many.
ac50fbac 10275If a correction is found, the corrected filename is printed,
ccc6cda3 10276and the command proceeds.
d166f048 10277This option is only used by interactive shells.
ccc6cda3
JA
10278.TP 8
10279.B checkhash
10280If set, \fBbash\fP checks that a command found in the hash
10281table exists before trying to execute it. If a hashed command no
10282longer exists, a normal path search is performed.
10283.TP 8
3185942a
JA
10284.B checkjobs
10285If set, \fBbash\fP lists the status of any stopped and running jobs before
10286exiting an interactive shell. If any jobs are running, this causes
10287the exit to be deferred until a second exit is attempted without an
0001803f
CR
10288intervening command (see
10289.SM
10290.B "JOB CONTROL"
74091dd4
CR
10291.ie \n(zZ=1 in \fIbash(1)\fP).
10292.el above).
10293The shell always postpones exiting if any jobs are stopped.
3185942a 10294.TP 8
ccc6cda3 10295.B checkwinsize
d233b485
CR
10296If set, \fBbash\fP checks the window size after each external (non-builtin)
10297command and, if necessary, updates the values of
ccc6cda3
JA
10298.SM
10299.B LINES
10300and
10301.SM
10302.BR COLUMNS .
d233b485 10303This option is enabled by default.
ccc6cda3
JA
10304.TP 8
10305.B cmdhist
10306If set,
10307.B bash
10308attempts to save all lines of a multiple-line
10309command in the same history entry. This allows
10310easy re-editing of multi-line commands.
d233b485 10311This option is enabled by default, but only has an effect if command
74091dd4
CR
10312history is enabled, as described
10313.ie \n(zZ=1 in \fIbash(1)\fP
10314.el above
10315under
d233b485
CR
10316.SM
10317.BR HISTORY .
8868edaf 10318.PD 0
ccc6cda3 10319.TP 8
f1be666c 10320.B compat31
0001803f 10321.TP 8
ac50fbac 10322.B compat32
ac50fbac 10323.TP 8
0001803f 10324.B compat40
0001803f 10325.TP 8
495aee44 10326.B compat41
495aee44 10327.TP 8
ac50fbac 10328.B compat42
ac50fbac 10329.TP 8
a0c0a00f 10330.B compat43
a0c0a00f 10331.TP 8
d233b485 10332.B compat44
74091dd4
CR
10333.TP 8
10334.B compat50
8868edaf
CR
10335.PD
10336These control aspects of the shell's compatibility mode
10337(see
10338.SM
10339.B "SHELL COMPATIBILITY MODE"
74091dd4
CR
10340.ie \n(zZ=1 in \fIbash(1)\fP).
10341.el below).
d233b485 10342.TP 8
ac50fbac
CR
10343.B complete_fullquote
10344If set,
10345.B bash
10346quotes all shell metacharacters in filenames and directory names when
10347performing completion.
10348If not set,
10349.B bash
10350removes metacharacters such as the dollar sign from the set of
10351characters that will be quoted in completed filenames
10352when these metacharacters appear in shell variable references in words to be
10353completed.
10354This means that dollar signs in variable names that expand to directories
10355will not be quoted;
10356however, any dollar signs appearing in filenames will not be quoted, either.
10357This is active only when bash is using backslashes to quote completed
10358filenames.
10359This variable is set by default, which is the default bash behavior in
10360versions through 4.2.
10361.TP 8
16b2d7f4
CR
10362.B direxpand
10363If set,
10364.B bash
10365replaces directory names with the results of word expansion when performing
10366filename completion. This changes the contents of the readline editing
10367buffer.
10368If not set,
10369.B bash
10370attempts to preserve what the user typed.
10371.TP 8
3185942a
JA
10372.B dirspell
10373If set,
10374.B bash
10375attempts spelling correction on directory names during word completion
10376if the directory name initially supplied does not exist.
10377.TP 8
ccc6cda3 10378.B dotglob
a0c0a00f 10379If set,
ccc6cda3
JA
10380.B bash
10381includes filenames beginning with a `.' in the results of pathname
10382expansion.
d233b485
CR
10383The filenames
10384.B ``.''
10385and
10386.B ``..''
10387must always be matched explicitly, even if
10388.B dotglob
10389is set.
ccc6cda3
JA
10390.TP 8
10391.B execfail
10392If set, a non-interactive shell will not exit if
10393it cannot execute the file specified as an argument to the
10394.B exec
10395builtin command. An interactive shell does not exit if
10396.B exec
10397fails.
10398.TP 8
10399.B expand_aliases
74091dd4
CR
10400If set, aliases are expanded as described
10401.ie \n(zZ=1 in \fIbash(1)\fP
10402.el above
10403under
ccc6cda3
JA
10404.SM
10405.BR ALIASES .
10406This option is enabled by default for interactive shells.
10407.TP 8
b80f6443 10408.B extdebug
8868edaf
CR
10409If set at shell invocation,
10410or in a shell startup file,
10411arrange to execute the debugger profile
a0c0a00f
CR
10412before the shell starts, identical to the \fB\-\-debugger\fP option.
10413If set after invocation, behavior intended for use by debuggers is enabled:
b80f6443
JA
10414.RS
10415.TP
10416.B 1.
10417The \fB\-F\fP option to the \fBdeclare\fP builtin displays the source
10418file name and line number corresponding to each function name supplied
10419as an argument.
10420.TP
10421.B 2.
10422If the command run by the \fBDEBUG\fP trap returns a non-zero value, the
10423next command is skipped and not executed.
10424.TP
10425.B 3.
10426If the command run by the \fBDEBUG\fP trap returns a value of 2, and the
10427shell is executing in a subroutine (a shell function or a shell script
a0c0a00f
CR
10428executed by the \fB.\fP or \fBsource\fP builtins), the shell simulates
10429a call to \fBreturn\fP.
95732b49
JA
10430.TP
10431.B 4.
0001803f
CR
10432.SM
10433.B BASH_ARGC
10434and
10435.SM
10436.B BASH_ARGV
74091dd4
CR
10437are updated as described in their descriptions
10438.ie \n(zZ=1 in \fIbash(1)\fP).
10439.el above).
95732b49
JA
10440.TP
10441.B 5.
a0c0a00f 10442Function tracing is enabled: command substitution, shell functions, and
95732b49
JA
10443subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the
10444\fBDEBUG\fP and \fBRETURN\fP traps.
10445.TP
10446.B 6.
a0c0a00f 10447Error tracing is enabled: command substitution, shell functions, and
95732b49 10448subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the
495aee44 10449\fBERR\fP trap.
b80f6443
JA
10450.RE
10451.TP 8
cce855bc 10452.B extglob
74091dd4
CR
10453If set, the extended pattern matching features described
10454.ie \n(zZ=1 in \fIbash(1)\fP
10455.el above
10456under
cce855bc
JA
10457\fBPathname Expansion\fP are enabled.
10458.TP 8
b80f6443 10459.B extquote
0628567a 10460If set, \fB$\fP\(aq\fIstring\fP\(aq and \fB$\fP"\fIstring\fP" quoting is
b80f6443
JA
10461performed within \fB${\fP\fIparameter\fP\fB}\fP expansions
10462enclosed in double quotes. This option is enabled by default.
10463.TP 8
10464.B failglob
10465If set, patterns which fail to match filenames during pathname expansion
10466result in an expansion error.
10467.TP 8
10468.B force_fignore
0001803f
CR
10469If set, the suffixes specified by the
10470.SM
10471.B FIGNORE
10472shell variable
b80f6443
JA
10473cause words to be ignored when performing word completion even if
10474the ignored words are the only possible completions.
10475See
10476.SM
10477\fBSHELL VARIABLES\fP
74091dd4
CR
10478.ie \n(zZ=1 in \fIbash(1)\fP
10479.el above
10480for a description of
0001803f
CR
10481.SM
10482.BR FIGNORE .
b80f6443
JA
10483This option is enabled by default.
10484.TP 8
ac50fbac
CR
10485.B globasciiranges
10486If set, range expressions used in pattern matching bracket expressions (see
10487.SM
10488.B Pattern Matching
74091dd4
CR
10489.ie \n(zZ=1 in \fIbash(1)\fP)
10490.el above)
10491behave as if in the traditional C locale when performing
ac50fbac
CR
10492comparisons. That is, the current locale's collating sequence
10493is not taken into account, so
10494.B b
10495will not collate between
10496.B A
10497and
10498.BR B ,
10499and upper-case and lower-case ASCII characters will collate together.
10500.TP 8
74091dd4
CR
10501.B globskipdots
10502If set, pathname expansion will never match the filenames
10503.B ``.''
10504and
10505.BR ``..'' ,
10506even if the pattern begins with a
10507.BR ``.'' .
10508This option is enabled by default.
10509.TP 8
3185942a 10510.B globstar
0001803f 10511If set, the pattern \fB**\fP used in a pathname expansion context will
495aee44 10512match all files and zero or more directories and subdirectories.
3185942a
JA
10513If the pattern is followed by a \fB/\fP, only directories and
10514subdirectories match.
10515.TP 8
b80f6443
JA
10516.B gnu_errfmt
10517If set, shell error messages are written in the standard GNU error
10518message format.
10519.TP 8
ccc6cda3
JA
10520.B histappend
10521If set, the history list is appended to the file named by the value
10522of the
0001803f 10523.SM
ccc6cda3
JA
10524.B HISTFILE
10525variable when the shell exits, rather than overwriting the file.
10526.TP 8
10527.B histreedit
10528If set, and
10529.B readline
10530is being used, a user is given the opportunity to re-edit a
10531failed history substitution.
10532.TP 8
10533.B histverify
a0c0a00f 10534If set, and
ccc6cda3
JA
10535.B readline
10536is being used, the results of history substitution are not immediately
10537passed to the shell parser. Instead, the resulting line is loaded into
10538the \fBreadline\fP editing buffer, allowing further modification.
10539.TP 8
10540.B hostcomplete
10541If set, and
10542.B readline
cce855bc
JA
10543is being used, \fBbash\fP will attempt to perform hostname completion when a
10544word containing a \fB@\fP is being completed (see
ccc6cda3
JA
10545.B Completing
10546under
10547.SM
10548.B READLINE
74091dd4
CR
10549.ie \n(zZ=1 in \fIbash(1)\fP).
10550.el above).
ccc6cda3
JA
10551This is enabled by default.
10552.TP 8
cce855bc
JA
10553.B huponexit
10554If set, \fBbash\fP will send
10555.SM
10556.B SIGHUP
10557to all jobs when an interactive login shell exits.
10558.TP 8
a0c0a00f
CR
10559.B inherit_errexit
10560If set, command substitution inherits the value of the \fBerrexit\fP option,
10561instead of unsetting it in the subshell environment.
10562This option is enabled when \fIposix mode\fP is enabled.
10563.TP 8
ccc6cda3
JA
10564.B interactive_comments
10565If set, allow a word beginning with
10566.B #
10567to cause that word and all remaining characters on that
10568line to be ignored in an interactive shell (see
10569.SM
10570.B COMMENTS
74091dd4
CR
10571.ie \n(zZ=1 in \fIbash(1)\fP).
10572.el above).
10573This option is enabled by default.
ccc6cda3 10574.TP 8
495aee44
CR
10575.B lastpipe
10576If set, and job control is not active, the shell runs the last command of
10577a pipeline not executed in the background in the current shell environment.
10578.TP 8
ccc6cda3
JA
10579.B lithist
10580If set, and the
10581.B cmdhist
10582option is enabled, multi-line commands are saved to the history with
10583embedded newlines rather than using semicolon separators where possible.
10584.TP 8
d233b485
CR
10585.B localvar_inherit
10586If set, local variables inherit the value and attributes of a variable of
10587the same name that exists at a previous scope before any new value is
10588assigned. The nameref attribute is not inherited.
10589.TP 8
10590.B localvar_unset
10591If set, calling \fBunset\fP on local variables in previous function scopes
10592marks them so subsequent lookups find them unset until that function
10593returns. This is identical to the behavior of unsetting local variables
10594at the current function scope.
10595.TP 8
f73dda09
JA
10596.B login_shell
10597The shell sets this option if it is started as a login shell (see
10598.SM
10599.B "INVOCATION"
74091dd4
CR
10600.ie \n(zZ=1 in \fIbash(1)\fP).
10601.el above).
f73dda09
JA
10602The value may not be changed.
10603.TP 8
ccc6cda3 10604.B mailwarn
a0c0a00f 10605If set, and a file that \fBbash\fP is checking for mail has been
ccc6cda3
JA
10606accessed since the last time it was checked, the message ``The mail in
10607\fImailfile\fP has been read'' is displayed.
10608.TP 8
bb70624e
JA
10609.B no_empty_cmd_completion
10610If set, and
10611.B readline
10612is being used,
10613.B bash
0001803f
CR
10614will not attempt to search the
10615.SM
10616.B PATH
10617for possible completions when
bb70624e
JA
10618completion is attempted on an empty line.
10619.TP 8
cce855bc
JA
10620.B nocaseglob
10621If set,
10622.B bash
10623matches filenames in a case\-insensitive fashion when performing pathname
10624expansion (see
10625.B Pathname Expansion
74091dd4
CR
10626.ie \n(zZ=1 in \fIbash(1)\fP).
10627.el above).
cce855bc 10628.TP 8
95732b49
JA
10629.B nocasematch
10630If set,
10631.B bash
10632matches patterns in a case\-insensitive fashion when performing matching
a0c0a00f
CR
10633while executing \fBcase\fP or \fB[[\fP conditional commands,
10634when performing pattern substitution word expansions,
10635or when filtering possible completions as part of programmable completion.
95732b49 10636.TP 8
74091dd4
CR
10637.B noexpand_translation
10638If set,
10639.B bash
10640encloses the translated results of $"..." quoting in single quotes
10641instead of double quotes.
10642If the string is not translated, this has no effect.
10643.TP 8
ccc6cda3
JA
10644.B nullglob
10645If set,
10646.B bash
10647allows patterns which match no
10648files (see
10649.B Pathname Expansion
74091dd4
CR
10650.ie \n(zZ=1 in \fIbash(1)\fP)
10651.el above)
ccc6cda3
JA
10652to expand to a null string, rather than themselves.
10653.TP 8
74091dd4
CR
10654.B patsub_replacement
10655If set, \fBbash\fP
10656expands occurrences of \fB&\fP in the replacement string of pattern
10657substitution to the text matched by the pattern, as described
10658under \fBParameter Expansion\fP
10659.ie \n(zZ=1 in \fIbash(1)\fP.
10660.el above.
10661This option is enabled by default.
10662.TP 8
bb70624e
JA
10663.B progcomp
10664If set, the programmable completion facilities (see
74091dd4
CR
10665\fBProgrammable Completion\fP
10666.ie \n(zZ=1 in \fIbash(1)\fP)
10667.el above)
10668are enabled.
bb70624e
JA
10669This option is enabled by default.
10670.TP 8
d233b485
CR
10671.B progcomp_alias
10672If set, and programmable completion is enabled, \fBbash\fP treats a command
10673name that doesn't have any completions as a possible alias and attempts
10674alias expansion. If it has an alias, \fBbash\fP attempts programmable
10675completion using the command word resulting from the expanded alias.
10676.TP 8
ccc6cda3 10677.B promptvars
b80f6443
JA
10678If set, prompt strings undergo
10679parameter expansion, command substitution, arithmetic
10680expansion, and quote removal after being expanded as described in
ccc6cda3
JA
10681.SM
10682.B PROMPTING
74091dd4
CR
10683.ie \n(zZ=1 in \fIbash(1)\fP.
10684.el above.
10685This option is enabled by default.
ccc6cda3 10686.TP 8
b72432fd 10687.B restricted_shell
74091dd4
CR
10688The shell sets this option if it is started in restricted mode
10689(see
b72432fd
JA
10690.SM
10691.B "RESTRICTED SHELL"
74091dd4
CR
10692.ie \n(zZ=1 in \fIbash(1)\fP).
10693.el below).
b72432fd
JA
10694The value may not be changed.
10695This is not reset when the startup files are executed, allowing
10696the startup files to discover whether or not a shell is restricted.
10697.TP 8
ccc6cda3
JA
10698.B shift_verbose
10699If set, the
10700.B shift
10701builtin prints an error message when the shift count exceeds the
10702number of positional parameters.
10703.TP 8
10704.B sourcepath
10705If set, the
74091dd4 10706\fB.\fP (\fBsource\fP) builtin uses the value of
ccc6cda3
JA
10707.SM
10708.B PATH
10709to find the directory containing the file supplied as an argument.
cce855bc 10710This option is enabled by default.
bb70624e 10711.TP 8
74091dd4
CR
10712.B varredir_close
10713If set, the shell automatically closes file descriptors assigned using the
10714\fI{varname}\fP redirection syntax (see
10715.SM
10716.B REDIRECTION
10717.ie \n(zZ=1 in \fIbash(1)\fP)
10718.el above)
10719instead of leaving them open when the command completes.
10720.TP 8
bb70624e
JA
10721.B xpg_echo
10722If set, the \fBecho\fP builtin expands backslash-escape sequences
10723by default.
ccc6cda3 10724.RE
495aee44 10725.PD
726f6388
JA
10726.TP
10727\fBsuspend\fP [\fB\-f\fP]
10728Suspend the execution of this shell until it receives a
10729.SM
10730.B SIGCONT
74091dd4
CR
10731signal. A login shell,
10732or a shell without job control enabled,
10733cannot be suspended; the
726f6388 10734.B \-f
3185942a 10735option can be used to override this and force the suspension.
74091dd4
CR
10736The return status is 0 unless the shell is a login shell
10737or job control is not enabled
10738and
726f6388 10739.B \-f
74091dd4 10740is not supplied.
726f6388 10741.TP
726f6388 10742\fBtest\fP \fIexpr\fP
7117c2d2 10743.PD 0
726f6388
JA
10744.TP
10745\fB[\fP \fIexpr\fP \fB]\fP
ac50fbac 10746Return a status of 0 (true) or 1 (false) depending on
726f6388
JA
10747the evaluation of the conditional expression
10748.IR expr .
cce855bc 10749Each operator and operand must be a separate argument.
74091dd4
CR
10750Expressions are composed of the primaries described
10751.ie \n(zZ=1 in \fIbash(1)\fP
10752.el above
10753under
cce855bc
JA
10754.SM
10755.BR "CONDITIONAL EXPRESSIONS" .
95732b49
JA
10756\fBtest\fP does not accept any options, nor does it accept and ignore
10757an argument of \fB\-\-\fP as signifying the end of options.
cce855bc
JA
10758.if t .sp 0.5
10759.if n .sp 1
10760Expressions may be combined using the following operators, listed
10761in decreasing order of precedence.
3185942a 10762The evaluation depends on the number of arguments; see below.
495aee44 10763Operator precedence is used when there are five or more arguments.
726f6388
JA
10764.RS
10765.PD 0
10766.TP
726f6388
JA
10767.B ! \fIexpr\fP
10768True if
10769.I expr
10770is false.
10771.TP
cce855bc
JA
10772.B ( \fIexpr\fP )
10773Returns the value of \fIexpr\fP.
10774This may be used to override the normal precedence of operators.
10775.TP
726f6388
JA
10776\fIexpr1\fP \-\fBa\fP \fIexpr2\fP
10777True if both
10778.I expr1
cce855bc 10779and
726f6388
JA
10780.I expr2
10781are true.
10782.TP
10783\fIexpr1\fP \-\fBo\fP \fIexpr2\fP
10784True if either
10785.I expr1
cce855bc 10786or
726f6388
JA
10787.I expr2
10788is true.
cce855bc
JA
10789.PD
10790.PP
10791\fBtest\fP and \fB[\fP evaluate conditional
10792expressions using a set of rules based on the number of arguments.
10793.if t .sp 0.5
10794.if n .sp 1
10795.PD 0
726f6388 10796.TP
cce855bc
JA
107970 arguments
10798The expression is false.
10799.TP
108001 argument
10801The expression is true if and only if the argument is not null.
10802.TP
108032 arguments
10804If the first argument is \fB!\fP, the expression is true if and
10805only if the second argument is null.
74091dd4
CR
10806If the first argument is one of the unary conditional operators listed
10807.ie \n(zZ=1 in \fIbash(1)\fP
10808.el above
cce855bc 10809under
726f6388 10810.SM
cce855bc
JA
10811.BR "CONDITIONAL EXPRESSIONS" ,
10812the expression is true if the unary test is true.
10813If the first argument is not a valid unary conditional operator, the expression
10814is false.
10815.TP
108163 arguments
495aee44 10817The following conditions are applied in the order listed.
74091dd4
CR
10818If the second argument is one of the binary conditional operators listed
10819.ie \n(zZ=1 in \fIbash(1)\fP
10820.el above
cce855bc
JA
10821under
10822.SM
10823.BR "CONDITIONAL EXPRESSIONS" ,
10824the result of the expression is the result of the binary test using
10825the first and third arguments as operands.
3185942a 10826The \fB\-a\fP and \fB\-o\fP operators are considered binary operators
a0c0a00f 10827when there are three arguments.
cce855bc
JA
10828If the first argument is \fB!\fP, the value is the negation of
10829the two-argument test using the second and third arguments.
10830If the first argument is exactly \fB(\fP and the third argument is
10831exactly \fB)\fP, the result is the one-argument test of the second
10832argument.
10833Otherwise, the expression is false.
cce855bc
JA
10834.TP
108354 arguments
74091dd4 10836The following conditions are applied in the order listed.
cce855bc
JA
10837If the first argument is \fB!\fP, the result is the negation of
10838the three-argument expression composed of the remaining arguments.
74091dd4
CR
10839the two-argument test using the second and third arguments.
10840If the first argument is exactly \fB(\fP and the fourth argument is
10841exactly \fB)\fP, the result is the two-argument test of the second
10842and third arguments.
a0c0a00f 10843Otherwise, the expression is parsed and evaluated according to
cce855bc
JA
10844precedence using the rules listed above.
10845.TP
108465 or more arguments
10847The expression is parsed and evaluated according to precedence
10848using the rules listed above.
495aee44
CR
10849.if t .sp 0.5
10850.if n .sp 1
10851.LP
10852When used with \fBtest\fP or \fB[\fP, the \fB<\fP and \fB>\fP operators
10853sort lexicographically using ASCII ordering.
726f6388 10854.RE
cce855bc 10855.PD
726f6388
JA
10856.TP
10857.B times
10858Print the accumulated user and system times for the shell and
10859for processes run from the shell. The return status is 0.
10860.TP
b80f6443 10861\fBtrap\fP [\fB\-lp\fP] [[\fIarg\fP] \fIsigspec\fP ...]
726f6388
JA
10862The command
10863.I arg
10864is to be read and executed when the shell receives
10865signal(s)
10866.IR sigspec .
10867If
10868.I arg
b80f6443 10869is absent (and there is a single \fIsigspec\fP) or
726f6388 10870.BR \- ,
b80f6443
JA
10871each specified signal is
10872reset to its original disposition (the value it had
d166f048 10873upon entrance to the shell).
a0c0a00f 10874If
726f6388 10875.I arg
d166f048
JA
10876is the null string the signal specified by each
10877.I sigspec
10878is ignored by the shell and by the commands it invokes.
ccc6cda3
JA
10879If
10880.I arg
bb70624e 10881is not present and
ccc6cda3 10882.B \-p
bb70624e 10883has been supplied, then the trap commands associated with each
ccc6cda3 10884.I sigspec
bb70624e
JA
10885are displayed.
10886If no arguments are supplied or if only
ccc6cda3
JA
10887.B \-p
10888is given,
10889.B trap
b80f6443
JA
10890prints the list of commands associated with each signal.
10891The
10892.B \-l
10893option causes the shell to print a list of signal names and
10894their corresponding numbers.
d166f048 10895Each
726f6388
JA
10896.I sigspec
10897is either
d166f048 10898a signal name defined in <\fIsignal.h\fP>, or a signal number.
495aee44
CR
10899Signal names are case insensitive and the
10900.SM
10901.B SIG
10902prefix is optional.
0001803f
CR
10903.if t .sp 0.5
10904.if n .sp 1
d166f048 10905If a
726f6388
JA
10906.I sigspec
10907is
10908.SM
10909.B EXIT
10910(0) the command
10911.I arg
f73dda09
JA
10912is executed on exit from the shell.
10913If a
ccc6cda3
JA
10914.I sigspec
10915is
10916.SM
10917.BR DEBUG ,
10918the command
10919.I arg
b80f6443
JA
10920is executed before every \fIsimple command\fP, \fIfor\fP command,
10921\fIcase\fP command, \fIselect\fP command, every arithmetic \fIfor\fP
10922command, and before the first command executes in a shell function (see
ccc6cda3
JA
10923.SM
10924.B SHELL GRAMMAR
74091dd4
CR
10925.ie \n(zZ=1 in \fIbash(1)\fP).
10926.el above).
95732b49 10927Refer to the description of the \fBextdebug\fP option to the
b80f6443 10928\fBshopt\fP builtin for details of its effect on the \fBDEBUG\fP trap.
f73dda09
JA
10929If a
10930.I sigspec
10931is
10932.SM
0001803f
CR
10933.BR RETURN ,
10934the command
10935.I arg
495aee44
CR
10936is executed each time a shell function or a script executed with
10937the \fB.\fP or \fBsource\fP builtins finishes executing.
0001803f
CR
10938.if t .sp 0.5
10939.if n .sp 1
10940If a
10941.I sigspec
10942is
10943.SM
f73dda09
JA
10944.BR ERR ,
10945the command
10946.I arg
a0c0a00f 10947is executed whenever
ac50fbac 10948a pipeline (which may consist of a single simple
a0c0a00f 10949command), a list, or a compound command returns a
ac50fbac 10950non\-zero exit status,
b80f6443 10951subject to the following conditions.
f73dda09
JA
10952The
10953.SM
b80f6443
JA
10954.B ERR
10955trap is not executed if the failed
10956command is part of the command list immediately following a
10957.B while
f73dda09 10958or
b80f6443 10959.B until
a0c0a00f 10960keyword,
b80f6443 10961part of the test in an
f73dda09 10962.I if
3185942a 10963statement, part of a command executed in a
f73dda09
JA
10964.B &&
10965or
495aee44 10966.B ||
ac50fbac
CR
10967list except the command following the final \fB&&\fP or \fB||\fP,
10968any command in a pipeline but the last,
10969or if the command's return value is
10970being inverted using
f73dda09 10971.BR ! .
ac50fbac 10972These are the same conditions obeyed by the \fBerrexit\fP (\fB\-e\fP) option.
0001803f
CR
10973.if t .sp 0.5
10974.if n .sp 1
726f6388 10975Signals ignored upon entry to the shell cannot be trapped or reset.
0628567a 10976Trapped signals that are not being ignored are reset to their original
0001803f 10977values in a subshell or subshell environment when one is created.
d166f048 10978The return status is false if any
ccc6cda3
JA
10979.I sigspec
10980is invalid; otherwise
726f6388
JA
10981.B trap
10982returns true.
10983.TP
7117c2d2 10984\fBtype\fP [\fB\-aftpP\fP] \fIname\fP [\fIname\fP ...]
a0c0a00f 10985With no options,
726f6388
JA
10986indicate how each
10987.I name
10988would be interpreted if used as a command name.
10989If the
cce855bc
JA
10990.B \-t
10991option is used,
726f6388 10992.B type
ccc6cda3 10993prints a string which is one of
726f6388
JA
10994.IR alias ,
10995.IR keyword ,
10996.IR function ,
10997.IR builtin ,
10998or
a0c0a00f 10999.I file
726f6388
JA
11000if
11001.I name
11002is an alias, shell reserved word, function, builtin, or disk file,
ccc6cda3
JA
11003respectively.
11004If the
11005.I name
11006is not found, then nothing is printed, and an exit status of false
11007is returned.
726f6388 11008If the
cce855bc
JA
11009.B \-p
11010option is used,
726f6388
JA
11011.B type
11012either returns the name of the disk file
11013that would be executed if
11014.I name
11015were specified as a command name,
28ef6c31
JA
11016or nothing if
11017.if t \f(CWtype -t name\fP
11018.if n ``type -t name''
726f6388
JA
11019would not return
11020.IR file .
7117c2d2
JA
11021The
11022.B \-P
11023option forces a
11024.SM
11025.B PATH
11026search for each \fIname\fP, even if
11027.if t \f(CWtype -t name\fP
11028.if n ``type -t name''
11029would not return
11030.IR file .
726f6388 11031If a command is hashed,
cce855bc 11032.B \-p
7117c2d2
JA
11033and
11034.B \-P
ac50fbac 11035print the hashed value, which is not necessarily the file that appears
a0c0a00f 11036first in
726f6388
JA
11037.SM
11038.BR PATH .
11039If the
cce855bc 11040.B \-a
a0c0a00f 11041option is used,
726f6388
JA
11042.B type
11043prints all of the places that contain
a0c0a00f 11044an executable named
726f6388
JA
11045.IR name .
11046This includes aliases and functions,
a0c0a00f 11047if and only if the
cce855bc
JA
11048.B \-p
11049option is not also used.
726f6388
JA
11050The table of hashed commands is not consulted
11051when using
cce855bc 11052.BR \-a .
7117c2d2
JA
11053The
11054.B \-f
11055option suppresses shell function lookup, as with the \fBcommand\fP builtin.
726f6388 11056.B type
3185942a
JA
11057returns true if all of the arguments are found, false if
11058any are not found.
726f6388 11059.TP
8868edaf
CR
11060\fBulimit\fP [\fB\-HS\fP] \fB\-a\fP
11061.PD 0
11062.TP
11063\fBulimit\fP [\fB\-HS\fP] [\fB\-bcdefiklmnpqrstuvxPRT\fP [\fIlimit\fP]]
11064.PD
ccc6cda3 11065Provides control over the resources available to the shell and to
f73dda09 11066processes started by it, on systems that allow such control.
ccc6cda3 11067The \fB\-H\fP and \fB\-S\fP options specify that the hard or soft limit is
3185942a
JA
11068set for the given resource.
11069A hard limit cannot be increased by a non-root user once it is set;
11070a soft limit may be increased up to the value of the hard limit.
ccc6cda3
JA
11071If neither \fB\-H\fP nor \fB\-S\fP is specified, both the soft and hard
11072limits are set.
f73dda09
JA
11073The value of
11074.I limit
11075can be a number in the unit specified for the resource
11076or one of the special values
11077.BR hard ,
11078.BR soft ,
11079or
11080.BR unlimited ,
11081which stand for the current hard limit, the current soft limit, and
11082no limit, respectively.
ccc6cda3 11083If
726f6388
JA
11084.I limit
11085is omitted, the current value of the soft limit of the resource is
ccc6cda3 11086printed, unless the \fB\-H\fP option is given. When more than one
8868edaf
CR
11087resource is specified, the limit name and unit, if appropriate,
11088are printed before the value.
726f6388
JA
11089Other options are interpreted as follows:
11090.RS
11091.PD 0
11092.TP
11093.B \-a
8868edaf 11094All current limits are reported; no limits are set
726f6388 11095.TP
3185942a
JA
11096.B \-b
11097The maximum socket buffer size
11098.TP
726f6388 11099.B \-c
ccc6cda3 11100The maximum size of core files created
726f6388
JA
11101.TP
11102.B \-d
ccc6cda3 11103The maximum size of a process's data segment
726f6388 11104.TP
0628567a
JA
11105.B \-e
11106The maximum scheduling priority ("nice")
11107.TP
726f6388 11108.B \-f
0628567a
JA
11109The maximum size of files written by the shell and its children
11110.TP
11111.B \-i
11112The maximum number of pending signals
726f6388 11113.TP
a0c0a00f
CR
11114.B \-k
11115The maximum number of kqueues that may be allocated
11116.TP
ccc6cda3
JA
11117.B \-l
11118The maximum size that may be locked into memory
726f6388 11119.TP
ccc6cda3 11120.B \-m
17345e5a 11121The maximum resident set size (many systems do not honor this limit)
726f6388 11122.TP
ccc6cda3
JA
11123.B \-n
11124The maximum number of open file descriptors (most systems do not
11125allow this value to be set)
726f6388
JA
11126.TP
11127.B \-p
ccc6cda3 11128The pipe size in 512-byte blocks (this may not be set)
726f6388 11129.TP
0628567a
JA
11130.B \-q
11131The maximum number of bytes in POSIX message queues
11132.TP
11133.B \-r
11134The maximum real-time scheduling priority
11135.TP
ccc6cda3
JA
11136.B \-s
11137The maximum stack size
11138.TP
11139.B \-t
11140The maximum amount of cpu time in seconds
726f6388
JA
11141.TP
11142.B \-u
ccc6cda3 11143The maximum number of processes available to a single user
726f6388
JA
11144.TP
11145.B \-v
495aee44
CR
11146The maximum amount of virtual memory available to the shell and, on
11147some systems, to its children
0628567a
JA
11148.TP
11149.B \-x
11150The maximum number of file locks
3185942a 11151.TP
a0c0a00f
CR
11152.B \-P
11153The maximum number of pseudoterminals
11154.TP
8868edaf
CR
11155.B \-R
11156The maximum time a real-time process can run before blocking, in microseconds
11157.TP
3185942a
JA
11158.B \-T
11159The maximum number of threads
726f6388
JA
11160.PD
11161.PP
ccc6cda3 11162If
726f6388 11163.I limit
ac50fbac 11164is given, and the
726f6388 11165.B \-a
ac50fbac
CR
11166option is not used,
11167\fIlimit\fP is the new value of the specified resource.
726f6388
JA
11168If no option is given, then
11169.B \-f
11170is assumed. Values are in 1024-byte increments, except for
11171.BR \-t ,
ac50fbac 11172which is in seconds;
8868edaf
CR
11173.BR \-R ,
11174which is in microseconds;
726f6388 11175.BR \-p ,
ac50fbac 11176which is in units of 512-byte blocks;
a0c0a00f 11177.BR \-P ,
3185942a
JA
11178.BR \-T ,
11179.BR \-b ,
a0c0a00f 11180.BR \-k ,
3185942a 11181.BR \-n ,
726f6388
JA
11182and
11183.BR \-u ,
a0c0a00f 11184which are unscaled values;
d233b485 11185and, when in posix mode,
a0c0a00f
CR
11186.B \-c
11187and
11188.BR \-f ,
11189which are in 512-byte increments.
f73dda09
JA
11190The return status is 0 unless an invalid option or argument is supplied,
11191or an error occurs while setting a new limit.
726f6388
JA
11192.RE
11193.TP
cce855bc 11194\fBumask\fP [\fB\-p\fP] [\fB\-S\fP] [\fImode\fP]
a0c0a00f 11195The user file-creation mask is set to
726f6388
JA
11196.IR mode .
11197If
11198.I mode
11199begins with a digit, it
11200is interpreted as an octal number; otherwise
11201it is interpreted as a symbolic mode mask similar
11202to that accepted by
11203.IR chmod (1).
11204If
11205.I mode
bb70624e 11206is omitted, the current value of the mask is printed.
ccc6cda3 11207The
726f6388
JA
11208.B \-S
11209option causes the mask to be printed in symbolic form; the
11210default output is an octal number.
cce855bc
JA
11211If the
11212.B \-p
11213option is supplied, and
11214.I mode
11215is omitted, the output is in a form that may be reused as input.
ccc6cda3 11216The return status is 0 if the mode was successfully changed or if
726f6388
JA
11217no \fImode\fP argument was supplied, and false otherwise.
11218.TP
11219\fBunalias\fP [\-\fBa\fP] [\fIname\fP ...]
bb70624e 11220Remove each \fIname\fP from the list of defined aliases. If
726f6388
JA
11221.B \-a
11222is supplied, all alias definitions are removed. The return
11223value is true unless a supplied
11224.I name
11225is not a defined alias.
11226.TP
ac50fbac 11227\fBunset\fP [\-\fBfv\fP] [\-\fBn\fP] [\fIname\fP ...]
726f6388
JA
11228For each
11229.IR name ,
ccc6cda3 11230remove the corresponding variable or function.
ac50fbac 11231If the
ccc6cda3
JA
11232.B \-v
11233option is given, each
11234.I name
ac50fbac 11235refers to a shell variable, and that variable is removed.
ccc6cda3
JA
11236Read-only variables may not be unset.
11237If
726f6388 11238.B \-f
95732b49 11239is specified, each
ccc6cda3
JA
11240.I name
11241refers to a shell function, and the function definition
11242is removed.
ac50fbac
CR
11243If the
11244.B \-n
11245option is supplied, and \fIname\fP is a variable with the \fInameref\fP
11246attribute, \fIname\fP will be unset rather than the variable it
11247references.
11248\fB\-n\fP has no effect if the \fB\-f\fP option is supplied.
11249If no options are supplied, each \fIname\fP refers to a variable; if
8868edaf 11250there is no variable by that name, a function with that name, if any, is
ac50fbac 11251unset.
ccc6cda3
JA
11252Each unset variable or function is removed from the environment
11253passed to subsequent commands.
11254If any of
726f6388 11255.SM
8868edaf 11256.BR BASH_ALIASES ,
0001803f 11257.SM
8868edaf 11258.BR BASH_ARGV0 ,
726f6388 11259.SM
8868edaf 11260.BR BASH_CMDS ,
726f6388 11261.SM
8868edaf 11262.BR BASH_COMMAND ,
ccc6cda3 11263.SM
8868edaf
CR
11264.BR BASH_SUBSHELL ,
11265.SM
11266.BR BASHPID ,
11267.SM
11268.BR COMP_WORDBREAKS ,
11269.SM
11270.BR DIRSTACK ,
11271.SM
11272.BR EPOCHREALTIME ,
11273.SM
11274.BR EPOCHSECONDS ,
bb70624e
JA
11275.SM
11276.BR FUNCNAME ,
11277.SM
11278.BR GROUPS ,
8868edaf
CR
11279.SM
11280.BR HISTCMD ,
11281.SM
11282.BR LINENO ,
11283.SM
11284.BR RANDOM ,
11285.SM
11286.BR SECONDS ,
726f6388
JA
11287or
11288.SM
8868edaf 11289.B SRANDOM
726f6388
JA
11290are unset, they lose their special properties, even if they are
11291subsequently reset. The exit status is true unless a
11292.I name
74091dd4 11293is readonly or may not be unset.
726f6388 11294.TP
8868edaf 11295\fBwait\fP [\fB\-fn\fP] [\fP\-p\fP \fIvarname\fP] [\fIid ...\fP]
ac50fbac 11296Wait for each specified child process and return its termination status.
95732b49 11297Each
d233b485 11298.I id
726f6388
JA
11299may be a process
11300ID or a job specification; if a job spec is given, all processes
11301in that job's pipeline are waited for. If
d233b485 11302.I id
8868edaf
CR
11303is not given,
11304\fBwait\fP waits for all running background jobs and
11305the last-executed process substitution, if its process id is the same as
11306\fB$!\fP,
11307and the return status is zero.
11308If the \fB\-n\fP option is supplied,
11309\fBwait\fP waits for a single job
11310from the list of \fIid\fPs or, if no \fIid\fPs are supplied, any job,
11311to complete and returns its exit status.
11312If none of the supplied arguments is a child of the shell, or if no arguments
11313are supplied and the shell has no unwaited-for children, the exit status
11314is 127.
11315If the \fB\-p\fP option is supplied, the process or job identifier of the job
11316for which the exit status is returned is assigned to the variable
11317\fIvarname\fP named by the option argument.
11318The variable will be unset initially, before any assignment.
11319This is useful only when the \fB\-n\fP option is supplied.
11320Supplying the \fB\-f\fP option, when job control is enabled,
11321forces \fBwait\fP to wait for \fIid\fP to terminate before returning
11322its status, instead of returning when it changes status.
ac50fbac 11323If
d233b485 11324.I id
74091dd4
CR
11325specifies a non-existent process or job, the return status is 127.
11326If \fBwait\fP is interrupted by a signal, the return status will be greater
11327than 128, as described under
11328.B SIGNALS
11329.ie \n(zZ=1 in \fIbash(1)\fP.
11330.el above.
11331Otherwise, the return status is the exit status of the last
726f6388 11332process or job waited for.
8868edaf 11333.SH "SHELL COMPATIBILITY MODE"
74091dd4
CR
11334Bash-4.0 introduced the concept of a \fIshell compatibility level\fP,
11335specified as a set of options to the shopt builtin (
8868edaf
CR
11336.BR compat31 ,
11337.BR compat32 ,
11338.BR compat40 ,
11339.BR compat41 ,
11340and so on).
11341There is only one current
11342compatibility level -- each option is mutually exclusive.
11343The compatibility level is intended to allow users to select behavior
11344from previous versions that is incompatible with newer versions
11345while they migrate scripts to use current features and
11346behavior. It's intended to be a temporary solution.
11347.PP
11348This section does not mention behavior that is standard for a particular
11349version (e.g., setting \fBcompat32\fP means that quoting the rhs of the regexp
11350matching operator quotes special regexp characters in the word, which is
74091dd4 11351default behavior in bash-3.2 and subsequent versions).
8868edaf
CR
11352.PP
11353If a user enables, say, \fBcompat32\fP, it may affect the behavior of other
11354compatibility levels up to and including the current compatibility level.
11355The idea is that each compatibility level controls behavior that changed
11356in that version of \fBbash\fP,
11357but that behavior may have been present in earlier versions.
11358For instance, the change to use locale-based comparisons with the \fB[[\fP
11359command came in bash-4.1, and earlier versions used ASCII-based comparisons,
11360so enabling \fBcompat32\fP will enable ASCII-based comparisons as well.
11361That granularity may not be sufficient for
11362all uses, and as a result users should employ compatibility levels carefully.
11363Read the documentation for a particular feature to find out the
11364current behavior.
11365.PP
11366Bash-4.3 introduced a new shell variable:
11367.SM
11368.BR BASH_COMPAT .
11369The value assigned
11370to this variable (a decimal version number like 4.2, or an integer
11371corresponding to the \fBcompat\fP\fINN\fP option, like 42) determines the
11372compatibility level.
11373.PP
11374Starting with bash-4.4, Bash has begun deprecating older compatibility
11375levels.
11376Eventually, the options will be removed in favor of
11377.SM
11378.BR BASH_COMPAT .
11379.PP
11380Bash-5.0 is the final version for which there will be an individual shopt
11381option for the previous version. Users should use
11382.SM
11383.B BASH_COMPAT
11384on bash-5.0 and later versions.
11385.PP
11386The following table describes the behavior changes controlled by each
11387compatibility level setting.
11388The \fBcompat\fP\fINN\fP tag is used as shorthand for setting the
11389compatibility level
11390to \fINN\fP using one of the following mechanisms.
11391For versions prior to bash-5.0, the compatibility level may be set using
11392the corresponding \fBcompat\fP\fINN\fP shopt option.
11393For bash-4.3 and later versions, the
11394.SM
11395.B BASH_COMPAT
11396variable is preferred,
11397and it is required for bash-5.1 and later versions.
11398.TP
11399\fBcompat31\fP
11400.PD 0
11401.RS
11402.IP \(bu
11403quoting the rhs of the \fB[[\fP command's regexp matching operator (=~)
11404has no special effect
11405.RE
11406.PD
11407.TP
11408\fBcompat32\fP
11409.PD 0
11410.RS
11411.IP \(bu
11412interrupting a command list such as "a ; b ; c" causes the execution
11413of the next command in the list (in bash-4.0 and later versions,
11414the shell acts as if it received the interrupt, so
11415interrupting one command in a list aborts the execution of the
11416entire list)
11417.RE
11418.PD
11419.TP
11420\fBcompat40\fP
11421.PD 0
11422.RS
11423.IP \(bu
11424the \fB<\fP and \fB>\fP operators to the \fB[[\fP command do not
11425consider the current locale when comparing strings; they use ASCII
11426ordering.
11427Bash versions prior to bash-4.1 use ASCII collation and
11428.IR strcmp (3);
11429bash-4.1 and later use the current locale's collation sequence and
11430.IR strcoll (3).
11431.RE
11432.PD
11433.TP
11434\fBcompat41\fP
11435.PD 0
11436.RS
11437.IP \(bu
11438in \fIposix\fP mode, \fBtime\fP may be followed by options and still be
11439recognized as a reserved word (this is POSIX interpretation 267)
11440.IP \(bu
11441in \fIposix\fP mode, the parser requires that an even number of single
11442quotes occur in the \fIword\fP portion of a double-quoted
11443parameter expansion and treats them specially, so that characters within
11444the single quotes are considered quoted
11445(this is POSIX interpretation 221)
11446.RE
11447.PD
11448.TP
11449\fBcompat42\fP
11450.PD 0
11451.RS
11452.IP \(bu
11453the replacement string in double-quoted pattern substitution does not
11454undergo quote removal, as it does in versions after bash-4.2
11455.IP \(bu
11456in posix mode, single quotes are considered special when expanding
11457the \fIword\fP portion of a double-quoted parameter expansion
11458and can be used to quote a closing brace or other special character
11459(this is part of POSIX interpretation 221);
11460in later versions, single quotes
11461are not special within double-quoted word expansions
11462.RE
11463.PD
11464.TP
11465\fBcompat43\fP
11466.PD 0
11467.RS
11468.IP \(bu
11469the shell does not print a warning message if an attempt is made to
11470use a quoted compound assignment as an argument to declare
74091dd4 11471(e.g., declare -a foo=\(aq(1 2)\(aq). Later versions warn that this usage is
8868edaf
CR
11472deprecated
11473.IP \(bu
11474word expansion errors are considered non-fatal errors that cause the
11475current command to fail, even in posix mode
11476(the default behavior is to make them fatal errors that cause the shell
11477to exit)
11478.IP \(bu
11479when executing a shell function, the loop state (while/until/etc.)
11480is not reset, so \fBbreak\fP or \fBcontinue\fP in that function will break
11481or continue loops in the calling context. Bash-4.4 and later reset
11482the loop state to prevent this
11483.RE
11484.PD
11485.TP
11486\fBcompat44\fP
11487.PD 0
11488.RS
11489.IP \(bu
11490the shell sets up the values used by
11491.SM
11492.B BASH_ARGV
11493and
11494.SM
11495.B BASH_ARGC
11496so they can expand to the shell's positional parameters even if extended
11497debugging mode is not enabled
11498.IP \(bu
11499a subshell inherits loops from its parent context, so \fBbreak\fP
11500or \fBcontinue\fP will cause the subshell to exit.
11501Bash-5.0 and later reset the loop state to prevent the exit
11502.IP \(bu
11503variable assignments preceding builtins like \fBexport\fP and \fBreadonly\fP
11504that set attributes continue to affect variables with the same
11505name in the calling environment even if the shell is not in posix
11506mode
11507.RE
11508.PD
11509.TP
11510\fBcompat50\fP
11511.PD 0
11512.RS
11513.IP \(bu
11514Bash-5.1 changed the way
11515.SM
11516.B $RANDOM
11517is generated to introduce slightly
11518more randomness. If the shell compatibility level is set to 50 or
11519lower, it reverts to the method from bash-5.0 and previous versions,
11520so seeding the random number generator by assigning a value to
11521.SM
11522.B RANDOM
11523will produce the same sequence as in bash-5.0
11524.IP \(bu
11525If the command hash table is empty, bash versions prior to bash-5.1
11526printed an informational message to that effect, even when producing
11527output that can be reused as input. Bash-5.1 suppresses that message
11528when the \fB\-l\fP option is supplied.
11529.RE
11530.PD
74091dd4
CR
11531.TP
11532\fBcompat51\fP
11533.PD 0
11534.RS
11535.IP \(bu
11536The \fBunset\fP builtin treats attempts to unset array subscripts \fB@\fP
11537and \fB*\fP differently depending on whether the array is indexed or
11538associative, and differently than in previous versions.
11539.RE
11540.PD
726f6388
JA
11541.\" bash_builtins
11542.if \n(zZ=1 .ig zZ
ccc6cda3 11543.SH "RESTRICTED SHELL"
bb70624e
JA
11544.\" rbash.1
11545.zY
726f6388 11546.PP
ccc6cda3 11547If
726f6388 11548.B bash
ccc6cda3
JA
11549is started with the name
11550.BR rbash ,
11551or the
11552.B \-r
11553option is supplied at invocation,
11554the shell becomes restricted.
11555A restricted shell is used to
11556set up an environment more controlled than the standard shell.
11557It behaves identically to
11558.B bash
cce855bc 11559with the exception that the following are disallowed or not performed:
ccc6cda3
JA
11560.IP \(bu
11561changing directories with \fBcd\fP
11562.IP \(bu
11563setting or unsetting the values of
0001803f 11564.SM
b72432fd 11565.BR SHELL ,
0001803f 11566.SM
b72432fd 11567.BR PATH ,
0001803f 11568.SM
8868edaf
CR
11569.BR HISTFILE ,
11570.SM
b72432fd 11571.BR ENV ,
ccc6cda3 11572or
0001803f 11573.SM
b72432fd 11574.B BASH_ENV
ccc6cda3
JA
11575.IP \(bu
11576specifying command names containing
11577.B /
11578.IP \(bu
ac50fbac 11579specifying a filename containing a
ccc6cda3
JA
11580.B /
11581as an argument to the
11582.B .
11583builtin command
11584.IP \(bu
495aee44 11585specifying a filename containing a slash as an argument to the
8868edaf
CR
11586.B history
11587builtin command
11588.IP \(bu
11589specifying a filename containing a slash as an argument to the
bb70624e
JA
11590.B \-p
11591option to the
11592.B hash
11593builtin command
11594.IP \(bu
ccc6cda3
JA
11595importing function definitions from the shell environment at startup
11596.IP \(bu
0001803f
CR
11597parsing the value of
11598.SM
11599.B SHELLOPTS
11600from the shell environment at startup
cce855bc 11601.IP \(bu
ccc6cda3
JA
11602redirecting output using the >, >|, <>, >&, &>, and >> redirection operators
11603.IP \(bu
11604using the
11605.B exec
11606builtin command to replace the shell with another command
11607.IP \(bu
11608adding or deleting builtin commands with the
11609.B \-f
726f6388 11610and
ccc6cda3
JA
11611.B \-d
11612options to the
11613.B enable
11614builtin command
11615.IP \(bu
495aee44 11616using the \fBenable\fP builtin command to enable disabled shell builtins
7117c2d2 11617.IP \(bu
ccc6cda3
JA
11618specifying the
11619.B \-p
11620option to the
11621.B command
11622builtin command
11623.IP \(bu
11624turning off restricted mode with
74091dd4 11625\fBset +r\fP or \fBshopt -u restricted_shell\fP.
726f6388 11626.PP
ccc6cda3
JA
11627These restrictions are enforced after any startup files are read.
11628.PP
b80f6443
JA
11629.ie \n(zY=1 When a command that is found to be a shell script is executed,
11630.el \{ When a command that is found to be a shell script is executed
11631(see
ccc6cda3
JA
11632.SM
11633.B "COMMAND EXECUTION"
11634above),
b80f6443 11635\}
ccc6cda3
JA
11636.B rbash
11637turns off any restrictions in the shell spawned to execute the
11638script.
bb70624e
JA
11639.\" end of rbash.1
11640.if \n(zY=1 .ig zY
726f6388
JA
11641.SH "SEE ALSO"
11642.PD 0
11643.TP
bb70624e 11644\fIBash Reference Manual\fP, Brian Fox and Chet Ramey
726f6388
JA
11645.TP
11646\fIThe Gnu Readline Library\fP, Brian Fox and Chet Ramey
11647.TP
11648\fIThe Gnu History Library\fP, Brian Fox and Chet Ramey
11649.TP
ac50fbac
CR
11650\fIPortable Operating System Interface (POSIX) Part 2: Shell and Utilities\fP, IEEE --
11651http://pubs.opengroup.org/onlinepubs/9699919799/
11652.TP
11653http://tiswww.case.edu/~chet/bash/POSIX -- a description of posix mode
726f6388
JA
11654.TP
11655\fIsh\fP(1), \fIksh\fP(1), \fIcsh\fP(1)
11656.TP
11657\fIemacs\fP(1), \fIvi\fP(1)
11658.TP
11659\fIreadline\fP(3)
11660.PD
11661.SH FILES
11662.PD 0
11663.TP
11664.FN /bin/bash
11665The \fBbash\fP executable
11666.TP
11667.FN /etc/profile
11668The systemwide initialization file, executed for login shells
11669.TP
11670.FN ~/.bash_profile
11671The personal initialization file, executed for login shells
11672.TP
11673.FN ~/.bashrc
11674The individual per-interactive-shell startup file
11675.TP
b72432fd
JA
11676.FN ~/.bash_logout
11677The individual login shell cleanup file, executed when a login shell exits
11678.TP
74091dd4
CR
11679.FN ~/.bash_history
11680The default value of \fBHISTFILE\fP, the file in which bash saves the
11681command history
11682.TP
726f6388
JA
11683.FN ~/.inputrc
11684Individual \fIreadline\fP initialization file
11685.PD
11686.SH AUTHORS
ccc6cda3 11687Brian Fox, Free Software Foundation
726f6388 11688.br
bb70624e 11689bfox@gnu.org
726f6388
JA
11690.PP
11691Chet Ramey, Case Western Reserve University
11692.br
17345e5a 11693chet.ramey@case.edu
726f6388
JA
11694.SH BUG REPORTS
11695If you find a bug in
11696.B bash,
11697you should report it. But first, you should
11698make sure that it really is a bug, and that it appears in the latest
11699version of
b80f6443
JA
11700.BR bash .
11701The latest version is always available from
74091dd4
CR
11702\fIftp://ftp.gnu.org/pub/gnu/bash/\fP and
11703\fIhttp://git.savannah.gnu.org/cgit/bash.git/snapshot/bash-master.tar.gz\fP.
726f6388
JA
11704.PP
11705Once you have determined that a bug actually exists, use the
11706.I bashbug
11707command to submit a bug report.
d166f048 11708If you have a fix, you are encouraged to mail that as well!
726f6388 11709Suggestions and `philosophical' bug reports may be mailed
cce855bc 11710to \fIbug-bash@gnu.org\fP or posted to the Usenet
726f6388
JA
11711newsgroup
11712.BR gnu.bash.bug .
11713.PP
11714ALL bug reports should include:
11715.PP
11716.PD 0
11717.TP 20
11718The version number of \fBbash\fR
11719.TP
11720The hardware and operating system
11721.TP
11722The compiler used to compile
11723.TP
11724A description of the bug behaviour
11725.TP
11726A short script or `recipe' which exercises the bug
11727.PD
11728.PP
11729.I bashbug
11730inserts the first three items automatically into the template
11731it provides for filing a bug report.
11732.PP
11733Comments and bug reports concerning
11734this manual page should be directed to
495aee44 11735.IR chet.ramey@case.edu .
726f6388 11736.SH BUGS
726f6388
JA
11737It's too big and too slow.
11738.PP
a0c0a00f 11739There are some subtle differences between
726f6388
JA
11740.B bash
11741and traditional versions of
11742.BR sh ,
11743mostly because of the
11744.SM
11745.B POSIX
11746specification.
11747.PP
11748Aliases are confusing in some uses.
ccc6cda3
JA
11749.PP
11750Shell builtin commands and functions are not stoppable/restartable.
11751.PP
11752Compound commands and command sequences of the form `a ; b ; c'
11753are not handled gracefully when process suspension is attempted.
11754When a process is stopped, the shell immediately executes the next
11755command in the sequence.
11756It suffices to place the sequence of commands between
11757parentheses to force it into a subshell, which may be stopped as
11758a unit.
11759.PP
ccc6cda3 11760Array variables may not (yet) be exported.
3185942a
JA
11761.PP
11762There may be only one active coprocess at a time.
726f6388 11763.zZ
bb70624e 11764.zY