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