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