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