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