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