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