Debian Codegraph @

upstream/debian-unstable/man1/bash.1

raw
1 .\"
2 .\" MAN PAGE COMMENTS to
3 .\"
4 .\" Chet Ramey
5 .\" Case Western Reserve University
6 .\" [email protected]
7 .\"
8 .\" Last Change: Mon Apr 7 16:59:13 EDT 2025
9 .\"
10 .\" For bash_builtins, strip all but "SHELL BUILTIN COMMANDS" section
11 .\" For rbash, strip all but "RESTRICTED SHELL" section
12 .\"
13 .\" Both conditionalize text based on the base page being formatted
14 .\" using the zZ and zY registers, respectively
15 .\"
16 .\" Ensure the registers are initialized to avoid groff warnings.
17 .nr zZ +0
18 .nr zY +0
19 .\" Ensure the macros/strings are initialized to avoid groff warnings.
20 .ds zZ \" empty
21 .ds zY \" empty
22 .if \n(zZ=1 .ig zZ
23 .if \n(zY=1 .ig zY
24 .TH BASH 1 "2025 April 7" "GNU Bash 5.3"
25 .\"
26 .ie \n(.g \{\
27 .ds ' \(aq
28 .ds " \(dq
29 .ds ^ \(ha
30 .ds ~ \(ti
31 .\}
32 .el \{\
33 .ds ' '
34 .\" \*" is not usable in macro arguments on AT&T troff (DWB, Solaris 10)
35 .ds " ""\" two adjacent quotes and no space before this comment
36 .ds ^ ^
37 .ds ~ ~
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 .\" \% at the beginning of the string protects the filename from hyphenation.
43 .\"
44 .de FN
45 \%\fI\|\\$1\|\fP\\$2
46 ..
47 .\"
48 .\" Quotation macro: generate consistent quoted strings that don't rely
49 .\" on the presence of the `CW' constant-width font.
50 .\"
51 .de Q
52 .ie \n(.g \(lq\\$1\(rq\\$2
53 .el \{\
54 . if t ``\\$1''\\$2
55 . if n "\\$1"\\$2
56 .\}
57 ..
58 .\" Q but disallowing hyphenation of the string
59 .de QN
60 .ie \n(.g \%\(lq\\$1\(rq\\$2
61 .el \{\
62 . if t \%``\\$1''\\$2
63 . if n \%"\\$1"\\$2
64 .\}
65 ..
66 .SH NAME
67 bash \- GNU Bourne-Again SHell
68 .SH SYNOPSIS
69 .B bash
70 [options]
71 [command_string | file]
72 .SH COPYRIGHT
73 .if n Bash is Copyright (C) 1989-2025 by the Free Software Foundation, Inc.
74 .if t Bash is Copyright \(co 1989-2025 by the Free Software Foundation, Inc.
75 .SH DESCRIPTION
76 .B Bash
77 is a command language interpreter that
78 executes commands read from the standard input, from a string,
79 or from a file.
80 It is a reimplementation and extension of the Bourne shell,
81 the historical Unix command language interpreter.
82 .B Bash
83 also incorporates useful features from the \fIKorn\fP and \fIC\fP
84 shells (\fBksh\fP and \fBcsh\fP).
85 .PP
86 .SM POSIX
87 is the name for a family of computing standards based on Unix.
88 .B Bash
89 is intended to be a conformant implementation of the
90 Shell and Utilities portion of the IEEE
91 .SM POSIX
92 specification (IEEE Standard 1003.1).
93 .B Bash
94 .SM POSIX
95 mode (hereafter referred to as \fIposix mode\fP)
96 changes the shell's behavior where its default operation differs
97 from the standard to strictly conform to the standard.
98 See
99 .SM
100 .B "SEE ALSO"
101 below for a reference to a document that details how posix mode affects
102 \fBbash\fP's behavior.
103 .B Bash
104 can be configured to be
105 .SM POSIX\c
106 -conformant by default.
107 .SH OPTIONS
108 All of the single-character shell options documented in the
109 description of the \fBset\fP builtin command, including \fB\-o\fP,
110 can be used as options when the shell is invoked.
111 In addition, \fBbash\fP
112 interprets the following options when it is invoked:
113 .PP
114 .TP 10
115 .B \-c
116 If the
117 .B \-c
118 option is present, then commands are read from the first non-option argument
119 .IR command_string .
120 If there are arguments after the
121 .IR command_string ,
122 the first argument is assigned to
123 .B $0
124 and any remaining arguments are assigned to the positional parameters.
125 The assignment to
126 .B $0
127 sets the name of the shell, which is used in warning and error messages.
128 .TP
129 .B \-i
130 If the
131 .B \-i
132 option is present, the shell is
133 .IR interactive .
134 .TP
135 .B \-l
136 Make
137 .B bash
138 act as if it had been invoked as a login shell (see
139 .SM
140 .B INVOCATION
141 below).
142 .TP
143 .B \-r
144 If the
145 .B \-r
146 option is present, the shell becomes
147 .I restricted
148 (see
149 .SM
150 .B "RESTRICTED SHELL"
151 below).
152 .TP
153 .B \-s
154 If the
155 .B \-s
156 option is present, or if no arguments remain after option
157 processing, the shell reads commands from the standard input.
158 This option allows the positional parameters to be set
159 when invoking an interactive shell or when reading input
160 through a pipe.
161 .TP
162 .B \-v
163 Print shell input lines as they are read.
164 .TP
165 .B \-x
166 Print commands and their arguments as they are executed.
167 .TP
168 .B \-D
169 Print a list of all double-quoted strings preceded by \fB$\fP
170 on the standard output.
171 These are the strings that
172 are subject to language translation when the current locale
173 is not \fBC\fP or \fBPOSIX\fP.
174 This implies the \fB\-n\fP option; no commands will be executed.
175 .TP
176 .B [\-+]O [\fIshopt_option\fP]
177 \fIshopt_option\fP is one of the shell options accepted by the
178 \fBshopt\fP builtin (see
179 .SM
180 .B "SHELL BUILTIN COMMANDS"
181 below).
182 If \fIshopt_option\fP is present, \fB\-O\fP sets the value of that option;
183 \fB+O\fP unsets it.
184 If \fIshopt_option\fP is not supplied, \fBbash\fP prints
185 the names and values of the shell
186 options accepted by \fBshopt\fP on the standard output.
187 If the invocation option is \fB+O\fP, the output is displayed in a format
188 that may be reused as input.
189 .TP
190 .B \-\-
191 A
192 .B \-\-
193 signals the end of options and disables further option processing.
194 Any arguments after the
195 .B \-\-
196 are treated as a shell script filename (see below)
197 and arguments passed to that script.
198 An argument of
199 .B \-
200 is equivalent to \fB\-\-\fP.
201 .PP
202 .B Bash
203 also interprets a number of multi-character options.
204 These options must appear on the command line before the
205 single-character options to be recognized.
206 .PP
207 .TP
208 .B \-\-debugger
209 Arrange for the debugger profile to be executed before the shell
210 starts.
211 Turns on extended debugging mode (see the description of the
212 .B extdebug
213 option to the
214 .B shopt
215 builtin below).
216 .TP
217 .B \-\-dump\-po\-strings
218 Equivalent to \fB\-D\fP, but the output is in the GNU \fIgettext\fP
219 .Q po
220 (portable object) file format.
221 .TP
222 .B \-\-dump\-strings
223 Equivalent to \fB\-D\fP.
224 .TP
225 .B \-\-help
226 Display a usage message on standard output and exit successfully.
227 .TP
228 .PD 0
229 \fB\-\-init\-file\fP \fIfile\fP
230 .TP
231 \fB\-\-rcfile\fP \fIfile\fP
232 .PD
233 Execute commands from
234 .I file
235 instead of the system wide initialization file
236 .I /etc/bash.bashrc
237 and the standard personal initialization file
238 .FN \*~/.bashrc
239 if the shell is interactive (see
240 .SM
241 .B INVOCATION
242 below).
243 .TP
244 .B \-\-login
245 Equivalent to \fB\-l\fP.
246 .TP
247 .B \-\-noediting
248 Do not use the GNU
249 .B readline
250 library to read command lines when the shell is interactive.
251 .TP
252 .B \-\-noprofile
253 Do not read either the system-wide startup file
254 .FN /etc/profile
255 or any of the personal initialization files
256 .FN \*~/.bash_profile ,
257 .FN \*~/.bash_login ,
258 or
259 .FN \*~/.profile .
260 By default,
261 .B bash
262 reads these files when it is invoked as a login shell (see
263 .SM
264 .B INVOCATION
265 below).
266 .TP
267 .B \-\-norc
268 Do not read and execute the system wide initialization file
269 .I /etc/bash.bashrc
270 and the personal initialization file
271 .FN \*~/.bashrc
272 if the shell is interactive.
273 This option is on by default if the shell is invoked as
274 .BR sh .
275 .TP
276 .B \-\-posix
277 Enable posix mode;
278 change the behavior of \fBbash\fP
279 where the default operation differs from the
280 .SM POSIX
281 standard to match the standard.
282 .TP
283 .B \-\-restricted
284 The shell becomes restricted (see
285 .SM
286 .B "RESTRICTED SHELL"
287 below).
288 .TP
289 .B \-\-verbose
290 Equivalent to \fB\-v\fP.
291 .TP
292 .B \-\-version
293 Show version information for this instance of
294 .B bash
295 on the standard output and exit successfully.
296 .SH ARGUMENTS
297 If arguments remain after option processing, and neither the
298 .B \-c
299 nor the
300 .B \-s
301 option has been supplied, the first argument is treated as
302 the name of a file containing shell commands (a \fIshell script\fP).
303 When
304 .B bash
305 is invoked in this fashion,
306 .B $0
307 is set to the name of the file, and the positional parameters
308 are set to the remaining arguments.
309 .B Bash
310 reads and executes commands from this file, then exits.
311 \fBBash\fP's exit status is the exit status of the last command
312 executed in the script.
313 If no commands are executed, the exit status is 0.
314 .B Bash
315 first attempts to open the file in the current directory,
316 and, if no file is found, searches the directories in
317 .SM
318 .B PATH
319 for the script.
320 .SH INVOCATION
321 A \fIlogin shell\fP is one whose first character of argument zero is a
322 .BR \- ,
323 or one started with the
324 .B \-\-login
325 option.
326 .PP
327 An \fIinteractive shell\fP is one started without non-option arguments
328 (unless \fB\-s\fP is specified)
329 and without the
330 .B \-c
331 option,
332 and whose standard input and standard error are
333 both connected to terminals (as determined by
334 .IR isatty (3)),
335 or one started with the
336 .B \-i
337 option.
338 .B Bash
339 sets
340 .SM
341 .B PS1
342 and
343 .B $\-
344 includes
345 .B i
346 if the shell is interactive,
347 so a shell script or a startup file can test this state.
348 .PP
349 The following paragraphs describe how
350 .B bash
351 executes its startup files.
352 If any of the files exist but cannot be read,
353 .B bash
354 reports an error.
355 Tildes are expanded in filenames as described below under
356 .B "Tilde Expansion"
357 in the
358 .SM
359 .B EXPANSION
360 section.
361 .PP
362 When
363 .B bash
364 is invoked as an interactive login shell, or as a non-interactive shell
365 with the \fB\-\-login\fP option, it first reads and
366 executes commands from the file
367 .FN /etc/profile ,
368 if that file exists.
369 After reading that file, it looks for
370 .FN \*~/.bash_profile ,
371 .FN \*~/.bash_login ,
372 and
373 .FN \*~/.profile ,
374 in that order, and reads
375 and executes commands from the first one that exists and is readable.
376 The
377 .B \-\-noprofile
378 option may be used when the shell is started to inhibit this behavior.
379 .PP
380 When an interactive login shell exits,
381 or a non-interactive login shell executes the \fBexit\fP builtin command,
382 .B bash
383 reads and executes commands from the file
384 .FN \*~/.bash_logout ,
385 if it exists.
386 .PP
387 When an interactive shell that is not a login shell is started,
388 .B bash
389 reads and executes commands from
390 .FN \*/etc/bash.bashrc
391 and
392 .FN \*~/.bashrc ,
393 if that file exists.
394 The
395 .B \-\-norc
396 option inhibits this behavior.
397 The \fB\-\-rcfile\fP \fIfile\fP option causes
398 .B bash
399 to use \fIfile\fP instead of
400 .FN \*/etc/bash.bashrc
401 and
402 .FN \*~/.bashrc .
403 .PP
404 When
405 .B bash
406 is started non-interactively, to run a shell script, for example, it
407 looks for the variable
408 .SM
409 .B BASH_ENV
410 in the environment, expands its value if it appears there, and uses the
411 expanded value as the name of a file to read and execute.
412 .B Bash
413 behaves as if the following command were executed:
414 .PP
415 .RS
416 .EX
417 if [ \-n \*"$BASH_ENV\*" ]; then . \*"$BASH_ENV\*"; fi
418 .EE
419 .RE
420 .PP
421 but does not use the value of the
422 .SM
423 .B PATH
424 variable to search for the filename.
425 .PP
426 If
427 .B bash
428 is invoked with the name
429 .BR sh ,
430 it tries to mimic the startup behavior of historical versions of
431 .B sh
432 as closely as possible,
433 while conforming to the
434 .SM POSIX
435 standard as well.
436 When invoked as an interactive login shell, or a non-interactive
437 shell with the \fB\-\-login\fP option, it first attempts to read
438 and execute commands from
439 .FN /etc/profile
440 and
441 .FN \*~/.profile ,
442 in that order.
443 The
444 .B \-\-noprofile
445 option inhibits this behavior.
446 When invoked as an interactive shell with the name
447 .BR sh ,
448 .B bash
449 looks for the variable
450 .SM
451 .BR ENV ,
452 expands its value if it is defined, and uses the
453 expanded value as the name of a file to read and execute.
454 Since a shell invoked as
455 .B sh
456 does not attempt to read and execute commands from any other startup
457 files, the
458 .B \-\-rcfile
459 option has no effect.
460 A non-interactive shell invoked with the name
461 .B sh
462 does not attempt to read any other startup files.
463 .PP
464 When invoked as
465 .BR sh ,
466 .B bash
467 enters posix mode after reading the startup files.
468 .PP
469 When
470 .B bash
471 is started in posix mode, as with the
472 .B \-\-posix
473 command line option, it follows the
474 .SM POSIX
475 standard for startup files.
476 In this mode, interactive shells expand the
477 .SM
478 .B ENV
479 variable and read and execute commands from the file
480 whose name is the expanded value.
481 No other startup files are read.
482 .PP
483 .B Bash
484 attempts to determine when it is being run with its standard input
485 connected to a network connection, as when executed by
486 the historical and rarely-seen remote shell daemon, usually \fIrshd\fP,
487 or the secure shell daemon \fIsshd\fP.
488 If
489 .B bash
490 determines it is being run non-interactively in this fashion,
491 it reads and executes commands from
492 .FN \*/etc/bash.bashrc
493 and
494 .FN \*~/.bashrc ,
495 if these files exist and are readable.
496 .B Bash
497 does not read this file if invoked as \fBsh\fP.
498 The
499 .B \-\-norc
500 option inhibits this behavior, and the
501 .B \-\-rcfile
502 option makes \fBbash\fP use a different file instead of
503 .FN \*~/.bashrc ,
504 but neither
505 \fIrshd\fP nor \fIsshd\fP generally invoke the shell with those options
506 or allow them to be specified.
507 .PP
508 If the shell is started with the effective user (group) id not equal to the
509 real user (group) id, and the \fB\-p\fP option is not supplied, no startup
510 files are read, shell functions are not inherited from the environment, the
511 .SM
512 .BR SHELLOPTS ,
513 .SM
514 .BR BASHOPTS ,
515 .SM
516 .BR CDPATH ,
517 and
518 .SM
519 .B GLOBIGNORE
520 variables, if they appear in the environment, are ignored,
521 and the effective user id is set to the real user id.
522 If the \fB\-p\fP option is supplied at invocation, the startup behavior is
523 the same, but the effective user id is not reset.
524 .SH DEFINITIONS
525 The following definitions are used throughout the rest of this
526 document.
527 .PD 0
528 .TP
529 .B blank
530 A space or tab.
531 .TP
532 .B whitespace
533 A character belonging to the \fBspace\fP character class in the
534 current locale, or for which \fIisspace\fP(3) returns true.
535 .TP
536 .B word
537 A sequence of characters considered as a single unit by the shell.
538 Also known as a
539 .BR token .
540 .TP
541 .B name
542 A
543 .I word
544 consisting only of alphanumeric characters and underscores, and
545 beginning with an alphabetic character or an underscore. Also
546 referred to as an
547 .BR identifier .
548 .TP
549 .B metacharacter
550 A character that, when unquoted, separates words.
551 One of the following:
552 .br
553 .RS
554 .PP
555 .if t \fB| & ; ( ) < > space tab newline\fP
556 .if n \fB| & ; ( ) < > space tab newline\fP
557 .RE
558 .TP
559 .B "control operator"
560 A \fItoken\fP that performs a control function.
561 It is one of the following symbols:
562 .RS
563 .PP
564 .if t \fB|| & && ; ;; ;& ;;& ( ) | |& <newline>\fP
565 .if n \fB|| & && ; ;; ;& ;;& ( ) | |& <newline>\fP
566 .RE
567 .PD
568 .SH "RESERVED WORDS"
569 \fIReserved words\fP are words that have a special meaning to the shell.
570 The following words are recognized as reserved when unquoted and either
571 the first word of a command (see
572 .SM
573 .B "SHELL GRAMMAR"
574 below), the third word of a
575 .B case
576 or
577 .B select
578 command
579 (only \fBin\fP is valid), or the third word of a
580 .B for
581 command (only \fBin\fP and \fBdo\fP are valid):
582 .if t .RS
583 .PP
584 .B
585 .if n ! case coproc do done elif else esac fi for function if in select \
586 then until while { } time [[ ]]
587 .if t ! case coproc do done elif else esac fi for function if in select then until while { } time [[ ]]
588 .if t .RE
589 .SH "SHELL GRAMMAR"
590 This section describes the syntax of the various forms of shell commands.
591 .SS Simple Commands
592 A \fIsimple command\fP is a sequence of optional variable assignments
593 followed by \fBblank\fP-separated words and redirections, and
594 terminated by a \fIcontrol operator\fP.
595 The first word
596 specifies the command to be executed, and is passed as argument zero.
597 The remaining words are passed as arguments to the invoked command.
598 .PP
599 The return value of a \fIsimple command\fP is its exit status, or
600 128+\fIn\^\fP if the command is terminated by signal
601 .IR n .
602 .SS Pipelines
603 A \fIpipeline\fP is a sequence of one or more commands separated by
604 one of the control operators
605 .B |
606 or \fB|&\fP.
607 The format for a pipeline is:
608 .RS
609 .PP
610 [\fBtime\fP [\fB\-p\fP]] [ ! ] \fIcommand1\fP [ [\fB|\fP\(bv\fB|&\fP] \fIcommand2\fP .\|.\|.\& ]
611 .RE
612 .PP
613 The standard output of
614 .I command1
615 is connected via a pipe to the standard input of
616 .IR command2 .
617 This connection is performed before any redirections specified by the
618 .IR command1 (see
619 .SM
620 .B REDIRECTION
621 below).
622 If \fB|&\fP is the pipeline operator,
623 \fIcommand1\fP's standard error, in addition to its
624 standard output, is connected to
625 \fIcommand2\fP's standard input through the pipe;
626 it is shorthand for \fB2>&1 |\fP.
627 This implicit redirection of the standard error to the standard output is
628 performed after any redirections specified by \fIcommand1\fP.
629 .PP
630 The return status of a pipeline is the exit status of the last
631 command, unless the \fBpipefail\fP option is enabled.
632 If \fBpipefail\fP is enabled, the pipeline's return status is the
633 value of the last (rightmost) command to exit with a non-zero status,
634 or zero if all commands exit successfully.
635 If the reserved word
636 .B !
637 precedes a pipeline, the exit status of that pipeline is the logical
638 negation of the exit status as described above.
639 If a pipeline is executed synchronously,
640 the shell waits for all commands in the pipeline to
641 terminate before returning a value.
642 .PP
643 If the
644 .B time
645 reserved word precedes a pipeline, the shell reports the
646 elapsed as well as user and system time consumed by its execution
647 when the pipeline terminates.
648 The \fB\-p\fP option changes the output format to that specified by
649 .SM POSIX\c
650 \&.
651 When the shell is in posix mode, it does not recognize
652 \fBtime\fP as a reserved word if the next token begins with a
653 .Q \- .
654 The value of the
655 .SM
656 .B TIMEFORMAT
657 variable is a format string that specifies how the timing
658 information should be displayed; see the description of
659 .SM
660 .B TIMEFORMAT
661 below under
662 .BR "Shell Variables" .
663 .PP
664 When the shell is in posix mode, \fBtime\fP
665 may appear by itself as the only word in a simple command.
666 In this case, the shell displays the
667 total user and system time consumed by the shell and its children.
668 The
669 .SM
670 .B TIMEFORMAT
671 variable specifies the format of the time information.
672 .PP
673 Each command in a multi-command pipeline,
674 where pipes are created,
675 is executed in a \fIsubshell\fP, which is a
676 separate process.
677 See
678 .SM
679 .B "COMMAND EXECUTION ENVIRONMENT"
680 for a description of subshells and a subshell environment.
681 If the \fBlastpipe\fP option is enabled using the \fBshopt\fP builtin
682 (see the description of \fBshopt\fP below),
683 and job control is not active,
684 the last element of a pipeline may be run by the shell process.
685 .SS Lists
686 A \fIlist\fP is a sequence of one or more pipelines separated by one
687 of the operators
688 .BR ; ,
689 .BR & ,
690 .BR && ,
691 or
692 .BR || ,
693 and optionally terminated by one of
694 .BR ; ,
695 .BR & ,
696 or
697 .BR <newline> .
698 .PP
699 Of these list operators,
700 .B &&
701 and
702 .B ||
703 have equal precedence, followed by
704 .B ;
705 and
706 .BR & ,
707 which have equal precedence.
708 .PP
709 A sequence of one or more newlines may appear in a \fIlist\fP instead
710 of a semicolon to delimit commands.
711 .PP
712 If a command is terminated by the control operator
713 .BR & ,
714 the shell executes the command in the \fIbackground\fP
715 in a subshell.
716 The shell does not wait for the command to
717 finish, and the return status is 0.
718 These are referred to as \fIasynchronous\fP commands.
719 Commands separated by a
720 .B ;
721 are executed sequentially; the shell waits for each
722 command to terminate in turn.
723 The return status is the exit status of the last command executed.
724 .PP
725 AND and OR lists are sequences of one or more pipelines separated by the
726 \fB&&\fP and \fB||\fP control operators, respectively.
727 AND and OR lists are executed with left associativity.
728 An AND list has the form
729 .RS
730 .PP
731 \fIcommand1\fP \fB&&\fP \fIcommand2\fP
732 .RE
733 .PP
734 .I command2
735 is executed if, and only if,
736 .I command1
737 returns an exit status of zero (success).
738 .PP
739 An OR list has the form
740 .RS
741 .PP
742 \fIcommand1\fP \fB||\fP \fIcommand2\fP
743 .RE
744 .PP
745 .I command2
746 is executed if, and only if,
747 .I command1
748 returns a non-zero exit status.
749 The return status of
750 AND and OR lists is the exit status of the last command
751 executed in the list.
752 .SS Compound Commands
753 A \fIcompound command\fP is one of the following.
754 In most cases a \fIlist\fP in a command's description may be separated from
755 the rest of the command by one or more newlines, and may be followed by a
756 newline in place of a semicolon.
757 .TP
758 (\fIlist\fP)
759 \fIlist\fP is executed in a subshell (see
760 .SM
761 .B "COMMAND EXECUTION ENVIRONMENT"
762 below for a description of a subshell environment).
763 Variable assignments and builtin
764 commands that affect the shell's environment do not remain in effect
765 after the command completes.
766 The return status is the exit status of \fIlist\fP.
767 .TP
768 { \fIlist\fP; }
769 \fIlist\fP is executed in the current shell environment.
770 \fIlist\fP must be terminated with a newline or semicolon.
771 This is known as a \fIgroup command\fP.
772 The return status is the exit status of \fIlist\fP.
773 .IP
774 Note that unlike the metacharacters \fB(\fP and \fB)\fP, \fB{\fP and
775 \fB}\fP are \fIreserved words\fP and must occur where a reserved
776 word is permitted to be recognized.
777 Since they do not cause a word break, they must be separated from
778 \fIlist\fP by whitespace or another shell metacharacter.
779 .TP
780 ((\fIexpression\fP))
781 The arithmetic \fIexpression\fP is evaluated according to the rules
782 described below under
783 .SM
784 .BR "ARITHMETIC EVALUATION" .
785 If the value of the expression is non-zero, the return status is 0;
786 otherwise the return status is 1.
787 The \fIexpression\fP
788 undergoes the same expansions
789 as if it were within double quotes,
790 but unescaped double quote characters
791 in \fIexpression\fP are not treated
792 specially and are removed.
793 Since this can potentially result in empty strings, this command treats
794 those as expressions that evaluate to 0.
795 .TP
796 \fB[[\fP \fIexpression\fP \fB]]\fP
797 .PD
798 Evaluate the conditional expression \fIexpression\fP
799 and return a status of zero (true) or non-zero (false).
800 Expressions are composed of the primaries described below under
801 .SM
802 .BR "CONDITIONAL EXPRESSIONS" .
803 The words between the \fB[[\fP and \fB]]\fP do not undergo word splitting
804 and pathname expansion.
805 The shell performs tilde expansion, parameter and
806 variable expansion, arithmetic expansion, command substitution, process
807 substitution, and quote removal on those words.
808 Conditional operators such as \fB\-f\fP must be unquoted to be recognized
809 as primaries.
810 .IP
811 When used with \fB[[\fP, the \fB<\fP and \fB>\fP operators sort
812 lexicographically using the current locale.
813 .PP
814 See the description of the \fItest\fP builtin command (section SHELL
815 BUILTIN COMMANDS below) for the handling of parameters (i.e.
816 missing parameters).
817 .IP
818 When the \fB==\fP and \fB!=\fP operators are used, the string to the
819 right of the operator is considered a pattern and matched according
820 to the rules described below under \fBPattern Matching\fP,
821 as if the \fBextglob\fP shell option were enabled.
822 The \fB=\fP operator is equivalent to \fB==\fP.
823 If the
824 .B nocasematch
825 shell option is enabled, the match is performed without regard to the case
826 of alphabetic characters.
827 The return value is 0 if the string matches (\fB==\fP) or does not match
828 (\fB!=\fP) the pattern, and 1 otherwise.
829 If any part of the pattern is quoted, the quoted portion is matched
830 as a string: every character in the quoted portion matches itself,
831 instead of having any special pattern matching meaning.
832 .IP
833 An additional binary operator, \fB=\*~\fP, is available, with the same
834 precedence as \fB==\fP and \fB!=\fP.
835 When it is used, the string to the right of the operator is considered
836 a
837 .SM POSIX
838 extended regular expression and matched accordingly
839 (using the
840 .SM POSIX
841 \fIregcomp\fP and \fIregexec\fP interfaces
842 usually described in
843 .IR regex (3)).
844 The return value is 0 if the string matches
845 the pattern, and 1 otherwise.
846 If the regular expression is syntactically incorrect, the conditional
847 expression's return value is 2.
848 If the
849 .B nocasematch
850 shell option is enabled, the match is performed without regard to the case
851 of alphabetic characters.
852 .IP
853 If any part of the pattern is quoted, the quoted portion is matched literally,
854 as above.
855 If the pattern is stored in a shell variable, quoting the variable
856 expansion forces the entire pattern to be matched literally.
857 Treat bracket expressions in regular expressions carefully,
858 since normal quoting and pattern characters lose their meanings
859 between brackets.
860 .IP
861 The match succeeds if the pattern matches any part of the string.
862 Anchor the pattern using the \fB\*^\fP and \fB$\fP regular expression
863 operators to force it to match the entire string.
864 .IP
865 The array variable
866 .SM
867 .B BASH_REMATCH
868 records which parts of the string matched the pattern.
869 The element of
870 .SM
871 .B BASH_REMATCH
872 with index 0 contains the portion of
873 the string matching the entire regular expression.
874 Substrings matched by parenthesized subexpressions within the regular
875 expression are saved in the remaining
876 .SM
877 .B BASH_REMATCH
878 indices.
879 The element of
880 .SM
881 .B BASH_REMATCH
882 with index \fIn\fP is the portion of the
883 string matching the \fIn\fPth parenthesized subexpression.
884 \fBBash\fP sets
885 .SM
886 .B BASH_REMATCH
887 in the global scope; declaring it as a local variable will lead to
888 unexpected results.
889 .IP
890 Expressions may be combined using the following operators, listed
891 in decreasing order of precedence:
892 .IP
893 .RS
894 .PD 0
895 .TP
896 .B ( \fIexpression\fP )
897 Returns the value of \fIexpression\fP.
898 This may be used to override the normal precedence of operators.
899 .TP
900 .B ! \fIexpression\fP
901 True if
902 .I expression
903 is false.
904 .TP
905 \fIexpression1\fP \fB&&\fP \fIexpression2\fP
906 True if both
907 .I expression1
908 and
909 .I expression2
910 are true.
911 .TP
912 \fIexpression1\fP \fB||\fP \fIexpression2\fP
913 True if either
914 .I expression1
915 or
916 .I expression2
917 is true.
918 .PD
919 .LP
920 The \fB&&\fP and \fB||\fP
921 operators do not evaluate \fIexpression2\fP if the value of
922 \fIexpression1\fP is sufficient to determine the return value of
923 the entire conditional expression.
924 .RE
925 .TP
926 \fBfor\fP \fIname\fP [ [ \fBin\fP \fIword .\|.\|.\&\fP ] ; ] \fBdo\fP \fIlist\fP ; \fBdone\fP
927 First, expand The list of words following \fBin\fP, generating a list
928 of items.
929 Then, the variable \fIname\fP is set to each element of this list
930 in turn, and \fIlist\fP is executed each time.
931 If the \fBin\fP \fIword\fP is omitted, the \fBfor\fP command executes
932 \fIlist\fP once for each positional parameter that is set (see
933 .SM
934 .B PARAMETERS
935 below).
936 The return status is the exit status of the last command that executes.
937 If the expansion of the items following \fBin\fP results in an empty
938 list, no commands are executed, and the return status is 0.
939 .TP
940 \fBfor\fP (( \fIexpr1\fP ; \fIexpr2\fP ; \fIexpr3\fP )) [;] \fBdo\fP \fIlist\fP ; \fBdone\fP
941 First, evaluate the arithmetic expression \fIexpr1\fP according
942 to the rules described below under
943 .SM
944 .BR "ARITHMETIC EVALUATION" .
945 Then, repeatedly evaluate the arithmetic expression \fIexpr2\fP
946 until it evaluates to zero.
947 Each time \fIexpr2\fP evaluates to a non-zero value,
948 execute \fIlist\fP
949 and evaluate the arithmetic expression \fIexpr3\fP.
950 If any expression is omitted, it behaves as if it evaluates to 1.
951 The return value is the exit status of the last command in \fIlist\fP
952 that is executed, or non-zero if any of the expressions is invalid.
953 .IP
954 Use the \fBbreak\fP and \fPcontinue\fP builtins
955 (see
956 .SM
957 .B "SHELL BUILTIN COMMANDS"
958 below)
959 to control loop execution.
960 .TP
961 \fBselect\fP \fIname\fP [ \fBin\fP \fIword\fP ] ; \fBdo\fP \fIlist\fP ; \fBdone\fP
962 First, expand the list of words following \fBin\fP,
963 generating a list of items, and print the set of expanded words
964 the standard error, each preceded by a number.
965 If the \fBin\fP
966 \fIword\fP is omitted, print the positional parameters (see
967 .SM
968 .B PARAMETERS
969 below).
970 .B select
971 then displays the
972 .SM
973 .B PS3
974 prompt and reads a line from the standard input.
975 If the line consists of a number corresponding to one of
976 the displayed words, then \fBselect\fP sets the value of
977 .I name
978 to that word.
979 If the line is empty, \fBselect\fP displays the words and prompt again.
980 If EOF is read, \fBselect\fP completes and returns 1.
981 Any other value sets
982 .I name
983 to null.
984 The line read is saved in the variable
985 .SM
986 .BR REPLY .
987 The
988 .I list
989 is executed after each selection until a
990 .B break
991 command is executed.
992 The exit status of
993 .B select
994 is the exit status of the last command executed in
995 .IR list ,
996 or zero if no commands were executed.
997 .TP
998 \fBcase\fP \fIword\fP \fBin\fP [ [(] \fIpattern\fP [ \fB|\fP \fIpattern\fP ] \
999 .\|.\|.\& ) \fIlist\fP ;; ] .\|.\|.\& \
1000 \fBesac\fP
1001 A \fBcase\fP command first expands \fIword\fP, and tries to match
1002 it against each \fIpattern\fP in turn,
1003 proceeding from first to last,
1004 using the matching rules
1005 described under
1006 .B "Pattern Matching"
1007 below.
1008 A pattern list is a set of one or more patterns separated by \|,
1009 and the ) operator terminates the pattern list.
1010 The \fIword\fP is expanded using tilde
1011 expansion, parameter and variable expansion, arithmetic expansion,
1012 command substitution, process substitution and quote removal.
1013 Each \fIpattern\fP examined is expanded using tilde
1014 expansion, parameter and variable expansion, arithmetic expansion,
1015 command substitution, process substitution, and quote removal.
1016 If the
1017 .B nocasematch
1018 shell option is enabled, the match is performed without regard to the case
1019 of alphabetic characters.
1020 A \fIclause\fP is a pattern list and an associated \fIlist\fP.
1021 .IP
1022 When a match is found, \fBcase\fP executes the corresponding \fIlist\fP.
1023 If the \fB;;\fP operator terminates the case clause, the \fBcase\fP
1024 command completes after the first match.
1025 Using \fB;&\fP in place of \fB;;\fP causes execution to continue with
1026 the \fIlist\fP associated with the next pattern list.
1027 Using \fB;;&\fP in place of \fB;;\fP causes the shell to test the next
1028 pattern list in the statement, if any, and execute any associated \fIlist\fP
1029 if the match succeeds,
1030 continuing the case statement execution as if the pattern list had not matched.
1031 The exit status is zero if no pattern matches.
1032 .IP
1033 Otherwise, it is the exit status of the
1034 last command executed in the last \fIlist\fP executed.
1035 .TP
1036 \fBif\fP \fIlist\fP; \fBthen\fP \fIlist\fP; \
1037 [ \fBelif\fP \fIlist\fP; \fBthen\fP \fIlist\fP; ] .\|.\|.\& \
1038 [ \fBelse\fP \fIlist\fP; ] \fBfi\fP
1039 The
1040 .B if
1041 .I list
1042 is executed.
1043 If its exit status is zero, the
1044 \fBthen\fP \fIlist\fP is executed.
1045 Otherwise, each \fBelif\fP \fIlist\fP is executed in turn,
1046 and if its exit status is zero, the corresponding \fBthen\fP \fIlist\fP
1047 is executed and the command completes.
1048 Otherwise, the \fBelse\fP \fIlist\fP is executed, if present.
1049 The exit status is the exit status of the
1050 last command executed, or zero if no condition tested true.
1051 .TP
1052 \fBwhile\fP \fIlist-1\fP; \fBdo\fP \fIlist-2\fP; \fBdone\fP
1053 .PD 0
1054 .TP
1055 \fBuntil\fP \fIlist-1\fP; \fBdo\fP \fIlist-2\fP; \fBdone\fP
1056 .PD
1057 The \fBwhile\fP command continuously executes the list
1058 \fIlist-2\fP as long as the last command in the list \fIlist-1\fP returns
1059 an exit status of zero.
1060 The \fBuntil\fP command is identical
1061 to the \fBwhile\fP command, except that the test is negated:
1062 .I list-2
1063 is executed as long as the last command in
1064 .I list-1
1065 returns a non-zero exit status.
1066 The exit status of the \fBwhile\fP and \fBuntil\fP commands
1067 is the exit status
1068 of the last command executed in \fIlist-2\fP, or zero if
1069 none was executed.
1070 .SS Coprocesses
1071 A \fIcoprocess\fP is a shell command preceded by the \fBcoproc\fP reserved
1072 word.
1073 A coprocess is executed asynchronously in a subshell, as if the command
1074 had been terminated with the \fB&\fP control operator, with a two-way pipe
1075 established between the executing shell and the coprocess.
1076 .PP
1077 The syntax for a coprocess is:
1078 .RS
1079 .PP
1080 \fBcoproc\fP [\fINAME\fP] \fIcommand\fP [\fIredirections\fP]
1081 .RE
1082 .PP
1083 This creates a coprocess named \fINAME\fP.
1084 \fIcommand\fP may be either a simple command or a compound
1085 command (see above).
1086 \fINAME\fP is a shell variable name.
1087 If \fINAME\fP is not supplied, the default name is \fBCOPROC\fP.
1088 .PP
1089 The recommended form to use for a coprocess is
1090 .RS
1091 .PP
1092 \fBcoproc\fP \fINAME\fP { \fIcommand\fP [\fIredirections\fP]; }
1093 .RE
1094 .PP
1095 This form is preferred because simple commands result in the coprocess
1096 always being named \fBCOPROC\fP, and it is simpler to use and more complete
1097 than the other compound commands.
1098 .PP
1099 If \fIcommand\fP is a compound command, \fINAME\fP is optional. The
1100 word following \fBcoproc\fP determines whether that word is interpreted
1101 as a variable name: it is interpreted as \fINAME\fP if it is not a
1102 reserved word that introduces a compound command.
1103 If \fIcommand\fP is a simple command, \fINAME\fP is not allowed; this
1104 is to avoid confusion between \fINAME\fP and the first word of the simple
1105 command.
1106 .PP
1107 When the coprocess is executed, the shell creates an array variable (see
1108 .B Arrays
1109 below) named \fINAME\fP in the context of the executing shell.
1110 The standard output of
1111 .I command
1112 is connected via a pipe to a file descriptor in the executing shell,
1113 and that file descriptor is assigned to \fINAME\fP[0].
1114 The standard input of
1115 .I command
1116 is connected via a pipe to a file descriptor in the executing shell,
1117 and that file descriptor is assigned to \fINAME\fP[1].
1118 This pipe is established before any redirections specified by the
1119 command (see
1120 .SM
1121 .B REDIRECTION
1122 below).
1123 The file descriptors can be utilized as arguments to shell commands
1124 and redirections using standard word expansions.
1125 Other than those created to execute command and process substitutions,
1126 the file descriptors are not available in subshells.
1127 .PP
1128 The process ID of the shell spawned to execute the coprocess is
1129 available as the value of the variable \fINAME\fP_PID.
1130 The \fBwait\fP
1131 builtin may be used to wait for the coprocess to terminate.
1132 .PP
1133 Since the coprocess is created as an asynchronous command,
1134 the \fBcoproc\fP command always returns success.
1135 The return status of a coprocess is the exit status of \fIcommand\fP.
1136 .SS Shell Function Definitions
1137 A shell function is an object that is called like a simple command and
1138 executes a compound command with a new set of positional parameters.
1139 Shell functions are declared as follows:
1140 .TP
1141 \fIfname\fP () \fIcompound\-command\fP [\fIredirection\fP]
1142 .PD 0
1143 .TP
1144 \fBfunction\fP \fIfname\fP [()] \fIcompound\-command\fP [\fIredirection\fP]
1145 .PD
1146 This defines a function named \fIfname\fP.
1147 The reserved word \fBfunction\fP is optional.
1148 If the \fBfunction\fP reserved word is supplied, the parentheses are optional.
1149 The \fIbody\fP of the function is the compound command
1150 .I compound\-command
1151 (see \fBCompound Commands\fP above).
1152 That command is usually a \fIlist\fP of commands between { and }, but
1153 may be any command listed under \fBCompound Commands\fP above.
1154 If the \fBfunction\fP reserved word is used, but the
1155 parentheses are not supplied, the braces are recommended.
1156 \fIcompound\-command\fP is executed whenever \fIfname\fP is specified as the
1157 name of a simple command.
1158 When in posix mode, \fIfname\fP must be a valid shell \fIname\fP
1159 and may not be the name of one of the
1160 .SM POSIX
1161 \fIspecial builtins\fP.
1162 In default mode, a function name can be any unquoted shell word that does
1163 not contain \fB$\fP.
1164 .PP
1165 Any redirections (see
1166 .SM
1167 .B REDIRECTION
1168 below) specified when a function is defined are performed
1169 when the function is executed.
1170 .PP
1171 The exit status of a function definition is zero unless a syntax error
1172 occurs or a readonly function with the same name already exists.
1173 When executed, the exit status of a function is the exit status of the
1174 last command executed in the body. (See
1175 .SM
1176 .B FUNCTIONS
1177 below.)
1178 .SH COMMENTS
1179 In a non-interactive shell, or an interactive shell in which the
1180 .B interactive_comments
1181 option to the
1182 .B shopt
1183 builtin is enabled (see
1184 .SM
1185 .B "SHELL BUILTIN COMMANDS"
1186 below), a word beginning with
1187 .B #
1188 introduces a comment.
1189 A word begins at the beginning of a line, after unquoted whitespace, or
1190 after an operator.
1191 The comment causes that word and all remaining characters on that line to
1192 be ignored.
1193 An interactive shell without the
1194 .B interactive_comments
1195 option enabled does not allow comments.
1196 The
1197 .B interactive_comments
1198 option is enabled by default in interactive shells.
1199 .SH QUOTING
1200 \fIQuoting\fP is used to remove the special meaning of certain
1201 characters or words to the shell.
1202 Quoting can be used to
1203 disable special treatment for special characters, to prevent
1204 reserved words from being recognized as such, and to prevent
1205 parameter expansion.
1206 .PP
1207 Each of the \fImetacharacters\fP listed above under
1208 .SM
1209 .B DEFINITIONS
1210 has special meaning to the shell and must be quoted if it is to
1211 represent itself.
1212 .PP
1213 When the command history expansion facilities are being used
1214 (see
1215 .SM
1216 .B "HISTORY EXPANSION"
1217 below), the
1218 \fIhistory expansion\fP character, usually \fB!\fP, must be quoted
1219 to prevent history expansion.
1220 .PP
1221 There are four quoting mechanisms: the
1222 .IR "escape character" ,
1223 single quotes, double quotes,
1224 and dollar-single quotes.
1225 .PP
1226 A non-quoted backslash (\fB\e\fP) is the
1227 .IR "escape character" .
1228 It preserves the literal value of the next character that follows,
1229 removing any special meaning it has,
1230 with the exception of <newline>.
1231 If a \fB\e\fP<newline> pair appears, and the backslash is not itself quoted,
1232 the \fB\e\fP<newline> is treated as a line continuation (that is, it is
1233 removed from the input stream and effectively ignored).
1234 .PP
1235 Enclosing characters in single quotes preserves the literal value
1236 of each character within the quotes.
1237 A single quote may not occur
1238 between single quotes, even when preceded by a backslash.
1239 .PP
1240 Enclosing characters in double quotes preserves the literal value
1241 of all characters within the quotes, with the exception of
1242 .BR $ ,
1243 .BR \` ,
1244 .BR \e ,
1245 and, when history expansion is enabled,
1246 .BR ! .
1247 When the shell is in posix mode,
1248 the \fB!\fP has no special meaning
1249 within double quotes, even when history expansion is enabled.
1250 The characters
1251 .B $
1252 and
1253 .B \`
1254 retain their special meaning within double quotes.
1255 The backslash retains its special meaning only when followed by one of
1256 the following characters:
1257 .BR $ ,
1258 .BR \` ,
1259 \^\fB\*"\fP\^,
1260 .BR \e ,
1261 or
1262 .BR <newline> .
1263 Backslashes preceding characters without a
1264 special meaning are left unmodified.
1265 .PP
1266 A double quote may be quoted within double quotes by preceding it with
1267 a backslash.
1268 If enabled, history expansion will be performed unless an
1269 .B !
1270 appearing in double quotes is escaped using a backslash.
1271 The backslash preceding the
1272 .B !
1273 is not removed.
1274 .PP
1275 The special parameters
1276 .B *
1277 and
1278 .B @
1279 have special meaning when in double quotes
1280 (see
1281 .SM
1282 .B PARAMETERS
1283 below).
1284 .PP
1285 Character sequences of the form \fB$\fP\*'\fIstring\fP\*' are treated
1286 as a special variant of single quotes.
1287 The sequence expands to \fIstring\fP, with backslash-escaped characters
1288 in \fIstring\fP replaced as specified by the ANSI C standard.
1289 Backslash escape sequences, if present, are decoded as follows:
1290 .RS
1291 .PD 0
1292 .TP
1293 .B \ea
1294 alert (bell)
1295 .TP
1296 .B \eb
1297 backspace
1298 .TP
1299 .B \ee
1300 .TP
1301 .B \eE
1302 an escape character
1303 .TP
1304 .B \ef
1305 form feed
1306 .TP
1307 .B \en
1308 new line
1309 .TP
1310 .B \er
1311 carriage return
1312 .TP
1313 .B \et
1314 horizontal tab
1315 .TP
1316 .B \ev
1317 vertical tab
1318 .TP
1319 .B \e\e
1320 backslash
1321 .TP
1322 .B \e\*'
1323 single quote
1324 .TP
1325 .B \e\*"
1326 double quote
1327 .TP
1328 .B \e?
1329 question mark
1330 .TP
1331 .B \e\fInnn\fP
1332 The eight-bit character whose value is the octal value \fInnn\fP
1333 (one to three octal digits).
1334 .TP
1335 .B \ex\fIHH\fP
1336 The eight-bit character whose value is the hexadecimal value \fIHH\fP
1337 (one or two hex digits).
1338 .TP
1339 .B \eu\fIHHHH\fP
1340 The Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
1341 \fIHHHH\fP (one to four hex digits).
1342 .TP
1343 .B \eU\fIHHHHHHHH\fP
1344 The Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
1345 \fIHHHHHHHH\fP (one to eight hex digits).
1346 .TP
1347 .B \ec\fIx\fP
1348 A control-\fIx\fP character.
1349 .PD
1350 .RE
1351 .LP
1352 The expanded result is single-quoted, as if the dollar sign had
1353 not been present.
1354 .SS "Translating Strings"
1355 A double-quoted string preceded by a dollar sign (\fB$\fP\*"\fIstring\fP\*")
1356 causes the string to be translated according to the current locale.
1357 The \fIgettext\fP infrastructure performs the lookup and
1358 translation, using the \fBLC_MESSAGES\fP, \fBTEXTDOMAINDIR\fP,
1359 and \fBTEXTDOMAIN\fP shell variables.
1360 If the current locale is \fBC\fP or \fBPOSIX\fP,
1361 if there are no translations available,
1362 or if the string is not translated, the dollar sign is ignored,
1363 and the string is treated as double-quoted as described above.
1364 This is a form of double quoting, so the string remains double-quoted
1365 by default, whether or not it is translated and replaced.
1366 If the \fBnoexpand_translation\fP option is enabled
1367 using the \fBshopt\fP builtin,
1368 translated strings are single-quoted instead of double-quoted.
1369 See the description of
1370 .B shopt
1371 below under
1372 .SM
1373 .BR "SHELL BUILTIN COMMANDS" .
1374 .SH PARAMETERS
1375 A
1376 .I parameter
1377 is an entity that stores values.
1378 It can be a
1379 .IR name ,
1380 a number, or one of the special characters listed below under
1381 .BR "Special Parameters" .
1382 A
1383 .I variable
1384 is a parameter denoted by a
1385 .IR name .
1386 A variable has a \fIvalue\fP and zero or more \fIattributes\fP.
1387 Attributes are assigned using the
1388 .B declare
1389 builtin command (see
1390 .B declare
1391 below in
1392 .SM
1393 .BR "SHELL BUILTIN COMMANDS" ).
1394 The \fBexport\fP and \fBreadonly\fP builtins assign specific attributes.
1395 .PP
1396 A parameter is set if it has been assigned a value.
1397 The null string is a valid value.
1398 Once a variable is set, it may be unset only by using the
1399 .B unset
1400 builtin command (see
1401 .SM
1402 .B "SHELL BUILTIN COMMANDS"
1403 below).
1404 .PP
1405 A
1406 .I variable
1407 is assigned to using a statement of the form
1408 .RS
1409 .PP
1410 \fIname\fP=[\fIvalue\fP]
1411 .RE
1412 .PP
1413 If
1414 .I value
1415 is not given, the variable is assigned the null string.
1416 All
1417 .I values
1418 undergo tilde expansion, parameter and variable expansion,
1419 command substitution, arithmetic expansion, and quote
1420 removal (see
1421 .SM
1422 .B EXPANSION
1423 below).
1424 If the variable has its
1425 .B integer
1426 attribute set, then
1427 .I value
1428 is evaluated as an arithmetic expression even if the
1429 .BR $(( .\|.\|.\& ))
1430 expansion is not used (see
1431 .B "Arithmetic Expansion"
1432 below).
1433 Word splitting and pathname expansion are not performed.
1434 Assignment statements may also appear as arguments to the
1435 .BR alias ,
1436 .BR declare ,
1437 .BR typeset ,
1438 .BR \%export ,
1439 .BR readonly ,
1440 and
1441 .B local
1442 builtin commands (\fIdeclaration\fP commands).
1443 When in posix mode, these builtins may appear in a command after
1444 one or more instances of the \fBcommand\fP builtin and retain these
1445 assignment statement properties.
1446 .PP
1447 In the context where an assignment statement is assigning a value
1448 to a shell variable or array index, the
1449 .Q +=
1450 operator appends to or adds to
1451 the variable's previous value.
1452 This includes arguments to \fIdeclaration\fP commands such as
1453 .B \%declare
1454 that accept assignment statements.
1455 When
1456 .Q +=
1457 is applied to a variable for which the
1458 .B \%integer
1459 attribute has been set,
1460 the variable's current value and \fIvalue\fP are each evaluated as
1461 arithmetic expressions,
1462 and the sum of the results is assigned as the variable's value.
1463 The current value is usually an integer constant, but may be an expression.
1464 When
1465 .Q +=
1466 is applied to an array variable using compound assignment
1467 (see
1468 .B Arrays
1469 below),
1470 the variable's value is not unset
1471 (as it is when using
1472 .Q = ),
1473 and new values are appended to the array
1474 beginning at one greater than the array's maximum index (for indexed arrays)
1475 or added as additional key\-value pairs in an associative array.
1476 When applied to a string-valued variable, \fIvalue\fP is expanded and
1477 appended to the variable's value.
1478 .PP
1479 A variable can be assigned the \fInameref\fP attribute using the
1480 \fB\-n\fP option to the \fBdeclare\fP or \fBlocal\fP builtin commands
1481 (see the descriptions of \fBdeclare\fP and \fBlocal\fP below)
1482 to create a \fInameref\fP, or a reference to another variable.
1483 This allows variables to be manipulated indirectly.
1484 Whenever the nameref variable is referenced, assigned to, unset, or has
1485 its attributes modified (other than using or changing the \fInameref\fP
1486 attribute itself), the
1487 operation is actually performed on the variable specified by the nameref
1488 variable's value.
1489 A nameref is commonly used within shell functions to refer to a variable
1490 whose name is passed as an argument to the function.
1491 For instance, if a variable name is passed to a shell function as its first
1492 argument, running
1493 .PP
1494 .RS
1495 .EX
1496 declare \-n ref=$1
1497 .EE
1498 .RE
1499 .PP
1500 inside the function creates a local nameref variable \fBref\fP whose value
1501 is the variable name passed as the first argument.
1502 References and assignments to \fBref\fP, and changes to its attributes,
1503 are treated as references, assignments, and attribute modifications
1504 to the variable whose name was passed as \fB$1\fP.
1505 If the control variable in a \fBfor\fP loop has the nameref attribute,
1506 the list of words can be a list of shell variables, and a name reference
1507 is established for each word in the list, in turn, when the loop is
1508 executed.
1509 Array variables cannot be given the \fBnameref\fP attribute.
1510 However, nameref variables can reference array variables and subscripted
1511 array variables.
1512 Namerefs can be unset using the \fB\-n\fP option to the \fBunset\fP builtin.
1513 Otherwise, if \fBunset\fP is executed with the name of a nameref variable
1514 as an argument, the variable referenced by the nameref variable is unset.
1515 .PP
1516 When the shell starts, it reads its environment and creates a shell
1517 variable from each environment variable that has a valid name,
1518 as described below
1519 (see
1520 .SM
1521 .BR ENVIRONMENT ).
1522 .SS Positional Parameters
1523 A
1524 .I positional parameter
1525 is a parameter denoted by one or more
1526 digits, other than the single digit 0.
1527 Positional parameters are
1528 assigned from the shell's arguments when it is invoked,
1529 and may be reassigned using the
1530 .B set
1531 builtin command.
1532 Positional parameters may not be assigned to
1533 with assignment statements.
1534 The positional parameters are
1535 temporarily replaced when a shell function is executed (see
1536 .SM
1537 .B FUNCTIONS
1538 below).
1539 .PP
1540 When a positional parameter consisting of more than a single
1541 digit is expanded, it must be enclosed in braces (see
1542 .SM
1543 .B EXPANSION
1544 below).
1545 Without braces, a digit following $ can only refer to
1546 one of the first nine positional parameters (\fB$1\-$9\fP) or the
1547 special parameter \fB$0\fP (see the next section).
1548 .SS Special Parameters
1549 The shell treats several parameters specially.
1550 These parameters may only be referenced; assignment to them is
1551 not allowed.
1552 Special parameters are denoted by one of the following characters.
1553 .TP
1554 .PD 0
1555 .B *
1556 (\fB$*\fP) Expands to the positional parameters, starting from one.
1557 When the expansion is not within double quotes, each positional parameter
1558 expands to a separate word.
1559 In contexts where word expansions are performed, those words
1560 are subject to further word splitting and pathname expansion.
1561 When the expansion occurs within double quotes, it expands to a
1562 single word with the value of each parameter separated by the first
1563 character of the
1564 .SM
1565 .B IFS
1566 variable.
1567 That is,
1568 .B \*"$*\*"
1569 is equivalent to
1570 .BR \*"$1\fIc\fP$2\fIc\fP.\|.\|.\*" ,
1571 where
1572 .I c
1573 is the first character of the value of the
1574 .SM
1575 .B IFS
1576 variable.
1577 If
1578 .SM
1579 .B IFS
1580 is unset, the parameters are separated by spaces.
1581 If
1582 .SM
1583 .B IFS
1584 is null, the parameters are joined without intervening separators.
1585 .TP
1586 .B @
1587 (\fB$@\fP) Expands to the positional parameters, starting from one.
1588 In contexts where word splitting is performed, this expands each
1589 positional parameter to a separate word; if not within double
1590 quotes, these words are subject to word splitting.
1591 In contexts where word splitting is not performed,
1592 such as the value portion of an assignment statement,
1593 this expands to a single word
1594 with each positional parameter separated by a space.
1595 When the expansion occurs within double quotes,
1596 and word splitting is performed,
1597 each parameter expands to a separate word.
1598 That is,
1599 .B \&\*"$@\*"
1600 is equivalent to
1601 .B \&\*"\&$1\&\*"\ \*"$2\*"\ .\|.\|.
1602 If the double-quoted expansion occurs within a word, the expansion of
1603 the first parameter is joined with the expansion of the
1604 beginning part of the original word,
1605 and the expansion of the last parameter is joined with the
1606 expansion of the last part of the original word.
1607 When there are no positional parameters,
1608 .B \&\*"$@\*"
1609 and
1610 .B $@
1611 expand to nothing (i.e., they are removed).
1612 .TP
1613 .B #
1614 (\fB$#\fP) Expands to the number of positional parameters in decimal.
1615 .TP
1616 .B ?
1617 (\fB$?\fP) Expands to the exit status of the most recently executed command.
1618 .TP
1619 .B \-
1620 (\fB$\-\fP) Expands to the current option flags as specified upon invocation,
1621 by the
1622 .B set
1623 builtin command, or those set by the shell itself
1624 (such as the
1625 .B \-i
1626 option).
1627 .TP
1628 .B $
1629 (\fB$$\fP) Expands to the process ID of the shell.
1630 In a subshell, it expands to the process ID of the parent shell,
1631 not the subshell.
1632 .TP
1633 .B !
1634 (\fB$!\fP)Expands to the process ID of the job most recently placed into the
1635 background, whether executed as an asynchronous command or using
1636 the \fBbg\fP builtin (see
1637 .SM
1638 .B "JOB CONTROL"
1639 below).
1640 .TP
1641 .B 0
1642 (\fB$0\fP) Expands to the name of the shell or shell script.
1643 This is set at shell initialization.
1644 If \fBbash\fP is invoked with a file of commands,
1645 .B $0
1646 is set to the name of that file.
1647 If \fBbash\fP is started with the
1648 .B \-c
1649 option, then
1650 .B $0
1651 is set to the first argument after the string to be
1652 executed, if one is present.
1653 Otherwise, it is set to the filename used to invoke
1654 .BR bash ,
1655 as given by argument zero.
1656 .PD
1657 .SS "Shell Variables"
1658 The shell sets following variables:
1659 .PP
1660 .PD 0
1661 .TP
1662 .B _
1663 (\fB$_\fP, an underscore)
1664 This has a number of meanings depending on context.
1665 At shell startup, \fB_\fP is set to the pathname used to invoke the
1666 shell or shell script being executed as passed in the environment
1667 or argument list.
1668 Subsequently, it expands to the last argument to the previous simple
1669 command executed in the foreground, after expansion.
1670 It is also set to the full pathname used to invoke each command executed
1671 and placed in the environment exported to that command.
1672 When checking mail, \fB$_\fP expands to the name of the mail file
1673 currently being checked.
1674 .TP
1675 .B BASH
1676 Expands to the full filename used to invoke this instance of
1677 .BR bash .
1678 .TP
1679 .B BASHOPTS
1680 A colon-separated list of enabled shell options. Each word in
1681 the list is a valid argument for the
1682 .B \-s
1683 option to the
1684 .B shopt
1685 builtin command (see
1686 .SM
1687 .B "SHELL BUILTIN COMMANDS"
1688 below).
1689 The options appearing in
1690 .SM
1691 .B BASHOPTS
1692 are those reported as
1693 .I on
1694 by \fBshopt\fP.
1695 If this variable is in the environment when
1696 .B bash
1697 starts up, the shell enables each option in the list before
1698 reading any startup files.
1699 If this variable is exported, child shells will enable each option
1700 in the list.
1701 This variable is read-only.
1702 .TP
1703 .B BASHPID
1704 Expands to the process ID of the current \fBbash\fP process.
1705 This differs from \fB$$\fP under certain circumstances, such as subshells
1706 that do not require \fBbash\fP to be re-initialized.
1707 Assignments to
1708 .SM
1709 .B BASHPID
1710 have no effect.
1711 If
1712 .SM
1713 .B BASHPID
1714 is unset, it loses its special properties, even if it is
1715 subsequently reset.
1716 .TP
1717 .B BASH_ALIASES
1718 An associative array variable whose members correspond to the internal
1719 list of aliases as maintained by the \fBalias\fP builtin.
1720 Elements added to this array appear in the alias list; however,
1721 unsetting array elements currently does not remove aliases
1722 from the alias list.
1723 If
1724 .SM
1725 .B BASH_ALIASES
1726 is unset, it loses its special properties, even if it is
1727 subsequently reset.
1728 .TP
1729 .B BASH_ARGC
1730 An array variable whose values are the number of parameters in each
1731 frame of the current \fBbash\fP execution call stack.
1732 The number of parameters to the current subroutine (shell function or
1733 script executed with \fB.\fP or \fBsource\fP) is at the top of the stack.
1734 When a subroutine is executed, the number of parameters passed is pushed onto
1735 .SM
1736 .BR BASH_ARGC .
1737 The shell sets
1738 .SM
1739 .B BASH_ARGC
1740 only when in extended debugging mode (see the description of the
1741 .B extdebug
1742 option to the
1743 .B shopt
1744 builtin below).
1745 Setting \fBextdebug\fP after the shell has started to execute a script,
1746 or referencing this variable when \fBextdebug\fP is not set,
1747 may result in inconsistent values.
1748 Assignments to
1749 .SM
1750 .B BASH_ARGC
1751 have no effect, and it may not be unset.
1752 .TP
1753 .B BASH_ARGV
1754 An array variable containing all of the parameters in the current \fBbash\fP
1755 execution call stack.
1756 The final parameter of the last subroutine call is at the top of the stack;
1757 the first parameter of the initial call is at the bottom.
1758 When a subroutine is executed, the shell pushes the supplied parameters onto
1759 .SM
1760 .BR BASH_ARGV .
1761 The shell sets
1762 .SM
1763 .B BASH_ARGV
1764 only when in extended debugging mode
1765 (see the description of the
1766 .B extdebug
1767 option to the
1768 .B shopt
1769 builtin below).
1770 Setting \fBextdebug\fP after the shell has started to execute a script,
1771 or referencing this variable when \fBextdebug\fP is not set,
1772 may result in inconsistent values.
1773 Assignments to
1774 .SM
1775 .B BASH_ARGV
1776 have no effect, and it may not be unset.
1777 .TP
1778 .B BASH_ARGV0
1779 When referenced, this variable expands to the name of the shell or shell
1780 script (identical to
1781 .BR $0 ;
1782 see the description of special parameter 0 above).
1783 Assigning a value to
1784 .SM
1785 .B BASH_ARGV0
1786 sets \fB$0\fP to the same value.
1787 If
1788 .SM
1789 .B BASH_ARGV0
1790 is unset, it loses its special properties, even if it is
1791 subsequently reset.
1792 .TP
1793 .B BASH_CMDS
1794 An associative array variable whose members correspond to the internal
1795 hash table of commands as maintained by the \fBhash\fP builtin.
1796 Adding elements to this array makes them appear in the hash table; however,
1797 unsetting array elements currently does not remove command names
1798 from the hash table.
1799 If
1800 .SM
1801 .B BASH_CMDS
1802 is unset, it loses its special properties, even if it is
1803 subsequently reset.
1804 .TP
1805 .B BASH_COMMAND
1806 Expands to the command currently being executed or about to be executed,
1807 unless the shell is executing a command as the result of a trap,
1808 in which case it is the command executing at the time of the trap.
1809 If
1810 .SM
1811 .B BASH_COMMAND
1812 is unset, it loses its special properties, even if it is
1813 subsequently reset.
1814 .TP
1815 .B BASH_EXECUTION_STRING
1816 The command argument to the \fB\-c\fP invocation option.
1817 .TP
1818 .B BASH_LINENO
1819 An array variable whose members are the line numbers in source files
1820 where each corresponding member of
1821 .SM
1822 .B FUNCNAME
1823 was invoked.
1824 \fB${BASH_LINENO[\fP\fI$i\fP\fB]}\fP
1825 is the line number in the source file
1826 (\fB${BASH_SOURCE[\fP\fI$i+1\fP\fB]}\fP)
1827 where
1828 \fB${FUNCNAME[\fP\fI$i\fP\fB]}\fP
1829 was called
1830 (or \fB${BASH_LINENO[\fP\fI$i\-1\fP\fB]}\fP if referenced within another
1831 shell function).
1832 Use
1833 .SM
1834 .B LINENO
1835 to obtain the current line number.
1836 Assignments to
1837 .SM
1838 .B BASH_LINENO
1839 have no effect, and it may not be unset.
1840 .TP
1841 .B BASH_LOADABLES_PATH
1842 A colon-separated list of directories in which the
1843 .B enable
1844 command
1845 looks for
1846 dynamically loadable builtins.
1847 .TP
1848 .B BASH_MONOSECONDS
1849 Each time this variable is referenced, it expands to the value returned
1850 by the system's monotonic clock, if one is available.
1851 If there is no monotonic clock, this is equivalent to \fBEPOCHSECONDS\fP.
1852 If
1853 .SM
1854 .B BASH_MONOSECONDS
1855 is unset, it loses its special properties, even if it is
1856 subsequently reset.
1857 .TP
1858 .B BASH_REMATCH
1859 An array variable whose members are assigned by the \fB=\*~\fP binary
1860 operator to the \fB[[\fP conditional command.
1861 The element with index 0 is the portion of the string
1862 matching the entire regular expression.
1863 The element with index \fIn\fP is the portion of the
1864 string matching the \fIn\fPth parenthesized subexpression.
1865 .TP
1866 .B BASH_SOURCE
1867 An array variable whose members are the source filenames
1868 where the corresponding shell function names in the
1869 .SM
1870 .B FUNCNAME
1871 array variable are defined.
1872 The shell function
1873 \fB${FUNCNAME[\fP\fI$i\fP\fB]}\fP is defined in the file
1874 \fB${BASH_SOURCE[\fP\fI$i\fP\fB]}\fP and called from
1875 \fB${BASH_SOURCE[\fP\fI$i+1\fP\fB]}\fP.
1876 Assignments to
1877 .SM
1878 .B BASH_SOURCE
1879 have no effect, and it may not be unset.
1880 .TP
1881 .B BASH_SUBSHELL
1882 Incremented by one within each subshell or subshell environment when
1883 the shell begins executing in that environment.
1884 The initial value is 0.
1885 If
1886 .SM
1887 .B BASH_SUBSHELL
1888 is unset, it loses its special properties, even if it is
1889 subsequently reset.
1890 .TP
1891 .B BASH_TRAPSIG
1892 Set to the signal number corresponding to the trap action being executed
1893 during its execution.
1894 See the description of \fBtrap\fP under
1895 .SM
1896 .B "SHELL BUILTIN COMMANDS"
1897 below for information about signal numbers and trap execution.
1898 .TP
1899 .B BASH_VERSINFO
1900 A readonly array variable whose members hold version information for
1901 this instance of
1902 .BR bash .
1903 The values assigned to the array members are as follows:
1904 .PP
1905 .RS
1906 .TP 24
1907 .B BASH_VERSINFO[\fR0\fP]
1908 The major version number (the \fIrelease\fP).
1909 .TP
1910 .B BASH_VERSINFO[\fR1\fP]
1911 The minor version number (the \fIversion\fP).
1912 .TP
1913 .B BASH_VERSINFO[\fR2\fP]
1914 The patch level.
1915 .TP
1916 .B BASH_VERSINFO[\fR3\fP]
1917 The build version.
1918 .TP
1919 .B BASH_VERSINFO[\fR4\fP]
1920 The release status (e.g., \fIbeta\fP).
1921 .TP
1922 .B BASH_VERSINFO[\fR5\fP]
1923 The value of
1924 .SM
1925 .BR MACHTYPE .
1926 .RE
1927 .TP
1928 .B BASH_VERSION
1929 Expands to a string describing the version of this instance of
1930 .B bash
1931 (e.g., 5.2.37(3)-release).
1932 .TP
1933 .B COMP_CWORD
1934 An index into \fB${COMP_WORDS}\fP of the word containing the current
1935 cursor position.
1936 This variable is available only in shell functions invoked by the
1937 programmable completion facilities (see \fBProgrammable Completion\fP
1938 below).
1939 .TP
1940 .B COMP_KEY
1941 The key (or final key of a key sequence) used to invoke the current
1942 completion function.
1943 This variable is available only in shell functions and external
1944 commands invoked by the
1945 programmable completion facilities (see \fBProgrammable Completion\fP
1946 below).
1947 .TP
1948 .B COMP_LINE
1949 The current command line.
1950 This variable is available only in shell functions and external
1951 commands invoked by the
1952 programmable completion facilities (see \fBProgrammable Completion\fP
1953 below).
1954 .TP
1955 .B COMP_POINT
1956 The index of the current cursor position relative to the beginning of
1957 the current command.
1958 If the current cursor position is at the end of the current command,
1959 the value of this variable is equal to \fB${#COMP_LINE}\fP.
1960 This variable is available only in shell functions and external
1961 commands invoked by the
1962 programmable completion facilities (see \fBProgrammable Completion\fP
1963 below).
1964 .TP
1965 .B COMP_TYPE
1966 Set to an integer value corresponding to the type of attempted completion
1967 that caused a completion function to be called:
1968 \fITAB\fP, for normal completion,
1969 \fI?\fP, for listing completions after successive tabs,
1970 \fI!\fP, for listing alternatives on partial word completion,
1971 \fI@\fP, to list completions if the word is not unmodified,
1972 or
1973 \fI%\fP, for menu completion.
1974 This variable is available only in shell functions and external
1975 commands invoked by the
1976 programmable completion facilities (see \fBProgrammable Completion\fP
1977 below).
1978 .TP
1979 .B COMP_WORDBREAKS
1980 The set of characters that the \fBreadline\fP library treats as word
1981 separators when performing word completion.
1982 If
1983 .SM
1984 .B COMP_WORDBREAKS
1985 is unset, it loses its special properties, even if it is
1986 subsequently reset.
1987 .TP
1988 .B COMP_WORDS
1989 An array variable (see \fBArrays\fP below) consisting of the individual
1990 words in the current command line.
1991 The line is split into words as \fBreadline\fP would split it, using
1992 .SM
1993 .B COMP_WORDBREAKS
1994 as described above.
1995 This variable is available only in shell functions invoked by the
1996 programmable completion facilities (see \fBProgrammable Completion\fP
1997 below).
1998 .TP
1999 .B COPROC
2000 An array variable (see \fBArrays\fP below) created to hold the file descriptors
2001 for output from and input to an unnamed coprocess (see \fBCoprocesses\fP
2002 above).
2003 .TP
2004 .B DIRSTACK
2005 An array variable (see
2006 .B Arrays
2007 below) containing the current contents of the directory stack.
2008 Directories appear in the stack in the order they are displayed by the
2009 .B dirs
2010 builtin.
2011 Assigning to members of this array variable may be used to modify
2012 directories already in the stack, but the
2013 .B pushd
2014 and
2015 .B popd
2016 builtins must be used to add and remove directories.
2017 Assigning to this variable does not change the current directory.
2018 If
2019 .SM
2020 .B DIRSTACK
2021 is unset, it loses its special properties, even if it is
2022 subsequently reset.
2023 .TP
2024 .B EPOCHREALTIME
2025 Each time this parameter is referenced, it expands to the number of seconds
2026 since the Unix Epoch (see
2027 .IR time (3))
2028 as a floating-point value with micro-second granularity.
2029 Assignments to
2030 .SM
2031 .B EPOCHREALTIME
2032 are ignored.
2033 If
2034 .SM
2035 .B EPOCHREALTIME
2036 is unset, it loses its special properties, even if it is
2037 subsequently reset.
2038 .TP
2039 .B EPOCHSECONDS
2040 Each time this parameter is referenced, it expands to the number of seconds
2041 since the Unix Epoch (see
2042 .IR time (3)).
2043 Assignments to
2044 .SM
2045 .B EPOCHSECONDS
2046 are ignored.
2047 If
2048 .SM
2049 .B EPOCHSECONDS
2050 is unset, it loses its special properties, even if it is
2051 subsequently reset.
2052 .TP
2053 .B EUID
2054 Expands to the effective user ID of the current user, initialized at
2055 shell startup. This variable is readonly.
2056 .TP
2057 .B FUNCNAME
2058 .PD
2059 An array variable containing the names of all shell functions
2060 currently in the execution call stack.
2061 The element with index 0 is the name of any currently-executing
2062 shell function.
2063 The bottom-most element (the one with the highest index) is
2064 .Q main .
2065 This variable exists only when a shell function is executing.
2066 Assignments to
2067 .SM
2068 .B FUNCNAME
2069 have no effect.
2070 If
2071 .SM
2072 .B FUNCNAME
2073 is unset, it loses its special properties, even if it is
2074 subsequently reset.
2075 .IP
2076 This variable can be used with
2077 .SM
2078 .B BASH_LINENO
2079 and
2080 .SM
2081 .BR BASH_SOURCE .
2082 Each element of
2083 .SM
2084 .B \%FUNCNAME
2085 has corresponding elements in
2086 .SM
2087 .B BASH_LINENO
2088 and
2089 .SM
2090 .B BASH_SOURCE
2091 to describe the call stack.
2092 For instance,
2093 \fB\%${FUNCNAME[\fP\fI$i\fP\fB]}\fP
2094 was called from the file
2095 \fB${BASH_SOURCE[\fP\fI$i+1\fP\fB]}\fP
2096 at line number
2097 \fB${BASH_LINENO[\fP\fI$i\fP\fB]}\fP.
2098 The \fBcaller\fP builtin displays the current call stack using this
2099 information.
2100 .PD 0
2101 .TP
2102 .B GROUPS
2103 An array variable containing the list of groups of which the current
2104 user is a member.
2105 Assignments to
2106 .SM
2107 .B GROUPS
2108 have no effect.
2109 If
2110 .SM
2111 .B GROUPS
2112 is unset, it loses its special properties, even if it is
2113 subsequently reset.
2114 .TP
2115 .B HISTCMD
2116 The history number, or index in the history list, of the current
2117 command.
2118 Assignments to
2119 .SM
2120 .B HISTCMD
2121 have no effect.
2122 If
2123 .SM
2124 .B HISTCMD
2125 is unset, it loses its special properties, even if it is
2126 subsequently reset.
2127 .TP
2128 .B HOSTNAME
2129 Automatically set to the name of the current host.
2130 .TP
2131 .B HOSTTYPE
2132 Automatically set to a string that uniquely
2133 describes the type of machine on which
2134 .B bash
2135 is executing.
2136 The default is system-dependent.
2137 .TP
2138 .B LINENO
2139 Each time this parameter is referenced, the shell substitutes
2140 a decimal number representing the current sequential line number
2141 (starting with 1) within a script or function.
2142 When not in a script or function, the value substituted is not
2143 guaranteed to be meaningful.
2144 If
2145 .SM
2146 .B LINENO
2147 is unset, it loses its special properties, even if it is
2148 subsequently reset.
2149 .TP
2150 .B MACHTYPE
2151 Automatically set to a string that fully describes the system
2152 type on which
2153 .B bash
2154 is executing, in the standard GNU \fIcpu-company-system\fP format.
2155 The default is system-dependent.
2156 .TP
2157 .B MAPFILE
2158 An array variable (see \fBArrays\fP below) created to hold the text
2159 read by the \fBmapfile\fP builtin when no variable name is supplied.
2160 .TP
2161 .B OLDPWD
2162 The previous working directory as set by the
2163 .B cd
2164 command.
2165 .TP
2166 .B OPTARG
2167 The value of the last option argument processed by the
2168 .B getopts
2169 builtin command (see
2170 .SM
2171 .B "SHELL BUILTIN COMMANDS"
2172 below).
2173 .TP
2174 .B OPTIND
2175 The index of the next argument to be processed by the
2176 .B getopts
2177 builtin command (see
2178 .SM
2179 .B "SHELL BUILTIN COMMANDS"
2180 below).
2181 .TP
2182 .B OSTYPE
2183 Automatically set to a string that
2184 describes the operating system on which
2185 .B bash
2186 is executing.
2187 The default is system-dependent.
2188 .TP
2189 .B PIPESTATUS
2190 An array variable (see
2191 .B Arrays
2192 below) containing a list of exit status values from the commands
2193 in the most-recently-executed foreground pipeline, which may
2194 consist of only a simple command
2195 (see
2196 .SM
2197 .B "SHELL GRAMMAR"
2198 above).
2199 \fBBash\fP sets
2200 .SM
2201 .B PIPESTATUS
2202 after executing multi-element pipelines,
2203 timed and negated pipelines,
2204 simple commands,
2205 subshells created with the ( operator,
2206 the
2207 .B [[
2208 and
2209 .B ((
2210 compound commands, and
2211 after error conditions that result in the
2212 shell aborting command execution.
2213 .TP
2214 .B PPID
2215 The process ID of the shell's parent.
2216 This variable is readonly.
2217 .TP
2218 .B PWD
2219 The current working directory as set by the
2220 .B cd
2221 command.
2222 .TP
2223 .B RANDOM
2224 Each time this parameter is referenced, it expands to a random integer
2225 between 0 and 32767.
2226 Assigning a value to
2227 .SM
2228 .B RANDOM
2229 initializes (seeds) the sequence of random numbers.
2230 Seeding the random number generator with the same constant value
2231 produces the same sequence of values.
2232 If
2233 .SM
2234 .B RANDOM
2235 is unset, it loses its special properties, even if it is
2236 subsequently reset.
2237 .TP
2238 .B READLINE_ARGUMENT
2239 Any numeric argument given to a
2240 .B \%readline
2241 command that was defined using
2242 .Q "bind \-x"
2243 (see
2244 .SM
2245 .B "SHELL BUILTIN COMMANDS"
2246 below)
2247 when it was invoked.
2248 .TP
2249 .B READLINE_LINE
2250 The contents of the
2251 .B readline
2252 line buffer, for use with
2253 .Q "bind \-x"
2254 (see
2255 .SM
2256 .B "SHELL BUILTIN COMMANDS"
2257 below).
2258 .TP
2259 .B READLINE_MARK
2260 The position of the mark (saved insertion point) in the
2261 .B readline
2262 line buffer, for use with
2263 .Q "bind \-x"
2264 (see
2265 .SM
2266 .B "SHELL BUILTIN COMMANDS"
2267 below).
2268 The characters between the insertion point and the mark are often
2269 called the \fIregion\fP.
2270 .TP
2271 .B READLINE_POINT
2272 The position of the insertion point in the
2273 .B readline
2274 line buffer, for use with
2275 .Q "bind \-x"
2276 (see
2277 .SM
2278 .B "SHELL BUILTIN COMMANDS"
2279 below).
2280 .TP
2281 .B REPLY
2282 Set to the line of input read by the
2283 .B read
2284 builtin command when no arguments are supplied.
2285 .TP
2286 .B SECONDS
2287 Each time this parameter is
2288 referenced, it expands to the number of seconds since shell invocation.
2289 If a value is assigned to
2290 .SM
2291 .BR SECONDS ,
2292 the value returned upon subsequent
2293 references is
2294 the number of seconds since the assignment plus the value assigned.
2295 The number of seconds at shell invocation and the current time are always
2296 determined by querying the system clock at one-second resolution.
2297 If
2298 .SM
2299 .B SECONDS
2300 is unset, it loses its special properties, even if it is
2301 subsequently reset.
2302 .TP
2303 .B SHELLOPTS
2304 A colon-separated list of enabled shell options.
2305 Each word in the list is a valid argument for the
2306 .B \-o
2307 option to the
2308 .B set
2309 builtin command (see
2310 .SM
2311 .B "SHELL BUILTIN COMMANDS"
2312 below).
2313 The options appearing in
2314 .SM
2315 .B SHELLOPTS
2316 are those reported as
2317 .I on
2318 by \fBset \-o\fP.
2319 If this variable is in the environment when
2320 .B bash
2321 starts up, the shell enables each option in the list before
2322 reading any startup files.
2323 If this variable is exported, child shells will enable each option
2324 in the list.
2325 This variable is read-only.
2326 .TP
2327 .B SHLVL
2328 Incremented by one each time an instance of
2329 .B bash
2330 is started.
2331 .TP
2332 .B SRANDOM
2333 Each time it is referenced, this variable expands to a 32-bit pseudo-random
2334 number.
2335 The random number generator is not linear on systems that
2336 support
2337 .FN /dev/urandom
2338 or
2339 .IR arc4random (3),
2340 so each returned number
2341 has no relationship to the numbers preceding it.
2342 The random number generator cannot be seeded, so assignments to this
2343 variable have no effect.
2344 If
2345 .SM
2346 .B SRANDOM
2347 is unset, it loses its special properties,
2348 even if it is subsequently reset.
2349 .TP
2350 .B UID
2351 Expands to the user ID of the current user, initialized at shell startup.
2352 This variable is readonly.
2353 .PD
2354 .PP
2355 The shell uses the following variables. In some cases,
2356 .B bash
2357 assigns a default value to a variable; these cases are noted
2358 below.
2359 .PP
2360 .PD 0
2361 .TP
2362 .B BASH_COMPAT
2363 The value is used to set the shell's compatibility level.
2364 See
2365 .SM
2366 .B "SHELL COMPATIBILITY MODE"
2367 below for a description of the various compatibility
2368 levels and their effects.
2369 The value may be a decimal number (e.g., 4.2) or an integer (e.g., 42)
2370 corresponding to the desired compatibility level.
2371 If
2372 .SM
2373 .B BASH_COMPAT
2374 is unset or set to the empty string, the compatibility
2375 level is set to the default for the current version.
2376 If
2377 .SM
2378 .B BASH_COMPAT
2379 is set to a value that is not one of the valid
2380 compatibility levels, the shell prints an error message and sets the
2381 compatibility level to the default for the current version.
2382 A subset of the valid values correspond to the compatibility levels
2383 described below under
2384 .SM
2385 .BR "SHELL COMPATIBILITY MODE" .
2386 For example, 4.2 and 42 are valid values that correspond
2387 to the \fBcompat42\fP \fBshopt\fP option
2388 and set the compatibility level to 42.
2389 The current version is also a valid value.
2390 .TP
2391 .B BASH_ENV
2392 If this parameter is set when \fBbash\fP is executing a shell script,
2393 its expanded value is interpreted as a filename containing commands to
2394 initialize the shell before it reads and executes commands from the
2395 script.
2396 The value of
2397 .SM
2398 .B BASH_ENV
2399 is subjected to parameter expansion, command substitution, and arithmetic
2400 expansion before being interpreted as a filename.
2401 .SM
2402 .B PATH
2403 is not used to search for the resultant filename.
2404 .TP
2405 .B BASH_XTRACEFD
2406 If set to an integer corresponding to a valid file descriptor,
2407 \fBbash\fP writes the trace output generated when
2408 .Q "set \-x"
2409 is enabled to that file descriptor,
2410 instead of the standard error.
2411 The file descriptor is closed when
2412 .SM
2413 .B BASH_XTRACEFD
2414 is unset or assigned a new value.
2415 Unsetting
2416 .SM
2417 .B BASH_XTRACEFD
2418 or assigning it the empty string causes the
2419 trace output to be sent to the standard error.
2420 Note that setting
2421 .SM
2422 .B BASH_XTRACEFD
2423 to 2 (the standard error file
2424 descriptor) and then unsetting it will result in the standard error
2425 being closed.
2426 .TP
2427 .B CDPATH
2428 The search path for the
2429 .B cd
2430 command.
2431 This is a colon-separated list of directories where the shell looks for
2432 directories specified as arguments to the
2433 .B cd
2434 command.
2435 A sample value is
2436 .Q .:\*~:/usr .
2437 .TP
2438 .B CHILD_MAX
2439 Set the number of exited child status values for the shell to remember.
2440 \fBBash\fP will not allow this value to be decreased below a
2441 .SM POSIX\c
2442 -mandated minimum,
2443 and there is a maximum value (currently 8192) that this may not exceed.
2444 The minimum value is system-dependent.
2445 .TP
2446 .B COLUMNS
2447 Used by the \fBselect\fP compound command to determine the terminal width
2448 when printing selection lists.
2449 Automatically set if the
2450 .B checkwinsize
2451 option is enabled or in an interactive shell upon receipt of a
2452 .SM
2453 .BR SIGWINCH .
2454 .TP
2455 .B COMPREPLY
2456 An array variable from which \fBbash\fP reads the possible completions
2457 generated by a shell function invoked by the programmable completion
2458 facility (see \fBProgrammable Completion\fP below).
2459 Each array element contains one possible completion.
2460 .TP
2461 .B EMACS
2462 If \fBbash\fP finds this variable in the environment when the shell starts
2463 with value
2464 .Q t ,
2465 it assumes that the shell is running in an Emacs shell buffer and disables
2466 line editing.
2467 .TP
2468 .B ENV
2469 Expanded and executed similarly to
2470 .SM
2471 .B BASH_ENV
2472 (see
2473 .SM
2474 .B INVOCATION
2475 above) when an interactive shell is invoked in posix mode.
2476 .TP
2477 .B EXECIGNORE
2478 A colon-separated list of shell patterns (see \fBPattern Matching\fP)
2479 defining the set of filenames to be ignored by command search using
2480 .SM
2481 .BR PATH .
2482 Files whose full pathnames match one of these patterns are not considered
2483 executable files for the purposes of completion and command execution
2484 via
2485 .SM
2486 .B PATH
2487 lookup.
2488 This does not affect the behavior of the \fB[\fP, \fBtest\fP, and \fB[[\fP
2489 commands.
2490 Full pathnames in the command hash table are not subject to
2491 .SM
2492 .BR EXECIGNORE .
2493 Use this variable to ignore shared library files that have the executable
2494 bit set, but are not executable files.
2495 The pattern matching honors the setting of the \fBextglob\fP shell
2496 option.
2497 .TP
2498 .B FCEDIT
2499 The default editor for the
2500 .B fc
2501 builtin command.
2502 .TP
2503 .B FIGNORE
2504 A colon-separated list of suffixes to ignore when performing
2505 filename completion (see
2506 .SM
2507 .B READLINE
2508 below).
2509 A filename whose suffix matches one of the entries in
2510 .SM
2511 .B FIGNORE
2512 is excluded from the list of matched filenames.
2513 A sample value is
2514 .Q .o:\*~
2515 (Quoting is needed when assigning a value to this variable,
2516 which contains tildes).
2517 .TP
2518 .B FUNCNEST
2519 If set to a numeric value greater than 0, defines a maximum function
2520 nesting level.
2521 Function invocations that exceed this nesting level
2522 cause the current command to abort.
2523 .TP
2524 .B GLOBIGNORE
2525 A colon-separated list of patterns defining the set of file names to
2526 be ignored by pathname expansion.
2527 If a file name matched by a pathname expansion pattern also matches one
2528 of the patterns in
2529 .SM
2530 .BR GLOBIGNORE ,
2531 it is removed from the list of matches.
2532 The pattern matching honors the setting of the \fBextglob\fP shell
2533 option.
2534 .TP
2535 .B GLOBSORT
2536 .PD
2537 Controls how the results of pathname expansion are sorted.
2538 The value of this variable specifies the sort criteria and sort order for
2539 the results of pathname expansion.
2540 If this variable is unset or set to the null string, pathname expansion
2541 uses the historical behavior of sorting by name,
2542 in ascending lexicographic order as determined by the
2543 .SM
2544 .B \%LC_COLLATE
2545 shell variable.
2546 .IP
2547 If set, a valid value begins with an optional \fI+\fP, which is ignored,
2548 or \fI\-\fP, which reverses the sort order from ascending to descending,
2549 followed by a sort specifier.
2550 The valid sort specifiers are
2551 .IR name ,
2552 .IR \%numeric ,
2553 .IR size ,
2554 .IR mtime ,
2555 .IR atime ,
2556 .IR ctime ,
2557 and
2558 .IR blocks ,
2559 which sort the files on name,
2560 names in numeric rather than lexicographic order,
2561 file size, modification time, access time,
2562 inode change time, and number of blocks, respectively.
2563 If any of the non-name keys compare as equal (e.g., if two files are
2564 the same size), sorting uses the name as a secondary sort key.
2565 .IP
2566 For example, a value of \fI\-mtime\fP sorts the results in descending
2567 order by modification time (newest first).
2568 .IP
2569 The \fInumeric\fP specifier treats names consisting solely of digits as
2570 numbers and sorts them using their numeric value
2571 (so
2572 .Q 2
2573 sorts before
2574 .Q 10 ,
2575 for example).
2576 When using \fInumeric\fP, names containing non-digits sort after all
2577 the all-digit names and are sorted by name using the traditional behavior.
2578 .IP
2579 A sort specifier of \fInosort\fP disables sorting completely;
2580 .B bash
2581 returns the results
2582 in the order they are read from the file system,
2583 ignoring any leading \fI\-\fP.
2584 .IP
2585 If the sort specifier is missing, it defaults to \fIname\fP,
2586 so a value of \fI+\fP is equivalent to the null string,
2587 and a value of \fI-\fP sorts by name in descending order.
2588 Any invalid value restores the historical sorting behavior.
2589 .PD 0
2590 .TP
2591 .B HISTCONTROL
2592 A colon-separated list of values controlling how commands are saved on
2593 the history list.
2594 If the list of values includes
2595 .IR ignorespace ,
2596 lines which begin with a
2597 .B space
2598 character are not saved in the history list.
2599 A value of
2600 .I ignoredups
2601 causes lines matching the previous history entry not to be saved.
2602 A value of
2603 .I ignoreboth
2604 is shorthand for \fIignorespace\fP and \fIignoredups\fP.
2605 A value of
2606 .I erasedups
2607 causes all previous lines matching the current line to be removed from
2608 the history list before that line is saved.
2609 Any value not in the above list is ignored.
2610 If
2611 .SM
2612 .B HISTCONTROL
2613 is unset, or does not include a valid value,
2614 \fBbash\fP saves all lines read by the shell parser on the history list,
2615 subject to the value of
2616 .SM
2617 .BR HISTIGNORE .
2618 If the first line of a multi-line compound command was saved,
2619 the second and subsequent lines are not tested,
2620 and are added to the history regardless of the value of
2621 .SM
2622 .BR HISTCONTROL .
2623 If the first line was not saved, the second and subsequent lines of
2624 the command are not saved either.
2625 .TP
2626 .B HISTFILE
2627 The name of the file in which command history is saved (see
2628 .SM
2629 .B HISTORY
2630 below).
2631 \fBBash\fP assigns a default value of
2632 .FN \*~/.bash_history .
2633 If
2634 .SM
2635 .B HISTFILE
2636 is unset or null,
2637 the shell does not save the command history when it exits.
2638 .TP
2639 .B HISTFILESIZE
2640 The maximum number of lines contained in the history file.
2641 When this variable is assigned a value, the history file is truncated,
2642 if necessary, to contain no more than
2643 the number of history entries
2644 that total no more than that number of lines
2645 by removing the oldest entries.
2646 If the history list contains multi-line entries,
2647 the history file may contain more lines than this maximum
2648 to avoid leaving partial history entries.
2649 The history file is also truncated to this size after
2650 writing it when a shell exits or by the
2651 .B \%history
2652 builtin.
2653 If the value is 0, the history file is truncated to zero size.
2654 Non-numeric values and numeric values less than zero inhibit truncation.
2655 The shell sets the default value to the value of
2656 .SM
2657 .B HISTSIZE
2658 after reading any startup files.
2659 .TP
2660 .B HISTIGNORE
2661 A colon-separated list of patterns used to decide which command lines
2662 should be saved on the history list.
2663 If a command line matches one of the patterns in the value of
2664 .SM
2665 .BR HISTIGNORE ,
2666 it is not saved on the history list.
2667 Each pattern is anchored at the
2668 beginning of the line and must match the complete line
2669 (\fBbash\fP does not implicitly append a
2670 .Q \fB*\fP ).
2671 Each pattern is tested against the line
2672 after the checks specified by
2673 .SM
2674 .B HISTCONTROL
2675 are applied.
2676 In addition to the normal shell pattern matching characters,
2677 .Q \fB&\fP
2678 matches the previous history line.
2679 A backslash escapes the
2680 .Q \fB&\fP ;
2681 the backslash is removed before attempting a match.
2682 If the first line of a multi-line compound command was saved,
2683 the second and subsequent lines are not tested,
2684 and are added to the history regardless of the value of
2685 .SM
2686 .BR HISTIGNORE .
2687 If the first line was not saved, the second and subsequent lines of
2688 the command are not saved either.
2689 The pattern matching honors the setting of the
2690 .B \%extglob
2691 shell option.
2692 .IP
2693 .SM
2694 .B HISTIGNORE
2695 subsumes some of the function of
2696 .SM
2697 .BR HISTCONTROL .
2698 A pattern of
2699 .Q &
2700 is identical to
2701 .Q \%ignoredups ,
2702 and a pattern of
2703 .Q "[ ]*"
2704 is identical to
2705 .Q \%ignorespace .
2706 Combining these two patterns, separating them with a colon,
2707 provides the functionality of
2708 .Q \%ignoreboth .
2709 .TP
2710 .B HISTSIZE
2711 The number of commands to remember in the command history (see
2712 .SM
2713 .B HISTORY
2714 below).
2715 If the value is 0, commands are not saved in the history list.
2716 Numeric values less than zero result in every command being saved
2717 on the history list (there is no limit).
2718 The shell sets the default value to 500 after reading any startup files.
2719 .TP
2720 .B HISTTIMEFORMAT
2721 If this variable is set and not null, its value is used as a format string
2722 for
2723 .IR strftime (3)
2724 to print the time stamp associated with each history
2725 entry displayed by the \fBhistory\fP builtin.
2726 If this variable is set, the shell writes time stamps to the history file so
2727 they may be preserved across shell sessions.
2728 This uses the history comment character to distinguish timestamps from
2729 other history lines.
2730 .TP
2731 .B HOME
2732 The home directory of the current user; the default argument for the
2733 \fBcd\fP builtin command.
2734 The value of this variable is also used when performing tilde expansion.
2735 .TP
2736 .B HOSTFILE
2737 Contains the name of a file in the same format as
2738 .FN /etc/hosts
2739 that should be read when the shell needs to complete a
2740 hostname.
2741 The list of possible hostname completions may be changed while the
2742 shell is running;
2743 the next time hostname completion is attempted after the
2744 value is changed,
2745 .B bash
2746 adds the contents of the new file to the existing list.
2747 If
2748 .SM
2749 .B HOSTFILE
2750 is set, but has no value, or does not name a readable file,
2751 \fBbash\fP attempts to read
2752 .FN /etc/hosts
2753 to obtain the list of possible hostname completions.
2754 When
2755 .SM
2756 .B HOSTFILE
2757 is unset, \fBbash\fP clears the hostname list.
2758 .TP
2759 .B IFS
2760 The
2761 .I Internal Field Separator
2762 that is used
2763 for word splitting after expansion and to
2764 split lines into words with the
2765 .B read
2766 builtin command.
2767 Word splitting is described below under
2768 .SM
2769 .BR EXPANSION .
2770 The default value is
2771 .Q <space><tab><newline> .
2772 .TP
2773 .B IGNOREEOF
2774 Controls the
2775 action of an interactive shell on receipt of an
2776 .SM
2777 .B EOF
2778 character as the sole input.
2779 If set, the value is the number of consecutive
2780 .SM
2781 .B EOF
2782 characters which must be
2783 typed as the first characters on an input line before
2784 .B bash
2785 exits.
2786 If the variable is set but does not have a numeric value,
2787 or the value is null,
2788 the default value is 10.
2789 If it is unset,
2790 .SM
2791 .B EOF
2792 signifies the end of input to the shell.
2793 .TP
2794 .B INPUTRC
2795 The filename for the
2796 .B readline
2797 startup file, overriding the default of
2798 .FN \*~/.inputrc
2799 (see
2800 .SM
2801 .B READLINE
2802 below).
2803 .TP
2804 .B INSIDE_EMACS
2805 If this variable appears in the environment when the shell starts,
2806 \fBbash\fP assumes that it is running inside an Emacs shell buffer
2807 and may disable line editing, depending on the value of
2808 .SM
2809 .BR TERM .
2810 .TP
2811 .B LANG
2812 Used to determine the locale category for any category not specifically
2813 selected with a variable starting with \fBLC_\fP.
2814 .TP
2815 .B LC_ALL
2816 This variable overrides the value of
2817 .SM
2818 .B LANG
2819 and any other
2820 \fBLC_\fP variable specifying a locale category.
2821 .TP
2822 .B LC_COLLATE
2823 This variable determines the collation order used when sorting the
2824 results of pathname expansion, and determines the behavior of range
2825 expressions, equivalence classes, and collating sequences within
2826 pathname expansion and pattern matching.
2827 .TP
2828 .B LC_CTYPE
2829 This variable determines the interpretation of characters and the
2830 behavior of character classes within pathname expansion and pattern
2831 matching.
2832 .TP
2833 .B LC_MESSAGES
2834 This variable determines the locale used to translate double-quoted
2835 strings preceded by a \fB$\fP.
2836 .TP
2837 .B LC_NUMERIC
2838 This variable determines the locale category used for number formatting.
2839 .TP
2840 .B LC_TIME
2841 This variable determines the locale category used for data and time
2842 formatting.
2843 .TP
2844 .B LINES
2845 Used by the \fBselect\fP compound command to determine the column length
2846 for printing selection lists.
2847 Automatically set if the
2848 .B checkwinsize
2849 option is enabled or in an interactive shell upon receipt of a
2850 .SM
2851 .BR SIGWINCH .
2852 .TP
2853 .B MAIL
2854 If the value is set to a file or directory name and the
2855 .SM
2856 .B MAILPATH
2857 variable is not set,
2858 .B bash
2859 informs the user of the arrival of mail in the specified file or
2860 Maildir-format directory.
2861 .TP
2862 .B MAILCHECK
2863 Specifies how
2864 often (in seconds)
2865 .B bash
2866 checks for mail.
2867 The default is 60 seconds.
2868 When it is time to check for mail,
2869 the shell does so before displaying the primary prompt.
2870 If this variable is unset, or set to a value that is not a number
2871 greater than or equal to zero, the shell disables mail checking.
2872 .TP
2873 .B MAILPATH
2874 A colon-separated list of filenames to be checked for mail.
2875 The message to be printed when mail arrives in a particular file
2876 may be specified by separating the filename from the message with a
2877 .Q ? .
2878 When used in the text of the message, \fB$_\fP expands to the name of
2879 the current mailfile.
2880 For example:
2881 .RS
2882 .PP
2883 .EX
2884 \fBMAILPATH\fP=\*'/var/mail/bfox?\*"You have mail\*":\*~/shell\-mail?\*"$_ has mail!\*"\*'
2885 .EE
2886 .PP
2887 .B Bash
2888 can be configured to supply
2889 a default value for this variable (there is no value by default),
2890 but the location of the user
2891 mail files that it uses is system dependent (e.g., /var/mail/\fB$USER\fP).
2892 .RE
2893 .TP
2894 .B OPTERR
2895 If set to the value 1,
2896 .B bash
2897 displays error messages generated by the
2898 .B getopts
2899 builtin command (see
2900 .SM
2901 .B "SHELL BUILTIN COMMANDS"
2902 below).
2903 .SM
2904 .B OPTERR
2905 is initialized to 1 each time the shell is invoked or a shell
2906 script is executed.
2907 .TP
2908 .B PATH
2909 The search path for commands.
2910 It is a colon-separated list of directories in which
2911 the shell looks for commands (see
2912 .SM
2913 .B "COMMAND EXECUTION"
2914 below).
2915 A zero-length (null) directory name in the value of
2916 .SM
2917 .B PATH
2918 indicates the current directory.
2919 A null directory name may appear as two adjacent colons, or as an initial
2920 or trailing colon.
2921 The default path is system-dependent,
2922 and is set by the administrator who installs
2923 .BR bash .
2924 A common value is
2925 .RS
2926 .RS 5n
2927 .EX
2928 /usr/local/bin:/usr/local/sbin:\c
2929 .if \n(LL<78n .br
2930 /usr/bin:/usr/sbin:/bin:/sbin
2931 .EE
2932 .RE
2933 .RE
2934 .TP
2935 .B POSIXLY_CORRECT
2936 If this variable is in the environment when \fBbash\fP starts, the shell
2937 enters posix mode before reading the startup files, as if the
2938 .B \-\-posix
2939 invocation option had been supplied.
2940 If it is set while the shell is
2941 running, \fBbash\fP enables posix mode, as if the command
2942 .Q "set \-o posix"
2943 had been executed.
2944 When the shell enters posix mode, it sets this variable if it was
2945 not already set.
2946 .TP
2947 .B PROMPT_COMMAND
2948 If this variable is set, and is an array,
2949 the value of each set element is executed as a command
2950 prior to issuing each primary prompt.
2951 If this is set but not an array variable,
2952 its value is used as a command to execute instead.
2953 .TP
2954 .B PROMPT_DIRTRIM
2955 If set to a number greater than zero, the value is used as the number of
2956 trailing directory components to retain when expanding the \fB\ew\fP and
2957 \fB\eW\fP prompt string escapes (see
2958 .SM
2959 .B PROMPTING
2960 below).
2961 Characters removed are replaced with an ellipsis.
2962 .TP
2963 .B PS0
2964 The value of this parameter is expanded (see
2965 .SM
2966 .B PROMPTING
2967 below) and displayed by interactive shells after reading a command
2968 and before the command is executed.
2969 .TP
2970 .B PS1
2971 The value of this parameter is expanded (see
2972 .SM
2973 .B PROMPTING
2974 below) and used as the primary prompt string.
2975 The default value is
2976 .Q \es\-\ev\e$\ .
2977 .TP
2978 .B PS2
2979 The value of this parameter is expanded as with
2980 .SM
2981 .B PS1
2982 and used as the secondary prompt string.
2983 The default is
2984 .Q >\ .
2985 .TP
2986 .B PS3
2987 The value of this parameter is used as the prompt for the
2988 .B select
2989 command (see
2990 .SM
2991 .B "SHELL GRAMMAR"
2992 above).
2993 .TP
2994 .B PS4
2995 The value of this parameter is expanded as with
2996 .SM
2997 .B PS1
2998 and the value is printed before each command
2999 .B bash
3000 displays during an execution trace.
3001 The first character of the expanded value of
3002 .SM
3003 .B PS4
3004 is replicated multiple times, as necessary, to indicate multiple
3005 levels of indirection.
3006 The default is
3007 .Q +\ .
3008 .TP
3009 .B SHELL
3010 This variable expands to the full pathname to the shell.
3011 If it is not set when the shell starts,
3012 .B bash
3013 assigns to it the full pathname of the current user's login shell.
3014 .TP
3015 .B TIMEFORMAT
3016 The value of this parameter is used as a format string specifying
3017 how the timing information for pipelines prefixed with the
3018 .B time
3019 reserved word should be displayed.
3020 The \fB%\fP character introduces an escape sequence that is
3021 expanded to a time value or other information.
3022 The escape sequences and their meanings are as follows; the
3023 brackets denote optional portions.
3024 .PP
3025 .RS
3026 .PD 0
3027 .TP 10
3028 .B %%
3029 A literal \fB%\fP.
3030 .TP
3031 .B %[\fIp\fP][l]R
3032 The elapsed time in seconds.
3033 .TP
3034 .B %[\fIp\fP][l]U
3035 The number of CPU seconds spent in user mode.
3036 .TP
3037 .B %[\fIp\fP][l]S
3038 The number of CPU seconds spent in system mode.
3039 .TP
3040 .B %P
3041 The CPU percentage, computed as (%U + %S) / %R.
3042 .PD
3043 .RE
3044 .IP
3045 The optional \fIp\fP is a digit specifying the \fIprecision\fP,
3046 the number of fractional digits after a decimal point.
3047 A value of 0 causes no decimal point or fraction to be output.
3048 \fBtime\fP prints at most six digits after the decimal point;
3049 values of \fIp\fP greater than 6 are changed to 6.
3050 If \fIp\fP is not specified,
3051 \fBtime\fP prints three digits after the decimal point.
3052 .IP
3053 The optional \fBl\fP specifies a longer format, including
3054 minutes, of the form \fIMM\fPm\fISS\fP.\fIFF\fPs.
3055 The value of \fIp\fP determines whether or not the fraction is
3056 included.
3057 .IP
3058 If this variable is not set, \fBbash\fP acts as if it had the
3059 value \fB$\*'\enreal\et%3lR\enuser\et%3lU\ensys\et%3lS\*'\fP.
3060 If the value is null, \fBbash\fP does not display any timing information.
3061 A trailing newline is added when the format string is displayed.
3062 .PD 0
3063 .TP
3064 .B TMOUT
3065 If set to a value greater than zero,
3066 the \fBread\fP builtin uses the value as its
3067 default timeout.
3068 The \fBselect\fP command terminates if input does not arrive
3069 after
3070 .SM
3071 .B TMOUT
3072 seconds when input is coming from a terminal.
3073 In an interactive shell, the value is interpreted as the
3074 number of seconds to wait for a line of input after issuing the
3075 primary prompt.
3076 .B Bash
3077 terminates after waiting for that number of seconds if a
3078 complete line of input does not arrive.
3079 .TP
3080 .B TMPDIR
3081 If set, \fBbash\fP uses its value as the name of a directory in which
3082 \fBbash\fP creates temporary files for the shell's use.
3083 .TP
3084 .B auto_resume
3085 This variable controls how the shell interacts with the user and
3086 job control.
3087 If this variable is set, simple commands
3088 consisting of only a single word,
3089 without redirections, are treated as candidates for resumption
3090 of an existing stopped job.
3091 There is no ambiguity allowed; if there is more than one job
3092 beginning with or containing
3093 the word, this selects the most recently accessed job.
3094 The
3095 .I name
3096 of a stopped job, in this context, is the command line used to
3097 start it, as displayed by \fBjobs\fP.
3098 If set to the value
3099 .IR exact ,
3100 the word must match the name of a stopped job exactly;
3101 if set to
3102 .IR substring ,
3103 the word needs to match a substring of the name of a stopped job.
3104 The
3105 .I substring
3106 value provides functionality analogous to the
3107 .B %?
3108 job identifier (see
3109 .SM
3110 .B "JOB CONTROL"
3111 below).
3112 If set to any other value (e.g.,
3113 .IR prefix ),
3114 the word must be a prefix of a stopped job's name;
3115 this provides functionality analogous to the \fB%\fP\fIstring\fP job identifier.
3116 .TP
3117 .B histchars
3118 The two or three characters which control history expansion,
3119 quick substitution, and tokenization
3120 (see
3121 .SM
3122 .B "HISTORY EXPANSION"
3123 below).
3124 The first character is the \fIhistory expansion\fP character,
3125 the character which begins a history expansion, normally
3126 .Q \fB!\fP .
3127 The second character is the \fIquick substitution\fP character, normally
3128 .Q \fB\*^\fP .
3129 When it appears as the first character on the line,
3130 history substitution repeats the previous command,
3131 replacing one string with another.
3132 The optional third character is the
3133 \fIhistory comment\fP
3134 character, normally
3135 .Q \fB#\fP ,
3136 which indicates
3137 that the remainder of the line is a comment
3138 when it appears as the first character of a word.
3139 The history comment character disables history substitution
3140 for the remaining words on the line.
3141 It does not necessarily cause the shell parser to treat the rest of the
3142 line as a comment.
3143 .PD
3144 .SS Arrays
3145 .B Bash
3146 provides one-dimensional indexed and associative array variables.
3147 Any variable may be used as an indexed array; the
3148 .B declare
3149 builtin explicitly declares an array.
3150 There is no maximum
3151 limit on the size of an array, nor any requirement that members
3152 be indexed or assigned contiguously.
3153 Indexed arrays are referenced using arithmetic expressions
3154 that must expand to an integer
3155 (see
3156 .SM
3157 .B
3158 ARITHMETIC EVALUATION
3159 below)
3160 and are zero-based;
3161 associative arrays are referenced using arbitrary strings.
3162 Unless otherwise noted, indexed array indices must be non-negative integers.
3163 .PP
3164 The shell performs
3165 parameter and variable expansion, arithmetic expansion,
3166 command substitution, and quote removal
3167 on indexed array subscripts.
3168 Since this
3169 can potentially result in empty strings,
3170 subscript indexing treats
3171 those as expressions that evaluate to 0.
3172 .PP
3173 The shell performs
3174 tilde expansion,
3175 parameter and variable expansion, arithmetic expansion,
3176 command substitution, and quote removal
3177 on associative array subscripts.
3178 Empty strings cannot be used as associative array keys.
3179 .PP
3180 \fBBash\fP automatically creates an indexed array
3181 if any variable is assigned to using the syntax
3182 .RS
3183 \fIname\fP[\fIsubscript\fP]=\fIvalue\fP
3184 \&.
3185 .RE
3186 The
3187 .I subscript
3188 is treated as an arithmetic expression that must evaluate to a number
3189 greater than or equal to zero.
3190 To explicitly declare an indexed array, use
3191 .RS
3192 .BI "declare \-a\ " name
3193 .RE
3194 (see
3195 .SM
3196 .B "SHELL BUILTIN COMMANDS"
3197 below).
3198 .RS
3199 \fBdeclare \-a\fP \fIname\fP[\fIsubscript\fP]
3200 .RE
3201 is also accepted; the \fIsubscript\fP is ignored.
3202 .PP
3203 Associative arrays are created using
3204 .RS
3205 .BI "declare \-A\ " name
3206 .RE
3207 \&.
3208 .PP
3209 Attributes may be specified for an array variable using the
3210 .B \%declare
3211 and
3212 .B \%readonly
3213 builtins.
3214 Each attribute applies to all members of an array.
3215 .PP
3216 Arrays are assigned using compound assignments of the form
3217 \fIname\fP=\fB(\fPvalue\fI1\fP .\|.\|.\& value\fIn\fP\fB)\fP, where each
3218 \fIvalue\fP may be of the form [\fIsubscript\fP]=\fIstring\fP.
3219 Indexed array assignments do not require anything but \fIstring\fP.
3220 Each \fIvalue\fP in the list is expanded using the shell expansions
3221 described below under
3222 .SM
3223 .BR EXPANSION ,
3224 but \fIvalue\fPs that are valid variable assignments
3225 including the brackets and subscript do not undergo
3226 brace expansion and word splitting, as with individual
3227 variable assignments.
3228 .PP
3229 When assigning to indexed arrays, if the optional brackets and subscript
3230 are supplied, that index is assigned to;
3231 otherwise the index of the element assigned is the last index assigned
3232 to by the statement plus one.
3233 Indexing starts at zero.
3234 .PP
3235 When assigning to an associative array, the words in a compound assignment
3236 may be either assignment statements, for which the subscript is required,
3237 or a list of words that is interpreted as a sequence of alternating keys
3238 and values:
3239 \fIname\fP=\fB( \fP\fIkey1 value1 key2 value2\fP .\|.\|.\&\fB)\fP.
3240 These are treated identically to
3241 \fIname\fP=\fB(\fP [\fIkey1\fP]=\fIvalue1\fP [\fIkey2\fP]=\fIvalue2\fP
3242 \&.\|.\|.\&\fB)\fP.
3243 The first word in the list determines how the remaining words
3244 are interpreted; all assignments in a list must be of the same type.
3245 When using key/value pairs, the keys may not be missing or empty;
3246 a final missing value is treated like the empty string.
3247 .PP
3248 This syntax is also accepted by the
3249 .B declare
3250 builtin.
3251 Individual array elements may be assigned to using the
3252 \fIname\fP[\fIsubscript\fP]=\fIvalue\fP syntax introduced above.
3253 .PP
3254 When assigning to an indexed array, if
3255 .I name
3256 is subscripted by a negative number, that number is
3257 interpreted as relative to one greater than the maximum index of
3258 \fIname\fP, so negative indices count back from the end of the
3259 array, and an index of \-1 references the last element.
3260 .PP
3261 The
3262 .Q +=
3263 operator appends to an array variable when assigning
3264 using the compound assignment syntax; see
3265 .SM
3266 .B PARAMETERS
3267 above.
3268 .PP
3269 An array element is referenced using
3270 ${\fIname\fP[\fIsubscript\fP]}.
3271 The braces are required to avoid conflicts with pathname expansion.
3272 If \fIsubscript\fP is \fB@\fP or \fB*\fP, the word expands to
3273 all members of \fIname\fP,
3274 unless noted in the description of a builtin or word expansion.
3275 These subscripts differ only when the
3276 word appears within double quotes.
3277 If the word is double-quoted, ${\fIname\fP[*]} expands to a single
3278 word with the value of each array member separated by the first
3279 character of the
3280 .SM
3281 .B IFS
3282 special variable, and ${\fIname\fP[@]} expands each element of
3283 \fIname\fP to a separate word.
3284 When there are no array members, ${\fIname\fP[@]} expands to nothing.
3285 If the double-quoted expansion occurs within a word, the expansion of
3286 the first parameter is joined with the beginning part of the
3287 expansion of the original word,
3288 and the expansion of the last parameter is joined with the last
3289 part of the
3290 expansion of the original word.
3291 This is analogous to the expansion
3292 of the special parameters \fB*\fP and \fB@\fP (see
3293 .B "Special Parameters"
3294 above).
3295 .PP
3296 ${#\fIname\fP[\fIsubscript\fP]} expands to the length of
3297 ${\fIname\fP[\fIsubscript\fP]}.
3298 If \fIsubscript\fP is \fB*\fP or \fB@\fP,
3299 the expansion is the number of elements in the array.
3300 .PP
3301 If the
3302 .I subscript
3303 used to reference an element of an indexed array
3304 evaluates to a number less than zero, it is
3305 interpreted as relative to one greater than the maximum index of the array,
3306 so negative indices count back from the end of the
3307 array, and an index of \-1 references the last element.
3308 .PP
3309 Referencing an array variable without a subscript is equivalent to
3310 referencing the array with a subscript of 0.
3311 Any reference to a variable using a valid subscript is valid;
3312 .B bash
3313 creates an array if necessary.
3314 .PP
3315 An array variable is considered set if a subscript has been assigned a
3316 value.
3317 The null string is a valid value.
3318 .PP
3319 It is possible to obtain the keys (indices) of an array as well as the values.
3320 ${\fB!\fP\fIname\fP[\fI@\fP]} and ${\fB!\fP\fIname\fP[\fI*\fP]}
3321 expand to the indices assigned in array variable \fIname\fP.
3322 The treatment when in double quotes is similar to the expansion of the
3323 special parameters \fI@\fP and \fI*\fP within double quotes.
3324 .PP
3325 The
3326 .B unset
3327 builtin is used to destroy arrays.
3328 \fBunset\fP \fIname\fP[\fIsubscript\fP]
3329 unsets the array element at index \fIsubscript\fP,
3330 for both indexed and associative arrays.
3331 Negative subscripts to indexed arrays are interpreted as described above.
3332 Unsetting the last element of an array variable does not unset the variable.
3333 \fBunset\fP \fIname\fP, where \fIname\fP is an array,
3334 removes the entire array.
3335 \fBunset\fP \fIname\fP[\fIsubscript\fP]
3336 behaves differently depending on
3337 whether \fIname\fP is an indexed or associative array
3338 when \fIsubscript\fP is \fB*\fP or \fB@\fP.
3339 If \fIname\fP is an associative array, this unsets the element with
3340 subscript \fB*\fP or \fB@\fP.
3341 If \fIname\fP is an indexed array, unset removes all of the elements but
3342 does not remove the array itself.
3343 .PP
3344 When using a variable name with a subscript as an argument to a command,
3345 such as with \fBunset\fP, without using the word expansion syntax
3346 described above,
3347 (e.g., unset a[4]),
3348 the argument is subject to pathname expansion.
3349 Quote the argument if pathname expansion is not desired
3350 (e.g., unset \*'a[4]\*').
3351 .PP
3352 The
3353 .BR declare ,
3354 .BR local ,
3355 and
3356 .B readonly
3357 builtins each accept a
3358 .B \-a
3359 option to specify an indexed array and a
3360 .B \-A
3361 option to specify an associative array.
3362 If both options are supplied,
3363 .B \-A
3364 takes precedence.
3365 The
3366 .B read
3367 builtin accepts a
3368 .B \-a
3369 option to assign a list of words read from the standard input
3370 to an array.
3371 The
3372 .B set
3373 and
3374 .B declare
3375 builtins display array values in a way that allows them to be
3376 reused as assignments.
3377 Other builtins accept array name arguments as well
3378 (e.g., \fBmapfile\fP); see the descriptions
3379 of individual builtins below for details.
3380 The shell provides a number of builtin array variables.
3381 .SH EXPANSION
3382 Expansion is performed on the command line after it has been split into
3383 words. The shell performs these expansions:
3384 .IR "brace expansion" ,
3385 .IR "tilde expansion" ,
3386 .IR "parameter and variable expansion" ,
3387 .IR "command substitution" ,
3388 .IR "arithmetic expansion" ,
3389 .IR "word splitting" ,
3390 .IR "pathname expansion" ,
3391 and
3392 .IR "quote removal" .
3393 .PP
3394 The order of expansions is:
3395 brace expansion;
3396 tilde expansion, parameter and variable expansion, arithmetic expansion,
3397 and command substitution (done in a left-to-right fashion);
3398 word splitting;
3399 pathname expansion;
3400 and quote removal.
3401 .PP
3402 On systems that can support it, there is an additional expansion
3403 available: \fIprocess substitution\fP.
3404 This is performed at the
3405 same time as tilde, parameter, variable, and arithmetic expansion and
3406 command substitution.
3407 .PP
3408 \fIQuote removal\fP is always performed last.
3409 It removes quote characters present in the original word,
3410 not ones resulting from one of the other expansions,
3411 unless they have been quoted themselves.
3412 .PP
3413 Only brace expansion, word splitting, and pathname expansion
3414 can increase the number of words of the expansion; other expansions
3415 expand a single word to a single word.
3416 The only exceptions to this are the expansions of
3417 .B \&\*"$@\*"
3418 and
3419 .B \&\*"${\fIname\fP[@]}\*"\c \" keep leading \& for AT&T troff
3420 .BR \& , \" .BR + \& + \*" doesn't work with AT&T troff
3421 and, in most cases, \fB$*\fP and \fB${\fP\fIname\fP\fB[*]}\fP
3422 as explained above (see
3423 .SM
3424 .BR PARAMETERS ).
3425 .SS Brace Expansion
3426 .I "Brace expansion"
3427 is a mechanism to generate arbitrary strings
3428 sharing a common prefix and suffix, either of which can be empty.
3429 This mechanism is similar to
3430 \fIpathname expansion\fP, but the filenames generated
3431 need not exist.
3432 Patterns to be brace expanded are formed from an optional
3433 .IR preamble ,
3434 followed by either a series of comma-separated strings or
3435 a sequence expression between a pair of braces,
3436 followed by an optional
3437 .IR postscript .
3438 The preamble is prefixed to each string contained within the braces,
3439 and the postscript is then appended to each resulting string,
3440 expanding left to right.
3441 .PP
3442 Brace expansions may be nested.
3443 The results of each expanded string are not sorted;
3444 brace expansion preserves left to right order.
3445 For example, a\fB{\fPd,c,b\fB}\fPe expands into
3446 .Q "ade ace abe" .
3447 .PP
3448 A sequence expression takes the form
3449 \fIx\fP\fB..\fP\fIy\fP\fB[..\fP\fIincr\fP\fB]\fP,
3450 where \fIx\fP and \fIy\fP are either integers or single letters,
3451 and \fIincr\fP, an optional increment, is an integer.
3452 When integers are supplied, the expression expands to each number between
3453 \fIx\fP and \fIy\fP, inclusive.
3454 If either \fIx\fP or \fIy\fP begins with a zero,
3455 each generated term will contain the same number of digits,
3456 zero-padding where necessary.
3457 When letters are supplied, the expression expands to each character
3458 lexicographically between \fIx\fP and \fIy\fP, inclusive,
3459 using the C locale.
3460 Note that both \fIx\fP and \fIy\fP must be of the same type
3461 (integer or letter).
3462 When the increment is supplied, it is used as the difference between
3463 each term.
3464 The default increment is 1 or \-1 as appropriate.
3465 .PP
3466 Brace expansion is performed before any other expansions,
3467 and any characters special to other expansions are preserved
3468 in the result.
3469 It is strictly textual.
3470 .B Bash
3471 does not apply any syntactic interpretation to the context of the
3472 expansion or the text between the braces.
3473 .PP
3474 A correctly-formed brace expansion must contain unquoted opening
3475 and closing braces, and at least one unquoted comma or a valid
3476 sequence expression.
3477 Any incorrectly formed brace expansion is left unchanged.
3478 .PP
3479 A
3480 .Q {
3481 or
3482 Q ,
3483 may be quoted with a backslash to prevent its
3484 being considered part of a brace expression.
3485 To avoid conflicts with parameter expansion, the string
3486 .Q ${
3487 is not considered eligible for brace expansion,
3488 and inhibits brace expansion until the closing
3489 .Q } .
3490 .PP
3491 This construct is typically used as shorthand when the common
3492 prefix of the strings to be generated is longer than in the
3493 above example:
3494 .PP
3495 .RS
3496 .EX
3497 mkdir /usr/local/src/bash/{old,new,dist,bugs}
3498 .EE
3499 .RE
3500 or
3501 .RS
3502 .EX
3503 chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
3504 .EE
3505 .RE
3506 .PP
3507 Brace expansion introduces a slight incompatibility with
3508 historical versions of
3509 .BR sh .
3510 .B sh
3511 does not treat opening or closing braces specially when they
3512 appear as part of a word, and preserves them in the output.
3513 .B Bash
3514 removes braces from words as a consequence of brace expansion.
3515 For example, a word entered to
3516 .B sh
3517 as
3518 .Q file{1,2}
3519 appears identically in the output.
3520 .B Bash
3521 outputs that word as
3522 .Q "file1 file2"
3523 after brace expansion.
3524 Start
3525 .B bash
3526 with the
3527 .B +B
3528 option or disable brace expansion with the
3529 .B +B
3530 option to the
3531 .B set
3532 command (see
3533 .SM
3534 .B "SHELL BUILTIN COMMANDS"
3535 below) for strict \fBsh\fP compatibility.
3536 .SS Tilde Expansion
3537 If a word begins with an unquoted tilde character (\c
3538 .Q \fB\*~\fP ),
3539 all of
3540 the characters preceding the first unquoted slash (or all characters,
3541 if there is no unquoted slash) are considered a \fItilde-prefix\fP.
3542 If none of the characters in the tilde-prefix are quoted, the
3543 characters in the tilde-prefix following the tilde are treated as a
3544 possible \fIlogin name\fP.
3545 If this login name is the null string, the tilde is replaced with the
3546 value of the shell parameter
3547 .SM
3548 .BR HOME .
3549 If
3550 .SM
3551 .B HOME
3552 is unset, the tilde expands to
3553 the home directory of the user executing the shell instead.
3554 Otherwise, the tilde-prefix is replaced with the home directory
3555 associated with the specified login name.
3556 .PP
3557 If the tilde-prefix is a
3558 .Q \*~+ ,
3559 the value of the shell variable
3560 .SM
3561 .B PWD
3562 replaces the tilde-prefix.
3563 If the tilde-prefix is a
3564 .Q \*~\- ,
3565 the shell substitutes the value of the shell variable
3566 .SM
3567 .BR OLDPWD ,
3568 if it is set.
3569 If the characters following the tilde in the tilde-prefix consist
3570 of a number \fIN\fP, optionally prefixed
3571 by a
3572 .Q +
3573 or a
3574 .Q \- ,
3575 the tilde-prefix is replaced with the corresponding
3576 element from the directory stack, as it would be displayed by the
3577 .B dirs
3578 builtin invoked with the characters following the tilde in the
3579 tilde-prefix as an argument.
3580 If the characters following the tilde in the tilde-prefix consist of a
3581 number without a leading
3582 .Q +
3583 or
3584 .Q \- ,
3585 tilde expansion assumes
3586 .Q + .
3587 .PP
3588 The results of tilde expansion are treated as if they were quoted, so
3589 the replacement is not subject to word splitting and pathname expansion.
3590 .PP
3591 If the login name is invalid, or the tilde expansion fails, the
3592 tilde-prefix is unchanged.
3593 .PP
3594 \fBBash\fP checks each variable assignment
3595 for unquoted tilde-prefixes immediately
3596 following a
3597 .B :
3598 or the first
3599 .BR = ,
3600 and performs tilde expansion in these cases.
3601 Consequently, one may use filenames with tildes in assignments to
3602 .SM
3603 .BR PATH ,
3604 .SM
3605 .BR MAILPATH ,
3606 and
3607 .SM
3608 .BR CDPATH ,
3609 and the shell assigns the expanded value.
3610 .PP
3611 \fBBash\fP also performs tilde expansion on words satisfying the conditions
3612 of variable assignments (as described above under
3613 .SM
3614 .BR PARAMETERS )
3615 when they appear as arguments to simple commands.
3616 \fBBash\fP does not do this,
3617 except for the \fIdeclaration\fP commands listed above,
3618 when in posix mode.
3619 .SS Parameter Expansion
3620 The
3621 .Q \fB$\fP
3622 character introduces parameter expansion,
3623 command substitution, or arithmetic expansion.
3624 The parameter name
3625 or symbol to be expanded may be enclosed in braces, which
3626 are optional but serve to protect the variable to be expanded from
3627 characters immediately following it which could be
3628 interpreted as part of the name.
3629 .PP
3630 When braces are used, the matching ending brace is the first
3631 .Q \fB}\fP
3632 not escaped by a backslash or within a quoted string, and not within an
3633 embedded arithmetic expansion, command substitution, or parameter
3634 expansion.
3635 .PP
3636 The basic form of parameter expansion is
3637 .PP
3638 ${\fIparameter\fP}
3639 .LP
3640 which substitutes the value of \fIparameter\fP.
3641 The braces are required
3642 when
3643 .I parameter
3644 is a positional parameter with more than one digit,
3645 or when
3646 .I parameter
3647 is followed by a character which is not to be
3648 interpreted as part of its name.
3649 The \fIparameter\fP is a shell parameter as described above
3650 \fBPARAMETERS\fP) or an array reference (\fBArrays\fP).
3651 .PD
3652 .PP
3653 If the first character of \fIparameter\fP is an exclamation point (\fB!\fP),
3654 and \fIparameter\fP is not a \fInameref\fP,
3655 it introduces a level of indirection.
3656 \fBBash\fP uses the value formed by expanding the rest of
3657 \fIparameter\fP as the new \fIparameter\fP;
3658 this new parameter is then expanded and that value is used
3659 in the rest of the expansion, rather
3660 than the expansion of the original \fIparameter\fP.
3661 This is known as \fIindirect expansion\fP.
3662 The value is subject to tilde expansion,
3663 parameter expansion, command substitution, and arithmetic expansion.
3664 If \fIparameter\fP is a nameref, this expands to the name of the
3665 parameter referenced by \fIparameter\fP instead of performing the
3666 complete indirect expansion, for compatibility.
3667 The exceptions to this are the expansions of ${\fB!\fP\fIprefix\fP\fB*\fP} and
3668 ${\fB!\fP\fIname\fP[\fI@\fP]} described below.
3669 The exclamation point must immediately follow the left brace in order to
3670 introduce indirection.
3671 .PP
3672 In each of the cases below, \fIword\fP is subject to tilde expansion,
3673 parameter expansion, command substitution, and arithmetic expansion.
3674 .PP
3675 When not performing substring expansion, using the forms documented below
3676 (e.g., \fB:-\fP),
3677 \fBbash\fP tests for a parameter that is unset or null.
3678 Omitting the colon tests only for a parameter that is unset.
3679 .PP
3680 .TP
3681 ${\fIparameter\fP\fB:\-\fP\fIword\fP}
3682 \fBUse Default Values\fP. If
3683 .I parameter
3684 is unset or null, the expansion of
3685 .I word
3686 is substituted.
3687 Otherwise, the value of
3688 .I parameter
3689 is substituted.
3690 .TP
3691 ${\fIparameter\fP\fB:=\fP\fIword\fP}
3692 \fBAssign Default Values\fP.
3693 If
3694 .I parameter
3695 is unset or null, the expansion of
3696 .I word
3697 is assigned to
3698 .IR parameter ,
3699 and the expansion is the final value of
3700 .IR parameter .
3701 Positional parameters and special parameters may
3702 not be assigned in this way.
3703 .TP
3704 ${\fIparameter\fP\fB:?\fP\fIword\fP}
3705 \fBDisplay Error if Null or Unset\fP.
3706 If
3707 .I parameter
3708 is null or unset, the shell writes
3709 the expansion of \fIword\fP (or a message to that effect
3710 if
3711 .I word
3712 is not present) to the standard error and, if it
3713 is not interactive, exits with a non-zero status.
3714 An interactive shell does not exit, but does not execute the command
3715 associated with the expansion.
3716 Otherwise, the value of \fIparameter\fP is substituted.
3717 .TP
3718 ${\fIparameter\fP\fB:+\fP\fIword\fP}
3719 \fBUse Alternate Value\fP.
3720 If
3721 .I parameter
3722 is null or unset, nothing is substituted, otherwise the expansion of
3723 .I word
3724 is substituted.
3725 The value of \fIparameter\fP is not used.
3726 .TP
3727 .PD 0
3728 ${\fIparameter\fP\fB:\fP\fIoffset\fP}
3729 .TP
3730 .PD
3731 ${\fIparameter\fP\fB:\fP\fIoffset\fP\fB:\fP\fIlength\fP}
3732 \fBSubstring Expansion\fP.
3733 Expands to up to \fIlength\fP characters of the value of \fIparameter\fP
3734 starting at the character specified by \fIoffset\fP.
3735 If \fIparameter\fP is \fB@\fP or \fB*\fP, an indexed array subscripted by
3736 \fB@\fP or \fB*\fP, or an associative array name, the results differ as
3737 described below.
3738 If \fB:\fP\fIlength\fP is omitted (the first form above), this
3739 expands to the substring of the value of
3740 \fIparameter\fP starting at the character specified by \fIoffset\fP
3741 and extending to the end of the value.
3742 If \fIoffset\fP is omitted,
3743 it is treated as 0.
3744 If \fIlength\fP is omitted,
3745 but the colon after \fIoffset\fP is present,
3746 it is treated as 0.
3747 \fIlength\fP and \fIoffset\fP are arithmetic expressions (see
3748 .SM
3749 .B
3750 ARITHMETIC EVALUATION
3751 below).
3752 .IP
3753 If \fIoffset\fP evaluates to a number less than zero, the value
3754 is used as an offset in characters
3755 from the end of the value of \fIparameter\fP.
3756 If \fIlength\fP evaluates to a number less than zero,
3757 it is interpreted as an offset in characters
3758 from the end of the value of \fIparameter\fP rather than
3759 a number of characters, and the expansion is the characters between
3760 \fIoffset\fP and that result.
3761 Note that a negative offset must be separated from the colon by at least
3762 one space to avoid being confused with the \fB:-\fP expansion.
3763 .IP
3764 If \fIparameter\fP is \fB@\fP or \fB*\fP, the result is \fIlength\fP
3765 positional parameters beginning at \fIoffset\fP.
3766 A negative \fIoffset\fP is taken relative to one greater than the greatest
3767 positional parameter, so an offset of \-1 evaluates to the last positional
3768 parameter (or 0 if there are no positional parameters).
3769 It is an expansion error if \fIlength\fP evaluates to a number less than
3770 zero.
3771 .IP
3772 If \fIparameter\fP is an indexed array name subscripted by @ or *,
3773 the result is the \fIlength\fP
3774 members of the array beginning with ${\fIparameter\fP[\fIoffset\fP]}.
3775 A negative \fIoffset\fP is taken relative to one greater than the maximum
3776 index of the specified array.
3777 It is an expansion error if \fIlength\fP evaluates to a number less than
3778 zero.
3779 .IP
3780 Substring expansion applied to an associative array produces undefined
3781 results.
3782 .IP
3783 Substring indexing is zero-based unless the positional parameters
3784 are used, in which case the indexing starts at 1 by default.
3785 If \fIoffset\fP is 0, and the positional parameters are used, \fB$0\fP is
3786 prefixed to the list.
3787 .TP
3788 .PD 0
3789 ${\fB!\fP\fIprefix\fP\fB*\fP}
3790 .TP
3791 ${\fB!\fP\fIprefix\fP\fB@\fP}
3792 .PD
3793 \fBNames matching prefix\fP.
3794 Expands to the names of variables whose names begin with \fIprefix\fP,
3795 separated by the first character of the
3796 .SM
3797 .B IFS
3798 special variable.
3799 When \fI@\fP is used and the expansion appears within double quotes, each
3800 variable name expands to a separate word.
3801 .TP
3802 .PD 0
3803 ${\fB!\fP\fIname\fP[\fI@\fP]}
3804 .TP
3805 ${\fB!\fP\fIname\fP[\fI*\fP]}
3806 .PD
3807 \fBList of array keys\fP.
3808 If \fIname\fP is an array variable, expands to the list of array indices
3809 (keys) assigned in \fIname\fP.
3810 If \fIname\fP is not an array, expands to 0 if \fIname\fP is set and null
3811 otherwise.
3812 When \fI@\fP is used and the expansion appears within double quotes, each
3813 key expands to a separate word.
3814 .TP
3815 ${\fB#\fP\fIparameter\fP}
3816 \fBParameter length\fP.
3817 Substitutes the length in characters of the expanded value of \fIparameter\fP.
3818 If
3819 .I parameter
3820 is
3821 .B *
3822 or
3823 .BR @ ,
3824 the value substituted is the number of positional parameters.
3825 If
3826 .I parameter
3827 is an array name subscripted by
3828 .B *
3829 or
3830 .BR @ ,
3831 the value substituted is the number of elements in the array.
3832 If
3833 .I parameter
3834 is an indexed array name subscripted by a negative number, that number is
3835 interpreted as relative to one greater than the maximum index of
3836 \fIparameter\fP, so negative indices count back from the end of the
3837 array, and an index of \-1 references the last element.
3838 .TP
3839 .PD 0
3840 ${\fIparameter\fP\fB#\fP\fIword\fP}
3841 .TP
3842 ${\fIparameter\fP\fB##\fP\fIword\fP}
3843 .PD
3844 \fBRemove matching prefix pattern\fP.
3845 The
3846 .I word
3847 is expanded to produce a pattern just as in pathname
3848 expansion, and matched against the expanded value of
3849 .I parameter
3850 using the rules described under
3851 .B "Pattern Matching"
3852 below.
3853 If the pattern matches the beginning of
3854 the value of
3855 .IR parameter ,
3856 then the result of the expansion is the expanded value of
3857 .I parameter
3858 with the shortest matching pattern (the
3859 .Q #
3860 case) or the longest matching pattern (the
3861 .Q ##
3862 case) deleted.
3863 If
3864 .I parameter
3865 is
3866 .B @
3867 or
3868 .BR * ,
3869 the pattern removal operation is applied to each positional
3870 parameter in turn, and the expansion is the resultant list.
3871 If
3872 .I parameter
3873 is an array variable subscripted with
3874 .B @
3875 or
3876 .BR * ,
3877 the pattern removal operation is applied to each member of the
3878 array in turn, and the expansion is the resultant list.
3879 .TP
3880 .PD 0
3881 ${\fIparameter\fP\fB%\fP\fIword\fP}
3882 .TP
3883 ${\fIparameter\fP\fB%%\fP\fIword\fP}
3884 .PD
3885 \fBRemove matching suffix pattern\fP.
3886 The \fIword\fP is expanded to produce a pattern just as in
3887 pathname expansion, and matched against the expanded value of
3888 .I parameter
3889 using the rules described under
3890 .B "Pattern Matching"
3891 below.
3892 If the pattern matches a trailing portion of the expanded value of
3893 .IR parameter ,
3894 then the result of the expansion is the expanded value of
3895 .I parameter
3896 with the shortest matching pattern (the
3897 .Q %
3898 case) or the longest matching pattern (the
3899 .Q %%
3900 case) deleted.
3901 If
3902 .I parameter
3903 is
3904 .B @
3905 or
3906 .BR * ,
3907 the pattern removal operation is applied to each positional
3908 parameter in turn, and the expansion is the resultant list.
3909 If
3910 .I parameter
3911 is an array variable subscripted with
3912 .B @
3913 or
3914 .BR * ,
3915 the pattern removal operation is applied to each member of the
3916 array in turn, and the expansion is the resultant list.
3917 .TP
3918 .PD 0
3919 ${\fIparameter\fP\fB/\fP\fIpattern\fP\fB/\fP\fIstring\fP}
3920 .TP
3921 ${\fIparameter\fP\fB//\fP\fIpattern\fP\fB/\fP\fIstring\fP}
3922 .TP
3923 ${\fIparameter\fP\fB/#\fP\fIpattern\fP\fB/\fP\fIstring\fP}
3924 .TP
3925 ${\fIparameter\fP\fB/%\fP\fIpattern\fP\fB/\fP\fIstring\fP}
3926 .PD
3927 \fBPattern substitution\fP.
3928 The \fIpattern\fP is expanded to produce a pattern
3929 and matched against the expanded value of \fIparameter\fP
3930 as described under
3931 .B "Pattern Matching"
3932 below.
3933 The longest match of \fIpattern\fP
3934 in the expanded value is replaced with \fIstring\fP.
3935 \fIstring\fP undergoes tilde expansion, parameter and variable expansion,
3936 arithmetic expansion, command and process substitution, and quote removal.
3937 .IP
3938 In the first form above, only the first match is replaced.
3939 If there are two slashes separating \fIparameter\fP and \fIpattern\fP
3940 (the second form above), all matches of \fIpattern\fP are
3941 replaced with \fIstring\fP.
3942 If \fIpattern\fP is preceded by \fB#\fP (the third form above),
3943 it must match at the beginning of the expanded value of \fIparameter\fP.
3944 If \fIpattern\fP is preceded by \fB%\fP (the fourth form above),
3945 it must match at the end of the expanded value of \fIparameter\fP.
3946 .IP
3947 If the expansion of \fIstring\fP is null,
3948 matches of \fIpattern\fP are deleted
3949 and the \fB/\fP following \fIpattern\fP may be omitted.
3950 .IP
3951 If the \fBpatsub_replacement\fP shell option is enabled using \fBshopt\fP,
3952 any unquoted instances of \fB&\fP in \fIstring\fP are replaced with the
3953 matching portion of \fIpattern\fP.
3954 .IP
3955 Quoting any part of \fIstring\fP inhibits replacement in the
3956 expansion of the quoted portion, including replacement strings stored
3957 in shell variables.
3958 Backslash escapes \fB&\fP in \fIstring\fP; the backslash is removed
3959 in order to permit a literal \fB&\fP in the replacement string.
3960 Backslash can also be used to escape a backslash; \fB\e\e\fP results in
3961 a literal backslash in the replacement.
3962 Users should take care if \fIstring\fP is double-quoted to avoid
3963 unwanted interactions between the backslash and double-quoting, since
3964 backslash has special meaning within double quotes.
3965 Pattern substitution performs the check for unquoted \fB&\fP after
3966 expanding \fIstring\fP;
3967 shell programmers should quote any occurrences of \fB&\fP
3968 they want to be taken literally in the replacement
3969 and ensure any instances of \fB&\fP they want to be replaced are unquoted.
3970 .IP
3971 Like the pattern removal operators, double quotes surrounding the
3972 replacement string quote the expanded characters, while double quotes
3973 enclosing the entire parameter substitution do not, since
3974 the expansion is performed in a
3975 context that doesn't take any enclosing double quotes into account.
3976 .IP
3977 If the
3978 .B nocasematch
3979 shell option is enabled, the match is performed without regard to the case
3980 of alphabetic characters.
3981 .IP
3982 If
3983 .I parameter
3984 is
3985 .B @
3986 or
3987 .BR * ,
3988 the substitution operation is applied to each positional
3989 parameter in turn, and the expansion is the resultant list.
3990 If
3991 .I parameter
3992 is an array variable subscripted with
3993 .B @
3994 or
3995 .BR * ,
3996 the substitution operation is applied to each member of the
3997 array in turn, and the expansion is the resultant list.
3998 .TP
3999 .PD 0
4000 ${\fIparameter\fP\fB\*^\fP\fIpattern\fP}
4001 .TP
4002 ${\fIparameter\fP\fB\*^\*^\fP\fIpattern\fP}
4003 .TP
4004 ${\fIparameter\fP\fB,\fP\fIpattern\fP}
4005 .TP
4006 ${\fIparameter\fP\fB,,\fP\fIpattern\fP}
4007 .PD
4008 \fBCase modification\fP.
4009 This expansion modifies the case of alphabetic characters in \fIparameter\fP.
4010 First, the \fIpattern\fP is expanded to produce a pattern
4011 as described below under
4012 .SM
4013 .BR "Pattern Matching" .
4014 .B Bash
4015 then examines characters in the expanded value of \fIparameter\fP
4016 against \fIpattern\fP as described below.
4017 If a character matches the pattern, its case is converted.
4018 The pattern should not attempt to match more than one character.
4019 .IP
4020 Using
4021 .Q \*^
4022 converts lowercase letters matching \fIpattern\fP to uppercase;
4023 .Q ,
4024 converts matching uppercase letters to lowercase.
4025 The
4026 \fB\*^\fP and \fB,\fP variants
4027 examine the first character in the expanded value
4028 and convert its case if it matches \fIpattern\fP;
4029 the
4030 \fB\*^\*^\fP and \fB,,\fP variants
4031 examine all characters in the expanded value
4032 and convert each one that matches \fIpattern\fP.
4033 If \fIpattern\fP is omitted, it is treated like a \fB?\fP, which matches
4034 every character.
4035 .IP
4036 If
4037 .I parameter
4038 is
4039 .B @
4040 or
4041 .BR * ,
4042 the case modification operation is applied to each positional
4043 parameter in turn, and the expansion is the resultant list.
4044 If
4045 .I parameter
4046 is an array variable subscripted with
4047 .B @
4048 or
4049 .BR * ,
4050 the case modification operation is applied to each member of the
4051 array in turn, and the expansion is the resultant list.
4052 .TP
4053 .PD 0
4054 ${\fIparameter\fP\fB@\fP\fIoperator\fP}
4055 \fBParameter transformation\fP.
4056 The expansion is either a transformation of the value of \fIparameter\fP
4057 or information about \fIparameter\fP itself, depending on the value of
4058 \fIoperator\fP. Each \fIoperator\fP is a single letter:
4059 .PP
4060 .RS
4061 .TP
4062 .B U
4063 The expansion is a string that is the value of \fIparameter\fP with lowercase
4064 alphabetic characters converted to uppercase.
4065 .TP
4066 .B u
4067 The expansion is a string that is the value of \fIparameter\fP with the first
4068 character converted to uppercase, if it is alphabetic.
4069 .TP
4070 .B L
4071 The expansion is a string that is the value of \fIparameter\fP with uppercase
4072 alphabetic characters converted to lowercase.
4073 .TP
4074 .B Q
4075 The expansion is a string that is the value of \fIparameter\fP quoted in a
4076 format that can be reused as input.
4077 .TP
4078 .B E
4079 The expansion is a string that is the value of \fIparameter\fP with backslash
4080 escape sequences expanded as with the \fB$\*'\fP.\|.\|.\%\fB\*'\fP
4081 quoting mechanism.
4082 .TP
4083 .B P
4084 The expansion is a string that is the result of expanding the value of
4085 \fIparameter\fP as if it were a prompt string (see \fBPROMPTING\fP below).
4086 .TP
4087 .B A
4088 The expansion is a string in the form of
4089 an assignment statement or \fBdeclare\fP command that, if
4090 evaluated, recreates \fIparameter\fP with its attributes and value.
4091 .TP
4092 .B K
4093 Produces a possibly-quoted version of the value of \fIparameter\fP,
4094 except that it prints the values of
4095 indexed and associative arrays as a sequence of quoted key-value pairs
4096 (see \fBArrays\fP above).
4097 The keys and values are quoted in a format that can be reused as input.
4098 .TP
4099 .B a
4100 The expansion is a string consisting of flag values representing
4101 \fIparameter\fP's attributes.
4102 .TP
4103 .B k
4104 Like the K transformation, but expands the keys and values of
4105 indexed and associative arrays to separate words after word splitting.
4106 .PD
4107 .PP
4108 If
4109 .I parameter
4110 is
4111 .B @
4112 or
4113 .BR * ,
4114 the operation is applied to each positional
4115 parameter in turn, and the expansion is the resultant list.
4116 If
4117 .I parameter
4118 is an array variable subscripted with
4119 .B @
4120 or
4121 .BR * ,
4122 the operation is applied to each member of the
4123 array in turn, and the expansion is the resultant list.
4124 .PP
4125 The result of the expansion is subject to word splitting and pathname
4126 expansion as described below.
4127 .RE
4128 .SS Command Substitution
4129 \fICommand substitution\fP allows the output of a command to replace
4130 the command itself.
4131 There are two standard forms:
4132 .RS
4133 .PP
4134 \fB$(\fP\fIcommand\fP\|\fB)\fP
4135 .RE
4136 or (deprecated)
4137 .RS
4138 \fB\`\fP\fIcommand\fP\fB\`\fP.
4139 .RE
4140 .PP
4141 .B Bash
4142 performs the expansion by executing \fIcommand\fP in a subshell environment
4143 and replacing the command substitution with the standard output of the
4144 command, with any trailing newlines deleted.
4145 Embedded newlines are not deleted, but they may be removed during
4146 word splitting.
4147 The command substitution \fB$(cat \fIfile\fP)\fR can be replaced by
4148 the equivalent but faster \fB$(< \fIfile\fP)\fR.
4149 .PP
4150 With the old-style backquote form of substitution,
4151 backslash retains its literal meaning except when followed by
4152 .BR $ ,
4153 .BR \` ,
4154 or
4155 .BR \e .
4156 The first backquote not preceded by a backslash terminates the
4157 command substitution.
4158 When using the $(\^\fIcommand\fP\|) form, all characters between the
4159 parentheses make up the command; none are treated specially.
4160 .PP
4161 There is an alternate form of command substitution:
4162 .RS
4163 .PP
4164 \fB${\fP\fIc\fP \fIcommand\fP\fB;\fP\|\fB}\fP
4165 .RE
4166 .PP
4167 which executes \fIcommand\fP in the current execution environment
4168 and captures its output, again with trailing newlines removed.
4169 .PP
4170 The character \fIc\fP following the open brace must be a space, tab,
4171 newline, or \fB|\fP, and the close brace must be in a position
4172 where a reserved word may appear (i.e., preceded by a command terminator
4173 such as semicolon).
4174 \fBBash\fP allows the close brace to be joined to the remaining characters in
4175 the word without being followed by a shell metacharacter as a reserved
4176 word would usually require.
4177 .PP
4178 Any side effects of \fIcommand\fP take effect immediately
4179 in the current execution environment and persist in the current
4180 environment after the command completes (e.g., the \fBexit\fP builtin
4181 exits the shell).
4182 .PP
4183 This type of command substitution superficially resembles executing an
4184 unnamed shell function: local variables are created as when a shell
4185 function is executing, and the \fBreturn\fP builtin forces
4186 \fIcommand\fP to complete;
4187 however, the rest of the execution environment,
4188 including the positional parameters, is shared with the caller.
4189 .PP
4190 If the first character following the open brace
4191 is a \fB|\fP, the construct expands to the
4192 value of the \fBREPLY\fP shell variable after \fIcommand\fP executes,
4193 without removing any trailing newlines,
4194 and the standard output of \fIcommand\fP remains the same as in the
4195 calling shell.
4196 \fBBash\fP creates \fBREPLY\fP as an initially-unset local variable when
4197 \fIcommand\fP executes, and restores \fBREPLY\fP to the value it had
4198 before the command substitution after \fIcommand\fP completes,
4199 as with any local variable.
4200 .PP
4201 Command substitutions may be nested. To nest when using the backquoted form,
4202 escape the inner backquotes with backslashes.
4203 .PP
4204 If the substitution appears within double quotes, \fBbash\fP does not perform
4205 word splitting and pathname expansion on the results.
4206 .SS Arithmetic Expansion
4207 Arithmetic expansion evaluates an arithmetic expression
4208 and substitutes the result.
4209 The format for arithmetic expansion is:
4210 .RS
4211 .PP
4212 \fB$((\fP\fIexpression\fP\fB))\fP
4213 .RE
4214 .PP
4215 The old format \fB$[\fP\fIexpression\fP\fB]\fP is deprecated and will
4216 be removed in upcoming versions of bash.
4217 .PP
4218 The
4219 .I expression
4220 undergoes the same expansions
4221 as if it were within double quotes,
4222 but unescaped double quote characters
4223 in \fIexpression\fP are not treated
4224 specially and are removed.
4225 All tokens in the expression undergo parameter and variable expansion,
4226 command substitution, and quote removal.
4227 The result is treated as the arithmetic expression to be evaluated.
4228 Since the way Bash handles double quotes
4229 can potentially result in empty strings,
4230 arithmetic expansion treats
4231 those as expressions that evaluate to 0.
4232 Arithmetic expansions may be nested.
4233 .PP
4234 The evaluation is performed according to the rules listed below under
4235 .SM
4236 .BR "ARITHMETIC EVALUATION" .
4237 If
4238 .I expression
4239 is invalid,
4240 .B bash
4241 prints a message to standard error indicating failure,
4242 does not perform the substitution,
4243 and does not execute the command associated with the expansion.
4244 .SS Process Substitution
4245 \fIProcess substitution\fP allows a process's input or output to be
4246 referred to using a filename.
4247 It takes the form of
4248 \fB<(\fP\fIlist\^\fP\fB)\fP
4249 or
4250 \fB>(\fP\fIlist\^\fP\fB)\fP.
4251 The process \fIlist\fP is run asynchronously, and its input or output
4252 appears as a filename.
4253 This filename is
4254 passed as an argument to the current command as the result of the
4255 expansion.
4256 .PP
4257 If the
4258 \fB>(\fP\fIlist\^\fP\fB)\fP form is used, writing to
4259 the file provides input for \fIlist\fP.
4260 If the
4261 \fB<(\fP\fIlist\^\fP\fB)\fP form is used, reading the file
4262 obtains the output of \fIlist\fP.
4263 No space may appear between the \fB<\fP or \fB>\fP
4264 and the left parenthesis, otherwise the construct would be interpreted
4265 as a redirection.
4266 .PP
4267 Process substitution is supported on systems that support named
4268 pipes (\fIFIFOs\fP) or the \fI/dev/fd\fP method of naming open files.
4269 .PP
4270 When available, process substitution is performed
4271 simultaneously with parameter and variable expansion,
4272 command substitution,
4273 and arithmetic expansion.
4274 .SS Word Splitting
4275 The shell scans the results of
4276 parameter expansion,
4277 command substitution,
4278 and
4279 arithmetic expansion
4280 that did not occur within double quotes for
4281 .IR "word splitting" .
4282 Words that were not expanded are not split.
4283 .PP
4284 The shell treats each character of
4285 .SM
4286 .B IFS
4287 as a delimiter,
4288 and splits the results of the other expansions into words
4289 using these characters as field terminators.
4290 .PP
4291 An \fIIFS whitespace\fP character is whitespace as defined above
4292 (see \fBDefinitions\fP) that appears in the value of
4293 .SM
4294 .BR IFS .
4295 Space, tab, and newline are always considered IFS whitespace, even
4296 if they don't appear in the locale's \fBspace\fP category.
4297 .PP
4298 If
4299 .SM
4300 .B IFS
4301 is unset, field splitting acts as if its value were
4302 .BR <space><tab><newline> ,
4303 and treats these characters as IFS whitespace.
4304 If the value of
4305 .SM
4306 .B IFS
4307 is null, no word splitting occurs,
4308 but implicit null arguments (see below) are still removed.
4309 .PP
4310 Word splitting begins by removing sequences of IFS whitespace characters
4311 from the beginning and end of the results of the previous expansions,
4312 then splits the remaining words.
4313 .PP
4314 If the value of
4315 .SM
4316 .B IFS
4317 consists solely of IFS whitespace,
4318 any sequence of IFS whitespace characters delimits a field,
4319 so a field consists of characters that are not unquoted IFS
4320 whitespace, and null fields result only from quoting.
4321 .PP
4322 If
4323 .SM
4324 .B IFS
4325 contains a non-whitespace character, then any character in
4326 the value of
4327 .SM
4328 .B IFS
4329 that is not IFS whitespace,
4330 along with any adjacent IFS whitespace characters, delimits a field.
4331 This means that adjacent non-IFS-whitespace delimiters produce a
4332 null field.
4333 A sequence of IFS whitespace characters also delimits a field.
4334 .PP
4335 Explicit null arguments (\^\fB\*"\^\*"\fP or
4336 \^\fB\*'\^\*'\fP\^) are retained
4337 and passed to commands as empty strings.
4338 Unquoted implicit null arguments, resulting from the expansion of
4339 parameters that have no values, are removed.
4340 Expanding a parameter with no value within double quotes
4341 produces a null field,
4342 which is retained and passed to a command as an empty string.
4343 .PP
4344 When a quoted null argument appears as part of a word whose expansion is
4345 non-null, word splitting removes the null argument portion,
4346 leaving the non-null expansion.
4347 That is, the word
4348 .Q "\-d\*'\^\*'"
4349 becomes
4350 .Q \-d
4351 after word splitting and null argument removal.
4352 .SS "Pathname Expansion"
4353 After word splitting,
4354 unless the
4355 .B \-f
4356 option has been set,
4357 .B bash
4358 scans each word for the characters
4359 .BR * ,
4360 .BR ? ,
4361 and
4362 .BR [ .
4363 If one of these characters appears, and is not quoted, then the word is
4364 regarded as a
4365 .IR pattern ,
4366 and replaced with a sorted list of filenames matching the pattern
4367 (see
4368 .SM
4369 .B "Pattern Matching"
4370 below)
4371 subject to the value of the \fBGLOBSORT\fP shell variable.
4372 .PP
4373 If no matching filenames are found,
4374 and the shell option
4375 .B nullglob
4376 is not enabled, the word is left unchanged.
4377 If the
4378 .B nullglob
4379 option is set, and no matches are found,
4380 the word is removed.
4381 If the
4382 .B failglob
4383 shell option is set, and no matches are found,
4384 \fBbash\fP prints an error message and does not execute the command.
4385 If the shell option
4386 .B nocaseglob
4387 is enabled, the match is performed without regard to the case
4388 of alphabetic characters.
4389 Note that when using range expressions like
4390 [a-z] (see below), letters of the other case may be included,
4391 depending on the setting of
4392 .B LC_COLLATE.
4393 .PP
4394 When a pattern is used for pathname expansion,
4395 the character
4396 .Q .\&
4397 at the start of a name or immediately following a slash
4398 must be matched explicitly, unless the shell option
4399 .B dotglob
4400 is set.
4401 In order to match the filenames
4402 .FN .\&
4403 and
4404 .FN ..\& ,
4405 the pattern must begin with
4406 .Q .\&
4407 (for example,
4408 .Q .?\& ),
4409 even if
4410 .B dotglob
4411 is set.
4412 If the
4413 .B globskipdots
4414 shell option is enabled, the filenames
4415 .FN .\&
4416 and
4417 .FN ..\&
4418 never match, even if the pattern begins with a
4419 .Q .\& .
4420 When not matching pathnames, the
4421 .Q .\&
4422 character is not treated specially.
4423 .PP
4424 When matching a pathname, the slash character must always be
4425 matched explicitly by a slash in the pattern, but in other matching
4426 contexts it can be matched by a special pattern character as described
4427 below under
4428 .SM
4429 .BR "Pattern Matching" .
4430 .PP
4431 See the description of
4432 .B shopt
4433 below under
4434 .SM
4435 .B "SHELL BUILTIN COMMANDS"
4436 for a description of the
4437 .BR nocaseglob ,
4438 .BR nullglob ,
4439 .BR globskipdots ,
4440 .BR failglob ,
4441 and
4442 .B dotglob
4443 shell options.
4444 .PP
4445 The
4446 .SM
4447 .B GLOBIGNORE
4448 shell variable may be used to restrict the set of file names matching a
4449 .IR pattern .
4450 If
4451 .SM
4452 .B GLOBIGNORE
4453 is set, each matching file name that also matches one of the patterns in
4454 .SM
4455 .B GLOBIGNORE
4456 is removed from the list of matches.
4457 If the \fBnocaseglob\fP option is set, the matching against the patterns in
4458 .SM
4459 .B GLOBIGNORE
4460 is performed without regard to case.
4461 The filenames
4462 .FN .\&
4463 and
4464 .FN ..\&
4465 are always ignored when
4466 .SM
4467 .B GLOBIGNORE
4468 is set and not null.
4469 However, setting
4470 .SM
4471 .B GLOBIGNORE
4472 to a non-null value has the effect of enabling the
4473 .B dotglob
4474 shell option, so all other filenames beginning with a
4475 .Q .\&
4476 match.
4477 To get the old behavior of ignoring filenames beginning with a
4478 .Q .\& ,
4479 make
4480 .Q .*
4481 one of the patterns in
4482 .SM
4483 .B GLOBIGNORE\c
4484 \&.
4485 The
4486 .B dotglob
4487 option is disabled when
4488 .SM
4489 .B GLOBIGNORE
4490 is unset.
4491 The
4492 .B GLOBIGNORE
4493 pattern matching honors the setting of the \fBextglob\fP shell
4494 option.
4495 .PP
4496 The value of the
4497 .SM
4498 .B GLOBSORT
4499 shell variable controls how the results of pathname expansion are sorted,
4500 as described above under
4501 .BR "Shell Variables" .
4502 .PP
4503 .B "Pattern Matching"
4504 .PP
4505 Any character that appears in a pattern, other than the special pattern
4506 characters described below, matches itself.
4507 The NUL character may not occur in a pattern.
4508 A backslash escapes the following character; the escaping backslash is
4509 discarded when matching.
4510 The special pattern characters must be quoted if
4511 they are to be matched literally.
4512 .PP
4513 The special pattern characters have the following meanings:
4514 .PP
4515 .PD 0
4516 .RS
4517 .TP
4518 .B *
4519 Matches any string, including the null string.
4520 When the \fBglobstar\fP shell option is enabled, and \fB*\fP is used in
4521 a pathname expansion context, two adjacent \fB*\fPs used as a single
4522 pattern match all files and zero or more directories and
4523 subdirectories.
4524 If followed by a \fB/\fP, two adjacent \fB*\fPs match only directories
4525 and subdirectories.
4526 .TP
4527 .B ?
4528 Matches any single character.
4529 .TP
4530 .BR [ .\|.\|. ]
4531 .PD
4532 Matches any one of the characters enclosed between the brackets.
4533 This is known as a \fIbracket expression\fP
4534 and matches a single character.
4535 A pair of characters separated by a hyphen denotes a
4536 \fIrange expression\fP;
4537 any character that falls between those two characters, inclusive,
4538 using the current locale's collating sequence and character set, matches.
4539 If the first character following the
4540 .B [
4541 is a
4542 .B !
4543 or a
4544 .B \*^
4545 then any character not within the range matches.
4546 To match a
4547 .BR \- ,
4548 include it as the first or last character in the set.
4549 To match a
4550 .BR ] ,
4551 include it as the first character in the set.
4552 .IP
4553 The sorting order of characters in range expressions,
4554 and the characters included in the range,
4555 are determined by the current locale and the values of the
4556 .SM
4557 .B LC_COLLATE
4558 or
4559 .SM
4560 .B LC_ALL
4561 shell variables, if set.
4562 To obtain the traditional interpretation of range expressions, where
4563 .B [a\-d]
4564 is equivalent to
4565 .BR [abcd] ,
4566 set the value of the
4567 .B LC_COLLATE
4568 or
4569 .B LC_ALL
4570 shell variables to
4571 .BR C ,
4572 or enable the
4573 .B globasciiranges
4574 shell option.
4575 .IP
4576 Within a bracket expression,
4577 \fIcharacter classes\fP can be specified using the syntax
4578 \fB[:\fP\fIclass\fP\fB:]\fP, where \fIclass\fP is one of the
4579 following classes defined in the
4580 .SM POSIX
4581 standard:
4582 .IP
4583 .RS
4584 .B
4585 .if n alnum alpha ascii blank cntrl digit graph lower print punct space \
4586 upper word xdigit
4587 .if t alnum alpha ascii blank cntrl digit graph lower \
4588 print punct space upper word xdigit
4589 .RE
4590 .IP
4591 A character class matches any character belonging to that class.
4592 The \fBword\fP character class matches letters, digits, and the character _.
4593 .IP
4594 Within a bracket expression,
4595 an \fIequivalence class\fP can be specified using the syntax
4596 \fB[=\fP\fIc\fP\fB=]\fP, which matches all characters with the
4597 same collation weight (as defined by the current locale) as
4598 the character \fIc\fP.
4599 .IP
4600 Within a bracket expression,
4601 the syntax \fB[.\fP\fIsymbol\fP\fB.]\fP matches the collating symbol
4602 \fIsymbol\fP.
4603 .RE
4604 .PP
4605 If the \fBextglob\fP shell option is enabled using the \fBshopt\fP
4606 builtin, the shell recognizes several extended pattern matching operators.
4607 In the following description, a \fIpattern-list\fP is a list of one
4608 or more patterns separated by a \fB|\fP.
4609 Composite patterns may be formed using one or more of the following
4610 sub-patterns:
4611 .PP
4612 .PD 0
4613 .RS
4614 .TP
4615 \fB?(\fP\^\fIpattern-list\^\fP\fB)\fP
4616 Matches zero or one occurrence of the given patterns.
4617 .TP
4618 \fB*(\fP\^\fIpattern-list\^\fP\fB)\fP
4619 Matches zero or more occurrences of the given patterns.
4620 .TP
4621 \fB+(\fP\^\fIpattern-list\^\fP\fB)\fP
4622 Matches one or more occurrences of the given patterns.
4623 .TP
4624 \fB@(\fP\^\fIpattern-list\^\fP\fB)\fP
4625 Matches one of the given patterns.
4626 .TP
4627 \fB!(\fP\^\fIpattern-list\^\fP\fB)\fP
4628 Matches anything except one of the given patterns.
4629 .RE
4630 .PD
4631 .PP
4632 The \fBextglob\fP option changes the behavior of the parser, since the
4633 parentheses are normally treated as operators with syntactic meaning.
4634 To ensure that extended matching patterns are parsed correctly, make sure
4635 that \fBextglob\fP is enabled before parsing constructs containing the
4636 patterns, including shell functions and command substitutions.
4637 .PP
4638 When matching filenames, the \fBdotglob\fP shell option determines
4639 the set of filenames that are tested:
4640 when \fBdotglob\fP is enabled, the set of filenames includes all files
4641 beginning with
4642 .Q .\& ,
4643 but
4644 .FN .\&
4645 and
4646 .FN ..\&
4647 must be matched by a pattern or sub-pattern that begins with a dot;
4648 when it is disabled, the set does not
4649 include any filenames beginning with
4650 .Q .\&
4651 unless the pattern or sub-pattern begins with a
4652 .Q .\& .
4653 If the
4654 .B globskipdots
4655 shell option is enabled, the filenames
4656 .FN .\&
4657 and
4658 .FN ..\&
4659 never appear in the set.
4660 As above,
4661 .Q .\&
4662 only has a special meaning when matching filenames.
4663 .PP
4664 Complicated extended pattern matching against long strings is slow,
4665 especially when the patterns contain alternations and the strings
4666 contain multiple matches.
4667 Using separate matches against shorter strings, or using arrays of
4668 strings instead of a single long string, may be faster.
4669 .SS Quote Removal
4670 After the preceding expansions, all unquoted occurrences of the
4671 characters
4672 .BR \e ,
4673 .BR \*' ,
4674 and \^\fB\*"\fP\^ that did not result from one of the above
4675 expansions are removed.
4676 .SH REDIRECTION
4677 Before a command is executed, its input and output may be
4678 .I redirected
4679 using a special notation interpreted by the shell.
4680 \fIRedirection\fP allows commands' file handles to be
4681 duplicated, opened, closed,
4682 made to refer to different files,
4683 and can change the files the command reads from and writes to.
4684 When used with the \fBexec\fP builtin,
4685 redirections modify file handles in the current shell execution environment.
4686 The following redirection
4687 operators may precede or appear anywhere within a
4688 .I simple command
4689 or may follow a
4690 .IR command .
4691 Redirections are processed in the order they appear, from
4692 left to right.
4693 .PP
4694 Each redirection that may be preceded by a file descriptor number
4695 may instead be preceded by a word of the form {\fIvarname\fP}.
4696 In this case, for each redirection operator except
4697 .B >&\-
4698 and
4699 .BR <&\- ,
4700 the shell allocates a file descriptor greater
4701 than or equal to 10 and assigns it to \fIvarname\fP.
4702 If {\fIvarname\fP} precedes
4703 .B >&\-
4704 or
4705 .BR <&\- ,
4706 the value of \fIvarname\fP defines the file descriptor to close.
4707 If {\fIvarname\fP} is supplied, the redirection persists beyond
4708 the scope of the command, which allows the shell programmer to
4709 manage the file descriptor's lifetime manually without using
4710 the \fBexec\fP builtin.
4711 The \fBvarredir_close\fP shell option manages this behavior.
4712 .PP
4713 In the following descriptions, if the file descriptor number is
4714 omitted, and the first character of the redirection operator is
4715 .Q < ,
4716 the redirection refers to the standard input (file descriptor 0).
4717 If the first character of the redirection operator is
4718 .Q > ,
4719 the redirection refers to the standard output (file descriptor 1).
4720 .PP
4721 The \fIword\fP following the redirection operator in the following
4722 descriptions, unless otherwise noted, is subjected to
4723 brace expansion,
4724 tilde expansion,
4725 parameter and variable expansion,
4726 command substitution,
4727 arithmetic expansion,
4728 quote removal,
4729 pathname expansion,
4730 and word splitting.
4731 If it expands to more than one word,
4732 .B bash
4733 reports an error.
4734 .PP
4735 The order of redirections is significant.
4736 For example,
4737 the command
4738 .RS
4739 .PP
4740 ls \fB>\fP dirlist 2\fB>&\fP1
4741 .RE
4742 .PP
4743 directs both standard output and standard error to the file
4744 .IR dirlist ,
4745 while the command
4746 .RS
4747 .PP
4748 ls 2\fB>&\fP1 \fB>\fP dirlist
4749 .RE
4750 .PP
4751 directs only the standard output to file
4752 .IR dirlist ,
4753 because the standard error was directed to the standard output
4754 before the standard output was redirected to
4755 .IR dirlist .
4756 .PP
4757 \fBBash\fP handles several filenames specially when they are used in
4758 redirections, as described in the following table.
4759 If the operating system on which \fBbash\fP is running provides these
4760 special files, \fBbash\fP uses them; otherwise it emulates them
4761 internally with the behavior described below.
4762 .RS
4763 .PP
4764 .PD 0
4765 .TP
4766 .B /dev/fd/\fIfd\fP
4767 If \fIfd\fP is a valid integer, duplicate file descriptor \fIfd\fP.
4768 .TP
4769 .B /dev/stdin
4770 File descriptor 0 is duplicated.
4771 .TP
4772 .B /dev/stdout
4773 File descriptor 1 is duplicated.
4774 .TP
4775 .B /dev/stderr
4776 File descriptor 2 is duplicated.
4777 .TP
4778 .B /dev/tcp/\fIhost\fP/\fIport\fP
4779 If \fIhost\fP is a valid hostname or Internet address, and \fIport\fP
4780 is an integer port number or service name, \fBbash\fP attempts to open
4781 the corresponding TCP socket.
4782 .TP
4783 .B /dev/udp/\fIhost\fP/\fIport\fP
4784 If \fIhost\fP is a valid hostname or Internet address, and \fIport\fP
4785 is an integer port number or service name, \fBbash\fP attempts to open
4786 the corresponding UDP socket.
4787 .PD
4788 .RE
4789 .PP
4790 A failure to open or create a file causes the redirection to fail.
4791 .PP
4792 Redirections using file descriptors greater than 9 should be used with
4793 care, as they may conflict with file descriptors the shell uses
4794 internally.
4795 .PP
4796 Note that the
4797 .B exec
4798 builtin command can make redirections take effect in the current shell.
4799 .SS Redirecting Input
4800 Redirecting input opens the file whose name results from
4801 the expansion of
4802 .I word
4803 for reading on file descriptor
4804 .IR n ,
4805 or the standard input (file descriptor 0) if
4806 .I n
4807 is not specified.
4808 .PP
4809 The general format for redirecting input is:
4810 .RS
4811 .PP
4812 [\fIn\fP]\fB<\fP\fIword\fP
4813 .RE
4814 .SS Redirecting Output
4815 Redirecting output opens the file whose name results from
4816 the expansion of
4817 .I word
4818 for writing on file descriptor
4819 .IR n ,
4820 or the standard output (file descriptor 1) if
4821 .I n
4822 is not specified.
4823 If the file does not exist it is created;
4824 if it does exist it is truncated to zero size.
4825 .PP
4826 The general format for redirecting output is:
4827 .RS
4828 .PP
4829 [\fIn\fP]\fB>\fP\fIword\fP
4830 .RE
4831 .PP
4832 If the redirection operator is
4833 .BR > ,
4834 and the
4835 .B noclobber
4836 option to the
4837 .B set
4838 builtin command has been enabled, the redirection fails if the file
4839 whose name results from the expansion of \fIword\fP exists and is
4840 a regular file.
4841 If the redirection operator is
4842 .BR >| ,
4843 or the redirection operator is
4844 .B >
4845 and the
4846 .B noclobber
4847 option to the
4848 .B set
4849 builtin is not enabled,
4850 \fBbash\fP attempts the redirection
4851 even if the file named by \fIword\fP exists.
4852 .SS Appending Redirected Output
4853 Redirecting output in this fashion opens
4854 the file whose name results from the expansion of
4855 .I word
4856 for appending on file descriptor
4857 .IR n ,
4858 or the standard output (file descriptor 1) if
4859 .I n
4860 is not specified.
4861 If the file does not exist it is created.
4862 .PP
4863 The general format for appending output is:
4864 .RS
4865 .PP
4866 [\fIn\fP]\fB>>\fP\fIword\fP
4867 .RE
4868 .SS Redirecting Standard Output and Standard Error
4869 This construct redirects both the
4870 standard output (file descriptor 1) and
4871 the standard error output (file descriptor 2)
4872 to the file whose name is the expansion of
4873 .IR word .
4874 .PP
4875 There are two formats for redirecting standard output and
4876 standard error:
4877 .RS
4878 .PP
4879 \fB&>\fP\fIword\fP
4880 .RE
4881 and
4882 .RS
4883 \fB>&\fP\fIword\fP
4884 .RE
4885 .PP
4886 Of the two forms, the first is preferred.
4887 This is semantically equivalent to
4888 .RS
4889 .PP
4890 \fB>\fP\fIword\fP 2\fB>&\fP1
4891 .RE
4892 .PP
4893 When using the second form, \fIword\fP may not expand to a number or
4894 \fB\-\fP.
4895 If it does, other redirection operators apply
4896 (see \fBDuplicating File Descriptors\fP below) for compatibility
4897 reasons.
4898 .SS Appending Standard Output and Standard Error
4899 This construct appends both the
4900 standard output (file descriptor 1) and
4901 the standard error output (file descriptor 2)
4902 to the file whose name is the expansion of
4903 .IR word .
4904 .PP
4905 The format for appending standard output and standard error is:
4906 .RS
4907 .PP
4908 \fB&>>\fP\fIword\fP
4909 .RE
4910 .PP
4911 This is semantically equivalent to
4912 .RS
4913 .PP
4914 \fB>>\fP\fIword\fP 2\fB>&\fP1
4915 .RE
4916 .PP
4917 (see \fBDuplicating File Descriptors\fP below).
4918 .SS Here Documents
4919 This type of redirection instructs the shell to read input from the
4920 current source until it reads a line containing only
4921 .I delimiter
4922 (with no trailing blanks).
4923 All of the lines read up to that point then become the standard
4924 input (or file descriptor \fIn\fP if \fIn\fP is specified) for a command.
4925 .PP
4926 The format of here-documents is:
4927 .RS
4928 .PP
4929 .nf
4930 [\fIn\fP]\fB<<\fP[\fB\-\fP]\fIword\fP
4931 \fIhere-document\fP
4932 \fIdelimiter\fP
4933 .fi
4934 .RE
4935 .PP
4936 The shell does not perform
4937 parameter and variable expansion, command substitution,
4938 arithmetic expansion, or pathname expansion on
4939 .IR word .
4940 .PP
4941 If any part of
4942 .I word
4943 is quoted, the
4944 .I delimiter
4945 is the result of quote removal on
4946 .IR word ,
4947 and the lines in the here-document are not expanded.
4948 If \fIword\fP is unquoted, the
4949 .I delimiter
4950 is \fIword\fP itself,
4951 and the here-document text is treated similarly to a double-quoted string:
4952 all lines of the here-document are subjected to
4953 parameter expansion, command substitution, and arithmetic expansion,
4954 the character sequence
4955 .B \e<newline>
4956 is treated literally, and
4957 .B \e
4958 must be used to quote the characters
4959 .BR \e ,
4960 .BR $ ,
4961 and
4962 .BR \` ;
4963 however, double quote characters have no special meaning.
4964 .PP
4965 If the redirection operator is
4966 .BR <<\- ,
4967 then the shell strips all leading tab characters from input lines
4968 and the line containing
4969 .IR delimiter .
4970 This allows
4971 here-documents within shell scripts to be indented in a
4972 natural fashion.
4973 .PP
4974 If the delimiter is not quoted, the
4975 .B \e<newline>
4976 sequence is treated as a line continuation: the two lines are joined
4977 and the backslash-newline is removed.
4978 This happens while reading the here-document, before the check for
4979 the ending delimiter, so joined lines can form the end delimiter.
4980 .SS "Here Strings"
4981 A variant of here documents, the format is:
4982 .RS
4983 .PP
4984 .nf
4985 [\fIn\fP]\fB<<<\fP\fIword\fP
4986 .fi
4987 .RE
4988 .PP
4989 The \fIword\fP undergoes
4990 tilde expansion, parameter and variable expansion,
4991 command substitution, arithmetic expansion, and quote removal.
4992 Pathname expansion and word splitting are not performed.
4993 The result is supplied as a single string, with a newline appended,
4994 to the command on its
4995 standard input (or file descriptor \fIn\fP if \fIn\fP is specified).
4996 .SS "Duplicating File Descriptors"
4997 The redirection operator
4998 .RS
4999 .PP
5000 [\fIn\fP]\fB<&\fP\fIword\fP
5001 .RE
5002 .PP
5003 is used to duplicate input file descriptors.
5004 If
5005 .I word
5006 expands to one or more digits, file descriptor
5007 .I n
5008 is made to be a copy of that file descriptor.
5009 It is a redirection error if the digits in
5010 .I word
5011 do not specify a file descriptor open for input.
5012 If
5013 .I word
5014 evaluates to
5015 .BR \- ,
5016 file descriptor
5017 .I n
5018 is closed.
5019 If
5020 .I n
5021 is not specified, this uses the standard input (file descriptor 0).
5022 .PP
5023 The operator
5024 .RS
5025 .PP
5026 [\fIn\fP]\fB>&\fP\fIword\fP
5027 .RE
5028 .PP
5029 is used similarly to duplicate output file descriptors.
5030 If
5031 .I n
5032 is not specified, this uses the standard output (file descriptor 1).
5033 It is a redirection error if the digits in
5034 .I word
5035 do not specify a file descriptor open for output.
5036 If
5037 .I word
5038 evaluates to
5039 .BR \- ,
5040 file descriptor
5041 .I n
5042 is closed.
5043 As a special case, if \fIn\fP is omitted,
5044 and \fIword\fP does not expand to one or more digits or \fB\-\fP,
5045 this redirects the standard output and standard error as described
5046 previously.
5047 .SS "Moving File Descriptors"
5048 The redirection operator
5049 .RS
5050 .PP
5051 [\fIn\fP]\fB<&\fP\fIdigit\fP\fB\-\fP
5052 .RE
5053 .PP
5054 moves the file descriptor \fIdigit\fP to file descriptor
5055 .IR n ,
5056 or the standard input (file descriptor 0) if \fIn\fP is not specified.
5057 \fIdigit\fP is closed after being duplicated to \fIn\fP.
5058 .PP
5059 Similarly, the redirection operator
5060 .RS
5061 .PP
5062 [\fIn\fP]\fB>&\fP\fIdigit\fP\fB\-\fP
5063 .RE
5064 .PP
5065 moves the file descriptor \fIdigit\fP to file descriptor
5066 .IR n ,
5067 or the standard output (file descriptor 1) if \fIn\fP is not specified.
5068 .SS "Opening File Descriptors for Reading and Writing"
5069 The redirection operator
5070 .RS
5071 .PP
5072 [\fIn\fP]\fB<>\fP\fIword\fP
5073 .RE
5074 .PP
5075 opens the file whose name is the expansion of
5076 .I word
5077 for both reading and writing on file descriptor
5078 .IR n ,
5079 or on file descriptor 0 if
5080 .I n
5081 is not specified.
5082 If the file does not exist, it is created.
5083 .SH ALIASES
5084 \fIAliases\fP allow a string to be substituted for a word that is in
5085 a position in the input where it can be the first word of a simple
5086 command.
5087 Aliases have names and corresponding values that are set
5088 and unset using the \fBalias\fP and \fBunalias\fP builtin commands
5089 (see
5090 .SM
5091 .B "SHELL BUILTIN COMMANDS"
5092 below).
5093 .PP
5094 If the shell reads an unquoted word in the right position, it checks
5095 the word to see if it matches an alias name.
5096 If it matches, the shell
5097 replaces the word with the alias value, and reads that value as if it
5098 had been read instead of the word.
5099 The shell doesn't look at any characters following the word before
5100 attempting alias substitution.
5101 .PP
5102 The characters \fB/\fP, \fB$\fP, \fB\`\fP, and \fB=\fP and
5103 any of the shell \fImetacharacters\fP or quoting characters
5104 listed above may not appear in an alias name.
5105 The replacement text may contain any valid shell input,
5106 including shell metacharacters.
5107 The first word of the replacement text is tested
5108 for aliases, but a word that is identical to an alias being expanded
5109 is not expanded a second time.
5110 This means that one may alias
5111 .B ls
5112 to
5113 .BR "ls \-F" ,
5114 for instance, and
5115 .B bash
5116 does not try to recursively expand the replacement text.
5117 .PP
5118 If the last character of the alias value is a
5119 .IR blank ,
5120 the shell checks the next command
5121 word following the alias for alias expansion.
5122 .PP
5123 Aliases are created and listed with the
5124 .B alias
5125 command, and removed with the
5126 .B unalias
5127 command.
5128 .PP
5129 There is no mechanism for using arguments in the replacement text.
5130 If arguments are needed, use a shell function (see
5131 .SM
5132 .B FUNCTIONS
5133 below) instead.
5134 .PP
5135 Aliases are not expanded when the shell is not interactive, unless
5136 the
5137 .B expand_aliases
5138 shell option is set using
5139 .B shopt
5140 (see the description of
5141 .B shopt
5142 under
5143 .SM
5144 .B "SHELL BUILTIN COMMANDS"
5145 below).
5146 .PP
5147 The rules concerning the definition and use of aliases are
5148 somewhat confusing.
5149 .B Bash
5150 always reads at least one complete line of input,
5151 and all lines that make up a compound command,
5152 before executing any of the commands on that line or the compound command.
5153 Aliases are expanded when a command is read, not when it is executed.
5154 Therefore, an
5155 alias definition appearing on the same line as another
5156 command does not take effect until the shell reads the next line of input,
5157 and an alias definition in a compound command does not take
5158 effect until the shell parses and executes the entire compound command.
5159 The commands following the alias definition
5160 on that line,
5161 or in the rest of a compound command,
5162 are not affected by the new alias.
5163 This behavior is also an issue when functions are executed.
5164 Aliases are expanded when a function definition is read,
5165 not when the function is executed, because a function definition
5166 is itself a command.
5167 As a consequence, aliases
5168 defined in a function are not available until after that
5169 function is executed.
5170 To be safe, always put
5171 alias definitions on a separate line, and do not use
5172 .B alias
5173 in compound commands.
5174 .PP
5175 For almost every purpose, shell functions are preferable to aliases.
5176 .SH FUNCTIONS
5177 A shell function, defined as described above under
5178 .SM
5179 .BR "SHELL GRAMMAR" ,
5180 stores a series of commands for later execution.
5181 When the name of a shell function is used as a simple command name,
5182 the shell executes
5183 the list of commands associated with that function name.
5184 Functions are executed in the context of the
5185 calling shell; there is no new process created to interpret
5186 them (contrast this with the execution of a shell script).
5187 .PP
5188 When a function is executed, the arguments to the
5189 function become the positional parameters
5190 during its execution.
5191 The special parameter
5192 .B #
5193 is updated to reflect the new positional parameters.
5194 Special parameter \fB0\fP is unchanged.
5195 The first element of the
5196 .SM
5197 .B FUNCNAME
5198 variable is set to the name of the function while the function
5199 is executing.
5200 .PP
5201 All other aspects of the shell execution
5202 environment are identical between a function and its caller
5203 with these exceptions: the
5204 .SM
5205 .B DEBUG
5206 and
5207 .B RETURN
5208 traps (see the description of the
5209 .B trap
5210 builtin under
5211 .SM
5212 .B "SHELL BUILTIN COMMANDS"
5213 below) are not inherited unless the function has been given the
5214 \fBtrace\fP attribute (see the description of the
5215 .SM
5216 .B declare
5217 builtin below) or the
5218 \fB\-o functrace\fP shell option has been enabled with
5219 the \fBset\fP builtin
5220 (in which case all functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps),
5221 and the
5222 .SM
5223 .B ERR
5224 trap is not inherited unless the \fB\-o errtrace\fP shell option has
5225 been enabled.
5226 .PP
5227 Variables local to the function are declared with the
5228 .B local
5229 builtin command (\fIlocal variables\fP).
5230 Ordinarily, variables and their values
5231 are shared between the function and its caller.
5232 If a variable is declared \fBlocal\fP, the variable's visible scope
5233 is restricted to that function and its children (including the functions
5234 it calls).
5235 .PP
5236 In the following description, the \fIcurrent scope\fP is a currently-
5237 executing function.
5238 Previous scopes consist of that function's caller and so on,
5239 back to the
5240 .Q global
5241 scope, where the shell is not executing any shell function.
5242 A local variable at the current scope is a variable
5243 declared using the \fBlocal\fP or \fBdeclare\fP builtins in the
5244 function that is currently executing.
5245 .PP
5246 Local variables
5247 .Q shadow
5248 variables with the same name declared at previous scopes.
5249 For instance, a local variable declared in a function
5250 hides variables with the same name declared at previous scopes,
5251 including global variables: references and assignments
5252 refer to the local variable, leaving the variables
5253 at previous scopes unmodified.
5254 When the function returns, the global variable is once again visible.
5255 .PP
5256 The shell uses \fIdynamic scoping\fP to control a variable's visibility
5257 within functions.
5258 With dynamic scoping, visible variables and their values
5259 are a result of the sequence of function calls that caused execution
5260 to reach the current function.
5261 The value of a variable that a function sees depends
5262 on its value within its caller, if any, whether that caller is
5263 the global
5264 scope or another shell function.
5265 This is also the value that a local variable
5266 declaration shadows,
5267 and the value that is restored when the function returns.
5268 .PP
5269 For example, if a variable \fIvar\fP is declared as local in function
5270 \fIfunc1\fP, and \fIfunc1\fP calls another function \fIfunc2\fP,
5271 references to \fIvar\fP made from within \fIfunc2\fP resolve to the
5272 local variable \fIvar\fP from \fIfunc1\fP, shadowing any global variable
5273 named \fIvar\fP.
5274 .PP
5275 The \fBunset\fP builtin also acts using the same dynamic scope: if a
5276 variable is local to the current scope, \fBunset\fP unsets it;
5277 otherwise the unset will refer to the variable found in any calling scope
5278 as described above.
5279 If a variable at the current local scope is unset, it remains so
5280 (appearing as unset)
5281 until it is reset in that scope or until the function returns.
5282 Once the function returns, any instance of the variable at a previous
5283 scope becomes visible.
5284 If the unset acts on a variable at a previous scope, any instance of a
5285 variable with that name that had been shadowed becomes visible
5286 (see below how the \fBlocalvar_unset\fP shell option changes this behavior).
5287 .PP
5288 The
5289 .SM
5290 .B FUNCNEST
5291 variable, if set to a numeric value greater
5292 than 0, defines a maximum function nesting level.
5293 Function invocations that exceed the limit cause the entire command to
5294 abort.
5295 .PP
5296 If the builtin command
5297 .B return
5298 is executed in a function, the function completes and
5299 execution resumes with the next command after the function
5300 call.
5301 If \fBreturn\fP is supplied a numeric argument,
5302 that is the function's return status; otherwise the function's
5303 return status is the exit status of the last command executed
5304 before the \fBreturn\fP.
5305 Any command associated with the \fBRETURN\fP trap is executed
5306 before execution resumes.
5307 When a function completes, the values of the
5308 positional parameters and the special parameter
5309 .B #
5310 are restored to the values they had prior to the function's
5311 execution.
5312 .PP
5313 The
5314 .B \-f
5315 option to the
5316 .B declare
5317 or
5318 .B typeset
5319 builtin commands
5320 lists function names and definitions.
5321 The
5322 .B \-F
5323 option to
5324 .B declare
5325 or
5326 .B typeset
5327 lists the function names only
5328 (and optionally the source file and line number, if the \fBextdebug\fP
5329 shell option is enabled).
5330 Functions may be exported so that child shell processes
5331 (those created when executing a separate shell invocation)
5332 automatically have them defined with the
5333 .B \-f
5334 option to the
5335 .B export
5336 builtin.
5337 The \fB\-f\fP option to
5338 the
5339 .B unset
5340 builtin deletes a function definition.
5341 .PP
5342 Functions may be recursive.
5343 The \fBFUNCNEST\fP variable may be used to limit the depth of the
5344 function call stack and restrict the number of function invocations.
5345 By default, \fBbash\fP imposes no limit on the number of recursive calls.
5346 .SH "ARITHMETIC EVALUATION"
5347 The shell allows arithmetic expressions to be evaluated, under
5348 certain circumstances
5349 (see the \fBlet\fP and \fBdeclare\fP builtin commands,
5350 the \fB((\fP compound command,
5351 the arithmetic \fBfor\fP command,
5352 the \fB[[\fP conditional command,
5353 and \fBArithmetic Expansion\fP).
5354 .PP
5355 Evaluation is done in the largest fixed-width integers available,
5356 with no check for overflow,
5357 though division by 0 is trapped and flagged as an error.
5358 The operators and their precedence, associativity, and values
5359 are the same as in the C language.
5360 The following list of operators is grouped into levels of
5361 equal-precedence operators.
5362 The levels are listed in order of decreasing precedence.
5363 .PP
5364 .PD 0
5365 .TP
5366 .B \fIid\fP++ \fIid\fP\-\-
5367 variable post-increment and post-decrement
5368 .TP
5369 .B ++\fIid\fP \-\-\fIid\fP
5370 variable pre-increment and pre-decrement
5371 .TP
5372 .B \- +
5373 unary minus and plus
5374 .TP
5375 .B ! \*~
5376 logical and bitwise negation
5377 .TP
5378 .B **
5379 exponentiation
5380 .TP
5381 .B * / %
5382 multiplication, division, remainder
5383 .TP
5384 .B + \-
5385 addition, subtraction
5386 .TP
5387 .B << >>
5388 left and right bitwise shifts
5389 .TP
5390 .B <= >= < >
5391 comparison
5392 .TP
5393 .B == !=
5394 equality and inequality
5395 .TP
5396 .B &
5397 bitwise AND
5398 .TP
5399 .B \*^
5400 bitwise exclusive OR
5401 .TP
5402 .B |
5403 bitwise OR
5404 .TP
5405 .B &&
5406 logical AND
5407 .TP
5408 .B ||
5409 logical OR
5410 .TP
5411 .B \fIexpr\fP?\fIexpr\fP:\fIexpr\fP
5412 conditional operator
5413 .TP
5414 .B "= *= /= %= += \-= <<= >>= &= \*^= |="
5415 assignment
5416 .TP
5417 .B \fIexpr1\fP , \fIexpr2\fP
5418 comma
5419 .PD
5420 .PP
5421 Shell variables are allowed as operands; parameter expansion is
5422 performed before the expression is evaluated.
5423 Within an expression, shell variables may also be referenced by name
5424 without using the parameter expansion syntax.
5425 This means you can use "x", where \fIx\fP is a shell variable name,
5426 in an arithmetic expression, and the shell will evaluate its value as
5427 an expression and use the result.
5428 A shell variable that is null or unset evaluates to 0 when referenced
5429 by name in an expression.
5430 .PP
5431 The value of a variable is evaluated as an arithmetic expression
5432 when it is referenced, or when a variable which has been given the
5433 \fIinteger\fP attribute using \fBdeclare \-i\fP is assigned a value.
5434 A null value evaluates to 0.
5435 A shell variable need not have its \fIinteger\fP attribute
5436 turned on to be used in an expression.
5437 .PP
5438 Integer constants follow the C language definition, without suffixes or
5439 character constants.
5440 Constants with a leading 0 are interpreted as octal numbers.
5441 A leading 0x or 0X denotes hexadecimal.
5442 Otherwise, numbers take the form [\fIbase#\fP]n, where the optional \fIbase\fP
5443 is a decimal number between 2 and 64 representing the arithmetic
5444 base, and \fIn\fP is a number in that base.
5445 If \fIbase#\fP is omitted, then base 10 is used.
5446 When specifying \fIn\fP,
5447 if a non-digit is required,
5448 the digits greater than 9 are represented by the lowercase letters,
5449 the uppercase letters, @, and _, in that order.
5450 If \fIbase\fP is less than or equal to 36, lowercase and uppercase
5451 letters may be used interchangeably to represent numbers between 10
5452 and 35.
5453 .PP
5454 Operators are evaluated in precedence order.
5455 Sub-expressions in parentheses are evaluated first
5456 and may override the precedence rules above.
5457 .SH "CONDITIONAL EXPRESSIONS"
5458 Conditional expressions are used by the \fB[[\fP compound command and
5459 the \fBtest\fP and \fB[\fP builtin commands to test file attributes
5460 and perform string and arithmetic comparisons.
5461 The \fBtest\fP and \fB[\fP commands determine their behavior based on
5462 the number of arguments; see the descriptions of those commands for any
5463 other command-specific actions.
5464 .PP
5465 Expressions are formed from the unary or binary primaries listed below.
5466 Unary expressions are often used to examine the status of a file
5467 or shell variable.
5468 Binary operators are used for string, numeric, and file attribute
5469 comparisons.
5470 .PP
5471 \fBBash\fP handles several filenames specially when they are used in
5472 expressions.
5473 If the operating system on which \fBbash\fP is running provides these
5474 special files, bash will use them; otherwise it will emulate them
5475 internally with this behavior:
5476 If any \fIfile\fP argument to one of the primaries is of the form
5477 .FN /dev/fd/n ,
5478 then \fBbash\fP checks file descriptor \fIn\fP.
5479 If the \fIfile\fP argument to one of the primaries is one of
5480 .FN /dev/stdin ,
5481 .FN /dev/stdout ,
5482 or
5483 .FN /dev/stderr ,
5484 \fBbash\fP checks file descriptor 0, 1, or 2, respectively.
5485 .PP
5486 Unless otherwise specified, primaries that operate on files follow symbolic
5487 links and operate on the target of the link, rather than the link itself.
5488 .PP
5489 When used with \fB[[\fP,
5490 or when the shell is in posix mode,
5491 the \fB<\fP and \fB>\fP operators sort
5492 lexicographically using the current locale.
5493 When the shell is not in posix mode,
5494 the \fBtest\fP command sorts using ASCII ordering.
5495 .PP
5496 .PD 0
5497 .TP
5498 .B \-a \fIfile\fP
5499 True if \fIfile\fP exists.
5500 .TP
5501 .B \-b \fIfile\fP
5502 True if \fIfile\fP exists and is a block special file.
5503 .TP
5504 .B \-c \fIfile\fP
5505 True if \fIfile\fP exists and is a character special file.
5506 .TP
5507 .B \-d \fIfile\fP
5508 True if \fIfile\fP exists and is a directory.
5509 .TP
5510 .B \-e \fIfile\fP
5511 True if \fIfile\fP exists.
5512 .TP
5513 .B \-f \fIfile\fP
5514 True if \fIfile\fP exists and is a regular file.
5515 .TP
5516 .B \-g \fIfile\fP
5517 True if \fIfile\fP exists and is set-group-id.
5518 .TP
5519 .B \-h \fIfile\fP
5520 True if \fIfile\fP exists and is a symbolic link.
5521 .TP
5522 .B \-k \fIfile\fP
5523 True if \fIfile\fP exists and its
5524 .Q sticky
5525 bit is set.
5526 .TP
5527 .B \-p \fIfile\fP
5528 True if \fIfile\fP exists and is a named pipe (FIFO).
5529 .TP
5530 .B \-r \fIfile\fP
5531 True if \fIfile\fP exists and is readable.
5532 .TP
5533 .B \-s \fIfile\fP
5534 True if \fIfile\fP exists and has a size greater than zero.
5535 .TP
5536 .B \-t \fIfd\fP
5537 True if file descriptor
5538 .I fd
5539 is open and refers to a terminal.
5540 .TP
5541 .B \-u \fIfile\fP
5542 True if \fIfile\fP exists and its set-user-id bit is set.
5543 .TP
5544 .B \-w \fIfile\fP
5545 True if \fIfile\fP exists and is writable.
5546 .TP
5547 .B \-x \fIfile\fP
5548 True if \fIfile\fP exists and is executable.
5549 .TP
5550 .B \-G \fIfile\fP
5551 True if \fIfile\fP exists and is owned by the effective group id.
5552 .TP
5553 .B \-L \fIfile\fP
5554 True if \fIfile\fP exists and is a symbolic link.
5555 .TP
5556 .B \-N \fIfile\fP
5557 True if \fIfile\fP exists and has been modified since it was last
5558 accessed.
5559 .TP
5560 .B \-O \fIfile\fP
5561 True if \fIfile\fP exists and is owned by the effective user id.
5562 .TP
5563 .B \-S \fIfile\fP
5564 True if \fIfile\fP exists and is a socket.
5565 .TP
5566 .B \-o \fIoptname\fP
5567 True if the shell option
5568 .I optname
5569 is enabled.
5570 See the list of options under the description of the
5571 .B \-o
5572 option to the
5573 .B set
5574 builtin below.
5575 .TP
5576 .B \-v \fIvarname\fP
5577 True if the shell variable
5578 .I varname
5579 is set (has been assigned a value).
5580 If \fIvarname\fP is an indexed
5581 array variable name subscripted by \fI@\fP or \fI*\fP,
5582 this returns true if the array has any set elements.
5583 If \fIvarname\fP is an associative
5584 array variable name subscripted by \fI@\fP or \fI*\fP,
5585 this returns true if an element with that key is set.
5586 .TP
5587 .B \-R \fIvarname\fP
5588 True if the shell variable
5589 .I varname
5590 is set and is a name reference.
5591 .TP
5592 .B \-z \fIstring\fP
5593 True if the length of \fIstring\fP is zero.
5594 .TP
5595 \fIstring\fP
5596 .TP
5597 .B \-n \fIstring\fP
5598 True if the length of
5599 .I string
5600 is non-zero.
5601 .PD
5602 .TP
5603 \fIstring1\fP \fB==\fP \fIstring2\fP
5604 .PD 0
5605 .TP
5606 \fIstring1\fP \fB=\fP \fIstring2\fP
5607 True if the strings are equal.
5608 \fB=\fP should be used with the \fBtest\fP command for
5609 .SM POSIX
5610 conformance.
5611 When used with the \fB[[\fP command, this performs pattern matching as
5612 described above (\fBCompound Commands\fP).
5613 .TP
5614 \fIstring1\fP \fB!=\fP \fIstring2\fP
5615 True if the strings are not equal.
5616 .TP
5617 \fIstring1\fP \fB<\fP \fIstring2\fP
5618 True if \fIstring1\fP sorts before \fIstring2\fP lexicographically.
5619 .TP
5620 \fIstring1\fP \fB>\fP \fIstring2\fP
5621 True if \fIstring1\fP sorts after \fIstring2\fP lexicographically.
5622 .PD
5623 .TP
5624 .PD 0
5625 \fIfile1\fP \fB\-ef\fP \fIfile2\fP
5626 True if \fIfile1\fP and \fIfile2\fP refer to the same device and
5627 inode numbers.
5628 .TP
5629 \fIfile1\fP \-\fBnt\fP \fIfile2\fP
5630 True if \fIfile1\fP is newer (according to modification date) than \fIfile2\fP,
5631 or if \fIfile1\fP exists and \fPfile2\fP does not.
5632 .TP
5633 \fIfile1\fP \-\fBot\fP \fIfile2\fP
5634 True if \fIfile1\fP is older than \fIfile2\fP, or if \fIfile2\fP exists
5635 and \fIfile1\fP does not.
5636 .PD
5637 .TP
5638 .I \fIarg1\fP \fBOP\fP \fIarg2\fP
5639 .SM
5640 .B OP
5641 is one of
5642 .BR \-eq ,
5643 .BR \-ne ,
5644 .BR \-lt ,
5645 .BR \-le ,
5646 .BR \-gt ,
5647 or
5648 .BR \-ge .
5649 These arithmetic binary operators return true if \fIarg1\fP
5650 is equal to, not equal to, less than, less than or equal to,
5651 greater than, or greater than or equal to \fIarg2\fP, respectively.
5652 .I arg1
5653 and
5654 .I arg2
5655 may be positive or negative integers.
5656 When used with the \fB[[\fP command,
5657 .I arg1
5658 and
5659 .I arg2
5660 are evaluated as arithmetic expressions (see
5661 .SM
5662 .B "ARITHMETIC EVALUATION"
5663 above).
5664 Since the expansions the \fB[[\fP command performs on
5665 .I arg1
5666 and
5667 .I arg2
5668 can potentially result in empty strings,
5669 arithmetic expression evaluation treats
5670 those as expressions that evaluate to 0.
5671 .PD
5672 .SH "SIMPLE COMMAND EXPANSION"
5673 When the shell executes a simple command, it performs the following
5674 expansions, assignments, and redirections, from left to right, in
5675 the following order.
5676 .IP 1.
5677 The words that the parser has marked as variable assignments (those
5678 preceding the command name) and redirections are saved for later
5679 processing.
5680 .IP 2.
5681 The words that are not variable assignments or redirections are
5682 expanded.
5683 If any words remain after expansion, the first word
5684 is taken to be the name of the command and the remaining words are
5685 the arguments.
5686 .IP 3.
5687 Redirections are performed as described above under
5688 .SM
5689 .BR REDIRECTION .
5690 .IP 4.
5691 The text after the \fB=\fP in each variable assignment undergoes tilde
5692 expansion, parameter expansion, command substitution, arithmetic expansion,
5693 and quote removal before being assigned to the variable.
5694 .PP
5695 If no command name results, the variable assignments affect the current
5696 shell environment.
5697 In the case of such a command (one that consists only of assignment
5698 statements and redirections), assignment statements are performed before
5699 redirections.
5700 Otherwise, the variables are added to the environment
5701 of the executed command and do not affect the current shell environment.
5702 If any of the assignments attempts to assign a value to a readonly variable,
5703 an error occurs, and the command exits with a non-zero status.
5704 .PP
5705 If no command name results, redirections are performed, but do not
5706 affect the current shell environment.
5707 A redirection error causes the command to exit with a non-zero status.
5708 .PP
5709 If there is a command name left after expansion, execution proceeds as
5710 described below.
5711 Otherwise, the command exits.
5712 If one of the expansions contained a command substitution,
5713 the exit status of the command is the exit status of
5714 the last command substitution performed.
5715 If there were no command substitutions,
5716 the command exits with a zero status.
5717 .SH "COMMAND EXECUTION"
5718 After a command has been split into words, if it results in a
5719 simple command and an optional list of arguments, the shell performs
5720 the following actions.
5721 .PP
5722 If the command name contains no slashes, the shell attempts to
5723 locate it.
5724 If there exists a shell function by that name, that function is
5725 invoked as described above in
5726 .SM
5727 .BR FUNCTIONS .
5728 If the name does not match a function, the shell searches for
5729 it in the list of shell builtins.
5730 If a match is found, that builtin is invoked.
5731 .PP
5732 If the name is neither a shell function nor a builtin,
5733 and contains no slashes,
5734 .B bash
5735 searches each element of the
5736 .SM
5737 .B PATH
5738 for a directory containing an executable file by that name.
5739 .B Bash
5740 uses a hash table to remember the full pathnames of executable
5741 files (see
5742 .B hash
5743 under
5744 .SM
5745 .B "SHELL BUILTIN COMMANDS"
5746 below).
5747 Bash performs a full search of the directories in
5748 .SM
5749 .B PATH
5750 only if the command is not found in the hash table.
5751 If the search is unsuccessful, the shell searches for a defined shell
5752 function named \fBcommand_not_found_handle\fP.
5753 If that function exists, it is invoked in a separate execution environment
5754 with the original command and
5755 the original command's arguments as its arguments, and the function's
5756 exit status becomes the exit status of that subshell.
5757 If that function is not defined, the shell prints an error
5758 message and returns an exit status of 127.
5759 .PP
5760 If the search is successful, or if the command name contains
5761 one or more slashes, the shell executes the named program in a
5762 separate execution environment.
5763 Argument 0 is set to the name given, and the remaining arguments
5764 to the command are set to the arguments given, if any.
5765 .PP
5766 If this execution fails because the file is not in executable
5767 format, and the file is not a directory, it is assumed to be
5768 a \fIshell script\fP, a file containing shell commands,
5769 and the shell creates a new instance of itself to execute it.
5770 Bash tries to determine whether the file is a text file or a binary,
5771 and will not execute files it determines to be binaries.
5772 This subshell reinitializes itself, so
5773 that the effect is as if a new shell had been invoked
5774 to handle the script, with the exception that the locations of
5775 commands remembered by the parent (see
5776 .B hash
5777 below under
5778 .SM
5779 .B "SHELL BUILTIN COMMANDS"
5780 are retained by the child.
5781 .PP
5782 If the program is a file beginning with
5783 .BR #! ,
5784 the remainder of the first line specifies an interpreter
5785 for the program.
5786 The shell executes the
5787 specified interpreter on operating systems that do not
5788 handle this executable format themselves.
5789 The arguments to the
5790 interpreter consist of a single optional argument following the
5791 interpreter name on the first line of the program, followed
5792 by the name of the program, followed by the command
5793 arguments, if any.
5794 .SH "COMMAND EXECUTION ENVIRONMENT"
5795 The shell has an \fIexecution environment\fP, which consists of the
5796 following:
5797 .IP \(bu
5798 Open files inherited by the shell at invocation, as modified by
5799 redirections supplied to the \fBexec\fP builtin.
5800 .IP \(bu
5801 The current working directory as set by \fBcd\fP, \fBpushd\fP, or
5802 \fBpopd\fP, or inherited by the shell at invocation.
5803 .IP \(bu
5804 The file creation mode mask as set by \fBumask\fP or inherited from
5805 the shell's parent.
5806 .IP \(bu
5807 Current traps set by \fBtrap\fP.
5808 .IP \(bu
5809 Shell parameters that are set by variable assignment or with \fBset\fP
5810 or inherited from the shell's parent in the environment.
5811 .IP \(bu
5812 Shell functions defined during execution or inherited from the shell's
5813 parent in the environment.
5814 .IP \(bu
5815 Options enabled at invocation (either by default or with command-line
5816 arguments) or by \fBset\fP.
5817 .IP \(bu
5818 Options enabled by \fBshopt\fP.
5819 .IP \(bu
5820 Shell aliases defined with \fBalias\fP.
5821 .IP \(bu
5822 Various process IDs, including those of background jobs, the value
5823 of \fB$$\fP, and the value of
5824 .SM
5825 .BR PPID .
5826 .PP
5827 When a simple command other than a builtin or shell function
5828 is to be executed, it
5829 is invoked in a separate execution environment that consists of
5830 the following.
5831 Unless otherwise noted, the values are inherited from the shell.
5832 .IP \(bu
5833 The shell's open files, plus any modifications and additions specified
5834 by redirections to the command.
5835 .IP \(bu
5836 The current working directory.
5837 .IP \(bu
5838 The file creation mode mask.
5839 .IP \(bu
5840 Shell variables and functions marked for export, along with variables
5841 exported for the command, passed in the environment.
5842 .IP \(bu
5843 Traps caught by the shell are reset to the values inherited from the
5844 shell's parent, and traps ignored by the shell are ignored.
5845 .PP
5846 A command invoked in this separate environment cannot affect the
5847 shell's execution environment.
5848 .PP
5849 A \fIsubshell\fP is a copy of the shell process.
5850 .PP
5851 Command substitution, commands grouped with parentheses,
5852 and asynchronous commands are invoked in a
5853 subshell environment that is a duplicate of the shell environment,
5854 except that traps caught by the shell are reset to the values
5855 that the shell inherited from its parent at invocation.
5856 Builtin commands that are invoked as part of a pipeline,
5857 except possibly in the last element depending on the value of the
5858 \fBlastpipe\fP shell option,
5859 are also executed in a subshell environment.
5860 Changes made to the subshell environment
5861 cannot affect the shell's execution environment.
5862 .PP
5863 When the shell is in posix mode,
5864 subshells spawned to execute command substitutions inherit the value of
5865 the \fB\-e\fP option from their parent shell.
5866 When not in posix mode,
5867 \fBbash\fP clears the \fB\-e\fP option in such subshells.
5868 See the
5869 description of the \fBinherit_errexit\fP shell option below
5870 for how to control this behavior when not in posix mode.
5871 .PP
5872 If a command is followed by a \fB&\fP and job control is not active, the
5873 default standard input for the command is the empty file
5874 .FN /dev/null .
5875 Otherwise, the invoked command inherits the file descriptors of the calling
5876 shell as modified by redirections.
5877 .SH ENVIRONMENT
5878 When a program is invoked it is given an array of strings
5879 called the
5880 .IR environment .
5881 This is a list of
5882 \fIname\fP\-\fIvalue\fP pairs, of the form
5883 .IR "name\fR=\fPvalue" .
5884 .PP
5885 The shell provides several ways to manipulate the environment.
5886 On invocation, the shell scans its own environment and
5887 creates a parameter for each name found, automatically marking
5888 it for
5889 .I export
5890 to child processes.
5891 Executed commands inherit the environment.
5892 The
5893 .BR export ,
5894 .BR "declare \-x" ,
5895 and
5896 .B unset
5897 commands modify the environment by
5898 adding and deleting parameters and functions.
5899 If the value of a parameter
5900 in the environment is modified, the new value automatically
5901 becomes part of the environment, replacing the old.
5902 The environment
5903 inherited by any executed command consists of the shell's
5904 initial environment, whose values may be modified in the shell,
5905 less any pairs removed by the
5906 .B unset
5907 or
5908 .B "export \-n"
5909 commands, plus any additions via the
5910 .B export
5911 and
5912 .B "declare \-x"
5913 commands.
5914 .PP
5915 If any parameter assignments, as described above in
5916 .SM
5917 .BR PARAMETERS ,
5918 appear before a
5919 .IR "simple command" ,
5920 the variable assignments are part of that command's environment
5921 for as long as it executes.
5922 These assignment statements affect only the environment seen
5923 by that command.
5924 If these assignments precede a call to a shell function, the variables
5925 are local to the function and exported to that function's children.
5926 .PP
5927 If the
5928 .B \-k
5929 option is set (see the
5930 .B set
5931 builtin command below), then
5932 .I all
5933 parameter assignments are placed in the environment for a command,
5934 not just those that precede the command name.
5935 .PP
5936 When
5937 .B bash
5938 invokes an external command, the variable
5939 .B _
5940 is set to the full pathname of the command and passed to that
5941 command in its environment.
5942 .SH "EXIT STATUS"
5943 The exit status of an executed command is the value returned by the
5944 \fIwaitpid\fP system call or equivalent function.
5945 Exit statuses fall between 0 and 255, though, as explained below,
5946 the shell may use values above 125 specially.
5947 Exit statuses from shell builtins and compound commands are also
5948 limited to this range.
5949 Under certain circumstances, the shell will use special values to
5950 indicate specific failure modes.
5951 .PP
5952 For the shell's purposes, a command which exits with a
5953 zero exit status has succeeded.
5954 So while an exit status of zero indicates success, a non-zero
5955 exit status indicates failure.
5956 .PP
5957 When a command terminates on a fatal signal \fIN\fP, \fBbash\fP uses
5958 the value of 128+\fIN\fP as the exit status.
5959 .PP
5960 If a command is not found, the child process created to
5961 execute it returns a status of 127. If a command is found
5962 but is not executable, the return status is 126.
5963 .PP
5964 If a command fails because of an error during expansion or redirection,
5965 the exit status is greater than zero.
5966 .PP
5967 Shell builtin commands return a status of 0 (\fItrue\fP) if
5968 successful, and non-zero (\fIfalse\fP) if an error occurs
5969 while they execute.
5970 All builtins return an exit status of 2 to indicate incorrect usage,
5971 generally invalid options or missing arguments.
5972 .PP
5973 The exit status of the last command is available in the special
5974 parameter $?.
5975 .PP
5976 \fBBash\fP itself returns the exit status of the last command
5977 executed, unless a syntax error occurs, in which case it exits
5978 with a non-zero value.
5979 See also the \fBexit\fP builtin command below.
5980 .SH SIGNALS
5981 When \fBbash\fP is interactive, in the absence of any traps, it ignores
5982 .SM
5983 .B SIGTERM
5984 (so that \fBkill 0\fP does not kill an interactive shell),
5985 and catches and handles
5986 .SM
5987 .B SIGINT
5988 (so that the \fBwait\fP builtin is interruptible).
5989 When \fBbash\fP receives
5990 .SM
5991 .BR SIGINT ,
5992 it breaks out of any executing loops.
5993 In all cases, \fBbash\fP ignores
5994 .SM
5995 .BR SIGQUIT .
5996 If job control is in effect,
5997 .B bash
5998 ignores
5999 .SM
6000 .BR SIGTTIN ,
6001 .SM
6002 .BR SIGTTOU ,
6003 and
6004 .SM
6005 .BR SIGTSTP .
6006 .PP
6007 The \fBtrap\fP builtin modifies the shell's signal handling, as
6008 described below.
6009 .PP
6010 Non-builtin commands \fBbash\fP executes have signal handlers
6011 set to the values inherited by the shell from its parent,
6012 unless \fBtrap\fP sets them to be ignored, in which case the child
6013 process will ignore them as well.
6014 When job control is not in effect, asynchronous commands
6015 ignore
6016 .SM
6017 .B SIGINT
6018 and
6019 .SM
6020 .B SIGQUIT
6021 in addition to these inherited handlers.
6022 Commands run as a result of command substitution ignore the
6023 keyboard-generated job control signals
6024 .SM
6025 .BR SIGTTIN ,
6026 .SM
6027 .BR SIGTTOU ,
6028 and
6029 .SM
6030 .BR SIGTSTP .
6031 .PP
6032 The shell exits by default upon receipt of a
6033 .SM
6034 .BR SIGHUP .
6035 Before exiting, an interactive shell resends the
6036 .SM
6037 .B SIGHUP
6038 to all jobs, running or stopped.
6039 The shell sends
6040 .SM
6041 .B SIGCONT
6042 to stopped jobs to ensure that they receive the
6043 .SM
6044 .B SIGHUP
6045 (see
6046 .SM
6047 .B "JOB CONTROL"
6048 below for more information about running and stopped jobs).
6049 To prevent the shell from
6050 sending the signal to a particular job, remove it from the
6051 jobs table with the
6052 .B disown
6053 builtin (see
6054 .SM
6055 .B "SHELL BUILTIN COMMANDS"
6056 below) or mark it not to receive
6057 .SM
6058 .B SIGHUP
6059 using
6060 .BR "disown \-h" .
6061 .PP
6062 If the
6063 .B huponexit
6064 shell option has been set using
6065 .BR shopt ,
6066 .B bash
6067 sends a
6068 .SM
6069 .B SIGHUP
6070 to all jobs when an interactive login shell exits.
6071 .PP
6072 If \fBbash\fP is waiting for a command to complete and receives a signal
6073 for which a trap has been set,
6074 it will not execute the trap until the command completes.
6075 If \fBbash\fP is waiting for an asynchronous command via the \fBwait\fP
6076 builtin,
6077 and it receives a signal for which a trap has been set,
6078 the \fBwait\fP builtin will return immediately with an exit status
6079 greater than 128, immediately after which the shell executes the trap.
6080 .PP
6081 When job control is not enabled, and \fBbash\fP is waiting for a foreground
6082 command to complete, the shell receives keyboard-generated signals
6083 such as
6084 .SM
6085 .B SIGINT
6086 (usually generated by \fB\*^C\fP) that users commonly intend to send
6087 to that command.
6088 This happens because the shell and the command are in the
6089 same process group as the terminal, and \fB\*^C\fP sends
6090 .SM
6091 .B SIGINT
6092 to all processes in that process group.
6093 Since \fBbash\fP does not enable job control by default when the
6094 shell is not interactive,
6095 this scenario is most common in non-interactive shells.
6096 .PP
6097 When job control is enabled, and \fBbash\fP is waiting for a foreground
6098 command to complete, the shell does not receive keyboard-generated
6099 signals, because it is not in the same process group as the terminal.
6100 This scenario is most common in interactive shells, where \fBbash\fP
6101 attempts to enable job control by default.
6102 See
6103 .SM
6104 .B "JOB CONTROL"
6105 below for more information about process groups.
6106 .PP
6107 When job control is not enabled, and \fBbash\fP receives
6108 .SM
6109 .B SIGINT
6110 while waiting for a foreground command, it waits until that foreground
6111 command terminates and then decides what to do about the
6112 .SM
6113 .BR SIGINT :
6114 .IP 1.
6115 If the command terminates due to the
6116 .SM
6117 .BR SIGINT ,
6118 \fBbash\fP concludes
6119 that the user meant to send the
6120 .SM
6121 .B SIGINT
6122 to the shell as well, and acts on the
6123 .SM
6124 .B SIGINT
6125 (e.g., by running a
6126 .SM
6127 .B SIGINT
6128 trap,
6129 exiting a non-interactive shell,
6130 or returning to the top level to read a new command).
6131 .IP 2.
6132 If the command does not terminate due to
6133 .SM
6134 .BR SIGINT ,
6135 the program handled the
6136 .SM
6137 .B SIGINT
6138 itself and did not treat it as a fatal signal.
6139 In that case, \fBbash\fP does not treat
6140 .SM
6141 .B SIGINT
6142 as a fatal signal, either, instead assuming that the
6143 .SM
6144 .B SIGINT
6145 was used as part of the program's normal operation
6146 (e.g., emacs uses it to abort editing
6147 commands) or deliberately discarded.
6148 However, \fBbash\fP will run any
6149 trap set on
6150 .SM
6151 .BR SIGINT ,
6152 as it does with any other trapped signal it
6153 receives while it is waiting for the foreground command to
6154 complete, for compatibility.
6155 .PP
6156 When job control is enabled, \fBbash\fP does not receive keyboard-generated
6157 signals such as
6158 .SM
6159 .B SIGINT
6160 while it is waiting for a foreground command.
6161 An interactive shell does not pay attention to the
6162 .SM
6163 .BR SIGINT ,
6164 even if the foreground command terminates as a result, other than noting
6165 its exit status.
6166 If the shell is not interactive, and
6167 the foreground command terminates due to the
6168 .SM
6169 .BR SIGINT ,
6170 \fBbash\fP pretends it received the
6171 .SM
6172 .B SIGINT
6173 itself (scenario 1 above), for compatibility.
6174 .SH "JOB CONTROL"
6175 .I Job control
6176 refers to the ability to selectively stop (\fIsuspend\fP)
6177 the execution of processes and continue (\fIresume\fP)
6178 their execution at a later point.
6179 A user typically employs
6180 this facility via an interactive interface supplied jointly
6181 by the operating system kernel's terminal driver and
6182 .BR bash .
6183 .PP
6184 The shell associates a
6185 .I job
6186 with each pipeline.
6187 It keeps a table of currently executing
6188 jobs, which the
6189 .B jobs
6190 command will display.
6191 Each job has a \fIjob number\fP, which \fBjobs\fP displays between brackets.
6192 Job numbers start at 1.
6193 When
6194 .B bash
6195 starts a job asynchronously (in the
6196 .IR background ),
6197 it prints a line that looks like:
6198 .RS
6199 .PP
6200 [1] 25647
6201 .RE
6202 .PP
6203 indicating that this job is job number 1 and that the process ID
6204 of the last process in the pipeline associated with this job is 25647.
6205 All of the processes in a single pipeline are members of the same job.
6206 .B Bash
6207 uses the
6208 .I job
6209 abstraction as the basis for job control.
6210 .PP
6211 To facilitate the implementation of the user interface to job control,
6212 each process has a \fIprocess group ID\fP, and
6213 the operating system maintains the notion of a \fIcurrent terminal
6214 process group ID\fP.
6215 This terminal process group ID is associated with the
6216 \fIcontrolling terminal\fP.
6217 .PP
6218 Processes that have the same process group ID are said to be part of
6219 the same \fIprocess group\fP.
6220 Members of the \fIforeground\fP process group (processes whose
6221 process group ID is equal to the current terminal process group ID)
6222 receive keyboard-generated signals such as
6223 .SM
6224 .BR SIGINT .
6225 Processes in the foreground process group are said to be
6226 .I foreground
6227 processes.
6228 .I Background
6229 processes are those whose process group ID differs from the
6230 controlling terminal's;
6231 such processes are immune to keyboard-generated signals.
6232 Only foreground processes are allowed to read from or,
6233 if the user so specifies with
6234 .Q "stty tostop" ,
6235 write to the controlling terminal.
6236 The system sends a
6237 .SM
6238 .B "SIGTTIN (SIGTTOU)"
6239 signal to background processes which attempt to
6240 read from (write to when
6241 .Q tostop
6242 is in effect)
6243 the terminal,
6244 which, unless caught, suspends the process.
6245 .PP
6246 If the operating system on which
6247 .B bash
6248 is running supports
6249 job control,
6250 .B bash
6251 contains facilities to use it.
6252 Typing the
6253 .I suspend
6254 character (typically
6255 .BR \*^Z ,
6256 Control-Z) while a process is running
6257 stops that process and returns control to
6258 .BR bash .
6259 Typing the
6260 .I "delayed suspend"
6261 character (typically
6262 .BR \*^Y ,
6263 Control-Y) causes the process stop when it
6264 attempts to read input from the terminal, and returns control to
6265 .BR bash .
6266 The user then manipulates the state of this job, using the
6267 .B bg
6268 command to continue it in the background, the
6269 .B fg
6270 command to continue it in the foreground, or the
6271 .B kill
6272 command to kill it.
6273 The suspend character takes effect immediately,
6274 and has the additional side effect of discarding any pending output
6275 and typeahead.
6276 To force a background process to stop, or stop a process
6277 that's not associated with the current terminal session,
6278 send it the
6279 .SM
6280 .B SIGSTOP
6281 signal using \fBkill\fP.
6282 .PP
6283 There are a number of ways to refer to a job in the shell.
6284 The
6285 .B %
6286 character introduces a job specification (jobspec).
6287 .PP
6288 Job number
6289 .I n
6290 may be referred to as
6291 .BR %n .
6292 A job may also be referred to using a prefix of the name used to
6293 start it, or using a substring that appears in its command line.
6294 For example,
6295 .B %ce
6296 refers to a job whose command name begins with
6297 .BR ce .
6298 Using
6299 .BR %?ce ,
6300 on the other hand, refers to any job containing the string
6301 .B ce
6302 in its command line.
6303 If the prefix or substring matches more than one job,
6304 .B bash
6305 reports an error.
6306 .PP
6307 The symbols
6308 .B %%
6309 and
6310 .B %+
6311 refer to the shell's notion of the
6312 .IR "current job" .
6313 A single % (with no accompanying job specification) also refers to the
6314 current job.
6315 .B %\-
6316 refers to the
6317 .IR "previous job" .
6318 When a job starts in the background,
6319 a job stops while in the foreground,
6320 or a job is resumed in the background,
6321 it becomes the current job.
6322 The job that was the current job becomes the previous job.
6323 When the current job terminates, the previous job becomes the
6324 current job.
6325 If there is only a single job, \fB%+\fP and \fB%\-\fP can both be used
6326 to refer to that job.
6327 In output pertaining to jobs (e.g., the output of the
6328 .B jobs
6329 command), the current job is always marked with a
6330 .BR + ,
6331 and the previous job with a
6332 .BR \- .
6333 .PP
6334 Simply naming a job can be used to bring it into the foreground:
6335 .B %1
6336 is a synonym for
6337 .Q "fg %1" ,
6338 bringing job 1 from the background into the foreground.
6339 Similarly,
6340 .Q "%1 &"
6341 resumes job 1 in the background, equivalent to
6342 .Q "bg %1" .
6343 .PP
6344 The shell learns immediately whenever a job changes state.
6345 Normally,
6346 .B bash
6347 waits until it is about to print a prompt before
6348 notifying the user about
6349 changes in a job's status so as to not interrupt
6350 any other output,
6351 though it will notify of changes in a job's status after a
6352 foreground command in
6353 a list completes, before executing the next command in the list.
6354 If the
6355 .B \-b
6356 option to the
6357 .B set
6358 builtin command
6359 is enabled,
6360 .B bash
6361 reports status changes immediately.
6362 \fBBash\fP executes any trap on
6363 .SM
6364 .B SIGCHLD
6365 for each child that terminates.
6366 .PP
6367 When a job terminates and \fBbash\fP notifies the user about it,
6368 \fBbash\fP removes the job from the table.
6369 It will not appear in \fBjobs\fP output, but \fBwait\fP will
6370 report its exit status, as long as it's supplied the process ID
6371 associated with the job as an argument.
6372 When the table is empty, job numbers start over at 1.
6373 .PP
6374 If a user attempts to exit
6375 .B bash
6376 while jobs are stopped (or, if the \fBcheckjobs\fP shell option has
6377 been enabled using the \fBshopt\fP builtin, running), the shell prints a
6378 warning message, and, if the \fBcheckjobs\fP option is enabled, lists the
6379 jobs and their statuses.
6380 The
6381 .B jobs
6382 command may then be used to inspect their status.
6383 If the user immediately attempts to exit again,
6384 without an intervening command,
6385 \fBbash\fP does not print another warning, and
6386 terminates any stopped jobs.
6387 .PP
6388 When the shell is waiting for a job or process using the \fBwait\fP
6389 builtin, and job control is enabled, \fBwait\fP will return when the
6390 job changes state.
6391 The \fB\-f\fP option causes \fBwait\fP to wait
6392 until the job or process terminates before returning.
6393 .SH PROMPTING
6394 When executing interactively,
6395 .B bash
6396 displays the primary prompt
6397 .SM
6398 .B PS1
6399 when it is ready to read a command, and the secondary prompt
6400 .SM
6401 .B PS2
6402 when it needs more input to complete a command.
6403 .PP
6404 .B Bash
6405 examines the value of the array variable \fBPROMPT_COMMAND\fP just before
6406 printing each primary prompt.
6407 If any elements in \fBPROMPT_COMMAND\fP are set and non-null, Bash
6408 executes each value, in numeric order,
6409 just as if it had been typed on the command line.
6410 .B Bash
6411 displays
6412 .SM
6413 .B PS0
6414 after it reads a command but before executing it.
6415 .PP
6416 .B Bash
6417 displays
6418 .SM
6419 .B PS4
6420 as described above
6421 before tracing each command when the \fB\-x\fP option is enabled.
6422 .PP
6423 .B Bash
6424 allows the prompt strings
6425 \fBPS0\fP, \fBPS1\fP, \fBPS2\fP, and \fBPS4\fP,
6426 to be customized by inserting a number of
6427 backslash-escaped special characters that are decoded as follows:
6428 .RS
6429 .TP
6430 .B \ea
6431 An ASCII bell character (07).
6432 .PD 0
6433 .TP
6434 .B \ed
6435 The date in
6436 .Q "Weekday Month Date"
6437 format (e.g.,
6438 .Q "Tue May 26" ).
6439 .TP
6440 .B \eD{\fIformat\fP}
6441 The \fIformat\fP is passed to
6442 .IR strftime (3)
6443 and the result is inserted
6444 into the prompt string; an empty \fIformat\fP results in a locale-specific
6445 time representation.
6446 The braces are required.
6447 .TP
6448 .B \ee
6449 An ASCII escape character (033).
6450 .TP
6451 .B \eh
6452 The hostname up to the first
6453 .Q . .
6454 .TP
6455 .B \eH
6456 The hostname.
6457 .TP
6458 .B \ej
6459 The number of jobs currently managed by the shell.
6460 .TP
6461 .B \el
6462 The basename of the shell's terminal device name (e.g.,
6463 .Q ttys0 ).
6464 .TP
6465 .B \en
6466 A newline.
6467 .TP
6468 .B \er
6469 A carriage return.
6470 .TP
6471 .B \es
6472 The name of the shell: the basename of
6473 .B $0
6474 (the portion following the final slash).
6475 .TP
6476 .B \et
6477 The current time in 24-hour HH:MM:SS format.
6478 .TP
6479 .B \eT
6480 The current time in 12-hour HH:MM:SS format.
6481 .TP
6482 .B \e@
6483 The current time in 12-hour am/pm format.
6484 .TP
6485 .B \eA
6486 The current time in 24-hour HH:MM format.
6487 .TP
6488 .B \eu
6489 The username of the current user.
6490 .TP
6491 .B \ev
6492 The \fBbash\fP version (e.g., 2.00).
6493 .TP
6494 .B \eV
6495 The \fBbash\fP release, version + patch level (e.g., 2.00.0)
6496 .TP
6497 .B \ew
6498 The value of the \fBPWD\fP shell variable (\fB$PWD\fP),
6499 with
6500 .SM
6501 .B $HOME
6502 abbreviated with a tilde
6503 (uses the value of the
6504 .SM
6505 .B PROMPT_DIRTRIM
6506 variable).
6507 .TP
6508 .B \eW
6509 The basename of \fB$PWD\fP,
6510 with
6511 .SM
6512 .B $HOME
6513 abbreviated with a tilde.
6514 .TP
6515 .B \e!
6516 The history number of this command.
6517 .TP
6518 .B \e#
6519 The command number of this command.
6520 .TP
6521 .B \e$
6522 If the effective UID is 0, a
6523 .BR # ,
6524 otherwise a
6525 .BR $ .
6526 .TP
6527 .B \e\fInnn\fP
6528 The character corresponding to the octal number \fInnn\fP.
6529 .TP
6530 .B \e\e
6531 A backslash.
6532 .TP
6533 .B \e[
6534 Begin a sequence of non-printing characters, which could be used to
6535 embed a terminal control sequence into the prompt.
6536 .TP
6537 .B \e]
6538 End a sequence of non-printing characters.
6539 .PD
6540 .RE
6541 .PP
6542 The command number and the history number are usually different:
6543 the history number of a command is its position in the history
6544 list, which may include commands restored from the history file
6545 (see
6546 .SM
6547 .B HISTORY
6548 below), while the command number is the position in the sequence
6549 of commands executed during the current shell session.
6550 After the string is decoded, it is expanded via
6551 parameter expansion, command substitution, arithmetic
6552 expansion, and quote removal, subject to the value of the
6553 .B promptvars
6554 shell option (see the description of the
6555 .B shopt
6556 command under
6557 .SM
6558 .B "SHELL BUILTIN COMMANDS"
6559 below).
6560 This can have unwanted side effects if escaped portions of the string
6561 appear within command substitution or contain characters special to
6562 word expansion.
6563 .SH READLINE
6564 This is the library that handles reading input when using an interactive
6565 shell, unless the
6566 .B \-\-noediting
6567 option is supplied at shell invocation.
6568 Line editing is also used when using the \fB\-e\fP option to the
6569 \fBread\fP builtin.
6570 By default, the line editing commands are similar to those of emacs;
6571 a vi-style line editing interface is also available.
6572 Line editing can be enabled at any time using the
6573 .B \-o emacs
6574 or
6575 .B \-o vi
6576 options to the
6577 .B set
6578 builtin (see
6579 .SM
6580 .B "SHELL BUILTIN COMMANDS"
6581 below).
6582 To turn off line editing after the shell is running, use the
6583 .B +o emacs
6584 or
6585 .B +o vi
6586 options to the
6587 .B set
6588 builtin.
6589 .SS "Readline Notation"
6590 This section uses Emacs-style editing concepts and uses its
6591 notation for keystrokes.
6592 Control keys are denoted by C\-\fIkey\fP, e.g., C\-n means Control\-N.
6593 Similarly,
6594 .I meta
6595 keys are denoted by M\-\fIkey\fP, so M\-x means Meta\-X.
6596 The Meta key is often labeled
6597 .Q Alt
6598 or
6599 .Q Option .
6600 .PP
6601 On keyboards without a
6602 .I Meta
6603 key, M\-\fIx\fP means ESC \fIx\fP,
6604 i.e., press and release the Escape key,
6605 then press and release the
6606 .I x
6607 key, in sequence.
6608 This makes ESC the \fImeta prefix\fP.
6609 The combination M\-C\-\fIx\fP means ESC Control\-\fIx\fP:
6610 press and release the Escape key,
6611 then press and hold the Control key while pressing the
6612 .I x
6613 key, then release both.
6614 .PP
6615 On some keyboards, the Meta key modifier produces characters with
6616 the eighth bit (0200) set.
6617 You can use the \fBenable\-meta\-key\fP variable
6618 to control whether or not it does this, if the keyboard allows it.
6619 On many others, the terminal or terminal emulator converts the metafied
6620 key to a key sequence beginning with ESC as described in the
6621 preceding paragraph.
6622 .PP
6623 If your \fIMeta\fP key produces a key sequence with the ESC meta prefix,
6624 you can make M-\fIkey\fP key bindings you specify (see
6625 .B "Readline Key Bindings"
6626 below) do the same thing by setting the \fBforce\-meta\-prefix\fP variable.
6627 .PP
6628 .B Readline
6629 commands may be given numeric
6630 .IR arguments ,
6631 which normally act as a repeat count.
6632 Sometimes, however, it is the sign of the argument that is significant.
6633 Passing a negative argument
6634 to a command that acts in the forward direction (e.g., \fBkill\-line\fP)
6635 makes that command act in a backward direction.
6636 Commands whose behavior with arguments deviates from this are noted
6637 below.
6638 .PP
6639 The \fIpoint\fP is the current cursor position, and \fImark\fP refers
6640 to a saved cursor position.
6641 The text between the point and mark is referred to as the \fIregion\fP.
6642 \fBReadline\fP has the concept of an \fIactive region\fP:
6643 when the region is active, \fBreadline\fP redisplay
6644 highlights the region using the
6645 value of the \fBactive-region-start-color\fP variable.
6646 The \fBenable\-active\-region\fP variable turns this on and off.
6647 Several commands set the region to active; those are noted below.
6648 .PP
6649 When a command is described as \fIkilling\fP text, the text
6650 deleted is saved for possible future retrieval
6651 (\fIyanking\fP).
6652 The killed text is saved in a \fIkill ring\fP.
6653 Consecutive kills accumulate the deleted text
6654 into one unit, which can be yanked all at once.
6655 Commands which do not kill text separate the chunks of text
6656 on the kill ring.
6657 .SS "Readline Initialization"
6658 .B Readline
6659 is customized by putting commands in an initialization
6660 file (the \fIinputrc\fP file).
6661 The name of this file is taken from the value of the
6662 .SM
6663 .B \%INPUTRC
6664 shell variable.
6665 If that variable is unset, the default is
6666 .FN \*~/.inputrc .
6667 If that file does not exist or cannot be read, \fBreadline\fP looks for
6668 .FN /etc/inputrc .
6669 When a program that uses the \fBreadline\fP library starts up,
6670 \fBreadline\fP reads the initialization file
6671 and sets the key bindings and variables found there,
6672 before reading any user input.
6673 .PP
6674 There are only a few basic constructs allowed in the inputrc file.
6675 Blank lines are ignored.
6676 Lines beginning with a \fB#\fP are comments.
6677 Lines beginning with a \fB$\fP indicate conditional constructs.
6678 Other lines denote key bindings and variable settings.
6679 .PP
6680 The default key-bindings in this section
6681 may be changed using key binding commands in the
6682 .I inputrc
6683 file.
6684 Programs that use the \fBreadline\fP library, including \fBbash\fP,
6685 may add their own commands and bindings.
6686 .PP
6687 For example, placing
6688 .RS
6689 .PP
6690 M\-Control\-u: universal\-argument
6691 .RE
6692 or
6693 .RS
6694 C\-Meta\-u: universal\-argument
6695 .RE
6696 .LP
6697 into the
6698 .I inputrc
6699 would make M\-C\-u execute the \fBreadline\fP command
6700 .IR universal\-argument .
6701 .PP
6702 Key bindings may contain the following symbolic character names:
6703 .IR DEL ,
6704 .IR ESC ,
6705 .IR ESCAPE ,
6706 .IR LFD ,
6707 .IR NEWLINE ,
6708 .IR RET ,
6709 .IR RETURN ,
6710 .I RUBOUT
6711 (a destructive backspace),
6712 .IR SPACE ,
6713 .IR SPC ,
6714 and
6715 .IR TAB .
6716 .PP
6717 In addition to command names, \fBreadline\fP allows keys to be bound
6718 to a string that is inserted when the key is pressed (a \fImacro\fP).
6719 The difference between a macro and a command is that a macro is
6720 enclosed in single or double quotes.
6721 .SS "Readline Key Bindings"
6722 The syntax for controlling key bindings in the
6723 .I inputrc
6724 file is simple.
6725 All that is required is the name of the command or the text of a macro
6726 and a key sequence to which it should be bound.
6727 The key sequence may be specified in one of two ways:
6728 as a symbolic key name,
6729 possibly with \fIMeta\-\fP or \fIControl\-\fP prefixes,
6730 or as a key sequence composed of one or more characters
6731 enclosed in double quotes.
6732 The key sequence and name are separated by a colon.
6733 There can be no whitespace between the name and the colon.
6734 .PP
6735 When using the form \fBkeyname\fP:\^\fIfunction\-name\fP or \fImacro\fP,
6736 .I keyname
6737 is the name of a key spelled out in English. For example:
6738 .PP
6739 .RS
6740 .EX
6741 .nf
6742 Control-u: universal\-argument
6743 Meta-Rubout: backward\-kill\-word
6744 Control-o: \*"> output\*"
6745 .fi
6746 .EE
6747 .RE
6748 .LP
6749 In the above example,
6750 .I C\-u
6751 is bound to the function
6752 .BR universal\-argument ,
6753 .I M\-DEL
6754 is bound to the function
6755 .BR backward\-kill\-word ,
6756 and
6757 .I C\-o
6758 is bound to run the macro
6759 expressed on the right hand side (that is, to insert the text
6760 .Q "> output"
6761 into the line).
6762 .PP
6763 In the second form,
6764 \fB\*"keyseq\*"\fP:\^\fIfunction\-name\fP or \fImacro\fP,
6765 .B keyseq
6766 differs from
6767 .B keyname
6768 above in that strings denoting
6769 an entire key sequence may be specified by placing the sequence
6770 within double quotes.
6771 Some GNU Emacs style key escapes can be
6772 used, as in the following example, but none of
6773 the symbolic character names are recognized.
6774 .PP
6775 .RS
6776 .EX
6777 .nf
6778 \*"\eC\-u\*": universal\-argument
6779 \*"\eC\-x\eC\-r\*": re\-read\-init\-file
6780 \*"\ee[11\*~\*": \*"Function Key 1\*"
6781 .fi
6782 .EE
6783 .RE
6784 .PP
6785 In this example,
6786 .I C\-u
6787 is again bound to the function
6788 .BR universal\-argument .
6789 .I "C\-x C\-r"
6790 is bound to the function
6791 .BR re\-read\-init\-file ,
6792 and
6793 .I "ESC [ 1 1 \*~"
6794 is bound to insert the text
6795 .Q "Function Key 1" .
6796 .PP
6797 The full set of GNU Emacs style escape sequences available when specifying
6798 key sequences is
6799 .RS
6800 .PD 0
6801 .TP
6802 .B \eC\-
6803 A control prefix.
6804 .TP
6805 .B \eM\-
6806 Adding the meta prefix or converting the following character to a meta
6807 character, as described below under \fBforce-meta-prefix\fP.
6808 .TP
6809 .B \ee
6810 An escape character.
6811 .TP
6812 .B \e\e
6813 Backslash.
6814 .TP
6815 .B \e\*"
6816 Literal \*", a double quote.
6817 .TP
6818 .B \e\*'
6819 Literal \*', a single quote.
6820 .RE
6821 .PD
6822 .PP
6823 In addition to the GNU Emacs style escape sequences, a second
6824 set of backslash escapes is available:
6825 .RS
6826 .PD 0
6827 .TP
6828 .B \ea
6829 alert (bell)
6830 .TP
6831 .B \eb
6832 backspace
6833 .TP
6834 .B \ed
6835 delete
6836 .TP
6837 .B \ef
6838 form feed
6839 .TP
6840 .B \en
6841 newline
6842 .TP
6843 .B \er
6844 carriage return
6845 .TP
6846 .B \et
6847 horizontal tab
6848 .TP
6849 .B \ev
6850 vertical tab
6851 .TP
6852 .B \e\fInnn\fP
6853 The eight-bit character whose value is the octal value \fInnn\fP
6854 (one to three digits).
6855 .TP
6856 .B \ex\fIHH\fP
6857 The eight-bit character whose value is the hexadecimal value \fIHH\fP
6858 (one or two hex digits).
6859 .RE
6860 .PD
6861 .PP
6862 When entering the text of a macro, single or double quotes must
6863 be used to indicate a macro definition.
6864 Unquoted text is assumed to be a function name.
6865 The backslash escapes described above are expanded
6866 in the macro body.
6867 Backslash quotes any other character in the macro text,
6868 including \*" and \*'.
6869 .PP
6870 .B Bash
6871 will display or modify the current \fBreadline\fP key bindings with the
6872 .B bind
6873 builtin command.
6874 The
6875 .B \-o emacs
6876 or
6877 .B \-o vi
6878 options to the
6879 .B set
6880 builtin
6881 (see
6882 .SM
6883 .B "SHELL BUILTIN COMMANDS"
6884 below)
6885 change the editing mode during interactive use.
6886 .SS "Readline Variables"
6887 \fBReadline\fP has variables that can be used to further customize its
6888 behavior.
6889 A variable may be set in the
6890 .I inputrc
6891 file with a statement of the form
6892 .RS
6893 .PP
6894 \fBset\fP \fIvariable\-name\fP \fIvalue\fP
6895 .RE
6896 or using the \fBbind\fP builtin command (see
6897 .SM
6898 .B "SHELL BUILTIN COMMANDS"
6899 below).
6900 .PP
6901 Except where noted, \fBreadline\fP variables can take the values
6902 .B On
6903 or
6904 .B Off
6905 (without regard to case).
6906 Unrecognized variable names are ignored.
6907 When \fBreadline\fP reads a variable value, empty or null values,
6908 .Q "on"
6909 (case-insensitive), and
6910 .Q 1
6911 are equivalent to \fBOn\fP.
6912 All other values are equivalent to
6913 \fBOff\fP.
6914 .PP
6915 The \fBbind \-V\fP command lists the current \fBreadline\fP variable names
6916 and values (see
6917 .SM
6918 .B "SHELL BUILTIN COMMANDS"
6919 below).
6920 .PP
6921 The variables and their default values are:
6922 .PP
6923 .PD 0
6924 .TP
6925 .B active\-region\-start\-color
6926 A string variable that controls the text color and background when displaying
6927 the text in the active region (see the description of
6928 \fBenable\-active\-region\fP below).
6929 This string must not take up any physical character positions on the display,
6930 so it should consist only of terminal escape sequences.
6931 It is output to the terminal before displaying the text in the active region.
6932 This variable is reset to the default value whenever the terminal type changes.
6933 The default value is the string that puts the terminal in standout mode,
6934 as obtained from the terminal's terminfo description.
6935 A sample value might be
6936 .Q \ee[01;33m .
6937 .TP
6938 .B active\-region\-end\-color
6939 A string variable that
6940 .Q undoes
6941 the effects of \fBactive\-region\-start\-color\fP
6942 and restores
6943 .Q normal
6944 terminal display appearance after displaying text in the active region.
6945 This string must not take up any physical character positions on the display,
6946 so it should consist only of terminal escape sequences.
6947 It is output to the terminal after displaying the text in the active region.
6948 This variable is reset to the default value whenever the terminal type changes.
6949 The default value is the string that restores the terminal from standout mode,
6950 as obtained from the terminal's terminfo description.
6951 A sample value might be
6952 .Q \ee[0m .
6953 .TP
6954 .B bell\-style (audible)
6955 Controls what happens when \fBreadline\fP wants to ring the terminal bell.
6956 If set to \fBnone\fP, \fBreadline\fP never rings the bell.
6957 If set to \fBvisible\fP, \fBreadline\fP uses a visible bell if one is available.
6958 If set to \fBaudible\fP, \fBreadline\fP attempts to ring the terminal's bell.
6959 .TP
6960 .B bind\-tty\-special\-chars (On)
6961 If set to \fBOn\fP, \fBreadline\fP attempts to bind
6962 the control characters that are treated specially by the kernel's
6963 terminal driver to their \fBreadline\fP equivalents.
6964 These override the default \fBreadline\fP bindings described here.
6965 Type
6966 .Q "stty \-a"
6967 at a \fBbash\fP prompt to see your current terminal settings,
6968 including the special control characters (usually \fBcchars\fP).
6969 .TP
6970 .B blink\-matching\-paren (Off)
6971 If set to \fBOn\fP, \fBreadline\fP attempts to briefly move the cursor to an
6972 opening parenthesis when a closing parenthesis is inserted.
6973 .TP
6974 .B colored\-completion\-prefix (Off)
6975 If set to \fBOn\fP, when listing completions, \fBreadline\fP displays the
6976 common prefix of the set of possible completions using a different color.
6977 The color definitions are taken from the value of the \fBLS_COLORS\fP
6978 environment variable.
6979 If there is a color definition in \fB$LS_COLORS\fP for the custom suffix
6980 .Q .readline-colored-completion-prefix ,
6981 \fBreadline\fP uses this color for
6982 the common prefix instead of its default.
6983 .TP
6984 .B colored\-stats (Off)
6985 If set to \fBOn\fP, \fBreadline\fP displays possible completions using different
6986 colors to indicate their file type.
6987 The color definitions are taken from the value of the \fBLS_COLORS\fP
6988 environment variable.
6989 .\" Tucking multiple macro calls into a paragraph tag requires some
6990 .\" finesse. We require `\c`, and while the single-font macros don't
6991 .\" honor input trap continuation, the font alternation macros do.
6992 .TP
6993 .BR comment\-begin\ ( \c
6994 .Q \fB#\fP \fB)\fP
6995 The string that the \fBreadline\fP
6996 .B insert\-comment
6997 command inserts.
6998 This command is bound to
6999 .B M\-#
7000 in emacs mode and to
7001 .B #
7002 in vi command mode.
7003 .TP
7004 .B completion\-display\-width (\-1)
7005 The number of screen columns used to display possible matches
7006 when performing completion.
7007 The value is ignored if it is less than 0 or greater than the terminal
7008 screen width.
7009 A value of 0 causes matches to be displayed one per line.
7010 The default value is \-1.
7011 .TP
7012 .B completion\-ignore\-case (Off)
7013 If set to \fBOn\fP, \fBreadline\fP performs filename matching and completion
7014 in a case\-insensitive fashion.
7015 .TP
7016 .B completion\-map\-case (Off)
7017 If set to \fBOn\fP, and \fBcompletion\-ignore\-case\fP is enabled,
7018 .B readline
7019 treats hyphens (\fI\-\fP) and underscores (\fI_\fP) as equivalent when
7020 performing case\-insensitive filename matching and completion.
7021 .TP
7022 .B completion\-prefix\-display\-length (0)
7023 The maximum
7024 length in characters of the common prefix of a list of possible
7025 completions that is displayed without modification.
7026 When set to a value greater than zero, \fBreadline\fP
7027 replaces common prefixes longer than this value
7028 with an ellipsis when displaying possible completions.
7029 If a completion begins with a period,
7030 and \fBeadline\fP is completing filenames,
7031 it uses three underscores instead of an ellipsis.
7032 .TP
7033 .B completion\-query\-items (100)
7034 This determines when the user is queried about viewing
7035 the number of possible completions
7036 generated by the \fBpossible\-completions\fP command.
7037 It may be set to any integer value greater than or equal to zero.
7038 If the number of possible completions is greater than
7039 or equal to the value of this variable,
7040 \fBreadline\fP asks whether or not the user wishes to view them;
7041 otherwise \fBreadline\fP simply lists them on the terminal.
7042 A zero value means \fBreadline\fP should never ask; negative values are
7043 treated as zero.
7044 .TP
7045 .B convert\-meta (On)
7046 If set to \fBOn\fP, \fBreadline\fP converts characters it reads
7047 that have the eighth bit set to an ASCII key sequence by
7048 clearing the eighth bit and prefixing it with an escape character
7049 (converting the character to have the meta prefix).
7050 The default is \fIOn\fP, but \fBreadline\fP sets it to \fIOff\fP
7051 if the locale contains
7052 characters whose encodings may include bytes with the eighth bit set.
7053 This variable is dependent on the \fBLC_CTYPE\fP locale category, and
7054 may change if the locale changes.
7055 This variable also affects key bindings; see the description of
7056 \fBforce\-meta\-prefix\fP below.
7057 .TP
7058 .B disable\-completion (Off)
7059 If set to \fBOn\fP, \fBreadline\fP inhibits word completion.
7060 Completion characters are inserted into the line as if they
7061 had been mapped to \fBself-insert\fP.
7062 .TP
7063 .B echo\-control\-characters (On)
7064 When set to \fBOn\fP, on operating systems that indicate they support it,
7065 \fBreadline\fP echoes a character corresponding to a signal generated from the
7066 keyboard.
7067 .TP
7068 .B editing\-mode (emacs)
7069 Controls whether \fBreadline\fP uses a set of key bindings similar
7070 to \fIEmacs\fP or \fIvi\fP.
7071 .B editing\-mode
7072 can be set to either
7073 .B emacs
7074 or
7075 .BR vi .
7076 .TP
7077 .B emacs\-mode\-string (@)
7078 If the \fIshow\-mode\-in\-prompt\fP variable is enabled,
7079 this string is displayed immediately before the last line of the
7080 primary prompt when emacs editing mode is active.
7081 The value is expanded like a
7082 key binding, so the standard set of meta- and control- prefixes and
7083 backslash escape sequences is available.
7084 The \e1 and \e2 escapes begin and end sequences of
7085 non-printing characters, which can be used to embed a terminal control
7086 sequence into the mode string.
7087 .TP
7088 .B enable\-active\-region (On)
7089 When this variable is set to \fIOn\fP, \fBreadline\fP allows certain commands
7090 to designate the region as \fIactive\fP.
7091 When the region is active, \fBreadline\fP
7092 highlights the text in the region using the value of the
7093 .B active\-region\-start\-color
7094 variable, which defaults to the string that enables
7095 the terminal's standout mode.
7096 The active region shows the text inserted by bracketed-paste and any
7097 matching text found by incremental and non-incremental history searches.
7098 .TP
7099 .B enable\-bracketed\-paste (On)
7100 When set to \fBOn\fP, \fBreadline\fP configures the terminal to insert each
7101 paste into the editing buffer as a single string of characters, instead
7102 of treating each character as if it had been read from the keyboard.
7103 This is called \fIbracketed\-paste mode\fP;
7104 it prevents \fBreadline\fP from executing any editing commands bound to key
7105 sequences appearing in the pasted text.
7106 .TP
7107 .B enable\-keypad (Off)
7108 When set to \fBOn\fP, \fBreadline\fP tries to enable the application
7109 keypad when it is called.
7110 Some systems need this to enable the arrow keys.
7111 .TP
7112 .B enable\-meta\-key (On)
7113 When set to \fBOn\fP, \fBreadline\fP tries to enable any meta modifier
7114 key the terminal claims to support.
7115 On many terminals, the Meta key is used to send eight-bit characters;
7116 this variable checks for the terminal capability that indicates the
7117 terminal can enable and disable a mode that sets the eighth bit of a
7118 character (0200) if the Meta key is held down when the character is
7119 typed (a meta character).
7120 .TP
7121 .B expand\-tilde (Off)
7122 If set to \fBOn\fP, \fBreadline\fP performs tilde expansion when it
7123 attempts word completion.
7124 .TP
7125 .B force\-meta\-prefix (Off)
7126 If set to \fBOn\fP, \fBreadline\fP modifies its behavior when binding key
7127 sequences containing \eM- or Meta-
7128 (see \fBKey Bindings\fP above) by converting a key sequence of the form
7129 \eM\-\fIC\fP or Meta\-\fIC\fP to the two-character sequence
7130 \fBESC\fP \fIC\fP (adding the meta prefix).
7131 If
7132 .B force\-meta\-prefix
7133 is set to \fBOff\fP (the default),
7134 \fBreadline\fP uses the value of the
7135 .B convert\-meta
7136 variable to determine whether to perform this conversion:
7137 if \fBconvert\-meta\fP is \fBOn\fP,
7138 \fBreadline\fP performs the conversion described above;
7139 if it is \fBOff\fP, \fBreadline\fP converts \fIC\fP to a meta character by
7140 setting the eighth bit (0200).
7141 .TP
7142 .B history\-preserve\-point (Off)
7143 If set to \fBOn\fP, the history code attempts to place point at the
7144 same location on each history line retrieved with \fBprevious-history\fP
7145 or \fBnext-history\fP.
7146 .TP
7147 .B history\-size (unset)
7148 Set the maximum number of history entries saved in the history list.
7149 If set to zero, any existing history entries are deleted and no new entries
7150 are saved.
7151 If set to a value less than zero, the number of history entries is not
7152 limited.
7153 By default, \fBbash\fP sets the maximum number of history entries to
7154 the value of the \fBHISTSIZE\fP shell variable.
7155 Setting \fIhistory\-size\fP to a non-numeric value will set
7156 the maximum number of history entries to 500.
7157 .TP
7158 .B horizontal\-scroll\-mode (Off)
7159 Setting this variable to \fBOn\fP makes \fBreadline\fP use a single line
7160 for display, scrolling the input horizontally on a single screen line
7161 when it becomes longer than the screen width rather than wrapping to
7162 a new line.
7163 This setting is automatically enabled for terminals of height 1.
7164 .TP
7165 .B input\-meta (Off)
7166 If set to \fBOn\fP, \fBreadline\fP enables eight-bit input (that is, it
7167 does not clear the eighth bit in the characters it reads),
7168 regardless of what the terminal claims it can support.
7169 The default is \fIOff\fP, but \fBreadline\fP sets it to \fIOn\fP
7170 if the locale contains characters whose encodings may include bytes
7171 with the eighth bit set.
7172 This variable is dependent on the \fBLC_CTYPE\fP locale category, and
7173 its value may change if the locale changes.
7174 The name \fBmeta\-flag\fP is a synonym for \fBinput\-meta\fP.
7175 .TP
7176 .BR isearch\-terminators\ ( \c
7177 .Q \fBC\-[C\-j\fP \fB)\fP
7178 The string of characters that should terminate an incremental
7179 search without subsequently executing the character as a command.
7180 If this variable has not been given a value, the characters
7181 \fIESC\fP and \fBC\-j\fP terminate an incremental search.
7182 .TP
7183 .B keymap (emacs)
7184 Set the current \fBreadline\fP keymap.
7185 The set of valid keymap names is
7186 \fIemacs, emacs\-standard, emacs\-meta, emacs\-ctlx, vi,
7187 vi\-command\fP, and
7188 .IR vi\-insert .
7189 \fIvi\fP is equivalent to \fIvi\-command\fP;
7190 \fIemacs\fP is equivalent to \fIemacs\-standard\fP.
7191 The default value is \fIemacs\fP;
7192 the value of
7193 .B editing\-mode
7194 also affects the default keymap.
7195 .TP
7196 .B keyseq\-timeout (500)
7197 Specifies the duration \fBreadline\fP will wait for a character when
7198 reading an ambiguous key sequence
7199 (one that can form a complete key sequence using the input read so far,
7200 or can take additional input to complete a longer key sequence).
7201 If \fBreadline\fP does not receive any input within the timeout,
7202 it uses the shorter but complete key sequence.
7203 The value is specified in milliseconds, so a value of 1000 means that
7204 \fBreadline\fP will wait one second for additional input.
7205 If this variable is set to a value less than or equal to zero, or to a
7206 non-numeric value, \fBreadline\fP waits until another key is pressed to
7207 decide which key sequence to complete.
7208 .TP
7209 .B mark\-directories (On)
7210 If set to \fBOn\fP, completed directory names have a slash appended.
7211 .TP
7212 .B mark\-modified\-lines (Off)
7213 If set to \fBOn\fP, \fBreadline\fP displays history lines
7214 that have been modified
7215 with a preceding asterisk (\fB*\fP).
7216 .TP
7217 .B mark\-symlinked\-directories (Off)
7218 If set to \fBOn\fP, completed names which are symbolic links to directories
7219 have a slash appended, subject to the value of \fBmark\-directories\fP.
7220 .TP
7221 .B match\-hidden\-files (On)
7222 This variable, when set to \fBOn\fP, forces \fBreadline\fP to match files whose
7223 names begin with a
7224 .Q .
7225 (hidden files) when performing filename completion.
7226 If set to \fBOff\fP, the user must include the leading
7227 .Q .
7228 in the filename to be completed.
7229 .TP
7230 .B menu\-complete\-display\-prefix (Off)
7231 If set to \fBOn\fP, menu completion displays the common prefix of the
7232 list of possible completions (which may be empty) before cycling through
7233 the list.
7234 .TP
7235 .B output\-meta (Off)
7236 If set to \fBOn\fP, \fBreadline\fP displays characters with the
7237 eighth bit set directly rather than as a meta-prefixed escape
7238 sequence.
7239 The default is \fIOff\fP, but \fBreadline\fP sets it to \fIOn\fP
7240 if the locale contains characters whose encodings may include
7241 bytes with the eighth bit set.
7242 This variable is dependent on the \fBLC_CTYPE\fP locale category, and
7243 its value may change if the locale changes.
7244 .TP
7245 .B page\-completions (On)
7246 If set to \fBOn\fP, \fBreadline\fP uses an internal pager resembling
7247 .IR more (1)
7248 to display a screenful of possible completions at a time.
7249 .TP
7250 .B prefer\-visible\-bell
7251 See \fBbell\-style\fP.
7252 .TP
7253 .B print\-completions\-horizontally (Off)
7254 If set to \fBOn\fP, \fBreadline\fP displays completions with matches
7255 sorted horizontally in alphabetical order, rather than down the screen.
7256 .TP
7257 .B revert\-all\-at\-newline (Off)
7258 If set to \fBOn\fP, \fBreadline\fP will undo all changes to history lines
7259 before returning when executing \fBaccept\-line\fP.
7260 By default,
7261 history lines may be modified and retain individual undo lists across
7262 calls to \fBreadline\fP.
7263 .TP
7264 .B search\-ignore\-case (Off)
7265 If set to \fBOn\fP, \fBreadline\fP performs incremental and non-incremental
7266 history list searches in a case\-insensitive fashion.
7267 .TP
7268 .B show\-all\-if\-ambiguous (Off)
7269 This alters the default behavior of the completion functions.
7270 If set to
7271 .BR On ,
7272 words which have more than one possible completion cause the
7273 matches to be listed immediately instead of ringing the bell.
7274 .TP
7275 .B show\-all\-if\-unmodified (Off)
7276 This alters the default behavior of the completion functions in
7277 a fashion similar to \fBshow\-all\-if\-ambiguous\fP.
7278 If set to
7279 .BR On ,
7280 words which have more than one possible completion without any
7281 possible partial completion (the possible completions don't share
7282 a common prefix) cause the matches to be listed immediately instead
7283 of ringing the bell.
7284 .TP
7285 .B show\-mode\-in\-prompt (Off)
7286 If set to \fBOn\fP, add a string to the beginning of the prompt
7287 indicating the editing mode: emacs, vi command, or vi insertion.
7288 The mode strings are user-settable (e.g., \fIemacs\-mode\-string\fP).
7289 .TP
7290 .B skip\-completed\-text (Off)
7291 If set to \fBOn\fP, this alters the default completion behavior when
7292 inserting a single match into the line.
7293 It's only active when performing completion in the middle of a word.
7294 If enabled, \fBreadline\fP does not insert characters from the completion
7295 that match characters after point in the word being completed,
7296 so portions of the word following the cursor are not duplicated.
7297 .TP
7298 .B vi\-cmd\-mode\-string ((cmd))
7299 If the \fIshow\-mode\-in\-prompt\fP variable is enabled,
7300 this string is displayed immediately before the last line of the primary
7301 prompt when vi editing mode is active and in command mode.
7302 The value is expanded like a key binding, so the standard set of
7303 meta- and control- prefixes and backslash escape sequences is available.
7304 The \e1 and \e2 escapes begin and end sequences of
7305 non-printing characters, which can be used to embed a terminal control
7306 sequence into the mode string.
7307 .TP
7308 .B vi\-ins\-mode\-string ((ins))
7309 If the \fIshow\-mode\-in\-prompt\fP variable is enabled,
7310 this string is displayed immediately before the last line of the primary
7311 prompt when vi editing mode is active and in insertion mode.
7312 The value is expanded like a key binding, so the standard set of
7313 meta- and control- prefixes and backslash escape sequences is available.
7314 The \e1 and \e2 escapes begin and end sequences of
7315 non-printing characters, which can be used to embed a terminal control
7316 sequence into the mode string.
7317 .TP
7318 .B visible\-stats (Off)
7319 If set to \fBOn\fP, a character denoting a file's type as reported
7320 by \fIstat\fP(2) is appended to the filename when listing possible
7321 completions.
7322 .PD
7323 .SS "Readline Conditional Constructs"
7324 .B Readline
7325 implements a facility similar in spirit to the conditional
7326 compilation features of the C preprocessor which allows key
7327 bindings and variable settings to be performed as the result
7328 of tests.
7329 There are four parser directives available.
7330 .TP
7331 .B $if
7332 The
7333 .B $if
7334 construct allows bindings to be made based on the
7335 editing mode, the terminal being used, or the application using
7336 \fBreadline\fP.
7337 The text of the test, after any comparison operator,
7338 extends to the end of the line;
7339 unless otherwise noted, no characters are required to isolate it.
7340 .RS
7341 .TP
7342 .B mode
7343 The \fBmode=\fP form of the \fB$if\fP directive is used to test
7344 whether \fBreadline\fP is in emacs or vi mode.
7345 This may be used in conjunction
7346 with the \fBset keymap\fP command, for instance, to set bindings in
7347 the \fIemacs\-standard\fP and \fIemacs\-ctlx\fP keymaps only if
7348 \fBreadline\fP is starting out in emacs mode.
7349 .TP
7350 .B term
7351 The \fBterm=\fP form may be used to include terminal-specific
7352 key bindings, perhaps to bind the key sequences output by the
7353 terminal's function keys.
7354 The word on the right side of the
7355 .B =
7356 is tested against both the full name of the terminal and the portion
7357 of the terminal name before the first \fB\-\fP.
7358 This allows
7359 .I xterm
7360 to match both
7361 .I xterm
7362 and
7363 .IR xterm\-256color ,
7364 for instance.
7365 .TP
7366 .B version
7367 The \fBversion\fP test may be used to perform comparisons against
7368 specific \fBreadline\fP versions.
7369 The \fBversion\fP expands to the current \fBreadline\fP version.
7370 The set of comparison operators includes
7371 .BR = ,
7372 (and
7373 .BR == ),
7374 .BR != ,
7375 .BR <= ,
7376 .BR >= ,
7377 .BR < ,
7378 and
7379 .BR > .
7380 The version number supplied on the right side of the operator consists
7381 of a major version number, an optional decimal point, and an optional
7382 minor version (e.g., \fB7.1\fP).
7383 If the minor version is omitted, it
7384 defaults to \fB0\fP.
7385 The operator may be separated from the string \fBversion\fP
7386 and from the version number argument by whitespace.
7387 .TP
7388 .I application
7389 The \fIapplication\fP construct is used to include
7390 application-specific settings.
7391 Each program using the \fBreadline\fP
7392 library sets the \fIapplication name\fP, and an initialization
7393 file can test for a particular value.
7394 This could be used to bind key sequences to functions useful for
7395 a specific program.
7396 For instance, the following command adds a
7397 key sequence that quotes the current or previous word in \fBbash\fP:
7398 .PP
7399 .RS
7400 .EX
7401 .nf
7402 \fB$if\fP Bash
7403 # Quote the current or previous word
7404 \*"\eC-xq\*": \*"\eeb\e\*"\eef\e\*"\*"
7405 \fB$endif\fP
7406 .fi
7407 .EE
7408 .RE
7409 .TP
7410 .I variable
7411 The \fIvariable\fP construct provides simple equality tests for \fBreadline\fP
7412 variables and values.
7413 The permitted comparison operators are \fI=\fP, \fI==\fP, and \fI!=\fP.
7414 The variable name must be separated from the comparison operator by
7415 whitespace; the operator may be separated from the value on the right hand
7416 side by whitespace.
7417 String and boolean variables may be tested.
7418 Boolean variables must be
7419 tested against the values \fIon\fP and \fIoff\fP.
7420 .RE
7421 .TP
7422 .B $else
7423 Commands in this branch of the \fB$if\fP directive are executed if
7424 the test fails.
7425 .TP
7426 .B $endif
7427 This command, as seen in the previous example, terminates an
7428 \fB$if\fP command.
7429 .TP
7430 .B $include
7431 This directive takes a single filename as an argument and reads commands
7432 and key bindings from that file.
7433 For example, the following directive would read
7434 .FN /etc/inputrc :
7435 .PP
7436 .RS
7437 .nf
7438 \fB$include\fP \^ \fI/etc/inputrc\fP
7439 .fi
7440 .RE
7441 .SS Searching
7442 .B Readline
7443 provides commands for searching through the command history (see
7444 .SM
7445 .B HISTORY
7446 below)
7447 for lines containing a specified string.
7448 There are two search modes:
7449 .I incremental
7450 and
7451 .IR non-incremental .
7452 .PP
7453 Incremental searches begin before the user has finished typing the
7454 search string.
7455 As each character of the search string is typed, \fBreadline\fP displays
7456 the next entry from the history matching the string typed so far.
7457 An incremental search requires only as many characters as needed to
7458 find the desired history entry.
7459 When using emacs editing mode, type \fBC\-r\fP to
7460 search backward in the history for a particular string.
7461 Typing \fBC\-s\fP searches forward through the history.
7462 The characters present in the value of the \fBisearch-terminators\fP
7463 variable are used to terminate an incremental search.
7464 If that variable has not been assigned a value,
7465 \fIESC\fP and \fBC\-j\fP terminate an incremental search.
7466 \fBC\-g\fP aborts an incremental search and restores the original line.
7467 When the search is terminated, the history entry containing the
7468 search string becomes the current line.
7469 .PP
7470 To find other matching entries in the history list, type \fBC\-r\fP or
7471 \fBC\-s\fP as appropriate.
7472 This searches backward or forward in the history for the next
7473 entry matching the search string typed so far.
7474 Any other key sequence bound to a \fBreadline\fP command terminates
7475 the search and executes that command.
7476 For instance, a newline terminates the search and accepts
7477 the line, thereby executing the command from the history list.
7478 A movement command will terminate the search, make the last line found
7479 the current line, and begin editing.
7480 .PP
7481 .B Readline
7482 remembers the last incremental search string.
7483 If two \fBC\-r\fPs are typed without any intervening characters defining
7484 a new search string, \fBreadline\fP uses any remembered search string.
7485 .PP
7486 Non-incremental searches read the entire search string before starting
7487 to search for matching history entries.
7488 The search string may be
7489 typed by the user or be part of the contents of the current line.
7490 .SS "Readline Command Names"
7491 The following is a list of the names of the commands and the default
7492 key sequences to which they are bound.
7493 Command names without an accompanying key sequence are unbound by default.
7494 .PP
7495 In the following descriptions, \fIpoint\fP refers to the current cursor
7496 position, and \fImark\fP refers to a cursor position saved by the
7497 \fBset\-mark\fP command.
7498 The text between the point and mark is referred to as the \fIregion\fP.
7499 .B Readline
7500 has the concept of an \fIactive region\fP:
7501 when the region is active, \fBreadline\fP redisplay
7502 highlights the region using the value of the
7503 .B active\-region\-start\-color
7504 variable.
7505 The \fBenable\-active\-region\fP \fBreadline\fP variable turns this on and off.
7506 Several commands set the region to active; those are noted below.
7507 .SS Commands for Moving
7508 .PD 0
7509 .TP
7510 .B beginning\-of\-line (C\-a)
7511 Move to the start of the current line.
7512 This may also be bound to the Home key on some keyboards.
7513 .TP
7514 .B end\-of\-line (C\-e)
7515 Move to the end of the line.
7516 This may also be bound to the End key on some keyboards.
7517 .TP
7518 .B forward\-char (C\-f)
7519 Move forward a character.
7520 This may also be bound to the right arrow key on some keyboards.
7521 .TP
7522 .B backward\-char (C\-b)
7523 Move back a character.
7524 This may also be bound to the left arrow key on some keyboards.
7525 .TP
7526 .B forward\-word (M\-f)
7527 Move forward to the end of the next word.
7528 Words are composed of alphanumeric characters (letters and digits).
7529 .TP
7530 .B backward\-word (M\-b)
7531 Move back to the start of the current or previous word.
7532 Words are composed of alphanumeric characters (letters and digits).
7533 .TP
7534 .B shell\-forward\-word (M\-C\-f)
7535 Move forward to the end of the next word.
7536 Words are delimited by non-quoted shell metacharacters.
7537 .TP
7538 .B shell\-backward\-word (M\-C\-b)
7539 Move back to the start of the current or previous word.
7540 Words are delimited by non-quoted shell metacharacters.
7541 .TP
7542 .B previous\-screen\-line
7543 Attempt to move point to the same physical screen column on the previous
7544 physical screen line.
7545 This will not have the desired effect if the current
7546 \fBreadline\fP line does not take up more than one physical line or if
7547 point is not greater than the length of the prompt plus the screen width.
7548 .TP
7549 .B next\-screen\-line
7550 Attempt to move point to the same physical screen column on the next
7551 physical screen line.
7552 This will not have the desired effect if the current
7553 \fBreadline\fP line does not take up more than one physical line or if
7554 the length of the current \fBreadline\fP line is
7555 not greater than the length of the prompt
7556 plus the screen width.
7557 .TP
7558 .B clear\-display (M\-C\-l)
7559 Clear the screen and, if possible, the terminal's scrollback buffer,
7560 then redraw the current line,
7561 leaving the current line at the top of the screen.
7562 .TP
7563 .B clear\-screen (C\-l)
7564 Clear the screen,
7565 then redraw the current line,
7566 leaving the current line at the top of the screen.
7567 With a numeric argument, refresh the current line without clearing the
7568 screen.
7569 .TP
7570 .B redraw\-current\-line
7571 Refresh the current line.
7572 .PD
7573 .SS Commands for Manipulating the History
7574 .PD 0
7575 .TP
7576 .B accept\-line (Newline, Return)
7577 Accept the line regardless of where the cursor is.
7578 If this line is non-empty, add it to the history list according to the
7579 state of the
7580 .SM
7581 .B HISTCONTROL
7582 and
7583 .B HISTIGNORE
7584 variables.
7585 If the line is a modified history line,
7586 restore the history line to its original state.
7587 .TP
7588 .B previous\-history (C\-p)
7589 Fetch the previous command from the history list, moving back in
7590 the list.
7591 This may also be bound to the up arrow key on some keyboards.
7592 .TP
7593 .B next\-history (C\-n)
7594 Fetch the next command from the history list, moving forward in the
7595 list.
7596 This may also be bound to the down arrow key on some keyboards.
7597 .TP
7598 .B beginning\-of\-history (M\-<)
7599 Move to the first line in the history.
7600 .TP
7601 .B end\-of\-history (M\->)
7602 Move to the end of the input history, i.e., the line currently being
7603 entered.
7604 .TP
7605 .B operate\-and\-get\-next (C\-o)
7606 Accept the current line for execution as if a
7607 newline had been entered,
7608 and fetch the next line relative to the current line from the history
7609 for editing.
7610 A numeric argument, if supplied, specifies the history entry to use instead
7611 of the current line.
7612 .TP
7613 .B
7614 fetch\-history
7615 With a numeric argument, fetch that entry from the history list
7616 and make it the current line.
7617 Without an argument, move back to the first entry in the history list.
7618 .TP
7619 .B reverse\-search\-history (C\-r)
7620 Search backward starting at the current line and moving
7621 .Q up
7622 through the history as necessary.
7623 This is an incremental search.
7624 This command sets the region to the matched text and activates the region.
7625 .TP
7626 .B forward\-search\-history (C\-s)
7627 Search forward starting at the current line and moving
7628 .Q down
7629 through the history as necessary.
7630 This is an incremental search.
7631 This command sets the region to the matched text and activates the region.
7632 .TP
7633 .B non\-incremental\-reverse\-search\-history (M\-p)
7634 Search backward through the history starting at the current line
7635 using a non-incremental search for a string supplied by the user.
7636 The search string may match anywhere in a history line.
7637 .TP
7638 .B non\-incremental\-forward\-search\-history (M\-n)
7639 Search forward through the history using a non-incremental search
7640 for a string supplied by the user.
7641 The search string may match anywhere in a history line.
7642 .TP
7643 .B history\-search\-backward
7644 Search backward through the history for the string of characters
7645 between the start of the current line and the point.
7646 The search string must match at the beginning of a history line.
7647 This is a non-incremental search.
7648 This may be bound to the Page Up key on some keyboards.
7649 .TP
7650 .B history\-search\-forward
7651 Search forward through the history for the string of characters
7652 between the start of the current line and the point.
7653 The search string must match at the beginning of a history line.
7654 This is a non-incremental search.
7655 This may be bound to the Page Down key on some keyboards.
7656 .TP
7657 .B history\-substring\-search\-backward
7658 Search backward through the history for the string of characters
7659 between the start of the current line and the point.
7660 The search string may match anywhere in a history line.
7661 This is a non-incremental search.
7662 .TP
7663 .B history\-substring\-search\-forward
7664 Search forward through the history for the string of characters
7665 between the start of the current line and the point.
7666 The search string may match anywhere in a history line.
7667 This is a non-incremental search.
7668 .TP
7669 .B yank\-nth\-arg (M\-C\-y)
7670 Insert the first argument to the previous command (usually
7671 the second word on the previous line) at point.
7672 With an argument
7673 .IR n ,
7674 insert the \fIn\fPth word from the previous command (the words
7675 in the previous command begin with word 0).
7676 A negative argument inserts the \fIn\fPth word from the end of
7677 the previous command.
7678 Once the argument \fIn\fP is computed,
7679 this uses the history expansion facilities to extract the
7680 \fIn\fPth word, as if the
7681 .Q !\fIn\fP
7682 history expansion had been specified.
7683 .TP
7684 .B
7685 yank\-last\-arg (M\-.\^, M\-_\^)
7686 Insert the last argument to the previous command (the last word of
7687 the previous history entry).
7688 With a numeric argument, behave exactly like \fByank\-nth\-arg\fP.
7689 Successive calls to \fByank\-last\-arg\fP move back through the history
7690 list, inserting the last word (or the word specified by the argument to
7691 the first call) of each line in turn.
7692 Any numeric argument supplied to these successive calls determines
7693 the direction to move through the history.
7694 A negative argument switches the direction through the history
7695 (back or forward).
7696 This uses the history expansion facilities to extract the
7697 last word, as if the
7698 .Q !$
7699 history expansion had been specified.
7700 .TP
7701 .B shell\-expand\-line (M\-C\-e)
7702 Expand the line by performing shell word expansions.
7703 This performs alias and history expansion,
7704 \fB$\fP\*'\fIstring\fP\*' and \fB$\fP\*"\fIstring\fP\*" quoting,
7705 tilde expansion, parameter and variable expansion, arithmetic expansion,
7706 command and process substitution,
7707 word splitting, and quote removal.
7708 An explicit argument suppresses command and process substitution.
7709 See
7710 .SM
7711 .B "HISTORY EXPANSION"
7712 below for a description of history expansion.
7713 .TP
7714 .B history\-expand\-line (M\-\*^)
7715 Perform history expansion on the current line.
7716 See
7717 .SM
7718 .B "HISTORY EXPANSION"
7719 below for a description of history expansion.
7720 .TP
7721 .B magic\-space
7722 Perform history expansion on the current line and insert a space.
7723 See
7724 .SM
7725 .B "HISTORY EXPANSION"
7726 below for a description of history expansion.
7727 .TP
7728 .B alias\-expand\-line
7729 Perform alias expansion on the current line.
7730 See
7731 .SM
7732 .B ALIASES
7733 above for a description of alias expansion.
7734 .TP
7735 .B history\-and\-alias\-expand\-line
7736 Perform history and alias expansion on the current line.
7737 .TP
7738 .B insert\-last\-argument (M\-.\^, M\-_\^)
7739 A synonym for \fByank\-last\-arg\fP.
7740 .TP
7741 .B edit\-and\-execute\-command (C\-x C\-e)
7742 Invoke an editor on the current command line, and execute the result as shell
7743 commands.
7744 \fBBash\fP attempts to invoke
7745 .SM
7746 .BR $VISUAL ,
7747 .SM
7748 .BR $EDITOR ,
7749 and \fIemacs\fP as the editor, in that order.
7750 .PD
7751 .SS Commands for Changing Text
7752 .PD 0
7753 .TP
7754 .B \fIend\-of\-file\fP (usually C\-d)
7755 The character indicating end-of-file as set, for example, by
7756 .IR stty (1).
7757 If this character is read when there are no characters
7758 on the line, and point is at the beginning of the line, \fBreadline\fP
7759 interprets it as the end of input and returns
7760 .SM
7761 .BR EOF .
7762 .TP
7763 .B delete\-char (C\-d)
7764 Delete the character at point.
7765 If this function is bound to the
7766 same character as the tty \fBEOF\fP character, as \fBC\-d\fP
7767 commonly is, see above for the effects.
7768 This may also be bound to the Delete key on some keyboards.
7769 .TP
7770 .B backward\-delete\-char (Rubout)
7771 Delete the character behind the cursor.
7772 When given a numeric argument,
7773 save the deleted text on the kill ring.
7774 .TP
7775 .B forward\-backward\-delete\-char
7776 Delete the character under the cursor, unless the cursor is at the
7777 end of the line, in which case the character behind the cursor is
7778 deleted.
7779 .TP
7780 .B quoted\-insert (C\-q, C\-v)
7781 Add the next character typed to the line verbatim.
7782 This is how to insert characters like \fBC\-q\fP, for example.
7783 .TP
7784 .B tab\-insert (C\-v TAB)
7785 Insert a tab character.
7786 .TP
7787 .B "self\-insert (a, b, A, 1, !, \fR.\|.\|.\fP)"
7788 Insert the character typed.
7789 .TP
7790 .B bracketed\-paste\-begin
7791 This function is intended to be bound to the
7792 .Q "bracketed paste"
7793 escape
7794 sequence sent by some terminals, and such a binding is assigned by default.
7795 It allows \fBreadline\fP to insert the pasted text as a single unit
7796 without treating each character as if it had been read from the keyboard.
7797 The pasted characters
7798 are inserted as if each one was bound to \fBself\-insert\fP instead of
7799 executing any editing commands.
7800 .IP
7801 Bracketed paste sets the region to the inserted text and activates the region.
7802 .TP
7803 .B transpose\-chars (C\-t)
7804 Drag the character before point forward over the character at point,
7805 moving point forward as well.
7806 If point is at the end of the line, then this transposes
7807 the two characters before point.
7808 Negative arguments have no effect.
7809 .TP
7810 .B transpose\-words (M\-t)
7811 Drag the word before point past the word after point,
7812 moving point past that word as well.
7813 If point is at the end of the line, this transposes
7814 the last two words on the line.
7815 .TP
7816 .B shell\-transpose\-words (M-C-t)
7817 Drag the word before point past the word after point,
7818 moving point past that word as well.
7819 If the insertion point is at the end of the line, this transposes
7820 the last two words on the line.
7821 Word boundaries are the same as \fBshell\-forward\-word\fP and
7822 \fBshell\-backward\-word\fP.
7823 .TP
7824 .B upcase\-word (M\-u)
7825 Uppercase the current (or following) word.
7826 With a negative argument,
7827 uppercase the previous word, but do not move point.
7828 .TP
7829 .B downcase\-word (M\-l)
7830 Lowercase the current (or following) word.
7831 With a negative argument,
7832 lowercase the previous word, but do not move point.
7833 .TP
7834 .B capitalize\-word (M\-c)
7835 Capitalize the current (or following) word.
7836 With a negative argument,
7837 capitalize the previous word, but do not move point.
7838 .TP
7839 .B overwrite\-mode
7840 Toggle overwrite mode.
7841 With an explicit positive numeric argument, switches to overwrite mode.
7842 With an explicit non-positive numeric argument, switches to insert mode.
7843 This command affects only \fBemacs\fP mode;
7844 \fBvi\fP mode does overwrite differently.
7845 Each call to \fIreadline()\fP starts in insert mode.
7846 .IP
7847 In overwrite mode, characters bound to \fBself\-insert\fP replace
7848 the text at point rather than pushing the text to the right.
7849 Characters bound to \fBbackward\-delete\-char\fP replace the character
7850 before point with a space.
7851 By default, this command is unbound,
7852 but may be bound to the Insert key on some keyboards.
7853 .PD
7854 .SS Killing and Yanking
7855 .PD 0
7856 .TP
7857 .B kill\-line (C\-k)
7858 Kill the text from point to the end of the current line.
7859 With a negative numeric argument, kill backward from the cursor to the
7860 beginning of the line.
7861 .TP
7862 .B backward\-kill\-line (C\-x Rubout)
7863 Kill backward to the beginning of the current line.
7864 With a negative numeric argument, kill forward from the cursor to the
7865 end of the line.
7866 .TP
7867 .B unix\-line\-discard (C\-u)
7868 Kill backward from point to the beginning of the line,
7869 saving the killed text on the kill-ring.
7870 .\" There is no real difference between this and backward-kill-line
7871 .TP
7872 .B kill\-whole\-line
7873 Kill all characters on the current line, no matter where point is.
7874 .TP
7875 .B kill\-word (M\-d)
7876 Kill from point to the end of the current word, or if between
7877 words, to the end of the next word.
7878 Word boundaries are the same as those used by \fBforward\-word\fP.
7879 .TP
7880 .B backward\-kill\-word (M\-Rubout)
7881 Kill the word behind point.
7882 Word boundaries are the same as those used by \fBbackward\-word\fP.
7883 .TP
7884 .B shell\-kill\-word (M\-C\-d)
7885 Kill from point to the end of the current word, or if between
7886 words, to the end of the next word.
7887 Word boundaries are the same as those used by \fBshell\-forward\-word\fP.
7888 .TP
7889 .B shell\-backward\-kill\-word
7890 Kill the word behind point.
7891 Word boundaries are the same as those used by \fBshell\-backward\-word\fP.
7892 .TP
7893 .B unix\-word\-rubout (C\-w)
7894 Kill the word behind point, using white space as a word boundary,
7895 saving the killed text on the kill-ring.
7896 .TP
7897 .B unix\-filename\-rubout
7898 Kill the word behind point, using white space and the slash character
7899 as the word boundaries,
7900 saving the killed text on the kill-ring.
7901 .TP
7902 .B delete\-horizontal\-space (M\-\e)
7903 Delete all spaces and tabs around point.
7904 .TP
7905 .B kill\-region
7906 Kill the text in the current region.
7907 .TP
7908 .B copy\-region\-as\-kill
7909 Copy the text in the region to the kill buffer,
7910 so it can be yanked immediately.
7911 .TP
7912 .B copy\-backward\-word
7913 Copy the word before point to the kill buffer.
7914 The word boundaries are the same as \fBbackward\-word\fP.
7915 .TP
7916 .B copy\-forward\-word
7917 Copy the word following point to the kill buffer.
7918 The word boundaries are the same as \fBforward\-word\fP.
7919 .TP
7920 .B yank (C\-y)
7921 Yank the top of the kill ring into the buffer at point.
7922 .TP
7923 .B yank\-pop (M\-y)
7924 Rotate the kill ring, and yank the new top.
7925 Only works following
7926 .B yank
7927 or
7928 .BR yank\-pop .
7929 .PD
7930 .SS Numeric Arguments
7931 .PD 0
7932 .TP
7933 .B digit\-argument (M\-0, M\-1, \fR.\|.\|.\fP, M\-\-)
7934 Add this digit to the argument already accumulating, or start a new
7935 argument.
7936 M\-\- starts a negative argument.
7937 .TP
7938 .B universal\-argument
7939 This is another way to specify an argument.
7940 If this command is followed by one or more digits, optionally with a
7941 leading minus sign, those digits define the argument.
7942 If the command is followed by digits, executing
7943 .B universal\-argument
7944 again ends the numeric argument, but is otherwise ignored.
7945 As a special case, if this command is immediately followed by a
7946 character that is neither a digit nor minus sign,
7947 the argument count for the next command is multiplied by four.
7948 The argument count is initially one, so executing this function the
7949 first time makes the argument count four, a second time makes the
7950 argument count sixteen, and so on.
7951 .PD
7952 .SS Completing
7953 .PD 0
7954 .TP
7955 .B complete (TAB)
7956 Attempt to perform completion on the text before point.
7957 .B Bash
7958 attempts completion by first checking for any programmable
7959 completions for the command word (see \fBProgrammable Completion\fP below),
7960 otherwise treating the text as a
7961 variable (if the text begins with \fB$\fP),
7962 username (if the text begins with \fB\*~\fP),
7963 hostname (if the text begins with \fB@\fP), or
7964 command (including aliases, functions, and builtins) in turn.
7965 If none of these produces a match, it falls back to filename completion.
7966 .TP
7967 .B possible\-completions (M\-?)
7968 List the possible completions of the text before point.
7969 When displaying completions, \fBreadline\fP sets the number of columns used
7970 for display to the value of \fBcompletion-display-width\fP, the value of
7971 the shell variable
7972 .SM
7973 .BR COLUMNS ,
7974 or the screen width, in that order.
7975 .TP
7976 .B insert\-completions (M\-*)
7977 Insert all completions of the text before point
7978 that would have been generated by
7979 \fBpossible\-completions\fP,
7980 separated by a space.
7981 .TP
7982 .B menu\-complete
7983 Similar to \fBcomplete\fP, but replaces the word to be completed
7984 with a single match from the list of possible completions.
7985 Repeatedly executing \fBmenu\-complete\fP steps through the list
7986 of possible completions, inserting each match in turn.
7987 At the end of the list of completions,
7988 \fBmenu\-complete\fP rings the bell
7989 (subject to the setting of \fBbell\-style\fP)
7990 and restores the original text.
7991 An argument of \fIn\fP moves \fIn\fP positions forward in the list
7992 of matches; a negative argument moves backward through the list.
7993 This command is intended to be bound to \fBTAB\fP, but is unbound
7994 by default.
7995 .TP
7996 .B menu\-complete\-backward
7997 Identical to \fBmenu\-complete\fP, but moves backward through the list
7998 of possible completions, as if \fBmenu\-complete\fP had been given a
7999 negative argument.
8000 This command is unbound by default.
8001 .TP
8002 .B export\-completions
8003 Perform completion on the word before point as described above
8004 and write the list of possible completions to \fBreadline\fP's output
8005 stream using the following format, writing information on separate lines:
8006 .RS
8007 .PD
8008 .IP \(bu
8009 .PD 0
8010 the number of matches \fIN\fP;
8011 .IP \(bu
8012 the word being completed;
8013 .IP \(bu
8014 \fIS\fP:\fIE\fP,
8015 where \fIS\fP and \fIE\fP are the start and end offsets of the word
8016 in the \fBreadline\fP line buffer; then
8017 .IP \(bu
8018 each match, one per line
8019 .RE
8020 .PD
8021 .IP
8022 If there are no matches, the first line will be
8023 .Q 0 ,
8024 and this command does not print any output after the \fIS\fP:\fIE\fP.
8025 If there is only a single match, this prints a single line containing it.
8026 If there is more than one match, this prints the common prefix of the
8027 matches, which may be empty, on the first line after the \fIS\fP:\fIE\fP,
8028 then the matches on subsequent lines.
8029 In this case, \fIN\fP will include the first line with the common prefix.
8030 .IP
8031 The user or application
8032 should be able to accommodate the possibility of a blank line.
8033 The intent is that the user or application reads \fIN\fP lines after
8034 the line containing \fIS\fP:\fIE\fP to obtain the match list.
8035 This command is unbound by default.
8036 .TP
8037 .B delete\-char\-or\-list
8038 Deletes the character under the cursor if not at the beginning or
8039 end of the line (like \fBdelete\-char\fP).
8040 At the end of the line, it behaves identically to \fBpossible\-completions\fP.
8041 This command is unbound by default.
8042 .TP
8043 .B complete\-filename (M\-/)
8044 Attempt filename completion on the text before point.
8045 .TP
8046 .B possible\-filename\-completions (C\-x /)
8047 List the possible completions of the text before point,
8048 treating it as a filename.
8049 .TP
8050 .B complete\-username (M\-\*~)
8051 Attempt completion on the text before point, treating
8052 it as a username.
8053 .TP
8054 .B possible\-username\-completions (C\-x \*~)
8055 List the possible completions of the text before point,
8056 treating it as a username.
8057 .TP
8058 .B complete\-variable (M\-$)
8059 Attempt completion on the text before point, treating
8060 it as a shell variable.
8061 .TP
8062 .B possible\-variable\-completions (C\-x $)
8063 List the possible completions of the text before point,
8064 treating it as a shell variable.
8065 .TP
8066 .B complete\-hostname (M\-@)
8067 Attempt completion on the text before point, treating
8068 it as a hostname.
8069 .TP
8070 .B possible\-hostname\-completions (C\-x @)
8071 List the possible completions of the text before point,
8072 treating it as a hostname.
8073 .TP
8074 .B complete\-command (M\-!)
8075 Attempt completion on the text before point, treating
8076 it as a command name.
8077 Command completion attempts to
8078 match the text against aliases, reserved words, shell
8079 functions, shell builtins, and finally executable filenames,
8080 in that order.
8081 .TP
8082 .B possible\-command\-completions (C\-x !)
8083 List the possible completions of the text before point,
8084 treating it as a command name.
8085 .TP
8086 .B dynamic\-complete\-history (M\-TAB)
8087 Attempt completion on the text before point, comparing
8088 the text against history list entries for possible
8089 completion matches.
8090 .TP
8091 .B dabbrev\-expand
8092 Attempt menu completion on the text before point, comparing
8093 the text against lines from the history list for possible
8094 completion matches.
8095 .TP
8096 .B complete\-into\-braces (M\-{)
8097 Perform filename completion and insert the list of possible completions
8098 enclosed within braces so the list is available to the shell (see
8099 .B "Brace Expansion"
8100 above).
8101 .PD
8102 .SS "Keyboard Macros"
8103 .PD 0
8104 .TP
8105 .B start\-kbd\-macro (C\-x (\^)
8106 Begin saving the characters typed into the current keyboard macro.
8107 .TP
8108 .B end\-kbd\-macro (C\-x )\^)
8109 Stop saving the characters typed into the current keyboard macro
8110 and store the definition.
8111 .TP
8112 .B call\-last\-kbd\-macro (C\-x e)
8113 Re-execute the last keyboard macro defined, by making the characters
8114 in the macro appear as if typed at the keyboard.
8115 .TP
8116 .B print\-last\-kbd\-macro ()
8117 Print the last keyboard macro defined in a format suitable for the
8118 \fIinputrc\fP file.
8119 .PD
8120 .SS Miscellaneous
8121 .PD 0
8122 .TP
8123 .B re\-read\-init\-file (C\-x C\-r)
8124 Read in the contents of the \fIinputrc\fP file, and incorporate
8125 any bindings or variable assignments found there.
8126 .TP
8127 .B abort (C\-g)
8128 Abort the current editing command and
8129 ring the terminal's bell (subject to the setting of
8130 .BR bell\-style ).
8131 .TP
8132 .B do\-lowercase\-version (M\-A, M\-B, M\-\fIx\fP, \fR.\|.\|.\fP)
8133 If the metafied character \fIx\fP is uppercase, run the command
8134 that is bound to the corresponding metafied lowercase character.
8135 The behavior is undefined if \fIx\fP is already lowercase.
8136 .TP
8137 .B prefix\-meta (ESC)
8138 Metafy the next character typed.
8139 .SM
8140 .B ESC
8141 .B f
8142 is equivalent to
8143 .BR Meta\-f .
8144 .TP
8145 .B undo (C\-_, C\-x C\-u)
8146 Incremental undo, separately remembered for each line.
8147 .TP
8148 .B revert\-line (M\-r)
8149 Undo all changes made to this line.
8150 This is like executing the
8151 .B undo
8152 command enough times to return the line to its initial state.
8153 .TP
8154 .B tilde\-expand (M\-&)
8155 Perform tilde expansion on the current word.
8156 .TP
8157 .B set\-mark (C\-@, M\-<space>)
8158 Set the mark to the point.
8159 If a numeric argument is supplied, set the mark to that position.
8160 .TP
8161 .B exchange\-point\-and\-mark (C\-x C\-x)
8162 Swap the point with the mark.
8163 Set the current cursor position to the saved position,
8164 then set the mark to the old cursor position.
8165 .TP
8166 .B character\-search (C\-])
8167 Read a character and move point to the next occurrence of that character.
8168 A negative argument searches for previous occurrences.
8169 .TP
8170 .B character\-search\-backward (M\-C\-])
8171 Read a character and move point to the previous occurrence of that character.
8172 A negative argument searches for subsequent occurrences.
8173 .TP
8174 .B skip\-csi\-sequence
8175 Read enough characters to consume a multi-key sequence such as those
8176 defined for keys like Home and End.
8177 CSI sequences begin with a Control Sequence Indicator (CSI), usually
8178 .IR "ESC [" .
8179 If this sequence is bound to
8180 .Q \ee[ ,
8181 keys producing CSI sequences have no effect
8182 unless explicitly bound to a \fBreadline\fP command,
8183 instead of inserting stray characters into the editing buffer.
8184 This is unbound by default, but usually bound to
8185 .IR "ESC [" .
8186 .TP
8187 .B insert\-comment (M\-#)
8188 Without a numeric argument, insert the value of the \fBreadline\fP
8189 .B comment\-begin
8190 variable at the beginning of the current line.
8191 If a numeric argument is supplied, this command acts as a toggle: if
8192 the characters at the beginning of the line do not match the value
8193 of \fBcomment\-begin\fP, insert the value; otherwise delete
8194 the characters in \fBcomment-begin\fP from the beginning of the line.
8195 In either case, the line is accepted as if a newline had been typed.
8196 The default value of
8197 \fBcomment\-begin\fP causes this command to make the current line
8198 a shell comment.
8199 If a numeric argument causes the comment character to be removed, the line
8200 will be executed by the shell.
8201 .TP
8202 .B spell\-correct\-word (C\-x s)
8203 Perform spelling correction on the current word, treating it as a directory
8204 or filename, in the same way as the \fBcdspell\fP shell option.
8205 Word boundaries are the same as those used by \fBshell\-forward\-word\fP.
8206 .TP
8207 .B glob\-complete\-word (M\-g)
8208 Treat the word before point as a pattern for pathname expansion,
8209 with an asterisk implicitly appended, then use the pattern to
8210 generate a list of matching file names for possible completions.
8211 .TP
8212 .B glob\-expand\-word (C\-x *)
8213 Treat the word before point as a pattern for pathname expansion,
8214 and insert the list of matching file names, replacing the word.
8215 If a numeric argument is supplied, append a \fB*\fP before
8216 pathname expansion.
8217 .TP
8218 .B glob\-list\-expansions (C\-x g)
8219 Display the list of expansions that would have been generated by
8220 .B glob\-expand\-word
8221 and redisplay the line.
8222 If a numeric argument is supplied, append a \fB*\fP before
8223 pathname expansion.
8224 .TP
8225 .B dump\-functions
8226 Print all of the functions and their key bindings
8227 to the \fBreadline\fP output stream.
8228 If a numeric argument is supplied,
8229 the output is formatted in such a way that it can be made part
8230 of an \fIinputrc\fP file.
8231 .TP
8232 .B dump\-variables
8233 Print all of the settable \fBreadline\fP variables and their values
8234 to the \fBreadline\fP output stream.
8235 If a numeric argument is supplied,
8236 the output is formatted in such a way that it can be made part
8237 of an \fIinputrc\fP file.
8238 .TP
8239 .B dump\-macros
8240 Print all of the \fBreadline\fP key sequences bound to macros and the
8241 strings they output
8242 to the \fBreadline\fP output stream.
8243 If a numeric argument is supplied,
8244 the output is formatted in such a way that it can be made part
8245 of an \fIinputrc\fP file.
8246 .TP
8247 .B execute\-named\-command (M-x)
8248 Read a bindable \fBreadline\fP command name from the input and execute the
8249 function to which it's bound, as if the key sequence to which it was
8250 bound appeared in the input.
8251 If this function is supplied with a numeric argument, it passes that
8252 argument to the function it executes.
8253 .TP
8254 .B display\-shell\-version (C\-x C\-v)
8255 Display version information about the current instance of
8256 .BR bash .
8257 .PD
8258 .SS "Programmable Completion"
8259 When a user attempts word completion
8260 for a command or an argument to a command for
8261 which a completion specification (a \fIcompspec\fP) has been defined
8262 using the \fBcomplete\fP builtin
8263 (see
8264 .SM
8265 .B "SHELL BUILTIN COMMANDS"
8266 below),
8267 \fBreadline\fP invokes the programmable completion facilities.
8268 .PP
8269 First, \fBbash\fP identifies the command name.
8270 If a compspec has been defined for that command, the
8271 compspec is used to generate the list of possible completions for the word.
8272 If the command word is the empty string (completion attempted at the
8273 beginning of an empty line), \fBbash\fP uses any compspec defined with
8274 the \fB\-E\fP option to \fBcomplete\fP.
8275 The \fB\-I\fP option to \fBcomplete\fP
8276 indicates that the command word is the first non-assignment word
8277 on the line, or after a command delimiter such as
8278 \fB;\fP or \fB|\fP.
8279 This usually indicates command name completion.
8280 .PP
8281 If the command word is a full pathname, \fBbash\fP
8282 searches for a compspec for the full pathname first.
8283 If there is no compspec for the full pathname, \fBbash\fP attempts to
8284 find a compspec for the portion following the final slash.
8285 If those searches do not result in a compspec,
8286 or if there is no compspec for the command word,
8287 \fBbash\fP uses any compspec defined with
8288 the \fB\-D\fP option to \fBcomplete\fP as the default.
8289 If there is no default compspec, \fBbash\fP performs alias expansion
8290 on the command word as a final resort,
8291 and attempts to find a compspec for the command word
8292 resulting from any successful expansion.
8293 .PP
8294 If a compspec is not found, \fBbash\fP performs its default completion as
8295 described above under \fBCompleting\fP.
8296 Otherwise, once a compspec has been found, \fBbash\fP uses it to generate
8297 the list of matching words.
8298 .PP
8299 First, \fBbash\fP performs the \fIactions\fP specified by the compspec.
8300 This only returns matches which are prefixes
8301 of the word being completed.
8302 When the
8303 .B \-f
8304 or
8305 .B \-d
8306 option is used for filename or directory name completion,
8307 \fBbash\fP uses the shell variable
8308 .SM
8309 .B FIGNORE
8310 to filter the matches.
8311 .PP
8312 Next, programmable completion generates matches
8313 specified by a pathname expansion pattern
8314 supplied as an argument to the
8315 \fB\-G\fP option.
8316 The words generated by the pattern need not match the word
8317 being completed.
8318 \fBBash\fP
8319 uses the
8320 .SM
8321 .B FIGNORE
8322 variable to filter the matches, but does not use the
8323 .SM
8324 .B GLOBIGNORE
8325 shell variable.
8326 .PP
8327 Next, completion considers
8328 the string specified as the argument to the \fB\-W\fP option.
8329 The string is first split using the characters in the
8330 .SM
8331 .B IFS
8332 special variable as delimiters.
8333 This honors shell quoting within the string, in order to provide a
8334 mechanism for the words to contain shell metacharacters or characters
8335 in the value of
8336 .SM
8337 .BR IFS .
8338 Each word is then expanded using
8339 brace expansion, tilde expansion, parameter and variable expansion,
8340 command substitution, and arithmetic expansion,
8341 as described above under
8342 .SM
8343 .BR EXPANSION .
8344 The results are split using the rules described above under
8345 \fBWord Splitting\fP.
8346 The results of the expansion are prefix-matched against the word being
8347 completed, and the matching words become possible completions.
8348 .PP
8349 After these matches have been generated,
8350 \fBbash\fP executes any shell function or command
8351 specified with the \fB\-F\fP and \fB\-C\fP options.
8352 When the command or function is invoked, \fBbash\fP
8353 assigns values to the
8354 .SM
8355 .BR COMP_LINE ,
8356 .SM
8357 .BR COMP_POINT ,
8358 .SM
8359 .BR COMP_KEY ,
8360 and
8361 .SM
8362 .B COMP_TYPE
8363 variables as described above
8364 under \fBShell Variables\fP.
8365 If a shell function is being invoked, \fBbash\fP
8366 also sets the
8367 .SM
8368 .B COMP_WORDS
8369 and
8370 .SM
8371 .B COMP_CWORD
8372 variables.
8373 When the function or command is invoked,
8374 the first argument (\fB$1\fP) is the name of the command whose arguments
8375 are being completed,
8376 the second argument (\fB$2\fP) is the word being completed,
8377 and the third argument (\fB$3\fP) is the word preceding the word being
8378 completed on the current command line.
8379 There is no filtering of the generated completions against the
8380 word being completed;
8381 the function or command has complete freedom in generating the matches
8382 and they do not need to match a prefix of the word.
8383 .PP
8384 Any function specified with \fB\-F\fP is invoked first.
8385 The function may use any of the shell facilities, including the
8386 \fBcompgen\fP and \fBcompopt\fP
8387 builtins described below, to generate the matches.
8388 It must put the possible completions in the
8389 .SM
8390 .B COMPREPLY
8391 array variable, one per array element.
8392 .PP
8393 Next, any command specified with the \fB\-C\fP option is invoked
8394 in an environment equivalent to command substitution.
8395 It should print a list of completions, one per line, to the
8396 standard output.
8397 Backslash will escape a newline, if necessary.
8398 These are added to the set of possible completions.
8399 .PP
8400 After generating all of the possible completions,
8401 \fBbash\fP applies any filter
8402 specified with the \fB\-X\fP option to the completions in the list.
8403 The filter is a pattern as used for pathname expansion; a \fB&\fP
8404 in the pattern is replaced with the text of the word being completed.
8405 A literal \fB&\fP may be escaped with a backslash; the backslash
8406 is removed before attempting a match.
8407 Any completion that matches the pattern is removed from the list.
8408 A leading \fB!\fP negates the pattern;
8409 in this case \fBbash\fP removes
8410 any completion that does not match the pattern.
8411 If the
8412 .B nocasematch
8413 shell option is enabled,
8414 \fBbash\fP performs the match without regard to the case
8415 of alphabetic characters.
8416 .PP
8417 Finally, programmable completion adds
8418 any prefix and suffix specified with the
8419 \fB\-P\fP and \fB\-S\fP
8420 options, respectively, to each completion,
8421 and returns the result
8422 to \fBreadline\fP as the list of possible completions.
8423 .PP
8424 If the previously-applied actions do not generate any matches, and the
8425 \fB\-o dirnames\fP option was supplied to \fBcomplete\fP when the
8426 compspec was defined, \fBbash\fP attempts directory name completion.
8427 .PP
8428 If the \fB\-o plusdirs\fP option was supplied to \fBcomplete\fP when the
8429 compspec was defined, \fBbash\fP attempts directory name completion and
8430 adds any matches to the set of possible completions.
8431 .PP
8432 By default, if a compspec is found, whatever it generates is returned
8433 to the completion code as the full set of possible completions.
8434 The default \fBbash\fP completions and the \fBreadline\fP
8435 default of filename completion are disabled.
8436 If the \fB\-o bashdefault\fP option was supplied to \fBcomplete\fP when
8437 the compspec was defined,
8438 and the compspec generates no matches,
8439 \fBbash\fP attempts its default completions.
8440 If the compspec and, if attempted, the default \fBbash\fP completions
8441 generate no matches,
8442 and the \fB\-o default\fP option was supplied to
8443 \fBcomplete\fP when the compspec was defined,
8444 programmable completion performs \fBreadline\fP's default completion.
8445 .PP
8446 The options supplied to \fBcomplete\fP and \fBcompopt\fP
8447 can control how \fBreadline\fP treats the completions.
8448 For instance, the \fI\-o fullquote\fP option tells \fBreadline\fP
8449 to quote the matches as if they were filenames.
8450 See the description of \fBcomplete\fP below
8451 for details.
8452 .PP
8453 When a compspec indicates that it wants directory name completion,
8454 the programmable completion functions force \fBreadline\fP
8455 to append a slash to completed names which are symbolic links
8456 to directories, subject to the value of the
8457 \fBmark\-directories\fP \fBreadline\fP variable,
8458 regardless of the setting of the
8459 \fBmark-symlinked\-directories\fP \fBreadline\fP variable.
8460 .PP
8461 There is some support for dynamically modifying completions.
8462 This is most useful when used in combination with a default completion
8463 specified with \fBcomplete \-D\fP.
8464 It's possible for shell functions executed as completion functions
8465 to indicate that completion should be retried by returning an
8466 exit status of 124.
8467 If a shell function returns 124, and changes
8468 the compspec associated with the command on which completion is being
8469 attempted (supplied as the first argument when the function is executed),
8470 programmable completion restarts from the beginning, with an
8471 attempt to find a new compspec for that command.
8472 This can be used to build a set of completions dynamically
8473 as completion is attempted, rather than loading them all at once.
8474 .PP
8475 For instance, assuming that there is a library of compspecs, each kept in a
8476 file corresponding to the name of the command, the following default
8477 completion function would load completions dynamically:
8478 .RS
8479 .EX
8480 .nf
8481 _completion_loader()
8482 {
8483 . \*"/etc/bash_completion.d/$1.sh\*" \c
8484 .if \n(LL<80n \{\
8485 \e
8486 .br
8487 .ti +4n
8488 .\}
8489 >/dev/null 2>&1 && return 124
8490 }
8491 complete \-D \-F _completion_loader \c
8492 .if \n(LL<80n \{\
8493 \e
8494 .br
8495 .ti +4n
8496 .\}
8497 \-o bashdefault \-o default
8498 .fi
8499 .EE
8500 .RE
8501 .SH HISTORY
8502 When the
8503 .B \-o history
8504 option to the
8505 .B set
8506 builtin is enabled, the shell provides access to the
8507 \fIcommand history\fP,
8508 the list of commands previously typed.
8509 The value of the
8510 .SM
8511 .B HISTSIZE
8512 variable is used as the
8513 number of commands to save in a history list:
8514 the shell saves the text of the last
8515 .SM
8516 .B HISTSIZE
8517 commands (default 500).
8518 The shell stores each command in the history list prior to
8519 parameter and variable expansion (see
8520 .SM
8521 .B EXPANSION
8522 above) but after history expansion is performed, subject to the
8523 values of the shell variables
8524 .SM
8525 .B HISTIGNORE
8526 and
8527 .SM
8528 .BR HISTCONTROL .
8529 .PP
8530 On startup, \fBbash\fP initializes the history list
8531 by reading history entries from the
8532 file named by the
8533 .SM
8534 .B HISTFILE
8535 variable (default
8536 .FN \*~/.bash_history ).
8537 That file is referred to as the \fIhistory file\fP.
8538 The history file is truncated, if necessary,
8539 to contain no more than the number of history entries
8540 specified by the value of the
8541 .SM
8542 .B HISTFILESIZE
8543 variable.
8544 If
8545 .SM
8546 .B HISTFILESIZE
8547 is unset, or set to null, a non-numeric value,
8548 or a numeric value less than zero, the history file is not truncated.
8549 .PP
8550 When the history file is read,
8551 lines beginning with the history comment character followed immediately
8552 by a digit are interpreted as timestamps for the following history line.
8553 These timestamps are optionally displayed depending on the value of the
8554 .SM
8555 .B HISTTIMEFORMAT
8556 variable.
8557 When present, history timestamps delimit history entries, making
8558 multi-line entries possible.
8559 .PP
8560 When a shell with history enabled exits, \fBbash\fP copies the last
8561 .SM
8562 .B $HISTSIZE
8563 entries from the history list to
8564 .SM
8565 .BR $HISTFILE .
8566 If the
8567 .B histappend
8568 shell option is enabled
8569 (see the description of
8570 .B shopt
8571 under
8572 .SM
8573 .B "SHELL BUILTIN COMMANDS"
8574 below), \fBbash\fP appends the entries to the history file,
8575 otherwise it overwrites the history file.
8576 If
8577 .SM
8578 .B HISTFILE
8579 is unset or null,
8580 or if the history file is unwritable, the history is not saved.
8581 After saving the history, \fBbash\fP truncates the history file
8582 to contain no more than
8583 .SM
8584 .B HISTFILESIZE
8585 lines as described above.
8586 .PP
8587 If the
8588 .SM
8589 .B HISTTIMEFORMAT
8590 variable is set, the shell writes
8591 the timestamp information
8592 associated with each history entry to the history file,
8593 marked with the history comment character, so
8594 timestamps are preserved across shell sessions.
8595 This uses the history comment character to distinguish timestamps from
8596 other history lines.
8597 As above, when using
8598 .SM
8599 .BR HISTTIMEFORMAT ,
8600 the timestamps delimit multi-line history entries.
8601 .PP
8602 The
8603 .B fc
8604 builtin command (see
8605 .SM
8606 .B "SHELL BUILTIN COMMANDS"
8607 below) will list or edit and re-execute a portion of the history list.
8608 The
8609 .B history
8610 builtin can display or modify the history list and
8611 manipulate the history file.
8612 When using command-line editing, search commands
8613 are available in each editing mode that provide access to the
8614 history list.
8615 .PP
8616 The shell allows control over which commands are saved on the history list.
8617 The
8618 .SM
8619 .B HISTCONTROL
8620 and
8621 .SM
8622 .B HISTIGNORE
8623 variables are used to save only a subset of the commands entered.
8624 If the
8625 .B cmdhist
8626 shell option is enabled, the shell attempts to save each
8627 line of a multi-line command in the same history entry, adding
8628 semicolons where necessary to preserve syntactic correctness.
8629 The
8630 .B lithist
8631 shell option modifies \fBcmdhist\fP by saving
8632 the command with embedded newlines instead of semicolons.
8633 See the description of the
8634 .B shopt
8635 builtin below under
8636 .SM
8637 .B "SHELL BUILTIN COMMANDS"
8638 for information on setting and unsetting shell options.
8639 .SH "HISTORY EXPANSION"
8640 The shell supports a history expansion feature that
8641 is similar to the history expansion in
8642 .BR csh .
8643 This section describes what syntax features are available.
8644 .PP
8645 History expansion is enabled by default for interactive shells,
8646 and can be disabled using the
8647 .B +H
8648 option to the
8649 .B set
8650 builtin command (see
8651 .SM
8652 .B "SHELL BUILTIN COMMANDS"
8653 below).
8654 Non-interactive shells do not perform history expansion by default,
8655 but it can be enabled with
8656 .Q "set -H" .
8657 .PP
8658 History expansions introduce words from the history list into
8659 the input stream, making it easy to repeat commands, insert the
8660 arguments to a previous command into the current input line, or
8661 fix errors in previous commands quickly.
8662 .PP
8663 History expansion is performed immediately after a complete line
8664 is read, before the shell breaks it into words, and is performed
8665 on each line individually.
8666 The shell attempts to inform the history
8667 expansion functions about quoting still in effect from previous lines.
8668 .PP
8669 It takes place in two parts.
8670 The first is to determine which history list entry
8671 to use during substitution.
8672 The second is to select portions of that entry to include into
8673 the current one.
8674 .PP
8675 The entry selected from the history is the \fIevent\fP,
8676 and the portions of that entry that are acted upon are \fIwords\fP.
8677 Various \fImodifiers\fP are available to manipulate the selected words.
8678 The entry is split into words in the same fashion as when reading input,
8679 so that several \fImetacharacter\fP-separated words surrounded by
8680 quotes are considered one word.
8681 The \fIevent designator\fP selects the event, the optional
8682 \fIword designator\fP selects words from the event, and
8683 various optional \fImodifiers\fP are available to manipulate the
8684 selected words.
8685 .PP
8686 History expansions are introduced by the appearance of the
8687 history expansion character, which is \^\fB!\fP\^ by default.
8688 History expansions may appear anywhere in the input, but do not nest.
8689 .PP
8690 Only backslash (\^\fB\e\fP\^) and single quotes can quote
8691 the history expansion character, but the history expansion character is
8692 also treated as quoted if it immediately precedes the closing double quote
8693 in a double-quoted string.
8694 .PP
8695 Several characters inhibit history expansion if found immediately
8696 following the history expansion character, even if it is unquoted:
8697 space, tab, newline, carriage return, \fB=\fP,
8698 and the other shell metacharacters defined above.
8699 .PP
8700 There is a special abbreviation for substitution, active when the
8701 \fIquick substitution\fP character (described above under
8702 .BR histchars )
8703 is the first character on the line.
8704 It selects the previous history list entry, using an event designator
8705 equivalent to \fB!!\fP,
8706 and substitutes one string for another in that entry.
8707 It is described below under \fBEvent Designators\fP.
8708 This is the only history expansion that does not begin with the history
8709 expansion character.
8710 .PP
8711 Several shell options settable with the
8712 .B shopt
8713 builtin will modify history expansion behavior
8714 (see the description of the
8715 .B shopt
8716 builtin below).and
8717 If the
8718 .B histverify
8719 shell option is enabled, and
8720 .B readline
8721 is being used, history substitutions are not immediately passed to
8722 the shell parser.
8723 Instead, the expanded line is reloaded into the
8724 .B readline
8725 editing buffer for further modification.
8726 If
8727 .B readline
8728 is being used, and the
8729 .B histreedit
8730 shell option is enabled, a failed history substitution is reloaded
8731 into the
8732 .B readline
8733 editing buffer for correction.
8734 .PP
8735 The
8736 .B \-p
8737 option to the
8738 .B history
8739 builtin command shows what a history expansion will
8740 do before using it.
8741 The
8742 .B \-s
8743 option to the
8744 .B history
8745 builtin will add commands to the end of the history list
8746 without actually executing them, so that they are available for
8747 subsequent recall.
8748 .PP
8749 The shell allows control of the various characters used by the
8750 history expansion mechanism (see the description of
8751 .B histchars
8752 above under
8753 .BR "Shell Variables" ).
8754 The shell uses
8755 the history comment character to mark history timestamps when
8756 writing the history file.
8757 .SS Event Designators
8758 An event designator is a reference to an entry in the history list.
8759 The event designator
8760 consists of the portion of the word beginning with the history
8761 expansion character and ending with the word designator if present,
8762 or the end of the word.
8763 Unless the reference is absolute, events are relative to the current
8764 position in the history list.
8765 .PP
8766 .PD 0
8767 .TP
8768 .B !
8769 Start a history substitution, except when followed by a
8770 .BR blank ,
8771 newline, carriage return, =,
8772 or, when the \fBextglob\fP shell option is enabled using
8773 the \fBshopt\fP builtin, (.
8774 .TP
8775 .B !\fIn\fP
8776 Refer to history list entry
8777 .IR n .
8778 .TP
8779 .B !\-\fIn\fP
8780 Refer to the current entry minus
8781 .IR n .
8782 .TP
8783 .B !!
8784 Refer to the previous entry.
8785 This is a synonym for
8786 .Q !\-1 .
8787 .TP
8788 .B !\fIstring\fP
8789 Refer to the most recent command preceding the current position in the
8790 history list starting with
8791 .IR string .
8792 .TP
8793 .B !?\fIstring\fR\fB[?]\fP
8794 Refer to the most recent command preceding the current position in the
8795 history list containing
8796 .IR string .
8797 The trailing \fB?\fP may be omitted if
8798 .I string
8799 is followed immediately by a newline.
8800 If \fIstring\fP is missing, this uses
8801 the string from the most recent search;
8802 it is an error if there is no previous search string.
8803 .TP
8804 .B \d\s+2\*^\s-2\u\fIstring1\fP\d\s+2\*^\s-2\u\fIstring2\fP\d\s+2\*^\s-2\u
8805 Quick substitution.
8806 Repeat the previous command, replacing
8807 .I string1
8808 with
8809 .IR string2 .
8810 Equivalent to
8811 .Q !!:s\d\s+2\*^\s-2\u\fIstring1\fP\d\s+2\*^\s-2\u\fIstring2\fP\d\s+2\*^\s-2\u
8812 (see \fBModifiers\fP below).
8813 .TP
8814 .B !#
8815 The entire command line typed so far.
8816 .PD
8817 .SS Word Designators
8818 Word designators are used to select desired words from the event.
8819 They are optional; if the word designator isn't supplied, the history
8820 expansion uses the entire event.
8821 A
8822 .B :
8823 separates the event specification from the word designator.
8824 It may be omitted if the word designator begins with a
8825 .BR \*^ ,
8826 .BR $ ,
8827 .BR * ,
8828 .BR \- ,
8829 or
8830 .BR % .
8831 Words are numbered from the beginning of the line,
8832 with the first word being denoted by 0 (zero).
8833 Words are inserted into the current line separated by single spaces.
8834 .PP
8835 .PD 0
8836 .TP
8837 .B 0 (zero)
8838 The zeroth word.
8839 For the shell, this is the command word.
8840 .TP
8841 .I n
8842 The \fIn\fPth word.
8843 .TP
8844 .B \*^
8845 The first argument: word 1.
8846 .TP
8847 .B $
8848 The last word.
8849 This is usually the last argument, but will expand to the
8850 zeroth word if there is only one word in the line.
8851 .TP
8852 .B %
8853 The first word matched by the most recent
8854 .Q ?\fIstring\fP?
8855 search,
8856 if the search string begins with a character that is part of a word.
8857 By default, searches begin at the end of each line and proceed to the
8858 beginning, so the first word matched is the one closest to the end of
8859 the line.
8860 .TP
8861 .I x\fB\-\fPy
8862 A range of words;
8863 .Q \-\fIy\fP
8864 abbreviates
8865 .Q 0\-\fIy\fP .
8866 .TP
8867 .B *
8868 All of the words but the zeroth.
8869 This is a synonym for
8870 .Q \fI1\-$\fP .
8871 It is not an error to use
8872 .B *
8873 if there is just one word in the event;
8874 it expands to the empty string in that case.
8875 .TP
8876 .B x*
8877 Abbreviates \fIx\-$\fP.
8878 .TP
8879 .B x\-
8880 Abbreviates \fIx\-$\fP like \fBx*\fP, but omits the last word.
8881 If \fBx\fP is missing, it defaults to 0.
8882 .PD
8883 .PP
8884 If a word designator is supplied without an event specification, the
8885 previous command is used as the event, equivalent to \fB!!\fP.
8886 .SS Modifiers
8887 After the optional word designator, the expansion may include a
8888 sequence of one or more of the following modifiers, each preceded by a
8889 .Q : .
8890 These modify, or edit, the word or words selected from the history event.
8891 .PP
8892 .PD 0
8893 .TP
8894 .B h
8895 Remove a trailing pathname component, leaving only the head.
8896 .TP
8897 .B t
8898 Remove all leading pathname components, leaving the tail.
8899 .TP
8900 .B r
8901 Remove a trailing suffix of the form \fI.xxx\fP, leaving the
8902 basename.
8903 .TP
8904 .B e
8905 Remove all but the trailing suffix.
8906 .TP
8907 .B p
8908 Print the new command but do not execute it.
8909 .TP
8910 .B q
8911 Quote the substituted words, escaping further substitutions.
8912 .TP
8913 .B x
8914 Quote the substituted words as with
8915 .BR q ,
8916 but break into words at
8917 .B blanks
8918 and newlines.
8919 The \fBq\fP and \fBx\fP modifiers are mutually exclusive;
8920 expansion uses the last one supplied.
8921 .TP
8922 .B s/\fIold\fP/\fInew\fP/
8923 Substitute
8924 .I new
8925 for the first occurrence of
8926 .I old
8927 in the event line.
8928 Any character may be used as the delimiter in place of /.
8929 The final delimiter is optional if it is the last character of the
8930 event line.
8931 A single backslash quotes the delimiter in
8932 .I old
8933 and
8934 .IR new .
8935 If & appears in
8936 .IR new ,
8937 it is replaced with
8938 .IR old .
8939 A single backslash quotes the &.
8940 If
8941 .I old
8942 is null, it is set to the last
8943 .I old
8944 substituted, or, if no previous history substitutions took place,
8945 the last
8946 .I string
8947 in a
8948 .B !?\fIstring\fP[?]
8949 search.
8950 If
8951 .I new
8952 is null, each matching
8953 .I old
8954 is deleted.
8955 .TP
8956 .B &
8957 Repeat the previous substitution.
8958 .TP
8959 .B g
8960 Cause changes to be applied over the entire event line.
8961 This is used in conjunction with
8962 .Q \fB:s\fP
8963 (e.g.,
8964 .Q \fB:gs/\fIold\fP/\fInew\fP/\fR )
8965 or
8966 .Q \fB:&\fP .
8967 If used with
8968 .Q \fB:s\fP ,
8969 any delimiter can be used in place of /,
8970 and the final delimiter is optional
8971 if it is the last character of the event line.
8972 An \fBa\fP may be used as a synonym for \fBg\fP.
8973 .TP
8974 .B G
8975 Apply the following
8976 .Q \fBs\fP
8977 or
8978 .Q \fB&\fP
8979 modifier once to each word in the event line.
8980 .PD
8981 .SH "SHELL BUILTIN COMMANDS"
8982 .\" start of bash_builtins
8983 .zZ
8984 .PP
8985 Unless otherwise noted, each builtin command documented in this
8986 section as accepting options preceded by
8987 .B \-
8988 accepts
8989 .B \-\-
8990 to signify the end of the options.
8991 The \fB:\fP, \fBtrue\fP, \fBfalse\fP, and \fBtest\fP/\fB[\fP builtins
8992 do not accept options and do not treat \fB\-\-\fP specially.
8993 The \fBexit\fP, \fBlogout\fP, \fBreturn\fP,
8994 \fBbreak\fP, \fBcontinue\fP, \fBlet\fP,
8995 and \fBshift\fP builtins accept and process arguments beginning with
8996 \fB\-\fP without requiring \fB\-\-\fP.
8997 Other builtins that accept arguments but are not specified as accepting
8998 options interpret arguments beginning with \fB\-\fP as invalid options and
8999 require \fB\-\-\fP to prevent this interpretation.
9000 .PP
9001 .PD 0
9002 .TP
9003 \fB:\fP [\fIarguments\fP]
9004 .PD
9005 No effect; the command does nothing beyond expanding
9006 .I arguments
9007 and performing any specified
9008 redirections.
9009 The return status is zero.
9010 .TP
9011 \fB\&.\&\fP [\fB\-p\fP \fIpath\fP] \fIfilename\fP [\fIarguments\fP]
9012 .PD 0
9013 .TP
9014 \fBsource\fP [\fB\-p\fP \fIpath\fP] \fIfilename\fP [\fIarguments\fP]
9015 .PD
9016 The \fB\&.\&\fP command (\fBsource\fP) reads and execute commands from
9017 .I filename
9018 in the current shell environment and returns the exit status of the
9019 last command executed from
9020 .IR filename .
9021 .IP
9022 If \fIfilename\fP does not contain a slash, \fB\&.\&\fP searches for it.
9023 If the \fB\-p\fP option is supplied, \fB\&.\&\fP treats \fIpath\fP
9024 as a colon-separated list of directories in which to find \fIfilename\fP;
9025 otherwise, \fB\&.\&\fP uses the entries in
9026 .SM
9027 .B PATH
9028 to find the directory containing
9029 .IR filename .
9030 \fIfilename\fP does not need to be executable.
9031 When \fBbash\fP is not in posix mode, it searches
9032 the current directory if \fIfilename\fP is not found in
9033 .SM
9034 .BR PATH ,
9035 but does not search the current directory if \fB\-p\fP is supplied.
9036 If the
9037 .B sourcepath
9038 option to the
9039 .B shopt
9040 builtin command is turned off, \fB\&.\&\fP does not search
9041 .SM
9042 .BR PATH .
9043 .IP
9044 If any \fIarguments\fP are supplied, they become the positional
9045 parameters when \fIfilename\fP is executed.
9046 Otherwise the positional parameters are unchanged.
9047 .IP
9048 If the \fB\-T\fP option is enabled, \fB.\fP inherits any trap on
9049 \fBDEBUG\fP; if it is not, any \fBDEBUG\fP trap string is saved and
9050 restored around the call to \fB.\fP, and \fB.\fP unsets the
9051 \fBDEBUG\fP trap while it executes.
9052 If \fB\-T\fP is not set, and the sourced file changes
9053 the \fBDEBUG\fP trap, the new value persists after \fB.\fP completes.
9054 The return status is the status of the last command executed from
9055 \fIfilename\fP (0 if no commands are executed), and non-zero if
9056 .I filename
9057 is not found or cannot be read.
9058 .TP
9059 \fBalias\fP [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] .\|.\|.]
9060 With no arguments or with the
9061 .B \-p
9062 option, \fBalias\fP prints the list of aliases in the form
9063 \fBalias\fP \fIname\fP=\fIvalue\fP on standard output.
9064 When arguments are supplied, define an alias for
9065 each \fIname\fP whose \fIvalue\fP is given.
9066 A trailing space in \fIvalue\fP causes the next word to be
9067 checked for alias substitution when the alias is expanded
9068 during command parsing.
9069 For each \fIname\fP in the argument list for which no \fIvalue\fP
9070 is supplied, print the name and value of the alias \fIname\fP.
9071 \fBalias\fP returns true unless a \fIname\fP is given
9072 (without a corresponding =\fIvalue\fP)
9073 for which no alias has been defined.
9074 .TP
9075 \fBbg\fP [\fIjobspec\fP .\|.\|.]
9076 Resume each suspended job \fIjobspec\fP in the background, as if it
9077 had been started with
9078 .BR & .
9079 If
9080 .I jobspec
9081 is not present, the shell uses its notion of the \fIcurrent job\fP.
9082 .B bg
9083 .I jobspec
9084 returns 0 unless run when job control is disabled or, when run with
9085 job control enabled, any specified \fIjobspec\fP was not found
9086 or was started without job control.
9087 .TP
9088 \fBbind\fP [\fB\-m\fP \fIkeymap\fP] [\fB\-lsvSVX\fP]
9089 .PD 0
9090 .TP
9091 \fBbind\fP [\fB\-m\fP \fIkeymap\fP] [\fB\-q\fP \fIfunction\fP] [\fB\-u\fP \fIfunction\fP] [\fB\-r\fP \fIkeyseq\fP]
9092 .TP
9093 \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-f\fP \fIfilename\fP
9094 .TP
9095 \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-x\fP \fIkeyseq\fP[:] \fIshell\-command\fP
9096 .TP
9097 \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fIkeyseq\fP:\fIfunction\-name\fP
9098 .TP
9099 \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-p\fP|\fB\-P\fP [\fIreadline\-command\fP]
9100 .TP
9101 \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fIkeyseq\fP:\fIreadline\-command\fP
9102 .TP
9103 \fBbind\fP \fIreadline-command-line\fP
9104 .PD
9105 Display current
9106 .B readline
9107 key and function bindings, bind a key sequence to a
9108 .B readline
9109 function or macro
9110 or to a shell command, or set a
9111 .B readline
9112 variable.
9113 Each non-option argument is a key binding or command as it would appear in a
9114 .B readline
9115 initialization file such as
9116 .IR .inputrc ,
9117 but each binding or command must be passed as a separate argument;
9118 e.g., \*'\*"\eC\-x\eC\-r\*": re\-read\-init\-file\*'.
9119 In the following descriptions, output available to be re-read is formatted
9120 as commands that would appear in a
9121 .B readline
9122 initialization file or that would be supplied as individual arguments to a
9123 .B bind
9124 command.
9125 Options, if supplied, have the following meanings:
9126 .RS
9127 .PD 0
9128 .TP
9129 .B \-m \fIkeymap\fP
9130 Use
9131 .I keymap
9132 as the keymap to be affected by the subsequent bindings.
9133 Acceptable
9134 .I keymap
9135 names are
9136 \fIemacs, emacs\-standard, emacs\-meta, emacs\-ctlx, vi,
9137 vi\-move, vi\-command\fP, and
9138 .IR vi\-insert .
9139 \fIvi\fP is equivalent to \fIvi\-command\fP
9140 (\fIvi\-move\fP is also a synonym);
9141 \fIemacs\fP is equivalent to \fIemacs\-standard\fP.
9142 .TP
9143 .B \-l
9144 List the names of all \fBreadline\fP functions.
9145 .TP
9146 .B \-p
9147 Display \fBreadline\fP function names and bindings in such a way
9148 that they can be
9149 used as an argument to a subsequent
9150 \fBbind\fP command or in a \fBreadline\fP initialization file.
9151 If arguments remain after option processing, \fBbind\fP treats
9152 them as \fBreadline\fP command names and restricts output to those names.
9153 .TP
9154 .B \-P
9155 List current \fBreadline\fP function names and bindings.
9156 If arguments remain after option processing, \fBbind\fP treats
9157 them as \fBreadline\fP command names and restricts output to those names.
9158 .TP
9159 .B \-s
9160 Display \fBreadline\fP key sequences bound to macros and the strings
9161 they output in such a way that they can be used
9162 as an argument to a subsequent \fBbind\fP command
9163 or in a \fBreadline\fP initialization file.
9164 .TP
9165 .B \-S
9166 Display \fBreadline\fP key sequences bound to macros and the strings
9167 they output.
9168 .TP
9169 .B \-v
9170 Display \fBreadline\fP variable names and values in such a way that they
9171 can be
9172 used as an argument to a subsequent
9173 \fBbind\fP command or in a \fBreadline\fP initialization file.
9174 .TP
9175 .B \-V
9176 List current \fBreadline\fP variable names and values.
9177 .TP
9178 .B \-f \fIfilename\fP
9179 Read key bindings from \fIfilename\fP.
9180 .TP
9181 .B \-q \fIfunction\fP
9182 Display key sequences that invoke the named \fBreadline\fP \fIfunction\fP.
9183 .TP
9184 .B \-u \fIfunction\fP
9185 Unbind all key sequences bound to the named \fBreadline\fP \fIfunction\fP.
9186 .TP
9187 .B \-r \fIkeyseq\fP
9188 Remove any current binding for \fIkeyseq\fP.
9189 .TP
9190 .B \-x \fIkeyseq\fP[: ]\fIshell\-command\fP
9191 Cause \fIshell\-command\fP to be executed whenever \fIkeyseq\fP is
9192 entered.
9193 The separator between \fIkeyseq\fP and \fIshell\-command\fP is either
9194 whitespace or a colon optionally followed by whitespace.
9195 If the separator is whitespace, \fIshell\-command\fP
9196 must be enclosed in double quotes and \fBreadline\fP expands any of its
9197 special backslash-escapes in \fIshell\-command\fP before saving it.
9198 If the separator is a colon, any enclosing double quotes are optional, and
9199 \fBreadline\fP does not expand the command string before saving it.
9200 Since the entire key binding expression must be a single argument, it
9201 should be enclosed in single quotes.
9202 When \fIshell\-command\fP is executed, the shell sets the
9203 .SM
9204 .B READLINE_LINE
9205 variable to the contents of the \fBreadline\fP line buffer and the
9206 .SM
9207 .B READLINE_POINT
9208 and
9209 .SM
9210 .B READLINE_MARK
9211 variables to the current location of the insertion point and the saved
9212 insertion point (the mark), respectively.
9213 The shell assigns any numeric argument the user supplied to the
9214 .SM
9215 .B READLINE_ARGUMENT
9216 variable.
9217 If there was no argument, that variable is not set.
9218 If the executed command changes the value of any of
9219 .SM
9220 .BR READLINE_LINE ,
9221 .SM
9222 .BR READLINE_POINT ,
9223 or
9224 .SM
9225 .BR READLINE_MARK ,
9226 those new values will be reflected in the editing state.
9227 .TP
9228 .B \-X
9229 List all key sequences bound to shell commands and the associated commands
9230 in a format that can be reused as
9231 an argument to a subsequent \fBbind\fP command.
9232 .PD
9233 .PP
9234 The return value is 0 unless an unrecognized option is supplied or an
9235 error occurred.
9236 .RE
9237 .TP
9238 \fBbreak\fP [\fIn\fP]
9239 Exit from within a
9240 .BR for ,
9241 .BR while ,
9242 .BR until ,
9243 or
9244 .B select
9245 loop.
9246 If \fIn\fP is specified, \fBbreak\fP exits \fIn\fP enclosing loops.
9247 .I n
9248 must be \(>= 1. If
9249 .I n
9250 is greater than the number of enclosing loops, all enclosing loops
9251 are exited.
9252 The return value is 0 unless \fIn\fP is not greater than or equal to 1.
9253 .TP
9254 \fBbuiltin\fP \fIshell\-builtin\fP [\fIarguments\fP]
9255 Execute the specified shell builtin \fIshell\-builtin\fP, passing it
9256 .IR arguments ,
9257 and return its exit status.
9258 This is useful when defining a
9259 function whose name is the same as a shell builtin,
9260 retaining the functionality of the builtin within the function.
9261 The \fBcd\fP builtin is commonly redefined this way.
9262 The return status is false if
9263 .I shell\-builtin
9264 is not a shell builtin command.
9265 .TP
9266 \fBcaller\fP [\fIexpr\fP]
9267 Returns the context of any active subroutine call (a shell function or
9268 a script executed with the \fB.\fP or \fBsource\fP builtins).
9269 .IP
9270 Without \fIexpr\fP, \fBcaller\fP displays the line number and source
9271 filename of the current subroutine call.
9272 If a non-negative integer is supplied as \fIexpr\fP, \fBcaller\fP
9273 displays the line number, subroutine name, and source file corresponding
9274 to that position in the current execution call stack.
9275 This extra information may be used, for example, to print a stack trace.
9276 The current frame is frame 0.
9277 .IP
9278 The return value is 0 unless the shell is not executing a subroutine
9279 call or \fIexpr\fP does not correspond to a valid position in the
9280 call stack.
9281 .TP
9282 .PD 0
9283 \fBcd\fP [\fB\-L\fP] [\fB\-@\fP] [\fIdir\fP]
9284 .TP
9285 \fBcd\fP \fB\-P\fP [\fB\-e\fP] [\fB\-@\fP] [\fIdir\fP]
9286 .PD
9287 Change the current directory to \fIdir\fP.
9288 if \fIdir\fP is not supplied, the value of the
9289 .SM
9290 .B HOME
9291 shell variable is used as \fIdir\fP.
9292 The variable
9293 .SM
9294 .B CDPATH
9295 exists,
9296 and \fIdir\fP does not begin with a slash (/),
9297 \fBcd\fP uses it as a search path:
9298 the shell searches each directory name in
9299 .SM
9300 .B CDPATH
9301 for \fIdir\fP.
9302 Alternative directory names in
9303 .SM
9304 .B CDPATH
9305 are separated by a colon (:).
9306 A null directory name in
9307 .SM
9308 .B CDPATH
9309 is the same as the current directory, i.e.,
9310 .Q .\& .
9311 .IP
9312 The
9313 .B \-P
9314 option causes \fBcd\fP to use the physical directory structure
9315 by resolving symbolic links while traversing \fIdir\fP and
9316 before processing instances of
9317 .FN .\|.\&
9318 in \fIdir\fP (see also the
9319 .B \-P
9320 option to the
9321 .B set
9322 builtin command).
9323 .IP
9324 The
9325 .B \-L
9326 option forces \fBcd\fP to follow symbolic links by resolving the link
9327 after processing instances of
9328 .FN .\|.\&
9329 in \fIdir\fP.
9330 If
9331 .FN .\|.\&
9332 appears in \fIdir\fP, \fBcd\fP processes it by removing the
9333 immediately previous pathname component from \fIdir\fP, back to a slash
9334 or the beginning of \fIdir\fP,
9335 and verifying that the portion of \fIdir\fP it has processed to
9336 that point is still a valid directory name after removing the pathname
9337 component.
9338 If it is not a valid directory name, \fBcd\fP returns a non-zero status.
9339 If neither
9340 .B \-L
9341 nor
9342 .B \-P
9343 is supplied,
9344 .B cd
9345 behaves as if
9346 .B \-L
9347 had been supplied.
9348 .IP
9349 If the
9350 .B \-e
9351 option is supplied with
9352 .BR \-P ,
9353 and \fBcd\fP cannot successfully determine the current working directory
9354 after a successful directory change, it returns a non-zero status.
9355 .IP
9356 On systems that support it, the \fB\-@\fP option presents the extended
9357 attributes associated with a file as a directory.
9358 .IP
9359 An argument of
9360 .B \-
9361 is converted to
9362 .SM
9363 .B $OLDPWD
9364 before attempting the directory change.
9365 .IP
9366 If \fBcd\fP uses a non-empty directory name from
9367 .SM
9368 .BR CDPATH ,
9369 or if \fB\-\fP is the first argument, and the directory change is
9370 successful, \fBcd\fP writes the absolute pathname of the new
9371 working directory to the standard output.
9372 .IP
9373 If the directory change is successful, \fBcd\fP sets the value of the
9374 \fBPWD\fP environment variable to the new directory name, and sets the
9375 \fBOLDPWD\fP environment variable to the value of the current working
9376 directory before the change.
9377 .IP
9378 The return value is true if the directory was successfully changed;
9379 false otherwise.
9380 .TP
9381 \fBcommand\fP [\fB\-pVv\fP] \fIcommand\fP [\fIarg\fP .\|.\|.]
9382 The \fBcommand\fP builtin runs
9383 .I command
9384 with
9385 .I args
9386 suppressing the normal shell function lookup for \fIcommand\fP.
9387 Only builtin commands or commands found in the
9388 .SM
9389 .B PATH
9390 named \fIcommand\fP are executed.
9391 If the
9392 .B \-p
9393 option is supplied, the search for
9394 .I command
9395 is performed using a default value for
9396 .SM
9397 .B PATH
9398 that is guaranteed to find all of the standard utilities.
9399 .IP
9400 If either the
9401 .B \-V
9402 or
9403 .B \-v
9404 option is supplied, \fBcommand\fP prints a description of
9405 .IR command .
9406 The
9407 .B \-v
9408 option displays a single word indicating the command or filename
9409 used to invoke
9410 .IR command ;
9411 the
9412 .B \-V
9413 option produces a more verbose description.
9414 .IP
9415 If the
9416 .B \-V
9417 or
9418 .B \-v
9419 option is supplied, the exit status is zero if
9420 .I command
9421 was found, and non-zero if not.
9422 If neither option is supplied and an error occurred or
9423 .I command
9424 cannot be found, the exit status is 127.
9425 Otherwise, the exit status of the
9426 .B command
9427 builtin is the exit status of
9428 .IR command .
9429 .TP
9430 \fBcompgen\fP [\fB\-V\fP \fIvarname\fP] [\fIoption\fP] [\fIword\fP]
9431 Generate possible completion matches for \fIword\fP according to
9432 the \fIoption\fPs, which may be any option accepted by the
9433 .B complete
9434 builtin with the exceptions of
9435 .BR \-p ,
9436 .BR \-r ,
9437 .BR \-D ,
9438 .BR \-E ,
9439 and
9440 .BR \-I ,
9441 and write the matches to the standard output.
9442 .IP
9443 If the \fB\-V\fP option is supplied, \fBcompgen\fP stores the generated
9444 completions into the indexed array variable \fIvarname\fP instead of writing
9445 them to the standard output.
9446 .IP
9447 When using the \fB\-F\fP or \fB\-C\fP options, the various shell variables
9448 set by the programmable completion facilities, while available, will not
9449 have useful values.
9450 .IP
9451 The matches will be generated in the same way as if the programmable
9452 completion code had generated them directly from a completion specification
9453 with the same flags.
9454 If \fIword\fP is specified, only those completions matching \fIword\fP
9455 will be displayed or stored.
9456 .IP
9457 The return value is true unless an invalid option is supplied, or no
9458 matches were generated.
9459 .TP
9460 \fBcomplete\fP [\fB\-abcdefgjksuv\fP] [\fB\-o\fP \fIcomp-option\fP] [\fB\-DEI\fP] [\fB\-A\fP \fIaction\fP]
9461 .br
9462 [\fB\-G\fP \fIglobpat\fP] [\fB\-W\fP \fIwordlist\fP] [\fB\-F\fP \fIfunction\fP] [\fB\-C\fP \fIcommand\fP]
9463 .br
9464 [\fB\-X\fP \fIfilterpat\fP] [\fB\-P\fP \fIprefix\fP] \
9465 [\fB\-S\fP \fIsuffix\fP] \fIname\fP [\fIname\fP .\|.\|.]
9466 .PD 0
9467 .TP
9468 \fBcomplete\fP \fB\-pr\fP [\fB\-DEI\fP] [\fIname\fP .\|.\|.]
9469 .PD
9470 Specify how arguments to each \fIname\fP should be completed.
9471 .IP
9472 If the \fB\-p\fP option is supplied, or if no options or \fIname\fPs
9473 are supplied, print existing completion specifications
9474 in a way that allows them to be reused as input.
9475 The \fB\-r\fP option removes a completion specification for
9476 each \fIname\fP, or, if no \fIname\fPs are supplied, all
9477 completion specifications.
9478 .IP
9479 The \fB\-D\fP option indicates that other supplied options and actions should
9480 apply to the
9481 .Q default
9482 command completion; that is, completion attempted
9483 on a command for which no completion has previously been defined.
9484 The \fB\-E\fP option indicates that other supplied options and actions should
9485 apply to
9486 .Q empty
9487 command completion; that is, completion attempted on a
9488 blank line.
9489 The \fB\-I\fP option indicates that other supplied options and actions should
9490 apply to completion on the initial non-assignment word on the line, or after
9491 a command delimiter such as \fB;\fP or \fB|\fP, which is usually command
9492 name completion.
9493 If multiple options are supplied, the \fB\-D\fP option takes precedence
9494 over \fB\-E\fP, and both take precedence over \fB\-I\fP.
9495 If any of \fB\-D\fP, \fB\-E\fP, or \fB\-I\fP are supplied, any other
9496 \fIname\fP arguments are ignored; these completions only apply to the case
9497 specified by the option.
9498 .IP
9499 The process of applying these completion specifications when
9500 attempting word completion is described
9501 .ie \n(zZ=1 in \fIbash\fP(1).
9502 .el above under \fBProgrammable Completion\fP.
9503 .IP
9504 Other options, if specified, have the following meanings.
9505 The arguments to the \fB\-G\fP, \fB\-W\fP, and \fB\-X\fP options
9506 (and, if necessary, the \fB\-P\fP and \fB\-S\fP options)
9507 should be quoted to protect them from expansion before the
9508 .B complete
9509 builtin is invoked.
9510 .IP
9511 .RS
9512 .PD 0
9513 .TP 8
9514 \fB\-o\fP \fIcomp-option\fP
9515 The \fIcomp-option\fP controls several aspects of the compspec's behavior
9516 beyond the simple generation of completions.
9517 \fIcomp-option\fP may be one of:
9518 .RS
9519 .TP 8
9520 .B bashdefault
9521 Perform the rest of the default \fBbash\fP completions if the compspec
9522 generates no matches.
9523 .TP 8
9524 .B default
9525 Use \fBreadline\fP's default filename completion if the compspec generates
9526 no matches.
9527 .TP 8
9528 .B dirnames
9529 Perform directory name completion if the compspec generates no matches.
9530 .TP 8
9531 .B filenames
9532 Tell \fBreadline\fP that the compspec generates filenames, so it can perform
9533 any filename\-specific processing (such as adding a slash to directory names,
9534 quoting special characters, or suppressing trailing spaces).
9535 This is intended to be used with shell functions.
9536 .TP 8
9537 .B fullquote
9538 Tell \fBreadline\fP to quote all the completed words even if they are not
9539 filenames.
9540 .TP 8
9541 .B noquote
9542 Tell \fBreadline\fP not to quote the completed words if they are filenames
9543 (quoting filenames is the default).
9544 .TP 8
9545 .B nosort
9546 Tell \fBreadline\fP not to sort the list of possible completions
9547 alphabetically.
9548 .TP 8
9549 .B nospace
9550 Tell \fBreadline\fP not to append a space (the default) to words completed
9551 at the end of the line.
9552 .TP 8
9553 .B plusdirs
9554 After generating any matches defined by the compspec,
9555 attempt directory name completion and add any
9556 matches to the results of the other actions.
9557 .RE
9558 .TP 8
9559 \fB\-A\fP \fIaction\fP
9560 The \fIaction\fP may be one of the following to generate a list of possible
9561 completions:
9562 .RS
9563 .TP 8
9564 .B alias
9565 Alias names.
9566 May also be specified as \fB\-a\fP.
9567 .TP 8
9568 .B arrayvar
9569 Array variable names.
9570 .TP 8
9571 .B binding
9572 \fBReadline\fP key binding names.
9573 .TP 8
9574 .B builtin
9575 Names of shell builtin commands.
9576 May also be specified as \fB\-b\fP.
9577 .TP 8
9578 .B command
9579 Command names.
9580 May also be specified as \fB\-c\fP.
9581 .TP 8
9582 .B directory
9583 Directory names.
9584 May also be specified as \fB\-d\fP.
9585 .TP 8
9586 .B disabled
9587 Names of disabled shell builtins.
9588 .TP 8
9589 .B enabled
9590 Names of enabled shell builtins.
9591 .TP 8
9592 .B export
9593 Names of exported shell variables.
9594 May also be specified as \fB\-e\fP.
9595 .TP 8
9596 .B file
9597 File and directory names, similar to \fBreadline\fP's filename completion.
9598 May also be specified as \fB\-f\fP.
9599 .TP 8
9600 .B function
9601 Names of shell functions.
9602 .TP 8
9603 .B group
9604 Group names.
9605 May also be specified as \fB\-g\fP.
9606 .TP 8
9607 .B helptopic
9608 Help topics as accepted by the \fBhelp\fP builtin.
9609 .TP 8
9610 .B hostname
9611 Hostnames, as taken from the file specified by the
9612 .SM
9613 .B HOSTFILE
9614 shell variable.
9615 .TP 8
9616 .B job
9617 Job names, if job control is active.
9618 May also be specified as \fB\-j\fP.
9619 .TP 8
9620 .B keyword
9621 Shell reserved words.
9622 May also be specified as \fB\-k\fP.
9623 .TP 8
9624 .B running
9625 Names of running jobs, if job control is active.
9626 .TP 8
9627 .B service
9628 Service names.
9629 May also be specified as \fB\-s\fP.
9630 .TP 8
9631 .B setopt
9632 Valid arguments for the \fB\-o\fP option to the \fBset\fP builtin.
9633 .TP 8
9634 .B shopt
9635 Shell option names as accepted by the \fBshopt\fP builtin.
9636 .TP 8
9637 .B signal
9638 Signal names.
9639 .TP 8
9640 .B stopped
9641 Names of stopped jobs, if job control is active.
9642 .TP 8
9643 .B user
9644 User names.
9645 May also be specified as \fB\-u\fP.
9646 .TP 8
9647 .B variable
9648 Names of all shell variables.
9649 May also be specified as \fB\-v\fP.
9650 .RE
9651 .TP 8
9652 \fB\-C\fP \fIcommand\fP
9653 \fIcommand\fP is executed in a subshell environment, and its output is
9654 used as the possible completions.
9655 Arguments are passed as with the \fB\-F\fP option.
9656 .TP 8
9657 \fB\-F\fP \fIfunction\fP
9658 The shell function \fIfunction\fP is executed in the current shell
9659 environment.
9660 When the function is executed,
9661 the first argument (\fB$1\fP) is the name of the command whose arguments are
9662 being completed,
9663 the second argument (\fB$2\fP) is the word being completed, and
9664 the third argument (\fB$3\fP) is the word preceding the word being
9665 completed on the current command line.
9666 When \fIfunction\fP finishes,
9667 programmable completion retrieves
9668 the possible completions from the value of the
9669 .SM
9670 .B COMPREPLY
9671 array variable.
9672 .TP 8
9673 \fB\-G\fP \fIglobpat\fP
9674 Expand the pathname expansion pattern \fIglobpat\fP to generate
9675 the possible completions.
9676 .TP 8
9677 \fB\-P\fP \fIprefix\fP
9678 Add \fIprefix\fP to the beginning of each possible completion
9679 after all other options have been applied.
9680 .TP 8
9681 \fB\-S\fP \fIsuffix\fP
9682 Append \fIsuffix\fP to each possible completion
9683 after all other options have been applied.
9684 .TP 8
9685 \fB\-W\fP \fIwordlist\fP
9686 Split the \fIwordlist\fP using the characters in the
9687 .SM
9688 .B IFS
9689 special variable as delimiters, and expand each resulting word.
9690 Shell quoting is honored within \fIwordlist\fP,
9691 in order to provide a
9692 mechanism for the words to contain shell metacharacters or characters
9693 in the value of
9694 .SM
9695 .BR IFS .
9696 The possible completions are the members of the resultant list which
9697 match a prefix of the word being completed.
9698 .TP 8
9699 \fB\-X\fP \fIfilterpat\fP
9700 \fIfilterpat\fP is a pattern as used for pathname expansion.
9701 It is applied to the list of possible completions generated by the
9702 preceding options and arguments, and each completion matching
9703 \fIfilterpat\fP is removed from the list.
9704 A leading \fB!\fP in \fIfilterpat\fP negates the pattern; in this
9705 case, any completion not matching \fIfilterpat\fP is removed.
9706 .PD
9707 .PP
9708 The return value is true unless an invalid option is supplied, an option
9709 other than
9710 .BR \-p ,
9711 .BR \-r ,
9712 .BR \-D ,
9713 .BR \-E ,
9714 or
9715 .B \-I
9716 is supplied without a \fIname\fP
9717 argument, an attempt is made to remove a completion specification for
9718 a \fIname\fP for which no specification exists, or
9719 an error occurs adding a completion specification.
9720 .RE
9721 .TP
9722 \fBcompopt\fP [\fB\-o\fP \fIoption\fP] [\fB\-DEI\fP] [\fB+o\fP \fIoption\fP] [\fIname\fP]
9723 Modify completion options for each \fIname\fP according to the
9724 \fIoption\fPs, or for the
9725 currently-executing completion if no \fIname\fPs are supplied.
9726 If no \fIoption\fPs are supplied, display the completion options for each
9727 \fIname\fP or the current completion.
9728 The possible values of \fIoption\fP are those valid for the \fBcomplete\fP
9729 builtin described above.
9730 .IP
9731 The \fB\-D\fP option indicates that other supplied options should
9732 apply to the
9733 .Q default
9734 command completion;
9735 the \fB\-E\fP option indicates that other supplied options should
9736 apply to
9737 .Q empty
9738 command completion; and
9739 the \fB\-I\fP option indicates that other supplied options should
9740 apply to completion on the initial word on the line.
9741 These are determined in the same way as the \fBcomplete\fP builtin.
9742 .IP
9743 If multiple options are supplied, the \fB\-D\fP option takes precedence
9744 over \fB\-E\fP, and both take precedence over \fB\-I\fP.
9745 .IP
9746 The return value is true unless an invalid option is supplied, an attempt
9747 is made to modify the options for a \fIname\fP for which no completion
9748 specification exists, or an output error occurs.
9749 .TP
9750 \fBcontinue\fP [\fIn\fP]
9751 \fBcontinue\fP resumes the next iteration of the enclosing
9752 .BR for ,
9753 .BR while ,
9754 .BR until ,
9755 or
9756 .B select
9757 loop.
9758 If
9759 .I n
9760 is specified, \fBbash\fP resumes the \fIn\fPth enclosing loop.
9761 .I n
9762 must be \(>= 1.
9763 If
9764 .I n
9765 is greater than the number of enclosing loops, the shell resumes
9766 the last enclosing loop
9767 (the
9768 .Q top-level
9769 loop).
9770 The return value is 0 unless \fIn\fP is not greater than or equal to 1.
9771 .TP
9772 \fBdeclare\fP [\fB\-aAfFgiIlnrtux\fP] [\fB\-p\fP] \
9773 [\fIname\fP[=\fIvalue\fP] .\|.\|.]
9774 .PD 0
9775 .TP
9776 \fBtypeset\fP [\fB\-aAfFgiIlnrtux\fP] [\fB\-p\fP] \
9777 [\fIname\fP[=\fIvalue\fP] .\|.\|.]
9778 .PD
9779 Declare variables and/or give them attributes.
9780 If no \fIname\fPs are given then display the values of variables
9781 or functions.
9782 The
9783 .B \-p
9784 option will display the attributes and values of each
9785 .IR name .
9786 When
9787 .B \-p
9788 is used with \fIname\fP arguments, additional options,
9789 other than \fB\-f\fP and \fB\-F\fP, are ignored.
9790 .IP
9791 When
9792 .B \-p
9793 is supplied without \fIname\fP arguments,
9794 \fBdeclare\fP will display the attributes and values
9795 of all variables having the attributes specified by the additional options.
9796 If no other options are supplied with \fB\-p\fP, \fBdeclare\fP will
9797 display the attributes and values of all shell variables.
9798 The \fB\-f\fP option restricts the display to shell functions.
9799 .IP
9800 The
9801 .B \-F
9802 option inhibits the display of function definitions; only the
9803 function name and attributes are printed.
9804 If the \fBextdebug\fP shell option is enabled using \fBshopt\fP,
9805 the source file name and line number where each \fIname\fP
9806 is defined are displayed as well.
9807 The
9808 .B \-F
9809 option implies
9810 .BR \-f .
9811 .IP
9812 The
9813 .B \-g
9814 option forces variables to be created or modified at the global scope,
9815 even when \fBdeclare\fP is executed in a shell function.
9816 It is ignored when \fBdeclare\fP is not executed in a shell function.
9817 .IP
9818 The
9819 .B \-I
9820 option causes local variables to inherit the attributes
9821 (except the \fInameref\fP attribute)
9822 and value of any existing variable with the same
9823 \fIname\fP at a surrounding scope.
9824 If there is no existing variable, the local variable is initially unset.
9825 .IP
9826 The following options can
9827 be used to restrict output to variables with the specified attribute or
9828 to give variables attributes:
9829 .RS
9830 .PD 0
9831 .TP
9832 .B \-a
9833 Each \fIname\fP is an indexed array variable (see
9834 .B Arrays
9835 .ie \n(zZ=1 in \fIbash\fP(1)).
9836 .el above).
9837 .TP
9838 .B \-A
9839 Each \fIname\fP is an associative array variable (see
9840 .B Arrays
9841 .ie \n(zZ=1 in \fIbash\fP(1)).
9842 .el above).
9843 .TP
9844 .B \-f
9845 Each \fIname\fP refers to a shell function.
9846 .TP
9847 .B \-i
9848 The variable is treated as an integer;
9849 arithmetic evaluation (see
9850 .SM
9851 .B "ARITHMETIC EVALUATION"
9852 .ie \n(zZ=1 in \fIbash\fP(1))
9853 .el above)
9854 is performed when the variable is assigned a value.
9855 .TP
9856 .B \-l
9857 When the variable is assigned a value, all upper-case characters are
9858 converted to lower-case.
9859 The upper-case attribute is disabled.
9860 .TP
9861 .B \-n
9862 Give each \fIname\fP the \fInameref\fP attribute, making
9863 it a name reference to another variable.
9864 That other variable is defined by the value of \fIname\fP.
9865 All references, assignments, and attribute modifications
9866 to \fIname\fP, except those using or changing the
9867 \fB\-n\fP attribute itself, are performed on the variable referenced by
9868 \fIname\fP's value.
9869 The nameref attribute cannot be applied to array variables.
9870 .TP
9871 .B \-r
9872 Make \fIname\fPs readonly.
9873 These names cannot then be assigned values
9874 by subsequent assignment statements or unset.
9875 .TP
9876 .B \-t
9877 Give each \fIname\fP the \fItrace\fP attribute.
9878 Traced functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps from
9879 the calling shell.
9880 The trace attribute has no special meaning for variables.
9881 .TP
9882 .B \-u
9883 When the variable is assigned a value, all lower-case characters are
9884 converted to upper-case.
9885 The lower-case attribute is disabled.
9886 .TP
9887 .B \-x
9888 Mark each \fIname\fP for export to subsequent commands via the environment.
9889 .PD
9890 .PP
9891 Using
9892 .Q +
9893 instead of
9894 .Q \-
9895 turns off the specified
9896 attribute instead, with the exceptions that \fB+a\fP and \fB+A\fP
9897 may not be used to destroy array variables and \fB+r\fP will not
9898 remove the readonly attribute.
9899 .PP
9900 When used in a function,
9901 .B declare
9902 and
9903 .B typeset
9904 make each
9905 \fIname\fP local, as with the
9906 .B local
9907 command,
9908 unless the \fB\-g\fP option is supplied.
9909 If a variable name is followed by =\fIvalue\fP, the value of
9910 the variable is set to \fIvalue\fP.
9911 When using \fB\-a\fP or \fB\-A\fP and the compound assignment syntax to
9912 create array variables, additional attributes do not take effect until
9913 subsequent assignments.
9914 .PP
9915 The return value is 0 unless an invalid option is encountered,
9916 an attempt is made to define a function using
9917 .Q "\-f foo=bar" ,
9918 an attempt is made to assign a value to a readonly variable,
9919 an attempt is made to assign a value to an array variable without
9920 using the compound assignment syntax (see
9921 .B Arrays
9922 .ie \n(zZ=1 in \fIbash\fP(1)),
9923 .el above),
9924 one of the \fInames\fP is not a valid shell variable name,
9925 an attempt is made to turn off readonly status for a readonly variable,
9926 an attempt is made to turn off array status for an array variable,
9927 or an attempt is made to display a non-existent function with \fB\-f\fP.
9928 .RE
9929 .TP
9930 .B dirs [\fB\-clpv\fP] [+\fIn\fP] [\-\fIn\fP]
9931 Without options, display the list of currently remembered directories.
9932 The default display is on a single line with directory names separated
9933 by spaces.
9934 Directories are added to the list with the
9935 .B pushd
9936 command; the
9937 .B popd
9938 command removes entries from the list.
9939 The current directory is always the first directory in the stack.
9940 .IP
9941 Options, if supplied, have the following meanings:
9942 .RS
9943 .PD 0
9944 .TP
9945 .B \-c
9946 Clears the directory stack by deleting all of the entries.
9947 .TP
9948 .B \-l
9949 Produces a listing using full pathnames;
9950 the default listing format uses a tilde to denote the home directory.
9951 .TP
9952 .B \-p
9953 Print the directory stack with one entry per line.
9954 .TP
9955 .B \-v
9956 Print the directory stack with one entry per line,
9957 prefixing each entry with its index in the stack.
9958 .TP
9959 \fB+\fP\fIn\fP
9960 Displays the \fIn\fPth entry counting from the left of the list
9961 shown by
9962 .B dirs
9963 when invoked without options, starting with zero.
9964 .TP
9965 \fB\-\fP\fIn\fP
9966 Displays the \fIn\fPth entry counting from the right of the list
9967 shown by
9968 .B dirs
9969 when invoked without options, starting with zero.
9970 .PD
9971 .PP
9972 The return value is 0 unless an
9973 invalid option is supplied or \fIn\fP indexes beyond the end
9974 of the directory stack.
9975 .RE
9976 .TP
9977 \fBdisown\fP [\fB\-ar\fP] [\fB\-h\fP] [\fIid\fP .\|.\|.]
9978 Without options, remove each
9979 .I id
9980 from the table of active jobs.
9981 Each \fIid\fP may be a job specification \fIjobspec\fP
9982 or a process ID \fIpid\fP;
9983 if \fIid\fP is a \fIpid\fP,
9984 \fBdisown\fP uses the job containing \fIpid\fP as \fIjobspec\fP.
9985 .IP
9986 If the \fB\-h\fP option is supplied,
9987 \fBdisown\fP does not remove the jobs corresponding to each
9988 .I id
9989 from the jobs table,
9990 but rather marks them so the shell does not send
9991 .SM
9992 .B SIGHUP
9993 to the job if the shell receives a
9994 .SM
9995 .BR SIGHUP .
9996 .IP
9997 If no
9998 .I id
9999 is supplied, the
10000 .B \-a
10001 option means to remove or mark all jobs; the
10002 .B \-r
10003 option without an
10004 .I id
10005 argument removes or marks running jobs.
10006 If no
10007 .I id
10008 is supplied, and neither the \fB\-a\fP nor the \fB\-r\fP option
10009 is supplied, \fBdisown\fP removes or marks the current job.
10010 .IP
10011 The return value is 0 unless an
10012 .I id
10013 does not specify a valid job.
10014 .TP
10015 \fBecho\fP [\fB\-neE\fP] [\fIarg\fP .\|.\|.]
10016 Output the \fIarg\fPs, separated by spaces, followed by a newline.
10017 The return status is 0 unless a write error occurs.
10018 If \fB\-n\fP is specified, the trailing newline is not printed.
10019 .IP
10020 If the \fB\-e\fP option is given, \fBecho\fP interprets
10021 the following backslash-escaped characters.
10022 The
10023 .B \-E
10024 option disables interpretation of these escape characters,
10025 even on systems where they are interpreted by default.
10026 The \fBxpg_echo\fP shell option determines
10027 whether or not \fBecho\fP interprets any options
10028 and expands these escape characters.
10029 .B echo
10030 does not interpret \fB\-\-\fP to mean the end of options.
10031 .IP
10032 .B echo
10033 interprets the following escape sequences:
10034 .RS
10035 .PD 0
10036 .TP
10037 .B \ea
10038 alert (bell)
10039 .TP
10040 .B \eb
10041 backspace
10042 .TP
10043 .B \ec
10044 suppress further output
10045 .TP
10046 .B \ee
10047 .TP
10048 .B \eE
10049 an escape character
10050 .TP
10051 .B \ef
10052 form feed
10053 .TP
10054 .B \en
10055 new line
10056 .TP
10057 .B \er
10058 carriage return
10059 .TP
10060 .B \et
10061 horizontal tab
10062 .TP
10063 .B \ev
10064 vertical tab
10065 .TP
10066 .B \e\e
10067 backslash
10068 .TP
10069 .B \e0\fInnn\fP
10070 The eight-bit character whose value is the octal value \fInnn\fP
10071 (zero to three octal digits).
10072 .TP
10073 .B \ex\fIHH\fP
10074 The eight-bit character whose value is the hexadecimal value \fIHH\fP
10075 (one or two hex digits).
10076 .TP
10077 .B \eu\fIHHHH\fP
10078 The Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
10079 \fIHHHH\fP (one to four hex digits).
10080 .TP
10081 .B \eU\fIHHHHHHHH\fP
10082 The Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
10083 \fIHHHHHHHH\fP (one to eight hex digits).
10084 .PD
10085 .PP
10086 \fBecho\fP writes any unrecognized backslash-escaped characters unchanged.
10087 .RE
10088 .TP
10089 \fBenable\fP [\fB\-a\fP] [\fB\-dnps\fP] [\fB\-f\fP \fIfilename\fP] \
10090 [\fIname\fP .\|.\|.]
10091 Enable and disable builtin shell commands.
10092 Disabling a builtin allows an executable file which has the same name
10093 as a shell builtin to be executed without specifying a full pathname,
10094 even though the shell normally searches for builtins before files.
10095 .IP
10096 If \fB\-n\fP is supplied, each \fIname\fP is disabled; otherwise,
10097 \fIname\fPs are enabled.
10098 For example, to use the
10099 .B test
10100 binary found using
10101 .SM
10102 .B PATH
10103 instead of the shell builtin version, run
10104 .QN "enable \-n test" .
10105 .IP
10106 If no \fIname\fP arguments are supplied, or if the
10107 .B \-p
10108 option is supplied, print a list of shell builtins.
10109 With no other option arguments, the list consists of all enabled
10110 shell builtins.
10111 If \fB\-n\fP is supplied, print only disabled builtins.
10112 If \fB\-a\fP is supplied, the list printed includes all builtins, with an
10113 indication of whether or not each is enabled.
10114 The \fB\-s\fP option means to restrict the output to the
10115 .SM POSIX
10116 \fIspecial\fP builtins.
10117 .IP
10118 The
10119 .B \-f
10120 option means to load the new builtin command
10121 .I name
10122 from shared object
10123 .IR filename ,
10124 on systems that support dynamic loading.
10125 If \fIfilename\fP does not contain a slash,
10126 \fBBash\fP will use the value of the \fBBASH_LOADABLES_PATH\fP variable as a
10127 colon-separated list of directories in which to search for \fIfilename\fP.
10128 The default for \fBBASH_LOADABLES_PATH\fP is system-dependent,
10129 and may include
10130 .Q .\&
10131 to force a search of the current directory.
10132 The
10133 .B \-d
10134 option will delete a builtin previously loaded with \fB\-f\fP.
10135 If \fI\-s\fP is used with \fI\-f\fP, the new builtin becomes a
10136 .SM POSIX
10137 special builtin.
10138 .IP
10139 If no options are supplied and a \fIname\fP is not a shell builtin,
10140 \fBenable\fP will attempt to load \fIname\fP from a shared
10141 object named \fIname\fP, as if the command were
10142 .QN "enable \-f \fIname name\fP" .
10143 .IP
10144 The return value is 0 unless a
10145 .I name
10146 is not a shell builtin or there is an error loading a new builtin
10147 from a shared object.
10148 .TP
10149 \fBeval\fP [\fIarg\fP .\|.\|.]
10150 Concatenate the \fIarg\fPs together into a single command, separating
10151 them with spaces.
10152 \fBBash\fP then reads and execute this command, and returns its exit status
10153 as the return status of \fBeval\fP.
10154 If there are no
10155 .IR args ,
10156 or only null arguments,
10157 .B eval
10158 returns 0.
10159 .TP
10160 \fBexec\fP [\fB\-cl\fP] [\fB\-a\fP \fIname\fP] [\fIcommand\fP [\fIarguments\fP]]
10161 If
10162 .I command
10163 is specified, it replaces the shell without creating a new process.
10164 \fIcommand\fP cannot be a shell builtin or function.
10165 The
10166 .I arguments
10167 become the arguments to \fIcommand\fP.
10168 If the
10169 .B \-l
10170 option is supplied,
10171 the shell places a dash at the beginning of the zeroth argument passed to
10172 .IR command .
10173 This is what
10174 .IR login (1)
10175 does. The
10176 .B \-c
10177 option causes
10178 .I command
10179 to be executed with an empty environment.
10180 If
10181 .B \-a
10182 is supplied, the shell passes
10183 .I name
10184 as the zeroth argument to the executed command.
10185 .IP
10186 If
10187 .I command
10188 cannot be executed for some reason, a non-interactive shell exits,
10189 unless the
10190 .B execfail
10191 shell option is enabled.
10192 In that case, it returns a non-zero status.
10193 An interactive shell returns a non-zero status if the file cannot be executed.
10194 A subshell exits unconditionally if \fBexec\fP fails.
10195 .IP
10196 If
10197 .I command
10198 is not specified, any redirections take effect in the current shell,
10199 and the return status is 0. If there is a redirection error, the
10200 return status is 1.
10201 .TP
10202 \fBexit\fP [\fIn\fP]
10203 Cause the shell to exit with a status of \fIn\fP.
10204 If
10205 .I n
10206 is omitted, the exit status is that of the last command executed.
10207 Any trap on
10208 .SM
10209 .B EXIT
10210 is executed before the shell terminates.
10211 .TP
10212 \fBexport\fP [\fB\-fn\fP\^] [\fIname\fP[=\fIvalue\fP]] .\|.\|.
10213 .PD 0
10214 .TP
10215 .B export \-p [\fB\-f\fP\^]
10216 .PD
10217 The supplied
10218 .I names
10219 are marked for automatic export to the environment of
10220 subsequently executed commands.
10221 If the
10222 .B \-f
10223 option is given, the
10224 .I names
10225 refer to functions.
10226 .IP
10227 The
10228 .B \-n
10229 option unexports, or removes the export attribute, from each \fIname\fP.
10230 If no
10231 .I names
10232 are given, or if only the
10233 .B \-p
10234 option is supplied,
10235 \fBexport\fP displays a list of names of all exported
10236 variables on the standard output.
10237 Using \fB\-p\fP and \fB\-f\fP together displays exported functions.
10238 The \fB\-p\fP option displays output in a form that may be reused as input.
10239 .IP
10240 \fBexport\fP allows the value of a variable to be set when it is exported
10241 or unexported by following the variable name with =\fIvalue\fP.
10242 This sets the value of the variable to \fIvalue\fP while modifying the
10243 export attribute.
10244 .B export
10245 returns an exit status of 0 unless an invalid option is
10246 encountered,
10247 one of the \fInames\fP is not a valid shell variable name, or
10248 .B \-f
10249 is supplied with a
10250 .I name
10251 that is not a function.
10252 .TP
10253 \fBfalse\fP
10254 Does nothing; returns a non-zero status.
10255 .TP
10256 \fBfc\fP [\fB\-e\fP \fIename\fP] [\fB\-lnr\fP] [\fIfirst\fP] [\fIlast\fP]
10257 .PD 0
10258 .TP
10259 \fBfc\fP \fB\-s\fP [\fIpat\fP=\fIrep\fP] [\fIcmd\fP]
10260 .PD
10261 The first form selects a range of commands from
10262 .I first
10263 to
10264 .I last
10265 from the history list and displays or edits and re-executes them.
10266 .I First
10267 and
10268 .I last
10269 may be specified as a string (to locate the last command beginning
10270 with that string) or as a number (an index into the history list,
10271 where a negative number is used as an offset from the current
10272 command number).
10273 .IP
10274 When listing, a \fIfirst\fP or \fIlast\fP of 0 is equivalent to \-1
10275 and \-0 is equivalent to the current command
10276 (usually the \fBfc\fP command);
10277 otherwise 0 is equivalent to \-1 and \-0 is invalid.
10278 If
10279 .I last
10280 is not specified, it is set to
10281 the current command for listing (so that
10282 .QN "fc \-l \-10"
10283 prints the last 10 commands) and to
10284 .I first
10285 otherwise.
10286 If
10287 .I first
10288 is not specified, it is set to the previous
10289 command for editing and \-16 for listing.
10290 .IP
10291 If the
10292 .B \-l
10293 option is supplied, the commands are listed on the standard output.
10294 The
10295 .B \-n
10296 option suppresses
10297 the command numbers when listing.
10298 The
10299 .B \-r
10300 option reverses the order of
10301 the commands.
10302 .IP
10303 Otherwise, \fBfc\fP invokes the editor named by
10304 .I ename
10305 on a file containing those commands.
10306 If
10307 .I ename
10308 is not supplied, \fBfc\fP uses the value of the
10309 .SM
10310 .B FCEDIT
10311 variable, and
10312 the value of
10313 .SM
10314 .B EDITOR
10315 if
10316 .SM
10317 .B FCEDIT
10318 is not set.
10319 If neither variable is set, \fBfc\fP uses
10320 .FN vi.
10321 When editing is complete, \fBfc\fP reads the file containing
10322 the edited commands and echoes and executes them.
10323 .IP
10324 In the second form, \fBfc\fP re-executes \fIcommand\fP
10325 after replacing each instance of \fIpat\fP with \fIrep\fP.
10326 \fICommand\fP is interpreted the same as \fIfirst\fP above.
10327 .IP
10328 A useful alias to use with \fBfc\fP is
10329 .Q "r=\*"fc \-s\*"" ,
10330 so that typing
10331 .Q "r cc"
10332 runs the last command beginning with
10333 .Q cc
10334 and typing
10335 .Q r
10336 re-executes the last command.
10337 .IP
10338 If the first form is used, the return value is zero unless an invalid
10339 option is encountered or
10340 .I first
10341 or
10342 .I last
10343 specify history lines out of range.
10344 When editing and re-executing a file of commands,
10345 the return value is the value of the last command executed
10346 or failure if an error occurs with the temporary file.
10347 If the second form is used, the return status
10348 is that of the re-executed command, unless
10349 .I cmd
10350 does not specify a valid history entry, in which case
10351 .B fc
10352 returns a non-zero status.
10353 .TP
10354 \fBfg\fP [\fIjobspec\fP]
10355 Resume
10356 .I jobspec
10357 in the foreground, and make it the current job.
10358 If
10359 .I jobspec
10360 is not present, \fBfg\fP uses the shell's notion of the \fIcurrent job\fP.
10361 The return value is that of the command placed into the foreground,
10362 or failure if run when job control is disabled or, when run with
10363 job control enabled, if
10364 .I jobspec
10365 does not specify a valid job or
10366 .I jobspec
10367 specifies a job that was started without job control.
10368 .TP
10369 \fBgetopts\fP \fIoptstring\fP \fIname\fP [\fIarg\fP .\|.\|.]
10370 .B getopts
10371 is used by shell scripts and functions to parse positional parameters
10372 and obtain options and their arguments.
10373 .I optstring
10374 contains the option characters to be recognized; if a character
10375 is followed by a colon, the option is expected to have an
10376 argument, which should be separated from it by white space.
10377 The colon and question mark characters may not be used as
10378 option characters.
10379 .IP
10380 Each time it is invoked,
10381 .B getopts
10382 places the next option in the shell variable
10383 .IR name ,
10384 initializing
10385 .I name
10386 if it does not exist,
10387 and the index of the next argument to be processed into the
10388 variable
10389 .SM
10390 .BR OPTIND .
10391 .SM
10392 .B OPTIND
10393 is initialized to 1 each time the shell or a shell script
10394 is invoked.
10395 When an option requires an argument,
10396 .B getopts
10397 places that argument into the variable
10398 .SM
10399 .BR OPTARG .
10400 .IP
10401 The shell does not reset
10402 .SM
10403 .B OPTIND
10404 automatically; it must be manually reset between multiple
10405 calls to
10406 .B getopts
10407 within the same shell invocation to use a new set of parameters.
10408 .IP
10409 When it reaches the end of options, \fBgetopts\fP exits with a
10410 return value greater than zero.
10411 .SM
10412 .B OPTIND
10413 is set to the index of the first non-option argument,
10414 and \fIname\fP is set to ?.
10415 .IP
10416 .B getopts
10417 normally parses the positional parameters, but if more arguments are
10418 supplied as
10419 .I arg
10420 values,
10421 .B getopts
10422 parses those instead.
10423 .IP
10424 .B getopts
10425 can report errors in two ways.
10426 If the first character of
10427 .I optstring
10428 is a colon, \fBgetopts\fP uses
10429 .I silent
10430 error reporting.
10431 In normal operation, \fBgetopts\fP prints diagnostic messages
10432 when it encounters invalid options or missing option arguments.
10433 If the variable
10434 .SM
10435 .B OPTERR
10436 is set to 0,
10437 .B getopts
10438 does not display any error messages,
10439 even if the first character of
10440 .I optstring
10441 is not a colon.
10442 .IP
10443 If
10444 .B getopts
10445 detects an invalid option, it places ? into
10446 .I name
10447 and, if not silent,
10448 prints an error message and unsets
10449 .SM
10450 .BR OPTARG .
10451 If
10452 .B getopts
10453 is silent, it assigns the option character found to
10454 .SM
10455 .B OPTARG
10456 and does not print a diagnostic message.
10457 .IP
10458 If a required argument is not found, and
10459 .B getopts
10460 is not silent, it sets the value of \fIname\fP to
10461 a question mark (\^\fB?\fP\^), unsets
10462 .SM
10463 .BR OPTARG ,
10464 and prints a diagnostic message.
10465 If
10466 .B getopts
10467 is silent, it sets the value of \fIname\fP to a colon (\^\fB:\fP\^)
10468 and sets
10469 .SM
10470 .B OPTARG
10471 to the option character found.
10472 .IP
10473 .B getopts
10474 returns true if an option, specified or unspecified, is found.
10475 It returns false if the end of options is encountered or an
10476 error occurs.
10477 .TP
10478 \fBhash\fP [\fB\-lr\fP] [\fB\-p\fP \fIfilename\fP] [\fB\-dt\fP] [\fIname\fP]
10479 Each time \fBhash\fP is invoked, it remembers
10480 the full pathname of the command
10481 .I name
10482 as determined by searching
10483 the directories in
10484 .BR $PATH .
10485 Any previously-remembered pathname associated with \fIname\fP is discarded.
10486 If the
10487 .B \-p
10488 option is supplied, \fBhash\fP uses
10489 .I filename
10490 as the full pathname of the command.
10491 .IP
10492 The
10493 .B \-r
10494 option causes the shell to forget all
10495 remembered locations.
10496 Assigning to the \fBPATH\fP variable also clears all hashed filenames.
10497 The
10498 .B \-d
10499 option causes the shell to forget the remembered location of each \fIname\fP.
10500 .IP
10501 If the
10502 .B \-t
10503 option is supplied, \fBhash\fP prints the full pathname corresponding to
10504 each \fIname\fP.
10505 If multiple \fIname\fP arguments are supplied with \fB\-t\fP,
10506 \fBhash\fP prints the \fIname\fP before the corresponding hashed
10507 full pathname.
10508 The
10509 .B \-l
10510 option displays output in a format that may be reused as input.
10511 .IP
10512 If no arguments are given, or if only \fB\-l\fP is supplied,
10513 \fBhash\fP prints information about remembered commands.
10514 The \fB\-t\fP, \fB\-d\fP, and \fB\-p\fP options (the options that
10515 act on the \fIname\fP arguments) are mutually exclusive.
10516 Only one will be active.
10517 If more than one is supplied, \fB\-t\fP has higher priority than
10518 \fB\-p\fP, and both have higher priority than \fB\-d\fP.
10519 .IP
10520 The return status is zero unless a
10521 .I name
10522 is not found or an invalid option is supplied.
10523 .TP
10524 \fBhelp\fP [\fB\-dms\fP] [\fIpattern\fP]
10525 Display helpful information about builtin commands.
10526 If
10527 .I pattern
10528 is specified,
10529 .B help
10530 gives detailed help on all commands matching
10531 .I pattern
10532 as described below;
10533 otherwise it displays a list of
10534 all the builtins and shell compound commands.
10535 .IP
10536 Options, if supplied, have the follow meanings:
10537 .RS
10538 .TP
10539 .PD 0
10540 .B \-d
10541 Display a short description of each \fIpattern\fP
10542 .TP
10543 .B \-m
10544 Display the description of each \fIpattern\fP in a manpage-like format
10545 .TP
10546 .B \-s
10547 Display only a short usage synopsis for each \fIpattern\fP
10548 .PD
10549 .RE
10550 .IP
10551 If \fIpattern\fP contains pattern matching characters
10552 (see
10553 .SM
10554 .B "Pattern Matching"
10555 above)
10556 it's treated as a shell pattern and
10557 \fBhelp\fP prints the description of each
10558 help topic matching \fIpattern\fP.
10559 .IP
10560 If not, and \fIpattern\fP exactly matches the name of a help topic,
10561 \fBhelp\fP prints the description
10562 associated with that topic.
10563 Otherwise, \fBhelp\fP performs prefix matching and
10564 prints the descriptions of all matching help topics.
10565 .IP
10566 The return status is 0 unless no command matches
10567 .IR pattern .
10568 .TP
10569 \fBhistory [\fIn\fP]
10570 .PD 0
10571 .TP
10572 \fBhistory\fP \fB\-c\fP
10573 .TP
10574 \fBhistory \-d\fP \fIoffset\fP
10575 .TP
10576 \fBhistory \-d\fP \fIstart\fP-\fIend\fP
10577 .TP
10578 \fBhistory\fP \fB\-anrw\fP [\fIfilename\fP]
10579 .TP
10580 \fBhistory\fP \fB\-p\fP \fIarg\fP [\fIarg\fP .\|.\|.]
10581 .TP
10582 \fBhistory\fP \fB\-s\fP \fIarg\fP [\fIarg\fP .\|.\|.]
10583 .PD
10584 With no options, display the command history list with numbers.
10585 Entries prefixed with a
10586 .B *
10587 have been modified.
10588 An argument of
10589 .I n
10590 lists only the last
10591 .I n
10592 entries.
10593 If the shell variable
10594 .SM
10595 .B HISTTIMEFORMAT
10596 is set and not null,
10597 it is used as a format string for
10598 .IR strftime (3)
10599 to display the time stamp associated with each displayed history entry.
10600 If
10601 .B history
10602 uses
10603 .SM
10604 .BR HISTTIMEFORMAT ,
10605 it does not print an intervening space between the formatted time stamp
10606 and the history entry.
10607 .IP
10608 If \fIfilename\fP is supplied, \fBhistory\fP uses it as the
10609 name of the history file; if not, it uses the value of
10610 .SM
10611 .BR HISTFILE .
10612 If \fIfilename\fP is not supplied and
10613 .SM
10614 .B HISTFILE
10615 is unset or null, the \fB\-a, \-n, \-r,\fP and \fB\-w\fP options
10616 have no effect.
10617 .IP
10618 Options, if supplied, have the following meanings:
10619 .RS
10620 .PD 0
10621 .TP
10622 .B \-c
10623 Clear the history list by deleting all the entries.
10624 This can be used with the other options to replace the history list.
10625 .TP
10626 \fB\-d\fP \fIoffset\fP
10627 Delete the history entry at position \fIoffset\fP.
10628 If \fIoffset\fP is negative, it is interpreted as relative to one greater
10629 than the last history position, so negative indices count back from the
10630 end of the history, and an index of \-1 refers to the current
10631 \fBhistory \-d\fP command.
10632 .TP
10633 \fB\-d\fP \fIstart\fP\-\fIend\fP
10634 Delete the range of history entries between positions \fIstart\fP and
10635 \fIend\fP, inclusive.
10636 Positive and negative values for \fIstart\fP and \fIend\fP
10637 are interpreted as described above.
10638 .TP
10639 .B \-a
10640 Append the
10641 .Q new
10642 history lines to the history file.
10643 These are history lines entered since the beginning of the current
10644 \fBbash\fP session, but not already appended to the history file.
10645 .TP
10646 .B \-n
10647 Read the history lines not already read from the history file
10648 and add them to the current history list.
10649 These are lines appended to the history file since the beginning of the
10650 current \fBbash\fP session.
10651 .TP
10652 .B \-r
10653 Read the history file and append its contents to the current history list.
10654 .TP
10655 .B \-w
10656 Write the current history list to the history file, overwriting
10657 the history file.
10658 .TP
10659 .B \-p
10660 Perform history substitution on the following \fIargs\fP and display
10661 the result on the standard output,
10662 without storing the results in the history list.
10663 Each \fIarg\fP must be quoted to disable normal history expansion.
10664 .TP
10665 .B \-s
10666 Store the
10667 .I args
10668 in the history list as a single entry.
10669 The last command in the
10670 history list is removed before adding the
10671 .IR args .
10672 .PD
10673 .RE
10674 .IP
10675 If the
10676 .SM
10677 .B HISTTIMEFORMAT
10678 variable is set, \fBhistory\fP writes the time stamp information
10679 associated with each history entry to the history file,
10680 marked with the history comment character as described above.
10681 When the history file is read, lines beginning with the history
10682 comment character followed immediately by a digit are interpreted
10683 as timestamps for the following history entry.
10684 .IP
10685 The return value is 0 unless an invalid option is encountered, an
10686 error occurs while reading or writing the history file, an invalid
10687 \fIoffset\fP or range is supplied as an argument to \fB\-d\fP, or the
10688 history expansion supplied as an argument to \fB\-p\fP fails.
10689 .TP
10690 \fBjobs\fP [\fB\-lnprs\fP] [ \fIjobspec\fP .\|.\|. ]
10691 .PD 0
10692 .TP
10693 \fBjobs\fP \fB\-x\fP \fIcommand\fP [ \fIargs\fP .\|.\|. ]
10694 .PD
10695 The first form lists the active jobs.
10696 The options have the following meanings:
10697 .RS
10698 .PD 0
10699 .TP
10700 .B \-l
10701 List process IDs in addition to the normal information.
10702 .TP
10703 .B \-n
10704 Display information only about jobs that have changed status since
10705 the user was last notified of their status.
10706 .TP
10707 .B \-p
10708 List only the process ID of the job's process group leader.
10709 .TP
10710 .B \-r
10711 Display only running jobs.
10712 .TP
10713 .B \-s
10714 Display only stopped jobs.
10715 .PD
10716 .RE
10717 .IP
10718 If
10719 .I jobspec
10720 is supplied, \fBjobs\fP restricts output to information about that job.
10721 The return status is 0 unless an invalid option is encountered
10722 or an invalid
10723 .I jobspec
10724 is supplied.
10725 .IP
10726 If the
10727 .B \-x
10728 option is supplied,
10729 .B jobs
10730 replaces any
10731 .I jobspec
10732 found in
10733 .I command
10734 or
10735 .I args
10736 with the corresponding process group ID, and executes
10737 .IR command ,
10738 passing it
10739 .IR args ,
10740 returning its exit status.
10741 .TP
10742 \fBkill\fP [\fB\-s\fP \fIsigspec\fP | \fB\-n\fP \fIsignum\fP | \fB\-\fP\fIsigspec\fP] \
10743 \fIid\fP [ .\|.\|. ]
10744 .PD 0
10745 .TP
10746 \fBkill\fP \fB\-l\fP|\fB\-L\fP [\fIsigspec\fP | \fIexit_status\fP]
10747 .PD
10748 Send the signal specified by
10749 .I sigspec
10750 or
10751 .I signum
10752 to the processes named by each
10753 .IR id .
10754 Each
10755 .I id
10756 may be a job specification \fIjobspec\fP
10757 or a process ID \fIpid\fP.
10758 .I sigspec
10759 is either a case-insensitive signal name such as
10760 .SM
10761 .B SIGKILL
10762 (with or without the
10763 .SM
10764 .B SIG
10765 prefix) or a signal number;
10766 .I signum
10767 is a signal number.
10768 If
10769 .I sigspec
10770 is not supplied, then
10771 .B kill
10772 sends
10773 .SM
10774 .BR SIGTERM .
10775 .IP
10776 The
10777 .B \-l
10778 option lists the signal names.
10779 If any arguments are supplied when
10780 .B \-l
10781 is given,
10782 .B kill
10783 lists the names of the signals corresponding to the arguments,
10784 and the return status is 0.
10785 The \fIexit_status\fP argument to
10786 .B \-l
10787 is a number specifying either a signal number or the exit status of
10788 a process terminated by a signal;
10789 if it is supplied, \fBkill\fP prints the name of the signal that caused
10790 the process to terminate.
10791 \fBkill\fP assumes that process exit statuses are greater than 128;
10792 anything less than that is a signal number.
10793 The
10794 .B \-L
10795 option is equivalent to \fB\-l\fP.
10796 .IP
10797 .B kill
10798 returns true if at least one signal was successfully sent, or false
10799 if an error occurs or an invalid option is encountered.
10800 .TP
10801 \fBlet\fP \fIarg\fP [\fIarg\fP .\|.\|.]
10802 Each
10803 .I arg
10804 is evaluated as an arithmetic expression (see
10805 .SM
10806 .B "ARITHMETIC EVALUATION"
10807 .ie \n(zZ=1 in \fIbash\fP(1)).
10808 .el above).
10809 If the last
10810 .I arg
10811 evaluates to 0,
10812 .B let
10813 returns 1; otherwise
10814 .B let
10815 returns 0.
10816 .TP
10817 \fBlocal\fP [\fIoption\fP] [\fIname\fP[=\fIvalue\fP] .\|.\|. | \- ]
10818 For each argument, create a local variable named
10819 .I name
10820 and assign it
10821 .IR value .
10822 The \fIoption\fP can be any of the options accepted by \fBdeclare\fP.
10823 When
10824 .B local
10825 is used within a function, it causes the variable
10826 .I name
10827 to have a visible scope restricted to that function and its children.
10828 It is an error to use
10829 .B local
10830 when not within a function.
10831 .IP
10832 If \fIname\fP is \-, it makes the set of shell options
10833 local to the function in which \fBlocal\fP is invoked:
10834 any shell options changed using the \fBset\fP builtin inside
10835 the function after the call to \fBlocal\fP are restored to their
10836 original values when the function returns.
10837 The restore is performed as if a series of \fBset\fP commands were
10838 executed to restore the values that were in place before the function.
10839 .IP
10840 With no operands,
10841 .B local
10842 writes a list of local variables to the standard output.
10843 .IP
10844 The return status is 0 unless
10845 .B local
10846 is used outside a function, an invalid
10847 .I name
10848 is supplied, or
10849 \fIname\fP is a readonly variable.
10850 .TP
10851 .B logout [\fIn\fP]
10852 Exit a login shell,
10853 returning a status of \fIn\fP to the shell's parent.
10854 .TP
10855 \fBmapfile\fP [\fB\-d\fP \fIdelim\fP] [\fB\-n\fP \fIcount\fP] [\fB\-O\fP \fIorigin\fP] [\fB\-s\fP \fIcount\fP] [\fB\-t\fP] [\fB\-u\fP \fIfd\fP] [\fB\-C\fP \fIcallback\fP] [\fB\-c\fP \fIquantum\fP] [\fIarray\fP]
10856 .PD 0
10857 .TP
10858 \fBreadarray\fP [\fB\-d\fP \fIdelim\fP] [\fB\-n\fP \fIcount\fP] [\fB\-O\fP \fIorigin\fP] [\fB\-s\fP \fIcount\fP] [\fB\-t\fP] [\fB\-u\fP \fIfd\fP] [\fB\-C\fP \fIcallback\fP] [\fB\-c\fP \fIquantum\fP] [\fIarray\fP]
10859 .PD
10860 Read lines from the standard input,
10861 or from file descriptor
10862 .I fd
10863 if the
10864 .B \-u
10865 option is supplied,
10866 into the indexed array variable
10867 .IR array .
10868 The variable
10869 .SM
10870 .B MAPFILE
10871 is the default \fIarray\fP.
10872 Options, if supplied, have the following meanings:
10873 .RS
10874 .PD 0
10875 .TP
10876 .B \-d
10877 Use the first character of \fIdelim\fP to terminate each input line,
10878 rather than newline.
10879 If \fIdelim\fP is the empty string, \fBmapfile\fP will terminate a line
10880 when it reads a NUL character.
10881 .TP
10882 .B \-n
10883 Copy at most
10884 .I count
10885 lines.
10886 If \fIcount\fP is 0, copy all lines.
10887 .TP
10888 .B \-O
10889 Begin assigning to
10890 .I array
10891 at index
10892 .IR origin .
10893 The default index is 0.
10894 .TP
10895 .B \-s
10896 Discard the first \fIcount\fP lines read.
10897 .TP
10898 .B \-t
10899 Remove a trailing \fIdelim\fP (default newline) from each line read.
10900 .TP
10901 .B \-u
10902 Read lines from file descriptor \fIfd\fP instead of the standard input.
10903 .TP
10904 .B \-C
10905 Evaluate
10906 .I callback
10907 each time \fIquantum\fP lines are read.
10908 The \fB\-c\fP option specifies
10909 .IR quantum .
10910 .TP
10911 .B \-c
10912 Specify the number of lines read between each call to
10913 .IR callback .
10914 .PD
10915 .RE
10916 .IP
10917 If
10918 .B \-C
10919 is specified without
10920 .BR \-c ,
10921 the default quantum is 5000.
10922 When \fIcallback\fP is evaluated, it is supplied the index of the next
10923 array element to be assigned and the line to be assigned to that element
10924 as additional arguments.
10925 \fIcallback\fP is evaluated after the line is read but before the
10926 array element is assigned.
10927 .IP
10928 If not supplied with an explicit origin, \fBmapfile\fP will clear \fIarray\fP
10929 before assigning to it.
10930 .IP
10931 \fBmapfile\fP returns zero unless an invalid option or option
10932 argument is supplied, \fIarray\fP is invalid or unassignable, or if
10933 \fIarray\fP is not an indexed array.
10934 .TP
10935 \fBpopd\fP [\-\fBn\fP] [+\fIn\fP] [\-\fIn\fP]
10936 Remove entries from the directory stack.
10937 The elements are numbered from 0 starting at the first directory
10938 listed by \fBdirs\fP, so \fBpopd\fP is equivalent to
10939 .Q "popd +0."
10940 With no arguments, \fBpopd\fP removes the top directory from the stack,
10941 and changes to the new top directory.
10942 Arguments, if supplied, have the following meanings:
10943 .RS
10944 .PD 0
10945 .TP
10946 .B \-n
10947 Suppress the normal change of directory when removing directories
10948 from the stack, only manipulate the stack.
10949 .TP
10950 \fB+\fP\fIn\fP
10951 Remove the \fIn\fPth entry counting from the left of the list
10952 shown by
10953 .BR dirs ,
10954 starting with zero, from the stack.
10955 For example:
10956 .Q "popd +0"
10957 removes the first directory,
10958 .Q "popd +1"
10959 the second.
10960 .TP
10961 \fB\-\fP\fIn\fP
10962 Remove the \fIn\fPth entry counting from the right of the list
10963 shown by
10964 .BR dirs ,
10965 starting with zero. For example:
10966 .Q "popd \-0"
10967 removes the last directory,
10968 .Q "popd \-1"
10969 the next to last.
10970 .PD
10971 .RE
10972 .IP
10973 If the top element of the directory stack is modified, and
10974 the \fI\-n\fP option was not supplied, \fBpopd\fP uses the \fBcd\fP
10975 builtin to change to the directory at the top of the stack.
10976 If the \fBcd\fP fails, \fBpopd\fP returns a non-zero value.
10977 .IP
10978 Otherwise,
10979 .B popd
10980 returns false if an invalid option is supplied, the directory stack
10981 is empty, or \fIn\fP specifies a non-existent directory stack entry.
10982 .IP
10983 If the
10984 .B popd
10985 command is successful,
10986 \fBbash\fP runs
10987 .B dirs
10988 to show the final contents of the directory stack,
10989 and the return status is 0.
10990 .TP
10991 \fBprintf\fP [\fB\-v\fP \fIvar\fP] \fIformat\fP [\fIarguments\fP]
10992 Write the formatted \fIarguments\fP to the standard output under the
10993 control of the \fIformat\fP.
10994 The \fB\-v\fP option assigns the output to the variable
10995 \fIvar\fP rather than printing it to the standard output.
10996 .IP
10997 The \fIformat\fP is a character string which contains three types of objects:
10998 plain characters, which are simply copied to standard output, character
10999 escape sequences, which are converted and copied to the standard output, and
11000 format specifications, each of which causes printing of the next successive
11001 \fIargument\fP.
11002 In addition to the standard
11003 .IR printf (3)
11004 format characters
11005 .BR cCsSndiouxXeEfFgGaA ,
11006 \fBprintf\fP interprets the following additional format specifiers:
11007 .RS
11008 .PD 0
11009 .TP
11010 .B %b
11011 causes
11012 \fBprintf\fP to expand backslash escape sequences in the corresponding
11013 \fIargument\fP
11014 in the same way as \fBecho \-e\fP.
11015 .TP
11016 .B %q
11017 causes \fBprintf\fP to output the corresponding
11018 \fIargument\fP in a format that can be reused as shell input.
11019 \fB%q\fP and \fB%Q\fP use the \fB$\*'\*'\fP quoting style if any characters
11020 in the argument string require it, and backslash quoting otherwise.
11021 If the format string uses the \fIprintf\fP alternate form, these two
11022 formats quote the argument string using single quotes.
11023 .TP
11024 .B %Q
11025 like \fB%q\fP, but applies any supplied precision to the \fIargument\fP
11026 before quoting it.
11027 .TP
11028 .B %(\fIdatefmt\fP)T
11029 causes \fBprintf\fP to output the date-time string resulting from using
11030 \fIdatefmt\fP as a format string for
11031 .IR strftime (3).
11032 The corresponding \fIargument\fP is an integer representing the number of
11033 seconds since the epoch.
11034 This format specifier recognizes two special argument values:
11035 \-1 represents the current time,
11036 and \-2 represents the time the shell was invoked.
11037 If no argument is specified, conversion behaves as if \-1 had been supplied.
11038 This is an exception to the usual \fBprintf\fP behavior.
11039 .PD
11040 .RE
11041 .IP
11042 The %b, %q, and %T format specifiers all use the field width and precision
11043 arguments from the format specification and write that many bytes from
11044 (or use that wide a field for) the expanded argument, which usually
11045 contains more characters than the original.
11046 .IP
11047 The %n format specifier accepts a corresponding argument that is treated
11048 as a shell variable name.
11049 .IP
11050 The %s and %c format specifiers accept an l (long) modifier, which forces
11051 them to convert the argument string to a wide-character string and apply
11052 any supplied field width and precision in terms of characters, not bytes.
11053 The %S and %C format specifiers are equivalent to %ls and %lc, respectively.
11054 .\" .IP
11055 .\" The %s format specifier understands the "altform" flag (#) and behaves
11056 .\" identically to the %b format specifier if it's supplied.
11057 .IP
11058 Arguments to non-string format specifiers are treated as C constants,
11059 except that a leading plus or minus sign is allowed, and if the leading
11060 character is a single or double quote, the value is the numeric value of
11061 the following character, using the current locale.
11062 .IP
11063 The \fIformat\fP is reused as necessary to consume all of the \fIarguments\fP.
11064 If the \fIformat\fP requires more \fIarguments\fP than are supplied, the
11065 extra format specifications behave as if a zero value or null string, as
11066 appropriate, had been supplied.
11067 The return value is zero on success,
11068 non-zero if an invalid option is supplied or a write or assignment error
11069 occurs.
11070 .TP
11071 \fBpushd\fP [\fB\-n\fP] [+\fIn\fP] [\-\fIn\fP]
11072 .PD 0
11073 .TP
11074 \fBpushd\fP [\fB\-n\fP] [\fIdir\fP]
11075 .PD
11076 Add a directory to the top of the directory stack, or rotate
11077 the stack, making the new top of the stack the current working
11078 directory.
11079 With no arguments, \fBpushd\fP exchanges the top two elements of
11080 the directory stack.
11081 Arguments, if supplied, have the following meanings:
11082 .RS
11083 .PD 0
11084 .TP
11085 .B \-n
11086 Suppress the normal change of directory when rotating or
11087 adding directories to the stack, only manipulate the stack.
11088 .TP
11089 \fB+\fP\fIn\fP
11090 Rotate the stack so that the \fIn\fPth directory
11091 (counting from the left of the list shown by
11092 .BR dirs ,
11093 starting with zero)
11094 is at the top.
11095 .TP
11096 \fB\-\fP\fIn\fP
11097 Rotates the stack so that the \fIn\fPth directory
11098 (counting from the right of the list shown by
11099 .BR dirs ,
11100 starting with zero) is at the top.
11101 .TP
11102 .I dir
11103 Adds
11104 .I dir
11105 to the directory stack at the top.
11106 .PD
11107 .RE
11108 .IP
11109 After the stack has been modified, if the \fB\-n\fP option was not
11110 supplied, \fBpushd\fP uses the \fBcd\fP builtin to change to the
11111 directory at the top of the stack.
11112 If the \fBcd\fP fails, \fBpushd\fP returns a non-zero value.
11113 .IP
11114 Otherwise, if no arguments are supplied,
11115 .B pushd
11116 returns zero unless the directory stack is empty.
11117 When rotating the directory stack,
11118 .B pushd
11119 returns zero unless the directory stack is empty or
11120 \fIn\fP specifies a non-existent directory stack element.
11121 .IP
11122 If the
11123 .B pushd
11124 command is successful,
11125 \fBbash\fP runs
11126 .B dirs
11127 to show the final contents of the directory stack.
11128 .TP
11129 \fBpwd\fP [\fB\-LP\fP]
11130 Print the absolute pathname of the current working directory.
11131 The pathname printed contains no symbolic links if the
11132 .B \-P
11133 option is supplied or the
11134 .B \-o physical
11135 option to the
11136 .B set
11137 builtin command is enabled.
11138 If the
11139 .B \-L
11140 option is used, the pathname printed may contain symbolic links.
11141 The return status is 0 unless an error occurs while
11142 reading the name of the current directory or an
11143 invalid option is supplied.
11144 .TP
11145 \fBread\fP [\fB\-Eers\fP] [\fB\-a\fP \fIaname\fP] \
11146 [\fB\-d\fP \fIdelim\fP] [\fB\-i\fP \fItext\fP] \
11147 [\fB\-n\fP \fInchars\fP] [\fB\-N\fP \fInchars\fP] \
11148 [\fB\-p\fP \fIprompt\fP] [\fB\-t\fP \fItimeout\fP] \
11149 [\fB\-u\fP \fIfd\fP] [\fIname\fP .\|.\|.]
11150 Read one line from the standard input, or from the file descriptor
11151 \fIfd\fP supplied as an argument to the \fB\-u\fP option,
11152 split it into words as described
11153 .ie \n(zZ=1 in \fIbash\fP (1)
11154 .el above
11155 under \fBWord Splitting\fP,
11156 and assign the first word to the first
11157 .IR name ,
11158 the second word to the second
11159 .IR name ,
11160 and so on.
11161 If there are more words than names, the remaining words and their
11162 intervening delimiters are assigned to the last
11163 .IR name .
11164 If there are fewer words read from the input stream than names,
11165 the remaining names are assigned empty values.
11166 The characters in the value of the
11167 .SM
11168 .B IFS
11169 variable
11170 are used to split the line into words using the same rules the shell
11171 uses for expansion (described
11172 .ie \n(zZ=1 in \fIbash\fP (1)
11173 .el above
11174 under \fBWord Splitting\fP).
11175 The backslash character (\fB\e\fP) removes any special
11176 meaning for the next character read and is used for line continuation.
11177 .IP
11178 Options, if supplied, have the following meanings:
11179 .RS
11180 .PD 0
11181 .TP
11182 .B \-a \fIaname\fP
11183 The words are assigned to sequential indices of the array variable
11184 .IR aname ,
11185 starting at 0.
11186 .I aname
11187 is unset before any new values are assigned.
11188 Other \fIname\fP arguments are ignored.
11189 .TP
11190 .B \-d \fIdelim\fP
11191 The first character of \fIdelim\fP terminates the input line,
11192 rather than newline.
11193 If \fIdelim\fP is the empty string, \fBread\fP will terminate a line
11194 when it reads a NUL character.
11195 .TP
11196 .B \-e
11197 If the standard input is coming from a terminal,
11198 \fBread\fP uses
11199 .B readline
11200 (see
11201 .SM
11202 .B READLINE
11203 .ie \n(zZ=1 in \fIbash\fP(1))
11204 .el above)
11205 to obtain the line.
11206 \fBReadline\fP uses the current
11207 (or default, if line editing was not previously active)
11208 editing settings, but uses \fBreadline\fP's default filename completion.
11209 .TP
11210 .B \-E
11211 If the standard input is coming from a terminal,
11212 \fBread\fP uses
11213 .B readline
11214 (see
11215 .SM
11216 .B READLINE
11217 .ie \n(zZ=1 in \fIbash\fP(1))
11218 .el above)
11219 to obtain the line.
11220 .B Readline
11221 uses the current (or default, if line editing was not previously
11222 active) editing settings, but uses bash's default completion, including
11223 programmable completion.
11224 .TP
11225 .B \-i \fItext\fP
11226 If
11227 .B readline
11228 is being used to read the line, \fBread\fP places \fItext\fP into
11229 the editing buffer before editing begins.
11230 .TP
11231 .B \-n \fInchars\fP
11232 \fBread\fP returns after reading \fInchars\fP characters rather than
11233 waiting for a complete line of input,
11234 unless it encounters EOF or \fBread\fP times out,
11235 but honors a delimiter if it reads fewer
11236 than \fInchars\fP characters before the delimiter.
11237 .TP
11238 .B \-N \fInchars\fP
11239 \fBread\fP returns after reading exactly \fInchars\fP characters rather
11240 than waiting for a complete line of input,
11241 unless it encounters EOF or \fBread\fP times out.
11242 Any delimiter characters in the input are
11243 not treated specially and do not cause \fBread\fP to return until
11244 it has read \fInchars\fP characters.
11245 The result is not split on the characters in \fBIFS\fP; the intent is
11246 that the variable is assigned exactly the characters read
11247 (with the exception of backslash; see the \fB\-r\fP option below).
11248 .TP
11249 .B \-p \fIprompt\fP
11250 Display \fIprompt\fP on standard error, without a
11251 trailing newline, before attempting to read any input, but
11252 only if input is coming from a terminal.
11253 .TP
11254 .B \-r
11255 Backslash does not act as an escape character.
11256 The backslash is considered to be part of the line.
11257 In particular, a backslash-newline pair may not then be used as a line
11258 continuation.
11259 .TP
11260 .B \-s
11261 Silent mode.
11262 If input is coming from a terminal, characters are not echoed.
11263 .TP
11264 .B \-t \fItimeout\fP
11265 Cause \fBread\fP to time out and return failure if it does not read
11266 a complete line of input (or a specified number of characters)
11267 within \fItimeout\fP seconds.
11268 \fItimeout\fP may be a decimal number with a fractional portion following
11269 the decimal point.
11270 This option is only effective if \fBread\fP is reading input from a
11271 terminal, pipe, or other special file; it has no effect when reading
11272 from regular files.
11273 If \fBread\fP times out, it saves any partial input read into
11274 the specified variable \fIname\fP, and the exit status is greater than 128.
11275 If \fItimeout\fP is 0, \fBread\fP returns immediately, without trying to
11276 read any data.
11277 In this case, the exit status is 0 if input is available on the specified
11278 file descriptor, or the read will return EOF, non-zero otherwise.
11279 .TP
11280 .B \-u \fIfd\fP
11281 Read input from file descriptor \fIfd\fP instead of the standard input.
11282 .PD
11283 .RE
11284 .IP
11285 Other than the case where \fIdelim\fP is the empty string, \fBread\fP
11286 ignores any NUL characters in the input.
11287 .IP
11288 If no
11289 .I names
11290 are supplied, \fBread\fP assigns the line read,
11291 without the ending delimiter but otherwise unmodified,
11292 to the variable
11293 .SM
11294 .BR REPLY .
11295 .IP
11296 The exit status is zero, unless end-of-file is encountered, \fBread\fP
11297 times out (in which case the status is greater than 128),
11298 a variable assignment error (such as assigning to a readonly variable) occurs,
11299 or an invalid file descriptor is supplied as the argument to \fB\-u\fP.
11300 .TP
11301 \fBreadonly\fP [\fB\-aAf\fP] [\fB\-p\fP] [\fIname\fP[=\fIword\fP] .\|.\|.]
11302 .PD
11303 The given
11304 \fInames\fP are marked readonly; the values of these
11305 .I names
11306 may not be changed by subsequent assignment or unset.
11307 If the
11308 .B \-f
11309 option is supplied, each \fIname\fP refers to a shell function.
11310 The
11311 .B \-a
11312 option restricts the variables to indexed arrays; the
11313 .B \-A
11314 option restricts the variables to associative arrays.
11315 If both options are supplied,
11316 .B \-A
11317 takes precedence.
11318 If no
11319 .I name
11320 arguments are supplied, or if the
11321 .B \-p
11322 option is supplied, print a list of all readonly names.
11323 The other options may be used to restrict the output to a subset of
11324 the set of readonly names.
11325 The
11326 .B \-p
11327 option displays output in a format that may be reused as input.
11328 .IP
11329 \fBreadonly\fP allows the value of a variable to be set at the same time
11330 the readonly attribute is changed by following the variable name with
11331 =\fIvalue\fP.
11332 This sets the value of the variable is to \fIvalue\fP while modifying
11333 the readonly attribute.
11334 .IP
11335 The return status is 0 unless an invalid option is encountered,
11336 one of the
11337 .I names
11338 is not a valid shell variable name, or
11339 .B \-f
11340 is supplied with a
11341 .I name
11342 that is not a function.
11343 .TP
11344 \fBreturn\fP [\fIn\fP]
11345 Stop executing a shell function or sourced file and return the value
11346 specified by
11347 .I n
11348 to its caller.
11349 If
11350 .I n
11351 is omitted, the return status is that of the last command
11352 executed.
11353 If \fBreturn\fP is executed by a trap handler, the last command used to
11354 determine the status is the last command executed before the trap handler.
11355 If \fBreturn\fP is executed during a \fBDEBUG\fP trap, the last command
11356 used to determine the status is the last command executed by the trap
11357 handler before \fBreturn\fP was invoked.
11358 .IP
11359 When
11360 .B return
11361 is used to terminate execution of a script being executed by the
11362 .B .
11363 (\fBsource\fP) command, it causes the shell to stop executing
11364 that script and return either
11365 .I n
11366 or the exit status of the last command executed within the
11367 script as the exit status of the script.
11368 If \fIn\fP is supplied, the return value is its least significant
11369 8 bits.
11370 .IP
11371 Any command associated with the \fBRETURN\fP trap is executed
11372 before execution resumes after the function or script.
11373 .IP
11374 The return status is non-zero if
11375 .B return
11376 is supplied a non-numeric argument, or is used outside a
11377 function and not during execution of a script by \fB.\fP\^ or \fBsource\fP.
11378 .TP
11379 \fBset\fP [\fB\-abefhkmnptuvxBCEHPT\fP] [\fB\-o\fP \fIoption\-name\fP] \
11380 [\fB\-\-\fP] [\fB\-\fP] [\fIarg\fP .\|.\|.]
11381 .PD 0
11382 .TP
11383 \fBset\fP [\fB+abefhkmnptuvxBCEHPT\fP] [\fB+o\fP \fIoption\-name\fP] \
11384 [\fB\-\-\fP] [\fB\-\fP] [\fIarg\fP .\|.\|.]
11385 .TP
11386 \fBset \-o\fP
11387 .TP
11388 \fBset +o\fP
11389 .PD
11390 Without options, display the name and value of each shell variable
11391 in a format that can be reused as input
11392 for setting or resetting the currently-set variables.
11393 Read-only variables cannot be reset.
11394 In posix mode, only shell variables are listed.
11395 The output is sorted according to the current locale.
11396 When options are specified, they set or unset shell attributes.
11397 Any arguments remaining after option processing are treated
11398 as values for the positional parameters and are assigned, in order, to
11399 .BR $1 ,
11400 .BR $2 ,
11401 \&.\|.\|.,
11402 .BR $\fIn\fP .
11403 Options, if specified, have the following meanings:
11404 .RS
11405 .PD 0
11406 .TP 8
11407 .B \-a
11408 Each variable or function that is created or modified is given the
11409 export attribute and marked for export to the environment of
11410 subsequent commands.
11411 .TP 8
11412 .B \-b
11413 Report the status of terminated background jobs
11414 immediately, rather than before the next primary prompt or after a
11415 foreground command terminates.
11416 This is effective only when job control is enabled.
11417 .TP 8
11418 .B \-e
11419 .PD
11420 Exit immediately if a
11421 \fIpipeline\fP (which may consist of a single \fIsimple command\fP),
11422 a \fIlist\fP,
11423 or a \fIcompound command\fP
11424 (see
11425 .SM
11426 .B "SHELL GRAMMAR"
11427 .ie \n(zZ=1 in \fIbash\fP(1)),
11428 .el above),
11429 exits with a non-zero status.
11430 The shell does not exit if the
11431 command that fails is part of the command list immediately following a
11432 .B while
11433 or
11434 .B until
11435 reserved word,
11436 part of the test following the
11437 .B if
11438 or
11439 .B elif
11440 reserved words, part of any command executed in a
11441 .B &&
11442 or
11443 .B ||
11444 list except the command following the final \fB&&\fP or \fB||\fP,
11445 any command in a pipeline but the last
11446 (subject to the state of the \fBpipefail\fP shell option),
11447 or if the command's return value is
11448 being inverted with
11449 .BR ! .
11450 If a compound command other than a subshell
11451 returns a non-zero status because a command failed
11452 while \fB\-e\fP was being ignored, the shell does not exit.
11453 A trap on \fBERR\fP, if set, is executed before the shell exits.
11454 This option applies to the shell environment and each subshell environment
11455 separately (see
11456 .SM
11457 .B "COMMAND EXECUTION ENVIRONMENT"
11458 .ie \n(zZ=1 in \fIbash\fP(1)),
11459 .el above),
11460 and may cause
11461 subshells to exit before executing all the commands in the subshell.
11462 .IP
11463 If a compound command or shell function executes in a context
11464 where \fB\-e\fP is being ignored,
11465 none of the commands executed within the compound command or function body
11466 will be affected by the \fB\-e\fP setting, even if \fB\-e\fP is set
11467 and a command returns a failure status.
11468 If a compound command or shell function sets \fB\-e\fP while executing in
11469 a context where \fB\-e\fP is ignored, that setting will not have any
11470 effect until the compound command or the command containing the function
11471 call completes.
11472 .PD 0
11473 .TP 8
11474 .B \-f
11475 Disable pathname expansion.
11476 .TP 8
11477 .B \-h
11478 Remember the location of commands as they are looked up for execution.
11479 This is enabled by default.
11480 .TP 8
11481 .B \-k
11482 All arguments in the form of assignment statements
11483 are placed in the environment for a command, not just
11484 those that precede the command name.
11485 .TP 8
11486 .B \-m
11487 Monitor mode.
11488 Job control is enabled.
11489 This option is on by default for interactive shells on systems
11490 that support it (see
11491 .SM
11492 .B "JOB CONTROL"
11493 .ie \n(zZ=1 in \fIbash\fP(1)).
11494 .el above).
11495 All processes run in a separate process group.
11496 When a background job completes, the shell prints a line
11497 containing its exit status.
11498 .TP 8
11499 .B \-n
11500 Read commands but do not execute them.
11501 This may be used to check a shell script for syntax errors.
11502 This is ignored by interactive shells.
11503 .TP 8
11504 .B \-o \fIoption\-name\fP
11505 The \fIoption\-name\fP can be one of the following:
11506 .RS
11507 .TP 8
11508 .B allexport
11509 Same as
11510 .BR \-a .
11511 .TP 8
11512 .B braceexpand
11513 Same as
11514 .BR \-B .
11515 .TP 8
11516 .B emacs
11517 Use an emacs-style command line editing interface. This is enabled
11518 by default when the shell is interactive, unless the shell is started
11519 with the
11520 .B \-\-noediting
11521 option.
11522 This also affects the editing interface used for \fBread \-e\fP.
11523 .TP 8
11524 .B errexit
11525 Same as
11526 .BR \-e .
11527 .TP 8
11528 .B errtrace
11529 Same as
11530 .BR \-E .
11531 .TP 8
11532 .B functrace
11533 Same as
11534 .BR \-T .
11535 .TP 8
11536 .B hashall
11537 Same as
11538 .BR \-h .
11539 .TP 8
11540 .B histexpand
11541 Same as
11542 .BR \-H .
11543 .TP 8
11544 .B history
11545 Enable command history, as described
11546 .ie \n(zZ=1 in \fIbash\fP(1)
11547 .el above
11548 under
11549 .SM
11550 .BR HISTORY .
11551 This option is on by default in interactive shells.
11552 .TP 8
11553 .B ignoreeof
11554 The effect is as if the shell command
11555 .QN "IGNOREEOF=10"
11556 had been executed
11557 (see
11558 .B "Shell Variables"
11559 .ie \n(zZ=1 in \fIbash\fP(1)).
11560 .el above).
11561 .TP 8
11562 .B keyword
11563 Same as
11564 .BR \-k .
11565 .TP 8
11566 .B monitor
11567 Same as
11568 .BR \-m .
11569 .TP 8
11570 .B noclobber
11571 Same as
11572 .BR \-C .
11573 .TP 8
11574 .B noexec
11575 Same as
11576 .BR \-n .
11577 .TP 8
11578 .B noglob
11579 Same as
11580 .BR \-f .
11581 .TP 8
11582 .B nolog
11583 Currently ignored.
11584 .TP 8
11585 .B notify
11586 Same as
11587 .BR \-b .
11588 .TP 8
11589 .B nounset
11590 Same as
11591 .BR \-u .
11592 .TP 8
11593 .B onecmd
11594 Same as
11595 .BR \-t .
11596 .TP 8
11597 .B physical
11598 Same as
11599 .BR \-P .
11600 .TP 8
11601 .B pipefail
11602 If set, the return value of a pipeline is the value of the last
11603 (rightmost) command to exit with a non-zero status, or zero if all
11604 commands in the pipeline exit successfully.
11605 This option is disabled by default.
11606 .TP 8
11607 .B posix
11608 Enable posix mode;
11609 change the behavior of
11610 .B bash
11611 where the default operation differs
11612 from the
11613 .SM POSIX
11614 standard to match the standard.
11615 See
11616 .SM
11617 .B "SEE ALSO"
11618 .ie \n(zZ=1 in \fIbash\fP(1)
11619 .el below
11620 for a reference to a document that details how posix mode affects
11621 bash's behavior.
11622 .TP 8
11623 .B privileged
11624 Same as
11625 .BR \-p .
11626 .TP 8
11627 .B verbose
11628 Same as
11629 .BR \-v .
11630 .TP 8
11631 .B vi
11632 Use a vi-style command line editing interface.
11633 This also affects the editing interface used for \fBread \-e\fP.
11634 .TP 8
11635 .B xtrace
11636 Same as
11637 .BR \-x .
11638 .PP
11639 If
11640 .B \-o
11641 is supplied with no \fIoption\-name\fP,
11642 \fBset\fP prints the current shell option settings.
11643 If
11644 .B +o
11645 is supplied with no \fIoption\-name\fP,
11646 \fBset\fP prints a series of
11647 .B set
11648 commands to recreate the current option settings
11649 on the standard output.
11650 .RE
11651 .TP 8
11652 .B \-p
11653 Turn on
11654 .I privileged
11655 mode. In this mode, the shell does not read the
11656 .SM
11657 .B $ENV
11658 and
11659 .SM
11660 .B $BASH_ENV
11661 files, shell functions are not inherited from the
11662 environment, and the
11663 .SM
11664 .BR SHELLOPTS ,
11665 .SM
11666 .BR BASHOPTS ,
11667 .SM
11668 .BR CDPATH ,
11669 and
11670 .SM
11671 .B GLOBIGNORE
11672 variables, if they appear in the environment, are ignored.
11673 If the shell is started with the effective user (group) id not equal to the
11674 real user (group) id, and the \fB\-p\fP option is not supplied, these actions
11675 are taken and the effective user id is set to the real user id.
11676 If the \fB\-p\fP option is supplied at startup, the effective user id is
11677 not reset.
11678 Turning this option off causes the effective user
11679 and group ids to be set to the real user and group ids.
11680 .TP 8
11681 .B \-r
11682 Enable restricted shell mode.
11683 This option cannot be unset once it has been set.
11684 .TP 8
11685 .B \-t
11686 Exit after reading and executing one command.
11687 .TP 8
11688 .B \-u
11689 Treat unset variables and parameters other than the special
11690 parameters
11691 .Q @
11692 and
11693 .Q * ,
11694 or array variables subscripted with
11695 .Q @
11696 or
11697 .Q * ,
11698 as an error when performing parameter expansion.
11699 If expansion is attempted on an unset variable or parameter,
11700 the shell prints an error message, and,
11701 if not interactive, exits with a non-zero status.
11702 .TP 8
11703 .B \-v
11704 Print shell input lines as they are read.
11705 .TP 8
11706 .B \-x
11707 After expanding each \fIsimple command\fP,
11708 \fBfor\fP command, \fBcase\fP command, \fBselect\fP command, or
11709 arithmetic \fBfor\fP command, display the expanded value of
11710 .SM
11711 .BR PS4 ,
11712 followed by the command and its expanded arguments
11713 or associated word list, to the standard error.
11714 .TP 8
11715 .B \-B
11716 The shell performs brace expansion (see
11717 .B "Brace Expansion"
11718 .ie \n(zZ=1 in \fIbash\fP(1)).
11719 .el above).
11720 This is on by default.
11721 .TP 8
11722 .B \-C
11723 If set,
11724 .B bash
11725 does not overwrite an existing file with the
11726 .BR > ,
11727 .BR >& ,
11728 and
11729 .B <>
11730 redirection operators.
11731 Using the redirection operator
11732 .B >|
11733 instead of
11734 .B >
11735 will override this and force the creation of an output file.
11736 .TP 8
11737 .B \-E
11738 If set, any trap on \fBERR\fP is inherited by shell functions, command
11739 substitutions, and commands executed in a subshell environment.
11740 The \fBERR\fP trap is normally not inherited in such cases.
11741 .TP 8
11742 .B \-H
11743 Enable
11744 .B !
11745 style history substitution.
11746 This option is on by default when the shell is interactive.
11747 .TP 8
11748 .B \-P
11749 If set, the shell does not resolve symbolic links when executing
11750 commands such as
11751 .B cd
11752 that change the current working directory.
11753 It uses the physical directory structure instead.
11754 By default,
11755 .B bash
11756 follows the logical chain of directories when performing commands
11757 which change the current directory.
11758 .TP 8
11759 .B \-T
11760 If set, any traps on \fBDEBUG\fP and \fBRETURN\fP are inherited by shell
11761 functions, command substitutions, and commands executed in a
11762 subshell environment.
11763 The \fBDEBUG\fP and \fBRETURN\fP traps are normally not inherited
11764 in such cases.
11765 .TP 8
11766 .B \-\-
11767 If no arguments follow this option, unset the positional parameters.
11768 Otherwise, set the positional parameters to the
11769 \fIarg\fPs, even if some of them begin with a
11770 .BR \- .
11771 .TP 8
11772 .B \-
11773 Signal the end of options, and assign all remaining \fIarg\fPs to
11774 the positional parameters.
11775 The
11776 .B \-x
11777 and
11778 .B \-v
11779 options are turned off.
11780 If there are no \fIarg\fPs, the positional parameters remain unchanged.
11781 .PD
11782 .PP
11783 The options are off by default unless otherwise noted.
11784 Using + rather than \- causes these options to be turned off.
11785 The options can also be specified as arguments to an invocation of
11786 the shell.
11787 The current set of options may be found in
11788 .BR $\- .
11789 The return status is always zero unless an invalid option is encountered.
11790 .RE
11791 .TP
11792 \fBshift\fP [\fIn\fP]
11793 Rename positional parameters from \fIn\fP+1 .\|.\|.\& to
11794 .B $1
11795 .B .\|.\|..
11796 Parameters represented by the numbers \fB$#\fP
11797 down to \fB$#\fP\-\fIn\fP+1 are unset.
11798 .I n
11799 must be a non-negative number less than or equal to \fB$#\fP.
11800 If
11801 .I n
11802 is 0, no parameters are changed.
11803 If
11804 .I n
11805 is not given, it is assumed to be 1.
11806 If
11807 .I n
11808 is greater than \fB$#\fP, the positional parameters are not changed.
11809 The return status is greater than zero if
11810 .I n
11811 is greater than
11812 .B $#
11813 or less than zero; otherwise 0.
11814 .TP
11815 \fBshopt\fP [\fB\-pqsu\fP] [\fB\-o\fP] [\fIoptname\fP .\|.\|.]
11816 Toggle the values of settings controlling optional shell behavior.
11817 The settings can be either those listed below, or, if the
11818 .B \-o
11819 option is used, those available with the
11820 .B \-o
11821 option to the \fBset\fP builtin command.
11822 .IP
11823 With no options, or with the
11824 .B \-p
11825 option, display a list of all settable options, with
11826 an indication of whether or not each is set;
11827 if any \fIoptnames\fP are supplied, the output is restricted to those options.
11828 The \fB\-p\fP option displays output in a form that
11829 may be reused as input.
11830 .IP
11831 Other options have the following meanings:
11832 .RS
11833 .PD 0
11834 .TP
11835 .B \-s
11836 Enable (set) each \fIoptname\fP.
11837 .TP
11838 .B \-u
11839 Disable (unset) each \fIoptname\fP.
11840 .TP
11841 .B \-q
11842 Suppresses normal output (quiet mode); the return status indicates
11843 whether the \fIoptname\fP is set or unset.
11844 If multiple \fIoptname\fP arguments are supplied with
11845 .BR \-q ,
11846 the return status is zero if all \fIoptnames\fP are enabled; non-zero
11847 otherwise.
11848 .TP
11849 .B \-o
11850 Restricts the values of \fIoptname\fP to be those defined for the
11851 .B \-o
11852 option to the
11853 .B set
11854 builtin.
11855 .PD
11856 .PP
11857 If either
11858 .B \-s
11859 or
11860 .B \-u
11861 is used with no \fIoptname\fP arguments,
11862 .B shopt
11863 shows only those options which are set or unset, respectively.
11864 Unless otherwise noted, the \fBshopt\fP options are disabled (unset)
11865 by default.
11866 .PP
11867 The return status when listing options is zero if all \fIoptnames\fP
11868 are enabled, non-zero otherwise. When setting or unsetting options,
11869 the return status is zero unless an \fIoptname\fP is not a valid shell
11870 option.
11871 .PP
11872 The list of \fBshopt\fP options is:
11873 .PP
11874 .PD 0
11875 .TP 8
11876 .B array_expand_once
11877 If set, the shell suppresses multiple evaluation of
11878 associative and indexed array subscripts
11879 during arithmetic expression evaluation, while executing
11880 builtins that can perform variable assignments,
11881 and while executing builtins that perform array dereferencing.
11882 .TP 8
11883 .B assoc_expand_once
11884 Deprecated; a synonym for \fBarray_expand_once\fP.
11885 .TP 8
11886 .B autocd
11887 If set, a command name that is the name of a directory is executed as if
11888 it were the argument to the \fBcd\fP command.
11889 This option is only used by interactive shells.
11890 .TP 8
11891 .B bash_source_fullpath
11892 If set, filenames added to the \fBBASH_SOURCE\fP array variable are
11893 converted to full pathnames (see \fBShell Variables\fP above).
11894 .TP 8
11895 .B cdable_vars
11896 If set, an argument to the
11897 .B cd
11898 builtin command that
11899 is not a directory is assumed to be the name of a variable whose
11900 value is the directory to change to.
11901 .TP 8
11902 .B cdspell
11903 If set, the
11904 .B cd
11905 command attempts to correct
11906 minor errors in the spelling of a directory component.
11907 Minor errors include transposed characters,
11908 a missing character, and one extra character.
11909 If \fBcd\fP corrects the directory name, it prints the corrected filename,
11910 and the command proceeds.
11911 This option is only used by interactive shells.
11912 .TP 8
11913 .B checkhash
11914 If set, \fBbash\fP checks that a command found in the hash
11915 table exists before trying to execute it.
11916 If a hashed command no longer exists, \fBbash\fP performs a normal path search.
11917 .TP 8
11918 .B checkjobs
11919 If set, \fBbash\fP lists the status of any stopped and running jobs before
11920 exiting an interactive shell.
11921 If any jobs are running, \fBbash\fP defers the exit until a second
11922 exit is attempted without an intervening command (see
11923 .SM
11924 .B "JOB CONTROL"
11925 .ie \n(zZ=1 in \fIbash\fP(1)).
11926 .el above).
11927 The shell always postpones exiting if any jobs are stopped.
11928 .TP 8
11929 .B checkwinsize
11930 If set, \fBbash\fP checks the window size after each external (non-builtin)
11931 command
11932 and, if necessary, updates the values of
11933 .SM
11934 .B LINES
11935 and
11936 .SM
11937 .BR COLUMNS ,
11938 using the file descriptor associated with the standard error
11939 if it is a terminal.
11940 This option is enabled by default.
11941 .TP 8
11942 .B cmdhist
11943 If set,
11944 .B bash
11945 attempts to save all lines of a multiple-line
11946 command in the same history entry.
11947 This allows easy re-editing of multi-line commands.
11948 This option is enabled by default, but only has an effect if command
11949 history is enabled, as described
11950 .ie \n(zZ=1 in \fIbash\fP(1)
11951 .el above
11952 under
11953 .SM
11954 .BR HISTORY .
11955 .PD 0
11956 .TP 8
11957 .B compat31
11958 .TP 8
11959 .B compat32
11960 .TP 8
11961 .B compat40
11962 .TP 8
11963 .B compat41
11964 .TP 8
11965 .B compat42
11966 .TP 8
11967 .B compat43
11968 .TP 8
11969 .B compat44
11970 .PD
11971 These control aspects of the shell's compatibility mode
11972 (see
11973 .SM
11974 .B "SHELL COMPATIBILITY MODE"
11975 .ie \n(zZ=1 in \fIbash\fP(1)).
11976 .el below).
11977 .PD 0
11978 .TP 8
11979 .B complete_fullquote
11980 If set,
11981 .B bash
11982 quotes all shell metacharacters in filenames and directory names when
11983 performing completion.
11984 If not set,
11985 .B bash
11986 removes metacharacters such as the dollar sign from the set of
11987 characters that will be quoted in completed filenames
11988 when these metacharacters appear in shell variable references in words to be
11989 completed.
11990 This means that dollar signs in variable names that expand to directories
11991 will not be quoted;
11992 however, any dollar signs appearing in filenames will not be quoted, either.
11993 This is active only when bash is using backslashes to quote completed
11994 filenames.
11995 This variable is set by default, which is the default bash behavior in
11996 versions through 4.2.
11997 .TP 8
11998 .B direxpand
11999 If set,
12000 .B bash
12001 replaces directory names with the results of word expansion when performing
12002 filename completion.
12003 This changes the contents of the \fBreadline\fP editing buffer.
12004 If not set,
12005 .B bash
12006 attempts to preserve what the user typed.
12007 .TP 8
12008 .B dirspell
12009 If set,
12010 .B bash
12011 attempts spelling correction on directory names during word completion
12012 if the directory name initially supplied does not exist.
12013 .TP 8
12014 .B dotglob
12015 If set,
12016 .B bash
12017 includes filenames beginning with a
12018 .Q .\&
12019 in the results of pathname expansion.
12020 The filenames
12021 .FN .\&
12022 and
12023 .FN ..\&
12024 must always be matched explicitly, even if
12025 .B dotglob
12026 is set.
12027 .TP 8
12028 .B execfail
12029 If set, a non-interactive shell will not exit if
12030 it cannot execute the file specified as an argument to the
12031 .B exec
12032 builtin.
12033 An interactive shell does not exit if
12034 .B exec
12035 fails.
12036 .TP 8
12037 .B expand_aliases
12038 If set, aliases are expanded as described
12039 .ie \n(zZ=1 in \fIbash\fP(1)
12040 .el above
12041 under
12042 .SM
12043 .BR ALIASES .
12044 This option is enabled by default for interactive shells.
12045 .TP 8
12046 .B extdebug
12047 If set at shell invocation, or in a shell startup file,
12048 arrange to execute the debugger profile
12049 before the shell starts, identical to the \fB\-\-debugger\fP option.
12050 If set after invocation, behavior intended for use by debuggers is enabled:
12051 .RS
12052 .TP
12053 .B 1.
12054 The \fB\-F\fP option to the \fBdeclare\fP builtin displays the source
12055 file name and line number corresponding to each function name supplied
12056 as an argument.
12057 .TP
12058 .B 2.
12059 If the command run by the \fBDEBUG\fP trap returns a non-zero value, the
12060 next command is skipped and not executed.
12061 .TP
12062 .B 3.
12063 If the command run by the \fBDEBUG\fP trap returns a value of 2, and the
12064 shell is executing in a subroutine (a shell function or a shell script
12065 executed by the \fB.\fP or \fBsource\fP builtins), the shell simulates
12066 a call to \fBreturn\fP.
12067 .TP
12068 .B 4.
12069 .SM
12070 .B BASH_ARGC
12071 and
12072 .SM
12073 .B BASH_ARGV
12074 are updated as described in their descriptions
12075 .ie \n(zZ=1 in \fIbash\fP(1)).
12076 .el above).
12077 .TP
12078 .B 5.
12079 Function tracing is enabled: command substitution, shell functions, and
12080 subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the
12081 \fBDEBUG\fP and \fBRETURN\fP traps.
12082 .TP
12083 .B 6.
12084 Error tracing is enabled: command substitution, shell functions, and
12085 subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the
12086 \fBERR\fP trap.
12087 .RE
12088 .TP 8
12089 .B extglob
12090 If set, enable the extended pattern matching features described
12091 .ie \n(zZ=1 in \fIbash\fP(1)
12092 .el above
12093 under
12094 \fBPathname Expansion\fP.
12095 .TP 8
12096 .B extquote
12097 If set, \fB$\fP\*'\fIstring\fP\*' and \fB$\fP\*"\fIstring\fP\*" quoting is
12098 performed within \fB${\fP\fIparameter\fP\fB}\fP expansions
12099 enclosed in double quotes.
12100 This option is enabled by default.
12101 .TP 8
12102 .B failglob
12103 If set, patterns which fail to match filenames during pathname expansion
12104 result in an expansion error.
12105 .TP 8
12106 .B force_fignore
12107 If set, the suffixes specified by the
12108 .SM
12109 .B FIGNORE
12110 shell variable
12111 cause words to be ignored when performing word completion even if
12112 the ignored words are the only possible completions.
12113 See
12114 .B "Shell Variables"
12115 .ie \n(zZ=1 in \fIbash\fP(1)
12116 .el above
12117 for a description of
12118 .SM
12119 .BR FIGNORE .
12120 This option is enabled by default.
12121 .TP 8
12122 .B globasciiranges
12123 If set, range expressions used in pattern matching bracket expressions (see
12124 .SM
12125 .B "Pattern Matching"
12126 .ie \n(zZ=1 in \fIbash\fP(1))
12127 .el above)
12128 behave as if in the traditional C locale when performing comparisons.
12129 That is, pattern matching does not take
12130 the current locale's collating sequence into account, so
12131 .B b
12132 will not collate between
12133 .B A
12134 and
12135 .BR B ,
12136 and upper-case and lower-case ASCII characters will collate together.
12137 .TP 8
12138 .B globskipdots
12139 If set, pathname expansion will never match the filenames
12140 .FN .\&
12141 and
12142 .FN ..\& ,
12143 even if the pattern begins with a
12144 .Q .\& .
12145 This option is enabled by default.
12146 .TP 8
12147 .B globstar
12148 If set, the pattern \fB**\fP used in a pathname expansion context will
12149 match all files and zero or more directories and subdirectories.
12150 If the pattern is followed by a \fB/\fP, only directories and
12151 subdirectories match.
12152 .TP 8
12153 .B gnu_errfmt
12154 If set, shell error messages are written in the standard GNU error
12155 message format.
12156 .TP 8
12157 .B histappend
12158 If set, the history list is appended to the file named by the value
12159 of the
12160 .SM
12161 .B HISTFILE
12162 variable when the shell exits, rather than overwriting the file.
12163 .TP 8
12164 .B histreedit
12165 If set, and
12166 .B readline
12167 is being used, the user is given the opportunity to re-edit a
12168 failed history substitution.
12169 .TP 8
12170 .B histverify
12171 If set, and
12172 .B readline
12173 is being used, the results of history substitution are not immediately
12174 passed to the shell parser.
12175 Instead, the resulting line is loaded into the \fBreadline\fP editing buffer,
12176 allowing further modification.
12177 .TP 8
12178 .B hostcomplete
12179 If set, and
12180 .B readline
12181 is being used, \fBbash\fP will attempt to perform hostname completion when a
12182 word containing a \fB@\fP is being completed (see
12183 .B Completing
12184 under
12185 .SM
12186 .B READLINE
12187 .ie \n(zZ=1 in \fIbash\fP(1)).
12188 .el above).
12189 This is enabled by default.
12190 .TP 8
12191 .B huponexit
12192 If set, \fBbash\fP will send
12193 .SM
12194 .B SIGHUP
12195 to all jobs when an interactive login shell exits.
12196 .TP 8
12197 .B inherit_errexit
12198 If set, command substitution inherits the value of the \fBerrexit\fP option,
12199 instead of unsetting it in the subshell environment.
12200 This option is enabled when posix mode is enabled.
12201 .TP 8
12202 .B interactive_comments
12203 In an interactive shell, a word beginning with \fB#\fP
12204 causes that word and all remaining characters on that
12205 line to be ignored, as in a non-interactive shell
12206 (see
12207 .SM
12208 .B COMMENTS
12209 .ie \n(zZ=1 in \fIbash\fP(1)).
12210 .el above).
12211 This option is enabled by default.
12212 .TP 8
12213 .B lastpipe
12214 If set, and job control is not active, the shell runs the last command of
12215 a pipeline not executed in the background in the current shell environment.
12216 .TP 8
12217 .B lithist
12218 If set, and the
12219 .B cmdhist
12220 option is enabled, multi-line commands are saved to the history with
12221 embedded newlines rather than using semicolon separators where possible.
12222 .TP 8
12223 .B localvar_inherit
12224 If set, local variables inherit the value and attributes of a variable of
12225 the same name that exists at a previous scope before any new value is
12226 assigned.
12227 The nameref attribute is not inherited.
12228 .TP 8
12229 .B localvar_unset
12230 If set, calling \fBunset\fP on local variables in previous function scopes
12231 marks them so subsequent lookups find them unset until that function
12232 returns.
12233 This is identical to the behavior of unsetting local variables at the
12234 current function scope.
12235 .TP 8
12236 .B login_shell
12237 The shell sets this option if it is started as a login shell (see
12238 .SM
12239 .B "INVOCATION"
12240 .ie \n(zZ=1 in \fIbash\fP(1)).
12241 .el above).
12242 The value may not be changed.
12243 .TP 8
12244 .B mailwarn
12245 If set, and a file that \fBbash\fP is checking for mail has been
12246 accessed since the last time it was checked,
12247 \fBbash\fP displays the message
12248 .Q "The mail in \fImailfile\fP has been read" .
12249 .TP 8
12250 .B no_empty_cmd_completion
12251 If set, and
12252 .B readline
12253 is being used,
12254 .B bash
12255 does not search
12256 .SM
12257 .B PATH
12258 for possible completions when completion is attempted on an empty line.
12259 .TP 8
12260 .B nocaseglob
12261 If set,
12262 .B bash
12263 matches filenames in a case\-insensitive fashion when performing pathname
12264 expansion (see
12265 .B "Pathname Expansion"
12266 .ie \n(zZ=1 in \fIbash\fP(1)).
12267 .el above).
12268 .TP 8
12269 .B nocasematch
12270 If set,
12271 .B bash
12272 matches patterns in a case\-insensitive fashion when performing matching
12273 while executing \fBcase\fP or \fB[[\fP conditional commands,
12274 when performing pattern substitution word expansions,
12275 or when filtering possible completions as part of programmable completion.
12276 .TP 8
12277 .B noexpand_translation
12278 If set,
12279 .B bash
12280 encloses the translated results of
12281 .BR $\*" .\|.\|.\& \*"
12282 quoting in single quotes instead of double quotes.
12283 If the string is not translated, this has no effect.
12284 .TP 8
12285 .B nullglob
12286 If set, pathname expansion patterns which match no files
12287 (see
12288 .B "Pathname Expansion"
12289 .ie \n(zZ=1 in \fIbash\fP(1))
12290 .el above)
12291 expand to nothing and are removed, rather than expanding to themselves.
12292 .TP 8
12293 .B patsub_replacement
12294 If set, \fBbash\fP
12295 expands occurrences of \fB&\fP in the replacement string of pattern
12296 substitution to the text matched by the pattern, as described
12297 under \fBParameter Expansion\fP
12298 .ie \n(zZ=1 in \fIbash\fP(1).
12299 .el above.
12300 This option is enabled by default.
12301 .TP 8
12302 .B progcomp
12303 If set, enable the programmable completion facilities (see
12304 \fBProgrammable Completion\fP
12305 .ie \n(zZ=1 in \fIbash\fP(1)).
12306 .el above).
12307 This option is enabled by default.
12308 .TP 8
12309 .B progcomp_alias
12310 If set, and programmable completion is enabled, \fBbash\fP treats a command
12311 name that doesn't have any completions as a possible alias and attempts
12312 alias expansion.
12313 If it has an alias, \fBbash\fP attempts programmable
12314 completion using the command word resulting from the expanded alias.
12315 .TP 8
12316 .B promptvars
12317 If set, prompt strings undergo
12318 parameter expansion, command substitution, arithmetic
12319 expansion, and quote removal after being expanded as described in
12320 .SM
12321 .B PROMPTING
12322 .ie \n(zZ=1 in \fIbash\fP(1).
12323 .el above.
12324 This option is enabled by default.
12325 .TP 8
12326 .B restricted_shell
12327 The shell sets this option if it is started in restricted mode
12328 (see
12329 .SM
12330 .B "RESTRICTED SHELL"
12331 .ie \n(zZ=1 in \fIbash\fP(1)).
12332 .el below).
12333 The value may not be changed.
12334 This is not reset when the startup files are executed, allowing
12335 the startup files to discover whether or not a shell is restricted.
12336 .TP 8
12337 .B shift_verbose
12338 If set, the
12339 .B shift
12340 builtin prints an error message when the shift count exceeds the
12341 number of positional parameters.
12342 .TP 8
12343 .B sourcepath
12344 If set, the
12345 \fB.\fP (\fBsource\fP) builtin uses the value of
12346 .SM
12347 .B PATH
12348 to find the directory containing the file supplied as an argument when
12349 the \fB\-p\fP option is not supplied.
12350 This option is enabled by default.
12351 .TP 8
12352 .B varredir_close
12353 If set, the shell automatically closes file descriptors assigned using the
12354 \fI{varname}\fP redirection syntax (see
12355 .SM
12356 .B REDIRECTION
12357 .ie \n(zZ=1 in \fIbash\fP(1))
12358 .el above)
12359 instead of leaving them open when the command completes.
12360 .TP 8
12361 .B xpg_echo
12362 If set, the \fBecho\fP builtin expands backslash-escape sequences
12363 by default.
12364 If the \fBposix\fP shell option is also enabled, \fBecho\fP does not
12365 interpret any options.
12366 .RE
12367 .PD
12368 .TP
12369 \fBsuspend\fP [\fB\-f\fP]
12370 Suspend the execution of this shell until it receives a
12371 .SM
12372 .B SIGCONT
12373 signal.
12374 A login shell, or a shell without job control enabled,
12375 cannot be suspended; the
12376 .B \-f
12377 option will override this and force the suspension.
12378 The return status is 0 unless the shell is a login shell
12379 or job control is not enabled
12380 and
12381 .B \-f
12382 is not supplied.
12383 .TP
12384 \fBtest\fP \fIexpr\fP
12385 .PD 0
12386 .TP
12387 \fB[\fP \fIexpr\fP \fB]\fP
12388 .PD
12389 Return a status of 0 (true) or 1 (false) depending on
12390 the evaluation of the conditional expression
12391 .IR expr .
12392 Each operator and operand must be a separate argument.
12393 Expressions are composed of the primaries described
12394 .ie \n(zZ=1 in \fIbash\fP(1)
12395 .el above
12396 under
12397 .SM
12398 .BR "CONDITIONAL EXPRESSIONS" .
12399 \fBtest\fP does not accept any options, nor does it accept and ignore
12400 an argument of \fB\-\-\fP as signifying the end of options.
12401 .IP
12402 Expressions may be combined using the following operators, listed
12403 in decreasing order of precedence.
12404 The evaluation depends on the number of arguments; see below.
12405 \fBtest\fP uses operator precedence when there are five or more arguments.
12406 .RS
12407 .PD 0
12408 .TP
12409 .B ! \fIexpr\fP
12410 True if
12411 .I expr
12412 is false.
12413 .TP
12414 .B ( \fIexpr\fP )
12415 Returns the value of \fIexpr\fP.
12416 This may be used to override normal operator precedence.
12417 .TP
12418 \fIexpr1\fP \-\fBa\fP \fIexpr2\fP
12419 True if both
12420 .I expr1
12421 and
12422 .I expr2
12423 are true.
12424 .TP
12425 \fIexpr1\fP \-\fBo\fP \fIexpr2\fP
12426 True if either
12427 .I expr1
12428 or
12429 .I expr2
12430 is true.
12431 .PD
12432 .PP
12433 \fBtest\fP and \fB[\fP evaluate conditional
12434 expressions using a set of rules based on the number of arguments.
12435 .PP
12436 .PD 0
12437 .TP
12438 0 arguments
12439 The expression is false.
12440 .TP
12441 1 argument
12442 The expression is true if and only if the argument is not null.
12443 .TP
12444 2 arguments
12445 If the first argument is \fB!\fP, the expression is true if and
12446 only if the second argument is null.
12447 If the first argument is one of the unary conditional operators listed
12448 .ie \n(zZ=1 in \fIbash\fP(1)
12449 .el above
12450 under
12451 .SM
12452 .BR "CONDITIONAL EXPRESSIONS" ,
12453 the expression is true if the unary test is true.
12454 If the first argument is not a valid unary conditional operator, the expression
12455 is false.
12456 .TP
12457 3 arguments
12458 The following conditions are applied in the order listed.
12459 If the second argument is one of the binary conditional operators listed
12460 .ie \n(zZ=1 in \fIbash\fP(1)
12461 .el above
12462 under
12463 .SM
12464 .BR "CONDITIONAL EXPRESSIONS" ,
12465 the result of the expression is the result of the binary test using
12466 the first and third arguments as operands.
12467 The \fB\-a\fP and \fB\-o\fP operators are considered binary operators
12468 when there are three arguments.
12469 If the first argument is \fB!\fP, the value is the negation of
12470 the two-argument test using the second and third arguments.
12471 If the first argument is exactly \fB(\fP and the third argument is
12472 exactly \fB)\fP, the result is the one-argument test of the second
12473 argument.
12474 Otherwise, the expression is false.
12475 .TP
12476 4 arguments
12477 The following conditions are applied in the order listed.
12478 If the first argument is \fB!\fP, the result is the negation of
12479 the three-argument expression composed of the remaining arguments.
12480 If the first argument is exactly \fB(\fP and the fourth argument is
12481 exactly \fB)\fP, the result is the two-argument test of the second
12482 and third arguments.
12483 Otherwise, the expression is parsed and evaluated according to
12484 precedence using the rules listed above.
12485 .TP
12486 5 or more arguments
12487 The expression is parsed and evaluated according to precedence
12488 using the rules listed above.
12489 .PD
12490 .PP
12491 When the shell is in posix mode, or if the expression is part
12492 of the \fB[[\fP command,
12493 the \fB<\fP and \fB>\fP operators sort using the
12494 current locale.
12495 If the shell is not in posix mode, the \fBtest\fP and \fB[\fP
12496 commands sort lexicographically using ASCII ordering.
12497 .PP
12498 The historical operator-precedence parsing with 4 or more arguments can
12499 lead to ambiguities when it encounters strings that look like primaries.
12500 The
12501 .SM POSIX
12502 standard has deprecated the \fB\-a\fP and \fB\-o\fP
12503 primaries and enclosing expressions within parentheses.
12504 Scripts should no longer use them.
12505 It's much more reliable to restrict test invocations to a single primary,
12506 and to replace uses of \fB\-a\fP and \fB\-o\fP with the shell's
12507 \fB&&\fP and \fB||\fP list operators.
12508 .RE
12509 .TP
12510 .B times
12511 Print the accumulated user and system times for the shell and
12512 for processes run from the shell.
12513 The return status is 0.
12514 .TP
12515 \fBtrap\fP [\fB\-lpP\fP] [[\fIaction\fP] \fIsigspec\fP .\|.\|.]
12516 The
12517 .I action
12518 is a command that is read and executed when the shell receives
12519 any of the signals
12520 .IR sigspec .
12521 If
12522 .I action
12523 is absent (and there is a single \fIsigspec\fP) or
12524 .BR \- ,
12525 each specified \fIsigspec\fP is
12526 reset to the value it had when the shell was started.
12527 If
12528 .I action
12529 is the null string the signal specified by each
12530 .I sigspec
12531 is ignored by the shell and by the commands it invokes.
12532 .IP
12533 If no arguments are supplied,
12534 .B trap
12535 displays the actions associated with each trapped signal
12536 as a set of \fBtrap\fP commands
12537 that can be reused as shell input to
12538 restore the current signal dispositions.
12539 If
12540 .B \-p
12541 is given,
12542 and
12543 .I action
12544 is not present,
12545 then \fBtrap\fP displays the actions associated with each
12546 .I sigspec
12547 or, if none are supplied, for all trapped signals,
12548 as a set of \fBtrap\fP commands
12549 that can be reused as shell input to
12550 restore the current signal dispositions.
12551 The
12552 .B \-P
12553 option behaves similarly, but displays only the actions
12554 associated with each \fIsigspec\fP argument.
12555 .B \-P
12556 requires at least one \fIsigspec\fP argument.
12557 The \fB\-P\fP or \fB\-p\fP options may be used
12558 in a subshell environment (e.g., command substitution) and, as
12559 long as they are used before \fBtrap\fP is used to change a signal's
12560 handling, will display the state of its parent's traps.
12561 .IP
12562 The
12563 .B \-l
12564 option prints a list of signal names and
12565 their corresponding numbers.
12566 Each
12567 .I sigspec
12568 is either
12569 a signal name defined in <\fIsignal.h\fP>, or a signal number.
12570 Signal names are case insensitive and the
12571 .SM
12572 .B SIG
12573 prefix is optional.
12574 If \fB\-l\fP is supplied with no \fIsigspec\fP arguments, it prints a
12575 list of valid signal names.
12576 .IP
12577 If a
12578 .I sigspec
12579 is
12580 .SM
12581 .B EXIT
12582 (0),
12583 .I action
12584 is executed on exit from the shell.
12585 If a
12586 .I sigspec
12587 is
12588 .SM
12589 .BR DEBUG ,
12590 .I action
12591 is executed before every \fIsimple command\fP, \fIfor\fP command,
12592 \fIcase\fP command, \fIselect\fP command, (( arithmetic command,
12593 [[ conditional command,
12594 arithmetic \fIfor\fP command, and before the first command executes
12595 in a shell function (see
12596 .SM
12597 .B "SHELL GRAMMAR"
12598 .ie \n(zZ=1 in \fIbash\fP(1)).
12599 .el above).
12600 Refer to the description of the \fBextdebug\fP shell option
12601 (see
12602 .B shopt
12603 .ie \n(zZ=1 in \fIbash\fP(1))
12604 .el above)
12605 for details of its effect on the \fBDEBUG\fP trap.
12606 If a
12607 .I sigspec
12608 is
12609 .SM
12610 .BR RETURN ,
12611 .I action
12612 is executed each time a shell function or a script executed with
12613 the \fB.\fP or \fBsource\fP builtins finishes executing.
12614 .IP
12615 If a
12616 .I sigspec
12617 is
12618 .SM
12619 .BR ERR ,
12620 .I action
12621 is executed whenever
12622 a pipeline (which may consist of a single simple
12623 command), a list, or a compound command returns a
12624 non\-zero exit status,
12625 subject to the following conditions.
12626 The
12627 .SM
12628 .B ERR
12629 trap is not executed if the failed
12630 command is part of the command list immediately following a
12631 .B while
12632 or
12633 .B until
12634 reserved word,
12635 part of the test in an
12636 .I if
12637 statement, part of a command executed in a
12638 .B &&
12639 or
12640 .B ||
12641 list except the command following the final \fB&&\fP or \fB||\fP,
12642 any command in a pipeline but the last
12643 (subject to the state of the \fBpipefail\fP shell option),
12644 or if the command's return value is
12645 being inverted using
12646 .BR ! .
12647 These are the same conditions obeyed by the \fBerrexit\fP (\fB\-e\fP) option.
12648 .IP
12649 When the shell is not interactive,
12650 signals ignored upon entry to the shell cannot be trapped or reset.
12651 Interactive shells permit trapping signals ignored on entry.
12652 Trapped signals that are not being ignored are reset to their original
12653 values in a subshell or subshell environment when one is created.
12654 The return status is false if any
12655 .I sigspec
12656 is invalid; otherwise
12657 .B trap
12658 returns true.
12659 .TP
12660 \fBtrue\fP
12661 Does nothing, returns a 0 status.
12662 .TP
12663 \fBtype\fP [\fB\-aftpP\fP] \fIname\fP [\fIname\fP .\|.\|.]
12664 Indicate how each
12665 .I name
12666 would be interpreted if used as a command name.
12667 .IP
12668 If the
12669 .B \-t
12670 option is used,
12671 .B type
12672 prints a string which is one of
12673 .IR alias ,
12674 .IR keyword ,
12675 .IR function ,
12676 .IR builtin ,
12677 or
12678 .I file
12679 if
12680 .I name
12681 is an alias, shell reserved word, function, builtin, or executable file,
12682 respectively.
12683 If the
12684 .I name
12685 is not found, \fBtype\fP prints nothing and returns a non-zero exit status.
12686 .IP
12687 If the
12688 .B \-p
12689 option is used,
12690 .B type
12691 either returns the pathname of the executable file
12692 that would be found by searching
12693 .B $PATH
12694 for
12695 .I name
12696 or nothing if
12697 .Q "type \-t name"
12698 would not return
12699 .IR file .
12700 The
12701 .B \-P
12702 option forces a
12703 .SM
12704 .B PATH
12705 search for each \fIname\fP, even if
12706 .Q "type \-t name"
12707 would not return
12708 .IR file .
12709 If \fIname\fP is present in the table of hashed commands,
12710 .B \-p
12711 and
12712 .B \-P
12713 print the hashed value, which is not necessarily the file that appears
12714 first in
12715 .SM
12716 .BR PATH .
12717 .IP
12718 If the
12719 .B \-a
12720 option is used,
12721 .B type
12722 prints all of the places that contain a command named
12723 .IR name .
12724 This includes aliases, reserved words, functions, and builtins,
12725 but the path search options (\fB\-p\fP and \fB\-P\fP)
12726 can be supplied to restrict the output to executable files.
12727 \fBtype\fP does not consult the table of hashed commands
12728 when using
12729 .B \-a
12730 with
12731 .BR \-p ,
12732 and only performs a
12733 .SM
12734 .B PATH
12735 search for \fIname\fP.
12736 .IP
12737 The
12738 .B \-f
12739 option suppresses shell function lookup, as with the \fBcommand\fP builtin.
12740 .B type
12741 returns true if all of the arguments are found, false if
12742 any are not found.
12743 .TP
12744 \fBulimit\fP [\fB\-HS\fP] \fB\-a\fP
12745 .PD 0
12746 .TP
12747 \fBulimit\fP [\fB\-HS\fP] [\fB\-bcdefiklmnpqrstuvxPRT\fP [\fIlimit\fP]]
12748 .PD
12749 Provides control over the resources available to the shell and to
12750 processes it starts, on systems that allow such control.
12751 .IP
12752 The \fB\-H\fP and \fB\-S\fP options specify whether
12753 the hard or soft limit is set for the given resource.
12754 A hard limit cannot be increased by a non-root user once it is set;
12755 a soft limit may be increased up to the value of the hard limit.
12756 If neither \fB\-H\fP nor \fB\-S\fP is specified,
12757 \fBulimit\fP sets both the soft and hard limits.
12758 .IP
12759 The value of
12760 .I limit
12761 can be a number in the unit specified for the resource
12762 or one of the special values
12763 .BR hard ,
12764 .BR soft ,
12765 or
12766 .BR unlimited ,
12767 which stand for the current hard limit, the current soft limit, and
12768 no limit, respectively.
12769 If
12770 .I limit
12771 is omitted, \fBulimit\fP prints the current value of the soft limit of
12772 the resource, unless the \fB\-H\fP option is given.
12773 When more than one resource is specified, the limit name and unit,
12774 if appropriate, are printed before the value.
12775 Other options are interpreted as follows:
12776 .RS
12777 .PD 0
12778 .TP
12779 .B \-a
12780 Report all current limits; no limits are set.
12781 .TP
12782 .B \-b
12783 The maximum socket buffer size.
12784 .TP
12785 .B \-c
12786 The maximum size of core files created.
12787 .TP
12788 .B \-d
12789 The maximum size of a process's data segment.
12790 .TP
12791 .B \-e
12792 The maximum scheduling priority (\c
12793 .Q nice ).
12794 .TP
12795 .B \-f
12796 The maximum size of files written by the shell and its children.
12797 .TP
12798 .B \-i
12799 The maximum number of pending signals.
12800 .TP
12801 .B \-k
12802 The maximum number of kqueues that may be allocated.
12803 .TP
12804 .B \-l
12805 The maximum size that may be locked into memory.
12806 .TP
12807 .B \-m
12808 The maximum resident set size (many systems do not honor this limit).
12809 .TP
12810 .B \-n
12811 The maximum number of open file descriptors (most systems do not
12812 allow this value to be set).
12813 .TP
12814 .B \-p
12815 The pipe size in 512-byte blocks (this may not be set).
12816 .TP
12817 .B \-q
12818 The maximum number of bytes in
12819 .SM POSIX
12820 message queues.
12821 .TP
12822 .B \-r
12823 The maximum real-time scheduling priority.
12824 .TP
12825 .B \-s
12826 The maximum stack size.
12827 .TP
12828 .B \-t
12829 The maximum amount of cpu time in seconds.
12830 .TP
12831 .B \-u
12832 The maximum number of processes available to a single user.
12833 .TP
12834 .B \-v
12835 The maximum amount of virtual memory available to the shell and, on
12836 some systems, to its children.
12837 .TP
12838 .B \-x
12839 The maximum number of file locks.
12840 .TP
12841 .B \-P
12842 The maximum number of pseudoterminals.
12843 .TP
12844 .B \-R
12845 The maximum time a real-time process can run before blocking, in microseconds.
12846 .TP
12847 .B \-T
12848 The maximum number of threads.
12849 .PD
12850 .PP
12851 If
12852 .I limit
12853 is supplied, and the
12854 .B \-a
12855 option is not used,
12856 \fIlimit\fP is the new value of the specified resource.
12857 If no option is supplied, then
12858 .B \-f
12859 is assumed.
12860 .PP
12861 Values are in 1024-byte increments, except for
12862 .BR \-t ,
12863 which is in seconds;
12864 .BR \-R ,
12865 which is in microseconds;
12866 .BR \-p ,
12867 which is in units of 512-byte blocks;
12868 .BR \-P ,
12869 .BR \-T ,
12870 .BR \-b ,
12871 .BR \-k ,
12872 .BR \-n ,
12873 and
12874 .BR \-u ,
12875 which are unscaled values;
12876 and, when in posix mode,
12877 .B \-c
12878 and
12879 .BR \-f ,
12880 which are in 512-byte increments.
12881 The return status is 0 unless an invalid option or argument is supplied,
12882 or an error occurs while setting a new limit.
12883 .RE
12884 .TP
12885 \fBumask\fP [\fB\-p\fP] [\fB\-S\fP] [\fImode\fP]
12886 Set the user file-creation mask to
12887 .IR mode .
12888 If
12889 .I mode
12890 begins with a digit, it is interpreted as an octal number;
12891 otherwise it is interpreted as a symbolic mode mask similar
12892 to that accepted by
12893 .IR chmod (1).
12894 If
12895 .I mode
12896 is omitted, \fBumask\fP prints the current value of the mask.
12897 The
12898 .B \-S
12899 option without a \fImode\fP argument
12900 prints the mask in a symbolic format;
12901 the default output is an octal number.
12902 If the
12903 .B \-p
12904 option is supplied, and
12905 .I mode
12906 is omitted, the output is in a form that may be reused as input.
12907 The return status is zero if the mode was successfully changed or
12908 if no \fImode\fP argument was supplied, and non-zero otherwise.
12909 .TP
12910 \fBunalias\fP [\-\fBa\fP] [\fIname\fP .\|.\|.]
12911 Remove each \fIname\fP from the list of defined aliases.
12912 If
12913 .B \-a
12914 is supplied, remove all alias definitions.
12915 The return value is true unless a supplied
12916 .I name
12917 is not a defined alias.
12918 .TP
12919 \fBunset\fP [\-\fBfv\fP] [\-\fBn\fP] [\fIname\fP .\|.\|.]
12920 For each
12921 .IR name ,
12922 remove the corresponding variable or function.
12923 If the
12924 .B \-v
12925 option is given, each
12926 .I name
12927 refers to a shell variable, and that variable is removed.
12928 If
12929 .B \-f
12930 is specified, each
12931 .I name
12932 refers to a shell function, and the function definition
12933 is removed.
12934 If the
12935 .B \-n
12936 option is supplied, and \fIname\fP is a variable with the \fInameref\fP
12937 attribute, \fIname\fP will be unset rather than the variable it
12938 references.
12939 \fB\-n\fP has no effect if the \fB\-f\fP option is supplied.
12940 Read-only variables and functions may not be unset.
12941 When variables or functions are removed, they are also removed
12942 from the environment passed to subsequent commands.
12943 If no options are supplied, each \fIname\fP refers to a variable; if
12944 there is no variable by that name, a function with that name, if any, is
12945 unset.
12946 Some shell variables may not be unset.
12947 If any of
12948 .SM
12949 .BR BASH_ALIASES ,
12950 .SM
12951 .BR BASH_ARGV0 ,
12952 .SM
12953 .BR BASH_CMDS ,
12954 .SM
12955 .BR BASH_COMMAND ,
12956 .SM
12957 .BR BASH_SUBSHELL ,
12958 .SM
12959 .BR BASHPID ,
12960 .SM
12961 .BR COMP_WORDBREAKS ,
12962 .SM
12963 .BR DIRSTACK ,
12964 .SM
12965 .BR EPOCHREALTIME ,
12966 .SM
12967 .BR EPOCHSECONDS ,
12968 .SM
12969 .BR FUNCNAME ,
12970 .SM
12971 .BR GROUPS ,
12972 .SM
12973 .BR HISTCMD ,
12974 .SM
12975 .BR LINENO ,
12976 .SM
12977 .BR RANDOM ,
12978 .SM
12979 .BR SECONDS ,
12980 or
12981 .SM
12982 .B SRANDOM
12983 are unset, they lose their special properties, even if they are
12984 subsequently reset.
12985 The exit status is true unless a
12986 .I name
12987 is readonly or may not be unset.
12988 .TP
12989 \fBwait\fP [\fB\-fn\fP] [\fP\-p\fP \fIvarname\fP] [\fIid\fP .\|.\|.]
12990 Wait for each specified child process \fIid\fP and return the
12991 termination status of the last \fIid\fP.
12992 Each \fIid\fP may be a process ID \fIpid\fP
12993 or a job specification \fIjobspec\fP;
12994 if a jobspec is supplied, \fBwait\fP waits for all processes in the job.
12995 .IP
12996 If no options or \fIid\fPs are supplied,
12997 \fBwait\fP waits for all running background jobs and
12998 the last-executed process substitution,
12999 if its process id is the same as \fB$!\fP,
13000 and the return status is zero.
13001 .IP
13002 If the \fB\-n\fP option is supplied, \fBwait\fP waits for any one of
13003 the given \fIid\fPs or,
13004 if no \fIid\fPs are supplied, any job or process substitution,
13005 to complete and returns its exit status.
13006 If none of the supplied \fIid\fPs is a child of the shell,
13007 or if no \fIid\fPs are supplied and the shell has no unwaited-for children,
13008 the exit status is 127.
13009 .IP
13010 If the \fB\-p\fP option is supplied, \fBwait\fP assigns
13011 the process or job identifier of the job
13012 for which the exit status is returned to the
13013 variable \fIvarname\fP named by the option argument.
13014 The variable,
13015 which cannot be readonly,
13016 will be unset initially, before any assignment.
13017 This is useful only when used with the \fB\-n\fP option.
13018 .IP
13019 Supplying the \fB\-f\fP option, when job control is enabled,
13020 forces \fBwait\fP to wait for each \fIid\fP to terminate before
13021 returning its status, instead of returning when it changes status.
13022 .IP
13023 If none of the \fIid\fPs specify one of the shell's active child
13024 processes, the return status is 127.
13025 If \fBwait\fP is interrupted by a signal,
13026 any \fIvarname\fP will remain unset,
13027 and the return status will be greater
13028 than 128, as described under
13029 .B SIGNALS
13030 .ie \n(zZ=1 in \fIbash\fP(1).
13031 .el above.
13032 Otherwise, the return status is the exit status of the last \fIid\fP.
13033 .SH "SHELL COMPATIBILITY MODE"
13034 Bash-4.0 introduced the concept of a \fIshell compatibility level\fP,
13035 specified as a set of options to the shopt builtin (\c
13036 .BR compat31 ,
13037 .BR compat32 ,
13038 .BR compat40 ,
13039 .BR compat41 ,
13040 and so on).
13041 There is only one current
13042 compatibility level \(em each option is mutually exclusive.
13043 The compatibility level is intended to allow users to select behavior
13044 from previous versions that is incompatible with newer versions
13045 while they migrate scripts to use current features and behavior.
13046 It's intended to be a temporary solution.
13047 .PP
13048 This section does not mention behavior that is standard for a particular
13049 version (e.g., setting \fBcompat32\fP means that quoting the right hand
13050 side of the regexp
13051 matching operator quotes special regexp characters in the word, which is
13052 default behavior in bash-3.2 and subsequent versions).
13053 .PP
13054 If a user enables, say, \fBcompat32\fP, it may affect the behavior of other
13055 compatibility levels up to and including the current compatibility level.
13056 The idea is that each compatibility level controls behavior that changed
13057 in that version of \fBbash\fP,
13058 but that behavior may have been present in earlier versions.
13059 For instance, the change to use locale-based comparisons with the \fB[[\fP
13060 command came in bash-4.1, and earlier versions used ASCII-based comparisons,
13061 so enabling \fBcompat32\fP will enable ASCII-based comparisons as well.
13062 That granularity may not be sufficient for
13063 all uses, and as a result users should employ compatibility levels carefully.
13064 Read the documentation for a particular feature to find out the
13065 current behavior.
13066 .PP
13067 Bash-4.3 introduced a new shell variable:
13068 .SM
13069 .BR BASH_COMPAT .
13070 The value assigned
13071 to this variable (a decimal version number like 4.2, or an integer
13072 corresponding to the \fBcompat\fP\fINN\fP option, like 42) determines the
13073 compatibility level.
13074 .PP
13075 Starting with bash-4.4, \fBbash\fP began deprecating older compatibility
13076 levels.
13077 Eventually, the options will be removed in favor of
13078 .SM
13079 .BR BASH_COMPAT .
13080 .PP
13081 Bash-5.0 was the final version for which there was an individual shopt
13082 option for the previous version.
13083 .SM
13084 .B BASH_COMPAT
13085 is the only mechanism to control the compatibility level
13086 in versions newer than bash-5.0.
13087 .PP
13088 The following table describes the behavior changes controlled by each
13089 compatibility level setting.
13090 The \fBcompat\fP\fINN\fP tag is used as shorthand for setting the
13091 compatibility level
13092 to \fINN\fP using one of the following mechanisms.
13093 For versions prior to bash-5.0, the compatibility level may be set using
13094 the corresponding \fBcompat\fP\fINN\fP shopt option.
13095 For bash-4.3 and later versions, the
13096 .SM
13097 .B BASH_COMPAT
13098 variable is preferred,
13099 and it is required for bash-5.1 and later versions.
13100 .TP
13101 \fBcompat31\fP
13102 .PD 0
13103 .RS
13104 .IP \(bu
13105 Quoting the rhs of the \fB[[\fP command's regexp matching operator (=\*~)
13106 has no special effect.
13107 .RE
13108 .PD
13109 .TP
13110 \fBcompat32\fP
13111 .PD 0
13112 .RS
13113 .IP \(bu
13114 The \fB<\fP and \fB>\fP operators to the \fB[[\fP command do not
13115 consider the current locale when comparing strings; they use ASCII
13116 ordering.
13117 .RE
13118 .PD
13119 .TP
13120 \fBcompat40\fP
13121 .PD 0
13122 .RS
13123 .IP \(bu
13124 The \fB<\fP and \fB>\fP operators to the \fB[[\fP command do not
13125 consider the current locale when comparing strings; they use ASCII
13126 ordering.
13127 \fBBash\fP versions prior to bash-4.1 use ASCII collation and
13128 .IR strcmp (3);
13129 bash-4.1 and later use the current locale's collation sequence and
13130 .IR strcoll (3).
13131 .RE
13132 .PD
13133 .TP
13134 \fBcompat41\fP
13135 .PD 0
13136 .RS
13137 .IP \(bu
13138 In posix mode, \fBtime\fP may be followed by options and still be
13139 recognized as a reserved word (this is
13140 .SM POSIX
13141 interpretation 267).
13142 .IP \(bu
13143 In \fIposix\fP mode, the parser requires that an even number of single
13144 quotes occur in the \fIword\fP portion of a double-quoted
13145 parameter expansion and treats them specially, so that characters within
13146 the single quotes are considered quoted
13147 (this is
13148 .SM POSIX
13149 interpretation 221).
13150 .RE
13151 .PD
13152 .TP
13153 \fBcompat42\fP
13154 .PD 0
13155 .RS
13156 .IP \(bu
13157 The replacement string in double-quoted pattern substitution does not
13158 undergo quote removal, as it does in versions after bash-4.2.
13159 .IP \(bu
13160 In posix mode, single quotes are considered special when expanding
13161 the \fIword\fP portion of a double-quoted parameter expansion
13162 and can be used to quote a closing brace or other special character
13163 (this is part of
13164 .SM POSIX
13165 interpretation 221);
13166 in later versions, single quotes
13167 are not special within double-quoted word expansions.
13168 .RE
13169 .PD
13170 .TP
13171 \fBcompat43\fP
13172 .PD 0
13173 .RS
13174 .IP \(bu
13175 Word expansion errors are considered non-fatal errors that cause the
13176 current command to fail, even in posix mode
13177 (the default behavior is to make them fatal errors that cause the shell
13178 to exit).
13179 .IP \(bu
13180 When executing a shell function, the loop state (while/until/etc.)
13181 is not reset, so \fBbreak\fP or \fBcontinue\fP in that function will break
13182 or continue loops in the calling context.
13183 Bash-4.4 and later reset the loop state to prevent this.
13184 .RE
13185 .PD
13186 .TP
13187 \fBcompat44\fP
13188 .PD 0
13189 .RS
13190 .IP \(bu
13191 The shell sets up the values used by
13192 .SM
13193 .B BASH_ARGV
13194 and
13195 .SM
13196 .B BASH_ARGC
13197 so they can expand to the shell's positional parameters even if extended
13198 debugging mode is not enabled.
13199 .IP \(bu
13200 A subshell inherits loops from its parent context, so \fBbreak\fP
13201 or \fBcontinue\fP will cause the subshell to exit.
13202 Bash-5.0 and later reset the loop state to prevent the exit
13203 .IP \(bu
13204 Variable assignments preceding builtins like \fBexport\fP and \fBreadonly\fP
13205 that set attributes continue to affect variables with the same
13206 name in the calling environment even if the shell is not in posix
13207 mode.
13208 .RE
13209 .PD
13210 .TP
13211 \fBcompat50\fP
13212 .PD 0
13213 .RS
13214 .IP \(bu
13215 Bash-5.1 changed the way
13216 .SM
13217 .B $RANDOM
13218 is generated to introduce slightly more randomness.
13219 If the shell compatibility level is set to 50 or
13220 lower, it reverts to the method from bash-5.0 and previous versions,
13221 so seeding the random number generator by assigning a value to
13222 .SM
13223 .B RANDOM
13224 will produce the same sequence as in bash-5.0.
13225 .IP \(bu
13226 If the command hash table is empty, bash versions prior to bash-5.1
13227 printed an informational message to that effect, even when producing
13228 output that can be reused as input.
13229 Bash-5.1 suppresses that message
13230 when the \fB\-l\fP option is supplied.
13231 .RE
13232 .PD
13233 .TP
13234 \fBcompat51\fP
13235 .PD 0
13236 .RS
13237 .IP \(bu
13238 The \fBunset\fP builtin treats attempts to unset array subscripts \fB@\fP
13239 and \fB*\fP differently depending on whether the array is indexed or
13240 associative, and differently than in previous versions.
13241 .IP \(bu
13242 Arithmetic commands (
13243 .BR (( .\|.\|.\& ))
13244 ) and the expressions in an arithmetic for
13245 statement can be expanded more than once.
13246 .IP \(bu
13247 Expressions used as arguments to arithmetic operators in the \fB[[\fP
13248 conditional command can be expanded more than once.
13249 .IP \(bu
13250 The expressions in substring parameter brace expansion can be
13251 expanded more than once.
13252 .IP \(bu
13253 The expressions in the
13254 .BR $(( .\|.\|.\& ))
13255 word expansion can be expanded more than once.
13256 .IP \(bu
13257 Arithmetic expressions used as indexed array subscripts can be
13258 expanded more than once.
13259 .IP \(bu
13260 \fBtest \-v\fP, when given an argument of \fBA[@]\fP, where \fBA\fP is
13261 an existing associative array, will return true if the array has any set
13262 elements.
13263 Bash-5.2 will look for and report on a key named \fB@\fP.
13264 .IP \(bu
13265 The ${\fIparameter\fP\fB[:]=\fP\fIvalue\fP} word expansion will return
13266 \fIvalue\fP, before any variable-specific transformations have been
13267 performed (e.g., converting to lowercase).
13268 Bash-5.2 will return the final value assigned to the variable.
13269 .IP \(bu
13270 Parsing command substitutions will behave as if extended globbing
13271 (see the description of the
13272 .B shopt
13273 builtin above)
13274 is enabled, so that parsing a command substitution containing an extglob
13275 pattern (say, as part of a shell function) will not fail.
13276 This assumes the intent is to enable extglob before the command is executed
13277 and word expansions are performed.
13278 It will fail at word expansion time if extglob hasn't been
13279 enabled by the time the command is executed.
13280 .RE
13281 .PD
13282 .TP
13283 \fBcompat52\fP
13284 .PD 0
13285 .RS
13286 .IP \(bu
13287 The \fBtest\fP builtin uses its historical algorithm to parse parenthesized
13288 subexpressions when given five or more arguments.
13289 .IP \(bu
13290 If the \fB\-p\fP or \fB\-P\fP option is supplied to the \fBbind\fP builtin,
13291 \fBbind\fP treats any arguments remaining after option processing
13292 as bindable command names, and
13293 displays any key sequences bound to those commands, instead of treating
13294 the arguments as key sequences to bind.
13295 .RE
13296 .PD
13297 .\" bash_builtins
13298 .if \n(zZ=1 .ig zZ
13299 .SH "RESTRICTED SHELL"
13300 .\" rbash.1
13301 .zY
13302 .PP
13303 If
13304 .B bash
13305 is started with the name
13306 .BR rbash ,
13307 or the
13308 .B \-r
13309 option is supplied at invocation, the shell becomes \fIrestricted\fP.
13310 A restricted shell is used to
13311 set up an environment more controlled than the standard shell.
13312 It behaves identically to
13313 .B bash
13314 with the exception that the following are disallowed or not performed:
13315 .IP \(bu
13316 Changing directories with \fBcd\fP.
13317 .IP \(bu
13318 Setting or unsetting the values of
13319 .SM
13320 .BR SHELL ,
13321 .SM
13322 .BR PATH ,
13323 .SM
13324 .BR HISTFILE ,
13325 .SM
13326 .BR ENV ,
13327 or
13328 .SM
13329 .BR BASH_ENV .
13330 .IP \(bu
13331 Specifying command names containing
13332 .BR / .
13333 .IP \(bu
13334 Specifying a filename containing a
13335 .B /
13336 as an argument to the
13337 .B .
13338 builtin command.
13339 .IP \(bu
13340 Using the \fB\-p\fP option to the
13341 .B .
13342 builtin command to specify a search path.
13343 .IP \(bu
13344 Specifying a filename containing a slash as an argument to the
13345 .B history
13346 builtin command.
13347 .IP \(bu
13348 Specifying a filename containing a slash as an argument to the
13349 .B \-p
13350 option to the
13351 .B hash
13352 builtin command.
13353 .IP \(bu
13354 Importing function definitions from the shell environment at startup.
13355 .IP \(bu
13356 Parsing the values of
13357 .SM
13358 .B BASHOPTS
13359 and
13360 .SM
13361 .B SHELLOPTS
13362 from the shell environment at startup.
13363 .IP \(bu
13364 Redirecting output using the >, >|, <>, >&, &>, and >> redirection operators.
13365 .IP \(bu
13366 Using the
13367 .B exec
13368 builtin command to replace the shell with another command.
13369 .IP \(bu
13370 Adding or deleting builtin commands with the
13371 .B \-f
13372 and
13373 .B \-d
13374 options to the
13375 .B enable
13376 builtin command.
13377 .IP \(bu
13378 Using the \fBenable\fP builtin command to enable disabled shell builtins.
13379 .IP \(bu
13380 Specifying the
13381 .B \-p
13382 option to the
13383 .B command
13384 builtin command.
13385 .IP \(bu
13386 Turning off restricted mode with
13387 \fBset +r\fP or \fBshopt \-u restricted_shell\fP.
13388 .PP
13389 These restrictions are enforced after any startup files are read.
13390 .PP
13391 .ie \n(zY=1 When a command that is found to be a shell script is executed,
13392 .el \{ When a command that is found to be a shell script is executed
13393 (see
13394 .SM
13395 .B "COMMAND EXECUTION"
13396 above),
13397 .\}
13398 .B rbash
13399 turns off any restrictions in the shell spawned to execute the
13400 script.
13401 .\" end of rbash.1
13402 .if \n(zY=1 .ig zY
13403 .SH "SEE ALSO"
13404 .PD 0
13405 .TP
13406 \fIBash Reference Manual\fP, Brian Fox and Chet Ramey
13407 .TP
13408 \fIThe Gnu Readline Library\fP, Brian Fox and Chet Ramey
13409 .TP
13410 \fIThe Gnu History Library\fP, Brian Fox and Chet Ramey
13411 .TP
13412 \fIPortable Operating System Interface (POSIX) Part 2: Shell and Utilities\fP, IEEE \(em
13413 http://pubs.opengroup.org/onlinepubs/9799919799/
13414 .TP
13415 http://tiswww.case.edu/\*~chet/bash/POSIX \(em a description of posix mode
13416 .TP
13417 \fIsh\fP(1), \fIksh\fP(1), \fIcsh\fP(1)
13418 .TP
13419 \fIemacs\fP(1), \fIvi\fP(1)
13420 .TP
13421 \fIreadline\fP(3)
13422 .PD
13423 .SH FILES
13424 .PD 0
13425 .TP
13426 .FN /bin/bash
13427 The \fBbash\fP executable
13428 .TP
13429 .FN /etc/profile
13430 The systemwide initialization file, executed for login shells
13431 .TP
13432 .FN /etc/bash.bashrc
13433 The systemwide per-interactive-shell startup file
13434 .TP
13435 .FN /etc/bash.bash.logout
13436 The systemwide login shell cleanup file, executed when a login shell exits
13437 .TP
13438 .FN \*~/.bash_profile
13439 The personal initialization file, executed for login shells
13440 .TP
13441 .FN \*~/.bashrc
13442 The individual per-interactive-shell startup file
13443 .TP
13444 .FN \*~/.bash_logout
13445 The individual login shell cleanup file, executed when a login shell exits
13446 .TP
13447 .FN \*~/.bash_history
13448 The default value of \fBHISTFILE\fP, the file in which bash saves the
13449 command history
13450 .TP
13451 .FN \*~/.inputrc
13452 Individual \fIreadline\fP initialization file
13453 .PD
13454 .SH AUTHORS
13455 Brian Fox, Free Software Foundation
13456 .br
13457 [email protected]
13458 .PP
13459 Chet Ramey, Case Western Reserve University
13460 .br
13461 [email protected]
13462 .SH BUG REPORTS
13463 If you find a bug in
13464 .BR bash ,
13465 you should report it. But first, you should
13466 make sure that it really is a bug, and that it appears in the latest
13467 version of
13468 .BR bash .
13469 The latest version is always available from
13470 \fIftp://ftp.gnu.org/pub/gnu/bash/\fP and
13471 \fIhttp://git.savannah.gnu.org/cgit/bash.git/snapshot/bash-master.tar.gz\fP.
13472 .PP
13473 Once you have determined that a bug actually exists, use the
13474 .I bashbug
13475 command to submit a bug report.
13476 If you have a fix, you are encouraged to mail that as well!
13477 You may send suggestions and
13478 .Q philosophical
13479 bug reports to \[email protected]\fP or post them to the Usenet
13480 newsgroup
13481 .BR gnu.bash.bug .
13482 .PP
13483 ALL bug reports should include:
13484 .PP
13485 .PD 0
13486 .TP 20
13487 The version number of \fBbash\fP
13488 .TP
13489 The hardware and operating system
13490 .TP
13491 The compiler used to compile
13492 .TP
13493 A description of the bug behavior
13494 .TP
13495 A short script or \c
13496 .Q recipe " \c"
13497 which exercises the bug
13498 .PD
13499 .PP
13500 .I bashbug
13501 inserts the first three items automatically into the template
13502 it provides for filing a bug report.
13503 .PP
13504 Comments and bug reports concerning
13505 this manual page should be directed to
13506 .IR [email protected] .
13507 .SH BUGS
13508 It's too big and too slow.
13509 .PP
13510 There are some subtle differences between
13511 .B bash
13512 and traditional versions of
13513 .BR sh ,
13514 mostly because of the
13515 .SM POSIX
13516 specification.
13517 .PP
13518 Aliases are confusing in some uses.
13519 .PP
13520 Shell builtin commands and functions are not stoppable/restartable.
13521 .PP
13522 Compound commands and command lists of the form
13523 .Q "a ; b ; c"
13524 are not handled gracefully when combined with process suspension.
13525 When a process is stopped, the shell immediately executes the next
13526 command in the list or breaks out of any existing loops.
13527 It suffices to enclose the command in parentheses to
13528 force it into a subshell, which may be stopped as a unit,
13529 or to start the command in the background and immediately
13530 bring it into the foreground.
13531 .PP
13532 Array variables may not (yet) be exported.
13533 .zZ
13534 .zY