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