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