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