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