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