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