]>
Commit | Line | Data |
---|---|---|
0628567a | 1 | .\" |
726f6388 JA |
2 | .\" MAN PAGE COMMENTS to |
3 | .\" | |
4 | .\" Chet Ramey | |
726f6388 | 5 | .\" Case Western Reserve University |
ac50fbac | 6 | .\" chet.ramey@case.edu |
726f6388 | 7 | .\" |
a0c0a00f | 8 | .\" Last Change: Fri Aug 26 09:45:10 EDT 2016 |
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 |
a0c0a00f | 13 | .TH BASH 1 "2016 August 26" "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] | |
ac50fbac | 51 | [command_string | file] |
726f6388 | 52 | .SH COPYRIGHT |
a0c0a00f CR |
53 | .if n Bash is Copyright (C) 1989-2016 by the Free Software Foundation, Inc. |
54 | .if t Bash is Copyright \(co 1989-2016 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 | |
0628567a JA |
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). | |
95732b49 JA |
67 | .B Bash |
68 | can be configured to be POSIX-conformant by default. | |
726f6388 | 69 | .SH OPTIONS |
a0c0a00f | 70 | All of the single-character shell options documented in the |
495aee44 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 | |
ac50fbac | 78 | .B \-c |
ccc6cda3 | 79 | If the |
726f6388 | 80 | .B \-c |
ac50fbac 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 |
ac50fbac | 84 | .IR command_string , |
a0c0a00f 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 | |
95732b49 | 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 |
b80f6443 JA |
163 | .B \-\-debugger |
164 | Arrange for the debugger profile to be executed before the shell | |
95732b49 JA |
165 | starts. |
166 | Turns on extended debugging mode (see the description of the | |
b80f6443 JA |
167 | .B extdebug |
168 | option to the | |
169 | .B shopt | |
b80f6443 JA |
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 | |
0628567a | 228 | from the POSIX standard to match the standard (\fIposix mode\fP). |
ac50fbac 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 |
a0c0a00f | 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 |
a0c0a00f | 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 \- , | |
a0c0a00f | 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 |
a0c0a00f | 280 | (unless \fB\-s\fP is specified) |
bb70624e JA |
281 | and without the |
282 | .B \-c | |
283 | option | |
b80f6443 | 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. | |
ac50fbac | 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 | |
a0c0a00f CR |
327 | When an interactive login shell exits, |
328 | or a non-interactive login shell executes the \fBexit\fP builtin command, | |
ccc6cda3 JA |
329 | .B bash |
330 | reads and executes commands from the file \fI~/.bash_logout\fP, if it | |
331 | exists. | |
332 | .PP | |
333 | When an interactive shell that is not a login shell is started, | |
334 | .B bash | |
335 | reads and executes commands from \fI~/.bashrc\fP, if that file exists. | |
336 | This may be inhibited by using the | |
337 | .B \-\-norc | |
338 | option. | |
339 | The \fB\-\-rcfile\fP \fIfile\fP option will force | |
340 | .B bash | |
341 | to read and execute commands from \fIfile\fP instead of \fI~/.bashrc\fP. | |
342 | .PP | |
343 | When | |
344 | .B bash | |
345 | is started non-interactively, to run a shell script, for example, it | |
346 | looks for the variable | |
347 | .SM | |
348 | .B BASH_ENV | |
349 | in the environment, expands its value if it appears there, and uses the | |
350 | expanded value as the name of a file to read and execute. | |
351 | .B Bash | |
352 | behaves as if the following command were executed: | |
353 | .sp .5 | |
354 | .RS | |
28ef6c31 JA |
355 | .if t \f(CWif [ \-n "$BASH_ENV" ]; then . "$BASH_ENV"; fi\fP |
356 | .if n if [ \-n "$BASH_ENV" ]; then . "$BASH_ENV"; fi | |
ccc6cda3 JA |
357 | .RE |
358 | .sp .5 | |
359 | but the value of the | |
360 | .SM | |
361 | .B PATH | |
ac50fbac | 362 | variable is not used to search for the filename. |
ccc6cda3 JA |
363 | .PP |
364 | If | |
365 | .B bash | |
366 | is invoked with the name | |
367 | .BR sh , | |
368 | it tries to mimic the startup behavior of historical versions of | |
369 | .B sh | |
370 | as closely as possible, | |
371 | while conforming to the POSIX standard as well. | |
b72432fd JA |
372 | When invoked as an interactive login shell, or a non-interactive |
373 | shell with the \fB\-\-login\fP option, it first attempts to | |
cce855bc | 374 | read and execute commands from |
ccc6cda3 JA |
375 | .I /etc/profile |
376 | and | |
377 | .IR ~/.profile , | |
378 | in that order. | |
379 | The | |
380 | .B \-\-noprofile | |
381 | option may be used to inhibit this behavior. | |
382 | When invoked as an interactive shell with the name | |
383 | .BR sh , | |
384 | .B bash | |
385 | looks for the variable | |
386 | .SM | |
387 | .BR ENV , | |
388 | expands its value if it is defined, and uses the | |
389 | expanded value as the name of a file to read and execute. | |
390 | Since a shell invoked as | |
391 | .B sh | |
392 | does not attempt to read and execute commands from any other startup | |
393 | files, the | |
394 | .B \-\-rcfile | |
395 | option has no effect. | |
396 | A non-interactive shell invoked with the name | |
397 | .B sh | |
b72432fd | 398 | does not attempt to read any other startup files. |
ccc6cda3 JA |
399 | When invoked as |
400 | .BR sh , | |
401 | .B bash | |
402 | enters | |
403 | .I posix | |
404 | mode after the startup files are read. | |
405 | .PP | |
406 | When | |
407 | .B bash | |
408 | is started in | |
409 | .I posix | |
410 | mode, as with the | |
411 | .B \-\-posix | |
412 | command line option, it follows the POSIX standard for startup files. | |
cce855bc | 413 | In this mode, interactive shells expand the |
ccc6cda3 JA |
414 | .SM |
415 | .B ENV | |
cce855bc | 416 | variable and commands are read and executed from the file |
ccc6cda3 JA |
417 | whose name is the expanded value. |
418 | No other startup files are read. | |
ccc6cda3 JA |
419 | .PP |
420 | .B Bash | |
3185942a | 421 | attempts to determine when it is being run with its standard input |
495aee44 | 422 | connected to a network connection, as when executed by the remote shell |
3185942a | 423 | daemon, usually \fIrshd\fP, or the secure shell daemon \fIsshd\fP. |
ccc6cda3 JA |
424 | If |
425 | .B bash | |
3185942a | 426 | determines it is being run in this fashion, it reads and executes |
ccc6cda3 JA |
427 | commands from \fI~/.bashrc\fP, if that file exists and is readable. |
428 | It will not do this if invoked as \fBsh\fP. | |
429 | The | |
430 | .B \-\-norc | |
431 | option may be used to inhibit this behavior, and the | |
432 | .B \-\-rcfile | |
ac50fbac CR |
433 | option may be used to force another file to be read, but neither |
434 | \fIrshd\fP nor \fIsshd\fP generally invoke the shell with those options | |
ccc6cda3 | 435 | or allow them to be specified. |
b72432fd JA |
436 | .PP |
437 | If the shell is started with the effective user (group) id not equal to the | |
438 | real user (group) id, and the \fB\-p\fP option is not supplied, no startup | |
f73dda09 JA |
439 | files are read, shell functions are not inherited from the environment, the |
440 | .SM | |
0001803f CR |
441 | .BR SHELLOPTS , |
442 | .SM | |
443 | .BR BASHOPTS , | |
444 | .SM | |
445 | .BR CDPATH , | |
446 | and | |
447 | .SM | |
448 | .B GLOBIGNORE | |
449 | variables, if they appear in the environment, are ignored, | |
b72432fd JA |
450 | and the effective user id is set to the real user id. |
451 | If the \fB\-p\fP option is supplied at invocation, the startup behavior is | |
452 | the same, but the effective user id is not reset. | |
726f6388 | 453 | .SH DEFINITIONS |
ccc6cda3 JA |
454 | .PP |
455 | The following definitions are used throughout the rest of this | |
456 | document. | |
726f6388 JA |
457 | .PD 0 |
458 | .TP | |
a0c0a00f | 459 | .B blank |
726f6388 JA |
460 | A space or tab. |
461 | .TP | |
462 | .B word | |
463 | A sequence of characters considered as a single unit by the shell. | |
464 | Also known as a | |
465 | .BR token . | |
466 | .TP | |
467 | .B name | |
a0c0a00f | 468 | A |
726f6388 JA |
469 | .I word |
470 | consisting only of alphanumeric characters and underscores, and | |
471 | beginning with an alphabetic character or an underscore. Also | |
472 | referred to as an | |
473 | .BR identifier . | |
474 | .TP | |
475 | .B metacharacter | |
476 | A character that, when unquoted, separates words. One of the following: | |
477 | .br | |
478 | .RS | |
479 | .PP | |
a0c0a00f CR |
480 | .if t \fB| & ; ( ) < > space tab newline\fP |
481 | .if n \fB| & ; ( ) < > space tab newline\fP | |
726f6388 JA |
482 | .RE |
483 | .PP | |
484 | .TP | |
485 | .B control operator | |
486 | A \fItoken\fP that performs a control function. It is one of the following | |
487 | symbols: | |
488 | .RS | |
489 | .PP | |
a0c0a00f CR |
490 | .if t \fB|| & && ; ;; ;& ;;& ( ) | |& <newline>\fP |
491 | .if n \fB|| & && ; ;; ;& ;;& ( ) | |& <newline>\fP | |
726f6388 JA |
492 | .RE |
493 | .PD | |
494 | .SH "RESERVED WORDS" | |
495 | \fIReserved words\fP are words that have a special meaning to the shell. | |
496 | The following words are recognized as reserved when unquoted and either | |
497 | the first word of a simple command (see | |
498 | .SM | |
499 | .B SHELL GRAMMAR | |
a0c0a00f CR |
500 | below) or the third word of a |
501 | .B case | |
726f6388 JA |
502 | or |
503 | .B for | |
504 | command: | |
505 | .if t .RS | |
506 | .PP | |
507 | .B | |
ac50fbac CR |
508 | .if n ! case coproc do done elif else esac fi for function if in select then until while { } time [[ ]] |
509 | .if t ! case coproc do done elif else esac fi for function if in select then until while { } time [[ ]] | |
726f6388 | 510 | .if t .RE |
726f6388 JA |
511 | .SH "SHELL GRAMMAR" |
512 | .SS Simple Commands | |
513 | .PP | |
514 | A \fIsimple command\fP is a sequence of optional variable assignments | |
ccc6cda3 | 515 | followed by \fBblank\fP-separated words and redirections, and |
726f6388 | 516 | terminated by a \fIcontrol operator\fP. The first word |
f73dda09 JA |
517 | specifies the command to be executed, and is passed as argument zero. |
518 | The remaining words are passed as arguments to the invoked command. | |
726f6388 JA |
519 | .PP |
520 | The return value of a \fIsimple command\fP is its exit status, or | |
521 | 128+\fIn\^\fP if the command is terminated by signal | |
522 | .IR n . | |
523 | .SS Pipelines | |
524 | .PP | |
525 | A \fIpipeline\fP is a sequence of one or more commands separated by | |
3185942a JA |
526 | one of the control operators |
527 | .B | | |
528 | or \fB|&\fP. | |
726f6388 JA |
529 | The format for a pipeline is: |
530 | .RS | |
531 | .PP | |
3185942a | 532 | [\fBtime\fP [\fB\-p\fP]] [ ! ] \fIcommand\fP [ [\fB|\fP\(bv\fB|&\fP] \fIcommand2\fP ... ] |
726f6388 JA |
533 | .RE |
534 | .PP | |
535 | The standard output of | |
536 | .I command | |
f73dda09 | 537 | is connected via a pipe to the standard input of |
726f6388 JA |
538 | .IR command2 . |
539 | This connection is performed before any redirections specified by the | |
540 | command (see | |
541 | .SM | |
542 | .B REDIRECTION | |
543 | below). | |
ac50fbac CR |
544 | If \fB|&\fP is used, \fIcommand\fP's standard error, in addition to its |
545 | standard output, is connected to | |
546 | \fIcommand2\fP's standard input through the pipe; | |
547 | it is shorthand for \fB2>&1 |\fP. | |
548 | This implicit redirection of the standard error to the standard output is | |
549 | performed after any redirections specified by the command. | |
726f6388 | 550 | .PP |
b80f6443 JA |
551 | The return status of a pipeline is the exit status of the last |
552 | command, unless the \fBpipefail\fP option is enabled. | |
553 | If \fBpipefail\fP is enabled, the pipeline's return status is the | |
554 | value of the last (rightmost) command to exit with a non-zero status, | |
555 | or zero if all commands exit successfully. | |
726f6388 JA |
556 | If the reserved word |
557 | .B ! | |
b80f6443 JA |
558 | precedes a pipeline, the exit status of that pipeline is the logical |
559 | negation of the exit status as described above. | |
ccc6cda3 | 560 | The shell waits for all commands in the pipeline to |
726f6388 JA |
561 | terminate before returning a value. |
562 | .PP | |
ccc6cda3 JA |
563 | If the |
564 | .B time | |
565 | reserved word precedes a pipeline, the elapsed as well as user and | |
566 | system time consumed by its execution are reported when the pipeline | |
567 | terminates. | |
568 | The \fB\-p\fP option changes the output format to that specified by POSIX. | |
495aee44 CR |
569 | When the shell is in \fIposix mode\fP, it does not recognize |
570 | \fBtime\fP as a reserved word if the next token begins with a `-'. | |
ccc6cda3 JA |
571 | The |
572 | .SM | |
573 | .B TIMEFORMAT | |
574 | variable may be set to a format string that specifies how the timing | |
575 | information should be displayed; see the description of | |
576 | .SM | |
577 | .B TIMEFORMAT | |
578 | under | |
579 | .B "Shell Variables" | |
580 | below. | |
581 | .PP | |
495aee44 CR |
582 | When the shell is in \fIposix mode\fP, \fBtime\fP |
583 | may be followed by a newline. In this case, the shell displays the | |
584 | total user and system time consumed by the shell and its children. | |
585 | The | |
586 | .SM | |
587 | .B TIMEFORMAT | |
588 | variable may be used to specify the format of | |
589 | the time information. | |
590 | .PP | |
726f6388 JA |
591 | Each command in a pipeline is executed as a separate process (i.e., in a |
592 | subshell). | |
593 | .SS Lists | |
594 | .PP | |
595 | A \fIlist\fP is a sequence of one or more pipelines separated by one | |
596 | of the operators | |
597 | .BR ; , | |
598 | .BR & , | |
599 | .BR && , | |
600 | or | |
495aee44 | 601 | .BR || , |
ccc6cda3 | 602 | and optionally terminated by one of |
726f6388 JA |
603 | .BR ; , |
604 | .BR & , | |
605 | or | |
606 | .BR <newline> . | |
607 | .PP | |
608 | Of these list operators, | |
609 | .B && | |
610 | and | |
495aee44 | 611 | .B || |
726f6388 JA |
612 | have equal precedence, followed by |
613 | .B ; | |
614 | and | |
3185942a | 615 | .BR & , |
726f6388 JA |
616 | which have equal precedence. |
617 | .PP | |
7117c2d2 JA |
618 | A sequence of one or more newlines may appear in a \fIlist\fP instead |
619 | of a semicolon to delimit commands. | |
620 | .PP | |
726f6388 JA |
621 | If a command is terminated by the control operator |
622 | .BR & , | |
623 | the shell executes the command in the \fIbackground\fP | |
624 | in a subshell. The shell does not wait for the command to | |
625 | finish, and the return status is 0. Commands separated by a | |
626 | .B ; | |
627 | are executed sequentially; the shell waits for each | |
628 | command to terminate in turn. The return status is the | |
629 | exit status of the last command executed. | |
630 | .PP | |
a0c0a00f | 631 | AND and OR lists are sequences of one or more pipelines separated by the |
495aee44 | 632 | \fB&&\fP and \fB||\fP control operators, respectively. |
3185942a | 633 | AND and OR lists are executed with left associativity. |
726f6388 JA |
634 | An AND list has the form |
635 | .RS | |
636 | .PP | |
bb70624e | 637 | \fIcommand1\fP \fB&&\fP \fIcommand2\fP |
726f6388 JA |
638 | .RE |
639 | .PP | |
640 | .I command2 | |
641 | is executed if, and only if, | |
bb70624e | 642 | .I command1 |
726f6388 JA |
643 | returns an exit status of zero. |
644 | .PP | |
645 | An OR list has the form | |
646 | .RS | |
647 | .PP | |
495aee44 | 648 | \fIcommand1\fP \fB||\fP \fIcommand2\fP |
726f6388 JA |
649 | .PP |
650 | .RE | |
651 | .PP | |
652 | .I command2 | |
653 | is executed if and only if | |
bb70624e | 654 | .I command1 |
3185942a JA |
655 | returns a non-zero exit status. |
656 | The return status of | |
726f6388 JA |
657 | AND and OR lists is the exit status of the last command |
658 | executed in the list. | |
659 | .SS Compound Commands | |
660 | .PP | |
ac50fbac CR |
661 | A \fIcompound command\fP is one of the following. |
662 | In most cases a \fIlist\fP in a command's description may be separated from | |
663 | the rest of the command by one or more newlines, and may be followed by a | |
664 | newline in place of a semicolon. | |
726f6388 JA |
665 | .TP |
666 | (\fIlist\fP) | |
b80f6443 JA |
667 | \fIlist\fP is executed in a subshell environment (see |
668 | .SM | |
669 | \fBCOMMAND EXECUTION ENVIRONMENT\fP | |
670 | below). | |
671 | Variable assignments and builtin | |
726f6388 JA |
672 | commands that affect the shell's environment do not remain in effect |
673 | after the command completes. The return status is the exit status of | |
674 | \fIlist\fP. | |
675 | .TP | |
676 | { \fIlist\fP; } | |
ccc6cda3 JA |
677 | \fIlist\fP is simply executed in the current shell environment. |
678 | \fIlist\fP must be terminated with a newline or semicolon. | |
679 | This is known as a \fIgroup command\fP. | |
680 | The return status is the exit status of | |
726f6388 | 681 | \fIlist\fP. |
b80f6443 | 682 | Note that unlike the metacharacters \fB(\fP and \fB)\fP, \fB{\fP and |
f73dda09 JA |
683 | \fB}\fP are \fIreserved words\fP and must occur where a reserved |
684 | word is permitted to be recognized. Since they do not cause a word | |
3185942a JA |
685 | break, they must be separated from \fIlist\fP by whitespace or another |
686 | shell metacharacter. | |
726f6388 | 687 | .TP |
ccc6cda3 JA |
688 | ((\fIexpression\fP)) |
689 | The \fIexpression\fP is evaluated according to the rules described | |
690 | below under | |
691 | .SM | |
692 | .BR "ARITHMETIC EVALUATION" . | |
693 | If the value of the expression is non-zero, the return status is 0; | |
694 | otherwise the return status is 1. This is exactly equivalent to | |
695 | \fBlet "\fIexpression\fP"\fR. | |
696 | .TP | |
cce855bc JA |
697 | \fB[[\fP \fIexpression\fP \fB]]\fP |
698 | Return a status of 0 or 1 depending on the evaluation of | |
699 | the conditional expression \fIexpression\fP. | |
700 | Expressions are composed of the primaries described below under | |
701 | .SM | |
702 | .BR "CONDITIONAL EXPRESSIONS" . | |
703 | Word splitting and pathname expansion are not performed on the words | |
ac50fbac CR |
704 | between the \fB[[\fP and \fB]]\fP; tilde expansion, |
705 | parameter and variable expansion, | |
706 | arithmetic expansion, command substitution, process | |
cce855bc | 707 | substitution, and quote removal are performed. |
b80f6443 JA |
708 | Conditional operators such as \fB\-f\fP must be unquoted to be recognized |
709 | as primaries. | |
cce855bc JA |
710 | .if t .sp 0.5 |
711 | .if n .sp 1 | |
495aee44 | 712 | When used with \fB[[\fP, the \fB<\fP and \fB>\fP operators sort |
0001803f CR |
713 | lexicographically using the current locale. |
714 | .if t .sp 0.5 | |
715 | .if n .sp 1 | |
cce855bc JA |
716 | When the \fB==\fP and \fB!=\fP operators are used, the string to the |
717 | right of the operator is considered a pattern and matched according | |
ac50fbac CR |
718 | to the rules described below under \fBPattern Matching\fP, |
719 | as if the \fBextglob\fP shell option were enabled. | |
720 | The \fB=\fP operator is equivalent to \fB==\fP. | |
a0c0a00f | 721 | If the |
95732b49 | 722 | .B nocasematch |
a0c0a00f | 723 | shell option is enabled, the match is performed without regard to the case |
95732b49 | 724 | of alphabetic characters. |
0628567a JA |
725 | The return value is 0 if the string matches (\fB==\fP) or does not match |
726 | (\fB!=\fP) the pattern, and 1 otherwise. | |
ac50fbac CR |
727 | Any part of the pattern may be quoted to force the quoted portion |
728 | to be matched as a string. | |
cce855bc JA |
729 | .if t .sp 0.5 |
730 | .if n .sp 1 | |
b80f6443 JA |
731 | An additional binary operator, \fB=~\fP, is available, with the same |
732 | precedence as \fB==\fP and \fB!=\fP. | |
733 | When it is used, the string to the right of the operator is considered | |
a0c0a00f | 734 | an extended regular expression and matched accordingly (as in \fIregex\fP(3)). |
b80f6443 JA |
735 | The return value is 0 if the string matches |
736 | the pattern, and 1 otherwise. | |
737 | If the regular expression is syntactically incorrect, the conditional | |
738 | expression's return value is 2. | |
a0c0a00f | 739 | If the |
95732b49 | 740 | .B nocasematch |
a0c0a00f | 741 | shell option is enabled, the match is performed without regard to the case |
b80f6443 | 742 | of alphabetic characters. |
ac50fbac CR |
743 | Any part of the pattern may be quoted to force the quoted portion |
744 | to be matched as a string. | |
745 | Bracket expressions in regular expressions must be treated carefully, | |
746 | since normal quoting characters lose their meanings between brackets. | |
747 | If the pattern is stored in a shell variable, quoting the variable | |
748 | expansion forces the entire pattern to be matched as a string. | |
b80f6443 | 749 | Substrings matched by parenthesized subexpressions within the regular |
0001803f CR |
750 | expression are saved in the array variable |
751 | .SM | |
752 | .BR BASH_REMATCH . | |
753 | The element of | |
754 | .SM | |
755 | .B BASH_REMATCH | |
756 | with index 0 is the portion of the string | |
b80f6443 | 757 | matching the entire regular expression. |
0001803f CR |
758 | The element of |
759 | .SM | |
760 | .B BASH_REMATCH | |
761 | with index \fIn\fP is the portion of the | |
b80f6443 JA |
762 | string matching the \fIn\fPth parenthesized subexpression. |
763 | .if t .sp 0.5 | |
764 | .if n .sp 1 | |
cce855bc JA |
765 | Expressions may be combined using the following operators, listed |
766 | in decreasing order of precedence: | |
767 | .if t .sp 0.5 | |
768 | .if n .sp 1 | |
769 | .RS | |
770 | .PD 0 | |
771 | .TP | |
772 | .B ( \fIexpression\fP ) | |
773 | Returns the value of \fIexpression\fP. | |
774 | This may be used to override the normal precedence of operators. | |
775 | .TP | |
776 | .B ! \fIexpression\fP | |
777 | True if | |
778 | .I expression | |
779 | is false. | |
780 | .TP | |
781 | \fIexpression1\fP \fB&&\fP \fIexpression2\fP | |
782 | True if both | |
783 | .I expression1 | |
784 | and | |
785 | .I expression2 | |
786 | are true. | |
787 | .TP | |
495aee44 | 788 | \fIexpression1\fP \fB||\fP \fIexpression2\fP |
cce855bc JA |
789 | True if either |
790 | .I expression1 | |
791 | or | |
792 | .I expression2 | |
793 | is true. | |
794 | .PD | |
cce855bc | 795 | .LP |
495aee44 | 796 | The \fB&&\fP and \fB||\fP |
7117c2d2 | 797 | operators do not evaluate \fIexpression2\fP if the value of |
cce855bc JA |
798 | \fIexpression1\fP is sufficient to determine the return value of |
799 | the entire conditional expression. | |
f73dda09 | 800 | .RE |
cce855bc | 801 | .TP |
0001803f | 802 | \fBfor\fP \fIname\fP [ [ \fBin\fP [ \fIword ...\fP ] ] ; ] \fBdo\fP \fIlist\fP ; \fBdone\fP |
726f6388 | 803 | The list of words following \fBin\fP is expanded, generating a list |
bb70624e JA |
804 | of items. |
805 | The variable \fIname\fP is set to each element of this list | |
806 | in turn, and \fIlist\fP is executed each time. | |
807 | If the \fBin\fP \fIword\fP is omitted, the \fBfor\fP command executes | |
808 | \fIlist\fP once for each positional parameter that is set (see | |
726f6388 JA |
809 | .SM |
810 | .B PARAMETERS | |
811 | below). | |
cce855bc JA |
812 | The return status is the exit status of the last command that executes. |
813 | If the expansion of the items following \fBin\fP results in an empty | |
814 | list, no commands are executed, and the return status is 0. | |
726f6388 | 815 | .TP |
bb70624e JA |
816 | \fBfor\fP (( \fIexpr1\fP ; \fIexpr2\fP ; \fIexpr3\fP )) ; \fBdo\fP \fIlist\fP ; \fBdone\fP |
817 | First, the arithmetic expression \fIexpr1\fP is evaluated according | |
818 | to the rules described below under | |
819 | .SM | |
820 | .BR "ARITHMETIC EVALUATION" . | |
821 | The arithmetic expression \fIexpr2\fP is then evaluated repeatedly | |
822 | until it evaluates to zero. | |
823 | Each time \fIexpr2\fP evaluates to a non-zero value, \fIlist\fP is | |
824 | executed and the arithmetic expression \fIexpr3\fP is evaluated. | |
825 | If any expression is omitted, it behaves as if it evaluates to 1. | |
826 | The return value is the exit status of the last command in \fIlist\fP | |
827 | that is executed, or false if any of the expressions is invalid. | |
828 | .TP | |
b72432fd | 829 | \fBselect\fP \fIname\fP [ \fBin\fP \fIword\fP ] ; \fBdo\fP \fIlist\fP ; \fBdone\fP |
726f6388 JA |
830 | The list of words following \fBin\fP is expanded, generating a list |
831 | of items. The set of expanded words is printed on the standard | |
832 | error, each preceded by a number. If the \fBin\fP | |
833 | \fIword\fP is omitted, the positional parameters are printed (see | |
834 | .SM | |
835 | .B PARAMETERS | |
836 | below). The | |
0001803f | 837 | .SM |
726f6388 JA |
838 | .B PS3 |
839 | prompt is then displayed and a line read from the standard input. | |
ccc6cda3 | 840 | If the line consists of a number corresponding to one of |
726f6388 JA |
841 | the displayed words, then the value of |
842 | .I name | |
843 | is set to that word. If the line is empty, the words and prompt | |
844 | are displayed again. If EOF is read, the command completes. Any | |
845 | other value read causes | |
846 | .I name | |
847 | to be set to null. The line read is saved in the variable | |
0001803f | 848 | .SM |
726f6388 JA |
849 | .BR REPLY . |
850 | The | |
851 | .I list | |
852 | is executed after each selection until a | |
853 | .B break | |
726f6388 JA |
854 | command is executed. |
855 | The exit status of | |
856 | .B select | |
857 | is the exit status of the last command executed in | |
858 | .IR list , | |
859 | or zero if no commands were executed. | |
860 | .TP | |
bb70624e | 861 | \fBcase\fP \fIword\fP \fBin\fP [ [(] \fIpattern\fP [ \fB|\fP \fIpattern\fP ] \ |
726f6388 JA |
862 | ... ) \fIlist\fP ;; ] ... \fBesac\fP |
863 | A \fBcase\fP command first expands \fIword\fP, and tries to match | |
864 | it against each \fIpattern\fP in turn, using the same matching rules | |
865 | as for pathname expansion (see | |
866 | .B Pathname Expansion | |
95732b49 | 867 | below). |
0628567a | 868 | The \fIword\fP is expanded using tilde |
a0c0a00f | 869 | expansion, parameter and variable expansion, arithmetic expansion, |
0628567a JA |
870 | command substitution, process substitution and quote removal. |
871 | Each \fIpattern\fP examined is expanded using tilde | |
a0c0a00f | 872 | expansion, parameter and variable expansion, arithmetic expansion, |
0628567a | 873 | command substitution, and process substitution. |
a0c0a00f | 874 | If the |
95732b49 | 875 | .B nocasematch |
a0c0a00f | 876 | shell option is enabled, the match is performed without regard to the case |
95732b49 | 877 | of alphabetic characters. |
3185942a JA |
878 | When a match is found, the corresponding \fIlist\fP is executed. |
879 | If the \fB;;\fP operator is used, no subsequent matches are attempted after | |
880 | the first pattern match. | |
881 | Using \fB;&\fP in place of \fB;;\fP causes execution to continue with | |
882 | the \fIlist\fP associated with the next set of patterns. | |
883 | Using \fB;;&\fP in place of \fB;;\fP causes the shell to test the next | |
884 | pattern list in the statement, if any, and execute any associated \fIlist\fP | |
885 | on a successful match. | |
886 | The exit status is zero if no | |
ccc6cda3 | 887 | pattern matches. Otherwise, it is the exit status of the |
726f6388 JA |
888 | last command executed in \fIlist\fP. |
889 | .TP | |
ac50fbac | 890 | \fBif\fP \fIlist\fP; \fBthen\fP \fIlist\fP; \ |
ccc6cda3 JA |
891 | [ \fBelif\fP \fIlist\fP; \fBthen\fP \fIlist\fP; ] ... \ |
892 | [ \fBelse\fP \fIlist\fP; ] \fBfi\fP | |
726f6388 | 893 | The |
a0c0a00f | 894 | .B if |
726f6388 JA |
895 | .I list |
896 | is executed. If its exit status is zero, the | |
897 | \fBthen\fP \fIlist\fP is executed. Otherwise, each \fBelif\fP | |
898 | \fIlist\fP is executed in turn, and if its exit status is zero, | |
899 | the corresponding \fBthen\fP \fIlist\fP is executed and the | |
900 | command completes. Otherwise, the \fBelse\fP \fIlist\fP is | |
901 | executed, if present. The exit status is the exit status of the | |
902 | last command executed, or zero if no condition tested true. | |
903 | .TP | |
495aee44 | 904 | \fBwhile\fP \fIlist-1\fP; \fBdo\fP \fIlist-2\fP; \fBdone\fP |
7117c2d2 | 905 | .PD 0 |
726f6388 | 906 | .TP |
495aee44 | 907 | \fBuntil\fP \fIlist-1\fP; \fBdo\fP \fIlist-2\fP; \fBdone\fP |
726f6388 | 908 | .PD |
495aee44 CR |
909 | The \fBwhile\fP command continuously executes the list |
910 | \fIlist-2\fP as long as the last command in the list \fIlist-1\fP returns | |
726f6388 | 911 | an exit status of zero. The \fBuntil\fP command is identical |
a0c0a00f | 912 | to the \fBwhile\fP command, except that the test is negated: |
495aee44 | 913 | .I list-2 |
726f6388 | 914 | is executed as long as the last command in |
495aee44 | 915 | .I list-1 |
ccc6cda3 | 916 | returns a non-zero exit status. |
726f6388 JA |
917 | The exit status of the \fBwhile\fP and \fBuntil\fP commands |
918 | is the exit status | |
495aee44 | 919 | of the last command executed in \fIlist-2\fP, or zero if |
726f6388 | 920 | none was executed. |
3185942a JA |
921 | .SS Coprocesses |
922 | .PP | |
923 | A \fIcoprocess\fP is a shell command preceded by the \fBcoproc\fP reserved | |
924 | word. | |
925 | A coprocess is executed asynchronously in a subshell, as if the command | |
926 | had been terminated with the \fB&\fP control operator, with a two-way pipe | |
927 | established between the executing shell and the coprocess. | |
928 | .PP | |
929 | The format for a coprocess is: | |
930 | .RS | |
931 | .PP | |
932 | \fBcoproc\fP [\fINAME\fP] \fIcommand\fP [\fIredirections\fP] | |
933 | .RE | |
934 | .PP | |
935 | This creates a coprocess named \fINAME\fP. | |
ac50fbac | 936 | If \fINAME\fP is not supplied, the default name is \fBCOPROC\fP. |
17345e5a JA |
937 | \fINAME\fP must not be supplied if \fIcommand\fP is a \fIsimple |
938 | command\fP (see above); otherwise, it is interpreted as the first word | |
939 | of the simple command. | |
ac50fbac | 940 | When the coprocess is executed, the shell creates an array variable (see |
3185942a JA |
941 | .B Arrays |
942 | below) named \fINAME\fP in the context of the executing shell. | |
943 | The standard output of | |
944 | .I command | |
945 | is connected via a pipe to a file descriptor in the executing shell, | |
946 | and that file descriptor is assigned to \fINAME\fP[0]. | |
947 | The standard input of | |
948 | .I command | |
949 | is connected via a pipe to a file descriptor in the executing shell, | |
950 | and that file descriptor is assigned to \fINAME\fP[1]. | |
951 | This pipe is established before any redirections specified by the | |
952 | command (see | |
953 | .SM | |
954 | .B REDIRECTION | |
955 | below). | |
956 | The file descriptors can be utilized as arguments to shell commands | |
957 | and redirections using standard word expansions. | |
ac50fbac | 958 | The file descriptors are not available in subshells. |
495aee44 | 959 | The process ID of the shell spawned to execute the coprocess is |
3185942a JA |
960 | available as the value of the variable \fINAME\fP_PID. |
961 | The \fBwait\fP | |
962 | builtin command may be used to wait for the coprocess to terminate. | |
963 | .PP | |
ac50fbac CR |
964 | Since the coprocess is created as an asynchronous command, |
965 | the \fBcoproc\fP command always returns success. | |
3185942a | 966 | The return status of a coprocess is the exit status of \fIcommand\fP. |
b80f6443 JA |
967 | .SS Shell Function Definitions |
968 | .PP | |
969 | A shell function is an object that is called like a simple command and | |
970 | executes a compound command with a new set of positional parameters. | |
971 | Shell functions are declared as follows: | |
972 | .TP | |
495aee44 CR |
973 | \fIname\fP () \fIcompound\-command\fP [\fIredirection\fP] |
974 | .PD 0 | |
975 | .TP | |
976 | \fBfunction\fP \fIname\fP [()] \fIcompound\-command\fP [\fIredirection\fP] | |
977 | .PD | |
b80f6443 JA |
978 | This defines a function named \fIname\fP. |
979 | The reserved word \fBfunction\fP is optional. | |
980 | If the \fBfunction\fP reserved word is supplied, the parentheses are optional. | |
981 | The \fIbody\fP of the function is the compound command | |
a0c0a00f | 982 | .I compound\-command |
b80f6443 JA |
983 | (see \fBCompound Commands\fP above). |
984 | That command is usually a \fIlist\fP of commands between { and }, but | |
a0c0a00f CR |
985 | may be any command listed under \fBCompound Commands\fP above, |
986 | with one exception: If the \fBfunction\fP reserved word is used, but the | |
987 | parentheses are not supplied, the braces are required. | |
b80f6443 JA |
988 | \fIcompound\-command\fP is executed whenever \fIname\fP is specified as the |
989 | name of a simple command. | |
ac50fbac CR |
990 | When in \fIposix mode\fP, \fIname\fP may not be the name of one of the |
991 | POSIX \fIspecial builtins\fP. | |
b80f6443 JA |
992 | Any redirections (see |
993 | .SM | |
994 | .B REDIRECTION | |
995 | below) specified when a function is defined are performed | |
996 | when the function is executed. | |
997 | The exit status of a function definition is zero unless a syntax error | |
998 | occurs or a readonly function with the same name already exists. | |
999 | When executed, the exit status of a function is the exit status of the | |
1000 | last command executed in the body. (See | |
726f6388 JA |
1001 | .SM |
1002 | .B FUNCTIONS | |
1003 | below.) | |
1004 | .SH COMMENTS | |
ccc6cda3 JA |
1005 | In a non-interactive shell, or an interactive shell in which the |
1006 | .B interactive_comments | |
1007 | option to the | |
1008 | .B shopt | |
1009 | builtin is enabled (see | |
1010 | .SM | |
1011 | .B "SHELL BUILTIN COMMANDS" | |
1012 | below), a word beginning with | |
726f6388 JA |
1013 | .B # |
1014 | causes that word and all remaining characters on that line to | |
1015 | be ignored. An interactive shell without the | |
ccc6cda3 | 1016 | .B interactive_comments |
ccc6cda3 JA |
1017 | option enabled does not allow comments. The |
1018 | .B interactive_comments | |
1019 | option is on by default in interactive shells. | |
726f6388 JA |
1020 | .SH QUOTING |
1021 | \fIQuoting\fP is used to remove the special meaning of certain | |
a0c0a00f | 1022 | characters or words to the shell. Quoting can be used to |
726f6388 JA |
1023 | disable special treatment for special characters, to prevent |
1024 | reserved words from being recognized as such, and to prevent | |
1025 | parameter expansion. | |
1026 | .PP | |
1027 | Each of the \fImetacharacters\fP listed above under | |
1028 | .SM | |
1029 | .B DEFINITIONS | |
bb70624e JA |
1030 | has special meaning to the shell and must be quoted if it is to |
1031 | represent itself. | |
1032 | .PP | |
95732b49 JA |
1033 | When the command history expansion facilities are being used |
1034 | (see | |
1035 | .SM | |
1036 | .B HISTORY EXPANSION | |
1037 | below), the | |
bb70624e JA |
1038 | \fIhistory expansion\fP character, usually \fB!\fP, must be quoted |
1039 | to prevent history expansion. | |
1040 | .PP | |
1041 | There are three quoting mechanisms: the | |
726f6388 JA |
1042 | .IR "escape character" , |
1043 | single quotes, and double quotes. | |
1044 | .PP | |
1045 | A non-quoted backslash (\fB\e\fP) is the | |
1046 | .IR "escape character" . | |
1047 | It preserves the literal value of the next character that follows, | |
1048 | with the exception of <newline>. If a \fB\e\fP<newline> pair | |
cce855bc JA |
1049 | appears, and the backslash is not itself quoted, the \fB\e\fP<newline> |
1050 | is treated as a line continuation (that is, it is removed from the | |
1051 | input stream and effectively ignored). | |
726f6388 JA |
1052 | .PP |
1053 | Enclosing characters in single quotes preserves the literal value | |
1054 | of each character within the quotes. A single quote may not occur | |
1055 | between single quotes, even when preceded by a backslash. | |
1056 | .PP | |
1057 | Enclosing characters in double quotes preserves the literal value | |
1058 | of all characters within the quotes, with the exception of | |
1059 | .BR $ , | |
3185942a | 1060 | .BR \` , |
95732b49 JA |
1061 | .BR \e , |
1062 | and, when history expansion is enabled, | |
1063 | .BR ! . | |
a0c0a00f CR |
1064 | When the shell is in \fIposix mode\fP, the \fB!\fP has no special meaning |
1065 | within double quotes, even when history expansion is enabled. | |
726f6388 JA |
1066 | The characters |
1067 | .B $ | |
1068 | and | |
3185942a | 1069 | .B \` |
726f6388 JA |
1070 | retain their special meaning within double quotes. The backslash |
1071 | retains its special meaning only when followed by one of the following | |
1072 | characters: | |
1073 | .BR $ , | |
3185942a | 1074 | .BR \` , |
726f6388 JA |
1075 | \^\fB"\fP\^, |
1076 | .BR \e , | |
1077 | or | |
1078 | .BR <newline> . | |
1079 | A double quote may be quoted within double quotes by preceding it with | |
1080 | a backslash. | |
95732b49 JA |
1081 | If enabled, history expansion will be performed unless an |
1082 | .B ! | |
1083 | appearing in double quotes is escaped using a backslash. | |
1084 | The backslash preceding the | |
1085 | .B ! | |
1086 | is not removed. | |
726f6388 JA |
1087 | .PP |
1088 | The special parameters | |
1089 | .B * | |
1090 | and | |
1091 | .B @ | |
1092 | have special meaning when in double | |
1093 | quotes (see | |
1094 | .SM | |
1095 | .B PARAMETERS | |
1096 | below). | |
ccc6cda3 | 1097 | .PP |
0628567a | 1098 | Words of the form \fB$\fP\(aq\fIstring\fP\(aq are treated specially. The |
ccc6cda3 | 1099 | word expands to \fIstring\fP, with backslash-escaped characters replaced |
95732b49 | 1100 | as specified by the ANSI C standard. Backslash escape sequences, if |
ccc6cda3 JA |
1101 | present, are decoded as follows: |
1102 | .RS | |
1103 | .PD 0 | |
1104 | .TP | |
1105 | .B \ea | |
1106 | alert (bell) | |
1107 | .TP | |
1108 | .B \eb | |
1109 | backspace | |
1110 | .TP | |
1111 | .B \ee | |
0001803f CR |
1112 | .TP |
1113 | .B \eE | |
ccc6cda3 | 1114 | an escape character |
a0c0a00f | 1115 | .TP |
ccc6cda3 JA |
1116 | .B \ef |
1117 | form feed | |
a0c0a00f | 1118 | .TP |
ccc6cda3 JA |
1119 | .B \en |
1120 | new line | |
a0c0a00f | 1121 | .TP |
ccc6cda3 JA |
1122 | .B \er |
1123 | carriage return | |
1124 | .TP | |
1125 | .B \et | |
1126 | horizontal tab | |
a0c0a00f | 1127 | .TP |
ccc6cda3 JA |
1128 | .B \ev |
1129 | vertical tab | |
1130 | .TP | |
1131 | .B \e\e | |
1132 | backslash | |
bb70624e | 1133 | .TP |
0628567a | 1134 | .B \e\(aq |
bb70624e | 1135 | single quote |
0001803f CR |
1136 | .TP |
1137 | .B \e\(dq | |
1138 | double quote | |
a0c0a00f CR |
1139 | .TP |
1140 | .B \e? | |
1141 | question mark | |
1142 | .TP | |
ccc6cda3 | 1143 | .B \e\fInnn\fP |
f73dda09 | 1144 | the eight-bit character whose value is the octal value \fInnn\fP |
cce855bc JA |
1145 | (one to three digits) |
1146 | .TP | |
f73dda09 JA |
1147 | .B \ex\fIHH\fP |
1148 | the eight-bit character whose value is the hexadecimal value \fIHH\fP | |
1149 | (one or two hex digits) | |
7117c2d2 | 1150 | .TP |
495aee44 CR |
1151 | .B \eu\fIHHHH\fP |
1152 | the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value | |
1153 | \fIHHHH\fP (one to four hex digits) | |
1154 | .TP | |
1155 | .B \eU\fIHHHHHHHH\fP | |
1156 | the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value | |
1157 | \fIHHHHHHHH\fP (one to eight hex digits) | |
1158 | .TP | |
7117c2d2 JA |
1159 | .B \ec\fIx\fP |
1160 | a control-\fIx\fP character | |
ccc6cda3 JA |
1161 | .PD |
1162 | .RE | |
1163 | .LP | |
bb70624e | 1164 | The expanded result is single-quoted, as if the dollar sign had |
ccc6cda3 JA |
1165 | not been present. |
1166 | .PP | |
0001803f CR |
1167 | A double-quoted string preceded by a dollar sign (\fB$\fP\(dq\fIstring\fP\(dq) |
1168 | will cause the string to be translated according to the current locale. | |
ccc6cda3 JA |
1169 | If the current locale is \fBC\fP or \fBPOSIX\fP, the dollar sign |
1170 | is ignored. | |
1171 | If the string is translated and replaced, the replacement is | |
1172 | double-quoted. | |
726f6388 JA |
1173 | .SH PARAMETERS |
1174 | A | |
1175 | .I parameter | |
ccc6cda3 JA |
1176 | is an entity that stores values. |
1177 | It can be a | |
726f6388 JA |
1178 | .IR name , |
1179 | a number, or one of the special characters listed below under | |
1180 | .BR "Special Parameters" . | |
b80f6443 | 1181 | A |
726f6388 JA |
1182 | .I variable |
1183 | is a parameter denoted by a | |
1184 | .IR name . | |
f73dda09 JA |
1185 | A variable has a \fIvalue\fP and zero or more \fIattributes\fP. |
1186 | Attributes are assigned using the | |
1187 | .B declare | |
1188 | builtin command (see | |
1189 | .B declare | |
1190 | below in | |
1191 | .SM | |
1192 | .BR "SHELL BUILTIN COMMANDS" ). | |
726f6388 JA |
1193 | .PP |
1194 | A parameter is set if it has been assigned a value. The null string is | |
1195 | a valid value. Once a variable is set, it may be unset only by using | |
1196 | the | |
1197 | .B unset | |
1198 | builtin command (see | |
1199 | .SM | |
1200 | .B SHELL BUILTIN COMMANDS | |
1201 | below). | |
1202 | .PP | |
1203 | A | |
1204 | .I variable | |
1205 | may be assigned to by a statement of the form | |
1206 | .RS | |
1207 | .PP | |
1208 | \fIname\fP=[\fIvalue\fP] | |
1209 | .RE | |
1210 | .PP | |
1211 | If | |
1212 | .I value | |
1213 | is not given, the variable is assigned the null string. All | |
1214 | .I values | |
bb70624e JA |
1215 | undergo tilde expansion, parameter and variable expansion, |
1216 | command substitution, arithmetic expansion, and quote | |
ccc6cda3 JA |
1217 | removal (see |
1218 | .SM | |
1219 | .B EXPANSION | |
1220 | below). If the variable has its | |
cce855bc | 1221 | .B integer |
f73dda09 | 1222 | attribute set, then |
726f6388 | 1223 | .I value |
b80f6443 | 1224 | is evaluated as an arithmetic expression even if the $((...)) expansion is |
cce855bc | 1225 | not used (see |
ccc6cda3 JA |
1226 | .B "Arithmetic Expansion" |
1227 | below). | |
1228 | Word splitting is not performed, with the exception | |
726f6388 JA |
1229 | of \fB"$@"\fP as explained below under |
1230 | .BR "Special Parameters" . | |
1231 | Pathname expansion is not performed. | |
f73dda09 | 1232 | Assignment statements may also appear as arguments to the |
b80f6443 | 1233 | .BR alias , |
f73dda09 JA |
1234 | .BR declare , |
1235 | .BR typeset , | |
1236 | .BR export , | |
1237 | .BR readonly , | |
1238 | and | |
1239 | .B local | |
a0c0a00f | 1240 | builtin commands (\fIdeclaration\fP commands). |
ac50fbac CR |
1241 | When in \fIposix mode\fP, these builtins may appear in a command after |
1242 | one or more instances of the \fBcommand\fP builtin and retain these | |
1243 | assignment statement properties. | |
95732b49 JA |
1244 | .PP |
1245 | In the context where an assignment statement is assigning a value | |
1246 | to a shell variable or array index, the += operator can be used to | |
1247 | append to or add to the variable's previous value. | |
a0c0a00f CR |
1248 | This includes arguments to builtin commands such as \fBdeclare\fP that |
1249 | accept assignment statements (\fIdeclaration\fP commands). | |
495aee44 | 1250 | When += is applied to a variable for which the \fIinteger\fP attribute has been |
95732b49 JA |
1251 | set, \fIvalue\fP is evaluated as an arithmetic expression and added to the |
1252 | variable's current value, which is also evaluated. | |
1253 | When += is applied to an array variable using compound assignment (see | |
1254 | .B Arrays | |
1255 | below), the | |
1256 | variable's value is not unset (as it is when using =), and new values are | |
3185942a JA |
1257 | appended to the array beginning at one greater than the array's maximum index |
1258 | (for indexed arrays) or added as additional key\-value pairs in an | |
1259 | associative array. | |
95732b49 JA |
1260 | When applied to a string-valued variable, \fIvalue\fP is expanded and |
1261 | appended to the variable's value. | |
ac50fbac CR |
1262 | .PP |
1263 | A variable can be assigned the \fInameref\fP attribute using the | |
1264 | \fB\-n\fP option to the \fBdeclare\fP or \fBlocal\fP builtin commands | |
1265 | (see the descriptions of \fBdeclare\fP and \fBlocal\fP below) | |
1266 | to create a \fInameref\fP, or a reference to another variable. | |
1267 | This allows variables to be manipulated indirectly. | |
a0c0a00f CR |
1268 | Whenever the nameref variable is referenced, assigned to, unset, or has |
1269 | its attributes modified (other than using or changing the \fInameref\fP | |
1270 | attribute itself), the | |
1271 | operation is actually performed on the variable specified by the nameref | |
1272 | variable's value. | |
ac50fbac CR |
1273 | A nameref is commonly used within shell functions to refer to a variable |
1274 | whose name is passed as an argument to the function. | |
1275 | For instance, if a variable name is passed to a shell function as its first | |
1276 | argument, running | |
1277 | .sp .5 | |
1278 | .RS | |
1279 | .if t \f(CWdeclare -n ref=$1\fP | |
1280 | .if n declare -n ref=$1 | |
1281 | .RE | |
1282 | .sp .5 | |
1283 | inside the function creates a nameref variable \fBref\fP whose value is | |
1284 | the variable name passed as the first argument. | |
a0c0a00f CR |
1285 | References and assignments to \fBref\fP, and changes to its attributes, |
1286 | are treated as references, assignments, and attribute modifications | |
1287 | to the variable whose name was passed as \fB$1\fP. | |
ac50fbac CR |
1288 | If the control variable in a \fBfor\fP loop has the nameref attribute, |
1289 | the list of words can be a list of shell variables, and a name reference | |
1290 | will be established for each word in the list, in turn, when the loop is | |
1291 | executed. | |
a0c0a00f | 1292 | Array variables cannot be given the \fBnameref\fP attribute. |
ac50fbac CR |
1293 | However, nameref variables can reference array variables and subscripted |
1294 | array variables. | |
1295 | Namerefs can be unset using the \fB\-n\fP option to the \fBunset\fP builtin. | |
1296 | Otherwise, if \fBunset\fP is executed with the name of a nameref variable | |
1297 | as an argument, the variable referenced by the nameref variable will be unset. | |
726f6388 JA |
1298 | .SS Positional Parameters |
1299 | .PP | |
1300 | A | |
1301 | .I positional parameter | |
1302 | is a parameter denoted by one or more | |
1303 | digits, other than the single digit 0. Positional parameters are | |
1304 | assigned from the shell's arguments when it is invoked, | |
1305 | and may be reassigned using the | |
1306 | .B set | |
1307 | builtin command. Positional parameters may not be assigned to | |
1308 | with assignment statements. The positional parameters are | |
1309 | temporarily replaced when a shell function is executed (see | |
1310 | .SM | |
1311 | .B FUNCTIONS | |
1312 | below). | |
1313 | .PP | |
1314 | When a positional parameter consisting of more than a single | |
1315 | digit is expanded, it must be enclosed in braces (see | |
1316 | .SM | |
1317 | .B EXPANSION | |
1318 | below). | |
1319 | .SS Special Parameters | |
1320 | .PP | |
1321 | The shell treats several parameters specially. These parameters may | |
1322 | only be referenced; assignment to them is not allowed. | |
1323 | .PD 0 | |
1324 | .TP | |
1325 | .B * | |
ac50fbac CR |
1326 | Expands to the positional parameters, starting from one. |
1327 | When the expansion is not within double quotes, each positional parameter | |
1328 | expands to a separate word. | |
1329 | In contexts where it is performed, those words | |
1330 | are subject to further word splitting and pathname expansion. | |
1331 | When the expansion occurs within double quotes, it expands to a single word | |
a0c0a00f | 1332 | with the value of each parameter separated by the first character of the |
726f6388 JA |
1333 | .SM |
1334 | .B IFS | |
cce855bc JA |
1335 | special variable. That is, "\fB$*\fP" is equivalent |
1336 | to "\fB$1\fP\fIc\fP\fB$2\fP\fIc\fP\fB...\fP", where | |
726f6388 JA |
1337 | .I c |
1338 | is the first character of the value of the | |
1339 | .SM | |
1340 | .B IFS | |
1341 | variable. If | |
1342 | .SM | |
1343 | .B IFS | |
d166f048 JA |
1344 | is unset, the parameters are separated by spaces. |
1345 | If | |
1346 | .SM | |
1347 | .B IFS | |
1348 | is null, the parameters are joined without intervening separators. | |
726f6388 JA |
1349 | .TP |
1350 | .B @ | |
1351 | Expands to the positional parameters, starting from one. When the | |
cce855bc JA |
1352 | expansion occurs within double quotes, each parameter expands to a |
1353 | separate word. That is, "\fB$@\fP" is equivalent to | |
1354 | "\fB$1\fP" "\fB$2\fP" ... | |
95732b49 JA |
1355 | If the double-quoted expansion occurs within a word, the expansion of |
1356 | the first parameter is joined with the beginning part of the original | |
1357 | word, and the expansion of the last parameter is joined with the last | |
1358 | part of the original word. | |
a0c0a00f | 1359 | When there are no positional parameters, "\fB$@\fP" and |
726f6388 JA |
1360 | .B $@ |
1361 | expand to nothing (i.e., they are removed). | |
1362 | .TP | |
1363 | .B # | |
1364 | Expands to the number of positional parameters in decimal. | |
1365 | .TP | |
1366 | .B ? | |
3185942a | 1367 | Expands to the exit status of the most recently executed foreground |
726f6388 JA |
1368 | pipeline. |
1369 | .TP | |
1370 | .B \- | |
1371 | Expands to the current option flags as specified upon invocation, | |
1372 | by the | |
1373 | .B set | |
1374 | builtin command, or those set by the shell itself | |
1375 | (such as the | |
1376 | .B \-i | |
cce855bc | 1377 | option). |
726f6388 JA |
1378 | .TP |
1379 | .B $ | |
1380 | Expands to the process ID of the shell. In a () subshell, it | |
1381 | expands to the process ID of the current shell, not the | |
1382 | subshell. | |
1383 | .TP | |
1384 | .B ! | |
ac50fbac CR |
1385 | Expands to the process ID of the job most recently placed into the |
1386 | background, whether executed as an asynchronous command or using | |
1387 | the \fBbg\fP builtin (see | |
1388 | .SM | |
1389 | .B "JOB CONTROL" | |
1390 | below). | |
726f6388 JA |
1391 | .TP |
1392 | .B 0 | |
1393 | Expands to the name of the shell or shell script. This is set at | |
1394 | shell initialization. If | |
1395 | .B bash | |
1396 | is invoked with a file of commands, | |
1397 | .B $0 | |
1398 | is set to the name of that file. If | |
1399 | .B bash | |
1400 | is started with the | |
1401 | .B \-c | |
1402 | option, then | |
1403 | .B $0 | |
1404 | is set to the first argument after the string to be | |
1405 | executed, if one is present. Otherwise, it is set | |
ac50fbac | 1406 | to the filename used to invoke |
726f6388 JA |
1407 | .BR bash , |
1408 | as given by argument zero. | |
1409 | .TP | |
1410 | .B _ | |
95732b49 JA |
1411 | At shell startup, set to the absolute pathname used to invoke the |
1412 | shell or shell script being executed as passed in the environment | |
1413 | or argument list. | |
ccc6cda3 JA |
1414 | Subsequently, expands to the last argument to the previous command, |
1415 | after expansion. | |
95732b49 JA |
1416 | Also set to the full pathname used to invoke each command executed |
1417 | and placed in the environment exported to that command. | |
ccc6cda3 JA |
1418 | When checking mail, this parameter holds the name of the mail file |
1419 | currently being checked. | |
726f6388 JA |
1420 | .PD |
1421 | .SS Shell Variables | |
1422 | .PP | |
1423 | The following variables are set by the shell: | |
1424 | .PP | |
1425 | .PD 0 | |
1426 | .TP | |
726f6388 | 1427 | .B BASH |
ac50fbac | 1428 | Expands to the full filename used to invoke this instance of |
726f6388 JA |
1429 | .BR bash . |
1430 | .TP | |
0001803f CR |
1431 | .B BASHOPTS |
1432 | A colon-separated list of enabled shell options. Each word in | |
1433 | the list is a valid argument for the | |
1434 | .B \-s | |
1435 | option to the | |
1436 | .B shopt | |
1437 | builtin command (see | |
1438 | .SM | |
1439 | .B "SHELL BUILTIN COMMANDS" | |
1440 | below). The options appearing in | |
1441 | .SM | |
1442 | .B BASHOPTS | |
1443 | are those reported as | |
1444 | .I on | |
1445 | by \fBshopt\fP. | |
1446 | If this variable is in the environment when | |
1447 | .B bash | |
1448 | starts up, each shell option in the list will be enabled before | |
1449 | reading any startup files. | |
1450 | This variable is read-only. | |
1451 | .TP | |
3185942a | 1452 | .B BASHPID |
495aee44 | 1453 | Expands to the process ID of the current \fBbash\fP process. |
3185942a JA |
1454 | This differs from \fB$$\fP under certain circumstances, such as subshells |
1455 | that do not require \fBbash\fP to be re-initialized. | |
1456 | .TP | |
1457 | .B BASH_ALIASES | |
1458 | An associative array variable whose members correspond to the internal | |
495aee44 | 1459 | list of aliases as maintained by the \fBalias\fP builtin. |
a0c0a00f CR |
1460 | Elements added to this array appear in the alias list; however, |
1461 | unsetting array elements currently does not cause aliases to be removed | |
1462 | from the alias list. | |
1463 | If | |
1464 | .B BASH_ALIASES | |
1465 | is unset, it loses its special properties, even if it is | |
1466 | subsequently reset. | |
3185942a | 1467 | .TP |
b80f6443 JA |
1468 | .B BASH_ARGC |
1469 | An array variable whose values are the number of parameters in each | |
3185942a | 1470 | frame of the current \fBbash\fP execution call stack. |
95732b49 | 1471 | The number of |
b80f6443 | 1472 | parameters to the current subroutine (shell function or script executed |
95732b49 JA |
1473 | with \fB.\fP or \fBsource\fP) is at the top of the stack. |
1474 | When a subroutine is executed, the number of parameters passed is pushed onto | |
0001803f CR |
1475 | .SM |
1476 | .BR BASH_ARGC . | |
1477 | The shell sets | |
1478 | .SM | |
1479 | .B BASH_ARGC | |
1480 | only when in extended debugging mode (see the description of the | |
95732b49 JA |
1481 | .B extdebug |
1482 | option to the | |
1483 | .B shopt | |
1484 | builtin below) | |
b80f6443 JA |
1485 | .TP |
1486 | .B BASH_ARGV | |
3185942a | 1487 | An array variable containing all of the parameters in the current \fBbash\fP |
b80f6443 JA |
1488 | execution call stack. The final parameter of the last subroutine call |
1489 | is at the top of the stack; the first parameter of the initial call is | |
1490 | at the bottom. When a subroutine is executed, the parameters supplied | |
0001803f CR |
1491 | are pushed onto |
1492 | .SM | |
1493 | .BR BASH_ARGV . | |
1494 | The shell sets | |
1495 | .SM | |
1496 | .B BASH_ARGV | |
1497 | only when in extended debugging mode | |
95732b49 JA |
1498 | (see the description of the |
1499 | .B extdebug | |
1500 | option to the | |
1501 | .B shopt | |
1502 | builtin below) | |
b80f6443 | 1503 | .TP |
3185942a JA |
1504 | .B BASH_CMDS |
1505 | An associative array variable whose members correspond to the internal | |
1506 | hash table of commands as maintained by the \fBhash\fP builtin. | |
a0c0a00f CR |
1507 | Elements added to this array appear in the hash table; however, |
1508 | unsetting array elements currently does not cause command names to be removed | |
1509 | from the hash table. | |
1510 | If | |
1511 | .B BASH_CMDS | |
1512 | is unset, it loses its special properties, even if it is | |
1513 | subsequently reset. | |
3185942a | 1514 | .TP |
b80f6443 JA |
1515 | .B BASH_COMMAND |
1516 | The command currently being executed or about to be executed, unless the | |
1517 | shell is executing a command as the result of a trap, | |
1518 | in which case it is the command executing at the time of the trap. | |
1519 | .TP | |
1520 | .B BASH_EXECUTION_STRING | |
1521 | The command argument to the \fB\-c\fP invocation option. | |
1522 | .TP | |
1523 | .B BASH_LINENO | |
1524 | An array variable whose members are the line numbers in source files | |
495aee44 | 1525 | where each corresponding member of |
0001803f | 1526 | .SM |
495aee44 CR |
1527 | .B FUNCNAME |
1528 | was invoked. | |
b80f6443 | 1529 | \fB${BASH_LINENO[\fP\fI$i\fP\fB]}\fP is the line number in the source |
495aee44 CR |
1530 | file (\fB${BASH_SOURCE[\fP\fI$i+1\fP\fB]}\fP) where |
1531 | \fB${FUNCNAME[\fP\fI$i\fP\fB]}\fP was called | |
3185942a JA |
1532 | (or \fB${BASH_LINENO[\fP\fI$i-1\fP\fB]}\fP if referenced within another |
1533 | shell function). | |
0001803f CR |
1534 | Use |
1535 | .SM | |
1536 | .B LINENO | |
1537 | to obtain the current line number. | |
b80f6443 | 1538 | .TP |
a0c0a00f CR |
1539 | .B BASH_LOADABLES_PATH |
1540 | A colon-separated list of directories in which the shell looks for | |
1541 | dynamically loadable builtins specified by the | |
1542 | .B enable | |
1543 | command. | |
1544 | .TP | |
b80f6443 JA |
1545 | .B BASH_REMATCH |
1546 | An array variable whose members are assigned by the \fB=~\fP binary | |
1547 | operator to the \fB[[\fP conditional command. | |
1548 | The element with index 0 is the portion of the string | |
1549 | matching the entire regular expression. | |
1550 | The element with index \fIn\fP is the portion of the | |
1551 | string matching the \fIn\fPth parenthesized subexpression. | |
1552 | This variable is read-only. | |
1553 | .TP | |
1554 | .B BASH_SOURCE | |
495aee44 CR |
1555 | An array variable whose members are the source filenames |
1556 | where the corresponding shell function names in the | |
0001803f CR |
1557 | .SM |
1558 | .B FUNCNAME | |
495aee44 CR |
1559 | array variable are defined. |
1560 | The shell function | |
1561 | \fB${FUNCNAME[\fP\fI$i\fP\fB]}\fP is defined in the file | |
1562 | \fB${BASH_SOURCE[\fP\fI$i\fP\fB]}\fP and called from | |
1563 | \fB${BASH_SOURCE[\fP\fI$i+1\fP\fB]}\fP. | |
b80f6443 JA |
1564 | .TP |
1565 | .B BASH_SUBSHELL | |
ac50fbac CR |
1566 | Incremented by one within each subshell or subshell environment when |
1567 | the shell begins executing in that environment. | |
b80f6443 JA |
1568 | The initial value is 0. |
1569 | .TP | |
ccc6cda3 | 1570 | .B BASH_VERSINFO |
cce855bc JA |
1571 | A readonly array variable whose members hold version information for |
1572 | this instance of | |
ccc6cda3 JA |
1573 | .BR bash . |
1574 | The values assigned to the array members are as follows: | |
1575 | .sp .5 | |
1576 | .RS | |
ccc6cda3 JA |
1577 | .TP 24 |
1578 | .B BASH_VERSINFO[\fR0\fP] | |
1579 | The major version number (the \fIrelease\fP). | |
1580 | .TP | |
1581 | .B BASH_VERSINFO[\fR1\fP] | |
1582 | The minor version number (the \fIversion\fP). | |
1583 | .TP | |
1584 | .B BASH_VERSINFO[\fR2\fP] | |
1585 | The patch level. | |
1586 | .TP | |
1587 | .B BASH_VERSINFO[\fR3\fP] | |
1588 | The build version. | |
1589 | .TP | |
1590 | .B BASH_VERSINFO[\fR4\fP] | |
1591 | The release status (e.g., \fIbeta1\fP). | |
1592 | .TP | |
1593 | .B BASH_VERSINFO[\fR5\fP] | |
0001803f CR |
1594 | The value of |
1595 | .SM | |
1596 | .BR MACHTYPE . | |
ccc6cda3 JA |
1597 | .RE |
1598 | .TP | |
f73dda09 JA |
1599 | .B BASH_VERSION |
1600 | Expands to a string describing the version of this instance of | |
1601 | .BR bash . | |
726f6388 | 1602 | .TP |
f73dda09 JA |
1603 | .B COMP_CWORD |
1604 | An index into \fB${COMP_WORDS}\fP of the word containing the current | |
1605 | cursor position. | |
1606 | This variable is available only in shell functions invoked by the | |
1607 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1608 | below). | |
1609 | .TP | |
3185942a JA |
1610 | .B COMP_KEY |
1611 | The key (or final key of a key sequence) used to invoke the current | |
1612 | completion function. | |
1613 | .TP | |
f73dda09 JA |
1614 | .B COMP_LINE |
1615 | The current command line. | |
1616 | This variable is available only in shell functions and external | |
1617 | commands invoked by the | |
1618 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1619 | below). | |
1620 | .TP | |
1621 | .B COMP_POINT | |
1622 | The index of the current cursor position relative to the beginning of | |
1623 | the current command. | |
1624 | If the current cursor position is at the end of the current command, | |
1625 | the value of this variable is equal to \fB${#COMP_LINE}\fP. | |
1626 | This variable is available only in shell functions and external | |
1627 | commands invoked by the | |
1628 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1629 | below). | |
1630 | .TP | |
3185942a JA |
1631 | .B COMP_TYPE |
1632 | Set to an integer value corresponding to the type of completion attempted | |
1633 | that caused a completion function to be called: | |
1634 | \fITAB\fP, for normal completion, | |
1635 | \fI?\fP, for listing completions after successive tabs, | |
1636 | \fI!\fP, for listing alternatives on partial word completion, | |
1637 | \fI@\fP, to list completions if the word is not unmodified, | |
1638 | or | |
1639 | \fI%\fP, for menu completion. | |
1640 | This variable is available only in shell functions and external | |
1641 | commands invoked by the | |
1642 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1643 | below). | |
1644 | .TP | |
b80f6443 | 1645 | .B COMP_WORDBREAKS |
17345e5a | 1646 | The set of characters that the \fBreadline\fP library treats as word |
b80f6443 JA |
1647 | separators when performing word completion. |
1648 | If | |
1649 | .SM | |
1650 | .B COMP_WORDBREAKS | |
1651 | is unset, it loses its special properties, even if it is | |
1652 | subsequently reset. | |
1653 | .TP | |
f73dda09 JA |
1654 | .B COMP_WORDS |
1655 | An array variable (see \fBArrays\fP below) consisting of the individual | |
1656 | words in the current command line. | |
17345e5a | 1657 | The line is split into words as \fBreadline\fP would split it, using |
0001803f CR |
1658 | .SM |
1659 | .B COMP_WORDBREAKS | |
1660 | as described above. | |
f73dda09 JA |
1661 | This variable is available only in shell functions invoked by the |
1662 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1663 | below). | |
1664 | .TP | |
495aee44 CR |
1665 | .B COPROC |
1666 | An array variable (see \fBArrays\fP below) created to hold the file descriptors | |
1667 | for output from and input to an unnamed coprocess (see \fBCoprocesses\fP | |
1668 | above). | |
1669 | .TP | |
f73dda09 JA |
1670 | .B DIRSTACK |
1671 | An array variable (see | |
1672 | .B Arrays | |
1673 | below) containing the current contents of the directory stack. | |
1674 | Directories appear in the stack in the order they are displayed by the | |
1675 | .B dirs | |
1676 | builtin. | |
1677 | Assigning to members of this array variable may be used to modify | |
1678 | directories already in the stack, but the | |
1679 | .B pushd | |
1680 | and | |
1681 | .B popd | |
1682 | builtins must be used to add and remove directories. | |
1683 | Assignment to this variable will not change the current directory. | |
726f6388 JA |
1684 | If |
1685 | .SM | |
f73dda09 | 1686 | .B DIRSTACK |
726f6388 JA |
1687 | is unset, it loses its special properties, even if it is |
1688 | subsequently reset. | |
1689 | .TP | |
f73dda09 JA |
1690 | .B EUID |
1691 | Expands to the effective user ID of the current user, initialized at | |
1692 | shell startup. This variable is readonly. | |
1693 | .TP | |
1694 | .B FUNCNAME | |
b80f6443 JA |
1695 | An array variable containing the names of all shell functions |
1696 | currently in the execution call stack. | |
1697 | The element with index 0 is the name of any currently-executing | |
1698 | shell function. | |
495aee44 | 1699 | The bottom-most element (the one with the highest index) is |
3185942a JA |
1700 | .if t \f(CW"main"\fP. |
1701 | .if n "main". | |
f73dda09 JA |
1702 | This variable exists only when a shell function is executing. |
1703 | Assignments to | |
726f6388 | 1704 | .SM |
f73dda09 | 1705 | .B FUNCNAME |
a0c0a00f | 1706 | have no effect. |
726f6388 JA |
1707 | If |
1708 | .SM | |
f73dda09 | 1709 | .B FUNCNAME |
726f6388 JA |
1710 | is unset, it loses its special properties, even if it is |
1711 | subsequently reset. | |
495aee44 CR |
1712 | .if t .sp 0.5 |
1713 | .if n .sp 1 | |
1714 | This variable can be used with \fBBASH_LINENO\fP and \fBBASH_SOURCE\fP. | |
1715 | Each element of \fBFUNCNAME\fP has corresponding elements in | |
1716 | \fBBASH_LINENO\fP and \fBBASH_SOURCE\fP to describe the call stack. | |
1717 | For instance, \fB${FUNCNAME[\fP\fI$i\fP\fB]}\fP was called from the file | |
1718 | \fB${BASH_SOURCE[\fP\fI$i+1\fP\fB]}\fP at line number | |
1719 | \fB${BASH_LINENO[\fP\fI$i\fP\fB]}\fP. | |
1720 | The \fBcaller\fP builtin displays the current call stack using this | |
1721 | information. | |
726f6388 | 1722 | .TP |
f73dda09 JA |
1723 | .B GROUPS |
1724 | An array variable containing the list of groups of which the current | |
1725 | user is a member. | |
a0c0a00f | 1726 | Assignments to |
f73dda09 JA |
1727 | .SM |
1728 | .B GROUPS | |
a0c0a00f | 1729 | have no effect. |
726f6388 JA |
1730 | If |
1731 | .SM | |
f73dda09 | 1732 | .B GROUPS |
726f6388 JA |
1733 | is unset, it loses its special properties, even if it is |
1734 | subsequently reset. | |
1735 | .TP | |
1736 | .B HISTCMD | |
1737 | The history number, or index in the history list, of the current | |
ccc6cda3 JA |
1738 | command. |
1739 | If | |
726f6388 JA |
1740 | .SM |
1741 | .B HISTCMD | |
1742 | is unset, it loses its special properties, even if it is | |
1743 | subsequently reset. | |
1744 | .TP | |
f73dda09 JA |
1745 | .B HOSTNAME |
1746 | Automatically set to the name of the current host. | |
bb70624e | 1747 | .TP |
f73dda09 JA |
1748 | .B HOSTTYPE |
1749 | Automatically set to a string that uniquely | |
1750 | describes the type of machine on which | |
1751 | .B bash | |
1752 | is executing. | |
1753 | The default is system-dependent. | |
1754 | .TP | |
1755 | .B LINENO | |
1756 | Each time this parameter is referenced, the shell substitutes | |
1757 | a decimal number representing the current sequential line number | |
1758 | (starting with 1) within a script or function. When not in a | |
1759 | script or function, the value substituted is not guaranteed to | |
1760 | be meaningful. | |
ccc6cda3 JA |
1761 | If |
1762 | .SM | |
f73dda09 | 1763 | .B LINENO |
ccc6cda3 JA |
1764 | is unset, it loses its special properties, even if it is |
1765 | subsequently reset. | |
1766 | .TP | |
f73dda09 JA |
1767 | .B MACHTYPE |
1768 | Automatically set to a string that fully describes the system | |
1769 | type on which | |
1770 | .B bash | |
1771 | is executing, in the standard GNU \fIcpu-company-system\fP format. | |
1772 | The default is system-dependent. | |
1773 | .TP | |
495aee44 CR |
1774 | .B MAPFILE |
1775 | An array variable (see \fBArrays\fP below) created to hold the text | |
1776 | read by the \fBmapfile\fP builtin when no variable name is supplied. | |
1777 | .TP | |
f73dda09 JA |
1778 | .B OLDPWD |
1779 | The previous working directory as set by the | |
1780 | .B cd | |
1781 | command. | |
ccc6cda3 | 1782 | .TP |
726f6388 JA |
1783 | .B OPTARG |
1784 | The value of the last option argument processed by the | |
1785 | .B getopts | |
1786 | builtin command (see | |
1787 | .SM | |
1788 | .B SHELL BUILTIN COMMANDS | |
1789 | below). | |
1790 | .TP | |
1791 | .B OPTIND | |
1792 | The index of the next argument to be processed by the | |
1793 | .B getopts | |
1794 | builtin command (see | |
1795 | .SM | |
1796 | .B SHELL BUILTIN COMMANDS | |
1797 | below). | |
1798 | .TP | |
726f6388 JA |
1799 | .B OSTYPE |
1800 | Automatically set to a string that | |
1801 | describes the operating system on which | |
1802 | .B bash | |
ccc6cda3 JA |
1803 | is executing. |
1804 | The default is system-dependent. | |
1805 | .TP | |
f73dda09 JA |
1806 | .B PIPESTATUS |
1807 | An array variable (see | |
1808 | .B Arrays | |
1809 | below) containing a list of exit status values from the processes | |
1810 | in the most-recently-executed foreground pipeline (which may | |
1811 | contain only a single command). | |
ccc6cda3 | 1812 | .TP |
f73dda09 JA |
1813 | .B PPID |
1814 | The process ID of the shell's parent. This variable is readonly. | |
1815 | .TP | |
1816 | .B PWD | |
1817 | The current working directory as set by the | |
1818 | .B cd | |
1819 | command. | |
1820 | .TP | |
1821 | .B RANDOM | |
1822 | Each time this parameter is referenced, a random integer between | |
1823 | 0 and 32767 is | |
1824 | generated. The sequence of random numbers may be initialized by assigning | |
1825 | a value to | |
1826 | .SM | |
1827 | .BR RANDOM . | |
1828 | If | |
1829 | .SM | |
1830 | .B RANDOM | |
1831 | is unset, it loses its special properties, even if it is | |
1832 | subsequently reset. | |
1833 | .TP | |
495aee44 CR |
1834 | .B READLINE_LINE |
1835 | The contents of the | |
1836 | .B readline | |
1837 | line buffer, for use with | |
1838 | .if t \f(CWbind -x\fP | |
1839 | .if n "bind -x" | |
1840 | (see | |
1841 | .SM | |
1842 | .B "SHELL BUILTIN COMMANDS" | |
1843 | below). | |
1844 | .TP | |
1845 | .B READLINE_POINT | |
1846 | The position of the insertion point in the | |
1847 | .B readline | |
1848 | line buffer, for use with | |
1849 | .if t \f(CWbind -x\fP | |
1850 | .if n "bind -x" | |
1851 | (see | |
1852 | .SM | |
1853 | .B "SHELL BUILTIN COMMANDS" | |
1854 | below). | |
1855 | .TP | |
f73dda09 JA |
1856 | .B REPLY |
1857 | Set to the line of input read by the | |
1858 | .B read | |
1859 | builtin command when no arguments are supplied. | |
1860 | .TP | |
1861 | .B SECONDS | |
1862 | Each time this parameter is | |
1863 | referenced, the number of seconds since shell invocation is returned. If a | |
a0c0a00f | 1864 | value is assigned to |
f73dda09 JA |
1865 | .SM |
1866 | .BR SECONDS , | |
1867 | the value returned upon subsequent | |
1868 | references is | |
1869 | the number of seconds since the assignment plus the value assigned. | |
1870 | If | |
1871 | .SM | |
1872 | .B SECONDS | |
1873 | is unset, it loses its special properties, even if it is | |
1874 | subsequently reset. | |
1875 | .TP | |
1876 | .B SHELLOPTS | |
1877 | A colon-separated list of enabled shell options. Each word in | |
1878 | the list is a valid argument for the | |
1879 | .B \-o | |
1880 | option to the | |
1881 | .B set | |
1882 | builtin command (see | |
1883 | .SM | |
1884 | .B "SHELL BUILTIN COMMANDS" | |
1885 | below). The options appearing in | |
ccc6cda3 JA |
1886 | .SM |
1887 | .B SHELLOPTS | |
1888 | are those reported as | |
1889 | .I on | |
1890 | by \fBset \-o\fP. | |
1891 | If this variable is in the environment when | |
1892 | .B bash | |
1893 | starts up, each shell option in the list will be enabled before | |
1894 | reading any startup files. | |
1895 | This variable is read-only. | |
bb70624e | 1896 | .TP |
f73dda09 JA |
1897 | .B SHLVL |
1898 | Incremented by one each time an instance of | |
1899 | .B bash | |
1900 | is started. | |
bb70624e | 1901 | .TP |
f73dda09 JA |
1902 | .B UID |
1903 | Expands to the user ID of the current user, initialized at shell startup. | |
1904 | This variable is readonly. | |
726f6388 JA |
1905 | .PD |
1906 | .PP | |
1907 | The following variables are used by the shell. In some cases, | |
1908 | .B bash | |
1909 | assigns a default value to a variable; these cases are noted | |
1910 | below. | |
1911 | .PP | |
1912 | .PD 0 | |
1913 | .TP | |
ac50fbac CR |
1914 | .B BASH_COMPAT |
1915 | The value is used to set the shell's compatibility level. | |
1916 | See the description of the \fBshopt\fP builtin below under | |
1917 | \fBSHELL BUILTIN COMMANDS\fP | |
1918 | for a description of the various compatibility | |
1919 | levels and their effects. | |
1920 | The value may be a decimal number (e.g., 4.2) or an integer (e.g., 42) | |
1921 | corresponding to the desired compatibility level. | |
1922 | If \fBBASH_COMPAT\fP is unset or set to the empty string, the compatibility | |
1923 | level is set to the default for the current version. | |
1924 | If \fBBASH_COMPAT\fP is set to a value that is not one of the valid | |
1925 | compatibility levels, the shell prints an error message and sets the | |
1926 | compatibility level to the default for the current version. | |
1927 | The valid compatibility levels correspond to the compatibility options | |
1928 | accepted by the \fBshopt\fP builtin described below (for example, | |
1929 | \fBcompat42\fP means that 4.2 and 42 are valid values). | |
1930 | The current version is also a valid value. | |
1931 | .TP | |
d166f048 | 1932 | .B BASH_ENV |
726f6388 JA |
1933 | If this parameter is set when \fBbash\fP is executing a shell script, |
1934 | its value is interpreted as a filename containing commands to | |
1935 | initialize the shell, as in | |
cce855bc | 1936 | .IR ~/.bashrc . |
726f6388 JA |
1937 | The value of |
1938 | .SM | |
d166f048 | 1939 | .B BASH_ENV |
726f6388 | 1940 | is subjected to parameter expansion, command substitution, and arithmetic |
ac50fbac | 1941 | expansion before being interpreted as a filename. |
726f6388 JA |
1942 | .SM |
1943 | .B PATH | |
ac50fbac | 1944 | is not used to search for the resultant filename. |
726f6388 | 1945 | .TP |
0001803f CR |
1946 | .B BASH_XTRACEFD |
1947 | If set to an integer corresponding to a valid file descriptor, \fBbash\fP | |
1948 | will write the trace output generated when | |
1949 | .if t \f(CWset -x\fP | |
1950 | .if n \fIset -x\fP | |
1951 | is enabled to that file descriptor. | |
1952 | The file descriptor is closed when | |
1953 | .SM | |
1954 | .B BASH_XTRACEFD | |
1955 | is unset or assigned a new value. | |
1956 | Unsetting | |
1957 | .SM | |
1958 | .B BASH_XTRACEFD | |
1959 | or assigning it the empty string causes the | |
1960 | trace output to be sent to the standard error. | |
1961 | Note that setting | |
1962 | .SM | |
1963 | .B BASH_XTRACEFD | |
1964 | to 2 (the standard error file | |
1965 | descriptor) and then unsetting it will result in the standard error | |
1966 | being closed. | |
1967 | .TP | |
495aee44 CR |
1968 | .B CDPATH |
1969 | The search path for the | |
1970 | .B cd | |
1971 | command. | |
1972 | This is a colon-separated list of directories in which the shell looks | |
1973 | for destination directories specified by the | |
1974 | .B cd | |
1975 | command. | |
1976 | A sample value is | |
1977 | .if t \f(CW".:~:/usr"\fP. | |
1978 | .if n ".:~:/usr". | |
1979 | .TP | |
ac50fbac CR |
1980 | .B CHILD_MAX |
1981 | Set the number of exited child status values for the shell to remember. | |
1982 | Bash will not allow this value to be decreased below a POSIX-mandated | |
1983 | minimum, and there is a maximum value (currently 8192) that this may | |
1984 | not exceed. | |
1985 | The minimum value is system-dependent. | |
1986 | .TP | |
f73dda09 | 1987 | .B COLUMNS |
495aee44 | 1988 | Used by the \fBselect\fP compound command to determine the terminal width |
ac50fbac CR |
1989 | when printing selection lists. |
1990 | Automatically set if the | |
1991 | .B checkwinsize | |
1992 | option is enabled or in an interactive shell upon receipt of a | |
495aee44 CR |
1993 | .SM |
1994 | .BR SIGWINCH . | |
726f6388 | 1995 | .TP |
f73dda09 JA |
1996 | .B COMPREPLY |
1997 | An array variable from which \fBbash\fP reads the possible completions | |
1998 | generated by a shell function invoked by the programmable completion | |
1999 | facility (see \fBProgrammable Completion\fP below). | |
ac50fbac | 2000 | Each array element contains one possible completion. |
726f6388 | 2001 | .TP |
b80f6443 JA |
2002 | .B EMACS |
2003 | If \fBbash\fP finds this variable in the environment when the shell starts | |
2004 | with value | |
2005 | .if t \f(CWt\fP, | |
2006 | .if n "t", | |
495aee44 | 2007 | it assumes that the shell is running in an Emacs shell buffer and disables |
b80f6443 JA |
2008 | line editing. |
2009 | .TP | |
495aee44 CR |
2010 | .B ENV |
2011 | Similar to | |
2012 | .SM | |
2013 | .BR BASH_ENV ; | |
2014 | used when the shell is invoked in POSIX mode. | |
2015 | .TP | |
a0c0a00f CR |
2016 | .B EXECIGNORE |
2017 | A colon-separated list of shell patterns (see \fBPattern Matching\fP) | |
2018 | defining the list of filenames to be ignored by command search using | |
2019 | \fBPATH\fP. | |
2020 | Files whose full pathnames match one of these patterns are not considered | |
2021 | executable files for the purposes of completion and command execution | |
2022 | via \fBPATH\fP lookup. | |
2023 | This does not affect the behavior of the \fB[\fP, \fBtest\fP, and \fB[[\fP | |
2024 | commands. | |
2025 | Full pathnames in the command hash table are not subject to \fBEXECIGNORE\fP. | |
2026 | Use this variable to ignore shared library files that have the executable | |
2027 | bit set, but are not executable files. | |
2028 | The pattern matching honors the setting of the \fBextglob\fP shell | |
2029 | option. | |
2030 | .TP | |
f73dda09 JA |
2031 | .B FCEDIT |
2032 | The default editor for the | |
2033 | .B fc | |
2034 | builtin command. | |
726f6388 | 2035 | .TP |
f73dda09 JA |
2036 | .B FIGNORE |
2037 | A colon-separated list of suffixes to ignore when performing | |
2038 | filename completion (see | |
726f6388 | 2039 | .SM |
f73dda09 JA |
2040 | .B READLINE |
2041 | below). | |
2042 | A filename whose suffix matches one of the entries in | |
726f6388 | 2043 | .SM |
f73dda09 JA |
2044 | .B FIGNORE |
2045 | is excluded from the list of matched filenames. | |
7117c2d2 JA |
2046 | A sample value is |
2047 | .if t \f(CW".o:~"\fP. | |
2048 | .if n ".o:~". | |
ccc6cda3 | 2049 | .TP |
495aee44 CR |
2050 | .B FUNCNEST |
2051 | If set to a numeric value greater than 0, defines a maximum function | |
2052 | nesting level. Function invocations that exceed this nesting level | |
2053 | will cause the current command to abort. | |
2054 | .TP | |
f73dda09 JA |
2055 | .B GLOBIGNORE |
2056 | A colon-separated list of patterns defining the set of filenames to | |
2057 | be ignored by pathname expansion. | |
2058 | If a filename matched by a pathname expansion pattern also matches one | |
2059 | of the patterns in | |
726f6388 | 2060 | .SM |
f73dda09 JA |
2061 | .BR GLOBIGNORE , |
2062 | it is removed from the list of matches. | |
2063 | .TP | |
2064 | .B HISTCONTROL | |
b80f6443 JA |
2065 | A colon-separated list of values controlling how commands are saved on |
2066 | the history list. | |
2067 | If the list of values includes | |
f73dda09 JA |
2068 | .IR ignorespace , |
2069 | lines which begin with a | |
2070 | .B space | |
b80f6443 | 2071 | character are not saved in the history list. |
a0c0a00f | 2072 | A value of |
b80f6443 JA |
2073 | .I ignoredups |
2074 | causes lines matching the previous history entry to not be saved. | |
f73dda09 JA |
2075 | A value of |
2076 | .I ignoreboth | |
b80f6443 JA |
2077 | is shorthand for \fIignorespace\fP and \fIignoredups\fP. |
2078 | A value of | |
2079 | .IR erasedups | |
2080 | causes all previous lines matching the current line to be removed from | |
2081 | the history list before that line is saved. | |
2082 | Any value not in the above list is ignored. | |
0001803f CR |
2083 | If |
2084 | .SM | |
2085 | .B HISTCONTROL | |
2086 | is unset, or does not include a valid value, | |
b80f6443 JA |
2087 | all lines read by the shell parser are saved on the history list, |
2088 | subject to the value of | |
0001803f | 2089 | .SM |
f73dda09 JA |
2090 | .BR HISTIGNORE . |
2091 | The second and subsequent lines of a multi-line compound command are | |
2092 | not tested, and are added to the history regardless of the value of | |
0001803f | 2093 | .SM |
f73dda09 | 2094 | .BR HISTCONTROL . |
726f6388 JA |
2095 | .TP |
2096 | .B HISTFILE | |
ccc6cda3 | 2097 | The name of the file in which command history is saved (see |
726f6388 JA |
2098 | .SM |
2099 | .B HISTORY | |
ccc6cda3 | 2100 | below). The default value is \fI~/.bash_history\fP. If unset, the |
ac50fbac | 2101 | command history is not saved when a shell exits. |
726f6388 JA |
2102 | .TP |
2103 | .B HISTFILESIZE | |
2104 | The maximum number of lines contained in the history file. When this | |
2105 | variable is assigned a value, the history file is truncated, if | |
ac50fbac CR |
2106 | necessary, |
2107 | to contain no more than that number of lines by removing the oldest entries. | |
2108 | The history file is also truncated to this size after | |
2109 | writing it when a shell exits. | |
2110 | If the value is 0, the history file is truncated to zero size. | |
2111 | Non-numeric values and numeric values less than zero inhibit truncation. | |
2112 | The shell sets the default value to the value of \fBHISTSIZE\fP | |
2113 | after reading any startup files. | |
726f6388 | 2114 | .TP |
f73dda09 JA |
2115 | .B HISTIGNORE |
2116 | A colon-separated list of patterns used to decide which command lines | |
2117 | should be saved on the history list. Each pattern is anchored at the | |
2118 | beginning of the line and must match the complete line (no implicit | |
2119 | `\fB*\fP' is appended). Each pattern is tested against the line | |
2120 | after the checks specified by | |
0001803f | 2121 | .SM |
f73dda09 JA |
2122 | .B HISTCONTROL |
2123 | are applied. | |
2124 | In addition to the normal shell pattern matching characters, `\fB&\fP' | |
2125 | matches the previous history line. `\fB&\fP' may be escaped using a | |
2126 | backslash; the backslash is removed before attempting a match. | |
2127 | The second and subsequent lines of a multi-line compound command are | |
2128 | not tested, and are added to the history regardless of the value of | |
0001803f | 2129 | .SM |
f73dda09 | 2130 | .BR HISTIGNORE . |
a0c0a00f CR |
2131 | The pattern matching honors the setting of the \fBextglob\fP shell |
2132 | option. | |
f73dda09 JA |
2133 | .TP |
2134 | .B HISTSIZE | |
2135 | The number of commands to remember in the command history (see | |
2136 | .SM | |
2137 | .B HISTORY | |
ac50fbac CR |
2138 | below). |
2139 | If the value is 0, commands are not saved in the history list. | |
2140 | Numeric values less than zero result in every command being saved | |
2141 | on the history list (there is no limit). | |
2142 | The shell sets the default value to 500 after reading any startup files. | |
f73dda09 | 2143 | .TP |
b80f6443 JA |
2144 | .B HISTTIMEFORMAT |
2145 | If this variable is set and not null, its value is used as a format string | |
2146 | for \fIstrftime\fP(3) to print the time stamp associated with each history | |
2147 | entry displayed by the \fBhistory\fP builtin. | |
2148 | If this variable is set, time stamps are written to the history file so | |
2149 | they may be preserved across shell sessions. | |
3185942a JA |
2150 | This uses the history comment character to distinguish timestamps from |
2151 | other history lines. | |
b80f6443 | 2152 | .TP |
f73dda09 JA |
2153 | .B HOME |
2154 | The home directory of the current user; the default argument for the | |
2155 | \fBcd\fP builtin command. | |
2156 | The value of this variable is also used when performing tilde expansion. | |
2157 | .TP | |
2158 | .B HOSTFILE | |
2159 | Contains the name of a file in the same format as | |
2160 | .FN /etc/hosts | |
2161 | that should be read when the shell needs to complete a | |
2162 | hostname. | |
2163 | The list of possible hostname completions may be changed while the | |
2164 | shell is running; | |
2165 | the next time hostname completion is attempted after the | |
2166 | value is changed, | |
726f6388 | 2167 | .B bash |
f73dda09 JA |
2168 | adds the contents of the new file to the existing list. |
2169 | If | |
726f6388 | 2170 | .SM |
f73dda09 | 2171 | .B HOSTFILE |
0001803f CR |
2172 | is set, but has no value, or does not name a readable file, |
2173 | \fBbash\fP attempts to read | |
f73dda09 JA |
2174 | .FN /etc/hosts |
2175 | to obtain the list of possible hostname completions. | |
2176 | When | |
726f6388 | 2177 | .SM |
f73dda09 JA |
2178 | .B HOSTFILE |
2179 | is unset, the hostname list is cleared. | |
2180 | .TP | |
2181 | .B IFS | |
2182 | The | |
2183 | .I Internal Field Separator | |
2184 | that is used | |
2185 | for word splitting after expansion and to | |
2186 | split lines into words with the | |
2187 | .B read | |
2188 | builtin command. The default value is | |
2189 | ``<space><tab><newline>''. | |
2190 | .TP | |
2191 | .B IGNOREEOF | |
2192 | Controls the | |
2193 | action of an interactive shell on receipt of an | |
2194 | .SM | |
2195 | .B EOF | |
2196 | character as the sole input. If set, the value is the number of | |
2197 | consecutive | |
2198 | .SM | |
2199 | .B EOF | |
2200 | characters which must be | |
2201 | typed as the first characters on an input line before | |
2202 | .B bash | |
2203 | exits. If the variable exists but does not have a numeric value, or | |
2204 | has no value, the default value is 10. If it does not exist, | |
2205 | .SM | |
2206 | .B EOF | |
2207 | signifies the end of input to the shell. | |
2208 | .TP | |
2209 | .B INPUTRC | |
2210 | The filename for the | |
2211 | .B readline | |
2212 | startup file, overriding the default of | |
2213 | .FN ~/.inputrc | |
2214 | (see | |
2215 | .SM | |
2216 | .B READLINE | |
2217 | below). | |
726f6388 | 2218 | .TP |
ccc6cda3 JA |
2219 | .B LANG |
2220 | Used to determine the locale category for any category not specifically | |
2221 | selected with a variable starting with \fBLC_\fP. | |
2222 | .TP | |
2223 | .B LC_ALL | |
0001803f CR |
2224 | This variable overrides the value of |
2225 | .SM | |
2226 | .B LANG | |
2227 | and any other | |
ccc6cda3 JA |
2228 | \fBLC_\fP variable specifying a locale category. |
2229 | .TP | |
2230 | .B LC_COLLATE | |
2231 | This variable determines the collation order used when sorting the | |
cce855bc JA |
2232 | results of pathname expansion, and determines the behavior of range |
2233 | expressions, equivalence classes, and collating sequences within | |
2234 | pathname expansion and pattern matching. | |
2235 | .TP | |
2236 | .B LC_CTYPE | |
2237 | This variable determines the interpretation of characters and the | |
2238 | behavior of character classes within pathname expansion and pattern | |
2239 | matching. | |
ccc6cda3 JA |
2240 | .TP |
2241 | .B LC_MESSAGES | |
2242 | This variable determines the locale used to translate double-quoted | |
2243 | strings preceded by a \fB$\fP. | |
2244 | .TP | |
bb70624e JA |
2245 | .B LC_NUMERIC |
2246 | This variable determines the locale category used for number formatting. | |
2247 | .TP | |
a0c0a00f CR |
2248 | .B LC_TIME |
2249 | This variable determines the locale category used for data and time | |
2250 | formatting. | |
2251 | .TP | |
28ef6c31 | 2252 | .B LINES |
495aee44 | 2253 | Used by the \fBselect\fP compound command to determine the column length |
ac50fbac CR |
2254 | for printing selection lists. |
2255 | Automatically set if the | |
2256 | .B checkwinsize | |
2257 | option is enabled or in an interactive shell upon receipt of a | |
0001803f CR |
2258 | .SM |
2259 | .BR SIGWINCH . | |
28ef6c31 | 2260 | .TP |
f73dda09 | 2261 | .B MAIL |
495aee44 | 2262 | If this parameter is set to a file or directory name and the |
726f6388 | 2263 | .SM |
f73dda09 JA |
2264 | .B MAILPATH |
2265 | variable is not set, | |
726f6388 | 2266 | .B bash |
495aee44 CR |
2267 | informs the user of the arrival of mail in the specified file or |
2268 | Maildir-format directory. | |
726f6388 | 2269 | .TP |
f73dda09 JA |
2270 | .B MAILCHECK |
2271 | Specifies how | |
2272 | often (in seconds) | |
2273 | .B bash | |
2274 | checks for mail. The default is 60 seconds. When it is time to check | |
2275 | for mail, the shell does so before displaying the primary prompt. | |
2276 | If this variable is unset, or set to a value that is not a number | |
2277 | greater than or equal to zero, the shell disables mail checking. | |
726f6388 | 2278 | .TP |
f73dda09 | 2279 | .B MAILPATH |
a0c0a00f | 2280 | A colon-separated list of filenames to be checked for mail. |
f73dda09 | 2281 | The message to be printed when mail arrives in a particular file |
ac50fbac | 2282 | may be specified by separating the filename from the message with a `?'. |
f73dda09 | 2283 | When used in the text of the message, \fB$_\fP expands to the name of |
a0c0a00f | 2284 | the current mailfile. |
f73dda09 JA |
2285 | Example: |
2286 | .RS | |
2287 | .PP | |
0628567a | 2288 | \fBMAILPATH\fP=\(aq/var/mail/bfox?"You have mail":~/shell\-mail?"$_ has mail!"\(aq |
f73dda09 JA |
2289 | .PP |
2290 | .B Bash | |
a0c0a00f CR |
2291 | can be configured to supply |
2292 | a default value for this variable (there is no value by default), | |
2293 | but the location of the user | |
f73dda09 JA |
2294 | mail files that it uses is system dependent (e.g., /var/mail/\fB$USER\fP). |
2295 | .RE | |
726f6388 | 2296 | .TP |
f73dda09 JA |
2297 | .B OPTERR |
2298 | If set to the value 1, | |
2299 | .B bash | |
2300 | displays error messages generated by the | |
2301 | .B getopts | |
2302 | builtin command (see | |
726f6388 | 2303 | .SM |
f73dda09 | 2304 | .B SHELL BUILTIN COMMANDS |
ccc6cda3 | 2305 | below). |
726f6388 | 2306 | .SM |
f73dda09 JA |
2307 | .B OPTERR |
2308 | is initialized to 1 each time the shell is invoked or a shell | |
2309 | script is executed. | |
ccc6cda3 | 2310 | .TP |
f73dda09 JA |
2311 | .B PATH |
2312 | The search path for commands. It | |
2313 | is a colon-separated list of directories in which | |
2314 | the shell looks for commands (see | |
ccc6cda3 | 2315 | .SM |
f73dda09 | 2316 | .B COMMAND EXECUTION |
b80f6443 | 2317 | below). |
0001803f CR |
2318 | A zero-length (null) directory name in the value of |
2319 | .SM | |
2320 | .B PATH | |
2321 | indicates the current directory. | |
b80f6443 JA |
2322 | A null directory name may appear as two adjacent colons, or as an initial |
2323 | or trailing colon. | |
2324 | The default path is system-dependent, | |
f73dda09 JA |
2325 | and is set by the administrator who installs |
2326 | .BR bash . | |
2327 | A common value is | |
a0c0a00f | 2328 | .na |
ac50fbac CR |
2329 | .if t \f(CW/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin\fP. |
2330 | .if n ``/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin''. | |
a0c0a00f | 2331 | .ad |
726f6388 | 2332 | .TP |
f73dda09 JA |
2333 | .B POSIXLY_CORRECT |
2334 | If this variable is in the environment when \fBbash\fP starts, the shell | |
2335 | enters \fIposix mode\fP before reading the startup files, as if the | |
2336 | .B \-\-posix | |
2337 | invocation option had been supplied. If it is set while the shell is | |
2338 | running, \fBbash\fP enables \fIposix mode\fP, as if the command | |
2339 | .if t \f(CWset -o posix\fP | |
2340 | .if n \fIset -o posix\fP | |
2341 | had been executed. | |
726f6388 | 2342 | .TP |
f73dda09 JA |
2343 | .B PROMPT_COMMAND |
2344 | If set, the value is executed as a command prior to issuing each primary | |
2345 | prompt. | |
ccc6cda3 | 2346 | .TP |
3185942a JA |
2347 | .B PROMPT_DIRTRIM |
2348 | If set to a number greater than zero, the value is used as the number of | |
0001803f | 2349 | trailing directory components to retain when expanding the \fB\ew\fP and |
3185942a JA |
2350 | \fB\eW\fP prompt string escapes (see |
2351 | .SM | |
2352 | .B PROMPTING | |
2353 | below). Characters removed are replaced with an ellipsis. | |
2354 | .TP | |
a0c0a00f CR |
2355 | .B PS0 |
2356 | The value of this parameter is expanded (see | |
2357 | .SM | |
2358 | .B PROMPTING | |
2359 | below) and displayed by interactive shells after reading a command | |
2360 | and before the command is executed. | |
2361 | .TP | |
f73dda09 JA |
2362 | .B PS1 |
2363 | The value of this parameter is expanded (see | |
2364 | .SM | |
2365 | .B PROMPTING | |
2366 | below) and used as the primary prompt string. The default value is | |
2367 | ``\fB\es\-\ev\e$ \fP''. | |
726f6388 | 2368 | .TP |
f73dda09 JA |
2369 | .B PS2 |
2370 | The value of this parameter is expanded as with | |
0001803f | 2371 | .SM |
f73dda09 JA |
2372 | .B PS1 |
2373 | and used as the secondary prompt string. The default is | |
2374 | ``\fB> \fP''. | |
2375 | .TP | |
2376 | .B PS3 | |
2377 | The value of this parameter is used as the prompt for the | |
2378 | .B select | |
2379 | command (see | |
726f6388 | 2380 | .SM |
f73dda09 JA |
2381 | .B SHELL GRAMMAR |
2382 | above). | |
726f6388 | 2383 | .TP |
f73dda09 JA |
2384 | .B PS4 |
2385 | The value of this parameter is expanded as with | |
0001803f | 2386 | .SM |
f73dda09 JA |
2387 | .B PS1 |
2388 | and the value is printed before each command | |
726f6388 | 2389 | .B bash |
f73dda09 | 2390 | displays during an execution trace. The first character of |
bb70624e | 2391 | .SM |
f73dda09 JA |
2392 | .B PS4 |
2393 | is replicated multiple times, as necessary, to indicate multiple | |
2394 | levels of indirection. The default is ``\fB+ \fP''. | |
2395 | .TP | |
b80f6443 JA |
2396 | .B SHELL |
2397 | The full pathname to the shell is kept in this environment variable. | |
2398 | If it is not set when the shell starts, | |
2399 | .B bash | |
2400 | assigns to it the full pathname of the current user's login shell. | |
2401 | .TP | |
f73dda09 JA |
2402 | .B TIMEFORMAT |
2403 | The value of this parameter is used as a format string specifying | |
2404 | how the timing information for pipelines prefixed with the | |
2405 | .B time | |
2406 | reserved word should be displayed. | |
2407 | The \fB%\fP character introduces an escape sequence that is | |
2408 | expanded to a time value or other information. | |
2409 | The escape sequences and their meanings are as follows; the | |
2410 | braces denote optional portions. | |
2411 | .sp .5 | |
2412 | .RS | |
2413 | .PD 0 | |
2414 | .TP 10 | |
2415 | .B %% | |
2416 | A literal \fB%\fP. | |
2417 | .TP | |
2418 | .B %[\fIp\fP][l]R | |
2419 | The elapsed time in seconds. | |
2420 | .TP | |
2421 | .B %[\fIp\fP][l]U | |
2422 | The number of CPU seconds spent in user mode. | |
2423 | .TP | |
2424 | .B %[\fIp\fP][l]S | |
2425 | The number of CPU seconds spent in system mode. | |
2426 | .TP | |
2427 | .B %P | |
2428 | The CPU percentage, computed as (%U + %S) / %R. | |
2429 | .PD | |
2430 | .RE | |
2431 | .IP | |
2432 | The optional \fIp\fP is a digit specifying the \fIprecision\fP, | |
2433 | the number of fractional digits after a decimal point. | |
2434 | A value of 0 causes no decimal point or fraction to be output. | |
2435 | At most three places after the decimal point may be specified; | |
2436 | values of \fIp\fP greater than 3 are changed to 3. | |
2437 | If \fIp\fP is not specified, the value 3 is used. | |
2438 | .IP | |
2439 | The optional \fBl\fP specifies a longer format, including | |
2440 | minutes, of the form \fIMM\fPm\fISS\fP.\fIFF\fPs. | |
2441 | The value of \fIp\fP determines whether or not the fraction is | |
2442 | included. | |
2443 | .IP | |
2444 | If this variable is not set, \fBbash\fP acts as if it had the | |
ac50fbac | 2445 | value \fB$\(aq\enreal\et%3lR\enuser\et%3lU\ensys\et%3lS\(aq\fP. |
f73dda09 JA |
2446 | If the value is null, no timing information is displayed. |
2447 | A trailing newline is added when the format string is displayed. | |
495aee44 | 2448 | .PD 0 |
f73dda09 JA |
2449 | .TP |
2450 | .B TMOUT | |
0001803f CR |
2451 | If set to a value greater than zero, |
2452 | .SM | |
2453 | .B TMOUT | |
2454 | is treated as the | |
7117c2d2 JA |
2455 | default timeout for the \fBread\fP builtin. |
2456 | The \fBselect\fP command terminates if input does not arrive | |
0001803f CR |
2457 | after |
2458 | .SM | |
2459 | .B TMOUT | |
2460 | seconds when input is coming from a terminal. | |
7117c2d2 | 2461 | In an interactive shell, the value is interpreted as the |
ac50fbac CR |
2462 | number of seconds to wait for a line of input after issuing the |
2463 | primary prompt. | |
f73dda09 | 2464 | .B Bash |
ac50fbac CR |
2465 | terminates after waiting for that number of seconds if a complete |
2466 | line of input does not arrive. | |
726f6388 | 2467 | .TP |
95732b49 | 2468 | .B TMPDIR |
495aee44 CR |
2469 | If set, \fBbash\fP uses its value as the name of a directory in which |
2470 | \fBbash\fP creates temporary files for the shell's use. | |
95732b49 | 2471 | .TP |
726f6388 JA |
2472 | .B auto_resume |
2473 | This variable controls how the shell interacts with the user and | |
2474 | job control. If this variable is set, single word simple | |
2475 | commands without redirections are treated as candidates for resumption | |
2476 | of an existing stopped job. There is no ambiguity allowed; if there is | |
2477 | more than one job beginning with the string typed, the job most recently | |
2478 | accessed is selected. The | |
2479 | .I name | |
2480 | of a stopped job, in this context, is the command line used to | |
2481 | start it. | |
2482 | If set to the value | |
2483 | .IR exact , | |
2484 | the string supplied must match the name of a stopped job exactly; | |
2485 | if set to | |
2486 | .IR substring , | |
2487 | the string supplied needs to match a substring of the name of a | |
2488 | stopped job. The | |
2489 | .I substring | |
2490 | value provides functionality analogous to the | |
2491 | .B %? | |
ccc6cda3 | 2492 | job identifier (see |
726f6388 JA |
2493 | .SM |
2494 | .B JOB CONTROL | |
2495 | below). If set to any other value, the supplied string must | |
2496 | be a prefix of a stopped job's name; this provides functionality | |
95732b49 | 2497 | analogous to the \fB%\fP\fIstring\fP job identifier. |
bb70624e | 2498 | .TP |
f73dda09 JA |
2499 | .B histchars |
2500 | The two or three characters which control history expansion | |
2501 | and tokenization (see | |
2502 | .SM | |
2503 | .B HISTORY EXPANSION | |
2504 | below). The first character is the \fIhistory expansion\fP character, | |
2505 | the character which signals the start of a history | |
2506 | expansion, normally `\fB!\fP'. | |
2507 | The second character is the \fIquick substitution\fP | |
2508 | character, which is used as shorthand for re-running the previous | |
2509 | command entered, substituting one string for another in the command. | |
2510 | The default is `\fB^\fP'. | |
2511 | The optional third character is the character | |
2512 | which indicates that the remainder of the line is a comment when found | |
2513 | as the first character of a word, normally `\fB#\fP'. The history | |
2514 | comment character causes history substitution to be skipped for the | |
2515 | remaining words on the line. It does not necessarily cause the shell | |
2516 | parser to treat the rest of the line as a comment. | |
726f6388 | 2517 | .PD |
ccc6cda3 JA |
2518 | .SS Arrays |
2519 | .B Bash | |
3185942a JA |
2520 | provides one-dimensional indexed and associative array variables. |
2521 | Any variable may be used as an indexed array; the | |
ccc6cda3 | 2522 | .B declare |
3185942a JA |
2523 | builtin will explicitly declare an array. |
2524 | There is no maximum | |
ccc6cda3 | 2525 | limit on the size of an array, nor any requirement that members |
3185942a JA |
2526 | be indexed or assigned contiguously. |
2527 | Indexed arrays are referenced using integers (including arithmetic | |
a0c0a00f | 2528 | expressions) and are zero-based; associative arrays are referenced |
3185942a | 2529 | using arbitrary strings. |
ac50fbac | 2530 | Unless otherwise noted, indexed array indices must be non-negative integers. |
ccc6cda3 | 2531 | .PP |
3185942a JA |
2532 | An indexed array is created automatically if any variable is assigned to |
2533 | using the syntax \fIname\fP[\fIsubscript\fP]=\fIvalue\fP. The | |
ccc6cda3 | 2534 | .I subscript |
495aee44 | 2535 | is treated as an arithmetic expression that must evaluate to a number. |
495aee44 | 2536 | To explicitly declare an indexed array, use |
ccc6cda3 JA |
2537 | .B declare \-a \fIname\fP |
2538 | (see | |
2539 | .SM | |
2540 | .B SHELL BUILTIN COMMANDS | |
2541 | below). | |
2542 | .B declare \-a \fIname\fP[\fIsubscript\fP] | |
3185942a JA |
2543 | is also accepted; the \fIsubscript\fP is ignored. |
2544 | .PP | |
2545 | Associative arrays are created using | |
2546 | .BR "declare \-A \fIname\fP" . | |
2547 | .PP | |
2548 | Attributes may be | |
ccc6cda3 JA |
2549 | specified for an array variable using the |
2550 | .B declare | |
2551 | and | |
2552 | .B readonly | |
2553 | builtins. Each attribute applies to all members of an array. | |
2554 | .PP | |
2555 | Arrays are assigned to using compound assignments of the form | |
2556 | \fIname\fP=\fB(\fPvalue\fI1\fP ... value\fIn\fP\fB)\fP, where each | |
3185942a | 2557 | \fIvalue\fP is of the form [\fIsubscript\fP]=\fIstring\fP. |
ac50fbac | 2558 | Indexed array assignments do not require anything but \fIstring\fP. |
3185942a JA |
2559 | When assigning to indexed arrays, if the optional brackets and subscript |
2560 | are supplied, that index is assigned to; | |
ccc6cda3 JA |
2561 | otherwise the index of the element assigned is the last index assigned |
2562 | to by the statement plus one. Indexing starts at zero. | |
3185942a JA |
2563 | .PP |
2564 | When assigning to an associative array, the subscript is required. | |
2565 | .PP | |
ccc6cda3 JA |
2566 | This syntax is also accepted by the |
2567 | .B declare | |
2568 | builtin. Individual array elements may be assigned to using the | |
2569 | \fIname\fP[\fIsubscript\fP]=\fIvalue\fP syntax introduced above. | |
ac50fbac CR |
2570 | When assigning to an indexed array, if |
2571 | .I name | |
2572 | is subscripted by a negative number, that number is | |
2573 | interpreted as relative to one greater than the maximum index of | |
2574 | \fIname\fP, so negative indices count back from the end of the | |
2575 | array, and an index of \-1 references the last element. | |
ccc6cda3 JA |
2576 | .PP |
2577 | Any element of an array may be referenced using | |
2578 | ${\fIname\fP[\fIsubscript\fP]}. The braces are required to avoid | |
2579 | conflicts with pathname expansion. If | |
2580 | \fIsubscript\fP is \fB@\fP or \fB*\fP, the word expands to | |
2581 | all members of \fIname\fP. These subscripts differ only when the | |
2582 | word appears within double quotes. If the word is double-quoted, | |
2583 | ${\fIname\fP[*]} expands to a single | |
2584 | word with the value of each array member separated by the first | |
2585 | character of the | |
2586 | .SM | |
2587 | .B IFS | |
2588 | special variable, and ${\fIname\fP[@]} expands each element of | |
2589 | \fIname\fP to a separate word. When there are no array members, | |
95732b49 JA |
2590 | ${\fIname\fP[@]} expands to nothing. |
2591 | If the double-quoted expansion occurs within a word, the expansion of | |
2592 | the first parameter is joined with the beginning part of the original | |
2593 | word, and the expansion of the last parameter is joined with the last | |
2594 | part of the original word. | |
2595 | This is analogous to the expansion | |
ccc6cda3 JA |
2596 | of the special parameters \fB*\fP and \fB@\fP (see |
2597 | .B Special Parameters | |
2598 | above). ${#\fIname\fP[\fIsubscript\fP]} expands to the length of | |
2599 | ${\fIname\fP[\fIsubscript\fP]}. If \fIsubscript\fP is \fB*\fP or | |
2600 | \fB@\fP, the expansion is the number of elements in the array. | |
ac50fbac CR |
2601 | If the |
2602 | .I subscript | |
2603 | used to reference an element of an indexed array | |
a0c0a00f | 2604 | evaluates to a number less than zero, it is |
ac50fbac CR |
2605 | interpreted as relative to one greater than the maximum index of the array, |
2606 | so negative indices count back from the end of the | |
2607 | array, and an index of \-1 references the last element. | |
ccc6cda3 | 2608 | .PP |
a0c0a00f CR |
2609 | Referencing an array variable without a subscript is equivalent to |
2610 | referencing the array with a subscript of 0. | |
2611 | Any reference to a variable using a valid subscript is legal, and | |
2612 | .B bash | |
2613 | will create an array if necessary. | |
2614 | .PP | |
0001803f CR |
2615 | An array variable is considered set if a subscript has been assigned a |
2616 | value. The null string is a valid value. | |
2617 | .PP | |
ac50fbac CR |
2618 | It is possible to obtain the keys (indices) of an array as well as the values. |
2619 | ${\fB!\fP\fIname\fP[\fI@\fP]} and ${\fB!\fP\fIname\fP[\fI*\fP]} | |
2620 | expand to the indices assigned in array variable \fIname\fP. | |
2621 | The treatment when in double quotes is similar to the expansion of the | |
2622 | special parameters \fI@\fP and \fI*\fP within double quotes. | |
2623 | .PP | |
ccc6cda3 JA |
2624 | The |
2625 | .B unset | |
bb70624e | 2626 | builtin is used to destroy arrays. \fBunset\fP \fIname\fP[\fIsubscript\fP] |
ccc6cda3 | 2627 | destroys the array element at index \fIsubscript\fP. |
ac50fbac | 2628 | Negative subscripts to indexed arrays are interpreted as described above. |
0001803f CR |
2629 | Care must be taken to avoid unwanted side effects caused by pathname |
2630 | expansion. | |
ccc6cda3 JA |
2631 | \fBunset\fP \fIname\fP, where \fIname\fP is an array, or |
2632 | \fBunset\fP \fIname\fP[\fIsubscript\fP], where | |
2633 | \fIsubscript\fP is \fB*\fP or \fB@\fP, removes the entire array. | |
2634 | .PP | |
2635 | The | |
2636 | .BR declare , | |
2637 | .BR local , | |
2638 | and | |
2639 | .B readonly | |
2640 | builtins each accept a | |
2641 | .B \-a | |
3185942a JA |
2642 | option to specify an indexed array and a |
2643 | .B \-A | |
2644 | option to specify an associative array. | |
a0c0a00f | 2645 | If both options are supplied, |
495aee44 CR |
2646 | .B \-A |
2647 | takes precedence. | |
3185942a | 2648 | The |
ccc6cda3 JA |
2649 | .B read |
2650 | builtin accepts a | |
2651 | .B \-a | |
2652 | option to assign a list of words read from the standard input | |
2653 | to an array. The | |
2654 | .B set | |
2655 | and | |
2656 | .B declare | |
2657 | builtins display array values in a way that allows them to be | |
2658 | reused as assignments. | |
726f6388 JA |
2659 | .SH EXPANSION |
2660 | Expansion is performed on the command line after it has been split into | |
2661 | words. There are seven kinds of expansion performed: | |
2662 | .IR "brace expansion" , | |
2663 | .IR "tilde expansion" , | |
2664 | .IR "parameter and variable expansion" , | |
2665 | .IR "command substitution" , | |
2666 | .IR "arithmetic expansion" , | |
2667 | .IR "word splitting" , | |
2668 | and | |
2669 | .IR "pathname expansion" . | |
2670 | .PP | |
ac50fbac CR |
2671 | The order of expansions is: |
2672 | brace expansion; | |
2673 | tilde expansion, parameter and variable expansion, arithmetic expansion, | |
2674 | and command substitution (done in a left-to-right fashion); | |
2675 | word splitting; | |
2676 | and pathname expansion. | |
726f6388 JA |
2677 | .PP |
2678 | On systems that can support it, there is an additional expansion | |
2679 | available: \fIprocess substitution\fP. | |
ac50fbac CR |
2680 | This is performed at the |
2681 | same time as tilde, parameter, variable, and arithmetic expansion and | |
2682 | command substitution. | |
726f6388 | 2683 | .PP |
a0c0a00f CR |
2684 | After these expansions are performed, quote characters present in the |
2685 | original word are removed unless they have been quoted themselves | |
2686 | (\fIquote removal\fP). | |
2687 | .PP | |
726f6388 JA |
2688 | Only brace expansion, word splitting, and pathname expansion |
2689 | can change the number of words of the expansion; other expansions | |
2690 | expand a single word to a single word. | |
ccc6cda3 | 2691 | The only exceptions to this are the expansions of |
cce855bc | 2692 | "\fB$@\fP" and "\fB${\fP\fIname\fP\fB[@]}\fP" |
ccc6cda3 | 2693 | as explained above (see |
726f6388 JA |
2694 | .SM |
2695 | .BR PARAMETERS ). | |
2696 | .SS Brace Expansion | |
2697 | .PP | |
2698 | .I "Brace expansion" | |
2699 | is a mechanism by which arbitrary strings | |
2700 | may be generated. This mechanism is similar to | |
2701 | \fIpathname expansion\fP, but the filenames generated | |
2702 | need not exist. Patterns to be brace expanded take | |
2703 | the form of an optional | |
2704 | .IR preamble , | |
b80f6443 JA |
2705 | followed by either a series of comma-separated strings or |
2706 | a sequence expression between a pair of braces, followed by | |
2707 | an optional | |
cce855bc | 2708 | .IR postscript . |
ccc6cda3 | 2709 | The preamble is prefixed to each string contained |
cce855bc | 2710 | within the braces, and the postscript is then appended |
726f6388 JA |
2711 | to each resulting string, expanding left to right. |
2712 | .PP | |
2713 | Brace expansions may be nested. The results of each expanded | |
2714 | string are not sorted; left to right order is preserved. | |
2715 | For example, a\fB{\fPd,c,b\fB}\fPe expands into `ade ace abe'. | |
2716 | .PP | |
3185942a JA |
2717 | A sequence expression takes the form |
2718 | \fB{\fP\fIx\fP\fB..\fP\fIy\fP\fB[..\fP\fIincr\fP\fB]}\fP, | |
2719 | where \fIx\fP and \fIy\fP are either integers or single characters, | |
2720 | and \fIincr\fP, an optional increment, is an integer. | |
b80f6443 JA |
2721 | When integers are supplied, the expression expands to each number between |
2722 | \fIx\fP and \fIy\fP, inclusive. | |
3185942a | 2723 | Supplied integers may be prefixed with \fI0\fP to force each term to have the |
ac50fbac CR |
2724 | same width. |
2725 | When either \fIx\fP or \fPy\fP begins with a zero, the shell | |
3185942a JA |
2726 | attempts to force all generated terms to contain the same number of digits, |
2727 | zero-padding where necessary. | |
b80f6443 | 2728 | When characters are supplied, the expression expands to each character |
ac50fbac CR |
2729 | lexicographically between \fIx\fP and \fIy\fP, inclusive, |
2730 | using the default C locale. | |
2731 | Note that both \fIx\fP and \fIy\fP must be of the same type. | |
3185942a JA |
2732 | When the increment is supplied, it is used as the difference between |
2733 | each term. The default increment is 1 or -1 as appropriate. | |
b80f6443 | 2734 | .PP |
726f6388 JA |
2735 | Brace expansion is performed before any other expansions, |
2736 | and any characters special to other expansions are preserved | |
2737 | in the result. It is strictly textual. | |
2738 | .B Bash | |
2739 | does not apply any syntactic interpretation to the context of the | |
2740 | expansion or the text between the braces. | |
2741 | .PP | |
2742 | A correctly-formed brace expansion must contain unquoted opening | |
b80f6443 JA |
2743 | and closing braces, and at least one unquoted comma or a valid |
2744 | sequence expression. | |
726f6388 | 2745 | Any incorrectly formed brace expansion is left unchanged. |
ccc6cda3 JA |
2746 | A \fB{\fP or \fB,\fP may be quoted with a backslash to prevent its |
2747 | being considered part of a brace expression. | |
bb70624e JA |
2748 | To avoid conflicts with parameter expansion, the string \fB${\fP |
2749 | is not considered eligible for brace expansion. | |
726f6388 JA |
2750 | .PP |
2751 | This construct is typically used as shorthand when the common | |
2752 | prefix of the strings to be generated is longer than in the | |
2753 | above example: | |
2754 | .RS | |
2755 | .PP | |
2756 | mkdir /usr/local/src/bash/{old,new,dist,bugs} | |
2757 | .RE | |
2758 | or | |
2759 | .RS | |
2760 | chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}} | |
2761 | .RE | |
2762 | .PP | |
2763 | Brace expansion introduces a slight incompatibility with | |
ccc6cda3 JA |
2764 | historical versions of |
2765 | .BR sh . | |
726f6388 JA |
2766 | .B sh |
2767 | does not treat opening or closing braces specially when they | |
2768 | appear as part of a word, and preserves them in the output. | |
2769 | .B Bash | |
2770 | removes braces from words as a consequence of brace | |
2771 | expansion. For example, a word entered to | |
2772 | .B sh | |
2773 | as \fIfile{1,2}\fP | |
2774 | appears identically in the output. The same word is | |
2775 | output as | |
2776 | .I file1 file2 | |
2777 | after expansion by | |
2778 | .BR bash . | |
2779 | If strict compatibility with | |
2780 | .B sh | |
2781 | is desired, start | |
2782 | .B bash | |
2783 | with the | |
a0c0a00f | 2784 | .B +B |
ccc6cda3 JA |
2785 | option or disable brace expansion with the |
2786 | .B +B | |
726f6388 JA |
2787 | option to the |
2788 | .B set | |
2789 | command (see | |
2790 | .SM | |
2791 | .B SHELL BUILTIN COMMANDS | |
2792 | below). | |
2793 | .SS Tilde Expansion | |
2794 | .PP | |
cce855bc JA |
2795 | If a word begins with an unquoted tilde character (`\fB~\fP'), all of |
2796 | the characters preceding the first unquoted slash (or all characters, | |
2797 | if there is no unquoted slash) are considered a \fItilde-prefix\fP. | |
2798 | If none of the characters in the tilde-prefix are quoted, the | |
2799 | characters in the tilde-prefix following the tilde are treated as a | |
2800 | possible \fIlogin name\fP. | |
2801 | If this login name is the null string, the tilde is replaced with the | |
2802 | value of the shell parameter | |
726f6388 JA |
2803 | .SM |
2804 | .BR HOME . | |
2805 | If | |
2806 | .SM | |
2807 | .B HOME | |
cce855bc JA |
2808 | is unset, the home directory of the user executing the shell is |
2809 | substituted instead. | |
2810 | Otherwise, the tilde-prefix is replaced with the home directory | |
2811 | associated with the specified login name. | |
726f6388 | 2812 | .PP |
cce855bc | 2813 | If the tilde-prefix is a `~+', the value of the shell variable |
726f6388 JA |
2814 | .SM |
2815 | .B PWD | |
cce855bc JA |
2816 | replaces the tilde-prefix. |
2817 | If the tilde-prefix is a `~\-', the value of the shell variable | |
2818 | .SM | |
2819 | .BR OLDPWD , | |
2820 | if it is set, is substituted. | |
2821 | If the characters following the tilde in the tilde-prefix consist | |
2822 | of a number \fIN\fP, optionally prefixed | |
2823 | by a `+' or a `\-', the tilde-prefix is replaced with the corresponding | |
2824 | element from the directory stack, as it would be displayed by the | |
2825 | .B dirs | |
2826 | builtin invoked with the tilde-prefix as an argument. | |
2827 | If the characters following the tilde in the tilde-prefix consist of a | |
2828 | number without a leading `+' or `\-', `+' is assumed. | |
2829 | .PP | |
2830 | If the login name is invalid, or the tilde expansion fails, the word | |
2831 | is unchanged. | |
726f6388 | 2832 | .PP |
cce855bc JA |
2833 | Each variable assignment is checked for unquoted tilde-prefixes immediately |
2834 | following a | |
726f6388 | 2835 | .B : |
95732b49 | 2836 | or the first |
726f6388 | 2837 | .BR = . |
cce855bc | 2838 | In these cases, tilde expansion is also performed. |
ac50fbac | 2839 | Consequently, one may use filenames with tildes in assignments to |
726f6388 JA |
2840 | .SM |
2841 | .BR PATH , | |
2842 | .SM | |
2843 | .BR MAILPATH , | |
2844 | and | |
2845 | .SM | |
2846 | .BR CDPATH , | |
2847 | and the shell assigns the expanded value. | |
2848 | .SS Parameter Expansion | |
2849 | .PP | |
2850 | The `\fB$\fP' character introduces parameter expansion, | |
2851 | command substitution, or arithmetic expansion. The parameter name | |
2852 | or symbol to be expanded may be enclosed in braces, which | |
2853 | are optional but serve to protect the variable to be expanded from | |
2854 | characters immediately following it which could be | |
2855 | interpreted as part of the name. | |
2856 | .PP | |
cce855bc JA |
2857 | When braces are used, the matching ending brace is the first `\fB}\fP' |
2858 | not escaped by a backslash or within a quoted string, and not within an | |
95732b49 | 2859 | embedded arithmetic expansion, command substitution, or parameter |
cce855bc JA |
2860 | expansion. |
2861 | .PP | |
726f6388 JA |
2862 | .PD 0 |
2863 | .TP | |
2864 | ${\fIparameter\fP} | |
2865 | The value of \fIparameter\fP is substituted. The braces are required | |
2866 | when | |
2867 | .I parameter | |
2868 | is a positional parameter with more than one digit, | |
2869 | or when | |
2870 | .I parameter | |
2871 | is followed by a character which is not to be | |
2872 | interpreted as part of its name. | |
ac50fbac CR |
2873 | The \fIparameter\fP is a shell parameter as described above |
2874 | \fBPARAMETERS\fP) or an array reference (\fBArrays\fP). | |
726f6388 JA |
2875 | .PD |
2876 | .PP | |
0001803f | 2877 | If the first character of \fIparameter\fP is an exclamation point (\fB!\fP), |
a0c0a00f | 2878 | and \fIparameter\fP is not a \fInameref\fP, |
ac50fbac | 2879 | it introduces a level of variable indirection. |
ccc6cda3 JA |
2880 | \fBBash\fP uses the value of the variable formed from the rest of |
2881 | \fIparameter\fP as the name of the variable; this variable is then | |
bb70624e | 2882 | expanded and that value is used in the rest of the substitution, rather |
ccc6cda3 JA |
2883 | than the value of \fIparameter\fP itself. |
2884 | This is known as \fIindirect expansion\fP. | |
a0c0a00f CR |
2885 | If \fIparameter\fP is a nameref, this expands to the name of the |
2886 | variable referenced by \fIparameter\fP instead of performing the | |
2887 | complete indirect expansion. | |
495aee44 | 2888 | The exceptions to this are the expansions of ${\fB!\fP\fIprefix\fP\fB*\fP} and |
b80f6443 JA |
2889 | ${\fB!\fP\fIname\fP[\fI@\fP]} described below. |
2890 | The exclamation point must immediately follow the left brace in order to | |
2891 | introduce indirection. | |
ccc6cda3 | 2892 | .PP |
726f6388 JA |
2893 | In each of the cases below, \fIword\fP is subject to tilde expansion, |
2894 | parameter expansion, command substitution, and arithmetic expansion. | |
17345e5a | 2895 | .PP |
ac50fbac CR |
2896 | When not performing substring expansion, using the forms documented below |
2897 | (e.g., \fB:-\fP), | |
17345e5a JA |
2898 | \fBbash\fP tests for a parameter that is unset or null. Omitting the colon |
2899 | results in a test only for a parameter that is unset. | |
726f6388 JA |
2900 | .PP |
2901 | .PD 0 | |
2902 | .TP | |
2903 | ${\fIparameter\fP\fB:\-\fP\fIword\fP} | |
2904 | \fBUse Default Values\fP. If | |
2905 | .I parameter | |
2906 | is unset or null, the expansion of | |
2907 | .I word | |
2908 | is substituted. Otherwise, the value of | |
2909 | .I parameter | |
2910 | is substituted. | |
2911 | .TP | |
2912 | ${\fIparameter\fP\fB:=\fP\fIword\fP} | |
2913 | \fBAssign Default Values\fP. | |
2914 | If | |
2915 | .I parameter | |
2916 | is unset or null, the expansion of | |
2917 | .I word | |
2918 | is assigned to | |
2919 | .IR parameter . | |
2920 | The value of | |
2921 | .I parameter | |
2922 | is then substituted. Positional parameters and special parameters may | |
2923 | not be assigned to in this way. | |
2924 | .TP | |
2925 | ${\fIparameter\fP\fB:?\fP\fIword\fP} | |
2926 | \fBDisplay Error if Null or Unset\fP. | |
2927 | If | |
2928 | .I parameter | |
2929 | is null or unset, the expansion of \fIword\fP (or a message to that effect | |
2930 | if | |
2931 | .I word | |
2932 | is not present) is written to the standard error and the shell, if it | |
2933 | is not interactive, exits. Otherwise, the value of \fIparameter\fP is | |
2934 | substituted. | |
2935 | .TP | |
2936 | ${\fIparameter\fP\fB:+\fP\fIword\fP} | |
2937 | \fBUse Alternate Value\fP. | |
2938 | If | |
2939 | .I parameter | |
2940 | is null or unset, nothing is substituted, otherwise the expansion of | |
2941 | .I word | |
2942 | is substituted. | |
2943 | .TP | |
ccc6cda3 | 2944 | ${\fIparameter\fP\fB:\fP\fIoffset\fP} |
7117c2d2 | 2945 | .PD 0 |
ccc6cda3 JA |
2946 | .TP |
2947 | ${\fIparameter\fP\fB:\fP\fIoffset\fP\fB:\fP\fIlength\fP} | |
2948 | .PD | |
495aee44 | 2949 | \fBSubstring Expansion\fP. |
ac50fbac | 2950 | Expands to up to \fIlength\fP characters of the value of \fIparameter\fP |
bb70624e | 2951 | starting at the character specified by \fIoffset\fP. |
ac50fbac CR |
2952 | If \fIparameter\fP is \fB@\fP, an indexed array subscripted by |
2953 | \fB@\fP or \fB*\fP, or an associative array name, the results differ as | |
2954 | described below. | |
2955 | If \fIlength\fP is omitted, expands to the substring of the value of | |
2956 | \fIparameter\fP starting at the character specified by \fIoffset\fP | |
2957 | and extending to the end of the value. | |
ccc6cda3 JA |
2958 | \fIlength\fP and \fIoffset\fP are arithmetic expressions (see |
2959 | .SM | |
2960 | .B | |
2961 | ARITHMETIC EVALUATION | |
2962 | below). | |
ac50fbac | 2963 | .sp 1 |
ccc6cda3 | 2964 | If \fIoffset\fP evaluates to a number less than zero, the value |
ac50fbac CR |
2965 | is used as an offset in characters |
2966 | from the end of the value of \fIparameter\fP. | |
2967 | If \fIlength\fP evaluates to a number less than zero, | |
2968 | it is interpreted as an offset in characters | |
2969 | from the end of the value of \fIparameter\fP rather than | |
2970 | a number of characters, and the expansion is the characters between | |
2971 | \fIoffset\fP and that result. | |
2972 | Note that a negative offset must be separated from the colon by at least | |
2973 | one space to avoid being confused with the \fB:-\fP expansion. | |
2974 | .sp 1 | |
ccc6cda3 JA |
2975 | If \fIparameter\fP is \fB@\fP, the result is \fIlength\fP positional |
2976 | parameters beginning at \fIoffset\fP. | |
ac50fbac CR |
2977 | A negative \fIoffset\fP is taken relative to one greater than the greatest |
2978 | positional parameter, so an offset of -1 evaluates to the last positional | |
2979 | parameter. | |
2980 | It is an expansion error if \fIlength\fP evaluates to a number less than | |
2981 | zero. | |
2982 | .sp 1 | |
3185942a | 2983 | If \fIparameter\fP is an indexed array name subscripted by @ or *, |
ccc6cda3 JA |
2984 | the result is the \fIlength\fP |
2985 | members of the array beginning with ${\fIparameter\fP[\fIoffset\fP]}. | |
95732b49 JA |
2986 | A negative \fIoffset\fP is taken relative to one greater than the maximum |
2987 | index of the specified array. | |
ac50fbac CR |
2988 | It is an expansion error if \fIlength\fP evaluates to a number less than |
2989 | zero. | |
2990 | .sp 1 | |
3185942a JA |
2991 | Substring expansion applied to an associative array produces undefined |
2992 | results. | |
ac50fbac | 2993 | .sp 1 |
a0c0a00f | 2994 | Substring indexing is zero-based unless the positional parameters |
3185942a JA |
2995 | are used, in which case the indexing starts at 1 by default. |
2996 | If \fIoffset\fP is 0, and the positional parameters are used, \fB$0\fP is | |
2997 | prefixed to the list. | |
ccc6cda3 | 2998 | .TP |
bb70624e | 2999 | ${\fB!\fP\fIprefix\fP\fB*\fP} |
b80f6443 JA |
3000 | .PD 0 |
3001 | .TP | |
3002 | ${\fB!\fP\fIprefix\fP\fB@\fP} | |
3003 | .PD | |
495aee44 | 3004 | \fBNames matching prefix\fP. |
bb70624e JA |
3005 | Expands to the names of variables whose names begin with \fIprefix\fP, |
3006 | separated by the first character of the | |
3007 | .SM | |
3008 | .B IFS | |
3009 | special variable. | |
3185942a JA |
3010 | When \fI@\fP is used and the expansion appears within double quotes, each |
3011 | variable name expands to a separate word. | |
bb70624e | 3012 | .TP |
b80f6443 JA |
3013 | ${\fB!\fP\fIname\fP[\fI@\fP]} |
3014 | .PD 0 | |
3015 | .TP | |
3016 | ${\fB!\fP\fIname\fP[\fI*\fP]} | |
3017 | .PD | |
495aee44 | 3018 | \fBList of array keys\fP. |
b80f6443 JA |
3019 | If \fIname\fP is an array variable, expands to the list of array indices |
3020 | (keys) assigned in \fIname\fP. | |
3021 | If \fIname\fP is not an array, expands to 0 if \fIname\fP is set and null | |
3022 | otherwise. | |
3023 | When \fI@\fP is used and the expansion appears within double quotes, each | |
3024 | key expands to a separate word. | |
3025 | .TP | |
726f6388 | 3026 | ${\fB#\fP\fIparameter\fP} |
495aee44 | 3027 | \fBParameter length\fP. |
726f6388 | 3028 | The length in characters of the value of \fIparameter\fP is substituted. |
ccc6cda3 JA |
3029 | If |
3030 | .I parameter | |
3031 | is | |
726f6388 | 3032 | .B * |
a0c0a00f | 3033 | or |
726f6388 | 3034 | .BR @ , |
cce855bc | 3035 | the value substituted is the number of positional parameters. |
ccc6cda3 JA |
3036 | If |
3037 | .I parameter | |
3038 | is an array name subscripted by | |
726f6388 | 3039 | .B * |
ccc6cda3 JA |
3040 | or |
3041 | .BR @ , | |
cce855bc | 3042 | the value substituted is the number of elements in the array. |
ac50fbac CR |
3043 | If |
3044 | .I parameter | |
3045 | is an indexed array name subscripted by a negative number, that number is | |
3046 | interpreted as relative to one greater than the maximum index of | |
3047 | \fIparameter\fP, so negative indices count back from the end of the | |
3048 | array, and an index of \-1 references the last element. | |
726f6388 | 3049 | .TP |
726f6388 | 3050 | ${\fIparameter\fP\fB#\fP\fIword\fP} |
7117c2d2 | 3051 | .PD 0 |
726f6388 JA |
3052 | .TP |
3053 | ${\fIparameter\fP\fB##\fP\fIword\fP} | |
3054 | .PD | |
495aee44 | 3055 | \fBRemove matching prefix pattern\fP. |
a0c0a00f | 3056 | The |
726f6388 JA |
3057 | .I word |
3058 | is expanded to produce a pattern just as in pathname | |
3059 | expansion. If the pattern matches the beginning of | |
3060 | the value of | |
3061 | .IR parameter , | |
cce855bc | 3062 | then the result of the expansion is the expanded value of |
726f6388 | 3063 | .I parameter |
ccc6cda3 JA |
3064 | with the shortest matching pattern (the ``\fB#\fP'' case) or the |
3065 | longest matching pattern (the ``\fB##\fP'' case) deleted. | |
3066 | If | |
3067 | .I parameter | |
3068 | is | |
3069 | .B @ | |
3070 | or | |
3071 | .BR * , | |
3072 | the pattern removal operation is applied to each positional | |
3073 | parameter in turn, and the expansion is the resultant list. | |
3074 | If | |
3075 | .I parameter | |
3076 | is an array variable subscripted with | |
3077 | .B @ | |
3078 | or | |
3079 | .BR * , | |
3080 | the pattern removal operation is applied to each member of the | |
3081 | array in turn, and the expansion is the resultant list. | |
726f6388 | 3082 | .TP |
726f6388 | 3083 | ${\fIparameter\fP\fB%\fP\fIword\fP} |
7117c2d2 | 3084 | .PD 0 |
726f6388 JA |
3085 | .TP |
3086 | ${\fIparameter\fP\fB%%\fP\fIword\fP} | |
3087 | .PD | |
495aee44 | 3088 | \fBRemove matching suffix pattern\fP. |
726f6388 | 3089 | The \fIword\fP is expanded to produce a pattern just as in |
ccc6cda3 | 3090 | pathname expansion. |
cce855bc | 3091 | If the pattern matches a trailing portion of the expanded value of |
726f6388 | 3092 | .IR parameter , |
cce855bc | 3093 | then the result of the expansion is the expanded value of |
726f6388 | 3094 | .I parameter |
ccc6cda3 JA |
3095 | with the shortest matching pattern (the ``\fB%\fP'' case) or the |
3096 | longest matching pattern (the ``\fB%%\fP'' case) deleted. | |
3097 | If | |
3098 | .I parameter | |
3099 | is | |
3100 | .B @ | |
3101 | or | |
3102 | .BR * , | |
3103 | the pattern removal operation is applied to each positional | |
3104 | parameter in turn, and the expansion is the resultant list. | |
3105 | If | |
3106 | .I parameter | |
3107 | is an array variable subscripted with | |
3108 | .B @ | |
3109 | or | |
3110 | .BR * , | |
3111 | the pattern removal operation is applied to each member of the | |
3112 | array in turn, and the expansion is the resultant list. | |
3113 | .TP | |
ccc6cda3 | 3114 | ${\fIparameter\fP\fB/\fP\fIpattern\fP\fB/\fP\fIstring\fP} |
495aee44 | 3115 | \fBPattern substitution\fP. |
ccc6cda3 JA |
3116 | The \fIpattern\fP is expanded to produce a pattern just as in |
3117 | pathname expansion. | |
3118 | \fIParameter\fP is expanded and the longest match of \fIpattern\fP | |
3119 | against its value is replaced with \fIstring\fP. | |
3185942a | 3120 | If \fIpattern\fP begins with \fB/\fP, all matches of \fIpattern\fP are |
0628567a | 3121 | replaced with \fIstring\fP. Normally only the first match is replaced. |
ccc6cda3 | 3122 | If \fIpattern\fP begins with \fB#\fP, it must match at the beginning |
b72432fd | 3123 | of the expanded value of \fIparameter\fP. |
ccc6cda3 | 3124 | If \fIpattern\fP begins with \fB%\fP, it must match at the end |
b72432fd | 3125 | of the expanded value of \fIparameter\fP. |
ccc6cda3 JA |
3126 | If \fIstring\fP is null, matches of \fIpattern\fP are deleted |
3127 | and the \fB/\fP following \fIpattern\fP may be omitted. | |
a0c0a00f CR |
3128 | If the |
3129 | .B nocasematch | |
3130 | shell option is enabled, the match is performed without regard to the case | |
3131 | of alphabetic characters. | |
ccc6cda3 JA |
3132 | If |
3133 | .I parameter | |
3134 | is | |
3135 | .B @ | |
3136 | or | |
3137 | .BR * , | |
3138 | the substitution operation is applied to each positional | |
3139 | parameter in turn, and the expansion is the resultant list. | |
3140 | If | |
3141 | .I parameter | |
3142 | is an array variable subscripted with | |
3143 | .B @ | |
3144 | or | |
3145 | .BR * , | |
3146 | the substitution operation is applied to each member of the | |
3147 | array in turn, and the expansion is the resultant list. | |
3185942a JA |
3148 | .TP |
3149 | ${\fIparameter\fP\fB^\fP\fIpattern\fP} | |
3150 | .PD 0 | |
3151 | .TP | |
3152 | ${\fIparameter\fP\fB^^\fP\fIpattern\fP} | |
3153 | .TP | |
3154 | ${\fIparameter\fP\fB,\fP\fIpattern\fP} | |
3155 | .TP | |
3156 | ${\fIparameter\fP\fB,,\fP\fIpattern\fP} | |
3157 | .PD | |
495aee44 | 3158 | \fBCase modification\fP. |
3185942a JA |
3159 | This expansion modifies the case of alphabetic characters in \fIparameter\fP. |
3160 | The \fIpattern\fP is expanded to produce a pattern just as in | |
3161 | pathname expansion. | |
ac50fbac CR |
3162 | Each character in the expanded value of \fIparameter\fP is tested against |
3163 | \fIpattern\fP, and, if it matches the pattern, its case is converted. | |
3164 | The pattern should not attempt to match more than one character. | |
3185942a JA |
3165 | The \fB^\fP operator converts lowercase letters matching \fIpattern\fP |
3166 | to uppercase; the \fB,\fP operator converts matching uppercase letters | |
3167 | to lowercase. | |
3168 | The \fB^^\fP and \fB,,\fP expansions convert each matched character in the | |
3169 | expanded value; the \fB^\fP and \fB,\fP expansions match and convert only | |
495aee44 | 3170 | the first character in the expanded value. |
3185942a JA |
3171 | If \fIpattern\fP is omitted, it is treated like a \fB?\fP, which matches |
3172 | every character. | |
3173 | If | |
3174 | .I parameter | |
3175 | is | |
3176 | .B @ | |
3177 | or | |
3178 | .BR * , | |
3179 | the case modification operation is applied to each positional | |
3180 | parameter in turn, and the expansion is the resultant list. | |
3181 | If | |
3182 | .I parameter | |
3183 | is an array variable subscripted with | |
3184 | .B @ | |
3185 | or | |
3186 | .BR * , | |
3187 | the case modification operation is applied to each member of the | |
3188 | array in turn, and the expansion is the resultant list. | |
a0c0a00f CR |
3189 | .TP |
3190 | ${\fIparameter\fP\fB@\fP\fIoperator\fP} | |
3191 | \fBParameter transformation\fP. | |
3192 | The expansion is either a transformation of the value of \fIparameter\fP | |
3193 | or information about \fIparameter\fP itself, depending on the value of | |
3194 | \fIoperator\fP. Each \fIoperator\fP is a single letter: | |
3195 | .sp 1 | |
3196 | .RS | |
3197 | .PD 0 | |
3198 | .TP | |
3199 | .B Q | |
3200 | The expansion is a string that is the value of \fIparameter\fP quoted in a | |
3201 | format that can be reused as input. | |
3202 | .TP | |
3203 | .B E | |
3204 | The expansion is a string that is the value of \fIparameter\fP with backslash | |
3205 | escape sequences expanded as with the \fB$'...'\fP quoting mechansim. | |
3206 | .TP | |
3207 | .B P | |
3208 | The expansion is a string that is the result of expanding the value of | |
3209 | \fIparameter\fP as if it were a prompt string (see \fBPROMPTING\fP below). | |
3210 | .TP | |
3211 | .B A | |
3212 | The expansion is a string in the form of | |
3213 | an assignment statement or \fBdeclare\fP command that, if | |
3214 | evaluated, will recreate \fIparameter\fP with its attributes and value. | |
3215 | .TP | |
3216 | .B a | |
3217 | The expansion is a string consisting of flag values representing | |
3218 | \fIparameter\fP's attributes. | |
3219 | .PD | |
3220 | .PP | |
3221 | If | |
3222 | .I parameter | |
3223 | is | |
3224 | .B @ | |
3225 | or | |
3226 | .BR * , | |
3227 | the operation is applied to each positional | |
3228 | parameter in turn, and the expansion is the resultant list. | |
3229 | If | |
3230 | .I parameter | |
3231 | is an array variable subscripted with | |
3232 | .B @ | |
3233 | or | |
3234 | .BR * , | |
3235 | the case modification operation is applied to each member of the | |
3236 | array in turn, and the expansion is the resultant list. | |
3237 | .sp 1 | |
3238 | The result of the expansion is subject to word splitting and pathname | |
3239 | expansion as described below. | |
3240 | .RE | |
726f6388 JA |
3241 | .SS Command Substitution |
3242 | .PP | |
cce855bc | 3243 | \fICommand substitution\fP allows the output of a command to replace |
726f6388 | 3244 | the command name. There are two forms: |
726f6388 JA |
3245 | .RS |
3246 | .PP | |
3247 | \fB$(\fP\fIcommand\fP\|\fB)\fP | |
3248 | .RE | |
3249 | or | |
3250 | .RS | |
3185942a | 3251 | \fB\`\fP\fIcommand\fP\fB\`\fP |
726f6388 JA |
3252 | .RE |
3253 | .PP | |
ccc6cda3 | 3254 | .B Bash |
a0c0a00f CR |
3255 | performs the expansion by executing \fIcommand\fP in a subshell environment |
3256 | and replacing the command substitution with the standard output of the | |
726f6388 | 3257 | command, with any trailing newlines deleted. |
cce855bc JA |
3258 | Embedded newlines are not deleted, but they may be removed during |
3259 | word splitting. | |
3260 | The command substitution \fB$(cat \fIfile\fP)\fR can be replaced by | |
3261 | the equivalent but faster \fB$(< \fIfile\fP)\fR. | |
726f6388 | 3262 | .PP |
ccc6cda3 | 3263 | When the old-style backquote form of substitution is used, |
726f6388 JA |
3264 | backslash retains its literal meaning except when followed by |
3265 | .BR $ , | |
3185942a | 3266 | .BR \` , |
726f6388 JA |
3267 | or |
3268 | .BR \e . | |
cce855bc JA |
3269 | The first backquote not preceded by a backslash terminates the |
3270 | command substitution. | |
726f6388 JA |
3271 | When using the $(\^\fIcommand\fP\|) form, all characters between the |
3272 | parentheses make up the command; none are treated specially. | |
3273 | .PP | |
cce855bc | 3274 | Command substitutions may be nested. To nest when using the backquoted form, |
726f6388 JA |
3275 | escape the inner backquotes with backslashes. |
3276 | .PP | |
3277 | If the substitution appears within double quotes, word splitting and | |
3278 | pathname expansion are not performed on the results. | |
3279 | .SS Arithmetic Expansion | |
3280 | .PP | |
3281 | Arithmetic expansion allows the evaluation of an arithmetic expression | |
ccc6cda3 | 3282 | and the substitution of the result. The format for arithmetic expansion is: |
726f6388 JA |
3283 | .RS |
3284 | .PP | |
726f6388 JA |
3285 | \fB$((\fP\fIexpression\fP\fB))\fP |
3286 | .RE | |
3287 | .PP | |
3288 | The | |
3289 | .I expression | |
3290 | is treated as if it were within double quotes, but a double quote | |
ccc6cda3 | 3291 | inside the parentheses is not treated specially. |
ac50fbac CR |
3292 | All tokens in the expression undergo parameter and variable expansion, |
3293 | command substitution, and quote removal. | |
3294 | The result is treated as the arithmetic expression to be evaluated. | |
b80f6443 | 3295 | Arithmetic expansions may be nested. |
726f6388 JA |
3296 | .PP |
3297 | The evaluation is performed according to the rules listed below under | |
3298 | .SM | |
3299 | .BR "ARITHMETIC EVALUATION" . | |
3300 | If | |
3301 | .I expression | |
3302 | is invalid, | |
3303 | .B bash | |
3304 | prints a message indicating failure and no substitution occurs. | |
3305 | .SS Process Substitution | |
3306 | .PP | |
a0c0a00f CR |
3307 | \fIProcess substitution\fP allows a process's input or output to be |
3308 | referred to using a filename. | |
726f6388 JA |
3309 | It takes the form of |
3310 | \fB<(\fP\fIlist\^\fP\fB)\fP | |
3311 | or | |
3312 | \fB>(\fP\fIlist\^\fP\fB)\fP. | |
a0c0a00f CR |
3313 | The process \fIlist\fP is run asynchronously, and its input or output |
3314 | appears as a filename. | |
3315 | This filename is | |
726f6388 | 3316 | passed as an argument to the current command as the result of the |
a0c0a00f CR |
3317 | expansion. |
3318 | If the \fB>(\fP\fIlist\^\fP\fB)\fP form is used, writing to | |
726f6388 JA |
3319 | the file will provide input for \fIlist\fP. If the |
3320 | \fB<(\fP\fIlist\^\fP\fB)\fP form is used, the file passed as an | |
3321 | argument should be read to obtain the output of \fIlist\fP. | |
a0c0a00f CR |
3322 | Process substitution is supported on systems that support named |
3323 | pipes (\fIFIFOs\fP) or the \fB/dev/fd\fP method of naming open files. | |
726f6388 | 3324 | .PP |
bb70624e | 3325 | When available, process substitution is performed |
a0c0a00f | 3326 | simultaneously with parameter and variable expansion, |
ccc6cda3 JA |
3327 | command substitution, |
3328 | and arithmetic expansion. | |
726f6388 JA |
3329 | .SS Word Splitting |
3330 | .PP | |
3331 | The shell scans the results of | |
3332 | parameter expansion, | |
3333 | command substitution, | |
3334 | and | |
3335 | arithmetic expansion | |
3336 | that did not occur within double quotes for | |
3337 | .IR "word splitting" . | |
3338 | .PP | |
3339 | The shell treats each character of | |
3340 | .SM | |
3341 | .B IFS | |
3342 | as a delimiter, and splits the results of the other | |
ac50fbac CR |
3343 | expansions into words using these characters as field terminators. |
3344 | If | |
726f6388 JA |
3345 | .SM |
3346 | .B IFS | |
ccc6cda3 JA |
3347 | is unset, or its |
3348 | value is exactly | |
726f6388 JA |
3349 | .BR <space><tab><newline> , |
3350 | the default, then | |
3185942a JA |
3351 | sequences of |
3352 | .BR <space> , | |
3353 | .BR <tab> , | |
3354 | and | |
3355 | .B <newline> | |
3356 | at the beginning and end of the results of the previous | |
3357 | expansions are ignored, and | |
726f6388 JA |
3358 | any sequence of |
3359 | .SM | |
3360 | .B IFS | |
3185942a JA |
3361 | characters not at the beginning or end serves to delimit words. |
3362 | If | |
726f6388 JA |
3363 | .SM |
3364 | .B IFS | |
3365 | has a value other than the default, then sequences of | |
3366 | the whitespace characters | |
a0c0a00f CR |
3367 | .BR space , |
3368 | .BR tab , | |
726f6388 | 3369 | and |
a0c0a00f | 3370 | .B newline |
726f6388 JA |
3371 | are ignored at the beginning and end of the |
3372 | word, as long as the whitespace character is in the | |
3373 | value of | |
3374 | .SM | |
3375 | .BR IFS | |
3376 | (an | |
3377 | .SM | |
3378 | .B IFS | |
3379 | whitespace character). | |
3380 | Any character in | |
3381 | .SM | |
3382 | .B IFS | |
3383 | that is not | |
3384 | .SM | |
3385 | .B IFS | |
3386 | whitespace, along with any adjacent | |
3387 | .SM | |
3388 | .B IFS | |
3389 | whitespace characters, delimits a field. | |
3390 | A sequence of | |
3391 | .SM | |
3392 | .B IFS | |
3393 | whitespace characters is also treated as a delimiter. | |
3394 | If the value of | |
3395 | .SM | |
3396 | .B IFS | |
3397 | is null, no word splitting occurs. | |
726f6388 | 3398 | .PP |
a0c0a00f CR |
3399 | Explicit null arguments (\^\f3"\^"\fP or \^\f3\(aq\^\(aq\fP\^) are retained |
3400 | and passed to commands as empty strings. | |
ccc6cda3 | 3401 | Unquoted implicit null arguments, resulting from the expansion of |
bb70624e | 3402 | parameters that have no values, are removed. |
ccc6cda3 | 3403 | If a parameter with no value is expanded within double quotes, a |
a0c0a00f CR |
3404 | null argument results and is retained |
3405 | and passed to a command as an empty string. | |
3406 | When a quoted null argument appears as part of a word whose expansion is | |
3407 | non-null, the null argument is removed. | |
3408 | That is, the word | |
3409 | \f(CW\-d\(aq\^\(aq\fP becomes \f(CW\-d\fP after word splitting and | |
3410 | null argument removal. | |
726f6388 JA |
3411 | .PP |
3412 | Note that if no expansion occurs, no splitting | |
3413 | is performed. | |
3414 | .SS Pathname Expansion | |
3415 | .PP | |
3416 | After word splitting, | |
3417 | unless the | |
3418 | .B \-f | |
3419 | option has been set, | |
3420 | .B bash | |
ccc6cda3 | 3421 | scans each word for the characters |
726f6388 JA |
3422 | .BR * , |
3423 | .BR ? , | |
3424 | and | |
3425 | .BR [ . | |
3426 | If one of these characters appears, then the word is | |
3427 | regarded as a | |
3428 | .IR pattern , | |
3429 | and replaced with an alphabetically sorted list of | |
ac50fbac CR |
3430 | filenames matching the pattern |
3431 | (see | |
3432 | .SM | |
3433 | .B "Pattern Matching" | |
3434 | below). | |
3435 | If no matching filenames are found, | |
ccc6cda3 JA |
3436 | and the shell option |
3437 | .B nullglob | |
3185942a | 3438 | is not enabled, the word is left unchanged. |
a0c0a00f | 3439 | If the |
cce855bc JA |
3440 | .B nullglob |
3441 | option is set, and no matches are found, | |
726f6388 | 3442 | the word is removed. |
b80f6443 JA |
3443 | If the |
3444 | .B failglob | |
3445 | shell option is set, and no matches are found, an error message | |
3446 | is printed and the command is not executed. | |
cce855bc JA |
3447 | If the shell option |
3448 | .B nocaseglob | |
3449 | is enabled, the match is performed without regard to the case | |
3450 | of alphabetic characters. | |
ccc6cda3 | 3451 | When a pattern is used for pathname expansion, |
726f6388 JA |
3452 | the character |
3453 | .B ``.'' | |
3454 | at the start of a name or immediately following a slash | |
ccc6cda3 JA |
3455 | must be matched explicitly, unless the shell option |
3456 | .B dotglob | |
3457 | is set. | |
cce855bc JA |
3458 | When matching a pathname, the slash character must always be |
3459 | matched explicitly. | |
ccc6cda3 | 3460 | In other cases, the |
726f6388 JA |
3461 | .B ``.'' |
3462 | character is not treated specially. | |
ccc6cda3 JA |
3463 | See the description of |
3464 | .B shopt | |
3465 | below under | |
3466 | .SM | |
3467 | .B SHELL BUILTIN COMMANDS | |
3468 | for a description of the | |
cce855bc JA |
3469 | .BR nocaseglob , |
3470 | .BR nullglob , | |
b80f6443 | 3471 | .BR failglob , |
ccc6cda3 JA |
3472 | and |
3473 | .B dotglob | |
3474 | shell options. | |
3475 | .PP | |
3476 | The | |
3477 | .SM | |
3478 | .B GLOBIGNORE | |
ac50fbac | 3479 | shell variable may be used to restrict the set of filenames matching a |
ccc6cda3 JA |
3480 | .IR pattern . |
3481 | If | |
3482 | .SM | |
3483 | .B GLOBIGNORE | |
ac50fbac | 3484 | is set, each matching filename that also matches one of the patterns in |
ccc6cda3 JA |
3485 | .SM |
3486 | .B GLOBIGNORE | |
3487 | is removed from the list of matches. | |
a0c0a00f CR |
3488 | If the \fBnocaseglob\fP option is set, the matching against the patterns in |
3489 | .SM | |
3490 | .B GLOBIGNORE | |
3491 | is performed without regard to case. | |
ac50fbac | 3492 | The filenames |
ccc6cda3 JA |
3493 | .B ``.'' |
3494 | and | |
3495 | .B ``..'' | |
b80f6443 | 3496 | are always ignored when |
ccc6cda3 JA |
3497 | .SM |
3498 | .B GLOBIGNORE | |
b80f6443 | 3499 | is set and not null. However, setting |
ccc6cda3 JA |
3500 | .SM |
3501 | .B GLOBIGNORE | |
b80f6443 | 3502 | to a non-null value has the effect of enabling the |
ccc6cda3 | 3503 | .B dotglob |
ac50fbac | 3504 | shell option, so all other filenames beginning with a |
ccc6cda3 JA |
3505 | .B ``.'' |
3506 | will match. | |
ac50fbac | 3507 | To get the old behavior of ignoring filenames beginning with a |
ccc6cda3 JA |
3508 | .BR ``.'' , |
3509 | make | |
3510 | .B ``.*'' | |
3511 | one of the patterns in | |
3512 | .SM | |
3513 | .BR GLOBIGNORE . | |
3514 | The | |
3515 | .B dotglob | |
3516 | option is disabled when | |
3517 | .SM | |
3518 | .B GLOBIGNORE | |
3519 | is unset. | |
a0c0a00f CR |
3520 | The pattern matching honors the setting of the \fBextglob\fP shell |
3521 | option. | |
726f6388 | 3522 | .PP |
cce855bc JA |
3523 | \fBPattern Matching\fP |
3524 | .PP | |
3525 | Any character that appears in a pattern, other than the special pattern | |
3526 | characters described below, matches itself. The NUL character may not | |
b80f6443 JA |
3527 | occur in a pattern. A backslash escapes the following character; the |
3528 | escaping backslash is discarded when matching. | |
3529 | The special pattern characters must be quoted if | |
cce855bc JA |
3530 | they are to be matched literally. |
3531 | .PP | |
726f6388 JA |
3532 | The special pattern characters have the following meanings: |
3533 | .PP | |
3534 | .PD 0 | |
495aee44 | 3535 | .RS |
726f6388 JA |
3536 | .TP |
3537 | .B * | |
3538 | Matches any string, including the null string. | |
3185942a | 3539 | When the \fBglobstar\fP shell option is enabled, and \fB*\fP is used in |
0001803f | 3540 | a pathname expansion context, two adjacent \fB*\fPs used as a single |
3185942a JA |
3541 | pattern will match all files and zero or more directories and |
3542 | subdirectories. | |
3543 | If followed by a \fB/\fP, two adjacent \fB*\fPs will match only directories | |
3544 | and subdirectories. | |
726f6388 JA |
3545 | .TP |
3546 | .B ? | |
3547 | Matches any single character. | |
3548 | .TP | |
3549 | .B [...] | |
3550 | Matches any one of the enclosed characters. A pair of characters | |
28ef6c31 JA |
3551 | separated by a hyphen denotes a |
3552 | \fIrange expression\fP; | |
ac50fbac | 3553 | any character that falls between those two characters, inclusive, |
28ef6c31 | 3554 | using the current locale's collating sequence and character set, |
726f6388 JA |
3555 | is matched. If the first character following the |
3556 | .B [ | |
3557 | is a | |
3558 | .B ! | |
3559 | or a | |
3560 | .B ^ | |
ccc6cda3 | 3561 | then any character not enclosed is matched. |
28ef6c31 | 3562 | The sorting order of characters in range expressions is determined by |
ac50fbac | 3563 | the current locale and the values of the |
0001803f CR |
3564 | .SM |
3565 | .B LC_COLLATE | |
ac50fbac CR |
3566 | or |
3567 | .SM | |
3568 | .B LC_ALL | |
3569 | shell variables, if set. | |
3570 | To obtain the traditional interpretation of range expressions, where | |
3571 | .B [a\-d] | |
3572 | is equivalent to | |
3573 | .BR [abcd] , | |
3574 | set value of the | |
3575 | .B LC_ALL | |
3576 | shell variable to | |
3577 | .BR C , | |
3578 | or enable the | |
3579 | .B globasciiranges | |
3580 | shell option. | |
a0c0a00f | 3581 | A |
726f6388 | 3582 | .B \- |
726f6388 JA |
3583 | may be matched by including it as the first or last character |
3584 | in the set. | |
ccc6cda3 JA |
3585 | A |
3586 | .B ] | |
3587 | may be matched by including it as the first character | |
3588 | in the set. | |
cce855bc JA |
3589 | .br |
3590 | .if t .sp 0.5 | |
3591 | .if n .sp 1 | |
3592 | Within | |
3593 | .B [ | |
3594 | and | |
3595 | .BR ] , | |
3596 | \fIcharacter classes\fP can be specified using the syntax | |
3597 | \fB[:\fP\fIclass\fP\fB:]\fP, where \fIclass\fP is one of the | |
0628567a | 3598 | following classes defined in the POSIX standard: |
cce855bc JA |
3599 | .PP |
3600 | .RS | |
3601 | .B | |
7117c2d2 JA |
3602 | .if n alnum alpha ascii blank cntrl digit graph lower print punct space upper word xdigit |
3603 | .if t alnum alpha ascii blank cntrl digit graph lower print punct space upper word xdigit | |
cce855bc JA |
3604 | .br |
3605 | A character class matches any character belonging to that class. | |
7117c2d2 | 3606 | The \fBword\fP character class matches letters, digits, and the character _. |
cce855bc JA |
3607 | .br |
3608 | .if t .sp 0.5 | |
3609 | .if n .sp 1 | |
3610 | Within | |
3611 | .B [ | |
a0c0a00f | 3612 | and |
cce855bc JA |
3613 | .BR ] , |
3614 | an \fIequivalence class\fP can be specified using the syntax | |
3615 | \fB[=\fP\fIc\fP\fB=]\fP, which matches all characters with the | |
3616 | same collation weight (as defined by the current locale) as | |
3617 | the character \fIc\fP. | |
3618 | .br | |
3619 | .if t .sp 0.5 | |
3620 | .if n .sp 1 | |
3621 | Within | |
3622 | .B [ | |
a0c0a00f | 3623 | and |
cce855bc JA |
3624 | .BR ] , |
3625 | the syntax \fB[.\fP\fIsymbol\fP\fB.]\fP matches the collating symbol | |
3626 | \fIsymbol\fP. | |
3627 | .RE | |
495aee44 | 3628 | .RE |
cce855bc JA |
3629 | .PD |
3630 | .PP | |
3631 | If the \fBextglob\fP shell option is enabled using the \fBshopt\fP | |
3632 | builtin, several extended pattern matching operators are recognized. | |
bb70624e | 3633 | In the following description, a \fIpattern-list\fP is a list of one |
cce855bc JA |
3634 | or more patterns separated by a \fB|\fP. |
3635 | Composite patterns may be formed using one or more of the following | |
3636 | sub-patterns: | |
3637 | .sp 1 | |
3638 | .PD 0 | |
3639 | .RS | |
3640 | .TP | |
3641 | \fB?(\fP\^\fIpattern-list\^\fP\fB)\fP | |
3642 | Matches zero or one occurrence of the given patterns | |
3643 | .TP | |
3644 | \fB*(\fP\^\fIpattern-list\^\fP\fB)\fP | |
3645 | Matches zero or more occurrences of the given patterns | |
3646 | .TP | |
3647 | \fB+(\fP\^\fIpattern-list\^\fP\fB)\fP | |
3648 | Matches one or more occurrences of the given patterns | |
3649 | .TP | |
3650 | \fB@(\fP\^\fIpattern-list\^\fP\fB)\fP | |
95732b49 | 3651 | Matches one of the given patterns |
cce855bc JA |
3652 | .TP |
3653 | \fB!(\fP\^\fIpattern-list\^\fP\fB)\fP | |
3654 | Matches anything except one of the given patterns | |
3655 | .RE | |
726f6388 JA |
3656 | .PD |
3657 | .SS Quote Removal | |
3658 | .PP | |
3659 | After the preceding expansions, all unquoted occurrences of the | |
3660 | characters | |
3661 | .BR \e , | |
0628567a | 3662 | .BR \(aq , |
ccc6cda3 JA |
3663 | and \^\f3"\fP\^ that did not result from one of the above |
3664 | expansions are removed. | |
726f6388 JA |
3665 | .SH REDIRECTION |
3666 | Before a command is executed, its input and output | |
3667 | may be | |
3668 | .I redirected | |
3669 | using a special notation interpreted by the shell. | |
ac50fbac CR |
3670 | Redirection allows commands' file handles to be |
3671 | duplicated, opened, closed, | |
3672 | made to refer to different files, | |
3673 | and can change the files the command reads from and writes to. | |
3674 | Redirection may also be used to modify file handles in the | |
3675 | current shell execution environment. | |
3676 | The following redirection | |
726f6388 JA |
3677 | operators may precede or appear anywhere within a |
3678 | .I simple command | |
3679 | or may follow a | |
3680 | .IR command . | |
3681 | Redirections are processed in the order they appear, from | |
3682 | left to right. | |
3683 | .PP | |
0001803f CR |
3684 | Each redirection that may be preceded by a file descriptor number |
3685 | may instead be preceded by a word of the form {\fIvarname\fP}. | |
3686 | In this case, for each redirection operator except | |
3687 | >&- and <&-, the shell will allocate a file descriptor greater | |
ac50fbac CR |
3688 | than or equal to 10 and assign it to \fIvarname\fP. |
3689 | If >&- or <&- is preceded | |
0001803f CR |
3690 | by {\fIvarname\fP}, the value of \fIvarname\fP defines the file |
3691 | descriptor to close. | |
3692 | .PP | |
726f6388 JA |
3693 | In the following descriptions, if the file descriptor number is |
3694 | omitted, and the first character of the redirection operator is | |
3695 | .BR < , | |
3696 | the redirection refers to the standard input (file descriptor | |
3697 | 0). If the first character of the redirection operator is | |
3698 | .BR > , | |
3699 | the redirection refers to the standard output (file descriptor | |
3700 | 1). | |
3701 | .PP | |
cce855bc | 3702 | The word following the redirection operator in the following |
ac50fbac CR |
3703 | descriptions, unless otherwise noted, is subjected to |
3704 | brace expansion, tilde expansion, parameter and variable expansion, | |
3705 | command substitution, arithmetic expansion, quote removal, | |
3706 | pathname expansion, and word splitting. | |
cce855bc | 3707 | If it expands to more than one word, |
726f6388 JA |
3708 | .B bash |
3709 | reports an error. | |
3710 | .PP | |
a0c0a00f | 3711 | Note that the order of redirections is significant. For example, |
726f6388 JA |
3712 | the command |
3713 | .RS | |
3714 | .PP | |
3715 | ls \fB>\fP dirlist 2\fB>&\fP1 | |
3716 | .RE | |
3717 | .PP | |
a0c0a00f | 3718 | directs both standard output and standard error to the file |
726f6388 JA |
3719 | .IR dirlist , |
3720 | while the command | |
3721 | .RS | |
3722 | .PP | |
3723 | ls 2\fB>&\fP1 \fB>\fP dirlist | |
3724 | .RE | |
3725 | .PP | |
3726 | directs only the standard output to file | |
3727 | .IR dirlist , | |
17345e5a | 3728 | because the standard error was duplicated from the standard output |
726f6388 JA |
3729 | before the standard output was redirected to |
3730 | .IR dirlist . | |
cce855bc | 3731 | .PP |
bb70624e | 3732 | \fBBash\fP handles several filenames specially when they are used in |
a0c0a00f CR |
3733 | redirections, as described in the following table. |
3734 | If the operating system on which \fBbash\fP is running provides these | |
3735 | special files, bash will use them; otherwise it will emulate them | |
3736 | internally with the behavior described below. | |
bb70624e JA |
3737 | .RS |
3738 | .PP | |
3739 | .PD 0 | |
3740 | .TP | |
3741 | .B /dev/fd/\fIfd\fP | |
3742 | If \fIfd\fP is a valid integer, file descriptor \fIfd\fP is duplicated. | |
3743 | .TP | |
3744 | .B /dev/stdin | |
3745 | File descriptor 0 is duplicated. | |
3746 | .TP | |
3747 | .B /dev/stdout | |
3748 | File descriptor 1 is duplicated. | |
3749 | .TP | |
3750 | .B /dev/stderr | |
3751 | File descriptor 2 is duplicated. | |
3752 | .TP | |
3753 | .B /dev/tcp/\fIhost\fP/\fIport\fP | |
3754 | If \fIhost\fP is a valid hostname or Internet address, and \fIport\fP | |
f73dda09 | 3755 | is an integer port number or service name, \fBbash\fP attempts to open |
ac50fbac | 3756 | the corresponding TCP socket. |
bb70624e JA |
3757 | .TP |
3758 | .B /dev/udp/\fIhost\fP/\fIport\fP | |
3759 | If \fIhost\fP is a valid hostname or Internet address, and \fIport\fP | |
f73dda09 | 3760 | is an integer port number or service name, \fBbash\fP attempts to open |
ac50fbac | 3761 | the corresponding UDP socket. |
bb70624e JA |
3762 | .PD |
3763 | .RE | |
3764 | .PP | |
cce855bc | 3765 | A failure to open or create a file causes the redirection to fail. |
95732b49 JA |
3766 | .PP |
3767 | Redirections using file descriptors greater than 9 should be used with | |
3768 | care, as they may conflict with file descriptors the shell uses | |
3769 | internally. | |
726f6388 JA |
3770 | .SS Redirecting Input |
3771 | .PP | |
3772 | Redirection of input causes the file whose name results from | |
3773 | the expansion of | |
3774 | .I word | |
3775 | to be opened for reading on file descriptor | |
3776 | .IR n , | |
3777 | or the standard input (file descriptor 0) if | |
3778 | .I n | |
3779 | is not specified. | |
3780 | .PP | |
3781 | The general format for redirecting input is: | |
3782 | .RS | |
3783 | .PP | |
3784 | [\fIn\fP]\fB<\fP\fIword\fP | |
3785 | .RE | |
3786 | .SS Redirecting Output | |
3787 | .PP | |
3788 | Redirection of output causes the file whose name results from | |
3789 | the expansion of | |
3790 | .I word | |
3791 | to be opened for writing on file descriptor | |
3792 | .IR n , | |
3793 | or the standard output (file descriptor 1) if | |
3794 | .I n | |
3795 | is not specified. If the file does not exist it is created; | |
3796 | if it does exist it is truncated to zero size. | |
3797 | .PP | |
3798 | The general format for redirecting output is: | |
3799 | .RS | |
3800 | .PP | |
3801 | [\fIn\fP]\fB>\fP\fIword\fP | |
3802 | .RE | |
3803 | .PP | |
3804 | If the redirection operator is | |
ccc6cda3 JA |
3805 | .BR > , |
3806 | and the | |
cce855bc | 3807 | .B noclobber |
ccc6cda3 JA |
3808 | option to the |
3809 | .B set | |
bb70624e | 3810 | builtin has been enabled, the redirection will fail if the file |
cce855bc JA |
3811 | whose name results from the expansion of \fIword\fP exists and is |
3812 | a regular file. | |
ccc6cda3 | 3813 | If the redirection operator is |
726f6388 | 3814 | .BR >| , |
cce855bc JA |
3815 | or the redirection operator is |
3816 | .B > | |
3817 | and the | |
3818 | .B noclobber | |
726f6388 JA |
3819 | option to the |
3820 | .B set | |
cce855bc | 3821 | builtin command is not enabled, the redirection is attempted even |
ccc6cda3 | 3822 | if the file named by \fIword\fP exists. |
726f6388 JA |
3823 | .SS Appending Redirected Output |
3824 | .PP | |
3825 | Redirection of output in this fashion | |
3826 | causes the file whose name results from | |
3827 | the expansion of | |
3828 | .I word | |
3829 | to be opened for appending on file descriptor | |
3830 | .IR n , | |
3831 | or the standard output (file descriptor 1) if | |
3832 | .I n | |
3833 | is not specified. If the file does not exist it is created. | |
3834 | .PP | |
3835 | The general format for appending output is: | |
3836 | .RS | |
3837 | .PP | |
3838 | [\fIn\fP]\fB>>\fP\fIword\fP | |
3839 | .RE | |
3840 | .PP | |
3841 | .SS Redirecting Standard Output and Standard Error | |
3842 | .PP | |
3185942a | 3843 | This construct allows both the |
726f6388 JA |
3844 | standard output (file descriptor 1) and |
3845 | the standard error output (file descriptor 2) | |
3846 | to be redirected to the file whose name is the | |
3847 | expansion of | |
3185942a | 3848 | .IR word . |
726f6388 JA |
3849 | .PP |
3850 | There are two formats for redirecting standard output and | |
3851 | standard error: | |
3852 | .RS | |
3853 | .PP | |
3854 | \fB&>\fP\fIword\fP | |
3855 | .RE | |
3856 | and | |
3857 | .RS | |
3858 | \fB>&\fP\fIword\fP | |
3859 | .RE | |
3860 | .PP | |
3861 | Of the two forms, the first is preferred. | |
3862 | This is semantically equivalent to | |
3863 | .RS | |
3864 | .PP | |
3865 | \fB>\fP\fIword\fP 2\fB>&\fP1 | |
3866 | .RE | |
3185942a | 3867 | .PP |
ac50fbac CR |
3868 | When using the second form, \fIword\fP may not expand to a number or |
3869 | \fB\-\fP. If it does, other redirection operators apply | |
3870 | (see \fBDuplicating File Descriptors\fP below) for compatibility | |
3871 | reasons. | |
3185942a JA |
3872 | .SS Appending Standard Output and Standard Error |
3873 | .PP | |
3874 | This construct allows both the | |
3875 | standard output (file descriptor 1) and | |
3876 | the standard error output (file descriptor 2) | |
3877 | to be appended to the file whose name is the | |
3878 | expansion of | |
3879 | .IR word . | |
3880 | .PP | |
3881 | The format for appending standard output and standard error is: | |
3882 | .RS | |
3883 | .PP | |
3884 | \fB&>>\fP\fIword\fP | |
3885 | .RE | |
3886 | .PP | |
3887 | This is semantically equivalent to | |
3888 | .RS | |
3889 | .PP | |
3890 | \fB>>\fP\fIword\fP 2\fB>&\fP1 | |
3891 | .RE | |
ac50fbac CR |
3892 | .PP |
3893 | (see \fBDuplicating File Descriptors\fP below). | |
726f6388 JA |
3894 | .SS Here Documents |
3895 | .PP | |
3896 | This type of redirection instructs the shell to read input from the | |
3897 | current source until a line containing only | |
3185942a | 3898 | .I delimiter |
726f6388 JA |
3899 | (with no trailing blanks) |
3900 | is seen. All of | |
3901 | the lines read up to that point are then used as the standard | |
a0c0a00f | 3902 | input (or file descriptor \fIn\fP if \fIn\fP is specified) for a command. |
726f6388 | 3903 | .PP |
7117c2d2 | 3904 | The format of here-documents is: |
726f6388 JA |
3905 | .RS |
3906 | .PP | |
3907 | .nf | |
a0c0a00f | 3908 | [\fIn\fP]\fB<<\fP[\fB\-\fP]\fIword\fP |
f73dda09 | 3909 | \fIhere-document\fP |
726f6388 JA |
3910 | \fIdelimiter\fP |
3911 | .fi | |
3912 | .RE | |
3913 | .PP | |
ac50fbac CR |
3914 | No parameter and variable expansion, command substitution, |
3915 | arithmetic expansion, or pathname expansion is performed on | |
726f6388 | 3916 | .IR word . |
a0c0a00f | 3917 | If any part of |
726f6388 | 3918 | .I word |
a0c0a00f | 3919 | is quoted, the |
726f6388 JA |
3920 | .I delimiter |
3921 | is the result of quote removal on | |
3922 | .IR word , | |
cce855bc JA |
3923 | and the lines in the here-document are not expanded. |
3924 | If \fIword\fP is unquoted, | |
ac50fbac CR |
3925 | all lines of the here-document are subjected to |
3926 | parameter expansion, command substitution, and arithmetic expansion, | |
3927 | the character sequence | |
726f6388 JA |
3928 | .B \e<newline> |
3929 | is ignored, and | |
3930 | .B \e | |
3931 | must be used to quote the characters | |
3932 | .BR \e , | |
3933 | .BR $ , | |
3934 | and | |
3185942a | 3935 | .BR \` . |
726f6388 JA |
3936 | .PP |
3937 | If the redirection operator is | |
3938 | .BR <<\- , | |
3939 | then all leading tab characters are stripped from input lines and the | |
3940 | line containing | |
3941 | .IR delimiter . | |
3942 | This allows | |
3943 | here-documents within shell scripts to be indented in a | |
3944 | natural fashion. | |
7117c2d2 JA |
3945 | .SS "Here Strings" |
3946 | A variant of here documents, the format is: | |
3947 | .RS | |
3948 | .PP | |
3949 | .nf | |
a0c0a00f | 3950 | [\fIn\fP]\fB<<<\fP\fIword\fP |
7117c2d2 JA |
3951 | .fi |
3952 | .RE | |
3953 | .PP | |
ac50fbac CR |
3954 | The \fIword\fP undergoes |
3955 | brace expansion, tilde expansion, parameter and variable expansion, | |
3956 | command substitution, arithmetic expansion, and quote removal. | |
3957 | Pathname expansion and word splitting are not performed. | |
a0c0a00f CR |
3958 | The result is supplied as a single string, with a newline appended, |
3959 | to the command on its | |
3960 | standard input (or file descriptor \fIn\fP if \fIn\fP is specified). | |
726f6388 JA |
3961 | .SS "Duplicating File Descriptors" |
3962 | .PP | |
3963 | The redirection operator | |
3964 | .RS | |
3965 | .PP | |
3966 | [\fIn\fP]\fB<&\fP\fIword\fP | |
3967 | .RE | |
3968 | .PP | |
3969 | is used to duplicate input file descriptors. | |
3970 | If | |
3971 | .I word | |
3972 | expands to one or more digits, the file descriptor denoted by | |
3973 | .I n | |
cce855bc JA |
3974 | is made to be a copy of that file descriptor. |
3975 | If the digits in | |
3976 | .I word | |
3977 | do not specify a file descriptor open for input, a redirection error occurs. | |
3978 | If | |
726f6388 JA |
3979 | .I word |
3980 | evaluates to | |
3981 | .BR \- , | |
3982 | file descriptor | |
3983 | .I n | |
3984 | is closed. If | |
3985 | .I n | |
3986 | is not specified, the standard input (file descriptor 0) is used. | |
3987 | .PP | |
3988 | The operator | |
3989 | .RS | |
3990 | .PP | |
3991 | [\fIn\fP]\fB>&\fP\fIword\fP | |
3992 | .RE | |
3993 | .PP | |
3994 | is used similarly to duplicate output file descriptors. If | |
3995 | .I n | |
3996 | is not specified, the standard output (file descriptor 1) is used. | |
cce855bc JA |
3997 | If the digits in |
3998 | .I word | |
3999 | do not specify a file descriptor open for output, a redirection error occurs. | |
ac50fbac CR |
4000 | If |
4001 | .I word | |
4002 | evaluates to | |
4003 | .BR \- , | |
4004 | file descriptor | |
4005 | .I n | |
4006 | is closed. | |
726f6388 | 4007 | As a special case, if \fIn\fP is omitted, and \fIword\fP does not |
ac50fbac | 4008 | expand to one or more digits or \fB\-\fP, the standard output and standard |
726f6388 | 4009 | error are redirected as described previously. |
7117c2d2 JA |
4010 | .SS "Moving File Descriptors" |
4011 | .PP | |
4012 | The redirection operator | |
4013 | .RS | |
4014 | .PP | |
4015 | [\fIn\fP]\fB<&\fP\fIdigit\fP\fB\-\fP | |
4016 | .RE | |
4017 | .PP | |
4018 | moves the file descriptor \fIdigit\fP to file descriptor | |
4019 | .IR n , | |
4020 | or the standard input (file descriptor 0) if \fIn\fP is not specified. | |
4021 | \fIdigit\fP is closed after being duplicated to \fIn\fP. | |
4022 | .PP | |
4023 | Similarly, the redirection operator | |
4024 | .RS | |
4025 | .PP | |
4026 | [\fIn\fP]\fB>&\fP\fIdigit\fP\fB\-\fP | |
4027 | .RE | |
4028 | .PP | |
4029 | moves the file descriptor \fIdigit\fP to file descriptor | |
4030 | .IR n , | |
4031 | or the standard output (file descriptor 1) if \fIn\fP is not specified. | |
726f6388 JA |
4032 | .SS "Opening File Descriptors for Reading and Writing" |
4033 | .PP | |
4034 | The redirection operator | |
4035 | .RS | |
4036 | .PP | |
4037 | [\fIn\fP]\fB<>\fP\fIword\fP | |
4038 | .RE | |
4039 | .PP | |
4040 | causes the file whose name is the expansion of | |
4041 | .I word | |
4042 | to be opened for both reading and writing on file descriptor | |
4043 | .IR n , | |
ccc6cda3 | 4044 | or on file descriptor 0 if |
726f6388 JA |
4045 | .I n |
4046 | is not specified. If the file does not exist, it is created. | |
726f6388 | 4047 | .SH ALIASES |
bb70624e | 4048 | \fIAliases\fP allow a string to be substituted for a word when it is used |
cce855bc | 4049 | as the first word of a simple command. |
bb70624e | 4050 | The shell maintains a list of aliases that may be set and unset with the |
726f6388 JA |
4051 | .B alias |
4052 | and | |
4053 | .B unalias | |
4054 | builtin commands (see | |
4055 | .SM | |
4056 | .B SHELL BUILTIN COMMANDS | |
4057 | below). | |
b80f6443 | 4058 | The first word of each simple command, if unquoted, |
726f6388 JA |
4059 | is checked to see if it has an |
4060 | alias. If so, that word is replaced by the text of the alias. | |
3185942a | 4061 | The characters \fB/\fP, \fB$\fP, \fB\`\fP, and \fB=\fP and |
b80f6443 JA |
4062 | any of the shell \fImetacharacters\fP or quoting characters |
4063 | listed above may not appear in an alias name. | |
4064 | The replacement text may contain any valid shell input, | |
4065 | including shell metacharacters. | |
4066 | The first word of the replacement text is tested | |
726f6388 | 4067 | for aliases, but a word that is identical to an alias being expanded |
b80f6443 JA |
4068 | is not expanded a second time. |
4069 | This means that one may alias | |
726f6388 JA |
4070 | .B ls |
4071 | to | |
4072 | .BR "ls \-F" , | |
4073 | for instance, and | |
4074 | .B bash | |
4075 | does not try to recursively expand the replacement text. | |
4076 | If the last character of the alias value is a | |
4077 | .IR blank , | |
4078 | then the next command | |
4079 | word following the alias is also checked for alias expansion. | |
4080 | .PP | |
4081 | Aliases are created and listed with the | |
4082 | .B alias | |
4083 | command, and removed with the | |
4084 | .B unalias | |
4085 | command. | |
4086 | .PP | |
ccc6cda3 | 4087 | There is no mechanism for using arguments in the replacement text. |
bb70624e JA |
4088 | If arguments are needed, a shell function should be used (see |
4089 | .SM | |
4090 | .B FUNCTIONS | |
4091 | below). | |
726f6388 | 4092 | .PP |
ccc6cda3 JA |
4093 | Aliases are not expanded when the shell is not interactive, unless |
4094 | the | |
4095 | .B expand_aliases | |
4096 | shell option is set using | |
4097 | .B shopt | |
4098 | (see the description of | |
4099 | .B shopt | |
4100 | under | |
4101 | .SM | |
4102 | \fBSHELL BUILTIN COMMANDS\fP | |
4103 | below). | |
726f6388 JA |
4104 | .PP |
4105 | The rules concerning the definition and use of aliases are | |
4106 | somewhat confusing. | |
4107 | .B Bash | |
4108 | always reads at least one complete line | |
4109 | of input before executing any | |
4110 | of the commands on that line. Aliases are expanded when a | |
4111 | command is read, not when it is executed. Therefore, an | |
4112 | alias definition appearing on the same line as another | |
4113 | command does not take effect until the next line of input is read. | |
ccc6cda3 | 4114 | The commands following the alias definition |
726f6388 JA |
4115 | on that line are not affected by the new alias. |
4116 | This behavior is also an issue when functions are executed. | |
cce855bc | 4117 | Aliases are expanded when a function definition is read, |
726f6388 | 4118 | not when the function is executed, because a function definition |
a0c0a00f | 4119 | is itself a command. As a consequence, aliases |
726f6388 JA |
4120 | defined in a function are not available until after that |
4121 | function is executed. To be safe, always put | |
4122 | alias definitions on a separate line, and do not use | |
4123 | .B alias | |
4124 | in compound commands. | |
4125 | .PP | |
cce855bc | 4126 | For almost every purpose, aliases are superseded by |
726f6388 | 4127 | shell functions. |
ccc6cda3 JA |
4128 | .SH FUNCTIONS |
4129 | A shell function, defined as described above under | |
4130 | .SM | |
4131 | .BR "SHELL GRAMMAR" , | |
4132 | stores a series of commands for later execution. | |
bb70624e JA |
4133 | When the name of a shell function is used as a simple command name, |
4134 | the list of commands associated with that function name is executed. | |
ccc6cda3 JA |
4135 | Functions are executed in the context of the |
4136 | current shell; no new process is created to interpret | |
4137 | them (contrast this with the execution of a shell script). | |
4138 | When a function is executed, the arguments to the | |
4139 | function become the positional parameters | |
bb70624e JA |
4140 | during its execution. |
4141 | The special parameter | |
ccc6cda3 | 4142 | .B # |
495aee44 | 4143 | is updated to reflect the change. Special parameter \fB0\fP |
bb70624e | 4144 | is unchanged. |
b80f6443 | 4145 | The first element of the |
bb70624e JA |
4146 | .SM |
4147 | .B FUNCNAME | |
4148 | variable is set to the name of the function while the function | |
4149 | is executing. | |
0001803f | 4150 | .PP |
bb70624e | 4151 | All other aspects of the shell execution |
ccc6cda3 | 4152 | environment are identical between a function and its caller |
a0c0a00f | 4153 | with these exceptions: the |
ccc6cda3 JA |
4154 | .SM |
4155 | .B DEBUG | |
95732b49 JA |
4156 | and |
4157 | .B RETURN | |
4158 | traps (see the description of the | |
ccc6cda3 JA |
4159 | .B trap |
4160 | builtin under | |
4161 | .SM | |
4162 | .B SHELL BUILTIN COMMANDS | |
95732b49 | 4163 | below) are not inherited unless the function has been given the |
7117c2d2 JA |
4164 | \fBtrace\fP attribute (see the description of the |
4165 | .SM | |
4166 | .B declare | |
b80f6443 JA |
4167 | builtin below) or the |
4168 | \fB\-o functrace\fP shell option has been enabled with | |
4169 | the \fBset\fP builtin | |
0001803f CR |
4170 | (in which case all functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps), |
4171 | and the | |
4172 | .SM | |
4173 | .B ERR | |
4174 | trap is not inherited unless the \fB\-o errtrace\fP shell option has | |
4175 | been enabled. | |
726f6388 | 4176 | .PP |
ccc6cda3 JA |
4177 | Variables local to the function may be declared with the |
4178 | .B local | |
4179 | builtin command. Ordinarily, variables and their values | |
4180 | are shared between the function and its caller. | |
726f6388 | 4181 | .PP |
495aee44 CR |
4182 | The \fBFUNCNEST\fP variable, if set to a numeric value greater |
4183 | than 0, defines a maximum function nesting level. Function | |
4184 | invocations that exceed the limit cause the entire command to | |
4185 | abort. | |
4186 | .PP | |
ccc6cda3 JA |
4187 | If the builtin command |
4188 | .B return | |
4189 | is executed in a function, the function completes and | |
4190 | execution resumes with the next command after the function | |
b80f6443 JA |
4191 | call. |
4192 | Any command associated with the \fBRETURN\fP trap is executed | |
4193 | before execution resumes. | |
4194 | When a function completes, the values of the | |
ccc6cda3 JA |
4195 | positional parameters and the special parameter |
4196 | .B # | |
cce855bc | 4197 | are restored to the values they had prior to the function's |
ccc6cda3 | 4198 | execution. |
726f6388 | 4199 | .PP |
ccc6cda3 JA |
4200 | Function names and definitions may be listed with the |
4201 | .B \-f | |
726f6388 | 4202 | option to the |
ccc6cda3 JA |
4203 | .B declare |
4204 | or | |
4205 | .B typeset | |
4206 | builtin commands. The | |
4207 | .B \-F | |
4208 | option to | |
4209 | .B declare | |
4210 | or | |
4211 | .B typeset | |
b80f6443 JA |
4212 | will list the function names only |
4213 | (and optionally the source file and line number, if the \fBextdebug\fP | |
4214 | shell option is enabled). | |
ccc6cda3 JA |
4215 | Functions may be exported so that subshells |
4216 | automatically have them defined with the | |
4217 | .B \-f | |
4218 | option to the | |
4219 | .B export | |
4220 | builtin. | |
0628567a JA |
4221 | A function definition may be deleted using the \fB\-f\fP option to |
4222 | the | |
4223 | .B unset | |
4224 | builtin. | |
b80f6443 JA |
4225 | Note that shell functions and variables with the same name may result |
4226 | in multiple identically-named entries in the environment passed to the | |
4227 | shell's children. | |
4228 | Care should be taken in cases where this may cause a problem. | |
726f6388 | 4229 | .PP |
495aee44 CR |
4230 | Functions may be recursive. |
4231 | The \fBFUNCNEST\fP variable may be used to limit the depth of the | |
4232 | function call stack and restrict the number of function invocations. | |
4233 | By default, no limit is imposed on the number of recursive calls. | |
cce855bc JA |
4234 | .SH "ARITHMETIC EVALUATION" |
4235 | The shell allows arithmetic expressions to be evaluated, under | |
b80f6443 | 4236 | certain circumstances (see the \fBlet\fP and \fBdeclare\fP builtin |
a0c0a00f | 4237 | commands, the \fB((\fP compound command, and \fBArithmetic Expansion\fP). |
7117c2d2 | 4238 | Evaluation is done in fixed-width integers with no check for overflow, |
cce855bc | 4239 | though division by 0 is trapped and flagged as an error. |
b80f6443 JA |
4240 | The operators and their precedence, associativity, and values |
4241 | are the same as in the C language. | |
cce855bc JA |
4242 | The following list of operators is grouped into levels of |
4243 | equal-precedence operators. | |
4244 | The levels are listed in order of decreasing precedence. | |
726f6388 | 4245 | .PP |
cce855bc JA |
4246 | .PD 0 |
4247 | .TP | |
bb70624e JA |
4248 | .B \fIid\fP++ \fIid\fP\-\- |
4249 | variable post-increment and post-decrement | |
4250 | .TP | |
4251 | .B ++\fIid\fP \-\-\fIid\fP | |
4252 | variable pre-increment and pre-decrement | |
4253 | .TP | |
cce855bc JA |
4254 | .B \- + |
4255 | unary minus and plus | |
4256 | .TP | |
4257 | .B ! ~ | |
4258 | logical and bitwise negation | |
4259 | .TP | |
4260 | .B ** | |
4261 | exponentiation | |
4262 | .TP | |
4263 | .B * / % | |
4264 | multiplication, division, remainder | |
4265 | .TP | |
4266 | .B + \- | |
4267 | addition, subtraction | |
4268 | .TP | |
4269 | .B << >> | |
4270 | left and right bitwise shifts | |
4271 | .TP | |
4272 | .B <= >= < > | |
4273 | comparison | |
4274 | .TP | |
4275 | .B == != | |
4276 | equality and inequality | |
4277 | .TP | |
4278 | .B & | |
4279 | bitwise AND | |
4280 | .TP | |
4281 | .B ^ | |
4282 | bitwise exclusive OR | |
4283 | .TP | |
4284 | .B | | |
4285 | bitwise OR | |
4286 | .TP | |
4287 | .B && | |
4288 | logical AND | |
4289 | .TP | |
4290 | .B || | |
4291 | logical OR | |
4292 | .TP | |
4293 | .B \fIexpr\fP?\fIexpr\fP:\fIexpr\fP | |
b80f6443 | 4294 | conditional operator |
cce855bc JA |
4295 | .TP |
4296 | .B = *= /= %= += \-= <<= >>= &= ^= |= | |
4297 | assignment | |
bb70624e JA |
4298 | .TP |
4299 | .B \fIexpr1\fP , \fIexpr2\fP | |
4300 | comma | |
cce855bc | 4301 | .PD |
ccc6cda3 | 4302 | .PP |
cce855bc | 4303 | Shell variables are allowed as operands; parameter expansion is |
bb70624e JA |
4304 | performed before the expression is evaluated. |
4305 | Within an expression, shell variables may also be referenced by name | |
4306 | without using the parameter expansion syntax. | |
b80f6443 JA |
4307 | A shell variable that is null or unset evaluates to 0 when referenced |
4308 | by name without using the parameter expansion syntax. | |
bb70624e | 4309 | The value of a variable is evaluated as an arithmetic expression |
b80f6443 JA |
4310 | when it is referenced, or when a variable which has been given the |
4311 | \fIinteger\fP attribute using \fBdeclare -i\fP is assigned a value. | |
4312 | A null value evaluates to 0. | |
495aee44 | 4313 | A shell variable need not have its \fIinteger\fP attribute |
cce855bc | 4314 | turned on to be used in an expression. |
ccc6cda3 | 4315 | .PP |
cce855bc JA |
4316 | Constants with a leading 0 are interpreted as octal numbers. |
4317 | A leading 0x or 0X denotes hexadecimal. | |
495aee44 | 4318 | Otherwise, numbers take the form [\fIbase#\fP]n, where the optional \fIbase\fP |
cce855bc JA |
4319 | is a decimal number between 2 and 64 representing the arithmetic |
4320 | base, and \fIn\fP is a number in that base. | |
bb70624e | 4321 | If \fIbase#\fP is omitted, then base 10 is used. |
ac50fbac | 4322 | When specifying \fIn\fP, |
a0c0a00f | 4323 | the digits greater than 9 are represented by the lowercase letters, |
f73dda09 | 4324 | the uppercase letters, @, and _, in that order. |
cce855bc | 4325 | If \fIbase\fP is less than or equal to 36, lowercase and uppercase |
95732b49 | 4326 | letters may be used interchangeably to represent numbers between 10 |
cce855bc | 4327 | and 35. |
ccc6cda3 | 4328 | .PP |
cce855bc JA |
4329 | Operators are evaluated in order of precedence. Sub-expressions in |
4330 | parentheses are evaluated first and may override the precedence | |
4331 | rules above. | |
4332 | .SH "CONDITIONAL EXPRESSIONS" | |
4333 | Conditional expressions are used by the \fB[[\fP compound command and | |
4334 | the \fBtest\fP and \fB[\fP builtin commands to test file attributes | |
4335 | and perform string and arithmetic comparisons. | |
4336 | Expressions are formed from the following unary or binary primaries. | |
a0c0a00f CR |
4337 | \fBBash\fP handles several filenames specially when they are used in |
4338 | expressions. | |
4339 | If the operating system on which \fBbash\fP is running provides these | |
4340 | special files, bash will use them; otherwise it will emulate them | |
4341 | internally with this behavior: | |
cce855bc | 4342 | If any \fIfile\fP argument to one of the primaries is of the form |
bb70624e JA |
4343 | \fI/dev/fd/n\fP, then file descriptor \fIn\fP is checked. |
4344 | If the \fIfile\fP argument to one of the primaries is one of | |
4345 | \fI/dev/stdin\fP, \fI/dev/stdout\fP, or \fI/dev/stderr\fP, file | |
4346 | descriptor 0, 1, or 2, respectively, is checked. | |
95732b49 JA |
4347 | .PP |
4348 | Unless otherwise specified, primaries that operate on files follow symbolic | |
4349 | links and operate on the target of the link, rather than the link itself. | |
0001803f CR |
4350 | .if t .sp 0.5 |
4351 | .if n .sp 1 | |
495aee44 | 4352 | When used with \fB[[\fP, the \fB<\fP and \fB>\fP operators sort |
0001803f | 4353 | lexicographically using the current locale. |
495aee44 | 4354 | The \fBtest\fP command sorts using ASCII ordering. |
cce855bc JA |
4355 | .sp 1 |
4356 | .PD 0 | |
4357 | .TP | |
4358 | .B \-a \fIfile\fP | |
4359 | True if \fIfile\fP exists. | |
4360 | .TP | |
4361 | .B \-b \fIfile\fP | |
4362 | True if \fIfile\fP exists and is a block special file. | |
4363 | .TP | |
4364 | .B \-c \fIfile\fP | |
4365 | True if \fIfile\fP exists and is a character special file. | |
4366 | .TP | |
4367 | .B \-d \fIfile\fP | |
4368 | True if \fIfile\fP exists and is a directory. | |
4369 | .TP | |
4370 | .B \-e \fIfile\fP | |
4371 | True if \fIfile\fP exists. | |
4372 | .TP | |
4373 | .B \-f \fIfile\fP | |
4374 | True if \fIfile\fP exists and is a regular file. | |
4375 | .TP | |
4376 | .B \-g \fIfile\fP | |
4377 | True if \fIfile\fP exists and is set-group-id. | |
4378 | .TP | |
b72432fd JA |
4379 | .B \-h \fIfile\fP |
4380 | True if \fIfile\fP exists and is a symbolic link. | |
4381 | .TP | |
cce855bc JA |
4382 | .B \-k \fIfile\fP |
4383 | True if \fIfile\fP exists and its ``sticky'' bit is set. | |
4384 | .TP | |
4385 | .B \-p \fIfile\fP | |
4386 | True if \fIfile\fP exists and is a named pipe (FIFO). | |
4387 | .TP | |
4388 | .B \-r \fIfile\fP | |
4389 | True if \fIfile\fP exists and is readable. | |
4390 | .TP | |
4391 | .B \-s \fIfile\fP | |
4392 | True if \fIfile\fP exists and has a size greater than zero. | |
4393 | .TP | |
4394 | .B \-t \fIfd\fP | |
4395 | True if file descriptor | |
4396 | .I fd | |
4397 | is open and refers to a terminal. | |
4398 | .TP | |
4399 | .B \-u \fIfile\fP | |
4400 | True if \fIfile\fP exists and its set-user-id bit is set. | |
4401 | .TP | |
4402 | .B \-w \fIfile\fP | |
4403 | True if \fIfile\fP exists and is writable. | |
4404 | .TP | |
4405 | .B \-x \fIfile\fP | |
4406 | True if \fIfile\fP exists and is executable. | |
4407 | .TP | |
cce855bc JA |
4408 | .B \-G \fIfile\fP |
4409 | True if \fIfile\fP exists and is owned by the effective group id. | |
4410 | .TP | |
4411 | .B \-L \fIfile\fP | |
4412 | True if \fIfile\fP exists and is a symbolic link. | |
4413 | .TP | |
495aee44 CR |
4414 | .B \-N \fIfile\fP |
4415 | True if \fIfile\fP exists and has been modified since it was last read. | |
4416 | .TP | |
4417 | .B \-O \fIfile\fP | |
4418 | True if \fIfile\fP exists and is owned by the effective user id. | |
4419 | .TP | |
cce855bc JA |
4420 | .B \-S \fIfile\fP |
4421 | True if \fIfile\fP exists and is a socket. | |
4422 | .TP | |
495aee44 CR |
4423 | \fIfile1\fP \fB\-ef\fP \fIfile2\fP |
4424 | True if \fIfile1\fP and \fIfile2\fP refer to the same device and | |
4425 | inode numbers. | |
cce855bc JA |
4426 | .TP |
4427 | \fIfile1\fP \-\fBnt\fP \fIfile2\fP | |
7117c2d2 JA |
4428 | True if \fIfile1\fP is newer (according to modification date) than \fIfile2\fP, |
4429 | or if \fIfile1\fP exists and \fPfile2\fP does not. | |
cce855bc JA |
4430 | .TP |
4431 | \fIfile1\fP \-\fBot\fP \fIfile2\fP | |
7117c2d2 JA |
4432 | True if \fIfile1\fP is older than \fIfile2\fP, or if \fIfile2\fP exists |
4433 | and \fIfile1\fP does not. | |
cce855bc | 4434 | .TP |
cce855bc | 4435 | .B \-o \fIoptname\fP |
495aee44 | 4436 | True if the shell option |
cce855bc JA |
4437 | .I optname |
4438 | is enabled. | |
4439 | See the list of options under the description of the | |
4440 | .B \-o | |
4441 | option to the | |
4442 | .B set | |
4443 | builtin below. | |
4444 | .TP | |
495aee44 CR |
4445 | .B \-v \fIvarname\fP |
4446 | True if the shell variable | |
4447 | .I varname | |
4448 | is set (has been assigned a value). | |
4449 | .TP | |
ac50fbac CR |
4450 | .B \-R \fIvarname\fP |
4451 | True if the shell variable | |
4452 | .I varname | |
4453 | is set and is a name reference. | |
4454 | .TP | |
cce855bc JA |
4455 | .B \-z \fIstring\fP |
4456 | True if the length of \fIstring\fP is zero. | |
4457 | .TP | |
cce855bc | 4458 | \fIstring\fP |
b80f6443 JA |
4459 | .PD 0 |
4460 | .TP | |
4461 | .B \-n \fIstring\fP | |
4462 | .PD | |
cce855bc JA |
4463 | True if the length of |
4464 | .I string | |
4465 | is non-zero. | |
4466 | .TP | |
4467 | \fIstring1\fP \fB==\fP \fIstring2\fP | |
0001803f CR |
4468 | .PD 0 |
4469 | .TP | |
4470 | \fIstring1\fP \fB=\fP \fIstring2\fP | |
4471 | .PD | |
4472 | True if the strings are equal. \fB=\fP should be used | |
4473 | with the \fBtest\fP command for POSIX conformance. | |
ac50fbac CR |
4474 | When used with the \fB[[\fP command, this performs pattern matching as |
4475 | described above (\fBCompound Commands\fP). | |
cce855bc JA |
4476 | .TP |
4477 | \fIstring1\fP \fB!=\fP \fIstring2\fP | |
4478 | True if the strings are not equal. | |
4479 | .TP | |
4480 | \fIstring1\fP \fB<\fP \fIstring2\fP | |
0001803f | 4481 | True if \fIstring1\fP sorts before \fIstring2\fP lexicographically. |
cce855bc JA |
4482 | .TP |
4483 | \fIstring1\fP \fB>\fP \fIstring2\fP | |
0001803f | 4484 | True if \fIstring1\fP sorts after \fIstring2\fP lexicographically. |
cce855bc JA |
4485 | .TP |
4486 | .I \fIarg1\fP \fBOP\fP \fIarg2\fP | |
4487 | .SM | |
4488 | .B OP | |
4489 | is one of | |
4490 | .BR \-eq , | |
4491 | .BR \-ne , | |
4492 | .BR \-lt , | |
4493 | .BR \-le , | |
4494 | .BR \-gt , | |
4495 | or | |
4496 | .BR \-ge . | |
4497 | These arithmetic binary operators return true if \fIarg1\fP | |
4498 | is equal to, not equal to, less than, less than or equal to, | |
4499 | greater than, or greater than or equal to \fIarg2\fP, respectively. | |
4500 | .I Arg1 | |
4501 | and | |
4502 | .I arg2 | |
4503 | may be positive or negative integers. | |
4504 | .PD | |
4505 | .SH "SIMPLE COMMAND EXPANSION" | |
4506 | When a simple command is executed, the shell performs the following | |
4507 | expansions, assignments, and redirections, from left to right. | |
4508 | .IP 1. | |
4509 | The words that the parser has marked as variable assignments (those | |
4510 | preceding the command name) and redirections are saved for later | |
4511 | processing. | |
4512 | .IP 2. | |
4513 | The words that are not variable assignments or redirections are | |
4514 | expanded. If any words remain after expansion, the first word | |
4515 | is taken to be the name of the command and the remaining words are | |
4516 | the arguments. | |
4517 | .IP 3. | |
4518 | Redirections are performed as described above under | |
4519 | .SM | |
4520 | .BR REDIRECTION . | |
4521 | .IP 4. | |
4522 | The text after the \fB=\fP in each variable assignment undergoes tilde | |
4523 | expansion, parameter expansion, command substitution, arithmetic expansion, | |
4524 | and quote removal before being assigned to the variable. | |
4525 | .PP | |
4526 | If no command name results, the variable assignments affect the current | |
4527 | shell environment. Otherwise, the variables are added to the environment | |
4528 | of the executed command and do not affect the current shell environment. | |
4529 | If any of the assignments attempts to assign a value to a readonly variable, | |
4530 | an error occurs, and the command exits with a non-zero status. | |
4531 | .PP | |
4532 | If no command name results, redirections are performed, but do not | |
4533 | affect the current shell environment. A redirection error causes the | |
4534 | command to exit with a non-zero status. | |
4535 | .PP | |
4536 | If there is a command name left after expansion, execution proceeds as | |
4537 | described below. Otherwise, the command exits. If one of the expansions | |
4538 | contained a command substitution, the exit status of the command is | |
4539 | the exit status of the last command substitution performed. If there | |
4540 | were no command substitutions, the command exits with a status of zero. | |
4541 | .SH "COMMAND EXECUTION" | |
4542 | After a command has been split into words, if it results in a | |
4543 | simple command and an optional list of arguments, the following | |
4544 | actions are taken. | |
4545 | .PP | |
4546 | If the command name contains no slashes, the shell attempts to | |
4547 | locate it. If there exists a shell function by that name, that | |
4548 | function is invoked as described above in | |
4549 | .SM | |
4550 | .BR FUNCTIONS . | |
4551 | If the name does not match a function, the shell searches for | |
4552 | it in the list of shell builtins. If a match is found, that | |
4553 | builtin is invoked. | |
4554 | .PP | |
4555 | If the name is neither a shell function nor a builtin, | |
4556 | and contains no slashes, | |
4557 | .B bash | |
4558 | searches each element of the | |
4559 | .SM | |
4560 | .B PATH | |
4561 | for a directory containing an executable file by that name. | |
4562 | .B Bash | |
bb70624e | 4563 | uses a hash table to remember the full pathnames of executable |
cce855bc JA |
4564 | files (see |
4565 | .B hash | |
4566 | under | |
4567 | .SM | |
4568 | .B "SHELL BUILTIN COMMANDS" | |
4569 | below). | |
4570 | A full search of the directories in | |
4571 | .SM | |
4572 | .B PATH | |
4573 | is performed only if the command is not found in the hash table. | |
3185942a JA |
4574 | If the search is unsuccessful, the shell searches for a defined shell |
4575 | function named \fBcommand_not_found_handle\fP. | |
4576 | If that function exists, it is invoked with the original command and | |
4577 | the original command's arguments as its arguments, and the function's | |
4578 | exit status becomes the exit status of the shell. | |
4579 | If that function is not defined, the shell prints an error | |
cce855bc JA |
4580 | message and returns an exit status of 127. |
4581 | .PP | |
4582 | If the search is successful, or if the command name contains | |
4583 | one or more slashes, the shell executes the named program in a | |
4584 | separate execution environment. | |
4585 | Argument 0 is set to the name given, and the remaining arguments | |
4586 | to the command are set to the arguments given, if any. | |
4587 | .PP | |
4588 | If this execution fails because the file is not in executable | |
4589 | format, and the file is not a directory, it is assumed to be | |
4590 | a \fIshell script\fP, a file | |
4591 | containing shell commands. A subshell is spawned to execute | |
4592 | it. This subshell reinitializes itself, so | |
4593 | that the effect is as if a new shell had been invoked | |
4594 | to handle the script, with the exception that the locations of | |
4595 | commands remembered by the parent (see | |
4596 | .B hash | |
4597 | below under | |
4598 | .SM | |
4599 | \fBSHELL BUILTIN COMMANDS\fP) | |
4600 | are retained by the child. | |
4601 | .PP | |
4602 | If the program is a file beginning with | |
4603 | .BR #! , | |
4604 | the remainder of the first line specifies an interpreter | |
4605 | for the program. The shell executes the | |
4606 | specified interpreter on operating systems that do not | |
a0c0a00f | 4607 | handle this executable format themselves. The arguments to the |
cce855bc JA |
4608 | interpreter consist of a single optional argument following the |
4609 | interpreter name on the first line of the program, followed | |
4610 | by the name of the program, followed by the command | |
4611 | arguments, if any. | |
4612 | .SH COMMAND EXECUTION ENVIRONMENT | |
4613 | The shell has an \fIexecution environment\fP, which consists of the | |
4614 | following: | |
cce855bc JA |
4615 | .IP \(bu |
4616 | open files inherited by the shell at invocation, as modified by | |
4617 | redirections supplied to the \fBexec\fP builtin | |
4618 | .IP \(bu | |
4619 | the current working directory as set by \fBcd\fP, \fBpushd\fP, or | |
4620 | \fBpopd\fP, or inherited by the shell at invocation | |
4621 | .IP \(bu | |
4622 | the file creation mode mask as set by \fBumask\fP or inherited from | |
4623 | the shell's parent | |
4624 | .IP \(bu | |
4625 | current traps set by \fBtrap\fP | |
4626 | .IP \(bu | |
4627 | shell parameters that are set by variable assignment or with \fBset\fP | |
4628 | or inherited from the shell's parent in the environment | |
4629 | .IP \(bu | |
4630 | shell functions defined during execution or inherited from the shell's | |
4631 | parent in the environment | |
4632 | .IP \(bu | |
4633 | options enabled at invocation (either by default or with command-line | |
4634 | arguments) or by \fBset\fP | |
4635 | .IP \(bu | |
4636 | options enabled by \fBshopt\fP | |
4637 | .IP \(bu | |
4638 | shell aliases defined with \fBalias\fP | |
4639 | .IP \(bu | |
4640 | various process IDs, including those of background jobs, the value | |
0001803f CR |
4641 | of \fB$$\fP, and the value of |
4642 | .SM | |
4643 | .B PPID | |
cce855bc JA |
4644 | .PP |
4645 | When a simple command other than a builtin or shell function | |
4646 | is to be executed, it | |
4647 | is invoked in a separate execution environment that consists of | |
4648 | the following. Unless otherwise noted, the values are inherited | |
4649 | from the shell. | |
0001803f | 4650 | .if n .sp 1 |
cce855bc JA |
4651 | .IP \(bu |
4652 | the shell's open files, plus any modifications and additions specified | |
4653 | by redirections to the command | |
4654 | .IP \(bu | |
4655 | the current working directory | |
4656 | .IP \(bu | |
4657 | the file creation mode mask | |
4658 | .IP \(bu | |
b80f6443 JA |
4659 | shell variables and functions marked for export, along with variables |
4660 | exported for the command, passed in the environment | |
cce855bc | 4661 | .IP \(bu |
b80f6443 JA |
4662 | traps caught by the shell are reset to the values inherited from the |
4663 | shell's parent, and traps ignored by the shell are ignored | |
cce855bc JA |
4664 | .PP |
4665 | A command invoked in this separate environment cannot affect the | |
a0c0a00f | 4666 | shell's execution environment. |
cce855bc | 4667 | .PP |
b80f6443 JA |
4668 | Command substitution, commands grouped with parentheses, |
4669 | and asynchronous commands are invoked in a | |
cce855bc JA |
4670 | subshell environment that is a duplicate of the shell environment, |
4671 | except that traps caught by the shell are reset to the values | |
4672 | that the shell inherited from its parent at invocation. Builtin | |
4673 | commands that are invoked as part of a pipeline are also executed in a | |
4674 | subshell environment. Changes made to the subshell environment | |
4675 | cannot affect the shell's execution environment. | |
f73dda09 | 4676 | .PP |
3185942a | 4677 | Subshells spawned to execute command substitutions inherit the value of |
495aee44 CR |
4678 | the \fB\-e\fP option from the parent shell. When not in \fIposix\fP mode, |
4679 | \fBbash\fP clears the \fB\-e\fP option in such subshells. | |
3185942a | 4680 | .PP |
f73dda09 JA |
4681 | If a command is followed by a \fB&\fP and job control is not active, the |
4682 | default standard input for the command is the empty file \fI/dev/null\fP. | |
4683 | Otherwise, the invoked command inherits the file descriptors of the calling | |
4684 | shell as modified by redirections. | |
cce855bc JA |
4685 | .SH ENVIRONMENT |
4686 | When a program is invoked it is given an array of strings | |
4687 | called the | |
4688 | .IR environment . | |
a0c0a00f | 4689 | This is a list of |
cce855bc JA |
4690 | \fIname\fP\-\fIvalue\fP pairs, of the form |
4691 | .IR "name\fR=\fPvalue" . | |
4692 | .PP | |
bb70624e JA |
4693 | The shell provides several ways to manipulate the environment. |
4694 | On invocation, the shell scans its own environment and | |
cce855bc JA |
4695 | creates a parameter for each name found, automatically marking |
4696 | it for | |
4697 | .I export | |
4698 | to child processes. Executed commands inherit the environment. | |
4699 | The | |
4700 | .B export | |
4701 | and | |
4702 | .B declare \-x | |
4703 | commands allow parameters and functions to be added to and | |
4704 | deleted from the environment. If the value of a parameter | |
4705 | in the environment is modified, the new value becomes part | |
4706 | of the environment, replacing the old. The environment | |
4707 | inherited by any executed command consists of the shell's | |
4708 | initial environment, whose values may be modified in the shell, | |
4709 | less any pairs removed by the | |
4710 | .B unset | |
4711 | command, plus any additions via the | |
4712 | .B export | |
4713 | and | |
4714 | .B declare \-x | |
4715 | commands. | |
4716 | .PP | |
4717 | The environment for any | |
4718 | .I simple command | |
4719 | or function may be augmented temporarily by prefixing it with | |
4720 | parameter assignments, as described above in | |
4721 | .SM | |
4722 | .BR PARAMETERS . | |
4723 | These assignment statements affect only the environment seen | |
4724 | by that command. | |
4725 | .PP | |
a0c0a00f | 4726 | If the |
cce855bc JA |
4727 | .B \-k |
4728 | option is set (see the | |
4729 | .B set | |
4730 | builtin command below), then | |
4731 | .I all | |
4732 | parameter assignments are placed in the environment for a command, | |
4733 | not just those that precede the command name. | |
4734 | .PP | |
4735 | When | |
4736 | .B bash | |
4737 | invokes an external command, the variable | |
4738 | .B _ | |
ac50fbac | 4739 | is set to the full filename of the command and passed to that |
ccc6cda3 JA |
4740 | command in its environment. |
4741 | .SH "EXIT STATUS" | |
3185942a JA |
4742 | .PP |
4743 | The exit status of an executed command is the value returned by the | |
4744 | \fIwaitpid\fP system call or equivalent function. Exit statuses | |
4745 | fall between 0 and 255, though, as explained below, the shell may | |
4746 | use values above 125 specially. Exit statuses from shell builtins and | |
a0c0a00f | 4747 | compound commands are also limited to this range. Under certain |
3185942a JA |
4748 | circumstances, the shell will use special values to indicate specific |
4749 | failure modes. | |
4750 | .PP | |
a0c0a00f | 4751 | For the shell's purposes, a command which exits with a |
ccc6cda3 JA |
4752 | zero exit status has succeeded. An exit status of zero |
4753 | indicates success. A non-zero exit status indicates failure. | |
bb70624e JA |
4754 | When a command terminates on a fatal signal \fIN\fP, \fBbash\fP uses |
4755 | the value of 128+\fIN\fP as the exit status. | |
ccc6cda3 JA |
4756 | .PP |
4757 | If a command is not found, the child process created to | |
4758 | execute it returns a status of 127. If a command is found | |
4759 | but is not executable, the return status is 126. | |
4760 | .PP | |
cce855bc JA |
4761 | If a command fails because of an error during expansion or redirection, |
4762 | the exit status is greater than zero. | |
4763 | .PP | |
ccc6cda3 JA |
4764 | Shell builtin commands return a status of 0 (\fItrue\fP) if |
4765 | successful, and non-zero (\fIfalse\fP) if an error occurs | |
a0c0a00f CR |
4766 | while they execute. |
4767 | All builtins return an exit status of 2 to indicate incorrect usage, | |
4768 | generally invalid options or missing arguments. | |
ccc6cda3 JA |
4769 | .PP |
4770 | \fBBash\fP itself returns the exit status of the last command | |
4771 | executed, unless a syntax error occurs, in which case it exits | |
4772 | with a non-zero value. See also the \fBexit\fP builtin | |
4773 | command below. | |
4774 | .SH SIGNALS | |
cce855bc | 4775 | When \fBbash\fP is interactive, in the absence of any traps, it ignores |
ccc6cda3 JA |
4776 | .SM |
4777 | .B SIGTERM | |
4778 | (so that \fBkill 0\fP does not kill an interactive shell), | |
4779 | and | |
4780 | .SM | |
4781 | .B SIGINT | |
4782 | is caught and handled (so that the \fBwait\fP builtin is interruptible). | |
4783 | In all cases, \fBbash\fP ignores | |
4784 | .SM | |
4785 | .BR SIGQUIT . | |
4786 | If job control is in effect, | |
4787 | .B bash | |
4788 | ignores | |
4789 | .SM | |
4790 | .BR SIGTTIN , | |
4791 | .SM | |
4792 | .BR SIGTTOU , | |
4793 | and | |
4794 | .SM | |
4795 | .BR SIGTSTP . | |
4796 | .PP | |
b80f6443 | 4797 | Non-builtin commands run by \fBbash\fP have signal handlers |
cce855bc JA |
4798 | set to the values inherited by the shell from its parent. |
4799 | When job control is not in effect, asynchronous commands | |
ccc6cda3 JA |
4800 | ignore |
4801 | .SM | |
4802 | .B SIGINT | |
4803 | and | |
4804 | .SM | |
cce855bc | 4805 | .B SIGQUIT |
b80f6443 | 4806 | in addition to these inherited handlers. |
ccc6cda3 JA |
4807 | Commands run as a result of command substitution ignore the |
4808 | keyboard-generated job control signals | |
4809 | .SM | |
4810 | .BR SIGTTIN , | |
4811 | .SM | |
4812 | .BR SIGTTOU , | |
4813 | and | |
4814 | .SM | |
4815 | .BR SIGTSTP . | |
4816 | .PP | |
4817 | The shell exits by default upon receipt of a | |
4818 | .SM | |
4819 | .BR SIGHUP . | |
f73dda09 | 4820 | Before exiting, an interactive shell resends the |
ccc6cda3 JA |
4821 | .SM |
4822 | .B SIGHUP | |
cce855bc JA |
4823 | to all jobs, running or stopped. |
4824 | Stopped jobs are sent | |
4825 | .SM | |
4826 | .B SIGCONT | |
4827 | to ensure that they receive the | |
4828 | .SM | |
4829 | .BR SIGHUP . | |
4830 | To prevent the shell from | |
4831 | sending the signal to a particular job, it should be removed from the | |
a0c0a00f | 4832 | jobs table with the |
ccc6cda3 JA |
4833 | .B disown |
4834 | builtin (see | |
4835 | .SM | |
4836 | .B "SHELL BUILTIN COMMANDS" | |
a0c0a00f | 4837 | below) or marked |
cce855bc | 4838 | to not receive |
ccc6cda3 | 4839 | .SM |
cce855bc JA |
4840 | .B SIGHUP |
4841 | using | |
4842 | .BR "disown \-h" . | |
4843 | .PP | |
4844 | If the | |
4845 | .B huponexit | |
4846 | shell option has been set with | |
4847 | .BR shopt , | |
4848 | .B bash | |
a0c0a00f | 4849 | sends a |
cce855bc JA |
4850 | .SM |
4851 | .B SIGHUP | |
4852 | to all jobs when an interactive login shell exits. | |
4853 | .PP | |
95732b49 | 4854 | If \fBbash\fP is waiting for a command to complete and receives a signal |
b80f6443 | 4855 | for which a trap has been set, the trap will not be executed until |
a0c0a00f | 4856 | the command completes. |
cce855bc JA |
4857 | When \fBbash\fP is waiting for an asynchronous command via the \fBwait\fP |
4858 | builtin, the reception of a signal for which a trap has been set will | |
4859 | cause the \fBwait\fP builtin to return immediately with an exit status | |
4860 | greater than 128, immediately after which the trap is executed. | |
ccc6cda3 JA |
4861 | .SH "JOB CONTROL" |
4862 | .I Job control | |
4863 | refers to the ability to selectively stop (\fIsuspend\fP) | |
4864 | the execution of processes and continue (\fIresume\fP) | |
4865 | their execution at a later point. A user typically employs | |
4866 | this facility via an interactive interface supplied jointly | |
0001803f | 4867 | by the operating system kernel's terminal driver and |
ccc6cda3 JA |
4868 | .BR bash . |
4869 | .PP | |
4870 | The shell associates a | |
4871 | .I job | |
4872 | with each pipeline. It keeps a table of currently executing | |
4873 | jobs, which may be listed with the | |
4874 | .B jobs | |
4875 | command. When | |
4876 | .B bash | |
4877 | starts a job asynchronously (in the | |
4878 | .IR background ), | |
4879 | it prints a line that looks like: | |
4880 | .RS | |
4881 | .PP | |
4882 | [1] 25647 | |
4883 | .RE | |
4884 | .PP | |
4885 | indicating that this job is job number 1 and that the process ID | |
4886 | of the last process in the pipeline associated with this job is 25647. | |
4887 | All of the processes in a single pipeline are members of the same job. | |
4888 | .B Bash | |
4889 | uses the | |
4890 | .I job | |
4891 | abstraction as the basis for job control. | |
4892 | .PP | |
4893 | To facilitate the implementation of the user interface to job | |
bb70624e | 4894 | control, the operating system maintains the notion of a \fIcurrent terminal |
ccc6cda3 JA |
4895 | process group ID\fP. Members of this process group (processes whose |
4896 | process group ID is equal to the current terminal process group ID) | |
4897 | receive keyboard-generated signals such as | |
4898 | .SM | |
4899 | .BR SIGINT . | |
4900 | These processes are said to be in the | |
4901 | .IR foreground . | |
4902 | .I Background | |
4903 | processes are those whose process group ID differs from the terminal's; | |
4904 | such processes are immune to keyboard-generated signals. | |
0001803f CR |
4905 | Only foreground processes are allowed to read from or, if the |
4906 | user so specifies with \f(CWstty tostop\fP, write to the | |
4907 | terminal. | |
4908 | Background processes which attempt to read from (write to when | |
4909 | \f(CWstty tostop\fP is in effect) the | |
a0c0a00f | 4910 | terminal are sent a |
ccc6cda3 JA |
4911 | .SM |
4912 | .B SIGTTIN (SIGTTOU) | |
0001803f | 4913 | signal by the kernel's terminal driver, |
ccc6cda3 JA |
4914 | which, unless caught, suspends the process. |
4915 | .PP | |
4916 | If the operating system on which | |
4917 | .B bash | |
4918 | is running supports | |
4919 | job control, | |
4920 | .B bash | |
bb70624e | 4921 | contains facilities to use it. |
ccc6cda3 JA |
4922 | Typing the |
4923 | .I suspend | |
4924 | character (typically | |
4925 | .BR ^Z , | |
4926 | Control-Z) while a process is running | |
a0c0a00f | 4927 | causes that process to be stopped and returns control to |
ccc6cda3 JA |
4928 | .BR bash . |
4929 | Typing the | |
4930 | .I "delayed suspend" | |
4931 | character (typically | |
4932 | .BR ^Y , | |
4933 | Control-Y) causes the process to be stopped when it | |
4934 | attempts to read input from the terminal, and control to | |
4935 | be returned to | |
4936 | .BR bash . | |
cce855bc | 4937 | The user may then manipulate the state of this job, using the |
ccc6cda3 JA |
4938 | .B bg |
4939 | command to continue it in the background, the | |
4940 | .B fg | |
4941 | command to continue it in the foreground, or | |
4942 | the | |
4943 | .B kill | |
4944 | command to kill it. A \fB^Z\fP takes effect immediately, | |
4945 | and has the additional side effect of causing pending output | |
4946 | and typeahead to be discarded. | |
4947 | .PP | |
4948 | There are a number of ways to refer to a job in the shell. | |
4949 | The character | |
4950 | .B % | |
3185942a | 4951 | introduces a job specification (\fIjobspec\fP). Job number |
ccc6cda3 JA |
4952 | .I n |
4953 | may be referred to as | |
4954 | .BR %n . | |
4955 | A job may also be referred to using a prefix of the name used to | |
4956 | start it, or using a substring that appears in its command line. | |
4957 | For example, | |
4958 | .B %ce | |
4959 | refers to a stopped | |
4960 | .B ce | |
4961 | job. If a prefix matches more than one job, | |
4962 | .B bash | |
4963 | reports an error. Using | |
4964 | .BR %?ce , | |
4965 | on the other hand, refers to any job containing the string | |
4966 | .B ce | |
4967 | in its command line. If the substring matches more than one job, | |
4968 | .B bash | |
4969 | reports an error. The symbols | |
4970 | .B %% | |
4971 | and | |
4972 | .B %+ | |
4973 | refer to the shell's notion of the | |
4974 | .IR "current job" , | |
4975 | which is the last job stopped while it was in | |
cce855bc | 4976 | the foreground or started in the background. |
a0c0a00f | 4977 | The |
ccc6cda3 JA |
4978 | .I "previous job" |
4979 | may be referenced using | |
4980 | .BR %\- . | |
3185942a JA |
4981 | If there is only a single job, \fB%+\fP and \fB%\-\fP can both be used |
4982 | to refer to that job. | |
ccc6cda3 JA |
4983 | In output pertaining to jobs (e.g., the output of the |
4984 | .B jobs | |
4985 | command), the current job is always flagged with a | |
4986 | .BR + , | |
4987 | and the previous job with a | |
4988 | .BR \- . | |
95732b49 JA |
4989 | A single % (with no accompanying job specification) also refers to the |
4990 | current job. | |
726f6388 | 4991 | .PP |
ccc6cda3 JA |
4992 | Simply naming a job can be used to bring it into the |
4993 | foreground: | |
4994 | .B %1 | |
4995 | is a synonym for | |
4996 | \fB``fg %1''\fP, | |
4997 | bringing job 1 from the background into the foreground. | |
4998 | Similarly, | |
4999 | .B ``%1 &'' | |
5000 | resumes job 1 in the background, equivalent to | |
5001 | \fB``bg %1''\fP. | |
726f6388 | 5002 | .PP |
ccc6cda3 JA |
5003 | The shell learns immediately whenever a job changes state. |
5004 | Normally, | |
5005 | .B bash | |
5006 | waits until it is about to print a prompt before reporting | |
5007 | changes in a job's status so as to not interrupt | |
a0c0a00f | 5008 | any other output. If the |
ccc6cda3 JA |
5009 | .B \-b |
5010 | option to the | |
726f6388 | 5011 | .B set |
ccc6cda3 | 5012 | builtin command |
cce855bc | 5013 | is enabled, |
726f6388 | 5014 | .B bash |
ccc6cda3 | 5015 | reports such changes immediately. |
f73dda09 JA |
5016 | Any trap on |
5017 | .SM | |
5018 | .B SIGCHLD | |
5019 | is executed for each child that exits. | |
726f6388 | 5020 | .PP |
ccc6cda3 JA |
5021 | If an attempt to exit |
5022 | .B bash | |
3185942a JA |
5023 | is made while jobs are stopped (or, if the \fBcheckjobs\fP shell option has |
5024 | been enabled using the \fBshopt\fP builtin, running), the shell prints a | |
5025 | warning message, and, if the \fBcheckjobs\fP option is enabled, lists the | |
5026 | jobs and their statuses. | |
5027 | The | |
ccc6cda3 | 5028 | .B jobs |
a0c0a00f | 5029 | command may then be used to inspect their status. |
ccc6cda3 | 5030 | If a second attempt to exit is made without an intervening command, |
3185942a | 5031 | the shell does not print another warning, and any stopped |
ccc6cda3 | 5032 | jobs are terminated. |
726f6388 | 5033 | .SH PROMPTING |
a0c0a00f | 5034 | When executing interactively, |
726f6388 JA |
5035 | .B bash |
5036 | displays the primary prompt | |
5037 | .SM | |
5038 | .B PS1 | |
5039 | when it is ready to read a command, and the secondary prompt | |
5040 | .SM | |
5041 | .B PS2 | |
5042 | when it needs more input to complete a command. | |
5043 | .B Bash | |
a0c0a00f CR |
5044 | displays |
5045 | .B PS0 | |
5046 | after it reads a command but before executing it. | |
5047 | .B Bash | |
726f6388 JA |
5048 | allows these prompt strings to be customized by inserting a number of |
5049 | backslash-escaped special characters that are decoded as follows: | |
5050 | .RS | |
5051 | .PD 0 | |
5052 | .TP | |
ccc6cda3 JA |
5053 | .B \ea |
5054 | an ASCII bell character (07) | |
726f6388 JA |
5055 | .TP |
5056 | .B \ed | |
5057 | the date in "Weekday Month Date" format (e.g., "Tue May 26") | |
5058 | .TP | |
7117c2d2 JA |
5059 | .B \eD{\fIformat\fP} |
5060 | the \fIformat\fP is passed to \fIstrftime\fP(3) and the result is inserted | |
5061 | into the prompt string; an empty \fIformat\fP results in a locale-specific | |
5062 | time representation. The braces are required | |
5063 | .TP | |
ccc6cda3 JA |
5064 | .B \ee |
5065 | an ASCII escape character (033) | |
5066 | .TP | |
5067 | .B \eh | |
5068 | the hostname up to the first `.' | |
5069 | .TP | |
5070 | .B \eH | |
5071 | the hostname | |
5072 | .TP | |
bb70624e JA |
5073 | .B \ej |
5074 | the number of jobs currently managed by the shell | |
5075 | .TP | |
5076 | .B \el | |
5077 | the basename of the shell's terminal device name | |
5078 | .TP | |
726f6388 JA |
5079 | .B \en |
5080 | newline | |
5081 | .TP | |
cce855bc JA |
5082 | .B \er |
5083 | carriage return | |
5084 | .TP | |
726f6388 JA |
5085 | .B \es |
5086 | the name of the shell, the basename of | |
5087 | .B $0 | |
5088 | (the portion following the final slash) | |
5089 | .TP | |
ccc6cda3 JA |
5090 | .B \et |
5091 | the current time in 24-hour HH:MM:SS format | |
726f6388 | 5092 | .TP |
ccc6cda3 JA |
5093 | .B \eT |
5094 | the current time in 12-hour HH:MM:SS format | |
5095 | .TP | |
5096 | .B \e@ | |
5097 | the current time in 12-hour am/pm format | |
726f6388 | 5098 | .TP |
f73dda09 JA |
5099 | .B \eA |
5100 | the current time in 24-hour HH:MM format | |
5101 | .TP | |
726f6388 JA |
5102 | .B \eu |
5103 | the username of the current user | |
5104 | .TP | |
ccc6cda3 JA |
5105 | .B \ev |
5106 | the version of \fBbash\fP (e.g., 2.00) | |
726f6388 | 5107 | .TP |
ccc6cda3 | 5108 | .B \eV |
b80f6443 | 5109 | the release of \fBbash\fP, version + patch level (e.g., 2.00.0) |
ccc6cda3 JA |
5110 | .TP |
5111 | .B \ew | |
0001803f CR |
5112 | the current working directory, with |
5113 | .SM | |
5114 | .B $HOME | |
5115 | abbreviated with a tilde | |
5116 | (uses the value of the | |
5117 | .SM | |
5118 | .B PROMPT_DIRTRIM | |
5119 | variable) | |
ccc6cda3 JA |
5120 | .TP |
5121 | .B \eW | |
0001803f CR |
5122 | the basename of the current working directory, with |
5123 | .SM | |
5124 | .B $HOME | |
b80f6443 | 5125 | abbreviated with a tilde |
726f6388 JA |
5126 | .TP |
5127 | .B \e! | |
5128 | the history number of this command | |
5129 | .TP | |
ccc6cda3 JA |
5130 | .B \e# |
5131 | the command number of this command | |
5132 | .TP | |
726f6388 JA |
5133 | .B \e$ |
5134 | if the effective UID is 0, a | |
5135 | .BR # , | |
5136 | otherwise a | |
5137 | .B $ | |
5138 | .TP | |
ccc6cda3 JA |
5139 | .B \e\fInnn\fP |
5140 | the character corresponding to the octal number \fInnn\fP | |
726f6388 JA |
5141 | .TP |
5142 | .B \e\e | |
5143 | a backslash | |
5144 | .TP | |
5145 | .B \e[ | |
5146 | begin a sequence of non-printing characters, which could be used to | |
5147 | embed a terminal control sequence into the prompt | |
5148 | .TP | |
5149 | .B \e] | |
5150 | end a sequence of non-printing characters | |
5151 | .PD | |
5152 | .RE | |
5153 | .PP | |
5154 | The command number and the history number are usually different: | |
5155 | the history number of a command is its position in the history | |
5156 | list, which may include commands restored from the history file | |
5157 | (see | |
5158 | .SM | |
5159 | .B HISTORY | |
5160 | below), while the command number is the position in the sequence | |
5161 | of commands executed during the current shell session. | |
5162 | After the string is decoded, it is expanded via | |
bb70624e JA |
5163 | parameter expansion, command substitution, arithmetic |
5164 | expansion, and quote removal, subject to the value of the | |
ccc6cda3 JA |
5165 | .B promptvars |
5166 | shell option (see the description of the | |
5167 | .B shopt | |
5168 | command under | |
5169 | .SM | |
5170 | .B "SHELL BUILTIN COMMANDS" | |
5171 | below). | |
726f6388 JA |
5172 | .SH READLINE |
5173 | This is the library that handles reading input when using an interactive | |
5174 | shell, unless the | |
d166f048 | 5175 | .B \-\-noediting |
ccc6cda3 | 5176 | option is given at shell invocation. |
3185942a JA |
5177 | Line editing is also used when using the \fB\-e\fP option to the |
5178 | \fBread\fP builtin. | |
495aee44 | 5179 | By default, the line editing commands are similar to those of Emacs. |
726f6388 | 5180 | A vi-style line editing interface is also available. |
3185942a JA |
5181 | Line editing can be enabled at any time using the |
5182 | .B \-o emacs | |
ccc6cda3 | 5183 | or |
3185942a | 5184 | .B \-o vi |
ccc6cda3 JA |
5185 | options to the |
5186 | .B set | |
5187 | builtin (see | |
5188 | .SM | |
5189 | .B SHELL BUILTIN COMMANDS | |
5190 | below). | |
3185942a JA |
5191 | To turn off line editing after the shell is running, use the |
5192 | .B +o emacs | |
5193 | or | |
5194 | .B +o vi | |
5195 | options to the | |
5196 | .B set | |
5197 | builtin. | |
ccc6cda3 | 5198 | .SS "Readline Notation" |
726f6388 | 5199 | .PP |
495aee44 | 5200 | In this section, the Emacs-style notation is used to denote |
726f6388 | 5201 | keystrokes. Control keys are denoted by C\-\fIkey\fR, e.g., C\-n |
a0c0a00f | 5202 | means Control\-N. Similarly, |
726f6388 JA |
5203 | .I meta |
5204 | keys are denoted by M\-\fIkey\fR, so M\-x means Meta\-X. (On keyboards | |
a0c0a00f | 5205 | without a |
726f6388 JA |
5206 | .I meta |
5207 | key, M\-\fIx\fP means ESC \fIx\fP, i.e., press the Escape key | |
5208 | then the | |
5209 | .I x | |
5210 | key. This makes ESC the \fImeta prefix\fP. | |
5211 | The combination M\-C\-\fIx\fP means ESC\-Control\-\fIx\fP, | |
5212 | or press the Escape key | |
5213 | then hold the Control key while pressing the | |
5214 | .I x | |
5215 | key.) | |
5216 | .PP | |
ccc6cda3 JA |
5217 | Readline commands may be given numeric |
5218 | .IR arguments , | |
5219 | which normally act as a repeat count. | |
5220 | Sometimes, however, it is the sign of the argument that is significant. | |
5221 | Passing a negative argument to a command that acts in the forward | |
5222 | direction (e.g., \fBkill\-line\fP) causes that command to act in a | |
a0c0a00f | 5223 | backward direction. |
ccc6cda3 JA |
5224 | Commands whose behavior with arguments deviates from this are noted |
5225 | below. | |
5226 | .PP | |
5227 | When a command is described as \fIkilling\fP text, the text | |
5228 | deleted is saved for possible future retrieval | |
5229 | (\fIyanking\fP). The killed text is saved in a | |
5230 | \fIkill ring\fP. Consecutive kills cause the text to be | |
a0c0a00f | 5231 | accumulated into one unit, which can be yanked all at once. |
ccc6cda3 JA |
5232 | Commands which do not kill text separate the chunks of text |
5233 | on the kill ring. | |
5234 | .SS "Readline Initialization" | |
5235 | .PP | |
5236 | Readline is customized by putting commands in an initialization | |
5237 | file (the \fIinputrc\fP file). | |
5238 | The name of this file is taken from the value of the | |
726f6388 | 5239 | .SM |
ccc6cda3 JA |
5240 | .B INPUTRC |
5241 | variable. If that variable is unset, the default is | |
726f6388 | 5242 | .IR ~/.inputrc . |
ccc6cda3 JA |
5243 | When a program which uses the readline library starts up, the |
5244 | initialization file is read, and the key bindings and variables | |
5245 | are set. | |
5246 | There are only a few basic constructs allowed in the | |
5247 | readline initialization file. | |
5248 | Blank lines are ignored. | |
5249 | Lines beginning with a \fB#\fP are comments. | |
5250 | Lines beginning with a \fB$\fP indicate conditional constructs. | |
5251 | Other lines denote key bindings and variable settings. | |
5252 | .PP | |
5253 | The default key-bindings may be changed with an | |
a0c0a00f | 5254 | .I inputrc |
ccc6cda3 | 5255 | file. |
726f6388 JA |
5256 | Other programs that use this library may add their own commands |
5257 | and bindings. | |
5258 | .PP | |
5259 | For example, placing | |
5260 | .RS | |
5261 | .PP | |
5262 | M\-Control\-u: universal\-argument | |
5263 | .RE | |
5264 | or | |
5265 | .RS | |
5266 | C\-Meta\-u: universal\-argument | |
5267 | .RE | |
a0c0a00f | 5268 | into the |
ccc6cda3 | 5269 | .I inputrc |
726f6388 JA |
5270 | would make M\-C\-u execute the readline command |
5271 | .IR universal\-argument . | |
5272 | .PP | |
5273 | The following symbolic character names are recognized: | |
5274 | .IR RUBOUT , | |
5275 | .IR DEL , | |
5276 | .IR ESC , | |
5277 | .IR LFD , | |
5278 | .IR NEWLINE , | |
5279 | .IR RET , | |
5280 | .IR RETURN , | |
5281 | .IR SPC , | |
5282 | .IR SPACE , | |
5283 | and | |
5284 | .IR TAB . | |
bb70624e | 5285 | .PP |
726f6388 JA |
5286 | In addition to command names, readline allows keys to be bound |
5287 | to a string that is inserted when the key is pressed (a \fImacro\fP). | |
ccc6cda3 | 5288 | .SS "Readline Key Bindings" |
726f6388 JA |
5289 | .PP |
5290 | The syntax for controlling key bindings in the | |
cce855bc | 5291 | .I inputrc |
726f6388 JA |
5292 | file is simple. All that is required is the name of the |
5293 | command or the text of a macro and a key sequence to which | |
a0c0a00f | 5294 | it should be bound. The name may be specified in one of two ways: |
ccc6cda3 | 5295 | as a symbolic key name, possibly with \fIMeta\-\fP or \fIControl\-\fP |
726f6388 | 5296 | prefixes, or as a key sequence. |
28ef6c31 | 5297 | .PP |
cce855bc | 5298 | When using the form \fBkeyname\fP:\^\fIfunction\-name\fP or \fImacro\fP, |
726f6388 JA |
5299 | .I keyname |
5300 | is the name of a key spelled out in English. For example: | |
5301 | .sp | |
5302 | .RS | |
5303 | Control-u: universal\-argument | |
5304 | .br | |
5305 | Meta-Rubout: backward-kill-word | |
5306 | .br | |
ccc6cda3 | 5307 | Control-o: "> output" |
726f6388 JA |
5308 | .RE |
5309 | .LP | |
5310 | In the above example, | |
ccc6cda3 | 5311 | .I C\-u |
726f6388 JA |
5312 | is bound to the function |
5313 | .BR universal\-argument , | |
ccc6cda3 | 5314 | .I M\-DEL |
726f6388 JA |
5315 | is bound to the function |
5316 | .BR backward\-kill\-word , | |
5317 | and | |
ccc6cda3 | 5318 | .I C\-o |
726f6388 JA |
5319 | is bound to run the macro |
5320 | expressed on the right hand side (that is, to insert the text | |
28ef6c31 JA |
5321 | .if t \f(CW> output\fP |
5322 | .if n ``> output'' | |
726f6388 JA |
5323 | into the line). |
5324 | .PP | |
cce855bc | 5325 | In the second form, \fB"keyseq"\fP:\^\fIfunction\-name\fP or \fImacro\fP, |
726f6388 JA |
5326 | .B keyseq |
5327 | differs from | |
5328 | .B keyname | |
5329 | above in that strings denoting | |
5330 | an entire key sequence may be specified by placing the sequence | |
5331 | within double quotes. Some GNU Emacs style key escapes can be | |
28ef6c31 JA |
5332 | used, as in the following example, but the symbolic character names |
5333 | are not recognized. | |
726f6388 JA |
5334 | .sp |
5335 | .RS | |
ccc6cda3 | 5336 | "\eC\-u": universal\-argument |
726f6388 | 5337 | .br |
ccc6cda3 | 5338 | "\eC\-x\eC\-r": re\-read\-init\-file |
726f6388 JA |
5339 | .br |
5340 | "\ee[11~": "Function Key 1" | |
5341 | .RE | |
5342 | .PP | |
5343 | In this example, | |
ccc6cda3 | 5344 | .I C\-u |
726f6388 JA |
5345 | is again bound to the function |
5346 | .BR universal\-argument . | |
ccc6cda3 | 5347 | .I "C\-x C\-r" |
726f6388 JA |
5348 | is bound to the function |
5349 | .BR re\-read\-init\-file , | |
a0c0a00f | 5350 | and |
726f6388 JA |
5351 | .I "ESC [ 1 1 ~" |
5352 | is bound to insert the text | |
28ef6c31 JA |
5353 | .if t \f(CWFunction Key 1\fP. |
5354 | .if n ``Function Key 1''. | |
5355 | .PP | |
cce855bc | 5356 | The full set of GNU Emacs style escape sequences is |
726f6388 | 5357 | .RS |
cce855bc | 5358 | .PD 0 |
726f6388 JA |
5359 | .TP |
5360 | .B \eC\- | |
5361 | control prefix | |
5362 | .TP | |
ccc6cda3 | 5363 | .B \eM\- |
726f6388 JA |
5364 | meta prefix |
5365 | .TP | |
5366 | .B \ee | |
5367 | an escape character | |
5368 | .TP | |
5369 | .B \e\e | |
5370 | backslash | |
5371 | .TP | |
5372 | .B \e" | |
5373 | literal " | |
5374 | .TP | |
0628567a JA |
5375 | .B \e\(aq |
5376 | literal \(aq | |
726f6388 | 5377 | .RE |
cce855bc JA |
5378 | .PD |
5379 | .PP | |
5380 | In addition to the GNU Emacs style escape sequences, a second | |
5381 | set of backslash escapes is available: | |
5382 | .RS | |
5383 | .PD 0 | |
5384 | .TP | |
5385 | .B \ea | |
5386 | alert (bell) | |
5387 | .TP | |
5388 | .B \eb | |
5389 | backspace | |
5390 | .TP | |
5391 | .B \ed | |
5392 | delete | |
5393 | .TP | |
5394 | .B \ef | |
5395 | form feed | |
5396 | .TP | |
5397 | .B \en | |
5398 | newline | |
5399 | .TP | |
5400 | .B \er | |
5401 | carriage return | |
5402 | .TP | |
5403 | .B \et | |
5404 | horizontal tab | |
5405 | .TP | |
5406 | .B \ev | |
5407 | vertical tab | |
5408 | .TP | |
5409 | .B \e\fInnn\fP | |
f73dda09 | 5410 | the eight-bit character whose value is the octal value \fInnn\fP |
cce855bc JA |
5411 | (one to three digits) |
5412 | .TP | |
f73dda09 JA |
5413 | .B \ex\fIHH\fP |
5414 | the eight-bit character whose value is the hexadecimal value \fIHH\fP | |
5415 | (one or two hex digits) | |
cce855bc JA |
5416 | .RE |
5417 | .PD | |
726f6388 | 5418 | .PP |
cce855bc JA |
5419 | When entering the text of a macro, single or double quotes must |
5420 | be used to indicate a macro definition. | |
5421 | Unquoted text is assumed to be a function name. | |
5422 | In the macro body, the backslash escapes described above are expanded. | |
5423 | Backslash will quote any other character in the macro text, | |
0628567a | 5424 | including " and \(aq. |
726f6388 JA |
5425 | .PP |
5426 | .B Bash | |
5427 | allows the current readline key bindings to be displayed or modified | |
5428 | with the | |
5429 | .B bind | |
5430 | builtin command. The editing mode may be switched during interactive | |
5431 | use by using the | |
5432 | .B \-o | |
5433 | option to the | |
5434 | .B set | |
5435 | builtin command (see | |
5436 | .SM | |
5437 | .B SHELL BUILTIN COMMANDS | |
5438 | below). | |
ccc6cda3 | 5439 | .SS "Readline Variables" |
726f6388 JA |
5440 | .PP |
5441 | Readline has variables that can be used to further customize its | |
5442 | behavior. A variable may be set in the | |
5443 | .I inputrc | |
5444 | file with a statement of the form | |
5445 | .RS | |
5446 | .PP | |
5447 | \fBset\fP \fIvariable\-name\fP \fIvalue\fP | |
5448 | .RE | |
5449 | .PP | |
5450 | Except where noted, readline variables can take the values | |
5451 | .B On | |
5452 | or | |
95732b49 JA |
5453 | .B Off |
5454 | (without regard to case). | |
5455 | Unrecognized variable names are ignored. | |
5456 | When a variable value is read, empty or null values, "on" (case-insensitive), | |
5457 | and "1" are equivalent to \fBOn\fP. All other values are equivalent to | |
5458 | \fBOff\fP. | |
726f6388 JA |
5459 | The variables and their default values are: |
5460 | .PP | |
5461 | .PD 0 | |
5462 | .TP | |
726f6388 JA |
5463 | .B bell\-style (audible) |
5464 | Controls what happens when readline wants to ring the terminal bell. | |
5465 | If set to \fBnone\fP, readline never rings the bell. If set to | |
5466 | \fBvisible\fP, readline uses a visible bell if one is available. | |
5467 | If set to \fBaudible\fP, readline attempts to ring the terminal's bell. | |
5468 | .TP | |
95732b49 JA |
5469 | .B bind\-tty\-special\-chars (On) |
5470 | If set to \fBOn\fP, readline attempts to bind the control characters | |
5471 | treated specially by the kernel's terminal driver to their readline | |
5472 | equivalents. | |
5473 | .TP | |
a0c0a00f CR |
5474 | .B blink\-matching\-paren (Off) |
5475 | If set to \fBOn\fP, readline attempts to briefly move the cursor to an | |
5476 | opening parenthesis when a closing parenthesis is inserted. | |
5477 | .TP | |
5478 | .B colored\-completion\-prefix (Off) | |
5479 | If set to \fBOn\fP, when listing completions, readline displays the | |
5480 | common prefix of the set of possible completions using a different color. | |
5481 | The color definitions are taken from the value of the \fBLS_COLORS\fP | |
5482 | environment variable. | |
5483 | .TP | |
ac50fbac CR |
5484 | .B colored\-stats (Off) |
5485 | If set to \fBOn\fP, readline displays possible completions using different | |
a0c0a00f | 5486 | colors to indicate their file type. |
ac50fbac CR |
5487 | The color definitions are taken from the value of the \fBLS_COLORS\fP |
5488 | environment variable. | |
5489 | .TP | |
726f6388 | 5490 | .B comment\-begin (``#'') |
bb70624e | 5491 | The string that is inserted when the readline |
ccc6cda3 | 5492 | .B insert\-comment |
726f6388 | 5493 | command is executed. |
ccc6cda3 JA |
5494 | This command is bound to |
5495 | .B M\-# | |
5496 | in emacs mode and to | |
5497 | .B # | |
5498 | in vi command mode. | |
726f6388 | 5499 | .TP |
a0c0a00f CR |
5500 | .B completion\-display\-width (-1) |
5501 | The number of screen columns used to display possible matches | |
5502 | when performing completion. | |
5503 | The value is ignored if it is less than 0 or greater than the terminal | |
5504 | screen width. | |
5505 | A value of 0 will cause matches to be displayed one per line. | |
5506 | The default value is -1. | |
5507 | .TP | |
cce855bc JA |
5508 | .B completion\-ignore\-case (Off) |
5509 | If set to \fBOn\fP, readline performs filename matching and completion | |
5510 | in a case\-insensitive fashion. | |
5511 | .TP | |
a0c0a00f CR |
5512 | .B completion\-map\-case (Off) |
5513 | If set to \fBOn\fP, and \fBcompletion\-ignore\-case\fP is enabled, readline | |
5514 | treats hyphens (\fI\-\fP) and underscores (\fI_\fP) as equivalent when | |
5515 | performing case\-insensitive filename matching and completion. | |
5516 | .TP | |
3185942a JA |
5517 | .B completion\-prefix\-display\-length (0) |
5518 | The length in characters of the common prefix of a list of possible | |
5519 | completions that is displayed without modification. When set to a | |
5520 | value greater than zero, common prefixes longer than this value are | |
5521 | replaced with an ellipsis when displaying possible completions. | |
5522 | .TP | |
726f6388 JA |
5523 | .B completion\-query\-items (100) |
5524 | This determines when the user is queried about viewing | |
5525 | the number of possible completions | |
5526 | generated by the \fBpossible\-completions\fP command. | |
5527 | It may be set to any integer value greater than or equal to | |
5528 | zero. If the number of possible completions is greater than | |
5529 | or equal to the value of this variable, the user is asked whether | |
5530 | or not he wishes to view them; otherwise they are simply listed | |
5531 | on the terminal. | |
5532 | .TP | |
ccc6cda3 JA |
5533 | .B convert\-meta (On) |
5534 | If set to \fBOn\fP, readline will convert characters with the | |
5535 | eighth bit set to an ASCII key sequence | |
bb70624e | 5536 | by stripping the eighth bit and prefixing an |
ccc6cda3 | 5537 | escape character (in effect, using escape as the \fImeta prefix\fP). |
a0c0a00f CR |
5538 | The default is \fIOn\fP, but readline will set it to \fIOff\fP if the |
5539 | locale contains eight-bit characters. | |
ccc6cda3 JA |
5540 | .TP |
5541 | .B disable\-completion (Off) | |
5542 | If set to \fBOn\fP, readline will inhibit word completion. Completion | |
5543 | characters will be inserted into the line as if they had been | |
5544 | mapped to \fBself-insert\fP. | |
5545 | .TP | |
a0c0a00f CR |
5546 | .B echo\-control\-characters (On) |
5547 | When set to \fBOn\fP, on operating systems that indicate they support it, | |
5548 | readline echoes a character corresponding to a signal generated from the | |
5549 | keyboard. | |
5550 | .TP | |
ccc6cda3 JA |
5551 | .B editing\-mode (emacs) |
5552 | Controls whether readline begins with a set of key bindings similar | |
495aee44 | 5553 | to \fIEmacs\fP or \fIvi\fP. |
ccc6cda3 JA |
5554 | .B editing\-mode |
5555 | can be set to either | |
5556 | .B emacs | |
5557 | or | |
5558 | .BR vi . | |
5559 | .TP | |
a0c0a00f CR |
5560 | .B enable\-bracketed\-paste (Off) |
5561 | When set to \fBOn\fP, readline will configure the terminal in a way | |
5562 | that will enable it to insert each paste into the editing buffer as a | |
5563 | single string of characters, instead of treating each character as if | |
5564 | it had been read from the keyboard. This can prevent pasted characters | |
5565 | from being interpreted as editing commands. | |
0001803f | 5566 | .TP |
ccc6cda3 JA |
5567 | .B enable\-keypad (Off) |
5568 | When set to \fBOn\fP, readline will try to enable the application | |
5569 | keypad when it is called. Some systems need this to enable the | |
5570 | arrow keys. | |
5571 | .TP | |
0001803f CR |
5572 | .B enable\-meta\-key (On) |
5573 | When set to \fBOn\fP, readline will try to enable any meta modifier | |
5574 | key the terminal claims to support when it is called. On many terminals, | |
5575 | the meta key is used to send eight-bit characters. | |
5576 | .TP | |
ccc6cda3 | 5577 | .B expand\-tilde (Off) |
495aee44 | 5578 | If set to \fBOn\fP, tilde expansion is performed when readline |
ccc6cda3 JA |
5579 | attempts word completion. |
5580 | .TP | |
95732b49 | 5581 | .B history\-preserve\-point (Off) |
495aee44 | 5582 | If set to \fBOn\fP, the history code attempts to place point at the |
95732b49 | 5583 | same location on each history line retrieved with \fBprevious-history\fP |
f73dda09 JA |
5584 | or \fBnext-history\fP. |
5585 | .TP | |
a0c0a00f | 5586 | .B history\-size (unset) |
ac50fbac CR |
5587 | Set the maximum number of history entries saved in the history list. |
5588 | If set to zero, any existing history entries are deleted and no new entries | |
5589 | are saved. | |
5590 | If set to a value less than zero, the number of history entries is not | |
5591 | limited. | |
a0c0a00f CR |
5592 | By default, the number of history entries is set to the value of the |
5593 | \fBHISTSIZE\fP shell variable. | |
5594 | If an attempt is made to set \fIhistory\-size\fP to a non-numeric value, | |
5595 | the maximum number of history entries will be set to 500. | |
3185942a | 5596 | .TP |
ccc6cda3 JA |
5597 | .B horizontal\-scroll\-mode (Off) |
5598 | When set to \fBOn\fP, makes readline use a single line for display, | |
5599 | scrolling the input horizontally on a single screen line when it | |
5600 | becomes longer than the screen width rather than wrapping to a new line. | |
5601 | .TP | |
5602 | .B input\-meta (Off) | |
5603 | If set to \fBOn\fP, readline will enable eight-bit input (that is, | |
a0c0a00f | 5604 | it will not strip the eighth bit from the characters it reads), |
ccc6cda3 JA |
5605 | regardless of what the terminal claims it can support. The name |
5606 | .B meta\-flag | |
5607 | is a synonym for this variable. | |
a0c0a00f CR |
5608 | The default is \fIOff\fP, but readline will set it to \fIOn\fP if the |
5609 | locale contains eight-bit characters. | |
ccc6cda3 | 5610 | .TP |
b72432fd JA |
5611 | .B isearch\-terminators (``C\-[C\-J'') |
5612 | The string of characters that should terminate an incremental | |
5613 | search without subsequently executing the character as a command. | |
5614 | If this variable has not been given a value, the characters | |
5615 | \fIESC\fP and \fIC\-J\fP will terminate an incremental search. | |
5616 | .TP | |
726f6388 | 5617 | .B keymap (emacs) |
cce855bc | 5618 | Set the current readline keymap. The set of valid keymap names is |
ccc6cda3 JA |
5619 | \fIemacs, emacs\-standard, emacs\-meta, emacs\-ctlx, vi, |
5620 | vi\-command\fP, and | |
5621 | .IR vi\-insert . | |
5622 | \fIvi\fP is equivalent to \fIvi\-command\fP; \fIemacs\fP is | |
5623 | equivalent to \fIemacs\-standard\fP. The default value is | |
726f6388 JA |
5624 | .IR emacs ; |
5625 | the value of | |
5626 | .B editing\-mode | |
5627 | also affects the default keymap. | |
5628 | .TP | |
a0c0a00f CR |
5629 | .B emacs\-mode\-string (@) |
5630 | This string is displayed immediately before the last line of the primary | |
5631 | prompt when emacs editing mode is active. The value is expanded like a | |
5632 | key binding, so the standard set of meta- and control prefixes and | |
5633 | backslash escape sequences is available. | |
5634 | Use the \e1 and \e2 escapes to begin and end sequences of | |
5635 | non-printing characters, which can be used to embed a terminal control | |
5636 | sequence into the mode string. | |
5637 | .TP | |
ac50fbac CR |
5638 | .B keyseq\-timeout (500) |
5639 | Specifies the duration \fIreadline\fP will wait for a character when reading an | |
5640 | ambiguous key sequence (one that can form a complete key sequence using | |
5641 | the input read so far, or can take additional input to complete a longer | |
5642 | key sequence). | |
5643 | If no input is received within the timeout, \fIreadline\fP will use the shorter | |
5644 | but complete key sequence. | |
5645 | The value is specified in milliseconds, so a value of 1000 means that | |
5646 | \fIreadline\fP will wait one second for additional input. | |
5647 | If this variable is set to a value less than or equal to zero, or to a | |
5648 | non-numeric value, \fIreadline\fP will wait until another key is pressed to | |
5649 | decide which key sequence to complete. | |
5650 | .TP | |
ccc6cda3 JA |
5651 | .B mark\-directories (On) |
5652 | If set to \fBOn\fP, completed directory names have a slash | |
5653 | appended. | |
5654 | .TP | |
5655 | .B mark\-modified\-lines (Off) | |
5656 | If set to \fBOn\fP, history lines that have been modified are displayed | |
5657 | with a preceding asterisk (\fB*\fP). | |
5658 | .TP | |
7117c2d2 JA |
5659 | .B mark\-symlinked\-directories (Off) |
5660 | If set to \fBOn\fP, completed names which are symbolic links to directories | |
5661 | have a slash appended (subject to the value of | |
5662 | \fBmark\-directories\fP). | |
5663 | .TP | |
f73dda09 JA |
5664 | .B match\-hidden\-files (On) |
5665 | This variable, when set to \fBOn\fP, causes readline to match files whose | |
a0c0a00f | 5666 | names begin with a `.' (hidden files) when performing filename |
495aee44 CR |
5667 | completion. |
5668 | If set to \fBOff\fP, the leading `.' must be | |
f73dda09 JA |
5669 | supplied by the user in the filename to be completed. |
5670 | .TP | |
495aee44 CR |
5671 | .B menu\-complete\-display\-prefix (Off) |
5672 | If set to \fBOn\fP, menu completion displays the common prefix of the | |
5673 | list of possible completions (which may be empty) before cycling through | |
5674 | the list. | |
5675 | .TP | |
ccc6cda3 JA |
5676 | .B output\-meta (Off) |
5677 | If set to \fBOn\fP, readline will display characters with the | |
5678 | eighth bit set directly rather than as a meta-prefixed escape | |
5679 | sequence. | |
a0c0a00f CR |
5680 | The default is \fIOff\fP, but readline will set it to \fIOn\fP if the |
5681 | locale contains eight-bit characters. | |
ccc6cda3 | 5682 | .TP |
7117c2d2 JA |
5683 | .B page\-completions (On) |
5684 | If set to \fBOn\fP, readline uses an internal \fImore\fP-like pager | |
5685 | to display a screenful of possible completions at a time. | |
5686 | .TP | |
cce855bc JA |
5687 | .B print\-completions\-horizontally (Off) |
5688 | If set to \fBOn\fP, readline will display completions with matches | |
5689 | sorted horizontally in alphabetical order, rather than down the screen. | |
a0c0a00f | 5690 | .TP |
3185942a | 5691 | .B revert\-all\-at\-newline (Off) |
a0c0a00f | 5692 | If set to \fBOn\fP, readline will undo all changes to history lines |
3185942a JA |
5693 | before returning when \fBaccept\-line\fP is executed. By default, |
5694 | history lines may be modified and retain individual undo lists across | |
5695 | calls to \fBreadline\fP. | |
cce855bc | 5696 | .TP |
726f6388 JA |
5697 | .B show\-all\-if\-ambiguous (Off) |
5698 | This alters the default behavior of the completion functions. If | |
5699 | set to | |
495aee44 | 5700 | .BR On , |
726f6388 JA |
5701 | words which have more than one possible completion cause the |
5702 | matches to be listed immediately instead of ringing the bell. | |
5703 | .TP | |
b80f6443 JA |
5704 | .B show\-all\-if\-unmodified (Off) |
5705 | This alters the default behavior of the completion functions in | |
5706 | a fashion similar to \fBshow\-all\-if\-ambiguous\fP. | |
5707 | If set to | |
495aee44 | 5708 | .BR On , |
b80f6443 JA |
5709 | words which have more than one possible completion without any |
5710 | possible partial completion (the possible completions don't share | |
5711 | a common prefix) cause the matches to be listed immediately instead | |
5712 | of ringing the bell. | |
5713 | .TP | |
ac50fbac CR |
5714 | .B show\-mode\-in\-prompt (Off) |
5715 | If set to \fBOn\fP, add a character to the beginning of the prompt | |
5716 | indicating the editing mode: emacs (@), vi command (:) or vi | |
5717 | insertion (+). | |
5718 | .TP | |
0001803f CR |
5719 | .B skip\-completed\-text (Off) |
5720 | If set to \fBOn\fP, this alters the default completion behavior when | |
5721 | inserting a single match into the line. It's only active when | |
5722 | performing completion in the middle of a word. If enabled, readline | |
5723 | does not insert characters from the completion that match characters | |
5724 | after point in the word being completed, so portions of the word | |
5725 | following the cursor are not duplicated. | |
5726 | .TP | |
a0c0a00f CR |
5727 | .B vi\-cmd\-mode\-string ((cmd)) |
5728 | This string is displayed immediately before the last line of the primary | |
5729 | prompt when vi editing mode is active and in command mode. | |
5730 | The value is expanded like a | |
5731 | key binding, so the standard set of meta- and control prefixes and | |
5732 | backslash escape sequences is available. | |
5733 | Use the \e1 and \e2 escapes to begin and end sequences of | |
5734 | non-printing characters, which can be used to embed a terminal control | |
5735 | sequence into the mode string. | |
5736 | .TP | |
5737 | .B vi\-ins\-mode\-string ((ins)) | |
5738 | This string is displayed immediately before the last line of the primary | |
5739 | prompt when vi editing mode is active and in insertion mode. | |
5740 | The value is expanded like a | |
5741 | key binding, so the standard set of meta- and control prefixes and | |
5742 | backslash escape sequences is available. | |
5743 | Use the \e1 and \e2 escapes to begin and end sequences of | |
5744 | non-printing characters, which can be used to embed a terminal control | |
5745 | sequence into the mode string. | |
5746 | .TP | |
ccc6cda3 JA |
5747 | .B visible\-stats (Off) |
5748 | If set to \fBOn\fP, a character denoting a file's type as reported | |
5749 | by \fIstat\fP(2) is appended to the filename when listing possible | |
5750 | completions. | |
726f6388 | 5751 | .PD |
ccc6cda3 | 5752 | .SS "Readline Conditional Constructs" |
726f6388 JA |
5753 | .PP |
5754 | Readline implements a facility similar in spirit to the conditional | |
5755 | compilation features of the C preprocessor which allows key | |
5756 | bindings and variable settings to be performed as the result | |
cce855bc | 5757 | of tests. There are four parser directives used. |
726f6388 | 5758 | .IP \fB$if\fP |
a0c0a00f | 5759 | The |
726f6388 JA |
5760 | .B $if |
5761 | construct allows bindings to be made based on the | |
5762 | editing mode, the terminal being used, or the application using | |
5763 | readline. The text of the test extends to the end of the line; | |
5764 | no characters are required to isolate it. | |
5765 | .RS | |
5766 | .IP \fBmode\fP | |
5767 | The \fBmode=\fP form of the \fB$if\fP directive is used to test | |
5768 | whether readline is in emacs or vi mode. | |
5769 | This may be used in conjunction | |
5770 | with the \fBset keymap\fP command, for instance, to set bindings in | |
ccc6cda3 | 5771 | the \fIemacs\-standard\fP and \fIemacs\-ctlx\fP keymaps only if |
726f6388 JA |
5772 | readline is starting out in emacs mode. |
5773 | .IP \fBterm\fP | |
5774 | The \fBterm=\fP form may be used to include terminal-specific | |
5775 | key bindings, perhaps to bind the key sequences output by the | |
5776 | terminal's function keys. The word on the right side of the | |
5777 | .B = | |
a0c0a00f | 5778 | is tested against both the full name of the terminal and the portion |
726f6388 JA |
5779 | of the terminal name before the first \fB\-\fP. This allows |
5780 | .I sun | |
5781 | to match both | |
5782 | .I sun | |
5783 | and | |
5784 | .IR sun\-cmd , | |
5785 | for instance. | |
5786 | .IP \fBapplication\fP | |
5787 | The \fBapplication\fP construct is used to include | |
ccc6cda3 | 5788 | application-specific settings. Each program using the readline |
726f6388 JA |
5789 | library sets the \fIapplication name\fP, and an initialization |
5790 | file can test for a particular value. | |
5791 | This could be used to bind key sequences to functions useful for | |
5792 | a specific program. For instance, the following command adds a | |
495aee44 | 5793 | key sequence that quotes the current or previous word in \fBbash\fP: |
cce855bc | 5794 | .sp 1 |
726f6388 JA |
5795 | .RS |
5796 | .nf | |
5797 | \fB$if\fP Bash | |
5798 | # Quote the current or previous word | |
ccc6cda3 | 5799 | "\eC\-xq": "\eeb\e"\eef\e"" |
726f6388 JA |
5800 | \fB$endif\fP |
5801 | .fi | |
5802 | .RE | |
5803 | .RE | |
5804 | .IP \fB$endif\fP | |
cce855bc | 5805 | This command, as seen in the previous example, terminates an |
726f6388 JA |
5806 | \fB$if\fP command. |
5807 | .IP \fB$else\fP | |
5808 | Commands in this branch of the \fB$if\fP directive are executed if | |
5809 | the test fails. | |
cce855bc JA |
5810 | .IP \fB$include\fP |
5811 | This directive takes a single filename as an argument and reads commands | |
5812 | and bindings from that file. For example, the following directive | |
5813 | would read \fI/etc/inputrc\fP: | |
5814 | .sp 1 | |
5815 | .RS | |
5816 | .nf | |
5817 | \fB$include\fP \^ \fI/etc/inputrc\fP | |
5818 | .fi | |
5819 | .RE | |
ccc6cda3 | 5820 | .SS Searching |
726f6388 | 5821 | .PP |
ccc6cda3 JA |
5822 | Readline provides commands for searching through the command history |
5823 | (see | |
5824 | .SM | |
5825 | .B HISTORY | |
5826 | below) for lines containing a specified string. | |
5827 | There are two search modes: | |
5828 | .I incremental | |
5829 | and | |
5830 | .IR non-incremental . | |
5831 | .PP | |
5832 | Incremental searches begin before the user has finished typing the | |
5833 | search string. | |
5834 | As each character of the search string is typed, readline displays | |
5835 | the next entry from the history matching the string typed so far. | |
5836 | An incremental search requires only as many characters as needed to | |
5837 | find the desired history entry. | |
bb70624e | 5838 | The characters present in the value of the \fBisearch-terminators\fP |
b72432fd JA |
5839 | variable are used to terminate an incremental search. |
5840 | If that variable has not been assigned a value the Escape and | |
5841 | Control-J characters will terminate an incremental search. | |
ccc6cda3 JA |
5842 | Control-G will abort an incremental search and restore the original |
5843 | line. | |
5844 | When the search is terminated, the history entry containing the | |
5845 | search string becomes the current line. | |
bb70624e | 5846 | .PP |
ccc6cda3 JA |
5847 | To find other matching entries in the history list, type Control-S or |
5848 | Control-R as appropriate. | |
5849 | This will search backward or forward in the history for the next | |
5850 | entry matching the search string typed so far. | |
5851 | Any other key sequence bound to a readline command will terminate | |
5852 | the search and execute that command. | |
5853 | For instance, a \fInewline\fP will terminate the search and accept | |
5854 | the line, thereby executing the command from the history list. | |
5855 | .PP | |
f73dda09 JA |
5856 | Readline remembers the last incremental search string. If two |
5857 | Control-Rs are typed without any intervening characters defining a | |
5858 | new search string, any remembered search string is used. | |
5859 | .PP | |
ccc6cda3 JA |
5860 | Non-incremental searches read the entire search string before starting |
5861 | to search for matching history lines. The search string may be | |
cce855bc | 5862 | typed by the user or be part of the contents of the current line. |
ccc6cda3 | 5863 | .SS "Readline Command Names" |
726f6388 JA |
5864 | .PP |
5865 | The following is a list of the names of the commands and the default | |
5866 | key sequences to which they are bound. | |
ccc6cda3 | 5867 | Command names without an accompanying key sequence are unbound by default. |
bb70624e JA |
5868 | In the following descriptions, \fIpoint\fP refers to the current cursor |
5869 | position, and \fImark\fP refers to a cursor position saved by the | |
5870 | \fBset\-mark\fP command. | |
5871 | The text between the point and mark is referred to as the \fIregion\fP. | |
726f6388 JA |
5872 | .SS Commands for Moving |
5873 | .PP | |
5874 | .PD 0 | |
5875 | .TP | |
5876 | .B beginning\-of\-line (C\-a) | |
5877 | Move to the start of the current line. | |
5878 | .TP | |
5879 | .B end\-of\-line (C\-e) | |
5880 | Move to the end of the line. | |
5881 | .TP | |
5882 | .B forward\-char (C\-f) | |
5883 | Move forward a character. | |
5884 | .TP | |
5885 | .B backward\-char (C\-b) | |
5886 | Move back a character. | |
5887 | .TP | |
5888 | .B forward\-word (M\-f) | |
5889 | Move forward to the end of the next word. Words are composed of | |
5890 | alphanumeric characters (letters and digits). | |
5891 | .TP | |
5892 | .B backward\-word (M\-b) | |
3185942a JA |
5893 | Move back to the start of the current or previous word. |
5894 | Words are composed of alphanumeric characters (letters and digits). | |
5895 | .TP | |
5896 | .B shell\-forward\-word | |
5897 | Move forward to the end of the next word. | |
5898 | Words are delimited by non-quoted shell metacharacters. | |
5899 | .TP | |
5900 | .B shell\-backward\-word | |
5901 | Move back to the start of the current or previous word. | |
5902 | Words are delimited by non-quoted shell metacharacters. | |
726f6388 JA |
5903 | .TP |
5904 | .B clear\-screen (C\-l) | |
5905 | Clear the screen leaving the current line at the top of the screen. | |
5906 | With an argument, refresh the current line without clearing the | |
5907 | screen. | |
5908 | .TP | |
5909 | .B redraw\-current\-line | |
ccc6cda3 | 5910 | Refresh the current line. |
726f6388 JA |
5911 | .PD |
5912 | .SS Commands for Manipulating the History | |
5913 | .PP | |
5914 | .PD 0 | |
5915 | .TP | |
5916 | .B accept\-line (Newline, Return) | |
5917 | Accept the line regardless of where the cursor is. If this line is | |
ccc6cda3 | 5918 | non-empty, add it to the history list according to the state of the |
726f6388 JA |
5919 | .SM |
5920 | .B HISTCONTROL | |
5921 | variable. If the line is a modified history | |
5922 | line, then restore the history line to its original state. | |
5923 | .TP | |
5924 | .B previous\-history (C\-p) | |
5925 | Fetch the previous command from the history list, moving back in | |
5926 | the list. | |
5927 | .TP | |
5928 | .B next\-history (C\-n) | |
5929 | Fetch the next command from the history list, moving forward in the | |
5930 | list. | |
5931 | .TP | |
5932 | .B beginning\-of\-history (M\-<) | |
5933 | Move to the first line in the history. | |
5934 | .TP | |
5935 | .B end\-of\-history (M\->) | |
5936 | Move to the end of the input history, i.e., the line currently being | |
5937 | entered. | |
5938 | .TP | |
5939 | .B reverse\-search\-history (C\-r) | |
5940 | Search backward starting at the current line and moving `up' through | |
5941 | the history as necessary. This is an incremental search. | |
5942 | .TP | |
5943 | .B forward\-search\-history (C\-s) | |
5944 | Search forward starting at the current line and moving `down' through | |
5945 | the history as necessary. This is an incremental search. | |
5946 | .TP | |
5947 | .B non\-incremental\-reverse\-search\-history (M\-p) | |
5948 | Search backward through the history starting at the current line | |
ccc6cda3 | 5949 | using a non-incremental search for a string supplied by the user. |
726f6388 JA |
5950 | .TP |
5951 | .B non\-incremental\-forward\-search\-history (M\-n) | |
ccc6cda3 | 5952 | Search forward through the history using a non-incremental search for |
726f6388 JA |
5953 | a string supplied by the user. |
5954 | .TP | |
5955 | .B history\-search\-forward | |
5956 | Search forward through the history for the string of characters | |
bb70624e | 5957 | between the start of the current line and the point. |
ccc6cda3 | 5958 | This is a non-incremental search. |
726f6388 JA |
5959 | .TP |
5960 | .B history\-search\-backward | |
5961 | Search backward through the history for the string of characters | |
ccc6cda3 JA |
5962 | between the start of the current line and the point. |
5963 | This is a non-incremental search. | |
726f6388 JA |
5964 | .TP |
5965 | .B yank\-nth\-arg (M\-C\-y) | |
5966 | Insert the first argument to the previous command (usually | |
28ef6c31 JA |
5967 | the second word on the previous line) at point. |
5968 | With an argument | |
726f6388 JA |
5969 | .IR n , |
5970 | insert the \fIn\fPth word from the previous command (the words | |
5971 | in the previous command begin with word 0). A negative argument | |
5972 | inserts the \fIn\fPth word from the end of the previous command. | |
95732b49 JA |
5973 | Once the argument \fIn\fP is computed, the argument is extracted |
5974 | as if the "!\fIn\fP" history expansion had been specified. | |
726f6388 JA |
5975 | .TP |
5976 | .B | |
5977 | yank\-last\-arg (M\-.\^, M\-_\^) | |
ccc6cda3 | 5978 | Insert the last argument to the previous command (the last word of |
495aee44 CR |
5979 | the previous history entry). |
5980 | With a numeric argument, behave exactly like \fByank\-nth\-arg\fP. | |
cce855bc | 5981 | Successive calls to \fByank\-last\-arg\fP move back through the history |
495aee44 CR |
5982 | list, inserting the last word (or the word specified by the argument to |
5983 | the first call) of each line in turn. | |
5984 | Any numeric argument supplied to these successive calls determines | |
5985 | the direction to move through the history. A negative argument switches | |
5986 | the direction through the history (back or forward). | |
ac50fbac | 5987 | The history expansion facilities are used to extract the last word, |
95732b49 | 5988 | as if the "!$" history expansion had been specified. |
726f6388 JA |
5989 | .TP |
5990 | .B shell\-expand\-line (M\-C\-e) | |
cce855bc | 5991 | Expand the line as the shell does. This |
726f6388 JA |
5992 | performs alias and history expansion as well as all of the shell |
5993 | word expansions. See | |
5994 | .SM | |
5995 | .B HISTORY EXPANSION | |
5996 | below for a description of history expansion. | |
5997 | .TP | |
5998 | .B history\-expand\-line (M\-^) | |
d166f048 JA |
5999 | Perform history expansion on the current line. |
6000 | See | |
726f6388 JA |
6001 | .SM |
6002 | .B HISTORY EXPANSION | |
6003 | below for a description of history expansion. | |
6004 | .TP | |
cce855bc JA |
6005 | .B magic\-space |
6006 | Perform history expansion on the current line and insert a space. | |
6007 | See | |
6008 | .SM | |
6009 | .B HISTORY EXPANSION | |
6010 | below for a description of history expansion. | |
6011 | .TP | |
d166f048 JA |
6012 | .B alias\-expand\-line |
6013 | Perform alias expansion on the current line. | |
6014 | See | |
6015 | .SM | |
6016 | .B ALIASES | |
6017 | above for a description of alias expansion. | |
6018 | .TP | |
6019 | .B history\-and\-alias\-expand\-line | |
6020 | Perform history and alias expansion on the current line. | |
6021 | .TP | |
726f6388 JA |
6022 | .B insert\-last\-argument (M\-.\^, M\-_\^) |
6023 | A synonym for \fByank\-last\-arg\fP. | |
6024 | .TP | |
ccc6cda3 | 6025 | .B operate\-and\-get\-next (C\-o) |
726f6388 JA |
6026 | Accept the current line for execution and fetch the next line |
6027 | relative to the current line from the history for editing. Any | |
6028 | argument is ignored. | |
7117c2d2 JA |
6029 | .TP |
6030 | .B edit\-and\-execute\-command (C\-xC\-e) | |
6031 | Invoke an editor on the current command line, and execute the result as shell | |
6032 | commands. | |
6033 | \fBBash\fP attempts to invoke | |
6034 | .SM | |
3185942a | 6035 | .BR $VISUAL , |
7117c2d2 JA |
6036 | .SM |
6037 | .BR $EDITOR , | |
6038 | and \fIemacs\fP as the editor, in that order. | |
726f6388 JA |
6039 | .PD |
6040 | .SS Commands for Changing Text | |
6041 | .PP | |
6042 | .PD 0 | |
6043 | .TP | |
ac50fbac CR |
6044 | .B \fIend\-of\-file\fP (usually C\-d) |
6045 | The character indicating end-of-file as set, for example, by | |
6046 | .if t \f(CWstty\fP. | |
6047 | .if n ``stty''. | |
6048 | If this character is read when there are no characters | |
6049 | on the line, and point is at the beginning of the line, Readline | |
6050 | interprets it as the end of input and returns | |
726f6388 JA |
6051 | .SM |
6052 | .BR EOF . | |
6053 | .TP | |
ac50fbac CR |
6054 | .B delete\-char (C\-d) |
6055 | Delete the character at point. | |
6056 | If this function is bound to the | |
6057 | same character as the tty \fBEOF\fP character, as \fBC\-d\fP | |
6058 | commonly is, see above for the effects. | |
6059 | .TP | |
726f6388 JA |
6060 | .B backward\-delete\-char (Rubout) |
6061 | Delete the character behind the cursor. When given a numeric argument, | |
ccc6cda3 | 6062 | save the deleted text on the kill ring. |
726f6388 | 6063 | .TP |
b72432fd JA |
6064 | .B forward\-backward\-delete\-char |
6065 | Delete the character under the cursor, unless the cursor is at the | |
6066 | end of the line, in which case the character behind the cursor is | |
f73dda09 | 6067 | deleted. |
b72432fd | 6068 | .TP |
726f6388 | 6069 | .B quoted\-insert (C\-q, C\-v) |
cce855bc | 6070 | Add the next character typed to the line verbatim. This is |
726f6388 JA |
6071 | how to insert characters like \fBC\-q\fP, for example. |
6072 | .TP | |
ccc6cda3 | 6073 | .B tab\-insert (C\-v TAB) |
726f6388 JA |
6074 | Insert a tab character. |
6075 | .TP | |
6076 | .B self\-insert (a,\ b,\ A,\ 1,\ !,\ ...) | |
6077 | Insert the character typed. | |
6078 | .TP | |
6079 | .B transpose\-chars (C\-t) | |
28ef6c31 JA |
6080 | Drag the character before point forward over the character at point, |
6081 | moving point forward as well. | |
6082 | If point is at the end of the line, then this transposes | |
6083 | the two characters before point. | |
bb70624e | 6084 | Negative arguments have no effect. |
726f6388 JA |
6085 | .TP |
6086 | .B transpose\-words (M\-t) | |
bb70624e | 6087 | Drag the word before point past the word after point, |
28ef6c31 | 6088 | moving point over that word as well. |
f73dda09 | 6089 | If point is at the end of the line, this transposes |
a0c0a00f | 6090 | the last two words on the line. |
726f6388 JA |
6091 | .TP |
6092 | .B upcase\-word (M\-u) | |
6093 | Uppercase the current (or following) word. With a negative argument, | |
cce855bc | 6094 | uppercase the previous word, but do not move point. |
726f6388 JA |
6095 | .TP |
6096 | .B downcase\-word (M\-l) | |
6097 | Lowercase the current (or following) word. With a negative argument, | |
cce855bc | 6098 | lowercase the previous word, but do not move point. |
726f6388 JA |
6099 | .TP |
6100 | .B capitalize\-word (M\-c) | |
6101 | Capitalize the current (or following) word. With a negative argument, | |
cce855bc | 6102 | capitalize the previous word, but do not move point. |
7117c2d2 JA |
6103 | .TP |
6104 | .B overwrite\-mode | |
6105 | Toggle overwrite mode. With an explicit positive numeric argument, | |
6106 | switches to overwrite mode. With an explicit non-positive numeric | |
6107 | argument, switches to insert mode. This command affects only | |
6108 | \fBemacs\fP mode; \fBvi\fP mode does overwrite differently. | |
6109 | Each call to \fIreadline()\fP starts in insert mode. | |
a0c0a00f | 6110 | In overwrite mode, characters bound to \fBself\-insert\fP replace |
7117c2d2 JA |
6111 | the text at point rather than pushing the text to the right. |
6112 | Characters bound to \fBbackward\-delete\-char\fP replace the character | |
6113 | before point with a space. By default, this command is unbound. | |
726f6388 JA |
6114 | .PD |
6115 | .SS Killing and Yanking | |
6116 | .PP | |
6117 | .PD 0 | |
6118 | .TP | |
6119 | .B kill\-line (C\-k) | |
bb70624e | 6120 | Kill the text from point to the end of the line. |
726f6388 | 6121 | .TP |
ccc6cda3 | 6122 | .B backward\-kill\-line (C\-x Rubout) |
726f6388 JA |
6123 | Kill backward to the beginning of the line. |
6124 | .TP | |
6125 | .B unix\-line\-discard (C\-u) | |
6126 | Kill backward from point to the beginning of the line. | |
cce855bc | 6127 | The killed text is saved on the kill-ring. |
bb70624e | 6128 | .\" There is no real difference between this and backward-kill-line |
726f6388 JA |
6129 | .TP |
6130 | .B kill\-whole\-line | |
bb70624e | 6131 | Kill all characters on the current line, no matter where point is. |
726f6388 | 6132 | .TP |
a0c0a00f | 6133 | .B kill\-word (M\-d) |
bb70624e JA |
6134 | Kill from point to the end of the current word, or if between |
6135 | words, to the end of the next word. | |
6136 | Word boundaries are the same as those used by \fBforward\-word\fP. | |
726f6388 JA |
6137 | .TP |
6138 | .B backward\-kill\-word (M\-Rubout) | |
bb70624e JA |
6139 | Kill the word behind point. |
6140 | Word boundaries are the same as those used by \fBbackward\-word\fP. | |
726f6388 | 6141 | .TP |
a0c0a00f | 6142 | .B shell\-kill\-word |
3185942a JA |
6143 | Kill from point to the end of the current word, or if between |
6144 | words, to the end of the next word. | |
6145 | Word boundaries are the same as those used by \fBshell\-forward\-word\fP. | |
6146 | .TP | |
a0c0a00f | 6147 | .B shell\-backward\-kill\-word |
3185942a JA |
6148 | Kill the word behind point. |
6149 | Word boundaries are the same as those used by \fBshell\-backward\-word\fP. | |
6150 | .TP | |
726f6388 | 6151 | .B unix\-word\-rubout (C\-w) |
bb70624e | 6152 | Kill the word behind point, using white space as a word boundary. |
bb70624e | 6153 | The killed text is saved on the kill-ring. |
ccc6cda3 | 6154 | .TP |
b80f6443 JA |
6155 | .B unix\-filename\-rubout |
6156 | Kill the word behind point, using white space and the slash character | |
6157 | as the word boundaries. | |
6158 | The killed text is saved on the kill-ring. | |
6159 | .TP | |
ccc6cda3 JA |
6160 | .B delete\-horizontal\-space (M\-\e) |
6161 | Delete all spaces and tabs around point. | |
6162 | .TP | |
6163 | .B kill\-region | |
bb70624e | 6164 | Kill the text in the current region. |
ccc6cda3 JA |
6165 | .TP |
6166 | .B copy\-region\-as\-kill | |
6167 | Copy the text in the region to the kill buffer. | |
726f6388 | 6168 | .TP |
ccc6cda3 JA |
6169 | .B copy\-backward\-word |
6170 | Copy the word before point to the kill buffer. | |
cce855bc | 6171 | The word boundaries are the same as \fBbackward\-word\fP. |
ccc6cda3 JA |
6172 | .TP |
6173 | .B copy\-forward\-word | |
6174 | Copy the word following point to the kill buffer. | |
cce855bc | 6175 | The word boundaries are the same as \fBforward\-word\fP. |
726f6388 JA |
6176 | .TP |
6177 | .B yank (C\-y) | |
28ef6c31 | 6178 | Yank the top of the kill ring into the buffer at point. |
726f6388 JA |
6179 | .TP |
6180 | .B yank\-pop (M\-y) | |
ccc6cda3 | 6181 | Rotate the kill ring, and yank the new top. Only works following |
726f6388 JA |
6182 | .B yank |
6183 | or | |
6184 | .BR yank\-pop . | |
6185 | .PD | |
6186 | .SS Numeric Arguments | |
6187 | .PP | |
6188 | .PD 0 | |
6189 | .TP | |
6190 | .B digit\-argument (M\-0, M\-1, ..., M\-\-) | |
6191 | Add this digit to the argument already accumulating, or start a new | |
6192 | argument. M\-\- starts a negative argument. | |
6193 | .TP | |
6194 | .B universal\-argument | |
d166f048 JA |
6195 | This is another way to specify an argument. |
6196 | If this command is followed by one or more digits, optionally with a | |
6197 | leading minus sign, those digits define the argument. | |
6198 | If the command is followed by digits, executing | |
6199 | .B universal\-argument | |
6200 | again ends the numeric argument, but is otherwise ignored. | |
6201 | As a special case, if this command is immediately followed by a | |
a0c0a00f | 6202 | character that is neither a digit nor minus sign, the argument count |
d166f048 | 6203 | for the next command is multiplied by four. |
726f6388 | 6204 | The argument count is initially one, so executing this function the |
d166f048 JA |
6205 | first time makes the argument count four, a second time makes the |
6206 | argument count sixteen, and so on. | |
726f6388 JA |
6207 | .PD |
6208 | .SS Completing | |
6209 | .PP | |
6210 | .PD 0 | |
6211 | .TP | |
6212 | .B complete (TAB) | |
6213 | Attempt to perform completion on the text before point. | |
6214 | .B Bash | |
6215 | attempts completion treating the text as a variable (if the | |
6216 | text begins with \fB$\fP), username (if the text begins with | |
6217 | \fB~\fP), hostname (if the text begins with \fB@\fP), or | |
6218 | command (including aliases and functions) in turn. If none | |
6219 | of these produces a match, filename completion is attempted. | |
6220 | .TP | |
ccc6cda3 | 6221 | .B possible\-completions (M\-?) |
726f6388 JA |
6222 | List the possible completions of the text before point. |
6223 | .TP | |
ccc6cda3 | 6224 | .B insert\-completions (M\-*) |
726f6388 JA |
6225 | Insert all completions of the text before point |
6226 | that would have been generated by | |
ccc6cda3 | 6227 | \fBpossible\-completions\fP. |
726f6388 | 6228 | .TP |
cce855bc JA |
6229 | .B menu\-complete |
6230 | Similar to \fBcomplete\fP, but replaces the word to be completed | |
6231 | with a single match from the list of possible completions. | |
6232 | Repeated execution of \fBmenu\-complete\fP steps through the list | |
6233 | of possible completions, inserting each match in turn. | |
28ef6c31 | 6234 | At the end of the list of completions, the bell is rung |
f73dda09 | 6235 | (subject to the setting of \fBbell\-style\fP) |
28ef6c31 | 6236 | and the original text is restored. |
cce855bc JA |
6237 | An argument of \fIn\fP moves \fIn\fP positions forward in the list |
6238 | of matches; a negative argument may be used to move backward | |
6239 | through the list. | |
6240 | This command is intended to be bound to \fBTAB\fP, but is unbound | |
6241 | by default. | |
6242 | .TP | |
495aee44 | 6243 | .B menu\-complete\-backward |
0001803f CR |
6244 | Identical to \fBmenu\-complete\fP, but moves backward through the list |
6245 | of possible completions, as if \fBmenu\-complete\fP had been given a | |
6246 | negative argument. This command is unbound by default. | |
6247 | .TP | |
b72432fd JA |
6248 | .B delete\-char\-or\-list |
6249 | Deletes the character under the cursor if not at the beginning or | |
bb70624e | 6250 | end of the line (like \fBdelete\-char\fP). |
b72432fd | 6251 | If at the end of the line, behaves identically to |
bb70624e | 6252 | \fBpossible\-completions\fP. |
b72432fd JA |
6253 | This command is unbound by default. |
6254 | .TP | |
726f6388 JA |
6255 | .B complete\-filename (M\-/) |
6256 | Attempt filename completion on the text before point. | |
6257 | .TP | |
6258 | .B possible\-filename\-completions (C\-x /) | |
6259 | List the possible completions of the text before point, | |
6260 | treating it as a filename. | |
6261 | .TP | |
6262 | .B complete\-username (M\-~) | |
6263 | Attempt completion on the text before point, treating | |
6264 | it as a username. | |
6265 | .TP | |
6266 | .B possible\-username\-completions (C\-x ~) | |
6267 | List the possible completions of the text before point, | |
6268 | treating it as a username. | |
6269 | .TP | |
6270 | .B complete\-variable (M\-$) | |
6271 | Attempt completion on the text before point, treating | |
6272 | it as a shell variable. | |
6273 | .TP | |
6274 | .B possible\-variable\-completions (C\-x $) | |
6275 | List the possible completions of the text before point, | |
6276 | treating it as a shell variable. | |
6277 | .TP | |
6278 | .B complete\-hostname (M\-@) | |
6279 | Attempt completion on the text before point, treating | |
6280 | it as a hostname. | |
6281 | .TP | |
6282 | .B possible\-hostname\-completions (C\-x @) | |
6283 | List the possible completions of the text before point, | |
6284 | treating it as a hostname. | |
6285 | .TP | |
6286 | .B complete\-command (M\-!) | |
6287 | Attempt completion on the text before point, treating | |
6288 | it as a command name. Command completion attempts to | |
6289 | match the text against aliases, reserved words, shell | |
cce855bc | 6290 | functions, shell builtins, and finally executable filenames, |
726f6388 JA |
6291 | in that order. |
6292 | .TP | |
6293 | .B possible\-command\-completions (C\-x !) | |
6294 | List the possible completions of the text before point, | |
6295 | treating it as a command name. | |
6296 | .TP | |
ccc6cda3 | 6297 | .B dynamic\-complete\-history (M\-TAB) |
726f6388 JA |
6298 | Attempt completion on the text before point, comparing |
6299 | the text against lines from the history list for possible | |
6300 | completion matches. | |
6301 | .TP | |
3185942a JA |
6302 | .B dabbrev\-expand |
6303 | Attempt menu completion on the text before point, comparing | |
6304 | the text against lines from the history list for possible | |
6305 | completion matches. | |
6306 | .TP | |
726f6388 | 6307 | .B complete\-into\-braces (M\-{) |
bb70624e | 6308 | Perform filename completion and insert the list of possible completions |
726f6388 JA |
6309 | enclosed within braces so the list is available to the shell (see |
6310 | .B Brace Expansion | |
6311 | above). | |
6312 | .PD | |
6313 | .SS Keyboard Macros | |
6314 | .PP | |
6315 | .PD 0 | |
6316 | .TP | |
ccc6cda3 | 6317 | .B start\-kbd\-macro (C\-x (\^) |
726f6388 JA |
6318 | Begin saving the characters typed into the current keyboard macro. |
6319 | .TP | |
ccc6cda3 | 6320 | .B end\-kbd\-macro (C\-x )\^) |
726f6388 | 6321 | Stop saving the characters typed into the current keyboard macro |
ccc6cda3 | 6322 | and store the definition. |
726f6388 | 6323 | .TP |
ccc6cda3 | 6324 | .B call\-last\-kbd\-macro (C\-x e) |
726f6388 JA |
6325 | Re-execute the last keyboard macro defined, by making the characters |
6326 | in the macro appear as if typed at the keyboard. | |
ac50fbac CR |
6327 | .TP |
6328 | .B print\-last\-kbd\-macro () | |
6329 | Print the last keyboard macro defined in a format suitable for the | |
6330 | \fIinputrc\fP file. | |
726f6388 JA |
6331 | .PD |
6332 | .SS Miscellaneous | |
6333 | .PP | |
6334 | .PD 0 | |
6335 | .TP | |
6336 | .B re\-read\-init\-file (C\-x C\-r) | |
ccc6cda3 | 6337 | Read in the contents of the \fIinputrc\fP file, and incorporate |
726f6388 JA |
6338 | any bindings or variable assignments found there. |
6339 | .TP | |
6340 | .B abort (C\-g) | |
6341 | Abort the current editing command and | |
6342 | ring the terminal's bell (subject to the setting of | |
6343 | .BR bell\-style ). | |
6344 | .TP | |
ccc6cda3 JA |
6345 | .B do\-uppercase\-version (M\-a, M\-b, M\-\fIx\fP, ...) |
6346 | If the metafied character \fIx\fP is lowercase, run the command | |
6347 | that is bound to the corresponding uppercase character. | |
726f6388 JA |
6348 | .TP |
6349 | .B prefix\-meta (ESC) | |
6350 | Metafy the next character typed. | |
6351 | .SM | |
6352 | .B ESC | |
6353 | .B f | |
6354 | is equivalent to | |
6355 | .BR Meta\-f . | |
6356 | .TP | |
6357 | .B undo (C\-_, C\-x C\-u) | |
6358 | Incremental undo, separately remembered for each line. | |
6359 | .TP | |
6360 | .B revert\-line (M\-r) | |
cce855bc | 6361 | Undo all changes made to this line. This is like executing the |
726f6388 JA |
6362 | .B undo |
6363 | command enough times to return the line to its initial state. | |
6364 | .TP | |
b72432fd | 6365 | .B tilde\-expand (M\-&) |
726f6388 JA |
6366 | Perform tilde expansion on the current word. |
6367 | .TP | |
ccc6cda3 | 6368 | .B set\-mark (C\-@, M\-<space>) |
28ef6c31 | 6369 | Set the mark to the point. If a |
ccc6cda3 JA |
6370 | numeric argument is supplied, the mark is set to that position. |
6371 | .TP | |
6372 | .B exchange\-point\-and\-mark (C\-x C\-x) | |
6373 | Swap the point with the mark. The current cursor position is set to | |
6374 | the saved position, and the old cursor position is saved as the mark. | |
6375 | .TP | |
6376 | .B character\-search (C\-]) | |
6377 | A character is read and point is moved to the next occurrence of that | |
6378 | character. A negative count searches for previous occurrences. | |
6379 | .TP | |
6380 | .B character\-search\-backward (M\-C\-]) | |
6381 | A character is read and point is moved to the previous occurrence of that | |
6382 | character. A negative count searches for subsequent occurrences. | |
6383 | .TP | |
495aee44 | 6384 | .B skip\-csi\-sequence |
0001803f CR |
6385 | Read enough characters to consume a multi-key sequence such as those |
6386 | defined for keys like Home and End. Such sequences begin with a | |
6387 | Control Sequence Indicator (CSI), usually ESC\-[. If this sequence is | |
6388 | bound to "\e[", keys producing such sequences will have no effect | |
6389 | unless explicitly bound to a readline command, instead of inserting | |
6390 | stray characters into the editing buffer. This is unbound by default, | |
6391 | but usually bound to ESC\-[. | |
6392 | .TP | |
ccc6cda3 | 6393 | .B insert\-comment (M\-#) |
7117c2d2 | 6394 | Without a numeric argument, the value of the readline |
ccc6cda3 | 6395 | .B comment\-begin |
7117c2d2 | 6396 | variable is inserted at the beginning of the current line. |
a0c0a00f | 6397 | If a numeric argument is supplied, this command acts as a toggle: if |
7117c2d2 JA |
6398 | the characters at the beginning of the line do not match the value |
6399 | of \fBcomment\-begin\fP, the value is inserted, otherwise | |
a0c0a00f | 6400 | the characters in \fBcomment\-begin\fP are deleted from the beginning of |
7117c2d2 JA |
6401 | the line. |
6402 | In either case, the line is accepted as if a newline had been typed. | |
6403 | The default value of | |
bb70624e | 6404 | \fBcomment\-begin\fP causes this command to make the current line |
ccc6cda3 | 6405 | a shell comment. |
7117c2d2 JA |
6406 | If a numeric argument causes the comment character to be removed, the line |
6407 | will be executed by the shell. | |
6408 | .TP | |
6409 | .B glob\-complete\-word (M\-g) | |
6410 | The word before point is treated as a pattern for pathname expansion, | |
6411 | with an asterisk implicitly appended. This pattern is used to | |
ac50fbac | 6412 | generate a list of matching filenames for possible completions. |
ccc6cda3 JA |
6413 | .TP |
6414 | .B glob\-expand\-word (C\-x *) | |
6415 | The word before point is treated as a pattern for pathname expansion, | |
ac50fbac | 6416 | and the list of matching filenames is inserted, replacing the word. |
7117c2d2 JA |
6417 | If a numeric argument is supplied, an asterisk is appended before |
6418 | pathname expansion. | |
ccc6cda3 JA |
6419 | .TP |
6420 | .B glob\-list\-expansions (C\-x g) | |
6421 | The list of expansions that would have been generated by | |
6422 | .B glob\-expand\-word | |
6423 | is displayed, and the line is redrawn. | |
7117c2d2 JA |
6424 | If a numeric argument is supplied, an asterisk is appended before |
6425 | pathname expansion. | |
ccc6cda3 | 6426 | .TP |
726f6388 JA |
6427 | .B dump\-functions |
6428 | Print all of the functions and their key bindings to the | |
6429 | readline output stream. If a numeric argument is supplied, | |
6430 | the output is formatted in such a way that it can be made part | |
6431 | of an \fIinputrc\fP file. | |
6432 | .TP | |
ccc6cda3 JA |
6433 | .B dump\-variables |
6434 | Print all of the settable readline variables and their values to the | |
6435 | readline output stream. If a numeric argument is supplied, | |
6436 | the output is formatted in such a way that it can be made part | |
6437 | of an \fIinputrc\fP file. | |
6438 | .TP | |
6439 | .B dump\-macros | |
6440 | Print all of the readline key sequences bound to macros and the | |
95732b49 | 6441 | strings they output. If a numeric argument is supplied, |
ccc6cda3 JA |
6442 | the output is formatted in such a way that it can be made part |
6443 | of an \fIinputrc\fP file. | |
6444 | .TP | |
726f6388 JA |
6445 | .B display\-shell\-version (C\-x C\-v) |
6446 | Display version information about the current instance of | |
6447 | .BR bash . | |
6448 | .PD | |
bb70624e JA |
6449 | .SS Programmable Completion |
6450 | .PP | |
6451 | When word completion is attempted for an argument to a command for | |
6452 | which a completion specification (a \fIcompspec\fP) has been defined | |
6453 | using the \fBcomplete\fP builtin (see | |
6454 | .SM | |
6455 | .B "SHELL BUILTIN COMMANDS" | |
6456 | below), the programmable completion facilities are invoked. | |
6457 | .PP | |
6458 | First, the command name is identified. | |
0001803f CR |
6459 | If the command word is the empty string (completion attempted at the |
6460 | beginning of an empty line), any compspec defined with | |
6461 | the \fB\-E\fP option to \fBcomplete\fP is used. | |
bb70624e JA |
6462 | If a compspec has been defined for that command, the |
6463 | compspec is used to generate the list of possible completions for the word. | |
6464 | If the command word is a full pathname, a compspec for the full | |
6465 | pathname is searched for first. | |
6466 | If no compspec is found for the full pathname, an attempt is made to | |
6467 | find a compspec for the portion following the final slash. | |
495aee44 | 6468 | If those searches do not result in a compspec, any compspec defined with |
0001803f | 6469 | the \fB\-D\fP option to \fBcomplete\fP is used as the default. |
bb70624e JA |
6470 | .PP |
6471 | Once a compspec has been found, it is used to generate the list of | |
6472 | matching words. | |
6473 | If a compspec is not found, the default \fBbash\fP completion as | |
6474 | described above under \fBCompleting\fP is performed. | |
6475 | .PP | |
6476 | First, the actions specified by the compspec are used. | |
6477 | Only matches which are prefixed by the word being completed are | |
6478 | returned. | |
6479 | When the | |
6480 | .B \-f | |
6481 | or | |
6482 | .B \-d | |
6483 | option is used for filename or directory name completion, the shell | |
6484 | variable | |
6485 | .SM | |
6486 | .B FIGNORE | |
6487 | is used to filter the matches. | |
6488 | .PP | |
0001803f | 6489 | Any completions specified by a pathname expansion pattern to the |
bb70624e JA |
6490 | \fB\-G\fP option are generated next. |
6491 | The words generated by the pattern need not match the word | |
6492 | being completed. | |
6493 | The | |
6494 | .SM | |
6495 | .B GLOBIGNORE | |
6496 | shell variable is not used to filter the matches, but the | |
6497 | .SM | |
6498 | .B FIGNORE | |
6499 | variable is used. | |
6500 | .PP | |
6501 | Next, the string specified as the argument to the \fB\-W\fP option | |
6502 | is considered. | |
6503 | The string is first split using the characters in the | |
6504 | .SM | |
6505 | .B IFS | |
6506 | special variable as delimiters. | |
6507 | Shell quoting is honored. | |
6508 | Each word is then expanded using | |
6509 | brace expansion, tilde expansion, parameter and variable expansion, | |
95732b49 | 6510 | command substitution, and arithmetic expansion, |
a0c0a00f | 6511 | as described above under |
bb70624e JA |
6512 | .SM |
6513 | .BR EXPANSION . | |
6514 | The results are split using the rules described above under | |
6515 | \fBWord Splitting\fP. | |
6516 | The results of the expansion are prefix-matched against the word being | |
6517 | completed, and the matching words become the possible completions. | |
6518 | .PP | |
6519 | After these matches have been generated, any shell function or command | |
6520 | specified with the \fB\-F\fP and \fB\-C\fP options is invoked. | |
6521 | When the command or function is invoked, the | |
6522 | .SM | |
3185942a JA |
6523 | .BR COMP_LINE , |
6524 | .SM | |
6525 | .BR COMP_POINT , | |
6526 | .SM | |
6527 | .BR COMP_KEY , | |
bb70624e JA |
6528 | and |
6529 | .SM | |
3185942a | 6530 | .B COMP_TYPE |
bb70624e JA |
6531 | variables are assigned values as described above under |
6532 | \fBShell Variables\fP. | |
a0c0a00f | 6533 | If a shell function is being invoked, the |
bb70624e JA |
6534 | .SM |
6535 | .B COMP_WORDS | |
6536 | and | |
6537 | .SM | |
6538 | .B COMP_CWORD | |
6539 | variables are also set. | |
ac50fbac CR |
6540 | When the function or command is invoked, |
6541 | the first argument (\fB$1\fP) is the name of the command whose arguments are | |
6542 | being completed, | |
6543 | the second argument (\fB$2\fP) is the word being completed, | |
6544 | and the third argument (\fB$3\fP) is the word preceding the word being | |
6545 | completed on the current command line. | |
bb70624e JA |
6546 | No filtering of the generated completions against the word being completed |
6547 | is performed; the function or command has complete freedom in generating | |
6548 | the matches. | |
6549 | .PP | |
6550 | Any function specified with \fB\-F\fP is invoked first. | |
6551 | The function may use any of the shell facilities, including the | |
6552 | \fBcompgen\fP builtin described below, to generate the matches. | |
6553 | It must put the possible completions in the | |
6554 | .SM | |
6555 | .B COMPREPLY | |
ac50fbac | 6556 | array variable, one per array element. |
bb70624e JA |
6557 | .PP |
6558 | Next, any command specified with the \fB\-C\fP option is invoked | |
6559 | in an environment equivalent to command substitution. | |
6560 | It should print a list of completions, one per line, to the | |
6561 | standard output. | |
6562 | Backslash may be used to escape a newline, if necessary. | |
6563 | .PP | |
6564 | After all of the possible completions are generated, any filter | |
6565 | specified with the \fB\-X\fP option is applied to the list. | |
6566 | The filter is a pattern as used for pathname expansion; a \fB&\fP | |
6567 | in the pattern is replaced with the text of the word being completed. | |
6568 | A literal \fB&\fP may be escaped with a backslash; the backslash | |
6569 | is removed before attempting a match. | |
6570 | Any completion that matches the pattern will be removed from the list. | |
6571 | A leading \fB!\fP negates the pattern; in this case any completion | |
6572 | not matching the pattern will be removed. | |
a0c0a00f CR |
6573 | If the |
6574 | .B nocasematch | |
6575 | shell option is enabled, the match is performed without regard to the case | |
6576 | of alphabetic characters. | |
bb70624e JA |
6577 | .PP |
6578 | Finally, any prefix and suffix specified with the \fB\-P\fP and \fB\-S\fP | |
6579 | options are added to each member of the completion list, and the result is | |
6580 | returned to the readline completion code as the list of possible | |
6581 | completions. | |
6582 | .PP | |
28ef6c31 JA |
6583 | If the previously-applied actions do not generate any matches, and the |
6584 | \fB\-o dirnames\fP option was supplied to \fBcomplete\fP when the | |
6585 | compspec was defined, directory name completion is attempted. | |
6586 | .PP | |
b80f6443 JA |
6587 | If the \fB\-o plusdirs\fP option was supplied to \fBcomplete\fP when the |
6588 | compspec was defined, directory name completion is attempted and any | |
6589 | matches are added to the results of the other actions. | |
6590 | .PP | |
28ef6c31 JA |
6591 | By default, if a compspec is found, whatever it generates is returned |
6592 | to the completion code as the full set of possible completions. | |
bb70624e JA |
6593 | The default \fBbash\fP completions are not attempted, and the readline |
6594 | default of filename completion is disabled. | |
b80f6443 JA |
6595 | If the \fB\-o bashdefault\fP option was supplied to \fBcomplete\fP when |
6596 | the compspec was defined, the \fBbash\fP default completions are attempted | |
28ef6c31 | 6597 | if the compspec generates no matches. |
b80f6443 JA |
6598 | If the \fB\-o default\fP option was supplied to \fBcomplete\fP when the |
6599 | compspec was defined, readline's default completion will be performed | |
6600 | if the compspec (and, if attempted, the default \fBbash\fP completions) | |
6601 | generate no matches. | |
7117c2d2 JA |
6602 | .PP |
6603 | When a compspec indicates that directory name completion is desired, | |
6604 | the programmable completion functions force readline to append a slash | |
a0c0a00f | 6605 | to completed names which are symbolic links to directories, subject to |
7117c2d2 JA |
6606 | the value of the \fBmark\-directories\fP readline variable, regardless |
6607 | of the setting of the \fBmark-symlinked\-directories\fP readline variable. | |
0001803f CR |
6608 | .PP |
6609 | There is some support for dynamically modifying completions. This is | |
6610 | most useful when used in combination with a default completion specified | |
6611 | with \fBcomplete -D\fP. | |
6612 | It's possible for shell functions executed as completion | |
6613 | handlers to indicate that completion should be retried by returning an | |
6614 | exit status of 124. If a shell function returns 124, and changes | |
6615 | the compspec associated with the command on which completion is being | |
6616 | attempted (supplied as the first argument when the function is executed), | |
6617 | programmable completion restarts from the beginning, with an | |
495aee44 | 6618 | attempt to find a new compspec for that command. This allows a set of |
0001803f CR |
6619 | completions to be built dynamically as completion is attempted, rather than |
6620 | being loaded all at once. | |
6621 | .PP | |
6622 | For instance, assuming that there is a library of compspecs, each kept in a | |
6623 | file corresponding to the name of the command, the following default | |
6624 | completion function would load completions dynamically: | |
6625 | .PP | |
6626 | \f(CW_completion_loader() | |
6627 | .br | |
6628 | { | |
6629 | .br | |
6630 | . "/etc/bash_completion.d/$1.sh" >/dev/null 2>&1 && return 124 | |
6631 | .br | |
6632 | } | |
6633 | .br | |
ac50fbac | 6634 | complete -D -F _completion_loader -o bashdefault -o default |
0001803f CR |
6635 | .br |
6636 | \fP | |
726f6388 | 6637 | .SH HISTORY |
ccc6cda3 | 6638 | When the |
d166f048 | 6639 | .B \-o history |
ccc6cda3 JA |
6640 | option to the |
6641 | .B set | |
6642 | builtin is enabled, the shell provides access to the | |
6643 | \fIcommand history\fP, | |
bb70624e | 6644 | the list of commands previously typed. |
0001803f CR |
6645 | The value of the |
6646 | .SM | |
6647 | .B HISTSIZE | |
6648 | variable is used as the | |
bb70624e JA |
6649 | number of commands to save in a history list. |
6650 | The text of the last | |
726f6388 JA |
6651 | .SM |
6652 | .B HISTSIZE | |
bb70624e | 6653 | commands (default 500) is saved. The shell |
726f6388 JA |
6654 | stores each command in the history list prior to parameter and |
6655 | variable expansion (see | |
6656 | .SM | |
6657 | .B EXPANSION | |
6658 | above) but after history expansion is performed, subject to the | |
6659 | values of the shell variables | |
ccc6cda3 JA |
6660 | .SM |
6661 | .B HISTIGNORE | |
726f6388 JA |
6662 | and |
6663 | .SM | |
6664 | .BR HISTCONTROL . | |
bb70624e | 6665 | .PP |
726f6388 JA |
6666 | On startup, the history is initialized from the file named by |
6667 | the variable | |
6668 | .SM | |
6669 | .B HISTFILE | |
6670 | (default \fI~/.bash_history\fP). | |
bb70624e | 6671 | The file named by the value of |
726f6388 JA |
6672 | .SM |
6673 | .B HISTFILE | |
6674 | is truncated, if necessary, to contain no more than | |
bb70624e | 6675 | the number of lines specified by the value of |
726f6388 | 6676 | .SM |
bb70624e | 6677 | .BR HISTFILESIZE . |
ac50fbac CR |
6678 | If \fBHISTFILESIZE\fP is unset, or set to null, a non-numeric value, |
6679 | or a numeric value less than zero, the history file is not truncated. | |
3185942a JA |
6680 | When the history file is read, |
6681 | lines beginning with the history comment character followed immediately | |
6682 | by a digit are interpreted as timestamps for the preceding history line. | |
6683 | These timestamps are optionally displayed depending on the value of the | |
6684 | .SM | |
6685 | .B HISTTIMEFORMAT | |
6686 | variable. | |
ac50fbac | 6687 | When a shell with history enabled exits, the last |
ccc6cda3 | 6688 | .SM |
bb70624e | 6689 | .B $HISTSIZE |
ccc6cda3 JA |
6690 | lines are copied from the history list to |
6691 | .SM | |
bb70624e | 6692 | .BR $HISTFILE . |
ccc6cda3 JA |
6693 | If the |
6694 | .B histappend | |
6695 | shell option is enabled | |
6696 | (see the description of | |
6697 | .B shopt | |
6698 | under | |
6699 | .SM | |
6700 | .B "SHELL BUILTIN COMMANDS" | |
6701 | below), the lines are appended to the history file, | |
6702 | otherwise the history file is overwritten. | |
6703 | If | |
6704 | .SM | |
6705 | .B HISTFILE | |
6706 | is unset, or if the history file is unwritable, the history is | |
3185942a JA |
6707 | not saved. |
6708 | If the | |
6709 | .SM | |
0001803f | 6710 | .B HISTTIMEFORMAT |
3185942a JA |
6711 | variable is set, time stamps are written to the history file, marked |
6712 | with the history comment character, so | |
6713 | they may be preserved across shell sessions. | |
6714 | This uses the history comment character to distinguish timestamps from | |
6715 | other history lines. | |
6716 | After saving the history, the history file is truncated | |
ccc6cda3 JA |
6717 | to contain no more than |
6718 | .SM | |
6719 | .B HISTFILESIZE | |
6720 | lines. If | |
6721 | .SM | |
6722 | .B HISTFILESIZE | |
ac50fbac CR |
6723 | is unset, or set to null, a non-numeric value, |
6724 | or a numeric value less than zero, the history file is not truncated. | |
ccc6cda3 | 6725 | .PP |
726f6388 JA |
6726 | The builtin command |
6727 | .B fc | |
6728 | (see | |
6729 | .SM | |
6730 | .B SHELL BUILTIN COMMANDS | |
6731 | below) may be used to list or edit and re-execute a portion of | |
6732 | the history list. | |
6733 | The | |
6734 | .B history | |
bb70624e | 6735 | builtin may be used to display or modify the history list and |
ccc6cda3 | 6736 | manipulate the history file. |
bb70624e | 6737 | When using command-line editing, search commands |
726f6388 | 6738 | are available in each editing mode that provide access to the |
ccc6cda3 JA |
6739 | history list. |
6740 | .PP | |
6741 | The shell allows control over which commands are saved on the history | |
6742 | list. The | |
726f6388 | 6743 | .SM |
ccc6cda3 JA |
6744 | .B HISTCONTROL |
6745 | and | |
726f6388 | 6746 | .SM |
ccc6cda3 JA |
6747 | .B HISTIGNORE |
6748 | variables may be set to cause the shell to save only a subset of the | |
6749 | commands entered. | |
6750 | The | |
6751 | .B cmdhist | |
6752 | shell option, if enabled, causes the shell to attempt to save each | |
6753 | line of a multi-line command in the same history entry, adding | |
6754 | semicolons where necessary to preserve syntactic correctness. | |
6755 | The | |
6756 | .B lithist | |
6757 | shell option causes the shell to save the command with embedded newlines | |
6758 | instead of semicolons. See the description of the | |
6759 | .B shopt | |
6760 | builtin below under | |
6761 | .SM | |
6762 | .B "SHELL BUILTIN COMMANDS" | |
6763 | for information on setting and unsetting shell options. | |
726f6388 JA |
6764 | .SH "HISTORY EXPANSION" |
6765 | .PP | |
6766 | The shell supports a history expansion feature that | |
6767 | is similar to the history expansion in | |
6768 | .BR csh. | |
6769 | This section describes what syntax features are available. This | |
6770 | feature is enabled by default for interactive shells, and can be | |
6771 | disabled using the | |
ac50fbac | 6772 | .B +H |
726f6388 JA |
6773 | option to the |
6774 | .B set | |
6775 | builtin command (see | |
6776 | .SM | |
6777 | .B SHELL BUILTIN COMMANDS | |
ccc6cda3 JA |
6778 | below). Non-interactive shells do not perform history expansion |
6779 | by default. | |
6780 | .PP | |
6781 | History expansions introduce words from the history list into | |
6782 | the input stream, making it easy to repeat commands, insert the | |
6783 | arguments to a previous command into the current input line, or | |
6784 | fix errors in previous commands quickly. | |
726f6388 JA |
6785 | .PP |
6786 | History expansion is performed immediately after a complete line | |
6787 | is read, before the shell breaks it into words. | |
ccc6cda3 | 6788 | It takes place in two parts. |
cce855bc | 6789 | The first is to determine which line from the history list |
ccc6cda3 JA |
6790 | to use during substitution. |
6791 | The second is to select portions of that line for inclusion into | |
6792 | the current one. | |
cce855bc | 6793 | The line selected from the history is the \fIevent\fP, |
ccc6cda3 JA |
6794 | and the portions of that line that are acted upon are \fIwords\fP. |
6795 | Various \fImodifiers\fP are available to manipulate the selected words. | |
6796 | The line is broken into words in the same fashion as when reading input, | |
6797 | so that several \fImetacharacter\fP-separated words surrounded by | |
cce855bc | 6798 | quotes are considered one word. |
ccc6cda3 JA |
6799 | History expansions are introduced by the appearance of the |
6800 | history expansion character, which is \^\fB!\fP\^ by default. | |
6801 | Only backslash (\^\fB\e\fP\^) and single quotes can quote | |
a0c0a00f CR |
6802 | the history expansion character, but the history expansion character is |
6803 | also treated as quoted if it immediately precedes the closing double quote | |
6804 | in a double-quoted string. | |
ccc6cda3 | 6805 | .PP |
b80f6443 JA |
6806 | Several characters inhibit history expansion if found immediately |
6807 | following the history expansion character, even if it is unquoted: | |
6808 | space, tab, newline, carriage return, and \fB=\fP. | |
6809 | If the \fBextglob\fP shell option is enabled, \fB(\fP will also | |
6810 | inhibit expansion. | |
6811 | .PP | |
ccc6cda3 JA |
6812 | Several shell options settable with the |
6813 | .B shopt | |
6814 | builtin may be used to tailor the behavior of history expansion. | |
6815 | If the | |
6816 | .B histverify | |
6817 | shell option is enabled (see the description of the | |
6818 | .B shopt | |
0001803f | 6819 | builtin below), and |
ccc6cda3 JA |
6820 | .B readline |
6821 | is being used, history substitutions are not immediately passed to | |
6822 | the shell parser. | |
6823 | Instead, the expanded line is reloaded into the | |
6824 | .B readline | |
6825 | editing buffer for further modification. | |
6826 | If | |
6827 | .B readline | |
6828 | is being used, and the | |
6829 | .B histreedit | |
6830 | shell option is enabled, a failed history substitution will be reloaded | |
6831 | into the | |
6832 | .B readline | |
6833 | editing buffer for correction. | |
6834 | The | |
6835 | .B \-p | |
6836 | option to the | |
6837 | .B history | |
6838 | builtin command may be used to see what a history expansion will | |
6839 | do before using it. | |
6840 | The | |
6841 | .B \-s | |
6842 | option to the | |
6843 | .B history | |
6844 | builtin may be used to add commands to the end of the history list | |
6845 | without actually executing them, so that they are available for | |
6846 | subsequent recall. | |
726f6388 JA |
6847 | .PP |
6848 | The shell allows control of the various characters used by the | |
6849 | history expansion mechanism (see the description of | |
6850 | .B histchars | |
6851 | above under | |
6852 | .BR "Shell Variables" ). | |
3185942a JA |
6853 | The shell uses |
6854 | the history comment character to mark history timestamps when | |
6855 | writing the history file. | |
726f6388 JA |
6856 | .SS Event Designators |
6857 | .PP | |
6858 | An event designator is a reference to a command line entry in the | |
6859 | history list. | |
495aee44 CR |
6860 | Unless the reference is absolute, events are relative to the current |
6861 | position in the history list. | |
726f6388 JA |
6862 | .PP |
6863 | .PD 0 | |
6864 | .TP | |
6865 | .B ! | |
6866 | Start a history substitution, except when followed by a | |
6867 | .BR blank , | |
b80f6443 JA |
6868 | newline, carriage return, = |
6869 | or ( (when the \fBextglob\fP shell option is enabled using | |
6870 | the \fBshopt\fP builtin). | |
726f6388 | 6871 | .TP |
726f6388 JA |
6872 | .B !\fIn\fR |
6873 | Refer to command line | |
6874 | .IR n . | |
6875 | .TP | |
6876 | .B !\-\fIn\fR | |
495aee44 | 6877 | Refer to the current command minus |
726f6388 JA |
6878 | .IR n . |
6879 | .TP | |
ccc6cda3 JA |
6880 | .B !! |
6881 | Refer to the previous command. This is a synonym for `!\-1'. | |
6882 | .TP | |
726f6388 | 6883 | .B !\fIstring\fR |
495aee44 CR |
6884 | Refer to the most recent command preceding the current position in the |
6885 | history list starting with | |
726f6388 JA |
6886 | .IR string . |
6887 | .TP | |
6888 | .B !?\fIstring\fR\fB[?]\fR | |
ac50fbac | 6889 | Refer to the most recent command preceding the current position in the |
495aee44 | 6890 | history list containing |
726f6388 | 6891 | .IR string . |
ccc6cda3 JA |
6892 | The trailing \fB?\fP may be omitted if |
6893 | .I string | |
6894 | is followed immediately by a newline. | |
726f6388 JA |
6895 | .TP |
6896 | .B \d\s+2^\s-2\u\fIstring1\fP\d\s+2^\s-2\u\fIstring2\fP\d\s+2^\s-2\u | |
495aee44 | 6897 | Quick substitution. Repeat the previous command, replacing |
726f6388 JA |
6898 | .I string1 |
6899 | with | |
6900 | .IR string2 . | |
6901 | Equivalent to | |
6902 | ``!!:s/\fIstring1\fP/\fIstring2\fP/'' | |
6903 | (see \fBModifiers\fP below). | |
6904 | .TP | |
6905 | .B !# | |
6906 | The entire command line typed so far. | |
6907 | .PD | |
6908 | .SS Word Designators | |
6909 | .PP | |
ccc6cda3 | 6910 | Word designators are used to select desired words from the event. |
a0c0a00f | 6911 | A |
726f6388 | 6912 | .B : |
ccc6cda3 | 6913 | separates the event specification from the word designator. |
cce855bc | 6914 | It may be omitted if the word designator begins with a |
726f6388 JA |
6915 | .BR ^ , |
6916 | .BR $ , | |
6917 | .BR * , | |
ccc6cda3 | 6918 | .BR \- , |
726f6388 JA |
6919 | or |
6920 | .BR % . | |
6921 | Words are numbered from the beginning of the line, | |
ccc6cda3 JA |
6922 | with the first word being denoted by 0 (zero). |
6923 | Words are inserted into the current line separated by single spaces. | |
726f6388 JA |
6924 | .PP |
6925 | .PD 0 | |
6926 | .TP | |
6927 | .B 0 (zero) | |
6928 | The zeroth word. For the shell, this is the command | |
6929 | word. | |
6930 | .TP | |
6931 | .I n | |
6932 | The \fIn\fRth word. | |
6933 | .TP | |
6934 | .B ^ | |
6935 | The first argument. That is, word 1. | |
6936 | .TP | |
6937 | .B $ | |
ac50fbac CR |
6938 | The last word. This is usually the last argument, but will expand to the |
6939 | zeroth word if there is only one word in the line. | |
726f6388 JA |
6940 | .TP |
6941 | .B % | |
6942 | The word matched by the most recent `?\fIstring\fR?' search. | |
6943 | .TP | |
6944 | .I x\fB\-\fPy | |
6945 | A range of words; `\-\fIy\fR' abbreviates `0\-\fIy\fR'. | |
6946 | .TP | |
6947 | .B * | |
6948 | All of the words but the zeroth. This is a synonym | |
6949 | for `\fI1\-$\fP'. It is not an error to use | |
6950 | .B * | |
6951 | if there is just one | |
6952 | word in the event; the empty string is returned in that case. | |
6953 | .TP | |
6954 | .B x* | |
6955 | Abbreviates \fIx\-$\fP. | |
6956 | .TP | |
6957 | .B x\- | |
6958 | Abbreviates \fIx\-$\fP like \fBx*\fP, but omits the last word. | |
6959 | .PD | |
ccc6cda3 JA |
6960 | .PP |
6961 | If a word designator is supplied without an event specification, the | |
6962 | previous command is used as the event. | |
726f6388 JA |
6963 | .SS Modifiers |
6964 | .PP | |
ccc6cda3 JA |
6965 | After the optional word designator, there may appear a sequence of |
6966 | one or more of the following modifiers, each preceded by a `:'. | |
726f6388 JA |
6967 | .PP |
6968 | .PD 0 | |
6969 | .PP | |
6970 | .TP | |
6971 | .B h | |
ac50fbac | 6972 | Remove a trailing filename component, leaving only the head. |
ccc6cda3 JA |
6973 | .TP |
6974 | .B t | |
ac50fbac | 6975 | Remove all leading filename components, leaving the tail. |
726f6388 JA |
6976 | .TP |
6977 | .B r | |
6978 | Remove a trailing suffix of the form \fI.xxx\fP, leaving the | |
6979 | basename. | |
6980 | .TP | |
6981 | .B e | |
6982 | Remove all but the trailing suffix. | |
6983 | .TP | |
726f6388 JA |
6984 | .B p |
6985 | Print the new command but do not execute it. | |
6986 | .TP | |
6987 | .B q | |
6988 | Quote the substituted words, escaping further substitutions. | |
6989 | .TP | |
cce855bc JA |
6990 | .B x |
6991 | Quote the substituted words as with | |
6992 | .BR q , | |
6993 | but break into words at | |
6994 | .B blanks | |
6995 | and newlines. | |
726f6388 | 6996 | .TP |
cce855bc JA |
6997 | .B s/\fIold\fP/\fInew\fP/ |
6998 | Substitute | |
6999 | .I new | |
7000 | for the first occurrence of | |
7001 | .I old | |
7002 | in the event line. Any delimiter can be used in place of /. The | |
7003 | final delimiter is optional if it is the last character of the | |
7004 | event line. The delimiter may be quoted in | |
7005 | .I old | |
7006 | and | |
7007 | .I new | |
7008 | with a single backslash. If & appears in | |
7009 | .IR new , | |
7010 | it is replaced by | |
7011 | .IR old . | |
7012 | A single backslash will quote the &. If | |
7013 | .I old | |
7014 | is null, it is set to the last | |
7015 | .I old | |
7016 | substituted, or, if no previous history substitutions took place, | |
7017 | the last | |
7018 | .I string | |
7019 | in a | |
7020 | .B !?\fIstring\fR\fB[?]\fR | |
7021 | search. | |
ccc6cda3 | 7022 | .TP |
cce855bc JA |
7023 | .B & |
7024 | Repeat the previous substitution. | |
7025 | .TP | |
7026 | .B g | |
7027 | Cause changes to be applied over the entire event line. This is | |
7028 | used in conjunction with `\fB:s\fP' (e.g., `\fB:gs/\fIold\fP/\fInew\fP/\fR') | |
7029 | or `\fB:&\fP'. If used with | |
7030 | `\fB:s\fP', any delimiter can be used | |
7031 | in place of /, and the final delimiter is optional | |
7032 | if it is the last character of the event line. | |
b80f6443 JA |
7033 | An \fBa\fP may be used as a synonym for \fBg\fP. |
7034 | .TP | |
7035 | .B G | |
7036 | Apply the following `\fBs\fP' modifier once to each word in the event line. | |
726f6388 | 7037 | .PD |
726f6388 JA |
7038 | .SH "SHELL BUILTIN COMMANDS" |
7039 | .\" start of bash_builtins | |
7040 | .zZ | |
ccc6cda3 JA |
7041 | .PP |
7042 | Unless otherwise noted, each builtin command documented in this | |
7043 | section as accepting options preceded by | |
7044 | .B \- | |
7045 | accepts | |
7046 | .B \-\- | |
7047 | to signify the end of the options. | |
0001803f CR |
7048 | The \fB:\fP, \fBtrue\fP, \fBfalse\fP, and \fBtest\fP builtins |
7049 | do not accept options and do not treat \fB\-\-\fP specially. | |
a0c0a00f CR |
7050 | The \fBexit\fP, \fBlogout\fP, \fBreturn\fP, |
7051 | \fBbreak\fP, \fBcontinue\fP, \fBlet\fP, | |
0001803f CR |
7052 | and \fBshift\fP builtins accept and process arguments beginning with |
7053 | \fB\-\fP without requiring \fB\-\-\fP. | |
7054 | Other builtins that accept arguments but are not specified as accepting | |
7055 | options interpret arguments beginning with \fB\-\fP as invalid options and | |
7056 | require \fB\-\-\fP to prevent this interpretation. | |
ccc6cda3 | 7057 | .sp .5 |
726f6388 JA |
7058 | .PD 0 |
7059 | .TP | |
7060 | \fB:\fP [\fIarguments\fP] | |
7061 | .PD | |
7062 | No effect; the command does nothing beyond expanding | |
7063 | .I arguments | |
7064 | and performing any specified | |
a0c0a00f CR |
7065 | redirections. |
7066 | The return status is zero. | |
726f6388 | 7067 | .TP |
726f6388 | 7068 | \fB .\| \fP \fIfilename\fP [\fIarguments\fP] |
7117c2d2 | 7069 | .PD 0 |
726f6388 JA |
7070 | .TP |
7071 | \fBsource\fP \fIfilename\fP [\fIarguments\fP] | |
7072 | .PD | |
7073 | Read and execute commands from | |
7074 | .I filename | |
7075 | in the current | |
7076 | shell environment and return the exit status of the last command | |
7077 | executed from | |
7078 | .IR filename . | |
7079 | If | |
7080 | .I filename | |
ac50fbac | 7081 | does not contain a slash, filenames in |
726f6388 JA |
7082 | .SM |
7083 | .B PATH | |
7084 | are used to find the directory containing | |
7085 | .IR filename . | |
7086 | The file searched for in | |
7087 | .SM | |
7088 | .B PATH | |
28ef6c31 JA |
7089 | need not be executable. |
7090 | When \fBbash\fP is not in \fIposix mode\fP, the current directory is | |
726f6388 JA |
7091 | searched if no file is found in |
7092 | .SM | |
7093 | .BR PATH . | |
ccc6cda3 JA |
7094 | If the |
7095 | .B sourcepath | |
7096 | option to the | |
7097 | .B shopt | |
7098 | builtin command is turned off, the | |
7099 | .SM | |
7100 | .B PATH | |
7101 | is not searched. | |
726f6388 | 7102 | If any \fIarguments\fP are supplied, they become the positional |
ccc6cda3 | 7103 | parameters when \fIfilename\fP is executed. Otherwise the positional |
726f6388 | 7104 | parameters are unchanged. |
a0c0a00f CR |
7105 | If the \fB\-T\fP option is enabled, \fBsource\fP inherits any trap on |
7106 | \fBDEBUG\fP; if it is not, any \fBDEBUG\fP trap string is saved and | |
7107 | restored around the call to \fBsource\fP, and \fBsource\fP unsets the | |
7108 | \fBDEBUG\fP trap while it executes. | |
7109 | If \fB\-T\fP is not set, and the sourced file changes | |
7110 | the \fBDEBUG\fP trap, the new value is retained when \fBsource\fP completes. | |
726f6388 JA |
7111 | The return status is the status of the last command exited within |
7112 | the script (0 if no commands are executed), and false if | |
7113 | .I filename | |
cce855bc | 7114 | is not found or cannot be read. |
726f6388 | 7115 | .TP |
ccc6cda3 JA |
7116 | \fBalias\fP [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...] |
7117 | \fBAlias\fP with no arguments or with the | |
7118 | .B \-p | |
7119 | option prints the list of aliases in the form | |
7120 | \fBalias\fP \fIname\fP=\fIvalue\fP on standard output. | |
7121 | When arguments are supplied, an alias is defined for | |
7122 | each \fIname\fP whose \fIvalue\fP is given. | |
a0c0a00f | 7123 | A trailing space in \fIvalue\fP causes the next word to be |
ccc6cda3 JA |
7124 | checked for alias substitution when the alias is expanded. |
7125 | For each \fIname\fP in the argument list for which no \fIvalue\fP | |
7126 | is supplied, the name and value of the alias is printed. | |
7127 | \fBAlias\fP returns true unless a \fIname\fP is given for which | |
7128 | no alias has been defined. | |
726f6388 | 7129 | .TP |
95732b49 JA |
7130 | \fBbg\fP [\fIjobspec\fP ...] |
7131 | Resume each suspended job \fIjobspec\fP in the background, as if it | |
cce855bc | 7132 | had been started with |
726f6388 | 7133 | .BR & . |
3185942a JA |
7134 | If |
7135 | .I jobspec | |
7136 | is not present, the shell's notion of the \fIcurrent job\fP is used. | |
726f6388 JA |
7137 | .B bg |
7138 | .I jobspec | |
7139 | returns 0 unless run when job control is disabled or, when run with | |
95732b49 JA |
7140 | job control enabled, any specified \fIjobspec\fP was not found |
7141 | or was started without job control. | |
726f6388 | 7142 | .TP |
ac50fbac | 7143 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] [\fB\-lpsvPSVX\fP] |
7117c2d2 | 7144 | .PD 0 |
cce855bc JA |
7145 | .TP |
7146 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] [\fB\-q\fP \fIfunction\fP] [\fB\-u\fP \fIfunction\fP] [\fB\-r\fP \fIkeyseq\fP] | |
726f6388 | 7147 | .TP |
ccc6cda3 | 7148 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-f\fP \fIfilename\fP |
726f6388 | 7149 | .TP |
bb70624e JA |
7150 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-x\fP \fIkeyseq\fP:\fIshell\-command\fP |
7151 | .TP | |
ccc6cda3 | 7152 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fIkeyseq\fP:\fIfunction\-name\fP |
7117c2d2 | 7153 | .TP |
a0c0a00f | 7154 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fIkeyseq\fP:\fIreadline\-command\fP |
726f6388 JA |
7155 | .PD |
7156 | Display current | |
7157 | .B readline | |
7117c2d2 | 7158 | key and function bindings, bind a key sequence to a |
726f6388 | 7159 | .B readline |
7117c2d2 JA |
7160 | function or macro, or set a |
7161 | .B readline | |
7162 | variable. | |
7163 | Each non-option argument is a command as it would appear in | |
726f6388 | 7164 | .IR .inputrc , |
7117c2d2 JA |
7165 | but each binding or command must be passed as a separate argument; |
7166 | e.g., '"\eC\-x\eC\-r": re\-read\-init\-file'. | |
7167 | Options, if supplied, have the following meanings: | |
726f6388 JA |
7168 | .RS |
7169 | .PD 0 | |
7170 | .TP | |
7171 | .B \-m \fIkeymap\fP | |
7172 | Use | |
7173 | .I keymap | |
7174 | as the keymap to be affected by the subsequent bindings. | |
7175 | Acceptable | |
7176 | .I keymap | |
7177 | names are | |
ccc6cda3 | 7178 | \fIemacs, emacs\-standard, emacs\-meta, emacs\-ctlx, vi, |
28ef6c31 | 7179 | vi\-move, vi\-command\fP, and |
ccc6cda3 | 7180 | .IR vi\-insert . |
a0c0a00f CR |
7181 | \fIvi\fP is equivalent to \fIvi\-command\fP (\fIvi\-move\fP is also |
7182 | a synonym); \fIemacs\fP is | |
ccc6cda3 | 7183 | equivalent to \fIemacs\-standard\fP. |
726f6388 JA |
7184 | .TP |
7185 | .B \-l | |
ccc6cda3 JA |
7186 | List the names of all \fBreadline\fP functions. |
7187 | .TP | |
7188 | .B \-p | |
7189 | Display \fBreadline\fP function names and bindings in such a way | |
7190 | that they can be re-read. | |
7191 | .TP | |
7192 | .B \-P | |
7193 | List current \fBreadline\fP function names and bindings. | |
726f6388 | 7194 | .TP |
ccc6cda3 JA |
7195 | .B \-s |
7196 | Display \fBreadline\fP key sequences bound to macros and the strings | |
7197 | they output in such a way that they can be re-read. | |
7198 | .TP | |
7199 | .B \-S | |
7200 | Display \fBreadline\fP key sequences bound to macros and the strings | |
7201 | they output. | |
726f6388 | 7202 | .TP |
3185942a JA |
7203 | .B \-v |
7204 | Display \fBreadline\fP variable names and values in such a way that they | |
7205 | can be re-read. | |
7206 | .TP | |
7207 | .B \-V | |
7208 | List current \fBreadline\fP variable names and values. | |
7209 | .TP | |
726f6388 | 7210 | .B \-f \fIfilename\fP |
ccc6cda3 | 7211 | Read key bindings from \fIfilename\fP. |
726f6388 JA |
7212 | .TP |
7213 | .B \-q \fIfunction\fP | |
ccc6cda3 JA |
7214 | Query about which keys invoke the named \fIfunction\fP. |
7215 | .TP | |
cce855bc JA |
7216 | .B \-u \fIfunction\fP |
7217 | Unbind all keys bound to the named \fIfunction\fP. | |
7218 | .TP | |
ccc6cda3 JA |
7219 | .B \-r \fIkeyseq\fP |
7220 | Remove any current binding for \fIkeyseq\fP. | |
bb70624e JA |
7221 | .TP |
7222 | .B \-x \fIkeyseq\fP:\fIshell\-command\fP | |
7223 | Cause \fIshell\-command\fP to be executed whenever \fIkeyseq\fP is | |
7224 | entered. | |
3185942a | 7225 | When \fIshell\-command\fP is executed, the shell sets the |
0001803f | 7226 | .SM |
3185942a JA |
7227 | .B READLINE_LINE |
7228 | variable to the contents of the \fBreadline\fP line buffer and the | |
0001803f | 7229 | .SM |
3185942a JA |
7230 | .B READLINE_POINT |
7231 | variable to the current location of the insertion point. | |
7232 | If the executed command changes the value of | |
0001803f | 7233 | .SM |
3185942a JA |
7234 | .B READLINE_LINE |
7235 | or | |
0001803f | 7236 | .SM |
3185942a JA |
7237 | .BR READLINE_POINT , |
7238 | those new values will be reflected in the editing state. | |
ac50fbac CR |
7239 | .TP |
7240 | .B \-X | |
7241 | List all key sequences bound to shell commands and the associated commands | |
7242 | in a format that can be reused as input. | |
726f6388 JA |
7243 | .PD |
7244 | .PP | |
7245 | The return value is 0 unless an unrecognized option is given or an | |
7246 | error occurred. | |
7247 | .RE | |
7248 | .TP | |
7249 | \fBbreak\fP [\fIn\fP] | |
7250 | Exit from within a | |
7251 | .BR for , | |
7252 | .BR while , | |
ccc6cda3 | 7253 | .BR until , |
726f6388 | 7254 | or |
ccc6cda3 | 7255 | .B select |
726f6388 JA |
7256 | loop. If \fIn\fP is specified, break \fIn\fP levels. |
7257 | .I n | |
7258 | must be \(>= 1. If | |
7259 | .I n | |
7260 | is greater than the number of enclosing loops, all enclosing loops | |
3185942a JA |
7261 | are exited. |
7262 | The return value is 0 unless \fIn\fP is not greater than or equal to 1. | |
726f6388 JA |
7263 | .TP |
7264 | \fBbuiltin\fP \fIshell\-builtin\fP [\fIarguments\fP] | |
7265 | Execute the specified shell builtin, passing it | |
7266 | .IR arguments , | |
7267 | and return its exit status. | |
cce855bc | 7268 | This is useful when defining a |
726f6388 | 7269 | function whose name is the same as a shell builtin, |
cce855bc JA |
7270 | retaining the functionality of the builtin within the function. |
7271 | The \fBcd\fP builtin is commonly redefined this way. | |
7272 | The return status is false if | |
726f6388 JA |
7273 | .I shell\-builtin |
7274 | is not a shell builtin command. | |
7275 | .TP | |
3185942a JA |
7276 | \fBcaller\fP [\fIexpr\fP] |
7277 | Returns the context of any active subroutine call (a shell function or | |
495aee44 | 7278 | a script executed with the \fB.\fP or \fBsource\fP builtins). |
3185942a JA |
7279 | Without \fIexpr\fP, \fBcaller\fP displays the line number and source |
7280 | filename of the current subroutine call. | |
a0c0a00f | 7281 | If a non-negative integer is supplied as \fIexpr\fP, \fBcaller\fP |
3185942a JA |
7282 | displays the line number, subroutine name, and source file corresponding |
7283 | to that position in the current execution call stack. This extra | |
7284 | information may be used, for example, to print a stack trace. The | |
7285 | current frame is frame 0. | |
7286 | The return value is 0 unless the shell is not executing a subroutine | |
7287 | call or \fIexpr\fP does not correspond to a valid position in the | |
7288 | call stack. | |
7289 | .TP | |
ac50fbac CR |
7290 | \fBcd\fP [\fB\-L\fP|[\fB\-P\fP [\fB\-e\fP]] [\-@]] [\fIdir\fP] |
7291 | Change the current directory to \fIdir\fP. | |
7292 | if \fIdir\fP is not supplied, the value of the | |
726f6388 JA |
7293 | .SM |
7294 | .B HOME | |
ac50fbac CR |
7295 | shell variable is the default. |
7296 | Any additional arguments following \fIdir\fP are ignored. | |
726f6388 JA |
7297 | The variable |
7298 | .SM | |
7299 | .B CDPATH | |
ccc6cda3 | 7300 | defines the search path for the directory containing |
ac50fbac CR |
7301 | .IR dir : |
7302 | each directory name in | |
7303 | .SM | |
7304 | .B CDPATH | |
7305 | is searched for \fIdir\fP. | |
ccc6cda3 JA |
7306 | Alternative directory names in |
7307 | .SM | |
7308 | .B CDPATH | |
7309 | are separated by a colon (:). A null directory name in | |
726f6388 JA |
7310 | .SM |
7311 | .B CDPATH | |
ccc6cda3 | 7312 | is the same as the current directory, i.e., ``\fB.\fP''. If |
726f6388 JA |
7313 | .I dir |
7314 | begins with a slash (/), | |
7315 | then | |
7316 | .SM | |
7317 | .B CDPATH | |
a0c0a00f | 7318 | is not used. The |
ccc6cda3 | 7319 | .B \-P |
ac50fbac CR |
7320 | option causes \fBcd\fP to use the physical directory structure |
7321 | by resolving symbolic links while traversing \fIdir\fP and | |
7322 | before processing instances of \fI..\fP in \fIdir\fP (see also the | |
ccc6cda3 JA |
7323 | .B \-P |
7324 | option to the | |
7325 | .B set | |
7326 | builtin command); the | |
7327 | .B \-L | |
ac50fbac CR |
7328 | option forces symbolic links to be followed by resolving the link |
7329 | after processing instances of \fI..\fP in \fIdir\fP. | |
7330 | If \fI..\fP appears in \fIdir\fP, it is processed by removing the | |
7331 | immediately previous pathname component from \fIdir\fP, back to a slash | |
7332 | or the beginning of \fIdir\fP. | |
495aee44 CR |
7333 | If the |
7334 | .B \-e | |
7335 | option is supplied with | |
7336 | .BR \-P , | |
7337 | and the current working directory cannot be successfully determined | |
7338 | after a successful directory change, \fBcd\fP will return an unsuccessful | |
7339 | status. | |
ac50fbac CR |
7340 | On systems that support it, the \fB\-@\fP option presents the extended |
7341 | attributes associated with a file as a directory. | |
495aee44 | 7342 | An argument of |
726f6388 | 7343 | .B \- |
ac50fbac | 7344 | is converted to |
726f6388 | 7345 | .SM |
ac50fbac CR |
7346 | .B $OLDPWD |
7347 | before the directory change is attempted. | |
0001803f CR |
7348 | If a non-empty directory name from |
7349 | .SM | |
7350 | .B CDPATH | |
7351 | is used, or if | |
b80f6443 JA |
7352 | \fB\-\fP is the first argument, and the directory change is |
7353 | successful, the absolute pathname of the new working directory is | |
7354 | written to the standard output. | |
726f6388 JA |
7355 | The return value is true if the directory was successfully changed; |
7356 | false otherwise. | |
7357 | .TP | |
ccc6cda3 | 7358 | \fBcommand\fP [\fB\-pVv\fP] \fIcommand\fP [\fIarg\fP ...] |
726f6388 JA |
7359 | Run |
7360 | .I command | |
7361 | with | |
7362 | .I args | |
a0c0a00f CR |
7363 | suppressing the normal shell function lookup. |
7364 | Only builtin commands or commands found in the | |
726f6388 JA |
7365 | .SM |
7366 | .B PATH | |
7367 | are executed. If the | |
7368 | .B \-p | |
7369 | option is given, the search for | |
7370 | .I command | |
7371 | is performed using a default value for | |
0001803f | 7372 | .SM |
726f6388 JA |
7373 | .B PATH |
7374 | that is guaranteed to find all of the standard utilities. | |
7375 | If either the | |
7376 | .B \-V | |
7377 | or | |
7378 | .B \-v | |
7379 | option is supplied, a description of | |
7380 | .I command | |
7381 | is printed. The | |
7382 | .B \-v | |
ac50fbac | 7383 | option causes a single word indicating the command or filename |
726f6388 JA |
7384 | used to invoke |
7385 | .I command | |
cce855bc | 7386 | to be displayed; the |
726f6388 JA |
7387 | .B \-V |
7388 | option produces a more verbose description. | |
726f6388 JA |
7389 | If the |
7390 | .B \-V | |
7391 | or | |
7392 | .B \-v | |
7393 | option is supplied, the exit status is 0 if | |
7394 | .I command | |
7395 | was found, and 1 if not. If neither option is supplied and | |
7396 | an error occurred or | |
7397 | .I command | |
7398 | cannot be found, the exit status is 127. Otherwise, the exit status of the | |
7399 | .B command | |
7400 | builtin is the exit status of | |
7401 | .IR command . | |
7402 | .TP | |
bb70624e JA |
7403 | \fBcompgen\fP [\fIoption\fP] [\fIword\fP] |
7404 | Generate possible completion matches for \fIword\fP according to | |
7405 | the \fIoption\fPs, which may be any option accepted by the | |
7406 | .B complete | |
7407 | builtin with the exception of \fB\-p\fP and \fB\-r\fP, and write | |
7408 | the matches to the standard output. | |
7409 | When using the \fB\-F\fP or \fB\-C\fP options, the various shell variables | |
7410 | set by the programmable completion facilities, while available, will not | |
7411 | have useful values. | |
7412 | .sp 1 | |
7413 | The matches will be generated in the same way as if the programmable | |
7414 | completion code had generated them directly from a completion specification | |
7415 | with the same flags. | |
7416 | If \fIword\fP is specified, only those completions matching \fIword\fP | |
7417 | will be displayed. | |
7418 | .sp 1 | |
7419 | The return value is true unless an invalid option is supplied, or no | |
7420 | matches were generated. | |
7421 | .TP | |
0001803f | 7422 | \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 | 7423 | .br |
3185942a | 7424 | [\fB\-X\fP \fIfilterpat\fP] [\fB\-P\fP \fIprefix\fP] [\fB\-S\fP \fIsuffix\fP] \fIname\fP [\fIname ...\fP] |
7117c2d2 | 7425 | .PD 0 |
bb70624e | 7426 | .TP |
0001803f | 7427 | \fBcomplete\fP \fB\-pr\fP [\fB\-DE\fP] [\fIname\fP ...] |
bb70624e JA |
7428 | .PD |
7429 | Specify how arguments to each \fIname\fP should be completed. | |
7430 | If the \fB\-p\fP option is supplied, or if no options are supplied, | |
7431 | existing completion specifications are printed in a way that allows | |
7432 | them to be reused as input. | |
7433 | The \fB\-r\fP option removes a completion specification for | |
7434 | each \fIname\fP, or, if no \fIname\fPs are supplied, all | |
7435 | completion specifications. | |
0001803f CR |
7436 | The \fB\-D\fP option indicates that the remaining options and actions should |
7437 | apply to the ``default'' command completion; that is, completion attempted | |
7438 | on a command for which no completion has previously been defined. | |
3185942a JA |
7439 | The \fB\-E\fP option indicates that the remaining options and actions should |
7440 | apply to ``empty'' command completion; that is, completion attempted on a | |
7441 | blank line. | |
bb70624e JA |
7442 | .sp 1 |
7443 | The process of applying these completion specifications when word completion | |
7444 | is attempted is described above under \fBProgrammable Completion\fP. | |
7445 | .sp 1 | |
7446 | Other options, if specified, have the following meanings. | |
7447 | The arguments to the \fB\-G\fP, \fB\-W\fP, and \fB\-X\fP options | |
7448 | (and, if necessary, the \fB\-P\fP and \fB\-S\fP options) | |
7449 | should be quoted to protect them from expansion before the | |
7450 | .B complete | |
7451 | builtin is invoked. | |
7452 | .RS | |
7453 | .PD 0 | |
7454 | .TP 8 | |
28ef6c31 JA |
7455 | \fB\-o\fP \fIcomp-option\fP |
7456 | The \fIcomp-option\fP controls several aspects of the compspec's behavior | |
7457 | beyond the simple generation of completions. | |
7458 | \fIcomp-option\fP may be one of: | |
7459 | .RS | |
7460 | .TP 8 | |
b80f6443 JA |
7461 | .B bashdefault |
7462 | Perform the rest of the default \fBbash\fP completions if the compspec | |
7463 | generates no matches. | |
7464 | .TP 8 | |
28ef6c31 | 7465 | .B default |
7117c2d2 JA |
7466 | Use readline's default filename completion if the compspec generates |
7467 | no matches. | |
28ef6c31 JA |
7468 | .TP 8 |
7469 | .B dirnames | |
7470 | Perform directory name completion if the compspec generates no matches. | |
7471 | .TP 8 | |
7472 | .B filenames | |
7473 | Tell readline that the compspec generates filenames, so it can perform any | |
3185942a JA |
7474 | filename\-specific processing (like adding a slash to directory names, |
7475 | quoting special characters, or suppressing trailing spaces). | |
7476 | Intended to be used with shell functions. | |
7117c2d2 | 7477 | .TP 8 |
ac50fbac CR |
7478 | .B noquote |
7479 | Tell readline not to quote the completed words if they are filenames | |
7480 | (quoting filenames is the default). | |
7481 | .TP 8 | |
a0c0a00f CR |
7482 | .B nosort |
7483 | Tell readline not to sort the list of possible completions alphabetically. | |
7484 | .TP 8 | |
7117c2d2 JA |
7485 | .B nospace |
7486 | Tell readline not to append a space (the default) to words completed at | |
7487 | the end of the line. | |
95732b49 JA |
7488 | .TP 8 |
7489 | .B plusdirs | |
a0c0a00f | 7490 | After any matches defined by the compspec are generated, |
95732b49 JA |
7491 | directory name completion is attempted and any |
7492 | matches are added to the results of the other actions. | |
28ef6c31 JA |
7493 | .RE |
7494 | .TP 8 | |
bb70624e JA |
7495 | \fB\-A\fP \fIaction\fP |
7496 | The \fIaction\fP may be one of the following to generate a list of possible | |
7497 | completions: | |
7498 | .RS | |
7499 | .TP 8 | |
7500 | .B alias | |
7501 | Alias names. May also be specified as \fB\-a\fP. | |
7502 | .TP 8 | |
7503 | .B arrayvar | |
7504 | Array variable names. | |
7505 | .TP 8 | |
7506 | .B binding | |
7507 | \fBReadline\fP key binding names. | |
7508 | .TP 8 | |
7509 | .B builtin | |
7510 | Names of shell builtin commands. May also be specified as \fB\-b\fP. | |
7511 | .TP 8 | |
7512 | .B command | |
7513 | Command names. May also be specified as \fB\-c\fP. | |
7514 | .TP 8 | |
7515 | .B directory | |
7516 | Directory names. May also be specified as \fB\-d\fP. | |
7517 | .TP 8 | |
7518 | .B disabled | |
7519 | Names of disabled shell builtins. | |
7520 | .TP 8 | |
7521 | .B enabled | |
7522 | Names of enabled shell builtins. | |
7523 | .TP 8 | |
7524 | .B export | |
7525 | Names of exported shell variables. May also be specified as \fB\-e\fP. | |
7526 | .TP 8 | |
7527 | .B file | |
7528 | File names. May also be specified as \fB\-f\fP. | |
7529 | .TP 8 | |
7530 | .B function | |
7531 | Names of shell functions. | |
7532 | .TP 8 | |
f73dda09 JA |
7533 | .B group |
7534 | Group names. May also be specified as \fB\-g\fP. | |
7535 | .TP 8 | |
bb70624e JA |
7536 | .B helptopic |
7537 | Help topics as accepted by the \fBhelp\fP builtin. | |
7538 | .TP 8 | |
7539 | .B hostname | |
7540 | Hostnames, as taken from the file specified by the | |
7541 | .SM | |
7542 | .B HOSTFILE | |
7543 | shell variable. | |
7544 | .TP 8 | |
7545 | .B job | |
7546 | Job names, if job control is active. May also be specified as \fB\-j\fP. | |
7547 | .TP 8 | |
7548 | .B keyword | |
7549 | Shell reserved words. May also be specified as \fB\-k\fP. | |
7550 | .TP 8 | |
7551 | .B running | |
7552 | Names of running jobs, if job control is active. | |
7553 | .TP 8 | |
7117c2d2 JA |
7554 | .B service |
7555 | Service names. May also be specified as \fB\-s\fP. | |
7556 | .TP 8 | |
bb70624e JA |
7557 | .B setopt |
7558 | Valid arguments for the \fB\-o\fP option to the \fBset\fP builtin. | |
7559 | .TP 8 | |
7560 | .B shopt | |
7561 | Shell option names as accepted by the \fBshopt\fP builtin. | |
7562 | .TP 8 | |
7563 | .B signal | |
7564 | Signal names. | |
7565 | .TP 8 | |
7566 | .B stopped | |
7567 | Names of stopped jobs, if job control is active. | |
7568 | .TP 8 | |
7569 | .B user | |
7570 | User names. May also be specified as \fB\-u\fP. | |
7571 | .TP 8 | |
7572 | .B variable | |
7573 | Names of all shell variables. May also be specified as \fB\-v\fP. | |
7574 | .RE | |
7575 | .TP 8 | |
bb70624e JA |
7576 | \fB\-C\fP \fIcommand\fP |
7577 | \fIcommand\fP is executed in a subshell environment, and its output is | |
7578 | used as the possible completions. | |
7579 | .TP 8 | |
7580 | \fB\-F\fP \fIfunction\fP | |
7581 | The shell function \fIfunction\fP is executed in the current shell | |
7582 | environment. | |
ac50fbac CR |
7583 | When the function is executed, |
7584 | the first argument (\fB$1\fP) is the name of the command whose arguments are | |
7585 | being completed, | |
7586 | the second argument (\fB$2\fP) is the word being completed, | |
7587 | and the third argument (\fB$3\fP) is the word preceding the word being | |
7588 | completed on the current command line. | |
bb70624e JA |
7589 | When it finishes, the possible completions are retrieved from the value |
7590 | of the | |
7591 | .SM | |
7592 | .B COMPREPLY | |
7593 | array variable. | |
7594 | .TP 8 | |
495aee44 CR |
7595 | \fB\-G\fP \fIglobpat\fP |
7596 | The pathname expansion pattern \fIglobpat\fP is expanded to generate | |
7597 | the possible completions. | |
bb70624e JA |
7598 | .TP 8 |
7599 | \fB\-P\fP \fIprefix\fP | |
7600 | \fIprefix\fP is added at the beginning of each possible completion | |
7601 | after all other options have been applied. | |
7602 | .TP 8 | |
7603 | \fB\-S\fP \fIsuffix\fP | |
7604 | \fIsuffix\fP is appended to each possible completion | |
7605 | after all other options have been applied. | |
495aee44 CR |
7606 | .TP 8 |
7607 | \fB\-W\fP \fIwordlist\fP | |
7608 | The \fIwordlist\fP is split using the characters in the | |
7609 | .SM | |
7610 | .B IFS | |
7611 | special variable as delimiters, and each resultant word is expanded. | |
7612 | The possible completions are the members of the resultant list which | |
7613 | match the word being completed. | |
7614 | .TP 8 | |
7615 | \fB\-X\fP \fIfilterpat\fP | |
7616 | \fIfilterpat\fP is a pattern as used for pathname expansion. | |
7617 | It is applied to the list of possible completions generated by the | |
7618 | preceding options and arguments, and each completion matching | |
7619 | \fIfilterpat\fP is removed from the list. | |
7620 | A leading \fB!\fP in \fIfilterpat\fP negates the pattern; in this | |
7621 | case, any completion not matching \fIfilterpat\fP is removed. | |
bb70624e JA |
7622 | .PD |
7623 | .PP | |
7624 | The return value is true unless an invalid option is supplied, an option | |
7625 | other than \fB\-p\fP or \fB\-r\fP is supplied without a \fIname\fP | |
7626 | argument, an attempt is made to remove a completion specification for | |
7627 | a \fIname\fP for which no specification exists, or | |
7628 | an error occurs adding a completion specification. | |
7629 | .RE | |
7630 | .TP | |
0001803f | 7631 | \fBcompopt\fP [\fB\-o\fP \fIoption\fP] [\fB\-DE\fP] [\fB+o\fP \fIoption\fP] [\fIname\fP] |
3185942a JA |
7632 | Modify completion options for each \fIname\fP according to the |
7633 | \fIoption\fPs, or for the | |
495aee44 | 7634 | currently-executing completion if no \fIname\fPs are supplied. |
3185942a JA |
7635 | If no \fIoption\fPs are given, display the completion options for each |
7636 | \fIname\fP or the current completion. | |
7637 | The possible values of \fIoption\fP are those valid for the \fBcomplete\fP | |
7638 | builtin described above. | |
0001803f CR |
7639 | The \fB\-D\fP option indicates that the remaining options should |
7640 | apply to the ``default'' command completion; that is, completion attempted | |
7641 | on a command for which no completion has previously been defined. | |
7642 | The \fB\-E\fP option indicates that the remaining options should | |
7643 | apply to ``empty'' command completion; that is, completion attempted on a | |
7644 | blank line. | |
495aee44 | 7645 | .sp 1 |
3185942a JA |
7646 | The return value is true unless an invalid option is supplied, an attempt |
7647 | is made to modify the options for a \fIname\fP for which no completion | |
7648 | specification exists, or an output error occurs. | |
7649 | .TP | |
726f6388 JA |
7650 | \fBcontinue\fP [\fIn\fP] |
7651 | Resume the next iteration of the enclosing | |
7652 | .BR for , | |
7653 | .BR while , | |
ccc6cda3 | 7654 | .BR until , |
726f6388 | 7655 | or |
ccc6cda3 | 7656 | .B select |
726f6388 JA |
7657 | loop. |
7658 | If | |
7659 | .I n | |
7660 | is specified, resume at the \fIn\fPth enclosing loop. | |
7661 | .I n | |
7662 | must be \(>= 1. If | |
7663 | .I n | |
7664 | is greater than the number of enclosing loops, the last enclosing loop | |
3185942a JA |
7665 | (the ``top-level'' loop) is resumed. |
7666 | The return value is 0 unless \fIn\fP is not greater than or equal to 1. | |
726f6388 | 7667 | .TP |
ac50fbac | 7668 | \fBdeclare\fP [\fB\-aAfFgilnrtux\fP] [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...] |
726f6388 | 7669 | .PD 0 |
726f6388 | 7670 | .TP |
ac50fbac | 7671 | \fBtypeset\fP [\fB\-aAfFgilnrtux\fP] [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...] |
726f6388 | 7672 | .PD |
ccc6cda3 JA |
7673 | Declare variables and/or give them attributes. |
7674 | If no \fIname\fPs are given then display the values of variables. | |
7675 | The | |
7676 | .B \-p | |
7677 | option will display the attributes and values of each | |
7678 | .IR name . | |
7679 | When | |
7680 | .B \-p | |
ac50fbac CR |
7681 | is used with \fIname\fP arguments, additional options, |
7682 | other than \fB\-f\fP and \fB\-F\fP, are ignored. | |
3185942a JA |
7683 | When |
7684 | .B \-p | |
7685 | is supplied without \fIname\fP arguments, it will display the attributes | |
7686 | and values of all variables having the attributes specified by the | |
7687 | additional options. | |
7688 | If no other options are supplied with \fB\-p\fP, \fBdeclare\fP will display | |
7689 | the attributes and values of all shell variables. The \fB\-f\fP option | |
7690 | will restrict the display to shell functions. | |
ccc6cda3 JA |
7691 | The |
7692 | .B \-F | |
7693 | option inhibits the display of function definitions; only the | |
7694 | function name and attributes are printed. | |
b80f6443 | 7695 | If the \fBextdebug\fP shell option is enabled using \fBshopt\fP, |
a0c0a00f CR |
7696 | the source file name and line number where each \fIname\fP |
7697 | is defined are displayed as well. The | |
ccc6cda3 JA |
7698 | .B \-F |
7699 | option implies | |
7700 | .BR \-f . | |
495aee44 CR |
7701 | The |
7702 | .B \-g | |
7703 | option forces variables to be created or modified at the global scope, | |
7704 | even when \fBdeclare\fP is executed in a shell function. | |
7705 | It is ignored in all other cases. | |
ccc6cda3 JA |
7706 | The following options can |
7707 | be used to restrict output to variables with the specified attribute or | |
7708 | to give variables attributes: | |
726f6388 JA |
7709 | .RS |
7710 | .PD 0 | |
7711 | .TP | |
ccc6cda3 | 7712 | .B \-a |
3185942a JA |
7713 | Each \fIname\fP is an indexed array variable (see |
7714 | .B Arrays | |
7715 | above). | |
7716 | .TP | |
7717 | .B \-A | |
7718 | Each \fIname\fP is an associative array variable (see | |
ccc6cda3 JA |
7719 | .B Arrays |
7720 | above). | |
7721 | .TP | |
726f6388 | 7722 | .B \-f |
ccc6cda3 JA |
7723 | Use function names only. |
7724 | .TP | |
7725 | .B \-i | |
7726 | The variable is treated as an integer; arithmetic evaluation (see | |
7727 | .SM | |
0001803f CR |
7728 | .B "ARITHMETIC EVALUATION" |
7729 | above) is performed when the variable is assigned a value. | |
726f6388 | 7730 | .TP |
3185942a JA |
7731 | .B \-l |
7732 | When the variable is assigned a value, all upper-case characters are | |
7733 | converted to lower-case. | |
7734 | The upper-case attribute is disabled. | |
7735 | .TP | |
ac50fbac CR |
7736 | .B \-n |
7737 | Give each \fIname\fP the \fInameref\fP attribute, making | |
7738 | it a name reference to another variable. | |
7739 | That other variable is defined by the value of \fIname\fP. | |
a0c0a00f CR |
7740 | All references, assignments, and attribute modifications |
7741 | to \fIname\fP, except those using or changing the | |
ac50fbac CR |
7742 | \fB\-n\fP attribute itself, are performed on the variable referenced by |
7743 | \fIname\fP's value. | |
a0c0a00f | 7744 | The nameref attribute cannot be applied to array variables. |
ac50fbac | 7745 | .TP |
726f6388 JA |
7746 | .B \-r |
7747 | Make \fIname\fPs readonly. These names cannot then be assigned values | |
cce855bc | 7748 | by subsequent assignment statements or unset. |
726f6388 | 7749 | .TP |
7117c2d2 JA |
7750 | .B \-t |
7751 | Give each \fIname\fP the \fItrace\fP attribute. | |
95732b49 JA |
7752 | Traced functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps from |
7753 | the calling shell. | |
7117c2d2 JA |
7754 | The trace attribute has no special meaning for variables. |
7755 | .TP | |
3185942a JA |
7756 | .B \-u |
7757 | When the variable is assigned a value, all lower-case characters are | |
7758 | converted to upper-case. | |
7759 | The lower-case attribute is disabled. | |
7760 | .TP | |
726f6388 JA |
7761 | .B \-x |
7762 | Mark \fIname\fPs for export to subsequent commands via the environment. | |
726f6388 JA |
7763 | .PD |
7764 | .PP | |
7765 | Using `+' instead of `\-' | |
3185942a JA |
7766 | turns off the attribute instead, |
7767 | with the exceptions that \fB+a\fP | |
0001803f | 7768 | may not be used to destroy an array variable and \fB+r\fP will not |
3185942a | 7769 | remove the readonly attribute. |
ac50fbac CR |
7770 | When used in a function, |
7771 | .B declare | |
7772 | and | |
7773 | .B typeset | |
7774 | make each | |
495aee44 | 7775 | \fIname\fP local, as with the |
726f6388 | 7776 | .B local |
495aee44 | 7777 | command, |
ac50fbac | 7778 | unless the \fB\-g\fP option is supplied. |
b80f6443 JA |
7779 | If a variable name is followed by =\fIvalue\fP, the value of |
7780 | the variable is set to \fIvalue\fP. | |
ac50fbac CR |
7781 | When using \fB\-a\fP or \fB\-A\fP and the compound assignment syntax to |
7782 | create array variables, additional attributes do not take effect until | |
7783 | subsequent assignments. | |
b80f6443 | 7784 | The return value is 0 unless an invalid option is encountered, |
bb70624e JA |
7785 | an attempt is made to define a function using |
7786 | .if n ``\-f foo=bar'', | |
7787 | .if t \f(CW\-f foo=bar\fP, | |
ccc6cda3 JA |
7788 | an attempt is made to assign a value to a readonly variable, |
7789 | an attempt is made to assign a value to an array variable without | |
7790 | using the compound assignment syntax (see | |
7791 | .B Arrays | |
cce855bc | 7792 | above), one of the \fInames\fP is not a valid shell variable name, |
726f6388 | 7793 | an attempt is made to turn off readonly status for a readonly variable, |
ccc6cda3 | 7794 | an attempt is made to turn off array status for an array variable, |
bb70624e | 7795 | or an attempt is made to display a non-existent function with \fB\-f\fP. |
726f6388 JA |
7796 | .RE |
7797 | .TP | |
ac50fbac | 7798 | .B dirs [\fB\-clpv\fP] [+\fIn\fP] [\-\fIn\fP] |
ccc6cda3 JA |
7799 | Without options, displays the list of currently remembered directories. |
7800 | The default display is on a single line with directory names separated | |
7801 | by spaces. | |
a0c0a00f | 7802 | Directories are added to the list with the |
726f6388 JA |
7803 | .B pushd |
7804 | command; the | |
7805 | .B popd | |
ccc6cda3 | 7806 | command removes entries from the list. |
a0c0a00f | 7807 | The current directory is always the first directory in the stack. |
726f6388 JA |
7808 | .RS |
7809 | .PD 0 | |
7810 | .TP | |
ccc6cda3 JA |
7811 | .B \-c |
7812 | Clears the directory stack by deleting all of the entries. | |
7813 | .TP | |
726f6388 | 7814 | .B \-l |
ac50fbac CR |
7815 | Produces a listing using full pathnames; |
7816 | the default listing format uses a tilde to denote the home directory. | |
ccc6cda3 JA |
7817 | .TP |
7818 | .B \-p | |
7819 | Print the directory stack with one entry per line. | |
7820 | .TP | |
7821 | .B \-v | |
7822 | Print the directory stack with one entry per line, | |
7823 | prefixing each entry with its index in the stack. | |
ac50fbac CR |
7824 | .TP |
7825 | \fB+\fP\fIn\fP | |
7826 | Displays the \fIn\fPth entry counting from the left of the list | |
7827 | shown by | |
7828 | .B dirs | |
7829 | when invoked without options, starting with zero. | |
7830 | .TP | |
7831 | \fB\-\fP\fIn\fP | |
7832 | Displays the \fIn\fPth entry counting from the right of the list | |
7833 | shown by | |
7834 | .B dirs | |
7835 | when invoked without options, starting with zero. | |
726f6388 JA |
7836 | .PD |
7837 | .PP | |
7838 | The return value is 0 unless an | |
cce855bc | 7839 | invalid option is supplied or \fIn\fP indexes beyond the end |
726f6388 JA |
7840 | of the directory stack. |
7841 | .RE | |
7842 | .TP | |
a0c0a00f | 7843 | \fBdisown\fP [\fB\-ar\fP] [\fB\-h\fP] [\fIjobspec\fP ... | \fIpid\fP ... ] |
ac50fbac | 7844 | Without options, remove each |
ccc6cda3 | 7845 | .I jobspec |
ac50fbac | 7846 | from the table of active jobs. |
3185942a JA |
7847 | If |
7848 | .I jobspec | |
ac50fbac CR |
7849 | is not present, and neither the \fB\-a\fP nor the \fB\-r\fP option |
7850 | is supplied, the \fIcurrent job\fP is used. | |
cce855bc JA |
7851 | If the \fB\-h\fP option is given, each |
7852 | .I jobspec | |
7853 | is not removed from the table, but is marked so that | |
ccc6cda3 JA |
7854 | .SM |
7855 | .B SIGHUP | |
7856 | is not sent to the job if the shell receives a | |
7857 | .SM | |
7858 | .BR SIGHUP . | |
7859 | If no | |
7860 | .I jobspec | |
cce855bc JA |
7861 | is supplied, the |
7862 | .B \-a | |
7863 | option means to remove or mark all jobs; the | |
7864 | .B \-r | |
7865 | option without a | |
7866 | .I jobspec | |
7867 | argument restricts operation to running jobs. | |
7868 | The return value is 0 unless a | |
ccc6cda3 JA |
7869 | .I jobspec |
7870 | does not specify a valid job. | |
7871 | .TP | |
726f6388 | 7872 | \fBecho\fP [\fB\-neE\fP] [\fIarg\fP ...] |
ccc6cda3 | 7873 | Output the \fIarg\fPs, separated by spaces, followed by a newline. |
ac50fbac | 7874 | The return status is 0 unless a write error occurs. |
ccc6cda3 | 7875 | If \fB\-n\fP is specified, the trailing newline is |
726f6388 JA |
7876 | suppressed. If the \fB\-e\fP option is given, interpretation of |
7877 | the following backslash-escaped characters is enabled. The | |
7878 | .B \-E | |
7879 | option disables the interpretation of these escape characters, | |
7880 | even on systems where they are interpreted by default. | |
28ef6c31 | 7881 | The \fBxpg_echo\fP shell option may be used to |
bb70624e JA |
7882 | dynamically determine whether or not \fBecho\fP expands these |
7883 | escape characters by default. | |
ccc6cda3 | 7884 | .B echo |
95732b49 | 7885 | does not interpret \fB\-\-\fP to mean the end of options. |
ccc6cda3 JA |
7886 | .B echo |
7887 | interprets the following escape sequences: | |
726f6388 JA |
7888 | .RS |
7889 | .PD 0 | |
7890 | .TP | |
7891 | .B \ea | |
7892 | alert (bell) | |
7893 | .TP | |
7894 | .B \eb | |
7895 | backspace | |
7896 | .TP | |
7897 | .B \ec | |
3185942a | 7898 | suppress further output |
726f6388 | 7899 | .TP |
ccc6cda3 | 7900 | .B \ee |
495aee44 CR |
7901 | .TP |
7902 | .B \eE | |
ccc6cda3 JA |
7903 | an escape character |
7904 | .TP | |
726f6388 JA |
7905 | .B \ef |
7906 | form feed | |
7907 | .TP | |
7908 | .B \en | |
7909 | new line | |
7910 | .TP | |
7911 | .B \er | |
7912 | carriage return | |
7913 | .TP | |
7914 | .B \et | |
7915 | horizontal tab | |
7916 | .TP | |
7917 | .B \ev | |
7918 | vertical tab | |
7919 | .TP | |
7920 | .B \e\e | |
7921 | backslash | |
7922 | .TP | |
7117c2d2 JA |
7923 | .B \e0\fInnn\fP |
7924 | the eight-bit character whose value is the octal value \fInnn\fP | |
7925 | (zero to three octal digits) | |
7926 | .TP | |
f73dda09 JA |
7927 | .B \ex\fIHH\fP |
7928 | the eight-bit character whose value is the hexadecimal value \fIHH\fP | |
7929 | (one or two hex digits) | |
495aee44 CR |
7930 | .TP |
7931 | .B \eu\fIHHHH\fP | |
7932 | the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value | |
7933 | \fIHHHH\fP (one to four hex digits) | |
7934 | .TP | |
7935 | .B \eU\fIHHHHHHHH\fP | |
7936 | the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value | |
7937 | \fIHHHHHHHH\fP (one to eight hex digits) | |
726f6388 JA |
7938 | .PD |
7939 | .RE | |
7940 | .TP | |
3185942a | 7941 | \fBenable\fP [\fB\-a\fP] [\fB\-dnps\fP] [\fB\-f\fP \fIfilename\fP] [\fIname\fP ...] |
cce855bc JA |
7942 | Enable and disable builtin shell commands. |
7943 | Disabling a builtin allows a disk command which has the same name | |
bb70624e | 7944 | as a shell builtin to be executed without specifying a full pathname, |
cce855bc | 7945 | even though the shell normally searches for builtins before disk commands. |
726f6388 JA |
7946 | If \fB\-n\fP is used, each \fIname\fP |
7947 | is disabled; otherwise, | |
7948 | \fInames\fP are enabled. For example, to use the | |
7949 | .B test | |
7950 | binary found via the | |
7951 | .SM | |
7952 | .B PATH | |
ccc6cda3 | 7953 | instead of the shell builtin version, run |
28ef6c31 JA |
7954 | .if t \f(CWenable -n test\fP. |
7955 | .if n ``enable -n test''. | |
ccc6cda3 JA |
7956 | The |
7957 | .B \-f | |
7958 | option means to load the new builtin command | |
7959 | .I name | |
7960 | from shared object | |
7961 | .IR filename , | |
7962 | on systems that support dynamic loading. The | |
7963 | .B \-d | |
7964 | option will delete a builtin previously loaded with | |
7965 | .BR \-f . | |
7966 | If no \fIname\fP arguments are given, or if the | |
7967 | .B \-p | |
7968 | option is supplied, a list of shell builtins is printed. | |
7969 | With no other option arguments, the list consists of all enabled | |
7970 | shell builtins. | |
7971 | If \fB\-n\fP is supplied, only disabled builtins are printed. | |
7972 | If \fB\-a\fP is supplied, the list printed includes all builtins, with an | |
726f6388 | 7973 | indication of whether or not each is enabled. |
ccc6cda3 JA |
7974 | If \fB\-s\fP is supplied, the output is restricted to the POSIX |
7975 | \fIspecial\fP builtins. | |
726f6388 JA |
7976 | The return value is 0 unless a |
7977 | .I name | |
bb70624e | 7978 | is not a shell builtin or there is an error loading a new builtin |
ccc6cda3 | 7979 | from a shared object. |
726f6388 JA |
7980 | .TP |
7981 | \fBeval\fP [\fIarg\fP ...] | |
7982 | The \fIarg\fPs are read and concatenated together into a single | |
7983 | command. This command is then read and executed by the shell, and | |
ccc6cda3 JA |
7984 | its exit status is returned as the value of |
7985 | .BR eval . | |
7986 | If there are no | |
726f6388 JA |
7987 | .IR args , |
7988 | or only null arguments, | |
7989 | .B eval | |
ccc6cda3 | 7990 | returns 0. |
726f6388 | 7991 | .TP |
cce855bc | 7992 | \fBexec\fP [\fB\-cl\fP] [\fB\-a\fP \fIname\fP] [\fIcommand\fP [\fIarguments\fP]] |
726f6388 JA |
7993 | If |
7994 | .I command | |
7995 | is specified, it replaces the shell. | |
7996 | No new process is created. The | |
7997 | .I arguments | |
7998 | become the arguments to \fIcommand\fP. | |
ccc6cda3 JA |
7999 | If the |
8000 | .B \-l | |
8001 | option is supplied, | |
a0c0a00f | 8002 | the shell places a dash at the beginning of the zeroth argument passed to |
726f6388 | 8003 | .IR command . |
ccc6cda3 JA |
8004 | This is what |
8005 | .IR login (1) | |
8006 | does. The | |
8007 | .B \-c | |
8008 | option causes | |
8009 | .I command | |
8010 | to be executed with an empty environment. If | |
8011 | .B \-a | |
8012 | is supplied, the shell passes | |
8013 | .I name | |
ac50fbac CR |
8014 | as the zeroth argument to the executed command. |
8015 | If | |
ccc6cda3 | 8016 | .I command |
726f6388 | 8017 | cannot be executed for some reason, a non-interactive shell exits, |
ac50fbac | 8018 | unless the |
ccc6cda3 | 8019 | .B execfail |
ac50fbac CR |
8020 | shell option |
8021 | is enabled. In that case, it returns failure. | |
ccc6cda3 | 8022 | An interactive shell returns failure if the file cannot be executed. |
726f6388 JA |
8023 | If |
8024 | .I command | |
8025 | is not specified, any redirections take effect in the current shell, | |
cce855bc JA |
8026 | and the return status is 0. If there is a redirection error, the |
8027 | return status is 1. | |
726f6388 JA |
8028 | .TP |
8029 | \fBexit\fP [\fIn\fP] | |
8030 | Cause the shell to exit | |
8031 | with a status of \fIn\fP. If | |
8032 | .I n | |
8033 | is omitted, the exit status | |
8034 | is that of the last command executed. | |
8035 | A trap on | |
8036 | .SM | |
8037 | .B EXIT | |
8038 | is executed before the shell terminates. | |
8039 | .TP | |
ccc6cda3 | 8040 | \fBexport\fP [\fB\-fn\fP\^] [\fIname\fP[=\fIword\fP]] ... |
7117c2d2 | 8041 | .PD 0 |
726f6388 JA |
8042 | .TP |
8043 | .B export \-p | |
8044 | .PD | |
8045 | The supplied | |
8046 | .I names | |
8047 | are marked for automatic export to the environment of | |
a0c0a00f | 8048 | subsequently executed commands. If the |
726f6388 | 8049 | .B \-f |
a0c0a00f | 8050 | option is given, the |
726f6388 JA |
8051 | .I names |
8052 | refer to functions. | |
8053 | If no | |
8054 | .I names | |
8055 | are given, or if the | |
8056 | .B \-p | |
8057 | option is supplied, a list | |
ac50fbac | 8058 | of names of all exported variables is printed. |
726f6388 JA |
8059 | The |
8060 | .B \-n | |
b80f6443 JA |
8061 | option causes the export property to be removed from each |
8062 | \fIname\fP. | |
8063 | If a variable name is followed by =\fIword\fP, the value of | |
8064 | the variable is set to \fIword\fP. | |
726f6388 | 8065 | .B export |
cce855bc | 8066 | returns an exit status of 0 unless an invalid option is |
726f6388 | 8067 | encountered, |
cce855bc | 8068 | one of the \fInames\fP is not a valid shell variable name, or |
726f6388 JA |
8069 | .B \-f |
8070 | is supplied with a | |
8071 | .I name | |
8072 | that is not a function. | |
8073 | .TP | |
3185942a | 8074 | \fBfc\fP [\fB\-e\fP \fIename\fP] [\fB\-lnr\fP] [\fIfirst\fP] [\fIlast\fP] |
7117c2d2 | 8075 | .PD 0 |
726f6388 JA |
8076 | .TP |
8077 | \fBfc\fP \fB\-s\fP [\fIpat\fP=\fIrep\fP] [\fIcmd\fP] | |
8078 | .PD | |
ac50fbac | 8079 | The first form selects a range of commands from |
726f6388 JA |
8080 | .I first |
8081 | to | |
8082 | .I last | |
ac50fbac | 8083 | from the history list and displays or edits and re-executes them. |
726f6388 JA |
8084 | .I First |
8085 | and | |
8086 | .I last | |
8087 | may be specified as a string (to locate the last command beginning | |
8088 | with that string) or as a number (an index into the history list, | |
8089 | where a negative number is used as an offset from the current | |
a0c0a00f | 8090 | command number). If |
726f6388 JA |
8091 | .I last |
8092 | is not specified it is set to | |
8093 | the current command for listing (so that | |
bb70624e JA |
8094 | .if n ``fc \-l \-10'' |
8095 | .if t \f(CWfc \-l \-10\fP | |
726f6388 JA |
8096 | prints the last 10 commands) and to |
8097 | .I first | |
8098 | otherwise. | |
8099 | If | |
8100 | .I first | |
8101 | is not specified it is set to the previous | |
8102 | command for editing and \-16 for listing. | |
8103 | .sp 1 | |
8104 | The | |
8105 | .B \-n | |
cce855bc | 8106 | option suppresses |
726f6388 JA |
8107 | the command numbers when listing. The |
8108 | .B \-r | |
cce855bc | 8109 | option reverses the order of |
726f6388 JA |
8110 | the commands. If the |
8111 | .B \-l | |
cce855bc | 8112 | option is given, |
726f6388 JA |
8113 | the commands are listed on |
8114 | standard output. Otherwise, the editor given by | |
8115 | .I ename | |
8116 | is invoked | |
8117 | on a file containing those commands. If | |
8118 | .I ename | |
8119 | is not given, the | |
8120 | value of the | |
8121 | .SM | |
8122 | .B FCEDIT | |
8123 | variable is used, and | |
8124 | the value of | |
8125 | .SM | |
8126 | .B EDITOR | |
8127 | if | |
8128 | .SM | |
8129 | .B FCEDIT | |
8130 | is not set. If neither variable is set, | |
8131 | .FN vi | |
8132 | is used. When editing is complete, the edited commands are | |
8133 | echoed and executed. | |
8134 | .sp 1 | |
8135 | In the second form, \fIcommand\fP is re-executed after each instance | |
8136 | of \fIpat\fP is replaced by \fIrep\fP. | |
ac50fbac | 8137 | \fICommand\fP is intepreted the same as \fIfirst\fP above. |
ccc6cda3 | 8138 | A useful alias to use with this is |
b80f6443 | 8139 | .if n ``r="fc -s"'', |
ccc6cda3 JA |
8140 | .if t \f(CWr='fc \-s'\fP, |
8141 | so that typing | |
8142 | .if n ``r cc'' | |
8143 | .if t \f(CWr cc\fP | |
8144 | runs the last command beginning with | |
8145 | .if n ``cc'' | |
8146 | .if t \f(CWcc\fP | |
8147 | and typing | |
8148 | .if n ``r'' | |
8149 | .if t \f(CWr\fP | |
726f6388 JA |
8150 | re-executes the last command. |
8151 | .sp 1 | |
cce855bc | 8152 | If the first form is used, the return value is 0 unless an invalid |
726f6388 JA |
8153 | option is encountered or |
8154 | .I first | |
8155 | or | |
8156 | .I last | |
8157 | specify history lines out of range. | |
8158 | If the | |
8159 | .B \-e | |
8160 | option is supplied, the return value is the value of the last | |
8161 | command executed or failure if an error occurs with the temporary | |
8162 | file of commands. If the second form is used, the return status | |
8163 | is that of the command re-executed, unless | |
8164 | .I cmd | |
8165 | does not specify a valid history line, in which case | |
8166 | .B fc | |
8167 | returns failure. | |
8168 | .TP | |
8169 | \fBfg\fP [\fIjobspec\fP] | |
cce855bc | 8170 | Resume |
726f6388 | 8171 | .I jobspec |
cce855bc JA |
8172 | in the foreground, and make it the current job. |
8173 | If | |
726f6388 JA |
8174 | .I jobspec |
8175 | is not present, the shell's notion of the \fIcurrent job\fP is used. | |
8176 | The return value is that of the command placed into the foreground, | |
8177 | or failure if run when job control is disabled or, when run with | |
8178 | job control enabled, if | |
8179 | .I jobspec | |
8180 | does not specify a valid job or | |
8181 | .I jobspec | |
8182 | specifies a job that was started without job control. | |
8183 | .TP | |
8184 | \fBgetopts\fP \fIoptstring\fP \fIname\fP [\fIargs\fP] | |
8185 | .B getopts | |
8186 | is used by shell procedures to parse positional parameters. | |
8187 | .I optstring | |
bb70624e | 8188 | contains the option characters to be recognized; if a character |
726f6388 JA |
8189 | is followed by a colon, the option is expected to have an |
8190 | argument, which should be separated from it by white space. | |
bb70624e JA |
8191 | The colon and question mark characters may not be used as |
8192 | option characters. | |
726f6388 JA |
8193 | Each time it is invoked, |
8194 | .B getopts | |
8195 | places the next option in the shell variable | |
8196 | .IR name , | |
8197 | initializing | |
8198 | .I name | |
8199 | if it does not exist, | |
8200 | and the index of the next argument to be processed into the | |
8201 | variable | |
8202 | .SM | |
8203 | .BR OPTIND . | |
8204 | .SM | |
8205 | .B OPTIND | |
8206 | is initialized to 1 each time the shell or a shell script | |
8207 | is invoked. When an option requires an argument, | |
8208 | .B getopts | |
8209 | places that argument into the variable | |
8210 | .SM | |
8211 | .BR OPTARG . | |
8212 | The shell does not reset | |
8213 | .SM | |
8214 | .B OPTIND | |
8215 | automatically; it must be manually reset between multiple | |
8216 | calls to | |
8217 | .B getopts | |
8218 | within the same shell invocation if a new set of parameters | |
8219 | is to be used. | |
8220 | .sp 1 | |
cce855bc JA |
8221 | When the end of options is encountered, \fBgetopts\fP exits with a |
8222 | return value greater than zero. | |
0001803f CR |
8223 | .SM |
8224 | .B OPTIND | |
8225 | is set to the index of the first non-option argument, | |
495aee44 | 8226 | and \fIname\fP is set to ?. |
cce855bc JA |
8227 | .sp 1 |
8228 | .B getopts | |
8229 | normally parses the positional parameters, but if more arguments are | |
8230 | given in | |
8231 | .IR args , | |
8232 | .B getopts | |
8233 | parses those instead. | |
8234 | .sp 1 | |
726f6388 JA |
8235 | .B getopts |
8236 | can report errors in two ways. If the first character of | |
8237 | .I optstring | |
8238 | is a colon, | |
8239 | .I silent | |
ac50fbac | 8240 | error reporting is used. In normal operation, diagnostic messages |
cce855bc | 8241 | are printed when invalid options or missing option arguments are |
726f6388 JA |
8242 | encountered. |
8243 | If the variable | |
8244 | .SM | |
8245 | .B OPTERR | |
cce855bc | 8246 | is set to 0, no error messages will be displayed, even if the first |
a0c0a00f | 8247 | character of |
726f6388 JA |
8248 | .I optstring |
8249 | is not a colon. | |
8250 | .sp 1 | |
cce855bc | 8251 | If an invalid option is seen, |
726f6388 JA |
8252 | .B getopts |
8253 | places ? into | |
8254 | .I name | |
8255 | and, if not silent, | |
8256 | prints an error message and unsets | |
8257 | .SM | |
8258 | .BR OPTARG . | |
8259 | If | |
8260 | .B getopts | |
8261 | is silent, | |
8262 | the option character found is placed in | |
8263 | .SM | |
8264 | .B OPTARG | |
8265 | and no diagnostic message is printed. | |
8266 | .sp 1 | |
8267 | If a required argument is not found, and | |
8268 | .B getopts | |
8269 | is not silent, | |
8270 | a question mark (\^\fB?\fP\^) is placed in | |
8271 | .IR name , | |
f73dda09 | 8272 | .SM |
726f6388 JA |
8273 | .B OPTARG |
8274 | is unset, and a diagnostic message is printed. | |
8275 | If | |
8276 | .B getopts | |
8277 | is silent, then a colon (\^\fB:\fP\^) is placed in | |
8278 | .I name | |
8279 | and | |
8280 | .SM | |
8281 | .B OPTARG | |
8282 | is set to the option character found. | |
8283 | .sp 1 | |
8284 | .B getopts | |
726f6388 JA |
8285 | returns true if an option, specified or unspecified, is found. |
8286 | It returns false if the end of options is encountered or an | |
8287 | error occurs. | |
8288 | .TP | |
7117c2d2 | 8289 | \fBhash\fP [\fB\-lr\fP] [\fB\-p\fP \fIfilename\fP] [\fB\-dt\fP] [\fIname\fP] |
495aee44 | 8290 | Each time \fBhash\fP is invoked, |
a0c0a00f | 8291 | the full pathname of the command |
495aee44 CR |
8292 | .I name |
8293 | is determined by searching | |
ccc6cda3 JA |
8294 | the directories in |
8295 | .B $PATH | |
495aee44 | 8296 | and remembered. Any previously-remembered pathname is discarded. |
ccc6cda3 JA |
8297 | If the |
8298 | .B \-p | |
8299 | option is supplied, no path search is performed, and | |
8300 | .I filename | |
ac50fbac | 8301 | is used as the full filename of the command. |
ccc6cda3 | 8302 | The |
726f6388 JA |
8303 | .B \-r |
8304 | option causes the shell to forget all | |
f73dda09 | 8305 | remembered locations. |
7117c2d2 JA |
8306 | The |
8307 | .B \-d | |
8308 | option causes the shell to forget the remembered location of each \fIname\fP. | |
f73dda09 JA |
8309 | If the |
8310 | .B \-t | |
8311 | option is supplied, the full pathname to which each \fIname\fP corresponds | |
8312 | is printed. If multiple \fIname\fP arguments are supplied with \fB\-t\fP, | |
8313 | the \fIname\fP is printed before the hashed full pathname. | |
7117c2d2 JA |
8314 | The |
8315 | .B \-l | |
8316 | option causes output to be displayed in a format that may be reused as input. | |
8317 | If no arguments are given, or if only \fB\-l\fP is supplied, | |
8318 | information about remembered commands is printed. | |
ccc6cda3 | 8319 | The return status is true unless a |
726f6388 | 8320 | .I name |
cce855bc | 8321 | is not found or an invalid option is supplied. |
726f6388 | 8322 | .TP |
3185942a | 8323 | \fBhelp\fP [\fB\-dms\fP] [\fIpattern\fP] |
726f6388 JA |
8324 | Display helpful information about builtin commands. If |
8325 | .I pattern | |
8326 | is specified, | |
8327 | .B help | |
8328 | gives detailed help on all commands matching | |
8329 | .IR pattern ; | |
ccc6cda3 | 8330 | otherwise help for all the builtins and shell control structures |
bb70624e | 8331 | is printed. |
3185942a JA |
8332 | .RS |
8333 | .PD 0 | |
8334 | .TP | |
8335 | .B \-d | |
8336 | Display a short description of each \fIpattern\fP | |
8337 | .TP | |
0001803f | 8338 | .B \-m |
3185942a JA |
8339 | Display the description of each \fIpattern\fP in a manpage-like format |
8340 | .TP | |
8341 | .B \-s | |
8342 | Display only a short usage synopsis for each \fIpattern\fP | |
8343 | .PD | |
495aee44 | 8344 | .PP |
bb70624e | 8345 | The return status is 0 unless no command matches |
726f6388 | 8346 | .IR pattern . |
495aee44 | 8347 | .RE |
726f6388 | 8348 | .TP |
bb70624e | 8349 | \fBhistory [\fIn\fP] |
7117c2d2 | 8350 | .PD 0 |
bb70624e JA |
8351 | .TP |
8352 | \fBhistory\fP \fB\-c\fP | |
8353 | .TP | |
8354 | \fBhistory \-d\fP \fIoffset\fP | |
ccc6cda3 JA |
8355 | .TP |
8356 | \fBhistory\fP \fB\-anrw\fP [\fIfilename\fP] | |
726f6388 | 8357 | .TP |
ccc6cda3 JA |
8358 | \fBhistory\fP \fB\-p\fP \fIarg\fP [\fIarg ...\fP] |
8359 | .TP | |
8360 | \fBhistory\fP \fB\-s\fP \fIarg\fP [\fIarg ...\fP] | |
726f6388 JA |
8361 | .PD |
8362 | With no options, display the command | |
8363 | history list with line numbers. Lines listed | |
a0c0a00f | 8364 | with a |
726f6388 JA |
8365 | .B * |
8366 | have been modified. An argument of | |
8367 | .I n | |
8368 | lists only the last | |
8369 | .I n | |
b80f6443 | 8370 | lines. |
0001803f CR |
8371 | If the shell variable |
8372 | .SM | |
8373 | .B HISTTIMEFORMAT | |
8374 | is set and not null, | |
b80f6443 JA |
8375 | it is used as a format string for \fIstrftime\fP(3) to display |
8376 | the time stamp associated with each displayed history entry. | |
8377 | No intervening blank is printed between the formatted time stamp | |
8378 | and the history line. | |
8379 | If \fIfilename\fP is supplied, it is used as the | |
726f6388 JA |
8380 | name of the history file; if not, the value of |
8381 | .SM | |
8382 | .B HISTFILE | |
8383 | is used. Options, if supplied, have the following meanings: | |
8384 | .RS | |
8385 | .PD 0 | |
8386 | .TP | |
bb70624e JA |
8387 | .B \-c |
8388 | Clear the history list by deleting all the entries. | |
8389 | .TP | |
8390 | \fB\-d\fP \fIoffset\fP | |
8391 | Delete the history entry at position \fIoffset\fP. | |
8392 | .TP | |
726f6388 | 8393 | .B \-a |
a0c0a00f CR |
8394 | Append the ``new'' history lines to the history file. |
8395 | These are history lines entered since the beginning of the current | |
8396 | \fBbash\fP session, but not already appended to the history file. | |
726f6388 JA |
8397 | .TP |
8398 | .B \-n | |
8399 | Read the history lines not already read from the history | |
8400 | file into the current history list. These are lines | |
8401 | appended to the history file since the beginning of the | |
8402 | current \fBbash\fP session. | |
8403 | .TP | |
8404 | .B \-r | |
8405 | Read the contents of the history file | |
ac50fbac | 8406 | and append them to the current history list. |
726f6388 JA |
8407 | .TP |
8408 | .B \-w | |
ac50fbac | 8409 | Write the current history list to the history file, overwriting the |
726f6388 | 8410 | history file's contents. |
ccc6cda3 | 8411 | .TP |
ccc6cda3 JA |
8412 | .B \-p |
8413 | Perform history substitution on the following \fIargs\fP and display | |
8414 | the result on the standard output. | |
8415 | Does not store the results in the history list. | |
8416 | Each \fIarg\fP must be quoted to disable normal history expansion. | |
8417 | .TP | |
8418 | .B \-s | |
8419 | Store the | |
8420 | .I args | |
8421 | in the history list as a single entry. The last command in the | |
8422 | history list is removed before the | |
8423 | .I args | |
8424 | are added. | |
726f6388 JA |
8425 | .PD |
8426 | .PP | |
0001803f CR |
8427 | If the |
8428 | .SM | |
8429 | .B HISTTIMEFORMAT | |
8430 | variable is set, the time stamp information | |
3185942a JA |
8431 | associated with each history entry is written to the history file, |
8432 | marked with the history comment character. | |
8433 | When the history file is read, lines beginning with the history | |
8434 | comment character followed immediately by a digit are interpreted | |
a0c0a00f | 8435 | as timestamps for the following history entry. |
bb70624e JA |
8436 | The return value is 0 unless an invalid option is encountered, an |
8437 | error occurs while reading or writing the history file, an invalid | |
8438 | \fIoffset\fP is supplied as an argument to \fB\-d\fP, or the | |
8439 | history expansion supplied as an argument to \fB\-p\fP fails. | |
726f6388 JA |
8440 | .RE |
8441 | .TP | |
ccc6cda3 | 8442 | \fBjobs\fP [\fB\-lnprs\fP] [ \fIjobspec\fP ... ] |
7117c2d2 | 8443 | .PD 0 |
726f6388 JA |
8444 | .TP |
8445 | \fBjobs\fP \fB\-x\fP \fIcommand\fP [ \fIargs\fP ... ] | |
8446 | .PD | |
ccc6cda3 JA |
8447 | The first form lists the active jobs. The options have the following |
8448 | meanings: | |
8449 | .RS | |
8450 | .PD 0 | |
8451 | .TP | |
726f6388 | 8452 | .B \-l |
ccc6cda3 JA |
8453 | List process IDs |
8454 | in addition to the normal information. | |
8455 | .TP | |
726f6388 | 8456 | .B \-n |
ccc6cda3 JA |
8457 | Display information only about jobs that have changed status since |
8458 | the user was last notified of their status. | |
8459 | .TP | |
495aee44 CR |
8460 | .B \-p |
8461 | List only the process ID of the job's process group | |
8462 | leader. | |
8463 | .TP | |
ccc6cda3 | 8464 | .B \-r |
ac50fbac | 8465 | Display only running jobs. |
ccc6cda3 JA |
8466 | .TP |
8467 | .B \-s | |
ac50fbac | 8468 | Display only stopped jobs. |
ccc6cda3 JA |
8469 | .PD |
8470 | .PP | |
8471 | If | |
726f6388 JA |
8472 | .I jobspec |
8473 | is given, output is restricted to information about that job. | |
cce855bc JA |
8474 | The return status is 0 unless an invalid option is encountered |
8475 | or an invalid | |
726f6388 JA |
8476 | .I jobspec |
8477 | is supplied. | |
ccc6cda3 | 8478 | .PP |
726f6388 JA |
8479 | If the |
8480 | .B \-x | |
8481 | option is supplied, | |
8482 | .B jobs | |
8483 | replaces any | |
8484 | .I jobspec | |
8485 | found in | |
8486 | .I command | |
8487 | or | |
8488 | .I args | |
8489 | with the corresponding process group ID, and executes | |
8490 | .I command | |
8491 | passing it | |
8492 | .IR args , | |
8493 | returning its exit status. | |
ccc6cda3 | 8494 | .RE |
726f6388 | 8495 | .TP |
ccc6cda3 | 8496 | \fBkill\fP [\fB\-s\fP \fIsigspec\fP | \fB\-n\fP \fIsignum\fP | \fB\-\fP\fIsigspec\fP] [\fIpid\fP | \fIjobspec\fP] ... |
7117c2d2 | 8497 | .PD 0 |
726f6388 | 8498 | .TP |
a0c0a00f | 8499 | \fBkill\fP \fB\-l\fP|\fB\-L\fP [\fIsigspec\fP | \fIexit_status\fP] |
726f6388 JA |
8500 | .PD |
8501 | Send the signal named by | |
8502 | .I sigspec | |
ccc6cda3 JA |
8503 | or |
8504 | .I signum | |
726f6388 JA |
8505 | to the processes named by |
8506 | .I pid | |
8507 | or | |
8508 | .IR jobspec . | |
8509 | .I sigspec | |
b80f6443 | 8510 | is either a case-insensitive signal name such as |
726f6388 JA |
8511 | .SM |
8512 | .B SIGKILL | |
b80f6443 | 8513 | (with or without the |
726f6388 JA |
8514 | .SM |
8515 | .B SIG | |
b80f6443 JA |
8516 | prefix) or a signal number; |
8517 | .I signum | |
8518 | is a signal number. | |
726f6388 JA |
8519 | If |
8520 | .I sigspec | |
8521 | is not present, then | |
8522 | .SM | |
8523 | .B SIGTERM | |
cce855bc JA |
8524 | is assumed. |
8525 | An argument of | |
726f6388 | 8526 | .B \-l |
cce855bc JA |
8527 | lists the signal names. |
8528 | If any arguments are supplied when | |
726f6388 | 8529 | .B \-l |
cce855bc JA |
8530 | is given, the names of the signals corresponding to the arguments are |
8531 | listed, and the return status is 0. | |
8532 | The \fIexit_status\fP argument to | |
ccc6cda3 | 8533 | .B \-l |
cce855bc JA |
8534 | is a number specifying either a signal number or the exit status of |
8535 | a process terminated by a signal. | |
a0c0a00f CR |
8536 | The |
8537 | .B \-L | |
8538 | option is equivalent to \fB\-l\fP. | |
726f6388 JA |
8539 | .B kill |
8540 | returns true if at least one signal was successfully sent, or false | |
cce855bc | 8541 | if an error occurs or an invalid option is encountered. |
726f6388 JA |
8542 | .TP |
8543 | \fBlet\fP \fIarg\fP [\fIarg\fP ...] | |
8544 | Each | |
8545 | .I arg | |
8546 | is an arithmetic expression to be evaluated (see | |
8547 | .SM | |
0001803f CR |
8548 | .B "ARITHMETIC EVALUATION" |
8549 | above). | |
726f6388 JA |
8550 | If the last |
8551 | .I arg | |
8552 | evaluates to 0, | |
8553 | .B let | |
8554 | returns 1; 0 is returned otherwise. | |
8555 | .TP | |
a0c0a00f | 8556 | \fBlocal\fP [\fIoption\fP] [\fIname\fP[=\fIvalue\fP] ... | \- ] |
cce855bc | 8557 | For each argument, a local variable named |
a0c0a00f | 8558 | .I name |
cce855bc | 8559 | is created, and assigned |
726f6388 | 8560 | .IR value . |
bb70624e | 8561 | The \fIoption\fP can be any of the options accepted by \fBdeclare\fP. |
726f6388 JA |
8562 | When |
8563 | .B local | |
8564 | is used within a function, it causes the variable | |
8565 | .I name | |
8566 | to have a visible scope restricted to that function and its children. | |
a0c0a00f CR |
8567 | If \fIname\fP is \-, the set of shell options is made local to the function |
8568 | in which \fBlocal\fP is invoked: shell options changed using the | |
8569 | \fBset\fP builtin inside the function are restored to their original values | |
8570 | when the function returns. | |
726f6388 JA |
8571 | With no operands, |
8572 | .B local | |
8573 | writes a list of local variables to the standard output. It is | |
8574 | an error to use | |
8575 | .B local | |
8576 | when not within a function. The return status is 0 unless | |
8577 | .B local | |
bb70624e | 8578 | is used outside a function, an invalid |
726f6388 | 8579 | .I name |
bb70624e JA |
8580 | is supplied, or |
8581 | \fIname\fP is a readonly variable. | |
726f6388 JA |
8582 | .TP |
8583 | .B logout | |
8584 | Exit a login shell. | |
8585 | .TP | |
a0c0a00f | 8586 | \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] |
17345e5a JA |
8587 | .PD 0 |
8588 | .TP | |
a0c0a00f | 8589 | \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] |
17345e5a | 8590 | .PD |
0001803f | 8591 | Read lines from the standard input into the indexed array variable |
3185942a | 8592 | .IR array , |
a0c0a00f | 8593 | or from file descriptor |
3185942a | 8594 | .IR fd |
a0c0a00f | 8595 | if the |
3185942a JA |
8596 | .B \-u |
8597 | option is supplied. | |
0001803f CR |
8598 | The variable |
8599 | .SM | |
8600 | .B MAPFILE | |
8601 | is the default \fIarray\fP. | |
3185942a JA |
8602 | Options, if supplied, have the following meanings: |
8603 | .RS | |
8604 | .PD 0 | |
8605 | .TP | |
a0c0a00f CR |
8606 | .B \-d |
8607 | The first character of \fIdelim\fP is used to terminate each input line, | |
8608 | rather than newline. | |
8609 | .TP | |
3185942a JA |
8610 | .B \-n |
8611 | Copy at most | |
8612 | .I count | |
8613 | lines. If \fIcount\fP is 0, all lines are copied. | |
8614 | .TP | |
8615 | .B \-O | |
8616 | Begin assigning to | |
8617 | .I array | |
8618 | at index | |
8619 | .IR origin . | |
8620 | The default index is 0. | |
8621 | .TP | |
8622 | .B \-s | |
8623 | Discard the first \fIcount\fP lines read. | |
8624 | .TP | |
8625 | .B \-t | |
a0c0a00f | 8626 | Remove a trailing \fIdelim\fP (default newline) from each line read. |
3185942a JA |
8627 | .TP |
8628 | .B \-u | |
8629 | Read lines from file descriptor \fIfd\fP instead of the standard input. | |
8630 | .TP | |
8631 | .B \-C | |
8632 | Evaluate | |
8633 | .I callback | |
8634 | each time \fIquantum\fP lines are read. The \fB\-c\fP option specifies | |
8635 | .IR quantum . | |
8636 | .TP | |
8637 | .B \-c | |
8638 | Specify the number of lines read between each call to | |
8639 | .IR callback . | |
8640 | .PD | |
8641 | .PP | |
8642 | If | |
8643 | .B \-C | |
a0c0a00f | 8644 | is specified without |
3185942a JA |
8645 | .BR \-c , |
8646 | the default quantum is 5000. | |
17345e5a | 8647 | When \fIcallback\fP is evaluated, it is supplied the index of the next |
495aee44 CR |
8648 | array element to be assigned and the line to be assigned to that element |
8649 | as additional arguments. | |
a0c0a00f | 8650 | \fIcallback\fP is evaluated after the line is read but before the |
17345e5a | 8651 | array element is assigned. |
3185942a JA |
8652 | .PP |
8653 | If not supplied with an explicit origin, \fBmapfile\fP will clear \fIarray\fP | |
8654 | before assigning to it. | |
8655 | .PP | |
8656 | \fBmapfile\fP returns successfully unless an invalid option or option | |
0001803f CR |
8657 | argument is supplied, \fIarray\fP is invalid or unassignable, or if |
8658 | \fIarray\fP is not an indexed array. | |
3185942a JA |
8659 | .RE |
8660 | .TP | |
ccc6cda3 | 8661 | \fBpopd\fP [\-\fBn\fP] [+\fIn\fP] [\-\fIn\fP] |
726f6388 JA |
8662 | Removes entries from the directory stack. With no arguments, |
8663 | removes the top directory from the stack, and performs a | |
8664 | .B cd | |
8665 | to the new top directory. | |
ccc6cda3 | 8666 | Arguments, if supplied, have the following meanings: |
726f6388 JA |
8667 | .RS |
8668 | .PD 0 | |
8669 | .TP | |
3185942a JA |
8670 | .B \-n |
8671 | Suppresses the normal change of directory when removing directories | |
8672 | from the stack, so that only the stack is manipulated. | |
8673 | .TP | |
ccc6cda3 JA |
8674 | \fB+\fP\fIn\fP |
8675 | Removes the \fIn\fPth entry counting from the left of the list | |
726f6388 JA |
8676 | shown by |
8677 | .BR dirs , | |
bb70624e JA |
8678 | starting with zero. For example: |
8679 | .if n ``popd +0'' | |
8680 | .if t \f(CWpopd +0\fP | |
8681 | removes the first directory, | |
8682 | .if n ``popd +1'' | |
8683 | .if t \f(CWpopd +1\fP | |
8684 | the second. | |
726f6388 | 8685 | .TP |
ccc6cda3 JA |
8686 | \fB\-\fP\fIn\fP |
8687 | Removes the \fIn\fPth entry counting from the right of the list | |
726f6388 JA |
8688 | shown by |
8689 | .BR dirs , | |
bb70624e JA |
8690 | starting with zero. For example: |
8691 | .if n ``popd -0'' | |
8692 | .if t \f(CWpopd -0\fP | |
8693 | removes the last directory, | |
8694 | .if n ``popd -1'' | |
8695 | .if t \f(CWpopd -1\fP | |
8696 | the next to last. | |
726f6388 JA |
8697 | .PD |
8698 | .PP | |
8699 | If the | |
8700 | .B popd | |
a0c0a00f | 8701 | command is successful, a |
726f6388 JA |
8702 | .B dirs |
8703 | is performed as well, and the return status is 0. | |
8704 | .B popd | |
cce855bc | 8705 | returns false if an invalid option is encountered, the directory stack |
726f6388 JA |
8706 | is empty, a non-existent directory stack entry is specified, or the |
8707 | directory change fails. | |
8708 | .RE | |
8709 | .TP | |
95732b49 | 8710 | \fBprintf\fP [\fB\-v\fP \fIvar\fP] \fIformat\fP [\fIarguments\fP] |
cce855bc JA |
8711 | Write the formatted \fIarguments\fP to the standard output under the |
8712 | control of the \fIformat\fP. | |
495aee44 CR |
8713 | The \fB\-v\fP option causes the output to be assigned to the variable |
8714 | \fIvar\fP rather than being printed to the standard output. | |
8715 | .sp 1 | |
cce855bc JA |
8716 | The \fIformat\fP is a character string which contains three types of objects: |
8717 | plain characters, which are simply copied to standard output, character | |
8718 | escape sequences, which are converted and copied to the standard output, and | |
8719 | format specifications, each of which causes printing of the next successive | |
8720 | \fIargument\fP. | |
495aee44 CR |
8721 | In addition to the standard \fIprintf\fP(1) format specifications, |
8722 | \fBprintf\fP interprets the following extensions: | |
8723 | .RS | |
8724 | .PD 0 | |
8725 | .TP | |
8726 | .B %b | |
8727 | causes | |
cce855bc | 8728 | \fBprintf\fP to expand backslash escape sequences in the corresponding |
a0c0a00f CR |
8729 | \fIargument\fP |
8730 | in the same way as \fBecho \-e\fP. | |
495aee44 CR |
8731 | .TP |
8732 | .B %q | |
8733 | causes \fBprintf\fP to output the corresponding | |
cce855bc | 8734 | \fIargument\fP in a format that can be reused as shell input. |
495aee44 CR |
8735 | .TP |
8736 | .B %(\fIdatefmt\fP)T | |
8737 | causes \fBprintf\fP to output the date-time string resulting from using | |
ac50fbac CR |
8738 | \fIdatefmt\fP as a format string for \fIstrftime\fP(3). |
8739 | The corresponding \fIargument\fP is an integer representing the number of | |
8740 | seconds since the epoch. | |
8741 | Two special argument values may be used: -1 represents the current | |
495aee44 | 8742 | time, and -2 represents the time the shell was invoked. |
ac50fbac CR |
8743 | If no argument is specified, conversion behaves as if -1 had been given. |
8744 | This is an exception to the usual \fBprintf\fP behavior. | |
495aee44 CR |
8745 | .PD |
8746 | .PP | |
8747 | Arguments to non-string format specifiers are treated as C constants, | |
8748 | except that a leading plus or minus sign is allowed, and if the leading | |
8749 | character is a single or double quote, the value is the ASCII value of | |
8750 | the following character. | |
8751 | .PP | |
cce855bc JA |
8752 | The \fIformat\fP is reused as necessary to consume all of the \fIarguments\fP. |
8753 | If the \fIformat\fP requires more \fIarguments\fP than are supplied, the | |
8754 | extra format specifications behave as if a zero value or null string, as | |
495aee44 CR |
8755 | appropriate, had been supplied. |
8756 | The return value is zero on success, non-zero on failure. | |
8757 | .RE | |
cce855bc | 8758 | .TP |
3185942a | 8759 | \fBpushd\fP [\fB\-n\fP] [+\fIn\fP] [\-\fIn\fP] |
7117c2d2 | 8760 | .PD 0 |
726f6388 | 8761 | .TP |
3185942a | 8762 | \fBpushd\fP [\fB\-n\fP] [\fIdir\fP] |
726f6388 JA |
8763 | .PD |
8764 | Adds a directory to the top of the directory stack, or rotates | |
8765 | the stack, making the new top of the stack the current working | |
a0c0a00f | 8766 | directory. With no arguments, \fBpushd\fP exchanges the top two directories |
726f6388 | 8767 | and returns 0, unless the directory stack is empty. |
ccc6cda3 | 8768 | Arguments, if supplied, have the following meanings: |
726f6388 JA |
8769 | .RS |
8770 | .PD 0 | |
8771 | .TP | |
3185942a | 8772 | .B \-n |
a0c0a00f CR |
8773 | Suppresses the normal change of directory when rotating or |
8774 | adding directories to the stack, so that only the stack is manipulated. | |
3185942a | 8775 | .TP |
ccc6cda3 | 8776 | \fB+\fP\fIn\fP |
726f6388 JA |
8777 | Rotates the stack so that the \fIn\fPth directory |
8778 | (counting from the left of the list shown by | |
d166f048 JA |
8779 | .BR dirs , |
8780 | starting with zero) | |
726f6388 JA |
8781 | is at the top. |
8782 | .TP | |
ccc6cda3 | 8783 | \fB\-\fP\fIn\fP |
726f6388 | 8784 | Rotates the stack so that the \fIn\fPth directory |
d166f048 JA |
8785 | (counting from the right of the list shown by |
8786 | .BR dirs , | |
8787 | starting with zero) is at the top. | |
726f6388 | 8788 | .TP |
bb70624e | 8789 | .I dir |
ccc6cda3 | 8790 | Adds |
726f6388 JA |
8791 | .I dir |
8792 | to the directory stack at the top, making it the | |
ac50fbac CR |
8793 | new current working directory as if it had been supplied as the argument |
8794 | to the \fBcd\fP builtin. | |
726f6388 JA |
8795 | .PD |
8796 | .PP | |
8797 | If the | |
8798 | .B pushd | |
a0c0a00f | 8799 | command is successful, a |
726f6388 JA |
8800 | .B dirs |
8801 | is performed as well. | |
8802 | If the first form is used, | |
8803 | .B pushd | |
8804 | returns 0 unless the cd to | |
8805 | .I dir | |
8806 | fails. With the second form, | |
8807 | .B pushd | |
8808 | returns 0 unless the directory stack is empty, | |
ccc6cda3 | 8809 | a non-existent directory stack element is specified, |
726f6388 JA |
8810 | or the directory change to the specified new current directory |
8811 | fails. | |
8812 | .RE | |
8813 | .TP | |
ccc6cda3 | 8814 | \fBpwd\fP [\fB\-LP\fP] |
bb70624e JA |
8815 | Print the absolute pathname of the current working directory. |
8816 | The pathname printed contains no symbolic links if the | |
726f6388 | 8817 | .B \-P |
a0c0a00f | 8818 | option is supplied or the |
ccc6cda3 | 8819 | .B \-o physical |
726f6388 JA |
8820 | option to the |
8821 | .B set | |
ccc6cda3 JA |
8822 | builtin command is enabled. |
8823 | If the | |
8824 | .B \-L | |
bb70624e | 8825 | option is used, the pathname printed may contain symbolic links. |
ccc6cda3 | 8826 | The return status is 0 unless an error occurs while |
cce855bc JA |
8827 | reading the name of the current directory or an |
8828 | invalid option is supplied. | |
726f6388 | 8829 | .TP |
0001803f | 8830 | \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 | 8831 | One line is read from the standard input, or from the file descriptor |
a0c0a00f CR |
8832 | \fIfd\fP supplied as an argument to the \fB\-u\fP option, |
8833 | split into words as described above under \fBWord Splitting\fP, | |
8834 | and the first word | |
726f6388 JA |
8835 | is assigned to the first |
8836 | .IR name , | |
8837 | the second word to the second | |
8838 | .IR name , | |
a0c0a00f CR |
8839 | and so on. |
8840 | If there are more words than names, the remaining words and their | |
8841 | intervening delimiters are assigned to the last | |
726f6388 | 8842 | .IR name . |
7117c2d2 | 8843 | If there are fewer words read from the input stream than names, |
cce855bc | 8844 | the remaining names are assigned empty values. |
a0c0a00f | 8845 | The characters in |
726f6388 JA |
8846 | .SM |
8847 | .B IFS | |
ac50fbac CR |
8848 | are used to split the line into words using the same rules the shell |
8849 | uses for expansion (described above under \fBWord Splitting\fP). | |
b72432fd JA |
8850 | The backslash character (\fB\e\fP) may be used to remove any special |
8851 | meaning for the next character read and for line continuation. | |
cce855bc | 8852 | Options, if supplied, have the following meanings: |
ccc6cda3 JA |
8853 | .RS |
8854 | .PD 0 | |
8855 | .TP | |
bb70624e | 8856 | .B \-a \fIaname\fP |
ccc6cda3 JA |
8857 | The words are assigned to sequential indices |
8858 | of the array variable | |
8859 | .IR aname , | |
8860 | starting at 0. | |
8861 | .I aname | |
8862 | is unset before any new values are assigned. | |
cce855bc | 8863 | Other \fIname\fP arguments are ignored. |
ccc6cda3 | 8864 | .TP |
bb70624e JA |
8865 | .B \-d \fIdelim\fP |
8866 | The first character of \fIdelim\fP is used to terminate the input line, | |
8867 | rather than newline. | |
8868 | .TP | |
ccc6cda3 JA |
8869 | .B \-e |
8870 | If the standard input | |
8871 | is coming from a terminal, | |
8872 | .B readline | |
8873 | (see | |
8874 | .SM | |
8875 | .B READLINE | |
8876 | above) is used to obtain the line. | |
3185942a JA |
8877 | Readline uses the current (or default, if line editing was not previously |
8878 | active) editing settings. | |
8879 | .TP | |
8880 | .B \-i \fItext\fP | |
8881 | If | |
8882 | .B readline | |
8883 | is being used to read the line, \fItext\fP is placed into the editing | |
8884 | buffer before editing begins. | |
bb70624e JA |
8885 | .TP |
8886 | .B \-n \fInchars\fP | |
8887 | \fBread\fP returns after reading \fInchars\fP characters rather than | |
a0c0a00f | 8888 | waiting for a complete line of input, but honors a delimiter if fewer |
0001803f CR |
8889 | than \fInchars\fP characters are read before the delimiter. |
8890 | .TP | |
8891 | .B \-N \fInchars\fP | |
8892 | \fBread\fP returns after reading exactly \fInchars\fP characters rather | |
8893 | than waiting for a complete line of input, unless EOF is encountered or | |
8894 | \fBread\fP times out. | |
8895 | Delimiter characters encountered in the input are | |
8896 | not treated specially and do not cause \fBread\fP to return until | |
8897 | \fInchars\fP characters are read. | |
a0c0a00f CR |
8898 | The result is not split on the characters in \fBIFS\fP; the intent is |
8899 | that the variable is assigned exactly the characters read | |
8900 | (with the exception of backslash; see the \fB\-r\fP option below). | |
bb70624e JA |
8901 | .TP |
8902 | .B \-p \fIprompt\fP | |
f73dda09 | 8903 | Display \fIprompt\fP on standard error, without a |
bb70624e JA |
8904 | trailing newline, before attempting to read any input. The prompt |
8905 | is displayed only if input is coming from a terminal. | |
8906 | .TP | |
8907 | .B \-r | |
8908 | Backslash does not act as an escape character. | |
8909 | The backslash is considered to be part of the line. | |
8910 | In particular, a backslash-newline pair may not be used as a line | |
8911 | continuation. | |
8912 | .TP | |
8913 | .B \-s | |
8914 | Silent mode. If input is coming from a terminal, characters are | |
8915 | not echoed. | |
8916 | .TP | |
8917 | .B \-t \fItimeout\fP | |
8918 | Cause \fBread\fP to time out and return failure if a complete line of | |
ac50fbac CR |
8919 | input (or a specified number of characters) |
8920 | is not read within \fItimeout\fP seconds. | |
3185942a JA |
8921 | \fItimeout\fP may be a decimal number with a fractional portion following |
8922 | the decimal point. | |
8923 | This option is only effective if \fBread\fP is reading input from a | |
8924 | terminal, pipe, or other special file; it has no effect when reading | |
8925 | from regular files. | |
ac50fbac CR |
8926 | If \fBread\fP times out, \fBread\fP saves any partial input read into |
8927 | the specified variable \fIname\fP. | |
8928 | If \fItimeout\fP is 0, \fBread\fP returns immediately, without trying to | |
8929 | read any data. The exit status is 0 if input is available on | |
8930 | the specified file descriptor, non-zero otherwise. | |
3185942a | 8931 | The exit status is greater than 128 if the timeout is exceeded. |
7117c2d2 | 8932 | .TP |
95732b49 | 8933 | .B \-u \fIfd\fP |
7117c2d2 | 8934 | Read input from file descriptor \fIfd\fP. |
ccc6cda3 JA |
8935 | .PD |
8936 | .PP | |
8937 | If no | |
726f6388 JA |
8938 | .I names |
8939 | are supplied, the line read is assigned to the variable | |
8940 | .SM | |
8941 | .BR REPLY . | |
a0c0a00f CR |
8942 | The exit status is zero, unless end-of-file is encountered, \fBread\fP |
8943 | times out (in which case the status is greater than 128), | |
ac50fbac CR |
8944 | a variable assignment error (such as assigning to a readonly variable) occurs, |
8945 | or an invalid file descriptor is supplied as the argument to \fB\-u\fP. | |
ccc6cda3 | 8946 | .RE |
726f6388 | 8947 | .TP |
495aee44 | 8948 | \fBreadonly\fP [\fB\-aAf\fP] [\fB\-p\fP] [\fIname\fP[=\fIword\fP] ...] |
726f6388 JA |
8949 | .PD |
8950 | The given | |
ccc6cda3 JA |
8951 | \fInames\fP are marked readonly; the values of these |
8952 | .I names | |
726f6388 JA |
8953 | may not be changed by subsequent assignment. |
8954 | If the | |
8955 | .B \-f | |
8956 | option is supplied, the functions corresponding to the | |
8957 | \fInames\fP are so | |
ccc6cda3 JA |
8958 | marked. |
8959 | The | |
8960 | .B \-a | |
3185942a JA |
8961 | option restricts the variables to indexed arrays; the |
8962 | .B \-A | |
8963 | option restricts the variables to associative arrays. | |
495aee44 CR |
8964 | If both options are supplied, |
8965 | .B \-A | |
8966 | takes precedence. | |
ccc6cda3 JA |
8967 | If no |
8968 | .I name | |
8969 | arguments are given, or if the | |
726f6388 | 8970 | .B \-p |
ccc6cda3 | 8971 | option is supplied, a list of all readonly names is printed. |
495aee44 CR |
8972 | The other options may be used to restrict the output to a subset of |
8973 | the set of readonly names. | |
cce855bc JA |
8974 | The |
8975 | .B \-p | |
bb70624e JA |
8976 | option causes output to be displayed in a format that |
8977 | may be reused as input. | |
b80f6443 JA |
8978 | If a variable name is followed by =\fIword\fP, the value of |
8979 | the variable is set to \fIword\fP. | |
cce855bc | 8980 | The return status is 0 unless an invalid option is encountered, |
ccc6cda3 JA |
8981 | one of the |
8982 | .I names | |
cce855bc | 8983 | is not a valid shell variable name, or |
726f6388 JA |
8984 | .B \-f |
8985 | is supplied with a | |
8986 | .I name | |
8987 | that is not a function. | |
8988 | .TP | |
8989 | \fBreturn\fP [\fIn\fP] | |
ac50fbac CR |
8990 | Causes a function to stop executing and return the value specified by |
8991 | .I n | |
8992 | to its caller. | |
a0c0a00f | 8993 | If |
726f6388 JA |
8994 | .I n |
8995 | is omitted, the return status is that of the last command | |
a0c0a00f CR |
8996 | executed in the function body. |
8997 | If \fBreturn\fP is executed by a trap handler, the last command used to | |
8998 | determine the status is the last command executed before the trap handler. | |
8999 | if \fBreturn\fP is executed during a \fBDEBUG\fP trap, the last command | |
9000 | used to determine the status is the last command executed by the trap | |
9001 | handler before \fBreturn\fP was invoked. | |
9002 | If | |
ac50fbac CR |
9003 | .B return |
9004 | is used outside a function, | |
a0c0a00f | 9005 | but during execution of a script by the |
726f6388 JA |
9006 | .B . |
9007 | (\fBsource\fP) command, it causes the shell to stop executing | |
9008 | that script and return either | |
9009 | .I n | |
9010 | or the exit status of the last command executed within the | |
ac50fbac CR |
9011 | script as the exit status of the script. |
9012 | If \fIn\fP is supplied, the return value is its least significant | |
9013 | 8 bits. | |
9014 | The return status is non-zero if | |
9015 | .B return | |
9016 | is supplied a non-numeric argument, or | |
9017 | is used outside a | |
9018 | function and not during execution of a script by \fB.\fP\^ or \fBsource\fP. | |
b80f6443 JA |
9019 | Any command associated with the \fBRETURN\fP trap is executed |
9020 | before execution resumes after the function or script. | |
726f6388 | 9021 | .TP |
495aee44 | 9022 | \fBset\fP [\fB\-\-abefhkmnptuvxBCEHPT\fP] [\fB\-o\fP \fIoption\-name\fP] [\fIarg\fP ...] |
3185942a JA |
9023 | .PD 0 |
9024 | .TP | |
495aee44 | 9025 | \fBset\fP [\fB+abefhkmnptuvxBCEHPT\fP] [\fB+o\fP \fIoption\-name\fP] [\fIarg\fP ...] |
3185942a | 9026 | .PD |
ccc6cda3 | 9027 | Without options, the name and value of each shell variable are displayed |
95732b49 JA |
9028 | in a format that can be reused as input |
9029 | for setting or resetting the currently-set variables. | |
9030 | Read-only variables cannot be reset. | |
ac50fbac | 9031 | In \fIposix\fP mode, only shell variables are listed. |
cce855bc | 9032 | The output is sorted according to the current locale. |
ccc6cda3 | 9033 | When options are specified, they set or unset shell attributes. |
3185942a | 9034 | Any arguments remaining after option processing are treated |
a0c0a00f | 9035 | as values for the positional parameters and are assigned, in order, to |
ccc6cda3 JA |
9036 | .BR $1 , |
9037 | .BR $2 , | |
9038 | .B ... | |
9039 | .BR $\fIn\fP . | |
9040 | Options, if specified, have the following meanings: | |
726f6388 JA |
9041 | .RS |
9042 | .PD 0 | |
9043 | .TP 8 | |
9044 | .B \-a | |
a0c0a00f CR |
9045 | Each variable or function that is created or modified is given the |
9046 | export attribute and marked for export to the environment of | |
9047 | subsequent commands. | |
726f6388 JA |
9048 | .TP 8 |
9049 | .B \-b | |
ccc6cda3 JA |
9050 | Report the status of terminated background jobs |
9051 | immediately, rather than before the next primary prompt. This is | |
9052 | effective only when job control is enabled. | |
726f6388 JA |
9053 | .TP 8 |
9054 | .B \-e | |
ac50fbac CR |
9055 | Exit immediately if a |
9056 | \fIpipeline\fP (which may consist of a single \fIsimple command\fP), | |
9057 | a \fIlist\fP, | |
9058 | or a \fIcompound command\fP | |
9059 | (see | |
726f6388 JA |
9060 | .SM |
9061 | .B SHELL GRAMMAR | |
a0c0a00f | 9062 | above), exits with a non-zero status. |
b80f6443 JA |
9063 | The shell does not exit if the |
9064 | command that fails is part of the command list immediately following a | |
9065 | .B while | |
726f6388 | 9066 | or |
b80f6443 | 9067 | .B until |
a0c0a00f | 9068 | keyword, |
17345e5a | 9069 | part of the test following the |
3185942a | 9070 | .B if |
17345e5a JA |
9071 | or |
9072 | .B elif | |
9073 | reserved words, part of any command executed in a | |
726f6388 JA |
9074 | .B && |
9075 | or | |
495aee44 CR |
9076 | .B || |
9077 | list except the command following the final \fB&&\fP or \fB||\fP, | |
3185942a JA |
9078 | any command in a pipeline but the last, |
9079 | or if the command's return value is | |
17345e5a | 9080 | being inverted with |
726f6388 | 9081 | .BR ! . |
ac50fbac CR |
9082 | If a compound command other than a subshell |
9083 | returns a non-zero status because a command failed | |
9084 | while \fB\-e\fP was being ignored, the shell does not exit. | |
f73dda09 | 9085 | A trap on \fBERR\fP, if set, is executed before the shell exits. |
17345e5a JA |
9086 | This option applies to the shell environment and each subshell environment |
9087 | separately (see | |
0001803f | 9088 | .SM |
17345e5a JA |
9089 | .B "COMMAND EXECUTION ENVIRONMENT" |
9090 | above), and may cause | |
9091 | subshells to exit before executing all the commands in the subshell. | |
ac50fbac CR |
9092 | .if t .sp 0.5 |
9093 | .if n .sp 1 | |
9094 | If a compound command or shell function executes in a context | |
9095 | where \fB\-e\fP is being ignored, | |
9096 | none of the commands executed within the compound command or function body | |
9097 | will be affected by the \fB\-e\fP setting, even if \fB\-e\fP is set | |
9098 | and a command returns a failure status. | |
9099 | If a compound command or shell function sets \fB\-e\fP while executing in | |
9100 | a context where \fB\-e\fP is ignored, that setting will not have any | |
9101 | effect until the compound command or the command containing the function | |
9102 | call completes. | |
726f6388 JA |
9103 | .TP 8 |
9104 | .B \-f | |
9105 | Disable pathname expansion. | |
a0c0a00f | 9106 | .TP 8 |
726f6388 | 9107 | .B \-h |
ccc6cda3 | 9108 | Remember the location of commands as they are looked up for execution. |
cce855bc | 9109 | This is enabled by default. |
726f6388 JA |
9110 | .TP 8 |
9111 | .B \-k | |
ccc6cda3 JA |
9112 | All arguments in the form of assignment statements |
9113 | are placed in the environment for a command, not just | |
9114 | those that precede the command name. | |
726f6388 JA |
9115 | .TP 8 |
9116 | .B \-m | |
cce855bc | 9117 | Monitor mode. Job control is enabled. This option is on |
726f6388 JA |
9118 | by default for interactive shells on systems that support |
9119 | it (see | |
9120 | .SM | |
9121 | .B JOB CONTROL | |
ac50fbac CR |
9122 | above). |
9123 | All processes run in a separate process group. | |
9124 | When a background job completes, the shell prints a line | |
9125 | containing its exit status. | |
726f6388 JA |
9126 | .TP 8 |
9127 | .B \-n | |
a0c0a00f CR |
9128 | Read commands but do not execute them. |
9129 | This may be used to check a shell script for syntax errors. | |
9130 | This is ignored by interactive shells. | |
726f6388 | 9131 | .TP 8 |
ccc6cda3 JA |
9132 | .B \-o \fIoption\-name\fP |
9133 | The \fIoption\-name\fP can be one of the following: | |
726f6388 JA |
9134 | .RS |
9135 | .TP 8 | |
9136 | .B allexport | |
9137 | Same as | |
9138 | .BR \-a . | |
9139 | .TP 8 | |
9140 | .B braceexpand | |
ccc6cda3 JA |
9141 | Same as |
9142 | .BR \-B . | |
726f6388 JA |
9143 | .TP 8 |
9144 | .B emacs | |
9145 | Use an emacs-style command line editing interface. This is enabled | |
9146 | by default when the shell is interactive, unless the shell is started | |
9147 | with the | |
ccc6cda3 | 9148 | .B \-\-noediting |
726f6388 | 9149 | option. |
3185942a | 9150 | This also affects the editing interface used for \fBread \-e\fP. |
726f6388 | 9151 | .TP 8 |
0001803f CR |
9152 | .B errexit |
9153 | Same as | |
9154 | .BR \-e . | |
9155 | .TP 8 | |
b80f6443 JA |
9156 | .B errtrace |
9157 | Same as | |
9158 | .BR \-E . | |
9159 | .TP 8 | |
9160 | .B functrace | |
9161 | Same as | |
9162 | .BR \-T . | |
9163 | .TP 8 | |
ccc6cda3 JA |
9164 | .B hashall |
9165 | Same as | |
9166 | .BR \-h . | |
9167 | .TP 8 | |
726f6388 JA |
9168 | .B histexpand |
9169 | Same as | |
9170 | .BR \-H . | |
9171 | .TP 8 | |
ccc6cda3 JA |
9172 | .B history |
9173 | Enable command history, as described above under | |
9174 | .SM | |
9175 | .BR HISTORY . | |
9176 | This option is on by default in interactive shells. | |
9177 | .TP 8 | |
726f6388 | 9178 | .B ignoreeof |
28ef6c31 JA |
9179 | The effect is as if the shell command |
9180 | .if t \f(CWIGNOREEOF=10\fP | |
9181 | .if n ``IGNOREEOF=10'' | |
9182 | had been executed | |
726f6388 JA |
9183 | (see |
9184 | .B Shell Variables | |
9185 | above). | |
9186 | .TP 8 | |
ccc6cda3 JA |
9187 | .B keyword |
9188 | Same as | |
9189 | .BR \-k . | |
726f6388 JA |
9190 | .TP 8 |
9191 | .B monitor | |
9192 | Same as | |
9193 | .BR \-m . | |
9194 | .TP 8 | |
9195 | .B noclobber | |
9196 | Same as | |
9197 | .BR \-C . | |
9198 | .TP 8 | |
9199 | .B noexec | |
9200 | Same as | |
9201 | .BR \-n . | |
9202 | .TP 8 | |
9203 | .B noglob | |
9204 | Same as | |
9205 | .BR \-f . | |
3185942a | 9206 | .TP 8 |
f73dda09 JA |
9207 | .B nolog |
9208 | Currently ignored. | |
726f6388 | 9209 | .TP 8 |
726f6388 JA |
9210 | .B notify |
9211 | Same as | |
9212 | .BR \-b . | |
9213 | .TP 8 | |
9214 | .B nounset | |
9215 | Same as | |
9216 | .BR \-u . | |
9217 | .TP 8 | |
ccc6cda3 JA |
9218 | .B onecmd |
9219 | Same as | |
9220 | .BR \-t . | |
9221 | .TP 8 | |
726f6388 JA |
9222 | .B physical |
9223 | Same as | |
9224 | .BR \-P . | |
9225 | .TP 8 | |
b80f6443 JA |
9226 | .B pipefail |
9227 | If set, the return value of a pipeline is the value of the last | |
9228 | (rightmost) command to exit with a non-zero status, or zero if all | |
9229 | commands in the pipeline exit successfully. | |
9230 | This option is disabled by default. | |
9231 | .TP 8 | |
726f6388 | 9232 | .B posix |
ccc6cda3 JA |
9233 | Change the behavior of |
9234 | .B bash | |
9235 | where the default operation differs | |
0628567a | 9236 | from the POSIX standard to match the standard (\fIposix mode\fP). |
ac50fbac CR |
9237 | See |
9238 | .SM | |
9239 | .B "SEE ALSO" | |
9240 | below for a reference to a document that details how posix mode affects | |
9241 | bash's behavior. | |
726f6388 JA |
9242 | .TP 8 |
9243 | .B privileged | |
9244 | Same as | |
9245 | .BR \-p . | |
9246 | .TP 8 | |
9247 | .B verbose | |
9248 | Same as | |
9249 | .BR \-v . | |
9250 | .TP 8 | |
9251 | .B vi | |
9252 | Use a vi-style command line editing interface. | |
3185942a | 9253 | This also affects the editing interface used for \fBread \-e\fP. |
726f6388 JA |
9254 | .TP 8 |
9255 | .B xtrace | |
9256 | Same as | |
9257 | .BR \-x . | |
ccc6cda3 | 9258 | .sp .5 |
726f6388 | 9259 | .PP |
ccc6cda3 JA |
9260 | If |
9261 | .B \-o | |
9262 | is supplied with no \fIoption\-name\fP, the values of the current options are | |
726f6388 | 9263 | printed. |
ccc6cda3 JA |
9264 | If |
9265 | .B +o | |
9266 | is supplied with no \fIoption\-name\fP, a series of | |
9267 | .B set | |
9268 | commands to recreate the current option settings is displayed on | |
9269 | the standard output. | |
726f6388 JA |
9270 | .RE |
9271 | .TP 8 | |
9272 | .B \-p | |
9273 | Turn on | |
9274 | .I privileged | |
9275 | mode. In this mode, the | |
bb70624e | 9276 | .SM |
726f6388 | 9277 | .B $ENV |
b72432fd | 9278 | and |
bb70624e | 9279 | .SM |
b72432fd JA |
9280 | .B $BASH_ENV |
9281 | files are not processed, shell functions are not inherited from the | |
bb70624e JA |
9282 | environment, and the |
9283 | .SM | |
3185942a | 9284 | .BR SHELLOPTS , |
0001803f CR |
9285 | .SM |
9286 | .BR BASHOPTS , | |
9287 | .SM | |
3185942a JA |
9288 | .BR CDPATH , |
9289 | and | |
0001803f | 9290 | .SM |
3185942a JA |
9291 | .B GLOBIGNORE |
9292 | variables, if they appear in the environment, are ignored. | |
b72432fd JA |
9293 | If the shell is started with the effective user (group) id not equal to the |
9294 | real user (group) id, and the \fB\-p\fP option is not supplied, these actions | |
9295 | are taken and the effective user id is set to the real user id. | |
9296 | If the \fB\-p\fP option is supplied at startup, the effective user id is | |
9297 | not reset. | |
cce855bc | 9298 | Turning this option off causes the effective user |
726f6388 JA |
9299 | and group ids to be set to the real user and group ids. |
9300 | .TP 8 | |
9301 | .B \-t | |
9302 | Exit after reading and executing one command. | |
9303 | .TP 8 | |
9304 | .B \-u | |
89a92869 CR |
9305 | Treat unset variables and parameters other than the special |
9306 | parameters "@" and "*" as an error when performing | |
726f6388 | 9307 | parameter expansion. If expansion is attempted on an |
89a92869 | 9308 | unset variable or parameter, the shell prints an error message, and, |
ccc6cda3 | 9309 | if not interactive, exits with a non-zero status. |
726f6388 JA |
9310 | .TP 8 |
9311 | .B \-v | |
9312 | Print shell input lines as they are read. | |
9313 | .TP 8 | |
9314 | .B \-x | |
ccc6cda3 | 9315 | After expanding each \fIsimple command\fP, |
b80f6443 JA |
9316 | \fBfor\fP command, \fBcase\fP command, \fBselect\fP command, or |
9317 | arithmetic \fBfor\fP command, display the expanded value of | |
726f6388 JA |
9318 | .SM |
9319 | .BR PS4 , | |
b80f6443 JA |
9320 | followed by the command and its expanded arguments |
9321 | or associated word list. | |
726f6388 | 9322 | .TP 8 |
ccc6cda3 JA |
9323 | .B \-B |
9324 | The shell performs brace expansion (see | |
9325 | .B Brace Expansion | |
9326 | above). This is on by default. | |
726f6388 JA |
9327 | .TP 8 |
9328 | .B \-C | |
ccc6cda3 JA |
9329 | If set, |
9330 | .B bash | |
9331 | does not overwrite an existing file with the | |
9332 | .BR > , | |
9333 | .BR >& , | |
9334 | and | |
9335 | .B <> | |
a0c0a00f | 9336 | redirection operators. This may be overridden when |
ccc6cda3 JA |
9337 | creating output files by using the redirection operator |
9338 | .B >| | |
9339 | instead of | |
9340 | .BR > . | |
726f6388 | 9341 | .TP 8 |
b80f6443 JA |
9342 | .B \-E |
9343 | If set, any trap on \fBERR\fP is inherited by shell functions, command | |
9344 | substitutions, and commands executed in a subshell environment. | |
9345 | The \fBERR\fP trap is normally not inherited in such cases. | |
9346 | .TP 8 | |
726f6388 JA |
9347 | .B \-H |
9348 | Enable | |
9349 | .B ! | |
cce855bc | 9350 | style history substitution. This option is on by |
726f6388 JA |
9351 | default when the shell is interactive. |
9352 | .TP 8 | |
9353 | .B \-P | |
ac50fbac | 9354 | If set, the shell does not resolve symbolic links when executing |
ccc6cda3 | 9355 | commands such as |
726f6388 | 9356 | .B cd |
ccc6cda3 JA |
9357 | that change the current working directory. It uses the |
9358 | physical directory structure instead. By default, | |
9359 | .B bash | |
9360 | follows the logical chain of directories when performing commands | |
9361 | which change the current directory. | |
726f6388 | 9362 | .TP 8 |
b80f6443 | 9363 | .B \-T |
95732b49 JA |
9364 | If set, any traps on \fBDEBUG\fP and \fBRETURN\fP are inherited by shell |
9365 | functions, command substitutions, and commands executed in a | |
9366 | subshell environment. | |
9367 | The \fBDEBUG\fP and \fBRETURN\fP traps are normally not inherited | |
9368 | in such cases. | |
b80f6443 | 9369 | .TP 8 |
726f6388 | 9370 | .B \-\- |
cce855bc | 9371 | If no arguments follow this option, then the positional parameters are |
726f6388 JA |
9372 | unset. Otherwise, the positional parameters are set to the |
9373 | \fIarg\fPs, even if some of them begin with a | |
9374 | .BR \- . | |
9375 | .TP 8 | |
9376 | .B \- | |
9377 | Signal the end of options, cause all remaining \fIarg\fPs to be | |
9378 | assigned to the positional parameters. The | |
9379 | .B \-x | |
9380 | and | |
9381 | .B \-v | |
9382 | options are turned off. | |
9383 | If there are no \fIarg\fPs, | |
9384 | the positional parameters remain unchanged. | |
9385 | .PD | |
9386 | .PP | |
cce855bc JA |
9387 | The options are off by default unless otherwise noted. |
9388 | Using + rather than \- causes these options to be turned off. | |
9389 | The options can also be specified as arguments to an invocation of | |
9390 | the shell. | |
9391 | The current set of options may be found in | |
726f6388 | 9392 | .BR $\- . |
cce855bc | 9393 | The return status is always true unless an invalid option is encountered. |
726f6388 JA |
9394 | .RE |
9395 | .TP | |
9396 | \fBshift\fP [\fIn\fP] | |
9397 | The positional parameters from \fIn\fP+1 ... are renamed to | |
9398 | .B $1 | |
9399 | .B .... | |
9400 | Parameters represented by the numbers \fB$#\fP | |
9401 | down to \fB$#\fP\-\fIn\fP+1 are unset. | |
ccc6cda3 JA |
9402 | .I n |
9403 | must be a non-negative number less than or equal to \fB$#\fP. | |
726f6388 JA |
9404 | If |
9405 | .I n | |
9406 | is 0, no parameters are changed. | |
9407 | If | |
a0c0a00f | 9408 | .I n |
726f6388 | 9409 | is not given, it is assumed to be 1. |
726f6388 JA |
9410 | If |
9411 | .I n | |
9412 | is greater than \fB$#\fP, the positional parameters are not changed. | |
ccc6cda3 | 9413 | The return status is greater than zero if |
726f6388 JA |
9414 | .I n |
9415 | is greater than | |
9416 | .B $# | |
ccc6cda3 JA |
9417 | or less than zero; otherwise 0. |
9418 | .TP | |
9419 | \fBshopt\fP [\fB\-pqsu\fP] [\fB\-o\fP] [\fIoptname\fP ...] | |
ac50fbac CR |
9420 | Toggle the values of settings controlling optional shell behavior. |
9421 | The settings can be either those listed below, or, if the | |
9422 | .B \-o | |
9423 | option is used, those available with the | |
9424 | .B \-o | |
9425 | option to the \fBset\fP builtin command. | |
ccc6cda3 JA |
9426 | With no options, or with the |
9427 | .B \-p | |
9428 | option, a list of all settable options is displayed, with | |
cce855bc JA |
9429 | an indication of whether or not each is set. |
9430 | The \fB\-p\fP option causes output to be displayed in a form that | |
9431 | may be reused as input. | |
9432 | Other options have the following meanings: | |
ccc6cda3 JA |
9433 | .RS |
9434 | .PD 0 | |
9435 | .TP | |
9436 | .B \-s | |
9437 | Enable (set) each \fIoptname\fP. | |
9438 | .TP | |
9439 | .B \-u | |
9440 | Disable (unset) each \fIoptname\fP. | |
9441 | .TP | |
9442 | .B \-q | |
9443 | Suppresses normal output (quiet mode); the return status indicates | |
9444 | whether the \fIoptname\fP is set or unset. | |
9445 | If multiple \fIoptname\fP arguments are given with | |
9446 | .BR \-q , | |
9447 | the return status is zero if all \fIoptnames\fP are enabled; non-zero | |
9448 | otherwise. | |
9449 | .TP | |
9450 | .B \-o | |
9451 | Restricts the values of \fIoptname\fP to be those defined for the | |
9452 | .B \-o | |
9453 | option to the | |
9454 | .B set | |
9455 | builtin. | |
9456 | .PD | |
9457 | .PP | |
9458 | If either | |
9459 | .B \-s | |
9460 | or | |
9461 | .B \-u | |
ac50fbac CR |
9462 | is used with no \fIoptname\fP arguments, |
9463 | .B shopt | |
9464 | shows only those options which are set or unset, respectively. | |
ccc6cda3 JA |
9465 | Unless otherwise noted, the \fBshopt\fP options are disabled (unset) |
9466 | by default. | |
9467 | .PP | |
9468 | The return status when listing options is zero if all \fIoptnames\fP | |
9469 | are enabled, non-zero otherwise. When setting or unsetting options, | |
cce855bc | 9470 | the return status is zero unless an \fIoptname\fP is not a valid shell |
ccc6cda3 JA |
9471 | option. |
9472 | .PP | |
9473 | The list of \fBshopt\fP options is: | |
9474 | .if t .sp .5v | |
9475 | .if n .sp 1v | |
9476 | .PD 0 | |
9477 | .TP 8 | |
3185942a JA |
9478 | .B autocd |
9479 | If set, a command name that is the name of a directory is executed as if | |
9480 | it were the argument to the \fBcd\fP command. | |
9481 | This option is only used by interactive shells. | |
9482 | .TP 8 | |
ccc6cda3 JA |
9483 | .B cdable_vars |
9484 | If set, an argument to the | |
9485 | .B cd | |
9486 | builtin command that | |
9487 | is not a directory is assumed to be the name of a variable whose | |
9488 | value is the directory to change to. | |
9489 | .TP 8 | |
9490 | .B cdspell | |
9491 | If set, minor errors in the spelling of a directory component in a | |
9492 | .B cd | |
9493 | command will be corrected. | |
9494 | The errors checked for are transposed characters, | |
9495 | a missing character, and one character too many. | |
ac50fbac | 9496 | If a correction is found, the corrected filename is printed, |
ccc6cda3 | 9497 | and the command proceeds. |
d166f048 | 9498 | This option is only used by interactive shells. |
ccc6cda3 JA |
9499 | .TP 8 |
9500 | .B checkhash | |
9501 | If set, \fBbash\fP checks that a command found in the hash | |
9502 | table exists before trying to execute it. If a hashed command no | |
9503 | longer exists, a normal path search is performed. | |
9504 | .TP 8 | |
3185942a JA |
9505 | .B checkjobs |
9506 | If set, \fBbash\fP lists the status of any stopped and running jobs before | |
9507 | exiting an interactive shell. If any jobs are running, this causes | |
9508 | the exit to be deferred until a second exit is attempted without an | |
0001803f CR |
9509 | intervening command (see |
9510 | .SM | |
9511 | .B "JOB CONTROL" | |
9512 | above). The shell always | |
3185942a JA |
9513 | postpones exiting if any jobs are stopped. |
9514 | .TP 8 | |
ccc6cda3 JA |
9515 | .B checkwinsize |
9516 | If set, \fBbash\fP checks the window size after each command | |
9517 | and, if necessary, updates the values of | |
9518 | .SM | |
9519 | .B LINES | |
9520 | and | |
9521 | .SM | |
9522 | .BR COLUMNS . | |
9523 | .TP 8 | |
9524 | .B cmdhist | |
9525 | If set, | |
9526 | .B bash | |
9527 | attempts to save all lines of a multiple-line | |
9528 | command in the same history entry. This allows | |
9529 | easy re-editing of multi-line commands. | |
9530 | .TP 8 | |
f1be666c JA |
9531 | .B compat31 |
9532 | If set, | |
9533 | .B bash | |
9534 | changes its behavior to that of version 3.1 with respect to quoted | |
ac50fbac CR |
9535 | arguments to the \fB[[\fP conditional command's \fB=~\fP operator |
9536 | and locale-specific string comparison when using the \fB[[\fP | |
495aee44 CR |
9537 | conditional command's \fB<\fP and \fB>\fP operators. |
9538 | Bash versions prior to bash-4.1 use ASCII collation and | |
9539 | .IR strcmp (3); | |
ac50fbac | 9540 | bash-4.1 and later use the current locale's collation sequence and |
495aee44 | 9541 | .IR strcoll (3). |
0001803f | 9542 | .TP 8 |
ac50fbac CR |
9543 | .B compat32 |
9544 | If set, | |
9545 | .B bash | |
9546 | changes its behavior to that of version 3.2 with respect to | |
9547 | locale-specific string comparison when using the \fB[[\fP | |
a0c0a00f CR |
9548 | conditional command's \fB<\fP and \fB>\fP operators (see previous item) |
9549 | and the effect of interrupting a command list. | |
9550 | Bash versions 3.2 and earlier continue with the next command in the list | |
9551 | after one terminates due to an interrupt. | |
ac50fbac | 9552 | .TP 8 |
0001803f CR |
9553 | .B compat40 |
9554 | If set, | |
9555 | .B bash | |
9556 | changes its behavior to that of version 4.0 with respect to locale-specific | |
495aee44 | 9557 | string comparison when using the \fB[[\fP |
ac50fbac CR |
9558 | conditional command's \fB<\fP and \fB>\fP operators (see description of |
9559 | \fBcompat31\fP) | |
0001803f | 9560 | and the effect of interrupting a command list. |
ac50fbac CR |
9561 | Bash versions 4.0 and later interrupt the list as if the shell received the |
9562 | interrupt; previous versions continue with the next command in the list. | |
0001803f | 9563 | .TP 8 |
495aee44 CR |
9564 | .B compat41 |
9565 | If set, | |
9566 | .BR bash , | |
ac50fbac | 9567 | when in \fIposix\fP mode, treats a single quote in a double-quoted |
495aee44 CR |
9568 | parameter expansion as a special character. The single quotes must match |
9569 | (an even number) and the characters between the single quotes are considered | |
9570 | quoted. This is the behavior of posix mode through version 4.1. | |
9571 | The default bash behavior remains as in previous versions. | |
9572 | .TP 8 | |
ac50fbac CR |
9573 | .B compat42 |
9574 | If set, | |
9575 | .B bash | |
9576 | does not process the replacement string in the pattern substitution word | |
9577 | expansion using quote removal. | |
9578 | .TP 8 | |
a0c0a00f CR |
9579 | .B compat43 |
9580 | If set, | |
9581 | .B bash | |
9582 | does not print a warning message if an attempt is made to use a quoted compound | |
9583 | array assignment as an argument to \fBdeclare\fP, | |
9584 | makes word expansion errors | |
9585 | non-fatal errors that cause the current command to fail (the default behavior is | |
9586 | to make them fatal errors that cause the shell to exit), | |
9587 | and does not reset the | |
9588 | loop state when a shell function is executed (this allows \fBbreak\fP or | |
9589 | \fBcontinue\fP in a shell function to affect loops in the caller's context). | |
9590 | .TP 8 | |
ac50fbac CR |
9591 | .B complete_fullquote |
9592 | If set, | |
9593 | .B bash | |
9594 | quotes all shell metacharacters in filenames and directory names when | |
9595 | performing completion. | |
9596 | If not set, | |
9597 | .B bash | |
9598 | removes metacharacters such as the dollar sign from the set of | |
9599 | characters that will be quoted in completed filenames | |
9600 | when these metacharacters appear in shell variable references in words to be | |
9601 | completed. | |
9602 | This means that dollar signs in variable names that expand to directories | |
9603 | will not be quoted; | |
9604 | however, any dollar signs appearing in filenames will not be quoted, either. | |
9605 | This is active only when bash is using backslashes to quote completed | |
9606 | filenames. | |
9607 | This variable is set by default, which is the default bash behavior in | |
9608 | versions through 4.2. | |
9609 | .TP 8 | |
16b2d7f4 CR |
9610 | .B direxpand |
9611 | If set, | |
9612 | .B bash | |
9613 | replaces directory names with the results of word expansion when performing | |
9614 | filename completion. This changes the contents of the readline editing | |
9615 | buffer. | |
9616 | If not set, | |
9617 | .B bash | |
9618 | attempts to preserve what the user typed. | |
9619 | .TP 8 | |
3185942a JA |
9620 | .B dirspell |
9621 | If set, | |
9622 | .B bash | |
9623 | attempts spelling correction on directory names during word completion | |
9624 | if the directory name initially supplied does not exist. | |
9625 | .TP 8 | |
ccc6cda3 | 9626 | .B dotglob |
a0c0a00f | 9627 | If set, |
ccc6cda3 JA |
9628 | .B bash |
9629 | includes filenames beginning with a `.' in the results of pathname | |
9630 | expansion. | |
9631 | .TP 8 | |
9632 | .B execfail | |
9633 | If set, a non-interactive shell will not exit if | |
9634 | it cannot execute the file specified as an argument to the | |
9635 | .B exec | |
9636 | builtin command. An interactive shell does not exit if | |
9637 | .B exec | |
9638 | fails. | |
9639 | .TP 8 | |
9640 | .B expand_aliases | |
9641 | If set, aliases are expanded as described above under | |
9642 | .SM | |
9643 | .BR ALIASES . | |
9644 | This option is enabled by default for interactive shells. | |
9645 | .TP 8 | |
b80f6443 | 9646 | .B extdebug |
a0c0a00f CR |
9647 | If set at shell invocation, arrange to execute the debugger profile |
9648 | before the shell starts, identical to the \fB\-\-debugger\fP option. | |
9649 | If set after invocation, behavior intended for use by debuggers is enabled: | |
b80f6443 JA |
9650 | .RS |
9651 | .TP | |
9652 | .B 1. | |
9653 | The \fB\-F\fP option to the \fBdeclare\fP builtin displays the source | |
9654 | file name and line number corresponding to each function name supplied | |
9655 | as an argument. | |
9656 | .TP | |
9657 | .B 2. | |
9658 | If the command run by the \fBDEBUG\fP trap returns a non-zero value, the | |
9659 | next command is skipped and not executed. | |
9660 | .TP | |
9661 | .B 3. | |
9662 | If the command run by the \fBDEBUG\fP trap returns a value of 2, and the | |
9663 | shell is executing in a subroutine (a shell function or a shell script | |
a0c0a00f CR |
9664 | executed by the \fB.\fP or \fBsource\fP builtins), the shell simulates |
9665 | a call to \fBreturn\fP. | |
95732b49 JA |
9666 | .TP |
9667 | .B 4. | |
0001803f CR |
9668 | .SM |
9669 | .B BASH_ARGC | |
9670 | and | |
9671 | .SM | |
9672 | .B BASH_ARGV | |
9673 | are updated as described in their descriptions above. | |
95732b49 JA |
9674 | .TP |
9675 | .B 5. | |
a0c0a00f | 9676 | Function tracing is enabled: command substitution, shell functions, and |
95732b49 JA |
9677 | subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the |
9678 | \fBDEBUG\fP and \fBRETURN\fP traps. | |
9679 | .TP | |
9680 | .B 6. | |
a0c0a00f | 9681 | Error tracing is enabled: command substitution, shell functions, and |
95732b49 | 9682 | subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the |
495aee44 | 9683 | \fBERR\fP trap. |
b80f6443 JA |
9684 | .RE |
9685 | .TP 8 | |
cce855bc JA |
9686 | .B extglob |
9687 | If set, the extended pattern matching features described above under | |
9688 | \fBPathname Expansion\fP are enabled. | |
9689 | .TP 8 | |
b80f6443 | 9690 | .B extquote |
0628567a | 9691 | If set, \fB$\fP\(aq\fIstring\fP\(aq and \fB$\fP"\fIstring\fP" quoting is |
b80f6443 JA |
9692 | performed within \fB${\fP\fIparameter\fP\fB}\fP expansions |
9693 | enclosed in double quotes. This option is enabled by default. | |
9694 | .TP 8 | |
9695 | .B failglob | |
9696 | If set, patterns which fail to match filenames during pathname expansion | |
9697 | result in an expansion error. | |
9698 | .TP 8 | |
9699 | .B force_fignore | |
0001803f CR |
9700 | If set, the suffixes specified by the |
9701 | .SM | |
9702 | .B FIGNORE | |
9703 | shell variable | |
b80f6443 JA |
9704 | cause words to be ignored when performing word completion even if |
9705 | the ignored words are the only possible completions. | |
9706 | See | |
9707 | .SM | |
9708 | \fBSHELL VARIABLES\fP | |
0001803f CR |
9709 | above for a description of |
9710 | .SM | |
9711 | .BR FIGNORE . | |
b80f6443 JA |
9712 | This option is enabled by default. |
9713 | .TP 8 | |
ac50fbac CR |
9714 | .B globasciiranges |
9715 | If set, range expressions used in pattern matching bracket expressions (see | |
9716 | .SM | |
9717 | .B Pattern Matching | |
9718 | above) behave as if in the traditional C locale when performing | |
9719 | comparisons. That is, the current locale's collating sequence | |
9720 | is not taken into account, so | |
9721 | .B b | |
9722 | will not collate between | |
9723 | .B A | |
9724 | and | |
9725 | .BR B , | |
9726 | and upper-case and lower-case ASCII characters will collate together. | |
9727 | .TP 8 | |
3185942a | 9728 | .B globstar |
0001803f | 9729 | If set, the pattern \fB**\fP used in a pathname expansion context will |
495aee44 | 9730 | match all files and zero or more directories and subdirectories. |
3185942a JA |
9731 | If the pattern is followed by a \fB/\fP, only directories and |
9732 | subdirectories match. | |
9733 | .TP 8 | |
b80f6443 JA |
9734 | .B gnu_errfmt |
9735 | If set, shell error messages are written in the standard GNU error | |
9736 | message format. | |
9737 | .TP 8 | |
ccc6cda3 JA |
9738 | .B histappend |
9739 | If set, the history list is appended to the file named by the value | |
9740 | of the | |
0001803f | 9741 | .SM |
ccc6cda3 JA |
9742 | .B HISTFILE |
9743 | variable when the shell exits, rather than overwriting the file. | |
9744 | .TP 8 | |
9745 | .B histreedit | |
9746 | If set, and | |
9747 | .B readline | |
9748 | is being used, a user is given the opportunity to re-edit a | |
9749 | failed history substitution. | |
9750 | .TP 8 | |
9751 | .B histverify | |
a0c0a00f | 9752 | If set, and |
ccc6cda3 JA |
9753 | .B readline |
9754 | is being used, the results of history substitution are not immediately | |
9755 | passed to the shell parser. Instead, the resulting line is loaded into | |
9756 | the \fBreadline\fP editing buffer, allowing further modification. | |
9757 | .TP 8 | |
9758 | .B hostcomplete | |
9759 | If set, and | |
9760 | .B readline | |
cce855bc JA |
9761 | is being used, \fBbash\fP will attempt to perform hostname completion when a |
9762 | word containing a \fB@\fP is being completed (see | |
ccc6cda3 JA |
9763 | .B Completing |
9764 | under | |
9765 | .SM | |
9766 | .B READLINE | |
9767 | above). | |
9768 | This is enabled by default. | |
9769 | .TP 8 | |
cce855bc JA |
9770 | .B huponexit |
9771 | If set, \fBbash\fP will send | |
9772 | .SM | |
9773 | .B SIGHUP | |
9774 | to all jobs when an interactive login shell exits. | |
9775 | .TP 8 | |
a0c0a00f CR |
9776 | .B inherit_errexit |
9777 | If set, command substitution inherits the value of the \fBerrexit\fP option, | |
9778 | instead of unsetting it in the subshell environment. | |
9779 | This option is enabled when \fIposix mode\fP is enabled. | |
9780 | .TP 8 | |
ccc6cda3 JA |
9781 | .B interactive_comments |
9782 | If set, allow a word beginning with | |
9783 | .B # | |
9784 | to cause that word and all remaining characters on that | |
9785 | line to be ignored in an interactive shell (see | |
9786 | .SM | |
9787 | .B COMMENTS | |
9788 | above). This option is enabled by default. | |
9789 | .TP 8 | |
495aee44 CR |
9790 | .B lastpipe |
9791 | If set, and job control is not active, the shell runs the last command of | |
9792 | a pipeline not executed in the background in the current shell environment. | |
9793 | .TP 8 | |
ccc6cda3 JA |
9794 | .B lithist |
9795 | If set, and the | |
9796 | .B cmdhist | |
9797 | option is enabled, multi-line commands are saved to the history with | |
9798 | embedded newlines rather than using semicolon separators where possible. | |
9799 | .TP 8 | |
f73dda09 JA |
9800 | .B login_shell |
9801 | The shell sets this option if it is started as a login shell (see | |
9802 | .SM | |
9803 | .B "INVOCATION" | |
9804 | above). | |
9805 | The value may not be changed. | |
9806 | .TP 8 | |
ccc6cda3 | 9807 | .B mailwarn |
a0c0a00f | 9808 | If set, and a file that \fBbash\fP is checking for mail has been |
ccc6cda3 JA |
9809 | accessed since the last time it was checked, the message ``The mail in |
9810 | \fImailfile\fP has been read'' is displayed. | |
9811 | .TP 8 | |
bb70624e JA |
9812 | .B no_empty_cmd_completion |
9813 | If set, and | |
9814 | .B readline | |
9815 | is being used, | |
9816 | .B bash | |
0001803f CR |
9817 | will not attempt to search the |
9818 | .SM | |
9819 | .B PATH | |
9820 | for possible completions when | |
bb70624e JA |
9821 | completion is attempted on an empty line. |
9822 | .TP 8 | |
cce855bc JA |
9823 | .B nocaseglob |
9824 | If set, | |
9825 | .B bash | |
9826 | matches filenames in a case\-insensitive fashion when performing pathname | |
9827 | expansion (see | |
9828 | .B Pathname Expansion | |
9829 | above). | |
9830 | .TP 8 | |
95732b49 JA |
9831 | .B nocasematch |
9832 | If set, | |
9833 | .B bash | |
9834 | matches patterns in a case\-insensitive fashion when performing matching | |
a0c0a00f CR |
9835 | while executing \fBcase\fP or \fB[[\fP conditional commands, |
9836 | when performing pattern substitution word expansions, | |
9837 | or when filtering possible completions as part of programmable completion. | |
95732b49 | 9838 | .TP 8 |
ccc6cda3 JA |
9839 | .B nullglob |
9840 | If set, | |
9841 | .B bash | |
9842 | allows patterns which match no | |
9843 | files (see | |
9844 | .B Pathname Expansion | |
9845 | above) | |
9846 | to expand to a null string, rather than themselves. | |
9847 | .TP 8 | |
bb70624e JA |
9848 | .B progcomp |
9849 | If set, the programmable completion facilities (see | |
9850 | \fBProgrammable Completion\fP above) are enabled. | |
9851 | This option is enabled by default. | |
9852 | .TP 8 | |
ccc6cda3 | 9853 | .B promptvars |
b80f6443 JA |
9854 | If set, prompt strings undergo |
9855 | parameter expansion, command substitution, arithmetic | |
9856 | expansion, and quote removal after being expanded as described in | |
ccc6cda3 JA |
9857 | .SM |
9858 | .B PROMPTING | |
9859 | above. This option is enabled by default. | |
9860 | .TP 8 | |
b72432fd JA |
9861 | .B restricted_shell |
9862 | The shell sets this option if it is started in restricted mode (see | |
9863 | .SM | |
9864 | .B "RESTRICTED SHELL" | |
9865 | below). | |
9866 | The value may not be changed. | |
9867 | This is not reset when the startup files are executed, allowing | |
9868 | the startup files to discover whether or not a shell is restricted. | |
9869 | .TP 8 | |
ccc6cda3 JA |
9870 | .B shift_verbose |
9871 | If set, the | |
9872 | .B shift | |
9873 | builtin prints an error message when the shift count exceeds the | |
9874 | number of positional parameters. | |
9875 | .TP 8 | |
9876 | .B sourcepath | |
9877 | If set, the | |
9878 | \fBsource\fP (\fB.\fP) builtin uses the value of | |
9879 | .SM | |
9880 | .B PATH | |
9881 | to find the directory containing the file supplied as an argument. | |
cce855bc | 9882 | This option is enabled by default. |
bb70624e JA |
9883 | .TP 8 |
9884 | .B xpg_echo | |
9885 | If set, the \fBecho\fP builtin expands backslash-escape sequences | |
9886 | by default. | |
ccc6cda3 | 9887 | .RE |
495aee44 | 9888 | .PD |
726f6388 JA |
9889 | .TP |
9890 | \fBsuspend\fP [\fB\-f\fP] | |
9891 | Suspend the execution of this shell until it receives a | |
9892 | .SM | |
9893 | .B SIGCONT | |
3185942a | 9894 | signal. A login shell cannot be suspended; the |
726f6388 | 9895 | .B \-f |
3185942a JA |
9896 | option can be used to override this and force the suspension. |
9897 | The return status is 0 unless the shell is a login shell and | |
726f6388 JA |
9898 | .B \-f |
9899 | is not supplied, or if job control is not enabled. | |
9900 | .TP | |
726f6388 | 9901 | \fBtest\fP \fIexpr\fP |
7117c2d2 | 9902 | .PD 0 |
726f6388 JA |
9903 | .TP |
9904 | \fB[\fP \fIexpr\fP \fB]\fP | |
ac50fbac | 9905 | Return a status of 0 (true) or 1 (false) depending on |
726f6388 JA |
9906 | the evaluation of the conditional expression |
9907 | .IR expr . | |
cce855bc JA |
9908 | Each operator and operand must be a separate argument. |
9909 | Expressions are composed of the primaries described above under | |
9910 | .SM | |
9911 | .BR "CONDITIONAL EXPRESSIONS" . | |
95732b49 JA |
9912 | \fBtest\fP does not accept any options, nor does it accept and ignore |
9913 | an argument of \fB\-\-\fP as signifying the end of options. | |
cce855bc JA |
9914 | .if t .sp 0.5 |
9915 | .if n .sp 1 | |
9916 | Expressions may be combined using the following operators, listed | |
9917 | in decreasing order of precedence. | |
3185942a | 9918 | The evaluation depends on the number of arguments; see below. |
495aee44 | 9919 | Operator precedence is used when there are five or more arguments. |
726f6388 JA |
9920 | .RS |
9921 | .PD 0 | |
9922 | .TP | |
726f6388 JA |
9923 | .B ! \fIexpr\fP |
9924 | True if | |
9925 | .I expr | |
9926 | is false. | |
9927 | .TP | |
cce855bc JA |
9928 | .B ( \fIexpr\fP ) |
9929 | Returns the value of \fIexpr\fP. | |
9930 | This may be used to override the normal precedence of operators. | |
9931 | .TP | |
726f6388 JA |
9932 | \fIexpr1\fP \-\fBa\fP \fIexpr2\fP |
9933 | True if both | |
9934 | .I expr1 | |
cce855bc | 9935 | and |
726f6388 JA |
9936 | .I expr2 |
9937 | are true. | |
9938 | .TP | |
9939 | \fIexpr1\fP \-\fBo\fP \fIexpr2\fP | |
9940 | True if either | |
9941 | .I expr1 | |
cce855bc | 9942 | or |
726f6388 JA |
9943 | .I expr2 |
9944 | is true. | |
cce855bc JA |
9945 | .PD |
9946 | .PP | |
9947 | \fBtest\fP and \fB[\fP evaluate conditional | |
9948 | expressions using a set of rules based on the number of arguments. | |
9949 | .if t .sp 0.5 | |
9950 | .if n .sp 1 | |
9951 | .PD 0 | |
726f6388 | 9952 | .TP |
cce855bc JA |
9953 | 0 arguments |
9954 | The expression is false. | |
9955 | .TP | |
9956 | 1 argument | |
9957 | The expression is true if and only if the argument is not null. | |
9958 | .TP | |
9959 | 2 arguments | |
9960 | If the first argument is \fB!\fP, the expression is true if and | |
9961 | only if the second argument is null. | |
9962 | If the first argument is one of the unary conditional operators listed above | |
9963 | under | |
726f6388 | 9964 | .SM |
cce855bc JA |
9965 | .BR "CONDITIONAL EXPRESSIONS" , |
9966 | the expression is true if the unary test is true. | |
9967 | If the first argument is not a valid unary conditional operator, the expression | |
9968 | is false. | |
9969 | .TP | |
9970 | 3 arguments | |
495aee44 | 9971 | The following conditions are applied in the order listed. |
cce855bc JA |
9972 | If the second argument is one of the binary conditional operators listed above |
9973 | under | |
9974 | .SM | |
9975 | .BR "CONDITIONAL EXPRESSIONS" , | |
9976 | the result of the expression is the result of the binary test using | |
9977 | the first and third arguments as operands. | |
3185942a | 9978 | The \fB\-a\fP and \fB\-o\fP operators are considered binary operators |
a0c0a00f | 9979 | when there are three arguments. |
cce855bc JA |
9980 | If the first argument is \fB!\fP, the value is the negation of |
9981 | the two-argument test using the second and third arguments. | |
9982 | If the first argument is exactly \fB(\fP and the third argument is | |
9983 | exactly \fB)\fP, the result is the one-argument test of the second | |
9984 | argument. | |
9985 | Otherwise, the expression is false. | |
cce855bc JA |
9986 | .TP |
9987 | 4 arguments | |
9988 | If the first argument is \fB!\fP, the result is the negation of | |
9989 | the three-argument expression composed of the remaining arguments. | |
a0c0a00f | 9990 | Otherwise, the expression is parsed and evaluated according to |
cce855bc JA |
9991 | precedence using the rules listed above. |
9992 | .TP | |
9993 | 5 or more arguments | |
9994 | The expression is parsed and evaluated according to precedence | |
9995 | using the rules listed above. | |
495aee44 CR |
9996 | .if t .sp 0.5 |
9997 | .if n .sp 1 | |
9998 | .LP | |
9999 | When used with \fBtest\fP or \fB[\fP, the \fB<\fP and \fB>\fP operators | |
10000 | sort lexicographically using ASCII ordering. | |
726f6388 | 10001 | .RE |
cce855bc | 10002 | .PD |
726f6388 JA |
10003 | .TP |
10004 | .B times | |
10005 | Print the accumulated user and system times for the shell and | |
10006 | for processes run from the shell. The return status is 0. | |
10007 | .TP | |
b80f6443 | 10008 | \fBtrap\fP [\fB\-lp\fP] [[\fIarg\fP] \fIsigspec\fP ...] |
726f6388 JA |
10009 | The command |
10010 | .I arg | |
10011 | is to be read and executed when the shell receives | |
10012 | signal(s) | |
10013 | .IR sigspec . | |
10014 | If | |
10015 | .I arg | |
b80f6443 | 10016 | is absent (and there is a single \fIsigspec\fP) or |
726f6388 | 10017 | .BR \- , |
b80f6443 JA |
10018 | each specified signal is |
10019 | reset to its original disposition (the value it had | |
d166f048 | 10020 | upon entrance to the shell). |
a0c0a00f | 10021 | If |
726f6388 | 10022 | .I arg |
d166f048 JA |
10023 | is the null string the signal specified by each |
10024 | .I sigspec | |
10025 | is ignored by the shell and by the commands it invokes. | |
ccc6cda3 JA |
10026 | If |
10027 | .I arg | |
bb70624e | 10028 | is not present and |
ccc6cda3 | 10029 | .B \-p |
bb70624e | 10030 | has been supplied, then the trap commands associated with each |
ccc6cda3 | 10031 | .I sigspec |
bb70624e JA |
10032 | are displayed. |
10033 | If no arguments are supplied or if only | |
ccc6cda3 JA |
10034 | .B \-p |
10035 | is given, | |
10036 | .B trap | |
b80f6443 JA |
10037 | prints the list of commands associated with each signal. |
10038 | The | |
10039 | .B \-l | |
10040 | option causes the shell to print a list of signal names and | |
10041 | their corresponding numbers. | |
d166f048 | 10042 | Each |
726f6388 JA |
10043 | .I sigspec |
10044 | is either | |
d166f048 | 10045 | a signal name defined in <\fIsignal.h\fP>, or a signal number. |
495aee44 CR |
10046 | Signal names are case insensitive and the |
10047 | .SM | |
10048 | .B SIG | |
10049 | prefix is optional. | |
0001803f CR |
10050 | .if t .sp 0.5 |
10051 | .if n .sp 1 | |
d166f048 | 10052 | If a |
726f6388 JA |
10053 | .I sigspec |
10054 | is | |
10055 | .SM | |
10056 | .B EXIT | |
10057 | (0) the command | |
10058 | .I arg | |
f73dda09 JA |
10059 | is executed on exit from the shell. |
10060 | If a | |
ccc6cda3 JA |
10061 | .I sigspec |
10062 | is | |
10063 | .SM | |
10064 | .BR DEBUG , | |
10065 | the command | |
10066 | .I arg | |
b80f6443 JA |
10067 | is executed before every \fIsimple command\fP, \fIfor\fP command, |
10068 | \fIcase\fP command, \fIselect\fP command, every arithmetic \fIfor\fP | |
10069 | command, and before the first command executes in a shell function (see | |
ccc6cda3 JA |
10070 | .SM |
10071 | .B SHELL GRAMMAR | |
10072 | above). | |
95732b49 | 10073 | Refer to the description of the \fBextdebug\fP option to the |
b80f6443 | 10074 | \fBshopt\fP builtin for details of its effect on the \fBDEBUG\fP trap. |
f73dda09 JA |
10075 | If a |
10076 | .I sigspec | |
10077 | is | |
10078 | .SM | |
0001803f CR |
10079 | .BR RETURN , |
10080 | the command | |
10081 | .I arg | |
495aee44 CR |
10082 | is executed each time a shell function or a script executed with |
10083 | the \fB.\fP or \fBsource\fP builtins finishes executing. | |
0001803f CR |
10084 | .if t .sp 0.5 |
10085 | .if n .sp 1 | |
10086 | If a | |
10087 | .I sigspec | |
10088 | is | |
10089 | .SM | |
f73dda09 JA |
10090 | .BR ERR , |
10091 | the command | |
10092 | .I arg | |
a0c0a00f | 10093 | is executed whenever |
ac50fbac | 10094 | a pipeline (which may consist of a single simple |
a0c0a00f | 10095 | command), a list, or a compound command returns a |
ac50fbac | 10096 | non\-zero exit status, |
b80f6443 | 10097 | subject to the following conditions. |
f73dda09 JA |
10098 | The |
10099 | .SM | |
b80f6443 JA |
10100 | .B ERR |
10101 | trap is not executed if the failed | |
10102 | command is part of the command list immediately following a | |
10103 | .B while | |
f73dda09 | 10104 | or |
b80f6443 | 10105 | .B until |
a0c0a00f | 10106 | keyword, |
b80f6443 | 10107 | part of the test in an |
f73dda09 | 10108 | .I if |
3185942a | 10109 | statement, part of a command executed in a |
f73dda09 JA |
10110 | .B && |
10111 | or | |
495aee44 | 10112 | .B || |
ac50fbac CR |
10113 | list except the command following the final \fB&&\fP or \fB||\fP, |
10114 | any command in a pipeline but the last, | |
10115 | or if the command's return value is | |
10116 | being inverted using | |
f73dda09 | 10117 | .BR ! . |
ac50fbac | 10118 | These are the same conditions obeyed by the \fBerrexit\fP (\fB\-e\fP) option. |
0001803f CR |
10119 | .if t .sp 0.5 |
10120 | .if n .sp 1 | |
726f6388 | 10121 | Signals ignored upon entry to the shell cannot be trapped or reset. |
0628567a | 10122 | Trapped signals that are not being ignored are reset to their original |
0001803f | 10123 | values in a subshell or subshell environment when one is created. |
d166f048 | 10124 | The return status is false if any |
ccc6cda3 JA |
10125 | .I sigspec |
10126 | is invalid; otherwise | |
726f6388 JA |
10127 | .B trap |
10128 | returns true. | |
10129 | .TP | |
7117c2d2 | 10130 | \fBtype\fP [\fB\-aftpP\fP] \fIname\fP [\fIname\fP ...] |
a0c0a00f | 10131 | With no options, |
726f6388 JA |
10132 | indicate how each |
10133 | .I name | |
10134 | would be interpreted if used as a command name. | |
10135 | If the | |
cce855bc JA |
10136 | .B \-t |
10137 | option is used, | |
726f6388 | 10138 | .B type |
ccc6cda3 | 10139 | prints a string which is one of |
726f6388 JA |
10140 | .IR alias , |
10141 | .IR keyword , | |
10142 | .IR function , | |
10143 | .IR builtin , | |
10144 | or | |
a0c0a00f | 10145 | .I file |
726f6388 JA |
10146 | if |
10147 | .I name | |
10148 | is an alias, shell reserved word, function, builtin, or disk file, | |
ccc6cda3 JA |
10149 | respectively. |
10150 | If the | |
10151 | .I name | |
10152 | is not found, then nothing is printed, and an exit status of false | |
10153 | is returned. | |
726f6388 | 10154 | If the |
cce855bc JA |
10155 | .B \-p |
10156 | option is used, | |
726f6388 JA |
10157 | .B type |
10158 | either returns the name of the disk file | |
10159 | that would be executed if | |
10160 | .I name | |
10161 | were specified as a command name, | |
28ef6c31 JA |
10162 | or nothing if |
10163 | .if t \f(CWtype -t name\fP | |
10164 | .if n ``type -t name'' | |
726f6388 JA |
10165 | would not return |
10166 | .IR file . | |
7117c2d2 JA |
10167 | The |
10168 | .B \-P | |
10169 | option forces a | |
10170 | .SM | |
10171 | .B PATH | |
10172 | search for each \fIname\fP, even if | |
10173 | .if t \f(CWtype -t name\fP | |
10174 | .if n ``type -t name'' | |
10175 | would not return | |
10176 | .IR file . | |
726f6388 | 10177 | If a command is hashed, |
cce855bc | 10178 | .B \-p |
7117c2d2 JA |
10179 | and |
10180 | .B \-P | |
ac50fbac | 10181 | print the hashed value, which is not necessarily the file that appears |
a0c0a00f | 10182 | first in |
726f6388 JA |
10183 | .SM |
10184 | .BR PATH . | |
10185 | If the | |
cce855bc | 10186 | .B \-a |
a0c0a00f | 10187 | option is used, |
726f6388 JA |
10188 | .B type |
10189 | prints all of the places that contain | |
a0c0a00f | 10190 | an executable named |
726f6388 JA |
10191 | .IR name . |
10192 | This includes aliases and functions, | |
a0c0a00f | 10193 | if and only if the |
cce855bc JA |
10194 | .B \-p |
10195 | option is not also used. | |
726f6388 JA |
10196 | The table of hashed commands is not consulted |
10197 | when using | |
cce855bc | 10198 | .BR \-a . |
7117c2d2 JA |
10199 | The |
10200 | .B \-f | |
10201 | option suppresses shell function lookup, as with the \fBcommand\fP builtin. | |
726f6388 | 10202 | .B type |
3185942a JA |
10203 | returns true if all of the arguments are found, false if |
10204 | any are not found. | |
726f6388 | 10205 | .TP |
a0c0a00f | 10206 | \fBulimit\fP [\fB\-HSabcdefiklmnpqrstuvxPT\fP [\fIlimit\fP]] |
ccc6cda3 | 10207 | Provides control over the resources available to the shell and to |
f73dda09 | 10208 | processes started by it, on systems that allow such control. |
ccc6cda3 | 10209 | The \fB\-H\fP and \fB\-S\fP options specify that the hard or soft limit is |
3185942a JA |
10210 | set for the given resource. |
10211 | A hard limit cannot be increased by a non-root user once it is set; | |
10212 | a soft limit may be increased up to the value of the hard limit. | |
ccc6cda3 JA |
10213 | If neither \fB\-H\fP nor \fB\-S\fP is specified, both the soft and hard |
10214 | limits are set. | |
f73dda09 JA |
10215 | The value of |
10216 | .I limit | |
10217 | can be a number in the unit specified for the resource | |
10218 | or one of the special values | |
10219 | .BR hard , | |
10220 | .BR soft , | |
10221 | or | |
10222 | .BR unlimited , | |
10223 | which stand for the current hard limit, the current soft limit, and | |
10224 | no limit, respectively. | |
ccc6cda3 | 10225 | If |
726f6388 JA |
10226 | .I limit |
10227 | is omitted, the current value of the soft limit of the resource is | |
ccc6cda3 JA |
10228 | printed, unless the \fB\-H\fP option is given. When more than one |
10229 | resource is specified, the limit name and unit are printed before the value. | |
726f6388 JA |
10230 | Other options are interpreted as follows: |
10231 | .RS | |
10232 | .PD 0 | |
10233 | .TP | |
10234 | .B \-a | |
ccc6cda3 | 10235 | All current limits are reported |
726f6388 | 10236 | .TP |
3185942a JA |
10237 | .B \-b |
10238 | The maximum socket buffer size | |
10239 | .TP | |
726f6388 | 10240 | .B \-c |
ccc6cda3 | 10241 | The maximum size of core files created |
726f6388 JA |
10242 | .TP |
10243 | .B \-d | |
ccc6cda3 | 10244 | The maximum size of a process's data segment |
726f6388 | 10245 | .TP |
0628567a JA |
10246 | .B \-e |
10247 | The maximum scheduling priority ("nice") | |
10248 | .TP | |
726f6388 | 10249 | .B \-f |
0628567a JA |
10250 | The maximum size of files written by the shell and its children |
10251 | .TP | |
10252 | .B \-i | |
10253 | The maximum number of pending signals | |
726f6388 | 10254 | .TP |
a0c0a00f CR |
10255 | .B \-k |
10256 | The maximum number of kqueues that may be allocated | |
10257 | .TP | |
ccc6cda3 JA |
10258 | .B \-l |
10259 | The maximum size that may be locked into memory | |
726f6388 | 10260 | .TP |
ccc6cda3 | 10261 | .B \-m |
17345e5a | 10262 | The maximum resident set size (many systems do not honor this limit) |
726f6388 | 10263 | .TP |
ccc6cda3 JA |
10264 | .B \-n |
10265 | The maximum number of open file descriptors (most systems do not | |
10266 | allow this value to be set) | |
726f6388 JA |
10267 | .TP |
10268 | .B \-p | |
ccc6cda3 | 10269 | The pipe size in 512-byte blocks (this may not be set) |
726f6388 | 10270 | .TP |
0628567a JA |
10271 | .B \-q |
10272 | The maximum number of bytes in POSIX message queues | |
10273 | .TP | |
10274 | .B \-r | |
10275 | The maximum real-time scheduling priority | |
10276 | .TP | |
ccc6cda3 JA |
10277 | .B \-s |
10278 | The maximum stack size | |
10279 | .TP | |
10280 | .B \-t | |
10281 | The maximum amount of cpu time in seconds | |
726f6388 JA |
10282 | .TP |
10283 | .B \-u | |
ccc6cda3 | 10284 | The maximum number of processes available to a single user |
726f6388 JA |
10285 | .TP |
10286 | .B \-v | |
495aee44 CR |
10287 | The maximum amount of virtual memory available to the shell and, on |
10288 | some systems, to its children | |
0628567a JA |
10289 | .TP |
10290 | .B \-x | |
10291 | The maximum number of file locks | |
3185942a | 10292 | .TP |
a0c0a00f CR |
10293 | .B \-P |
10294 | The maximum number of pseudoterminals | |
10295 | .TP | |
3185942a JA |
10296 | .B \-T |
10297 | The maximum number of threads | |
726f6388 JA |
10298 | .PD |
10299 | .PP | |
ccc6cda3 | 10300 | If |
726f6388 | 10301 | .I limit |
ac50fbac | 10302 | is given, and the |
726f6388 | 10303 | .B \-a |
ac50fbac CR |
10304 | option is not used, |
10305 | \fIlimit\fP is the new value of the specified resource. | |
726f6388 JA |
10306 | If no option is given, then |
10307 | .B \-f | |
10308 | is assumed. Values are in 1024-byte increments, except for | |
10309 | .BR \-t , | |
ac50fbac | 10310 | which is in seconds; |
726f6388 | 10311 | .BR \-p , |
ac50fbac | 10312 | which is in units of 512-byte blocks; |
a0c0a00f | 10313 | .BR \-P , |
3185942a JA |
10314 | .BR \-T , |
10315 | .BR \-b , | |
a0c0a00f | 10316 | .BR \-k , |
3185942a | 10317 | .BR \-n , |
726f6388 JA |
10318 | and |
10319 | .BR \-u , | |
a0c0a00f CR |
10320 | which are unscaled values; |
10321 | and, when in Posix mode, | |
10322 | .B \-c | |
10323 | and | |
10324 | .BR \-f , | |
10325 | which are in 512-byte increments. | |
f73dda09 JA |
10326 | The return status is 0 unless an invalid option or argument is supplied, |
10327 | or an error occurs while setting a new limit. | |
726f6388 JA |
10328 | .RE |
10329 | .TP | |
cce855bc | 10330 | \fBumask\fP [\fB\-p\fP] [\fB\-S\fP] [\fImode\fP] |
a0c0a00f | 10331 | The user file-creation mask is set to |
726f6388 JA |
10332 | .IR mode . |
10333 | If | |
10334 | .I mode | |
10335 | begins with a digit, it | |
10336 | is interpreted as an octal number; otherwise | |
10337 | it is interpreted as a symbolic mode mask similar | |
10338 | to that accepted by | |
10339 | .IR chmod (1). | |
10340 | If | |
10341 | .I mode | |
bb70624e | 10342 | is omitted, the current value of the mask is printed. |
ccc6cda3 | 10343 | The |
726f6388 JA |
10344 | .B \-S |
10345 | option causes the mask to be printed in symbolic form; the | |
10346 | default output is an octal number. | |
cce855bc JA |
10347 | If the |
10348 | .B \-p | |
10349 | option is supplied, and | |
10350 | .I mode | |
10351 | is omitted, the output is in a form that may be reused as input. | |
ccc6cda3 | 10352 | The return status is 0 if the mode was successfully changed or if |
726f6388 JA |
10353 | no \fImode\fP argument was supplied, and false otherwise. |
10354 | .TP | |
10355 | \fBunalias\fP [\-\fBa\fP] [\fIname\fP ...] | |
bb70624e | 10356 | Remove each \fIname\fP from the list of defined aliases. If |
726f6388 JA |
10357 | .B \-a |
10358 | is supplied, all alias definitions are removed. The return | |
10359 | value is true unless a supplied | |
10360 | .I name | |
10361 | is not a defined alias. | |
10362 | .TP | |
ac50fbac | 10363 | \fBunset\fP [\-\fBfv\fP] [\-\fBn\fP] [\fIname\fP ...] |
726f6388 JA |
10364 | For each |
10365 | .IR name , | |
ccc6cda3 | 10366 | remove the corresponding variable or function. |
ac50fbac | 10367 | If the |
ccc6cda3 JA |
10368 | .B \-v |
10369 | option is given, each | |
10370 | .I name | |
ac50fbac | 10371 | refers to a shell variable, and that variable is removed. |
ccc6cda3 JA |
10372 | Read-only variables may not be unset. |
10373 | If | |
726f6388 | 10374 | .B \-f |
95732b49 | 10375 | is specified, each |
ccc6cda3 JA |
10376 | .I name |
10377 | refers to a shell function, and the function definition | |
10378 | is removed. | |
ac50fbac CR |
10379 | If the |
10380 | .B \-n | |
10381 | option is supplied, and \fIname\fP is a variable with the \fInameref\fP | |
10382 | attribute, \fIname\fP will be unset rather than the variable it | |
10383 | references. | |
10384 | \fB\-n\fP has no effect if the \fB\-f\fP option is supplied. | |
10385 | If no options are supplied, each \fIname\fP refers to a variable; if | |
10386 | there is no variable by that name, any function with that name is | |
10387 | unset. | |
ccc6cda3 JA |
10388 | Each unset variable or function is removed from the environment |
10389 | passed to subsequent commands. | |
10390 | If any of | |
726f6388 | 10391 | .SM |
0001803f CR |
10392 | .BR COMP_WORDBREAKS , |
10393 | .SM | |
726f6388 JA |
10394 | .BR RANDOM , |
10395 | .SM | |
10396 | .BR SECONDS , | |
10397 | .SM | |
10398 | .BR LINENO , | |
ccc6cda3 JA |
10399 | .SM |
10400 | .BR HISTCMD , | |
bb70624e JA |
10401 | .SM |
10402 | .BR FUNCNAME , | |
10403 | .SM | |
10404 | .BR GROUPS , | |
726f6388 JA |
10405 | or |
10406 | .SM | |
ccc6cda3 | 10407 | .B DIRSTACK |
726f6388 JA |
10408 | are unset, they lose their special properties, even if they are |
10409 | subsequently reset. The exit status is true unless a | |
10410 | .I name | |
b80f6443 | 10411 | is readonly. |
726f6388 | 10412 | .TP |
ac50fbac CR |
10413 | \fBwait\fP [\fB\-n\fP] [\fIn ...\fP] |
10414 | Wait for each specified child process and return its termination status. | |
95732b49 | 10415 | Each |
726f6388 JA |
10416 | .I n |
10417 | may be a process | |
10418 | ID or a job specification; if a job spec is given, all processes | |
10419 | in that job's pipeline are waited for. If | |
10420 | .I n | |
10421 | is not given, all currently active child processes | |
ac50fbac CR |
10422 | are waited for, and the return status is zero. |
10423 | If the \fB\-n\fP option is supplied, \fBwait\fP waits for any job to | |
10424 | terminate and returns its exit status. | |
10425 | If | |
726f6388 | 10426 | .I n |
ccc6cda3 | 10427 | specifies a non-existent process or job, the return status is |
726f6388 JA |
10428 | 127. Otherwise, the return status is the exit status of the last |
10429 | process or job waited for. | |
10430 | .\" bash_builtins | |
10431 | .if \n(zZ=1 .ig zZ | |
ccc6cda3 | 10432 | .SH "RESTRICTED SHELL" |
bb70624e JA |
10433 | .\" rbash.1 |
10434 | .zY | |
726f6388 | 10435 | .PP |
ccc6cda3 | 10436 | If |
726f6388 | 10437 | .B bash |
ccc6cda3 JA |
10438 | is started with the name |
10439 | .BR rbash , | |
10440 | or the | |
10441 | .B \-r | |
10442 | option is supplied at invocation, | |
10443 | the shell becomes restricted. | |
10444 | A restricted shell is used to | |
10445 | set up an environment more controlled than the standard shell. | |
10446 | It behaves identically to | |
10447 | .B bash | |
cce855bc | 10448 | with the exception that the following are disallowed or not performed: |
ccc6cda3 JA |
10449 | .IP \(bu |
10450 | changing directories with \fBcd\fP | |
10451 | .IP \(bu | |
10452 | setting or unsetting the values of | |
0001803f | 10453 | .SM |
b72432fd | 10454 | .BR SHELL , |
0001803f | 10455 | .SM |
b72432fd | 10456 | .BR PATH , |
0001803f | 10457 | .SM |
b72432fd | 10458 | .BR ENV , |
ccc6cda3 | 10459 | or |
0001803f | 10460 | .SM |
b72432fd | 10461 | .B BASH_ENV |
ccc6cda3 JA |
10462 | .IP \(bu |
10463 | specifying command names containing | |
10464 | .B / | |
10465 | .IP \(bu | |
ac50fbac | 10466 | specifying a filename containing a |
ccc6cda3 JA |
10467 | .B / |
10468 | as an argument to the | |
10469 | .B . | |
10470 | builtin command | |
10471 | .IP \(bu | |
495aee44 | 10472 | specifying a filename containing a slash as an argument to the |
bb70624e JA |
10473 | .B \-p |
10474 | option to the | |
10475 | .B hash | |
10476 | builtin command | |
10477 | .IP \(bu | |
ccc6cda3 JA |
10478 | importing function definitions from the shell environment at startup |
10479 | .IP \(bu | |
0001803f CR |
10480 | parsing the value of |
10481 | .SM | |
10482 | .B SHELLOPTS | |
10483 | from the shell environment at startup | |
cce855bc | 10484 | .IP \(bu |
ccc6cda3 JA |
10485 | redirecting output using the >, >|, <>, >&, &>, and >> redirection operators |
10486 | .IP \(bu | |
10487 | using the | |
10488 | .B exec | |
10489 | builtin command to replace the shell with another command | |
10490 | .IP \(bu | |
10491 | adding or deleting builtin commands with the | |
10492 | .B \-f | |
726f6388 | 10493 | and |
ccc6cda3 JA |
10494 | .B \-d |
10495 | options to the | |
10496 | .B enable | |
10497 | builtin command | |
10498 | .IP \(bu | |
495aee44 | 10499 | using the \fBenable\fP builtin command to enable disabled shell builtins |
7117c2d2 | 10500 | .IP \(bu |
ccc6cda3 JA |
10501 | specifying the |
10502 | .B \-p | |
10503 | option to the | |
10504 | .B command | |
10505 | builtin command | |
10506 | .IP \(bu | |
10507 | turning off restricted mode with | |
cce855bc | 10508 | \fBset +r\fP or \fBset +o restricted\fP. |
726f6388 | 10509 | .PP |
ccc6cda3 JA |
10510 | These restrictions are enforced after any startup files are read. |
10511 | .PP | |
b80f6443 JA |
10512 | .ie \n(zY=1 When a command that is found to be a shell script is executed, |
10513 | .el \{ When a command that is found to be a shell script is executed | |
10514 | (see | |
ccc6cda3 JA |
10515 | .SM |
10516 | .B "COMMAND EXECUTION" | |
10517 | above), | |
b80f6443 | 10518 | \} |
ccc6cda3 JA |
10519 | .B rbash |
10520 | turns off any restrictions in the shell spawned to execute the | |
10521 | script. | |
bb70624e JA |
10522 | .\" end of rbash.1 |
10523 | .if \n(zY=1 .ig zY | |
726f6388 JA |
10524 | .SH "SEE ALSO" |
10525 | .PD 0 | |
10526 | .TP | |
bb70624e | 10527 | \fIBash Reference Manual\fP, Brian Fox and Chet Ramey |
726f6388 JA |
10528 | .TP |
10529 | \fIThe Gnu Readline Library\fP, Brian Fox and Chet Ramey | |
10530 | .TP | |
10531 | \fIThe Gnu History Library\fP, Brian Fox and Chet Ramey | |
10532 | .TP | |
ac50fbac CR |
10533 | \fIPortable Operating System Interface (POSIX) Part 2: Shell and Utilities\fP, IEEE -- |
10534 | http://pubs.opengroup.org/onlinepubs/9699919799/ | |
10535 | .TP | |
10536 | http://tiswww.case.edu/~chet/bash/POSIX -- a description of posix mode | |
726f6388 JA |
10537 | .TP |
10538 | \fIsh\fP(1), \fIksh\fP(1), \fIcsh\fP(1) | |
10539 | .TP | |
10540 | \fIemacs\fP(1), \fIvi\fP(1) | |
10541 | .TP | |
10542 | \fIreadline\fP(3) | |
10543 | .PD | |
10544 | .SH FILES | |
10545 | .PD 0 | |
10546 | .TP | |
10547 | .FN /bin/bash | |
10548 | The \fBbash\fP executable | |
10549 | .TP | |
10550 | .FN /etc/profile | |
10551 | The systemwide initialization file, executed for login shells | |
10552 | .TP | |
10553 | .FN ~/.bash_profile | |
10554 | The personal initialization file, executed for login shells | |
10555 | .TP | |
10556 | .FN ~/.bashrc | |
10557 | The individual per-interactive-shell startup file | |
10558 | .TP | |
b72432fd JA |
10559 | .FN ~/.bash_logout |
10560 | The individual login shell cleanup file, executed when a login shell exits | |
10561 | .TP | |
726f6388 JA |
10562 | .FN ~/.inputrc |
10563 | Individual \fIreadline\fP initialization file | |
10564 | .PD | |
10565 | .SH AUTHORS | |
ccc6cda3 | 10566 | Brian Fox, Free Software Foundation |
726f6388 | 10567 | .br |
bb70624e | 10568 | bfox@gnu.org |
726f6388 JA |
10569 | .PP |
10570 | Chet Ramey, Case Western Reserve University | |
10571 | .br | |
17345e5a | 10572 | chet.ramey@case.edu |
726f6388 JA |
10573 | .SH BUG REPORTS |
10574 | If you find a bug in | |
10575 | .B bash, | |
10576 | you should report it. But first, you should | |
10577 | make sure that it really is a bug, and that it appears in the latest | |
10578 | version of | |
b80f6443 JA |
10579 | .BR bash . |
10580 | The latest version is always available from | |
495aee44 | 10581 | \fIftp://ftp.gnu.org/pub/gnu/bash/\fP. |
726f6388 JA |
10582 | .PP |
10583 | Once you have determined that a bug actually exists, use the | |
10584 | .I bashbug | |
10585 | command to submit a bug report. | |
d166f048 | 10586 | If you have a fix, you are encouraged to mail that as well! |
726f6388 | 10587 | Suggestions and `philosophical' bug reports may be mailed |
cce855bc | 10588 | to \fIbug-bash@gnu.org\fP or posted to the Usenet |
726f6388 JA |
10589 | newsgroup |
10590 | .BR gnu.bash.bug . | |
10591 | .PP | |
10592 | ALL bug reports should include: | |
10593 | .PP | |
10594 | .PD 0 | |
10595 | .TP 20 | |
10596 | The version number of \fBbash\fR | |
10597 | .TP | |
10598 | The hardware and operating system | |
10599 | .TP | |
10600 | The compiler used to compile | |
10601 | .TP | |
10602 | A description of the bug behaviour | |
10603 | .TP | |
10604 | A short script or `recipe' which exercises the bug | |
10605 | .PD | |
10606 | .PP | |
10607 | .I bashbug | |
10608 | inserts the first three items automatically into the template | |
10609 | it provides for filing a bug report. | |
10610 | .PP | |
10611 | Comments and bug reports concerning | |
10612 | this manual page should be directed to | |
495aee44 | 10613 | .IR chet.ramey@case.edu . |
726f6388 JA |
10614 | .SH BUGS |
10615 | .PP | |
10616 | It's too big and too slow. | |
10617 | .PP | |
a0c0a00f | 10618 | There are some subtle differences between |
726f6388 JA |
10619 | .B bash |
10620 | and traditional versions of | |
10621 | .BR sh , | |
10622 | mostly because of the | |
10623 | .SM | |
10624 | .B POSIX | |
10625 | specification. | |
10626 | .PP | |
10627 | Aliases are confusing in some uses. | |
ccc6cda3 JA |
10628 | .PP |
10629 | Shell builtin commands and functions are not stoppable/restartable. | |
10630 | .PP | |
10631 | Compound commands and command sequences of the form `a ; b ; c' | |
10632 | are not handled gracefully when process suspension is attempted. | |
10633 | When a process is stopped, the shell immediately executes the next | |
10634 | command in the sequence. | |
10635 | It suffices to place the sequence of commands between | |
10636 | parentheses to force it into a subshell, which may be stopped as | |
10637 | a unit. | |
10638 | .PP | |
ccc6cda3 | 10639 | Array variables may not (yet) be exported. |
3185942a JA |
10640 | .PP |
10641 | There may be only one active coprocess at a time. | |
726f6388 | 10642 | .zZ |
bb70624e | 10643 | .zY |