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