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