]>
Commit | Line | Data |
---|---|---|
d3ad40de | 1 | .\" |
726f6388 JA |
2 | .\" MAN PAGE COMMENTS to |
3 | .\" | |
4 | .\" Chet Ramey | |
726f6388 | 5 | .\" Case Western Reserve University |
bb579650 | 6 | .\" chet.ramey@case.edu |
726f6388 | 7 | .\" |
06c3a575 | 8 | .\" Last Change: Sat Mar 21 20:10:48 EDT 2015 |
726f6388 JA |
9 | .\" |
10 | .\" bash_builtins, strip all but Built-Ins section | |
11 | .if \n(zZ=1 .ig zZ | |
bb70624e | 12 | .if \n(zY=1 .ig zY |
06c3a575 | 13 | .TH BASH 1 "2015 March 21" "GNU Bash 4.4" |
726f6388 JA |
14 | .\" |
15 | .\" There's some problem with having a `@' | |
16 | .\" in a tagged paragraph with the BSD man macros. | |
17 | .\" It has to do with `@' appearing in the }1 macro. | |
18 | .\" This is a problem on 4.3 BSD and Ultrix, but Sun | |
19 | .\" appears to have fixed it. | |
20 | .\" If you're seeing the characters | |
21 | .\" `@u-3p' appearing before the lines reading | |
22 | .\" `possible-hostname-completions | |
23 | .\" and `complete-hostname' down in READLINE, | |
24 | .\" then uncomment this redefinition. | |
25 | .\" | |
26 | .de }1 | |
27 | .ds ]X \&\\*(]B\\ | |
28 | .nr )E 0 | |
29 | .if !"\\$1"" .nr )I \\$1n | |
30 | .}f | |
31 | .ll \\n(LLu | |
32 | .in \\n()Ru+\\n(INu+\\n()Iu | |
33 | .ti \\n(INu | |
34 | .ie !\\n()Iu+\\n()Ru-\w\a\\*(]X\au-3p \{\\*(]X | |
35 | .br\} | |
36 | .el \\*(]X\h\a|\\n()Iu+\\n()Ru\a\c | |
37 | .}f | |
38 | .. | |
39 | .\" | |
40 | .\" File Name macro. This used to be `.PN', for Path Name, | |
41 | .\" but Sun doesn't seem to like that very much. | |
42 | .\" | |
43 | .de FN | |
44 | \fI\|\\$1\|\fP | |
45 | .. | |
46 | .SH NAME | |
ccc6cda3 | 47 | bash \- GNU Bourne-Again SHell |
726f6388 JA |
48 | .SH SYNOPSIS |
49 | .B bash | |
50 | [options] | |
e67d0029 | 51 | [command_string | file] |
726f6388 | 52 | .SH COPYRIGHT |
8f50a023 CR |
53 | .if n Bash is Copyright (C) 1989-2015 by the Free Software Foundation, Inc. |
54 | .if t Bash is Copyright \(co 1989-2015 by the Free Software Foundation, Inc. | |
726f6388 JA |
55 | .SH DESCRIPTION |
56 | .B Bash | |
ccc6cda3 | 57 | is an \fBsh\fR-compatible command language interpreter that |
726f6388 JA |
58 | executes commands read from the standard input or from a file. |
59 | .B Bash | |
60 | also incorporates useful features from the \fIKorn\fP and \fIC\fP | |
61 | shells (\fBksh\fP and \fBcsh\fP). | |
62 | .PP | |
63 | .B Bash | |
ac18b312 CR |
64 | is intended to be a conformant implementation of the |
65 | Shell and Utilities portion of the IEEE POSIX specification | |
66 | (IEEE Standard 1003.1). | |
7790f917 CR |
67 | .B Bash |
68 | can be configured to be POSIX-conformant by default. | |
726f6388 | 69 | .SH OPTIONS |
fc527055 | 70 | All of the single-character shell options documented in the |
3d8cce26 CR |
71 | description of the \fBset\fR builtin command can be used as options |
72 | when the shell is invoked. | |
73 | In addition, \fBbash\fR | |
cce855bc | 74 | interprets the following options when it is invoked: |
726f6388 JA |
75 | .PP |
76 | .PD 0 | |
77 | .TP 10 | |
e67d0029 | 78 | .B \-c |
ccc6cda3 | 79 | If the |
726f6388 | 80 | .B \-c |
e67d0029 CR |
81 | option is present, then commands are read from the first non-option argument |
82 | .IR command_string . | |
726f6388 | 83 | If there are arguments after the |
e67d0029 | 84 | .IR command_string , |
aee3e561 CR |
85 | the first argument is assigned to |
86 | .B $0 | |
87 | and any remaining arguments are assigned to the positional parameters. | |
88 | The assignment to | |
89 | .B $0 | |
90 | sets the name of the shell, which is used in warning and error messages. | |
726f6388 | 91 | .TP |
7117c2d2 JA |
92 | .B \-i |
93 | If the | |
94 | .B \-i | |
95 | option is present, the shell is | |
96 | .IR interactive . | |
97 | .TP | |
98 | .B \-l | |
99 | Make | |
100 | .B bash | |
101 | act as if it had been invoked as a login shell (see | |
102 | .SM | |
103 | .B INVOCATION | |
104 | below). | |
105 | .TP | |
ccc6cda3 JA |
106 | .B \-r |
107 | If the | |
108 | .B \-r | |
cce855bc | 109 | option is present, the shell becomes |
ccc6cda3 JA |
110 | .I restricted |
111 | (see | |
112 | .SM | |
113 | .B "RESTRICTED SHELL" | |
114 | below). | |
115 | .TP | |
726f6388 JA |
116 | .B \-s |
117 | If the | |
118 | .B \-s | |
cce855bc | 119 | option is present, or if no arguments remain after option |
726f6388 JA |
120 | processing, then commands are read from the standard input. |
121 | This option allows the positional parameters to be set | |
122 | when invoking an interactive shell. | |
123 | .TP | |
ccc6cda3 JA |
124 | .B \-D |
125 | A list of all double-quoted strings preceded by \fB$\fP | |
22e63b05 | 126 | is printed on the standard output. |
ccc6cda3 JA |
127 | These are the strings that |
128 | are subject to language translation when the current locale | |
28ef6c31 | 129 | is not \fBC\fP or \fBPOSIX\fP. |
ccc6cda3 JA |
130 | This implies the \fB\-n\fP option; no commands will be executed. |
131 | .TP | |
f73dda09 JA |
132 | .B [\-+]O [\fIshopt_option\fP] |
133 | \fIshopt_option\fP is one of the shell options accepted by the | |
134 | \fBshopt\fP builtin (see | |
135 | .SM | |
136 | .B SHELL BUILTIN COMMANDS | |
137 | below). | |
138 | If \fIshopt_option\fP is present, \fB\-O\fP sets the value of that option; | |
139 | \fB+O\fP unsets it. | |
140 | If \fIshopt_option\fP is not supplied, the names and values of the shell | |
141 | options accepted by \fBshopt\fP are printed on the standard output. | |
142 | If the invocation option is \fB+O\fP, the output is displayed in a format | |
143 | that may be reused as input. | |
144 | .TP | |
ccc6cda3 JA |
145 | .B \-\- |
146 | A | |
147 | .B \-\- | |
726f6388 JA |
148 | signals the end of options and disables further option processing. |
149 | Any arguments after the | |
726f6388 | 150 | .B \-\- |
ccc6cda3 JA |
151 | are treated as filenames and arguments. An argument of |
152 | .B \- | |
153 | is equivalent to \fB\-\-\fP. | |
726f6388 JA |
154 | .PD |
155 | .PP | |
156 | .B Bash | |
ccc6cda3 JA |
157 | also interprets a number of multi-character options. |
158 | These options must appear on the command line before the | |
7117c2d2 | 159 | single-character options to be recognized. |
726f6388 JA |
160 | .PP |
161 | .PD 0 | |
726f6388 | 162 | .TP |
d3a24ed2 CR |
163 | .B \-\-debugger |
164 | Arrange for the debugger profile to be executed before the shell | |
2206f89a CR |
165 | starts. |
166 | Turns on extended debugging mode (see the description of the | |
d3a24ed2 CR |
167 | .B extdebug |
168 | option to the | |
169 | .B shopt | |
d3a24ed2 CR |
170 | builtin below). |
171 | .TP | |
cce855bc JA |
172 | .B \-\-dump\-po\-strings |
173 | Equivalent to \fB\-D\fP, but the output is in the GNU \fIgettext\fP | |
174 | \fBpo\fP (portable object) file format. | |
175 | .TP | |
ccc6cda3 JA |
176 | .B \-\-dump\-strings |
177 | Equivalent to \fB\-D\fP. | |
178 | .TP | |
179 | .B \-\-help | |
180 | Display a usage message on standard output and exit successfully. | |
181 | .TP | |
28ef6c31 | 182 | \fB\-\-init\-file\fP \fIfile\fP |
7117c2d2 | 183 | .PD 0 |
28ef6c31 JA |
184 | .TP |
185 | \fB\-\-rcfile\fP \fIfile\fP | |
186 | .PD | |
187 | Execute commands from | |
188 | .I file | |
189 | instead of the standard personal initialization file | |
190 | .I ~/.bashrc | |
191 | if the shell is interactive (see | |
192 | .SM | |
193 | .B INVOCATION | |
194 | below). | |
195 | .TP | |
ccc6cda3 | 196 | .B \-\-login |
7117c2d2 | 197 | Equivalent to \fB\-l\fP. |
ccc6cda3 JA |
198 | .TP |
199 | .B \-\-noediting | |
200 | Do not use the GNU | |
201 | .B readline | |
bb70624e | 202 | library to read command lines when the shell is interactive. |
ccc6cda3 JA |
203 | .TP |
204 | .B \-\-noprofile | |
205 | Do not read either the system-wide startup file | |
726f6388 JA |
206 | .FN /etc/profile |
207 | or any of the personal initialization files | |
208 | .IR ~/.bash_profile , | |
209 | .IR ~/.bash_login , | |
210 | or | |
211 | .IR ~/.profile . | |
212 | By default, | |
213 | .B bash | |
ccc6cda3 | 214 | reads these files when it is invoked as a login shell (see |
726f6388 JA |
215 | .SM |
216 | .B INVOCATION | |
217 | below). | |
218 | .TP | |
ccc6cda3 JA |
219 | .B \-\-norc |
220 | Do not read and execute the personal initialization file | |
221 | .I ~/.bashrc | |
222 | if the shell is interactive. | |
223 | This option is on by default if the shell is invoked as | |
224 | .BR sh . | |
225 | .TP | |
226 | .B \-\-posix | |
227 | Change the behavior of \fBbash\fP where the default operation differs | |
ac18b312 | 228 | from the POSIX standard to match the standard (\fIposix mode\fP). |
c677e9e0 CR |
229 | See |
230 | .SM | |
231 | .B "SEE ALSO" | |
232 | below for a reference to a document that details how posix mode affects | |
233 | bash's behavior. | |
726f6388 | 234 | .TP |
ccc6cda3 JA |
235 | .B \-\-restricted |
236 | The shell becomes restricted (see | |
237 | .SM | |
238 | .B "RESTRICTED SHELL" | |
726f6388 JA |
239 | below). |
240 | .TP | |
ccc6cda3 | 241 | .B \-\-verbose |
fc527055 | 242 | Equivalent to \fB\-v\fP. |
726f6388 | 243 | .TP |
ccc6cda3 JA |
244 | .B \-\-version |
245 | Show version information for this instance of | |
246 | .B bash | |
247 | on the standard output and exit successfully. | |
726f6388 JA |
248 | .PD |
249 | .SH ARGUMENTS | |
250 | If arguments remain after option processing, and neither the | |
251 | .B \-c | |
252 | nor the | |
253 | .B \-s | |
254 | option has been supplied, the first argument is assumed to | |
ccc6cda3 JA |
255 | be the name of a file containing shell commands. |
256 | If | |
726f6388 | 257 | .B bash |
fc527055 | 258 | is invoked in this fashion, |
726f6388 JA |
259 | .B $0 |
260 | is set to the name of the file, and the positional parameters | |
261 | are set to the remaining arguments. | |
262 | .B Bash | |
263 | reads and executes commands from this file, then exits. | |
ccc6cda3 JA |
264 | \fBBash\fP's exit status is the exit status of the last command |
265 | executed in the script. | |
266 | If no commands are executed, the exit status is 0. | |
f73dda09 JA |
267 | An attempt is first made to open the file in the current directory, and, |
268 | if no file is found, then the shell searches the directories in | |
269 | .SM | |
270 | .B PATH | |
271 | for the script. | |
ccc6cda3 JA |
272 | .SH INVOCATION |
273 | A \fIlogin shell\fP is one whose first character of argument zero is a | |
274 | .BR \- , | |
fc527055 | 275 | or one started with the |
ccc6cda3 JA |
276 | .B \-\-login |
277 | option. | |
278 | .PP | |
bb70624e | 279 | An \fIinteractive\fP shell is one started without non-option arguments |
06c3a575 | 280 | (unless \fB\-s\fP is specified) |
bb70624e JA |
281 | and without the |
282 | .B \-c | |
283 | option | |
da5b17cd | 284 | whose standard input and error are |
ccc6cda3 JA |
285 | both connected to terminals (as determined by |
286 | .IR isatty (3)), | |
287 | or one started with the | |
288 | .B \-i | |
289 | option. | |
290 | .SM | |
291 | .B PS1 | |
292 | is set and | |
293 | .B $\- | |
294 | includes | |
295 | .B i | |
296 | if | |
297 | .B bash | |
298 | is interactive, | |
299 | allowing a shell script or a startup file to test this state. | |
300 | .PP | |
301 | The following paragraphs describe how | |
302 | .B bash | |
303 | executes its startup files. | |
304 | If any of the files exist but cannot be read, | |
305 | .B bash | |
306 | reports an error. | |
b28ff8c9 | 307 | Tildes are expanded in filenames as described below under |
ccc6cda3 JA |
308 | .B "Tilde Expansion" |
309 | in the | |
310 | .SM | |
311 | .B EXPANSION | |
312 | section. | |
313 | .PP | |
314 | When | |
315 | .B bash | |
b72432fd JA |
316 | is invoked as an interactive login shell, or as a non-interactive shell |
317 | with the \fB\-\-login\fP option, it first reads and | |
d166f048 JA |
318 | executes commands from the file \fI/etc/profile\fP, if that |
319 | file exists. | |
ccc6cda3 JA |
320 | After reading that file, it looks for \fI~/.bash_profile\fP, |
321 | \fI~/.bash_login\fP, and \fI~/.profile\fP, in that order, and reads | |
322 | and executes commands from the first one that exists and is readable. | |
323 | The | |
324 | .B \-\-noprofile | |
325 | option may be used when the shell is started to inhibit this behavior. | |
326 | .PP | |
327 | When a login shell exits, | |
328 | .B bash | |
329 | reads and executes commands from the file \fI~/.bash_logout\fP, if it | |
330 | exists. | |
331 | .PP | |
332 | When an interactive shell that is not a login shell is started, | |
333 | .B bash | |
334 | reads and executes commands from \fI~/.bashrc\fP, if that file exists. | |
335 | This may be inhibited by using the | |
336 | .B \-\-norc | |
337 | option. | |
338 | The \fB\-\-rcfile\fP \fIfile\fP option will force | |
339 | .B bash | |
340 | to read and execute commands from \fIfile\fP instead of \fI~/.bashrc\fP. | |
341 | .PP | |
342 | When | |
343 | .B bash | |
344 | is started non-interactively, to run a shell script, for example, it | |
345 | looks for the variable | |
346 | .SM | |
347 | .B BASH_ENV | |
348 | in the environment, expands its value if it appears there, and uses the | |
349 | expanded value as the name of a file to read and execute. | |
350 | .B Bash | |
351 | behaves as if the following command were executed: | |
352 | .sp .5 | |
353 | .RS | |
28ef6c31 JA |
354 | .if t \f(CWif [ \-n "$BASH_ENV" ]; then . "$BASH_ENV"; fi\fP |
355 | .if n if [ \-n "$BASH_ENV" ]; then . "$BASH_ENV"; fi | |
ccc6cda3 JA |
356 | .RE |
357 | .sp .5 | |
358 | but the value of the | |
359 | .SM | |
360 | .B PATH | |
b28ff8c9 | 361 | variable is not used to search for the filename. |
ccc6cda3 JA |
362 | .PP |
363 | If | |
364 | .B bash | |
365 | is invoked with the name | |
366 | .BR sh , | |
367 | it tries to mimic the startup behavior of historical versions of | |
368 | .B sh | |
369 | as closely as possible, | |
370 | while conforming to the POSIX standard as well. | |
b72432fd JA |
371 | When invoked as an interactive login shell, or a non-interactive |
372 | shell with the \fB\-\-login\fP option, it first attempts to | |
cce855bc | 373 | read and execute commands from |
ccc6cda3 JA |
374 | .I /etc/profile |
375 | and | |
376 | .IR ~/.profile , | |
377 | in that order. | |
378 | The | |
379 | .B \-\-noprofile | |
380 | option may be used to inhibit this behavior. | |
381 | When invoked as an interactive shell with the name | |
382 | .BR sh , | |
383 | .B bash | |
384 | looks for the variable | |
385 | .SM | |
386 | .BR ENV , | |
387 | expands its value if it is defined, and uses the | |
388 | expanded value as the name of a file to read and execute. | |
389 | Since a shell invoked as | |
390 | .B sh | |
391 | does not attempt to read and execute commands from any other startup | |
392 | files, the | |
393 | .B \-\-rcfile | |
394 | option has no effect. | |
395 | A non-interactive shell invoked with the name | |
396 | .B sh | |
b72432fd | 397 | does not attempt to read any other startup files. |
ccc6cda3 JA |
398 | When invoked as |
399 | .BR sh , | |
400 | .B bash | |
401 | enters | |
402 | .I posix | |
403 | mode after the startup files are read. | |
404 | .PP | |
405 | When | |
406 | .B bash | |
407 | is started in | |
408 | .I posix | |
409 | mode, as with the | |
410 | .B \-\-posix | |
411 | command line option, it follows the POSIX standard for startup files. | |
cce855bc | 412 | In this mode, interactive shells expand the |
ccc6cda3 JA |
413 | .SM |
414 | .B ENV | |
cce855bc | 415 | variable and commands are read and executed from the file |
ccc6cda3 JA |
416 | whose name is the expanded value. |
417 | No other startup files are read. | |
ccc6cda3 JA |
418 | .PP |
419 | .B Bash | |
866961ad | 420 | attempts to determine when it is being run with its standard input |
dc60d4e0 | 421 | connected to a network connection, as when executed by the remote shell |
866961ad | 422 | daemon, usually \fIrshd\fP, or the secure shell daemon \fIsshd\fP. |
ccc6cda3 JA |
423 | If |
424 | .B bash | |
866961ad | 425 | determines it is being run in this fashion, it reads and executes |
ccc6cda3 JA |
426 | commands from \fI~/.bashrc\fP, if that file exists and is readable. |
427 | It will not do this if invoked as \fBsh\fP. | |
428 | The | |
429 | .B \-\-norc | |
430 | option may be used to inhibit this behavior, and the | |
431 | .B \-\-rcfile | |
0ee50808 CR |
432 | option may be used to force another file to be read, but neither |
433 | \fIrshd\fP nor \fIsshd\fP generally invoke the shell with those options | |
ccc6cda3 | 434 | or allow them to be specified. |
b72432fd JA |
435 | .PP |
436 | If the shell is started with the effective user (group) id not equal to the | |
437 | real user (group) id, and the \fB\-p\fP option is not supplied, no startup | |
f73dda09 JA |
438 | files are read, shell functions are not inherited from the environment, the |
439 | .SM | |
691aebcb | 440 | .BR SHELLOPTS , |
984a1947 | 441 | .SM |
691aebcb | 442 | .BR BASHOPTS , |
984a1947 | 443 | .SM |
691aebcb CR |
444 | .BR CDPATH , |
445 | and | |
984a1947 | 446 | .SM |
691aebcb CR |
447 | .B GLOBIGNORE |
448 | variables, if they appear in the environment, are ignored, | |
b72432fd JA |
449 | and the effective user id is set to the real user id. |
450 | If the \fB\-p\fP option is supplied at invocation, the startup behavior is | |
451 | the same, but the effective user id is not reset. | |
726f6388 | 452 | .SH DEFINITIONS |
ccc6cda3 JA |
453 | .PP |
454 | The following definitions are used throughout the rest of this | |
455 | document. | |
726f6388 JA |
456 | .PD 0 |
457 | .TP | |
fc527055 | 458 | .B blank |
726f6388 JA |
459 | A space or tab. |
460 | .TP | |
461 | .B word | |
462 | A sequence of characters considered as a single unit by the shell. | |
463 | Also known as a | |
464 | .BR token . | |
465 | .TP | |
466 | .B name | |
fc527055 | 467 | A |
726f6388 JA |
468 | .I word |
469 | consisting only of alphanumeric characters and underscores, and | |
470 | beginning with an alphabetic character or an underscore. Also | |
471 | referred to as an | |
472 | .BR identifier . | |
473 | .TP | |
474 | .B metacharacter | |
475 | A character that, when unquoted, separates words. One of the following: | |
476 | .br | |
477 | .RS | |
478 | .PP | |
479 | .if t \fB| & ; ( ) < > space tab\fP | |
480 | .if n \fB| & ; ( ) < > space tab\fP | |
481 | .RE | |
482 | .PP | |
483 | .TP | |
484 | .B control operator | |
485 | A \fItoken\fP that performs a control function. It is one of the following | |
486 | symbols: | |
487 | .RS | |
488 | .PP | |
adc6cff5 | 489 | .if t \fB|| & && ; ;; ( ) | |& <newline>\fP |
8943768b | 490 | .if n \fB|| & && ; ;; ( ) | |& <newline>\fP |
726f6388 JA |
491 | .RE |
492 | .PD | |
493 | .SH "RESERVED WORDS" | |
494 | \fIReserved words\fP are words that have a special meaning to the shell. | |
495 | The following words are recognized as reserved when unquoted and either | |
496 | the first word of a simple command (see | |
497 | .SM | |
498 | .B SHELL GRAMMAR | |
fc527055 CR |
499 | below) or the third word of a |
500 | .B case | |
726f6388 JA |
501 | or |
502 | .B for | |
503 | command: | |
504 | .if t .RS | |
505 | .PP | |
506 | .B | |
8360b906 CR |
507 | .if n ! case coproc do done elif else esac fi for function if in select then until while { } time [[ ]] |
508 | .if t ! case coproc do done elif else esac fi for function if in select then until while { } time [[ ]] | |
726f6388 | 509 | .if t .RE |
726f6388 JA |
510 | .SH "SHELL GRAMMAR" |
511 | .SS Simple Commands | |
512 | .PP | |
513 | A \fIsimple command\fP is a sequence of optional variable assignments | |
ccc6cda3 | 514 | followed by \fBblank\fP-separated words and redirections, and |
726f6388 | 515 | terminated by a \fIcontrol operator\fP. The first word |
f73dda09 JA |
516 | specifies the command to be executed, and is passed as argument zero. |
517 | The remaining words are passed as arguments to the invoked command. | |
726f6388 JA |
518 | .PP |
519 | The return value of a \fIsimple command\fP is its exit status, or | |
520 | 128+\fIn\^\fP if the command is terminated by signal | |
521 | .IR n . | |
522 | .SS Pipelines | |
523 | .PP | |
524 | A \fIpipeline\fP is a sequence of one or more commands separated by | |
8943768b CR |
525 | one of the control operators |
526 | .B | | |
527 | or \fB|&\fP. | |
726f6388 JA |
528 | The format for a pipeline is: |
529 | .RS | |
530 | .PP | |
8943768b | 531 | [\fBtime\fP [\fB\-p\fP]] [ ! ] \fIcommand\fP [ [\fB|\fP\(bv\fB|&\fP] \fIcommand2\fP ... ] |
726f6388 JA |
532 | .RE |
533 | .PP | |
534 | The standard output of | |
535 | .I command | |
f73dda09 | 536 | is connected via a pipe to the standard input of |
726f6388 JA |
537 | .IR command2 . |
538 | This connection is performed before any redirections specified by the | |
539 | command (see | |
540 | .SM | |
541 | .B REDIRECTION | |
542 | below). | |
0ee50808 CR |
543 | If \fB|&\fP is used, \fIcommand\fP's standard error, in addition to its |
544 | standard output, is connected to | |
c920c360 CR |
545 | \fIcommand2\fP's standard input through the pipe; |
546 | it is shorthand for \fB2>&1 |\fP. | |
0ee50808 | 547 | This implicit redirection of the standard error to the standard output is |
c920c360 | 548 | performed after any redirections specified by the command. |
726f6388 | 549 | .PP |
d3a24ed2 CR |
550 | The return status of a pipeline is the exit status of the last |
551 | command, unless the \fBpipefail\fP option is enabled. | |
552 | If \fBpipefail\fP is enabled, the pipeline's return status is the | |
553 | value of the last (rightmost) command to exit with a non-zero status, | |
554 | or zero if all commands exit successfully. | |
726f6388 JA |
555 | If the reserved word |
556 | .B ! | |
d3a24ed2 CR |
557 | precedes a pipeline, the exit status of that pipeline is the logical |
558 | negation of the exit status as described above. | |
ccc6cda3 | 559 | The shell waits for all commands in the pipeline to |
726f6388 JA |
560 | terminate before returning a value. |
561 | .PP | |
ccc6cda3 JA |
562 | If the |
563 | .B time | |
564 | reserved word precedes a pipeline, the elapsed as well as user and | |
565 | system time consumed by its execution are reported when the pipeline | |
566 | terminates. | |
567 | The \fB\-p\fP option changes the output format to that specified by POSIX. | |
7d92f73f CR |
568 | When the shell is in \fIposix mode\fP, it does not recognize |
569 | \fBtime\fP as a reserved word if the next token begins with a `-'. | |
ccc6cda3 JA |
570 | The |
571 | .SM | |
572 | .B TIMEFORMAT | |
573 | variable may be set to a format string that specifies how the timing | |
574 | information should be displayed; see the description of | |
575 | .SM | |
576 | .B TIMEFORMAT | |
577 | under | |
578 | .B "Shell Variables" | |
579 | below. | |
580 | .PP | |
6faad625 CR |
581 | When the shell is in \fIposix mode\fP, \fBtime\fP |
582 | may be followed by a newline. In this case, the shell displays the | |
583 | total user and system time consumed by the shell and its children. | |
584 | The | |
585 | .SM | |
586 | .B TIMEFORMAT | |
587 | variable may be used to specify the format of | |
588 | the time information. | |
589 | .PP | |
726f6388 JA |
590 | Each command in a pipeline is executed as a separate process (i.e., in a |
591 | subshell). | |
592 | .SS Lists | |
593 | .PP | |
594 | A \fIlist\fP is a sequence of one or more pipelines separated by one | |
595 | of the operators | |
596 | .BR ; , | |
597 | .BR & , | |
598 | .BR && , | |
599 | or | |
adc6cff5 | 600 | .BR || , |
ccc6cda3 | 601 | and optionally terminated by one of |
726f6388 JA |
602 | .BR ; , |
603 | .BR & , | |
604 | or | |
605 | .BR <newline> . | |
606 | .PP | |
607 | Of these list operators, | |
608 | .B && | |
609 | and | |
adc6cff5 | 610 | .B || |
726f6388 JA |
611 | have equal precedence, followed by |
612 | .B ; | |
613 | and | |
b1a26c01 | 614 | .BR & , |
726f6388 JA |
615 | which have equal precedence. |
616 | .PP | |
7117c2d2 JA |
617 | A sequence of one or more newlines may appear in a \fIlist\fP instead |
618 | of a semicolon to delimit commands. | |
619 | .PP | |
726f6388 JA |
620 | If a command is terminated by the control operator |
621 | .BR & , | |
622 | the shell executes the command in the \fIbackground\fP | |
623 | in a subshell. The shell does not wait for the command to | |
624 | finish, and the return status is 0. Commands separated by a | |
625 | .B ; | |
626 | are executed sequentially; the shell waits for each | |
627 | command to terminate in turn. The return status is the | |
628 | exit status of the last command executed. | |
629 | .PP | |
6fbe7620 | 630 | AND and OR lists are sequences of one of more pipelines separated by the |
adc6cff5 | 631 | \fB&&\fP and \fB||\fP control operators, respectively. |
6fbe7620 | 632 | AND and OR lists are executed with left associativity. |
726f6388 JA |
633 | An AND list has the form |
634 | .RS | |
635 | .PP | |
bb70624e | 636 | \fIcommand1\fP \fB&&\fP \fIcommand2\fP |
726f6388 JA |
637 | .RE |
638 | .PP | |
639 | .I command2 | |
640 | is executed if, and only if, | |
bb70624e | 641 | .I command1 |
726f6388 JA |
642 | returns an exit status of zero. |
643 | .PP | |
644 | An OR list has the form | |
645 | .RS | |
646 | .PP | |
adc6cff5 | 647 | \fIcommand1\fP \fB||\fP \fIcommand2\fP |
726f6388 JA |
648 | .PP |
649 | .RE | |
650 | .PP | |
651 | .I command2 | |
652 | is executed if and only if | |
bb70624e | 653 | .I command1 |
6fbe7620 CR |
654 | returns a non-zero exit status. |
655 | The return status of | |
726f6388 JA |
656 | AND and OR lists is the exit status of the last command |
657 | executed in the list. | |
658 | .SS Compound Commands | |
659 | .PP | |
f4f5e1c2 CR |
660 | A \fIcompound command\fP is one of the following. |
661 | In most cases a \fIlist\fP in a command's description may be separated from | |
662 | the rest of the command by one or more newlines, and may be followed by a | |
663 | newline in place of a semicolon. | |
726f6388 JA |
664 | .TP |
665 | (\fIlist\fP) | |
d3a24ed2 CR |
666 | \fIlist\fP is executed in a subshell environment (see |
667 | .SM | |
668 | \fBCOMMAND EXECUTION ENVIRONMENT\fP | |
669 | below). | |
670 | Variable assignments and builtin | |
726f6388 JA |
671 | commands that affect the shell's environment do not remain in effect |
672 | after the command completes. The return status is the exit status of | |
673 | \fIlist\fP. | |
674 | .TP | |
675 | { \fIlist\fP; } | |
ccc6cda3 JA |
676 | \fIlist\fP is simply executed in the current shell environment. |
677 | \fIlist\fP must be terminated with a newline or semicolon. | |
678 | This is known as a \fIgroup command\fP. | |
679 | The return status is the exit status of | |
726f6388 | 680 | \fIlist\fP. |
d3a24ed2 | 681 | Note that unlike the metacharacters \fB(\fP and \fB)\fP, \fB{\fP and |
f73dda09 JA |
682 | \fB}\fP are \fIreserved words\fP and must occur where a reserved |
683 | word is permitted to be recognized. Since they do not cause a word | |
641d8f00 CR |
684 | break, they must be separated from \fIlist\fP by whitespace or another |
685 | shell metacharacter. | |
726f6388 | 686 | .TP |
ccc6cda3 JA |
687 | ((\fIexpression\fP)) |
688 | The \fIexpression\fP is evaluated according to the rules described | |
689 | below under | |
690 | .SM | |
691 | .BR "ARITHMETIC EVALUATION" . | |
692 | If the value of the expression is non-zero, the return status is 0; | |
693 | otherwise the return status is 1. This is exactly equivalent to | |
694 | \fBlet "\fIexpression\fP"\fR. | |
695 | .TP | |
cce855bc JA |
696 | \fB[[\fP \fIexpression\fP \fB]]\fP |
697 | Return a status of 0 or 1 depending on the evaluation of | |
698 | the conditional expression \fIexpression\fP. | |
699 | Expressions are composed of the primaries described below under | |
700 | .SM | |
701 | .BR "CONDITIONAL EXPRESSIONS" . | |
702 | Word splitting and pathname expansion are not performed on the words | |
15825757 CR |
703 | between the \fB[[\fP and \fB]]\fP; tilde expansion, |
704 | parameter and variable expansion, | |
705 | arithmetic expansion, command substitution, process | |
cce855bc | 706 | substitution, and quote removal are performed. |
d3a24ed2 CR |
707 | Conditional operators such as \fB\-f\fP must be unquoted to be recognized |
708 | as primaries. | |
cce855bc JA |
709 | .if t .sp 0.5 |
710 | .if n .sp 1 | |
54a1fa7c | 711 | When used with \fB[[\fP, the \fB<\fP and \fB>\fP operators sort |
a8fd3f3e CR |
712 | lexicographically using the current locale. |
713 | .if t .sp 0.5 | |
714 | .if n .sp 1 | |
cce855bc JA |
715 | When the \fB==\fP and \fB!=\fP operators are used, the string to the |
716 | right of the operator is considered a pattern and matched according | |
d1ce6d68 CR |
717 | to the rules described below under \fBPattern Matching\fP, |
718 | as if the \fBextglob\fP shell option were enabled. | |
df0e4bfe | 719 | The \fB=\fP operator is equivalent to \fB==\fP. |
0a233f3e | 720 | If the |
2206f89a | 721 | .B nocasematch |
0a233f3e | 722 | shell option is enabled, the match is performed without regard to the case |
2206f89a | 723 | of alphabetic characters. |
dc8fbaf9 CR |
724 | The return value is 0 if the string matches (\fB==\fP) or does not match |
725 | (\fB!=\fP) the pattern, and 1 otherwise. | |
e192f341 CR |
726 | Any part of the pattern may be quoted to force the quoted portion |
727 | to be matched as a string. | |
cce855bc JA |
728 | .if t .sp 0.5 |
729 | .if n .sp 1 | |
d3a24ed2 CR |
730 | An additional binary operator, \fB=~\fP, is available, with the same |
731 | precedence as \fB==\fP and \fB!=\fP. | |
732 | When it is used, the string to the right of the operator is considered | |
fc527055 | 733 | an extended regular expression and matched accordingly (as in \fIregex\fP(3)). |
d7f49990 CR |
734 | The return value is 0 if the string matches |
735 | the pattern, and 1 otherwise. | |
d3a24ed2 CR |
736 | If the regular expression is syntactically incorrect, the conditional |
737 | expression's return value is 2. | |
0a233f3e | 738 | If the |
2206f89a | 739 | .B nocasematch |
0a233f3e | 740 | shell option is enabled, the match is performed without regard to the case |
d3a24ed2 | 741 | of alphabetic characters. |
e192f341 CR |
742 | Any part of the pattern may be quoted to force the quoted portion |
743 | to be matched as a string. | |
084c952b CR |
744 | Bracket expressions in regular expressions must be treated carefully, |
745 | since normal quoting characters lose their meanings between brackets. | |
746 | If the pattern is stored in a shell variable, quoting the variable | |
747 | expansion forces the entire pattern to be matched as a string. | |
d3a24ed2 | 748 | Substrings matched by parenthesized subexpressions within the regular |
984a1947 CR |
749 | expression are saved in the array variable |
750 | .SM | |
751 | .BR BASH_REMATCH . | |
752 | The element of | |
753 | .SM | |
754 | .B BASH_REMATCH | |
755 | with index 0 is the portion of the string | |
d3a24ed2 | 756 | matching the entire regular expression. |
984a1947 CR |
757 | The element of |
758 | .SM | |
759 | .B BASH_REMATCH | |
760 | with index \fIn\fP is the portion of the | |
d3a24ed2 CR |
761 | string matching the \fIn\fPth parenthesized subexpression. |
762 | .if t .sp 0.5 | |
763 | .if n .sp 1 | |
cce855bc JA |
764 | Expressions may be combined using the following operators, listed |
765 | in decreasing order of precedence: | |
766 | .if t .sp 0.5 | |
767 | .if n .sp 1 | |
768 | .RS | |
769 | .PD 0 | |
770 | .TP | |
771 | .B ( \fIexpression\fP ) | |
772 | Returns the value of \fIexpression\fP. | |
773 | This may be used to override the normal precedence of operators. | |
774 | .TP | |
775 | .B ! \fIexpression\fP | |
776 | True if | |
777 | .I expression | |
778 | is false. | |
779 | .TP | |
780 | \fIexpression1\fP \fB&&\fP \fIexpression2\fP | |
781 | True if both | |
782 | .I expression1 | |
783 | and | |
784 | .I expression2 | |
785 | are true. | |
786 | .TP | |
adc6cff5 | 787 | \fIexpression1\fP \fB||\fP \fIexpression2\fP |
cce855bc JA |
788 | True if either |
789 | .I expression1 | |
790 | or | |
791 | .I expression2 | |
792 | is true. | |
793 | .PD | |
cce855bc | 794 | .LP |
adc6cff5 | 795 | The \fB&&\fP and \fB||\fP |
7117c2d2 | 796 | operators do not evaluate \fIexpression2\fP if the value of |
cce855bc JA |
797 | \fIexpression1\fP is sufficient to determine the return value of |
798 | the entire conditional expression. | |
f73dda09 | 799 | .RE |
cce855bc | 800 | .TP |
0d8616ff | 801 | \fBfor\fP \fIname\fP [ [ \fBin\fP [ \fIword ...\fP ] ] ; ] \fBdo\fP \fIlist\fP ; \fBdone\fP |
726f6388 | 802 | The list of words following \fBin\fP is expanded, generating a list |
bb70624e JA |
803 | of items. |
804 | The variable \fIname\fP is set to each element of this list | |
805 | in turn, and \fIlist\fP is executed each time. | |
806 | If the \fBin\fP \fIword\fP is omitted, the \fBfor\fP command executes | |
807 | \fIlist\fP once for each positional parameter that is set (see | |
726f6388 JA |
808 | .SM |
809 | .B PARAMETERS | |
810 | below). | |
cce855bc JA |
811 | The return status is the exit status of the last command that executes. |
812 | If the expansion of the items following \fBin\fP results in an empty | |
813 | list, no commands are executed, and the return status is 0. | |
726f6388 | 814 | .TP |
bb70624e JA |
815 | \fBfor\fP (( \fIexpr1\fP ; \fIexpr2\fP ; \fIexpr3\fP )) ; \fBdo\fP \fIlist\fP ; \fBdone\fP |
816 | First, the arithmetic expression \fIexpr1\fP is evaluated according | |
817 | to the rules described below under | |
818 | .SM | |
819 | .BR "ARITHMETIC EVALUATION" . | |
820 | The arithmetic expression \fIexpr2\fP is then evaluated repeatedly | |
821 | until it evaluates to zero. | |
822 | Each time \fIexpr2\fP evaluates to a non-zero value, \fIlist\fP is | |
823 | executed and the arithmetic expression \fIexpr3\fP is evaluated. | |
824 | If any expression is omitted, it behaves as if it evaluates to 1. | |
825 | The return value is the exit status of the last command in \fIlist\fP | |
826 | that is executed, or false if any of the expressions is invalid. | |
827 | .TP | |
b72432fd | 828 | \fBselect\fP \fIname\fP [ \fBin\fP \fIword\fP ] ; \fBdo\fP \fIlist\fP ; \fBdone\fP |
726f6388 JA |
829 | The list of words following \fBin\fP is expanded, generating a list |
830 | of items. The set of expanded words is printed on the standard | |
831 | error, each preceded by a number. If the \fBin\fP | |
832 | \fIword\fP is omitted, the positional parameters are printed (see | |
833 | .SM | |
834 | .B PARAMETERS | |
835 | below). The | |
984a1947 | 836 | .SM |
726f6388 JA |
837 | .B PS3 |
838 | prompt is then displayed and a line read from the standard input. | |
ccc6cda3 | 839 | If the line consists of a number corresponding to one of |
726f6388 JA |
840 | the displayed words, then the value of |
841 | .I name | |
842 | is set to that word. If the line is empty, the words and prompt | |
843 | are displayed again. If EOF is read, the command completes. Any | |
844 | other value read causes | |
845 | .I name | |
846 | to be set to null. The line read is saved in the variable | |
984a1947 | 847 | .SM |
726f6388 JA |
848 | .BR REPLY . |
849 | The | |
850 | .I list | |
851 | is executed after each selection until a | |
852 | .B break | |
726f6388 JA |
853 | command is executed. |
854 | The exit status of | |
855 | .B select | |
856 | is the exit status of the last command executed in | |
857 | .IR list , | |
858 | or zero if no commands were executed. | |
859 | .TP | |
bb70624e | 860 | \fBcase\fP \fIword\fP \fBin\fP [ [(] \fIpattern\fP [ \fB|\fP \fIpattern\fP ] \ |
726f6388 JA |
861 | ... ) \fIlist\fP ;; ] ... \fBesac\fP |
862 | A \fBcase\fP command first expands \fIword\fP, and tries to match | |
863 | it against each \fIpattern\fP in turn, using the same matching rules | |
864 | as for pathname expansion (see | |
865 | .B Pathname Expansion | |
2206f89a | 866 | below). |
dc8fbaf9 | 867 | The \fIword\fP is expanded using tilde |
96f3fb66 | 868 | expansion, parameter and variable expansion, arithmetic expansion, |
dc8fbaf9 CR |
869 | command substitution, process substitution and quote removal. |
870 | Each \fIpattern\fP examined is expanded using tilde | |
96f3fb66 | 871 | expansion, parameter and variable expansion, arithmetic expansion, |
dc8fbaf9 | 872 | command substitution, and process substitution. |
0a233f3e | 873 | If the |
2206f89a | 874 | .B nocasematch |
0a233f3e | 875 | shell option is enabled, the match is performed without regard to the case |
2206f89a | 876 | of alphabetic characters. |
8943768b CR |
877 | When a match is found, the corresponding \fIlist\fP is executed. |
878 | If the \fB;;\fP operator is used, no subsequent matches are attempted after | |
879 | the first pattern match. | |
880 | Using \fB;&\fP in place of \fB;;\fP causes execution to continue with | |
881 | the \fIlist\fP associated with the next set of patterns. | |
882 | Using \fB;;&\fP in place of \fB;;\fP causes the shell to test the next | |
883 | pattern list in the statement, if any, and execute any associated \fIlist\fP | |
884 | on a successful match. | |
885 | The exit status is zero if no | |
ccc6cda3 | 886 | pattern matches. Otherwise, it is the exit status of the |
726f6388 JA |
887 | last command executed in \fIlist\fP. |
888 | .TP | |
5f0df7f9 | 889 | \fBif\fP \fIlist\fP; \fBthen\fP \fIlist\fP; \ |
ccc6cda3 JA |
890 | [ \fBelif\fP \fIlist\fP; \fBthen\fP \fIlist\fP; ] ... \ |
891 | [ \fBelse\fP \fIlist\fP; ] \fBfi\fP | |
726f6388 | 892 | The |
fc527055 | 893 | .B if |
726f6388 JA |
894 | .I list |
895 | is executed. If its exit status is zero, the | |
896 | \fBthen\fP \fIlist\fP is executed. Otherwise, each \fBelif\fP | |
897 | \fIlist\fP is executed in turn, and if its exit status is zero, | |
898 | the corresponding \fBthen\fP \fIlist\fP is executed and the | |
899 | command completes. Otherwise, the \fBelse\fP \fIlist\fP is | |
900 | executed, if present. The exit status is the exit status of the | |
901 | last command executed, or zero if no condition tested true. | |
902 | .TP | |
89c77bc7 | 903 | \fBwhile\fP \fIlist-1\fP; \fBdo\fP \fIlist-2\fP; \fBdone\fP |
7117c2d2 | 904 | .PD 0 |
726f6388 | 905 | .TP |
89c77bc7 | 906 | \fBuntil\fP \fIlist-1\fP; \fBdo\fP \fIlist-2\fP; \fBdone\fP |
726f6388 | 907 | .PD |
89c77bc7 CR |
908 | The \fBwhile\fP command continuously executes the list |
909 | \fIlist-2\fP as long as the last command in the list \fIlist-1\fP returns | |
726f6388 JA |
910 | an exit status of zero. The \fBuntil\fP command is identical |
911 | to the \fBwhile\fP command, except that the test is negated; | |
89c77bc7 | 912 | .I list-2 |
726f6388 | 913 | is executed as long as the last command in |
89c77bc7 | 914 | .I list-1 |
ccc6cda3 | 915 | returns a non-zero exit status. |
726f6388 JA |
916 | The exit status of the \fBwhile\fP and \fBuntil\fP commands |
917 | is the exit status | |
89c77bc7 | 918 | of the last command executed in \fIlist-2\fP, or zero if |
726f6388 | 919 | none was executed. |
09767ff0 CR |
920 | .SS Coprocesses |
921 | .PP | |
922 | A \fIcoprocess\fP is a shell command preceded by the \fBcoproc\fP reserved | |
923 | word. | |
924 | A coprocess is executed asynchronously in a subshell, as if the command | |
925 | had been terminated with the \fB&\fP control operator, with a two-way pipe | |
926 | established between the executing shell and the coprocess. | |
927 | .PP | |
928 | The format for a coprocess is: | |
929 | .RS | |
930 | .PP | |
931 | \fBcoproc\fP [\fINAME\fP] \fIcommand\fP [\fIredirections\fP] | |
932 | .RE | |
933 | .PP | |
934 | This creates a coprocess named \fINAME\fP. | |
f6da9f85 | 935 | If \fINAME\fP is not supplied, the default name is \fBCOPROC\fP. |
e141c35a CR |
936 | \fINAME\fP must not be supplied if \fIcommand\fP is a \fIsimple |
937 | command\fP (see above); otherwise, it is interpreted as the first word | |
938 | of the simple command. | |
b28ff8c9 | 939 | When the coprocess is executed, the shell creates an array variable (see |
09767ff0 CR |
940 | .B Arrays |
941 | below) named \fINAME\fP in the context of the executing shell. | |
942 | The standard output of | |
943 | .I command | |
944 | is connected via a pipe to a file descriptor in the executing shell, | |
945 | and that file descriptor is assigned to \fINAME\fP[0]. | |
946 | The standard input of | |
947 | .I command | |
948 | is connected via a pipe to a file descriptor in the executing shell, | |
949 | and that file descriptor is assigned to \fINAME\fP[1]. | |
950 | This pipe is established before any redirections specified by the | |
951 | command (see | |
952 | .SM | |
953 | .B REDIRECTION | |
954 | below). | |
955 | The file descriptors can be utilized as arguments to shell commands | |
956 | and redirections using standard word expansions. | |
8360b906 | 957 | The file descriptors are not available in subshells. |
dc60d4e0 | 958 | The process ID of the shell spawned to execute the coprocess is |
30915f17 CR |
959 | available as the value of the variable \fINAME\fP_PID. |
960 | The \fBwait\fP | |
961 | builtin command may be used to wait for the coprocess to terminate. | |
09767ff0 | 962 | .PP |
77b3aacb CR |
963 | Since the coprocess is created as an asynchronous command, |
964 | the \fBcoproc\fP command always returns success. | |
09767ff0 | 965 | The return status of a coprocess is the exit status of \fIcommand\fP. |
d3a24ed2 CR |
966 | .SS Shell Function Definitions |
967 | .PP | |
968 | A shell function is an object that is called like a simple command and | |
969 | executes a compound command with a new set of positional parameters. | |
970 | Shell functions are declared as follows: | |
971 | .TP | |
9ec5ed66 CR |
972 | \fIname\fP () \fIcompound\-command\fP [\fIredirection\fP] |
973 | .PD 0 | |
974 | .TP | |
975 | \fBfunction\fP \fIname\fP [()] \fIcompound\-command\fP [\fIredirection\fP] | |
976 | .PD | |
d3a24ed2 CR |
977 | This defines a function named \fIname\fP. |
978 | The reserved word \fBfunction\fP is optional. | |
979 | If the \fBfunction\fP reserved word is supplied, the parentheses are optional. | |
980 | The \fIbody\fP of the function is the compound command | |
fc527055 | 981 | .I compound\-command |
d3a24ed2 CR |
982 | (see \fBCompound Commands\fP above). |
983 | That command is usually a \fIlist\fP of commands between { and }, but | |
939d190e CR |
984 | may be any command listed under \fBCompound Commands\fP above, |
985 | with one exception: If the \fBfunction\fP reserved word is used, but the | |
986 | parentheses are not supplied, the braces are required. | |
d3a24ed2 CR |
987 | \fIcompound\-command\fP is executed whenever \fIname\fP is specified as the |
988 | name of a simple command. | |
b28ff8c9 CR |
989 | When in \fIposix mode\fP, \fIname\fP may not be the name of one of the |
990 | POSIX \fIspecial builtins\fP. | |
d3a24ed2 CR |
991 | Any redirections (see |
992 | .SM | |
993 | .B REDIRECTION | |
994 | below) specified when a function is defined are performed | |
995 | when the function is executed. | |
996 | The exit status of a function definition is zero unless a syntax error | |
997 | occurs or a readonly function with the same name already exists. | |
998 | When executed, the exit status of a function is the exit status of the | |
999 | last command executed in the body. (See | |
726f6388 JA |
1000 | .SM |
1001 | .B FUNCTIONS | |
1002 | below.) | |
1003 | .SH COMMENTS | |
ccc6cda3 JA |
1004 | In a non-interactive shell, or an interactive shell in which the |
1005 | .B interactive_comments | |
1006 | option to the | |
1007 | .B shopt | |
1008 | builtin is enabled (see | |
1009 | .SM | |
1010 | .B "SHELL BUILTIN COMMANDS" | |
1011 | below), a word beginning with | |
726f6388 JA |
1012 | .B # |
1013 | causes that word and all remaining characters on that line to | |
1014 | be ignored. An interactive shell without the | |
ccc6cda3 | 1015 | .B interactive_comments |
ccc6cda3 JA |
1016 | option enabled does not allow comments. The |
1017 | .B interactive_comments | |
1018 | option is on by default in interactive shells. | |
726f6388 JA |
1019 | .SH QUOTING |
1020 | \fIQuoting\fP is used to remove the special meaning of certain | |
fc527055 | 1021 | characters or words to the shell. Quoting can be used to |
726f6388 JA |
1022 | disable special treatment for special characters, to prevent |
1023 | reserved words from being recognized as such, and to prevent | |
1024 | parameter expansion. | |
1025 | .PP | |
1026 | Each of the \fImetacharacters\fP listed above under | |
1027 | .SM | |
1028 | .B DEFINITIONS | |
bb70624e JA |
1029 | has special meaning to the shell and must be quoted if it is to |
1030 | represent itself. | |
1031 | .PP | |
5c96a638 CR |
1032 | When the command history expansion facilities are being used |
1033 | (see | |
1034 | .SM | |
1035 | .B HISTORY EXPANSION | |
1036 | below), the | |
bb70624e JA |
1037 | \fIhistory expansion\fP character, usually \fB!\fP, must be quoted |
1038 | to prevent history expansion. | |
1039 | .PP | |
1040 | There are three quoting mechanisms: the | |
726f6388 JA |
1041 | .IR "escape character" , |
1042 | single quotes, and double quotes. | |
1043 | .PP | |
1044 | A non-quoted backslash (\fB\e\fP) is the | |
1045 | .IR "escape character" . | |
1046 | It preserves the literal value of the next character that follows, | |
1047 | with the exception of <newline>. If a \fB\e\fP<newline> pair | |
cce855bc JA |
1048 | appears, and the backslash is not itself quoted, the \fB\e\fP<newline> |
1049 | is treated as a line continuation (that is, it is removed from the | |
1050 | input stream and effectively ignored). | |
726f6388 JA |
1051 | .PP |
1052 | Enclosing characters in single quotes preserves the literal value | |
1053 | of each character within the quotes. A single quote may not occur | |
1054 | between single quotes, even when preceded by a backslash. | |
1055 | .PP | |
1056 | Enclosing characters in double quotes preserves the literal value | |
1057 | of all characters within the quotes, with the exception of | |
1058 | .BR $ , | |
3d4e09aa | 1059 | .BR \` , |
5c96a638 CR |
1060 | .BR \e , |
1061 | and, when history expansion is enabled, | |
1062 | .BR ! . | |
726f6388 JA |
1063 | The characters |
1064 | .B $ | |
1065 | and | |
3d4e09aa | 1066 | .B \` |
726f6388 JA |
1067 | retain their special meaning within double quotes. The backslash |
1068 | retains its special meaning only when followed by one of the following | |
1069 | characters: | |
1070 | .BR $ , | |
3d4e09aa | 1071 | .BR \` , |
726f6388 JA |
1072 | \^\fB"\fP\^, |
1073 | .BR \e , | |
1074 | or | |
1075 | .BR <newline> . | |
1076 | A double quote may be quoted within double quotes by preceding it with | |
1077 | a backslash. | |
5c96a638 CR |
1078 | If enabled, history expansion will be performed unless an |
1079 | .B ! | |
1080 | appearing in double quotes is escaped using a backslash. | |
1081 | The backslash preceding the | |
1082 | .B ! | |
1083 | is not removed. | |
726f6388 JA |
1084 | .PP |
1085 | The special parameters | |
1086 | .B * | |
1087 | and | |
1088 | .B @ | |
1089 | have special meaning when in double | |
1090 | quotes (see | |
1091 | .SM | |
1092 | .B PARAMETERS | |
1093 | below). | |
ccc6cda3 | 1094 | .PP |
20587658 | 1095 | Words of the form \fB$\fP\(aq\fIstring\fP\(aq are treated specially. The |
ccc6cda3 | 1096 | word expands to \fIstring\fP, with backslash-escaped characters replaced |
f75912ae | 1097 | as specified by the ANSI C standard. Backslash escape sequences, if |
ccc6cda3 JA |
1098 | present, are decoded as follows: |
1099 | .RS | |
1100 | .PD 0 | |
1101 | .TP | |
1102 | .B \ea | |
1103 | alert (bell) | |
1104 | .TP | |
1105 | .B \eb | |
1106 | backspace | |
1107 | .TP | |
1108 | .B \ee | |
a3143574 CR |
1109 | .TP |
1110 | .B \eE | |
ccc6cda3 | 1111 | an escape character |
fc527055 | 1112 | .TP |
ccc6cda3 JA |
1113 | .B \ef |
1114 | form feed | |
fc527055 | 1115 | .TP |
ccc6cda3 JA |
1116 | .B \en |
1117 | new line | |
fc527055 | 1118 | .TP |
ccc6cda3 JA |
1119 | .B \er |
1120 | carriage return | |
1121 | .TP | |
1122 | .B \et | |
1123 | horizontal tab | |
fc527055 | 1124 | .TP |
ccc6cda3 JA |
1125 | .B \ev |
1126 | vertical tab | |
1127 | .TP | |
1128 | .B \e\e | |
1129 | backslash | |
bb70624e | 1130 | .TP |
20587658 | 1131 | .B \e\(aq |
bb70624e | 1132 | single quote |
a3143574 CR |
1133 | .TP |
1134 | .B \e\(dq | |
1135 | double quote | |
fc527055 | 1136 | .TP |
ccc6cda3 | 1137 | .B \e\fInnn\fP |
f73dda09 | 1138 | the eight-bit character whose value is the octal value \fInnn\fP |
cce855bc JA |
1139 | (one to three digits) |
1140 | .TP | |
f73dda09 JA |
1141 | .B \ex\fIHH\fP |
1142 | the eight-bit character whose value is the hexadecimal value \fIHH\fP | |
1143 | (one or two hex digits) | |
7117c2d2 | 1144 | .TP |
eb0b2ad8 CR |
1145 | .B \eu\fIHHHH\fP |
1146 | the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value | |
1147 | \fIHHHH\fP (one to four hex digits) | |
1148 | .TP | |
1149 | .B \eU\fIHHHHHHHH\fP | |
1150 | the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value | |
1151 | \fIHHHHHHHH\fP (one to eight hex digits) | |
1152 | .TP | |
7117c2d2 JA |
1153 | .B \ec\fIx\fP |
1154 | a control-\fIx\fP character | |
ccc6cda3 JA |
1155 | .PD |
1156 | .RE | |
1157 | .LP | |
bb70624e | 1158 | The expanded result is single-quoted, as if the dollar sign had |
ccc6cda3 JA |
1159 | not been present. |
1160 | .PP | |
08e72d7a CR |
1161 | A double-quoted string preceded by a dollar sign (\fB$\fP\(dq\fIstring\fP\(dq) |
1162 | will cause the string to be translated according to the current locale. | |
ccc6cda3 JA |
1163 | If the current locale is \fBC\fP or \fBPOSIX\fP, the dollar sign |
1164 | is ignored. | |
1165 | If the string is translated and replaced, the replacement is | |
1166 | double-quoted. | |
726f6388 JA |
1167 | .SH PARAMETERS |
1168 | A | |
1169 | .I parameter | |
ccc6cda3 JA |
1170 | is an entity that stores values. |
1171 | It can be a | |
726f6388 JA |
1172 | .IR name , |
1173 | a number, or one of the special characters listed below under | |
1174 | .BR "Special Parameters" . | |
d3a24ed2 | 1175 | A |
726f6388 JA |
1176 | .I variable |
1177 | is a parameter denoted by a | |
1178 | .IR name . | |
f73dda09 JA |
1179 | A variable has a \fIvalue\fP and zero or more \fIattributes\fP. |
1180 | Attributes are assigned using the | |
1181 | .B declare | |
1182 | builtin command (see | |
1183 | .B declare | |
1184 | below in | |
1185 | .SM | |
1186 | .BR "SHELL BUILTIN COMMANDS" ). | |
726f6388 JA |
1187 | .PP |
1188 | A parameter is set if it has been assigned a value. The null string is | |
1189 | a valid value. Once a variable is set, it may be unset only by using | |
1190 | the | |
1191 | .B unset | |
1192 | builtin command (see | |
1193 | .SM | |
1194 | .B SHELL BUILTIN COMMANDS | |
1195 | below). | |
1196 | .PP | |
1197 | A | |
1198 | .I variable | |
1199 | may be assigned to by a statement of the form | |
1200 | .RS | |
1201 | .PP | |
1202 | \fIname\fP=[\fIvalue\fP] | |
1203 | .RE | |
1204 | .PP | |
1205 | If | |
1206 | .I value | |
1207 | is not given, the variable is assigned the null string. All | |
1208 | .I values | |
bb70624e JA |
1209 | undergo tilde expansion, parameter and variable expansion, |
1210 | command substitution, arithmetic expansion, and quote | |
ccc6cda3 JA |
1211 | removal (see |
1212 | .SM | |
1213 | .B EXPANSION | |
1214 | below). If the variable has its | |
cce855bc | 1215 | .B integer |
f73dda09 | 1216 | attribute set, then |
726f6388 | 1217 | .I value |
d3a24ed2 | 1218 | is evaluated as an arithmetic expression even if the $((...)) expansion is |
cce855bc | 1219 | not used (see |
ccc6cda3 JA |
1220 | .B "Arithmetic Expansion" |
1221 | below). | |
1222 | Word splitting is not performed, with the exception | |
726f6388 JA |
1223 | of \fB"$@"\fP as explained below under |
1224 | .BR "Special Parameters" . | |
1225 | Pathname expansion is not performed. | |
f73dda09 | 1226 | Assignment statements may also appear as arguments to the |
5e13499c | 1227 | .BR alias , |
f73dda09 JA |
1228 | .BR declare , |
1229 | .BR typeset , | |
1230 | .BR export , | |
1231 | .BR readonly , | |
1232 | and | |
1233 | .B local | |
25a0eacf | 1234 | builtin commands (\fIdeclaration\fP commands). |
19baff85 CR |
1235 | When in \fIposix mode\fP, these builtins may appear in a command after |
1236 | one or more instances of the \fBcommand\fP builtin and retain these | |
1237 | assignment statement properties. | |
d11b8b46 CR |
1238 | .PP |
1239 | In the context where an assignment statement is assigning a value | |
1240 | to a shell variable or array index, the += operator can be used to | |
1241 | append to or add to the variable's previous value. | |
25a0eacf CR |
1242 | This includes arguments to builtin commands such as \fBdeclare\fP that |
1243 | accept assignment statements (\fIdeclaration\fP commands). | |
dc60d4e0 | 1244 | When += is applied to a variable for which the \fIinteger\fP attribute has been |
d11b8b46 CR |
1245 | set, \fIvalue\fP is evaluated as an arithmetic expression and added to the |
1246 | variable's current value, which is also evaluated. | |
1247 | When += is applied to an array variable using compound assignment (see | |
1248 | .B Arrays | |
1249 | below), the | |
1250 | variable's value is not unset (as it is when using =), and new values are | |
fdf670ea CR |
1251 | appended to the array beginning at one greater than the array's maximum index |
1252 | (for indexed arrays) or added as additional key\-value pairs in an | |
1253 | associative array. | |
d11b8b46 CR |
1254 | When applied to a string-valued variable, \fIvalue\fP is expanded and |
1255 | appended to the variable's value. | |
87c1f4ec CR |
1256 | .PP |
1257 | A variable can be assigned the \fInameref\fP attribute using the | |
1258 | \fB\-n\fP option to the \fBdeclare\fP or \fBlocal\fP builtin commands | |
1259 | (see the descriptions of \fBdeclare\fP and \fBlocal\fP below) | |
1260 | to create a \fInameref\fP, or a reference to another variable. | |
1261 | This allows variables to be manipulated indirectly. | |
d2465f43 | 1262 | Whenever the nameref variable is referenced, assigned to, unset, or has |
96f3fb66 | 1263 | its attributes modified (other than the \fInameref\fP attribute itself), the |
d2465f43 CR |
1264 | operation is actually performed on the variable specified by the nameref |
1265 | variable's value. | |
87c1f4ec CR |
1266 | A nameref is commonly used within shell functions to refer to a variable |
1267 | whose name is passed as an argument to the function. | |
1268 | For instance, if a variable name is passed to a shell function as its first | |
1269 | argument, running | |
1270 | .sp .5 | |
1271 | .RS | |
1272 | .if t \f(CWdeclare -n ref=$1\fP | |
1273 | .if n declare -n ref=$1 | |
1274 | .RE | |
1275 | .sp .5 | |
1276 | inside the function creates a nameref variable \fBref\fP whose value is | |
1277 | the variable name passed as the first argument. | |
d2465f43 CR |
1278 | References and assignments to \fBref\fP, and changes to its attributes, |
1279 | are treated as references, assignments, and attribute modifications | |
1280 | to the variable whose name was passed as \fB$1\fP. | |
87c1f4ec CR |
1281 | If the control variable in a \fBfor\fP loop has the nameref attribute, |
1282 | the list of words can be a list of shell variables, and a name reference | |
1283 | will be established for each word in the list, in turn, when the loop is | |
1284 | executed. | |
b4a00022 | 1285 | Array variables cannot be given the \fBnameref\fP attribute. |
87c1f4ec CR |
1286 | However, nameref variables can reference array variables and subscripted |
1287 | array variables. | |
1288 | Namerefs can be unset using the \fB\-n\fP option to the \fBunset\fP builtin. | |
1289 | Otherwise, if \fBunset\fP is executed with the name of a nameref variable | |
1290 | as an argument, the variable referenced by the nameref variable will be unset. | |
726f6388 JA |
1291 | .SS Positional Parameters |
1292 | .PP | |
1293 | A | |
1294 | .I positional parameter | |
1295 | is a parameter denoted by one or more | |
1296 | digits, other than the single digit 0. Positional parameters are | |
1297 | assigned from the shell's arguments when it is invoked, | |
1298 | and may be reassigned using the | |
1299 | .B set | |
1300 | builtin command. Positional parameters may not be assigned to | |
1301 | with assignment statements. The positional parameters are | |
1302 | temporarily replaced when a shell function is executed (see | |
1303 | .SM | |
1304 | .B FUNCTIONS | |
1305 | below). | |
1306 | .PP | |
1307 | When a positional parameter consisting of more than a single | |
1308 | digit is expanded, it must be enclosed in braces (see | |
1309 | .SM | |
1310 | .B EXPANSION | |
1311 | below). | |
1312 | .SS Special Parameters | |
1313 | .PP | |
1314 | The shell treats several parameters specially. These parameters may | |
1315 | only be referenced; assignment to them is not allowed. | |
1316 | .PD 0 | |
1317 | .TP | |
1318 | .B * | |
5f0df7f9 CR |
1319 | Expands to the positional parameters, starting from one. |
1320 | When the expansion is not within double quotes, each positional parameter | |
1321 | expands to a separate word. | |
1322 | In contexts where it is performed, those words | |
1323 | are subject to further word splitting and pathname expansion. | |
1324 | When the expansion occurs within double quotes, it expands to a single word | |
fc527055 | 1325 | with the value of each parameter separated by the first character of the |
726f6388 JA |
1326 | .SM |
1327 | .B IFS | |
cce855bc JA |
1328 | special variable. That is, "\fB$*\fP" is equivalent |
1329 | to "\fB$1\fP\fIc\fP\fB$2\fP\fIc\fP\fB...\fP", where | |
726f6388 JA |
1330 | .I c |
1331 | is the first character of the value of the | |
1332 | .SM | |
1333 | .B IFS | |
1334 | variable. If | |
1335 | .SM | |
1336 | .B IFS | |
d166f048 JA |
1337 | is unset, the parameters are separated by spaces. |
1338 | If | |
1339 | .SM | |
1340 | .B IFS | |
1341 | is null, the parameters are joined without intervening separators. | |
726f6388 JA |
1342 | .TP |
1343 | .B @ | |
1344 | Expands to the positional parameters, starting from one. When the | |
cce855bc JA |
1345 | expansion occurs within double quotes, each parameter expands to a |
1346 | separate word. That is, "\fB$@\fP" is equivalent to | |
1347 | "\fB$1\fP" "\fB$2\fP" ... | |
be7d8f2d CR |
1348 | If the double-quoted expansion occurs within a word, the expansion of |
1349 | the first parameter is joined with the beginning part of the original | |
1350 | word, and the expansion of the last parameter is joined with the last | |
1351 | part of the original word. | |
fc527055 | 1352 | When there are no positional parameters, "\fB$@\fP" and |
726f6388 JA |
1353 | .B $@ |
1354 | expand to nothing (i.e., they are removed). | |
1355 | .TP | |
1356 | .B # | |
1357 | Expands to the number of positional parameters in decimal. | |
1358 | .TP | |
1359 | .B ? | |
e882163b | 1360 | Expands to the exit status of the most recently executed foreground |
726f6388 JA |
1361 | pipeline. |
1362 | .TP | |
1363 | .B \- | |
1364 | Expands to the current option flags as specified upon invocation, | |
1365 | by the | |
1366 | .B set | |
1367 | builtin command, or those set by the shell itself | |
1368 | (such as the | |
1369 | .B \-i | |
cce855bc | 1370 | option). |
726f6388 JA |
1371 | .TP |
1372 | .B $ | |
1373 | Expands to the process ID of the shell. In a () subshell, it | |
1374 | expands to the process ID of the current shell, not the | |
1375 | subshell. | |
1376 | .TP | |
1377 | .B ! | |
adbaf2b3 CR |
1378 | Expands to the process ID of the job most recently placed into the |
1379 | background, whether executed as an asynchronous command or using | |
1380 | the \fBbg\fP builtin (see | |
1381 | .SM | |
1382 | .B "JOB CONTROL" | |
1383 | below). | |
726f6388 JA |
1384 | .TP |
1385 | .B 0 | |
1386 | Expands to the name of the shell or shell script. This is set at | |
1387 | shell initialization. If | |
1388 | .B bash | |
1389 | is invoked with a file of commands, | |
1390 | .B $0 | |
1391 | is set to the name of that file. If | |
1392 | .B bash | |
1393 | is started with the | |
1394 | .B \-c | |
1395 | option, then | |
1396 | .B $0 | |
1397 | is set to the first argument after the string to be | |
1398 | executed, if one is present. Otherwise, it is set | |
b28ff8c9 | 1399 | to the filename used to invoke |
726f6388 JA |
1400 | .BR bash , |
1401 | as given by argument zero. | |
1402 | .TP | |
1403 | .B _ | |
cc87ba64 CR |
1404 | At shell startup, set to the absolute pathname used to invoke the |
1405 | shell or shell script being executed as passed in the environment | |
1406 | or argument list. | |
ccc6cda3 JA |
1407 | Subsequently, expands to the last argument to the previous command, |
1408 | after expansion. | |
cc87ba64 CR |
1409 | Also set to the full pathname used to invoke each command executed |
1410 | and placed in the environment exported to that command. | |
ccc6cda3 JA |
1411 | When checking mail, this parameter holds the name of the mail file |
1412 | currently being checked. | |
726f6388 JA |
1413 | .PD |
1414 | .SS Shell Variables | |
1415 | .PP | |
1416 | The following variables are set by the shell: | |
1417 | .PP | |
1418 | .PD 0 | |
1419 | .TP | |
726f6388 | 1420 | .B BASH |
b28ff8c9 | 1421 | Expands to the full filename used to invoke this instance of |
726f6388 JA |
1422 | .BR bash . |
1423 | .TP | |
691aebcb CR |
1424 | .B BASHOPTS |
1425 | A colon-separated list of enabled shell options. Each word in | |
1426 | the list is a valid argument for the | |
1427 | .B \-s | |
1428 | option to the | |
1429 | .B shopt | |
1430 | builtin command (see | |
1431 | .SM | |
1432 | .B "SHELL BUILTIN COMMANDS" | |
1433 | below). The options appearing in | |
1434 | .SM | |
1435 | .B BASHOPTS | |
1436 | are those reported as | |
1437 | .I on | |
1438 | by \fBshopt\fP. | |
1439 | If this variable is in the environment when | |
1440 | .B bash | |
1441 | starts up, each shell option in the list will be enabled before | |
1442 | reading any startup files. | |
1443 | This variable is read-only. | |
1444 | .TP | |
d3ad40de | 1445 | .B BASHPID |
dc60d4e0 | 1446 | Expands to the process ID of the current \fBbash\fP process. |
d3ad40de | 1447 | This differs from \fB$$\fP under certain circumstances, such as subshells |
29d25b54 | 1448 | that do not require \fBbash\fP to be re-initialized. |
d3ad40de | 1449 | .TP |
fdf670ea CR |
1450 | .B BASH_ALIASES |
1451 | An associative array variable whose members correspond to the internal | |
5cdaaf76 | 1452 | list of aliases as maintained by the \fBalias\fP builtin. |
fdf670ea CR |
1453 | Elements added to this array appear in the alias list; unsetting array |
1454 | elements cause aliases to be removed from the alias list. | |
1455 | .TP | |
d3a24ed2 CR |
1456 | .B BASH_ARGC |
1457 | An array variable whose values are the number of parameters in each | |
29d25b54 | 1458 | frame of the current \fBbash\fP execution call stack. |
2206f89a | 1459 | The number of |
d3a24ed2 | 1460 | parameters to the current subroutine (shell function or script executed |
2206f89a CR |
1461 | with \fB.\fP or \fBsource\fP) is at the top of the stack. |
1462 | When a subroutine is executed, the number of parameters passed is pushed onto | |
984a1947 CR |
1463 | .SM |
1464 | .BR BASH_ARGC . | |
1465 | The shell sets | |
1466 | .SM | |
1467 | .B BASH_ARGC | |
1468 | only when in extended debugging mode (see the description of the | |
2206f89a CR |
1469 | .B extdebug |
1470 | option to the | |
1471 | .B shopt | |
1472 | builtin below) | |
d3a24ed2 CR |
1473 | .TP |
1474 | .B BASH_ARGV | |
29d25b54 | 1475 | An array variable containing all of the parameters in the current \fBbash\fP |
d3a24ed2 CR |
1476 | execution call stack. The final parameter of the last subroutine call |
1477 | is at the top of the stack; the first parameter of the initial call is | |
1478 | at the bottom. When a subroutine is executed, the parameters supplied | |
984a1947 CR |
1479 | are pushed onto |
1480 | .SM | |
1481 | .BR BASH_ARGV . | |
1482 | The shell sets | |
1483 | .SM | |
1484 | .B BASH_ARGV | |
1485 | only when in extended debugging mode | |
2206f89a CR |
1486 | (see the description of the |
1487 | .B extdebug | |
1488 | option to the | |
1489 | .B shopt | |
1490 | builtin below) | |
d3a24ed2 | 1491 | .TP |
fdf670ea CR |
1492 | .B BASH_CMDS |
1493 | An associative array variable whose members correspond to the internal | |
1494 | hash table of commands as maintained by the \fBhash\fP builtin. | |
1495 | Elements added to this array appear in the hash table; unsetting array | |
1496 | elements cause commands to be removed from the hash table. | |
1497 | .TP | |
d3a24ed2 CR |
1498 | .B BASH_COMMAND |
1499 | The command currently being executed or about to be executed, unless the | |
1500 | shell is executing a command as the result of a trap, | |
1501 | in which case it is the command executing at the time of the trap. | |
1502 | .TP | |
1503 | .B BASH_EXECUTION_STRING | |
1504 | The command argument to the \fB\-c\fP invocation option. | |
1505 | .TP | |
1506 | .B BASH_LINENO | |
1507 | An array variable whose members are the line numbers in source files | |
7d92f73f | 1508 | where each corresponding member of |
984a1947 | 1509 | .SM |
7d92f73f CR |
1510 | .B FUNCNAME |
1511 | was invoked. | |
d3a24ed2 | 1512 | \fB${BASH_LINENO[\fP\fI$i\fP\fB]}\fP is the line number in the source |
7d92f73f CR |
1513 | file (\fB${BASH_SOURCE[\fP\fI$i+1\fP\fB]}\fP) where |
1514 | \fB${FUNCNAME[\fP\fI$i\fP\fB]}\fP was called | |
3d4e09aa CR |
1515 | (or \fB${BASH_LINENO[\fP\fI$i-1\fP\fB]}\fP if referenced within another |
1516 | shell function). | |
984a1947 CR |
1517 | Use |
1518 | .SM | |
1519 | .B LINENO | |
1520 | to obtain the current line number. | |
d3a24ed2 CR |
1521 | .TP |
1522 | .B BASH_REMATCH | |
1523 | An array variable whose members are assigned by the \fB=~\fP binary | |
1524 | operator to the \fB[[\fP conditional command. | |
1525 | The element with index 0 is the portion of the string | |
1526 | matching the entire regular expression. | |
1527 | The element with index \fIn\fP is the portion of the | |
1528 | string matching the \fIn\fPth parenthesized subexpression. | |
1529 | This variable is read-only. | |
1530 | .TP | |
1531 | .B BASH_SOURCE | |
7d92f73f CR |
1532 | An array variable whose members are the source filenames |
1533 | where the corresponding shell function names in the | |
984a1947 CR |
1534 | .SM |
1535 | .B FUNCNAME | |
7d92f73f CR |
1536 | array variable are defined. |
1537 | The shell function | |
1538 | \fB${FUNCNAME[\fP\fI$i\fP\fB]}\fP is defined in the file | |
1539 | \fB${BASH_SOURCE[\fP\fI$i\fP\fB]}\fP and called from | |
1540 | \fB${BASH_SOURCE[\fP\fI$i+1\fP\fB]}\fP. | |
d3a24ed2 CR |
1541 | .TP |
1542 | .B BASH_SUBSHELL | |
c1854f2d CR |
1543 | Incremented by one within each subshell or subshell environment when |
1544 | the shell begins executing in that environment. | |
d3a24ed2 CR |
1545 | The initial value is 0. |
1546 | .TP | |
ccc6cda3 | 1547 | .B BASH_VERSINFO |
cce855bc JA |
1548 | A readonly array variable whose members hold version information for |
1549 | this instance of | |
ccc6cda3 JA |
1550 | .BR bash . |
1551 | The values assigned to the array members are as follows: | |
1552 | .sp .5 | |
1553 | .RS | |
ccc6cda3 JA |
1554 | .TP 24 |
1555 | .B BASH_VERSINFO[\fR0\fP] | |
1556 | The major version number (the \fIrelease\fP). | |
1557 | .TP | |
1558 | .B BASH_VERSINFO[\fR1\fP] | |
1559 | The minor version number (the \fIversion\fP). | |
1560 | .TP | |
1561 | .B BASH_VERSINFO[\fR2\fP] | |
1562 | The patch level. | |
1563 | .TP | |
1564 | .B BASH_VERSINFO[\fR3\fP] | |
1565 | The build version. | |
1566 | .TP | |
1567 | .B BASH_VERSINFO[\fR4\fP] | |
1568 | The release status (e.g., \fIbeta1\fP). | |
1569 | .TP | |
1570 | .B BASH_VERSINFO[\fR5\fP] | |
984a1947 CR |
1571 | The value of |
1572 | .SM | |
1573 | .BR MACHTYPE . | |
ccc6cda3 JA |
1574 | .RE |
1575 | .TP | |
f73dda09 JA |
1576 | .B BASH_VERSION |
1577 | Expands to a string describing the version of this instance of | |
1578 | .BR bash . | |
726f6388 | 1579 | .TP |
f73dda09 JA |
1580 | .B COMP_CWORD |
1581 | An index into \fB${COMP_WORDS}\fP of the word containing the current | |
1582 | cursor position. | |
1583 | This variable is available only in shell functions invoked by the | |
1584 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1585 | below). | |
1586 | .TP | |
d3ad40de CR |
1587 | .B COMP_KEY |
1588 | The key (or final key of a key sequence) used to invoke the current | |
1589 | completion function. | |
1590 | .TP | |
f73dda09 JA |
1591 | .B COMP_LINE |
1592 | The current command line. | |
1593 | This variable is available only in shell functions and external | |
1594 | commands invoked by the | |
1595 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1596 | below). | |
1597 | .TP | |
1598 | .B COMP_POINT | |
1599 | The index of the current cursor position relative to the beginning of | |
1600 | the current command. | |
1601 | If the current cursor position is at the end of the current command, | |
1602 | the value of this variable is equal to \fB${#COMP_LINE}\fP. | |
1603 | This variable is available only in shell functions and external | |
1604 | commands invoked by the | |
1605 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1606 | below). | |
1607 | .TP | |
d3ad40de CR |
1608 | .B COMP_TYPE |
1609 | Set to an integer value corresponding to the type of completion attempted | |
1610 | that caused a completion function to be called: | |
1611 | \fITAB\fP, for normal completion, | |
1612 | \fI?\fP, for listing completions after successive tabs, | |
1613 | \fI!\fP, for listing alternatives on partial word completion, | |
1614 | \fI@\fP, to list completions if the word is not unmodified, | |
1615 | or | |
1616 | \fI%\fP, for menu completion. | |
1617 | This variable is available only in shell functions and external | |
1618 | commands invoked by the | |
1619 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1620 | below). | |
1621 | .TP | |
d3a24ed2 | 1622 | .B COMP_WORDBREAKS |
db31fb26 | 1623 | The set of characters that the \fBreadline\fP library treats as word |
d3a24ed2 CR |
1624 | separators when performing word completion. |
1625 | If | |
1626 | .SM | |
1627 | .B COMP_WORDBREAKS | |
1628 | is unset, it loses its special properties, even if it is | |
1629 | subsequently reset. | |
1630 | .TP | |
f73dda09 JA |
1631 | .B COMP_WORDS |
1632 | An array variable (see \fBArrays\fP below) consisting of the individual | |
1633 | words in the current command line. | |
db31fb26 | 1634 | The line is split into words as \fBreadline\fP would split it, using |
984a1947 CR |
1635 | .SM |
1636 | .B COMP_WORDBREAKS | |
1637 | as described above. | |
f73dda09 JA |
1638 | This variable is available only in shell functions invoked by the |
1639 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1640 | below). | |
1641 | .TP | |
5cdaaf76 CR |
1642 | .B COPROC |
1643 | An array variable (see \fBArrays\fP below) created to hold the file descriptors | |
1644 | for output from and input to an unnamed coprocess (see \fBCoprocesses\fP | |
1645 | above). | |
1646 | .TP | |
f73dda09 JA |
1647 | .B DIRSTACK |
1648 | An array variable (see | |
1649 | .B Arrays | |
1650 | below) containing the current contents of the directory stack. | |
1651 | Directories appear in the stack in the order they are displayed by the | |
1652 | .B dirs | |
1653 | builtin. | |
1654 | Assigning to members of this array variable may be used to modify | |
1655 | directories already in the stack, but the | |
1656 | .B pushd | |
1657 | and | |
1658 | .B popd | |
1659 | builtins must be used to add and remove directories. | |
1660 | Assignment to this variable will not change the current directory. | |
726f6388 JA |
1661 | If |
1662 | .SM | |
f73dda09 | 1663 | .B DIRSTACK |
726f6388 JA |
1664 | is unset, it loses its special properties, even if it is |
1665 | subsequently reset. | |
1666 | .TP | |
f73dda09 JA |
1667 | .B EUID |
1668 | Expands to the effective user ID of the current user, initialized at | |
1669 | shell startup. This variable is readonly. | |
1670 | .TP | |
1671 | .B FUNCNAME | |
d3a24ed2 CR |
1672 | An array variable containing the names of all shell functions |
1673 | currently in the execution call stack. | |
1674 | The element with index 0 is the name of any currently-executing | |
1675 | shell function. | |
7d92f73f | 1676 | The bottom-most element (the one with the highest index) is |
d3ad40de CR |
1677 | .if t \f(CW"main"\fP. |
1678 | .if n "main". | |
f73dda09 JA |
1679 | This variable exists only when a shell function is executing. |
1680 | Assignments to | |
726f6388 | 1681 | .SM |
f73dda09 JA |
1682 | .B FUNCNAME |
1683 | have no effect and return an error status. | |
726f6388 JA |
1684 | If |
1685 | .SM | |
f73dda09 | 1686 | .B FUNCNAME |
726f6388 JA |
1687 | is unset, it loses its special properties, even if it is |
1688 | subsequently reset. | |
7d92f73f CR |
1689 | .if t .sp 0.5 |
1690 | .if n .sp 1 | |
1691 | This variable can be used with \fBBASH_LINENO\fP and \fBBASH_SOURCE\fP. | |
1692 | Each element of \fBFUNCNAME\fP has corresponding elements in | |
1693 | \fBBASH_LINENO\fP and \fBBASH_SOURCE\fP to describe the call stack. | |
1694 | For instance, \fB${FUNCNAME[\fP\fI$i\fP\fB]}\fP was called from the file | |
1695 | \fB${BASH_SOURCE[\fP\fI$i+1\fP\fB]}\fP at line number | |
1696 | \fB${BASH_LINENO[\fP\fI$i\fP\fB]}\fP. | |
1697 | The \fBcaller\fP builtin displays the current call stack using this | |
1698 | information. | |
726f6388 | 1699 | .TP |
f73dda09 JA |
1700 | .B GROUPS |
1701 | An array variable containing the list of groups of which the current | |
1702 | user is a member. | |
fc527055 | 1703 | Assignments to |
f73dda09 JA |
1704 | .SM |
1705 | .B GROUPS | |
1706 | have no effect and return an error status. | |
726f6388 JA |
1707 | If |
1708 | .SM | |
f73dda09 | 1709 | .B GROUPS |
726f6388 JA |
1710 | is unset, it loses its special properties, even if it is |
1711 | subsequently reset. | |
1712 | .TP | |
1713 | .B HISTCMD | |
1714 | The history number, or index in the history list, of the current | |
ccc6cda3 JA |
1715 | command. |
1716 | If | |
726f6388 JA |
1717 | .SM |
1718 | .B HISTCMD | |
1719 | is unset, it loses its special properties, even if it is | |
1720 | subsequently reset. | |
1721 | .TP | |
f73dda09 JA |
1722 | .B HOSTNAME |
1723 | Automatically set to the name of the current host. | |
bb70624e | 1724 | .TP |
f73dda09 JA |
1725 | .B HOSTTYPE |
1726 | Automatically set to a string that uniquely | |
1727 | describes the type of machine on which | |
1728 | .B bash | |
1729 | is executing. | |
1730 | The default is system-dependent. | |
1731 | .TP | |
1732 | .B LINENO | |
1733 | Each time this parameter is referenced, the shell substitutes | |
1734 | a decimal number representing the current sequential line number | |
1735 | (starting with 1) within a script or function. When not in a | |
1736 | script or function, the value substituted is not guaranteed to | |
1737 | be meaningful. | |
ccc6cda3 JA |
1738 | If |
1739 | .SM | |
f73dda09 | 1740 | .B LINENO |
ccc6cda3 JA |
1741 | is unset, it loses its special properties, even if it is |
1742 | subsequently reset. | |
1743 | .TP | |
f73dda09 JA |
1744 | .B MACHTYPE |
1745 | Automatically set to a string that fully describes the system | |
1746 | type on which | |
1747 | .B bash | |
1748 | is executing, in the standard GNU \fIcpu-company-system\fP format. | |
1749 | The default is system-dependent. | |
1750 | .TP | |
5cdaaf76 CR |
1751 | .B MAPFILE |
1752 | An array variable (see \fBArrays\fP below) created to hold the text | |
1753 | read by the \fBmapfile\fP builtin when no variable name is supplied. | |
1754 | .TP | |
f73dda09 JA |
1755 | .B OLDPWD |
1756 | The previous working directory as set by the | |
1757 | .B cd | |
1758 | command. | |
ccc6cda3 | 1759 | .TP |
726f6388 JA |
1760 | .B OPTARG |
1761 | The value of the last option argument processed by the | |
1762 | .B getopts | |
1763 | builtin command (see | |
1764 | .SM | |
1765 | .B SHELL BUILTIN COMMANDS | |
1766 | below). | |
1767 | .TP | |
1768 | .B OPTIND | |
1769 | The index of the next argument to be processed by the | |
1770 | .B getopts | |
1771 | builtin command (see | |
1772 | .SM | |
1773 | .B SHELL BUILTIN COMMANDS | |
1774 | below). | |
1775 | .TP | |
726f6388 JA |
1776 | .B OSTYPE |
1777 | Automatically set to a string that | |
1778 | describes the operating system on which | |
1779 | .B bash | |
ccc6cda3 JA |
1780 | is executing. |
1781 | The default is system-dependent. | |
1782 | .TP | |
f73dda09 JA |
1783 | .B PIPESTATUS |
1784 | An array variable (see | |
1785 | .B Arrays | |
1786 | below) containing a list of exit status values from the processes | |
1787 | in the most-recently-executed foreground pipeline (which may | |
1788 | contain only a single command). | |
ccc6cda3 | 1789 | .TP |
f73dda09 JA |
1790 | .B PPID |
1791 | The process ID of the shell's parent. This variable is readonly. | |
1792 | .TP | |
1793 | .B PWD | |
1794 | The current working directory as set by the | |
1795 | .B cd | |
1796 | command. | |
1797 | .TP | |
1798 | .B RANDOM | |
1799 | Each time this parameter is referenced, a random integer between | |
1800 | 0 and 32767 is | |
1801 | generated. The sequence of random numbers may be initialized by assigning | |
1802 | a value to | |
1803 | .SM | |
1804 | .BR RANDOM . | |
1805 | If | |
1806 | .SM | |
1807 | .B RANDOM | |
1808 | is unset, it loses its special properties, even if it is | |
1809 | subsequently reset. | |
1810 | .TP | |
5cdaaf76 CR |
1811 | .B READLINE_LINE |
1812 | The contents of the | |
1813 | .B readline | |
1814 | line buffer, for use with | |
1815 | .if t \f(CWbind -x\fP | |
1816 | .if n "bind -x" | |
1817 | (see | |
1818 | .SM | |
1819 | .B "SHELL BUILTIN COMMANDS" | |
1820 | below). | |
1821 | .TP | |
1822 | .B READLINE_POINT | |
1823 | The position of the insertion point in the | |
1824 | .B readline | |
1825 | line buffer, for use with | |
1826 | .if t \f(CWbind -x\fP | |
1827 | .if n "bind -x" | |
1828 | (see | |
1829 | .SM | |
1830 | .B "SHELL BUILTIN COMMANDS" | |
1831 | below). | |
1832 | .TP | |
f73dda09 JA |
1833 | .B REPLY |
1834 | Set to the line of input read by the | |
1835 | .B read | |
1836 | builtin command when no arguments are supplied. | |
1837 | .TP | |
1838 | .B SECONDS | |
1839 | Each time this parameter is | |
1840 | referenced, the number of seconds since shell invocation is returned. If a | |
fc527055 | 1841 | value is assigned to |
f73dda09 JA |
1842 | .SM |
1843 | .BR SECONDS , | |
1844 | the value returned upon subsequent | |
1845 | references is | |
1846 | the number of seconds since the assignment plus the value assigned. | |
1847 | If | |
1848 | .SM | |
1849 | .B SECONDS | |
1850 | is unset, it loses its special properties, even if it is | |
1851 | subsequently reset. | |
1852 | .TP | |
1853 | .B SHELLOPTS | |
1854 | A colon-separated list of enabled shell options. Each word in | |
1855 | the list is a valid argument for the | |
1856 | .B \-o | |
1857 | option to the | |
1858 | .B set | |
1859 | builtin command (see | |
1860 | .SM | |
1861 | .B "SHELL BUILTIN COMMANDS" | |
1862 | below). The options appearing in | |
ccc6cda3 JA |
1863 | .SM |
1864 | .B SHELLOPTS | |
1865 | are those reported as | |
1866 | .I on | |
1867 | by \fBset \-o\fP. | |
1868 | If this variable is in the environment when | |
1869 | .B bash | |
1870 | starts up, each shell option in the list will be enabled before | |
1871 | reading any startup files. | |
1872 | This variable is read-only. | |
bb70624e | 1873 | .TP |
f73dda09 JA |
1874 | .B SHLVL |
1875 | Incremented by one each time an instance of | |
1876 | .B bash | |
1877 | is started. | |
bb70624e | 1878 | .TP |
f73dda09 JA |
1879 | .B UID |
1880 | Expands to the user ID of the current user, initialized at shell startup. | |
1881 | This variable is readonly. | |
726f6388 JA |
1882 | .PD |
1883 | .PP | |
1884 | The following variables are used by the shell. In some cases, | |
1885 | .B bash | |
1886 | assigns a default value to a variable; these cases are noted | |
1887 | below. | |
1888 | .PP | |
1889 | .PD 0 | |
1890 | .TP | |
7175a77f CR |
1891 | .B BASH_COMPAT |
1892 | The value is used to set the shell's compatibility level. | |
c2fa6583 CR |
1893 | See the description of the \fBshopt\fP builtin below under |
1894 | \fBSHELL BUILTIN COMMANDS\fP | |
1895 | for a description of the various compatibility | |
7175a77f CR |
1896 | levels and their effects. |
1897 | The value may be a decimal number (e.g., 4.2) or an integer (e.g., 42) | |
1898 | corresponding to the desired compatibility level. | |
1899 | If \fBBASH_COMPAT\fP is unset or set to the empty string, the compatibility | |
1900 | level is set to the default for the current version. | |
1901 | If \fBBASH_COMPAT\fP is set to a value that is not one of the valid | |
1902 | compatibility levels, the shell prints an error message and sets the | |
1903 | compatibility level to the default for the current version. | |
1904 | The valid compatibility levels correspond to the compatibility options | |
1905 | accepted by the \fBshopt\fP builtin described below (for example, | |
1906 | \fBcompat42\fP means that 4.2 and 42 are valid values). | |
1907 | The current version is also a valid value. | |
1908 | .TP | |
d166f048 | 1909 | .B BASH_ENV |
726f6388 JA |
1910 | If this parameter is set when \fBbash\fP is executing a shell script, |
1911 | its value is interpreted as a filename containing commands to | |
1912 | initialize the shell, as in | |
cce855bc | 1913 | .IR ~/.bashrc . |
726f6388 JA |
1914 | The value of |
1915 | .SM | |
d166f048 | 1916 | .B BASH_ENV |
726f6388 | 1917 | is subjected to parameter expansion, command substitution, and arithmetic |
b28ff8c9 | 1918 | expansion before being interpreted as a filename. |
726f6388 JA |
1919 | .SM |
1920 | .B PATH | |
b28ff8c9 | 1921 | is not used to search for the resultant filename. |
726f6388 | 1922 | .TP |
8f714a7c CR |
1923 | .B BASH_XTRACEFD |
1924 | If set to an integer corresponding to a valid file descriptor, \fBbash\fP | |
1925 | will write the trace output generated when | |
1926 | .if t \f(CWset -x\fP | |
1927 | .if n \fIset -x\fP | |
1928 | is enabled to that file descriptor. | |
984a1947 CR |
1929 | The file descriptor is closed when |
1930 | .SM | |
1931 | .B BASH_XTRACEFD | |
1932 | is unset or assigned a new value. | |
1933 | Unsetting | |
1934 | .SM | |
1935 | .B BASH_XTRACEFD | |
1936 | or assigning it the empty string causes the | |
8f714a7c | 1937 | trace output to be sent to the standard error. |
984a1947 CR |
1938 | Note that setting |
1939 | .SM | |
1940 | .B BASH_XTRACEFD | |
1941 | to 2 (the standard error file | |
8f714a7c CR |
1942 | descriptor) and then unsetting it will result in the standard error |
1943 | being closed. | |
1944 | .TP | |
5cdaaf76 CR |
1945 | .B CDPATH |
1946 | The search path for the | |
1947 | .B cd | |
1948 | command. | |
1949 | This is a colon-separated list of directories in which the shell looks | |
1950 | for destination directories specified by the | |
1951 | .B cd | |
1952 | command. | |
1953 | A sample value is | |
1954 | .if t \f(CW".:~:/usr"\fP. | |
1955 | .if n ".:~:/usr". | |
1956 | .TP | |
a7ad477f CR |
1957 | .B CHILD_MAX |
1958 | Set the number of exited child status values for the shell to remember. | |
c677e9e0 | 1959 | Bash will not allow this value to be decreased below a POSIX-mandated |
a7ad477f CR |
1960 | minimum, and there is a maximum value (currently 8192) that this may |
1961 | not exceed. | |
1962 | The minimum value is system-dependent. | |
1963 | .TP | |
f73dda09 | 1964 | .B COLUMNS |
54a1fa7c | 1965 | Used by the \fBselect\fP compound command to determine the terminal width |
ad4aef08 CR |
1966 | when printing selection lists. |
1967 | Automatically set if the | |
1968 | .B checkwinsize | |
1969 | option is enabled or in an interactive shell upon receipt of a | |
9c7f20c7 CR |
1970 | .SM |
1971 | .BR SIGWINCH . | |
726f6388 | 1972 | .TP |
f73dda09 JA |
1973 | .B COMPREPLY |
1974 | An array variable from which \fBbash\fP reads the possible completions | |
1975 | generated by a shell function invoked by the programmable completion | |
1976 | facility (see \fBProgrammable Completion\fP below). | |
ba4ab055 | 1977 | Each array element contains one possible completion. |
726f6388 | 1978 | .TP |
d3a24ed2 CR |
1979 | .B EMACS |
1980 | If \fBbash\fP finds this variable in the environment when the shell starts | |
1981 | with value | |
1982 | .if t \f(CWt\fP, | |
1983 | .if n "t", | |
5f8cde23 | 1984 | it assumes that the shell is running in an Emacs shell buffer and disables |
d3a24ed2 CR |
1985 | line editing. |
1986 | .TP | |
5cdaaf76 CR |
1987 | .B ENV |
1988 | Similar to | |
1989 | .SM | |
1990 | .BR BASH_ENV ; | |
1991 | used when the shell is invoked in POSIX mode. | |
1992 | .TP | |
f73dda09 JA |
1993 | .B FCEDIT |
1994 | The default editor for the | |
1995 | .B fc | |
1996 | builtin command. | |
726f6388 | 1997 | .TP |
f73dda09 JA |
1998 | .B FIGNORE |
1999 | A colon-separated list of suffixes to ignore when performing | |
2000 | filename completion (see | |
726f6388 | 2001 | .SM |
f73dda09 JA |
2002 | .B READLINE |
2003 | below). | |
2004 | A filename whose suffix matches one of the entries in | |
726f6388 | 2005 | .SM |
f73dda09 JA |
2006 | .B FIGNORE |
2007 | is excluded from the list of matched filenames. | |
7117c2d2 JA |
2008 | A sample value is |
2009 | .if t \f(CW".o:~"\fP. | |
2010 | .if n ".o:~". | |
ccc6cda3 | 2011 | .TP |
6faad625 CR |
2012 | .B FUNCNEST |
2013 | If set to a numeric value greater than 0, defines a maximum function | |
2014 | nesting level. Function invocations that exceed this nesting level | |
2015 | will cause the current command to abort. | |
2016 | .TP | |
f73dda09 JA |
2017 | .B GLOBIGNORE |
2018 | A colon-separated list of patterns defining the set of filenames to | |
2019 | be ignored by pathname expansion. | |
2020 | If a filename matched by a pathname expansion pattern also matches one | |
2021 | of the patterns in | |
726f6388 | 2022 | .SM |
f73dda09 JA |
2023 | .BR GLOBIGNORE , |
2024 | it is removed from the list of matches. | |
2025 | .TP | |
2026 | .B HISTCONTROL | |
d3a24ed2 CR |
2027 | A colon-separated list of values controlling how commands are saved on |
2028 | the history list. | |
2029 | If the list of values includes | |
f73dda09 JA |
2030 | .IR ignorespace , |
2031 | lines which begin with a | |
2032 | .B space | |
d3a24ed2 | 2033 | character are not saved in the history list. |
fc527055 | 2034 | A value of |
d3a24ed2 CR |
2035 | .I ignoredups |
2036 | causes lines matching the previous history entry to not be saved. | |
f73dda09 JA |
2037 | A value of |
2038 | .I ignoreboth | |
d3a24ed2 CR |
2039 | is shorthand for \fIignorespace\fP and \fIignoredups\fP. |
2040 | A value of | |
2041 | .IR erasedups | |
2042 | causes all previous lines matching the current line to be removed from | |
2043 | the history list before that line is saved. | |
2044 | Any value not in the above list is ignored. | |
984a1947 CR |
2045 | If |
2046 | .SM | |
2047 | .B HISTCONTROL | |
2048 | is unset, or does not include a valid value, | |
d3a24ed2 CR |
2049 | all lines read by the shell parser are saved on the history list, |
2050 | subject to the value of | |
984a1947 | 2051 | .SM |
f73dda09 JA |
2052 | .BR HISTIGNORE . |
2053 | The second and subsequent lines of a multi-line compound command are | |
2054 | not tested, and are added to the history regardless of the value of | |
984a1947 | 2055 | .SM |
f73dda09 | 2056 | .BR HISTCONTROL . |
726f6388 JA |
2057 | .TP |
2058 | .B HISTFILE | |
ccc6cda3 | 2059 | The name of the file in which command history is saved (see |
726f6388 JA |
2060 | .SM |
2061 | .B HISTORY | |
ccc6cda3 | 2062 | below). The default value is \fI~/.bash_history\fP. If unset, the |
ed3f3b6c | 2063 | command history is not saved when a shell exits. |
726f6388 JA |
2064 | .TP |
2065 | .B HISTFILESIZE | |
2066 | The maximum number of lines contained in the history file. When this | |
2067 | variable is assigned a value, the history file is truncated, if | |
4b82d1cd CR |
2068 | necessary, |
2069 | to contain no more than that number of lines by removing the oldest entries. | |
2070 | The history file is also truncated to this size after | |
ed3f3b6c | 2071 | writing it when a shell exits. |
4b82d1cd | 2072 | If the value is 0, the history file is truncated to zero size. |
e67d0029 | 2073 | Non-numeric values and numeric values less than zero inhibit truncation. |
4b82d1cd CR |
2074 | The shell sets the default value to the value of \fBHISTSIZE\fP |
2075 | after reading any startup files. | |
726f6388 | 2076 | .TP |
f73dda09 JA |
2077 | .B HISTIGNORE |
2078 | A colon-separated list of patterns used to decide which command lines | |
2079 | should be saved on the history list. Each pattern is anchored at the | |
2080 | beginning of the line and must match the complete line (no implicit | |
2081 | `\fB*\fP' is appended). Each pattern is tested against the line | |
2082 | after the checks specified by | |
984a1947 | 2083 | .SM |
f73dda09 JA |
2084 | .B HISTCONTROL |
2085 | are applied. | |
2086 | In addition to the normal shell pattern matching characters, `\fB&\fP' | |
2087 | matches the previous history line. `\fB&\fP' may be escaped using a | |
2088 | backslash; the backslash is removed before attempting a match. | |
2089 | The second and subsequent lines of a multi-line compound command are | |
2090 | not tested, and are added to the history regardless of the value of | |
984a1947 | 2091 | .SM |
f73dda09 JA |
2092 | .BR HISTIGNORE . |
2093 | .TP | |
2094 | .B HISTSIZE | |
2095 | The number of commands to remember in the command history (see | |
2096 | .SM | |
2097 | .B HISTORY | |
4b82d1cd CR |
2098 | below). |
2099 | If the value is 0, commands are not saved in the history list. | |
2100 | Numeric values less than zero result in every command being saved | |
2101 | on the history list (there is no limit). | |
2102 | The shell sets the default value to 500 after reading any startup files. | |
f73dda09 | 2103 | .TP |
d3a24ed2 CR |
2104 | .B HISTTIMEFORMAT |
2105 | If this variable is set and not null, its value is used as a format string | |
2106 | for \fIstrftime\fP(3) to print the time stamp associated with each history | |
2107 | entry displayed by the \fBhistory\fP builtin. | |
2108 | If this variable is set, time stamps are written to the history file so | |
2109 | they may be preserved across shell sessions. | |
d3ad40de CR |
2110 | This uses the history comment character to distinguish timestamps from |
2111 | other history lines. | |
d3a24ed2 | 2112 | .TP |
f73dda09 JA |
2113 | .B HOME |
2114 | The home directory of the current user; the default argument for the | |
2115 | \fBcd\fP builtin command. | |
2116 | The value of this variable is also used when performing tilde expansion. | |
2117 | .TP | |
2118 | .B HOSTFILE | |
2119 | Contains the name of a file in the same format as | |
2120 | .FN /etc/hosts | |
2121 | that should be read when the shell needs to complete a | |
2122 | hostname. | |
2123 | The list of possible hostname completions may be changed while the | |
2124 | shell is running; | |
2125 | the next time hostname completion is attempted after the | |
2126 | value is changed, | |
726f6388 | 2127 | .B bash |
f73dda09 JA |
2128 | adds the contents of the new file to the existing list. |
2129 | If | |
726f6388 | 2130 | .SM |
f73dda09 | 2131 | .B HOSTFILE |
9dd88db7 CR |
2132 | is set, but has no value, or does not name a readable file, |
2133 | \fBbash\fP attempts to read | |
f73dda09 JA |
2134 | .FN /etc/hosts |
2135 | to obtain the list of possible hostname completions. | |
2136 | When | |
726f6388 | 2137 | .SM |
f73dda09 JA |
2138 | .B HOSTFILE |
2139 | is unset, the hostname list is cleared. | |
2140 | .TP | |
2141 | .B IFS | |
2142 | The | |
2143 | .I Internal Field Separator | |
2144 | that is used | |
2145 | for word splitting after expansion and to | |
2146 | split lines into words with the | |
2147 | .B read | |
2148 | builtin command. The default value is | |
2149 | ``<space><tab><newline>''. | |
2150 | .TP | |
2151 | .B IGNOREEOF | |
2152 | Controls the | |
2153 | action of an interactive shell on receipt of an | |
2154 | .SM | |
2155 | .B EOF | |
2156 | character as the sole input. If set, the value is the number of | |
2157 | consecutive | |
2158 | .SM | |
2159 | .B EOF | |
2160 | characters which must be | |
2161 | typed as the first characters on an input line before | |
2162 | .B bash | |
2163 | exits. If the variable exists but does not have a numeric value, or | |
2164 | has no value, the default value is 10. If it does not exist, | |
2165 | .SM | |
2166 | .B EOF | |
2167 | signifies the end of input to the shell. | |
2168 | .TP | |
2169 | .B INPUTRC | |
2170 | The filename for the | |
2171 | .B readline | |
2172 | startup file, overriding the default of | |
2173 | .FN ~/.inputrc | |
2174 | (see | |
2175 | .SM | |
2176 | .B READLINE | |
2177 | below). | |
726f6388 | 2178 | .TP |
ccc6cda3 JA |
2179 | .B LANG |
2180 | Used to determine the locale category for any category not specifically | |
2181 | selected with a variable starting with \fBLC_\fP. | |
2182 | .TP | |
2183 | .B LC_ALL | |
984a1947 CR |
2184 | This variable overrides the value of |
2185 | .SM | |
2186 | .B LANG | |
2187 | and any other | |
ccc6cda3 JA |
2188 | \fBLC_\fP variable specifying a locale category. |
2189 | .TP | |
2190 | .B LC_COLLATE | |
2191 | This variable determines the collation order used when sorting the | |
cce855bc JA |
2192 | results of pathname expansion, and determines the behavior of range |
2193 | expressions, equivalence classes, and collating sequences within | |
2194 | pathname expansion and pattern matching. | |
2195 | .TP | |
2196 | .B LC_CTYPE | |
2197 | This variable determines the interpretation of characters and the | |
2198 | behavior of character classes within pathname expansion and pattern | |
2199 | matching. | |
ccc6cda3 JA |
2200 | .TP |
2201 | .B LC_MESSAGES | |
2202 | This variable determines the locale used to translate double-quoted | |
2203 | strings preceded by a \fB$\fP. | |
2204 | .TP | |
bb70624e JA |
2205 | .B LC_NUMERIC |
2206 | This variable determines the locale category used for number formatting. | |
2207 | .TP | |
28ef6c31 | 2208 | .B LINES |
54a1fa7c | 2209 | Used by the \fBselect\fP compound command to determine the column length |
ad4aef08 CR |
2210 | for printing selection lists. |
2211 | Automatically set if the | |
2212 | .B checkwinsize | |
2213 | option is enabled or in an interactive shell upon receipt of a | |
984a1947 CR |
2214 | .SM |
2215 | .BR SIGWINCH . | |
28ef6c31 | 2216 | .TP |
f73dda09 | 2217 | .B MAIL |
9ec5ed66 | 2218 | If this parameter is set to a file or directory name and the |
726f6388 | 2219 | .SM |
f73dda09 JA |
2220 | .B MAILPATH |
2221 | variable is not set, | |
726f6388 | 2222 | .B bash |
9ec5ed66 CR |
2223 | informs the user of the arrival of mail in the specified file or |
2224 | Maildir-format directory. | |
726f6388 | 2225 | .TP |
f73dda09 JA |
2226 | .B MAILCHECK |
2227 | Specifies how | |
2228 | often (in seconds) | |
2229 | .B bash | |
2230 | checks for mail. The default is 60 seconds. When it is time to check | |
2231 | for mail, the shell does so before displaying the primary prompt. | |
2232 | If this variable is unset, or set to a value that is not a number | |
2233 | greater than or equal to zero, the shell disables mail checking. | |
726f6388 | 2234 | .TP |
f73dda09 | 2235 | .B MAILPATH |
fc527055 | 2236 | A colon-separated list of filenames to be checked for mail. |
f73dda09 | 2237 | The message to be printed when mail arrives in a particular file |
b28ff8c9 | 2238 | may be specified by separating the filename from the message with a `?'. |
f73dda09 | 2239 | When used in the text of the message, \fB$_\fP expands to the name of |
fc527055 | 2240 | the current mailfile. |
f73dda09 JA |
2241 | Example: |
2242 | .RS | |
2243 | .PP | |
20587658 | 2244 | \fBMAILPATH\fP=\(aq/var/mail/bfox?"You have mail":~/shell\-mail?"$_ has mail!"\(aq |
f73dda09 JA |
2245 | .PP |
2246 | .B Bash | |
2247 | supplies a default value for this variable, but the location of the user | |
2248 | mail files that it uses is system dependent (e.g., /var/mail/\fB$USER\fP). | |
2249 | .RE | |
726f6388 | 2250 | .TP |
f73dda09 JA |
2251 | .B OPTERR |
2252 | If set to the value 1, | |
2253 | .B bash | |
2254 | displays error messages generated by the | |
2255 | .B getopts | |
2256 | builtin command (see | |
726f6388 | 2257 | .SM |
f73dda09 | 2258 | .B SHELL BUILTIN COMMANDS |
ccc6cda3 | 2259 | below). |
726f6388 | 2260 | .SM |
f73dda09 JA |
2261 | .B OPTERR |
2262 | is initialized to 1 each time the shell is invoked or a shell | |
2263 | script is executed. | |
ccc6cda3 | 2264 | .TP |
f73dda09 JA |
2265 | .B PATH |
2266 | The search path for commands. It | |
2267 | is a colon-separated list of directories in which | |
2268 | the shell looks for commands (see | |
ccc6cda3 | 2269 | .SM |
f73dda09 | 2270 | .B COMMAND EXECUTION |
d3a24ed2 | 2271 | below). |
984a1947 CR |
2272 | A zero-length (null) directory name in the value of |
2273 | .SM | |
2274 | .B PATH | |
2275 | indicates the current directory. | |
d3a24ed2 CR |
2276 | A null directory name may appear as two adjacent colons, or as an initial |
2277 | or trailing colon. | |
2278 | The default path is system-dependent, | |
f73dda09 JA |
2279 | and is set by the administrator who installs |
2280 | .BR bash . | |
2281 | A common value is | |
f6da9f85 CR |
2282 | .if t \f(CW/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin\fP. |
2283 | .if n ``/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin''. | |
726f6388 | 2284 | .TP |
f73dda09 JA |
2285 | .B POSIXLY_CORRECT |
2286 | If this variable is in the environment when \fBbash\fP starts, the shell | |
2287 | enters \fIposix mode\fP before reading the startup files, as if the | |
2288 | .B \-\-posix | |
2289 | invocation option had been supplied. If it is set while the shell is | |
2290 | running, \fBbash\fP enables \fIposix mode\fP, as if the command | |
2291 | .if t \f(CWset -o posix\fP | |
2292 | .if n \fIset -o posix\fP | |
2293 | had been executed. | |
726f6388 | 2294 | .TP |
f73dda09 JA |
2295 | .B PROMPT_COMMAND |
2296 | If set, the value is executed as a command prior to issuing each primary | |
2297 | prompt. | |
ccc6cda3 | 2298 | .TP |
ed35cb4a CR |
2299 | .B PROMPT_DIRTRIM |
2300 | If set to a number greater than zero, the value is used as the number of | |
d0ca3503 | 2301 | trailing directory components to retain when expanding the \fB\ew\fP and |
ed35cb4a CR |
2302 | \fB\eW\fP prompt string escapes (see |
2303 | .SM | |
2304 | .B PROMPTING | |
2305 | below). Characters removed are replaced with an ellipsis. | |
2306 | .TP | |
f73dda09 JA |
2307 | .B PS1 |
2308 | The value of this parameter is expanded (see | |
2309 | .SM | |
2310 | .B PROMPTING | |
2311 | below) and used as the primary prompt string. The default value is | |
2312 | ``\fB\es\-\ev\e$ \fP''. | |
726f6388 | 2313 | .TP |
f73dda09 JA |
2314 | .B PS2 |
2315 | The value of this parameter is expanded as with | |
984a1947 | 2316 | .SM |
f73dda09 JA |
2317 | .B PS1 |
2318 | and used as the secondary prompt string. The default is | |
2319 | ``\fB> \fP''. | |
2320 | .TP | |
2321 | .B PS3 | |
2322 | The value of this parameter is used as the prompt for the | |
2323 | .B select | |
2324 | command (see | |
726f6388 | 2325 | .SM |
f73dda09 JA |
2326 | .B SHELL GRAMMAR |
2327 | above). | |
726f6388 | 2328 | .TP |
f73dda09 JA |
2329 | .B PS4 |
2330 | The value of this parameter is expanded as with | |
984a1947 | 2331 | .SM |
f73dda09 JA |
2332 | .B PS1 |
2333 | and the value is printed before each command | |
726f6388 | 2334 | .B bash |
f73dda09 | 2335 | displays during an execution trace. The first character of |
bb70624e | 2336 | .SM |
f73dda09 JA |
2337 | .B PS4 |
2338 | is replicated multiple times, as necessary, to indicate multiple | |
2339 | levels of indirection. The default is ``\fB+ \fP''. | |
2340 | .TP | |
61deeb13 CR |
2341 | .B SHELL |
2342 | The full pathname to the shell is kept in this environment variable. | |
2343 | If it is not set when the shell starts, | |
2344 | .B bash | |
2345 | assigns to it the full pathname of the current user's login shell. | |
2346 | .TP | |
f73dda09 JA |
2347 | .B TIMEFORMAT |
2348 | The value of this parameter is used as a format string specifying | |
2349 | how the timing information for pipelines prefixed with the | |
2350 | .B time | |
2351 | reserved word should be displayed. | |
2352 | The \fB%\fP character introduces an escape sequence that is | |
2353 | expanded to a time value or other information. | |
2354 | The escape sequences and their meanings are as follows; the | |
2355 | braces denote optional portions. | |
2356 | .sp .5 | |
2357 | .RS | |
2358 | .PD 0 | |
2359 | .TP 10 | |
2360 | .B %% | |
2361 | A literal \fB%\fP. | |
2362 | .TP | |
2363 | .B %[\fIp\fP][l]R | |
2364 | The elapsed time in seconds. | |
2365 | .TP | |
2366 | .B %[\fIp\fP][l]U | |
2367 | The number of CPU seconds spent in user mode. | |
2368 | .TP | |
2369 | .B %[\fIp\fP][l]S | |
2370 | The number of CPU seconds spent in system mode. | |
2371 | .TP | |
2372 | .B %P | |
2373 | The CPU percentage, computed as (%U + %S) / %R. | |
2374 | .PD | |
2375 | .RE | |
2376 | .IP | |
2377 | The optional \fIp\fP is a digit specifying the \fIprecision\fP, | |
2378 | the number of fractional digits after a decimal point. | |
2379 | A value of 0 causes no decimal point or fraction to be output. | |
2380 | At most three places after the decimal point may be specified; | |
2381 | values of \fIp\fP greater than 3 are changed to 3. | |
2382 | If \fIp\fP is not specified, the value 3 is used. | |
2383 | .IP | |
2384 | The optional \fBl\fP specifies a longer format, including | |
2385 | minutes, of the form \fIMM\fPm\fISS\fP.\fIFF\fPs. | |
2386 | The value of \fIp\fP determines whether or not the fraction is | |
2387 | included. | |
2388 | .IP | |
2389 | If this variable is not set, \fBbash\fP acts as if it had the | |
d76edd30 | 2390 | value \fB$\(aq\enreal\et%3lR\enuser\et%3lU\ensys\et%3lS\(aq\fP. |
f73dda09 JA |
2391 | If the value is null, no timing information is displayed. |
2392 | A trailing newline is added when the format string is displayed. | |
54a1fa7c | 2393 | .PD 0 |
f73dda09 JA |
2394 | .TP |
2395 | .B TMOUT | |
984a1947 CR |
2396 | If set to a value greater than zero, |
2397 | .SM | |
2398 | .B TMOUT | |
2399 | is treated as the | |
7117c2d2 JA |
2400 | default timeout for the \fBread\fP builtin. |
2401 | The \fBselect\fP command terminates if input does not arrive | |
984a1947 CR |
2402 | after |
2403 | .SM | |
2404 | .B TMOUT | |
2405 | seconds when input is coming from a terminal. | |
7117c2d2 | 2406 | In an interactive shell, the value is interpreted as the |
ed3f3b6c CR |
2407 | number of seconds to wait for a line of input after issuing the |
2408 | primary prompt. | |
f73dda09 | 2409 | .B Bash |
ed3f3b6c CR |
2410 | terminates after waiting for that number of seconds if a complete |
2411 | line of input does not arrive. | |
726f6388 | 2412 | .TP |
1569c106 | 2413 | .B TMPDIR |
5f8cde23 CR |
2414 | If set, \fBbash\fP uses its value as the name of a directory in which |
2415 | \fBbash\fP creates temporary files for the shell's use. | |
1569c106 | 2416 | .TP |
726f6388 JA |
2417 | .B auto_resume |
2418 | This variable controls how the shell interacts with the user and | |
2419 | job control. If this variable is set, single word simple | |
2420 | commands without redirections are treated as candidates for resumption | |
2421 | of an existing stopped job. There is no ambiguity allowed; if there is | |
2422 | more than one job beginning with the string typed, the job most recently | |
2423 | accessed is selected. The | |
2424 | .I name | |
2425 | of a stopped job, in this context, is the command line used to | |
2426 | start it. | |
2427 | If set to the value | |
2428 | .IR exact , | |
2429 | the string supplied must match the name of a stopped job exactly; | |
2430 | if set to | |
2431 | .IR substring , | |
2432 | the string supplied needs to match a substring of the name of a | |
2433 | stopped job. The | |
2434 | .I substring | |
2435 | value provides functionality analogous to the | |
2436 | .B %? | |
ccc6cda3 | 2437 | job identifier (see |
726f6388 JA |
2438 | .SM |
2439 | .B JOB CONTROL | |
2440 | below). If set to any other value, the supplied string must | |
2441 | be a prefix of a stopped job's name; this provides functionality | |
22e63b05 | 2442 | analogous to the \fB%\fP\fIstring\fP job identifier. |
bb70624e | 2443 | .TP |
f73dda09 JA |
2444 | .B histchars |
2445 | The two or three characters which control history expansion | |
2446 | and tokenization (see | |
2447 | .SM | |
2448 | .B HISTORY EXPANSION | |
2449 | below). The first character is the \fIhistory expansion\fP character, | |
2450 | the character which signals the start of a history | |
2451 | expansion, normally `\fB!\fP'. | |
2452 | The second character is the \fIquick substitution\fP | |
2453 | character, which is used as shorthand for re-running the previous | |
2454 | command entered, substituting one string for another in the command. | |
2455 | The default is `\fB^\fP'. | |
2456 | The optional third character is the character | |
2457 | which indicates that the remainder of the line is a comment when found | |
2458 | as the first character of a word, normally `\fB#\fP'. The history | |
2459 | comment character causes history substitution to be skipped for the | |
2460 | remaining words on the line. It does not necessarily cause the shell | |
2461 | parser to treat the rest of the line as a comment. | |
726f6388 | 2462 | .PD |
ccc6cda3 JA |
2463 | .SS Arrays |
2464 | .B Bash | |
fdf670ea | 2465 | provides one-dimensional indexed and associative array variables. |
09767ff0 | 2466 | Any variable may be used as an indexed array; the |
ccc6cda3 | 2467 | .B declare |
fdf670ea CR |
2468 | builtin will explicitly declare an array. |
2469 | There is no maximum | |
ccc6cda3 | 2470 | limit on the size of an array, nor any requirement that members |
fdf670ea CR |
2471 | be indexed or assigned contiguously. |
2472 | Indexed arrays are referenced using integers (including arithmetic | |
fc527055 | 2473 | expressions) and are zero-based; associative arrays are referenced |
09767ff0 | 2474 | using arbitrary strings. |
861a1900 | 2475 | Unless otherwise noted, indexed array indices must be non-negative integers. |
ccc6cda3 | 2476 | .PP |
fdf670ea CR |
2477 | An indexed array is created automatically if any variable is assigned to |
2478 | using the syntax \fIname\fP[\fIsubscript\fP]=\fIvalue\fP. The | |
ccc6cda3 | 2479 | .I subscript |
67362c60 | 2480 | is treated as an arithmetic expression that must evaluate to a number. |
67362c60 | 2481 | To explicitly declare an indexed array, use |
ccc6cda3 JA |
2482 | .B declare \-a \fIname\fP |
2483 | (see | |
2484 | .SM | |
2485 | .B SHELL BUILTIN COMMANDS | |
2486 | below). | |
2487 | .B declare \-a \fIname\fP[\fIsubscript\fP] | |
09767ff0 CR |
2488 | is also accepted; the \fIsubscript\fP is ignored. |
2489 | .PP | |
2490 | Associative arrays are created using | |
2491 | .BR "declare \-A \fIname\fP" . | |
2492 | .PP | |
2493 | Attributes may be | |
ccc6cda3 JA |
2494 | specified for an array variable using the |
2495 | .B declare | |
2496 | and | |
2497 | .B readonly | |
2498 | builtins. Each attribute applies to all members of an array. | |
2499 | .PP | |
2500 | Arrays are assigned to using compound assignments of the form | |
2501 | \fIname\fP=\fB(\fPvalue\fI1\fP ... value\fIn\fP\fB)\fP, where each | |
09767ff0 | 2502 | \fIvalue\fP is of the form [\fIsubscript\fP]=\fIstring\fP. |
b28ff8c9 | 2503 | Indexed array assignments do not require anything but \fIstring\fP. |
09767ff0 CR |
2504 | When assigning to indexed arrays, if the optional brackets and subscript |
2505 | are supplied, that index is assigned to; | |
ccc6cda3 JA |
2506 | otherwise the index of the element assigned is the last index assigned |
2507 | to by the statement plus one. Indexing starts at zero. | |
fdf670ea CR |
2508 | .PP |
2509 | When assigning to an associative array, the subscript is required. | |
2510 | .PP | |
ccc6cda3 JA |
2511 | This syntax is also accepted by the |
2512 | .B declare | |
2513 | builtin. Individual array elements may be assigned to using the | |
2514 | \fIname\fP[\fIsubscript\fP]=\fIvalue\fP syntax introduced above. | |
a7ad477f CR |
2515 | When assigning to an indexed array, if |
2516 | .I name | |
2517 | is subscripted by a negative number, that number is | |
2518 | interpreted as relative to one greater than the maximum index of | |
2519 | \fIname\fP, so negative indices count back from the end of the | |
2520 | array, and an index of \-1 references the last element. | |
ccc6cda3 JA |
2521 | .PP |
2522 | Any element of an array may be referenced using | |
2523 | ${\fIname\fP[\fIsubscript\fP]}. The braces are required to avoid | |
2524 | conflicts with pathname expansion. If | |
2525 | \fIsubscript\fP is \fB@\fP or \fB*\fP, the word expands to | |
2526 | all members of \fIname\fP. These subscripts differ only when the | |
2527 | word appears within double quotes. If the word is double-quoted, | |
2528 | ${\fIname\fP[*]} expands to a single | |
2529 | word with the value of each array member separated by the first | |
2530 | character of the | |
2531 | .SM | |
2532 | .B IFS | |
2533 | special variable, and ${\fIname\fP[@]} expands each element of | |
2534 | \fIname\fP to a separate word. When there are no array members, | |
be7d8f2d CR |
2535 | ${\fIname\fP[@]} expands to nothing. |
2536 | If the double-quoted expansion occurs within a word, the expansion of | |
2537 | the first parameter is joined with the beginning part of the original | |
2538 | word, and the expansion of the last parameter is joined with the last | |
2539 | part of the original word. | |
2540 | This is analogous to the expansion | |
ccc6cda3 JA |
2541 | of the special parameters \fB*\fP and \fB@\fP (see |
2542 | .B Special Parameters | |
2543 | above). ${#\fIname\fP[\fIsubscript\fP]} expands to the length of | |
2544 | ${\fIname\fP[\fIsubscript\fP]}. If \fIsubscript\fP is \fB*\fP or | |
2545 | \fB@\fP, the expansion is the number of elements in the array. | |
d9e1f41e CR |
2546 | If the |
2547 | .I subscript | |
2548 | used to reference an element of an indexed array | |
fc527055 | 2549 | evaluates to a number less than zero, it is |
a7ad477f CR |
2550 | interpreted as relative to one greater than the maximum index of the array, |
2551 | so negative indices count back from the end of the | |
2552 | array, and an index of \-1 references the last element. | |
ccc6cda3 | 2553 | .PP |
09f70f2f CR |
2554 | Referencing an array variable without a subscript is equivalent to |
2555 | referencing the array with a subscript of 0. | |
2556 | Any reference to a variable using a valid subscript is legal, and | |
2557 | .B bash | |
2558 | will create an array if necessary. | |
2559 | .PP | |
94a5513e CR |
2560 | An array variable is considered set if a subscript has been assigned a |
2561 | value. The null string is a valid value. | |
2562 | .PP | |
c2fa6583 CR |
2563 | It is possible to obtain the keys (indices) of an array as well as the values. |
2564 | ${\fB!\fP\fIname\fP[\fI@\fP]} and ${\fB!\fP\fIname\fP[\fI*\fP]} | |
2565 | expand to the indices assigned in array variable \fIname\fP. | |
2566 | The treatment when in double quotes is similar to the expansion of the | |
2567 | special parameters \fI@\fP and \fI*\fP within double quotes. | |
2568 | .PP | |
ccc6cda3 JA |
2569 | The |
2570 | .B unset | |
bb70624e | 2571 | builtin is used to destroy arrays. \fBunset\fP \fIname\fP[\fIsubscript\fP] |
ccc6cda3 | 2572 | destroys the array element at index \fIsubscript\fP. |
a7ad477f | 2573 | Negative subscripts to indexed arrays are interpreted as described above. |
d0ca3503 CR |
2574 | Care must be taken to avoid unwanted side effects caused by pathname |
2575 | expansion. | |
ccc6cda3 JA |
2576 | \fBunset\fP \fIname\fP, where \fIname\fP is an array, or |
2577 | \fBunset\fP \fIname\fP[\fIsubscript\fP], where | |
2578 | \fIsubscript\fP is \fB*\fP or \fB@\fP, removes the entire array. | |
2579 | .PP | |
2580 | The | |
2581 | .BR declare , | |
2582 | .BR local , | |
2583 | and | |
2584 | .B readonly | |
2585 | builtins each accept a | |
2586 | .B \-a | |
fdf670ea CR |
2587 | option to specify an indexed array and a |
2588 | .B \-A | |
2589 | option to specify an associative array. | |
fc527055 | 2590 | If both options are supplied, |
54a1fa7c CR |
2591 | .B \-A |
2592 | takes precedence. | |
fdf670ea | 2593 | The |
ccc6cda3 JA |
2594 | .B read |
2595 | builtin accepts a | |
2596 | .B \-a | |
2597 | option to assign a list of words read from the standard input | |
2598 | to an array. The | |
2599 | .B set | |
2600 | and | |
2601 | .B declare | |
2602 | builtins display array values in a way that allows them to be | |
2603 | reused as assignments. | |
726f6388 JA |
2604 | .SH EXPANSION |
2605 | Expansion is performed on the command line after it has been split into | |
2606 | words. There are seven kinds of expansion performed: | |
2607 | .IR "brace expansion" , | |
2608 | .IR "tilde expansion" , | |
2609 | .IR "parameter and variable expansion" , | |
2610 | .IR "command substitution" , | |
2611 | .IR "arithmetic expansion" , | |
2612 | .IR "word splitting" , | |
2613 | and | |
2614 | .IR "pathname expansion" . | |
2615 | .PP | |
39feef01 CR |
2616 | The order of expansions is: |
2617 | brace expansion; | |
2618 | tilde expansion, parameter and variable expansion, arithmetic expansion, | |
2619 | and command substitution (done in a left-to-right fashion); | |
2620 | word splitting; | |
2621 | and pathname expansion. | |
726f6388 JA |
2622 | .PP |
2623 | On systems that can support it, there is an additional expansion | |
2624 | available: \fIprocess substitution\fP. | |
39feef01 CR |
2625 | This is performed at the |
2626 | same time as tilde, parameter, variable, and arithmetic expansion and | |
2627 | command substitution. | |
726f6388 JA |
2628 | .PP |
2629 | Only brace expansion, word splitting, and pathname expansion | |
2630 | can change the number of words of the expansion; other expansions | |
2631 | expand a single word to a single word. | |
ccc6cda3 | 2632 | The only exceptions to this are the expansions of |
cce855bc | 2633 | "\fB$@\fP" and "\fB${\fP\fIname\fP\fB[@]}\fP" |
ccc6cda3 | 2634 | as explained above (see |
726f6388 JA |
2635 | .SM |
2636 | .BR PARAMETERS ). | |
2637 | .SS Brace Expansion | |
2638 | .PP | |
2639 | .I "Brace expansion" | |
2640 | is a mechanism by which arbitrary strings | |
2641 | may be generated. This mechanism is similar to | |
2642 | \fIpathname expansion\fP, but the filenames generated | |
2643 | need not exist. Patterns to be brace expanded take | |
2644 | the form of an optional | |
2645 | .IR preamble , | |
d3a24ed2 CR |
2646 | followed by either a series of comma-separated strings or |
2647 | a sequence expression between a pair of braces, followed by | |
2648 | an optional | |
cce855bc | 2649 | .IR postscript . |
ccc6cda3 | 2650 | The preamble is prefixed to each string contained |
cce855bc | 2651 | within the braces, and the postscript is then appended |
726f6388 JA |
2652 | to each resulting string, expanding left to right. |
2653 | .PP | |
2654 | Brace expansions may be nested. The results of each expanded | |
2655 | string are not sorted; left to right order is preserved. | |
2656 | For example, a\fB{\fPd,c,b\fB}\fPe expands into `ade ace abe'. | |
2657 | .PP | |
8943768b | 2658 | A sequence expression takes the form |
36211029 | 2659 | \fB{\fP\fIx\fP\fB..\fP\fIy\fP\fB[..\fP\fIincr\fP\fB]}\fP, |
8943768b CR |
2660 | where \fIx\fP and \fIy\fP are either integers or single characters, |
2661 | and \fIincr\fP, an optional increment, is an integer. | |
d3a24ed2 CR |
2662 | When integers are supplied, the expression expands to each number between |
2663 | \fIx\fP and \fIy\fP, inclusive. | |
8943768b | 2664 | Supplied integers may be prefixed with \fI0\fP to force each term to have the |
47b599dc CR |
2665 | same width. |
2666 | When either \fIx\fP or \fPy\fP begins with a zero, the shell | |
8943768b CR |
2667 | attempts to force all generated terms to contain the same number of digits, |
2668 | zero-padding where necessary. | |
d3a24ed2 | 2669 | When characters are supplied, the expression expands to each character |
47b599dc CR |
2670 | lexicographically between \fIx\fP and \fIy\fP, inclusive, |
2671 | using the default C locale. | |
2672 | Note that both \fIx\fP and \fIy\fP must be of the same type. | |
8943768b CR |
2673 | When the increment is supplied, it is used as the difference between |
2674 | each term. The default increment is 1 or -1 as appropriate. | |
d3a24ed2 | 2675 | .PP |
726f6388 JA |
2676 | Brace expansion is performed before any other expansions, |
2677 | and any characters special to other expansions are preserved | |
2678 | in the result. It is strictly textual. | |
2679 | .B Bash | |
2680 | does not apply any syntactic interpretation to the context of the | |
2681 | expansion or the text between the braces. | |
2682 | .PP | |
2683 | A correctly-formed brace expansion must contain unquoted opening | |
d3a24ed2 CR |
2684 | and closing braces, and at least one unquoted comma or a valid |
2685 | sequence expression. | |
726f6388 | 2686 | Any incorrectly formed brace expansion is left unchanged. |
ccc6cda3 JA |
2687 | A \fB{\fP or \fB,\fP may be quoted with a backslash to prevent its |
2688 | being considered part of a brace expression. | |
bb70624e JA |
2689 | To avoid conflicts with parameter expansion, the string \fB${\fP |
2690 | is not considered eligible for brace expansion. | |
726f6388 JA |
2691 | .PP |
2692 | This construct is typically used as shorthand when the common | |
2693 | prefix of the strings to be generated is longer than in the | |
2694 | above example: | |
2695 | .RS | |
2696 | .PP | |
2697 | mkdir /usr/local/src/bash/{old,new,dist,bugs} | |
2698 | .RE | |
2699 | or | |
2700 | .RS | |
2701 | chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}} | |
2702 | .RE | |
2703 | .PP | |
2704 | Brace expansion introduces a slight incompatibility with | |
ccc6cda3 JA |
2705 | historical versions of |
2706 | .BR sh . | |
726f6388 JA |
2707 | .B sh |
2708 | does not treat opening or closing braces specially when they | |
2709 | appear as part of a word, and preserves them in the output. | |
2710 | .B Bash | |
2711 | removes braces from words as a consequence of brace | |
2712 | expansion. For example, a word entered to | |
2713 | .B sh | |
2714 | as \fIfile{1,2}\fP | |
2715 | appears identically in the output. The same word is | |
2716 | output as | |
2717 | .I file1 file2 | |
2718 | after expansion by | |
2719 | .BR bash . | |
2720 | If strict compatibility with | |
2721 | .B sh | |
2722 | is desired, start | |
2723 | .B bash | |
2724 | with the | |
fc527055 | 2725 | .B +B |
ccc6cda3 JA |
2726 | option or disable brace expansion with the |
2727 | .B +B | |
726f6388 JA |
2728 | option to the |
2729 | .B set | |
2730 | command (see | |
2731 | .SM | |
2732 | .B SHELL BUILTIN COMMANDS | |
2733 | below). | |
2734 | .SS Tilde Expansion | |
2735 | .PP | |
cce855bc JA |
2736 | If a word begins with an unquoted tilde character (`\fB~\fP'), all of |
2737 | the characters preceding the first unquoted slash (or all characters, | |
2738 | if there is no unquoted slash) are considered a \fItilde-prefix\fP. | |
2739 | If none of the characters in the tilde-prefix are quoted, the | |
2740 | characters in the tilde-prefix following the tilde are treated as a | |
2741 | possible \fIlogin name\fP. | |
2742 | If this login name is the null string, the tilde is replaced with the | |
2743 | value of the shell parameter | |
726f6388 JA |
2744 | .SM |
2745 | .BR HOME . | |
2746 | If | |
2747 | .SM | |
2748 | .B HOME | |
cce855bc JA |
2749 | is unset, the home directory of the user executing the shell is |
2750 | substituted instead. | |
2751 | Otherwise, the tilde-prefix is replaced with the home directory | |
2752 | associated with the specified login name. | |
726f6388 | 2753 | .PP |
cce855bc | 2754 | If the tilde-prefix is a `~+', the value of the shell variable |
726f6388 JA |
2755 | .SM |
2756 | .B PWD | |
cce855bc JA |
2757 | replaces the tilde-prefix. |
2758 | If the tilde-prefix is a `~\-', the value of the shell variable | |
2759 | .SM | |
2760 | .BR OLDPWD , | |
2761 | if it is set, is substituted. | |
2762 | If the characters following the tilde in the tilde-prefix consist | |
2763 | of a number \fIN\fP, optionally prefixed | |
2764 | by a `+' or a `\-', the tilde-prefix is replaced with the corresponding | |
2765 | element from the directory stack, as it would be displayed by the | |
2766 | .B dirs | |
2767 | builtin invoked with the tilde-prefix as an argument. | |
2768 | If the characters following the tilde in the tilde-prefix consist of a | |
2769 | number without a leading `+' or `\-', `+' is assumed. | |
2770 | .PP | |
2771 | If the login name is invalid, or the tilde expansion fails, the word | |
2772 | is unchanged. | |
726f6388 | 2773 | .PP |
cce855bc JA |
2774 | Each variable assignment is checked for unquoted tilde-prefixes immediately |
2775 | following a | |
726f6388 | 2776 | .B : |
43df7bbb | 2777 | or the first |
726f6388 | 2778 | .BR = . |
cce855bc | 2779 | In these cases, tilde expansion is also performed. |
b28ff8c9 | 2780 | Consequently, one may use filenames with tildes in assignments to |
726f6388 JA |
2781 | .SM |
2782 | .BR PATH , | |
2783 | .SM | |
2784 | .BR MAILPATH , | |
2785 | and | |
2786 | .SM | |
2787 | .BR CDPATH , | |
2788 | and the shell assigns the expanded value. | |
2789 | .SS Parameter Expansion | |
2790 | .PP | |
2791 | The `\fB$\fP' character introduces parameter expansion, | |
2792 | command substitution, or arithmetic expansion. The parameter name | |
2793 | or symbol to be expanded may be enclosed in braces, which | |
2794 | are optional but serve to protect the variable to be expanded from | |
2795 | characters immediately following it which could be | |
2796 | interpreted as part of the name. | |
2797 | .PP | |
cce855bc JA |
2798 | When braces are used, the matching ending brace is the first `\fB}\fP' |
2799 | not escaped by a backslash or within a quoted string, and not within an | |
f75912ae | 2800 | embedded arithmetic expansion, command substitution, or parameter |
cce855bc JA |
2801 | expansion. |
2802 | .PP | |
726f6388 JA |
2803 | .PD 0 |
2804 | .TP | |
2805 | ${\fIparameter\fP} | |
2806 | The value of \fIparameter\fP is substituted. The braces are required | |
2807 | when | |
2808 | .I parameter | |
2809 | is a positional parameter with more than one digit, | |
2810 | or when | |
2811 | .I parameter | |
2812 | is followed by a character which is not to be | |
2813 | interpreted as part of its name. | |
348a457e CR |
2814 | The \fIparameter\fP is a shell parameter as described above |
2815 | \fBPARAMETERS\fP) or an array reference (\fBArrays\fP). | |
726f6388 JA |
2816 | .PD |
2817 | .PP | |
08e72d7a | 2818 | If the first character of \fIparameter\fP is an exclamation point (\fB!\fP), |
5e37553a | 2819 | and \fIparameter\fP is not a \fInameref\fP, |
348a457e | 2820 | it introduces a level of variable indirection. |
ccc6cda3 JA |
2821 | \fBBash\fP uses the value of the variable formed from the rest of |
2822 | \fIparameter\fP as the name of the variable; this variable is then | |
bb70624e | 2823 | expanded and that value is used in the rest of the substitution, rather |
ccc6cda3 JA |
2824 | than the value of \fIparameter\fP itself. |
2825 | This is known as \fIindirect expansion\fP. | |
5e37553a CR |
2826 | If \fIparameter\fP is a nameref, this expands to the name of the |
2827 | variable referenced by \fIparameter\fP instead of performing the | |
2828 | complete indirect expansion. | |
54a1fa7c | 2829 | The exceptions to this are the expansions of ${\fB!\fP\fIprefix\fP\fB*\fP} and |
d3a24ed2 CR |
2830 | ${\fB!\fP\fIname\fP[\fI@\fP]} described below. |
2831 | The exclamation point must immediately follow the left brace in order to | |
2832 | introduce indirection. | |
ccc6cda3 | 2833 | .PP |
726f6388 JA |
2834 | In each of the cases below, \fIword\fP is subject to tilde expansion, |
2835 | parameter expansion, command substitution, and arithmetic expansion. | |
e141c35a | 2836 | .PP |
348a457e CR |
2837 | When not performing substring expansion, using the forms documented below |
2838 | (e.g., \fB:-\fP), | |
e141c35a CR |
2839 | \fBbash\fP tests for a parameter that is unset or null. Omitting the colon |
2840 | results in a test only for a parameter that is unset. | |
726f6388 JA |
2841 | .PP |
2842 | .PD 0 | |
2843 | .TP | |
2844 | ${\fIparameter\fP\fB:\-\fP\fIword\fP} | |
2845 | \fBUse Default Values\fP. If | |
2846 | .I parameter | |
2847 | is unset or null, the expansion of | |
2848 | .I word | |
2849 | is substituted. Otherwise, the value of | |
2850 | .I parameter | |
2851 | is substituted. | |
2852 | .TP | |
2853 | ${\fIparameter\fP\fB:=\fP\fIword\fP} | |
2854 | \fBAssign Default Values\fP. | |
2855 | If | |
2856 | .I parameter | |
2857 | is unset or null, the expansion of | |
2858 | .I word | |
2859 | is assigned to | |
2860 | .IR parameter . | |
2861 | The value of | |
2862 | .I parameter | |
2863 | is then substituted. Positional parameters and special parameters may | |
2864 | not be assigned to in this way. | |
2865 | .TP | |
2866 | ${\fIparameter\fP\fB:?\fP\fIword\fP} | |
2867 | \fBDisplay Error if Null or Unset\fP. | |
2868 | If | |
2869 | .I parameter | |
2870 | is null or unset, the expansion of \fIword\fP (or a message to that effect | |
2871 | if | |
2872 | .I word | |
2873 | is not present) is written to the standard error and the shell, if it | |
2874 | is not interactive, exits. Otherwise, the value of \fIparameter\fP is | |
2875 | substituted. | |
2876 | .TP | |
2877 | ${\fIparameter\fP\fB:+\fP\fIword\fP} | |
2878 | \fBUse Alternate Value\fP. | |
2879 | If | |
2880 | .I parameter | |
2881 | is null or unset, nothing is substituted, otherwise the expansion of | |
2882 | .I word | |
2883 | is substituted. | |
2884 | .TP | |
ccc6cda3 | 2885 | ${\fIparameter\fP\fB:\fP\fIoffset\fP} |
7117c2d2 | 2886 | .PD 0 |
ccc6cda3 JA |
2887 | .TP |
2888 | ${\fIparameter\fP\fB:\fP\fIoffset\fP\fB:\fP\fIlength\fP} | |
2889 | .PD | |
dc60d4e0 | 2890 | \fBSubstring Expansion\fP. |
348a457e | 2891 | Expands to up to \fIlength\fP characters of the value of \fIparameter\fP |
bb70624e | 2892 | starting at the character specified by \fIoffset\fP. |
348a457e CR |
2893 | If \fIparameter\fP is \fB@\fP, an indexed array subscripted by |
2894 | \fB@\fP or \fB*\fP, or an associative array name, the results differ as | |
2895 | described below. | |
2896 | If \fIlength\fP is omitted, expands to the substring of the value of | |
2897 | \fIparameter\fP starting at the character specified by \fIoffset\fP | |
2898 | and extending to the end of the value. | |
ccc6cda3 JA |
2899 | \fIlength\fP and \fIoffset\fP are arithmetic expressions (see |
2900 | .SM | |
2901 | .B | |
2902 | ARITHMETIC EVALUATION | |
2903 | below). | |
348a457e | 2904 | .sp 1 |
ccc6cda3 | 2905 | If \fIoffset\fP evaluates to a number less than zero, the value |
348a457e CR |
2906 | is used as an offset in characters |
2907 | from the end of the value of \fIparameter\fP. | |
2908 | If \fIlength\fP evaluates to a number less than zero, | |
2909 | it is interpreted as an offset in characters | |
2910 | from the end of the value of \fIparameter\fP rather than | |
2911 | a number of characters, and the expansion is the characters between | |
2912 | \fIoffset\fP and that result. | |
2913 | Note that a negative offset must be separated from the colon by at least | |
2914 | one space to avoid being confused with the \fB:-\fP expansion. | |
2915 | .sp 1 | |
ccc6cda3 JA |
2916 | If \fIparameter\fP is \fB@\fP, the result is \fIlength\fP positional |
2917 | parameters beginning at \fIoffset\fP. | |
348a457e CR |
2918 | A negative \fIoffset\fP is taken relative to one greater than the greatest |
2919 | positional parameter, so an offset of -1 evaluates to the last positional | |
2920 | parameter. | |
2921 | It is an expansion error if \fIlength\fP evaluates to a number less than | |
2922 | zero. | |
2923 | .sp 1 | |
09767ff0 | 2924 | If \fIparameter\fP is an indexed array name subscripted by @ or *, |
ccc6cda3 JA |
2925 | the result is the \fIlength\fP |
2926 | members of the array beginning with ${\fIparameter\fP[\fIoffset\fP]}. | |
ec2199bd CR |
2927 | A negative \fIoffset\fP is taken relative to one greater than the maximum |
2928 | index of the specified array. | |
348a457e CR |
2929 | It is an expansion error if \fIlength\fP evaluates to a number less than |
2930 | zero. | |
2931 | .sp 1 | |
09767ff0 CR |
2932 | Substring expansion applied to an associative array produces undefined |
2933 | results. | |
348a457e | 2934 | .sp 1 |
fc527055 | 2935 | Substring indexing is zero-based unless the positional parameters |
d3ad40de CR |
2936 | are used, in which case the indexing starts at 1 by default. |
2937 | If \fIoffset\fP is 0, and the positional parameters are used, \fB$0\fP is | |
2938 | prefixed to the list. | |
ccc6cda3 | 2939 | .TP |
bb70624e | 2940 | ${\fB!\fP\fIprefix\fP\fB*\fP} |
d3a24ed2 CR |
2941 | .PD 0 |
2942 | .TP | |
2943 | ${\fB!\fP\fIprefix\fP\fB@\fP} | |
2944 | .PD | |
dc60d4e0 | 2945 | \fBNames matching prefix\fP. |
bb70624e JA |
2946 | Expands to the names of variables whose names begin with \fIprefix\fP, |
2947 | separated by the first character of the | |
2948 | .SM | |
2949 | .B IFS | |
2950 | special variable. | |
d3ad40de CR |
2951 | When \fI@\fP is used and the expansion appears within double quotes, each |
2952 | variable name expands to a separate word. | |
bb70624e | 2953 | .TP |
d3a24ed2 CR |
2954 | ${\fB!\fP\fIname\fP[\fI@\fP]} |
2955 | .PD 0 | |
2956 | .TP | |
2957 | ${\fB!\fP\fIname\fP[\fI*\fP]} | |
2958 | .PD | |
dc60d4e0 | 2959 | \fBList of array keys\fP. |
d3a24ed2 CR |
2960 | If \fIname\fP is an array variable, expands to the list of array indices |
2961 | (keys) assigned in \fIname\fP. | |
2962 | If \fIname\fP is not an array, expands to 0 if \fIname\fP is set and null | |
2963 | otherwise. | |
2964 | When \fI@\fP is used and the expansion appears within double quotes, each | |
2965 | key expands to a separate word. | |
2966 | .TP | |
726f6388 | 2967 | ${\fB#\fP\fIparameter\fP} |
dc60d4e0 | 2968 | \fBParameter length\fP. |
726f6388 | 2969 | The length in characters of the value of \fIparameter\fP is substituted. |
ccc6cda3 JA |
2970 | If |
2971 | .I parameter | |
2972 | is | |
726f6388 | 2973 | .B * |
fc527055 | 2974 | or |
726f6388 | 2975 | .BR @ , |
cce855bc | 2976 | the value substituted is the number of positional parameters. |
ccc6cda3 JA |
2977 | If |
2978 | .I parameter | |
2979 | is an array name subscripted by | |
726f6388 | 2980 | .B * |
ccc6cda3 JA |
2981 | or |
2982 | .BR @ , | |
cce855bc | 2983 | the value substituted is the number of elements in the array. |
a7ad477f CR |
2984 | If |
2985 | .I parameter | |
2986 | is an indexed array name subscripted by a negative number, that number is | |
2987 | interpreted as relative to one greater than the maximum index of | |
2988 | \fIparameter\fP, so negative indices count back from the end of the | |
2989 | array, and an index of \-1 references the last element. | |
726f6388 | 2990 | .TP |
726f6388 | 2991 | ${\fIparameter\fP\fB#\fP\fIword\fP} |
7117c2d2 | 2992 | .PD 0 |
726f6388 JA |
2993 | .TP |
2994 | ${\fIparameter\fP\fB##\fP\fIword\fP} | |
2995 | .PD | |
dc60d4e0 | 2996 | \fBRemove matching prefix pattern\fP. |
fc527055 | 2997 | The |
726f6388 JA |
2998 | .I word |
2999 | is expanded to produce a pattern just as in pathname | |
3000 | expansion. If the pattern matches the beginning of | |
3001 | the value of | |
3002 | .IR parameter , | |
cce855bc | 3003 | then the result of the expansion is the expanded value of |
726f6388 | 3004 | .I parameter |
ccc6cda3 JA |
3005 | with the shortest matching pattern (the ``\fB#\fP'' case) or the |
3006 | longest matching pattern (the ``\fB##\fP'' case) deleted. | |
3007 | If | |
3008 | .I parameter | |
3009 | is | |
3010 | .B @ | |
3011 | or | |
3012 | .BR * , | |
3013 | the pattern removal operation is applied to each positional | |
3014 | parameter in turn, and the expansion is the resultant list. | |
3015 | If | |
3016 | .I parameter | |
3017 | is an array variable subscripted with | |
3018 | .B @ | |
3019 | or | |
3020 | .BR * , | |
3021 | the pattern removal operation is applied to each member of the | |
3022 | array in turn, and the expansion is the resultant list. | |
726f6388 | 3023 | .TP |
726f6388 | 3024 | ${\fIparameter\fP\fB%\fP\fIword\fP} |
7117c2d2 | 3025 | .PD 0 |
726f6388 JA |
3026 | .TP |
3027 | ${\fIparameter\fP\fB%%\fP\fIword\fP} | |
3028 | .PD | |
dc60d4e0 | 3029 | \fBRemove matching suffix pattern\fP. |
726f6388 | 3030 | The \fIword\fP is expanded to produce a pattern just as in |
ccc6cda3 | 3031 | pathname expansion. |
cce855bc | 3032 | If the pattern matches a trailing portion of the expanded value of |
726f6388 | 3033 | .IR parameter , |
cce855bc | 3034 | then the result of the expansion is the expanded value of |
726f6388 | 3035 | .I parameter |
ccc6cda3 JA |
3036 | with the shortest matching pattern (the ``\fB%\fP'' case) or the |
3037 | longest matching pattern (the ``\fB%%\fP'' case) deleted. | |
3038 | If | |
3039 | .I parameter | |
3040 | is | |
3041 | .B @ | |
3042 | or | |
3043 | .BR * , | |
3044 | the pattern removal operation is applied to each positional | |
3045 | parameter in turn, and the expansion is the resultant list. | |
3046 | If | |
3047 | .I parameter | |
3048 | is an array variable subscripted with | |
3049 | .B @ | |
3050 | or | |
3051 | .BR * , | |
3052 | the pattern removal operation is applied to each member of the | |
3053 | array in turn, and the expansion is the resultant list. | |
3054 | .TP | |
ccc6cda3 | 3055 | ${\fIparameter\fP\fB/\fP\fIpattern\fP\fB/\fP\fIstring\fP} |
dc60d4e0 | 3056 | \fBPattern substitution\fP. |
ccc6cda3 JA |
3057 | The \fIpattern\fP is expanded to produce a pattern just as in |
3058 | pathname expansion. | |
3059 | \fIParameter\fP is expanded and the longest match of \fIpattern\fP | |
3060 | against its value is replaced with \fIstring\fP. | |
e6598ba4 | 3061 | If \fIpattern\fP begins with \fB/\fP, all matches of \fIpattern\fP are |
dc8fbaf9 | 3062 | replaced with \fIstring\fP. Normally only the first match is replaced. |
ccc6cda3 | 3063 | If \fIpattern\fP begins with \fB#\fP, it must match at the beginning |
b72432fd | 3064 | of the expanded value of \fIparameter\fP. |
ccc6cda3 | 3065 | If \fIpattern\fP begins with \fB%\fP, it must match at the end |
b72432fd | 3066 | of the expanded value of \fIparameter\fP. |
ccc6cda3 JA |
3067 | If \fIstring\fP is null, matches of \fIpattern\fP are deleted |
3068 | and the \fB/\fP following \fIpattern\fP may be omitted. | |
0a233f3e CR |
3069 | If the |
3070 | .B nocasematch | |
3071 | shell option is enabled, the match is performed without regard to the case | |
3072 | of alphabetic characters. | |
ccc6cda3 JA |
3073 | If |
3074 | .I parameter | |
3075 | is | |
3076 | .B @ | |
3077 | or | |
3078 | .BR * , | |
3079 | the substitution operation is applied to each positional | |
3080 | parameter in turn, and the expansion is the resultant list. | |
3081 | If | |
3082 | .I parameter | |
3083 | is an array variable subscripted with | |
3084 | .B @ | |
3085 | or | |
3086 | .BR * , | |
3087 | the substitution operation is applied to each member of the | |
3088 | array in turn, and the expansion is the resultant list. | |
09767ff0 CR |
3089 | .TP |
3090 | ${\fIparameter\fP\fB^\fP\fIpattern\fP} | |
3091 | .PD 0 | |
3092 | .TP | |
3093 | ${\fIparameter\fP\fB^^\fP\fIpattern\fP} | |
3094 | .TP | |
3095 | ${\fIparameter\fP\fB,\fP\fIpattern\fP} | |
3096 | .TP | |
3097 | ${\fIparameter\fP\fB,,\fP\fIpattern\fP} | |
3098 | .PD | |
dc60d4e0 | 3099 | \fBCase modification\fP. |
09767ff0 CR |
3100 | This expansion modifies the case of alphabetic characters in \fIparameter\fP. |
3101 | The \fIpattern\fP is expanded to produce a pattern just as in | |
3102 | pathname expansion. | |
45c0f7f8 CR |
3103 | Each character in the expanded value of \fIparameter\fP is tested against |
3104 | \fIpattern\fP, and, if it matches the pattern, its case is converted. | |
3105 | The pattern should not attempt to match more than one character. | |
09767ff0 CR |
3106 | The \fB^\fP operator converts lowercase letters matching \fIpattern\fP |
3107 | to uppercase; the \fB,\fP operator converts matching uppercase letters | |
3108 | to lowercase. | |
3109 | The \fB^^\fP and \fB,,\fP expansions convert each matched character in the | |
3110 | expanded value; the \fB^\fP and \fB,\fP expansions match and convert only | |
5cdaaf76 | 3111 | the first character in the expanded value. |
09767ff0 CR |
3112 | If \fIpattern\fP is omitted, it is treated like a \fB?\fP, which matches |
3113 | every character. | |
3114 | If | |
3115 | .I parameter | |
3116 | is | |
3117 | .B @ | |
3118 | or | |
3119 | .BR * , | |
3120 | the case modification operation is applied to each positional | |
3121 | parameter in turn, and the expansion is the resultant list. | |
3122 | If | |
3123 | .I parameter | |
3124 | is an array variable subscripted with | |
3125 | .B @ | |
3126 | or | |
3127 | .BR * , | |
3128 | the case modification operation is applied to each member of the | |
3129 | array in turn, and the expansion is the resultant list. | |
09f70f2f CR |
3130 | .TP |
3131 | ${\fIparameter\fP\fB@\fP\fIoperator\fP} | |
3132 | \fBParameter transformation\fP. | |
3133 | The expansion is either a transformation of the value of \fIparameter\fP | |
3134 | or information about \fIparameter\fP itself, depending on the value of | |
3135 | \fIoperator\fP. Each \fIoperator\fP is a single letter: | |
3136 | .sp 1 | |
3137 | .RS | |
3138 | .PD 0 | |
3139 | .TP | |
3140 | .B Q | |
3141 | The expansion is a string that is the value of \fIparameter\fP quoted in a | |
3142 | format that can be reused as input. | |
3143 | .TP | |
3144 | .B E | |
3145 | The expansion is a string that is the value of \fIparameter\fP with backslash | |
3146 | escape sequences expanded as with the \fB$'...'\fP quoting mechansim. | |
3147 | .TP | |
3148 | .B P | |
3149 | The expansion is a string that is the result of expanding the value of | |
3150 | \fIparameter\fP as if it were a prompt string (see \fBPROMPTING\fP below). | |
3151 | .TP | |
3152 | .B A | |
3153 | The expansion is a string in the form of a \fBdeclare\fP command that, if | |
3154 | evaluated, will recreate \fIparameter\fP with its attributes and value. | |
3155 | .TP | |
3156 | .B a | |
3157 | The expansion is a string consisting of flag values representing | |
3158 | \fIparameter\fP's attributes. | |
3159 | .PD | |
3160 | .PP | |
3161 | If | |
3162 | .I parameter | |
3163 | is | |
3164 | .B @ | |
3165 | or | |
3166 | .BR * , | |
3167 | the operation is applied to each positional | |
3168 | parameter in turn, and the expansion is the resultant list. | |
3169 | If | |
3170 | .I parameter | |
3171 | is an array variable subscripted with | |
3172 | .B @ | |
3173 | or | |
3174 | .BR * , | |
3175 | the case modification operation is applied to each member of the | |
3176 | array in turn, and the expansion is the resultant list. | |
3177 | .sp 1 | |
3178 | The result of the expansion is subject to word splitting and pathname | |
3179 | expansion as described below. | |
3180 | .RE | |
726f6388 JA |
3181 | .SS Command Substitution |
3182 | .PP | |
cce855bc | 3183 | \fICommand substitution\fP allows the output of a command to replace |
726f6388 | 3184 | the command name. There are two forms: |
726f6388 JA |
3185 | .RS |
3186 | .PP | |
3187 | \fB$(\fP\fIcommand\fP\|\fB)\fP | |
3188 | .RE | |
3189 | or | |
3190 | .RS | |
3d4e09aa | 3191 | \fB\`\fP\fIcommand\fP\fB\`\fP |
726f6388 JA |
3192 | .RE |
3193 | .PP | |
ccc6cda3 | 3194 | .B Bash |
726f6388 JA |
3195 | performs the expansion by executing \fIcommand\fP and |
3196 | replacing the command substitution with the standard output of the | |
3197 | command, with any trailing newlines deleted. | |
cce855bc JA |
3198 | Embedded newlines are not deleted, but they may be removed during |
3199 | word splitting. | |
3200 | The command substitution \fB$(cat \fIfile\fP)\fR can be replaced by | |
3201 | the equivalent but faster \fB$(< \fIfile\fP)\fR. | |
726f6388 | 3202 | .PP |
ccc6cda3 | 3203 | When the old-style backquote form of substitution is used, |
726f6388 JA |
3204 | backslash retains its literal meaning except when followed by |
3205 | .BR $ , | |
3d4e09aa | 3206 | .BR \` , |
726f6388 JA |
3207 | or |
3208 | .BR \e . | |
cce855bc JA |
3209 | The first backquote not preceded by a backslash terminates the |
3210 | command substitution. | |
726f6388 JA |
3211 | When using the $(\^\fIcommand\fP\|) form, all characters between the |
3212 | parentheses make up the command; none are treated specially. | |
3213 | .PP | |
cce855bc | 3214 | Command substitutions may be nested. To nest when using the backquoted form, |
726f6388 JA |
3215 | escape the inner backquotes with backslashes. |
3216 | .PP | |
3217 | If the substitution appears within double quotes, word splitting and | |
3218 | pathname expansion are not performed on the results. | |
3219 | .SS Arithmetic Expansion | |
3220 | .PP | |
3221 | Arithmetic expansion allows the evaluation of an arithmetic expression | |
ccc6cda3 | 3222 | and the substitution of the result. The format for arithmetic expansion is: |
726f6388 JA |
3223 | .RS |
3224 | .PP | |
726f6388 JA |
3225 | \fB$((\fP\fIexpression\fP\fB))\fP |
3226 | .RE | |
3227 | .PP | |
3228 | The | |
3229 | .I expression | |
3230 | is treated as if it were within double quotes, but a double quote | |
ccc6cda3 | 3231 | inside the parentheses is not treated specially. |
2c511d38 CR |
3232 | All tokens in the expression undergo parameter and variable expansion, |
3233 | command substitution, and quote removal. | |
3234 | The result is treated as the arithmetic expression to be evaluated. | |
d3a24ed2 | 3235 | Arithmetic expansions may be nested. |
726f6388 JA |
3236 | .PP |
3237 | The evaluation is performed according to the rules listed below under | |
3238 | .SM | |
3239 | .BR "ARITHMETIC EVALUATION" . | |
3240 | If | |
3241 | .I expression | |
3242 | is invalid, | |
3243 | .B bash | |
3244 | prints a message indicating failure and no substitution occurs. | |
3245 | .SS Process Substitution | |
3246 | .PP | |
3247 | \fIProcess substitution\fP is supported on systems that support named | |
3248 | pipes (\fIFIFOs\fP) or the \fB/dev/fd\fP method of naming open files. | |
3249 | It takes the form of | |
3250 | \fB<(\fP\fIlist\^\fP\fB)\fP | |
3251 | or | |
3252 | \fB>(\fP\fIlist\^\fP\fB)\fP. | |
3253 | The process \fIlist\fP is run with its input or output connected to a | |
3254 | \fIFIFO\fP or some file in \fB/dev/fd\fP. The name of this file is | |
3255 | passed as an argument to the current command as the result of the | |
3256 | expansion. If the \fB>(\fP\fIlist\^\fP\fB)\fP form is used, writing to | |
3257 | the file will provide input for \fIlist\fP. If the | |
3258 | \fB<(\fP\fIlist\^\fP\fB)\fP form is used, the file passed as an | |
3259 | argument should be read to obtain the output of \fIlist\fP. | |
3260 | .PP | |
bb70624e | 3261 | When available, process substitution is performed |
fc527055 | 3262 | simultaneously with parameter and variable expansion, |
ccc6cda3 JA |
3263 | command substitution, |
3264 | and arithmetic expansion. | |
726f6388 JA |
3265 | .SS Word Splitting |
3266 | .PP | |
3267 | The shell scans the results of | |
3268 | parameter expansion, | |
3269 | command substitution, | |
3270 | and | |
3271 | arithmetic expansion | |
3272 | that did not occur within double quotes for | |
3273 | .IR "word splitting" . | |
3274 | .PP | |
3275 | The shell treats each character of | |
3276 | .SM | |
3277 | .B IFS | |
3278 | as a delimiter, and splits the results of the other | |
c8fe669a CR |
3279 | expansions into words using these characters as field terminators. |
3280 | If | |
726f6388 JA |
3281 | .SM |
3282 | .B IFS | |
ccc6cda3 JA |
3283 | is unset, or its |
3284 | value is exactly | |
726f6388 JA |
3285 | .BR <space><tab><newline> , |
3286 | the default, then | |
d3ad40de CR |
3287 | sequences of |
3288 | .BR <space> , | |
3289 | .BR <tab> , | |
3290 | and | |
3291 | .B <newline> | |
3292 | at the beginning and end of the results of the previous | |
3293 | expansions are ignored, and | |
726f6388 JA |
3294 | any sequence of |
3295 | .SM | |
3296 | .B IFS | |
d3ad40de CR |
3297 | characters not at the beginning or end serves to delimit words. |
3298 | If | |
726f6388 JA |
3299 | .SM |
3300 | .B IFS | |
3301 | has a value other than the default, then sequences of | |
3302 | the whitespace characters | |
3303 | .B space | |
3304 | and | |
3305 | .B tab | |
3306 | are ignored at the beginning and end of the | |
3307 | word, as long as the whitespace character is in the | |
3308 | value of | |
3309 | .SM | |
3310 | .BR IFS | |
3311 | (an | |
3312 | .SM | |
3313 | .B IFS | |
3314 | whitespace character). | |
3315 | Any character in | |
3316 | .SM | |
3317 | .B IFS | |
3318 | that is not | |
3319 | .SM | |
3320 | .B IFS | |
3321 | whitespace, along with any adjacent | |
3322 | .SM | |
3323 | .B IFS | |
3324 | whitespace characters, delimits a field. | |
3325 | A sequence of | |
3326 | .SM | |
3327 | .B IFS | |
3328 | whitespace characters is also treated as a delimiter. | |
3329 | If the value of | |
3330 | .SM | |
3331 | .B IFS | |
3332 | is null, no word splitting occurs. | |
726f6388 | 3333 | .PP |
20587658 | 3334 | Explicit null arguments (\^\f3"\^"\fP or \^\f3\(aq\^\(aq\fP\^) are retained. |
ccc6cda3 | 3335 | Unquoted implicit null arguments, resulting from the expansion of |
bb70624e | 3336 | parameters that have no values, are removed. |
ccc6cda3 JA |
3337 | If a parameter with no value is expanded within double quotes, a |
3338 | null argument results and is retained. | |
726f6388 JA |
3339 | .PP |
3340 | Note that if no expansion occurs, no splitting | |
3341 | is performed. | |
3342 | .SS Pathname Expansion | |
3343 | .PP | |
3344 | After word splitting, | |
3345 | unless the | |
3346 | .B \-f | |
3347 | option has been set, | |
3348 | .B bash | |
ccc6cda3 | 3349 | scans each word for the characters |
726f6388 JA |
3350 | .BR * , |
3351 | .BR ? , | |
3352 | and | |
3353 | .BR [ . | |
3354 | If one of these characters appears, then the word is | |
3355 | regarded as a | |
3356 | .IR pattern , | |
3357 | and replaced with an alphabetically sorted list of | |
b28ff8c9 | 3358 | filenames matching the pattern |
bfd181e7 CR |
3359 | (see |
3360 | .SM | |
3361 | .B "Pattern Matching" | |
3362 | below). | |
b28ff8c9 | 3363 | If no matching filenames are found, |
ccc6cda3 JA |
3364 | and the shell option |
3365 | .B nullglob | |
57a3f689 | 3366 | is not enabled, the word is left unchanged. |
fc527055 | 3367 | If the |
cce855bc JA |
3368 | .B nullglob |
3369 | option is set, and no matches are found, | |
726f6388 | 3370 | the word is removed. |
d3a24ed2 CR |
3371 | If the |
3372 | .B failglob | |
3373 | shell option is set, and no matches are found, an error message | |
3374 | is printed and the command is not executed. | |
cce855bc JA |
3375 | If the shell option |
3376 | .B nocaseglob | |
3377 | is enabled, the match is performed without regard to the case | |
3378 | of alphabetic characters. | |
ccc6cda3 | 3379 | When a pattern is used for pathname expansion, |
726f6388 JA |
3380 | the character |
3381 | .B ``.'' | |
3382 | at the start of a name or immediately following a slash | |
ccc6cda3 JA |
3383 | must be matched explicitly, unless the shell option |
3384 | .B dotglob | |
3385 | is set. | |
cce855bc JA |
3386 | When matching a pathname, the slash character must always be |
3387 | matched explicitly. | |
ccc6cda3 | 3388 | In other cases, the |
726f6388 JA |
3389 | .B ``.'' |
3390 | character is not treated specially. | |
ccc6cda3 JA |
3391 | See the description of |
3392 | .B shopt | |
3393 | below under | |
3394 | .SM | |
3395 | .B SHELL BUILTIN COMMANDS | |
3396 | for a description of the | |
cce855bc JA |
3397 | .BR nocaseglob , |
3398 | .BR nullglob , | |
d3a24ed2 | 3399 | .BR failglob , |
ccc6cda3 JA |
3400 | and |
3401 | .B dotglob | |
3402 | shell options. | |
3403 | .PP | |
3404 | The | |
3405 | .SM | |
3406 | .B GLOBIGNORE | |
b28ff8c9 | 3407 | shell variable may be used to restrict the set of filenames matching a |
ccc6cda3 JA |
3408 | .IR pattern . |
3409 | If | |
3410 | .SM | |
3411 | .B GLOBIGNORE | |
b28ff8c9 | 3412 | is set, each matching filename that also matches one of the patterns in |
ccc6cda3 JA |
3413 | .SM |
3414 | .B GLOBIGNORE | |
3415 | is removed from the list of matches. | |
0a233f3e CR |
3416 | If the \fBnocaseglob\fP option is set, the matching against the patterns in |
3417 | .SM | |
3418 | .B GLOBIGNORE | |
3419 | is performed without regard to case. | |
b28ff8c9 | 3420 | The filenames |
ccc6cda3 JA |
3421 | .B ``.'' |
3422 | and | |
3423 | .B ``..'' | |
d3a24ed2 | 3424 | are always ignored when |
ccc6cda3 JA |
3425 | .SM |
3426 | .B GLOBIGNORE | |
d3a24ed2 | 3427 | is set and not null. However, setting |
ccc6cda3 JA |
3428 | .SM |
3429 | .B GLOBIGNORE | |
d3a24ed2 | 3430 | to a non-null value has the effect of enabling the |
ccc6cda3 | 3431 | .B dotglob |
b28ff8c9 | 3432 | shell option, so all other filenames beginning with a |
ccc6cda3 JA |
3433 | .B ``.'' |
3434 | will match. | |
b28ff8c9 | 3435 | To get the old behavior of ignoring filenames beginning with a |
ccc6cda3 JA |
3436 | .BR ``.'' , |
3437 | make | |
3438 | .B ``.*'' | |
3439 | one of the patterns in | |
3440 | .SM | |
3441 | .BR GLOBIGNORE . | |
3442 | The | |
3443 | .B dotglob | |
3444 | option is disabled when | |
3445 | .SM | |
3446 | .B GLOBIGNORE | |
3447 | is unset. | |
726f6388 | 3448 | .PP |
cce855bc JA |
3449 | \fBPattern Matching\fP |
3450 | .PP | |
3451 | Any character that appears in a pattern, other than the special pattern | |
3452 | characters described below, matches itself. The NUL character may not | |
d3a24ed2 CR |
3453 | occur in a pattern. A backslash escapes the following character; the |
3454 | escaping backslash is discarded when matching. | |
3455 | The special pattern characters must be quoted if | |
cce855bc JA |
3456 | they are to be matched literally. |
3457 | .PP | |
726f6388 JA |
3458 | The special pattern characters have the following meanings: |
3459 | .PP | |
3460 | .PD 0 | |
89c77bc7 | 3461 | .RS |
726f6388 JA |
3462 | .TP |
3463 | .B * | |
3464 | Matches any string, including the null string. | |
4ac1ff98 | 3465 | When the \fBglobstar\fP shell option is enabled, and \fB*\fP is used in |
d0ca3503 | 3466 | a pathname expansion context, two adjacent \fB*\fPs used as a single |
4ac1ff98 CR |
3467 | pattern will match all files and zero or more directories and |
3468 | subdirectories. | |
3469 | If followed by a \fB/\fP, two adjacent \fB*\fPs will match only directories | |
3470 | and subdirectories. | |
726f6388 JA |
3471 | .TP |
3472 | .B ? | |
3473 | Matches any single character. | |
3474 | .TP | |
3475 | .B [...] | |
3476 | Matches any one of the enclosed characters. A pair of characters | |
28ef6c31 JA |
3477 | separated by a hyphen denotes a |
3478 | \fIrange expression\fP; | |
47b599dc | 3479 | any character that falls between those two characters, inclusive, |
28ef6c31 | 3480 | using the current locale's collating sequence and character set, |
726f6388 JA |
3481 | is matched. If the first character following the |
3482 | .B [ | |
3483 | is a | |
3484 | .B ! | |
3485 | or a | |
3486 | .B ^ | |
ccc6cda3 | 3487 | then any character not enclosed is matched. |
28ef6c31 | 3488 | The sorting order of characters in range expressions is determined by |
3443670e | 3489 | the current locale and the values of the |
984a1947 CR |
3490 | .SM |
3491 | .B LC_COLLATE | |
3443670e CR |
3492 | or |
3493 | .SM | |
3494 | .B LC_ALL | |
3495 | shell variables, if set. | |
3496 | To obtain the traditional interpretation of range expressions, where | |
3497 | .B [a\-d] | |
3498 | is equivalent to | |
3499 | .BR [abcd] , | |
3500 | set value of the | |
3501 | .B LC_ALL | |
3502 | shell variable to | |
74d0116b CR |
3503 | .BR C , |
3504 | or enable the | |
3505 | .B globasciiranges | |
3506 | shell option. | |
fc527055 | 3507 | A |
726f6388 | 3508 | .B \- |
726f6388 JA |
3509 | may be matched by including it as the first or last character |
3510 | in the set. | |
ccc6cda3 JA |
3511 | A |
3512 | .B ] | |
3513 | may be matched by including it as the first character | |
3514 | in the set. | |
cce855bc JA |
3515 | .br |
3516 | .if t .sp 0.5 | |
3517 | .if n .sp 1 | |
3518 | Within | |
3519 | .B [ | |
3520 | and | |
3521 | .BR ] , | |
3522 | \fIcharacter classes\fP can be specified using the syntax | |
3523 | \fB[:\fP\fIclass\fP\fB:]\fP, where \fIclass\fP is one of the | |
ac18b312 | 3524 | following classes defined in the POSIX standard: |
cce855bc JA |
3525 | .PP |
3526 | .RS | |
3527 | .B | |
7117c2d2 JA |
3528 | .if n alnum alpha ascii blank cntrl digit graph lower print punct space upper word xdigit |
3529 | .if t alnum alpha ascii blank cntrl digit graph lower print punct space upper word xdigit | |
cce855bc JA |
3530 | .br |
3531 | A character class matches any character belonging to that class. | |
7117c2d2 | 3532 | The \fBword\fP character class matches letters, digits, and the character _. |
cce855bc JA |
3533 | .br |
3534 | .if t .sp 0.5 | |
3535 | .if n .sp 1 | |
3536 | Within | |
3537 | .B [ | |
fc527055 | 3538 | and |
cce855bc JA |
3539 | .BR ] , |
3540 | an \fIequivalence class\fP can be specified using the syntax | |
3541 | \fB[=\fP\fIc\fP\fB=]\fP, which matches all characters with the | |
3542 | same collation weight (as defined by the current locale) as | |
3543 | the character \fIc\fP. | |
3544 | .br | |
3545 | .if t .sp 0.5 | |
3546 | .if n .sp 1 | |
3547 | Within | |
3548 | .B [ | |
fc527055 | 3549 | and |
cce855bc JA |
3550 | .BR ] , |
3551 | the syntax \fB[.\fP\fIsymbol\fP\fB.]\fP matches the collating symbol | |
3552 | \fIsymbol\fP. | |
3553 | .RE | |
89c77bc7 | 3554 | .RE |
cce855bc JA |
3555 | .PD |
3556 | .PP | |
3557 | If the \fBextglob\fP shell option is enabled using the \fBshopt\fP | |
3558 | builtin, several extended pattern matching operators are recognized. | |
bb70624e | 3559 | In the following description, a \fIpattern-list\fP is a list of one |
cce855bc JA |
3560 | or more patterns separated by a \fB|\fP. |
3561 | Composite patterns may be formed using one or more of the following | |
3562 | sub-patterns: | |
3563 | .sp 1 | |
3564 | .PD 0 | |
3565 | .RS | |
3566 | .TP | |
3567 | \fB?(\fP\^\fIpattern-list\^\fP\fB)\fP | |
3568 | Matches zero or one occurrence of the given patterns | |
3569 | .TP | |
3570 | \fB*(\fP\^\fIpattern-list\^\fP\fB)\fP | |
3571 | Matches zero or more occurrences of the given patterns | |
3572 | .TP | |
3573 | \fB+(\fP\^\fIpattern-list\^\fP\fB)\fP | |
3574 | Matches one or more occurrences of the given patterns | |
3575 | .TP | |
3576 | \fB@(\fP\^\fIpattern-list\^\fP\fB)\fP | |
43df7bbb | 3577 | Matches one of the given patterns |
cce855bc JA |
3578 | .TP |
3579 | \fB!(\fP\^\fIpattern-list\^\fP\fB)\fP | |
3580 | Matches anything except one of the given patterns | |
3581 | .RE | |
726f6388 JA |
3582 | .PD |
3583 | .SS Quote Removal | |
3584 | .PP | |
3585 | After the preceding expansions, all unquoted occurrences of the | |
3586 | characters | |
3587 | .BR \e , | |
20587658 | 3588 | .BR \(aq , |
ccc6cda3 JA |
3589 | and \^\f3"\fP\^ that did not result from one of the above |
3590 | expansions are removed. | |
726f6388 JA |
3591 | .SH REDIRECTION |
3592 | Before a command is executed, its input and output | |
3593 | may be | |
3594 | .I redirected | |
3595 | using a special notation interpreted by the shell. | |
c31d56a7 CR |
3596 | Redirection allows commands' file handles to be |
3597 | duplicated, opened, closed, | |
3598 | made to refer to different files, | |
3599 | and can change the files the command reads from and writes to. | |
3600 | Redirection may also be used to modify file handles in the | |
3601 | current shell execution environment. | |
3602 | The following redirection | |
726f6388 JA |
3603 | operators may precede or appear anywhere within a |
3604 | .I simple command | |
3605 | or may follow a | |
3606 | .IR command . | |
3607 | Redirections are processed in the order they appear, from | |
3608 | left to right. | |
3609 | .PP | |
a8fd3f3e CR |
3610 | Each redirection that may be preceded by a file descriptor number |
3611 | may instead be preceded by a word of the form {\fIvarname\fP}. | |
3612 | In this case, for each redirection operator except | |
3613 | >&- and <&-, the shell will allocate a file descriptor greater | |
19baff85 CR |
3614 | than or equal to 10 and assign it to \fIvarname\fP. |
3615 | If >&- or <&- is preceded | |
a8fd3f3e CR |
3616 | by {\fIvarname\fP}, the value of \fIvarname\fP defines the file |
3617 | descriptor to close. | |
3618 | .PP | |
726f6388 JA |
3619 | In the following descriptions, if the file descriptor number is |
3620 | omitted, and the first character of the redirection operator is | |
3621 | .BR < , | |
3622 | the redirection refers to the standard input (file descriptor | |
3623 | 0). If the first character of the redirection operator is | |
3624 | .BR > , | |
3625 | the redirection refers to the standard output (file descriptor | |
3626 | 1). | |
3627 | .PP | |
cce855bc | 3628 | The word following the redirection operator in the following |
7610e0c5 CR |
3629 | descriptions, unless otherwise noted, is subjected to |
3630 | brace expansion, tilde expansion, parameter and variable expansion, | |
3631 | command substitution, arithmetic expansion, quote removal, | |
3632 | pathname expansion, and word splitting. | |
cce855bc | 3633 | If it expands to more than one word, |
726f6388 JA |
3634 | .B bash |
3635 | reports an error. | |
3636 | .PP | |
fc527055 | 3637 | Note that the order of redirections is significant. For example, |
726f6388 JA |
3638 | the command |
3639 | .RS | |
3640 | .PP | |
3641 | ls \fB>\fP dirlist 2\fB>&\fP1 | |
3642 | .RE | |
3643 | .PP | |
fc527055 | 3644 | directs both standard output and standard error to the file |
726f6388 JA |
3645 | .IR dirlist , |
3646 | while the command | |
3647 | .RS | |
3648 | .PP | |
3649 | ls 2\fB>&\fP1 \fB>\fP dirlist | |
3650 | .RE | |
3651 | .PP | |
3652 | directs only the standard output to file | |
3653 | .IR dirlist , | |
db31fb26 | 3654 | because the standard error was duplicated from the standard output |
726f6388 JA |
3655 | before the standard output was redirected to |
3656 | .IR dirlist . | |
cce855bc | 3657 | .PP |
bb70624e JA |
3658 | \fBBash\fP handles several filenames specially when they are used in |
3659 | redirections, as described in the following table: | |
3660 | .RS | |
3661 | .PP | |
3662 | .PD 0 | |
3663 | .TP | |
3664 | .B /dev/fd/\fIfd\fP | |
3665 | If \fIfd\fP is a valid integer, file descriptor \fIfd\fP is duplicated. | |
3666 | .TP | |
3667 | .B /dev/stdin | |
3668 | File descriptor 0 is duplicated. | |
3669 | .TP | |
3670 | .B /dev/stdout | |
3671 | File descriptor 1 is duplicated. | |
3672 | .TP | |
3673 | .B /dev/stderr | |
3674 | File descriptor 2 is duplicated. | |
3675 | .TP | |
3676 | .B /dev/tcp/\fIhost\fP/\fIport\fP | |
3677 | If \fIhost\fP is a valid hostname or Internet address, and \fIport\fP | |
f73dda09 | 3678 | is an integer port number or service name, \fBbash\fP attempts to open |
e107650c | 3679 | the corresponding TCP socket. |
bb70624e JA |
3680 | .TP |
3681 | .B /dev/udp/\fIhost\fP/\fIport\fP | |
3682 | If \fIhost\fP is a valid hostname or Internet address, and \fIport\fP | |
f73dda09 | 3683 | is an integer port number or service name, \fBbash\fP attempts to open |
e107650c | 3684 | the corresponding UDP socket. |
bb70624e JA |
3685 | .PD |
3686 | .RE | |
3687 | .PP | |
cce855bc | 3688 | A failure to open or create a file causes the redirection to fail. |
cac4cdbf CR |
3689 | .PP |
3690 | Redirections using file descriptors greater than 9 should be used with | |
3691 | care, as they may conflict with file descriptors the shell uses | |
3692 | internally. | |
726f6388 JA |
3693 | .SS Redirecting Input |
3694 | .PP | |
3695 | Redirection of input causes the file whose name results from | |
3696 | the expansion of | |
3697 | .I word | |
3698 | to be opened for reading on file descriptor | |
3699 | .IR n , | |
3700 | or the standard input (file descriptor 0) if | |
3701 | .I n | |
3702 | is not specified. | |
3703 | .PP | |
3704 | The general format for redirecting input is: | |
3705 | .RS | |
3706 | .PP | |
3707 | [\fIn\fP]\fB<\fP\fIword\fP | |
3708 | .RE | |
3709 | .SS Redirecting Output | |
3710 | .PP | |
3711 | Redirection of output causes the file whose name results from | |
3712 | the expansion of | |
3713 | .I word | |
3714 | to be opened for writing on file descriptor | |
3715 | .IR n , | |
3716 | or the standard output (file descriptor 1) if | |
3717 | .I n | |
3718 | is not specified. If the file does not exist it is created; | |
3719 | if it does exist it is truncated to zero size. | |
3720 | .PP | |
3721 | The general format for redirecting output is: | |
3722 | .RS | |
3723 | .PP | |
3724 | [\fIn\fP]\fB>\fP\fIword\fP | |
3725 | .RE | |
3726 | .PP | |
3727 | If the redirection operator is | |
ccc6cda3 JA |
3728 | .BR > , |
3729 | and the | |
cce855bc | 3730 | .B noclobber |
ccc6cda3 JA |
3731 | option to the |
3732 | .B set | |
bb70624e | 3733 | builtin has been enabled, the redirection will fail if the file |
cce855bc JA |
3734 | whose name results from the expansion of \fIword\fP exists and is |
3735 | a regular file. | |
ccc6cda3 | 3736 | If the redirection operator is |
726f6388 | 3737 | .BR >| , |
cce855bc JA |
3738 | or the redirection operator is |
3739 | .B > | |
3740 | and the | |
3741 | .B noclobber | |
726f6388 JA |
3742 | option to the |
3743 | .B set | |
cce855bc | 3744 | builtin command is not enabled, the redirection is attempted even |
ccc6cda3 | 3745 | if the file named by \fIword\fP exists. |
726f6388 JA |
3746 | .SS Appending Redirected Output |
3747 | .PP | |
3748 | Redirection of output in this fashion | |
3749 | causes the file whose name results from | |
3750 | the expansion of | |
3751 | .I word | |
3752 | to be opened for appending on file descriptor | |
3753 | .IR n , | |
3754 | or the standard output (file descriptor 1) if | |
3755 | .I n | |
3756 | is not specified. If the file does not exist it is created. | |
3757 | .PP | |
3758 | The general format for appending output is: | |
3759 | .RS | |
3760 | .PP | |
3761 | [\fIn\fP]\fB>>\fP\fIword\fP | |
3762 | .RE | |
3763 | .PP | |
3764 | .SS Redirecting Standard Output and Standard Error | |
3765 | .PP | |
8943768b | 3766 | This construct allows both the |
726f6388 JA |
3767 | standard output (file descriptor 1) and |
3768 | the standard error output (file descriptor 2) | |
3769 | to be redirected to the file whose name is the | |
3770 | expansion of | |
8943768b | 3771 | .IR word . |
726f6388 JA |
3772 | .PP |
3773 | There are two formats for redirecting standard output and | |
3774 | standard error: | |
3775 | .RS | |
3776 | .PP | |
3777 | \fB&>\fP\fIword\fP | |
3778 | .RE | |
3779 | and | |
3780 | .RS | |
3781 | \fB>&\fP\fIword\fP | |
3782 | .RE | |
3783 | .PP | |
3784 | Of the two forms, the first is preferred. | |
3785 | This is semantically equivalent to | |
3786 | .RS | |
3787 | .PP | |
3788 | \fB>\fP\fIword\fP 2\fB>&\fP1 | |
3789 | .RE | |
8943768b | 3790 | .PP |
c5402025 CR |
3791 | When using the second form, \fIword\fP may not expand to a number or |
3792 | \fB\-\fP. If it does, other redirection operators apply | |
3793 | (see \fBDuplicating File Descriptors\fP below) for compatibility | |
3794 | reasons. | |
8943768b CR |
3795 | .SS Appending Standard Output and Standard Error |
3796 | .PP | |
3797 | This construct allows both the | |
3798 | standard output (file descriptor 1) and | |
3799 | the standard error output (file descriptor 2) | |
3800 | to be appended to the file whose name is the | |
3801 | expansion of | |
3802 | .IR word . | |
3803 | .PP | |
3804 | The format for appending standard output and standard error is: | |
3805 | .RS | |
3806 | .PP | |
3807 | \fB&>>\fP\fIword\fP | |
3808 | .RE | |
3809 | .PP | |
3810 | This is semantically equivalent to | |
3811 | .RS | |
3812 | .PP | |
3813 | \fB>>\fP\fIword\fP 2\fB>&\fP1 | |
3814 | .RE | |
f6da9f85 CR |
3815 | .PP |
3816 | (see \fBDuplicating File Descriptors\fP below). | |
726f6388 JA |
3817 | .SS Here Documents |
3818 | .PP | |
3819 | This type of redirection instructs the shell to read input from the | |
3820 | current source until a line containing only | |
626d0694 | 3821 | .I delimiter |
726f6388 JA |
3822 | (with no trailing blanks) |
3823 | is seen. All of | |
3824 | the lines read up to that point are then used as the standard | |
d36d2bcf | 3825 | input (or file descriptor \fIn\fP if \fIn\fP is specified) for a command. |
726f6388 | 3826 | .PP |
7117c2d2 | 3827 | The format of here-documents is: |
726f6388 JA |
3828 | .RS |
3829 | .PP | |
3830 | .nf | |
d36d2bcf | 3831 | [\fIn\fP]\fB<<\fP[\fB\-\fP]\fIword\fP |
f73dda09 | 3832 | \fIhere-document\fP |
726f6388 JA |
3833 | \fIdelimiter\fP |
3834 | .fi | |
3835 | .RE | |
3836 | .PP | |
7610e0c5 CR |
3837 | No parameter and variable expansion, command substitution, |
3838 | arithmetic expansion, or pathname expansion is performed on | |
726f6388 JA |
3839 | .IR word . |
3840 | If any characters in | |
3841 | .I word | |
3842 | are quoted, the | |
3843 | .I delimiter | |
3844 | is the result of quote removal on | |
3845 | .IR word , | |
cce855bc JA |
3846 | and the lines in the here-document are not expanded. |
3847 | If \fIword\fP is unquoted, | |
e73012f1 CR |
3848 | all lines of the here-document are subjected to |
3849 | parameter expansion, command substitution, and arithmetic expansion, | |
3850 | the character sequence | |
726f6388 JA |
3851 | .B \e<newline> |
3852 | is ignored, and | |
3853 | .B \e | |
3854 | must be used to quote the characters | |
3855 | .BR \e , | |
3856 | .BR $ , | |
3857 | and | |
3d4e09aa | 3858 | .BR \` . |
726f6388 JA |
3859 | .PP |
3860 | If the redirection operator is | |
3861 | .BR <<\- , | |
3862 | then all leading tab characters are stripped from input lines and the | |
3863 | line containing | |
3864 | .IR delimiter . | |
3865 | This allows | |
3866 | here-documents within shell scripts to be indented in a | |
3867 | natural fashion. | |
7117c2d2 JA |
3868 | .SS "Here Strings" |
3869 | A variant of here documents, the format is: | |
3870 | .RS | |
3871 | .PP | |
3872 | .nf | |
d36d2bcf | 3873 | [\fIn\fP]\fB<<<\fP\fIword\fP |
7117c2d2 JA |
3874 | .fi |
3875 | .RE | |
3876 | .PP | |
7610e0c5 CR |
3877 | The \fIword\fP undergoes |
3878 | brace expansion, tilde expansion, parameter and variable expansion, | |
3879 | command substitution, arithmetic expansion, and quote removal. | |
e73012f1 | 3880 | Pathname expansion and word splitting are not performed. |
7610e0c5 | 3881 | The result is supplied as a single string to the command on its |
d36d2bcf | 3882 | standard input (or file descriptor \fIn\fP if \fIn\fP is specified). |
726f6388 | 3883 | .SS "Duplicating File Descriptors" |
d36d2bcf | 3884 | |
726f6388 JA |
3885 | .PP |
3886 | The redirection operator | |
3887 | .RS | |
3888 | .PP | |
3889 | [\fIn\fP]\fB<&\fP\fIword\fP | |
3890 | .RE | |
3891 | .PP | |
3892 | is used to duplicate input file descriptors. | |
3893 | If | |
3894 | .I word | |
3895 | expands to one or more digits, the file descriptor denoted by | |
3896 | .I n | |
cce855bc JA |
3897 | is made to be a copy of that file descriptor. |
3898 | If the digits in | |
3899 | .I word | |
3900 | do not specify a file descriptor open for input, a redirection error occurs. | |
3901 | If | |
726f6388 JA |
3902 | .I word |
3903 | evaluates to | |
3904 | .BR \- , | |
3905 | file descriptor | |
3906 | .I n | |
3907 | is closed. If | |
3908 | .I n | |
3909 | is not specified, the standard input (file descriptor 0) is used. | |
3910 | .PP | |
3911 | The operator | |
3912 | .RS | |
3913 | .PP | |
3914 | [\fIn\fP]\fB>&\fP\fIword\fP | |
3915 | .RE | |
3916 | .PP | |
3917 | is used similarly to duplicate output file descriptors. If | |
3918 | .I n | |
3919 | is not specified, the standard output (file descriptor 1) is used. | |
cce855bc JA |
3920 | If the digits in |
3921 | .I word | |
3922 | do not specify a file descriptor open for output, a redirection error occurs. | |
c5402025 CR |
3923 | If |
3924 | .I word | |
3925 | evaluates to | |
3926 | .BR \- , | |
3927 | file descriptor | |
3928 | .I n | |
3929 | is closed. | |
726f6388 | 3930 | As a special case, if \fIn\fP is omitted, and \fIword\fP does not |
c5402025 | 3931 | expand to one or more digits or \fB\-\fP, the standard output and standard |
726f6388 | 3932 | error are redirected as described previously. |
7117c2d2 JA |
3933 | .SS "Moving File Descriptors" |
3934 | .PP | |
3935 | The redirection operator | |
3936 | .RS | |
3937 | .PP | |
3938 | [\fIn\fP]\fB<&\fP\fIdigit\fP\fB\-\fP | |
3939 | .RE | |
3940 | .PP | |
3941 | moves the file descriptor \fIdigit\fP to file descriptor | |
3942 | .IR n , | |
3943 | or the standard input (file descriptor 0) if \fIn\fP is not specified. | |
3944 | \fIdigit\fP is closed after being duplicated to \fIn\fP. | |
3945 | .PP | |
3946 | Similarly, the redirection operator | |
3947 | .RS | |
3948 | .PP | |
3949 | [\fIn\fP]\fB>&\fP\fIdigit\fP\fB\-\fP | |
3950 | .RE | |
3951 | .PP | |
3952 | moves the file descriptor \fIdigit\fP to file descriptor | |
3953 | .IR n , | |
3954 | or the standard output (file descriptor 1) if \fIn\fP is not specified. | |
726f6388 JA |
3955 | .SS "Opening File Descriptors for Reading and Writing" |
3956 | .PP | |
3957 | The redirection operator | |
3958 | .RS | |
3959 | .PP | |
3960 | [\fIn\fP]\fB<>\fP\fIword\fP | |
3961 | .RE | |
3962 | .PP | |
3963 | causes the file whose name is the expansion of | |
3964 | .I word | |
3965 | to be opened for both reading and writing on file descriptor | |
3966 | .IR n , | |
ccc6cda3 | 3967 | or on file descriptor 0 if |
726f6388 JA |
3968 | .I n |
3969 | is not specified. If the file does not exist, it is created. | |
726f6388 | 3970 | .SH ALIASES |
bb70624e | 3971 | \fIAliases\fP allow a string to be substituted for a word when it is used |
cce855bc | 3972 | as the first word of a simple command. |
bb70624e | 3973 | The shell maintains a list of aliases that may be set and unset with the |
726f6388 JA |
3974 | .B alias |
3975 | and | |
3976 | .B unalias | |
3977 | builtin commands (see | |
3978 | .SM | |
3979 | .B SHELL BUILTIN COMMANDS | |
3980 | below). | |
de8913bd | 3981 | The first word of each simple command, if unquoted, |
726f6388 JA |
3982 | is checked to see if it has an |
3983 | alias. If so, that word is replaced by the text of the alias. | |
3d4e09aa | 3984 | The characters \fB/\fP, \fB$\fP, \fB\`\fP, and \fB=\fP and |
de8913bd CR |
3985 | any of the shell \fImetacharacters\fP or quoting characters |
3986 | listed above may not appear in an alias name. | |
3987 | The replacement text may contain any valid shell input, | |
3988 | including shell metacharacters. | |
3989 | The first word of the replacement text is tested | |
726f6388 | 3990 | for aliases, but a word that is identical to an alias being expanded |
de8913bd CR |
3991 | is not expanded a second time. |
3992 | This means that one may alias | |
726f6388 JA |
3993 | .B ls |
3994 | to | |
3995 | .BR "ls \-F" , | |
3996 | for instance, and | |
3997 | .B bash | |
3998 | does not try to recursively expand the replacement text. | |
3999 | If the last character of the alias value is a | |
4000 | .IR blank , | |
4001 | then the next command | |
4002 | word following the alias is also checked for alias expansion. | |
4003 | .PP | |
4004 | Aliases are created and listed with the | |
4005 | .B alias | |
4006 | command, and removed with the | |
4007 | .B unalias | |
4008 | command. | |
4009 | .PP | |
ccc6cda3 | 4010 | There is no mechanism for using arguments in the replacement text. |
bb70624e JA |
4011 | If arguments are needed, a shell function should be used (see |
4012 | .SM | |
4013 | .B FUNCTIONS | |
4014 | below). | |
726f6388 | 4015 | .PP |
ccc6cda3 JA |
4016 | Aliases are not expanded when the shell is not interactive, unless |
4017 | the | |
4018 | .B expand_aliases | |
4019 | shell option is set using | |
4020 | .B shopt | |
4021 | (see the description of | |
4022 | .B shopt | |
4023 | under | |
4024 | .SM | |
4025 | \fBSHELL BUILTIN COMMANDS\fP | |
4026 | below). | |
726f6388 JA |
4027 | .PP |
4028 | The rules concerning the definition and use of aliases are | |
4029 | somewhat confusing. | |
4030 | .B Bash | |
4031 | always reads at least one complete line | |
4032 | of input before executing any | |
4033 | of the commands on that line. Aliases are expanded when a | |
4034 | command is read, not when it is executed. Therefore, an | |
4035 | alias definition appearing on the same line as another | |
4036 | command does not take effect until the next line of input is read. | |
ccc6cda3 | 4037 | The commands following the alias definition |
726f6388 JA |
4038 | on that line are not affected by the new alias. |
4039 | This behavior is also an issue when functions are executed. | |
cce855bc | 4040 | Aliases are expanded when a function definition is read, |
726f6388 | 4041 | not when the function is executed, because a function definition |
e2f12fdf | 4042 | is itself a command. As a consequence, aliases |
726f6388 JA |
4043 | defined in a function are not available until after that |
4044 | function is executed. To be safe, always put | |
4045 | alias definitions on a separate line, and do not use | |
4046 | .B alias | |
4047 | in compound commands. | |
4048 | .PP | |
cce855bc | 4049 | For almost every purpose, aliases are superseded by |
726f6388 | 4050 | shell functions. |
ccc6cda3 JA |
4051 | .SH FUNCTIONS |
4052 | A shell function, defined as described above under | |
4053 | .SM | |
4054 | .BR "SHELL GRAMMAR" , | |
4055 | stores a series of commands for later execution. | |
bb70624e JA |
4056 | When the name of a shell function is used as a simple command name, |
4057 | the list of commands associated with that function name is executed. | |
ccc6cda3 JA |
4058 | Functions are executed in the context of the |
4059 | current shell; no new process is created to interpret | |
4060 | them (contrast this with the execution of a shell script). | |
4061 | When a function is executed, the arguments to the | |
4062 | function become the positional parameters | |
bb70624e JA |
4063 | during its execution. |
4064 | The special parameter | |
ccc6cda3 | 4065 | .B # |
dc60d4e0 | 4066 | is updated to reflect the change. Special parameter \fB0\fP |
bb70624e | 4067 | is unchanged. |
d3a24ed2 | 4068 | The first element of the |
bb70624e JA |
4069 | .SM |
4070 | .B FUNCNAME | |
4071 | variable is set to the name of the function while the function | |
4072 | is executing. | |
4301bca7 | 4073 | .PP |
bb70624e | 4074 | All other aspects of the shell execution |
ccc6cda3 | 4075 | environment are identical between a function and its caller |
fc527055 | 4076 | with these exceptions: the |
ccc6cda3 JA |
4077 | .SM |
4078 | .B DEBUG | |
76a8d78d CR |
4079 | and |
4080 | .B RETURN | |
4081 | traps (see the description of the | |
ccc6cda3 JA |
4082 | .B trap |
4083 | builtin under | |
4084 | .SM | |
4085 | .B SHELL BUILTIN COMMANDS | |
76a8d78d | 4086 | below) are not inherited unless the function has been given the |
7117c2d2 JA |
4087 | \fBtrace\fP attribute (see the description of the |
4088 | .SM | |
4089 | .B declare | |
d3a24ed2 CR |
4090 | builtin below) or the |
4091 | \fB\-o functrace\fP shell option has been enabled with | |
4092 | the \fBset\fP builtin | |
4301bca7 CR |
4093 | (in which case all functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps), |
4094 | and the | |
4095 | .SM | |
4096 | .B ERR | |
4097 | trap is not inherited unless the \fB\-o errtrace\fP shell option has | |
4098 | been enabled. | |
726f6388 | 4099 | .PP |
ccc6cda3 JA |
4100 | Variables local to the function may be declared with the |
4101 | .B local | |
4102 | builtin command. Ordinarily, variables and their values | |
4103 | are shared between the function and its caller. | |
726f6388 | 4104 | .PP |
6faad625 CR |
4105 | The \fBFUNCNEST\fP variable, if set to a numeric value greater |
4106 | than 0, defines a maximum function nesting level. Function | |
4107 | invocations that exceed the limit cause the entire command to | |
4108 | abort. | |
4109 | .PP | |
ccc6cda3 JA |
4110 | If the builtin command |
4111 | .B return | |
4112 | is executed in a function, the function completes and | |
4113 | execution resumes with the next command after the function | |
d3a24ed2 CR |
4114 | call. |
4115 | Any command associated with the \fBRETURN\fP trap is executed | |
4116 | before execution resumes. | |
4117 | When a function completes, the values of the | |
ccc6cda3 JA |
4118 | positional parameters and the special parameter |
4119 | .B # | |
cce855bc | 4120 | are restored to the values they had prior to the function's |
ccc6cda3 | 4121 | execution. |
726f6388 | 4122 | .PP |
ccc6cda3 JA |
4123 | Function names and definitions may be listed with the |
4124 | .B \-f | |
726f6388 | 4125 | option to the |
ccc6cda3 JA |
4126 | .B declare |
4127 | or | |
4128 | .B typeset | |
4129 | builtin commands. The | |
4130 | .B \-F | |
4131 | option to | |
4132 | .B declare | |
4133 | or | |
4134 | .B typeset | |
d3a24ed2 CR |
4135 | will list the function names only |
4136 | (and optionally the source file and line number, if the \fBextdebug\fP | |
4137 | shell option is enabled). | |
ccc6cda3 JA |
4138 | Functions may be exported so that subshells |
4139 | automatically have them defined with the | |
4140 | .B \-f | |
4141 | option to the | |
4142 | .B export | |
4143 | builtin. | |
11a6f9a9 CR |
4144 | A function definition may be deleted using the \fB\-f\fP option to |
4145 | the | |
4146 | .B unset | |
4147 | builtin. | |
d3a24ed2 CR |
4148 | Note that shell functions and variables with the same name may result |
4149 | in multiple identically-named entries in the environment passed to the | |
4150 | shell's children. | |
4151 | Care should be taken in cases where this may cause a problem. | |
726f6388 | 4152 | .PP |
7d92f73f CR |
4153 | Functions may be recursive. |
4154 | The \fBFUNCNEST\fP variable may be used to limit the depth of the | |
4155 | function call stack and restrict the number of function invocations. | |
4156 | By default, no limit is imposed on the number of recursive calls. | |
cce855bc JA |
4157 | .SH "ARITHMETIC EVALUATION" |
4158 | The shell allows arithmetic expressions to be evaluated, under | |
d3a24ed2 CR |
4159 | certain circumstances (see the \fBlet\fP and \fBdeclare\fP builtin |
4160 | commands and \fBArithmetic Expansion\fP). | |
7117c2d2 | 4161 | Evaluation is done in fixed-width integers with no check for overflow, |
cce855bc | 4162 | though division by 0 is trapped and flagged as an error. |
d3a24ed2 CR |
4163 | The operators and their precedence, associativity, and values |
4164 | are the same as in the C language. | |
cce855bc JA |
4165 | The following list of operators is grouped into levels of |
4166 | equal-precedence operators. | |
4167 | The levels are listed in order of decreasing precedence. | |
726f6388 | 4168 | .PP |
cce855bc JA |
4169 | .PD 0 |
4170 | .TP | |
bb70624e JA |
4171 | .B \fIid\fP++ \fIid\fP\-\- |
4172 | variable post-increment and post-decrement | |
4173 | .TP | |
4174 | .B ++\fIid\fP \-\-\fIid\fP | |
4175 | variable pre-increment and pre-decrement | |
4176 | .TP | |
cce855bc JA |
4177 | .B \- + |
4178 | unary minus and plus | |
4179 | .TP | |
4180 | .B ! ~ | |
4181 | logical and bitwise negation | |
4182 | .TP | |
4183 | .B ** | |
4184 | exponentiation | |
4185 | .TP | |
4186 | .B * / % | |
4187 | multiplication, division, remainder | |
4188 | .TP | |
4189 | .B + \- | |
4190 | addition, subtraction | |
4191 | .TP | |
4192 | .B << >> | |
4193 | left and right bitwise shifts | |
4194 | .TP | |
4195 | .B <= >= < > | |
4196 | comparison | |
4197 | .TP | |
4198 | .B == != | |
4199 | equality and inequality | |
4200 | .TP | |
4201 | .B & | |
4202 | bitwise AND | |
4203 | .TP | |
4204 | .B ^ | |
4205 | bitwise exclusive OR | |
4206 | .TP | |
4207 | .B | | |
4208 | bitwise OR | |
4209 | .TP | |
4210 | .B && | |
4211 | logical AND | |
4212 | .TP | |
4213 | .B || | |
4214 | logical OR | |
4215 | .TP | |
4216 | .B \fIexpr\fP?\fIexpr\fP:\fIexpr\fP | |
d3a24ed2 | 4217 | conditional operator |
cce855bc JA |
4218 | .TP |
4219 | .B = *= /= %= += \-= <<= >>= &= ^= |= | |
4220 | assignment | |
bb70624e JA |
4221 | .TP |
4222 | .B \fIexpr1\fP , \fIexpr2\fP | |
4223 | comma | |
cce855bc | 4224 | .PD |
ccc6cda3 | 4225 | .PP |
cce855bc | 4226 | Shell variables are allowed as operands; parameter expansion is |
bb70624e JA |
4227 | performed before the expression is evaluated. |
4228 | Within an expression, shell variables may also be referenced by name | |
4229 | without using the parameter expansion syntax. | |
d3a24ed2 CR |
4230 | A shell variable that is null or unset evaluates to 0 when referenced |
4231 | by name without using the parameter expansion syntax. | |
bb70624e | 4232 | The value of a variable is evaluated as an arithmetic expression |
d3a24ed2 CR |
4233 | when it is referenced, or when a variable which has been given the |
4234 | \fIinteger\fP attribute using \fBdeclare -i\fP is assigned a value. | |
4235 | A null value evaluates to 0. | |
dc60d4e0 | 4236 | A shell variable need not have its \fIinteger\fP attribute |
cce855bc | 4237 | turned on to be used in an expression. |
ccc6cda3 | 4238 | .PP |
cce855bc JA |
4239 | Constants with a leading 0 are interpreted as octal numbers. |
4240 | A leading 0x or 0X denotes hexadecimal. | |
1b13a290 | 4241 | Otherwise, numbers take the form [\fIbase#\fP]n, where the optional \fIbase\fP |
cce855bc JA |
4242 | is a decimal number between 2 and 64 representing the arithmetic |
4243 | base, and \fIn\fP is a number in that base. | |
bb70624e | 4244 | If \fIbase#\fP is omitted, then base 10 is used. |
c31d56a7 | 4245 | When specifying \fIn\fP, |
687a967e | 4246 | the digits greater than 9 are represented by the lowercase letters, |
f73dda09 | 4247 | the uppercase letters, @, and _, in that order. |
cce855bc | 4248 | If \fIbase\fP is less than or equal to 36, lowercase and uppercase |
f75912ae | 4249 | letters may be used interchangeably to represent numbers between 10 |
cce855bc | 4250 | and 35. |
ccc6cda3 | 4251 | .PP |
cce855bc JA |
4252 | Operators are evaluated in order of precedence. Sub-expressions in |
4253 | parentheses are evaluated first and may override the precedence | |
4254 | rules above. | |
4255 | .SH "CONDITIONAL EXPRESSIONS" | |
4256 | Conditional expressions are used by the \fB[[\fP compound command and | |
4257 | the \fBtest\fP and \fB[\fP builtin commands to test file attributes | |
4258 | and perform string and arithmetic comparisons. | |
4259 | Expressions are formed from the following unary or binary primaries. | |
4260 | If any \fIfile\fP argument to one of the primaries is of the form | |
bb70624e JA |
4261 | \fI/dev/fd/n\fP, then file descriptor \fIn\fP is checked. |
4262 | If the \fIfile\fP argument to one of the primaries is one of | |
4263 | \fI/dev/stdin\fP, \fI/dev/stdout\fP, or \fI/dev/stderr\fP, file | |
4264 | descriptor 0, 1, or 2, respectively, is checked. | |
be7d8f2d CR |
4265 | .PP |
4266 | Unless otherwise specified, primaries that operate on files follow symbolic | |
4267 | links and operate on the target of the link, rather than the link itself. | |
6bf8a8a7 CR |
4268 | .if t .sp 0.5 |
4269 | .if n .sp 1 | |
54a1fa7c | 4270 | When used with \fB[[\fP, the \fB<\fP and \fB>\fP operators sort |
6bf8a8a7 | 4271 | lexicographically using the current locale. |
54a1fa7c | 4272 | The \fBtest\fP command sorts using ASCII ordering. |
cce855bc JA |
4273 | .sp 1 |
4274 | .PD 0 | |
4275 | .TP | |
4276 | .B \-a \fIfile\fP | |
4277 | True if \fIfile\fP exists. | |
4278 | .TP | |
4279 | .B \-b \fIfile\fP | |
4280 | True if \fIfile\fP exists and is a block special file. | |
4281 | .TP | |
4282 | .B \-c \fIfile\fP | |
4283 | True if \fIfile\fP exists and is a character special file. | |
4284 | .TP | |
4285 | .B \-d \fIfile\fP | |
4286 | True if \fIfile\fP exists and is a directory. | |
4287 | .TP | |
4288 | .B \-e \fIfile\fP | |
4289 | True if \fIfile\fP exists. | |
4290 | .TP | |
4291 | .B \-f \fIfile\fP | |
4292 | True if \fIfile\fP exists and is a regular file. | |
4293 | .TP | |
4294 | .B \-g \fIfile\fP | |
4295 | True if \fIfile\fP exists and is set-group-id. | |
4296 | .TP | |
b72432fd JA |
4297 | .B \-h \fIfile\fP |
4298 | True if \fIfile\fP exists and is a symbolic link. | |
4299 | .TP | |
cce855bc JA |
4300 | .B \-k \fIfile\fP |
4301 | True if \fIfile\fP exists and its ``sticky'' bit is set. | |
4302 | .TP | |
4303 | .B \-p \fIfile\fP | |
4304 | True if \fIfile\fP exists and is a named pipe (FIFO). | |
4305 | .TP | |
4306 | .B \-r \fIfile\fP | |
4307 | True if \fIfile\fP exists and is readable. | |
4308 | .TP | |
4309 | .B \-s \fIfile\fP | |
4310 | True if \fIfile\fP exists and has a size greater than zero. | |
4311 | .TP | |
4312 | .B \-t \fIfd\fP | |
4313 | True if file descriptor | |
4314 | .I fd | |
4315 | is open and refers to a terminal. | |
4316 | .TP | |
4317 | .B \-u \fIfile\fP | |
4318 | True if \fIfile\fP exists and its set-user-id bit is set. | |
4319 | .TP | |
4320 | .B \-w \fIfile\fP | |
4321 | True if \fIfile\fP exists and is writable. | |
4322 | .TP | |
4323 | .B \-x \fIfile\fP | |
4324 | True if \fIfile\fP exists and is executable. | |
4325 | .TP | |
cce855bc JA |
4326 | .B \-G \fIfile\fP |
4327 | True if \fIfile\fP exists and is owned by the effective group id. | |
4328 | .TP | |
4329 | .B \-L \fIfile\fP | |
4330 | True if \fIfile\fP exists and is a symbolic link. | |
4331 | .TP | |
5cdaaf76 CR |
4332 | .B \-N \fIfile\fP |
4333 | True if \fIfile\fP exists and has been modified since it was last read. | |
4334 | .TP | |
4335 | .B \-O \fIfile\fP | |
4336 | True if \fIfile\fP exists and is owned by the effective user id. | |
4337 | .TP | |
cce855bc JA |
4338 | .B \-S \fIfile\fP |
4339 | True if \fIfile\fP exists and is a socket. | |
4340 | .TP | |
5cdaaf76 CR |
4341 | \fIfile1\fP \fB\-ef\fP \fIfile2\fP |
4342 | True if \fIfile1\fP and \fIfile2\fP refer to the same device and | |
4343 | inode numbers. | |
cce855bc JA |
4344 | .TP |
4345 | \fIfile1\fP \-\fBnt\fP \fIfile2\fP | |
7117c2d2 JA |
4346 | True if \fIfile1\fP is newer (according to modification date) than \fIfile2\fP, |
4347 | or if \fIfile1\fP exists and \fPfile2\fP does not. | |
cce855bc JA |
4348 | .TP |
4349 | \fIfile1\fP \-\fBot\fP \fIfile2\fP | |
7117c2d2 JA |
4350 | True if \fIfile1\fP is older than \fIfile2\fP, or if \fIfile2\fP exists |
4351 | and \fIfile1\fP does not. | |
cce855bc | 4352 | .TP |
cce855bc | 4353 | .B \-o \fIoptname\fP |
6faad625 | 4354 | True if the shell option |
cce855bc JA |
4355 | .I optname |
4356 | is enabled. | |
4357 | See the list of options under the description of the | |
4358 | .B \-o | |
4359 | option to the | |
4360 | .B set | |
4361 | builtin below. | |
4362 | .TP | |
6faad625 CR |
4363 | .B \-v \fIvarname\fP |
4364 | True if the shell variable | |
4365 | .I varname | |
4366 | is set (has been assigned a value). | |
4367 | .TP | |
15623760 CR |
4368 | .B \-R \fIvarname\fP |
4369 | True if the shell variable | |
4370 | .I varname | |
4371 | is set and is a name reference. | |
4372 | .TP | |
cce855bc JA |
4373 | .B \-z \fIstring\fP |
4374 | True if the length of \fIstring\fP is zero. | |
4375 | .TP | |
cce855bc | 4376 | \fIstring\fP |
f085a21f CR |
4377 | .PD 0 |
4378 | .TP | |
4379 | .B \-n \fIstring\fP | |
4380 | .PD | |
cce855bc JA |
4381 | True if the length of |
4382 | .I string | |
4383 | is non-zero. | |
4384 | .TP | |
4385 | \fIstring1\fP \fB==\fP \fIstring2\fP | |
a3143574 CR |
4386 | .PD 0 |
4387 | .TP | |
4388 | \fIstring1\fP \fB=\fP \fIstring2\fP | |
4389 | .PD | |
4390 | True if the strings are equal. \fB=\fP should be used | |
4391 | with the \fBtest\fP command for POSIX conformance. | |
df0e4bfe CR |
4392 | When used with the \fB[[\fP command, this performs pattern matching as |
4393 | described above (\fBCompound Commands\fP). | |
cce855bc JA |
4394 | .TP |
4395 | \fIstring1\fP \fB!=\fP \fIstring2\fP | |
4396 | True if the strings are not equal. | |
4397 | .TP | |
4398 | \fIstring1\fP \fB<\fP \fIstring2\fP | |
0d8616ff | 4399 | True if \fIstring1\fP sorts before \fIstring2\fP lexicographically. |
cce855bc JA |
4400 | .TP |
4401 | \fIstring1\fP \fB>\fP \fIstring2\fP | |
0d8616ff | 4402 | True if \fIstring1\fP sorts after \fIstring2\fP lexicographically. |
cce855bc JA |
4403 | .TP |
4404 | .I \fIarg1\fP \fBOP\fP \fIarg2\fP | |
4405 | .SM | |
4406 | .B OP | |
4407 | is one of | |
4408 | .BR \-eq , | |
4409 | .BR \-ne , | |
4410 | .BR \-lt , | |
4411 | .BR \-le , | |
4412 | .BR \-gt , | |
4413 | or | |
4414 | .BR \-ge . | |
4415 | These arithmetic binary operators return true if \fIarg1\fP | |
4416 | is equal to, not equal to, less than, less than or equal to, | |
4417 | greater than, or greater than or equal to \fIarg2\fP, respectively. | |
4418 | .I Arg1 | |
4419 | and | |
4420 | .I arg2 | |
4421 | may be positive or negative integers. | |
4422 | .PD | |
4423 | .SH "SIMPLE COMMAND EXPANSION" | |
4424 | When a simple command is executed, the shell performs the following | |
4425 | expansions, assignments, and redirections, from left to right. | |
4426 | .IP 1. | |
4427 | The words that the parser has marked as variable assignments (those | |
4428 | preceding the command name) and redirections are saved for later | |
4429 | processing. | |
4430 | .IP 2. | |
4431 | The words that are not variable assignments or redirections are | |
4432 | expanded. If any words remain after expansion, the first word | |
4433 | is taken to be the name of the command and the remaining words are | |
4434 | the arguments. | |
4435 | .IP 3. | |
4436 | Redirections are performed as described above under | |
4437 | .SM | |
4438 | .BR REDIRECTION . | |
4439 | .IP 4. | |
4440 | The text after the \fB=\fP in each variable assignment undergoes tilde | |
4441 | expansion, parameter expansion, command substitution, arithmetic expansion, | |
4442 | and quote removal before being assigned to the variable. | |
4443 | .PP | |
4444 | If no command name results, the variable assignments affect the current | |
4445 | shell environment. Otherwise, the variables are added to the environment | |
4446 | of the executed command and do not affect the current shell environment. | |
4447 | If any of the assignments attempts to assign a value to a readonly variable, | |
4448 | an error occurs, and the command exits with a non-zero status. | |
4449 | .PP | |
4450 | If no command name results, redirections are performed, but do not | |
4451 | affect the current shell environment. A redirection error causes the | |
4452 | command to exit with a non-zero status. | |
4453 | .PP | |
4454 | If there is a command name left after expansion, execution proceeds as | |
4455 | described below. Otherwise, the command exits. If one of the expansions | |
4456 | contained a command substitution, the exit status of the command is | |
4457 | the exit status of the last command substitution performed. If there | |
4458 | were no command substitutions, the command exits with a status of zero. | |
4459 | .SH "COMMAND EXECUTION" | |
4460 | After a command has been split into words, if it results in a | |
4461 | simple command and an optional list of arguments, the following | |
4462 | actions are taken. | |
4463 | .PP | |
4464 | If the command name contains no slashes, the shell attempts to | |
4465 | locate it. If there exists a shell function by that name, that | |
4466 | function is invoked as described above in | |
4467 | .SM | |
4468 | .BR FUNCTIONS . | |
4469 | If the name does not match a function, the shell searches for | |
4470 | it in the list of shell builtins. If a match is found, that | |
4471 | builtin is invoked. | |
4472 | .PP | |
4473 | If the name is neither a shell function nor a builtin, | |
4474 | and contains no slashes, | |
4475 | .B bash | |
4476 | searches each element of the | |
4477 | .SM | |
4478 | .B PATH | |
4479 | for a directory containing an executable file by that name. | |
4480 | .B Bash | |
bb70624e | 4481 | uses a hash table to remember the full pathnames of executable |
cce855bc JA |
4482 | files (see |
4483 | .B hash | |
4484 | under | |
4485 | .SM | |
4486 | .B "SHELL BUILTIN COMMANDS" | |
4487 | below). | |
4488 | A full search of the directories in | |
4489 | .SM | |
4490 | .B PATH | |
4491 | is performed only if the command is not found in the hash table. | |
245a493c CR |
4492 | If the search is unsuccessful, the shell searches for a defined shell |
4493 | function named \fBcommand_not_found_handle\fP. | |
4494 | If that function exists, it is invoked with the original command and | |
4495 | the original command's arguments as its arguments, and the function's | |
4496 | exit status becomes the exit status of the shell. | |
4497 | If that function is not defined, the shell prints an error | |
cce855bc JA |
4498 | message and returns an exit status of 127. |
4499 | .PP | |
4500 | If the search is successful, or if the command name contains | |
4501 | one or more slashes, the shell executes the named program in a | |
4502 | separate execution environment. | |
4503 | Argument 0 is set to the name given, and the remaining arguments | |
4504 | to the command are set to the arguments given, if any. | |
4505 | .PP | |
4506 | If this execution fails because the file is not in executable | |
4507 | format, and the file is not a directory, it is assumed to be | |
4508 | a \fIshell script\fP, a file | |
4509 | containing shell commands. A subshell is spawned to execute | |
4510 | it. This subshell reinitializes itself, so | |
4511 | that the effect is as if a new shell had been invoked | |
4512 | to handle the script, with the exception that the locations of | |
4513 | commands remembered by the parent (see | |
4514 | .B hash | |
4515 | below under | |
4516 | .SM | |
4517 | \fBSHELL BUILTIN COMMANDS\fP) | |
4518 | are retained by the child. | |
4519 | .PP | |
4520 | If the program is a file beginning with | |
4521 | .BR #! , | |
4522 | the remainder of the first line specifies an interpreter | |
4523 | for the program. The shell executes the | |
4524 | specified interpreter on operating systems that do not | |
fc527055 | 4525 | handle this executable format themselves. The arguments to the |
cce855bc JA |
4526 | interpreter consist of a single optional argument following the |
4527 | interpreter name on the first line of the program, followed | |
4528 | by the name of the program, followed by the command | |
4529 | arguments, if any. | |
4530 | .SH COMMAND EXECUTION ENVIRONMENT | |
4531 | The shell has an \fIexecution environment\fP, which consists of the | |
4532 | following: | |
cce855bc JA |
4533 | .IP \(bu |
4534 | open files inherited by the shell at invocation, as modified by | |
4535 | redirections supplied to the \fBexec\fP builtin | |
4536 | .IP \(bu | |
4537 | the current working directory as set by \fBcd\fP, \fBpushd\fP, or | |
4538 | \fBpopd\fP, or inherited by the shell at invocation | |
4539 | .IP \(bu | |
4540 | the file creation mode mask as set by \fBumask\fP or inherited from | |
4541 | the shell's parent | |
4542 | .IP \(bu | |
4543 | current traps set by \fBtrap\fP | |
4544 | .IP \(bu | |
4545 | shell parameters that are set by variable assignment or with \fBset\fP | |
4546 | or inherited from the shell's parent in the environment | |
4547 | .IP \(bu | |
4548 | shell functions defined during execution or inherited from the shell's | |
4549 | parent in the environment | |
4550 | .IP \(bu | |
4551 | options enabled at invocation (either by default or with command-line | |
4552 | arguments) or by \fBset\fP | |
4553 | .IP \(bu | |
4554 | options enabled by \fBshopt\fP | |
4555 | .IP \(bu | |
4556 | shell aliases defined with \fBalias\fP | |
4557 | .IP \(bu | |
4558 | various process IDs, including those of background jobs, the value | |
984a1947 CR |
4559 | of \fB$$\fP, and the value of |
4560 | .SM | |
4561 | .B PPID | |
cce855bc JA |
4562 | .PP |
4563 | When a simple command other than a builtin or shell function | |
4564 | is to be executed, it | |
4565 | is invoked in a separate execution environment that consists of | |
4566 | the following. Unless otherwise noted, the values are inherited | |
4567 | from the shell. | |
984a1947 | 4568 | .if n .sp 1 |
cce855bc JA |
4569 | .IP \(bu |
4570 | the shell's open files, plus any modifications and additions specified | |
4571 | by redirections to the command | |
4572 | .IP \(bu | |
4573 | the current working directory | |
4574 | .IP \(bu | |
4575 | the file creation mode mask | |
4576 | .IP \(bu | |
d3a24ed2 CR |
4577 | shell variables and functions marked for export, along with variables |
4578 | exported for the command, passed in the environment | |
cce855bc | 4579 | .IP \(bu |
d3a24ed2 CR |
4580 | traps caught by the shell are reset to the values inherited from the |
4581 | shell's parent, and traps ignored by the shell are ignored | |
cce855bc JA |
4582 | .PP |
4583 | A command invoked in this separate environment cannot affect the | |
fc527055 | 4584 | shell's execution environment. |
cce855bc | 4585 | .PP |
d3a24ed2 CR |
4586 | Command substitution, commands grouped with parentheses, |
4587 | and asynchronous commands are invoked in a | |
cce855bc JA |
4588 | subshell environment that is a duplicate of the shell environment, |
4589 | except that traps caught by the shell are reset to the values | |
4590 | that the shell inherited from its parent at invocation. Builtin | |
4591 | commands that are invoked as part of a pipeline are also executed in a | |
4592 | subshell environment. Changes made to the subshell environment | |
4593 | cannot affect the shell's execution environment. | |
f73dda09 | 4594 | .PP |
012bac39 | 4595 | Subshells spawned to execute command substitutions inherit the value of |
dc60d4e0 CR |
4596 | the \fB\-e\fP option from the parent shell. When not in \fIposix\fP mode, |
4597 | \fBbash\fP clears the \fB\-e\fP option in such subshells. | |
012bac39 | 4598 | .PP |
f73dda09 JA |
4599 | If a command is followed by a \fB&\fP and job control is not active, the |
4600 | default standard input for the command is the empty file \fI/dev/null\fP. | |
4601 | Otherwise, the invoked command inherits the file descriptors of the calling | |
4602 | shell as modified by redirections. | |
cce855bc JA |
4603 | .SH ENVIRONMENT |
4604 | When a program is invoked it is given an array of strings | |
4605 | called the | |
4606 | .IR environment . | |
fc527055 | 4607 | This is a list of |
cce855bc JA |
4608 | \fIname\fP\-\fIvalue\fP pairs, of the form |
4609 | .IR "name\fR=\fPvalue" . | |
4610 | .PP | |
bb70624e JA |
4611 | The shell provides several ways to manipulate the environment. |
4612 | On invocation, the shell scans its own environment and | |
cce855bc JA |
4613 | creates a parameter for each name found, automatically marking |
4614 | it for | |
4615 | .I export | |
4616 | to child processes. Executed commands inherit the environment. | |
4617 | The | |
4618 | .B export | |
4619 | and | |
4620 | .B declare \-x | |
4621 | commands allow parameters and functions to be added to and | |
4622 | deleted from the environment. If the value of a parameter | |
4623 | in the environment is modified, the new value becomes part | |
4624 | of the environment, replacing the old. The environment | |
4625 | inherited by any executed command consists of the shell's | |
4626 | initial environment, whose values may be modified in the shell, | |
4627 | less any pairs removed by the | |
4628 | .B unset | |
4629 | command, plus any additions via the | |
4630 | .B export | |
4631 | and | |
4632 | .B declare \-x | |
4633 | commands. | |
4634 | .PP | |
4635 | The environment for any | |
4636 | .I simple command | |
4637 | or function may be augmented temporarily by prefixing it with | |
4638 | parameter assignments, as described above in | |
4639 | .SM | |
4640 | .BR PARAMETERS . | |
4641 | These assignment statements affect only the environment seen | |
4642 | by that command. | |
4643 | .PP | |
fc527055 | 4644 | If the |
cce855bc JA |
4645 | .B \-k |
4646 | option is set (see the | |
4647 | .B set | |
4648 | builtin command below), then | |
4649 | .I all | |
4650 | parameter assignments are placed in the environment for a command, | |
4651 | not just those that precede the command name. | |
4652 | .PP | |
4653 | When | |
4654 | .B bash | |
4655 | invokes an external command, the variable | |
4656 | .B _ | |
b28ff8c9 | 4657 | is set to the full filename of the command and passed to that |
ccc6cda3 JA |
4658 | command in its environment. |
4659 | .SH "EXIT STATUS" | |
35ee8ea0 CR |
4660 | .PP |
4661 | The exit status of an executed command is the value returned by the | |
4662 | \fIwaitpid\fP system call or equivalent function. Exit statuses | |
4663 | fall between 0 and 255, though, as explained below, the shell may | |
4664 | use values above 125 specially. Exit statuses from shell builtins and | |
fc527055 | 4665 | compound commands are also limited to this range. Under certain |
35ee8ea0 CR |
4666 | circumstances, the shell will use special values to indicate specific |
4667 | failure modes. | |
4668 | .PP | |
fc527055 | 4669 | For the shell's purposes, a command which exits with a |
ccc6cda3 JA |
4670 | zero exit status has succeeded. An exit status of zero |
4671 | indicates success. A non-zero exit status indicates failure. | |
bb70624e JA |
4672 | When a command terminates on a fatal signal \fIN\fP, \fBbash\fP uses |
4673 | the value of 128+\fIN\fP as the exit status. | |
ccc6cda3 JA |
4674 | .PP |
4675 | If a command is not found, the child process created to | |
4676 | execute it returns a status of 127. If a command is found | |
4677 | but is not executable, the return status is 126. | |
4678 | .PP | |
cce855bc JA |
4679 | If a command fails because of an error during expansion or redirection, |
4680 | the exit status is greater than zero. | |
4681 | .PP | |
ccc6cda3 JA |
4682 | Shell builtin commands return a status of 0 (\fItrue\fP) if |
4683 | successful, and non-zero (\fIfalse\fP) if an error occurs | |
fc527055 | 4684 | while they execute. |
f7958d04 CR |
4685 | All builtins return an exit status of 2 to indicate incorrect usage, |
4686 | generally invalid options or missing arguments. | |
ccc6cda3 JA |
4687 | .PP |
4688 | \fBBash\fP itself returns the exit status of the last command | |
4689 | executed, unless a syntax error occurs, in which case it exits | |
4690 | with a non-zero value. See also the \fBexit\fP builtin | |
4691 | command below. | |
4692 | .SH SIGNALS | |
cce855bc | 4693 | When \fBbash\fP is interactive, in the absence of any traps, it ignores |
ccc6cda3 JA |
4694 | .SM |
4695 | .B SIGTERM | |
4696 | (so that \fBkill 0\fP does not kill an interactive shell), | |
4697 | and | |
4698 | .SM | |
4699 | .B SIGINT | |
4700 | is caught and handled (so that the \fBwait\fP builtin is interruptible). | |
4701 | In all cases, \fBbash\fP ignores | |
4702 | .SM | |
4703 | .BR SIGQUIT . | |
4704 | If job control is in effect, | |
4705 | .B bash | |
4706 | ignores | |
4707 | .SM | |
4708 | .BR SIGTTIN , | |
4709 | .SM | |
4710 | .BR SIGTTOU , | |
4711 | and | |
4712 | .SM | |
4713 | .BR SIGTSTP . | |
4714 | .PP | |
5e13499c | 4715 | Non-builtin commands run by \fBbash\fP have signal handlers |
cce855bc JA |
4716 | set to the values inherited by the shell from its parent. |
4717 | When job control is not in effect, asynchronous commands | |
ccc6cda3 JA |
4718 | ignore |
4719 | .SM | |
4720 | .B SIGINT | |
4721 | and | |
4722 | .SM | |
cce855bc | 4723 | .B SIGQUIT |
5e13499c | 4724 | in addition to these inherited handlers. |
ccc6cda3 JA |
4725 | Commands run as a result of command substitution ignore the |
4726 | keyboard-generated job control signals | |
4727 | .SM | |
4728 | .BR SIGTTIN , | |
4729 | .SM | |
4730 | .BR SIGTTOU , | |
4731 | and | |
4732 | .SM | |
4733 | .BR SIGTSTP . | |
4734 | .PP | |
4735 | The shell exits by default upon receipt of a | |
4736 | .SM | |
4737 | .BR SIGHUP . | |
f73dda09 | 4738 | Before exiting, an interactive shell resends the |
ccc6cda3 JA |
4739 | .SM |
4740 | .B SIGHUP | |
cce855bc JA |
4741 | to all jobs, running or stopped. |
4742 | Stopped jobs are sent | |
4743 | .SM | |
4744 | .B SIGCONT | |
4745 | to ensure that they receive the | |
4746 | .SM | |
4747 | .BR SIGHUP . | |
4748 | To prevent the shell from | |
4749 | sending the signal to a particular job, it should be removed from the | |
fc527055 | 4750 | jobs table with the |
ccc6cda3 JA |
4751 | .B disown |
4752 | builtin (see | |
4753 | .SM | |
4754 | .B "SHELL BUILTIN COMMANDS" | |
fc527055 | 4755 | below) or marked |
cce855bc | 4756 | to not receive |
ccc6cda3 | 4757 | .SM |
cce855bc JA |
4758 | .B SIGHUP |
4759 | using | |
4760 | .BR "disown \-h" . | |
4761 | .PP | |
4762 | If the | |
4763 | .B huponexit | |
4764 | shell option has been set with | |
4765 | .BR shopt , | |
4766 | .B bash | |
fc527055 | 4767 | sends a |
cce855bc JA |
4768 | .SM |
4769 | .B SIGHUP | |
4770 | to all jobs when an interactive login shell exits. | |
4771 | .PP | |
b66cc816 | 4772 | If \fBbash\fP is waiting for a command to complete and receives a signal |
5e13499c | 4773 | for which a trap has been set, the trap will not be executed until |
fc527055 | 4774 | the command completes. |
cce855bc JA |
4775 | When \fBbash\fP is waiting for an asynchronous command via the \fBwait\fP |
4776 | builtin, the reception of a signal for which a trap has been set will | |
4777 | cause the \fBwait\fP builtin to return immediately with an exit status | |
4778 | greater than 128, immediately after which the trap is executed. | |
ccc6cda3 JA |
4779 | .SH "JOB CONTROL" |
4780 | .I Job control | |
4781 | refers to the ability to selectively stop (\fIsuspend\fP) | |
4782 | the execution of processes and continue (\fIresume\fP) | |
4783 | their execution at a later point. A user typically employs | |
4784 | this facility via an interactive interface supplied jointly | |
602bb739 | 4785 | by the operating system kernel's terminal driver and |
ccc6cda3 JA |
4786 | .BR bash . |
4787 | .PP | |
4788 | The shell associates a | |
4789 | .I job | |
4790 | with each pipeline. It keeps a table of currently executing | |
4791 | jobs, which may be listed with the | |
4792 | .B jobs | |
4793 | command. When | |
4794 | .B bash | |
4795 | starts a job asynchronously (in the | |
4796 | .IR background ), | |
4797 | it prints a line that looks like: | |
4798 | .RS | |
4799 | .PP | |
4800 | [1] 25647 | |
4801 | .RE | |
4802 | .PP | |
4803 | indicating that this job is job number 1 and that the process ID | |
4804 | of the last process in the pipeline associated with this job is 25647. | |
4805 | All of the processes in a single pipeline are members of the same job. | |
4806 | .B Bash | |
4807 | uses the | |
4808 | .I job | |
4809 | abstraction as the basis for job control. | |
4810 | .PP | |
4811 | To facilitate the implementation of the user interface to job | |
bb70624e | 4812 | control, the operating system maintains the notion of a \fIcurrent terminal |
ccc6cda3 JA |
4813 | process group ID\fP. Members of this process group (processes whose |
4814 | process group ID is equal to the current terminal process group ID) | |
4815 | receive keyboard-generated signals such as | |
4816 | .SM | |
4817 | .BR SIGINT . | |
4818 | These processes are said to be in the | |
4819 | .IR foreground . | |
4820 | .I Background | |
4821 | processes are those whose process group ID differs from the terminal's; | |
4822 | such processes are immune to keyboard-generated signals. | |
602bb739 CR |
4823 | Only foreground processes are allowed to read from or, if the |
4824 | user so specifies with \f(CWstty tostop\fP, write to the | |
4825 | terminal. | |
4826 | Background processes which attempt to read from (write to when | |
4827 | \f(CWstty tostop\fP is in effect) the | |
fc527055 | 4828 | terminal are sent a |
ccc6cda3 JA |
4829 | .SM |
4830 | .B SIGTTIN (SIGTTOU) | |
602bb739 | 4831 | signal by the kernel's terminal driver, |
ccc6cda3 JA |
4832 | which, unless caught, suspends the process. |
4833 | .PP | |
4834 | If the operating system on which | |
4835 | .B bash | |
4836 | is running supports | |
4837 | job control, | |
4838 | .B bash | |
bb70624e | 4839 | contains facilities to use it. |
ccc6cda3 JA |
4840 | Typing the |
4841 | .I suspend | |
4842 | character (typically | |
4843 | .BR ^Z , | |
4844 | Control-Z) while a process is running | |
fc527055 | 4845 | causes that process to be stopped and returns control to |
ccc6cda3 JA |
4846 | .BR bash . |
4847 | Typing the | |
4848 | .I "delayed suspend" | |
4849 | character (typically | |
4850 | .BR ^Y , | |
4851 | Control-Y) causes the process to be stopped when it | |
4852 | attempts to read input from the terminal, and control to | |
4853 | be returned to | |
4854 | .BR bash . | |
cce855bc | 4855 | The user may then manipulate the state of this job, using the |
ccc6cda3 JA |
4856 | .B bg |
4857 | command to continue it in the background, the | |
4858 | .B fg | |
4859 | command to continue it in the foreground, or | |
4860 | the | |
4861 | .B kill | |
4862 | command to kill it. A \fB^Z\fP takes effect immediately, | |
4863 | and has the additional side effect of causing pending output | |
4864 | and typeahead to be discarded. | |
4865 | .PP | |
4866 | There are a number of ways to refer to a job in the shell. | |
4867 | The character | |
4868 | .B % | |
8e1a6eaa | 4869 | introduces a job specification (\fIjobspec\fP). Job number |
ccc6cda3 JA |
4870 | .I n |
4871 | may be referred to as | |
4872 | .BR %n . | |
4873 | A job may also be referred to using a prefix of the name used to | |
4874 | start it, or using a substring that appears in its command line. | |
4875 | For example, | |
4876 | .B %ce | |
4877 | refers to a stopped | |
4878 | .B ce | |
4879 | job. If a prefix matches more than one job, | |
4880 | .B bash | |
4881 | reports an error. Using | |
4882 | .BR %?ce , | |
4883 | on the other hand, refers to any job containing the string | |
4884 | .B ce | |
4885 | in its command line. If the substring matches more than one job, | |
4886 | .B bash | |
4887 | reports an error. The symbols | |
4888 | .B %% | |
4889 | and | |
4890 | .B %+ | |
4891 | refer to the shell's notion of the | |
4892 | .IR "current job" , | |
4893 | which is the last job stopped while it was in | |
cce855bc | 4894 | the foreground or started in the background. |
fc527055 | 4895 | The |
ccc6cda3 JA |
4896 | .I "previous job" |
4897 | may be referenced using | |
4898 | .BR %\- . | |
e33f2203 CR |
4899 | If there is only a single job, \fB%+\fP and \fB%\-\fP can both be used |
4900 | to refer to that job. | |
ccc6cda3 JA |
4901 | In output pertaining to jobs (e.g., the output of the |
4902 | .B jobs | |
4903 | command), the current job is always flagged with a | |
4904 | .BR + , | |
4905 | and the previous job with a | |
4906 | .BR \- . | |
43df7bbb CR |
4907 | A single % (with no accompanying job specification) also refers to the |
4908 | current job. | |
726f6388 | 4909 | .PP |
ccc6cda3 JA |
4910 | Simply naming a job can be used to bring it into the |
4911 | foreground: | |
4912 | .B %1 | |
4913 | is a synonym for | |
4914 | \fB``fg %1''\fP, | |
4915 | bringing job 1 from the background into the foreground. | |
4916 | Similarly, | |
4917 | .B ``%1 &'' | |
4918 | resumes job 1 in the background, equivalent to | |
4919 | \fB``bg %1''\fP. | |
726f6388 | 4920 | .PP |
ccc6cda3 JA |
4921 | The shell learns immediately whenever a job changes state. |
4922 | Normally, | |
4923 | .B bash | |
4924 | waits until it is about to print a prompt before reporting | |
4925 | changes in a job's status so as to not interrupt | |
fc527055 | 4926 | any other output. If the |
ccc6cda3 JA |
4927 | .B \-b |
4928 | option to the | |
726f6388 | 4929 | .B set |
ccc6cda3 | 4930 | builtin command |
cce855bc | 4931 | is enabled, |
726f6388 | 4932 | .B bash |
ccc6cda3 | 4933 | reports such changes immediately. |
f73dda09 JA |
4934 | Any trap on |
4935 | .SM | |
4936 | .B SIGCHLD | |
4937 | is executed for each child that exits. | |
726f6388 | 4938 | .PP |
ccc6cda3 JA |
4939 | If an attempt to exit |
4940 | .B bash | |
d3ad40de CR |
4941 | is made while jobs are stopped (or, if the \fBcheckjobs\fP shell option has |
4942 | been enabled using the \fBshopt\fP builtin, running), the shell prints a | |
4943 | warning message, and, if the \fBcheckjobs\fP option is enabled, lists the | |
4944 | jobs and their statuses. | |
4945 | The | |
ccc6cda3 | 4946 | .B jobs |
fc527055 | 4947 | command may then be used to inspect their status. |
ccc6cda3 | 4948 | If a second attempt to exit is made without an intervening command, |
d3ad40de | 4949 | the shell does not print another warning, and any stopped |
ccc6cda3 | 4950 | jobs are terminated. |
726f6388 | 4951 | .SH PROMPTING |
fc527055 | 4952 | When executing interactively, |
726f6388 JA |
4953 | .B bash |
4954 | displays the primary prompt | |
4955 | .SM | |
4956 | .B PS1 | |
4957 | when it is ready to read a command, and the secondary prompt | |
4958 | .SM | |
4959 | .B PS2 | |
4960 | when it needs more input to complete a command. | |
4961 | .B Bash | |
4962 | allows these prompt strings to be customized by inserting a number of | |
4963 | backslash-escaped special characters that are decoded as follows: | |
4964 | .RS | |
4965 | .PD 0 | |
4966 | .TP | |
ccc6cda3 JA |
4967 | .B \ea |
4968 | an ASCII bell character (07) | |
726f6388 JA |
4969 | .TP |
4970 | .B \ed | |
4971 | the date in "Weekday Month Date" format (e.g., "Tue May 26") | |
4972 | .TP | |
7117c2d2 JA |
4973 | .B \eD{\fIformat\fP} |
4974 | the \fIformat\fP is passed to \fIstrftime\fP(3) and the result is inserted | |
4975 | into the prompt string; an empty \fIformat\fP results in a locale-specific | |
4976 | time representation. The braces are required | |
4977 | .TP | |
ccc6cda3 JA |
4978 | .B \ee |
4979 | an ASCII escape character (033) | |
4980 | .TP | |
4981 | .B \eh | |
4982 | the hostname up to the first `.' | |
4983 | .TP | |
4984 | .B \eH | |
4985 | the hostname | |
4986 | .TP | |
bb70624e JA |
4987 | .B \ej |
4988 | the number of jobs currently managed by the shell | |
4989 | .TP | |
4990 | .B \el | |
4991 | the basename of the shell's terminal device name | |
4992 | .TP | |
726f6388 JA |
4993 | .B \en |
4994 | newline | |
4995 | .TP | |
cce855bc JA |
4996 | .B \er |
4997 | carriage return | |
4998 | .TP | |
726f6388 JA |
4999 | .B \es |
5000 | the name of the shell, the basename of | |
5001 | .B $0 | |
5002 | (the portion following the final slash) | |
5003 | .TP | |
ccc6cda3 JA |
5004 | .B \et |
5005 | the current time in 24-hour HH:MM:SS format | |
726f6388 | 5006 | .TP |
ccc6cda3 JA |
5007 | .B \eT |
5008 | the current time in 12-hour HH:MM:SS format | |
5009 | .TP | |
5010 | .B \e@ | |
5011 | the current time in 12-hour am/pm format | |
726f6388 | 5012 | .TP |
f73dda09 JA |
5013 | .B \eA |
5014 | the current time in 24-hour HH:MM format | |
5015 | .TP | |
726f6388 JA |
5016 | .B \eu |
5017 | the username of the current user | |
5018 | .TP | |
ccc6cda3 JA |
5019 | .B \ev |
5020 | the version of \fBbash\fP (e.g., 2.00) | |
726f6388 | 5021 | .TP |
ccc6cda3 | 5022 | .B \eV |
a5e25162 | 5023 | the release of \fBbash\fP, version + patch level (e.g., 2.00.0) |
ccc6cda3 JA |
5024 | .TP |
5025 | .B \ew | |
984a1947 CR |
5026 | the current working directory, with |
5027 | .SM | |
5028 | .B $HOME | |
5029 | abbreviated with a tilde | |
5030 | (uses the value of the | |
5031 | .SM | |
5032 | .B PROMPT_DIRTRIM | |
5033 | variable) | |
ccc6cda3 JA |
5034 | .TP |
5035 | .B \eW | |
984a1947 CR |
5036 | the basename of the current working directory, with |
5037 | .SM | |
5038 | .B $HOME | |
12d937f9 | 5039 | abbreviated with a tilde |
726f6388 JA |
5040 | .TP |
5041 | .B \e! | |
5042 | the history number of this command | |
5043 | .TP | |
ccc6cda3 JA |
5044 | .B \e# |
5045 | the command number of this command | |
5046 | .TP | |
726f6388 JA |
5047 | .B \e$ |
5048 | if the effective UID is 0, a | |
5049 | .BR # , | |
5050 | otherwise a | |
5051 | .B $ | |
5052 | .TP | |
ccc6cda3 JA |
5053 | .B \e\fInnn\fP |
5054 | the character corresponding to the octal number \fInnn\fP | |
726f6388 JA |
5055 | .TP |
5056 | .B \e\e | |
5057 | a backslash | |
5058 | .TP | |
5059 | .B \e[ | |
5060 | begin a sequence of non-printing characters, which could be used to | |
5061 | embed a terminal control sequence into the prompt | |
5062 | .TP | |
5063 | .B \e] | |
5064 | end a sequence of non-printing characters | |
5065 | .PD | |
5066 | .RE | |
5067 | .PP | |
5068 | The command number and the history number are usually different: | |
5069 | the history number of a command is its position in the history | |
5070 | list, which may include commands restored from the history file | |
5071 | (see | |
5072 | .SM | |
5073 | .B HISTORY | |
5074 | below), while the command number is the position in the sequence | |
5075 | of commands executed during the current shell session. | |
5076 | After the string is decoded, it is expanded via | |
bb70624e JA |
5077 | parameter expansion, command substitution, arithmetic |
5078 | expansion, and quote removal, subject to the value of the | |
ccc6cda3 JA |
5079 | .B promptvars |
5080 | shell option (see the description of the | |
5081 | .B shopt | |
5082 | command under | |
5083 | .SM | |
5084 | .B "SHELL BUILTIN COMMANDS" | |
5085 | below). | |
726f6388 JA |
5086 | .SH READLINE |
5087 | This is the library that handles reading input when using an interactive | |
5088 | shell, unless the | |
d166f048 | 5089 | .B \-\-noediting |
ccc6cda3 | 5090 | option is given at shell invocation. |
14e8b2a7 CR |
5091 | Line editing is also used when using the \fB\-e\fP option to the |
5092 | \fBread\fP builtin. | |
dc60d4e0 | 5093 | By default, the line editing commands are similar to those of Emacs. |
726f6388 | 5094 | A vi-style line editing interface is also available. |
14e8b2a7 CR |
5095 | Line editing can be enabled at any time using the |
5096 | .B \-o emacs | |
ccc6cda3 | 5097 | or |
14e8b2a7 | 5098 | .B \-o vi |
ccc6cda3 JA |
5099 | options to the |
5100 | .B set | |
5101 | builtin (see | |
5102 | .SM | |
5103 | .B SHELL BUILTIN COMMANDS | |
5104 | below). | |
14e8b2a7 CR |
5105 | To turn off line editing after the shell is running, use the |
5106 | .B +o emacs | |
5107 | or | |
5108 | .B +o vi | |
5109 | options to the | |
5110 | .B set | |
5111 | builtin. | |
ccc6cda3 | 5112 | .SS "Readline Notation" |
726f6388 | 5113 | .PP |
dc60d4e0 | 5114 | In this section, the Emacs-style notation is used to denote |
726f6388 | 5115 | keystrokes. Control keys are denoted by C\-\fIkey\fR, e.g., C\-n |
fc527055 | 5116 | means Control\-N. Similarly, |
726f6388 JA |
5117 | .I meta |
5118 | keys are denoted by M\-\fIkey\fR, so M\-x means Meta\-X. (On keyboards | |
fc527055 | 5119 | without a |
726f6388 JA |
5120 | .I meta |
5121 | key, M\-\fIx\fP means ESC \fIx\fP, i.e., press the Escape key | |
5122 | then the | |
5123 | .I x | |
5124 | key. This makes ESC the \fImeta prefix\fP. | |
5125 | The combination M\-C\-\fIx\fP means ESC\-Control\-\fIx\fP, | |
5126 | or press the Escape key | |
5127 | then hold the Control key while pressing the | |
5128 | .I x | |
5129 | key.) | |
5130 | .PP | |
ccc6cda3 JA |
5131 | Readline commands may be given numeric |
5132 | .IR arguments , | |
5133 | which normally act as a repeat count. | |
5134 | Sometimes, however, it is the sign of the argument that is significant. | |
5135 | Passing a negative argument to a command that acts in the forward | |
5136 | direction (e.g., \fBkill\-line\fP) causes that command to act in a | |
fc527055 | 5137 | backward direction. |
ccc6cda3 JA |
5138 | Commands whose behavior with arguments deviates from this are noted |
5139 | below. | |
5140 | .PP | |
5141 | When a command is described as \fIkilling\fP text, the text | |
5142 | deleted is saved for possible future retrieval | |
5143 | (\fIyanking\fP). The killed text is saved in a | |
5144 | \fIkill ring\fP. Consecutive kills cause the text to be | |
fc527055 | 5145 | accumulated into one unit, which can be yanked all at once. |
ccc6cda3 JA |
5146 | Commands which do not kill text separate the chunks of text |
5147 | on the kill ring. | |
5148 | .SS "Readline Initialization" | |
5149 | .PP | |
5150 | Readline is customized by putting commands in an initialization | |
5151 | file (the \fIinputrc\fP file). | |
5152 | The name of this file is taken from the value of the | |
726f6388 | 5153 | .SM |
ccc6cda3 JA |
5154 | .B INPUTRC |
5155 | variable. If that variable is unset, the default is | |
726f6388 | 5156 | .IR ~/.inputrc . |
ccc6cda3 JA |
5157 | When a program which uses the readline library starts up, the |
5158 | initialization file is read, and the key bindings and variables | |
5159 | are set. | |
5160 | There are only a few basic constructs allowed in the | |
5161 | readline initialization file. | |
5162 | Blank lines are ignored. | |
5163 | Lines beginning with a \fB#\fP are comments. | |
5164 | Lines beginning with a \fB$\fP indicate conditional constructs. | |
5165 | Other lines denote key bindings and variable settings. | |
5166 | .PP | |
5167 | The default key-bindings may be changed with an | |
fc527055 | 5168 | .I inputrc |
ccc6cda3 | 5169 | file. |
726f6388 JA |
5170 | Other programs that use this library may add their own commands |
5171 | and bindings. | |
5172 | .PP | |
5173 | For example, placing | |
5174 | .RS | |
5175 | .PP | |
5176 | M\-Control\-u: universal\-argument | |
5177 | .RE | |
5178 | or | |
5179 | .RS | |
5180 | C\-Meta\-u: universal\-argument | |
5181 | .RE | |
fc527055 | 5182 | into the |
ccc6cda3 | 5183 | .I inputrc |
726f6388 JA |
5184 | would make M\-C\-u execute the readline command |
5185 | .IR universal\-argument . | |
5186 | .PP | |
5187 | The following symbolic character names are recognized: | |
5188 | .IR RUBOUT , | |
5189 | .IR DEL , | |
5190 | .IR ESC , | |
5191 | .IR LFD , | |
5192 | .IR NEWLINE , | |
5193 | .IR RET , | |
5194 | .IR RETURN , | |
5195 | .IR SPC , | |
5196 | .IR SPACE , | |
5197 | and | |
5198 | .IR TAB . | |
bb70624e | 5199 | .PP |
726f6388 JA |
5200 | In addition to command names, readline allows keys to be bound |
5201 | to a string that is inserted when the key is pressed (a \fImacro\fP). | |
ccc6cda3 | 5202 | .SS "Readline Key Bindings" |
726f6388 JA |
5203 | .PP |
5204 | The syntax for controlling key bindings in the | |
cce855bc | 5205 | .I inputrc |
726f6388 JA |
5206 | file is simple. All that is required is the name of the |
5207 | command or the text of a macro and a key sequence to which | |
fc527055 | 5208 | it should be bound. The name may be specified in one of two ways: |
ccc6cda3 | 5209 | as a symbolic key name, possibly with \fIMeta\-\fP or \fIControl\-\fP |
726f6388 | 5210 | prefixes, or as a key sequence. |
28ef6c31 | 5211 | .PP |
cce855bc | 5212 | When using the form \fBkeyname\fP:\^\fIfunction\-name\fP or \fImacro\fP, |
726f6388 JA |
5213 | .I keyname |
5214 | is the name of a key spelled out in English. For example: | |
5215 | .sp | |
5216 | .RS | |
5217 | Control-u: universal\-argument | |
5218 | .br | |
5219 | Meta-Rubout: backward-kill-word | |
5220 | .br | |
ccc6cda3 | 5221 | Control-o: "> output" |
726f6388 JA |
5222 | .RE |
5223 | .LP | |
5224 | In the above example, | |
ccc6cda3 | 5225 | .I C\-u |
726f6388 JA |
5226 | is bound to the function |
5227 | .BR universal\-argument , | |
ccc6cda3 | 5228 | .I M\-DEL |
726f6388 JA |
5229 | is bound to the function |
5230 | .BR backward\-kill\-word , | |
5231 | and | |
ccc6cda3 | 5232 | .I C\-o |
726f6388 JA |
5233 | is bound to run the macro |
5234 | expressed on the right hand side (that is, to insert the text | |
28ef6c31 JA |
5235 | .if t \f(CW> output\fP |
5236 | .if n ``> output'' | |
726f6388 JA |
5237 | into the line). |
5238 | .PP | |
cce855bc | 5239 | In the second form, \fB"keyseq"\fP:\^\fIfunction\-name\fP or \fImacro\fP, |
726f6388 JA |
5240 | .B keyseq |
5241 | differs from | |
5242 | .B keyname | |
5243 | above in that strings denoting | |
5244 | an entire key sequence may be specified by placing the sequence | |
5245 | within double quotes. Some GNU Emacs style key escapes can be | |
28ef6c31 JA |
5246 | used, as in the following example, but the symbolic character names |
5247 | are not recognized. | |
726f6388 JA |
5248 | .sp |
5249 | .RS | |
ccc6cda3 | 5250 | "\eC\-u": universal\-argument |
726f6388 | 5251 | .br |
ccc6cda3 | 5252 | "\eC\-x\eC\-r": re\-read\-init\-file |
726f6388 JA |
5253 | .br |
5254 | "\ee[11~": "Function Key 1" | |
5255 | .RE | |
5256 | .PP | |
5257 | In this example, | |
ccc6cda3 | 5258 | .I C\-u |
726f6388 JA |
5259 | is again bound to the function |
5260 | .BR universal\-argument . | |
ccc6cda3 | 5261 | .I "C\-x C\-r" |
726f6388 JA |
5262 | is bound to the function |
5263 | .BR re\-read\-init\-file , | |
fc527055 | 5264 | and |
726f6388 JA |
5265 | .I "ESC [ 1 1 ~" |
5266 | is bound to insert the text | |
28ef6c31 JA |
5267 | .if t \f(CWFunction Key 1\fP. |
5268 | .if n ``Function Key 1''. | |
5269 | .PP | |
cce855bc | 5270 | The full set of GNU Emacs style escape sequences is |
726f6388 | 5271 | .RS |
cce855bc | 5272 | .PD 0 |
726f6388 JA |
5273 | .TP |
5274 | .B \eC\- | |
5275 | control prefix | |
5276 | .TP | |
ccc6cda3 | 5277 | .B \eM\- |
726f6388 JA |
5278 | meta prefix |
5279 | .TP | |
5280 | .B \ee | |
5281 | an escape character | |
5282 | .TP | |
5283 | .B \e\e | |
5284 | backslash | |
5285 | .TP | |
5286 | .B \e" | |
5287 | literal " | |
5288 | .TP | |
20587658 CR |
5289 | .B \e\(aq |
5290 | literal \(aq | |
726f6388 | 5291 | .RE |
cce855bc JA |
5292 | .PD |
5293 | .PP | |
5294 | In addition to the GNU Emacs style escape sequences, a second | |
5295 | set of backslash escapes is available: | |
5296 | .RS | |
5297 | .PD 0 | |
5298 | .TP | |
5299 | .B \ea | |
5300 | alert (bell) | |
5301 | .TP | |
5302 | .B \eb | |
5303 | backspace | |
5304 | .TP | |
5305 | .B \ed | |
5306 | delete | |
5307 | .TP | |
5308 | .B \ef | |
5309 | form feed | |
5310 | .TP | |
5311 | .B \en | |
5312 | newline | |
5313 | .TP | |
5314 | .B \er | |
5315 | carriage return | |
5316 | .TP | |
5317 | .B \et | |
5318 | horizontal tab | |
5319 | .TP | |
5320 | .B \ev | |
5321 | vertical tab | |
5322 | .TP | |
5323 | .B \e\fInnn\fP | |
f73dda09 | 5324 | the eight-bit character whose value is the octal value \fInnn\fP |
cce855bc JA |
5325 | (one to three digits) |
5326 | .TP | |
f73dda09 JA |
5327 | .B \ex\fIHH\fP |
5328 | the eight-bit character whose value is the hexadecimal value \fIHH\fP | |
5329 | (one or two hex digits) | |
cce855bc JA |
5330 | .RE |
5331 | .PD | |
726f6388 | 5332 | .PP |
cce855bc JA |
5333 | When entering the text of a macro, single or double quotes must |
5334 | be used to indicate a macro definition. | |
5335 | Unquoted text is assumed to be a function name. | |
5336 | In the macro body, the backslash escapes described above are expanded. | |
5337 | Backslash will quote any other character in the macro text, | |
20587658 | 5338 | including " and \(aq. |
726f6388 JA |
5339 | .PP |
5340 | .B Bash | |
5341 | allows the current readline key bindings to be displayed or modified | |
5342 | with the | |
5343 | .B bind | |
5344 | builtin command. The editing mode may be switched during interactive | |
5345 | use by using the | |
5346 | .B \-o | |
5347 | option to the | |
5348 | .B set | |
5349 | builtin command (see | |
5350 | .SM | |
5351 | .B SHELL BUILTIN COMMANDS | |
5352 | below). | |
ccc6cda3 | 5353 | .SS "Readline Variables" |
726f6388 JA |
5354 | .PP |
5355 | Readline has variables that can be used to further customize its | |
5356 | behavior. A variable may be set in the | |
5357 | .I inputrc | |
5358 | file with a statement of the form | |
5359 | .RS | |
5360 | .PP | |
5361 | \fBset\fP \fIvariable\-name\fP \fIvalue\fP | |
5362 | .RE | |
5363 | .PP | |
5364 | Except where noted, readline variables can take the values | |
5365 | .B On | |
5366 | or | |
ff247e74 CR |
5367 | .B Off |
5368 | (without regard to case). | |
5369 | Unrecognized variable names are ignored. | |
5370 | When a variable value is read, empty or null values, "on" (case-insensitive), | |
5371 | and "1" are equivalent to \fBOn\fP. All other values are equivalent to | |
5372 | \fBOff\fP. | |
726f6388 JA |
5373 | The variables and their default values are: |
5374 | .PP | |
5375 | .PD 0 | |
5376 | .TP | |
726f6388 JA |
5377 | .B bell\-style (audible) |
5378 | Controls what happens when readline wants to ring the terminal bell. | |
5379 | If set to \fBnone\fP, readline never rings the bell. If set to | |
5380 | \fBvisible\fP, readline uses a visible bell if one is available. | |
5381 | If set to \fBaudible\fP, readline attempts to ring the terminal's bell. | |
5382 | .TP | |
453f278a CR |
5383 | .B bind\-tty\-special\-chars (On) |
5384 | If set to \fBOn\fP, readline attempts to bind the control characters | |
5385 | treated specially by the kernel's terminal driver to their readline | |
5386 | equivalents. | |
5387 | .TP | |
0a233f3e CR |
5388 | .B colored\-completion\-prefix (Off) |
5389 | If set to \fBOn\fP, when listing completions, readline displays the | |
5390 | common prefix of the set of possible completions using a different color. | |
5391 | The color definitions are taken from the value of the \fBLS_COLORS\fP | |
5392 | environment variable. | |
5393 | .TP | |
5a318736 CR |
5394 | .B colored\-stats (Off) |
5395 | If set to \fBOn\fP, readline displays possible completions using different | |
fc527055 | 5396 | colors to indicate their file type. |
5a318736 CR |
5397 | The color definitions are taken from the value of the \fBLS_COLORS\fP |
5398 | environment variable. | |
5399 | .TP | |
726f6388 | 5400 | .B comment\-begin (``#'') |
bb70624e | 5401 | The string that is inserted when the readline |
ccc6cda3 | 5402 | .B insert\-comment |
726f6388 | 5403 | command is executed. |
ccc6cda3 JA |
5404 | This command is bound to |
5405 | .B M\-# | |
5406 | in emacs mode and to | |
5407 | .B # | |
5408 | in vi command mode. | |
726f6388 | 5409 | .TP |
cce855bc JA |
5410 | .B completion\-ignore\-case (Off) |
5411 | If set to \fBOn\fP, readline performs filename matching and completion | |
5412 | in a case\-insensitive fashion. | |
5413 | .TP | |
f13513ff CR |
5414 | .B completion\-prefix\-display\-length (0) |
5415 | The length in characters of the common prefix of a list of possible | |
5416 | completions that is displayed without modification. When set to a | |
5417 | value greater than zero, common prefixes longer than this value are | |
5418 | replaced with an ellipsis when displaying possible completions. | |
5419 | .TP | |
726f6388 JA |
5420 | .B completion\-query\-items (100) |
5421 | This determines when the user is queried about viewing | |
5422 | the number of possible completions | |
5423 | generated by the \fBpossible\-completions\fP command. | |
5424 | It may be set to any integer value greater than or equal to | |
5425 | zero. If the number of possible completions is greater than | |
5426 | or equal to the value of this variable, the user is asked whether | |
5427 | or not he wishes to view them; otherwise they are simply listed | |
5428 | on the terminal. | |
5429 | .TP | |
ccc6cda3 JA |
5430 | .B convert\-meta (On) |
5431 | If set to \fBOn\fP, readline will convert characters with the | |
5432 | eighth bit set to an ASCII key sequence | |
bb70624e | 5433 | by stripping the eighth bit and prefixing an |
ccc6cda3 JA |
5434 | escape character (in effect, using escape as the \fImeta prefix\fP). |
5435 | .TP | |
5436 | .B disable\-completion (Off) | |
5437 | If set to \fBOn\fP, readline will inhibit word completion. Completion | |
5438 | characters will be inserted into the line as if they had been | |
5439 | mapped to \fBself-insert\fP. | |
5440 | .TP | |
5441 | .B editing\-mode (emacs) | |
5442 | Controls whether readline begins with a set of key bindings similar | |
dc60d4e0 | 5443 | to \fIEmacs\fP or \fIvi\fP. |
ccc6cda3 JA |
5444 | .B editing\-mode |
5445 | can be set to either | |
5446 | .B emacs | |
5447 | or | |
5448 | .BR vi . | |
5449 | .TP | |
824dfe68 CR |
5450 | .B echo\-control\-characters (On) |
5451 | When set to \fBOn\fP, on operating systems that indicate they support it, | |
5452 | readline echoes a character corresponding to a signal generated from the | |
5453 | keyboard. | |
5454 | .TP | |
0a233f3e CR |
5455 | .B enable\-bracketed\-paste (Off) |
5456 | When set to \fBOn\fP, readline will configure the terminal in a way | |
5457 | that will enable it to insert each paste into the editing buffer as a | |
5458 | single string of characters, instead of treating each character as if | |
5459 | it had been read from the keyboard. This can prevent pasted characters | |
5460 | from being interpreted as editing commands. | |
5461 | .TP | |
ccc6cda3 JA |
5462 | .B enable\-keypad (Off) |
5463 | When set to \fBOn\fP, readline will try to enable the application | |
5464 | keypad when it is called. Some systems need this to enable the | |
5465 | arrow keys. | |
5466 | .TP | |
08e72d7a CR |
5467 | .B enable\-meta\-key (On) |
5468 | When set to \fBOn\fP, readline will try to enable any meta modifier | |
5469 | key the terminal claims to support when it is called. On many terminals, | |
5470 | the meta key is used to send eight-bit characters. | |
5471 | .TP | |
ccc6cda3 | 5472 | .B expand\-tilde (Off) |
dc60d4e0 | 5473 | If set to \fBOn\fP, tilde expansion is performed when readline |
ccc6cda3 JA |
5474 | attempts word completion. |
5475 | .TP | |
cdb32d45 | 5476 | .B history\-preserve\-point (Off) |
dc60d4e0 | 5477 | If set to \fBOn\fP, the history code attempts to place point at the |
f75912ae | 5478 | same location on each history line retrieved with \fBprevious-history\fP |
f73dda09 JA |
5479 | or \fBnext-history\fP. |
5480 | .TP | |
b4a00022 | 5481 | .B history\-size (unset) |
0500de0b CR |
5482 | Set the maximum number of history entries saved in the history list. |
5483 | If set to zero, any existing history entries are deleted and no new entries | |
5484 | are saved. | |
5485 | If set to a value less than zero, the number of history entries is not | |
5486 | limited. | |
5487 | By default, the number of history entries is not limited. | |
1d0e1a34 | 5488 | .TP |
ccc6cda3 JA |
5489 | .B horizontal\-scroll\-mode (Off) |
5490 | When set to \fBOn\fP, makes readline use a single line for display, | |
5491 | scrolling the input horizontally on a single screen line when it | |
5492 | becomes longer than the screen width rather than wrapping to a new line. | |
5493 | .TP | |
5494 | .B input\-meta (Off) | |
5495 | If set to \fBOn\fP, readline will enable eight-bit input (that is, | |
5496 | it will not strip the high bit from the characters it reads), | |
5497 | regardless of what the terminal claims it can support. The name | |
5498 | .B meta\-flag | |
5499 | is a synonym for this variable. | |
5500 | .TP | |
b72432fd JA |
5501 | .B isearch\-terminators (``C\-[C\-J'') |
5502 | The string of characters that should terminate an incremental | |
5503 | search without subsequently executing the character as a command. | |
5504 | If this variable has not been given a value, the characters | |
5505 | \fIESC\fP and \fIC\-J\fP will terminate an incremental search. | |
5506 | .TP | |
726f6388 | 5507 | .B keymap (emacs) |
cce855bc | 5508 | Set the current readline keymap. The set of valid keymap names is |
ccc6cda3 JA |
5509 | \fIemacs, emacs\-standard, emacs\-meta, emacs\-ctlx, vi, |
5510 | vi\-command\fP, and | |
5511 | .IR vi\-insert . | |
5512 | \fIvi\fP is equivalent to \fIvi\-command\fP; \fIemacs\fP is | |
5513 | equivalent to \fIemacs\-standard\fP. The default value is | |
726f6388 JA |
5514 | .IR emacs ; |
5515 | the value of | |
5516 | .B editing\-mode | |
5517 | also affects the default keymap. | |
5518 | .TP | |
0a233f3e CR |
5519 | .B emacs\-mode\-string (@) |
5520 | This string is displayed immediately before the last line of the primary | |
5521 | prompt when emacs editing mode is active. The value is expanded like a | |
5522 | key binding, so the standard set of meta- and control prefixes and | |
5523 | backslash escape sequences is available. | |
5524 | Use the \e1 and \e2 escapes to begin and end sequences of | |
5525 | non-printing characters, which can be used to embed a terminal control | |
5526 | sequence into the mode string. | |
5527 | .TP | |
abe2eb5b CR |
5528 | .B keyseq\-timeout (500) |
5529 | Specifies the duration \fIreadline\fP will wait for a character when reading an | |
5530 | ambiguous key sequence (one that can form a complete key sequence using | |
5531 | the input read so far, or can take additional input to complete a longer | |
5532 | key sequence). | |
5533 | If no input is received within the timeout, \fIreadline\fP will use the shorter | |
5534 | but complete key sequence. | |
5535 | The value is specified in milliseconds, so a value of 1000 means that | |
5536 | \fIreadline\fP will wait one second for additional input. | |
5537 | If this variable is set to a value less than or equal to zero, or to a | |
5538 | non-numeric value, \fIreadline\fP will wait until another key is pressed to | |
5539 | decide which key sequence to complete. | |
5540 | .TP | |
ccc6cda3 JA |
5541 | .B mark\-directories (On) |
5542 | If set to \fBOn\fP, completed directory names have a slash | |
5543 | appended. | |
5544 | .TP | |
5545 | .B mark\-modified\-lines (Off) | |
5546 | If set to \fBOn\fP, history lines that have been modified are displayed | |
5547 | with a preceding asterisk (\fB*\fP). | |
5548 | .TP | |
7117c2d2 JA |
5549 | .B mark\-symlinked\-directories (Off) |
5550 | If set to \fBOn\fP, completed names which are symbolic links to directories | |
5551 | have a slash appended (subject to the value of | |
5552 | \fBmark\-directories\fP). | |
5553 | .TP | |
f73dda09 JA |
5554 | .B match\-hidden\-files (On) |
5555 | This variable, when set to \fBOn\fP, causes readline to match files whose | |
fc527055 | 5556 | names begin with a `.' (hidden files) when performing filename |
112ff2a6 CR |
5557 | completion. |
5558 | If set to \fBOff\fP, the leading `.' must be | |
f73dda09 JA |
5559 | supplied by the user in the filename to be completed. |
5560 | .TP | |
d7c725b5 CR |
5561 | .B menu\-complete\-display\-prefix (Off) |
5562 | If set to \fBOn\fP, menu completion displays the common prefix of the | |
5563 | list of possible completions (which may be empty) before cycling through | |
5564 | the list. | |
5565 | .TP | |
ccc6cda3 JA |
5566 | .B output\-meta (Off) |
5567 | If set to \fBOn\fP, readline will display characters with the | |
5568 | eighth bit set directly rather than as a meta-prefixed escape | |
5569 | sequence. | |
5570 | .TP | |
7117c2d2 JA |
5571 | .B page\-completions (On) |
5572 | If set to \fBOn\fP, readline uses an internal \fImore\fP-like pager | |
5573 | to display a screenful of possible completions at a time. | |
5574 | .TP | |
cce855bc JA |
5575 | .B print\-completions\-horizontally (Off) |
5576 | If set to \fBOn\fP, readline will display completions with matches | |
5577 | sorted horizontally in alphabetical order, rather than down the screen. | |
fc527055 | 5578 | .TP |
f13513ff | 5579 | .B revert\-all\-at\-newline (Off) |
fc527055 | 5580 | If set to \fBOn\fP, readline will undo all changes to history lines |
f13513ff CR |
5581 | before returning when \fBaccept\-line\fP is executed. By default, |
5582 | history lines may be modified and retain individual undo lists across | |
5583 | calls to \fBreadline\fP. | |
cce855bc | 5584 | .TP |
726f6388 JA |
5585 | .B show\-all\-if\-ambiguous (Off) |
5586 | This alters the default behavior of the completion functions. If | |
5587 | set to | |
dc60d4e0 | 5588 | .BR On , |
726f6388 JA |
5589 | words which have more than one possible completion cause the |
5590 | matches to be listed immediately instead of ringing the bell. | |
5591 | .TP | |
d3a24ed2 CR |
5592 | .B show\-all\-if\-unmodified (Off) |
5593 | This alters the default behavior of the completion functions in | |
5594 | a fashion similar to \fBshow\-all\-if\-ambiguous\fP. | |
5595 | If set to | |
dc60d4e0 | 5596 | .BR On , |
d3a24ed2 CR |
5597 | words which have more than one possible completion without any |
5598 | possible partial completion (the possible completions don't share | |
5599 | a common prefix) cause the matches to be listed immediately instead | |
5600 | of ringing the bell. | |
5601 | .TP | |
a7ad477f CR |
5602 | .B show\-mode\-in\-prompt (Off) |
5603 | If set to \fBOn\fP, add a character to the beginning of the prompt | |
5604 | indicating the editing mode: emacs (@), vi command (:) or vi | |
5605 | insertion (+). | |
5606 | .TP | |
8f714a7c CR |
5607 | .B skip\-completed\-text (Off) |
5608 | If set to \fBOn\fP, this alters the default completion behavior when | |
5609 | inserting a single match into the line. It's only active when | |
5610 | performing completion in the middle of a word. If enabled, readline | |
5611 | does not insert characters from the completion that match characters | |
5612 | after point in the word being completed, so portions of the word | |
5613 | following the cursor are not duplicated. | |
5614 | .TP | |
0a233f3e CR |
5615 | .B vi\-cmd\-mode\-string ((cmd)) |
5616 | This string is displayed immediately before the last line of the primary | |
5617 | prompt when vi editing mode is active and in command mode. | |
5618 | The value is expanded like a | |
5619 | key binding, so the standard set of meta- and control prefixes and | |
5620 | backslash escape sequences is available. | |
5621 | Use the \e1 and \e2 escapes to begin and end sequences of | |
5622 | non-printing characters, which can be used to embed a terminal control | |
5623 | sequence into the mode string. | |
5624 | .TP | |
5625 | .B vi\-ins\-mode\-string ((ins)) | |
5626 | This string is displayed immediately before the last line of the primary | |
5627 | prompt when vi editing mode is active and in insertion mode. | |
5628 | The value is expanded like a | |
5629 | key binding, so the standard set of meta- and control prefixes and | |
5630 | backslash escape sequences is available. | |
5631 | Use the \e1 and \e2 escapes to begin and end sequences of | |
5632 | non-printing characters, which can be used to embed a terminal control | |
5633 | sequence into the mode string. | |
5634 | .TP | |
ccc6cda3 JA |
5635 | .B visible\-stats (Off) |
5636 | If set to \fBOn\fP, a character denoting a file's type as reported | |
5637 | by \fIstat\fP(2) is appended to the filename when listing possible | |
5638 | completions. | |
726f6388 | 5639 | .PD |
ccc6cda3 | 5640 | .SS "Readline Conditional Constructs" |
726f6388 JA |
5641 | .PP |
5642 | Readline implements a facility similar in spirit to the conditional | |
5643 | compilation features of the C preprocessor which allows key | |
5644 | bindings and variable settings to be performed as the result | |
cce855bc | 5645 | of tests. There are four parser directives used. |
726f6388 | 5646 | .IP \fB$if\fP |
fc527055 | 5647 | The |
726f6388 JA |
5648 | .B $if |
5649 | construct allows bindings to be made based on the | |
5650 | editing mode, the terminal being used, or the application using | |
5651 | readline. The text of the test extends to the end of the line; | |
5652 | no characters are required to isolate it. | |
5653 | .RS | |
5654 | .IP \fBmode\fP | |
5655 | The \fBmode=\fP form of the \fB$if\fP directive is used to test | |
5656 | whether readline is in emacs or vi mode. | |
5657 | This may be used in conjunction | |
5658 | with the \fBset keymap\fP command, for instance, to set bindings in | |
ccc6cda3 | 5659 | the \fIemacs\-standard\fP and \fIemacs\-ctlx\fP keymaps only if |
726f6388 JA |
5660 | readline is starting out in emacs mode. |
5661 | .IP \fBterm\fP | |
5662 | The \fBterm=\fP form may be used to include terminal-specific | |
5663 | key bindings, perhaps to bind the key sequences output by the | |
5664 | terminal's function keys. The word on the right side of the | |
5665 | .B = | |
687a967e | 5666 | is tested against both the full name of the terminal and the portion |
726f6388 JA |
5667 | of the terminal name before the first \fB\-\fP. This allows |
5668 | .I sun | |
5669 | to match both | |
5670 | .I sun | |
5671 | and | |
5672 | .IR sun\-cmd , | |
5673 | for instance. | |
5674 | .IP \fBapplication\fP | |
5675 | The \fBapplication\fP construct is used to include | |
ccc6cda3 | 5676 | application-specific settings. Each program using the readline |
726f6388 JA |
5677 | library sets the \fIapplication name\fP, and an initialization |
5678 | file can test for a particular value. | |
5679 | This could be used to bind key sequences to functions useful for | |
5680 | a specific program. For instance, the following command adds a | |
dc60d4e0 | 5681 | key sequence that quotes the current or previous word in \fBbash\fP: |
cce855bc | 5682 | .sp 1 |
726f6388 JA |
5683 | .RS |
5684 | .nf | |
5685 | \fB$if\fP Bash | |
5686 | # Quote the current or previous word | |
ccc6cda3 | 5687 | "\eC\-xq": "\eeb\e"\eef\e"" |
726f6388 JA |
5688 | \fB$endif\fP |
5689 | .fi | |
5690 | .RE | |
5691 | .RE | |
5692 | .IP \fB$endif\fP | |
cce855bc | 5693 | This command, as seen in the previous example, terminates an |
726f6388 JA |
5694 | \fB$if\fP command. |
5695 | .IP \fB$else\fP | |
5696 | Commands in this branch of the \fB$if\fP directive are executed if | |
5697 | the test fails. | |
cce855bc JA |
5698 | .IP \fB$include\fP |
5699 | This directive takes a single filename as an argument and reads commands | |
5700 | and bindings from that file. For example, the following directive | |
5701 | would read \fI/etc/inputrc\fP: | |
5702 | .sp 1 | |
5703 | .RS | |
5704 | .nf | |
5705 | \fB$include\fP \^ \fI/etc/inputrc\fP | |
5706 | .fi | |
5707 | .RE | |
ccc6cda3 | 5708 | .SS Searching |
726f6388 | 5709 | .PP |
ccc6cda3 JA |
5710 | Readline provides commands for searching through the command history |
5711 | (see | |
5712 | .SM | |
5713 | .B HISTORY | |
5714 | below) for lines containing a specified string. | |
5715 | There are two search modes: | |
5716 | .I incremental | |
5717 | and | |
5718 | .IR non-incremental . | |
5719 | .PP | |
5720 | Incremental searches begin before the user has finished typing the | |
5721 | search string. | |
5722 | As each character of the search string is typed, readline displays | |
5723 | the next entry from the history matching the string typed so far. | |
5724 | An incremental search requires only as many characters as needed to | |
5725 | find the desired history entry. | |
bb70624e | 5726 | The characters present in the value of the \fBisearch-terminators\fP |
b72432fd JA |
5727 | variable are used to terminate an incremental search. |
5728 | If that variable has not been assigned a value the Escape and | |
5729 | Control-J characters will terminate an incremental search. | |
ccc6cda3 JA |
5730 | Control-G will abort an incremental search and restore the original |
5731 | line. | |
5732 | When the search is terminated, the history entry containing the | |
5733 | search string becomes the current line. | |
bb70624e | 5734 | .PP |
ccc6cda3 JA |
5735 | To find other matching entries in the history list, type Control-S or |
5736 | Control-R as appropriate. | |
5737 | This will search backward or forward in the history for the next | |
5738 | entry matching the search string typed so far. | |
5739 | Any other key sequence bound to a readline command will terminate | |
5740 | the search and execute that command. | |
5741 | For instance, a \fInewline\fP will terminate the search and accept | |
5742 | the line, thereby executing the command from the history list. | |
5743 | .PP | |
f73dda09 JA |
5744 | Readline remembers the last incremental search string. If two |
5745 | Control-Rs are typed without any intervening characters defining a | |
5746 | new search string, any remembered search string is used. | |
5747 | .PP | |
ccc6cda3 JA |
5748 | Non-incremental searches read the entire search string before starting |
5749 | to search for matching history lines. The search string may be | |
cce855bc | 5750 | typed by the user or be part of the contents of the current line. |
ccc6cda3 | 5751 | .SS "Readline Command Names" |
726f6388 JA |
5752 | .PP |
5753 | The following is a list of the names of the commands and the default | |
5754 | key sequences to which they are bound. | |
ccc6cda3 | 5755 | Command names without an accompanying key sequence are unbound by default. |
bb70624e JA |
5756 | In the following descriptions, \fIpoint\fP refers to the current cursor |
5757 | position, and \fImark\fP refers to a cursor position saved by the | |
5758 | \fBset\-mark\fP command. | |
5759 | The text between the point and mark is referred to as the \fIregion\fP. | |
726f6388 JA |
5760 | .SS Commands for Moving |
5761 | .PP | |
5762 | .PD 0 | |
5763 | .TP | |
5764 | .B beginning\-of\-line (C\-a) | |
5765 | Move to the start of the current line. | |
5766 | .TP | |
5767 | .B end\-of\-line (C\-e) | |
5768 | Move to the end of the line. | |
5769 | .TP | |
5770 | .B forward\-char (C\-f) | |
5771 | Move forward a character. | |
5772 | .TP | |
5773 | .B backward\-char (C\-b) | |
5774 | Move back a character. | |
5775 | .TP | |
5776 | .B forward\-word (M\-f) | |
5777 | Move forward to the end of the next word. Words are composed of | |
5778 | alphanumeric characters (letters and digits). | |
5779 | .TP | |
5780 | .B backward\-word (M\-b) | |
8c2fef19 CR |
5781 | Move back to the start of the current or previous word. |
5782 | Words are composed of alphanumeric characters (letters and digits). | |
5783 | .TP | |
5784 | .B shell\-forward\-word | |
5785 | Move forward to the end of the next word. | |
5786 | Words are delimited by non-quoted shell metacharacters. | |
5787 | .TP | |
5788 | .B shell\-backward\-word | |
5789 | Move back to the start of the current or previous word. | |
5790 | Words are delimited by non-quoted shell metacharacters. | |
726f6388 JA |
5791 | .TP |
5792 | .B clear\-screen (C\-l) | |
5793 | Clear the screen leaving the current line at the top of the screen. | |
5794 | With an argument, refresh the current line without clearing the | |
5795 | screen. | |
5796 | .TP | |
5797 | .B redraw\-current\-line | |
ccc6cda3 | 5798 | Refresh the current line. |
726f6388 JA |
5799 | .PD |
5800 | .SS Commands for Manipulating the History | |
5801 | .PP | |
5802 | .PD 0 | |
5803 | .TP | |
5804 | .B accept\-line (Newline, Return) | |
5805 | Accept the line regardless of where the cursor is. If this line is | |
ccc6cda3 | 5806 | non-empty, add it to the history list according to the state of the |
726f6388 JA |
5807 | .SM |
5808 | .B HISTCONTROL | |
5809 | variable. If the line is a modified history | |
5810 | line, then restore the history line to its original state. | |
5811 | .TP | |
5812 | .B previous\-history (C\-p) | |
5813 | Fetch the previous command from the history list, moving back in | |
5814 | the list. | |
5815 | .TP | |
5816 | .B next\-history (C\-n) | |
5817 | Fetch the next command from the history list, moving forward in the | |
5818 | list. | |
5819 | .TP | |
5820 | .B beginning\-of\-history (M\-<) | |
5821 | Move to the first line in the history. | |
5822 | .TP | |
5823 | .B end\-of\-history (M\->) | |
5824 | Move to the end of the input history, i.e., the line currently being | |
5825 | entered. | |
5826 | .TP | |
5827 | .B reverse\-search\-history (C\-r) | |
5828 | Search backward starting at the current line and moving `up' through | |
5829 | the history as necessary. This is an incremental search. | |
5830 | .TP | |
5831 | .B forward\-search\-history (C\-s) | |
5832 | Search forward starting at the current line and moving `down' through | |
5833 | the history as necessary. This is an incremental search. | |
5834 | .TP | |
5835 | .B non\-incremental\-reverse\-search\-history (M\-p) | |
5836 | Search backward through the history starting at the current line | |
ccc6cda3 | 5837 | using a non-incremental search for a string supplied by the user. |
726f6388 JA |
5838 | .TP |
5839 | .B non\-incremental\-forward\-search\-history (M\-n) | |
ccc6cda3 | 5840 | Search forward through the history using a non-incremental search for |
726f6388 JA |
5841 | a string supplied by the user. |
5842 | .TP | |
5843 | .B history\-search\-forward | |
5844 | Search forward through the history for the string of characters | |
bb70624e | 5845 | between the start of the current line and the point. |
ccc6cda3 | 5846 | This is a non-incremental search. |
726f6388 JA |
5847 | .TP |
5848 | .B history\-search\-backward | |
5849 | Search backward through the history for the string of characters | |
ccc6cda3 JA |
5850 | between the start of the current line and the point. |
5851 | This is a non-incremental search. | |
726f6388 JA |
5852 | .TP |
5853 | .B yank\-nth\-arg (M\-C\-y) | |
5854 | Insert the first argument to the previous command (usually | |
28ef6c31 JA |
5855 | the second word on the previous line) at point. |
5856 | With an argument | |
726f6388 JA |
5857 | .IR n , |
5858 | insert the \fIn\fPth word from the previous command (the words | |
5859 | in the previous command begin with word 0). A negative argument | |
5860 | inserts the \fIn\fPth word from the end of the previous command. | |
eb2bb562 CR |
5861 | Once the argument \fIn\fP is computed, the argument is extracted |
5862 | as if the "!\fIn\fP" history expansion had been specified. | |
726f6388 JA |
5863 | .TP |
5864 | .B | |
5865 | yank\-last\-arg (M\-.\^, M\-_\^) | |
ccc6cda3 | 5866 | Insert the last argument to the previous command (the last word of |
adc6cff5 CR |
5867 | the previous history entry). |
5868 | With a numeric argument, behave exactly like \fByank\-nth\-arg\fP. | |
cce855bc | 5869 | Successive calls to \fByank\-last\-arg\fP move back through the history |
adc6cff5 CR |
5870 | list, inserting the last word (or the word specified by the argument to |
5871 | the first call) of each line in turn. | |
5872 | Any numeric argument supplied to these successive calls determines | |
5873 | the direction to move through the history. A negative argument switches | |
5874 | the direction through the history (back or forward). | |
c111d992 | 5875 | The history expansion facilities are used to extract the last word, |
eb2bb562 | 5876 | as if the "!$" history expansion had been specified. |
726f6388 JA |
5877 | .TP |
5878 | .B shell\-expand\-line (M\-C\-e) | |
cce855bc | 5879 | Expand the line as the shell does. This |
726f6388 JA |
5880 | performs alias and history expansion as well as all of the shell |
5881 | word expansions. See | |
5882 | .SM | |
5883 | .B HISTORY EXPANSION | |
5884 | below for a description of history expansion. | |
5885 | .TP | |
5886 | .B history\-expand\-line (M\-^) | |
d166f048 JA |
5887 | Perform history expansion on the current line. |
5888 | See | |
726f6388 JA |
5889 | .SM |
5890 | .B HISTORY EXPANSION | |
5891 | below for a description of history expansion. | |
5892 | .TP | |
cce855bc JA |
5893 | .B magic\-space |
5894 | Perform history expansion on the current line and insert a space. | |
5895 | See | |
5896 | .SM | |
5897 | .B HISTORY EXPANSION | |
5898 | below for a description of history expansion. | |
5899 | .TP | |
d166f048 JA |
5900 | .B alias\-expand\-line |
5901 | Perform alias expansion on the current line. | |
5902 | See | |
5903 | .SM | |
5904 | .B ALIASES | |
5905 | above for a description of alias expansion. | |
5906 | .TP | |
5907 | .B history\-and\-alias\-expand\-line | |
5908 | Perform history and alias expansion on the current line. | |
5909 | .TP | |
726f6388 JA |
5910 | .B insert\-last\-argument (M\-.\^, M\-_\^) |
5911 | A synonym for \fByank\-last\-arg\fP. | |
5912 | .TP | |
ccc6cda3 | 5913 | .B operate\-and\-get\-next (C\-o) |
726f6388 JA |
5914 | Accept the current line for execution and fetch the next line |
5915 | relative to the current line from the history for editing. Any | |
5916 | argument is ignored. | |
7117c2d2 JA |
5917 | .TP |
5918 | .B edit\-and\-execute\-command (C\-xC\-e) | |
5919 | Invoke an editor on the current command line, and execute the result as shell | |
5920 | commands. | |
5921 | \fBBash\fP attempts to invoke | |
5922 | .SM | |
dd4f3dd8 | 5923 | .BR $VISUAL , |
7117c2d2 JA |
5924 | .SM |
5925 | .BR $EDITOR , | |
5926 | and \fIemacs\fP as the editor, in that order. | |
726f6388 JA |
5927 | .PD |
5928 | .SS Commands for Changing Text | |
5929 | .PP | |
5930 | .PD 0 | |
5931 | .TP | |
bb579650 CR |
5932 | .B \fIend\-of\-file\fP (usually C\-d) |
5933 | The character indicating end-of-file as set, for example, by | |
5934 | .if t \f(CWstty\fP. | |
5935 | .if n ``stty''. | |
5936 | If this character is read when there are no characters | |
5937 | on the line, and point is at the beginning of the line, Readline | |
5938 | interprets it as the end of input and returns | |
726f6388 JA |
5939 | .SM |
5940 | .BR EOF . | |
5941 | .TP | |
bb579650 CR |
5942 | .B delete\-char (C\-d) |
5943 | Delete the character at point. | |
5944 | If this function is bound to the | |
5945 | same character as the tty \fBEOF\fP character, as \fBC\-d\fP | |
5946 | commonly is, see above for the effects. | |
5947 | .TP | |
726f6388 JA |
5948 | .B backward\-delete\-char (Rubout) |
5949 | Delete the character behind the cursor. When given a numeric argument, | |
ccc6cda3 | 5950 | save the deleted text on the kill ring. |
726f6388 | 5951 | .TP |
b72432fd JA |
5952 | .B forward\-backward\-delete\-char |
5953 | Delete the character under the cursor, unless the cursor is at the | |
5954 | end of the line, in which case the character behind the cursor is | |
f73dda09 | 5955 | deleted. |
b72432fd | 5956 | .TP |
726f6388 | 5957 | .B quoted\-insert (C\-q, C\-v) |
cce855bc | 5958 | Add the next character typed to the line verbatim. This is |
726f6388 JA |
5959 | how to insert characters like \fBC\-q\fP, for example. |
5960 | .TP | |
ccc6cda3 | 5961 | .B tab\-insert (C\-v TAB) |
726f6388 JA |
5962 | Insert a tab character. |
5963 | .TP | |
5964 | .B self\-insert (a,\ b,\ A,\ 1,\ !,\ ...) | |
5965 | Insert the character typed. | |
5966 | .TP | |
5967 | .B transpose\-chars (C\-t) | |
28ef6c31 JA |
5968 | Drag the character before point forward over the character at point, |
5969 | moving point forward as well. | |
5970 | If point is at the end of the line, then this transposes | |
5971 | the two characters before point. | |
bb70624e | 5972 | Negative arguments have no effect. |
726f6388 JA |
5973 | .TP |
5974 | .B transpose\-words (M\-t) | |
bb70624e | 5975 | Drag the word before point past the word after point, |
28ef6c31 | 5976 | moving point over that word as well. |
f73dda09 | 5977 | If point is at the end of the line, this transposes |
fc527055 | 5978 | the last two words on the line. |
726f6388 JA |
5979 | .TP |
5980 | .B upcase\-word (M\-u) | |
5981 | Uppercase the current (or following) word. With a negative argument, | |
cce855bc | 5982 | uppercase the previous word, but do not move point. |
726f6388 JA |
5983 | .TP |
5984 | .B downcase\-word (M\-l) | |
5985 | Lowercase the current (or following) word. With a negative argument, | |
cce855bc | 5986 | lowercase the previous word, but do not move point. |
726f6388 JA |
5987 | .TP |
5988 | .B capitalize\-word (M\-c) | |
5989 | Capitalize the current (or following) word. With a negative argument, | |
cce855bc | 5990 | capitalize the previous word, but do not move point. |
7117c2d2 JA |
5991 | .TP |
5992 | .B overwrite\-mode | |
5993 | Toggle overwrite mode. With an explicit positive numeric argument, | |
5994 | switches to overwrite mode. With an explicit non-positive numeric | |
5995 | argument, switches to insert mode. This command affects only | |
5996 | \fBemacs\fP mode; \fBvi\fP mode does overwrite differently. | |
5997 | Each call to \fIreadline()\fP starts in insert mode. | |
fc527055 | 5998 | In overwrite mode, characters bound to \fBself\-insert\fP replace |
7117c2d2 JA |
5999 | the text at point rather than pushing the text to the right. |
6000 | Characters bound to \fBbackward\-delete\-char\fP replace the character | |
6001 | before point with a space. By default, this command is unbound. | |
726f6388 JA |
6002 | .PD |
6003 | .SS Killing and Yanking | |
6004 | .PP | |
6005 | .PD 0 | |
6006 | .TP | |
6007 | .B kill\-line (C\-k) | |
bb70624e | 6008 | Kill the text from point to the end of the line. |
726f6388 | 6009 | .TP |
ccc6cda3 | 6010 | .B backward\-kill\-line (C\-x Rubout) |
726f6388 JA |
6011 | Kill backward to the beginning of the line. |
6012 | .TP | |
6013 | .B unix\-line\-discard (C\-u) | |
6014 | Kill backward from point to the beginning of the line. | |
cce855bc | 6015 | The killed text is saved on the kill-ring. |
bb70624e | 6016 | .\" There is no real difference between this and backward-kill-line |
726f6388 JA |
6017 | .TP |
6018 | .B kill\-whole\-line | |
bb70624e | 6019 | Kill all characters on the current line, no matter where point is. |
726f6388 | 6020 | .TP |
fc527055 | 6021 | .B kill\-word (M\-d) |
bb70624e JA |
6022 | Kill from point to the end of the current word, or if between |
6023 | words, to the end of the next word. | |
6024 | Word boundaries are the same as those used by \fBforward\-word\fP. | |
726f6388 JA |
6025 | .TP |
6026 | .B backward\-kill\-word (M\-Rubout) | |
bb70624e JA |
6027 | Kill the word behind point. |
6028 | Word boundaries are the same as those used by \fBbackward\-word\fP. | |
726f6388 | 6029 | .TP |
939d190e | 6030 | .B shell\-kill\-word |
8c2fef19 CR |
6031 | Kill from point to the end of the current word, or if between |
6032 | words, to the end of the next word. | |
6033 | Word boundaries are the same as those used by \fBshell\-forward\-word\fP. | |
6034 | .TP | |
939d190e | 6035 | .B shell\-backward\-kill\-word |
8c2fef19 CR |
6036 | Kill the word behind point. |
6037 | Word boundaries are the same as those used by \fBshell\-backward\-word\fP. | |
6038 | .TP | |
726f6388 | 6039 | .B unix\-word\-rubout (C\-w) |
bb70624e | 6040 | Kill the word behind point, using white space as a word boundary. |
bb70624e | 6041 | The killed text is saved on the kill-ring. |
113d85a4 CR |
6042 | .TP |
6043 | .B unix\-filename\-rubout | |
6044 | Kill the word behind point, using white space and the slash character | |
6045 | as the word boundaries. | |
6046 | The killed text is saved on the kill-ring. | |
ccc6cda3 JA |
6047 | .TP |
6048 | .B delete\-horizontal\-space (M\-\e) | |
6049 | Delete all spaces and tabs around point. | |
6050 | .TP | |
6051 | .B kill\-region | |
bb70624e | 6052 | Kill the text in the current region. |
ccc6cda3 JA |
6053 | .TP |
6054 | .B copy\-region\-as\-kill | |
6055 | Copy the text in the region to the kill buffer. | |
726f6388 | 6056 | .TP |
ccc6cda3 JA |
6057 | .B copy\-backward\-word |
6058 | Copy the word before point to the kill buffer. | |
cce855bc | 6059 | The word boundaries are the same as \fBbackward\-word\fP. |
ccc6cda3 JA |
6060 | .TP |
6061 | .B copy\-forward\-word | |
6062 | Copy the word following point to the kill buffer. | |
cce855bc | 6063 | The word boundaries are the same as \fBforward\-word\fP. |
726f6388 JA |
6064 | .TP |
6065 | .B yank (C\-y) | |
28ef6c31 | 6066 | Yank the top of the kill ring into the buffer at point. |
726f6388 JA |
6067 | .TP |
6068 | .B yank\-pop (M\-y) | |
ccc6cda3 | 6069 | Rotate the kill ring, and yank the new top. Only works following |
726f6388 JA |
6070 | .B yank |
6071 | or | |
6072 | .BR yank\-pop . | |
6073 | .PD | |
6074 | .SS Numeric Arguments | |
6075 | .PP | |
6076 | .PD 0 | |
6077 | .TP | |
6078 | .B digit\-argument (M\-0, M\-1, ..., M\-\-) | |
6079 | Add this digit to the argument already accumulating, or start a new | |
6080 | argument. M\-\- starts a negative argument. | |
6081 | .TP | |
6082 | .B universal\-argument | |
d166f048 JA |
6083 | This is another way to specify an argument. |
6084 | If this command is followed by one or more digits, optionally with a | |
6085 | leading minus sign, those digits define the argument. | |
6086 | If the command is followed by digits, executing | |
6087 | .B universal\-argument | |
6088 | again ends the numeric argument, but is otherwise ignored. | |
6089 | As a special case, if this command is immediately followed by a | |
687a967e | 6090 | character that is neither a digit nor minus sign, the argument count |
d166f048 | 6091 | for the next command is multiplied by four. |
726f6388 | 6092 | The argument count is initially one, so executing this function the |
d166f048 JA |
6093 | first time makes the argument count four, a second time makes the |
6094 | argument count sixteen, and so on. | |
726f6388 JA |
6095 | .PD |
6096 | .SS Completing | |
6097 | .PP | |
6098 | .PD 0 | |
6099 | .TP | |
6100 | .B complete (TAB) | |
6101 | Attempt to perform completion on the text before point. | |
6102 | .B Bash | |
6103 | attempts completion treating the text as a variable (if the | |
6104 | text begins with \fB$\fP), username (if the text begins with | |
6105 | \fB~\fP), hostname (if the text begins with \fB@\fP), or | |
6106 | command (including aliases and functions) in turn. If none | |
6107 | of these produces a match, filename completion is attempted. | |
6108 | .TP | |
ccc6cda3 | 6109 | .B possible\-completions (M\-?) |
726f6388 JA |
6110 | List the possible completions of the text before point. |
6111 | .TP | |
ccc6cda3 | 6112 | .B insert\-completions (M\-*) |
726f6388 JA |
6113 | Insert all completions of the text before point |
6114 | that would have been generated by | |
ccc6cda3 | 6115 | \fBpossible\-completions\fP. |
726f6388 | 6116 | .TP |
cce855bc JA |
6117 | .B menu\-complete |
6118 | Similar to \fBcomplete\fP, but replaces the word to be completed | |
6119 | with a single match from the list of possible completions. | |
6120 | Repeated execution of \fBmenu\-complete\fP steps through the list | |
6121 | of possible completions, inserting each match in turn. | |
28ef6c31 | 6122 | At the end of the list of completions, the bell is rung |
f73dda09 | 6123 | (subject to the setting of \fBbell\-style\fP) |
28ef6c31 | 6124 | and the original text is restored. |
cce855bc JA |
6125 | An argument of \fIn\fP moves \fIn\fP positions forward in the list |
6126 | of matches; a negative argument may be used to move backward | |
6127 | through the list. | |
6128 | This command is intended to be bound to \fBTAB\fP, but is unbound | |
6129 | by default. | |
6130 | .TP | |
dc60d4e0 | 6131 | .B menu\-complete\-backward |
9dd88db7 CR |
6132 | Identical to \fBmenu\-complete\fP, but moves backward through the list |
6133 | of possible completions, as if \fBmenu\-complete\fP had been given a | |
6134 | negative argument. This command is unbound by default. | |
6135 | .TP | |
b72432fd JA |
6136 | .B delete\-char\-or\-list |
6137 | Deletes the character under the cursor if not at the beginning or | |
bb70624e | 6138 | end of the line (like \fBdelete\-char\fP). |
b72432fd | 6139 | If at the end of the line, behaves identically to |
bb70624e | 6140 | \fBpossible\-completions\fP. |
b72432fd JA |
6141 | This command is unbound by default. |
6142 | .TP | |
726f6388 JA |
6143 | .B complete\-filename (M\-/) |
6144 | Attempt filename completion on the text before point. | |
6145 | .TP | |
6146 | .B possible\-filename\-completions (C\-x /) | |
6147 | List the possible completions of the text before point, | |
6148 | treating it as a filename. | |
6149 | .TP | |
6150 | .B complete\-username (M\-~) | |
6151 | Attempt completion on the text before point, treating | |
6152 | it as a username. | |
6153 | .TP | |
6154 | .B possible\-username\-completions (C\-x ~) | |
6155 | List the possible completions of the text before point, | |
6156 | treating it as a username. | |
6157 | .TP | |
6158 | .B complete\-variable (M\-$) | |
6159 | Attempt completion on the text before point, treating | |
6160 | it as a shell variable. | |
6161 | .TP | |
6162 | .B possible\-variable\-completions (C\-x $) | |
6163 | List the possible completions of the text before point, | |
6164 | treating it as a shell variable. | |
6165 | .TP | |
6166 | .B complete\-hostname (M\-@) | |
6167 | Attempt completion on the text before point, treating | |
6168 | it as a hostname. | |
6169 | .TP | |
6170 | .B possible\-hostname\-completions (C\-x @) | |
6171 | List the possible completions of the text before point, | |
6172 | treating it as a hostname. | |
6173 | .TP | |
6174 | .B complete\-command (M\-!) | |
6175 | Attempt completion on the text before point, treating | |
6176 | it as a command name. Command completion attempts to | |
6177 | match the text against aliases, reserved words, shell | |
cce855bc | 6178 | functions, shell builtins, and finally executable filenames, |
726f6388 JA |
6179 | in that order. |
6180 | .TP | |
6181 | .B possible\-command\-completions (C\-x !) | |
6182 | List the possible completions of the text before point, | |
6183 | treating it as a command name. | |
6184 | .TP | |
ccc6cda3 | 6185 | .B dynamic\-complete\-history (M\-TAB) |
726f6388 JA |
6186 | Attempt completion on the text before point, comparing |
6187 | the text against lines from the history list for possible | |
6188 | completion matches. | |
6189 | .TP | |
8943768b CR |
6190 | .B dabbrev\-expand |
6191 | Attempt menu completion on the text before point, comparing | |
6192 | the text against lines from the history list for possible | |
6193 | completion matches. | |
6194 | .TP | |
726f6388 | 6195 | .B complete\-into\-braces (M\-{) |
bb70624e | 6196 | Perform filename completion and insert the list of possible completions |
726f6388 JA |
6197 | enclosed within braces so the list is available to the shell (see |
6198 | .B Brace Expansion | |
6199 | above). | |
6200 | .PD | |
6201 | .SS Keyboard Macros | |
6202 | .PP | |
6203 | .PD 0 | |
6204 | .TP | |
ccc6cda3 | 6205 | .B start\-kbd\-macro (C\-x (\^) |
726f6388 JA |
6206 | Begin saving the characters typed into the current keyboard macro. |
6207 | .TP | |
ccc6cda3 | 6208 | .B end\-kbd\-macro (C\-x )\^) |
726f6388 | 6209 | Stop saving the characters typed into the current keyboard macro |
ccc6cda3 | 6210 | and store the definition. |
726f6388 | 6211 | .TP |
ccc6cda3 | 6212 | .B call\-last\-kbd\-macro (C\-x e) |
726f6388 JA |
6213 | Re-execute the last keyboard macro defined, by making the characters |
6214 | in the macro appear as if typed at the keyboard. | |
4a2c75c6 | 6215 | .TP |
ba4ab055 CR |
6216 | .B print\-last\-kbd\-macro () |
6217 | Print the last keyboard macro defined in a format suitable for the | |
6218 | \fIinputrc\fP file. | |
726f6388 JA |
6219 | .PD |
6220 | .SS Miscellaneous | |
6221 | .PP | |
6222 | .PD 0 | |
6223 | .TP | |
6224 | .B re\-read\-init\-file (C\-x C\-r) | |
ccc6cda3 | 6225 | Read in the contents of the \fIinputrc\fP file, and incorporate |
726f6388 JA |
6226 | any bindings or variable assignments found there. |
6227 | .TP | |
6228 | .B abort (C\-g) | |
6229 | Abort the current editing command and | |
6230 | ring the terminal's bell (subject to the setting of | |
6231 | .BR bell\-style ). | |
6232 | .TP | |
ccc6cda3 JA |
6233 | .B do\-uppercase\-version (M\-a, M\-b, M\-\fIx\fP, ...) |
6234 | If the metafied character \fIx\fP is lowercase, run the command | |
6235 | that is bound to the corresponding uppercase character. | |
726f6388 JA |
6236 | .TP |
6237 | .B prefix\-meta (ESC) | |
6238 | Metafy the next character typed. | |
6239 | .SM | |
6240 | .B ESC | |
6241 | .B f | |
6242 | is equivalent to | |
6243 | .BR Meta\-f . | |
6244 | .TP | |
6245 | .B undo (C\-_, C\-x C\-u) | |
6246 | Incremental undo, separately remembered for each line. | |
6247 | .TP | |
6248 | .B revert\-line (M\-r) | |
cce855bc | 6249 | Undo all changes made to this line. This is like executing the |
726f6388 JA |
6250 | .B undo |
6251 | command enough times to return the line to its initial state. | |
6252 | .TP | |
b72432fd | 6253 | .B tilde\-expand (M\-&) |
726f6388 JA |
6254 | Perform tilde expansion on the current word. |
6255 | .TP | |
ccc6cda3 | 6256 | .B set\-mark (C\-@, M\-<space>) |
28ef6c31 | 6257 | Set the mark to the point. If a |
ccc6cda3 JA |
6258 | numeric argument is supplied, the mark is set to that position. |
6259 | .TP | |
6260 | .B exchange\-point\-and\-mark (C\-x C\-x) | |
6261 | Swap the point with the mark. The current cursor position is set to | |
6262 | the saved position, and the old cursor position is saved as the mark. | |
6263 | .TP | |
6264 | .B character\-search (C\-]) | |
6265 | A character is read and point is moved to the next occurrence of that | |
6266 | character. A negative count searches for previous occurrences. | |
6267 | .TP | |
6268 | .B character\-search\-backward (M\-C\-]) | |
6269 | A character is read and point is moved to the previous occurrence of that | |
6270 | character. A negative count searches for subsequent occurrences. | |
6271 | .TP | |
dc60d4e0 | 6272 | .B skip\-csi\-sequence |
691aebcb CR |
6273 | Read enough characters to consume a multi-key sequence such as those |
6274 | defined for keys like Home and End. Such sequences begin with a | |
6275 | Control Sequence Indicator (CSI), usually ESC\-[. If this sequence is | |
6276 | bound to "\e[", keys producing such sequences will have no effect | |
6277 | unless explicitly bound to a readline command, instead of inserting | |
6278 | stray characters into the editing buffer. This is unbound by default, | |
6279 | but usually bound to ESC\-[. | |
6280 | .TP | |
ccc6cda3 | 6281 | .B insert\-comment (M\-#) |
7117c2d2 | 6282 | Without a numeric argument, the value of the readline |
ccc6cda3 | 6283 | .B comment\-begin |
7117c2d2 | 6284 | variable is inserted at the beginning of the current line. |
fc527055 | 6285 | If a numeric argument is supplied, this command acts as a toggle: if |
7117c2d2 JA |
6286 | the characters at the beginning of the line do not match the value |
6287 | of \fBcomment\-begin\fP, the value is inserted, otherwise | |
fc527055 | 6288 | the characters in \fBcomment\-begin\fP are deleted from the beginning of |
7117c2d2 JA |
6289 | the line. |
6290 | In either case, the line is accepted as if a newline had been typed. | |
6291 | The default value of | |
bb70624e | 6292 | \fBcomment\-begin\fP causes this command to make the current line |
ccc6cda3 | 6293 | a shell comment. |
7117c2d2 JA |
6294 | If a numeric argument causes the comment character to be removed, the line |
6295 | will be executed by the shell. | |
6296 | .TP | |
6297 | .B glob\-complete\-word (M\-g) | |
6298 | The word before point is treated as a pattern for pathname expansion, | |
6299 | with an asterisk implicitly appended. This pattern is used to | |
b28ff8c9 | 6300 | generate a list of matching filenames for possible completions. |
ccc6cda3 JA |
6301 | .TP |
6302 | .B glob\-expand\-word (C\-x *) | |
6303 | The word before point is treated as a pattern for pathname expansion, | |
b28ff8c9 | 6304 | and the list of matching filenames is inserted, replacing the word. |
7117c2d2 JA |
6305 | If a numeric argument is supplied, an asterisk is appended before |
6306 | pathname expansion. | |
ccc6cda3 JA |
6307 | .TP |
6308 | .B glob\-list\-expansions (C\-x g) | |
6309 | The list of expansions that would have been generated by | |
6310 | .B glob\-expand\-word | |
6311 | is displayed, and the line is redrawn. | |
7117c2d2 JA |
6312 | If a numeric argument is supplied, an asterisk is appended before |
6313 | pathname expansion. | |
ccc6cda3 | 6314 | .TP |
726f6388 JA |
6315 | .B dump\-functions |
6316 | Print all of the functions and their key bindings to the | |
6317 | readline output stream. If a numeric argument is supplied, | |
6318 | the output is formatted in such a way that it can be made part | |
6319 | of an \fIinputrc\fP file. | |
6320 | .TP | |
ccc6cda3 JA |
6321 | .B dump\-variables |
6322 | Print all of the settable readline variables and their values to the | |
6323 | readline output stream. If a numeric argument is supplied, | |
6324 | the output is formatted in such a way that it can be made part | |
6325 | of an \fIinputrc\fP file. | |
6326 | .TP | |
6327 | .B dump\-macros | |
6328 | Print all of the readline key sequences bound to macros and the | |
22e63b05 | 6329 | strings they output. If a numeric argument is supplied, |
ccc6cda3 JA |
6330 | the output is formatted in such a way that it can be made part |
6331 | of an \fIinputrc\fP file. | |
6332 | .TP | |
726f6388 JA |
6333 | .B display\-shell\-version (C\-x C\-v) |
6334 | Display version information about the current instance of | |
6335 | .BR bash . | |
6336 | .PD | |
bb70624e JA |
6337 | .SS Programmable Completion |
6338 | .PP | |
6339 | When word completion is attempted for an argument to a command for | |
6340 | which a completion specification (a \fIcompspec\fP) has been defined | |
6341 | using the \fBcomplete\fP builtin (see | |
6342 | .SM | |
6343 | .B "SHELL BUILTIN COMMANDS" | |
6344 | below), the programmable completion facilities are invoked. | |
6345 | .PP | |
6346 | First, the command name is identified. | |
3eb2d94a CR |
6347 | If the command word is the empty string (completion attempted at the |
6348 | beginning of an empty line), any compspec defined with | |
6349 | the \fB\-E\fP option to \fBcomplete\fP is used. | |
bb70624e JA |
6350 | If a compspec has been defined for that command, the |
6351 | compspec is used to generate the list of possible completions for the word. | |
6352 | If the command word is a full pathname, a compspec for the full | |
6353 | pathname is searched for first. | |
6354 | If no compspec is found for the full pathname, an attempt is made to | |
6355 | find a compspec for the portion following the final slash. | |
dc60d4e0 | 6356 | If those searches do not result in a compspec, any compspec defined with |
3eb2d94a | 6357 | the \fB\-D\fP option to \fBcomplete\fP is used as the default. |
bb70624e JA |
6358 | .PP |
6359 | Once a compspec has been found, it is used to generate the list of | |
6360 | matching words. | |
6361 | If a compspec is not found, the default \fBbash\fP completion as | |
6362 | described above under \fBCompleting\fP is performed. | |
6363 | .PP | |
6364 | First, the actions specified by the compspec are used. | |
6365 | Only matches which are prefixed by the word being completed are | |
6366 | returned. | |
6367 | When the | |
6368 | .B \-f | |
6369 | or | |
6370 | .B \-d | |
6371 | option is used for filename or directory name completion, the shell | |
6372 | variable | |
6373 | .SM | |
6374 | .B FIGNORE | |
6375 | is used to filter the matches. | |
6376 | .PP | |
d0ca3503 | 6377 | Any completions specified by a pathname expansion pattern to the |
bb70624e JA |
6378 | \fB\-G\fP option are generated next. |
6379 | The words generated by the pattern need not match the word | |
6380 | being completed. | |
6381 | The | |
6382 | .SM | |
6383 | .B GLOBIGNORE | |
6384 | shell variable is not used to filter the matches, but the | |
6385 | .SM | |
6386 | .B FIGNORE | |
6387 | variable is used. | |
6388 | .PP | |
6389 | Next, the string specified as the argument to the \fB\-W\fP option | |
6390 | is considered. | |
6391 | The string is first split using the characters in the | |
6392 | .SM | |
6393 | .B IFS | |
6394 | special variable as delimiters. | |
6395 | Shell quoting is honored. | |
6396 | Each word is then expanded using | |
6397 | brace expansion, tilde expansion, parameter and variable expansion, | |
6e70dbff | 6398 | command substitution, and arithmetic expansion, |
fc527055 | 6399 | as described above under |
bb70624e JA |
6400 | .SM |
6401 | .BR EXPANSION . | |
6402 | The results are split using the rules described above under | |
6403 | \fBWord Splitting\fP. | |
6404 | The results of the expansion are prefix-matched against the word being | |
6405 | completed, and the matching words become the possible completions. | |
6406 | .PP | |
6407 | After these matches have been generated, any shell function or command | |
6408 | specified with the \fB\-F\fP and \fB\-C\fP options is invoked. | |
6409 | When the command or function is invoked, the | |
6410 | .SM | |
d3ad40de CR |
6411 | .BR COMP_LINE , |
6412 | .SM | |
6413 | .BR COMP_POINT , | |
6414 | .SM | |
6415 | .BR COMP_KEY , | |
bb70624e JA |
6416 | and |
6417 | .SM | |
d3ad40de | 6418 | .B COMP_TYPE |
bb70624e JA |
6419 | variables are assigned values as described above under |
6420 | \fBShell Variables\fP. | |
fc527055 | 6421 | If a shell function is being invoked, the |
bb70624e JA |
6422 | .SM |
6423 | .B COMP_WORDS | |
6424 | and | |
6425 | .SM | |
6426 | .B COMP_CWORD | |
6427 | variables are also set. | |
ba4ab055 CR |
6428 | When the function or command is invoked, |
6429 | the first argument (\fB$1\fP) is the name of the command whose arguments are | |
6430 | being completed, | |
6431 | the second argument (\fB$2\fP) is the word being completed, | |
6432 | and the third argument (\fB$3\fP) is the word preceding the word being | |
6433 | completed on the current command line. | |
bb70624e JA |
6434 | No filtering of the generated completions against the word being completed |
6435 | is performed; the function or command has complete freedom in generating | |
6436 | the matches. | |
6437 | .PP | |
6438 | Any function specified with \fB\-F\fP is invoked first. | |
6439 | The function may use any of the shell facilities, including the | |
6440 | \fBcompgen\fP builtin described below, to generate the matches. | |
6441 | It must put the possible completions in the | |
6442 | .SM | |
6443 | .B COMPREPLY | |
ba4ab055 | 6444 | array variable, one per array element. |
bb70624e JA |
6445 | .PP |
6446 | Next, any command specified with the \fB\-C\fP option is invoked | |
6447 | in an environment equivalent to command substitution. | |
6448 | It should print a list of completions, one per line, to the | |
6449 | standard output. | |
6450 | Backslash may be used to escape a newline, if necessary. | |
6451 | .PP | |
6452 | After all of the possible completions are generated, any filter | |
6453 | specified with the \fB\-X\fP option is applied to the list. | |
6454 | The filter is a pattern as used for pathname expansion; a \fB&\fP | |
6455 | in the pattern is replaced with the text of the word being completed. | |
6456 | A literal \fB&\fP may be escaped with a backslash; the backslash | |
6457 | is removed before attempting a match. | |
6458 | Any completion that matches the pattern will be removed from the list. | |
6459 | A leading \fB!\fP negates the pattern; in this case any completion | |
6460 | not matching the pattern will be removed. | |
0a233f3e CR |
6461 | If the |
6462 | .B nocasematch | |
6463 | shell option is enabled, the match is performed without regard to the case | |
6464 | of alphabetic characters. | |
bb70624e JA |
6465 | .PP |
6466 | Finally, any prefix and suffix specified with the \fB\-P\fP and \fB\-S\fP | |
6467 | options are added to each member of the completion list, and the result is | |
6468 | returned to the readline completion code as the list of possible | |
6469 | completions. | |
6470 | .PP | |
28ef6c31 JA |
6471 | If the previously-applied actions do not generate any matches, and the |
6472 | \fB\-o dirnames\fP option was supplied to \fBcomplete\fP when the | |
6473 | compspec was defined, directory name completion is attempted. | |
6474 | .PP | |
d3a24ed2 CR |
6475 | If the \fB\-o plusdirs\fP option was supplied to \fBcomplete\fP when the |
6476 | compspec was defined, directory name completion is attempted and any | |
6477 | matches are added to the results of the other actions. | |
6478 | .PP | |
28ef6c31 JA |
6479 | By default, if a compspec is found, whatever it generates is returned |
6480 | to the completion code as the full set of possible completions. | |
bb70624e JA |
6481 | The default \fBbash\fP completions are not attempted, and the readline |
6482 | default of filename completion is disabled. | |
d3a24ed2 CR |
6483 | If the \fB\-o bashdefault\fP option was supplied to \fBcomplete\fP when |
6484 | the compspec was defined, the \fBbash\fP default completions are attempted | |
28ef6c31 | 6485 | if the compspec generates no matches. |
d3a24ed2 CR |
6486 | If the \fB\-o default\fP option was supplied to \fBcomplete\fP when the |
6487 | compspec was defined, readline's default completion will be performed | |
6488 | if the compspec (and, if attempted, the default \fBbash\fP completions) | |
6489 | generate no matches. | |
7117c2d2 JA |
6490 | .PP |
6491 | When a compspec indicates that directory name completion is desired, | |
6492 | the programmable completion functions force readline to append a slash | |
fc527055 | 6493 | to completed names which are symbolic links to directories, subject to |
7117c2d2 JA |
6494 | the value of the \fBmark\-directories\fP readline variable, regardless |
6495 | of the setting of the \fBmark-symlinked\-directories\fP readline variable. | |
3eb2d94a CR |
6496 | .PP |
6497 | There is some support for dynamically modifying completions. This is | |
6498 | most useful when used in combination with a default completion specified | |
6499 | with \fBcomplete -D\fP. | |
6500 | It's possible for shell functions executed as completion | |
6501 | handlers to indicate that completion should be retried by returning an | |
6502 | exit status of 124. If a shell function returns 124, and changes | |
6503 | the compspec associated with the command on which completion is being | |
6504 | attempted (supplied as the first argument when the function is executed), | |
6505 | programmable completion restarts from the beginning, with an | |
3d8cce26 | 6506 | attempt to find a new compspec for that command. This allows a set of |
3eb2d94a CR |
6507 | completions to be built dynamically as completion is attempted, rather than |
6508 | being loaded all at once. | |
6509 | .PP | |
6510 | For instance, assuming that there is a library of compspecs, each kept in a | |
6511 | file corresponding to the name of the command, the following default | |
6512 | completion function would load completions dynamically: | |
6513 | .PP | |
6514 | \f(CW_completion_loader() | |
6515 | .br | |
6516 | { | |
6517 | .br | |
6518 | . "/etc/bash_completion.d/$1.sh" >/dev/null 2>&1 && return 124 | |
6519 | .br | |
6520 | } | |
6521 | .br | |
9353cc05 | 6522 | complete -D -F _completion_loader -o bashdefault -o default |
3eb2d94a CR |
6523 | .br |
6524 | \fP | |
726f6388 | 6525 | .SH HISTORY |
ccc6cda3 | 6526 | When the |
d166f048 | 6527 | .B \-o history |
ccc6cda3 JA |
6528 | option to the |
6529 | .B set | |
6530 | builtin is enabled, the shell provides access to the | |
6531 | \fIcommand history\fP, | |
bb70624e | 6532 | the list of commands previously typed. |
984a1947 CR |
6533 | The value of the |
6534 | .SM | |
6535 | .B HISTSIZE | |
6536 | variable is used as the | |
bb70624e JA |
6537 | number of commands to save in a history list. |
6538 | The text of the last | |
726f6388 JA |
6539 | .SM |
6540 | .B HISTSIZE | |
bb70624e | 6541 | commands (default 500) is saved. The shell |
726f6388 JA |
6542 | stores each command in the history list prior to parameter and |
6543 | variable expansion (see | |
6544 | .SM | |
6545 | .B EXPANSION | |
6546 | above) but after history expansion is performed, subject to the | |
6547 | values of the shell variables | |
ccc6cda3 JA |
6548 | .SM |
6549 | .B HISTIGNORE | |
726f6388 JA |
6550 | and |
6551 | .SM | |
6552 | .BR HISTCONTROL . | |
bb70624e | 6553 | .PP |
726f6388 JA |
6554 | On startup, the history is initialized from the file named by |
6555 | the variable | |
6556 | .SM | |
6557 | .B HISTFILE | |
6558 | (default \fI~/.bash_history\fP). | |
bb70624e | 6559 | The file named by the value of |
726f6388 JA |
6560 | .SM |
6561 | .B HISTFILE | |
6562 | is truncated, if necessary, to contain no more than | |
bb70624e | 6563 | the number of lines specified by the value of |
726f6388 | 6564 | .SM |
bb70624e | 6565 | .BR HISTFILESIZE . |
4b82d1cd CR |
6566 | If \fBHISTFILESIZE\fP is unset, or set to null, a non-numeric value, |
6567 | or a numeric value less than zero, the history file is not truncated. | |
d3ad40de CR |
6568 | When the history file is read, |
6569 | lines beginning with the history comment character followed immediately | |
6570 | by a digit are interpreted as timestamps for the preceding history line. | |
6571 | These timestamps are optionally displayed depending on the value of the | |
6572 | .SM | |
6573 | .B HISTTIMEFORMAT | |
6574 | variable. | |
ed3f3b6c | 6575 | When a shell with history enabled exits, the last |
ccc6cda3 | 6576 | .SM |
bb70624e | 6577 | .B $HISTSIZE |
ccc6cda3 JA |
6578 | lines are copied from the history list to |
6579 | .SM | |
bb70624e | 6580 | .BR $HISTFILE . |
ccc6cda3 JA |
6581 | If the |
6582 | .B histappend | |
6583 | shell option is enabled | |
6584 | (see the description of | |
6585 | .B shopt | |
6586 | under | |
6587 | .SM | |
6588 | .B "SHELL BUILTIN COMMANDS" | |
6589 | below), the lines are appended to the history file, | |
6590 | otherwise the history file is overwritten. | |
6591 | If | |
6592 | .SM | |
6593 | .B HISTFILE | |
6594 | is unset, or if the history file is unwritable, the history is | |
d3ad40de CR |
6595 | not saved. |
6596 | If the | |
6597 | .SM | |
984a1947 | 6598 | .B HISTTIMEFORMAT |
d3ad40de CR |
6599 | variable is set, time stamps are written to the history file, marked |
6600 | with the history comment character, so | |
6601 | they may be preserved across shell sessions. | |
6602 | This uses the history comment character to distinguish timestamps from | |
6603 | other history lines. | |
6604 | After saving the history, the history file is truncated | |
ccc6cda3 JA |
6605 | to contain no more than |
6606 | .SM | |
6607 | .B HISTFILESIZE | |
6608 | lines. If | |
6609 | .SM | |
6610 | .B HISTFILESIZE | |
e67d0029 CR |
6611 | is unset, or set to null, a non-numeric value, |
6612 | or a numeric value less than zero, the history file is not truncated. | |
ccc6cda3 | 6613 | .PP |
726f6388 JA |
6614 | The builtin command |
6615 | .B fc | |
6616 | (see | |
6617 | .SM | |
6618 | .B SHELL BUILTIN COMMANDS | |
6619 | below) may be used to list or edit and re-execute a portion of | |
6620 | the history list. | |
6621 | The | |
6622 | .B history | |
bb70624e | 6623 | builtin may be used to display or modify the history list and |
ccc6cda3 | 6624 | manipulate the history file. |
bb70624e | 6625 | When using command-line editing, search commands |
726f6388 | 6626 | are available in each editing mode that provide access to the |
ccc6cda3 JA |
6627 | history list. |
6628 | .PP | |
6629 | The shell allows control over which commands are saved on the history | |
6630 | list. The | |
726f6388 | 6631 | .SM |
ccc6cda3 JA |
6632 | .B HISTCONTROL |
6633 | and | |
726f6388 | 6634 | .SM |
ccc6cda3 JA |
6635 | .B HISTIGNORE |
6636 | variables may be set to cause the shell to save only a subset of the | |
6637 | commands entered. | |
6638 | The | |
6639 | .B cmdhist | |
6640 | shell option, if enabled, causes the shell to attempt to save each | |
6641 | line of a multi-line command in the same history entry, adding | |
6642 | semicolons where necessary to preserve syntactic correctness. | |
6643 | The | |
6644 | .B lithist | |
6645 | shell option causes the shell to save the command with embedded newlines | |
6646 | instead of semicolons. See the description of the | |
6647 | .B shopt | |
6648 | builtin below under | |
6649 | .SM | |
6650 | .B "SHELL BUILTIN COMMANDS" | |
6651 | for information on setting and unsetting shell options. | |
726f6388 JA |
6652 | .SH "HISTORY EXPANSION" |
6653 | .PP | |
6654 | The shell supports a history expansion feature that | |
6655 | is similar to the history expansion in | |
6656 | .BR csh. | |
6657 | This section describes what syntax features are available. This | |
6658 | feature is enabled by default for interactive shells, and can be | |
6659 | disabled using the | |
863d31ae | 6660 | .B +H |
726f6388 JA |
6661 | option to the |
6662 | .B set | |
6663 | builtin command (see | |
6664 | .SM | |
6665 | .B SHELL BUILTIN COMMANDS | |
ccc6cda3 JA |
6666 | below). Non-interactive shells do not perform history expansion |
6667 | by default. | |
6668 | .PP | |
6669 | History expansions introduce words from the history list into | |
6670 | the input stream, making it easy to repeat commands, insert the | |
6671 | arguments to a previous command into the current input line, or | |
6672 | fix errors in previous commands quickly. | |
726f6388 JA |
6673 | .PP |
6674 | History expansion is performed immediately after a complete line | |
6675 | is read, before the shell breaks it into words. | |
ccc6cda3 | 6676 | It takes place in two parts. |
cce855bc | 6677 | The first is to determine which line from the history list |
ccc6cda3 JA |
6678 | to use during substitution. |
6679 | The second is to select portions of that line for inclusion into | |
6680 | the current one. | |
cce855bc | 6681 | The line selected from the history is the \fIevent\fP, |
ccc6cda3 JA |
6682 | and the portions of that line that are acted upon are \fIwords\fP. |
6683 | Various \fImodifiers\fP are available to manipulate the selected words. | |
6684 | The line is broken into words in the same fashion as when reading input, | |
6685 | so that several \fImetacharacter\fP-separated words surrounded by | |
cce855bc | 6686 | quotes are considered one word. |
ccc6cda3 JA |
6687 | History expansions are introduced by the appearance of the |
6688 | history expansion character, which is \^\fB!\fP\^ by default. | |
6689 | Only backslash (\^\fB\e\fP\^) and single quotes can quote | |
6690 | the history expansion character. | |
6691 | .PP | |
d3a24ed2 CR |
6692 | Several characters inhibit history expansion if found immediately |
6693 | following the history expansion character, even if it is unquoted: | |
6694 | space, tab, newline, carriage return, and \fB=\fP. | |
6695 | If the \fBextglob\fP shell option is enabled, \fB(\fP will also | |
6696 | inhibit expansion. | |
6697 | .PP | |
ccc6cda3 JA |
6698 | Several shell options settable with the |
6699 | .B shopt | |
6700 | builtin may be used to tailor the behavior of history expansion. | |
6701 | If the | |
6702 | .B histverify | |
6703 | shell option is enabled (see the description of the | |
6704 | .B shopt | |
984a1947 | 6705 | builtin below), and |
ccc6cda3 JA |
6706 | .B readline |
6707 | is being used, history substitutions are not immediately passed to | |
6708 | the shell parser. | |
6709 | Instead, the expanded line is reloaded into the | |
6710 | .B readline | |
6711 | editing buffer for further modification. | |
6712 | If | |
6713 | .B readline | |
6714 | is being used, and the | |
6715 | .B histreedit | |
6716 | shell option is enabled, a failed history substitution will be reloaded | |
6717 | into the | |
6718 | .B readline | |
6719 | editing buffer for correction. | |
6720 | The | |
6721 | .B \-p | |
6722 | option to the | |
6723 | .B history | |
6724 | builtin command may be used to see what a history expansion will | |
6725 | do before using it. | |
6726 | The | |
6727 | .B \-s | |
6728 | option to the | |
6729 | .B history | |
6730 | builtin may be used to add commands to the end of the history list | |
6731 | without actually executing them, so that they are available for | |
6732 | subsequent recall. | |
726f6388 JA |
6733 | .PP |
6734 | The shell allows control of the various characters used by the | |
6735 | history expansion mechanism (see the description of | |
6736 | .B histchars | |
6737 | above under | |
6738 | .BR "Shell Variables" ). | |
d3ad40de CR |
6739 | The shell uses |
6740 | the history comment character to mark history timestamps when | |
6741 | writing the history file. | |
726f6388 JA |
6742 | .SS Event Designators |
6743 | .PP | |
6744 | An event designator is a reference to a command line entry in the | |
6745 | history list. | |
5f8cde23 CR |
6746 | Unless the reference is absolute, events are relative to the current |
6747 | position in the history list. | |
726f6388 JA |
6748 | .PP |
6749 | .PD 0 | |
6750 | .TP | |
6751 | .B ! | |
6752 | Start a history substitution, except when followed by a | |
6753 | .BR blank , | |
d3a24ed2 CR |
6754 | newline, carriage return, = |
6755 | or ( (when the \fBextglob\fP shell option is enabled using | |
6756 | the \fBshopt\fP builtin). | |
726f6388 | 6757 | .TP |
726f6388 JA |
6758 | .B !\fIn\fR |
6759 | Refer to command line | |
6760 | .IR n . | |
6761 | .TP | |
6762 | .B !\-\fIn\fR | |
5f8cde23 | 6763 | Refer to the current command minus |
726f6388 JA |
6764 | .IR n . |
6765 | .TP | |
ccc6cda3 JA |
6766 | .B !! |
6767 | Refer to the previous command. This is a synonym for `!\-1'. | |
6768 | .TP | |
726f6388 | 6769 | .B !\fIstring\fR |
5f8cde23 CR |
6770 | Refer to the most recent command preceding the current position in the |
6771 | history list starting with | |
726f6388 JA |
6772 | .IR string . |
6773 | .TP | |
6774 | .B !?\fIstring\fR\fB[?]\fR | |
e3db237e | 6775 | Refer to the most recent command preceding the current position in the |
5f8cde23 | 6776 | history list containing |
726f6388 | 6777 | .IR string . |
ccc6cda3 JA |
6778 | The trailing \fB?\fP may be omitted if |
6779 | .I string | |
6780 | is followed immediately by a newline. | |
726f6388 JA |
6781 | .TP |
6782 | .B \d\s+2^\s-2\u\fIstring1\fP\d\s+2^\s-2\u\fIstring2\fP\d\s+2^\s-2\u | |
5f8cde23 | 6783 | Quick substitution. Repeat the previous command, replacing |
726f6388 JA |
6784 | .I string1 |
6785 | with | |
6786 | .IR string2 . | |
6787 | Equivalent to | |
6788 | ``!!:s/\fIstring1\fP/\fIstring2\fP/'' | |
6789 | (see \fBModifiers\fP below). | |
6790 | .TP | |
6791 | .B !# | |
6792 | The entire command line typed so far. | |
6793 | .PD | |
6794 | .SS Word Designators | |
6795 | .PP | |
ccc6cda3 | 6796 | Word designators are used to select desired words from the event. |
fc527055 | 6797 | A |
726f6388 | 6798 | .B : |
ccc6cda3 | 6799 | separates the event specification from the word designator. |
cce855bc | 6800 | It may be omitted if the word designator begins with a |
726f6388 JA |
6801 | .BR ^ , |
6802 | .BR $ , | |
6803 | .BR * , | |
ccc6cda3 | 6804 | .BR \- , |
726f6388 JA |
6805 | or |
6806 | .BR % . | |
6807 | Words are numbered from the beginning of the line, | |
ccc6cda3 JA |
6808 | with the first word being denoted by 0 (zero). |
6809 | Words are inserted into the current line separated by single spaces. | |
726f6388 JA |
6810 | .PP |
6811 | .PD 0 | |
6812 | .TP | |
6813 | .B 0 (zero) | |
6814 | The zeroth word. For the shell, this is the command | |
6815 | word. | |
6816 | .TP | |
6817 | .I n | |
6818 | The \fIn\fRth word. | |
6819 | .TP | |
6820 | .B ^ | |
6821 | The first argument. That is, word 1. | |
6822 | .TP | |
6823 | .B $ | |
c111d992 CR |
6824 | The last word. This is usually the last argument, but will expand to the |
6825 | zeroth word if there is only one word in the line. | |
726f6388 JA |
6826 | .TP |
6827 | .B % | |
6828 | The word matched by the most recent `?\fIstring\fR?' search. | |
6829 | .TP | |
6830 | .I x\fB\-\fPy | |
6831 | A range of words; `\-\fIy\fR' abbreviates `0\-\fIy\fR'. | |
6832 | .TP | |
6833 | .B * | |
6834 | All of the words but the zeroth. This is a synonym | |
6835 | for `\fI1\-$\fP'. It is not an error to use | |
6836 | .B * | |
6837 | if there is just one | |
6838 | word in the event; the empty string is returned in that case. | |
6839 | .TP | |
6840 | .B x* | |
6841 | Abbreviates \fIx\-$\fP. | |
6842 | .TP | |
6843 | .B x\- | |
6844 | Abbreviates \fIx\-$\fP like \fBx*\fP, but omits the last word. | |
6845 | .PD | |
ccc6cda3 JA |
6846 | .PP |
6847 | If a word designator is supplied without an event specification, the | |
6848 | previous command is used as the event. | |
726f6388 JA |
6849 | .SS Modifiers |
6850 | .PP | |
ccc6cda3 JA |
6851 | After the optional word designator, there may appear a sequence of |
6852 | one or more of the following modifiers, each preceded by a `:'. | |
726f6388 JA |
6853 | .PP |
6854 | .PD 0 | |
6855 | .PP | |
6856 | .TP | |
6857 | .B h | |
b28ff8c9 | 6858 | Remove a trailing filename component, leaving only the head. |
ccc6cda3 JA |
6859 | .TP |
6860 | .B t | |
b28ff8c9 | 6861 | Remove all leading filename components, leaving the tail. |
726f6388 JA |
6862 | .TP |
6863 | .B r | |
6864 | Remove a trailing suffix of the form \fI.xxx\fP, leaving the | |
6865 | basename. | |
6866 | .TP | |
6867 | .B e | |
6868 | Remove all but the trailing suffix. | |
6869 | .TP | |
726f6388 JA |
6870 | .B p |
6871 | Print the new command but do not execute it. | |
6872 | .TP | |
6873 | .B q | |
6874 | Quote the substituted words, escaping further substitutions. | |
6875 | .TP | |
cce855bc JA |
6876 | .B x |
6877 | Quote the substituted words as with | |
6878 | .BR q , | |
6879 | but break into words at | |
6880 | .B blanks | |
6881 | and newlines. | |
726f6388 | 6882 | .TP |
cce855bc JA |
6883 | .B s/\fIold\fP/\fInew\fP/ |
6884 | Substitute | |
6885 | .I new | |
6886 | for the first occurrence of | |
6887 | .I old | |
6888 | in the event line. Any delimiter can be used in place of /. The | |
6889 | final delimiter is optional if it is the last character of the | |
6890 | event line. The delimiter may be quoted in | |
6891 | .I old | |
6892 | and | |
6893 | .I new | |
6894 | with a single backslash. If & appears in | |
6895 | .IR new , | |
6896 | it is replaced by | |
6897 | .IR old . | |
6898 | A single backslash will quote the &. If | |
6899 | .I old | |
6900 | is null, it is set to the last | |
6901 | .I old | |
6902 | substituted, or, if no previous history substitutions took place, | |
6903 | the last | |
6904 | .I string | |
6905 | in a | |
6906 | .B !?\fIstring\fR\fB[?]\fR | |
6907 | search. | |
ccc6cda3 | 6908 | .TP |
cce855bc JA |
6909 | .B & |
6910 | Repeat the previous substitution. | |
6911 | .TP | |
6912 | .B g | |
6913 | Cause changes to be applied over the entire event line. This is | |
6914 | used in conjunction with `\fB:s\fP' (e.g., `\fB:gs/\fIold\fP/\fInew\fP/\fR') | |
6915 | or `\fB:&\fP'. If used with | |
6916 | `\fB:s\fP', any delimiter can be used | |
6917 | in place of /, and the final delimiter is optional | |
6918 | if it is the last character of the event line. | |
d3a24ed2 CR |
6919 | An \fBa\fP may be used as a synonym for \fBg\fP. |
6920 | .TP | |
6921 | .B G | |
6922 | Apply the following `\fBs\fP' modifier once to each word in the event line. | |
726f6388 | 6923 | .PD |
726f6388 JA |
6924 | .SH "SHELL BUILTIN COMMANDS" |
6925 | .\" start of bash_builtins | |
6926 | .zZ | |
ccc6cda3 JA |
6927 | .PP |
6928 | Unless otherwise noted, each builtin command documented in this | |
6929 | section as accepting options preceded by | |
6930 | .B \- | |
6931 | accepts | |
6932 | .B \-\- | |
6933 | to signify the end of the options. | |
6932f7f5 CR |
6934 | The \fB:\fP, \fBtrue\fP, \fBfalse\fP, and \fBtest\fP builtins |
6935 | do not accept options and do not treat \fB\-\-\fP specially. | |
6936 | The \fBexit\fP, \fBlogout\fP, \fBbreak\fP, \fBcontinue\fP, \fBlet\fP, | |
6937 | and \fBshift\fP builtins accept and process arguments beginning with | |
6938 | \fB\-\fP without requiring \fB\-\-\fP. | |
6939 | Other builtins that accept arguments but are not specified as accepting | |
6940 | options interpret arguments beginning with \fB\-\fP as invalid options and | |
6941 | require \fB\-\-\fP to prevent this interpretation. | |
ccc6cda3 | 6942 | .sp .5 |
726f6388 JA |
6943 | .PD 0 |
6944 | .TP | |
6945 | \fB:\fP [\fIarguments\fP] | |
6946 | .PD | |
6947 | No effect; the command does nothing beyond expanding | |
6948 | .I arguments | |
6949 | and performing any specified | |
6950 | redirections. A zero exit code is returned. | |
6951 | .TP | |
726f6388 | 6952 | \fB .\| \fP \fIfilename\fP [\fIarguments\fP] |
7117c2d2 | 6953 | .PD 0 |
726f6388 JA |
6954 | .TP |
6955 | \fBsource\fP \fIfilename\fP [\fIarguments\fP] | |
6956 | .PD | |
6957 | Read and execute commands from | |
6958 | .I filename | |
6959 | in the current | |
6960 | shell environment and return the exit status of the last command | |
6961 | executed from | |
6962 | .IR filename . | |
6963 | If | |
6964 | .I filename | |
b28ff8c9 | 6965 | does not contain a slash, filenames in |
726f6388 JA |
6966 | .SM |
6967 | .B PATH | |
6968 | are used to find the directory containing | |
6969 | .IR filename . | |
6970 | The file searched for in | |
6971 | .SM | |
6972 | .B PATH | |
28ef6c31 JA |
6973 | need not be executable. |
6974 | When \fBbash\fP is not in \fIposix mode\fP, the current directory is | |
726f6388 JA |
6975 | searched if no file is found in |
6976 | .SM | |
6977 | .BR PATH . | |
ccc6cda3 JA |
6978 | If the |
6979 | .B sourcepath | |
6980 | option to the | |
6981 | .B shopt | |
6982 | builtin command is turned off, the | |
6983 | .SM | |
6984 | .B PATH | |
6985 | is not searched. | |
726f6388 | 6986 | If any \fIarguments\fP are supplied, they become the positional |
ccc6cda3 | 6987 | parameters when \fIfilename\fP is executed. Otherwise the positional |
726f6388 JA |
6988 | parameters are unchanged. |
6989 | The return status is the status of the last command exited within | |
6990 | the script (0 if no commands are executed), and false if | |
6991 | .I filename | |
cce855bc | 6992 | is not found or cannot be read. |
726f6388 | 6993 | .TP |
ccc6cda3 JA |
6994 | \fBalias\fP [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...] |
6995 | \fBAlias\fP with no arguments or with the | |
6996 | .B \-p | |
6997 | option prints the list of aliases in the form | |
6998 | \fBalias\fP \fIname\fP=\fIvalue\fP on standard output. | |
6999 | When arguments are supplied, an alias is defined for | |
7000 | each \fIname\fP whose \fIvalue\fP is given. | |
fc527055 | 7001 | A trailing space in \fIvalue\fP causes the next word to be |
ccc6cda3 JA |
7002 | checked for alias substitution when the alias is expanded. |
7003 | For each \fIname\fP in the argument list for which no \fIvalue\fP | |
7004 | is supplied, the name and value of the alias is printed. | |
7005 | \fBAlias\fP returns true unless a \fIname\fP is given for which | |
7006 | no alias has been defined. | |
726f6388 | 7007 | .TP |
de3341d1 CR |
7008 | \fBbg\fP [\fIjobspec\fP ...] |
7009 | Resume each suspended job \fIjobspec\fP in the background, as if it | |
cce855bc | 7010 | had been started with |
726f6388 | 7011 | .BR & . |
d3ad40de CR |
7012 | If |
7013 | .I jobspec | |
7014 | is not present, the shell's notion of the \fIcurrent job\fP is used. | |
726f6388 JA |
7015 | .B bg |
7016 | .I jobspec | |
7017 | returns 0 unless run when job control is disabled or, when run with | |
ff247e74 CR |
7018 | job control enabled, any specified \fIjobspec\fP was not found |
7019 | or was started without job control. | |
726f6388 | 7020 | .TP |
ba4ab055 | 7021 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] [\fB\-lpsvPSVX\fP] |
7117c2d2 | 7022 | .PD 0 |
cce855bc JA |
7023 | .TP |
7024 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] [\fB\-q\fP \fIfunction\fP] [\fB\-u\fP \fIfunction\fP] [\fB\-r\fP \fIkeyseq\fP] | |
726f6388 | 7025 | .TP |
ccc6cda3 | 7026 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-f\fP \fIfilename\fP |
726f6388 | 7027 | .TP |
bb70624e JA |
7028 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-x\fP \fIkeyseq\fP:\fIshell\-command\fP |
7029 | .TP | |
ccc6cda3 | 7030 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fIkeyseq\fP:\fIfunction\-name\fP |
7117c2d2 | 7031 | .TP |
66119cfc | 7032 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fIkeyseq\fP:\fIreadline\-command\fP |
726f6388 JA |
7033 | .PD |
7034 | Display current | |
7035 | .B readline | |
7117c2d2 | 7036 | key and function bindings, bind a key sequence to a |
726f6388 | 7037 | .B readline |
7117c2d2 JA |
7038 | function or macro, or set a |
7039 | .B readline | |
7040 | variable. | |
7041 | Each non-option argument is a command as it would appear in | |
726f6388 | 7042 | .IR .inputrc , |
7117c2d2 JA |
7043 | but each binding or command must be passed as a separate argument; |
7044 | e.g., '"\eC\-x\eC\-r": re\-read\-init\-file'. | |
7045 | Options, if supplied, have the following meanings: | |
726f6388 JA |
7046 | .RS |
7047 | .PD 0 | |
7048 | .TP | |
7049 | .B \-m \fIkeymap\fP | |
7050 | Use | |
7051 | .I keymap | |
7052 | as the keymap to be affected by the subsequent bindings. | |
7053 | Acceptable | |
7054 | .I keymap | |
7055 | names are | |
ccc6cda3 | 7056 | \fIemacs, emacs\-standard, emacs\-meta, emacs\-ctlx, vi, |
28ef6c31 | 7057 | vi\-move, vi\-command\fP, and |
ccc6cda3 JA |
7058 | .IR vi\-insert . |
7059 | \fIvi\fP is equivalent to \fIvi\-command\fP; \fIemacs\fP is | |
7060 | equivalent to \fIemacs\-standard\fP. | |
726f6388 JA |
7061 | .TP |
7062 | .B \-l | |
ccc6cda3 JA |
7063 | List the names of all \fBreadline\fP functions. |
7064 | .TP | |
7065 | .B \-p | |
7066 | Display \fBreadline\fP function names and bindings in such a way | |
7067 | that they can be re-read. | |
7068 | .TP | |
7069 | .B \-P | |
7070 | List current \fBreadline\fP function names and bindings. | |
726f6388 | 7071 | .TP |
ccc6cda3 JA |
7072 | .B \-s |
7073 | Display \fBreadline\fP key sequences bound to macros and the strings | |
7074 | they output in such a way that they can be re-read. | |
7075 | .TP | |
7076 | .B \-S | |
7077 | Display \fBreadline\fP key sequences bound to macros and the strings | |
7078 | they output. | |
726f6388 | 7079 | .TP |
d3ad40de CR |
7080 | .B \-v |
7081 | Display \fBreadline\fP variable names and values in such a way that they | |
7082 | can be re-read. | |
7083 | .TP | |
7084 | .B \-V | |
7085 | List current \fBreadline\fP variable names and values. | |
7086 | .TP | |
726f6388 | 7087 | .B \-f \fIfilename\fP |
ccc6cda3 | 7088 | Read key bindings from \fIfilename\fP. |
726f6388 JA |
7089 | .TP |
7090 | .B \-q \fIfunction\fP | |
ccc6cda3 JA |
7091 | Query about which keys invoke the named \fIfunction\fP. |
7092 | .TP | |
cce855bc JA |
7093 | .B \-u \fIfunction\fP |
7094 | Unbind all keys bound to the named \fIfunction\fP. | |
7095 | .TP | |
ccc6cda3 JA |
7096 | .B \-r \fIkeyseq\fP |
7097 | Remove any current binding for \fIkeyseq\fP. | |
bb70624e JA |
7098 | .TP |
7099 | .B \-x \fIkeyseq\fP:\fIshell\-command\fP | |
7100 | Cause \fIshell\-command\fP to be executed whenever \fIkeyseq\fP is | |
7101 | entered. | |
8943768b | 7102 | When \fIshell\-command\fP is executed, the shell sets the |
984a1947 | 7103 | .SM |
8943768b CR |
7104 | .B READLINE_LINE |
7105 | variable to the contents of the \fBreadline\fP line buffer and the | |
984a1947 | 7106 | .SM |
8943768b CR |
7107 | .B READLINE_POINT |
7108 | variable to the current location of the insertion point. | |
7109 | If the executed command changes the value of | |
984a1947 | 7110 | .SM |
8943768b CR |
7111 | .B READLINE_LINE |
7112 | or | |
984a1947 | 7113 | .SM |
8943768b CR |
7114 | .BR READLINE_POINT , |
7115 | those new values will be reflected in the editing state. | |
ba4ab055 CR |
7116 | .TP |
7117 | .B \-X | |
7118 | List all key sequences bound to shell commands and the associated commands | |
7119 | in a format that can be reused as input. | |
726f6388 JA |
7120 | .PD |
7121 | .PP | |
7122 | The return value is 0 unless an unrecognized option is given or an | |
7123 | error occurred. | |
7124 | .RE | |
7125 | .TP | |
7126 | \fBbreak\fP [\fIn\fP] | |
7127 | Exit from within a | |
7128 | .BR for , | |
7129 | .BR while , | |
ccc6cda3 | 7130 | .BR until , |
726f6388 | 7131 | or |
ccc6cda3 | 7132 | .B select |
726f6388 JA |
7133 | loop. If \fIn\fP is specified, break \fIn\fP levels. |
7134 | .I n | |
7135 | must be \(>= 1. If | |
7136 | .I n | |
7137 | is greater than the number of enclosing loops, all enclosing loops | |
33fe8777 CR |
7138 | are exited. |
7139 | The return value is 0 unless \fIn\fP is not greater than or equal to 1. | |
726f6388 JA |
7140 | .TP |
7141 | \fBbuiltin\fP \fIshell\-builtin\fP [\fIarguments\fP] | |
7142 | Execute the specified shell builtin, passing it | |
7143 | .IR arguments , | |
7144 | and return its exit status. | |
cce855bc | 7145 | This is useful when defining a |
726f6388 | 7146 | function whose name is the same as a shell builtin, |
cce855bc JA |
7147 | retaining the functionality of the builtin within the function. |
7148 | The \fBcd\fP builtin is commonly redefined this way. | |
7149 | The return status is false if | |
726f6388 JA |
7150 | .I shell\-builtin |
7151 | is not a shell builtin command. | |
7152 | .TP | |
6a8fd0ed CR |
7153 | \fBcaller\fP [\fIexpr\fP] |
7154 | Returns the context of any active subroutine call (a shell function or | |
5cdaaf76 | 7155 | a script executed with the \fB.\fP or \fBsource\fP builtins). |
6a8fd0ed CR |
7156 | Without \fIexpr\fP, \fBcaller\fP displays the line number and source |
7157 | filename of the current subroutine call. | |
fc527055 | 7158 | If a non-negative integer is supplied as \fIexpr\fP, \fBcaller\fP |
6a8fd0ed CR |
7159 | displays the line number, subroutine name, and source file corresponding |
7160 | to that position in the current execution call stack. This extra | |
7161 | information may be used, for example, to print a stack trace. The | |
7162 | current frame is frame 0. | |
7163 | The return value is 0 unless the shell is not executing a subroutine | |
7164 | call or \fIexpr\fP does not correspond to a valid position in the | |
7165 | call stack. | |
7166 | .TP | |
39feef01 | 7167 | \fBcd\fP [\fB\-L\fP|[\fB\-P\fP [\fB\-e\fP]] [\-@]] [\fIdir\fP] |
2dead0c4 CR |
7168 | Change the current directory to \fIdir\fP. |
7169 | if \fIdir\fP is not supplied, the value of the | |
726f6388 JA |
7170 | .SM |
7171 | .B HOME | |
2dead0c4 CR |
7172 | shell variable is the default. |
7173 | Any additional arguments following \fIdir\fP are ignored. | |
726f6388 JA |
7174 | The variable |
7175 | .SM | |
7176 | .B CDPATH | |
ccc6cda3 | 7177 | defines the search path for the directory containing |
45c0f7f8 CR |
7178 | .IR dir : |
7179 | each directory name in | |
7180 | .SM | |
7181 | .B CDPATH | |
7182 | is searched for \fIdir\fP. | |
ccc6cda3 JA |
7183 | Alternative directory names in |
7184 | .SM | |
7185 | .B CDPATH | |
7186 | are separated by a colon (:). A null directory name in | |
726f6388 JA |
7187 | .SM |
7188 | .B CDPATH | |
ccc6cda3 | 7189 | is the same as the current directory, i.e., ``\fB.\fP''. If |
726f6388 JA |
7190 | .I dir |
7191 | begins with a slash (/), | |
7192 | then | |
7193 | .SM | |
7194 | .B CDPATH | |
fc527055 | 7195 | is not used. The |
ccc6cda3 | 7196 | .B \-P |
45c0f7f8 CR |
7197 | option causes \fBcd\fP to use the physical directory structure |
7198 | by resolving symbolic links while traversing \fIdir\fP and | |
7199 | before processing instances of \fI..\fP in \fIdir\fP (see also the | |
ccc6cda3 JA |
7200 | .B \-P |
7201 | option to the | |
7202 | .B set | |
7203 | builtin command); the | |
7204 | .B \-L | |
45c0f7f8 CR |
7205 | option forces symbolic links to be followed by resolving the link |
7206 | after processing instances of \fI..\fP in \fIdir\fP. | |
7207 | If \fI..\fP appears in \fIdir\fP, it is processed by removing the | |
7208 | immediately previous pathname component from \fIdir\fP, back to a slash | |
7209 | or the beginning of \fIdir\fP. | |
220537f2 CR |
7210 | If the |
7211 | .B \-e | |
7212 | option is supplied with | |
7213 | .BR \-P , | |
7214 | and the current working directory cannot be successfully determined | |
7215 | after a successful directory change, \fBcd\fP will return an unsuccessful | |
7216 | status. | |
39feef01 CR |
7217 | On systems that support it, the \fB\-@\fP option presents the extended |
7218 | attributes associated with a file as a directory. | |
220537f2 | 7219 | An argument of |
726f6388 | 7220 | .B \- |
19baff85 | 7221 | is converted to |
726f6388 | 7222 | .SM |
19baff85 CR |
7223 | .B $OLDPWD |
7224 | before the directory change is attempted. | |
984a1947 CR |
7225 | If a non-empty directory name from |
7226 | .SM | |
7227 | .B CDPATH | |
7228 | is used, or if | |
d3a24ed2 CR |
7229 | \fB\-\fP is the first argument, and the directory change is |
7230 | successful, the absolute pathname of the new working directory is | |
7231 | written to the standard output. | |
726f6388 JA |
7232 | The return value is true if the directory was successfully changed; |
7233 | false otherwise. | |
7234 | .TP | |
ccc6cda3 | 7235 | \fBcommand\fP [\fB\-pVv\fP] \fIcommand\fP [\fIarg\fP ...] |
726f6388 JA |
7236 | Run |
7237 | .I command | |
7238 | with | |
7239 | .I args | |
fc527055 CR |
7240 | suppressing the normal shell function lookup. |
7241 | Only builtin commands or commands found in the | |
726f6388 JA |
7242 | .SM |
7243 | .B PATH | |
7244 | are executed. If the | |
7245 | .B \-p | |
7246 | option is given, the search for | |
7247 | .I command | |
7248 | is performed using a default value for | |
984a1947 | 7249 | .SM |
726f6388 JA |
7250 | .B PATH |
7251 | that is guaranteed to find all of the standard utilities. | |
7252 | If either the | |
7253 | .B \-V | |
7254 | or | |
7255 | .B \-v | |
7256 | option is supplied, a description of | |
7257 | .I command | |
7258 | is printed. The | |
7259 | .B \-v | |
b28ff8c9 | 7260 | option causes a single word indicating the command or filename |
726f6388 JA |
7261 | used to invoke |
7262 | .I command | |
cce855bc | 7263 | to be displayed; the |
726f6388 JA |
7264 | .B \-V |
7265 | option produces a more verbose description. | |
726f6388 JA |
7266 | If the |
7267 | .B \-V | |
7268 | or | |
7269 | .B \-v | |
7270 | option is supplied, the exit status is 0 if | |
7271 | .I command | |
7272 | was found, and 1 if not. If neither option is supplied and | |
7273 | an error occurred or | |
7274 | .I command | |
7275 | cannot be found, the exit status is 127. Otherwise, the exit status of the | |
7276 | .B command | |
7277 | builtin is the exit status of | |
7278 | .IR command . | |
7279 | .TP | |
bb70624e JA |
7280 | \fBcompgen\fP [\fIoption\fP] [\fIword\fP] |
7281 | Generate possible completion matches for \fIword\fP according to | |
7282 | the \fIoption\fPs, which may be any option accepted by the | |
7283 | .B complete | |
7284 | builtin with the exception of \fB\-p\fP and \fB\-r\fP, and write | |
7285 | the matches to the standard output. | |
7286 | When using the \fB\-F\fP or \fB\-C\fP options, the various shell variables | |
7287 | set by the programmable completion facilities, while available, will not | |
7288 | have useful values. | |
7289 | .sp 1 | |
7290 | The matches will be generated in the same way as if the programmable | |
7291 | completion code had generated them directly from a completion specification | |
7292 | with the same flags. | |
7293 | If \fIword\fP is specified, only those completions matching \fIword\fP | |
7294 | will be displayed. | |
7295 | .sp 1 | |
7296 | The return value is true unless an invalid option is supplied, or no | |
7297 | matches were generated. | |
7298 | .TP | |
3eb2d94a | 7299 | \fBcomplete\fP [\fB\-abcdefgjksuv\fP] [\fB\-o\fP \fIcomp-option\fP] [\fB\-DE\fP] [\fB\-A\fP \fIaction\fP] [\fB\-G\fP \fIglobpat\fP] [\fB\-W\fP \fIwordlist\fP] [\fB\-F\fP \fIfunction\fP] [\fB\-C\fP \fIcommand\fP] |
bb70624e | 7300 | .br |
d3ad40de | 7301 | [\fB\-X\fP \fIfilterpat\fP] [\fB\-P\fP \fIprefix\fP] [\fB\-S\fP \fIsuffix\fP] \fIname\fP [\fIname ...\fP] |
7117c2d2 | 7302 | .PD 0 |
bb70624e | 7303 | .TP |
3eb2d94a | 7304 | \fBcomplete\fP \fB\-pr\fP [\fB\-DE\fP] [\fIname\fP ...] |
bb70624e JA |
7305 | .PD |
7306 | Specify how arguments to each \fIname\fP should be completed. | |
7307 | If the \fB\-p\fP option is supplied, or if no options are supplied, | |
7308 | existing completion specifications are printed in a way that allows | |
7309 | them to be reused as input. | |
7310 | The \fB\-r\fP option removes a completion specification for | |
7311 | each \fIname\fP, or, if no \fIname\fPs are supplied, all | |
7312 | completion specifications. | |
3eb2d94a CR |
7313 | The \fB\-D\fP option indicates that the remaining options and actions should |
7314 | apply to the ``default'' command completion; that is, completion attempted | |
7315 | on a command for which no completion has previously been defined. | |
6a8fd0ed CR |
7316 | The \fB\-E\fP option indicates that the remaining options and actions should |
7317 | apply to ``empty'' command completion; that is, completion attempted on a | |
7318 | blank line. | |
bb70624e JA |
7319 | .sp 1 |
7320 | The process of applying these completion specifications when word completion | |
7321 | is attempted is described above under \fBProgrammable Completion\fP. | |
7322 | .sp 1 | |
7323 | Other options, if specified, have the following meanings. | |
7324 | The arguments to the \fB\-G\fP, \fB\-W\fP, and \fB\-X\fP options | |
7325 | (and, if necessary, the \fB\-P\fP and \fB\-S\fP options) | |
7326 | should be quoted to protect them from expansion before the | |
7327 | .B complete | |
7328 | builtin is invoked. | |
7329 | .RS | |
7330 | .PD 0 | |
7331 | .TP 8 | |
28ef6c31 JA |
7332 | \fB\-o\fP \fIcomp-option\fP |
7333 | The \fIcomp-option\fP controls several aspects of the compspec's behavior | |
7334 | beyond the simple generation of completions. | |
7335 | \fIcomp-option\fP may be one of: | |
7336 | .RS | |
7337 | .TP 8 | |
d3a24ed2 CR |
7338 | .B bashdefault |
7339 | Perform the rest of the default \fBbash\fP completions if the compspec | |
7340 | generates no matches. | |
7341 | .TP 8 | |
28ef6c31 | 7342 | .B default |
7117c2d2 JA |
7343 | Use readline's default filename completion if the compspec generates |
7344 | no matches. | |
28ef6c31 JA |
7345 | .TP 8 |
7346 | .B dirnames | |
7347 | Perform directory name completion if the compspec generates no matches. | |
7348 | .TP 8 | |
7349 | .B filenames | |
7350 | Tell readline that the compspec generates filenames, so it can perform any | |
e77a3058 CR |
7351 | filename\-specific processing (like adding a slash to directory names, |
7352 | quoting special characters, or suppressing trailing spaces). | |
7353 | Intended to be used with shell functions. | |
7117c2d2 | 7354 | .TP 8 |
084c952b CR |
7355 | .B noquote |
7356 | Tell readline not to quote the completed words if they are filenames | |
7357 | (quoting filenames is the default). | |
7358 | .TP 8 | |
947f0491 CR |
7359 | .B nosort |
7360 | Tell readline not to sort the list of possible completions alphabetically. | |
7361 | .TP 8 | |
7117c2d2 JA |
7362 | .B nospace |
7363 | Tell readline not to append a space (the default) to words completed at | |
7364 | the end of the line. | |
301e2142 CR |
7365 | .TP 8 |
7366 | .B plusdirs | |
fc527055 | 7367 | After any matches defined by the compspec are generated, |
301e2142 CR |
7368 | directory name completion is attempted and any |
7369 | matches are added to the results of the other actions. | |
28ef6c31 JA |
7370 | .RE |
7371 | .TP 8 | |
bb70624e JA |
7372 | \fB\-A\fP \fIaction\fP |
7373 | The \fIaction\fP may be one of the following to generate a list of possible | |
7374 | completions: | |
7375 | .RS | |
7376 | .TP 8 | |
7377 | .B alias | |
7378 | Alias names. May also be specified as \fB\-a\fP. | |
7379 | .TP 8 | |
7380 | .B arrayvar | |
7381 | Array variable names. | |
7382 | .TP 8 | |
7383 | .B binding | |
7384 | \fBReadline\fP key binding names. | |
7385 | .TP 8 | |
7386 | .B builtin | |
7387 | Names of shell builtin commands. May also be specified as \fB\-b\fP. | |
7388 | .TP 8 | |
7389 | .B command | |
7390 | Command names. May also be specified as \fB\-c\fP. | |
7391 | .TP 8 | |
7392 | .B directory | |
7393 | Directory names. May also be specified as \fB\-d\fP. | |
7394 | .TP 8 | |
7395 | .B disabled | |
7396 | Names of disabled shell builtins. | |
7397 | .TP 8 | |
7398 | .B enabled | |
7399 | Names of enabled shell builtins. | |
7400 | .TP 8 | |
7401 | .B export | |
7402 | Names of exported shell variables. May also be specified as \fB\-e\fP. | |
7403 | .TP 8 | |
7404 | .B file | |
7405 | File names. May also be specified as \fB\-f\fP. | |
7406 | .TP 8 | |
7407 | .B function | |
7408 | Names of shell functions. | |
7409 | .TP 8 | |
f73dda09 JA |
7410 | .B group |
7411 | Group names. May also be specified as \fB\-g\fP. | |
7412 | .TP 8 | |
bb70624e JA |
7413 | .B helptopic |
7414 | Help topics as accepted by the \fBhelp\fP builtin. | |
7415 | .TP 8 | |
7416 | .B hostname | |
7417 | Hostnames, as taken from the file specified by the | |
7418 | .SM | |
7419 | .B HOSTFILE | |
7420 | shell variable. | |
7421 | .TP 8 | |
7422 | .B job | |
7423 | Job names, if job control is active. May also be specified as \fB\-j\fP. | |
7424 | .TP 8 | |
7425 | .B keyword | |
7426 | Shell reserved words. May also be specified as \fB\-k\fP. | |
7427 | .TP 8 | |
7428 | .B running | |
7429 | Names of running jobs, if job control is active. | |
7430 | .TP 8 | |
7117c2d2 JA |
7431 | .B service |
7432 | Service names. May also be specified as \fB\-s\fP. | |
7433 | .TP 8 | |
bb70624e JA |
7434 | .B setopt |
7435 | Valid arguments for the \fB\-o\fP option to the \fBset\fP builtin. | |
7436 | .TP 8 | |
7437 | .B shopt | |
7438 | Shell option names as accepted by the \fBshopt\fP builtin. | |
7439 | .TP 8 | |
7440 | .B signal | |
7441 | Signal names. | |
7442 | .TP 8 | |
7443 | .B stopped | |
7444 | Names of stopped jobs, if job control is active. | |
7445 | .TP 8 | |
7446 | .B user | |
7447 | User names. May also be specified as \fB\-u\fP. | |
7448 | .TP 8 | |
7449 | .B variable | |
7450 | Names of all shell variables. May also be specified as \fB\-v\fP. | |
7451 | .RE | |
7452 | .TP 8 | |
bb70624e JA |
7453 | \fB\-C\fP \fIcommand\fP |
7454 | \fIcommand\fP is executed in a subshell environment, and its output is | |
7455 | used as the possible completions. | |
7456 | .TP 8 | |
7457 | \fB\-F\fP \fIfunction\fP | |
7458 | The shell function \fIfunction\fP is executed in the current shell | |
7459 | environment. | |
ba4ab055 CR |
7460 | When the function is executed, |
7461 | the first argument (\fB$1\fP) is the name of the command whose arguments are | |
7462 | being completed, | |
7463 | the second argument (\fB$2\fP) is the word being completed, | |
7464 | and the third argument (\fB$3\fP) is the word preceding the word being | |
7465 | completed on the current command line. | |
bb70624e JA |
7466 | When it finishes, the possible completions are retrieved from the value |
7467 | of the | |
7468 | .SM | |
7469 | .B COMPREPLY | |
7470 | array variable. | |
7471 | .TP 8 | |
5cdaaf76 CR |
7472 | \fB\-G\fP \fIglobpat\fP |
7473 | The pathname expansion pattern \fIglobpat\fP is expanded to generate | |
7474 | the possible completions. | |
bb70624e JA |
7475 | .TP 8 |
7476 | \fB\-P\fP \fIprefix\fP | |
7477 | \fIprefix\fP is added at the beginning of each possible completion | |
7478 | after all other options have been applied. | |
7479 | .TP 8 | |
7480 | \fB\-S\fP \fIsuffix\fP | |
7481 | \fIsuffix\fP is appended to each possible completion | |
7482 | after all other options have been applied. | |
5cdaaf76 CR |
7483 | .TP 8 |
7484 | \fB\-W\fP \fIwordlist\fP | |
7485 | The \fIwordlist\fP is split using the characters in the | |
7486 | .SM | |
7487 | .B IFS | |
7488 | special variable as delimiters, and each resultant word is expanded. | |
7489 | The possible completions are the members of the resultant list which | |
7490 | match the word being completed. | |
7491 | .TP 8 | |
7492 | \fB\-X\fP \fIfilterpat\fP | |
7493 | \fIfilterpat\fP is a pattern as used for pathname expansion. | |
7494 | It is applied to the list of possible completions generated by the | |
7495 | preceding options and arguments, and each completion matching | |
7496 | \fIfilterpat\fP is removed from the list. | |
7497 | A leading \fB!\fP in \fIfilterpat\fP negates the pattern; in this | |
7498 | case, any completion not matching \fIfilterpat\fP is removed. | |
bb70624e JA |
7499 | .PD |
7500 | .PP | |
7501 | The return value is true unless an invalid option is supplied, an option | |
7502 | other than \fB\-p\fP or \fB\-r\fP is supplied without a \fIname\fP | |
7503 | argument, an attempt is made to remove a completion specification for | |
7504 | a \fIname\fP for which no specification exists, or | |
7505 | an error occurs adding a completion specification. | |
7506 | .RE | |
7507 | .TP | |
3eb2d94a | 7508 | \fBcompopt\fP [\fB\-o\fP \fIoption\fP] [\fB\-DE\fP] [\fB+o\fP \fIoption\fP] [\fIname\fP] |
6fbe7620 CR |
7509 | Modify completion options for each \fIname\fP according to the |
7510 | \fIoption\fPs, or for the | |
5cdaaf76 | 7511 | currently-executing completion if no \fIname\fPs are supplied. |
6fbe7620 CR |
7512 | If no \fIoption\fPs are given, display the completion options for each |
7513 | \fIname\fP or the current completion. | |
7514 | The possible values of \fIoption\fP are those valid for the \fBcomplete\fP | |
7515 | builtin described above. | |
3eb2d94a CR |
7516 | The \fB\-D\fP option indicates that the remaining options should |
7517 | apply to the ``default'' command completion; that is, completion attempted | |
7518 | on a command for which no completion has previously been defined. | |
7519 | The \fB\-E\fP option indicates that the remaining options should | |
7520 | apply to ``empty'' command completion; that is, completion attempted on a | |
7521 | blank line. | |
9c7f20c7 | 7522 | .sp 1 |
6fbe7620 CR |
7523 | The return value is true unless an invalid option is supplied, an attempt |
7524 | is made to modify the options for a \fIname\fP for which no completion | |
7525 | specification exists, or an output error occurs. | |
7526 | .TP | |
726f6388 JA |
7527 | \fBcontinue\fP [\fIn\fP] |
7528 | Resume the next iteration of the enclosing | |
7529 | .BR for , | |
7530 | .BR while , | |
ccc6cda3 | 7531 | .BR until , |
726f6388 | 7532 | or |
ccc6cda3 | 7533 | .B select |
726f6388 JA |
7534 | loop. |
7535 | If | |
7536 | .I n | |
7537 | is specified, resume at the \fIn\fPth enclosing loop. | |
7538 | .I n | |
7539 | must be \(>= 1. If | |
7540 | .I n | |
7541 | is greater than the number of enclosing loops, the last enclosing loop | |
33fe8777 CR |
7542 | (the ``top-level'' loop) is resumed. |
7543 | The return value is 0 unless \fIn\fP is not greater than or equal to 1. | |
726f6388 | 7544 | .TP |
87c1f4ec | 7545 | \fBdeclare\fP [\fB\-aAfFgilnrtux\fP] [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...] |
726f6388 | 7546 | .PD 0 |
726f6388 | 7547 | .TP |
87c1f4ec | 7548 | \fBtypeset\fP [\fB\-aAfFgilnrtux\fP] [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...] |
726f6388 | 7549 | .PD |
ccc6cda3 JA |
7550 | Declare variables and/or give them attributes. |
7551 | If no \fIname\fPs are given then display the values of variables. | |
7552 | The | |
7553 | .B \-p | |
7554 | option will display the attributes and values of each | |
7555 | .IR name . | |
7556 | When | |
7557 | .B \-p | |
fc34b3a4 CR |
7558 | is used with \fIname\fP arguments, additional options, |
7559 | other than \fB\-f\fP and \fB\-F\fP, are ignored. | |
6fbe7620 CR |
7560 | When |
7561 | .B \-p | |
7562 | is supplied without \fIname\fP arguments, it will display the attributes | |
7563 | and values of all variables having the attributes specified by the | |
7564 | additional options. | |
7565 | If no other options are supplied with \fB\-p\fP, \fBdeclare\fP will display | |
7566 | the attributes and values of all shell variables. The \fB\-f\fP option | |
7567 | will restrict the display to shell functions. | |
ccc6cda3 JA |
7568 | The |
7569 | .B \-F | |
7570 | option inhibits the display of function definitions; only the | |
7571 | function name and attributes are printed. | |
d3a24ed2 CR |
7572 | If the \fBextdebug\fP shell option is enabled using \fBshopt\fP, |
7573 | the source file name and line number where the function is defined | |
7574 | are displayed as well. The | |
ccc6cda3 JA |
7575 | .B \-F |
7576 | option implies | |
7577 | .BR \-f . | |
6faad625 CR |
7578 | The |
7579 | .B \-g | |
7580 | option forces variables to be created or modified at the global scope, | |
7581 | even when \fBdeclare\fP is executed in a shell function. | |
7582 | It is ignored in all other cases. | |
ccc6cda3 JA |
7583 | The following options can |
7584 | be used to restrict output to variables with the specified attribute or | |
7585 | to give variables attributes: | |
726f6388 JA |
7586 | .RS |
7587 | .PD 0 | |
7588 | .TP | |
ccc6cda3 | 7589 | .B \-a |
fdf670ea CR |
7590 | Each \fIname\fP is an indexed array variable (see |
7591 | .B Arrays | |
7592 | above). | |
7593 | .TP | |
7594 | .B \-A | |
7595 | Each \fIname\fP is an associative array variable (see | |
ccc6cda3 JA |
7596 | .B Arrays |
7597 | above). | |
7598 | .TP | |
726f6388 | 7599 | .B \-f |
ccc6cda3 JA |
7600 | Use function names only. |
7601 | .TP | |
7602 | .B \-i | |
7603 | The variable is treated as an integer; arithmetic evaluation (see | |
7604 | .SM | |
984a1947 CR |
7605 | .B "ARITHMETIC EVALUATION" |
7606 | above) is performed when the variable is assigned a value. | |
726f6388 | 7607 | .TP |
09767ff0 CR |
7608 | .B \-l |
7609 | When the variable is assigned a value, all upper-case characters are | |
7610 | converted to lower-case. | |
7611 | The upper-case attribute is disabled. | |
7612 | .TP | |
87c1f4ec CR |
7613 | .B \-n |
7614 | Give each \fIname\fP the \fInameref\fP attribute, making | |
7615 | it a name reference to another variable. | |
7616 | That other variable is defined by the value of \fIname\fP. | |
d2465f43 CR |
7617 | All references, assignments, and attribute modifications |
7618 | to \fIname\fP, except for changing the | |
87c1f4ec CR |
7619 | \fB\-n\fP attribute itself, are performed on the variable referenced by |
7620 | \fIname\fP's value. | |
d2465f43 | 7621 | The nameref attribute cannot be applied to array variables. |
87c1f4ec | 7622 | .TP |
726f6388 JA |
7623 | .B \-r |
7624 | Make \fIname\fPs readonly. These names cannot then be assigned values | |
cce855bc | 7625 | by subsequent assignment statements or unset. |
726f6388 | 7626 | .TP |
7117c2d2 JA |
7627 | .B \-t |
7628 | Give each \fIname\fP the \fItrace\fP attribute. | |
76a8d78d CR |
7629 | Traced functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps from |
7630 | the calling shell. | |
7117c2d2 JA |
7631 | The trace attribute has no special meaning for variables. |
7632 | .TP | |
09767ff0 CR |
7633 | .B \-u |
7634 | When the variable is assigned a value, all lower-case characters are | |
7635 | converted to upper-case. | |
7636 | The lower-case attribute is disabled. | |
7637 | .TP | |
726f6388 JA |
7638 | .B \-x |
7639 | Mark \fIname\fPs for export to subsequent commands via the environment. | |
726f6388 JA |
7640 | .PD |
7641 | .PP | |
7642 | Using `+' instead of `\-' | |
d3ad40de CR |
7643 | turns off the attribute instead, |
7644 | with the exceptions that \fB+a\fP | |
984a1947 | 7645 | may not be used to destroy an array variable and \fB+r\fP will not |
d3ad40de | 7646 | remove the readonly attribute. |
b28ff8c9 CR |
7647 | When used in a function, |
7648 | .B declare | |
7649 | and | |
7650 | .B typeset | |
7651 | make each | |
54a1fa7c | 7652 | \fIname\fP local, as with the |
726f6388 | 7653 | .B local |
6faad625 | 7654 | command, |
b28ff8c9 | 7655 | unless the \fB\-g\fP option is supplied. |
d3a24ed2 CR |
7656 | If a variable name is followed by =\fIvalue\fP, the value of |
7657 | the variable is set to \fIvalue\fP. | |
595e3e69 CR |
7658 | When using \fB\-a\fP or \fB\-A\fP and the compound assignment syntax to |
7659 | create array variables, additional attributes do not take effect until | |
7660 | subsequent assignments. | |
d3a24ed2 | 7661 | The return value is 0 unless an invalid option is encountered, |
bb70624e JA |
7662 | an attempt is made to define a function using |
7663 | .if n ``\-f foo=bar'', | |
7664 | .if t \f(CW\-f foo=bar\fP, | |
ccc6cda3 JA |
7665 | an attempt is made to assign a value to a readonly variable, |
7666 | an attempt is made to assign a value to an array variable without | |
7667 | using the compound assignment syntax (see | |
7668 | .B Arrays | |
cce855bc | 7669 | above), one of the \fInames\fP is not a valid shell variable name, |
726f6388 | 7670 | an attempt is made to turn off readonly status for a readonly variable, |
ccc6cda3 | 7671 | an attempt is made to turn off array status for an array variable, |
bb70624e | 7672 | or an attempt is made to display a non-existent function with \fB\-f\fP. |
726f6388 JA |
7673 | .RE |
7674 | .TP | |
b28ff8c9 | 7675 | .B dirs [\fB\-clpv\fP] [+\fIn\fP] [\-\fIn\fP] |
ccc6cda3 JA |
7676 | Without options, displays the list of currently remembered directories. |
7677 | The default display is on a single line with directory names separated | |
7678 | by spaces. | |
fc527055 | 7679 | Directories are added to the list with the |
726f6388 JA |
7680 | .B pushd |
7681 | command; the | |
7682 | .B popd | |
ccc6cda3 | 7683 | command removes entries from the list. |
726f6388 JA |
7684 | .RS |
7685 | .PD 0 | |
7686 | .TP | |
ccc6cda3 JA |
7687 | .B \-c |
7688 | Clears the directory stack by deleting all of the entries. | |
7689 | .TP | |
726f6388 | 7690 | .B \-l |
b28ff8c9 CR |
7691 | Produces a listing using full pathnames; |
7692 | the default listing format uses a tilde to denote the home directory. | |
ccc6cda3 JA |
7693 | .TP |
7694 | .B \-p | |
7695 | Print the directory stack with one entry per line. | |
7696 | .TP | |
7697 | .B \-v | |
7698 | Print the directory stack with one entry per line, | |
7699 | prefixing each entry with its index in the stack. | |
b28ff8c9 CR |
7700 | .TP |
7701 | \fB+\fP\fIn\fP | |
7702 | Displays the \fIn\fPth entry counting from the left of the list | |
7703 | shown by | |
7704 | .B dirs | |
7705 | when invoked without options, starting with zero. | |
7706 | .TP | |
7707 | \fB\-\fP\fIn\fP | |
7708 | Displays the \fIn\fPth entry counting from the right of the list | |
7709 | shown by | |
7710 | .B dirs | |
7711 | when invoked without options, starting with zero. | |
726f6388 JA |
7712 | .PD |
7713 | .PP | |
7714 | The return value is 0 unless an | |
cce855bc | 7715 | invalid option is supplied or \fIn\fP indexes beyond the end |
726f6388 JA |
7716 | of the directory stack. |
7717 | .RE | |
7718 | .TP | |
cce855bc | 7719 | \fBdisown\fP [\fB\-ar\fP] [\fB\-h\fP] [\fIjobspec\fP ...] |
b28ff8c9 | 7720 | Without options, remove each |
ccc6cda3 | 7721 | .I jobspec |
b28ff8c9 | 7722 | from the table of active jobs. |
d3ad40de CR |
7723 | If |
7724 | .I jobspec | |
912dc4e9 CR |
7725 | is not present, and neither the \fB\-a\fP nor the \fB\-r\fP option |
7726 | is supplied, the \fIcurrent job\fP is used. | |
cce855bc JA |
7727 | If the \fB\-h\fP option is given, each |
7728 | .I jobspec | |
7729 | is not removed from the table, but is marked so that | |
ccc6cda3 JA |
7730 | .SM |
7731 | .B SIGHUP | |
7732 | is not sent to the job if the shell receives a | |
7733 | .SM | |
7734 | .BR SIGHUP . | |
7735 | If no | |
7736 | .I jobspec | |
cce855bc JA |
7737 | is supplied, the |
7738 | .B \-a | |
7739 | option means to remove or mark all jobs; the | |
7740 | .B \-r | |
7741 | option without a | |
7742 | .I jobspec | |
7743 | argument restricts operation to running jobs. | |
7744 | The return value is 0 unless a | |
ccc6cda3 JA |
7745 | .I jobspec |
7746 | does not specify a valid job. | |
7747 | .TP | |
726f6388 | 7748 | \fBecho\fP [\fB\-neE\fP] [\fIarg\fP ...] |
ccc6cda3 | 7749 | Output the \fIarg\fPs, separated by spaces, followed by a newline. |
f6da9f85 | 7750 | The return status is 0 unless a write error occurs. |
ccc6cda3 | 7751 | If \fB\-n\fP is specified, the trailing newline is |
726f6388 JA |
7752 | suppressed. If the \fB\-e\fP option is given, interpretation of |
7753 | the following backslash-escaped characters is enabled. The | |
7754 | .B \-E | |
7755 | option disables the interpretation of these escape characters, | |
7756 | even on systems where they are interpreted by default. | |
28ef6c31 | 7757 | The \fBxpg_echo\fP shell option may be used to |
bb70624e JA |
7758 | dynamically determine whether or not \fBecho\fP expands these |
7759 | escape characters by default. | |
ccc6cda3 | 7760 | .B echo |
3ffb039a | 7761 | does not interpret \fB\-\-\fP to mean the end of options. |
ccc6cda3 JA |
7762 | .B echo |
7763 | interprets the following escape sequences: | |
726f6388 JA |
7764 | .RS |
7765 | .PD 0 | |
7766 | .TP | |
7767 | .B \ea | |
7768 | alert (bell) | |
7769 | .TP | |
7770 | .B \eb | |
7771 | backspace | |
7772 | .TP | |
7773 | .B \ec | |
2e4498b3 | 7774 | suppress further output |
726f6388 | 7775 | .TP |
ccc6cda3 | 7776 | .B \ee |
9ec5ed66 CR |
7777 | .TP |
7778 | .B \eE | |
ccc6cda3 JA |
7779 | an escape character |
7780 | .TP | |
726f6388 JA |
7781 | .B \ef |
7782 | form feed | |
7783 | .TP | |
7784 | .B \en | |
7785 | new line | |
7786 | .TP | |
7787 | .B \er | |
7788 | carriage return | |
7789 | .TP | |
7790 | .B \et | |
7791 | horizontal tab | |
7792 | .TP | |
7793 | .B \ev | |
7794 | vertical tab | |
7795 | .TP | |
7796 | .B \e\e | |
7797 | backslash | |
7798 | .TP | |
7117c2d2 JA |
7799 | .B \e0\fInnn\fP |
7800 | the eight-bit character whose value is the octal value \fInnn\fP | |
7801 | (zero to three octal digits) | |
7802 | .TP | |
f73dda09 JA |
7803 | .B \ex\fIHH\fP |
7804 | the eight-bit character whose value is the hexadecimal value \fIHH\fP | |
7805 | (one or two hex digits) | |
eb0b2ad8 CR |
7806 | .TP |
7807 | .B \eu\fIHHHH\fP | |
7808 | the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value | |
7809 | \fIHHHH\fP (one to four hex digits) | |
7810 | .TP | |
7811 | .B \eU\fIHHHHHHHH\fP | |
7812 | the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value | |
7813 | \fIHHHHHHHH\fP (one to eight hex digits) | |
726f6388 JA |
7814 | .PD |
7815 | .RE | |
7816 | .TP | |
d3ad40de | 7817 | \fBenable\fP [\fB\-a\fP] [\fB\-dnps\fP] [\fB\-f\fP \fIfilename\fP] [\fIname\fP ...] |
cce855bc JA |
7818 | Enable and disable builtin shell commands. |
7819 | Disabling a builtin allows a disk command which has the same name | |
bb70624e | 7820 | as a shell builtin to be executed without specifying a full pathname, |
cce855bc | 7821 | even though the shell normally searches for builtins before disk commands. |
726f6388 JA |
7822 | If \fB\-n\fP is used, each \fIname\fP |
7823 | is disabled; otherwise, | |
7824 | \fInames\fP are enabled. For example, to use the | |
7825 | .B test | |
7826 | binary found via the | |
7827 | .SM | |
7828 | .B PATH | |
ccc6cda3 | 7829 | instead of the shell builtin version, run |
28ef6c31 JA |
7830 | .if t \f(CWenable -n test\fP. |
7831 | .if n ``enable -n test''. | |
ccc6cda3 JA |
7832 | The |
7833 | .B \-f | |
7834 | option means to load the new builtin command | |
7835 | .I name | |
7836 | from shared object | |
7837 | .IR filename , | |
7838 | on systems that support dynamic loading. The | |
7839 | .B \-d | |
7840 | option will delete a builtin previously loaded with | |
7841 | .BR \-f . | |
7842 | If no \fIname\fP arguments are given, or if the | |
7843 | .B \-p | |
7844 | option is supplied, a list of shell builtins is printed. | |
7845 | With no other option arguments, the list consists of all enabled | |
7846 | shell builtins. | |
7847 | If \fB\-n\fP is supplied, only disabled builtins are printed. | |
7848 | If \fB\-a\fP is supplied, the list printed includes all builtins, with an | |
726f6388 | 7849 | indication of whether or not each is enabled. |
ccc6cda3 JA |
7850 | If \fB\-s\fP is supplied, the output is restricted to the POSIX |
7851 | \fIspecial\fP builtins. | |
726f6388 JA |
7852 | The return value is 0 unless a |
7853 | .I name | |
bb70624e | 7854 | is not a shell builtin or there is an error loading a new builtin |
ccc6cda3 | 7855 | from a shared object. |
726f6388 JA |
7856 | .TP |
7857 | \fBeval\fP [\fIarg\fP ...] | |
7858 | The \fIarg\fPs are read and concatenated together into a single | |
7859 | command. This command is then read and executed by the shell, and | |
ccc6cda3 JA |
7860 | its exit status is returned as the value of |
7861 | .BR eval . | |
7862 | If there are no | |
726f6388 JA |
7863 | .IR args , |
7864 | or only null arguments, | |
7865 | .B eval | |
ccc6cda3 | 7866 | returns 0. |
726f6388 | 7867 | .TP |
cce855bc | 7868 | \fBexec\fP [\fB\-cl\fP] [\fB\-a\fP \fIname\fP] [\fIcommand\fP [\fIarguments\fP]] |
726f6388 JA |
7869 | If |
7870 | .I command | |
7871 | is specified, it replaces the shell. | |
7872 | No new process is created. The | |
7873 | .I arguments | |
7874 | become the arguments to \fIcommand\fP. | |
ccc6cda3 JA |
7875 | If the |
7876 | .B \-l | |
7877 | option is supplied, | |
fc527055 | 7878 | the shell places a dash at the beginning of the zeroth argument passed to |
726f6388 | 7879 | .IR command . |
ccc6cda3 JA |
7880 | This is what |
7881 | .IR login (1) | |
7882 | does. The | |
7883 | .B \-c | |
7884 | option causes | |
7885 | .I command | |
7886 | to be executed with an empty environment. If | |
7887 | .B \-a | |
7888 | is supplied, the shell passes | |
7889 | .I name | |
b28ff8c9 CR |
7890 | as the zeroth argument to the executed command. |
7891 | If | |
ccc6cda3 | 7892 | .I command |
726f6388 | 7893 | cannot be executed for some reason, a non-interactive shell exits, |
b28ff8c9 | 7894 | unless the |
ccc6cda3 | 7895 | .B execfail |
b28ff8c9 CR |
7896 | shell option |
7897 | is enabled. In that case, it returns failure. | |
ccc6cda3 | 7898 | An interactive shell returns failure if the file cannot be executed. |
726f6388 JA |
7899 | If |
7900 | .I command | |
7901 | is not specified, any redirections take effect in the current shell, | |
cce855bc JA |
7902 | and the return status is 0. If there is a redirection error, the |
7903 | return status is 1. | |
726f6388 JA |
7904 | .TP |
7905 | \fBexit\fP [\fIn\fP] | |
7906 | Cause the shell to exit | |
7907 | with a status of \fIn\fP. If | |
7908 | .I n | |
7909 | is omitted, the exit status | |
7910 | is that of the last command executed. | |
7911 | A trap on | |
7912 | .SM | |
7913 | .B EXIT | |
7914 | is executed before the shell terminates. | |
7915 | .TP | |
ccc6cda3 | 7916 | \fBexport\fP [\fB\-fn\fP\^] [\fIname\fP[=\fIword\fP]] ... |
7117c2d2 | 7917 | .PD 0 |
726f6388 JA |
7918 | .TP |
7919 | .B export \-p | |
7920 | .PD | |
7921 | The supplied | |
7922 | .I names | |
7923 | are marked for automatic export to the environment of | |
fc527055 | 7924 | subsequently executed commands. If the |
726f6388 | 7925 | .B \-f |
fc527055 | 7926 | option is given, the |
726f6388 JA |
7927 | .I names |
7928 | refer to functions. | |
7929 | If no | |
7930 | .I names | |
7931 | are given, or if the | |
7932 | .B \-p | |
7933 | option is supplied, a list | |
b28ff8c9 | 7934 | of names of all exported variables is printed. |
726f6388 JA |
7935 | The |
7936 | .B \-n | |
5e13499c CR |
7937 | option causes the export property to be removed from each |
7938 | \fIname\fP. | |
d3a24ed2 CR |
7939 | If a variable name is followed by =\fIword\fP, the value of |
7940 | the variable is set to \fIword\fP. | |
726f6388 | 7941 | .B export |
cce855bc | 7942 | returns an exit status of 0 unless an invalid option is |
726f6388 | 7943 | encountered, |
cce855bc | 7944 | one of the \fInames\fP is not a valid shell variable name, or |
726f6388 JA |
7945 | .B \-f |
7946 | is supplied with a | |
7947 | .I name | |
7948 | that is not a function. | |
7949 | .TP | |
d3ad40de | 7950 | \fBfc\fP [\fB\-e\fP \fIename\fP] [\fB\-lnr\fP] [\fIfirst\fP] [\fIlast\fP] |
7117c2d2 | 7951 | .PD 0 |
726f6388 JA |
7952 | .TP |
7953 | \fBfc\fP \fB\-s\fP [\fIpat\fP=\fIrep\fP] [\fIcmd\fP] | |
7954 | .PD | |
b28ff8c9 | 7955 | The first form selects a range of commands from |
726f6388 JA |
7956 | .I first |
7957 | to | |
7958 | .I last | |
b28ff8c9 | 7959 | from the history list and displays or edits and re-executes them. |
726f6388 JA |
7960 | .I First |
7961 | and | |
7962 | .I last | |
7963 | may be specified as a string (to locate the last command beginning | |
7964 | with that string) or as a number (an index into the history list, | |
7965 | where a negative number is used as an offset from the current | |
fc527055 | 7966 | command number). If |
726f6388 JA |
7967 | .I last |
7968 | is not specified it is set to | |
7969 | the current command for listing (so that | |
bb70624e JA |
7970 | .if n ``fc \-l \-10'' |
7971 | .if t \f(CWfc \-l \-10\fP | |
726f6388 JA |
7972 | prints the last 10 commands) and to |
7973 | .I first | |
7974 | otherwise. | |
7975 | If | |
7976 | .I first | |
7977 | is not specified it is set to the previous | |
7978 | command for editing and \-16 for listing. | |
7979 | .sp 1 | |
7980 | The | |
7981 | .B \-n | |
cce855bc | 7982 | option suppresses |
726f6388 JA |
7983 | the command numbers when listing. The |
7984 | .B \-r | |
cce855bc | 7985 | option reverses the order of |
726f6388 JA |
7986 | the commands. If the |
7987 | .B \-l | |
cce855bc | 7988 | option is given, |
726f6388 JA |
7989 | the commands are listed on |
7990 | standard output. Otherwise, the editor given by | |
7991 | .I ename | |
7992 | is invoked | |
7993 | on a file containing those commands. If | |
7994 | .I ename | |
7995 | is not given, the | |
7996 | value of the | |
7997 | .SM | |
7998 | .B FCEDIT | |
7999 | variable is used, and | |
8000 | the value of | |
8001 | .SM | |
8002 | .B EDITOR | |
8003 | if | |
8004 | .SM | |
8005 | .B FCEDIT | |
8006 | is not set. If neither variable is set, | |
8007 | .FN vi | |
8008 | is used. When editing is complete, the edited commands are | |
8009 | echoed and executed. | |
8010 | .sp 1 | |
8011 | In the second form, \fIcommand\fP is re-executed after each instance | |
8012 | of \fIpat\fP is replaced by \fIrep\fP. | |
b28ff8c9 | 8013 | \fICommand\fP is intepreted the same as \fIfirst\fP above. |
ccc6cda3 | 8014 | A useful alias to use with this is |
d3a24ed2 | 8015 | .if n ``r="fc -s"'', |
ccc6cda3 JA |
8016 | .if t \f(CWr='fc \-s'\fP, |
8017 | so that typing | |
8018 | .if n ``r cc'' | |
8019 | .if t \f(CWr cc\fP | |
8020 | runs the last command beginning with | |
8021 | .if n ``cc'' | |
8022 | .if t \f(CWcc\fP | |
8023 | and typing | |
8024 | .if n ``r'' | |
8025 | .if t \f(CWr\fP | |
726f6388 JA |
8026 | re-executes the last command. |
8027 | .sp 1 | |
cce855bc | 8028 | If the first form is used, the return value is 0 unless an invalid |
726f6388 JA |
8029 | option is encountered or |
8030 | .I first | |
8031 | or | |
8032 | .I last | |
8033 | specify history lines out of range. | |
8034 | If the | |
8035 | .B \-e | |
8036 | option is supplied, the return value is the value of the last | |
8037 | command executed or failure if an error occurs with the temporary | |
8038 | file of commands. If the second form is used, the return status | |
8039 | is that of the command re-executed, unless | |
8040 | .I cmd | |
8041 | does not specify a valid history line, in which case | |
8042 | .B fc | |
8043 | returns failure. | |
8044 | .TP | |
8045 | \fBfg\fP [\fIjobspec\fP] | |
cce855bc | 8046 | Resume |
726f6388 | 8047 | .I jobspec |
cce855bc JA |
8048 | in the foreground, and make it the current job. |
8049 | If | |
726f6388 JA |
8050 | .I jobspec |
8051 | is not present, the shell's notion of the \fIcurrent job\fP is used. | |
8052 | The return value is that of the command placed into the foreground, | |
8053 | or failure if run when job control is disabled or, when run with | |
8054 | job control enabled, if | |
8055 | .I jobspec | |
8056 | does not specify a valid job or | |
8057 | .I jobspec | |
8058 | specifies a job that was started without job control. | |
8059 | .TP | |
8060 | \fBgetopts\fP \fIoptstring\fP \fIname\fP [\fIargs\fP] | |
8061 | .B getopts | |
8062 | is used by shell procedures to parse positional parameters. | |
8063 | .I optstring | |
bb70624e | 8064 | contains the option characters to be recognized; if a character |
726f6388 JA |
8065 | is followed by a colon, the option is expected to have an |
8066 | argument, which should be separated from it by white space. | |
bb70624e JA |
8067 | The colon and question mark characters may not be used as |
8068 | option characters. | |
726f6388 JA |
8069 | Each time it is invoked, |
8070 | .B getopts | |
8071 | places the next option in the shell variable | |
8072 | .IR name , | |
8073 | initializing | |
8074 | .I name | |
8075 | if it does not exist, | |
8076 | and the index of the next argument to be processed into the | |
8077 | variable | |
8078 | .SM | |
8079 | .BR OPTIND . | |
8080 | .SM | |
8081 | .B OPTIND | |
8082 | is initialized to 1 each time the shell or a shell script | |
8083 | is invoked. When an option requires an argument, | |
8084 | .B getopts | |
8085 | places that argument into the variable | |
8086 | .SM | |
8087 | .BR OPTARG . | |
8088 | The shell does not reset | |
8089 | .SM | |
8090 | .B OPTIND | |
8091 | automatically; it must be manually reset between multiple | |
8092 | calls to | |
8093 | .B getopts | |
8094 | within the same shell invocation if a new set of parameters | |
8095 | is to be used. | |
8096 | .sp 1 | |
cce855bc JA |
8097 | When the end of options is encountered, \fBgetopts\fP exits with a |
8098 | return value greater than zero. | |
984a1947 CR |
8099 | .SM |
8100 | .B OPTIND | |
8101 | is set to the index of the first non-option argument, | |
dc60d4e0 | 8102 | and \fIname\fP is set to ?. |
cce855bc JA |
8103 | .sp 1 |
8104 | .B getopts | |
8105 | normally parses the positional parameters, but if more arguments are | |
8106 | given in | |
8107 | .IR args , | |
8108 | .B getopts | |
8109 | parses those instead. | |
8110 | .sp 1 | |
726f6388 JA |
8111 | .B getopts |
8112 | can report errors in two ways. If the first character of | |
8113 | .I optstring | |
8114 | is a colon, | |
8115 | .I silent | |
b28ff8c9 | 8116 | error reporting is used. In normal operation, diagnostic messages |
cce855bc | 8117 | are printed when invalid options or missing option arguments are |
726f6388 JA |
8118 | encountered. |
8119 | If the variable | |
8120 | .SM | |
8121 | .B OPTERR | |
cce855bc | 8122 | is set to 0, no error messages will be displayed, even if the first |
fc527055 | 8123 | character of |
726f6388 JA |
8124 | .I optstring |
8125 | is not a colon. | |
8126 | .sp 1 | |
cce855bc | 8127 | If an invalid option is seen, |
726f6388 JA |
8128 | .B getopts |
8129 | places ? into | |
8130 | .I name | |
8131 | and, if not silent, | |
8132 | prints an error message and unsets | |
8133 | .SM | |
8134 | .BR OPTARG . | |
8135 | If | |
8136 | .B getopts | |
8137 | is silent, | |
8138 | the option character found is placed in | |
8139 | .SM | |
8140 | .B OPTARG | |
8141 | and no diagnostic message is printed. | |
8142 | .sp 1 | |
8143 | If a required argument is not found, and | |
8144 | .B getopts | |
8145 | is not silent, | |
8146 | a question mark (\^\fB?\fP\^) is placed in | |
8147 | .IR name , | |
f73dda09 | 8148 | .SM |
726f6388 JA |
8149 | .B OPTARG |
8150 | is unset, and a diagnostic message is printed. | |
8151 | If | |
8152 | .B getopts | |
8153 | is silent, then a colon (\^\fB:\fP\^) is placed in | |
8154 | .I name | |
8155 | and | |
8156 | .SM | |
8157 | .B OPTARG | |
8158 | is set to the option character found. | |
8159 | .sp 1 | |
8160 | .B getopts | |
726f6388 JA |
8161 | returns true if an option, specified or unspecified, is found. |
8162 | It returns false if the end of options is encountered or an | |
8163 | error occurs. | |
8164 | .TP | |
7117c2d2 | 8165 | \fBhash\fP [\fB\-lr\fP] [\fB\-p\fP \fIfilename\fP] [\fB\-dt\fP] [\fIname\fP] |
4691dc6b | 8166 | Each time \fBhash\fP is invoked, |
fc527055 | 8167 | the full pathname of the command |
4691dc6b CR |
8168 | .I name |
8169 | is determined by searching | |
ccc6cda3 JA |
8170 | the directories in |
8171 | .B $PATH | |
4691dc6b | 8172 | and remembered. Any previously-remembered pathname is discarded. |
ccc6cda3 JA |
8173 | If the |
8174 | .B \-p | |
8175 | option is supplied, no path search is performed, and | |
8176 | .I filename | |
b28ff8c9 | 8177 | is used as the full filename of the command. |
ccc6cda3 | 8178 | The |
726f6388 JA |
8179 | .B \-r |
8180 | option causes the shell to forget all | |
f73dda09 | 8181 | remembered locations. |
7117c2d2 JA |
8182 | The |
8183 | .B \-d | |
8184 | option causes the shell to forget the remembered location of each \fIname\fP. | |
f73dda09 JA |
8185 | If the |
8186 | .B \-t | |
8187 | option is supplied, the full pathname to which each \fIname\fP corresponds | |
8188 | is printed. If multiple \fIname\fP arguments are supplied with \fB\-t\fP, | |
8189 | the \fIname\fP is printed before the hashed full pathname. | |
7117c2d2 JA |
8190 | The |
8191 | .B \-l | |
8192 | option causes output to be displayed in a format that may be reused as input. | |
8193 | If no arguments are given, or if only \fB\-l\fP is supplied, | |
8194 | information about remembered commands is printed. | |
ccc6cda3 | 8195 | The return status is true unless a |
726f6388 | 8196 | .I name |
cce855bc | 8197 | is not found or an invalid option is supplied. |
726f6388 | 8198 | .TP |
6a8fd0ed | 8199 | \fBhelp\fP [\fB\-dms\fP] [\fIpattern\fP] |
726f6388 JA |
8200 | Display helpful information about builtin commands. If |
8201 | .I pattern | |
8202 | is specified, | |
8203 | .B help | |
8204 | gives detailed help on all commands matching | |
8205 | .IR pattern ; | |
ccc6cda3 | 8206 | otherwise help for all the builtins and shell control structures |
bb70624e | 8207 | is printed. |
6a8fd0ed CR |
8208 | .RS |
8209 | .PD 0 | |
8210 | .TP | |
8211 | .B \-d | |
8212 | Display a short description of each \fIpattern\fP | |
8213 | .TP | |
6932f7f5 | 8214 | .B \-m |
6a8fd0ed CR |
8215 | Display the description of each \fIpattern\fP in a manpage-like format |
8216 | .TP | |
8217 | .B \-s | |
8218 | Display only a short usage synopsis for each \fIpattern\fP | |
8219 | .PD | |
54a1fa7c | 8220 | .PP |
bb70624e | 8221 | The return status is 0 unless no command matches |
726f6388 | 8222 | .IR pattern . |
54a1fa7c | 8223 | .RE |
726f6388 | 8224 | .TP |
bb70624e | 8225 | \fBhistory [\fIn\fP] |
7117c2d2 | 8226 | .PD 0 |
bb70624e JA |
8227 | .TP |
8228 | \fBhistory\fP \fB\-c\fP | |
8229 | .TP | |
8230 | \fBhistory \-d\fP \fIoffset\fP | |
ccc6cda3 JA |
8231 | .TP |
8232 | \fBhistory\fP \fB\-anrw\fP [\fIfilename\fP] | |
726f6388 | 8233 | .TP |
ccc6cda3 JA |
8234 | \fBhistory\fP \fB\-p\fP \fIarg\fP [\fIarg ...\fP] |
8235 | .TP | |
8236 | \fBhistory\fP \fB\-s\fP \fIarg\fP [\fIarg ...\fP] | |
726f6388 JA |
8237 | .PD |
8238 | With no options, display the command | |
8239 | history list with line numbers. Lines listed | |
fc527055 | 8240 | with a |
726f6388 JA |
8241 | .B * |
8242 | have been modified. An argument of | |
8243 | .I n | |
8244 | lists only the last | |
8245 | .I n | |
d3a24ed2 | 8246 | lines. |
984a1947 CR |
8247 | If the shell variable |
8248 | .SM | |
8249 | .B HISTTIMEFORMAT | |
8250 | is set and not null, | |
d3a24ed2 CR |
8251 | it is used as a format string for \fIstrftime\fP(3) to display |
8252 | the time stamp associated with each displayed history entry. | |
8253 | No intervening blank is printed between the formatted time stamp | |
8254 | and the history line. | |
8255 | If \fIfilename\fP is supplied, it is used as the | |
726f6388 JA |
8256 | name of the history file; if not, the value of |
8257 | .SM | |
8258 | .B HISTFILE | |
8259 | is used. Options, if supplied, have the following meanings: | |
8260 | .RS | |
8261 | .PD 0 | |
8262 | .TP | |
bb70624e JA |
8263 | .B \-c |
8264 | Clear the history list by deleting all the entries. | |
8265 | .TP | |
8266 | \fB\-d\fP \fIoffset\fP | |
8267 | Delete the history entry at position \fIoffset\fP. | |
8268 | .TP | |
726f6388 JA |
8269 | .B \-a |
8270 | Append the ``new'' history lines (history lines entered since the | |
ccc6cda3 | 8271 | beginning of the current \fBbash\fP session) to the history file. |
726f6388 JA |
8272 | .TP |
8273 | .B \-n | |
8274 | Read the history lines not already read from the history | |
8275 | file into the current history list. These are lines | |
8276 | appended to the history file since the beginning of the | |
8277 | current \fBbash\fP session. | |
8278 | .TP | |
8279 | .B \-r | |
8280 | Read the contents of the history file | |
b28ff8c9 | 8281 | and append them to the current history list. |
726f6388 JA |
8282 | .TP |
8283 | .B \-w | |
b28ff8c9 | 8284 | Write the current history list to the history file, overwriting the |
726f6388 | 8285 | history file's contents. |
ccc6cda3 | 8286 | .TP |
ccc6cda3 JA |
8287 | .B \-p |
8288 | Perform history substitution on the following \fIargs\fP and display | |
8289 | the result on the standard output. | |
8290 | Does not store the results in the history list. | |
8291 | Each \fIarg\fP must be quoted to disable normal history expansion. | |
8292 | .TP | |
8293 | .B \-s | |
8294 | Store the | |
8295 | .I args | |
8296 | in the history list as a single entry. The last command in the | |
8297 | history list is removed before the | |
8298 | .I args | |
8299 | are added. | |
726f6388 JA |
8300 | .PD |
8301 | .PP | |
984a1947 CR |
8302 | If the |
8303 | .SM | |
8304 | .B HISTTIMEFORMAT | |
8305 | variable is set, the time stamp information | |
d3ad40de CR |
8306 | associated with each history entry is written to the history file, |
8307 | marked with the history comment character. | |
8308 | When the history file is read, lines beginning with the history | |
8309 | comment character followed immediately by a digit are interpreted | |
8310 | as timestamps for the previous history line. | |
bb70624e JA |
8311 | The return value is 0 unless an invalid option is encountered, an |
8312 | error occurs while reading or writing the history file, an invalid | |
8313 | \fIoffset\fP is supplied as an argument to \fB\-d\fP, or the | |
8314 | history expansion supplied as an argument to \fB\-p\fP fails. | |
726f6388 JA |
8315 | .RE |
8316 | .TP | |
ccc6cda3 | 8317 | \fBjobs\fP [\fB\-lnprs\fP] [ \fIjobspec\fP ... ] |
7117c2d2 | 8318 | .PD 0 |
726f6388 JA |
8319 | .TP |
8320 | \fBjobs\fP \fB\-x\fP \fIcommand\fP [ \fIargs\fP ... ] | |
8321 | .PD | |
ccc6cda3 JA |
8322 | The first form lists the active jobs. The options have the following |
8323 | meanings: | |
8324 | .RS | |
8325 | .PD 0 | |
8326 | .TP | |
726f6388 | 8327 | .B \-l |
ccc6cda3 JA |
8328 | List process IDs |
8329 | in addition to the normal information. | |
8330 | .TP | |
726f6388 | 8331 | .B \-n |
ccc6cda3 JA |
8332 | Display information only about jobs that have changed status since |
8333 | the user was last notified of their status. | |
8334 | .TP | |
5cdaaf76 CR |
8335 | .B \-p |
8336 | List only the process ID of the job's process group | |
8337 | leader. | |
8338 | .TP | |
ccc6cda3 | 8339 | .B \-r |
b28ff8c9 | 8340 | Display only running jobs. |
ccc6cda3 JA |
8341 | .TP |
8342 | .B \-s | |
b28ff8c9 | 8343 | Display only stopped jobs. |
ccc6cda3 JA |
8344 | .PD |
8345 | .PP | |
8346 | If | |
726f6388 JA |
8347 | .I jobspec |
8348 | is given, output is restricted to information about that job. | |
cce855bc JA |
8349 | The return status is 0 unless an invalid option is encountered |
8350 | or an invalid | |
726f6388 JA |
8351 | .I jobspec |
8352 | is supplied. | |
ccc6cda3 | 8353 | .PP |
726f6388 JA |
8354 | If the |
8355 | .B \-x | |
8356 | option is supplied, | |
8357 | .B jobs | |
8358 | replaces any | |
8359 | .I jobspec | |
8360 | found in | |
8361 | .I command | |
8362 | or | |
8363 | .I args | |
8364 | with the corresponding process group ID, and executes | |
8365 | .I command | |
8366 | passing it | |
8367 | .IR args , | |
8368 | returning its exit status. | |
ccc6cda3 | 8369 | .RE |
726f6388 | 8370 | .TP |
ccc6cda3 | 8371 | \fBkill\fP [\fB\-s\fP \fIsigspec\fP | \fB\-n\fP \fIsignum\fP | \fB\-\fP\fIsigspec\fP] [\fIpid\fP | \fIjobspec\fP] ... |
7117c2d2 | 8372 | .PD 0 |
726f6388 | 8373 | .TP |
cce855bc | 8374 | \fBkill\fP \fB\-l\fP [\fIsigspec\fP | \fIexit_status\fP] |
726f6388 JA |
8375 | .PD |
8376 | Send the signal named by | |
8377 | .I sigspec | |
ccc6cda3 JA |
8378 | or |
8379 | .I signum | |
726f6388 JA |
8380 | to the processes named by |
8381 | .I pid | |
8382 | or | |
8383 | .IR jobspec . | |
8384 | .I sigspec | |
61deeb13 | 8385 | is either a case-insensitive signal name such as |
726f6388 JA |
8386 | .SM |
8387 | .B SIGKILL | |
61deeb13 | 8388 | (with or without the |
726f6388 JA |
8389 | .SM |
8390 | .B SIG | |
61deeb13 CR |
8391 | prefix) or a signal number; |
8392 | .I signum | |
8393 | is a signal number. | |
726f6388 JA |
8394 | If |
8395 | .I sigspec | |
8396 | is not present, then | |
8397 | .SM | |
8398 | .B SIGTERM | |
cce855bc JA |
8399 | is assumed. |
8400 | An argument of | |
726f6388 | 8401 | .B \-l |
cce855bc JA |
8402 | lists the signal names. |
8403 | If any arguments are supplied when | |
726f6388 | 8404 | .B \-l |
cce855bc JA |
8405 | is given, the names of the signals corresponding to the arguments are |
8406 | listed, and the return status is 0. | |
8407 | The \fIexit_status\fP argument to | |
ccc6cda3 | 8408 | .B \-l |
cce855bc JA |
8409 | is a number specifying either a signal number or the exit status of |
8410 | a process terminated by a signal. | |
726f6388 JA |
8411 | .B kill |
8412 | returns true if at least one signal was successfully sent, or false | |
cce855bc | 8413 | if an error occurs or an invalid option is encountered. |
726f6388 JA |
8414 | .TP |
8415 | \fBlet\fP \fIarg\fP [\fIarg\fP ...] | |
8416 | Each | |
8417 | .I arg | |
8418 | is an arithmetic expression to be evaluated (see | |
8419 | .SM | |
984a1947 CR |
8420 | .B "ARITHMETIC EVALUATION" |
8421 | above). | |
726f6388 JA |
8422 | If the last |
8423 | .I arg | |
8424 | evaluates to 0, | |
8425 | .B let | |
8426 | returns 1; 0 is returned otherwise. | |
8427 | .TP | |
8f50a023 | 8428 | \fBlocal\fP [\fIoption\fP] [\fIname\fP[=\fIvalue\fP] ... | \- ] |
cce855bc | 8429 | For each argument, a local variable named |
fc527055 | 8430 | .I name |
cce855bc | 8431 | is created, and assigned |
726f6388 | 8432 | .IR value . |
bb70624e | 8433 | The \fIoption\fP can be any of the options accepted by \fBdeclare\fP. |
726f6388 JA |
8434 | When |
8435 | .B local | |
8436 | is used within a function, it causes the variable | |
8437 | .I name | |
8438 | to have a visible scope restricted to that function and its children. | |
8f50a023 CR |
8439 | If \fIname\fP is \-, the set of shell options is made local to the function |
8440 | in which \fBlocal\fP is invoked: shell options changed using the | |
8441 | \fBset\fP builtin inside the function are restored to their original values | |
8442 | when the function returns. | |
726f6388 JA |
8443 | With no operands, |
8444 | .B local | |
8445 | writes a list of local variables to the standard output. It is | |
8446 | an error to use | |
8447 | .B local | |
8448 | when not within a function. The return status is 0 unless | |
8449 | .B local | |
bb70624e | 8450 | is used outside a function, an invalid |
726f6388 | 8451 | .I name |
bb70624e JA |
8452 | is supplied, or |
8453 | \fIname\fP is a readonly variable. | |
726f6388 JA |
8454 | .TP |
8455 | .B logout | |
8456 | Exit a login shell. | |
8457 | .TP | |
25a0eacf | 8458 | \fBmapfile\fP [\fB\-d\fP \fIdelim\fP] [\fB\-n\fP \fIcount\fP] [\fB\-O\fP \fIorigin\fP] [\fB\-s\fP \fIcount\fP] [\fB\-t\fP] [\fB\-u\fP \fIfd\fP] [\fB\-C\fP \fIcallback\fP] [\fB\-c\fP \fIquantum\fP] [\fIarray\fP] |
e141c35a CR |
8459 | .PD 0 |
8460 | .TP | |
25a0eacf | 8461 | \fBreadarray\fP [\fB\-d\fP \fIdelim\fP] [\fB\-n\fP \fIcount\fP] [\fB\-O\fP \fIorigin\fP] [\fB\-s\fP \fIcount\fP] [\fB\-t\fP] [\fB\-u\fP \fIfd\fP] [\fB\-C\fP \fIcallback\fP] [\fB\-c\fP \fIquantum\fP] [\fIarray\fP] |
e141c35a | 8462 | .PD |
e1e48bba | 8463 | Read lines from the standard input into the indexed array variable |
6a8fd0ed | 8464 | .IR array , |
fc527055 | 8465 | or from file descriptor |
6a8fd0ed | 8466 | .IR fd |
fc527055 | 8467 | if the |
6a8fd0ed CR |
8468 | .B \-u |
8469 | option is supplied. | |
984a1947 CR |
8470 | The variable |
8471 | .SM | |
8472 | .B MAPFILE | |
8473 | is the default \fIarray\fP. | |
6a8fd0ed CR |
8474 | Options, if supplied, have the following meanings: |
8475 | .RS | |
8476 | .PD 0 | |
8477 | .TP | |
25a0eacf CR |
8478 | .B \-d |
8479 | The first character of \fIdelim\fP is used to terminate each input line, | |
8480 | rather than newline. | |
8481 | .TP | |
6a8fd0ed CR |
8482 | .B \-n |
8483 | Copy at most | |
8484 | .I count | |
8485 | lines. If \fIcount\fP is 0, all lines are copied. | |
8486 | .TP | |
8487 | .B \-O | |
8488 | Begin assigning to | |
8489 | .I array | |
8490 | at index | |
8491 | .IR origin . | |
8492 | The default index is 0. | |
8493 | .TP | |
8494 | .B \-s | |
8495 | Discard the first \fIcount\fP lines read. | |
8496 | .TP | |
8497 | .B \-t | |
06c3a575 | 8498 | Remove a trailing \fIdelim\fP (default newline) from each line read. |
6a8fd0ed CR |
8499 | .TP |
8500 | .B \-u | |
8501 | Read lines from file descriptor \fIfd\fP instead of the standard input. | |
8502 | .TP | |
8503 | .B \-C | |
8504 | Evaluate | |
8505 | .I callback | |
8506 | each time \fIquantum\fP lines are read. The \fB\-c\fP option specifies | |
8507 | .IR quantum . | |
8508 | .TP | |
8509 | .B \-c | |
8510 | Specify the number of lines read between each call to | |
8511 | .IR callback . | |
8512 | .PD | |
8513 | .PP | |
8514 | If | |
8515 | .B \-C | |
fc527055 | 8516 | is specified without |
6a8fd0ed CR |
8517 | .BR \-c , |
8518 | the default quantum is 5000. | |
e141c35a | 8519 | When \fIcallback\fP is evaluated, it is supplied the index of the next |
6faad625 CR |
8520 | array element to be assigned and the line to be assigned to that element |
8521 | as additional arguments. | |
fc527055 | 8522 | \fIcallback\fP is evaluated after the line is read but before the |
e141c35a | 8523 | array element is assigned. |
6a8fd0ed CR |
8524 | .PP |
8525 | If not supplied with an explicit origin, \fBmapfile\fP will clear \fIarray\fP | |
8526 | before assigning to it. | |
8527 | .PP | |
8528 | \fBmapfile\fP returns successfully unless an invalid option or option | |
e1e48bba CR |
8529 | argument is supplied, \fIarray\fP is invalid or unassignable, or if |
8530 | \fIarray\fP is not an indexed array. | |
6a8fd0ed CR |
8531 | .RE |
8532 | .TP | |
ccc6cda3 | 8533 | \fBpopd\fP [\-\fBn\fP] [+\fIn\fP] [\-\fIn\fP] |
726f6388 JA |
8534 | Removes entries from the directory stack. With no arguments, |
8535 | removes the top directory from the stack, and performs a | |
8536 | .B cd | |
8537 | to the new top directory. | |
ccc6cda3 | 8538 | Arguments, if supplied, have the following meanings: |
726f6388 JA |
8539 | .RS |
8540 | .PD 0 | |
8541 | .TP | |
d3ad40de CR |
8542 | .B \-n |
8543 | Suppresses the normal change of directory when removing directories | |
8544 | from the stack, so that only the stack is manipulated. | |
8545 | .TP | |
ccc6cda3 JA |
8546 | \fB+\fP\fIn\fP |
8547 | Removes the \fIn\fPth entry counting from the left of the list | |
726f6388 JA |
8548 | shown by |
8549 | .BR dirs , | |
bb70624e JA |
8550 | starting with zero. For example: |
8551 | .if n ``popd +0'' | |
8552 | .if t \f(CWpopd +0\fP | |
8553 | removes the first directory, | |
8554 | .if n ``popd +1'' | |
8555 | .if t \f(CWpopd +1\fP | |
8556 | the second. | |
726f6388 | 8557 | .TP |
ccc6cda3 JA |
8558 | \fB\-\fP\fIn\fP |
8559 | Removes the \fIn\fPth entry counting from the right of the list | |
726f6388 JA |
8560 | shown by |
8561 | .BR dirs , | |
bb70624e JA |
8562 | starting with zero. For example: |
8563 | .if n ``popd -0'' | |
8564 | .if t \f(CWpopd -0\fP | |
8565 | removes the last directory, | |
8566 | .if n ``popd -1'' | |
8567 | .if t \f(CWpopd -1\fP | |
8568 | the next to last. | |
726f6388 JA |
8569 | .PD |
8570 | .PP | |
8571 | If the | |
8572 | .B popd | |
fc527055 | 8573 | command is successful, a |
726f6388 JA |
8574 | .B dirs |
8575 | is performed as well, and the return status is 0. | |
8576 | .B popd | |
cce855bc | 8577 | returns false if an invalid option is encountered, the directory stack |
726f6388 JA |
8578 | is empty, a non-existent directory stack entry is specified, or the |
8579 | directory change fails. | |
8580 | .RE | |
8581 | .TP | |
3ee6b87d | 8582 | \fBprintf\fP [\fB\-v\fP \fIvar\fP] \fIformat\fP [\fIarguments\fP] |
cce855bc JA |
8583 | Write the formatted \fIarguments\fP to the standard output under the |
8584 | control of the \fIformat\fP. | |
6faad625 CR |
8585 | The \fB\-v\fP option causes the output to be assigned to the variable |
8586 | \fIvar\fP rather than being printed to the standard output. | |
8587 | .sp 1 | |
cce855bc JA |
8588 | The \fIformat\fP is a character string which contains three types of objects: |
8589 | plain characters, which are simply copied to standard output, character | |
8590 | escape sequences, which are converted and copied to the standard output, and | |
8591 | format specifications, each of which causes printing of the next successive | |
8592 | \fIargument\fP. | |
6faad625 CR |
8593 | In addition to the standard \fIprintf\fP(1) format specifications, |
8594 | \fBprintf\fP interprets the following extensions: | |
8595 | .RS | |
8596 | .PD 0 | |
8597 | .TP | |
8598 | .B %b | |
8599 | causes | |
cce855bc | 8600 | \fBprintf\fP to expand backslash escape sequences in the corresponding |
5e13499c | 8601 | \fIargument\fP (except that \fB\ec\fP terminates output, backslashes in |
20587658 | 8602 | \fB\e\(aq\fP, \fB\e"\fP, and \fB\e?\fP are not removed, and octal escapes |
6faad625 CR |
8603 | beginning with \fB\e0\fP may contain up to four digits). |
8604 | .TP | |
8605 | .B %q | |
8606 | causes \fBprintf\fP to output the corresponding | |
cce855bc | 8607 | \fIargument\fP in a format that can be reused as shell input. |
6faad625 CR |
8608 | .TP |
8609 | .B %(\fIdatefmt\fP)T | |
8610 | causes \fBprintf\fP to output the date-time string resulting from using | |
77b3aacb CR |
8611 | \fIdatefmt\fP as a format string for \fIstrftime\fP(3). |
8612 | The corresponding \fIargument\fP is an integer representing the number of | |
8613 | seconds since the epoch. | |
8614 | Two special argument values may be used: -1 represents the current | |
6faad625 | 8615 | time, and -2 represents the time the shell was invoked. |
77b3aacb CR |
8616 | If no argument is specified, conversion behaves as if -1 had been given. |
8617 | This is an exception to the usual \fBprintf\fP behavior. | |
6faad625 CR |
8618 | .PD |
8619 | .PP | |
112ff2a6 CR |
8620 | Arguments to non-string format specifiers are treated as C constants, |
8621 | except that a leading plus or minus sign is allowed, and if the leading | |
8622 | character is a single or double quote, the value is the ASCII value of | |
8623 | the following character. | |
6faad625 | 8624 | .PP |
cce855bc JA |
8625 | The \fIformat\fP is reused as necessary to consume all of the \fIarguments\fP. |
8626 | If the \fIformat\fP requires more \fIarguments\fP than are supplied, the | |
8627 | extra format specifications behave as if a zero value or null string, as | |
6faad625 CR |
8628 | appropriate, had been supplied. |
8629 | The return value is zero on success, non-zero on failure. | |
8630 | .RE | |
cce855bc | 8631 | .TP |
d3ad40de | 8632 | \fBpushd\fP [\fB\-n\fP] [+\fIn\fP] [\-\fIn\fP] |
7117c2d2 | 8633 | .PD 0 |
726f6388 | 8634 | .TP |
d3ad40de | 8635 | \fBpushd\fP [\fB\-n\fP] [\fIdir\fP] |
726f6388 JA |
8636 | .PD |
8637 | Adds a directory to the top of the directory stack, or rotates | |
8638 | the stack, making the new top of the stack the current working | |
8639 | directory. With no arguments, exchanges the top two directories | |
8640 | and returns 0, unless the directory stack is empty. | |
ccc6cda3 | 8641 | Arguments, if supplied, have the following meanings: |
726f6388 JA |
8642 | .RS |
8643 | .PD 0 | |
8644 | .TP | |
d3ad40de CR |
8645 | .B \-n |
8646 | Suppresses the normal change of directory when adding directories | |
8647 | to the stack, so that only the stack is manipulated. | |
8648 | .TP | |
ccc6cda3 | 8649 | \fB+\fP\fIn\fP |
726f6388 JA |
8650 | Rotates the stack so that the \fIn\fPth directory |
8651 | (counting from the left of the list shown by | |
d166f048 JA |
8652 | .BR dirs , |
8653 | starting with zero) | |
726f6388 JA |
8654 | is at the top. |
8655 | .TP | |
ccc6cda3 | 8656 | \fB\-\fP\fIn\fP |
726f6388 | 8657 | Rotates the stack so that the \fIn\fPth directory |
d166f048 JA |
8658 | (counting from the right of the list shown by |
8659 | .BR dirs , | |
8660 | starting with zero) is at the top. | |
726f6388 | 8661 | .TP |
bb70624e | 8662 | .I dir |
ccc6cda3 | 8663 | Adds |
726f6388 JA |
8664 | .I dir |
8665 | to the directory stack at the top, making it the | |
19baff85 CR |
8666 | new current working directory as if it had been supplied as the argument |
8667 | to the \fBcd\fP builtin. | |
726f6388 JA |
8668 | .PD |
8669 | .PP | |
8670 | If the | |
8671 | .B pushd | |
fc527055 | 8672 | command is successful, a |
726f6388 JA |
8673 | .B dirs |
8674 | is performed as well. | |
8675 | If the first form is used, | |
8676 | .B pushd | |
8677 | returns 0 unless the cd to | |
8678 | .I dir | |
8679 | fails. With the second form, | |
8680 | .B pushd | |
8681 | returns 0 unless the directory stack is empty, | |
ccc6cda3 | 8682 | a non-existent directory stack element is specified, |
726f6388 JA |
8683 | or the directory change to the specified new current directory |
8684 | fails. | |
8685 | .RE | |
8686 | .TP | |
ccc6cda3 | 8687 | \fBpwd\fP [\fB\-LP\fP] |
bb70624e JA |
8688 | Print the absolute pathname of the current working directory. |
8689 | The pathname printed contains no symbolic links if the | |
726f6388 | 8690 | .B \-P |
fc527055 | 8691 | option is supplied or the |
ccc6cda3 | 8692 | .B \-o physical |
726f6388 JA |
8693 | option to the |
8694 | .B set | |
ccc6cda3 JA |
8695 | builtin command is enabled. |
8696 | If the | |
8697 | .B \-L | |
bb70624e | 8698 | option is used, the pathname printed may contain symbolic links. |
ccc6cda3 | 8699 | The return status is 0 unless an error occurs while |
cce855bc JA |
8700 | reading the name of the current directory or an |
8701 | invalid option is supplied. | |
726f6388 | 8702 | .TP |
08e72d7a | 8703 | \fBread\fP [\fB\-ers\fP] [\fB\-a\fP \fIaname\fP] [\fB\-d\fP \fIdelim\fP] [\fB\-i\fP \fItext\fP] [\fB\-n\fP \fInchars\fP] [\fB\-N\fP \fInchars\fP] [\fB\-p\fP \fIprompt\fP] [\fB\-t\fP \fItimeout\fP] [\fB\-u\fP \fIfd\fP] [\fIname\fP ...] |
7117c2d2 JA |
8704 | One line is read from the standard input, or from the file descriptor |
8705 | \fIfd\fP supplied as an argument to the \fB\-u\fP option, and the first word | |
726f6388 JA |
8706 | is assigned to the first |
8707 | .IR name , | |
8708 | the second word to the second | |
8709 | .IR name , | |
cce855bc JA |
8710 | and so on, with leftover words and their intervening separators assigned |
8711 | to the last | |
726f6388 | 8712 | .IR name . |
7117c2d2 | 8713 | If there are fewer words read from the input stream than names, |
cce855bc | 8714 | the remaining names are assigned empty values. |
fc527055 | 8715 | The characters in |
726f6388 JA |
8716 | .SM |
8717 | .B IFS | |
c677e9e0 CR |
8718 | are used to split the line into words using the same rules the shell |
8719 | uses for expansion (described above under \fBWord Splitting\fP). | |
b72432fd JA |
8720 | The backslash character (\fB\e\fP) may be used to remove any special |
8721 | meaning for the next character read and for line continuation. | |
cce855bc | 8722 | Options, if supplied, have the following meanings: |
ccc6cda3 JA |
8723 | .RS |
8724 | .PD 0 | |
8725 | .TP | |
bb70624e | 8726 | .B \-a \fIaname\fP |
ccc6cda3 JA |
8727 | The words are assigned to sequential indices |
8728 | of the array variable | |
8729 | .IR aname , | |
8730 | starting at 0. | |
8731 | .I aname | |
8732 | is unset before any new values are assigned. | |
cce855bc | 8733 | Other \fIname\fP arguments are ignored. |
ccc6cda3 | 8734 | .TP |
bb70624e JA |
8735 | .B \-d \fIdelim\fP |
8736 | The first character of \fIdelim\fP is used to terminate the input line, | |
8737 | rather than newline. | |
8738 | .TP | |
ccc6cda3 JA |
8739 | .B \-e |
8740 | If the standard input | |
8741 | is coming from a terminal, | |
8742 | .B readline | |
8743 | (see | |
8744 | .SM | |
8745 | .B READLINE | |
8746 | above) is used to obtain the line. | |
14e8b2a7 CR |
8747 | Readline uses the current (or default, if line editing was not previously |
8748 | active) editing settings. | |
bb70624e | 8749 | .TP |
1d0e1a34 CR |
8750 | .B \-i \fItext\fP |
8751 | If | |
8752 | .B readline | |
8753 | is being used to read the line, \fItext\fP is placed into the editing | |
8754 | buffer before editing begins. | |
8755 | .TP | |
bb70624e JA |
8756 | .B \-n \fInchars\fP |
8757 | \fBread\fP returns after reading \fInchars\fP characters rather than | |
687a967e | 8758 | waiting for a complete line of input, but honors a delimiter if fewer |
08e72d7a CR |
8759 | than \fInchars\fP characters are read before the delimiter. |
8760 | .TP | |
8761 | .B \-N \fInchars\fP | |
8762 | \fBread\fP returns after reading exactly \fInchars\fP characters rather | |
8763 | than waiting for a complete line of input, unless EOF is encountered or | |
a3143574 CR |
8764 | \fBread\fP times out. |
8765 | Delimiter characters encountered in the input are | |
8766 | not treated specially and do not cause \fBread\fP to return until | |
8767 | \fInchars\fP characters are read. | |
bb70624e JA |
8768 | .TP |
8769 | .B \-p \fIprompt\fP | |
f73dda09 | 8770 | Display \fIprompt\fP on standard error, without a |
bb70624e JA |
8771 | trailing newline, before attempting to read any input. The prompt |
8772 | is displayed only if input is coming from a terminal. | |
8773 | .TP | |
8774 | .B \-r | |
8775 | Backslash does not act as an escape character. | |
8776 | The backslash is considered to be part of the line. | |
8777 | In particular, a backslash-newline pair may not be used as a line | |
8778 | continuation. | |
8779 | .TP | |
8780 | .B \-s | |
8781 | Silent mode. If input is coming from a terminal, characters are | |
8782 | not echoed. | |
8783 | .TP | |
8784 | .B \-t \fItimeout\fP | |
8785 | Cause \fBread\fP to time out and return failure if a complete line of | |
77b3aacb CR |
8786 | input (or a specified number of characters) |
8787 | is not read within \fItimeout\fP seconds. | |
4ac1ff98 CR |
8788 | \fItimeout\fP may be a decimal number with a fractional portion following |
8789 | the decimal point. | |
e33f2203 CR |
8790 | This option is only effective if \fBread\fP is reading input from a |
8791 | terminal, pipe, or other special file; it has no effect when reading | |
8792 | from regular files. | |
77b3aacb CR |
8793 | If \fBread\fP times out, \fBread\fP saves any partial input read into |
8794 | the specified variable \fIname\fP. | |
b13b8a87 | 8795 | If \fItimeout\fP is 0, \fBread\fP returns immediately, without trying to |
77b3aacb | 8796 | read any data. The exit status is 0 if input is available on |
b13b8a87 | 8797 | the specified file descriptor, non-zero otherwise. |
e33f2203 | 8798 | The exit status is greater than 128 if the timeout is exceeded. |
7117c2d2 | 8799 | .TP |
0f445e6c | 8800 | .B \-u \fIfd\fP |
7117c2d2 | 8801 | Read input from file descriptor \fIfd\fP. |
ccc6cda3 JA |
8802 | .PD |
8803 | .PP | |
8804 | If no | |
726f6388 JA |
8805 | .I names |
8806 | are supplied, the line read is assigned to the variable | |
8807 | .SM | |
8808 | .BR REPLY . | |
7117c2d2 | 8809 | The return code is zero, unless end-of-file is encountered, \fBread\fP |
ba4ab055 CR |
8810 | times out (in which case the return code is greater than 128), |
8811 | a variable assignment error (such as assigning to a readonly variable) occurs, | |
8812 | or an invalid file descriptor is supplied as the argument to \fB\-u\fP. | |
ccc6cda3 | 8813 | .RE |
726f6388 | 8814 | .TP |
54a1fa7c | 8815 | \fBreadonly\fP [\fB\-aAf\fP] [\fB\-p\fP] [\fIname\fP[=\fIword\fP] ...] |
726f6388 JA |
8816 | .PD |
8817 | The given | |
ccc6cda3 JA |
8818 | \fInames\fP are marked readonly; the values of these |
8819 | .I names | |
726f6388 JA |
8820 | may not be changed by subsequent assignment. |
8821 | If the | |
8822 | .B \-f | |
8823 | option is supplied, the functions corresponding to the | |
8824 | \fInames\fP are so | |
ccc6cda3 JA |
8825 | marked. |
8826 | The | |
8827 | .B \-a | |
fdf670ea CR |
8828 | option restricts the variables to indexed arrays; the |
8829 | .B \-A | |
8830 | option restricts the variables to associative arrays. | |
54a1fa7c CR |
8831 | If both options are supplied, |
8832 | .B \-A | |
8833 | takes precedence. | |
ccc6cda3 JA |
8834 | If no |
8835 | .I name | |
8836 | arguments are given, or if the | |
726f6388 | 8837 | .B \-p |
ccc6cda3 | 8838 | option is supplied, a list of all readonly names is printed. |
54a1fa7c CR |
8839 | The other options may be used to restrict the output to a subset of |
8840 | the set of readonly names. | |
cce855bc JA |
8841 | The |
8842 | .B \-p | |
bb70624e JA |
8843 | option causes output to be displayed in a format that |
8844 | may be reused as input. | |
d3a24ed2 CR |
8845 | If a variable name is followed by =\fIword\fP, the value of |
8846 | the variable is set to \fIword\fP. | |
cce855bc | 8847 | The return status is 0 unless an invalid option is encountered, |
ccc6cda3 JA |
8848 | one of the |
8849 | .I names | |
cce855bc | 8850 | is not a valid shell variable name, or |
726f6388 JA |
8851 | .B \-f |
8852 | is supplied with a | |
8853 | .I name | |
8854 | that is not a function. | |
8855 | .TP | |
8856 | \fBreturn\fP [\fIn\fP] | |
b28ff8c9 CR |
8857 | Causes a function to stop executing and return the value specified by |
8858 | .I n | |
8859 | to its caller. | |
fc527055 | 8860 | If |
726f6388 JA |
8861 | .I n |
8862 | is omitted, the return status is that of the last command | |
e2f12fdf CR |
8863 | executed in the function body. |
8864 | If \fBreturn\fP is executed by a trap handler, the last command used to | |
8865 | determine the status is the last command executed before the trap handler. | |
8866 | if \fBreturn\fP is executed during a \fBDEBUG\fP trap, the last command | |
8867 | used to determine the status is the last command executed by the trap | |
8868 | handler before \fBreturn\fP was invoked. | |
8869 | If | |
b28ff8c9 CR |
8870 | .B return |
8871 | is used outside a function, | |
fc527055 | 8872 | but during execution of a script by the |
726f6388 JA |
8873 | .B . |
8874 | (\fBsource\fP) command, it causes the shell to stop executing | |
8875 | that script and return either | |
8876 | .I n | |
8877 | or the exit status of the last command executed within the | |
b28ff8c9 | 8878 | script as the exit status of the script. |
3d4f66ca CR |
8879 | If \fIn\fP is supplied, the return value is its least significant |
8880 | 8 bits. | |
b28ff8c9 CR |
8881 | The return status is non-zero if |
8882 | .B return | |
3d4f66ca | 8883 | is supplied a non-numeric argument, or |
b28ff8c9 CR |
8884 | is used outside a |
8885 | function and not during execution of a script by \fB.\fP\^ or \fBsource\fP. | |
d3a24ed2 CR |
8886 | Any command associated with the \fBRETURN\fP trap is executed |
8887 | before execution resumes after the function or script. | |
726f6388 | 8888 | .TP |
dc60d4e0 | 8889 | \fBset\fP [\fB\-\-abefhkmnptuvxBCEHPT\fP] [\fB\-o\fP \fIoption\-name\fP] [\fIarg\fP ...] |
d3ad40de CR |
8890 | .PD 0 |
8891 | .TP | |
dc60d4e0 | 8892 | \fBset\fP [\fB+abefhkmnptuvxBCEHPT\fP] [\fB+o\fP \fIoption\-name\fP] [\fIarg\fP ...] |
d3ad40de | 8893 | .PD |
ccc6cda3 | 8894 | Without options, the name and value of each shell variable are displayed |
54cdd75a CR |
8895 | in a format that can be reused as input |
8896 | for setting or resetting the currently-set variables. | |
8897 | Read-only variables cannot be reset. | |
c677e9e0 | 8898 | In \fIposix\fP mode, only shell variables are listed. |
cce855bc | 8899 | The output is sorted according to the current locale. |
ccc6cda3 | 8900 | When options are specified, they set or unset shell attributes. |
626d0694 | 8901 | Any arguments remaining after option processing are treated |
fc527055 | 8902 | as values for the positional parameters and are assigned, in order, to |
ccc6cda3 JA |
8903 | .BR $1 , |
8904 | .BR $2 , | |
8905 | .B ... | |
8906 | .BR $\fIn\fP . | |
8907 | Options, if specified, have the following meanings: | |
726f6388 JA |
8908 | .RS |
8909 | .PD 0 | |
8910 | .TP 8 | |
8911 | .B \-a | |
09afa613 CR |
8912 | Each variable or function that is created or modified is given the |
8913 | export attribute and marked for export to the environment of | |
8914 | subsequent commands. | |
726f6388 JA |
8915 | .TP 8 |
8916 | .B \-b | |
ccc6cda3 JA |
8917 | Report the status of terminated background jobs |
8918 | immediately, rather than before the next primary prompt. This is | |
8919 | effective only when job control is enabled. | |
726f6388 JA |
8920 | .TP 8 |
8921 | .B \-e | |
15825757 CR |
8922 | Exit immediately if a |
8923 | \fIpipeline\fP (which may consist of a single \fIsimple command\fP), | |
8924 | a \fIlist\fP, | |
8925 | or a \fIcompound command\fP | |
8926 | (see | |
726f6388 JA |
8927 | .SM |
8928 | .B SHELL GRAMMAR | |
fc527055 | 8929 | above), exits with a non-zero status. |
d3a24ed2 CR |
8930 | The shell does not exit if the |
8931 | command that fails is part of the command list immediately following a | |
8932 | .B while | |
726f6388 | 8933 | or |
d3a24ed2 | 8934 | .B until |
fc527055 | 8935 | keyword, |
4b9cc222 | 8936 | part of the test following the |
d3ad40de | 8937 | .B if |
4b9cc222 CR |
8938 | or |
8939 | .B elif | |
8940 | reserved words, part of any command executed in a | |
726f6388 JA |
8941 | .B && |
8942 | or | |
adc6cff5 CR |
8943 | .B || |
8944 | list except the command following the final \fB&&\fP or \fB||\fP, | |
d3ad40de CR |
8945 | any command in a pipeline but the last, |
8946 | or if the command's return value is | |
a05a1337 | 8947 | being inverted with |
726f6388 | 8948 | .BR ! . |
15825757 CR |
8949 | If a compound command other than a subshell |
8950 | returns a non-zero status because a command failed | |
8951 | while \fB\-e\fP was being ignored, the shell does not exit. | |
f73dda09 | 8952 | A trap on \fBERR\fP, if set, is executed before the shell exits. |
a05a1337 CR |
8953 | This option applies to the shell environment and each subshell environment |
8954 | separately (see | |
984a1947 | 8955 | .SM |
a05a1337 CR |
8956 | .B "COMMAND EXECUTION ENVIRONMENT" |
8957 | above), and may cause | |
8958 | subshells to exit before executing all the commands in the subshell. | |
1b1fe467 CR |
8959 | .if t .sp 0.5 |
8960 | .if n .sp 1 | |
8961 | If a compound command or shell function executes in a context | |
8962 | where \fB\-e\fP is being ignored, | |
8963 | none of the commands executed within the compound command or function body | |
8964 | will be affected by the \fB\-e\fP setting, even if \fB\-e\fP is set | |
8965 | and a command returns a failure status. | |
8966 | If a compound command or shell function sets \fB\-e\fP while executing in | |
8967 | a context where \fB\-e\fP is ignored, that setting will not have any | |
8968 | effect until the compound command or the command containing the function | |
8969 | call completes. | |
726f6388 JA |
8970 | .TP 8 |
8971 | .B \-f | |
8972 | Disable pathname expansion. | |
fc527055 | 8973 | .TP 8 |
726f6388 | 8974 | .B \-h |
ccc6cda3 | 8975 | Remember the location of commands as they are looked up for execution. |
cce855bc | 8976 | This is enabled by default. |
726f6388 JA |
8977 | .TP 8 |
8978 | .B \-k | |
ccc6cda3 JA |
8979 | All arguments in the form of assignment statements |
8980 | are placed in the environment for a command, not just | |
8981 | those that precede the command name. | |
726f6388 JA |
8982 | .TP 8 |
8983 | .B \-m | |
cce855bc | 8984 | Monitor mode. Job control is enabled. This option is on |
726f6388 JA |
8985 | by default for interactive shells on systems that support |
8986 | it (see | |
8987 | .SM | |
8988 | .B JOB CONTROL | |
f6da9f85 CR |
8989 | above). |
8990 | All processes run in a separate process group. | |
8991 | When a background job completes, the shell prints a line | |
8992 | containing its exit status. | |
726f6388 JA |
8993 | .TP 8 |
8994 | .B \-n | |
fc527055 CR |
8995 | Read commands but do not execute them. |
8996 | This may be used to check a shell script for syntax errors. | |
8997 | This is ignored by interactive shells. | |
726f6388 | 8998 | .TP 8 |
ccc6cda3 JA |
8999 | .B \-o \fIoption\-name\fP |
9000 | The \fIoption\-name\fP can be one of the following: | |
726f6388 JA |
9001 | .RS |
9002 | .TP 8 | |
9003 | .B allexport | |
9004 | Same as | |
9005 | .BR \-a . | |
9006 | .TP 8 | |
9007 | .B braceexpand | |
ccc6cda3 JA |
9008 | Same as |
9009 | .BR \-B . | |
726f6388 JA |
9010 | .TP 8 |
9011 | .B emacs | |
9012 | Use an emacs-style command line editing interface. This is enabled | |
9013 | by default when the shell is interactive, unless the shell is started | |
9014 | with the | |
ccc6cda3 | 9015 | .B \-\-noediting |
726f6388 | 9016 | option. |
10a4e415 | 9017 | This also affects the editing interface used for \fBread \-e\fP. |
726f6388 | 9018 | .TP 8 |
a3143574 CR |
9019 | .B errexit |
9020 | Same as | |
9021 | .BR \-e . | |
9022 | .TP 8 | |
d3a24ed2 CR |
9023 | .B errtrace |
9024 | Same as | |
9025 | .BR \-E . | |
9026 | .TP 8 | |
9027 | .B functrace | |
9028 | Same as | |
9029 | .BR \-T . | |
9030 | .TP 8 | |
ccc6cda3 JA |
9031 | .B hashall |
9032 | Same as | |
9033 | .BR \-h . | |
9034 | .TP 8 | |
726f6388 JA |
9035 | .B histexpand |
9036 | Same as | |
9037 | .BR \-H . | |
9038 | .TP 8 | |
ccc6cda3 JA |
9039 | .B history |
9040 | Enable command history, as described above under | |
9041 | .SM | |
9042 | .BR HISTORY . | |
9043 | This option is on by default in interactive shells. | |
9044 | .TP 8 | |
726f6388 | 9045 | .B ignoreeof |
28ef6c31 JA |
9046 | The effect is as if the shell command |
9047 | .if t \f(CWIGNOREEOF=10\fP | |
9048 | .if n ``IGNOREEOF=10'' | |
9049 | had been executed | |
726f6388 JA |
9050 | (see |
9051 | .B Shell Variables | |
9052 | above). | |
9053 | .TP 8 | |
ccc6cda3 JA |
9054 | .B keyword |
9055 | Same as | |
9056 | .BR \-k . | |
726f6388 JA |
9057 | .TP 8 |
9058 | .B monitor | |
9059 | Same as | |
9060 | .BR \-m . | |
9061 | .TP 8 | |
9062 | .B noclobber | |
9063 | Same as | |
9064 | .BR \-C . | |
9065 | .TP 8 | |
9066 | .B noexec | |
9067 | Same as | |
9068 | .BR \-n . | |
9069 | .TP 8 | |
9070 | .B noglob | |
9071 | Same as | |
9072 | .BR \-f . | |
57a3f689 | 9073 | .TP 8 |
f73dda09 JA |
9074 | .B nolog |
9075 | Currently ignored. | |
726f6388 | 9076 | .TP 8 |
726f6388 JA |
9077 | .B notify |
9078 | Same as | |
9079 | .BR \-b . | |
9080 | .TP 8 | |
9081 | .B nounset | |
9082 | Same as | |
9083 | .BR \-u . | |
9084 | .TP 8 | |
ccc6cda3 JA |
9085 | .B onecmd |
9086 | Same as | |
9087 | .BR \-t . | |
9088 | .TP 8 | |
726f6388 JA |
9089 | .B physical |
9090 | Same as | |
9091 | .BR \-P . | |
9092 | .TP 8 | |
d3a24ed2 CR |
9093 | .B pipefail |
9094 | If set, the return value of a pipeline is the value of the last | |
9095 | (rightmost) command to exit with a non-zero status, or zero if all | |
9096 | commands in the pipeline exit successfully. | |
9097 | This option is disabled by default. | |
9098 | .TP 8 | |
726f6388 | 9099 | .B posix |
ccc6cda3 JA |
9100 | Change the behavior of |
9101 | .B bash | |
9102 | where the default operation differs | |
ac18b312 | 9103 | from the POSIX standard to match the standard (\fIposix mode\fP). |
c677e9e0 CR |
9104 | See |
9105 | .SM | |
9106 | .B "SEE ALSO" | |
9107 | below for a reference to a document that details how posix mode affects | |
9108 | bash's behavior. | |
726f6388 JA |
9109 | .TP 8 |
9110 | .B privileged | |
9111 | Same as | |
9112 | .BR \-p . | |
9113 | .TP 8 | |
9114 | .B verbose | |
9115 | Same as | |
9116 | .BR \-v . | |
9117 | .TP 8 | |
9118 | .B vi | |
9119 | Use a vi-style command line editing interface. | |
10a4e415 | 9120 | This also affects the editing interface used for \fBread \-e\fP. |
726f6388 JA |
9121 | .TP 8 |
9122 | .B xtrace | |
9123 | Same as | |
9124 | .BR \-x . | |
ccc6cda3 | 9125 | .sp .5 |
726f6388 | 9126 | .PP |
ccc6cda3 JA |
9127 | If |
9128 | .B \-o | |
9129 | is supplied with no \fIoption\-name\fP, the values of the current options are | |
726f6388 | 9130 | printed. |
ccc6cda3 JA |
9131 | If |
9132 | .B +o | |
9133 | is supplied with no \fIoption\-name\fP, a series of | |
9134 | .B set | |
9135 | commands to recreate the current option settings is displayed on | |
9136 | the standard output. | |
726f6388 JA |
9137 | .RE |
9138 | .TP 8 | |
9139 | .B \-p | |
9140 | Turn on | |
9141 | .I privileged | |
9142 | mode. In this mode, the | |
bb70624e | 9143 | .SM |
726f6388 | 9144 | .B $ENV |
b72432fd | 9145 | and |
bb70624e | 9146 | .SM |
b72432fd JA |
9147 | .B $BASH_ENV |
9148 | files are not processed, shell functions are not inherited from the | |
bb70624e JA |
9149 | environment, and the |
9150 | .SM | |
e77a3058 | 9151 | .BR SHELLOPTS , |
984a1947 | 9152 | .SM |
691aebcb | 9153 | .BR BASHOPTS , |
984a1947 | 9154 | .SM |
e77a3058 CR |
9155 | .BR CDPATH , |
9156 | and | |
984a1947 | 9157 | .SM |
e77a3058 CR |
9158 | .B GLOBIGNORE |
9159 | variables, if they appear in the environment, are ignored. | |
b72432fd JA |
9160 | If the shell is started with the effective user (group) id not equal to the |
9161 | real user (group) id, and the \fB\-p\fP option is not supplied, these actions | |
9162 | are taken and the effective user id is set to the real user id. | |
9163 | If the \fB\-p\fP option is supplied at startup, the effective user id is | |
9164 | not reset. | |
cce855bc | 9165 | Turning this option off causes the effective user |
726f6388 JA |
9166 | and group ids to be set to the real user and group ids. |
9167 | .TP 8 | |
9168 | .B \-t | |
9169 | Exit after reading and executing one command. | |
9170 | .TP 8 | |
9171 | .B \-u | |
2c471a92 CR |
9172 | Treat unset variables and parameters other than the special |
9173 | parameters "@" and "*" as an error when performing | |
726f6388 | 9174 | parameter expansion. If expansion is attempted on an |
2c471a92 | 9175 | unset variable or parameter, the shell prints an error message, and, |
ccc6cda3 | 9176 | if not interactive, exits with a non-zero status. |
726f6388 JA |
9177 | .TP 8 |
9178 | .B \-v | |
9179 | Print shell input lines as they are read. | |
9180 | .TP 8 | |
9181 | .B \-x | |
ccc6cda3 | 9182 | After expanding each \fIsimple command\fP, |
d3a24ed2 CR |
9183 | \fBfor\fP command, \fBcase\fP command, \fBselect\fP command, or |
9184 | arithmetic \fBfor\fP command, display the expanded value of | |
726f6388 JA |
9185 | .SM |
9186 | .BR PS4 , | |
d3a24ed2 CR |
9187 | followed by the command and its expanded arguments |
9188 | or associated word list. | |
726f6388 | 9189 | .TP 8 |
ccc6cda3 JA |
9190 | .B \-B |
9191 | The shell performs brace expansion (see | |
9192 | .B Brace Expansion | |
9193 | above). This is on by default. | |
726f6388 JA |
9194 | .TP 8 |
9195 | .B \-C | |
ccc6cda3 JA |
9196 | If set, |
9197 | .B bash | |
9198 | does not overwrite an existing file with the | |
9199 | .BR > , | |
9200 | .BR >& , | |
9201 | and | |
9202 | .B <> | |
fc527055 | 9203 | redirection operators. This may be overridden when |
ccc6cda3 JA |
9204 | creating output files by using the redirection operator |
9205 | .B >| | |
9206 | instead of | |
9207 | .BR > . | |
726f6388 | 9208 | .TP 8 |
d3a24ed2 CR |
9209 | .B \-E |
9210 | If set, any trap on \fBERR\fP is inherited by shell functions, command | |
9211 | substitutions, and commands executed in a subshell environment. | |
9212 | The \fBERR\fP trap is normally not inherited in such cases. | |
9213 | .TP 8 | |
726f6388 JA |
9214 | .B \-H |
9215 | Enable | |
9216 | .B ! | |
cce855bc | 9217 | style history substitution. This option is on by |
726f6388 JA |
9218 | default when the shell is interactive. |
9219 | .TP 8 | |
9220 | .B \-P | |
45c0f7f8 | 9221 | If set, the shell does not resolve symbolic links when executing |
ccc6cda3 | 9222 | commands such as |
726f6388 | 9223 | .B cd |
ccc6cda3 JA |
9224 | that change the current working directory. It uses the |
9225 | physical directory structure instead. By default, | |
9226 | .B bash | |
9227 | follows the logical chain of directories when performing commands | |
9228 | which change the current directory. | |
726f6388 | 9229 | .TP 8 |
d3a24ed2 | 9230 | .B \-T |
76a8d78d CR |
9231 | If set, any traps on \fBDEBUG\fP and \fBRETURN\fP are inherited by shell |
9232 | functions, command substitutions, and commands executed in a | |
9233 | subshell environment. | |
9234 | The \fBDEBUG\fP and \fBRETURN\fP traps are normally not inherited | |
9235 | in such cases. | |
d3a24ed2 | 9236 | .TP 8 |
726f6388 | 9237 | .B \-\- |
cce855bc | 9238 | If no arguments follow this option, then the positional parameters are |
726f6388 JA |
9239 | unset. Otherwise, the positional parameters are set to the |
9240 | \fIarg\fPs, even if some of them begin with a | |
9241 | .BR \- . | |
9242 | .TP 8 | |
9243 | .B \- | |
9244 | Signal the end of options, cause all remaining \fIarg\fPs to be | |
9245 | assigned to the positional parameters. The | |
9246 | .B \-x | |
9247 | and | |
9248 | .B \-v | |
9249 | options are turned off. | |
9250 | If there are no \fIarg\fPs, | |
9251 | the positional parameters remain unchanged. | |
9252 | .PD | |
9253 | .PP | |
cce855bc JA |
9254 | The options are off by default unless otherwise noted. |
9255 | Using + rather than \- causes these options to be turned off. | |
9256 | The options can also be specified as arguments to an invocation of | |
9257 | the shell. | |
9258 | The current set of options may be found in | |
726f6388 | 9259 | .BR $\- . |
cce855bc | 9260 | The return status is always true unless an invalid option is encountered. |
726f6388 JA |
9261 | .RE |
9262 | .TP | |
9263 | \fBshift\fP [\fIn\fP] | |
9264 | The positional parameters from \fIn\fP+1 ... are renamed to | |
9265 | .B $1 | |
9266 | .B .... | |
9267 | Parameters represented by the numbers \fB$#\fP | |
9268 | down to \fB$#\fP\-\fIn\fP+1 are unset. | |
ccc6cda3 JA |
9269 | .I n |
9270 | must be a non-negative number less than or equal to \fB$#\fP. | |
726f6388 JA |
9271 | If |
9272 | .I n | |
9273 | is 0, no parameters are changed. | |
9274 | If | |
fc527055 | 9275 | .I n |
726f6388 | 9276 | is not given, it is assumed to be 1. |
726f6388 JA |
9277 | If |
9278 | .I n | |
9279 | is greater than \fB$#\fP, the positional parameters are not changed. | |
ccc6cda3 | 9280 | The return status is greater than zero if |
726f6388 JA |
9281 | .I n |
9282 | is greater than | |
9283 | .B $# | |
ccc6cda3 JA |
9284 | or less than zero; otherwise 0. |
9285 | .TP | |
9286 | \fBshopt\fP [\fB\-pqsu\fP] [\fB\-o\fP] [\fIoptname\fP ...] | |
fc34b3a4 CR |
9287 | Toggle the values of settings controlling optional shell behavior. |
9288 | The settings can be either those listed below, or, if the | |
9289 | .B \-o | |
9290 | option is used, those available with the | |
9291 | .B \-o | |
9292 | option to the \fBset\fP builtin command. | |
ccc6cda3 JA |
9293 | With no options, or with the |
9294 | .B \-p | |
9295 | option, a list of all settable options is displayed, with | |
cce855bc JA |
9296 | an indication of whether or not each is set. |
9297 | The \fB\-p\fP option causes output to be displayed in a form that | |
9298 | may be reused as input. | |
9299 | Other options have the following meanings: | |
ccc6cda3 JA |
9300 | .RS |
9301 | .PD 0 | |
9302 | .TP | |
9303 | .B \-s | |
9304 | Enable (set) each \fIoptname\fP. | |
9305 | .TP | |
9306 | .B \-u | |
9307 | Disable (unset) each \fIoptname\fP. | |
9308 | .TP | |
9309 | .B \-q | |
9310 | Suppresses normal output (quiet mode); the return status indicates | |
9311 | whether the \fIoptname\fP is set or unset. | |
9312 | If multiple \fIoptname\fP arguments are given with | |
9313 | .BR \-q , | |
9314 | the return status is zero if all \fIoptnames\fP are enabled; non-zero | |
9315 | otherwise. | |
9316 | .TP | |
9317 | .B \-o | |
9318 | Restricts the values of \fIoptname\fP to be those defined for the | |
9319 | .B \-o | |
9320 | option to the | |
9321 | .B set | |
9322 | builtin. | |
9323 | .PD | |
9324 | .PP | |
9325 | If either | |
9326 | .B \-s | |
9327 | or | |
9328 | .B \-u | |
b28ff8c9 CR |
9329 | is used with no \fIoptname\fP arguments, |
9330 | .B shopt | |
9331 | shows only those options which are set or unset, respectively. | |
ccc6cda3 JA |
9332 | Unless otherwise noted, the \fBshopt\fP options are disabled (unset) |
9333 | by default. | |
9334 | .PP | |
9335 | The return status when listing options is zero if all \fIoptnames\fP | |
9336 | are enabled, non-zero otherwise. When setting or unsetting options, | |
cce855bc | 9337 | the return status is zero unless an \fIoptname\fP is not a valid shell |
ccc6cda3 JA |
9338 | option. |
9339 | .PP | |
9340 | The list of \fBshopt\fP options is: | |
9341 | .if t .sp .5v | |
9342 | .if n .sp 1v | |
9343 | .PD 0 | |
9344 | .TP 8 | |
d3ad40de CR |
9345 | .B autocd |
9346 | If set, a command name that is the name of a directory is executed as if | |
9347 | it were the argument to the \fBcd\fP command. | |
9348 | This option is only used by interactive shells. | |
9349 | .TP 8 | |
ccc6cda3 JA |
9350 | .B cdable_vars |
9351 | If set, an argument to the | |
9352 | .B cd | |
9353 | builtin command that | |
9354 | is not a directory is assumed to be the name of a variable whose | |
9355 | value is the directory to change to. | |
9356 | .TP 8 | |
9357 | .B cdspell | |
9358 | If set, minor errors in the spelling of a directory component in a | |
9359 | .B cd | |
9360 | command will be corrected. | |
9361 | The errors checked for are transposed characters, | |
9362 | a missing character, and one character too many. | |
b28ff8c9 | 9363 | If a correction is found, the corrected filename is printed, |
ccc6cda3 | 9364 | and the command proceeds. |
d166f048 | 9365 | This option is only used by interactive shells. |
ccc6cda3 JA |
9366 | .TP 8 |
9367 | .B checkhash | |
9368 | If set, \fBbash\fP checks that a command found in the hash | |
9369 | table exists before trying to execute it. If a hashed command no | |
9370 | longer exists, a normal path search is performed. | |
9371 | .TP 8 | |
d3ad40de | 9372 | .B checkjobs |
29d25b54 | 9373 | If set, \fBbash\fP lists the status of any stopped and running jobs before |
d3ad40de CR |
9374 | exiting an interactive shell. If any jobs are running, this causes |
9375 | the exit to be deferred until a second exit is attempted without an | |
984a1947 CR |
9376 | intervening command (see |
9377 | .SM | |
9378 | .B "JOB CONTROL" | |
9379 | above). The shell always | |
d3ad40de CR |
9380 | postpones exiting if any jobs are stopped. |
9381 | .TP 8 | |
ccc6cda3 | 9382 | .B checkwinsize |
51f7ea36 | 9383 | If set, \fBbash\fP checks the window size after each command |
ccc6cda3 JA |
9384 | and, if necessary, updates the values of |
9385 | .SM | |
9386 | .B LINES | |
9387 | and | |
9388 | .SM | |
9389 | .BR COLUMNS . | |
9390 | .TP 8 | |
9391 | .B cmdhist | |
9392 | If set, | |
9393 | .B bash | |
9394 | attempts to save all lines of a multiple-line | |
9395 | command in the same history entry. This allows | |
9396 | easy re-editing of multi-line commands. | |
9397 | .TP 8 | |
35ee8ea0 CR |
9398 | .B compat31 |
9399 | If set, | |
9400 | .B bash | |
9401 | changes its behavior to that of version 3.1 with respect to quoted | |
5a318736 CR |
9402 | arguments to the \fB[[\fP conditional command's \fB=~\fP operator |
9403 | and locale-specific string comparison when using the \fB[[\fP | |
54a1fa7c CR |
9404 | conditional command's \fB<\fP and \fB>\fP operators. |
9405 | Bash versions prior to bash-4.1 use ASCII collation and | |
9406 | .IR strcmp (3); | |
5a318736 | 9407 | bash-4.1 and later use the current locale's collation sequence and |
54a1fa7c | 9408 | .IR strcoll (3). |
cd0ef727 | 9409 | .TP 8 |
5a318736 CR |
9410 | .B compat32 |
9411 | If set, | |
9412 | .B bash | |
9413 | changes its behavior to that of version 3.2 with respect to | |
9414 | locale-specific string comparison when using the \fB[[\fP | |
9415 | conditional command's \fB<\fP and \fB>\fP operators (see previous item). | |
9416 | .TP 8 | |
cd0ef727 CR |
9417 | .B compat40 |
9418 | If set, | |
9419 | .B bash | |
9420 | changes its behavior to that of version 4.0 with respect to locale-specific | |
54a1fa7c | 9421 | string comparison when using the \fB[[\fP |
5a318736 CR |
9422 | conditional command's \fB<\fP and \fB>\fP operators (see description of |
9423 | \fBcompat31\fP) | |
54a1fa7c | 9424 | and the effect of interrupting a command list. |
5a318736 CR |
9425 | Bash versions 4.0 and later interrupt the list as if the shell received the |
9426 | interrupt; previous versions continue with the next command in the list. | |
cd0ef727 | 9427 | .TP 8 |
67362c60 | 9428 | .B compat41 |
67362c60 CR |
9429 | If set, |
9430 | .BR bash , | |
c677e9e0 | 9431 | when in \fIposix\fP mode, treats a single quote in a double-quoted |
67362c60 CR |
9432 | parameter expansion as a special character. The single quotes must match |
9433 | (an even number) and the characters between the single quotes are considered | |
9434 | quoted. This is the behavior of posix mode through version 4.1. | |
9435 | The default bash behavior remains as in previous versions. | |
9436 | .TP 8 | |
7175a77f CR |
9437 | .B compat42 |
9438 | If set, | |
9439 | .B bash | |
9440 | does not process the replacement string in the pattern substitution word | |
9441 | expansion using quote removal. | |
9442 | .TP 8 | |
ddef12ff CR |
9443 | .B complete_fullquote |
9444 | If set, | |
9445 | .B bash | |
9446 | quotes all shell metacharacters in filenames and directory names when | |
9447 | performing completion. | |
9448 | If not set, | |
9449 | .B bash | |
9450 | removes metacharacters such as the dollar sign from the set of | |
9451 | characters that will be quoted in completed filenames | |
9452 | when these metacharacters appear in shell variable references in words to be | |
9453 | completed. | |
9454 | This means that dollar signs in variable names that expand to directories | |
9455 | will not be quoted; | |
9456 | however, any dollar signs appearing in filenames will not be quoted, either. | |
9457 | This is active only when bash is using backslashes to quote completed | |
9458 | filenames. | |
9459 | This variable is set by default, which is the default bash behavior in | |
9460 | versions through 4.2. | |
9461 | .TP 8 | |
74d0116b CR |
9462 | .B direxpand |
9463 | If set, | |
9464 | .B bash | |
9465 | replaces directory names with the results of word expansion when performing | |
9466 | filename completion. This changes the contents of the readline editing | |
9467 | buffer. | |
9468 | If not set, | |
9469 | .B bash | |
9470 | attempts to preserve what the user typed. | |
9471 | .TP 8 | |
4ac1ff98 CR |
9472 | .B dirspell |
9473 | If set, | |
9474 | .B bash | |
9475 | attempts spelling correction on directory names during word completion | |
9476 | if the directory name initially supplied does not exist. | |
9477 | .TP 8 | |
ccc6cda3 | 9478 | .B dotglob |
fc527055 | 9479 | If set, |
ccc6cda3 JA |
9480 | .B bash |
9481 | includes filenames beginning with a `.' in the results of pathname | |
9482 | expansion. | |
9483 | .TP 8 | |
9484 | .B execfail | |
9485 | If set, a non-interactive shell will not exit if | |
9486 | it cannot execute the file specified as an argument to the | |
9487 | .B exec | |
9488 | builtin command. An interactive shell does not exit if | |
9489 | .B exec | |
9490 | fails. | |
9491 | .TP 8 | |
9492 | .B expand_aliases | |
9493 | If set, aliases are expanded as described above under | |
9494 | .SM | |
9495 | .BR ALIASES . | |
9496 | This option is enabled by default for interactive shells. | |
9497 | .TP 8 | |
d3a24ed2 CR |
9498 | .B extdebug |
9499 | If set, behavior intended for use by debuggers is enabled: | |
9500 | .RS | |
9501 | .TP | |
9502 | .B 1. | |
9503 | The \fB\-F\fP option to the \fBdeclare\fP builtin displays the source | |
9504 | file name and line number corresponding to each function name supplied | |
9505 | as an argument. | |
9506 | .TP | |
9507 | .B 2. | |
9508 | If the command run by the \fBDEBUG\fP trap returns a non-zero value, the | |
9509 | next command is skipped and not executed. | |
9510 | .TP | |
9511 | .B 3. | |
9512 | If the command run by the \fBDEBUG\fP trap returns a value of 2, and the | |
9513 | shell is executing in a subroutine (a shell function or a shell script | |
e2f12fdf CR |
9514 | executed by the \fB.\fP or \fBsource\fP builtins), the shell simulates |
9515 | a call to \fBreturn\fP. | |
2206f89a CR |
9516 | .TP |
9517 | .B 4. | |
984a1947 CR |
9518 | .SM |
9519 | .B BASH_ARGC | |
9520 | and | |
9521 | .SM | |
9522 | .B BASH_ARGV | |
9523 | are updated as described in their descriptions above. | |
2206f89a CR |
9524 | .TP |
9525 | .B 5. | |
fc527055 | 9526 | Function tracing is enabled: command substitution, shell functions, and |
2206f89a CR |
9527 | subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the |
9528 | \fBDEBUG\fP and \fBRETURN\fP traps. | |
9529 | .TP | |
9530 | .B 6. | |
fc527055 | 9531 | Error tracing is enabled: command substitution, shell functions, and |
2206f89a | 9532 | subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the |
5cdaaf76 | 9533 | \fBERR\fP trap. |
d3a24ed2 CR |
9534 | .RE |
9535 | .TP 8 | |
cce855bc JA |
9536 | .B extglob |
9537 | If set, the extended pattern matching features described above under | |
9538 | \fBPathname Expansion\fP are enabled. | |
9539 | .TP 8 | |
d3a24ed2 | 9540 | .B extquote |
20587658 | 9541 | If set, \fB$\fP\(aq\fIstring\fP\(aq and \fB$\fP"\fIstring\fP" quoting is |
d3a24ed2 CR |
9542 | performed within \fB${\fP\fIparameter\fP\fB}\fP expansions |
9543 | enclosed in double quotes. This option is enabled by default. | |
9544 | .TP 8 | |
9545 | .B failglob | |
9546 | If set, patterns which fail to match filenames during pathname expansion | |
9547 | result in an expansion error. | |
9548 | .TP 8 | |
9549 | .B force_fignore | |
984a1947 CR |
9550 | If set, the suffixes specified by the |
9551 | .SM | |
9552 | .B FIGNORE | |
9553 | shell variable | |
d3a24ed2 CR |
9554 | cause words to be ignored when performing word completion even if |
9555 | the ignored words are the only possible completions. | |
9556 | See | |
9557 | .SM | |
9558 | \fBSHELL VARIABLES\fP | |
984a1947 CR |
9559 | above for a description of |
9560 | .SM | |
9561 | .BR FIGNORE . | |
d3a24ed2 CR |
9562 | This option is enabled by default. |
9563 | .TP 8 | |
74d0116b | 9564 | .B globasciiranges |
c111d992 | 9565 | If set, range expressions used in pattern matching bracket expressions (see |
74d0116b CR |
9566 | .SM |
9567 | .B Pattern Matching | |
9568 | above) behave as if in the traditional C locale when performing | |
9569 | comparisons. That is, the current locale's collating sequence | |
9570 | is not taken into account, so | |
9571 | .B b | |
9572 | will not collate between | |
9573 | .B A | |
9574 | and | |
9575 | .BR B , | |
9576 | and upper-case and lower-case ASCII characters will collate together. | |
9577 | .TP 8 | |
4ac1ff98 | 9578 | .B globstar |
d0ca3503 | 9579 | If set, the pattern \fB**\fP used in a pathname expansion context will |
54a1fa7c | 9580 | match all files and zero or more directories and subdirectories. |
4ac1ff98 CR |
9581 | If the pattern is followed by a \fB/\fP, only directories and |
9582 | subdirectories match. | |
9583 | .TP 8 | |
d3a24ed2 CR |
9584 | .B gnu_errfmt |
9585 | If set, shell error messages are written in the standard GNU error | |
9586 | message format. | |
9587 | .TP 8 | |
ccc6cda3 JA |
9588 | .B histappend |
9589 | If set, the history list is appended to the file named by the value | |
9590 | of the | |
984a1947 | 9591 | .SM |
ccc6cda3 JA |
9592 | .B HISTFILE |
9593 | variable when the shell exits, rather than overwriting the file. | |
9594 | .TP 8 | |
9595 | .B histreedit | |
9596 | If set, and | |
9597 | .B readline | |
9598 | is being used, a user is given the opportunity to re-edit a | |
9599 | failed history substitution. | |
9600 | .TP 8 | |
9601 | .B histverify | |
fc527055 | 9602 | If set, and |
ccc6cda3 JA |
9603 | .B readline |
9604 | is being used, the results of history substitution are not immediately | |
9605 | passed to the shell parser. Instead, the resulting line is loaded into | |
9606 | the \fBreadline\fP editing buffer, allowing further modification. | |
9607 | .TP 8 | |
9608 | .B hostcomplete | |
9609 | If set, and | |
9610 | .B readline | |
cce855bc JA |
9611 | is being used, \fBbash\fP will attempt to perform hostname completion when a |
9612 | word containing a \fB@\fP is being completed (see | |
ccc6cda3 JA |
9613 | .B Completing |
9614 | under | |
9615 | .SM | |
9616 | .B READLINE | |
9617 | above). | |
9618 | This is enabled by default. | |
9619 | .TP 8 | |
cce855bc JA |
9620 | .B huponexit |
9621 | If set, \fBbash\fP will send | |
9622 | .SM | |
9623 | .B SIGHUP | |
9624 | to all jobs when an interactive login shell exits. | |
9625 | .TP 8 | |
ccc6cda3 JA |
9626 | .B interactive_comments |
9627 | If set, allow a word beginning with | |
9628 | .B # | |
9629 | to cause that word and all remaining characters on that | |
9630 | line to be ignored in an interactive shell (see | |
9631 | .SM | |
9632 | .B COMMENTS | |
9633 | above). This option is enabled by default. | |
9634 | .TP 8 | |
7d92f73f CR |
9635 | .B lastpipe |
9636 | If set, and job control is not active, the shell runs the last command of | |
9637 | a pipeline not executed in the background in the current shell environment. | |
9638 | .TP 8 | |
ccc6cda3 JA |
9639 | .B lithist |
9640 | If set, and the | |
9641 | .B cmdhist | |
9642 | option is enabled, multi-line commands are saved to the history with | |
9643 | embedded newlines rather than using semicolon separators where possible. | |
9644 | .TP 8 | |
f73dda09 JA |
9645 | .B login_shell |
9646 | The shell sets this option if it is started as a login shell (see | |
9647 | .SM | |
9648 | .B "INVOCATION" | |
9649 | above). | |
9650 | The value may not be changed. | |
9651 | .TP 8 | |
ccc6cda3 | 9652 | .B mailwarn |
fc527055 | 9653 | If set, and a file that \fBbash\fP is checking for mail has been |
ccc6cda3 JA |
9654 | accessed since the last time it was checked, the message ``The mail in |
9655 | \fImailfile\fP has been read'' is displayed. | |
9656 | .TP 8 | |
bb70624e JA |
9657 | .B no_empty_cmd_completion |
9658 | If set, and | |
9659 | .B readline | |
9660 | is being used, | |
9661 | .B bash | |
984a1947 CR |
9662 | will not attempt to search the |
9663 | .SM | |
9664 | .B PATH | |
9665 | for possible completions when | |
bb70624e JA |
9666 | completion is attempted on an empty line. |
9667 | .TP 8 | |
cce855bc JA |
9668 | .B nocaseglob |
9669 | If set, | |
9670 | .B bash | |
9671 | matches filenames in a case\-insensitive fashion when performing pathname | |
9672 | expansion (see | |
9673 | .B Pathname Expansion | |
9674 | above). | |
9675 | .TP 8 | |
2206f89a CR |
9676 | .B nocasematch |
9677 | If set, | |
9678 | .B bash | |
9679 | matches patterns in a case\-insensitive fashion when performing matching | |
0a233f3e | 9680 | while executing \fBcase\fP or \fB[[\fP conditional commands, |
09f70f2f | 9681 | when performing pattern substitution word expansions, |
0a233f3e | 9682 | or when filtering possible completions as part of programmable completion. |
2206f89a | 9683 | .TP 8 |
ccc6cda3 JA |
9684 | .B nullglob |
9685 | If set, | |
9686 | .B bash | |
9687 | allows patterns which match no | |
9688 | files (see | |
9689 | .B Pathname Expansion | |
9690 | above) | |
9691 | to expand to a null string, rather than themselves. | |
9692 | .TP 8 | |
bb70624e JA |
9693 | .B progcomp |
9694 | If set, the programmable completion facilities (see | |
9695 | \fBProgrammable Completion\fP above) are enabled. | |
9696 | This option is enabled by default. | |
9697 | .TP 8 | |
ccc6cda3 | 9698 | .B promptvars |
d3a24ed2 CR |
9699 | If set, prompt strings undergo |
9700 | parameter expansion, command substitution, arithmetic | |
9701 | expansion, and quote removal after being expanded as described in | |
ccc6cda3 JA |
9702 | .SM |
9703 | .B PROMPTING | |
9704 | above. This option is enabled by default. | |
9705 | .TP 8 | |
b72432fd JA |
9706 | .B restricted_shell |
9707 | The shell sets this option if it is started in restricted mode (see | |
9708 | .SM | |
9709 | .B "RESTRICTED SHELL" | |
9710 | below). | |
9711 | The value may not be changed. | |
9712 | This is not reset when the startup files are executed, allowing | |
9713 | the startup files to discover whether or not a shell is restricted. | |
9714 | .TP 8 | |
ccc6cda3 JA |
9715 | .B shift_verbose |
9716 | If set, the | |
9717 | .B shift | |
9718 | builtin prints an error message when the shift count exceeds the | |
9719 | number of positional parameters. | |
9720 | .TP 8 | |
9721 | .B sourcepath | |
9722 | If set, the | |
9723 | \fBsource\fP (\fB.\fP) builtin uses the value of | |
9724 | .SM | |
9725 | .B PATH | |
9726 | to find the directory containing the file supplied as an argument. | |
cce855bc | 9727 | This option is enabled by default. |
bb70624e JA |
9728 | .TP 8 |
9729 | .B xpg_echo | |
9730 | If set, the \fBecho\fP builtin expands backslash-escape sequences | |
9731 | by default. | |
ccc6cda3 | 9732 | .RE |
54a1fa7c | 9733 | .PD |
726f6388 JA |
9734 | .TP |
9735 | \fBsuspend\fP [\fB\-f\fP] | |
9736 | Suspend the execution of this shell until it receives a | |
9737 | .SM | |
9738 | .B SIGCONT | |
09767ff0 | 9739 | signal. A login shell cannot be suspended; the |
726f6388 | 9740 | .B \-f |
09767ff0 CR |
9741 | option can be used to override this and force the suspension. |
9742 | The return status is 0 unless the shell is a login shell and | |
726f6388 JA |
9743 | .B \-f |
9744 | is not supplied, or if job control is not enabled. | |
9745 | .TP | |
726f6388 | 9746 | \fBtest\fP \fIexpr\fP |
7117c2d2 | 9747 | .PD 0 |
726f6388 JA |
9748 | .TP |
9749 | \fB[\fP \fIexpr\fP \fB]\fP | |
b28ff8c9 | 9750 | Return a status of 0 (true) or 1 (false) depending on |
726f6388 JA |
9751 | the evaluation of the conditional expression |
9752 | .IR expr . | |
cce855bc JA |
9753 | Each operator and operand must be a separate argument. |
9754 | Expressions are composed of the primaries described above under | |
9755 | .SM | |
9756 | .BR "CONDITIONAL EXPRESSIONS" . | |
3ffb039a CR |
9757 | \fBtest\fP does not accept any options, nor does it accept and ignore |
9758 | an argument of \fB\-\-\fP as signifying the end of options. | |
cce855bc JA |
9759 | .if t .sp 0.5 |
9760 | .if n .sp 1 | |
9761 | Expressions may be combined using the following operators, listed | |
9762 | in decreasing order of precedence. | |
641d8f00 | 9763 | The evaluation depends on the number of arguments; see below. |
06dff54a | 9764 | Operator precedence is used when there are five or more arguments. |
726f6388 JA |
9765 | .RS |
9766 | .PD 0 | |
9767 | .TP | |
726f6388 JA |
9768 | .B ! \fIexpr\fP |
9769 | True if | |
9770 | .I expr | |
9771 | is false. | |
9772 | .TP | |
cce855bc JA |
9773 | .B ( \fIexpr\fP ) |
9774 | Returns the value of \fIexpr\fP. | |
9775 | This may be used to override the normal precedence of operators. | |
9776 | .TP | |
726f6388 JA |
9777 | \fIexpr1\fP \-\fBa\fP \fIexpr2\fP |
9778 | True if both | |
9779 | .I expr1 | |
cce855bc | 9780 | and |
726f6388 JA |
9781 | .I expr2 |
9782 | are true. | |
9783 | .TP | |
9784 | \fIexpr1\fP \-\fBo\fP \fIexpr2\fP | |
9785 | True if either | |
9786 | .I expr1 | |
cce855bc | 9787 | or |
726f6388 JA |
9788 | .I expr2 |
9789 | is true. | |
cce855bc JA |
9790 | .PD |
9791 | .PP | |
9792 | \fBtest\fP and \fB[\fP evaluate conditional | |
9793 | expressions using a set of rules based on the number of arguments. | |
9794 | .if t .sp 0.5 | |
9795 | .if n .sp 1 | |
9796 | .PD 0 | |
726f6388 | 9797 | .TP |
cce855bc JA |
9798 | 0 arguments |
9799 | The expression is false. | |
9800 | .TP | |
9801 | 1 argument | |
9802 | The expression is true if and only if the argument is not null. | |
9803 | .TP | |
9804 | 2 arguments | |
9805 | If the first argument is \fB!\fP, the expression is true if and | |
9806 | only if the second argument is null. | |
9807 | If the first argument is one of the unary conditional operators listed above | |
9808 | under | |
726f6388 | 9809 | .SM |
cce855bc JA |
9810 | .BR "CONDITIONAL EXPRESSIONS" , |
9811 | the expression is true if the unary test is true. | |
9812 | If the first argument is not a valid unary conditional operator, the expression | |
9813 | is false. | |
9814 | .TP | |
9815 | 3 arguments | |
adc6cff5 | 9816 | The following conditions are applied in the order listed. |
cce855bc JA |
9817 | If the second argument is one of the binary conditional operators listed above |
9818 | under | |
9819 | .SM | |
9820 | .BR "CONDITIONAL EXPRESSIONS" , | |
9821 | the result of the expression is the result of the binary test using | |
9822 | the first and third arguments as operands. | |
641d8f00 | 9823 | The \fB\-a\fP and \fB\-o\fP operators are considered binary operators |
fc527055 | 9824 | when there are three arguments. |
cce855bc JA |
9825 | If the first argument is \fB!\fP, the value is the negation of |
9826 | the two-argument test using the second and third arguments. | |
9827 | If the first argument is exactly \fB(\fP and the third argument is | |
9828 | exactly \fB)\fP, the result is the one-argument test of the second | |
9829 | argument. | |
9830 | Otherwise, the expression is false. | |
cce855bc JA |
9831 | .TP |
9832 | 4 arguments | |
9833 | If the first argument is \fB!\fP, the result is the negation of | |
9834 | the three-argument expression composed of the remaining arguments. | |
fc527055 | 9835 | Otherwise, the expression is parsed and evaluated according to |
cce855bc JA |
9836 | precedence using the rules listed above. |
9837 | .TP | |
9838 | 5 or more arguments | |
9839 | The expression is parsed and evaluated according to precedence | |
9840 | using the rules listed above. | |
54a1fa7c CR |
9841 | .if t .sp 0.5 |
9842 | .if n .sp 1 | |
9843 | .LP | |
9844 | When used with \fBtest\fP or \fB[\fP, the \fB<\fP and \fB>\fP operators | |
9845 | sort lexicographically using ASCII ordering. | |
726f6388 | 9846 | .RE |
cce855bc | 9847 | .PD |
726f6388 JA |
9848 | .TP |
9849 | .B times | |
9850 | Print the accumulated user and system times for the shell and | |
9851 | for processes run from the shell. The return status is 0. | |
9852 | .TP | |
61deeb13 | 9853 | \fBtrap\fP [\fB\-lp\fP] [[\fIarg\fP] \fIsigspec\fP ...] |
726f6388 JA |
9854 | The command |
9855 | .I arg | |
9856 | is to be read and executed when the shell receives | |
9857 | signal(s) | |
9858 | .IR sigspec . | |
9859 | If | |
9860 | .I arg | |
61deeb13 | 9861 | is absent (and there is a single \fIsigspec\fP) or |
726f6388 | 9862 | .BR \- , |
61deeb13 CR |
9863 | each specified signal is |
9864 | reset to its original disposition (the value it had | |
d166f048 | 9865 | upon entrance to the shell). |
fc527055 | 9866 | If |
726f6388 | 9867 | .I arg |
d166f048 JA |
9868 | is the null string the signal specified by each |
9869 | .I sigspec | |
9870 | is ignored by the shell and by the commands it invokes. | |
ccc6cda3 JA |
9871 | If |
9872 | .I arg | |
bb70624e | 9873 | is not present and |
ccc6cda3 | 9874 | .B \-p |
bb70624e | 9875 | has been supplied, then the trap commands associated with each |
ccc6cda3 | 9876 | .I sigspec |
bb70624e JA |
9877 | are displayed. |
9878 | If no arguments are supplied or if only | |
ccc6cda3 JA |
9879 | .B \-p |
9880 | is given, | |
9881 | .B trap | |
61deeb13 | 9882 | prints the list of commands associated with each signal. |
d3a24ed2 CR |
9883 | The |
9884 | .B \-l | |
9885 | option causes the shell to print a list of signal names and | |
9886 | their corresponding numbers. | |
d166f048 | 9887 | Each |
726f6388 JA |
9888 | .I sigspec |
9889 | is either | |
d166f048 | 9890 | a signal name defined in <\fIsignal.h\fP>, or a signal number. |
9c7f20c7 CR |
9891 | Signal names are case insensitive and the |
9892 | .SM | |
9893 | .B SIG | |
9894 | prefix is optional. | |
4301bca7 CR |
9895 | .if t .sp 0.5 |
9896 | .if n .sp 1 | |
d166f048 | 9897 | If a |
726f6388 JA |
9898 | .I sigspec |
9899 | is | |
9900 | .SM | |
9901 | .B EXIT | |
9902 | (0) the command | |
9903 | .I arg | |
f73dda09 JA |
9904 | is executed on exit from the shell. |
9905 | If a | |
ccc6cda3 JA |
9906 | .I sigspec |
9907 | is | |
9908 | .SM | |
9909 | .BR DEBUG , | |
9910 | the command | |
9911 | .I arg | |
d3a24ed2 CR |
9912 | is executed before every \fIsimple command\fP, \fIfor\fP command, |
9913 | \fIcase\fP command, \fIselect\fP command, every arithmetic \fIfor\fP | |
9914 | command, and before the first command executes in a shell function (see | |
ccc6cda3 JA |
9915 | .SM |
9916 | .B SHELL GRAMMAR | |
9917 | above). | |
40b074c6 | 9918 | Refer to the description of the \fBextdebug\fP option to the |
d3a24ed2 | 9919 | \fBshopt\fP builtin for details of its effect on the \fBDEBUG\fP trap. |
f73dda09 JA |
9920 | If a |
9921 | .I sigspec | |
9922 | is | |
9923 | .SM | |
4301bca7 CR |
9924 | .BR RETURN , |
9925 | the command | |
9926 | .I arg | |
e05be32d CR |
9927 | is executed each time a shell function or a script executed with |
9928 | the \fB.\fP or \fBsource\fP builtins finishes executing. | |
4301bca7 CR |
9929 | .if t .sp 0.5 |
9930 | .if n .sp 1 | |
9931 | If a | |
9932 | .I sigspec | |
9933 | is | |
9934 | .SM | |
f73dda09 JA |
9935 | .BR ERR , |
9936 | the command | |
9937 | .I arg | |
fc527055 | 9938 | is executed whenever a |
1b1fe467 | 9939 | a pipeline (which may consist of a single simple |
fc527055 | 9940 | command), a list, or a compound command returns a |
1b1fe467 | 9941 | non\-zero exit status, |
5e13499c | 9942 | subject to the following conditions. |
f73dda09 JA |
9943 | The |
9944 | .SM | |
d3a24ed2 CR |
9945 | .B ERR |
9946 | trap is not executed if the failed | |
9947 | command is part of the command list immediately following a | |
9948 | .B while | |
f73dda09 | 9949 | or |
d3a24ed2 | 9950 | .B until |
fc527055 | 9951 | keyword, |
d3a24ed2 | 9952 | part of the test in an |
f73dda09 | 9953 | .I if |
9d85af6d | 9954 | statement, part of a command executed in a |
f73dda09 JA |
9955 | .B && |
9956 | or | |
adc6cff5 | 9957 | .B || |
1b1fe467 CR |
9958 | list except the command following the final \fB&&\fP or \fB||\fP, |
9959 | any command in a pipeline but the last, | |
9960 | or if the command's return value is | |
9961 | being inverted using | |
f73dda09 | 9962 | .BR ! . |
1b1fe467 | 9963 | These are the same conditions obeyed by the \fBerrexit\fP (\fB\-e\fP) option. |
4301bca7 CR |
9964 | .if t .sp 0.5 |
9965 | .if n .sp 1 | |
726f6388 | 9966 | Signals ignored upon entry to the shell cannot be trapped or reset. |
d3ad40de | 9967 | Trapped signals that are not being ignored are reset to their original |
4301bca7 | 9968 | values in a subshell or subshell environment when one is created. |
d166f048 | 9969 | The return status is false if any |
ccc6cda3 JA |
9970 | .I sigspec |
9971 | is invalid; otherwise | |
726f6388 JA |
9972 | .B trap |
9973 | returns true. | |
9974 | .TP | |
7117c2d2 | 9975 | \fBtype\fP [\fB\-aftpP\fP] \fIname\fP [\fIname\fP ...] |
fc527055 | 9976 | With no options, |
726f6388 JA |
9977 | indicate how each |
9978 | .I name | |
9979 | would be interpreted if used as a command name. | |
9980 | If the | |
cce855bc JA |
9981 | .B \-t |
9982 | option is used, | |
726f6388 | 9983 | .B type |
ccc6cda3 | 9984 | prints a string which is one of |
726f6388 JA |
9985 | .IR alias , |
9986 | .IR keyword , | |
9987 | .IR function , | |
9988 | .IR builtin , | |
9989 | or | |
fc527055 | 9990 | .I file |
726f6388 JA |
9991 | if |
9992 | .I name | |
9993 | is an alias, shell reserved word, function, builtin, or disk file, | |
ccc6cda3 JA |
9994 | respectively. |
9995 | If the | |
9996 | .I name | |
9997 | is not found, then nothing is printed, and an exit status of false | |
9998 | is returned. | |
726f6388 | 9999 | If the |
cce855bc JA |
10000 | .B \-p |
10001 | option is used, | |
726f6388 JA |
10002 | .B type |
10003 | either returns the name of the disk file | |
10004 | that would be executed if | |
10005 | .I name | |
10006 | were specified as a command name, | |
28ef6c31 JA |
10007 | or nothing if |
10008 | .if t \f(CWtype -t name\fP | |
10009 | .if n ``type -t name'' | |
726f6388 JA |
10010 | would not return |
10011 | .IR file . | |
7117c2d2 JA |
10012 | The |
10013 | .B \-P | |
10014 | option forces a | |
10015 | .SM | |
10016 | .B PATH | |
10017 | search for each \fIname\fP, even if | |
10018 | .if t \f(CWtype -t name\fP | |
10019 | .if n ``type -t name'' | |
10020 | would not return | |
10021 | .IR file . | |
726f6388 | 10022 | If a command is hashed, |
cce855bc | 10023 | .B \-p |
7117c2d2 JA |
10024 | and |
10025 | .B \-P | |
b28ff8c9 | 10026 | print the hashed value, which is not necessarily the file that appears |
fc527055 | 10027 | first in |
726f6388 JA |
10028 | .SM |
10029 | .BR PATH . | |
10030 | If the | |
cce855bc | 10031 | .B \-a |
fc527055 | 10032 | option is used, |
726f6388 JA |
10033 | .B type |
10034 | prints all of the places that contain | |
fc527055 | 10035 | an executable named |
726f6388 JA |
10036 | .IR name . |
10037 | This includes aliases and functions, | |
fc527055 | 10038 | if and only if the |
cce855bc JA |
10039 | .B \-p |
10040 | option is not also used. | |
726f6388 JA |
10041 | The table of hashed commands is not consulted |
10042 | when using | |
cce855bc | 10043 | .BR \-a . |
7117c2d2 JA |
10044 | The |
10045 | .B \-f | |
10046 | option suppresses shell function lookup, as with the \fBcommand\fP builtin. | |
726f6388 | 10047 | .B type |
6a8fd0ed CR |
10048 | returns true if all of the arguments are found, false if |
10049 | any are not found. | |
726f6388 | 10050 | .TP |
f3aad56d | 10051 | \fBulimit\fP [\fB\-HSabcdefiklmnpqrstuvxPT\fP [\fIlimit\fP]] |
ccc6cda3 | 10052 | Provides control over the resources available to the shell and to |
f73dda09 | 10053 | processes started by it, on systems that allow such control. |
ccc6cda3 | 10054 | The \fB\-H\fP and \fB\-S\fP options specify that the hard or soft limit is |
79e6c7dc CR |
10055 | set for the given resource. |
10056 | A hard limit cannot be increased by a non-root user once it is set; | |
10057 | a soft limit may be increased up to the value of the hard limit. | |
ccc6cda3 JA |
10058 | If neither \fB\-H\fP nor \fB\-S\fP is specified, both the soft and hard |
10059 | limits are set. | |
f73dda09 JA |
10060 | The value of |
10061 | .I limit | |
10062 | can be a number in the unit specified for the resource | |
10063 | or one of the special values | |
10064 | .BR hard , | |
10065 | .BR soft , | |
10066 | or | |
10067 | .BR unlimited , | |
10068 | which stand for the current hard limit, the current soft limit, and | |
10069 | no limit, respectively. | |
ccc6cda3 | 10070 | If |
726f6388 JA |
10071 | .I limit |
10072 | is omitted, the current value of the soft limit of the resource is | |
ccc6cda3 JA |
10073 | printed, unless the \fB\-H\fP option is given. When more than one |
10074 | resource is specified, the limit name and unit are printed before the value. | |
726f6388 JA |
10075 | Other options are interpreted as follows: |
10076 | .RS | |
10077 | .PD 0 | |
10078 | .TP | |
10079 | .B \-a | |
ccc6cda3 | 10080 | All current limits are reported |
726f6388 | 10081 | .TP |
6fbe7620 CR |
10082 | .B \-b |
10083 | The maximum socket buffer size | |
10084 | .TP | |
726f6388 | 10085 | .B \-c |
ccc6cda3 | 10086 | The maximum size of core files created |
726f6388 JA |
10087 | .TP |
10088 | .B \-d | |
ccc6cda3 | 10089 | The maximum size of a process's data segment |
726f6388 | 10090 | .TP |
dc8fbaf9 CR |
10091 | .B \-e |
10092 | The maximum scheduling priority ("nice") | |
10093 | .TP | |
726f6388 | 10094 | .B \-f |
d3ad40de | 10095 | The maximum size of files written by the shell and its children |
726f6388 | 10096 | .TP |
af12dacd CR |
10097 | .B \-i |
10098 | The maximum number of pending signals | |
10099 | .TP | |
f3aad56d CR |
10100 | .B \-k |
10101 | The maximum number of kqueues that may be allocated | |
10102 | .TP | |
ccc6cda3 JA |
10103 | .B \-l |
10104 | The maximum size that may be locked into memory | |
726f6388 | 10105 | .TP |
ccc6cda3 | 10106 | .B \-m |
db31fb26 | 10107 | The maximum resident set size (many systems do not honor this limit) |
726f6388 | 10108 | .TP |
ccc6cda3 JA |
10109 | .B \-n |
10110 | The maximum number of open file descriptors (most systems do not | |
10111 | allow this value to be set) | |
726f6388 JA |
10112 | .TP |
10113 | .B \-p | |
ccc6cda3 | 10114 | The pipe size in 512-byte blocks (this may not be set) |
726f6388 | 10115 | .TP |
af12dacd CR |
10116 | .B \-q |
10117 | The maximum number of bytes in POSIX message queues | |
10118 | .TP | |
dc8fbaf9 CR |
10119 | .B \-r |
10120 | The maximum real-time scheduling priority | |
10121 | .TP | |
ccc6cda3 JA |
10122 | .B \-s |
10123 | The maximum stack size | |
10124 | .TP | |
10125 | .B \-t | |
10126 | The maximum amount of cpu time in seconds | |
726f6388 JA |
10127 | .TP |
10128 | .B \-u | |
ccc6cda3 | 10129 | The maximum number of processes available to a single user |
726f6388 JA |
10130 | .TP |
10131 | .B \-v | |
68dfe178 CR |
10132 | The maximum amount of virtual memory available to the shell and, on |
10133 | some systems, to its children | |
af12dacd CR |
10134 | .TP |
10135 | .B \-x | |
10136 | The maximum number of file locks | |
6fbe7620 | 10137 | .TP |
f3aad56d CR |
10138 | .B \-P |
10139 | The maximum number of pseudoterminals | |
10140 | .TP | |
6fbe7620 CR |
10141 | .B \-T |
10142 | The maximum number of threads | |
726f6388 JA |
10143 | .PD |
10144 | .PP | |
ccc6cda3 | 10145 | If |
726f6388 | 10146 | .I limit |
b28ff8c9 | 10147 | is given, and the |
726f6388 | 10148 | .B \-a |
b28ff8c9 CR |
10149 | option is not used, |
10150 | \fIlimit\fP is the new value of the specified resource. | |
726f6388 JA |
10151 | If no option is given, then |
10152 | .B \-f | |
10153 | is assumed. Values are in 1024-byte increments, except for | |
10154 | .BR \-t , | |
b28ff8c9 | 10155 | which is in seconds; |
726f6388 | 10156 | .BR \-p , |
b28ff8c9 | 10157 | which is in units of 512-byte blocks; |
726f6388 | 10158 | and |
f3aad56d | 10159 | .BR \-P , |
6fbe7620 CR |
10160 | .BR \-T , |
10161 | .BR \-b , | |
f3aad56d | 10162 | .BR \-k , |
6fbe7620 | 10163 | .BR \-n , |
726f6388 JA |
10164 | and |
10165 | .BR \-u , | |
f73dda09 JA |
10166 | which are unscaled values. |
10167 | The return status is 0 unless an invalid option or argument is supplied, | |
10168 | or an error occurs while setting a new limit. | |
726f6388 JA |
10169 | .RE |
10170 | .TP | |
cce855bc | 10171 | \fBumask\fP [\fB\-p\fP] [\fB\-S\fP] [\fImode\fP] |
fc527055 | 10172 | The user file-creation mask is set to |
726f6388 JA |
10173 | .IR mode . |
10174 | If | |
10175 | .I mode | |
10176 | begins with a digit, it | |
10177 | is interpreted as an octal number; otherwise | |
10178 | it is interpreted as a symbolic mode mask similar | |
10179 | to that accepted by | |
10180 | .IR chmod (1). | |
10181 | If | |
10182 | .I mode | |
bb70624e | 10183 | is omitted, the current value of the mask is printed. |
ccc6cda3 | 10184 | The |
726f6388 JA |
10185 | .B \-S |
10186 | option causes the mask to be printed in symbolic form; the | |
10187 | default output is an octal number. | |
cce855bc JA |
10188 | If the |
10189 | .B \-p | |
10190 | option is supplied, and | |
10191 | .I mode | |
10192 | is omitted, the output is in a form that may be reused as input. | |
ccc6cda3 | 10193 | The return status is 0 if the mode was successfully changed or if |
726f6388 JA |
10194 | no \fImode\fP argument was supplied, and false otherwise. |
10195 | .TP | |
10196 | \fBunalias\fP [\-\fBa\fP] [\fIname\fP ...] | |
bb70624e | 10197 | Remove each \fIname\fP from the list of defined aliases. If |
726f6388 JA |
10198 | .B \-a |
10199 | is supplied, all alias definitions are removed. The return | |
10200 | value is true unless a supplied | |
10201 | .I name | |
10202 | is not a defined alias. | |
10203 | .TP | |
87c1f4ec | 10204 | \fBunset\fP [\-\fBfv\fP] [\-\fBn\fP] [\fIname\fP ...] |
726f6388 JA |
10205 | For each |
10206 | .IR name , | |
ccc6cda3 | 10207 | remove the corresponding variable or function. |
276cb932 | 10208 | If the |
ccc6cda3 JA |
10209 | .B \-v |
10210 | option is given, each | |
10211 | .I name | |
276cb932 | 10212 | refers to a shell variable, and that variable is removed. |
ccc6cda3 JA |
10213 | Read-only variables may not be unset. |
10214 | If | |
726f6388 | 10215 | .B \-f |
f75912ae | 10216 | is specified, each |
ccc6cda3 JA |
10217 | .I name |
10218 | refers to a shell function, and the function definition | |
10219 | is removed. | |
87c1f4ec CR |
10220 | If the |
10221 | .B \-n | |
10222 | option is supplied, and \fIname\fP is a variable with the \fInameref\fP | |
10223 | attribute, \fIname\fP will be unset rather than the variable it | |
10224 | references. | |
10225 | \fB\-n\fP has no effect if the \fB\-f\fP option is supplied. | |
276cb932 CR |
10226 | If no options are supplied, each \fIname\fP refers to a variable; if |
10227 | there is no variable by that name, any function with that name is | |
10228 | unset. | |
ccc6cda3 JA |
10229 | Each unset variable or function is removed from the environment |
10230 | passed to subsequent commands. | |
10231 | If any of | |
726f6388 | 10232 | .SM |
984a1947 CR |
10233 | .BR COMP_WORDBREAKS , |
10234 | .SM | |
726f6388 JA |
10235 | .BR RANDOM , |
10236 | .SM | |
10237 | .BR SECONDS , | |
10238 | .SM | |
10239 | .BR LINENO , | |
ccc6cda3 JA |
10240 | .SM |
10241 | .BR HISTCMD , | |
bb70624e JA |
10242 | .SM |
10243 | .BR FUNCNAME , | |
10244 | .SM | |
10245 | .BR GROUPS , | |
726f6388 JA |
10246 | or |
10247 | .SM | |
ccc6cda3 | 10248 | .B DIRSTACK |
726f6388 JA |
10249 | are unset, they lose their special properties, even if they are |
10250 | subsequently reset. The exit status is true unless a | |
10251 | .I name | |
d3a24ed2 | 10252 | is readonly. |
726f6388 | 10253 | .TP |
9353cc05 | 10254 | \fBwait\fP [\fB\-n\fP] [\fIn ...\fP] |
ef5b315f | 10255 | Wait for each specified child process and return its termination status. |
d90269dd | 10256 | Each |
726f6388 JA |
10257 | .I n |
10258 | may be a process | |
10259 | ID or a job specification; if a job spec is given, all processes | |
10260 | in that job's pipeline are waited for. If | |
10261 | .I n | |
10262 | is not given, all currently active child processes | |
3087e51c | 10263 | are waited for, and the return status is zero. |
9353cc05 | 10264 | If the \fB\-n\fP option is supplied, \fBwait\fP waits for any job to |
3087e51c CR |
10265 | terminate and returns its exit status. |
10266 | If | |
726f6388 | 10267 | .I n |
ccc6cda3 | 10268 | specifies a non-existent process or job, the return status is |
726f6388 JA |
10269 | 127. Otherwise, the return status is the exit status of the last |
10270 | process or job waited for. | |
10271 | .\" bash_builtins | |
10272 | .if \n(zZ=1 .ig zZ | |
ccc6cda3 | 10273 | .SH "RESTRICTED SHELL" |
bb70624e JA |
10274 | .\" rbash.1 |
10275 | .zY | |
726f6388 | 10276 | .PP |
ccc6cda3 | 10277 | If |
726f6388 | 10278 | .B bash |
ccc6cda3 JA |
10279 | is started with the name |
10280 | .BR rbash , | |
10281 | or the | |
10282 | .B \-r | |
10283 | option is supplied at invocation, | |
10284 | the shell becomes restricted. | |
10285 | A restricted shell is used to | |
10286 | set up an environment more controlled than the standard shell. | |
10287 | It behaves identically to | |
10288 | .B bash | |
cce855bc | 10289 | with the exception that the following are disallowed or not performed: |
ccc6cda3 JA |
10290 | .IP \(bu |
10291 | changing directories with \fBcd\fP | |
10292 | .IP \(bu | |
10293 | setting or unsetting the values of | |
984a1947 | 10294 | .SM |
b72432fd | 10295 | .BR SHELL , |
984a1947 | 10296 | .SM |
b72432fd | 10297 | .BR PATH , |
984a1947 | 10298 | .SM |
b72432fd | 10299 | .BR ENV , |
ccc6cda3 | 10300 | or |
984a1947 | 10301 | .SM |
b72432fd | 10302 | .B BASH_ENV |
ccc6cda3 JA |
10303 | .IP \(bu |
10304 | specifying command names containing | |
10305 | .B / | |
10306 | .IP \(bu | |
b28ff8c9 | 10307 | specifying a filename containing a |
ccc6cda3 JA |
10308 | .B / |
10309 | as an argument to the | |
10310 | .B . | |
10311 | builtin command | |
10312 | .IP \(bu | |
dc60d4e0 | 10313 | specifying a filename containing a slash as an argument to the |
bb70624e JA |
10314 | .B \-p |
10315 | option to the | |
10316 | .B hash | |
10317 | builtin command | |
10318 | .IP \(bu | |
ccc6cda3 JA |
10319 | importing function definitions from the shell environment at startup |
10320 | .IP \(bu | |
984a1947 CR |
10321 | parsing the value of |
10322 | .SM | |
10323 | .B SHELLOPTS | |
10324 | from the shell environment at startup | |
cce855bc | 10325 | .IP \(bu |
ccc6cda3 JA |
10326 | redirecting output using the >, >|, <>, >&, &>, and >> redirection operators |
10327 | .IP \(bu | |
10328 | using the | |
10329 | .B exec | |
10330 | builtin command to replace the shell with another command | |
10331 | .IP \(bu | |
10332 | adding or deleting builtin commands with the | |
10333 | .B \-f | |
726f6388 | 10334 | and |
ccc6cda3 JA |
10335 | .B \-d |
10336 | options to the | |
10337 | .B enable | |
10338 | builtin command | |
10339 | .IP \(bu | |
dc60d4e0 | 10340 | using the \fBenable\fP builtin command to enable disabled shell builtins |
7117c2d2 | 10341 | .IP \(bu |
ccc6cda3 JA |
10342 | specifying the |
10343 | .B \-p | |
10344 | option to the | |
10345 | .B command | |
10346 | builtin command | |
10347 | .IP \(bu | |
10348 | turning off restricted mode with | |
cce855bc | 10349 | \fBset +r\fP or \fBset +o restricted\fP. |
726f6388 | 10350 | .PP |
ccc6cda3 JA |
10351 | These restrictions are enforced after any startup files are read. |
10352 | .PP | |
61deeb13 CR |
10353 | .ie \n(zY=1 When a command that is found to be a shell script is executed, |
10354 | .el \{ When a command that is found to be a shell script is executed | |
10355 | (see | |
ccc6cda3 JA |
10356 | .SM |
10357 | .B "COMMAND EXECUTION" | |
10358 | above), | |
61deeb13 | 10359 | \} |
ccc6cda3 JA |
10360 | .B rbash |
10361 | turns off any restrictions in the shell spawned to execute the | |
10362 | script. | |
bb70624e JA |
10363 | .\" end of rbash.1 |
10364 | .if \n(zY=1 .ig zY | |
726f6388 JA |
10365 | .SH "SEE ALSO" |
10366 | .PD 0 | |
10367 | .TP | |
bb70624e | 10368 | \fIBash Reference Manual\fP, Brian Fox and Chet Ramey |
726f6388 JA |
10369 | .TP |
10370 | \fIThe Gnu Readline Library\fP, Brian Fox and Chet Ramey | |
10371 | .TP | |
10372 | \fIThe Gnu History Library\fP, Brian Fox and Chet Ramey | |
10373 | .TP | |
a539713a CR |
10374 | \fIPortable Operating System Interface (POSIX) Part 2: Shell and Utilities\fP, IEEE -- |
10375 | http://pubs.opengroup.org/onlinepubs/9699919799/ | |
726f6388 | 10376 | .TP |
c677e9e0 CR |
10377 | http://tiswww.case.edu/~chet/bash/POSIX -- a description of posix mode |
10378 | .TP | |
726f6388 JA |
10379 | \fIsh\fP(1), \fIksh\fP(1), \fIcsh\fP(1) |
10380 | .TP | |
10381 | \fIemacs\fP(1), \fIvi\fP(1) | |
10382 | .TP | |
10383 | \fIreadline\fP(3) | |
10384 | .PD | |
10385 | .SH FILES | |
10386 | .PD 0 | |
10387 | .TP | |
10388 | .FN /bin/bash | |
10389 | The \fBbash\fP executable | |
10390 | .TP | |
10391 | .FN /etc/profile | |
10392 | The systemwide initialization file, executed for login shells | |
10393 | .TP | |
10394 | .FN ~/.bash_profile | |
10395 | The personal initialization file, executed for login shells | |
10396 | .TP | |
10397 | .FN ~/.bashrc | |
10398 | The individual per-interactive-shell startup file | |
10399 | .TP | |
b72432fd JA |
10400 | .FN ~/.bash_logout |
10401 | The individual login shell cleanup file, executed when a login shell exits | |
10402 | .TP | |
726f6388 JA |
10403 | .FN ~/.inputrc |
10404 | Individual \fIreadline\fP initialization file | |
10405 | .PD | |
10406 | .SH AUTHORS | |
ccc6cda3 | 10407 | Brian Fox, Free Software Foundation |
726f6388 | 10408 | .br |
bb70624e | 10409 | bfox@gnu.org |
726f6388 JA |
10410 | .PP |
10411 | Chet Ramey, Case Western Reserve University | |
10412 | .br | |
db31fb26 | 10413 | chet.ramey@case.edu |
726f6388 JA |
10414 | .SH BUG REPORTS |
10415 | If you find a bug in | |
10416 | .B bash, | |
10417 | you should report it. But first, you should | |
10418 | make sure that it really is a bug, and that it appears in the latest | |
10419 | version of | |
d3a24ed2 CR |
10420 | .BR bash . |
10421 | The latest version is always available from | |
9c7f20c7 | 10422 | \fIftp://ftp.gnu.org/pub/gnu/bash/\fP. |
726f6388 JA |
10423 | .PP |
10424 | Once you have determined that a bug actually exists, use the | |
10425 | .I bashbug | |
10426 | command to submit a bug report. | |
d166f048 | 10427 | If you have a fix, you are encouraged to mail that as well! |
726f6388 | 10428 | Suggestions and `philosophical' bug reports may be mailed |
cce855bc | 10429 | to \fIbug-bash@gnu.org\fP or posted to the Usenet |
726f6388 JA |
10430 | newsgroup |
10431 | .BR gnu.bash.bug . | |
10432 | .PP | |
10433 | ALL bug reports should include: | |
10434 | .PP | |
10435 | .PD 0 | |
10436 | .TP 20 | |
10437 | The version number of \fBbash\fR | |
10438 | .TP | |
10439 | The hardware and operating system | |
10440 | .TP | |
10441 | The compiler used to compile | |
10442 | .TP | |
10443 | A description of the bug behaviour | |
10444 | .TP | |
10445 | A short script or `recipe' which exercises the bug | |
10446 | .PD | |
10447 | .PP | |
10448 | .I bashbug | |
10449 | inserts the first three items automatically into the template | |
10450 | it provides for filing a bug report. | |
10451 | .PP | |
10452 | Comments and bug reports concerning | |
10453 | this manual page should be directed to | |
54a1fa7c | 10454 | .IR chet.ramey@case.edu . |
726f6388 JA |
10455 | .SH BUGS |
10456 | .PP | |
10457 | It's too big and too slow. | |
10458 | .PP | |
fc527055 | 10459 | There are some subtle differences between |
726f6388 JA |
10460 | .B bash |
10461 | and traditional versions of | |
10462 | .BR sh , | |
10463 | mostly because of the | |
10464 | .SM | |
10465 | .B POSIX | |
10466 | specification. | |
10467 | .PP | |
10468 | Aliases are confusing in some uses. | |
ccc6cda3 JA |
10469 | .PP |
10470 | Shell builtin commands and functions are not stoppable/restartable. | |
10471 | .PP | |
10472 | Compound commands and command sequences of the form `a ; b ; c' | |
10473 | are not handled gracefully when process suspension is attempted. | |
10474 | When a process is stopped, the shell immediately executes the next | |
10475 | command in the sequence. | |
10476 | It suffices to place the sequence of commands between | |
10477 | parentheses to force it into a subshell, which may be stopped as | |
10478 | a unit. | |
10479 | .PP | |
ccc6cda3 | 10480 | Array variables may not (yet) be exported. |
09767ff0 CR |
10481 | .PP |
10482 | There may be only one active coprocess at a time. | |
726f6388 | 10483 | .zZ |
bb70624e | 10484 | .zY |