]> git.ipfire.org Git - thirdparty/bash.git/blame - doc/bash.1
bash-20120224 remove leftover and stray files
[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.\"
abe2eb5b 8.\" Last Change: Sat Feb 4 17:32:13 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
abe2eb5b 13.TH BASH 1 "2012 February 4" "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
abe2eb5b
CR
5286.B keyseq\-timeout (500)
5287Specifies the duration \fIreadline\fP will wait for a character when reading an
5288ambiguous key sequence (one that can form a complete key sequence using
5289the input read so far, or can take additional input to complete a longer
5290key sequence).
5291If no input is received within the timeout, \fIreadline\fP will use the shorter
5292but complete key sequence.
5293The value is specified in milliseconds, so a value of 1000 means that
5294\fIreadline\fP will wait one second for additional input.
5295If this variable is set to a value less than or equal to zero, or to a
5296non-numeric value, \fIreadline\fP will wait until another key is pressed to
5297decide which key sequence to complete.
5298.TP
ccc6cda3
JA
5299.B mark\-directories (On)
5300If set to \fBOn\fP, completed directory names have a slash
5301appended.
5302.TP
5303.B mark\-modified\-lines (Off)
5304If set to \fBOn\fP, history lines that have been modified are displayed
5305with a preceding asterisk (\fB*\fP).
5306.TP
7117c2d2
JA
5307.B mark\-symlinked\-directories (Off)
5308If set to \fBOn\fP, completed names which are symbolic links to directories
5309have a slash appended (subject to the value of
5310\fBmark\-directories\fP).
5311.TP
f73dda09
JA
5312.B match\-hidden\-files (On)
5313This variable, when set to \fBOn\fP, causes readline to match files whose
5314names begin with a `.' (hidden files) when performing filename
112ff2a6
CR
5315completion.
5316If set to \fBOff\fP, the leading `.' must be
f73dda09
JA
5317supplied by the user in the filename to be completed.
5318.TP
d7c725b5
CR
5319.B menu\-complete\-display\-prefix (Off)
5320If set to \fBOn\fP, menu completion displays the common prefix of the
5321list of possible completions (which may be empty) before cycling through
5322the list.
5323.TP
ccc6cda3
JA
5324.B output\-meta (Off)
5325If set to \fBOn\fP, readline will display characters with the
5326eighth bit set directly rather than as a meta-prefixed escape
5327sequence.
5328.TP
7117c2d2
JA
5329.B page\-completions (On)
5330If set to \fBOn\fP, readline uses an internal \fImore\fP-like pager
5331to display a screenful of possible completions at a time.
5332.TP
cce855bc
JA
5333.B print\-completions\-horizontally (Off)
5334If set to \fBOn\fP, readline will display completions with matches
5335sorted horizontally in alphabetical order, rather than down the screen.
f13513ff
CR
5336.TP
5337.B revert\-all\-at\-newline (Off)
dc60d4e0 5338If set to \fBOn\fP, readline will undo all changes to history lines
f13513ff
CR
5339before returning when \fBaccept\-line\fP is executed. By default,
5340history lines may be modified and retain individual undo lists across
5341calls to \fBreadline\fP.
cce855bc 5342.TP
726f6388
JA
5343.B show\-all\-if\-ambiguous (Off)
5344This alters the default behavior of the completion functions. If
5345set to
dc60d4e0 5346.BR On ,
726f6388
JA
5347words which have more than one possible completion cause the
5348matches to be listed immediately instead of ringing the bell.
5349.TP
d3a24ed2
CR
5350.B show\-all\-if\-unmodified (Off)
5351This alters the default behavior of the completion functions in
5352a fashion similar to \fBshow\-all\-if\-ambiguous\fP.
5353If set to
dc60d4e0 5354.BR On ,
d3a24ed2
CR
5355words which have more than one possible completion without any
5356possible partial completion (the possible completions don't share
5357a common prefix) cause the matches to be listed immediately instead
5358of ringing the bell.
5359.TP
8f714a7c
CR
5360.B skip\-completed\-text (Off)
5361If set to \fBOn\fP, this alters the default completion behavior when
5362inserting a single match into the line. It's only active when
5363performing completion in the middle of a word. If enabled, readline
5364does not insert characters from the completion that match characters
5365after point in the word being completed, so portions of the word
5366following the cursor are not duplicated.
5367.TP
ccc6cda3
JA
5368.B visible\-stats (Off)
5369If set to \fBOn\fP, a character denoting a file's type as reported
5370by \fIstat\fP(2) is appended to the filename when listing possible
5371completions.
726f6388 5372.PD
ccc6cda3 5373.SS "Readline Conditional Constructs"
726f6388
JA
5374.PP
5375Readline implements a facility similar in spirit to the conditional
5376compilation features of the C preprocessor which allows key
5377bindings and variable settings to be performed as the result
cce855bc 5378of tests. There are four parser directives used.
726f6388
JA
5379.IP \fB$if\fP
5380The
5381.B $if
5382construct allows bindings to be made based on the
5383editing mode, the terminal being used, or the application using
5384readline. The text of the test extends to the end of the line;
5385no characters are required to isolate it.
5386.RS
5387.IP \fBmode\fP
5388The \fBmode=\fP form of the \fB$if\fP directive is used to test
5389whether readline is in emacs or vi mode.
5390This may be used in conjunction
5391with the \fBset keymap\fP command, for instance, to set bindings in
ccc6cda3 5392the \fIemacs\-standard\fP and \fIemacs\-ctlx\fP keymaps only if
726f6388
JA
5393readline is starting out in emacs mode.
5394.IP \fBterm\fP
5395The \fBterm=\fP form may be used to include terminal-specific
5396key bindings, perhaps to bind the key sequences output by the
5397terminal's function keys. The word on the right side of the
5398.B =
cce855bc 5399is tested against the both full name of the terminal and the portion
726f6388
JA
5400of the terminal name before the first \fB\-\fP. This allows
5401.I sun
5402to match both
5403.I sun
5404and
5405.IR sun\-cmd ,
5406for instance.
5407.IP \fBapplication\fP
5408The \fBapplication\fP construct is used to include
ccc6cda3 5409application-specific settings. Each program using the readline
726f6388
JA
5410library sets the \fIapplication name\fP, and an initialization
5411file can test for a particular value.
5412This could be used to bind key sequences to functions useful for
5413a specific program. For instance, the following command adds a
dc60d4e0 5414key sequence that quotes the current or previous word in \fBbash\fP:
cce855bc 5415.sp 1
726f6388
JA
5416.RS
5417.nf
5418\fB$if\fP Bash
5419# Quote the current or previous word
ccc6cda3 5420"\eC\-xq": "\eeb\e"\eef\e""
726f6388
JA
5421\fB$endif\fP
5422.fi
5423.RE
5424.RE
5425.IP \fB$endif\fP
cce855bc 5426This command, as seen in the previous example, terminates an
726f6388
JA
5427\fB$if\fP command.
5428.IP \fB$else\fP
5429Commands in this branch of the \fB$if\fP directive are executed if
5430the test fails.
cce855bc
JA
5431.IP \fB$include\fP
5432This directive takes a single filename as an argument and reads commands
5433and bindings from that file. For example, the following directive
5434would read \fI/etc/inputrc\fP:
5435.sp 1
5436.RS
5437.nf
5438\fB$include\fP \^ \fI/etc/inputrc\fP
5439.fi
5440.RE
ccc6cda3 5441.SS Searching
726f6388 5442.PP
ccc6cda3
JA
5443Readline provides commands for searching through the command history
5444(see
5445.SM
5446.B HISTORY
5447below) for lines containing a specified string.
5448There are two search modes:
5449.I incremental
5450and
5451.IR non-incremental .
5452.PP
5453Incremental searches begin before the user has finished typing the
5454search string.
5455As each character of the search string is typed, readline displays
5456the next entry from the history matching the string typed so far.
5457An incremental search requires only as many characters as needed to
5458find the desired history entry.
bb70624e 5459The characters present in the value of the \fBisearch-terminators\fP
b72432fd
JA
5460variable are used to terminate an incremental search.
5461If that variable has not been assigned a value the Escape and
5462Control-J characters will terminate an incremental search.
ccc6cda3
JA
5463Control-G will abort an incremental search and restore the original
5464line.
5465When the search is terminated, the history entry containing the
5466search string becomes the current line.
bb70624e 5467.PP
ccc6cda3
JA
5468To find other matching entries in the history list, type Control-S or
5469Control-R as appropriate.
5470This will search backward or forward in the history for the next
5471entry matching the search string typed so far.
5472Any other key sequence bound to a readline command will terminate
5473the search and execute that command.
5474For instance, a \fInewline\fP will terminate the search and accept
5475the line, thereby executing the command from the history list.
5476.PP
f73dda09
JA
5477Readline remembers the last incremental search string. If two
5478Control-Rs are typed without any intervening characters defining a
5479new search string, any remembered search string is used.
5480.PP
ccc6cda3
JA
5481Non-incremental searches read the entire search string before starting
5482to search for matching history lines. The search string may be
cce855bc 5483typed by the user or be part of the contents of the current line.
ccc6cda3 5484.SS "Readline Command Names"
726f6388
JA
5485.PP
5486The following is a list of the names of the commands and the default
5487key sequences to which they are bound.
ccc6cda3 5488Command names without an accompanying key sequence are unbound by default.
bb70624e
JA
5489In the following descriptions, \fIpoint\fP refers to the current cursor
5490position, and \fImark\fP refers to a cursor position saved by the
5491\fBset\-mark\fP command.
5492The text between the point and mark is referred to as the \fIregion\fP.
726f6388
JA
5493.SS Commands for Moving
5494.PP
5495.PD 0
5496.TP
5497.B beginning\-of\-line (C\-a)
5498Move to the start of the current line.
5499.TP
5500.B end\-of\-line (C\-e)
5501Move to the end of the line.
5502.TP
5503.B forward\-char (C\-f)
5504Move forward a character.
5505.TP
5506.B backward\-char (C\-b)
5507Move back a character.
5508.TP
5509.B forward\-word (M\-f)
5510Move forward to the end of the next word. Words are composed of
5511alphanumeric characters (letters and digits).
5512.TP
5513.B backward\-word (M\-b)
8c2fef19
CR
5514Move back to the start of the current or previous word.
5515Words are composed of alphanumeric characters (letters and digits).
5516.TP
5517.B shell\-forward\-word
5518Move forward to the end of the next word.
5519Words are delimited by non-quoted shell metacharacters.
5520.TP
5521.B shell\-backward\-word
5522Move back to the start of the current or previous word.
5523Words are delimited by non-quoted shell metacharacters.
726f6388
JA
5524.TP
5525.B clear\-screen (C\-l)
5526Clear the screen leaving the current line at the top of the screen.
5527With an argument, refresh the current line without clearing the
5528screen.
5529.TP
5530.B redraw\-current\-line
ccc6cda3 5531Refresh the current line.
726f6388
JA
5532.PD
5533.SS Commands for Manipulating the History
5534.PP
5535.PD 0
5536.TP
5537.B accept\-line (Newline, Return)
5538Accept the line regardless of where the cursor is. If this line is
ccc6cda3 5539non-empty, add it to the history list according to the state of the
726f6388
JA
5540.SM
5541.B HISTCONTROL
5542variable. If the line is a modified history
5543line, then restore the history line to its original state.
5544.TP
5545.B previous\-history (C\-p)
5546Fetch the previous command from the history list, moving back in
5547the list.
5548.TP
5549.B next\-history (C\-n)
5550Fetch the next command from the history list, moving forward in the
5551list.
5552.TP
5553.B beginning\-of\-history (M\-<)
5554Move to the first line in the history.
5555.TP
5556.B end\-of\-history (M\->)
5557Move to the end of the input history, i.e., the line currently being
5558entered.
5559.TP
5560.B reverse\-search\-history (C\-r)
5561Search backward starting at the current line and moving `up' through
5562the history as necessary. This is an incremental search.
5563.TP
5564.B forward\-search\-history (C\-s)
5565Search forward starting at the current line and moving `down' through
5566the history as necessary. This is an incremental search.
5567.TP
5568.B non\-incremental\-reverse\-search\-history (M\-p)
5569Search backward through the history starting at the current line
ccc6cda3 5570using a non-incremental search for a string supplied by the user.
726f6388
JA
5571.TP
5572.B non\-incremental\-forward\-search\-history (M\-n)
ccc6cda3 5573Search forward through the history using a non-incremental search for
726f6388
JA
5574a string supplied by the user.
5575.TP
5576.B history\-search\-forward
5577Search forward through the history for the string of characters
bb70624e 5578between the start of the current line and the point.
ccc6cda3 5579This is a non-incremental search.
726f6388
JA
5580.TP
5581.B history\-search\-backward
5582Search backward through the history for the string of characters
ccc6cda3
JA
5583between the start of the current line and the point.
5584This is a non-incremental search.
726f6388
JA
5585.TP
5586.B yank\-nth\-arg (M\-C\-y)
5587Insert the first argument to the previous command (usually
28ef6c31
JA
5588the second word on the previous line) at point.
5589With an argument
726f6388
JA
5590.IR n ,
5591insert the \fIn\fPth word from the previous command (the words
5592in the previous command begin with word 0). A negative argument
5593inserts the \fIn\fPth word from the end of the previous command.
eb2bb562
CR
5594Once the argument \fIn\fP is computed, the argument is extracted
5595as if the "!\fIn\fP" history expansion had been specified.
726f6388
JA
5596.TP
5597.B
5598yank\-last\-arg (M\-.\^, M\-_\^)
ccc6cda3 5599Insert the last argument to the previous command (the last word of
adc6cff5
CR
5600the previous history entry).
5601With a numeric argument, behave exactly like \fByank\-nth\-arg\fP.
cce855bc 5602Successive calls to \fByank\-last\-arg\fP move back through the history
adc6cff5
CR
5603list, inserting the last word (or the word specified by the argument to
5604the first call) of each line in turn.
5605Any numeric argument supplied to these successive calls determines
5606the direction to move through the history. A negative argument switches
5607the direction through the history (back or forward).
eb2bb562
CR
5608The history expansion facilities are used to extract the last argument,
5609as if the "!$" history expansion had been specified.
726f6388
JA
5610.TP
5611.B shell\-expand\-line (M\-C\-e)
cce855bc 5612Expand the line as the shell does. This
726f6388
JA
5613performs alias and history expansion as well as all of the shell
5614word expansions. See
5615.SM
5616.B HISTORY EXPANSION
5617below for a description of history expansion.
5618.TP
5619.B history\-expand\-line (M\-^)
d166f048
JA
5620Perform history expansion on the current line.
5621See
726f6388
JA
5622.SM
5623.B HISTORY EXPANSION
5624below for a description of history expansion.
5625.TP
cce855bc
JA
5626.B magic\-space
5627Perform history expansion on the current line and insert a space.
5628See
5629.SM
5630.B HISTORY EXPANSION
5631below for a description of history expansion.
5632.TP
d166f048
JA
5633.B alias\-expand\-line
5634Perform alias expansion on the current line.
5635See
5636.SM
5637.B ALIASES
5638above for a description of alias expansion.
5639.TP
5640.B history\-and\-alias\-expand\-line
5641Perform history and alias expansion on the current line.
5642.TP
726f6388
JA
5643.B insert\-last\-argument (M\-.\^, M\-_\^)
5644A synonym for \fByank\-last\-arg\fP.
5645.TP
ccc6cda3 5646.B operate\-and\-get\-next (C\-o)
726f6388
JA
5647Accept the current line for execution and fetch the next line
5648relative to the current line from the history for editing. Any
5649argument is ignored.
7117c2d2
JA
5650.TP
5651.B edit\-and\-execute\-command (C\-xC\-e)
5652Invoke an editor on the current command line, and execute the result as shell
5653commands.
5654\fBBash\fP attempts to invoke
5655.SM
dd4f3dd8 5656.BR $VISUAL ,
7117c2d2
JA
5657.SM
5658.BR $EDITOR ,
5659and \fIemacs\fP as the editor, in that order.
726f6388
JA
5660.PD
5661.SS Commands for Changing Text
5662.PP
5663.PD 0
5664.TP
5665.B delete\-char (C\-d)
28ef6c31 5666Delete the character at point. If point is at the
726f6388 5667beginning of the line, there are no characters in the line, and
cce855bc 5668the last character typed was not bound to \fBdelete\-char\fP,
726f6388
JA
5669then return
5670.SM
5671.BR EOF .
5672.TP
5673.B backward\-delete\-char (Rubout)
5674Delete the character behind the cursor. When given a numeric argument,
ccc6cda3 5675save the deleted text on the kill ring.
726f6388 5676.TP
b72432fd
JA
5677.B forward\-backward\-delete\-char
5678Delete the character under the cursor, unless the cursor is at the
5679end of the line, in which case the character behind the cursor is
f73dda09 5680deleted.
b72432fd 5681.TP
726f6388 5682.B quoted\-insert (C\-q, C\-v)
cce855bc 5683Add the next character typed to the line verbatim. This is
726f6388
JA
5684how to insert characters like \fBC\-q\fP, for example.
5685.TP
ccc6cda3 5686.B tab\-insert (C\-v TAB)
726f6388
JA
5687Insert a tab character.
5688.TP
5689.B self\-insert (a,\ b,\ A,\ 1,\ !,\ ...)
5690Insert the character typed.
5691.TP
5692.B transpose\-chars (C\-t)
28ef6c31
JA
5693Drag the character before point forward over the character at point,
5694moving point forward as well.
5695If point is at the end of the line, then this transposes
5696the two characters before point.
bb70624e 5697Negative arguments have no effect.
726f6388
JA
5698.TP
5699.B transpose\-words (M\-t)
bb70624e 5700Drag the word before point past the word after point,
28ef6c31 5701moving point over that word as well.
f73dda09
JA
5702If point is at the end of the line, this transposes
5703the last two words on the line.
726f6388
JA
5704.TP
5705.B upcase\-word (M\-u)
5706Uppercase the current (or following) word. With a negative argument,
cce855bc 5707uppercase the previous word, but do not move point.
726f6388
JA
5708.TP
5709.B downcase\-word (M\-l)
5710Lowercase the current (or following) word. With a negative argument,
cce855bc 5711lowercase the previous word, but do not move point.
726f6388
JA
5712.TP
5713.B capitalize\-word (M\-c)
5714Capitalize the current (or following) word. With a negative argument,
cce855bc 5715capitalize the previous word, but do not move point.
7117c2d2
JA
5716.TP
5717.B overwrite\-mode
5718Toggle overwrite mode. With an explicit positive numeric argument,
5719switches to overwrite mode. With an explicit non-positive numeric
5720argument, switches to insert mode. This command affects only
5721\fBemacs\fP mode; \fBvi\fP mode does overwrite differently.
5722Each call to \fIreadline()\fP starts in insert mode.
5723In overwrite mode, characters bound to \fBself\-insert\fP replace
5724the text at point rather than pushing the text to the right.
5725Characters bound to \fBbackward\-delete\-char\fP replace the character
5726before point with a space. By default, this command is unbound.
726f6388
JA
5727.PD
5728.SS Killing and Yanking
5729.PP
5730.PD 0
5731.TP
5732.B kill\-line (C\-k)
bb70624e 5733Kill the text from point to the end of the line.
726f6388 5734.TP
ccc6cda3 5735.B backward\-kill\-line (C\-x Rubout)
726f6388
JA
5736Kill backward to the beginning of the line.
5737.TP
5738.B unix\-line\-discard (C\-u)
5739Kill backward from point to the beginning of the line.
cce855bc 5740The killed text is saved on the kill-ring.
bb70624e 5741.\" There is no real difference between this and backward-kill-line
726f6388
JA
5742.TP
5743.B kill\-whole\-line
bb70624e 5744Kill all characters on the current line, no matter where point is.
726f6388
JA
5745.TP
5746.B kill\-word (M\-d)
bb70624e
JA
5747Kill from point to the end of the current word, or if between
5748words, to the end of the next word.
5749Word boundaries are the same as those used by \fBforward\-word\fP.
726f6388
JA
5750.TP
5751.B backward\-kill\-word (M\-Rubout)
bb70624e
JA
5752Kill the word behind point.
5753Word boundaries are the same as those used by \fBbackward\-word\fP.
726f6388 5754.TP
8c2fef19
CR
5755.B shell\-kill\-word (M\-d)
5756Kill from point to the end of the current word, or if between
5757words, to the end of the next word.
5758Word boundaries are the same as those used by \fBshell\-forward\-word\fP.
5759.TP
5760.B shell\-backward\-kill\-word (M\-Rubout)
5761Kill the word behind point.
5762Word boundaries are the same as those used by \fBshell\-backward\-word\fP.
5763.TP
726f6388 5764.B unix\-word\-rubout (C\-w)
bb70624e 5765Kill the word behind point, using white space as a word boundary.
bb70624e 5766The killed text is saved on the kill-ring.
113d85a4
CR
5767.TP
5768.B unix\-filename\-rubout
5769Kill the word behind point, using white space and the slash character
5770as the word boundaries.
5771The killed text is saved on the kill-ring.
ccc6cda3
JA
5772.TP
5773.B delete\-horizontal\-space (M\-\e)
5774Delete all spaces and tabs around point.
5775.TP
5776.B kill\-region
bb70624e 5777Kill the text in the current region.
ccc6cda3
JA
5778.TP
5779.B copy\-region\-as\-kill
5780Copy the text in the region to the kill buffer.
726f6388 5781.TP
ccc6cda3
JA
5782.B copy\-backward\-word
5783Copy the word before point to the kill buffer.
cce855bc 5784The word boundaries are the same as \fBbackward\-word\fP.
ccc6cda3
JA
5785.TP
5786.B copy\-forward\-word
5787Copy the word following point to the kill buffer.
cce855bc 5788The word boundaries are the same as \fBforward\-word\fP.
726f6388
JA
5789.TP
5790.B yank (C\-y)
28ef6c31 5791Yank the top of the kill ring into the buffer at point.
726f6388
JA
5792.TP
5793.B yank\-pop (M\-y)
ccc6cda3 5794Rotate the kill ring, and yank the new top. Only works following
726f6388
JA
5795.B yank
5796or
5797.BR yank\-pop .
5798.PD
5799.SS Numeric Arguments
5800.PP
5801.PD 0
5802.TP
5803.B digit\-argument (M\-0, M\-1, ..., M\-\-)
5804Add this digit to the argument already accumulating, or start a new
5805argument. M\-\- starts a negative argument.
5806.TP
5807.B universal\-argument
d166f048
JA
5808This is another way to specify an argument.
5809If this command is followed by one or more digits, optionally with a
5810leading minus sign, those digits define the argument.
5811If the command is followed by digits, executing
5812.B universal\-argument
5813again ends the numeric argument, but is otherwise ignored.
5814As a special case, if this command is immediately followed by a
5815character that is neither a digit or minus sign, the argument count
5816for the next command is multiplied by four.
726f6388 5817The argument count is initially one, so executing this function the
d166f048
JA
5818first time makes the argument count four, a second time makes the
5819argument count sixteen, and so on.
726f6388
JA
5820.PD
5821.SS Completing
5822.PP
5823.PD 0
5824.TP
5825.B complete (TAB)
5826Attempt to perform completion on the text before point.
5827.B Bash
5828attempts completion treating the text as a variable (if the
5829text begins with \fB$\fP), username (if the text begins with
5830\fB~\fP), hostname (if the text begins with \fB@\fP), or
5831command (including aliases and functions) in turn. If none
5832of these produces a match, filename completion is attempted.
5833.TP
ccc6cda3 5834.B possible\-completions (M\-?)
726f6388
JA
5835List the possible completions of the text before point.
5836.TP
ccc6cda3 5837.B insert\-completions (M\-*)
726f6388
JA
5838Insert all completions of the text before point
5839that would have been generated by
ccc6cda3 5840\fBpossible\-completions\fP.
726f6388 5841.TP
cce855bc
JA
5842.B menu\-complete
5843Similar to \fBcomplete\fP, but replaces the word to be completed
5844with a single match from the list of possible completions.
5845Repeated execution of \fBmenu\-complete\fP steps through the list
5846of possible completions, inserting each match in turn.
28ef6c31 5847At the end of the list of completions, the bell is rung
f73dda09 5848(subject to the setting of \fBbell\-style\fP)
28ef6c31 5849and the original text is restored.
cce855bc
JA
5850An argument of \fIn\fP moves \fIn\fP positions forward in the list
5851of matches; a negative argument may be used to move backward
5852through the list.
5853This command is intended to be bound to \fBTAB\fP, but is unbound
5854by default.
5855.TP
dc60d4e0 5856.B menu\-complete\-backward
9dd88db7
CR
5857Identical to \fBmenu\-complete\fP, but moves backward through the list
5858of possible completions, as if \fBmenu\-complete\fP had been given a
5859negative argument. This command is unbound by default.
5860.TP
b72432fd
JA
5861.B delete\-char\-or\-list
5862Deletes the character under the cursor if not at the beginning or
bb70624e 5863end of the line (like \fBdelete\-char\fP).
b72432fd 5864If at the end of the line, behaves identically to
bb70624e 5865\fBpossible\-completions\fP.
b72432fd
JA
5866This command is unbound by default.
5867.TP
726f6388
JA
5868.B complete\-filename (M\-/)
5869Attempt filename completion on the text before point.
5870.TP
5871.B possible\-filename\-completions (C\-x /)
5872List the possible completions of the text before point,
5873treating it as a filename.
5874.TP
5875.B complete\-username (M\-~)
5876Attempt completion on the text before point, treating
5877it as a username.
5878.TP
5879.B possible\-username\-completions (C\-x ~)
5880List the possible completions of the text before point,
5881treating it as a username.
5882.TP
5883.B complete\-variable (M\-$)
5884Attempt completion on the text before point, treating
5885it as a shell variable.
5886.TP
5887.B possible\-variable\-completions (C\-x $)
5888List the possible completions of the text before point,
5889treating it as a shell variable.
5890.TP
5891.B complete\-hostname (M\-@)
5892Attempt completion on the text before point, treating
5893it as a hostname.
5894.TP
5895.B possible\-hostname\-completions (C\-x @)
5896List the possible completions of the text before point,
5897treating it as a hostname.
5898.TP
5899.B complete\-command (M\-!)
5900Attempt completion on the text before point, treating
5901it as a command name. Command completion attempts to
5902match the text against aliases, reserved words, shell
cce855bc 5903functions, shell builtins, and finally executable filenames,
726f6388
JA
5904in that order.
5905.TP
5906.B possible\-command\-completions (C\-x !)
5907List the possible completions of the text before point,
5908treating it as a command name.
5909.TP
ccc6cda3 5910.B dynamic\-complete\-history (M\-TAB)
726f6388
JA
5911Attempt completion on the text before point, comparing
5912the text against lines from the history list for possible
5913completion matches.
5914.TP
8943768b
CR
5915.B dabbrev\-expand
5916Attempt menu completion on the text before point, comparing
5917the text against lines from the history list for possible
5918completion matches.
5919.TP
726f6388 5920.B complete\-into\-braces (M\-{)
bb70624e 5921Perform filename completion and insert the list of possible completions
726f6388
JA
5922enclosed within braces so the list is available to the shell (see
5923.B Brace Expansion
5924above).
5925.PD
5926.SS Keyboard Macros
5927.PP
5928.PD 0
5929.TP
ccc6cda3 5930.B start\-kbd\-macro (C\-x (\^)
726f6388
JA
5931Begin saving the characters typed into the current keyboard macro.
5932.TP
ccc6cda3 5933.B end\-kbd\-macro (C\-x )\^)
726f6388 5934Stop saving the characters typed into the current keyboard macro
ccc6cda3 5935and store the definition.
726f6388 5936.TP
ccc6cda3 5937.B call\-last\-kbd\-macro (C\-x e)
726f6388
JA
5938Re-execute the last keyboard macro defined, by making the characters
5939in the macro appear as if typed at the keyboard.
ba4ab055
CR
5940.B print\-last\-kbd\-macro ()
5941Print the last keyboard macro defined in a format suitable for the
5942\fIinputrc\fP file.
726f6388
JA
5943.PD
5944.SS Miscellaneous
5945.PP
5946.PD 0
5947.TP
5948.B re\-read\-init\-file (C\-x C\-r)
ccc6cda3 5949Read in the contents of the \fIinputrc\fP file, and incorporate
726f6388
JA
5950any bindings or variable assignments found there.
5951.TP
5952.B abort (C\-g)
5953Abort the current editing command and
5954ring the terminal's bell (subject to the setting of
5955.BR bell\-style ).
5956.TP
ccc6cda3
JA
5957.B do\-uppercase\-version (M\-a, M\-b, M\-\fIx\fP, ...)
5958If the metafied character \fIx\fP is lowercase, run the command
5959that is bound to the corresponding uppercase character.
726f6388
JA
5960.TP
5961.B prefix\-meta (ESC)
5962Metafy the next character typed.
5963.SM
5964.B ESC
5965.B f
5966is equivalent to
5967.BR Meta\-f .
5968.TP
5969.B undo (C\-_, C\-x C\-u)
5970Incremental undo, separately remembered for each line.
5971.TP
5972.B revert\-line (M\-r)
cce855bc 5973Undo all changes made to this line. This is like executing the
726f6388
JA
5974.B undo
5975command enough times to return the line to its initial state.
5976.TP
b72432fd 5977.B tilde\-expand (M\-&)
726f6388
JA
5978Perform tilde expansion on the current word.
5979.TP
ccc6cda3 5980.B set\-mark (C\-@, M\-<space>)
28ef6c31 5981Set the mark to the point. If a
ccc6cda3
JA
5982numeric argument is supplied, the mark is set to that position.
5983.TP
5984.B exchange\-point\-and\-mark (C\-x C\-x)
5985Swap the point with the mark. The current cursor position is set to
5986the saved position, and the old cursor position is saved as the mark.
5987.TP
5988.B character\-search (C\-])
5989A character is read and point is moved to the next occurrence of that
5990character. A negative count searches for previous occurrences.
5991.TP
5992.B character\-search\-backward (M\-C\-])
5993A character is read and point is moved to the previous occurrence of that
5994character. A negative count searches for subsequent occurrences.
5995.TP
dc60d4e0 5996.B skip\-csi\-sequence
691aebcb
CR
5997Read enough characters to consume a multi-key sequence such as those
5998defined for keys like Home and End. Such sequences begin with a
5999Control Sequence Indicator (CSI), usually ESC\-[. If this sequence is
6000bound to "\e[", keys producing such sequences will have no effect
6001unless explicitly bound to a readline command, instead of inserting
6002stray characters into the editing buffer. This is unbound by default,
6003but usually bound to ESC\-[.
6004.TP
ccc6cda3 6005.B insert\-comment (M\-#)
7117c2d2 6006Without a numeric argument, the value of the readline
ccc6cda3 6007.B comment\-begin
7117c2d2
JA
6008variable is inserted at the beginning of the current line.
6009If a numeric argument is supplied, this command acts as a toggle: if
6010the characters at the beginning of the line do not match the value
6011of \fBcomment\-begin\fP, the value is inserted, otherwise
db31fb26 6012the characters in \fBcomment\-begin\fP are deleted from the beginning of
7117c2d2
JA
6013the line.
6014In either case, the line is accepted as if a newline had been typed.
6015The default value of
bb70624e 6016\fBcomment\-begin\fP causes this command to make the current line
ccc6cda3 6017a shell comment.
7117c2d2
JA
6018If a numeric argument causes the comment character to be removed, the line
6019will be executed by the shell.
6020.TP
6021.B glob\-complete\-word (M\-g)
6022The word before point is treated as a pattern for pathname expansion,
6023with an asterisk implicitly appended. This pattern is used to
b28ff8c9 6024generate a list of matching filenames for possible completions.
ccc6cda3
JA
6025.TP
6026.B glob\-expand\-word (C\-x *)
6027The word before point is treated as a pattern for pathname expansion,
b28ff8c9 6028and the list of matching filenames is inserted, replacing the word.
7117c2d2
JA
6029If a numeric argument is supplied, an asterisk is appended before
6030pathname expansion.
ccc6cda3
JA
6031.TP
6032.B glob\-list\-expansions (C\-x g)
6033The list of expansions that would have been generated by
6034.B glob\-expand\-word
6035is displayed, and the line is redrawn.
7117c2d2
JA
6036If a numeric argument is supplied, an asterisk is appended before
6037pathname expansion.
ccc6cda3 6038.TP
726f6388
JA
6039.B dump\-functions
6040Print all of the functions and their key bindings to the
6041readline output stream. If a numeric argument is supplied,
6042the output is formatted in such a way that it can be made part
6043of an \fIinputrc\fP file.
6044.TP
ccc6cda3
JA
6045.B dump\-variables
6046Print all of the settable readline variables and their values to the
6047readline output stream. If a numeric argument is supplied,
6048the output is formatted in such a way that it can be made part
6049of an \fIinputrc\fP file.
6050.TP
6051.B dump\-macros
6052Print all of the readline key sequences bound to macros and the
22e63b05 6053strings they output. If a numeric argument is supplied,
ccc6cda3
JA
6054the output is formatted in such a way that it can be made part
6055of an \fIinputrc\fP file.
6056.TP
726f6388
JA
6057.B display\-shell\-version (C\-x C\-v)
6058Display version information about the current instance of
6059.BR bash .
6060.PD
bb70624e
JA
6061.SS Programmable Completion
6062.PP
6063When word completion is attempted for an argument to a command for
6064which a completion specification (a \fIcompspec\fP) has been defined
6065using the \fBcomplete\fP builtin (see
6066.SM
6067.B "SHELL BUILTIN COMMANDS"
6068below), the programmable completion facilities are invoked.
6069.PP
6070First, the command name is identified.
3eb2d94a
CR
6071If the command word is the empty string (completion attempted at the
6072beginning of an empty line), any compspec defined with
6073the \fB\-E\fP option to \fBcomplete\fP is used.
bb70624e
JA
6074If a compspec has been defined for that command, the
6075compspec is used to generate the list of possible completions for the word.
6076If the command word is a full pathname, a compspec for the full
6077pathname is searched for first.
6078If no compspec is found for the full pathname, an attempt is made to
6079find a compspec for the portion following the final slash.
dc60d4e0 6080If those searches do not result in a compspec, any compspec defined with
3eb2d94a 6081the \fB\-D\fP option to \fBcomplete\fP is used as the default.
bb70624e
JA
6082.PP
6083Once a compspec has been found, it is used to generate the list of
6084matching words.
6085If a compspec is not found, the default \fBbash\fP completion as
6086described above under \fBCompleting\fP is performed.
6087.PP
6088First, the actions specified by the compspec are used.
6089Only matches which are prefixed by the word being completed are
6090returned.
6091When the
6092.B \-f
6093or
6094.B \-d
6095option is used for filename or directory name completion, the shell
6096variable
6097.SM
6098.B FIGNORE
6099is used to filter the matches.
6100.PP
d0ca3503 6101Any completions specified by a pathname expansion pattern to the
bb70624e
JA
6102\fB\-G\fP option are generated next.
6103The words generated by the pattern need not match the word
6104being completed.
6105The
6106.SM
6107.B GLOBIGNORE
6108shell variable is not used to filter the matches, but the
6109.SM
6110.B FIGNORE
6111variable is used.
6112.PP
6113Next, the string specified as the argument to the \fB\-W\fP option
6114is considered.
6115The string is first split using the characters in the
6116.SM
6117.B IFS
6118special variable as delimiters.
6119Shell quoting is honored.
6120Each word is then expanded using
6121brace expansion, tilde expansion, parameter and variable expansion,
6e70dbff 6122command substitution, and arithmetic expansion,
bb70624e
JA
6123as described above under
6124.SM
6125.BR EXPANSION .
6126The results are split using the rules described above under
6127\fBWord Splitting\fP.
6128The results of the expansion are prefix-matched against the word being
6129completed, and the matching words become the possible completions.
6130.PP
6131After these matches have been generated, any shell function or command
6132specified with the \fB\-F\fP and \fB\-C\fP options is invoked.
6133When the command or function is invoked, the
6134.SM
d3ad40de
CR
6135.BR COMP_LINE ,
6136.SM
6137.BR COMP_POINT ,
6138.SM
6139.BR COMP_KEY ,
bb70624e
JA
6140and
6141.SM
d3ad40de 6142.B COMP_TYPE
bb70624e
JA
6143variables are assigned values as described above under
6144\fBShell Variables\fP.
6145If a shell function is being invoked, the
6146.SM
6147.B COMP_WORDS
6148and
6149.SM
6150.B COMP_CWORD
6151variables are also set.
ba4ab055
CR
6152When the function or command is invoked,
6153the first argument (\fB$1\fP) is the name of the command whose arguments are
6154being completed,
6155the second argument (\fB$2\fP) is the word being completed,
6156and the third argument (\fB$3\fP) is the word preceding the word being
6157completed on the current command line.
bb70624e
JA
6158No filtering of the generated completions against the word being completed
6159is performed; the function or command has complete freedom in generating
6160the matches.
6161.PP
6162Any function specified with \fB\-F\fP is invoked first.
6163The function may use any of the shell facilities, including the
6164\fBcompgen\fP builtin described below, to generate the matches.
6165It must put the possible completions in the
6166.SM
6167.B COMPREPLY
ba4ab055 6168array variable, one per array element.
bb70624e
JA
6169.PP
6170Next, any command specified with the \fB\-C\fP option is invoked
6171in an environment equivalent to command substitution.
6172It should print a list of completions, one per line, to the
6173standard output.
6174Backslash may be used to escape a newline, if necessary.
6175.PP
6176After all of the possible completions are generated, any filter
6177specified with the \fB\-X\fP option is applied to the list.
6178The filter is a pattern as used for pathname expansion; a \fB&\fP
6179in the pattern is replaced with the text of the word being completed.
6180A literal \fB&\fP may be escaped with a backslash; the backslash
6181is removed before attempting a match.
6182Any completion that matches the pattern will be removed from the list.
6183A leading \fB!\fP negates the pattern; in this case any completion
6184not matching the pattern will be removed.
6185.PP
6186Finally, any prefix and suffix specified with the \fB\-P\fP and \fB\-S\fP
6187options are added to each member of the completion list, and the result is
6188returned to the readline completion code as the list of possible
6189completions.
6190.PP
28ef6c31
JA
6191If the previously-applied actions do not generate any matches, and the
6192\fB\-o dirnames\fP option was supplied to \fBcomplete\fP when the
6193compspec was defined, directory name completion is attempted.
6194.PP
d3a24ed2
CR
6195If the \fB\-o plusdirs\fP option was supplied to \fBcomplete\fP when the
6196compspec was defined, directory name completion is attempted and any
6197matches are added to the results of the other actions.
6198.PP
28ef6c31
JA
6199By default, if a compspec is found, whatever it generates is returned
6200to the completion code as the full set of possible completions.
bb70624e
JA
6201The default \fBbash\fP completions are not attempted, and the readline
6202default of filename completion is disabled.
d3a24ed2
CR
6203If the \fB\-o bashdefault\fP option was supplied to \fBcomplete\fP when
6204the compspec was defined, the \fBbash\fP default completions are attempted
28ef6c31 6205if the compspec generates no matches.
d3a24ed2
CR
6206If the \fB\-o default\fP option was supplied to \fBcomplete\fP when the
6207compspec was defined, readline's default completion will be performed
6208if the compspec (and, if attempted, the default \fBbash\fP completions)
6209generate no matches.
7117c2d2
JA
6210.PP
6211When a compspec indicates that directory name completion is desired,
6212the programmable completion functions force readline to append a slash
6213to completed names which are symbolic links to directories, subject to
6214the value of the \fBmark\-directories\fP readline variable, regardless
6215of the setting of the \fBmark-symlinked\-directories\fP readline variable.
3eb2d94a
CR
6216.PP
6217There is some support for dynamically modifying completions. This is
6218most useful when used in combination with a default completion specified
6219with \fBcomplete -D\fP.
6220It's possible for shell functions executed as completion
6221handlers to indicate that completion should be retried by returning an
6222exit status of 124. If a shell function returns 124, and changes
6223the compspec associated with the command on which completion is being
6224attempted (supplied as the first argument when the function is executed),
6225programmable completion restarts from the beginning, with an
3d8cce26 6226attempt to find a new compspec for that command. This allows a set of
3eb2d94a
CR
6227completions to be built dynamically as completion is attempted, rather than
6228being loaded all at once.
6229.PP
6230For instance, assuming that there is a library of compspecs, each kept in a
6231file corresponding to the name of the command, the following default
6232completion function would load completions dynamically:
6233.PP
6234\f(CW_completion_loader()
6235.br
6236{
6237.br
6238 . "/etc/bash_completion.d/$1.sh" >/dev/null 2>&1 && return 124
6239.br
6240}
6241.br
6242complete -D -F _completion_loader
6243.br
6244\fP
726f6388 6245.SH HISTORY
ccc6cda3 6246When the
d166f048 6247.B \-o history
ccc6cda3
JA
6248option to the
6249.B set
6250builtin is enabled, the shell provides access to the
6251\fIcommand history\fP,
bb70624e 6252the list of commands previously typed.
984a1947
CR
6253The value of the
6254.SM
6255.B HISTSIZE
6256variable is used as the
bb70624e
JA
6257number of commands to save in a history list.
6258The text of the last
726f6388
JA
6259.SM
6260.B HISTSIZE
bb70624e 6261commands (default 500) is saved. The shell
726f6388
JA
6262stores each command in the history list prior to parameter and
6263variable expansion (see
6264.SM
6265.B EXPANSION
6266above) but after history expansion is performed, subject to the
6267values of the shell variables
ccc6cda3
JA
6268.SM
6269.B HISTIGNORE
726f6388
JA
6270and
6271.SM
6272.BR HISTCONTROL .
bb70624e 6273.PP
726f6388
JA
6274On startup, the history is initialized from the file named by
6275the variable
6276.SM
6277.B HISTFILE
6278(default \fI~/.bash_history\fP).
bb70624e 6279The file named by the value of
726f6388
JA
6280.SM
6281.B HISTFILE
6282is truncated, if necessary, to contain no more than
bb70624e 6283the number of lines specified by the value of
726f6388 6284.SM
bb70624e 6285.BR HISTFILESIZE .
4b82d1cd
CR
6286If \fBHISTFILESIZE\fP is unset, or set to null, a non-numeric value,
6287or a numeric value less than zero, the history file is not truncated.
d3ad40de
CR
6288When the history file is read,
6289lines beginning with the history comment character followed immediately
6290by a digit are interpreted as timestamps for the preceding history line.
6291These timestamps are optionally displayed depending on the value of the
6292.SM
6293.B HISTTIMEFORMAT
6294variable.
ccc6cda3
JA
6295When an interactive shell exits, the last
6296.SM
bb70624e 6297.B $HISTSIZE
ccc6cda3
JA
6298lines are copied from the history list to
6299.SM
bb70624e 6300.BR $HISTFILE .
ccc6cda3
JA
6301If the
6302.B histappend
6303shell option is enabled
6304(see the description of
6305.B shopt
6306under
6307.SM
6308.B "SHELL BUILTIN COMMANDS"
6309below), the lines are appended to the history file,
6310otherwise the history file is overwritten.
6311If
6312.SM
6313.B HISTFILE
6314is unset, or if the history file is unwritable, the history is
d3ad40de
CR
6315not saved.
6316If the
6317.SM
984a1947 6318.B HISTTIMEFORMAT
d3ad40de
CR
6319variable is set, time stamps are written to the history file, marked
6320with the history comment character, so
6321they may be preserved across shell sessions.
6322This uses the history comment character to distinguish timestamps from
6323other history lines.
6324After saving the history, the history file is truncated
ccc6cda3
JA
6325to contain no more than
6326.SM
6327.B HISTFILESIZE
6328lines. If
6329.SM
6330.B HISTFILESIZE
e67d0029
CR
6331is unset, or set to null, a non-numeric value,
6332or a numeric value less than zero, the history file is not truncated.
ccc6cda3 6333.PP
726f6388
JA
6334The builtin command
6335.B fc
6336(see
6337.SM
6338.B SHELL BUILTIN COMMANDS
6339below) may be used to list or edit and re-execute a portion of
6340the history list.
6341The
6342.B history
bb70624e 6343builtin may be used to display or modify the history list and
ccc6cda3 6344manipulate the history file.
bb70624e 6345When using command-line editing, search commands
726f6388 6346are available in each editing mode that provide access to the
ccc6cda3
JA
6347history list.
6348.PP
6349The shell allows control over which commands are saved on the history
6350list. The
726f6388 6351.SM
ccc6cda3
JA
6352.B HISTCONTROL
6353and
726f6388 6354.SM
ccc6cda3
JA
6355.B HISTIGNORE
6356variables may be set to cause the shell to save only a subset of the
6357commands entered.
6358The
6359.B cmdhist
6360shell option, if enabled, causes the shell to attempt to save each
6361line of a multi-line command in the same history entry, adding
6362semicolons where necessary to preserve syntactic correctness.
6363The
6364.B lithist
6365shell option causes the shell to save the command with embedded newlines
6366instead of semicolons. See the description of the
6367.B shopt
6368builtin below under
6369.SM
6370.B "SHELL BUILTIN COMMANDS"
6371for information on setting and unsetting shell options.
726f6388
JA
6372.SH "HISTORY EXPANSION"
6373.PP
6374The shell supports a history expansion feature that
6375is similar to the history expansion in
6376.BR csh.
6377This section describes what syntax features are available. This
6378feature is enabled by default for interactive shells, and can be
6379disabled using the
863d31ae 6380.B +H
726f6388
JA
6381option to the
6382.B set
6383builtin command (see
6384.SM
6385.B SHELL BUILTIN COMMANDS
ccc6cda3
JA
6386below). Non-interactive shells do not perform history expansion
6387by default.
6388.PP
6389History expansions introduce words from the history list into
6390the input stream, making it easy to repeat commands, insert the
6391arguments to a previous command into the current input line, or
6392fix errors in previous commands quickly.
726f6388
JA
6393.PP
6394History expansion is performed immediately after a complete line
6395is read, before the shell breaks it into words.
ccc6cda3 6396It takes place in two parts.
cce855bc 6397The first is to determine which line from the history list
ccc6cda3
JA
6398to use during substitution.
6399The second is to select portions of that line for inclusion into
6400the current one.
cce855bc 6401The line selected from the history is the \fIevent\fP,
ccc6cda3
JA
6402and the portions of that line that are acted upon are \fIwords\fP.
6403Various \fImodifiers\fP are available to manipulate the selected words.
6404The line is broken into words in the same fashion as when reading input,
6405so that several \fImetacharacter\fP-separated words surrounded by
cce855bc 6406quotes are considered one word.
ccc6cda3
JA
6407History expansions are introduced by the appearance of the
6408history expansion character, which is \^\fB!\fP\^ by default.
6409Only backslash (\^\fB\e\fP\^) and single quotes can quote
6410the history expansion character.
6411.PP
d3a24ed2
CR
6412Several characters inhibit history expansion if found immediately
6413following the history expansion character, even if it is unquoted:
6414space, tab, newline, carriage return, and \fB=\fP.
6415If the \fBextglob\fP shell option is enabled, \fB(\fP will also
6416inhibit expansion.
6417.PP
ccc6cda3
JA
6418Several shell options settable with the
6419.B shopt
6420builtin may be used to tailor the behavior of history expansion.
6421If the
6422.B histverify
6423shell option is enabled (see the description of the
6424.B shopt
984a1947 6425builtin below), and
ccc6cda3
JA
6426.B readline
6427is being used, history substitutions are not immediately passed to
6428the shell parser.
6429Instead, the expanded line is reloaded into the
6430.B readline
6431editing buffer for further modification.
6432If
6433.B readline
6434is being used, and the
6435.B histreedit
6436shell option is enabled, a failed history substitution will be reloaded
6437into the
6438.B readline
6439editing buffer for correction.
6440The
6441.B \-p
6442option to the
6443.B history
6444builtin command may be used to see what a history expansion will
6445do before using it.
6446The
6447.B \-s
6448option to the
6449.B history
6450builtin may be used to add commands to the end of the history list
6451without actually executing them, so that they are available for
6452subsequent recall.
726f6388
JA
6453.PP
6454The shell allows control of the various characters used by the
6455history expansion mechanism (see the description of
6456.B histchars
6457above under
6458.BR "Shell Variables" ).
d3ad40de
CR
6459The shell uses
6460the history comment character to mark history timestamps when
6461writing the history file.
726f6388
JA
6462.SS Event Designators
6463.PP
6464An event designator is a reference to a command line entry in the
6465history list.
5f8cde23
CR
6466Unless the reference is absolute, events are relative to the current
6467position in the history list.
726f6388
JA
6468.PP
6469.PD 0
6470.TP
6471.B !
6472Start a history substitution, except when followed by a
6473.BR blank ,
d3a24ed2
CR
6474newline, carriage return, =
6475or ( (when the \fBextglob\fP shell option is enabled using
6476the \fBshopt\fP builtin).
726f6388 6477.TP
726f6388
JA
6478.B !\fIn\fR
6479Refer to command line
6480.IR n .
6481.TP
6482.B !\-\fIn\fR
5f8cde23 6483Refer to the current command minus
726f6388
JA
6484.IR n .
6485.TP
ccc6cda3
JA
6486.B !!
6487Refer to the previous command. This is a synonym for `!\-1'.
6488.TP
726f6388 6489.B !\fIstring\fR
5f8cde23
CR
6490Refer to the most recent command preceding the current position in the
6491history list starting with
726f6388
JA
6492.IR string .
6493.TP
6494.B !?\fIstring\fR\fB[?]\fR
e3db237e 6495Refer to the most recent command preceding the current position in the
5f8cde23 6496history list containing
726f6388 6497.IR string .
ccc6cda3
JA
6498The trailing \fB?\fP may be omitted if
6499.I string
6500is followed immediately by a newline.
726f6388
JA
6501.TP
6502.B \d\s+2^\s-2\u\fIstring1\fP\d\s+2^\s-2\u\fIstring2\fP\d\s+2^\s-2\u
5f8cde23 6503Quick substitution. Repeat the previous command, replacing
726f6388
JA
6504.I string1
6505with
6506.IR string2 .
6507Equivalent to
6508``!!:s/\fIstring1\fP/\fIstring2\fP/''
6509(see \fBModifiers\fP below).
6510.TP
6511.B !#
6512The entire command line typed so far.
6513.PD
6514.SS Word Designators
6515.PP
ccc6cda3 6516Word designators are used to select desired words from the event.
726f6388
JA
6517A
6518.B :
ccc6cda3 6519separates the event specification from the word designator.
cce855bc 6520It may be omitted if the word designator begins with a
726f6388
JA
6521.BR ^ ,
6522.BR $ ,
6523.BR * ,
ccc6cda3 6524.BR \- ,
726f6388
JA
6525or
6526.BR % .
6527Words are numbered from the beginning of the line,
ccc6cda3
JA
6528with the first word being denoted by 0 (zero).
6529Words are inserted into the current line separated by single spaces.
726f6388
JA
6530.PP
6531.PD 0
6532.TP
6533.B 0 (zero)
6534The zeroth word. For the shell, this is the command
6535word.
6536.TP
6537.I n
6538The \fIn\fRth word.
6539.TP
6540.B ^
6541The first argument. That is, word 1.
6542.TP
6543.B $
6544The last argument.
6545.TP
6546.B %
6547The word matched by the most recent `?\fIstring\fR?' search.
6548.TP
6549.I x\fB\-\fPy
6550A range of words; `\-\fIy\fR' abbreviates `0\-\fIy\fR'.
6551.TP
6552.B *
6553All of the words but the zeroth. This is a synonym
6554for `\fI1\-$\fP'. It is not an error to use
6555.B *
6556if there is just one
6557word in the event; the empty string is returned in that case.
6558.TP
6559.B x*
6560Abbreviates \fIx\-$\fP.
6561.TP
6562.B x\-
6563Abbreviates \fIx\-$\fP like \fBx*\fP, but omits the last word.
6564.PD
ccc6cda3
JA
6565.PP
6566If a word designator is supplied without an event specification, the
6567previous command is used as the event.
726f6388
JA
6568.SS Modifiers
6569.PP
ccc6cda3
JA
6570After the optional word designator, there may appear a sequence of
6571one or more of the following modifiers, each preceded by a `:'.
726f6388
JA
6572.PP
6573.PD 0
6574.PP
6575.TP
6576.B h
b28ff8c9 6577Remove a trailing filename component, leaving only the head.
ccc6cda3
JA
6578.TP
6579.B t
b28ff8c9 6580Remove all leading filename components, leaving the tail.
726f6388
JA
6581.TP
6582.B r
6583Remove a trailing suffix of the form \fI.xxx\fP, leaving the
6584basename.
6585.TP
6586.B e
6587Remove all but the trailing suffix.
6588.TP
726f6388
JA
6589.B p
6590Print the new command but do not execute it.
6591.TP
6592.B q
6593Quote the substituted words, escaping further substitutions.
6594.TP
cce855bc
JA
6595.B x
6596Quote the substituted words as with
6597.BR q ,
6598but break into words at
6599.B blanks
6600and newlines.
726f6388 6601.TP
cce855bc
JA
6602.B s/\fIold\fP/\fInew\fP/
6603Substitute
6604.I new
6605for the first occurrence of
6606.I old
6607in the event line. Any delimiter can be used in place of /. The
6608final delimiter is optional if it is the last character of the
6609event line. The delimiter may be quoted in
6610.I old
6611and
6612.I new
6613with a single backslash. If & appears in
6614.IR new ,
6615it is replaced by
6616.IR old .
6617A single backslash will quote the &. If
6618.I old
6619is null, it is set to the last
6620.I old
6621substituted, or, if no previous history substitutions took place,
6622the last
6623.I string
6624in a
6625.B !?\fIstring\fR\fB[?]\fR
6626search.
ccc6cda3 6627.TP
cce855bc
JA
6628.B &
6629Repeat the previous substitution.
6630.TP
6631.B g
6632Cause changes to be applied over the entire event line. This is
6633used in conjunction with `\fB:s\fP' (e.g., `\fB:gs/\fIold\fP/\fInew\fP/\fR')
6634or `\fB:&\fP'. If used with
6635`\fB:s\fP', any delimiter can be used
6636in place of /, and the final delimiter is optional
6637if it is the last character of the event line.
d3a24ed2
CR
6638An \fBa\fP may be used as a synonym for \fBg\fP.
6639.TP
6640.B G
6641Apply the following `\fBs\fP' modifier once to each word in the event line.
726f6388 6642.PD
726f6388
JA
6643.SH "SHELL BUILTIN COMMANDS"
6644.\" start of bash_builtins
6645.zZ
ccc6cda3
JA
6646.PP
6647Unless otherwise noted, each builtin command documented in this
6648section as accepting options preceded by
6649.B \-
6650accepts
6651.B \-\-
6652to signify the end of the options.
6932f7f5
CR
6653The \fB:\fP, \fBtrue\fP, \fBfalse\fP, and \fBtest\fP builtins
6654do not accept options and do not treat \fB\-\-\fP specially.
6655The \fBexit\fP, \fBlogout\fP, \fBbreak\fP, \fBcontinue\fP, \fBlet\fP,
6656and \fBshift\fP builtins accept and process arguments beginning with
6657\fB\-\fP without requiring \fB\-\-\fP.
6658Other builtins that accept arguments but are not specified as accepting
6659options interpret arguments beginning with \fB\-\fP as invalid options and
6660require \fB\-\-\fP to prevent this interpretation.
ccc6cda3 6661.sp .5
726f6388
JA
6662.PD 0
6663.TP
6664\fB:\fP [\fIarguments\fP]
6665.PD
6666No effect; the command does nothing beyond expanding
6667.I arguments
6668and performing any specified
6669redirections. A zero exit code is returned.
6670.TP
726f6388 6671\fB .\| \fP \fIfilename\fP [\fIarguments\fP]
7117c2d2 6672.PD 0
726f6388
JA
6673.TP
6674\fBsource\fP \fIfilename\fP [\fIarguments\fP]
6675.PD
6676Read and execute commands from
6677.I filename
6678in the current
6679shell environment and return the exit status of the last command
6680executed from
6681.IR filename .
6682If
6683.I filename
b28ff8c9 6684does not contain a slash, filenames in
726f6388
JA
6685.SM
6686.B PATH
6687are used to find the directory containing
6688.IR filename .
6689The file searched for in
6690.SM
6691.B PATH
28ef6c31
JA
6692need not be executable.
6693When \fBbash\fP is not in \fIposix mode\fP, the current directory is
726f6388
JA
6694searched if no file is found in
6695.SM
6696.BR PATH .
ccc6cda3
JA
6697If the
6698.B sourcepath
6699option to the
6700.B shopt
6701builtin command is turned off, the
6702.SM
6703.B PATH
6704is not searched.
726f6388 6705If any \fIarguments\fP are supplied, they become the positional
ccc6cda3 6706parameters when \fIfilename\fP is executed. Otherwise the positional
726f6388
JA
6707parameters are unchanged.
6708The return status is the status of the last command exited within
6709the script (0 if no commands are executed), and false if
6710.I filename
cce855bc 6711is not found or cannot be read.
726f6388 6712.TP
ccc6cda3
JA
6713\fBalias\fP [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...]
6714\fBAlias\fP with no arguments or with the
6715.B \-p
6716option prints the list of aliases in the form
6717\fBalias\fP \fIname\fP=\fIvalue\fP on standard output.
6718When arguments are supplied, an alias is defined for
6719each \fIname\fP whose \fIvalue\fP is given.
6720A trailing space in \fIvalue\fP causes the next word to be
6721checked for alias substitution when the alias is expanded.
6722For each \fIname\fP in the argument list for which no \fIvalue\fP
6723is supplied, the name and value of the alias is printed.
6724\fBAlias\fP returns true unless a \fIname\fP is given for which
6725no alias has been defined.
726f6388 6726.TP
de3341d1
CR
6727\fBbg\fP [\fIjobspec\fP ...]
6728Resume each suspended job \fIjobspec\fP in the background, as if it
cce855bc 6729had been started with
726f6388 6730.BR & .
d3ad40de
CR
6731If
6732.I jobspec
6733is not present, the shell's notion of the \fIcurrent job\fP is used.
726f6388
JA
6734.B bg
6735.I jobspec
6736returns 0 unless run when job control is disabled or, when run with
ff247e74
CR
6737job control enabled, any specified \fIjobspec\fP was not found
6738or was started without job control.
726f6388 6739.TP
ba4ab055 6740\fBbind\fP [\fB\-m\fP \fIkeymap\fP] [\fB\-lpsvPSVX\fP]
7117c2d2 6741.PD 0
cce855bc
JA
6742.TP
6743\fBbind\fP [\fB\-m\fP \fIkeymap\fP] [\fB\-q\fP \fIfunction\fP] [\fB\-u\fP \fIfunction\fP] [\fB\-r\fP \fIkeyseq\fP]
726f6388 6744.TP
ccc6cda3 6745\fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-f\fP \fIfilename\fP
726f6388 6746.TP
bb70624e
JA
6747\fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-x\fP \fIkeyseq\fP:\fIshell\-command\fP
6748.TP
ccc6cda3 6749\fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fIkeyseq\fP:\fIfunction\-name\fP
7117c2d2
JA
6750.TP
6751\fBbind\fP \fIreadline\-command\fP
726f6388
JA
6752.PD
6753Display current
6754.B readline
7117c2d2 6755key and function bindings, bind a key sequence to a
726f6388 6756.B readline
7117c2d2
JA
6757function or macro, or set a
6758.B readline
6759variable.
6760Each non-option argument is a command as it would appear in
726f6388 6761.IR .inputrc ,
7117c2d2
JA
6762but each binding or command must be passed as a separate argument;
6763e.g., '"\eC\-x\eC\-r": re\-read\-init\-file'.
6764Options, if supplied, have the following meanings:
726f6388
JA
6765.RS
6766.PD 0
6767.TP
6768.B \-m \fIkeymap\fP
6769Use
6770.I keymap
6771as the keymap to be affected by the subsequent bindings.
6772Acceptable
6773.I keymap
6774names are
ccc6cda3 6775\fIemacs, emacs\-standard, emacs\-meta, emacs\-ctlx, vi,
28ef6c31 6776vi\-move, vi\-command\fP, and
ccc6cda3
JA
6777.IR vi\-insert .
6778\fIvi\fP is equivalent to \fIvi\-command\fP; \fIemacs\fP is
6779equivalent to \fIemacs\-standard\fP.
726f6388
JA
6780.TP
6781.B \-l
ccc6cda3
JA
6782List the names of all \fBreadline\fP functions.
6783.TP
6784.B \-p
6785Display \fBreadline\fP function names and bindings in such a way
6786that they can be re-read.
6787.TP
6788.B \-P
6789List current \fBreadline\fP function names and bindings.
726f6388 6790.TP
ccc6cda3
JA
6791.B \-s
6792Display \fBreadline\fP key sequences bound to macros and the strings
6793they output in such a way that they can be re-read.
6794.TP
6795.B \-S
6796Display \fBreadline\fP key sequences bound to macros and the strings
6797they output.
726f6388 6798.TP
d3ad40de
CR
6799.B \-v
6800Display \fBreadline\fP variable names and values in such a way that they
6801can be re-read.
6802.TP
6803.B \-V
6804List current \fBreadline\fP variable names and values.
6805.TP
726f6388 6806.B \-f \fIfilename\fP
ccc6cda3 6807Read key bindings from \fIfilename\fP.
726f6388
JA
6808.TP
6809.B \-q \fIfunction\fP
ccc6cda3
JA
6810Query about which keys invoke the named \fIfunction\fP.
6811.TP
cce855bc
JA
6812.B \-u \fIfunction\fP
6813Unbind all keys bound to the named \fIfunction\fP.
6814.TP
ccc6cda3
JA
6815.B \-r \fIkeyseq\fP
6816Remove any current binding for \fIkeyseq\fP.
bb70624e
JA
6817.TP
6818.B \-x \fIkeyseq\fP:\fIshell\-command\fP
6819Cause \fIshell\-command\fP to be executed whenever \fIkeyseq\fP is
6820entered.
8943768b 6821When \fIshell\-command\fP is executed, the shell sets the
984a1947 6822.SM
8943768b
CR
6823.B READLINE_LINE
6824variable to the contents of the \fBreadline\fP line buffer and the
984a1947 6825.SM
8943768b
CR
6826.B READLINE_POINT
6827variable to the current location of the insertion point.
6828If the executed command changes the value of
984a1947 6829.SM
8943768b
CR
6830.B READLINE_LINE
6831or
984a1947 6832.SM
8943768b
CR
6833.BR READLINE_POINT ,
6834those new values will be reflected in the editing state.
ba4ab055
CR
6835.TP
6836.B \-X
6837List all key sequences bound to shell commands and the associated commands
6838in a format that can be reused as input.
726f6388
JA
6839.PD
6840.PP
6841The return value is 0 unless an unrecognized option is given or an
6842error occurred.
6843.RE
6844.TP
6845\fBbreak\fP [\fIn\fP]
6846Exit from within a
6847.BR for ,
6848.BR while ,
ccc6cda3 6849.BR until ,
726f6388 6850or
ccc6cda3 6851.B select
726f6388
JA
6852loop. If \fIn\fP is specified, break \fIn\fP levels.
6853.I n
6854must be \(>= 1. If
6855.I n
6856is greater than the number of enclosing loops, all enclosing loops
33fe8777
CR
6857are exited.
6858The return value is 0 unless \fIn\fP is not greater than or equal to 1.
726f6388
JA
6859.TP
6860\fBbuiltin\fP \fIshell\-builtin\fP [\fIarguments\fP]
6861Execute the specified shell builtin, passing it
6862.IR arguments ,
6863and return its exit status.
cce855bc 6864This is useful when defining a
726f6388 6865function whose name is the same as a shell builtin,
cce855bc
JA
6866retaining the functionality of the builtin within the function.
6867The \fBcd\fP builtin is commonly redefined this way.
6868The return status is false if
726f6388
JA
6869.I shell\-builtin
6870is not a shell builtin command.
6871.TP
6a8fd0ed
CR
6872\fBcaller\fP [\fIexpr\fP]
6873Returns the context of any active subroutine call (a shell function or
5cdaaf76 6874a script executed with the \fB.\fP or \fBsource\fP builtins).
6a8fd0ed
CR
6875Without \fIexpr\fP, \fBcaller\fP displays the line number and source
6876filename of the current subroutine call.
6877If a non-negative integer is supplied as \fIexpr\fP, \fBcaller\fP
6878displays the line number, subroutine name, and source file corresponding
6879to that position in the current execution call stack. This extra
6880information may be used, for example, to print a stack trace. The
6881current frame is frame 0.
6882The return value is 0 unless the shell is not executing a subroutine
6883call or \fIexpr\fP does not correspond to a valid position in the
6884call stack.
6885.TP
220537f2 6886\fBcd\fP [\fB\-L\fP|[\fB\-P\fP [\fB\-e\fP]]] [\fIdir\fP]
2dead0c4
CR
6887Change the current directory to \fIdir\fP.
6888if \fIdir\fP is not supplied, the value of the
726f6388
JA
6889.SM
6890.B HOME
2dead0c4
CR
6891shell variable is the default.
6892Any additional arguments following \fIdir\fP are ignored.
726f6388
JA
6893The variable
6894.SM
6895.B CDPATH
ccc6cda3 6896defines the search path for the directory containing
45c0f7f8
CR
6897.IR dir :
6898each directory name in
6899.SM
6900.B CDPATH
6901is searched for \fIdir\fP.
ccc6cda3
JA
6902Alternative directory names in
6903.SM
6904.B CDPATH
6905are separated by a colon (:). A null directory name in
726f6388
JA
6906.SM
6907.B CDPATH
ccc6cda3 6908is the same as the current directory, i.e., ``\fB.\fP''. If
726f6388
JA
6909.I dir
6910begins with a slash (/),
6911then
6912.SM
6913.B CDPATH
ccc6cda3
JA
6914is not used. The
6915.B \-P
45c0f7f8
CR
6916option causes \fBcd\fP to use the physical directory structure
6917by resolving symbolic links while traversing \fIdir\fP and
6918before processing instances of \fI..\fP in \fIdir\fP (see also the
ccc6cda3
JA
6919.B \-P
6920option to the
6921.B set
6922builtin command); the
6923.B \-L
45c0f7f8
CR
6924option forces symbolic links to be followed by resolving the link
6925after processing instances of \fI..\fP in \fIdir\fP.
6926If \fI..\fP appears in \fIdir\fP, it is processed by removing the
6927immediately previous pathname component from \fIdir\fP, back to a slash
6928or the beginning of \fIdir\fP.
220537f2
CR
6929If the
6930.B \-e
6931option is supplied with
6932.BR \-P ,
6933and the current working directory cannot be successfully determined
6934after a successful directory change, \fBcd\fP will return an unsuccessful
6935status.
6936An argument of
726f6388 6937.B \-
19baff85 6938is converted to
726f6388 6939.SM
19baff85
CR
6940.B $OLDPWD
6941before the directory change is attempted.
984a1947
CR
6942If a non-empty directory name from
6943.SM
6944.B CDPATH
6945is used, or if
d3a24ed2
CR
6946\fB\-\fP is the first argument, and the directory change is
6947successful, the absolute pathname of the new working directory is
6948written to the standard output.
726f6388
JA
6949The return value is true if the directory was successfully changed;
6950false otherwise.
6951.TP
ccc6cda3 6952\fBcommand\fP [\fB\-pVv\fP] \fIcommand\fP [\fIarg\fP ...]
726f6388
JA
6953Run
6954.I command
6955with
6956.I args
6957suppressing the normal shell function lookup. Only builtin
6958commands or commands found in the
6959.SM
6960.B PATH
6961are executed. If the
6962.B \-p
6963option is given, the search for
6964.I command
6965is performed using a default value for
984a1947 6966.SM
726f6388
JA
6967.B PATH
6968that is guaranteed to find all of the standard utilities.
6969If either the
6970.B \-V
6971or
6972.B \-v
6973option is supplied, a description of
6974.I command
6975is printed. The
6976.B \-v
b28ff8c9 6977option causes a single word indicating the command or filename
726f6388
JA
6978used to invoke
6979.I command
cce855bc 6980to be displayed; the
726f6388
JA
6981.B \-V
6982option produces a more verbose description.
726f6388
JA
6983If the
6984.B \-V
6985or
6986.B \-v
6987option is supplied, the exit status is 0 if
6988.I command
6989was found, and 1 if not. If neither option is supplied and
6990an error occurred or
6991.I command
6992cannot be found, the exit status is 127. Otherwise, the exit status of the
6993.B command
6994builtin is the exit status of
6995.IR command .
6996.TP
bb70624e
JA
6997\fBcompgen\fP [\fIoption\fP] [\fIword\fP]
6998Generate possible completion matches for \fIword\fP according to
6999the \fIoption\fPs, which may be any option accepted by the
7000.B complete
7001builtin with the exception of \fB\-p\fP and \fB\-r\fP, and write
7002the matches to the standard output.
7003When using the \fB\-F\fP or \fB\-C\fP options, the various shell variables
7004set by the programmable completion facilities, while available, will not
7005have useful values.
7006.sp 1
7007The matches will be generated in the same way as if the programmable
7008completion code had generated them directly from a completion specification
7009with the same flags.
7010If \fIword\fP is specified, only those completions matching \fIword\fP
7011will be displayed.
7012.sp 1
7013The return value is true unless an invalid option is supplied, or no
7014matches were generated.
7015.TP
3eb2d94a 7016\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 7017.br
d3ad40de 7018[\fB\-X\fP \fIfilterpat\fP] [\fB\-P\fP \fIprefix\fP] [\fB\-S\fP \fIsuffix\fP] \fIname\fP [\fIname ...\fP]
7117c2d2 7019.PD 0
bb70624e 7020.TP
3eb2d94a 7021\fBcomplete\fP \fB\-pr\fP [\fB\-DE\fP] [\fIname\fP ...]
bb70624e
JA
7022.PD
7023Specify how arguments to each \fIname\fP should be completed.
7024If the \fB\-p\fP option is supplied, or if no options are supplied,
7025existing completion specifications are printed in a way that allows
7026them to be reused as input.
7027The \fB\-r\fP option removes a completion specification for
7028each \fIname\fP, or, if no \fIname\fPs are supplied, all
7029completion specifications.
3eb2d94a
CR
7030The \fB\-D\fP option indicates that the remaining options and actions should
7031apply to the ``default'' command completion; that is, completion attempted
7032on a command for which no completion has previously been defined.
6a8fd0ed
CR
7033The \fB\-E\fP option indicates that the remaining options and actions should
7034apply to ``empty'' command completion; that is, completion attempted on a
7035blank line.
bb70624e
JA
7036.sp 1
7037The process of applying these completion specifications when word completion
7038is attempted is described above under \fBProgrammable Completion\fP.
7039.sp 1
7040Other options, if specified, have the following meanings.
7041The arguments to the \fB\-G\fP, \fB\-W\fP, and \fB\-X\fP options
7042(and, if necessary, the \fB\-P\fP and \fB\-S\fP options)
7043should be quoted to protect them from expansion before the
7044.B complete
7045builtin is invoked.
7046.RS
7047.PD 0
7048.TP 8
28ef6c31
JA
7049\fB\-o\fP \fIcomp-option\fP
7050The \fIcomp-option\fP controls several aspects of the compspec's behavior
7051beyond the simple generation of completions.
7052\fIcomp-option\fP may be one of:
7053.RS
7054.TP 8
d3a24ed2
CR
7055.B bashdefault
7056Perform the rest of the default \fBbash\fP completions if the compspec
7057generates no matches.
7058.TP 8
28ef6c31 7059.B default
7117c2d2
JA
7060Use readline's default filename completion if the compspec generates
7061no matches.
28ef6c31
JA
7062.TP 8
7063.B dirnames
7064Perform directory name completion if the compspec generates no matches.
7065.TP 8
7066.B filenames
7067Tell readline that the compspec generates filenames, so it can perform any
e77a3058
CR
7068filename\-specific processing (like adding a slash to directory names,
7069quoting special characters, or suppressing trailing spaces).
7070Intended to be used with shell functions.
7117c2d2 7071.TP 8
084c952b
CR
7072.B noquote
7073Tell readline not to quote the completed words if they are filenames
7074(quoting filenames is the default).
7075.TP 8
7117c2d2
JA
7076.B nospace
7077Tell readline not to append a space (the default) to words completed at
7078the end of the line.
301e2142
CR
7079.TP 8
7080.B plusdirs
7081After any matches defined by the compspec are generated,
7082directory name completion is attempted and any
7083matches are added to the results of the other actions.
28ef6c31
JA
7084.RE
7085.TP 8
bb70624e
JA
7086\fB\-A\fP \fIaction\fP
7087The \fIaction\fP may be one of the following to generate a list of possible
7088completions:
7089.RS
7090.TP 8
7091.B alias
7092Alias names. May also be specified as \fB\-a\fP.
7093.TP 8
7094.B arrayvar
7095Array variable names.
7096.TP 8
7097.B binding
7098\fBReadline\fP key binding names.
7099.TP 8
7100.B builtin
7101Names of shell builtin commands. May also be specified as \fB\-b\fP.
7102.TP 8
7103.B command
7104Command names. May also be specified as \fB\-c\fP.
7105.TP 8
7106.B directory
7107Directory names. May also be specified as \fB\-d\fP.
7108.TP 8
7109.B disabled
7110Names of disabled shell builtins.
7111.TP 8
7112.B enabled
7113Names of enabled shell builtins.
7114.TP 8
7115.B export
7116Names of exported shell variables. May also be specified as \fB\-e\fP.
7117.TP 8
7118.B file
7119File names. May also be specified as \fB\-f\fP.
7120.TP 8
7121.B function
7122Names of shell functions.
7123.TP 8
f73dda09
JA
7124.B group
7125Group names. May also be specified as \fB\-g\fP.
7126.TP 8
bb70624e
JA
7127.B helptopic
7128Help topics as accepted by the \fBhelp\fP builtin.
7129.TP 8
7130.B hostname
7131Hostnames, as taken from the file specified by the
7132.SM
7133.B HOSTFILE
7134shell variable.
7135.TP 8
7136.B job
7137Job names, if job control is active. May also be specified as \fB\-j\fP.
7138.TP 8
7139.B keyword
7140Shell reserved words. May also be specified as \fB\-k\fP.
7141.TP 8
7142.B running
7143Names of running jobs, if job control is active.
7144.TP 8
7117c2d2
JA
7145.B service
7146Service names. May also be specified as \fB\-s\fP.
7147.TP 8
bb70624e
JA
7148.B setopt
7149Valid arguments for the \fB\-o\fP option to the \fBset\fP builtin.
7150.TP 8
7151.B shopt
7152Shell option names as accepted by the \fBshopt\fP builtin.
7153.TP 8
7154.B signal
7155Signal names.
7156.TP 8
7157.B stopped
7158Names of stopped jobs, if job control is active.
7159.TP 8
7160.B user
7161User names. May also be specified as \fB\-u\fP.
7162.TP 8
7163.B variable
7164Names of all shell variables. May also be specified as \fB\-v\fP.
7165.RE
7166.TP 8
bb70624e
JA
7167\fB\-C\fP \fIcommand\fP
7168\fIcommand\fP is executed in a subshell environment, and its output is
7169used as the possible completions.
7170.TP 8
7171\fB\-F\fP \fIfunction\fP
7172The shell function \fIfunction\fP is executed in the current shell
7173environment.
ba4ab055
CR
7174When the function is executed,
7175the first argument (\fB$1\fP) is the name of the command whose arguments are
7176being completed,
7177the second argument (\fB$2\fP) is the word being completed,
7178and the third argument (\fB$3\fP) is the word preceding the word being
7179completed on the current command line.
bb70624e
JA
7180When it finishes, the possible completions are retrieved from the value
7181of the
7182.SM
7183.B COMPREPLY
7184array variable.
7185.TP 8
5cdaaf76
CR
7186\fB\-G\fP \fIglobpat\fP
7187The pathname expansion pattern \fIglobpat\fP is expanded to generate
7188the possible completions.
bb70624e
JA
7189.TP 8
7190\fB\-P\fP \fIprefix\fP
7191\fIprefix\fP is added at the beginning of each possible completion
7192after all other options have been applied.
7193.TP 8
7194\fB\-S\fP \fIsuffix\fP
7195\fIsuffix\fP is appended to each possible completion
7196after all other options have been applied.
5cdaaf76
CR
7197.TP 8
7198\fB\-W\fP \fIwordlist\fP
7199The \fIwordlist\fP is split using the characters in the
7200.SM
7201.B IFS
7202special variable as delimiters, and each resultant word is expanded.
7203The possible completions are the members of the resultant list which
7204match the word being completed.
7205.TP 8
7206\fB\-X\fP \fIfilterpat\fP
7207\fIfilterpat\fP is a pattern as used for pathname expansion.
7208It is applied to the list of possible completions generated by the
7209preceding options and arguments, and each completion matching
7210\fIfilterpat\fP is removed from the list.
7211A leading \fB!\fP in \fIfilterpat\fP negates the pattern; in this
7212case, any completion not matching \fIfilterpat\fP is removed.
bb70624e
JA
7213.PD
7214.PP
7215The return value is true unless an invalid option is supplied, an option
7216other than \fB\-p\fP or \fB\-r\fP is supplied without a \fIname\fP
7217argument, an attempt is made to remove a completion specification for
7218a \fIname\fP for which no specification exists, or
7219an error occurs adding a completion specification.
7220.RE
7221.TP
3eb2d94a 7222\fBcompopt\fP [\fB\-o\fP \fIoption\fP] [\fB\-DE\fP] [\fB+o\fP \fIoption\fP] [\fIname\fP]
6fbe7620
CR
7223Modify completion options for each \fIname\fP according to the
7224\fIoption\fPs, or for the
5cdaaf76 7225currently-executing completion if no \fIname\fPs are supplied.
6fbe7620
CR
7226If no \fIoption\fPs are given, display the completion options for each
7227\fIname\fP or the current completion.
7228The possible values of \fIoption\fP are those valid for the \fBcomplete\fP
7229builtin described above.
3eb2d94a
CR
7230The \fB\-D\fP option indicates that the remaining options should
7231apply to the ``default'' command completion; that is, completion attempted
7232on a command for which no completion has previously been defined.
7233The \fB\-E\fP option indicates that the remaining options should
7234apply to ``empty'' command completion; that is, completion attempted on a
7235blank line.
9c7f20c7 7236.sp 1
6fbe7620
CR
7237The return value is true unless an invalid option is supplied, an attempt
7238is made to modify the options for a \fIname\fP for which no completion
7239specification exists, or an output error occurs.
7240.TP
726f6388
JA
7241\fBcontinue\fP [\fIn\fP]
7242Resume the next iteration of the enclosing
7243.BR for ,
7244.BR while ,
ccc6cda3 7245.BR until ,
726f6388 7246or
ccc6cda3 7247.B select
726f6388
JA
7248loop.
7249If
7250.I n
7251is specified, resume at the \fIn\fPth enclosing loop.
7252.I n
7253must be \(>= 1. If
7254.I n
7255is greater than the number of enclosing loops, the last enclosing loop
33fe8777
CR
7256(the ``top-level'' loop) is resumed.
7257The return value is 0 unless \fIn\fP is not greater than or equal to 1.
726f6388 7258.TP
6faad625 7259\fBdeclare\fP [\fB\-aAfFgilrtux\fP] [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...]
726f6388 7260.PD 0
726f6388 7261.TP
6faad625 7262\fBtypeset\fP [\fB\-aAfFgilrtux\fP] [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...]
726f6388 7263.PD
ccc6cda3
JA
7264Declare variables and/or give them attributes.
7265If no \fIname\fPs are given then display the values of variables.
7266The
7267.B \-p
7268option will display the attributes and values of each
7269.IR name .
7270When
7271.B \-p
6fbe7620
CR
7272is used with \fIname\fP arguments, additional options are ignored.
7273When
7274.B \-p
7275is supplied without \fIname\fP arguments, it will display the attributes
7276and values of all variables having the attributes specified by the
7277additional options.
7278If no other options are supplied with \fB\-p\fP, \fBdeclare\fP will display
7279the attributes and values of all shell variables. The \fB\-f\fP option
7280will restrict the display to shell functions.
ccc6cda3
JA
7281The
7282.B \-F
7283option inhibits the display of function definitions; only the
7284function name and attributes are printed.
d3a24ed2
CR
7285If the \fBextdebug\fP shell option is enabled using \fBshopt\fP,
7286the source file name and line number where the function is defined
7287are displayed as well. The
ccc6cda3
JA
7288.B \-F
7289option implies
7290.BR \-f .
6faad625
CR
7291The
7292.B \-g
7293option forces variables to be created or modified at the global scope,
7294even when \fBdeclare\fP is executed in a shell function.
7295It is ignored in all other cases.
ccc6cda3
JA
7296The following options can
7297be used to restrict output to variables with the specified attribute or
7298to give variables attributes:
726f6388
JA
7299.RS
7300.PD 0
7301.TP
ccc6cda3 7302.B \-a
fdf670ea
CR
7303Each \fIname\fP is an indexed array variable (see
7304.B Arrays
7305above).
7306.TP
7307.B \-A
7308Each \fIname\fP is an associative array variable (see
ccc6cda3
JA
7309.B Arrays
7310above).
7311.TP
726f6388 7312.B \-f
ccc6cda3
JA
7313Use function names only.
7314.TP
7315.B \-i
7316The variable is treated as an integer; arithmetic evaluation (see
7317.SM
984a1947
CR
7318.B "ARITHMETIC EVALUATION"
7319above) is performed when the variable is assigned a value.
726f6388 7320.TP
09767ff0
CR
7321.B \-l
7322When the variable is assigned a value, all upper-case characters are
7323converted to lower-case.
7324The upper-case attribute is disabled.
7325.TP
726f6388
JA
7326.B \-r
7327Make \fIname\fPs readonly. These names cannot then be assigned values
cce855bc 7328by subsequent assignment statements or unset.
726f6388 7329.TP
7117c2d2
JA
7330.B \-t
7331Give each \fIname\fP the \fItrace\fP attribute.
76a8d78d
CR
7332Traced functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps from
7333the calling shell.
7117c2d2
JA
7334The trace attribute has no special meaning for variables.
7335.TP
09767ff0
CR
7336.B \-u
7337When the variable is assigned a value, all lower-case characters are
7338converted to upper-case.
7339The lower-case attribute is disabled.
7340.TP
726f6388
JA
7341.B \-x
7342Mark \fIname\fPs for export to subsequent commands via the environment.
726f6388
JA
7343.PD
7344.PP
7345Using `+' instead of `\-'
d3ad40de
CR
7346turns off the attribute instead,
7347with the exceptions that \fB+a\fP
984a1947 7348may not be used to destroy an array variable and \fB+r\fP will not
d3ad40de 7349remove the readonly attribute.
b28ff8c9
CR
7350When used in a function,
7351.B declare
7352and
7353.B typeset
7354make each
54a1fa7c 7355\fIname\fP local, as with the
726f6388 7356.B local
6faad625 7357command,
b28ff8c9 7358unless the \fB\-g\fP option is supplied.
d3a24ed2
CR
7359If a variable name is followed by =\fIvalue\fP, the value of
7360the variable is set to \fIvalue\fP.
7361The return value is 0 unless an invalid option is encountered,
bb70624e
JA
7362an attempt is made to define a function using
7363.if n ``\-f foo=bar'',
7364.if t \f(CW\-f foo=bar\fP,
ccc6cda3
JA
7365an attempt is made to assign a value to a readonly variable,
7366an attempt is made to assign a value to an array variable without
7367using the compound assignment syntax (see
7368.B Arrays
cce855bc 7369above), one of the \fInames\fP is not a valid shell variable name,
726f6388 7370an attempt is made to turn off readonly status for a readonly variable,
ccc6cda3 7371an attempt is made to turn off array status for an array variable,
bb70624e 7372or an attempt is made to display a non-existent function with \fB\-f\fP.
726f6388
JA
7373.RE
7374.TP
b28ff8c9 7375.B dirs [\fB\-clpv\fP] [+\fIn\fP] [\-\fIn\fP]
ccc6cda3
JA
7376Without options, displays the list of currently remembered directories.
7377The default display is on a single line with directory names separated
7378by spaces.
7379Directories are added to the list with the
726f6388
JA
7380.B pushd
7381command; the
7382.B popd
ccc6cda3 7383command removes entries from the list.
726f6388
JA
7384.RS
7385.PD 0
7386.TP
ccc6cda3
JA
7387.B \-c
7388Clears the directory stack by deleting all of the entries.
7389.TP
726f6388 7390.B \-l
b28ff8c9
CR
7391Produces a listing using full pathnames;
7392the default listing format uses a tilde to denote the home directory.
ccc6cda3
JA
7393.TP
7394.B \-p
7395Print the directory stack with one entry per line.
7396.TP
7397.B \-v
7398Print the directory stack with one entry per line,
7399prefixing each entry with its index in the stack.
b28ff8c9
CR
7400.TP
7401\fB+\fP\fIn\fP
7402Displays the \fIn\fPth entry counting from the left of the list
7403shown by
7404.B dirs
7405when invoked without options, starting with zero.
7406.TP
7407\fB\-\fP\fIn\fP
7408Displays the \fIn\fPth entry counting from the right of the list
7409shown by
7410.B dirs
7411when invoked without options, starting with zero.
726f6388
JA
7412.PD
7413.PP
7414The return value is 0 unless an
cce855bc 7415invalid option is supplied or \fIn\fP indexes beyond the end
726f6388
JA
7416of the directory stack.
7417.RE
7418.TP
cce855bc 7419\fBdisown\fP [\fB\-ar\fP] [\fB\-h\fP] [\fIjobspec\fP ...]
b28ff8c9 7420Without options, remove each
ccc6cda3 7421.I jobspec
b28ff8c9 7422from the table of active jobs.
d3ad40de
CR
7423If
7424.I jobspec
984a1947 7425is not present, and neither \fB\-a\fP nor \fB\-r\fP is supplied,
d3ad40de 7426the shell's notion of the \fIcurrent job\fP is used.
cce855bc
JA
7427If the \fB\-h\fP option is given, each
7428.I jobspec
7429is not removed from the table, but is marked so that
ccc6cda3
JA
7430.SM
7431.B SIGHUP
7432is not sent to the job if the shell receives a
7433.SM
7434.BR SIGHUP .
7435If no
7436.I jobspec
cce855bc
JA
7437is present, and neither the
7438.B \-a
7439nor the
7440.B \-r
7441option is supplied, the \fIcurrent job\fP is used.
7442If no
7443.I jobspec
7444is supplied, the
7445.B \-a
7446option means to remove or mark all jobs; the
7447.B \-r
7448option without a
7449.I jobspec
7450argument restricts operation to running jobs.
7451The return value is 0 unless a
ccc6cda3
JA
7452.I jobspec
7453does not specify a valid job.
7454.TP
726f6388 7455\fBecho\fP [\fB\-neE\fP] [\fIarg\fP ...]
ccc6cda3 7456Output the \fIarg\fPs, separated by spaces, followed by a newline.
f6da9f85 7457The return status is 0 unless a write error occurs.
ccc6cda3 7458If \fB\-n\fP is specified, the trailing newline is
726f6388
JA
7459suppressed. If the \fB\-e\fP option is given, interpretation of
7460the following backslash-escaped characters is enabled. The
7461.B \-E
7462option disables the interpretation of these escape characters,
7463even on systems where they are interpreted by default.
28ef6c31 7464The \fBxpg_echo\fP shell option may be used to
bb70624e
JA
7465dynamically determine whether or not \fBecho\fP expands these
7466escape characters by default.
ccc6cda3 7467.B echo
3ffb039a 7468does not interpret \fB\-\-\fP to mean the end of options.
ccc6cda3
JA
7469.B echo
7470interprets the following escape sequences:
726f6388
JA
7471.RS
7472.PD 0
7473.TP
7474.B \ea
7475alert (bell)
7476.TP
7477.B \eb
7478backspace
7479.TP
7480.B \ec
2e4498b3 7481suppress further output
726f6388 7482.TP
ccc6cda3 7483.B \ee
9ec5ed66
CR
7484.TP
7485.B \eE
ccc6cda3
JA
7486an escape character
7487.TP
726f6388
JA
7488.B \ef
7489form feed
7490.TP
7491.B \en
7492new line
7493.TP
7494.B \er
7495carriage return
7496.TP
7497.B \et
7498horizontal tab
7499.TP
7500.B \ev
7501vertical tab
7502.TP
7503.B \e\e
7504backslash
7505.TP
7117c2d2
JA
7506.B \e0\fInnn\fP
7507the eight-bit character whose value is the octal value \fInnn\fP
7508(zero to three octal digits)
7509.TP
f73dda09
JA
7510.B \ex\fIHH\fP
7511the eight-bit character whose value is the hexadecimal value \fIHH\fP
7512(one or two hex digits)
eb0b2ad8
CR
7513.TP
7514.B \eu\fIHHHH\fP
7515the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
7516\fIHHHH\fP (one to four hex digits)
7517.TP
7518.B \eU\fIHHHHHHHH\fP
7519the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
7520\fIHHHHHHHH\fP (one to eight hex digits)
726f6388
JA
7521.PD
7522.RE
7523.TP
d3ad40de 7524\fBenable\fP [\fB\-a\fP] [\fB\-dnps\fP] [\fB\-f\fP \fIfilename\fP] [\fIname\fP ...]
cce855bc
JA
7525Enable and disable builtin shell commands.
7526Disabling a builtin allows a disk command which has the same name
bb70624e 7527as a shell builtin to be executed without specifying a full pathname,
cce855bc 7528even though the shell normally searches for builtins before disk commands.
726f6388
JA
7529If \fB\-n\fP is used, each \fIname\fP
7530is disabled; otherwise,
7531\fInames\fP are enabled. For example, to use the
7532.B test
7533binary found via the
7534.SM
7535.B PATH
ccc6cda3 7536instead of the shell builtin version, run
28ef6c31
JA
7537.if t \f(CWenable -n test\fP.
7538.if n ``enable -n test''.
ccc6cda3
JA
7539The
7540.B \-f
7541option means to load the new builtin command
7542.I name
7543from shared object
7544.IR filename ,
7545on systems that support dynamic loading. The
7546.B \-d
7547option will delete a builtin previously loaded with
7548.BR \-f .
7549If no \fIname\fP arguments are given, or if the
7550.B \-p
7551option is supplied, a list of shell builtins is printed.
7552With no other option arguments, the list consists of all enabled
7553shell builtins.
7554If \fB\-n\fP is supplied, only disabled builtins are printed.
7555If \fB\-a\fP is supplied, the list printed includes all builtins, with an
726f6388 7556indication of whether or not each is enabled.
ccc6cda3
JA
7557If \fB\-s\fP is supplied, the output is restricted to the POSIX
7558\fIspecial\fP builtins.
726f6388
JA
7559The return value is 0 unless a
7560.I name
bb70624e 7561is not a shell builtin or there is an error loading a new builtin
ccc6cda3 7562from a shared object.
726f6388
JA
7563.TP
7564\fBeval\fP [\fIarg\fP ...]
7565The \fIarg\fPs are read and concatenated together into a single
7566command. This command is then read and executed by the shell, and
ccc6cda3
JA
7567its exit status is returned as the value of
7568.BR eval .
7569If there are no
726f6388
JA
7570.IR args ,
7571or only null arguments,
7572.B eval
ccc6cda3 7573returns 0.
726f6388 7574.TP
cce855bc 7575\fBexec\fP [\fB\-cl\fP] [\fB\-a\fP \fIname\fP] [\fIcommand\fP [\fIarguments\fP]]
726f6388
JA
7576If
7577.I command
7578is specified, it replaces the shell.
7579No new process is created. The
7580.I arguments
7581become the arguments to \fIcommand\fP.
ccc6cda3
JA
7582If the
7583.B \-l
7584option is supplied,
d3ad40de 7585the shell places a dash at the beginning of the zeroth argument passed to
726f6388 7586.IR command .
ccc6cda3
JA
7587This is what
7588.IR login (1)
7589does. The
7590.B \-c
7591option causes
7592.I command
7593to be executed with an empty environment. If
7594.B \-a
7595is supplied, the shell passes
7596.I name
b28ff8c9
CR
7597as the zeroth argument to the executed command.
7598If
ccc6cda3 7599.I command
726f6388 7600cannot be executed for some reason, a non-interactive shell exits,
b28ff8c9 7601unless the
ccc6cda3 7602.B execfail
b28ff8c9
CR
7603shell option
7604is enabled. In that case, it returns failure.
ccc6cda3 7605An interactive shell returns failure if the file cannot be executed.
726f6388
JA
7606If
7607.I command
7608is not specified, any redirections take effect in the current shell,
cce855bc
JA
7609and the return status is 0. If there is a redirection error, the
7610return status is 1.
726f6388
JA
7611.TP
7612\fBexit\fP [\fIn\fP]
7613Cause the shell to exit
7614with a status of \fIn\fP. If
7615.I n
7616is omitted, the exit status
7617is that of the last command executed.
7618A trap on
7619.SM
7620.B EXIT
7621is executed before the shell terminates.
7622.TP
ccc6cda3 7623\fBexport\fP [\fB\-fn\fP\^] [\fIname\fP[=\fIword\fP]] ...
7117c2d2 7624.PD 0
726f6388
JA
7625.TP
7626.B export \-p
7627.PD
7628The supplied
7629.I names
7630are marked for automatic export to the environment of
7631subsequently executed commands. If the
7632.B \-f
7633option is given,
7634the
7635.I names
7636refer to functions.
7637If no
7638.I names
7639are given, or if the
7640.B \-p
7641option is supplied, a list
b28ff8c9 7642of names of all exported variables is printed.
726f6388
JA
7643The
7644.B \-n
5e13499c
CR
7645option causes the export property to be removed from each
7646\fIname\fP.
d3a24ed2
CR
7647If a variable name is followed by =\fIword\fP, the value of
7648the variable is set to \fIword\fP.
726f6388 7649.B export
cce855bc 7650returns an exit status of 0 unless an invalid option is
726f6388 7651encountered,
cce855bc 7652one of the \fInames\fP is not a valid shell variable name, or
726f6388
JA
7653.B \-f
7654is supplied with a
7655.I name
7656that is not a function.
7657.TP
d3ad40de 7658\fBfc\fP [\fB\-e\fP \fIename\fP] [\fB\-lnr\fP] [\fIfirst\fP] [\fIlast\fP]
7117c2d2 7659.PD 0
726f6388
JA
7660.TP
7661\fBfc\fP \fB\-s\fP [\fIpat\fP=\fIrep\fP] [\fIcmd\fP]
7662.PD
b28ff8c9 7663The first form selects a range of commands from
726f6388
JA
7664.I first
7665to
7666.I last
b28ff8c9 7667from the history list and displays or edits and re-executes them.
726f6388
JA
7668.I First
7669and
7670.I last
7671may be specified as a string (to locate the last command beginning
7672with that string) or as a number (an index into the history list,
7673where a negative number is used as an offset from the current
7674command number). If
7675.I last
7676is not specified it is set to
7677the current command for listing (so that
bb70624e
JA
7678.if n ``fc \-l \-10''
7679.if t \f(CWfc \-l \-10\fP
726f6388
JA
7680prints the last 10 commands) and to
7681.I first
7682otherwise.
7683If
7684.I first
7685is not specified it is set to the previous
7686command for editing and \-16 for listing.
7687.sp 1
7688The
7689.B \-n
cce855bc 7690option suppresses
726f6388
JA
7691the command numbers when listing. The
7692.B \-r
cce855bc 7693option reverses the order of
726f6388
JA
7694the commands. If the
7695.B \-l
cce855bc 7696option is given,
726f6388
JA
7697the commands are listed on
7698standard output. Otherwise, the editor given by
7699.I ename
7700is invoked
7701on a file containing those commands. If
7702.I ename
7703is not given, the
7704value of the
7705.SM
7706.B FCEDIT
7707variable is used, and
7708the value of
7709.SM
7710.B EDITOR
7711if
7712.SM
7713.B FCEDIT
7714is not set. If neither variable is set,
7715.FN vi
7716is used. When editing is complete, the edited commands are
7717echoed and executed.
7718.sp 1
7719In the second form, \fIcommand\fP is re-executed after each instance
7720of \fIpat\fP is replaced by \fIrep\fP.
b28ff8c9 7721\fICommand\fP is intepreted the same as \fIfirst\fP above.
ccc6cda3 7722A useful alias to use with this is
d3a24ed2 7723.if n ``r="fc -s"'',
ccc6cda3
JA
7724.if t \f(CWr='fc \-s'\fP,
7725so that typing
7726.if n ``r cc''
7727.if t \f(CWr cc\fP
7728runs the last command beginning with
7729.if n ``cc''
7730.if t \f(CWcc\fP
7731and typing
7732.if n ``r''
7733.if t \f(CWr\fP
726f6388
JA
7734re-executes the last command.
7735.sp 1
cce855bc 7736If the first form is used, the return value is 0 unless an invalid
726f6388
JA
7737option is encountered or
7738.I first
7739or
7740.I last
7741specify history lines out of range.
7742If the
7743.B \-e
7744option is supplied, the return value is the value of the last
7745command executed or failure if an error occurs with the temporary
7746file of commands. If the second form is used, the return status
7747is that of the command re-executed, unless
7748.I cmd
7749does not specify a valid history line, in which case
7750.B fc
7751returns failure.
7752.TP
7753\fBfg\fP [\fIjobspec\fP]
cce855bc 7754Resume
726f6388 7755.I jobspec
cce855bc
JA
7756in the foreground, and make it the current job.
7757If
726f6388
JA
7758.I jobspec
7759is not present, the shell's notion of the \fIcurrent job\fP is used.
7760The return value is that of the command placed into the foreground,
7761or failure if run when job control is disabled or, when run with
7762job control enabled, if
7763.I jobspec
7764does not specify a valid job or
7765.I jobspec
7766specifies a job that was started without job control.
7767.TP
7768\fBgetopts\fP \fIoptstring\fP \fIname\fP [\fIargs\fP]
7769.B getopts
7770is used by shell procedures to parse positional parameters.
7771.I optstring
bb70624e 7772contains the option characters to be recognized; if a character
726f6388
JA
7773is followed by a colon, the option is expected to have an
7774argument, which should be separated from it by white space.
bb70624e
JA
7775The colon and question mark characters may not be used as
7776option characters.
726f6388
JA
7777Each time it is invoked,
7778.B getopts
7779places the next option in the shell variable
7780.IR name ,
7781initializing
7782.I name
7783if it does not exist,
7784and the index of the next argument to be processed into the
7785variable
7786.SM
7787.BR OPTIND .
7788.SM
7789.B OPTIND
7790is initialized to 1 each time the shell or a shell script
7791is invoked. When an option requires an argument,
7792.B getopts
7793places that argument into the variable
7794.SM
7795.BR OPTARG .
7796The shell does not reset
7797.SM
7798.B OPTIND
7799automatically; it must be manually reset between multiple
7800calls to
7801.B getopts
7802within the same shell invocation if a new set of parameters
7803is to be used.
7804.sp 1
cce855bc
JA
7805When the end of options is encountered, \fBgetopts\fP exits with a
7806return value greater than zero.
984a1947
CR
7807.SM
7808.B OPTIND
7809is set to the index of the first non-option argument,
dc60d4e0 7810and \fIname\fP is set to ?.
cce855bc
JA
7811.sp 1
7812.B getopts
7813normally parses the positional parameters, but if more arguments are
7814given in
7815.IR args ,
7816.B getopts
7817parses those instead.
7818.sp 1
726f6388
JA
7819.B getopts
7820can report errors in two ways. If the first character of
7821.I optstring
7822is a colon,
7823.I silent
b28ff8c9 7824error reporting is used. In normal operation, diagnostic messages
cce855bc 7825are printed when invalid options or missing option arguments are
726f6388
JA
7826encountered.
7827If the variable
7828.SM
7829.B OPTERR
cce855bc 7830is set to 0, no error messages will be displayed, even if the first
726f6388
JA
7831character of
7832.I optstring
7833is not a colon.
7834.sp 1
cce855bc 7835If an invalid option is seen,
726f6388
JA
7836.B getopts
7837places ? into
7838.I name
7839and, if not silent,
7840prints an error message and unsets
7841.SM
7842.BR OPTARG .
7843If
7844.B getopts
7845is silent,
7846the option character found is placed in
7847.SM
7848.B OPTARG
7849and no diagnostic message is printed.
7850.sp 1
7851If a required argument is not found, and
7852.B getopts
7853is not silent,
7854a question mark (\^\fB?\fP\^) is placed in
7855.IR name ,
f73dda09 7856.SM
726f6388
JA
7857.B OPTARG
7858is unset, and a diagnostic message is printed.
7859If
7860.B getopts
7861is silent, then a colon (\^\fB:\fP\^) is placed in
7862.I name
7863and
7864.SM
7865.B OPTARG
7866is set to the option character found.
7867.sp 1
7868.B getopts
726f6388
JA
7869returns true if an option, specified or unspecified, is found.
7870It returns false if the end of options is encountered or an
7871error occurs.
7872.TP
7117c2d2 7873\fBhash\fP [\fB\-lr\fP] [\fB\-p\fP \fIfilename\fP] [\fB\-dt\fP] [\fIname\fP]
4691dc6b
CR
7874Each time \fBhash\fP is invoked,
7875the full pathname of the command
7876.I name
7877is determined by searching
ccc6cda3
JA
7878the directories in
7879.B $PATH
4691dc6b 7880and remembered. Any previously-remembered pathname is discarded.
ccc6cda3
JA
7881If the
7882.B \-p
7883option is supplied, no path search is performed, and
7884.I filename
b28ff8c9 7885is used as the full filename of the command.
ccc6cda3 7886The
726f6388
JA
7887.B \-r
7888option causes the shell to forget all
f73dda09 7889remembered locations.
7117c2d2
JA
7890The
7891.B \-d
7892option causes the shell to forget the remembered location of each \fIname\fP.
f73dda09
JA
7893If the
7894.B \-t
7895option is supplied, the full pathname to which each \fIname\fP corresponds
7896is printed. If multiple \fIname\fP arguments are supplied with \fB\-t\fP,
7897the \fIname\fP is printed before the hashed full pathname.
7117c2d2
JA
7898The
7899.B \-l
7900option causes output to be displayed in a format that may be reused as input.
7901If no arguments are given, or if only \fB\-l\fP is supplied,
7902information about remembered commands is printed.
ccc6cda3 7903The return status is true unless a
726f6388 7904.I name
cce855bc 7905is not found or an invalid option is supplied.
726f6388 7906.TP
6a8fd0ed 7907\fBhelp\fP [\fB\-dms\fP] [\fIpattern\fP]
726f6388
JA
7908Display helpful information about builtin commands. If
7909.I pattern
7910is specified,
7911.B help
7912gives detailed help on all commands matching
7913.IR pattern ;
ccc6cda3 7914otherwise help for all the builtins and shell control structures
bb70624e 7915is printed.
6a8fd0ed
CR
7916.RS
7917.PD 0
7918.TP
7919.B \-d
7920Display a short description of each \fIpattern\fP
7921.TP
6932f7f5 7922.B \-m
6a8fd0ed
CR
7923Display the description of each \fIpattern\fP in a manpage-like format
7924.TP
7925.B \-s
7926Display only a short usage synopsis for each \fIpattern\fP
7927.PD
54a1fa7c 7928.PP
bb70624e 7929The return status is 0 unless no command matches
726f6388 7930.IR pattern .
54a1fa7c 7931.RE
726f6388 7932.TP
bb70624e 7933\fBhistory [\fIn\fP]
7117c2d2 7934.PD 0
bb70624e
JA
7935.TP
7936\fBhistory\fP \fB\-c\fP
7937.TP
7938\fBhistory \-d\fP \fIoffset\fP
ccc6cda3
JA
7939.TP
7940\fBhistory\fP \fB\-anrw\fP [\fIfilename\fP]
726f6388 7941.TP
ccc6cda3
JA
7942\fBhistory\fP \fB\-p\fP \fIarg\fP [\fIarg ...\fP]
7943.TP
7944\fBhistory\fP \fB\-s\fP \fIarg\fP [\fIarg ...\fP]
726f6388
JA
7945.PD
7946With no options, display the command
7947history list with line numbers. Lines listed
7948with a
7949.B *
7950have been modified. An argument of
7951.I n
7952lists only the last
7953.I n
d3a24ed2 7954lines.
984a1947
CR
7955If the shell variable
7956.SM
7957.B HISTTIMEFORMAT
7958is set and not null,
d3a24ed2
CR
7959it is used as a format string for \fIstrftime\fP(3) to display
7960the time stamp associated with each displayed history entry.
7961No intervening blank is printed between the formatted time stamp
7962and the history line.
7963If \fIfilename\fP is supplied, it is used as the
726f6388
JA
7964name of the history file; if not, the value of
7965.SM
7966.B HISTFILE
7967is used. Options, if supplied, have the following meanings:
7968.RS
7969.PD 0
7970.TP
bb70624e
JA
7971.B \-c
7972Clear the history list by deleting all the entries.
7973.TP
7974\fB\-d\fP \fIoffset\fP
7975Delete the history entry at position \fIoffset\fP.
7976.TP
726f6388
JA
7977.B \-a
7978Append the ``new'' history lines (history lines entered since the
ccc6cda3 7979beginning of the current \fBbash\fP session) to the history file.
726f6388
JA
7980.TP
7981.B \-n
7982Read the history lines not already read from the history
7983file into the current history list. These are lines
7984appended to the history file since the beginning of the
7985current \fBbash\fP session.
7986.TP
7987.B \-r
7988Read the contents of the history file
b28ff8c9 7989and append them to the current history list.
726f6388
JA
7990.TP
7991.B \-w
b28ff8c9 7992Write the current history list to the history file, overwriting the
726f6388 7993history file's contents.
ccc6cda3 7994.TP
ccc6cda3
JA
7995.B \-p
7996Perform history substitution on the following \fIargs\fP and display
7997the result on the standard output.
7998Does not store the results in the history list.
7999Each \fIarg\fP must be quoted to disable normal history expansion.
8000.TP
8001.B \-s
8002Store the
8003.I args
8004in the history list as a single entry. The last command in the
8005history list is removed before the
8006.I args
8007are added.
726f6388
JA
8008.PD
8009.PP
984a1947
CR
8010If the
8011.SM
8012.B HISTTIMEFORMAT
8013variable is set, the time stamp information
d3ad40de
CR
8014associated with each history entry is written to the history file,
8015marked with the history comment character.
8016When the history file is read, lines beginning with the history
8017comment character followed immediately by a digit are interpreted
8018as timestamps for the previous history line.
bb70624e
JA
8019The return value is 0 unless an invalid option is encountered, an
8020error occurs while reading or writing the history file, an invalid
8021\fIoffset\fP is supplied as an argument to \fB\-d\fP, or the
8022history expansion supplied as an argument to \fB\-p\fP fails.
726f6388
JA
8023.RE
8024.TP
ccc6cda3 8025\fBjobs\fP [\fB\-lnprs\fP] [ \fIjobspec\fP ... ]
7117c2d2 8026.PD 0
726f6388
JA
8027.TP
8028\fBjobs\fP \fB\-x\fP \fIcommand\fP [ \fIargs\fP ... ]
8029.PD
ccc6cda3
JA
8030The first form lists the active jobs. The options have the following
8031meanings:
8032.RS
8033.PD 0
8034.TP
726f6388 8035.B \-l
ccc6cda3
JA
8036List process IDs
8037in addition to the normal information.
8038.TP
726f6388 8039.B \-n
ccc6cda3
JA
8040Display information only about jobs that have changed status since
8041the user was last notified of their status.
8042.TP
5cdaaf76
CR
8043.B \-p
8044List only the process ID of the job's process group
8045leader.
8046.TP
ccc6cda3 8047.B \-r
b28ff8c9 8048Display only running jobs.
ccc6cda3
JA
8049.TP
8050.B \-s
b28ff8c9 8051Display only stopped jobs.
ccc6cda3
JA
8052.PD
8053.PP
8054If
726f6388
JA
8055.I jobspec
8056is given, output is restricted to information about that job.
cce855bc
JA
8057The return status is 0 unless an invalid option is encountered
8058or an invalid
726f6388
JA
8059.I jobspec
8060is supplied.
ccc6cda3 8061.PP
726f6388
JA
8062If the
8063.B \-x
8064option is supplied,
8065.B jobs
8066replaces any
8067.I jobspec
8068found in
8069.I command
8070or
8071.I args
8072with the corresponding process group ID, and executes
8073.I command
8074passing it
8075.IR args ,
8076returning its exit status.
ccc6cda3 8077.RE
726f6388 8078.TP
ccc6cda3 8079\fBkill\fP [\fB\-s\fP \fIsigspec\fP | \fB\-n\fP \fIsignum\fP | \fB\-\fP\fIsigspec\fP] [\fIpid\fP | \fIjobspec\fP] ...
7117c2d2 8080.PD 0
726f6388 8081.TP
cce855bc 8082\fBkill\fP \fB\-l\fP [\fIsigspec\fP | \fIexit_status\fP]
726f6388
JA
8083.PD
8084Send the signal named by
8085.I sigspec
ccc6cda3
JA
8086or
8087.I signum
726f6388
JA
8088to the processes named by
8089.I pid
8090or
8091.IR jobspec .
8092.I sigspec
61deeb13 8093is either a case-insensitive signal name such as
726f6388
JA
8094.SM
8095.B SIGKILL
61deeb13 8096(with or without the
726f6388
JA
8097.SM
8098.B SIG
61deeb13
CR
8099prefix) or a signal number;
8100.I signum
8101is a signal number.
726f6388
JA
8102If
8103.I sigspec
8104is not present, then
8105.SM
8106.B SIGTERM
cce855bc
JA
8107is assumed.
8108An argument of
726f6388 8109.B \-l
cce855bc
JA
8110lists the signal names.
8111If any arguments are supplied when
726f6388 8112.B \-l
cce855bc
JA
8113is given, the names of the signals corresponding to the arguments are
8114listed, and the return status is 0.
8115The \fIexit_status\fP argument to
ccc6cda3 8116.B \-l
cce855bc
JA
8117is a number specifying either a signal number or the exit status of
8118a process terminated by a signal.
726f6388
JA
8119.B kill
8120returns true if at least one signal was successfully sent, or false
cce855bc 8121if an error occurs or an invalid option is encountered.
726f6388
JA
8122.TP
8123\fBlet\fP \fIarg\fP [\fIarg\fP ...]
8124Each
8125.I arg
8126is an arithmetic expression to be evaluated (see
8127.SM
984a1947
CR
8128.B "ARITHMETIC EVALUATION"
8129above).
726f6388
JA
8130If the last
8131.I arg
8132evaluates to 0,
8133.B let
8134returns 1; 0 is returned otherwise.
8135.TP
bb70624e 8136\fBlocal\fP [\fIoption\fP] [\fIname\fP[=\fIvalue\fP] ...]
cce855bc
JA
8137For each argument, a local variable named
8138.I name
8139is created, and assigned
726f6388 8140.IR value .
bb70624e 8141The \fIoption\fP can be any of the options accepted by \fBdeclare\fP.
726f6388
JA
8142When
8143.B local
8144is used within a function, it causes the variable
8145.I name
8146to have a visible scope restricted to that function and its children.
8147With no operands,
8148.B local
8149writes a list of local variables to the standard output. It is
8150an error to use
8151.B local
8152when not within a function. The return status is 0 unless
8153.B local
bb70624e 8154is used outside a function, an invalid
726f6388 8155.I name
bb70624e
JA
8156is supplied, or
8157\fIname\fP is a readonly variable.
726f6388
JA
8158.TP
8159.B logout
8160Exit a login shell.
8161.TP
09767ff0 8162\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
8163.PD 0
8164.TP
8165\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]
8166.PD
e1e48bba 8167Read lines from the standard input into the indexed array variable
6a8fd0ed
CR
8168.IR array ,
8169or from file descriptor
8170.IR fd
8171if the
8172.B \-u
8173option is supplied.
984a1947
CR
8174The variable
8175.SM
8176.B MAPFILE
8177is the default \fIarray\fP.
6a8fd0ed
CR
8178Options, if supplied, have the following meanings:
8179.RS
8180.PD 0
8181.TP
8182.B \-n
8183Copy at most
8184.I count
8185lines. If \fIcount\fP is 0, all lines are copied.
8186.TP
8187.B \-O
8188Begin assigning to
8189.I array
8190at index
8191.IR origin .
8192The default index is 0.
8193.TP
8194.B \-s
8195Discard the first \fIcount\fP lines read.
8196.TP
8197.B \-t
984a1947 8198Remove a trailing newline from each line read.
6a8fd0ed
CR
8199.TP
8200.B \-u
8201Read lines from file descriptor \fIfd\fP instead of the standard input.
8202.TP
8203.B \-C
8204Evaluate
8205.I callback
8206each time \fIquantum\fP lines are read. The \fB\-c\fP option specifies
8207.IR quantum .
8208.TP
8209.B \-c
8210Specify the number of lines read between each call to
8211.IR callback .
8212.PD
8213.PP
8214If
8215.B \-C
8216is specified without
8217.BR \-c ,
8218the default quantum is 5000.
e141c35a 8219When \fIcallback\fP is evaluated, it is supplied the index of the next
6faad625
CR
8220array element to be assigned and the line to be assigned to that element
8221as additional arguments.
e141c35a
CR
8222\fIcallback\fP is evaluated after the line is read but before the
8223array element is assigned.
6a8fd0ed
CR
8224.PP
8225If not supplied with an explicit origin, \fBmapfile\fP will clear \fIarray\fP
8226before assigning to it.
8227.PP
8228\fBmapfile\fP returns successfully unless an invalid option or option
e1e48bba
CR
8229argument is supplied, \fIarray\fP is invalid or unassignable, or if
8230\fIarray\fP is not an indexed array.
6a8fd0ed
CR
8231.RE
8232.TP
ccc6cda3 8233\fBpopd\fP [\-\fBn\fP] [+\fIn\fP] [\-\fIn\fP]
726f6388
JA
8234Removes entries from the directory stack. With no arguments,
8235removes the top directory from the stack, and performs a
8236.B cd
8237to the new top directory.
ccc6cda3 8238Arguments, if supplied, have the following meanings:
726f6388
JA
8239.RS
8240.PD 0
8241.TP
d3ad40de
CR
8242.B \-n
8243Suppresses the normal change of directory when removing directories
8244from the stack, so that only the stack is manipulated.
8245.TP
ccc6cda3
JA
8246\fB+\fP\fIn\fP
8247Removes the \fIn\fPth entry counting from the left of the list
726f6388
JA
8248shown by
8249.BR dirs ,
bb70624e
JA
8250starting with zero. For example:
8251.if n ``popd +0''
8252.if t \f(CWpopd +0\fP
8253removes the first directory,
8254.if n ``popd +1''
8255.if t \f(CWpopd +1\fP
8256the second.
726f6388 8257.TP
ccc6cda3
JA
8258\fB\-\fP\fIn\fP
8259Removes the \fIn\fPth entry counting from the right of the list
726f6388
JA
8260shown by
8261.BR dirs ,
bb70624e
JA
8262starting with zero. For example:
8263.if n ``popd -0''
8264.if t \f(CWpopd -0\fP
8265removes the last directory,
8266.if n ``popd -1''
8267.if t \f(CWpopd -1\fP
8268the next to last.
726f6388
JA
8269.PD
8270.PP
8271If the
8272.B popd
8273command is successful, a
8274.B dirs
8275is performed as well, and the return status is 0.
8276.B popd
cce855bc 8277returns false if an invalid option is encountered, the directory stack
726f6388
JA
8278is empty, a non-existent directory stack entry is specified, or the
8279directory change fails.
8280.RE
8281.TP
3ee6b87d 8282\fBprintf\fP [\fB\-v\fP \fIvar\fP] \fIformat\fP [\fIarguments\fP]
cce855bc
JA
8283Write the formatted \fIarguments\fP to the standard output under the
8284control of the \fIformat\fP.
6faad625
CR
8285The \fB\-v\fP option causes the output to be assigned to the variable
8286\fIvar\fP rather than being printed to the standard output.
8287.sp 1
cce855bc
JA
8288The \fIformat\fP is a character string which contains three types of objects:
8289plain characters, which are simply copied to standard output, character
8290escape sequences, which are converted and copied to the standard output, and
8291format specifications, each of which causes printing of the next successive
8292\fIargument\fP.
6faad625
CR
8293In addition to the standard \fIprintf\fP(1) format specifications,
8294\fBprintf\fP interprets the following extensions:
8295.RS
8296.PD 0
8297.TP
8298.B %b
8299causes
cce855bc 8300\fBprintf\fP to expand backslash escape sequences in the corresponding
5e13499c 8301\fIargument\fP (except that \fB\ec\fP terminates output, backslashes in
20587658 8302\fB\e\(aq\fP, \fB\e"\fP, and \fB\e?\fP are not removed, and octal escapes
6faad625
CR
8303beginning with \fB\e0\fP may contain up to four digits).
8304.TP
8305.B %q
8306causes \fBprintf\fP to output the corresponding
cce855bc 8307\fIargument\fP in a format that can be reused as shell input.
6faad625
CR
8308.TP
8309.B %(\fIdatefmt\fP)T
8310causes \fBprintf\fP to output the date-time string resulting from using
8311\fIdatefmt\fP as a format string for \fIstrftime\fP(3). The corresponding
8312\fIargument\fP is an integer representing the number of seconds since the
8313epoch. Two special argument values may be used: -1 represents the current
8314time, and -2 represents the time the shell was invoked.
8315.PD
8316.PP
112ff2a6
CR
8317Arguments to non-string format specifiers are treated as C constants,
8318except that a leading plus or minus sign is allowed, and if the leading
8319character is a single or double quote, the value is the ASCII value of
8320the following character.
6faad625 8321.PP
cce855bc
JA
8322The \fIformat\fP is reused as necessary to consume all of the \fIarguments\fP.
8323If the \fIformat\fP requires more \fIarguments\fP than are supplied, the
8324extra format specifications behave as if a zero value or null string, as
6faad625
CR
8325appropriate, had been supplied.
8326The return value is zero on success, non-zero on failure.
8327.RE
cce855bc 8328.TP
d3ad40de 8329\fBpushd\fP [\fB\-n\fP] [+\fIn\fP] [\-\fIn\fP]
7117c2d2 8330.PD 0
726f6388 8331.TP
d3ad40de 8332\fBpushd\fP [\fB\-n\fP] [\fIdir\fP]
726f6388
JA
8333.PD
8334Adds a directory to the top of the directory stack, or rotates
8335the stack, making the new top of the stack the current working
8336directory. With no arguments, exchanges the top two directories
8337and returns 0, unless the directory stack is empty.
ccc6cda3 8338Arguments, if supplied, have the following meanings:
726f6388
JA
8339.RS
8340.PD 0
8341.TP
d3ad40de
CR
8342.B \-n
8343Suppresses the normal change of directory when adding directories
8344to the stack, so that only the stack is manipulated.
8345.TP
ccc6cda3 8346\fB+\fP\fIn\fP
726f6388
JA
8347Rotates the stack so that the \fIn\fPth directory
8348(counting from the left of the list shown by
d166f048
JA
8349.BR dirs ,
8350starting with zero)
726f6388
JA
8351is at the top.
8352.TP
ccc6cda3 8353\fB\-\fP\fIn\fP
726f6388 8354Rotates the stack so that the \fIn\fPth directory
d166f048
JA
8355(counting from the right of the list shown by
8356.BR dirs ,
8357starting with zero) is at the top.
726f6388 8358.TP
bb70624e 8359.I dir
ccc6cda3 8360Adds
726f6388
JA
8361.I dir
8362to the directory stack at the top, making it the
19baff85
CR
8363new current working directory as if it had been supplied as the argument
8364to the \fBcd\fP builtin.
726f6388
JA
8365.PD
8366.PP
8367If the
8368.B pushd
8369command is successful, a
8370.B dirs
8371is performed as well.
8372If the first form is used,
8373.B pushd
8374returns 0 unless the cd to
8375.I dir
8376fails. With the second form,
8377.B pushd
8378returns 0 unless the directory stack is empty,
ccc6cda3 8379a non-existent directory stack element is specified,
726f6388
JA
8380or the directory change to the specified new current directory
8381fails.
8382.RE
8383.TP
ccc6cda3 8384\fBpwd\fP [\fB\-LP\fP]
bb70624e
JA
8385Print the absolute pathname of the current working directory.
8386The pathname printed contains no symbolic links if the
726f6388 8387.B \-P
ccc6cda3
JA
8388option is supplied or the
8389.B \-o physical
726f6388
JA
8390option to the
8391.B set
ccc6cda3
JA
8392builtin command is enabled.
8393If the
8394.B \-L
bb70624e 8395option is used, the pathname printed may contain symbolic links.
ccc6cda3 8396The return status is 0 unless an error occurs while
cce855bc
JA
8397reading the name of the current directory or an
8398invalid option is supplied.
726f6388 8399.TP
08e72d7a 8400\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
8401One line is read from the standard input, or from the file descriptor
8402\fIfd\fP supplied as an argument to the \fB\-u\fP option, and the first word
726f6388
JA
8403is assigned to the first
8404.IR name ,
8405the second word to the second
8406.IR name ,
cce855bc
JA
8407and so on, with leftover words and their intervening separators assigned
8408to the last
726f6388 8409.IR name .
7117c2d2 8410If there are fewer words read from the input stream than names,
cce855bc
JA
8411the remaining names are assigned empty values.
8412The characters in
726f6388
JA
8413.SM
8414.B IFS
cce855bc 8415are used to split the line into words.
b72432fd
JA
8416The backslash character (\fB\e\fP) may be used to remove any special
8417meaning for the next character read and for line continuation.
cce855bc 8418Options, if supplied, have the following meanings:
ccc6cda3
JA
8419.RS
8420.PD 0
8421.TP
bb70624e 8422.B \-a \fIaname\fP
ccc6cda3
JA
8423The words are assigned to sequential indices
8424of the array variable
8425.IR aname ,
8426starting at 0.
8427.I aname
8428is unset before any new values are assigned.
cce855bc 8429Other \fIname\fP arguments are ignored.
ccc6cda3 8430.TP
bb70624e
JA
8431.B \-d \fIdelim\fP
8432The first character of \fIdelim\fP is used to terminate the input line,
8433rather than newline.
8434.TP
ccc6cda3
JA
8435.B \-e
8436If the standard input
8437is coming from a terminal,
8438.B readline
8439(see
8440.SM
8441.B READLINE
8442above) is used to obtain the line.
14e8b2a7
CR
8443Readline uses the current (or default, if line editing was not previously
8444active) editing settings.
bb70624e 8445.TP
1d0e1a34
CR
8446.B \-i \fItext\fP
8447If
8448.B readline
8449is being used to read the line, \fItext\fP is placed into the editing
8450buffer before editing begins.
8451.TP
bb70624e
JA
8452.B \-n \fInchars\fP
8453\fBread\fP returns after reading \fInchars\fP characters rather than
08e72d7a
CR
8454waiting for a complete line of input, but honor a delimiter if fewer
8455than \fInchars\fP characters are read before the delimiter.
8456.TP
8457.B \-N \fInchars\fP
8458\fBread\fP returns after reading exactly \fInchars\fP characters rather
8459than waiting for a complete line of input, unless EOF is encountered or
a3143574
CR
8460\fBread\fP times out.
8461Delimiter characters encountered in the input are
8462not treated specially and do not cause \fBread\fP to return until
8463\fInchars\fP characters are read.
bb70624e
JA
8464.TP
8465.B \-p \fIprompt\fP
f73dda09 8466Display \fIprompt\fP on standard error, without a
bb70624e
JA
8467trailing newline, before attempting to read any input. The prompt
8468is displayed only if input is coming from a terminal.
8469.TP
8470.B \-r
8471Backslash does not act as an escape character.
8472The backslash is considered to be part of the line.
8473In particular, a backslash-newline pair may not be used as a line
8474continuation.
8475.TP
8476.B \-s
8477Silent mode. If input is coming from a terminal, characters are
8478not echoed.
8479.TP
8480.B \-t \fItimeout\fP
8481Cause \fBread\fP to time out and return failure if a complete line of
8482input is not read within \fItimeout\fP seconds.
4ac1ff98
CR
8483\fItimeout\fP may be a decimal number with a fractional portion following
8484the decimal point.
e33f2203
CR
8485This option is only effective if \fBread\fP is reading input from a
8486terminal, pipe, or other special file; it has no effect when reading
8487from regular files.
b13b8a87
CR
8488If \fItimeout\fP is 0, \fBread\fP returns immediately, without trying to
8489read any data. The exit statis is 0 if input is available on
8490the specified file descriptor, non-zero otherwise.
e33f2203 8491The exit status is greater than 128 if the timeout is exceeded.
7117c2d2 8492.TP
0f445e6c 8493.B \-u \fIfd\fP
7117c2d2 8494Read input from file descriptor \fIfd\fP.
ccc6cda3
JA
8495.PD
8496.PP
8497If no
726f6388
JA
8498.I names
8499are supplied, the line read is assigned to the variable
8500.SM
8501.BR REPLY .
7117c2d2 8502The return code is zero, unless end-of-file is encountered, \fBread\fP
ba4ab055
CR
8503times out (in which case the return code is greater than 128),
8504a variable assignment error (such as assigning to a readonly variable) occurs,
8505or an invalid file descriptor is supplied as the argument to \fB\-u\fP.
ccc6cda3 8506.RE
726f6388 8507.TP
54a1fa7c 8508\fBreadonly\fP [\fB\-aAf\fP] [\fB\-p\fP] [\fIname\fP[=\fIword\fP] ...]
726f6388
JA
8509.PD
8510The given
ccc6cda3
JA
8511\fInames\fP are marked readonly; the values of these
8512.I names
726f6388
JA
8513may not be changed by subsequent assignment.
8514If the
8515.B \-f
8516option is supplied, the functions corresponding to the
8517\fInames\fP are so
ccc6cda3
JA
8518marked.
8519The
8520.B \-a
fdf670ea
CR
8521option restricts the variables to indexed arrays; the
8522.B \-A
8523option restricts the variables to associative arrays.
54a1fa7c
CR
8524If both options are supplied,
8525.B \-A
8526takes precedence.
ccc6cda3
JA
8527If no
8528.I name
8529arguments are given, or if the
726f6388 8530.B \-p
ccc6cda3 8531option is supplied, a list of all readonly names is printed.
54a1fa7c
CR
8532The other options may be used to restrict the output to a subset of
8533the set of readonly names.
cce855bc
JA
8534The
8535.B \-p
bb70624e
JA
8536option causes output to be displayed in a format that
8537may be reused as input.
d3a24ed2
CR
8538If a variable name is followed by =\fIword\fP, the value of
8539the variable is set to \fIword\fP.
cce855bc 8540The return status is 0 unless an invalid option is encountered,
ccc6cda3
JA
8541one of the
8542.I names
cce855bc 8543is not a valid shell variable name, or
726f6388
JA
8544.B \-f
8545is supplied with a
8546.I name
8547that is not a function.
8548.TP
8549\fBreturn\fP [\fIn\fP]
b28ff8c9
CR
8550Causes a function to stop executing and return the value specified by
8551.I n
8552to its caller.
726f6388
JA
8553If
8554.I n
8555is omitted, the return status is that of the last command
b28ff8c9
CR
8556executed in the function body. If
8557.B return
8558is used outside a function,
726f6388
JA
8559but during execution of a script by the
8560.B .
8561(\fBsource\fP) command, it causes the shell to stop executing
8562that script and return either
8563.I n
8564or the exit status of the last command executed within the
b28ff8c9 8565script as the exit status of the script.
3d4f66ca
CR
8566If \fIn\fP is supplied, the return value is its least significant
85678 bits.
b28ff8c9
CR
8568The return status is non-zero if
8569.B return
3d4f66ca 8570is supplied a non-numeric argument, or
b28ff8c9
CR
8571is used outside a
8572function and not during execution of a script by \fB.\fP\^ or \fBsource\fP.
d3a24ed2
CR
8573Any command associated with the \fBRETURN\fP trap is executed
8574before execution resumes after the function or script.
726f6388 8575.TP
dc60d4e0 8576\fBset\fP [\fB\-\-abefhkmnptuvxBCEHPT\fP] [\fB\-o\fP \fIoption\-name\fP] [\fIarg\fP ...]
d3ad40de
CR
8577.PD 0
8578.TP
dc60d4e0 8579\fBset\fP [\fB+abefhkmnptuvxBCEHPT\fP] [\fB+o\fP \fIoption\-name\fP] [\fIarg\fP ...]
d3ad40de 8580.PD
ccc6cda3 8581Without options, the name and value of each shell variable are displayed
54cdd75a
CR
8582in a format that can be reused as input
8583for setting or resetting the currently-set variables.
8584Read-only variables cannot be reset.
8585In \fIposix mode\fP, only shell variables are listed.
cce855bc 8586The output is sorted according to the current locale.
ccc6cda3 8587When options are specified, they set or unset shell attributes.
626d0694 8588Any arguments remaining after option processing are treated
ccc6cda3
JA
8589as values for the positional parameters and are assigned, in order, to
8590.BR $1 ,
8591.BR $2 ,
8592.B ...
8593.BR $\fIn\fP .
8594Options, if specified, have the following meanings:
726f6388
JA
8595.RS
8596.PD 0
8597.TP 8
8598.B \-a
5e13499c
CR
8599Automatically mark variables and functions which are modified or
8600created for export to the environment of subsequent commands.
726f6388
JA
8601.TP 8
8602.B \-b
ccc6cda3
JA
8603Report the status of terminated background jobs
8604immediately, rather than before the next primary prompt. This is
8605effective only when job control is enabled.
726f6388
JA
8606.TP 8
8607.B \-e
15825757
CR
8608Exit immediately if a
8609\fIpipeline\fP (which may consist of a single \fIsimple command\fP),
8610a \fIlist\fP,
8611or a \fIcompound command\fP
8612(see
726f6388
JA
8613.SM
8614.B SHELL GRAMMAR
15825757 8615above), exits with a non-zero status.
d3a24ed2
CR
8616The shell does not exit if the
8617command that fails is part of the command list immediately following a
8618.B while
726f6388 8619or
d3a24ed2
CR
8620.B until
8621keyword,
4b9cc222 8622part of the test following the
d3ad40de 8623.B if
4b9cc222
CR
8624or
8625.B elif
8626reserved words, part of any command executed in a
726f6388
JA
8627.B &&
8628or
adc6cff5
CR
8629.B ||
8630list except the command following the final \fB&&\fP or \fB||\fP,
d3ad40de
CR
8631any command in a pipeline but the last,
8632or if the command's return value is
a05a1337 8633being inverted with
726f6388 8634.BR ! .
15825757
CR
8635If a compound command other than a subshell
8636returns a non-zero status because a command failed
8637while \fB\-e\fP was being ignored, the shell does not exit.
f73dda09 8638A trap on \fBERR\fP, if set, is executed before the shell exits.
a05a1337
CR
8639This option applies to the shell environment and each subshell environment
8640separately (see
984a1947 8641.SM
a05a1337
CR
8642.B "COMMAND EXECUTION ENVIRONMENT"
8643above), and may cause
8644subshells to exit before executing all the commands in the subshell.
726f6388
JA
8645.TP 8
8646.B \-f
8647Disable pathname expansion.
8648.TP 8
8649.B \-h
ccc6cda3 8650Remember the location of commands as they are looked up for execution.
cce855bc 8651This is enabled by default.
726f6388
JA
8652.TP 8
8653.B \-k
ccc6cda3
JA
8654All arguments in the form of assignment statements
8655are placed in the environment for a command, not just
8656those that precede the command name.
726f6388
JA
8657.TP 8
8658.B \-m
cce855bc 8659Monitor mode. Job control is enabled. This option is on
726f6388
JA
8660by default for interactive shells on systems that support
8661it (see
8662.SM
8663.B JOB CONTROL
f6da9f85
CR
8664above).
8665All processes run in a separate process group.
8666When a background job completes, the shell prints a line
8667containing its exit status.
726f6388
JA
8668.TP 8
8669.B \-n
8670Read commands but do not execute them. This may be used to
ccc6cda3 8671check a shell script for syntax errors. This is ignored by
726f6388
JA
8672interactive shells.
8673.TP 8
ccc6cda3
JA
8674.B \-o \fIoption\-name\fP
8675The \fIoption\-name\fP can be one of the following:
726f6388
JA
8676.RS
8677.TP 8
8678.B allexport
8679Same as
8680.BR \-a .
8681.TP 8
8682.B braceexpand
ccc6cda3
JA
8683Same as
8684.BR \-B .
726f6388
JA
8685.TP 8
8686.B emacs
8687Use an emacs-style command line editing interface. This is enabled
8688by default when the shell is interactive, unless the shell is started
8689with the
ccc6cda3 8690.B \-\-noediting
726f6388 8691option.
10a4e415 8692This also affects the editing interface used for \fBread \-e\fP.
726f6388 8693.TP 8
a3143574
CR
8694.B errexit
8695Same as
8696.BR \-e .
8697.TP 8
d3a24ed2
CR
8698.B errtrace
8699Same as
8700.BR \-E .
8701.TP 8
8702.B functrace
8703Same as
8704.BR \-T .
8705.TP 8
ccc6cda3
JA
8706.B hashall
8707Same as
8708.BR \-h .
8709.TP 8
726f6388
JA
8710.B histexpand
8711Same as
8712.BR \-H .
8713.TP 8
ccc6cda3
JA
8714.B history
8715Enable command history, as described above under
8716.SM
8717.BR HISTORY .
8718This option is on by default in interactive shells.
8719.TP 8
726f6388 8720.B ignoreeof
28ef6c31
JA
8721The effect is as if the shell command
8722.if t \f(CWIGNOREEOF=10\fP
8723.if n ``IGNOREEOF=10''
8724had been executed
726f6388
JA
8725(see
8726.B Shell Variables
8727above).
8728.TP 8
ccc6cda3
JA
8729.B keyword
8730Same as
8731.BR \-k .
726f6388
JA
8732.TP 8
8733.B monitor
8734Same as
8735.BR \-m .
8736.TP 8
8737.B noclobber
8738Same as
8739.BR \-C .
8740.TP 8
8741.B noexec
8742Same as
8743.BR \-n .
8744.TP 8
8745.B noglob
8746Same as
8747.BR \-f .
57a3f689 8748.TP 8
f73dda09
JA
8749.B nolog
8750Currently ignored.
726f6388 8751.TP 8
726f6388
JA
8752.B notify
8753Same as
8754.BR \-b .
8755.TP 8
8756.B nounset
8757Same as
8758.BR \-u .
8759.TP 8
ccc6cda3
JA
8760.B onecmd
8761Same as
8762.BR \-t .
8763.TP 8
726f6388
JA
8764.B physical
8765Same as
8766.BR \-P .
8767.TP 8
d3a24ed2
CR
8768.B pipefail
8769If set, the return value of a pipeline is the value of the last
8770(rightmost) command to exit with a non-zero status, or zero if all
8771commands in the pipeline exit successfully.
8772This option is disabled by default.
8773.TP 8
726f6388 8774.B posix
ccc6cda3
JA
8775Change the behavior of
8776.B bash
8777where the default operation differs
ac18b312 8778from the POSIX standard to match the standard (\fIposix mode\fP).
726f6388
JA
8779.TP 8
8780.B privileged
8781Same as
8782.BR \-p .
8783.TP 8
8784.B verbose
8785Same as
8786.BR \-v .
8787.TP 8
8788.B vi
8789Use a vi-style command line editing interface.
10a4e415 8790This also affects the editing interface used for \fBread \-e\fP.
726f6388
JA
8791.TP 8
8792.B xtrace
8793Same as
8794.BR \-x .
ccc6cda3 8795.sp .5
726f6388 8796.PP
ccc6cda3
JA
8797If
8798.B \-o
8799is supplied with no \fIoption\-name\fP, the values of the current options are
726f6388 8800printed.
ccc6cda3
JA
8801If
8802.B +o
8803is supplied with no \fIoption\-name\fP, a series of
8804.B set
8805commands to recreate the current option settings is displayed on
8806the standard output.
726f6388
JA
8807.RE
8808.TP 8
8809.B \-p
8810Turn on
8811.I privileged
8812mode. In this mode, the
bb70624e 8813.SM
726f6388 8814.B $ENV
b72432fd 8815and
bb70624e 8816.SM
b72432fd
JA
8817.B $BASH_ENV
8818files are not processed, shell functions are not inherited from the
bb70624e
JA
8819environment, and the
8820.SM
e77a3058 8821.BR SHELLOPTS ,
984a1947 8822.SM
691aebcb 8823.BR BASHOPTS ,
984a1947 8824.SM
e77a3058
CR
8825.BR CDPATH ,
8826and
984a1947 8827.SM
e77a3058
CR
8828.B GLOBIGNORE
8829variables, if they appear in the environment, are ignored.
b72432fd
JA
8830If the shell is started with the effective user (group) id not equal to the
8831real user (group) id, and the \fB\-p\fP option is not supplied, these actions
8832are taken and the effective user id is set to the real user id.
8833If the \fB\-p\fP option is supplied at startup, the effective user id is
8834not reset.
cce855bc 8835Turning this option off causes the effective user
726f6388
JA
8836and group ids to be set to the real user and group ids.
8837.TP 8
8838.B \-t
8839Exit after reading and executing one command.
8840.TP 8
8841.B \-u
2c471a92
CR
8842Treat unset variables and parameters other than the special
8843parameters "@" and "*" as an error when performing
726f6388 8844parameter expansion. If expansion is attempted on an
2c471a92 8845unset variable or parameter, the shell prints an error message, and,
ccc6cda3 8846if not interactive, exits with a non-zero status.
726f6388
JA
8847.TP 8
8848.B \-v
8849Print shell input lines as they are read.
8850.TP 8
8851.B \-x
ccc6cda3 8852After expanding each \fIsimple command\fP,
d3a24ed2
CR
8853\fBfor\fP command, \fBcase\fP command, \fBselect\fP command, or
8854arithmetic \fBfor\fP command, display the expanded value of
726f6388
JA
8855.SM
8856.BR PS4 ,
d3a24ed2
CR
8857followed by the command and its expanded arguments
8858or associated word list.
726f6388 8859.TP 8
ccc6cda3
JA
8860.B \-B
8861The shell performs brace expansion (see
8862.B Brace Expansion
8863above). This is on by default.
726f6388
JA
8864.TP 8
8865.B \-C
ccc6cda3
JA
8866If set,
8867.B bash
8868does not overwrite an existing file with the
8869.BR > ,
8870.BR >& ,
8871and
8872.B <>
8873redirection operators. This may be overridden when
8874creating output files by using the redirection operator
8875.B >|
8876instead of
8877.BR > .
726f6388 8878.TP 8
d3a24ed2
CR
8879.B \-E
8880If set, any trap on \fBERR\fP is inherited by shell functions, command
8881substitutions, and commands executed in a subshell environment.
8882The \fBERR\fP trap is normally not inherited in such cases.
8883.TP 8
726f6388
JA
8884.B \-H
8885Enable
8886.B !
cce855bc 8887style history substitution. This option is on by
726f6388
JA
8888default when the shell is interactive.
8889.TP 8
8890.B \-P
45c0f7f8 8891If set, the shell does not resolve symbolic links when executing
ccc6cda3 8892commands such as
726f6388 8893.B cd
ccc6cda3
JA
8894that change the current working directory. It uses the
8895physical directory structure instead. By default,
8896.B bash
8897follows the logical chain of directories when performing commands
8898which change the current directory.
726f6388 8899.TP 8
d3a24ed2 8900.B \-T
76a8d78d
CR
8901If set, any traps on \fBDEBUG\fP and \fBRETURN\fP are inherited by shell
8902functions, command substitutions, and commands executed in a
8903subshell environment.
8904The \fBDEBUG\fP and \fBRETURN\fP traps are normally not inherited
8905in such cases.
d3a24ed2 8906.TP 8
726f6388 8907.B \-\-
cce855bc 8908If no arguments follow this option, then the positional parameters are
726f6388
JA
8909unset. Otherwise, the positional parameters are set to the
8910\fIarg\fPs, even if some of them begin with a
8911.BR \- .
8912.TP 8
8913.B \-
8914Signal the end of options, cause all remaining \fIarg\fPs to be
8915assigned to the positional parameters. The
8916.B \-x
8917and
8918.B \-v
8919options are turned off.
8920If there are no \fIarg\fPs,
8921the positional parameters remain unchanged.
8922.PD
8923.PP
cce855bc
JA
8924The options are off by default unless otherwise noted.
8925Using + rather than \- causes these options to be turned off.
8926The options can also be specified as arguments to an invocation of
8927the shell.
8928The current set of options may be found in
726f6388 8929.BR $\- .
cce855bc 8930The return status is always true unless an invalid option is encountered.
726f6388
JA
8931.RE
8932.TP
8933\fBshift\fP [\fIn\fP]
8934The positional parameters from \fIn\fP+1 ... are renamed to
8935.B $1
8936.B ....
8937Parameters represented by the numbers \fB$#\fP
8938down to \fB$#\fP\-\fIn\fP+1 are unset.
ccc6cda3
JA
8939.I n
8940must be a non-negative number less than or equal to \fB$#\fP.
726f6388
JA
8941If
8942.I n
8943is 0, no parameters are changed.
8944If
8945.I n
8946is not given, it is assumed to be 1.
726f6388
JA
8947If
8948.I n
8949is greater than \fB$#\fP, the positional parameters are not changed.
ccc6cda3 8950The return status is greater than zero if
726f6388
JA
8951.I n
8952is greater than
8953.B $#
ccc6cda3
JA
8954or less than zero; otherwise 0.
8955.TP
8956\fBshopt\fP [\fB\-pqsu\fP] [\fB\-o\fP] [\fIoptname\fP ...]
8957Toggle the values of variables controlling optional shell behavior.
8958With no options, or with the
8959.B \-p
8960option, a list of all settable options is displayed, with
cce855bc
JA
8961an indication of whether or not each is set.
8962The \fB\-p\fP option causes output to be displayed in a form that
8963may be reused as input.
8964Other options have the following meanings:
ccc6cda3
JA
8965.RS
8966.PD 0
8967.TP
8968.B \-s
8969Enable (set) each \fIoptname\fP.
8970.TP
8971.B \-u
8972Disable (unset) each \fIoptname\fP.
8973.TP
8974.B \-q
8975Suppresses normal output (quiet mode); the return status indicates
8976whether the \fIoptname\fP is set or unset.
8977If multiple \fIoptname\fP arguments are given with
8978.BR \-q ,
8979the return status is zero if all \fIoptnames\fP are enabled; non-zero
8980otherwise.
8981.TP
8982.B \-o
8983Restricts the values of \fIoptname\fP to be those defined for the
8984.B \-o
8985option to the
8986.B set
8987builtin.
8988.PD
8989.PP
8990If either
8991.B \-s
8992or
8993.B \-u
b28ff8c9
CR
8994is used with no \fIoptname\fP arguments,
8995.B shopt
8996shows only those options which are set or unset, respectively.
ccc6cda3
JA
8997Unless otherwise noted, the \fBshopt\fP options are disabled (unset)
8998by default.
8999.PP
9000The return status when listing options is zero if all \fIoptnames\fP
9001are enabled, non-zero otherwise. When setting or unsetting options,
cce855bc 9002the return status is zero unless an \fIoptname\fP is not a valid shell
ccc6cda3
JA
9003option.
9004.PP
9005The list of \fBshopt\fP options is:
9006.if t .sp .5v
9007.if n .sp 1v
9008.PD 0
9009.TP 8
d3ad40de
CR
9010.B autocd
9011If set, a command name that is the name of a directory is executed as if
9012it were the argument to the \fBcd\fP command.
9013This option is only used by interactive shells.
9014.TP 8
ccc6cda3
JA
9015.B cdable_vars
9016If set, an argument to the
9017.B cd
9018builtin command that
9019is not a directory is assumed to be the name of a variable whose
9020value is the directory to change to.
9021.TP 8
9022.B cdspell
9023If set, minor errors in the spelling of a directory component in a
9024.B cd
9025command will be corrected.
9026The errors checked for are transposed characters,
9027a missing character, and one character too many.
b28ff8c9 9028If a correction is found, the corrected filename is printed,
ccc6cda3 9029and the command proceeds.
d166f048 9030This option is only used by interactive shells.
ccc6cda3
JA
9031.TP 8
9032.B checkhash
9033If set, \fBbash\fP checks that a command found in the hash
9034table exists before trying to execute it. If a hashed command no
9035longer exists, a normal path search is performed.
9036.TP 8
d3ad40de 9037.B checkjobs
29d25b54 9038If set, \fBbash\fP lists the status of any stopped and running jobs before
d3ad40de
CR
9039exiting an interactive shell. If any jobs are running, this causes
9040the exit to be deferred until a second exit is attempted without an
984a1947
CR
9041intervening command (see
9042.SM
9043.B "JOB CONTROL"
9044above). The shell always
d3ad40de
CR
9045postpones exiting if any jobs are stopped.
9046.TP 8
ccc6cda3 9047.B checkwinsize
51f7ea36 9048If set, \fBbash\fP checks the window size after each command
ccc6cda3
JA
9049and, if necessary, updates the values of
9050.SM
9051.B LINES
9052and
9053.SM
9054.BR COLUMNS .
9055.TP 8
9056.B cmdhist
9057If set,
9058.B bash
9059attempts to save all lines of a multiple-line
9060command in the same history entry. This allows
9061easy re-editing of multi-line commands.
9062.TP 8
35ee8ea0
CR
9063.B compat31
9064If set,
9065.B bash
9066changes its behavior to that of version 3.1 with respect to quoted
5a318736
CR
9067arguments to the \fB[[\fP conditional command's \fB=~\fP operator
9068and locale-specific string comparison when using the \fB[[\fP
54a1fa7c
CR
9069conditional command's \fB<\fP and \fB>\fP operators.
9070Bash versions prior to bash-4.1 use ASCII collation and
9071.IR strcmp (3);
5a318736 9072bash-4.1 and later use the current locale's collation sequence and
54a1fa7c 9073.IR strcoll (3).
cd0ef727 9074.TP 8
5a318736
CR
9075.B compat32
9076If set,
9077.B bash
9078changes its behavior to that of version 3.2 with respect to
9079locale-specific string comparison when using the \fB[[\fP
9080conditional command's \fB<\fP and \fB>\fP operators (see previous item).
9081.TP 8
cd0ef727
CR
9082.B compat40
9083If set,
9084.B bash
9085changes its behavior to that of version 4.0 with respect to locale-specific
54a1fa7c 9086string comparison when using the \fB[[\fP
5a318736
CR
9087conditional command's \fB<\fP and \fB>\fP operators (see description of
9088\fBcompat31\fP)
54a1fa7c 9089and the effect of interrupting a command list.
5a318736
CR
9090Bash versions 4.0 and later interrupt the list as if the shell received the
9091interrupt; previous versions continue with the next command in the list.
cd0ef727 9092.TP 8
67362c60 9093.B compat41
67362c60
CR
9094If set,
9095.BR bash ,
9096when in posix mode, treats a single quote in a double-quoted
9097parameter expansion as a special character. The single quotes must match
9098(an even number) and the characters between the single quotes are considered
9099quoted. This is the behavior of posix mode through version 4.1.
9100The default bash behavior remains as in previous versions.
9101.TP 8
ddef12ff
CR
9102.B complete_fullquote
9103If set,
9104.B bash
9105quotes all shell metacharacters in filenames and directory names when
9106performing completion.
9107If not set,
9108.B bash
9109removes metacharacters such as the dollar sign from the set of
9110characters that will be quoted in completed filenames
9111when these metacharacters appear in shell variable references in words to be
9112completed.
9113This means that dollar signs in variable names that expand to directories
9114will not be quoted;
9115however, any dollar signs appearing in filenames will not be quoted, either.
9116This is active only when bash is using backslashes to quote completed
9117filenames.
9118This variable is set by default, which is the default bash behavior in
9119versions through 4.2.
9120.TP 8
74d0116b
CR
9121.B direxpand
9122If set,
9123.B bash
9124replaces directory names with the results of word expansion when performing
9125filename completion. This changes the contents of the readline editing
9126buffer.
9127If not set,
9128.B bash
9129attempts to preserve what the user typed.
9130.TP 8
4ac1ff98
CR
9131.B dirspell
9132If set,
9133.B bash
9134attempts spelling correction on directory names during word completion
9135if the directory name initially supplied does not exist.
9136.TP 8
ccc6cda3
JA
9137.B dotglob
9138If set,
9139.B bash
9140includes filenames beginning with a `.' in the results of pathname
9141expansion.
9142.TP 8
9143.B execfail
9144If set, a non-interactive shell will not exit if
9145it cannot execute the file specified as an argument to the
9146.B exec
9147builtin command. An interactive shell does not exit if
9148.B exec
9149fails.
9150.TP 8
9151.B expand_aliases
9152If set, aliases are expanded as described above under
9153.SM
9154.BR ALIASES .
9155This option is enabled by default for interactive shells.
9156.TP 8
d3a24ed2
CR
9157.B extdebug
9158If set, behavior intended for use by debuggers is enabled:
9159.RS
9160.TP
9161.B 1.
9162The \fB\-F\fP option to the \fBdeclare\fP builtin displays the source
9163file name and line number corresponding to each function name supplied
9164as an argument.
9165.TP
9166.B 2.
9167If the command run by the \fBDEBUG\fP trap returns a non-zero value, the
9168next command is skipped and not executed.
9169.TP
9170.B 3.
9171If the command run by the \fBDEBUG\fP trap returns a value of 2, and the
9172shell is executing in a subroutine (a shell function or a shell script
9173executed by the \fB.\fP or \fBsource\fP builtins), a call to
9174\fBreturn\fP is simulated.
2206f89a
CR
9175.TP
9176.B 4.
984a1947
CR
9177.SM
9178.B BASH_ARGC
9179and
9180.SM
9181.B BASH_ARGV
9182are updated as described in their descriptions above.
2206f89a
CR
9183.TP
9184.B 5.
9185Function tracing is enabled: command substitution, shell functions, and
9186subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the
9187\fBDEBUG\fP and \fBRETURN\fP traps.
9188.TP
9189.B 6.
9190Error tracing is enabled: command substitution, shell functions, and
9191subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the
5cdaaf76 9192\fBERR\fP trap.
d3a24ed2
CR
9193.RE
9194.TP 8
cce855bc
JA
9195.B extglob
9196If set, the extended pattern matching features described above under
9197\fBPathname Expansion\fP are enabled.
9198.TP 8
d3a24ed2 9199.B extquote
20587658 9200If set, \fB$\fP\(aq\fIstring\fP\(aq and \fB$\fP"\fIstring\fP" quoting is
d3a24ed2
CR
9201performed within \fB${\fP\fIparameter\fP\fB}\fP expansions
9202enclosed in double quotes. This option is enabled by default.
9203.TP 8
9204.B failglob
9205If set, patterns which fail to match filenames during pathname expansion
9206result in an expansion error.
9207.TP 8
9208.B force_fignore
984a1947
CR
9209If set, the suffixes specified by the
9210.SM
9211.B FIGNORE
9212shell variable
d3a24ed2
CR
9213cause words to be ignored when performing word completion even if
9214the ignored words are the only possible completions.
9215See
9216.SM
9217\fBSHELL VARIABLES\fP
984a1947
CR
9218above for a description of
9219.SM
9220.BR FIGNORE .
d3a24ed2
CR
9221This option is enabled by default.
9222.TP 8
74d0116b
CR
9223.B globasciiranges
9224If set, range expressions used in pattern matching (see
9225.SM
9226.B Pattern Matching
9227above) behave as if in the traditional C locale when performing
9228comparisons. That is, the current locale's collating sequence
9229is not taken into account, so
9230.B b
9231will not collate between
9232.B A
9233and
9234.BR B ,
9235and upper-case and lower-case ASCII characters will collate together.
9236.TP 8
4ac1ff98 9237.B globstar
d0ca3503 9238If set, the pattern \fB**\fP used in a pathname expansion context will
54a1fa7c 9239match all files and zero or more directories and subdirectories.
4ac1ff98
CR
9240If the pattern is followed by a \fB/\fP, only directories and
9241subdirectories match.
9242.TP 8
d3a24ed2
CR
9243.B gnu_errfmt
9244If set, shell error messages are written in the standard GNU error
9245message format.
9246.TP 8
ccc6cda3
JA
9247.B histappend
9248If set, the history list is appended to the file named by the value
9249of the
984a1947 9250.SM
ccc6cda3
JA
9251.B HISTFILE
9252variable when the shell exits, rather than overwriting the file.
9253.TP 8
9254.B histreedit
9255If set, and
9256.B readline
9257is being used, a user is given the opportunity to re-edit a
9258failed history substitution.
9259.TP 8
9260.B histverify
9261If set, and
9262.B readline
9263is being used, the results of history substitution are not immediately
9264passed to the shell parser. Instead, the resulting line is loaded into
9265the \fBreadline\fP editing buffer, allowing further modification.
9266.TP 8
9267.B hostcomplete
9268If set, and
9269.B readline
cce855bc
JA
9270is being used, \fBbash\fP will attempt to perform hostname completion when a
9271word containing a \fB@\fP is being completed (see
ccc6cda3
JA
9272.B Completing
9273under
9274.SM
9275.B READLINE
9276above).
9277This is enabled by default.
9278.TP 8
cce855bc
JA
9279.B huponexit
9280If set, \fBbash\fP will send
9281.SM
9282.B SIGHUP
9283to all jobs when an interactive login shell exits.
9284.TP 8
ccc6cda3
JA
9285.B interactive_comments
9286If set, allow a word beginning with
9287.B #
9288to cause that word and all remaining characters on that
9289line to be ignored in an interactive shell (see
9290.SM
9291.B COMMENTS
9292above). This option is enabled by default.
9293.TP 8
7d92f73f
CR
9294.B lastpipe
9295If set, and job control is not active, the shell runs the last command of
9296a pipeline not executed in the background in the current shell environment.
9297.TP 8
ccc6cda3
JA
9298.B lithist
9299If set, and the
9300.B cmdhist
9301option is enabled, multi-line commands are saved to the history with
9302embedded newlines rather than using semicolon separators where possible.
9303.TP 8
f73dda09
JA
9304.B login_shell
9305The shell sets this option if it is started as a login shell (see
9306.SM
9307.B "INVOCATION"
9308above).
9309The value may not be changed.
9310.TP 8
ccc6cda3
JA
9311.B mailwarn
9312If set, and a file that \fBbash\fP is checking for mail has been
9313accessed since the last time it was checked, the message ``The mail in
9314\fImailfile\fP has been read'' is displayed.
9315.TP 8
bb70624e
JA
9316.B no_empty_cmd_completion
9317If set, and
9318.B readline
9319is being used,
9320.B bash
984a1947
CR
9321will not attempt to search the
9322.SM
9323.B PATH
9324for possible completions when
bb70624e
JA
9325completion is attempted on an empty line.
9326.TP 8
cce855bc
JA
9327.B nocaseglob
9328If set,
9329.B bash
9330matches filenames in a case\-insensitive fashion when performing pathname
9331expansion (see
9332.B Pathname Expansion
9333above).
9334.TP 8
2206f89a
CR
9335.B nocasematch
9336If set,
9337.B bash
9338matches patterns in a case\-insensitive fashion when performing matching
9339while executing \fBcase\fP or \fB[[\fP conditional commands.
9340.TP 8
ccc6cda3
JA
9341.B nullglob
9342If set,
9343.B bash
9344allows patterns which match no
9345files (see
9346.B Pathname Expansion
9347above)
9348to expand to a null string, rather than themselves.
9349.TP 8
bb70624e
JA
9350.B progcomp
9351If set, the programmable completion facilities (see
9352\fBProgrammable Completion\fP above) are enabled.
9353This option is enabled by default.
9354.TP 8
ccc6cda3 9355.B promptvars
d3a24ed2
CR
9356If set, prompt strings undergo
9357parameter expansion, command substitution, arithmetic
9358expansion, and quote removal after being expanded as described in
ccc6cda3
JA
9359.SM
9360.B PROMPTING
9361above. This option is enabled by default.
9362.TP 8
b72432fd
JA
9363.B restricted_shell
9364The shell sets this option if it is started in restricted mode (see
9365.SM
9366.B "RESTRICTED SHELL"
9367below).
9368The value may not be changed.
9369This is not reset when the startup files are executed, allowing
9370the startup files to discover whether or not a shell is restricted.
9371.TP 8
ccc6cda3
JA
9372.B shift_verbose
9373If set, the
9374.B shift
9375builtin prints an error message when the shift count exceeds the
9376number of positional parameters.
9377.TP 8
9378.B sourcepath
9379If set, the
9380\fBsource\fP (\fB.\fP) builtin uses the value of
9381.SM
9382.B PATH
9383to find the directory containing the file supplied as an argument.
cce855bc 9384This option is enabled by default.
bb70624e
JA
9385.TP 8
9386.B xpg_echo
9387If set, the \fBecho\fP builtin expands backslash-escape sequences
9388by default.
ccc6cda3 9389.RE
54a1fa7c 9390.PD
726f6388
JA
9391.TP
9392\fBsuspend\fP [\fB\-f\fP]
9393Suspend the execution of this shell until it receives a
9394.SM
9395.B SIGCONT
09767ff0 9396signal. A login shell cannot be suspended; the
726f6388 9397.B \-f
09767ff0
CR
9398option can be used to override this and force the suspension.
9399The return status is 0 unless the shell is a login shell and
726f6388
JA
9400.B \-f
9401is not supplied, or if job control is not enabled.
9402.TP
726f6388 9403\fBtest\fP \fIexpr\fP
7117c2d2 9404.PD 0
726f6388
JA
9405.TP
9406\fB[\fP \fIexpr\fP \fB]\fP
b28ff8c9 9407Return a status of 0 (true) or 1 (false) depending on
726f6388
JA
9408the evaluation of the conditional expression
9409.IR expr .
cce855bc
JA
9410Each operator and operand must be a separate argument.
9411Expressions are composed of the primaries described above under
9412.SM
9413.BR "CONDITIONAL EXPRESSIONS" .
3ffb039a
CR
9414\fBtest\fP does not accept any options, nor does it accept and ignore
9415an argument of \fB\-\-\fP as signifying the end of options.
cce855bc
JA
9416.if t .sp 0.5
9417.if n .sp 1
9418Expressions may be combined using the following operators, listed
9419in decreasing order of precedence.
641d8f00 9420The evaluation depends on the number of arguments; see below.
06dff54a 9421Operator precedence is used when there are five or more arguments.
726f6388
JA
9422.RS
9423.PD 0
9424.TP
726f6388
JA
9425.B ! \fIexpr\fP
9426True if
9427.I expr
9428is false.
9429.TP
cce855bc
JA
9430.B ( \fIexpr\fP )
9431Returns the value of \fIexpr\fP.
9432This may be used to override the normal precedence of operators.
9433.TP
726f6388
JA
9434\fIexpr1\fP \-\fBa\fP \fIexpr2\fP
9435True if both
9436.I expr1
cce855bc 9437and
726f6388
JA
9438.I expr2
9439are true.
9440.TP
9441\fIexpr1\fP \-\fBo\fP \fIexpr2\fP
9442True if either
9443.I expr1
cce855bc 9444or
726f6388
JA
9445.I expr2
9446is true.
cce855bc
JA
9447.PD
9448.PP
9449\fBtest\fP and \fB[\fP evaluate conditional
9450expressions using a set of rules based on the number of arguments.
9451.if t .sp 0.5
9452.if n .sp 1
9453.PD 0
726f6388 9454.TP
cce855bc
JA
94550 arguments
9456The expression is false.
9457.TP
94581 argument
9459The expression is true if and only if the argument is not null.
9460.TP
94612 arguments
9462If the first argument is \fB!\fP, the expression is true if and
9463only if the second argument is null.
9464If the first argument is one of the unary conditional operators listed above
9465under
726f6388 9466.SM
cce855bc
JA
9467.BR "CONDITIONAL EXPRESSIONS" ,
9468the expression is true if the unary test is true.
9469If the first argument is not a valid unary conditional operator, the expression
9470is false.
9471.TP
94723 arguments
adc6cff5 9473The following conditions are applied in the order listed.
cce855bc
JA
9474If the second argument is one of the binary conditional operators listed above
9475under
9476.SM
9477.BR "CONDITIONAL EXPRESSIONS" ,
9478the result of the expression is the result of the binary test using
9479the first and third arguments as operands.
641d8f00
CR
9480The \fB\-a\fP and \fB\-o\fP operators are considered binary operators
9481when there are three arguments.
cce855bc
JA
9482If the first argument is \fB!\fP, the value is the negation of
9483the two-argument test using the second and third arguments.
9484If the first argument is exactly \fB(\fP and the third argument is
9485exactly \fB)\fP, the result is the one-argument test of the second
9486argument.
9487Otherwise, the expression is false.
cce855bc
JA
9488.TP
94894 arguments
9490If the first argument is \fB!\fP, the result is the negation of
9491the three-argument expression composed of the remaining arguments.
9492Otherwise, the expression is parsed and evaluated according to
9493precedence using the rules listed above.
9494.TP
94955 or more arguments
9496The expression is parsed and evaluated according to precedence
9497using the rules listed above.
54a1fa7c
CR
9498.if t .sp 0.5
9499.if n .sp 1
9500.LP
9501When used with \fBtest\fP or \fB[\fP, the \fB<\fP and \fB>\fP operators
9502sort lexicographically using ASCII ordering.
726f6388 9503.RE
cce855bc 9504.PD
726f6388
JA
9505.TP
9506.B times
9507Print the accumulated user and system times for the shell and
9508for processes run from the shell. The return status is 0.
9509.TP
61deeb13 9510\fBtrap\fP [\fB\-lp\fP] [[\fIarg\fP] \fIsigspec\fP ...]
726f6388
JA
9511The command
9512.I arg
9513is to be read and executed when the shell receives
9514signal(s)
9515.IR sigspec .
9516If
9517.I arg
61deeb13 9518is absent (and there is a single \fIsigspec\fP) or
726f6388 9519.BR \- ,
61deeb13
CR
9520each specified signal is
9521reset to its original disposition (the value it had
d166f048
JA
9522upon entrance to the shell).
9523If
726f6388 9524.I arg
d166f048
JA
9525is the null string the signal specified by each
9526.I sigspec
9527is ignored by the shell and by the commands it invokes.
ccc6cda3
JA
9528If
9529.I arg
bb70624e 9530is not present and
ccc6cda3 9531.B \-p
bb70624e 9532has been supplied, then the trap commands associated with each
ccc6cda3 9533.I sigspec
bb70624e
JA
9534are displayed.
9535If no arguments are supplied or if only
ccc6cda3
JA
9536.B \-p
9537is given,
9538.B trap
61deeb13 9539prints the list of commands associated with each signal.
d3a24ed2
CR
9540The
9541.B \-l
9542option causes the shell to print a list of signal names and
9543their corresponding numbers.
d166f048 9544Each
726f6388
JA
9545.I sigspec
9546is either
d166f048 9547a signal name defined in <\fIsignal.h\fP>, or a signal number.
9c7f20c7
CR
9548Signal names are case insensitive and the
9549.SM
9550.B SIG
9551prefix is optional.
4301bca7
CR
9552.if t .sp 0.5
9553.if n .sp 1
d166f048 9554If a
726f6388
JA
9555.I sigspec
9556is
9557.SM
9558.B EXIT
9559(0) the command
9560.I arg
f73dda09
JA
9561is executed on exit from the shell.
9562If a
ccc6cda3
JA
9563.I sigspec
9564is
9565.SM
9566.BR DEBUG ,
9567the command
9568.I arg
d3a24ed2
CR
9569is executed before every \fIsimple command\fP, \fIfor\fP command,
9570\fIcase\fP command, \fIselect\fP command, every arithmetic \fIfor\fP
9571command, and before the first command executes in a shell function (see
ccc6cda3
JA
9572.SM
9573.B SHELL GRAMMAR
9574above).
40b074c6 9575Refer to the description of the \fBextdebug\fP option to the
d3a24ed2 9576\fBshopt\fP builtin for details of its effect on the \fBDEBUG\fP trap.
f73dda09
JA
9577If a
9578.I sigspec
9579is
9580.SM
4301bca7
CR
9581.BR RETURN ,
9582the command
9583.I arg
e05be32d
CR
9584is executed each time a shell function or a script executed with
9585the \fB.\fP or \fBsource\fP builtins finishes executing.
4301bca7
CR
9586.if t .sp 0.5
9587.if n .sp 1
9588If a
9589.I sigspec
9590is
9591.SM
f73dda09
JA
9592.BR ERR ,
9593the command
9594.I arg
5e13499c
CR
9595is executed whenever a simple command has a non\-zero exit status,
9596subject to the following conditions.
f73dda09
JA
9597The
9598.SM
d3a24ed2
CR
9599.B ERR
9600trap is not executed if the failed
9601command is part of the command list immediately following a
9602.B while
f73dda09 9603or
d3a24ed2
CR
9604.B until
9605keyword,
9606part of the test in an
f73dda09 9607.I if
9d85af6d 9608statement, part of a command executed in a
f73dda09
JA
9609.B &&
9610or
adc6cff5 9611.B ||
f73dda09
JA
9612list, or if the command's return value is
9613being inverted via
9614.BR ! .
5e13499c 9615These are the same conditions obeyed by the \fBerrexit\fP option.
4301bca7
CR
9616.if t .sp 0.5
9617.if n .sp 1
726f6388 9618Signals ignored upon entry to the shell cannot be trapped or reset.
d3ad40de 9619Trapped signals that are not being ignored are reset to their original
4301bca7 9620values in a subshell or subshell environment when one is created.
d166f048 9621The return status is false if any
ccc6cda3
JA
9622.I sigspec
9623is invalid; otherwise
726f6388
JA
9624.B trap
9625returns true.
9626.TP
7117c2d2 9627\fBtype\fP [\fB\-aftpP\fP] \fIname\fP [\fIname\fP ...]
726f6388
JA
9628With no options,
9629indicate how each
9630.I name
9631would be interpreted if used as a command name.
9632If the
cce855bc
JA
9633.B \-t
9634option is used,
726f6388 9635.B type
ccc6cda3 9636prints a string which is one of
726f6388
JA
9637.IR alias ,
9638.IR keyword ,
9639.IR function ,
9640.IR builtin ,
9641or
9642.I file
9643if
9644.I name
9645is an alias, shell reserved word, function, builtin, or disk file,
ccc6cda3
JA
9646respectively.
9647If the
9648.I name
9649is not found, then nothing is printed, and an exit status of false
9650is returned.
726f6388 9651If the
cce855bc
JA
9652.B \-p
9653option is used,
726f6388
JA
9654.B type
9655either returns the name of the disk file
9656that would be executed if
9657.I name
9658were specified as a command name,
28ef6c31
JA
9659or nothing if
9660.if t \f(CWtype -t name\fP
9661.if n ``type -t name''
726f6388
JA
9662would not return
9663.IR file .
7117c2d2
JA
9664The
9665.B \-P
9666option forces a
9667.SM
9668.B PATH
9669search for each \fIname\fP, even if
9670.if t \f(CWtype -t name\fP
9671.if n ``type -t name''
9672would not return
9673.IR file .
726f6388 9674If a command is hashed,
cce855bc 9675.B \-p
7117c2d2
JA
9676and
9677.B \-P
b28ff8c9 9678print the hashed value, which is not necessarily the file that appears
726f6388
JA
9679first in
9680.SM
9681.BR PATH .
9682If the
cce855bc
JA
9683.B \-a
9684option is used,
726f6388
JA
9685.B type
9686prints all of the places that contain
9687an executable named
9688.IR name .
9689This includes aliases and functions,
9690if and only if the
cce855bc
JA
9691.B \-p
9692option is not also used.
726f6388
JA
9693The table of hashed commands is not consulted
9694when using
cce855bc 9695.BR \-a .
7117c2d2
JA
9696The
9697.B \-f
9698option suppresses shell function lookup, as with the \fBcommand\fP builtin.
726f6388 9699.B type
6a8fd0ed
CR
9700returns true if all of the arguments are found, false if
9701any are not found.
726f6388 9702.TP
6fbe7620 9703\fBulimit\fP [\fB\-HSTabcdefilmnpqrstuvx\fP [\fIlimit\fP]]
ccc6cda3 9704Provides control over the resources available to the shell and to
f73dda09 9705processes started by it, on systems that allow such control.
ccc6cda3 9706The \fB\-H\fP and \fB\-S\fP options specify that the hard or soft limit is
79e6c7dc
CR
9707set for the given resource.
9708A hard limit cannot be increased by a non-root user once it is set;
9709a soft limit may be increased up to the value of the hard limit.
ccc6cda3
JA
9710If neither \fB\-H\fP nor \fB\-S\fP is specified, both the soft and hard
9711limits are set.
f73dda09
JA
9712The value of
9713.I limit
9714can be a number in the unit specified for the resource
9715or one of the special values
9716.BR hard ,
9717.BR soft ,
9718or
9719.BR unlimited ,
9720which stand for the current hard limit, the current soft limit, and
9721no limit, respectively.
ccc6cda3 9722If
726f6388
JA
9723.I limit
9724is omitted, the current value of the soft limit of the resource is
ccc6cda3
JA
9725printed, unless the \fB\-H\fP option is given. When more than one
9726resource is specified, the limit name and unit are printed before the value.
726f6388
JA
9727Other options are interpreted as follows:
9728.RS
9729.PD 0
9730.TP
9731.B \-a
ccc6cda3 9732All current limits are reported
726f6388 9733.TP
6fbe7620
CR
9734.B \-b
9735The maximum socket buffer size
9736.TP
726f6388 9737.B \-c
ccc6cda3 9738The maximum size of core files created
726f6388
JA
9739.TP
9740.B \-d
ccc6cda3 9741The maximum size of a process's data segment
726f6388 9742.TP
dc8fbaf9
CR
9743.B \-e
9744The maximum scheduling priority ("nice")
9745.TP
726f6388 9746.B \-f
d3ad40de 9747The maximum size of files written by the shell and its children
726f6388 9748.TP
af12dacd
CR
9749.B \-i
9750The maximum number of pending signals
9751.TP
ccc6cda3
JA
9752.B \-l
9753The maximum size that may be locked into memory
726f6388 9754.TP
ccc6cda3 9755.B \-m
db31fb26 9756The maximum resident set size (many systems do not honor this limit)
726f6388 9757.TP
ccc6cda3
JA
9758.B \-n
9759The maximum number of open file descriptors (most systems do not
9760allow this value to be set)
726f6388
JA
9761.TP
9762.B \-p
ccc6cda3 9763The pipe size in 512-byte blocks (this may not be set)
726f6388 9764.TP
af12dacd
CR
9765.B \-q
9766The maximum number of bytes in POSIX message queues
9767.TP
dc8fbaf9
CR
9768.B \-r
9769The maximum real-time scheduling priority
9770.TP
ccc6cda3
JA
9771.B \-s
9772The maximum stack size
9773.TP
9774.B \-t
9775The maximum amount of cpu time in seconds
726f6388
JA
9776.TP
9777.B \-u
ccc6cda3 9778The maximum number of processes available to a single user
726f6388
JA
9779.TP
9780.B \-v
68dfe178
CR
9781The maximum amount of virtual memory available to the shell and, on
9782some systems, to its children
af12dacd
CR
9783.TP
9784.B \-x
9785The maximum number of file locks
6fbe7620
CR
9786.TP
9787.B \-T
9788The maximum number of threads
726f6388
JA
9789.PD
9790.PP
ccc6cda3 9791If
726f6388 9792.I limit
b28ff8c9 9793is given, and the
726f6388 9794.B \-a
b28ff8c9
CR
9795option is not used,
9796\fIlimit\fP is the new value of the specified resource.
726f6388
JA
9797If no option is given, then
9798.B \-f
9799is assumed. Values are in 1024-byte increments, except for
9800.BR \-t ,
b28ff8c9 9801which is in seconds;
726f6388 9802.BR \-p ,
b28ff8c9 9803which is in units of 512-byte blocks;
726f6388 9804and
6fbe7620
CR
9805.BR \-T ,
9806.BR \-b ,
9807.BR \-n ,
726f6388
JA
9808and
9809.BR \-u ,
f73dda09
JA
9810which are unscaled values.
9811The return status is 0 unless an invalid option or argument is supplied,
9812or an error occurs while setting a new limit.
726f6388
JA
9813.RE
9814.TP
cce855bc 9815\fBumask\fP [\fB\-p\fP] [\fB\-S\fP] [\fImode\fP]
726f6388
JA
9816The user file-creation mask is set to
9817.IR mode .
9818If
9819.I mode
9820begins with a digit, it
9821is interpreted as an octal number; otherwise
9822it is interpreted as a symbolic mode mask similar
9823to that accepted by
9824.IR chmod (1).
9825If
9826.I mode
bb70624e 9827is omitted, the current value of the mask is printed.
ccc6cda3 9828The
726f6388
JA
9829.B \-S
9830option causes the mask to be printed in symbolic form; the
9831default output is an octal number.
cce855bc
JA
9832If the
9833.B \-p
9834option is supplied, and
9835.I mode
9836is omitted, the output is in a form that may be reused as input.
ccc6cda3 9837The return status is 0 if the mode was successfully changed or if
726f6388
JA
9838no \fImode\fP argument was supplied, and false otherwise.
9839.TP
9840\fBunalias\fP [\-\fBa\fP] [\fIname\fP ...]
bb70624e 9841Remove each \fIname\fP from the list of defined aliases. If
726f6388
JA
9842.B \-a
9843is supplied, all alias definitions are removed. The return
9844value is true unless a supplied
9845.I name
9846is not a defined alias.
9847.TP
9848\fBunset\fP [\-\fBfv\fP] [\fIname\fP ...]
9849For each
9850.IR name ,
ccc6cda3 9851remove the corresponding variable or function.
276cb932 9852If the
ccc6cda3
JA
9853.B \-v
9854option is given, each
9855.I name
276cb932 9856refers to a shell variable, and that variable is removed.
ccc6cda3
JA
9857Read-only variables may not be unset.
9858If
726f6388 9859.B \-f
f75912ae 9860is specified, each
ccc6cda3
JA
9861.I name
9862refers to a shell function, and the function definition
9863is removed.
276cb932
CR
9864If no options are supplied, each \fIname\fP refers to a variable; if
9865there is no variable by that name, any function with that name is
9866unset.
ccc6cda3
JA
9867Each unset variable or function is removed from the environment
9868passed to subsequent commands.
9869If any of
726f6388 9870.SM
984a1947
CR
9871.BR COMP_WORDBREAKS ,
9872.SM
726f6388
JA
9873.BR RANDOM ,
9874.SM
9875.BR SECONDS ,
9876.SM
9877.BR LINENO ,
ccc6cda3
JA
9878.SM
9879.BR HISTCMD ,
bb70624e
JA
9880.SM
9881.BR FUNCNAME ,
9882.SM
9883.BR GROUPS ,
726f6388
JA
9884or
9885.SM
ccc6cda3 9886.B DIRSTACK
726f6388
JA
9887are unset, they lose their special properties, even if they are
9888subsequently reset. The exit status is true unless a
9889.I name
d3a24ed2 9890is readonly.
726f6388 9891.TP
d90269dd
CR
9892\fBwait\fP [\fIn ...\fP]
9893Wait for each specified process and return its termination status.
9894Each
726f6388
JA
9895.I n
9896may be a process
9897ID or a job specification; if a job spec is given, all processes
9898in that job's pipeline are waited for. If
9899.I n
9900is not given, all currently active child processes
9901are waited for, and the return status is zero. If
9902.I n
ccc6cda3 9903specifies a non-existent process or job, the return status is
726f6388
JA
9904127. Otherwise, the return status is the exit status of the last
9905process or job waited for.
9906.\" bash_builtins
9907.if \n(zZ=1 .ig zZ
ccc6cda3 9908.SH "RESTRICTED SHELL"
bb70624e
JA
9909.\" rbash.1
9910.zY
726f6388 9911.PP
ccc6cda3 9912If
726f6388 9913.B bash
ccc6cda3
JA
9914is started with the name
9915.BR rbash ,
9916or the
9917.B \-r
9918option is supplied at invocation,
9919the shell becomes restricted.
9920A restricted shell is used to
9921set up an environment more controlled than the standard shell.
9922It behaves identically to
9923.B bash
cce855bc 9924with the exception that the following are disallowed or not performed:
ccc6cda3
JA
9925.IP \(bu
9926changing directories with \fBcd\fP
9927.IP \(bu
9928setting or unsetting the values of
984a1947 9929.SM
b72432fd 9930.BR SHELL ,
984a1947 9931.SM
b72432fd 9932.BR PATH ,
984a1947 9933.SM
b72432fd 9934.BR ENV ,
ccc6cda3 9935or
984a1947 9936.SM
b72432fd 9937.B BASH_ENV
ccc6cda3
JA
9938.IP \(bu
9939specifying command names containing
9940.B /
9941.IP \(bu
b28ff8c9 9942specifying a filename containing a
ccc6cda3
JA
9943.B /
9944as an argument to the
9945.B .
9946builtin command
9947.IP \(bu
dc60d4e0 9948specifying a filename containing a slash as an argument to the
bb70624e
JA
9949.B \-p
9950option to the
9951.B hash
9952builtin command
9953.IP \(bu
ccc6cda3
JA
9954importing function definitions from the shell environment at startup
9955.IP \(bu
984a1947
CR
9956parsing the value of
9957.SM
9958.B SHELLOPTS
9959from the shell environment at startup
cce855bc 9960.IP \(bu
ccc6cda3
JA
9961redirecting output using the >, >|, <>, >&, &>, and >> redirection operators
9962.IP \(bu
9963using the
9964.B exec
9965builtin command to replace the shell with another command
9966.IP \(bu
9967adding or deleting builtin commands with the
9968.B \-f
726f6388 9969and
ccc6cda3
JA
9970.B \-d
9971options to the
9972.B enable
9973builtin command
9974.IP \(bu
dc60d4e0 9975using the \fBenable\fP builtin command to enable disabled shell builtins
7117c2d2 9976.IP \(bu
ccc6cda3
JA
9977specifying the
9978.B \-p
9979option to the
9980.B command
9981builtin command
9982.IP \(bu
9983turning off restricted mode with
cce855bc 9984\fBset +r\fP or \fBset +o restricted\fP.
726f6388 9985.PP
ccc6cda3
JA
9986These restrictions are enforced after any startup files are read.
9987.PP
61deeb13
CR
9988.ie \n(zY=1 When a command that is found to be a shell script is executed,
9989.el \{ When a command that is found to be a shell script is executed
9990(see
ccc6cda3
JA
9991.SM
9992.B "COMMAND EXECUTION"
9993above),
61deeb13 9994\}
ccc6cda3
JA
9995.B rbash
9996turns off any restrictions in the shell spawned to execute the
9997script.
bb70624e
JA
9998.\" end of rbash.1
9999.if \n(zY=1 .ig zY
726f6388
JA
10000.SH "SEE ALSO"
10001.PD 0
10002.TP
bb70624e 10003\fIBash Reference Manual\fP, Brian Fox and Chet Ramey
726f6388
JA
10004.TP
10005\fIThe Gnu Readline Library\fP, Brian Fox and Chet Ramey
10006.TP
10007\fIThe Gnu History Library\fP, Brian Fox and Chet Ramey
10008.TP
726f6388
JA
10009\fIPortable Operating System Interface (POSIX) Part 2: Shell and Utilities\fP, IEEE
10010.TP
10011\fIsh\fP(1), \fIksh\fP(1), \fIcsh\fP(1)
10012.TP
10013\fIemacs\fP(1), \fIvi\fP(1)
10014.TP
10015\fIreadline\fP(3)
10016.PD
10017.SH FILES
10018.PD 0
10019.TP
10020.FN /bin/bash
10021The \fBbash\fP executable
10022.TP
10023.FN /etc/profile
10024The systemwide initialization file, executed for login shells
10025.TP
10026.FN ~/.bash_profile
10027The personal initialization file, executed for login shells
10028.TP
10029.FN ~/.bashrc
10030The individual per-interactive-shell startup file
10031.TP
b72432fd
JA
10032.FN ~/.bash_logout
10033The individual login shell cleanup file, executed when a login shell exits
10034.TP
726f6388
JA
10035.FN ~/.inputrc
10036Individual \fIreadline\fP initialization file
10037.PD
10038.SH AUTHORS
ccc6cda3 10039Brian Fox, Free Software Foundation
726f6388 10040.br
bb70624e 10041bfox@gnu.org
726f6388
JA
10042.PP
10043Chet Ramey, Case Western Reserve University
10044.br
db31fb26 10045chet.ramey@case.edu
726f6388
JA
10046.SH BUG REPORTS
10047If you find a bug in
10048.B bash,
10049you should report it. But first, you should
10050make sure that it really is a bug, and that it appears in the latest
10051version of
d3a24ed2
CR
10052.BR bash .
10053The latest version is always available from
9c7f20c7 10054\fIftp://ftp.gnu.org/pub/gnu/bash/\fP.
726f6388
JA
10055.PP
10056Once you have determined that a bug actually exists, use the
10057.I bashbug
10058command to submit a bug report.
d166f048 10059If you have a fix, you are encouraged to mail that as well!
726f6388 10060Suggestions and `philosophical' bug reports may be mailed
cce855bc 10061to \fIbug-bash@gnu.org\fP or posted to the Usenet
726f6388
JA
10062newsgroup
10063.BR gnu.bash.bug .
10064.PP
10065ALL bug reports should include:
10066.PP
10067.PD 0
10068.TP 20
10069The version number of \fBbash\fR
10070.TP
10071The hardware and operating system
10072.TP
10073The compiler used to compile
10074.TP
10075A description of the bug behaviour
10076.TP
10077A short script or `recipe' which exercises the bug
10078.PD
10079.PP
10080.I bashbug
10081inserts the first three items automatically into the template
10082it provides for filing a bug report.
10083.PP
10084Comments and bug reports concerning
10085this manual page should be directed to
54a1fa7c 10086.IR chet.ramey@case.edu .
726f6388
JA
10087.SH BUGS
10088.PP
10089It's too big and too slow.
10090.PP
10091There are some subtle differences between
10092.B bash
10093and traditional versions of
10094.BR sh ,
10095mostly because of the
10096.SM
10097.B POSIX
10098specification.
10099.PP
10100Aliases are confusing in some uses.
ccc6cda3
JA
10101.PP
10102Shell builtin commands and functions are not stoppable/restartable.
10103.PP
10104Compound commands and command sequences of the form `a ; b ; c'
10105are not handled gracefully when process suspension is attempted.
10106When a process is stopped, the shell immediately executes the next
10107command in the sequence.
10108It suffices to place the sequence of commands between
10109parentheses to force it into a subshell, which may be stopped as
10110a unit.
10111.PP
ccc6cda3 10112Array variables may not (yet) be exported.
09767ff0
CR
10113.PP
10114There may be only one active coprocess at a time.
726f6388 10115.zZ
bb70624e 10116.zY