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