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