Debian Codegraph @

upstream/opensuse-tumbleweed/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 standard personal initialization file
236 .FN \*~/.bashrc
237 if the shell is interactive (see
238 .SM
239 .B INVOCATION
240 below).
241 .TP
242 .B \-\-login
243 Equivalent to \fB\-l\fP.
244 .TP
245 .B \-\-noediting
246 Do not use the GNU
247 .B readline
248 library to read command lines when the shell is interactive.
249 .TP
250 .B \-\-noprofile
251 Do not read either the system-wide startup file
252 .FN /etc/profile
253 or any of the personal initialization files
254 .FN \*~/.bash_profile ,
255 .FN \*~/.bash_login ,
256 or
257 .FN \*~/.profile .
258 By default,
259 .B bash
260 reads these files when it is invoked as a login shell (see
261 .SM
262 .B INVOCATION
263 below).
264 .TP
265 .B \-\-norc
266 Do not read and execute the personal initialization file
267 .FN \*~/.bashrc
268 if the shell is interactive.
269 This option is on by default if the shell is invoked as
270 .BR sh .
271 .TP
272 .B \-\-posix
273 Enable posix mode;
274 change the behavior of \fBbash\fP
275 where the default operation differs from the
276 .SM POSIX
277 standard to match the standard.
278 .TP
279 .B \-\-restricted
280 The shell becomes restricted (see
281 .SM
282 .B "RESTRICTED SHELL"
283 below).
284 .TP
285 .B \-\-verbose
286 Equivalent to \fB\-v\fP.
287 .TP
288 .B \-\-version
289 Show version information for this instance of
290 .B bash
291 on the standard output and exit successfully.
292 .SH ARGUMENTS
293 If arguments remain after option processing, and neither the
294 .B \-c
295 nor the
296 .B \-s
297 option has been supplied, the first argument is treated as
298 the name of a file containing shell commands (a \fIshell script\fP).
299 When
300 .B bash
301 is invoked in this fashion,
302 .B $0
303 is set to the name of the file, and the positional parameters
304 are set to the remaining arguments.
305 .B Bash
306 reads and executes commands from this file, then exits.
307 \fBBash\fP's exit status is the exit status of the last command
308 executed in the script.
309 If no commands are executed, the exit status is 0.
310 .B Bash
311 first attempts to open the file in the current directory,
312 and, if no file is found, searches the directories in
313 .SM
314 .B PATH
315 for the script.
316 .SH INVOCATION
317 A \fIlogin shell\fP is one whose first character of argument zero is a
318 .BR \- ,
319 or one started with the
320 .B \-\-login
321 option.
322 .PP
323 An \fIinteractive shell\fP is one started without non-option arguments
324 (unless \fB\-s\fP is specified)
325 and without the
326 .B \-c
327 option,
328 and whose standard input and standard error are
329 both connected to terminals (as determined by
330 .IR isatty (3)),
331 or one started with the
332 .B \-i
333 option.
334 .B Bash
335 sets
336 .SM
337 .B PS1
338 and
339 .B $\-
340 includes
341 .B i
342 if the shell is interactive,
343 so a shell script or a startup file can test this state.
344 .PP
345 The following paragraphs describe how
346 .B bash
347 executes its startup files.
348 If any of the files exist but cannot be read,
349 .B bash
350 reports an error.
351 Tildes are expanded in filenames as described below under
352 .B "Tilde Expansion"
353 in the
354 .SM
355 .B EXPANSION
356 section.
357 .PP
358 When
359 .B bash
360 is invoked as an interactive login shell, or as a non-interactive shell
361 with the \fB\-\-login\fP option, it first reads and
362 executes commands from the file
363 .FN /etc/profile ,
364 if that file exists.
365 After reading that file, it looks for
366 .FN \*~/.bash_profile ,
367 .FN \*~/.bash_login ,
368 and
369 .FN \*~/.profile ,
370 in that order, and reads
371 and executes commands from the first one that exists and is readable.
372 The
373 .B \-\-noprofile
374 option may be used when the shell is started to inhibit this behavior.
375 Please note that the file \fI/etc/profile\fP includes an autodetection shell
376 code wether it has to source \fI/etc/bash.bashrc\fP as well as \fI~/.bashrc\fP.
377 .PP
378 When an interactive login shell exits,
379 or a non-interactive login shell executes the \fBexit\fP builtin command,
380 .B bash
381 reads and executes commands from the file
382 .FN \*~/.bash_logout ,
383 if it exists.
384 .PP
385 When an interactive shell that is not a login shell is started,
386 .B bash
387 reads and executes commands from
388 .FN /etc/bash.bashrc
389 then
390 .FN \*~/.bashrc
391 when those files exist and are readable.
392 The
393 .B \-\-norc
394 option inhibits this behavior.
395 The \fB\-\-rcfile\fP \fIfile\fP option causes
396 .B bash
397 to use \fIfile\fP instead of
398 .FN \*~/.bashrc .
399 Please note that the file
400 .FN /etc/bash.bashrc
401 includes an autodetection shell
402 code wether it is used for by a remote OpenSSH SSH client like
403 .BR ssh (1)
404 or
405 .BR slogin (1)
406 to source the local
407 .FN /etc/profile
408 if not already done.
409 .PP
410 When
411 .B bash
412 is started non-interactively, to run a shell script, for example, it
413 looks for the variable
414 .SM
415 .B BASH_ENV
416 in the environment, expands its value if it appears there, and uses the
417 expanded value as the name of a file to read and execute.
418 .B Bash
419 behaves as if the following command were executed:
420 .PP
421 .RS
422 .EX
423 if [ \-n \*"$BASH_ENV\*" ]; then . \*"$BASH_ENV\*"; fi
424 .EE
425 .RE
426 .PP
427 but does not use the value of the
428 .SM
429 .B PATH
430 variable to search for the filename.
431 .PP
432 If
433 .B bash
434 is invoked with the name
435 .BR sh ,
436 it tries to mimic the startup behavior of historical versions of
437 .B sh
438 as closely as possible,
439 while conforming to the
440 .SM POSIX
441 standard as well.
442 When invoked as an interactive login shell, or a non-interactive
443 shell with the \fB\-\-login\fP option, it first attempts to read
444 and execute commands from
445 .FN /etc/profile
446 and
447 .FN \*~/.profile ,
448 in that order.
449 The
450 .B \-\-noprofile
451 option inhibits this behavior.
452 When invoked as an interactive shell with the name
453 .BR sh ,
454 .B bash
455 looks for the variable
456 .SM
457 .BR ENV ,
458 expands its value if it is defined, and uses the
459 expanded value as the name of a file to read and execute.
460 Since a shell invoked as
461 .B sh
462 does not attempt to read and execute commands from any other startup
463 files, the
464 .B \-\-rcfile
465 option has no effect.
466 A non-interactive shell invoked with the name
467 .B sh
468 does not attempt to read any other startup files.
469 .PP
470 When invoked as
471 .BR sh ,
472 .B bash
473 enters posix mode after reading the startup files.
474 .PP
475 When
476 .B bash
477 is started in posix mode, as with the
478 .B \-\-posix
479 command line option, it follows the
480 .SM POSIX
481 standard for startup files.
482 In this mode, interactive shells expand the
483 .SM
484 .B ENV
485 variable and read and execute commands from the file
486 whose name is the expanded value.
487 No other startup files are read.
488 .PP
489 .B Bash
490 attempts to determine when it is being run with its standard input
491 connected to a network connection, as when executed by
492 the historical and rarely-seen remote shell daemon, usually \fIrshd\fP,
493 or the secure shell daemon \fIsshd\fP.
494 If
495 .B bash
496 determines it is being run non-interactively in this fashion,
497 it reads and executes commands from
498 .FN /etc/bash.bashrc
499 then
500 .FN \*~/.bashrc ,
501 when those file exists and is readable.
502 .B Bash
503 does not read this file if invoked as \fBsh\fP.
504 The
505 .B \-\-norc
506 option inhibits this behavior, and the
507 .B \-\-rcfile
508 option makes \fBbash\fP use a different file instead of
509 .FN \*~/.bashrc ,
510 but neither
511 \fIrshd\fP nor \fIsshd\fP generally invoke the shell with those options
512 or allow them to be specified.
513 .PP
514 If the shell is started with the effective user (group) id not equal to the
515 real user (group) id, and the \fB\-p\fP option is not supplied, no startup
516 files are read, shell functions are not inherited from the environment, the
517 .SM
518 .BR SHELLOPTS ,
519 .SM
520 .BR BASHOPTS ,
521 .SM
522 .BR CDPATH ,
523 and
524 .SM
525 .B GLOBIGNORE
526 variables, if they appear in the environment, are ignored,
527 and the effective user id is set to the real user id.
528 If the \fB\-p\fP option is supplied at invocation, the startup behavior is
529 the same, but the effective user id is not reset.
530 .SH DEFINITIONS
531 The following definitions are used throughout the rest of this
532 document.
533 .PD 0
534 .TP
535 .B blank
536 A space or tab.
537 .TP
538 .B whitespace
539 A character belonging to the \fBspace\fP character class in the
540 current locale, or for which \fIisspace\fP(3) returns true.
541 .TP
542 .B word
543 A sequence of characters considered as a single unit by the shell.
544 Also known as a
545 .BR token .
546 .TP
547 .B name
548 A
549 .I word
550 consisting only of alphanumeric characters and underscores, and
551 beginning with an alphabetic character or an underscore. Also
552 referred to as an
553 .BR identifier .
554 .TP
555 .B metacharacter
556 A character that, when unquoted, separates words.
557 One of the following:
558 .br
559 .RS
560 .PP
561 .if t \fB| & ; ( ) < > space tab newline\fP
562 .if n \fB| & ; ( ) < > space tab newline\fP
563 .RE
564 .TP
565 .B "control operator"
566 A \fItoken\fP that performs a control function.
567 It is one of the following symbols:
568 .RS
569 .PP
570 .if t \fB|| & && ; ;; ;& ;;& ( ) | |& <newline>\fP
571 .if n \fB|| & && ; ;; ;& ;;& ( ) | |& <newline>\fP
572 .RE
573 .PD
574 .SH "RESERVED WORDS"
575 \fIReserved words\fP are words that have a special meaning to the shell.
576 The following words are recognized as reserved when unquoted and either
577 the first word of a command (see
578 .SM
579 .B "SHELL GRAMMAR"
580 below), the third word of a
581 .B case
582 or
583 .B select
584 command
585 (only \fBin\fP is valid), or the third word of a
586 .B for
587 command (only \fBin\fP and \fBdo\fP are valid):
588 .if t .RS
589 .PP
590 .B
591 .if n ! case coproc do done elif else esac fi for function if in select \
592 then until while { } time [[ ]]
593 .if t ! case coproc do done elif else esac fi for function if in select then until while { } time [[ ]]
594 .if t .RE
595 .SH "SHELL GRAMMAR"
596 This section describes the syntax of the various forms of shell commands.
597 .SS Simple Commands
598 A \fIsimple command\fP is a sequence of optional variable assignments
599 followed by \fBblank\fP-separated words and redirections, and
600 terminated by a \fIcontrol operator\fP.
601 The first word
602 specifies the command to be executed, and is passed as argument zero.
603 The remaining words are passed as arguments to the invoked command.
604 .PP
605 The return value of a \fIsimple command\fP is its exit status, or
606 128+\fIn\^\fP if the command is terminated by signal
607 .IR n .
608 .SS Pipelines
609 A \fIpipeline\fP is a sequence of one or more commands separated by
610 one of the control operators
611 .B |
612 or \fB|&\fP.
613 The format for a pipeline is:
614 .RS
615 .PP
616 [\fBtime\fP [\fB\-p\fP]] [ ! ] \fIcommand1\fP [ [\fB|\fP\(bv\fB|&\fP] \fIcommand2\fP .\|.\|.\& ]
617 .RE
618 .PP
619 The standard output of
620 .I command1
621 is connected via a pipe to the standard input of
622 .IR command2 .
623 This connection is performed before any redirections specified by the
624 .IR command1 (see
625 .SM
626 .B REDIRECTION
627 below).
628 If \fB|&\fP is the pipeline operator,
629 \fIcommand1\fP's standard error, in addition to its
630 standard output, is connected to
631 \fIcommand2\fP's standard input through the pipe;
632 it is shorthand for \fB2>&1 |\fP.
633 This implicit redirection of the standard error to the standard output is
634 performed after any redirections specified by \fIcommand1\fP.
635 .PP
636 The return status of a pipeline is the exit status of the last
637 command, unless the \fBpipefail\fP option is enabled.
638 If \fBpipefail\fP is enabled, the pipeline's return status is the
639 value of the last (rightmost) command to exit with a non-zero status,
640 or zero if all commands exit successfully.
641 If the reserved word
642 .B !
643 precedes a pipeline, the exit status of that pipeline is the logical
644 negation of the exit status as described above.
645 If a pipeline is executed synchronously,
646 the shell waits for all commands in the pipeline to
647 terminate before returning a value.
648 .PP
649 If the
650 .B time
651 reserved word precedes a pipeline, the shell reports the
652 elapsed as well as user and system time consumed by its execution
653 when the pipeline terminates.
654 The \fB\-p\fP option changes the output format to that specified by
655 .SM POSIX\c
656 \&.
657 When the shell is in posix mode, it does not recognize
658 \fBtime\fP as a reserved word if the next token begins with a
659 .Q \- .
660 The value of the
661 .SM
662 .B TIMEFORMAT
663 variable is a format string that specifies how the timing
664 information should be displayed; see the description of
665 .SM
666 .B TIMEFORMAT
667 below under
668 .BR "Shell Variables" .
669 .PP
670 When the shell is in posix mode, \fBtime\fP
671 may appear by itself as the only word in a simple command.
672 In this case, the shell displays the
673 total user and system time consumed by the shell and its children.
674 The
675 .SM
676 .B TIMEFORMAT
677 variable specifies the format of the time information.
678 .PP
679 Each command in a multi-command pipeline,
680 where pipes are created,
681 is executed in a \fIsubshell\fP, which is a
682 separate process.
683 See
684 .SM
685 .B "COMMAND EXECUTION ENVIRONMENT"
686 for a description of subshells and a subshell environment.
687 If the \fBlastpipe\fP option is enabled using the \fBshopt\fP builtin
688 (see the description of \fBshopt\fP below),
689 and job control is not active,
690 the last element of a pipeline may be run by the shell process.
691 .SS Lists
692 A \fIlist\fP is a sequence of one or more pipelines separated by one
693 of the operators
694 .BR ; ,
695 .BR & ,
696 .BR && ,
697 or
698 .BR || ,
699 and optionally terminated by one of
700 .BR ; ,
701 .BR & ,
702 or
703 .BR <newline> .
704 .PP
705 Of these list operators,
706 .B &&
707 and
708 .B ||
709 have equal precedence, followed by
710 .B ;
711 and
712 .BR & ,
713 which have equal precedence.
714 .PP
715 A sequence of one or more newlines may appear in a \fIlist\fP instead
716 of a semicolon to delimit commands.
717 .PP
718 If a command is terminated by the control operator
719 .BR & ,
720 the shell executes the command in the \fIbackground\fP
721 in a subshell.
722 The shell does not wait for the command to
723 finish, and the return status is 0.
724 These are referred to as \fIasynchronous\fP commands.
725 Commands separated by a
726 .B ;
727 are executed sequentially; the shell waits for each
728 command to terminate in turn.
729 The return status is the exit status of the last command executed.
730 .PP
731 AND and OR lists are sequences of one or more pipelines separated by the
732 \fB&&\fP and \fB||\fP control operators, respectively.
733 AND and OR lists are executed with left associativity.
734 An AND list has the form
735 .RS
736 .PP
737 \fIcommand1\fP \fB&&\fP \fIcommand2\fP
738 .RE
739 .PP
740 .I command2
741 is executed if, and only if,
742 .I command1
743 returns an exit status of zero (success).
744 .PP
745 An OR list has the form
746 .RS
747 .PP
748 \fIcommand1\fP \fB||\fP \fIcommand2\fP
749 .RE
750 .PP
751 .I command2
752 is executed if, and only if,
753 .I command1
754 returns a non-zero exit status.
755 The return status of
756 AND and OR lists is the exit status of the last command
757 executed in the list.
758 .SS Compound Commands
759 A \fIcompound command\fP is one of the following.
760 In most cases a \fIlist\fP in a command's description may be separated from
761 the rest of the command by one or more newlines, and may be followed by a
762 newline in place of a semicolon.
763 .TP
764 (\fIlist\fP)
765 \fIlist\fP is executed in a subshell (see
766 .SM
767 .B "COMMAND EXECUTION ENVIRONMENT"
768 below for a description of a subshell environment).
769 Variable assignments and builtin
770 commands that affect the shell's environment do not remain in effect
771 after the command completes.
772 The return status is the exit status of \fIlist\fP.
773 .TP
774 { \fIlist\fP; }
775 \fIlist\fP is executed in the current shell environment.
776 \fIlist\fP must be terminated with a newline or semicolon.
777 This is known as a \fIgroup command\fP.
778 The return status is the exit status of \fIlist\fP.
779 .IP
780 Note that unlike the metacharacters \fB(\fP and \fB)\fP, \fB{\fP and
781 \fB}\fP are \fIreserved words\fP and must occur where a reserved
782 word is permitted to be recognized.
783 Since they do not cause a word break, they must be separated from
784 \fIlist\fP by whitespace or another shell metacharacter.
785 .TP
786 ((\fIexpression\fP))
787 The arithmetic \fIexpression\fP is evaluated according to the rules
788 described below under
789 .SM
790 .BR "ARITHMETIC EVALUATION" .
791 If the value of the expression is non-zero, the return status is 0;
792 otherwise the return status is 1.
793 The \fIexpression\fP
794 undergoes the same expansions
795 as if it were within double quotes,
796 but unescaped double quote characters
797 in \fIexpression\fP are not treated
798 specially and are removed.
799 Since this can potentially result in empty strings, this command treats
800 those as expressions that evaluate to 0.
801 .TP
802 \fB[[\fP \fIexpression\fP \fB]]\fP
803 .PD
804 Evaluate the conditional expression \fIexpression\fP
805 and return a status of zero (true) or non-zero (false).
806 Expressions are composed of the primaries described below under
807 .SM
808 .BR "CONDITIONAL EXPRESSIONS" .
809 The words between the \fB[[\fP and \fB]]\fP do not undergo word splitting
810 and pathname expansion.
811 The shell performs tilde expansion, parameter and
812 variable expansion, arithmetic expansion, command substitution, process
813 substitution, and quote removal on those words.
814 Conditional operators such as \fB\-f\fP must be unquoted to be recognized
815 as primaries.
816 .IP
817 When used with \fB[[\fP, the \fB<\fP and \fB>\fP operators sort
818 lexicographically using the current locale.
819 .IP
820 When the \fB==\fP and \fB!=\fP operators are used, the string to the
821 right of the operator is considered a pattern and matched according
822 to the rules described below under \fBPattern Matching\fP,
823 as if the \fBextglob\fP shell option were enabled.
824 The \fB=\fP operator is equivalent to \fB==\fP.
825 If the
826 .B nocasematch
827 shell option is enabled, the match is performed without regard to the case
828 of alphabetic characters.
829 The return value is 0 if the string matches (\fB==\fP) or does not match
830 (\fB!=\fP) the pattern, and 1 otherwise.
831 If any part of the pattern is quoted, the quoted portion is matched
832 as a string: every character in the quoted portion matches itself,
833 instead of having any special pattern matching meaning.
834 .IP
835 An additional binary operator, \fB=\*~\fP, is available, with the same
836 precedence as \fB==\fP and \fB!=\fP.
837 When it is used, the string to the right of the operator is considered
838 a
839 .SM POSIX
840 extended regular expression and matched accordingly
841 (using the
842 .SM POSIX
843 \fIregcomp\fP and \fIregexec\fP interfaces
844 usually described in
845 .IR regex (3)).
846 The return value is 0 if the string matches
847 the pattern, and 1 otherwise.
848 If the regular expression is syntactically incorrect, the conditional
849 expression's return value is 2.
850 If the
851 .B nocasematch
852 shell option is enabled, the match is performed without regard to the case
853 of alphabetic characters.
854 .IP
855 If any part of the pattern is quoted, the quoted portion is matched literally,
856 as above.
857 If the pattern is stored in a shell variable, quoting the variable
858 expansion forces the entire pattern to be matched literally.
859 Treat bracket expressions in regular expressions carefully,
860 since normal quoting and pattern characters lose their meanings
861 between brackets.
862 .IP
863 The match succeeds if the pattern matches any part of the string.
864 Anchor the pattern using the \fB\*^\fP and \fB$\fP regular expression
865 operators to force it to match the entire string.
866 .IP
867 The array variable
868 .SM
869 .B BASH_REMATCH
870 records which parts of the string matched the pattern.
871 The element of
872 .SM
873 .B BASH_REMATCH
874 with index 0 contains the portion of
875 the string matching the entire regular expression.
876 Substrings matched by parenthesized subexpressions within the regular
877 expression are saved in the remaining
878 .SM
879 .B BASH_REMATCH
880 indices.
881 The element of
882 .SM
883 .B BASH_REMATCH
884 with index \fIn\fP is the portion of the
885 string matching the \fIn\fPth parenthesized subexpression.
886 \fBBash\fP sets
887 .SM
888 .B BASH_REMATCH
889 in the global scope; declaring it as a local variable will lead to
890 unexpected results.
891 .IP
892 Expressions may be combined using the following operators, listed
893 in decreasing order of precedence:
894 .IP
895 .RS
896 .PD 0
897 .TP
898 .B ( \fIexpression\fP )
899 Returns the value of \fIexpression\fP.
900 This may be used to override the normal precedence of operators.
901 .TP
902 .B ! \fIexpression\fP
903 True if
904 .I expression
905 is false.
906 .TP
907 \fIexpression1\fP \fB&&\fP \fIexpression2\fP
908 True if both
909 .I expression1
910 and
911 .I expression2
912 are true.
913 .TP
914 \fIexpression1\fP \fB||\fP \fIexpression2\fP
915 True if either
916 .I expression1
917 or
918 .I expression2
919 is true.
920 .PD
921 .LP
922 The \fB&&\fP and \fB||\fP
923 operators do not evaluate \fIexpression2\fP if the value of
924 \fIexpression1\fP is sufficient to determine the return value of
925 the entire conditional expression.
926 .RE
927 .TP
928 \fBfor\fP \fIname\fP [ [ \fBin\fP \fIword .\|.\|.\&\fP ] ; ] \fBdo\fP \fIlist\fP ; \fBdone\fP
929 First, expand The list of words following \fBin\fP, generating a list
930 of items.
931 Then, the variable \fIname\fP is set to each element of this list
932 in turn, and \fIlist\fP is executed each time.
933 If the \fBin\fP \fIword\fP is omitted, the \fBfor\fP command executes
934 \fIlist\fP once for each positional parameter that is set (see
935 .SM
936 .B PARAMETERS
937 below).
938 The return status is the exit status of the last command that executes.
939 If the expansion of the items following \fBin\fP results in an empty
940 list, no commands are executed, and the return status is 0.
941 .TP
942 \fBfor\fP (( \fIexpr1\fP ; \fIexpr2\fP ; \fIexpr3\fP )) [;] \fBdo\fP \fIlist\fP ; \fBdone\fP
943 First, evaluate the arithmetic expression \fIexpr1\fP according
944 to the rules described below under
945 .SM
946 .BR "ARITHMETIC EVALUATION" .
947 Then, repeatedly evaluate the arithmetic expression \fIexpr2\fP
948 until it evaluates to zero.
949 Each time \fIexpr2\fP evaluates to a non-zero value,
950 execute \fIlist\fP
951 and evaluate the arithmetic expression \fIexpr3\fP.
952 If any expression is omitted, it behaves as if it evaluates to 1.
953 The return value is the exit status of the last command in \fIlist\fP
954 that is executed, or non-zero if any of the expressions is invalid.
955 .IP
956 Use the \fBbreak\fP and \fPcontinue\fP builtins
957 (see
958 .SM
959 .B "SHELL BUILTIN COMMANDS"
960 below)
961 to control loop execution.
962 .TP
963 \fBselect\fP \fIname\fP [ \fBin\fP \fIword\fP ] ; \fBdo\fP \fIlist\fP ; \fBdone\fP
964 First, expand the list of words following \fBin\fP,
965 generating a list of items, and print the set of expanded words
966 the standard error, each preceded by a number.
967 If the \fBin\fP
968 \fIword\fP is omitted, print the positional parameters (see
969 .SM
970 .B PARAMETERS
971 below).
972 .B select
973 then displays the
974 .SM
975 .B PS3
976 prompt and reads a line from the standard input.
977 If the line consists of a number corresponding to one of
978 the displayed words, then \fBselect\fP sets the value of
979 .I name
980 to that word.
981 If the line is empty, \fBselect\fP displays the words and prompt again.
982 If EOF is read, \fBselect\fP completes and returns 1.
983 Any other value sets
984 .I name
985 to null.
986 The line read is saved in the variable
987 .SM
988 .BR REPLY .
989 The
990 .I list
991 is executed after each selection until a
992 .B break
993 command is executed.
994 The exit status of
995 .B select
996 is the exit status of the last command executed in
997 .IR list ,
998 or zero if no commands were executed.
999 .TP
1000 \fBcase\fP \fIword\fP \fBin\fP [ [(] \fIpattern\fP [ \fB|\fP \fIpattern\fP ] \
1001 .\|.\|.\& ) \fIlist\fP ;; ] .\|.\|.\& \
1002 \fBesac\fP
1003 A \fBcase\fP command first expands \fIword\fP, and tries to match
1004 it against each \fIpattern\fP in turn,
1005 proceeding from first to last,
1006 using the matching rules
1007 described under
1008 .B "Pattern Matching"
1009 below.
1010 A pattern list is a set of one or more patterns separated by \|,
1011 and the ) operator terminates the pattern list.
1012 The \fIword\fP is expanded using tilde
1013 expansion, parameter and variable expansion, arithmetic expansion,
1014 command substitution, process substitution and quote removal.
1015 Each \fIpattern\fP examined is expanded using tilde
1016 expansion, parameter and variable expansion, arithmetic expansion,
1017 command substitution, process substitution, and quote removal.
1018 If the
1019 .B nocasematch
1020 shell option is enabled, the match is performed without regard to the case
1021 of alphabetic characters.
1022 A \fIclause\fP is a pattern list and an associated \fIlist\fP.
1023 .IP
1024 When a match is found, \fBcase\fP executes the corresponding \fIlist\fP.
1025 If the \fB;;\fP operator terminates the case clause, the \fBcase\fP
1026 command completes after the first match.
1027 Using \fB;&\fP in place of \fB;;\fP causes execution to continue with
1028 the \fIlist\fP associated with the next pattern list.
1029 Using \fB;;&\fP in place of \fB;;\fP causes the shell to test the next
1030 pattern list in the statement, if any, and execute any associated \fIlist\fP
1031 if the match succeeds,
1032 continuing the case statement execution as if the pattern list had not matched.
1033 The exit status is zero if no pattern matches.
1034 .IP
1035 Otherwise, it is the exit status of the
1036 last command executed in the last \fIlist\fP executed.
1037 .TP
1038 \fBif\fP \fIlist\fP; \fBthen\fP \fIlist\fP; \
1039 [ \fBelif\fP \fIlist\fP; \fBthen\fP \fIlist\fP; ] .\|.\|.\& \
1040 [ \fBelse\fP \fIlist\fP; ] \fBfi\fP
1041 The
1042 .B if
1043 .I list
1044 is executed.
1045 If its exit status is zero, the
1046 \fBthen\fP \fIlist\fP is executed.
1047 Otherwise, each \fBelif\fP \fIlist\fP is executed in turn,
1048 and if its exit status is zero, the corresponding \fBthen\fP \fIlist\fP
1049 is executed and the command completes.
1050 Otherwise, the \fBelse\fP \fIlist\fP is executed, if present.
1051 The exit status is the exit status of the
1052 last command executed, or zero if no condition tested true.
1053 .TP
1054 \fBwhile\fP \fIlist-1\fP; \fBdo\fP \fIlist-2\fP; \fBdone\fP
1055 .PD 0
1056 .TP
1057 \fBuntil\fP \fIlist-1\fP; \fBdo\fP \fIlist-2\fP; \fBdone\fP
1058 .PD
1059 The \fBwhile\fP command continuously executes the list
1060 \fIlist-2\fP as long as the last command in the list \fIlist-1\fP returns
1061 an exit status of zero.
1062 The \fBuntil\fP command is identical
1063 to the \fBwhile\fP command, except that the test is negated:
1064 .I list-2
1065 is executed as long as the last command in
1066 .I list-1
1067 returns a non-zero exit status.
1068 The exit status of the \fBwhile\fP and \fBuntil\fP commands
1069 is the exit status
1070 of the last command executed in \fIlist-2\fP, or zero if
1071 none was executed.
1072 .SS Coprocesses
1073 A \fIcoprocess\fP is a shell command preceded by the \fBcoproc\fP reserved
1074 word.
1075 A coprocess is executed asynchronously in a subshell, as if the command
1076 had been terminated with the \fB&\fP control operator, with a two-way pipe
1077 established between the executing shell and the coprocess.
1078 .PP
1079 The syntax for a coprocess is:
1080 .RS
1081 .PP
1082 \fBcoproc\fP [\fINAME\fP] \fIcommand\fP [\fIredirections\fP]
1083 .RE
1084 .PP
1085 This creates a coprocess named \fINAME\fP.
1086 \fIcommand\fP may be either a simple command or a compound
1087 command (see above).
1088 \fINAME\fP is a shell variable name.
1089 If \fINAME\fP is not supplied, the default name is \fBCOPROC\fP.
1090 .PP
1091 The recommended form to use for a coprocess is
1092 .RS
1093 .PP
1094 \fBcoproc\fP \fINAME\fP { \fIcommand\fP [\fIredirections\fP]; }
1095 .RE
1096 .PP
1097 This form is preferred because simple commands result in the coprocess
1098 always being named \fBCOPROC\fP, and it is simpler to use and more complete
1099 than the other compound commands.
1100 .PP
1101 If \fIcommand\fP is a compound command, \fINAME\fP is optional. The
1102 word following \fBcoproc\fP determines whether that word is interpreted
1103 as a variable name: it is interpreted as \fINAME\fP if it is not a
1104 reserved word that introduces a compound command.
1105 If \fIcommand\fP is a simple command, \fINAME\fP is not allowed; this
1106 is to avoid confusion between \fINAME\fP and the first word of the simple
1107 command.
1108 .PP
1109 When the coprocess is executed, the shell creates an array variable (see
1110 .B Arrays
1111 below) named \fINAME\fP in the context of the executing shell.
1112 The standard output of
1113 .I command
1114 is connected via a pipe to a file descriptor in the executing shell,
1115 and that file descriptor is assigned to \fINAME\fP[0].
1116 The standard input of
1117 .I command
1118 is connected via a pipe to a file descriptor in the executing shell,
1119 and that file descriptor is assigned to \fINAME\fP[1].
1120 This pipe is established before any redirections specified by the
1121 command (see
1122 .SM
1123 .B REDIRECTION
1124 below).
1125 The file descriptors can be utilized as arguments to shell commands
1126 and redirections using standard word expansions.
1127 Other than those created to execute command and process substitutions,
1128 the file descriptors are not available in subshells.
1129 .PP
1130 The process ID of the shell spawned to execute the coprocess is
1131 available as the value of the variable \fINAME\fP_PID.
1132 The \fBwait\fP
1133 builtin may be used to wait for the coprocess to terminate.
1134 .PP
1135 Since the coprocess is created as an asynchronous command,
1136 the \fBcoproc\fP command always returns success.
1137 The return status of a coprocess is the exit status of \fIcommand\fP.
1138 .SS Shell Function Definitions
1139 A shell function is an object that is called like a simple command and
1140 executes a compound command with a new set of positional parameters.
1141 Shell functions are declared as follows:
1142 .TP
1143 \fIfname\fP () \fIcompound\-command\fP [\fIredirection\fP]
1144 .PD 0
1145 .TP
1146 \fBfunction\fP \fIfname\fP [()] \fIcompound\-command\fP [\fIredirection\fP]
1147 .PD
1148 This defines a function named \fIfname\fP.
1149 The reserved word \fBfunction\fP is optional.
1150 If the \fBfunction\fP reserved word is supplied, the parentheses are optional.
1151 The \fIbody\fP of the function is the compound command
1152 .I compound\-command
1153 (see \fBCompound Commands\fP above).
1154 That command is usually a \fIlist\fP of commands between { and }, but
1155 may be any command listed under \fBCompound Commands\fP above.
1156 If the \fBfunction\fP reserved word is used, but the
1157 parentheses are not supplied, the braces are recommended.
1158 \fIcompound\-command\fP is executed whenever \fIfname\fP is specified as the
1159 name of a simple command.
1160 When in posix mode, \fIfname\fP must be a valid shell \fIname\fP
1161 and may not be the name of one of the
1162 .SM POSIX
1163 \fIspecial builtins\fP.
1164 In default mode, a function name can be any unquoted shell word that does
1165 not contain \fB$\fP.
1166 .PP
1167 Any redirections (see
1168 .SM
1169 .B REDIRECTION
1170 below) specified when a function is defined are performed
1171 when the function is executed.
1172 .PP
1173 The exit status of a function definition is zero unless a syntax error
1174 occurs or a readonly function with the same name already exists.
1175 When executed, the exit status of a function is the exit status of the
1176 last command executed in the body. (See
1177 .SM
1178 .B FUNCTIONS
1179 below.)
1180 .SH COMMENTS
1181 In a non-interactive shell, or an interactive shell in which the
1182 .B interactive_comments
1183 option to the
1184 .B shopt
1185 builtin is enabled (see
1186 .SM
1187 .B "SHELL BUILTIN COMMANDS"
1188 below), a word beginning with
1189 .B #
1190 introduces a comment.
1191 A word begins at the beginning of a line, after unquoted whitespace, or
1192 after an operator.
1193 The comment causes that word and all remaining characters on that line to
1194 be ignored.
1195 An interactive shell without the
1196 .B interactive_comments
1197 option enabled does not allow comments.
1198 The
1199 .B interactive_comments
1200 option is enabled by default in interactive shells.
1201 .SH QUOTING
1202 \fIQuoting\fP is used to remove the special meaning of certain
1203 characters or words to the shell.
1204 Quoting can be used to
1205 disable special treatment for special characters, to prevent
1206 reserved words from being recognized as such, and to prevent
1207 parameter expansion.
1208 .PP
1209 Each of the \fImetacharacters\fP listed above under
1210 .SM
1211 .B DEFINITIONS
1212 has special meaning to the shell and must be quoted if it is to
1213 represent itself.
1214 .PP
1215 When the command history expansion facilities are being used
1216 (see
1217 .SM
1218 .B "HISTORY EXPANSION"
1219 below), the
1220 \fIhistory expansion\fP character, usually \fB!\fP, must be quoted
1221 to prevent history expansion.
1222 .PP
1223 There are four quoting mechanisms: the
1224 .IR "escape character" ,
1225 single quotes, double quotes,
1226 and dollar-single quotes.
1227 .PP
1228 A non-quoted backslash (\fB\e\fP) is the
1229 .IR "escape character" .
1230 It preserves the literal value of the next character that follows,
1231 removing any special meaning it has,
1232 with the exception of <newline>.
1233 If a \fB\e\fP<newline> pair appears, and the backslash is not itself quoted,
1234 the \fB\e\fP<newline> is treated as a line continuation (that is, it is
1235 removed from the input stream and effectively ignored).
1236 .PP
1237 Enclosing characters in single quotes preserves the literal value
1238 of each character within the quotes.
1239 A single quote may not occur
1240 between single quotes, even when preceded by a backslash.
1241 .PP
1242 Enclosing characters in double quotes preserves the literal value
1243 of all characters within the quotes, with the exception of
1244 .BR $ ,
1245 .BR \` ,
1246 .BR \e ,
1247 and, when history expansion is enabled,
1248 .BR ! .
1249 When the shell is in posix mode,
1250 the \fB!\fP has no special meaning
1251 within double quotes, even when history expansion is enabled.
1252 The characters
1253 .B $
1254 and
1255 .B \`
1256 retain their special meaning within double quotes.
1257 The backslash retains its special meaning only when followed by one of
1258 the following characters:
1259 .BR $ ,
1260 .BR \` ,
1261 \^\fB\*"\fP\^,
1262 .BR \e ,
1263 or
1264 .BR <newline> .
1265 Backslashes preceding characters without a
1266 special meaning are left unmodified.
1267 .PP
1268 A double quote may be quoted within double quotes by preceding it with
1269 a backslash.
1270 If enabled, history expansion will be performed unless an
1271 .B !
1272 appearing in double quotes is escaped using a backslash.
1273 The backslash preceding the
1274 .B !
1275 is not removed.
1276 .PP
1277 The special parameters
1278 .B *
1279 and
1280 .B @
1281 have special meaning when in double quotes
1282 (see
1283 .SM
1284 .B PARAMETERS
1285 below).
1286 .PP
1287 Character sequences of the form \fB$\fP\*'\fIstring\fP\*' are treated
1288 as a special variant of single quotes.
1289 The sequence expands to \fIstring\fP, with backslash-escaped characters
1290 in \fIstring\fP replaced as specified by the ANSI C standard.
1291 Backslash escape sequences, if present, are decoded as follows:
1292 .RS
1293 .PD 0
1294 .TP
1295 .B \ea
1296 alert (bell)
1297 .TP
1298 .B \eb
1299 backspace
1300 .TP
1301 .B \ee
1302 .TP
1303 .B \eE
1304 an escape character
1305 .TP
1306 .B \ef
1307 form feed
1308 .TP
1309 .B \en
1310 new line
1311 .TP
1312 .B \er
1313 carriage return
1314 .TP
1315 .B \et
1316 horizontal tab
1317 .TP
1318 .B \ev
1319 vertical tab
1320 .TP
1321 .B \e\e
1322 backslash
1323 .TP
1324 .B \e\*'
1325 single quote
1326 .TP
1327 .B \e\*"
1328 double quote
1329 .TP
1330 .B \e?
1331 question mark
1332 .TP
1333 .B \e\fInnn\fP
1334 The eight-bit character whose value is the octal value \fInnn\fP
1335 (one to three octal digits).
1336 .TP
1337 .B \ex\fIHH\fP
1338 The eight-bit character whose value is the hexadecimal value \fIHH\fP
1339 (one or two hex digits).
1340 .TP
1341 .B \eu\fIHHHH\fP
1342 The Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
1343 \fIHHHH\fP (one to four hex digits).
1344 .TP
1345 .B \eU\fIHHHHHHHH\fP
1346 The Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
1347 \fIHHHHHHHH\fP (one to eight hex digits).
1348 .TP
1349 .B \ec\fIx\fP
1350 A control-\fIx\fP character.
1351 .PD
1352 .RE
1353 .LP
1354 The expanded result is single-quoted, as if the dollar sign had
1355 not been present.
1356 .SS "Translating Strings"
1357 A double-quoted string preceded by a dollar sign (\fB$\fP\*"\fIstring\fP\*")
1358 causes the string to be translated according to the current locale.
1359 The \fIgettext\fP infrastructure performs the lookup and
1360 translation, using the \fBLC_MESSAGES\fP, \fBTEXTDOMAINDIR\fP,
1361 and \fBTEXTDOMAIN\fP shell variables.
1362 If the current locale is \fBC\fP or \fBPOSIX\fP,
1363 if there are no translations available,
1364 or if the string is not translated, the dollar sign is ignored,
1365 and the string is treated as double-quoted as described above.
1366 This is a form of double quoting, so the string remains double-quoted
1367 by default, whether or not it is translated and replaced.
1368 If the \fBnoexpand_translation\fP option is enabled
1369 using the \fBshopt\fP builtin,
1370 translated strings are single-quoted instead of double-quoted.
1371 See the description of
1372 .B shopt
1373 below under
1374 .SM
1375 .BR "SHELL BUILTIN COMMANDS" .
1376 .SH PARAMETERS
1377 A
1378 .I parameter
1379 is an entity that stores values.
1380 It can be a
1381 .IR name ,
1382 a number, or one of the special characters listed below under
1383 .BR "Special Parameters" .
1384 A
1385 .I variable
1386 is a parameter denoted by a
1387 .IR name .
1388 A variable has a \fIvalue\fP and zero or more \fIattributes\fP.
1389 Attributes are assigned using the
1390 .B declare
1391 builtin command (see
1392 .B declare
1393 below in
1394 .SM
1395 .BR "SHELL BUILTIN COMMANDS" ).
1396 The \fBexport\fP and \fBreadonly\fP builtins assign specific attributes.
1397 .PP
1398 A parameter is set if it has been assigned a value.
1399 The null string is a valid value.
1400 Once a variable is set, it may be unset only by using the
1401 .B unset
1402 builtin command (see
1403 .SM
1404 .B "SHELL BUILTIN COMMANDS"
1405 below).
1406 .PP
1407 A
1408 .I variable
1409 is assigned to using a statement of the form
1410 .RS
1411 .PP
1412 \fIname\fP=[\fIvalue\fP]
1413 .RE
1414 .PP
1415 If
1416 .I value
1417 is not given, the variable is assigned the null string.
1418 All
1419 .I values
1420 undergo tilde expansion, parameter and variable expansion,
1421 command substitution, arithmetic expansion, and quote
1422 removal (see
1423 .SM
1424 .B EXPANSION
1425 below).
1426 If the variable has its
1427 .B integer
1428 attribute set, then
1429 .I value
1430 is evaluated as an arithmetic expression even if the
1431 .BR $(( .\|.\|.\& ))
1432 expansion is not used (see
1433 .B "Arithmetic Expansion"
1434 below).
1435 Word splitting and pathname expansion are not performed.
1436 Assignment statements may also appear as arguments to the
1437 .BR alias ,
1438 .BR declare ,
1439 .BR typeset ,
1440 .BR \%export ,
1441 .BR readonly ,
1442 and
1443 .B local
1444 builtin commands (\fIdeclaration\fP commands).
1445 When in posix mode, these builtins may appear in a command after
1446 one or more instances of the \fBcommand\fP builtin and retain these
1447 assignment statement properties.
1448 .PP
1449 In the context where an assignment statement is assigning a value
1450 to a shell variable or array index, the
1451 .Q +=
1452 operator appends to or adds to
1453 the variable's previous value.
1454 This includes arguments to \fIdeclaration\fP commands such as
1455 .B \%declare
1456 that accept assignment statements.
1457 When
1458 .Q +=
1459 is applied to a variable for which the
1460 .B \%integer
1461 attribute has been set,
1462 the variable's current value and \fIvalue\fP are each evaluated as
1463 arithmetic expressions,
1464 and the sum of the results is assigned as the variable's value.
1465 The current value is usually an integer constant, but may be an expression.
1466 When
1467 .Q +=
1468 is applied to an array variable using compound assignment
1469 (see
1470 .B Arrays
1471 below),
1472 the variable's value is not unset
1473 (as it is when using
1474 .Q = ),
1475 and new values are appended to the array
1476 beginning at one greater than the array's maximum index (for indexed arrays)
1477 or added as additional key\-value pairs in an associative array.
1478 When applied to a string-valued variable, \fIvalue\fP is expanded and
1479 appended to the variable's value.
1480 .PP
1481 A variable can be assigned the \fInameref\fP attribute using the
1482 \fB\-n\fP option to the \fBdeclare\fP or \fBlocal\fP builtin commands
1483 (see the descriptions of \fBdeclare\fP and \fBlocal\fP below)
1484 to create a \fInameref\fP, or a reference to another variable.
1485 This allows variables to be manipulated indirectly.
1486 Whenever the nameref variable is referenced, assigned to, unset, or has
1487 its attributes modified (other than using or changing the \fInameref\fP
1488 attribute itself), the
1489 operation is actually performed on the variable specified by the nameref
1490 variable's value.
1491 A nameref is commonly used within shell functions to refer to a variable
1492 whose name is passed as an argument to the function.
1493 For instance, if a variable name is passed to a shell function as its first
1494 argument, running
1495 .PP
1496 .RS
1497 .EX
1498 declare \-n ref=$1
1499 .EE
1500 .RE
1501 .PP
1502 inside the function creates a local nameref variable \fBref\fP whose value
1503 is the variable name passed as the first argument.
1504 References and assignments to \fBref\fP, and changes to its attributes,
1505 are treated as references, assignments, and attribute modifications
1506 to the variable whose name was passed as \fB$1\fP.
1507 If the control variable in a \fBfor\fP loop has the nameref attribute,
1508 the list of words can be a list of shell variables, and a name reference
1509 is established for each word in the list, in turn, when the loop is
1510 executed.
1511 Array variables cannot be given the \fBnameref\fP attribute.
1512 However, nameref variables can reference array variables and subscripted
1513 array variables.
1514 Namerefs can be unset using the \fB\-n\fP option to the \fBunset\fP builtin.
1515 Otherwise, if \fBunset\fP is executed with the name of a nameref variable
1516 as an argument, the variable referenced by the nameref variable is unset.
1517 .PP
1518 When the shell starts, it reads its environment and creates a shell
1519 variable from each environment variable that has a valid name,
1520 as described below
1521 (see
1522 .SM
1523 .BR ENVIRONMENT ).
1524 .SS Positional Parameters
1525 A
1526 .I positional parameter
1527 is a parameter denoted by one or more
1528 digits, other than the single digit 0.
1529 Positional parameters are
1530 assigned from the shell's arguments when it is invoked,
1531 and may be reassigned using the
1532 .B set
1533 builtin command.
1534 Positional parameters may not be assigned to
1535 with assignment statements.
1536 The positional parameters are
1537 temporarily replaced when a shell function is executed (see
1538 .SM
1539 .B FUNCTIONS
1540 below).
1541 .PP
1542 When a positional parameter consisting of more than a single
1543 digit is expanded, it must be enclosed in braces (see
1544 .SM
1545 .B EXPANSION
1546 below).
1547 Without braces, a digit following $ can only refer to
1548 one of the first nine positional parameters (\fB$1\-$9\fP) or the
1549 special parameter \fB$0\fP (see the next section).
1550 .SS Special Parameters
1551 The shell treats several parameters specially.
1552 These parameters may only be referenced; assignment to them is
1553 not allowed.
1554 Special parameters are denoted by one of the following characters.
1555 .TP
1556 .PD 0
1557 .B *
1558 (\fB$*\fP) Expands to the positional parameters, starting from one.
1559 When the expansion is not within double quotes, each positional parameter
1560 expands to a separate word.
1561 In contexts where word expansions are performed, those words
1562 are subject to further word splitting and pathname expansion.
1563 When the expansion occurs within double quotes, it expands to a
1564 single word with the value of each parameter separated by the first
1565 character of the
1566 .SM
1567 .B IFS
1568 variable.
1569 That is,
1570 .B \*"$*\*"
1571 is equivalent to
1572 .BR \*"$1\fIc\fP$2\fIc\fP.\|.\|.\*" ,
1573 where
1574 .I c
1575 is the first character of the value of the
1576 .SM
1577 .B IFS
1578 variable.
1579 If
1580 .SM
1581 .B IFS
1582 is unset, the parameters are separated by spaces.
1583 If
1584 .SM
1585 .B IFS
1586 is null, the parameters are joined without intervening separators.
1587 .TP
1588 .B @
1589 (\fB$@\fP) Expands to the positional parameters, starting from one.
1590 In contexts where word splitting is performed, this expands each
1591 positional parameter to a separate word; if not within double
1592 quotes, these words are subject to word splitting.
1593 In contexts where word splitting is not performed,
1594 such as the value portion of an assignment statement,
1595 this expands to a single word
1596 with each positional parameter separated by a space.
1597 When the expansion occurs within double quotes,
1598 and word splitting is performed,
1599 each parameter expands to a separate word.
1600 That is,
1601 .B \&\*"$@\*"
1602 is equivalent to
1603 .B \&\*"\&$1\&\*"\ \*"$2\*"\ .\|.\|.
1604 If the double-quoted expansion occurs within a word, the expansion of
1605 the first parameter is joined with the expansion of the
1606 beginning part of the original word,
1607 and the expansion of the last parameter is joined with the
1608 expansion of the last part of the original word.
1609 When there are no positional parameters,
1610 .B \&\*"$@\*"
1611 and
1612 .B $@
1613 expand to nothing (i.e., they are removed).
1614 .TP
1615 .B #
1616 (\fB$#\fP) Expands to the number of positional parameters in decimal.
1617 .TP
1618 .B ?
1619 (\fB$?\fP) Expands to the exit status of the most recently executed command.
1620 .TP
1621 .B \-
1622 (\fB$\-\fP) Expands to the current option flags as specified upon invocation,
1623 by the
1624 .B set
1625 builtin command, or those set by the shell itself
1626 (such as the
1627 .B \-i
1628 option).
1629 .TP
1630 .B $
1631 (\fB$$\fP) Expands to the process ID of the shell.
1632 In a subshell, it expands to the process ID of the parent shell,
1633 not the subshell.
1634 .TP
1635 .B !
1636 (\fB$!\fP)Expands to the process ID of the job most recently placed into the
1637 background, whether executed as an asynchronous command or using
1638 the \fBbg\fP builtin (see
1639 .SM
1640 .B "JOB CONTROL"
1641 below).
1642 .TP
1643 .B 0
1644 (\fB$0\fP) Expands to the name of the shell or shell script.
1645 This is set at shell initialization.
1646 If \fBbash\fP is invoked with a file of commands,
1647 .B $0
1648 is set to the name of that file.
1649 If \fBbash\fP is started with the
1650 .B \-c
1651 option, then
1652 .B $0
1653 is set to the first argument after the string to be
1654 executed, if one is present.
1655 Otherwise, it is set to the filename used to invoke
1656 .BR bash ,
1657 as given by argument zero.
1658 .PD
1659 .SS "Shell Variables"
1660 The shell sets following variables:
1661 .PP
1662 .PD 0
1663 .TP
1664 .B _
1665 (\fB$_\fP, an underscore)
1666 This has a number of meanings depending on context.
1667 At shell startup, \fB_\fP is set to the pathname used to invoke the
1668 shell or shell script being executed as passed in the environment
1669 or argument list.
1670 Subsequently, it expands to the last argument to the previous simple
1671 command executed in the foreground, after expansion.
1672 It is also set to the full pathname used to invoke each command executed
1673 and placed in the environment exported to that command.
1674 When checking mail, \fB$_\fP expands to the name of the mail file
1675 currently being checked.
1676 .TP
1677 .B BASH
1678 Expands to the full filename used to invoke this instance of
1679 .BR bash .
1680 .TP
1681 .B BASHOPTS
1682 A colon-separated list of enabled shell options. Each word in
1683 the list is a valid argument for the
1684 .B \-s
1685 option to the
1686 .B shopt
1687 builtin command (see
1688 .SM
1689 .B "SHELL BUILTIN COMMANDS"
1690 below).
1691 The options appearing in
1692 .SM
1693 .B BASHOPTS
1694 are those reported as
1695 .I on
1696 by \fBshopt\fP.
1697 If this variable is in the environment when
1698 .B bash
1699 starts up, the shell enables each option in the list before
1700 reading any startup files.
1701 If this variable is exported, child shells will enable each option
1702 in the list.
1703 This variable is read-only.
1704 .TP
1705 .B BASHPID
1706 Expands to the process ID of the current \fBbash\fP process.
1707 This differs from \fB$$\fP under certain circumstances, such as subshells
1708 that do not require \fBbash\fP to be re-initialized.
1709 Assignments to
1710 .SM
1711 .B BASHPID
1712 have no effect.
1713 If
1714 .SM
1715 .B BASHPID
1716 is unset, it loses its special properties, even if it is
1717 subsequently reset.
1718 .TP
1719 .B BASH_ALIASES
1720 An associative array variable whose members correspond to the internal
1721 list of aliases as maintained by the \fBalias\fP builtin.
1722 Elements added to this array appear in the alias list; however,
1723 unsetting array elements currently does not remove aliases
1724 from the alias list.
1725 If
1726 .SM
1727 .B BASH_ALIASES
1728 is unset, it loses its special properties, even if it is
1729 subsequently reset.
1730 .TP
1731 .B BASH_ARGC
1732 An array variable whose values are the number of parameters in each
1733 frame of the current \fBbash\fP execution call stack.
1734 The number of parameters to the current subroutine (shell function or
1735 script executed with \fB.\fP or \fBsource\fP) is at the top of the stack.
1736 When a subroutine is executed, the number of parameters passed is pushed onto
1737 .SM
1738 .BR BASH_ARGC .
1739 The shell sets
1740 .SM
1741 .B BASH_ARGC
1742 only when in extended debugging mode (see the description of the
1743 .B extdebug
1744 option to the
1745 .B shopt
1746 builtin below).
1747 Setting \fBextdebug\fP after the shell has started to execute a script,
1748 or referencing this variable when \fBextdebug\fP is not set,
1749 may result in inconsistent values.
1750 Assignments to
1751 .SM
1752 .B BASH_ARGC
1753 have no effect, and it may not be unset.
1754 .TP
1755 .B BASH_ARGV
1756 An array variable containing all of the parameters in the current \fBbash\fP
1757 execution call stack.
1758 The final parameter of the last subroutine call is at the top of the stack;
1759 the first parameter of the initial call is at the bottom.
1760 When a subroutine is executed, the shell pushes the supplied parameters onto
1761 .SM
1762 .BR BASH_ARGV .
1763 The shell sets
1764 .SM
1765 .B BASH_ARGV
1766 only when in extended debugging mode
1767 (see the description of the
1768 .B extdebug
1769 option to the
1770 .B shopt
1771 builtin below).
1772 Setting \fBextdebug\fP after the shell has started to execute a script,
1773 or referencing this variable when \fBextdebug\fP is not set,
1774 may result in inconsistent values.
1775 Assignments to
1776 .SM
1777 .B BASH_ARGV
1778 have no effect, and it may not be unset.
1779 .TP
1780 .B BASH_ARGV0
1781 When referenced, this variable expands to the name of the shell or shell
1782 script (identical to
1783 .BR $0 ;
1784 see the description of special parameter 0 above).
1785 Assigning a value to
1786 .SM
1787 .B BASH_ARGV0
1788 sets \fB$0\fP to the same value.
1789 If
1790 .SM
1791 .B BASH_ARGV0
1792 is unset, it loses its special properties, even if it is
1793 subsequently reset.
1794 .TP
1795 .B BASH_CMDS
1796 An associative array variable whose members correspond to the internal
1797 hash table of commands as maintained by the \fBhash\fP builtin.
1798 Adding elements to this array makes them appear in the hash table; however,
1799 unsetting array elements currently does not remove command names
1800 from the hash table.
1801 If
1802 .SM
1803 .B BASH_CMDS
1804 is unset, it loses its special properties, even if it is
1805 subsequently reset.
1806 .TP
1807 .B BASH_COMMAND
1808 Expands to the command currently being executed or about to be executed,
1809 unless the shell is executing a command as the result of a trap,
1810 in which case it is the command executing at the time of the trap.
1811 If
1812 .SM
1813 .B BASH_COMMAND
1814 is unset, it loses its special properties, even if it is
1815 subsequently reset.
1816 .TP
1817 .B BASH_EXECUTION_STRING
1818 The command argument to the \fB\-c\fP invocation option.
1819 .TP
1820 .B BASH_LINENO
1821 An array variable whose members are the line numbers in source files
1822 where each corresponding member of
1823 .SM
1824 .B FUNCNAME
1825 was invoked.
1826 \fB${BASH_LINENO[\fP\fI$i\fP\fB]}\fP
1827 is the line number in the source file
1828 (\fB${BASH_SOURCE[\fP\fI$i+1\fP\fB]}\fP)
1829 where
1830 \fB${FUNCNAME[\fP\fI$i\fP\fB]}\fP
1831 was called
1832 (or \fB${BASH_LINENO[\fP\fI$i\-1\fP\fB]}\fP if referenced within another
1833 shell function).
1834 Use
1835 .SM
1836 .B LINENO
1837 to obtain the current line number.
1838 Assignments to
1839 .SM
1840 .B BASH_LINENO
1841 have no effect, and it may not be unset.
1842 .TP
1843 .B BASH_LOADABLES_PATH
1844 A colon-separated list of directories in which the
1845 .B enable
1846 command
1847 looks for
1848 dynamically loadable builtins.
1849 .TP
1850 .B BASH_MONOSECONDS
1851 Each time this variable is referenced, it expands to the value returned
1852 by the system's monotonic clock, if one is available.
1853 If there is no monotonic clock, this is equivalent to \fBEPOCHSECONDS\fP.
1854 If
1855 .SM
1856 .B BASH_MONOSECONDS
1857 is unset, it loses its special properties, even if it is
1858 subsequently reset.
1859 .TP
1860 .B BASH_REMATCH
1861 An array variable whose members are assigned by the \fB=\*~\fP binary
1862 operator to the \fB[[\fP conditional command.
1863 The element with index 0 is the portion of the string
1864 matching the entire regular expression.
1865 The element with index \fIn\fP is the portion of the
1866 string matching the \fIn\fPth parenthesized subexpression.
1867 .TP
1868 .B BASH_SOURCE
1869 An array variable whose members are the source filenames
1870 where the corresponding shell function names in the
1871 .SM
1872 .B FUNCNAME
1873 array variable are defined.
1874 The shell function
1875 \fB${FUNCNAME[\fP\fI$i\fP\fB]}\fP is defined in the file
1876 \fB${BASH_SOURCE[\fP\fI$i\fP\fB]}\fP and called from
1877 \fB${BASH_SOURCE[\fP\fI$i+1\fP\fB]}\fP.
1878 Assignments to
1879 .SM
1880 .B BASH_SOURCE
1881 have no effect, and it may not be unset.
1882 .TP
1883 .B BASH_SUBSHELL
1884 Incremented by one within each subshell or subshell environment when
1885 the shell begins executing in that environment.
1886 The initial value is 0.
1887 If
1888 .SM
1889 .B BASH_SUBSHELL
1890 is unset, it loses its special properties, even if it is
1891 subsequently reset.
1892 .TP
1893 .B BASH_TRAPSIG
1894 Set to the signal number corresponding to the trap action being executed
1895 during its execution.
1896 See the description of \fBtrap\fP under
1897 .SM
1898 .B "SHELL BUILTIN COMMANDS"
1899 below for information about signal numbers and trap execution.
1900 .TP
1901 .B BASH_VERSINFO
1902 A readonly array variable whose members hold version information for
1903 this instance of
1904 .BR bash .
1905 The values assigned to the array members are as follows:
1906 .PP
1907 .RS
1908 .TP 24
1909 .B BASH_VERSINFO[\fR0\fP]
1910 The major version number (the \fIrelease\fP).
1911 .TP
1912 .B BASH_VERSINFO[\fR1\fP]
1913 The minor version number (the \fIversion\fP).
1914 .TP
1915 .B BASH_VERSINFO[\fR2\fP]
1916 The patch level.
1917 .TP
1918 .B BASH_VERSINFO[\fR3\fP]
1919 The build version.
1920 .TP
1921 .B BASH_VERSINFO[\fR4\fP]
1922 The release status (e.g., \fIbeta\fP).
1923 .TP
1924 .B BASH_VERSINFO[\fR5\fP]
1925 The value of
1926 .SM
1927 .BR MACHTYPE .
1928 .RE
1929 .TP
1930 .B BASH_VERSION
1931 Expands to a string describing the version of this instance of
1932 .B bash
1933 (e.g., 5.2.37(3)-release).
1934 .TP
1935 .B COMP_CWORD
1936 An index into \fB${COMP_WORDS}\fP of the word containing the current
1937 cursor position.
1938 This variable is available only in shell functions invoked by the
1939 programmable completion facilities (see \fBProgrammable Completion\fP
1940 below).
1941 .TP
1942 .B COMP_KEY
1943 The key (or final key of a key sequence) used to invoke the current
1944 completion function.
1945 This variable is available only in shell functions and external
1946 commands invoked by the
1947 programmable completion facilities (see \fBProgrammable Completion\fP
1948 below).
1949 .TP
1950 .B COMP_LINE
1951 The current command line.
1952 This variable is available only in shell functions and external
1953 commands invoked by the
1954 programmable completion facilities (see \fBProgrammable Completion\fP
1955 below).
1956 .TP
1957 .B COMP_POINT
1958 The index of the current cursor position relative to the beginning of
1959 the current command.
1960 If the current cursor position is at the end of the current command,
1961 the value of this variable is equal to \fB${#COMP_LINE}\fP.
1962 This variable is available only in shell functions and external
1963 commands invoked by the
1964 programmable completion facilities (see \fBProgrammable Completion\fP
1965 below).
1966 .TP
1967 .B COMP_TYPE
1968 Set to an integer value corresponding to the type of attempted completion
1969 that caused a completion function to be called:
1970 \fITAB\fP, for normal completion,
1971 \fI?\fP, for listing completions after successive tabs,
1972 \fI!\fP, for listing alternatives on partial word completion,
1973 \fI@\fP, to list completions if the word is not unmodified,
1974 or
1975 \fI%\fP, for menu completion.
1976 This variable is available only in shell functions and external
1977 commands invoked by the
1978 programmable completion facilities (see \fBProgrammable Completion\fP
1979 below).
1980 .TP
1981 .B COMP_WORDBREAKS
1982 The set of characters that the \fBreadline\fP library treats as word
1983 separators when performing word completion.
1984 If
1985 .SM
1986 .B COMP_WORDBREAKS
1987 is unset, it loses its special properties, even if it is
1988 subsequently reset.
1989 .TP
1990 .B COMP_WORDS
1991 An array variable (see \fBArrays\fP below) consisting of the individual
1992 words in the current command line.
1993 The line is split into words as \fBreadline\fP would split it, using
1994 .SM
1995 .B COMP_WORDBREAKS
1996 as described above.
1997 This variable is available only in shell functions invoked by the
1998 programmable completion facilities (see \fBProgrammable Completion\fP
1999 below).
2000 .TP
2001 .B COPROC
2002 An array variable (see \fBArrays\fP below) created to hold the file descriptors
2003 for output from and input to an unnamed coprocess (see \fBCoprocesses\fP
2004 above).
2005 .TP
2006 .B DIRSTACK
2007 An array variable (see
2008 .B Arrays
2009 below) containing the current contents of the directory stack.
2010 Directories appear in the stack in the order they are displayed by the
2011 .B dirs
2012 builtin.
2013 Assigning to members of this array variable may be used to modify
2014 directories already in the stack, but the
2015 .B pushd
2016 and
2017 .B popd
2018 builtins must be used to add and remove directories.
2019 Assigning to this variable does not change the current directory.
2020 If
2021 .SM
2022 .B DIRSTACK
2023 is unset, it loses its special properties, even if it is
2024 subsequently reset.
2025 .TP
2026 .B EPOCHREALTIME
2027 Each time this parameter is referenced, it expands to the number of seconds
2028 since the Unix Epoch (see
2029 .IR time (3))
2030 as a floating-point value with micro-second granularity.
2031 Assignments to
2032 .SM
2033 .B EPOCHREALTIME
2034 are ignored.
2035 If
2036 .SM
2037 .B EPOCHREALTIME
2038 is unset, it loses its special properties, even if it is
2039 subsequently reset.
2040 .TP
2041 .B EPOCHSECONDS
2042 Each time this parameter is referenced, it expands to the number of seconds
2043 since the Unix Epoch (see
2044 .IR time (3)).
2045 Assignments to
2046 .SM
2047 .B EPOCHSECONDS
2048 are ignored.
2049 If
2050 .SM
2051 .B EPOCHSECONDS
2052 is unset, it loses its special properties, even if it is
2053 subsequently reset.
2054 .TP
2055 .B EUID
2056 Expands to the effective user ID of the current user, initialized at
2057 shell startup. This variable is readonly.
2058 .TP
2059 .B FUNCNAME
2060 .PD
2061 An array variable containing the names of all shell functions
2062 currently in the execution call stack.
2063 The element with index 0 is the name of any currently-executing
2064 shell function.
2065 The bottom-most element (the one with the highest index) is
2066 .Q main .
2067 This variable exists only when a shell function is executing.
2068 Assignments to
2069 .SM
2070 .B FUNCNAME
2071 have no effect.
2072 If
2073 .SM
2074 .B FUNCNAME
2075 is unset, it loses its special properties, even if it is
2076 subsequently reset.
2077 .IP
2078 This variable can be used with
2079 .SM
2080 .B BASH_LINENO
2081 and
2082 .SM
2083 .BR BASH_SOURCE .
2084 Each element of
2085 .SM
2086 .B \%FUNCNAME
2087 has corresponding elements in
2088 .SM
2089 .B BASH_LINENO
2090 and
2091 .SM
2092 .B BASH_SOURCE
2093 to describe the call stack.
2094 For instance,
2095 \fB\%${FUNCNAME[\fP\fI$i\fP\fB]}\fP
2096 was called from the file
2097 \fB${BASH_SOURCE[\fP\fI$i+1\fP\fB]}\fP
2098 at line number
2099 \fB${BASH_LINENO[\fP\fI$i\fP\fB]}\fP.
2100 The \fBcaller\fP builtin displays the current call stack using this
2101 information.
2102 .PD 0
2103 .TP
2104 .B GROUPS
2105 An array variable containing the list of groups of which the current
2106 user is a member.
2107 Assignments to
2108 .SM
2109 .B GROUPS
2110 have no effect.
2111 If
2112 .SM
2113 .B GROUPS
2114 is unset, it loses its special properties, even if it is
2115 subsequently reset.
2116 .TP
2117 .B HISTCMD
2118 The history number, or index in the history list, of the current
2119 command.
2120 Assignments to
2121 .SM
2122 .B HISTCMD
2123 have no effect.
2124 If
2125 .SM
2126 .B HISTCMD
2127 is unset, it loses its special properties, even if it is
2128 subsequently reset.
2129 .TP
2130 .B HOSTNAME
2131 Automatically set to the name of the current host.
2132 .TP
2133 .B HOSTTYPE
2134 Automatically set to a string that uniquely
2135 describes the type of machine on which
2136 .B bash
2137 is executing.
2138 The default is system-dependent.
2139 .TP
2140 .B LINENO
2141 Each time this parameter is referenced, the shell substitutes
2142 a decimal number representing the current sequential line number
2143 (starting with 1) within a script or function.
2144 When not in a script or function, the value substituted is not
2145 guaranteed to be meaningful.
2146 If
2147 .SM
2148 .B LINENO
2149 is unset, it loses its special properties, even if it is
2150 subsequently reset.
2151 .TP
2152 .B MACHTYPE
2153 Automatically set to a string that fully describes the system
2154 type on which
2155 .B bash
2156 is executing, in the standard GNU \fIcpu-company-system\fP format.
2157 The default is system-dependent.
2158 .TP
2159 .B MAPFILE
2160 An array variable (see \fBArrays\fP below) created to hold the text
2161 read by the \fBmapfile\fP builtin when no variable name is supplied.
2162 .TP
2163 .B OLDPWD
2164 The previous working directory as set by the
2165 .B cd
2166 command.
2167 .TP
2168 .B OPTARG
2169 The value of the last option argument processed by the
2170 .B getopts
2171 builtin command (see
2172 .SM
2173 .B "SHELL BUILTIN COMMANDS"
2174 below).
2175 .TP
2176 .B OPTIND
2177 The index of the next argument to be processed by the
2178 .B getopts
2179 builtin command (see
2180 .SM
2181 .B "SHELL BUILTIN COMMANDS"
2182 below).
2183 .TP
2184 .B OSTYPE
2185 Automatically set to a string that
2186 describes the operating system on which
2187 .B bash
2188 is executing.
2189 The default is system-dependent.
2190 .TP
2191 .B PIPESTATUS
2192 An array variable (see
2193 .B Arrays
2194 below) containing a list of exit status values from the commands
2195 in the most-recently-executed foreground pipeline, which may
2196 consist of only a simple command
2197 (see
2198 .SM
2199 .B "SHELL GRAMMAR"
2200 above).
2201 \fBBash\fP sets
2202 .SM
2203 .B PIPESTATUS
2204 after executing multi-element pipelines,
2205 timed and negated pipelines,
2206 simple commands,
2207 subshells created with the ( operator,
2208 the
2209 .B [[
2210 and
2211 .B ((
2212 compound commands, and
2213 after error conditions that result in the
2214 shell aborting command execution.
2215 .TP
2216 .B PPID
2217 The process ID of the shell's parent.
2218 This variable is readonly.
2219 .TP
2220 .B PWD
2221 The current working directory as set by the
2222 .B cd
2223 command.
2224 .TP
2225 .B RANDOM
2226 Each time this parameter is referenced, it expands to a random integer
2227 between 0 and 32767.
2228 Assigning a value to
2229 .SM
2230 .B RANDOM
2231 initializes (seeds) the sequence of random numbers.
2232 Seeding the random number generator with the same constant value
2233 produces the same sequence of values.
2234 If
2235 .SM
2236 .B RANDOM
2237 is unset, it loses its special properties, even if it is
2238 subsequently reset.
2239 .TP
2240 .B READLINE_ARGUMENT
2241 Any numeric argument given to a
2242 .B \%readline
2243 command that was defined using
2244 .Q "bind \-x"
2245 (see
2246 .SM
2247 .B "SHELL BUILTIN COMMANDS"
2248 below)
2249 when it was invoked.
2250 .TP
2251 .B READLINE_LINE
2252 The contents of the
2253 .B readline
2254 line buffer, for use with
2255 .Q "bind \-x"
2256 (see
2257 .SM
2258 .B "SHELL BUILTIN COMMANDS"
2259 below).
2260 .TP
2261 .B READLINE_MARK
2262 The position of the mark (saved insertion point) in the
2263 .B readline
2264 line buffer, for use with
2265 .Q "bind \-x"
2266 (see
2267 .SM
2268 .B "SHELL BUILTIN COMMANDS"
2269 below).
2270 The characters between the insertion point and the mark are often
2271 called the \fIregion\fP.
2272 .TP
2273 .B READLINE_POINT
2274 The position of the insertion point in the
2275 .B readline
2276 line buffer, for use with
2277 .Q "bind \-x"
2278 (see
2279 .SM
2280 .B "SHELL BUILTIN COMMANDS"
2281 below).
2282 .TP
2283 .B REPLY
2284 Set to the line of input read by the
2285 .B read
2286 builtin command when no arguments are supplied.
2287 .TP
2288 .B SECONDS
2289 Each time this parameter is
2290 referenced, it expands to the number of seconds since shell invocation.
2291 If a value is assigned to
2292 .SM
2293 .BR SECONDS ,
2294 the value returned upon subsequent
2295 references is
2296 the number of seconds since the assignment plus the value assigned.
2297 The number of seconds at shell invocation and the current time are always
2298 determined by querying the system clock at one-second resolution.
2299 If
2300 .SM
2301 .B SECONDS
2302 is unset, it loses its special properties, even if it is
2303 subsequently reset.
2304 .TP
2305 .B SHELLOPTS
2306 A colon-separated list of enabled shell options.
2307 Each word in the list is a valid argument for the
2308 .B \-o
2309 option to the
2310 .B set
2311 builtin command (see
2312 .SM
2313 .B "SHELL BUILTIN COMMANDS"
2314 below).
2315 The options appearing in
2316 .SM
2317 .B SHELLOPTS
2318 are those reported as
2319 .I on
2320 by \fBset \-o\fP.
2321 If this variable is in the environment when
2322 .B bash
2323 starts up, the shell enables each option in the list before
2324 reading any startup files.
2325 If this variable is exported, child shells will enable each option
2326 in the list.
2327 This variable is read-only.
2328 .TP
2329 .B SHLVL
2330 Incremented by one each time an instance of
2331 .B bash
2332 is started.
2333 .TP
2334 .B SRANDOM
2335 Each time it is referenced, this variable expands to a 32-bit pseudo-random
2336 number.
2337 The random number generator is not linear on systems that
2338 support
2339 .FN /dev/urandom
2340 or
2341 .IR arc4random (3),
2342 so each returned number
2343 has no relationship to the numbers preceding it.
2344 The random number generator cannot be seeded, so assignments to this
2345 variable have no effect.
2346 If
2347 .SM
2348 .B SRANDOM
2349 is unset, it loses its special properties,
2350 even if it is subsequently reset.
2351 .TP
2352 .B UID
2353 Expands to the user ID of the current user, initialized at shell startup.
2354 This variable is readonly.
2355 .PD
2356 .PP
2357 The shell uses the following variables. In some cases,
2358 .B bash
2359 assigns a default value to a variable; these cases are noted
2360 below.
2361 .PP
2362 .PD 0
2363 .TP
2364 .B BASH_COMPAT
2365 The value is used to set the shell's compatibility level.
2366 See
2367 .SM
2368 .B "SHELL COMPATIBILITY MODE"
2369 below for a description of the various compatibility
2370 levels and their effects.
2371 The value may be a decimal number (e.g., 4.2) or an integer (e.g., 42)
2372 corresponding to the desired compatibility level.
2373 If
2374 .SM
2375 .B BASH_COMPAT
2376 is unset or set to the empty string, the compatibility
2377 level is set to the default for the current version.
2378 If
2379 .SM
2380 .B BASH_COMPAT
2381 is set to a value that is not one of the valid
2382 compatibility levels, the shell prints an error message and sets the
2383 compatibility level to the default for the current version.
2384 A subset of the valid values correspond to the compatibility levels
2385 described below under
2386 .SM
2387 .BR "SHELL COMPATIBILITY MODE" .
2388 For example, 4.2 and 42 are valid values that correspond
2389 to the \fBcompat42\fP \fBshopt\fP option
2390 and set the compatibility level to 42.
2391 The current version is also a valid value.
2392 .TP
2393 .B BASH_ENV
2394 If this parameter is set when \fBbash\fP is executing a shell script,
2395 its expanded value is interpreted as a filename containing commands to
2396 initialize the shell before it reads and executes commands from the
2397 script.
2398 The value of
2399 .SM
2400 .B BASH_ENV
2401 is subjected to parameter expansion, command substitution, and arithmetic
2402 expansion before being interpreted as a filename.
2403 .SM
2404 .B PATH
2405 is not used to search for the resultant filename.
2406 .TP
2407 .B BASH_XTRACEFD
2408 If set to an integer corresponding to a valid file descriptor,
2409 \fBbash\fP writes the trace output generated when
2410 .Q "set \-x"
2411 is enabled to that file descriptor,
2412 instead of the standard error.
2413 The file descriptor is closed when
2414 .SM
2415 .B BASH_XTRACEFD
2416 is unset or assigned a new value.
2417 Unsetting
2418 .SM
2419 .B BASH_XTRACEFD
2420 or assigning it the empty string causes the
2421 trace output to be sent to the standard error.
2422 Note that setting
2423 .SM
2424 .B BASH_XTRACEFD
2425 to 2 (the standard error file
2426 descriptor) and then unsetting it will result in the standard error
2427 being closed.
2428 .TP
2429 .B CDPATH
2430 The search path for the
2431 .B cd
2432 command.
2433 This is a colon-separated list of directories where the shell looks for
2434 directories specified as arguments to the
2435 .B cd
2436 command.
2437 A sample value is
2438 .Q .:\*~:/usr .
2439 .TP
2440 .B CHILD_MAX
2441 Set the number of exited child status values for the shell to remember.
2442 \fBBash\fP will not allow this value to be decreased below a
2443 .SM POSIX\c
2444 -mandated minimum,
2445 and there is a maximum value (currently 8192) that this may not exceed.
2446 The minimum value is system-dependent.
2447 .TP
2448 .B COLUMNS
2449 Used by the \fBselect\fP compound command to determine the terminal width
2450 when printing selection lists.
2451 Automatically set if the
2452 .B checkwinsize
2453 option is enabled or in an interactive shell upon receipt of a
2454 .SM
2455 .BR SIGWINCH .
2456 .TP
2457 .B COMPREPLY
2458 An array variable from which \fBbash\fP reads the possible completions
2459 generated by a shell function invoked by the programmable completion
2460 facility (see \fBProgrammable Completion\fP below).
2461 Each array element contains one possible completion.
2462 .TP
2463 .B EMACS
2464 If \fBbash\fP finds this variable in the environment when the shell starts
2465 with value
2466 .Q t ,
2467 it assumes that the shell is running in an Emacs shell buffer and disables
2468 line editing.
2469 .TP
2470 .B ENV
2471 Expanded and executed similarly to
2472 .SM
2473 .B BASH_ENV
2474 (see
2475 .SM
2476 .B INVOCATION
2477 above) when an interactive shell is invoked in posix mode.
2478 .TP
2479 .B EXECIGNORE
2480 A colon-separated list of shell patterns (see \fBPattern Matching\fP)
2481 defining the set of filenames to be ignored by command search using
2482 .SM
2483 .BR PATH .
2484 Files whose full pathnames match one of these patterns are not considered
2485 executable files for the purposes of completion and command execution
2486 via
2487 .SM
2488 .B PATH
2489 lookup.
2490 This does not affect the behavior of the \fB[\fP, \fBtest\fP, and \fB[[\fP
2491 commands.
2492 Full pathnames in the command hash table are not subject to
2493 .SM
2494 .BR EXECIGNORE .
2495 Use this variable to ignore shared library files that have the executable
2496 bit set, but are not executable files.
2497 The pattern matching honors the setting of the \fBextglob\fP shell
2498 option.
2499 .TP
2500 .B FCEDIT
2501 The default editor for the
2502 .B fc
2503 builtin command.
2504 .TP
2505 .B FIGNORE
2506 A colon-separated list of suffixes to ignore when performing
2507 filename completion (see
2508 .SM
2509 .B READLINE
2510 below).
2511 A filename whose suffix matches one of the entries in
2512 .SM
2513 .B FIGNORE
2514 is excluded from the list of matched filenames.
2515 A sample value is
2516 .Q .o:\*~ .
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 If that variable is unset, readline will read both
2804 .FN /etc/inputrc
2805 and
2806 .FN \*~/.inputrc .
2807 .TP
2808 .B INSIDE_EMACS
2809 If this variable appears in the environment when the shell starts,
2810 \fBbash\fP assumes that it is running inside an Emacs shell buffer
2811 and may disable line editing, depending on the value of
2812 .SM
2813 .BR TERM .
2814 .TP
2815 .B LANG
2816 Used to determine the locale category for any category not specifically
2817 selected with a variable starting with \fBLC_\fP.
2818 .TP
2819 .B LC_ALL
2820 This variable overrides the value of
2821 .SM
2822 .B LANG
2823 and any other
2824 \fBLC_\fP variable specifying a locale category.
2825 .TP
2826 .B LC_COLLATE
2827 This variable determines the collation order used when sorting the
2828 results of pathname expansion, and determines the behavior of range
2829 expressions, equivalence classes, and collating sequences within
2830 pathname expansion and pattern matching.
2831 .TP
2832 .B LC_CTYPE
2833 This variable determines the interpretation of characters and the
2834 behavior of character classes within pathname expansion and pattern
2835 matching.
2836 .TP
2837 .B LC_MESSAGES
2838 This variable determines the locale used to translate double-quoted
2839 strings preceded by a \fB$\fP.
2840 .TP
2841 .B LC_NUMERIC
2842 This variable determines the locale category used for number formatting.
2843 .TP
2844 .B LC_TIME
2845 This variable determines the locale category used for data and time
2846 formatting.
2847 .TP
2848 .B LINES
2849 Used by the \fBselect\fP compound command to determine the column length
2850 for printing selection lists.
2851 Automatically set if the
2852 .B checkwinsize
2853 option is enabled or in an interactive shell upon receipt of a
2854 .SM
2855 .BR SIGWINCH .
2856 .TP
2857 .B MAIL
2858 If the value is set to a file or directory name and the
2859 .SM
2860 .B MAILPATH
2861 variable is not set,
2862 .B bash
2863 informs the user of the arrival of mail in the specified file or
2864 Maildir-format directory.
2865 .TP
2866 .B MAILCHECK
2867 Specifies how
2868 often (in seconds)
2869 .B bash
2870 checks for mail.
2871 The default is 60 seconds.
2872 When it is time to check for mail,
2873 the shell does so before displaying the primary prompt.
2874 If this variable is unset, or set to a value that is not a number
2875 greater than or equal to zero, the shell disables mail checking.
2876 .TP
2877 .B MAILPATH
2878 A colon-separated list of filenames to be checked for mail.
2879 The message to be printed when mail arrives in a particular file
2880 may be specified by separating the filename from the message with a
2881 .Q ? .
2882 When used in the text of the message, \fB$_\fP expands to the name of
2883 the current mailfile.
2884 For example:
2885 .RS
2886 .PP
2887 .EX
2888 \fBMAILPATH\fP=\*'/var/mail/bfox?\*"You have mail\*":\*~/shell\-mail?\*"$_ has mail!\*"\*'
2889 .EE
2890 .PP
2891 .B Bash
2892 can be configured to supply
2893 a default value for this variable (there is no value by default),
2894 but the location of the user
2895 mail files that it uses is system dependent (e.g., /var/mail/\fB$USER\fP).
2896 .RE
2897 .TP
2898 .B OPTERR
2899 If set to the value 1,
2900 .B bash
2901 displays error messages generated by the
2902 .B getopts
2903 builtin command (see
2904 .SM
2905 .B "SHELL BUILTIN COMMANDS"
2906 below).
2907 .SM
2908 .B OPTERR
2909 is initialized to 1 each time the shell is invoked or a shell
2910 script is executed.
2911 .TP
2912 .B PATH
2913 The search path for commands.
2914 It is a colon-separated list of directories in which
2915 the shell looks for commands (see
2916 .SM
2917 .B "COMMAND EXECUTION"
2918 below).
2919 A zero-length (null) directory name in the value of
2920 .SM
2921 .B PATH
2922 indicates the current directory.
2923 A null directory name may appear as two adjacent colons, or as an initial
2924 or trailing colon.
2925 The default path is system-dependent,
2926 and is set by the administrator who installs
2927 .BR bash .
2928 A common value is
2929 .RS
2930 .RS 5n
2931 .EX
2932 /usr/local/bin:/usr/local/sbin:\c
2933 .if \n(LL<78n .br
2934 /usr/bin:/usr/sbin:/bin:/sbin
2935 .EE
2936 .RE
2937 .RE
2938 .TP
2939 .B POSIXLY_CORRECT
2940 If this variable is in the environment when \fBbash\fP starts, the shell
2941 enters posix mode before reading the startup files, as if the
2942 .B \-\-posix
2943 invocation option had been supplied.
2944 If it is set while the shell is
2945 running, \fBbash\fP enables posix mode, as if the command
2946 .Q "set \-o posix"
2947 had been executed.
2948 When the shell enters posix mode, it sets this variable if it was
2949 not already set.
2950 .TP
2951 .B PROMPT_COMMAND
2952 If this variable is set, and is an array,
2953 the value of each set element is executed as a command
2954 prior to issuing each primary prompt.
2955 If this is set but not an array variable,
2956 its value is used as a command to execute instead.
2957 .TP
2958 .B PROMPT_DIRTRIM
2959 If set to a number greater than zero, the value is used as the number of
2960 trailing directory components to retain when expanding the \fB\ew\fP and
2961 \fB\eW\fP prompt string escapes (see
2962 .SM
2963 .B PROMPTING
2964 below).
2965 Characters removed are replaced with an ellipsis.
2966 .TP
2967 .B PS0
2968 The value of this parameter is expanded (see
2969 .SM
2970 .B PROMPTING
2971 below) and displayed by interactive shells after reading a command
2972 and before the command is executed.
2973 .TP
2974 .B PS1
2975 The value of this parameter is expanded (see
2976 .SM
2977 .B PROMPTING
2978 below) and used as the primary prompt string.
2979 The default value is
2980 .Q \es\-\ev\e$\ .
2981 .TP
2982 .B PS2
2983 The value of this parameter is expanded as with
2984 .SM
2985 .B PS1
2986 and used as the secondary prompt string.
2987 The default is
2988 .Q >\ .
2989 .TP
2990 .B PS3
2991 The value of this parameter is used as the prompt for the
2992 .B select
2993 command (see
2994 .SM
2995 .B "SHELL GRAMMAR"
2996 above).
2997 .TP
2998 .B PS4
2999 The value of this parameter is expanded as with
3000 .SM
3001 .B PS1
3002 and the value is printed before each command
3003 .B bash
3004 displays during an execution trace.
3005 The first character of the expanded value of
3006 .SM
3007 .B PS4
3008 is replicated multiple times, as necessary, to indicate multiple
3009 levels of indirection.
3010 The default is
3011 .Q +\ .
3012 .TP
3013 .B SHELL
3014 This variable expands to the full pathname to the shell.
3015 If it is not set when the shell starts,
3016 .B bash
3017 assigns to it the full pathname of the current user's login shell.
3018 .TP
3019 .B TIMEFORMAT
3020 The value of this parameter is used as a format string specifying
3021 how the timing information for pipelines prefixed with the
3022 .B time
3023 reserved word should be displayed.
3024 The \fB%\fP character introduces an escape sequence that is
3025 expanded to a time value or other information.
3026 The escape sequences and their meanings are as follows; the
3027 brackets denote optional portions.
3028 .PP
3029 .RS
3030 .PD 0
3031 .TP 10
3032 .B %%
3033 A literal \fB%\fP.
3034 .TP
3035 .B %[\fIp\fP][l]R
3036 The elapsed time in seconds.
3037 .TP
3038 .B %[\fIp\fP][l]U
3039 The number of CPU seconds spent in user mode.
3040 .TP
3041 .B %[\fIp\fP][l]S
3042 The number of CPU seconds spent in system mode.
3043 .TP
3044 .B %P
3045 The CPU percentage, computed as (%U + %S) / %R.
3046 .PD
3047 .RE
3048 .IP
3049 The optional \fIp\fP is a digit specifying the \fIprecision\fP,
3050 the number of fractional digits after a decimal point.
3051 A value of 0 causes no decimal point or fraction to be output.
3052 \fBtime\fP prints at most six digits after the decimal point;
3053 values of \fIp\fP greater than 6 are changed to 6.
3054 If \fIp\fP is not specified,
3055 \fBtime\fP prints three digits after the decimal point.
3056 .IP
3057 The optional \fBl\fP specifies a longer format, including
3058 minutes, of the form \fIMM\fPm\fISS\fP.\fIFF\fPs.
3059 The value of \fIp\fP determines whether or not the fraction is
3060 included.
3061 .IP
3062 If this variable is not set, \fBbash\fP acts as if it had the
3063 value \fB$\*'\enreal\et%3lR\enuser\et%3lU\ensys\et%3lS\*'\fP.
3064 If the value is null, \fBbash\fP does not display any timing information.
3065 A trailing newline is added when the format string is displayed.
3066 .PD 0
3067 .TP
3068 .B TMOUT
3069 If set to a value greater than zero,
3070 the \fBread\fP builtin uses the value as its
3071 default timeout.
3072 The \fBselect\fP command terminates if input does not arrive
3073 after
3074 .SM
3075 .B TMOUT
3076 seconds when input is coming from a terminal.
3077 In an interactive shell, the value is interpreted as the
3078 number of seconds to wait for a line of input after issuing the
3079 primary prompt.
3080 .B Bash
3081 terminates after waiting for that number of seconds if a
3082 complete line of input does not arrive.
3083 .TP
3084 .B TMPDIR
3085 If set, \fBbash\fP uses its value as the name of a directory in which
3086 \fBbash\fP creates temporary files for the shell's use.
3087 .TP
3088 .B auto_resume
3089 This variable controls how the shell interacts with the user and
3090 job control.
3091 If this variable is set, simple commands
3092 consisting of only a single word,
3093 without redirections, are treated as candidates for resumption
3094 of an existing stopped job.
3095 There is no ambiguity allowed; if there is more than one job
3096 beginning with or containing
3097 the word, this selects the most recently accessed job.
3098 The
3099 .I name
3100 of a stopped job, in this context, is the command line used to
3101 start it, as displayed by \fBjobs\fP.
3102 If set to the value
3103 .IR exact ,
3104 the word must match the name of a stopped job exactly;
3105 if set to
3106 .IR substring ,
3107 the word needs to match a substring of the name of a stopped job.
3108 The
3109 .I substring
3110 value provides functionality analogous to the
3111 .B %?
3112 job identifier (see
3113 .SM
3114 .B "JOB CONTROL"
3115 below).
3116 If set to any other value (e.g.,
3117 .IR prefix ),
3118 the word must be a prefix of a stopped job's name;
3119 this provides functionality analogous to the \fB%\fP\fIstring\fP job identifier.
3120 .TP
3121 .B histchars
3122 The two or three characters which control history expansion,
3123 quick substitution, and tokenization
3124 (see
3125 .SM
3126 .B "HISTORY EXPANSION"
3127 below).
3128 The first character is the \fIhistory expansion\fP character,
3129 the character which begins a history expansion, normally
3130 .Q \fB!\fP .
3131 The second character is the \fIquick substitution\fP character, normally
3132 .Q \fB\*^\fP .
3133 When it appears as the first character on the line,
3134 history substitution repeats the previous command,
3135 replacing one string with another.
3136 The optional third character is the
3137 \fIhistory comment\fP
3138 character, normally
3139 .Q \fB#\fP ,
3140 which indicates
3141 that the remainder of the line is a comment
3142 when it appears as the first character of a word.
3143 The history comment character disables history substitution
3144 for the remaining words on the line.
3145 It does not necessarily cause the shell parser to treat the rest of the
3146 line as a comment.
3147 .PD
3148 .SS Arrays
3149 .B Bash
3150 provides one-dimensional indexed and associative array variables.
3151 Any variable may be used as an indexed array; the
3152 .B declare
3153 builtin explicitly declares an array.
3154 There is no maximum
3155 limit on the size of an array, nor any requirement that members
3156 be indexed or assigned contiguously.
3157 Indexed arrays are referenced using arithmetic expressions
3158 that must expand to an integer
3159 (see
3160 .SM
3161 .B
3162 ARITHMETIC EVALUATION
3163 below)
3164 and are zero-based;
3165 associative arrays are referenced using arbitrary strings.
3166 Unless otherwise noted, indexed array indices must be non-negative integers.
3167 .PP
3168 The shell performs
3169 parameter and variable expansion, arithmetic expansion,
3170 command substitution, and quote removal
3171 on indexed array subscripts.
3172 Since this
3173 can potentially result in empty strings,
3174 subscript indexing treats
3175 those as expressions that evaluate to 0.
3176 .PP
3177 The shell performs
3178 tilde expansion,
3179 parameter and variable expansion, arithmetic expansion,
3180 command substitution, and quote removal
3181 on associative array subscripts.
3182 Empty strings cannot be used as associative array keys.
3183 .PP
3184 \fBBash\fP automatically creates an indexed array
3185 if any variable is assigned to using the syntax
3186 .RS
3187 \fIname\fP[\fIsubscript\fP]=\fIvalue\fP
3188 \&.
3189 .RE
3190 The
3191 .I subscript
3192 is treated as an arithmetic expression that must evaluate to a number
3193 greater than or equal to zero.
3194 To explicitly declare an indexed array, use
3195 .RS
3196 .BI "declare \-a\ " name
3197 .RE
3198 (see
3199 .SM
3200 .B "SHELL BUILTIN COMMANDS"
3201 below).
3202 .RS
3203 \fBdeclare \-a\fP \fIname\fP[\fIsubscript\fP]
3204 .RE
3205 is also accepted; the \fIsubscript\fP is ignored.
3206 .PP
3207 Associative arrays are created using
3208 .RS
3209 .BI "declare \-A\ " name
3210 .RE
3211 \&.
3212 .PP
3213 Attributes may be specified for an array variable using the
3214 .B \%declare
3215 and
3216 .B \%readonly
3217 builtins.
3218 Each attribute applies to all members of an array.
3219 .PP
3220 Arrays are assigned using compound assignments of the form
3221 \fIname\fP=\fB(\fPvalue\fI1\fP .\|.\|.\& value\fIn\fP\fB)\fP, where each
3222 \fIvalue\fP may be of the form [\fIsubscript\fP]=\fIstring\fP.
3223 Indexed array assignments do not require anything but \fIstring\fP.
3224 Each \fIvalue\fP in the list is expanded using the shell expansions
3225 described below under
3226 .SM
3227 .BR EXPANSION ,
3228 but \fIvalue\fPs that are valid variable assignments
3229 including the brackets and subscript do not undergo
3230 brace expansion and word splitting, as with individual
3231 variable assignments.
3232 .PP
3233 When assigning to indexed arrays, if the optional brackets and subscript
3234 are supplied, that index is assigned to;
3235 otherwise the index of the element assigned is the last index assigned
3236 to by the statement plus one.
3237 Indexing starts at zero.
3238 .PP
3239 When assigning to an associative array, the words in a compound assignment
3240 may be either assignment statements, for which the subscript is required,
3241 or a list of words that is interpreted as a sequence of alternating keys
3242 and values:
3243 \fIname\fP=\fB( \fP\fIkey1 value1 key2 value2\fP .\|.\|.\&\fB)\fP.
3244 These are treated identically to
3245 \fIname\fP=\fB(\fP [\fIkey1\fP]=\fIvalue1\fP [\fIkey2\fP]=\fIvalue2\fP
3246 \&.\|.\|.\&\fB)\fP.
3247 The first word in the list determines how the remaining words
3248 are interpreted; all assignments in a list must be of the same type.
3249 When using key/value pairs, the keys may not be missing or empty;
3250 a final missing value is treated like the empty string.
3251 .PP
3252 This syntax is also accepted by the
3253 .B declare
3254 builtin.
3255 Individual array elements may be assigned to using the
3256 \fIname\fP[\fIsubscript\fP]=\fIvalue\fP syntax introduced above.
3257 .PP
3258 When assigning to an indexed array, if
3259 .I name
3260 is subscripted by a negative number, that number is
3261 interpreted as relative to one greater than the maximum index of
3262 \fIname\fP, so negative indices count back from the end of the
3263 array, and an index of \-1 references the last element.
3264 .PP
3265 The
3266 .Q +=
3267 operator appends to an array variable when assigning
3268 using the compound assignment syntax; see
3269 .SM
3270 .B PARAMETERS
3271 above.
3272 .PP
3273 An array element is referenced using
3274 ${\fIname\fP[\fIsubscript\fP]}.
3275 The braces are required to avoid conflicts with pathname expansion.
3276 If \fIsubscript\fP is \fB@\fP or \fB*\fP, the word expands to
3277 all members of \fIname\fP,
3278 unless noted in the description of a builtin or word expansion.
3279 These subscripts differ only when the
3280 word appears within double quotes.
3281 If the word is double-quoted, ${\fIname\fP[*]} expands to a single
3282 word with the value of each array member separated by the first
3283 character of the
3284 .SM
3285 .B IFS
3286 special variable, and ${\fIname\fP[@]} expands each element of
3287 \fIname\fP to a separate word.
3288 When there are no array members, ${\fIname\fP[@]} expands to nothing.
3289 If the double-quoted expansion occurs within a word, the expansion of
3290 the first parameter is joined with the beginning part of the
3291 expansion of the original word,
3292 and the expansion of the last parameter is joined with the last
3293 part of the
3294 expansion of the original word.
3295 This is analogous to the expansion
3296 of the special parameters \fB*\fP and \fB@\fP (see
3297 .B "Special Parameters"
3298 above).
3299 .PP
3300 ${#\fIname\fP[\fIsubscript\fP]} expands to the length of
3301 ${\fIname\fP[\fIsubscript\fP]}.
3302 If \fIsubscript\fP is \fB*\fP or \fB@\fP,
3303 the expansion is the number of elements in the array.
3304 .PP
3305 If the
3306 .I subscript
3307 used to reference an element of an indexed array
3308 evaluates to a number less than zero, it is
3309 interpreted as relative to one greater than the maximum index of the array,
3310 so negative indices count back from the end of the
3311 array, and an index of \-1 references the last element.
3312 .PP
3313 Referencing an array variable without a subscript is equivalent to
3314 referencing the array with a subscript of 0.
3315 Any reference to a variable using a valid subscript is valid;
3316 .B bash
3317 creates an array if necessary.
3318 .PP
3319 An array variable is considered set if a subscript has been assigned a
3320 value.
3321 The null string is a valid value.
3322 .PP
3323 It is possible to obtain the keys (indices) of an array as well as the values.
3324 ${\fB!\fP\fIname\fP[\fI@\fP]} and ${\fB!\fP\fIname\fP[\fI*\fP]}
3325 expand to the indices assigned in array variable \fIname\fP.
3326 The treatment when in double quotes is similar to the expansion of the
3327 special parameters \fI@\fP and \fI*\fP within double quotes.
3328 .PP
3329 The
3330 .B unset
3331 builtin is used to destroy arrays.
3332 \fBunset\fP \fIname\fP[\fIsubscript\fP]
3333 unsets the array element at index \fIsubscript\fP,
3334 for both indexed and associative arrays.
3335 Negative subscripts to indexed arrays are interpreted as described above.
3336 Unsetting the last element of an array variable does not unset the variable.
3337 \fBunset\fP \fIname\fP, where \fIname\fP is an array,
3338 removes the entire array.
3339 \fBunset\fP \fIname\fP[\fIsubscript\fP]
3340 behaves differently depending on
3341 whether \fIname\fP is an indexed or associative array
3342 when \fIsubscript\fP is \fB*\fP or \fB@\fP.
3343 If \fIname\fP is an associative array, this unsets the element with
3344 subscript \fB*\fP or \fB@\fP.
3345 If \fIname\fP is an indexed array, unset removes all of the elements but
3346 does not remove the array itself.
3347 .PP
3348 When using a variable name with a subscript as an argument to a command,
3349 such as with \fBunset\fP, without using the word expansion syntax
3350 described above,
3351 (e.g., unset a[4]),
3352 the argument is subject to pathname expansion.
3353 Quote the argument if pathname expansion is not desired
3354 (e.g., unset \*'a[4]\*').
3355 .PP
3356 The
3357 .BR declare ,
3358 .BR local ,
3359 and
3360 .B readonly
3361 builtins each accept a
3362 .B \-a
3363 option to specify an indexed array and a
3364 .B \-A
3365 option to specify an associative array.
3366 If both options are supplied,
3367 .B \-A
3368 takes precedence.
3369 The
3370 .B read
3371 builtin accepts a
3372 .B \-a
3373 option to assign a list of words read from the standard input
3374 to an array.
3375 The
3376 .B set
3377 and
3378 .B declare
3379 builtins display array values in a way that allows them to be
3380 reused as assignments.
3381 Other builtins accept array name arguments as well
3382 (e.g., \fBmapfile\fP); see the descriptions
3383 of individual builtins below for details.
3384 The shell provides a number of builtin array variables.
3385 .SH EXPANSION
3386 Expansion is performed on the command line after it has been split into
3387 words. The shell performs these expansions:
3388 .IR "brace expansion" ,
3389 .IR "tilde expansion" ,
3390 .IR "parameter and variable expansion" ,
3391 .IR "command substitution" ,
3392 .IR "arithmetic expansion" ,
3393 .IR "word splitting" ,
3394 .IR "pathname expansion" ,
3395 and
3396 .IR "quote removal" .
3397 .PP
3398 The order of expansions is:
3399 brace expansion;
3400 tilde expansion, parameter and variable expansion, arithmetic expansion,
3401 and command substitution (done in a left-to-right fashion);
3402 word splitting;
3403 pathname expansion;
3404 and quote removal.
3405 .PP
3406 On systems that can support it, there is an additional expansion
3407 available: \fIprocess substitution\fP.
3408 This is performed at the
3409 same time as tilde, parameter, variable, and arithmetic expansion and
3410 command substitution.
3411 .PP
3412 \fIQuote removal\fP is always performed last.
3413 It removes quote characters present in the original word,
3414 not ones resulting from one of the other expansions,
3415 unless they have been quoted themselves.
3416 .PP
3417 Only brace expansion, word splitting, and pathname expansion
3418 can increase the number of words of the expansion; other expansions
3419 expand a single word to a single word.
3420 The only exceptions to this are the expansions of
3421 .B \&\*"$@\*"
3422 and
3423 .B \&\*"${\fIname\fP[@]}\*"\c \" keep leading \& for AT&T troff
3424 .BR \& , \" .BR + \& + \*" doesn't work with AT&T troff
3425 and, in most cases, \fB$*\fP and \fB${\fP\fIname\fP\fB[*]}\fP
3426 as explained above (see
3427 .SM
3428 .BR PARAMETERS ).
3429 .SS Brace Expansion
3430 .I "Brace expansion"
3431 is a mechanism to generate arbitrary strings
3432 sharing a common prefix and suffix, either of which can be empty.
3433 This mechanism is similar to
3434 \fIpathname expansion\fP, but the filenames generated
3435 need not exist.
3436 Patterns to be brace expanded are formed from an optional
3437 .IR preamble ,
3438 followed by either a series of comma-separated strings or
3439 a sequence expression between a pair of braces,
3440 followed by an optional
3441 .IR postscript .
3442 The preamble is prefixed to each string contained within the braces,
3443 and the postscript is then appended to each resulting string,
3444 expanding left to right.
3445 .PP
3446 Brace expansions may be nested.
3447 The results of each expanded string are not sorted;
3448 brace expansion preserves left to right order.
3449 For example, a\fB{\fPd,c,b\fB}\fPe expands into
3450 .Q "ade ace abe" .
3451 .PP
3452 A sequence expression takes the form
3453 \fIx\fP\fB..\fP\fIy\fP\fB[..\fP\fIincr\fP\fB]\fP,
3454 where \fIx\fP and \fIy\fP are either integers or single letters,
3455 and \fIincr\fP, an optional increment, is an integer.
3456 When integers are supplied, the expression expands to each number between
3457 \fIx\fP and \fIy\fP, inclusive.
3458 If either \fIx\fP or \fIy\fP begins with a zero,
3459 each generated term will contain the same number of digits,
3460 zero-padding where necessary.
3461 When letters are supplied, the expression expands to each character
3462 lexicographically between \fIx\fP and \fIy\fP, inclusive,
3463 using the C locale.
3464 Note that both \fIx\fP and \fIy\fP must be of the same type
3465 (integer or letter).
3466 When the increment is supplied, it is used as the difference between
3467 each term.
3468 The default increment is 1 or \-1 as appropriate.
3469 .PP
3470 Brace expansion is performed before any other expansions,
3471 and any characters special to other expansions are preserved
3472 in the result.
3473 It is strictly textual.
3474 .B Bash
3475 does not apply any syntactic interpretation to the context of the
3476 expansion or the text between the braces.
3477 .PP
3478 A correctly-formed brace expansion must contain unquoted opening
3479 and closing braces, and at least one unquoted comma or a valid
3480 sequence expression.
3481 Any incorrectly formed brace expansion is left unchanged.
3482 .PP
3483 A
3484 .Q {
3485 or
3486 Q ,
3487 may be quoted with a backslash to prevent its
3488 being considered part of a brace expression.
3489 To avoid conflicts with parameter expansion, the string
3490 .Q ${
3491 is not considered eligible for brace expansion,
3492 and inhibits brace expansion until the closing
3493 .Q } .
3494 .PP
3495 This construct is typically used as shorthand when the common
3496 prefix of the strings to be generated is longer than in the
3497 above example:
3498 .PP
3499 .RS
3500 .EX
3501 mkdir /usr/local/src/bash/{old,new,dist,bugs}
3502 .EE
3503 .RE
3504 or
3505 .RS
3506 .EX
3507 chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
3508 .EE
3509 .RE
3510 .PP
3511 Brace expansion introduces a slight incompatibility with
3512 historical versions of
3513 .BR sh .
3514 .B sh
3515 does not treat opening or closing braces specially when they
3516 appear as part of a word, and preserves them in the output.
3517 .B Bash
3518 removes braces from words as a consequence of brace expansion.
3519 For example, a word entered to
3520 .B sh
3521 as
3522 .Q file{1,2}
3523 appears identically in the output.
3524 .B Bash
3525 outputs that word as
3526 .Q "file1 file2"
3527 after brace expansion.
3528 Start
3529 .B bash
3530 with the
3531 .B +B
3532 option or disable brace expansion with the
3533 .B +B
3534 option to the
3535 .B set
3536 command (see
3537 .SM
3538 .B "SHELL BUILTIN COMMANDS"
3539 below) for strict \fBsh\fP compatibility.
3540 .SS Tilde Expansion
3541 If a word begins with an unquoted tilde character (\c
3542 .Q \fB\*~\fP ),
3543 all of
3544 the characters preceding the first unquoted slash (or all characters,
3545 if there is no unquoted slash) are considered a \fItilde-prefix\fP.
3546 If none of the characters in the tilde-prefix are quoted, the
3547 characters in the tilde-prefix following the tilde are treated as a
3548 possible \fIlogin name\fP.
3549 If this login name is the null string, the tilde is replaced with the
3550 value of the shell parameter
3551 .SM
3552 .BR HOME .
3553 If
3554 .SM
3555 .B HOME
3556 is unset, the tilde expands to
3557 the home directory of the user executing the shell instead.
3558 Otherwise, the tilde-prefix is replaced with the home directory
3559 associated with the specified login name.
3560 .PP
3561 If the tilde-prefix is a
3562 .Q \*~+ ,
3563 the value of the shell variable
3564 .SM
3565 .B PWD
3566 replaces the tilde-prefix.
3567 If the tilde-prefix is a
3568 .Q \*~\- ,
3569 the shell substitutes the value of the shell variable
3570 .SM
3571 .BR OLDPWD ,
3572 if it is set.
3573 If the characters following the tilde in the tilde-prefix consist
3574 of a number \fIN\fP, optionally prefixed
3575 by a
3576 .Q +
3577 or a
3578 .Q \- ,
3579 the tilde-prefix is replaced with the corresponding
3580 element from the directory stack, as it would be displayed by the
3581 .B dirs
3582 builtin invoked with the characters following the tilde in the
3583 tilde-prefix as an argument.
3584 If the characters following the tilde in the tilde-prefix consist of a
3585 number without a leading
3586 .Q +
3587 or
3588 .Q \- ,
3589 tilde expansion assumes
3590 .Q + .
3591 .PP
3592 The results of tilde expansion are treated as if they were quoted, so
3593 the replacement is not subject to word splitting and pathname expansion.
3594 .PP
3595 If the login name is invalid, or the tilde expansion fails, the
3596 tilde-prefix is unchanged.
3597 .PP
3598 \fBBash\fP checks each variable assignment
3599 for unquoted tilde-prefixes immediately
3600 following a
3601 .B :
3602 or the first
3603 .BR = ,
3604 and performs tilde expansion in these cases.
3605 Consequently, one may use filenames with tildes in assignments to
3606 .SM
3607 .BR PATH ,
3608 .SM
3609 .BR MAILPATH ,
3610 and
3611 .SM
3612 .BR CDPATH ,
3613 and the shell assigns the expanded value.
3614 .PP
3615 \fBBash\fP also performs tilde expansion on words satisfying the conditions
3616 of variable assignments (as described above under
3617 .SM
3618 .BR PARAMETERS )
3619 when they appear as arguments to simple commands.
3620 \fBBash\fP does not do this,
3621 except for the \fIdeclaration\fP commands listed above,
3622 when in posix mode.
3623 .SS Parameter Expansion
3624 The
3625 .Q \fB$\fP
3626 character introduces parameter expansion,
3627 command substitution, or arithmetic expansion.
3628 The parameter name
3629 or symbol to be expanded may be enclosed in braces, which
3630 are optional but serve to protect the variable to be expanded from
3631 characters immediately following it which could be
3632 interpreted as part of the name.
3633 .PP
3634 When braces are used, the matching ending brace is the first
3635 .Q \fB}\fP
3636 not escaped by a backslash or within a quoted string, and not within an
3637 embedded arithmetic expansion, command substitution, or parameter
3638 expansion.
3639 .PP
3640 The basic form of parameter expansion is
3641 .PP
3642 ${\fIparameter\fP}
3643 .LP
3644 which substitutes the value of \fIparameter\fP.
3645 The braces are required
3646 when
3647 .I parameter
3648 is a positional parameter with more than one digit,
3649 or when
3650 .I parameter
3651 is followed by a character which is not to be
3652 interpreted as part of its name.
3653 The \fIparameter\fP is a shell parameter as described above
3654 \fBPARAMETERS\fP) or an array reference (\fBArrays\fP).
3655 .PD
3656 .PP
3657 If the first character of \fIparameter\fP is an exclamation point (\fB!\fP),
3658 and \fIparameter\fP is not a \fInameref\fP,
3659 it introduces a level of indirection.
3660 \fBBash\fP uses the value formed by expanding the rest of
3661 \fIparameter\fP as the new \fIparameter\fP;
3662 this new parameter is then expanded and that value is used
3663 in the rest of the expansion, rather
3664 than the expansion of the original \fIparameter\fP.
3665 This is known as \fIindirect expansion\fP.
3666 The value is subject to tilde expansion,
3667 parameter expansion, command substitution, and arithmetic expansion.
3668 If \fIparameter\fP is a nameref, this expands to the name of the
3669 parameter referenced by \fIparameter\fP instead of performing the
3670 complete indirect expansion, for compatibility.
3671 The exceptions to this are the expansions of ${\fB!\fP\fIprefix\fP\fB*\fP} and
3672 ${\fB!\fP\fIname\fP[\fI@\fP]} described below.
3673 The exclamation point must immediately follow the left brace in order to
3674 introduce indirection.
3675 .PP
3676 In each of the cases below, \fIword\fP is subject to tilde expansion,
3677 parameter expansion, command substitution, and arithmetic expansion.
3678 .PP
3679 When not performing substring expansion, using the forms documented below
3680 (e.g., \fB:-\fP),
3681 \fBbash\fP tests for a parameter that is unset or null.
3682 Omitting the colon tests only for a parameter that is unset.
3683 .PP
3684 .TP
3685 ${\fIparameter\fP\fB:\-\fP\fIword\fP}
3686 \fBUse Default Values\fP. If
3687 .I parameter
3688 is unset or null, the expansion of
3689 .I word
3690 is substituted.
3691 Otherwise, the value of
3692 .I parameter
3693 is substituted.
3694 .TP
3695 ${\fIparameter\fP\fB:=\fP\fIword\fP}
3696 \fBAssign Default Values\fP.
3697 If
3698 .I parameter
3699 is unset or null, the expansion of
3700 .I word
3701 is assigned to
3702 .IR parameter ,
3703 and the expansion is the final value of
3704 .IR parameter .
3705 Positional parameters and special parameters may
3706 not be assigned in this way.
3707 .TP
3708 ${\fIparameter\fP\fB:?\fP\fIword\fP}
3709 \fBDisplay Error if Null or Unset\fP.
3710 If
3711 .I parameter
3712 is null or unset, the shell writes
3713 the expansion of \fIword\fP (or a message to that effect
3714 if
3715 .I word
3716 is not present) to the standard error and, if it
3717 is not interactive, exits with a non-zero status.
3718 An interactive shell does not exit, but does not execute the command
3719 associated with the expansion.
3720 Otherwise, the value of \fIparameter\fP is substituted.
3721 .TP
3722 ${\fIparameter\fP\fB:+\fP\fIword\fP}
3723 \fBUse Alternate Value\fP.
3724 If
3725 .I parameter
3726 is null or unset, nothing is substituted, otherwise the expansion of
3727 .I word
3728 is substituted.
3729 The value of \fIparameter\fP is not used.
3730 .TP
3731 .PD 0
3732 ${\fIparameter\fP\fB:\fP\fIoffset\fP}
3733 .TP
3734 .PD
3735 ${\fIparameter\fP\fB:\fP\fIoffset\fP\fB:\fP\fIlength\fP}
3736 \fBSubstring Expansion\fP.
3737 Expands to up to \fIlength\fP characters of the value of \fIparameter\fP
3738 starting at the character specified by \fIoffset\fP.
3739 If \fIparameter\fP is \fB@\fP or \fB*\fP, an indexed array subscripted by
3740 \fB@\fP or \fB*\fP, or an associative array name, the results differ as
3741 described below.
3742 If \fB:\fP\fIlength\fP is omitted (the first form above), this
3743 expands to the substring of the value of
3744 \fIparameter\fP starting at the character specified by \fIoffset\fP
3745 and extending to the end of the value.
3746 If \fIoffset\fP is omitted,
3747 it is treated as 0.
3748 If \fIlength\fP is omitted,
3749 but the colon after \fIoffset\fP is present,
3750 it is treated as 0.
3751 \fIlength\fP and \fIoffset\fP are arithmetic expressions (see
3752 .SM
3753 .B
3754 ARITHMETIC EVALUATION
3755 below).
3756 .IP
3757 If \fIoffset\fP evaluates to a number less than zero, the value
3758 is used as an offset in characters
3759 from the end of the value of \fIparameter\fP.
3760 If \fIlength\fP evaluates to a number less than zero,
3761 it is interpreted as an offset in characters
3762 from the end of the value of \fIparameter\fP rather than
3763 a number of characters, and the expansion is the characters between
3764 \fIoffset\fP and that result.
3765 Note that a negative offset must be separated from the colon by at least
3766 one space to avoid being confused with the \fB:-\fP expansion.
3767 .IP
3768 If \fIparameter\fP is \fB@\fP or \fB*\fP, the result is \fIlength\fP
3769 positional parameters beginning at \fIoffset\fP.
3770 A negative \fIoffset\fP is taken relative to one greater than the greatest
3771 positional parameter, so an offset of \-1 evaluates to the last positional
3772 parameter (or 0 if there are no positional parameters).
3773 It is an expansion error if \fIlength\fP evaluates to a number less than
3774 zero.
3775 .IP
3776 If \fIparameter\fP is an indexed array name subscripted by @ or *,
3777 the result is the \fIlength\fP
3778 members of the array beginning with ${\fIparameter\fP[\fIoffset\fP]}.
3779 A negative \fIoffset\fP is taken relative to one greater than the maximum
3780 index of the specified array.
3781 It is an expansion error if \fIlength\fP evaluates to a number less than
3782 zero.
3783 .IP
3784 Substring expansion applied to an associative array produces undefined
3785 results.
3786 .IP
3787 Substring indexing is zero-based unless the positional parameters
3788 are used, in which case the indexing starts at 1 by default.
3789 If \fIoffset\fP is 0, and the positional parameters are used, \fB$0\fP is
3790 prefixed to the list.
3791 .TP
3792 .PD 0
3793 ${\fB!\fP\fIprefix\fP\fB*\fP}
3794 .TP
3795 ${\fB!\fP\fIprefix\fP\fB@\fP}
3796 .PD
3797 \fBNames matching prefix\fP.
3798 Expands to the names of variables whose names begin with \fIprefix\fP,
3799 separated by the first character of the
3800 .SM
3801 .B IFS
3802 special variable.
3803 When \fI@\fP is used and the expansion appears within double quotes, each
3804 variable name expands to a separate word.
3805 .TP
3806 .PD 0
3807 ${\fB!\fP\fIname\fP[\fI@\fP]}
3808 .TP
3809 ${\fB!\fP\fIname\fP[\fI*\fP]}
3810 .PD
3811 \fBList of array keys\fP.
3812 If \fIname\fP is an array variable, expands to the list of array indices
3813 (keys) assigned in \fIname\fP.
3814 If \fIname\fP is not an array, expands to 0 if \fIname\fP is set and null
3815 otherwise.
3816 When \fI@\fP is used and the expansion appears within double quotes, each
3817 key expands to a separate word.
3818 .TP
3819 ${\fB#\fP\fIparameter\fP}
3820 \fBParameter length\fP.
3821 Substitutes the length in characters of the expanded value of \fIparameter\fP.
3822 If
3823 .I parameter
3824 is
3825 .B *
3826 or
3827 .BR @ ,
3828 the value substituted is the number of positional parameters.
3829 If
3830 .I parameter
3831 is an array name subscripted by
3832 .B *
3833 or
3834 .BR @ ,
3835 the value substituted is the number of elements in the array.
3836 If
3837 .I parameter
3838 is an indexed array name subscripted by a negative number, that number is
3839 interpreted as relative to one greater than the maximum index of
3840 \fIparameter\fP, so negative indices count back from the end of the
3841 array, and an index of \-1 references the last element.
3842 .TP
3843 .PD 0
3844 ${\fIparameter\fP\fB#\fP\fIword\fP}
3845 .TP
3846 ${\fIparameter\fP\fB##\fP\fIword\fP}
3847 .PD
3848 \fBRemove matching prefix pattern\fP.
3849 The
3850 .I word
3851 is expanded to produce a pattern just as in pathname
3852 expansion, and matched against the expanded value of
3853 .I parameter
3854 using the rules described under
3855 .B "Pattern Matching"
3856 below.
3857 If the pattern matches the beginning of
3858 the value of
3859 .IR parameter ,
3860 then the result of the expansion is the expanded value of
3861 .I parameter
3862 with the shortest matching pattern (the
3863 .Q #
3864 case) or the longest matching pattern (the
3865 .Q ##
3866 case) deleted.
3867 If
3868 .I parameter
3869 is
3870 .B @
3871 or
3872 .BR * ,
3873 the pattern removal operation is applied to each positional
3874 parameter in turn, and the expansion is the resultant list.
3875 If
3876 .I parameter
3877 is an array variable subscripted with
3878 .B @
3879 or
3880 .BR * ,
3881 the pattern removal operation is applied to each member of the
3882 array in turn, and the expansion is the resultant list.
3883 .TP
3884 .PD 0
3885 ${\fIparameter\fP\fB%\fP\fIword\fP}
3886 .TP
3887 ${\fIparameter\fP\fB%%\fP\fIword\fP}
3888 .PD
3889 \fBRemove matching suffix pattern\fP.
3890 The \fIword\fP is expanded to produce a pattern just as in
3891 pathname expansion, and matched against the expanded value of
3892 .I parameter
3893 using the rules described under
3894 .B "Pattern Matching"
3895 below.
3896 If the pattern matches a trailing portion of the expanded value of
3897 .IR parameter ,
3898 then the result of the expansion is the expanded value of
3899 .I parameter
3900 with the shortest matching pattern (the
3901 .Q %
3902 case) or the longest matching pattern (the
3903 .Q %%
3904 case) deleted.
3905 If
3906 .I parameter
3907 is
3908 .B @
3909 or
3910 .BR * ,
3911 the pattern removal operation is applied to each positional
3912 parameter in turn, and the expansion is the resultant list.
3913 If
3914 .I parameter
3915 is an array variable subscripted with
3916 .B @
3917 or
3918 .BR * ,
3919 the pattern removal operation is applied to each member of the
3920 array in turn, and the expansion is the resultant list.
3921 .TP
3922 .PD 0
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 .TP
3927 ${\fIparameter\fP\fB/#\fP\fIpattern\fP\fB/\fP\fIstring\fP}
3928 .TP
3929 ${\fIparameter\fP\fB/%\fP\fIpattern\fP\fB/\fP\fIstring\fP}
3930 .PD
3931 \fBPattern substitution\fP.
3932 The \fIpattern\fP is expanded to produce a pattern
3933 and matched against the expanded value of \fIparameter\fP
3934 as described under
3935 .B "Pattern Matching"
3936 below.
3937 The longest match of \fIpattern\fP
3938 in the expanded value is replaced with \fIstring\fP.
3939 \fIstring\fP undergoes tilde expansion, parameter and variable expansion,
3940 arithmetic expansion, command and process substitution, and quote removal.
3941 .IP
3942 In the first form above, only the first match is replaced.
3943 If there are two slashes separating \fIparameter\fP and \fIpattern\fP
3944 (the second form above), all matches of \fIpattern\fP are
3945 replaced with \fIstring\fP.
3946 If \fIpattern\fP is preceded by \fB#\fP (the third form above),
3947 it must match at the beginning of the expanded value of \fIparameter\fP.
3948 If \fIpattern\fP is preceded by \fB%\fP (the fourth form above),
3949 it must match at the end of the expanded value of \fIparameter\fP.
3950 .IP
3951 If the expansion of \fIstring\fP is null,
3952 matches of \fIpattern\fP are deleted
3953 and the \fB/\fP following \fIpattern\fP may be omitted.
3954 .IP
3955 If the \fBpatsub_replacement\fP shell option is enabled using \fBshopt\fP,
3956 any unquoted instances of \fB&\fP in \fIstring\fP are replaced with the
3957 matching portion of \fIpattern\fP.
3958 .IP
3959 Quoting any part of \fIstring\fP inhibits replacement in the
3960 expansion of the quoted portion, including replacement strings stored
3961 in shell variables.
3962 Backslash escapes \fB&\fP in \fIstring\fP; the backslash is removed
3963 in order to permit a literal \fB&\fP in the replacement string.
3964 Backslash can also be used to escape a backslash; \fB\e\e\fP results in
3965 a literal backslash in the replacement.
3966 Users should take care if \fIstring\fP is double-quoted to avoid
3967 unwanted interactions between the backslash and double-quoting, since
3968 backslash has special meaning within double quotes.
3969 Pattern substitution performs the check for unquoted \fB&\fP after
3970 expanding \fIstring\fP;
3971 shell programmers should quote any occurrences of \fB&\fP
3972 they want to be taken literally in the replacement
3973 and ensure any instances of \fB&\fP they want to be replaced are unquoted.
3974 .IP
3975 Like the pattern removal operators, double quotes surrounding the
3976 replacement string quote the expanded characters, while double quotes
3977 enclosing the entire parameter substitution do not, since
3978 the expansion is performed in a
3979 context that doesn't take any enclosing double quotes into account.
3980 .IP
3981 If the
3982 .B nocasematch
3983 shell option is enabled, the match is performed without regard to the case
3984 of alphabetic characters.
3985 .IP
3986 If
3987 .I parameter
3988 is
3989 .B @
3990 or
3991 .BR * ,
3992 the substitution operation is applied to each positional
3993 parameter in turn, and the expansion is the resultant list.
3994 If
3995 .I parameter
3996 is an array variable subscripted with
3997 .B @
3998 or
3999 .BR * ,
4000 the substitution operation is applied to each member of the
4001 array in turn, and the expansion is the resultant list.
4002 .TP
4003 .PD 0
4004 ${\fIparameter\fP\fB\*^\fP\fIpattern\fP}
4005 .TP
4006 ${\fIparameter\fP\fB\*^\*^\fP\fIpattern\fP}
4007 .TP
4008 ${\fIparameter\fP\fB,\fP\fIpattern\fP}
4009 .TP
4010 ${\fIparameter\fP\fB,,\fP\fIpattern\fP}
4011 .PD
4012 \fBCase modification\fP.
4013 This expansion modifies the case of alphabetic characters in \fIparameter\fP.
4014 First, the \fIpattern\fP is expanded to produce a pattern
4015 as described below under
4016 .SM
4017 .BR "Pattern Matching" .
4018 .B Bash
4019 then examines characters in the expanded value of \fIparameter\fP
4020 against \fIpattern\fP as described below.
4021 If a character matches the pattern, its case is converted.
4022 The pattern should not attempt to match more than one character.
4023 .IP
4024 Using
4025 .Q \*^
4026 converts lowercase letters matching \fIpattern\fP to uppercase;
4027 .Q ,
4028 converts matching uppercase letters to lowercase.
4029 The
4030 \fB\*^\fP and \fB,\fP variants
4031 examine the first character in the expanded value
4032 and convert its case if it matches \fIpattern\fP;
4033 the
4034 \fB\*^\*^\fP and \fB,,\fP variants
4035 examine all characters in the expanded value
4036 and convert each one that matches \fIpattern\fP.
4037 If \fIpattern\fP is omitted, it is treated like a \fB?\fP, which matches
4038 every character.
4039 .IP
4040 If
4041 .I parameter
4042 is
4043 .B @
4044 or
4045 .BR * ,
4046 the case modification operation is applied to each positional
4047 parameter in turn, and the expansion is the resultant list.
4048 If
4049 .I parameter
4050 is an array variable subscripted with
4051 .B @
4052 or
4053 .BR * ,
4054 the case modification operation is applied to each member of the
4055 array in turn, and the expansion is the resultant list.
4056 .TP
4057 .PD 0
4058 ${\fIparameter\fP\fB@\fP\fIoperator\fP}
4059 \fBParameter transformation\fP.
4060 The expansion is either a transformation of the value of \fIparameter\fP
4061 or information about \fIparameter\fP itself, depending on the value of
4062 \fIoperator\fP. Each \fIoperator\fP is a single letter:
4063 .PP
4064 .RS
4065 .TP
4066 .B U
4067 The expansion is a string that is the value of \fIparameter\fP with lowercase
4068 alphabetic characters converted to uppercase.
4069 .TP
4070 .B u
4071 The expansion is a string that is the value of \fIparameter\fP with the first
4072 character converted to uppercase, if it is alphabetic.
4073 .TP
4074 .B L
4075 The expansion is a string that is the value of \fIparameter\fP with uppercase
4076 alphabetic characters converted to lowercase.
4077 .TP
4078 .B Q
4079 The expansion is a string that is the value of \fIparameter\fP quoted in a
4080 format that can be reused as input.
4081 .TP
4082 .B E
4083 The expansion is a string that is the value of \fIparameter\fP with backslash
4084 escape sequences expanded as with the \fB$\*'\fP.\|.\|.\%\fB\*'\fP
4085 quoting mechanism.
4086 .TP
4087 .B P
4088 The expansion is a string that is the result of expanding the value of
4089 \fIparameter\fP as if it were a prompt string (see \fBPROMPTING\fP below).
4090 .TP
4091 .B A
4092 The expansion is a string in the form of
4093 an assignment statement or \fBdeclare\fP command that, if
4094 evaluated, recreates \fIparameter\fP with its attributes and value.
4095 .TP
4096 .B K
4097 Produces a possibly-quoted version of the value of \fIparameter\fP,
4098 except that it prints the values of
4099 indexed and associative arrays as a sequence of quoted key-value pairs
4100 (see \fBArrays\fP above).
4101 The keys and values are quoted in a format that can be reused as input.
4102 .TP
4103 .B a
4104 The expansion is a string consisting of flag values representing
4105 \fIparameter\fP's attributes.
4106 .TP
4107 .B k
4108 Like the K transformation, but expands the keys and values of
4109 indexed and associative arrays to separate words after word splitting.
4110 .PD
4111 .PP
4112 If
4113 .I parameter
4114 is
4115 .B @
4116 or
4117 .BR * ,
4118 the operation is applied to each positional
4119 parameter in turn, and the expansion is the resultant list.
4120 If
4121 .I parameter
4122 is an array variable subscripted with
4123 .B @
4124 or
4125 .BR * ,
4126 the operation is applied to each member of the
4127 array in turn, and the expansion is the resultant list.
4128 .PP
4129 The result of the expansion is subject to word splitting and pathname
4130 expansion as described below.
4131 .RE
4132 .SS Command Substitution
4133 \fICommand substitution\fP allows the output of a command to replace
4134 the command itself.
4135 There are two standard forms:
4136 .RS
4137 .PP
4138 \fB$(\fP\fIcommand\fP\|\fB)\fP
4139 .RE
4140 or (deprecated)
4141 .RS
4142 \fB\`\fP\fIcommand\fP\fB\`\fP.
4143 .RE
4144 .PP
4145 .B Bash
4146 performs the expansion by executing \fIcommand\fP in a subshell environment
4147 and replacing the command substitution with the standard output of the
4148 command, with any trailing newlines deleted.
4149 Embedded newlines are not deleted, but they may be removed during
4150 word splitting.
4151 The command substitution \fB$(cat \fIfile\fP)\fR can be replaced by
4152 the equivalent but faster \fB$(< \fIfile\fP)\fR.
4153 .PP
4154 With the old-style backquote form of substitution,
4155 backslash retains its literal meaning except when followed by
4156 .BR $ ,
4157 .BR \` ,
4158 or
4159 .BR \e .
4160 The first backquote not preceded by a backslash terminates the
4161 command substitution.
4162 When using the $(\^\fIcommand\fP\|) form, all characters between the
4163 parentheses make up the command; none are treated specially.
4164 .PP
4165 There is an alternate form of command substitution:
4166 .RS
4167 .PP
4168 \fB${\fP\fIc\fP \fIcommand\fP\fB;\fP\|\fB}\fP
4169 .RE
4170 .PP
4171 which executes \fIcommand\fP in the current execution environment
4172 and captures its output, again with trailing newlines removed.
4173 .PP
4174 The character \fIc\fP following the open brace must be a space, tab,
4175 newline, or \fB|\fP, and the close brace must be in a position
4176 where a reserved word may appear (i.e., preceded by a command terminator
4177 such as semicolon).
4178 \fBBash\fP allows the close brace to be joined to the remaining characters in
4179 the word without being followed by a shell metacharacter as a reserved
4180 word would usually require.
4181 .PP
4182 Any side effects of \fIcommand\fP take effect immediately
4183 in the current execution environment and persist in the current
4184 environment after the command completes (e.g., the \fBexit\fP builtin
4185 exits the shell).
4186 .PP
4187 This type of command substitution superficially resembles executing an
4188 unnamed shell function: local variables are created as when a shell
4189 function is executing, and the \fBreturn\fP builtin forces
4190 \fIcommand\fP to complete;
4191 however, the rest of the execution environment,
4192 including the positional parameters, is shared with the caller.
4193 .PP
4194 If the first character following the open brace
4195 is a \fB|\fP, the construct expands to the
4196 value of the \fBREPLY\fP shell variable after \fIcommand\fP executes,
4197 without removing any trailing newlines,
4198 and the standard output of \fIcommand\fP remains the same as in the
4199 calling shell.
4200 \fBBash\fP creates \fBREPLY\fP as an initially-unset local variable when
4201 \fIcommand\fP executes, and restores \fBREPLY\fP to the value it had
4202 before the command substitution after \fIcommand\fP completes,
4203 as with any local variable.
4204 .PP
4205 Command substitutions may be nested. To nest when using the backquoted form,
4206 escape the inner backquotes with backslashes.
4207 .PP
4208 If the substitution appears within double quotes, \fBbash\fP does not perform
4209 word splitting and pathname expansion on the results.
4210 .SS Arithmetic Expansion
4211 Arithmetic expansion evaluates an arithmetic expression
4212 and substitutes the result.
4213 The format for arithmetic expansion is:
4214 .RS
4215 .PP
4216 \fB$((\fP\fIexpression\fP\fB))\fP
4217 .RE
4218 .PP
4219 The
4220 .I expression
4221 undergoes the same expansions
4222 as if it were within double quotes,
4223 but unescaped double quote characters
4224 in \fIexpression\fP are not treated
4225 specially and are removed.
4226 All tokens in the expression undergo parameter and variable expansion,
4227 command substitution, and quote removal.
4228 The result is treated as the arithmetic expression to be evaluated.
4229 Since the way Bash handles double quotes
4230 can potentially result in empty strings,
4231 arithmetic expansion treats
4232 those as expressions that evaluate to 0.
4233 Arithmetic expansions may be nested.
4234 .PP
4235 The evaluation is performed according to the rules listed below under
4236 .SM
4237 .BR "ARITHMETIC EVALUATION" .
4238 If
4239 .I expression
4240 is invalid,
4241 .B bash
4242 prints a message to standard error indicating failure,
4243 does not perform the substitution,
4244 and does not execute the command associated with the expansion.
4245 .SS Process Substitution
4246 \fIProcess substitution\fP allows a process's input or output to be
4247 referred to using a filename.
4248 It takes the form of
4249 \fB<(\fP\fIlist\^\fP\fB)\fP
4250 or
4251 \fB>(\fP\fIlist\^\fP\fB)\fP.
4252 The process \fIlist\fP is run asynchronously, and its input or output
4253 appears as a filename.
4254 This filename is
4255 passed as an argument to the current command as the result of the
4256 expansion.
4257 .PP
4258 If the
4259 \fB>(\fP\fIlist\^\fP\fB)\fP form is used, writing to
4260 the file provides input for \fIlist\fP.
4261 If the
4262 \fB<(\fP\fIlist\^\fP\fB)\fP form is used, reading the file
4263 obtains the output of \fIlist\fP.
4264 No space may appear between the \fB<\fP or \fB>\fP
4265 and the left parenthesis, otherwise the construct would be interpreted
4266 as a redirection.
4267 .PP
4268 Process substitution is supported on systems that support named
4269 pipes (\fIFIFOs\fP) or the \fI/dev/fd\fP method of naming open files.
4270 .PP
4271 When available, process substitution is performed
4272 simultaneously with parameter and variable expansion,
4273 command substitution,
4274 and arithmetic expansion.
4275 .SS Word Splitting
4276 The shell scans the results of
4277 parameter expansion,
4278 command substitution,
4279 and
4280 arithmetic expansion
4281 that did not occur within double quotes for
4282 .IR "word splitting" .
4283 Words that were not expanded are not split.
4284 .PP
4285 The shell treats each character of
4286 .SM
4287 .B IFS
4288 as a delimiter,
4289 and splits the results of the other expansions into words
4290 using these characters as field terminators.
4291 .PP
4292 An \fIIFS whitespace\fP character is whitespace as defined above
4293 (see \fBDefinitions\fP) that appears in the value of
4294 .SM
4295 .BR IFS .
4296 Space, tab, and newline are always considered IFS whitespace, even
4297 if they don't appear in the locale's \fBspace\fP category.
4298 .PP
4299 If
4300 .SM
4301 .B IFS
4302 is unset, field splitting acts as if its value were
4303 .BR <space><tab><newline> ,
4304 and treats these characters as IFS whitespace.
4305 If the value of
4306 .SM
4307 .B IFS
4308 is null, no word splitting occurs,
4309 but implicit null arguments (see below) are still removed.
4310 .PP
4311 Word splitting begins by removing sequences of IFS whitespace characters
4312 from the beginning and end of the results of the previous expansions,
4313 then splits the remaining words.
4314 .PP
4315 If the value of
4316 .SM
4317 .B IFS
4318 consists solely of IFS whitespace,
4319 any sequence of IFS whitespace characters delimits a field,
4320 so a field consists of characters that are not unquoted IFS
4321 whitespace, and null fields result only from quoting.
4322 .PP
4323 If
4324 .SM
4325 .B IFS
4326 contains a non-whitespace character, then any character in
4327 the value of
4328 .SM
4329 .B IFS
4330 that is not IFS whitespace,
4331 along with any adjacent IFS whitespace characters, delimits a field.
4332 This means that adjacent non-IFS-whitespace delimiters produce a
4333 null field.
4334 A sequence of IFS whitespace characters also delimits a field.
4335 .PP
4336 Explicit null arguments (\^\fB\*"\^\*"\fP or
4337 \^\fB\*'\^\*'\fP\^) are retained
4338 and passed to commands as empty strings.
4339 Unquoted implicit null arguments, resulting from the expansion of
4340 parameters that have no values, are removed.
4341 Expanding a parameter with no value within double quotes
4342 produces a null field,
4343 which is retained and passed to a command as an empty string.
4344 .PP
4345 When a quoted null argument appears as part of a word whose expansion is
4346 non-null, word splitting removes the null argument portion,
4347 leaving the non-null expansion.
4348 That is, the word
4349 .Q "\-d\*'\^\*'"
4350 becomes
4351 .Q \-d
4352 after word splitting and null argument removal.
4353 .SS "Pathname Expansion"
4354 After word splitting,
4355 unless the
4356 .B \-f
4357 option has been set,
4358 .B bash
4359 scans each word for the characters
4360 .BR * ,
4361 .BR ? ,
4362 and
4363 .BR [ .
4364 If one of these characters appears, and is not quoted, then the word is
4365 regarded as a
4366 .IR pattern ,
4367 and replaced with a sorted list of filenames matching the pattern
4368 (see
4369 .SM
4370 .B "Pattern Matching"
4371 below)
4372 subject to the value of the \fBGLOBSORT\fP shell variable.
4373 .PP
4374 If no matching filenames are found,
4375 and the shell option
4376 .B nullglob
4377 is not enabled, the word is left unchanged.
4378 If the
4379 .B nullglob
4380 option is set, and no matches are found,
4381 the word is removed.
4382 If the
4383 .B failglob
4384 shell option is set, and no matches are found,
4385 \fBbash\fP prints an error message and does not execute the command.
4386 If the shell option
4387 .B nocaseglob
4388 is enabled, the match is performed without regard to the case
4389 of alphabetic characters.
4390 .PP
4391 When a pattern is used for pathname expansion,
4392 the character
4393 .Q .\&
4394 at the start of a name or immediately following a slash
4395 must be matched explicitly, unless the shell option
4396 .B dotglob
4397 is set.
4398 In order to match the filenames
4399 .FN .\&
4400 and
4401 .FN ..\& ,
4402 the pattern must begin with
4403 .Q .\&
4404 (for example,
4405 .Q .?\& ),
4406 even if
4407 .B dotglob
4408 is set.
4409 If the
4410 .B globskipdots
4411 shell option is enabled, the filenames
4412 .FN .\&
4413 and
4414 .FN ..\&
4415 never match, even if the pattern begins with a
4416 .Q .\& .
4417 When not matching pathnames, the
4418 .Q .\&
4419 character is not treated specially.
4420 .PP
4421 When matching a pathname, the slash character must always be
4422 matched explicitly by a slash in the pattern, but in other matching
4423 contexts it can be matched by a special pattern character as described
4424 below under
4425 .SM
4426 .BR "Pattern Matching" .
4427 .PP
4428 See the description of
4429 .B shopt
4430 below under
4431 .SM
4432 .B "SHELL BUILTIN COMMANDS"
4433 for a description of the
4434 .BR nocaseglob ,
4435 .BR nullglob ,
4436 .BR globskipdots ,
4437 .BR failglob ,
4438 and
4439 .B dotglob
4440 shell options.
4441 .PP
4442 The
4443 .SM
4444 .B GLOBIGNORE
4445 shell variable may be used to restrict the set of file names matching a
4446 .IR pattern .
4447 If
4448 .SM
4449 .B GLOBIGNORE
4450 is set, each matching file name that also matches one of the patterns in
4451 .SM
4452 .B GLOBIGNORE
4453 is removed from the list of matches.
4454 If the \fBnocaseglob\fP option is set, the matching against the patterns in
4455 .SM
4456 .B GLOBIGNORE
4457 is performed without regard to case.
4458 The filenames
4459 .FN .\&
4460 and
4461 .FN ..\&
4462 are always ignored when
4463 .SM
4464 .B GLOBIGNORE
4465 is set and not null.
4466 However, setting
4467 .SM
4468 .B GLOBIGNORE
4469 to a non-null value has the effect of enabling the
4470 .B dotglob
4471 shell option, so all other filenames beginning with a
4472 .Q .\&
4473 match.
4474 To get the old behavior of ignoring filenames beginning with a
4475 .Q .\& ,
4476 make
4477 .Q .*
4478 one of the patterns in
4479 .SM
4480 .B GLOBIGNORE\c
4481 \&.
4482 The
4483 .B dotglob
4484 option is disabled when
4485 .SM
4486 .B GLOBIGNORE
4487 is unset.
4488 The
4489 .B GLOBIGNORE
4490 pattern matching honors the setting of the \fBextglob\fP shell
4491 option.
4492 .PP
4493 The value of the
4494 .SM
4495 .B GLOBSORT
4496 shell variable controls how the results of pathname expansion are sorted,
4497 as described above under
4498 .BR "Shell Variables" .
4499 .PP
4500 .B "Pattern Matching"
4501 .PP
4502 Any character that appears in a pattern, other than the special pattern
4503 characters described below, matches itself.
4504 The NUL character may not occur in a pattern.
4505 A backslash escapes the following character; the escaping backslash is
4506 discarded when matching.
4507 The special pattern characters must be quoted if
4508 they are to be matched literally.
4509 .PP
4510 The special pattern characters have the following meanings:
4511 .PP
4512 .PD 0
4513 .RS
4514 .TP
4515 .B *
4516 Matches any string, including the null string.
4517 When the \fBglobstar\fP shell option is enabled, and \fB*\fP is used in
4518 a pathname expansion context, two adjacent \fB*\fPs used as a single
4519 pattern match all files and zero or more directories and
4520 subdirectories.
4521 If followed by a \fB/\fP, two adjacent \fB*\fPs match only directories
4522 and subdirectories.
4523 .TP
4524 .B ?
4525 Matches any single character.
4526 .TP
4527 .BR [ .\|.\|. ]
4528 .PD
4529 Matches any one of the characters enclosed between the brackets.
4530 This is known as a \fIbracket expression\fP
4531 and matches a single character.
4532 A pair of characters separated by a hyphen denotes a
4533 \fIrange expression\fP;
4534 any character that falls between those two characters, inclusive,
4535 using the current locale's collating sequence and character set, matches.
4536 If the first character following the
4537 .B [
4538 is a
4539 .B !
4540 or a
4541 .B \*^
4542 then any character not within the range matches.
4543 To match a
4544 .BR \- ,
4545 include it as the first or last character in the set.
4546 To match a
4547 .BR ] ,
4548 include it as the first character in the set.
4549 .IP
4550 The sorting order of characters in range expressions,
4551 and the characters included in the range,
4552 are determined by the current locale and the values of the
4553 .SM
4554 .B LC_COLLATE
4555 or
4556 .SM
4557 .B LC_ALL
4558 shell variables, if set.
4559 To obtain the traditional interpretation of range expressions, where
4560 .B [a\-d]
4561 is equivalent to
4562 .BR [abcd] ,
4563 set the value of the
4564 .B LC_COLLATE
4565 or
4566 .B LC_ALL
4567 shell variables to
4568 .BR C ,
4569 or enable the
4570 .B globasciiranges
4571 shell option.
4572 .IP
4573 Within a bracket expression,
4574 \fIcharacter classes\fP can be specified using the syntax
4575 \fB[:\fP\fIclass\fP\fB:]\fP, where \fIclass\fP is one of the
4576 following classes defined in the
4577 .SM POSIX
4578 standard:
4579 .IP
4580 .RS
4581 .B
4582 .if n alnum alpha ascii blank cntrl digit graph lower print punct space \
4583 upper word xdigit
4584 .if t alnum alpha ascii blank cntrl digit graph lower \
4585 print punct space upper word xdigit
4586 .RE
4587 .IP
4588 A character class matches any character belonging to that class.
4589 The \fBword\fP character class matches letters, digits, and the character _.
4590 .IP
4591 Within a bracket expression,
4592 an \fIequivalence class\fP can be specified using the syntax
4593 \fB[=\fP\fIc\fP\fB=]\fP, which matches all characters with the
4594 same collation weight (as defined by the current locale) as
4595 the character \fIc\fP.
4596 .IP
4597 Within a bracket expression,
4598 the syntax \fB[.\fP\fIsymbol\fP\fB.]\fP matches the collating symbol
4599 \fIsymbol\fP.
4600 .RE
4601 .PP
4602 If the \fBextglob\fP shell option is enabled using the \fBshopt\fP
4603 builtin, the shell recognizes several extended pattern matching operators.
4604 In the following description, a \fIpattern-list\fP is a list of one
4605 or more patterns separated by a \fB|\fP.
4606 Composite patterns may be formed using one or more of the following
4607 sub-patterns:
4608 .PP
4609 .PD 0
4610 .RS
4611 .TP
4612 \fB?(\fP\^\fIpattern-list\^\fP\fB)\fP
4613 Matches zero or one occurrence of the given patterns.
4614 .TP
4615 \fB*(\fP\^\fIpattern-list\^\fP\fB)\fP
4616 Matches zero or more occurrences of the given patterns.
4617 .TP
4618 \fB+(\fP\^\fIpattern-list\^\fP\fB)\fP
4619 Matches one or more occurrences of the given patterns.
4620 .TP
4621 \fB@(\fP\^\fIpattern-list\^\fP\fB)\fP
4622 Matches one of the given patterns.
4623 .TP
4624 \fB!(\fP\^\fIpattern-list\^\fP\fB)\fP
4625 Matches anything except one of the given patterns.
4626 .RE
4627 .PD
4628 .PP
4629 The \fBextglob\fP option changes the behavior of the parser, since the
4630 parentheses are normally treated as operators with syntactic meaning.
4631 To ensure that extended matching patterns are parsed correctly, make sure
4632 that \fBextglob\fP is enabled before parsing constructs containing the
4633 patterns, including shell functions and command substitutions.
4634 .PP
4635 When matching filenames, the \fBdotglob\fP shell option determines
4636 the set of filenames that are tested:
4637 when \fBdotglob\fP is enabled, the set of filenames includes all files
4638 beginning with
4639 .Q .\& ,
4640 but
4641 .FN .\&
4642 and
4643 .FN ..\&
4644 must be matched by a pattern or sub-pattern that begins with a dot;
4645 when it is disabled, the set does not
4646 include any filenames beginning with
4647 .Q .\&
4648 unless the pattern or sub-pattern begins with a
4649 .Q .\& .
4650 If the
4651 .B globskipdots
4652 shell option is enabled, the filenames
4653 .FN .\&
4654 and
4655 .FN ..\&
4656 never appear in the set.
4657 As above,
4658 .Q .\&
4659 only has a special meaning when matching filenames.
4660 .PP
4661 Complicated extended pattern matching against long strings is slow,
4662 especially when the patterns contain alternations and the strings
4663 contain multiple matches.
4664 Using separate matches against shorter strings, or using arrays of
4665 strings instead of a single long string, may be faster.
4666 .SS Quote Removal
4667 After the preceding expansions, all unquoted occurrences of the
4668 characters
4669 .BR \e ,
4670 .BR \*' ,
4671 and \^\fB\*"\fP\^ that did not result from one of the above
4672 expansions are removed.
4673 .SH REDIRECTION
4674 Before a command is executed, its input and output may be
4675 .I redirected
4676 using a special notation interpreted by the shell.
4677 \fIRedirection\fP allows commands' file handles to be
4678 duplicated, opened, closed,
4679 made to refer to different files,
4680 and can change the files the command reads from and writes to.
4681 When used with the \fBexec\fP builtin,
4682 redirections modify file handles in the current shell execution environment.
4683 The following redirection
4684 operators may precede or appear anywhere within a
4685 .I simple command
4686 or may follow a
4687 .IR command .
4688 Redirections are processed in the order they appear, from
4689 left to right.
4690 .PP
4691 Each redirection that may be preceded by a file descriptor number
4692 may instead be preceded by a word of the form {\fIvarname\fP}.
4693 In this case, for each redirection operator except
4694 .B >&\-
4695 and
4696 .BR <&\- ,
4697 the shell allocates a file descriptor greater
4698 than or equal to 10 and assigns it to \fIvarname\fP.
4699 If {\fIvarname\fP} precedes
4700 .B >&\-
4701 or
4702 .BR <&\- ,
4703 the value of \fIvarname\fP defines the file descriptor to close.
4704 If {\fIvarname\fP} is supplied, the redirection persists beyond
4705 the scope of the command, which allows the shell programmer to
4706 manage the file descriptor's lifetime manually without using
4707 the \fBexec\fP builtin.
4708 The \fBvarredir_close\fP shell option manages this behavior.
4709 .PP
4710 In the following descriptions, if the file descriptor number is
4711 omitted, and the first character of the redirection operator is
4712 .Q < ,
4713 the redirection refers to the standard input (file descriptor 0).
4714 If the first character of the redirection operator is
4715 .Q > ,
4716 the redirection refers to the standard output (file descriptor 1).
4717 .PP
4718 The \fIword\fP following the redirection operator in the following
4719 descriptions, unless otherwise noted, is subjected to
4720 brace expansion,
4721 tilde expansion,
4722 parameter and variable expansion,
4723 command substitution,
4724 arithmetic expansion,
4725 quote removal,
4726 pathname expansion,
4727 and word splitting.
4728 If it expands to more than one word,
4729 .B bash
4730 reports an error.
4731 .PP
4732 The order of redirections is significant.
4733 For example,
4734 the command
4735 .RS
4736 .PP
4737 ls \fB>\fP dirlist 2\fB>&\fP1
4738 .RE
4739 .PP
4740 directs both standard output and standard error to the file
4741 .IR dirlist ,
4742 while the command
4743 .RS
4744 .PP
4745 ls 2\fB>&\fP1 \fB>\fP dirlist
4746 .RE
4747 .PP
4748 directs only the standard output to file
4749 .IR dirlist ,
4750 because the standard error was directed to the standard output
4751 before the standard output was redirected to
4752 .IR dirlist .
4753 .PP
4754 \fBBash\fP handles several filenames specially when they are used in
4755 redirections, as described in the following table.
4756 If the operating system on which \fBbash\fP is running provides these
4757 special files, \fBbash\fP uses them; otherwise it emulates them
4758 internally with the behavior described below.
4759 .RS
4760 .PP
4761 .PD 0
4762 .TP
4763 .B /dev/fd/\fIfd\fP
4764 If \fIfd\fP is a valid integer, duplicate file descriptor \fIfd\fP.
4765 .TP
4766 .B /dev/stdin
4767 File descriptor 0 is duplicated.
4768 .TP
4769 .B /dev/stdout
4770 File descriptor 1 is duplicated.
4771 .TP
4772 .B /dev/stderr
4773 File descriptor 2 is duplicated.
4774 .TP
4775 .B /dev/tcp/\fIhost\fP/\fIport\fP
4776 If \fIhost\fP is a valid hostname or Internet address, and \fIport\fP
4777 is an integer port number or service name, \fBbash\fP attempts to open
4778 the corresponding TCP socket.
4779 .TP
4780 .B /dev/udp/\fIhost\fP/\fIport\fP
4781 If \fIhost\fP is a valid hostname or Internet address, and \fIport\fP
4782 is an integer port number or service name, \fBbash\fP attempts to open
4783 the corresponding UDP socket.
4784 .PD
4785 .RE
4786 .PP
4787 A failure to open or create a file causes the redirection to fail.
4788 .PP
4789 Redirections using file descriptors greater than 9 should be used with
4790 care, as they may conflict with file descriptors the shell uses
4791 internally.
4792 .SS Redirecting Input
4793 Redirecting input opens the file whose name results from
4794 the expansion of
4795 .I word
4796 for reading on file descriptor
4797 .IR n ,
4798 or the standard input (file descriptor 0) if
4799 .I n
4800 is not specified.
4801 .PP
4802 The general format for redirecting input is:
4803 .RS
4804 .PP
4805 [\fIn\fP]\fB<\fP\fIword\fP
4806 .RE
4807 .SS Redirecting Output
4808 Redirecting output opens the file whose name results from
4809 the expansion of
4810 .I word
4811 for writing on file descriptor
4812 .IR n ,
4813 or the standard output (file descriptor 1) if
4814 .I n
4815 is not specified.
4816 If the file does not exist it is created;
4817 if it does exist it is truncated to zero size.
4818 .PP
4819 The general format for redirecting output is:
4820 .RS
4821 .PP
4822 [\fIn\fP]\fB>\fP\fIword\fP
4823 .RE
4824 .PP
4825 If the redirection operator is
4826 .BR > ,
4827 and the
4828 .B noclobber
4829 option to the
4830 .B set
4831 builtin command has been enabled, the redirection fails if the file
4832 whose name results from the expansion of \fIword\fP exists and is
4833 a regular file.
4834 If the redirection operator is
4835 .BR >| ,
4836 or the redirection operator is
4837 .B >
4838 and the
4839 .B noclobber
4840 option to the
4841 .B set
4842 builtin is not enabled,
4843 \fBbash\fP attempts the redirection
4844 even if the file named by \fIword\fP exists.
4845 .SS Appending Redirected Output
4846 Redirecting output in this fashion opens
4847 the file whose name results from the expansion of
4848 .I word
4849 for appending on file descriptor
4850 .IR n ,
4851 or the standard output (file descriptor 1) if
4852 .I n
4853 is not specified.
4854 If the file does not exist it is created.
4855 .PP
4856 The general format for appending output is:
4857 .RS
4858 .PP
4859 [\fIn\fP]\fB>>\fP\fIword\fP
4860 .RE
4861 .SS Redirecting Standard Output and Standard Error
4862 This construct redirects both the
4863 standard output (file descriptor 1) and
4864 the standard error output (file descriptor 2)
4865 to the file whose name is the expansion of
4866 .IR word .
4867 .PP
4868 There are two formats for redirecting standard output and
4869 standard error:
4870 .RS
4871 .PP
4872 \fB&>\fP\fIword\fP
4873 .RE
4874 and
4875 .RS
4876 \fB>&\fP\fIword\fP
4877 .RE
4878 .PP
4879 Of the two forms, the first is preferred.
4880 This is semantically equivalent to
4881 .RS
4882 .PP
4883 \fB>\fP\fIword\fP 2\fB>&\fP1
4884 .RE
4885 .PP
4886 When using the second form, \fIword\fP may not expand to a number or
4887 \fB\-\fP.
4888 If it does, other redirection operators apply
4889 (see \fBDuplicating File Descriptors\fP below) for compatibility
4890 reasons.
4891 .SS Appending Standard Output and Standard Error
4892 This construct appends both the
4893 standard output (file descriptor 1) and
4894 the standard error output (file descriptor 2)
4895 to the file whose name is the expansion of
4896 .IR word .
4897 .PP
4898 The format for appending standard output and standard error is:
4899 .RS
4900 .PP
4901 \fB&>>\fP\fIword\fP
4902 .RE
4903 .PP
4904 This is semantically equivalent to
4905 .RS
4906 .PP
4907 \fB>>\fP\fIword\fP 2\fB>&\fP1
4908 .RE
4909 .PP
4910 (see \fBDuplicating File Descriptors\fP below).
4911 .SS Here Documents
4912 This type of redirection instructs the shell to read input from the
4913 current source until it reads a line containing only
4914 .I delimiter
4915 (with no trailing blanks).
4916 All of the lines read up to that point then become the standard
4917 input (or file descriptor \fIn\fP if \fIn\fP is specified) for a command.
4918 .PP
4919 The format of here-documents is:
4920 .RS
4921 .PP
4922 .nf
4923 [\fIn\fP]\fB<<\fP[\fB\-\fP]\fIword\fP
4924 \fIhere-document\fP
4925 \fIdelimiter\fP
4926 .fi
4927 .RE
4928 .PP
4929 The shell does not perform
4930 parameter and variable expansion, command substitution,
4931 arithmetic expansion, or pathname expansion on
4932 .IR word .
4933 .PP
4934 If any part of
4935 .I word
4936 is quoted, the
4937 .I delimiter
4938 is the result of quote removal on
4939 .IR word ,
4940 and the lines in the here-document are not expanded.
4941 If \fIword\fP is unquoted, the
4942 .I delimiter
4943 is \fIword\fP itself,
4944 and the here-document text is treated similarly to a double-quoted string:
4945 all lines of the here-document are subjected to
4946 parameter expansion, command substitution, and arithmetic expansion,
4947 the character sequence
4948 .B \e<newline>
4949 is treated literally, and
4950 .B \e
4951 must be used to quote the characters
4952 .BR \e ,
4953 .BR $ ,
4954 and
4955 .BR \` ;
4956 however, double quote characters have no special meaning.
4957 .PP
4958 If the redirection operator is
4959 .BR <<\- ,
4960 then the shell strips all leading tab characters from input lines
4961 and the line containing
4962 .IR delimiter .
4963 This allows
4964 here-documents within shell scripts to be indented in a
4965 natural fashion.
4966 .PP
4967 If the delimiter is not quoted, the
4968 .B \e<newline>
4969 sequence is treated as a line continuation: the two lines are joined
4970 and the backslash-newline is removed.
4971 This happens while reading the here-document, before the check for
4972 the ending delimiter, so joined lines can form the end delimiter.
4973 .SS "Here Strings"
4974 A variant of here documents, the format is:
4975 .RS
4976 .PP
4977 .nf
4978 [\fIn\fP]\fB<<<\fP\fIword\fP
4979 .fi
4980 .RE
4981 .PP
4982 The \fIword\fP undergoes
4983 tilde expansion, parameter and variable expansion,
4984 command substitution, arithmetic expansion, and quote removal.
4985 Pathname expansion and word splitting are not performed.
4986 The result is supplied as a single string, with a newline appended,
4987 to the command on its
4988 standard input (or file descriptor \fIn\fP if \fIn\fP is specified).
4989 .SS "Duplicating File Descriptors"
4990 The redirection operator
4991 .RS
4992 .PP
4993 [\fIn\fP]\fB<&\fP\fIword\fP
4994 .RE
4995 .PP
4996 is used to duplicate input file descriptors.
4997 If
4998 .I word
4999 expands to one or more digits, file descriptor
5000 .I n
5001 is made to be a copy of that file descriptor.
5002 It is a redirection error if the digits in
5003 .I word
5004 do not specify a file descriptor open for input.
5005 If
5006 .I word
5007 evaluates to
5008 .BR \- ,
5009 file descriptor
5010 .I n
5011 is closed.
5012 If
5013 .I n
5014 is not specified, this uses the standard input (file descriptor 0).
5015 .PP
5016 The operator
5017 .RS
5018 .PP
5019 [\fIn\fP]\fB>&\fP\fIword\fP
5020 .RE
5021 .PP
5022 is used similarly to duplicate output file descriptors.
5023 If
5024 .I n
5025 is not specified, this uses the standard output (file descriptor 1).
5026 It is a redirection error if the digits in
5027 .I word
5028 do not specify a file descriptor open for output.
5029 If
5030 .I word
5031 evaluates to
5032 .BR \- ,
5033 file descriptor
5034 .I n
5035 is closed.
5036 As a special case, if \fIn\fP is omitted,
5037 and \fIword\fP does not expand to one or more digits or \fB\-\fP,
5038 this redirects the standard output and standard error as described
5039 previously.
5040 .SS "Moving File Descriptors"
5041 The redirection operator
5042 .RS
5043 .PP
5044 [\fIn\fP]\fB<&\fP\fIdigit\fP\fB\-\fP
5045 .RE
5046 .PP
5047 moves the file descriptor \fIdigit\fP to file descriptor
5048 .IR n ,
5049 or the standard input (file descriptor 0) if \fIn\fP is not specified.
5050 \fIdigit\fP is closed after being duplicated to \fIn\fP.
5051 .PP
5052 Similarly, the redirection operator
5053 .RS
5054 .PP
5055 [\fIn\fP]\fB>&\fP\fIdigit\fP\fB\-\fP
5056 .RE
5057 .PP
5058 moves the file descriptor \fIdigit\fP to file descriptor
5059 .IR n ,
5060 or the standard output (file descriptor 1) if \fIn\fP is not specified.
5061 .SS "Opening File Descriptors for Reading and Writing"
5062 The redirection operator
5063 .RS
5064 .PP
5065 [\fIn\fP]\fB<>\fP\fIword\fP
5066 .RE
5067 .PP
5068 opens the file whose name is the expansion of
5069 .I word
5070 for both reading and writing on file descriptor
5071 .IR n ,
5072 or on file descriptor 0 if
5073 .I n
5074 is not specified.
5075 If the file does not exist, it is created.
5076 .SH ALIASES
5077 \fIAliases\fP allow a string to be substituted for a word that is in
5078 a position in the input where it can be the first word of a simple
5079 command.
5080 Aliases have names and corresponding values that are set
5081 and unset using the \fBalias\fP and \fBunalias\fP builtin commands
5082 (see
5083 .SM
5084 .B "SHELL BUILTIN COMMANDS"
5085 below).
5086 .PP
5087 If the shell reads an unquoted word in the right position, it checks
5088 the word to see if it matches an alias name.
5089 If it matches, the shell
5090 replaces the word with the alias value, and reads that value as if it
5091 had been read instead of the word.
5092 The shell doesn't look at any characters following the word before
5093 attempting alias substitution.
5094 .PP
5095 The characters \fB/\fP, \fB$\fP, \fB\`\fP, and \fB=\fP and
5096 any of the shell \fImetacharacters\fP or quoting characters
5097 listed above may not appear in an alias name.
5098 The replacement text may contain any valid shell input,
5099 including shell metacharacters.
5100 The first word of the replacement text is tested
5101 for aliases, but a word that is identical to an alias being expanded
5102 is not expanded a second time.
5103 This means that one may alias
5104 .B ls
5105 to
5106 .BR "ls \-F" ,
5107 for instance, and
5108 .B bash
5109 does not try to recursively expand the replacement text.
5110 .PP
5111 If the last character of the alias value is a
5112 .IR blank ,
5113 the shell checks the next command
5114 word following the alias for alias expansion.
5115 .PP
5116 Aliases are created and listed with the
5117 .B alias
5118 command, and removed with the
5119 .B unalias
5120 command.
5121 .PP
5122 There is no mechanism for using arguments in the replacement text.
5123 If arguments are needed, use a shell function (see
5124 .SM
5125 .B FUNCTIONS
5126 below) instead.
5127 .PP
5128 Aliases are not expanded when the shell is not interactive, unless
5129 the
5130 .B expand_aliases
5131 shell option is set using
5132 .B shopt
5133 (see the description of
5134 .B shopt
5135 under
5136 .SM
5137 .B "SHELL BUILTIN COMMANDS"
5138 below).
5139 .PP
5140 The rules concerning the definition and use of aliases are
5141 somewhat confusing.
5142 .B Bash
5143 always reads at least one complete line of input,
5144 and all lines that make up a compound command,
5145 before executing any of the commands on that line or the compound command.
5146 Aliases are expanded when a command is read, not when it is executed.
5147 Therefore, an
5148 alias definition appearing on the same line as another
5149 command does not take effect until the shell reads the next line of input,
5150 and an alias definition in a compound command does not take
5151 effect until the shell parses and executes the entire compound command.
5152 The commands following the alias definition
5153 on that line,
5154 or in the rest of a compound command,
5155 are not affected by the new alias.
5156 This behavior is also an issue when functions are executed.
5157 Aliases are expanded when a function definition is read,
5158 not when the function is executed, because a function definition
5159 is itself a command.
5160 As a consequence, aliases
5161 defined in a function are not available until after that
5162 function is executed.
5163 To be safe, always put
5164 alias definitions on a separate line, and do not use
5165 .B alias
5166 in compound commands.
5167 .PP
5168 For almost every purpose, shell functions are preferable to aliases.
5169 .SH FUNCTIONS
5170 A shell function, defined as described above under
5171 .SM
5172 .BR "SHELL GRAMMAR" ,
5173 stores a series of commands for later execution.
5174 When the name of a shell function is used as a simple command name,
5175 the shell executes
5176 the list of commands associated with that function name.
5177 Functions are executed in the context of the
5178 calling shell; there is no new process created to interpret
5179 them (contrast this with the execution of a shell script).
5180 .PP
5181 When a function is executed, the arguments to the
5182 function become the positional parameters
5183 during its execution.
5184 The special parameter
5185 .B #
5186 is updated to reflect the new positional parameters.
5187 Special parameter \fB0\fP is unchanged.
5188 The first element of the
5189 .SM
5190 .B FUNCNAME
5191 variable is set to the name of the function while the function
5192 is executing.
5193 .PP
5194 All other aspects of the shell execution
5195 environment are identical between a function and its caller
5196 with these exceptions: the
5197 .SM
5198 .B DEBUG
5199 and
5200 .B RETURN
5201 traps (see the description of the
5202 .B trap
5203 builtin under
5204 .SM
5205 .B "SHELL BUILTIN COMMANDS"
5206 below) are not inherited unless the function has been given the
5207 \fBtrace\fP attribute (see the description of the
5208 .SM
5209 .B declare
5210 builtin below) or the
5211 \fB\-o functrace\fP shell option has been enabled with
5212 the \fBset\fP builtin
5213 (in which case all functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps),
5214 and the
5215 .SM
5216 .B ERR
5217 trap is not inherited unless the \fB\-o errtrace\fP shell option has
5218 been enabled.
5219 .PP
5220 Variables local to the function are declared with the
5221 .B local
5222 builtin command (\fIlocal variables\fP).
5223 Ordinarily, variables and their values
5224 are shared between the function and its caller.
5225 If a variable is declared \fBlocal\fP, the variable's visible scope
5226 is restricted to that function and its children (including the functions
5227 it calls).
5228 .PP
5229 In the following description, the \fIcurrent scope\fP is a currently-
5230 executing function.
5231 Previous scopes consist of that function's caller and so on,
5232 back to the
5233 .Q global
5234 scope, where the shell is not executing any shell function.
5235 A local variable at the current scope is a variable
5236 declared using the \fBlocal\fP or \fBdeclare\fP builtins in the
5237 function that is currently executing.
5238 .PP
5239 Local variables
5240 .Q shadow
5241 variables with the same name declared at previous scopes.
5242 For instance, a local variable declared in a function
5243 hides variables with the same name declared at previous scopes,
5244 including global variables: references and assignments
5245 refer to the local variable, leaving the variables
5246 at previous scopes unmodified.
5247 When the function returns, the global variable is once again visible.
5248 .PP
5249 The shell uses \fIdynamic scoping\fP to control a variable's visibility
5250 within functions.
5251 With dynamic scoping, visible variables and their values
5252 are a result of the sequence of function calls that caused execution
5253 to reach the current function.
5254 The value of a variable that a function sees depends
5255 on its value within its caller, if any, whether that caller is
5256 the global
5257 scope or another shell function.
5258 This is also the value that a local variable
5259 declaration shadows,
5260 and the value that is restored when the function returns.
5261 .PP
5262 For example, if a variable \fIvar\fP is declared as local in function
5263 \fIfunc1\fP, and \fIfunc1\fP calls another function \fIfunc2\fP,
5264 references to \fIvar\fP made from within \fIfunc2\fP resolve to the
5265 local variable \fIvar\fP from \fIfunc1\fP, shadowing any global variable
5266 named \fIvar\fP.
5267 .PP
5268 The \fBunset\fP builtin also acts using the same dynamic scope: if a
5269 variable is local to the current scope, \fBunset\fP unsets it;
5270 otherwise the unset will refer to the variable found in any calling scope
5271 as described above.
5272 If a variable at the current local scope is unset, it remains so
5273 (appearing as unset)
5274 until it is reset in that scope or until the function returns.
5275 Once the function returns, any instance of the variable at a previous
5276 scope becomes visible.
5277 If the unset acts on a variable at a previous scope, any instance of a
5278 variable with that name that had been shadowed becomes visible
5279 (see below how the \fBlocalvar_unset\fP shell option changes this behavior).
5280 .PP
5281 The
5282 .SM
5283 .B FUNCNEST
5284 variable, if set to a numeric value greater
5285 than 0, defines a maximum function nesting level.
5286 Function invocations that exceed the limit cause the entire command to
5287 abort.
5288 .PP
5289 If the builtin command
5290 .B return
5291 is executed in a function, the function completes and
5292 execution resumes with the next command after the function
5293 call.
5294 If \fBreturn\fP is supplied a numeric argument,
5295 that is the function's return status; otherwise the function's
5296 return status is the exit status of the last command executed
5297 before the \fBreturn\fP.
5298 Any command associated with the \fBRETURN\fP trap is executed
5299 before execution resumes.
5300 When a function completes, the values of the
5301 positional parameters and the special parameter
5302 .B #
5303 are restored to the values they had prior to the function's
5304 execution.
5305 .PP
5306 The
5307 .B \-f
5308 option to the
5309 .B declare
5310 or
5311 .B typeset
5312 builtin commands
5313 lists function names and definitions.
5314 The
5315 .B \-F
5316 option to
5317 .B declare
5318 or
5319 .B typeset
5320 lists the function names only
5321 (and optionally the source file and line number, if the \fBextdebug\fP
5322 shell option is enabled).
5323 Functions may be exported so that child shell processes
5324 (those created when executing a separate shell invocation)
5325 automatically have them defined with the
5326 .B \-f
5327 option to the
5328 .B export
5329 builtin.
5330 The \fB\-f\fP option to
5331 the
5332 .B unset
5333 builtin deletes a function definition.
5334 .PP
5335 Functions may be recursive.
5336 The \fBFUNCNEST\fP variable may be used to limit the depth of the
5337 function call stack and restrict the number of function invocations.
5338 By default, \fBbash\fP imposes no limit on the number of recursive calls.
5339 .SH "ARITHMETIC EVALUATION"
5340 The shell allows arithmetic expressions to be evaluated, under
5341 certain circumstances
5342 (see the \fBlet\fP and \fBdeclare\fP builtin commands,
5343 the \fB((\fP compound command,
5344 the arithmetic \fBfor\fP command,
5345 the \fB[[\fP conditional command,
5346 and \fBArithmetic Expansion\fP).
5347 .PP
5348 Evaluation is done in the largest fixed-width integers available,
5349 with no check for overflow,
5350 though division by 0 is trapped and flagged as an error.
5351 The operators and their precedence, associativity, and values
5352 are the same as in the C language.
5353 The following list of operators is grouped into levels of
5354 equal-precedence operators.
5355 The levels are listed in order of decreasing precedence.
5356 .PP
5357 .PD 0
5358 .TP
5359 .B \fIid\fP++ \fIid\fP\-\-
5360 variable post-increment and post-decrement
5361 .TP
5362 .B ++\fIid\fP \-\-\fIid\fP
5363 variable pre-increment and pre-decrement
5364 .TP
5365 .B \- +
5366 unary minus and plus
5367 .TP
5368 .B ! \*~
5369 logical and bitwise negation
5370 .TP
5371 .B **
5372 exponentiation
5373 .TP
5374 .B * / %
5375 multiplication, division, remainder
5376 .TP
5377 .B + \-
5378 addition, subtraction
5379 .TP
5380 .B << >>
5381 left and right bitwise shifts
5382 .TP
5383 .B <= >= < >
5384 comparison
5385 .TP
5386 .B == !=
5387 equality and inequality
5388 .TP
5389 .B &
5390 bitwise AND
5391 .TP
5392 .B \*^
5393 bitwise exclusive OR
5394 .TP
5395 .B |
5396 bitwise OR
5397 .TP
5398 .B &&
5399 logical AND
5400 .TP
5401 .B ||
5402 logical OR
5403 .TP
5404 .B \fIexpr\fP?\fIexpr\fP:\fIexpr\fP
5405 conditional operator
5406 .TP
5407 .B "= *= /= %= += \-= <<= >>= &= \*^= |="
5408 assignment
5409 .TP
5410 .B \fIexpr1\fP , \fIexpr2\fP
5411 comma
5412 .PD
5413 .PP
5414 Shell variables are allowed as operands; parameter expansion is
5415 performed before the expression is evaluated.
5416 Within an expression, shell variables may also be referenced by name
5417 without using the parameter expansion syntax.
5418 This means you can use "x", where \fIx\fP is a shell variable name,
5419 in an arithmetic expression, and the shell will evaluate its value as
5420 an expression and use the result.
5421 A shell variable that is null or unset evaluates to 0 when referenced
5422 by name in an expression.
5423 .PP
5424 The value of a variable is evaluated as an arithmetic expression
5425 when it is referenced, or when a variable which has been given the
5426 \fIinteger\fP attribute using \fBdeclare \-i\fP is assigned a value.
5427 A null value evaluates to 0.
5428 A shell variable need not have its \fIinteger\fP attribute
5429 turned on to be used in an expression.
5430 .PP
5431 Integer constants follow the C language definition, without suffixes or
5432 character constants.
5433 Constants with a leading 0 are interpreted as octal numbers.
5434 A leading 0x or 0X denotes hexadecimal.
5435 Otherwise, numbers take the form [\fIbase#\fP]n, where the optional \fIbase\fP
5436 is a decimal number between 2 and 64 representing the arithmetic
5437 base, and \fIn\fP is a number in that base.
5438 If \fIbase#\fP is omitted, then base 10 is used.
5439 When specifying \fIn\fP,
5440 if a non-digit is required,
5441 the digits greater than 9 are represented by the lowercase letters,
5442 the uppercase letters, @, and _, in that order.
5443 If \fIbase\fP is less than or equal to 36, lowercase and uppercase
5444 letters may be used interchangeably to represent numbers between 10
5445 and 35.
5446 .PP
5447 Operators are evaluated in precedence order.
5448 Sub-expressions in parentheses are evaluated first
5449 and may override the precedence rules above.
5450 .SH "CONDITIONAL EXPRESSIONS"
5451 Conditional expressions are used by the \fB[[\fP compound command and
5452 the \fBtest\fP and \fB[\fP builtin commands to test file attributes
5453 and perform string and arithmetic comparisons.
5454 The \fBtest\fP and \fB[\fP commands determine their behavior based on
5455 the number of arguments; see the descriptions of those commands for any
5456 other command-specific actions.
5457 .PP
5458 Expressions are formed from the unary or binary primaries listed below.
5459 Unary expressions are often used to examine the status of a file
5460 or shell variable.
5461 Binary operators are used for string, numeric, and file attribute
5462 comparisons.
5463 .PP
5464 \fBBash\fP handles several filenames specially when they are used in
5465 expressions.
5466 If the operating system on which \fBbash\fP is running provides these
5467 special files, bash will use them; otherwise it will emulate them
5468 internally with this behavior:
5469 If any \fIfile\fP argument to one of the primaries is of the form
5470 .FN /dev/fd/n ,
5471 then \fBbash\fP checks file descriptor \fIn\fP.
5472 If the \fIfile\fP argument to one of the primaries is one of
5473 .FN /dev/stdin ,
5474 .FN /dev/stdout ,
5475 or
5476 .FN /dev/stderr ,
5477 \fBbash\fP checks file descriptor 0, 1, or 2, respectively.
5478 .PP
5479 Unless otherwise specified, primaries that operate on files follow symbolic
5480 links and operate on the target of the link, rather than the link itself.
5481 .PP
5482 When used with \fB[[\fP,
5483 or when the shell is in posix mode,
5484 the \fB<\fP and \fB>\fP operators sort
5485 lexicographically using the current locale.
5486 When the shell is not in posix mode,
5487 the \fBtest\fP command sorts using ASCII ordering.
5488 .PP
5489 .PD 0
5490 .TP
5491 .B \-a \fIfile\fP
5492 True if \fIfile\fP exists.
5493 .TP
5494 .B \-b \fIfile\fP
5495 True if \fIfile\fP exists and is a block special file.
5496 .TP
5497 .B \-c \fIfile\fP
5498 True if \fIfile\fP exists and is a character special file.
5499 .TP
5500 .B \-d \fIfile\fP
5501 True if \fIfile\fP exists and is a directory.
5502 .TP
5503 .B \-e \fIfile\fP
5504 True if \fIfile\fP exists.
5505 .TP
5506 .B \-f \fIfile\fP
5507 True if \fIfile\fP exists and is a regular file.
5508 .TP
5509 .B \-g \fIfile\fP
5510 True if \fIfile\fP exists and is set-group-id.
5511 .TP
5512 .B \-h \fIfile\fP
5513 True if \fIfile\fP exists and is a symbolic link.
5514 .TP
5515 .B \-k \fIfile\fP
5516 True if \fIfile\fP exists and its
5517 .Q sticky
5518 bit is set.
5519 .TP
5520 .B \-p \fIfile\fP
5521 True if \fIfile\fP exists and is a named pipe (FIFO).
5522 .TP
5523 .B \-r \fIfile\fP
5524 True if \fIfile\fP exists and is readable.
5525 .TP
5526 .B \-s \fIfile\fP
5527 True if \fIfile\fP exists and has a size greater than zero.
5528 .TP
5529 .B \-t \fIfd\fP
5530 True if file descriptor
5531 .I fd
5532 is open and refers to a terminal.
5533 .TP
5534 .B \-u \fIfile\fP
5535 True if \fIfile\fP exists and its set-user-id bit is set.
5536 .TP
5537 .B \-w \fIfile\fP
5538 True if \fIfile\fP exists and is writable.
5539 .TP
5540 .B \-x \fIfile\fP
5541 True if \fIfile\fP exists and is executable.
5542 .TP
5543 .B \-G \fIfile\fP
5544 True if \fIfile\fP exists and is owned by the effective group id.
5545 .TP
5546 .B \-L \fIfile\fP
5547 True if \fIfile\fP exists and is a symbolic link.
5548 .TP
5549 .B \-N \fIfile\fP
5550 True if \fIfile\fP exists and has been modified since it was last
5551 accessed.
5552 .TP
5553 .B \-O \fIfile\fP
5554 True if \fIfile\fP exists and is owned by the effective user id.
5555 .TP
5556 .B \-S \fIfile\fP
5557 True if \fIfile\fP exists and is a socket.
5558 .TP
5559 .B \-o \fIoptname\fP
5560 True if the shell option
5561 .I optname
5562 is enabled.
5563 See the list of options under the description of the
5564 .B \-o
5565 option to the
5566 .B set
5567 builtin below.
5568 .TP
5569 .B \-v \fIvarname\fP
5570 True if the shell variable
5571 .I varname
5572 is set (has been assigned a value).
5573 If \fIvarname\fP is an indexed
5574 array variable name subscripted by \fI@\fP or \fI*\fP,
5575 this returns true if the array has any set elements.
5576 If \fIvarname\fP is an associative
5577 array variable name subscripted by \fI@\fP or \fI*\fP,
5578 this returns true if an element with that key is set.
5579 .TP
5580 .B \-R \fIvarname\fP
5581 True if the shell variable
5582 .I varname
5583 is set and is a name reference.
5584 .TP
5585 .B \-z \fIstring\fP
5586 True if the length of \fIstring\fP is zero.
5587 .TP
5588 \fIstring\fP
5589 .TP
5590 .B \-n \fIstring\fP
5591 True if the length of
5592 .I string
5593 is non-zero.
5594 .PD
5595 .TP
5596 \fIstring1\fP \fB==\fP \fIstring2\fP
5597 .PD 0
5598 .TP
5599 \fIstring1\fP \fB=\fP \fIstring2\fP
5600 True if the strings are equal.
5601 \fB=\fP should be used with the \fBtest\fP command for
5602 .SM POSIX
5603 conformance.
5604 When used with the \fB[[\fP command, this performs pattern matching as
5605 described above (\fBCompound Commands\fP).
5606 .TP
5607 \fIstring1\fP \fB!=\fP \fIstring2\fP
5608 True if the strings are not equal.
5609 .TP
5610 \fIstring1\fP \fB<\fP \fIstring2\fP
5611 True if \fIstring1\fP sorts before \fIstring2\fP lexicographically.
5612 .TP
5613 \fIstring1\fP \fB>\fP \fIstring2\fP
5614 True if \fIstring1\fP sorts after \fIstring2\fP lexicographically.
5615 .PD
5616 .TP
5617 .PD 0
5618 \fIfile1\fP \fB\-ef\fP \fIfile2\fP
5619 True if \fIfile1\fP and \fIfile2\fP refer to the same device and
5620 inode numbers.
5621 .TP
5622 \fIfile1\fP \-\fBnt\fP \fIfile2\fP
5623 True if \fIfile1\fP is newer (according to modification date) than \fIfile2\fP,
5624 or if \fIfile1\fP exists and \fPfile2\fP does not.
5625 .TP
5626 \fIfile1\fP \-\fBot\fP \fIfile2\fP
5627 True if \fIfile1\fP is older than \fIfile2\fP, or if \fIfile2\fP exists
5628 and \fIfile1\fP does not.
5629 .PD
5630 .TP
5631 .I \fIarg1\fP \fBOP\fP \fIarg2\fP
5632 .SM
5633 .B OP
5634 is one of
5635 .BR \-eq ,
5636 .BR \-ne ,
5637 .BR \-lt ,
5638 .BR \-le ,
5639 .BR \-gt ,
5640 or
5641 .BR \-ge .
5642 These arithmetic binary operators return true if \fIarg1\fP
5643 is equal to, not equal to, less than, less than or equal to,
5644 greater than, or greater than or equal to \fIarg2\fP, respectively.
5645 .I arg1
5646 and
5647 .I arg2
5648 may be positive or negative integers.
5649 When used with the \fB[[\fP command,
5650 .I arg1
5651 and
5652 .I arg2
5653 are evaluated as arithmetic expressions (see
5654 .SM
5655 .B "ARITHMETIC EVALUATION"
5656 above).
5657 Since the expansions the \fB[[\fP command performs on
5658 .I arg1
5659 and
5660 .I arg2
5661 can potentially result in empty strings,
5662 arithmetic expression evaluation treats
5663 those as expressions that evaluate to 0.
5664 .PD
5665 .SH "SIMPLE COMMAND EXPANSION"
5666 When the shell executes a simple command, it performs the following
5667 expansions, assignments, and redirections, from left to right, in
5668 the following order.
5669 .IP 1.
5670 The words that the parser has marked as variable assignments (those
5671 preceding the command name) and redirections are saved for later
5672 processing.
5673 .IP 2.
5674 The words that are not variable assignments or redirections are
5675 expanded.
5676 If any words remain after expansion, the first word
5677 is taken to be the name of the command and the remaining words are
5678 the arguments.
5679 .IP 3.
5680 Redirections are performed as described above under
5681 .SM
5682 .BR REDIRECTION .
5683 .IP 4.
5684 The text after the \fB=\fP in each variable assignment undergoes tilde
5685 expansion, parameter expansion, command substitution, arithmetic expansion,
5686 and quote removal before being assigned to the variable.
5687 .PP
5688 If no command name results, the variable assignments affect the current
5689 shell environment.
5690 In the case of such a command (one that consists only of assignment
5691 statements and redirections), assignment statements are performed before
5692 redirections.
5693 Otherwise, the variables are added to the environment
5694 of the executed command and do not affect the current shell environment.
5695 If any of the assignments attempts to assign a value to a readonly variable,
5696 an error occurs, and the command exits with a non-zero status.
5697 .PP
5698 If no command name results, redirections are performed, but do not
5699 affect the current shell environment.
5700 A redirection error causes the command to exit with a non-zero status.
5701 .PP
5702 If there is a command name left after expansion, execution proceeds as
5703 described below.
5704 Otherwise, the command exits.
5705 If one of the expansions contained a command substitution,
5706 the exit status of the command is the exit status of
5707 the last command substitution performed.
5708 If there were no command substitutions,
5709 the command exits with a zero status.
5710 .SH "COMMAND EXECUTION"
5711 After a command has been split into words, if it results in a
5712 simple command and an optional list of arguments, the shell performs
5713 the following actions.
5714 .PP
5715 If the command name contains no slashes, the shell attempts to
5716 locate it.
5717 If there exists a shell function by that name, that function is
5718 invoked as described above in
5719 .SM
5720 .BR FUNCTIONS .
5721 If the name does not match a function, the shell searches for
5722 it in the list of shell builtins.
5723 If a match is found, that builtin is invoked.
5724 .PP
5725 If the name is neither a shell function nor a builtin,
5726 and contains no slashes,
5727 .B bash
5728 searches each element of the
5729 .SM
5730 .B PATH
5731 for a directory containing an executable file by that name.
5732 .B Bash
5733 uses a hash table to remember the full pathnames of executable
5734 files (see
5735 .B hash
5736 under
5737 .SM
5738 .B "SHELL BUILTIN COMMANDS"
5739 below).
5740 Bash performs a full search of the directories in
5741 .SM
5742 .B PATH
5743 only if the command is not found in the hash table.
5744 If the search is unsuccessful, the shell searches for a defined shell
5745 function named \fBcommand_not_found_handle\fP.
5746 If that function exists, it is invoked in a separate execution environment
5747 with the original command and
5748 the original command's arguments as its arguments, and the function's
5749 exit status becomes the exit status of that subshell.
5750 If that function is not defined, the shell prints an error
5751 message and returns an exit status of 127.
5752 .PP
5753 If the search is successful, or if the command name contains
5754 one or more slashes, the shell executes the named program in a
5755 separate execution environment.
5756 Argument 0 is set to the name given, and the remaining arguments
5757 to the command are set to the arguments given, if any.
5758 .PP
5759 If this execution fails because the file is not in executable
5760 format, and the file is not a directory, it is assumed to be
5761 a \fIshell script\fP, a file containing shell commands,
5762 and the shell creates a new instance of itself to execute it.
5763 Bash tries to determine whether the file is a text file or a binary,
5764 and will not execute files it determines to be binaries.
5765 This subshell reinitializes itself, so
5766 that the effect is as if a new shell had been invoked
5767 to handle the script, with the exception that the locations of
5768 commands remembered by the parent (see
5769 .B hash
5770 below under
5771 .SM
5772 .B "SHELL BUILTIN COMMANDS"
5773 are retained by the child.
5774 .PP
5775 If the program is a file beginning with
5776 .BR #! ,
5777 the remainder of the first line specifies an interpreter
5778 for the program.
5779 The shell executes the
5780 specified interpreter on operating systems that do not
5781 handle this executable format themselves.
5782 The arguments to the
5783 interpreter consist of a single optional argument following the
5784 interpreter name on the first line of the program, followed
5785 by the name of the program, followed by the command
5786 arguments, if any.
5787 .SH "COMMAND EXECUTION ENVIRONMENT"
5788 The shell has an \fIexecution environment\fP, which consists of the
5789 following:
5790 .IP \(bu
5791 Open files inherited by the shell at invocation, as modified by
5792 redirections supplied to the \fBexec\fP builtin.
5793 .IP \(bu
5794 The current working directory as set by \fBcd\fP, \fBpushd\fP, or
5795 \fBpopd\fP, or inherited by the shell at invocation.
5796 .IP \(bu
5797 The file creation mode mask as set by \fBumask\fP or inherited from
5798 the shell's parent.
5799 .IP \(bu
5800 Current traps set by \fBtrap\fP.
5801 .IP \(bu
5802 Shell parameters that are set by variable assignment or with \fBset\fP
5803 or inherited from the shell's parent in the environment.
5804 .IP \(bu
5805 Shell functions defined during execution or inherited from the shell's
5806 parent in the environment.
5807 .IP \(bu
5808 Options enabled at invocation (either by default or with command-line
5809 arguments) or by \fBset\fP.
5810 .IP \(bu
5811 Options enabled by \fBshopt\fP.
5812 .IP \(bu
5813 Shell aliases defined with \fBalias\fP.
5814 .IP \(bu
5815 Various process IDs, including those of background jobs, the value
5816 of \fB$$\fP, and the value of
5817 .SM
5818 .BR PPID .
5819 .PP
5820 When a simple command other than a builtin or shell function
5821 is to be executed, it
5822 is invoked in a separate execution environment that consists of
5823 the following.
5824 Unless otherwise noted, the values are inherited from the shell.
5825 .IP \(bu
5826 The shell's open files, plus any modifications and additions specified
5827 by redirections to the command.
5828 .IP \(bu
5829 The current working directory.
5830 .IP \(bu
5831 The file creation mode mask.
5832 .IP \(bu
5833 Shell variables and functions marked for export, along with variables
5834 exported for the command, passed in the environment.
5835 .IP \(bu
5836 Traps caught by the shell are reset to the values inherited from the
5837 shell's parent, and traps ignored by the shell are ignored.
5838 .PP
5839 A command invoked in this separate environment cannot affect the
5840 shell's execution environment.
5841 .PP
5842 A \fIsubshell\fP is a copy of the shell process.
5843 .PP
5844 Command substitution, commands grouped with parentheses,
5845 and asynchronous commands are invoked in a
5846 subshell environment that is a duplicate of the shell environment,
5847 except that traps caught by the shell are reset to the values
5848 that the shell inherited from its parent at invocation.
5849 Builtin commands that are invoked as part of a pipeline,
5850 except possibly in the last element depending on the value of the
5851 \fBlastpipe\fP shell option,
5852 are also executed in a subshell environment.
5853 Changes made to the subshell environment
5854 cannot affect the shell's execution environment.
5855 .PP
5856 When the shell is in posix mode,
5857 subshells spawned to execute command substitutions inherit the value of
5858 the \fB\-e\fP option from their parent shell.
5859 When not in posix mode,
5860 \fBbash\fP clears the \fB\-e\fP option in such subshells.
5861 See the
5862 description of the \fBinherit_errexit\fP shell option below
5863 for how to control this behavior when not in posix mode.
5864 .PP
5865 If a command is followed by a \fB&\fP and job control is not active, the
5866 default standard input for the command is the empty file
5867 .FN /dev/null .
5868 Otherwise, the invoked command inherits the file descriptors of the calling
5869 shell as modified by redirections.
5870 .SH ENVIRONMENT
5871 When a program is invoked it is given an array of strings
5872 called the
5873 .IR environment .
5874 This is a list of
5875 \fIname\fP\-\fIvalue\fP pairs, of the form
5876 .IR "name\fR=\fPvalue" .
5877 .PP
5878 The shell provides several ways to manipulate the environment.
5879 On invocation, the shell scans its own environment and
5880 creates a parameter for each name found, automatically marking
5881 it for
5882 .I export
5883 to child processes.
5884 Executed commands inherit the environment.
5885 The
5886 .BR export ,
5887 .BR "declare \-x" ,
5888 and
5889 .B unset
5890 commands modify the environment by
5891 adding and deleting parameters and functions.
5892 If the value of a parameter
5893 in the environment is modified, the new value automatically
5894 becomes part of the environment, replacing the old.
5895 The environment
5896 inherited by any executed command consists of the shell's
5897 initial environment, whose values may be modified in the shell,
5898 less any pairs removed by the
5899 .B unset
5900 or
5901 .B "export \-n"
5902 commands, plus any additions via the
5903 .B export
5904 and
5905 .B "declare \-x"
5906 commands.
5907 .PP
5908 If any parameter assignments, as described above in
5909 .SM
5910 .BR PARAMETERS ,
5911 appear before a
5912 .IR "simple command" ,
5913 the variable assignments are part of that command's environment
5914 for as long as it executes.
5915 These assignment statements affect only the environment seen
5916 by that command.
5917 If these assignments precede a call to a shell function, the variables
5918 are local to the function and exported to that function's children.
5919 .PP
5920 If the
5921 .B \-k
5922 option is set (see the
5923 .B set
5924 builtin command below), then
5925 .I all
5926 parameter assignments are placed in the environment for a command,
5927 not just those that precede the command name.
5928 .PP
5929 When
5930 .B bash
5931 invokes an external command, the variable
5932 .B _
5933 is set to the full pathname of the command and passed to that
5934 command in its environment.
5935 .SH "EXIT STATUS"
5936 The exit status of an executed command is the value returned by the
5937 \fIwaitpid\fP system call or equivalent function.
5938 Exit statuses fall between 0 and 255, though, as explained below,
5939 the shell may use values above 125 specially.
5940 Exit statuses from shell builtins and compound commands are also
5941 limited to this range.
5942 Under certain circumstances, the shell will use special values to
5943 indicate specific failure modes.
5944 .PP
5945 For the shell's purposes, a command which exits with a
5946 zero exit status has succeeded.
5947 So while an exit status of zero indicates success, a non-zero
5948 exit status indicates failure.
5949 .PP
5950 When a command terminates on a fatal signal \fIN\fP, \fBbash\fP uses
5951 the value of 128+\fIN\fP as the exit status.
5952 .PP
5953 If a command is not found, the child process created to
5954 execute it returns a status of 127. If a command is found
5955 but is not executable, the return status is 126.
5956 .PP
5957 If a command fails because of an error during expansion or redirection,
5958 the exit status is greater than zero.
5959 .PP
5960 Shell builtin commands return a status of 0 (\fItrue\fP) if
5961 successful, and non-zero (\fIfalse\fP) if an error occurs
5962 while they execute.
5963 All builtins return an exit status of 2 to indicate incorrect usage,
5964 generally invalid options or missing arguments.
5965 .PP
5966 The exit status of the last command is available in the special
5967 parameter $?.
5968 .PP
5969 \fBBash\fP itself returns the exit status of the last command
5970 executed, unless a syntax error occurs, in which case it exits
5971 with a non-zero value.
5972 See also the \fBexit\fP builtin command below.
5973 .SH SIGNALS
5974 When \fBbash\fP is interactive, in the absence of any traps, it ignores
5975 .SM
5976 .B SIGTERM
5977 (so that \fBkill 0\fP does not kill an interactive shell),
5978 and catches and handles
5979 .SM
5980 .B SIGINT
5981 (so that the \fBwait\fP builtin is interruptible).
5982 When \fBbash\fP receives
5983 .SM
5984 .BR SIGINT ,
5985 it breaks out of any executing loops.
5986 In all cases, \fBbash\fP ignores
5987 .SM
5988 .BR SIGQUIT .
5989 If job control is in effect,
5990 .B bash
5991 ignores
5992 .SM
5993 .BR SIGTTIN ,
5994 .SM
5995 .BR SIGTTOU ,
5996 and
5997 .SM
5998 .BR SIGTSTP .
5999 .PP
6000 The \fBtrap\fP builtin modifies the shell's signal handling, as
6001 described below.
6002 .PP
6003 Non-builtin commands \fBbash\fP executes have signal handlers
6004 set to the values inherited by the shell from its parent,
6005 unless \fBtrap\fP sets them to be ignored, in which case the child
6006 process will ignore them as well.
6007 When job control is not in effect, asynchronous commands
6008 ignore
6009 .SM
6010 .B SIGINT
6011 and
6012 .SM
6013 .B SIGQUIT
6014 in addition to these inherited handlers.
6015 Commands run as a result of command substitution ignore the
6016 keyboard-generated job control signals
6017 .SM
6018 .BR SIGTTIN ,
6019 .SM
6020 .BR SIGTTOU ,
6021 and
6022 .SM
6023 .BR SIGTSTP .
6024 .PP
6025 The shell exits by default upon receipt of a
6026 .SM
6027 .BR SIGHUP .
6028 Before exiting, an interactive shell resends the
6029 .SM
6030 .B SIGHUP
6031 to all jobs, running or stopped.
6032 The shell sends
6033 .SM
6034 .B SIGCONT
6035 to stopped jobs to ensure that they receive the
6036 .SM
6037 .B SIGHUP
6038 (see
6039 .SM
6040 .B "JOB CONTROL"
6041 below for more information about running and stopped jobs).
6042 To prevent the shell from
6043 sending the signal to a particular job, remove it from the
6044 jobs table with the
6045 .B disown
6046 builtin (see
6047 .SM
6048 .B "SHELL BUILTIN COMMANDS"
6049 below) or mark it not to receive
6050 .SM
6051 .B SIGHUP
6052 using
6053 .BR "disown \-h" .
6054 .PP
6055 If the
6056 .B huponexit
6057 shell option has been set using
6058 .BR shopt ,
6059 .B bash
6060 sends a
6061 .SM
6062 .B SIGHUP
6063 to all jobs when an interactive login shell exits.
6064 .PP
6065 If \fBbash\fP is waiting for a command to complete and receives a signal
6066 for which a trap has been set,
6067 it will not execute the trap until the command completes.
6068 If \fBbash\fP is waiting for an asynchronous command via the \fBwait\fP
6069 builtin,
6070 and it receives a signal for which a trap has been set,
6071 the \fBwait\fP builtin will return immediately with an exit status
6072 greater than 128, immediately after which the shell executes the trap.
6073 .PP
6074 When job control is not enabled, and \fBbash\fP is waiting for a foreground
6075 command to complete, the shell receives keyboard-generated signals
6076 such as
6077 .SM
6078 .B SIGINT
6079 (usually generated by \fB\*^C\fP) that users commonly intend to send
6080 to that command.
6081 This happens because the shell and the command are in the
6082 same process group as the terminal, and \fB\*^C\fP sends
6083 .SM
6084 .B SIGINT
6085 to all processes in that process group.
6086 Since \fBbash\fP does not enable job control by default when the
6087 shell is not interactive,
6088 this scenario is most common in non-interactive shells.
6089 .PP
6090 When job control is enabled, and \fBbash\fP is waiting for a foreground
6091 command to complete, the shell does not receive keyboard-generated
6092 signals, because it is not in the same process group as the terminal.
6093 This scenario is most common in interactive shells, where \fBbash\fP
6094 attempts to enable job control by default.
6095 See
6096 .SM
6097 .B "JOB CONTROL"
6098 below for more information about process groups.
6099 .PP
6100 When job control is not enabled, and \fBbash\fP receives
6101 .SM
6102 .B SIGINT
6103 while waiting for a foreground command, it waits until that foreground
6104 command terminates and then decides what to do about the
6105 .SM
6106 .BR SIGINT :
6107 .IP 1.
6108 If the command terminates due to the
6109 .SM
6110 .BR SIGINT ,
6111 \fBbash\fP concludes
6112 that the user meant to send the
6113 .SM
6114 .B SIGINT
6115 to the shell as well, and acts on the
6116 .SM
6117 .B SIGINT
6118 (e.g., by running a
6119 .SM
6120 .B SIGINT
6121 trap,
6122 exiting a non-interactive shell,
6123 or returning to the top level to read a new command).
6124 .IP 2.
6125 If the command does not terminate due to
6126 .SM
6127 .BR SIGINT ,
6128 the program handled the
6129 .SM
6130 .B SIGINT
6131 itself and did not treat it as a fatal signal.
6132 In that case, \fBbash\fP does not treat
6133 .SM
6134 .B SIGINT
6135 as a fatal signal, either, instead assuming that the
6136 .SM
6137 .B SIGINT
6138 was used as part of the program's normal operation
6139 (e.g., emacs uses it to abort editing
6140 commands) or deliberately discarded.
6141 However, \fBbash\fP will run any
6142 trap set on
6143 .SM
6144 .BR SIGINT ,
6145 as it does with any other trapped signal it
6146 receives while it is waiting for the foreground command to
6147 complete, for compatibility.
6148 .PP
6149 When job control is enabled, \fBbash\fP does not receive keyboard-generated
6150 signals such as
6151 .SM
6152 .B SIGINT
6153 while it is waiting for a foreground command.
6154 An interactive shell does not pay attention to the
6155 .SM
6156 .BR SIGINT ,
6157 even if the foreground command terminates as a result, other than noting
6158 its exit status.
6159 If the shell is not interactive, and
6160 the foreground command terminates due to the
6161 .SM
6162 .BR SIGINT ,
6163 \fBbash\fP pretends it received the
6164 .SM
6165 .B SIGINT
6166 itself (scenario 1 above), for compatibility.
6167 .SH "JOB CONTROL"
6168 .I Job control
6169 refers to the ability to selectively stop (\fIsuspend\fP)
6170 the execution of processes and continue (\fIresume\fP)
6171 their execution at a later point.
6172 A user typically employs
6173 this facility via an interactive interface supplied jointly
6174 by the operating system kernel's terminal driver and
6175 .BR bash .
6176 .PP
6177 The shell associates a
6178 .I job
6179 with each pipeline.
6180 It keeps a table of currently executing
6181 jobs, which the
6182 .B jobs
6183 command will display.
6184 Each job has a \fIjob number\fP, which \fBjobs\fP displays between brackets.
6185 Job numbers start at 1.
6186 When
6187 .B bash
6188 starts a job asynchronously (in the
6189 .IR background ),
6190 it prints a line that looks like:
6191 .RS
6192 .PP
6193 [1] 25647
6194 .RE
6195 .PP
6196 indicating that this job is job number 1 and that the process ID
6197 of the last process in the pipeline associated with this job is 25647.
6198 All of the processes in a single pipeline are members of the same job.
6199 .B Bash
6200 uses the
6201 .I job
6202 abstraction as the basis for job control.
6203 .PP
6204 To facilitate the implementation of the user interface to job control,
6205 each process has a \fIprocess group ID\fP, and
6206 the operating system maintains the notion of a \fIcurrent terminal
6207 process group ID\fP.
6208 This terminal process group ID is associated with the
6209 \fIcontrolling terminal\fP.
6210 .PP
6211 Processes that have the same process group ID are said to be part of
6212 the same \fIprocess group\fP.
6213 Members of the \fIforeground\fP process group (processes whose
6214 process group ID is equal to the current terminal process group ID)
6215 receive keyboard-generated signals such as
6216 .SM
6217 .BR SIGINT .
6218 Processes in the foreground process group are said to be
6219 .I foreground
6220 processes.
6221 .I Background
6222 processes are those whose process group ID differs from the
6223 controlling terminal's;
6224 such processes are immune to keyboard-generated signals.
6225 Only foreground processes are allowed to read from or,
6226 if the user so specifies with
6227 .Q "stty tostop" ,
6228 write to the controlling terminal.
6229 The system sends a
6230 .SM
6231 .B "SIGTTIN (SIGTTOU)"
6232 signal to background processes which attempt to
6233 read from (write to when
6234 .Q tostop
6235 is in effect)
6236 the terminal,
6237 which, unless caught, suspends the process.
6238 .PP
6239 If the operating system on which
6240 .B bash
6241 is running supports
6242 job control,
6243 .B bash
6244 contains facilities to use it.
6245 Typing the
6246 .I suspend
6247 character (typically
6248 .BR \*^Z ,
6249 Control-Z) while a process is running
6250 stops that process and returns control to
6251 .BR bash .
6252 Typing the
6253 .I "delayed suspend"
6254 character (typically
6255 .BR \*^Y ,
6256 Control-Y) causes the process stop when it
6257 attempts to read input from the terminal, and returns control to
6258 .BR bash .
6259 The user then manipulates the state of this job, using the
6260 .B bg
6261 command to continue it in the background, the
6262 .B fg
6263 command to continue it in the foreground, or the
6264 .B kill
6265 command to kill it.
6266 The suspend character takes effect immediately,
6267 and has the additional side effect of discarding any pending output
6268 and typeahead.
6269 To force a background process to stop, or stop a process
6270 that's not associated with the current terminal session,
6271 send it the
6272 .SM
6273 .B SIGSTOP
6274 signal using \fBkill\fP.
6275 .PP
6276 There are a number of ways to refer to a job in the shell.
6277 The
6278 .B %
6279 character introduces a job specification (jobspec).
6280 .PP
6281 Job number
6282 .I n
6283 may be referred to as
6284 .BR %n .
6285 A job may also be referred to using a prefix of the name used to
6286 start it, or using a substring that appears in its command line.
6287 For example,
6288 .B %ce
6289 refers to a job whose command name begins with
6290 .BR ce .
6291 Using
6292 .BR %?ce ,
6293 on the other hand, refers to any job containing the string
6294 .B ce
6295 in its command line.
6296 If the prefix or substring matches more than one job,
6297 .B bash
6298 reports an error.
6299 .PP
6300 The symbols
6301 .B %%
6302 and
6303 .B %+
6304 refer to the shell's notion of the
6305 .IR "current job" .
6306 A single % (with no accompanying job specification) also refers to the
6307 current job.
6308 .B %\-
6309 refers to the
6310 .IR "previous job" .
6311 When a job starts in the background,
6312 a job stops while in the foreground,
6313 or a job is resumed in the background,
6314 it becomes the current job.
6315 The job that was the current job becomes the previous job.
6316 When the current job terminates, the previous job becomes the
6317 current job.
6318 If there is only a single job, \fB%+\fP and \fB%\-\fP can both be used
6319 to refer to that job.
6320 In output pertaining to jobs (e.g., the output of the
6321 .B jobs
6322 command), the current job is always marked with a
6323 .BR + ,
6324 and the previous job with a
6325 .BR \- .
6326 .PP
6327 Simply naming a job can be used to bring it into the foreground:
6328 .B %1
6329 is a synonym for
6330 .Q "fg %1" ,
6331 bringing job 1 from the background into the foreground.
6332 Similarly,
6333 .Q "%1 &"
6334 resumes job 1 in the background, equivalent to
6335 .Q "bg %1" .
6336 .PP
6337 The shell learns immediately whenever a job changes state.
6338 Normally,
6339 .B bash
6340 waits until it is about to print a prompt before
6341 notifying the user about
6342 changes in a job's status so as to not interrupt
6343 any other output,
6344 though it will notify of changes in a job's status after a
6345 foreground command in
6346 a list completes, before executing the next command in the list.
6347 If the
6348 .B \-b
6349 option to the
6350 .B set
6351 builtin command
6352 is enabled,
6353 .B bash
6354 reports status changes immediately.
6355 \fBBash\fP executes any trap on
6356 .SM
6357 .B SIGCHLD
6358 for each child that terminates.
6359 .PP
6360 When a job terminates and \fBbash\fP notifies the user about it,
6361 \fBbash\fP removes the job from the table.
6362 It will not appear in \fBjobs\fP output, but \fBwait\fP will
6363 report its exit status, as long as it's supplied the process ID
6364 associated with the job as an argument.
6365 When the table is empty, job numbers start over at 1.
6366 .PP
6367 If a user attempts to exit
6368 .B bash
6369 while jobs are stopped (or, if the \fBcheckjobs\fP shell option has
6370 been enabled using the \fBshopt\fP builtin, running), the shell prints a
6371 warning message, and, if the \fBcheckjobs\fP option is enabled, lists the
6372 jobs and their statuses.
6373 The
6374 .B jobs
6375 command may then be used to inspect their status.
6376 If the user immediately attempts to exit again,
6377 without an intervening command,
6378 \fBbash\fP does not print another warning, and
6379 terminates any stopped jobs.
6380 .PP
6381 When the shell is waiting for a job or process using the \fBwait\fP
6382 builtin, and job control is enabled, \fBwait\fP will return when the
6383 job changes state.
6384 The \fB\-f\fP option causes \fBwait\fP to wait
6385 until the job or process terminates before returning.
6386 .SH PROMPTING
6387 When executing interactively,
6388 .B bash
6389 displays the primary prompt
6390 .SM
6391 .B PS1
6392 when it is ready to read a command, and the secondary prompt
6393 .SM
6394 .B PS2
6395 when it needs more input to complete a command.
6396 .PP
6397 .B Bash
6398 examines the value of the array variable \fBPROMPT_COMMAND\fP just before
6399 printing each primary prompt.
6400 If any elements in \fBPROMPT_COMMAND\fP are set and non-null, Bash
6401 executes each value, in numeric order,
6402 just as if it had been typed on the command line.
6403 .B Bash
6404 displays
6405 .SM
6406 .B PS0
6407 after it reads a command but before executing it.
6408 .PP
6409 .B Bash
6410 displays
6411 .SM
6412 .B PS4
6413 as described above
6414 before tracing each command when the \fB\-x\fP option is enabled.
6415 .PP
6416 .B Bash
6417 allows the prompt strings
6418 \fBPS0\fP, \fBPS1\fP, \fBPS2\fP, and \fBPS4\fP,
6419 to be customized by inserting a number of
6420 backslash-escaped special characters that are decoded as follows:
6421 .RS
6422 .TP
6423 .B \ea
6424 An ASCII bell character (07).
6425 .PD 0
6426 .TP
6427 .B \ed
6428 The date in
6429 .Q "Weekday Month Date"
6430 format (e.g.,
6431 .Q "Tue May 26" ).
6432 .TP
6433 .B \eD{\fIformat\fP}
6434 The \fIformat\fP is passed to
6435 .IR strftime (3)
6436 and the result is inserted
6437 into the prompt string; an empty \fIformat\fP results in a locale-specific
6438 time representation.
6439 The braces are required.
6440 .TP
6441 .B \ee
6442 An ASCII escape character (033).
6443 .TP
6444 .B \eh
6445 The hostname up to the first
6446 .Q . .
6447 .TP
6448 .B \eH
6449 The hostname.
6450 .TP
6451 .B \ej
6452 The number of jobs currently managed by the shell.
6453 .TP
6454 .B \el
6455 The basename of the shell's terminal device name (e.g.,
6456 .Q ttys0 ).
6457 .TP
6458 .B \en
6459 A newline.
6460 .TP
6461 .B \er
6462 A carriage return.
6463 .TP
6464 .B \es
6465 The name of the shell: the basename of
6466 .B $0
6467 (the portion following the final slash).
6468 .TP
6469 .B \et
6470 The current time in 24-hour HH:MM:SS format.
6471 .TP
6472 .B \eT
6473 The current time in 12-hour HH:MM:SS format.
6474 .TP
6475 .B \e@
6476 The current time in 12-hour am/pm format.
6477 .TP
6478 .B \eA
6479 The current time in 24-hour HH:MM format.
6480 .TP
6481 .B \eu
6482 The username of the current user.
6483 .TP
6484 .B \ev
6485 The \fBbash\fP version (e.g., 2.00).
6486 .TP
6487 .B \eV
6488 The \fBbash\fP release, version + patch level (e.g., 2.00.0)
6489 .TP
6490 .B \ew
6491 The value of the \fBPWD\fP shell variable (\fB$PWD\fP),
6492 with
6493 .SM
6494 .B $HOME
6495 abbreviated with a tilde
6496 (uses the value of the
6497 .SM
6498 .B PROMPT_DIRTRIM
6499 variable).
6500 .TP
6501 .B \eW
6502 The basename of \fB$PWD\fP,
6503 with
6504 .SM
6505 .B $HOME
6506 abbreviated with a tilde.
6507 .TP
6508 .B \e!
6509 The history number of this command.
6510 .TP
6511 .B \e#
6512 The command number of this command.
6513 .TP
6514 .B \e$
6515 If the effective UID is 0, a
6516 .BR # ,
6517 otherwise a
6518 .BR $ .
6519 .TP
6520 .B \e\fInnn\fP
6521 The character corresponding to the octal number \fInnn\fP.
6522 .TP
6523 .B \e\e
6524 A backslash.
6525 .TP
6526 .B \e[
6527 Begin a sequence of non-printing characters, which could be used to
6528 embed a terminal control sequence into the prompt.
6529 .TP
6530 .B \e]
6531 End a sequence of non-printing characters.
6532 .PD
6533 .RE
6534 .PP
6535 The command number and the history number are usually different:
6536 the history number of a command is its position in the history
6537 list, which may include commands restored from the history file
6538 (see
6539 .SM
6540 .B HISTORY
6541 below), while the command number is the position in the sequence
6542 of commands executed during the current shell session.
6543 After the string is decoded, it is expanded via
6544 parameter expansion, command substitution, arithmetic
6545 expansion, and quote removal, subject to the value of the
6546 .B promptvars
6547 shell option (see the description of the
6548 .B shopt
6549 command under
6550 .SM
6551 .B "SHELL BUILTIN COMMANDS"
6552 below).
6553 This can have unwanted side effects if escaped portions of the string
6554 appear within command substitution or contain characters special to
6555 word expansion.
6556 .SH READLINE
6557 This is the library that handles reading input when using an interactive
6558 shell, unless the
6559 .B \-\-noediting
6560 option is supplied at shell invocation.
6561 Line editing is also used when using the \fB\-e\fP option to the
6562 \fBread\fP builtin.
6563 By default, the line editing commands are similar to those of emacs;
6564 a vi-style line editing interface is also available.
6565 Line editing can be enabled at any time using the
6566 .B \-o emacs
6567 or
6568 .B \-o vi
6569 options to the
6570 .B set
6571 builtin (see
6572 .SM
6573 .B "SHELL BUILTIN COMMANDS"
6574 below).
6575 To turn off line editing after the shell is running, use the
6576 .B +o emacs
6577 or
6578 .B +o vi
6579 options to the
6580 .B set
6581 builtin.
6582 .SS "Readline Notation"
6583 This section uses Emacs-style editing concepts and uses its
6584 notation for keystrokes.
6585 Control keys are denoted by C\-\fIkey\fP, e.g., C\-n means Control\-N.
6586 Similarly,
6587 .I meta
6588 keys are denoted by M\-\fIkey\fP, so M\-x means Meta\-X.
6589 The Meta key is often labeled
6590 .Q Alt
6591 or
6592 .Q Option .
6593 .PP
6594 On keyboards without a
6595 .I Meta
6596 key, M\-\fIx\fP means ESC \fIx\fP,
6597 i.e., press and release the Escape key,
6598 then press and release the
6599 .I x
6600 key, in sequence.
6601 This makes ESC the \fImeta prefix\fP.
6602 The combination M\-C\-\fIx\fP means ESC Control\-\fIx\fP:
6603 press and release the Escape key,
6604 then press and hold the Control key while pressing the
6605 .I x
6606 key, then release both.
6607 .PP
6608 On some keyboards, the Meta key modifier produces characters with
6609 the eighth bit (0200) set.
6610 You can use the \fBenable\-meta\-key\fP variable
6611 to control whether or not it does this, if the keyboard allows it.
6612 On many others, the terminal or terminal emulator converts the metafied
6613 key to a key sequence beginning with ESC as described in the
6614 preceding paragraph.
6615 .PP
6616 If your \fIMeta\fP key produces a key sequence with the ESC meta prefix,
6617 you can make M-\fIkey\fP key bindings you specify (see
6618 .B "Readline Key Bindings"
6619 below) do the same thing by setting the \fBforce\-meta\-prefix\fP variable.
6620 .PP
6621 .B Readline
6622 commands may be given numeric
6623 .IR arguments ,
6624 which normally act as a repeat count.
6625 Sometimes, however, it is the sign of the argument that is significant.
6626 Passing a negative argument
6627 to a command that acts in the forward direction (e.g., \fBkill\-line\fP)
6628 makes that command act in a backward direction.
6629 Commands whose behavior with arguments deviates from this are noted
6630 below.
6631 .PP
6632 The \fIpoint\fP is the current cursor position, and \fImark\fP refers
6633 to a saved cursor position.
6634 The text between the point and mark is referred to as the \fIregion\fP.
6635 \fBReadline\fP has the concept of an \fIactive region\fP:
6636 when the region is active, \fBreadline\fP redisplay
6637 highlights the region using the
6638 value of the \fBactive-region-start-color\fP variable.
6639 The \fBenable\-active\-region\fP variable turns this on and off.
6640 Several commands set the region to active; those are noted below.
6641 .PP
6642 When a command is described as \fIkilling\fP text, the text
6643 deleted is saved for possible future retrieval
6644 (\fIyanking\fP).
6645 The killed text is saved in a \fIkill ring\fP.
6646 Consecutive kills accumulate the deleted text
6647 into one unit, which can be yanked all at once.
6648 Commands which do not kill text separate the chunks of text
6649 on the kill ring.
6650 .SS "Readline Initialization"
6651 .B Readline
6652 is customized by putting commands in an initialization
6653 file (the \fIinputrc\fP file).
6654 The name of this file is taken from the value of the
6655 .SM
6656 .B \%INPUTRC
6657 shell variable.
6658 If that variable is unset, the default is
6659 .FN \*~/.inputrc .
6660 If that file does not exist or cannot be read, \fBreadline\fP looks for
6661 .FN /etc/inputrc .
6662 When a program that uses the \fBreadline\fP library starts up,
6663 \fBreadline\fP reads the initialization file
6664 and sets the key bindings and variables found there,
6665 before reading any user input.
6666 .PP
6667 There are only a few basic constructs allowed in the inputrc file.
6668 Blank lines are ignored.
6669 Lines beginning with a \fB#\fP are comments.
6670 Lines beginning with a \fB$\fP indicate conditional constructs.
6671 Other lines denote key bindings and variable settings.
6672 .PP
6673 The default key-bindings in this section
6674 may be changed using key binding commands in the
6675 .I inputrc
6676 file.
6677 Programs that use the \fBreadline\fP library, including \fBbash\fP,
6678 may add their own commands and bindings.
6679 .PP
6680 For example, placing
6681 .RS
6682 .PP
6683 M\-Control\-u: universal\-argument
6684 .RE
6685 or
6686 .RS
6687 C\-Meta\-u: universal\-argument
6688 .RE
6689 .LP
6690 into the
6691 .I inputrc
6692 would make M\-C\-u execute the \fBreadline\fP command
6693 .IR universal\-argument .
6694 .PP
6695 Key bindings may contain the following symbolic character names:
6696 .IR DEL ,
6697 .IR ESC ,
6698 .IR ESCAPE ,
6699 .IR LFD ,
6700 .IR NEWLINE ,
6701 .IR RET ,
6702 .IR RETURN ,
6703 .I RUBOUT
6704 (a destructive backspace),
6705 .IR SPACE ,
6706 .IR SPC ,
6707 and
6708 .IR TAB .
6709 .PP
6710 In addition to command names, \fBreadline\fP allows keys to be bound
6711 to a string that is inserted when the key is pressed (a \fImacro\fP).
6712 The difference between a macro and a command is that a macro is
6713 enclosed in single or double quotes.
6714 .SS "Readline Key Bindings"
6715 The syntax for controlling key bindings in the
6716 .I inputrc
6717 file is simple.
6718 All that is required is the name of the command or the text of a macro
6719 and a key sequence to which it should be bound.
6720 The key sequence may be specified in one of two ways:
6721 as a symbolic key name,
6722 possibly with \fIMeta\-\fP or \fIControl\-\fP prefixes,
6723 or as a key sequence composed of one or more characters
6724 enclosed in double quotes.
6725 The key sequence and name are separated by a colon.
6726 There can be no whitespace between the name and the colon.
6727 .PP
6728 When using the form \fBkeyname\fP:\^\fIfunction\-name\fP or \fImacro\fP,
6729 .I keyname
6730 is the name of a key spelled out in English. For example:
6731 .PP
6732 .RS
6733 .EX
6734 .nf
6735 Control-u: universal\-argument
6736 Meta-Rubout: backward\-kill\-word
6737 Control-o: \*"> output\*"
6738 .fi
6739 .EE
6740 .RE
6741 .LP
6742 In the above example,
6743 .I C\-u
6744 is bound to the function
6745 .BR universal\-argument ,
6746 .I M\-DEL
6747 is bound to the function
6748 .BR backward\-kill\-word ,
6749 and
6750 .I C\-o
6751 is bound to run the macro
6752 expressed on the right hand side (that is, to insert the text
6753 .Q "> output"
6754 into the line).
6755 .PP
6756 In the second form,
6757 \fB\*"keyseq\*"\fP:\^\fIfunction\-name\fP or \fImacro\fP,
6758 .B keyseq
6759 differs from
6760 .B keyname
6761 above in that strings denoting
6762 an entire key sequence may be specified by placing the sequence
6763 within double quotes.
6764 Some GNU Emacs style key escapes can be
6765 used, as in the following example, but none of
6766 the symbolic character names are recognized.
6767 .PP
6768 .RS
6769 .EX
6770 .nf
6771 \*"\eC\-u\*": universal\-argument
6772 \*"\eC\-x\eC\-r\*": re\-read\-init\-file
6773 \*"\ee[11\*~\*": \*"Function Key 1\*"
6774 .fi
6775 .EE
6776 .RE
6777 .PP
6778 In this example,
6779 .I C\-u
6780 is again bound to the function
6781 .BR universal\-argument .
6782 .I "C\-x C\-r"
6783 is bound to the function
6784 .BR re\-read\-init\-file ,
6785 and
6786 .I "ESC [ 1 1 \*~"
6787 is bound to insert the text
6788 .Q "Function Key 1" .
6789 .PP
6790 The full set of GNU Emacs style escape sequences available when specifying
6791 key sequences is
6792 .RS
6793 .PD 0
6794 .TP
6795 .B \eC\-
6796 A control prefix.
6797 .TP
6798 .B \eM\-
6799 Adding the meta prefix or converting the following character to a meta
6800 character, as described below under \fBforce-meta-prefix\fP.
6801 .TP
6802 .B \ee
6803 An escape character.
6804 .TP
6805 .B \e\e
6806 Backslash.
6807 .TP
6808 .B \e\*"
6809 Literal \*", a double quote.
6810 .TP
6811 .B \e\*'
6812 Literal \*', a single quote.
6813 .RE
6814 .PD
6815 .PP
6816 In addition to the GNU Emacs style escape sequences, a second
6817 set of backslash escapes is available:
6818 .RS
6819 .PD 0
6820 .TP
6821 .B \ea
6822 alert (bell)
6823 .TP
6824 .B \eb
6825 backspace
6826 .TP
6827 .B \ed
6828 delete
6829 .TP
6830 .B \ef
6831 form feed
6832 .TP
6833 .B \en
6834 newline
6835 .TP
6836 .B \er
6837 carriage return
6838 .TP
6839 .B \et
6840 horizontal tab
6841 .TP
6842 .B \ev
6843 vertical tab
6844 .TP
6845 .B \e\fInnn\fP
6846 The eight-bit character whose value is the octal value \fInnn\fP
6847 (one to three digits).
6848 .TP
6849 .B \ex\fIHH\fP
6850 The eight-bit character whose value is the hexadecimal value \fIHH\fP
6851 (one or two hex digits).
6852 .RE
6853 .PD
6854 .PP
6855 When entering the text of a macro, single or double quotes must
6856 be used to indicate a macro definition.
6857 Unquoted text is assumed to be a function name.
6858 The backslash escapes described above are expanded
6859 in the macro body.
6860 Backslash quotes any other character in the macro text,
6861 including \*" and \*'.
6862 .PP
6863 .B Bash
6864 will display or modify the current \fBreadline\fP key bindings with the
6865 .B bind
6866 builtin command.
6867 The
6868 .B \-o emacs
6869 or
6870 .B \-o vi
6871 options to the
6872 .B set
6873 builtin
6874 (see
6875 .SM
6876 .B "SHELL BUILTIN COMMANDS"
6877 below)
6878 change the editing mode during interactive use.
6879 .SS "Readline Variables"
6880 \fBReadline\fP has variables that can be used to further customize its
6881 behavior.
6882 A variable may be set in the
6883 .I inputrc
6884 file with a statement of the form
6885 .RS
6886 .PP
6887 \fBset\fP \fIvariable\-name\fP \fIvalue\fP
6888 .RE
6889 or using the \fBbind\fP builtin command (see
6890 .SM
6891 .B "SHELL BUILTIN COMMANDS"
6892 below).
6893 .PP
6894 Except where noted, \fBreadline\fP variables can take the values
6895 .B On
6896 or
6897 .B Off
6898 (without regard to case).
6899 Unrecognized variable names are ignored.
6900 When \fBreadline\fP reads a variable value, empty or null values,
6901 .Q "on"
6902 (case-insensitive), and
6903 .Q 1
6904 are equivalent to \fBOn\fP.
6905 All other values are equivalent to
6906 \fBOff\fP.
6907 .PP
6908 The \fBbind \-V\fP command lists the current \fBreadline\fP variable names
6909 and values (see
6910 .SM
6911 .B "SHELL BUILTIN COMMANDS"
6912 below).
6913 .PP
6914 The variables and their default values are:
6915 .PP
6916 .PD 0
6917 .TP
6918 .B active\-region\-start\-color
6919 A string variable that controls the text color and background when displaying
6920 the text in the active region (see the description of
6921 \fBenable\-active\-region\fP below).
6922 This string must not take up any physical character positions on the display,
6923 so it should consist only of terminal escape sequences.
6924 It is output to the terminal before displaying the text in the active region.
6925 This variable is reset to the default value whenever the terminal type changes.
6926 The default value is the string that puts the terminal in standout mode,
6927 as obtained from the terminal's terminfo description.
6928 A sample value might be
6929 .Q \ee[01;33m .
6930 .TP
6931 .B active\-region\-end\-color
6932 A string variable that
6933 .Q undoes
6934 the effects of \fBactive\-region\-start\-color\fP
6935 and restores
6936 .Q normal
6937 terminal display appearance after displaying text in the active region.
6938 This string must not take up any physical character positions on the display,
6939 so it should consist only of terminal escape sequences.
6940 It is output to the terminal after displaying the text in the active region.
6941 This variable is reset to the default value whenever the terminal type changes.
6942 The default value is the string that restores the terminal from standout mode,
6943 as obtained from the terminal's terminfo description.
6944 A sample value might be
6945 .Q \ee[0m .
6946 .TP
6947 .B bell\-style (audible)
6948 Controls what happens when \fBreadline\fP wants to ring the terminal bell.
6949 If set to \fBnone\fP, \fBreadline\fP never rings the bell.
6950 If set to \fBvisible\fP, \fBreadline\fP uses a visible bell if one is available.
6951 If set to \fBaudible\fP, \fBreadline\fP attempts to ring the terminal's bell.
6952 .TP
6953 .B bind\-tty\-special\-chars (On)
6954 If set to \fBOn\fP, \fBreadline\fP attempts to bind
6955 the control characters that are treated specially by the kernel's
6956 terminal driver to their \fBreadline\fP equivalents.
6957 These override the default \fBreadline\fP bindings described here.
6958 Type
6959 .Q "stty \-a"
6960 at a \fBbash\fP prompt to see your current terminal settings,
6961 including the special control characters (usually \fBcchars\fP).
6962 .TP
6963 .B blink\-matching\-paren (Off)
6964 If set to \fBOn\fP, \fBreadline\fP attempts to briefly move the cursor to an
6965 opening parenthesis when a closing parenthesis is inserted.
6966 .TP
6967 .B colored\-completion\-prefix (Off)
6968 If set to \fBOn\fP, when listing completions, \fBreadline\fP displays the
6969 common prefix of the set of possible completions using a different color.
6970 The color definitions are taken from the value of the \fBLS_COLORS\fP
6971 environment variable.
6972 If there is a color definition in \fB$LS_COLORS\fP for the custom suffix
6973 .Q .readline-colored-completion-prefix ,
6974 \fBreadline\fP uses this color for
6975 the common prefix instead of its default.
6976 .TP
6977 .B colored\-stats (Off)
6978 If set to \fBOn\fP, \fBreadline\fP displays possible completions using different
6979 colors to indicate their file type.
6980 The color definitions are taken from the value of the \fBLS_COLORS\fP
6981 environment variable.
6982 .\" Tucking multiple macro calls into a paragraph tag requires some
6983 .\" finesse. We require `\c`, and while the single-font macros don't
6984 .\" honor input trap continuation, the font alternation macros do.
6985 .TP
6986 .BR comment\-begin\ ( \c
6987 .Q \fB#\fP \fB)\fP
6988 The string that the \fBreadline\fP
6989 .B insert\-comment
6990 command inserts.
6991 This command is bound to
6992 .B M\-#
6993 in emacs mode and to
6994 .B #
6995 in vi command mode.
6996 .TP
6997 .B completion\-display\-width (\-1)
6998 The number of screen columns used to display possible matches
6999 when performing completion.
7000 The value is ignored if it is less than 0 or greater than the terminal
7001 screen width.
7002 A value of 0 causes matches to be displayed one per line.
7003 The default value is \-1.
7004 .TP
7005 .B completion\-ignore\-case (Off)
7006 If set to \fBOn\fP, \fBreadline\fP performs filename matching and completion
7007 in a case\-insensitive fashion.
7008 .TP
7009 .B completion\-map\-case (Off)
7010 If set to \fBOn\fP, and \fBcompletion\-ignore\-case\fP is enabled,
7011 .B readline
7012 treats hyphens (\fI\-\fP) and underscores (\fI_\fP) as equivalent when
7013 performing case\-insensitive filename matching and completion.
7014 .TP
7015 .B completion\-prefix\-display\-length (0)
7016 The maximum
7017 length in characters of the common prefix of a list of possible
7018 completions that is displayed without modification.
7019 When set to a value greater than zero, \fBreadline\fP
7020 replaces common prefixes longer than this value
7021 with an ellipsis when displaying possible completions.
7022 If a completion begins with a period,
7023 and \fBeadline\fP is completing filenames,
7024 it uses three underscores instead of an ellipsis.
7025 .TP
7026 .B completion\-query\-items (100)
7027 This determines when the user is queried about viewing
7028 the number of possible completions
7029 generated by the \fBpossible\-completions\fP command.
7030 It may be set to any integer value greater than or equal to zero.
7031 If the number of possible completions is greater than
7032 or equal to the value of this variable,
7033 \fBreadline\fP asks whether or not the user wishes to view them;
7034 otherwise \fBreadline\fP simply lists them on the terminal.
7035 A zero value means \fBreadline\fP should never ask; negative values are
7036 treated as zero.
7037 .TP
7038 .B convert\-meta (On)
7039 If set to \fBOn\fP, \fBreadline\fP converts characters it reads
7040 that have the eighth bit set to an ASCII key sequence by
7041 clearing the eighth bit and prefixing it with an escape character
7042 (converting the character to have the meta prefix).
7043 The default is \fIOn\fP, but \fBreadline\fP sets it to \fIOff\fP
7044 if the locale contains
7045 characters whose encodings may include bytes with the eighth bit set.
7046 This variable is dependent on the \fBLC_CTYPE\fP locale category, and
7047 may change if the locale changes.
7048 This variable also affects key bindings; see the description of
7049 \fBforce\-meta\-prefix\fP below.
7050 .TP
7051 .B disable\-completion (Off)
7052 If set to \fBOn\fP, \fBreadline\fP inhibits word completion.
7053 Completion characters are inserted into the line as if they
7054 had been mapped to \fBself-insert\fP.
7055 .TP
7056 .B echo\-control\-characters (On)
7057 When set to \fBOn\fP, on operating systems that indicate they support it,
7058 \fBreadline\fP echoes a character corresponding to a signal generated from the
7059 keyboard.
7060 .TP
7061 .B editing\-mode (emacs)
7062 Controls whether \fBreadline\fP uses a set of key bindings similar
7063 to \fIEmacs\fP or \fIvi\fP.
7064 .B editing\-mode
7065 can be set to either
7066 .B emacs
7067 or
7068 .BR vi .
7069 .TP
7070 .B emacs\-mode\-string (@)
7071 If the \fIshow\-mode\-in\-prompt\fP variable is enabled,
7072 this string is displayed immediately before the last line of the
7073 primary prompt when emacs editing mode is active.
7074 The value is expanded like a
7075 key binding, so the standard set of meta- and control- prefixes and
7076 backslash escape sequences is available.
7077 The \e1 and \e2 escapes begin and end sequences of
7078 non-printing characters, which can be used to embed a terminal control
7079 sequence into the mode string.
7080 .TP
7081 .B enable\-active\-region (On)
7082 When this variable is set to \fIOn\fP, \fBreadline\fP allows certain commands
7083 to designate the region as \fIactive\fP.
7084 When the region is active, \fBreadline\fP
7085 highlights the text in the region using the value of the
7086 .B active\-region\-start\-color
7087 variable, which defaults to the string that enables
7088 the terminal's standout mode.
7089 The active region shows the text inserted by bracketed-paste and any
7090 matching text found by incremental and non-incremental history searches.
7091 .TP
7092 .B enable\-bracketed\-paste (On)
7093 When set to \fBOn\fP, \fBreadline\fP configures the terminal to insert each
7094 paste into the editing buffer as a single string of characters, instead
7095 of treating each character as if it had been read from the keyboard.
7096 This is called \fIbracketed\-paste mode\fP;
7097 it prevents \fBreadline\fP from executing any editing commands bound to key
7098 sequences appearing in the pasted text.
7099 .TP
7100 .B enable\-keypad (Off)
7101 When set to \fBOn\fP, \fBreadline\fP tries to enable the application
7102 keypad when it is called.
7103 Some systems need this to enable the arrow keys.
7104 .TP
7105 .B enable\-meta\-key (On)
7106 When set to \fBOn\fP, \fBreadline\fP tries to enable any meta modifier
7107 key the terminal claims to support.
7108 On many terminals, the Meta key is used to send eight-bit characters;
7109 this variable checks for the terminal capability that indicates the
7110 terminal can enable and disable a mode that sets the eighth bit of a
7111 character (0200) if the Meta key is held down when the character is
7112 typed (a meta character).
7113 .TP
7114 .B expand\-tilde (Off)
7115 If set to \fBOn\fP, \fBreadline\fP performs tilde expansion when it
7116 attempts word completion.
7117 .TP
7118 .B force\-meta\-prefix (Off)
7119 If set to \fBOn\fP, \fBreadline\fP modifies its behavior when binding key
7120 sequences containing \eM- or Meta-
7121 (see \fBKey Bindings\fP above) by converting a key sequence of the form
7122 \eM\-\fIC\fP or Meta\-\fIC\fP to the two-character sequence
7123 \fBESC\fP \fIC\fP (adding the meta prefix).
7124 If
7125 .B force\-meta\-prefix
7126 is set to \fBOff\fP (the default),
7127 \fBreadline\fP uses the value of the
7128 .B convert\-meta
7129 variable to determine whether to perform this conversion:
7130 if \fBconvert\-meta\fP is \fBOn\fP,
7131 \fBreadline\fP performs the conversion described above;
7132 if it is \fBOff\fP, \fBreadline\fP converts \fIC\fP to a meta character by
7133 setting the eighth bit (0200).
7134 .TP
7135 .B history\-preserve\-point (Off)
7136 If set to \fBOn\fP, the history code attempts to place point at the
7137 same location on each history line retrieved with \fBprevious-history\fP
7138 or \fBnext-history\fP.
7139 .TP
7140 .B history\-size (unset)
7141 Set the maximum number of history entries saved in the history list.
7142 If set to zero, any existing history entries are deleted and no new entries
7143 are saved.
7144 If set to a value less than zero, the number of history entries is not
7145 limited.
7146 By default, \fBbash\fP sets the maximum number of history entries to
7147 the value of the \fBHISTSIZE\fP shell variable.
7148 Setting \fIhistory\-size\fP to a non-numeric value will set
7149 the maximum number of history entries to 500.
7150 .TP
7151 .B horizontal\-scroll\-mode (Off)
7152 Setting this variable to \fBOn\fP makes \fBreadline\fP use a single line
7153 for display, scrolling the input horizontally on a single screen line
7154 when it becomes longer than the screen width rather than wrapping to
7155 a new line.
7156 This setting is automatically enabled for terminals of height 1.
7157 .TP
7158 .B input\-meta (Off)
7159 If set to \fBOn\fP, \fBreadline\fP enables eight-bit input (that is, it
7160 does not clear the eighth bit in the characters it reads),
7161 regardless of what the terminal claims it can support.
7162 The default is \fIOff\fP, but \fBreadline\fP sets it to \fIOn\fP
7163 if the locale contains characters whose encodings may include bytes
7164 with the eighth bit set.
7165 This variable is dependent on the \fBLC_CTYPE\fP locale category, and
7166 its value may change if the locale changes.
7167 The name \fBmeta\-flag\fP is a synonym for \fBinput\-meta\fP.
7168 .TP
7169 .BR isearch\-terminators\ ( \c
7170 .Q \fBC\-[C\-j\fP \fB)\fP
7171 The string of characters that should terminate an incremental
7172 search without subsequently executing the character as a command.
7173 If this variable has not been given a value, the characters
7174 \fIESC\fP and \fBC\-j\fP terminate an incremental search.
7175 .TP
7176 .B keymap (emacs)
7177 Set the current \fBreadline\fP keymap.
7178 The set of valid keymap names is
7179 \fIemacs, emacs\-standard, emacs\-meta, emacs\-ctlx, vi,
7180 vi\-command\fP, and
7181 .IR vi\-insert .
7182 \fIvi\fP is equivalent to \fIvi\-command\fP;
7183 \fIemacs\fP is equivalent to \fIemacs\-standard\fP.
7184 The default value is \fIemacs\fP;
7185 the value of
7186 .B editing\-mode
7187 also affects the default keymap.
7188 .TP
7189 .B keyseq\-timeout (500)
7190 Specifies the duration \fBreadline\fP will wait for a character when
7191 reading an ambiguous key sequence
7192 (one that can form a complete key sequence using the input read so far,
7193 or can take additional input to complete a longer key sequence).
7194 If \fBreadline\fP does not receive any input within the timeout,
7195 it uses the shorter but complete key sequence.
7196 The value is specified in milliseconds, so a value of 1000 means that
7197 \fBreadline\fP will wait one second for additional input.
7198 If this variable is set to a value less than or equal to zero, or to a
7199 non-numeric value, \fBreadline\fP waits until another key is pressed to
7200 decide which key sequence to complete.
7201 .TP
7202 .B mark\-directories (On)
7203 If set to \fBOn\fP, completed directory names have a slash appended.
7204 .TP
7205 .B mark\-modified\-lines (Off)
7206 If set to \fBOn\fP, \fBreadline\fP displays history lines
7207 that have been modified
7208 with a preceding asterisk (\fB*\fP).
7209 .TP
7210 .B mark\-symlinked\-directories (Off)
7211 If set to \fBOn\fP, completed names which are symbolic links to directories
7212 have a slash appended, subject to the value of \fBmark\-directories\fP.
7213 .TP
7214 .B match\-hidden\-files (On)
7215 This variable, when set to \fBOn\fP, forces \fBreadline\fP to match files whose
7216 names begin with a
7217 .Q .
7218 (hidden files) when performing filename completion.
7219 If set to \fBOff\fP, the user must include the leading
7220 .Q .
7221 in the filename to be completed.
7222 .TP
7223 .B menu\-complete\-display\-prefix (Off)
7224 If set to \fBOn\fP, menu completion displays the common prefix of the
7225 list of possible completions (which may be empty) before cycling through
7226 the list.
7227 .TP
7228 .B output\-meta (Off)
7229 If set to \fBOn\fP, \fBreadline\fP displays characters with the
7230 eighth bit set directly rather than as a meta-prefixed escape
7231 sequence.
7232 The default is \fIOff\fP, but \fBreadline\fP sets it to \fIOn\fP
7233 if the locale contains characters whose encodings may include
7234 bytes with the eighth bit set.
7235 This variable is dependent on the \fBLC_CTYPE\fP locale category, and
7236 its value may change if the locale changes.
7237 .TP
7238 .B page\-completions (On)
7239 If set to \fBOn\fP, \fBreadline\fP uses an internal pager resembling
7240 .IR more (1)
7241 to display a screenful of possible completions at a time.
7242 .TP
7243 .B prefer\-visible\-bell
7244 See \fBbell\-style\fP.
7245 .TP
7246 .B print\-completions\-horizontally (Off)
7247 If set to \fBOn\fP, \fBreadline\fP displays completions with matches
7248 sorted horizontally in alphabetical order, rather than down the screen.
7249 .TP
7250 .B revert\-all\-at\-newline (Off)
7251 If set to \fBOn\fP, \fBreadline\fP will undo all changes to history lines
7252 before returning when executing \fBaccept\-line\fP.
7253 By default,
7254 history lines may be modified and retain individual undo lists across
7255 calls to \fBreadline\fP.
7256 .TP
7257 .B search\-ignore\-case (Off)
7258 If set to \fBOn\fP, \fBreadline\fP performs incremental and non-incremental
7259 history list searches in a case\-insensitive fashion.
7260 .TP
7261 .B show\-all\-if\-ambiguous (Off)
7262 This alters the default behavior of the completion functions.
7263 If set to
7264 .BR On ,
7265 words which have more than one possible completion cause the
7266 matches to be listed immediately instead of ringing the bell.
7267 .TP
7268 .B show\-all\-if\-unmodified (Off)
7269 This alters the default behavior of the completion functions in
7270 a fashion similar to \fBshow\-all\-if\-ambiguous\fP.
7271 If set to
7272 .BR On ,
7273 words which have more than one possible completion without any
7274 possible partial completion (the possible completions don't share
7275 a common prefix) cause the matches to be listed immediately instead
7276 of ringing the bell.
7277 .TP
7278 .B show\-mode\-in\-prompt (Off)
7279 If set to \fBOn\fP, add a string to the beginning of the prompt
7280 indicating the editing mode: emacs, vi command, or vi insertion.
7281 The mode strings are user-settable (e.g., \fIemacs\-mode\-string\fP).
7282 .TP
7283 .B skip\-completed\-text (Off)
7284 If set to \fBOn\fP, this alters the default completion behavior when
7285 inserting a single match into the line.
7286 It's only active when performing completion in the middle of a word.
7287 If enabled, \fBreadline\fP does not insert characters from the completion
7288 that match characters after point in the word being completed,
7289 so portions of the word following the cursor are not duplicated.
7290 .TP
7291 .B vi\-cmd\-mode\-string ((cmd))
7292 If the \fIshow\-mode\-in\-prompt\fP variable is enabled,
7293 this string is displayed immediately before the last line of the primary
7294 prompt when vi editing mode is active and in command mode.
7295 The value is expanded like a key binding, so the standard set of
7296 meta- and control- prefixes and backslash escape sequences is available.
7297 The \e1 and \e2 escapes begin and end sequences of
7298 non-printing characters, which can be used to embed a terminal control
7299 sequence into the mode string.
7300 .TP
7301 .B vi\-ins\-mode\-string ((ins))
7302 If the \fIshow\-mode\-in\-prompt\fP variable is enabled,
7303 this string is displayed immediately before the last line of the primary
7304 prompt when vi editing mode is active and in insertion mode.
7305 The value is expanded like a key binding, so the standard set of
7306 meta- and control- prefixes and backslash escape sequences is available.
7307 The \e1 and \e2 escapes begin and end sequences of
7308 non-printing characters, which can be used to embed a terminal control
7309 sequence into the mode string.
7310 .TP
7311 .B visible\-stats (Off)
7312 If set to \fBOn\fP, a character denoting a file's type as reported
7313 by \fIstat\fP(2) is appended to the filename when listing possible
7314 completions.
7315 .PD
7316 .SS "Readline Conditional Constructs"
7317 .B Readline
7318 implements a facility similar in spirit to the conditional
7319 compilation features of the C preprocessor which allows key
7320 bindings and variable settings to be performed as the result
7321 of tests.
7322 There are four parser directives available.
7323 .TP
7324 .B $if
7325 The
7326 .B $if
7327 construct allows bindings to be made based on the
7328 editing mode, the terminal being used, or the application using
7329 \fBreadline\fP.
7330 The text of the test, after any comparison operator,
7331 extends to the end of the line;
7332 unless otherwise noted, no characters are required to isolate it.
7333 .RS
7334 .TP
7335 .B mode
7336 The \fBmode=\fP form of the \fB$if\fP directive is used to test
7337 whether \fBreadline\fP is in emacs or vi mode.
7338 This may be used in conjunction
7339 with the \fBset keymap\fP command, for instance, to set bindings in
7340 the \fIemacs\-standard\fP and \fIemacs\-ctlx\fP keymaps only if
7341 \fBreadline\fP is starting out in emacs mode.
7342 .TP
7343 .B term
7344 The \fBterm=\fP form may be used to include terminal-specific
7345 key bindings, perhaps to bind the key sequences output by the
7346 terminal's function keys.
7347 The word on the right side of the
7348 .B =
7349 is tested against both the full name of the terminal and the portion
7350 of the terminal name before the first \fB\-\fP.
7351 This allows
7352 .I xterm
7353 to match both
7354 .I xterm
7355 and
7356 .IR xterm\-256color ,
7357 for instance.
7358 .TP
7359 .B version
7360 The \fBversion\fP test may be used to perform comparisons against
7361 specific \fBreadline\fP versions.
7362 The \fBversion\fP expands to the current \fBreadline\fP version.
7363 The set of comparison operators includes
7364 .BR = ,
7365 (and
7366 .BR == ),
7367 .BR != ,
7368 .BR <= ,
7369 .BR >= ,
7370 .BR < ,
7371 and
7372 .BR > .
7373 The version number supplied on the right side of the operator consists
7374 of a major version number, an optional decimal point, and an optional
7375 minor version (e.g., \fB7.1\fP).
7376 If the minor version is omitted, it
7377 defaults to \fB0\fP.
7378 The operator may be separated from the string \fBversion\fP
7379 and from the version number argument by whitespace.
7380 .TP
7381 .I application
7382 The \fIapplication\fP construct is used to include
7383 application-specific settings.
7384 Each program using the \fBreadline\fP
7385 library sets the \fIapplication name\fP, and an initialization
7386 file can test for a particular value.
7387 This could be used to bind key sequences to functions useful for
7388 a specific program.
7389 For instance, the following command adds a
7390 key sequence that quotes the current or previous word in \fBbash\fP:
7391 .PP
7392 .RS
7393 .EX
7394 .nf
7395 \fB$if\fP Bash
7396 # Quote the current or previous word
7397 \*"\eC-xq\*": \*"\eeb\e\*"\eef\e\*"\*"
7398 \fB$endif\fP
7399 .fi
7400 .EE
7401 .RE
7402 .TP
7403 .I variable
7404 The \fIvariable\fP construct provides simple equality tests for \fBreadline\fP
7405 variables and values.
7406 The permitted comparison operators are \fI=\fP, \fI==\fP, and \fI!=\fP.
7407 The variable name must be separated from the comparison operator by
7408 whitespace; the operator may be separated from the value on the right hand
7409 side by whitespace.
7410 String and boolean variables may be tested.
7411 Boolean variables must be
7412 tested against the values \fIon\fP and \fIoff\fP.
7413 .RE
7414 .TP
7415 .B $else
7416 Commands in this branch of the \fB$if\fP directive are executed if
7417 the test fails.
7418 .TP
7419 .B $endif
7420 This command, as seen in the previous example, terminates an
7421 \fB$if\fP command.
7422 .TP
7423 .B $include
7424 This directive takes a single filename as an argument and reads commands
7425 and key bindings from that file.
7426 For example, the following directive would read
7427 .FN /etc/inputrc :
7428 .PP
7429 .RS
7430 .nf
7431 \fB$include\fP \^ \fI/etc/inputrc\fP
7432 .fi
7433 .RE
7434 .SS Searching
7435 .B Readline
7436 provides commands for searching through the command history (see
7437 .SM
7438 .B HISTORY
7439 below)
7440 for lines containing a specified string.
7441 There are two search modes:
7442 .I incremental
7443 and
7444 .IR non-incremental .
7445 .PP
7446 Incremental searches begin before the user has finished typing the
7447 search string.
7448 As each character of the search string is typed, \fBreadline\fP displays
7449 the next entry from the history matching the string typed so far.
7450 An incremental search requires only as many characters as needed to
7451 find the desired history entry.
7452 When using emacs editing mode, type \fBC\-r\fP to
7453 search backward in the history for a particular string.
7454 Typing \fBC\-s\fP searches forward through the history.
7455 The characters present in the value of the \fBisearch-terminators\fP
7456 variable are used to terminate an incremental search.
7457 If that variable has not been assigned a value,
7458 \fIESC\fP and \fBC\-j\fP terminate an incremental search.
7459 \fBC\-g\fP aborts an incremental search and restores the original line.
7460 When the search is terminated, the history entry containing the
7461 search string becomes the current line.
7462 .PP
7463 To find other matching entries in the history list, type \fBC\-r\fP or
7464 \fBC\-s\fP as appropriate.
7465 This searches backward or forward in the history for the next
7466 entry matching the search string typed so far.
7467 Any other key sequence bound to a \fBreadline\fP command terminates
7468 the search and executes that command.
7469 For instance, a newline terminates the search and accepts
7470 the line, thereby executing the command from the history list.
7471 A movement command will terminate the search, make the last line found
7472 the current line, and begin editing.
7473 .PP
7474 .B Readline
7475 remembers the last incremental search string.
7476 If two \fBC\-r\fPs are typed without any intervening characters defining
7477 a new search string, \fBreadline\fP uses any remembered search string.
7478 .PP
7479 Non-incremental searches read the entire search string before starting
7480 to search for matching history entries.
7481 The search string may be
7482 typed by the user or be part of the contents of the current line.
7483 .SS "Readline Command Names"
7484 The following is a list of the names of the commands and the default
7485 key sequences to which they are bound.
7486 Command names without an accompanying key sequence are unbound by default.
7487 .PP
7488 In the following descriptions, \fIpoint\fP refers to the current cursor
7489 position, and \fImark\fP refers to a cursor position saved by the
7490 \fBset\-mark\fP command.
7491 The text between the point and mark is referred to as the \fIregion\fP.
7492 .B Readline
7493 has the concept of an \fIactive region\fP:
7494 when the region is active, \fBreadline\fP redisplay
7495 highlights the region using the value of the
7496 .B active\-region\-start\-color
7497 variable.
7498 The \fBenable\-active\-region\fP \fBreadline\fP variable turns this on and off.
7499 Several commands set the region to active; those are noted below.
7500 .SS Commands for Moving
7501 .PD 0
7502 .TP
7503 .B beginning\-of\-line (C\-a)
7504 Move to the start of the current line.
7505 This may also be bound to the Home key on some keyboards.
7506 .TP
7507 .B end\-of\-line (C\-e)
7508 Move to the end of the line.
7509 This may also be bound to the End key on some keyboards.
7510 .TP
7511 .B forward\-char (C\-f)
7512 Move forward a character.
7513 This may also be bound to the right arrow key on some keyboards.
7514 .TP
7515 .B backward\-char (C\-b)
7516 Move back a character.
7517 This may also be bound to the left arrow key on some keyboards.
7518 .TP
7519 .B forward\-word (M\-f)
7520 Move forward to the end of the next word.
7521 Words are composed of alphanumeric characters (letters and digits).
7522 .TP
7523 .B backward\-word (M\-b)
7524 Move back to the start of the current or previous word.
7525 Words are composed of alphanumeric characters (letters and digits).
7526 .TP
7527 .B shell\-forward\-word (M\-C\-f)
7528 Move forward to the end of the next word.
7529 Words are delimited by non-quoted shell metacharacters.
7530 .TP
7531 .B shell\-backward\-word (M\-C\-b)
7532 Move back to the start of the current or previous word.
7533 Words are delimited by non-quoted shell metacharacters.
7534 .TP
7535 .B previous\-screen\-line
7536 Attempt to move point to the same physical screen column on the previous
7537 physical screen line.
7538 This will not have the desired effect if the current
7539 \fBreadline\fP line does not take up more than one physical line or if
7540 point is not greater than the length of the prompt plus the screen width.
7541 .TP
7542 .B next\-screen\-line
7543 Attempt to move point to the same physical screen column on the next
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 the length of the current \fBreadline\fP line is
7548 not greater than the length of the prompt
7549 plus the screen width.
7550 .TP
7551 .B clear\-display (M\-C\-l)
7552 Clear the screen and, if possible, the terminal's scrollback buffer,
7553 then redraw the current line,
7554 leaving the current line at the top of the screen.
7555 .TP
7556 .B clear\-screen (C\-l)
7557 Clear the screen,
7558 then redraw the current line,
7559 leaving the current line at the top of the screen.
7560 With a numeric argument, refresh the current line without clearing the
7561 screen.
7562 .TP
7563 .B redraw\-current\-line
7564 Refresh the current line.
7565 .PD
7566 .SS Commands for Manipulating the History
7567 .PD 0
7568 .TP
7569 .B accept\-line (Newline, Return)
7570 Accept the line regardless of where the cursor is.
7571 If this line is non-empty, add it to the history list according to the
7572 state of the
7573 .SM
7574 .B HISTCONTROL
7575 and
7576 .B HISTIGNORE
7577 variables.
7578 If the line is a modified history line,
7579 restore the history line to its original state.
7580 .TP
7581 .B previous\-history (C\-p)
7582 Fetch the previous command from the history list, moving back in
7583 the list.
7584 This may also be bound to the up arrow key on some keyboards.
7585 .TP
7586 .B next\-history (C\-n)
7587 Fetch the next command from the history list, moving forward in the
7588 list.
7589 This may also be bound to the down arrow key on some keyboards.
7590 .TP
7591 .B beginning\-of\-history (M\-<)
7592 Move to the first line in the history.
7593 .TP
7594 .B end\-of\-history (M\->)
7595 Move to the end of the input history, i.e., the line currently being
7596 entered.
7597 .TP
7598 .B operate\-and\-get\-next (C\-o)
7599 Accept the current line for execution as if a
7600 newline had been entered,
7601 and fetch the next line relative to the current line from the history
7602 for editing.
7603 A numeric argument, if supplied, specifies the history entry to use instead
7604 of the current line.
7605 .TP
7606 .B
7607 fetch\-history
7608 With a numeric argument, fetch that entry from the history list
7609 and make it the current line.
7610 Without an argument, move back to the first entry in the history list.
7611 .TP
7612 .B reverse\-search\-history (C\-r)
7613 Search backward starting at the current line and moving
7614 .Q up
7615 through the history as necessary.
7616 This is an incremental search.
7617 This command sets the region to the matched text and activates the region.
7618 .TP
7619 .B forward\-search\-history (C\-s)
7620 Search forward starting at the current line and moving
7621 .Q down
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 non\-incremental\-reverse\-search\-history (M\-p)
7627 Search backward through the history starting at the current line
7628 using a non-incremental search for a string supplied by the user.
7629 The search string may match anywhere in a history line.
7630 .TP
7631 .B non\-incremental\-forward\-search\-history (M\-n)
7632 Search forward through the history using a non-incremental search
7633 for a string supplied by the user.
7634 The search string may match anywhere in a history line.
7635 .TP
7636 .B history\-search\-backward
7637 Search backward through the history for the string of characters
7638 between the start of the current line and the point.
7639 The search string must match at the beginning of a history line.
7640 This is a non-incremental search.
7641 This may be bound to the Page Up key on some keyboards.
7642 .TP
7643 .B history\-search\-forward
7644 Search forward 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 Down key on some keyboards.
7649 .TP
7650 .B history\-substring\-search\-backward
7651 Search backward through the history for the string of characters
7652 between the start of the current line and the point.
7653 The search string may match anywhere in a history line.
7654 This is a non-incremental search.
7655 .TP
7656 .B history\-substring\-search\-forward
7657 Search forward through the history for the string of characters
7658 between the start of the current line and the point.
7659 The search string may match anywhere in a history line.
7660 This is a non-incremental search.
7661 .TP
7662 .B yank\-nth\-arg (M\-C\-y)
7663 Insert the first argument to the previous command (usually
7664 the second word on the previous line) at point.
7665 With an argument
7666 .IR n ,
7667 insert the \fIn\fPth word from the previous command (the words
7668 in the previous command begin with word 0).
7669 A negative argument inserts the \fIn\fPth word from the end of
7670 the previous command.
7671 Once the argument \fIn\fP is computed,
7672 this uses the history expansion facilities to extract the
7673 \fIn\fPth word, as if the
7674 .Q !\fIn\fP
7675 history expansion had been specified.
7676 .TP
7677 .B
7678 yank\-last\-arg (M\-.\^, M\-_\^)
7679 Insert the last argument to the previous command (the last word of
7680 the previous history entry).
7681 With a numeric argument, behave exactly like \fByank\-nth\-arg\fP.
7682 Successive calls to \fByank\-last\-arg\fP move back through the history
7683 list, inserting the last word (or the word specified by the argument to
7684 the first call) of each line in turn.
7685 Any numeric argument supplied to these successive calls determines
7686 the direction to move through the history.
7687 A negative argument switches the direction through the history
7688 (back or forward).
7689 This uses the history expansion facilities to extract the
7690 last word, as if the
7691 .Q !$
7692 history expansion had been specified.
7693 .TP
7694 .B shell\-expand\-line (M\-C\-e)
7695 Expand the line by performing shell word expansions.
7696 This performs alias and history expansion,
7697 \fB$\fP\*'\fIstring\fP\*' and \fB$\fP\*"\fIstring\fP\*" quoting,
7698 tilde expansion, parameter and variable expansion, arithmetic expansion,
7699 command and process substitution,
7700 word splitting, and quote removal.
7701 An explicit argument suppresses command and process substitution.
7702 See
7703 .SM
7704 .B "HISTORY EXPANSION"
7705 below for a description of history expansion.
7706 .TP
7707 .B history\-expand\-line (M\-\*^)
7708 Perform history expansion on the current line.
7709 See
7710 .SM
7711 .B "HISTORY EXPANSION"
7712 below for a description of history expansion.
7713 .TP
7714 .B magic\-space
7715 Perform history expansion on the current line and insert a space.
7716 See
7717 .SM
7718 .B "HISTORY EXPANSION"
7719 below for a description of history expansion.
7720 .TP
7721 .B alias\-expand\-line
7722 Perform alias expansion on the current line.
7723 See
7724 .SM
7725 .B ALIASES
7726 above for a description of alias expansion.
7727 .TP
7728 .B history\-and\-alias\-expand\-line
7729 Perform history and alias expansion on the current line.
7730 .TP
7731 .B insert\-last\-argument (M\-.\^, M\-_\^)
7732 A synonym for \fByank\-last\-arg\fP.
7733 .TP
7734 .B edit\-and\-execute\-command (C\-x C\-e)
7735 Invoke an editor on the current command line, and execute the result as shell
7736 commands.
7737 \fBBash\fP attempts to invoke
7738 .SM
7739 .BR $VISUAL ,
7740 .SM
7741 .BR $EDITOR ,
7742 and \fIemacs\fP as the editor, in that order.
7743 .PD
7744 .SS Commands for Changing Text
7745 .PD 0
7746 .TP
7747 .B \fIend\-of\-file\fP (usually C\-d)
7748 The character indicating end-of-file as set, for example, by
7749 .IR stty (1).
7750 If this character is read when there are no characters
7751 on the line, and point is at the beginning of the line, \fBreadline\fP
7752 interprets it as the end of input and returns
7753 .SM
7754 .BR EOF .
7755 .TP
7756 .B delete\-char (C\-d)
7757 Delete the character at point.
7758 If this function is bound to the
7759 same character as the tty \fBEOF\fP character, as \fBC\-d\fP
7760 commonly is, see above for the effects.
7761 This may also be bound to the Delete key on some keyboards.
7762 .TP
7763 .B backward\-delete\-char (Rubout)
7764 Delete the character behind the cursor.
7765 When given a numeric argument,
7766 save the deleted text on the kill ring.
7767 .TP
7768 .B forward\-backward\-delete\-char
7769 Delete the character under the cursor, unless the cursor is at the
7770 end of the line, in which case the character behind the cursor is
7771 deleted.
7772 .TP
7773 .B quoted\-insert (C\-q, C\-v)
7774 Add the next character typed to the line verbatim.
7775 This is how to insert characters like \fBC\-q\fP, for example.
7776 .TP
7777 .B tab\-insert (C\-v TAB)
7778 Insert a tab character.
7779 .TP
7780 .B "self\-insert (a, b, A, 1, !, \fR.\|.\|.\fP)"
7781 Insert the character typed.
7782 .TP
7783 .B bracketed\-paste\-begin
7784 This function is intended to be bound to the
7785 .Q "bracketed paste"
7786 escape
7787 sequence sent by some terminals, and such a binding is assigned by default.
7788 It allows \fBreadline\fP to insert the pasted text as a single unit
7789 without treating each character as if it had been read from the keyboard.
7790 The pasted characters
7791 are inserted as if each one was bound to \fBself\-insert\fP instead of
7792 executing any editing commands.
7793 .IP
7794 Bracketed paste sets the region to the inserted text and activates the region.
7795 .TP
7796 .B transpose\-chars (C\-t)
7797 Drag the character before point forward over the character at point,
7798 moving point forward as well.
7799 If point is at the end of the line, then this transposes
7800 the two characters before point.
7801 Negative arguments have no effect.
7802 .TP
7803 .B transpose\-words (M\-t)
7804 Drag the word before point past the word after point,
7805 moving point past that word as well.
7806 If point is at the end of the line, this transposes
7807 the last two words on the line.
7808 .TP
7809 .B shell\-transpose\-words (M-C-t)
7810 Drag the word before point past the word after point,
7811 moving point past that word as well.
7812 If the insertion point is at the end of the line, this transposes
7813 the last two words on the line.
7814 Word boundaries are the same as \fBshell\-forward\-word\fP and
7815 \fBshell\-backward\-word\fP.
7816 .TP
7817 .B upcase\-word (M\-u)
7818 Uppercase the current (or following) word.
7819 With a negative argument,
7820 uppercase the previous word, but do not move point.
7821 .TP
7822 .B downcase\-word (M\-l)
7823 Lowercase the current (or following) word.
7824 With a negative argument,
7825 lowercase the previous word, but do not move point.
7826 .TP
7827 .B capitalize\-word (M\-c)
7828 Capitalize the current (or following) word.
7829 With a negative argument,
7830 capitalize the previous word, but do not move point.
7831 .TP
7832 .B overwrite\-mode
7833 Toggle overwrite mode.
7834 With an explicit positive numeric argument, switches to overwrite mode.
7835 With an explicit non-positive numeric argument, switches to insert mode.
7836 This command affects only \fBemacs\fP mode;
7837 \fBvi\fP mode does overwrite differently.
7838 Each call to \fIreadline()\fP starts in insert mode.
7839 .IP
7840 In overwrite mode, characters bound to \fBself\-insert\fP replace
7841 the text at point rather than pushing the text to the right.
7842 Characters bound to \fBbackward\-delete\-char\fP replace the character
7843 before point with a space.
7844 By default, this command is unbound,
7845 but may be bound to the Insert key on some keyboards.
7846 .PD
7847 .SS Killing and Yanking
7848 .PD 0
7849 .TP
7850 .B kill\-line (C\-k)
7851 Kill the text from point to the end of the current line.
7852 With a negative numeric argument, kill backward from the cursor to the
7853 beginning of the line.
7854 .TP
7855 .B backward\-kill\-line (C\-x Rubout)
7856 Kill backward to the beginning of the current line.
7857 With a negative numeric argument, kill forward from the cursor to the
7858 end of the line.
7859 .TP
7860 .B unix\-line\-discard (C\-u)
7861 Kill backward from point to the beginning of the line,
7862 saving the killed text on the kill-ring.
7863 .\" There is no real difference between this and backward-kill-line
7864 .TP
7865 .B kill\-whole\-line
7866 Kill all characters on the current line, no matter where point is.
7867 .TP
7868 .B kill\-word (M\-d)
7869 Kill from point to the end of the current word, or if between
7870 words, to the end of the next word.
7871 Word boundaries are the same as those used by \fBforward\-word\fP.
7872 .TP
7873 .B backward\-kill\-word (M\-Rubout)
7874 Kill the word behind point.
7875 Word boundaries are the same as those used by \fBbackward\-word\fP.
7876 .TP
7877 .B shell\-kill\-word (M\-C\-d)
7878 Kill from point to the end of the current word, or if between
7879 words, to the end of the next word.
7880 Word boundaries are the same as those used by \fBshell\-forward\-word\fP.
7881 .TP
7882 .B shell\-backward\-kill\-word
7883 Kill the word behind point.
7884 Word boundaries are the same as those used by \fBshell\-backward\-word\fP.
7885 .TP
7886 .B unix\-word\-rubout (C\-w)
7887 Kill the word behind point, using white space as a word boundary,
7888 saving the killed text on the kill-ring.
7889 .TP
7890 .B unix\-filename\-rubout
7891 Kill the word behind point, using white space and the slash character
7892 as the word boundaries,
7893 saving the killed text on the kill-ring.
7894 .TP
7895 .B delete\-horizontal\-space (M\-\e)
7896 Delete all spaces and tabs around point.
7897 .TP
7898 .B kill\-region
7899 Kill the text in the current region.
7900 .TP
7901 .B copy\-region\-as\-kill
7902 Copy the text in the region to the kill buffer,
7903 so it can be yanked immediately.
7904 .TP
7905 .B copy\-backward\-word
7906 Copy the word before point to the kill buffer.
7907 The word boundaries are the same as \fBbackward\-word\fP.
7908 .TP
7909 .B copy\-forward\-word
7910 Copy the word following point to the kill buffer.
7911 The word boundaries are the same as \fBforward\-word\fP.
7912 .TP
7913 .B yank (C\-y)
7914 Yank the top of the kill ring into the buffer at point.
7915 .TP
7916 .B yank\-pop (M\-y)
7917 Rotate the kill ring, and yank the new top.
7918 Only works following
7919 .B yank
7920 or
7921 .BR yank\-pop .
7922 .PD
7923 .SS Numeric Arguments
7924 .PD 0
7925 .TP
7926 .B digit\-argument (M\-0, M\-1, \fR.\|.\|.\fP, M\-\-)
7927 Add this digit to the argument already accumulating, or start a new
7928 argument.
7929 M\-\- starts a negative argument.
7930 .TP
7931 .B universal\-argument
7932 This is another way to specify an argument.
7933 If this command is followed by one or more digits, optionally with a
7934 leading minus sign, those digits define the argument.
7935 If the command is followed by digits, executing
7936 .B universal\-argument
7937 again ends the numeric argument, but is otherwise ignored.
7938 As a special case, if this command is immediately followed by a
7939 character that is neither a digit nor minus sign,
7940 the argument count for the next command is multiplied by four.
7941 The argument count is initially one, so executing this function the
7942 first time makes the argument count four, a second time makes the
7943 argument count sixteen, and so on.
7944 .PD
7945 .SS Completing
7946 .PD 0
7947 .TP
7948 .B complete (TAB)
7949 Attempt to perform completion on the text before point.
7950 .B Bash
7951 attempts completion by first checking for any programmable
7952 completions for the command word (see \fBProgrammable Completion\fP below),
7953 otherwise treating the text as a
7954 variable (if the text begins with \fB$\fP),
7955 username (if the text begins with \fB\*~\fP),
7956 hostname (if the text begins with \fB@\fP), or
7957 command (including aliases, functions, and builtins) in turn.
7958 If none of these produces a match, it falls back to filename completion.
7959 .TP
7960 .B possible\-completions (M\-?)
7961 List the possible completions of the text before point.
7962 When displaying completions, \fBreadline\fP sets the number of columns used
7963 for display to the value of \fBcompletion-display-width\fP, the value of
7964 the shell variable
7965 .SM
7966 .BR COLUMNS ,
7967 or the screen width, in that order.
7968 .TP
7969 .B insert\-completions (M\-*)
7970 Insert all completions of the text before point
7971 that would have been generated by
7972 \fBpossible\-completions\fP,
7973 separated by a space.
7974 .TP
7975 .B menu\-complete
7976 Similar to \fBcomplete\fP, but replaces the word to be completed
7977 with a single match from the list of possible completions.
7978 Repeatedly executing \fBmenu\-complete\fP steps through the list
7979 of possible completions, inserting each match in turn.
7980 At the end of the list of completions,
7981 \fBmenu\-complete\fP rings the bell
7982 (subject to the setting of \fBbell\-style\fP)
7983 and restores the original text.
7984 An argument of \fIn\fP moves \fIn\fP positions forward in the list
7985 of matches; a negative argument moves backward through the list.
7986 This command is intended to be bound to \fBTAB\fP, but is unbound
7987 by default.
7988 .TP
7989 .B menu\-complete\-backward
7990 Identical to \fBmenu\-complete\fP, but moves backward through the list
7991 of possible completions, as if \fBmenu\-complete\fP had been given a
7992 negative argument.
7993 This command is unbound by default.
7994 .TP
7995 .B export\-completions
7996 Perform completion on the word before point as described above
7997 and write the list of possible completions to \fBreadline\fP's output
7998 stream using the following format, writing information on separate lines:
7999 .RS
8000 .PD
8001 .IP \(bu
8002 .PD 0
8003 the number of matches \fIN\fP;
8004 .IP \(bu
8005 the word being completed;
8006 .IP \(bu
8007 \fIS\fP:\fIE\fP,
8008 where \fIS\fP and \fIE\fP are the start and end offsets of the word
8009 in the \fBreadline\fP line buffer; then
8010 .IP \(bu
8011 each match, one per line
8012 .RE
8013 .PD
8014 .IP
8015 If there are no matches, the first line will be
8016 .Q 0 ,
8017 and this command does not print any output after the \fIS\fP:\fIE\fP.
8018 If there is only a single match, this prints a single line containing it.
8019 If there is more than one match, this prints the common prefix of the
8020 matches, which may be empty, on the first line after the \fIS\fP:\fIE\fP,
8021 then the matches on subsequent lines.
8022 In this case, \fIN\fP will include the first line with the common prefix.
8023 .IP
8024 The user or application
8025 should be able to accommodate the possibility of a blank line.
8026 The intent is that the user or application reads \fIN\fP lines after
8027 the line containing \fIS\fP:\fIE\fP to obtain the match list.
8028 This command is unbound by default.
8029 .TP
8030 .B delete\-char\-or\-list
8031 Deletes the character under the cursor if not at the beginning or
8032 end of the line (like \fBdelete\-char\fP).
8033 At the end of the line, it behaves identically to \fBpossible\-completions\fP.
8034 This command is unbound by default.
8035 .TP
8036 .B complete\-filename (M\-/)
8037 Attempt filename completion on the text before point.
8038 .TP
8039 .B possible\-filename\-completions (C\-x /)
8040 List the possible completions of the text before point,
8041 treating it as a filename.
8042 .TP
8043 .B complete\-username (M\-\*~)
8044 Attempt completion on the text before point, treating
8045 it as a username.
8046 .TP
8047 .B possible\-username\-completions (C\-x \*~)
8048 List the possible completions of the text before point,
8049 treating it as a username.
8050 .TP
8051 .B complete\-variable (M\-$)
8052 Attempt completion on the text before point, treating
8053 it as a shell variable.
8054 .TP
8055 .B possible\-variable\-completions (C\-x $)
8056 List the possible completions of the text before point,
8057 treating it as a shell variable.
8058 .TP
8059 .B complete\-hostname (M\-@)
8060 Attempt completion on the text before point, treating
8061 it as a hostname.
8062 .TP
8063 .B possible\-hostname\-completions (C\-x @)
8064 List the possible completions of the text before point,
8065 treating it as a hostname.
8066 .TP
8067 .B complete\-command (M\-!)
8068 Attempt completion on the text before point, treating
8069 it as a command name.
8070 Command completion attempts to
8071 match the text against aliases, reserved words, shell
8072 functions, shell builtins, and finally executable filenames,
8073 in that order.
8074 .TP
8075 .B possible\-command\-completions (C\-x !)
8076 List the possible completions of the text before point,
8077 treating it as a command name.
8078 .TP
8079 .B dynamic\-complete\-history (M\-TAB)
8080 Attempt completion on the text before point, comparing
8081 the text against history list entries for possible
8082 completion matches.
8083 .TP
8084 .B dabbrev\-expand
8085 Attempt menu completion on the text before point, comparing
8086 the text against lines from the history list for possible
8087 completion matches.
8088 .TP
8089 .B complete\-into\-braces (M\-{)
8090 Perform filename completion and insert the list of possible completions
8091 enclosed within braces so the list is available to the shell (see
8092 .B "Brace Expansion"
8093 above).
8094 .PD
8095 .SS "Keyboard Macros"
8096 .PD 0
8097 .TP
8098 .B start\-kbd\-macro (C\-x (\^)
8099 Begin saving the characters typed into the current keyboard macro.
8100 .TP
8101 .B end\-kbd\-macro (C\-x )\^)
8102 Stop saving the characters typed into the current keyboard macro
8103 and store the definition.
8104 .TP
8105 .B call\-last\-kbd\-macro (C\-x e)
8106 Re-execute the last keyboard macro defined, by making the characters
8107 in the macro appear as if typed at the keyboard.
8108 .TP
8109 .B print\-last\-kbd\-macro ()
8110 Print the last keyboard macro defined in a format suitable for the
8111 \fIinputrc\fP file.
8112 .PD
8113 .SS Miscellaneous
8114 .PD 0
8115 .TP
8116 .B re\-read\-init\-file (C\-x C\-r)
8117 Read in the contents of the \fIinputrc\fP file, and incorporate
8118 any bindings or variable assignments found there.
8119 .TP
8120 .B abort (C\-g)
8121 Abort the current editing command and
8122 ring the terminal's bell (subject to the setting of
8123 .BR bell\-style ).
8124 .TP
8125 .B do\-lowercase\-version (M\-A, M\-B, M\-\fIx\fP, \fR.\|.\|.\fP)
8126 If the metafied character \fIx\fP is uppercase, run the command
8127 that is bound to the corresponding metafied lowercase character.
8128 The behavior is undefined if \fIx\fP is already lowercase.
8129 .TP
8130 .B prefix\-meta (ESC)
8131 Metafy the next character typed.
8132 .SM
8133 .B ESC
8134 .B f
8135 is equivalent to
8136 .BR Meta\-f .
8137 .TP
8138 .B undo (C\-_, C\-x C\-u)
8139 Incremental undo, separately remembered for each line.
8140 .TP
8141 .B revert\-line (M\-r)
8142 Undo all changes made to this line.
8143 This is like executing the
8144 .B undo
8145 command enough times to return the line to its initial state.
8146 .TP
8147 .B tilde\-expand (M\-&)
8148 Perform tilde expansion on the current word.
8149 .TP
8150 .B set\-mark (C\-@, M\-<space>)
8151 Set the mark to the point.
8152 If a numeric argument is supplied, set the mark to that position.
8153 .TP
8154 .B exchange\-point\-and\-mark (C\-x C\-x)
8155 Swap the point with the mark.
8156 Set the current cursor position to the saved position,
8157 then set the mark to the old cursor position.
8158 .TP
8159 .B character\-search (C\-])
8160 Read a character and move point to the next occurrence of that character.
8161 A negative argument searches for previous occurrences.
8162 .TP
8163 .B character\-search\-backward (M\-C\-])
8164 Read a character and move point to the previous occurrence of that character.
8165 A negative argument searches for subsequent occurrences.
8166 .TP
8167 .B skip\-csi\-sequence
8168 Read enough characters to consume a multi-key sequence such as those
8169 defined for keys like Home and End.
8170 CSI sequences begin with a Control Sequence Indicator (CSI), usually
8171 .IR "ESC [" .
8172 If this sequence is bound to
8173 .Q \ee[ ,
8174 keys producing CSI sequences have no effect
8175 unless explicitly bound to a \fBreadline\fP command,
8176 instead of inserting stray characters into the editing buffer.
8177 This is unbound by default, but usually bound to
8178 .IR "ESC [" .
8179 .TP
8180 .B insert\-comment (M\-#)
8181 Without a numeric argument, insert the value of the \fBreadline\fP
8182 .B comment\-begin
8183 variable at the beginning of the current line.
8184 If a numeric argument is supplied, this command acts as a toggle: if
8185 the characters at the beginning of the line do not match the value
8186 of \fBcomment\-begin\fP, insert the value; otherwise delete
8187 the characters in \fBcomment-begin\fP from the beginning of the line.
8188 In either case, the line is accepted as if a newline had been typed.
8189 The default value of
8190 \fBcomment\-begin\fP causes this command to make the current line
8191 a shell comment.
8192 If a numeric argument causes the comment character to be removed, the line
8193 will be executed by the shell.
8194 .TP
8195 .B spell\-correct\-word (C\-x s)
8196 Perform spelling correction on the current word, treating it as a directory
8197 or filename, in the same way as the \fBcdspell\fP shell option.
8198 Word boundaries are the same as those used by \fBshell\-forward\-word\fP.
8199 .TP
8200 .B glob\-complete\-word (M\-g)
8201 Treat the word before point as a pattern for pathname expansion,
8202 with an asterisk implicitly appended, then use the pattern to
8203 generate a list of matching file names for possible completions.
8204 .TP
8205 .B glob\-expand\-word (C\-x *)
8206 Treat the word before point as a pattern for pathname expansion,
8207 and insert the list of matching file names, replacing the word.
8208 If a numeric argument is supplied, append a \fB*\fP before
8209 pathname expansion.
8210 .TP
8211 .B glob\-list\-expansions (C\-x g)
8212 Display the list of expansions that would have been generated by
8213 .B glob\-expand\-word
8214 and redisplay the line.
8215 If a numeric argument is supplied, append a \fB*\fP before
8216 pathname expansion.
8217 .TP
8218 .B dump\-functions
8219 Print all of the functions and their key bindings
8220 to the \fBreadline\fP output stream.
8221 If a numeric argument is supplied,
8222 the output is formatted in such a way that it can be made part
8223 of an \fIinputrc\fP file.
8224 .TP
8225 .B dump\-variables
8226 Print all of the settable \fBreadline\fP variables and their values
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\-macros
8233 Print all of the \fBreadline\fP key sequences bound to macros and the
8234 strings they output
8235 to the \fBreadline\fP output stream.
8236 If a numeric argument is supplied,
8237 the output is formatted in such a way that it can be made part
8238 of an \fIinputrc\fP file.
8239 .TP
8240 .B execute\-named\-command (M-x)
8241 Read a bindable \fBreadline\fP command name from the input and execute the
8242 function to which it's bound, as if the key sequence to which it was
8243 bound appeared in the input.
8244 If this function is supplied with a numeric argument, it passes that
8245 argument to the function it executes.
8246 .TP
8247 .B display\-shell\-version (C\-x C\-v)
8248 Display version information about the current instance of
8249 .BR bash .
8250 .PD
8251 .SS "Programmable Completion"
8252 When a user attempts word completion
8253 for a command or an argument to a command for
8254 which a completion specification (a \fIcompspec\fP) has been defined
8255 using the \fBcomplete\fP builtin
8256 (see
8257 .SM
8258 .B "SHELL BUILTIN COMMANDS"
8259 below),
8260 \fBreadline\fP invokes the programmable completion facilities.
8261 .PP
8262 First, \fBbash\fP identifies the command name.
8263 If a compspec has been defined for that command, the
8264 compspec is used to generate the list of possible completions for the word.
8265 If the command word is the empty string (completion attempted at the
8266 beginning of an empty line), \fBbash\fP uses any compspec defined with
8267 the \fB\-E\fP option to \fBcomplete\fP.
8268 The \fB\-I\fP option to \fBcomplete\fP
8269 indicates that the command word is the first non-assignment word
8270 on the line, or after a command delimiter such as
8271 \fB;\fP or \fB|\fP.
8272 This usually indicates command name completion.
8273 .PP
8274 If the command word is a full pathname, \fBbash\fP
8275 searches for a compspec for the full pathname first.
8276 If there is no compspec for the full pathname, \fBbash\fP attempts to
8277 find a compspec for the portion following the final slash.
8278 If those searches do not result in a compspec,
8279 or if there is no compspec for the command word,
8280 \fBbash\fP uses any compspec defined with
8281 the \fB\-D\fP option to \fBcomplete\fP as the default.
8282 If there is no default compspec, \fBbash\fP performs alias expansion
8283 on the command word as a final resort,
8284 and attempts to find a compspec for the command word
8285 resulting from any successful expansion.
8286 .PP
8287 If a compspec is not found, \fBbash\fP performs its default completion as
8288 described above under \fBCompleting\fP.
8289 Otherwise, once a compspec has been found, \fBbash\fP uses it to generate
8290 the list of matching words.
8291 .PP
8292 First, \fBbash\fP performs the \fIactions\fP specified by the compspec.
8293 This only returns matches which are prefixes
8294 of the word being completed.
8295 When the
8296 .B \-f
8297 or
8298 .B \-d
8299 option is used for filename or directory name completion,
8300 \fBbash\fP uses the shell variable
8301 .SM
8302 .B FIGNORE
8303 to filter the matches.
8304 .PP
8305 Next, programmable completion generates matches
8306 specified by a pathname expansion pattern
8307 supplied as an argument to the
8308 \fB\-G\fP option.
8309 The words generated by the pattern need not match the word
8310 being completed.
8311 \fBBash\fP
8312 uses the
8313 .SM
8314 .B FIGNORE
8315 variable to filter the matches, but does not use the
8316 .SM
8317 .B GLOBIGNORE
8318 shell variable.
8319 .PP
8320 Next, completion considers
8321 the string specified as the argument to the \fB\-W\fP option.
8322 The string is first split using the characters in the
8323 .SM
8324 .B IFS
8325 special variable as delimiters.
8326 This honors shell quoting within the string, in order to provide a
8327 mechanism for the words to contain shell metacharacters or characters
8328 in the value of
8329 .SM
8330 .BR IFS .
8331 Each word is then expanded using
8332 brace expansion, tilde expansion, parameter and variable expansion,
8333 command substitution, and arithmetic expansion,
8334 as described above under
8335 .SM
8336 .BR EXPANSION .
8337 The results are split using the rules described above under
8338 \fBWord Splitting\fP.
8339 The results of the expansion are prefix-matched against the word being
8340 completed, and the matching words become possible completions.
8341 .PP
8342 After these matches have been generated,
8343 \fBbash\fP executes any shell function or command
8344 specified with the \fB\-F\fP and \fB\-C\fP options.
8345 When the command or function is invoked, \fBbash\fP
8346 assigns values to the
8347 .SM
8348 .BR COMP_LINE ,
8349 .SM
8350 .BR COMP_POINT ,
8351 .SM
8352 .BR COMP_KEY ,
8353 and
8354 .SM
8355 .B COMP_TYPE
8356 variables as described above
8357 under \fBShell Variables\fP.
8358 If a shell function is being invoked, \fBbash\fP
8359 also sets the
8360 .SM
8361 .B COMP_WORDS
8362 and
8363 .SM
8364 .B COMP_CWORD
8365 variables.
8366 When the function or command is invoked,
8367 the first argument (\fB$1\fP) is the name of the command whose arguments
8368 are being completed,
8369 the second argument (\fB$2\fP) is the word being completed,
8370 and the third argument (\fB$3\fP) is the word preceding the word being
8371 completed on the current command line.
8372 There is no filtering of the generated completions against the
8373 word being completed;
8374 the function or command has complete freedom in generating the matches
8375 and they do not need to match a prefix of the word.
8376 .PP
8377 Any function specified with \fB\-F\fP is invoked first.
8378 The function may use any of the shell facilities, including the
8379 \fBcompgen\fP and \fBcompopt\fP
8380 builtins described below, to generate the matches.
8381 It must put the possible completions in the
8382 .SM
8383 .B COMPREPLY
8384 array variable, one per array element.
8385 .PP
8386 Next, any command specified with the \fB\-C\fP option is invoked
8387 in an environment equivalent to command substitution.
8388 It should print a list of completions, one per line, to the
8389 standard output.
8390 Backslash will escape a newline, if necessary.
8391 These are added to the set of possible completions.
8392 .PP
8393 After generating all of the possible completions,
8394 \fBbash\fP applies any filter
8395 specified with the \fB\-X\fP option to the completions in the list.
8396 The filter is a pattern as used for pathname expansion; a \fB&\fP
8397 in the pattern is replaced with the text of the word being completed.
8398 A literal \fB&\fP may be escaped with a backslash; the backslash
8399 is removed before attempting a match.
8400 Any completion that matches the pattern is removed from the list.
8401 A leading \fB!\fP negates the pattern;
8402 in this case \fBbash\fP removes
8403 any completion that does not match the pattern.
8404 If the
8405 .B nocasematch
8406 shell option is enabled,
8407 \fBbash\fP performs the match without regard to the case
8408 of alphabetic characters.
8409 .PP
8410 Finally, programmable completion adds
8411 any prefix and suffix specified with the
8412 \fB\-P\fP and \fB\-S\fP
8413 options, respectively, to each completion,
8414 and returns the result
8415 to \fBreadline\fP as the list of possible completions.
8416 .PP
8417 If the previously-applied actions do not generate any matches, and the
8418 \fB\-o dirnames\fP option was supplied to \fBcomplete\fP when the
8419 compspec was defined, \fBbash\fP attempts directory name completion.
8420 .PP
8421 If the \fB\-o plusdirs\fP option was supplied to \fBcomplete\fP when the
8422 compspec was defined, \fBbash\fP attempts directory name completion and
8423 adds any matches to the set of possible completions.
8424 .PP
8425 By default, if a compspec is found, whatever it generates is returned
8426 to the completion code as the full set of possible completions.
8427 The default \fBbash\fP completions and the \fBreadline\fP
8428 default of filename completion are disabled.
8429 If the \fB\-o bashdefault\fP option was supplied to \fBcomplete\fP when
8430 the compspec was defined,
8431 and the compspec generates no matches,
8432 \fBbash\fP attempts its default completions.
8433 If the compspec and, if attempted, the default \fBbash\fP completions
8434 generate no matches,
8435 and the \fB\-o default\fP option was supplied to
8436 \fBcomplete\fP when the compspec was defined,
8437 programmable completion performs \fBreadline\fP's default completion.
8438 .PP
8439 The options supplied to \fBcomplete\fP and \fBcompopt\fP
8440 can control how \fBreadline\fP treats the completions.
8441 For instance, the \fI\-o fullquote\fP option tells \fBreadline\fP
8442 to quote the matches as if they were filenames.
8443 See the description of \fBcomplete\fP below
8444 for details.
8445 .PP
8446 When a compspec indicates that it wants directory name completion,
8447 the programmable completion functions force \fBreadline\fP
8448 to append a slash to completed names which are symbolic links
8449 to directories, subject to the value of the
8450 \fBmark\-directories\fP \fBreadline\fP variable,
8451 regardless of the setting of the
8452 \fBmark-symlinked\-directories\fP \fBreadline\fP variable.
8453 .PP
8454 There is some support for dynamically modifying completions.
8455 This is most useful when used in combination with a default completion
8456 specified with \fBcomplete \-D\fP.
8457 It's possible for shell functions executed as completion functions
8458 to indicate that completion should be retried by returning an
8459 exit status of 124.
8460 If a shell function returns 124, and changes
8461 the compspec associated with the command on which completion is being
8462 attempted (supplied as the first argument when the function is executed),
8463 programmable completion restarts from the beginning, with an
8464 attempt to find a new compspec for that command.
8465 This can be used to build a set of completions dynamically
8466 as completion is attempted, rather than loading them all at once.
8467 .PP
8468 For instance, assuming that there is a library of compspecs, each kept in a
8469 file corresponding to the name of the command, the following default
8470 completion function would load completions dynamically:
8471 .RS
8472 .EX
8473 .nf
8474 _completion_loader()
8475 {
8476 . \*"/etc/bash_completion.d/$1.sh\*" \c
8477 .if \n(LL<80n \{\
8478 \e
8479 .br
8480 .ti +4n
8481 .\}
8482 >/dev/null 2>&1 && return 124
8483 }
8484 complete \-D \-F _completion_loader \c
8485 .if \n(LL<80n \{\
8486 \e
8487 .br
8488 .ti +4n
8489 .\}
8490 \-o bashdefault \-o default
8491 .fi
8492 .EE
8493 .RE
8494 .SH HISTORY
8495 When the
8496 .B \-o history
8497 option to the
8498 .B set
8499 builtin is enabled, the shell provides access to the
8500 \fIcommand history\fP,
8501 the list of commands previously typed.
8502 The value of the
8503 .SM
8504 .B HISTSIZE
8505 variable is used as the
8506 number of commands to save in a history list:
8507 the shell saves the text of the last
8508 .SM
8509 .B HISTSIZE
8510 commands (default 500).
8511 The shell stores each command in the history list prior to
8512 parameter and variable expansion (see
8513 .SM
8514 .B EXPANSION
8515 above) but after history expansion is performed, subject to the
8516 values of the shell variables
8517 .SM
8518 .B HISTIGNORE
8519 and
8520 .SM
8521 .BR HISTCONTROL .
8522 .PP
8523 On startup, \fBbash\fP initializes the history list
8524 by reading history entries from the
8525 file named by the
8526 .SM
8527 .B HISTFILE
8528 variable (default
8529 .FN \*~/.bash_history ).
8530 That file is referred to as the \fIhistory file\fP.
8531 The history file is truncated, if necessary,
8532 to contain no more than the number of history entries
8533 specified by the value of the
8534 .SM
8535 .B HISTFILESIZE
8536 variable.
8537 If
8538 .SM
8539 .B HISTFILESIZE
8540 is unset, or set to null, a non-numeric value,
8541 or a numeric value less than zero, the history file is not truncated.
8542 .PP
8543 When the history file is read,
8544 lines beginning with the history comment character followed immediately
8545 by a digit are interpreted as timestamps for the following history line.
8546 These timestamps are optionally displayed depending on the value of the
8547 .SM
8548 .B HISTTIMEFORMAT
8549 variable.
8550 When present, history timestamps delimit history entries, making
8551 multi-line entries possible.
8552 .PP
8553 When a shell with history enabled exits, \fBbash\fP copies the last
8554 .SM
8555 .B $HISTSIZE
8556 entries from the history list to
8557 .SM
8558 .BR $HISTFILE .
8559 If the
8560 .B histappend
8561 shell option is enabled
8562 (see the description of
8563 .B shopt
8564 under
8565 .SM
8566 .B "SHELL BUILTIN COMMANDS"
8567 below), \fBbash\fP appends the entries to the history file,
8568 otherwise it overwrites the history file.
8569 If
8570 .SM
8571 .B HISTFILE
8572 is unset or null,
8573 or if the history file is unwritable, the history is not saved.
8574 After saving the history, \fBbash\fP truncates the history file
8575 to contain no more than
8576 .SM
8577 .B HISTFILESIZE
8578 lines as described above.
8579 .PP
8580 If the
8581 .SM
8582 .B HISTTIMEFORMAT
8583 variable is set, the shell writes
8584 the timestamp information
8585 associated with each history entry to the history file,
8586 marked with the history comment character, so
8587 timestamps are preserved across shell sessions.
8588 This uses the history comment character to distinguish timestamps from
8589 other history lines.
8590 As above, when using
8591 .SM
8592 .BR HISTTIMEFORMAT ,
8593 the timestamps delimit multi-line history entries.
8594 .PP
8595 The
8596 .B fc
8597 builtin command (see
8598 .SM
8599 .B "SHELL BUILTIN COMMANDS"
8600 below) will list or edit and re-execute a portion of the history list.
8601 The
8602 .B history
8603 builtin can display or modify the history list and
8604 manipulate the history file.
8605 When using command-line editing, search commands
8606 are available in each editing mode that provide access to the
8607 history list.
8608 .PP
8609 The shell allows control over which commands are saved on the history list.
8610 The
8611 .SM
8612 .B HISTCONTROL
8613 and
8614 .SM
8615 .B HISTIGNORE
8616 variables are used to save only a subset of the commands entered.
8617 If the
8618 .B cmdhist
8619 shell option is enabled, the shell attempts to save each
8620 line of a multi-line command in the same history entry, adding
8621 semicolons where necessary to preserve syntactic correctness.
8622 The
8623 .B lithist
8624 shell option modifies \fBcmdhist\fP by saving
8625 the command with embedded newlines instead of semicolons.
8626 See the description of the
8627 .B shopt
8628 builtin below under
8629 .SM
8630 .B "SHELL BUILTIN COMMANDS"
8631 for information on setting and unsetting shell options.
8632 .SH "HISTORY EXPANSION"
8633 The shell supports a history expansion feature that
8634 is similar to the history expansion in
8635 .BR csh .
8636 This section describes what syntax features are available.
8637 .PP
8638 History expansion is enabled by default for interactive shells,
8639 and can be disabled using the
8640 .B +H
8641 option to the
8642 .B set
8643 builtin command (see
8644 .SM
8645 .B "SHELL BUILTIN COMMANDS"
8646 below).
8647 Non-interactive shells do not perform history expansion by default,
8648 but it can be enabled with
8649 .Q "set -H" .
8650 .PP
8651 History expansions introduce words from the history list into
8652 the input stream, making it easy to repeat commands, insert the
8653 arguments to a previous command into the current input line, or
8654 fix errors in previous commands quickly.
8655 .PP
8656 History expansion is performed immediately after a complete line
8657 is read, before the shell breaks it into words, and is performed
8658 on each line individually.
8659 The shell attempts to inform the history
8660 expansion functions about quoting still in effect from previous lines.
8661 .PP
8662 It takes place in two parts.
8663 The first is to determine which history list entry
8664 to use during substitution.
8665 The second is to select portions of that entry to include into
8666 the current one.
8667 .PP
8668 The entry selected from the history is the \fIevent\fP,
8669 and the portions of that entry that are acted upon are \fIwords\fP.
8670 Various \fImodifiers\fP are available to manipulate the selected words.
8671 The entry is split into words in the same fashion as when reading input,
8672 so that several \fImetacharacter\fP-separated words surrounded by
8673 quotes are considered one word.
8674 The \fIevent designator\fP selects the event, the optional
8675 \fIword designator\fP selects words from the event, and
8676 various optional \fImodifiers\fP are available to manipulate the
8677 selected words.
8678 .PP
8679 History expansions are introduced by the appearance of the
8680 history expansion character, which is \^\fB!\fP\^ by default.
8681 History expansions may appear anywhere in the input, but do not nest.
8682 .PP
8683 Only backslash (\^\fB\e\fP\^) and single quotes can quote
8684 the history expansion character, but the history expansion character is
8685 also treated as quoted if it immediately precedes the closing double quote
8686 in a double-quoted string.
8687 .PP
8688 Several characters inhibit history expansion if found immediately
8689 following the history expansion character, even if it is unquoted:
8690 space, tab, newline, carriage return, \fB=\fP,
8691 and the other shell metacharacters defined above.
8692 .PP
8693 There is a special abbreviation for substitution, active when the
8694 \fIquick substitution\fP character (described above under
8695 .BR histchars )
8696 is the first character on the line.
8697 It selects the previous history list entry, using an event designator
8698 equivalent to \fB!!\fP,
8699 and substitutes one string for another in that entry.
8700 It is described below under \fBEvent Designators\fP.
8701 This is the only history expansion that does not begin with the history
8702 expansion character.
8703 .PP
8704 Several shell options settable with the
8705 .B shopt
8706 builtin will modify history expansion behavior
8707 (see the description of the
8708 .B shopt
8709 builtin below).and
8710 If the
8711 .B histverify
8712 shell option is enabled, and
8713 .B readline
8714 is being used, history substitutions are not immediately passed to
8715 the shell parser.
8716 Instead, the expanded line is reloaded into the
8717 .B readline
8718 editing buffer for further modification.
8719 If
8720 .B readline
8721 is being used, and the
8722 .B histreedit
8723 shell option is enabled, a failed history substitution is reloaded
8724 into the
8725 .B readline
8726 editing buffer for correction.
8727 .PP
8728 The
8729 .B \-p
8730 option to the
8731 .B history
8732 builtin command shows what a history expansion will
8733 do before using it.
8734 The
8735 .B \-s
8736 option to the
8737 .B history
8738 builtin will add commands to the end of the history list
8739 without actually executing them, so that they are available for
8740 subsequent recall.
8741 .PP
8742 The shell allows control of the various characters used by the
8743 history expansion mechanism (see the description of
8744 .B histchars
8745 above under
8746 .BR "Shell Variables" ).
8747 The shell uses
8748 the history comment character to mark history timestamps when
8749 writing the history file.
8750 .SS Event Designators
8751 An event designator is a reference to an entry in the history list.
8752 The event designator
8753 consists of the portion of the word beginning with the history
8754 expansion character and ending with the word designator if present,
8755 or the end of the word.
8756 Unless the reference is absolute, events are relative to the current
8757 position in the history list.
8758 .PP
8759 .PD 0
8760 .TP
8761 .B !
8762 Start a history substitution, except when followed by a
8763 .BR blank ,
8764 newline, carriage return, =,
8765 or, when the \fBextglob\fP shell option is enabled using
8766 the \fBshopt\fP builtin, (.
8767 .TP
8768 .B !\fIn\fP
8769 Refer to history list entry
8770 .IR n .
8771 .TP
8772 .B !\-\fIn\fP
8773 Refer to the current entry minus
8774 .IR n .
8775 .TP
8776 .B !!
8777 Refer to the previous entry.
8778 This is a synonym for
8779 .Q !\-1 .
8780 .TP
8781 .B !\fIstring\fP
8782 Refer to the most recent command preceding the current position in the
8783 history list starting with
8784 .IR string .
8785 .TP
8786 .B !?\fIstring\fR\fB[?]\fP
8787 Refer to the most recent command preceding the current position in the
8788 history list containing
8789 .IR string .
8790 The trailing \fB?\fP may be omitted if
8791 .I string
8792 is followed immediately by a newline.
8793 If \fIstring\fP is missing, this uses
8794 the string from the most recent search;
8795 it is an error if there is no previous search string.
8796 .TP
8797 .B \d\s+2\*^\s-2\u\fIstring1\fP\d\s+2\*^\s-2\u\fIstring2\fP\d\s+2\*^\s-2\u
8798 Quick substitution.
8799 Repeat the previous command, replacing
8800 .I string1
8801 with
8802 .IR string2 .
8803 Equivalent to
8804 .Q !!:s\d\s+2\*^\s-2\u\fIstring1\fP\d\s+2\*^\s-2\u\fIstring2\fP\d\s+2\*^\s-2\u
8805 (see \fBModifiers\fP below).
8806 .TP
8807 .B !#
8808 The entire command line typed so far.
8809 .PD
8810 .SS Word Designators
8811 Word designators are used to select desired words from the event.
8812 They are optional; if the word designator isn't supplied, the history
8813 expansion uses the entire event.
8814 A
8815 .B :
8816 separates the event specification from the word designator.
8817 It may be omitted if the word designator begins with a
8818 .BR \*^ ,
8819 .BR $ ,
8820 .BR * ,
8821 .BR \- ,
8822 or
8823 .BR % .
8824 Words are numbered from the beginning of the line,
8825 with the first word being denoted by 0 (zero).
8826 Words are inserted into the current line separated by single spaces.
8827 .PP
8828 .PD 0
8829 .TP
8830 .B 0 (zero)
8831 The zeroth word.
8832 For the shell, this is the command word.
8833 .TP
8834 .I n
8835 The \fIn\fPth word.
8836 .TP
8837 .B \*^
8838 The first argument: word 1.
8839 .TP
8840 .B $
8841 The last word.
8842 This is usually the last argument, but will expand to the
8843 zeroth word if there is only one word in the line.
8844 .TP
8845 .B %
8846 The first word matched by the most recent
8847 .Q ?\fIstring\fP?
8848 search,
8849 if the search string begins with a character that is part of a word.
8850 By default, searches begin at the end of each line and proceed to the
8851 beginning, so the first word matched is the one closest to the end of
8852 the line.
8853 .TP
8854 .I x\fB\-\fPy
8855 A range of words;
8856 .Q \-\fIy\fP
8857 abbreviates
8858 .Q 0\-\fIy\fP .
8859 .TP
8860 .B *
8861 All of the words but the zeroth.
8862 This is a synonym for
8863 .Q \fI1\-$\fP .
8864 It is not an error to use
8865 .B *
8866 if there is just one word in the event;
8867 it expands to the empty string in that case.
8868 .TP
8869 .B x*
8870 Abbreviates \fIx\-$\fP.
8871 .TP
8872 .B x\-
8873 Abbreviates \fIx\-$\fP like \fBx*\fP, but omits the last word.
8874 If \fBx\fP is missing, it defaults to 0.
8875 .PD
8876 .PP
8877 If a word designator is supplied without an event specification, the
8878 previous command is used as the event, equivalent to \fB!!\fP.
8879 .SS Modifiers
8880 After the optional word designator, the expansion may include a
8881 sequence of one or more of the following modifiers, each preceded by a
8882 .Q : .
8883 These modify, or edit, the word or words selected from the history event.
8884 .PP
8885 .PD 0
8886 .TP
8887 .B h
8888 Remove a trailing pathname component, leaving only the head.
8889 .TP
8890 .B t
8891 Remove all leading pathname components, leaving the tail.
8892 .TP
8893 .B r
8894 Remove a trailing suffix of the form \fI.xxx\fP, leaving the
8895 basename.
8896 .TP
8897 .B e
8898 Remove all but the trailing suffix.
8899 .TP
8900 .B p
8901 Print the new command but do not execute it.
8902 .TP
8903 .B q
8904 Quote the substituted words, escaping further substitutions.
8905 .TP
8906 .B x
8907 Quote the substituted words as with
8908 .BR q ,
8909 but break into words at
8910 .B blanks
8911 and newlines.
8912 The \fBq\fP and \fBx\fP modifiers are mutually exclusive;
8913 expansion uses the last one supplied.
8914 .TP
8915 .B s/\fIold\fP/\fInew\fP/
8916 Substitute
8917 .I new
8918 for the first occurrence of
8919 .I old
8920 in the event line.
8921 Any character may be used as the delimiter in place of /.
8922 The final delimiter is optional if it is the last character of the
8923 event line.
8924 A single backslash quotes the delimiter in
8925 .I old
8926 and
8927 .IR new .
8928 If & appears in
8929 .IR new ,
8930 it is replaced with
8931 .IR old .
8932 A single backslash quotes the &.
8933 If
8934 .I old
8935 is null, it is set to the last
8936 .I old
8937 substituted, or, if no previous history substitutions took place,
8938 the last
8939 .I string
8940 in a
8941 .B !?\fIstring\fP[?]
8942 search.
8943 If
8944 .I new
8945 is null, each matching
8946 .I old
8947 is deleted.
8948 .TP
8949 .B &
8950 Repeat the previous substitution.
8951 .TP
8952 .B g
8953 Cause changes to be applied over the entire event line.
8954 This is used in conjunction with
8955 .Q \fB:s\fP
8956 (e.g.,
8957 .Q \fB:gs/\fIold\fP/\fInew\fP/\fR )
8958 or
8959 .Q \fB:&\fP .
8960 If used with
8961 .Q \fB:s\fP ,
8962 any delimiter can be used in place of /,
8963 and the final delimiter is optional
8964 if it is the last character of the event line.
8965 An \fBa\fP may be used as a synonym for \fBg\fP.
8966 .TP
8967 .B G
8968 Apply the following
8969 .Q \fBs\fP
8970 or
8971 .Q \fB&\fP
8972 modifier once to each word in the event line.
8973 .PD
8974 .SH "SHELL BUILTIN COMMANDS"
8975 .\" start of bash_builtins
8976 .zZ
8977 .if !dFN \{\
8978 .de FN
8979 \fI\|\\$1\|\fP
8980 ..
8981 .\}
8982 .PP
8983 Unless otherwise noted, each builtin command documented in this
8984 section as accepting options preceded by
8985 .B \-
8986 accepts
8987 .B \-\-
8988 to signify the end of the options.
8989 The \fB:\fP, \fBtrue\fP, \fBfalse\fP, and \fBtest\fP/\fB[\fP builtins
8990 do not accept options and do not treat \fB\-\-\fP specially.
8991 The \fBexit\fP, \fBlogout\fP, \fBreturn\fP,
8992 \fBbreak\fP, \fBcontinue\fP, \fBlet\fP,
8993 and \fBshift\fP builtins accept and process arguments beginning with
8994 \fB\-\fP without requiring \fB\-\-\fP.
8995 Other builtins that accept arguments but are not specified as accepting
8996 options interpret arguments beginning with \fB\-\fP as invalid options and
8997 require \fB\-\-\fP to prevent this interpretation.
8998 .PP
8999 .PD 0
9000 .TP
9001 \fB:\fP [\fIarguments\fP]
9002 .PD
9003 No effect; the command does nothing beyond expanding
9004 .I arguments
9005 and performing any specified
9006 redirections.
9007 The return status is zero.
9008 .TP
9009 \fB\&.\&\fP [\fB\-p\fP \fIpath\fP] \fIfilename\fP [\fIarguments\fP]
9010 .PD 0
9011 .TP
9012 \fBsource\fP [\fB\-p\fP \fIpath\fP] \fIfilename\fP [\fIarguments\fP]
9013 .PD
9014 The \fB\&.\&\fP command (\fBsource\fP) reads and execute commands from
9015 .I filename
9016 in the current shell environment and returns the exit status of the
9017 last command executed from
9018 .IR filename .
9019 .IP
9020 If \fIfilename\fP does not contain a slash, \fB\&.\&\fP searches for it.
9021 If the \fB\-p\fP option is supplied, \fB\&.\&\fP treats \fIpath\fP
9022 as a colon-separated list of directories in which to find \fIfilename\fP;
9023 otherwise, \fB\&.\&\fP uses the entries in
9024 .SM
9025 .B PATH
9026 to find the directory containing
9027 .IR filename .
9028 \fIfilename\fP does not need to be executable.
9029 When \fBbash\fP is not in posix mode, it searches
9030 the current directory if \fIfilename\fP is not found in
9031 .SM
9032 .BR PATH ,
9033 but does not search the current directory if \fB\-p\fP is supplied.
9034 If the
9035 .B sourcepath
9036 option to the
9037 .B shopt
9038 builtin command is turned off, \fB\&.\&\fP does not search
9039 .SM
9040 .BR PATH .
9041 .IP
9042 If any \fIarguments\fP are supplied, they become the positional
9043 parameters when \fIfilename\fP is executed.
9044 Otherwise the positional parameters are unchanged.
9045 .IP
9046 If the \fB\-T\fP option is enabled, \fB.\fP inherits any trap on
9047 \fBDEBUG\fP; if it is not, any \fBDEBUG\fP trap string is saved and
9048 restored around the call to \fB.\fP, and \fB.\fP unsets the
9049 \fBDEBUG\fP trap while it executes.
9050 If \fB\-T\fP is not set, and the sourced file changes
9051 the \fBDEBUG\fP trap, the new value persists after \fB.\fP completes.
9052 The return status is the status of the last command executed from
9053 \fIfilename\fP (0 if no commands are executed), and non-zero if
9054 .I filename
9055 is not found or cannot be read.
9056 .TP
9057 \fBalias\fP [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] .\|.\|.]
9058 With no arguments or with the
9059 .B \-p
9060 option, \fBalias\fP prints the list of aliases in the form
9061 \fBalias\fP \fIname\fP=\fIvalue\fP on standard output.
9062 When arguments are supplied, define an alias for
9063 each \fIname\fP whose \fIvalue\fP is given.
9064 A trailing space in \fIvalue\fP causes the next word to be
9065 checked for alias substitution when the alias is expanded
9066 during command parsing.
9067 For each \fIname\fP in the argument list for which no \fIvalue\fP
9068 is supplied, print the name and value of the alias \fIname\fP.
9069 \fBalias\fP returns true unless a \fIname\fP is given
9070 (without a corresponding =\fIvalue\fP)
9071 for which no alias has been defined.
9072 .TP
9073 \fBbg\fP [\fIjobspec\fP .\|.\|.]
9074 Resume each suspended job \fIjobspec\fP in the background, as if it
9075 had been started with
9076 .BR & .
9077 If
9078 .I jobspec
9079 is not present, the shell uses its notion of the \fIcurrent job\fP.
9080 .B bg
9081 .I jobspec
9082 returns 0 unless run when job control is disabled or, when run with
9083 job control enabled, any specified \fIjobspec\fP was not found
9084 or was started without job control.
9085 .TP
9086 \fBbind\fP [\fB\-m\fP \fIkeymap\fP] [\fB\-lsvSVX\fP]
9087 .PD 0
9088 .TP
9089 \fBbind\fP [\fB\-m\fP \fIkeymap\fP] [\fB\-q\fP \fIfunction\fP] [\fB\-u\fP \fIfunction\fP] [\fB\-r\fP \fIkeyseq\fP]
9090 .TP
9091 \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-f\fP \fIfilename\fP
9092 .TP
9093 \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-x\fP \fIkeyseq\fP[:] \fIshell\-command\fP
9094 .TP
9095 \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fIkeyseq\fP:\fIfunction\-name\fP
9096 .TP
9097 \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-p\fP|\fB\-P\fP [\fIreadline\-command\fP]
9098 .TP
9099 \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fIkeyseq\fP:\fIreadline\-command\fP
9100 .TP
9101 \fBbind\fP \fIreadline-command-line\fP
9102 .PD
9103 Display current
9104 .B readline
9105 key and function bindings, bind a key sequence to a
9106 .B readline
9107 function or macro
9108 or to a shell command, or set a
9109 .B readline
9110 variable.
9111 Each non-option argument is a key binding or command as it would appear in a
9112 .B readline
9113 initialization file such as
9114 .IR .inputrc ,
9115 but each binding or command must be passed as a separate argument;
9116 e.g., \*'\*"\eC\-x\eC\-r\*": re\-read\-init\-file\*'.
9117 In the following descriptions, output available to be re-read is formatted
9118 as commands that would appear in a
9119 .B readline
9120 initialization file or that would be supplied as individual arguments to a
9121 .B bind
9122 command.
9123 Options, if supplied, have the following meanings:
9124 .RS
9125 .PD 0
9126 .TP
9127 .B \-m \fIkeymap\fP
9128 Use
9129 .I keymap
9130 as the keymap to be affected by the subsequent bindings.
9131 Acceptable
9132 .I keymap
9133 names are
9134 \fIemacs, emacs\-standard, emacs\-meta, emacs\-ctlx, vi,
9135 vi\-move, vi\-command\fP, and
9136 .IR vi\-insert .
9137 \fIvi\fP is equivalent to \fIvi\-command\fP
9138 (\fIvi\-move\fP is also a synonym);
9139 \fIemacs\fP is equivalent to \fIemacs\-standard\fP.
9140 .TP
9141 .B \-l
9142 List the names of all \fBreadline\fP functions.
9143 .TP
9144 .B \-p
9145 Display \fBreadline\fP function names and bindings in such a way
9146 that they can be
9147 used as an argument to a subsequent
9148 \fBbind\fP command or in a \fBreadline\fP initialization file.
9149 If arguments remain after option processing, \fBbind\fP treats
9150 them as \fBreadline\fP command names and restricts output to those names.
9151 .TP
9152 .B \-P
9153 List current \fBreadline\fP function names and bindings.
9154 If arguments remain after option processing, \fBbind\fP treats
9155 them as \fBreadline\fP command names and restricts output to those names.
9156 .TP
9157 .B \-s
9158 Display \fBreadline\fP key sequences bound to macros and the strings
9159 they output in such a way that they can be used
9160 as an argument to a subsequent \fBbind\fP command
9161 or in a \fBreadline\fP initialization file.
9162 .TP
9163 .B \-S
9164 Display \fBreadline\fP key sequences bound to macros and the strings
9165 they output.
9166 .TP
9167 .B \-v
9168 Display \fBreadline\fP variable names and values in such a way that they
9169 can be
9170 used as an argument to a subsequent
9171 \fBbind\fP command or in a \fBreadline\fP initialization file.
9172 .TP
9173 .B \-V
9174 List current \fBreadline\fP variable names and values.
9175 .TP
9176 .B \-f \fIfilename\fP
9177 Read key bindings from \fIfilename\fP.
9178 .TP
9179 .B \-q \fIfunction\fP
9180 Display key sequences that invoke the named \fBreadline\fP \fIfunction\fP.
9181 .TP
9182 .B \-u \fIfunction\fP
9183 Unbind all key sequences bound to the named \fBreadline\fP \fIfunction\fP.
9184 .TP
9185 .B \-r \fIkeyseq\fP
9186 Remove any current binding for \fIkeyseq\fP.
9187 .TP
9188 .B \-x \fIkeyseq\fP[: ]\fIshell\-command\fP
9189 Cause \fIshell\-command\fP to be executed whenever \fIkeyseq\fP is
9190 entered.
9191 The separator between \fIkeyseq\fP and \fIshell\-command\fP is either
9192 whitespace or a colon optionally followed by whitespace.
9193 If the separator is whitespace, \fIshell\-command\fP
9194 must be enclosed in double quotes and \fBreadline\fP expands any of its
9195 special backslash-escapes in \fIshell\-command\fP before saving it.
9196 If the separator is a colon, any enclosing double quotes are optional, and
9197 \fBreadline\fP does not expand the command string before saving it.
9198 Since the entire key binding expression must be a single argument, it
9199 should be enclosed in single quotes.
9200 When \fIshell\-command\fP is executed, the shell sets the
9201 .SM
9202 .B READLINE_LINE
9203 variable to the contents of the \fBreadline\fP line buffer and the
9204 .SM
9205 .B READLINE_POINT
9206 and
9207 .SM
9208 .B READLINE_MARK
9209 variables to the current location of the insertion point and the saved
9210 insertion point (the mark), respectively.
9211 The shell assigns any numeric argument the user supplied to the
9212 .SM
9213 .B READLINE_ARGUMENT
9214 variable.
9215 If there was no argument, that variable is not set.
9216 If the executed command changes the value of any of
9217 .SM
9218 .BR READLINE_LINE ,
9219 .SM
9220 .BR READLINE_POINT ,
9221 or
9222 .SM
9223 .BR READLINE_MARK ,
9224 those new values will be reflected in the editing state.
9225 .TP
9226 .B \-X
9227 List all key sequences bound to shell commands and the associated commands
9228 in a format that can be reused as
9229 an argument to a subsequent \fBbind\fP command.
9230 .PD
9231 .PP
9232 The return value is 0 unless an unrecognized option is supplied or an
9233 error occurred.
9234 .RE
9235 .TP
9236 \fBbreak\fP [\fIn\fP]
9237 Exit from within a
9238 .BR for ,
9239 .BR while ,
9240 .BR until ,
9241 or
9242 .B select
9243 loop.
9244 If \fIn\fP is specified, \fBbreak\fP exits \fIn\fP enclosing loops.
9245 .I n
9246 must be \(>= 1. If
9247 .I n
9248 is greater than the number of enclosing loops, all enclosing loops
9249 are exited.
9250 The return value is 0 unless \fIn\fP is not greater than or equal to 1.
9251 .TP
9252 \fBbuiltin\fP \fIshell\-builtin\fP [\fIarguments\fP]
9253 Execute the specified shell builtin \fIshell\-builtin\fP, passing it
9254 .IR arguments ,
9255 and return its exit status.
9256 This is useful when defining a
9257 function whose name is the same as a shell builtin,
9258 retaining the functionality of the builtin within the function.
9259 The \fBcd\fP builtin is commonly redefined this way.
9260 The return status is false if
9261 .I shell\-builtin
9262 is not a shell builtin command.
9263 .TP
9264 \fBcaller\fP [\fIexpr\fP]
9265 Returns the context of any active subroutine call (a shell function or
9266 a script executed with the \fB.\fP or \fBsource\fP builtins).
9267 .IP
9268 Without \fIexpr\fP, \fBcaller\fP displays the line number and source
9269 filename of the current subroutine call.
9270 If a non-negative integer is supplied as \fIexpr\fP, \fBcaller\fP
9271 displays the line number, subroutine name, and source file corresponding
9272 to that position in the current execution call stack.
9273 This extra information may be used, for example, to print a stack trace.
9274 The current frame is frame 0.
9275 .IP
9276 The return value is 0 unless the shell is not executing a subroutine
9277 call or \fIexpr\fP does not correspond to a valid position in the
9278 call stack.
9279 .TP
9280 .PD 0
9281 \fBcd\fP [\fB\-L\fP] [\fB\-@\fP] [\fIdir\fP]
9282 .TP
9283 \fBcd\fP \fB\-P\fP [\fB\-e\fP] [\fB\-@\fP] [\fIdir\fP]
9284 .PD
9285 Change the current directory to \fIdir\fP.
9286 if \fIdir\fP is not supplied, the value of the
9287 .SM
9288 .B HOME
9289 shell variable is used as \fIdir\fP.
9290 The variable
9291 .SM
9292 .B CDPATH
9293 exists,
9294 and \fIdir\fP does not begin with a slash (/),
9295 \fBcd\fP uses it as a search path:
9296 the shell searches each directory name in
9297 .SM
9298 .B CDPATH
9299 for \fIdir\fP.
9300 Alternative directory names in
9301 .SM
9302 .B CDPATH
9303 are separated by a colon (:).
9304 A null directory name in
9305 .SM
9306 .B CDPATH
9307 is the same as the current directory, i.e.,
9308 .Q .\& .
9309 .IP
9310 The
9311 .B \-P
9312 option causes \fBcd\fP to use the physical directory structure
9313 by resolving symbolic links while traversing \fIdir\fP and
9314 before processing instances of
9315 .FN .\|.\&
9316 in \fIdir\fP (see also the
9317 .B \-P
9318 option to the
9319 .B set
9320 builtin command).
9321 .IP
9322 The
9323 .B \-L
9324 option forces \fBcd\fP to follow symbolic links by resolving the link
9325 after processing instances of
9326 .FN .\|.\&
9327 in \fIdir\fP.
9328 If
9329 .FN .\|.\&
9330 appears in \fIdir\fP, \fBcd\fP processes it by removing the
9331 immediately previous pathname component from \fIdir\fP, back to a slash
9332 or the beginning of \fIdir\fP,
9333 and verifying that the portion of \fIdir\fP it has processed to
9334 that point is still a valid directory name after removing the pathname
9335 component.
9336 If it is not a valid directory name, \fBcd\fP returns a non-zero status.
9337 If neither
9338 .B \-L
9339 nor
9340 .B \-P
9341 is supplied,
9342 .B cd
9343 behaves as if
9344 .B \-L
9345 had been supplied.
9346 .IP
9347 If the
9348 .B \-e
9349 option is supplied with
9350 .BR \-P ,
9351 and \fBcd\fP cannot successfully determine the current working directory
9352 after a successful directory change, it returns a non-zero status.
9353 .IP
9354 On systems that support it, the \fB\-@\fP option presents the extended
9355 attributes associated with a file as a directory.
9356 .IP
9357 An argument of
9358 .B \-
9359 is converted to
9360 .SM
9361 .B $OLDPWD
9362 before attempting the directory change.
9363 .IP
9364 If \fBcd\fP uses a non-empty directory name from
9365 .SM
9366 .BR CDPATH ,
9367 or if \fB\-\fP is the first argument, and the directory change is
9368 successful, \fBcd\fP writes the absolute pathname of the new
9369 working directory to the standard output.
9370 .IP
9371 If the directory change is successful, \fBcd\fP sets the value of the
9372 \fBPWD\fP environment variable to the new directory name, and sets the
9373 \fBOLDPWD\fP environment variable to the value of the current working
9374 directory before the change.
9375 .IP
9376 The return value is true if the directory was successfully changed;
9377 false otherwise.
9378 .TP
9379 \fBcommand\fP [\fB\-pVv\fP] \fIcommand\fP [\fIarg\fP .\|.\|.]
9380 The \fBcommand\fP builtin runs
9381 .I command
9382 with
9383 .I args
9384 suppressing the normal shell function lookup for \fIcommand\fP.
9385 Only builtin commands or commands found in the
9386 .SM
9387 .B PATH
9388 named \fIcommand\fP are executed.
9389 If the
9390 .B \-p
9391 option is supplied, the search for
9392 .I command
9393 is performed using a default value for
9394 .SM
9395 .B PATH
9396 that is guaranteed to find all of the standard utilities.
9397 .IP
9398 If either the
9399 .B \-V
9400 or
9401 .B \-v
9402 option is supplied, \fBcommand\fP prints a description of
9403 .IR command .
9404 The
9405 .B \-v
9406 option displays a single word indicating the command or filename
9407 used to invoke
9408 .IR command ;
9409 the
9410 .B \-V
9411 option produces a more verbose description.
9412 .IP
9413 If the
9414 .B \-V
9415 or
9416 .B \-v
9417 option is supplied, the exit status is zero if
9418 .I command
9419 was found, and non-zero if not.
9420 If neither option is supplied and an error occurred or
9421 .I command
9422 cannot be found, the exit status is 127.
9423 Otherwise, the exit status of the
9424 .B command
9425 builtin is the exit status of
9426 .IR command .
9427 .TP
9428 \fBcompgen\fP [\fB\-V\fP \fIvarname\fP] [\fIoption\fP] [\fIword\fP]
9429 Generate possible completion matches for \fIword\fP according to
9430 the \fIoption\fPs, which may be any option accepted by the
9431 .B complete
9432 builtin with the exceptions of
9433 .BR \-p ,
9434 .BR \-r ,
9435 .BR \-D ,
9436 .BR \-E ,
9437 and
9438 .BR \-I ,
9439 and write the matches to the standard output.
9440 .IP
9441 If the \fB\-V\fP option is supplied, \fBcompgen\fP stores the generated
9442 completions into the indexed array variable \fIvarname\fP instead of writing
9443 them to the standard output.
9444 .IP
9445 When using the \fB\-F\fP or \fB\-C\fP options, the various shell variables
9446 set by the programmable completion facilities, while available, will not
9447 have useful values.
9448 .IP
9449 The matches will be generated in the same way as if the programmable
9450 completion code had generated them directly from a completion specification
9451 with the same flags.
9452 If \fIword\fP is specified, only those completions matching \fIword\fP
9453 will be displayed or stored.
9454 .IP
9455 The return value is true unless an invalid option is supplied, or no
9456 matches were generated.
9457 .TP
9458 \fBcomplete\fP [\fB\-abcdefgjksuv\fP] [\fB\-o\fP \fIcomp-option\fP] [\fB\-DEI\fP] [\fB\-A\fP \fIaction\fP]
9459 .br
9460 [\fB\-G\fP \fIglobpat\fP] [\fB\-W\fP \fIwordlist\fP] [\fB\-F\fP \fIfunction\fP] [\fB\-C\fP \fIcommand\fP]
9461 .br
9462 [\fB\-X\fP \fIfilterpat\fP] [\fB\-P\fP \fIprefix\fP] \
9463 [\fB\-S\fP \fIsuffix\fP] \fIname\fP [\fIname\fP .\|.\|.]
9464 .PD 0
9465 .TP
9466 \fBcomplete\fP \fB\-pr\fP [\fB\-DEI\fP] [\fIname\fP .\|.\|.]
9467 .PD
9468 Specify how arguments to each \fIname\fP should be completed.
9469 .IP
9470 If the \fB\-p\fP option is supplied, or if no options or \fIname\fPs
9471 are supplied, print existing completion specifications
9472 in a way that allows them to be reused as input.
9473 The \fB\-r\fP option removes a completion specification for
9474 each \fIname\fP, or, if no \fIname\fPs are supplied, all
9475 completion specifications.
9476 .IP
9477 The \fB\-D\fP option indicates that other supplied options and actions should
9478 apply to the
9479 .Q default
9480 command completion; that is, completion attempted
9481 on a command for which no completion has previously been defined.
9482 The \fB\-E\fP option indicates that other supplied options and actions should
9483 apply to
9484 .Q empty
9485 command completion; that is, completion attempted on a
9486 blank line.
9487 The \fB\-I\fP option indicates that other supplied options and actions should
9488 apply to completion on the initial non-assignment word on the line, or after
9489 a command delimiter such as \fB;\fP or \fB|\fP, which is usually command
9490 name completion.
9491 If multiple options are supplied, the \fB\-D\fP option takes precedence
9492 over \fB\-E\fP, and both take precedence over \fB\-I\fP.
9493 If any of \fB\-D\fP, \fB\-E\fP, or \fB\-I\fP are supplied, any other
9494 \fIname\fP arguments are ignored; these completions only apply to the case
9495 specified by the option.
9496 .IP
9497 The process of applying these completion specifications when
9498 attempting word completion is described
9499 .ie \n(zZ=1 in \fIbash\fP(1).
9500 .el above under \fBProgrammable Completion\fP.
9501 .IP
9502 Other options, if specified, have the following meanings.
9503 The arguments to the \fB\-G\fP, \fB\-W\fP, and \fB\-X\fP options
9504 (and, if necessary, the \fB\-P\fP and \fB\-S\fP options)
9505 should be quoted to protect them from expansion before the
9506 .B complete
9507 builtin is invoked.
9508 .IP
9509 .RS
9510 .PD 0
9511 .TP 8
9512 \fB\-o\fP \fIcomp-option\fP
9513 The \fIcomp-option\fP controls several aspects of the compspec's behavior
9514 beyond the simple generation of completions.
9515 \fIcomp-option\fP may be one of:
9516 .RS
9517 .TP 8
9518 .B bashdefault
9519 Perform the rest of the default \fBbash\fP completions if the compspec
9520 generates no matches.
9521 .TP 8
9522 .B default
9523 Use \fBreadline\fP's default filename completion if the compspec generates
9524 no matches.
9525 .TP 8
9526 .B dirnames
9527 Perform directory name completion if the compspec generates no matches.
9528 .TP 8
9529 .B filenames
9530 Tell \fBreadline\fP that the compspec generates filenames, so it can perform
9531 any filename\-specific processing (such as adding a slash to directory names,
9532 quoting special characters, or suppressing trailing spaces).
9533 This is intended to be used with shell functions.
9534 .TP 8
9535 .B fullquote
9536 Tell \fBreadline\fP to quote all the completed words even if they are not
9537 filenames.
9538 .TP 8
9539 .B noquote
9540 Tell \fBreadline\fP not to quote the completed words if they are filenames
9541 (quoting filenames is the default).
9542 .TP 8
9543 .B nosort
9544 Tell \fBreadline\fP not to sort the list of possible completions
9545 alphabetically.
9546 .TP 8
9547 .B nospace
9548 Tell \fBreadline\fP not to append a space (the default) to words completed
9549 at the end of the line.
9550 .TP 8
9551 .B plusdirs
9552 After generating any matches defined by the compspec,
9553 attempt directory name completion and add any
9554 matches to the results of the other actions.
9555 .RE
9556 .TP 8
9557 \fB\-A\fP \fIaction\fP
9558 The \fIaction\fP may be one of the following to generate a list of possible
9559 completions:
9560 .RS
9561 .TP 8
9562 .B alias
9563 Alias names.
9564 May also be specified as \fB\-a\fP.
9565 .TP 8
9566 .B arrayvar
9567 Array variable names.
9568 .TP 8
9569 .B binding
9570 \fBReadline\fP key binding names.
9571 .TP 8
9572 .B builtin
9573 Names of shell builtin commands.
9574 May also be specified as \fB\-b\fP.
9575 .TP 8
9576 .B command
9577 Command names.
9578 May also be specified as \fB\-c\fP.
9579 .TP 8
9580 .B directory
9581 Directory names.
9582 May also be specified as \fB\-d\fP.
9583 .TP 8
9584 .B disabled
9585 Names of disabled shell builtins.
9586 .TP 8
9587 .B enabled
9588 Names of enabled shell builtins.
9589 .TP 8
9590 .B export
9591 Names of exported shell variables.
9592 May also be specified as \fB\-e\fP.
9593 .TP 8
9594 .B file
9595 File and directory names, similar to \fBreadline\fP's filename completion.
9596 May also be specified as \fB\-f\fP.
9597 .TP 8
9598 .B function
9599 Names of shell functions.
9600 .TP 8
9601 .B group
9602 Group names.
9603 May also be specified as \fB\-g\fP.
9604 .TP 8
9605 .B helptopic
9606 Help topics as accepted by the \fBhelp\fP builtin.
9607 .TP 8
9608 .B hostname
9609 Hostnames, as taken from the file specified by the
9610 .SM
9611 .B HOSTFILE
9612 shell variable.
9613 .TP 8
9614 .B job
9615 Job names, if job control is active.
9616 May also be specified as \fB\-j\fP.
9617 .TP 8
9618 .B keyword
9619 Shell reserved words.
9620 May also be specified as \fB\-k\fP.
9621 .TP 8
9622 .B running
9623 Names of running jobs, if job control is active.
9624 .TP 8
9625 .B service
9626 Service names.
9627 May also be specified as \fB\-s\fP.
9628 .TP 8
9629 .B setopt
9630 Valid arguments for the \fB\-o\fP option to the \fBset\fP builtin.
9631 .TP 8
9632 .B shopt
9633 Shell option names as accepted by the \fBshopt\fP builtin.
9634 .TP 8
9635 .B signal
9636 Signal names.
9637 .TP 8
9638 .B stopped
9639 Names of stopped jobs, if job control is active.
9640 .TP 8
9641 .B user
9642 User names.
9643 May also be specified as \fB\-u\fP.
9644 .TP 8
9645 .B variable
9646 Names of all shell variables.
9647 May also be specified as \fB\-v\fP.
9648 .RE
9649 .TP 8
9650 \fB\-C\fP \fIcommand\fP
9651 \fIcommand\fP is executed in a subshell environment, and its output is
9652 used as the possible completions.
9653 Arguments are passed as with the \fB\-F\fP option.
9654 .TP 8
9655 \fB\-F\fP \fIfunction\fP
9656 The shell function \fIfunction\fP is executed in the current shell
9657 environment.
9658 When the function is executed,
9659 the first argument (\fB$1\fP) is the name of the command whose arguments are
9660 being completed,
9661 the second argument (\fB$2\fP) is the word being completed, and
9662 the third argument (\fB$3\fP) is the word preceding the word being
9663 completed on the current command line.
9664 When \fIfunction\fP finishes,
9665 programmable completion retrieves
9666 the possible completions from the value of the
9667 .SM
9668 .B COMPREPLY
9669 array variable.
9670 .TP 8
9671 \fB\-G\fP \fIglobpat\fP
9672 Expand the pathname expansion pattern \fIglobpat\fP to generate
9673 the possible completions.
9674 .TP 8
9675 \fB\-P\fP \fIprefix\fP
9676 Add \fIprefix\fP to the beginning of each possible completion
9677 after all other options have been applied.
9678 .TP 8
9679 \fB\-S\fP \fIsuffix\fP
9680 Append \fIsuffix\fP to each possible completion
9681 after all other options have been applied.
9682 .TP 8
9683 \fB\-W\fP \fIwordlist\fP
9684 Split the \fIwordlist\fP using the characters in the
9685 .SM
9686 .B IFS
9687 special variable as delimiters, and expand each resulting word.
9688 Shell quoting is honored within \fIwordlist\fP,
9689 in order to provide a
9690 mechanism for the words to contain shell metacharacters or characters
9691 in the value of
9692 .SM
9693 .BR IFS .
9694 The possible completions are the members of the resultant list which
9695 match a prefix of the word being completed.
9696 .TP 8
9697 \fB\-X\fP \fIfilterpat\fP
9698 \fIfilterpat\fP is a pattern as used for pathname expansion.
9699 It is applied to the list of possible completions generated by the
9700 preceding options and arguments, and each completion matching
9701 \fIfilterpat\fP is removed from the list.
9702 A leading \fB!\fP in \fIfilterpat\fP negates the pattern; in this
9703 case, any completion not matching \fIfilterpat\fP is removed.
9704 .PD
9705 .PP
9706 The return value is true unless an invalid option is supplied, an option
9707 other than
9708 .BR \-p ,
9709 .BR \-r ,
9710 .BR \-D ,
9711 .BR \-E ,
9712 or
9713 .B \-I
9714 is supplied without a \fIname\fP
9715 argument, an attempt is made to remove a completion specification for
9716 a \fIname\fP for which no specification exists, or
9717 an error occurs adding a completion specification.
9718 .RE
9719 .TP
9720 \fBcompopt\fP [\fB\-o\fP \fIoption\fP] [\fB\-DEI\fP] [\fB+o\fP \fIoption\fP] [\fIname\fP]
9721 Modify completion options for each \fIname\fP according to the
9722 \fIoption\fPs, or for the
9723 currently-executing completion if no \fIname\fPs are supplied.
9724 If no \fIoption\fPs are supplied, display the completion options for each
9725 \fIname\fP or the current completion.
9726 The possible values of \fIoption\fP are those valid for the \fBcomplete\fP
9727 builtin described above.
9728 .IP
9729 The \fB\-D\fP option indicates that other supplied options should
9730 apply to the
9731 .Q default
9732 command completion;
9733 the \fB\-E\fP option indicates that other supplied options should
9734 apply to
9735 .Q empty
9736 command completion; and
9737 the \fB\-I\fP option indicates that other supplied options should
9738 apply to completion on the initial word on the line.
9739 These are determined in the same way as the \fBcomplete\fP builtin.
9740 .IP
9741 If multiple options are supplied, the \fB\-D\fP option takes precedence
9742 over \fB\-E\fP, and both take precedence over \fB\-I\fP.
9743 .IP
9744 The return value is true unless an invalid option is supplied, an attempt
9745 is made to modify the options for a \fIname\fP for which no completion
9746 specification exists, or an output error occurs.
9747 .TP
9748 \fBcontinue\fP [\fIn\fP]
9749 \fBcontinue\fP resumes the next iteration of the enclosing
9750 .BR for ,
9751 .BR while ,
9752 .BR until ,
9753 or
9754 .B select
9755 loop.
9756 If
9757 .I n
9758 is specified, \fBbash\fP resumes the \fIn\fPth enclosing loop.
9759 .I n
9760 must be \(>= 1.
9761 If
9762 .I n
9763 is greater than the number of enclosing loops, the shell resumes
9764 the last enclosing loop
9765 (the
9766 .Q top-level
9767 loop).
9768 The return value is 0 unless \fIn\fP is not greater than or equal to 1.
9769 .TP
9770 \fBdeclare\fP [\fB\-aAfFgiIlnrtux\fP] [\fB\-p\fP] \
9771 [\fIname\fP[=\fIvalue\fP] .\|.\|.]
9772 .PD 0
9773 .TP
9774 \fBtypeset\fP [\fB\-aAfFgiIlnrtux\fP] [\fB\-p\fP] \
9775 [\fIname\fP[=\fIvalue\fP] .\|.\|.]
9776 .PD
9777 Declare variables and/or give them attributes.
9778 If no \fIname\fPs are given then display the values of variables
9779 or functions.
9780 The
9781 .B \-p
9782 option will display the attributes and values of each
9783 .IR name .
9784 When
9785 .B \-p
9786 is used with \fIname\fP arguments, additional options,
9787 other than \fB\-f\fP and \fB\-F\fP, are ignored.
9788 .IP
9789 When
9790 .B \-p
9791 is supplied without \fIname\fP arguments,
9792 \fBdeclare\fP will display the attributes and values
9793 of all variables having the attributes specified by the additional options.
9794 If no other options are supplied with \fB\-p\fP, \fBdeclare\fP will
9795 display the attributes and values of all shell variables.
9796 The \fB\-f\fP option restricts the display to shell functions.
9797 .IP
9798 The
9799 .B \-F
9800 option inhibits the display of function definitions; only the
9801 function name and attributes are printed.
9802 If the \fBextdebug\fP shell option is enabled using \fBshopt\fP,
9803 the source file name and line number where each \fIname\fP
9804 is defined are displayed as well.
9805 The
9806 .B \-F
9807 option implies
9808 .BR \-f .
9809 .IP
9810 The
9811 .B \-g
9812 option forces variables to be created or modified at the global scope,
9813 even when \fBdeclare\fP is executed in a shell function.
9814 It is ignored when \fBdeclare\fP is not executed in a shell function.
9815 .IP
9816 The
9817 .B \-I
9818 option causes local variables to inherit the attributes
9819 (except the \fInameref\fP attribute)
9820 and value of any existing variable with the same
9821 \fIname\fP at a surrounding scope.
9822 If there is no existing variable, the local variable is initially unset.
9823 .IP
9824 The following options can
9825 be used to restrict output to variables with the specified attribute or
9826 to give variables attributes:
9827 .RS
9828 .PD 0
9829 .TP
9830 .B \-a
9831 Each \fIname\fP is an indexed array variable (see
9832 .B Arrays
9833 .ie \n(zZ=1 in \fIbash\fP(1)).
9834 .el above).
9835 .TP
9836 .B \-A
9837 Each \fIname\fP is an associative array variable (see
9838 .B Arrays
9839 .ie \n(zZ=1 in \fIbash\fP(1)).
9840 .el above).
9841 .TP
9842 .B \-f
9843 Each \fIname\fP refers to a shell function.
9844 .TP
9845 .B \-i
9846 The variable is treated as an integer;
9847 arithmetic evaluation (see
9848 .SM
9849 .B "ARITHMETIC EVALUATION"
9850 .ie \n(zZ=1 in \fIbash\fP(1))
9851 .el above)
9852 is performed when the variable is assigned a value.
9853 .TP
9854 .B \-l
9855 When the variable is assigned a value, all upper-case characters are
9856 converted to lower-case.
9857 The upper-case attribute is disabled.
9858 .TP
9859 .B \-n
9860 Give each \fIname\fP the \fInameref\fP attribute, making
9861 it a name reference to another variable.
9862 That other variable is defined by the value of \fIname\fP.
9863 All references, assignments, and attribute modifications
9864 to \fIname\fP, except those using or changing the
9865 \fB\-n\fP attribute itself, are performed on the variable referenced by
9866 \fIname\fP's value.
9867 The nameref attribute cannot be applied to array variables.
9868 .TP
9869 .B \-r
9870 Make \fIname\fPs readonly.
9871 These names cannot then be assigned values
9872 by subsequent assignment statements or unset.
9873 .TP
9874 .B \-t
9875 Give each \fIname\fP the \fItrace\fP attribute.
9876 Traced functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps from
9877 the calling shell.
9878 The trace attribute has no special meaning for variables.
9879 .TP
9880 .B \-u
9881 When the variable is assigned a value, all lower-case characters are
9882 converted to upper-case.
9883 The lower-case attribute is disabled.
9884 .TP
9885 .B \-x
9886 Mark each \fIname\fP for export to subsequent commands via the environment.
9887 .PD
9888 .PP
9889 Using
9890 .Q +
9891 instead of
9892 .Q \-
9893 turns off the specified
9894 attribute instead, with the exceptions that \fB+a\fP and \fB+A\fP
9895 may not be used to destroy array variables and \fB+r\fP will not
9896 remove the readonly attribute.
9897 .PP
9898 When used in a function,
9899 .B declare
9900 and
9901 .B typeset
9902 make each
9903 \fIname\fP local, as with the
9904 .B local
9905 command,
9906 unless the \fB\-g\fP option is supplied.
9907 If a variable name is followed by =\fIvalue\fP, the value of
9908 the variable is set to \fIvalue\fP.
9909 When using \fB\-a\fP or \fB\-A\fP and the compound assignment syntax to
9910 create array variables, additional attributes do not take effect until
9911 subsequent assignments.
9912 .PP
9913 The return value is 0 unless an invalid option is encountered,
9914 an attempt is made to define a function using
9915 .Q "\-f foo=bar" ,
9916 an attempt is made to assign a value to a readonly variable,
9917 an attempt is made to assign a value to an array variable without
9918 using the compound assignment syntax (see
9919 .B Arrays
9920 .ie \n(zZ=1 in \fIbash\fP(1)),
9921 .el above),
9922 one of the \fInames\fP is not a valid shell variable name,
9923 an attempt is made to turn off readonly status for a readonly variable,
9924 an attempt is made to turn off array status for an array variable,
9925 or an attempt is made to display a non-existent function with \fB\-f\fP.
9926 .RE
9927 .TP
9928 .B dirs [\fB\-clpv\fP] [+\fIn\fP] [\-\fIn\fP]
9929 Without options, display the list of currently remembered directories.
9930 The default display is on a single line with directory names separated
9931 by spaces.
9932 Directories are added to the list with the
9933 .B pushd
9934 command; the
9935 .B popd
9936 command removes entries from the list.
9937 The current directory is always the first directory in the stack.
9938 .IP
9939 Options, if supplied, have the following meanings:
9940 .RS
9941 .PD 0
9942 .TP
9943 .B \-c
9944 Clears the directory stack by deleting all of the entries.
9945 .TP
9946 .B \-l
9947 Produces a listing using full pathnames;
9948 the default listing format uses a tilde to denote the home directory.
9949 .TP
9950 .B \-p
9951 Print the directory stack with one entry per line.
9952 .TP
9953 .B \-v
9954 Print the directory stack with one entry per line,
9955 prefixing each entry with its index in the stack.
9956 .TP
9957 \fB+\fP\fIn\fP
9958 Displays the \fIn\fPth entry counting from the left of the list
9959 shown by
9960 .B dirs
9961 when invoked without options, starting with zero.
9962 .TP
9963 \fB\-\fP\fIn\fP
9964 Displays the \fIn\fPth entry counting from the right of the list
9965 shown by
9966 .B dirs
9967 when invoked without options, starting with zero.
9968 .PD
9969 .PP
9970 The return value is 0 unless an
9971 invalid option is supplied or \fIn\fP indexes beyond the end
9972 of the directory stack.
9973 .RE
9974 .TP
9975 \fBdisown\fP [\fB\-ar\fP] [\fB\-h\fP] [\fIid\fP .\|.\|.]
9976 Without options, remove each
9977 .I id
9978 from the table of active jobs.
9979 Each \fIid\fP may be a job specification \fIjobspec\fP
9980 or a process ID \fIpid\fP;
9981 if \fIid\fP is a \fIpid\fP,
9982 \fBdisown\fP uses the job containing \fIpid\fP as \fIjobspec\fP.
9983 .IP
9984 If the \fB\-h\fP option is supplied,
9985 \fBdisown\fP does not remove the jobs corresponding to each
9986 .I id
9987 from the jobs table,
9988 but rather marks them so the shell does not send
9989 .SM
9990 .B SIGHUP
9991 to the job if the shell receives a
9992 .SM
9993 .BR SIGHUP .
9994 .IP
9995 If no
9996 .I id
9997 is supplied, the
9998 .B \-a
9999 option means to remove or mark all jobs; the
10000 .B \-r
10001 option without an
10002 .I id
10003 argument removes or marks running jobs.
10004 If no
10005 .I id
10006 is supplied, and neither the \fB\-a\fP nor the \fB\-r\fP option
10007 is supplied, \fBdisown\fP removes or marks the current job.
10008 .IP
10009 The return value is 0 unless an
10010 .I id
10011 does not specify a valid job.
10012 .TP
10013 \fBecho\fP [\fB\-neE\fP] [\fIarg\fP .\|.\|.]
10014 Output the \fIarg\fPs, separated by spaces, followed by a newline.
10015 The return status is 0 unless a write error occurs.
10016 If \fB\-n\fP is specified, the trailing newline is not printed.
10017 .IP
10018 If the \fB\-e\fP option is given, \fBecho\fP interprets
10019 the following backslash-escaped characters.
10020 The
10021 .B \-E
10022 option disables interpretation of these escape characters,
10023 even on systems where they are interpreted by default.
10024 The \fBxpg_echo\fP shell option determines
10025 whether or not \fBecho\fP interprets any options
10026 and expands these escape characters.
10027 .B echo
10028 does not interpret \fB\-\-\fP to mean the end of options.
10029 .IP
10030 .B echo
10031 interprets the following escape sequences:
10032 .RS
10033 .PD 0
10034 .TP
10035 .B \ea
10036 alert (bell)
10037 .TP
10038 .B \eb
10039 backspace
10040 .TP
10041 .B \ec
10042 suppress further output
10043 .TP
10044 .B \ee
10045 .TP
10046 .B \eE
10047 an escape character
10048 .TP
10049 .B \ef
10050 form feed
10051 .TP
10052 .B \en
10053 new line
10054 .TP
10055 .B \er
10056 carriage return
10057 .TP
10058 .B \et
10059 horizontal tab
10060 .TP
10061 .B \ev
10062 vertical tab
10063 .TP
10064 .B \e\e
10065 backslash
10066 .TP
10067 .B \e0\fInnn\fP
10068 The eight-bit character whose value is the octal value \fInnn\fP
10069 (zero to three octal digits).
10070 .TP
10071 .B \ex\fIHH\fP
10072 The eight-bit character whose value is the hexadecimal value \fIHH\fP
10073 (one or two hex digits).
10074 .TP
10075 .B \eu\fIHHHH\fP
10076 The Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
10077 \fIHHHH\fP (one to four hex digits).
10078 .TP
10079 .B \eU\fIHHHHHHHH\fP
10080 The Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
10081 \fIHHHHHHHH\fP (one to eight hex digits).
10082 .PD
10083 .PP
10084 \fBecho\fP writes any unrecognized backslash-escaped characters unchanged.
10085 .RE
10086 .TP
10087 \fBenable\fP [\fB\-a\fP] [\fB\-dnps\fP] [\fB\-f\fP \fIfilename\fP] \
10088 [\fIname\fP .\|.\|.]
10089 Enable and disable builtin shell commands.
10090 Disabling a builtin allows an executable file which has the same name
10091 as a shell builtin to be executed without specifying a full pathname,
10092 even though the shell normally searches for builtins before files.
10093 .IP
10094 If \fB\-n\fP is supplied, each \fIname\fP is disabled; otherwise,
10095 \fIname\fPs are enabled.
10096 For example, to use the
10097 .B test
10098 binary found using
10099 .SM
10100 .B PATH
10101 instead of the shell builtin version, run
10102 .QN "enable \-n test" .
10103 .IP
10104 If no \fIname\fP arguments are supplied, or if the
10105 .B \-p
10106 option is supplied, print a list of shell builtins.
10107 With no other option arguments, the list consists of all enabled
10108 shell builtins.
10109 If \fB\-n\fP is supplied, print only disabled builtins.
10110 If \fB\-a\fP is supplied, the list printed includes all builtins, with an
10111 indication of whether or not each is enabled.
10112 The \fB\-s\fP option means to restrict the output to the
10113 .SM POSIX
10114 \fIspecial\fP builtins.
10115 .IP
10116 The
10117 .B \-f
10118 option means to load the new builtin command
10119 .I name
10120 from shared object
10121 .IR filename ,
10122 on systems that support dynamic loading.
10123 If \fIfilename\fP does not contain a slash,
10124 \fBBash\fP will use the value of the \fBBASH_LOADABLES_PATH\fP variable as a
10125 colon-separated list of directories in which to search for \fIfilename\fP.
10126 The default for \fBBASH_LOADABLES_PATH\fP is system-dependent,
10127 and may include
10128 .Q .\&
10129 to force a search of the current directory.
10130 The
10131 .B \-d
10132 option will delete a builtin previously loaded with \fB\-f\fP.
10133 If \fI\-s\fP is used with \fI\-f\fP, the new builtin becomes a
10134 .SM POSIX
10135 special builtin.
10136 .IP
10137 If no options are supplied and a \fIname\fP is not a shell builtin,
10138 \fBenable\fP will attempt to load \fIname\fP from a shared
10139 object named \fIname\fP, as if the command were
10140 .QN "enable \-f \fIname name\fP" .
10141 .IP
10142 The return value is 0 unless a
10143 .I name
10144 is not a shell builtin or there is an error loading a new builtin
10145 from a shared object.
10146 .TP
10147 \fBeval\fP [\fIarg\fP .\|.\|.]
10148 Concatenate the \fIarg\fPs together into a single command, separating
10149 them with spaces.
10150 \fBBash\fP then reads and execute this command, and returns its exit status
10151 as the return status of \fBeval\fP.
10152 If there are no
10153 .IR args ,
10154 or only null arguments,
10155 .B eval
10156 returns 0.
10157 .TP
10158 \fBexec\fP [\fB\-cl\fP] [\fB\-a\fP \fIname\fP] [\fIcommand\fP [\fIarguments\fP]]
10159 If
10160 .I command
10161 is specified, it replaces the shell without creating a new process.
10162 \fIcommand\fP cannot be a shell builtin or function.
10163 The
10164 .I arguments
10165 become the arguments to \fIcommand\fP.
10166 If the
10167 .B \-l
10168 option is supplied,
10169 the shell places a dash at the beginning of the zeroth argument passed to
10170 .IR command .
10171 This is what
10172 .IR login (1)
10173 does. The
10174 .B \-c
10175 option causes
10176 .I command
10177 to be executed with an empty environment.
10178 If
10179 .B \-a
10180 is supplied, the shell passes
10181 .I name
10182 as the zeroth argument to the executed command.
10183 .IP
10184 If
10185 .I command
10186 cannot be executed for some reason, a non-interactive shell exits,
10187 unless the
10188 .B execfail
10189 shell option is enabled.
10190 In that case, it returns a non-zero status.
10191 An interactive shell returns a non-zero status if the file cannot be executed.
10192 A subshell exits unconditionally if \fBexec\fP fails.
10193 .IP
10194 If
10195 .I command
10196 is not specified, any redirections take effect in the current shell,
10197 and the return status is 0. If there is a redirection error, the
10198 return status is 1.
10199 .TP
10200 \fBexit\fP [\fIn\fP]
10201 Cause the shell to exit with a status of \fIn\fP.
10202 If
10203 .I n
10204 is omitted, the exit status is that of the last command executed.
10205 Any trap on
10206 .SM
10207 .B EXIT
10208 is executed before the shell terminates.
10209 .TP
10210 \fBexport\fP [\fB\-fn\fP\^] [\fIname\fP[=\fIvalue\fP]] .\|.\|.
10211 .PD 0
10212 .TP
10213 .B export \-p [\fB\-f\fP\^]
10214 .PD
10215 The supplied
10216 .I names
10217 are marked for automatic export to the environment of
10218 subsequently executed commands.
10219 If the
10220 .B \-f
10221 option is given, the
10222 .I names
10223 refer to functions.
10224 .IP
10225 The
10226 .B \-n
10227 option unexports, or removes the export attribute, from each \fIname\fP.
10228 If no
10229 .I names
10230 are given, or if only the
10231 .B \-p
10232 option is supplied,
10233 \fBexport\fP displays a list of names of all exported
10234 variables on the standard output.
10235 Using \fB\-p\fP and \fB\-f\fP together displays exported functions.
10236 The \fB\-p\fP option displays output in a form that may be reused as input.
10237 .IP
10238 \fBexport\fP allows the value of a variable to be set when it is exported
10239 or unexported by following the variable name with =\fIvalue\fP.
10240 This sets the value of the variable to \fIvalue\fP while modifying the
10241 export attribute.
10242 .B export
10243 returns an exit status of 0 unless an invalid option is
10244 encountered,
10245 one of the \fInames\fP is not a valid shell variable name, or
10246 .B \-f
10247 is supplied with a
10248 .I name
10249 that is not a function.
10250 .TP
10251 \fBfalse\fP
10252 Does nothing; returns a non-zero status.
10253 .TP
10254 \fBfc\fP [\fB\-e\fP \fIename\fP] [\fB\-lnr\fP] [\fIfirst\fP] [\fIlast\fP]
10255 .PD 0
10256 .TP
10257 \fBfc\fP \fB\-s\fP [\fIpat\fP=\fIrep\fP] [\fIcmd\fP]
10258 .PD
10259 The first form selects a range of commands from
10260 .I first
10261 to
10262 .I last
10263 from the history list and displays or edits and re-executes them.
10264 .I First
10265 and
10266 .I last
10267 may be specified as a string (to locate the last command beginning
10268 with that string) or as a number (an index into the history list,
10269 where a negative number is used as an offset from the current
10270 command number).
10271 .IP
10272 When listing, a \fIfirst\fP or \fIlast\fP of 0 is equivalent to \-1
10273 and \-0 is equivalent to the current command
10274 (usually the \fBfc\fP command);
10275 otherwise 0 is equivalent to \-1 and \-0 is invalid.
10276 If
10277 .I last
10278 is not specified, it is set to
10279 the current command for listing (so that
10280 .QN "fc \-l \-10"
10281 prints the last 10 commands) and to
10282 .I first
10283 otherwise.
10284 If
10285 .I first
10286 is not specified, it is set to the previous
10287 command for editing and \-16 for listing.
10288 .IP
10289 If the
10290 .B \-l
10291 option is supplied, the commands are listed on the standard output.
10292 The
10293 .B \-n
10294 option suppresses
10295 the command numbers when listing.
10296 The
10297 .B \-r
10298 option reverses the order of
10299 the commands.
10300 .IP
10301 Otherwise, \fBfc\fP invokes the editor named by
10302 .I ename
10303 on a file containing those commands.
10304 If
10305 .I ename
10306 is not supplied, \fBfc\fP uses the value of the
10307 .SM
10308 .B FCEDIT
10309 variable, and
10310 the value of
10311 .SM
10312 .B EDITOR
10313 if
10314 .SM
10315 .B FCEDIT
10316 is not set.
10317 If neither variable is set, \fBfc\fP uses
10318 .FN vi.
10319 When editing is complete, \fBfc\fP reads the file containing
10320 the edited commands and echoes and executes them.
10321 .IP
10322 In the second form, \fBfc\fP re-executes \fIcommand\fP
10323 after replacing each instance of \fIpat\fP with \fIrep\fP.
10324 \fICommand\fP is interpreted the same as \fIfirst\fP above.
10325 .IP
10326 A useful alias to use with \fBfc\fP is
10327 .Q "r=\*"fc \-s\*"" ,
10328 so that typing
10329 .Q "r cc"
10330 runs the last command beginning with
10331 .Q cc
10332 and typing
10333 .Q r
10334 re-executes the last command.
10335 .IP
10336 If the first form is used, the return value is zero unless an invalid
10337 option is encountered or
10338 .I first
10339 or
10340 .I last
10341 specify history lines out of range.
10342 When editing and re-executing a file of commands,
10343 the return value is the value of the last command executed
10344 or failure if an error occurs with the temporary file.
10345 If the second form is used, the return status
10346 is that of the re-executed command, unless
10347 .I cmd
10348 does not specify a valid history entry, in which case
10349 .B fc
10350 returns a non-zero status.
10351 .TP
10352 \fBfg\fP [\fIjobspec\fP]
10353 Resume
10354 .I jobspec
10355 in the foreground, and make it the current job.
10356 If
10357 .I jobspec
10358 is not present, \fBfg\fP uses the shell's notion of the \fIcurrent job\fP.
10359 The return value is that of the command placed into the foreground,
10360 or failure if run when job control is disabled or, when run with
10361 job control enabled, if
10362 .I jobspec
10363 does not specify a valid job or
10364 .I jobspec
10365 specifies a job that was started without job control.
10366 .TP
10367 \fBgetopts\fP \fIoptstring\fP \fIname\fP [\fIarg\fP .\|.\|.]
10368 .B getopts
10369 is used by shell scripts and functions to parse positional parameters
10370 and obtain options and their arguments.
10371 .I optstring
10372 contains the option characters to be recognized; if a character
10373 is followed by a colon, the option is expected to have an
10374 argument, which should be separated from it by white space.
10375 The colon and question mark characters may not be used as
10376 option characters.
10377 .IP
10378 Each time it is invoked,
10379 .B getopts
10380 places the next option in the shell variable
10381 .IR name ,
10382 initializing
10383 .I name
10384 if it does not exist,
10385 and the index of the next argument to be processed into the
10386 variable
10387 .SM
10388 .BR OPTIND .
10389 .SM
10390 .B OPTIND
10391 is initialized to 1 each time the shell or a shell script
10392 is invoked.
10393 When an option requires an argument,
10394 .B getopts
10395 places that argument into the variable
10396 .SM
10397 .BR OPTARG .
10398 .IP
10399 The shell does not reset
10400 .SM
10401 .B OPTIND
10402 automatically; it must be manually reset between multiple
10403 calls to
10404 .B getopts
10405 within the same shell invocation to use a new set of parameters.
10406 .IP
10407 When it reaches the end of options, \fBgetopts\fP exits with a
10408 return value greater than zero.
10409 .SM
10410 .B OPTIND
10411 is set to the index of the first non-option argument,
10412 and \fIname\fP is set to ?.
10413 .IP
10414 .B getopts
10415 normally parses the positional parameters, but if more arguments are
10416 supplied as
10417 .I arg
10418 values,
10419 .B getopts
10420 parses those instead.
10421 .IP
10422 .B getopts
10423 can report errors in two ways.
10424 If the first character of
10425 .I optstring
10426 is a colon, \fBgetopts\fP uses
10427 .I silent
10428 error reporting.
10429 In normal operation, \fBgetopts\fP prints diagnostic messages
10430 when it encounters invalid options or missing option arguments.
10431 If the variable
10432 .SM
10433 .B OPTERR
10434 is set to 0,
10435 .B getopts
10436 does not display any error messages,
10437 even if the first character of
10438 .I optstring
10439 is not a colon.
10440 .IP
10441 If
10442 .B getopts
10443 detects an invalid option, it places ? into
10444 .I name
10445 and, if not silent,
10446 prints an error message and unsets
10447 .SM
10448 .BR OPTARG .
10449 If
10450 .B getopts
10451 is silent, it assigns the option character found to
10452 .SM
10453 .B OPTARG
10454 and does not print a diagnostic message.
10455 .IP
10456 If a required argument is not found, and
10457 .B getopts
10458 is not silent, it sets the value of \fIname\fP to
10459 a question mark (\^\fB?\fP\^), unsets
10460 .SM
10461 .BR OPTARG ,
10462 and prints a diagnostic message.
10463 If
10464 .B getopts
10465 is silent, it sets the value of \fIname\fP to a colon (\^\fB:\fP\^)
10466 and sets
10467 .SM
10468 .B OPTARG
10469 to the option character found.
10470 .IP
10471 .B getopts
10472 returns true if an option, specified or unspecified, is found.
10473 It returns false if the end of options is encountered or an
10474 error occurs.
10475 .TP
10476 \fBhash\fP [\fB\-lr\fP] [\fB\-p\fP \fIfilename\fP] [\fB\-dt\fP] [\fIname\fP]
10477 Each time \fBhash\fP is invoked, it remembers
10478 the full pathname of the command
10479 .I name
10480 as determined by searching
10481 the directories in
10482 .BR $PATH .
10483 Any previously-remembered pathname associated with \fIname\fP is discarded.
10484 If the
10485 .B \-p
10486 option is supplied, \fBhash\fP uses
10487 .I filename
10488 as the full pathname of the command.
10489 .IP
10490 The
10491 .B \-r
10492 option causes the shell to forget all
10493 remembered locations.
10494 Assigning to the \fBPATH\fP variable also clears all hashed filenames.
10495 The
10496 .B \-d
10497 option causes the shell to forget the remembered location of each \fIname\fP.
10498 .IP
10499 If the
10500 .B \-t
10501 option is supplied, \fBhash\fP prints the full pathname corresponding to
10502 each \fIname\fP.
10503 If multiple \fIname\fP arguments are supplied with \fB\-t\fP,
10504 \fBhash\fP prints the \fIname\fP before the corresponding hashed
10505 full pathname.
10506 The
10507 .B \-l
10508 option displays output in a format that may be reused as input.
10509 .IP
10510 If no arguments are given, or if only \fB\-l\fP is supplied,
10511 \fBhash\fP prints information about remembered commands.
10512 The \fB\-t\fP, \fB\-d\fP, and \fB\-p\fP options (the options that
10513 act on the \fIname\fP arguments) are mutually exclusive.
10514 Only one will be active.
10515 If more than one is supplied, \fB\-t\fP has higher priority than
10516 \fB\-p\fP, and both have higher priority than \fB\-d\fP.
10517 .IP
10518 The return status is zero unless a
10519 .I name
10520 is not found or an invalid option is supplied.
10521 .TP
10522 \fBhelp\fP [\fB\-dms\fP] [\fIpattern\fP]
10523 Display helpful information about builtin commands.
10524 If
10525 .I pattern
10526 is specified,
10527 .B help
10528 gives detailed help on all commands matching
10529 .I pattern
10530 as described below;
10531 otherwise it displays a list of
10532 all the builtins and shell compound commands.
10533 .IP
10534 Options, if supplied, have the follow meanings:
10535 .RS
10536 .TP
10537 .PD 0
10538 .B \-d
10539 Display a short description of each \fIpattern\fP
10540 .TP
10541 .B \-m
10542 Display the description of each \fIpattern\fP in a manpage-like format
10543 .TP
10544 .B \-s
10545 Display only a short usage synopsis for each \fIpattern\fP
10546 .PD
10547 .RE
10548 .IP
10549 If \fIpattern\fP contains pattern matching characters
10550 (see
10551 .SM
10552 .B "Pattern Matching"
10553 above)
10554 it's treated as a shell pattern and
10555 \fBhelp\fP prints the description of each
10556 help topic matching \fIpattern\fP.
10557 .IP
10558 If not, and \fIpattern\fP exactly matches the name of a help topic,
10559 \fBhelp\fP prints the description
10560 associated with that topic.
10561 Otherwise, \fBhelp\fP performs prefix matching and
10562 prints the descriptions of all matching help topics.
10563 .IP
10564 The return status is 0 unless no command matches
10565 .IR pattern .
10566 .TP
10567 \fBhistory [\fIn\fP]
10568 .PD 0
10569 .TP
10570 \fBhistory\fP \fB\-c\fP
10571 .TP
10572 \fBhistory \-d\fP \fIoffset\fP
10573 .TP
10574 \fBhistory \-d\fP \fIstart\fP-\fIend\fP
10575 .TP
10576 \fBhistory\fP \fB\-anrw\fP [\fIfilename\fP]
10577 .TP
10578 \fBhistory\fP \fB\-p\fP \fIarg\fP [\fIarg\fP .\|.\|.]
10579 .TP
10580 \fBhistory\fP \fB\-s\fP \fIarg\fP [\fIarg\fP .\|.\|.]
10581 .PD
10582 With no options, display the command history list with numbers.
10583 Entries prefixed with a
10584 .B *
10585 have been modified.
10586 An argument of
10587 .I n
10588 lists only the last
10589 .I n
10590 entries.
10591 If the shell variable
10592 .SM
10593 .B HISTTIMEFORMAT
10594 is set and not null,
10595 it is used as a format string for
10596 .IR strftime (3)
10597 to display the time stamp associated with each displayed history entry.
10598 If
10599 .B history
10600 uses
10601 .SM
10602 .BR HISTTIMEFORMAT ,
10603 it does not print an intervening space between the formatted time stamp
10604 and the history entry.
10605 .IP
10606 If \fIfilename\fP is supplied, \fBhistory\fP uses it as the
10607 name of the history file; if not, it uses the value of
10608 .SM
10609 .BR HISTFILE .
10610 If \fIfilename\fP is not supplied and
10611 .SM
10612 .B HISTFILE
10613 is unset or null, the \fB\-a, \-n, \-r,\fP and \fB\-w\fP options
10614 have no effect.
10615 .IP
10616 Options, if supplied, have the following meanings:
10617 .RS
10618 .PD 0
10619 .TP
10620 .B \-c
10621 Clear the history list by deleting all the entries.
10622 This can be used with the other options to replace the history list.
10623 .TP
10624 \fB\-d\fP \fIoffset\fP
10625 Delete the history entry at position \fIoffset\fP.
10626 If \fIoffset\fP is negative, it is interpreted as relative to one greater
10627 than the last history position, so negative indices count back from the
10628 end of the history, and an index of \-1 refers to the current
10629 \fBhistory \-d\fP command.
10630 .TP
10631 \fB\-d\fP \fIstart\fP\-\fIend\fP
10632 Delete the range of history entries between positions \fIstart\fP and
10633 \fIend\fP, inclusive.
10634 Positive and negative values for \fIstart\fP and \fIend\fP
10635 are interpreted as described above.
10636 .TP
10637 .B \-a
10638 Append the
10639 .Q new
10640 history lines to the history file.
10641 These are history lines entered since the beginning of the current
10642 \fBbash\fP session, but not already appended to the history file.
10643 .TP
10644 .B \-n
10645 Read the history lines not already read from the history file
10646 and add them to the current history list.
10647 These are lines appended to the history file since the beginning of the
10648 current \fBbash\fP session.
10649 .TP
10650 .B \-r
10651 Read the history file and append its contents to the current history list.
10652 .TP
10653 .B \-w
10654 Write the current history list to the history file, overwriting
10655 the history file.
10656 .TP
10657 .B \-p
10658 Perform history substitution on the following \fIargs\fP and display
10659 the result on the standard output,
10660 without storing the results in the history list.
10661 Each \fIarg\fP must be quoted to disable normal history expansion.
10662 .TP
10663 .B \-s
10664 Store the
10665 .I args
10666 in the history list as a single entry.
10667 The last command in the
10668 history list is removed before adding the
10669 .IR args .
10670 .PD
10671 .RE
10672 .IP
10673 If the
10674 .SM
10675 .B HISTTIMEFORMAT
10676 variable is set, \fBhistory\fP writes the time stamp information
10677 associated with each history entry to the history file,
10678 marked with the history comment character as described above.
10679 When the history file is read, lines beginning with the history
10680 comment character followed immediately by a digit are interpreted
10681 as timestamps for the following history entry.
10682 .IP
10683 The return value is 0 unless an invalid option is encountered, an
10684 error occurs while reading or writing the history file, an invalid
10685 \fIoffset\fP or range is supplied as an argument to \fB\-d\fP, or the
10686 history expansion supplied as an argument to \fB\-p\fP fails.
10687 .TP
10688 \fBjobs\fP [\fB\-lnprs\fP] [ \fIjobspec\fP .\|.\|. ]
10689 .PD 0
10690 .TP
10691 \fBjobs\fP \fB\-x\fP \fIcommand\fP [ \fIargs\fP .\|.\|. ]
10692 .PD
10693 The first form lists the active jobs.
10694 The options have the following meanings:
10695 .RS
10696 .PD 0
10697 .TP
10698 .B \-l
10699 List process IDs in addition to the normal information.
10700 .TP
10701 .B \-n
10702 Display information only about jobs that have changed status since
10703 the user was last notified of their status.
10704 .TP
10705 .B \-p
10706 List only the process ID of the job's process group leader.
10707 .TP
10708 .B \-r
10709 Display only running jobs.
10710 .TP
10711 .B \-s
10712 Display only stopped jobs.
10713 .PD
10714 .RE
10715 .IP
10716 If
10717 .I jobspec
10718 is supplied, \fBjobs\fP restricts output to information about that job.
10719 The return status is 0 unless an invalid option is encountered
10720 or an invalid
10721 .I jobspec
10722 is supplied.
10723 .IP
10724 If the
10725 .B \-x
10726 option is supplied,
10727 .B jobs
10728 replaces any
10729 .I jobspec
10730 found in
10731 .I command
10732 or
10733 .I args
10734 with the corresponding process group ID, and executes
10735 .IR command ,
10736 passing it
10737 .IR args ,
10738 returning its exit status.
10739 .TP
10740 \fBkill\fP [\fB\-s\fP \fIsigspec\fP | \fB\-n\fP \fIsignum\fP | \fB\-\fP\fIsigspec\fP] \
10741 \fIid\fP [ .\|.\|. ]
10742 .PD 0
10743 .TP
10744 \fBkill\fP \fB\-l\fP|\fB\-L\fP [\fIsigspec\fP | \fIexit_status\fP]
10745 .PD
10746 Send the signal specified by
10747 .I sigspec
10748 or
10749 .I signum
10750 to the processes named by each
10751 .IR id .
10752 Each
10753 .I id
10754 may be a job specification \fIjobspec\fP
10755 or a process ID \fIpid\fP.
10756 .I sigspec
10757 is either a case-insensitive signal name such as
10758 .SM
10759 .B SIGKILL
10760 (with or without the
10761 .SM
10762 .B SIG
10763 prefix) or a signal number;
10764 .I signum
10765 is a signal number.
10766 If
10767 .I sigspec
10768 is not supplied, then
10769 .B kill
10770 sends
10771 .SM
10772 .BR SIGTERM .
10773 .IP
10774 The
10775 .B \-l
10776 option lists the signal names.
10777 If any arguments are supplied when
10778 .B \-l
10779 is given,
10780 .B kill
10781 lists the names of the signals corresponding to the arguments,
10782 and the return status is 0.
10783 The \fIexit_status\fP argument to
10784 .B \-l
10785 is a number specifying either a signal number or the exit status of
10786 a process terminated by a signal;
10787 if it is supplied, \fBkill\fP prints the name of the signal that caused
10788 the process to terminate.
10789 \fBkill\fP assumes that process exit statuses are greater than 128;
10790 anything less than that is a signal number.
10791 The
10792 .B \-L
10793 option is equivalent to \fB\-l\fP.
10794 .IP
10795 .B kill
10796 returns true if at least one signal was successfully sent, or false
10797 if an error occurs or an invalid option is encountered.
10798 .TP
10799 \fBlet\fP \fIarg\fP [\fIarg\fP .\|.\|.]
10800 Each
10801 .I arg
10802 is evaluated as an arithmetic expression (see
10803 .SM
10804 .B "ARITHMETIC EVALUATION"
10805 .ie \n(zZ=1 in \fIbash\fP(1)).
10806 .el above).
10807 If the last
10808 .I arg
10809 evaluates to 0,
10810 .B let
10811 returns 1; otherwise
10812 .B let
10813 returns 0.
10814 .TP
10815 \fBlocal\fP [\fIoption\fP] [\fIname\fP[=\fIvalue\fP] .\|.\|. | \- ]
10816 For each argument, create a local variable named
10817 .I name
10818 and assign it
10819 .IR value .
10820 The \fIoption\fP can be any of the options accepted by \fBdeclare\fP.
10821 When
10822 .B local
10823 is used within a function, it causes the variable
10824 .I name
10825 to have a visible scope restricted to that function and its children.
10826 It is an error to use
10827 .B local
10828 when not within a function.
10829 .IP
10830 If \fIname\fP is \-, it makes the set of shell options
10831 local to the function in which \fBlocal\fP is invoked:
10832 any shell options changed using the \fBset\fP builtin inside
10833 the function after the call to \fBlocal\fP are restored to their
10834 original values when the function returns.
10835 The restore is performed as if a series of \fBset\fP commands were
10836 executed to restore the values that were in place before the function.
10837 .IP
10838 With no operands,
10839 .B local
10840 writes a list of local variables to the standard output.
10841 .IP
10842 The return status is 0 unless
10843 .B local
10844 is used outside a function, an invalid
10845 .I name
10846 is supplied, or
10847 \fIname\fP is a readonly variable.
10848 .TP
10849 .B logout [\fIn\fP]
10850 Exit a login shell,
10851 returning a status of \fIn\fP to the shell's parent.
10852 .TP
10853 \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]
10854 .PD 0
10855 .TP
10856 \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]
10857 .PD
10858 Read lines from the standard input,
10859 or from file descriptor
10860 .I fd
10861 if the
10862 .B \-u
10863 option is supplied,
10864 into the indexed array variable
10865 .IR array .
10866 The variable
10867 .SM
10868 .B MAPFILE
10869 is the default \fIarray\fP.
10870 Options, if supplied, have the following meanings:
10871 .RS
10872 .PD 0
10873 .TP
10874 .B \-d
10875 Use the first character of \fIdelim\fP to terminate each input line,
10876 rather than newline.
10877 If \fIdelim\fP is the empty string, \fBmapfile\fP will terminate a line
10878 when it reads a NUL character.
10879 .TP
10880 .B \-n
10881 Copy at most
10882 .I count
10883 lines.
10884 If \fIcount\fP is 0, copy all lines.
10885 .TP
10886 .B \-O
10887 Begin assigning to
10888 .I array
10889 at index
10890 .IR origin .
10891 The default index is 0.
10892 .TP
10893 .B \-s
10894 Discard the first \fIcount\fP lines read.
10895 .TP
10896 .B \-t
10897 Remove a trailing \fIdelim\fP (default newline) from each line read.
10898 .TP
10899 .B \-u
10900 Read lines from file descriptor \fIfd\fP instead of the standard input.
10901 .TP
10902 .B \-C
10903 Evaluate
10904 .I callback
10905 each time \fIquantum\fP lines are read.
10906 The \fB\-c\fP option specifies
10907 .IR quantum .
10908 .TP
10909 .B \-c
10910 Specify the number of lines read between each call to
10911 .IR callback .
10912 .PD
10913 .RE
10914 .IP
10915 If
10916 .B \-C
10917 is specified without
10918 .BR \-c ,
10919 the default quantum is 5000.
10920 When \fIcallback\fP is evaluated, it is supplied the index of the next
10921 array element to be assigned and the line to be assigned to that element
10922 as additional arguments.
10923 \fIcallback\fP is evaluated after the line is read but before the
10924 array element is assigned.
10925 .IP
10926 If not supplied with an explicit origin, \fBmapfile\fP will clear \fIarray\fP
10927 before assigning to it.
10928 .IP
10929 \fBmapfile\fP returns zero unless an invalid option or option
10930 argument is supplied, \fIarray\fP is invalid or unassignable, or if
10931 \fIarray\fP is not an indexed array.
10932 .TP
10933 \fBpopd\fP [\-\fBn\fP] [+\fIn\fP] [\-\fIn\fP]
10934 Remove entries from the directory stack.
10935 The elements are numbered from 0 starting at the first directory
10936 listed by \fBdirs\fP, so \fBpopd\fP is equivalent to
10937 .Q "popd +0."
10938 With no arguments, \fBpopd\fP removes the top directory from the stack,
10939 and changes to the new top directory.
10940 Arguments, if supplied, have the following meanings:
10941 .RS
10942 .PD 0
10943 .TP
10944 .B \-n
10945 Suppress the normal change of directory when removing directories
10946 from the stack, only manipulate the stack.
10947 .TP
10948 \fB+\fP\fIn\fP
10949 Remove the \fIn\fPth entry counting from the left of the list
10950 shown by
10951 .BR dirs ,
10952 starting with zero, from the stack.
10953 For example:
10954 .Q "popd +0"
10955 removes the first directory,
10956 .Q "popd +1"
10957 the second.
10958 .TP
10959 \fB\-\fP\fIn\fP
10960 Remove the \fIn\fPth entry counting from the right of the list
10961 shown by
10962 .BR dirs ,
10963 starting with zero. For example:
10964 .Q "popd \-0"
10965 removes the last directory,
10966 .Q "popd \-1"
10967 the next to last.
10968 .PD
10969 .RE
10970 .IP
10971 If the top element of the directory stack is modified, and
10972 the \fI\-n\fP option was not supplied, \fBpopd\fP uses the \fBcd\fP
10973 builtin to change to the directory at the top of the stack.
10974 If the \fBcd\fP fails, \fBpopd\fP returns a non-zero value.
10975 .IP
10976 Otherwise,
10977 .B popd
10978 returns false if an invalid option is supplied, the directory stack
10979 is empty, or \fIn\fP specifies a non-existent directory stack entry.
10980 .IP
10981 If the
10982 .B popd
10983 command is successful,
10984 \fBbash\fP runs
10985 .B dirs
10986 to show the final contents of the directory stack,
10987 and the return status is 0.
10988 .TP
10989 \fBprintf\fP [\fB\-v\fP \fIvar\fP] \fIformat\fP [\fIarguments\fP]
10990 Write the formatted \fIarguments\fP to the standard output under the
10991 control of the \fIformat\fP.
10992 The \fB\-v\fP option assigns the output to the variable
10993 \fIvar\fP rather than printing it to the standard output.
10994 .IP
10995 The \fIformat\fP is a character string which contains three types of objects:
10996 plain characters, which are simply copied to standard output, character
10997 escape sequences, which are converted and copied to the standard output, and
10998 format specifications, each of which causes printing of the next successive
10999 \fIargument\fP.
11000 In addition to the standard
11001 .IR printf (3)
11002 format characters
11003 .BR cCsSndiouxXeEfFgGaA ,
11004 \fBprintf\fP interprets the following additional format specifiers:
11005 .RS
11006 .PD 0
11007 .TP
11008 .B %b
11009 causes
11010 \fBprintf\fP to expand backslash escape sequences in the corresponding
11011 \fIargument\fP
11012 in the same way as \fBecho \-e\fP.
11013 .TP
11014 .B %q
11015 causes \fBprintf\fP to output the corresponding
11016 \fIargument\fP in a format that can be reused as shell input.
11017 \fB%q\fP and \fB%Q\fP use the \fB$\*'\*'\fP quoting style if any characters
11018 in the argument string require it, and backslash quoting otherwise.
11019 If the format string uses the \fIprintf\fP alternate form, these two
11020 formats quote the argument string using single quotes.
11021 .TP
11022 .B %Q
11023 like \fB%q\fP, but applies any supplied precision to the \fIargument\fP
11024 before quoting it.
11025 .TP
11026 .B %(\fIdatefmt\fP)T
11027 causes \fBprintf\fP to output the date-time string resulting from using
11028 \fIdatefmt\fP as a format string for
11029 .IR strftime (3).
11030 The corresponding \fIargument\fP is an integer representing the number of
11031 seconds since the epoch.
11032 This format specifier recognizes two special argument values:
11033 \-1 represents the current time,
11034 and \-2 represents the time the shell was invoked.
11035 If no argument is specified, conversion behaves as if \-1 had been supplied.
11036 This is an exception to the usual \fBprintf\fP behavior.
11037 .PD
11038 .RE
11039 .IP
11040 The %b, %q, and %T format specifiers all use the field width and precision
11041 arguments from the format specification and write that many bytes from
11042 (or use that wide a field for) the expanded argument, which usually
11043 contains more characters than the original.
11044 .IP
11045 The %n format specifier accepts a corresponding argument that is treated
11046 as a shell variable name.
11047 .IP
11048 The %s and %c format specifiers accept an l (long) modifier, which forces
11049 them to convert the argument string to a wide-character string and apply
11050 any supplied field width and precision in terms of characters, not bytes.
11051 The %S and %C format specifiers are equivalent to %ls and %lc, respectively.
11052 .\" .IP
11053 .\" The %s format specifier understands the "altform" flag (#) and behaves
11054 .\" identically to the %b format specifier if it's supplied.
11055 .IP
11056 Arguments to non-string format specifiers are treated as C constants,
11057 except that a leading plus or minus sign is allowed, and if the leading
11058 character is a single or double quote, the value is the numeric value of
11059 the following character, using the current locale.
11060 .IP
11061 The \fIformat\fP is reused as necessary to consume all of the \fIarguments\fP.
11062 If the \fIformat\fP requires more \fIarguments\fP than are supplied, the
11063 extra format specifications behave as if a zero value or null string, as
11064 appropriate, had been supplied.
11065 The return value is zero on success,
11066 non-zero if an invalid option is supplied or a write or assignment error
11067 occurs.
11068 .TP
11069 \fBpushd\fP [\fB\-n\fP] [+\fIn\fP] [\-\fIn\fP]
11070 .PD 0
11071 .TP
11072 \fBpushd\fP [\fB\-n\fP] [\fIdir\fP]
11073 .PD
11074 Add a directory to the top of the directory stack, or rotate
11075 the stack, making the new top of the stack the current working
11076 directory.
11077 With no arguments, \fBpushd\fP exchanges the top two elements of
11078 the directory stack.
11079 Arguments, if supplied, have the following meanings:
11080 .RS
11081 .PD 0
11082 .TP
11083 .B \-n
11084 Suppress the normal change of directory when rotating or
11085 adding directories to the stack, only manipulate the stack.
11086 .TP
11087 \fB+\fP\fIn\fP
11088 Rotate the stack so that the \fIn\fPth directory
11089 (counting from the left of the list shown by
11090 .BR dirs ,
11091 starting with zero)
11092 is at the top.
11093 .TP
11094 \fB\-\fP\fIn\fP
11095 Rotates the stack so that the \fIn\fPth directory
11096 (counting from the right of the list shown by
11097 .BR dirs ,
11098 starting with zero) is at the top.
11099 .TP
11100 .I dir
11101 Adds
11102 .I dir
11103 to the directory stack at the top.
11104 .PD
11105 .RE
11106 .IP
11107 After the stack has been modified, if the \fB\-n\fP option was not
11108 supplied, \fBpushd\fP uses the \fBcd\fP builtin to change to the
11109 directory at the top of the stack.
11110 If the \fBcd\fP fails, \fBpushd\fP returns a non-zero value.
11111 .IP
11112 Otherwise, if no arguments are supplied,
11113 .B pushd
11114 returns zero unless the directory stack is empty.
11115 When rotating the directory stack,
11116 .B pushd
11117 returns zero unless the directory stack is empty or
11118 \fIn\fP specifies a non-existent directory stack element.
11119 .IP
11120 If the
11121 .B pushd
11122 command is successful,
11123 \fBbash\fP runs
11124 .B dirs
11125 to show the final contents of the directory stack.
11126 .TP
11127 \fBpwd\fP [\fB\-LP\fP]
11128 Print the absolute pathname of the current working directory.
11129 The pathname printed contains no symbolic links if the
11130 .B \-P
11131 option is supplied or the
11132 .B \-o physical
11133 option to the
11134 .B set
11135 builtin command is enabled.
11136 If the
11137 .B \-L
11138 option is used, the pathname printed may contain symbolic links.
11139 The return status is 0 unless an error occurs while
11140 reading the name of the current directory or an
11141 invalid option is supplied.
11142 .TP
11143 \fBread\fP [\fB\-Eers\fP] [\fB\-a\fP \fIaname\fP] \
11144 [\fB\-d\fP \fIdelim\fP] [\fB\-i\fP \fItext\fP] \
11145 [\fB\-n\fP \fInchars\fP] [\fB\-N\fP \fInchars\fP] \
11146 [\fB\-p\fP \fIprompt\fP] [\fB\-t\fP \fItimeout\fP] \
11147 [\fB\-u\fP \fIfd\fP] [\fIname\fP .\|.\|.]
11148 Read one line from the standard input, or from the file descriptor
11149 \fIfd\fP supplied as an argument to the \fB\-u\fP option,
11150 split it into words as described
11151 .ie \n(zZ=1 in \fIbash\fP (1)
11152 .el above
11153 under \fBWord Splitting\fP,
11154 and assign the first word to the first
11155 .IR name ,
11156 the second word to the second
11157 .IR name ,
11158 and so on.
11159 If there are more words than names, the remaining words and their
11160 intervening delimiters are assigned to the last
11161 .IR name .
11162 If there are fewer words read from the input stream than names,
11163 the remaining names are assigned empty values.
11164 The characters in the value of the
11165 .SM
11166 .B IFS
11167 variable
11168 are used to split the line into words using the same rules the shell
11169 uses for expansion (described
11170 .ie \n(zZ=1 in \fIbash\fP (1)
11171 .el above
11172 under \fBWord Splitting\fP).
11173 The backslash character (\fB\e\fP) removes any special
11174 meaning for the next character read and is used for line continuation.
11175 .IP
11176 Options, if supplied, have the following meanings:
11177 .RS
11178 .PD 0
11179 .TP
11180 .B \-a \fIaname\fP
11181 The words are assigned to sequential indices of the array variable
11182 .IR aname ,
11183 starting at 0.
11184 .I aname
11185 is unset before any new values are assigned.
11186 Other \fIname\fP arguments are ignored.
11187 .TP
11188 .B \-d \fIdelim\fP
11189 The first character of \fIdelim\fP terminates the input line,
11190 rather than newline.
11191 If \fIdelim\fP is the empty string, \fBread\fP will terminate a line
11192 when it reads a NUL character.
11193 .TP
11194 .B \-e
11195 If the standard input is coming from a terminal,
11196 \fBread\fP uses
11197 .B readline
11198 (see
11199 .SM
11200 .B READLINE
11201 .ie \n(zZ=1 in \fIbash\fP(1))
11202 .el above)
11203 to obtain the line.
11204 \fBReadline\fP uses the current
11205 (or default, if line editing was not previously active)
11206 editing settings, but uses \fBreadline\fP's default filename completion.
11207 .TP
11208 .B \-E
11209 If the standard input is coming from a terminal,
11210 \fBread\fP uses
11211 .B readline
11212 (see
11213 .SM
11214 .B READLINE
11215 .ie \n(zZ=1 in \fIbash\fP(1))
11216 .el above)
11217 to obtain the line.
11218 .B Readline
11219 uses the current (or default, if line editing was not previously
11220 active) editing settings, but uses bash's default completion, including
11221 programmable completion.
11222 .TP
11223 .B \-i \fItext\fP
11224 If
11225 .B readline
11226 is being used to read the line, \fBread\fP places \fItext\fP into
11227 the editing buffer before editing begins.
11228 .TP
11229 .B \-n \fInchars\fP
11230 \fBread\fP returns after reading \fInchars\fP characters rather than
11231 waiting for a complete line of input,
11232 unless it encounters EOF or \fBread\fP times out,
11233 but honors a delimiter if it reads fewer
11234 than \fInchars\fP characters before the delimiter.
11235 .TP
11236 .B \-N \fInchars\fP
11237 \fBread\fP returns after reading exactly \fInchars\fP characters rather
11238 than waiting for a complete line of input,
11239 unless it encounters EOF or \fBread\fP times out.
11240 Any delimiter characters in the input are
11241 not treated specially and do not cause \fBread\fP to return until
11242 it has read \fInchars\fP characters.
11243 The result is not split on the characters in \fBIFS\fP; the intent is
11244 that the variable is assigned exactly the characters read
11245 (with the exception of backslash; see the \fB\-r\fP option below).
11246 .TP
11247 .B \-p \fIprompt\fP
11248 Display \fIprompt\fP on standard error, without a
11249 trailing newline, before attempting to read any input, but
11250 only if input is coming from a terminal.
11251 .TP
11252 .B \-r
11253 Backslash does not act as an escape character.
11254 The backslash is considered to be part of the line.
11255 In particular, a backslash-newline pair may not then be used as a line
11256 continuation.
11257 .TP
11258 .B \-s
11259 Silent mode.
11260 If input is coming from a terminal, characters are not echoed.
11261 .TP
11262 .B \-t \fItimeout\fP
11263 Cause \fBread\fP to time out and return failure if it does not read
11264 a complete line of input (or a specified number of characters)
11265 within \fItimeout\fP seconds.
11266 \fItimeout\fP may be a decimal number with a fractional portion following
11267 the decimal point.
11268 This option is only effective if \fBread\fP is reading input from a
11269 terminal, pipe, or other special file; it has no effect when reading
11270 from regular files.
11271 If \fBread\fP times out, it saves any partial input read into
11272 the specified variable \fIname\fP, and the exit status is greater than 128.
11273 If \fItimeout\fP is 0, \fBread\fP returns immediately, without trying to
11274 read any data.
11275 In this case, the exit status is 0 if input is available on the specified
11276 file descriptor, or the read will return EOF, non-zero otherwise.
11277 .TP
11278 .B \-u \fIfd\fP
11279 Read input from file descriptor \fIfd\fP instead of the standard input.
11280 .PD
11281 .RE
11282 .IP
11283 Other than the case where \fIdelim\fP is the empty string, \fBread\fP
11284 ignores any NUL characters in the input.
11285 .IP
11286 If no
11287 .I names
11288 are supplied, \fBread\fP assigns the line read,
11289 without the ending delimiter but otherwise unmodified,
11290 to the variable
11291 .SM
11292 .BR REPLY .
11293 .IP
11294 The exit status is zero, unless end-of-file is encountered, \fBread\fP
11295 times out (in which case the status is greater than 128),
11296 a variable assignment error (such as assigning to a readonly variable) occurs,
11297 or an invalid file descriptor is supplied as the argument to \fB\-u\fP.
11298 .TP
11299 \fBreadonly\fP [\fB\-aAf\fP] [\fB\-p\fP] [\fIname\fP[=\fIword\fP] .\|.\|.]
11300 .PD
11301 The given
11302 \fInames\fP are marked readonly; the values of these
11303 .I names
11304 may not be changed by subsequent assignment or unset.
11305 If the
11306 .B \-f
11307 option is supplied, each \fIname\fP refers to a shell function.
11308 The
11309 .B \-a
11310 option restricts the variables to indexed arrays; the
11311 .B \-A
11312 option restricts the variables to associative arrays.
11313 If both options are supplied,
11314 .B \-A
11315 takes precedence.
11316 If no
11317 .I name
11318 arguments are supplied, or if the
11319 .B \-p
11320 option is supplied, print a list of all readonly names.
11321 The other options may be used to restrict the output to a subset of
11322 the set of readonly names.
11323 The
11324 .B \-p
11325 option displays output in a format that may be reused as input.
11326 .IP
11327 \fBreadonly\fP allows the value of a variable to be set at the same time
11328 the readonly attribute is changed by following the variable name with
11329 =\fIvalue\fP.
11330 This sets the value of the variable is to \fIvalue\fP while modifying
11331 the readonly attribute.
11332 .IP
11333 The return status is 0 unless an invalid option is encountered,
11334 one of the
11335 .I names
11336 is not a valid shell variable name, or
11337 .B \-f
11338 is supplied with a
11339 .I name
11340 that is not a function.
11341 .TP
11342 \fBreturn\fP [\fIn\fP]
11343 Stop executing a shell function or sourced file and return the value
11344 specified by
11345 .I n
11346 to its caller.
11347 If
11348 .I n
11349 is omitted, the return status is that of the last command
11350 executed.
11351 If \fBreturn\fP is executed by a trap handler, the last command used to
11352 determine the status is the last command executed before the trap handler.
11353 If \fBreturn\fP is executed during a \fBDEBUG\fP trap, the last command
11354 used to determine the status is the last command executed by the trap
11355 handler before \fBreturn\fP was invoked.
11356 .IP
11357 When
11358 .B return
11359 is used to terminate execution of a script being executed by the
11360 .B .
11361 (\fBsource\fP) command, it causes the shell to stop executing
11362 that script and return either
11363 .I n
11364 or the exit status of the last command executed within the
11365 script as the exit status of the script.
11366 If \fIn\fP is supplied, the return value is its least significant
11367 8 bits.
11368 .IP
11369 Any command associated with the \fBRETURN\fP trap is executed
11370 before execution resumes after the function or script.
11371 .IP
11372 The return status is non-zero if
11373 .B return
11374 is supplied a non-numeric argument, or is used outside a
11375 function and not during execution of a script by \fB.\fP\^ or \fBsource\fP.
11376 .TP
11377 \fBset\fP [\fB\-abefhkmnptuvxBCEHPT\fP] [\fB\-o\fP \fIoption\-name\fP] \
11378 [\fB\-\-\fP] [\fB\-\fP] [\fIarg\fP .\|.\|.]
11379 .PD 0
11380 .TP
11381 \fBset\fP [\fB+abefhkmnptuvxBCEHPT\fP] [\fB+o\fP \fIoption\-name\fP] \
11382 [\fB\-\-\fP] [\fB\-\fP] [\fIarg\fP .\|.\|.]
11383 .TP
11384 \fBset \-o\fP
11385 .TP
11386 \fBset +o\fP
11387 .PD
11388 Without options, display the name and value of each shell variable
11389 in a format that can be reused as input
11390 for setting or resetting the currently-set variables.
11391 Read-only variables cannot be reset.
11392 In posix mode, only shell variables are listed.
11393 The output is sorted according to the current locale.
11394 When options are specified, they set or unset shell attributes.
11395 Any arguments remaining after option processing are treated
11396 as values for the positional parameters and are assigned, in order, to
11397 .BR $1 ,
11398 .BR $2 ,
11399 \&.\|.\|.,
11400 .BR $\fIn\fP .
11401 Options, if specified, have the following meanings:
11402 .RS
11403 .PD 0
11404 .TP 8
11405 .B \-a
11406 Each variable or function that is created or modified is given the
11407 export attribute and marked for export to the environment of
11408 subsequent commands.
11409 .TP 8
11410 .B \-b
11411 Report the status of terminated background jobs
11412 immediately, rather than before the next primary prompt or after a
11413 foreground command terminates.
11414 This is effective only when job control is enabled.
11415 .TP 8
11416 .B \-e
11417 .PD
11418 Exit immediately if a
11419 \fIpipeline\fP (which may consist of a single \fIsimple command\fP),
11420 a \fIlist\fP,
11421 or a \fIcompound command\fP
11422 (see
11423 .SM
11424 .B "SHELL GRAMMAR"
11425 .ie \n(zZ=1 in \fIbash\fP(1)),
11426 .el above),
11427 exits with a non-zero status.
11428 The shell does not exit if the
11429 command that fails is part of the command list immediately following a
11430 .B while
11431 or
11432 .B until
11433 reserved word,
11434 part of the test following the
11435 .B if
11436 or
11437 .B elif
11438 reserved words, part of any command executed in a
11439 .B &&
11440 or
11441 .B ||
11442 list except the command following the final \fB&&\fP or \fB||\fP,
11443 any command in a pipeline but the last
11444 (subject to the state of the \fBpipefail\fP shell option),
11445 or if the command's return value is
11446 being inverted with
11447 .BR ! .
11448 If a compound command other than a subshell
11449 returns a non-zero status because a command failed
11450 while \fB\-e\fP was being ignored, the shell does not exit.
11451 A trap on \fBERR\fP, if set, is executed before the shell exits.
11452 This option applies to the shell environment and each subshell environment
11453 separately (see
11454 .SM
11455 .B "COMMAND EXECUTION ENVIRONMENT"
11456 .ie \n(zZ=1 in \fIbash\fP(1)),
11457 .el above),
11458 and may cause
11459 subshells to exit before executing all the commands in the subshell.
11460 .IP
11461 If a compound command or shell function executes in a context
11462 where \fB\-e\fP is being ignored,
11463 none of the commands executed within the compound command or function body
11464 will be affected by the \fB\-e\fP setting, even if \fB\-e\fP is set
11465 and a command returns a failure status.
11466 If a compound command or shell function sets \fB\-e\fP while executing in
11467 a context where \fB\-e\fP is ignored, that setting will not have any
11468 effect until the compound command or the command containing the function
11469 call completes.
11470 .PD 0
11471 .TP 8
11472 .B \-f
11473 Disable pathname expansion.
11474 .TP 8
11475 .B \-h
11476 Remember the location of commands as they are looked up for execution.
11477 This is enabled by default.
11478 .TP 8
11479 .B \-k
11480 All arguments in the form of assignment statements
11481 are placed in the environment for a command, not just
11482 those that precede the command name.
11483 .TP 8
11484 .B \-m
11485 Monitor mode.
11486 Job control is enabled.
11487 This option is on by default for interactive shells on systems
11488 that support it (see
11489 .SM
11490 .B "JOB CONTROL"
11491 .ie \n(zZ=1 in \fIbash\fP(1)).
11492 .el above).
11493 All processes run in a separate process group.
11494 When a background job completes, the shell prints a line
11495 containing its exit status.
11496 .TP 8
11497 .B \-n
11498 Read commands but do not execute them.
11499 This may be used to check a shell script for syntax errors.
11500 This is ignored by interactive shells.
11501 .TP 8
11502 .B \-o \fIoption\-name\fP
11503 The \fIoption\-name\fP can be one of the following:
11504 .RS
11505 .TP 8
11506 .B allexport
11507 Same as
11508 .BR \-a .
11509 .TP 8
11510 .B braceexpand
11511 Same as
11512 .BR \-B .
11513 .TP 8
11514 .B emacs
11515 Use an emacs-style command line editing interface. This is enabled
11516 by default when the shell is interactive, unless the shell is started
11517 with the
11518 .B \-\-noediting
11519 option.
11520 This also affects the editing interface used for \fBread \-e\fP.
11521 .TP 8
11522 .B errexit
11523 Same as
11524 .BR \-e .
11525 .TP 8
11526 .B errtrace
11527 Same as
11528 .BR \-E .
11529 .TP 8
11530 .B functrace
11531 Same as
11532 .BR \-T .
11533 .TP 8
11534 .B hashall
11535 Same as
11536 .BR \-h .
11537 .TP 8
11538 .B histexpand
11539 Same as
11540 .BR \-H .
11541 .TP 8
11542 .B history
11543 Enable command history, as described
11544 .ie \n(zZ=1 in \fIbash\fP(1)
11545 .el above
11546 under
11547 .SM
11548 .BR HISTORY .
11549 This option is on by default in interactive shells.
11550 .TP 8
11551 .B ignoreeof
11552 The effect is as if the shell command
11553 .QN "IGNOREEOF=10"
11554 had been executed
11555 (see
11556 .B "Shell Variables"
11557 .ie \n(zZ=1 in \fIbash\fP(1)).
11558 .el above).
11559 .TP 8
11560 .B keyword
11561 Same as
11562 .BR \-k .
11563 .TP 8
11564 .B monitor
11565 Same as
11566 .BR \-m .
11567 .TP 8
11568 .B noclobber
11569 Same as
11570 .BR \-C .
11571 .TP 8
11572 .B noexec
11573 Same as
11574 .BR \-n .
11575 .TP 8
11576 .B noglob
11577 Same as
11578 .BR \-f .
11579 .TP 8
11580 .B nolog
11581 Currently ignored.
11582 .TP 8
11583 .B notify
11584 Same as
11585 .BR \-b .
11586 .TP 8
11587 .B nounset
11588 Same as
11589 .BR \-u .
11590 .TP 8
11591 .B onecmd
11592 Same as
11593 .BR \-t .
11594 .TP 8
11595 .B physical
11596 Same as
11597 .BR \-P .
11598 .TP 8
11599 .B pipefail
11600 If set, the return value of a pipeline is the value of the last
11601 (rightmost) command to exit with a non-zero status, or zero if all
11602 commands in the pipeline exit successfully.
11603 This option is disabled by default.
11604 .TP 8
11605 .B posix
11606 Enable posix mode;
11607 change the behavior of
11608 .B bash
11609 where the default operation differs
11610 from the
11611 .SM POSIX
11612 standard to match the standard.
11613 See
11614 .SM
11615 .B "SEE ALSO"
11616 .ie \n(zZ=1 in \fIbash\fP(1)
11617 .el below
11618 for a reference to a document that details how posix mode affects
11619 bash's behavior.
11620 .TP 8
11621 .B privileged
11622 Same as
11623 .BR \-p .
11624 .TP 8
11625 .B verbose
11626 Same as
11627 .BR \-v .
11628 .TP 8
11629 .B vi
11630 Use a vi-style command line editing interface.
11631 This also affects the editing interface used for \fBread \-e\fP.
11632 .TP 8
11633 .B xtrace
11634 Same as
11635 .BR \-x .
11636 .PP
11637 If
11638 .B \-o
11639 is supplied with no \fIoption\-name\fP,
11640 \fBset\fP prints the current shell option settings.
11641 If
11642 .B +o
11643 is supplied with no \fIoption\-name\fP,
11644 \fBset\fP prints a series of
11645 .B set
11646 commands to recreate the current option settings
11647 on the standard output.
11648 .RE
11649 .TP 8
11650 .B \-p
11651 Turn on
11652 .I privileged
11653 mode. In this mode, the shell does not read the
11654 .SM
11655 .B $ENV
11656 and
11657 .SM
11658 .B $BASH_ENV
11659 files, shell functions are not inherited from the
11660 environment, and the
11661 .SM
11662 .BR SHELLOPTS ,
11663 .SM
11664 .BR BASHOPTS ,
11665 .SM
11666 .BR CDPATH ,
11667 and
11668 .SM
11669 .B GLOBIGNORE
11670 variables, if they appear in the environment, are ignored.
11671 If the shell is started with the effective user (group) id not equal to the
11672 real user (group) id, and the \fB\-p\fP option is not supplied, these actions
11673 are taken and the effective user id is set to the real user id.
11674 If the \fB\-p\fP option is supplied at startup, the effective user id is
11675 not reset.
11676 Turning this option off causes the effective user
11677 and group ids to be set to the real user and group ids.
11678 .TP 8
11679 .B \-r
11680 Enable restricted shell mode.
11681 This option cannot be unset once it has been set.
11682 .TP 8
11683 .B \-t
11684 Exit after reading and executing one command.
11685 .TP 8
11686 .B \-u
11687 Treat unset variables and parameters other than the special
11688 parameters
11689 .Q @
11690 and
11691 .Q * ,
11692 or array variables subscripted with
11693 .Q @
11694 or
11695 .Q * ,
11696 as an error when performing parameter expansion.
11697 If expansion is attempted on an unset variable or parameter,
11698 the shell prints an error message, and,
11699 if not interactive, exits with a non-zero status.
11700 .TP 8
11701 .B \-v
11702 Print shell input lines as they are read.
11703 .TP 8
11704 .B \-x
11705 After expanding each \fIsimple command\fP,
11706 \fBfor\fP command, \fBcase\fP command, \fBselect\fP command, or
11707 arithmetic \fBfor\fP command, display the expanded value of
11708 .SM
11709 .BR PS4 ,
11710 followed by the command and its expanded arguments
11711 or associated word list, to the standard error.
11712 .TP 8
11713 .B \-B
11714 The shell performs brace expansion (see
11715 .B "Brace Expansion"
11716 .ie \n(zZ=1 in \fIbash\fP(1)).
11717 .el above).
11718 This is on by default.
11719 .TP 8
11720 .B \-C
11721 If set,
11722 .B bash
11723 does not overwrite an existing file with the
11724 .BR > ,
11725 .BR >& ,
11726 and
11727 .B <>
11728 redirection operators.
11729 Using the redirection operator
11730 .B >|
11731 instead of
11732 .B >
11733 will override this and force the creation of an output file.
11734 .TP 8
11735 .B \-E
11736 If set, any trap on \fBERR\fP is inherited by shell functions, command
11737 substitutions, and commands executed in a subshell environment.
11738 The \fBERR\fP trap is normally not inherited in such cases.
11739 .TP 8
11740 .B \-H
11741 Enable
11742 .B !
11743 style history substitution.
11744 This option is on by default when the shell is interactive.
11745 .TP 8
11746 .B \-P
11747 If set, the shell does not resolve symbolic links when executing
11748 commands such as
11749 .B cd
11750 that change the current working directory.
11751 It uses the physical directory structure instead.
11752 By default,
11753 .B bash
11754 follows the logical chain of directories when performing commands
11755 which change the current directory.
11756 .TP 8
11757 .B \-T
11758 If set, any traps on \fBDEBUG\fP and \fBRETURN\fP are inherited by shell
11759 functions, command substitutions, and commands executed in a
11760 subshell environment.
11761 The \fBDEBUG\fP and \fBRETURN\fP traps are normally not inherited
11762 in such cases.
11763 .TP 8
11764 .B \-\-
11765 If no arguments follow this option, unset the positional parameters.
11766 Otherwise, set the positional parameters to the
11767 \fIarg\fPs, even if some of them begin with a
11768 .BR \- .
11769 .TP 8
11770 .B \-
11771 Signal the end of options, and assign all remaining \fIarg\fPs to
11772 the positional parameters.
11773 The
11774 .B \-x
11775 and
11776 .B \-v
11777 options are turned off.
11778 If there are no \fIarg\fPs, the positional parameters remain unchanged.
11779 .PD
11780 .PP
11781 The options are off by default unless otherwise noted.
11782 Using + rather than \- causes these options to be turned off.
11783 The options can also be specified as arguments to an invocation of
11784 the shell.
11785 The current set of options may be found in
11786 .BR $\- .
11787 The return status is always zero unless an invalid option is encountered.
11788 .RE
11789 .TP
11790 \fBshift\fP [\fIn\fP]
11791 Rename positional parameters from \fIn\fP+1 .\|.\|.\& to
11792 .B $1
11793 .B .\|.\|..
11794 Parameters represented by the numbers \fB$#\fP
11795 down to \fB$#\fP\-\fIn\fP+1 are unset.
11796 .I n
11797 must be a non-negative number less than or equal to \fB$#\fP.
11798 If
11799 .I n
11800 is 0, no parameters are changed.
11801 If
11802 .I n
11803 is not given, it is assumed to be 1.
11804 If
11805 .I n
11806 is greater than \fB$#\fP, the positional parameters are not changed.
11807 The return status is greater than zero if
11808 .I n
11809 is greater than
11810 .B $#
11811 or less than zero; otherwise 0.
11812 .TP
11813 \fBshopt\fP [\fB\-pqsu\fP] [\fB\-o\fP] [\fIoptname\fP .\|.\|.]
11814 Toggle the values of settings controlling optional shell behavior.
11815 The settings can be either those listed below, or, if the
11816 .B \-o
11817 option is used, those available with the
11818 .B \-o
11819 option to the \fBset\fP builtin command.
11820 .IP
11821 With no options, or with the
11822 .B \-p
11823 option, display a list of all settable options, with
11824 an indication of whether or not each is set;
11825 if any \fIoptnames\fP are supplied, the output is restricted to those options.
11826 The \fB\-p\fP option displays output in a form that
11827 may be reused as input.
11828 .IP
11829 Other options have the following meanings:
11830 .RS
11831 .PD 0
11832 .TP
11833 .B \-s
11834 Enable (set) each \fIoptname\fP.
11835 .TP
11836 .B \-u
11837 Disable (unset) each \fIoptname\fP.
11838 .TP
11839 .B \-q
11840 Suppresses normal output (quiet mode); the return status indicates
11841 whether the \fIoptname\fP is set or unset.
11842 If multiple \fIoptname\fP arguments are supplied with
11843 .BR \-q ,
11844 the return status is zero if all \fIoptnames\fP are enabled; non-zero
11845 otherwise.
11846 .TP
11847 .B \-o
11848 Restricts the values of \fIoptname\fP to be those defined for the
11849 .B \-o
11850 option to the
11851 .B set
11852 builtin.
11853 .PD
11854 .PP
11855 If either
11856 .B \-s
11857 or
11858 .B \-u
11859 is used with no \fIoptname\fP arguments,
11860 .B shopt
11861 shows only those options which are set or unset, respectively.
11862 Unless otherwise noted, the \fBshopt\fP options are disabled (unset)
11863 by default.
11864 .PP
11865 The return status when listing options is zero if all \fIoptnames\fP
11866 are enabled, non-zero otherwise. When setting or unsetting options,
11867 the return status is zero unless an \fIoptname\fP is not a valid shell
11868 option.
11869 .PP
11870 The list of \fBshopt\fP options is:
11871 .PP
11872 .PD 0
11873 .TP 8
11874 .B array_expand_once
11875 If set, the shell suppresses multiple evaluation of
11876 associative and indexed array subscripts
11877 during arithmetic expression evaluation, while executing
11878 builtins that can perform variable assignments,
11879 and while executing builtins that perform array dereferencing.
11880 .TP 8
11881 .B assoc_expand_once
11882 Deprecated; a synonym for \fBarray_expand_once\fP.
11883 .TP 8
11884 .B autocd
11885 If set, a command name that is the name of a directory is executed as if
11886 it were the argument to the \fBcd\fP command.
11887 This option is only used by interactive shells.
11888 .TP 8
11889 .B bash_source_fullpath
11890 If set, filenames added to the \fBBASH_SOURCE\fP array variable are
11891 converted to full pathnames (see \fBShell Variables\fP above).
11892 .TP 8
11893 .B cdable_vars
11894 If set, an argument to the
11895 .B cd
11896 builtin command that
11897 is not a directory is assumed to be the name of a variable whose
11898 value is the directory to change to.
11899 .TP 8
11900 .B cdspell
11901 If set, the
11902 .B cd
11903 command attempts to correct
11904 minor errors in the spelling of a directory component.
11905 Minor errors include transposed characters,
11906 a missing character, and one extra character.
11907 If \fBcd\fP corrects the directory name, it prints the corrected filename,
11908 and the command proceeds.
11909 This option is only used by interactive shells.
11910 .TP 8
11911 .B checkhash
11912 If set, \fBbash\fP checks that a command found in the hash
11913 table exists before trying to execute it.
11914 If a hashed command no longer exists, \fBbash\fP performs a normal path search.
11915 .TP 8
11916 .B checkjobs
11917 If set, \fBbash\fP lists the status of any stopped and running jobs before
11918 exiting an interactive shell.
11919 If any jobs are running, \fBbash\fP defers the exit until a second
11920 exit is attempted without an intervening command (see
11921 .SM
11922 .B "JOB CONTROL"
11923 .ie \n(zZ=1 in \fIbash\fP(1)).
11924 .el above).
11925 The shell always postpones exiting if any jobs are stopped.
11926 .TP 8
11927 .B checkwinsize
11928 If set, \fBbash\fP checks the window size after each external (non-builtin)
11929 command
11930 and, if necessary, updates the values of
11931 .SM
11932 .B LINES
11933 and
11934 .SM
11935 .BR COLUMNS ,
11936 using the file descriptor associated with the standard error
11937 if it is a terminal.
11938 This option is enabled by default.
11939 .TP 8
11940 .B cmdhist
11941 If set,
11942 .B bash
11943 attempts to save all lines of a multiple-line
11944 command in the same history entry.
11945 This allows easy re-editing of multi-line commands.
11946 This option is enabled by default, but only has an effect if command
11947 history is enabled, as described
11948 .ie \n(zZ=1 in \fIbash\fP(1)
11949 .el above
11950 under
11951 .SM
11952 .BR HISTORY .
11953 .PD 0
11954 .TP 8
11955 .B compat31
11956 .TP 8
11957 .B compat32
11958 .TP 8
11959 .B compat40
11960 .TP 8
11961 .B compat41
11962 .TP 8
11963 .B compat42
11964 .TP 8
11965 .B compat43
11966 .TP 8
11967 .B compat44
11968 .PD
11969 These control aspects of the shell's compatibility mode
11970 (see
11971 .SM
11972 .B "SHELL COMPATIBILITY MODE"
11973 .ie \n(zZ=1 in \fIbash\fP(1)).
11974 .el below).
11975 .PD 0
11976 .TP 8
11977 .B complete_fullquote
11978 If set,
11979 .B bash
11980 quotes all shell metacharacters in filenames and directory names when
11981 performing completion.
11982 If not set,
11983 .B bash
11984 removes metacharacters such as the dollar sign from the set of
11985 characters that will be quoted in completed filenames
11986 when these metacharacters appear in shell variable references in words to be
11987 completed.
11988 This means that dollar signs in variable names that expand to directories
11989 will not be quoted;
11990 however, any dollar signs appearing in filenames will not be quoted, either.
11991 This is active only when bash is using backslashes to quote completed
11992 filenames.
11993 This variable is set by default, which is the default bash behavior in
11994 versions through 4.2.
11995 .TP 8
11996 .B direxpand
11997 If set,
11998 .B bash
11999 replaces directory names with the results of word expansion when performing
12000 filename completion.
12001 This changes the contents of the \fBreadline\fP editing buffer.
12002 If not set,
12003 .B bash
12004 attempts to preserve what the user typed.
12005 .TP 8
12006 .B dirspell
12007 If set,
12008 .B bash
12009 attempts spelling correction on directory names during word completion
12010 if the directory name initially supplied does not exist.
12011 .TP 8
12012 .B dotglob
12013 If set,
12014 .B bash
12015 includes filenames beginning with a
12016 .Q .\&
12017 in the results of pathname expansion.
12018 The filenames
12019 .FN .\&
12020 and
12021 .FN ..\&
12022 must always be matched explicitly, even if
12023 .B dotglob
12024 is set.
12025 .TP 8
12026 .B execfail
12027 If set, a non-interactive shell will not exit if
12028 it cannot execute the file specified as an argument to the
12029 .B exec
12030 builtin.
12031 An interactive shell does not exit if
12032 .B exec
12033 fails.
12034 .TP 8
12035 .B expand_aliases
12036 If set, aliases are expanded as described
12037 .ie \n(zZ=1 in \fIbash\fP(1)
12038 .el above
12039 under
12040 .SM
12041 .BR ALIASES .
12042 This option is enabled by default for interactive shells.
12043 .TP 8
12044 .B extdebug
12045 If set at shell invocation, or in a shell startup file,
12046 arrange to execute the debugger profile
12047 before the shell starts, identical to the \fB\-\-debugger\fP option.
12048 If set after invocation, behavior intended for use by debuggers is enabled:
12049 .RS
12050 .TP
12051 .B 1.
12052 The \fB\-F\fP option to the \fBdeclare\fP builtin displays the source
12053 file name and line number corresponding to each function name supplied
12054 as an argument.
12055 .TP
12056 .B 2.
12057 If the command run by the \fBDEBUG\fP trap returns a non-zero value, the
12058 next command is skipped and not executed.
12059 .TP
12060 .B 3.
12061 If the command run by the \fBDEBUG\fP trap returns a value of 2, and the
12062 shell is executing in a subroutine (a shell function or a shell script
12063 executed by the \fB.\fP or \fBsource\fP builtins), the shell simulates
12064 a call to \fBreturn\fP.
12065 .TP
12066 .B 4.
12067 .SM
12068 .B BASH_ARGC
12069 and
12070 .SM
12071 .B BASH_ARGV
12072 are updated as described in their descriptions
12073 .ie \n(zZ=1 in \fIbash\fP(1)).
12074 .el above).
12075 .TP
12076 .B 5.
12077 Function tracing is enabled: command substitution, shell functions, and
12078 subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the
12079 \fBDEBUG\fP and \fBRETURN\fP traps.
12080 .TP
12081 .B 6.
12082 Error tracing is enabled: command substitution, shell functions, and
12083 subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the
12084 \fBERR\fP trap.
12085 .RE
12086 .TP 8
12087 .B extglob
12088 If set, enable the extended pattern matching features described
12089 .ie \n(zZ=1 in \fIbash\fP(1)
12090 .el above
12091 under
12092 \fBPathname Expansion\fP.
12093 .TP 8
12094 .B extquote
12095 If set, \fB$\fP\*'\fIstring\fP\*' and \fB$\fP\*"\fIstring\fP\*" quoting is
12096 performed within \fB${\fP\fIparameter\fP\fB}\fP expansions
12097 enclosed in double quotes.
12098 This option is enabled by default.
12099 .TP 8
12100 .B failglob
12101 If set, patterns which fail to match filenames during pathname expansion
12102 result in an expansion error.
12103 .TP 8
12104 .B force_fignore
12105 If set, the suffixes specified by the
12106 .SM
12107 .B FIGNORE
12108 shell variable
12109 cause words to be ignored when performing word completion even if
12110 the ignored words are the only possible completions.
12111 See
12112 .B "Shell Variables"
12113 .ie \n(zZ=1 in \fIbash\fP(1)
12114 .el above
12115 for a description of
12116 .SM
12117 .BR FIGNORE .
12118 This option is enabled by default.
12119 .TP 8
12120 .B globasciiranges
12121 If set, range expressions used in pattern matching bracket expressions (see
12122 .SM
12123 .B "Pattern Matching"
12124 .ie \n(zZ=1 in \fIbash\fP(1))
12125 .el above)
12126 behave as if in the traditional C locale when performing comparisons.
12127 That is, pattern matching does not take
12128 the current locale's collating sequence into account, so
12129 .B b
12130 will not collate between
12131 .B A
12132 and
12133 .BR B ,
12134 and upper-case and lower-case ASCII characters will collate together.
12135 .TP 8
12136 .B globskipdots
12137 If set, pathname expansion will never match the filenames
12138 .FN .\&
12139 and
12140 .FN ..\& ,
12141 even if the pattern begins with a
12142 .Q .\& .
12143 This option is enabled by default.
12144 .TP 8
12145 .B globstar
12146 If set, the pattern \fB**\fP used in a pathname expansion context will
12147 match all files and zero or more directories and subdirectories.
12148 If the pattern is followed by a \fB/\fP, only directories and
12149 subdirectories match.
12150 .TP 8
12151 .B gnu_errfmt
12152 If set, shell error messages are written in the standard GNU error
12153 message format.
12154 .TP 8
12155 .B histappend
12156 If set, the history list is appended to the file named by the value
12157 of the
12158 .SM
12159 .B HISTFILE
12160 variable when the shell exits, rather than overwriting the file.
12161 .TP 8
12162 .B histreedit
12163 If set, and
12164 .B readline
12165 is being used, the user is given the opportunity to re-edit a
12166 failed history substitution.
12167 .TP 8
12168 .B histverify
12169 If set, and
12170 .B readline
12171 is being used, the results of history substitution are not immediately
12172 passed to the shell parser.
12173 Instead, the resulting line is loaded into the \fBreadline\fP editing buffer,
12174 allowing further modification.
12175 .TP 8
12176 .B hostcomplete
12177 If set, and
12178 .B readline
12179 is being used, \fBbash\fP will attempt to perform hostname completion when a
12180 word containing a \fB@\fP is being completed (see
12181 .B Completing
12182 under
12183 .SM
12184 .B READLINE
12185 .ie \n(zZ=1 in \fIbash\fP(1)).
12186 .el above).
12187 This is enabled by default.
12188 .TP 8
12189 .B huponexit
12190 If set, \fBbash\fP will send
12191 .SM
12192 .B SIGHUP
12193 to all jobs when an interactive login shell exits.
12194 .TP 8
12195 .B inherit_errexit
12196 If set, command substitution inherits the value of the \fBerrexit\fP option,
12197 instead of unsetting it in the subshell environment.
12198 This option is enabled when posix mode is enabled.
12199 .TP 8
12200 .B interactive_comments
12201 In an interactive shell, a word beginning with \fB#\fP
12202 causes that word and all remaining characters on that
12203 line to be ignored, as in a non-interactive shell
12204 (see
12205 .SM
12206 .B COMMENTS
12207 .ie \n(zZ=1 in \fIbash\fP(1)).
12208 .el above).
12209 This option is enabled by default.
12210 .TP 8
12211 .B lastpipe
12212 If set, and job control is not active, the shell runs the last command of
12213 a pipeline not executed in the background in the current shell environment.
12214 .TP 8
12215 .B lithist
12216 If set, and the
12217 .B cmdhist
12218 option is enabled, multi-line commands are saved to the history with
12219 embedded newlines rather than using semicolon separators where possible.
12220 .TP 8
12221 .B localvar_inherit
12222 If set, local variables inherit the value and attributes of a variable of
12223 the same name that exists at a previous scope before any new value is
12224 assigned.
12225 The nameref attribute is not inherited.
12226 .TP 8
12227 .B localvar_unset
12228 If set, calling \fBunset\fP on local variables in previous function scopes
12229 marks them so subsequent lookups find them unset until that function
12230 returns.
12231 This is identical to the behavior of unsetting local variables at the
12232 current function scope.
12233 .TP 8
12234 .B login_shell
12235 The shell sets this option if it is started as a login shell (see
12236 .SM
12237 .B "INVOCATION"
12238 .ie \n(zZ=1 in \fIbash\fP(1)).
12239 .el above).
12240 The value may not be changed.
12241 .TP 8
12242 .B mailwarn
12243 If set, and a file that \fBbash\fP is checking for mail has been
12244 accessed since the last time it was checked,
12245 \fBbash\fP displays the message
12246 .Q "The mail in \fImailfile\fP has been read" .
12247 .TP 8
12248 .B no_empty_cmd_completion
12249 If set, and
12250 .B readline
12251 is being used,
12252 .B bash
12253 does not search
12254 .SM
12255 .B PATH
12256 for possible completions when completion is attempted on an empty line.
12257 .TP 8
12258 .B nocaseglob
12259 If set,
12260 .B bash
12261 matches filenames in a case\-insensitive fashion when performing pathname
12262 expansion (see
12263 .B "Pathname Expansion"
12264 .ie \n(zZ=1 in \fIbash\fP(1)).
12265 .el above).
12266 .TP 8
12267 .B nocasematch
12268 If set,
12269 .B bash
12270 matches patterns in a case\-insensitive fashion when performing matching
12271 while executing \fBcase\fP or \fB[[\fP conditional commands,
12272 when performing pattern substitution word expansions,
12273 or when filtering possible completions as part of programmable completion.
12274 .TP 8
12275 .B noexpand_translation
12276 If set,
12277 .B bash
12278 encloses the translated results of
12279 .BR $\*" .\|.\|.\& \*"
12280 quoting in single quotes instead of double quotes.
12281 If the string is not translated, this has no effect.
12282 .TP 8
12283 .B nullglob
12284 If set, pathname expansion patterns which match no files
12285 (see
12286 .B "Pathname Expansion"
12287 .ie \n(zZ=1 in \fIbash\fP(1))
12288 .el above)
12289 expand to nothing and are removed, rather than expanding to themselves.
12290 .TP 8
12291 .B patsub_replacement
12292 If set, \fBbash\fP
12293 expands occurrences of \fB&\fP in the replacement string of pattern
12294 substitution to the text matched by the pattern, as described
12295 under \fBParameter Expansion\fP
12296 .ie \n(zZ=1 in \fIbash\fP(1).
12297 .el above.
12298 This option is enabled by default.
12299 .TP 8
12300 .B progcomp
12301 If set, enable the programmable completion facilities (see
12302 \fBProgrammable Completion\fP
12303 .ie \n(zZ=1 in \fIbash\fP(1)).
12304 .el above).
12305 This option is enabled by default.
12306 .TP 8
12307 .B progcomp_alias
12308 If set, and programmable completion is enabled, \fBbash\fP treats a command
12309 name that doesn't have any completions as a possible alias and attempts
12310 alias expansion.
12311 If it has an alias, \fBbash\fP attempts programmable
12312 completion using the command word resulting from the expanded alias.
12313 .TP 8
12314 .B promptvars
12315 If set, prompt strings undergo
12316 parameter expansion, command substitution, arithmetic
12317 expansion, and quote removal after being expanded as described in
12318 .SM
12319 .B PROMPTING
12320 .ie \n(zZ=1 in \fIbash\fP(1).
12321 .el above.
12322 This option is enabled by default.
12323 .TP 8
12324 .B restricted_shell
12325 The shell sets this option if it is started in restricted mode
12326 (see
12327 .SM
12328 .B "RESTRICTED SHELL"
12329 .ie \n(zZ=1 in \fIbash\fP(1)).
12330 .el below).
12331 The value may not be changed.
12332 This is not reset when the startup files are executed, allowing
12333 the startup files to discover whether or not a shell is restricted.
12334 .TP 8
12335 .B shift_verbose
12336 If set, the
12337 .B shift
12338 builtin prints an error message when the shift count exceeds the
12339 number of positional parameters.
12340 .TP 8
12341 .B sourcepath
12342 If set, the
12343 \fB.\fP (\fBsource\fP) builtin uses the value of
12344 .SM
12345 .B PATH
12346 to find the directory containing the file supplied as an argument when
12347 the \fB\-p\fP option is not supplied.
12348 This option is enabled by default.
12349 .TP 8
12350 .B varredir_close
12351 If set, the shell automatically closes file descriptors assigned using the
12352 \fI{varname}\fP redirection syntax (see
12353 .SM
12354 .B REDIRECTION
12355 .ie \n(zZ=1 in \fIbash\fP(1))
12356 .el above)
12357 instead of leaving them open when the command completes.
12358 .TP 8
12359 .B xpg_echo
12360 If set, the \fBecho\fP builtin expands backslash-escape sequences
12361 by default.
12362 If the \fBposix\fP shell option is also enabled, \fBecho\fP does not
12363 interpret any options.
12364 .RE
12365 .PD
12366 .TP
12367 \fBsuspend\fP [\fB\-f\fP]
12368 Suspend the execution of this shell until it receives a
12369 .SM
12370 .B SIGCONT
12371 signal.
12372 A login shell, or a shell without job control enabled,
12373 cannot be suspended; the
12374 .B \-f
12375 option will override this and force the suspension.
12376 The return status is 0 unless the shell is a login shell
12377 or job control is not enabled
12378 and
12379 .B \-f
12380 is not supplied.
12381 .TP
12382 \fBtest\fP \fIexpr\fP
12383 .PD 0
12384 .TP
12385 \fB[\fP \fIexpr\fP \fB]\fP
12386 .PD
12387 Return a status of 0 (true) or 1 (false) depending on
12388 the evaluation of the conditional expression
12389 .IR expr .
12390 Each operator and operand must be a separate argument.
12391 Expressions are composed of the primaries described
12392 .ie \n(zZ=1 in \fIbash\fP(1)
12393 .el above
12394 under
12395 .SM
12396 .BR "CONDITIONAL EXPRESSIONS" .
12397 \fBtest\fP does not accept any options, nor does it accept and ignore
12398 an argument of \fB\-\-\fP as signifying the end of options.
12399 .IP
12400 Expressions may be combined using the following operators, listed
12401 in decreasing order of precedence.
12402 The evaluation depends on the number of arguments; see below.
12403 \fBtest\fP uses operator precedence when there are five or more arguments.
12404 .RS
12405 .PD 0
12406 .TP
12407 .B ! \fIexpr\fP
12408 True if
12409 .I expr
12410 is false.
12411 .TP
12412 .B ( \fIexpr\fP )
12413 Returns the value of \fIexpr\fP.
12414 This may be used to override normal operator precedence.
12415 .TP
12416 \fIexpr1\fP \-\fBa\fP \fIexpr2\fP
12417 True if both
12418 .I expr1
12419 and
12420 .I expr2
12421 are true.
12422 .TP
12423 \fIexpr1\fP \-\fBo\fP \fIexpr2\fP
12424 True if either
12425 .I expr1
12426 or
12427 .I expr2
12428 is true.
12429 .PD
12430 .PP
12431 \fBtest\fP and \fB[\fP evaluate conditional
12432 expressions using a set of rules based on the number of arguments.
12433 .PP
12434 .PD 0
12435 .TP
12436 0 arguments
12437 The expression is false.
12438 .TP
12439 1 argument
12440 The expression is true if and only if the argument is not null.
12441 .TP
12442 2 arguments
12443 If the first argument is \fB!\fP, the expression is true if and
12444 only if the second argument is null.
12445 If the first argument is one of the unary conditional operators listed
12446 .ie \n(zZ=1 in \fIbash\fP(1)
12447 .el above
12448 under
12449 .SM
12450 .BR "CONDITIONAL EXPRESSIONS" ,
12451 the expression is true if the unary test is true.
12452 If the first argument is not a valid unary conditional operator, the expression
12453 is false.
12454 .TP
12455 3 arguments
12456 The following conditions are applied in the order listed.
12457 If the second argument is one of the binary conditional operators listed
12458 .ie \n(zZ=1 in \fIbash\fP(1)
12459 .el above
12460 under
12461 .SM
12462 .BR "CONDITIONAL EXPRESSIONS" ,
12463 the result of the expression is the result of the binary test using
12464 the first and third arguments as operands.
12465 The \fB\-a\fP and \fB\-o\fP operators are considered binary operators
12466 when there are three arguments.
12467 If the first argument is \fB!\fP, the value is the negation of
12468 the two-argument test using the second and third arguments.
12469 If the first argument is exactly \fB(\fP and the third argument is
12470 exactly \fB)\fP, the result is the one-argument test of the second
12471 argument.
12472 Otherwise, the expression is false.
12473 .TP
12474 4 arguments
12475 The following conditions are applied in the order listed.
12476 If the first argument is \fB!\fP, the result is the negation of
12477 the three-argument expression composed of the remaining arguments.
12478 If the first argument is exactly \fB(\fP and the fourth argument is
12479 exactly \fB)\fP, the result is the two-argument test of the second
12480 and third arguments.
12481 Otherwise, the expression is parsed and evaluated according to
12482 precedence using the rules listed above.
12483 .TP
12484 5 or more arguments
12485 The expression is parsed and evaluated according to precedence
12486 using the rules listed above.
12487 .PD
12488 .PP
12489 When the shell is in posix mode, or if the expression is part
12490 of the \fB[[\fP command,
12491 the \fB<\fP and \fB>\fP operators sort using the
12492 current locale.
12493 If the shell is not in posix mode, the \fBtest\fP and \fB[\fP
12494 commands sort lexicographically using ASCII ordering.
12495 .PP
12496 The historical operator-precedence parsing with 4 or more arguments can
12497 lead to ambiguities when it encounters strings that look like primaries.
12498 The
12499 .SM POSIX
12500 standard has deprecated the \fB\-a\fP and \fB\-o\fP
12501 primaries and enclosing expressions within parentheses.
12502 Scripts should no longer use them.
12503 It's much more reliable to restrict test invocations to a single primary,
12504 and to replace uses of \fB\-a\fP and \fB\-o\fP with the shell's
12505 \fB&&\fP and \fB||\fP list operators.
12506 .RE
12507 .TP
12508 .B times
12509 Print the accumulated user and system times for the shell and
12510 for processes run from the shell.
12511 The return status is 0.
12512 .TP
12513 \fBtrap\fP [\fB\-lpP\fP] [[\fIaction\fP] \fIsigspec\fP .\|.\|.]
12514 The
12515 .I action
12516 is a command that is read and executed when the shell receives
12517 any of the signals
12518 .IR sigspec .
12519 If
12520 .I action
12521 is absent (and there is a single \fIsigspec\fP) or
12522 .BR \- ,
12523 each specified \fIsigspec\fP is
12524 reset to the value it had when the shell was started.
12525 If
12526 .I action
12527 is the null string the signal specified by each
12528 .I sigspec
12529 is ignored by the shell and by the commands it invokes.
12530 .IP
12531 If no arguments are supplied,
12532 .B trap
12533 displays the actions associated with each trapped signal
12534 as a set of \fBtrap\fP commands
12535 that can be reused as shell input to
12536 restore the current signal dispositions.
12537 If
12538 .B \-p
12539 is given,
12540 and
12541 .I action
12542 is not present,
12543 then \fBtrap\fP displays the actions associated with each
12544 .I sigspec
12545 or, if none are supplied, for all trapped signals,
12546 as a set of \fBtrap\fP commands
12547 that can be reused as shell input to
12548 restore the current signal dispositions.
12549 The
12550 .B \-P
12551 option behaves similarly, but displays only the actions
12552 associated with each \fIsigspec\fP argument.
12553 .B \-P
12554 requires at least one \fIsigspec\fP argument.
12555 The \fB\-P\fP or \fB\-p\fP options may be used
12556 in a subshell environment (e.g., command substitution) and, as
12557 long as they are used before \fBtrap\fP is used to change a signal's
12558 handling, will display the state of its parent's traps.
12559 .IP
12560 The
12561 .B \-l
12562 option prints a list of signal names and
12563 their corresponding numbers.
12564 Each
12565 .I sigspec
12566 is either
12567 a signal name defined in <\fIsignal.h\fP>, or a signal number.
12568 Signal names are case insensitive and the
12569 .SM
12570 .B SIG
12571 prefix is optional.
12572 If \fB\-l\fP is supplied with no \fIsigspec\fP arguments, it prints a
12573 list of valid signal names.
12574 .IP
12575 If a
12576 .I sigspec
12577 is
12578 .SM
12579 .B EXIT
12580 (0),
12581 .I action
12582 is executed on exit from the shell.
12583 If a
12584 .I sigspec
12585 is
12586 .SM
12587 .BR DEBUG ,
12588 .I action
12589 is executed before every \fIsimple command\fP, \fIfor\fP command,
12590 \fIcase\fP command, \fIselect\fP command, (( arithmetic command,
12591 [[ conditional command,
12592 arithmetic \fIfor\fP command, and before the first command executes
12593 in a shell function (see
12594 .SM
12595 .B "SHELL GRAMMAR"
12596 .ie \n(zZ=1 in \fIbash\fP(1)).
12597 .el above).
12598 Refer to the description of the \fBextdebug\fP shell option
12599 (see
12600 .B shopt
12601 .ie \n(zZ=1 in \fIbash\fP(1))
12602 .el above)
12603 for details of its effect on the \fBDEBUG\fP trap.
12604 If a
12605 .I sigspec
12606 is
12607 .SM
12608 .BR RETURN ,
12609 .I action
12610 is executed each time a shell function or a script executed with
12611 the \fB.\fP or \fBsource\fP builtins finishes executing.
12612 .IP
12613 If a
12614 .I sigspec
12615 is
12616 .SM
12617 .BR ERR ,
12618 .I action
12619 is executed whenever
12620 a pipeline (which may consist of a single simple
12621 command), a list, or a compound command returns a
12622 non\-zero exit status,
12623 subject to the following conditions.
12624 The
12625 .SM
12626 .B ERR
12627 trap is not executed if the failed
12628 command is part of the command list immediately following a
12629 .B while
12630 or
12631 .B until
12632 reserved word,
12633 part of the test in an
12634 .I if
12635 statement, part of a command executed in a
12636 .B &&
12637 or
12638 .B ||
12639 list except the command following the final \fB&&\fP or \fB||\fP,
12640 any command in a pipeline but the last
12641 (subject to the state of the \fBpipefail\fP shell option),
12642 or if the command's return value is
12643 being inverted using
12644 .BR ! .
12645 These are the same conditions obeyed by the \fBerrexit\fP (\fB\-e\fP) option.
12646 .IP
12647 When the shell is not interactive,
12648 signals ignored upon entry to the shell cannot be trapped or reset.
12649 Interactive shells permit trapping signals ignored on entry.
12650 Trapped signals that are not being ignored are reset to their original
12651 values in a subshell or subshell environment when one is created.
12652 The return status is false if any
12653 .I sigspec
12654 is invalid; otherwise
12655 .B trap
12656 returns true.
12657 .TP
12658 \fBtrue\fP
12659 Does nothing, returns a 0 status.
12660 .TP
12661 \fBtype\fP [\fB\-aftpP\fP] \fIname\fP [\fIname\fP .\|.\|.]
12662 Indicate how each
12663 .I name
12664 would be interpreted if used as a command name.
12665 .IP
12666 If the
12667 .B \-t
12668 option is used,
12669 .B type
12670 prints a string which is one of
12671 .IR alias ,
12672 .IR keyword ,
12673 .IR function ,
12674 .IR builtin ,
12675 or
12676 .I file
12677 if
12678 .I name
12679 is an alias, shell reserved word, function, builtin, or executable file,
12680 respectively.
12681 If the
12682 .I name
12683 is not found, \fBtype\fP prints nothing and returns a non-zero exit status.
12684 .IP
12685 If the
12686 .B \-p
12687 option is used,
12688 .B type
12689 either returns the pathname of the executable file
12690 that would be found by searching
12691 .B $PATH
12692 for
12693 .I name
12694 or nothing if
12695 .Q "type \-t name"
12696 would not return
12697 .IR file .
12698 The
12699 .B \-P
12700 option forces a
12701 .SM
12702 .B PATH
12703 search for each \fIname\fP, even if
12704 .Q "type \-t name"
12705 would not return
12706 .IR file .
12707 If \fIname\fP is present in the table of hashed commands,
12708 .B \-p
12709 and
12710 .B \-P
12711 print the hashed value, which is not necessarily the file that appears
12712 first in
12713 .SM
12714 .BR PATH .
12715 .IP
12716 If the
12717 .B \-a
12718 option is used,
12719 .B type
12720 prints all of the places that contain a command named
12721 .IR name .
12722 This includes aliases, reserved words, functions, and builtins,
12723 but the path search options (\fB\-p\fP and \fB\-P\fP)
12724 can be supplied to restrict the output to executable files.
12725 \fBtype\fP does not consult the table of hashed commands
12726 when using
12727 .B \-a
12728 with
12729 .BR \-p ,
12730 and only performs a
12731 .SM
12732 .B PATH
12733 search for \fIname\fP.
12734 .IP
12735 The
12736 .B \-f
12737 option suppresses shell function lookup, as with the \fBcommand\fP builtin.
12738 .B type
12739 returns true if all of the arguments are found, false if
12740 any are not found.
12741 .TP
12742 \fBulimit\fP [\fB\-HS\fP] \fB\-a\fP
12743 .PD 0
12744 .TP
12745 \fBulimit\fP [\fB\-HS\fP] [\fB\-bcdefiklmnpqrstuvxPRT\fP [\fIlimit\fP]]
12746 .PD
12747 Provides control over the resources available to the shell and to
12748 processes it starts, on systems that allow such control.
12749 .IP
12750 The \fB\-H\fP and \fB\-S\fP options specify whether
12751 the hard or soft limit is set for the given resource.
12752 A hard limit cannot be increased by a non-root user once it is set;
12753 a soft limit may be increased up to the value of the hard limit.
12754 If neither \fB\-H\fP nor \fB\-S\fP is specified,
12755 \fBulimit\fP sets both the soft and hard limits.
12756 .IP
12757 The value of
12758 .I limit
12759 can be a number in the unit specified for the resource
12760 or one of the special values
12761 .BR hard ,
12762 .BR soft ,
12763 or
12764 .BR unlimited ,
12765 which stand for the current hard limit, the current soft limit, and
12766 no limit, respectively.
12767 If
12768 .I limit
12769 is omitted, \fBulimit\fP prints the current value of the soft limit of
12770 the resource, unless the \fB\-H\fP option is given.
12771 When more than one resource is specified, the limit name and unit,
12772 if appropriate, are printed before the value.
12773 Other options are interpreted as follows:
12774 .RS
12775 .PD 0
12776 .TP
12777 .B \-a
12778 Report all current limits; no limits are set.
12779 .TP
12780 .B \-b
12781 The maximum socket buffer size.
12782 .TP
12783 .B \-c
12784 The maximum size of core files created.
12785 .TP
12786 .B \-d
12787 The maximum size of a process's data segment.
12788 .TP
12789 .B \-e
12790 The maximum scheduling priority (\c
12791 .Q nice ).
12792 .TP
12793 .B \-f
12794 The maximum size of files written by the shell and its children.
12795 .TP
12796 .B \-i
12797 The maximum number of pending signals.
12798 .TP
12799 .B \-k
12800 The maximum number of kqueues that may be allocated.
12801 .TP
12802 .B \-l
12803 The maximum size that may be locked into memory.
12804 .TP
12805 .B \-m
12806 The maximum resident set size (many systems do not honor this limit).
12807 .TP
12808 .B \-n
12809 The maximum number of open file descriptors (most systems do not
12810 allow this value to be set).
12811 .TP
12812 .B \-p
12813 The pipe size in 512-byte blocks (this may not be set).
12814 .TP
12815 .B \-q
12816 The maximum number of bytes in
12817 .SM POSIX
12818 message queues.
12819 .TP
12820 .B \-r
12821 The maximum real-time scheduling priority.
12822 .TP
12823 .B \-s
12824 The maximum stack size.
12825 .TP
12826 .B \-t
12827 The maximum amount of cpu time in seconds.
12828 .TP
12829 .B \-u
12830 The maximum number of processes available to a single user.
12831 .TP
12832 .B \-v
12833 The maximum amount of virtual memory available to the shell and, on
12834 some systems, to its children.
12835 .TP
12836 .B \-x
12837 The maximum number of file locks.
12838 .TP
12839 .B \-P
12840 The maximum number of pseudoterminals.
12841 .TP
12842 .B \-R
12843 The maximum time a real-time process can run before blocking, in microseconds.
12844 .TP
12845 .B \-T
12846 The maximum number of threads.
12847 .PD
12848 .PP
12849 If
12850 .I limit
12851 is supplied, and the
12852 .B \-a
12853 option is not used,
12854 \fIlimit\fP is the new value of the specified resource.
12855 If no option is supplied, then
12856 .B \-f
12857 is assumed.
12858 .PP
12859 Values are in 1024-byte increments, except for
12860 .BR \-t ,
12861 which is in seconds;
12862 .BR \-R ,
12863 which is in microseconds;
12864 .BR \-p ,
12865 which is in units of 512-byte blocks;
12866 .BR \-P ,
12867 .BR \-T ,
12868 .BR \-b ,
12869 .BR \-k ,
12870 .BR \-n ,
12871 and
12872 .BR \-u ,
12873 which are unscaled values;
12874 and, when in posix mode,
12875 .B \-c
12876 and
12877 .BR \-f ,
12878 which are in 512-byte increments.
12879 The return status is 0 unless an invalid option or argument is supplied,
12880 or an error occurs while setting a new limit.
12881 .RE
12882 .TP
12883 \fBumask\fP [\fB\-p\fP] [\fB\-S\fP] [\fImode\fP]
12884 Set the user file-creation mask to
12885 .IR mode .
12886 If
12887 .I mode
12888 begins with a digit, it is interpreted as an octal number;
12889 otherwise it is interpreted as a symbolic mode mask similar
12890 to that accepted by
12891 .IR chmod (1).
12892 If
12893 .I mode
12894 is omitted, \fBumask\fP prints the current value of the mask.
12895 The
12896 .B \-S
12897 option without a \fImode\fP argument
12898 prints the mask in a symbolic format;
12899 the default output is an octal number.
12900 If the
12901 .B \-p
12902 option is supplied, and
12903 .I mode
12904 is omitted, the output is in a form that may be reused as input.
12905 The return status is zero if the mode was successfully changed or
12906 if no \fImode\fP argument was supplied, and non-zero otherwise.
12907 .TP
12908 \fBunalias\fP [\-\fBa\fP] [\fIname\fP .\|.\|.]
12909 Remove each \fIname\fP from the list of defined aliases.
12910 If
12911 .B \-a
12912 is supplied, remove all alias definitions.
12913 The return value is true unless a supplied
12914 .I name
12915 is not a defined alias.
12916 .TP
12917 \fBunset\fP [\-\fBfv\fP] [\-\fBn\fP] [\fIname\fP .\|.\|.]
12918 For each
12919 .IR name ,
12920 remove the corresponding variable or function.
12921 If the
12922 .B \-v
12923 option is given, each
12924 .I name
12925 refers to a shell variable, and that variable is removed.
12926 If
12927 .B \-f
12928 is specified, each
12929 .I name
12930 refers to a shell function, and the function definition
12931 is removed.
12932 If the
12933 .B \-n
12934 option is supplied, and \fIname\fP is a variable with the \fInameref\fP
12935 attribute, \fIname\fP will be unset rather than the variable it
12936 references.
12937 \fB\-n\fP has no effect if the \fB\-f\fP option is supplied.
12938 Read-only variables and functions may not be unset.
12939 When variables or functions are removed, they are also removed
12940 from the environment passed to subsequent commands.
12941 If no options are supplied, each \fIname\fP refers to a variable; if
12942 there is no variable by that name, a function with that name, if any, is
12943 unset.
12944 Some shell variables may not be unset.
12945 If any of
12946 .SM
12947 .BR BASH_ALIASES ,
12948 .SM
12949 .BR BASH_ARGV0 ,
12950 .SM
12951 .BR BASH_CMDS ,
12952 .SM
12953 .BR BASH_COMMAND ,
12954 .SM
12955 .BR BASH_SUBSHELL ,
12956 .SM
12957 .BR BASHPID ,
12958 .SM
12959 .BR COMP_WORDBREAKS ,
12960 .SM
12961 .BR DIRSTACK ,
12962 .SM
12963 .BR EPOCHREALTIME ,
12964 .SM
12965 .BR EPOCHSECONDS ,
12966 .SM
12967 .BR FUNCNAME ,
12968 .SM
12969 .BR GROUPS ,
12970 .SM
12971 .BR HISTCMD ,
12972 .SM
12973 .BR LINENO ,
12974 .SM
12975 .BR RANDOM ,
12976 .SM
12977 .BR SECONDS ,
12978 or
12979 .SM
12980 .B SRANDOM
12981 are unset, they lose their special properties, even if they are
12982 subsequently reset.
12983 The exit status is true unless a
12984 .I name
12985 is readonly or may not be unset.
12986 .TP
12987 \fBwait\fP [\fB\-fn\fP] [\fP\-p\fP \fIvarname\fP] [\fIid\fP .\|.\|.]
12988 Wait for each specified child process \fIid\fP and return the
12989 termination status of the last \fIid\fP.
12990 Each \fIid\fP may be a process ID \fIpid\fP
12991 or a job specification \fIjobspec\fP;
12992 if a jobspec is supplied, \fBwait\fP waits for all processes in the job.
12993 .IP
12994 If no options or \fIid\fPs are supplied,
12995 \fBwait\fP waits for all running background jobs and
12996 the last-executed process substitution,
12997 if its process id is the same as \fB$!\fP,
12998 and the return status is zero.
12999 .IP
13000 If the \fB\-n\fP option is supplied, \fBwait\fP waits for any one of
13001 the given \fIid\fPs or,
13002 if no \fIid\fPs are supplied, any job or process substitution,
13003 to complete and returns its exit status.
13004 If none of the supplied \fIid\fPs is a child of the shell,
13005 or if no \fIid\fPs are supplied and the shell has no unwaited-for children,
13006 the exit status is 127.
13007 .IP
13008 If the \fB\-p\fP option is supplied, \fBwait\fP assigns
13009 the process or job identifier of the job
13010 for which the exit status is returned to the
13011 variable \fIvarname\fP named by the option argument.
13012 The variable,
13013 which cannot be readonly,
13014 will be unset initially, before any assignment.
13015 This is useful only when used with the \fB\-n\fP option.
13016 .IP
13017 Supplying the \fB\-f\fP option, when job control is enabled,
13018 forces \fBwait\fP to wait for each \fIid\fP to terminate before
13019 returning its status, instead of returning when it changes status.
13020 .IP
13021 If none of the \fIid\fPs specify one of the shell's active child
13022 processes, the return status is 127.
13023 If \fBwait\fP is interrupted by a signal,
13024 any \fIvarname\fP will remain unset,
13025 and the return status will be greater
13026 than 128, as described under
13027 .B SIGNALS
13028 .ie \n(zZ=1 in \fIbash\fP(1).
13029 .el above.
13030 Otherwise, the return status is the exit status of the last \fIid\fP.
13031 .SH "SHELL COMPATIBILITY MODE"
13032 Bash-4.0 introduced the concept of a \fIshell compatibility level\fP,
13033 specified as a set of options to the shopt builtin (\c
13034 .BR compat31 ,
13035 .BR compat32 ,
13036 .BR compat40 ,
13037 .BR compat41 ,
13038 and so on).
13039 There is only one current
13040 compatibility level \(em each option is mutually exclusive.
13041 The compatibility level is intended to allow users to select behavior
13042 from previous versions that is incompatible with newer versions
13043 while they migrate scripts to use current features and behavior.
13044 It's intended to be a temporary solution.
13045 .PP
13046 This section does not mention behavior that is standard for a particular
13047 version (e.g., setting \fBcompat32\fP means that quoting the right hand
13048 side of the regexp
13049 matching operator quotes special regexp characters in the word, which is
13050 default behavior in bash-3.2 and subsequent versions).
13051 .PP
13052 If a user enables, say, \fBcompat32\fP, it may affect the behavior of other
13053 compatibility levels up to and including the current compatibility level.
13054 The idea is that each compatibility level controls behavior that changed
13055 in that version of \fBbash\fP,
13056 but that behavior may have been present in earlier versions.
13057 For instance, the change to use locale-based comparisons with the \fB[[\fP
13058 command came in bash-4.1, and earlier versions used ASCII-based comparisons,
13059 so enabling \fBcompat32\fP will enable ASCII-based comparisons as well.
13060 That granularity may not be sufficient for
13061 all uses, and as a result users should employ compatibility levels carefully.
13062 Read the documentation for a particular feature to find out the
13063 current behavior.
13064 .PP
13065 Bash-4.3 introduced a new shell variable:
13066 .SM
13067 .BR BASH_COMPAT .
13068 The value assigned
13069 to this variable (a decimal version number like 4.2, or an integer
13070 corresponding to the \fBcompat\fP\fINN\fP option, like 42) determines the
13071 compatibility level.
13072 .PP
13073 Starting with bash-4.4, \fBbash\fP began deprecating older compatibility
13074 levels.
13075 Eventually, the options will be removed in favor of
13076 .SM
13077 .BR BASH_COMPAT .
13078 .PP
13079 Bash-5.0 was the final version for which there was an individual shopt
13080 option for the previous version.
13081 .SM
13082 .B BASH_COMPAT
13083 is the only mechanism to control the compatibility level
13084 in versions newer than bash-5.0.
13085 .PP
13086 The following table describes the behavior changes controlled by each
13087 compatibility level setting.
13088 The \fBcompat\fP\fINN\fP tag is used as shorthand for setting the
13089 compatibility level
13090 to \fINN\fP using one of the following mechanisms.
13091 For versions prior to bash-5.0, the compatibility level may be set using
13092 the corresponding \fBcompat\fP\fINN\fP shopt option.
13093 For bash-4.3 and later versions, the
13094 .SM
13095 .B BASH_COMPAT
13096 variable is preferred,
13097 and it is required for bash-5.1 and later versions.
13098 .TP
13099 \fBcompat31\fP
13100 .PD 0
13101 .RS
13102 .IP \(bu
13103 Quoting the rhs of the \fB[[\fP command's regexp matching operator (=\*~)
13104 has no special effect.
13105 .RE
13106 .PD
13107 .TP
13108 \fBcompat32\fP
13109 .PD 0
13110 .RS
13111 .IP \(bu
13112 The \fB<\fP and \fB>\fP operators to the \fB[[\fP command do not
13113 consider the current locale when comparing strings; they use ASCII
13114 ordering.
13115 .RE
13116 .PD
13117 .TP
13118 \fBcompat40\fP
13119 .PD 0
13120 .RS
13121 .IP \(bu
13122 The \fB<\fP and \fB>\fP operators to the \fB[[\fP command do not
13123 consider the current locale when comparing strings; they use ASCII
13124 ordering.
13125 \fBBash\fP versions prior to bash-4.1 use ASCII collation and
13126 .IR strcmp (3);
13127 bash-4.1 and later use the current locale's collation sequence and
13128 .IR strcoll (3).
13129 .RE
13130 .PD
13131 .TP
13132 \fBcompat41\fP
13133 .PD 0
13134 .RS
13135 .IP \(bu
13136 In posix mode, \fBtime\fP may be followed by options and still be
13137 recognized as a reserved word (this is
13138 .SM POSIX
13139 interpretation 267).
13140 .IP \(bu
13141 In \fIposix\fP mode, the parser requires that an even number of single
13142 quotes occur in the \fIword\fP portion of a double-quoted
13143 parameter expansion and treats them specially, so that characters within
13144 the single quotes are considered quoted
13145 (this is
13146 .SM POSIX
13147 interpretation 221).
13148 .RE
13149 .PD
13150 .TP
13151 \fBcompat42\fP
13152 .PD 0
13153 .RS
13154 .IP \(bu
13155 The replacement string in double-quoted pattern substitution does not
13156 undergo quote removal, as it does in versions after bash-4.2.
13157 .IP \(bu
13158 In posix mode, single quotes are considered special when expanding
13159 the \fIword\fP portion of a double-quoted parameter expansion
13160 and can be used to quote a closing brace or other special character
13161 (this is part of
13162 .SM POSIX
13163 interpretation 221);
13164 in later versions, single quotes
13165 are not special within double-quoted word expansions.
13166 .RE
13167 .PD
13168 .TP
13169 \fBcompat43\fP
13170 .PD 0
13171 .RS
13172 .IP \(bu
13173 Word expansion errors are considered non-fatal errors that cause the
13174 current command to fail, even in posix mode
13175 (the default behavior is to make them fatal errors that cause the shell
13176 to exit).
13177 .IP \(bu
13178 When executing a shell function, the loop state (while/until/etc.)
13179 is not reset, so \fBbreak\fP or \fBcontinue\fP in that function will break
13180 or continue loops in the calling context.
13181 Bash-4.4 and later reset the loop state to prevent this.
13182 .RE
13183 .PD
13184 .TP
13185 \fBcompat44\fP
13186 .PD 0
13187 .RS
13188 .IP \(bu
13189 The shell sets up the values used by
13190 .SM
13191 .B BASH_ARGV
13192 and
13193 .SM
13194 .B BASH_ARGC
13195 so they can expand to the shell's positional parameters even if extended
13196 debugging mode is not enabled.
13197 .IP \(bu
13198 A subshell inherits loops from its parent context, so \fBbreak\fP
13199 or \fBcontinue\fP will cause the subshell to exit.
13200 Bash-5.0 and later reset the loop state to prevent the exit
13201 .IP \(bu
13202 Variable assignments preceding builtins like \fBexport\fP and \fBreadonly\fP
13203 that set attributes continue to affect variables with the same
13204 name in the calling environment even if the shell is not in posix
13205 mode.
13206 .RE
13207 .PD
13208 .TP
13209 \fBcompat50\fP
13210 .PD 0
13211 .RS
13212 .IP \(bu
13213 Bash-5.1 changed the way
13214 .SM
13215 .B $RANDOM
13216 is generated to introduce slightly more randomness.
13217 If the shell compatibility level is set to 50 or
13218 lower, it reverts to the method from bash-5.0 and previous versions,
13219 so seeding the random number generator by assigning a value to
13220 .SM
13221 .B RANDOM
13222 will produce the same sequence as in bash-5.0.
13223 .IP \(bu
13224 If the command hash table is empty, bash versions prior to bash-5.1
13225 printed an informational message to that effect, even when producing
13226 output that can be reused as input.
13227 Bash-5.1 suppresses that message
13228 when the \fB\-l\fP option is supplied.
13229 .RE
13230 .PD
13231 .TP
13232 \fBcompat51\fP
13233 .PD 0
13234 .RS
13235 .IP \(bu
13236 The \fBunset\fP builtin treats attempts to unset array subscripts \fB@\fP
13237 and \fB*\fP differently depending on whether the array is indexed or
13238 associative, and differently than in previous versions.
13239 .IP \(bu
13240 Arithmetic commands (
13241 .BR (( .\|.\|.\& ))
13242 ) and the expressions in an arithmetic for
13243 statement can be expanded more than once.
13244 .IP \(bu
13245 Expressions used as arguments to arithmetic operators in the \fB[[\fP
13246 conditional command can be expanded more than once.
13247 .IP \(bu
13248 The expressions in substring parameter brace expansion can be
13249 expanded more than once.
13250 .IP \(bu
13251 The expressions in the
13252 .BR $(( .\|.\|.\& ))
13253 word expansion can be expanded more than once.
13254 .IP \(bu
13255 Arithmetic expressions used as indexed array subscripts can be
13256 expanded more than once.
13257 .IP \(bu
13258 \fBtest \-v\fP, when given an argument of \fBA[@]\fP, where \fBA\fP is
13259 an existing associative array, will return true if the array has any set
13260 elements.
13261 Bash-5.2 will look for and report on a key named \fB@\fP.
13262 .IP \(bu
13263 The ${\fIparameter\fP\fB[:]=\fP\fIvalue\fP} word expansion will return
13264 \fIvalue\fP, before any variable-specific transformations have been
13265 performed (e.g., converting to lowercase).
13266 Bash-5.2 will return the final value assigned to the variable.
13267 .IP \(bu
13268 Parsing command substitutions will behave as if extended globbing
13269 (see the description of the
13270 .B shopt
13271 builtin above)
13272 is enabled, so that parsing a command substitution containing an extglob
13273 pattern (say, as part of a shell function) will not fail.
13274 This assumes the intent is to enable extglob before the command is executed
13275 and word expansions are performed.
13276 It will fail at word expansion time if extglob hasn't been
13277 enabled by the time the command is executed.
13278 .RE
13279 .PD
13280 .TP
13281 \fBcompat52\fP
13282 .PD 0
13283 .RS
13284 .IP \(bu
13285 The \fBtest\fP builtin uses its historical algorithm to parse parenthesized
13286 subexpressions when given five or more arguments.
13287 .IP \(bu
13288 If the \fB\-p\fP or \fB\-P\fP option is supplied to the \fBbind\fP builtin,
13289 \fBbind\fP treats any arguments remaining after option processing
13290 as bindable command names, and
13291 displays any key sequences bound to those commands, instead of treating
13292 the arguments as key sequences to bind.
13293 .RE
13294 .PD
13295 .\" bash_builtins
13296 .if \n(zZ=1 .ig zZ
13297 .SH "RESTRICTED SHELL"
13298 .\" rbash.1
13299 .zY
13300 .if !dFN \{\
13301 .de FN
13302 \fI\|\\$1\|\fP
13303 ..
13304 .\}
13305 .PP
13306 If
13307 .B bash
13308 is started with the name
13309 .BR rbash ,
13310 or the
13311 .B \-r
13312 option is supplied at invocation, the shell becomes \fIrestricted\fP.
13313 A restricted shell is used to
13314 set up an environment more controlled than the standard shell.
13315 It behaves identically to
13316 .B bash
13317 with the exception that the following are disallowed or not performed:
13318 .IP \(bu
13319 Changing directories with \fBcd\fP.
13320 .IP \(bu
13321 Setting or unsetting the values of
13322 .SM
13323 .BR SHELL ,
13324 .SM
13325 .BR PATH ,
13326 .SM
13327 .BR HISTFILE ,
13328 .SM
13329 .BR ENV ,
13330 or
13331 .SM
13332 .BR BASH_ENV .
13333 .IP \(bu
13334 Specifying command names containing
13335 .BR / .
13336 .IP \(bu
13337 Specifying a filename containing a
13338 .B /
13339 as an argument to the
13340 .B .
13341 builtin command.
13342 .IP \(bu
13343 Using the \fB\-p\fP option to the
13344 .B .
13345 builtin command to specify a search path.
13346 .IP \(bu
13347 Specifying a filename containing a slash as an argument to the
13348 .B history
13349 builtin command.
13350 .IP \(bu
13351 Specifying a filename containing a slash as an argument to the
13352 .B \-p
13353 option to the
13354 .B hash
13355 builtin command.
13356 .IP \(bu
13357 Importing function definitions from the shell environment at startup.
13358 .IP \(bu
13359 Parsing the values of
13360 .SM
13361 .B BASHOPTS
13362 and
13363 .SM
13364 .B SHELLOPTS
13365 from the shell environment at startup.
13366 .IP \(bu
13367 Redirecting output using the >, >|, <>, >&, &>, and >> redirection operators.
13368 .IP \(bu
13369 Using the
13370 .B exec
13371 builtin command to replace the shell with another command.
13372 .IP \(bu
13373 Adding or deleting builtin commands with the
13374 .B \-f
13375 and
13376 .B \-d
13377 options to the
13378 .B enable
13379 builtin command.
13380 .IP \(bu
13381 Using the \fBenable\fP builtin command to enable disabled shell builtins.
13382 .IP \(bu
13383 Specifying the
13384 .B \-p
13385 option to the
13386 .B command
13387 builtin command.
13388 .IP \(bu
13389 Turning off restricted mode with
13390 \fBset +r\fP or \fBshopt \-u restricted_shell\fP.
13391 .PP
13392 These restrictions are enforced after any startup files are read.
13393 .PP
13394 .ie \n(zY=1 When a command that is found to be a shell script is executed,
13395 .el \{ When a command that is found to be a shell script is executed
13396 (see
13397 .SM
13398 .B "COMMAND EXECUTION"
13399 above),
13400 .\}
13401 .B rbash
13402 turns off any restrictions in the shell spawned to execute the
13403 script.
13404 .\" end of rbash.1
13405 .if \n(zY=1 .ig zY
13406 .SH "SEE ALSO"
13407 .PD 0
13408 .TP
13409 \fIBash Reference Manual\fP, Brian Fox and Chet Ramey
13410 .TP
13411 \fIThe Gnu Readline Library\fP, Brian Fox and Chet Ramey
13412 .TP
13413 \fIThe Gnu History Library\fP, Brian Fox and Chet Ramey
13414 .TP
13415 \fIPortable Operating System Interface (POSIX) Part 2: Shell and Utilities\fP, IEEE \(em
13416 http://pubs.opengroup.org/onlinepubs/9799919799/
13417 .TP
13418 http://tiswww.case.edu/\*~chet/bash/POSIX \(em a description of posix mode
13419 .TP
13420 \fIsh\fP(1), \fIksh\fP(1), \fIcsh\fP(1)
13421 .TP
13422 \fIemacs\fP(1), \fIvi\fP(1)
13423 .TP
13424 \fIreadline\fP(3)
13425 .PD
13426 .SH FILES
13427 .PD 0
13428 .TP
13429 .FN /bin/bash
13430 The \fBbash\fP executable
13431 .TP
13432 .FN /etc/profile
13433 The systemwide initialization file, executed for login shells
13434 .TP
13435 .FN \*~/.bash_profile
13436 The personal initialization file, executed for login shells
13437 .TP
13438 .FN \*~/.bashrc
13439 The individual per-interactive-shell startup file
13440 .TP
13441 .FN \*~/.bash_logout
13442 The individual login shell cleanup file, executed when a login shell exits
13443 .TP
13444 .FN \*~/.bash_history
13445 The default value of \fBHISTFILE\fP, the file in which bash saves the
13446 command history
13447 .TP
13448 .FN \*~/.inputrc
13449 Individual \fIreadline\fP initialization file
13450 .TP
13451 .FN /etc/inputrc
13452 System \fBreadline\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