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