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