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