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