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