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

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

bash 3.1

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