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