source: vendor/bash/3.1-p17/doc/bash.1

Last change on this file was 3237, checked in by bird, 18 years ago

Applied bash31-002

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