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