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