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